Use a common function for parsing cipher suites
authorJouni Malinen <j@w1.fi>
Sun, 13 Jan 2013 15:06:22 +0000 (17:06 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 13 Jan 2013 15:06:22 +0000 (17:06 +0200)
Signed-hostap: Jouni Malinen <j@w1.fi>

hostapd/config_file.c
src/common/wpa_common.c
src/common/wpa_common.h
wpa_supplicant/config.c

index 7b2c41c..6c04ce4 100644 (file)
@@ -661,49 +661,12 @@ static int hostapd_config_parse_key_mgmt(int line, const char *value)
 
 static int hostapd_config_parse_cipher(int line, const char *value)
 {
-       int val = 0, last;
-       char *start, *end, *buf;
-
-       buf = os_strdup(value);
-       if (buf == NULL)
+       int val = wpa_parse_cipher(value);
+       if (val < 0) {
+               wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
+                          line, value);
                return -1;
-       start = buf;
-
-       while (*start != '\0') {
-               while (*start == ' ' || *start == '\t')
-                       start++;
-               if (*start == '\0')
-                       break;
-               end = start;
-               while (*end != ' ' && *end != '\t' && *end != '\0')
-                       end++;
-               last = *end == '\0';
-               *end = '\0';
-               if (os_strcmp(start, "CCMP") == 0)
-                       val |= WPA_CIPHER_CCMP;
-               else if (os_strcmp(start, "GCMP") == 0)
-                       val |= WPA_CIPHER_GCMP;
-               else if (os_strcmp(start, "TKIP") == 0)
-                       val |= WPA_CIPHER_TKIP;
-               else if (os_strcmp(start, "WEP104") == 0)
-                       val |= WPA_CIPHER_WEP104;
-               else if (os_strcmp(start, "WEP40") == 0)
-                       val |= WPA_CIPHER_WEP40;
-               else if (os_strcmp(start, "NONE") == 0)
-                       val |= WPA_CIPHER_NONE;
-               else {
-                       wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
-                                  line, start);
-                       os_free(buf);
-                       return -1;
-               }
-
-               if (last)
-                       break;
-               start = end + 1;
        }
-       os_free(buf);
-
        if (val == 0) {
                wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
                           line);
index d834c6e..6c99b49 100644 (file)
@@ -1244,3 +1244,50 @@ int wpa_pick_group_cipher(int ciphers)
                return WPA_CIPHER_WEP40;
        return -1;
 }
+
+
+int wpa_parse_cipher(const char *value)
+{
+       int val = 0, last;
+       char *start, *end, *buf;
+
+       buf = os_strdup(value);
+       if (buf == NULL)
+               return -1;
+       start = buf;
+
+       while (*start != '\0') {
+               while (*start == ' ' || *start == '\t')
+                       start++;
+               if (*start == '\0')
+                       break;
+               end = start;
+               while (*end != ' ' && *end != '\t' && *end != '\0')
+                       end++;
+               last = *end == '\0';
+               *end = '\0';
+               if (os_strcmp(start, "CCMP") == 0)
+                       val |= WPA_CIPHER_CCMP;
+               else if (os_strcmp(start, "GCMP") == 0)
+                       val |= WPA_CIPHER_GCMP;
+               else if (os_strcmp(start, "TKIP") == 0)
+                       val |= WPA_CIPHER_TKIP;
+               else if (os_strcmp(start, "WEP104") == 0)
+                       val |= WPA_CIPHER_WEP104;
+               else if (os_strcmp(start, "WEP40") == 0)
+                       val |= WPA_CIPHER_WEP40;
+               else if (os_strcmp(start, "NONE") == 0)
+                       val |= WPA_CIPHER_NONE;
+               else {
+                       os_free(buf);
+                       return -1;
+               }
+
+               if (last)
+                       break;
+               start = end + 1;
+       }
+       os_free(buf);
+
+       return val;
+}
index 99b3a22..c26c2cc 100644 (file)
@@ -392,5 +392,6 @@ int rsn_cipher_put_suites(u8 *pos, int ciphers);
 int wpa_cipher_put_suites(u8 *pos, int ciphers);
 int wpa_pick_pairwise_cipher(int ciphers, int none_allowed);
 int wpa_pick_group_cipher(int ciphers);
+int wpa_parse_cipher(const char *value);
 
 #endif /* WPA_COMMON_H */
index 136deea..c8b8b1d 100644 (file)
@@ -629,49 +629,12 @@ static char * wpa_config_write_key_mgmt(const struct parse_data *data,
 
 static int wpa_config_parse_cipher(int line, const char *value)
 {
-       int val = 0, last;
-       char *start, *end, *buf;
-
-       buf = os_strdup(value);
-       if (buf == NULL)
+       int val = wpa_parse_cipher(value);
+       if (val < 0) {
+               wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
+                          line, value);
                return -1;
-       start = buf;
-
-       while (*start != '\0') {
-               while (*start == ' ' || *start == '\t')
-                       start++;
-               if (*start == '\0')
-                       break;
-               end = start;
-               while (*end != ' ' && *end != '\t' && *end != '\0')
-                       end++;
-               last = *end == '\0';
-               *end = '\0';
-               if (os_strcmp(start, "CCMP") == 0)
-                       val |= WPA_CIPHER_CCMP;
-               else if (os_strcmp(start, "GCMP") == 0)
-                       val |= WPA_CIPHER_GCMP;
-               else if (os_strcmp(start, "TKIP") == 0)
-                       val |= WPA_CIPHER_TKIP;
-               else if (os_strcmp(start, "WEP104") == 0)
-                       val |= WPA_CIPHER_WEP104;
-               else if (os_strcmp(start, "WEP40") == 0)
-                       val |= WPA_CIPHER_WEP40;
-               else if (os_strcmp(start, "NONE") == 0)
-                       val |= WPA_CIPHER_NONE;
-               else {
-                       wpa_printf(MSG_ERROR, "Line %d: invalid cipher '%s'.",
-                                  line, start);
-                       os_free(buf);
-                       return -1;
-               }
-
-               if (last)
-                       break;
-               start = end + 1;
        }
-       os_free(buf);
-
        if (val == 0) {
                wpa_printf(MSG_ERROR, "Line %d: no cipher values configured.",
                           line);