Skip to content

Commit

Permalink
Merge pull request #73 from hkwi/radiotap_fcs
Browse files Browse the repository at this point in the history
FCS may be handled in Radiotap
  • Loading branch information
gconnell committed Apr 28, 2015
2 parents 5d988aa + 2f3771a commit 09bce8a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 101 deletions.
8 changes: 2 additions & 6 deletions layers/dot11.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,8 @@ func (m *Dot11) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
offset += 6
}

if mainType == Dot11TypeData {
m.BaseLayer = BaseLayer{Contents: data[0:offset], Payload: data[offset:len(data)]}
} else {
m.BaseLayer = BaseLayer{Contents: data[0:offset], Payload: data[offset : len(data)-4]}
m.Checksum = binary.LittleEndian.Uint32(data[len(data)-4 : len(data)])
}
m.BaseLayer = BaseLayer{Contents: data[0:offset], Payload: data[offset : len(data)-4]}
m.Checksum = binary.LittleEndian.Uint32(data[len(data)-4 : len(data)])
return nil
}

Expand Down
157 changes: 63 additions & 94 deletions layers/dot11_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
package layers

import (
"bytes"
_ "fmt"
"github.com/google/gopacket"
"net"
"reflect"
"bytes"
"testing"
)

Expand Down Expand Up @@ -102,73 +102,53 @@ func BenchmarkDecodePacketDot11CtrlCTS(b *testing.B) {
}

// testPacketDot11MgmtBeacon is the packet:
// 06:14:26.492772 637444841us tsft short preamble 6.0 Mb/s -40dB signal -96dB noise antenna 2 5180 MHz 11a Beacon () [6.0* 9.0 12.0* 18.0 24.0* 36.0 48.0 54.0 Mbit] IBSS CH: 36
// 0x0000: 0000 2000 6708 0400 e9a2 fe25 0000 0000 ....g......%....
// 0x0010: 220c d8a0 0200 0000 4001 0000 3c14 2411 ".......@...<.$.
// 0x0020: 8000 0000 ffff ffff ffff 0003 7f07 a016 ................
// 0x0030: 0000 0000 0000 d09b 3840 1028 0000 0000 ........8@.(....
// 0x0040: 6400 0005 0000 0108 8c12 9824 b048 606c d..........$.H`l
// 0x0050: 0301 2405 0400 0100 0007 2a55 5320 2401 ..$.......*US.$.
// 0x0060: 1128 0111 2c01 1130 0111 3401 1738 0117 .(..,..0..4..8..
// 0x0070: 3c01 1740 0117 9501 1e99 011e 9d01 1ea1 <..@............
// 0x0080: 011e a501 1e20 0100 dd18 0050 f202 0101 ...........P....
// 0x0090: 0000 03a4 0000 27a4 0000 4243 5e00 6232 ......'...BC^.b2
// 0x00a0: 2f00 340c 6672 6565 6273 642d 6d65 7368 /.4.freebsd-mesh
// 0x00b0: 3317 0100 0fac 0000 0fac 0000 0fac ff00 3...............
// 0x00c0: 0fac ff00 0fac ff00 df .........
// 15:44:56.531833 6.0 Mb/s 2412 MHz 11g -81dB signal antenna 5 Beacon (Wi2) [6.0* 9.0 12.0* 18.0 24.0* 36.0 48.0 54.0 Mbit] ESS CH: 1
// 0x0000: 0000 1200 2e48 0000 100c 6c09 c000 af05 .....H....l.....
// 0x0010: 0000 8000 0000 ffff ffff ffff c08a de01 ................
// 0x0020: 11b8 c08a de01 11b8 f097 80f1 30bc 1300 ............0...
// 0x0030: 0000 6400 2104 0003 5769 3201 088c 1298 ..d.!...Wi2.....
// 0x0040: 24b0 4860 6c03 0101 0504 0001 0000 2a01 $.H`l.........*.
// 0x0050: 00dd 1800 50f2 0201 0181 0007 a400 0023 ....P..........#
// 0x0060: a400 0042 435e 0062 322f 00dd 1e00 904c ...BC^.b2/.....L
// 0x0070: 338c 011b ffff 0000 0000 0000 0000 0000 3...............
// 0x0080: 1000 0000 0000 0000 0000 002d 1a8c 011b ...........-....
// 0x0090: ffff 0000 0000 0000 0000 0000 1000 0000 ................
// 0x00a0: 0000 0000 0000 00dd 1a00 904c 3401 0000 ...........L4...
// 0x00b0: 0000 0000 0000 0000 0000 0000 0000 0000 ................
// 0x00c0: 0000 003d 1601 0000 0000 0000 0000 0000 ...=............
// 0x00d0: 0000 0000 0000 0000 0000 007f 0400 0000 ................
// 0x00e0: 00dd 0800 1392 0100 0185 0094 0b90 15 ...............
var testPacketDot11MgmtBeacon = []byte{
0x00, 0x00, 0x20, 0x00, 0x67, 0x08, 0x04, 0x00, 0xe9, 0xa2, 0xfe, 0x25, 0x00, 0x00, 0x00, 0x00,
0x22, 0x0c, 0xd8, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x3c, 0x14, 0x24, 0x11,
0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x03, 0x7f, 0x07, 0xa0, 0x16,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, 0x9b, 0x38, 0x40, 0x10, 0x28, 0x00, 0x00, 0x00, 0x00,
0x64, 0x00, 0x00, 0x05, 0x00, 0x00, 0x01, 0x08, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c,
0x03, 0x01, 0x24, 0x05, 0x04, 0x00, 0x01, 0x00, 0x00, 0x07, 0x2a, 0x55, 0x53, 0x20, 0x24, 0x01,
0x11, 0x28, 0x01, 0x11, 0x2c, 0x01, 0x11, 0x30, 0x01, 0x11, 0x34, 0x01, 0x17, 0x38, 0x01, 0x17,
0x3c, 0x01, 0x17, 0x40, 0x01, 0x17, 0x95, 0x01, 0x1e, 0x99, 0x01, 0x1e, 0x9d, 0x01, 0x1e, 0xa1,
0x01, 0x1e, 0xa5, 0x01, 0x1e, 0x20, 0x01, 0x00, 0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01,
0x00, 0x00, 0x03, 0xa4, 0x00, 0x00, 0x27, 0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00, 0x62, 0x32,
0x2f, 0x00, 0x34, 0x0c, 0x66, 0x72, 0x65, 0x65, 0x62, 0x73, 0x64, 0x2d, 0x6d, 0x65, 0x73, 0x68,
0x33, 0x17, 0x01, 0x00, 0x0f, 0xac, 0x00, 0x00, 0x0f, 0xac, 0x00, 0x00, 0x0f, 0xac, 0xff, 0x00,
0x0f, 0xac, 0xff, 0x00, 0x0f, 0xac, 0xff, 0x00, 0xdf,
0x00, 0x00, 0x12, 0x00, 0x2e, 0x48, 0x00, 0x00, 0x10, 0x0c, 0x6c, 0x09, 0xc0, 0x00, 0xaf, 0x05,
0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x8a, 0xde, 0x01,
0x11, 0xb8, 0xc0, 0x8a, 0xde, 0x01, 0x11, 0xb8, 0xf0, 0x97, 0x80, 0xf1, 0x30, 0xbc, 0x13, 0x00,
0x00, 0x00, 0x64, 0x00, 0x21, 0x04, 0x00, 0x03, 0x57, 0x69, 0x32, 0x01, 0x08, 0x8c, 0x12, 0x98,
0x24, 0xb0, 0x48, 0x60, 0x6c, 0x03, 0x01, 0x01, 0x05, 0x04, 0x00, 0x01, 0x00, 0x00, 0x2a, 0x01,
0x00, 0xdd, 0x18, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01, 0x81, 0x00, 0x07, 0xa4, 0x00, 0x00, 0x23,
0xa4, 0x00, 0x00, 0x42, 0x43, 0x5e, 0x00, 0x62, 0x32, 0x2f, 0x00, 0xdd, 0x1e, 0x00, 0x90, 0x4c,
0x33, 0x8c, 0x01, 0x1b, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2d, 0x1a, 0x8c, 0x01, 0x1b,
0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdd, 0x1a, 0x00, 0x90, 0x4c, 0x34, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x3d, 0x16, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x04, 0x00, 0x00, 0x00,
0x00, 0xdd, 0x08, 0x00, 0x13, 0x92, 0x01, 0x00, 0x01, 0x85, 0x00, 0x94, 0x0b, 0x90, 0x15,
}

func TestPacketDot11MgmtBeacon(t *testing.T) {
p := gopacket.NewPacket(testPacketDot11MgmtBeacon, LinkTypeIEEE80211Radio, gopacket.Default)
if p.ErrorLayer() != nil {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}

checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11MgmtBeacon}, t)

if got, ok := p.Layer(LayerTypeRadioTap).(*RadioTap); ok {
want := &RadioTap{BaseLayer: BaseLayer{Contents: []uint8{0x0, 0x0, 0x20, 0x0, 0x67, 0x8, 0x4, 0x0, 0xe9, 0xa2, 0xfe, 0x25, 0x0, 0x0, 0x0, 0x0, 0x22, 0xc, 0xd8, 0xa0, 0x2, 0x0, 0x0, 0x0, 0x40, 0x1, 0x0, 0x0, 0x3c, 0x14, 0x24, 0x11}, Payload: []uint8{0x80, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x3, 0x7f, 0x7, 0xa0, 0x16, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xd0, 0x9b, 0x38, 0x40, 0x10, 0x28, 0x0, 0x0, 0x0, 0x0, 0x64, 0x0, 0x0, 0x5, 0x0, 0x0, 0x1, 0x8, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x24, 0x5, 0x4, 0x0, 0x1, 0x0, 0x0, 0x7, 0x2a, 0x55, 0x53, 0x20, 0x24, 0x1, 0x11, 0x28, 0x1, 0x11, 0x2c, 0x1, 0x11, 0x30, 0x1, 0x11, 0x34, 0x1, 0x17, 0x38, 0x1, 0x17, 0x3c, 0x1, 0x17, 0x40, 0x1, 0x17, 0x95, 0x1, 0x1e, 0x99, 0x1, 0x1e, 0x9d, 0x1, 0x1e, 0xa1, 0x1, 0x1e, 0xa5, 0x1, 0x1e, 0x20, 0x1, 0x0, 0xdd, 0x18, 0x0, 0x50, 0xf2, 0x2, 0x1, 0x1, 0x0, 0x0, 0x3, 0xa4, 0x0, 0x0, 0x27, 0xa4, 0x0, 0x0, 0x42, 0x43, 0x5e, 0x0, 0x62, 0x32, 0x2f, 0x0, 0x34, 0xc, 0x66, 0x72, 0x65, 0x65, 0x62, 0x73, 0x64, 0x2d, 0x6d, 0x65, 0x73, 0x68, 0x33, 0x17, 0x1, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf, 0xac, 0xff, 0x0, 0xdf}}, Version: 0x0, Length: 0x20, Present: 0x40867, TSFT: 0x25fea2e9, Flags: 0x22, Rate: 0xc, ChannelFrequency: 0x0, ChannelFlags: 0x0, FHSS: 0x0, DBMAntennaSignal: -40, DBMAntennaNoise: -96, LockQuality: 0x0, TxAttenuation: 0x0, DBTxAttenuation: 0x0, DBMTxPower: 0, Antenna: 0x2, DBAntennaSignal: 0x0, DBAntennaNoise: 0x0}

if !reflect.DeepEqual(got, want) {
t.Errorf("RadioTap packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
expectedLayers := []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11MgmtBeacon}
for i := 0; i < 12; i++ {
expectedLayers = append(expectedLayers, LayerTypeDot11InformationElement)
}
checkLayers(p, expectedLayers, t)

if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok {
want := &Dot11{
BaseLayer: BaseLayer{
Contents: []uint8{0x80, 0x0, 0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0, 0x3, 0x7f, 0x7, 0xa0, 0x16, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xd0, 0x9b},
Payload: []uint8{0x38, 0x40, 0x10, 0x28, 0x0, 0x0, 0x0, 0x0, 0x64, 0x0, 0x0, 0x5, 0x0, 0x0, 0x1, 0x8, 0x8c, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6c, 0x3, 0x1, 0x24, 0x5, 0x4, 0x0, 0x1, 0x0, 0x0, 0x7, 0x2a, 0x55, 0x53, 0x20, 0x24, 0x1, 0x11, 0x28, 0x1, 0x11, 0x2c, 0x1, 0x11, 0x30, 0x1, 0x11, 0x34, 0x1, 0x17, 0x38, 0x1, 0x17, 0x3c, 0x1, 0x17, 0x40, 0x1, 0x17, 0x95, 0x1, 0x1e, 0x99, 0x1, 0x1e, 0x9d, 0x1, 0x1e, 0xa1, 0x1, 0x1e, 0xa5, 0x1, 0x1e, 0x20, 0x1, 0x0, 0xdd, 0x18, 0x0, 0x50, 0xf2, 0x2, 0x1, 0x1, 0x0, 0x0, 0x3, 0xa4, 0x0, 0x0, 0x27, 0xa4, 0x0, 0x0, 0x42, 0x43, 0x5e, 0x0, 0x62, 0x32, 0x2f, 0x0, 0x34, 0xc, 0x66, 0x72, 0x65, 0x65, 0x62, 0x73, 0x64, 0x2d, 0x6d, 0x65, 0x73, 0x68, 0x33, 0x17, 0x1, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0x0, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf, 0xac, 0xff, 0x0, 0xf},
},
Type: Dot11TypeMgmtBeacon,
Proto: 0x0,
Flags: 0x0,
DurationID: 0x0,
Address1: net.HardwareAddr{0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
Address2: net.HardwareAddr{0x0, 0x3, 0x7f, 0x7, 0xa0, 0x16},
Address3: net.HardwareAddr{0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
Address4: net.HardwareAddr(nil),
SequenceNumber: 0x26f, FragmentNumber: 0x10,
Checksum: 0xdf00ffac,
}

if !reflect.DeepEqual(got, want) {
t.Errorf("Dot11 packet processing failed:\ngot :\n%#v\n\nwant :\n%#v\n\n", got, want)
}
if _, ok := p.Layer(LayerTypeDot11MgmtBeacon).(*Dot11MgmtBeacon); !ok {
t.Errorf("dot11 management beacon frame was expected")
}
}

Expand Down Expand Up @@ -229,25 +209,17 @@ func BenchmarkDecodePacketDot11DataQOSData(b *testing.B) {
}
}

// this test is failing, this has probably todo with the datapad

// testPacketDot11MgmtAction is the packet:
// 06:14:23.248019 634199967us tsft short preamble 6.0 Mb/s -41dB signal -96dB noise antenna 1 5180 MHz 11a Action (00:03:7f:07:a0:16): Reserved(32) Act#0
// 0x0000: 0000 2000 6708 0400 9f1f cd25 0000 0000 ....g......%....
// 0x0010: 220c d7a0 0100 0000 4001 0000 3c14 2411 ".......@...<.$.
// 0x0020: d000 0000 ffff ffff ffff 0003 7f07 a016 ................
// 0x0030: 0003 7f07 a016 a002 2000 4425 0001 1e06 ..........D%....
// 0x0040: 0000 0000 037f 0342 5206 0000 0088 1300 .......BR.......
// 0x0050: 0030 0b00 0001 0600 16cb ace5 f900 0000 .0..............
// 0x0060: 00 .
// 15:54:43.236460 1.0 Mb/s 2412 MHz 11b -67dB signal antenna 5 Action (8e:3a:e3:44:ac:c6): Spectrum Management Act#4
// 0x0000: 0000 1200 2e48 0000 1002 6c09 a000 bd05 .....H....l.....
// 0x0010: 0000 d000 0000 ffff ffff ffff 8e3a e344 .............:.D
// 0x0020: acc6 8e3a e344 acc6 001b 0004 2503 0001 ...:.D......%...
// 0x0030: 0055 39f0 33 .U9.3
var testPacketDot11MgmtAction = []byte{
0x00, 0x00, 0x20, 0x00, 0x67, 0x08, 0x04, 0x00, 0x9f, 0x1f, 0xcd, 0x25, 0x00, 0x00, 0x00, 0x00,
0x22, 0x0c, 0xd7, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x3c, 0x14, 0x24, 0x11,
0xd0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x03, 0x7f, 0x07, 0xa0, 0x16,
0x00, 0x03, 0x7f, 0x07, 0xa0, 0x16, 0xa0, 0x02, 0x20, 0x00, 0x44, 0x25, 0x00, 0x01, 0x1e, 0x06,
0x00, 0x00, 0x00, 0x00, 0x03, 0x7f, 0x03, 0x42, 0x52, 0x06, 0x00, 0x00, 0x00, 0x88, 0x13, 0x00,
0x00, 0x30, 0x0b, 0x00, 0x00, 0x01, 0x06, 0x00, 0x16, 0xcb, 0xac, 0xe5, 0xf9, 0x00, 0x00, 0x00,
0x00,
0x00, 0x00, 0x12, 0x00, 0x2e, 0x48, 0x00, 0x00, 0x10, 0x02, 0x6c, 0x09, 0xa0, 0x00, 0xbd, 0x05,
0x00, 0x00, 0xd0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x8e, 0x3a, 0xe3, 0x44,
0xac, 0xc6, 0x8e, 0x3a, 0xe3, 0x44, 0xac, 0xc6, 0x00, 0x1b, 0x00, 0x04, 0x25, 0x03, 0x00, 0x01,
0x00, 0x55, 0x39, 0xf0, 0x33,
}

func TestPacketDot11MgmtAction(t *testing.T) {
Expand All @@ -256,24 +228,18 @@ func TestPacketDot11MgmtAction(t *testing.T) {
t.Error("Failed to decode packet:", p.ErrorLayer().Error())
}
checkLayers(p, []gopacket.LayerType{LayerTypeRadioTap, LayerTypeDot11, LayerTypeDot11MgmtAction}, t)

want := `PACKET: 97 bytes
- Layer 1 (32 bytes) = RadioTap {Contents=[..32..] Payload=[..65..] Version=0 Length=32 Present=264295 TSFT=634199967 Flags=SHORT-PREAMBLE,DATAPAD Rate=6 Mb/s ChannelFrequency=0 MHz ChannelFlags= FHSS=0 DBMAntennaSignal=-41 DBMAntennaNoise=-96 LockQuality=0 TxAttenuation=0 DBTxAttenuation=0 DBMTxPower=0 Antenna=1 DBAntennaSignal=0 DBAntennaNoise=0}
- Layer 2 (24 bytes) = Dot11 {Contents=[..24..] Payload=[..37..] Type=MgmtAction Proto=0 Flags= DurationID=0 Address1=ff:ff:ff:ff:ff:ff Address2=00:03:7f:07:a0:16 Address3=00:03:7f:07:a0:16 Address4= SequenceNumber=10 FragmentNumber=32 Checksum=0}
- Layer 3 (37 bytes) = Dot11MgmtAction {Contents=[..37..] Payload=[]}
`
if got := p.String(); got != want {
t.Errorf("packet string mismatch:\n---got---\n%q\n---want---\n%q", got, want)
if got, ok := p.Layer(LayerTypeDot11).(*Dot11); !ok {
t.Errorf("dot11 frame was not parsed")
} else if !got.ChecksumValid() {
t.Errorf("Dot11 packet processing failed: checksum failed")
}
if _, ok := p.Layer(LayerTypeDot11).(*Dot11); !ok {
t.Errorf("could not get Dot11 layer from packet")
} else {
// See note above: this checksum fails most likely due to datapad.
// wireshark also says this packet is malformed, so I'm not going to waste
// too much more time on it.
// if !got.ChecksumValid() { t.Errorf("Dot11 packet processing failed: checksum failed") }
if got, ok := p.Layer(LayerTypeDot11MgmtAction).(*Dot11MgmtAction); !ok {
t.Errorf("management action frame was not parsed")
} else if got.Contents[0] != 0 {
t.Errorf("action category was not spectrum management")
}
}

func BenchmarkDecodePacketDot11MgmtAction(b *testing.B) {
for i := 0; i < b.N; i++ {
gopacket.NewPacket(testPacketDot11MgmtAction, LinkTypeIEEE80211Radio, gopacket.NoCopy)
Expand All @@ -287,7 +253,7 @@ func BenchmarkDecodePacketDot11MgmtAction(b *testing.B) {
// 0x0020: d400 0000 0019 e3d3 5352 46e9 7687 ........SRF.v.
var testPacketDot11CtrlAck = []byte{
0x00, 0x00, 0x20, 0x00, 0x67, 0x08, 0x04, 0x00, 0x96, 0xac, 0x12, 0x26, 0x00, 0x00, 0x00, 0x00,
0x22, 0x30, 0xd9, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x3c, 0x14, 0x24, 0x11,
0x32, 0x30, 0xd9, 0xa0, 0x02, 0x00, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x3c, 0x14, 0x24, 0x11,
0xd4, 0x00, 0x00, 0x00, 0x00, 0x19, 0xe3, 0xd3, 0x53, 0x52, 0x46, 0xe9, 0x76, 0x87,
}

Expand All @@ -305,6 +271,9 @@ func TestPacketDot11CtrlAck(t *testing.T) {
}

if got, ok := p.Layer(LayerTypeDot11).(*Dot11); ok {
if !got.ChecksumValid() {
t.Errorf("Dot11 packet processing failed:\nchecksum failed. got :\n%#v\n\n", got)
}
want := &Dot11{
BaseLayer: BaseLayer{
Contents: []uint8{0xd4, 0x0, 0x0, 0x0, 0x0, 0x19, 0xe3, 0xd3, 0x53, 0x52},
Expand Down Expand Up @@ -505,13 +474,13 @@ func TestInformationElement(t *testing.T) {
221, 5, 1, 2, 3, 4, 5,
}
pkt := gopacket.NewPacket(bin, LayerTypeDot11InformationElement, gopacket.NoCopy)

buf := gopacket.NewSerializeBuffer()
var sLayers []gopacket.SerializableLayer
for _,l := range pkt.Layers() {
for _, l := range pkt.Layers() {
sLayers = append(sLayers, l.(*Dot11InformationElement))
}
if err := gopacket.SerializeLayers(buf, gopacket.SerializeOptions{}, sLayers...); err!=nil {
if err := gopacket.SerializeLayers(buf, gopacket.SerializeOptions{}, sLayers...); err != nil {
t.Error(err.Error())
}
if !bytes.Equal(bin, buf.Bytes()) {
Expand Down
11 changes: 10 additions & 1 deletion layers/radiotap.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"encoding/binary"
"fmt"
"github.com/google/gopacket"
"hash/crc32"
)

// align calculates the number of bytes needed to align with the width
Expand Down Expand Up @@ -405,7 +406,15 @@ func (m *RadioTap) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) erro
offset += align(offset, 4)
}

m.BaseLayer = BaseLayer{Contents: data[:m.Length], Payload: data[m.Length:]}
payload := data[m.Length:]
if !m.Flags.FCS() { // Dot11.DecodeFromBytes() expects FCS present
fcs := make([]byte, 4)
h := crc32.NewIEEE()
h.Write(payload)
binary.LittleEndian.PutUint32(fcs, h.Sum32())
payload = append(payload, fcs...)
}
m.BaseLayer = BaseLayer{Contents: data[:m.Length], Payload: payload}

return nil
}
Expand Down

0 comments on commit 09bce8a

Please sign in to comment.