iwinfo: add initial hardware detection capabilities
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 4 Dec 2011 03:42:17 +0000 (03:42 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 4 Dec 2011 03:42:17 +0000 (03:42 +0000)
SVN-Revision: 29421

16 files changed:
package/iwinfo/Makefile
package/iwinfo/src/include/iwinfo.h
package/iwinfo/src/include/iwinfo/lua.h
package/iwinfo/src/include/iwinfo/madwifi.h
package/iwinfo/src/include/iwinfo/nl80211.h
package/iwinfo/src/include/iwinfo/utils.h
package/iwinfo/src/include/iwinfo/wext.h
package/iwinfo/src/include/iwinfo/wl.h
package/iwinfo/src/iwinfo_cli.c
package/iwinfo/src/iwinfo_lib.c
package/iwinfo/src/iwinfo_lua.c
package/iwinfo/src/iwinfo_madwifi.c
package/iwinfo/src/iwinfo_nl80211.c
package/iwinfo/src/iwinfo_utils.c
package/iwinfo/src/iwinfo_wext.c
package/iwinfo/src/iwinfo_wl.c

index a6611397949452ef687a44839456a15609e8a7e8..db11844cfb0bae3bc49e8b5f7c1157c3d606c75e 100644 (file)
@@ -7,7 +7,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=libiwinfo
-PKG_RELEASE:=18
+PKG_RELEASE:=19
 
 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
 
index 824b945365bf47af78c341a5c2549f2ac2b86ab3..86bf8b1b6d067af47a4b2f4bcba9b0e494cc46a2 100644 (file)
@@ -95,7 +95,26 @@ struct iwinfo_iso3166_label {
        uint8_t  name[28];
 };
 
+struct iwinfo_hardware_id {
+       uint16_t vendor_id;
+       uint16_t device_id;
+       uint16_t subsystem_vendor_id;
+       uint16_t subsystem_device_id;
+};
+
+struct iwinfo_hardware_entry {
+       const char *vendor_name;
+       const char *device_name;
+       uint16_t vendor_id;
+       uint16_t device_id;
+       uint16_t subsystem_vendor_id;
+       uint16_t subsystem_device_id;
+       int16_t txpower_offset;
+       int16_t frequency_offset;
+};
+
 extern const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[];
+extern const struct iwinfo_hardware_entry IWINFO_HARDWARE_ENTRIES[];
 
 
 struct iwinfo_ops {
@@ -113,6 +132,8 @@ struct iwinfo_ops {
        int (*ssid)(const char *, char *);
        int (*bssid)(const char *, char *);
        int (*country)(const char *, char *);
+       int (*hardware_id)(const char *, char *);
+       int (*hardware_name)(const char *, char *);
        int (*encryption)(const char *, char *);
        int (*assoclist)(const char *, char *, int *);
        int (*txpwrlist)(const char *, char *, int *);
index 65a3a5cb910930346b52e559a01c6531870ad3a1..d976c0cf467cd4c5db9026f534cccea108da862e 100644 (file)
                return 1;                                                                               \
        }
 
-#define LUA_WRAP_LIST(type,op)                                                 \
+#define LUA_WRAP_STRUCT(type,op)                                               \
        static int iwinfo_L_##type##_##op(lua_State *L)         \
        {                                                                                                       \
                return iwinfo_L_##op(L, type##_get_##op);               \
        }
 
 #endif
-
index 4de48557d44172ca453af8dc5f9249f4aa8f9e41..ecbe749c8abd50d4e6116abbda40132d312a9b39 100644 (file)
@@ -46,6 +46,8 @@ int madwifi_get_freqlist(const char *ifname, char *buf, int *len);
 int madwifi_get_countrylist(const char *ifname, char *buf, int *len);
 int madwifi_get_hwmodelist(const char *ifname, int *buf);
 int madwifi_get_mbssid_support(const char *ifname, int *buf);
+int madwifi_get_hardware_id(const char *ifname, char *buf);
+int madwifi_get_hardware_name(const char *ifname, char *buf);
 void madwifi_close(void);
 
 static const struct iwinfo_ops madwifi_ops = {
@@ -63,6 +65,8 @@ static const struct iwinfo_ops madwifi_ops = {
        .ssid           = madwifi_get_ssid,
        .bssid          = madwifi_get_bssid,
        .country        = madwifi_get_country,
+       .hardware_id    = madwifi_get_hardware_id,
+       .hardware_name  = madwifi_get_hardware_name,
        .encryption     = madwifi_get_encryption,
        .assoclist      = madwifi_get_assoclist,
        .txpwrlist      = madwifi_get_txpwrlist,
index dce508cf0ae4b1dbbf6ca6bdc55e994c3e6391ab..3df25d34b44a68c3705a16de0cf31a6372992ff3 100644 (file)
@@ -77,6 +77,8 @@ int nl80211_get_freqlist(const char *ifname, char *buf, int *len);
 int nl80211_get_countrylist(const char *ifname, char *buf, int *len);
 int nl80211_get_hwmodelist(const char *ifname, int *buf);
 int nl80211_get_mbssid_support(const char *ifname, int *buf);
+int nl80211_get_hardware_id(const char *ifname, char *buf);
+int nl80211_get_hardware_name(const char *ifname, char *buf);
 void nl80211_close(void);
 
 static const struct iwinfo_ops nl80211_ops = {
@@ -94,6 +96,8 @@ static const struct iwinfo_ops nl80211_ops = {
        .ssid           = nl80211_get_ssid,
        .bssid          = nl80211_get_bssid,
        .country        = nl80211_get_country,
+       .hardware_id    = nl80211_get_hardware_id,
+       .hardware_name  = nl80211_get_hardware_name,
        .encryption     = nl80211_get_encryption,
        .assoclist      = nl80211_get_assoclist,
        .txpwrlist      = nl80211_get_txpwrlist,
index 57958b1b54967ff592eee6d3a823c6b3d7008e74..e897b2718a332b6924d0bac860a805c3a74f56df 100644 (file)
@@ -37,4 +37,6 @@ int iwinfo_ifmac(const char *ifname);
 
 void iwinfo_close(void);
 
+struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id);
+
 #endif
index 69b7a8e3d031255cbcaf2e4d4c417b48ae7fc5b4..4d2f4aa0a246894a252eb03f3d6e6e1949d63b30 100644 (file)
@@ -47,6 +47,8 @@ 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 = {
@@ -64,6 +66,8 @@ static const struct iwinfo_ops wext_ops = {
        .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,
        .assoclist      = wext_get_assoclist,
        .txpwrlist      = wext_get_txpwrlist,
index e931f7c6e37f2f870089682029a5ad4f1d65fd1b..10be96aeb9a540a4bb30fdbeea902f0578d7f64a 100644 (file)
@@ -47,6 +47,8 @@ int wl_get_freqlist(const char *ifname, char *buf, int *len);
 int wl_get_countrylist(const char *ifname, char *buf, int *len);
 int wl_get_hwmodelist(const char *ifname, int *buf);
 int wl_get_mbssid_support(const char *ifname, int *buf);
+int wl_get_hardware_id(const char *ifname, char *buf);
+int wl_get_hardware_name(const char *ifname, char *buf);
 void wl_close(void);
 
 static const struct iwinfo_ops wl_ops = {
@@ -64,6 +66,8 @@ static const struct iwinfo_ops wl_ops = {
        .ssid           = wl_get_ssid,
        .bssid          = wl_get_bssid,
        .country        = wl_get_country,
+       .hardware_id    = wl_get_hardware_id,
+       .hardware_name  = wl_get_hardware_name,
        .encryption     = wl_get_encryption,
        .assoclist      = wl_get_assoclist,
        .txpwrlist      = wl_get_txpwrlist,
index 4229b19f565e86c4bfb0e17c12e8b937785b767e..bfa1d88ef90b48752cf7c858f14bcfe0bd8da73f 100644 (file)
@@ -282,6 +282,35 @@ static const char * print_type(const struct iwinfo_ops *iw, const char *ifname)
        return type ? type : "unknown";
 }
 
+static char * print_hardware_id(const struct iwinfo_ops *iw, const char *ifname)
+{
+       static char buf[20];
+       struct iwinfo_hardware_id ids;
+
+       if (!iw->hardware_id(ifname, (char *)&ids))
+       {
+               snprintf(buf, sizeof(buf), "%04X:%04X %04X:%04X",
+                       ids.vendor_id, ids.device_id,
+                       ids.subsystem_vendor_id, ids.subsystem_device_id);
+       }
+       else
+       {
+               snprintf(buf, sizeof(buf), "unknown");
+       }
+
+       return buf;
+}
+
+static char * print_hardware_name(const struct iwinfo_ops *iw, const char *ifname)
+{
+       static char buf[128];
+
+       if (iw->hardware_name(ifname, buf))
+               snprintf(buf, sizeof(buf), "unknown");
+
+       return buf;
+}
+
 static char * print_ssid(const struct iwinfo_ops *iw, const char *ifname)
 {
        char buf[IWINFO_ESSID_MAX_SIZE+1] = { 0 };
@@ -423,9 +452,6 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname)
                print_ssid(iw, ifname));
        printf("          Access Point: %s\n",
                print_bssid(iw, ifname));
-       printf("          Type: %s  HW Mode(s): %s\n",
-               print_type(iw, ifname),
-               print_hwmodes(iw, ifname));
        printf("          Mode: %s  Channel: %s (%s)\n",
                print_mode(iw, ifname),
                print_channel(iw, ifname),
@@ -441,6 +467,12 @@ static void print_info(const struct iwinfo_ops *iw, const char *ifname)
                print_rate(iw, ifname));
        printf("          Encryption: %s\n",
                print_encryption(iw, ifname));
+       printf("          Type: %s  HW Mode(s): %s\n",
+               print_type(iw, ifname),
+               print_hwmodes(iw, ifname));
+       printf("          Hardware: %s [%s]\n",
+               print_hardware_id(iw, ifname),
+               print_hardware_name(iw, ifname));
        printf("          Supports VAPs: %s\n",
                print_mbssid_supp(iw, ifname));
 }
index a7160417d2e750e3999e28092523770a7bcfe998..ca2dc3b2e9b8d3d08874a0ec64554417aeac78b8 100644 (file)
@@ -300,6 +300,58 @@ const struct iwinfo_iso3166_label IWINFO_ISO3166_NAMES[] = {
        { 0,               "" }
 };
 
+/*
+ * hardware database
+ */
+
+const char VENDOR_UBNT[] = "Ubiquiti";
+const char VENDOR_ATH[]  = "Atheros";
+
+const struct iwinfo_hardware_entry IWINFO_HARDWARE_ENTRIES[] = {
+/*     { vendor, model, vendorid, deviceid, subsys vendorid, subsys deviceid, poweroff, freqoff } */
+#if defined(USE_MADWIFI) || defined(USE_NL80211)
+       { VENDOR_UBNT, "PowerStation2 (18V)",   0xffff, 0xffff, 0xffff, 0xb102,  0,     0 },
+       { VENDOR_UBNT, "PowerStation2 (16D)",   0xffff, 0xffff, 0xffff, 0xb202,  0,     0 },
+       { VENDOR_UBNT, "PowerStation2 (EXT)",   0xffff, 0xffff, 0xffff, 0xb302,  0,     0 },
+       { VENDOR_UBNT, "PowerStation5 (22V)",   0xffff, 0xffff, 0xffff, 0xb105,  0,     0 },
+       { VENDOR_UBNT, "PowerStation5 (EXT)",   0xffff, 0xffff, 0xffff, 0xb305,  0,     0 },
+       { VENDOR_UBNT, "WispStation5",          0xffff, 0xffff, 0xffff, 0xa105,  0,     0 },
+       { VENDOR_UBNT, "LiteStation2",          0xffff, 0xffff, 0xffff, 0xa002,  0,     0 },
+       { VENDOR_UBNT, "LiteStation5",          0xffff, 0xffff, 0xffff, 0xa005,  0,     0 },
+       { VENDOR_UBNT, "NanoStation2",          0xffff, 0xffff, 0xffff, 0xc002,  0,     0 },
+       { VENDOR_UBNT, "NanoStation5",          0xffff, 0xffff, 0xffff, 0xc005,  0,     0 },
+       { VENDOR_UBNT, "NanoStation Loco2",     0xffff, 0xffff, 0xffff, 0xc102,  0,     0 },
+       { VENDOR_UBNT, "NanoStation Loco5",     0xffff, 0xffff, 0xffff, 0xc105,  0,     0 },
+       { VENDOR_UBNT, "Bullet2",               0xffff, 0xffff, 0xffff, 0xc202,  0,     0 },
+       { VENDOR_UBNT, "Bullet5",               0xffff, 0xffff, 0xffff, 0xc205,  0,     0 },
+       { VENDOR_UBNT, "XR2",                   0x168c, 0x001b, 0x0777, 0x3002, 10,     0 },
+       { VENDOR_UBNT, "XR2",                   0x168c, 0x001b, 0x7777, 0x3002, 10,     0 },
+       { VENDOR_UBNT, "XR2.3",                 0x168c, 0x001b, 0x0777, 0x3b02, 10,     0 },
+       { VENDOR_UBNT, "XR2.6",                 0x168c, 0x001b, 0x0777, 0x3c02, 10,     0 },
+       { VENDOR_UBNT, "XR3-2.8",               0x168c, 0x001b, 0x0777, 0x3b03, 10,     0 },
+       { VENDOR_UBNT, "XR3-3.6",               0x168c, 0x001b, 0x0777, 0x3c03, 10,     0 },
+       { VENDOR_UBNT, "XR3",                   0x168c, 0x001b, 0x0777, 0x3003, 10,     0 },
+       { VENDOR_UBNT, "XR4",                   0x168c, 0x001b, 0x0777, 0x3004, 10,     0 },
+       { VENDOR_UBNT, "XR5",                   0x168c, 0x001b, 0x0777, 0x3005, 10,     0 },
+       { VENDOR_UBNT, "XR5",                   0x168c, 0x001b, 0x7777, 0x3005, 10,     0 },
+       { VENDOR_UBNT, "XR7",                   0x168c, 0x001b, 0x0777, 0x3007, 10,     0 },
+       { VENDOR_UBNT, "XR9",                   0x168c, 0x001b, 0x0777, 0x3009, 10, -1520 },
+       { VENDOR_UBNT, "SRC",                   0x168c, 0x0013, 0x168c, 0x1042,  1,     0 },
+       { VENDOR_UBNT, "SR2",                   0x168c, 0x0013, 0x0777, 0x2041, 10,     0 },
+       { VENDOR_UBNT, "SR4",                   0x168c, 0x0013, 0x0777, 0x2004,  6,     0 },
+       { VENDOR_UBNT, "SR4",                   0x168c, 0x0013, 0x7777, 0x2004,  6,     0 },
+       { VENDOR_UBNT, "SR4C",                  0x168c, 0x0013, 0x0777, 0x1004,  6,     0 },
+       { VENDOR_UBNT, "SR4C",                  0x168c, 0x0013, 0x7777, 0x1004,  6,     0 },
+       { VENDOR_UBNT, "SR5",                   0x168c, 0x0013, 0x168c, 0x2042,  7,     0 },
+       { VENDOR_UBNT, "SR9",                   0x168c, 0x0013, 0x7777, 0x2009, 12, -1500 },
+       { VENDOR_UBNT, "SR71A",                 0x168c, 0x0027, 0x168c, 0x2082, 10,     0 },
+       { VENDOR_UBNT, "SR71",                  0x168c, 0x0027, 0x0777, 0x4082, 10,     0 },
+       { VENDOR_ATH,  "AR9220",                0x168c, 0x0029, 0x168c, 0xa094,  0,     0 },
+       { VENDOR_ATH,  "AR9223",                0x168c, 0x0029, 0x168c, 0xa095,  0,     0 },
+#endif
+       { NULL }
+};
+
 
 const char * iwinfo_type(const char *ifname)
 {
index 997cc8a566a997452e157474ba411bd85a5587bf..08eec18bd92abf2d0406ccdfcea50a1d8d3a751a 100644 (file)
@@ -451,7 +451,7 @@ static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
        return 1;
 }
 
-/* Wrapper for mbbsid_support */
+/* Wrapper for mbssid_support */
 static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
 {
        const char *ifname = luaL_checkstring(L, 1);
@@ -467,6 +467,36 @@ static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *
        return 1;
 }
 
+/* Wrapper for hardware_id */
+static int iwinfo_L_hardware_id(lua_State *L, int (*func)(const char *, char *))
+{
+       const char *ifname = luaL_checkstring(L, 1);
+       struct iwinfo_hardware_id ids;
+
+       if (!(*func)(ifname, (char *)&ids))
+       {
+               lua_newtable(L);
+
+               lua_pushnumber(L, ids.vendor_id);
+               lua_setfield(L, -2, "vendor_id");
+
+               lua_pushnumber(L, ids.device_id);
+               lua_setfield(L, -2, "device_id");
+
+               lua_pushnumber(L, ids.subsystem_vendor_id);
+               lua_setfield(L, -2, "subsystem_vendor_id");
+
+               lua_pushnumber(L, ids.subsystem_device_id);
+               lua_setfield(L, -2, "subsystem_device_id");
+       }
+       else
+       {
+               lua_pushnil(L);
+       }
+
+       return 1;
+}
+
 /* Wrapper for country list */
 static char * iwinfo_L_country_lookup(char *buf, int len, int iso3166)
 {
@@ -538,14 +568,16 @@ LUA_WRAP_STRING(wl,mode)
 LUA_WRAP_STRING(wl,ssid)
 LUA_WRAP_STRING(wl,bssid)
 LUA_WRAP_STRING(wl,country)
-LUA_WRAP_LIST(wl,assoclist)
-LUA_WRAP_LIST(wl,txpwrlist)
-LUA_WRAP_LIST(wl,scanlist)
-LUA_WRAP_LIST(wl,freqlist)
-LUA_WRAP_LIST(wl,countrylist)
-LUA_WRAP_LIST(wl,hwmodelist)
-LUA_WRAP_LIST(wl,encryption)
-LUA_WRAP_LIST(wl,mbssid_support)
+LUA_WRAP_STRING(wl,hardware_name)
+LUA_WRAP_STRUCT(wl,assoclist)
+LUA_WRAP_STRUCT(wl,txpwrlist)
+LUA_WRAP_STRUCT(wl,scanlist)
+LUA_WRAP_STRUCT(wl,freqlist)
+LUA_WRAP_STRUCT(wl,countrylist)
+LUA_WRAP_STRUCT(wl,hwmodelist)
+LUA_WRAP_STRUCT(wl,encryption)
+LUA_WRAP_STRUCT(wl,mbssid_support)
+LUA_WRAP_STRUCT(wl,hardware_id)
 #endif
 
 #ifdef USE_MADWIFI
@@ -562,14 +594,16 @@ LUA_WRAP_STRING(madwifi,mode)
 LUA_WRAP_STRING(madwifi,ssid)
 LUA_WRAP_STRING(madwifi,bssid)
 LUA_WRAP_STRING(madwifi,country)
-LUA_WRAP_LIST(madwifi,assoclist)
-LUA_WRAP_LIST(madwifi,txpwrlist)
-LUA_WRAP_LIST(madwifi,scanlist)
-LUA_WRAP_LIST(madwifi,freqlist)
-LUA_WRAP_LIST(madwifi,countrylist)
-LUA_WRAP_LIST(madwifi,hwmodelist)
-LUA_WRAP_LIST(madwifi,encryption)
-LUA_WRAP_LIST(madwifi,mbssid_support)
+LUA_WRAP_STRING(madwifi,hardware_name)
+LUA_WRAP_STRUCT(madwifi,assoclist)
+LUA_WRAP_STRUCT(madwifi,txpwrlist)
+LUA_WRAP_STRUCT(madwifi,scanlist)
+LUA_WRAP_STRUCT(madwifi,freqlist)
+LUA_WRAP_STRUCT(madwifi,countrylist)
+LUA_WRAP_STRUCT(madwifi,hwmodelist)
+LUA_WRAP_STRUCT(madwifi,encryption)
+LUA_WRAP_STRUCT(madwifi,mbssid_support)
+LUA_WRAP_STRUCT(madwifi,hardware_id)
 #endif
 
 #ifdef USE_NL80211
@@ -586,14 +620,16 @@ LUA_WRAP_STRING(nl80211,mode)
 LUA_WRAP_STRING(nl80211,ssid)
 LUA_WRAP_STRING(nl80211,bssid)
 LUA_WRAP_STRING(nl80211,country)
-LUA_WRAP_LIST(nl80211,assoclist)
-LUA_WRAP_LIST(nl80211,txpwrlist)
-LUA_WRAP_LIST(nl80211,scanlist)
-LUA_WRAP_LIST(nl80211,freqlist)
-LUA_WRAP_LIST(nl80211,countrylist)
-LUA_WRAP_LIST(nl80211,hwmodelist)
-LUA_WRAP_LIST(nl80211,encryption)
-LUA_WRAP_LIST(nl80211,mbssid_support)
+LUA_WRAP_STRING(nl80211,hardware_name)
+LUA_WRAP_STRUCT(nl80211,assoclist)
+LUA_WRAP_STRUCT(nl80211,txpwrlist)
+LUA_WRAP_STRUCT(nl80211,scanlist)
+LUA_WRAP_STRUCT(nl80211,freqlist)
+LUA_WRAP_STRUCT(nl80211,countrylist)
+LUA_WRAP_STRUCT(nl80211,hwmodelist)
+LUA_WRAP_STRUCT(nl80211,encryption)
+LUA_WRAP_STRUCT(nl80211,mbssid_support)
+LUA_WRAP_STRUCT(nl80211,hardware_id)
 #endif
 
 /* Wext */
@@ -609,14 +645,16 @@ LUA_WRAP_STRING(wext,mode)
 LUA_WRAP_STRING(wext,ssid)
 LUA_WRAP_STRING(wext,bssid)
 LUA_WRAP_STRING(wext,country)
-LUA_WRAP_LIST(wext,assoclist)
-LUA_WRAP_LIST(wext,txpwrlist)
-LUA_WRAP_LIST(wext,scanlist)
-LUA_WRAP_LIST(wext,freqlist)
-LUA_WRAP_LIST(wext,countrylist)
-LUA_WRAP_LIST(wext,hwmodelist)
-LUA_WRAP_LIST(wext,encryption)
-LUA_WRAP_LIST(wext,mbssid_support)
+LUA_WRAP_STRING(wext,hardware_name)
+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)
 
 #ifdef USE_WL
 /* Broadcom table */
@@ -641,6 +679,8 @@ static const luaL_reg R_wl[] = {
        LUA_REG(wl,hwmodelist),
        LUA_REG(wl,encryption),
        LUA_REG(wl,mbssid_support),
+       LUA_REG(wl,hardware_id),
+       LUA_REG(wl,hardware_name),
        { NULL, NULL }
 };
 #endif
@@ -668,6 +708,8 @@ static const luaL_reg R_madwifi[] = {
        LUA_REG(madwifi,hwmodelist),
        LUA_REG(madwifi,encryption),
        LUA_REG(madwifi,mbssid_support),
+       LUA_REG(madwifi,hardware_id),
+       LUA_REG(madwifi,hardware_name),
        { NULL, NULL }
 };
 #endif
@@ -695,6 +737,8 @@ static const luaL_reg R_nl80211[] = {
        LUA_REG(nl80211,hwmodelist),
        LUA_REG(nl80211,encryption),
        LUA_REG(nl80211,mbssid_support),
+       LUA_REG(nl80211,hardware_id),
+       LUA_REG(nl80211,hardware_name),
        { NULL, NULL }
 };
 #endif
@@ -721,6 +765,8 @@ static const luaL_reg R_wext[] = {
        LUA_REG(wext,hwmodelist),
        LUA_REG(wext,encryption),
        LUA_REG(wext,mbssid_support),
+       LUA_REG(wext,hardware_id),
+       LUA_REG(wext,hardware_name),
        { NULL, NULL }
 };
 
index 54082c737165674c15a6c51a8efb5c7cae45230d..feb98e25a27030fd033a9fa1054f423c9f275567 100644 (file)
@@ -987,3 +987,26 @@ int madwifi_get_mbssid_support(const char *ifname, int *buf)
 
        return -1;
 }
+
+int madwifi_get_hardware_id(const char *ifname, char *buf)
+{
+       return wext_get_hardware_id(ifname, buf);
+}
+
+int madwifi_get_hardware_name(const char *ifname, char *buf)
+{
+       struct iwinfo_hardware_id id;
+       struct iwinfo_hardware_entry *hw;
+
+       if (madwifi_get_hardware_id(ifname, (char *)&id))
+               return -1;
+
+       hw = iwinfo_hardware(&id);
+
+       if (hw)
+               sprintf(buf, "%s %s", hw->vendor_name, hw->device_name);
+       else
+               sprintf(buf, "Generic Atheros");
+
+       return 0;
+}
index b3da8384e77af0ae01bc3ac721da64e106507992..d3726821fceb0797c3b769a5009d5232c3ac1df8 100644 (file)
@@ -1628,3 +1628,26 @@ int nl80211_get_mbssid_support(const char *ifname, int *buf)
 
        return -1;
 }
+
+int nl80211_get_hardware_id(const char *ifname, char *buf)
+{
+       return wext_get_hardware_id(ifname, buf);
+}
+
+int nl80211_get_hardware_name(const char *ifname, char *buf)
+{
+       struct iwinfo_hardware_id id;
+       struct iwinfo_hardware_entry *hw;
+
+       if (nl80211_get_hardware_id(ifname, (char *)&id))
+               return -1;
+
+       hw = iwinfo_hardware(&id);
+
+       if (hw)
+               sprintf(buf, "%s %s", hw->vendor_name, hw->device_name);
+       else
+               sprintf(buf, "Generic MAC80211");
+
+       return 0;
+}
index 081464aafad38a11a021d4caccc0e98d578a6fe4..b49447b072aa277d150ff3bdf61d8de659fe7a8d 100644 (file)
@@ -124,3 +124,29 @@ void iwinfo_close(void)
        if( ioctl_socket > -1 )
                close(ioctl_socket);
 }
+
+struct iwinfo_hardware_entry * iwinfo_hardware(struct iwinfo_hardware_id *id)
+{
+       const struct iwinfo_hardware_entry *e;
+
+       for (e = IWINFO_HARDWARE_ENTRIES; e->vendor_name; e++)
+       {
+               if ((e->vendor_id != 0xffff) && (e->vendor_id != id->vendor_id))
+                       continue;
+
+               if ((e->device_id != 0xffff) && (e->device_id != id->device_id))
+                       continue;
+
+               if ((e->subsystem_vendor_id != 0xffff) &&
+                       (e->subsystem_vendor_id != id->subsystem_vendor_id))
+                       continue;
+
+               if ((e->subsystem_device_id != 0xffff) &&
+                       (e->subsystem_device_id != id->subsystem_device_id))
+                       continue;
+
+               return e;
+       }
+
+       return NULL;
+}
index 283f77e9f8e805b3bf4449021709b28b68e315f6..3923c9e7604c9c3298b361a1045f0841258d58ee 100644 (file)
@@ -462,3 +462,56 @@ int wext_get_mbssid_support(const char *ifname, int *buf)
        /* No multi bssid support atm */
        return -1;
 }
+
+static char * wext_sysfs_ifname_file(const char *ifname, const char *path)
+{
+       FILE *f;
+       static char buf[128];
+       char *rv = NULL;
+
+       snprintf(buf, sizeof(buf), "/sys/class/net/%s/%s", ifname, path);
+
+       if ((f = fopen(buf, "r")) != NULL)
+       {
+               memset(buf, 0, sizeof(buf));
+
+               if (fread(buf, 1, sizeof(buf), f))
+                       rv = buf;
+
+               fclose(f);
+       }
+
+       return rv;
+}
+
+int wext_get_hardware_id(const char *ifname, char *buf)
+{
+       char *data;
+       struct iwinfo_hardware_id *id = (struct iwinfo_hardware_id *)buf;
+
+       memset(id, 0, sizeof(struct iwinfo_hardware_id));
+
+       data = wext_sysfs_ifname_file(ifname, "device/vendor");
+       if (data)
+               id->vendor_id = strtoul(data, NULL, 16);
+
+       data = wext_sysfs_ifname_file(ifname, "device/device");
+       if (data)
+               id->device_id = strtoul(data, NULL, 16);
+
+       data = wext_sysfs_ifname_file(ifname, "device/subsystem_device");
+       if (data)
+               id->subsystem_device_id = strtoul(data, NULL, 16);
+
+       data = wext_sysfs_ifname_file(ifname, "device/subsystem_vendor");
+       if (data)
+               id->subsystem_vendor_id = strtoul(data, NULL, 16);
+
+       return (id->vendor_id > 0 && id->device_id > 0) ? 0 : -1;
+}
+
+int wext_get_hardware_name(const char *ifname, char *buf)
+{
+       sprintf(buf, "Generic WEXT");
+       return 0;
+}
index b3227918d4b1355c11659523325201e3c17a69fb..76984de3369f8ab022d000bfba15437123f9b46d 100644 (file)
@@ -135,6 +135,7 @@ int wl_get_frequency(const char *ifname, int *buf)
 
 int wl_get_txpower(const char *ifname, int *buf)
 {
+       /* WLC_GET_VAR "qtxpower" */
        return wext_get_txpower(ifname, buf);
 }
 
@@ -556,3 +557,31 @@ int wl_get_mbssid_support(const char *ifname, int *buf)
 
        return -1;
 }
+
+int wl_get_hardware_id(const char *ifname, char *buf)
+{
+       wlc_rev_info_t revinfo;
+       struct iwinfo_hardware_id *ids = (struct iwinfo_hardware_id *)buf;
+
+       if (wl_ioctl(ifname, WLC_GET_REVINFO, &revinfo, sizeof(revinfo)))
+               return -1;
+
+       ids->vendor_id = revinfo.vendorid;
+       ids->device_id = revinfo.deviceid;
+       ids->subsystem_vendor_id = revinfo.boardvendor;
+       ids->subsystem_device_id = revinfo.boardid;
+
+       return 0;
+}
+
+int wl_get_hardware_name(const char *ifname, char *buf)
+{
+       struct iwinfo_hardware_id ids;
+
+       if (wl_get_hardware_id(ifname, (char *)&ids))
+               return -1;
+
+       sprintf(buf, "Broadcom BCM%04X", ids.device_id);
+
+       return 0;
+}