Browse Source

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.
Jouni Malinen 15 years ago
parent
commit
9734dc17b6

+ 12 - 34
wpa_supplicant/dbus/dbus_old.c

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

+ 24 - 38
wpa_supplicant/dbus/dbus_old_handlers.c

@@ -25,6 +25,7 @@
 #include "../driver_i.h"
 #include "../notify.h"
 #include "../wpas_glue.h"
+#include "../bss.h"
 #include "dbus_old.h"
 #include "dbus_old_handlers.h"
 #include "dbus_dict_helpers.h"
@@ -357,15 +358,7 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
 	DBusMessage *reply = NULL;
 	DBusMessageIter iter;
 	DBusMessageIter sub_iter;
-	size_t i;
-
-	/* 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.");
-	}
+	struct wpa_bss *bss;
 
 	/* Create and initialize the return message */
 	reply = dbus_message_new_method_return(message);
@@ -375,26 +368,19 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
 					 &sub_iter);
 
 	/* Loop through scan results and append each result's object path */
-	for (i = 0; i < wpa_s->scan_res->num; i++) {
-		struct wpa_scan_res *res = wpa_s->scan_res->res[i];
-		char *path;
-
-		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;
-		}
+	dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
+		char path_buf[WPAS_DBUS_OBJECT_PATH_MAX];
+		char *path = path_buf;
+
 		/* Construct the object path for this network.  Note that ':'
 		 * is not a valid character in dbus object paths.
 		 */
 		os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
 			    "%s/" WPAS_DBUS_BSSIDS_PART "/"
 			    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_TYPE_OBJECT_PATH, &path);
-		os_free(path);
 	}
 
 	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,
 					 struct wpa_supplicant *wpa_s,
-					 struct wpa_scan_res *res)
+					 struct wpa_bss *bss)
 {
-	DBusMessage *reply = NULL;
+	DBusMessage *reply;
 	DBusMessageIter iter, iter_dict;
 	const u8 *ie;
 
@@ -429,11 +415,11 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
 		goto error;
 
 	if (!wpa_dbus_dict_append_byte_array(&iter_dict, "bssid",
-					     (const char *) res->bssid,
+					     (const char *) bss->bssid,
 					     ETH_ALEN))
 		goto error;
 
-	ie = wpa_scan_get_ie(res, WLAN_EID_SSID);
+	ie = wpa_bss_get_ie(bss, WLAN_EID_SSID);
 	if (ie) {
 		if (!wpa_dbus_dict_append_byte_array(&iter_dict, "ssid",
 						     (const char *) (ie + 2),
@@ -441,7 +427,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
 		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 (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpaie",
 						     (const char *) ie,
@@ -449,7 +435,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
 			goto error;
 	}
 
-	ie = wpa_scan_get_ie(res, WLAN_EID_RSN);
+	ie = wpa_bss_get_ie(bss, WLAN_EID_RSN);
 	if (ie) {
 		if (!wpa_dbus_dict_append_byte_array(&iter_dict, "rsnie",
 						     (const char *) ie,
@@ -457,7 +443,7 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
 			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 (!wpa_dbus_dict_append_byte_array(&iter_dict, "wpsie",
 						     (const char *) ie,
@@ -465,25 +451,25 @@ DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
 			goto error;
 	}
 
-	if (res->freq) {
+	if (bss->freq) {
 		if (!wpa_dbus_dict_append_int32(&iter_dict, "frequency",
-						res->freq))
+						bss->freq))
 			goto error;
 	}
 	if (!wpa_dbus_dict_append_uint16(&iter_dict, "capabilities",
-					 res->caps))
+					 bss->caps))
 		goto error;
-	if (!(res->flags & WPA_SCAN_QUAL_INVALID) &&
-	    !wpa_dbus_dict_append_int32(&iter_dict, "quality", res->qual))
+	if (!(bss->flags & WPA_BSS_QUAL_INVALID) &&
+	    !wpa_dbus_dict_append_int32(&iter_dict, "quality", bss->qual))
 		goto error;
-	if (!(res->flags & WPA_SCAN_NOISE_INVALID) &&
-	    !wpa_dbus_dict_append_int32(&iter_dict, "noise", res->noise))
+	if (!(bss->flags & WPA_BSS_NOISE_INVALID) &&
+	    !wpa_dbus_dict_append_int32(&iter_dict, "noise", bss->noise))
 		goto error;
-	if (!(res->flags & WPA_SCAN_LEVEL_INVALID) &&
-	    !wpa_dbus_dict_append_int32(&iter_dict, "level", res->level))
+	if (!(bss->flags & WPA_BSS_LEVEL_INVALID) &&
+	    !wpa_dbus_dict_append_int32(&iter_dict, "level", bss->level))
 		goto error;
 	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;
 
 	if (!wpa_dbus_dict_close_write(&iter, &iter_dict))

+ 3 - 1
wpa_supplicant/dbus/dbus_old_handlers.h

@@ -15,6 +15,8 @@
 #ifndef 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_network_error(DBusMessage *message);
 
@@ -38,7 +40,7 @@ DBusMessage * wpas_dbus_iface_scan_results(DBusMessage *message,
 
 DBusMessage * wpas_dbus_bssid_properties(DBusMessage *message,
 					 struct wpa_supplicant *wpa_s,
-					 struct wpa_scan_res *res);
+					 struct wpa_bss *bss);
 
 DBusMessage * wpas_dbus_iface_capabilities(DBusMessage *message,
 					   struct wpa_supplicant *wpa_s);