nl80211: fix possible fd leak in nl80211_hostapd_hup()
[project/iwinfo.git] / iwinfo_wext.h
1 /*
2  * iwinfo - Wireless Information Library - Linux Wireless Extension Headers
3  *
4  *   Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
5  *
6  * The iwinfo library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License version 2
8  * as published by the Free Software Foundation.
9  *
10  * The iwinfo library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
17  */
18
19 #ifndef __IWINFO_WEXT_SCAN_H_
20 #define __IWINFO_WEXT_SCAN_H_
21
22 #include <fcntl.h>
23
24 #include "iwinfo.h"
25 #include "iwinfo/utils.h"
26 #include "api/wext.h"
27
28
29 typedef struct stream_descr
30 {
31   char *        end;            /* End of the stream */
32   char *        current;        /* Current event in stream of events */
33   char *        value;          /* Current value in event */
34 } stream_descr;
35
36 /*
37  * Describe how a standard IOCTL looks like.
38  */
39 struct iw_ioctl_description
40 {
41         uint8_t header_type;            /* NULL, iw_point or other */
42         uint8_t token_type;             /* Future */
43         uint16_t        token_size;             /* Granularity of payload */
44         uint16_t        min_tokens;             /* Min acceptable token number */
45         uint16_t        max_tokens;             /* Max acceptable token number */
46         uint32_t        flags;                  /* Special handling of the request */
47 };
48
49 /* Type of headers we know about (basically union iwreq_data) */
50 #define IW_HEADER_TYPE_NULL     0       /* Not available */
51 #define IW_HEADER_TYPE_CHAR     2       /* char [IFNAMSIZ] */
52 #define IW_HEADER_TYPE_UINT     4       /* __u32 */
53 #define IW_HEADER_TYPE_FREQ     5       /* struct iw_freq */
54 #define IW_HEADER_TYPE_ADDR     6       /* struct sockaddr */
55 #define IW_HEADER_TYPE_POINT    8       /* struct iw_point */
56 #define IW_HEADER_TYPE_PARAM    9       /* struct iw_param */
57 #define IW_HEADER_TYPE_QUAL     10      /* struct iw_quality */
58
59 /* Handling flags */
60 /* Most are not implemented. I just use them as a reminder of some
61  * cool features we might need one day ;-) */
62 #define IW_DESCR_FLAG_NONE      0x0000  /* Obvious */
63 /* Wrapper level flags */
64 #define IW_DESCR_FLAG_DUMP      0x0001  /* Not part of the dump command */
65 #define IW_DESCR_FLAG_EVENT     0x0002  /* Generate an event on SET */
66 #define IW_DESCR_FLAG_RESTRICT  0x0004  /* GET : request is ROOT only */
67                                 /* SET : Omit payload from generated iwevent */
68 #define IW_DESCR_FLAG_NOMAX     0x0008  /* GET : no limit on request size */
69 /* Driver level flags */
70 #define IW_DESCR_FLAG_WAIT      0x0100  /* Wait for driver event */
71
72
73 /*
74  * Meta-data about all the standard Wireless Extension request we
75  * know about.
76  */
77 static const struct iw_ioctl_description standard_ioctl_descr[] = {
78         [SIOCSIWCOMMIT  - SIOCIWFIRST] = {
79                 .header_type    = IW_HEADER_TYPE_NULL,
80         },
81         [SIOCGIWNAME    - SIOCIWFIRST] = {
82                 .header_type    = IW_HEADER_TYPE_CHAR,
83                 .flags          = IW_DESCR_FLAG_DUMP,
84         },
85         [SIOCSIWNWID    - SIOCIWFIRST] = {
86                 .header_type    = IW_HEADER_TYPE_PARAM,
87                 .flags          = IW_DESCR_FLAG_EVENT,
88         },
89         [SIOCGIWNWID    - SIOCIWFIRST] = {
90                 .header_type    = IW_HEADER_TYPE_PARAM,
91                 .flags          = IW_DESCR_FLAG_DUMP,
92         },
93         [SIOCSIWFREQ    - SIOCIWFIRST] = {
94                 .header_type    = IW_HEADER_TYPE_FREQ,
95                 .flags          = IW_DESCR_FLAG_EVENT,
96         },
97         [SIOCGIWFREQ    - SIOCIWFIRST] = {
98                 .header_type    = IW_HEADER_TYPE_FREQ,
99                 .flags          = IW_DESCR_FLAG_DUMP,
100         },
101         [SIOCSIWMODE    - SIOCIWFIRST] = {
102                 .header_type    = IW_HEADER_TYPE_UINT,
103                 .flags          = IW_DESCR_FLAG_EVENT,
104         },
105         [SIOCGIWMODE    - SIOCIWFIRST] = {
106                 .header_type    = IW_HEADER_TYPE_UINT,
107                 .flags          = IW_DESCR_FLAG_DUMP,
108         },
109         [SIOCSIWSENS    - SIOCIWFIRST] = {
110                 .header_type    = IW_HEADER_TYPE_PARAM,
111         },
112         [SIOCGIWSENS    - SIOCIWFIRST] = {
113                 .header_type    = IW_HEADER_TYPE_PARAM,
114         },
115         [SIOCSIWRANGE   - SIOCIWFIRST] = {
116                 .header_type    = IW_HEADER_TYPE_NULL,
117         },
118         [SIOCGIWRANGE   - SIOCIWFIRST] = {
119                 .header_type    = IW_HEADER_TYPE_POINT,
120                 .token_size     = 1,
121                 .max_tokens     = sizeof(struct iw_range),
122                 .flags          = IW_DESCR_FLAG_DUMP,
123         },
124         [SIOCSIWPRIV    - SIOCIWFIRST] = {
125                 .header_type    = IW_HEADER_TYPE_NULL,
126         },
127         [SIOCGIWPRIV    - SIOCIWFIRST] = { /* (handled directly by us) */
128                 .header_type    = IW_HEADER_TYPE_NULL,
129         },
130         [SIOCSIWSTATS   - SIOCIWFIRST] = {
131                 .header_type    = IW_HEADER_TYPE_NULL,
132         },
133         [SIOCGIWSTATS   - SIOCIWFIRST] = { /* (handled directly by us) */
134                 .header_type    = IW_HEADER_TYPE_NULL,
135                 .flags          = IW_DESCR_FLAG_DUMP,
136         },
137         [SIOCSIWSPY     - SIOCIWFIRST] = {
138                 .header_type    = IW_HEADER_TYPE_POINT,
139                 .token_size     = sizeof(struct sockaddr),
140                 .max_tokens     = IW_MAX_SPY,
141         },
142         [SIOCGIWSPY     - SIOCIWFIRST] = {
143                 .header_type    = IW_HEADER_TYPE_POINT,
144                 .token_size     = sizeof(struct sockaddr) +
145                                   sizeof(struct iw_quality),
146                 .max_tokens     = IW_MAX_SPY,
147         },
148         [SIOCSIWTHRSPY  - SIOCIWFIRST] = {
149                 .header_type    = IW_HEADER_TYPE_POINT,
150                 .token_size     = sizeof(struct iw_thrspy),
151                 .min_tokens     = 1,
152                 .max_tokens     = 1,
153         },
154         [SIOCGIWTHRSPY  - SIOCIWFIRST] = {
155                 .header_type    = IW_HEADER_TYPE_POINT,
156                 .token_size     = sizeof(struct iw_thrspy),
157                 .min_tokens     = 1,
158                 .max_tokens     = 1,
159         },
160         [SIOCSIWAP      - SIOCIWFIRST] = {
161                 .header_type    = IW_HEADER_TYPE_ADDR,
162         },
163         [SIOCGIWAP      - SIOCIWFIRST] = {
164                 .header_type    = IW_HEADER_TYPE_ADDR,
165                 .flags          = IW_DESCR_FLAG_DUMP,
166         },
167         [SIOCSIWMLME    - SIOCIWFIRST] = {
168                 .header_type    = IW_HEADER_TYPE_POINT,
169                 .token_size     = 1,
170                 .min_tokens     = sizeof(struct iw_mlme),
171                 .max_tokens     = sizeof(struct iw_mlme),
172         },
173         [SIOCGIWAPLIST  - SIOCIWFIRST] = {
174                 .header_type    = IW_HEADER_TYPE_POINT,
175                 .token_size     = sizeof(struct sockaddr) +
176                                   sizeof(struct iw_quality),
177                 .max_tokens     = IW_MAX_AP,
178                 .flags          = IW_DESCR_FLAG_NOMAX,
179         },
180         [SIOCSIWSCAN    - SIOCIWFIRST] = {
181                 .header_type    = IW_HEADER_TYPE_POINT,
182                 .token_size     = 1,
183                 .min_tokens     = 0,
184                 .max_tokens     = sizeof(struct iw_scan_req),
185         },
186         [SIOCGIWSCAN    - SIOCIWFIRST] = {
187                 .header_type    = IW_HEADER_TYPE_POINT,
188                 .token_size     = 1,
189                 .max_tokens     = IW_SCAN_MAX_DATA,
190                 .flags          = IW_DESCR_FLAG_NOMAX,
191         },
192         [SIOCSIWESSID   - SIOCIWFIRST] = {
193                 .header_type    = IW_HEADER_TYPE_POINT,
194                 .token_size     = 1,
195                 .max_tokens     = IW_ESSID_MAX_SIZE + 1,
196                 .flags          = IW_DESCR_FLAG_EVENT,
197         },
198         [SIOCGIWESSID   - SIOCIWFIRST] = {
199                 .header_type    = IW_HEADER_TYPE_POINT,
200                 .token_size     = 1,
201                 .max_tokens     = IW_ESSID_MAX_SIZE + 1,
202                 .flags          = IW_DESCR_FLAG_DUMP,
203         },
204         [SIOCSIWNICKN   - SIOCIWFIRST] = {
205                 .header_type    = IW_HEADER_TYPE_POINT,
206                 .token_size     = 1,
207                 .max_tokens     = IW_ESSID_MAX_SIZE + 1,
208         },
209         [SIOCGIWNICKN   - SIOCIWFIRST] = {
210                 .header_type    = IW_HEADER_TYPE_POINT,
211                 .token_size     = 1,
212                 .max_tokens     = IW_ESSID_MAX_SIZE + 1,
213         },
214         [SIOCSIWRATE    - SIOCIWFIRST] = {
215                 .header_type    = IW_HEADER_TYPE_PARAM,
216         },
217         [SIOCGIWRATE    - SIOCIWFIRST] = {
218                 .header_type    = IW_HEADER_TYPE_PARAM,
219         },
220         [SIOCSIWRTS     - SIOCIWFIRST] = {
221                 .header_type    = IW_HEADER_TYPE_PARAM,
222         },
223         [SIOCGIWRTS     - SIOCIWFIRST] = {
224                 .header_type    = IW_HEADER_TYPE_PARAM,
225         },
226         [SIOCSIWFRAG    - SIOCIWFIRST] = {
227                 .header_type    = IW_HEADER_TYPE_PARAM,
228         },
229         [SIOCGIWFRAG    - SIOCIWFIRST] = {
230                 .header_type    = IW_HEADER_TYPE_PARAM,
231         },
232         [SIOCSIWTXPOW   - SIOCIWFIRST] = {
233                 .header_type    = IW_HEADER_TYPE_PARAM,
234         },
235         [SIOCGIWTXPOW   - SIOCIWFIRST] = {
236                 .header_type    = IW_HEADER_TYPE_PARAM,
237         },
238         [SIOCSIWRETRY   - SIOCIWFIRST] = {
239                 .header_type    = IW_HEADER_TYPE_PARAM,
240         },
241         [SIOCGIWRETRY   - SIOCIWFIRST] = {
242                 .header_type    = IW_HEADER_TYPE_PARAM,
243         },
244         [SIOCSIWENCODE  - SIOCIWFIRST] = {
245                 .header_type    = IW_HEADER_TYPE_POINT,
246                 .token_size     = 1,
247                 .max_tokens     = IW_ENCODING_TOKEN_MAX,
248                 .flags          = IW_DESCR_FLAG_EVENT | IW_DESCR_FLAG_RESTRICT,
249         },
250         [SIOCGIWENCODE  - SIOCIWFIRST] = {
251                 .header_type    = IW_HEADER_TYPE_POINT,
252                 .token_size     = 1,
253                 .max_tokens     = IW_ENCODING_TOKEN_MAX,
254                 .flags          = IW_DESCR_FLAG_DUMP | IW_DESCR_FLAG_RESTRICT,
255         },
256         [SIOCSIWPOWER   - SIOCIWFIRST] = {
257                 .header_type    = IW_HEADER_TYPE_PARAM,
258         },
259         [SIOCGIWPOWER   - SIOCIWFIRST] = {
260                 .header_type    = IW_HEADER_TYPE_PARAM,
261         },
262         [SIOCSIWMODUL   - SIOCIWFIRST] = {
263                 .header_type    = IW_HEADER_TYPE_PARAM,
264         },
265         [SIOCGIWMODUL   - SIOCIWFIRST] = {
266                 .header_type    = IW_HEADER_TYPE_PARAM,
267         },
268         [SIOCSIWGENIE   - SIOCIWFIRST] = {
269                 .header_type    = IW_HEADER_TYPE_POINT,
270                 .token_size     = 1,
271                 .max_tokens     = IW_GENERIC_IE_MAX,
272         },
273         [SIOCGIWGENIE   - SIOCIWFIRST] = {
274                 .header_type    = IW_HEADER_TYPE_POINT,
275                 .token_size     = 1,
276                 .max_tokens     = IW_GENERIC_IE_MAX,
277         },
278         [SIOCSIWAUTH    - SIOCIWFIRST] = {
279                 .header_type    = IW_HEADER_TYPE_PARAM,
280         },
281         [SIOCGIWAUTH    - SIOCIWFIRST] = {
282                 .header_type    = IW_HEADER_TYPE_PARAM,
283         },
284         [SIOCSIWENCODEEXT - SIOCIWFIRST] = {
285                 .header_type    = IW_HEADER_TYPE_POINT,
286                 .token_size     = 1,
287                 .min_tokens     = sizeof(struct iw_encode_ext),
288                 .max_tokens     = sizeof(struct iw_encode_ext) +
289                                   IW_ENCODING_TOKEN_MAX,
290         },
291         [SIOCGIWENCODEEXT - SIOCIWFIRST] = {
292                 .header_type    = IW_HEADER_TYPE_POINT,
293                 .token_size     = 1,
294                 .min_tokens     = sizeof(struct iw_encode_ext),
295                 .max_tokens     = sizeof(struct iw_encode_ext) +
296                                   IW_ENCODING_TOKEN_MAX,
297         },
298         [SIOCSIWPMKSA - SIOCIWFIRST] = {
299                 .header_type    = IW_HEADER_TYPE_POINT,
300                 .token_size     = 1,
301                 .min_tokens     = sizeof(struct iw_pmksa),
302                 .max_tokens     = sizeof(struct iw_pmksa),
303         },
304 };
305
306 /*
307  * Meta-data about all the additional standard Wireless Extension events
308  * we know about.
309  */
310 static const struct iw_ioctl_description standard_event_descr[] = {
311         [IWEVTXDROP     - IWEVFIRST] = {
312                 .header_type    = IW_HEADER_TYPE_ADDR,
313         },
314         [IWEVQUAL       - IWEVFIRST] = {
315                 .header_type    = IW_HEADER_TYPE_QUAL,
316         },
317         [IWEVCUSTOM     - IWEVFIRST] = {
318                 .header_type    = IW_HEADER_TYPE_POINT,
319                 .token_size     = 1,
320                 .max_tokens     = IW_CUSTOM_MAX,
321         },
322         [IWEVREGISTERED - IWEVFIRST] = {
323                 .header_type    = IW_HEADER_TYPE_ADDR,
324         },
325         [IWEVEXPIRED    - IWEVFIRST] = {
326                 .header_type    = IW_HEADER_TYPE_ADDR,
327         },
328         [IWEVGENIE      - IWEVFIRST] = {
329                 .header_type    = IW_HEADER_TYPE_POINT,
330                 .token_size     = 1,
331                 .max_tokens     = IW_GENERIC_IE_MAX,
332         },
333         [IWEVMICHAELMICFAILURE  - IWEVFIRST] = {
334                 .header_type    = IW_HEADER_TYPE_POINT,
335                 .token_size     = 1,
336                 .max_tokens     = sizeof(struct iw_michaelmicfailure),
337         },
338         [IWEVASSOCREQIE - IWEVFIRST] = {
339                 .header_type    = IW_HEADER_TYPE_POINT,
340                 .token_size     = 1,
341                 .max_tokens     = IW_GENERIC_IE_MAX,
342         },
343         [IWEVASSOCRESPIE        - IWEVFIRST] = {
344                 .header_type    = IW_HEADER_TYPE_POINT,
345                 .token_size     = 1,
346                 .max_tokens     = IW_GENERIC_IE_MAX,
347         },
348         [IWEVPMKIDCAND  - IWEVFIRST] = {
349                 .header_type    = IW_HEADER_TYPE_POINT,
350                 .token_size     = 1,
351                 .max_tokens     = sizeof(struct iw_pmkid_cand),
352         },
353 };
354
355 /* Size (in bytes) of various events */
356 static const int event_type_size[] = {
357         IW_EV_LCP_PK_LEN,       /* IW_HEADER_TYPE_NULL */
358         0,
359         IW_EV_CHAR_PK_LEN,      /* IW_HEADER_TYPE_CHAR */
360         0,
361         IW_EV_UINT_PK_LEN,      /* IW_HEADER_TYPE_UINT */
362         IW_EV_FREQ_PK_LEN,      /* IW_HEADER_TYPE_FREQ */
363         IW_EV_ADDR_PK_LEN,      /* IW_HEADER_TYPE_ADDR */
364         0,
365         IW_EV_POINT_PK_LEN,     /* Without variable payload */
366         IW_EV_PARAM_PK_LEN,     /* IW_HEADER_TYPE_PARAM */
367         IW_EV_QUAL_PK_LEN,      /* IW_HEADER_TYPE_QUAL */
368 };
369
370
371 static const unsigned int standard_ioctl_num =
372         (sizeof(standard_ioctl_descr) / sizeof(struct iw_ioctl_description));
373
374 static const unsigned int standard_event_num =
375         (sizeof(standard_event_descr) / sizeof(struct iw_ioctl_description));
376
377 #define IW_IE_CYPHER_NUM        8
378 #define IW_IE_KEY_MGMT_NUM      3
379
380 int wext_get_scanlist(const char *ifname, char *buf, int *len);
381
382 #endif