dbus: Use BSS table instead of raw scan results in older API

Change the old D-Bus API to use the new BSS table instead of raw
scan results.
This commit is contained in:
Jouni Malinen 2010-01-02 15:13:25 +02:00
parent 8d923a4acf
commit 9734dc17b6
3 changed files with 38 additions and 72 deletions

View file

@ -17,10 +17,10 @@
#include "common.h" #include "common.h"
#include "eloop.h" #include "eloop.h"
#include "drivers/driver.h"
#include "wps/wps.h" #include "wps/wps.h"
#include "../config.h" #include "../config.h"
#include "../wpa_supplicant_i.h" #include "../wpa_supplicant_i.h"
#include "../bss.h"
#include "dbus_old.h" #include "dbus_old.h"
#include "dbus_old_handlers.h" #include "dbus_old_handlers.h"
#include "dbus_common.h" #include "dbus_common.h"
@ -176,45 +176,23 @@ static DBusMessage * wpas_dispatch_network_method(DBusMessage *message,
*/ */
static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message, static DBusMessage * wpas_dispatch_bssid_method(DBusMessage *message,
struct wpa_supplicant *wpa_s, struct wpa_supplicant *wpa_s,
const char *bssid) const char *bssid_txt)
{ {
DBusMessage *reply = NULL; u8 bssid[ETH_ALEN];
const char *method = dbus_message_get_member(message); struct wpa_bss *bss;
struct wpa_scan_res *res = NULL;
size_t i;
/* Ensure we actually have scan data */ if (hexstr2bin(bssid_txt, bssid, ETH_ALEN) < 0)
if (wpa_s->scan_res == NULL && return wpas_dbus_new_invalid_bssid_error(message);
wpa_supplicant_get_scan_results(wpa_s, NULL, 0) < 0) {
reply = wpas_dbus_new_invalid_bssid_error(message);
goto out;
}
/* Find the bssid's scan data */ bss = wpa_bss_get_bssid(wpa_s, bssid);
for (i = 0; i < wpa_s->scan_res->num; i++) { if (bss == NULL)
struct wpa_scan_res *search_res = wpa_s->scan_res->res[i]; return wpas_dbus_new_invalid_bssid_error(message);
char mac_str[18];
memset(mac_str, 0, sizeof(mac_str));
snprintf(mac_str, sizeof(mac_str) - 1, WPAS_DBUS_BSSID_FORMAT,
MAC2STR(search_res->bssid));
if (!strcmp(bssid, mac_str)) {
res = search_res;
break;
}
}
if (!res) {
reply = wpas_dbus_new_invalid_bssid_error(message);
goto out;
}
/* Dispatch the method call against the scanned bssid */ /* Dispatch the method call against the scanned bssid */
if (!strcmp(method, "properties")) if (os_strcmp(dbus_message_get_member(message), "properties") == 0)
reply = wpas_dbus_bssid_properties(message, wpa_s, res); return wpas_dbus_bssid_properties(message, wpa_s, bss);
out: return NULL;
return reply;
} }

View file

@ -25,6 +25,7 @@
#include "../driver_i.h" #include "../driver_i.h"
#include "../notify.h" #include "../notify.h"
#include "../wpas_glue.h" #include "../wpas_glue.h"
#include "../bss.h"
#include "dbus_old.h" #include "dbus_old.h"
#include "dbus_old_handlers.h" #include "dbus_old_handlers.h"
#include "dbus_dict_helpers.h" #include "dbus_dict_helpers.h"
@ -357,15 +358,7 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
DBusMessage *reply = NULL; DBusMessage *reply = NULL;
DBusMessageIter iter; DBusMessageIter iter;
DBusMessageIter sub_iter; DBusMessageIter sub_iter;
size_t i; struct wpa_bss *bss;
/* Ensure we've actually got scan results to return */
if (wpa_s->scan_res == NULL &&
wpa_supplicant_get_scan_results(wpa_s, NULL, 0) < 0) {
return dbus_message_new_error(message, WPAS_ERROR_SCAN_ERROR,
"An error ocurred getting scan "
"results.");
}
/* Create and initialize the return message */ /* Create and initialize the return message */
reply = dbus_message_new_method_return(message); reply = dbus_message_new_method_return(message);
@ -375,26 +368,19 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
&sub_iter); &sub_iter);
/* Loop through scan results and append each result's object path */ /* Loop through scan results and append each result's object path */
for (i = 0; i < wpa_s->scan_res->num; i++) { dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
struct wpa_scan_res *res = wpa_s->scan_res->res[i]; char path_buf[WPAS_DBUS_OBJECT_PATH_MAX];
char *path; char *path = path_buf;
path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (path == NULL) {
wpa_printf(MSG_ERROR, "dbus: Not enough memory to "
"send scan results signal");
break;
}
/* Construct the object path for this network. Note that ':' /* Construct the object path for this network. Note that ':'
* is not a valid character in dbus object paths. * is not a valid character in dbus object paths.
*/ */
os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX, os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
"%s/" WPAS_DBUS_BSSIDS_PART "/" "%s/" WPAS_DBUS_BSSIDS_PART "/"
WPAS_DBUS_BSSID_FORMAT, WPAS_DBUS_BSSID_FORMAT,
wpa_s->dbus_path, MAC2STR(res->bssid)); wpa_s->dbus_path, MAC2STR(bss->bssid));
dbus_message_iter_append_basic(&sub_iter, dbus_message_iter_append_basic(&sub_iter,
DBUS_TYPE_OBJECT_PATH, &path); DBUS_TYPE_OBJECT_PATH, &path);
os_free(path);
} }
dbus_message_iter_close_container(&iter, &sub_iter); dbus_message_iter_close_container(&iter, &sub_iter);
@ -415,9 +401,9 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
*/ */
DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message, DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
struct wpa_supplicant *wpa_s, struct wpa_supplicant *wpa_s,
struct wpa_scan_res *res) struct wpa_bss *bss)
{ {
DBusMessage *reply = NULL; DBusMessage *reply;
DBusMessageIter iter, iter_dict; DBusMessageIter iter, iter_dict;
const u8 *ie; const u8 *ie;
@ -429,11 +415,11 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error; goto error;
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "bssid", if (!wpa_dbus_dict_append_byte_array(&iter_dict, "bssid",
(const char *) res->bssid, (const char *) bss->bssid,
ETH_ALEN)) ETH_ALEN))
goto error; goto error;
ie = wpa_scan_get_ie(res, WLAN_EID_SSID); ie = wpa_bss_get_ie(bss, WLAN_EID_SSID);
if (ie) { if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "ssid", if (!wpa_dbus_dict_append_byte_array(&iter_dict, "ssid",
(const char *) (ie + 2), (const char *) (ie + 2),
@ -441,7 +427,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error; goto error;
} }
ie = wpa_scan_get_vendor_ie(res, WPA_IE_VENDOR_TYPE); ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
if (ie) { if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpaie", if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpaie",
(const char *) ie, (const char *) ie,
@ -449,7 +435,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error; goto error;
} }
ie = wpa_scan_get_ie(res, WLAN_EID_RSN); ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
if (ie) { if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "rsnie", if (!wpa_dbus_dict_append_byte_array(&iter_dict, "rsnie",
(const char *) ie, (const char *) ie,
@ -457,7 +443,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error; goto error;
} }
ie = wpa_scan_get_vendor_ie(res, WPS_IE_VENDOR_TYPE); ie = wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE);
if (ie) { if (ie) {
if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpsie", if (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpsie",
(const char *) ie, (const char *) ie,
@ -465,25 +451,25 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
goto error; goto error;
} }
if (res->freq) { if (bss->freq) {
if (!wpa_dbus_dict_append_int32(&iter_dict, "frequency", if (!wpa_dbus_dict_append_int32(&iter_dict, "frequency",
res->freq)) bss->freq))
goto error; goto error;
} }
if (!wpa_dbus_dict_append_uint16(&iter_dict, "capabilities", if (!wpa_dbus_dict_append_uint16(&iter_dict, "capabilities",
res->caps)) bss->caps))
goto error; goto error;
if (!(res->flags & WPA_SCAN_QUAL_INVALID) && if (!(bss->flags & WPA_BSS_QUAL_INVALID) &&
!wpa_dbus_dict_append_int32(&iter_dict, "quality", res->qual)) !wpa_dbus_dict_append_int32(&iter_dict, "quality", bss->qual))
goto error; goto error;
if (!(res->flags & WPA_SCAN_NOISE_INVALID) && if (!(bss->flags & WPA_BSS_NOISE_INVALID) &&
!wpa_dbus_dict_append_int32(&iter_dict, "noise", res->noise)) !wpa_dbus_dict_append_int32(&iter_dict, "noise", bss->noise))
goto error; goto error;
if (!(res->flags & WPA_SCAN_LEVEL_INVALID) && if (!(bss->flags & WPA_BSS_LEVEL_INVALID) &&
!wpa_dbus_dict_append_int32(&iter_dict, "level", res->level)) !wpa_dbus_dict_append_int32(&iter_dict, "level", bss->level))
goto error; goto error;
if (!wpa_dbus_dict_append_int32(&iter_dict, "maxrate", if (!wpa_dbus_dict_append_int32(&iter_dict, "maxrate",
wpa_scan_get_max_rate(res) * 500000)) wpa_bss_get_max_rate(bss) * 500000))
goto error; goto error;
if (!wpa_dbus_dict_close_write(&iter, &iter_dict)) if (!wpa_dbus_dict_close_write(&iter, &iter_dict))

View file

@ -15,6 +15,8 @@
#ifndef CTRL_IFACE_DBUS_HANDLERS_H #ifndef CTRL_IFACE_DBUS_HANDLERS_H
#define CTRL_IFACE_DBUS_HANDLERS_H #define CTRL_IFACE_DBUS_HANDLERS_H
struct wpa_bss;
DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message); DBusMessage * wpas_dbus_new_invalid_iface_error(DBusMessage *message);
DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message); DBusMessage * wpas_dbus_new_invalid_network_error(DBusMessage *message);
@ -38,7 +40,7 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message, DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
struct wpa_supplicant *wpa_s, struct wpa_supplicant *wpa_s,
struct wpa_scan_res *res); struct wpa_bss *bss);
DBusMessage * wpas_dbus_iface_capabilities(DBusMessage *message, DBusMessage * wpas_dbus_iface_capabilities(DBusMessage *message,
struct wpa_supplicant *wpa_s); struct wpa_supplicant *wpa_s);