struct _GSupplicantInterface {
char *path;
+ char *network_path;
unsigned int keymgmt_capa;
unsigned int authalg_capa;
unsigned int proto_capa;
case G_SUPPLICANT_MODE_UNKNOWN:
break;
case G_SUPPLICANT_MODE_INFRA:
- return "infra";
+ return "managed";
case G_SUPPLICANT_MODE_IBSS:
return "adhoc";
}
interface->data = data;
}
-const void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
+void *g_supplicant_interface_get_data(GSupplicantInterface *interface)
{
if (interface == NULL)
return NULL;
g_string_append_printf(str, "%02x", ssid[i]);
if (g_strcmp0(mode, "0") == 0)
- g_string_append_printf(str, "_infra");
+ g_string_append_printf(str, "_managed");
else if (g_strcmp0(mode, "1") == 0)
g_string_append_printf(str, "_adhoc");
}
supplicant_dbus_property_get_all(path,
- SUPPLICANT_INTERFACE ".Interface.Network",
+ SUPPLICANT_INTERFACE ".Network",
network_property, network);
}
}
supplicant_dbus_property_get_all(path,
- SUPPLICANT_INTERFACE ".Interface.BSS",
+ SUPPLICANT_INTERFACE ".BSS",
bss_property, bss);
}
key, dbus_message_iter_get_arg_type(iter));
}
+static void scan_network_update(DBusMessageIter *iter, void *user_data)
+{
+ GSupplicantInterface *interface = user_data;
+ GSupplicantNetwork *network;
+ char *path;
+
+ if (iter == NULL)
+ return;
+
+ dbus_message_iter_get_basic(iter, &path);
+
+ if (path == NULL)
+ return;
+
+ if (g_strcmp0(path, "/") == 0)
+ return;
+
+ /* Update the network details based on scan BSS data */
+ network = g_hash_table_lookup(interface->bss_mapping, path);
+ if (network != NULL)
+ callback_network_added(network);
+}
+
+static void scan_bss_data(const char *key, DBusMessageIter *iter,
+ void *user_data)
+{
+ GSupplicantInterface *interface = user_data;
+
+ if (iter)
+ supplicant_dbus_array_foreach(iter, scan_network_update,
+ interface);
+
+ if (interface->scan_callback != NULL)
+ interface->scan_callback(0, interface, interface->scan_data);
+
+ interface->scan_callback = NULL;
+ interface->scan_data = NULL;
+}
+
static GSupplicantInterface *interface_alloc(const char *path)
{
GSupplicantInterface *interface;
dbus_message_iter_get_basic(iter, &success);
- if (interface->scan_callback != NULL) {
- int result = 0;
+ /*
+ * If scan is unsuccessful return -EIO else get the scanned BSSs
+ * and update the network details accordingly
+ */
+ if (success == FALSE) {
+ if (interface->scan_callback != NULL)
+ interface->scan_callback(-EIO, interface,
+ interface->scan_data);
- if (success == FALSE)
- result = -EIO;
+ interface->scan_callback = NULL;
+ interface->scan_data = NULL;
- interface->scan_callback(result, interface,
- interface->scan_data);
+ return;
}
- interface->scan_callback = NULL;
- interface->scan_data = NULL;
+ supplicant_dbus_property_get(path, SUPPLICANT_INTERFACE ".Interface",
+ "BSSs", scan_bss_data, interface);
}
static void signal_bss_added(const char *path, DBusMessageIter *iter)
{ SUPPLICANT_INTERFACE ".Interface", "NetworkAdded", signal_network_added },
{ SUPPLICANT_INTERFACE ".Interface", "NetworkRemoved", signal_network_removed },
- { SUPPLICANT_INTERFACE ".Interface.BSS", "PropertiesChanged", signal_bss_changed },
+ { SUPPLICANT_INTERFACE ".BSS", "PropertiesChanged", signal_bss_changed },
{ }
};
if (interface->scanning == TRUE)
return -EALREADY;
+ switch (interface->state) {
+ case G_SUPPLICANT_STATE_AUTHENTICATING:
+ case G_SUPPLICANT_STATE_ASSOCIATING:
+ case G_SUPPLICANT_STATE_ASSOCIATED:
+ case G_SUPPLICANT_STATE_4WAY_HANDSHAKE:
+ case G_SUPPLICANT_STATE_GROUP_HANDSHAKE:
+ return -EBUSY;
+ case G_SUPPLICANT_STATE_UNKNOWN:
+ case G_SUPPLICANT_STATE_DISCONNECTED:
+ case G_SUPPLICANT_STATE_INACTIVE:
+ case G_SUPPLICANT_STATE_SCANNING:
+ case G_SUPPLICANT_STATE_COMPLETED:
+ break;
+ }
+
data = dbus_malloc0(sizeof(*data));
if (data == NULL)
return -ENOMEM;
static void interface_select_network_result(const char *error,
DBusMessageIter *iter, void *user_data)
{
+ struct interface_connect_data *data = user_data;
+
SUPPLICANT_DBG("");
+
+ dbus_free(data);
}
static void interface_select_network_params(DBusMessageIter *iter,
void *user_data)
{
- char *path = user_data;
+ struct interface_connect_data *data = user_data;
+ GSupplicantInterface *interface = data->interface;
- dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH,
+ &interface->network_path);
}
static void interface_add_network_result(const char *error,
DBusMessageIter *iter, void *user_data)
{
struct interface_connect_data *data = user_data;
- char *path = NULL;
+ GSupplicantInterface *interface = data->interface;
+ const char *path;
if (error != NULL)
- goto done;
+ goto error;
dbus_message_iter_get_basic(iter, &path);
if (path == NULL)
- goto done;
+ goto error;
SUPPLICANT_DBG("PATH: %s", path);
+ g_free(interface->network_path);
+ interface->network_path = g_strdup(path);
+
supplicant_dbus_method_call(data->interface->path,
SUPPLICANT_INTERFACE ".Interface", "SelectNetwork",
interface_select_network_params,
- interface_select_network_result, path);
+ interface_select_network_result, data);
-done:
- dbus_free(data);
+ return;
+
+error:
+ g_free(interface->network_path);
+ interface->network_path = NULL;
+ g_free(data);
}
static void add_network_security_wep(DBusMessageIter *dict,
static void add_network_security_eap(DBusMessageIter *dict,
GSupplicantSSID *ssid)
{
+ char *eap_value;
+
if (ssid->eap == NULL || ssid->identity == NULL)
return;
} else
return;
+ eap_value = g_ascii_strup(ssid->eap, -1);
+
supplicant_dbus_dict_append_basic(dict, "eap",
DBUS_TYPE_STRING,
- &ssid->eap);
+ &eap_value);
supplicant_dbus_dict_append_basic(dict, "identity",
DBUS_TYPE_STRING,
&ssid->identity);
+
+ g_free(eap_value);
}
static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
return -EINPROGRESS;
}
-static void interface_disconnect_result(const char *error,
+static void network_remove_result(const char *error,
DBusMessageIter *iter, void *user_data)
{
struct interface_data *data = user_data;
dbus_free(data);
}
+static void network_remove_params(DBusMessageIter *iter, void *user_data)
+{
+ struct interface_data *data = user_data;
+ const char *path = data->interface->network_path;
+
+ SUPPLICANT_DBG("path %s", path);
+
+ dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
+}
+
+static int network_remove(struct interface_data *data)
+{
+ GSupplicantInterface *interface = data->interface;
+
+ SUPPLICANT_DBG("");
+
+ return supplicant_dbus_method_call(interface->path,
+ SUPPLICANT_INTERFACE ".Interface", "RemoveNetwork",
+ network_remove_params, network_remove_result, data);
+}
+
+static void interface_disconnect_result(const char *error,
+ DBusMessageIter *iter, void *user_data)
+{
+ struct interface_data *data = user_data;
+
+ SUPPLICANT_DBG("");
+
+ if (error != NULL && data->callback != NULL) {
+ data->callback(-EIO, data->interface, data->user_data);
+ return;
+ }
+
+ network_remove(data);
+}
+
int g_supplicant_interface_disconnect(GSupplicantInterface *interface,
GSupplicantInterfaceCallback callback,
void *user_data)
static const char *g_supplicant_rule3 = "type=signal,"
"interface=" SUPPLICANT_INTERFACE ".Interface.WPS";
static const char *g_supplicant_rule4 = "type=signal,"
- "interface=" SUPPLICANT_INTERFACE ".Interface.BSS";
+ "interface=" SUPPLICANT_INTERFACE ".BSS";
static const char *g_supplicant_rule5 = "type=signal,"
- "interface=" SUPPLICANT_INTERFACE ".Interface.Network";
-static const char *g_supplicant_rule6 = "type=signal,"
- "interface=" SUPPLICANT_INTERFACE ".Interface.Blob";
+ "interface=" SUPPLICANT_INTERFACE ".Network";
+
+static void invoke_introspect_method(void)
+{
+ DBusMessage *message;
+
+ message = dbus_message_new_method_call(SUPPLICANT_SERVICE,
+ SUPPLICANT_PATH,
+ DBUS_INTERFACE_INTROSPECTABLE,
+ "Introspect");
+
+ if (message == NULL)
+ return;
+
+ dbus_message_set_no_reply(message, TRUE);
+ dbus_connection_send(connection, message, NULL);
+ dbus_message_unref(message);
+}
int g_supplicant_register(const GSupplicantCallbacks *callbacks)
{
dbus_bus_add_match(connection, g_supplicant_rule3, NULL);
dbus_bus_add_match(connection, g_supplicant_rule4, NULL);
dbus_bus_add_match(connection, g_supplicant_rule5, NULL);
- dbus_bus_add_match(connection, g_supplicant_rule6, NULL);
dbus_connection_flush(connection);
if (dbus_bus_name_has_owner(connection,
supplicant_dbus_property_get_all(SUPPLICANT_PATH,
SUPPLICANT_INTERFACE,
service_property, NULL);
- }
+ } else
+ invoke_introspect_method();
return 0;
}
SUPPLICANT_DBG("");
if (connection != NULL) {
- dbus_bus_remove_match(connection, g_supplicant_rule6, NULL);
dbus_bus_remove_match(connection, g_supplicant_rule5, NULL);
dbus_bus_remove_match(connection, g_supplicant_rule4, NULL);
dbus_bus_remove_match(connection, g_supplicant_rule3, NULL);