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