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 7// See http://standards.ieee.org/findstds/standard/802.11-2012.html for info on 8// all of the layers in this file. 9 10package layers 11 12import ( 13 "bytes" 14 "encoding/binary" 15 "fmt" 16 "hash/crc32" 17 "net" 18 19 "github.com/google/gopacket" 20) 21 22// Dot11Flags contains the set of 8 flags in the IEEE 802.11 frame control 23// header, all in one place. 24type Dot11Flags uint8 25 26const ( 27 Dot11FlagsToDS Dot11Flags = 1 << iota 28 Dot11FlagsFromDS 29 Dot11FlagsMF 30 Dot11FlagsRetry 31 Dot11FlagsPowerManagement 32 Dot11FlagsMD 33 Dot11FlagsWEP 34 Dot11FlagsOrder 35) 36 37func (d Dot11Flags) ToDS() bool { 38 return d&Dot11FlagsToDS != 0 39} 40func (d Dot11Flags) FromDS() bool { 41 return d&Dot11FlagsFromDS != 0 42} 43func (d Dot11Flags) MF() bool { 44 return d&Dot11FlagsMF != 0 45} 46func (d Dot11Flags) Retry() bool { 47 return d&Dot11FlagsRetry != 0 48} 49func (d Dot11Flags) PowerManagement() bool { 50 return d&Dot11FlagsPowerManagement != 0 51} 52func (d Dot11Flags) MD() bool { 53 return d&Dot11FlagsMD != 0 54} 55func (d Dot11Flags) WEP() bool { 56 return d&Dot11FlagsWEP != 0 57} 58func (d Dot11Flags) Order() bool { 59 return d&Dot11FlagsOrder != 0 60} 61 62// String provides a human readable string for Dot11Flags. 63// This string is possibly subject to change over time; if you're storing this 64// persistently, you should probably store the Dot11Flags value, not its string. 65func (a Dot11Flags) String() string { 66 var out bytes.Buffer 67 if a.ToDS() { 68 out.WriteString("TO-DS,") 69 } 70 if a.FromDS() { 71 out.WriteString("FROM-DS,") 72 } 73 if a.MF() { 74 out.WriteString("MF,") 75 } 76 if a.Retry() { 77 out.WriteString("Retry,") 78 } 79 if a.PowerManagement() { 80 out.WriteString("PowerManagement,") 81 } 82 if a.MD() { 83 out.WriteString("MD,") 84 } 85 if a.WEP() { 86 out.WriteString("WEP,") 87 } 88 if a.Order() { 89 out.WriteString("Order,") 90 } 91 92 if length := out.Len(); length > 0 { 93 return string(out.Bytes()[:length-1]) // strip final comma 94 } 95 return "" 96} 97 98type Dot11Reason uint16 99 100// TODO: Verify these reasons, and append more reasons if necessary. 101 102const ( 103 Dot11ReasonReserved Dot11Reason = 1 104 Dot11ReasonUnspecified Dot11Reason = 2 105 Dot11ReasonAuthExpired Dot11Reason = 3 106 Dot11ReasonDeauthStLeaving Dot11Reason = 4 107 Dot11ReasonInactivity Dot11Reason = 5 108 Dot11ReasonApFull Dot11Reason = 6 109 Dot11ReasonClass2FromNonAuth Dot11Reason = 7 110 Dot11ReasonClass3FromNonAss Dot11Reason = 8 111 Dot11ReasonDisasStLeaving Dot11Reason = 9 112 Dot11ReasonStNotAuth Dot11Reason = 10 113) 114 115// String provides a human readable string for Dot11Reason. 116// This string is possibly subject to change over time; if you're storing this 117// persistently, you should probably store the Dot11Reason value, not its string. 118func (a Dot11Reason) String() string { 119 switch a { 120 case Dot11ReasonReserved: 121 return "Reserved" 122 case Dot11ReasonUnspecified: 123 return "Unspecified" 124 case Dot11ReasonAuthExpired: 125 return "Auth. expired" 126 case Dot11ReasonDeauthStLeaving: 127 return "Deauth. st. leaving" 128 case Dot11ReasonInactivity: 129 return "Inactivity" 130 case Dot11ReasonApFull: 131 return "Ap. full" 132 case Dot11ReasonClass2FromNonAuth: 133 return "Class2 from non auth." 134 case Dot11ReasonClass3FromNonAss: 135 return "Class3 from non ass." 136 case Dot11ReasonDisasStLeaving: 137 return "Disass st. leaving" 138 case Dot11ReasonStNotAuth: 139 return "St. not auth." 140 default: 141 return "Unknown reason" 142 } 143} 144 145type Dot11Status uint16 146 147const ( 148 Dot11StatusSuccess Dot11Status = 0 149 Dot11StatusFailure Dot11Status = 1 // Unspecified failure 150 Dot11StatusCannotSupportAllCapabilities Dot11Status = 10 // Cannot support all requested capabilities in the Capability Information field 151 Dot11StatusInabilityExistsAssociation Dot11Status = 11 // Reassociation denied due to inability to confirm that association exists 152 Dot11StatusAssociationDenied Dot11Status = 12 // Association denied due to reason outside the scope of this standard 153 Dot11StatusAlgorithmUnsupported Dot11Status = 13 // Responding station does not support the specified authentication algorithm 154 Dot11StatusOufOfExpectedSequence Dot11Status = 14 // Received an Authentication frame with authentication transaction sequence number out of expected sequence 155 Dot11StatusChallengeFailure Dot11Status = 15 // Authentication rejected because of challenge failure 156 Dot11StatusTimeout Dot11Status = 16 // Authentication rejected due to timeout waiting for next frame in sequence 157 Dot11StatusAPUnableToHandle Dot11Status = 17 // Association denied because AP is unable to handle additional associated stations 158 Dot11StatusRateUnsupported Dot11Status = 18 // Association denied due to requesting station not supporting all of the data rates in the BSSBasicRateSet parameter 159) 160 161// String provides a human readable string for Dot11Status. 162// This string is possibly subject to change over time; if you're storing this 163// persistently, you should probably store the Dot11Status value, not its string. 164func (a Dot11Status) String() string { 165 switch a { 166 case Dot11StatusSuccess: 167 return "success" 168 case Dot11StatusFailure: 169 return "failure" 170 case Dot11StatusCannotSupportAllCapabilities: 171 return "cannot-support-all-capabilities" 172 case Dot11StatusInabilityExistsAssociation: 173 return "inability-exists-association" 174 case Dot11StatusAssociationDenied: 175 return "association-denied" 176 case Dot11StatusAlgorithmUnsupported: 177 return "algorithm-unsupported" 178 case Dot11StatusOufOfExpectedSequence: 179 return "out-of-expected-sequence" 180 case Dot11StatusChallengeFailure: 181 return "challenge-failure" 182 case Dot11StatusTimeout: 183 return "timeout" 184 case Dot11StatusAPUnableToHandle: 185 return "ap-unable-to-handle" 186 case Dot11StatusRateUnsupported: 187 return "rate-unsupported" 188 default: 189 return "unknown status" 190 } 191} 192 193type Dot11AckPolicy uint8 194 195const ( 196 Dot11AckPolicyNormal Dot11AckPolicy = 0 197 Dot11AckPolicyNone Dot11AckPolicy = 1 198 Dot11AckPolicyNoExplicit Dot11AckPolicy = 2 199 Dot11AckPolicyBlock Dot11AckPolicy = 3 200) 201 202// String provides a human readable string for Dot11AckPolicy. 203// This string is possibly subject to change over time; if you're storing this 204// persistently, you should probably store the Dot11AckPolicy value, not its string. 205func (a Dot11AckPolicy) String() string { 206 switch a { 207 case Dot11AckPolicyNormal: 208 return "normal-ack" 209 case Dot11AckPolicyNone: 210 return "no-ack" 211 case Dot11AckPolicyNoExplicit: 212 return "no-explicit-ack" 213 case Dot11AckPolicyBlock: 214 return "block-ack" 215 default: 216 return "unknown-ack-policy" 217 } 218} 219 220type Dot11Algorithm uint16 221 222const ( 223 Dot11AlgorithmOpen Dot11Algorithm = 0 224 Dot11AlgorithmSharedKey Dot11Algorithm = 1 225) 226 227// String provides a human readable string for Dot11Algorithm. 228// This string is possibly subject to change over time; if you're storing this 229// persistently, you should probably store the Dot11Algorithm value, not its string. 230func (a Dot11Algorithm) String() string { 231 switch a { 232 case Dot11AlgorithmOpen: 233 return "open" 234 case Dot11AlgorithmSharedKey: 235 return "shared-key" 236 default: 237 return "unknown-algorithm" 238 } 239} 240 241type Dot11InformationElementID uint8 242 243const ( 244 Dot11InformationElementIDSSID Dot11InformationElementID = 0 245 Dot11InformationElementIDRates Dot11InformationElementID = 1 246 Dot11InformationElementIDFHSet Dot11InformationElementID = 2 247 Dot11InformationElementIDDSSet Dot11InformationElementID = 3 248 Dot11InformationElementIDCFSet Dot11InformationElementID = 4 249 Dot11InformationElementIDTIM Dot11InformationElementID = 5 250 Dot11InformationElementIDIBSSSet Dot11InformationElementID = 6 251 Dot11InformationElementIDCountryInfo Dot11InformationElementID = 7 252 Dot11InformationElementIDHoppingPatternParam Dot11InformationElementID = 8 253 Dot11InformationElementIDHoppingPatternTable Dot11InformationElementID = 9 254 Dot11InformationElementIDRequest Dot11InformationElementID = 10 255 Dot11InformationElementIDQBSSLoadElem Dot11InformationElementID = 11 256 Dot11InformationElementIDEDCAParamSet Dot11InformationElementID = 12 257 Dot11InformationElementIDTrafficSpec Dot11InformationElementID = 13 258 Dot11InformationElementIDTrafficClass Dot11InformationElementID = 14 259 Dot11InformationElementIDSchedule Dot11InformationElementID = 15 260 Dot11InformationElementIDChallenge Dot11InformationElementID = 16 261 Dot11InformationElementIDPowerConst Dot11InformationElementID = 32 262 Dot11InformationElementIDPowerCapability Dot11InformationElementID = 33 263 Dot11InformationElementIDTPCRequest Dot11InformationElementID = 34 264 Dot11InformationElementIDTPCReport Dot11InformationElementID = 35 265 Dot11InformationElementIDSupportedChannels Dot11InformationElementID = 36 266 Dot11InformationElementIDSwitchChannelAnnounce Dot11InformationElementID = 37 267 Dot11InformationElementIDMeasureRequest Dot11InformationElementID = 38 268 Dot11InformationElementIDMeasureReport Dot11InformationElementID = 39 269 Dot11InformationElementIDQuiet Dot11InformationElementID = 40 270 Dot11InformationElementIDIBSSDFS Dot11InformationElementID = 41 271 Dot11InformationElementIDERPInfo Dot11InformationElementID = 42 272 Dot11InformationElementIDTSDelay Dot11InformationElementID = 43 273 Dot11InformationElementIDTCLASProcessing Dot11InformationElementID = 44 274 Dot11InformationElementIDHTCapabilities Dot11InformationElementID = 45 275 Dot11InformationElementIDQOSCapability Dot11InformationElementID = 46 276 Dot11InformationElementIDERPInfo2 Dot11InformationElementID = 47 277 Dot11InformationElementIDRSNInfo Dot11InformationElementID = 48 278 Dot11InformationElementIDESRates Dot11InformationElementID = 50 279 Dot11InformationElementIDAPChannelReport Dot11InformationElementID = 51 280 Dot11InformationElementIDNeighborReport Dot11InformationElementID = 52 281 Dot11InformationElementIDRCPI Dot11InformationElementID = 53 282 Dot11InformationElementIDMobilityDomain Dot11InformationElementID = 54 283 Dot11InformationElementIDFastBSSTrans Dot11InformationElementID = 55 284 Dot11InformationElementIDTimeoutInt Dot11InformationElementID = 56 285 Dot11InformationElementIDRICData Dot11InformationElementID = 57 286 Dot11InformationElementIDDSERegisteredLoc Dot11InformationElementID = 58 287 Dot11InformationElementIDSuppOperatingClass Dot11InformationElementID = 59 288 Dot11InformationElementIDExtChanSwitchAnnounce Dot11InformationElementID = 60 289 Dot11InformationElementIDHTInfo Dot11InformationElementID = 61 290 Dot11InformationElementIDSecChanOffset Dot11InformationElementID = 62 291 Dot11InformationElementIDBSSAverageAccessDelay Dot11InformationElementID = 63 292 Dot11InformationElementIDAntenna Dot11InformationElementID = 64 293 Dot11InformationElementIDRSNI Dot11InformationElementID = 65 294 Dot11InformationElementIDMeasurePilotTrans Dot11InformationElementID = 66 295 Dot11InformationElementIDBSSAvailAdmCapacity Dot11InformationElementID = 67 296 Dot11InformationElementIDBSSACAccDelayWAPIParam Dot11InformationElementID = 68 297 Dot11InformationElementIDTimeAdvertisement Dot11InformationElementID = 69 298 Dot11InformationElementIDRMEnabledCapabilities Dot11InformationElementID = 70 299 Dot11InformationElementIDMultipleBSSID Dot11InformationElementID = 71 300 Dot11InformationElementID2040BSSCoExist Dot11InformationElementID = 72 301 Dot11InformationElementID2040BSSIntChanReport Dot11InformationElementID = 73 302 Dot11InformationElementIDOverlapBSSScanParam Dot11InformationElementID = 74 303 Dot11InformationElementIDRICDescriptor Dot11InformationElementID = 75 304 Dot11InformationElementIDManagementMIC Dot11InformationElementID = 76 305 Dot11InformationElementIDEventRequest Dot11InformationElementID = 78 306 Dot11InformationElementIDEventReport Dot11InformationElementID = 79 307 Dot11InformationElementIDDiagnosticRequest Dot11InformationElementID = 80 308 Dot11InformationElementIDDiagnosticReport Dot11InformationElementID = 81 309 Dot11InformationElementIDLocationParam Dot11InformationElementID = 82 310 Dot11InformationElementIDNonTransBSSIDCapability Dot11InformationElementID = 83 311 Dot11InformationElementIDSSIDList Dot11InformationElementID = 84 312 Dot11InformationElementIDMultipleBSSIDIndex Dot11InformationElementID = 85 313 Dot11InformationElementIDFMSDescriptor Dot11InformationElementID = 86 314 Dot11InformationElementIDFMSRequest Dot11InformationElementID = 87 315 Dot11InformationElementIDFMSResponse Dot11InformationElementID = 88 316 Dot11InformationElementIDQOSTrafficCapability Dot11InformationElementID = 89 317 Dot11InformationElementIDBSSMaxIdlePeriod Dot11InformationElementID = 90 318 Dot11InformationElementIDTFSRequest Dot11InformationElementID = 91 319 Dot11InformationElementIDTFSResponse Dot11InformationElementID = 92 320 Dot11InformationElementIDWNMSleepMode Dot11InformationElementID = 93 321 Dot11InformationElementIDTIMBroadcastRequest Dot11InformationElementID = 94 322 Dot11InformationElementIDTIMBroadcastResponse Dot11InformationElementID = 95 323 Dot11InformationElementIDCollInterferenceReport Dot11InformationElementID = 96 324 Dot11InformationElementIDChannelUsage Dot11InformationElementID = 97 325 Dot11InformationElementIDTimeZone Dot11InformationElementID = 98 326 Dot11InformationElementIDDMSRequest Dot11InformationElementID = 99 327 Dot11InformationElementIDDMSResponse Dot11InformationElementID = 100 328 Dot11InformationElementIDLinkIdentifier Dot11InformationElementID = 101 329 Dot11InformationElementIDWakeupSchedule Dot11InformationElementID = 102 330 Dot11InformationElementIDChannelSwitchTiming Dot11InformationElementID = 104 331 Dot11InformationElementIDPTIControl Dot11InformationElementID = 105 332 Dot11InformationElementIDPUBufferStatus Dot11InformationElementID = 106 333 Dot11InformationElementIDInterworking Dot11InformationElementID = 107 334 Dot11InformationElementIDAdvertisementProtocol Dot11InformationElementID = 108 335 Dot11InformationElementIDExpBWRequest Dot11InformationElementID = 109 336 Dot11InformationElementIDQOSMapSet Dot11InformationElementID = 110 337 Dot11InformationElementIDRoamingConsortium Dot11InformationElementID = 111 338 Dot11InformationElementIDEmergencyAlertIdentifier Dot11InformationElementID = 112 339 Dot11InformationElementIDMeshConfiguration Dot11InformationElementID = 113 340 Dot11InformationElementIDMeshID Dot11InformationElementID = 114 341 Dot11InformationElementIDMeshLinkMetricReport Dot11InformationElementID = 115 342 Dot11InformationElementIDCongestionNotification Dot11InformationElementID = 116 343 Dot11InformationElementIDMeshPeeringManagement Dot11InformationElementID = 117 344 Dot11InformationElementIDMeshChannelSwitchParam Dot11InformationElementID = 118 345 Dot11InformationElementIDMeshAwakeWindows Dot11InformationElementID = 119 346 Dot11InformationElementIDBeaconTiming Dot11InformationElementID = 120 347 Dot11InformationElementIDMCCAOPSetupRequest Dot11InformationElementID = 121 348 Dot11InformationElementIDMCCAOPSetupReply Dot11InformationElementID = 122 349 Dot11InformationElementIDMCCAOPAdvertisement Dot11InformationElementID = 123 350 Dot11InformationElementIDMCCAOPTeardown Dot11InformationElementID = 124 351 Dot11InformationElementIDGateAnnouncement Dot11InformationElementID = 125 352 Dot11InformationElementIDRootAnnouncement Dot11InformationElementID = 126 353 Dot11InformationElementIDExtCapability Dot11InformationElementID = 127 354 Dot11InformationElementIDAgereProprietary Dot11InformationElementID = 128 355 Dot11InformationElementIDPathRequest Dot11InformationElementID = 130 356 Dot11InformationElementIDPathReply Dot11InformationElementID = 131 357 Dot11InformationElementIDPathError Dot11InformationElementID = 132 358 Dot11InformationElementIDCiscoCCX1CKIPDeviceName Dot11InformationElementID = 133 359 Dot11InformationElementIDCiscoCCX2 Dot11InformationElementID = 136 360 Dot11InformationElementIDProxyUpdate Dot11InformationElementID = 137 361 Dot11InformationElementIDProxyUpdateConfirmation Dot11InformationElementID = 138 362 Dot11InformationElementIDAuthMeshPerringExch Dot11InformationElementID = 139 363 Dot11InformationElementIDMIC Dot11InformationElementID = 140 364 Dot11InformationElementIDDestinationURI Dot11InformationElementID = 141 365 Dot11InformationElementIDUAPSDCoexistence Dot11InformationElementID = 142 366 Dot11InformationElementIDWakeupSchedule80211ad Dot11InformationElementID = 143 367 Dot11InformationElementIDExtendedSchedule Dot11InformationElementID = 144 368 Dot11InformationElementIDSTAAvailability Dot11InformationElementID = 145 369 Dot11InformationElementIDDMGTSPEC Dot11InformationElementID = 146 370 Dot11InformationElementIDNextDMGATI Dot11InformationElementID = 147 371 Dot11InformationElementIDDMSCapabilities Dot11InformationElementID = 148 372 Dot11InformationElementIDCiscoUnknown95 Dot11InformationElementID = 149 373 Dot11InformationElementIDVendor2 Dot11InformationElementID = 150 374 Dot11InformationElementIDDMGOperating Dot11InformationElementID = 151 375 Dot11InformationElementIDDMGBSSParamChange Dot11InformationElementID = 152 376 Dot11InformationElementIDDMGBeamRefinement Dot11InformationElementID = 153 377 Dot11InformationElementIDChannelMeasFeedback Dot11InformationElementID = 154 378 Dot11InformationElementIDAwakeWindow Dot11InformationElementID = 157 379 Dot11InformationElementIDMultiBand Dot11InformationElementID = 158 380 Dot11InformationElementIDADDBAExtension Dot11InformationElementID = 159 381 Dot11InformationElementIDNEXTPCPList Dot11InformationElementID = 160 382 Dot11InformationElementIDPCPHandover Dot11InformationElementID = 161 383 Dot11InformationElementIDDMGLinkMargin Dot11InformationElementID = 162 384 Dot11InformationElementIDSwitchingStream Dot11InformationElementID = 163 385 Dot11InformationElementIDSessionTransmission Dot11InformationElementID = 164 386 Dot11InformationElementIDDynamicTonePairReport Dot11InformationElementID = 165 387 Dot11InformationElementIDClusterReport Dot11InformationElementID = 166 388 Dot11InformationElementIDRelayCapabilities Dot11InformationElementID = 167 389 Dot11InformationElementIDRelayTransferParameter Dot11InformationElementID = 168 390 Dot11InformationElementIDBeamlinkMaintenance Dot11InformationElementID = 169 391 Dot11InformationElementIDMultipleMacSublayers Dot11InformationElementID = 170 392 Dot11InformationElementIDUPID Dot11InformationElementID = 171 393 Dot11InformationElementIDDMGLinkAdaptionAck Dot11InformationElementID = 172 394 Dot11InformationElementIDSymbolProprietary Dot11InformationElementID = 173 395 Dot11InformationElementIDMCCAOPAdvertOverview Dot11InformationElementID = 174 396 Dot11InformationElementIDQuietPeriodRequest Dot11InformationElementID = 175 397 Dot11InformationElementIDQuietPeriodResponse Dot11InformationElementID = 177 398 Dot11InformationElementIDECPACPolicy Dot11InformationElementID = 182 399 Dot11InformationElementIDClusterTimeOffset Dot11InformationElementID = 183 400 Dot11InformationElementIDAntennaSectorID Dot11InformationElementID = 190 401 Dot11InformationElementIDVHTCapabilities Dot11InformationElementID = 191 402 Dot11InformationElementIDVHTOperation Dot11InformationElementID = 192 403 Dot11InformationElementIDExtendedBSSLoad Dot11InformationElementID = 193 404 Dot11InformationElementIDWideBWChannelSwitch Dot11InformationElementID = 194 405 Dot11InformationElementIDVHTTxPowerEnvelope Dot11InformationElementID = 195 406 Dot11InformationElementIDChannelSwitchWrapper Dot11InformationElementID = 196 407 Dot11InformationElementIDOperatingModeNotification Dot11InformationElementID = 199 408 Dot11InformationElementIDUPSIM Dot11InformationElementID = 200 409 Dot11InformationElementIDReducedNeighborReport Dot11InformationElementID = 201 410 Dot11InformationElementIDTVHTOperation Dot11InformationElementID = 202 411 Dot11InformationElementIDDeviceLocation Dot11InformationElementID = 204 412 Dot11InformationElementIDWhiteSpaceMap Dot11InformationElementID = 205 413 Dot11InformationElementIDFineTuningMeasureParams Dot11InformationElementID = 206 414 Dot11InformationElementIDVendor Dot11InformationElementID = 221 415) 416 417// String provides a human readable string for Dot11InformationElementID. 418// This string is possibly subject to change over time; if you're storing this 419// persistently, you should probably store the Dot11InformationElementID value, 420// not its string. 421func (a Dot11InformationElementID) String() string { 422 switch a { 423 case Dot11InformationElementIDSSID: 424 return "SSID parameter set" 425 case Dot11InformationElementIDRates: 426 return "Supported Rates" 427 case Dot11InformationElementIDFHSet: 428 return "FH Parameter set" 429 case Dot11InformationElementIDDSSet: 430 return "DS Parameter set" 431 case Dot11InformationElementIDCFSet: 432 return "CF Parameter set" 433 case Dot11InformationElementIDTIM: 434 return "Traffic Indication Map (TIM)" 435 case Dot11InformationElementIDIBSSSet: 436 return "IBSS Parameter set" 437 case Dot11InformationElementIDCountryInfo: 438 return "Country Information" 439 case Dot11InformationElementIDHoppingPatternParam: 440 return "Hopping Pattern Parameters" 441 case Dot11InformationElementIDHoppingPatternTable: 442 return "Hopping Pattern Table" 443 case Dot11InformationElementIDRequest: 444 return "Request" 445 case Dot11InformationElementIDQBSSLoadElem: 446 return "QBSS Load Element" 447 case Dot11InformationElementIDEDCAParamSet: 448 return "EDCA Parameter Set" 449 case Dot11InformationElementIDTrafficSpec: 450 return "Traffic Specification" 451 case Dot11InformationElementIDTrafficClass: 452 return "Traffic Classification" 453 case Dot11InformationElementIDSchedule: 454 return "Schedule" 455 case Dot11InformationElementIDChallenge: 456 return "Challenge text" 457 case Dot11InformationElementIDPowerConst: 458 return "Power Constraint" 459 case Dot11InformationElementIDPowerCapability: 460 return "Power Capability" 461 case Dot11InformationElementIDTPCRequest: 462 return "TPC Request" 463 case Dot11InformationElementIDTPCReport: 464 return "TPC Report" 465 case Dot11InformationElementIDSupportedChannels: 466 return "Supported Channels" 467 case Dot11InformationElementIDSwitchChannelAnnounce: 468 return "Channel Switch Announcement" 469 case Dot11InformationElementIDMeasureRequest: 470 return "Measurement Request" 471 case Dot11InformationElementIDMeasureReport: 472 return "Measurement Report" 473 case Dot11InformationElementIDQuiet: 474 return "Quiet" 475 case Dot11InformationElementIDIBSSDFS: 476 return "IBSS DFS" 477 case Dot11InformationElementIDERPInfo: 478 return "ERP Information" 479 case Dot11InformationElementIDTSDelay: 480 return "TS Delay" 481 case Dot11InformationElementIDTCLASProcessing: 482 return "TCLAS Processing" 483 case Dot11InformationElementIDHTCapabilities: 484 return "HT Capabilities (802.11n D1.10)" 485 case Dot11InformationElementIDQOSCapability: 486 return "QOS Capability" 487 case Dot11InformationElementIDERPInfo2: 488 return "ERP Information-2" 489 case Dot11InformationElementIDRSNInfo: 490 return "RSN Information" 491 case Dot11InformationElementIDESRates: 492 return "Extended Supported Rates" 493 case Dot11InformationElementIDAPChannelReport: 494 return "AP Channel Report" 495 case Dot11InformationElementIDNeighborReport: 496 return "Neighbor Report" 497 case Dot11InformationElementIDRCPI: 498 return "RCPI" 499 case Dot11InformationElementIDMobilityDomain: 500 return "Mobility Domain" 501 case Dot11InformationElementIDFastBSSTrans: 502 return "Fast BSS Transition" 503 case Dot11InformationElementIDTimeoutInt: 504 return "Timeout Interval" 505 case Dot11InformationElementIDRICData: 506 return "RIC Data" 507 case Dot11InformationElementIDDSERegisteredLoc: 508 return "DSE Registered Location" 509 case Dot11InformationElementIDSuppOperatingClass: 510 return "Supported Operating Classes" 511 case Dot11InformationElementIDExtChanSwitchAnnounce: 512 return "Extended Channel Switch Announcement" 513 case Dot11InformationElementIDHTInfo: 514 return "HT Information (802.11n D1.10)" 515 case Dot11InformationElementIDSecChanOffset: 516 return "Secondary Channel Offset (802.11n D1.10)" 517 case Dot11InformationElementIDBSSAverageAccessDelay: 518 return "BSS Average Access Delay" 519 case Dot11InformationElementIDAntenna: 520 return "Antenna" 521 case Dot11InformationElementIDRSNI: 522 return "RSNI" 523 case Dot11InformationElementIDMeasurePilotTrans: 524 return "Measurement Pilot Transmission" 525 case Dot11InformationElementIDBSSAvailAdmCapacity: 526 return "BSS Available Admission Capacity" 527 case Dot11InformationElementIDBSSACAccDelayWAPIParam: 528 return "BSS AC Access Delay/WAPI Parameter Set" 529 case Dot11InformationElementIDTimeAdvertisement: 530 return "Time Advertisement" 531 case Dot11InformationElementIDRMEnabledCapabilities: 532 return "RM Enabled Capabilities" 533 case Dot11InformationElementIDMultipleBSSID: 534 return "Multiple BSSID" 535 case Dot11InformationElementID2040BSSCoExist: 536 return "20/40 BSS Coexistence" 537 case Dot11InformationElementID2040BSSIntChanReport: 538 return "20/40 BSS Intolerant Channel Report" 539 case Dot11InformationElementIDOverlapBSSScanParam: 540 return "Overlapping BSS Scan Parameters" 541 case Dot11InformationElementIDRICDescriptor: 542 return "RIC Descriptor" 543 case Dot11InformationElementIDManagementMIC: 544 return "Management MIC" 545 case Dot11InformationElementIDEventRequest: 546 return "Event Request" 547 case Dot11InformationElementIDEventReport: 548 return "Event Report" 549 case Dot11InformationElementIDDiagnosticRequest: 550 return "Diagnostic Request" 551 case Dot11InformationElementIDDiagnosticReport: 552 return "Diagnostic Report" 553 case Dot11InformationElementIDLocationParam: 554 return "Location Parameters" 555 case Dot11InformationElementIDNonTransBSSIDCapability: 556 return "Non Transmitted BSSID Capability" 557 case Dot11InformationElementIDSSIDList: 558 return "SSID List" 559 case Dot11InformationElementIDMultipleBSSIDIndex: 560 return "Multiple BSSID Index" 561 case Dot11InformationElementIDFMSDescriptor: 562 return "FMS Descriptor" 563 case Dot11InformationElementIDFMSRequest: 564 return "FMS Request" 565 case Dot11InformationElementIDFMSResponse: 566 return "FMS Response" 567 case Dot11InformationElementIDQOSTrafficCapability: 568 return "QoS Traffic Capability" 569 case Dot11InformationElementIDBSSMaxIdlePeriod: 570 return "BSS Max Idle Period" 571 case Dot11InformationElementIDTFSRequest: 572 return "TFS Request" 573 case Dot11InformationElementIDTFSResponse: 574 return "TFS Response" 575 case Dot11InformationElementIDWNMSleepMode: 576 return "WNM-Sleep Mode" 577 case Dot11InformationElementIDTIMBroadcastRequest: 578 return "TIM Broadcast Request" 579 case Dot11InformationElementIDTIMBroadcastResponse: 580 return "TIM Broadcast Response" 581 case Dot11InformationElementIDCollInterferenceReport: 582 return "Collocated Interference Report" 583 case Dot11InformationElementIDChannelUsage: 584 return "Channel Usage" 585 case Dot11InformationElementIDTimeZone: 586 return "Time Zone" 587 case Dot11InformationElementIDDMSRequest: 588 return "DMS Request" 589 case Dot11InformationElementIDDMSResponse: 590 return "DMS Response" 591 case Dot11InformationElementIDLinkIdentifier: 592 return "Link Identifier" 593 case Dot11InformationElementIDWakeupSchedule: 594 return "Wakeup Schedule" 595 case Dot11InformationElementIDChannelSwitchTiming: 596 return "Channel Switch Timing" 597 case Dot11InformationElementIDPTIControl: 598 return "PTI Control" 599 case Dot11InformationElementIDPUBufferStatus: 600 return "PU Buffer Status" 601 case Dot11InformationElementIDInterworking: 602 return "Interworking" 603 case Dot11InformationElementIDAdvertisementProtocol: 604 return "Advertisement Protocol" 605 case Dot11InformationElementIDExpBWRequest: 606 return "Expedited Bandwidth Request" 607 case Dot11InformationElementIDQOSMapSet: 608 return "QoS Map Set" 609 case Dot11InformationElementIDRoamingConsortium: 610 return "Roaming Consortium" 611 case Dot11InformationElementIDEmergencyAlertIdentifier: 612 return "Emergency Alert Identifier" 613 case Dot11InformationElementIDMeshConfiguration: 614 return "Mesh Configuration" 615 case Dot11InformationElementIDMeshID: 616 return "Mesh ID" 617 case Dot11InformationElementIDMeshLinkMetricReport: 618 return "Mesh Link Metric Report" 619 case Dot11InformationElementIDCongestionNotification: 620 return "Congestion Notification" 621 case Dot11InformationElementIDMeshPeeringManagement: 622 return "Mesh Peering Management" 623 case Dot11InformationElementIDMeshChannelSwitchParam: 624 return "Mesh Channel Switch Parameters" 625 case Dot11InformationElementIDMeshAwakeWindows: 626 return "Mesh Awake Windows" 627 case Dot11InformationElementIDBeaconTiming: 628 return "Beacon Timing" 629 case Dot11InformationElementIDMCCAOPSetupRequest: 630 return "MCCAOP Setup Request" 631 case Dot11InformationElementIDMCCAOPSetupReply: 632 return "MCCAOP SETUP Reply" 633 case Dot11InformationElementIDMCCAOPAdvertisement: 634 return "MCCAOP Advertisement" 635 case Dot11InformationElementIDMCCAOPTeardown: 636 return "MCCAOP Teardown" 637 case Dot11InformationElementIDGateAnnouncement: 638 return "Gate Announcement" 639 case Dot11InformationElementIDRootAnnouncement: 640 return "Root Announcement" 641 case Dot11InformationElementIDExtCapability: 642 return "Extended Capabilities" 643 case Dot11InformationElementIDAgereProprietary: 644 return "Agere Proprietary" 645 case Dot11InformationElementIDPathRequest: 646 return "Path Request" 647 case Dot11InformationElementIDPathReply: 648 return "Path Reply" 649 case Dot11InformationElementIDPathError: 650 return "Path Error" 651 case Dot11InformationElementIDCiscoCCX1CKIPDeviceName: 652 return "Cisco CCX1 CKIP + Device Name" 653 case Dot11InformationElementIDCiscoCCX2: 654 return "Cisco CCX2" 655 case Dot11InformationElementIDProxyUpdate: 656 return "Proxy Update" 657 case Dot11InformationElementIDProxyUpdateConfirmation: 658 return "Proxy Update Confirmation" 659 case Dot11InformationElementIDAuthMeshPerringExch: 660 return "Auhenticated Mesh Perring Exchange" 661 case Dot11InformationElementIDMIC: 662 return "MIC (Message Integrity Code)" 663 case Dot11InformationElementIDDestinationURI: 664 return "Destination URI" 665 case Dot11InformationElementIDUAPSDCoexistence: 666 return "U-APSD Coexistence" 667 case Dot11InformationElementIDWakeupSchedule80211ad: 668 return "Wakeup Schedule 802.11ad" 669 case Dot11InformationElementIDExtendedSchedule: 670 return "Extended Schedule" 671 case Dot11InformationElementIDSTAAvailability: 672 return "STA Availability" 673 case Dot11InformationElementIDDMGTSPEC: 674 return "DMG TSPEC" 675 case Dot11InformationElementIDNextDMGATI: 676 return "Next DMG ATI" 677 case Dot11InformationElementIDDMSCapabilities: 678 return "DMG Capabilities" 679 case Dot11InformationElementIDCiscoUnknown95: 680 return "Cisco Unknown 95" 681 case Dot11InformationElementIDVendor2: 682 return "Vendor Specific" 683 case Dot11InformationElementIDDMGOperating: 684 return "DMG Operating" 685 case Dot11InformationElementIDDMGBSSParamChange: 686 return "DMG BSS Parameter Change" 687 case Dot11InformationElementIDDMGBeamRefinement: 688 return "DMG Beam Refinement" 689 case Dot11InformationElementIDChannelMeasFeedback: 690 return "Channel Measurement Feedback" 691 case Dot11InformationElementIDAwakeWindow: 692 return "Awake Window" 693 case Dot11InformationElementIDMultiBand: 694 return "Multi Band" 695 case Dot11InformationElementIDADDBAExtension: 696 return "ADDBA Extension" 697 case Dot11InformationElementIDNEXTPCPList: 698 return "NEXTPCP List" 699 case Dot11InformationElementIDPCPHandover: 700 return "PCP Handover" 701 case Dot11InformationElementIDDMGLinkMargin: 702 return "DMG Link Margin" 703 case Dot11InformationElementIDSwitchingStream: 704 return "Switching Stream" 705 case Dot11InformationElementIDSessionTransmission: 706 return "Session Transmission" 707 case Dot11InformationElementIDDynamicTonePairReport: 708 return "Dynamic Tone Pairing Report" 709 case Dot11InformationElementIDClusterReport: 710 return "Cluster Report" 711 case Dot11InformationElementIDRelayCapabilities: 712 return "Relay Capabilities" 713 case Dot11InformationElementIDRelayTransferParameter: 714 return "Relay Transfer Parameter" 715 case Dot11InformationElementIDBeamlinkMaintenance: 716 return "Beamlink Maintenance" 717 case Dot11InformationElementIDMultipleMacSublayers: 718 return "Multiple MAC Sublayers" 719 case Dot11InformationElementIDUPID: 720 return "U-PID" 721 case Dot11InformationElementIDDMGLinkAdaptionAck: 722 return "DMG Link Adaption Acknowledgment" 723 case Dot11InformationElementIDSymbolProprietary: 724 return "Symbol Proprietary" 725 case Dot11InformationElementIDMCCAOPAdvertOverview: 726 return "MCCAOP Advertisement Overview" 727 case Dot11InformationElementIDQuietPeriodRequest: 728 return "Quiet Period Request" 729 case Dot11InformationElementIDQuietPeriodResponse: 730 return "Quiet Period Response" 731 case Dot11InformationElementIDECPACPolicy: 732 return "ECPAC Policy" 733 case Dot11InformationElementIDClusterTimeOffset: 734 return "Cluster Time Offset" 735 case Dot11InformationElementIDAntennaSectorID: 736 return "Antenna Sector ID" 737 case Dot11InformationElementIDVHTCapabilities: 738 return "VHT Capabilities (IEEE Std 802.11ac/D3.1)" 739 case Dot11InformationElementIDVHTOperation: 740 return "VHT Operation (IEEE Std 802.11ac/D3.1)" 741 case Dot11InformationElementIDExtendedBSSLoad: 742 return "Extended BSS Load" 743 case Dot11InformationElementIDWideBWChannelSwitch: 744 return "Wide Bandwidth Channel Switch" 745 case Dot11InformationElementIDVHTTxPowerEnvelope: 746 return "VHT Tx Power Envelope (IEEE Std 802.11ac/D5.0)" 747 case Dot11InformationElementIDChannelSwitchWrapper: 748 return "Channel Switch Wrapper" 749 case Dot11InformationElementIDOperatingModeNotification: 750 return "Operating Mode Notification" 751 case Dot11InformationElementIDUPSIM: 752 return "UP SIM" 753 case Dot11InformationElementIDReducedNeighborReport: 754 return "Reduced Neighbor Report" 755 case Dot11InformationElementIDTVHTOperation: 756 return "TVHT Op" 757 case Dot11InformationElementIDDeviceLocation: 758 return "Device Location" 759 case Dot11InformationElementIDWhiteSpaceMap: 760 return "White Space Map" 761 case Dot11InformationElementIDFineTuningMeasureParams: 762 return "Fine Tuning Measure Parameters" 763 case Dot11InformationElementIDVendor: 764 return "Vendor" 765 default: 766 return "Unknown information element id" 767 } 768} 769 770// Dot11 provides an IEEE 802.11 base packet header. 771// See http://standards.ieee.org/findstds/standard/802.11-2012.html 772// for excruciating detail. 773type Dot11 struct { 774 BaseLayer 775 Type Dot11Type 776 Proto uint8 777 Flags Dot11Flags 778 DurationID uint16 779 Address1 net.HardwareAddr 780 Address2 net.HardwareAddr 781 Address3 net.HardwareAddr 782 Address4 net.HardwareAddr 783 SequenceNumber uint16 784 FragmentNumber uint16 785 Checksum uint32 786 QOS *Dot11QOS 787 HTControl *Dot11HTControl 788 DataLayer gopacket.Layer 789} 790 791type Dot11QOS struct { 792 TID uint8 /* Traffic IDentifier */ 793 EOSP bool /* End of service period */ 794 AckPolicy Dot11AckPolicy 795 TXOP uint8 796} 797 798type Dot11HTControl struct { 799 ACConstraint bool 800 RDGMorePPDU bool 801 802 VHT *Dot11HTControlVHT 803 HT *Dot11HTControlHT 804} 805 806type Dot11HTControlHT struct { 807 LinkAdapationControl *Dot11LinkAdapationControl 808 CalibrationPosition uint8 809 CalibrationSequence uint8 810 CSISteering uint8 811 NDPAnnouncement bool 812 DEI bool 813} 814 815type Dot11HTControlVHT struct { 816 MRQ bool 817 UnsolicitedMFB bool 818 MSI *uint8 819 MFB Dot11HTControlMFB 820 CompressedMSI *uint8 821 STBCIndication bool 822 MFSI *uint8 823 GID *uint8 824 CodingType *Dot11CodingType 825 FbTXBeamformed bool 826} 827 828type Dot11HTControlMFB struct { 829 NumSTS uint8 830 VHTMCS uint8 831 BW uint8 832 SNR int8 833} 834 835type Dot11LinkAdapationControl struct { 836 TRQ bool 837 MRQ bool 838 MSI uint8 839 MFSI uint8 840 ASEL *Dot11ASEL 841 MFB *uint8 842} 843 844type Dot11ASEL struct { 845 Command uint8 846 Data uint8 847} 848 849type Dot11CodingType uint8 850 851const ( 852 Dot11CodingTypeBCC = 0 853 Dot11CodingTypeLDPC = 1 854) 855 856func (a Dot11CodingType) String() string { 857 switch a { 858 case Dot11CodingTypeBCC: 859 return "BCC" 860 case Dot11CodingTypeLDPC: 861 return "LDPC" 862 default: 863 return "Unknown coding type" 864 } 865} 866 867func (m *Dot11HTControlMFB) NoFeedBackPresent() bool { 868 return m.VHTMCS == 15 && m.NumSTS == 7 869} 870 871func decodeDot11(data []byte, p gopacket.PacketBuilder) error { 872 d := &Dot11{} 873 err := d.DecodeFromBytes(data, p) 874 if err != nil { 875 return err 876 } 877 p.AddLayer(d) 878 if d.DataLayer != nil { 879 p.AddLayer(d.DataLayer) 880 } 881 return p.NextDecoder(d.NextLayerType()) 882} 883 884func (m *Dot11) LayerType() gopacket.LayerType { return LayerTypeDot11 } 885func (m *Dot11) CanDecode() gopacket.LayerClass { return LayerTypeDot11 } 886func (m *Dot11) NextLayerType() gopacket.LayerType { 887 if m.DataLayer != nil { 888 if m.Flags.WEP() { 889 return LayerTypeDot11WEP 890 } 891 return m.DataLayer.(gopacket.DecodingLayer).NextLayerType() 892 } 893 return m.Type.LayerType() 894} 895 896func createU8(x uint8) *uint8 { 897 return &x 898} 899 900var dataDecodeMap = map[Dot11Type]func() gopacket.DecodingLayer{ 901 Dot11TypeData: func() gopacket.DecodingLayer { return &Dot11Data{} }, 902 Dot11TypeDataCFAck: func() gopacket.DecodingLayer { return &Dot11DataCFAck{} }, 903 Dot11TypeDataCFPoll: func() gopacket.DecodingLayer { return &Dot11DataCFPoll{} }, 904 Dot11TypeDataCFAckPoll: func() gopacket.DecodingLayer { return &Dot11DataCFAckPoll{} }, 905 Dot11TypeDataNull: func() gopacket.DecodingLayer { return &Dot11DataNull{} }, 906 Dot11TypeDataCFAckNoData: func() gopacket.DecodingLayer { return &Dot11DataCFAckNoData{} }, 907 Dot11TypeDataCFPollNoData: func() gopacket.DecodingLayer { return &Dot11DataCFPollNoData{} }, 908 Dot11TypeDataCFAckPollNoData: func() gopacket.DecodingLayer { return &Dot11DataCFAckPollNoData{} }, 909 Dot11TypeDataQOSData: func() gopacket.DecodingLayer { return &Dot11DataQOSData{} }, 910 Dot11TypeDataQOSDataCFAck: func() gopacket.DecodingLayer { return &Dot11DataQOSDataCFAck{} }, 911 Dot11TypeDataQOSDataCFPoll: func() gopacket.DecodingLayer { return &Dot11DataQOSDataCFPoll{} }, 912 Dot11TypeDataQOSDataCFAckPoll: func() gopacket.DecodingLayer { return &Dot11DataQOSDataCFAckPoll{} }, 913 Dot11TypeDataQOSNull: func() gopacket.DecodingLayer { return &Dot11DataQOSNull{} }, 914 Dot11TypeDataQOSCFPollNoData: func() gopacket.DecodingLayer { return &Dot11DataQOSCFPollNoData{} }, 915 Dot11TypeDataQOSCFAckPollNoData: func() gopacket.DecodingLayer { return &Dot11DataQOSCFAckPollNoData{} }, 916} 917 918func (m *Dot11) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 919 if len(data) < 10 { 920 df.SetTruncated() 921 return fmt.Errorf("Dot11 length %v too short, %v required", len(data), 10) 922 } 923 m.Type = Dot11Type((data[0])&0xFC) >> 2 924 925 m.DataLayer = nil 926 m.Proto = uint8(data[0]) & 0x0003 927 m.Flags = Dot11Flags(data[1]) 928 m.DurationID = binary.LittleEndian.Uint16(data[2:4]) 929 m.Address1 = net.HardwareAddr(data[4:10]) 930 931 offset := 10 932 933 mainType := m.Type.MainType() 934 935 switch mainType { 936 case Dot11TypeCtrl: 937 switch m.Type { 938 case Dot11TypeCtrlRTS, Dot11TypeCtrlPowersavePoll, Dot11TypeCtrlCFEnd, Dot11TypeCtrlCFEndAck: 939 if len(data) < offset+6 { 940 df.SetTruncated() 941 return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6) 942 } 943 m.Address2 = net.HardwareAddr(data[offset : offset+6]) 944 offset += 6 945 } 946 case Dot11TypeMgmt, Dot11TypeData: 947 if len(data) < offset+14 { 948 df.SetTruncated() 949 return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+14) 950 } 951 m.Address2 = net.HardwareAddr(data[offset : offset+6]) 952 offset += 6 953 m.Address3 = net.HardwareAddr(data[offset : offset+6]) 954 offset += 6 955 956 m.SequenceNumber = (binary.LittleEndian.Uint16(data[offset:offset+2]) & 0xFFF0) >> 4 957 m.FragmentNumber = (binary.LittleEndian.Uint16(data[offset:offset+2]) & 0x000F) 958 offset += 2 959 } 960 961 if mainType == Dot11TypeData && m.Flags.FromDS() && m.Flags.ToDS() { 962 if len(data) < offset+6 { 963 df.SetTruncated() 964 return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6) 965 } 966 m.Address4 = net.HardwareAddr(data[offset : offset+6]) 967 offset += 6 968 } 969 970 if m.Type.QOS() { 971 if len(data) < offset+2 { 972 df.SetTruncated() 973 return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6) 974 } 975 m.QOS = &Dot11QOS{ 976 TID: (uint8(data[offset]) & 0x0F), 977 EOSP: (uint8(data[offset]) & 0x10) == 0x10, 978 AckPolicy: Dot11AckPolicy((uint8(data[offset]) & 0x60) >> 5), 979 TXOP: uint8(data[offset+1]), 980 } 981 offset += 2 982 } 983 if m.Flags.Order() && (m.Type.QOS() || mainType == Dot11TypeMgmt) { 984 if len(data) < offset+4 { 985 df.SetTruncated() 986 return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+6) 987 } 988 989 htc := &Dot11HTControl{ 990 ACConstraint: data[offset+3]&0x40 != 0, 991 RDGMorePPDU: data[offset+3]&0x80 != 0, 992 } 993 m.HTControl = htc 994 995 if data[offset]&0x1 != 0 { // VHT Variant 996 vht := &Dot11HTControlVHT{} 997 htc.VHT = vht 998 vht.MRQ = data[offset]&0x4 != 0 999 vht.UnsolicitedMFB = data[offset+3]&0x20 != 0 1000 vht.MFB = Dot11HTControlMFB{ 1001 NumSTS: uint8(data[offset+1] >> 1 & 0x7), 1002 VHTMCS: uint8(data[offset+1] >> 4 & 0xF), 1003 BW: uint8(data[offset+2] & 0x3), 1004 SNR: int8((-(data[offset+2] >> 2 & 0x20))+data[offset+2]>>2&0x1F) + 22, 1005 } 1006 1007 if vht.UnsolicitedMFB { 1008 if !vht.MFB.NoFeedBackPresent() { 1009 vht.CompressedMSI = createU8(data[offset] >> 3 & 0x3) 1010 vht.STBCIndication = data[offset]&0x20 != 0 1011 vht.CodingType = (*Dot11CodingType)(createU8(data[offset+3] >> 3 & 0x1)) 1012 vht.FbTXBeamformed = data[offset+3]&0x10 != 0 1013 vht.GID = createU8( 1014 data[offset]>>6 + 1015 (data[offset+1] & 0x1 << 2) + 1016 data[offset+3]&0x7<<3) 1017 } 1018 } else { 1019 if vht.MRQ { 1020 vht.MSI = createU8((data[offset] >> 3) & 0x07) 1021 } 1022 vht.MFSI = createU8(data[offset]>>6 + (data[offset+1] & 0x1 << 2)) 1023 } 1024 1025 } else { // HT Variant 1026 ht := &Dot11HTControlHT{} 1027 htc.HT = ht 1028 1029 lac := &Dot11LinkAdapationControl{} 1030 ht.LinkAdapationControl = lac 1031 lac.TRQ = data[offset]&0x2 != 0 1032 lac.MFSI = data[offset]>>6&0x3 + data[offset+1]&0x1<<3 1033 if data[offset]&0x3C == 0x38 { // ASEL 1034 lac.ASEL = &Dot11ASEL{ 1035 Command: data[offset+1] >> 1 & 0x7, 1036 Data: data[offset+1] >> 4 & 0xF, 1037 } 1038 } else { 1039 lac.MRQ = data[offset]&0x4 != 0 1040 if lac.MRQ { 1041 lac.MSI = data[offset] >> 3 & 0x7 1042 } 1043 lac.MFB = createU8(data[offset+1] >> 1) 1044 } 1045 ht.CalibrationPosition = data[offset+2] & 0x3 1046 ht.CalibrationSequence = data[offset+2] >> 2 & 0x3 1047 ht.CSISteering = data[offset+2] >> 6 & 0x3 1048 ht.NDPAnnouncement = data[offset+3]&0x1 != 0 1049 if mainType != Dot11TypeMgmt { 1050 ht.DEI = data[offset+3]&0x20 != 0 1051 } 1052 } 1053 1054 offset += 4 1055 } 1056 1057 if len(data) < offset+4 { 1058 df.SetTruncated() 1059 return fmt.Errorf("Dot11 length %v too short, %v required", len(data), offset+4) 1060 } 1061 1062 m.BaseLayer = BaseLayer{ 1063 Contents: data[0:offset], 1064 Payload: data[offset : len(data)-4], 1065 } 1066 1067 if mainType == Dot11TypeData { 1068 l := dataDecodeMap[m.Type]() 1069 err := l.DecodeFromBytes(m.BaseLayer.Payload, df) 1070 if err != nil { 1071 return err 1072 } 1073 m.DataLayer = l.(gopacket.Layer) 1074 } 1075 1076 m.Checksum = binary.LittleEndian.Uint32(data[len(data)-4 : len(data)]) 1077 return nil 1078} 1079 1080func (m *Dot11) ChecksumValid() bool { 1081 // only for CTRL and MGMT frames 1082 h := crc32.NewIEEE() 1083 h.Write(m.Contents) 1084 h.Write(m.Payload) 1085 return m.Checksum == h.Sum32() 1086} 1087 1088func (m Dot11) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1089 buf, err := b.PrependBytes(24) 1090 1091 if err != nil { 1092 return err 1093 } 1094 1095 buf[0] = (uint8(m.Type) << 2) | m.Proto 1096 buf[1] = uint8(m.Flags) 1097 1098 binary.LittleEndian.PutUint16(buf[2:4], m.DurationID) 1099 1100 copy(buf[4:10], m.Address1) 1101 1102 offset := 10 1103 1104 switch m.Type.MainType() { 1105 case Dot11TypeCtrl: 1106 switch m.Type { 1107 case Dot11TypeCtrlRTS, Dot11TypeCtrlPowersavePoll, Dot11TypeCtrlCFEnd, Dot11TypeCtrlCFEndAck: 1108 copy(buf[offset:offset+6], m.Address2) 1109 offset += 6 1110 } 1111 case Dot11TypeMgmt, Dot11TypeData: 1112 copy(buf[offset:offset+6], m.Address2) 1113 offset += 6 1114 copy(buf[offset:offset+6], m.Address3) 1115 offset += 6 1116 1117 binary.LittleEndian.PutUint16(buf[offset:offset+2], (m.SequenceNumber<<4)|m.FragmentNumber) 1118 offset += 2 1119 } 1120 1121 if m.Type.MainType() == Dot11TypeData && m.Flags.FromDS() && m.Flags.ToDS() { 1122 copy(buf[offset:offset+6], m.Address4) 1123 offset += 6 1124 } 1125 1126 return nil 1127} 1128 1129// Dot11Mgmt is a base for all IEEE 802.11 management layers. 1130type Dot11Mgmt struct { 1131 BaseLayer 1132} 1133 1134func (m *Dot11Mgmt) NextLayerType() gopacket.LayerType { return gopacket.LayerTypePayload } 1135func (m *Dot11Mgmt) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1136 m.Contents = data 1137 return nil 1138} 1139 1140// Dot11Ctrl is a base for all IEEE 802.11 control layers. 1141type Dot11Ctrl struct { 1142 BaseLayer 1143} 1144 1145func (m *Dot11Ctrl) NextLayerType() gopacket.LayerType { return gopacket.LayerTypePayload } 1146 1147func (m *Dot11Ctrl) LayerType() gopacket.LayerType { return LayerTypeDot11Ctrl } 1148func (m *Dot11Ctrl) CanDecode() gopacket.LayerClass { return LayerTypeDot11Ctrl } 1149func (m *Dot11Ctrl) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1150 m.Contents = data 1151 return nil 1152} 1153 1154func decodeDot11Ctrl(data []byte, p gopacket.PacketBuilder) error { 1155 d := &Dot11Ctrl{} 1156 return decodingLayerDecoder(d, data, p) 1157} 1158 1159// Dot11WEP contains WEP encrpted IEEE 802.11 data. 1160type Dot11WEP struct { 1161 BaseLayer 1162} 1163 1164func (m *Dot11WEP) NextLayerType() gopacket.LayerType { return gopacket.LayerTypePayload } 1165 1166func (m *Dot11WEP) LayerType() gopacket.LayerType { return LayerTypeDot11WEP } 1167func (m *Dot11WEP) CanDecode() gopacket.LayerClass { return LayerTypeDot11WEP } 1168func (m *Dot11WEP) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1169 m.Contents = data 1170 return nil 1171} 1172 1173func decodeDot11WEP(data []byte, p gopacket.PacketBuilder) error { 1174 d := &Dot11WEP{} 1175 return decodingLayerDecoder(d, data, p) 1176} 1177 1178// Dot11Data is a base for all IEEE 802.11 data layers. 1179type Dot11Data struct { 1180 BaseLayer 1181} 1182 1183func (m *Dot11Data) NextLayerType() gopacket.LayerType { 1184 return LayerTypeLLC 1185} 1186 1187func (m *Dot11Data) LayerType() gopacket.LayerType { return LayerTypeDot11Data } 1188func (m *Dot11Data) CanDecode() gopacket.LayerClass { return LayerTypeDot11Data } 1189func (m *Dot11Data) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1190 m.Payload = data 1191 return nil 1192} 1193 1194func decodeDot11Data(data []byte, p gopacket.PacketBuilder) error { 1195 d := &Dot11Data{} 1196 return decodingLayerDecoder(d, data, p) 1197} 1198 1199type Dot11DataCFAck struct { 1200 Dot11Data 1201} 1202 1203func decodeDot11DataCFAck(data []byte, p gopacket.PacketBuilder) error { 1204 d := &Dot11DataCFAck{} 1205 return decodingLayerDecoder(d, data, p) 1206} 1207 1208func (m *Dot11DataCFAck) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFAck } 1209func (m *Dot11DataCFAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFAck } 1210func (m *Dot11DataCFAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1211 return m.Dot11Data.DecodeFromBytes(data, df) 1212} 1213 1214type Dot11DataCFPoll struct { 1215 Dot11Data 1216} 1217 1218func decodeDot11DataCFPoll(data []byte, p gopacket.PacketBuilder) error { 1219 d := &Dot11DataCFPoll{} 1220 return decodingLayerDecoder(d, data, p) 1221} 1222 1223func (m *Dot11DataCFPoll) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFPoll } 1224func (m *Dot11DataCFPoll) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFPoll } 1225func (m *Dot11DataCFPoll) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1226 return m.Dot11Data.DecodeFromBytes(data, df) 1227} 1228 1229type Dot11DataCFAckPoll struct { 1230 Dot11Data 1231} 1232 1233func decodeDot11DataCFAckPoll(data []byte, p gopacket.PacketBuilder) error { 1234 d := &Dot11DataCFAckPoll{} 1235 return decodingLayerDecoder(d, data, p) 1236} 1237 1238func (m *Dot11DataCFAckPoll) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFAckPoll } 1239func (m *Dot11DataCFAckPoll) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFAckPoll } 1240func (m *Dot11DataCFAckPoll) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1241 return m.Dot11Data.DecodeFromBytes(data, df) 1242} 1243 1244type Dot11DataNull struct { 1245 Dot11Data 1246} 1247 1248func decodeDot11DataNull(data []byte, p gopacket.PacketBuilder) error { 1249 d := &Dot11DataNull{} 1250 return decodingLayerDecoder(d, data, p) 1251} 1252 1253func (m *Dot11DataNull) LayerType() gopacket.LayerType { return LayerTypeDot11DataNull } 1254func (m *Dot11DataNull) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataNull } 1255func (m *Dot11DataNull) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1256 return m.Dot11Data.DecodeFromBytes(data, df) 1257} 1258 1259type Dot11DataCFAckNoData struct { 1260 Dot11Data 1261} 1262 1263func decodeDot11DataCFAckNoData(data []byte, p gopacket.PacketBuilder) error { 1264 d := &Dot11DataCFAckNoData{} 1265 return decodingLayerDecoder(d, data, p) 1266} 1267 1268func (m *Dot11DataCFAckNoData) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFAckNoData } 1269func (m *Dot11DataCFAckNoData) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFAckNoData } 1270func (m *Dot11DataCFAckNoData) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1271 return m.Dot11Data.DecodeFromBytes(data, df) 1272} 1273 1274type Dot11DataCFPollNoData struct { 1275 Dot11Data 1276} 1277 1278func decodeDot11DataCFPollNoData(data []byte, p gopacket.PacketBuilder) error { 1279 d := &Dot11DataCFPollNoData{} 1280 return decodingLayerDecoder(d, data, p) 1281} 1282 1283func (m *Dot11DataCFPollNoData) LayerType() gopacket.LayerType { return LayerTypeDot11DataCFPollNoData } 1284func (m *Dot11DataCFPollNoData) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataCFPollNoData } 1285func (m *Dot11DataCFPollNoData) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1286 return m.Dot11Data.DecodeFromBytes(data, df) 1287} 1288 1289type Dot11DataCFAckPollNoData struct { 1290 Dot11Data 1291} 1292 1293func decodeDot11DataCFAckPollNoData(data []byte, p gopacket.PacketBuilder) error { 1294 d := &Dot11DataCFAckPollNoData{} 1295 return decodingLayerDecoder(d, data, p) 1296} 1297 1298func (m *Dot11DataCFAckPollNoData) LayerType() gopacket.LayerType { 1299 return LayerTypeDot11DataCFAckPollNoData 1300} 1301func (m *Dot11DataCFAckPollNoData) CanDecode() gopacket.LayerClass { 1302 return LayerTypeDot11DataCFAckPollNoData 1303} 1304func (m *Dot11DataCFAckPollNoData) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1305 return m.Dot11Data.DecodeFromBytes(data, df) 1306} 1307 1308type Dot11DataQOS struct { 1309 Dot11Ctrl 1310} 1311 1312func (m *Dot11DataQOS) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1313 m.BaseLayer = BaseLayer{Payload: data} 1314 return nil 1315} 1316 1317type Dot11DataQOSData struct { 1318 Dot11DataQOS 1319} 1320 1321func decodeDot11DataQOSData(data []byte, p gopacket.PacketBuilder) error { 1322 d := &Dot11DataQOSData{} 1323 return decodingLayerDecoder(d, data, p) 1324} 1325 1326func (m *Dot11DataQOSData) LayerType() gopacket.LayerType { return LayerTypeDot11DataQOSData } 1327func (m *Dot11DataQOSData) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataQOSData } 1328 1329func (m *Dot11DataQOSData) NextLayerType() gopacket.LayerType { 1330 return LayerTypeDot11Data 1331} 1332 1333type Dot11DataQOSDataCFAck struct { 1334 Dot11DataQOS 1335} 1336 1337func decodeDot11DataQOSDataCFAck(data []byte, p gopacket.PacketBuilder) error { 1338 d := &Dot11DataQOSDataCFAck{} 1339 return decodingLayerDecoder(d, data, p) 1340} 1341 1342func (m *Dot11DataQOSDataCFAck) LayerType() gopacket.LayerType { return LayerTypeDot11DataQOSDataCFAck } 1343func (m *Dot11DataQOSDataCFAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataQOSDataCFAck } 1344func (m *Dot11DataQOSDataCFAck) NextLayerType() gopacket.LayerType { return LayerTypeDot11DataCFAck } 1345 1346type Dot11DataQOSDataCFPoll struct { 1347 Dot11DataQOS 1348} 1349 1350func decodeDot11DataQOSDataCFPoll(data []byte, p gopacket.PacketBuilder) error { 1351 d := &Dot11DataQOSDataCFPoll{} 1352 return decodingLayerDecoder(d, data, p) 1353} 1354 1355func (m *Dot11DataQOSDataCFPoll) LayerType() gopacket.LayerType { 1356 return LayerTypeDot11DataQOSDataCFPoll 1357} 1358func (m *Dot11DataQOSDataCFPoll) CanDecode() gopacket.LayerClass { 1359 return LayerTypeDot11DataQOSDataCFPoll 1360} 1361func (m *Dot11DataQOSDataCFPoll) NextLayerType() gopacket.LayerType { return LayerTypeDot11DataCFPoll } 1362 1363type Dot11DataQOSDataCFAckPoll struct { 1364 Dot11DataQOS 1365} 1366 1367func decodeDot11DataQOSDataCFAckPoll(data []byte, p gopacket.PacketBuilder) error { 1368 d := &Dot11DataQOSDataCFAckPoll{} 1369 return decodingLayerDecoder(d, data, p) 1370} 1371 1372func (m *Dot11DataQOSDataCFAckPoll) LayerType() gopacket.LayerType { 1373 return LayerTypeDot11DataQOSDataCFAckPoll 1374} 1375func (m *Dot11DataQOSDataCFAckPoll) CanDecode() gopacket.LayerClass { 1376 return LayerTypeDot11DataQOSDataCFAckPoll 1377} 1378func (m *Dot11DataQOSDataCFAckPoll) NextLayerType() gopacket.LayerType { 1379 return LayerTypeDot11DataCFAckPoll 1380} 1381 1382type Dot11DataQOSNull struct { 1383 Dot11DataQOS 1384} 1385 1386func decodeDot11DataQOSNull(data []byte, p gopacket.PacketBuilder) error { 1387 d := &Dot11DataQOSNull{} 1388 return decodingLayerDecoder(d, data, p) 1389} 1390 1391func (m *Dot11DataQOSNull) LayerType() gopacket.LayerType { return LayerTypeDot11DataQOSNull } 1392func (m *Dot11DataQOSNull) CanDecode() gopacket.LayerClass { return LayerTypeDot11DataQOSNull } 1393func (m *Dot11DataQOSNull) NextLayerType() gopacket.LayerType { return LayerTypeDot11DataNull } 1394 1395type Dot11DataQOSCFPollNoData struct { 1396 Dot11DataQOS 1397} 1398 1399func decodeDot11DataQOSCFPollNoData(data []byte, p gopacket.PacketBuilder) error { 1400 d := &Dot11DataQOSCFPollNoData{} 1401 return decodingLayerDecoder(d, data, p) 1402} 1403 1404func (m *Dot11DataQOSCFPollNoData) LayerType() gopacket.LayerType { 1405 return LayerTypeDot11DataQOSCFPollNoData 1406} 1407func (m *Dot11DataQOSCFPollNoData) CanDecode() gopacket.LayerClass { 1408 return LayerTypeDot11DataQOSCFPollNoData 1409} 1410func (m *Dot11DataQOSCFPollNoData) NextLayerType() gopacket.LayerType { 1411 return LayerTypeDot11DataCFPollNoData 1412} 1413 1414type Dot11DataQOSCFAckPollNoData struct { 1415 Dot11DataQOS 1416} 1417 1418func decodeDot11DataQOSCFAckPollNoData(data []byte, p gopacket.PacketBuilder) error { 1419 d := &Dot11DataQOSCFAckPollNoData{} 1420 return decodingLayerDecoder(d, data, p) 1421} 1422 1423func (m *Dot11DataQOSCFAckPollNoData) LayerType() gopacket.LayerType { 1424 return LayerTypeDot11DataQOSCFAckPollNoData 1425} 1426func (m *Dot11DataQOSCFAckPollNoData) CanDecode() gopacket.LayerClass { 1427 return LayerTypeDot11DataQOSCFAckPollNoData 1428} 1429func (m *Dot11DataQOSCFAckPollNoData) NextLayerType() gopacket.LayerType { 1430 return LayerTypeDot11DataCFAckPollNoData 1431} 1432 1433type Dot11InformationElement struct { 1434 BaseLayer 1435 ID Dot11InformationElementID 1436 Length uint8 1437 OUI []byte 1438 Info []byte 1439} 1440 1441func (m *Dot11InformationElement) LayerType() gopacket.LayerType { 1442 return LayerTypeDot11InformationElement 1443} 1444func (m *Dot11InformationElement) CanDecode() gopacket.LayerClass { 1445 return LayerTypeDot11InformationElement 1446} 1447 1448func (m *Dot11InformationElement) NextLayerType() gopacket.LayerType { 1449 return LayerTypeDot11InformationElement 1450} 1451 1452func (m *Dot11InformationElement) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1453 if len(data) < 2 { 1454 df.SetTruncated() 1455 return fmt.Errorf("Dot11InformationElement length %v too short, %v required", len(data), 2) 1456 } 1457 m.ID = Dot11InformationElementID(data[0]) 1458 m.Length = data[1] 1459 offset := int(2) 1460 1461 if len(data) < offset+int(m.Length) { 1462 df.SetTruncated() 1463 return fmt.Errorf("Dot11InformationElement length %v too short, %v required", len(data), offset+int(m.Length)) 1464 } 1465 if m.ID == 221 { 1466 // Vendor extension 1467 m.OUI = data[offset : offset+4] 1468 m.Info = data[offset+4 : offset+int(m.Length)] 1469 } else { 1470 m.Info = data[offset : offset+int(m.Length)] 1471 } 1472 1473 offset += int(m.Length) 1474 1475 m.BaseLayer = BaseLayer{Contents: data[:offset], Payload: data[offset:]} 1476 return nil 1477} 1478 1479func (d *Dot11InformationElement) String() string { 1480 if d.ID == 0 { 1481 return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, SSID: %v)", d.ID, d.Length, string(d.Info)) 1482 } else if d.ID == 1 { 1483 rates := "" 1484 for i := 0; i < len(d.Info); i++ { 1485 if d.Info[i]&0x80 == 0 { 1486 rates += fmt.Sprintf("%.1f ", float32(d.Info[i])*0.5) 1487 } else { 1488 rates += fmt.Sprintf("%.1f* ", float32(d.Info[i]&0x7F)*0.5) 1489 } 1490 } 1491 return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, Rates: %s Mbit)", d.ID, d.Length, rates) 1492 } else if d.ID == 221 { 1493 return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, OUI: %X, Info: %X)", d.ID, d.Length, d.OUI, d.Info) 1494 } else { 1495 return fmt.Sprintf("802.11 Information Element (ID: %v, Length: %v, Info: %X)", d.ID, d.Length, d.Info) 1496 } 1497} 1498 1499func (m Dot11InformationElement) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1500 length := len(m.Info) + len(m.OUI) 1501 if buf, err := b.PrependBytes(2 + length); err != nil { 1502 return err 1503 } else { 1504 buf[0] = uint8(m.ID) 1505 buf[1] = uint8(length) 1506 copy(buf[2:], m.OUI) 1507 copy(buf[2+len(m.OUI):], m.Info) 1508 } 1509 return nil 1510} 1511 1512func decodeDot11InformationElement(data []byte, p gopacket.PacketBuilder) error { 1513 d := &Dot11InformationElement{} 1514 return decodingLayerDecoder(d, data, p) 1515} 1516 1517type Dot11CtrlCTS struct { 1518 Dot11Ctrl 1519} 1520 1521func decodeDot11CtrlCTS(data []byte, p gopacket.PacketBuilder) error { 1522 d := &Dot11CtrlCTS{} 1523 return decodingLayerDecoder(d, data, p) 1524} 1525 1526func (m *Dot11CtrlCTS) LayerType() gopacket.LayerType { 1527 return LayerTypeDot11CtrlCTS 1528} 1529func (m *Dot11CtrlCTS) CanDecode() gopacket.LayerClass { 1530 return LayerTypeDot11CtrlCTS 1531} 1532func (m *Dot11CtrlCTS) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1533 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1534} 1535 1536type Dot11CtrlRTS struct { 1537 Dot11Ctrl 1538} 1539 1540func decodeDot11CtrlRTS(data []byte, p gopacket.PacketBuilder) error { 1541 d := &Dot11CtrlRTS{} 1542 return decodingLayerDecoder(d, data, p) 1543} 1544 1545func (m *Dot11CtrlRTS) LayerType() gopacket.LayerType { 1546 return LayerTypeDot11CtrlRTS 1547} 1548func (m *Dot11CtrlRTS) CanDecode() gopacket.LayerClass { 1549 return LayerTypeDot11CtrlRTS 1550} 1551func (m *Dot11CtrlRTS) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1552 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1553} 1554 1555type Dot11CtrlBlockAckReq struct { 1556 Dot11Ctrl 1557} 1558 1559func decodeDot11CtrlBlockAckReq(data []byte, p gopacket.PacketBuilder) error { 1560 d := &Dot11CtrlBlockAckReq{} 1561 return decodingLayerDecoder(d, data, p) 1562} 1563 1564func (m *Dot11CtrlBlockAckReq) LayerType() gopacket.LayerType { 1565 return LayerTypeDot11CtrlBlockAckReq 1566} 1567func (m *Dot11CtrlBlockAckReq) CanDecode() gopacket.LayerClass { 1568 return LayerTypeDot11CtrlBlockAckReq 1569} 1570func (m *Dot11CtrlBlockAckReq) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1571 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1572} 1573 1574type Dot11CtrlBlockAck struct { 1575 Dot11Ctrl 1576} 1577 1578func decodeDot11CtrlBlockAck(data []byte, p gopacket.PacketBuilder) error { 1579 d := &Dot11CtrlBlockAck{} 1580 return decodingLayerDecoder(d, data, p) 1581} 1582 1583func (m *Dot11CtrlBlockAck) LayerType() gopacket.LayerType { return LayerTypeDot11CtrlBlockAck } 1584func (m *Dot11CtrlBlockAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11CtrlBlockAck } 1585func (m *Dot11CtrlBlockAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1586 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1587} 1588 1589type Dot11CtrlPowersavePoll struct { 1590 Dot11Ctrl 1591} 1592 1593func decodeDot11CtrlPowersavePoll(data []byte, p gopacket.PacketBuilder) error { 1594 d := &Dot11CtrlPowersavePoll{} 1595 return decodingLayerDecoder(d, data, p) 1596} 1597 1598func (m *Dot11CtrlPowersavePoll) LayerType() gopacket.LayerType { 1599 return LayerTypeDot11CtrlPowersavePoll 1600} 1601func (m *Dot11CtrlPowersavePoll) CanDecode() gopacket.LayerClass { 1602 return LayerTypeDot11CtrlPowersavePoll 1603} 1604func (m *Dot11CtrlPowersavePoll) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1605 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1606} 1607 1608type Dot11CtrlAck struct { 1609 Dot11Ctrl 1610} 1611 1612func decodeDot11CtrlAck(data []byte, p gopacket.PacketBuilder) error { 1613 d := &Dot11CtrlAck{} 1614 return decodingLayerDecoder(d, data, p) 1615} 1616 1617func (m *Dot11CtrlAck) LayerType() gopacket.LayerType { return LayerTypeDot11CtrlAck } 1618func (m *Dot11CtrlAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11CtrlAck } 1619func (m *Dot11CtrlAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1620 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1621} 1622 1623type Dot11CtrlCFEnd struct { 1624 Dot11Ctrl 1625} 1626 1627func decodeDot11CtrlCFEnd(data []byte, p gopacket.PacketBuilder) error { 1628 d := &Dot11CtrlCFEnd{} 1629 return decodingLayerDecoder(d, data, p) 1630} 1631 1632func (m *Dot11CtrlCFEnd) LayerType() gopacket.LayerType { 1633 return LayerTypeDot11CtrlCFEnd 1634} 1635func (m *Dot11CtrlCFEnd) CanDecode() gopacket.LayerClass { 1636 return LayerTypeDot11CtrlCFEnd 1637} 1638func (m *Dot11CtrlCFEnd) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1639 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1640} 1641 1642type Dot11CtrlCFEndAck struct { 1643 Dot11Ctrl 1644} 1645 1646func decodeDot11CtrlCFEndAck(data []byte, p gopacket.PacketBuilder) error { 1647 d := &Dot11CtrlCFEndAck{} 1648 return decodingLayerDecoder(d, data, p) 1649} 1650 1651func (m *Dot11CtrlCFEndAck) LayerType() gopacket.LayerType { 1652 return LayerTypeDot11CtrlCFEndAck 1653} 1654func (m *Dot11CtrlCFEndAck) CanDecode() gopacket.LayerClass { 1655 return LayerTypeDot11CtrlCFEndAck 1656} 1657func (m *Dot11CtrlCFEndAck) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1658 return m.Dot11Ctrl.DecodeFromBytes(data, df) 1659} 1660 1661type Dot11MgmtAssociationReq struct { 1662 Dot11Mgmt 1663 CapabilityInfo uint16 1664 ListenInterval uint16 1665} 1666 1667func decodeDot11MgmtAssociationReq(data []byte, p gopacket.PacketBuilder) error { 1668 d := &Dot11MgmtAssociationReq{} 1669 return decodingLayerDecoder(d, data, p) 1670} 1671 1672func (m *Dot11MgmtAssociationReq) LayerType() gopacket.LayerType { 1673 return LayerTypeDot11MgmtAssociationReq 1674} 1675func (m *Dot11MgmtAssociationReq) CanDecode() gopacket.LayerClass { 1676 return LayerTypeDot11MgmtAssociationReq 1677} 1678func (m *Dot11MgmtAssociationReq) NextLayerType() gopacket.LayerType { 1679 return LayerTypeDot11InformationElement 1680} 1681func (m *Dot11MgmtAssociationReq) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1682 if len(data) < 4 { 1683 df.SetTruncated() 1684 return fmt.Errorf("Dot11MgmtAssociationReq length %v too short, %v required", len(data), 4) 1685 } 1686 m.CapabilityInfo = binary.LittleEndian.Uint16(data[0:2]) 1687 m.ListenInterval = binary.LittleEndian.Uint16(data[2:4]) 1688 m.Payload = data[4:] 1689 return m.Dot11Mgmt.DecodeFromBytes(data, df) 1690} 1691 1692func (m Dot11MgmtAssociationReq) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1693 buf, err := b.PrependBytes(4) 1694 1695 if err != nil { 1696 return err 1697 } 1698 1699 binary.LittleEndian.PutUint16(buf[0:2], m.CapabilityInfo) 1700 binary.LittleEndian.PutUint16(buf[2:4], m.ListenInterval) 1701 1702 return nil 1703} 1704 1705type Dot11MgmtAssociationResp struct { 1706 Dot11Mgmt 1707 CapabilityInfo uint16 1708 Status Dot11Status 1709 AID uint16 1710} 1711 1712func decodeDot11MgmtAssociationResp(data []byte, p gopacket.PacketBuilder) error { 1713 d := &Dot11MgmtAssociationResp{} 1714 return decodingLayerDecoder(d, data, p) 1715} 1716 1717func (m *Dot11MgmtAssociationResp) CanDecode() gopacket.LayerClass { 1718 return LayerTypeDot11MgmtAssociationResp 1719} 1720func (m *Dot11MgmtAssociationResp) LayerType() gopacket.LayerType { 1721 return LayerTypeDot11MgmtAssociationResp 1722} 1723func (m *Dot11MgmtAssociationResp) NextLayerType() gopacket.LayerType { 1724 return LayerTypeDot11InformationElement 1725} 1726func (m *Dot11MgmtAssociationResp) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1727 if len(data) < 6 { 1728 df.SetTruncated() 1729 return fmt.Errorf("Dot11MgmtAssociationResp length %v too short, %v required", len(data), 6) 1730 } 1731 m.CapabilityInfo = binary.LittleEndian.Uint16(data[0:2]) 1732 m.Status = Dot11Status(binary.LittleEndian.Uint16(data[2:4])) 1733 m.AID = binary.LittleEndian.Uint16(data[4:6]) 1734 m.Payload = data[6:] 1735 return m.Dot11Mgmt.DecodeFromBytes(data, df) 1736} 1737 1738func (m Dot11MgmtAssociationResp) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1739 buf, err := b.PrependBytes(6) 1740 1741 if err != nil { 1742 return err 1743 } 1744 1745 binary.LittleEndian.PutUint16(buf[0:2], m.CapabilityInfo) 1746 binary.LittleEndian.PutUint16(buf[2:4], uint16(m.Status)) 1747 binary.LittleEndian.PutUint16(buf[4:6], m.AID) 1748 1749 return nil 1750} 1751 1752type Dot11MgmtReassociationReq struct { 1753 Dot11Mgmt 1754 CapabilityInfo uint16 1755 ListenInterval uint16 1756 CurrentApAddress net.HardwareAddr 1757} 1758 1759func decodeDot11MgmtReassociationReq(data []byte, p gopacket.PacketBuilder) error { 1760 d := &Dot11MgmtReassociationReq{} 1761 return decodingLayerDecoder(d, data, p) 1762} 1763 1764func (m *Dot11MgmtReassociationReq) LayerType() gopacket.LayerType { 1765 return LayerTypeDot11MgmtReassociationReq 1766} 1767func (m *Dot11MgmtReassociationReq) CanDecode() gopacket.LayerClass { 1768 return LayerTypeDot11MgmtReassociationReq 1769} 1770func (m *Dot11MgmtReassociationReq) NextLayerType() gopacket.LayerType { 1771 return LayerTypeDot11InformationElement 1772} 1773func (m *Dot11MgmtReassociationReq) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1774 if len(data) < 10 { 1775 df.SetTruncated() 1776 return fmt.Errorf("Dot11MgmtReassociationReq length %v too short, %v required", len(data), 10) 1777 } 1778 m.CapabilityInfo = binary.LittleEndian.Uint16(data[0:2]) 1779 m.ListenInterval = binary.LittleEndian.Uint16(data[2:4]) 1780 m.CurrentApAddress = net.HardwareAddr(data[4:10]) 1781 m.Payload = data[10:] 1782 return m.Dot11Mgmt.DecodeFromBytes(data, df) 1783} 1784 1785func (m Dot11MgmtReassociationReq) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1786 buf, err := b.PrependBytes(10) 1787 1788 if err != nil { 1789 return err 1790 } 1791 1792 binary.LittleEndian.PutUint16(buf[0:2], m.CapabilityInfo) 1793 binary.LittleEndian.PutUint16(buf[2:4], m.ListenInterval) 1794 1795 copy(buf[4:10], m.CurrentApAddress) 1796 1797 return nil 1798} 1799 1800type Dot11MgmtReassociationResp struct { 1801 Dot11Mgmt 1802} 1803 1804func decodeDot11MgmtReassociationResp(data []byte, p gopacket.PacketBuilder) error { 1805 d := &Dot11MgmtReassociationResp{} 1806 return decodingLayerDecoder(d, data, p) 1807} 1808 1809func (m *Dot11MgmtReassociationResp) LayerType() gopacket.LayerType { 1810 return LayerTypeDot11MgmtReassociationResp 1811} 1812func (m *Dot11MgmtReassociationResp) CanDecode() gopacket.LayerClass { 1813 return LayerTypeDot11MgmtReassociationResp 1814} 1815func (m *Dot11MgmtReassociationResp) NextLayerType() gopacket.LayerType { 1816 return LayerTypeDot11InformationElement 1817} 1818 1819type Dot11MgmtProbeReq struct { 1820 Dot11Mgmt 1821} 1822 1823func decodeDot11MgmtProbeReq(data []byte, p gopacket.PacketBuilder) error { 1824 d := &Dot11MgmtProbeReq{} 1825 return decodingLayerDecoder(d, data, p) 1826} 1827 1828func (m *Dot11MgmtProbeReq) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtProbeReq } 1829func (m *Dot11MgmtProbeReq) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtProbeReq } 1830func (m *Dot11MgmtProbeReq) NextLayerType() gopacket.LayerType { 1831 return LayerTypeDot11InformationElement 1832} 1833 1834type Dot11MgmtProbeResp struct { 1835 Dot11Mgmt 1836 Timestamp uint64 1837 Interval uint16 1838 Flags uint16 1839} 1840 1841func decodeDot11MgmtProbeResp(data []byte, p gopacket.PacketBuilder) error { 1842 d := &Dot11MgmtProbeResp{} 1843 return decodingLayerDecoder(d, data, p) 1844} 1845 1846func (m *Dot11MgmtProbeResp) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtProbeResp } 1847func (m *Dot11MgmtProbeResp) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtProbeResp } 1848func (m *Dot11MgmtProbeResp) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1849 if len(data) < 12 { 1850 df.SetTruncated() 1851 1852 return fmt.Errorf("Dot11MgmtProbeResp length %v too short, %v required", len(data), 12) 1853 } 1854 1855 m.Timestamp = binary.LittleEndian.Uint64(data[0:8]) 1856 m.Interval = binary.LittleEndian.Uint16(data[8:10]) 1857 m.Flags = binary.LittleEndian.Uint16(data[10:12]) 1858 m.Payload = data[12:] 1859 1860 return m.Dot11Mgmt.DecodeFromBytes(data, df) 1861} 1862 1863func (m *Dot11MgmtProbeResp) NextLayerType() gopacket.LayerType { 1864 return LayerTypeDot11InformationElement 1865} 1866 1867func (m Dot11MgmtProbeResp) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1868 buf, err := b.PrependBytes(12) 1869 1870 if err != nil { 1871 return err 1872 } 1873 1874 binary.LittleEndian.PutUint64(buf[0:8], m.Timestamp) 1875 binary.LittleEndian.PutUint16(buf[8:10], m.Interval) 1876 binary.LittleEndian.PutUint16(buf[10:12], m.Flags) 1877 1878 return nil 1879} 1880 1881type Dot11MgmtMeasurementPilot struct { 1882 Dot11Mgmt 1883} 1884 1885func decodeDot11MgmtMeasurementPilot(data []byte, p gopacket.PacketBuilder) error { 1886 d := &Dot11MgmtMeasurementPilot{} 1887 return decodingLayerDecoder(d, data, p) 1888} 1889 1890func (m *Dot11MgmtMeasurementPilot) LayerType() gopacket.LayerType { 1891 return LayerTypeDot11MgmtMeasurementPilot 1892} 1893func (m *Dot11MgmtMeasurementPilot) CanDecode() gopacket.LayerClass { 1894 return LayerTypeDot11MgmtMeasurementPilot 1895} 1896 1897type Dot11MgmtBeacon struct { 1898 Dot11Mgmt 1899 Timestamp uint64 1900 Interval uint16 1901 Flags uint16 1902} 1903 1904func decodeDot11MgmtBeacon(data []byte, p gopacket.PacketBuilder) error { 1905 d := &Dot11MgmtBeacon{} 1906 return decodingLayerDecoder(d, data, p) 1907} 1908 1909func (m *Dot11MgmtBeacon) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtBeacon } 1910func (m *Dot11MgmtBeacon) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtBeacon } 1911func (m *Dot11MgmtBeacon) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1912 if len(data) < 12 { 1913 df.SetTruncated() 1914 return fmt.Errorf("Dot11MgmtBeacon length %v too short, %v required", len(data), 12) 1915 } 1916 m.Timestamp = binary.LittleEndian.Uint64(data[0:8]) 1917 m.Interval = binary.LittleEndian.Uint16(data[8:10]) 1918 m.Flags = binary.LittleEndian.Uint16(data[10:12]) 1919 m.Payload = data[12:] 1920 return m.Dot11Mgmt.DecodeFromBytes(data, df) 1921} 1922 1923func (m *Dot11MgmtBeacon) NextLayerType() gopacket.LayerType { return LayerTypeDot11InformationElement } 1924 1925func (m Dot11MgmtBeacon) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1926 buf, err := b.PrependBytes(12) 1927 1928 if err != nil { 1929 return err 1930 } 1931 1932 binary.LittleEndian.PutUint64(buf[0:8], m.Timestamp) 1933 binary.LittleEndian.PutUint16(buf[8:10], m.Interval) 1934 binary.LittleEndian.PutUint16(buf[10:12], m.Flags) 1935 1936 return nil 1937} 1938 1939type Dot11MgmtATIM struct { 1940 Dot11Mgmt 1941} 1942 1943func decodeDot11MgmtATIM(data []byte, p gopacket.PacketBuilder) error { 1944 d := &Dot11MgmtATIM{} 1945 return decodingLayerDecoder(d, data, p) 1946} 1947 1948func (m *Dot11MgmtATIM) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtATIM } 1949func (m *Dot11MgmtATIM) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtATIM } 1950 1951type Dot11MgmtDisassociation struct { 1952 Dot11Mgmt 1953 Reason Dot11Reason 1954} 1955 1956func decodeDot11MgmtDisassociation(data []byte, p gopacket.PacketBuilder) error { 1957 d := &Dot11MgmtDisassociation{} 1958 return decodingLayerDecoder(d, data, p) 1959} 1960 1961func (m *Dot11MgmtDisassociation) LayerType() gopacket.LayerType { 1962 return LayerTypeDot11MgmtDisassociation 1963} 1964func (m *Dot11MgmtDisassociation) CanDecode() gopacket.LayerClass { 1965 return LayerTypeDot11MgmtDisassociation 1966} 1967func (m *Dot11MgmtDisassociation) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 1968 if len(data) < 2 { 1969 df.SetTruncated() 1970 return fmt.Errorf("Dot11MgmtDisassociation length %v too short, %v required", len(data), 2) 1971 } 1972 m.Reason = Dot11Reason(binary.LittleEndian.Uint16(data[0:2])) 1973 return m.Dot11Mgmt.DecodeFromBytes(data, df) 1974} 1975 1976func (m Dot11MgmtDisassociation) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 1977 buf, err := b.PrependBytes(2) 1978 1979 if err != nil { 1980 return err 1981 } 1982 1983 binary.LittleEndian.PutUint16(buf[0:2], uint16(m.Reason)) 1984 1985 return nil 1986} 1987 1988type Dot11MgmtAuthentication struct { 1989 Dot11Mgmt 1990 Algorithm Dot11Algorithm 1991 Sequence uint16 1992 Status Dot11Status 1993} 1994 1995func decodeDot11MgmtAuthentication(data []byte, p gopacket.PacketBuilder) error { 1996 d := &Dot11MgmtAuthentication{} 1997 return decodingLayerDecoder(d, data, p) 1998} 1999 2000func (m *Dot11MgmtAuthentication) LayerType() gopacket.LayerType { 2001 return LayerTypeDot11MgmtAuthentication 2002} 2003func (m *Dot11MgmtAuthentication) CanDecode() gopacket.LayerClass { 2004 return LayerTypeDot11MgmtAuthentication 2005} 2006func (m *Dot11MgmtAuthentication) NextLayerType() gopacket.LayerType { 2007 return LayerTypeDot11InformationElement 2008} 2009func (m *Dot11MgmtAuthentication) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 2010 if len(data) < 6 { 2011 df.SetTruncated() 2012 return fmt.Errorf("Dot11MgmtAuthentication length %v too short, %v required", len(data), 6) 2013 } 2014 m.Algorithm = Dot11Algorithm(binary.LittleEndian.Uint16(data[0:2])) 2015 m.Sequence = binary.LittleEndian.Uint16(data[2:4]) 2016 m.Status = Dot11Status(binary.LittleEndian.Uint16(data[4:6])) 2017 m.Payload = data[6:] 2018 return m.Dot11Mgmt.DecodeFromBytes(data, df) 2019} 2020 2021func (m Dot11MgmtAuthentication) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 2022 buf, err := b.PrependBytes(6) 2023 2024 if err != nil { 2025 return err 2026 } 2027 2028 binary.LittleEndian.PutUint16(buf[0:2], uint16(m.Algorithm)) 2029 binary.LittleEndian.PutUint16(buf[2:4], m.Sequence) 2030 binary.LittleEndian.PutUint16(buf[4:6], uint16(m.Status)) 2031 2032 return nil 2033} 2034 2035type Dot11MgmtDeauthentication struct { 2036 Dot11Mgmt 2037 Reason Dot11Reason 2038} 2039 2040func decodeDot11MgmtDeauthentication(data []byte, p gopacket.PacketBuilder) error { 2041 d := &Dot11MgmtDeauthentication{} 2042 return decodingLayerDecoder(d, data, p) 2043} 2044 2045func (m *Dot11MgmtDeauthentication) LayerType() gopacket.LayerType { 2046 return LayerTypeDot11MgmtDeauthentication 2047} 2048func (m *Dot11MgmtDeauthentication) CanDecode() gopacket.LayerClass { 2049 return LayerTypeDot11MgmtDeauthentication 2050} 2051func (m *Dot11MgmtDeauthentication) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { 2052 if len(data) < 2 { 2053 df.SetTruncated() 2054 return fmt.Errorf("Dot11MgmtDeauthentication length %v too short, %v required", len(data), 2) 2055 } 2056 m.Reason = Dot11Reason(binary.LittleEndian.Uint16(data[0:2])) 2057 return m.Dot11Mgmt.DecodeFromBytes(data, df) 2058} 2059 2060func (m Dot11MgmtDeauthentication) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { 2061 buf, err := b.PrependBytes(2) 2062 2063 if err != nil { 2064 return err 2065 } 2066 2067 binary.LittleEndian.PutUint16(buf[0:2], uint16(m.Reason)) 2068 2069 return nil 2070} 2071 2072type Dot11MgmtAction struct { 2073 Dot11Mgmt 2074} 2075 2076func decodeDot11MgmtAction(data []byte, p gopacket.PacketBuilder) error { 2077 d := &Dot11MgmtAction{} 2078 return decodingLayerDecoder(d, data, p) 2079} 2080 2081func (m *Dot11MgmtAction) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtAction } 2082func (m *Dot11MgmtAction) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtAction } 2083 2084type Dot11MgmtActionNoAck struct { 2085 Dot11Mgmt 2086} 2087 2088func decodeDot11MgmtActionNoAck(data []byte, p gopacket.PacketBuilder) error { 2089 d := &Dot11MgmtActionNoAck{} 2090 return decodingLayerDecoder(d, data, p) 2091} 2092 2093func (m *Dot11MgmtActionNoAck) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtActionNoAck } 2094func (m *Dot11MgmtActionNoAck) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtActionNoAck } 2095 2096type Dot11MgmtArubaWLAN struct { 2097 Dot11Mgmt 2098} 2099 2100func decodeDot11MgmtArubaWLAN(data []byte, p gopacket.PacketBuilder) error { 2101 d := &Dot11MgmtArubaWLAN{} 2102 return decodingLayerDecoder(d, data, p) 2103} 2104 2105func (m *Dot11MgmtArubaWLAN) LayerType() gopacket.LayerType { return LayerTypeDot11MgmtArubaWLAN } 2106func (m *Dot11MgmtArubaWLAN) CanDecode() gopacket.LayerClass { return LayerTypeDot11MgmtArubaWLAN } 2107