WPS: Moved Version attribute validation into a shared function
authorJouni Malinen <jouni.malinen@atheros.com>
Fri, 6 Feb 2009 12:15:47 +0000 (14:15 +0200)
committerJouni Malinen <j@w1.fi>
Fri, 6 Feb 2009 12:15:47 +0000 (14:15 +0200)
src/wps/wps_enrollee.c
src/wps/wps_i.h
src/wps/wps_registrar.c

index 6b6bc27..179f7db 100644 (file)
@@ -956,7 +956,7 @@ static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
        if (wps_parse_msg(msg, &attr) < 0)
                return WPS_FAILURE;
 
-       if (attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
                           attr.version ? *attr.version : 0);
                return WPS_FAILURE;
@@ -1029,7 +1029,7 @@ static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
        if (wps_parse_msg(msg, &attr) < 0)
                return WPS_FAILURE;
 
-       if (attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
                           attr.version ? *attr.version : 0);
                return WPS_FAILURE;
@@ -1081,7 +1081,7 @@ static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
        if (wps_parse_msg(msg, &attr) < 0)
                return WPS_FAILURE;
 
-       if (attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
                           attr.version ? *attr.version : 0);
                return WPS_FAILURE;
index b32a68f..b5b1232 100644 (file)
@@ -238,4 +238,10 @@ enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
                                               enum wsc_op_code op_code,
                                               const struct wpabuf *msg);
 
+
+static inline int wps_version_supported(const u8 *version)
+{
+       return version && *version == WPS_VERSION;
+}
+
 #endif /* WPS_I_H */
index 0fcc9ac..de76a00 100644 (file)
@@ -602,8 +602,9 @@ void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
                        "WPS: Probe Request with WPS data received",
                        wps_data);
 
-       if (wps_parse_msg(wps_data, &attr) < 0 ||
-           attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (wps_parse_msg(wps_data, &attr) < 0)
+               return;
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported ProbeReq WPS IE "
                           "version 0x%x", attr.version ? *attr.version : 0);
                return;
@@ -1933,7 +1934,7 @@ static enum wps_process_res wps_process_wsc_msg(struct wps_data *wps,
        if (wps_parse_msg(msg, &attr) < 0)
                return WPS_FAILURE;
 
-       if (attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
                           attr.version ? *attr.version : 0);
                return WPS_FAILURE;
@@ -2009,7 +2010,7 @@ static enum wps_process_res wps_process_wsc_ack(struct wps_data *wps,
        if (wps_parse_msg(msg, &attr) < 0)
                return WPS_FAILURE;
 
-       if (attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
                           attr.version ? *attr.version : 0);
                return WPS_FAILURE;
@@ -2084,7 +2085,7 @@ static enum wps_process_res wps_process_wsc_nack(struct wps_data *wps,
        if (wps_parse_msg(msg, &attr) < 0)
                return WPS_FAILURE;
 
-       if (attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
                           attr.version ? *attr.version : 0);
                return WPS_FAILURE;
@@ -2169,7 +2170,7 @@ static enum wps_process_res wps_process_wsc_done(struct wps_data *wps,
        if (wps_parse_msg(msg, &attr) < 0)
                return WPS_FAILURE;
 
-       if (attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported message version 0x%x",
                           attr.version ? *attr.version : 0);
                return WPS_FAILURE;
@@ -2360,8 +2361,9 @@ int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
        wpa_hexdump_buf(MSG_MSGDUMP, "WPS: SetSelectedRegistrar attributes",
                        msg);
 
-       if (wps_parse_msg(msg, &attr) < 0 ||
-           attr.version == NULL || *attr.version != WPS_VERSION) {
+       if (wps_parse_msg(msg, &attr) < 0)
+               return -1;
+       if (!wps_version_supported(attr.version)) {
                wpa_printf(MSG_DEBUG, "WPS: Unsupported SetSelectedRegistrar "
                           "version 0x%x", attr.version ? *attr.version : 0);
                return -1;