[package] iwinfo: add per-station rate and mcs info to assoclist op
[openwrt.git] / package / iwinfo / src / 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 < 8; 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 < 8; 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 < 8; 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 < 8; 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 assoclist */
239 static int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, int *))
240 {
241         int i, len;
242         char rv[IWINFO_BUFSIZE];
243         char macstr[18];
244         const char *ifname = luaL_checkstring(L, 1);
245         struct iwinfo_assoclist_entry *e;
246
247         lua_newtable(L);
248         memset(rv, 0, sizeof(rv));
249
250         if (!(*func)(ifname, rv, &len))
251         {
252                 for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
253                 {
254                         e = (struct iwinfo_assoclist_entry *) &rv[i];
255
256                         sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
257                                 e->mac[0], e->mac[1], e->mac[2],
258                                 e->mac[3], e->mac[4], e->mac[5]);
259
260                         lua_newtable(L);
261
262                         lua_pushnumber(L, e->signal);
263                         lua_setfield(L, -2, "signal");
264
265                         lua_pushnumber(L, e->noise);
266                         lua_setfield(L, -2, "noise");
267
268                         lua_pushnumber(L, e->inactive);
269                         lua_setfield(L, -2, "inactive");
270
271                         lua_pushnumber(L, e->rx_packets);
272                         lua_setfield(L, -2, "rx_packets");
273
274                         lua_pushnumber(L, e->tx_packets);
275                         lua_setfield(L, -2, "tx_packets");
276
277                         lua_pushnumber(L, e->rx_rate.rate);
278                         lua_setfield(L, -2, "rx_rate");
279
280                         lua_pushnumber(L, e->tx_rate.rate);
281                         lua_setfield(L, -2, "tx_rate");
282
283                         if (e->rx_rate.mcs >= 0)
284                         {
285                                 lua_pushnumber(L, e->rx_rate.mcs);
286                                 lua_setfield(L, -2, "rx_mcs");
287
288                                 lua_pushboolean(L, e->rx_rate.is_40mhz);
289                                 lua_setfield(L, -2, "rx_40mhz");
290
291                                 lua_pushboolean(L, e->rx_rate.is_short_gi);
292                                 lua_setfield(L, -2, "rx_short_gi");
293                         }
294
295                         if (e->tx_rate.mcs >= 0)
296                         {
297                                 lua_pushnumber(L, e->tx_rate.mcs);
298                                 lua_setfield(L, -2, "tx_mcs");
299
300                                 lua_pushboolean(L, e->tx_rate.is_40mhz);
301                                 lua_setfield(L, -2, "tx_40mhz");
302
303                                 lua_pushboolean(L, e->tx_rate.is_short_gi);
304                                 lua_setfield(L, -2, "tx_short_gi");
305                         }
306
307                         lua_setfield(L, -2, macstr);
308                 }
309         }
310
311         return 1;
312 }
313
314 /* Wrapper for tx power list */
315 static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, int *))
316 {
317         int i, x, len;
318         char rv[IWINFO_BUFSIZE];
319         const char *ifname = luaL_checkstring(L, 1);
320         struct iwinfo_txpwrlist_entry *e;
321
322         lua_newtable(L);
323         memset(rv, 0, sizeof(rv));
324
325         if (!(*func)(ifname, rv, &len))
326         {
327                 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_txpwrlist_entry), x++)
328                 {
329                         e = (struct iwinfo_txpwrlist_entry *) &rv[i];
330
331                         lua_newtable(L);
332
333                         lua_pushnumber(L, e->mw);
334                         lua_setfield(L, -2, "mw");
335
336                         lua_pushnumber(L, e->dbm);
337                         lua_setfield(L, -2, "dbm");
338
339                         lua_rawseti(L, -2, x);
340                 }
341         }
342
343         return 1;
344 }
345
346 /* Wrapper for scan list */
347 static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int *))
348 {
349         int i, x, len;
350         char rv[IWINFO_BUFSIZE];
351         char macstr[18];
352         const char *ifname = luaL_checkstring(L, 1);
353         struct iwinfo_scanlist_entry *e;
354
355         lua_newtable(L);
356         memset(rv, 0, sizeof(rv));
357
358         if (!(*func)(ifname, rv, &len))
359         {
360                 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
361                 {
362                         e = (struct iwinfo_scanlist_entry *) &rv[i];
363
364                         lua_newtable(L);
365
366                         /* BSSID */
367                         sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
368                                 e->mac[0], e->mac[1], e->mac[2],
369                                 e->mac[3], e->mac[4], e->mac[5]);
370
371                         lua_pushstring(L, macstr);
372                         lua_setfield(L, -2, "bssid");
373
374                         /* ESSID */
375                         if (e->ssid[0])
376                         {
377                                 lua_pushstring(L, (char *) e->ssid);
378                                 lua_setfield(L, -2, "ssid");
379                         }
380
381                         /* Channel */
382                         lua_pushinteger(L, e->channel);
383                         lua_setfield(L, -2, "channel");
384
385                         /* Mode */
386                         lua_pushstring(L, (char *) e->mode);
387                         lua_setfield(L, -2, "mode");
388
389                         /* Quality, Signal */
390                         lua_pushinteger(L, e->quality);
391                         lua_setfield(L, -2, "quality");
392
393                         lua_pushinteger(L, e->quality_max);
394                         lua_setfield(L, -2, "quality_max");
395
396                         lua_pushnumber(L, (e->signal - 0x100));
397                         lua_setfield(L, -2, "signal");
398
399                         /* Crypto */
400                         iwinfo_L_cryptotable(L, &e->crypto);
401                         lua_setfield(L, -2, "encryption");
402
403                         lua_rawseti(L, -2, x);
404                 }
405         }
406
407         return 1;
408 }
409
410 /* Wrapper for frequency list */
411 static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int *))
412 {
413         int i, x, len;
414         char rv[IWINFO_BUFSIZE];
415         const char *ifname = luaL_checkstring(L, 1);
416         struct iwinfo_freqlist_entry *e;
417
418         lua_newtable(L);
419         memset(rv, 0, sizeof(rv));
420
421         if (!(*func)(ifname, rv, &len))
422         {
423                 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_freqlist_entry), x++)
424                 {
425                         e = (struct iwinfo_freqlist_entry *) &rv[i];
426
427                         lua_newtable(L);
428
429                         /* MHz */
430                         lua_pushinteger(L, e->mhz);
431                         lua_setfield(L, -2, "mhz");
432
433                         /* Channel */
434                         lua_pushinteger(L, e->channel);
435                         lua_setfield(L, -2, "channel");
436
437                         /* Restricted (DFS/TPC/Radar) */
438                         lua_pushboolean(L, e->restricted);
439                         lua_setfield(L, -2, "restricted");
440
441                         lua_rawseti(L, -2, x);
442                 }
443         }
444
445         return 1;
446 }
447
448 /* Wrapper for crypto settings */
449 static int iwinfo_L_encryption(lua_State *L, int (*func)(const char *, char *))
450 {
451         const char *ifname = luaL_checkstring(L, 1);
452         struct iwinfo_crypto_entry c = { 0 };
453
454         if (!(*func)(ifname, (char *)&c))
455         {
456                 iwinfo_L_cryptotable(L, &c);
457                 return 1;
458         }
459
460         lua_pushnil(L);
461         return 1;
462 }
463
464 /* Wrapper for hwmode list */
465 static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
466 {
467         const char *ifname = luaL_checkstring(L, 1);
468         int hwmodes = 0;
469
470         if (!(*func)(ifname, &hwmodes))
471         {
472                 lua_newtable(L);
473
474                 lua_pushboolean(L, hwmodes & IWINFO_80211_A);
475                 lua_setfield(L, -2, "a");
476
477                 lua_pushboolean(L, hwmodes & IWINFO_80211_B);
478                 lua_setfield(L, -2, "b");
479
480                 lua_pushboolean(L, hwmodes & IWINFO_80211_G);
481                 lua_setfield(L, -2, "g");
482
483                 lua_pushboolean(L, hwmodes & IWINFO_80211_N);
484                 lua_setfield(L, -2, "n");
485
486                 return 1;
487         }
488
489         lua_pushnil(L);
490         return 1;
491 }
492
493 /* Wrapper for mbssid_support */
494 static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
495 {
496         const char *ifname = luaL_checkstring(L, 1);
497         int support = 0;
498
499         if (!(*func)(ifname, &support))
500         {
501                 lua_pushboolean(L, support);
502                 return 1;
503         }
504
505         lua_pushnil(L);
506         return 1;
507 }
508
509 /* Wrapper for hardware_id */
510 static int iwinfo_L_hardware_id(lua_State *L, int (*func)(const char *, char *))
511 {
512         const char *ifname = luaL_checkstring(L, 1);
513         struct iwinfo_hardware_id ids;
514
515         if (!(*func)(ifname, (char *)&ids))
516         {
517                 lua_newtable(L);
518
519                 lua_pushnumber(L, ids.vendor_id);
520                 lua_setfield(L, -2, "vendor_id");
521
522                 lua_pushnumber(L, ids.device_id);
523                 lua_setfield(L, -2, "device_id");
524
525                 lua_pushnumber(L, ids.subsystem_vendor_id);
526                 lua_setfield(L, -2, "subsystem_vendor_id");
527
528                 lua_pushnumber(L, ids.subsystem_device_id);
529                 lua_setfield(L, -2, "subsystem_device_id");
530         }
531         else
532         {
533                 lua_pushnil(L);
534         }
535
536         return 1;
537 }
538
539 /* Wrapper for country list */
540 static char * iwinfo_L_country_lookup(char *buf, int len, int iso3166)
541 {
542         int i;
543         struct iwinfo_country_entry *c;
544
545         for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
546         {
547                 c = (struct iwinfo_country_entry *) &buf[i];
548
549                 if (c->iso3166 == iso3166)
550                         return c->ccode;
551         }
552
553         return NULL;
554 }
555
556 static int iwinfo_L_countrylist(lua_State *L, int (*func)(const char *, char *, int *))
557 {
558         int len, i, j;
559         char rv[IWINFO_BUFSIZE], alpha2[3];
560         char *ccode;
561         const char *ifname = luaL_checkstring(L, 1);
562         const struct iwinfo_iso3166_label *l;
563
564         lua_newtable(L);
565         memset(rv, 0, sizeof(rv));
566
567         if (!(*func)(ifname, rv, &len))
568         {
569                 for (l = IWINFO_ISO3166_NAMES, j = 1; l->iso3166; l++)
570                 {
571                         if ((ccode = iwinfo_L_country_lookup(rv, len, l->iso3166)) != NULL)
572                         {
573                                 sprintf(alpha2, "%c%c",
574                                         (l->iso3166 / 256), (l->iso3166 % 256));
575
576                                 lua_newtable(L);
577
578                                 lua_pushstring(L, alpha2);
579                                 lua_setfield(L, -2, "alpha2");
580
581                                 lua_pushstring(L, ccode);
582                                 lua_setfield(L, -2, "ccode");
583
584                                 lua_pushstring(L, l->name);
585                                 lua_setfield(L, -2, "name");
586
587                                 lua_rawseti(L, -2, j++);
588                         }
589                 }
590         }
591
592         return 1;
593 }
594
595
596 #ifdef USE_WL
597 /* Broadcom */
598 LUA_WRAP_INT(wl,channel)
599 LUA_WRAP_INT(wl,frequency)
600 LUA_WRAP_INT(wl,frequency_offset)
601 LUA_WRAP_INT(wl,txpower)
602 LUA_WRAP_INT(wl,txpower_offset)
603 LUA_WRAP_INT(wl,bitrate)
604 LUA_WRAP_INT(wl,signal)
605 LUA_WRAP_INT(wl,noise)
606 LUA_WRAP_INT(wl,quality)
607 LUA_WRAP_INT(wl,quality_max)
608 LUA_WRAP_STRING(wl,mode)
609 LUA_WRAP_STRING(wl,ssid)
610 LUA_WRAP_STRING(wl,bssid)
611 LUA_WRAP_STRING(wl,country)
612 LUA_WRAP_STRING(wl,hardware_name)
613 LUA_WRAP_STRUCT(wl,assoclist)
614 LUA_WRAP_STRUCT(wl,txpwrlist)
615 LUA_WRAP_STRUCT(wl,scanlist)
616 LUA_WRAP_STRUCT(wl,freqlist)
617 LUA_WRAP_STRUCT(wl,countrylist)
618 LUA_WRAP_STRUCT(wl,hwmodelist)
619 LUA_WRAP_STRUCT(wl,encryption)
620 LUA_WRAP_STRUCT(wl,mbssid_support)
621 LUA_WRAP_STRUCT(wl,hardware_id)
622 #endif
623
624 #ifdef USE_MADWIFI
625 /* Madwifi */
626 LUA_WRAP_INT(madwifi,channel)
627 LUA_WRAP_INT(madwifi,frequency)
628 LUA_WRAP_INT(madwifi,frequency_offset)
629 LUA_WRAP_INT(madwifi,txpower)
630 LUA_WRAP_INT(madwifi,txpower_offset)
631 LUA_WRAP_INT(madwifi,bitrate)
632 LUA_WRAP_INT(madwifi,signal)
633 LUA_WRAP_INT(madwifi,noise)
634 LUA_WRAP_INT(madwifi,quality)
635 LUA_WRAP_INT(madwifi,quality_max)
636 LUA_WRAP_STRING(madwifi,mode)
637 LUA_WRAP_STRING(madwifi,ssid)
638 LUA_WRAP_STRING(madwifi,bssid)
639 LUA_WRAP_STRING(madwifi,country)
640 LUA_WRAP_STRING(madwifi,hardware_name)
641 LUA_WRAP_STRUCT(madwifi,assoclist)
642 LUA_WRAP_STRUCT(madwifi,txpwrlist)
643 LUA_WRAP_STRUCT(madwifi,scanlist)
644 LUA_WRAP_STRUCT(madwifi,freqlist)
645 LUA_WRAP_STRUCT(madwifi,countrylist)
646 LUA_WRAP_STRUCT(madwifi,hwmodelist)
647 LUA_WRAP_STRUCT(madwifi,encryption)
648 LUA_WRAP_STRUCT(madwifi,mbssid_support)
649 LUA_WRAP_STRUCT(madwifi,hardware_id)
650 #endif
651
652 #ifdef USE_NL80211
653 /* NL80211 */
654 LUA_WRAP_INT(nl80211,channel)
655 LUA_WRAP_INT(nl80211,frequency)
656 LUA_WRAP_INT(nl80211,frequency_offset)
657 LUA_WRAP_INT(nl80211,txpower)
658 LUA_WRAP_INT(nl80211,txpower_offset)
659 LUA_WRAP_INT(nl80211,bitrate)
660 LUA_WRAP_INT(nl80211,signal)
661 LUA_WRAP_INT(nl80211,noise)
662 LUA_WRAP_INT(nl80211,quality)
663 LUA_WRAP_INT(nl80211,quality_max)
664 LUA_WRAP_STRING(nl80211,mode)
665 LUA_WRAP_STRING(nl80211,ssid)
666 LUA_WRAP_STRING(nl80211,bssid)
667 LUA_WRAP_STRING(nl80211,country)
668 LUA_WRAP_STRING(nl80211,hardware_name)
669 LUA_WRAP_STRUCT(nl80211,assoclist)
670 LUA_WRAP_STRUCT(nl80211,txpwrlist)
671 LUA_WRAP_STRUCT(nl80211,scanlist)
672 LUA_WRAP_STRUCT(nl80211,freqlist)
673 LUA_WRAP_STRUCT(nl80211,countrylist)
674 LUA_WRAP_STRUCT(nl80211,hwmodelist)
675 LUA_WRAP_STRUCT(nl80211,encryption)
676 LUA_WRAP_STRUCT(nl80211,mbssid_support)
677 LUA_WRAP_STRUCT(nl80211,hardware_id)
678 #endif
679
680 /* Wext */
681 LUA_WRAP_INT(wext,channel)
682 LUA_WRAP_INT(wext,frequency)
683 LUA_WRAP_INT(wext,frequency_offset)
684 LUA_WRAP_INT(wext,txpower)
685 LUA_WRAP_INT(wext,txpower_offset)
686 LUA_WRAP_INT(wext,bitrate)
687 LUA_WRAP_INT(wext,signal)
688 LUA_WRAP_INT(wext,noise)
689 LUA_WRAP_INT(wext,quality)
690 LUA_WRAP_INT(wext,quality_max)
691 LUA_WRAP_STRING(wext,mode)
692 LUA_WRAP_STRING(wext,ssid)
693 LUA_WRAP_STRING(wext,bssid)
694 LUA_WRAP_STRING(wext,country)
695 LUA_WRAP_STRING(wext,hardware_name)
696 LUA_WRAP_STRUCT(wext,assoclist)
697 LUA_WRAP_STRUCT(wext,txpwrlist)
698 LUA_WRAP_STRUCT(wext,scanlist)
699 LUA_WRAP_STRUCT(wext,freqlist)
700 LUA_WRAP_STRUCT(wext,countrylist)
701 LUA_WRAP_STRUCT(wext,hwmodelist)
702 LUA_WRAP_STRUCT(wext,encryption)
703 LUA_WRAP_STRUCT(wext,mbssid_support)
704 LUA_WRAP_STRUCT(wext,hardware_id)
705
706 #ifdef USE_WL
707 /* Broadcom table */
708 static const luaL_reg R_wl[] = {
709         LUA_REG(wl,channel),
710         LUA_REG(wl,frequency),
711         LUA_REG(wl,frequency_offset),
712         LUA_REG(wl,txpower),
713         LUA_REG(wl,txpower_offset),
714         LUA_REG(wl,bitrate),
715         LUA_REG(wl,signal),
716         LUA_REG(wl,noise),
717         LUA_REG(wl,quality),
718         LUA_REG(wl,quality_max),
719         LUA_REG(wl,mode),
720         LUA_REG(wl,ssid),
721         LUA_REG(wl,bssid),
722         LUA_REG(wl,country),
723         LUA_REG(wl,assoclist),
724         LUA_REG(wl,txpwrlist),
725         LUA_REG(wl,scanlist),
726         LUA_REG(wl,freqlist),
727         LUA_REG(wl,countrylist),
728         LUA_REG(wl,hwmodelist),
729         LUA_REG(wl,encryption),
730         LUA_REG(wl,mbssid_support),
731         LUA_REG(wl,hardware_id),
732         LUA_REG(wl,hardware_name),
733         { NULL, NULL }
734 };
735 #endif
736
737 #ifdef USE_MADWIFI
738 /* Madwifi table */
739 static const luaL_reg R_madwifi[] = {
740         LUA_REG(madwifi,channel),
741         LUA_REG(madwifi,frequency),
742         LUA_REG(madwifi,frequency_offset),
743         LUA_REG(madwifi,txpower),
744         LUA_REG(madwifi,txpower_offset),
745         LUA_REG(madwifi,bitrate),
746         LUA_REG(madwifi,signal),
747         LUA_REG(madwifi,noise),
748         LUA_REG(madwifi,quality),
749         LUA_REG(madwifi,quality_max),
750         LUA_REG(madwifi,mode),
751         LUA_REG(madwifi,ssid),
752         LUA_REG(madwifi,bssid),
753         LUA_REG(madwifi,country),
754         LUA_REG(madwifi,assoclist),
755         LUA_REG(madwifi,txpwrlist),
756         LUA_REG(madwifi,scanlist),
757         LUA_REG(madwifi,freqlist),
758         LUA_REG(madwifi,countrylist),
759         LUA_REG(madwifi,hwmodelist),
760         LUA_REG(madwifi,encryption),
761         LUA_REG(madwifi,mbssid_support),
762         LUA_REG(madwifi,hardware_id),
763         LUA_REG(madwifi,hardware_name),
764         { NULL, NULL }
765 };
766 #endif
767
768 #ifdef USE_NL80211
769 /* NL80211 table */
770 static const luaL_reg R_nl80211[] = {
771         LUA_REG(nl80211,channel),
772         LUA_REG(nl80211,frequency),
773         LUA_REG(nl80211,frequency_offset),
774         LUA_REG(nl80211,txpower),
775         LUA_REG(nl80211,txpower_offset),
776         LUA_REG(nl80211,bitrate),
777         LUA_REG(nl80211,signal),
778         LUA_REG(nl80211,noise),
779         LUA_REG(nl80211,quality),
780         LUA_REG(nl80211,quality_max),
781         LUA_REG(nl80211,mode),
782         LUA_REG(nl80211,ssid),
783         LUA_REG(nl80211,bssid),
784         LUA_REG(nl80211,country),
785         LUA_REG(nl80211,assoclist),
786         LUA_REG(nl80211,txpwrlist),
787         LUA_REG(nl80211,scanlist),
788         LUA_REG(nl80211,freqlist),
789         LUA_REG(nl80211,countrylist),
790         LUA_REG(nl80211,hwmodelist),
791         LUA_REG(nl80211,encryption),
792         LUA_REG(nl80211,mbssid_support),
793         LUA_REG(nl80211,hardware_id),
794         LUA_REG(nl80211,hardware_name),
795         { NULL, NULL }
796 };
797 #endif
798
799 /* Wext table */
800 static const luaL_reg R_wext[] = {
801         LUA_REG(wext,channel),
802         LUA_REG(wext,frequency),
803         LUA_REG(wext,frequency_offset),
804         LUA_REG(wext,txpower),
805         LUA_REG(wext,txpower_offset),
806         LUA_REG(wext,bitrate),
807         LUA_REG(wext,signal),
808         LUA_REG(wext,noise),
809         LUA_REG(wext,quality),
810         LUA_REG(wext,quality_max),
811         LUA_REG(wext,mode),
812         LUA_REG(wext,ssid),
813         LUA_REG(wext,bssid),
814         LUA_REG(wext,country),
815         LUA_REG(wext,assoclist),
816         LUA_REG(wext,txpwrlist),
817         LUA_REG(wext,scanlist),
818         LUA_REG(wext,freqlist),
819         LUA_REG(wext,countrylist),
820         LUA_REG(wext,hwmodelist),
821         LUA_REG(wext,encryption),
822         LUA_REG(wext,mbssid_support),
823         LUA_REG(wext,hardware_id),
824         LUA_REG(wext,hardware_name),
825         { NULL, NULL }
826 };
827
828 /* Common */
829 static const luaL_reg R_common[] = {
830         { "type", iwinfo_L_type },
831         { "__gc", iwinfo_L__gc  },
832         { NULL, NULL }
833 };
834
835
836 LUALIB_API int luaopen_iwinfo(lua_State *L) {
837         luaL_register(L, IWINFO_META, R_common);
838
839 #ifdef USE_WL
840         luaL_newmetatable(L, IWINFO_WL_META);
841         luaL_register(L, NULL, R_wl);
842         lua_pushvalue(L, -1);
843         lua_setfield(L, -2, "__index");
844         lua_setfield(L, -2, "wl");
845 #endif
846
847 #ifdef USE_MADWIFI
848         luaL_newmetatable(L, IWINFO_MADWIFI_META);
849         luaL_register(L, NULL, R_madwifi);
850         lua_pushvalue(L, -1);
851         lua_setfield(L, -2, "__index");
852         lua_setfield(L, -2, "madwifi");
853 #endif
854
855 #ifdef USE_NL80211
856         luaL_newmetatable(L, IWINFO_NL80211_META);
857         luaL_register(L, NULL, R_nl80211);
858         lua_pushvalue(L, -1);
859         lua_setfield(L, -2, "__index");
860         lua_setfield(L, -2, "nl80211");
861 #endif
862
863         luaL_newmetatable(L, IWINFO_WEXT_META);
864         luaL_register(L, NULL, R_wext);
865         lua_pushvalue(L, -1);
866         lua_setfield(L, -2, "__index");
867         lua_setfield(L, -2, "wext");
868
869         return 1;
870 }