diff options
| -rw-r--r-- | include/net/cfg80211.h | 83 | ||||
| -rw-r--r-- | include/net/ieee80211_radiotap.h | 4 | ||||
| -rw-r--r-- | net/mac80211/tx.c | 9 | ||||
| -rw-r--r-- | net/wireless/radiotap.c | 305 |
4 files changed, 271 insertions, 130 deletions
diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index a3f0a7ed31ac..5b3569b2a74c 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h | |||
| @@ -1561,37 +1561,82 @@ ieee80211_get_response_rate(struct ieee80211_supported_band *sband, | |||
| 1561 | * Documentation in Documentation/networking/radiotap-headers.txt | 1561 | * Documentation in Documentation/networking/radiotap-headers.txt |
| 1562 | */ | 1562 | */ |
| 1563 | 1563 | ||
| 1564 | struct radiotap_align_size { | ||
| 1565 | uint8_t align:4, size:4; | ||
| 1566 | }; | ||
| 1567 | |||
| 1568 | struct ieee80211_radiotap_namespace { | ||
| 1569 | const struct radiotap_align_size *align_size; | ||
| 1570 | int n_bits; | ||
| 1571 | uint32_t oui; | ||
| 1572 | uint8_t subns; | ||
| 1573 | }; | ||
| 1574 | |||
| 1575 | struct ieee80211_radiotap_vendor_namespaces { | ||
| 1576 | const struct ieee80211_radiotap_namespace *ns; | ||
| 1577 | int n_ns; | ||
| 1578 | }; | ||
| 1579 | |||
| 1564 | /** | 1580 | /** |
| 1565 | * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args | 1581 | * struct ieee80211_radiotap_iterator - tracks walk thru present radiotap args |
| 1566 | * @rtheader: pointer to the radiotap header we are walking through | 1582 | * @this_arg_index: index of current arg, valid after each successful call |
| 1567 | * @max_length: length of radiotap header in cpu byte ordering | 1583 | * to ieee80211_radiotap_iterator_next() |
| 1568 | * @this_arg_index: IEEE80211_RADIOTAP_... index of current arg | 1584 | * @this_arg: pointer to current radiotap arg; it is valid after each |
| 1569 | * @this_arg: pointer to current radiotap arg | 1585 | * call to ieee80211_radiotap_iterator_next() but also after |
| 1570 | * @arg_index: internal next argument index | 1586 | * ieee80211_radiotap_iterator_init() where it will point to |
| 1571 | * @arg: internal next argument pointer | 1587 | * the beginning of the actual data portion |
| 1572 | * @next_bitmap: internal pointer to next present u32 | 1588 | * @this_arg_size: length of the current arg, for convenience |
| 1573 | * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present | 1589 | * @current_namespace: pointer to the current namespace definition |
| 1590 | * (or internally %NULL if the current namespace is unknown) | ||
| 1591 | * @is_radiotap_ns: indicates whether the current namespace is the default | ||
| 1592 | * radiotap namespace or not | ||
| 1593 | * | ||
| 1594 | * @overrides: override standard radiotap fields | ||
| 1595 | * @n_overrides: number of overrides | ||
| 1596 | * | ||
| 1597 | * @_rtheader: pointer to the radiotap header we are walking through | ||
| 1598 | * @_max_length: length of radiotap header in cpu byte ordering | ||
| 1599 | * @_arg_index: next argument index | ||
| 1600 | * @_arg: next argument pointer | ||
| 1601 | * @_next_bitmap: internal pointer to next present u32 | ||
| 1602 | * @_bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present | ||
| 1603 | * @_vns: vendor namespace definitions | ||
| 1604 | * @_next_ns_data: beginning of the next namespace's data | ||
| 1605 | * @_reset_on_ext: internal; reset the arg index to 0 when going to the | ||
| 1606 | * next bitmap word | ||
| 1607 | * | ||
| 1608 | * Describes the radiotap parser state. Fields prefixed with an underscore | ||
| 1609 | * must not be used by users of the parser, only by the parser internally. | ||
| 1574 | */ | 1610 | */ |
| 1575 | 1611 | ||
| 1576 | struct ieee80211_radiotap_iterator { | 1612 | struct ieee80211_radiotap_iterator { |
| 1577 | struct ieee80211_radiotap_header *rtheader; | 1613 | struct ieee80211_radiotap_header *_rtheader; |
| 1578 | int max_length; | 1614 | const struct ieee80211_radiotap_vendor_namespaces *_vns; |
| 1615 | const struct ieee80211_radiotap_namespace *current_namespace; | ||
| 1616 | |||
| 1617 | unsigned char *_arg, *_next_ns_data; | ||
| 1618 | uint32_t *_next_bitmap; | ||
| 1619 | |||
| 1620 | unsigned char *this_arg; | ||
| 1579 | int this_arg_index; | 1621 | int this_arg_index; |
| 1580 | u8 *this_arg; | 1622 | int this_arg_size; |
| 1581 | 1623 | ||
| 1582 | int arg_index; | 1624 | int is_radiotap_ns; |
| 1583 | u8 *arg; | 1625 | |
| 1584 | __le32 *next_bitmap; | 1626 | int _max_length; |
| 1585 | u32 bitmap_shifter; | 1627 | int _arg_index; |
| 1628 | uint32_t _bitmap_shifter; | ||
| 1629 | int _reset_on_ext; | ||
| 1586 | }; | 1630 | }; |
| 1587 | 1631 | ||
| 1588 | extern int ieee80211_radiotap_iterator_init( | 1632 | extern int ieee80211_radiotap_iterator_init( |
| 1589 | struct ieee80211_radiotap_iterator *iterator, | 1633 | struct ieee80211_radiotap_iterator *iterator, |
| 1590 | struct ieee80211_radiotap_header *radiotap_header, | 1634 | struct ieee80211_radiotap_header *radiotap_header, |
| 1591 | int max_length); | 1635 | int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns); |
| 1592 | 1636 | ||
| 1593 | extern int ieee80211_radiotap_iterator_next( | 1637 | extern int ieee80211_radiotap_iterator_next( |
| 1594 | struct ieee80211_radiotap_iterator *iterator); | 1638 | struct ieee80211_radiotap_iterator *iterator); |
| 1639 | |||
| 1595 | 1640 | ||
| 1596 | extern const unsigned char rfc1042_header[6]; | 1641 | extern const unsigned char rfc1042_header[6]; |
| 1597 | extern const unsigned char bridge_tunnel_header[6]; | 1642 | extern const unsigned char bridge_tunnel_header[6]; |
diff --git a/include/net/ieee80211_radiotap.h b/include/net/ieee80211_radiotap.h index 9d3d86aaccbb..af49f8ab7f81 100644 --- a/include/net/ieee80211_radiotap.h +++ b/include/net/ieee80211_radiotap.h | |||
| @@ -198,6 +198,10 @@ enum ieee80211_radiotap_type { | |||
| 198 | IEEE80211_RADIOTAP_TX_FLAGS = 15, | 198 | IEEE80211_RADIOTAP_TX_FLAGS = 15, |
| 199 | IEEE80211_RADIOTAP_RTS_RETRIES = 16, | 199 | IEEE80211_RADIOTAP_RTS_RETRIES = 16, |
| 200 | IEEE80211_RADIOTAP_DATA_RETRIES = 17, | 200 | IEEE80211_RADIOTAP_DATA_RETRIES = 17, |
| 201 | |||
| 202 | /* valid in every it_present bitmap, even vendor namespaces */ | ||
| 203 | IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29, | ||
| 204 | IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30, | ||
| 201 | IEEE80211_RADIOTAP_EXT = 31 | 205 | IEEE80211_RADIOTAP_EXT = 31 |
| 202 | }; | 206 | }; |
| 203 | 207 | ||
diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index 85e382aa894e..e392820a4c33 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c | |||
| @@ -1010,7 +1010,8 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx, | |||
| 1010 | (struct ieee80211_radiotap_header *) skb->data; | 1010 | (struct ieee80211_radiotap_header *) skb->data; |
| 1011 | struct ieee80211_supported_band *sband; | 1011 | struct ieee80211_supported_band *sband; |
| 1012 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); | 1012 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1013 | int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); | 1013 | int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, |
| 1014 | NULL); | ||
| 1014 | 1015 | ||
| 1015 | sband = tx->local->hw.wiphy->bands[tx->channel->band]; | 1016 | sband = tx->local->hw.wiphy->bands[tx->channel->band]; |
| 1016 | 1017 | ||
| @@ -1046,7 +1047,7 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx, | |||
| 1046 | * because it will be recomputed and added | 1047 | * because it will be recomputed and added |
| 1047 | * on transmission | 1048 | * on transmission |
| 1048 | */ | 1049 | */ |
| 1049 | if (skb->len < (iterator.max_length + FCS_LEN)) | 1050 | if (skb->len < (iterator._max_length + FCS_LEN)) |
| 1050 | return false; | 1051 | return false; |
| 1051 | 1052 | ||
| 1052 | skb_trim(skb, skb->len - FCS_LEN); | 1053 | skb_trim(skb, skb->len - FCS_LEN); |
| @@ -1073,10 +1074,10 @@ static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx, | |||
| 1073 | 1074 | ||
| 1074 | /* | 1075 | /* |
| 1075 | * remove the radiotap header | 1076 | * remove the radiotap header |
| 1076 | * iterator->max_length was sanity-checked against | 1077 | * iterator->_max_length was sanity-checked against |
| 1077 | * skb->len by iterator init | 1078 | * skb->len by iterator init |
| 1078 | */ | 1079 | */ |
| 1079 | skb_pull(skb, iterator.max_length); | 1080 | skb_pull(skb, iterator._max_length); |
| 1080 | 1081 | ||
| 1081 | return true; | 1082 | return true; |
| 1082 | } | 1083 | } |
diff --git a/net/wireless/radiotap.c b/net/wireless/radiotap.c index f591871a7b4f..1332c445d1c7 100644 --- a/net/wireless/radiotap.c +++ b/net/wireless/radiotap.c | |||
| @@ -2,6 +2,16 @@ | |||
| 2 | * Radiotap parser | 2 | * Radiotap parser |
| 3 | * | 3 | * |
| 4 | * Copyright 2007 Andy Green <andy@warmcat.com> | 4 | * Copyright 2007 Andy Green <andy@warmcat.com> |
| 5 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | * | ||
| 11 | * Alternatively, this software may be distributed under the terms of BSD | ||
| 12 | * license. | ||
| 13 | * | ||
| 14 | * See COPYING for more details. | ||
| 5 | */ | 15 | */ |
| 6 | 16 | ||
| 7 | #include <net/cfg80211.h> | 17 | #include <net/cfg80211.h> |
| @@ -10,6 +20,35 @@ | |||
| 10 | 20 | ||
| 11 | /* function prototypes and related defs are in include/net/cfg80211.h */ | 21 | /* function prototypes and related defs are in include/net/cfg80211.h */ |
| 12 | 22 | ||
| 23 | static const struct radiotap_align_size rtap_namespace_sizes[] = { | ||
| 24 | [IEEE80211_RADIOTAP_TSFT] = { .align = 8, .size = 8, }, | ||
| 25 | [IEEE80211_RADIOTAP_FLAGS] = { .align = 1, .size = 1, }, | ||
| 26 | [IEEE80211_RADIOTAP_RATE] = { .align = 1, .size = 1, }, | ||
| 27 | [IEEE80211_RADIOTAP_CHANNEL] = { .align = 2, .size = 4, }, | ||
| 28 | [IEEE80211_RADIOTAP_FHSS] = { .align = 2, .size = 2, }, | ||
| 29 | [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = { .align = 1, .size = 1, }, | ||
| 30 | [IEEE80211_RADIOTAP_DBM_ANTNOISE] = { .align = 1, .size = 1, }, | ||
| 31 | [IEEE80211_RADIOTAP_LOCK_QUALITY] = { .align = 2, .size = 2, }, | ||
| 32 | [IEEE80211_RADIOTAP_TX_ATTENUATION] = { .align = 2, .size = 2, }, | ||
| 33 | [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = { .align = 2, .size = 2, }, | ||
| 34 | [IEEE80211_RADIOTAP_DBM_TX_POWER] = { .align = 1, .size = 1, }, | ||
| 35 | [IEEE80211_RADIOTAP_ANTENNA] = { .align = 1, .size = 1, }, | ||
| 36 | [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = { .align = 1, .size = 1, }, | ||
| 37 | [IEEE80211_RADIOTAP_DB_ANTNOISE] = { .align = 1, .size = 1, }, | ||
| 38 | [IEEE80211_RADIOTAP_RX_FLAGS] = { .align = 2, .size = 2, }, | ||
| 39 | [IEEE80211_RADIOTAP_TX_FLAGS] = { .align = 2, .size = 2, }, | ||
| 40 | [IEEE80211_RADIOTAP_RTS_RETRIES] = { .align = 1, .size = 1, }, | ||
| 41 | [IEEE80211_RADIOTAP_DATA_RETRIES] = { .align = 1, .size = 1, }, | ||
| 42 | /* | ||
| 43 | * add more here as they are defined in radiotap.h | ||
| 44 | */ | ||
| 45 | }; | ||
| 46 | |||
| 47 | static const struct ieee80211_radiotap_namespace radiotap_ns = { | ||
| 48 | .n_bits = sizeof(rtap_namespace_sizes) / sizeof(rtap_namespace_sizes[0]), | ||
| 49 | .align_size = rtap_namespace_sizes, | ||
| 50 | }; | ||
| 51 | |||
| 13 | /** | 52 | /** |
| 14 | * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization | 53 | * ieee80211_radiotap_iterator_init - radiotap parser iterator initialization |
| 15 | * @iterator: radiotap_iterator to initialize | 54 | * @iterator: radiotap_iterator to initialize |
| @@ -50,9 +89,9 @@ | |||
| 50 | */ | 89 | */ |
| 51 | 90 | ||
| 52 | int ieee80211_radiotap_iterator_init( | 91 | int ieee80211_radiotap_iterator_init( |
| 53 | struct ieee80211_radiotap_iterator *iterator, | 92 | struct ieee80211_radiotap_iterator *iterator, |
| 54 | struct ieee80211_radiotap_header *radiotap_header, | 93 | struct ieee80211_radiotap_header *radiotap_header, |
| 55 | int max_length) | 94 | int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns) |
| 56 | { | 95 | { |
| 57 | /* Linux only supports version 0 radiotap format */ | 96 | /* Linux only supports version 0 radiotap format */ |
| 58 | if (radiotap_header->it_version) | 97 | if (radiotap_header->it_version) |
| @@ -62,19 +101,24 @@ int ieee80211_radiotap_iterator_init( | |||
| 62 | if (max_length < get_unaligned_le16(&radiotap_header->it_len)) | 101 | if (max_length < get_unaligned_le16(&radiotap_header->it_len)) |
| 63 | return -EINVAL; | 102 | return -EINVAL; |
| 64 | 103 | ||
| 65 | iterator->rtheader = radiotap_header; | 104 | iterator->_rtheader = radiotap_header; |
| 66 | iterator->max_length = get_unaligned_le16(&radiotap_header->it_len); | 105 | iterator->_max_length = get_unaligned_le16(&radiotap_header->it_len); |
| 67 | iterator->arg_index = 0; | 106 | iterator->_arg_index = 0; |
| 68 | iterator->bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present); | 107 | iterator->_bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present); |
| 69 | iterator->arg = (u8 *)radiotap_header + sizeof(*radiotap_header); | 108 | iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header); |
| 70 | iterator->this_arg = NULL; | 109 | iterator->_reset_on_ext = 0; |
| 110 | iterator->_next_bitmap = &radiotap_header->it_present; | ||
| 111 | iterator->_next_bitmap++; | ||
| 112 | iterator->_vns = vns; | ||
| 113 | iterator->current_namespace = &radiotap_ns; | ||
| 114 | iterator->is_radiotap_ns = 1; | ||
| 71 | 115 | ||
| 72 | /* find payload start allowing for extended bitmap(s) */ | 116 | /* find payload start allowing for extended bitmap(s) */ |
| 73 | 117 | ||
| 74 | if (unlikely(iterator->bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT))) { | 118 | if (iterator->_bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT)) { |
| 75 | while (get_unaligned_le32(iterator->arg) & | 119 | while (get_unaligned_le32(iterator->_arg) & |
| 76 | (1 << IEEE80211_RADIOTAP_EXT)) { | 120 | (1 << IEEE80211_RADIOTAP_EXT)) { |
| 77 | iterator->arg += sizeof(u32); | 121 | iterator->_arg += sizeof(uint32_t); |
| 78 | 122 | ||
| 79 | /* | 123 | /* |
| 80 | * check for insanity where the present bitmaps | 124 | * check for insanity where the present bitmaps |
| @@ -82,12 +126,13 @@ int ieee80211_radiotap_iterator_init( | |||
| 82 | * stated radiotap header length | 126 | * stated radiotap header length |
| 83 | */ | 127 | */ |
| 84 | 128 | ||
| 85 | if (((ulong)iterator->arg - | 129 | if ((unsigned long)iterator->_arg - |
| 86 | (ulong)iterator->rtheader) > iterator->max_length) | 130 | (unsigned long)iterator->_rtheader > |
| 131 | (unsigned long)iterator->_max_length) | ||
| 87 | return -EINVAL; | 132 | return -EINVAL; |
| 88 | } | 133 | } |
| 89 | 134 | ||
| 90 | iterator->arg += sizeof(u32); | 135 | iterator->_arg += sizeof(uint32_t); |
| 91 | 136 | ||
| 92 | /* | 137 | /* |
| 93 | * no need to check again for blowing past stated radiotap | 138 | * no need to check again for blowing past stated radiotap |
| @@ -96,12 +141,36 @@ int ieee80211_radiotap_iterator_init( | |||
| 96 | */ | 141 | */ |
| 97 | } | 142 | } |
| 98 | 143 | ||
| 144 | iterator->this_arg = iterator->_arg; | ||
| 145 | |||
| 99 | /* we are all initialized happily */ | 146 | /* we are all initialized happily */ |
| 100 | 147 | ||
| 101 | return 0; | 148 | return 0; |
| 102 | } | 149 | } |
| 103 | EXPORT_SYMBOL(ieee80211_radiotap_iterator_init); | 150 | EXPORT_SYMBOL(ieee80211_radiotap_iterator_init); |
| 104 | 151 | ||
| 152 | static void find_ns(struct ieee80211_radiotap_iterator *iterator, | ||
| 153 | uint32_t oui, uint8_t subns) | ||
| 154 | { | ||
| 155 | int i; | ||
| 156 | |||
| 157 | iterator->current_namespace = NULL; | ||
| 158 | |||
| 159 | if (!iterator->_vns) | ||
| 160 | return; | ||
| 161 | |||
| 162 | for (i = 0; i < iterator->_vns->n_ns; i++) { | ||
| 163 | if (iterator->_vns->ns[i].oui != oui) | ||
| 164 | continue; | ||
| 165 | if (iterator->_vns->ns[i].subns != subns) | ||
| 166 | continue; | ||
| 167 | |||
| 168 | iterator->current_namespace = &iterator->_vns->ns[i]; | ||
| 169 | break; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | |||
| 105 | 174 | ||
| 106 | /** | 175 | /** |
| 107 | * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg | 176 | * ieee80211_radiotap_iterator_next - return next radiotap parser iterator arg |
| @@ -127,99 +196,80 @@ EXPORT_SYMBOL(ieee80211_radiotap_iterator_init); | |||
| 127 | */ | 196 | */ |
| 128 | 197 | ||
| 129 | int ieee80211_radiotap_iterator_next( | 198 | int ieee80211_radiotap_iterator_next( |
| 130 | struct ieee80211_radiotap_iterator *iterator) | 199 | struct ieee80211_radiotap_iterator *iterator) |
| 131 | { | 200 | { |
| 132 | 201 | while (1) { | |
| 133 | /* | ||
| 134 | * small length lookup table for all radiotap types we heard of | ||
| 135 | * starting from b0 in the bitmap, so we can walk the payload | ||
| 136 | * area of the radiotap header | ||
| 137 | * | ||
| 138 | * There is a requirement to pad args, so that args | ||
| 139 | * of a given length must begin at a boundary of that length | ||
| 140 | * -- but note that compound args are allowed (eg, 2 x u16 | ||
| 141 | * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not | ||
| 142 | * a reliable indicator of alignment requirement. | ||
| 143 | * | ||
| 144 | * upper nybble: content alignment for arg | ||
| 145 | * lower nybble: content length for arg | ||
| 146 | */ | ||
| 147 | |||
| 148 | static const u8 rt_sizes[] = { | ||
| 149 | [IEEE80211_RADIOTAP_TSFT] = 0x88, | ||
| 150 | [IEEE80211_RADIOTAP_FLAGS] = 0x11, | ||
| 151 | [IEEE80211_RADIOTAP_RATE] = 0x11, | ||
| 152 | [IEEE80211_RADIOTAP_CHANNEL] = 0x24, | ||
| 153 | [IEEE80211_RADIOTAP_FHSS] = 0x22, | ||
| 154 | [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11, | ||
| 155 | [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11, | ||
| 156 | [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22, | ||
| 157 | [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22, | ||
| 158 | [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22, | ||
| 159 | [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11, | ||
| 160 | [IEEE80211_RADIOTAP_ANTENNA] = 0x11, | ||
| 161 | [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11, | ||
| 162 | [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11, | ||
| 163 | [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22, | ||
| 164 | [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22, | ||
| 165 | [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11, | ||
| 166 | [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11, | ||
| 167 | /* | ||
| 168 | * add more here as they are defined in | ||
| 169 | * include/net/ieee80211_radiotap.h | ||
| 170 | */ | ||
| 171 | }; | ||
| 172 | |||
| 173 | /* | ||
| 174 | * for every radiotap entry we can at | ||
| 175 | * least skip (by knowing the length)... | ||
| 176 | */ | ||
| 177 | |||
| 178 | while (iterator->arg_index < sizeof(rt_sizes)) { | ||
| 179 | int hit = 0; | 202 | int hit = 0; |
| 180 | int pad; | 203 | int pad, align, size, subns, vnslen; |
| 204 | uint32_t oui; | ||
| 181 | 205 | ||
| 182 | if (!(iterator->bitmap_shifter & 1)) | 206 | /* if no more EXT bits, that's it */ |
| 207 | if ((iterator->_arg_index % 32) == IEEE80211_RADIOTAP_EXT && | ||
| 208 | !(iterator->_bitmap_shifter & 1)) | ||
| 209 | return -ENOENT; | ||
| 210 | |||
| 211 | if (!(iterator->_bitmap_shifter & 1)) | ||
| 183 | goto next_entry; /* arg not present */ | 212 | goto next_entry; /* arg not present */ |
| 184 | 213 | ||
| 214 | /* get alignment/size of data */ | ||
| 215 | switch (iterator->_arg_index % 32) { | ||
| 216 | case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE: | ||
| 217 | case IEEE80211_RADIOTAP_EXT: | ||
| 218 | align = 1; | ||
| 219 | size = 0; | ||
| 220 | break; | ||
| 221 | case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: | ||
| 222 | align = 2; | ||
| 223 | size = 6; | ||
| 224 | break; | ||
| 225 | default: | ||
| 226 | if (!iterator->current_namespace || | ||
| 227 | iterator->_arg_index >= iterator->current_namespace->n_bits) { | ||
| 228 | if (iterator->current_namespace == &radiotap_ns) | ||
| 229 | return -ENOENT; | ||
| 230 | align = 0; | ||
| 231 | } else { | ||
| 232 | align = iterator->current_namespace->align_size[iterator->_arg_index].align; | ||
| 233 | size = iterator->current_namespace->align_size[iterator->_arg_index].size; | ||
| 234 | } | ||
| 235 | if (!align) { | ||
| 236 | /* skip all subsequent data */ | ||
| 237 | iterator->_arg = iterator->_next_ns_data; | ||
| 238 | /* give up on this namespace */ | ||
| 239 | iterator->current_namespace = NULL; | ||
| 240 | goto next_entry; | ||
| 241 | } | ||
| 242 | break; | ||
| 243 | } | ||
| 244 | |||
| 185 | /* | 245 | /* |
| 186 | * arg is present, account for alignment padding | 246 | * arg is present, account for alignment padding |
| 187 | * 8-bit args can be at any alignment | ||
| 188 | * 16-bit args must start on 16-bit boundary | ||
| 189 | * 32-bit args must start on 32-bit boundary | ||
| 190 | * 64-bit args must start on 64-bit boundary | ||
| 191 | * | 247 | * |
| 192 | * note that total arg size can differ from alignment of | 248 | * Note that these alignments are relative to the start |
| 193 | * elements inside arg, so we use upper nybble of length | 249 | * of the radiotap header. There is no guarantee |
| 194 | * table to base alignment on | ||
| 195 | * | ||
| 196 | * also note: these alignments are ** relative to the | ||
| 197 | * start of the radiotap header **. There is no guarantee | ||
| 198 | * that the radiotap header itself is aligned on any | 250 | * that the radiotap header itself is aligned on any |
| 199 | * kind of boundary. | 251 | * kind of boundary. |
| 200 | * | 252 | * |
| 201 | * the above is why get_unaligned() is used to dereference | 253 | * The above is why get_unaligned() is used to dereference |
| 202 | * multibyte elements from the radiotap area | 254 | * multibyte elements from the radiotap area. |
| 203 | */ | 255 | */ |
| 204 | 256 | ||
| 205 | pad = (((ulong)iterator->arg) - | 257 | pad = ((unsigned long)iterator->_arg - |
| 206 | ((ulong)iterator->rtheader)) & | 258 | (unsigned long)iterator->_rtheader) & (align - 1); |
| 207 | ((rt_sizes[iterator->arg_index] >> 4) - 1); | ||
| 208 | 259 | ||
| 209 | if (pad) | 260 | if (pad) |
| 210 | iterator->arg += | 261 | iterator->_arg += align - pad; |
| 211 | (rt_sizes[iterator->arg_index] >> 4) - pad; | ||
| 212 | 262 | ||
| 213 | /* | 263 | /* |
| 214 | * this is what we will return to user, but we need to | 264 | * this is what we will return to user, but we need to |
| 215 | * move on first so next call has something fresh to test | 265 | * move on first so next call has something fresh to test |
| 216 | */ | 266 | */ |
| 217 | iterator->this_arg_index = iterator->arg_index; | 267 | iterator->this_arg_index = iterator->_arg_index; |
| 218 | iterator->this_arg = iterator->arg; | 268 | iterator->this_arg = iterator->_arg; |
| 219 | hit = 1; | 269 | iterator->this_arg_size = size; |
| 220 | 270 | ||
| 221 | /* internally move on the size of this arg */ | 271 | /* internally move on the size of this arg */ |
| 222 | iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; | 272 | iterator->_arg += size; |
| 223 | 273 | ||
| 224 | /* | 274 | /* |
| 225 | * check for insanity where we are given a bitmap that | 275 | * check for insanity where we are given a bitmap that |
| @@ -228,32 +278,73 @@ int ieee80211_radiotap_iterator_next( | |||
| 228 | * max_length on the last arg, never exceeding it. | 278 | * max_length on the last arg, never exceeding it. |
| 229 | */ | 279 | */ |
| 230 | 280 | ||
| 231 | if (((ulong)iterator->arg - (ulong)iterator->rtheader) > | 281 | if ((unsigned long)iterator->_arg - |
| 232 | iterator->max_length) | 282 | (unsigned long)iterator->_rtheader > |
| 283 | (unsigned long)iterator->_max_length) | ||
| 233 | return -EINVAL; | 284 | return -EINVAL; |
| 234 | 285 | ||
| 235 | next_entry: | 286 | /* these special ones are valid in each bitmap word */ |
| 236 | iterator->arg_index++; | 287 | switch (iterator->_arg_index % 32) { |
| 237 | if (unlikely((iterator->arg_index & 31) == 0)) { | 288 | case IEEE80211_RADIOTAP_VENDOR_NAMESPACE: |
| 238 | /* completed current u32 bitmap */ | 289 | iterator->_bitmap_shifter >>= 1; |
| 239 | if (iterator->bitmap_shifter & 1) { | 290 | iterator->_arg_index++; |
| 240 | /* b31 was set, there is more */ | 291 | |
| 241 | /* move to next u32 bitmap */ | 292 | iterator->_reset_on_ext = 1; |
| 242 | iterator->bitmap_shifter = | 293 | |
| 243 | get_unaligned_le32(iterator->next_bitmap); | 294 | vnslen = get_unaligned_le16(iterator->this_arg + 4); |
| 244 | iterator->next_bitmap++; | 295 | iterator->_next_ns_data = iterator->_arg + vnslen; |
| 245 | } else | 296 | oui = (*iterator->this_arg << 16) | |
| 246 | /* no more bitmaps: end */ | 297 | (*(iterator->this_arg + 1) << 8) | |
| 247 | iterator->arg_index = sizeof(rt_sizes); | 298 | *(iterator->this_arg + 2); |
| 248 | } else /* just try the next bit */ | 299 | subns = *(iterator->this_arg + 3); |
| 249 | iterator->bitmap_shifter >>= 1; | 300 | |
| 301 | find_ns(iterator, oui, subns); | ||
| 302 | |||
| 303 | iterator->is_radiotap_ns = 0; | ||
| 304 | /* allow parsers to show this information */ | ||
| 305 | iterator->this_arg_index = | ||
| 306 | IEEE80211_RADIOTAP_VENDOR_NAMESPACE; | ||
| 307 | iterator->this_arg_size += vnslen; | ||
| 308 | if ((unsigned long)iterator->this_arg + | ||
| 309 | iterator->this_arg_size - | ||
| 310 | (unsigned long)iterator->_rtheader > | ||
| 311 | (unsigned long)(unsigned long)iterator->_max_length) | ||
| 312 | return -EINVAL; | ||
| 313 | hit = 1; | ||
| 314 | break; | ||
| 315 | case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE: | ||
| 316 | iterator->_bitmap_shifter >>= 1; | ||
| 317 | iterator->_arg_index++; | ||
| 318 | |||
| 319 | iterator->_reset_on_ext = 1; | ||
| 320 | iterator->current_namespace = &radiotap_ns; | ||
| 321 | iterator->is_radiotap_ns = 1; | ||
| 322 | break; | ||
| 323 | case IEEE80211_RADIOTAP_EXT: | ||
| 324 | /* | ||
| 325 | * bit 31 was set, there is more | ||
| 326 | * -- move to next u32 bitmap | ||
| 327 | */ | ||
| 328 | iterator->_bitmap_shifter = | ||
| 329 | get_unaligned_le32(iterator->_next_bitmap); | ||
| 330 | iterator->_next_bitmap++; | ||
| 331 | if (iterator->_reset_on_ext) | ||
| 332 | iterator->_arg_index = 0; | ||
| 333 | else | ||
| 334 | iterator->_arg_index++; | ||
| 335 | iterator->_reset_on_ext = 0; | ||
| 336 | break; | ||
| 337 | default: | ||
| 338 | /* we've got a hit! */ | ||
| 339 | hit = 1; | ||
| 340 | next_entry: | ||
| 341 | iterator->_bitmap_shifter >>= 1; | ||
| 342 | iterator->_arg_index++; | ||
| 343 | } | ||
| 250 | 344 | ||
| 251 | /* if we found a valid arg earlier, return it now */ | 345 | /* if we found a valid arg earlier, return it now */ |
| 252 | if (hit) | 346 | if (hit) |
| 253 | return 0; | 347 | return 0; |
| 254 | } | 348 | } |
| 255 | |||
| 256 | /* we don't know how to handle any more args, we're done */ | ||
| 257 | return -ENOENT; | ||
| 258 | } | 349 | } |
| 259 | EXPORT_SYMBOL(ieee80211_radiotap_iterator_next); | 350 | EXPORT_SYMBOL(ieee80211_radiotap_iterator_next); |
