dissectors: 80211_mac_hdr: Check return value of pkt_pull
[netsniff-ng.git] / proto_80211_mac_hdr.c
blob199c4e79a7d69d62c70892547dcb59da2385d41d
1 /*
2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2012, 2013 Markus Amend <markus@netsniff-ng.org>
4 * Copyright 2012 Daniel Borkmann <daniel@netsniff-ng.org>
5 * Subject to the GPL, version 2.
6 */
8 /* TODO
9 * check all possible frame combinations for their behavior
10 * with respect to endianess (little / big)
13 #include <inttypes.h>
14 #include <stdio.h>
15 #include <stdint.h>
16 #include <netinet/in.h> /* for ntohs() */
17 #include <asm/byteorder.h>
18 #include <arpa/inet.h> /* for inet_ntop() */
20 #include "proto.h"
21 #include "dissector_80211.h"
22 #include "built_in.h"
23 #include "pkt_buff.h"
24 #include "oui.h"
25 #include "linktype.h"
27 #define TU 0.001024
29 /* Note: Fields are encoded in little-endian! */
30 struct ieee80211_frm_ctrl {
31 union {
32 u16 frame_control;
33 struct {
34 #if defined(__LITTLE_ENDIAN_BITFIELD)
35 /* Correct order here ... */
36 __extension__ u16 proto_version:2,
37 type:2,
38 subtype:4,
39 to_ds:1,
40 from_ds:1,
41 more_frags:1,
42 retry:1,
43 power_mgmt:1,
44 more_data:1,
45 wep:1,
46 order:1;
47 #elif defined(__BIG_ENDIAN_BITFIELD)
48 __extension__ u16 subtype:4,
49 type:2,
50 proto_version:2,
51 order:1,
52 wep:1,
53 more_data:1,
54 power_mgmt:1,
55 retry:1,
56 more_frags:1,
57 from_ds:1,
58 to_ds:1;
59 #else
60 # error "Adjust your <asm/byteorder.h> defines"
61 #endif
64 } __packed;
66 /* Management Frame start */
67 /* Note: Fields are encoded in little-endian! */
68 struct ieee80211_mgmt {
69 u16 duration;
70 u8 da[6];
71 u8 sa[6];
72 u8 bssid[6];
73 u16 seq_ctrl;
74 } __packed;
76 struct ieee80211_mgmt_auth {
77 u16 auth_alg;
78 u16 auth_transaction;
79 u16 status_code;
80 /* possibly followed by Challenge text */
81 u8 variable[0];
82 } __packed;
84 struct ieee80211_mgmt_deauth {
85 u16 reason_code;
86 } __packed;
88 struct ieee80211_mgmt_assoc_req {
89 u16 capab_info;
90 u16 listen_interval;
91 /* followed by SSID and Supported rates */
92 u8 variable[0];
93 } __packed;
95 struct ieee80211_mgmt_assoc_resp {
96 u16 capab_info;
97 u16 status_code;
98 u16 aid;
99 /* followed by Supported rates */
100 u8 variable[0];
101 } __packed;
103 struct ieee80211_mgmt_reassoc_resp {
104 u16 capab_info;
105 u16 status_code;
106 u16 aid;
107 /* followed by Supported rates */
108 u8 variable[0];
109 } __packed;
111 struct ieee80211_mgmt_reassoc_req {
112 u16 capab_info;
113 u16 listen_interval;
114 u8 current_ap[6];
115 /* followed by SSID and Supported rates */
116 u8 variable[0];
117 } __packed;
119 struct ieee80211_mgmt_disassoc {
120 u16 reason_code;
121 } __packed;
123 struct ieee80211_mgmt_probe_req {
124 } __packed;
126 struct ieee80211_mgmt_beacon {
127 u64 timestamp;
128 u16 beacon_int;
129 u16 capab_info;
130 /* followed by some of SSID, Supported rates,
131 * FH Params, DS Params, CF Params, IBSS Params, TIM */
132 u8 variable[0];
133 } __packed;
135 struct ieee80211_mgmt_probe_resp {
136 u8 timestamp[8];
137 u16 beacon_int;
138 u16 capab_info;
139 /* followed by some of SSID, Supported rates,
140 * FH Params, DS Params, CF Params, IBSS Params, TIM */
141 u8 variable[0];
142 } __packed;
143 /* Management Frame end */
145 /* Control Frame start */
146 /* Note: Fields are encoded in little-endian! */
147 struct ieee80211_ctrl {
148 } __packed;
150 struct ieee80211_ctrl_rts {
151 u16 duration;
152 u8 da[6];
153 u8 sa[6];
154 } __packed;
156 struct ieee80211_ctrl_cts {
157 u16 duration;
158 u8 da[6];
159 } __packed;
161 struct ieee80211_ctrl_ack {
162 u16 duration;
163 u8 da[6];
164 } __packed;
166 struct ieee80211_ctrl_ps_poll {
167 u16 aid;
168 u8 bssid[6];
169 u8 sa[6];
170 } __packed;
172 struct ieee80211_ctrl_cf_end {
173 u16 duration;
174 u8 bssid[6];
175 u8 sa[6];
176 } __packed;
178 struct ieee80211_ctrl_cf_end_ack {
179 u16 duration;
180 u8 bssid[6];
181 u8 sa[6];
182 } __packed;
183 /* Control Frame end */
185 /* Data Frame start */
186 /* Note: Fields are encoded in little-endian! */
187 struct ieee80211_data {
188 } __packed;
190 /* TODO: Extend */
191 /* Data Frame end */
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 rates[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 apsd: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 apsd: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;
404 #else
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;
454 #else
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_meas_basic {
520 u8 ch_nr;
521 u64 start;
522 u16 dur;
523 } __packed;
525 struct element_meas_cca {
526 u8 ch_nr;
527 u64 start;
528 u16 dur;
529 } __packed;
531 struct element_meas_rpi {
532 u8 ch_nr;
533 u64 start;
534 u16 dur;
535 } __packed;
537 struct element_meas_ch_load {
538 u8 op_class;
539 u8 ch_nr;
540 u16 rand_intv;
541 u16 dur;
542 u8 sub[0];
543 } __packed;
545 struct element_meas_noise {
546 u8 op_class;
547 u8 ch_nr;
548 u16 rand_intv;
549 u16 dur;
550 u8 sub[0];
551 } __packed;
553 struct element_meas_beacon {
554 u8 op_class;
555 u8 ch_nr;
556 u16 rand_intv;
557 u16 dur;
558 u8 mode;
559 u8 bssid[6];
560 u8 sub[0];
561 } __packed;
563 struct element_meas_frame {
564 u8 op_class;
565 u8 ch_nr;
566 u16 rand_intv;
567 u16 dur;
568 u8 frame;
569 u8 mac[6];
570 u8 sub[0];
571 } __packed;
573 struct element_meas_sta {
574 u8 peer_mac[6];
575 u16 rand_intv;
576 u16 dur;
577 u8 group_id;
578 u8 sub[0];
579 } __packed;
581 struct element_meas_lci {
582 u8 loc_subj;
583 u8 latitude_req_res;
584 u8 longitude_req_res;
585 u8 altitude_req_res;
586 u8 sub[0];
587 } __packed;
589 struct element_meas_trans_str_cat {
590 u16 rand_intv;
591 u16 dur;
592 u8 peer_sta_addr[6];
593 u8 traffic_id;
594 u8 bin_0_range;
595 u8 sub[0];
596 } __packed;
598 struct element_meas_mcast_diag {
599 u16 rand_intv;
600 u16 dur;
601 u8 group_mac[6];
602 u8 mcast_triggered[0];
603 u8 sub[0];
604 } __packed;
606 struct element_meas_loc_civic {
607 u8 loc_subj;
608 u8 civic_loc;
609 u8 loc_srv_intv_unit;
610 u16 loc_srv_intv;
611 u8 sub[0];
612 } __packed;
614 struct element_meas_loc_id {
615 u8 loc_subj;
616 u8 loc_srv_intv_unit;
617 u16 loc_srv_intv;
618 u8 sub[0];
619 } __packed;
621 struct element_meas_pause {
622 u8 time;
623 u8 sub[0];
624 } __packed;
626 struct element_meas_req {
627 u8 len;
628 u8 token;
629 u8 req_mode;
630 u8 type;
631 u8 req[0];
632 } __packed;
634 struct element_meas_rep {
635 u8 len;
636 u8 token;
637 u8 rep_mode;
638 u8 type;
639 u8 rep[0];
640 } __packed;
642 struct element_quiet {
643 u8 len;
644 u8 cnt;
645 u8 period;
646 u16 dur;
647 u16 offs;
648 } __packed;
650 struct element_ibss_dfs {
651 u8 len;
652 u8 owner[6];
653 u8 rec_intv;
654 u8 ch_map[0];
655 } __packed;
657 struct element_ibss_dfs_tuple {
658 u8 ch_nr;
659 u8 map;
660 } __packed;
662 struct element_erp {
663 u8 len;
664 u8 param;
665 } __packed;
667 struct element_ts_del {
668 u8 len;
669 u32 delay;
670 } __packed;
672 struct element_tclas_proc {
673 u8 len;
674 u8 proc;
675 } __packed;
677 struct element_ht_cap {
678 u8 len;
679 union {
680 u16 info;
681 struct {
682 #if defined(__LITTLE_ENDIAN_BITFIELD)
683 /* Correct order here ... */
684 __extension__ u16 ldpc:1,
685 supp_width:1,
686 sm_pwr:2,
687 ht_green:1,
688 gi_20mhz:1,
689 gi_40mhz:1,
690 tx_stbc:1,
691 rx_stbc:2,
692 ht_ack:1,
693 max_msdu_length:1,
694 dsss_ck_mode:1,
695 res:1,
696 forty_int:1,
697 prot_supp:1;
698 #elif defined(__BIG_ENDIAN_BITFIELD)
699 __extension__ u16 rx_stbc:2,
700 ht_ack:1,
701 max_msdu_length:1,
702 dsss_ck_mode:1,
703 res:1,
704 forty_int:1,
705 prot_supp:1,
706 ldpc:1,
707 supp_width:1,
708 sm_pwr:2,
709 ht_green:1,
710 gi_20mhz:1,
711 gi_40mhz:1,
712 tx_stbc:1;
713 #else
714 # error "Adjust your <asm/byteorder.h> defines"
715 #endif
718 u8 param;
719 union {
720 u8 mcs_set[16];
721 struct {
722 #if defined(__LITTLE_ENDIAN_BITFIELD)
723 /* Correct order here ... */
724 __extension__ u8 bitmask1:8;
725 __extension__ u8 bitmask2:8;
726 __extension__ u8 bitmask3:8;
727 __extension__ u8 bitmask4:8;
728 __extension__ u8 bitmask5:8;
729 __extension__ u8 bitmask6:8;
730 __extension__ u8 bitmask7:8;
731 __extension__ u8 bitmask8:8;
732 __extension__ u8 bitmask9:8;
733 __extension__ u8 bitmask10_res:8;
734 __extension__ u16 supp_rate_res:16;
735 __extension__ u32 tx_param_res:32;
737 #elif defined(__BIG_ENDIAN_BITFIELD)
738 __extension__ u32 tx_param_res:32;
739 __extension__ u16 supp_rate_res:16;
740 __extension__ u8 bitmask10_res:8;
741 __extension__ u8 bitmask9:8;
742 __extension__ u8 bitmask8:8;
743 __extension__ u8 bitmask7:8;
744 __extension__ u8 bitmask6:8;
745 __extension__ u8 bitmask5:8;
746 __extension__ u8 bitmask4:8;
747 __extension__ u8 bitmask3:8;
748 __extension__ u8 bitmask2:8;
749 __extension__ u8 bitmask1:8;
750 #else
751 # error "Adjust your <asm/byteorder.h> defines"
752 #endif
755 u16 ext_cap;
756 u32 beam_cap;
757 u8 asel_cap;
758 } __packed;
760 struct element_qos_cap {
761 u8 len;
762 u8 info;
763 } __packed;
765 struct element_ext_supp_rates {
766 u8 len;
767 u8 rates[0];
768 } __packed;
770 struct element_vend_spec {
771 u8 len;
772 u8 oui[0];
773 u8 specific[0];
774 } __packed;
776 struct ieee80211_radiotap_header {
777 u8 version; /* set to 0 */
778 u8 pad;
779 u16 len; /* entire length */
780 u32 present; /* fields present */
781 } __packed;
783 static int8_t len_neq_error(u8 len, u8 intended)
785 if(intended != len) {
786 tprintf("Length should be %u Bytes", intended);
787 return 1;
790 return 0;
793 static int8_t len_lt_error(u8 len, u8 intended)
795 if(len < intended) {
796 tprintf("Length should be greater %u Bytes", intended);
797 return 1;
800 return 0;
803 static float data_rates(u8 id)
805 /* XXX Why not (id / 2.f)? */
806 switch (id) {
807 case 2: return 1.0f;
808 case 3: return 1.5f;
809 case 4: return 2.0f;
810 case 5: return 2.5f;
811 case 6: return 3.0f;
812 case 9: return 4.5f;
813 case 11: return 5.5f;
814 case 12: return 6.0f;
815 case 18: return 9.0f;
816 case 22: return 11.0f;
817 case 24: return 12.0f;
818 case 27: return 13.5f;
819 case 36: return 18.0f;
820 case 44: return 22.0f;
821 case 48: return 24.0f;
822 case 54: return 27.0f;
823 case 66: return 33.0f;
824 case 72: return 36.0f;
825 case 96: return 48.0f;
826 case 108: return 54.0f;
829 return 0.f;
832 struct subelement {
833 u8 id;
834 u8 len;
835 u8 data[0];
836 } __packed;
839 static int8_t subelements(struct pkt_buff *pkt, u8 len)
841 u8 i, j;
842 u8 *data;
844 for (i=0; i<len;) {
845 struct subelement *sub;
847 sub = (struct subelement *) pkt_pull(pkt, sizeof(*sub));
848 if (sub == NULL)
849 return 0;
851 tprintf(", Subelement ID %u, ", sub->id);
852 tprintf("Length %u, ", sub->len);
854 data = pkt_pull(pkt, sub->len);
855 if (data == NULL)
856 return 0;
858 tprintf("Data: 0x");
859 for(j=0; j < sub->len; j++)
860 tprintf("%.2x ", data[j]);
862 i += sub->len + 1;
865 /* Not needed ?! Should break before*/
867 *if (i != len) {
868 * tprintf("Length error");
869 * return 0;
873 return 1;
876 static int8_t inf_reserved(struct pkt_buff *pkt, u8 *id)
878 u8 i;
879 u8 *data;
880 struct element_reserved *reserved;
882 reserved = (struct element_reserved *) pkt_pull(pkt, sizeof(*reserved));
883 if (reserved == NULL)
884 return 0;
886 tprintf("Reserved (%u, Len (%u)): ", *id, reserved->len);
888 data = pkt_pull(pkt, reserved->len);
889 if (data == NULL)
890 return 0;
892 tprintf("Data 0x");
893 for (i = 0; i < reserved->len; i++)
894 tprintf("%.2x", data[i]);
896 return 1;
899 static int8_t inf_ssid(struct pkt_buff *pkt, u8 *id)
901 u8 i;
902 struct element_ssid *ssid;
903 char *ssid_name;
905 ssid = (struct element_ssid *) pkt_pull(pkt, sizeof(*ssid));
906 if (ssid == NULL)
907 return 0;
909 tprintf(" SSID (%u, Len (%u)): ", *id, ssid->len);
911 if ((ssid->len - sizeof(*ssid) + 1) > 0) {
912 ssid_name = (char *) pkt_pull(pkt, ssid->len);
913 if (ssid_name == NULL)
914 return 0;
916 for (i = 0; i < ssid->len; i++)
917 tprintf("%c",ssid_name[i]);
918 } else {
919 tprintf("Wildcard SSID");
922 return 1;
925 static int8_t inf_supp_rates(struct pkt_buff *pkt, u8 *id)
927 u8 i;
928 u8 *rates;
929 struct element_supp_rates *supp_rates;
931 supp_rates = (struct element_supp_rates *)
932 pkt_pull(pkt, sizeof(*supp_rates));
933 if (supp_rates == NULL)
934 return 0;
936 tprintf(" Supp. Rates (%u, Len (%u)): ", *id, supp_rates->len);
937 if (len_lt_error(supp_rates->len, 1))
938 return 0;
940 if ((supp_rates->len - sizeof(*supp_rates) + 1) > 0) {
941 rates = pkt_pull(pkt, supp_rates->len);
942 if (rates == NULL)
943 return 0;
945 for (i = 0; i < supp_rates->len; i++)
946 tprintf("%g%s ", ((rates[i] & 0x80) >> 7) ?
947 data_rates(rates[i] & 0x3f) :
948 ((rates[i] & 0x3f) * 0.5),
949 ((rates[i] & 0x80) >> 7) ? "(B)" : "");
950 return 1;
953 return 0;
956 static int8_t inf_fh_ps(struct pkt_buff *pkt, u8 *id)
958 struct element_fh_ps *fh_ps;
960 fh_ps = (struct element_fh_ps *) pkt_pull(pkt, sizeof(*fh_ps));
961 if (fh_ps == NULL)
962 return 0;
964 tprintf(" FH Param Set (%u, Len(%u)): ", *id, fh_ps->len);
965 if (len_neq_error(fh_ps->len, 5))
966 return 0;
967 tprintf("Dwell Time: %fs, ", le16_to_cpu(fh_ps->dwell_time) * TU);
968 tprintf("HopSet: %u, ", fh_ps->hop_set);
969 tprintf("HopPattern: %u, ", fh_ps->hop_pattern);
970 tprintf("HopIndex: %u", fh_ps->hop_index);
972 return 1;
975 static int8_t inf_dsss_ps(struct pkt_buff *pkt, u8 *id)
977 struct element_dsss_ps *dsss_ps;
979 dsss_ps = (struct element_dsss_ps *) pkt_pull(pkt, sizeof(*dsss_ps));
980 if (dsss_ps == NULL)
981 return 0;
983 tprintf(" DSSS Param Set (%u, Len(%u)): ", *id, dsss_ps->len);
984 if (len_neq_error(dsss_ps->len, 1))
985 return 0;
986 tprintf("Current Channel: %u", dsss_ps->curr_ch);
988 return 1;
991 static int8_t inf_cf_ps(struct pkt_buff *pkt, u8 *id)
993 struct element_cf_ps *cf_ps;
995 cf_ps = (struct element_cf_ps *) pkt_pull(pkt, sizeof(*cf_ps));
996 if (cf_ps == NULL)
997 return 0;
999 tprintf(" CF Param Set (%u, Len(%u)): ", *id, cf_ps->len);
1000 if (len_neq_error(cf_ps->len, 6))
1001 return 0;
1002 tprintf("CFP Count: %u, ", cf_ps->cfp_cnt);
1003 tprintf("CFP Period: %u, ", cf_ps->cfp_period);
1004 tprintf("CFP MaxDur: %fs, ", le16_to_cpu(cf_ps->cfp_max_dur) * TU);
1005 tprintf("CFP DurRem: %fs", le16_to_cpu(cf_ps->cfp_dur_rem) * TU);
1007 return 1;
1010 static int8_t inf_tim(struct pkt_buff *pkt, u8 *id)
1012 struct element_tim *tim;
1013 u8 i;
1015 tim = (struct element_tim *) pkt_pull(pkt, sizeof(*tim));
1016 if (tim == NULL)
1017 return 0;
1019 tprintf(" TIM (%u, Len(%u)): ", *id, tim->len);
1020 if (len_lt_error(tim->len, 3))
1021 return 0;
1022 tprintf("DTIM Count: %u, ", tim->dtim_cnt);
1023 tprintf("DTIM Period: %u, ", tim->dtim_period);
1024 tprintf("Bitmap Control: %u, ", tim->bmp_cntrl);
1025 if ((tim->len - sizeof(*tim) + 1) > 0) {
1026 u8 *bmp = pkt_pull(pkt, (tim->len - sizeof(*tim) + 1));
1027 if (bmp == NULL)
1028 return 0;
1030 tprintf("Partial Virtual Bitmap: 0x");
1031 for (i = 0; i < (tim->len - sizeof(*tim) + 1); i++)
1032 tprintf("%.2x", bmp[i]);
1035 return 1;
1038 static int8_t inf_ibss_ps(struct pkt_buff *pkt, u8 *id)
1040 struct element_ibss_ps *ibss_ps;
1042 ibss_ps = (struct element_ibss_ps *) pkt_pull(pkt, sizeof(*ibss_ps));
1043 if (ibss_ps == NULL)
1044 return 0;
1046 tprintf(" IBSS Param Set (%u, Len(%u)): ", *id, ibss_ps->len);
1047 if (len_neq_error(ibss_ps->len, 2))
1048 return 0;
1049 tprintf("ATIM Window: %fs", le16_to_cpu(ibss_ps->atim_win) * TU);
1051 return 1;
1054 static int8_t inf_country(struct pkt_buff *pkt, u8 *id)
1056 u8 i;
1057 u8 *pad;
1058 struct element_country *country;
1060 country = (struct element_country *) pkt_pull(pkt, sizeof(*country));
1061 if (country == NULL)
1062 return 0;
1064 tprintf(" Country (%u, Len(%u)): ", *id, country->len);
1065 if (len_lt_error(country->len, 6))
1066 return 0;
1067 tprintf("Country String: %c%c%c", country->country_first,
1068 country->country_sec, country->country_third);
1070 for (i = country->len % 3; i < (country->len - 3); i += 3) {
1071 struct element_country_tripled *country_tripled;
1073 country_tripled = (struct element_country_tripled *)
1074 pkt_pull(pkt, sizeof(*country_tripled));
1075 if (country_tripled == NULL)
1076 return 0;
1078 if(country_tripled->frst_ch >= 201) {
1079 tprintf("Oper Ext ID: %u, ", country_tripled->frst_ch);
1080 tprintf("Operating Class: %u, ", country_tripled->nr_ch);
1081 tprintf("Coverage Class: %u", country_tripled->max_trans);
1082 } else {
1083 tprintf("First Ch Nr: %u, ", country_tripled->frst_ch);
1084 tprintf("Nr of Ch: %u, ", country_tripled->nr_ch);
1085 tprintf("Max Transmit Pwr Lvl: %u", country_tripled->max_trans);
1089 if(country->len % 3) {
1090 pad = pkt_pull(pkt, 1);
1091 if (pad == NULL)
1092 return 0;
1094 tprintf(", Pad: 0x%x", *pad);
1097 return 1;
1100 static int8_t inf_hop_pp(struct pkt_buff *pkt, u8 *id)
1102 struct element_hop_pp *hop_pp;
1104 hop_pp = (struct element_hop_pp *) pkt_pull(pkt, sizeof(*hop_pp));
1105 if (hop_pp == NULL)
1106 return 0;
1108 tprintf(" Hopping Pattern Param (%u, Len(%u)): ", *id, hop_pp->len);
1109 if (len_neq_error(hop_pp->len, 2))
1110 return 0;
1111 tprintf("Prime Radix: %u, ", hop_pp->prime_radix);
1112 tprintf("Nr of Ch: %u", hop_pp->nr_ch);
1114 return 1;
1117 static int8_t inf_hop_pt(struct pkt_buff *pkt, u8 *id)
1119 size_t i;
1120 u8 *rand_tabl;
1121 struct element_hop_pt *hop_pt;
1123 hop_pt = (struct element_hop_pt *) pkt_pull(pkt, sizeof(*hop_pt));
1124 if (hop_pt == NULL)
1125 return 0;
1127 tprintf(" Hopping Pattern Table (%u, Len(%u)): ", *id, hop_pt->len);
1128 if (len_lt_error(hop_pt->len, 4))
1129 return 0;
1130 tprintf("Flag: %u, ", hop_pt->flag);
1131 tprintf("Nr of Sets: %u, ", hop_pt->nr_sets);
1132 tprintf("Modulus: %u, ", hop_pt->modules);
1133 tprintf("Offs: %u", hop_pt->offs);
1135 if ((hop_pt->len - sizeof(*hop_pt) + 1) > 0) {
1136 rand_tabl = pkt_pull(pkt, (hop_pt->len - sizeof(*hop_pt) + 1));
1137 if (rand_tabl == NULL)
1138 return 0;
1140 tprintf(", Rand table: 0x");
1141 for (i = 0; i < (hop_pt->len - sizeof(*hop_pt) + 1); i++)
1142 tprintf("%.2x", rand_tabl[i]);
1145 return 1;
1148 static int8_t inf_req(struct pkt_buff *pkt, u8 *id)
1150 size_t i;
1151 struct element_req *req;
1152 u8 *req_ids;
1154 req = (struct element_req *) pkt_pull(pkt, sizeof(*req));
1155 if (req == NULL)
1156 return 0;
1158 tprintf(" Request Element (%u, Len(%u)): ", *id, req->len);
1159 if ((req->len - sizeof(*req) + 1) > 0) {
1160 req_ids = pkt_pull(pkt, (req->len - sizeof(*req) + 1));
1161 if (req_ids == NULL)
1162 return 0;
1164 tprintf(", Requested Element IDs: ");
1165 for (i = 0; i < (req->len - sizeof(*req) + 1); i++)
1166 tprintf("%u ", req_ids[i]);
1169 return 1;
1172 static int8_t inf_bss_load(struct pkt_buff *pkt, u8 *id)
1174 struct element_bss_load *bss_load;
1176 bss_load = (struct element_bss_load *) pkt_pull(pkt, sizeof(*bss_load));
1177 if (bss_load == NULL)
1178 return 0;
1180 tprintf(" BSS Load element (%u, Len(%u)): ", *id, bss_load->len);
1181 if (len_neq_error(bss_load->len, 5))
1182 return 0;
1183 tprintf("Station Count: %u, ", le16_to_cpu(bss_load->station_cnt));
1184 tprintf("Channel Utilization: %u, ", bss_load->ch_util);
1185 tprintf("Available Admission Capacity: %uus",
1186 bss_load->avlb_adm_cap * 32);
1188 return 1;
1191 static int8_t inf_edca_ps(struct pkt_buff *pkt, u8 *id)
1193 u32 ac_be, ac_bk, ac_vi, ac_vo;
1194 struct element_edca_ps *edca_ps;
1196 edca_ps = (struct element_edca_ps *) pkt_pull(pkt, sizeof(*edca_ps));
1197 if (edca_ps == NULL)
1198 return 0;
1200 ac_be = le32_to_cpu(edca_ps->ac_be);
1201 ac_bk = le32_to_cpu(edca_ps->ac_bk);
1202 ac_vi = le32_to_cpu(edca_ps->ac_vi);
1203 ac_vo = le32_to_cpu(edca_ps->ac_vo);
1205 tprintf(" EDCA Param Set (%u, Len(%u)): ", *id, edca_ps->len);
1206 if (len_neq_error(edca_ps->len, 18))
1207 return 0;
1208 tprintf("QoS Info: 0x%x (-> EDCA Param Set Update Count (%u),"
1209 "Q-Ack (%u), Queue Re (%u), TXOP Req(%u), Res(%u)), ",
1210 edca_ps->qos_inf, edca_ps->qos_inf >> 4,
1211 (edca_ps->qos_inf >> 3) & 1, (edca_ps->qos_inf >> 2) & 1,
1212 (edca_ps->qos_inf >> 1) & 1, edca_ps->qos_inf & 1);
1213 tprintf("Reserved: 0x%x, ", edca_ps->res);
1214 tprintf("AC_BE Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
1215 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_be,
1216 ac_be >> 28, (ac_be >> 27) & 1, (ac_be >> 25) & 3,
1217 (ac_be >> 24) & 1, (ac_be >> 20) & 15, (ac_be >> 16) & 15,
1218 bswap_16(ac_be & 0xFFFF) * 32);
1219 tprintf("AC_BK Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
1220 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_bk,
1221 ac_bk >> 28, (ac_bk >> 27) & 1, (ac_bk >> 25) & 3,
1222 (ac_bk >> 24) & 1, (ac_bk >> 20) & 15, (ac_bk >> 16) & 15,
1223 bswap_16(ac_bk & 0xFFFF) * 32);
1224 tprintf("AC_VI Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
1225 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)), ", ac_vi,
1226 ac_vi >> 28, (ac_vi >> 27) & 1, (ac_vi >> 25) & 3,
1227 (ac_vi >> 24) & 1, (ac_vi >> 20) & 15, (ac_vi >> 16) & 15,
1228 bswap_16(ac_vi & 0xFFFF) * 32);
1229 tprintf("AC_VO Param Rec: 0x%x (-> AIFSN (%u), ACM (%u), ACI (%u),"
1230 "Res (%u), ECWmin (%u), ECWmax(%u)), TXOP Limit (%uus)", ac_vo,
1231 ac_vo >> 28, (ac_vo >> 27) & 1, (ac_vo >> 25) & 3,
1232 (ac_vo >> 24) & 1, (ac_vo >> 20) & 15, (ac_vo >> 16) & 15,
1233 bswap_16(ac_vo & 0xFFFF) * 32);
1235 return 1;
1238 static int8_t inf_tspec(struct pkt_buff *pkt, u8 *id)
1240 u16 nom_msdu_size, surplus_bandw_allow;
1241 struct element_tspec *tspec;
1243 tspec = (struct element_tspec *) pkt_pull(pkt, sizeof(*tspec));
1244 if (tspec == NULL)
1245 return 0;
1247 nom_msdu_size = le16_to_cpu(tspec->nom_msdu_size);
1248 surplus_bandw_allow = le16_to_cpu(tspec->surplus_bandw_allow);
1250 tprintf(" TSPEC (%u, Len(%u)): ", *id, tspec->len);
1251 if (len_neq_error(tspec->len, 55))
1252 return 0;
1253 tprintf("Traffic Type: %u, ", tspec->traffic_type);
1254 tprintf("TSID: %u, ", tspec->tsid);
1255 tprintf("Direction: %u, ", tspec->direction);
1256 tprintf("Access Policy: %u, ", tspec->access_policy);
1257 tprintf("Aggregation: %u, ", tspec->aggr);
1258 tprintf("APSD: %u, ", tspec->apsd);
1259 tprintf("User Priority: %u, ", tspec->user_prior);
1260 tprintf("TSinfo Ack Policy: %u, ", tspec->tsinfo_ack_pol);
1261 tprintf("Schedule: %u, ", tspec->schedule);
1262 tprintf("Reserved: 0x%x, ", tspec->res);
1263 tprintf("Nominal MSDU Size: %uB (Fixed (%u)), ",
1264 nom_msdu_size >> 1, nom_msdu_size & 1);
1265 tprintf("Maximum MSDU Size: %uB, ", le16_to_cpu(tspec->max_msdu_size));
1266 tprintf("Minimum Service Interval: %uus, ",
1267 le32_to_cpu(tspec->min_srv_intv));
1268 tprintf("Maximum Service Interval: %uus, ",
1269 le32_to_cpu(tspec->max_srv_intv));
1270 tprintf("Inactivity Interval: %uus, ",
1271 le32_to_cpu(tspec->inactive_intv));
1272 tprintf("Suspension Interval: %uus, ", le32_to_cpu(tspec->susp_intv));
1273 tprintf("Service Start Time: %uus, ",
1274 le32_to_cpu(tspec->srv_start_time));
1275 tprintf("Minimum Data Rate: %ub/s, ",le32_to_cpu(tspec->min_data_rate));
1276 tprintf("Mean Data Rate: %ub/s, ", le32_to_cpu(tspec->mean_data_rate));
1277 tprintf("Peak Data Rate: %ub/s, ",le32_to_cpu(tspec->peak_data_rate));
1278 tprintf("Burst Size: %uB, ", le32_to_cpu(tspec->burst_size));
1279 tprintf("Delay Bound: %uus, ", le32_to_cpu(tspec->delay_bound));
1280 tprintf("Minimum PHY Rate: %ub/s, ", le32_to_cpu(tspec->min_phy_rate));
1281 tprintf("Surplus Bandwidth: %u.%u, ", surplus_bandw_allow >> 13,
1282 surplus_bandw_allow & 0x1FFF);
1283 tprintf("Medium Time: %uus", le16_to_cpu(tspec->med_time) * 32);
1285 return 1;
1288 static const char *class_type(u8 type)
1290 switch (type) {
1291 case 0: return "Ethernet parameters";
1292 case 1: return "TCP/UDP IP parameters";
1293 case 2: return "IEEE 802.1Q parameters";
1294 case 3: return "Filter Offset parameters";
1295 case 4: return "IP and higher layer parameters";
1296 case 5: return "IEEE 802.1D/Q parameters";
1297 default: return "Reserved";
1301 static int8_t inf_tclas(struct pkt_buff *pkt, u8 *id)
1303 struct element_tclas *tclas;
1304 struct element_tclas_frm_class *frm_class;
1306 tclas = (struct element_tclas *) pkt_pull(pkt, sizeof(*tclas));
1307 if (tclas == NULL)
1308 return 0;
1310 frm_class = (struct element_tclas_frm_class *)
1311 pkt_pull(pkt, sizeof(*frm_class));
1312 if (frm_class == NULL)
1313 return 0;
1315 tprintf(" TCLAS (%u, Len(%u)): ", *id, tclas->len);
1316 if (len_lt_error(tclas->len, 3))
1317 return 0;
1318 tprintf("User Priority: %u, ", tclas->user_priority);
1319 tprintf("Classifier Type: %s (%u), ", class_type(frm_class->type),
1320 frm_class->type);
1321 tprintf("Classifier Mask: 0x%x, ", frm_class->mask);
1323 if(frm_class->type == 0) {
1324 struct element_tclas_type0 *type0;
1326 type0 = (struct element_tclas_type0 *)
1327 pkt_pull(pkt, sizeof(*type0));
1328 if (type0 == NULL)
1329 return 0;
1331 /* I think little endian, like the rest */
1332 tprintf("Src Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
1333 type0->sa[5], type0->sa[4], type0->sa[3],
1334 type0->sa[2], type0->sa[1], type0->sa[0]);
1335 tprintf("Dst Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
1336 type0->da[5], type0->da[4], type0->da[3],
1337 type0->da[2], type0->da[1], type0->da[0]);
1338 tprintf("Type: 0x%x", le16_to_cpu(type0->type));
1340 else if(frm_class->type == 1) {
1341 struct element_tclas_type1 *type1;
1343 type1 = (struct element_tclas_type1 *)
1344 pkt_pull(pkt, sizeof(*type1));
1345 if (type1 == NULL)
1346 return 0;
1348 tprintf("Version: %u, ", type1->version);
1349 /* big endian format follows */
1350 if(type1->version == 4) {
1351 struct element_tclas_type1_ip4 *type1_ip4;
1352 char src_ip[INET_ADDRSTRLEN];
1353 char dst_ip[INET_ADDRSTRLEN];
1355 type1_ip4 = (struct element_tclas_type1_ip4 *)
1356 pkt_pull(pkt, sizeof(*type1_ip4));
1357 if (type1_ip4 == NULL)
1358 return 0;
1360 inet_ntop(AF_INET, &type1_ip4->sa, src_ip, sizeof(src_ip));
1361 inet_ntop(AF_INET, &type1_ip4->da, dst_ip, sizeof(dst_ip));
1363 tprintf("Src IP: %s, ", src_ip);
1364 tprintf("Dst IP: %s, ", dst_ip);
1365 tprintf("Src Port: %u, ", ntohs(type1_ip4->sp));
1366 tprintf("Dst Port: %u, ", ntohs(type1_ip4->dp));
1367 tprintf("DSCP: 0x%x, ", type1_ip4->dscp);
1368 tprintf("Proto: %u, ", type1_ip4->proto);
1369 tprintf("Res: 0x%x", type1_ip4->reserved);
1371 else if(type1->version == 6) {
1372 struct element_tclas_type1_ip6 *type1_ip6;
1373 char src_ip[INET6_ADDRSTRLEN];
1374 char dst_ip[INET6_ADDRSTRLEN];
1376 type1_ip6 = (struct element_tclas_type1_ip6 *)
1377 pkt_pull(pkt, sizeof(*type1_ip6));
1378 if (type1_ip6 == NULL)
1379 return 0;
1381 inet_ntop(AF_INET6, &type1_ip6->sa,
1382 src_ip, sizeof(src_ip));
1383 inet_ntop(AF_INET6, &type1_ip6->da,
1384 dst_ip, sizeof(dst_ip));
1386 tprintf("Src IP: %s, ", src_ip);
1387 tprintf("Dst IP: %s, ", dst_ip);
1388 tprintf("Src Port: %u, ", ntohs(type1_ip6->sp));
1389 tprintf("Dst Port: %u, ", ntohs(type1_ip6->dp));
1390 tprintf("Flow Label: 0x%x%x%x", type1_ip6->flow_label1,
1391 type1_ip6->flow_label2, type1_ip6->flow_label3);
1393 else {
1394 tprintf("Version (%u) not supported", type1->version);
1395 return 0;
1399 else if(frm_class->type == 2) {
1400 struct element_tclas_type2 *type2;
1402 type2 = (struct element_tclas_type2 *)
1403 pkt_pull(pkt, sizeof(*type2));
1404 if (type2 == NULL)
1405 return 0;
1407 tprintf("802.1Q VLAN TCI: 0x%x", ntohs(type2->vlan_tci));
1409 else if(frm_class->type == 3) {
1410 struct element_tclas_type3 *type3;
1411 u8 len, i;
1412 u8 *val;
1414 type3 = (struct element_tclas_type3 *)
1415 pkt_pull(pkt, sizeof(*type3));
1416 if (type3 == NULL)
1417 return 0;
1419 len = (tclas->len - 5) / 2;
1421 tprintf("Filter Offset: %u, ", type3->offs);
1423 if((len & 1) || (len_lt_error(tclas->len, 5))) {
1424 tprintf("Length of TCLAS (%u) not correct", tclas->len);
1425 return 0;
1427 else {
1428 val = pkt_pull(pkt, len);
1429 if (val == NULL)
1430 return 0;
1432 tprintf("Filter Value: 0x");
1433 for (i = 0; i < len / 2; i++)
1434 tprintf("%x ", val[i]);
1435 tprintf(", ");
1436 tprintf("Filter Mask: 0x");
1437 for (i = len / 2; i < len; i++)
1438 tprintf("%x ", val[i]);
1442 else if(frm_class->type == 4) {
1443 struct element_tclas_type4 *type4;
1445 type4 = (struct element_tclas_type4 *)
1446 pkt_pull(pkt, sizeof(*type4));
1447 if (type4 == NULL)
1448 return 0;
1450 tprintf("Version: %u, ", type4->version);
1451 /* big endian format follows */
1452 if(type4->version == 4) {
1453 struct element_tclas_type4_ip4 *type4_ip4;
1454 char src_ip[INET_ADDRSTRLEN];
1455 char dst_ip[INET_ADDRSTRLEN];
1457 type4_ip4 = (struct element_tclas_type4_ip4 *)
1458 pkt_pull(pkt, sizeof(*type4_ip4));
1459 if (type4_ip4 == NULL)
1460 return 0;
1462 inet_ntop(AF_INET, &type4_ip4->sa, src_ip, sizeof(src_ip));
1463 inet_ntop(AF_INET, &type4_ip4->da, dst_ip, sizeof(dst_ip));
1465 tprintf("Src IP: %s, ", src_ip);
1466 tprintf("Dst IP: %s, ", dst_ip);
1467 tprintf("Src Port: %u, ", ntohs(type4_ip4->sp));
1468 tprintf("Dst Port: %u, ", ntohs(type4_ip4->dp));
1469 tprintf("DSCP: 0x%x, ", type4_ip4->dscp);
1470 tprintf("Proto: %u, ", type4_ip4->proto);
1471 tprintf("Res: 0x%x", type4_ip4->reserved);
1473 else if(type4->version == 6) {
1474 struct element_tclas_type4_ip6 *type4_ip6;
1475 char src_ip[INET6_ADDRSTRLEN];
1476 char dst_ip[INET6_ADDRSTRLEN];
1478 type4_ip6 = (struct element_tclas_type4_ip6 *)
1479 pkt_pull(pkt, sizeof(*type4_ip6));
1480 if (type4_ip6 == NULL)
1481 return 0;
1483 inet_ntop(AF_INET6, &type4_ip6->sa,
1484 src_ip, sizeof(src_ip));
1485 inet_ntop(AF_INET6, &type4_ip6->da,
1486 dst_ip, sizeof(dst_ip));
1488 tprintf("Src IP: %s, ", src_ip);
1489 tprintf("Dst IP: %s, ", dst_ip);
1490 tprintf("Src Port: %u, ", ntohs(type4_ip6->sp));
1491 tprintf("Dst Port: %u, ", ntohs(type4_ip6->dp));
1492 tprintf("DSCP: 0x%x, ", type4_ip6->dscp);
1493 tprintf("Nxt Hdr: %u, ", type4_ip6->nxt_hdr);
1494 tprintf("Flow Label: 0x%x%x%x", type4_ip6->flow_label1,
1495 type4_ip6->flow_label2, type4_ip6->flow_label3);
1497 else {
1498 tprintf("Version (%u) not supported", type4->version);
1499 return 0;
1502 else if(frm_class->type == 5) {
1503 struct element_tclas_type5 *type5;
1505 type5 = (struct element_tclas_type5 *)
1506 pkt_pull(pkt, sizeof(*type5));
1507 if (type5 == NULL)
1508 return 0;
1510 tprintf("802.1Q PCP: 0x%x, ", type5->pcp);
1511 tprintf("802.1Q CFI: 0x%x, ", type5->cfi);
1512 tprintf("802.1Q VID: 0x%x", type5->vid);
1514 else {
1515 tprintf("Classifier Type (%u) not supported", frm_class->type);
1516 return 0;
1519 return 1;
1522 static int8_t inf_sched(struct pkt_buff *pkt, u8 *id)
1524 struct element_schedule *schedule;
1525 u16 info;
1527 schedule = (struct element_schedule *) pkt_pull(pkt, sizeof(*schedule));
1528 if (schedule == NULL)
1529 return 0;
1531 info = le16_to_cpu(schedule->inf);
1533 tprintf(" Schedule (%u, Len(%u)): ", *id, schedule->len);
1534 if (len_neq_error(schedule->len, 12))
1535 return 0;
1537 tprintf("Aggregation: %u, ", info >> 15);
1538 tprintf("TSID: %u, ", (info >> 11) & 0xF);
1539 tprintf("Direction: %u, ", (info >> 9) & 0x3);
1540 tprintf("Res: %u, ", info & 0x1FF);
1541 tprintf("Serv Start Time: %uus, ", le32_to_cpu(schedule->start));
1542 tprintf("Serv Interval: %uus, ", le32_to_cpu(schedule->serv_intv));
1543 tprintf("Spec Interval: %fs", le32_to_cpu(schedule->spec_intv) * TU);
1545 return 1;
1548 static int8_t inf_chall_txt(struct pkt_buff *pkt, u8 *id)
1550 struct element_chall_txt *chall_txt;
1551 u8 i;
1552 u8 *txt;
1554 chall_txt = (struct element_chall_txt *)
1555 pkt_pull(pkt, sizeof(*chall_txt));
1556 if (chall_txt == NULL)
1557 return 0;
1559 tprintf(" Challenge Text (%u, Len(%u)): ", *id, chall_txt->len);
1560 if ((chall_txt->len - sizeof(*chall_txt) + 1) > 0) {
1561 txt = pkt_pull(pkt, (chall_txt->len - sizeof(*chall_txt) + 1));
1562 if (txt == NULL)
1563 return 0;
1565 tprintf("0x");
1566 for (i = 0; i < (chall_txt->len - sizeof(*chall_txt) + 1); i++)
1567 tprintf("%x", txt[i]);
1570 return 1;
1573 static int8_t inf_pwr_constr(struct pkt_buff *pkt, u8 *id)
1575 struct element_pwr_constr *pwr_constr;
1577 pwr_constr = (struct element_pwr_constr *) pkt_pull(pkt, sizeof(*pwr_constr));
1578 if (pwr_constr == NULL)
1579 return 0;
1581 tprintf(" Power Constraint (%u, Len(%u)): ", *id, pwr_constr->len);
1582 if (len_neq_error(pwr_constr->len, 1))
1583 return 0;
1585 tprintf("Local Power Constraint: %udB", pwr_constr->local_pwr_constr);
1587 return 1;
1590 static int8_t inf_pwr_cap(struct pkt_buff *pkt, u8 *id)
1592 struct element_pwr_cap *pwr_cap;
1594 pwr_cap = (struct element_pwr_cap *) pkt_pull(pkt, sizeof(*pwr_cap));
1595 if (pwr_cap == NULL)
1596 return 0;
1598 tprintf(" Power Capability (%u, Len(%u)): ", *id, pwr_cap->len);
1599 if (len_neq_error(pwr_cap->len, 2))
1600 return 0;
1602 tprintf("Min. Transm. Pwr Cap.: %ddBm, ", (int8_t)pwr_cap->min_pwr_cap);
1603 tprintf("Max. Transm. Pwr Cap.: %ddBm", (int8_t)pwr_cap->max_pwr_cap);
1605 return 1;
1608 static int8_t inf_tpc_req(struct pkt_buff *pkt, u8 *id)
1610 struct element_tpc_req *tpc_req;
1612 tpc_req = (struct element_tpc_req *) pkt_pull(pkt, sizeof(*tpc_req));
1613 if (tpc_req == NULL)
1614 return 0;
1616 tprintf(" TPC Request (%u, Len(%u))", *id, tpc_req->len);
1617 if (len_neq_error(tpc_req->len, 0))
1618 return 0;
1620 return 1;
1623 static int8_t inf_tpc_rep(struct pkt_buff *pkt, u8 *id)
1625 struct element_tpc_rep *tpc_rep;
1627 tpc_rep = (struct element_tpc_rep *) pkt_pull(pkt, sizeof(*tpc_rep));
1628 if (tpc_rep == NULL)
1629 return 0;
1631 tprintf(" TPC Report (%u, Len(%u)): ", *id, tpc_rep->len);
1632 if (len_neq_error(tpc_rep->len, 2))
1633 return 0;
1635 tprintf("Transmit Power: %udBm, ", (int8_t)tpc_rep->trans_pwr);
1636 tprintf("Link Margin: %udB", (int8_t)tpc_rep->trans_pwr);
1638 return 1;
1641 static int8_t inf_supp_ch(struct pkt_buff *pkt, u8 *id)
1643 struct element_supp_ch *supp_ch;
1644 u8 i;
1646 supp_ch = (struct element_supp_ch *) pkt_pull(pkt, sizeof(*supp_ch));
1647 if (supp_ch == NULL)
1648 return 0;
1650 tprintf(" Supp Channels (%u, Len(%u)): ", *id, supp_ch->len);
1651 if (len_lt_error(supp_ch->len, 2))
1652 return 0;
1654 if(supp_ch->len & 1) {
1655 tprintf("Length should be even");
1656 return 0;
1659 for (i = 0; i < supp_ch->len; i += 2) {
1660 struct element_supp_ch_tuple *supp_ch_tuple;
1662 supp_ch_tuple = (struct element_supp_ch_tuple *)
1663 pkt_pull(pkt, sizeof(*supp_ch_tuple));
1664 if (supp_ch_tuple == NULL)
1665 return 0;
1667 tprintf("First Channel Nr: %u, ", supp_ch_tuple->first_ch_nr);
1668 tprintf("Nr of Channels: %u, ", supp_ch_tuple->nr_ch);
1671 return 1;
1674 static int8_t inf_ch_sw_ann(struct pkt_buff *pkt, u8 *id)
1676 struct element_ch_sw_ann *ch_sw_ann;
1678 ch_sw_ann = (struct element_ch_sw_ann *)
1679 pkt_pull(pkt, sizeof(*ch_sw_ann));
1680 if (ch_sw_ann == NULL)
1681 return 0;
1683 tprintf(" Channel Switch Announc (%u, Len(%u)): ", *id, ch_sw_ann->len);
1684 if (len_neq_error(ch_sw_ann->len, 3))
1685 return 0;
1687 tprintf("Switch Mode: %u, ", ch_sw_ann->switch_mode);
1688 tprintf("New Nr: %u, ", ch_sw_ann->new_nr);
1689 tprintf("Switch Count: %u", ch_sw_ann->switch_cnt);
1691 return 1;
1694 static const char *meas_type(u8 type)
1696 switch (type) {
1697 case 0: return "Basic";
1698 case 1: return "Clear Channel assesment (CCA)";
1699 case 2: return "Receive power indication (RPI) histogram";
1700 case 3: return "Channel load";
1701 case 4: return "Noise histogram";
1702 case 5: return "Beacon";
1703 case 6: return "Frame";
1704 case 7: return "STA statistics";
1705 case 8: return "LCI";
1706 case 9: return "Transmit stream/category measurement";
1707 case 10: return "Multicast diagnostics";
1708 case 11: return "Location Civic";
1709 case 12: return "Location Identifier";
1710 default: return "Reserved";
1714 static int8_t inf_meas_req(struct pkt_buff *pkt, u8 *id)
1716 struct element_meas_req *meas_req;
1718 meas_req = (struct element_meas_req *) pkt_pull(pkt, sizeof(*meas_req));
1719 if (meas_req == NULL)
1720 return 0;
1722 tprintf(" Measurement Req (%u, Len(%u)): ", *id, meas_req->len);
1723 if (len_lt_error(meas_req->len, 3))
1724 return 0;
1726 tprintf("Token: %u, ", meas_req->token);
1727 tprintf("Req Mode: 0x%x (Parallel (%u), Enable(%u), Request(%u), "
1728 "Report(%u), Dur Mand(%u), Res(0x%x)), ", meas_req->req_mode,
1729 meas_req->req_mode & 0x1,
1730 (meas_req->req_mode >> 1) & 0x1,
1731 (meas_req->req_mode >> 2) & 0x1,
1732 (meas_req->req_mode >> 3) & 0x1,
1733 (meas_req->req_mode >> 4) & 0x1,
1734 meas_req->req_mode >> 7);
1735 tprintf("Type: %s (%u), ", meas_type(meas_req->type), meas_req->type);
1737 if(meas_req->len > 3) {
1738 if(meas_req->type == 0) {
1739 struct element_meas_basic *basic;
1741 basic = (struct element_meas_basic *)
1742 pkt_pull(pkt, sizeof(*basic));
1743 if (basic == NULL)
1744 return 0;
1746 if ((meas_req->len - 3 - sizeof(*basic)) != 0) {
1747 tprintf("Length of Req matchs not Type %u",
1748 meas_req->type);
1749 return 0;
1752 tprintf("Ch Nr: %uus, ", basic->ch_nr);
1753 tprintf("Meas Start Time: %"PRIu64", ",
1754 le64_to_cpu(basic->start));
1755 tprintf("Meas Duration: %fs",
1756 le16_to_cpu(basic->dur) * TU);
1759 else if(meas_req->type == 1) {
1760 struct element_meas_cca *cca;
1762 cca = (struct element_meas_cca *)
1763 pkt_pull(pkt, sizeof(*cca));
1764 if (cca == NULL)
1765 return 0;
1767 if ((meas_req->len - 3 - sizeof(*cca)) != 0) {
1768 tprintf("Length of Req matchs not Type %u",
1769 meas_req->type);
1770 return 0;
1773 tprintf("Ch Nr: %uus, ", cca->ch_nr);
1774 tprintf("Meas Start Time: %"PRIu64", ",
1775 le64_to_cpu(cca->start));
1776 tprintf("Meas Duration: %fs",
1777 le16_to_cpu(cca->dur) * TU);
1779 else if(meas_req->type == 2) {
1780 struct element_meas_rpi *rpi;
1782 rpi = (struct element_meas_rpi *)
1783 pkt_pull(pkt, sizeof(*rpi));
1784 if (rpi == NULL)
1785 return 0;
1787 if ((meas_req->len - 3 - sizeof(*rpi)) != 0) {
1788 tprintf("Length of Req matchs not Type %u",
1789 meas_req->type);
1790 return 0;
1793 tprintf("Ch Nr: %uus, ", rpi->ch_nr);
1794 tprintf("Meas Start Time: %"PRIu64", ",
1795 le64_to_cpu(rpi->start));
1796 tprintf("Meas Duration: %fs",
1797 le16_to_cpu(rpi->dur) * TU);
1799 else if(meas_req->type == 3) {
1800 struct element_meas_ch_load *ch_load;
1802 ch_load = (struct element_meas_ch_load *)
1803 pkt_pull(pkt, sizeof(*ch_load));
1804 if (ch_load == NULL)
1805 return 0;
1807 if ((ssize_t)(meas_req->len - 3 - sizeof(*ch_load)) < 0) {
1808 tprintf("Length of Req matchs not Type %u",
1809 meas_req->type);
1810 return 0;
1813 tprintf("OP Class: %u, ", ch_load->op_class);
1814 tprintf("Ch Nr: %u, ", ch_load->ch_nr);
1815 tprintf("Rand Intv: %fs, ",
1816 le16_to_cpu(ch_load->rand_intv) * TU);
1817 tprintf("Meas Duration: %fs",
1818 le16_to_cpu(ch_load->dur) * TU);
1820 if(!subelements(pkt,
1821 meas_req->len - 3 - sizeof(*ch_load)))
1822 return 0;
1824 else if(meas_req->type == 4) {
1825 struct element_meas_noise *noise;
1827 noise = (struct element_meas_noise *)
1828 pkt_pull(pkt, sizeof(*noise));
1829 if (noise == NULL)
1830 return 0;
1832 if ((ssize_t)(meas_req->len - 3 - sizeof(*noise)) < 0) {
1833 tprintf("Length of Req matchs not Type %u",
1834 meas_req->type);
1835 return 0;
1838 tprintf("OP Class: %u, ", noise->op_class);
1839 tprintf("Ch Nr: %u, ", noise->ch_nr);
1840 tprintf("Rand Intv: %fs, ",
1841 le16_to_cpu(noise->rand_intv) * TU);
1842 tprintf("Meas Duration: %fs",
1843 le16_to_cpu(noise->dur) * TU);
1845 if(!subelements(pkt,
1846 meas_req->len - 3 - sizeof(*noise)))
1847 return 0;
1849 else if(meas_req->type == 5) {
1850 struct element_meas_beacon *beacon;
1852 beacon = (struct element_meas_beacon *)
1853 pkt_pull(pkt, sizeof(*beacon));
1854 if (beacon == NULL)
1855 return 0;
1857 if ((ssize_t)(meas_req->len - 3 - sizeof(*beacon)) < 0) {
1858 tprintf("Length of Req matchs not Type %u",
1859 meas_req->type);
1860 return 0;
1863 tprintf("OP Class: %u, ", beacon->op_class);
1864 tprintf("Ch Nr: %u, ", beacon->ch_nr);
1865 tprintf("Rand Intv: %fs, ",
1866 le16_to_cpu(beacon->rand_intv) * TU);
1867 tprintf("Meas Duration: %fs",
1868 le16_to_cpu(beacon->dur) * TU);
1869 tprintf("Mode: %u, ", beacon->mode);
1870 tprintf("BSSID: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
1871 beacon->bssid[0], beacon->bssid[1],
1872 beacon->bssid[2], beacon->bssid[3],
1873 beacon->bssid[4], beacon->bssid[5]);
1875 if(!subelements(pkt,
1876 meas_req->len - 3 - sizeof(*beacon)))
1877 return 0;
1879 else if(meas_req->type == 6) {
1880 struct element_meas_frame *frame;
1882 frame = (struct element_meas_frame *)
1883 pkt_pull(pkt, sizeof(*frame));
1884 if (frame == NULL)
1885 return 0;
1887 if ((ssize_t)(meas_req->len - 3 - sizeof(*frame)) < 0) {
1888 tprintf("Length of Req matchs not Type %u",
1889 meas_req->type);
1890 return 0;
1893 tprintf("OP Class: %u, ", frame->op_class);
1894 tprintf("Ch Nr: %u, ", frame->ch_nr);
1895 tprintf("Rand Intv: %fs, ",
1896 le16_to_cpu(frame->rand_intv) * TU);
1897 tprintf("Meas Duration: %fs",
1898 le16_to_cpu(frame->dur) * TU);
1899 tprintf("Request Type: %u, ", frame->frame);
1900 tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
1901 frame->mac[0], frame->mac[1],
1902 frame->mac[2], frame->mac[3],
1903 frame->mac[4], frame->mac[5]);
1905 if(!subelements(pkt,
1906 meas_req->len - 3 - sizeof(*frame)))
1907 return 0;
1909 else if(meas_req->type == 7) {
1910 struct element_meas_sta *sta;
1912 sta = (struct element_meas_sta *)
1913 pkt_pull(pkt, sizeof(*sta));
1914 if (sta == NULL)
1915 return 0;
1917 if ((ssize_t)(meas_req->len - 3 - sizeof(*sta)) < 0) {
1918 tprintf("Length of Req matchs not Type %u",
1919 meas_req->type);
1920 return 0;
1923 tprintf("Peer MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
1924 sta->peer_mac[0], sta->peer_mac[1],
1925 sta->peer_mac[2], sta->peer_mac[3],
1926 sta->peer_mac[4], sta->peer_mac[5]);
1927 tprintf("Rand Intv: %fs, ",
1928 le16_to_cpu(sta->rand_intv) * TU);
1929 tprintf("Meas Duration: %fs",
1930 le16_to_cpu(sta->dur) * TU);
1931 tprintf("Group ID: %u, ", sta->group_id);
1933 if(!subelements(pkt,
1934 meas_req->len - 3 - sizeof(*sta)))
1935 return 0;
1937 else if(meas_req->type == 8) {
1938 struct element_meas_lci *lci;
1940 lci = (struct element_meas_lci *)
1941 pkt_pull(pkt, sizeof(*lci));
1942 if (lci == NULL)
1943 return 0;
1945 if ((ssize_t)(meas_req->len - 3 - sizeof(*lci)) < 0) {
1946 tprintf("Length of Req matchs not Type %u",
1947 meas_req->type);
1948 return 0;
1951 tprintf("Location Subj: %u, ", lci->loc_subj);
1952 tprintf("Latitude Req Res: %udeg",
1953 lci->latitude_req_res);
1954 tprintf("Longitude Req Res: %udeg",
1955 lci->longitude_req_res);
1956 tprintf("Altitude Req Res: %udeg",
1957 lci->altitude_req_res);
1959 if(!subelements(pkt,
1960 meas_req->len - 3 - sizeof(*lci)))
1961 return 0;
1963 else if(meas_req->type == 9) {
1964 struct element_meas_trans_str_cat *trans;
1966 trans = (struct element_meas_trans_str_cat *)
1967 pkt_pull(pkt, sizeof(*trans));
1968 if (trans == NULL)
1969 return 0;
1971 if ((ssize_t)(meas_req->len - 3 - sizeof(*trans)) < 0) {
1972 tprintf("Length of Req matchs not Type %u",
1973 meas_req->type);
1974 return 0;
1977 tprintf("Rand Intv: %fs, ",
1978 le16_to_cpu(trans->rand_intv) * TU);
1979 tprintf("Meas Duration: %fs",
1980 le16_to_cpu(trans->dur) * TU);
1981 tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
1982 trans->peer_sta_addr[0], trans->peer_sta_addr[1],
1983 trans->peer_sta_addr[2], trans->peer_sta_addr[3],
1984 trans->peer_sta_addr[4], trans->peer_sta_addr[5]);
1985 tprintf("Traffic ID: %u, ", trans->traffic_id);
1986 tprintf("Bin 0 Range: %u, ", trans->bin_0_range);
1988 if(!subelements(pkt,
1989 meas_req->len - 3 - sizeof(*trans)))
1990 return 0;
1992 else if(meas_req->type == 10) {
1993 struct element_meas_mcast_diag *mcast;
1995 mcast = (struct element_meas_mcast_diag *)
1996 pkt_pull(pkt, sizeof(*mcast));
1997 if (mcast == NULL)
1998 return 0;
2000 if ((ssize_t)(meas_req->len - 3 - sizeof(*mcast)) < 0) {
2001 tprintf("Length of Req matchs not Type %u",
2002 meas_req->type);
2003 return 0;
2006 tprintf("Rand Intv: %fs, ",
2007 le16_to_cpu(mcast->rand_intv) * TU);
2008 tprintf("Meas Duration: %fs",
2009 le16_to_cpu(mcast->dur) * TU);
2010 tprintf("Group MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
2011 mcast->group_mac[0], mcast->group_mac[1],
2012 mcast->group_mac[2], mcast->group_mac[3],
2013 mcast->group_mac[4], mcast->group_mac[5]);
2015 if(!subelements(pkt,
2016 meas_req->len - 3 - sizeof(*mcast)))
2017 return 0;
2019 else if(meas_req->type == 11) {
2020 struct element_meas_loc_civic *civic;
2022 civic = (struct element_meas_loc_civic *)
2023 pkt_pull(pkt, sizeof(*civic));
2024 if (civic == NULL)
2025 return 0;
2027 if ((ssize_t)(meas_req->len - 3 - sizeof(*civic)) < 0) {
2028 tprintf("Length of Req matchs not Type %u",
2029 meas_req->type);
2030 return 0;
2033 tprintf("Location Subj: %u, ", civic->loc_subj);
2034 tprintf("Type: %u, ", civic->civic_loc);
2035 tprintf("Srv Intv Units: %u, ",
2036 le16_to_cpu(civic->loc_srv_intv_unit));
2037 tprintf("Srv Intv: %u, ", civic->loc_srv_intv);
2039 if(!subelements(pkt,
2040 meas_req->len - 3 - sizeof(*civic)))
2041 return 0;
2043 else if(meas_req->type == 12) {
2044 struct element_meas_loc_id *id;
2046 id = (struct element_meas_loc_id *)
2047 pkt_pull(pkt, sizeof(*id));
2048 if (id == NULL)
2049 return 0;
2051 if ((ssize_t)(meas_req->len - 3 - sizeof(*id)) < 0) {
2052 tprintf("Length of Req matchs not Type %u",
2053 meas_req->type);
2054 return 0;
2057 tprintf("Location Subj: %u, ", id->loc_subj);
2058 tprintf("Srv Intv Units: %u, ",
2059 le16_to_cpu(id->loc_srv_intv_unit));
2060 tprintf("Srv Intv: %u", id->loc_srv_intv);
2062 if(!subelements(pkt,
2063 meas_req->len - 3 - sizeof(*id)))
2064 return 0;
2066 else if(meas_req->type == 255) {
2067 struct element_meas_pause *pause;
2069 pause = (struct element_meas_pause *)
2070 pkt_pull(pkt, sizeof(*pause));
2071 if (pause == NULL)
2072 return 0;
2074 if ((ssize_t)(meas_req->len - 3 - sizeof(*pause)) < 0) {
2075 tprintf("Length of Req matchs not Type %u",
2076 meas_req->type);
2077 return 0;
2080 tprintf("Pause Time: %fs, ", pause->time * 10 * TU);
2082 if(!subelements(pkt,
2083 meas_req->len - 3 - sizeof(*pause)))
2084 return 0;
2086 else {
2087 tprintf("Length field indicates data,"
2088 " but could not interpreted");
2089 return 0;
2093 return 1;
2096 static int8_t inf_meas_rep(struct pkt_buff *pkt, u8 *id)
2098 struct element_meas_rep *meas_rep;
2100 meas_rep = (struct element_meas_rep *) pkt_pull(pkt, sizeof(*meas_rep));
2101 if (meas_rep == NULL)
2102 return 0;
2104 tprintf(" Measurement Rep (%u, Len(%u)): ", *id, meas_rep->len);
2105 if (len_lt_error(meas_rep->len, 3))
2106 return 0;
2108 tprintf("Token: %u, ", meas_rep->token);
2109 tprintf("Rep Mode: 0x%x (Late (%u), Incapable(%u), Refused(%u), ",
2110 meas_rep->rep_mode, meas_rep->rep_mode >> 7,
2111 (meas_rep->rep_mode >> 6) & 0x1,
2112 (meas_rep->rep_mode >> 5) & 0x1);
2113 tprintf("Type: %s (%u), ", meas_type(meas_rep->type), meas_rep->type);
2115 if(meas_rep->len > 3) {
2116 if(meas_rep->type == 0) {
2117 struct element_meas_basic *basic;
2119 basic = (struct element_meas_basic *)
2120 pkt_pull(pkt, sizeof(*basic));
2121 if (basic == NULL)
2122 return 0;
2124 if ((meas_rep->len - 3 - sizeof(*basic)) != 0) {
2125 tprintf("Length of Req matchs not Type %u",
2126 meas_rep->type);
2127 return 0;
2130 tprintf("Ch Nr: %uus, ", basic->ch_nr);
2131 tprintf("Meas Start Time: %"PRIu64", ",
2132 le64_to_cpu(basic->start));
2133 tprintf("Meas Duration: %fs",
2134 le16_to_cpu(basic->dur) * TU);
2137 else if(meas_rep->type == 1) {
2138 struct element_meas_cca *cca;
2140 cca = (struct element_meas_cca *)
2141 pkt_pull(pkt, sizeof(*cca));
2142 if (cca == NULL)
2143 return 0;
2145 if ((meas_rep->len - 3 - sizeof(*cca)) != 0) {
2146 tprintf("Length of Req matchs not Type %u",
2147 meas_rep->type);
2148 return 0;
2151 tprintf("Ch Nr: %uus, ", cca->ch_nr);
2152 tprintf("Meas Start Time: %"PRIu64", ",
2153 le64_to_cpu(cca->start));
2154 tprintf("Meas Duration: %fs",
2155 le16_to_cpu(cca->dur) * TU);
2157 else if(meas_rep->type == 2) {
2158 struct element_meas_rpi *rpi;
2160 rpi = (struct element_meas_rpi *)
2161 pkt_pull(pkt, sizeof(*rpi));
2162 if (rpi == NULL)
2163 return 0;
2165 if ((meas_rep->len - 3 - sizeof(*rpi)) != 0) {
2166 tprintf("Length of Req matchs not Type %u",
2167 meas_rep->type);
2168 return 0;
2171 tprintf("Ch Nr: %uus, ", rpi->ch_nr);
2172 tprintf("Meas Start Time: %"PRIu64", ",
2173 le64_to_cpu(rpi->start));
2174 tprintf("Meas Duration: %fs",
2175 le16_to_cpu(rpi->dur) * TU);
2177 else if(meas_rep->type == 3) {
2178 struct element_meas_ch_load *ch_load;
2180 ch_load = (struct element_meas_ch_load *)
2181 pkt_pull(pkt, sizeof(*ch_load));
2182 if (ch_load == NULL)
2183 return 0;
2185 if ((ssize_t)(meas_rep->len - 3 - sizeof(*ch_load)) < 0) {
2186 tprintf("Length of Req matchs not Type %u",
2187 meas_rep->type);
2188 return 0;
2191 tprintf("OP Class: %u, ", ch_load->op_class);
2192 tprintf("Ch Nr: %u, ", ch_load->ch_nr);
2193 tprintf("Rand Intv: %fs, ",
2194 le16_to_cpu(ch_load->rand_intv) * TU);
2195 tprintf("Meas Duration: %fs",
2196 le16_to_cpu(ch_load->dur) * TU);
2198 if(!subelements(pkt,
2199 meas_rep->len - 3 - sizeof(*ch_load)))
2200 return 0;
2202 else if(meas_rep->type == 4) {
2203 struct element_meas_noise *noise;
2205 noise = (struct element_meas_noise *)
2206 pkt_pull(pkt, sizeof(*noise));
2207 if (noise == NULL)
2208 return 0;
2210 if ((ssize_t)(meas_rep->len - 3 - sizeof(*noise)) < 0) {
2211 tprintf("Length of Req matchs not Type %u",
2212 meas_rep->type);
2213 return 0;
2216 tprintf("OP Class: %u, ", noise->op_class);
2217 tprintf("Ch Nr: %u, ", noise->ch_nr);
2218 tprintf("Rand Intv: %fs, ",
2219 le16_to_cpu(noise->rand_intv) * TU);
2220 tprintf("Meas Duration: %fs",
2221 le16_to_cpu(noise->dur) * TU);
2223 if(!subelements(pkt,
2224 meas_rep->len - 3 - sizeof(*noise)))
2225 return 0;
2227 else if(meas_rep->type == 5) {
2228 struct element_meas_beacon *beacon;
2230 beacon = (struct element_meas_beacon *)
2231 pkt_pull(pkt, sizeof(*beacon));
2232 if (beacon == NULL)
2233 return 0;
2235 if ((ssize_t)(meas_rep->len - 3 - sizeof(*beacon)) < 0) {
2236 tprintf("Length of Req matchs not Type %u",
2237 meas_rep->type);
2238 return 0;
2241 tprintf("OP Class: %u, ", beacon->op_class);
2242 tprintf("Ch Nr: %u, ", beacon->ch_nr);
2243 tprintf("Rand Intv: %fs, ",
2244 le16_to_cpu(beacon->rand_intv) * TU);
2245 tprintf("Meas Duration: %fs",
2246 le16_to_cpu(beacon->dur) * TU);
2247 tprintf("Mode: %u, ", beacon->mode);
2248 tprintf("BSSID: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
2249 beacon->bssid[0], beacon->bssid[1],
2250 beacon->bssid[2], beacon->bssid[3],
2251 beacon->bssid[4], beacon->bssid[5]);
2253 if(!subelements(pkt,
2254 meas_rep->len - 3 - sizeof(*beacon)))
2255 return 0;
2257 else if(meas_rep->type == 6) {
2258 struct element_meas_frame *frame;
2260 frame = (struct element_meas_frame *)
2261 pkt_pull(pkt, sizeof(*frame));
2262 if (frame == NULL)
2263 return 0;
2265 if ((ssize_t)(meas_rep->len - 3 - sizeof(*frame)) < 0) {
2266 tprintf("Length of Req matchs not Type %u",
2267 meas_rep->type);
2268 return 0;
2271 tprintf("OP Class: %u, ", frame->op_class);
2272 tprintf("Ch Nr: %u, ", frame->ch_nr);
2273 tprintf("Rand Intv: %fs, ",
2274 le16_to_cpu(frame->rand_intv) * TU);
2275 tprintf("Meas Duration: %fs",
2276 le16_to_cpu(frame->dur) * TU);
2277 tprintf("Request Type: %u, ", frame->frame);
2278 tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
2279 frame->mac[0], frame->mac[1],
2280 frame->mac[2], frame->mac[3],
2281 frame->mac[4], frame->mac[5]);
2283 if(!subelements(pkt,
2284 meas_rep->len - 3 - sizeof(*frame)))
2285 return 0;
2287 else if(meas_rep->type == 7) {
2288 struct element_meas_sta *sta;
2290 sta = (struct element_meas_sta *)
2291 pkt_pull(pkt, sizeof(*sta));
2292 if (sta == NULL)
2293 return 0;
2295 if ((ssize_t)(meas_rep->len - 3 - sizeof(*sta)) < 0) {
2296 tprintf("Length of Req matchs not Type %u",
2297 meas_rep->type);
2298 return 0;
2301 tprintf("Peer MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
2302 sta->peer_mac[0], sta->peer_mac[1],
2303 sta->peer_mac[2], sta->peer_mac[3],
2304 sta->peer_mac[4], sta->peer_mac[5]);
2305 tprintf("Rand Intv: %fs, ",
2306 le16_to_cpu(sta->rand_intv) * TU);
2307 tprintf("Meas Duration: %fs",
2308 le16_to_cpu(sta->dur) * TU);
2309 tprintf("Group ID: %u, ", sta->group_id);
2311 if(!subelements(pkt,
2312 meas_rep->len - 3 - sizeof(*sta)))
2313 return 0;
2315 else if(meas_rep->type == 8) {
2316 struct element_meas_lci *lci;
2318 lci = (struct element_meas_lci *)
2319 pkt_pull(pkt, sizeof(*lci));
2320 if (lci == NULL)
2321 return 0;
2323 if ((ssize_t)(meas_rep->len - 3 - sizeof(*lci)) < 0) {
2324 tprintf("Length of Req matchs not Type %u",
2325 meas_rep->type);
2326 return 0;
2329 tprintf("Location Subj: %u, ", lci->loc_subj);
2330 tprintf("Latitude Req Res: %udeg",
2331 lci->latitude_req_res);
2332 tprintf("Longitude Req Res: %udeg",
2333 lci->longitude_req_res);
2334 tprintf("Altitude Req Res: %udeg",
2335 lci->altitude_req_res);
2337 if(!subelements(pkt,
2338 meas_rep->len - 3 - sizeof(*lci)))
2339 return 0;
2341 else if(meas_rep->type == 9) {
2342 struct element_meas_trans_str_cat *trans;
2344 trans = (struct element_meas_trans_str_cat *)
2345 pkt_pull(pkt, sizeof(*trans));
2346 if (trans == NULL)
2347 return 0;
2349 if ((ssize_t)(meas_rep->len - 3 - sizeof(*trans)) < 0) {
2350 tprintf("Length of Req matchs not Type %u",
2351 meas_rep->type);
2352 return 0;
2355 tprintf("Rand Intv: %fs, ",
2356 le16_to_cpu(trans->rand_intv) * TU);
2357 tprintf("Meas Duration: %fs",
2358 le16_to_cpu(trans->dur) * TU);
2359 tprintf("MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
2360 trans->peer_sta_addr[0], trans->peer_sta_addr[1],
2361 trans->peer_sta_addr[2], trans->peer_sta_addr[3],
2362 trans->peer_sta_addr[4], trans->peer_sta_addr[5]);
2363 tprintf("Traffic ID: %u, ", trans->traffic_id);
2364 tprintf("Bin 0 Range: %u, ", trans->bin_0_range);
2366 if(!subelements(pkt,
2367 meas_rep->len - 3 - sizeof(*trans)))
2368 return 0;
2370 else if(meas_rep->type == 10) {
2371 struct element_meas_mcast_diag *mcast;
2373 mcast = (struct element_meas_mcast_diag *)
2374 pkt_pull(pkt, sizeof(*mcast));
2375 if (mcast == NULL)
2376 return 0;
2378 if ((ssize_t)(meas_rep->len - 3 - sizeof(*mcast)) < 0) {
2379 tprintf("Length of Req matchs not Type %u",
2380 meas_rep->type);
2381 return 0;
2384 tprintf("Rand Intv: %fs, ",
2385 le16_to_cpu(mcast->rand_intv) * TU);
2386 tprintf("Meas Duration: %fs",
2387 le16_to_cpu(mcast->dur) * TU);
2388 tprintf("Group MAC Addr: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x",
2389 mcast->group_mac[0], mcast->group_mac[1],
2390 mcast->group_mac[2], mcast->group_mac[3],
2391 mcast->group_mac[4], mcast->group_mac[5]);
2393 if(!subelements(pkt,
2394 meas_rep->len - 3 - sizeof(*mcast)))
2395 return 0;
2397 else if(meas_rep->type == 11) {
2398 struct element_meas_loc_civic *civic;
2400 civic = (struct element_meas_loc_civic *)
2401 pkt_pull(pkt, sizeof(*civic));
2402 if (civic == NULL)
2403 return 0;
2405 if ((ssize_t)(meas_rep->len - 3 - sizeof(*civic)) < 0) {
2406 tprintf("Length of Req matchs not Type %u",
2407 meas_rep->type);
2408 return 0;
2411 tprintf("Location Subj: %u, ", civic->loc_subj);
2412 tprintf("Type: %u, ", civic->civic_loc);
2413 tprintf("Srv Intv Units: %u, ",
2414 le16_to_cpu(civic->loc_srv_intv_unit));
2415 tprintf("Srv Intv: %u, ", civic->loc_srv_intv);
2417 if(!subelements(pkt,
2418 meas_rep->len - 3 - sizeof(*civic)))
2419 return 0;
2421 else if(meas_rep->type == 12) {
2422 struct element_meas_loc_id *id;
2424 id = (struct element_meas_loc_id *)
2425 pkt_pull(pkt, sizeof(*id));
2426 if (id == NULL)
2427 return 0;
2429 if ((ssize_t)(meas_rep->len - 3 - sizeof(*id)) < 0) {
2430 tprintf("Length of Req matchs not Type %u",
2431 meas_rep->type);
2432 return 0;
2435 tprintf("Location Subj: %u, ", id->loc_subj);
2436 tprintf("Srv Intv Units: %u, ",
2437 le16_to_cpu(id->loc_srv_intv_unit));
2438 tprintf("Srv Intv: %u", id->loc_srv_intv);
2440 if(!subelements(pkt,
2441 meas_rep->len - 3 - sizeof(*id)))
2442 return 0;
2444 else {
2445 tprintf("Length field indicates data,"
2446 " but could not interpreted");
2447 return 0;
2451 return 1;
2454 static int8_t inf_quiet(struct pkt_buff *pkt, u8 *id)
2456 struct element_quiet *quiet;
2458 quiet = (struct element_quiet *) pkt_pull(pkt, sizeof(*quiet));
2459 if (quiet == NULL)
2460 return 0;
2462 tprintf(" Quit (%u, Len(%u)): ", *id, quiet->len);
2463 if (len_neq_error(quiet->len, 6))
2464 return 0;
2466 tprintf("Count: %ud, ", quiet->cnt);
2467 tprintf("Period: %u, ", quiet->period);
2468 tprintf("Duration: %fs, ", le16_to_cpu(quiet->dur) * TU);
2469 tprintf("Offs: %fs", le16_to_cpu(quiet->offs) * TU);
2472 return 1;
2475 static int8_t inf_ibss_dfs(struct pkt_buff *pkt, u8 *id)
2477 struct element_ibss_dfs *ibss_dfs;
2478 u8 i;
2480 ibss_dfs = (struct element_ibss_dfs *) pkt_pull(pkt, sizeof(*ibss_dfs));
2481 if (ibss_dfs == NULL)
2482 return 0;
2484 tprintf(" IBSS DFS (%u, Len(%u)): ", *id, ibss_dfs->len);
2485 if (len_lt_error(ibss_dfs->len, 7))
2486 return 0;
2488 tprintf("Owner: %.2x:%.2x:%.2x:%.2x:%.2x:%.2x, ",
2489 ibss_dfs->owner[0], ibss_dfs->owner[1],
2490 ibss_dfs->owner[2], ibss_dfs->owner[3],
2491 ibss_dfs->owner[4], ibss_dfs->owner[5]);
2492 tprintf("Recovery Intv: %u, ", ibss_dfs->rec_intv);
2494 if((ibss_dfs->len - sizeof(*ibss_dfs) + 1) & 1) {
2495 tprintf("Length of Channel Map should be modulo 2");
2496 return 0;
2499 for (i = 0; i < ibss_dfs->len; i += 2) {
2500 struct element_ibss_dfs_tuple *ibss_dfs_tuple;
2502 ibss_dfs_tuple = (struct element_ibss_dfs_tuple *)
2503 pkt_pull(pkt, sizeof(*ibss_dfs_tuple));
2504 if (ibss_dfs_tuple == NULL)
2505 return 0;
2507 tprintf("Channel Nr: %u, ", ibss_dfs_tuple->ch_nr);
2508 tprintf("Map: %u, ", ibss_dfs_tuple->map);
2511 return 1;
2514 static int8_t inf_erp(struct pkt_buff *pkt, u8 *id)
2516 struct element_erp *erp;
2518 erp = (struct element_erp *) pkt_pull(pkt, sizeof(*erp));
2519 if (erp == NULL)
2520 return 0;
2522 tprintf(" ERP (%u, Len(%u)): ", *id, erp->len);
2523 if (len_neq_error(erp->len, 1))
2524 return 0;
2525 tprintf("Non ERP Present (%u), ", erp->param & 0x1);
2526 tprintf("Use Protection (%u), ", (erp->param >> 1) & 0x1);
2527 tprintf("Barker Preamble Mode (%u), ", (erp->param >> 2) & 0x1);
2528 tprintf("Reserved (0x%.5x)", erp->param >> 3);
2530 return 1;
2533 static int8_t inf_ts_del(struct pkt_buff *pkt, u8 *id)
2535 struct element_ts_del *ts_del;
2537 ts_del = (struct element_ts_del *) pkt_pull(pkt, sizeof(*ts_del));
2538 if (ts_del == NULL)
2539 return 0;
2541 tprintf(" TS Delay (%u, Len(%u)): ", *id, ts_del->len);
2542 if (len_neq_error(ts_del->len, 4))
2543 return 0;
2544 tprintf("Delay (%fs)", le32_to_cpu(ts_del->delay) * TU);
2546 return 1;
2549 static int8_t inf_tclas_proc(struct pkt_buff *pkt, u8 *id)
2551 struct element_tclas_proc *tclas_proc;
2553 tclas_proc = (struct element_tclas_proc *)
2554 pkt_pull(pkt, sizeof(*tclas_proc));
2555 if (tclas_proc == NULL)
2556 return 0;
2558 tprintf(" TCLAS Procesing (%u, Len(%u)): ", *id, tclas_proc->len);
2559 if (len_neq_error(tclas_proc->len, 1))
2560 return 0;
2561 tprintf("Processing (%u)", tclas_proc->proc);
2563 return 1;
2566 static int8_t inf_ht_cap(struct pkt_buff *pkt, u8 *id)
2568 struct element_ht_cap *ht_cap;
2569 u32 tx_param_res, beam_cap;
2570 u16 ext_cap;
2572 ht_cap = (struct element_ht_cap *)
2573 pkt_pull(pkt, sizeof(*ht_cap));
2574 if (ht_cap == NULL)
2575 return 0;
2577 tx_param_res = le32_to_cpu(ht_cap->tx_param_res);
2578 beam_cap = le32_to_cpu(ht_cap->beam_cap);
2579 ext_cap = le16_to_cpu(ht_cap->ext_cap);
2581 tprintf(" HT Capabilities (%u, Len(%u)): ", *id, ht_cap->len);
2582 if (len_neq_error(ht_cap->len, 26))
2583 return 0;
2584 tprintf("Info (LDCP Cod Cap (%u), Supp Ch Width Set (%u),"
2585 " SM Pwr Save(%u), HT-Greenfield (%u), Short GI for 20/40 MHz"
2586 " (%u/%u), Tx/Rx STBC (%u/%u), HT-Delayed Block Ack (%u),"
2587 " Max A-MSDU Len (%u), DSSS/CCK Mode in 40 MHz (%u),"
2588 " Res (0x%x), Forty MHz Intol (%u), L-SIG TXOP Protection Supp"
2589 " (%u)), ", ht_cap->ldpc, ht_cap->supp_width,
2590 ht_cap->sm_pwr, ht_cap->ht_green, ht_cap->gi_20mhz,
2591 ht_cap->gi_40mhz, ht_cap->tx_stbc, ht_cap->rx_stbc,
2592 ht_cap->ht_ack, ht_cap->max_msdu_length, ht_cap->dsss_ck_mode,
2593 ht_cap->res, ht_cap->forty_int, ht_cap->prot_supp);
2594 tprintf("A-MPDU Params (Max Len Exp (%u), Min Start Spacing (%u),"
2595 " Res (0x%x)), ", ht_cap->param >> 6, (ht_cap->param >> 3) & 0x7,
2596 ht_cap->param & 0x07);
2597 tprintf("Supp MCS Set (Rx MCS Bitmask (0x%x%x%x%x%x%x%x%x%x%x),"
2598 " Res (0x%x), Rx High Supp Data Rate (%u), Res (0x%x),"
2599 " Tx MCS Set Def (%u), Tx Rx MCS Set Not Eq (%u),"
2600 " Tx Max Number Spat Str Supp (%u),"
2601 " Tx Uneq Mod Supp (%u), Res (0x%x)), ",
2602 ht_cap->bitmask1, ht_cap->bitmask2, ht_cap->bitmask3,
2603 ht_cap->bitmask4, ht_cap->bitmask5, ht_cap->bitmask6,
2604 ht_cap->bitmask7, ht_cap->bitmask8, ht_cap->bitmask9,
2605 ht_cap->bitmask10_res >> 3, ht_cap->bitmask10_res & 0x7,
2606 le16_to_cpu(ht_cap->supp_rate_res) >> 6,
2607 le16_to_cpu(ht_cap->supp_rate_res) & 0x3F,
2608 tx_param_res >> 31, (tx_param_res >> 30) & 1,
2609 (tx_param_res >> 28) & 3, (tx_param_res >> 27) & 1,
2610 tx_param_res & 0x7FFFFFF);
2611 tprintf("Ext Cap (PCO (%u), PCO Trans Time (%u), Res (0x%x),"
2612 " MCS Feedb (%u), +HTC Supp (%u), RD Resp (%u), Res (0x%x)), ",
2613 ext_cap >> 15, (ext_cap >> 13) & 3, (ext_cap >> 8) & 0x1F,
2614 (ext_cap >> 6) & 3, (ext_cap >> 5) & 1, (ext_cap >> 4) & 1,
2615 ext_cap & 0xF);
2616 tprintf("Transm Beamf (Impl Transm Beamf Rec Cap (%u),"
2617 " Rec/Transm Stagg Sound Cap (%u/%u),"
2618 " Rec/Trans NDP Cap (%u/%u), Impl Transm Beamf Cap (%u),"
2619 " Cal (%u), Expl CSI Transm Beamf Cap (%u),"
2620 " Expl Noncmpr/Compr Steering Cap (%u/%u),"
2621 " Expl Trans Beamf CSI Feedb (%u),"
2622 " Expl Noncmpr/Cmpr Feedb Cap (%u/%u),"
2623 " Min Grpg (%u), CSI Num Beamf Ant Supp (%u),"
2624 " Noncmpr/Cmpr Steering Nr Beamf Ant Supp (%u/%u),"
2625 " CSI Max Nr Rows Beamf Supp (%u),"
2626 " Ch Estim Cap (%u), Res (0x%x)), ",
2627 beam_cap >> 31, (beam_cap >> 30) & 1, (beam_cap >> 29) & 1,
2628 (beam_cap >> 28) & 1, (beam_cap >> 27) & 1, (beam_cap >> 26) & 1,
2629 (beam_cap >> 24) & 3, (beam_cap >> 23) & 1, (beam_cap >> 22) & 1,
2630 (beam_cap >> 21) & 1, (beam_cap >> 19) & 3, (beam_cap >> 17) & 3,
2631 (beam_cap >> 15) & 3, (beam_cap >> 13) & 3, (beam_cap >> 11) & 3,
2632 (beam_cap >> 9) & 3, (beam_cap >> 7) & 3, (beam_cap >> 5) & 3,
2633 (beam_cap >> 3) & 3, beam_cap & 7);
2634 tprintf("ASEL (Ant Select Cap (%u),"
2635 " Expl CSI Feedb Based Transm ASEL Cap (%u),"
2636 " Ant Indic Feedb Based Transm ASEL Cap (%u),"
2637 " Expl CSI Feedb Cap (%u), Ant Indic Feedb Cap (%u),"
2638 " Rec ASEL Cap (%u), Transm Sound PPDUs Cap (%u), Res (0x%x))",
2639 ht_cap->asel_cap >> 7, (ht_cap->asel_cap >> 6) & 1,
2640 (ht_cap->asel_cap >> 5) & 1, (ht_cap->asel_cap >> 4) & 1,
2641 (ht_cap->asel_cap >> 3) & 1, (ht_cap->asel_cap >> 2) & 1,
2642 (ht_cap->asel_cap >> 1) & 1, ht_cap->asel_cap & 1);
2644 return 1;
2647 static int8_t inf_qos_cap(struct pkt_buff *pkt, u8 *id)
2649 struct element_qos_cap *qos_cap;
2651 qos_cap = (struct element_qos_cap *)
2652 pkt_pull(pkt, sizeof(*qos_cap));
2653 if (qos_cap == NULL)
2654 return 0;
2656 tprintf(" QoS Capabilities (%u, Len(%u)): ", *id, qos_cap->len);
2657 if (len_neq_error(qos_cap->len, 1))
2658 return 0;
2660 tprintf("Info (0x%x)", qos_cap->info);
2662 return 1;
2665 static int8_t inf_ext_supp_rates(struct pkt_buff *pkt, u8 *id)
2667 u8 i;
2668 u8 *rates;
2669 struct element_ext_supp_rates *ext_supp_rates;
2671 ext_supp_rates = (struct element_ext_supp_rates *)
2672 pkt_pull(pkt, sizeof(*ext_supp_rates));
2673 if (ext_supp_rates == NULL)
2674 return 0;
2676 tprintf(" Ext Support Rates (%u, Len(%u)): ", *id, ext_supp_rates->len);
2678 if ((ext_supp_rates->len - sizeof(*ext_supp_rates) + 1) > 0) {
2679 rates = pkt_pull(pkt, ext_supp_rates->len);
2680 if (rates == NULL)
2681 return 0;
2683 for (i = 0; i < ext_supp_rates->len; i++)
2684 tprintf("%g ", (rates[i] & 0x80) ?
2685 ((rates[i] & 0x3f) * 0.5) :
2686 data_rates(rates[i]));
2687 return 1;
2690 return 0;
2693 static int8_t inf_vend_spec(struct pkt_buff *pkt, u8 *id)
2695 u8 i;
2696 u8 *data;
2697 struct element_vend_spec *vend_spec;
2699 vend_spec = (struct element_vend_spec *)
2700 pkt_pull(pkt, sizeof(*vend_spec));
2701 if (vend_spec == NULL)
2702 return 0;
2704 tprintf(" Vendor Specific (%u, Len (%u)): ", *id, vend_spec->len);
2706 data = pkt_pull(pkt, vend_spec->len);
2707 if (data == NULL)
2708 return 0;
2710 tprintf("Data 0x");
2711 for (i = 0; i < vend_spec->len; i++)
2712 tprintf("%.2x", data[i]);
2714 return 1;
2717 static int8_t inf_unimplemented(struct pkt_buff *pkt __maybe_unused,
2718 u8 *id __maybe_unused)
2720 return 0;
2723 static int8_t inf_elements(struct pkt_buff *pkt)
2725 u8 *id = pkt_pull(pkt, 1);
2726 if (id == NULL)
2727 return 0;
2729 switch (*id) {
2730 case 0: return inf_ssid(pkt, id);
2731 case 1: return inf_supp_rates(pkt, id);
2732 case 2: return inf_fh_ps(pkt, id);
2733 case 3: return inf_dsss_ps(pkt, id);
2734 case 4: return inf_cf_ps(pkt, id);
2735 case 5: return inf_tim(pkt, id);
2736 case 6: return inf_ibss_ps(pkt, id);
2737 case 7: return inf_country(pkt, id);
2738 case 8: return inf_hop_pp(pkt, id);
2739 case 9: return inf_hop_pt(pkt, id);
2740 case 10: return inf_req(pkt, id);
2741 case 11: return inf_bss_load(pkt, id);
2742 case 12: return inf_edca_ps(pkt, id);
2743 case 13: return inf_tspec(pkt, id);
2744 case 14: return inf_tclas(pkt, id);
2745 case 15: return inf_sched(pkt, id);
2746 case 16: return inf_chall_txt(pkt, id);
2747 case 17 ... 31: return inf_reserved(pkt, id);
2748 case 32: return inf_pwr_constr(pkt, id);
2749 case 33: return inf_pwr_cap(pkt, id);
2750 case 34: return inf_tpc_req(pkt, id);
2751 case 35: return inf_tpc_rep(pkt, id);
2752 case 36: return inf_supp_ch(pkt, id);
2753 case 37: return inf_ch_sw_ann(pkt, id);
2754 case 38: return inf_meas_req(pkt, id);
2755 case 39: return inf_meas_rep(pkt, id);
2756 case 40: return inf_quiet(pkt, id);
2757 case 41: return inf_ibss_dfs(pkt, id);
2758 case 42: return inf_erp(pkt, id);
2759 case 43: return inf_ts_del(pkt, id);
2760 case 44: return inf_tclas_proc(pkt, id);
2761 case 45: return inf_ht_cap(pkt, id);
2762 case 46: return inf_qos_cap(pkt, id);
2763 case 47: return inf_reserved(pkt, id);
2764 case 48: return inf_unimplemented(pkt, id);
2765 case 49: return inf_unimplemented(pkt, id);
2766 case 50: return inf_ext_supp_rates(pkt, id);
2767 case 51: return inf_unimplemented(pkt, id);
2768 case 52: return inf_unimplemented(pkt, id);
2769 case 53: return inf_unimplemented(pkt, id);
2770 case 54: return inf_unimplemented(pkt, id);
2771 case 55: return inf_unimplemented(pkt, id);
2772 case 56: return inf_unimplemented(pkt, id);
2773 case 57: return inf_unimplemented(pkt, id);
2774 case 58: return inf_unimplemented(pkt, id);
2775 case 59: return inf_unimplemented(pkt, id);
2776 case 60: return inf_unimplemented(pkt, id);
2777 case 61: return inf_unimplemented(pkt, id);
2778 case 62: return inf_unimplemented(pkt, id);
2779 case 63: return inf_unimplemented(pkt, id);
2780 case 64: return inf_unimplemented(pkt, id);
2781 case 65: return inf_unimplemented(pkt, id);
2782 case 66: return inf_unimplemented(pkt, id);
2783 case 67: return inf_unimplemented(pkt, id);
2784 case 68: return inf_unimplemented(pkt, id);
2785 case 69: return inf_unimplemented(pkt, id);
2786 case 70: return inf_unimplemented(pkt, id);
2787 case 71: return inf_unimplemented(pkt, id);
2788 case 72: return inf_unimplemented(pkt, id);
2789 case 73: return inf_unimplemented(pkt, id);
2790 case 74: return inf_unimplemented(pkt, id);
2791 case 75: return inf_unimplemented(pkt, id);
2792 case 76: return inf_unimplemented(pkt, id);
2793 case 78: return inf_unimplemented(pkt, id);
2794 case 79: return inf_unimplemented(pkt, id);
2795 case 80: return inf_unimplemented(pkt, id);
2796 case 81: return inf_unimplemented(pkt, id);
2797 case 82: return inf_unimplemented(pkt, id);
2798 case 83: return inf_unimplemented(pkt, id);
2799 case 84: return inf_unimplemented(pkt, id);
2800 case 85: return inf_unimplemented(pkt, id);
2801 case 86: return inf_unimplemented(pkt, id);
2802 case 87: return inf_unimplemented(pkt, id);
2803 case 88: return inf_unimplemented(pkt, id);
2804 case 89: return inf_unimplemented(pkt, id);
2805 case 90: return inf_unimplemented(pkt, id);
2806 case 91: return inf_unimplemented(pkt, id);
2807 case 92: return inf_unimplemented(pkt, id);
2808 case 93: return inf_unimplemented(pkt, id);
2809 case 94: return inf_unimplemented(pkt, id);
2810 case 95: return inf_unimplemented(pkt, id);
2811 case 96: return inf_unimplemented(pkt, id);
2812 case 97: return inf_unimplemented(pkt, id);
2813 case 98: return inf_unimplemented(pkt, id);
2814 case 99: return inf_unimplemented(pkt, id);
2815 case 100: return inf_unimplemented(pkt, id);
2816 case 101: return inf_unimplemented(pkt, id);
2817 case 102: return inf_unimplemented(pkt, id);
2818 case 104: return inf_unimplemented(pkt, id);
2819 case 105: return inf_unimplemented(pkt, id);
2820 case 106: return inf_unimplemented(pkt, id);
2821 case 107: return inf_unimplemented(pkt, id);
2822 case 108: return inf_unimplemented(pkt, id);
2823 case 109: return inf_unimplemented(pkt, id);
2824 case 110: return inf_unimplemented(pkt, id);
2825 case 111: return inf_unimplemented(pkt, id);
2826 case 112: return inf_unimplemented(pkt, id);
2827 case 113: return inf_unimplemented(pkt, id);
2828 case 114: return inf_unimplemented(pkt, id);
2829 case 115: return inf_unimplemented(pkt, id);
2830 case 116: return inf_unimplemented(pkt, id);
2831 case 117: return inf_unimplemented(pkt, id);
2832 case 118: return inf_unimplemented(pkt, id);
2833 case 119: return inf_unimplemented(pkt, id);
2834 case 120: return inf_unimplemented(pkt, id);
2835 case 121: return inf_unimplemented(pkt, id);
2836 case 122: return inf_unimplemented(pkt, id);
2837 case 123: return inf_unimplemented(pkt, id);
2838 case 124: return inf_unimplemented(pkt, id);
2839 case 125: return inf_unimplemented(pkt, id);
2840 case 126: return inf_unimplemented(pkt, id);
2841 case 127: return inf_unimplemented(pkt, id);
2842 case 128: return inf_reserved(pkt, id);
2843 case 129: return inf_reserved(pkt, id);
2844 case 130: return inf_unimplemented(pkt, id);
2845 case 131: return inf_unimplemented(pkt, id);
2846 case 132: return inf_unimplemented(pkt, id);
2847 case 133: return inf_reserved(pkt, id);
2848 case 134: return inf_reserved(pkt, id);
2849 case 135: return inf_reserved(pkt, id);
2850 case 136: return inf_reserved(pkt, id);
2851 case 137: return inf_unimplemented(pkt, id);
2852 case 138: return inf_unimplemented(pkt, id);
2853 case 139: return inf_unimplemented(pkt, id);
2854 case 140: return inf_unimplemented(pkt, id);
2855 case 141: return inf_unimplemented(pkt, id);
2856 case 142: return inf_unimplemented(pkt, id);
2857 case 143 ... 173: return inf_reserved(pkt, id);
2858 case 174: return inf_unimplemented(pkt, id);
2859 case 221: return inf_vend_spec(pkt, id);
2862 return 0;
2865 #define ESS 0x0001
2866 #define IBSS 0x0002
2867 #define CF_Pollable 0x0004
2868 #define CF_Poll_Req 0x0008
2869 #define Privacy 0x0010
2870 #define Short_Pre 0x0020
2871 #define PBCC 0x0040
2872 #define Ch_Agility 0x0080
2873 #define Spec_Mgmt 0x0100
2874 #define QoS 0x0200
2875 #define Short_Slot_t 0x0400
2876 #define APSD 0x0800
2877 #define Radio_Meas 0x1000
2878 #define DSSS_OFDM 0x2000
2879 #define Del_Block_ACK 0x4000
2880 #define Imm_Block_ACK 0x8000
2882 static int8_t cap_field(u16 cap_inf)
2884 if (ESS & cap_inf)
2885 tprintf(" ESS;");
2886 if (IBSS & cap_inf)
2887 tprintf(" IBSS;");
2888 if (CF_Pollable & cap_inf)
2889 tprintf(" CF Pollable;");
2890 if (CF_Poll_Req & cap_inf)
2891 tprintf(" CF-Poll Request;");
2892 if (Privacy & cap_inf)
2893 tprintf(" Privacy;");
2894 if (Short_Pre & cap_inf)
2895 tprintf(" Short Preamble;");
2896 if (PBCC & cap_inf)
2897 tprintf(" PBCC;");
2898 if (Ch_Agility & cap_inf)
2899 tprintf(" Channel Agility;");
2900 if (Spec_Mgmt & cap_inf)
2901 tprintf(" Spectrum Management;");
2902 if (QoS & cap_inf)
2903 tprintf(" QoS;");
2904 if (Short_Slot_t & cap_inf)
2905 tprintf(" Short Slot Time;");
2906 if (APSD & cap_inf)
2907 tprintf(" APSD;");
2908 if (Radio_Meas & cap_inf)
2909 tprintf(" Radio Measurement;");
2910 if (DSSS_OFDM & cap_inf)
2911 tprintf(" DSSS-OFDM;");
2912 if (Del_Block_ACK & cap_inf)
2913 tprintf(" Delayed Block Ack;");
2914 if (Imm_Block_ACK & cap_inf)
2915 tprintf(" Immediate Block Ack;");
2917 return 1;
2920 /* Management Dissectors */
2921 static int8_t beacon(struct pkt_buff *pkt)
2923 struct ieee80211_mgmt_beacon *beacon;
2925 beacon = (struct ieee80211_mgmt_beacon *)
2926 pkt_pull(pkt, sizeof(*beacon));
2927 if (beacon == NULL)
2928 return 0;
2930 tprintf("Timestamp 0x%.16"PRIx64", ", le64_to_cpu(beacon->timestamp));
2931 tprintf("Beacon Interval (%fs), ", le16_to_cpu(beacon->beacon_int)*TU);
2932 tprintf("Capabilities (0x%x <->", le16_to_cpu(beacon->capab_info));
2933 cap_field(le16_to_cpu(beacon->capab_info));
2934 tprintf(")");
2936 if(pkt_len(pkt)) {
2937 tprintf("\n\tParameters:");
2938 while (inf_elements(pkt)) {
2939 tprintf("\n\t");
2943 if(pkt_len(pkt))
2944 return 0;
2945 return 1;
2948 static int8_t mgmt_unimplemented(struct pkt_buff *pkt __maybe_unused)
2950 return 0;
2952 /* End Management Dissectors */
2954 /* Control Dissectors */
2955 static int8_t ctrl_unimplemented(struct pkt_buff *pkt __maybe_unused)
2957 return 0;
2959 /* End Control Dissectors */
2961 /* Data Dissectors */
2962 static int8_t data_unimplemented(struct pkt_buff *pkt __maybe_unused)
2964 return 0;
2966 /* End Data Dissectors */
2968 static const char *mgt_sub(u8 subtype, struct pkt_buff *pkt,
2969 int8_t (**get_content)(struct pkt_buff *pkt))
2971 u16 seq_ctrl;
2972 struct ieee80211_mgmt *mgmt;
2973 const char *dst, *src, *bssid;
2975 mgmt = (struct ieee80211_mgmt *) pkt_pull(pkt, sizeof(*mgmt));
2976 if (!mgmt)
2977 return NULL;
2979 dst = lookup_vendor((mgmt->da[0] << 16) |
2980 (mgmt->da[1] << 8) |
2981 mgmt->da[2]);
2982 src = lookup_vendor((mgmt->sa[0] << 16) |
2983 (mgmt->sa[1] << 8) |
2984 mgmt->sa[2]);
2986 bssid = lookup_vendor((mgmt->bssid[0] << 16) |
2987 (mgmt->bssid[1] << 8) |
2988 mgmt->bssid[2]);
2989 seq_ctrl = le16_to_cpu(mgmt->seq_ctrl);
2991 tprintf("Duration (%u),", le16_to_cpu(mgmt->duration));
2992 tprintf("\n\tDestination (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
2993 mgmt->da[0], mgmt->da[1], mgmt->da[2],
2994 mgmt->da[3], mgmt->da[4], mgmt->da[5]);
2995 if (dst) {
2996 tprintf("=> (%s:%.2x:%.2x:%.2x)", dst,
2997 mgmt->da[3], mgmt->da[4], mgmt->da[5]);
3000 tprintf("\n\tSource (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
3001 mgmt->sa[0], mgmt->sa[1], mgmt->sa[2],
3002 mgmt->sa[3], mgmt->sa[4], mgmt->sa[5]);
3003 if (src) {
3004 tprintf("=> (%s:%.2x:%.2x:%.2x)", src,
3005 mgmt->sa[3], mgmt->sa[4], mgmt->sa[5]);
3008 tprintf("\n\tBSSID (%.2x:%.2x:%.2x:%.2x:%.2x:%.2x) ",
3009 mgmt->bssid[0], mgmt->bssid[1], mgmt->bssid[2],
3010 mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5]);
3011 if(bssid) {
3012 tprintf("=> (%s:%.2x:%.2x:%.2x)", bssid,
3013 mgmt->bssid[3], mgmt->bssid[4], mgmt->bssid[5]);
3016 tprintf("\n\tFragmentnr. (%u), Seqnr. (%u). ",
3017 seq_ctrl & 0xf, seq_ctrl >> 4);
3019 switch (subtype) {
3020 case 0x0:
3021 *get_content = mgmt_unimplemented;
3022 return "Association Request";
3023 case 0x1:
3024 *get_content = mgmt_unimplemented;
3025 return "Association Response";
3026 case 0x2:
3027 *get_content = mgmt_unimplemented;
3028 return "Reassociation Request";
3029 case 0x3:
3030 *get_content = mgmt_unimplemented;
3031 return "Reassociation Response";
3032 case 0x4:
3033 *get_content = mgmt_unimplemented;
3034 return "Probe Request";
3035 case 0x5:
3036 *get_content = mgmt_unimplemented;
3037 return "Probe Response";
3038 case 0x8:
3039 *get_content = beacon;
3040 return "Beacon";
3041 case 0x9:
3042 *get_content = mgmt_unimplemented;
3043 return "ATIM";
3044 case 0xA:
3045 *get_content = mgmt_unimplemented;
3046 return "Disassociation";
3047 case 0xB:
3048 *get_content = mgmt_unimplemented;
3049 return "Authentication";
3050 case 0xC:
3051 *get_content = mgmt_unimplemented;
3052 return "Deauthentication";
3053 default:
3054 *get_content = NULL;
3055 return "Reserved";
3059 static const char *ctrl_sub(u8 subtype, struct pkt_buff *pkt __maybe_unused,
3060 int8_t (**get_content)(struct pkt_buff *pkt))
3062 switch (subtype) {
3063 case 0xA:
3064 *get_content = ctrl_unimplemented;
3065 return "PS-Poll";
3066 case 0xB:
3067 *get_content = ctrl_unimplemented;
3068 return "RTS";
3069 case 0xC:
3070 *get_content = ctrl_unimplemented;
3071 return "CTS";
3072 case 0xD:
3073 *get_content = ctrl_unimplemented;
3074 return "ACK";
3075 case 0xE:
3076 *get_content = ctrl_unimplemented;
3077 return "CF End";
3078 case 0xF:
3079 *get_content = ctrl_unimplemented;
3080 return "CF End + CF-ACK";
3081 default:
3082 *get_content = NULL;
3083 return "Reserved";
3087 static const char *data_sub(u8 subtype, struct pkt_buff *pkt __maybe_unused,
3088 int8_t (**get_content)(struct pkt_buff *pkt))
3090 switch (subtype) {
3091 case 0x0:
3092 *get_content = data_unimplemented;
3093 return "Data";
3094 case 0x1:
3095 *get_content = data_unimplemented;
3096 return "Data + CF-ACK";
3097 case 0x2:
3098 *get_content = data_unimplemented;
3099 return "Data + CF-Poll";
3100 case 0x3:
3101 *get_content = data_unimplemented;
3102 return "Data + CF-ACK + CF-Poll";
3103 case 0x4:
3104 *get_content = data_unimplemented;
3105 return "Null";
3106 case 0x5:
3107 *get_content = data_unimplemented;
3108 return "CF-ACK";
3109 case 0x6:
3110 *get_content = data_unimplemented;
3111 return "CF-Poll";
3112 case 0x7:
3113 *get_content = data_unimplemented;
3114 return "CF-ACK + CF-Poll";
3115 default:
3116 *get_content = NULL;
3117 return "Reserved";
3121 static const char *
3122 frame_control_type(u8 type, const char *(**get_subtype)(u8 subtype,
3123 struct pkt_buff *pkt, int8_t (**get_content)(struct pkt_buff *pkt)))
3125 switch (type) {
3126 case 0x0:
3127 *get_subtype = mgt_sub;
3128 return "Management";
3129 case 0x1:
3130 *get_subtype = ctrl_sub;
3131 return "Control";
3132 case 0x2:
3133 *get_subtype = data_sub;
3134 return "Data";
3135 case 0x3:
3136 *get_subtype = NULL;
3137 return "Reserved";
3138 default:
3139 *get_subtype = NULL;
3140 return "Control Type unknown";
3144 static void ieee80211(struct pkt_buff *pkt)
3146 int8_t (*get_content)(struct pkt_buff *pkt) = NULL;
3147 const char *(*get_subtype)(u8 subtype, struct pkt_buff *pkt,
3148 int8_t (**get_content)(struct pkt_buff *pkt)) = NULL;
3149 const char *subtype = NULL;
3150 struct ieee80211_frm_ctrl *frm_ctrl;
3152 if (pkt->link_type == LINKTYPE_IEEE802_11_RADIOTAP) {
3153 struct ieee80211_radiotap_header *rtap;
3155 rtap = (struct ieee80211_radiotap_header *)pkt_pull(pkt,
3156 sizeof(*rtap));
3157 if (rtap == NULL)
3158 return;
3160 tprintf(" [ Radiotap ");
3161 tprintf("Version (%u), ", rtap->version);
3162 tprintf("Length (%u), ", le16_to_cpu(rtap->len));
3163 tprintf("Flags (0x%08x) ]\n", le32_to_cpu(rtap->present));
3165 pkt_pull(pkt, le16_to_cpu(rtap->len) - sizeof(*rtap));
3168 frm_ctrl = (struct ieee80211_frm_ctrl *)pkt_pull(pkt, sizeof(*frm_ctrl));
3169 if (frm_ctrl == NULL)
3170 return;
3172 tprintf(" [ 802.11 Frame Control (0x%04x)]\n",
3173 le16_to_cpu(frm_ctrl->frame_control));
3175 tprintf(" [ Proto Version (%u), ", frm_ctrl->proto_version);
3176 tprintf("Type (%u, %s), ", frm_ctrl->type,
3177 frame_control_type(frm_ctrl->type, &get_subtype));
3178 if (get_subtype) {
3179 subtype = (*get_subtype)(frm_ctrl->subtype, pkt, &get_content);
3180 tprintf("Subtype (%u, %s)", frm_ctrl->subtype, subtype);
3181 } else {
3182 tprintf("%s%s%s", colorize_start_full(black, red),
3183 "No SubType Data available", colorize_end());
3186 tprintf("%s%s", frm_ctrl->to_ds ? ", Frame goes to DS" : "",
3187 frm_ctrl->from_ds ? ", Frame comes from DS" : "");
3188 tprintf("%s", frm_ctrl->more_frags ? ", More Fragments" : "");
3189 tprintf("%s", frm_ctrl->retry ? ", Frame is retransmitted" : "");
3190 tprintf("%s", frm_ctrl->power_mgmt ? ", In Power Saving Mode" : "");
3191 tprintf("%s", frm_ctrl->more_data ? ", More Data" : "");
3192 tprintf("%s", frm_ctrl->wep ? ", Needs WEP" : "");
3193 tprintf("%s", frm_ctrl->order ? ", Order" : "");
3194 tprintf(" ]\n");
3196 if (get_content) {
3197 tprintf(" [ Subtype %s: ", subtype);
3198 if (!((*get_content) (pkt)))
3199 tprintf("%s%s%s", colorize_start_full(black, red),
3200 "Failed to dissect Subtype", colorize_end());
3201 tprintf(" ]");
3202 } else {
3203 tprintf("%s%s%s", colorize_start_full(black, red),
3204 "No SubType Data available", colorize_end());
3207 tprintf("\n");
3209 // pkt_set_proto(pkt, &ieee802_lay2, ntohs(eth->h_proto));
3212 static void ieee80211_less(struct pkt_buff *pkt __maybe_unused)
3214 tprintf("802.11 frame (more on todo)");
3217 struct protocol ieee80211_ops = {
3218 .key = 0,
3219 .print_full = ieee80211,
3220 .print_less = ieee80211_less,