#define IEEE80211_CAP_PRIVACY 0x0010
struct supplicant_task {
- DBusConnection *conn;
int ifindex;
gchar *ifname;
struct connman_element *element;
static GStaticMutex task_mutex = G_STATIC_MUTEX_INIT;
static GSList *task_list = NULL;
+static DBusConnection *connection;
+
static struct supplicant_task *find_task_by_index(int index)
{
GSList *list;
return NULL;
}
+static struct supplicant_task *find_task_by_path(const char *path)
+{
+ GSList *list;
+
+ for (list = task_list; list; list = list->next) {
+ struct supplicant_task *task = list->data;
+
+ if (g_str_equal(task->path, path) == TRUE)
+ return task;
+ }
+
+ return NULL;
+}
+
static int get_interface(struct supplicant_task *task)
{
DBusMessage *message, *reply;
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_message_append_args(message, DBUS_TYPE_STRING, &task->ifname,
DBUS_TYPE_INVALID);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
dbus_error_init(&error);
- reply = dbus_connection_send_with_reply_and_block(task->conn,
+ reply = dbus_connection_send_with_reply_and_block(connection,
message, -1, &error);
if (reply == NULL) {
if (dbus_error_is_set(&error) == TRUE) {
if (message == NULL)
return -ENOMEM;
- if (dbus_connection_send_with_reply(task->conn, message,
+ if (dbus_connection_send_with_reply(connection, message,
&call, TIMEOUT) == FALSE) {
connman_error("Failed to initiate scan");
dbus_message_unref(message);
if (message == NULL)
return -ENOMEM;
- if (dbus_connection_send_with_reply(task->conn, message,
+ if (dbus_connection_send_with_reply(connection, message,
&call, TIMEOUT) == FALSE) {
connman_error("Failed to get network properties");
dbus_message_unref(message);
if (message == NULL)
return -ENOMEM;
- if (dbus_connection_send_with_reply(task->conn, message,
+ if (dbus_connection_send_with_reply(connection, message,
&call, TIMEOUT) == FALSE) {
connman_error("Failed to request scan result");
dbus_message_unref(message);
static DBusHandlerResult supplicant_filter(DBusConnection *conn,
DBusMessage *msg, void *data)
{
- struct supplicant_task *task = data;
- const char *member;
+ struct supplicant_task *task;
+ const char *member, *path;
if (dbus_message_has_interface(msg,
SUPPLICANT_INTF ".Interface") == FALSE)
if (member == NULL)
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ path = dbus_message_get_path(msg);
+ if (path == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ task = find_task_by_path(path);
+ if (task == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
DBG("task %p member %s", task, member);
if (g_str_equal(member, "ScanResultsAvailable") == TRUE)
DBusError error;
gchar *filter;
- if (dbus_connection_add_filter(task->conn,
- supplicant_filter, task, NULL) == FALSE)
- return -EIO;
-
filter = g_strdup_printf("type=signal,interface=%s.Interface,path=%s",
SUPPLICANT_INTF, task->path);
dbus_error_init(&error);
- dbus_bus_add_match(task->conn, filter, &error);
+ dbus_bus_add_match(connection, filter, &error);
g_free(filter);
dbus_error_init(&error);
- dbus_bus_add_match(task->conn, filter, &error);
+ dbus_bus_remove_match(connection, filter, &error);
g_free(filter);
dbus_error_free(&error);
}
- dbus_connection_remove_filter(task->conn, supplicant_filter, task);
-
return 0;
}
return -ENOMEM;
}
- task->conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (task->conn == NULL) {
- g_free(task);
- return -EIO;
- }
-
task->created = FALSE;
task->state = STATE_INACTIVE;
remove_interface(task);
- dbus_connection_unref(task->conn);
-
g_free(task->ifname);
g_free(task->path);
g_free(task);
int __supplicant_connect(struct connman_element *element, const char *ssid)
{
struct supplicant_task *task;
+ const char *passphrase = NULL;
DBG("element %p name %s", element, element->name);
select_network(task);
disable_network(task);
- set_network(task, ssid, NULL);
+ set_network(task, ssid, passphrase);
enable_network(task);
return 0;
}
+
+int __supplicant_init(void)
+{
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (connection == NULL)
+ return -EIO;
+
+ if (dbus_connection_add_filter(connection,
+ supplicant_filter, NULL, NULL) == FALSE) {
+ dbus_connection_unref(connection);
+ return -EIO;
+ }
+
+ return 0;
+}
+
+void __supplicant_exit(void)
+{
+ if (connection == NULL)
+ return;
+
+ dbus_connection_remove_filter(connection, supplicant_filter, NULL);
+
+ dbus_connection_unref(connection);
+ connection = NULL;
+}