dot11.go 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430
  1. // Copyright 2014 Google, Inc. All rights reserved.
  2. //
  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
  5. // tree.
  6. // See http://standards.ieee.org/findstds/standard/802.11-2012.html for info on
  7. // all of the layers in this file.
  8. package layers
  9. import (
  10. "bytes"
  11. "encoding/binary"
  12. "fmt"
  13. "hash/crc32"
  14. "net"
  15. "github.com/google/gopacket"
  16. )
  17. // Dot11Flags contains the set of 8 flags in the IEEE 802.11 frame control
  18. // header, all in one place.
  19. type Dot11Flags uint8
  20. const (
  21. Dot11FlagsToDS Dot11Flags = 1 << iota
  22. Dot11FlagsFromDS
  23. Dot11FlagsMF
  24. Dot11FlagsRetry
  25. Dot11FlagsPowerManagement
  26. Dot11FlagsMD
  27. Dot11FlagsWEP
  28. Dot11FlagsOrder
  29. )
  30. func (d Dot11Flags) ToDS() bool {
  31. return d&Dot11FlagsToDS != 0
  32. }
  33. func (d Dot11Flags) FromDS() bool {
  34. return d&Dot11FlagsFromDS != 0
  35. }
  36. func (d Dot11Flags) MF() bool {
  37. return d&Dot11FlagsMF != 0
  38. }
  39. func (d Dot11Flags) Retry() bool {
  40. return d&Dot11FlagsRetry != 0
  41. }
  42. func (d Dot11Flags) PowerManagement() bool {
  43. return d&Dot11FlagsPowerManagement != 0
  44. }
  45. func (d Dot11Flags) MD() bool {
  46. return d&Dot11FlagsMD != 0
  47. }
  48. func (d Dot11Flags) WEP() bool {
  49. return d&Dot11FlagsWEP != 0
  50. }
  51. func (d Dot11Flags) Order() bool {
  52. return d&Dot11FlagsOrder != 0
  53. }
  54. // String provides a human readable string for Dot11Flags.
  55. // This string is possibly subject to change over time; if you're storing this
  56. // persistently, you should probably store the Dot11Flags value, not its string.
  57. func (a Dot11Flags) String() string {
  58. var out bytes.Buffer
  59. if a.ToDS() {
  60. out.WriteString("TO-DS,")
  61. }
  62. if a.FromDS() {
  63. out.WriteString("FROM-DS,")
  64. }
  65. if a.MF() {
  66. out.WriteString("MF,")
  67. }
  68. if a.Retry() {
  69. out.WriteString("Retry,")
  70. }
  71. if a.PowerManagement() {
  72. out.WriteString("PowerManagement,")
  73. }
  74. if a.MD() {
  75. out.WriteString("MD,")
  76. }
  77. if a.WEP() {
  78. out.WriteString("WEP,")
  79. }
  80. if a.Order() {
  81. out.WriteString("Order,")
  82. }
  83. if length := out.Len(); length > 0 {
  84. return string(out.Bytes()[:length-1]) // strip final comma
  85. }
  86. return ""
  87. }
  88. type Dot11Reason uint16
  89. // TODO: Verify these reasons, and append more reasons if necessary.
  90. const (
  91. Dot11ReasonReserved Dot11Reason = 1
  92. Dot11ReasonUnspecified Dot11Reason = 2
  93. Dot11ReasonAuthExpired Dot11Reason = 3
  94. Dot11ReasonDeauthStLeaving Dot11Reason = 4
  95. Dot11ReasonInactivity Dot11Reason = 5
  96. Dot11ReasonApFull Dot11Reason = 6
  97. Dot11ReasonClass2FromNonAuth Dot11Reason = 7
  98. Dot11ReasonClass3FromNonAss Dot11Reason = 8
  99. Dot11ReasonDisasStLeaving Dot11Reason = 9
  100. Dot11ReasonStNotAuth Dot11Reason = 10
  101. )
  102. // String provides a human readable string for Dot11Reason.
  103. // This string is possibly subject to change over time; if you're storing this
  104. // persistently, you should probably store the Dot11Reason value, not its string.
  105. func (a Dot11Reason) String() string {
  106. switch a {
  107. case Dot11ReasonReserved:
  108. return "Reserved"
  109. case Dot11ReasonUnspecified:
  110. return "Unspecified"
  111. case Dot11ReasonAuthExpired:
  112. return "Auth. expired"
  113. case Dot11ReasonDeauthStLeaving:
  114. return "Deauth. st. leaving"
  115. case Dot11ReasonInactivity:
  116. return "Inactivity"
  117. case Dot11ReasonApFull:
  118. return "Ap. full"
  119. case Dot11ReasonClass2FromNonAuth:
  120. return "Class2 from non auth."
  121. case Dot11ReasonClass3FromNonAss:
  122. return "Class3 from non ass."
  123. case Dot11ReasonDisasStLeaving:
  124. return "Disass st. leaving"
  125. case Dot11ReasonStNotAuth:
  126. return "St. not auth."
  127. default:
  128. return "Unknown reason"
  129. }
  130. }
  131. type Dot11Status uint16
  132. const (
  133. Dot11StatusSuccess Dot11Status = 0
  134. Dot11StatusFailure Dot11Status = 1 // Unspecified failure
  135. Dot11StatusCannotSupportAllCapabilities Dot11Status = 10 // Cannot support all requested capabilities in the Capability Information field
  136. Dot11StatusInabilityExistsAssociation Dot11Status = 11 // Reassociation denied due to inability to confirm that association exists
  137. Dot11StatusAssociationDenied Dot11Status = 12 // Association denied due to reason outside the scope of this standard
  138. Dot11StatusAlgorithmUnsupported Dot11Status = 13 // Responding station does not support the specified authentication algorithm
  139. Dot11StatusOufOfExpectedSequence Dot11Status = 14 // Received an Authentication frame with authentication transaction sequence number out of expected sequence
  140. Dot11StatusChallengeFailure Dot11Status = 15 // Authentication rejected because of challenge failure
  141. Dot11StatusTimeout Dot11Status = 16 // Authentication rejected due to timeout waiting for next frame in sequence
  142. Dot11StatusAPUnableToHandle Dot11Status = 17 // Association denied because AP is unable to handle additional associated stations
  143. Dot11StatusRateUnsupported Dot11Status = 18 // Association denied due to requesting station not supporting all of the data rates in the BSSBasicRateSet parameter
  144. )
  145. // String provides a human readable string for Dot11Status.
  146. // This string is possibly subject to change over time; if you're storing this
  147. // persistently, you should probably store the Dot11Status value, not its string.
  148. func (a Dot11Status) String() string {
  149. switch a {
  150. case Dot11StatusSuccess:
  151. return "success"
  152. case Dot11StatusFailure:
  153. return "failure"
  154. case Dot11StatusCannotSupportAllCapabilities:
  155. return "cannot-support-all-capabilities"
  156. case Dot11StatusInabilityExistsAssociation:
  157. return "inability-exists-association"
  158. case Dot11StatusAssociationDenied:
  159. return "association-denied"
  160. case Dot11StatusAlgorithmUnsupported:
  161. return "algorithm-unsupported"
  162. case Dot11StatusOufOfExpectedSequence:
  163. return "out-of-expected-sequence"
  164. case Dot11StatusChallengeFailure:
  165. return "challenge-failure"
  166. case Dot11StatusTimeout:
  167. return "timeout"
  168. case Dot11StatusAPUnableToHandle:
  169. return "ap-unable-to-handle"
  170. case Dot11StatusRateUnsupported:
  171. return "rate-unsupported"
  172. default:
  173. return "unknown status"
  174. }
  175. }
  176. type Dot11AckPolicy uint8
  177. const (
  178. Dot11AckPolicyNormal Dot11AckPolicy = 0
  179. Dot11AckPolicyNone Dot11AckPolicy = 1
  180. Dot11AckPolicyNoExplicit Dot11AckPolicy = 2
  181. Dot11AckPolicyBlock Dot11AckPolicy = 3
  182. )
  183. // String provides a human readable string for Dot11AckPolicy.
  184. // This string is possibly subject to change over time; if you're storing this
  185. // persistently, you should probably store the Dot11AckPolicy value, not its string.
  186. func (a Dot11AckPolicy) String() string {
  187. switch a {
  188. case Dot11AckPolicyNormal:
  189. return "normal-ack"
  190. case Dot11AckPolicyNone:
  191. return "no-ack"
  192. case Dot11AckPolicyNoExplicit:
  193. return "no-explicit-ack"
  194. case Dot11AckPolicyBlock:
  195. return "block-ack"
  196. default:
  197. return "unknown-ack-policy"
  198. }
  199. }
  200. type Dot11Algorithm uint16
  201. const (
  202. Dot11AlgorithmOpen Dot11Algorithm = 0
  203. Dot11AlgorithmSharedKey Dot11Algorithm = 1
  204. )
  205. // String provides a human readable string for Dot11Algorithm.
  206. // This string is possibly subject to change over time; if you're storing this
  207. // persistently, you should probably store the Dot11Algorithm value, not its string.
  208. func (a Dot11Algorithm) String() string {
  209. switch a {
  210. case Dot11AlgorithmOpen:
  211. return "open"
  212. case Dot11AlgorithmSharedKey:
  213. return "shared-key"
  214. default:
  215. return "unknown-algorithm"
  216. }
  217. }
  218. type Dot11InformationElementID uint8
  219. // TODO: Verify these element ids, and append more ids if more.
  220. const (
  221. Dot11InformationElementIDSSID Dot11InformationElementID = 0
  222. Dot11InformationElementIDRates Dot11InformationElementID = 1
  223. Dot11InformationElementIDFHSet Dot11InformationElementID = 2
  224. Dot11InformationElementIDDSSet Dot11InformationElementID = 3
  225. Dot11InformationElementIDCFSet Dot11InformationElementID = 4
  226. Dot11InformationElementIDTIM Dot11InformationElementID = 5
  227. Dot11InformationElementIDIBSSSet Dot11InformationElementID = 6
  228. Dot11InformationElementIDChallenge Dot11InformationElementID = 16
  229. Dot11InformationElementIDERPInfo Dot11InformationElementID = 42
  230. Dot11InformationElementIDQOSCapability Dot11InformationElementID = 46
  231. Dot11InformationElementIDERPInfo2 Dot11InformationElementID = 47
  232. Dot11InformationElementIDRSNInfo Dot11InformationElementID = 48
  233. Dot11InformationElementIDESRates Dot11InformationElementID = 50
  234. Dot11InformationElementIDVendor Dot11InformationElementID = 221
  235. Dot11InformationElementIDReserved Dot11InformationElementID = 68
  236. )
  237. // String provides a human readable string for Dot11InformationElementID.
  238. // This string is possibly subject to change over time; if you're storing this
  239. // persistently, you should probably store the Dot11InformationElementID value,
  240. // not its string.
  241. func (a Dot11InformationElementID) String() string {
  242. switch a {
  243. case Dot11InformationElementIDSSID:
  244. return "SSID"
  245. case Dot11InformationElementIDRates:
  246. return "Rates"
  247. case Dot11InformationElementIDFHSet:
  248. return "FHset"
  249. case Dot11InformationElementIDDSSet:
  250. return "DSset"
  251. case Dot11InformationElementIDCFSet:
  252. return "CFset"
  253. case Dot11InformationElementIDTIM:
  254. return "TIM"
  255. case Dot11InformationElementIDIBSSSet:
  256. return "IBSSset"
  257. case Dot11InformationElementIDChallenge:
  258. return "Challenge"
  259. case Dot11InformationElementIDERPInfo:
  260. return "ERPinfo"
  261. case Dot11InformationElementIDQOSCapability:
  262. return "QOS capability"
  263. case Dot11InformationElementIDERPInfo2:
  264. return "ERPinfo2"
  265. case Dot11InformationElementIDRSNInfo:
  266. return "RSNinfo"
  267. case Dot11InformationElementIDESRates:
  268. return "ESrates"
  269. case Dot11InformationElementIDVendor:
  270. return "Vendor"
  271. case Dot11InformationElementIDReserved:
  272. return "Reserved"
  273. default:
  274. return "Unknown information element id"
  275. }
  276. }
  277. // Dot11 provides an IEEE 802.11 base packet header.
  278. // See http://standards.ieee.org/findstds/standard/802.11-2012.html
  279. // for excrutiating detail.
  280. type Dot11 struct {
  281. BaseLayer
  282. Type Dot11Type
  283. Proto uint8
  284. Flags Dot11Flags
  285. DurationID uint16
  286. Address1 net.HardwareAddr
  287. Address2 net.HardwareAddr
  288. Address3 net.HardwareAddr
  289. Address4 net.HardwareAddr
  290. SequenceNumber uint16
  291. FragmentNumber uint16
  292. Checksum uint32
  293. }
  294. func decodeDot11(data []byte, p gopacket.PacketBuilder) error {
  295. d := &Dot11{}
  296. return decodingLayerDecoder(d, data, p)
  297. }
  298. func (m *Dot11) LayerType() gopacket.LayerType { return LayerTypeDot11 }
  299. func (m *Dot11) CanDecode() gopacket.LayerClass { return LayerTypeDot11 }
  300. func (m *Dot11) NextLayerType() gopacket.LayerType {
  301. if m.Flags.WEP() {
  302. return (LayerTypeDot11WEP)
  303. }
  304. return m.Type.LayerType()
  305. }
  306. func (m *Dot11) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  307. if len(data) < 10 {
  308. df.SetTruncated()
  309. return fmt.Errorf("Dot11 length %v too short, %v required", len(data), 10)
  310. }
  311. m.Type = Dot11Type((data[0])&0xFC) >> 2
  312. m.Proto = uint8(data[0]) & 0x0003
  313. m.Flags = Dot11Flags(data[1])
  314. m.DurationID = binary.LittleEndian.Uint16(data[2:4])
  315. m.Address1 = net.HardwareAddr(data[4:10])
  316. offset := 10
  317. mainType := m.Type.MainType()
  318. switch mainType {
  319. case Dot11TypeCtrl:
  320. switch m.Type {
  321. case Dot11TypeCtrlRTS, Dot11TypeCtrlPowersavePoll, Dot11TypeCtrlCFEnd, Dot11TypeCtrlCFEndAck:
  322. if len(data) < offset+6 {
  323. df.SetTruncated()
  324. return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6)
  325. }
  326. m.Address2 = net.HardwareAddr(data[offset : offset+6])
  327. offset += 6
  328. }
  329. case Dot11TypeMgmt, Dot11TypeData:
  330. if len(data) < offset+14 {
  331. df.SetTruncated()
  332. return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+14)
  333. }
  334. m.Address2 = net.HardwareAddr(data[offset : offset+6])
  335. offset += 6
  336. m.Address3 = net.HardwareAddr(data[offset : offset+6])
  337. offset += 6
  338. m.SequenceNumber = (binary.LittleEndian.Uint16(data[offset:offset+2]) & 0xFFF0) >> 4
  339. m.FragmentNumber = (binary.LittleEndian.Uint16(data[offset:offset+2]) & 0x000F)
  340. offset += 2
  341. }
  342. if mainType == Dot11TypeData && m.Flags.FromDS() && m.Flags.ToDS() {
  343. if len(data) < offset+6 {
  344. df.SetTruncated()
  345. return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6)
  346. }
  347. m.Address4 = net.HardwareAddr(data[offset : offset+6])
  348. offset += 6
  349. }
  350. m.BaseLayer = BaseLayer{Contents: data[0:offset], Payload: data[offset : len(data)-4]}
  351. m.Checksum = binary.LittleEndian.Uint32(data[len(data)-4 : len(data)])
  352. return nil
  353. }
  354. func (m *Dot11) ChecksumValid() bool {
  355. // only for CTRL and MGMT frames
  356. h := crc32.NewIEEE()
  357. h.Write(m.Contents)
  358. h.Write(m.Payload)
  359. return m.Checksum == h.Sum32()
  360. }
  361. func (m Dot11) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  362. buf, err := b.PrependBytes(24)
  363. if err != nil {
  364. return err
  365. }
  366. buf[0] = (uint8(m.Type) << 2) | m.Proto
  367. buf[1] = uint8(m.Flags)
  368. binary.LittleEndian.PutUint16(buf[2:4], m.DurationID)
  369. copy(buf[4:10], m.Address1)
  370. offset := 10
  371. switch m.Type.MainType() {
  372. case Dot11TypeCtrl:
  373. switch m.Type {
  374. case Dot11TypeCtrlRTS, Dot11TypeCtrlPowersavePoll, Dot11TypeCtrlCFEnd, Dot11TypeCtrlCFEndAck:
  375. copy(buf[offset:offset+6], m.Address2)
  376. offset += 6
  377. }
  378. case Dot11TypeMgmt, Dot11TypeData:
  379. copy(buf[offset:offset+6], m.Address2)
  380. offset += 6
  381. copy(buf[offset:offset+6], m.Address3)
  382. offset += 6
  383. binary.LittleEndian.PutUint16(buf[offset:offset+2], (m.SequenceNumber<<4)|m.FragmentNumber)
  384. offset += 2
  385. }
  386. if m.Type.MainType() == Dot11TypeData && m.Flags.FromDS() && m.Flags.ToDS() {
  387. copy(buf[offset:offset+6], m.Address4)
  388. offset += 6
  389. }
  390. return nil
  391. }
  392. // Dot11Mgmt is a base for all IEEE 802.11 management layers.
  393. type Dot11Mgmt struct {
  394. BaseLayer
  395. }
  396. func (m *Dot11Mgmt) NextLayerType() gopacket.LayerType { return gopacket.LayerTypePayload }
  397. func (m *Dot11Mgmt) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  398. m.Contents = data
  399. return nil
  400. }
  401. // Dot11Ctrl is a base for all IEEE 802.11 control layers.
  402. type Dot11Ctrl struct {
  403. BaseLayer
  404. }
  405. func (m *Dot11Ctrl) NextLayerType() gopacket.LayerType { return gopacket.LayerTypePayload }
  406. func (m *Dot11Ctrl) LayerType() gopacket.LayerType { return LayerTypeDot11Ctrl }
  407. func (m *Dot11Ctrl) CanDecode() gopacket.LayerClass { return LayerTypeDot11Ctrl }
  408. func (m *Dot11Ctrl) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  409. m.Contents = data
  410. return nil
  411. }
  412. func decodeDot11Ctrl(data []byte, p gopacket.PacketBuilder) error {
  413. d := &Dot11Ctrl{}
  414. return decodingLayerDecoder(d, data, p)
  415. }
  416. // Dot11WEP contains WEP encrpted IEEE 802.11 data.
  417. type Dot11WEP struct {
  418. BaseLayer
  419. }
  420. func (m *Dot11WEP) NextLayerType() gopacket.LayerType { return LayerTypeLLC }
  421. func (m *Dot11WEP) LayerType() gopacket.LayerType { return LayerTypeDot11WEP }
  422. func (m *Dot11WEP) CanDecode() gopacket.LayerClass { return LayerTypeDot11WEP }
  423. func (m *Dot11WEP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  424. m.Contents = data
  425. return nil
  426. }
  427. func decodeDot11WEP(data []byte, p gopacket.PacketBuilder) error {
  428. d := &Dot11WEP{}
  429. return decodingLayerDecoder(d, data, p)
  430. }
  431. // Dot11Data is a base for all IEEE 802.11 data layers.
  432. type Dot11Data struct {
  433. BaseLayer
  434. }
  435. func (m *Dot11Data) NextLayerType() gopacket.LayerType { return LayerTypeLLC }
  436. func (m *Dot11Data) LayerType() gopacket.LayerType { return LayerTypeDot11Data }
  437. func (m *Dot11Data) CanDecode() gopacket.LayerClass { return LayerTypeDot11Data }
  438. func (m *Dot11Data) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  439. m.Payload = data
  440. return nil
  441. }
  442. func decodeDot11Data(data []byte, p gopacket.PacketBuilder) error {
  443. d := &Dot11Data{}
  444. return decodingLayerDecoder(d, data, p)
  445. }
  446. type Dot11DataCFAck struct {
  447. Dot11Data
  448. }
  449. func decodeDot11DataCFAck(data []byte, p gopacket.PacketBuilder) error {
  450. d := &Dot11DataCFAck{}
  451. return decodingLayerDecoder(d, data, p)
  452. }
  453. func (m *Dot11DataCFAck) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFAck }
  454. func (m *Dot11DataCFAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFAck }
  455. func (m *Dot11DataCFAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  456. return m.Dot11Data.DecodeFromBytes(data, df)
  457. }
  458. type Dot11DataCFPoll struct {
  459. Dot11Data
  460. }
  461. func decodeDot11DataCFPoll(data []byte, p gopacket.PacketBuilder) error {
  462. d := &Dot11DataCFPoll{}
  463. return decodingLayerDecoder(d, data, p)
  464. }
  465. func (m *Dot11DataCFPoll) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFPoll }
  466. func (m *Dot11DataCFPoll) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFPoll }
  467. func (m *Dot11DataCFPoll) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  468. return m.Dot11Data.DecodeFromBytes(data, df)
  469. }
  470. type Dot11DataCFAckPoll struct {
  471. Dot11Data
  472. }
  473. func decodeDot11DataCFAckPoll(data []byte, p gopacket.PacketBuilder) error {
  474. d := &Dot11DataCFAckPoll{}
  475. return decodingLayerDecoder(d, data, p)
  476. }
  477. func (m *Dot11DataCFAckPoll) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFAckPoll }
  478. func (m *Dot11DataCFAckPoll) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFAckPoll }
  479. func (m *Dot11DataCFAckPoll) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  480. return m.Dot11Data.DecodeFromBytes(data, df)
  481. }
  482. type Dot11DataNull struct {
  483. Dot11Data
  484. }
  485. func decodeDot11DataNull(data []byte, p gopacket.PacketBuilder) error {
  486. d := &Dot11DataNull{}
  487. return decodingLayerDecoder(d, data, p)
  488. }
  489. func (m *Dot11DataNull) LayerType() gopacket.LayerType { return LayerTypeDot11DataNull }
  490. func (m *Dot11DataNull) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataNull }
  491. func (m *Dot11DataNull) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  492. return m.Dot11Data.DecodeFromBytes(data, df)
  493. }
  494. type Dot11DataCFAckNoData struct {
  495. Dot11Data
  496. }
  497. func decodeDot11DataCFAckNoData(data []byte, p gopacket.PacketBuilder) error {
  498. d := &Dot11DataCFAckNoData{}
  499. return decodingLayerDecoder(d, data, p)
  500. }
  501. func (m *Dot11DataCFAckNoData) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFAckNoData }
  502. func (m *Dot11DataCFAckNoData) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFAckNoData }
  503. func (m *Dot11DataCFAckNoData) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  504. return m.Dot11Data.DecodeFromBytes(data, df)
  505. }
  506. type Dot11DataCFPollNoData struct {
  507. Dot11Data
  508. }
  509. func decodeDot11DataCFPollNoData(data []byte, p gopacket.PacketBuilder) error {
  510. d := &Dot11DataCFPollNoData{}
  511. return decodingLayerDecoder(d, data, p)
  512. }
  513. func (m *Dot11DataCFPollNoData) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFPollNoData }
  514. func (m *Dot11DataCFPollNoData) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFPollNoData }
  515. func (m *Dot11DataCFPollNoData) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  516. return m.Dot11Data.DecodeFromBytes(data, df)
  517. }
  518. type Dot11DataCFAckPollNoData struct {
  519. Dot11Data
  520. }
  521. func decodeDot11DataCFAckPollNoData(data []byte, p gopacket.PacketBuilder) error {
  522. d := &Dot11DataCFAckPollNoData{}
  523. return decodingLayerDecoder(d, data, p)
  524. }
  525. func (m *Dot11DataCFAckPollNoData) LayerType() gopacket.LayerType {
  526. return LayerTypeDot11DataCFAckPollNoData
  527. }
  528. func (m *Dot11DataCFAckPollNoData) CanDecode() gopacket.LayerClass {
  529. return LayerTypeDot11DataCFAckPollNoData
  530. }
  531. func (m *Dot11DataCFAckPollNoData) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  532. return m.Dot11Data.DecodeFromBytes(data, df)
  533. }
  534. type Dot11DataQOS struct {
  535. Dot11Ctrl
  536. TID uint8 /* Traffic IDentifier */
  537. EOSP bool /* End of service period */
  538. AckPolicy Dot11AckPolicy
  539. TXOP uint8
  540. }
  541. func (m *Dot11DataQOS) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  542. if len(data) < 4 {
  543. df.SetTruncated()
  544. return fmt.Errorf("Dot11DataQOS length %v too short, %v required", len(data), 4)
  545. }
  546. m.TID = (uint8(data[0]) & 0x0F)
  547. m.EOSP = (uint8(data[0]) & 0x10) == 0x10
  548. m.AckPolicy = Dot11AckPolicy((uint8(data[0]) & 0x60) >> 5)
  549. m.TXOP = uint8(data[1])
  550. // TODO: Mesh Control bytes 2:4
  551. m.BaseLayer = BaseLayer{Contents: data[0:4], Payload: data[4:]}
  552. return nil
  553. }
  554. type Dot11DataQOSData struct {
  555. Dot11DataQOS
  556. }
  557. func decodeDot11DataQOSData(data []byte, p gopacket.PacketBuilder) error {
  558. d := &Dot11DataQOSData{}
  559. return decodingLayerDecoder(d, data, p)
  560. }
  561. func (m *Dot11DataQOSData) LayerType() gopacket.LayerType { return LayerTypeDot11DataQOSData }
  562. func (m *Dot11DataQOSData) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataQOSData }
  563. func (m *Dot11DataQOSData) NextLayerType() gopacket.LayerType {
  564. return LayerTypeDot11Data
  565. }
  566. type Dot11DataQOSDataCFAck struct {
  567. Dot11DataQOS
  568. }
  569. func decodeDot11DataQOSDataCFAck(data []byte, p gopacket.PacketBuilder) error {
  570. d := &Dot11DataQOSDataCFAck{}
  571. return decodingLayerDecoder(d, data, p)
  572. }
  573. func (m *Dot11DataQOSDataCFAck) LayerType() gopacket.LayerType { return LayerTypeDot11DataQOSDataCFAck }
  574. func (m *Dot11DataQOSDataCFAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataQOSDataCFAck }
  575. func (m *Dot11DataQOSDataCFAck) NextLayerType() gopacket.LayerType { return LayerTypeDot11DataCFAck }
  576. type Dot11DataQOSDataCFPoll struct {
  577. Dot11DataQOS
  578. }
  579. func decodeDot11DataQOSDataCFPoll(data []byte, p gopacket.PacketBuilder) error {
  580. d := &Dot11DataQOSDataCFPoll{}
  581. return decodingLayerDecoder(d, data, p)
  582. }
  583. func (m *Dot11DataQOSDataCFPoll) LayerType() gopacket.LayerType {
  584. return LayerTypeDot11DataQOSDataCFPoll
  585. }
  586. func (m *Dot11DataQOSDataCFPoll) CanDecode() gopacket.LayerClass {
  587. return LayerTypeDot11DataQOSDataCFPoll
  588. }
  589. func (m *Dot11DataQOSDataCFPoll) NextLayerType() gopacket.LayerType { return LayerTypeDot11DataCFPoll }
  590. type Dot11DataQOSDataCFAckPoll struct {
  591. Dot11DataQOS
  592. }
  593. func decodeDot11DataQOSDataCFAckPoll(data []byte, p gopacket.PacketBuilder) error {
  594. d := &Dot11DataQOSDataCFAckPoll{}
  595. return decodingLayerDecoder(d, data, p)
  596. }
  597. func (m *Dot11DataQOSDataCFAckPoll) LayerType() gopacket.LayerType {
  598. return LayerTypeDot11DataQOSDataCFAckPoll
  599. }
  600. func (m *Dot11DataQOSDataCFAckPoll) CanDecode() gopacket.LayerClass {
  601. return LayerTypeDot11DataQOSDataCFAckPoll
  602. }
  603. func (m *Dot11DataQOSDataCFAckPoll) NextLayerType() gopacket.LayerType {
  604. return LayerTypeDot11DataCFAckPoll
  605. }
  606. type Dot11DataQOSNull struct {
  607. Dot11DataQOS
  608. }
  609. func decodeDot11DataQOSNull(data []byte, p gopacket.PacketBuilder) error {
  610. d := &Dot11DataQOSNull{}
  611. return decodingLayerDecoder(d, data, p)
  612. }
  613. func (m *Dot11DataQOSNull) LayerType() gopacket.LayerType { return LayerTypeDot11DataQOSNull }
  614. func (m *Dot11DataQOSNull) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataQOSNull }
  615. func (m *Dot11DataQOSNull) NextLayerType() gopacket.LayerType { return LayerTypeDot11DataNull }
  616. type Dot11DataQOSCFPollNoData struct {
  617. Dot11DataQOS
  618. }
  619. func decodeDot11DataQOSCFPollNoData(data []byte, p gopacket.PacketBuilder) error {
  620. d := &Dot11DataQOSCFPollNoData{}
  621. return decodingLayerDecoder(d, data, p)
  622. }
  623. func (m *Dot11DataQOSCFPollNoData) LayerType() gopacket.LayerType {
  624. return LayerTypeDot11DataQOSCFPollNoData
  625. }
  626. func (m *Dot11DataQOSCFPollNoData) CanDecode() gopacket.LayerClass {
  627. return LayerTypeDot11DataQOSCFPollNoData
  628. }
  629. func (m *Dot11DataQOSCFPollNoData) NextLayerType() gopacket.LayerType {
  630. return LayerTypeDot11DataCFPollNoData
  631. }
  632. type Dot11DataQOSCFAckPollNoData struct {
  633. Dot11DataQOS
  634. }
  635. func decodeDot11DataQOSCFAckPollNoData(data []byte, p gopacket.PacketBuilder) error {
  636. d := &Dot11DataQOSCFAckPollNoData{}
  637. return decodingLayerDecoder(d, data, p)
  638. }
  639. func (m *Dot11DataQOSCFAckPollNoData) LayerType() gopacket.LayerType {
  640. return LayerTypeDot11DataQOSCFAckPollNoData
  641. }
  642. func (m *Dot11DataQOSCFAckPollNoData) CanDecode() gopacket.LayerClass {
  643. return LayerTypeDot11DataQOSCFAckPollNoData
  644. }
  645. func (m *Dot11DataQOSCFAckPollNoData) NextLayerType() gopacket.LayerType {
  646. return LayerTypeDot11DataCFAckPollNoData
  647. }
  648. type Dot11InformationElement struct {
  649. BaseLayer
  650. ID Dot11InformationElementID
  651. Length uint8
  652. OUI []byte
  653. Info []byte
  654. }
  655. func (m *Dot11InformationElement) LayerType() gopacket.LayerType {
  656. return LayerTypeDot11InformationElement
  657. }
  658. func (m *Dot11InformationElement) CanDecode() gopacket.LayerClass {
  659. return LayerTypeDot11InformationElement
  660. }
  661. func (m *Dot11InformationElement) NextLayerType() gopacket.LayerType {
  662. return LayerTypeDot11InformationElement
  663. }
  664. func (m *Dot11InformationElement) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  665. if len(data) < 2 {
  666. df.SetTruncated()
  667. return fmt.Errorf("Dot11InformationElement length %v too short, %v required", len(data), 2)
  668. }
  669. m.ID = Dot11InformationElementID(data[0])
  670. m.Length = data[1]
  671. offset := int(2)
  672. if len(data) < offset+int(m.Length) {
  673. df.SetTruncated()
  674. return fmt.Errorf("Dot11InformationElement length %v too short, %v required", len(data), offset+int(m.Length))
  675. }
  676. if m.ID == 221 {
  677. // Vendor extension
  678. m.OUI = data[offset : offset+4]
  679. m.Info = data[offset+4 : offset+int(m.Length)]
  680. } else {
  681. m.Info = data[offset : offset+int(m.Length)]
  682. }
  683. offset += int(m.Length)
  684. m.BaseLayer = BaseLayer{Contents: data[:offset], Payload: data[offset:]}
  685. return nil
  686. }
  687. func (d *Dot11InformationElement) String() string {
  688. if d.ID == 0 {
  689. return fmt.Sprintf("802.11 Information Element (SSID: %v)", string(d.Info))
  690. } else if d.ID == 1 {
  691. rates := ""
  692. for i := 0; i < len(d.Info); i++ {
  693. if d.Info[i]&0x80 == 0 {
  694. rates += fmt.Sprintf("%.1f ", float32(d.Info[i])*0.5)
  695. } else {
  696. rates += fmt.Sprintf("%.1f* ", float32(d.Info[i]&0x7F)*0.5)
  697. }
  698. }
  699. return fmt.Sprintf("802.11 Information Element (Rates: %s Mbit)", rates)
  700. } else if d.ID == 221 {
  701. return fmt.Sprintf("802.11 Information Element (Vendor: ID: %v, Length: %v, OUI: %X, Info: %X)", d.ID, d.Length, d.OUI, d.Info)
  702. } else {
  703. return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, Info: %X)", d.ID, d.Length, d.Info)
  704. }
  705. }
  706. func (m Dot11InformationElement) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  707. length := len(m.Info) + len(m.OUI)
  708. if buf, err := b.PrependBytes(2 + length); err != nil {
  709. return err
  710. } else {
  711. buf[0] = uint8(m.ID)
  712. buf[1] = uint8(length)
  713. copy(buf[2:], m.OUI)
  714. copy(buf[2+len(m.OUI):], m.Info)
  715. }
  716. return nil
  717. }
  718. func decodeDot11InformationElement(data []byte, p gopacket.PacketBuilder) error {
  719. d := &Dot11InformationElement{}
  720. return decodingLayerDecoder(d, data, p)
  721. }
  722. type Dot11CtrlCTS struct {
  723. Dot11Ctrl
  724. }
  725. func decodeDot11CtrlCTS(data []byte, p gopacket.PacketBuilder) error {
  726. d := &Dot11CtrlCTS{}
  727. return decodingLayerDecoder(d, data, p)
  728. }
  729. func (m *Dot11CtrlCTS) LayerType() gopacket.LayerType {
  730. return LayerTypeDot11CtrlCTS
  731. }
  732. func (m *Dot11CtrlCTS) CanDecode() gopacket.LayerClass {
  733. return LayerTypeDot11CtrlCTS
  734. }
  735. func (m *Dot11CtrlCTS) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  736. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  737. }
  738. type Dot11CtrlRTS struct {
  739. Dot11Ctrl
  740. }
  741. func decodeDot11CtrlRTS(data []byte, p gopacket.PacketBuilder) error {
  742. d := &Dot11CtrlRTS{}
  743. return decodingLayerDecoder(d, data, p)
  744. }
  745. func (m *Dot11CtrlRTS) LayerType() gopacket.LayerType {
  746. return LayerTypeDot11CtrlRTS
  747. }
  748. func (m *Dot11CtrlRTS) CanDecode() gopacket.LayerClass {
  749. return LayerTypeDot11CtrlRTS
  750. }
  751. func (m *Dot11CtrlRTS) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  752. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  753. }
  754. type Dot11CtrlBlockAckReq struct {
  755. Dot11Ctrl
  756. }
  757. func decodeDot11CtrlBlockAckReq(data []byte, p gopacket.PacketBuilder) error {
  758. d := &Dot11CtrlBlockAckReq{}
  759. return decodingLayerDecoder(d, data, p)
  760. }
  761. func (m *Dot11CtrlBlockAckReq) LayerType() gopacket.LayerType {
  762. return LayerTypeDot11CtrlBlockAckReq
  763. }
  764. func (m *Dot11CtrlBlockAckReq) CanDecode() gopacket.LayerClass {
  765. return LayerTypeDot11CtrlBlockAckReq
  766. }
  767. func (m *Dot11CtrlBlockAckReq) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  768. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  769. }
  770. type Dot11CtrlBlockAck struct {
  771. Dot11Ctrl
  772. }
  773. func decodeDot11CtrlBlockAck(data []byte, p gopacket.PacketBuilder) error {
  774. d := &Dot11CtrlBlockAck{}
  775. return decodingLayerDecoder(d, data, p)
  776. }
  777. func (m *Dot11CtrlBlockAck) LayerType() gopacket.LayerType { return LayerTypeDot11CtrlBlockAck }
  778. func (m *Dot11CtrlBlockAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11CtrlBlockAck }
  779. func (m *Dot11CtrlBlockAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  780. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  781. }
  782. type Dot11CtrlPowersavePoll struct {
  783. Dot11Ctrl
  784. }
  785. func decodeDot11CtrlPowersavePoll(data []byte, p gopacket.PacketBuilder) error {
  786. d := &Dot11CtrlPowersavePoll{}
  787. return decodingLayerDecoder(d, data, p)
  788. }
  789. func (m *Dot11CtrlPowersavePoll) LayerType() gopacket.LayerType {
  790. return LayerTypeDot11CtrlPowersavePoll
  791. }
  792. func (m *Dot11CtrlPowersavePoll) CanDecode() gopacket.LayerClass {
  793. return LayerTypeDot11CtrlPowersavePoll
  794. }
  795. func (m *Dot11CtrlPowersavePoll) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  796. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  797. }
  798. type Dot11CtrlAck struct {
  799. Dot11Ctrl
  800. }
  801. func decodeDot11CtrlAck(data []byte, p gopacket.PacketBuilder) error {
  802. d := &Dot11CtrlAck{}
  803. return decodingLayerDecoder(d, data, p)
  804. }
  805. func (m *Dot11CtrlAck) LayerType() gopacket.LayerType { return LayerTypeDot11CtrlAck }
  806. func (m *Dot11CtrlAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11CtrlAck }
  807. func (m *Dot11CtrlAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  808. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  809. }
  810. type Dot11CtrlCFEnd struct {
  811. Dot11Ctrl
  812. }
  813. func decodeDot11CtrlCFEnd(data []byte, p gopacket.PacketBuilder) error {
  814. d := &Dot11CtrlCFEnd{}
  815. return decodingLayerDecoder(d, data, p)
  816. }
  817. func (m *Dot11CtrlCFEnd) LayerType() gopacket.LayerType {
  818. return LayerTypeDot11CtrlCFEnd
  819. }
  820. func (m *Dot11CtrlCFEnd) CanDecode() gopacket.LayerClass {
  821. return LayerTypeDot11CtrlCFEnd
  822. }
  823. func (m *Dot11CtrlCFEnd) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  824. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  825. }
  826. type Dot11CtrlCFEndAck struct {
  827. Dot11Ctrl
  828. }
  829. func decodeDot11CtrlCFEndAck(data []byte, p gopacket.PacketBuilder) error {
  830. d := &Dot11CtrlCFEndAck{}
  831. return decodingLayerDecoder(d, data, p)
  832. }
  833. func (m *Dot11CtrlCFEndAck) LayerType() gopacket.LayerType {
  834. return LayerTypeDot11CtrlCFEndAck
  835. }
  836. func (m *Dot11CtrlCFEndAck) CanDecode() gopacket.LayerClass {
  837. return LayerTypeDot11CtrlCFEndAck
  838. }
  839. func (m *Dot11CtrlCFEndAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  840. return m.Dot11Ctrl.DecodeFromBytes(data, df)
  841. }
  842. type Dot11MgmtAssociationReq struct {
  843. Dot11Mgmt
  844. CapabilityInfo uint16
  845. ListenInterval uint16
  846. }
  847. func decodeDot11MgmtAssociationReq(data []byte, p gopacket.PacketBuilder) error {
  848. d := &Dot11MgmtAssociationReq{}
  849. return decodingLayerDecoder(d, data, p)
  850. }
  851. func (m *Dot11MgmtAssociationReq) LayerType() gopacket.LayerType {
  852. return LayerTypeDot11MgmtAssociationReq
  853. }
  854. func (m *Dot11MgmtAssociationReq) CanDecode() gopacket.LayerClass {
  855. return LayerTypeDot11MgmtAssociationReq
  856. }
  857. func (m *Dot11MgmtAssociationReq) NextLayerType() gopacket.LayerType {
  858. return LayerTypeDot11InformationElement
  859. }
  860. func (m *Dot11MgmtAssociationReq) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  861. if len(data) < 4 {
  862. df.SetTruncated()
  863. return fmt.Errorf("Dot11MgmtAssociationReq length %v too short, %v required", len(data), 4)
  864. }
  865. m.CapabilityInfo = binary.LittleEndian.Uint16(data[0:2])
  866. m.ListenInterval = binary.LittleEndian.Uint16(data[2:4])
  867. m.Payload = data[4:]
  868. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  869. }
  870. func (m Dot11MgmtAssociationReq) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  871. buf, err := b.PrependBytes(4)
  872. if err != nil {
  873. return err
  874. }
  875. binary.LittleEndian.PutUint16(buf[0:2], m.CapabilityInfo)
  876. binary.LittleEndian.PutUint16(buf[2:4], m.ListenInterval)
  877. return nil
  878. }
  879. type Dot11MgmtAssociationResp struct {
  880. Dot11Mgmt
  881. CapabilityInfo uint16
  882. Status Dot11Status
  883. AID uint16
  884. }
  885. func decodeDot11MgmtAssociationResp(data []byte, p gopacket.PacketBuilder) error {
  886. d := &Dot11MgmtAssociationResp{}
  887. return decodingLayerDecoder(d, data, p)
  888. }
  889. func (m *Dot11MgmtAssociationResp) CanDecode() gopacket.LayerClass {
  890. return LayerTypeDot11MgmtAssociationResp
  891. }
  892. func (m *Dot11MgmtAssociationResp) LayerType() gopacket.LayerType {
  893. return LayerTypeDot11MgmtAssociationResp
  894. }
  895. func (m *Dot11MgmtAssociationResp) NextLayerType() gopacket.LayerType {
  896. return LayerTypeDot11InformationElement
  897. }
  898. func (m *Dot11MgmtAssociationResp) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  899. if len(data) < 6 {
  900. df.SetTruncated()
  901. return fmt.Errorf("Dot11MgmtAssociationResp length %v too short, %v required", len(data), 6)
  902. }
  903. m.CapabilityInfo = binary.LittleEndian.Uint16(data[0:2])
  904. m.Status = Dot11Status(binary.LittleEndian.Uint16(data[2:4]))
  905. m.AID = binary.LittleEndian.Uint16(data[4:6])
  906. m.Payload = data[6:]
  907. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  908. }
  909. func (m Dot11MgmtAssociationResp) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  910. buf, err := b.PrependBytes(6)
  911. if err != nil {
  912. return err
  913. }
  914. binary.LittleEndian.PutUint16(buf[0:2], m.CapabilityInfo)
  915. binary.LittleEndian.PutUint16(buf[2:4], uint16(m.Status))
  916. binary.LittleEndian.PutUint16(buf[4:6], m.AID)
  917. return nil
  918. }
  919. type Dot11MgmtReassociationReq struct {
  920. Dot11Mgmt
  921. CapabilityInfo uint16
  922. ListenInterval uint16
  923. CurrentApAddress net.HardwareAddr
  924. }
  925. func decodeDot11MgmtReassociationReq(data []byte, p gopacket.PacketBuilder) error {
  926. d := &Dot11MgmtReassociationReq{}
  927. return decodingLayerDecoder(d, data, p)
  928. }
  929. func (m *Dot11MgmtReassociationReq) LayerType() gopacket.LayerType {
  930. return LayerTypeDot11MgmtReassociationReq
  931. }
  932. func (m *Dot11MgmtReassociationReq) CanDecode() gopacket.LayerClass {
  933. return LayerTypeDot11MgmtReassociationReq
  934. }
  935. func (m *Dot11MgmtReassociationReq) NextLayerType() gopacket.LayerType {
  936. return LayerTypeDot11InformationElement
  937. }
  938. func (m *Dot11MgmtReassociationReq) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  939. if len(data) < 10 {
  940. df.SetTruncated()
  941. return fmt.Errorf("Dot11MgmtReassociationReq length %v too short, %v required", len(data), 10)
  942. }
  943. m.CapabilityInfo = binary.LittleEndian.Uint16(data[0:2])
  944. m.ListenInterval = binary.LittleEndian.Uint16(data[2:4])
  945. m.CurrentApAddress = net.HardwareAddr(data[4:10])
  946. m.Payload = data[10:]
  947. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  948. }
  949. func (m Dot11MgmtReassociationReq) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  950. buf, err := b.PrependBytes(10)
  951. if err != nil {
  952. return err
  953. }
  954. binary.LittleEndian.PutUint16(buf[0:2], m.CapabilityInfo)
  955. binary.LittleEndian.PutUint16(buf[2:4], m.ListenInterval)
  956. copy(buf[4:10], m.CurrentApAddress)
  957. return nil
  958. }
  959. type Dot11MgmtReassociationResp struct {
  960. Dot11Mgmt
  961. }
  962. func decodeDot11MgmtReassociationResp(data []byte, p gopacket.PacketBuilder) error {
  963. d := &Dot11MgmtReassociationResp{}
  964. return decodingLayerDecoder(d, data, p)
  965. }
  966. func (m *Dot11MgmtReassociationResp) LayerType() gopacket.LayerType {
  967. return LayerTypeDot11MgmtReassociationResp
  968. }
  969. func (m *Dot11MgmtReassociationResp) CanDecode() gopacket.LayerClass {
  970. return LayerTypeDot11MgmtReassociationResp
  971. }
  972. func (m *Dot11MgmtReassociationResp) NextLayerType() gopacket.LayerType {
  973. return LayerTypeDot11InformationElement
  974. }
  975. type Dot11MgmtProbeReq struct {
  976. Dot11Mgmt
  977. }
  978. func decodeDot11MgmtProbeReq(data []byte, p gopacket.PacketBuilder) error {
  979. d := &Dot11MgmtProbeReq{}
  980. return decodingLayerDecoder(d, data, p)
  981. }
  982. func (m *Dot11MgmtProbeReq) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtProbeReq }
  983. func (m *Dot11MgmtProbeReq) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtProbeReq }
  984. func (m *Dot11MgmtProbeReq) NextLayerType() gopacket.LayerType {
  985. return LayerTypeDot11InformationElement
  986. }
  987. type Dot11MgmtProbeResp struct {
  988. Dot11Mgmt
  989. Timestamp uint64
  990. Interval uint16
  991. Flags uint16
  992. }
  993. func decodeDot11MgmtProbeResp(data []byte, p gopacket.PacketBuilder) error {
  994. d := &Dot11MgmtProbeResp{}
  995. return decodingLayerDecoder(d, data, p)
  996. }
  997. func (m *Dot11MgmtProbeResp) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtProbeResp }
  998. func (m *Dot11MgmtProbeResp) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtProbeResp }
  999. func (m *Dot11MgmtProbeResp) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  1000. if len(data) < 12 {
  1001. df.SetTruncated()
  1002. return fmt.Errorf("Dot11MgmtProbeResp length %v too short, %v required", len(data), 12)
  1003. }
  1004. m.Timestamp = binary.LittleEndian.Uint64(data[0:8])
  1005. m.Interval = binary.LittleEndian.Uint16(data[8:10])
  1006. m.Flags = binary.LittleEndian.Uint16(data[10:12])
  1007. m.Payload = data[12:]
  1008. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  1009. }
  1010. func (m *Dot11MgmtProbeResp) NextLayerType() gopacket.LayerType {
  1011. return LayerTypeDot11InformationElement
  1012. }
  1013. func (m Dot11MgmtProbeResp) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  1014. buf, err := b.PrependBytes(12)
  1015. if err != nil {
  1016. return err
  1017. }
  1018. binary.LittleEndian.PutUint64(buf[0:8], m.Timestamp)
  1019. binary.LittleEndian.PutUint16(buf[8:10], m.Interval)
  1020. binary.LittleEndian.PutUint16(buf[10:12], m.Flags)
  1021. return nil
  1022. }
  1023. type Dot11MgmtMeasurementPilot struct {
  1024. Dot11Mgmt
  1025. }
  1026. func decodeDot11MgmtMeasurementPilot(data []byte, p gopacket.PacketBuilder) error {
  1027. d := &Dot11MgmtMeasurementPilot{}
  1028. return decodingLayerDecoder(d, data, p)
  1029. }
  1030. func (m *Dot11MgmtMeasurementPilot) LayerType() gopacket.LayerType {
  1031. return LayerTypeDot11MgmtMeasurementPilot
  1032. }
  1033. func (m *Dot11MgmtMeasurementPilot) CanDecode() gopacket.LayerClass {
  1034. return LayerTypeDot11MgmtMeasurementPilot
  1035. }
  1036. type Dot11MgmtBeacon struct {
  1037. Dot11Mgmt
  1038. Timestamp uint64
  1039. Interval uint16
  1040. Flags uint16
  1041. }
  1042. func decodeDot11MgmtBeacon(data []byte, p gopacket.PacketBuilder) error {
  1043. d := &Dot11MgmtBeacon{}
  1044. return decodingLayerDecoder(d, data, p)
  1045. }
  1046. func (m *Dot11MgmtBeacon) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtBeacon }
  1047. func (m *Dot11MgmtBeacon) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtBeacon }
  1048. func (m *Dot11MgmtBeacon) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  1049. if len(data) < 12 {
  1050. df.SetTruncated()
  1051. return fmt.Errorf("Dot11MgmtBeacon length %v too short, %v required", len(data), 12)
  1052. }
  1053. m.Timestamp = binary.LittleEndian.Uint64(data[0:8])
  1054. m.Interval = binary.LittleEndian.Uint16(data[8:10])
  1055. m.Flags = binary.LittleEndian.Uint16(data[10:12])
  1056. m.Payload = data[12:]
  1057. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  1058. }
  1059. func (m *Dot11MgmtBeacon) NextLayerType() gopacket.LayerType { return LayerTypeDot11InformationElement }
  1060. func (m Dot11MgmtBeacon) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  1061. buf, err := b.PrependBytes(12)
  1062. if err != nil {
  1063. return err
  1064. }
  1065. binary.LittleEndian.PutUint64(buf[0:8], m.Timestamp)
  1066. binary.LittleEndian.PutUint16(buf[8:10], m.Interval)
  1067. binary.LittleEndian.PutUint16(buf[10:12], m.Flags)
  1068. return nil
  1069. }
  1070. type Dot11MgmtATIM struct {
  1071. Dot11Mgmt
  1072. }
  1073. func decodeDot11MgmtATIM(data []byte, p gopacket.PacketBuilder) error {
  1074. d := &Dot11MgmtATIM{}
  1075. return decodingLayerDecoder(d, data, p)
  1076. }
  1077. func (m *Dot11MgmtATIM) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtATIM }
  1078. func (m *Dot11MgmtATIM) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtATIM }
  1079. type Dot11MgmtDisassociation struct {
  1080. Dot11Mgmt
  1081. Reason Dot11Reason
  1082. }
  1083. func decodeDot11MgmtDisassociation(data []byte, p gopacket.PacketBuilder) error {
  1084. d := &Dot11MgmtDisassociation{}
  1085. return decodingLayerDecoder(d, data, p)
  1086. }
  1087. func (m *Dot11MgmtDisassociation) LayerType() gopacket.LayerType {
  1088. return LayerTypeDot11MgmtDisassociation
  1089. }
  1090. func (m *Dot11MgmtDisassociation) CanDecode() gopacket.LayerClass {
  1091. return LayerTypeDot11MgmtDisassociation
  1092. }
  1093. func (m *Dot11MgmtDisassociation) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  1094. if len(data) < 2 {
  1095. df.SetTruncated()
  1096. return fmt.Errorf("Dot11MgmtDisassociation length %v too short, %v required", len(data), 2)
  1097. }
  1098. m.Reason = Dot11Reason(binary.LittleEndian.Uint16(data[0:2]))
  1099. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  1100. }
  1101. func (m Dot11MgmtDisassociation) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  1102. buf, err := b.PrependBytes(2)
  1103. if err != nil {
  1104. return err
  1105. }
  1106. binary.LittleEndian.PutUint16(buf[0:2], uint16(m.Reason))
  1107. return nil
  1108. }
  1109. type Dot11MgmtAuthentication struct {
  1110. Dot11Mgmt
  1111. Algorithm Dot11Algorithm
  1112. Sequence uint16
  1113. Status Dot11Status
  1114. }
  1115. func decodeDot11MgmtAuthentication(data []byte, p gopacket.PacketBuilder) error {
  1116. d := &Dot11MgmtAuthentication{}
  1117. return decodingLayerDecoder(d, data, p)
  1118. }
  1119. func (m *Dot11MgmtAuthentication) LayerType() gopacket.LayerType {
  1120. return LayerTypeDot11MgmtAuthentication
  1121. }
  1122. func (m *Dot11MgmtAuthentication) CanDecode() gopacket.LayerClass {
  1123. return LayerTypeDot11MgmtAuthentication
  1124. }
  1125. func (m *Dot11MgmtAuthentication) NextLayerType() gopacket.LayerType {
  1126. return LayerTypeDot11InformationElement
  1127. }
  1128. func (m *Dot11MgmtAuthentication) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  1129. if len(data) < 6 {
  1130. df.SetTruncated()
  1131. return fmt.Errorf("Dot11MgmtAuthentication length %v too short, %v required", len(data), 6)
  1132. }
  1133. m.Algorithm = Dot11Algorithm(binary.LittleEndian.Uint16(data[0:2]))
  1134. m.Sequence = binary.LittleEndian.Uint16(data[2:4])
  1135. m.Status = Dot11Status(binary.LittleEndian.Uint16(data[4:6]))
  1136. m.Payload = data[6:]
  1137. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  1138. }
  1139. func (m Dot11MgmtAuthentication) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  1140. buf, err := b.PrependBytes(6)
  1141. if err != nil {
  1142. return err
  1143. }
  1144. binary.LittleEndian.PutUint16(buf[0:2], uint16(m.Algorithm))
  1145. binary.LittleEndian.PutUint16(buf[2:4], m.Sequence)
  1146. binary.LittleEndian.PutUint16(buf[4:6], uint16(m.Status))
  1147. return nil
  1148. }
  1149. type Dot11MgmtDeauthentication struct {
  1150. Dot11Mgmt
  1151. Reason Dot11Reason
  1152. }
  1153. func decodeDot11MgmtDeauthentication(data []byte, p gopacket.PacketBuilder) error {
  1154. d := &Dot11MgmtDeauthentication{}
  1155. return decodingLayerDecoder(d, data, p)
  1156. }
  1157. func (m *Dot11MgmtDeauthentication) LayerType() gopacket.LayerType {
  1158. return LayerTypeDot11MgmtDeauthentication
  1159. }
  1160. func (m *Dot11MgmtDeauthentication) CanDecode() gopacket.LayerClass {
  1161. return LayerTypeDot11MgmtDeauthentication
  1162. }
  1163. func (m *Dot11MgmtDeauthentication) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
  1164. if len(data) < 2 {
  1165. df.SetTruncated()
  1166. return fmt.Errorf("Dot11MgmtDeauthentication length %v too short, %v required", len(data), 2)
  1167. }
  1168. m.Reason = Dot11Reason(binary.LittleEndian.Uint16(data[0:2]))
  1169. return m.Dot11Mgmt.DecodeFromBytes(data, df)
  1170. }
  1171. func (m Dot11MgmtDeauthentication) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
  1172. buf, err := b.PrependBytes(2)
  1173. if err != nil {
  1174. return err
  1175. }
  1176. binary.LittleEndian.PutUint16(buf[0:2], uint16(m.Reason))
  1177. return nil
  1178. }
  1179. type Dot11MgmtAction struct {
  1180. Dot11Mgmt
  1181. }
  1182. func decodeDot11MgmtAction(data []byte, p gopacket.PacketBuilder) error {
  1183. d := &Dot11MgmtAction{}
  1184. return decodingLayerDecoder(d, data, p)
  1185. }
  1186. func (m *Dot11MgmtAction) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtAction }
  1187. func (m *Dot11MgmtAction) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtAction }
  1188. type Dot11MgmtActionNoAck struct {
  1189. Dot11Mgmt
  1190. }
  1191. func decodeDot11MgmtActionNoAck(data []byte, p gopacket.PacketBuilder) error {
  1192. d := &Dot11MgmtActionNoAck{}
  1193. return decodingLayerDecoder(d, data, p)
  1194. }
  1195. func (m *Dot11MgmtActionNoAck) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtActionNoAck }
  1196. func (m *Dot11MgmtActionNoAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtActionNoAck }
  1197. type Dot11MgmtArubaWLAN struct {
  1198. Dot11Mgmt
  1199. }
  1200. func decodeDot11MgmtArubaWLAN(data []byte, p gopacket.PacketBuilder) error {
  1201. d := &Dot11MgmtArubaWLAN{}
  1202. return decodingLayerDecoder(d, data, p)
  1203. }
  1204. func (m *Dot11MgmtArubaWLAN) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtArubaWLAN }
  1205. func (m *Dot11MgmtArubaWLAN) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtArubaWLAN }