[PATCH 1/4] gsupplicant: Report AddNetwork and SelectNetwork errors to caller

patrik.flykt at nokia.com patrik.flykt at nokia.com
Mon Jan 24 04:20:55 PST 2011


From: Patrik Flykt <patrik.flykt at nokia.com>

Call interface_connect_data callback when an error is reported for
wpa_supplicant AddNetwork and SelectNetwork method calls. In the case
of WPA-PSK or WEP key being incorrectly formatted, set the callback
result to -ENOKEY.
---
 gsupplicant/supplicant.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 96f4d83..7869f3f 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -2142,13 +2142,40 @@ int g_supplicant_interface_scan(GSupplicantInterface *interface,
 			interface_scan_params, interface_scan_result, data);
 }
 
+static int parse_supplicant_error(DBusMessageIter *iter)
+{
+	int err = -ECANCELED;
+	char *key;
+
+	while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_STRING) {
+		dbus_message_iter_get_basic(iter, &key);
+		if (strcmp(key, "psk") == 0 ||
+			strncmp(key, "wep_key", 7) == 0) {
+			err = -ENOKEY;
+			break;
+		}
+		dbus_message_iter_next(iter);
+	}
+
+	return err;
+}
+
 static void interface_select_network_result(const char *error,
 				DBusMessageIter *iter, void *user_data)
 {
 	struct interface_connect_data *data = user_data;
+	int result = 0;
 
 	SUPPLICANT_DBG("");
 
+	if (error != NULL) {
+		SUPPLICANT_DBG("SelectNetwork error '%s'", error);
+		result = parse_supplicant_error(iter);
+	}
+
+	if (data->callback != NULL)
+		data->callback(result, data->interface, data->user_data);
+
 	g_free(data->ssid);
 	dbus_free(data);
 }
@@ -2169,6 +2196,7 @@ static void interface_add_network_result(const char *error,
 	struct interface_connect_data *data = user_data;
 	GSupplicantInterface *interface = data->interface;
 	const char *path;
+	int err;
 
 	if (error != NULL)
 		goto error;
@@ -2190,6 +2218,11 @@ static void interface_add_network_result(const char *error,
 	return;
 
 error:
+	SUPPLICANT_DBG("AddNetwork error '%s'", error);
+	err = parse_supplicant_error(iter);
+	if (data->callback != NULL)
+		data->callback(err, data->interface, data->user_data);
+
 	g_free(interface->network_path);
 	interface->network_path = NULL;
 	g_free(data->ssid);
-- 
1.7.2.3




More information about the connman mailing list