Hi Martin,
On Tue, Jun 30, 2009 at 09:30:10AM +0800, Xu, Martin wrote:
> >-----Original Message-----
> >From: Samuel Ortiz [mailto:[email protected]]
> >Sent: 2009年6月30日 3:22
> >To: [email protected]
> >Cc: [email protected]; Xu, Martin
> >Subject: [PATCH RFC] device: set network name at join time
> >
> >
> >With 802.11 hidden ssids, the network name can only be set if by chance we
> >receive a probe response from wpa_s.
> >When calling the JoinNetwork method, we should set the network name at that
> >time too otherwise hidden ssid will most likely not get a proper network
> >name.
> >
> >This patch applied on top of connmann git
> >22e99f1a44c4400e73ff78f51b81a1e16b68d429 seems to fix bug #3445 for me, but
> >as
> >this is my first poke at connman code, I'm tagging it as RFC.
> >
> >Signed-off-by: Samuel Ortiz <[email protected]>
> >---
> > src/device.c | 15 +++++++++++++--
> > 1 files changed, 13 insertions(+), 2 deletions(-)
> >
> >diff --git a/src/device.c b/src/device.c
> >index 1fa2bc6..d78747e 100644
> >--- a/src/device.c
> >+++ b/src/device.c
> >@@ -595,10 +595,21 @@ static DBusMessage *join_network(DBusConnection *conn,
> > switch (dbus_message_iter_get_arg_type(&value)) {
> > case DBUS_TYPE_STRING:
> > dbus_message_iter_get_basic(&value, &str);
> >- if (g_str_equal(key, "WiFi.SSID") == TRUE)
> >+ if (g_str_equal(key, "WiFi.SSID") == TRUE) {
> >+ char *name;
> >+
> > connman_network_set_blob(network, key,
> > str, strlen(str));
> >- else
> >+ name = g_try_malloc0(strlen(str) + 1);
> >+ if (name == NULL)
> >+ return __connman_error_failed(msg,
> >+ -ENOMEM);
> >+
> >+ strncpy(name, (char *)str, strlen(str));
> >+ connman_network_set_name(network, name);
> We can set name here, but we can also let UI set it, and
> connman_network_set_string() here can handle it.
>
I agree, but we can't rely on all connman UIs to have the same behaviour, so
we should set a default name here as well.
> Besides, I find a potential issue to set name from SSID. SSID can be any
> value even 0 and other non-print char, that is the reason why SSID has a
> parameter length.
> So when get network name from ssid we need to transfer non-print char to
> print char.
>
I agree, but otoh the supplicant currently copies the SSID from the scan
results into the result->name, which eventually gets copied into the
service->name.
So here comes an updated version of this patch, that sets the network name to
the printable chars of the SSID, and also fix the supplicant to do the same:
With 802.11 hidden ssids, the network name can only be set if by chance we
receive a probe response from wpa_s.
When calling the JoinNetwork method, we should set the network name at that
time too otherwise hidden ssid will most likely not get a proper network name.
For consistency, we are also setting the same network name from the
supplicant.
---
plugins/supplicant.c | 10 ++++++++--
src/device.c | 30 ++++++++++++++++++++++++++++--
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/plugins/supplicant.c b/plugins/supplicant.c
index e9612f3..d955f6f 100644
--- a/plugins/supplicant.c
+++ b/plugins/supplicant.c
@@ -929,7 +929,8 @@ static void extract_ssid(DBusMessageIter *value,
{
DBusMessageIter array;
unsigned char *ssid;
- int ssid_len;
+ int ssid_len, i;
+ char *d;
dbus_message_iter_recurse(value, &array);
dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len);
@@ -948,7 +949,12 @@ static void extract_ssid(DBusMessageIter *value,
if (result->name == NULL)
return;
- memcpy(result->name, ssid, ssid_len);
+ d = result->name;
+ for (i = 0; i < ssid_len; i++)
+ if (g_ascii_isprint(ssid[i]))
+ *d++ = ssid[i];
+
+ *d = '\0';
}
static void extract_wpaie(DBusMessageIter *value,
diff --git a/src/device.c b/src/device.c
index a2507b5..fb53e72 100644
--- a/src/device.c
+++ b/src/device.c
@@ -468,6 +468,20 @@ static char *build_group(const unsigned char *ssid,
unsigned int ssid_len,
return g_string_free(str, FALSE);
}
+static char *build_network_name(const char *ssid, char *name,
+ unsigned int ssid_len)
+{
+ unsigned int i;
+ char *d = name;
+
+ for (i = 0; i < ssid_len; i++)
+ if (g_ascii_isprint(ssid[i]))
+ *d++ = ssid[i];
+
+ *d = '\0';
+ return name;
+}
+
static DBusMessage *join_network(DBusConnection *conn,
DBusMessage *msg, void *data)
{
@@ -517,10 +531,22 @@ static DBusMessage *join_network(DBusConnection *conn,
switch (dbus_message_iter_get_arg_type(&value)) {
case DBUS_TYPE_STRING:
dbus_message_iter_get_basic(&value, &str);
- if (g_str_equal(key, "WiFi.SSID") == TRUE)
+ if (g_str_equal(key, "WiFi.SSID") == TRUE) {
+ char *name;
+
connman_network_set_blob(network, key,
str, strlen(str));
- else
+ name = g_try_malloc0(strlen(str) + 1);
+ if (name == NULL)
+ return __connman_error_failed(msg,
+ -ENOMEM);
+
+ name = build_network_name((char *)str, name,
+ strlen(str));
+ connman_network_set_name(network, name);
+ g_free(name);
+
+ } else
connman_network_set_string(network, key, str);
break;
}
--
1.6.3.1
--
Intel Open Source Technology Centre
http://oss.intel.com/
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman