Added a separate ctx pointer for wpa_msg() calls in WPA supp

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.
This commit is contained in:
Jouni Malinen 2009-01-17 17:54:40 +02:00
parent b9a2e577b4
commit 0f057fb2c7
8 changed files with 34 additions and 28 deletions

View file

@ -255,7 +255,7 @@ static int wpa_supplicant_process_smk_m2(
#endif /* CONFIG_IEEE80211W */ #endif /* CONFIG_IEEE80211W */
if (os_get_random(peerkey->pnonce, WPA_NONCE_LEN)) { 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: Failed to get random data for PNonce");
wpa_supplicant_peerkey_free(sm, peerkey); wpa_supplicant_peerkey_free(sm, peerkey);
return -1; return -1;
@ -371,7 +371,7 @@ static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
peerkey->smkid, PMKID_LEN); peerkey->smkid, PMKID_LEN);
if (os_get_random(peerkey->inonce, WPA_NONCE_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)"); "RSN: Failed to get random data for INonce (STK)");
os_free(mbuf); os_free(mbuf);
return; return;
@ -636,7 +636,7 @@ static int wpa_supplicant_process_smk_error(
os_memcpy(peer, kde.mac_addr, ETH_ALEN); os_memcpy(peer, kde.mac_addr, ETH_ALEN);
os_memcpy(&error, kde.error, sizeof(error)); os_memcpy(&error, kde.error, sizeof(error));
error_type = be_to_host16(error.error_type); 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 " "RSN: SMK Error KDE received: MUI %d error_type %d peer "
MACSTR, MACSTR,
be_to_host16(error.mui), error_type, 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)) { 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"); "RSN: Failed to get random data for PNonce");
return; 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); inc_byte_array(sm->request_counter, WPA_REPLAY_COUNTER_LEN);
if (os_get_random(peerkey->inonce, WPA_NONCE_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"); "WPA: Failed to get random data for INonce");
os_free(rbuf); os_free(rbuf);
wpa_supplicant_peerkey_free(sm, peerkey); wpa_supplicant_peerkey_free(sm, peerkey);

View file

@ -107,15 +107,15 @@ static void rsn_preauth_eapol_cb(struct eapol_sm *eapol, int success,
sm->network_ctx, sm->network_ctx,
WPA_KEY_MGMT_IEEE8021X); WPA_KEY_MGMT_IEEE8021X);
} else { } else {
wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: failed to get " wpa_msg(sm->ctx->msg_ctx, MSG_INFO,
"master session key from pre-auth EAPOL state " "RSN: failed to get master session key from "
"machines"); "pre-auth EAPOL state machines");
success = 0; success = 0;
} }
} }
wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: pre-authentication with " MACSTR wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
" %s", MAC2STR(sm->preauth_bssid), MACSTR " %s", MAC2STR(sm->preauth_bssid),
success ? "completed successfully" : "failed"); success ? "completed successfully" : "failed");
rsn_preauth_deinit(sm); 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; struct wpa_sm *sm = eloop_ctx;
wpa_msg(sm->ctx->ctx, MSG_INFO, "RSN: pre-authentication with " MACSTR wpa_msg(sm->ctx->msg_ctx, MSG_INFO, "RSN: pre-authentication with "
" timed out", MAC2STR(sm->preauth_bssid)); MACSTR " timed out", MAC2STR(sm->preauth_bssid));
rsn_preauth_deinit(sm); rsn_preauth_deinit(sm);
rsn_preauth_candidate_process(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) if (sm->preauth_eapol)
return -1; return -1;
wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: starting pre-authentication " wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG,
"with " MACSTR, MAC2STR(dst)); "RSN: starting pre-authentication with " MACSTR, MAC2STR(dst));
sm->l2_preauth = l2_packet_init(sm->ifname, sm->own_addr, sm->l2_preauth = l2_packet_init(sm->ifname, sm->own_addr,
ETH_P_RSN_PREAUTH, ETH_P_RSN_PREAUTH,
@ -300,15 +300,15 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
/* TODO: drop priority for old candidate entries */ /* 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"); "list");
if (sm->preauth_eapol || if (sm->preauth_eapol ||
sm->proto != WPA_PROTO_RSN || sm->proto != WPA_PROTO_RSN ||
wpa_sm_get_state(sm) != WPA_COMPLETED || wpa_sm_get_state(sm) != WPA_COMPLETED ||
(sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X && (sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X &&
sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X_SHA256)) { sm->key_mgmt != WPA_KEY_MGMT_IEEE8021X_SHA256)) {
wpa_msg(sm->ctx->ctx, MSG_DEBUG, "RSN: not in suitable state " wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: not in suitable "
"for new pre-authentication"); "state for new pre-authentication");
return; /* invalid state for new pre-auth */ 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); p = pmksa_cache_get(sm->pmksa, candidate->bssid, NULL);
if (os_memcmp(sm->bssid, candidate->bssid, ETH_ALEN) != 0 && if (os_memcmp(sm->bssid, candidate->bssid, ETH_ALEN) != 0 &&
(p == NULL || p->opportunistic)) { (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 "candidate " MACSTR
" selected for pre-authentication", " selected for pre-authentication",
MAC2STR(candidate->bssid)); MAC2STR(candidate->bssid));
@ -328,7 +328,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
os_free(candidate); os_free(candidate);
return; 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", MACSTR " does not need pre-authentication anymore",
MAC2STR(candidate->bssid)); MAC2STR(candidate->bssid));
/* Some drivers (e.g., NDIS) expect to get notified about the /* 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; sm->pmksa_candidates = candidate->next;
os_free(candidate); 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"); "candidates");
} }
@ -414,7 +414,7 @@ void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
else else
sm->pmksa_candidates = cand; 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); "candidate " MACSTR " prio %d", MAC2STR(bssid), prio);
rsn_preauth_candidate_process(sm); rsn_preauth_candidate_process(sm);
} }

View file

@ -258,10 +258,10 @@ static int wpa_supplicant_get_pmk(struct wpa_sm *sm,
abort_cached = 0; abort_cached = 0;
} }
} else { } else {
wpa_msg(sm->ctx->ctx, MSG_WARNING, wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Failed to get master session key from " "WPA: Failed to get master session key from "
"EAPOL state machines"); "EAPOL state machines");
wpa_msg(sm->ctx->ctx, MSG_WARNING, wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Key handshake aborted"); "WPA: Key handshake aborted");
if (sm->cur_pmksa) { if (sm->cur_pmksa) {
wpa_printf(MSG_DEBUG, "RSN: Cancelled 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 (sm->renew_snonce) {
if (os_get_random(sm->snonce, WPA_NONCE_LEN)) { 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"); "WPA: Failed to get random data for SNonce");
return; 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, static void wpa_supplicant_key_neg_complete(struct wpa_sm *sm,
const u8 *addr, int secure) 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), MACSTR " [PTK=%s GTK=%s]", MAC2STR(addr),
wpa_cipher_txt(sm->pairwise_cipher), wpa_cipher_txt(sm->pairwise_cipher),
wpa_cipher_txt(sm->group_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 *wpa_ie, size_t wpa_ie_len,
const u8 *rsn_ie, size_t rsn_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)); reason, MAC2STR(src_addr));
if (sm->ap_wpa_ie) { if (sm->ap_wpa_ie) {
@ -1218,7 +1219,7 @@ static void wpa_supplicant_process_1_of_2(struct wpa_sm *sm,
return; return;
if (rekey) { 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]", "completed with " MACSTR " [GTK=%s]",
MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher)); MAC2STR(sm->bssid), wpa_cipher_txt(sm->group_cipher));
wpa_sm_cancel_auth_timeout(sm); 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); extra_len = data_len - sizeof(*hdr) - sizeof(*key);
if (WPA_GET_BE16(key->key_data_length) > extra_len) { 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)", "frame - key_data overflow (%d > %lu)",
WPA_GET_BE16(key->key_data_length), WPA_GET_BE16(key->key_data_length),
(unsigned long) extra_len); (unsigned long) extra_len);

View file

@ -33,6 +33,7 @@ struct wpa_config_blob;
struct wpa_sm_ctx { struct wpa_sm_ctx {
void *ctx; /* pointer to arbitrary upper level context */ 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); void (*set_state)(void *ctx, wpa_states state);
wpa_states (*get_state)(void *ctx); wpa_states (*get_state)(void *ctx);

View file

@ -144,6 +144,7 @@ int ibss_rsn_supp_init(struct ibss_rsn_peer *peer, const u8 *own_addr,
return -1; return -1;
ctx->ctx = peer; ctx->ctx = peer;
ctx->msg_ctx = peer->ibss_rsn->wpa_s;
ctx->set_state = supp_set_state; ctx->set_state = supp_set_state;
ctx->ether_send = supp_ether_send; ctx->ether_send = supp_ether_send;
ctx->get_beacon_ie = supp_get_beacon_ie; ctx->get_beacon_ie = supp_get_beacon_ie;

View file

@ -239,6 +239,7 @@ static void wpa_init_conf(struct wpa_supplicant *wpa_s, const char *ifname)
assert(ctx != NULL); assert(ctx != NULL);
ctx->ctx = wpa_s; ctx->ctx = wpa_s;
ctx->msg_ctx = wpa_s;
ctx->set_state = _wpa_supplicant_set_state; ctx->set_state = _wpa_supplicant_set_state;
ctx->get_state = _wpa_supplicant_get_state; ctx->get_state = _wpa_supplicant_get_state;
ctx->deauthenticate = _wpa_supplicant_deauthenticate; ctx->deauthenticate = _wpa_supplicant_deauthenticate;

View file

@ -180,6 +180,7 @@ static int supp_init(struct wpa *wpa)
return -1; return -1;
ctx->ctx = wpa; ctx->ctx = wpa;
ctx->msg_ctx = wpa;
ctx->set_state = supp_set_state; ctx->set_state = supp_set_state;
ctx->get_bssid = supp_get_bssid; ctx->get_bssid = supp_get_bssid;
ctx->ether_send = supp_ether_send; ctx->ether_send = supp_ether_send;

View file

@ -586,6 +586,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s)
} }
ctx->ctx = wpa_s; ctx->ctx = wpa_s;
ctx->msg_ctx = wpa_s;
ctx->set_state = _wpa_supplicant_set_state; ctx->set_state = _wpa_supplicant_set_state;
ctx->get_state = _wpa_supplicant_get_state; ctx->get_state = _wpa_supplicant_get_state;
ctx->deauthenticate = _wpa_supplicant_deauthenticate; ctx->deauthenticate = _wpa_supplicant_deauthenticate;