1 // Copyright 2012 Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
12 "github.com/google/gopacket"
19 EAPCodeRequest EAPCode = 1
20 EAPCodeResponse EAPCode = 2
21 EAPCodeSuccess EAPCode = 3
22 EAPCodeFailure EAPCode = 4
24 // EAPTypeNone means that this EAP layer has no Type or TypeData.
25 // Success and Failure EAPs will have this set.
26 EAPTypeNone EAPType = 0
28 EAPTypeIdentity EAPType = 1
29 EAPTypeNotification EAPType = 2
30 EAPTypeNACK EAPType = 3
31 EAPTypeOTP EAPType = 4
32 EAPTypeTokenCard EAPType = 5
35 // EAP defines an Extensible Authentication Protocol (rfc 3748) layer.
45 // LayerType returns LayerTypeEAP.
46 func (e *EAP) LayerType() gopacket.LayerType { return LayerTypeEAP }
48 // DecodeFromBytes decodes the given bytes into this layer.
49 func (e *EAP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
50 e.Code = EAPCode(data[0])
52 e.Length = binary.BigEndian.Uint16(data[2:4])
55 e.Type = EAPType(data[4])
61 return fmt.Errorf("invalid EAP length %d", e.Length)
63 e.BaseLayer.Contents = data[:e.Length]
64 e.BaseLayer.Payload = data[e.Length:] // Should be 0 bytes
68 // SerializeTo writes the serialized form of this layer into the
69 // SerializationBuffer, implementing gopacket.SerializableLayer.
70 // See the docs for gopacket.SerializableLayer for more info.
71 func (e *EAP) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
73 e.Length = uint16(len(e.TypeData) + 1)
75 size := len(e.TypeData) + 4
79 bytes, err := b.PrependBytes(size)
83 bytes[0] = byte(e.Code)
85 binary.BigEndian.PutUint16(bytes[2:], e.Length)
87 bytes[4] = byte(e.Type)
88 copy(bytes[5:], e.TypeData)
93 // CanDecode returns the set of layer types that this DecodingLayer can decode.
94 func (e *EAP) CanDecode() gopacket.LayerClass {
98 // NextLayerType returns the layer type contained by this DecodingLayer.
99 func (e *EAP) NextLayerType() gopacket.LayerType {
100 return gopacket.LayerTypeZero
103 func decodeEAP(data []byte, p gopacket.PacketBuilder) error {
105 return decodingLayerDecoder(e, data, p)