*
* Connection Manager
*
- * Copyright (C) 2007-2008 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2009 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <config.h>
#endif
+#include <stdlib.h>
#include <string.h>
#include <dbus/dbus.h>
+#include <glib.h>
+
+#define CONNMAN_API_SUBJECT_TO_CHANGE
#include <connman/log.h>
#include <connman/dbus.h>
struct supplicant_task {
int ifindex;
gchar *ifname;
- struct connman_element *element;
+ struct connman_device *device;
struct supplicant_callback *callback;
gchar *path;
gboolean created;
connman_dbus_dict_append_array(&dict, "ssid",
DBUS_TYPE_BYTE, &network, len);
- if (passphrase && strlen(passphrase) > 0) {
+ if (g_ascii_strcasecmp(security, "wpa") == 0 ||
+ g_ascii_strcasecmp(security, "wpa2") == 0) {
const char *key_mgmt = "WPA-PSK";
connman_dbus_dict_append_variant(&dict, "key_mgmt",
DBUS_TYPE_STRING, &key_mgmt);
- connman_dbus_dict_append_variant(&dict, "psk",
+
+ if (passphrase && strlen(passphrase) > 0)
+ connman_dbus_dict_append_variant(&dict, "psk",
DBUS_TYPE_STRING, &passphrase);
+ } else if (g_ascii_strcasecmp(security, "wep") == 0) {
+ const char *key_mgmt = "NONE", *index = "0";
+ connman_dbus_dict_append_variant(&dict, "key_mgmt",
+ DBUS_TYPE_STRING, &key_mgmt);
+
+ if (passphrase) {
+ int size = strlen(passphrase);
+ if (size == 10 || size == 26) {
+ unsigned char *key = malloc(13);
+ char tmp[3];
+ int i;
+ memset(tmp, 0, sizeof(tmp));
+ if (key == NULL)
+ size = 0;
+ for (i = 0; i < size / 2; i++) {
+ memcpy(tmp, passphrase + (i * 2), 2);
+ key[i] = (unsigned char) strtol(tmp,
+ NULL, 16);
+ }
+ connman_dbus_dict_append_array(&dict,
+ "wep_key0", DBUS_TYPE_BYTE,
+ &key, size / 2);
+ free(key);
+ } else
+ connman_dbus_dict_append_variant(&dict,
+ "wep_key0", DBUS_TYPE_STRING,
+ &passphrase);
+ connman_dbus_dict_append_variant(&dict, "wep_tx_keyidx",
+ DBUS_TYPE_STRING, &index);
+ }
} else {
const char *key_mgmt = "NONE";
connman_dbus_dict_append_variant(&dict, "key_mgmt",
{
dbus_message_iter_get_basic(value, &network->capabilities);
+ if (network->capabilities & IEEE80211_CAP_ESS)
+ network->adhoc = FALSE;
+ else if (network->capabilities & IEEE80211_CAP_IBSS)
+ network->adhoc = TRUE;
+
if (network->capabilities & IEEE80211_CAP_PRIVACY)
network->has_wep = TRUE;
}
}
if (task->callback && task->callback->scan_result)
- task->callback->scan_result(task->element, network);
+ task->callback->scan_result(task->device, network);
g_free(network->identifier);
g_free(network->ssid);
goto done;
}
+ if (task->callback && task->callback->clear_results)
+ task->callback->clear_results(task->device);
+
for (i = 0; i < num_results; i++)
get_network_properties(task, results[i]);
task->state = STATE_DISCONNECTED;
if (task->callback && task->callback->state_change)
- task->callback->state_change(task->element, task->state);
+ task->callback->state_change(task->device, task->state);
switch (task->state) {
case STATE_COMPLETED:
return 0;
}
-int __supplicant_start(struct connman_element *element,
+int __supplicant_start(struct connman_device *device,
struct supplicant_callback *callback)
{
struct supplicant_task *task;
int err;
- DBG("element %p name %s", element, element->name);
+ DBG("device %p", device);
task = g_try_new0(struct supplicant_task, 1);
if (task == NULL)
return -ENOMEM;
- task->ifindex = element->index;
- task->ifname = inet_index2name(element->index);
- task->element = element;
+ task->ifindex = connman_device_get_index(device);
+ task->ifname = inet_index2name(task->ifindex);
+ task->device = device;
task->callback = callback;
if (task->ifname == NULL) {
return 0;
}
-int __supplicant_stop(struct connman_element *element)
+int __supplicant_stop(struct connman_device *device)
{
+ int index = connman_device_get_index(device);
struct supplicant_task *task;
- DBG("element %p name %s", element, element->name);
+ DBG("device %p", device);
- task = find_task_by_index(element->index);
+ task = find_task_by_index(index);
if (task == NULL)
return -ENODEV;
return 0;
}
-int __supplicant_scan(struct connman_element *element)
+int __supplicant_scan(struct connman_device *device)
{
+ int index = connman_device_get_index(device);
struct supplicant_task *task;
int err;
- DBG("element %p name %s", element, element->name);
+ DBG("device %p", device);
- task = find_task_by_index(element->index);
+ task = find_task_by_index(index);
if (task == NULL)
return -ENODEV;
{
struct supplicant_task *task;
- DBG("element %p name %s", element, element->name);
+ DBG("element %p", element);
task = find_task_by_index(element->index);
if (task == NULL)
{
struct supplicant_task *task;
- DBG("element %p name %s", element, element->name);
+ DBG("element %p", element);
task = find_task_by_index(element->index);
if (task == NULL)
return 0;
}
+void __supplicant_activate(DBusConnection *conn)
+{
+ DBusMessage *message;
+
+ DBG("conn %p", conn);
+
+ message = dbus_message_new_method_call(SUPPLICANT_NAME, "/",
+ DBUS_INTERFACE_INTROSPECTABLE, "Introspect");
+ if (message == NULL)
+ return;
+
+ dbus_message_set_no_reply(message, TRUE);
+
+ dbus_connection_send(conn, message, NULL);
+
+ dbus_message_unref(message);
+}
+
int __supplicant_init(DBusConnection *conn)
{
+ DBG("conn %p", conn);
+
connection = conn;
if (dbus_connection_add_filter(connection,
void __supplicant_exit(void)
{
+ DBG("conn %p", connection);
+
dbus_connection_remove_filter(connection, supplicant_filter, NULL);
}