]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
hostapd: Add alternative format for configuring SSID
authorJouni Malinen <j@w1.fi>
Tue, 7 Aug 2012 13:27:40 +0000 (16:27 +0300)
committerJouni Malinen <j@w1.fi>
Tue, 7 Aug 2012 13:27:40 +0000 (16:27 +0300)
The new ssid2 parameter can be used as an alternative mechanism for
configuring SSID for hostapd. It uses the same formats that
wpa_supplicant uses in the configuration file for strings.

Signed-hostap: Jouni Malinen <j@w1.fi>

hostapd/config_file.c
hostapd/hostapd.conf
src/ap/wps_hostapd.c
src/utils/common.c
src/utils/common.h
wpa_supplicant/config.c

index 1f898dbb259e031b246c9c0b83b9a9c2f00f11b6..03f29ad53f35d20d272e9714a17d96eb034c2708 100644 (file)
@@ -1472,6 +1472,20 @@ static int hostapd_config_fill(struct hostapd_config *conf,
                                          bss->ssid.ssid_len);
                                bss->ssid.ssid_set = 1;
                        }
+               } else if (os_strcmp(buf, "ssid2") == 0) {
+                       size_t slen;
+                       char *str = wpa_config_parse_string(pos, &slen);
+                       if (str == NULL || slen < 1 ||
+                                  slen > HOSTAPD_MAX_SSID_LEN) {
+                               wpa_printf(MSG_ERROR, "Line %d: invalid SSID "
+                                          "'%s'", line, pos);
+                               errors++;
+                       } else {
+                               os_memcpy(bss->ssid.ssid, str, slen);
+                               bss->ssid.ssid_len = slen;
+                               bss->ssid.ssid_set = 1;
+                       }
+                       os_free(str);
                } else if (os_strcmp(buf, "macaddr_acl") == 0) {
                        bss->macaddr_acl = atoi(pos);
                        if (bss->macaddr_acl != ACCEPT_UNLESS_DENIED &&
index 74f64d0e4ccdda4941fe78d35daead7fafefe44e..7e4e5d247f0bb4ca7d056b38520f26bf2a19a384 100644 (file)
@@ -84,6 +84,11 @@ ctrl_interface_group=0
 
 # SSID to be used in IEEE 802.11 management frames
 ssid=test
+# Alternative formats for configuring SSID
+# (double quoted string, hexdump, printf-escaped string)
+#ssid2="test"
+#ssid2=74657374
+#ssid2=P"hello\nthere"
 
 # Country code (ISO/IEC 3166-1). Used to set regulatory domain.
 # Set as needed to indicate country in which device is operating.
index 07ce06c10786eff6910339f452aa1cd63c98659c..a051dfa158ba665a08be55c26b3b78492b3a9cec 100644 (file)
@@ -371,10 +371,17 @@ static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
 
        fprintf(nconf, "wps_state=2\n");
 
-       fprintf(nconf, "ssid=");
-       for (i = 0; i < cred->ssid_len; i++)
-               fputc(cred->ssid[i], nconf);
-       fprintf(nconf, "\n");
+       if (is_hex(cred->ssid, cred->ssid_len)) {
+               fprintf(nconf, "ssid2=");
+               for (i = 0; i < cred->ssid_len; i++)
+                       fprintf(nconf, "%02x", cred->ssid[i]);
+               fprintf(nconf, "\n");
+       } else {
+               fprintf(nconf, "ssid=");
+               for (i = 0; i < cred->ssid_len; i++)
+                       fputc(cred->ssid[i], nconf);
+               fprintf(nconf, "\n");
+       }
 
        if ((cred->auth_type & (WPS_AUTH_WPA2 | WPS_AUTH_WPA2PSK)) &&
            (cred->auth_type & (WPS_AUTH_WPA | WPS_AUTH_WPAPSK)))
@@ -464,6 +471,7 @@ static int hapd_wps_cred_cb(struct hostapd_data *hapd, void *ctx)
                        multi_bss = 1;
                if (!multi_bss &&
                    (str_starts(buf, "ssid=") ||
+                    str_starts(buf, "ssid2=") ||
                     str_starts(buf, "auth_algs=") ||
                     str_starts(buf, "wep_default_key=") ||
                     str_starts(buf, "wep_key") ||
index e0d20d2c3205668e7621f0ff78eff77e21a019e8..bae73faca9a5ec08f3e4ad47cc057aecd14272c0 100644 (file)
@@ -566,3 +566,15 @@ char * wpa_config_parse_string(const char *value, size_t *len)
                return (char *) str;
        }
 }
+
+
+int is_hex(const u8 *data, size_t len)
+{
+       size_t i;
+
+       for (i = 0; i < len; i++) {
+               if (data[i] < 32 || data[i] >= 127)
+                       return 1;
+       }
+       return 0;
+}
index 3833ce264c8fcfd0abbcc52d0b9fe3cfd54709a2..18b76bd43a7d5494a412ee2c0e859fbabec360b6 100644 (file)
@@ -447,6 +447,7 @@ size_t printf_decode(u8 *buf, size_t maxlen, const char *str);
 const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
 
 char * wpa_config_parse_string(const char *value, size_t *len);
+int is_hex(const u8 *data, size_t len);
 
 static inline int is_zero_ether_addr(const u8 *a)
 {
index c3cbca6c0fee412e2c632bab3c59d48ae2538426..e72ac34320cc24685a044d51dbc9d7717899912d 100644 (file)
@@ -113,18 +113,6 @@ set:
 
 
 #ifndef NO_CONFIG_WRITE
-static int is_hex(const u8 *data, size_t len)
-{
-       size_t i;
-
-       for (i = 0; i < len; i++) {
-               if (data[i] < 32 || data[i] >= 127)
-                       return 1;
-       }
-       return 0;
-}
-
-
 static char * wpa_config_write_string_ascii(const u8 *value, size_t len)
 {
        char *buf;