13ff40c12SJohn Marino /*
23ff40c12SJohn Marino * Radiotap parser
33ff40c12SJohn Marino *
43ff40c12SJohn Marino * Copyright 2007 Andy Green <andy@warmcat.com>
5*a1157835SDaniel Fojt * Copyright 2009 Johannes Berg <johannes@sipsolutions.net>
63ff40c12SJohn Marino *
73ff40c12SJohn Marino * This program is free software; you can redistribute it and/or modify
83ff40c12SJohn Marino * it under the terms of the GNU General Public License version 2 as
93ff40c12SJohn Marino * published by the Free Software Foundation.
103ff40c12SJohn Marino *
113ff40c12SJohn Marino * Alternatively, this software may be distributed under the terms of BSD
123ff40c12SJohn Marino * license.
133ff40c12SJohn Marino *
14*a1157835SDaniel Fojt * See COPYING for more details.
153ff40c12SJohn Marino */
16*a1157835SDaniel Fojt #include "platform.h"
173ff40c12SJohn Marino #include "radiotap_iter.h"
183ff40c12SJohn Marino
193ff40c12SJohn Marino /* function prototypes and related defs are in radiotap_iter.h */
203ff40c12SJohn Marino
21*a1157835SDaniel Fojt static const struct radiotap_align_size rtap_namespace_sizes[] = {
22*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_TSFT] = { .align = 8, .size = 8, },
23*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_FLAGS] = { .align = 1, .size = 1, },
24*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_RATE] = { .align = 1, .size = 1, },
25*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_CHANNEL] = { .align = 2, .size = 4, },
26*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_FHSS] = { .align = 2, .size = 2, },
27*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = { .align = 1, .size = 1, },
28*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_DBM_ANTNOISE] = { .align = 1, .size = 1, },
29*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_LOCK_QUALITY] = { .align = 2, .size = 2, },
30*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_TX_ATTENUATION] = { .align = 2, .size = 2, },
31*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = { .align = 2, .size = 2, },
32*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_DBM_TX_POWER] = { .align = 1, .size = 1, },
33*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_ANTENNA] = { .align = 1, .size = 1, },
34*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = { .align = 1, .size = 1, },
35*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_DB_ANTNOISE] = { .align = 1, .size = 1, },
36*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_RX_FLAGS] = { .align = 2, .size = 2, },
37*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_TX_FLAGS] = { .align = 2, .size = 2, },
38*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_RTS_RETRIES] = { .align = 1, .size = 1, },
39*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_DATA_RETRIES] = { .align = 1, .size = 1, },
40*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_MCS] = { .align = 1, .size = 3, },
41*a1157835SDaniel Fojt [IEEE80211_RADIOTAP_AMPDU_STATUS] = { .align = 4, .size = 8, },
42*a1157835SDaniel Fojt /*
43*a1157835SDaniel Fojt * add more here as they are defined in radiotap.h
44*a1157835SDaniel Fojt */
45*a1157835SDaniel Fojt };
46*a1157835SDaniel Fojt
47*a1157835SDaniel Fojt static const struct ieee80211_radiotap_namespace radiotap_ns = {
48*a1157835SDaniel Fojt .n_bits = sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]),
49*a1157835SDaniel Fojt .align_size = rtap_namespace_sizes,
50*a1157835SDaniel Fojt };
51*a1157835SDaniel Fojt
523ff40c12SJohn Marino /**
533ff40c12SJohn Marino * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization
543ff40c12SJohn Marino * @iterator: radiotap_iterator to initialize
553ff40c12SJohn Marino * @radiotap_header: radiotap header to parse
563ff40c12SJohn Marino * @max_length: total length we can parse into (eg, whole packet length)
573ff40c12SJohn Marino *
583ff40c12SJohn Marino * Returns: 0 or a negative error code if there is a problem.
593ff40c12SJohn Marino *
603ff40c12SJohn Marino * This function initializes an opaque iterator struct which can then
613ff40c12SJohn Marino * be passed to ieee80211_radiotap_iterator_next() to visit every radiotap
623ff40c12SJohn Marino * argument which is present in the header. It knows about extended
633ff40c12SJohn Marino * present headers and handles them.
643ff40c12SJohn Marino *
653ff40c12SJohn Marino * How to use:
663ff40c12SJohn Marino * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator
673ff40c12SJohn Marino * struct ieee80211_radiotap_iterator (no need to init the struct beforehand)
683ff40c12SJohn Marino * checking for a good 0 return code. Then loop calling
693ff40c12SJohn Marino * __ieee80211_radiotap_iterator_next()... it returns either 0,
703ff40c12SJohn Marino * -ENOENT if there are no more args to parse, or -EINVAL if there is a problem.
713ff40c12SJohn Marino * The iterator's @this_arg member points to the start of the argument
723ff40c12SJohn Marino * associated with the current argument index that is present, which can be
733ff40c12SJohn Marino * found in the iterator's @this_arg_index member. This arg index corresponds
743ff40c12SJohn Marino * to the IEEE80211_RADIOTAP_... defines.
753ff40c12SJohn Marino *
763ff40c12SJohn Marino * Radiotap header length:
773ff40c12SJohn Marino * You can find the CPU-endian total radiotap header length in
783ff40c12SJohn Marino * iterator->max_length after executing ieee80211_radiotap_iterator_init()
793ff40c12SJohn Marino * successfully.
803ff40c12SJohn Marino *
813ff40c12SJohn Marino * Alignment Gotcha:
823ff40c12SJohn Marino * You must take care when dereferencing iterator.this_arg
833ff40c12SJohn Marino * for multibyte types... the pointer is not aligned. Use
843ff40c12SJohn Marino * get_unaligned((type *)iterator.this_arg) to dereference
853ff40c12SJohn Marino * iterator.this_arg for type "type" safely on all arches.
863ff40c12SJohn Marino *
87*a1157835SDaniel Fojt * Example code: parse.c
883ff40c12SJohn Marino */
893ff40c12SJohn Marino
ieee80211_radiotap_iterator_init(struct ieee80211_radiotap_iterator * iterator,struct ieee80211_radiotap_header * radiotap_header,int max_length,const struct ieee80211_radiotap_vendor_namespaces * vns)903ff40c12SJohn Marino int ieee80211_radiotap_iterator_init(
913ff40c12SJohn Marino struct ieee80211_radiotap_iterator *iterator,
923ff40c12SJohn Marino struct ieee80211_radiotap_header *radiotap_header,
93*a1157835SDaniel Fojt int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns)
943ff40c12SJohn Marino {
95*a1157835SDaniel Fojt /* must at least have the radiotap header */
96*a1157835SDaniel Fojt if (max_length < (int)sizeof(struct ieee80211_radiotap_header))
97*a1157835SDaniel Fojt return -EINVAL;
98*a1157835SDaniel Fojt
993ff40c12SJohn Marino /* Linux only supports version 0 radiotap format */
1003ff40c12SJohn Marino if (radiotap_header->it_version)
1013ff40c12SJohn Marino return -EINVAL;
1023ff40c12SJohn Marino
1033ff40c12SJohn Marino /* sanity check for allowed length and radiotap length field */
104*a1157835SDaniel Fojt if (max_length < get_unaligned_le16(&radiotap_header->it_len))
1053ff40c12SJohn Marino return -EINVAL;
1063ff40c12SJohn Marino
107*a1157835SDaniel Fojt iterator->_rtheader = radiotap_header;
108*a1157835SDaniel Fojt iterator->_max_length = get_unaligned_le16(&radiotap_header->it_len);
109*a1157835SDaniel Fojt iterator->_arg_index = 0;
110*a1157835SDaniel Fojt iterator->_bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present);
111*a1157835SDaniel Fojt iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header);
112*a1157835SDaniel Fojt iterator->_next_ns_data = NULL;
113*a1157835SDaniel Fojt iterator->_reset_on_ext = 0;
114*a1157835SDaniel Fojt iterator->_next_bitmap = &radiotap_header->it_present;
115*a1157835SDaniel Fojt iterator->_next_bitmap++;
116*a1157835SDaniel Fojt iterator->_vns = vns;
117*a1157835SDaniel Fojt iterator->current_namespace = &radiotap_ns;
118*a1157835SDaniel Fojt iterator->is_radiotap_ns = 1;
119*a1157835SDaniel Fojt #ifdef RADIOTAP_SUPPORT_OVERRIDES
120*a1157835SDaniel Fojt iterator->n_overrides = 0;
121*a1157835SDaniel Fojt iterator->overrides = NULL;
122*a1157835SDaniel Fojt #endif
1233ff40c12SJohn Marino
1243ff40c12SJohn Marino /* find payload start allowing for extended bitmap(s) */
1253ff40c12SJohn Marino
126*a1157835SDaniel Fojt if (iterator->_bitmap_shifter & BIT(IEEE80211_RADIOTAP_EXT)) {
127*a1157835SDaniel Fojt if ((unsigned long)iterator->_arg -
128*a1157835SDaniel Fojt (unsigned long)iterator->_rtheader + sizeof(uint32_t) >
129*a1157835SDaniel Fojt (unsigned long)iterator->_max_length)
130*a1157835SDaniel Fojt return -EINVAL;
131*a1157835SDaniel Fojt while (get_unaligned_le32(iterator->_arg) &
132*a1157835SDaniel Fojt BIT(IEEE80211_RADIOTAP_EXT)) {
133*a1157835SDaniel Fojt iterator->_arg += sizeof(uint32_t);
1343ff40c12SJohn Marino
1353ff40c12SJohn Marino /*
1363ff40c12SJohn Marino * check for insanity where the present bitmaps
1373ff40c12SJohn Marino * keep claiming to extend up to or even beyond the
1383ff40c12SJohn Marino * stated radiotap header length
1393ff40c12SJohn Marino */
1403ff40c12SJohn Marino
141*a1157835SDaniel Fojt if ((unsigned long)iterator->_arg -
142*a1157835SDaniel Fojt (unsigned long)iterator->_rtheader +
143*a1157835SDaniel Fojt sizeof(uint32_t) >
144*a1157835SDaniel Fojt (unsigned long)iterator->_max_length)
1453ff40c12SJohn Marino return -EINVAL;
1463ff40c12SJohn Marino }
1473ff40c12SJohn Marino
148*a1157835SDaniel Fojt iterator->_arg += sizeof(uint32_t);
1493ff40c12SJohn Marino
1503ff40c12SJohn Marino /*
1513ff40c12SJohn Marino * no need to check again for blowing past stated radiotap
1523ff40c12SJohn Marino * header length, because ieee80211_radiotap_iterator_next
1533ff40c12SJohn Marino * checks it before it is dereferenced
1543ff40c12SJohn Marino */
1553ff40c12SJohn Marino }
1563ff40c12SJohn Marino
157*a1157835SDaniel Fojt iterator->this_arg = iterator->_arg;
158*a1157835SDaniel Fojt iterator->this_arg_index = 0;
159*a1157835SDaniel Fojt iterator->this_arg_size = 0;
160*a1157835SDaniel Fojt
1613ff40c12SJohn Marino /* we are all initialized happily */
1623ff40c12SJohn Marino
1633ff40c12SJohn Marino return 0;
1643ff40c12SJohn Marino }
1653ff40c12SJohn Marino
find_ns(struct ieee80211_radiotap_iterator * iterator,uint32_t oui,uint8_t subns)166*a1157835SDaniel Fojt static void find_ns(struct ieee80211_radiotap_iterator *iterator,
167*a1157835SDaniel Fojt uint32_t oui, uint8_t subns)
168*a1157835SDaniel Fojt {
169*a1157835SDaniel Fojt int i;
170*a1157835SDaniel Fojt
171*a1157835SDaniel Fojt iterator->current_namespace = NULL;
172*a1157835SDaniel Fojt
173*a1157835SDaniel Fojt if (!iterator->_vns)
174*a1157835SDaniel Fojt return;
175*a1157835SDaniel Fojt
176*a1157835SDaniel Fojt for (i = 0; i < iterator->_vns->n_ns; i++) {
177*a1157835SDaniel Fojt if (iterator->_vns->ns[i].oui != oui)
178*a1157835SDaniel Fojt continue;
179*a1157835SDaniel Fojt if (iterator->_vns->ns[i].subns != subns)
180*a1157835SDaniel Fojt continue;
181*a1157835SDaniel Fojt
182*a1157835SDaniel Fojt iterator->current_namespace = &iterator->_vns->ns[i];
183*a1157835SDaniel Fojt break;
184*a1157835SDaniel Fojt }
185*a1157835SDaniel Fojt }
186*a1157835SDaniel Fojt
187*a1157835SDaniel Fojt #ifdef RADIOTAP_SUPPORT_OVERRIDES
find_override(struct ieee80211_radiotap_iterator * iterator,int * align,int * size)188*a1157835SDaniel Fojt static int find_override(struct ieee80211_radiotap_iterator *iterator,
189*a1157835SDaniel Fojt int *align, int *size)
190*a1157835SDaniel Fojt {
191*a1157835SDaniel Fojt int i;
192*a1157835SDaniel Fojt
193*a1157835SDaniel Fojt if (!iterator->overrides)
194*a1157835SDaniel Fojt return 0;
195*a1157835SDaniel Fojt
196*a1157835SDaniel Fojt for (i = 0; i < iterator->n_overrides; i++) {
197*a1157835SDaniel Fojt if (iterator->_arg_index == iterator->overrides[i].field) {
198*a1157835SDaniel Fojt *align = iterator->overrides[i].align;
199*a1157835SDaniel Fojt *size = iterator->overrides[i].size;
200*a1157835SDaniel Fojt if (!*align) /* erroneous override */
201*a1157835SDaniel Fojt return 0;
202*a1157835SDaniel Fojt return 1;
203*a1157835SDaniel Fojt }
204*a1157835SDaniel Fojt }
205*a1157835SDaniel Fojt
206*a1157835SDaniel Fojt return 0;
207*a1157835SDaniel Fojt }
208*a1157835SDaniel Fojt #endif
209*a1157835SDaniel Fojt
2103ff40c12SJohn Marino
2113ff40c12SJohn Marino /**
2123ff40c12SJohn Marino * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg
2133ff40c12SJohn Marino * @iterator: radiotap_iterator to move to next arg (if any)
2143ff40c12SJohn Marino *
2153ff40c12SJohn Marino * Returns: 0 if there is an argument to handle,
2163ff40c12SJohn Marino * -ENOENT if there are no more args or -EINVAL
2173ff40c12SJohn Marino * if there is something else wrong.
2183ff40c12SJohn Marino *
2193ff40c12SJohn Marino * This function provides the next radiotap arg index (IEEE80211_RADIOTAP_*)
2203ff40c12SJohn Marino * in @this_arg_index and sets @this_arg to point to the
2213ff40c12SJohn Marino * payload for the field. It takes care of alignment handling and extended
2223ff40c12SJohn Marino * present fields. @this_arg can be changed by the caller (eg,
2233ff40c12SJohn Marino * incremented to move inside a compound argument like
2243ff40c12SJohn Marino * IEEE80211_RADIOTAP_CHANNEL). The args pointed to are in
2253ff40c12SJohn Marino * little-endian format whatever the endianess of your CPU.
2263ff40c12SJohn Marino *
2273ff40c12SJohn Marino * Alignment Gotcha:
2283ff40c12SJohn Marino * You must take care when dereferencing iterator.this_arg
2293ff40c12SJohn Marino * for multibyte types... the pointer is not aligned. Use
2303ff40c12SJohn Marino * get_unaligned((type *)iterator.this_arg) to dereference
2313ff40c12SJohn Marino * iterator.this_arg for type "type" safely on all arches.
2323ff40c12SJohn Marino */
2333ff40c12SJohn Marino
ieee80211_radiotap_iterator_next(struct ieee80211_radiotap_iterator * iterator)2343ff40c12SJohn Marino int ieee80211_radiotap_iterator_next(
2353ff40c12SJohn Marino struct ieee80211_radiotap_iterator *iterator)
2363ff40c12SJohn Marino {
237*a1157835SDaniel Fojt while (1) {
2383ff40c12SJohn Marino int hit = 0;
239*a1157835SDaniel Fojt int pad, align, size, subns;
240*a1157835SDaniel Fojt uint32_t oui;
2413ff40c12SJohn Marino
242*a1157835SDaniel Fojt /* if no more EXT bits, that's it */
243*a1157835SDaniel Fojt if ((iterator->_arg_index % 32) == IEEE80211_RADIOTAP_EXT &&
244*a1157835SDaniel Fojt !(iterator->_bitmap_shifter & 1))
245*a1157835SDaniel Fojt return -ENOENT;
246*a1157835SDaniel Fojt
247*a1157835SDaniel Fojt if (!(iterator->_bitmap_shifter & 1))
2483ff40c12SJohn Marino goto next_entry; /* arg not present */
2493ff40c12SJohn Marino
250*a1157835SDaniel Fojt /* get alignment/size of data */
251*a1157835SDaniel Fojt switch (iterator->_arg_index % 32) {
252*a1157835SDaniel Fojt case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE:
253*a1157835SDaniel Fojt case IEEE80211_RADIOTAP_EXT:
254*a1157835SDaniel Fojt align = 1;
255*a1157835SDaniel Fojt size = 0;
256*a1157835SDaniel Fojt break;
257*a1157835SDaniel Fojt case IEEE80211_RADIOTAP_VENDOR_NAMESPACE:
258*a1157835SDaniel Fojt align = 2;
259*a1157835SDaniel Fojt size = 6;
260*a1157835SDaniel Fojt break;
261*a1157835SDaniel Fojt default:
262*a1157835SDaniel Fojt #ifdef RADIOTAP_SUPPORT_OVERRIDES
263*a1157835SDaniel Fojt if (find_override(iterator, &align, &size)) {
264*a1157835SDaniel Fojt /* all set */
265*a1157835SDaniel Fojt } else
266*a1157835SDaniel Fojt #endif
267*a1157835SDaniel Fojt if (!iterator->current_namespace ||
268*a1157835SDaniel Fojt iterator->_arg_index >= iterator->current_namespace->n_bits) {
269*a1157835SDaniel Fojt if (iterator->current_namespace == &radiotap_ns)
270*a1157835SDaniel Fojt return -ENOENT;
271*a1157835SDaniel Fojt align = 0;
272*a1157835SDaniel Fojt } else {
273*a1157835SDaniel Fojt align = iterator->current_namespace->align_size[iterator->_arg_index].align;
274*a1157835SDaniel Fojt size = iterator->current_namespace->align_size[iterator->_arg_index].size;
275*a1157835SDaniel Fojt }
276*a1157835SDaniel Fojt if (!align) {
277*a1157835SDaniel Fojt /* skip all subsequent data */
278*a1157835SDaniel Fojt iterator->_arg = iterator->_next_ns_data;
279*a1157835SDaniel Fojt /* give up on this namespace */
280*a1157835SDaniel Fojt iterator->current_namespace = NULL;
281*a1157835SDaniel Fojt goto next_entry;
282*a1157835SDaniel Fojt }
283*a1157835SDaniel Fojt break;
284*a1157835SDaniel Fojt }
285*a1157835SDaniel Fojt
2863ff40c12SJohn Marino /*
2873ff40c12SJohn Marino * arg is present, account for alignment padding
2883ff40c12SJohn Marino *
289*a1157835SDaniel Fojt * Note that these alignments are relative to the start
290*a1157835SDaniel Fojt * of the radiotap header. There is no guarantee
2913ff40c12SJohn Marino * that the radiotap header itself is aligned on any
2923ff40c12SJohn Marino * kind of boundary.
2933ff40c12SJohn Marino *
294*a1157835SDaniel Fojt * The above is why get_unaligned() is used to dereference
295*a1157835SDaniel Fojt * multibyte elements from the radiotap area.
2963ff40c12SJohn Marino */
2973ff40c12SJohn Marino
298*a1157835SDaniel Fojt pad = ((unsigned long)iterator->_arg -
299*a1157835SDaniel Fojt (unsigned long)iterator->_rtheader) & (align - 1);
3003ff40c12SJohn Marino
3013ff40c12SJohn Marino if (pad)
302*a1157835SDaniel Fojt iterator->_arg += align - pad;
303*a1157835SDaniel Fojt
304*a1157835SDaniel Fojt if (iterator->_arg_index % 32 == IEEE80211_RADIOTAP_VENDOR_NAMESPACE) {
305*a1157835SDaniel Fojt int vnslen;
306*a1157835SDaniel Fojt
307*a1157835SDaniel Fojt if ((unsigned long)iterator->_arg + size -
308*a1157835SDaniel Fojt (unsigned long)iterator->_rtheader >
309*a1157835SDaniel Fojt (unsigned long)iterator->_max_length)
310*a1157835SDaniel Fojt return -EINVAL;
311*a1157835SDaniel Fojt
312*a1157835SDaniel Fojt oui = (*iterator->_arg << 16) |
313*a1157835SDaniel Fojt (*(iterator->_arg + 1) << 8) |
314*a1157835SDaniel Fojt *(iterator->_arg + 2);
315*a1157835SDaniel Fojt subns = *(iterator->_arg + 3);
316*a1157835SDaniel Fojt
317*a1157835SDaniel Fojt find_ns(iterator, oui, subns);
318*a1157835SDaniel Fojt
319*a1157835SDaniel Fojt vnslen = get_unaligned_le16(iterator->_arg + 4);
320*a1157835SDaniel Fojt iterator->_next_ns_data = iterator->_arg + size + vnslen;
321*a1157835SDaniel Fojt if (!iterator->current_namespace)
322*a1157835SDaniel Fojt size += vnslen;
323*a1157835SDaniel Fojt }
3243ff40c12SJohn Marino
3253ff40c12SJohn Marino /*
3263ff40c12SJohn Marino * this is what we will return to user, but we need to
3273ff40c12SJohn Marino * move on first so next call has something fresh to test
3283ff40c12SJohn Marino */
329*a1157835SDaniel Fojt iterator->this_arg_index = iterator->_arg_index;
330*a1157835SDaniel Fojt iterator->this_arg = iterator->_arg;
331*a1157835SDaniel Fojt iterator->this_arg_size = size;
3323ff40c12SJohn Marino
3333ff40c12SJohn Marino /* internally move on the size of this arg */
334*a1157835SDaniel Fojt iterator->_arg += size;
3353ff40c12SJohn Marino
3363ff40c12SJohn Marino /*
3373ff40c12SJohn Marino * check for insanity where we are given a bitmap that
3383ff40c12SJohn Marino * claims to have more arg content than the length of the
3393ff40c12SJohn Marino * radiotap section. We will normally end up equalling this
3403ff40c12SJohn Marino * max_length on the last arg, never exceeding it.
3413ff40c12SJohn Marino */
3423ff40c12SJohn Marino
343*a1157835SDaniel Fojt if ((unsigned long)iterator->_arg -
344*a1157835SDaniel Fojt (unsigned long)iterator->_rtheader >
345*a1157835SDaniel Fojt (unsigned long)iterator->_max_length)
3463ff40c12SJohn Marino return -EINVAL;
3473ff40c12SJohn Marino
348*a1157835SDaniel Fojt /* these special ones are valid in each bitmap word */
349*a1157835SDaniel Fojt switch (iterator->_arg_index % 32) {
350*a1157835SDaniel Fojt case IEEE80211_RADIOTAP_VENDOR_NAMESPACE:
351*a1157835SDaniel Fojt iterator->_reset_on_ext = 1;
352*a1157835SDaniel Fojt
353*a1157835SDaniel Fojt iterator->is_radiotap_ns = 0;
354*a1157835SDaniel Fojt /*
355*a1157835SDaniel Fojt * If parser didn't register this vendor
356*a1157835SDaniel Fojt * namespace with us, allow it to show it
357*a1157835SDaniel Fojt * as 'raw. Do do that, set argument index
358*a1157835SDaniel Fojt * to vendor namespace.
359*a1157835SDaniel Fojt */
360*a1157835SDaniel Fojt iterator->this_arg_index =
361*a1157835SDaniel Fojt IEEE80211_RADIOTAP_VENDOR_NAMESPACE;
362*a1157835SDaniel Fojt if (!iterator->current_namespace)
363*a1157835SDaniel Fojt hit = 1;
364*a1157835SDaniel Fojt goto next_entry;
365*a1157835SDaniel Fojt case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE:
366*a1157835SDaniel Fojt iterator->_reset_on_ext = 1;
367*a1157835SDaniel Fojt iterator->current_namespace = &radiotap_ns;
368*a1157835SDaniel Fojt iterator->is_radiotap_ns = 1;
369*a1157835SDaniel Fojt goto next_entry;
370*a1157835SDaniel Fojt case IEEE80211_RADIOTAP_EXT:
371*a1157835SDaniel Fojt /*
372*a1157835SDaniel Fojt * bit 31 was set, there is more
373*a1157835SDaniel Fojt * -- move to next u32 bitmap
374*a1157835SDaniel Fojt */
375*a1157835SDaniel Fojt iterator->_bitmap_shifter =
376*a1157835SDaniel Fojt get_unaligned_le32(iterator->_next_bitmap);
377*a1157835SDaniel Fojt iterator->_next_bitmap++;
378*a1157835SDaniel Fojt if (iterator->_reset_on_ext)
379*a1157835SDaniel Fojt iterator->_arg_index = 0;
380*a1157835SDaniel Fojt else
381*a1157835SDaniel Fojt iterator->_arg_index++;
382*a1157835SDaniel Fojt iterator->_reset_on_ext = 0;
383*a1157835SDaniel Fojt break;
384*a1157835SDaniel Fojt default:
385*a1157835SDaniel Fojt /* we've got a hit! */
386*a1157835SDaniel Fojt hit = 1;
3873ff40c12SJohn Marino next_entry:
388*a1157835SDaniel Fojt iterator->_bitmap_shifter >>= 1;
389*a1157835SDaniel Fojt iterator->_arg_index++;
390*a1157835SDaniel Fojt }
3913ff40c12SJohn Marino
3923ff40c12SJohn Marino /* if we found a valid arg earlier, return it now */
3933ff40c12SJohn Marino if (hit)
3943ff40c12SJohn Marino return 0;
3953ff40c12SJohn Marino }
3963ff40c12SJohn Marino }
397