1e5b75505Sopenharmony_ci/* 2e5b75505Sopenharmony_ci * Radiotap parser 3e5b75505Sopenharmony_ci * 4e5b75505Sopenharmony_ci * Copyright 2007 Andy Green <andy@warmcat.com> 5e5b75505Sopenharmony_ci * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> 6e5b75505Sopenharmony_ci * 7e5b75505Sopenharmony_ci * This program is free software; you can redistribute it and/or modify 8e5b75505Sopenharmony_ci * it under the terms of the GNU General Public License version 2 as 9e5b75505Sopenharmony_ci * published by the Free Software Foundation. 10e5b75505Sopenharmony_ci * 11e5b75505Sopenharmony_ci * Alternatively, this software may be distributed under the terms of BSD 12e5b75505Sopenharmony_ci * license. 13e5b75505Sopenharmony_ci * 14e5b75505Sopenharmony_ci * See COPYING for more details. 15e5b75505Sopenharmony_ci */ 16e5b75505Sopenharmony_ci#include "platform.h" 17e5b75505Sopenharmony_ci#include "radiotap_iter.h" 18e5b75505Sopenharmony_ci 19e5b75505Sopenharmony_ci/* function prototypes and related defs are in radiotap_iter.h */ 20e5b75505Sopenharmony_ci 21e5b75505Sopenharmony_cistatic const struct radiotap_align_size rtap_namespace_sizes[] = { 22e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_TSFT] = { .align = 8, .size = 8, }, 23e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_FLAGS] = { .align = 1, .size = 1, }, 24e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_RATE] = { .align = 1, .size = 1, }, 25e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_CHANNEL] = { .align = 2, .size = 4, }, 26e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_FHSS] = { .align = 2, .size = 2, }, 27e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = { .align = 1, .size = 1, }, 28e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_DBM_ANTNOISE] = { .align = 1, .size = 1, }, 29e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_LOCK_QUALITY] = { .align = 2, .size = 2, }, 30e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_TX_ATTENUATION] = { .align = 2, .size = 2, }, 31e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = { .align = 2, .size = 2, }, 32e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_DBM_TX_POWER] = { .align = 1, .size = 1, }, 33e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_ANTENNA] = { .align = 1, .size = 1, }, 34e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = { .align = 1, .size = 1, }, 35e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_DB_ANTNOISE] = { .align = 1, .size = 1, }, 36e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_RX_FLAGS] = { .align = 2, .size = 2, }, 37e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_TX_FLAGS] = { .align = 2, .size = 2, }, 38e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_RTS_RETRIES] = { .align = 1, .size = 1, }, 39e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_DATA_RETRIES] = { .align = 1, .size = 1, }, 40e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_MCS] = { .align = 1, .size = 3, }, 41e5b75505Sopenharmony_ci [IEEE80211_RADIOTAP_AMPDU_STATUS] = { .align = 4, .size = 8, }, 42e5b75505Sopenharmony_ci /* 43e5b75505Sopenharmony_ci * add more here as they are defined in radiotap.h 44e5b75505Sopenharmony_ci */ 45e5b75505Sopenharmony_ci}; 46e5b75505Sopenharmony_ci 47e5b75505Sopenharmony_cistatic const struct ieee80211_radiotap_namespace radiotap_ns = { 48e5b75505Sopenharmony_ci .n_bits = sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]), 49e5b75505Sopenharmony_ci .align_size = rtap_namespace_sizes, 50e5b75505Sopenharmony_ci}; 51e5b75505Sopenharmony_ci 52e5b75505Sopenharmony_ci/** 53e5b75505Sopenharmony_ci * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization 54e5b75505Sopenharmony_ci * @iterator: radiotap_iterator to initialize 55e5b75505Sopenharmony_ci * @radiotap_header: radiotap header to parse 56e5b75505Sopenharmony_ci * @max_length: total length we can parse into (eg, whole packet length) 57e5b75505Sopenharmony_ci * 58e5b75505Sopenharmony_ci * Returns: 0 or a negative error code if there is a problem. 59e5b75505Sopenharmony_ci * 60e5b75505Sopenharmony_ci * This function initializes an opaque iterator struct which can then 61e5b75505Sopenharmony_ci * be passed to ieee80211_radiotap_iterator_next() to visit every radiotap 62e5b75505Sopenharmony_ci * argument which is present in the header. It knows about extended 63e5b75505Sopenharmony_ci * present headers and handles them. 64e5b75505Sopenharmony_ci * 65e5b75505Sopenharmony_ci * How to use: 66e5b75505Sopenharmony_ci * call __ieee80211_radiotap_iterator_init() to init a semi-opaque iterator 67e5b75505Sopenharmony_ci * struct ieee80211_radiotap_iterator (no need to init the struct beforehand) 68e5b75505Sopenharmony_ci * checking for a good 0 return code. Then loop calling 69e5b75505Sopenharmony_ci * __ieee80211_radiotap_iterator_next()... it returns either 0, 70e5b75505Sopenharmony_ci * -ENOENT if there are no more args to parse, or -EINVAL if there is a problem. 71e5b75505Sopenharmony_ci * The iterator's @this_arg member points to the start of the argument 72e5b75505Sopenharmony_ci * associated with the current argument index that is present, which can be 73e5b75505Sopenharmony_ci * found in the iterator's @this_arg_index member. This arg index corresponds 74e5b75505Sopenharmony_ci * to the IEEE80211_RADIOTAP_... defines. 75e5b75505Sopenharmony_ci * 76e5b75505Sopenharmony_ci * Radiotap header length: 77e5b75505Sopenharmony_ci * You can find the CPU-endian total radiotap header length in 78e5b75505Sopenharmony_ci * iterator->max_length after executing ieee80211_radiotap_iterator_init() 79e5b75505Sopenharmony_ci * successfully. 80e5b75505Sopenharmony_ci * 81e5b75505Sopenharmony_ci * Alignment Gotcha: 82e5b75505Sopenharmony_ci * You must take care when dereferencing iterator.this_arg 83e5b75505Sopenharmony_ci * for multibyte types... the pointer is not aligned. Use 84e5b75505Sopenharmony_ci * get_unaligned((type *)iterator.this_arg) to dereference 85e5b75505Sopenharmony_ci * iterator.this_arg for type "type" safely on all arches. 86e5b75505Sopenharmony_ci * 87e5b75505Sopenharmony_ci * Example code: parse.c 88e5b75505Sopenharmony_ci */ 89e5b75505Sopenharmony_ci 90e5b75505Sopenharmony_ciint ieee80211_radiotap_iterator_init( 91e5b75505Sopenharmony_ci struct ieee80211_radiotap_iterator *iterator, 92e5b75505Sopenharmony_ci struct ieee80211_radiotap_header *radiotap_header, 93e5b75505Sopenharmony_ci int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns) 94e5b75505Sopenharmony_ci{ 95e5b75505Sopenharmony_ci /* must at least have the radiotap header */ 96e5b75505Sopenharmony_ci if (max_length < (int)sizeof(struct ieee80211_radiotap_header)) 97e5b75505Sopenharmony_ci return -EINVAL; 98e5b75505Sopenharmony_ci 99e5b75505Sopenharmony_ci /* Linux only supports version 0 radiotap format */ 100e5b75505Sopenharmony_ci if (radiotap_header->it_version) 101e5b75505Sopenharmony_ci return -EINVAL; 102e5b75505Sopenharmony_ci 103e5b75505Sopenharmony_ci /* sanity check for allowed length and radiotap length field */ 104e5b75505Sopenharmony_ci if (max_length < get_unaligned_le16(&radiotap_header->it_len)) 105e5b75505Sopenharmony_ci return -EINVAL; 106e5b75505Sopenharmony_ci 107e5b75505Sopenharmony_ci iterator->_rtheader = radiotap_header; 108e5b75505Sopenharmony_ci iterator->_max_length = get_unaligned_le16(&radiotap_header->it_len); 109e5b75505Sopenharmony_ci iterator->_arg_index = 0; 110e5b75505Sopenharmony_ci iterator->_bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present); 111e5b75505Sopenharmony_ci iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header); 112e5b75505Sopenharmony_ci iterator->_next_ns_data = NULL; 113e5b75505Sopenharmony_ci iterator->_reset_on_ext = 0; 114e5b75505Sopenharmony_ci iterator->_next_bitmap = &radiotap_header->it_present; 115e5b75505Sopenharmony_ci iterator->_next_bitmap++; 116e5b75505Sopenharmony_ci iterator->_vns = vns; 117e5b75505Sopenharmony_ci iterator->current_namespace = &radiotap_ns; 118e5b75505Sopenharmony_ci iterator->is_radiotap_ns = 1; 119e5b75505Sopenharmony_ci#ifdef RADIOTAP_SUPPORT_OVERRIDES 120e5b75505Sopenharmony_ci iterator->n_overrides = 0; 121e5b75505Sopenharmony_ci iterator->overrides = NULL; 122e5b75505Sopenharmony_ci#endif 123e5b75505Sopenharmony_ci 124e5b75505Sopenharmony_ci /* find payload start allowing for extended bitmap(s) */ 125e5b75505Sopenharmony_ci 126e5b75505Sopenharmony_ci if (iterator->_bitmap_shifter & BIT(IEEE80211_RADIOTAP_EXT)) { 127e5b75505Sopenharmony_ci if ((unsigned long)iterator->_arg - 128e5b75505Sopenharmony_ci (unsigned long)iterator->_rtheader + sizeof(uint32_t) > 129e5b75505Sopenharmony_ci (unsigned long)iterator->_max_length) 130e5b75505Sopenharmony_ci return -EINVAL; 131e5b75505Sopenharmony_ci while (get_unaligned_le32(iterator->_arg) & 132e5b75505Sopenharmony_ci BIT(IEEE80211_RADIOTAP_EXT)) { 133e5b75505Sopenharmony_ci iterator->_arg += sizeof(uint32_t); 134e5b75505Sopenharmony_ci 135e5b75505Sopenharmony_ci /* 136e5b75505Sopenharmony_ci * check for insanity where the present bitmaps 137e5b75505Sopenharmony_ci * keep claiming to extend up to or even beyond the 138e5b75505Sopenharmony_ci * stated radiotap header length 139e5b75505Sopenharmony_ci */ 140e5b75505Sopenharmony_ci 141e5b75505Sopenharmony_ci if ((unsigned long)iterator->_arg - 142e5b75505Sopenharmony_ci (unsigned long)iterator->_rtheader + 143e5b75505Sopenharmony_ci sizeof(uint32_t) > 144e5b75505Sopenharmony_ci (unsigned long)iterator->_max_length) 145e5b75505Sopenharmony_ci return -EINVAL; 146e5b75505Sopenharmony_ci } 147e5b75505Sopenharmony_ci 148e5b75505Sopenharmony_ci iterator->_arg += sizeof(uint32_t); 149e5b75505Sopenharmony_ci 150e5b75505Sopenharmony_ci /* 151e5b75505Sopenharmony_ci * no need to check again for blowing past stated radiotap 152e5b75505Sopenharmony_ci * header length, because ieee80211_radiotap_iterator_next 153e5b75505Sopenharmony_ci * checks it before it is dereferenced 154e5b75505Sopenharmony_ci */ 155e5b75505Sopenharmony_ci } 156e5b75505Sopenharmony_ci 157e5b75505Sopenharmony_ci iterator->this_arg = iterator->_arg; 158e5b75505Sopenharmony_ci iterator->this_arg_index = 0; 159e5b75505Sopenharmony_ci iterator->this_arg_size = 0; 160e5b75505Sopenharmony_ci 161e5b75505Sopenharmony_ci /* we are all initialized happily */ 162e5b75505Sopenharmony_ci 163e5b75505Sopenharmony_ci return 0; 164e5b75505Sopenharmony_ci} 165e5b75505Sopenharmony_ci 166e5b75505Sopenharmony_cistatic void find_ns(struct ieee80211_radiotap_iterator *iterator, 167e5b75505Sopenharmony_ci uint32_t oui, uint8_t subns) 168e5b75505Sopenharmony_ci{ 169e5b75505Sopenharmony_ci int i; 170e5b75505Sopenharmony_ci 171e5b75505Sopenharmony_ci iterator->current_namespace = NULL; 172e5b75505Sopenharmony_ci 173e5b75505Sopenharmony_ci if (!iterator->_vns) 174e5b75505Sopenharmony_ci return; 175e5b75505Sopenharmony_ci 176e5b75505Sopenharmony_ci for (i = 0; i < iterator->_vns->n_ns; i++) { 177e5b75505Sopenharmony_ci if (iterator->_vns->ns[i].oui != oui) 178e5b75505Sopenharmony_ci continue; 179e5b75505Sopenharmony_ci if (iterator->_vns->ns[i].subns != subns) 180e5b75505Sopenharmony_ci continue; 181e5b75505Sopenharmony_ci 182e5b75505Sopenharmony_ci iterator->current_namespace = &iterator->_vns->ns[i]; 183e5b75505Sopenharmony_ci break; 184e5b75505Sopenharmony_ci } 185e5b75505Sopenharmony_ci} 186e5b75505Sopenharmony_ci 187e5b75505Sopenharmony_ci#ifdef RADIOTAP_SUPPORT_OVERRIDES 188e5b75505Sopenharmony_cistatic int find_override(struct ieee80211_radiotap_iterator *iterator, 189e5b75505Sopenharmony_ci int *align, int *size) 190e5b75505Sopenharmony_ci{ 191e5b75505Sopenharmony_ci int i; 192e5b75505Sopenharmony_ci 193e5b75505Sopenharmony_ci if (!iterator->overrides) 194e5b75505Sopenharmony_ci return 0; 195e5b75505Sopenharmony_ci 196e5b75505Sopenharmony_ci for (i = 0; i < iterator->n_overrides; i++) { 197e5b75505Sopenharmony_ci if (iterator->_arg_index == iterator->overrides[i].field) { 198e5b75505Sopenharmony_ci *align = iterator->overrides[i].align; 199e5b75505Sopenharmony_ci *size = iterator->overrides[i].size; 200e5b75505Sopenharmony_ci if (!*align) /* erroneous override */ 201e5b75505Sopenharmony_ci return 0; 202e5b75505Sopenharmony_ci return 1; 203e5b75505Sopenharmony_ci } 204e5b75505Sopenharmony_ci } 205e5b75505Sopenharmony_ci 206e5b75505Sopenharmony_ci return 0; 207e5b75505Sopenharmony_ci} 208e5b75505Sopenharmony_ci#endif 209e5b75505Sopenharmony_ci 210e5b75505Sopenharmony_ci 211e5b75505Sopenharmony_ci/** 212e5b75505Sopenharmony_ci * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg 213e5b75505Sopenharmony_ci * @iterator: radiotap_iterator to move to next arg (if any) 214e5b75505Sopenharmony_ci * 215e5b75505Sopenharmony_ci * Returns: 0 if there is an argument to handle, 216e5b75505Sopenharmony_ci * -ENOENT if there are no more args or -EINVAL 217e5b75505Sopenharmony_ci * if there is something else wrong. 218e5b75505Sopenharmony_ci * 219e5b75505Sopenharmony_ci * This function provides the next radiotap arg index (IEEE80211_RADIOTAP_*) 220e5b75505Sopenharmony_ci * in @this_arg_index and sets @this_arg to point to the 221e5b75505Sopenharmony_ci * payload for the field. It takes care of alignment handling and extended 222e5b75505Sopenharmony_ci * present fields. @this_arg can be changed by the caller (eg, 223e5b75505Sopenharmony_ci * incremented to move inside a compound argument like 224e5b75505Sopenharmony_ci * IEEE80211_RADIOTAP_CHANNEL). The args pointed to are in 225e5b75505Sopenharmony_ci * little-endian format whatever the endianess of your CPU. 226e5b75505Sopenharmony_ci * 227e5b75505Sopenharmony_ci * Alignment Gotcha: 228e5b75505Sopenharmony_ci * You must take care when dereferencing iterator.this_arg 229e5b75505Sopenharmony_ci * for multibyte types... the pointer is not aligned. Use 230e5b75505Sopenharmony_ci * get_unaligned((type *)iterator.this_arg) to dereference 231e5b75505Sopenharmony_ci * iterator.this_arg for type "type" safely on all arches. 232e5b75505Sopenharmony_ci */ 233e5b75505Sopenharmony_ci 234e5b75505Sopenharmony_ciint ieee80211_radiotap_iterator_next( 235e5b75505Sopenharmony_ci struct ieee80211_radiotap_iterator *iterator) 236e5b75505Sopenharmony_ci{ 237e5b75505Sopenharmony_ci while (1) { 238e5b75505Sopenharmony_ci int hit = 0; 239e5b75505Sopenharmony_ci int pad, align, size, subns; 240e5b75505Sopenharmony_ci uint32_t oui; 241e5b75505Sopenharmony_ci 242e5b75505Sopenharmony_ci /* if no more EXT bits, that's it */ 243e5b75505Sopenharmony_ci if ((iterator->_arg_index % 32) == IEEE80211_RADIOTAP_EXT && 244e5b75505Sopenharmony_ci !(iterator->_bitmap_shifter & 1)) 245e5b75505Sopenharmony_ci return -ENOENT; 246e5b75505Sopenharmony_ci 247e5b75505Sopenharmony_ci if (!(iterator->_bitmap_shifter & 1)) 248e5b75505Sopenharmony_ci goto next_entry; /* arg not present */ 249e5b75505Sopenharmony_ci 250e5b75505Sopenharmony_ci /* get alignment/size of data */ 251e5b75505Sopenharmony_ci switch (iterator->_arg_index % 32) { 252e5b75505Sopenharmony_ci case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE: 253e5b75505Sopenharmony_ci case IEEE80211_RADIOTAP_EXT: 254e5b75505Sopenharmony_ci align = 1; 255e5b75505Sopenharmony_ci size = 0; 256e5b75505Sopenharmony_ci break; 257e5b75505Sopenharmony_ci case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: 258e5b75505Sopenharmony_ci align = 2; 259e5b75505Sopenharmony_ci size = 6; 260e5b75505Sopenharmony_ci break; 261e5b75505Sopenharmony_ci default: 262e5b75505Sopenharmony_ci#ifdef RADIOTAP_SUPPORT_OVERRIDES 263e5b75505Sopenharmony_ci if (find_override(iterator, &align, &size)) { 264e5b75505Sopenharmony_ci /* all set */ 265e5b75505Sopenharmony_ci } else 266e5b75505Sopenharmony_ci#endif 267e5b75505Sopenharmony_ci if (!iterator->current_namespace || 268e5b75505Sopenharmony_ci iterator->_arg_index >= iterator->current_namespace->n_bits) { 269e5b75505Sopenharmony_ci if (iterator->current_namespace == &radiotap_ns) 270e5b75505Sopenharmony_ci return -ENOENT; 271e5b75505Sopenharmony_ci align = 0; 272e5b75505Sopenharmony_ci } else { 273e5b75505Sopenharmony_ci align = iterator->current_namespace->align_size[iterator->_arg_index].align; 274e5b75505Sopenharmony_ci size = iterator->current_namespace->align_size[iterator->_arg_index].size; 275e5b75505Sopenharmony_ci } 276e5b75505Sopenharmony_ci if (!align) { 277e5b75505Sopenharmony_ci /* skip all subsequent data */ 278e5b75505Sopenharmony_ci iterator->_arg = iterator->_next_ns_data; 279e5b75505Sopenharmony_ci /* give up on this namespace */ 280e5b75505Sopenharmony_ci iterator->current_namespace = NULL; 281e5b75505Sopenharmony_ci goto next_entry; 282e5b75505Sopenharmony_ci } 283e5b75505Sopenharmony_ci break; 284e5b75505Sopenharmony_ci } 285e5b75505Sopenharmony_ci 286e5b75505Sopenharmony_ci /* 287e5b75505Sopenharmony_ci * arg is present, account for alignment padding 288e5b75505Sopenharmony_ci * 289e5b75505Sopenharmony_ci * Note that these alignments are relative to the start 290e5b75505Sopenharmony_ci * of the radiotap header. There is no guarantee 291e5b75505Sopenharmony_ci * that the radiotap header itself is aligned on any 292e5b75505Sopenharmony_ci * kind of boundary. 293e5b75505Sopenharmony_ci * 294e5b75505Sopenharmony_ci * The above is why get_unaligned() is used to dereference 295e5b75505Sopenharmony_ci * multibyte elements from the radiotap area. 296e5b75505Sopenharmony_ci */ 297e5b75505Sopenharmony_ci 298e5b75505Sopenharmony_ci pad = ((unsigned long)iterator->_arg - 299e5b75505Sopenharmony_ci (unsigned long)iterator->_rtheader) & (align - 1); 300e5b75505Sopenharmony_ci 301e5b75505Sopenharmony_ci if (pad) 302e5b75505Sopenharmony_ci iterator->_arg += align - pad; 303e5b75505Sopenharmony_ci 304e5b75505Sopenharmony_ci if (iterator->_arg_index % 32 == IEEE80211_RADIOTAP_VENDOR_NAMESPACE) { 305e5b75505Sopenharmony_ci int vnslen; 306e5b75505Sopenharmony_ci 307e5b75505Sopenharmony_ci if ((unsigned long)iterator->_arg + size - 308e5b75505Sopenharmony_ci (unsigned long)iterator->_rtheader > 309e5b75505Sopenharmony_ci (unsigned long)iterator->_max_length) 310e5b75505Sopenharmony_ci return -EINVAL; 311e5b75505Sopenharmony_ci 312e5b75505Sopenharmony_ci oui = (*iterator->_arg << 16) | 313e5b75505Sopenharmony_ci (*(iterator->_arg + 1) << 8) | 314e5b75505Sopenharmony_ci *(iterator->_arg + 2); 315e5b75505Sopenharmony_ci subns = *(iterator->_arg + 3); 316e5b75505Sopenharmony_ci 317e5b75505Sopenharmony_ci find_ns(iterator, oui, subns); 318e5b75505Sopenharmony_ci 319e5b75505Sopenharmony_ci vnslen = get_unaligned_le16(iterator->_arg + 4); 320e5b75505Sopenharmony_ci iterator->_next_ns_data = iterator->_arg + size + vnslen; 321e5b75505Sopenharmony_ci if (!iterator->current_namespace) 322e5b75505Sopenharmony_ci size += vnslen; 323e5b75505Sopenharmony_ci } 324e5b75505Sopenharmony_ci 325e5b75505Sopenharmony_ci /* 326e5b75505Sopenharmony_ci * this is what we will return to user, but we need to 327e5b75505Sopenharmony_ci * move on first so next call has something fresh to test 328e5b75505Sopenharmony_ci */ 329e5b75505Sopenharmony_ci iterator->this_arg_index = iterator->_arg_index; 330e5b75505Sopenharmony_ci iterator->this_arg = iterator->_arg; 331e5b75505Sopenharmony_ci iterator->this_arg_size = size; 332e5b75505Sopenharmony_ci 333e5b75505Sopenharmony_ci /* internally move on the size of this arg */ 334e5b75505Sopenharmony_ci iterator->_arg += size; 335e5b75505Sopenharmony_ci 336e5b75505Sopenharmony_ci /* 337e5b75505Sopenharmony_ci * check for insanity where we are given a bitmap that 338e5b75505Sopenharmony_ci * claims to have more arg content than the length of the 339e5b75505Sopenharmony_ci * radiotap section. We will normally end up equalling this 340e5b75505Sopenharmony_ci * max_length on the last arg, never exceeding it. 341e5b75505Sopenharmony_ci */ 342e5b75505Sopenharmony_ci 343e5b75505Sopenharmony_ci if ((unsigned long)iterator->_arg - 344e5b75505Sopenharmony_ci (unsigned long)iterator->_rtheader > 345e5b75505Sopenharmony_ci (unsigned long)iterator->_max_length) 346e5b75505Sopenharmony_ci return -EINVAL; 347e5b75505Sopenharmony_ci 348e5b75505Sopenharmony_ci /* these special ones are valid in each bitmap word */ 349e5b75505Sopenharmony_ci switch (iterator->_arg_index % 32) { 350e5b75505Sopenharmony_ci case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: 351e5b75505Sopenharmony_ci iterator->_reset_on_ext = 1; 352e5b75505Sopenharmony_ci 353e5b75505Sopenharmony_ci iterator->is_radiotap_ns = 0; 354e5b75505Sopenharmony_ci /* 355e5b75505Sopenharmony_ci * If parser didn't register this vendor 356e5b75505Sopenharmony_ci * namespace with us, allow it to show it 357e5b75505Sopenharmony_ci * as 'raw. Do do that, set argument index 358e5b75505Sopenharmony_ci * to vendor namespace. 359e5b75505Sopenharmony_ci */ 360e5b75505Sopenharmony_ci iterator->this_arg_index = 361e5b75505Sopenharmony_ci IEEE80211_RADIOTAP_VENDOR_NAMESPACE; 362e5b75505Sopenharmony_ci if (!iterator->current_namespace) 363e5b75505Sopenharmony_ci hit = 1; 364e5b75505Sopenharmony_ci goto next_entry; 365e5b75505Sopenharmony_ci case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE: 366e5b75505Sopenharmony_ci iterator->_reset_on_ext = 1; 367e5b75505Sopenharmony_ci iterator->current_namespace = &radiotap_ns; 368e5b75505Sopenharmony_ci iterator->is_radiotap_ns = 1; 369e5b75505Sopenharmony_ci goto next_entry; 370e5b75505Sopenharmony_ci case IEEE80211_RADIOTAP_EXT: 371e5b75505Sopenharmony_ci /* 372e5b75505Sopenharmony_ci * bit 31 was set, there is more 373e5b75505Sopenharmony_ci * -- move to next u32 bitmap 374e5b75505Sopenharmony_ci */ 375e5b75505Sopenharmony_ci iterator->_bitmap_shifter = 376e5b75505Sopenharmony_ci get_unaligned_le32(iterator->_next_bitmap); 377e5b75505Sopenharmony_ci iterator->_next_bitmap++; 378e5b75505Sopenharmony_ci if (iterator->_reset_on_ext) 379e5b75505Sopenharmony_ci iterator->_arg_index = 0; 380e5b75505Sopenharmony_ci else 381e5b75505Sopenharmony_ci iterator->_arg_index++; 382e5b75505Sopenharmony_ci iterator->_reset_on_ext = 0; 383e5b75505Sopenharmony_ci break; 384e5b75505Sopenharmony_ci default: 385e5b75505Sopenharmony_ci /* we've got a hit! */ 386e5b75505Sopenharmony_ci hit = 1; 387e5b75505Sopenharmony_ci next_entry: 388e5b75505Sopenharmony_ci iterator->_bitmap_shifter >>= 1; 389e5b75505Sopenharmony_ci iterator->_arg_index++; 390e5b75505Sopenharmony_ci } 391e5b75505Sopenharmony_ci 392e5b75505Sopenharmony_ci /* if we found a valid arg earlier, return it now */ 393e5b75505Sopenharmony_ci if (hit) 394e5b75505Sopenharmony_ci return 0; 395e5b75505Sopenharmony_ci } 396e5b75505Sopenharmony_ci} 397