Added a separate ctx pointer for wpa_msg() calls in WPA supp
authorJouni Malinen <j@w1.fi>
Sat, 17 Jan 2009 15:54:40 +0000 (17:54 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 17 Jan 2009 15:54:40 +0000 (17:54 +0200)
This is needed to allow IBSS RSN to use per-peer context while
maintaining support for wpa_msg() calls to get *wpa_s as the pointer.

src/rsn_supp/peerkey.c
src/rsn_supp/preauth.c
src/rsn_supp/wpa.c
src/rsn_supp/wpa.h
wpa_supplicant/ibss_rsn.c
wpa_supplicant/preauth_test.c
wpa_supplicant/tests/test_wpa.c
wpa_supplicant/wpas_glue.c

index 45c256a..36392ba 100644 (file)
@@ -255,7 +255,7 @@ static int wpa_supplicant_process_smk_m2(
 #endif /* CONFIG_IEEE80211W */
 
        if (os_get_random(peerkey->pnonce, WPA_NONCE_LEN)) {
-               wpa_msg(sm->ctx->ctx, MSG_WARNING,
+               wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
                        "WPA: Failed to get random data for PNonce");
                wpa_supplicant_peerkey_free(sm, peerkey);
                return -1;
@@ -371,7 +371,7 @@ static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
                    peerkey->smkid, PMKID_LEN);
 
        if (os_get_random(peerkey->inonce, WPA_NONCE_LEN)) {
-               wpa_msg(sm->ctx->ctx, MSG_WARNING,
+               wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
                        "RSN: Failed to get random data for INonce (STK)");
                os_free(mbuf);
                return;
@@ -636,7 +636,7 @@ static int wpa_supplicant_process_smk_error(
                os_memcpy(peer, kde.mac_addr, ETH_ALEN);
        os_memcpy(&error, kde.error, sizeof(error));
        error_type = be_to_host16(error.error_type);
-       wpa_msg(sm->ctx->ctx, MSG_INFO,
+       wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
                "RSN: SMK Error KDE received: MUI %d error_type %d peer "
                MACSTR,
                be_to_host16(error.mui), error_type,
@@ -696,7 +696,7 @@ static void wpa_supplicant_process_stk_1_of_4(struct wpa_sm *sm,
        }
 
        if (os_get_random(peerkey->pnonce, WPA_NONCE_LEN)) {
-               wpa_msg(sm->ctx->ctx, MSG_WARNING,
+               wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
                        "RSN: Failed to get random data for PNonce");
                return;
        }
@@ -1096,7 +1096,7 @@ int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
        inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN);
 
        if (os_get_random(peerkey->inonce, WPA_NONCE_LEN)) {
-               wpa_msg(sm->ctx->ctx, MSG_WARNING,
+               wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
                        "WPA: Failed to get random data for INonce");
                os_free(rbuf);
                wpa_supplicant_peerkey_free(sm, peerkey);
index b00c004..07d5b81 100644 (file)
@@ -107,15 +107,15 @@ static void rsn_preauth_eapol_cb(struct eapol_sm *eapol, int success,
                                        sm->network_ctx,
                                        WPA_KEY_MGMT_IEEE8021X);
                } else {
-                       wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: failed to get "
-                               "master session key from pre-auth EAPOL state "
-                               "machines");
+                       wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
+                               "RSN: failed to get master session key from "
+                               "pre-auth EAPOL state machines");
                        success = 0;
                }
        }
 
-       wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: pre-authentication with " MACSTR
-               " %s", MAC2STR(sm->preauth_bssid),
+       wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
+               MACSTR " %s", MAC2STR(sm->preauth_bssid),
                success ? "completed successfully" : "failed");
 
        rsn_preauth_deinit(sm);
@@ -127,8 +127,8 @@ static void rsn_preauth_timeout(void *eloop_ctx, void *timeout_ctx)
 {
        struct wpa_sm *sm = eloop_ctx;
 
-       wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: pre-authentication with " MACSTR
-               " timed out", MAC2STR(sm->preauth_bssid));
+       wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
+               MACSTR " timed out", MAC2STR(sm->preauth_bssid));
        rsn_preauth_deinit(sm);
        rsn_preauth_candidate_process(sm);
 }
@@ -183,8 +183,8 @@ int rsn_preauth_init(struct wpa_sm *sm, const u8 *dst,
        if (sm->preauth_eapol)
                return -1;
 
-       wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: starting pre-authentication "
-               "with " MACSTR, MAC2STR(dst));
+       wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG,
+               "RSN: starting pre-authentication with " MACSTR, MAC2STR(dst));
 
        sm->l2_preauth = l2_packet_init(sm->ifname, sm->own_addr,
                                        ETH_P_RSN_PREAUTH,
@@ -300,15 +300,15 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
 
        /* TODO: drop priority for old candidate entries */
 
-       wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: processing PMKSA candidate "
+       wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: processing PMKSA candidate "
                "list");
        if (sm->preauth_eapol ||
            sm->proto != WPA_PROTO_RSN ||
            wpa_sm_get_state(sm) != WPA_COMPLETED ||
            (sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X &&
             sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X_SHA256)) {
-               wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: not in suitable state "
-                       "for new pre-authentication");
+               wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: not in suitable "
+                       "state for new pre-authentication");
                return; /* invalid state for new pre-auth */
        }
 
@@ -318,7 +318,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
                p = pmksa_cache_get(sm->pmksa, candidate->bssid, NULL);
                if (os_memcmp(sm->bssid, candidate->bssid, ETH_ALEN) != 0 &&
                    (p == NULL || p->opportunistic)) {
-                       wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: PMKSA "
+                       wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA "
                                "candidate " MACSTR
                                " selected for pre-authentication",
                                MAC2STR(candidate->bssid));
@@ -328,7 +328,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
                        os_free(candidate);
                        return;
                }
-               wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: PMKSA candidate "
+               wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: PMKSA candidate "
                        MACSTR " does not need pre-authentication anymore",
                        MAC2STR(candidate->bssid));
                /* Some drivers (e.g., NDIS) expect to get notified about the
@@ -340,7 +340,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
                sm->pmksa_candidates = candidate->next;
                os_free(candidate);
        }
-       wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: no more pending PMKSA "
+       wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: no more pending PMKSA "
                "candidates");
 }
 
@@ -414,7 +414,7 @@ void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
        else
                sm->pmksa_candidates = cand;
 
-       wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: added PMKSA cache "
+       wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: added PMKSA cache "
                "candidate " MACSTR " prio %d", MAC2STR(bssid), prio);
        rsn_preauth_candidate_process(sm);
 }
index 4531e83..5270858 100644 (file)
@@ -258,10 +258,10 @@ static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
                                abort_cached = 0;
                        }
                } else {
-                       wpa_msg(sm->ctx->ctx, MSG_WARNING,
+                       wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
                                "WPA: Failed to get master session key from "
                                "EAPOL state machines");
-                       wpa_msg(sm->ctx->ctx, MSG_WARNING,
+                       wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
                                "WPA: Key handshake aborted");
                        if (sm->cur_pmksa) {
                                wpa_printf(MSG_DEBUG, "RSN: Cancelled PMKSA "
@@ -413,7 +413,7 @@ static void wpa_supplicant_process_1_of_4(struct wpa_sm *sm,
 
        if (sm->renew_snonce) {
                if (os_get_random(sm->snonce, WPA_NONCE_LEN)) {
-                       wpa_msg(sm->ctx->ctx, MSG_WARNING,
+                       wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
                                "WPA: Failed to get random data for SNonce");
                        return;
                }
@@ -451,7 +451,8 @@ static void wpa_sm_start_preauth(void *eloop_ctx, void *timeout_ctx)
 static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm,
                                            const u8 *addr, int secure)
 {
-       wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Key negotiation completed with "
+       wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
+               "WPA: Key negotiation completed with "
                MACSTR " [PTK=%s GTK=%s]", MAC2STR(addr),
                wpa_cipher_txt(sm->pairwise_cipher),
                wpa_cipher_txt(sm->group_cipher));
@@ -769,7 +770,7 @@ static void wpa_report_ie_mismatch(struct wpa_sm *sm,
                                   const u8 *wpa_ie, size_t wpa_ie_len,
                                   const u8 *rsn_ie, size_t rsn_ie_len)
 {
-       wpa_msg(sm->ctx->ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")",
+       wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, "WPA: %s (src=" MACSTR ")",
                reason, MAC2STR(src_addr));
 
        if (sm->ap_wpa_ie) {
@@ -1218,7 +1219,7 @@ static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm,
                return;
 
        if (rekey) {
-               wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Group rekeying "
+               wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Group rekeying "
                        "completed with " MACSTR " [GTK=%s]",
                        MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher));
                wpa_sm_cancel_auth_timeout(sm);
@@ -1586,7 +1587,7 @@ int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr,
        extra_len = data_len - sizeof(*hdr) - sizeof(*key);
 
        if (WPA_GET_BE16(key->key_data_length) > extra_len) {
-               wpa_msg(sm->ctx->ctx, MSG_INFO, "WPA: Invalid EAPOL-Key "
+               wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "WPA: Invalid EAPOL-Key "
                        "frame - key_data overflow (%d > %lu)",
                        WPA_GET_BE16(key->key_data_length),
                        (unsigned long) extra_len);
index 1b11651..f97d9c5 100644 (file)
@@ -33,6 +33,7 @@ struct wpa_config_blob;
 
 struct wpa_sm_ctx {
        void *ctx; /* pointer to arbitrary upper level context */
+       void *msg_ctx; /* upper level context for wpa_msg() calls */
 
        void (*set_state)(void *ctx, wpa_states state);
        wpa_states (*get_state)(void *ctx);
index d605def..080c1f6 100644 (file)
@@ -144,6 +144,7 @@ int ibss_rsn_supp_init(struct ibss_rsn_peer *peer, const u8 *own_addr,
                return -1;
 
        ctx->ctx = peer;
+       ctx->msg_ctx = peer->ibss_rsn->wpa_s;
        ctx->set_state = supp_set_state;
        ctx->ether_send = supp_ether_send;
        ctx->get_beacon_ie = supp_get_beacon_ie;
index 86307a8..db43071 100644 (file)
@@ -239,6 +239,7 @@ static void wpa_init_conf(struct wpa_supplicant *wpa_s, const char *ifname)
        assert(ctx != NULL);
 
        ctx->ctx = wpa_s;
+       ctx->msg_ctx = wpa_s;
        ctx->set_state = _wpa_supplicant_set_state;
        ctx->get_state = _wpa_supplicant_get_state;
        ctx->deauthenticate = _wpa_supplicant_deauthenticate;
index 61b6336..4c341b6 100644 (file)
@@ -180,6 +180,7 @@ static int supp_init(struct wpa *wpa)
                return -1;
 
        ctx->ctx = wpa;
+       ctx->msg_ctx = wpa;
        ctx->set_state = supp_set_state;
        ctx->get_bssid = supp_get_bssid;
        ctx->ether_send = supp_ether_send;
index 2b96aa7..eb2796e 100644 (file)
@@ -586,6 +586,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
        }
 
        ctx->ctx = wpa_s;
+       ctx->msg_ctx = wpa_s;
        ctx->set_state = _wpa_supplicant_set_state;
        ctx->get_state = _wpa_supplicant_get_state;
        ctx->deauthenticate = _wpa_supplicant_deauthenticate;