print-802_11.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365
  1. /*
  2. * Copyright (c) 2001
  3. * Fortress Technologies, Inc. All rights reserved.
  4. * Charlie Lenahan (clenahan@fortresstech.com)
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that: (1) source code distributions
  8. * retain the above copyright notice and this paragraph in its entirety, (2)
  9. * distributions including binary code include the above copyright notice and
  10. * this paragraph in its entirety in the documentation or other materials
  11. * provided with the distribution, and (3) all advertising materials mentioning
  12. * features or use of this software display the following acknowledgement:
  13. * ``This product includes software developed by the University of California,
  14. * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
  15. * the University nor the names of its contributors may be used to endorse
  16. * or promote products derived from this software without specific prior
  17. * written permission.
  18. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  19. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  20. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  21. */
  22. /* \summary: IEEE 802.11 printer */
  23. #ifdef HAVE_CONFIG_H
  24. #include "config.h"
  25. #endif
  26. #include <netdissect-stdinc.h>
  27. #include <string.h>
  28. #include "netdissect.h"
  29. #include "addrtoname.h"
  30. #include "extract.h"
  31. #include "cpack.h"
  32. /* Lengths of 802.11 header components. */
  33. #define IEEE802_11_FC_LEN 2
  34. #define IEEE802_11_DUR_LEN 2
  35. #define IEEE802_11_DA_LEN 6
  36. #define IEEE802_11_SA_LEN 6
  37. #define IEEE802_11_BSSID_LEN 6
  38. #define IEEE802_11_RA_LEN 6
  39. #define IEEE802_11_TA_LEN 6
  40. #define IEEE802_11_ADDR1_LEN 6
  41. #define IEEE802_11_SEQ_LEN 2
  42. #define IEEE802_11_CTL_LEN 2
  43. #define IEEE802_11_CARRIED_FC_LEN 2
  44. #define IEEE802_11_HT_CONTROL_LEN 4
  45. #define IEEE802_11_IV_LEN 3
  46. #define IEEE802_11_KID_LEN 1
  47. /* Frame check sequence length. */
  48. #define IEEE802_11_FCS_LEN 4
  49. /* Lengths of beacon components. */
  50. #define IEEE802_11_TSTAMP_LEN 8
  51. #define IEEE802_11_BCNINT_LEN 2
  52. #define IEEE802_11_CAPINFO_LEN 2
  53. #define IEEE802_11_LISTENINT_LEN 2
  54. #define IEEE802_11_AID_LEN 2
  55. #define IEEE802_11_STATUS_LEN 2
  56. #define IEEE802_11_REASON_LEN 2
  57. /* Length of previous AP in reassocation frame */
  58. #define IEEE802_11_AP_LEN 6
  59. #define T_MGMT 0x0 /* management */
  60. #define T_CTRL 0x1 /* control */
  61. #define T_DATA 0x2 /* data */
  62. #define T_RESV 0x3 /* reserved */
  63. #define ST_ASSOC_REQUEST 0x0
  64. #define ST_ASSOC_RESPONSE 0x1
  65. #define ST_REASSOC_REQUEST 0x2
  66. #define ST_REASSOC_RESPONSE 0x3
  67. #define ST_PROBE_REQUEST 0x4
  68. #define ST_PROBE_RESPONSE 0x5
  69. /* RESERVED 0x6 */
  70. /* RESERVED 0x7 */
  71. #define ST_BEACON 0x8
  72. #define ST_ATIM 0x9
  73. #define ST_DISASSOC 0xA
  74. #define ST_AUTH 0xB
  75. #define ST_DEAUTH 0xC
  76. #define ST_ACTION 0xD
  77. /* RESERVED 0xE */
  78. /* RESERVED 0xF */
  79. static const struct tok st_str[] = {
  80. { ST_ASSOC_REQUEST, "Assoc Request" },
  81. { ST_ASSOC_RESPONSE, "Assoc Response" },
  82. { ST_REASSOC_REQUEST, "ReAssoc Request" },
  83. { ST_REASSOC_RESPONSE, "ReAssoc Response" },
  84. { ST_PROBE_REQUEST, "Probe Request" },
  85. { ST_PROBE_RESPONSE, "Probe Response" },
  86. { ST_BEACON, "Beacon" },
  87. { ST_ATIM, "ATIM" },
  88. { ST_DISASSOC, "Disassociation" },
  89. { ST_AUTH, "Authentication" },
  90. { ST_DEAUTH, "DeAuthentication" },
  91. { ST_ACTION, "Action" },
  92. { 0, NULL }
  93. };
  94. #define CTRL_CONTROL_WRAPPER 0x7
  95. #define CTRL_BAR 0x8
  96. #define CTRL_BA 0x9
  97. #define CTRL_PS_POLL 0xA
  98. #define CTRL_RTS 0xB
  99. #define CTRL_CTS 0xC
  100. #define CTRL_ACK 0xD
  101. #define CTRL_CF_END 0xE
  102. #define CTRL_END_ACK 0xF
  103. static const struct tok ctrl_str[] = {
  104. { CTRL_CONTROL_WRAPPER, "Control Wrapper" },
  105. { CTRL_BAR, "BAR" },
  106. { CTRL_BA, "BA" },
  107. { CTRL_PS_POLL, "Power Save-Poll" },
  108. { CTRL_RTS, "Request-To-Send" },
  109. { CTRL_CTS, "Clear-To-Send" },
  110. { CTRL_ACK, "Acknowledgment" },
  111. { CTRL_CF_END, "CF-End" },
  112. { CTRL_END_ACK, "CF-End+CF-Ack" },
  113. { 0, NULL }
  114. };
  115. #define DATA_DATA 0x0
  116. #define DATA_DATA_CF_ACK 0x1
  117. #define DATA_DATA_CF_POLL 0x2
  118. #define DATA_DATA_CF_ACK_POLL 0x3
  119. #define DATA_NODATA 0x4
  120. #define DATA_NODATA_CF_ACK 0x5
  121. #define DATA_NODATA_CF_POLL 0x6
  122. #define DATA_NODATA_CF_ACK_POLL 0x7
  123. #define DATA_QOS_DATA 0x8
  124. #define DATA_QOS_DATA_CF_ACK 0x9
  125. #define DATA_QOS_DATA_CF_POLL 0xA
  126. #define DATA_QOS_DATA_CF_ACK_POLL 0xB
  127. #define DATA_QOS_NODATA 0xC
  128. #define DATA_QOS_CF_POLL_NODATA 0xE
  129. #define DATA_QOS_CF_ACK_POLL_NODATA 0xF
  130. /*
  131. * The subtype field of a data frame is, in effect, composed of 4 flag
  132. * bits - CF-Ack, CF-Poll, Null (means the frame doesn't actually have
  133. * any data), and QoS.
  134. */
  135. #define DATA_FRAME_IS_CF_ACK(x) ((x) & 0x01)
  136. #define DATA_FRAME_IS_CF_POLL(x) ((x) & 0x02)
  137. #define DATA_FRAME_IS_NULL(x) ((x) & 0x04)
  138. #define DATA_FRAME_IS_QOS(x) ((x) & 0x08)
  139. /*
  140. * Bits in the frame control field.
  141. */
  142. #define FC_VERSION(fc) ((fc) & 0x3)
  143. #define FC_TYPE(fc) (((fc) >> 2) & 0x3)
  144. #define FC_SUBTYPE(fc) (((fc) >> 4) & 0xF)
  145. #define FC_TO_DS(fc) ((fc) & 0x0100)
  146. #define FC_FROM_DS(fc) ((fc) & 0x0200)
  147. #define FC_MORE_FLAG(fc) ((fc) & 0x0400)
  148. #define FC_RETRY(fc) ((fc) & 0x0800)
  149. #define FC_POWER_MGMT(fc) ((fc) & 0x1000)
  150. #define FC_MORE_DATA(fc) ((fc) & 0x2000)
  151. #define FC_PROTECTED(fc) ((fc) & 0x4000)
  152. #define FC_ORDER(fc) ((fc) & 0x8000)
  153. struct mgmt_header_t {
  154. uint16_t fc;
  155. uint16_t duration;
  156. uint8_t da[IEEE802_11_DA_LEN];
  157. uint8_t sa[IEEE802_11_SA_LEN];
  158. uint8_t bssid[IEEE802_11_BSSID_LEN];
  159. uint16_t seq_ctrl;
  160. };
  161. #define MGMT_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
  162. IEEE802_11_DA_LEN+IEEE802_11_SA_LEN+\
  163. IEEE802_11_BSSID_LEN+IEEE802_11_SEQ_LEN)
  164. #define CAPABILITY_ESS(cap) ((cap) & 0x0001)
  165. #define CAPABILITY_IBSS(cap) ((cap) & 0x0002)
  166. #define CAPABILITY_CFP(cap) ((cap) & 0x0004)
  167. #define CAPABILITY_CFP_REQ(cap) ((cap) & 0x0008)
  168. #define CAPABILITY_PRIVACY(cap) ((cap) & 0x0010)
  169. struct ssid_t {
  170. uint8_t element_id;
  171. uint8_t length;
  172. u_char ssid[33]; /* 32 + 1 for null */
  173. };
  174. struct rates_t {
  175. uint8_t element_id;
  176. uint8_t length;
  177. uint8_t rate[16];
  178. };
  179. struct challenge_t {
  180. uint8_t element_id;
  181. uint8_t length;
  182. uint8_t text[254]; /* 1-253 + 1 for null */
  183. };
  184. struct fh_t {
  185. uint8_t element_id;
  186. uint8_t length;
  187. uint16_t dwell_time;
  188. uint8_t hop_set;
  189. uint8_t hop_pattern;
  190. uint8_t hop_index;
  191. };
  192. struct ds_t {
  193. uint8_t element_id;
  194. uint8_t length;
  195. uint8_t channel;
  196. };
  197. struct cf_t {
  198. uint8_t element_id;
  199. uint8_t length;
  200. uint8_t count;
  201. uint8_t period;
  202. uint16_t max_duration;
  203. uint16_t dur_remaing;
  204. };
  205. struct tim_t {
  206. uint8_t element_id;
  207. uint8_t length;
  208. uint8_t count;
  209. uint8_t period;
  210. uint8_t bitmap_control;
  211. uint8_t bitmap[251];
  212. };
  213. #define E_SSID 0
  214. #define E_RATES 1
  215. #define E_FH 2
  216. #define E_DS 3
  217. #define E_CF 4
  218. #define E_TIM 5
  219. #define E_IBSS 6
  220. /* reserved 7 */
  221. /* reserved 8 */
  222. /* reserved 9 */
  223. /* reserved 10 */
  224. /* reserved 11 */
  225. /* reserved 12 */
  226. /* reserved 13 */
  227. /* reserved 14 */
  228. /* reserved 15 */
  229. /* reserved 16 */
  230. #define E_CHALLENGE 16
  231. /* reserved 17 */
  232. /* reserved 18 */
  233. /* reserved 19 */
  234. /* reserved 16 */
  235. /* reserved 16 */
  236. struct mgmt_body_t {
  237. uint8_t timestamp[IEEE802_11_TSTAMP_LEN];
  238. uint16_t beacon_interval;
  239. uint16_t listen_interval;
  240. uint16_t status_code;
  241. uint16_t aid;
  242. u_char ap[IEEE802_11_AP_LEN];
  243. uint16_t reason_code;
  244. uint16_t auth_alg;
  245. uint16_t auth_trans_seq_num;
  246. int challenge_present;
  247. struct challenge_t challenge;
  248. uint16_t capability_info;
  249. int ssid_present;
  250. struct ssid_t ssid;
  251. int rates_present;
  252. struct rates_t rates;
  253. int ds_present;
  254. struct ds_t ds;
  255. int cf_present;
  256. struct cf_t cf;
  257. int fh_present;
  258. struct fh_t fh;
  259. int tim_present;
  260. struct tim_t tim;
  261. };
  262. struct ctrl_control_wrapper_hdr_t {
  263. uint16_t fc;
  264. uint16_t duration;
  265. uint8_t addr1[IEEE802_11_ADDR1_LEN];
  266. uint16_t carried_fc[IEEE802_11_CARRIED_FC_LEN];
  267. uint16_t ht_control[IEEE802_11_HT_CONTROL_LEN];
  268. };
  269. #define CTRL_CONTROL_WRAPPER_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
  270. IEEE802_11_ADDR1_LEN+\
  271. IEEE802_11_CARRIED_FC_LEN+\
  272. IEEE802_11_HT_CONTROL_LEN)
  273. struct ctrl_rts_hdr_t {
  274. uint16_t fc;
  275. uint16_t duration;
  276. uint8_t ra[IEEE802_11_RA_LEN];
  277. uint8_t ta[IEEE802_11_TA_LEN];
  278. };
  279. #define CTRL_RTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
  280. IEEE802_11_RA_LEN+IEEE802_11_TA_LEN)
  281. struct ctrl_cts_hdr_t {
  282. uint16_t fc;
  283. uint16_t duration;
  284. uint8_t ra[IEEE802_11_RA_LEN];
  285. };
  286. #define CTRL_CTS_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
  287. struct ctrl_ack_hdr_t {
  288. uint16_t fc;
  289. uint16_t duration;
  290. uint8_t ra[IEEE802_11_RA_LEN];
  291. };
  292. #define CTRL_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
  293. struct ctrl_ps_poll_hdr_t {
  294. uint16_t fc;
  295. uint16_t aid;
  296. uint8_t bssid[IEEE802_11_BSSID_LEN];
  297. uint8_t ta[IEEE802_11_TA_LEN];
  298. };
  299. #define CTRL_PS_POLL_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_AID_LEN+\
  300. IEEE802_11_BSSID_LEN+IEEE802_11_TA_LEN)
  301. struct ctrl_end_hdr_t {
  302. uint16_t fc;
  303. uint16_t duration;
  304. uint8_t ra[IEEE802_11_RA_LEN];
  305. uint8_t bssid[IEEE802_11_BSSID_LEN];
  306. };
  307. #define CTRL_END_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
  308. IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
  309. struct ctrl_end_ack_hdr_t {
  310. uint16_t fc;
  311. uint16_t duration;
  312. uint8_t ra[IEEE802_11_RA_LEN];
  313. uint8_t bssid[IEEE802_11_BSSID_LEN];
  314. };
  315. #define CTRL_END_ACK_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
  316. IEEE802_11_RA_LEN+IEEE802_11_BSSID_LEN)
  317. struct ctrl_ba_hdr_t {
  318. uint16_t fc;
  319. uint16_t duration;
  320. uint8_t ra[IEEE802_11_RA_LEN];
  321. };
  322. #define CTRL_BA_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+IEEE802_11_RA_LEN)
  323. struct ctrl_bar_hdr_t {
  324. uint16_t fc;
  325. uint16_t dur;
  326. uint8_t ra[IEEE802_11_RA_LEN];
  327. uint8_t ta[IEEE802_11_TA_LEN];
  328. uint16_t ctl;
  329. uint16_t seq;
  330. };
  331. #define CTRL_BAR_HDRLEN (IEEE802_11_FC_LEN+IEEE802_11_DUR_LEN+\
  332. IEEE802_11_RA_LEN+IEEE802_11_TA_LEN+\
  333. IEEE802_11_CTL_LEN+IEEE802_11_SEQ_LEN)
  334. struct meshcntl_t {
  335. uint8_t flags;
  336. uint8_t ttl;
  337. uint8_t seq[4];
  338. uint8_t addr4[6];
  339. uint8_t addr5[6];
  340. uint8_t addr6[6];
  341. };
  342. #define IV_IV(iv) ((iv) & 0xFFFFFF)
  343. #define IV_PAD(iv) (((iv) >> 24) & 0x3F)
  344. #define IV_KEYID(iv) (((iv) >> 30) & 0x03)
  345. #define PRINT_SSID(p) \
  346. if (p.ssid_present) { \
  347. ND_PRINT((ndo, " (")); \
  348. fn_print(ndo, p.ssid.ssid, NULL); \
  349. ND_PRINT((ndo, ")")); \
  350. }
  351. #define PRINT_RATE(_sep, _r, _suf) \
  352. ND_PRINT((ndo, "%s%2.1f%s", _sep, (.5 * ((_r) & 0x7f)), _suf))
  353. #define PRINT_RATES(p) \
  354. if (p.rates_present) { \
  355. int z; \
  356. const char *sep = " ["; \
  357. for (z = 0; z < p.rates.length ; z++) { \
  358. PRINT_RATE(sep, p.rates.rate[z], \
  359. (p.rates.rate[z] & 0x80 ? "*" : "")); \
  360. sep = " "; \
  361. } \
  362. if (p.rates.length != 0) \
  363. ND_PRINT((ndo, " Mbit]")); \
  364. }
  365. #define PRINT_DS_CHANNEL(p) \
  366. if (p.ds_present) \
  367. ND_PRINT((ndo, " CH: %u", p.ds.channel)); \
  368. ND_PRINT((ndo, "%s", \
  369. CAPABILITY_PRIVACY(p.capability_info) ? ", PRIVACY" : ""));
  370. #define MAX_MCS_INDEX 76
  371. /*
  372. * Indices are:
  373. *
  374. * the MCS index (0-76);
  375. *
  376. * 0 for 20 MHz, 1 for 40 MHz;
  377. *
  378. * 0 for a long guard interval, 1 for a short guard interval.
  379. */
  380. static const float ieee80211_float_htrates[MAX_MCS_INDEX+1][2][2] = {
  381. /* MCS 0 */
  382. { /* 20 Mhz */ { 6.5, /* SGI */ 7.2, },
  383. /* 40 Mhz */ { 13.5, /* SGI */ 15.0, },
  384. },
  385. /* MCS 1 */
  386. { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
  387. /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
  388. },
  389. /* MCS 2 */
  390. { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
  391. /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
  392. },
  393. /* MCS 3 */
  394. { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
  395. /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
  396. },
  397. /* MCS 4 */
  398. { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
  399. /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
  400. },
  401. /* MCS 5 */
  402. { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
  403. /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
  404. },
  405. /* MCS 6 */
  406. { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
  407. /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
  408. },
  409. /* MCS 7 */
  410. { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
  411. /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
  412. },
  413. /* MCS 8 */
  414. { /* 20 Mhz */ { 13.0, /* SGI */ 14.4, },
  415. /* 40 Mhz */ { 27.0, /* SGI */ 30.0, },
  416. },
  417. /* MCS 9 */
  418. { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
  419. /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
  420. },
  421. /* MCS 10 */
  422. { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
  423. /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
  424. },
  425. /* MCS 11 */
  426. { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
  427. /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
  428. },
  429. /* MCS 12 */
  430. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  431. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  432. },
  433. /* MCS 13 */
  434. { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
  435. /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
  436. },
  437. /* MCS 14 */
  438. { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
  439. /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
  440. },
  441. /* MCS 15 */
  442. { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
  443. /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
  444. },
  445. /* MCS 16 */
  446. { /* 20 Mhz */ { 19.5, /* SGI */ 21.7, },
  447. /* 40 Mhz */ { 40.5, /* SGI */ 45.0, },
  448. },
  449. /* MCS 17 */
  450. { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
  451. /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
  452. },
  453. /* MCS 18 */
  454. { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
  455. /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
  456. },
  457. /* MCS 19 */
  458. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  459. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  460. },
  461. /* MCS 20 */
  462. { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
  463. /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
  464. },
  465. /* MCS 21 */
  466. { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
  467. /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
  468. },
  469. /* MCS 22 */
  470. { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
  471. /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
  472. },
  473. /* MCS 23 */
  474. { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
  475. /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
  476. },
  477. /* MCS 24 */
  478. { /* 20 Mhz */ { 26.0, /* SGI */ 28.9, },
  479. /* 40 Mhz */ { 54.0, /* SGI */ 60.0, },
  480. },
  481. /* MCS 25 */
  482. { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
  483. /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
  484. },
  485. /* MCS 26 */
  486. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  487. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  488. },
  489. /* MCS 27 */
  490. { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
  491. /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
  492. },
  493. /* MCS 28 */
  494. { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
  495. /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
  496. },
  497. /* MCS 29 */
  498. { /* 20 Mhz */ { 208.0, /* SGI */ 231.1, },
  499. /* 40 Mhz */ { 432.0, /* SGI */ 480.0, },
  500. },
  501. /* MCS 30 */
  502. { /* 20 Mhz */ { 234.0, /* SGI */ 260.0, },
  503. /* 40 Mhz */ { 486.0, /* SGI */ 540.0, },
  504. },
  505. /* MCS 31 */
  506. { /* 20 Mhz */ { 260.0, /* SGI */ 288.9, },
  507. /* 40 Mhz */ { 540.0, /* SGI */ 600.0, },
  508. },
  509. /* MCS 32 */
  510. { /* 20 Mhz */ { 0.0, /* SGI */ 0.0, }, /* not valid */
  511. /* 40 Mhz */ { 6.0, /* SGI */ 6.7, },
  512. },
  513. /* MCS 33 */
  514. { /* 20 Mhz */ { 39.0, /* SGI */ 43.3, },
  515. /* 40 Mhz */ { 81.0, /* SGI */ 90.0, },
  516. },
  517. /* MCS 34 */
  518. { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
  519. /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
  520. },
  521. /* MCS 35 */
  522. { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
  523. /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
  524. },
  525. /* MCS 36 */
  526. { /* 20 Mhz */ { 58.5, /* SGI */ 65.0, },
  527. /* 40 Mhz */ { 121.5, /* SGI */ 135.0, },
  528. },
  529. /* MCS 37 */
  530. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  531. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  532. },
  533. /* MCS 38 */
  534. { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
  535. /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
  536. },
  537. /* MCS 39 */
  538. { /* 20 Mhz */ { 52.0, /* SGI */ 57.8, },
  539. /* 40 Mhz */ { 108.0, /* SGI */ 120.0, },
  540. },
  541. /* MCS 40 */
  542. { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
  543. /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
  544. },
  545. /* MCS 41 */
  546. { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
  547. /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
  548. },
  549. /* MCS 42 */
  550. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  551. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  552. },
  553. /* MCS 43 */
  554. { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
  555. /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
  556. },
  557. /* MCS 44 */
  558. { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
  559. /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
  560. },
  561. /* MCS 45 */
  562. { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
  563. /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
  564. },
  565. /* MCS 46 */
  566. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  567. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  568. },
  569. /* MCS 47 */
  570. { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
  571. /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
  572. },
  573. /* MCS 48 */
  574. { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
  575. /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
  576. },
  577. /* MCS 49 */
  578. { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
  579. /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
  580. },
  581. /* MCS 50 */
  582. { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
  583. /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
  584. },
  585. /* MCS 51 */
  586. { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
  587. /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
  588. },
  589. /* MCS 52 */
  590. { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
  591. /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
  592. },
  593. /* MCS 53 */
  594. { /* 20 Mhz */ { 65.0, /* SGI */ 72.2, },
  595. /* 40 Mhz */ { 135.0, /* SGI */ 150.0, },
  596. },
  597. /* MCS 54 */
  598. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  599. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  600. },
  601. /* MCS 55 */
  602. { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
  603. /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
  604. },
  605. /* MCS 56 */
  606. { /* 20 Mhz */ { 78.0, /* SGI */ 86.7, },
  607. /* 40 Mhz */ { 162.0, /* SGI */ 180.0, },
  608. },
  609. /* MCS 57 */
  610. { /* 20 Mhz */ { 91.0, /* SGI */ 101.1, },
  611. /* 40 Mhz */ { 189.0, /* SGI */ 210.0, },
  612. },
  613. /* MCS 58 */
  614. { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
  615. /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
  616. },
  617. /* MCS 59 */
  618. { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
  619. /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
  620. },
  621. /* MCS 60 */
  622. { /* 20 Mhz */ { 104.0, /* SGI */ 115.6, },
  623. /* 40 Mhz */ { 216.0, /* SGI */ 240.0, },
  624. },
  625. /* MCS 61 */
  626. { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
  627. /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
  628. },
  629. /* MCS 62 */
  630. { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
  631. /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
  632. },
  633. /* MCS 63 */
  634. { /* 20 Mhz */ { 130.0, /* SGI */ 144.4, },
  635. /* 40 Mhz */ { 270.0, /* SGI */ 300.0, },
  636. },
  637. /* MCS 64 */
  638. { /* 20 Mhz */ { 143.0, /* SGI */ 158.9, },
  639. /* 40 Mhz */ { 297.0, /* SGI */ 330.0, },
  640. },
  641. /* MCS 65 */
  642. { /* 20 Mhz */ { 97.5, /* SGI */ 108.3, },
  643. /* 40 Mhz */ { 202.5, /* SGI */ 225.0, },
  644. },
  645. /* MCS 66 */
  646. { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
  647. /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
  648. },
  649. /* MCS 67 */
  650. { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
  651. /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
  652. },
  653. /* MCS 68 */
  654. { /* 20 Mhz */ { 117.0, /* SGI */ 130.0, },
  655. /* 40 Mhz */ { 243.0, /* SGI */ 270.0, },
  656. },
  657. /* MCS 69 */
  658. { /* 20 Mhz */ { 136.5, /* SGI */ 151.7, },
  659. /* 40 Mhz */ { 283.5, /* SGI */ 315.0, },
  660. },
  661. /* MCS 70 */
  662. { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
  663. /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
  664. },
  665. /* MCS 71 */
  666. { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
  667. /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
  668. },
  669. /* MCS 72 */
  670. { /* 20 Mhz */ { 156.0, /* SGI */ 173.3, },
  671. /* 40 Mhz */ { 324.0, /* SGI */ 360.0, },
  672. },
  673. /* MCS 73 */
  674. { /* 20 Mhz */ { 175.5, /* SGI */ 195.0, },
  675. /* 40 Mhz */ { 364.5, /* SGI */ 405.0, },
  676. },
  677. /* MCS 74 */
  678. { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
  679. /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
  680. },
  681. /* MCS 75 */
  682. { /* 20 Mhz */ { 195.0, /* SGI */ 216.7, },
  683. /* 40 Mhz */ { 405.0, /* SGI */ 450.0, },
  684. },
  685. /* MCS 76 */
  686. { /* 20 Mhz */ { 214.5, /* SGI */ 238.3, },
  687. /* 40 Mhz */ { 445.5, /* SGI */ 495.0, },
  688. },
  689. };
  690. static const char *auth_alg_text[]={"Open System","Shared Key","EAP"};
  691. #define NUM_AUTH_ALGS (sizeof auth_alg_text / sizeof auth_alg_text[0])
  692. static const char *status_text[] = {
  693. "Successful", /* 0 */
  694. "Unspecified failure", /* 1 */
  695. "Reserved", /* 2 */
  696. "Reserved", /* 3 */
  697. "Reserved", /* 4 */
  698. "Reserved", /* 5 */
  699. "Reserved", /* 6 */
  700. "Reserved", /* 7 */
  701. "Reserved", /* 8 */
  702. "Reserved", /* 9 */
  703. "Cannot Support all requested capabilities in the Capability "
  704. "Information field", /* 10 */
  705. "Reassociation denied due to inability to confirm that association "
  706. "exists", /* 11 */
  707. "Association denied due to reason outside the scope of the "
  708. "standard", /* 12 */
  709. "Responding station does not support the specified authentication "
  710. "algorithm ", /* 13 */
  711. "Received an Authentication frame with authentication transaction "
  712. "sequence number out of expected sequence", /* 14 */
  713. "Authentication rejected because of challenge failure", /* 15 */
  714. "Authentication rejected due to timeout waiting for next frame in "
  715. "sequence", /* 16 */
  716. "Association denied because AP is unable to handle additional"
  717. "associated stations", /* 17 */
  718. "Association denied due to requesting station not supporting all of "
  719. "the data rates in BSSBasicRateSet parameter", /* 18 */
  720. "Association denied due to requesting station not supporting "
  721. "short preamble operation", /* 19 */
  722. "Association denied due to requesting station not supporting "
  723. "PBCC encoding", /* 20 */
  724. "Association denied due to requesting station not supporting "
  725. "channel agility", /* 21 */
  726. "Association request rejected because Spectrum Management "
  727. "capability is required", /* 22 */
  728. "Association request rejected because the information in the "
  729. "Power Capability element is unacceptable", /* 23 */
  730. "Association request rejected because the information in the "
  731. "Supported Channels element is unacceptable", /* 24 */
  732. "Association denied due to requesting station not supporting "
  733. "short slot operation", /* 25 */
  734. "Association denied due to requesting station not supporting "
  735. "DSSS-OFDM operation", /* 26 */
  736. "Association denied because the requested STA does not support HT "
  737. "features", /* 27 */
  738. "Reserved", /* 28 */
  739. "Association denied because the requested STA does not support "
  740. "the PCO transition time required by the AP", /* 29 */
  741. "Reserved", /* 30 */
  742. "Reserved", /* 31 */
  743. "Unspecified, QoS-related failure", /* 32 */
  744. "Association denied due to QAP having insufficient bandwidth "
  745. "to handle another QSTA", /* 33 */
  746. "Association denied due to excessive frame loss rates and/or "
  747. "poor conditions on current operating channel", /* 34 */
  748. "Association (with QBSS) denied due to requesting station not "
  749. "supporting the QoS facility", /* 35 */
  750. "Association denied due to requesting station not supporting "
  751. "Block Ack", /* 36 */
  752. "The request has been declined", /* 37 */
  753. "The request has not been successful as one or more parameters "
  754. "have invalid values", /* 38 */
  755. "The TS has not been created because the request cannot be honored. "
  756. "Try again with the suggested changes to the TSPEC", /* 39 */
  757. "Invalid Information Element", /* 40 */
  758. "Group Cipher is not valid", /* 41 */
  759. "Pairwise Cipher is not valid", /* 42 */
  760. "AKMP is not valid", /* 43 */
  761. "Unsupported RSN IE version", /* 44 */
  762. "Invalid RSN IE Capabilities", /* 45 */
  763. "Cipher suite is rejected per security policy", /* 46 */
  764. "The TS has not been created. However, the HC may be capable of "
  765. "creating a TS, in response to a request, after the time indicated "
  766. "in the TS Delay element", /* 47 */
  767. "Direct Link is not allowed in the BSS by policy", /* 48 */
  768. "Destination STA is not present within this QBSS.", /* 49 */
  769. "The Destination STA is not a QSTA.", /* 50 */
  770. };
  771. #define NUM_STATUSES (sizeof status_text / sizeof status_text[0])
  772. static const char *reason_text[] = {
  773. "Reserved", /* 0 */
  774. "Unspecified reason", /* 1 */
  775. "Previous authentication no longer valid", /* 2 */
  776. "Deauthenticated because sending station is leaving (or has left) "
  777. "IBSS or ESS", /* 3 */
  778. "Disassociated due to inactivity", /* 4 */
  779. "Disassociated because AP is unable to handle all currently "
  780. " associated stations", /* 5 */
  781. "Class 2 frame received from nonauthenticated station", /* 6 */
  782. "Class 3 frame received from nonassociated station", /* 7 */
  783. "Disassociated because sending station is leaving "
  784. "(or has left) BSS", /* 8 */
  785. "Station requesting (re)association is not authenticated with "
  786. "responding station", /* 9 */
  787. "Disassociated because the information in the Power Capability "
  788. "element is unacceptable", /* 10 */
  789. "Disassociated because the information in the SupportedChannels "
  790. "element is unacceptable", /* 11 */
  791. "Invalid Information Element", /* 12 */
  792. "Reserved", /* 13 */
  793. "Michael MIC failure", /* 14 */
  794. "4-Way Handshake timeout", /* 15 */
  795. "Group key update timeout", /* 16 */
  796. "Information element in 4-Way Handshake different from (Re)Association"
  797. "Request/Probe Response/Beacon", /* 17 */
  798. "Group Cipher is not valid", /* 18 */
  799. "AKMP is not valid", /* 20 */
  800. "Unsupported RSN IE version", /* 21 */
  801. "Invalid RSN IE Capabilities", /* 22 */
  802. "IEEE 802.1X Authentication failed", /* 23 */
  803. "Cipher suite is rejected per security policy", /* 24 */
  804. "Reserved", /* 25 */
  805. "Reserved", /* 26 */
  806. "Reserved", /* 27 */
  807. "Reserved", /* 28 */
  808. "Reserved", /* 29 */
  809. "Reserved", /* 30 */
  810. "TS deleted because QoS AP lacks sufficient bandwidth for this "
  811. "QoS STA due to a change in BSS service characteristics or "
  812. "operational mode (e.g. an HT BSS change from 40 MHz channel "
  813. "to 20 MHz channel)", /* 31 */
  814. "Disassociated for unspecified, QoS-related reason", /* 32 */
  815. "Disassociated because QoS AP lacks sufficient bandwidth for this "
  816. "QoS STA", /* 33 */
  817. "Disassociated because of excessive number of frames that need to be "
  818. "acknowledged, but are not acknowledged for AP transmissions "
  819. "and/or poor channel conditions", /* 34 */
  820. "Disassociated because STA is transmitting outside the limits "
  821. "of its TXOPs", /* 35 */
  822. "Requested from peer STA as the STA is leaving the BSS "
  823. "(or resetting)", /* 36 */
  824. "Requested from peer STA as it does not want to use the "
  825. "mechanism", /* 37 */
  826. "Requested from peer STA as the STA received frames using the "
  827. "mechanism for which a set up is required", /* 38 */
  828. "Requested from peer STA due to time out", /* 39 */
  829. "Reserved", /* 40 */
  830. "Reserved", /* 41 */
  831. "Reserved", /* 42 */
  832. "Reserved", /* 43 */
  833. "Reserved", /* 44 */
  834. "Peer STA does not support the requested cipher suite", /* 45 */
  835. "Association denied due to requesting STA not supporting HT "
  836. "features", /* 46 */
  837. };
  838. #define NUM_REASONS (sizeof reason_text / sizeof reason_text[0])
  839. static int
  840. wep_print(netdissect_options *ndo,
  841. const u_char *p)
  842. {
  843. uint32_t iv;
  844. if (!ND_TTEST2(*p, IEEE802_11_IV_LEN + IEEE802_11_KID_LEN))
  845. return 0;
  846. iv = EXTRACT_LE_32BITS(p);
  847. ND_PRINT((ndo, " IV:%3x Pad %x KeyID %x", IV_IV(iv), IV_PAD(iv),
  848. IV_KEYID(iv)));
  849. return 1;
  850. }
  851. static int
  852. parse_elements(netdissect_options *ndo,
  853. struct mgmt_body_t *pbody, const u_char *p, int offset,
  854. u_int length)
  855. {
  856. u_int elementlen;
  857. struct ssid_t ssid;
  858. struct challenge_t challenge;
  859. struct rates_t rates;
  860. struct ds_t ds;
  861. struct cf_t cf;
  862. struct tim_t tim;
  863. /*
  864. * We haven't seen any elements yet.
  865. */
  866. pbody->challenge_present = 0;
  867. pbody->ssid_present = 0;
  868. pbody->rates_present = 0;
  869. pbody->ds_present = 0;
  870. pbody->cf_present = 0;
  871. pbody->tim_present = 0;
  872. while (length != 0) {
  873. /* Make sure we at least have the element ID and length. */
  874. if (!ND_TTEST2(*(p + offset), 2))
  875. return 0;
  876. if (length < 2)
  877. return 0;
  878. elementlen = *(p + offset + 1);
  879. /* Make sure we have the entire element. */
  880. if (!ND_TTEST2(*(p + offset + 2), elementlen))
  881. return 0;
  882. if (length < elementlen + 2)
  883. return 0;
  884. switch (*(p + offset)) {
  885. case E_SSID:
  886. memcpy(&ssid, p + offset, 2);
  887. offset += 2;
  888. length -= 2;
  889. if (ssid.length != 0) {
  890. if (ssid.length > sizeof(ssid.ssid) - 1)
  891. return 0;
  892. memcpy(&ssid.ssid, p + offset, ssid.length);
  893. offset += ssid.length;
  894. length -= ssid.length;
  895. }
  896. ssid.ssid[ssid.length] = '\0';
  897. /*
  898. * Present and not truncated.
  899. *
  900. * If we haven't already seen an SSID IE,
  901. * copy this one, otherwise ignore this one,
  902. * so we later report the first one we saw.
  903. */
  904. if (!pbody->ssid_present) {
  905. pbody->ssid = ssid;
  906. pbody->ssid_present = 1;
  907. }
  908. break;
  909. case E_CHALLENGE:
  910. memcpy(&challenge, p + offset, 2);
  911. offset += 2;
  912. length -= 2;
  913. if (challenge.length != 0) {
  914. if (challenge.length >
  915. sizeof(challenge.text) - 1)
  916. return 0;
  917. memcpy(&challenge.text, p + offset,
  918. challenge.length);
  919. offset += challenge.length;
  920. length -= challenge.length;
  921. }
  922. challenge.text[challenge.length] = '\0';
  923. /*
  924. * Present and not truncated.
  925. *
  926. * If we haven't already seen a challenge IE,
  927. * copy this one, otherwise ignore this one,
  928. * so we later report the first one we saw.
  929. */
  930. if (!pbody->challenge_present) {
  931. pbody->challenge = challenge;
  932. pbody->challenge_present = 1;
  933. }
  934. break;
  935. case E_RATES:
  936. memcpy(&rates, p + offset, 2);
  937. offset += 2;
  938. length -= 2;
  939. if (rates.length != 0) {
  940. if (rates.length > sizeof rates.rate)
  941. return 0;
  942. memcpy(&rates.rate, p + offset, rates.length);
  943. offset += rates.length;
  944. length -= rates.length;
  945. }
  946. /*
  947. * Present and not truncated.
  948. *
  949. * If we haven't already seen a rates IE,
  950. * copy this one if it's not zero-length,
  951. * otherwise ignore this one, so we later
  952. * report the first one we saw.
  953. *
  954. * We ignore zero-length rates IEs as some
  955. * devices seem to put a zero-length rates
  956. * IE, followed by an SSID IE, followed by
  957. * a non-zero-length rates IE into frames,
  958. * even though IEEE Std 802.11-2007 doesn't
  959. * seem to indicate that a zero-length rates
  960. * IE is valid.
  961. */
  962. if (!pbody->rates_present && rates.length != 0) {
  963. pbody->rates = rates;
  964. pbody->rates_present = 1;
  965. }
  966. break;
  967. case E_DS:
  968. memcpy(&ds, p + offset, 2);
  969. offset += 2;
  970. length -= 2;
  971. if (ds.length != 1) {
  972. offset += ds.length;
  973. length -= ds.length;
  974. break;
  975. }
  976. ds.channel = *(p + offset);
  977. offset += 1;
  978. length -= 1;
  979. /*
  980. * Present and not truncated.
  981. *
  982. * If we haven't already seen a DS IE,
  983. * copy this one, otherwise ignore this one,
  984. * so we later report the first one we saw.
  985. */
  986. if (!pbody->ds_present) {
  987. pbody->ds = ds;
  988. pbody->ds_present = 1;
  989. }
  990. break;
  991. case E_CF:
  992. memcpy(&cf, p + offset, 2);
  993. offset += 2;
  994. length -= 2;
  995. if (cf.length != 6) {
  996. offset += cf.length;
  997. length -= cf.length;
  998. break;
  999. }
  1000. memcpy(&cf.count, p + offset, 6);
  1001. offset += 6;
  1002. length -= 6;
  1003. /*
  1004. * Present and not truncated.
  1005. *
  1006. * If we haven't already seen a CF IE,
  1007. * copy this one, otherwise ignore this one,
  1008. * so we later report the first one we saw.
  1009. */
  1010. if (!pbody->cf_present) {
  1011. pbody->cf = cf;
  1012. pbody->cf_present = 1;
  1013. }
  1014. break;
  1015. case E_TIM:
  1016. memcpy(&tim, p + offset, 2);
  1017. offset += 2;
  1018. length -= 2;
  1019. if (tim.length <= 3) {
  1020. offset += tim.length;
  1021. length -= tim.length;
  1022. break;
  1023. }
  1024. if (tim.length - 3 > (int)sizeof tim.bitmap)
  1025. return 0;
  1026. memcpy(&tim.count, p + offset, 3);
  1027. offset += 3;
  1028. length -= 3;
  1029. memcpy(tim.bitmap, p + offset, tim.length - 3);
  1030. offset += tim.length - 3;
  1031. length -= tim.length - 3;
  1032. /*
  1033. * Present and not truncated.
  1034. *
  1035. * If we haven't already seen a TIM IE,
  1036. * copy this one, otherwise ignore this one,
  1037. * so we later report the first one we saw.
  1038. */
  1039. if (!pbody->tim_present) {
  1040. pbody->tim = tim;
  1041. pbody->tim_present = 1;
  1042. }
  1043. break;
  1044. default:
  1045. #if 0
  1046. ND_PRINT((ndo, "(1) unhandled element_id (%d) ",
  1047. *(p + offset)));
  1048. #endif
  1049. offset += 2 + elementlen;
  1050. length -= 2 + elementlen;
  1051. break;
  1052. }
  1053. }
  1054. /* No problems found. */
  1055. return 1;
  1056. }
  1057. /*********************************************************************************
  1058. * Print Handle functions for the management frame types
  1059. *********************************************************************************/
  1060. static int
  1061. handle_beacon(netdissect_options *ndo,
  1062. const u_char *p, u_int length)
  1063. {
  1064. struct mgmt_body_t pbody;
  1065. int offset = 0;
  1066. int ret;
  1067. memset(&pbody, 0, sizeof(pbody));
  1068. if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
  1069. IEEE802_11_CAPINFO_LEN))
  1070. return 0;
  1071. if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
  1072. IEEE802_11_CAPINFO_LEN)
  1073. return 0;
  1074. memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
  1075. offset += IEEE802_11_TSTAMP_LEN;
  1076. length -= IEEE802_11_TSTAMP_LEN;
  1077. pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
  1078. offset += IEEE802_11_BCNINT_LEN;
  1079. length -= IEEE802_11_BCNINT_LEN;
  1080. pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
  1081. offset += IEEE802_11_CAPINFO_LEN;
  1082. length -= IEEE802_11_CAPINFO_LEN;
  1083. ret = parse_elements(ndo, &pbody, p, offset, length);
  1084. PRINT_SSID(pbody);
  1085. PRINT_RATES(pbody);
  1086. ND_PRINT((ndo, " %s",
  1087. CAPABILITY_ESS(pbody.capability_info) ? "ESS" : "IBSS"));
  1088. PRINT_DS_CHANNEL(pbody);
  1089. return ret;
  1090. }
  1091. static int
  1092. handle_assoc_request(netdissect_options *ndo,
  1093. const u_char *p, u_int length)
  1094. {
  1095. struct mgmt_body_t pbody;
  1096. int offset = 0;
  1097. int ret;
  1098. memset(&pbody, 0, sizeof(pbody));
  1099. if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN))
  1100. return 0;
  1101. if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN)
  1102. return 0;
  1103. pbody.capability_info = EXTRACT_LE_16BITS(p);
  1104. offset += IEEE802_11_CAPINFO_LEN;
  1105. length -= IEEE802_11_CAPINFO_LEN;
  1106. pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
  1107. offset += IEEE802_11_LISTENINT_LEN;
  1108. length -= IEEE802_11_LISTENINT_LEN;
  1109. ret = parse_elements(ndo, &pbody, p, offset, length);
  1110. PRINT_SSID(pbody);
  1111. PRINT_RATES(pbody);
  1112. return ret;
  1113. }
  1114. static int
  1115. handle_assoc_response(netdissect_options *ndo,
  1116. const u_char *p, u_int length)
  1117. {
  1118. struct mgmt_body_t pbody;
  1119. int offset = 0;
  1120. int ret;
  1121. memset(&pbody, 0, sizeof(pbody));
  1122. if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
  1123. IEEE802_11_AID_LEN))
  1124. return 0;
  1125. if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_STATUS_LEN +
  1126. IEEE802_11_AID_LEN)
  1127. return 0;
  1128. pbody.capability_info = EXTRACT_LE_16BITS(p);
  1129. offset += IEEE802_11_CAPINFO_LEN;
  1130. length -= IEEE802_11_CAPINFO_LEN;
  1131. pbody.status_code = EXTRACT_LE_16BITS(p+offset);
  1132. offset += IEEE802_11_STATUS_LEN;
  1133. length -= IEEE802_11_STATUS_LEN;
  1134. pbody.aid = EXTRACT_LE_16BITS(p+offset);
  1135. offset += IEEE802_11_AID_LEN;
  1136. length -= IEEE802_11_AID_LEN;
  1137. ret = parse_elements(ndo, &pbody, p, offset, length);
  1138. ND_PRINT((ndo, " AID(%x) :%s: %s", ((uint16_t)(pbody.aid << 2 )) >> 2 ,
  1139. CAPABILITY_PRIVACY(pbody.capability_info) ? " PRIVACY " : "",
  1140. (pbody.status_code < NUM_STATUSES
  1141. ? status_text[pbody.status_code]
  1142. : "n/a")));
  1143. return ret;
  1144. }
  1145. static int
  1146. handle_reassoc_request(netdissect_options *ndo,
  1147. const u_char *p, u_int length)
  1148. {
  1149. struct mgmt_body_t pbody;
  1150. int offset = 0;
  1151. int ret;
  1152. memset(&pbody, 0, sizeof(pbody));
  1153. if (!ND_TTEST2(*p, IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
  1154. IEEE802_11_AP_LEN))
  1155. return 0;
  1156. if (length < IEEE802_11_CAPINFO_LEN + IEEE802_11_LISTENINT_LEN +
  1157. IEEE802_11_AP_LEN)
  1158. return 0;
  1159. pbody.capability_info = EXTRACT_LE_16BITS(p);
  1160. offset += IEEE802_11_CAPINFO_LEN;
  1161. length -= IEEE802_11_CAPINFO_LEN;
  1162. pbody.listen_interval = EXTRACT_LE_16BITS(p+offset);
  1163. offset += IEEE802_11_LISTENINT_LEN;
  1164. length -= IEEE802_11_LISTENINT_LEN;
  1165. memcpy(&pbody.ap, p+offset, IEEE802_11_AP_LEN);
  1166. offset += IEEE802_11_AP_LEN;
  1167. length -= IEEE802_11_AP_LEN;
  1168. ret = parse_elements(ndo, &pbody, p, offset, length);
  1169. PRINT_SSID(pbody);
  1170. ND_PRINT((ndo, " AP : %s", etheraddr_string(ndo, pbody.ap )));
  1171. return ret;
  1172. }
  1173. static int
  1174. handle_reassoc_response(netdissect_options *ndo,
  1175. const u_char *p, u_int length)
  1176. {
  1177. /* Same as a Association Reponse */
  1178. return handle_assoc_response(ndo, p, length);
  1179. }
  1180. static int
  1181. handle_probe_request(netdissect_options *ndo,
  1182. const u_char *p, u_int length)
  1183. {
  1184. struct mgmt_body_t pbody;
  1185. int offset = 0;
  1186. int ret;
  1187. memset(&pbody, 0, sizeof(pbody));
  1188. ret = parse_elements(ndo, &pbody, p, offset, length);
  1189. PRINT_SSID(pbody);
  1190. PRINT_RATES(pbody);
  1191. return ret;
  1192. }
  1193. static int
  1194. handle_probe_response(netdissect_options *ndo,
  1195. const u_char *p, u_int length)
  1196. {
  1197. struct mgmt_body_t pbody;
  1198. int offset = 0;
  1199. int ret;
  1200. memset(&pbody, 0, sizeof(pbody));
  1201. if (!ND_TTEST2(*p, IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
  1202. IEEE802_11_CAPINFO_LEN))
  1203. return 0;
  1204. if (length < IEEE802_11_TSTAMP_LEN + IEEE802_11_BCNINT_LEN +
  1205. IEEE802_11_CAPINFO_LEN)
  1206. return 0;
  1207. memcpy(&pbody.timestamp, p, IEEE802_11_TSTAMP_LEN);
  1208. offset += IEEE802_11_TSTAMP_LEN;
  1209. length -= IEEE802_11_TSTAMP_LEN;
  1210. pbody.beacon_interval = EXTRACT_LE_16BITS(p+offset);
  1211. offset += IEEE802_11_BCNINT_LEN;
  1212. length -= IEEE802_11_BCNINT_LEN;
  1213. pbody.capability_info = EXTRACT_LE_16BITS(p+offset);
  1214. offset += IEEE802_11_CAPINFO_LEN;
  1215. length -= IEEE802_11_CAPINFO_LEN;
  1216. ret = parse_elements(ndo, &pbody, p, offset, length);
  1217. PRINT_SSID(pbody);
  1218. PRINT_RATES(pbody);
  1219. PRINT_DS_CHANNEL(pbody);
  1220. return ret;
  1221. }
  1222. static int
  1223. handle_atim(void)
  1224. {
  1225. /* the frame body for ATIM is null. */
  1226. return 1;
  1227. }
  1228. static int
  1229. handle_disassoc(netdissect_options *ndo,
  1230. const u_char *p, u_int length)
  1231. {
  1232. struct mgmt_body_t pbody;
  1233. memset(&pbody, 0, sizeof(pbody));
  1234. if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN))
  1235. return 0;
  1236. if (length < IEEE802_11_REASON_LEN)
  1237. return 0;
  1238. pbody.reason_code = EXTRACT_LE_16BITS(p);
  1239. ND_PRINT((ndo, ": %s",
  1240. (pbody.reason_code < NUM_REASONS)
  1241. ? reason_text[pbody.reason_code]
  1242. : "Reserved"));
  1243. return 1;
  1244. }
  1245. static int
  1246. handle_auth(netdissect_options *ndo,
  1247. const u_char *p, u_int length)
  1248. {
  1249. struct mgmt_body_t pbody;
  1250. int offset = 0;
  1251. int ret;
  1252. memset(&pbody, 0, sizeof(pbody));
  1253. if (!ND_TTEST2(*p, 6))
  1254. return 0;
  1255. if (length < 6)
  1256. return 0;
  1257. pbody.auth_alg = EXTRACT_LE_16BITS(p);
  1258. offset += 2;
  1259. length -= 2;
  1260. pbody.auth_trans_seq_num = EXTRACT_LE_16BITS(p + offset);
  1261. offset += 2;
  1262. length -= 2;
  1263. pbody.status_code = EXTRACT_LE_16BITS(p + offset);
  1264. offset += 2;
  1265. length -= 2;
  1266. ret = parse_elements(ndo, &pbody, p, offset, length);
  1267. if ((pbody.auth_alg == 1) &&
  1268. ((pbody.auth_trans_seq_num == 2) ||
  1269. (pbody.auth_trans_seq_num == 3))) {
  1270. ND_PRINT((ndo, " (%s)-%x [Challenge Text] %s",
  1271. (pbody.auth_alg < NUM_AUTH_ALGS)
  1272. ? auth_alg_text[pbody.auth_alg]
  1273. : "Reserved",
  1274. pbody.auth_trans_seq_num,
  1275. ((pbody.auth_trans_seq_num % 2)
  1276. ? ((pbody.status_code < NUM_STATUSES)
  1277. ? status_text[pbody.status_code]
  1278. : "n/a") : "")));
  1279. return ret;
  1280. }
  1281. ND_PRINT((ndo, " (%s)-%x: %s",
  1282. (pbody.auth_alg < NUM_AUTH_ALGS)
  1283. ? auth_alg_text[pbody.auth_alg]
  1284. : "Reserved",
  1285. pbody.auth_trans_seq_num,
  1286. (pbody.auth_trans_seq_num % 2)
  1287. ? ((pbody.status_code < NUM_STATUSES)
  1288. ? status_text[pbody.status_code]
  1289. : "n/a")
  1290. : ""));
  1291. return ret;
  1292. }
  1293. static int
  1294. handle_deauth(netdissect_options *ndo,
  1295. const uint8_t *src, const u_char *p, u_int length)
  1296. {
  1297. struct mgmt_body_t pbody;
  1298. const char *reason = NULL;
  1299. memset(&pbody, 0, sizeof(pbody));
  1300. if (!ND_TTEST2(*p, IEEE802_11_REASON_LEN))
  1301. return 0;
  1302. if (length < IEEE802_11_REASON_LEN)
  1303. return 0;
  1304. pbody.reason_code = EXTRACT_LE_16BITS(p);
  1305. reason = (pbody.reason_code < NUM_REASONS)
  1306. ? reason_text[pbody.reason_code]
  1307. : "Reserved";
  1308. if (ndo->ndo_eflag) {
  1309. ND_PRINT((ndo, ": %s", reason));
  1310. } else {
  1311. ND_PRINT((ndo, " (%s): %s", etheraddr_string(ndo, src), reason));
  1312. }
  1313. return 1;
  1314. }
  1315. #define PRINT_HT_ACTION(v) (\
  1316. (v) == 0 ? ND_PRINT((ndo, "TxChWidth")) : \
  1317. (v) == 1 ? ND_PRINT((ndo, "MIMOPwrSave")) : \
  1318. ND_PRINT((ndo, "Act#%d", (v))) \
  1319. )
  1320. #define PRINT_BA_ACTION(v) (\
  1321. (v) == 0 ? ND_PRINT((ndo, "ADDBA Request")) : \
  1322. (v) == 1 ? ND_PRINT((ndo, "ADDBA Response")) : \
  1323. (v) == 2 ? ND_PRINT((ndo, "DELBA")) : \
  1324. ND_PRINT((ndo, "Act#%d", (v))) \
  1325. )
  1326. #define PRINT_MESHLINK_ACTION(v) (\
  1327. (v) == 0 ? ND_PRINT((ndo, "Request")) : \
  1328. (v) == 1 ? ND_PRINT((ndo, "Report")) : \
  1329. ND_PRINT((ndo, "Act#%d", (v))) \
  1330. )
  1331. #define PRINT_MESHPEERING_ACTION(v) (\
  1332. (v) == 0 ? ND_PRINT((ndo, "Open")) : \
  1333. (v) == 1 ? ND_PRINT((ndo, "Confirm")) : \
  1334. (v) == 2 ? ND_PRINT((ndo, "Close")) : \
  1335. ND_PRINT((ndo, "Act#%d", (v))) \
  1336. )
  1337. #define PRINT_MESHPATH_ACTION(v) (\
  1338. (v) == 0 ? ND_PRINT((ndo, "Request")) : \
  1339. (v) == 1 ? ND_PRINT((ndo, "Report")) : \
  1340. (v) == 2 ? ND_PRINT((ndo, "Error")) : \
  1341. (v) == 3 ? ND_PRINT((ndo, "RootAnnouncement")) : \
  1342. ND_PRINT((ndo, "Act#%d", (v))) \
  1343. )
  1344. #define PRINT_MESH_ACTION(v) (\
  1345. (v) == 0 ? ND_PRINT((ndo, "MeshLink")) : \
  1346. (v) == 1 ? ND_PRINT((ndo, "HWMP")) : \
  1347. (v) == 2 ? ND_PRINT((ndo, "Gate Announcement")) : \
  1348. (v) == 3 ? ND_PRINT((ndo, "Congestion Control")) : \
  1349. (v) == 4 ? ND_PRINT((ndo, "MCCA Setup Request")) : \
  1350. (v) == 5 ? ND_PRINT((ndo, "MCCA Setup Reply")) : \
  1351. (v) == 6 ? ND_PRINT((ndo, "MCCA Advertisement Request")) : \
  1352. (v) == 7 ? ND_PRINT((ndo, "MCCA Advertisement")) : \
  1353. (v) == 8 ? ND_PRINT((ndo, "MCCA Teardown")) : \
  1354. (v) == 9 ? ND_PRINT((ndo, "TBTT Adjustment Request")) : \
  1355. (v) == 10 ? ND_PRINT((ndo, "TBTT Adjustment Response")) : \
  1356. ND_PRINT((ndo, "Act#%d", (v))) \
  1357. )
  1358. #define PRINT_MULTIHOP_ACTION(v) (\
  1359. (v) == 0 ? ND_PRINT((ndo, "Proxy Update")) : \
  1360. (v) == 1 ? ND_PRINT((ndo, "Proxy Update Confirmation")) : \
  1361. ND_PRINT((ndo, "Act#%d", (v))) \
  1362. )
  1363. #define PRINT_SELFPROT_ACTION(v) (\
  1364. (v) == 1 ? ND_PRINT((ndo, "Peering Open")) : \
  1365. (v) == 2 ? ND_PRINT((ndo, "Peering Confirm")) : \
  1366. (v) == 3 ? ND_PRINT((ndo, "Peering Close")) : \
  1367. (v) == 4 ? ND_PRINT((ndo, "Group Key Inform")) : \
  1368. (v) == 5 ? ND_PRINT((ndo, "Group Key Acknowledge")) : \
  1369. ND_PRINT((ndo, "Act#%d", (v))) \
  1370. )
  1371. static int
  1372. handle_action(netdissect_options *ndo,
  1373. const uint8_t *src, const u_char *p, u_int length)
  1374. {
  1375. if (!ND_TTEST2(*p, 2))
  1376. return 0;
  1377. if (length < 2)
  1378. return 0;
  1379. if (ndo->ndo_eflag) {
  1380. ND_PRINT((ndo, ": "));
  1381. } else {
  1382. ND_PRINT((ndo, " (%s): ", etheraddr_string(ndo, src)));
  1383. }
  1384. switch (p[0]) {
  1385. case 0: ND_PRINT((ndo, "Spectrum Management Act#%d", p[1])); break;
  1386. case 1: ND_PRINT((ndo, "QoS Act#%d", p[1])); break;
  1387. case 2: ND_PRINT((ndo, "DLS Act#%d", p[1])); break;
  1388. case 3: ND_PRINT((ndo, "BA ")); PRINT_BA_ACTION(p[1]); break;
  1389. case 7: ND_PRINT((ndo, "HT ")); PRINT_HT_ACTION(p[1]); break;
  1390. case 13: ND_PRINT((ndo, "MeshAction ")); PRINT_MESH_ACTION(p[1]); break;
  1391. case 14:
  1392. ND_PRINT((ndo, "MultiohopAction "));
  1393. PRINT_MULTIHOP_ACTION(p[1]); break;
  1394. case 15:
  1395. ND_PRINT((ndo, "SelfprotectAction "));
  1396. PRINT_SELFPROT_ACTION(p[1]); break;
  1397. case 127: ND_PRINT((ndo, "Vendor Act#%d", p[1])); break;
  1398. default:
  1399. ND_PRINT((ndo, "Reserved(%d) Act#%d", p[0], p[1]));
  1400. break;
  1401. }
  1402. return 1;
  1403. }
  1404. /*********************************************************************************
  1405. * Print Body funcs
  1406. *********************************************************************************/
  1407. static int
  1408. mgmt_body_print(netdissect_options *ndo,
  1409. uint16_t fc, const uint8_t *src, const u_char *p, u_int length)
  1410. {
  1411. ND_PRINT((ndo, "%s", tok2str(st_str, "Unhandled Management subtype(%x)", FC_SUBTYPE(fc))));
  1412. /* There may be a problem w/ AP not having this bit set */
  1413. if (FC_PROTECTED(fc))
  1414. return wep_print(ndo, p);
  1415. switch (FC_SUBTYPE(fc)) {
  1416. case ST_ASSOC_REQUEST:
  1417. return handle_assoc_request(ndo, p, length);
  1418. case ST_ASSOC_RESPONSE:
  1419. return handle_assoc_response(ndo, p, length);
  1420. case ST_REASSOC_REQUEST:
  1421. return handle_reassoc_request(ndo, p, length);
  1422. case ST_REASSOC_RESPONSE:
  1423. return handle_reassoc_response(ndo, p, length);
  1424. case ST_PROBE_REQUEST:
  1425. return handle_probe_request(ndo, p, length);
  1426. case ST_PROBE_RESPONSE:
  1427. return handle_probe_response(ndo, p, length);
  1428. case ST_BEACON:
  1429. return handle_beacon(ndo, p, length);
  1430. case ST_ATIM:
  1431. return handle_atim();
  1432. case ST_DISASSOC:
  1433. return handle_disassoc(ndo, p, length);
  1434. case ST_AUTH:
  1435. return handle_auth(ndo, p, length);
  1436. case ST_DEAUTH:
  1437. return handle_deauth(ndo, src, p, length);
  1438. case ST_ACTION:
  1439. return handle_action(ndo, src, p, length);
  1440. default:
  1441. return 1;
  1442. }
  1443. }
  1444. /*********************************************************************************
  1445. * Handles printing all the control frame types
  1446. *********************************************************************************/
  1447. static int
  1448. ctrl_body_print(netdissect_options *ndo,
  1449. uint16_t fc, const u_char *p)
  1450. {
  1451. ND_PRINT((ndo, "%s", tok2str(ctrl_str, "Unknown Ctrl Subtype", FC_SUBTYPE(fc))));
  1452. switch (FC_SUBTYPE(fc)) {
  1453. case CTRL_CONTROL_WRAPPER:
  1454. /* XXX - requires special handling */
  1455. break;
  1456. case CTRL_BAR:
  1457. if (!ND_TTEST2(*p, CTRL_BAR_HDRLEN))
  1458. return 0;
  1459. if (!ndo->ndo_eflag)
  1460. ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
  1461. etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ra),
  1462. etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ta),
  1463. EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->ctl)),
  1464. EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->seq))));
  1465. break;
  1466. case CTRL_BA:
  1467. if (!ND_TTEST2(*p, CTRL_BA_HDRLEN))
  1468. return 0;
  1469. if (!ndo->ndo_eflag)
  1470. ND_PRINT((ndo, " RA:%s ",
  1471. etheraddr_string(ndo, ((const struct ctrl_ba_hdr_t *)p)->ra)));
  1472. break;
  1473. case CTRL_PS_POLL:
  1474. if (!ND_TTEST2(*p, CTRL_PS_POLL_HDRLEN))
  1475. return 0;
  1476. ND_PRINT((ndo, " AID(%x)",
  1477. EXTRACT_LE_16BITS(&(((const struct ctrl_ps_poll_hdr_t *)p)->aid))));
  1478. break;
  1479. case CTRL_RTS:
  1480. if (!ND_TTEST2(*p, CTRL_RTS_HDRLEN))
  1481. return 0;
  1482. if (!ndo->ndo_eflag)
  1483. ND_PRINT((ndo, " TA:%s ",
  1484. etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ta)));
  1485. break;
  1486. case CTRL_CTS:
  1487. if (!ND_TTEST2(*p, CTRL_CTS_HDRLEN))
  1488. return 0;
  1489. if (!ndo->ndo_eflag)
  1490. ND_PRINT((ndo, " RA:%s ",
  1491. etheraddr_string(ndo, ((const struct ctrl_cts_hdr_t *)p)->ra)));
  1492. break;
  1493. case CTRL_ACK:
  1494. if (!ND_TTEST2(*p, CTRL_ACK_HDRLEN))
  1495. return 0;
  1496. if (!ndo->ndo_eflag)
  1497. ND_PRINT((ndo, " RA:%s ",
  1498. etheraddr_string(ndo, ((const struct ctrl_ack_hdr_t *)p)->ra)));
  1499. break;
  1500. case CTRL_CF_END:
  1501. if (!ND_TTEST2(*p, CTRL_END_HDRLEN))
  1502. return 0;
  1503. if (!ndo->ndo_eflag)
  1504. ND_PRINT((ndo, " RA:%s ",
  1505. etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->ra)));
  1506. break;
  1507. case CTRL_END_ACK:
  1508. if (!ND_TTEST2(*p, CTRL_END_ACK_HDRLEN))
  1509. return 0;
  1510. if (!ndo->ndo_eflag)
  1511. ND_PRINT((ndo, " RA:%s ",
  1512. etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->ra)));
  1513. break;
  1514. }
  1515. return 1;
  1516. }
  1517. /*
  1518. * Data Frame - Address field contents
  1519. *
  1520. * To Ds | From DS | Addr 1 | Addr 2 | Addr 3 | Addr 4
  1521. * 0 | 0 | DA | SA | BSSID | n/a
  1522. * 0 | 1 | DA | BSSID | SA | n/a
  1523. * 1 | 0 | BSSID | SA | DA | n/a
  1524. * 1 | 1 | RA | TA | DA | SA
  1525. */
  1526. /*
  1527. * Function to get source and destination MAC addresses for a data frame.
  1528. */
  1529. static void
  1530. get_data_src_dst_mac(uint16_t fc, const u_char *p, const uint8_t **srcp,
  1531. const uint8_t **dstp)
  1532. {
  1533. #define ADDR1 (p + 4)
  1534. #define ADDR2 (p + 10)
  1535. #define ADDR3 (p + 16)
  1536. #define ADDR4 (p + 24)
  1537. if (!FC_TO_DS(fc)) {
  1538. if (!FC_FROM_DS(fc)) {
  1539. /* not To DS and not From DS */
  1540. *srcp = ADDR2;
  1541. *dstp = ADDR1;
  1542. } else {
  1543. /* not To DS and From DS */
  1544. *srcp = ADDR3;
  1545. *dstp = ADDR1;
  1546. }
  1547. } else {
  1548. if (!FC_FROM_DS(fc)) {
  1549. /* From DS and not To DS */
  1550. *srcp = ADDR2;
  1551. *dstp = ADDR3;
  1552. } else {
  1553. /* To DS and From DS */
  1554. *srcp = ADDR4;
  1555. *dstp = ADDR3;
  1556. }
  1557. }
  1558. #undef ADDR1
  1559. #undef ADDR2
  1560. #undef ADDR3
  1561. #undef ADDR4
  1562. }
  1563. static void
  1564. get_mgmt_src_dst_mac(const u_char *p, const uint8_t **srcp, const uint8_t **dstp)
  1565. {
  1566. const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p;
  1567. if (srcp != NULL)
  1568. *srcp = hp->sa;
  1569. if (dstp != NULL)
  1570. *dstp = hp->da;
  1571. }
  1572. /*
  1573. * Print Header funcs
  1574. */
  1575. static void
  1576. data_header_print(netdissect_options *ndo, uint16_t fc, const u_char *p)
  1577. {
  1578. u_int subtype = FC_SUBTYPE(fc);
  1579. if (DATA_FRAME_IS_CF_ACK(subtype) || DATA_FRAME_IS_CF_POLL(subtype) ||
  1580. DATA_FRAME_IS_QOS(subtype)) {
  1581. ND_PRINT((ndo, "CF "));
  1582. if (DATA_FRAME_IS_CF_ACK(subtype)) {
  1583. if (DATA_FRAME_IS_CF_POLL(subtype))
  1584. ND_PRINT((ndo, "Ack/Poll"));
  1585. else
  1586. ND_PRINT((ndo, "Ack"));
  1587. } else {
  1588. if (DATA_FRAME_IS_CF_POLL(subtype))
  1589. ND_PRINT((ndo, "Poll"));
  1590. }
  1591. if (DATA_FRAME_IS_QOS(subtype))
  1592. ND_PRINT((ndo, "+QoS"));
  1593. ND_PRINT((ndo, " "));
  1594. }
  1595. #define ADDR1 (p + 4)
  1596. #define ADDR2 (p + 10)
  1597. #define ADDR3 (p + 16)
  1598. #define ADDR4 (p + 24)
  1599. if (!FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
  1600. ND_PRINT((ndo, "DA:%s SA:%s BSSID:%s ",
  1601. etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
  1602. etheraddr_string(ndo, ADDR3)));
  1603. } else if (!FC_TO_DS(fc) && FC_FROM_DS(fc)) {
  1604. ND_PRINT((ndo, "DA:%s BSSID:%s SA:%s ",
  1605. etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
  1606. etheraddr_string(ndo, ADDR3)));
  1607. } else if (FC_TO_DS(fc) && !FC_FROM_DS(fc)) {
  1608. ND_PRINT((ndo, "BSSID:%s SA:%s DA:%s ",
  1609. etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
  1610. etheraddr_string(ndo, ADDR3)));
  1611. } else if (FC_TO_DS(fc) && FC_FROM_DS(fc)) {
  1612. ND_PRINT((ndo, "RA:%s TA:%s DA:%s SA:%s ",
  1613. etheraddr_string(ndo, ADDR1), etheraddr_string(ndo, ADDR2),
  1614. etheraddr_string(ndo, ADDR3), etheraddr_string(ndo, ADDR4)));
  1615. }
  1616. #undef ADDR1
  1617. #undef ADDR2
  1618. #undef ADDR3
  1619. #undef ADDR4
  1620. }
  1621. static void
  1622. mgmt_header_print(netdissect_options *ndo, const u_char *p)
  1623. {
  1624. const struct mgmt_header_t *hp = (const struct mgmt_header_t *) p;
  1625. ND_PRINT((ndo, "BSSID:%s DA:%s SA:%s ",
  1626. etheraddr_string(ndo, (hp)->bssid), etheraddr_string(ndo, (hp)->da),
  1627. etheraddr_string(ndo, (hp)->sa)));
  1628. }
  1629. static void
  1630. ctrl_header_print(netdissect_options *ndo, uint16_t fc, const u_char *p)
  1631. {
  1632. switch (FC_SUBTYPE(fc)) {
  1633. case CTRL_BAR:
  1634. ND_PRINT((ndo, " RA:%s TA:%s CTL(%x) SEQ(%u) ",
  1635. etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ra),
  1636. etheraddr_string(ndo, ((const struct ctrl_bar_hdr_t *)p)->ta),
  1637. EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->ctl)),
  1638. EXTRACT_LE_16BITS(&(((const struct ctrl_bar_hdr_t *)p)->seq))));
  1639. break;
  1640. case CTRL_BA:
  1641. ND_PRINT((ndo, "RA:%s ",
  1642. etheraddr_string(ndo, ((const struct ctrl_ba_hdr_t *)p)->ra)));
  1643. break;
  1644. case CTRL_PS_POLL:
  1645. ND_PRINT((ndo, "BSSID:%s TA:%s ",
  1646. etheraddr_string(ndo, ((const struct ctrl_ps_poll_hdr_t *)p)->bssid),
  1647. etheraddr_string(ndo, ((const struct ctrl_ps_poll_hdr_t *)p)->ta)));
  1648. break;
  1649. case CTRL_RTS:
  1650. ND_PRINT((ndo, "RA:%s TA:%s ",
  1651. etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ra),
  1652. etheraddr_string(ndo, ((const struct ctrl_rts_hdr_t *)p)->ta)));
  1653. break;
  1654. case CTRL_CTS:
  1655. ND_PRINT((ndo, "RA:%s ",
  1656. etheraddr_string(ndo, ((const struct ctrl_cts_hdr_t *)p)->ra)));
  1657. break;
  1658. case CTRL_ACK:
  1659. ND_PRINT((ndo, "RA:%s ",
  1660. etheraddr_string(ndo, ((const struct ctrl_ack_hdr_t *)p)->ra)));
  1661. break;
  1662. case CTRL_CF_END:
  1663. ND_PRINT((ndo, "RA:%s BSSID:%s ",
  1664. etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->ra),
  1665. etheraddr_string(ndo, ((const struct ctrl_end_hdr_t *)p)->bssid)));
  1666. break;
  1667. case CTRL_END_ACK:
  1668. ND_PRINT((ndo, "RA:%s BSSID:%s ",
  1669. etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->ra),
  1670. etheraddr_string(ndo, ((const struct ctrl_end_ack_hdr_t *)p)->bssid)));
  1671. break;
  1672. default:
  1673. /* We shouldn't get here - we should already have quit */
  1674. break;
  1675. }
  1676. }
  1677. static int
  1678. extract_header_length(netdissect_options *ndo,
  1679. uint16_t fc)
  1680. {
  1681. int len;
  1682. switch (FC_TYPE(fc)) {
  1683. case T_MGMT:
  1684. return MGMT_HDRLEN;
  1685. case T_CTRL:
  1686. switch (FC_SUBTYPE(fc)) {
  1687. case CTRL_CONTROL_WRAPPER:
  1688. return CTRL_CONTROL_WRAPPER_HDRLEN;
  1689. case CTRL_BAR:
  1690. return CTRL_BAR_HDRLEN;
  1691. case CTRL_BA:
  1692. return CTRL_BA_HDRLEN;
  1693. case CTRL_PS_POLL:
  1694. return CTRL_PS_POLL_HDRLEN;
  1695. case CTRL_RTS:
  1696. return CTRL_RTS_HDRLEN;
  1697. case CTRL_CTS:
  1698. return CTRL_CTS_HDRLEN;
  1699. case CTRL_ACK:
  1700. return CTRL_ACK_HDRLEN;
  1701. case CTRL_CF_END:
  1702. return CTRL_END_HDRLEN;
  1703. case CTRL_END_ACK:
  1704. return CTRL_END_ACK_HDRLEN;
  1705. default:
  1706. ND_PRINT((ndo, "unknown 802.11 ctrl frame subtype (%d)", FC_SUBTYPE(fc)));
  1707. return 0;
  1708. }
  1709. case T_DATA:
  1710. len = (FC_TO_DS(fc) && FC_FROM_DS(fc)) ? 30 : 24;
  1711. if (DATA_FRAME_IS_QOS(FC_SUBTYPE(fc)))
  1712. len += 2;
  1713. return len;
  1714. default:
  1715. ND_PRINT((ndo, "unknown 802.11 frame type (%d)", FC_TYPE(fc)));
  1716. return 0;
  1717. }
  1718. }
  1719. static int
  1720. extract_mesh_header_length(const u_char *p)
  1721. {
  1722. return (p[0] &~ 3) ? 0 : 6*(1 + (p[0] & 3));
  1723. }
  1724. /*
  1725. * Print the 802.11 MAC header.
  1726. */
  1727. static void
  1728. ieee_802_11_hdr_print(netdissect_options *ndo,
  1729. uint16_t fc, const u_char *p, u_int hdrlen,
  1730. u_int meshdrlen)
  1731. {
  1732. if (ndo->ndo_vflag) {
  1733. if (FC_MORE_DATA(fc))
  1734. ND_PRINT((ndo, "More Data "));
  1735. if (FC_MORE_FLAG(fc))
  1736. ND_PRINT((ndo, "More Fragments "));
  1737. if (FC_POWER_MGMT(fc))
  1738. ND_PRINT((ndo, "Pwr Mgmt "));
  1739. if (FC_RETRY(fc))
  1740. ND_PRINT((ndo, "Retry "));
  1741. if (FC_ORDER(fc))
  1742. ND_PRINT((ndo, "Strictly Ordered "));
  1743. if (FC_PROTECTED(fc))
  1744. ND_PRINT((ndo, "Protected "));
  1745. if (FC_TYPE(fc) != T_CTRL || FC_SUBTYPE(fc) != CTRL_PS_POLL)
  1746. ND_PRINT((ndo, "%dus ",
  1747. EXTRACT_LE_16BITS(
  1748. &((const struct mgmt_header_t *)p)->duration)));
  1749. }
  1750. if (meshdrlen != 0) {
  1751. const struct meshcntl_t *mc =
  1752. (const struct meshcntl_t *)&p[hdrlen - meshdrlen];
  1753. int ae = mc->flags & 3;
  1754. ND_PRINT((ndo, "MeshData (AE %d TTL %u seq %u", ae, mc->ttl,
  1755. EXTRACT_LE_32BITS(mc->seq)));
  1756. if (ae > 0)
  1757. ND_PRINT((ndo, " A4:%s", etheraddr_string(ndo, mc->addr4)));
  1758. if (ae > 1)
  1759. ND_PRINT((ndo, " A5:%s", etheraddr_string(ndo, mc->addr5)));
  1760. if (ae > 2)
  1761. ND_PRINT((ndo, " A6:%s", etheraddr_string(ndo, mc->addr6)));
  1762. ND_PRINT((ndo, ") "));
  1763. }
  1764. switch (FC_TYPE(fc)) {
  1765. case T_MGMT:
  1766. mgmt_header_print(ndo, p);
  1767. break;
  1768. case T_CTRL:
  1769. ctrl_header_print(ndo, fc, p);
  1770. break;
  1771. case T_DATA:
  1772. data_header_print(ndo, fc, p);
  1773. break;
  1774. default:
  1775. break;
  1776. }
  1777. }
  1778. #ifndef roundup2
  1779. #define roundup2(x, y) (((x)+((y)-1))&(~((y)-1))) /* if y is powers of two */
  1780. #endif
  1781. static const char tstr[] = "[|802.11]";
  1782. static u_int
  1783. ieee802_11_print(netdissect_options *ndo,
  1784. const u_char *p, u_int length, u_int orig_caplen, int pad,
  1785. u_int fcslen)
  1786. {
  1787. uint16_t fc;
  1788. u_int caplen, hdrlen, meshdrlen;
  1789. struct lladdr_info src, dst;
  1790. int llc_hdrlen;
  1791. caplen = orig_caplen;
  1792. /* Remove FCS, if present */
  1793. if (length < fcslen) {
  1794. ND_PRINT((ndo, "%s", tstr));
  1795. return caplen;
  1796. }
  1797. length -= fcslen;
  1798. if (caplen > length) {
  1799. /* Amount of FCS in actual packet data, if any */
  1800. fcslen = caplen - length;
  1801. caplen -= fcslen;
  1802. ndo->ndo_snapend -= fcslen;
  1803. }
  1804. if (caplen < IEEE802_11_FC_LEN) {
  1805. ND_PRINT((ndo, "%s", tstr));
  1806. return orig_caplen;
  1807. }
  1808. fc = EXTRACT_LE_16BITS(p);
  1809. hdrlen = extract_header_length(ndo, fc);
  1810. if (hdrlen == 0) {
  1811. /* Unknown frame type or control frame subtype; quit. */
  1812. return (0);
  1813. }
  1814. if (pad)
  1815. hdrlen = roundup2(hdrlen, 4);
  1816. if (ndo->ndo_Hflag && FC_TYPE(fc) == T_DATA &&
  1817. DATA_FRAME_IS_QOS(FC_SUBTYPE(fc))) {
  1818. meshdrlen = extract_mesh_header_length(p+hdrlen);
  1819. hdrlen += meshdrlen;
  1820. } else
  1821. meshdrlen = 0;
  1822. if (caplen < hdrlen) {
  1823. ND_PRINT((ndo, "%s", tstr));
  1824. return hdrlen;
  1825. }
  1826. if (ndo->ndo_eflag)
  1827. ieee_802_11_hdr_print(ndo, fc, p, hdrlen, meshdrlen);
  1828. /*
  1829. * Go past the 802.11 header.
  1830. */
  1831. length -= hdrlen;
  1832. caplen -= hdrlen;
  1833. p += hdrlen;
  1834. src.addr_string = etheraddr_string;
  1835. dst.addr_string = etheraddr_string;
  1836. switch (FC_TYPE(fc)) {
  1837. case T_MGMT:
  1838. get_mgmt_src_dst_mac(p - hdrlen, &src.addr, &dst.addr);
  1839. if (!mgmt_body_print(ndo, fc, src.addr, p, length)) {
  1840. ND_PRINT((ndo, "%s", tstr));
  1841. return hdrlen;
  1842. }
  1843. break;
  1844. case T_CTRL:
  1845. if (!ctrl_body_print(ndo, fc, p - hdrlen)) {
  1846. ND_PRINT((ndo, "%s", tstr));
  1847. return hdrlen;
  1848. }
  1849. break;
  1850. case T_DATA:
  1851. if (DATA_FRAME_IS_NULL(FC_SUBTYPE(fc)))
  1852. return hdrlen; /* no-data frame */
  1853. /* There may be a problem w/ AP not having this bit set */
  1854. if (FC_PROTECTED(fc)) {
  1855. ND_PRINT((ndo, "Data"));
  1856. if (!wep_print(ndo, p)) {
  1857. ND_PRINT((ndo, "%s", tstr));
  1858. return hdrlen;
  1859. }
  1860. } else {
  1861. get_data_src_dst_mac(fc, p - hdrlen, &src.addr, &dst.addr);
  1862. llc_hdrlen = llc_print(ndo, p, length, caplen, &src, &dst);
  1863. if (llc_hdrlen < 0) {
  1864. /*
  1865. * Some kinds of LLC packet we cannot
  1866. * handle intelligently
  1867. */
  1868. if (!ndo->ndo_suppress_default_print)
  1869. ND_DEFAULTPRINT(p, caplen);
  1870. llc_hdrlen = -llc_hdrlen;
  1871. }
  1872. hdrlen += llc_hdrlen;
  1873. }
  1874. break;
  1875. default:
  1876. /* We shouldn't get here - we should already have quit */
  1877. break;
  1878. }
  1879. return hdrlen;
  1880. }
  1881. /*
  1882. * This is the top level routine of the printer. 'p' points
  1883. * to the 802.11 header of the packet, 'h->ts' is the timestamp,
  1884. * 'h->len' is the length of the packet off the wire, and 'h->caplen'
  1885. * is the number of bytes actually captured.
  1886. */
  1887. u_int
  1888. ieee802_11_if_print(netdissect_options *ndo,
  1889. const struct pcap_pkthdr *h, const u_char *p)
  1890. {
  1891. return ieee802_11_print(ndo, p, h->len, h->caplen, 0, 0);
  1892. }
  1893. /* $FreeBSD: src/sys/net80211/ieee80211_radiotap.h,v 1.5 2005/01/22 20:12:05 sam Exp $ */
  1894. /* NetBSD: ieee802_11_radio.h,v 1.2 2006/02/26 03:04:03 dyoung Exp */
  1895. /*-
  1896. * Copyright (c) 2003, 2004 David Young. All rights reserved.
  1897. *
  1898. * Redistribution and use in source and binary forms, with or without
  1899. * modification, are permitted provided that the following conditions
  1900. * are met:
  1901. * 1. Redistributions of source code must retain the above copyright
  1902. * notice, this list of conditions and the following disclaimer.
  1903. * 2. Redistributions in binary form must reproduce the above copyright
  1904. * notice, this list of conditions and the following disclaimer in the
  1905. * documentation and/or other materials provided with the distribution.
  1906. * 3. The name of David Young may not be used to endorse or promote
  1907. * products derived from this software without specific prior
  1908. * written permission.
  1909. *
  1910. * THIS SOFTWARE IS PROVIDED BY DAVID YOUNG ``AS IS'' AND ANY
  1911. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  1912. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  1913. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DAVID
  1914. * YOUNG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  1915. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  1916. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  1917. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  1918. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  1919. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1920. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  1921. * OF SUCH DAMAGE.
  1922. */
  1923. /* A generic radio capture format is desirable. It must be
  1924. * rigidly defined (e.g., units for fields should be given),
  1925. * and easily extensible.
  1926. *
  1927. * The following is an extensible radio capture format. It is
  1928. * based on a bitmap indicating which fields are present.
  1929. *
  1930. * I am trying to describe precisely what the application programmer
  1931. * should expect in the following, and for that reason I tell the
  1932. * units and origin of each measurement (where it applies), or else I
  1933. * use sufficiently weaselly language ("is a monotonically nondecreasing
  1934. * function of...") that I cannot set false expectations for lawyerly
  1935. * readers.
  1936. */
  1937. /*
  1938. * The radio capture header precedes the 802.11 header.
  1939. *
  1940. * Note well: all radiotap fields are little-endian.
  1941. */
  1942. struct ieee80211_radiotap_header {
  1943. uint8_t it_version; /* Version 0. Only increases
  1944. * for drastic changes,
  1945. * introduction of compatible
  1946. * new fields does not count.
  1947. */
  1948. uint8_t it_pad;
  1949. uint16_t it_len; /* length of the whole
  1950. * header in bytes, including
  1951. * it_version, it_pad,
  1952. * it_len, and data fields.
  1953. */
  1954. uint32_t it_present; /* A bitmap telling which
  1955. * fields are present. Set bit 31
  1956. * (0x80000000) to extend the
  1957. * bitmap by another 32 bits.
  1958. * Additional extensions are made
  1959. * by setting bit 31.
  1960. */
  1961. };
  1962. /* Name Data type Units
  1963. * ---- --------- -----
  1964. *
  1965. * IEEE80211_RADIOTAP_TSFT uint64_t microseconds
  1966. *
  1967. * Value in microseconds of the MAC's 64-bit 802.11 Time
  1968. * Synchronization Function timer when the first bit of the
  1969. * MPDU arrived at the MAC. For received frames, only.
  1970. *
  1971. * IEEE80211_RADIOTAP_CHANNEL 2 x uint16_t MHz, bitmap
  1972. *
  1973. * Tx/Rx frequency in MHz, followed by flags (see below).
  1974. * Note that IEEE80211_RADIOTAP_XCHANNEL must be used to
  1975. * represent an HT channel as there is not enough room in
  1976. * the flags word.
  1977. *
  1978. * IEEE80211_RADIOTAP_FHSS uint16_t see below
  1979. *
  1980. * For frequency-hopping radios, the hop set (first byte)
  1981. * and pattern (second byte).
  1982. *
  1983. * IEEE80211_RADIOTAP_RATE uint8_t 500kb/s or index
  1984. *
  1985. * Tx/Rx data rate. If bit 0x80 is set then it represents an
  1986. * an MCS index and not an IEEE rate.
  1987. *
  1988. * IEEE80211_RADIOTAP_DBM_ANTSIGNAL int8_t decibels from
  1989. * one milliwatt (dBm)
  1990. *
  1991. * RF signal power at the antenna, decibel difference from
  1992. * one milliwatt.
  1993. *
  1994. * IEEE80211_RADIOTAP_DBM_ANTNOISE int8_t decibels from
  1995. * one milliwatt (dBm)
  1996. *
  1997. * RF noise power at the antenna, decibel difference from one
  1998. * milliwatt.
  1999. *
  2000. * IEEE80211_RADIOTAP_DB_ANTSIGNAL uint8_t decibel (dB)
  2001. *
  2002. * RF signal power at the antenna, decibel difference from an
  2003. * arbitrary, fixed reference.
  2004. *
  2005. * IEEE80211_RADIOTAP_DB_ANTNOISE uint8_t decibel (dB)
  2006. *
  2007. * RF noise power at the antenna, decibel difference from an
  2008. * arbitrary, fixed reference point.
  2009. *
  2010. * IEEE80211_RADIOTAP_LOCK_QUALITY uint16_t unitless
  2011. *
  2012. * Quality of Barker code lock. Unitless. Monotonically
  2013. * nondecreasing with "better" lock strength. Called "Signal
  2014. * Quality" in datasheets. (Is there a standard way to measure
  2015. * this?)
  2016. *
  2017. * IEEE80211_RADIOTAP_TX_ATTENUATION uint16_t unitless
  2018. *
  2019. * Transmit power expressed as unitless distance from max
  2020. * power set at factory calibration. 0 is max power.
  2021. * Monotonically nondecreasing with lower power levels.
  2022. *
  2023. * IEEE80211_RADIOTAP_DB_TX_ATTENUATION uint16_t decibels (dB)
  2024. *
  2025. * Transmit power expressed as decibel distance from max power
  2026. * set at factory calibration. 0 is max power. Monotonically
  2027. * nondecreasing with lower power levels.
  2028. *
  2029. * IEEE80211_RADIOTAP_DBM_TX_POWER int8_t decibels from
  2030. * one milliwatt (dBm)
  2031. *
  2032. * Transmit power expressed as dBm (decibels from a 1 milliwatt
  2033. * reference). This is the absolute power level measured at
  2034. * the antenna port.
  2035. *
  2036. * IEEE80211_RADIOTAP_FLAGS uint8_t bitmap
  2037. *
  2038. * Properties of transmitted and received frames. See flags
  2039. * defined below.
  2040. *
  2041. * IEEE80211_RADIOTAP_ANTENNA uint8_t antenna index
  2042. *
  2043. * Unitless indication of the Rx/Tx antenna for this packet.
  2044. * The first antenna is antenna 0.
  2045. *
  2046. * IEEE80211_RADIOTAP_RX_FLAGS uint16_t bitmap
  2047. *
  2048. * Properties of received frames. See flags defined below.
  2049. *
  2050. * IEEE80211_RADIOTAP_XCHANNEL uint32_t bitmap
  2051. * uint16_t MHz
  2052. * uint8_t channel number
  2053. * uint8_t .5 dBm
  2054. *
  2055. * Extended channel specification: flags (see below) followed by
  2056. * frequency in MHz, the corresponding IEEE channel number, and
  2057. * finally the maximum regulatory transmit power cap in .5 dBm
  2058. * units. This property supersedes IEEE80211_RADIOTAP_CHANNEL
  2059. * and only one of the two should be present.
  2060. *
  2061. * IEEE80211_RADIOTAP_MCS uint8_t known
  2062. * uint8_t flags
  2063. * uint8_t mcs
  2064. *
  2065. * Bitset indicating which fields have known values, followed
  2066. * by bitset of flag values, followed by the MCS rate index as
  2067. * in IEEE 802.11n.
  2068. *
  2069. *
  2070. * IEEE80211_RADIOTAP_AMPDU_STATUS u32, u16, u8, u8 unitless
  2071. *
  2072. * Contains the AMPDU information for the subframe.
  2073. *
  2074. * IEEE80211_RADIOTAP_VHT u16, u8, u8, u8[4], u8, u8, u16
  2075. *
  2076. * Contains VHT information about this frame.
  2077. *
  2078. * IEEE80211_RADIOTAP_VENDOR_NAMESPACE
  2079. * uint8_t OUI[3]
  2080. * uint8_t subspace
  2081. * uint16_t length
  2082. *
  2083. * The Vendor Namespace Field contains three sub-fields. The first
  2084. * sub-field is 3 bytes long. It contains the vendor's IEEE 802
  2085. * Organizationally Unique Identifier (OUI). The fourth byte is a
  2086. * vendor-specific "namespace selector."
  2087. *
  2088. */
  2089. enum ieee80211_radiotap_type {
  2090. IEEE80211_RADIOTAP_TSFT = 0,
  2091. IEEE80211_RADIOTAP_FLAGS = 1,
  2092. IEEE80211_RADIOTAP_RATE = 2,
  2093. IEEE80211_RADIOTAP_CHANNEL = 3,
  2094. IEEE80211_RADIOTAP_FHSS = 4,
  2095. IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
  2096. IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
  2097. IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
  2098. IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
  2099. IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
  2100. IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
  2101. IEEE80211_RADIOTAP_ANTENNA = 11,
  2102. IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
  2103. IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
  2104. IEEE80211_RADIOTAP_RX_FLAGS = 14,
  2105. /* NB: gap for netbsd definitions */
  2106. IEEE80211_RADIOTAP_XCHANNEL = 18,
  2107. IEEE80211_RADIOTAP_MCS = 19,
  2108. IEEE80211_RADIOTAP_AMPDU_STATUS = 20,
  2109. IEEE80211_RADIOTAP_VHT = 21,
  2110. IEEE80211_RADIOTAP_NAMESPACE = 29,
  2111. IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
  2112. IEEE80211_RADIOTAP_EXT = 31
  2113. };
  2114. /* channel attributes */
  2115. #define IEEE80211_CHAN_TURBO 0x00010 /* Turbo channel */
  2116. #define IEEE80211_CHAN_CCK 0x00020 /* CCK channel */
  2117. #define IEEE80211_CHAN_OFDM 0x00040 /* OFDM channel */
  2118. #define IEEE80211_CHAN_2GHZ 0x00080 /* 2 GHz spectrum channel. */
  2119. #define IEEE80211_CHAN_5GHZ 0x00100 /* 5 GHz spectrum channel */
  2120. #define IEEE80211_CHAN_PASSIVE 0x00200 /* Only passive scan allowed */
  2121. #define IEEE80211_CHAN_DYN 0x00400 /* Dynamic CCK-OFDM channel */
  2122. #define IEEE80211_CHAN_GFSK 0x00800 /* GFSK channel (FHSS PHY) */
  2123. #define IEEE80211_CHAN_GSM 0x01000 /* 900 MHz spectrum channel */
  2124. #define IEEE80211_CHAN_STURBO 0x02000 /* 11a static turbo channel only */
  2125. #define IEEE80211_CHAN_HALF 0x04000 /* Half rate channel */
  2126. #define IEEE80211_CHAN_QUARTER 0x08000 /* Quarter rate channel */
  2127. #define IEEE80211_CHAN_HT20 0x10000 /* HT 20 channel */
  2128. #define IEEE80211_CHAN_HT40U 0x20000 /* HT 40 channel w/ ext above */
  2129. #define IEEE80211_CHAN_HT40D 0x40000 /* HT 40 channel w/ ext below */
  2130. /* Useful combinations of channel characteristics, borrowed from Ethereal */
  2131. #define IEEE80211_CHAN_A \
  2132. (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
  2133. #define IEEE80211_CHAN_B \
  2134. (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
  2135. #define IEEE80211_CHAN_G \
  2136. (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
  2137. #define IEEE80211_CHAN_TA \
  2138. (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM | IEEE80211_CHAN_TURBO)
  2139. #define IEEE80211_CHAN_TG \
  2140. (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN | IEEE80211_CHAN_TURBO)
  2141. /* For IEEE80211_RADIOTAP_FLAGS */
  2142. #define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
  2143. * during CFP
  2144. */
  2145. #define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
  2146. * with short
  2147. * preamble
  2148. */
  2149. #define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
  2150. * with WEP encryption
  2151. */
  2152. #define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
  2153. * with fragmentation
  2154. */
  2155. #define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
  2156. #define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
  2157. * 802.11 header and payload
  2158. * (to 32-bit boundary)
  2159. */
  2160. #define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* does not pass FCS check */
  2161. /* For IEEE80211_RADIOTAP_RX_FLAGS */
  2162. #define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
  2163. #define IEEE80211_RADIOTAP_F_RX_PLCP_CRC 0x0002 /* frame failed PLCP CRC check */
  2164. /* For IEEE80211_RADIOTAP_MCS known */
  2165. #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN 0x01
  2166. #define IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN 0x02 /* MCS index field */
  2167. #define IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN 0x04
  2168. #define IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN 0x08
  2169. #define IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN 0x10
  2170. #define IEEE80211_RADIOTAP_MCS_STBC_KNOWN 0x20
  2171. #define IEEE80211_RADIOTAP_MCS_NESS_KNOWN 0x40
  2172. #define IEEE80211_RADIOTAP_MCS_NESS_BIT_1 0x80
  2173. /* For IEEE80211_RADIOTAP_MCS flags */
  2174. #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK 0x03
  2175. #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20 0
  2176. #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 1
  2177. #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20L 2
  2178. #define IEEE80211_RADIOTAP_MCS_BANDWIDTH_20U 3
  2179. #define IEEE80211_RADIOTAP_MCS_SHORT_GI 0x04 /* short guard interval */
  2180. #define IEEE80211_RADIOTAP_MCS_HT_GREENFIELD 0x08
  2181. #define IEEE80211_RADIOTAP_MCS_FEC_LDPC 0x10
  2182. #define IEEE80211_RADIOTAP_MCS_STBC_MASK 0x60
  2183. #define IEEE80211_RADIOTAP_MCS_STBC_1 1
  2184. #define IEEE80211_RADIOTAP_MCS_STBC_2 2
  2185. #define IEEE80211_RADIOTAP_MCS_STBC_3 3
  2186. #define IEEE80211_RADIOTAP_MCS_STBC_SHIFT 5
  2187. #define IEEE80211_RADIOTAP_MCS_NESS_BIT_0 0x80
  2188. /* For IEEE80211_RADIOTAP_AMPDU_STATUS */
  2189. #define IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN 0x0001
  2190. #define IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN 0x0002
  2191. #define IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN 0x0004
  2192. #define IEEE80211_RADIOTAP_AMPDU_IS_LAST 0x0008
  2193. #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR 0x0010
  2194. #define IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN 0x0020
  2195. /* For IEEE80211_RADIOTAP_VHT known */
  2196. #define IEEE80211_RADIOTAP_VHT_STBC_KNOWN 0x0001
  2197. #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA_KNOWN 0x0002
  2198. #define IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN 0x0004
  2199. #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_DIS_KNOWN 0x0008
  2200. #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM_KNOWN 0x0010
  2201. #define IEEE80211_RADIOTAP_VHT_BEAMFORMED_KNOWN 0x0020
  2202. #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN 0x0040
  2203. #define IEEE80211_RADIOTAP_VHT_GROUP_ID_KNOWN 0x0080
  2204. #define IEEE80211_RADIOTAP_VHT_PARTIAL_AID_KNOWN 0x0100
  2205. /* For IEEE80211_RADIOTAP_VHT flags */
  2206. #define IEEE80211_RADIOTAP_VHT_STBC 0x01
  2207. #define IEEE80211_RADIOTAP_VHT_TXOP_PS_NA 0x02
  2208. #define IEEE80211_RADIOTAP_VHT_SHORT_GI 0x04
  2209. #define IEEE80211_RADIOTAP_VHT_SGI_NSYM_M10_9 0x08
  2210. #define IEEE80211_RADIOTAP_VHT_LDPC_EXTRA_OFDM_SYM 0x10
  2211. #define IEEE80211_RADIOTAP_VHT_BEAMFORMED 0x20
  2212. #define IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK 0x1f
  2213. #define IEEE80211_RADIOTAP_VHT_NSS_MASK 0x0f
  2214. #define IEEE80211_RADIOTAP_VHT_MCS_MASK 0xf0
  2215. #define IEEE80211_RADIOTAP_VHT_MCS_SHIFT 4
  2216. #define IEEE80211_RADIOTAP_CODING_LDPC_USERn 0x01
  2217. #define IEEE80211_CHAN_FHSS \
  2218. (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_GFSK)
  2219. #define IEEE80211_CHAN_A \
  2220. (IEEE80211_CHAN_5GHZ | IEEE80211_CHAN_OFDM)
  2221. #define IEEE80211_CHAN_B \
  2222. (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_CCK)
  2223. #define IEEE80211_CHAN_PUREG \
  2224. (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_OFDM)
  2225. #define IEEE80211_CHAN_G \
  2226. (IEEE80211_CHAN_2GHZ | IEEE80211_CHAN_DYN)
  2227. #define IS_CHAN_FHSS(flags) \
  2228. ((flags & IEEE80211_CHAN_FHSS) == IEEE80211_CHAN_FHSS)
  2229. #define IS_CHAN_A(flags) \
  2230. ((flags & IEEE80211_CHAN_A) == IEEE80211_CHAN_A)
  2231. #define IS_CHAN_B(flags) \
  2232. ((flags & IEEE80211_CHAN_B) == IEEE80211_CHAN_B)
  2233. #define IS_CHAN_PUREG(flags) \
  2234. ((flags & IEEE80211_CHAN_PUREG) == IEEE80211_CHAN_PUREG)
  2235. #define IS_CHAN_G(flags) \
  2236. ((flags & IEEE80211_CHAN_G) == IEEE80211_CHAN_G)
  2237. #define IS_CHAN_ANYG(flags) \
  2238. (IS_CHAN_PUREG(flags) || IS_CHAN_G(flags))
  2239. static void
  2240. print_chaninfo(netdissect_options *ndo,
  2241. uint16_t freq, int flags, int presentflags)
  2242. {
  2243. ND_PRINT((ndo, "%u MHz", freq));
  2244. if (presentflags & (1 << IEEE80211_RADIOTAP_MCS)) {
  2245. /*
  2246. * We have the MCS field, so this is 11n, regardless
  2247. * of what the channel flags say.
  2248. */
  2249. ND_PRINT((ndo, " 11n"));
  2250. } else {
  2251. if (IS_CHAN_FHSS(flags))
  2252. ND_PRINT((ndo, " FHSS"));
  2253. if (IS_CHAN_A(flags)) {
  2254. if (flags & IEEE80211_CHAN_HALF)
  2255. ND_PRINT((ndo, " 11a/10Mhz"));
  2256. else if (flags & IEEE80211_CHAN_QUARTER)
  2257. ND_PRINT((ndo, " 11a/5Mhz"));
  2258. else
  2259. ND_PRINT((ndo, " 11a"));
  2260. }
  2261. if (IS_CHAN_ANYG(flags)) {
  2262. if (flags & IEEE80211_CHAN_HALF)
  2263. ND_PRINT((ndo, " 11g/10Mhz"));
  2264. else if (flags & IEEE80211_CHAN_QUARTER)
  2265. ND_PRINT((ndo, " 11g/5Mhz"));
  2266. else
  2267. ND_PRINT((ndo, " 11g"));
  2268. } else if (IS_CHAN_B(flags))
  2269. ND_PRINT((ndo, " 11b"));
  2270. if (flags & IEEE80211_CHAN_TURBO)
  2271. ND_PRINT((ndo, " Turbo"));
  2272. }
  2273. /*
  2274. * These apply to 11n.
  2275. */
  2276. if (flags & IEEE80211_CHAN_HT20)
  2277. ND_PRINT((ndo, " ht/20"));
  2278. else if (flags & IEEE80211_CHAN_HT40D)
  2279. ND_PRINT((ndo, " ht/40-"));
  2280. else if (flags & IEEE80211_CHAN_HT40U)
  2281. ND_PRINT((ndo, " ht/40+"));
  2282. ND_PRINT((ndo, " "));
  2283. }
  2284. static int
  2285. print_radiotap_field(netdissect_options *ndo,
  2286. struct cpack_state *s, uint32_t bit, uint8_t *flagsp,
  2287. uint32_t presentflags)
  2288. {
  2289. u_int i;
  2290. int rc;
  2291. switch (bit) {
  2292. case IEEE80211_RADIOTAP_TSFT: {
  2293. uint64_t tsft;
  2294. rc = cpack_uint64(s, &tsft);
  2295. if (rc != 0)
  2296. goto trunc;
  2297. ND_PRINT((ndo, "%" PRIu64 "us tsft ", tsft));
  2298. break;
  2299. }
  2300. case IEEE80211_RADIOTAP_FLAGS: {
  2301. uint8_t flagsval;
  2302. rc = cpack_uint8(s, &flagsval);
  2303. if (rc != 0)
  2304. goto trunc;
  2305. *flagsp = flagsval;
  2306. if (flagsval & IEEE80211_RADIOTAP_F_CFP)
  2307. ND_PRINT((ndo, "cfp "));
  2308. if (flagsval & IEEE80211_RADIOTAP_F_SHORTPRE)
  2309. ND_PRINT((ndo, "short preamble "));
  2310. if (flagsval & IEEE80211_RADIOTAP_F_WEP)
  2311. ND_PRINT((ndo, "wep "));
  2312. if (flagsval & IEEE80211_RADIOTAP_F_FRAG)
  2313. ND_PRINT((ndo, "fragmented "));
  2314. if (flagsval & IEEE80211_RADIOTAP_F_BADFCS)
  2315. ND_PRINT((ndo, "bad-fcs "));
  2316. break;
  2317. }
  2318. case IEEE80211_RADIOTAP_RATE: {
  2319. uint8_t rate;
  2320. rc = cpack_uint8(s, &rate);
  2321. if (rc != 0)
  2322. goto trunc;
  2323. /*
  2324. * XXX On FreeBSD rate & 0x80 means we have an MCS. On
  2325. * Linux and AirPcap it does not. (What about
  2326. * Mac OS X, NetBSD, OpenBSD, and DragonFly BSD?)
  2327. *
  2328. * This is an issue either for proprietary extensions
  2329. * to 11a or 11g, which do exist, or for 11n
  2330. * implementations that stuff a rate value into
  2331. * this field, which also appear to exist.
  2332. *
  2333. * We currently handle that by assuming that
  2334. * if the 0x80 bit is set *and* the remaining
  2335. * bits have a value between 0 and 15 it's
  2336. * an MCS value, otherwise it's a rate. If
  2337. * there are cases where systems that use
  2338. * "0x80 + MCS index" for MCS indices > 15,
  2339. * or stuff a rate value here between 64 and
  2340. * 71.5 Mb/s in here, we'll need a preference
  2341. * setting. Such rates do exist, e.g. 11n
  2342. * MCS 7 at 20 MHz with a long guard interval.
  2343. */
  2344. if (rate >= 0x80 && rate <= 0x8f) {
  2345. /*
  2346. * XXX - we don't know the channel width
  2347. * or guard interval length, so we can't
  2348. * convert this to a data rate.
  2349. *
  2350. * If you want us to show a data rate,
  2351. * use the MCS field, not the Rate field;
  2352. * the MCS field includes not only the
  2353. * MCS index, it also includes bandwidth
  2354. * and guard interval information.
  2355. *
  2356. * XXX - can we get the channel width
  2357. * from XChannel and the guard interval
  2358. * information from Flags, at least on
  2359. * FreeBSD?
  2360. */
  2361. ND_PRINT((ndo, "MCS %u ", rate & 0x7f));
  2362. } else
  2363. ND_PRINT((ndo, "%2.1f Mb/s ", .5 * rate));
  2364. break;
  2365. }
  2366. case IEEE80211_RADIOTAP_CHANNEL: {
  2367. uint16_t frequency;
  2368. uint16_t flags;
  2369. rc = cpack_uint16(s, &frequency);
  2370. if (rc != 0)
  2371. goto trunc;
  2372. rc = cpack_uint16(s, &flags);
  2373. if (rc != 0)
  2374. goto trunc;
  2375. /*
  2376. * If CHANNEL and XCHANNEL are both present, skip
  2377. * CHANNEL.
  2378. */
  2379. if (presentflags & (1 << IEEE80211_RADIOTAP_XCHANNEL))
  2380. break;
  2381. print_chaninfo(ndo, frequency, flags, presentflags);
  2382. break;
  2383. }
  2384. case IEEE80211_RADIOTAP_FHSS: {
  2385. uint8_t hopset;
  2386. uint8_t hoppat;
  2387. rc = cpack_uint8(s, &hopset);
  2388. if (rc != 0)
  2389. goto trunc;
  2390. rc = cpack_uint8(s, &hoppat);
  2391. if (rc != 0)
  2392. goto trunc;
  2393. ND_PRINT((ndo, "fhset %d fhpat %d ", hopset, hoppat));
  2394. break;
  2395. }
  2396. case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: {
  2397. int8_t dbm_antsignal;
  2398. rc = cpack_int8(s, &dbm_antsignal);
  2399. if (rc != 0)
  2400. goto trunc;
  2401. ND_PRINT((ndo, "%ddBm signal ", dbm_antsignal));
  2402. break;
  2403. }
  2404. case IEEE80211_RADIOTAP_DBM_ANTNOISE: {
  2405. int8_t dbm_antnoise;
  2406. rc = cpack_int8(s, &dbm_antnoise);
  2407. if (rc != 0)
  2408. goto trunc;
  2409. ND_PRINT((ndo, "%ddBm noise ", dbm_antnoise));
  2410. break;
  2411. }
  2412. case IEEE80211_RADIOTAP_LOCK_QUALITY: {
  2413. uint16_t lock_quality;
  2414. rc = cpack_uint16(s, &lock_quality);
  2415. if (rc != 0)
  2416. goto trunc;
  2417. ND_PRINT((ndo, "%u sq ", lock_quality));
  2418. break;
  2419. }
  2420. case IEEE80211_RADIOTAP_TX_ATTENUATION: {
  2421. uint16_t tx_attenuation;
  2422. rc = cpack_uint16(s, &tx_attenuation);
  2423. if (rc != 0)
  2424. goto trunc;
  2425. ND_PRINT((ndo, "%d tx power ", -(int)tx_attenuation));
  2426. break;
  2427. }
  2428. case IEEE80211_RADIOTAP_DB_TX_ATTENUATION: {
  2429. uint8_t db_tx_attenuation;
  2430. rc = cpack_uint8(s, &db_tx_attenuation);
  2431. if (rc != 0)
  2432. goto trunc;
  2433. ND_PRINT((ndo, "%ddB tx attenuation ", -(int)db_tx_attenuation));
  2434. break;
  2435. }
  2436. case IEEE80211_RADIOTAP_DBM_TX_POWER: {
  2437. int8_t dbm_tx_power;
  2438. rc = cpack_int8(s, &dbm_tx_power);
  2439. if (rc != 0)
  2440. goto trunc;
  2441. ND_PRINT((ndo, "%ddBm tx power ", dbm_tx_power));
  2442. break;
  2443. }
  2444. case IEEE80211_RADIOTAP_ANTENNA: {
  2445. uint8_t antenna;
  2446. rc = cpack_uint8(s, &antenna);
  2447. if (rc != 0)
  2448. goto trunc;
  2449. ND_PRINT((ndo, "antenna %u ", antenna));
  2450. break;
  2451. }
  2452. case IEEE80211_RADIOTAP_DB_ANTSIGNAL: {
  2453. uint8_t db_antsignal;
  2454. rc = cpack_uint8(s, &db_antsignal);
  2455. if (rc != 0)
  2456. goto trunc;
  2457. ND_PRINT((ndo, "%ddB signal ", db_antsignal));
  2458. break;
  2459. }
  2460. case IEEE80211_RADIOTAP_DB_ANTNOISE: {
  2461. uint8_t db_antnoise;
  2462. rc = cpack_uint8(s, &db_antnoise);
  2463. if (rc != 0)
  2464. goto trunc;
  2465. ND_PRINT((ndo, "%ddB noise ", db_antnoise));
  2466. break;
  2467. }
  2468. case IEEE80211_RADIOTAP_RX_FLAGS: {
  2469. uint16_t rx_flags;
  2470. rc = cpack_uint16(s, &rx_flags);
  2471. if (rc != 0)
  2472. goto trunc;
  2473. /* Do nothing for now */
  2474. break;
  2475. }
  2476. case IEEE80211_RADIOTAP_XCHANNEL: {
  2477. uint32_t flags;
  2478. uint16_t frequency;
  2479. uint8_t channel;
  2480. uint8_t maxpower;
  2481. rc = cpack_uint32(s, &flags);
  2482. if (rc != 0)
  2483. goto trunc;
  2484. rc = cpack_uint16(s, &frequency);
  2485. if (rc != 0)
  2486. goto trunc;
  2487. rc = cpack_uint8(s, &channel);
  2488. if (rc != 0)
  2489. goto trunc;
  2490. rc = cpack_uint8(s, &maxpower);
  2491. if (rc != 0)
  2492. goto trunc;
  2493. print_chaninfo(ndo, frequency, flags, presentflags);
  2494. break;
  2495. }
  2496. case IEEE80211_RADIOTAP_MCS: {
  2497. uint8_t known;
  2498. uint8_t flags;
  2499. uint8_t mcs_index;
  2500. static const char *ht_bandwidth[4] = {
  2501. "20 MHz",
  2502. "40 MHz",
  2503. "20 MHz (L)",
  2504. "20 MHz (U)"
  2505. };
  2506. float htrate;
  2507. rc = cpack_uint8(s, &known);
  2508. if (rc != 0)
  2509. goto trunc;
  2510. rc = cpack_uint8(s, &flags);
  2511. if (rc != 0)
  2512. goto trunc;
  2513. rc = cpack_uint8(s, &mcs_index);
  2514. if (rc != 0)
  2515. goto trunc;
  2516. if (known & IEEE80211_RADIOTAP_MCS_MCS_INDEX_KNOWN) {
  2517. /*
  2518. * We know the MCS index.
  2519. */
  2520. if (mcs_index <= MAX_MCS_INDEX) {
  2521. /*
  2522. * And it's in-range.
  2523. */
  2524. if (known & (IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN|IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN)) {
  2525. /*
  2526. * And we know both the bandwidth and
  2527. * the guard interval, so we can look
  2528. * up the rate.
  2529. */
  2530. htrate =
  2531. ieee80211_float_htrates \
  2532. [mcs_index] \
  2533. [((flags & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK) == IEEE80211_RADIOTAP_MCS_BANDWIDTH_40 ? 1 : 0)] \
  2534. [((flags & IEEE80211_RADIOTAP_MCS_SHORT_GI) ? 1 : 0)];
  2535. } else {
  2536. /*
  2537. * We don't know both the bandwidth
  2538. * and the guard interval, so we can
  2539. * only report the MCS index.
  2540. */
  2541. htrate = 0.0;
  2542. }
  2543. } else {
  2544. /*
  2545. * The MCS value is out of range.
  2546. */
  2547. htrate = 0.0;
  2548. }
  2549. if (htrate != 0.0) {
  2550. /*
  2551. * We have the rate.
  2552. * Print it.
  2553. */
  2554. ND_PRINT((ndo, "%.1f Mb/s MCS %u ", htrate, mcs_index));
  2555. } else {
  2556. /*
  2557. * We at least have the MCS index.
  2558. * Print it.
  2559. */
  2560. ND_PRINT((ndo, "MCS %u ", mcs_index));
  2561. }
  2562. }
  2563. if (known & IEEE80211_RADIOTAP_MCS_BANDWIDTH_KNOWN) {
  2564. ND_PRINT((ndo, "%s ",
  2565. ht_bandwidth[flags & IEEE80211_RADIOTAP_MCS_BANDWIDTH_MASK]));
  2566. }
  2567. if (known & IEEE80211_RADIOTAP_MCS_GUARD_INTERVAL_KNOWN) {
  2568. ND_PRINT((ndo, "%s GI ",
  2569. (flags & IEEE80211_RADIOTAP_MCS_SHORT_GI) ?
  2570. "short" : "long"));
  2571. }
  2572. if (known & IEEE80211_RADIOTAP_MCS_HT_FORMAT_KNOWN) {
  2573. ND_PRINT((ndo, "%s ",
  2574. (flags & IEEE80211_RADIOTAP_MCS_HT_GREENFIELD) ?
  2575. "greenfield" : "mixed"));
  2576. }
  2577. if (known & IEEE80211_RADIOTAP_MCS_FEC_TYPE_KNOWN) {
  2578. ND_PRINT((ndo, "%s FEC ",
  2579. (flags & IEEE80211_RADIOTAP_MCS_FEC_LDPC) ?
  2580. "LDPC" : "BCC"));
  2581. }
  2582. if (known & IEEE80211_RADIOTAP_MCS_STBC_KNOWN) {
  2583. ND_PRINT((ndo, "RX-STBC%u ",
  2584. (flags & IEEE80211_RADIOTAP_MCS_STBC_MASK) >> IEEE80211_RADIOTAP_MCS_STBC_SHIFT));
  2585. }
  2586. break;
  2587. }
  2588. case IEEE80211_RADIOTAP_AMPDU_STATUS: {
  2589. uint32_t reference_num;
  2590. uint16_t flags;
  2591. uint8_t delim_crc;
  2592. uint8_t reserved;
  2593. rc = cpack_uint32(s, &reference_num);
  2594. if (rc != 0)
  2595. goto trunc;
  2596. rc = cpack_uint16(s, &flags);
  2597. if (rc != 0)
  2598. goto trunc;
  2599. rc = cpack_uint8(s, &delim_crc);
  2600. if (rc != 0)
  2601. goto trunc;
  2602. rc = cpack_uint8(s, &reserved);
  2603. if (rc != 0)
  2604. goto trunc;
  2605. /* Do nothing for now */
  2606. break;
  2607. }
  2608. case IEEE80211_RADIOTAP_VHT: {
  2609. uint16_t known;
  2610. uint8_t flags;
  2611. uint8_t bandwidth;
  2612. uint8_t mcs_nss[4];
  2613. uint8_t coding;
  2614. uint8_t group_id;
  2615. uint16_t partial_aid;
  2616. static const char *vht_bandwidth[32] = {
  2617. "20 MHz",
  2618. "40 MHz",
  2619. "20 MHz (L)",
  2620. "20 MHz (U)",
  2621. "80 MHz",
  2622. "80 MHz (L)",
  2623. "80 MHz (U)",
  2624. "80 MHz (LL)",
  2625. "80 MHz (LU)",
  2626. "80 MHz (UL)",
  2627. "80 MHz (UU)",
  2628. "160 MHz",
  2629. "160 MHz (L)",
  2630. "160 MHz (U)",
  2631. "160 MHz (LL)",
  2632. "160 MHz (LU)",
  2633. "160 MHz (UL)",
  2634. "160 MHz (UU)",
  2635. "160 MHz (LLL)",
  2636. "160 MHz (LLU)",
  2637. "160 MHz (LUL)",
  2638. "160 MHz (UUU)",
  2639. "160 MHz (ULL)",
  2640. "160 MHz (ULU)",
  2641. "160 MHz (UUL)",
  2642. "160 MHz (UUU)",
  2643. "unknown (26)",
  2644. "unknown (27)",
  2645. "unknown (28)",
  2646. "unknown (29)",
  2647. "unknown (30)",
  2648. "unknown (31)"
  2649. };
  2650. rc = cpack_uint16(s, &known);
  2651. if (rc != 0)
  2652. goto trunc;
  2653. rc = cpack_uint8(s, &flags);
  2654. if (rc != 0)
  2655. goto trunc;
  2656. rc = cpack_uint8(s, &bandwidth);
  2657. if (rc != 0)
  2658. goto trunc;
  2659. for (i = 0; i < 4; i++) {
  2660. rc = cpack_uint8(s, &mcs_nss[i]);
  2661. if (rc != 0)
  2662. goto trunc;
  2663. }
  2664. rc = cpack_uint8(s, &coding);
  2665. if (rc != 0)
  2666. goto trunc;
  2667. rc = cpack_uint8(s, &group_id);
  2668. if (rc != 0)
  2669. goto trunc;
  2670. rc = cpack_uint16(s, &partial_aid);
  2671. if (rc != 0)
  2672. goto trunc;
  2673. for (i = 0; i < 4; i++) {
  2674. u_int nss, mcs;
  2675. nss = mcs_nss[i] & IEEE80211_RADIOTAP_VHT_NSS_MASK;
  2676. mcs = (mcs_nss[i] & IEEE80211_RADIOTAP_VHT_MCS_MASK) >> IEEE80211_RADIOTAP_VHT_MCS_SHIFT;
  2677. if (nss == 0)
  2678. continue;
  2679. ND_PRINT((ndo, "User %u MCS %u ", i, mcs));
  2680. ND_PRINT((ndo, "%s FEC ",
  2681. (coding & (IEEE80211_RADIOTAP_CODING_LDPC_USERn << i)) ?
  2682. "LDPC" : "BCC"));
  2683. }
  2684. if (known & IEEE80211_RADIOTAP_VHT_BANDWIDTH_KNOWN) {
  2685. ND_PRINT((ndo, "%s ",
  2686. vht_bandwidth[bandwidth & IEEE80211_RADIOTAP_VHT_BANDWIDTH_MASK]));
  2687. }
  2688. if (known & IEEE80211_RADIOTAP_VHT_GUARD_INTERVAL_KNOWN) {
  2689. ND_PRINT((ndo, "%s GI ",
  2690. (flags & IEEE80211_RADIOTAP_VHT_SHORT_GI) ?
  2691. "short" : "long"));
  2692. }
  2693. break;
  2694. }
  2695. default:
  2696. /* this bit indicates a field whose
  2697. * size we do not know, so we cannot
  2698. * proceed. Just print the bit number.
  2699. */
  2700. ND_PRINT((ndo, "[bit %u] ", bit));
  2701. return -1;
  2702. }
  2703. return 0;
  2704. trunc:
  2705. ND_PRINT((ndo, "%s", tstr));
  2706. return rc;
  2707. }
  2708. static int
  2709. print_in_radiotap_namespace(netdissect_options *ndo,
  2710. struct cpack_state *s, uint8_t *flags,
  2711. uint32_t presentflags, int bit0)
  2712. {
  2713. #define BITNO_32(x) (((x) >> 16) ? 16 + BITNO_16((x) >> 16) : BITNO_16((x)))
  2714. #define BITNO_16(x) (((x) >> 8) ? 8 + BITNO_8((x) >> 8) : BITNO_8((x)))
  2715. #define BITNO_8(x) (((x) >> 4) ? 4 + BITNO_4((x) >> 4) : BITNO_4((x)))
  2716. #define BITNO_4(x) (((x) >> 2) ? 2 + BITNO_2((x) >> 2) : BITNO_2((x)))
  2717. #define BITNO_2(x) (((x) & 2) ? 1 : 0)
  2718. uint32_t present, next_present;
  2719. int bitno;
  2720. enum ieee80211_radiotap_type bit;
  2721. int rc;
  2722. for (present = presentflags; present; present = next_present) {
  2723. /*
  2724. * Clear the least significant bit that is set.
  2725. */
  2726. next_present = present & (present - 1);
  2727. /*
  2728. * Get the bit number, within this presence word,
  2729. * of the remaining least significant bit that
  2730. * is set.
  2731. */
  2732. bitno = BITNO_32(present ^ next_present);
  2733. /*
  2734. * Stop if this is one of the "same meaning
  2735. * in all presence flags" bits.
  2736. */
  2737. if (bitno >= IEEE80211_RADIOTAP_NAMESPACE)
  2738. break;
  2739. /*
  2740. * Get the radiotap bit number of that bit.
  2741. */
  2742. bit = (enum ieee80211_radiotap_type)(bit0 + bitno);
  2743. rc = print_radiotap_field(ndo, s, bit, flags, presentflags);
  2744. if (rc != 0)
  2745. return rc;
  2746. }
  2747. return 0;
  2748. }
  2749. static u_int
  2750. ieee802_11_radio_print(netdissect_options *ndo,
  2751. const u_char *p, u_int length, u_int caplen)
  2752. {
  2753. #define BIT(n) (1U << n)
  2754. #define IS_EXTENDED(__p) \
  2755. (EXTRACT_LE_32BITS(__p) & BIT(IEEE80211_RADIOTAP_EXT)) != 0
  2756. struct cpack_state cpacker;
  2757. const struct ieee80211_radiotap_header *hdr;
  2758. uint32_t presentflags;
  2759. const uint32_t *presentp, *last_presentp;
  2760. int vendor_namespace;
  2761. uint8_t vendor_oui[3];
  2762. uint8_t vendor_subnamespace;
  2763. uint16_t skip_length;
  2764. int bit0;
  2765. u_int len;
  2766. uint8_t flags;
  2767. int pad;
  2768. u_int fcslen;
  2769. if (caplen < sizeof(*hdr)) {
  2770. ND_PRINT((ndo, "%s", tstr));
  2771. return caplen;
  2772. }
  2773. hdr = (const struct ieee80211_radiotap_header *)p;
  2774. len = EXTRACT_LE_16BITS(&hdr->it_len);
  2775. /*
  2776. * If we don't have the entire radiotap header, just give up.
  2777. */
  2778. if (caplen < len) {
  2779. ND_PRINT((ndo, "%s", tstr));
  2780. return caplen;
  2781. }
  2782. cpack_init(&cpacker, (const uint8_t *)hdr, len); /* align against header start */
  2783. cpack_advance(&cpacker, sizeof(*hdr)); /* includes the 1st bitmap */
  2784. for (last_presentp = &hdr->it_present;
  2785. (const u_char*)(last_presentp + 1) <= p + len &&
  2786. IS_EXTENDED(last_presentp);
  2787. last_presentp++)
  2788. cpack_advance(&cpacker, sizeof(hdr->it_present)); /* more bitmaps */
  2789. /* are there more bitmap extensions than bytes in header? */
  2790. if ((const u_char*)(last_presentp + 1) > p + len) {
  2791. ND_PRINT((ndo, "%s", tstr));
  2792. return caplen;
  2793. }
  2794. /*
  2795. * Start out at the beginning of the default radiotap namespace.
  2796. */
  2797. bit0 = 0;
  2798. vendor_namespace = 0;
  2799. memset(vendor_oui, 0, 3);
  2800. vendor_subnamespace = 0;
  2801. skip_length = 0;
  2802. /* Assume no flags */
  2803. flags = 0;
  2804. /* Assume no Atheros padding between 802.11 header and body */
  2805. pad = 0;
  2806. /* Assume no FCS at end of frame */
  2807. fcslen = 0;
  2808. for (presentp = &hdr->it_present; presentp <= last_presentp;
  2809. presentp++) {
  2810. presentflags = EXTRACT_LE_32BITS(presentp);
  2811. /*
  2812. * If this is a vendor namespace, we don't handle it.
  2813. */
  2814. if (vendor_namespace) {
  2815. /*
  2816. * Skip past the stuff we don't understand.
  2817. * If we add support for any vendor namespaces,
  2818. * it'd be added here; use vendor_oui and
  2819. * vendor_subnamespace to interpret the fields.
  2820. */
  2821. if (cpack_advance(&cpacker, skip_length) != 0) {
  2822. /*
  2823. * Ran out of space in the packet.
  2824. */
  2825. break;
  2826. }
  2827. /*
  2828. * We've skipped it all; nothing more to
  2829. * skip.
  2830. */
  2831. skip_length = 0;
  2832. } else {
  2833. if (print_in_radiotap_namespace(ndo, &cpacker,
  2834. &flags, presentflags, bit0) != 0) {
  2835. /*
  2836. * Fatal error - can't process anything
  2837. * more in the radiotap header.
  2838. */
  2839. break;
  2840. }
  2841. }
  2842. /*
  2843. * Handle the namespace switch bits; we've already handled
  2844. * the extension bit in all but the last word above.
  2845. */
  2846. switch (presentflags &
  2847. (BIT(IEEE80211_RADIOTAP_NAMESPACE)|BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE))) {
  2848. case 0:
  2849. /*
  2850. * We're not changing namespaces.
  2851. * advance to the next 32 bits in the current
  2852. * namespace.
  2853. */
  2854. bit0 += 32;
  2855. break;
  2856. case BIT(IEEE80211_RADIOTAP_NAMESPACE):
  2857. /*
  2858. * We're switching to the radiotap namespace.
  2859. * Reset the presence-bitmap index to 0, and
  2860. * reset the namespace to the default radiotap
  2861. * namespace.
  2862. */
  2863. bit0 = 0;
  2864. vendor_namespace = 0;
  2865. memset(vendor_oui, 0, 3);
  2866. vendor_subnamespace = 0;
  2867. skip_length = 0;
  2868. break;
  2869. case BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE):
  2870. /*
  2871. * We're switching to a vendor namespace.
  2872. * Reset the presence-bitmap index to 0,
  2873. * note that we're in a vendor namespace,
  2874. * and fetch the fields of the Vendor Namespace
  2875. * item.
  2876. */
  2877. bit0 = 0;
  2878. vendor_namespace = 1;
  2879. if ((cpack_align_and_reserve(&cpacker, 2)) == NULL) {
  2880. ND_PRINT((ndo, "%s", tstr));
  2881. break;
  2882. }
  2883. if (cpack_uint8(&cpacker, &vendor_oui[0]) != 0) {
  2884. ND_PRINT((ndo, "%s", tstr));
  2885. break;
  2886. }
  2887. if (cpack_uint8(&cpacker, &vendor_oui[1]) != 0) {
  2888. ND_PRINT((ndo, "%s", tstr));
  2889. break;
  2890. }
  2891. if (cpack_uint8(&cpacker, &vendor_oui[2]) != 0) {
  2892. ND_PRINT((ndo, "%s", tstr));
  2893. break;
  2894. }
  2895. if (cpack_uint8(&cpacker, &vendor_subnamespace) != 0) {
  2896. ND_PRINT((ndo, "%s", tstr));
  2897. break;
  2898. }
  2899. if (cpack_uint16(&cpacker, &skip_length) != 0) {
  2900. ND_PRINT((ndo, "%s", tstr));
  2901. break;
  2902. }
  2903. break;
  2904. default:
  2905. /*
  2906. * Illegal combination. The behavior in this
  2907. * case is undefined by the radiotap spec; we
  2908. * just ignore both bits.
  2909. */
  2910. break;
  2911. }
  2912. }
  2913. if (flags & IEEE80211_RADIOTAP_F_DATAPAD)
  2914. pad = 1; /* Atheros padding */
  2915. if (flags & IEEE80211_RADIOTAP_F_FCS)
  2916. fcslen = 4; /* FCS at end of packet */
  2917. return len + ieee802_11_print(ndo, p + len, length - len, caplen - len, pad,
  2918. fcslen);
  2919. #undef BITNO_32
  2920. #undef BITNO_16
  2921. #undef BITNO_8
  2922. #undef BITNO_4
  2923. #undef BITNO_2
  2924. #undef BIT
  2925. }
  2926. static u_int
  2927. ieee802_11_avs_radio_print(netdissect_options *ndo,
  2928. const u_char *p, u_int length, u_int caplen)
  2929. {
  2930. uint32_t caphdr_len;
  2931. if (caplen < 8) {
  2932. ND_PRINT((ndo, "%s", tstr));
  2933. return caplen;
  2934. }
  2935. caphdr_len = EXTRACT_32BITS(p + 4);
  2936. if (caphdr_len < 8) {
  2937. /*
  2938. * Yow! The capture header length is claimed not
  2939. * to be large enough to include even the version
  2940. * cookie or capture header length!
  2941. */
  2942. ND_PRINT((ndo, "%s", tstr));
  2943. return caplen;
  2944. }
  2945. if (caplen < caphdr_len) {
  2946. ND_PRINT((ndo, "%s", tstr));
  2947. return caplen;
  2948. }
  2949. return caphdr_len + ieee802_11_print(ndo, p + caphdr_len,
  2950. length - caphdr_len, caplen - caphdr_len, 0, 0);
  2951. }
  2952. #define PRISM_HDR_LEN 144
  2953. #define WLANCAP_MAGIC_COOKIE_BASE 0x80211000
  2954. #define WLANCAP_MAGIC_COOKIE_V1 0x80211001
  2955. #define WLANCAP_MAGIC_COOKIE_V2 0x80211002
  2956. /*
  2957. * For DLT_PRISM_HEADER; like DLT_IEEE802_11, but with an extra header,
  2958. * containing information such as radio information, which we
  2959. * currently ignore.
  2960. *
  2961. * If, however, the packet begins with WLANCAP_MAGIC_COOKIE_V1 or
  2962. * WLANCAP_MAGIC_COOKIE_V2, it's really DLT_IEEE802_11_RADIO_AVS
  2963. * (currently, on Linux, there's no ARPHRD_ type for
  2964. * DLT_IEEE802_11_RADIO_AVS, as there is a ARPHRD_IEEE80211_PRISM
  2965. * for DLT_PRISM_HEADER, so ARPHRD_IEEE80211_PRISM is used for
  2966. * the AVS header, and the first 4 bytes of the header are used to
  2967. * indicate whether it's a Prism header or an AVS header).
  2968. */
  2969. u_int
  2970. prism_if_print(netdissect_options *ndo,
  2971. const struct pcap_pkthdr *h, const u_char *p)
  2972. {
  2973. u_int caplen = h->caplen;
  2974. u_int length = h->len;
  2975. uint32_t msgcode;
  2976. if (caplen < 4) {
  2977. ND_PRINT((ndo, "%s", tstr));
  2978. return caplen;
  2979. }
  2980. msgcode = EXTRACT_32BITS(p);
  2981. if (msgcode == WLANCAP_MAGIC_COOKIE_V1 ||
  2982. msgcode == WLANCAP_MAGIC_COOKIE_V2)
  2983. return ieee802_11_avs_radio_print(ndo, p, length, caplen);
  2984. if (caplen < PRISM_HDR_LEN) {
  2985. ND_PRINT((ndo, "%s", tstr));
  2986. return caplen;
  2987. }
  2988. return PRISM_HDR_LEN + ieee802_11_print(ndo, p + PRISM_HDR_LEN,
  2989. length - PRISM_HDR_LEN, caplen - PRISM_HDR_LEN, 0, 0);
  2990. }
  2991. /*
  2992. * For DLT_IEEE802_11_RADIO; like DLT_IEEE802_11, but with an extra
  2993. * header, containing information such as radio information.
  2994. */
  2995. u_int
  2996. ieee802_11_radio_if_print(netdissect_options *ndo,
  2997. const struct pcap_pkthdr *h, const u_char *p)
  2998. {
  2999. return ieee802_11_radio_print(ndo, p, h->len, h->caplen);
  3000. }
  3001. /*
  3002. * For DLT_IEEE802_11_RADIO_AVS; like DLT_IEEE802_11, but with an
  3003. * extra header, containing information such as radio information,
  3004. * which we currently ignore.
  3005. */
  3006. u_int
  3007. ieee802_11_radio_avs_if_print(netdissect_options *ndo,
  3008. const struct pcap_pkthdr *h, const u_char *p)
  3009. {
  3010. return ieee802_11_avs_radio_print(ndo, p, h->len, h->caplen);
  3011. }