Disable AP PIN on all interfaces controlled by the same process
[libeap.git] / wpa_supplicant / ibss_rsn.c
index 79878b5..0e33253 100644 (file)
 
 #include "common.h"
 #include "l2_packet/l2_packet.h"
-#include "wpa_supplicant_i.h"
 #include "rsn_supp/wpa.h"
 #include "rsn_supp/wpa_ie.h"
-#include "../hostapd/wpa.h"
+#include "ap/wpa_auth.h"
+#include "wpa_supplicant_i.h"
+#include "driver_i.h"
 #include "ibss_rsn.h"
 
 
@@ -31,7 +32,7 @@ static void ibss_rsn_free(struct ibss_rsn_peer *peer)
 }
 
 
-static void supp_set_state(void *ctx, wpa_states state)
+static void supp_set_state(void *ctx, enum wpa_states state)
 {
        struct ibss_rsn_peer *peer = ctx;
        peer->supp_state = state;
@@ -99,29 +100,31 @@ static int supp_get_beacon_ie(void *ctx)
 }
 
 
-static int supp_set_key(void *ctx, wpa_alg alg,
+static int supp_set_key(void *ctx, enum wpa_alg alg,
                        const u8 *addr, int key_idx, int set_tx,
                        const u8 *seq, size_t seq_len,
                        const u8 *key, size_t key_len)
 {
        struct ibss_rsn_peer *peer = ctx;
 
+       wpa_printf(MSG_DEBUG, "SUPP: %s(alg=%d addr=" MACSTR " key_idx=%d "
+                  "set_tx=%d)",
+                  __func__, alg, MAC2STR(addr), key_idx, set_tx);
+       wpa_hexdump(MSG_DEBUG, "SUPP: set_key - seq", seq, seq_len);
+       wpa_hexdump_key(MSG_DEBUG, "SUPP: set_key - key", key, key_len);
+
        if (key_idx == 0) {
                /*
                 * In IBSS RSN, the pairwise key from the 4-way handshake
                 * initiated by the peer with highest MAC address is used.
                 */
                if (os_memcmp(peer->ibss_rsn->wpa_s->own_addr, peer->addr,
-                             ETH_ALEN) > 0)
+                             ETH_ALEN) > 0) {
+                       wpa_printf(MSG_DEBUG, "SUPP: Do not use this PTK");
                        return 0;
+               }
        }
 
-       wpa_printf(MSG_DEBUG, "SUPP: %s(alg=%d addr=" MACSTR " key_idx=%d "
-                  "set_tx=%d)",
-                  __func__, alg, MAC2STR(addr), key_idx, set_tx);
-       wpa_hexdump(MSG_DEBUG, "SUPP: set_key - seq", seq, seq_len);
-       wpa_hexdump_key(MSG_DEBUG, "SUPP: set_key - key", key, key_len);
-
        return wpa_drv_set_key(peer->ibss_rsn->wpa_s, alg, addr, key_idx,
                               set_tx, seq, seq_len, key, key_len);
 }
@@ -235,35 +238,34 @@ static int auth_send_eapol(void *ctx, const u8 *addr, const u8 *data,
 }
 
 
-static int auth_set_key(void *ctx, int vlan_id, const char *_alg,
-                       const u8 *addr, int idx, u8 *key,
-                       size_t key_len)
+static int auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
+                       const u8 *addr, int idx, u8 *key, size_t key_len)
 {
        struct ibss_rsn *ibss_rsn = ctx;
        u8 seq[6];
-       wpa_alg alg;
 
        os_memset(seq, 0, sizeof(seq));
-       if (os_strcmp(_alg, "none") == 0)
-               alg = WPA_ALG_NONE;
-       else if (os_strcmp(_alg, "WEP") == 0)
-               alg = WPA_ALG_WEP;
-       else if (os_strcmp(_alg, "TKIP") == 0)
-               alg = WPA_ALG_TKIP;
-       else if (os_strcmp(_alg, "CCMP") == 0)
-               alg = WPA_ALG_CCMP;
-       else if (os_strcmp(_alg, "IGTK") == 0)
-               alg = WPA_ALG_IGTK;
-       else
-               return -1;
+
+       if (addr) {
+               wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d addr=" MACSTR
+                          " key_idx=%d)",
+                          __func__, alg, MAC2STR(addr), idx);
+       } else {
+               wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d key_idx=%d)",
+                          __func__, alg, idx);
+       }
+       wpa_hexdump_key(MSG_DEBUG, "AUTH: set_key - key", key, key_len);
 
        if (idx == 0) {
                /*
                 * In IBSS RSN, the pairwise key from the 4-way handshake
                 * initiated by the peer with highest MAC address is used.
                 */
-               if (os_memcmp(ibss_rsn->wpa_s->own_addr, addr, ETH_ALEN) < 0)
+               if (addr == NULL ||
+                   os_memcmp(ibss_rsn->wpa_s->own_addr, addr, ETH_ALEN) < 0) {
+                       wpa_printf(MSG_DEBUG, "AUTH: Do not use this PTK");
                        return 0;
+               }
        }
 
        return wpa_drv_set_key(ibss_rsn->wpa_s, alg, addr, idx,
@@ -325,9 +327,11 @@ static int ibss_rsn_auth_init(struct ibss_rsn *ibss_rsn,
                return -1;
        }
 
-       wpa_auth_sm_event(peer->auth, WPA_ASSOC);
+       if (wpa_auth_sm_event(peer->auth, WPA_ASSOC))
+               return -1;
 
-       wpa_auth_sta_associated(ibss_rsn->auth_group, peer->auth);
+       if (wpa_auth_sta_associated(ibss_rsn->auth_group, peer->auth))
+               return -1;
 
        return 0;
 }