From: Vinay Gannevaram Date: Sun, 20 Nov 2022 13:57:51 +0000 (+0530) Subject: Add a callback to notify added PMKSA cache entry details X-Git-Tag: hostap_2_11~1460 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46e6b72b7b9202aebf6fc1dc4fa1015252bfcfa2;p=thirdparty%2Fhostap.git Add a callback to notify added PMKSA cache entry details Add a callback handler to notify details of a PMKSA cache entry when it is added to the PMKSA cache. This can be used to provide external components more convenient access to the PMKSA cache contents. Signed-off-by: Jouni Malinen --- diff --git a/src/rsn_supp/pmksa_cache.c b/src/rsn_supp/pmksa_cache.c index 1a4011bc3..ea83e76e6 100644 --- a/src/rsn_supp/pmksa_cache.c +++ b/src/rsn_supp/pmksa_cache.c @@ -28,6 +28,7 @@ struct rsn_pmksa_cache { enum pmksa_free_reason reason); bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx); + void (*notify_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx); void *ctx; }; @@ -360,6 +361,9 @@ pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa, if (!pmksa->sm) return entry; + if (pmksa->notify_cb) + pmksa->notify_cb(entry, pmksa->ctx); + wpa_sm_add_pmkid(pmksa->sm, entry->network_ctx, entry->aa, entry->pmkid, entry->fils_cache_id_set ? entry->fils_cache_id : NULL, entry->pmk, entry->pmk_len, @@ -754,6 +758,8 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx, enum pmksa_free_reason reason), bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx), + void (*notify_cb)(struct rsn_pmksa_cache_entry *entry, + void *ctx), void *ctx, struct wpa_sm *sm) { struct rsn_pmksa_cache *pmksa; @@ -762,6 +768,7 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry, if (pmksa) { pmksa->free_cb = free_cb; pmksa->is_current_cb = is_current_cb; + pmksa->notify_cb = notify_cb; pmksa->ctx = ctx; pmksa->sm = sm; } diff --git a/src/rsn_supp/pmksa_cache.h b/src/rsn_supp/pmksa_cache.h index 69f83b579..48c9e0465 100644 --- a/src/rsn_supp/pmksa_cache.h +++ b/src/rsn_supp/pmksa_cache.h @@ -62,6 +62,8 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx, enum pmksa_free_reason reason), bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx), + void (*notify_cb)(struct rsn_pmksa_cache_entry *entry, + void *ctx), void *ctx, struct wpa_sm *sm); void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa); struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa, @@ -101,6 +103,8 @@ pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx, enum pmksa_free_reason reason), bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry, void *ctx), + void (*notify_cb)(struct rsn_pmksa_cache_entry *entry, + void *ctx), void *ctx, struct wpa_sm *sm) { return (void *) -1; diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c index 37296771a..2b3349d8c 100644 --- a/src/rsn_supp/wpa.c +++ b/src/rsn_supp/wpa.c @@ -3969,6 +3969,15 @@ static bool wpa_sm_pmksa_is_current_cb(struct rsn_pmksa_cache_entry *entry, } +static void wpa_sm_pmksa_notify_cb(struct rsn_pmksa_cache_entry *entry, + void *ctx) +{ + struct wpa_sm *sm = ctx; + + wpa_sm_notify_pmksa_cache_entry(sm, entry); +} + + /** * wpa_sm_init - Initialize WPA state machine * @ctx: Context pointer for callbacks; this needs to be an allocated buffer @@ -3993,7 +4002,8 @@ struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx) sm->dot11RSNAConfigSATimeout = 60; sm->pmksa = pmksa_cache_init(wpa_sm_pmksa_free_cb, - wpa_sm_pmksa_is_current_cb, sm, sm); + wpa_sm_pmksa_is_current_cb, + wpa_sm_pmksa_notify_cb, sm, sm); if (sm->pmksa == NULL) { wpa_msg(sm->ctx->msg_ctx, MSG_ERROR, "RSN: PMKSA cache initialization failed"); diff --git a/src/rsn_supp/wpa.h b/src/rsn_supp/wpa.h index 3fd76bde8..c79ebfcea 100644 --- a/src/rsn_supp/wpa.h +++ b/src/rsn_supp/wpa.h @@ -19,6 +19,7 @@ struct eapol_sm; struct wpa_config_blob; struct hostapd_freq_params; struct wpa_channel_info; +struct rsn_pmksa_cache_entry; enum frame_encryption; struct wpa_sm_ctx { @@ -98,6 +99,8 @@ struct wpa_sm_ctx { const u8 *peer_addr, size_t ltf_keyseed_len, const u8 *ltf_keyseed); #endif /* CONFIG_PASN */ + void (*notify_pmksa_cache_entry)(void *ctx, + struct rsn_pmksa_cache_entry *entry); }; diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h index 3c933e9e3..2eac13358 100644 --- a/src/rsn_supp/wpa_i.h +++ b/src/rsn_supp/wpa_i.h @@ -497,6 +497,14 @@ static inline int wpa_sm_set_ltf_keyseed(struct wpa_sm *sm, const u8 *own_addr, } #endif /* CONFIG_PASN */ +static inline void +wpa_sm_notify_pmksa_cache_entry(struct wpa_sm *sm, + struct rsn_pmksa_cache_entry *entry) +{ + if (sm->ctx->notify_pmksa_cache_entry) + sm->ctx->notify_pmksa_cache_entry(sm->ctx->ctx, entry); +} + int wpa_eapol_key_send(struct wpa_sm *sm, struct wpa_ptk *ptk, int ver, const u8 *dest, u16 proto, u8 *msg, size_t msg_len, u8 *key_mic); diff --git a/wpa_supplicant/notify.c b/wpa_supplicant/notify.c index 5a471091a..427405da9 100644 --- a/wpa_supplicant/notify.c +++ b/wpa_supplicant/notify.c @@ -17,6 +17,7 @@ #include "dbus/dbus_common.h" #include "dbus/dbus_new.h" #include "rsn_supp/wpa.h" +#include "rsn_supp/pmksa_cache.h" #include "fst/fst.h" #include "crypto/tls.h" #include "bss.h" @@ -976,3 +977,10 @@ void wpas_notify_interworking_select_done(struct wpa_supplicant *wpa_s) } #endif /* CONFIG_INTERWORKING */ + + +void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s, + struct rsn_pmksa_cache_entry *entry) +{ + /* TODO: Notify external entities of the added PMKSA cache entry */ +} diff --git a/wpa_supplicant/notify.h b/wpa_supplicant/notify.h index c46e7986e..f26f4286d 100644 --- a/wpa_supplicant/notify.h +++ b/wpa_supplicant/notify.h @@ -16,6 +16,7 @@ struct wps_event_m2d; struct wps_event_fail; struct tls_cert_data; struct wpa_cred; +struct rsn_pmksa_cache_entry; int wpas_notify_supplicant_initialized(struct wpa_global *global); void wpas_notify_supplicant_deinitialized(struct wpa_global *global); @@ -163,5 +164,7 @@ void wpas_notify_interworking_ap_added(struct wpa_supplicant *wpa_s, const char *type, int bh, int bss_load, int conn_capab); void wpas_notify_interworking_select_done(struct wpa_supplicant *wpa_s); +void wpas_notify_pmk_cache_added(struct wpa_supplicant *wpa_s, + struct rsn_pmksa_cache_entry *entry); #endif /* NOTIFY_H */ diff --git a/wpa_supplicant/wpas_glue.c b/wpa_supplicant/wpas_glue.c index 464159546..a309ea278 100644 --- a/wpa_supplicant/wpas_glue.c +++ b/wpa_supplicant/wpas_glue.c @@ -1381,6 +1381,16 @@ static int wpa_supplicant_set_ltf_keyseed(void *_wpa_s, const u8 *own_addr, #endif /* CONFIG_PASN */ +static void +wpa_supplicant_notify_pmksa_cache_entry(void *_wpa_s, + struct rsn_pmksa_cache_entry *entry) +{ + struct wpa_supplicant *wpa_s = _wpa_s; + + wpas_notify_pmk_cache_added(wpa_s, entry); +} + + int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s) { #ifndef CONFIG_NO_WPA @@ -1446,6 +1456,7 @@ int wpa_supplicant_init_wpa(struct wpa_supplicant *wpa_s) #ifdef CONFIG_PASN ctx->set_ltf_keyseed = wpa_supplicant_set_ltf_keyseed; #endif /* CONFIG_PASN */ + ctx->notify_pmksa_cache_entry = wpa_supplicant_notify_pmksa_cache_entry; wpa_s->wpa = wpa_sm_init(ctx); if (wpa_s->wpa == NULL) {