Get rid of unnecessary typedefs for enums.
[mech_eap.git] / wpa_supplicant / wpa_supplicant.c
index 7decd7a..a02fd77 100644 (file)
@@ -143,7 +143,7 @@ static int wpa_supplicant_set_wpa_none_key(struct wpa_supplicant *wpa_s,
 {
        u8 key[32];
        size_t keylen;
-       wpa_alg alg;
+       enum wpa_alg alg;
        u8 seq[6] = { 0 };
 
        /* IBSS/WPA-None uses only one key (Group) for both receiving and
@@ -478,7 +478,7 @@ void wpa_clear_keys(struct wpa_supplicant *wpa_s, const u8 *addr)
  * @state: State (wpa_state; WPA_*)
  * Returns: The state name as a printable text string
  */
-const char * wpa_supplicant_state_txt(int state)
+const char * wpa_supplicant_state_txt(enum wpa_states state)
 {
        switch (state) {
        case WPA_DISCONNECTED:
@@ -513,7 +513,8 @@ const char * wpa_supplicant_state_txt(int state)
  * This function is called whenever the connection state changes, e.g.,
  * association is completed for WPA/WPA2 4-Way Handshake is started.
  */
-void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state)
+void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s,
+                             enum wpa_states state)
 {
        wpa_printf(MSG_DEBUG, "State: %s -> %s",
                   wpa_supplicant_state_txt(wpa_s->wpa_state),
@@ -546,22 +547,38 @@ void wpa_supplicant_set_state(struct wpa_supplicant *wpa_s, wpa_states state)
 }
 
 
-static void wpa_supplicant_terminate(int sig, void *eloop_ctx,
-                                    void *signal_ctx)
+void wpa_supplicant_terminate_proc(struct wpa_global *global)
 {
-       struct wpa_global *global = eloop_ctx;
+       int pending = 0;
+#ifdef CONFIG_WPS
+       struct wpa_supplicant *wpa_s = global->ifaces;
+       while (wpa_s) {
+               if (wpas_wps_terminate_pending(wpa_s) == 1)
+                       pending = 1;
+               wpa_s = wpa_s->next;
+       }
+#endif /* CONFIG_WPS */
+       if (pending)
+               return;
+       eloop_terminate();
+}
+
+
+static void wpa_supplicant_terminate(int sig, void *signal_ctx)
+{
+       struct wpa_global *global = signal_ctx;
        struct wpa_supplicant *wpa_s;
        for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
                wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING "- signal %d "
                        "received", sig);
        }
-       eloop_terminate();
+       wpa_supplicant_terminate_proc(global);
 }
 
 
 static void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s)
 {
-       wpa_states old_state = wpa_s->wpa_state;
+       enum wpa_states old_state = wpa_s->wpa_state;
        wpa_s->pairwise_cipher = 0;
        wpa_s->group_cipher = 0;
        wpa_s->mgmt_group_cipher = 0;
@@ -647,21 +664,20 @@ int wpa_supplicant_reload_configuration(struct wpa_supplicant *wpa_s)
 }
 
 
-static void wpa_supplicant_reconfig(int sig, void *eloop_ctx,
-                                   void *signal_ctx)
+static void wpa_supplicant_reconfig(int sig, void *signal_ctx)
 {
-       struct wpa_global *global = eloop_ctx;
+       struct wpa_global *global = signal_ctx;
        struct wpa_supplicant *wpa_s;
        wpa_printf(MSG_DEBUG, "Signal %d received - reconfiguring", sig);
        for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
                if (wpa_supplicant_reload_configuration(wpa_s) < 0) {
-                       eloop_terminate();
+                       wpa_supplicant_terminate_proc(global);
                }
        }
 }
 
 
-static wpa_cipher cipher_suite2driver(int cipher)
+static enum wpa_cipher cipher_suite2driver(int cipher)
 {
        switch (cipher) {
        case WPA_CIPHER_NONE:
@@ -679,7 +695,7 @@ static wpa_cipher cipher_suite2driver(int cipher)
 }
 
 
-static wpa_key_mgmt key_mgmt2driver(int key_mgmt)
+static enum wpa_key_mgmt key_mgmt2driver(int key_mgmt)
 {
        switch (key_mgmt) {
        case WPA_KEY_MGMT_NONE:
@@ -965,7 +981,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
        size_t wpa_ie_len;
        int use_crypt, ret, i, bssid_changed;
        int algs = AUTH_ALG_OPEN_SYSTEM;
-       wpa_cipher cipher_pairwise, cipher_group;
+       enum wpa_cipher cipher_pairwise, cipher_group;
        struct wpa_driver_associate_params params;
        int wep_keys_set = 0;
        struct wpa_driver_capa capa;
@@ -1244,7 +1260,6 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
                 * per-BSSID authentication.
                 */
                wpa_supplicant_cancel_auth_timeout(wpa_s);
-               wpa_supplicant_set_state(wpa_s, WPA_COMPLETED);
 #endif /* CONFIG_IBSS_RSN */
        } else {
                /* Timeout for IEEE 802.11 authentication and association */
@@ -1774,7 +1789,9 @@ void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
        if (wpa_s->eapol_received == 0 &&
            (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE) ||
             !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) ||
-            wpa_s->wpa_state != WPA_COMPLETED)) {
+            wpa_s->wpa_state != WPA_COMPLETED) &&
+           (wpa_s->current_ssid == NULL ||
+            wpa_s->current_ssid->mode != IEEE80211_MODE_IBSS)) {
                /* Timeout for completing IEEE 802.1X and WPA authentication */
                wpa_supplicant_req_auth_timeout(
                        wpa_s,
@@ -1914,6 +1931,7 @@ static struct wpa_supplicant * wpa_supplicant_alloc(void)
        if (wpa_s == NULL)
                return NULL;
        wpa_s->scan_req = 1;
+       wpa_s->new_connection = 1;
 
        return wpa_s;
 }
@@ -2015,7 +2033,7 @@ next_driver:
        wpa_s->drv_priv = wpa_drv_init(wpa_s, wpa_s->ifname);
        if (wpa_s->drv_priv == NULL) {
                const char *pos;
-               pos = os_strchr(driver, ',');
+               pos = driver ? os_strchr(driver, ',') : NULL;
                if (pos) {
                        wpa_printf(MSG_DEBUG, "Failed to initialize driver "
                                   "interface - try next driver wrapper");
@@ -2285,7 +2303,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
        if (params->wpa_debug_syslog)
                wpa_debug_open_syslog();
 
-       ret = eap_peer_register_methods();
+       ret = eap_register_methods();
        if (ret) {
                wpa_printf(MSG_ERROR, "Failed to register EAP methods");
                if (ret == -2)
@@ -2294,17 +2312,6 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
                return NULL;
        }
 
-#ifdef CONFIG_AP
-       ret = eap_server_register_methods();
-       if (ret) {
-               wpa_printf(MSG_ERROR, "Failed to register EAP server methods");
-               if (ret == -2)
-                       wpa_printf(MSG_ERROR, "Two or more EAP methods used "
-                                  "the same EAP type.");
-               return NULL;
-       }
-#endif /* CONFIG_AP */
-
        global = os_zalloc(sizeof(*global));
        if (global == NULL)
                return NULL;
@@ -2329,7 +2336,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
        wpa_debug_timestamp = global->params.wpa_debug_timestamp =
                params->wpa_debug_timestamp;
 
-       if (eloop_init(global)) {
+       if (eloop_init()) {
                wpa_printf(MSG_ERROR, "Failed to initialize event loop");
                wpa_supplicant_deinit(global);
                return NULL;
@@ -2398,8 +2405,8 @@ int wpa_supplicant_run(struct wpa_global *global)
                                        wpa_s->ctrl_iface);
        }
 
-       eloop_register_signal_terminate(wpa_supplicant_terminate, NULL);
-       eloop_register_signal_reconfig(wpa_supplicant_reconfig, NULL);
+       eloop_register_signal_terminate(wpa_supplicant_terminate, global);
+       eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
 
        eloop_run();