]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
Add a callback to notify added PMKSA cache entry details
authorVinay Gannevaram <quic_vganneva@quicinc.com>
Sun, 20 Nov 2022 13:57:51 +0000 (19:27 +0530)
committerJouni Malinen <j@w1.fi>
Mon, 28 Nov 2022 09:39:06 +0000 (11:39 +0200)
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 <quic_jouni@quicinc.com>
src/rsn_supp/pmksa_cache.c
src/rsn_supp/pmksa_cache.h
src/rsn_supp/wpa.c
src/rsn_supp/wpa.h
src/rsn_supp/wpa_i.h
wpa_supplicant/notify.c
wpa_supplicant/notify.h
wpa_supplicant/wpas_glue.c

index 1a4011bc3d754d767ef387510f96aea7b9e65f3d..ea83e76e6e52ba5e5dd645e4a3f96e86fb9e9a67 100644 (file)
@@ -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;
        }
index 69f83b5797a287518fa7b830f4bf7fd7e6cba6fc..48c9e0465b30dfb2be230a090336eba989b05bce 100644 (file)
@@ -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;
index 37296771aed02ffe87e47d2fedd8eee53c40fe6d..2b3349d8cbe0cfb4a83f09fe2f88c6867f578a6d 100644 (file)
@@ -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");
index 3fd76bde8a7ac5ed7c98fe8cdef05d0c2c5234c9..c79ebfceab2febae101d3fa9cec23d3dcd475935 100644 (file)
@@ -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);
 };
 
 
index 3c933e9e368307485603ed5bdb3bbdbdb56e2c7d..2eac13358a643153e6115e486483ae9899e3e5cf 100644 (file)
@@ -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);
index 5a471091af07a088e36f57ac16ceaea1f800a468..427405da9249c6f26d74ca39bcd1c02522245db1 100644 (file)
@@ -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 */
+}
index c46e7986e3b336e3b782c3840a28f5f39b8228b9..f26f4286dc782ac34ba7fb2ab8ae88686fbd830e 100644 (file)
@@ -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 */
index 4641595467d4db750f094d039bc4870c73e4e6f1..a309ea27831d47baca2b1451074c2be8d0a2c1b4 100644 (file)
@@ -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) {