5fb6dc7e4379240d3424d75b0edafc42e67c29c8
[netsniff-ng.git] / src / proto_80211_mac_hdr.c
blob5fb6dc7e4379240d3424d75b0edafc42e67c29c8
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012 Markus Amend <markus@netsniff-ng.org>
4 * Copyright 2012 Daniel Borkmann <daniel@netsniff-ng.org>
5 * Subject to the GPL, version 2.
6 */
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <netinet/in.h> /* for ntohs() */
11 #include <asm/byteorder.h>
12 #include <arpa/inet.h> /* for inet_ntop() */
14 #include "proto.h"
15 #include "protos.h"
16 #include "dissector_80211.h"
17 #include "built_in.h"
18 #include "pkt_buff.h"
19 #include "oui.h"
21 #define TU 0.001024
23 /* Note: Fields are encoded in little-endian! */
24 struct ieee80211_frm_ctrl {
25 union {
26 u16 frame_control;
27 struct {
28 #if defined(__LITTLE_ENDIAN_BITFIELD)
29 /* Correct order here ... */
30 __extension__ u16 proto_version:2,
31 type:2,
32 subtype:4,
33 to_ds:1,
34 from_ds:1,
35 more_frags:1,
36 retry:1,
37 power_mgmt:1,
38 more_data:1,
39 wep:1,
40 order:1;
41 #elif defined(__BIG_ENDIAN_BITFIELD)
42 __extension__ u16 subtype:4,
43 type:2,
44 proto_version:2,
45 order:1,
46 wep:1,
47 more_data:1,
48 power_mgmt:1,
49 retry:1,
50 more_frags:1,
51 from_ds:1,
52 to_ds:1;
53 #else
54 # error "Adjust your <asm/byteorder.h> defines"
55 #endif
58 } __packed;
60 /* Management Frame start */
61 /* Note: Fields are encoded in little-endian! */
62 struct ieee80211_mgmt {
63 u16 duration;
64 u8 da[6];
65 u8 sa[6];
66 u8 bssid[6];
67 u16 seq_ctrl;
68 } __packed;
70 struct ieee80211_mgmt_auth {
71 u16 auth_alg;
72 u16 auth_transaction;
73 u16 status_code;
74 /* possibly followed by Challenge text */
75 u8 variable[0];
76 } __packed;
78 struct ieee80211_mgmt_deauth {
79 u16 reason_code;
80 } __packed;
82 struct ieee80211_mgmt_assoc_req {
83 u16 capab_info;
84 u16 listen_interval;
85 /* followed by SSID and Supported rates */
86 u8 variable[0];
87 } __packed;
89 struct ieee80211_mgmt_assoc_resp {
90 u16 capab_info;
91 u16 status_code;
92 u16 aid;
93 /* followed by Supported rates */
94 u8 variable[0];
95 } __packed;
97 struct ieee80211_mgmt_reassoc_resp {
98 u16 capab_info;
99 u16 status_code;
100 u16 aid;
101 /* followed by Supported rates */
102 u8 variable[0];
103 } __packed;
105 struct ieee80211_mgmt_reassoc_req {
106 u16 capab_info;
107 u16 listen_interval;
108 u8 current_ap[6];
109 /* followed by SSID and Supported rates */
110 u8 variable[0];
111 } __packed;
113 struct ieee80211_mgmt_disassoc {
114 u16 reason_code;
115 } __packed;
117 struct ieee80211_mgmt_probe_req {
118 } __packed;
120 struct ieee80211_mgmt_beacon {
121 u64 timestamp;
122 u16 beacon_int;
123 u16 capab_info;
124 /* followed by some of SSID, Supported rates,
125 * FH Params, DS Params, CF Params, IBSS Params, TIM */
126 u8 variable[0];
127 } __packed;
129 struct ieee80211_mgmt_probe_resp {
130 u8 timestamp[8];
131 u16 beacon_int;
132 u16 capab_info;
133 /* followed by some of SSID, Supported rates,
134 * FH Params, DS Params, CF Params, IBSS Params, TIM */
135 u8 variable[0];
136 } __packed;
137 /* Management Frame end */
139 /* Control Frame start */
140 /* Note: Fields are encoded in little-endian! */
141 struct ieee80211_ctrl {
142 } __packed;
144 struct ieee80211_ctrl_rts {
145 u16 duration;
146 u8 da[6];
147 u8 sa[6];
148 } __packed;
150 struct ieee80211_ctrl_cts {
151 u16 duration;
152 u8 da[6];
153 } __packed;
155 struct ieee80211_ctrl_ack {
156 u16 duration;
157 u8 da[6];
158 } __packed;
160 struct ieee80211_ctrl_ps_poll {
161 u16 aid;
162 u8 bssid[6];
163 u8 sa[6];
164 } __packed;
166 struct ieee80211_ctrl_cf_end {
167 u16 duration;
168 u8 bssid[6];
169 u8 sa[6];
170 } __packed;
172 struct ieee80211_ctrl_cf_end_ack {
173 u16 duration;
174 u8 bssid[6];
175 u8 sa[6];
176 } __packed;
177 /* Control Frame end */
179 /* Data Frame start */
180 /* Note: Fields are encoded in little-endian! */
181 struct ieee80211_data {
182 } __packed;
184 /* TODO: Extend */
185 /* Data Frame end */
187 /* http://www.sss-mag.com/pdf/802_11tut.pdf
188 * http://www.scribd.com/doc/78443651/111/Management-Frames
189 * http://www.wildpackets.com/resources/compendium/wireless_lan/wlan_packets
190 * http://www.rhyshaden.com/wireless.htm
193 struct element_reserved {
194 u8 len;
195 } __packed;
197 struct element_ssid {
198 u8 len;
199 u8 SSID[0];
200 } __packed;
202 struct element_supp_rates {
203 u8 len;
204 u8 SSID[0];
205 } __packed;
207 struct element_fh_ps {
208 u8 len;
209 u16 dwell_time;
210 u8 hop_set;
211 u8 hop_pattern;
212 u8 hop_index;
213 } __packed;
215 struct element_dsss_ps {
216 u8 len;
217 u8 curr_ch;
218 } __packed;
220 struct element_cf_ps {
221 u8 len;
222 u8 cfp_cnt;
223 u8 cfp_period;
224 u16 cfp_max_dur;
225 u16 cfp_dur_rem;
226 } __packed;
228 struct element_tim {
229 u8 len;
230 u8 dtim_cnt;
231 u8 dtim_period;
232 u8 bmp_cntrl;
233 u8 part_virt_bmp[0];
234 } __packed;
236 struct element_ibss_ps {
237 u8 len;
238 u16 atim_win;
239 } __packed;
241 struct element_country_tripled {
242 u8 frst_ch;
243 u8 nr_ch;
244 u8 max_trans;
245 } __packed;
247 struct element_country {
248 u8 len;
249 #if defined(__LITTLE_ENDIAN_BITFIELD)
250 /* Correct order here ... */
251 u8 country_first;
252 u8 country_sec;
253 u8 country_third;
254 #elif defined(__BIG_ENDIAN_BITFIELD)
255 u8 country_third;
256 u8 country_sec;
257 u8 country_first;
258 #else
259 # error "Adjust your <asm/byteorder.h> defines"
260 #endif
261 /* triplet may repeat */
262 struct element_country_tripled tripled [0];
263 /* end triplet */
264 u8 pad[0];
265 } __packed;
267 struct element_hop_pp {
268 u8 len;
269 u8 prime_radix;
270 u8 nr_ch;
271 } __packed;
273 struct element_hop_pt {
274 u8 len;
275 u8 flag;
276 u8 nr_sets;
277 u8 modules;
278 u8 offs;
279 u8 rand_tabl[0];
280 } __packed;
282 struct element_req {
283 u8 len;
284 u8 req_elem_idl[0];
285 } __packed;
287 struct element_bss_load {
288 u8 len;
289 u16 station_cnt;
290 u8 ch_util;
291 u16 avlb_adm_cap;
292 } __packed;
294 struct element_edca_ps {
295 u8 len;
296 u8 qos_inf;
297 u8 res;
298 u32 ac_be;
299 u32 ac_bk;
300 u32 ac_vi;
301 u32 ac_vo;
302 } __packed;
304 struct element_tspec {
305 union {
306 u32 len_ts_info;
307 struct {
308 #if defined(__LITTLE_ENDIAN_BITFIELD)
309 /* Correct order here ... */
310 __extension__ u32 len:8,
311 traffic_type:1,
312 tsid:4,
313 direction:2,
314 access_policy:2,
315 aggr:1,
316 apsid:1,
317 user_prior:3,
318 tsinfo_ack_pol:2,
319 schedule:1,
320 res:7;
321 #elif defined(__BIG_ENDIAN_BITFIELD)
322 __extension__ u32 len:8,
323 res:7,
324 schedule:1,
325 tsinfo_ack_pol:2,
326 user_prior:3,
327 apsid:1,
328 aggr:1,
329 access_policy:2,
330 direction:2,
331 tsid:4,
332 traffic_type:1;
333 #else
334 # error "Adjust your <asm/byteorder.h> defines"
335 #endif
338 u16 nom_msdu_size;
339 u16 max_msdu_size;
340 u32 min_srv_intv;
341 u32 max_srv_intv;
342 u32 inactive_intv;
343 u32 susp_intv;
344 u32 srv_start_time;
345 u32 min_data_rate;
346 u32 mean_data_rate;
347 u32 peak_data_rate;
348 u32 burst_size;
349 u32 delay_bound;
350 u32 min_phy_rate;
351 u16 surplus_bandw_allow;
352 u16 med_time;
353 } __packed;
355 struct element_tclas {
356 u8 len;
357 u8 user_priority;
358 u8 frm_class[0];
359 } __packed;
361 struct element_tclas_frm_class {
362 u8 type;
363 u8 mask;
364 u8 param[0];
365 } __packed;
367 struct element_tclas_type0 {
368 u8 sa[6];
369 u8 da[6];
370 u16 type;
371 } __packed;
373 struct element_tclas_type1 {
374 u8 version;
375 u8 subparam[0];
376 } __packed;
378 struct element_tclas_type1_ip4 {
379 u32 sa;
380 u32 da;
381 u16 sp;
382 u16 dp;
383 u8 dscp;
384 u8 proto;
385 u8 reserved;
386 } __packed;
388 struct element_tclas_type1_ip6 {
389 struct in6_addr sa;
390 struct in6_addr da;
391 u16 sp;
392 u16 dp;
393 union {
394 u8 flow_label[3];
395 struct {
396 #if defined(__LITTLE_ENDIAN_BITFIELD)
397 __extension__ u8 flow_label3:8;
398 __extension__ u8 flow_label2:8;
399 __extension__ u8 flow_label1:8;
400 #elif defined(__BIG_ENDIAN_BITFIELD)
401 __extension__ u8 flow_label1:8;
402 __extension__ u8 flow_label2:8;
403 __extension__ u8 flow_label3:8;
405 # error "Adjust your <asm/byteorder.h> defines"
406 #endif
409 } __packed;
411 struct element_tclas_type2 {
412 u16 vlan_tci;
413 } __packed;
415 struct element_tclas_type3 {
416 u16 offs;
417 u8 value[0];
418 u8 mask[0];
419 } __packed;
421 struct element_tclas_type4 {
422 u8 version;
423 u8 subparam[0];
424 } __packed;
426 struct element_tclas_type4_ip4 {
427 u32 sa;
428 u32 da;
429 u16 sp;
430 u16 dp;
431 u8 dscp;
432 u8 proto;
433 u8 reserved;
434 } __packed;
436 struct element_tclas_type4_ip6 {
437 struct in6_addr sa;
438 struct in6_addr da;
439 u16 sp;
440 u16 dp;
441 u8 dscp;
442 u8 nxt_hdr;
443 union {
444 u8 flow_label[3];
445 struct {
446 #if defined(__LITTLE_ENDIAN_BITFIELD)
447 __extension__ u8 flow_label3:8;
448 __extension__ u8 flow_label2:8;
449 __extension__ u8 flow_label1:8;
450 #elif defined(__BIG_ENDIAN_BITFIELD)
451 __extension__ u8 flow_label1:8;
452 __extension__ u8 flow_label2:8;
453 __extension__ u8 flow_label3:8;
455 # error "Adjust your <asm/byteorder.h> defines"
456 #endif
459 } __packed;
461 struct element_tclas_type5 {
462 u8 pcp;
463 u8 cfi;
464 u8 vid;
465 } __packed;
467 struct element_schedule {
468 u8 len;
469 u16 inf;
470 u32 start;
471 u32 serv_intv;
472 u16 spec_intv;
473 } __packed;
475 struct element_chall_txt {
476 u8 len;
477 u8 chall_txt[0];
478 } __packed;
480 struct element_pwr_constr {
481 u8 len;
482 u8 local_pwr_constr;
483 } __packed;
485 struct element_pwr_cap {
486 u8 len;
487 u8 min_pwr_cap;
488 u8 max_pwr_cap;
489 } __packed;
491 struct element_tpc_req {
492 u8 len;
493 } __packed;
495 struct element_tpc_rep {
496 u8 len;
497 u8 trans_pwr;
498 u8 link_marg;
499 } __packed;
501 struct element_supp_ch {
502 u8 len;
503 u8 first_ch_nr[0];
504 u8 nr_ch[0];
505 } __packed;
507 struct element_supp_ch_tuple {
508 u8 first_ch_nr;
509 u8 nr_ch;
510 } __packed;
512 struct element_ch_sw_ann {
513 u8 len;
514 u8 switch_mode;
515 u8 new_nr;
516 u8 switch_cnt;
517 } __packed;
519 struct element_erp {
520 u8 len;
521 u8 param;
522 } __packed;
524 struct element_ext_supp_rates {
525 u8 len;
526 u8 rates[0];
527 } __packed;
529 struct element_vend_spec {
530 u8 len;
531 u8 oui[0];
532 u8 specific[0];
533 } __packed;
535 static int8_t len_neq_error(u8 len, u8 intended)
537 if(intended != len) {
538 tprintf("Length should be %u Bytes", intended);
539 return 1;
542 return 0;
545 static int8_t len_lt_error(u8 len, u8 intended)
547 if(len < intended) {
548 tprintf("Length should be greater %u Bytes", intended);
549 return 1;
552 return 0;
555 static float data_rates(u8 id)
557 /* XXX Why not (id / 2.f)? */
558 switch (id) {
559 case 2: return 1.0f;
560 case 3: return 1.5f;
561 case 4: return 2.0f;
562 case 5: return 2.5f;
563 case 6: return 3.0f;
564 case 9: return 4.5f;
565 case 11: return 5.5f;
566 case 12: return 6.0f;
567 case 18: return 9.0f;
568 case 22: return 11.0f;
569 case 24: return 12.0f;
570 case 27: return 13.5f;
571 case 36: return 18.0f;
572 case 44: return 22.0f;
573 case 48: return 24.0f;
574 case 54: return 27.0f;
575 case 66: return 33.0f;
576 case 72: return 36.0f;
577 case 96: return 48.0f;
578 case 108: return 54.0f;
581 return 0.f;
584 static int8_t inf_reserved(struct pkt_buff *pkt, u8 *id)
586 u8 i;
587 u8 *data;
588 struct element_reserved *reserved;
590 reserved = (struct element_reserved *) pkt_pull(pkt, sizeof(*reserved));
591 if (reserved == NULL)
592 return 0;
594 tprintf("Reserved (%u, Len (%u)): ", *id, reserved->len);
596 data = pkt_pull(pkt, reserved->len);
597 if (data == NULL)
598 return 0;
600 tprintf("Data 0x");
601 for (i = 0; i < reserved->len; i++)
602 tprintf("%.2x", data[i]);
604 return 1;
607 static int8_t inf_ssid(struct pkt_buff *pkt, u8 *id)
609 u8 i;
610 struct element_ssid *ssid;
611 char *ssid_name;
613 ssid = (struct element_ssid *) pkt_pull(pkt, sizeof(*ssid));
614 if (ssid == NULL)
615 return 0;
617 tprintf(" SSID (%u, Len (%u)): ", *id, ssid->len);
619 if ((ssid->len - sizeof(*ssid) + 1) > 0) {
620 ssid_name = (char *) pkt_pull(pkt, ssid->len);
621 if (ssid_name == NULL)
622 return 0;
624 for (i = 0; i < ssid->len; i++)
625 tprintf("%c",ssid_name[i]);
626 } else {
627 tprintf("Wildcard SSID");
630 return 1;
633 static int8_t inf_supp_rates(struct pkt_buff *pkt, u8 *id)
635 u8 i;
636 u8 *rates;
637 struct element_supp_rates *supp_rates;
639 supp_rates = (struct element_supp_rates *)
640 pkt_pull(pkt, sizeof(*supp_rates));
641 if (supp_rates == NULL)
642 return 0;
644 tprintf("Rates (%u, Len (%u)): ", *id, supp_rates->len);
645 if (len_lt_error(supp_rates->len, 1))
646 return 0;
648 if ((supp_rates->len - sizeof(*supp_rates) + 1) > 0) {
649 rates = pkt_pull(pkt, supp_rates->len);
650 if (rates == NULL)
651 return 0;
653 for (i = 0; i < supp_rates->len; i++)
654 tprintf("%g ", (rates[i] & 0x80) ?
655 ((rates[i] & 0x3f) * 0.5) :
656 data_rates(rates[i]));
657 return 1;
660 return 0;
663 static int8_t inf_fh_ps(struct pkt_buff *pkt, u8 *id)
665 struct element_fh_ps *fh_ps;
667 fh_ps = (struct element_fh_ps *) pkt_pull(pkt, sizeof(*fh_ps));
668 if (fh_ps == NULL)
669 return 0;
671 tprintf("FH Param Set (%u, Len(%u)): ", *id, fh_ps->len);
672 if (len_neq_error(fh_ps->len, 5))
673 return 0;
674 tprintf("Dwell Time: %fs, ", le16_to_cpu(fh_ps->dwell_time) * TU);
675 tprintf("HopSet: %u, ", fh_ps->hop_set);
676 tprintf("HopPattern: %u, ", fh_ps->hop_pattern);
677 tprintf("HopIndex: %u", fh_ps->hop_index);
679 return 1;
682 static int8_t inf_dsss_ps(struct pkt_buff *pkt, u8 *id)
684 struct element_dsss_ps *dsss_ps;
686 dsss_ps = (struct element_dsss_ps *) pkt_pull(pkt, sizeof(*dsss_ps));
687 if (dsss_ps == NULL)
688 return 0;
690 tprintf("DSSS Param Set (%u, Len(%u)): ", *id, dsss_ps->len);
691 if (len_neq_error(dsss_ps->len, 1))
692 return 0;
693 tprintf("Current Channel: %u", dsss_ps->curr_ch);
695 return 1;
698 static int8_t inf_cf_ps(struct pkt_buff *pkt, u8 *id)
700 struct element_cf_ps *cf_ps;
702 cf_ps = (struct element_cf_ps *) pkt_pull(pkt, sizeof(*cf_ps));
703 if (cf_ps == NULL)
704 return 0;
706 tprintf("CF Param Set (%u, Len(%u)): ", *id, cf_ps->len);
707 if (len_neq_error(cf_ps->len, 6))
708 return 0;
709 tprintf("CFP Count: %u, ", cf_ps->cfp_cnt);
710 tprintf("CFP Period: %u, ", cf_ps->cfp_period);
711 tprintf("CFP MaxDur: %fs, ", le16_to_cpu(cf_ps->cfp_max_dur) * TU);
712 tprintf("CFP DurRem: %fs", le16_to_cpu(cf_ps->cfp_dur_rem) * TU);
714 return 1;
717 static int8_t inf_tim(struct pkt_buff *pkt, u8 *id)
719 struct element_tim *tim;
721 tim = (struct element_tim *) pkt_pull(pkt, sizeof(*tim));
722 if (tim == NULL)
723 return 0;
725 tprintf("TIM (%u, Len(%u)): ", *id, tim->len);
726 if (len_lt_error(tim->len, 3))
727 return 0;
728 tprintf("DTIM Count: %u, ", tim->dtim_cnt);
729 tprintf("DTIM Period: %u, ", tim->dtim_period);
730 tprintf("Bitmap Control: %u, ", tim->bmp_cntrl);
731 if ((tim->len - sizeof(*tim) + 1) > 0) {
732 u8 *bmp = pkt_pull(pkt, (tim->len - sizeof(*tim) + 1));
733 if (bmp == NULL)
734 return 0;
736 tprintf("Partial Virtual Bitmap: 0x");
737 for(u8 i=0; i < (tim->len - sizeof(*tim) + 1); i++)
738 tprintf("%.2x ", bmp[i]);
741 return 1;
744 static int8_t inf_ibss_ps(struct pkt_buff *pkt, u8 *id)
746 struct element_ibss_ps *ibss_ps;
748 ibss_ps = (struct element_ibss_ps *) pkt_pull(pkt, sizeof(*ibss_ps));
749 if (ibss_ps == NULL)
750 return 0;
752 tprintf("IBSS Param Set (%u, Len(%u)): ", *id, ibss_ps->len);
753 if (len_neq_error(ibss_ps->len, 2))
754 return 0;
755 tprintf("ATIM Window: %fs", le16_to_cpu(ibss_ps->atim_win) * TU);
757 return 1;
760 static int8_t inf_country(struct pkt_buff *pkt, u8 *id)
762 u8 i;
763 u8 *pad;
764 struct element_country *country;
766 country = (struct element_country *) pkt_pull(pkt, sizeof(*country));
767 if (country == NULL)
768 return 0;
770 tprintf("Country (%u, Len(%u)): ", *id, country->len);
771 if (len_lt_error(country->len, 6))
772 return 0;
773 tprintf("Country String: %c%c%c", country->country_first,
774 country->country_sec, country->country_third);
776 for (i = 0; i < (country->len - 3); i += 3) {
777 struct element_country_tripled *country_tripled;
779 country_tripled = (struct element_country_tripled *)
780 pkt_pull(pkt, sizeof(*country_tripled));
781 if (country_tripled == NULL)
782 return 0;
784 if(country_tripled->frst_ch >= 201) {
785 tprintf("Oper Ext ID: %u, ", country_tripled->frst_ch);
786 tprintf("Operating Class: %u, ", country_tripled->nr_ch);
787 tprintf("Coverage Class: %u", country_tripled->max_trans);
788 } else {
789 tprintf("First Ch Nr: %u, ", country_tripled->frst_ch);
790 tprintf("Nr of Ch: %u, ", country_tripled->nr_ch);
791 tprintf("Max Transmit Pwr Lvl: %u", country_tripled->max_trans);
795 if(country->len % 2) {
796 pad = pkt_pull(pkt, 1);
797 if (pad == NULL)
798 return 0;
800 tprintf(", Pad: 0x%x", *pad);
803 return 1;
806 static int8_t inf_hop_pp(struct pkt_buff *pkt, u8 *id)
808 struct element_hop_pp *hop_pp;
810 hop_pp = (struct element_hop_pp *) pkt_pull(pkt, sizeof(*hop_pp));
811 if (hop_pp == NULL)
812 return 0;
814 tprintf("Hopping Pattern Param (%u, Len(%u)): ", *id, hop_pp->len);
815 if (len_neq_error(hop_pp->len, 2))
816 return 0;
817 tprintf("Nr of Ch: %u", hop_pp->nr_ch);
819 return 1;
822 static int8_t inf_hop_pt(struct pkt_buff *pkt, u8 *id)
824 int i;
825 u8 *rand_tabl;
826 struct element_hop_pt *hop_pt;
828 hop_pt = (struct element_hop_pt *) pkt_pull(pkt, sizeof(*hop_pt));
829 if (hop_pt == NULL)
830 return 0;
832 tprintf("Hopping Pattern Table (%u, Len(%u)): ", *id, hop_pt->len);
833 if (len_lt_error(hop_pt->len, 4))
834 return 0;
835 tprintf("Flag: %u, ", hop_pt->flag);
836 tprintf("Nr of Sets: %u, ", hop_pt->nr_sets);
837 tprintf("Modules: %u, ", hop_pt->modules);
838 tprintf("Offs: %u", hop_pt->offs);
840 if ((hop_pt->len - sizeof(*hop_pt) + 1) > 0) {
841 rand_tabl = pkt_pull(pkt, (hop_pt->len - sizeof(*hop_pt) + 1));
842 if (rand_tabl == NULL)
843 return 0;
845 tprintf(", Rand table: 0x");
846 for (i = 0; i < (hop_pt->len - sizeof(*hop_pt) + 1); i++)
847 tprintf("%.2x ", rand_tabl[i]);
850 return 1;
853 static int8_t inf_req(struct pkt_buff *pkt, u8 *id)
855 int i;
856 struct element_req *req;
857 u8 *req_ids;
859 req = (struct element_req *) pkt_pull(pkt, sizeof(*req));
860 if (req == NULL)
861 return 0;
863 tprintf("Request Element (%u, Len(%u)): ", *id, req->len);
864 if ((req->len - sizeof(*req) + 1) > 0) {
865 req_ids = pkt_pull(pkt, (req->len - sizeof(*req) + 1));
866 if (req_ids == NULL)
867 return 0;
869 tprintf(", Requested Element IDs: ");
870 for (i = 0; i < (req->len - sizeof(*req) + 1); i++)
871 tprintf("%u ", req_ids[i]);
874 return 1;
877 static int8_t inf_bss_load(struct pkt_buff *pkt, u8 *id)
879 struct element_bss_load *bss_load;
881 bss_load = (struct element_bss_load *) pkt_pull(pkt, sizeof(*bss_load));
882 if (bss_load == NULL)
883 return 0;
885 tprintf("BSS Load element (%u, Len(%u)): ", *id, bss_load->len);
886 if (len_neq_error(bss_load->len, 5))
887 return 0;
888 tprintf("Station Count: %u, ", le16_to_cpu(bss_load->station_cnt));
889 tprintf("Channel Utilization: %u, ", bss_load->ch_util);
890 tprintf("Available Admission Capacity: %uus",
891 bss_load->avlb_adm_cap * 32);
893 return 1;
896 static int8_t inf_edca_ps(struct pkt_buff *pkt, u8 *id)
898 u32 ac_be, ac_bk, ac_vi, ac_vo;
899 struct element_edca_ps *edca_ps;
901 edca_ps = (struct element_edca_ps *) pkt_pull(pkt, sizeof(*edca_ps));
902 if (edca_ps == NULL)
903 return 0;
905 ac_be = le32_to_cpu(edca_ps->ac_be);
906 ac_bk = le32_to_cpu(edca_ps->ac_bk);
907 ac_vi = le32_to_cpu(edca_ps->ac_vi);
908 ac_vo = le32_to_cpu(edca_ps->ac_vo);
910 tprintf("EDCA Param Set (%u, Len(%u)): ", *id, edca_ps->len);
911 if (len_neq_error(edca_ps->len, 18))
912 return 0;
913 tprintf("QoS Info: 0x%x (-> EDCA Param Set Update Count (%u),"
914 "Q-Ack (%u), Queue Re (%u), TXOP Req(%u), Res(%u)), ",
915 edca_ps->qos_inf, edca_ps->qos_inf >> 4,
916 (edca_ps->qos_inf >> 3) & 1, (edca_ps->qos_inf >> 2) & 1,
917 (edca_ps->qos_inf >> 1) & 1, edca_ps->qos_inf & 1);
918 tprintf("Reserved: 0x%x, ", edca_ps->res);
919 tprintf("AC_BE Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
920 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_be,
921 ac_be >> 28, (ac_be >> 27) & 1, (ac_be >> 25) & 3,
922 (ac_be >> 24) & 1, (ac_be >> 20) & 15, (ac_be >> 16) & 15,
923 bswap_16(ac_be & 0xFFFF) * 32);
924 tprintf("AC_BK Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
925 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_bk,
926 ac_bk >> 28, (ac_bk >> 27) & 1, (ac_bk >> 25) & 3,
927 (ac_bk >> 24) & 1, (ac_bk >> 20) & 15, (ac_bk >> 16) & 15,
928 bswap_16(ac_bk & 0xFFFF) * 32);
929 tprintf("AC_VI Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
930 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_vi,
931 ac_vi >> 28, (ac_vi >> 27) & 1, (ac_vi >> 25) & 3,
932 (ac_vi >> 24) & 1, (ac_vi >> 20) & 15, (ac_vi >> 16) & 15,
933 bswap_16(ac_vi & 0xFFFF) * 32);
934 tprintf("AC_VO Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
935 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)", ac_vo,
936 ac_vo >> 28, (ac_vo >> 27) & 1, (ac_vo >> 25) & 3,
937 (ac_vo >> 24) & 1, (ac_vo >> 20) & 15, (ac_vo >> 16) & 15,
938 bswap_16(ac_vo & 0xFFFF) * 32);
940 return 1;
943 static int8_t inf_tspec(struct pkt_buff *pkt, u8 *id)
945 u16 nom_msdu_size, surplus_bandw_allow;
946 struct element_tspec *tspec;
948 tspec = (struct element_tspec *) pkt_pull(pkt, sizeof(*tspec));
949 if (tspec == NULL)
950 return 0;
952 nom_msdu_size = le16_to_cpu(tspec->nom_msdu_size);
953 surplus_bandw_allow = le16_to_cpu(tspec->surplus_bandw_allow);
955 tprintf("TSPEC (%u, Len(%u)): ", *id, tspec->len);
956 if (len_neq_error(tspec->len, 55))
957 return 0;
958 tprintf("Traffic Type: %u, ", tspec->traffic_type);
959 tprintf("TSID: %u, ", tspec->tsid);
960 tprintf("Direction: %u, ", tspec->direction);
961 tprintf("Access Policy: %u, ", tspec->access_policy);
962 tprintf("Aggregation: %u, ", tspec->aggr);
963 tprintf("User Priority: %u, ", tspec->user_prior);
964 tprintf("TSinfo Ack Policy: %u, ", tspec->tsinfo_ack_pol);
965 tprintf("Schedule: %u, ", tspec->schedule);
966 tprintf("Reserved: 0x%x, ", tspec->res);
967 tprintf("Nominal MSDU Size: %uB (Fixed (%u)), ",
968 nom_msdu_size >> 1, nom_msdu_size & 1);
969 tprintf("Maximum MSDU Size: %uB, ", le16_to_cpu(tspec->max_msdu_size));
970 tprintf("Minimum Service Interval: %uus, ",
971 le32_to_cpu(tspec->min_srv_intv));
972 tprintf("Maximum Service Interval: %uus, ",
973 le32_to_cpu(tspec->max_srv_intv));
974 tprintf("Inactivity Interval: %uus, ",
975 le32_to_cpu(tspec->inactive_intv));
976 tprintf("Suspension Interval: %uus, ", le32_to_cpu(tspec->susp_intv));
977 tprintf("Service Start Time: %uus, ",
978 le32_to_cpu(tspec->srv_start_time));
979 tprintf("Minimum Data Rate: %ub/s, ",le32_to_cpu(tspec->min_data_rate));
980 tprintf("Mean Data Rate: %ub/s, ", le32_to_cpu(tspec->mean_data_rate));
981 tprintf("Peak Data Rate: %ub/s, ",le32_to_cpu(tspec->peak_data_rate));
982 tprintf("Burst Size: %uB, ", le32_to_cpu(tspec->burst_size));
983 tprintf("Delay Bound: %uus, ", le32_to_cpu(tspec->delay_bound));
984 tprintf("Minimum PHY Rate: %ub/s, ", le32_to_cpu(tspec->min_phy_rate));
985 tprintf("Surplus Bandwidth: %u.%u, ", surplus_bandw_allow >> 13,
986 surplus_bandw_allow & 0x1FFF);
987 tprintf("Medium Time: %uus", le16_to_cpu(tspec->med_time) * 32);
989 return 1;
992 static const char *class_type(u8 type)
994 switch (type) {
995 case 0: return "Ethernet parameters";
996 case 1: return "TCP/UDP IP parameters";
997 case 2: return "IEEE 802.1Q parameters";
998 case 3: return "Filter Offset parameters";
999 case 4: return "IP and higher layer parameters";
1000 case 5: return "IEEE 802.1D/Q parameters";
1001 default: return "Reserved";
1005 static int8_t inf_tclas(struct pkt_buff *pkt, u8 *id)
1007 struct element_tclas *tclas;
1008 struct element_tclas_frm_class *frm_class;
1010 tclas = (struct element_tclas *) pkt_pull(pkt, sizeof(*tclas));
1011 if (tclas == NULL)
1012 return 0;
1014 frm_class = (struct element_tclas_frm_class *)
1015 pkt_pull(pkt, sizeof(*frm_class));
1016 if (frm_class == NULL)
1017 return 0;
1019 tprintf("TCLAS (%u, Len(%u)): ", *id, tclas->len);
1020 if (len_lt_error(tclas->len, 3))
1021 return 0;
1022 tprintf("User Priority: %u, ", tclas->user_priority);
1023 tprintf("Classifier Type: %s (%u), ", class_type(frm_class->type),
1024 frm_class->type);
1025 tprintf("Classifier Mask: 0x%x, ", frm_class->mask);
1027 if(frm_class->type == 0) {
1028 struct element_tclas_type0 *type0;
1030 type0 = (struct element_tclas_type0 *)
1031 pkt_pull(pkt, sizeof(*type0));
1032 if (type0 == NULL)
1033 return 0;
1035 /* I think little endian, like the rest */
1036 tprintf("Src Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
1037 type0->sa[5], type0->sa[4], type0->sa[3],
1038 type0->sa[2], type0->sa[1], type0->sa[0]);
1039 tprintf("Dst Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
1040 type0->da[5], type0->da[4], type0->da[3],
1041 type0->da[2], type0->da[1], type0->da[0]);
1042 tprintf("Type: 0x%x", le16_to_cpu(type0->type));
1044 else if(frm_class->type == 1) {
1045 struct element_tclas_type1 *type1;
1047 type1 = (struct element_tclas_type1 *)
1048 pkt_pull(pkt, sizeof(*type1));
1049 if (type1 == NULL)
1050 return 0;
1052 tprintf("Version: %u, ", type1->version);
1053 /* big endian format follows */
1054 if(type1->version == 4) {
1055 struct element_tclas_type1_ip4 *type1_ip4;
1056 char src_ip[INET_ADDRSTRLEN];
1057 char dst_ip[INET_ADDRSTRLEN];
1059 type1_ip4 = (struct element_tclas_type1_ip4 *)
1060 pkt_pull(pkt, sizeof(*type1_ip4));
1061 if (type1_ip4 == NULL)
1062 return 0;
1064 inet_ntop(AF_INET, &type1_ip4->sa, src_ip, sizeof(src_ip));
1065 inet_ntop(AF_INET, &type1_ip4->da, dst_ip, sizeof(dst_ip));
1067 tprintf("Src IP: %s, ", src_ip);
1068 tprintf("Dst IP: %s, ", dst_ip);
1069 tprintf("Src Port: %u, ", ntohs(type1_ip4->sp));
1070 tprintf("Dst Port: %u, ", ntohs(type1_ip4->dp));
1071 tprintf("DSCP: 0x%x, ", type1_ip4->dscp);
1072 tprintf("Proto: %u, ", type1_ip4->proto);
1073 tprintf("Res: 0x%x", type1_ip4->reserved);
1075 else if(type1->version == 6) {
1076 struct element_tclas_type1_ip6 *type1_ip6;
1077 char src_ip[INET6_ADDRSTRLEN];
1078 char dst_ip[INET6_ADDRSTRLEN];
1080 type1_ip6 = (struct element_tclas_type1_ip6 *)
1081 pkt_pull(pkt, sizeof(*type1_ip6));
1082 if (type1_ip6 == NULL)
1083 return 0;
1085 inet_ntop(AF_INET6, &type1_ip6->sa,
1086 src_ip, sizeof(src_ip));
1087 inet_ntop(AF_INET6, &type1_ip6->da,
1088 dst_ip, sizeof(dst_ip));
1090 tprintf("Src IP: %s, ", src_ip);
1091 tprintf("Dst IP: %s, ", dst_ip);
1092 tprintf("Src Port: %u, ", ntohs(type1_ip6->sp));
1093 tprintf("Dst Port: %u, ", ntohs(type1_ip6->dp));
1094 tprintf("Flow Label: 0x%x%x%x", type1_ip6->flow_label1,
1095 type1_ip6->flow_label2, type1_ip6->flow_label3);
1097 else {
1098 tprintf("Version (%u) not supported", type1->version);
1099 return 0;
1103 else if(frm_class->type == 2) {
1104 struct element_tclas_type2 *type2;
1106 type2 = (struct element_tclas_type2 *)
1107 pkt_pull(pkt, sizeof(*type2));
1108 if (type2 == NULL)
1109 return 0;
1111 tprintf("802.1Q VLAN TCI: 0x%x", ntohs(type2->vlan_tci));
1113 else if(frm_class->type == 3) {
1114 struct element_tclas_type3 *type3;
1115 u8 len, i;
1116 u8 *val;
1118 type3 = (struct element_tclas_type3 *)
1119 pkt_pull(pkt, sizeof(*type3));
1120 if (type3 == NULL)
1121 return 0;
1123 len = (tclas->len - 5) / 2;
1125 tprintf("Filter Offset: %u, ", type3->offs);
1127 if((len & 1) || (len_lt_error(tclas->len, 5))) {
1128 tprintf("Length of TCLAS (%u) not correct", tclas->len);
1129 return 0;
1131 else {
1132 val = pkt_pull(pkt, len);
1133 if (val == NULL)
1134 return 0;
1136 tprintf("Filter Value: 0x");
1137 for (i = 0; i < len / 2; i++)
1138 tprintf("%x ", val[i]);
1139 tprintf(", ");
1140 tprintf("Filter Mask: 0x");
1141 for (i = len / 2; i < len; i++)
1142 tprintf("%x ", val[i]);
1146 else if(frm_class->type == 4) {
1147 struct element_tclas_type4 *type4;
1149 type4 = (struct element_tclas_type4 *)
1150 pkt_pull(pkt, sizeof(*type4));
1151 if (type4 == NULL)
1152 return 0;
1154 tprintf("Version: %u, ", type4->version);
1155 /* big endian format follows */
1156 if(type4->version == 4) {
1157 struct element_tclas_type4_ip4 *type4_ip4;
1158 char src_ip[INET_ADDRSTRLEN];
1159 char dst_ip[INET_ADDRSTRLEN];
1161 type4_ip4 = (struct element_tclas_type4_ip4 *)
1162 pkt_pull(pkt, sizeof(*type4_ip4));
1163 if (type4_ip4 == NULL)
1164 return 0;
1166 inet_ntop(AF_INET, &type4_ip4->sa, src_ip, sizeof(src_ip));
1167 inet_ntop(AF_INET, &type4_ip4->da, dst_ip, sizeof(dst_ip));
1169 tprintf("Src IP: %s, ", src_ip);
1170 tprintf("Dst IP: %s, ", dst_ip);
1171 tprintf("Src Port: %u, ", ntohs(type4_ip4->sp));
1172 tprintf("Dst Port: %u, ", ntohs(type4_ip4->dp));
1173 tprintf("DSCP: 0x%x, ", type4_ip4->dscp);
1174 tprintf("Proto: %u, ", type4_ip4->proto);
1175 tprintf("Res: 0x%x", type4_ip4->reserved);
1177 else if(type4->version == 6) {
1178 struct element_tclas_type4_ip6 *type4_ip6;
1179 char src_ip[INET6_ADDRSTRLEN];
1180 char dst_ip[INET6_ADDRSTRLEN];
1182 type4_ip6 = (struct element_tclas_type4_ip6 *)
1183 pkt_pull(pkt, sizeof(*type4_ip6));
1184 if (type4_ip6 == NULL)
1185 return 0;
1187 inet_ntop(AF_INET6, &type4_ip6->sa,
1188 src_ip, sizeof(src_ip));
1189 inet_ntop(AF_INET6, &type4_ip6->da,
1190 dst_ip, sizeof(dst_ip));
1192 tprintf("Src IP: %s, ", src_ip);
1193 tprintf("Dst IP: %s, ", dst_ip);
1194 tprintf("Src Port: %u, ", ntohs(type4_ip6->sp));
1195 tprintf("Dst Port: %u, ", ntohs(type4_ip6->dp));
1196 tprintf("DSCP: 0x%x, ", type4_ip6->dscp);
1197 tprintf("Nxt Hdr: %u, ", type4_ip6->nxt_hdr);
1198 tprintf("Flow Label: 0x%x%x%x", type4_ip6->flow_label1,
1199 type4_ip6->flow_label2, type4_ip6->flow_label3);
1201 else {
1202 tprintf("Version (%u) not supported", type4->version);
1203 return 0;
1206 else if(frm_class->type == 5) {
1207 struct element_tclas_type5 *type5;
1209 type5 = (struct element_tclas_type5 *)
1210 pkt_pull(pkt, sizeof(*type5));
1211 if (type5 == NULL)
1212 return 0;
1214 tprintf("802.1Q PCP: 0x%x, ", type5->pcp);
1215 tprintf("802.1Q CFI: 0x%x, ", type5->cfi);
1216 tprintf("802.1Q VID: 0x%x", type5->vid);
1218 else {
1219 tprintf("Classifier Type (%u) not supported", frm_class->type);
1220 return 0;
1223 return 1;
1226 static int8_t inf_sched(struct pkt_buff *pkt, u8 *id)
1228 struct element_schedule *schedule;
1229 u16 info;
1231 schedule = (struct element_schedule *) pkt_pull(pkt, sizeof(*schedule));
1232 if (schedule == NULL)
1233 return 0;
1235 info = le16_to_cpu(schedule->inf);
1237 tprintf("Schedule (%u, Len(%u)): ", *id, schedule->len);
1238 if (len_neq_error(schedule->len, 12))
1239 return 0;
1241 tprintf("Aggregation: %u, ", info >> 15);
1242 tprintf("TSID: %u, ", (info >> 11) & 0xF);
1243 tprintf("Direction: %u, ", (info >> 9) & 0x3);
1244 tprintf("Res: %u, ", info & 0x1FF);
1245 tprintf("Serv Start Time: %uus, ", le32_to_cpu(schedule->start));
1246 tprintf("Serv Interval: %uus, ", le32_to_cpu(schedule->serv_intv));
1247 tprintf("Spec Interval: %fs", le32_to_cpu(schedule->spec_intv) * TU);
1249 return 1;
1252 static int8_t inf_chall_txt(struct pkt_buff *pkt, u8 *id)
1254 struct element_chall_txt *chall_txt;
1255 u8 i;
1256 u8 *txt;
1258 chall_txt = (struct element_chall_txt *)
1259 pkt_pull(pkt, sizeof(*chall_txt));
1260 if (chall_txt == NULL)
1261 return 0;
1263 tprintf("Challenge Text (%u, Len(%u)): ", *id, chall_txt->len);
1264 if ((chall_txt->len - sizeof(*chall_txt) + 1) > 0) {
1265 txt = pkt_pull(pkt, (chall_txt->len - sizeof(*chall_txt) + 1));
1266 if (txt == NULL)
1267 return 0;
1269 tprintf("0x");
1270 for (i = 0; i < (chall_txt->len - sizeof(*chall_txt) + 1); i++)
1271 tprintf("%x ", txt[i]);
1274 return 1;
1277 static int8_t inf_pwr_constr(struct pkt_buff *pkt, u8 *id)
1279 struct element_pwr_constr *pwr_constr;
1281 pwr_constr = (struct element_pwr_constr *) pkt_pull(pkt, sizeof(*pwr_constr));
1282 if (pwr_constr == NULL)
1283 return 0;
1285 tprintf("Power Constraint (%u, Len(%u)): ", *id, pwr_constr->len);
1286 if (len_neq_error(pwr_constr->len, 1))
1287 return 0;
1289 tprintf("Local Power Constraint: %udB", pwr_constr->local_pwr_constr);
1291 return 1;
1294 static int8_t inf_pwr_cap(struct pkt_buff *pkt, u8 *id)
1296 struct element_pwr_cap *pwr_cap;
1298 pwr_cap = (struct element_pwr_cap *) pkt_pull(pkt, sizeof(*pwr_cap));
1299 if (pwr_cap == NULL)
1300 return 0;
1302 tprintf("Power Capability (%u, Len(%u)): ", *id, pwr_cap->len);
1303 if (len_neq_error(pwr_cap->len, 2))
1304 return 0;
1306 tprintf("Min. Transm. Pwr Cap.: %ddBm, ", (int8_t)pwr_cap->min_pwr_cap);
1307 tprintf("Max. Transm. Pwr Cap.: %ddBm", (int8_t)pwr_cap->max_pwr_cap);
1309 return 1;
1312 static int8_t inf_tpc_req(struct pkt_buff *pkt, u8 *id)
1314 struct element_tpc_req *tpc_req;
1316 tpc_req = (struct element_tpc_req *) pkt_pull(pkt, sizeof(*tpc_req));
1317 if (tpc_req == NULL)
1318 return 0;
1320 tprintf("TPC Request (%u, Len(%u))", *id, tpc_req->len);
1321 if (len_neq_error(tpc_req->len, 0))
1322 return 0;
1324 return 1;
1327 static int8_t inf_tpc_rep(struct pkt_buff *pkt, u8 *id)
1329 struct element_tpc_rep *tpc_rep;
1331 tpc_rep = (struct element_tpc_rep *) pkt_pull(pkt, sizeof(*tpc_rep));
1332 if (tpc_rep == NULL)
1333 return 0;
1335 tprintf("TPC Report (%u, Len(%u)): ", *id, tpc_rep->len);
1336 if (len_neq_error(tpc_rep->len, 2))
1337 return 0;
1339 tprintf("Transmit Power: %udBm, ", (int8_t)tpc_rep->trans_pwr);
1340 tprintf("Link Margin: %udB", (int8_t)tpc_rep->trans_pwr);
1342 return 1;
1345 static int8_t inf_supp_ch(struct pkt_buff *pkt, u8 *id)
1347 struct element_supp_ch *supp_ch;
1348 u8 i;
1350 supp_ch = (struct element_supp_ch *) pkt_pull(pkt, sizeof(*supp_ch));
1351 if (supp_ch == NULL)
1352 return 0;
1354 tprintf("Supp Channels (%u, Len(%u)): ", *id, supp_ch->len);
1355 if (len_lt_error(supp_ch->len, 2))
1356 return 0;
1358 if(supp_ch->len & 1) {
1359 tprintf("Length should be modulo 2");
1360 return 0;
1363 for (i = 0; i < supp_ch->len; i += 2) {
1364 struct element_supp_ch_tuple *supp_ch_tuple;
1366 supp_ch_tuple = (struct element_supp_ch_tuple *)
1367 pkt_pull(pkt, sizeof(*supp_ch_tuple));
1368 if (supp_ch_tuple == NULL)
1369 return 0;
1371 tprintf("First Channel Nr: %u, ", supp_ch_tuple->first_ch_nr);
1372 tprintf("Nr of Channels: %u, ", supp_ch_tuple->nr_ch);
1375 return 1;
1378 static int8_t inf_ch_sw_ann(struct pkt_buff *pkt, u8 *id)
1380 struct element_ch_sw_ann *ch_sw_ann;
1382 ch_sw_ann = (struct element_ch_sw_ann *)
1383 pkt_pull(pkt, sizeof(*ch_sw_ann));
1384 if (ch_sw_ann == NULL)
1385 return 0;
1387 tprintf("Channel Switch Announc (%u, Len(%u)): ", *id, ch_sw_ann->len);
1388 if (len_neq_error(ch_sw_ann->len, 3))
1389 return 0;
1391 tprintf("Switch Mode: %ud, ", ch_sw_ann->switch_mode);
1392 tprintf("New Nr: %u, ", ch_sw_ann->new_nr);
1393 tprintf("Switch Count: %u", ch_sw_ann->switch_cnt);
1395 return 1;
1398 static int8_t inf_meas_req(struct pkt_buff *pkt, u8 *id)
1400 return 0;
1403 static int8_t inf_meas_rep(struct pkt_buff *pkt, u8 *id)
1405 return 0;
1408 static int8_t inf_quiet(struct pkt_buff *pkt, u8 *id)
1410 return 0;
1413 static int8_t inf_ibss_dfs(struct pkt_buff *pkt, u8 *id)
1415 return 0;
1418 static int8_t inf_erp(struct pkt_buff *pkt, u8 *id)
1420 struct element_erp *erp;
1422 erp = (struct element_erp *) pkt_pull(pkt, sizeof(*erp));
1423 if (erp == NULL)
1424 return 0;
1426 tprintf("ERP (%u, Len(%u)): ", *id, erp->len);
1427 if (len_neq_error(erp->len, 1))
1428 return 0;
1429 tprintf("Non ERP Present (%u), ", erp->param & 0x1);
1430 tprintf("Use Protection (%u), ", (erp->param >> 1) & 0x1);
1431 tprintf("Barker Preamble Mode (%u), ", (erp->param >> 2) & 0x1);
1432 tprintf("Reserved (0x%.5x)", erp->param >> 3);
1434 return 1;
1437 static int8_t inf_ts_del(struct pkt_buff *pkt, u8 *id)
1439 return 0;
1442 static int8_t inf_tclas_proc(struct pkt_buff *pkt, u8 *id)
1444 return 0;
1447 static int8_t inf_ht_cap(struct pkt_buff *pkt, u8 *id)
1449 return 0;
1452 static int8_t inf_qos_cap(struct pkt_buff *pkt, u8 *id)
1454 return 0;
1457 static int8_t inf_rsn(struct pkt_buff *pkt, u8 *id)
1459 return 0;
1462 static int8_t inf_ext_supp_rates(struct pkt_buff *pkt, u8 *id)
1464 u8 i;
1465 u8 *rates;
1466 struct element_ext_supp_rates *ext_supp_rates;
1468 ext_supp_rates = (struct element_ext_supp_rates *)
1469 pkt_pull(pkt, sizeof(*ext_supp_rates));
1470 if (ext_supp_rates == NULL)
1471 return 0;
1473 tprintf("Ext Support Rates (%u, Len(%u)): ", *id, ext_supp_rates->len);
1475 if ((ext_supp_rates->len - sizeof(*ext_supp_rates) + 1) > 0) {
1476 rates = pkt_pull(pkt, ext_supp_rates->len);
1477 if (rates == NULL)
1478 return 0;
1480 for (i = 0; i < ext_supp_rates->len; i++)
1481 tprintf("%g ", (rates[i] & 0x80) ?
1482 ((rates[i] & 0x3f) * 0.5) :
1483 data_rates(rates[i]));
1484 return 1;
1487 return 0;
1490 static int8_t inf_ap_ch_exp(struct pkt_buff *pkt, u8 *id) {
1491 return 0;
1494 static int8_t inf_neighb_rep(struct pkt_buff *pkt, u8 *id) {
1495 return 0;
1498 static int8_t inf_rcpi(struct pkt_buff *pkt, u8 *id) {
1499 return 0;
1502 static int8_t inf_mde(struct pkt_buff *pkt, u8 *id) {
1503 return 0;
1506 static int8_t inf_fte(struct pkt_buff *pkt, u8 *id) {
1507 return 0;
1510 static int8_t inf_time_out_int(struct pkt_buff *pkt, u8 *id) {
1511 return 0;
1514 static int8_t inf_rde(struct pkt_buff *pkt, u8 *id) {
1515 return 0;
1518 static int8_t inf_dse_reg_loc(struct pkt_buff *pkt, u8 *id) {
1519 return 0;
1522 static int8_t inf_supp_op_class(struct pkt_buff *pkt, u8 *id) {
1523 return 0;
1526 static int8_t inf_ext_ch_sw_ann(struct pkt_buff *pkt, u8 *id) {
1527 return 0;
1530 static int8_t inf_ht_op(struct pkt_buff *pkt, u8 *id) {
1531 return 0;
1534 static int8_t inf_sec_ch_offs(struct pkt_buff *pkt, u8 *id) {
1535 return 0;
1538 static int8_t inf_bss_avg_acc_del(struct pkt_buff *pkt, u8 *id) {
1539 return 0;
1542 static int8_t inf_ant(struct pkt_buff *pkt, u8 *id) {
1543 return 0;
1546 static int8_t inf_rsni(struct pkt_buff *pkt, u8 *id) {
1547 return 0;
1550 static int8_t inf_meas_pilot_trans(struct pkt_buff *pkt, u8 *id) {
1551 return 0;
1554 static int8_t inf_bss_avl_adm_cap(struct pkt_buff *pkt, u8 *id) {
1555 return 0;
1558 static int8_t inf_bss_ac_acc_del(struct pkt_buff *pkt, u8 *id) {
1559 return 0;
1562 static int8_t inf_time_adv(struct pkt_buff *pkt, u8 *id) {
1563 return 0;
1566 static int8_t inf_rm_ena_cap(struct pkt_buff *pkt, u8 *id) {
1567 return 0;
1570 static int8_t inf_mult_bssid(struct pkt_buff *pkt, u8 *id) {
1571 return 0;
1574 static int8_t inf_20_40_bss_coex(struct pkt_buff *pkt, u8 *id) {
1575 return 0;
1578 static int8_t inf_20_40_bss_int_ch_rep(struct pkt_buff *pkt, u8 *id) {
1579 return 0;
1582 static int8_t inf_overl_bss_scan_para(struct pkt_buff *pkt, u8 *id) {
1583 return 0;
1586 static int8_t inf_ric_desc(struct pkt_buff *pkt, u8 *id) {
1587 return 0;
1590 static int8_t inf_mgmt_mic(struct pkt_buff *pkt, u8 *id) {
1591 return 0;
1594 static int8_t inf_ev_req(struct pkt_buff *pkt, u8 *id) {
1595 return 0;
1598 static int8_t inf_ev_rep(struct pkt_buff *pkt, u8 *id) {
1599 return 0;
1602 static int8_t inf_diagn_req(struct pkt_buff *pkt, u8 *id) {
1603 return 0;
1606 static int8_t inf_diagn_rep(struct pkt_buff *pkt, u8 *id) {
1607 return 0;
1610 static int8_t inf_loc_para(struct pkt_buff *pkt, u8 *id) {
1611 return 0;
1614 static int8_t inf_nontr_bssid_cap(struct pkt_buff *pkt, u8 *id) {
1615 return 0;
1618 static int8_t inf_ssid_list(struct pkt_buff *pkt, u8 *id) {
1619 return 0;
1622 static int8_t inf_mult_bssid_index(struct pkt_buff *pkt, u8 *id) {
1623 return 0;
1626 static int8_t inf_fms_desc(struct pkt_buff *pkt, u8 *id) {
1627 return 0;
1630 static int8_t inf_fms_req(struct pkt_buff *pkt, u8 *id) {
1631 return 0;
1634 static int8_t inf_fms_resp(struct pkt_buff *pkt, u8 *id) {
1635 return 0;
1638 static int8_t inf_qos_tfc_cap(struct pkt_buff *pkt, u8 *id) {
1639 return 0;
1642 static int8_t inf_bss_max_idle_per(struct pkt_buff *pkt, u8 *id) {
1643 return 0;
1646 static int8_t inf_tfs_req(struct pkt_buff *pkt, u8 *id) {
1647 return 0;
1650 static int8_t inf_tfs_resp(struct pkt_buff *pkt, u8 *id) {
1651 return 0;
1654 static int8_t inf_wnm_sleep_mod(struct pkt_buff *pkt, u8 *id) {
1655 return 0;
1658 static int8_t inf_tim_bcst_req(struct pkt_buff *pkt, u8 *id) {
1659 return 0;
1662 static int8_t inf_tim_bcst_resp(struct pkt_buff *pkt, u8 *id) {
1663 return 0;
1666 static int8_t inf_coll_interf_rep(struct pkt_buff *pkt, u8 *id) {
1667 return 0;
1670 static int8_t inf_ch_usage(struct pkt_buff *pkt, u8 *id) {
1671 return 0;
1674 static int8_t inf_time_zone(struct pkt_buff *pkt, u8 *id) {
1675 return 0;
1678 static int8_t inf_dms_req(struct pkt_buff *pkt, u8 *id) {
1679 return 0;
1682 static int8_t inf_dms_resp(struct pkt_buff *pkt, u8 *id) {
1683 return 0;
1686 static int8_t inf_link_id(struct pkt_buff *pkt, u8 *id) {
1687 return 0;
1690 static int8_t inf_wakeup_sched(struct pkt_buff *pkt, u8 *id) {
1691 return 0;
1694 static int8_t inf_ch_sw_timing(struct pkt_buff *pkt, u8 *id) {
1695 return 0;
1698 static int8_t inf_pti_ctrl(struct pkt_buff *pkt, u8 *id) {
1699 return 0;
1702 static int8_t inf_tpu_buff_status(struct pkt_buff *pkt, u8 *id) {
1703 return 0;
1706 static int8_t inf_interw(struct pkt_buff *pkt, u8 *id) {
1707 return 0;
1710 static int8_t inf_adv_proto(struct pkt_buff *pkt, u8 *id) {
1711 return 0;
1714 static int8_t inf_exp_bandw_req(struct pkt_buff *pkt, u8 *id) {
1715 return 0;
1718 static int8_t inf_qos_map_set(struct pkt_buff *pkt, u8 *id) {
1719 return 0;
1722 static int8_t inf_roam_cons(struct pkt_buff *pkt, u8 *id) {
1723 return 0;
1726 static int8_t inf_emer_alert_id(struct pkt_buff *pkt, u8 *id) {
1727 return 0;
1730 static int8_t inf_mesh_conf(struct pkt_buff *pkt, u8 *id) {
1731 return 0;
1734 static int8_t inf_mesh_id(struct pkt_buff *pkt, u8 *id) {
1735 return 0;
1738 static int8_t inf_mesh_link_metr_rep(struct pkt_buff *pkt, u8 *id) {
1739 return 0;
1742 static int8_t inf_cong_notif(struct pkt_buff *pkt, u8 *id) {
1743 return 0;
1746 static int8_t inf_mesh_peer_mgmt(struct pkt_buff *pkt, u8 *id) {
1747 return 0;
1750 static int8_t inf_mesh_ch_sw_para(struct pkt_buff *pkt, u8 *id) {
1751 return 0;
1754 static int8_t inf_mesh_awake_win(struct pkt_buff *pkt, u8 *id) {
1755 return 0;
1758 static int8_t inf_beacon_timing(struct pkt_buff *pkt, u8 *id) {
1759 return 0;
1762 static int8_t inf_mccaop_setup_req(struct pkt_buff *pkt, u8 *id) {
1763 return 0;
1766 static int8_t inf_mccaop_setup_rep(struct pkt_buff *pkt, u8 *id) {
1767 return 0;
1770 static int8_t inf_mccaop_adv(struct pkt_buff *pkt, u8 *id) {
1771 return 0;
1774 static int8_t inf_mccaop_teardwn(struct pkt_buff *pkt, u8 *id) {
1775 return 0;
1778 static int8_t inf_gann(struct pkt_buff *pkt, u8 *id) {
1779 return 0;
1782 static int8_t inf_rann(struct pkt_buff *pkt, u8 *id) {
1783 return 0;
1786 static int8_t inf_ext_cap(struct pkt_buff *pkt, u8 *id) {
1787 return 0;
1790 static int8_t inf_preq(struct pkt_buff *pkt, u8 *id) {
1791 return 0;
1794 static int8_t inf_prep(struct pkt_buff *pkt, u8 *id) {
1795 return 0;
1798 static int8_t inf_perr(struct pkt_buff *pkt, u8 *id) {
1799 return 0;
1802 static int8_t inf_pxu(struct pkt_buff *pkt, u8 *id) {
1803 return 0;
1806 static int8_t inf_pxuc(struct pkt_buff *pkt, u8 *id) {
1807 return 0;
1810 static int8_t inf_auth_mesh_peer_exch(struct pkt_buff *pkt, u8 *id) {
1811 return 0;
1814 static int8_t inf_mic(struct pkt_buff *pkt, u8 *id) {
1815 return 0;
1818 static int8_t inf_dest_uri(struct pkt_buff *pkt, u8 *id) {
1819 return 0;
1822 static int8_t inf_u_apsd_coex(struct pkt_buff *pkt, u8 *id) {
1823 return 0;
1826 static int8_t inf_mccaop_adv_overv(struct pkt_buff *pkt, u8 *id) {
1827 return 0;
1830 static int8_t inf_vend_spec(struct pkt_buff *pkt, u8 *id)
1832 u8 i;
1833 u8 *data;
1834 struct element_vend_spec *vend_spec;
1836 vend_spec = (struct element_vend_spec *)
1837 pkt_pull(pkt, sizeof(*vend_spec));
1838 if (vend_spec == NULL)
1839 return 0;
1841 tprintf("Vendor Specific (%u, Len (%u)): ", *id, vend_spec->len);
1843 data = pkt_pull(pkt, vend_spec->len);
1844 if (data == NULL)
1845 return 0;
1847 tprintf("Data 0x");
1848 for (i = 0; i < vend_spec->len; i++)
1849 tprintf("%.2x", data[i]);
1851 return 1;
1854 static int8_t inf_elements(struct pkt_buff *pkt)
1856 u8 *id = pkt_pull(pkt, 1);
1857 if (id == NULL)
1858 return 0;
1860 switch (*id) {
1861 case 0: return inf_ssid(pkt, id);
1862 case 1: return inf_supp_rates(pkt, id);
1863 case 2: return inf_fh_ps(pkt, id);
1864 case 3: return inf_dsss_ps(pkt, id);
1865 case 4: return inf_cf_ps(pkt, id);
1866 case 5: return inf_tim(pkt, id);
1867 case 6: return inf_ibss_ps(pkt, id);
1868 case 7: return inf_country(pkt, id);
1869 case 8: return inf_hop_pp(pkt, id);
1870 case 9: return inf_hop_pt(pkt, id);
1871 case 10: return inf_req(pkt, id);
1872 case 11: return inf_bss_load(pkt, id);
1873 case 12: return inf_edca_ps(pkt, id);
1874 case 13: return inf_tspec(pkt, id);
1875 case 14: return inf_tclas(pkt, id);
1876 case 15: return inf_sched(pkt, id);
1877 case 16: return inf_chall_txt(pkt, id);
1878 case 17 ... 31: return inf_reserved(pkt, id);
1879 case 32: return inf_pwr_constr(pkt, id);
1880 case 33: return inf_pwr_cap(pkt, id);
1881 case 34: return inf_tpc_req(pkt, id);
1882 case 35: return inf_tpc_rep(pkt, id);
1883 case 36: return inf_supp_ch(pkt, id);
1884 case 37: return inf_ch_sw_ann(pkt, id);
1885 case 38: return inf_meas_req(pkt, id);
1886 case 39: return inf_meas_rep(pkt, id);
1887 case 40: return inf_quiet(pkt, id);
1888 case 41: return inf_ibss_dfs(pkt, id);
1889 case 42: return inf_erp(pkt, id);
1890 case 43: return inf_ts_del(pkt, id);
1891 case 44: return inf_tclas_proc(pkt, id);
1892 case 45: return inf_ht_cap(pkt, id);
1893 case 46: return inf_qos_cap(pkt, id);
1894 case 47: return inf_reserved(pkt, id);
1895 case 48: return inf_rsn(pkt, id);
1896 case 49: return inf_rsn(pkt, id);
1897 case 50: return inf_ext_supp_rates(pkt, id);
1898 case 51: return inf_ap_ch_exp(pkt, id);
1899 case 52: return inf_neighb_rep(pkt, id);
1900 case 53: return inf_rcpi(pkt, id);
1901 case 54: return inf_mde(pkt, id);
1902 case 55: return inf_fte(pkt, id);
1903 case 56: return inf_time_out_int(pkt, id);
1904 case 57: return inf_rde(pkt, id);
1905 case 58: return inf_dse_reg_loc(pkt, id);
1906 case 59: return inf_supp_op_class(pkt, id);
1907 case 60: return inf_ext_ch_sw_ann(pkt, id);
1908 case 61: return inf_ht_op(pkt, id);
1909 case 62: return inf_sec_ch_offs(pkt, id);
1910 case 63: return inf_bss_avg_acc_del(pkt, id);
1911 case 64: return inf_ant(pkt, id);
1912 case 65: return inf_rsni(pkt, id);
1913 case 66: return inf_meas_pilot_trans(pkt, id);
1914 case 67: return inf_bss_avl_adm_cap(pkt, id);
1915 case 68: return inf_bss_ac_acc_del(pkt, id);
1916 case 69: return inf_time_adv(pkt, id);
1917 case 70: return inf_rm_ena_cap(pkt, id);
1918 case 71: return inf_mult_bssid(pkt, id);
1919 case 72: return inf_20_40_bss_coex(pkt, id);
1920 case 73: return inf_20_40_bss_int_ch_rep(pkt, id);
1921 case 74: return inf_overl_bss_scan_para(pkt, id);
1922 case 75: return inf_ric_desc(pkt, id);
1923 case 76: return inf_mgmt_mic(pkt, id);
1924 case 78: return inf_ev_req(pkt, id);
1925 case 79: return inf_ev_rep(pkt, id);
1926 case 80: return inf_diagn_req(pkt, id);
1927 case 81: return inf_diagn_rep(pkt, id);
1928 case 82: return inf_loc_para(pkt, id);
1929 case 83: return inf_nontr_bssid_cap(pkt, id);
1930 case 84: return inf_ssid_list(pkt, id);
1931 case 85: return inf_mult_bssid_index(pkt, id);
1932 case 86: return inf_fms_desc(pkt, id);
1933 case 87: return inf_fms_req(pkt, id);
1934 case 88: return inf_fms_resp(pkt, id);
1935 case 89: return inf_qos_tfc_cap(pkt, id);
1936 case 90: return inf_bss_max_idle_per(pkt, id);
1937 case 91: return inf_tfs_req(pkt, id);
1938 case 92: return inf_tfs_resp(pkt, id);
1939 case 93: return inf_wnm_sleep_mod(pkt, id);
1940 case 94: return inf_tim_bcst_req(pkt, id);
1941 case 95: return inf_tim_bcst_resp(pkt, id);
1942 case 96: return inf_coll_interf_rep(pkt, id);
1943 case 97: return inf_ch_usage(pkt, id);
1944 case 98: return inf_time_zone(pkt, id);
1945 case 99: return inf_dms_req(pkt, id);
1946 case 100: return inf_dms_resp(pkt, id);
1947 case 101: return inf_link_id(pkt, id);
1948 case 102: return inf_wakeup_sched(pkt, id);
1949 case 104: return inf_ch_sw_timing(pkt, id);
1950 case 105: return inf_pti_ctrl(pkt, id);
1951 case 106: return inf_tpu_buff_status(pkt, id);
1952 case 107: return inf_interw(pkt, id);
1953 case 108: return inf_adv_proto(pkt, id);
1954 case 109: return inf_exp_bandw_req(pkt, id);
1955 case 110: return inf_qos_map_set(pkt, id);
1956 case 111: return inf_roam_cons(pkt, id);
1957 case 112: return inf_emer_alert_id(pkt, id);
1958 case 113: return inf_mesh_conf(pkt, id);
1959 case 114: return inf_mesh_id(pkt, id);
1960 case 115: return inf_mesh_link_metr_rep(pkt, id);
1961 case 116: return inf_cong_notif(pkt, id);
1962 case 117: return inf_mesh_peer_mgmt(pkt, id);
1963 case 118: return inf_mesh_ch_sw_para(pkt, id);
1964 case 119: return inf_mesh_awake_win(pkt, id);
1965 case 120: return inf_beacon_timing(pkt, id);
1966 case 121: return inf_mccaop_setup_req(pkt, id);
1967 case 122: return inf_mccaop_setup_rep(pkt, id);
1968 case 123: return inf_mccaop_adv(pkt, id);
1969 case 124: return inf_mccaop_teardwn(pkt, id);
1970 case 125: return inf_gann(pkt, id);
1971 case 126: return inf_rann(pkt, id);
1972 case 127: return inf_ext_cap(pkt, id);
1973 case 128: return inf_reserved(pkt, id);
1974 case 129: return inf_reserved(pkt, id);
1975 case 130: return inf_preq(pkt, id);
1976 case 131: return inf_prep(pkt, id);
1977 case 132: return inf_perr(pkt, id);
1978 case 133: return inf_reserved(pkt, id);
1979 case 134: return inf_reserved(pkt, id);
1980 case 135: return inf_reserved(pkt, id);
1981 case 136: return inf_reserved(pkt, id);
1982 case 137: return inf_pxu(pkt, id);
1983 case 138: return inf_pxuc(pkt, id);
1984 case 139: return inf_auth_mesh_peer_exch(pkt, id);
1985 case 140: return inf_mic(pkt, id);
1986 case 141: return inf_dest_uri(pkt, id);
1987 case 142: return inf_u_apsd_coex(pkt, id);
1988 case 143 ... 173: return inf_reserved(pkt, id);
1989 case 174: return inf_mccaop_adv_overv(pkt, id);
1990 case 221: return inf_vend_spec(pkt, id);
1993 return 0;
1996 #define ESS 0b0000000000000001
1997 #define IBSS 0b0000000000000010
1998 #define CF_Pollable 0b0000000000000100
1999 #define CF_Poll_Req 0b0000000000001000
2000 #define Privacy 0b0000000000010000
2001 #define Short_Pre 0b0000000000100000
2002 #define PBCC 0b0000000001000000
2003 #define Ch_Agility 0b0000000010000000
2004 #define Spec_Mgmt 0b0000000100000000
2005 #define QoS 0b0000001000000000
2006 #define Short_Slot_t 0b0000010000000000
2007 #define APSD 0b0000100000000000
2008 #define Radio_Meas 0b0001000000000000
2009 #define DSSS_OFDM 0b0010000000000000
2010 #define Del_Block_ACK 0b0100000000000000
2011 #define Imm_Block_ACK 0b1000000000000000
2013 static int8_t cap_field(u16 cap_inf)
2015 if (ESS & cap_inf)
2016 tprintf(" ESS;");
2017 if (IBSS & cap_inf)
2018 tprintf(" IBSS;");
2019 if (CF_Pollable & cap_inf)
2020 tprintf(" CF Pollable;");
2021 if (CF_Poll_Req & cap_inf)
2022 tprintf(" CF-Poll Request;");
2023 if (Privacy & cap_inf)
2024 tprintf(" Privacy;");
2025 if (Short_Pre & cap_inf)
2026 tprintf(" Short Preamble;");
2027 if (PBCC & cap_inf)
2028 tprintf(" PBCC;");
2029 if (Ch_Agility & cap_inf)
2030 tprintf(" Channel Agility;");
2031 if (Spec_Mgmt & cap_inf)
2032 tprintf(" Spectrum Management;");
2033 if (QoS & cap_inf)
2034 tprintf(" QoS;");
2035 if (Short_Slot_t & cap_inf)
2036 tprintf(" Short Slot Time;");
2037 if (APSD & cap_inf)
2038 tprintf(" APSD;");
2039 if (Radio_Meas & cap_inf)
2040 tprintf(" Radio Measurement;");
2041 if (DSSS_OFDM & cap_inf)
2042 tprintf(" DSSS-OFDM;");
2043 if (Del_Block_ACK & cap_inf)
2044 tprintf(" Delayed Block Ack;");
2045 if (Imm_Block_ACK & cap_inf)
2046 tprintf(" Immediate Block Ack;");
2048 return 1;
2051 /* Management Dissectors */
2052 static int8_t assoc_req(struct pkt_buff *pkt) {
2053 return 0;
2056 static int8_t assoc_resp(struct pkt_buff *pkt) {
2057 return 0;
2060 static int8_t reassoc_req(struct pkt_buff *pkt) {
2061 return 0;
2064 static int8_t reassoc_resp(struct pkt_buff *pkt) {
2065 return 0;
2068 static int8_t probe_req(struct pkt_buff *pkt) {
2069 return 0;
2072 static int8_t probe_resp(struct pkt_buff *pkt) {
2073 return 0;
2076 static int8_t beacon(struct pkt_buff *pkt)
2078 struct ieee80211_mgmt_beacon *beacon;
2080 beacon = (struct ieee80211_mgmt_beacon *)
2081 pkt_pull(pkt, sizeof(*beacon));
2082 if (beacon == NULL)
2083 return 0;
2085 tprintf("Timestamp 0x%.16lx, ", le64_to_cpu(beacon->timestamp));
2086 tprintf("Beacon Interval (%fs), ", le16_to_cpu(beacon->beacon_int)*TU);
2087 tprintf("Capabilities (0x%x <->", le16_to_cpu(beacon->capab_info));
2088 cap_field(le16_to_cpu(beacon->capab_info));
2089 tprintf(")");
2091 if(pkt_len(pkt)) {
2092 tprintf("\n\tParameters:");
2093 while (inf_elements(pkt)) {
2094 tprintf("\n\t");
2098 if(pkt_len(pkt))
2099 return 0;
2100 return 1;
2103 static int8_t atim(struct pkt_buff *pkt) {
2104 return 0;
2107 static int8_t disassoc(struct pkt_buff *pkt) {
2108 return 0;
2111 static int8_t auth(struct pkt_buff *pkt) {
2112 return 0;
2115 static int8_t deauth(struct pkt_buff *pkt) {
2116 return 0;
2118 /* End Management Dissectors */
2120 /* Control Dissectors */
2121 static int8_t ps_poll(struct pkt_buff *pkt) {
2122 return 0;
2125 static int8_t rts(struct pkt_buff *pkt) {
2126 return 0;
2129 static int8_t cts(struct pkt_buff *pkt) {
2130 return 0;
2133 static int8_t ack(struct pkt_buff *pkt) {
2134 return 0;
2137 static int8_t cf_end(struct pkt_buff *pkt) {
2138 return 0;
2141 static int8_t cf_end_ack(struct pkt_buff *pkt) {
2142 return 0;
2144 /* End Control Dissectors */
2146 /* Data Dissectors */
2147 static int8_t data(struct pkt_buff *pkt) {
2148 return 0;
2151 static int8_t data_cf_ack(struct pkt_buff *pkt) {
2152 return 0;
2155 static int8_t data_cf_poll(struct pkt_buff *pkt) {
2156 return 0;
2159 static int8_t data_cf_ack_poll(struct pkt_buff *pkt) {
2160 return 0;
2163 static int8_t null(struct pkt_buff *pkt) {
2164 return 0;
2167 static int8_t cf_ack(struct pkt_buff *pkt) {
2168 return 0;
2171 static int8_t cf_poll(struct pkt_buff *pkt) {
2172 return 0;
2175 static int8_t cf_ack_poll(struct pkt_buff *pkt) {
2176 return 0;
2178 /* End Data Dissectors */
2180 static const char *mgt_sub(u8 subtype, struct pkt_buff *pkt,
2181 int8_t (**get_content)(struct pkt_buff *pkt))
2183 u16 seq_ctrl;
2184 struct ieee80211_mgmt *mgmt;
2185 const char *dst, *src, *bssid;
2187 mgmt = (struct ieee80211_mgmt *) pkt_pull(pkt, sizeof(*mgmt));
2188 if (mgmt == NULL)
2189 return 0;
2191 dst = lookup_vendor((mgmt->da[0] << 16) |
2192 (mgmt->da[1] << 8) |
2193 mgmt->da[2]);
2194 src = lookup_vendor((mgmt->sa[0] << 16) |
2195 (mgmt->sa[1] << 8) |
2196 mgmt->sa[2]);
2198 bssid = lookup_vendor((mgmt->bssid[0] << 16) |
2199 (mgmt->bssid[1] << 8) |
2200 mgmt->bssid[2]);
2201 seq_ctrl = le16_to_cpu(mgmt->seq_ctrl);
2203 tprintf("Duration (%u),", le16_to_cpu(mgmt->duration));
2204 tprintf("\n\tDestination (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
2205 mgmt->da[0], mgmt->da[1], mgmt->da[2],
2206 mgmt->da[3], mgmt->da[4], mgmt->da[5]);
2207 if (dst) {
2208 tprintf("=> (%s:%.2x:%.2x:%.2x)", dst,
2209 mgmt->da[3], mgmt->da[4], mgmt->da[5]);
2212 tprintf("\n\tSource (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
2213 mgmt->sa[0], mgmt->sa[1], mgmt->sa[2],
2214 mgmt->sa[3], mgmt->sa[4], mgmt->sa[5]);
2215 if (src) {
2216 tprintf("=> (%s:%.2x:%.2x:%.2x)", src,
2217 mgmt->sa[3], mgmt->sa[4], mgmt->sa[5]);
2220 tprintf("\n\tBSSID (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
2221 mgmt->bssid[0], mgmt->bssid[1], mgmt->bssid[2],
2222 mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5]);
2223 if(bssid) {
2224 tprintf("=> (%s:%.2x:%.2x:%.2x)", bssid,
2225 mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5]);
2228 tprintf("\n\tFragmentnr. (%u), Seqnr. (%u). ",
2229 seq_ctrl & 0xf, seq_ctrl >> 4);
2231 switch (subtype) {
2232 case 0b0000:
2233 *get_content = assoc_req;
2234 return "Association Request";
2235 case 0b0001:
2236 *get_content = assoc_resp;
2237 return "Association Response";
2238 case 0b0010:
2239 *get_content = reassoc_req;
2240 return "Reassociation Request";
2241 case 0b0011:
2242 *get_content = reassoc_resp;
2243 return "Reassociation Response";
2244 case 0b0100:
2245 *get_content = probe_req;
2246 return "Probe Request";
2247 case 0b0101:
2248 *get_content = probe_resp;
2249 return "Probe Response";
2250 case 0b1000:
2251 *get_content = beacon;
2252 return "Beacon";
2253 case 0b1001:
2254 *get_content = atim;
2255 return "ATIM";
2256 case 0b1010:
2257 *get_content = disassoc;
2258 return "Disassociation";
2259 case 0b1011:
2260 *get_content = auth;
2261 return "Authentication";
2262 case 0b1100:
2263 *get_content = deauth;
2264 return "Deauthentication";
2265 case 0b0110 ... 0b0111:
2266 case 0b1101 ... 0b1111:
2267 *get_content = NULL;
2268 return "Reserved";
2269 default:
2270 *get_content = NULL;
2271 return "Management SubType unknown";
2275 static const char *ctrl_sub(u8 subtype, struct pkt_buff *pkt,
2276 int8_t (**get_content)(struct pkt_buff *pkt))
2278 switch (subtype) {
2279 case 0b1010:
2280 *get_content = ps_poll;
2281 return "PS-Poll";
2282 case 0b1011:
2283 *get_content = rts;
2284 return "RTS";
2285 case 0b1100:
2286 *get_content = cts;
2287 return "CTS";
2288 case 0b1101:
2289 *get_content = ack;
2290 return "ACK";
2291 case 0b1110:
2292 *get_content = cf_end;
2293 return "CF End";
2294 case 0b1111:
2295 *get_content = cf_end_ack;
2296 return "CF End + CF-ACK";
2297 case 0b0000 ... 0b1001:
2298 *get_content = NULL;
2299 return "Reserved";
2300 default:
2301 return "Control SubType unkown";
2305 static const char *data_sub(u8 subtype, struct pkt_buff *pkt,
2306 int8_t (**get_content)(struct pkt_buff *pkt))
2308 switch (subtype) {
2309 case 0b0000:
2310 *get_content = data;
2311 return "Data";
2312 case 0b0001:
2313 *get_content = data_cf_ack;
2314 return "Data + CF-ACK";
2315 case 0b0010:
2316 *get_content = data_cf_poll;
2317 return "Data + CF-Poll";
2318 case 0b0011:
2319 *get_content = data_cf_ack_poll;
2320 return "Data + CF-ACK + CF-Poll";
2321 case 0b0100:
2322 *get_content = null;
2323 return "Null";
2324 case 0b0101:
2325 *get_content = cf_ack;
2326 return "CF-ACK";
2327 case 0b0110:
2328 *get_content = cf_poll;
2329 return "CF-Poll";
2330 case 0b0111:
2331 *get_content = cf_ack_poll;
2332 return "CF-ACK + CF-Poll";
2333 case 0b1000 ... 0b1111:
2334 *get_content = NULL;
2335 return "Reserved";
2336 default:
2337 *get_content = NULL;
2338 return "Data SubType unkown";
2342 static const char *
2343 frame_control_type(u8 type, const char *(**get_subtype)(u8 subtype,
2344 struct pkt_buff *pkt, int8_t (**get_content)(struct pkt_buff *pkt)))
2346 switch (type) {
2347 case 0b00:
2348 *get_subtype = mgt_sub;
2349 return "Management";
2350 case 0b01:
2351 *get_subtype = ctrl_sub;
2352 return "Control";
2353 case 0b10:
2354 *get_subtype = data_sub;
2355 return "Data";
2356 case 0b11:
2357 *get_subtype = NULL;
2358 return "Reserved";
2359 default:
2360 *get_subtype = NULL;
2361 return "Control Type unkown";
2365 static void ieee80211(struct pkt_buff *pkt)
2367 int8_t (*get_content)(struct pkt_buff *pkt) = NULL;
2368 const char *(*get_subtype)(u8 subtype, struct pkt_buff *pkt,
2369 int8_t (**get_content)(struct pkt_buff *pkt)) = NULL;
2370 const char *subtype = NULL;
2371 struct ieee80211_frm_ctrl *frm_ctrl;
2373 frm_ctrl = (struct ieee80211_frm_ctrl *)
2374 pkt_pull(pkt, sizeof(*frm_ctrl));
2375 if (frm_ctrl == NULL)
2376 return;
2378 tprintf(" [ 802.11 Frame Control (0x%04x)]\n",
2379 le16_to_cpu(frm_ctrl->frame_control));
2381 tprintf(" [ Proto Version (%u), ", frm_ctrl->proto_version);
2382 tprintf("Type (%u, %s), ", frm_ctrl->type,
2383 frame_control_type(frm_ctrl->type, &get_subtype));
2384 if (get_subtype) {
2385 subtype = (*get_subtype)(frm_ctrl->subtype, pkt, &get_content);
2386 tprintf("Subtype (%u, %s)", frm_ctrl->subtype, subtype);
2387 } else {
2388 tprintf("%s%s%s", colorize_start_full(black, red),
2389 "No SubType Data available", colorize_end());
2392 tprintf("%s%s", frm_ctrl->to_ds ? ", Frame goes to DS" : "",
2393 frm_ctrl->from_ds ? ", Frame comes from DS" : "");
2394 tprintf("%s", frm_ctrl->more_frags ? ", More Fragments" : "");
2395 tprintf("%s", frm_ctrl->retry ? ", Frame is retransmitted" : "");
2396 tprintf("%s", frm_ctrl->power_mgmt ? ", In Power Saving Mode" : "");
2397 tprintf("%s", frm_ctrl->more_data ? ", More Data" : "");
2398 tprintf("%s", frm_ctrl->wep ? ", Needs WEP" : "");
2399 tprintf("%s", frm_ctrl->order ? ", Order" : "");
2400 tprintf(" ]\n");
2402 if (get_content) {
2403 tprintf(" [ Subtype %s: ", subtype);
2404 if (!((*get_content) (pkt)))
2405 tprintf("%s%s%s", colorize_start_full(black, red),
2406 "Failed to dissect Subtype", colorize_end());
2407 tprintf(" ]");
2408 } else {
2409 tprintf("%s%s%s", colorize_start_full(black, red),
2410 "No SubType Data available", colorize_end());
2413 tprintf("\n");
2415 // pkt_set_proto(pkt, &ieee802_lay2, ntohs(eth->h_proto));
2418 static void ieee80211_less(struct pkt_buff *pkt)
2420 tprintf("802.11 frame (more on todo)");
2423 struct protocol ieee80211_ops = {
2424 .key = 0,
2425 .print_full = ieee80211,
2426 .print_less = ieee80211_less,
2429 EXPORT_SYMBOL(ieee80211_ops);