WPS: Share a common function for error strings
authorJouni Malinen <jouni@qca.qualcomm.com>
Wed, 31 Jul 2013 14:30:45 +0000 (17:30 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 23 Aug 2013 13:32:34 +0000 (16:32 +0300)
This makes it easier to maintain the list of WPS_EI_* error values and
matching strings.

Signed-hostap: Jouni Malinen <jouni@qca.qualcomm.com>

src/ap/wps_hostapd.c
src/wps/wps.c
src/wps/wps.h
wpa_supplicant/wps_supplicant.c

index 69b34fe..a3950d3 100644 (file)
@@ -734,12 +734,6 @@ static void hostapd_wps_ap_pin_success(struct hostapd_data *hapd)
 }
 
 
-static const char * wps_event_fail_reason[NUM_WPS_EI_VALUES] = {
-       "No Error", /* WPS_EI_NO_ERROR */
-       "TKIP Only Prohibited", /* WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED */
-       "WEP Prohibited" /* WPS_EI_SECURITY_WEP_PROHIBITED */
-};
-
 static void hostapd_wps_event_fail(struct hostapd_data *hapd,
                                   struct wps_event_fail *fail)
 {
@@ -748,7 +742,7 @@ static void hostapd_wps_event_fail(struct hostapd_data *hapd,
                wpa_msg(hapd->msg_ctx, MSG_INFO,
                        WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)",
                        fail->msg, fail->config_error, fail->error_indication,
-                       wps_event_fail_reason[fail->error_indication]);
+                       wps_ei_str(fail->error_indication));
        } else {
                wpa_msg(hapd->msg_ctx, MSG_INFO,
                        WPS_EVENT_FAIL "msg=%d config_error=%d",
index ff4b20d..96aba4d 100644 (file)
@@ -640,3 +640,18 @@ int wps_attr_text(struct wpabuf *data, char *buf, char *end)
 
        return pos - buf;
 }
+
+
+const char * wps_ei_str(enum wps_error_indication ei)
+{
+       switch (ei) {
+       case WPS_EI_NO_ERROR:
+               return "No Error";
+       case WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED:
+               return "TKIP Only Prohibited";
+       case WPS_EI_SECURITY_WEP_PROHIBITED:
+               return "WEP Prohibited";
+       default:
+               return "Unknown";
+       }
+}
index cb03dbd..a301b51 100644 (file)
@@ -786,6 +786,7 @@ void wps_free_pending_msgs(struct upnp_pending_message *msgs);
 struct wpabuf * wps_get_oob_cred(struct wps_context *wps);
 int wps_oob_use_cred(struct wps_context *wps, struct wps_parse_attr *attr);
 int wps_attr_text(struct wpabuf *data, char *buf, char *end);
+const char * wps_ei_str(enum wps_error_indication ei);
 
 struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname,
                            const char *filter);
index 8e0207c..44b935a 100644 (file)
@@ -567,12 +567,6 @@ static void wpa_supplicant_wps_event_m2d(struct wpa_supplicant *wpa_s,
 }
 
 
-static const char * wps_event_fail_reason[NUM_WPS_EI_VALUES] = {
-       "No Error", /* WPS_EI_NO_ERROR */
-       "TKIP Only Prohibited", /* WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED */
-       "WEP Prohibited" /* WPS_EI_SECURITY_WEP_PROHIBITED */
-};
-
 static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
                                          struct wps_event_fail *fail)
 {
@@ -581,13 +575,13 @@ static void wpa_supplicant_wps_event_fail(struct wpa_supplicant *wpa_s,
                wpa_msg(wpa_s, MSG_INFO,
                        WPS_EVENT_FAIL "msg=%d config_error=%d reason=%d (%s)",
                        fail->msg, fail->config_error, fail->error_indication,
-                       wps_event_fail_reason[fail->error_indication]);
+                       wps_ei_str(fail->error_indication));
                if (wpa_s->parent && wpa_s->parent != wpa_s)
                        wpa_msg(wpa_s->parent, MSG_INFO, WPS_EVENT_FAIL
                                "msg=%d config_error=%d reason=%d (%s)",
                                fail->msg, fail->config_error,
                                fail->error_indication,
-                               wps_event_fail_reason[fail->error_indication]);
+                               wps_ei_str(fail->error_indication));
        } else {
                wpa_msg(wpa_s, MSG_INFO,
                        WPS_EVENT_FAIL "msg=%d config_error=%d",