This source file includes following definitions.
- ieee80211_radiotap_iterator_init
- find_ns
- ieee80211_radiotap_iterator_next
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #include <linux/kernel.h>
18 #include <linux/export.h>
19 #include <net/cfg80211.h>
20 #include <net/ieee80211_radiotap.h>
21 #include <asm/unaligned.h>
22
23
24
25 static const struct radiotap_align_size rtap_namespace_sizes[] = {
26 [IEEE80211_RADIOTAP_TSFT] = { .align = 8, .size = 8, },
27 [IEEE80211_RADIOTAP_FLAGS] = { .align = 1, .size = 1, },
28 [IEEE80211_RADIOTAP_RATE] = { .align = 1, .size = 1, },
29 [IEEE80211_RADIOTAP_CHANNEL] = { .align = 2, .size = 4, },
30 [IEEE80211_RADIOTAP_FHSS] = { .align = 2, .size = 2, },
31 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = { .align = 1, .size = 1, },
32 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = { .align = 1, .size = 1, },
33 [IEEE80211_RADIOTAP_LOCK_QUALITY] = { .align = 2, .size = 2, },
34 [IEEE80211_RADIOTAP_TX_ATTENUATION] = { .align = 2, .size = 2, },
35 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = { .align = 2, .size = 2, },
36 [IEEE80211_RADIOTAP_DBM_TX_POWER] = { .align = 1, .size = 1, },
37 [IEEE80211_RADIOTAP_ANTENNA] = { .align = 1, .size = 1, },
38 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = { .align = 1, .size = 1, },
39 [IEEE80211_RADIOTAP_DB_ANTNOISE] = { .align = 1, .size = 1, },
40 [IEEE80211_RADIOTAP_RX_FLAGS] = { .align = 2, .size = 2, },
41 [IEEE80211_RADIOTAP_TX_FLAGS] = { .align = 2, .size = 2, },
42 [IEEE80211_RADIOTAP_RTS_RETRIES] = { .align = 1, .size = 1, },
43 [IEEE80211_RADIOTAP_DATA_RETRIES] = { .align = 1, .size = 1, },
44 [IEEE80211_RADIOTAP_MCS] = { .align = 1, .size = 3, },
45 [IEEE80211_RADIOTAP_AMPDU_STATUS] = { .align = 4, .size = 8, },
46 [IEEE80211_RADIOTAP_VHT] = { .align = 2, .size = 12, },
47
48
49
50 };
51
52 static const struct ieee80211_radiotap_namespace radiotap_ns = {
53 .n_bits = ARRAY_SIZE(rtap_namespace_sizes),
54 .align_size = rtap_namespace_sizes,
55 };
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 int ieee80211_radiotap_iterator_init(
97 struct ieee80211_radiotap_iterator *iterator,
98 struct ieee80211_radiotap_header *radiotap_header,
99 int max_length, const struct ieee80211_radiotap_vendor_namespaces *vns)
100 {
101
102 if (max_length < sizeof(struct ieee80211_radiotap_header))
103 return -EINVAL;
104
105
106 if (radiotap_header->it_version)
107 return -EINVAL;
108
109
110 if (max_length < get_unaligned_le16(&radiotap_header->it_len))
111 return -EINVAL;
112
113 iterator->_rtheader = radiotap_header;
114 iterator->_max_length = get_unaligned_le16(&radiotap_header->it_len);
115 iterator->_arg_index = 0;
116 iterator->_bitmap_shifter = get_unaligned_le32(&radiotap_header->it_present);
117 iterator->_arg = (uint8_t *)radiotap_header + sizeof(*radiotap_header);
118 iterator->_reset_on_ext = 0;
119 iterator->_next_bitmap = &radiotap_header->it_present;
120 iterator->_next_bitmap++;
121 iterator->_vns = vns;
122 iterator->current_namespace = &radiotap_ns;
123 iterator->is_radiotap_ns = 1;
124
125
126
127 if (iterator->_bitmap_shifter & (1<<IEEE80211_RADIOTAP_EXT)) {
128 if ((unsigned long)iterator->_arg -
129 (unsigned long)iterator->_rtheader + sizeof(uint32_t) >
130 (unsigned long)iterator->_max_length)
131 return -EINVAL;
132 while (get_unaligned_le32(iterator->_arg) &
133 (1 << IEEE80211_RADIOTAP_EXT)) {
134 iterator->_arg += sizeof(uint32_t);
135
136
137
138
139
140
141
142 if ((unsigned long)iterator->_arg -
143 (unsigned long)iterator->_rtheader +
144 sizeof(uint32_t) >
145 (unsigned long)iterator->_max_length)
146 return -EINVAL;
147 }
148
149 iterator->_arg += sizeof(uint32_t);
150
151
152
153
154
155
156 }
157
158 iterator->this_arg = iterator->_arg;
159
160
161
162 return 0;
163 }
164 EXPORT_SYMBOL(ieee80211_radiotap_iterator_init);
165
166 static void find_ns(struct ieee80211_radiotap_iterator *iterator,
167 uint32_t oui, uint8_t subns)
168 {
169 int i;
170
171 iterator->current_namespace = NULL;
172
173 if (!iterator->_vns)
174 return;
175
176 for (i = 0; i < iterator->_vns->n_ns; i++) {
177 if (iterator->_vns->ns[i].oui != oui)
178 continue;
179 if (iterator->_vns->ns[i].subns != subns)
180 continue;
181
182 iterator->current_namespace = &iterator->_vns->ns[i];
183 break;
184 }
185 }
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212 int ieee80211_radiotap_iterator_next(
213 struct ieee80211_radiotap_iterator *iterator)
214 {
215 while (1) {
216 int hit = 0;
217 int pad, align, size, subns;
218 uint32_t oui;
219
220
221 if ((iterator->_arg_index % 32) == IEEE80211_RADIOTAP_EXT &&
222 !(iterator->_bitmap_shifter & 1))
223 return -ENOENT;
224
225 if (!(iterator->_bitmap_shifter & 1))
226 goto next_entry;
227
228
229 switch (iterator->_arg_index % 32) {
230 case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE:
231 case IEEE80211_RADIOTAP_EXT:
232 align = 1;
233 size = 0;
234 break;
235 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE:
236 align = 2;
237 size = 6;
238 break;
239 default:
240 if (!iterator->current_namespace ||
241 iterator->_arg_index >= iterator->current_namespace->n_bits) {
242 if (iterator->current_namespace == &radiotap_ns)
243 return -ENOENT;
244 align = 0;
245 } else {
246 align = iterator->current_namespace->align_size[iterator->_arg_index].align;
247 size = iterator->current_namespace->align_size[iterator->_arg_index].size;
248 }
249 if (!align) {
250
251 iterator->_arg = iterator->_next_ns_data;
252
253 iterator->current_namespace = NULL;
254 goto next_entry;
255 }
256 break;
257 }
258
259
260
261
262
263
264
265
266
267
268
269
270
271 pad = ((unsigned long)iterator->_arg -
272 (unsigned long)iterator->_rtheader) & (align - 1);
273
274 if (pad)
275 iterator->_arg += align - pad;
276
277 if (iterator->_arg_index % 32 == IEEE80211_RADIOTAP_VENDOR_NAMESPACE) {
278 int vnslen;
279
280 if ((unsigned long)iterator->_arg + size -
281 (unsigned long)iterator->_rtheader >
282 (unsigned long)iterator->_max_length)
283 return -EINVAL;
284
285 oui = (*iterator->_arg << 16) |
286 (*(iterator->_arg + 1) << 8) |
287 *(iterator->_arg + 2);
288 subns = *(iterator->_arg + 3);
289
290 find_ns(iterator, oui, subns);
291
292 vnslen = get_unaligned_le16(iterator->_arg + 4);
293 iterator->_next_ns_data = iterator->_arg + size + vnslen;
294 if (!iterator->current_namespace)
295 size += vnslen;
296 }
297
298
299
300
301
302 iterator->this_arg_index = iterator->_arg_index;
303 iterator->this_arg = iterator->_arg;
304 iterator->this_arg_size = size;
305
306
307 iterator->_arg += size;
308
309
310
311
312
313
314
315
316 if ((unsigned long)iterator->_arg -
317 (unsigned long)iterator->_rtheader >
318 (unsigned long)iterator->_max_length)
319 return -EINVAL;
320
321
322 switch (iterator->_arg_index % 32) {
323 case IEEE80211_RADIOTAP_VENDOR_NAMESPACE:
324 iterator->_reset_on_ext = 1;
325
326 iterator->is_radiotap_ns = 0;
327
328
329
330
331
332
333 iterator->this_arg_index =
334 IEEE80211_RADIOTAP_VENDOR_NAMESPACE;
335 if (!iterator->current_namespace)
336 hit = 1;
337 goto next_entry;
338 case IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE:
339 iterator->_reset_on_ext = 1;
340 iterator->current_namespace = &radiotap_ns;
341 iterator->is_radiotap_ns = 1;
342 goto next_entry;
343 case IEEE80211_RADIOTAP_EXT:
344
345
346
347
348 iterator->_bitmap_shifter =
349 get_unaligned_le32(iterator->_next_bitmap);
350 iterator->_next_bitmap++;
351 if (iterator->_reset_on_ext)
352 iterator->_arg_index = 0;
353 else
354 iterator->_arg_index++;
355 iterator->_reset_on_ext = 0;
356 break;
357 default:
358
359 hit = 1;
360 next_entry:
361 iterator->_bitmap_shifter >>= 1;
362 iterator->_arg_index++;
363 }
364
365
366 if (hit)
367 return 0;
368 }
369 }
370 EXPORT_SYMBOL(ieee80211_radiotap_iterator_next);