[PATCH] dbus: Change BSS property MaxRate to Rates
Marcel Holtmann
marcel
Mon Jan 4 01:57:34 PST 2010
From: Witold Sowa <witold.sowa at gmail.com>
Instaead of exposing maximal BSS bit rate, expose sorted array
of all supported rates
---
doc/dbus.doxygen | 4 +-
wpa_supplicant/bss.c | 29 ++++++++++++++++++
wpa_supplicant/bss.h | 3 +-
wpa_supplicant/dbus/dbus_new.c | 4 +-
wpa_supplicant/dbus/dbus_new_handlers.c | 48 ++++++++++++++++++++++++-----
wpa_supplicant/dbus/dbus_new_handlers.h | 2 +-
wpa_supplicant/examples/wpas-dbus-new.py | 4 +-
7 files changed, 77 insertions(+), 17 deletions(-)
diff --git a/doc/dbus.doxygen b/doc/dbus.doxygen
index 6f40b2d..0fe121a 100644
--- a/doc/dbus.doxygen
+++ b/doc/dbus.doxygen
@@ -656,8 +656,8 @@ scan results.
<p>Frequency of the BSS in MHz.</p>
</li>
<li>
- <h3>MaxRate - q - (read)</h3>
- <p>Maximal data rate of the BSS in bits per second.</p>
+ <h3>Rates - au - (read)</h3>
+ <p>Descending ordered array of rates suported by BSS in bits per second.</p>
</li>
<li>
<h3>Signal - n - (read)</h3>
diff --git a/wpa_supplicant/bss.c b/wpa_supplicant/bss.c
index a125ca1..d6a6409 100644
--- a/wpa_supplicant/bss.c
+++ b/wpa_supplicant/bss.c
@@ -434,3 +434,32 @@ int wpa_bss_get_max_rate(const struct wpa_bss *bss)
return rate;
}
+
+
+int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates)
+{
+ const u8 *ie, *ie2;
+ int i, j, len;
+
+ ie = wpa_bss_get_ie(bss, WLAN_EID_SUPP_RATES);
+ ie2 = wpa_bss_get_ie(bss, WLAN_EID_EXT_SUPP_RATES);
+
+ len = (ie ? ie[1] : 0) + (ie2 ? ie2[1] : 0);
+
+ *rates = os_malloc (sizeof(u8) * len);
+ if (!rates) {
+ wpa_printf(MSG_ERROR, "wpa_bss_get_bit_rates: no memory"
+ "for rates array");
+ return 0;
+ }
+
+ for (i = 0; ie && i < ie[1]; i++) {
+ (*rates)[i] = ie[i + 2] & 0x7f;
+ }
+
+ for (j = 0; ie2 && j < ie2[1]; j++) {
+ (*rates)[i+j] = ie2[j + 2] & 0x7f;
+ }
+
+ return len;
+}
diff --git a/wpa_supplicant/bss.h b/wpa_supplicant/bss.h
index d6e0613..2fa4863 100644
--- a/wpa_supplicant/bss.h
+++ b/wpa_supplicant/bss.h
@@ -40,7 +40,7 @@ struct wpa_scan_res;
* @noise: noise level
* @level: signal level
* @tsf: Timestamp of last Beacon/Probe Response frame
- * @last_update: Time of the last update (i.e., Beacon or Probe Response RX)
+ * @last_update: Time of the last update (i.e., Beacon or Probe Response RX)
* @ie_len: length of the following IE field in octets
*
* This structure is used to store information about neighboring BSSes in
@@ -85,5 +85,6 @@ const u8 * wpa_bss_get_vendor_ie(const struct wpa_bss *bss, u32 vendor_type);
struct wpabuf * wpa_bss_get_vendor_ie_multi(const struct wpa_bss *bss,
u32 vendor_type);
int wpa_bss_get_max_rate(const struct wpa_bss *bss);
+int wpa_bss_get_bit_rates(const struct wpa_bss *bss, u8 **rates);
#endif /* BSS_H */
diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index 2b2a24c..e2f0248 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -1137,8 +1137,8 @@ static const struct wpa_dbus_property_desc wpas_dbus_bss_properties[] = {
NULL,
R
},
- { "MaxRate", WPAS_DBUS_NEW_IFACE_BSSID, "q",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_max_rate,
+ { "Rates", WPAS_DBUS_NEW_IFACE_BSSID, "au",
+ (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rates,
NULL,
R
},
diff --git a/wpa_supplicant/dbus/dbus_new_handlers.c b/wpa_supplicant/dbus/dbus_new_handlers.c
index 2d2e7a3..7cc220d 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.c
+++ b/wpa_supplicant/dbus/dbus_new_handlers.c
@@ -2487,29 +2487,59 @@ DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
}
+static int cmp_u8s_desc(const void * a, const void * b)
+{
+ return (*(u8*)b - *(u8*)a);
+}
+
+
/**
- * wpas_dbus_getter_bss_max_rate - Return the maximal rate of a BSS
+ * wpas_dbus_getter_bss_rates - Return available bit rates of a BSS
* @message: Pointer to incoming dbus message
* @bss: a pair of interface describing structure and bss's id
- * Returns: a dbus message containing the maximal data rate of requested bss
+ * Returns: a dbus message containing sorted array of bit rates
*
- * Getter for "MaxRate" property.
+ * Getter for "Rates" property.
*/
-DBusMessage * wpas_dbus_getter_bss_max_rate(DBusMessage *message,
+DBusMessage * wpas_dbus_getter_bss_rates(DBusMessage *message,
struct bss_handler_args *bss)
{
+ DBusMessage *reply;
struct wpa_bss *res = wpa_bss_get_id(bss->wpa_s, bss->id);
- int max_rate;
+ u8 *ie_rates = NULL;
+ uint32_t *real_rates = NULL;
+ int rates_num, i;
if (!res) {
- wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_max_rate[dbus]: "
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rates[dbus]: "
"no bss with id %d found", bss->id);
return NULL;
}
- max_rate = wpa_bss_get_max_rate(res);
- return wpas_dbus_simple_property_getter(message, DBUS_TYPE_UINT16,
- &max_rate);
+ rates_num = wpa_bss_get_bit_rates(res, &ie_rates);
+
+ qsort(ie_rates, rates_num, sizeof(u8), cmp_u8s_desc);
+
+ real_rates = os_malloc(sizeof(uint32_t) * rates_num);
+ if (!real_rates) {
+ os_free(ie_rates);
+ wpa_printf(MSG_ERROR, "wpas_dbus_getter_bss_rates[dbus]: "
+ "no moemory for rates array");
+ return dbus_message_new_error(message, DBUS_ERROR_NO_MEMORY,
+ NULL);
+ }
+
+ for (i = 0; i < rates_num; i++)
+ real_rates[i] = ie_rates[i]*500000;
+
+ reply = wpas_dbus_simple_array_property_getter(message,
+ DBUS_TYPE_UINT32,
+ real_rates, rates_num);
+
+ os_free(ie_rates);
+ os_free(real_rates);
+ return reply;
+
}
diff --git a/wpa_supplicant/dbus/dbus_new_handlers.h b/wpa_supplicant/dbus/dbus_new_handlers.h
index af63a7f..ca31d51 100644
--- a/wpa_supplicant/dbus/dbus_new_handlers.h
+++ b/wpa_supplicant/dbus/dbus_new_handlers.h
@@ -151,7 +151,7 @@ DBusMessage * wpas_dbus_getter_bss_signal(DBusMessage *message,
DBusMessage * wpas_dbus_getter_bss_frequency(DBusMessage *message,
struct bss_handler_args *bss);
-DBusMessage * wpas_dbus_getter_bss_max_rate(DBusMessage *message,
+DBusMessage * wpas_dbus_getter_bss_rates(DBusMessage *message,
struct bss_handler_args *bss);
DBusMessage * wpas_dbus_getter_bss_wpaie(DBusMessage *message,
diff --git a/wpa_supplicant/examples/wpas-dbus-new.py b/wpa_supplicant/examples/wpas-dbus-new.py
index a313197..da79d54 100755
--- a/wpa_supplicant/examples/wpas-dbus-new.py
+++ b/wpa_supplicant/examples/wpas-dbus-new.py
@@ -65,9 +65,9 @@ def showBss(bss):
dbus_interface=dbus.PROPERTIES_IFACE)
signal = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Signal',
dbus_interface=dbus.PROPERTIES_IFACE)
- val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'MaxRate',
+ val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Rates',
dbus_interface=dbus.PROPERTIES_IFACE)
- maxrate = val / 1000000
+ maxrate = val[0] / 1000000
print " %s :: ssid='%s' wpa=%s wpa2=%s signal=%d rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, signal, maxrate, freq)
--
1.6.5.2
More information about the Hostap
mailing list