aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorDavid Spinadel <david.spinadel@intel.com>2016-04-06 16:42:04 (GMT)
committerJouni Malinen <j@w1.fi>2016-04-16 18:05:37 (GMT)
commit624b8a061f502d09ba932984482195bd5a839db5 (patch)
tree2e78e0d96a7205c41fbde8b04469e3efc522d0cd /src/utils
parente4fbc8d4239a806846a14ceb683f2db371c96f24 (diff)
downloadhostap-624b8a061f502d09ba932984482195bd5a839db5.zip
hostap-624b8a061f502d09ba932984482195bd5a839db5.tar.gz
hostap-624b8a061f502d09ba932984482195bd5a839db5.tar.bz2
utils: Add ssid_parse() function
Add a function that parses SSID in text or hex format. In case of the text format, the SSID is enclosed in double quotes. In case of the hex format, the SSID must include only hex digits and not be enclosed in double quotes. The input string may include other arguments after the SSID. Signed-off-by: David Spinadel <david.spinadel@intel.com>
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/common.c48
-rw-r--r--src/utils/common.h8
2 files changed, 56 insertions, 0 deletions
diff --git a/src/utils/common.c b/src/utils/common.c
index 9c7d0d4..450e2c6 100644
--- a/src/utils/common.c
+++ b/src/utils/common.c
@@ -1123,3 +1123,51 @@ int is_ctrl_char(char c)
{
return c > 0 && c < 32;
}
+
+
+/**
+ * ssid_parse - Parse a string that contains SSID in hex or text format
+ * @buf: Input NULL terminated string that contains the SSID
+ * @ssid: Output SSID
+ * Returns: 0 on success, -1 otherwise
+ *
+ * The SSID has to be enclosed in double quotes for the text format or space
+ * or NULL terminated string of hex digits for the hex format. buf can include
+ * additional arguments after the SSID.
+ */
+int ssid_parse(const char *buf, struct wpa_ssid_value *ssid)
+{
+ char *tmp, *res, *end;
+ size_t len;
+
+ ssid->ssid_len = 0;
+
+ tmp = os_strdup(buf);
+ if (!tmp)
+ return -1;
+
+ if (*tmp != '"') {
+ end = os_strchr(tmp, ' ');
+ if (end)
+ *end = '\0';
+ } else {
+ end = os_strchr(tmp + 1, '"');
+ if (!end) {
+ os_free(tmp);
+ return -1;
+ }
+
+ end[1] = '\0';
+ }
+
+ res = wpa_config_parse_string(tmp, &len);
+ if (res && len <= SSID_MAX_LEN) {
+ ssid->ssid_len = len;
+ os_memcpy(ssid->ssid, res, len);
+ }
+
+ os_free(tmp);
+ os_free(res);
+
+ return ssid->ssid_len ? 0 : -1;
+}
diff --git a/src/utils/common.h b/src/utils/common.h
index 6f0de69..701dbb2 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -448,6 +448,13 @@ typedef u64 __bitwise le64;
#endif /* __GNUC__ */
#endif /* __must_check */
+#define SSID_MAX_LEN 32
+
+struct wpa_ssid_value {
+ u8 ssid[SSID_MAX_LEN];
+ size_t ssid_len;
+};
+
int hwaddr_aton(const char *txt, u8 *addr);
int hwaddr_masked_aton(const char *txt, u8 *addr, u8 *mask, u8 maskable);
int hwaddr_compact_aton(const char *txt, u8 *addr);
@@ -464,6 +471,7 @@ int wpa_snprintf_hex_uppercase(char *buf, size_t buf_size, const u8 *data,
size_t len);
int hwaddr_mask_txt(char *buf, size_t len, const u8 *addr, const u8 *mask);
+int ssid_parse(const char *buf, struct wpa_ssid_value *ssid);
#ifdef CONFIG_NATIVE_WINDOWS
void wpa_unicode2ascii_inplace(TCHAR *str);