nl80211: propagate netlink errors to callers
[project/iwinfo.git] / iwinfo_lua.c
1 /*
2  * iwinfo - Wireless Information Library - Lua Bindings
3  *
4  *   Copyright (C) 2009 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 #include "iwinfo/lua.h"
20
21
22 /* Determine type */
23 static int iwinfo_L_type(lua_State *L)
24 {
25         const char *ifname = luaL_checkstring(L, 1);
26         const char *type = iwinfo_type(ifname);
27
28         if (type)
29                 lua_pushstring(L, type);
30         else
31                 lua_pushnil(L);
32
33         return 1;
34 }
35
36 /* Shutdown backends */
37 static int iwinfo_L__gc(lua_State *L)
38 {
39         iwinfo_finish();
40         return 0;
41 }
42
43 /*
44  * Build a short textual description of the crypto info
45  */
46
47 static char * iwinfo_crypto_print_ciphers(int ciphers)
48 {
49         static char str[128] = { 0 };
50         char *pos = str;
51
52         if (ciphers & IWINFO_CIPHER_WEP40)
53                 pos += sprintf(pos, "WEP-40, ");
54
55         if (ciphers & IWINFO_CIPHER_WEP104)
56                 pos += sprintf(pos, "WEP-104, ");
57
58         if (ciphers & IWINFO_CIPHER_TKIP)
59                 pos += sprintf(pos, "TKIP, ");
60
61         if (ciphers & IWINFO_CIPHER_CCMP)
62                 pos += sprintf(pos, "CCMP, ");
63
64         if (ciphers & IWINFO_CIPHER_WRAP)
65                 pos += sprintf(pos, "WRAP, ");
66
67         if (ciphers & IWINFO_CIPHER_AESOCB)
68                 pos += sprintf(pos, "AES-OCB, ");
69
70         if (ciphers & IWINFO_CIPHER_CKIP)
71                 pos += sprintf(pos, "CKIP, ");
72
73         if (!ciphers || (ciphers & IWINFO_CIPHER_NONE))
74                 pos += sprintf(pos, "NONE, ");
75
76         *(pos - 2) = 0;
77
78         return str;
79 }
80
81 static char * iwinfo_crypto_print_suites(int suites)
82 {
83         static char str[64] = { 0 };
84         char *pos = str;
85
86         if (suites & IWINFO_KMGMT_PSK)
87                 pos += sprintf(pos, "PSK/");
88
89         if (suites & IWINFO_KMGMT_8021x)
90                 pos += sprintf(pos, "802.1X/");
91
92         if (!suites || (suites & IWINFO_KMGMT_NONE))
93                 pos += sprintf(pos, "NONE/");
94
95         *(pos - 1) = 0;
96
97         return str;
98 }
99
100 static char * iwinfo_crypto_desc(struct iwinfo_crypto_entry *c)
101 {
102         static char desc[512] = { 0 };
103
104         if (c)
105         {
106                 if (c->enabled)
107                 {
108                         /* WEP */
109                         if (c->auth_algs && !c->wpa_version)
110                         {
111                                 if ((c->auth_algs & IWINFO_AUTH_OPEN) &&
112                                     (c->auth_algs & IWINFO_AUTH_SHARED))
113                                 {
114                                         sprintf(desc, "WEP Open/Shared (%s)",
115                                                 iwinfo_crypto_print_ciphers(c->pair_ciphers));
116                                 }
117                                 else if (c->auth_algs & IWINFO_AUTH_OPEN)
118                                 {
119                                         sprintf(desc, "WEP Open System (%s)",
120                                                 iwinfo_crypto_print_ciphers(c->pair_ciphers));
121                                 }
122                                 else if (c->auth_algs & IWINFO_AUTH_SHARED)
123                                 {
124                                         sprintf(desc, "WEP Shared Auth (%s)",
125                                                 iwinfo_crypto_print_ciphers(c->pair_ciphers));
126                                 }
127                         }
128
129                         /* WPA */
130                         else if (c->wpa_version)
131                         {
132                                 switch (c->wpa_version) {
133                                         case 3:
134                                                 sprintf(desc, "mixed WPA/WPA2 %s (%s)",
135                                                         iwinfo_crypto_print_suites(c->auth_suites),
136                                                         iwinfo_crypto_print_ciphers(
137                                                                 c->pair_ciphers | c->group_ciphers));
138                                                 break;
139
140                                         case 2:
141                                                 sprintf(desc, "WPA2 %s (%s)",
142                                                         iwinfo_crypto_print_suites(c->auth_suites),
143                                                         iwinfo_crypto_print_ciphers(
144                                                                 c->pair_ciphers | c->group_ciphers));
145                                                 break;
146
147                                         case 1:
148                                                 sprintf(desc, "WPA %s (%s)",
149                                                         iwinfo_crypto_print_suites(c->auth_suites),
150                                                         iwinfo_crypto_print_ciphers(
151                                                                 c->pair_ciphers | c->group_ciphers));
152                                                 break;
153                                 }
154                         }
155                         else
156                         {
157                                 sprintf(desc, "None");
158                         }
159                 }
160                 else
161                 {
162                         sprintf(desc, "None");
163                 }
164         }
165         else
166         {
167                 sprintf(desc, "Unknown");
168         }
169
170         return desc;
171 }
172
173 /* Build Lua table from crypto data */
174 static void iwinfo_L_cryptotable(lua_State *L, struct iwinfo_crypto_entry *c)
175 {
176         int i, j;
177
178         lua_newtable(L);
179
180         lua_pushboolean(L, c->enabled);
181         lua_setfield(L, -2, "enabled");
182
183         lua_pushstring(L, iwinfo_crypto_desc(c));
184         lua_setfield(L, -2, "description");
185
186         lua_pushboolean(L, (c->enabled && !c->wpa_version));
187         lua_setfield(L, -2, "wep");
188
189         lua_pushinteger(L, c->wpa_version);
190         lua_setfield(L, -2, "wpa");
191
192         lua_newtable(L);
193         for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_CIPHER_NAMES); i++)
194         {
195                 if (c->pair_ciphers & (1 << i))
196                 {
197                         lua_pushstring(L, IWINFO_CIPHER_NAMES[i]);
198                         lua_rawseti(L, -2, j++);
199                 }
200         }
201         lua_setfield(L, -2, "pair_ciphers");
202
203         lua_newtable(L);
204         for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_CIPHER_NAMES); i++)
205         {
206                 if (c->group_ciphers & (1 << i))
207                 {
208                         lua_pushstring(L, IWINFO_CIPHER_NAMES[i]);
209                         lua_rawseti(L, -2, j++);
210                 }
211         }
212         lua_setfield(L, -2, "group_ciphers");
213
214         lua_newtable(L);
215         for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_KMGMT_NAMES); i++)
216         {
217                 if (c->auth_suites & (1 << i))
218                 {
219                         lua_pushstring(L, IWINFO_KMGMT_NAMES[i]);
220                         lua_rawseti(L, -2, j++);
221                 }
222         }
223         lua_setfield(L, -2, "auth_suites");
224
225         lua_newtable(L);
226         for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_AUTH_NAMES); i++)
227         {
228                 if (c->auth_algs & (1 << i))
229                 {
230                         lua_pushstring(L, IWINFO_AUTH_NAMES[i]);
231                         lua_rawseti(L, -2, j++);
232                 }
233         }
234         lua_setfield(L, -2, "auth_algs");
235 }
236
237
238 /* Wrapper for mode */
239 static int iwinfo_L_mode(lua_State *L, int (*func)(const char *, int *))
240 {
241         int mode;
242         const char *ifname = luaL_checkstring(L, 1);
243
244         if ((*func)(ifname, &mode))
245                 mode = IWINFO_OPMODE_UNKNOWN;
246
247         lua_pushstring(L, IWINFO_OPMODE_NAMES[mode]);
248         return 1;
249 }
250
251 static void set_rateinfo(lua_State *L, struct iwinfo_rate_entry *r, bool rx)
252 {
253         lua_pushnumber(L, r->rate);
254         lua_setfield(L, -2, rx ? "rx_rate" : "tx_rate");
255
256         lua_pushboolean(L, r->is_ht);
257         lua_setfield(L, -2, rx ? "rx_ht" : "tx_ht");
258
259         lua_pushboolean(L, r->is_vht);
260         lua_setfield(L, -2, rx ? "rx_vht" : "tx_vht");
261
262         lua_pushnumber(L, r->mhz);
263         lua_setfield(L, -2, rx ? "rx_mhz" : "tx_mhz");
264
265         if (r->is_ht)
266         {
267                 lua_pushboolean(L, r->is_40mhz);
268                 lua_setfield(L, -2, rx ? "rx_40mhz" : "tx_40mhz");
269
270                 lua_pushnumber(L, r->mcs);
271                 lua_setfield(L, -2, rx ? "rx_mcs" : "tx_mcs");
272
273                 lua_pushboolean(L, r->is_short_gi);
274                 lua_setfield(L, -2, rx ? "rx_short_gi" : "tx_short_gi");
275         }
276         else if (r->is_vht)
277         {
278                 lua_pushnumber(L, r->mcs);
279                 lua_setfield(L, -2, rx ? "rx_mcs" : "tx_mcs");
280
281                 lua_pushnumber(L, r->nss);
282                 lua_setfield(L, -2, rx ? "rx_nss" : "tx_nss");
283
284                 lua_pushboolean(L, r->is_short_gi);
285                 lua_setfield(L, -2, rx ? "rx_short_gi" : "tx_short_gi");
286         }
287 }
288
289 /* Wrapper for assoclist */
290 static int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, int *))
291 {
292         int i, len;
293         char rv[IWINFO_BUFSIZE];
294         char macstr[18];
295         const char *ifname = luaL_checkstring(L, 1);
296         struct iwinfo_assoclist_entry *e;
297
298         lua_newtable(L);
299         memset(rv, 0, sizeof(rv));
300
301         if (!(*func)(ifname, rv, &len))
302         {
303                 for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
304                 {
305                         e = (struct iwinfo_assoclist_entry *) &rv[i];
306
307                         sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
308                                 e->mac[0], e->mac[1], e->mac[2],
309                                 e->mac[3], e->mac[4], e->mac[5]);
310
311                         lua_newtable(L);
312
313                         lua_pushnumber(L, e->signal);
314                         lua_setfield(L, -2, "signal");
315
316                         lua_pushnumber(L, e->noise);
317                         lua_setfield(L, -2, "noise");
318
319                         lua_pushnumber(L, e->inactive);
320                         lua_setfield(L, -2, "inactive");
321
322                         lua_pushnumber(L, e->rx_packets);
323                         lua_setfield(L, -2, "rx_packets");
324
325                         lua_pushnumber(L, e->tx_packets);
326                         lua_setfield(L, -2, "tx_packets");
327
328                         set_rateinfo(L, &e->rx_rate, true);
329                         set_rateinfo(L, &e->tx_rate, false);
330
331                         lua_setfield(L, -2, macstr);
332                 }
333         }
334
335         return 1;
336 }
337
338 /* Wrapper for tx power list */
339 static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, int *))
340 {
341         int i, x, len;
342         char rv[IWINFO_BUFSIZE];
343         const char *ifname = luaL_checkstring(L, 1);
344         struct iwinfo_txpwrlist_entry *e;
345
346         memset(rv, 0, sizeof(rv));
347
348         if (!(*func)(ifname, rv, &len))
349         {
350                 lua_newtable(L);
351
352                 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_txpwrlist_entry), x++)
353                 {
354                         e = (struct iwinfo_txpwrlist_entry *) &rv[i];
355
356                         lua_newtable(L);
357
358                         lua_pushnumber(L, e->mw);
359                         lua_setfield(L, -2, "mw");
360
361                         lua_pushnumber(L, e->dbm);
362                         lua_setfield(L, -2, "dbm");
363
364                         lua_rawseti(L, -2, x);
365                 }
366
367                 return 1;
368         }
369
370         return 0;
371 }
372
373 /* Wrapper for scan list */
374 static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int *))
375 {
376         int i, x, len = 0;
377         char rv[IWINFO_BUFSIZE];
378         char macstr[18];
379         const char *ifname = luaL_checkstring(L, 1);
380         struct iwinfo_scanlist_entry *e;
381
382         lua_newtable(L);
383         memset(rv, 0, sizeof(rv));
384
385         if (!(*func)(ifname, rv, &len))
386         {
387                 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
388                 {
389                         e = (struct iwinfo_scanlist_entry *) &rv[i];
390
391                         lua_newtable(L);
392
393                         /* BSSID */
394                         sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
395                                 e->mac[0], e->mac[1], e->mac[2],
396                                 e->mac[3], e->mac[4], e->mac[5]);
397
398                         lua_pushstring(L, macstr);
399                         lua_setfield(L, -2, "bssid");
400
401                         /* ESSID */
402                         if (e->ssid[0])
403                         {
404                                 lua_pushstring(L, (char *) e->ssid);
405                                 lua_setfield(L, -2, "ssid");
406                         }
407
408                         /* Channel */
409                         lua_pushinteger(L, e->channel);
410                         lua_setfield(L, -2, "channel");
411
412                         /* Mode */
413                         lua_pushstring(L, IWINFO_OPMODE_NAMES[e->mode]);
414                         lua_setfield(L, -2, "mode");
415
416                         /* Quality, Signal */
417                         lua_pushinteger(L, e->quality);
418                         lua_setfield(L, -2, "quality");
419
420                         lua_pushinteger(L, e->quality_max);
421                         lua_setfield(L, -2, "quality_max");
422
423                         lua_pushnumber(L, (e->signal - 0x100));
424                         lua_setfield(L, -2, "signal");
425
426                         /* Crypto */
427                         iwinfo_L_cryptotable(L, &e->crypto);
428                         lua_setfield(L, -2, "encryption");
429
430                         lua_rawseti(L, -2, x);
431                 }
432         }
433
434         return 1;
435 }
436
437 /* Wrapper for frequency list */
438 static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int *))
439 {
440         int i, x, len;
441         char rv[IWINFO_BUFSIZE];
442         const char *ifname = luaL_checkstring(L, 1);
443         struct iwinfo_freqlist_entry *e;
444
445         lua_newtable(L);
446         memset(rv, 0, sizeof(rv));
447
448         if (!(*func)(ifname, rv, &len))
449         {
450                 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_freqlist_entry), x++)
451                 {
452                         e = (struct iwinfo_freqlist_entry *) &rv[i];
453
454                         lua_newtable(L);
455
456                         /* MHz */
457                         lua_pushinteger(L, e->mhz);
458                         lua_setfield(L, -2, "mhz");
459
460                         /* Channel */
461                         lua_pushinteger(L, e->channel);
462                         lua_setfield(L, -2, "channel");
463
464                         /* Restricted (DFS/TPC/Radar) */
465                         lua_pushboolean(L, e->restricted);
466                         lua_setfield(L, -2, "restricted");
467
468                         lua_rawseti(L, -2, x);
469                 }
470         }
471
472         return 1;
473 }
474
475 /* Wrapper for crypto settings */
476 static int iwinfo_L_encryption(lua_State *L, int (*func)(const char *, char *))
477 {
478         const char *ifname = luaL_checkstring(L, 1);
479         struct iwinfo_crypto_entry c = { 0 };
480
481         if (!(*func)(ifname, (char *)&c))
482         {
483                 iwinfo_L_cryptotable(L, &c);
484                 return 1;
485         }
486
487         lua_pushnil(L);
488         return 1;
489 }
490
491 /* Wrapper for hwmode list */
492 static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
493 {
494         const char *ifname = luaL_checkstring(L, 1);
495         int hwmodes = 0;
496
497         if (!(*func)(ifname, &hwmodes))
498         {
499                 lua_newtable(L);
500
501                 lua_pushboolean(L, hwmodes & IWINFO_80211_A);
502                 lua_setfield(L, -2, "a");
503
504                 lua_pushboolean(L, hwmodes & IWINFO_80211_B);
505                 lua_setfield(L, -2, "b");
506
507                 lua_pushboolean(L, hwmodes & IWINFO_80211_G);
508                 lua_setfield(L, -2, "g");
509
510                 lua_pushboolean(L, hwmodes & IWINFO_80211_N);
511                 lua_setfield(L, -2, "n");
512
513                 lua_pushboolean(L, hwmodes & IWINFO_80211_AC);
514                 lua_setfield(L, -2, "ac");
515
516                 return 1;
517         }
518
519         lua_pushnil(L);
520         return 1;
521 }
522
523 /* Wrapper for htmode list */
524 static int iwinfo_L_htmodelist(lua_State *L, int (*func)(const char *, int *))
525 {
526         const char *ifname = luaL_checkstring(L, 1);
527         int i, htmodes = 0;
528
529         if (!(*func)(ifname, &htmodes))
530         {
531                 lua_newtable(L);
532
533                 for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
534                 {
535                         lua_pushboolean(L, htmodes & (1 << i));
536                         lua_setfield(L, -2, IWINFO_HTMODE_NAMES[i]);
537                 }
538
539                 return 1;
540         }
541
542         lua_pushnil(L);
543         return 1;
544 }
545
546 /* Wrapper for mbssid_support */
547 static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
548 {
549         const char *ifname = luaL_checkstring(L, 1);
550         int support = 0;
551
552         if (!(*func)(ifname, &support))
553         {
554                 lua_pushboolean(L, support);
555                 return 1;
556         }
557
558         lua_pushnil(L);
559         return 1;
560 }
561
562 /* Wrapper for hardware_id */
563 static int iwinfo_L_hardware_id(lua_State *L, int (*func)(const char *, char *))
564 {
565         const char *ifname = luaL_checkstring(L, 1);
566         struct iwinfo_hardware_id ids;
567
568         if (!(*func)(ifname, (char *)&ids))
569         {
570                 lua_newtable(L);
571
572                 lua_pushnumber(L, ids.vendor_id);
573                 lua_setfield(L, -2, "vendor_id");
574
575                 lua_pushnumber(L, ids.device_id);
576                 lua_setfield(L, -2, "device_id");
577
578                 lua_pushnumber(L, ids.subsystem_vendor_id);
579                 lua_setfield(L, -2, "subsystem_vendor_id");
580
581                 lua_pushnumber(L, ids.subsystem_device_id);
582                 lua_setfield(L, -2, "subsystem_device_id");
583         }
584         else
585         {
586                 lua_pushnil(L);
587         }
588
589         return 1;
590 }
591
592 /* Wrapper for country list */
593 static char * iwinfo_L_country_lookup(char *buf, int len, int iso3166)
594 {
595         int i;
596         struct iwinfo_country_entry *c;
597
598         for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
599         {
600                 c = (struct iwinfo_country_entry *) &buf[i];
601
602                 if (c->iso3166 == iso3166)
603                         return c->ccode;
604         }
605
606         return NULL;
607 }
608
609 static int iwinfo_L_countrylist(lua_State *L, int (*func)(const char *, char *, int *))
610 {
611         int len, i;
612         char rv[IWINFO_BUFSIZE], alpha2[3];
613         char *ccode;
614         const char *ifname = luaL_checkstring(L, 1);
615         const struct iwinfo_iso3166_label *l;
616
617         lua_newtable(L);
618         memset(rv, 0, sizeof(rv));
619
620         if (!(*func)(ifname, rv, &len))
621         {
622                 for (l = IWINFO_ISO3166_NAMES, i = 1; l->iso3166; l++)
623                 {
624                         if ((ccode = iwinfo_L_country_lookup(rv, len, l->iso3166)) != NULL)
625                         {
626                                 sprintf(alpha2, "%c%c",
627                                         (l->iso3166 / 256), (l->iso3166 % 256));
628
629                                 lua_newtable(L);
630
631                                 lua_pushstring(L, alpha2);
632                                 lua_setfield(L, -2, "alpha2");
633
634                                 lua_pushstring(L, ccode);
635                                 lua_setfield(L, -2, "ccode");
636
637                                 lua_pushstring(L, l->name);
638                                 lua_setfield(L, -2, "name");
639
640                                 lua_rawseti(L, -2, i++);
641                         }
642                 }
643         }
644
645         return 1;
646 }
647
648
649 #ifdef USE_WL
650 /* Broadcom */
651 LUA_WRAP_INT_OP(wl,channel)
652 LUA_WRAP_INT_OP(wl,frequency)
653 LUA_WRAP_INT_OP(wl,frequency_offset)
654 LUA_WRAP_INT_OP(wl,txpower)
655 LUA_WRAP_INT_OP(wl,txpower_offset)
656 LUA_WRAP_INT_OP(wl,bitrate)
657 LUA_WRAP_INT_OP(wl,signal)
658 LUA_WRAP_INT_OP(wl,noise)
659 LUA_WRAP_INT_OP(wl,quality)
660 LUA_WRAP_INT_OP(wl,quality_max)
661 LUA_WRAP_STRING_OP(wl,ssid)
662 LUA_WRAP_STRING_OP(wl,bssid)
663 LUA_WRAP_STRING_OP(wl,country)
664 LUA_WRAP_STRING_OP(wl,hardware_name)
665 LUA_WRAP_STRING_OP(wl,phyname)
666 LUA_WRAP_STRUCT_OP(wl,mode)
667 LUA_WRAP_STRUCT_OP(wl,assoclist)
668 LUA_WRAP_STRUCT_OP(wl,txpwrlist)
669 LUA_WRAP_STRUCT_OP(wl,scanlist)
670 LUA_WRAP_STRUCT_OP(wl,freqlist)
671 LUA_WRAP_STRUCT_OP(wl,countrylist)
672 LUA_WRAP_STRUCT_OP(wl,hwmodelist)
673 LUA_WRAP_STRUCT_OP(wl,htmodelist)
674 LUA_WRAP_STRUCT_OP(wl,encryption)
675 LUA_WRAP_STRUCT_OP(wl,mbssid_support)
676 LUA_WRAP_STRUCT_OP(wl,hardware_id)
677 #endif
678
679 #ifdef USE_MADWIFI
680 /* Madwifi */
681 LUA_WRAP_INT_OP(madwifi,channel)
682 LUA_WRAP_INT_OP(madwifi,frequency)
683 LUA_WRAP_INT_OP(madwifi,frequency_offset)
684 LUA_WRAP_INT_OP(madwifi,txpower)
685 LUA_WRAP_INT_OP(madwifi,txpower_offset)
686 LUA_WRAP_INT_OP(madwifi,bitrate)
687 LUA_WRAP_INT_OP(madwifi,signal)
688 LUA_WRAP_INT_OP(madwifi,noise)
689 LUA_WRAP_INT_OP(madwifi,quality)
690 LUA_WRAP_INT_OP(madwifi,quality_max)
691 LUA_WRAP_STRING_OP(madwifi,ssid)
692 LUA_WRAP_STRING_OP(madwifi,bssid)
693 LUA_WRAP_STRING_OP(madwifi,country)
694 LUA_WRAP_STRING_OP(madwifi,hardware_name)
695 LUA_WRAP_STRING_OP(madwifi,phyname)
696 LUA_WRAP_STRUCT_OP(madwifi,mode)
697 LUA_WRAP_STRUCT_OP(madwifi,assoclist)
698 LUA_WRAP_STRUCT_OP(madwifi,txpwrlist)
699 LUA_WRAP_STRUCT_OP(madwifi,scanlist)
700 LUA_WRAP_STRUCT_OP(madwifi,freqlist)
701 LUA_WRAP_STRUCT_OP(madwifi,countrylist)
702 LUA_WRAP_STRUCT_OP(madwifi,hwmodelist)
703 LUA_WRAP_STRUCT_OP(madwifi,htmodelist)
704 LUA_WRAP_STRUCT_OP(madwifi,encryption)
705 LUA_WRAP_STRUCT_OP(madwifi,mbssid_support)
706 LUA_WRAP_STRUCT_OP(madwifi,hardware_id)
707 #endif
708
709 #ifdef USE_NL80211
710 /* NL80211 */
711 LUA_WRAP_INT_OP(nl80211,channel)
712 LUA_WRAP_INT_OP(nl80211,frequency)
713 LUA_WRAP_INT_OP(nl80211,frequency_offset)
714 LUA_WRAP_INT_OP(nl80211,txpower)
715 LUA_WRAP_INT_OP(nl80211,txpower_offset)
716 LUA_WRAP_INT_OP(nl80211,bitrate)
717 LUA_WRAP_INT_OP(nl80211,signal)
718 LUA_WRAP_INT_OP(nl80211,noise)
719 LUA_WRAP_INT_OP(nl80211,quality)
720 LUA_WRAP_INT_OP(nl80211,quality_max)
721 LUA_WRAP_STRING_OP(nl80211,ssid)
722 LUA_WRAP_STRING_OP(nl80211,bssid)
723 LUA_WRAP_STRING_OP(nl80211,country)
724 LUA_WRAP_STRING_OP(nl80211,hardware_name)
725 LUA_WRAP_STRING_OP(nl80211,phyname)
726 LUA_WRAP_STRUCT_OP(nl80211,mode)
727 LUA_WRAP_STRUCT_OP(nl80211,assoclist)
728 LUA_WRAP_STRUCT_OP(nl80211,txpwrlist)
729 LUA_WRAP_STRUCT_OP(nl80211,scanlist)
730 LUA_WRAP_STRUCT_OP(nl80211,freqlist)
731 LUA_WRAP_STRUCT_OP(nl80211,countrylist)
732 LUA_WRAP_STRUCT_OP(nl80211,hwmodelist)
733 LUA_WRAP_STRUCT_OP(nl80211,htmodelist)
734 LUA_WRAP_STRUCT_OP(nl80211,encryption)
735 LUA_WRAP_STRUCT_OP(nl80211,mbssid_support)
736 LUA_WRAP_STRUCT_OP(nl80211,hardware_id)
737 #endif
738
739 /* Wext */
740 LUA_WRAP_INT_OP(wext,channel)
741 LUA_WRAP_INT_OP(wext,frequency)
742 LUA_WRAP_INT_OP(wext,frequency_offset)
743 LUA_WRAP_INT_OP(wext,txpower)
744 LUA_WRAP_INT_OP(wext,txpower_offset)
745 LUA_WRAP_INT_OP(wext,bitrate)
746 LUA_WRAP_INT_OP(wext,signal)
747 LUA_WRAP_INT_OP(wext,noise)
748 LUA_WRAP_INT_OP(wext,quality)
749 LUA_WRAP_INT_OP(wext,quality_max)
750 LUA_WRAP_STRING_OP(wext,ssid)
751 LUA_WRAP_STRING_OP(wext,bssid)
752 LUA_WRAP_STRING_OP(wext,country)
753 LUA_WRAP_STRING_OP(wext,hardware_name)
754 LUA_WRAP_STRING_OP(wext,phyname)
755 LUA_WRAP_STRUCT_OP(wext,mode)
756 LUA_WRAP_STRUCT_OP(wext,assoclist)
757 LUA_WRAP_STRUCT_OP(wext,txpwrlist)
758 LUA_WRAP_STRUCT_OP(wext,scanlist)
759 LUA_WRAP_STRUCT_OP(wext,freqlist)
760 LUA_WRAP_STRUCT_OP(wext,countrylist)
761 LUA_WRAP_STRUCT_OP(wext,hwmodelist)
762 LUA_WRAP_STRUCT_OP(wext,htmodelist)
763 LUA_WRAP_STRUCT_OP(wext,encryption)
764 LUA_WRAP_STRUCT_OP(wext,mbssid_support)
765 LUA_WRAP_STRUCT_OP(wext,hardware_id)
766
767 #ifdef USE_WL
768 /* Broadcom table */
769 static const luaL_reg R_wl[] = {
770         LUA_REG(wl,channel),
771         LUA_REG(wl,frequency),
772         LUA_REG(wl,frequency_offset),
773         LUA_REG(wl,txpower),
774         LUA_REG(wl,txpower_offset),
775         LUA_REG(wl,bitrate),
776         LUA_REG(wl,signal),
777         LUA_REG(wl,noise),
778         LUA_REG(wl,quality),
779         LUA_REG(wl,quality_max),
780         LUA_REG(wl,mode),
781         LUA_REG(wl,ssid),
782         LUA_REG(wl,bssid),
783         LUA_REG(wl,country),
784         LUA_REG(wl,assoclist),
785         LUA_REG(wl,txpwrlist),
786         LUA_REG(wl,scanlist),
787         LUA_REG(wl,freqlist),
788         LUA_REG(wl,countrylist),
789         LUA_REG(wl,hwmodelist),
790         LUA_REG(wl,htmodelist),
791         LUA_REG(wl,encryption),
792         LUA_REG(wl,mbssid_support),
793         LUA_REG(wl,hardware_id),
794         LUA_REG(wl,hardware_name),
795         LUA_REG(wl,phyname),
796         { NULL, NULL }
797 };
798 #endif
799
800 #ifdef USE_MADWIFI
801 /* Madwifi table */
802 static const luaL_reg R_madwifi[] = {
803         LUA_REG(madwifi,channel),
804         LUA_REG(madwifi,frequency),
805         LUA_REG(madwifi,frequency_offset),
806         LUA_REG(madwifi,txpower),
807         LUA_REG(madwifi,txpower_offset),
808         LUA_REG(madwifi,bitrate),
809         LUA_REG(madwifi,signal),
810         LUA_REG(madwifi,noise),
811         LUA_REG(madwifi,quality),
812         LUA_REG(madwifi,quality_max),
813         LUA_REG(madwifi,mode),
814         LUA_REG(madwifi,ssid),
815         LUA_REG(madwifi,bssid),
816         LUA_REG(madwifi,country),
817         LUA_REG(madwifi,assoclist),
818         LUA_REG(madwifi,txpwrlist),
819         LUA_REG(madwifi,scanlist),
820         LUA_REG(madwifi,freqlist),
821         LUA_REG(madwifi,countrylist),
822         LUA_REG(madwifi,hwmodelist),
823         LUA_REG(madwifi,htmodelist),
824         LUA_REG(madwifi,encryption),
825         LUA_REG(madwifi,mbssid_support),
826         LUA_REG(madwifi,hardware_id),
827         LUA_REG(madwifi,hardware_name),
828         LUA_REG(madwifi,phyname),
829         { NULL, NULL }
830 };
831 #endif
832
833 #ifdef USE_NL80211
834 /* NL80211 table */
835 static const luaL_reg R_nl80211[] = {
836         LUA_REG(nl80211,channel),
837         LUA_REG(nl80211,frequency),
838         LUA_REG(nl80211,frequency_offset),
839         LUA_REG(nl80211,txpower),
840         LUA_REG(nl80211,txpower_offset),
841         LUA_REG(nl80211,bitrate),
842         LUA_REG(nl80211,signal),
843         LUA_REG(nl80211,noise),
844         LUA_REG(nl80211,quality),
845         LUA_REG(nl80211,quality_max),
846         LUA_REG(nl80211,mode),
847         LUA_REG(nl80211,ssid),
848         LUA_REG(nl80211,bssid),
849         LUA_REG(nl80211,country),
850         LUA_REG(nl80211,assoclist),
851         LUA_REG(nl80211,txpwrlist),
852         LUA_REG(nl80211,scanlist),
853         LUA_REG(nl80211,freqlist),
854         LUA_REG(nl80211,countrylist),
855         LUA_REG(nl80211,hwmodelist),
856         LUA_REG(nl80211,htmodelist),
857         LUA_REG(nl80211,encryption),
858         LUA_REG(nl80211,mbssid_support),
859         LUA_REG(nl80211,hardware_id),
860         LUA_REG(nl80211,hardware_name),
861         LUA_REG(nl80211,phyname),
862         { NULL, NULL }
863 };
864 #endif
865
866 /* Wext table */
867 static const luaL_reg R_wext[] = {
868         LUA_REG(wext,channel),
869         LUA_REG(wext,frequency),
870         LUA_REG(wext,frequency_offset),
871         LUA_REG(wext,txpower),
872         LUA_REG(wext,txpower_offset),
873         LUA_REG(wext,bitrate),
874         LUA_REG(wext,signal),
875         LUA_REG(wext,noise),
876         LUA_REG(wext,quality),
877         LUA_REG(wext,quality_max),
878         LUA_REG(wext,mode),
879         LUA_REG(wext,ssid),
880         LUA_REG(wext,bssid),
881         LUA_REG(wext,country),
882         LUA_REG(wext,assoclist),
883         LUA_REG(wext,txpwrlist),
884         LUA_REG(wext,scanlist),
885         LUA_REG(wext,freqlist),
886         LUA_REG(wext,countrylist),
887         LUA_REG(wext,hwmodelist),
888         LUA_REG(wext,htmodelist),
889         LUA_REG(wext,encryption),
890         LUA_REG(wext,mbssid_support),
891         LUA_REG(wext,hardware_id),
892         LUA_REG(wext,hardware_name),
893         LUA_REG(wext,phyname),
894         { NULL, NULL }
895 };
896
897 /* Common */
898 static const luaL_reg R_common[] = {
899         { "type", iwinfo_L_type },
900         { "__gc", iwinfo_L__gc  },
901         { NULL, NULL }
902 };
903
904
905 LUALIB_API int luaopen_iwinfo(lua_State *L) {
906         luaL_register(L, IWINFO_META, R_common);
907
908 #ifdef USE_WL
909         luaL_newmetatable(L, IWINFO_WL_META);
910         luaL_register(L, NULL, R_common);
911         luaL_register(L, NULL, R_wl);
912         lua_pushvalue(L, -1);
913         lua_setfield(L, -2, "__index");
914         lua_setfield(L, -2, "wl");
915 #endif
916
917 #ifdef USE_MADWIFI
918         luaL_newmetatable(L, IWINFO_MADWIFI_META);
919         luaL_register(L, NULL, R_common);
920         luaL_register(L, NULL, R_madwifi);
921         lua_pushvalue(L, -1);
922         lua_setfield(L, -2, "__index");
923         lua_setfield(L, -2, "madwifi");
924 #endif
925
926 #ifdef USE_NL80211
927         luaL_newmetatable(L, IWINFO_NL80211_META);
928         luaL_register(L, NULL, R_common);
929         luaL_register(L, NULL, R_nl80211);
930         lua_pushvalue(L, -1);
931         lua_setfield(L, -2, "__index");
932         lua_setfield(L, -2, "nl80211");
933 #endif
934
935         luaL_newmetatable(L, IWINFO_WEXT_META);
936         luaL_register(L, NULL, R_common);
937         luaL_register(L, NULL, R_wext);
938         lua_pushvalue(L, -1);
939         lua_setfield(L, -2, "__index");
940         lua_setfield(L, -2, "wext");
941
942         return 1;
943 }