const struct iwinfo_ops * iwinfo_backend(const char *ifname);
void iwinfo_finish(void);
-#include "iwinfo/wext.h"
+extern const struct iwinfo_ops wext_ops;
#ifdef USE_WL
#include "iwinfo/wl.h"
#include <lauxlib.h>
#include "iwinfo.h"
-#include "iwinfo/wext_scan.h"
#define IWINFO_META "iwinfo"
return 1; \
}
+#define LUA_WRAP_INT_OP(type,op) \
+ static int iwinfo_L_##type##_##op(lua_State *L) \
+ { \
+ const char *ifname = luaL_checkstring(L, 1); \
+ int rv; \
+ if( !type##_ops.op(ifname, &rv) ) \
+ lua_pushnumber(L, rv); \
+ else \
+ lua_pushnil(L); \
+ return 1; \
+ }
+
#define LUA_WRAP_STRING(type,op) \
static int iwinfo_L_##type##_##op(lua_State *L) \
{ \
return 1; \
}
+#define LUA_WRAP_STRING_OP(type,op) \
+ static int iwinfo_L_##type##_##op(lua_State *L) \
+ { \
+ const char *ifname = luaL_checkstring(L, 1); \
+ char rv[IWINFO_BUFSIZE]; \
+ memset(rv, 0, IWINFO_BUFSIZE); \
+ if( !type##_ops.op(ifname, rv) ) \
+ lua_pushstring(L, rv); \
+ else \
+ lua_pushnil(L); \
+ return 1; \
+ }
+
#define LUA_WRAP_STRUCT(type,op) \
static int iwinfo_L_##type##_##op(lua_State *L) \
{ \
return iwinfo_L_##op(L, type##_get_##op); \
}
+#define LUA_WRAP_STRUCT_OP(type,op) \
+ static int iwinfo_L_##type##_##op(lua_State *L) \
+ { \
+ return iwinfo_L_##op(L, type##_ops.op); \
+ }
+
#endif
+++ /dev/null
-/*
- * iwinfo - Wireless Information Library - Linux Wireless Extension Headers
- *
- * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
- *
- * The iwinfo library is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * The iwinfo library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
- */
-
-#ifndef __IWINFO_WEXT_H_
-#define __IWINFO_WEXT_H_
-
-#include <fcntl.h>
-
-#include "iwinfo.h"
-#include "iwinfo/utils.h"
-#include "iwinfo/api/wext.h"
-
-
-int wext_probe(const char *ifname);
-int wext_get_mode(const char *ifname, int *buf);
-int wext_get_ssid(const char *ifname, char *buf);
-int wext_get_bssid(const char *ifname, char *buf);
-int wext_get_country(const char *ifname, char *buf);
-int wext_get_channel(const char *ifname, int *buf);
-int wext_get_frequency(const char *ifname, int *buf);
-int wext_get_frequency_offset(const char *ifname, int *buf);
-int wext_get_txpower(const char *ifname, int *buf);
-int wext_get_txpower_offset(const char *ifname, int *buf);
-int wext_get_bitrate(const char *ifname, int *buf);
-int wext_get_signal(const char *ifname, int *buf);
-int wext_get_noise(const char *ifname, int *buf);
-int wext_get_quality(const char *ifname, int *buf);
-int wext_get_quality_max(const char *ifname, int *buf);
-int wext_get_encryption(const char *ifname, char *buf);
-int wext_get_phyname(const char *ifname, char *buf);
-int wext_get_assoclist(const char *ifname, char *buf, int *len);
-int wext_get_txpwrlist(const char *ifname, char *buf, int *len);
-int wext_get_scanlist(const char *ifname, char *buf, int *len);
-int wext_get_freqlist(const char *ifname, char *buf, int *len);
-int wext_get_countrylist(const char *ifname, char *buf, int *len);
-int wext_get_hwmodelist(const char *ifname, int *buf);
-int wext_get_mbssid_support(const char *ifname, int *buf);
-int wext_get_hardware_id(const char *ifname, char *buf);
-int wext_get_hardware_name(const char *ifname, char *buf);
-void wext_close(void);
-
-static const struct iwinfo_ops wext_ops = {
- .name = "wext",
- .probe = wext_probe,
- .channel = wext_get_channel,
- .frequency = wext_get_frequency,
- .frequency_offset = wext_get_frequency_offset,
- .txpower = wext_get_txpower,
- .txpower_offset = wext_get_txpower_offset,
- .bitrate = wext_get_bitrate,
- .signal = wext_get_signal,
- .noise = wext_get_noise,
- .quality = wext_get_quality,
- .quality_max = wext_get_quality_max,
- .mbssid_support = wext_get_mbssid_support,
- .hwmodelist = wext_get_hwmodelist,
- .mode = wext_get_mode,
- .ssid = wext_get_ssid,
- .bssid = wext_get_bssid,
- .country = wext_get_country,
- .hardware_id = wext_get_hardware_id,
- .hardware_name = wext_get_hardware_name,
- .encryption = wext_get_encryption,
- .phyname = wext_get_phyname,
- .assoclist = wext_get_assoclist,
- .txpwrlist = wext_get_txpwrlist,
- .scanlist = wext_get_scanlist,
- .freqlist = wext_get_freqlist,
- .countrylist = wext_get_countrylist,
- .close = wext_close
-};
-
-#endif
#endif
/* Wext */
-LUA_WRAP_INT(wext,channel)
-LUA_WRAP_INT(wext,frequency)
-LUA_WRAP_INT(wext,frequency_offset)
-LUA_WRAP_INT(wext,txpower)
-LUA_WRAP_INT(wext,txpower_offset)
-LUA_WRAP_INT(wext,bitrate)
-LUA_WRAP_INT(wext,signal)
-LUA_WRAP_INT(wext,noise)
-LUA_WRAP_INT(wext,quality)
-LUA_WRAP_INT(wext,quality_max)
-LUA_WRAP_STRING(wext,ssid)
-LUA_WRAP_STRING(wext,bssid)
-LUA_WRAP_STRING(wext,country)
-LUA_WRAP_STRING(wext,hardware_name)
-LUA_WRAP_STRING(wext,phyname)
-LUA_WRAP_STRUCT(wext,mode)
-LUA_WRAP_STRUCT(wext,assoclist)
-LUA_WRAP_STRUCT(wext,txpwrlist)
-LUA_WRAP_STRUCT(wext,scanlist)
-LUA_WRAP_STRUCT(wext,freqlist)
-LUA_WRAP_STRUCT(wext,countrylist)
-LUA_WRAP_STRUCT(wext,hwmodelist)
-LUA_WRAP_STRUCT(wext,encryption)
-LUA_WRAP_STRUCT(wext,mbssid_support)
-LUA_WRAP_STRUCT(wext,hardware_id)
+LUA_WRAP_INT_OP(wext,channel)
+LUA_WRAP_INT_OP(wext,frequency)
+LUA_WRAP_INT_OP(wext,frequency_offset)
+LUA_WRAP_INT_OP(wext,txpower)
+LUA_WRAP_INT_OP(wext,txpower_offset)
+LUA_WRAP_INT_OP(wext,bitrate)
+LUA_WRAP_INT_OP(wext,signal)
+LUA_WRAP_INT_OP(wext,noise)
+LUA_WRAP_INT_OP(wext,quality)
+LUA_WRAP_INT_OP(wext,quality_max)
+LUA_WRAP_STRING_OP(wext,ssid)
+LUA_WRAP_STRING_OP(wext,bssid)
+LUA_WRAP_STRING_OP(wext,country)
+LUA_WRAP_STRING_OP(wext,hardware_name)
+LUA_WRAP_STRING_OP(wext,phyname)
+LUA_WRAP_STRUCT_OP(wext,mode)
+LUA_WRAP_STRUCT_OP(wext,assoclist)
+LUA_WRAP_STRUCT_OP(wext,txpwrlist)
+LUA_WRAP_STRUCT_OP(wext,scanlist)
+LUA_WRAP_STRUCT_OP(wext,freqlist)
+LUA_WRAP_STRUCT_OP(wext,countrylist)
+LUA_WRAP_STRUCT_OP(wext,hwmodelist)
+LUA_WRAP_STRUCT_OP(wext,encryption)
+LUA_WRAP_STRUCT_OP(wext,mbssid_support)
+LUA_WRAP_STRUCT_OP(wext,hardware_id)
#ifdef USE_WL
/* Broadcom table */
*/
#include "iwinfo/madwifi.h"
-#include "iwinfo/wext.h"
+#include "iwinfo_wext.h"
/*
int madwifi_get_mode(const char *ifname, int *buf)
{
- return wext_get_mode(ifname, buf);
+ return wext_ops.mode(ifname, buf);
}
int madwifi_get_ssid(const char *ifname, char *buf)
{
- return wext_get_ssid(ifname, buf);
+ return wext_ops.ssid(ifname, buf);
}
int madwifi_get_bssid(const char *ifname, char *buf)
{
- return wext_get_bssid(ifname, buf);
+ return wext_ops.bssid(ifname, buf);
}
int madwifi_get_channel(const char *ifname, int *buf)
int madwifi_get_txpower(const char *ifname, int *buf)
{
- return wext_get_txpower(ifname, buf);
+ return wext_ops.txpower(ifname, buf);
}
int madwifi_get_bitrate(const char *ifname, int *buf)
}
/* Return whatever wext tells us ... */
- return wext_get_bitrate(ifname, buf);
+ return wext_ops.bitrate(ifname, buf);
}
return -1;
}
/* Return whatever wext tells us ... */
- return wext_get_signal(ifname, buf);
+ return wext_ops.signal(ifname, buf);
}
return -1;
int madwifi_get_noise(const char *ifname, int *buf)
{
- return wext_get_noise(ifname, buf);
+ return wext_ops.noise(ifname, buf);
}
int madwifi_get_quality(const char *ifname, int *buf)
}
/* Return whatever wext tells us ... */
- return wext_get_quality(ifname, buf);
+ return wext_ops.quality(ifname, buf);
}
return -1;
int madwifi_get_quality_max(const char *ifname, int *buf)
{
- return wext_get_quality_max(ifname, buf);
+ return wext_ops.quality_max(ifname, buf);
}
int madwifi_get_encryption(const char *ifname, char *buf)
{
if( (res = madwifi_ifadd(ifname)) != NULL )
{
- rc = wext_get_txpwrlist(res, buf, len);
+ rc = wext_ops.txpwrlist(res, buf, len);
madwifi_ifdel(res);
}
}
/* Its an athX ... */
else if( !!madwifi_isvap(ifname, NULL) )
{
- rc = wext_get_txpwrlist(ifname, buf, len);
+ rc = wext_ops.txpwrlist(ifname, buf, len);
}
return rc;
{
if( iwinfo_ifup(e->d_name) )
{
- ret = wext_get_scanlist(e->d_name, buf, len);
+ ret = wext_ops.scanlist(e->d_name, buf, len);
break;
}
}
{
if( iwinfo_ifup(res) )
{
- wext_get_scanlist(res, buf, len);
+ wext_ops.scanlist(res, buf, len);
sleep(1);
- wext_get_scanlist(res, buf, len);
+ wext_ops.scanlist(res, buf, len);
sleep(1);
- ret = wext_get_scanlist(res, buf, len);
+ ret = wext_ops.scanlist(res, buf, len);
}
iwinfo_ifdown(res);
/* Got athX device? */
else if( !!madwifi_isvap(ifname, NULL) )
{
- ret = wext_get_scanlist(ifname, buf, len);
+ ret = wext_ops.scanlist(ifname, buf, len);
}
return ret;
struct iwinfo_hardware_entry *e;
const char *phy = madwifi_phyname(ifname);
- if (wext_get_hardware_id(phy, buf))
+ if (wext_ops.hardware_id(phy, buf))
return iwinfo_hardware_id_from_mtd((struct iwinfo_hardware_id *)buf);
return 0;
*/
#include "iwinfo/nl80211.h"
-#include "iwinfo/wext.h"
#define min(x, y) ((x) < (y)) ? (x) : (y)
return 0;
#endif
- return wext_get_txpower(ifname, buf);
+ return wext_ops.txpower(ifname, buf);
}
/* Reuse existing interface */
if ((res = nl80211_phy2ifname(ifname)) != NULL)
{
- rv = wext_get_hardware_id(res, buf);
+ rv = wext_ops.hardware_id(res, buf);
}
/* Need to spawn a temporary iface for finding IDs */
else if ((res = nl80211_ifadd(ifname)) != NULL)
{
- rv = wext_get_hardware_id(res, buf);
+ rv = wext_ops.hardware_id(res, buf);
nl80211_ifdel(res);
}
}
else
{
- rv = wext_get_hardware_id(ifname, buf);
+ rv = wext_ops.hardware_id(ifname, buf);
}
/* Failed to obtain hardware IDs, search board config */
*/
#include "iwinfo.h"
-#include "iwinfo/wext.h"
+#include "iwinfo_wext.h"
static double wext_freq2float(const struct iw_freq *in)
{
}
-int wext_probe(const char *ifname)
+static int wext_probe(const char *ifname)
{
struct iwreq wrq;
return 0;
}
-void wext_close(void)
+static void wext_close(void)
{
/* Nop */
}
-int wext_get_mode(const char *ifname, int *buf)
+static int wext_get_mode(const char *ifname, int *buf)
{
struct iwreq wrq;
return -1;
}
-int wext_get_ssid(const char *ifname, char *buf)
+static int wext_get_ssid(const char *ifname, char *buf)
{
struct iwreq wrq;
return -1;
}
-int wext_get_bssid(const char *ifname, char *buf)
+static int wext_get_bssid(const char *ifname, char *buf)
{
struct iwreq wrq;
return -1;
}
-int wext_get_bitrate(const char *ifname, int *buf)
+static int wext_get_bitrate(const char *ifname, int *buf)
{
struct iwreq wrq;
return -1;
}
-int wext_get_channel(const char *ifname, int *buf)
+static int wext_get_channel(const char *ifname, int *buf)
{
struct iwreq wrq;
struct iw_range range;
return -1;
}
-int wext_get_frequency(const char *ifname, int *buf)
+static int wext_get_frequency(const char *ifname, int *buf)
{
struct iwreq wrq;
struct iw_range range;
return -1;
}
-int wext_get_txpower(const char *ifname, int *buf)
+static int wext_get_txpower(const char *ifname, int *buf)
{
struct iwreq wrq;
return -1;
}
-int wext_get_signal(const char *ifname, int *buf)
+static int wext_get_signal(const char *ifname, int *buf)
{
struct iwreq wrq;
struct iw_statistics stats;
return -1;
}
-int wext_get_noise(const char *ifname, int *buf)
+static int wext_get_noise(const char *ifname, int *buf)
{
struct iwreq wrq;
struct iw_statistics stats;
return -1;
}
-int wext_get_quality(const char *ifname, int *buf)
+static int wext_get_quality(const char *ifname, int *buf)
{
struct iwreq wrq;
struct iw_statistics stats;
return -1;
}
-int wext_get_quality_max(const char *ifname, int *buf)
+static int wext_get_quality_max(const char *ifname, int *buf)
{
struct iwreq wrq;
struct iw_range range;
return -1;
}
-int wext_get_assoclist(const char *ifname, char *buf, int *len)
+static int wext_get_assoclist(const char *ifname, char *buf, int *len)
{
/* Stub */
return -1;
}
-int wext_get_txpwrlist(const char *ifname, char *buf, int *len)
+static int wext_get_txpwrlist(const char *ifname, char *buf, int *len)
{
struct iwreq wrq;
struct iw_range range;
return -1;
}
-int wext_get_freqlist(const char *ifname, char *buf, int *len)
+static int wext_get_freqlist(const char *ifname, char *buf, int *len)
{
struct iwreq wrq;
struct iw_range range;
return -1;
}
-int wext_get_country(const char *ifname, char *buf)
+static int wext_get_country(const char *ifname, char *buf)
{
sprintf(buf, "00");
return 0;
}
-int wext_get_countrylist(const char *ifname, char *buf, int *len)
+static int wext_get_countrylist(const char *ifname, char *buf, int *len)
{
/* Stub */
return -1;
}
-int wext_get_hwmodelist(const char *ifname, int *buf)
+static int wext_get_hwmodelist(const char *ifname, int *buf)
{
char chans[IWINFO_BUFSIZE] = { 0 };
struct iwinfo_freqlist_entry *e = NULL;
return -1;
}
-int wext_get_encryption(const char *ifname, char *buf)
+static int wext_get_encryption(const char *ifname, char *buf)
{
/* No reliable crypto info in wext */
return -1;
}
-int wext_get_phyname(const char *ifname, char *buf)
+static int wext_get_phyname(const char *ifname, char *buf)
{
/* No suitable api in wext */
strcpy(buf, ifname);
return 0;
}
-int wext_get_mbssid_support(const char *ifname, int *buf)
+static int wext_get_mbssid_support(const char *ifname, int *buf)
{
/* No multi bssid support atm */
return -1;
return rv;
}
-int wext_get_hardware_id(const char *ifname, char *buf)
+static int wext_get_hardware_id(const char *ifname, char *buf)
{
char *data;
struct iwinfo_hardware_id *id = (struct iwinfo_hardware_id *)buf;
return (id->vendor_id > 0 && id->device_id > 0) ? 0 : -1;
}
-int wext_get_hardware_name(const char *ifname, char *buf)
+static int wext_get_hardware_name(const char *ifname, char *buf)
{
sprintf(buf, "Generic WEXT");
return 0;
}
-int wext_get_txpower_offset(const char *ifname, int *buf)
+static int wext_get_txpower_offset(const char *ifname, int *buf)
{
/* Stub */
*buf = 0;
return -1;
}
-int wext_get_frequency_offset(const char *ifname, int *buf)
+static int wext_get_frequency_offset(const char *ifname, int *buf)
{
/* Stub */
*buf = 0;
return -1;
}
+
+const struct iwinfo_ops wext_ops = {
+ .name = "wext",
+ .probe = wext_probe,
+ .channel = wext_get_channel,
+ .frequency = wext_get_frequency,
+ .frequency_offset = wext_get_frequency_offset,
+ .txpower = wext_get_txpower,
+ .txpower_offset = wext_get_txpower_offset,
+ .bitrate = wext_get_bitrate,
+ .signal = wext_get_signal,
+ .noise = wext_get_noise,
+ .quality = wext_get_quality,
+ .quality_max = wext_get_quality_max,
+ .mbssid_support = wext_get_mbssid_support,
+ .hwmodelist = wext_get_hwmodelist,
+ .mode = wext_get_mode,
+ .ssid = wext_get_ssid,
+ .bssid = wext_get_bssid,
+ .country = wext_get_country,
+ .hardware_id = wext_get_hardware_id,
+ .hardware_name = wext_get_hardware_name,
+ .encryption = wext_get_encryption,
+ .phyname = wext_get_phyname,
+ .assoclist = wext_get_assoclist,
+ .txpwrlist = wext_get_txpwrlist,
+ .scanlist = wext_get_scanlist,
+ .freqlist = wext_get_freqlist,
+ .countrylist = wext_get_countrylist,
+ .close = wext_close
+};
#define IW_IE_CYPHER_NUM 8
#define IW_IE_KEY_MGMT_NUM 3
+int wext_get_scanlist(const char *ifname, char *buf, int *len);
+
#endif
*/
#include "iwinfo.h"
-#include "iwinfo/wext_scan.h"
+#include "iwinfo_wext.h"
static int wext_ioctl(const char *ifname, int cmd, struct iwreq *wrq)
*/
#include "iwinfo/wl.h"
-#include "iwinfo/wext.h"
static int wl_ioctl(const char *name, int cmd, void *buf, int len)
{
int wl_get_frequency(const char *ifname, int *buf)
{
- return wext_get_frequency(ifname, buf);
+ return wext_ops.frequency(ifname, buf);
}
int wl_get_txpower(const char *ifname, int *buf)
{
/* WLC_GET_VAR "qtxpower" */
- return wext_get_txpower(ifname, buf);
+ return wext_ops.txpower(ifname, buf);
}
int wl_get_bitrate(const char *ifname, int *buf)
int wl_get_quality(const char *ifname, int *buf)
{
- return wext_get_quality(ifname, buf);
+ return wext_ops.quality(ifname, buf);
}
int wl_get_quality_max(const char *ifname, int *buf)
{
- return wext_get_quality_max(ifname, buf);
+ return wext_ops.quality_max(ifname, buf);
}
int wl_get_encryption(const char *ifname, char *buf)
int wl_get_scanlist(const char *ifname, char *buf, int *len)
{
- return wext_get_scanlist(ifname, buf, len);
+ return wext_ops.scanlist(ifname, buf, len);
}
int wl_get_freqlist(const char *ifname, char *buf, int *len)
{
- return wext_get_freqlist(ifname, buf, len);
+ return wext_ops.freqlist(ifname, buf, len);
}
int wl_get_country(const char *ifname, char *buf)