summaryrefslogtreecommitdiff
path: root/gsupplicant
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2010-09-16 12:34:48 +0200
committerSamuel Ortiz <sameo@linux.intel.com>2010-09-20 15:14:17 +0200
commit711ca31591cdda88fb5045c831b03e666f1e6c18 (patch)
treea9825f31361f6467fc0222dc352a6ce70e6875b9 /gsupplicant
parentc818549e6ed14df4ae83ec120fe0731ed2b6ea19 (diff)
downloadconnman-711ca31591cdda88fb5045c831b03e666f1e6c18.tar.gz
connman-711ca31591cdda88fb5045c831b03e666f1e6c18.tar.bz2
connman-711ca31591cdda88fb5045c831b03e666f1e6c18.zip
WEP and WPA-PSK support for GSupplicant
Diffstat (limited to 'gsupplicant')
-rw-r--r--gsupplicant/gsupplicant.h2
-rw-r--r--gsupplicant/supplicant.c68
2 files changed, 69 insertions, 1 deletions
diff --git a/gsupplicant/gsupplicant.h b/gsupplicant/gsupplicant.h
index 481d0a37..8461c494 100644
--- a/gsupplicant/gsupplicant.h
+++ b/gsupplicant/gsupplicant.h
@@ -103,7 +103,7 @@ struct _GSupplicantSSID {
GSupplicantMode mode;
GSupplicantSecurity security;
unsigned int eap_method;
- char *passphrase;
+ const char *passphrase;
char *identity;
char *ca_cert_path;
char *client_cert_path;
diff --git a/gsupplicant/supplicant.c b/gsupplicant/supplicant.c
index 4850b634..c1679b52 100644
--- a/gsupplicant/supplicant.c
+++ b/gsupplicant/supplicant.c
@@ -24,6 +24,7 @@
#endif
#include <errno.h>
+#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <syslog.h>
@@ -1997,6 +1998,71 @@ done:
dbus_free(data);
}
+static void add_network_security_wep(DBusMessageIter *dict,
+ GSupplicantSSID *ssid)
+{
+ const char *auth_alg = "OPEN SHARED";
+ const char *key_index = "0";
+
+ supplicant_dbus_dict_append_basic(dict, "auth_alg",
+ DBUS_TYPE_STRING, &auth_alg);
+
+ if (ssid->passphrase) {
+ int size = strlen(ssid->passphrase);
+ if (size == 10 || size == 26) {
+ unsigned char *key = g_try_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, ssid->passphrase + (i * 2), 2);
+ key[i] = (unsigned char) strtol(tmp, NULL, 16);
+ }
+
+ supplicant_dbus_dict_append_fixed_array(dict,
+ "wep_key0",
+ DBUS_TYPE_BYTE,
+ &key, size / 2);
+ g_free(key);
+ } else if (size == 5 || size == 13) {
+ unsigned char *key = g_try_malloc(13);
+ int i;
+
+ if (key == NULL)
+ size = 0;
+
+ for (i = 0; i < size; i++)
+ key[i] = (unsigned char) ssid->passphrase[i];
+
+ supplicant_dbus_dict_append_fixed_array(dict,
+ "wep_key0",
+ DBUS_TYPE_BYTE,
+ &key, size);
+ g_free(key);
+ } else
+ supplicant_dbus_dict_append_basic(dict,
+ "wep_key0",
+ DBUS_TYPE_STRING,
+ &ssid->passphrase);
+
+ supplicant_dbus_dict_append_basic(dict, "wep_tx_keyidx",
+ DBUS_TYPE_STRING, &key_index);
+ }
+}
+
+static void add_network_security_psk(DBusMessageIter *dict,
+ GSupplicantSSID *ssid)
+{
+ if (ssid->passphrase && strlen(ssid->passphrase) > 0)
+ supplicant_dbus_dict_append_basic(dict, "psk",
+ DBUS_TYPE_STRING,
+ &ssid->passphrase);
+}
+
static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
{
char *key_mgmt;
@@ -2006,9 +2072,11 @@ static void add_network_security(DBusMessageIter *dict, GSupplicantSSID *ssid)
case G_SUPPLICANT_SECURITY_NONE:
case G_SUPPLICANT_SECURITY_WEP:
key_mgmt = "NONE";
+ add_network_security_wep(dict, ssid);
break;
case G_SUPPLICANT_SECURITY_PSK:
key_mgmt = "WPA-PSK";
+ add_network_security_psk(dict, ssid);
break;
case G_SUPPLICANT_SECURITY_IEEE8021X:
key_mgmt = "WPA-EAP";