Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * | 2 * |
| 3 * Connection Manager | 3 * Connection Manager |
| 4 * | 4 * |
| 5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. | 5 * Copyright (C) 2007-2009 Intel Corporation. All rights reserved. |
| 6 * | 6 * |
| 7 * This program is free software; you can redistribute it and/or modify | 7 * This program is free software; you can redistribute it and/or modify |
| 8 * it under the terms of the GNU General Public License version 2 as | 8 * it under the terms of the GNU General Public License version 2 as |
| 9 * published by the Free Software Foundation. | 9 * published by the Free Software Foundation. |
| 10 * | 10 * |
| 11 * This program is distributed in the hope that it will be useful, | 11 * This program is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 * GNU General Public License for more details. | 14 * GNU General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU General Public License | 16 * You should have received a copy of the GNU General Public License |
| 17 * along with this program; if not, write to the Free Software | 17 * along with this program; if not, write to the Free Software |
| 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 * | 19 * |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #ifdef HAVE_CONFIG_H | 22 #ifdef HAVE_CONFIG_H |
| 23 #include <config.h> | 23 #include <config.h> |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #include <net/ethernet.h> | |
| 27 | |
| 26 #include <glib.h> | 28 #include <glib.h> |
| 27 | 29 |
| 28 #include "connman.h" | 30 #include "connman.h" |
| 29 | 31 |
| 32 static inline gboolean ispsk(const char *security) | |
| 33 { | |
| 34 return (g_strcmp0(security, "wpa") == 0 || | |
| 35 g_strcmp0(security, "rsn") == 0 || | |
| 36 g_strcmp0(security, "psk") == 0); | |
| 37 } | |
| 38 | |
| 30 char *connman_wifi_build_group_name(const unsigned char *ssid, | 39 char *connman_wifi_build_group_name(const unsigned char *ssid, |
| 31 unsigned int ssid_len, | 40 unsigned int ssid_len, |
| 32 const char *mode, | 41 const char *mode, |
| 33 const char *security) | 42 const char *security) |
| 34 { | 43 { |
| 35 GString *str; | 44 GString *str; |
| 36 unsigned int i; | 45 unsigned int i; |
| 37 | 46 |
| 38 str = g_string_sized_new((ssid_len * 2) + 24); | 47 str = g_string_sized_new((ssid_len * 2) + 24); |
| 39 if (str == NULL) | 48 if (str == NULL) |
| 40 return NULL; | 49 return NULL; |
| 41 | 50 |
| 42 if (ssid_len > 0 && ssid[0] != '\0') { | 51 if (ssid_len > 0 && ssid[0] != '\0') { |
| 43 for (i = 0; i < ssid_len; i++) | 52 for (i = 0; i < ssid_len; i++) |
| 44 g_string_append_printf(str, "%02x", ssid[i]); | 53 g_string_append_printf(str, "%02x", ssid[i]); |
| 45 } | 54 } |
| 46 | 55 |
| 47 » g_string_append_printf(str, "_%s_%s", mode, security); | 56 » /* NB: use "psk" for all wpa/rsn/psk services */ |
| 57 » g_string_append_printf(str, "_%s_%s", mode, | |
| 58 » ispsk(security) ? "psk" : security); | |
| 48 | 59 |
| 49 return g_string_free(str, FALSE); | 60 return g_string_free(str, FALSE); |
| 50 } | 61 } |
| 62 | |
| 63 static struct { | |
| 64 char *name; | |
| 65 char *value; | |
| 66 } special_ssid[] = { | |
| 67 { "<hidden>", "hidden" }, | |
| 68 { "default", "linksys" }, | |
| 69 { "wireless" }, | |
| 70 { "linksys" }, | |
| 71 { "netgear" }, | |
| 72 { "dlink" }, | |
| 73 { "2wire" }, | |
| 74 { "compaq" }, | |
| 75 { "tsunami" }, | |
| 76 { "comcomcom", "3com" }, | |
| 77 { "3Com", "3com" }, | |
| 78 { "Symbol", "symbol" }, | |
| 79 { "Motorola", "motorola" }, | |
| 80 { "Wireless" , "wireless" }, | |
| 81 { "WLAN", "wlan" }, | |
| 82 { } | |
| 83 }; | |
| 84 | |
| 85 char *connman_wifi_build_group(const char *addr, const char *name, | |
|
Paul Stewart
2011/03/03 19:55:04
Could you comment these specifically so that peopl
| |
| 86 const unsigned char *ssid, unsigned int ssid_len, | |
| 87 const char *mode, const char *security) | |
| 88 { | |
| 89 GString *str; | |
| 90 unsigned int i; | |
| 91 | |
| 92 if (addr == NULL) | |
| 93 return NULL; | |
| 94 | |
| 95 str = g_string_sized_new((ssid_len * 2) + 24); | |
| 96 if (str == NULL) | |
| 97 return NULL; | |
| 98 | |
| 99 if (ssid == NULL) { | |
| 100 g_string_append_printf(str, "hidden_%s", addr); | |
| 101 goto done; | |
| 102 } | |
| 103 | |
| 104 for (i = 0; special_ssid[i].name; i++) { | |
| 105 if (g_strcmp0(special_ssid[i].name, name) == 0) { | |
| 106 if (special_ssid[i].value == NULL) | |
| 107 g_string_append_printf(str, "%s_%.*s", | |
| 108 name, 2*ETH_ALEN, addr); | |
| 109 else | |
| 110 g_string_append_printf(str, "%s_%.*s", | |
| 111 special_ssid[i].value, 2*ETH_ALEN, addr); | |
| 112 goto done; | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 if (ssid_len > 0 && ssid[0] != '\0') { | |
| 117 for (i = 0; i < ssid_len; i++) | |
| 118 g_string_append_printf(str, "%02x", ssid[i]); | |
| 119 } else | |
| 120 g_string_append_printf(str, "hidden_%.*s", 2*ETH_ALEN, addr); | |
| 121 done: | |
| 122 /* NB: use "psk" for all wpa/rsn/psk services */ | |
| 123 g_string_append_printf(str, "_%s_%s", mode, | |
| 124 ispsk(security) ? "psk" : security); | |
| 125 | |
| 126 return g_string_free(str, FALSE); | |
| 127 } | |
| OLD | NEW |