aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/config_file.c
diff options
context:
space:
mode:
authorJouni Malinen <jouni@qca.qualcomm.com>2016-04-20 10:19:08 (GMT)
committerJouni Malinen <j@w1.fi>2016-04-20 10:19:08 (GMT)
commit4ac33989a6d6b933c098d8c87757cf2d00ce3855 (patch)
tree0ffc3f337f35daeb49cc3be6e2229c1b4eeab3bb /hostapd/config_file.c
parenta9112270615dd68d422623ebc26c21a6887a2a11 (diff)
downloadhostap-4ac33989a6d6b933c098d8c87757cf2d00ce3855.zip
hostap-4ac33989a6d6b933c098d8c87757cf2d00ce3855.tar.gz
hostap-4ac33989a6d6b933c098d8c87757cf2d00ce3855.tar.bz2
Use a shared helper function for parsing hostapd.conf IEs
wpabuf_parse_bin() can be used to take care of parsing a hexstring to a wpabuf and a shared helper function can take care of clearing the previous value when empty string is used. Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
Diffstat (limited to 'hostapd/config_file.c')
-rw-r--r--hostapd/config_file.c83
1 files changed, 27 insertions, 56 deletions
diff --git a/hostapd/config_file.c b/hostapd/config_file.c
index 93f25b2..dbeaa3c 100644
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
@@ -1962,6 +1962,31 @@ fail:
#endif /* CONFIG_ACS */
+static int parse_wpabuf_hex(int line, const char *name, struct wpabuf **buf,
+ const char *val)
+{
+ struct wpabuf *elems;
+
+ if (val[0] == '\0') {
+ wpabuf_free(*buf);
+ *buf = NULL;
+ return 0;
+ }
+
+ elems = wpabuf_parse_bin(val);
+ if (!elems) {
+ wpa_printf(MSG_ERROR, "Line %d: Invalid %s '%s'",
+ line, name, val);
+ return -1;
+ }
+
+ wpabuf_free(*buf);
+ *buf = elems;
+
+ return 0;
+}
+
+
static int hostapd_config_fill(struct hostapd_config *conf,
struct hostapd_bss_config *bss,
const char *buf, char *pos, int line)
@@ -3350,65 +3375,11 @@ static int hostapd_config_fill(struct hostapd_config *conf,
bss->own_ie_override = tmp;
#endif /* CONFIG_TESTING_OPTIONS */
} else if (os_strcmp(buf, "vendor_elements") == 0) {
- struct wpabuf *elems;
- size_t len = os_strlen(pos);
- if (len & 0x01) {
- wpa_printf(MSG_ERROR,
- "Line %d: Invalid vendor_elements '%s'",
- line, pos);
- return 1;
- }
- len /= 2;
- if (len == 0) {
- wpabuf_free(bss->vendor_elements);
- bss->vendor_elements = NULL;
- return 0;
- }
-
- elems = wpabuf_alloc(len);
- if (elems == NULL)
+ if (parse_wpabuf_hex(line, buf, &bss->vendor_elements, pos))
return 1;
-
- if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
- wpabuf_free(elems);
- wpa_printf(MSG_ERROR,
- "Line %d: Invalid vendor_elements '%s'",
- line, pos);
- return 1;
- }
-
- wpabuf_free(bss->vendor_elements);
- bss->vendor_elements = elems;
} else if (os_strcmp(buf, "assocresp_elements") == 0) {
- struct wpabuf *elems;
- size_t len = os_strlen(pos);
- if (len & 0x01) {
- wpa_printf(MSG_ERROR,
- "Line %d: Invalid assocresp_elements '%s'",
- line, pos);
- return 1;
- }
- len /= 2;
- if (len == 0) {
- wpabuf_free(bss->assocresp_elements);
- bss->assocresp_elements = NULL;
- return 0;
- }
-
- elems = wpabuf_alloc(len);
- if (elems == NULL)
+ if (parse_wpabuf_hex(line, buf, &bss->assocresp_elements, pos))
return 1;
-
- if (hexstr2bin(pos, wpabuf_put(elems, len), len)) {
- wpabuf_free(elems);
- wpa_printf(MSG_ERROR,
- "Line %d: Invalid assocresp_elements '%s'",
- line, pos);
- return 1;
- }
-
- wpabuf_free(bss->assocresp_elements);
- bss->assocresp_elements = elems;
} else if (os_strcmp(buf, "sae_anti_clogging_threshold") == 0) {
bss->sae_anti_clogging_threshold = atoi(pos);
} else if (os_strcmp(buf, "sae_groups") == 0) {