18dbcf02cSchristos /*
28dbcf02cSchristos * wpa_supplicant - WPA2/RSN PMKSA cache functions
362a52023Schristos * Copyright (c) 2003-2009, 2011-2012, Jouni Malinen <j@w1.fi>
48dbcf02cSchristos *
562a52023Schristos * This software may be distributed under the terms of the BSD license.
662a52023Schristos * See README for more details.
78dbcf02cSchristos */
88dbcf02cSchristos
98dbcf02cSchristos #ifndef PMKSA_CACHE_H
108dbcf02cSchristos #define PMKSA_CACHE_H
118dbcf02cSchristos
128dbcf02cSchristos /**
138dbcf02cSchristos * struct rsn_pmksa_cache_entry - PMKSA cache entry
148dbcf02cSchristos */
158dbcf02cSchristos struct rsn_pmksa_cache_entry {
168dbcf02cSchristos struct rsn_pmksa_cache_entry *next;
178dbcf02cSchristos u8 pmkid[PMKID_LEN];
18928750b6Schristos u8 pmk[PMK_LEN_MAX];
198dbcf02cSchristos size_t pmk_len;
208dbcf02cSchristos os_time_t expiration;
218dbcf02cSchristos int akmp; /* WPA_KEY_MGMT_* */
228dbcf02cSchristos u8 aa[ETH_ALEN];
238dbcf02cSchristos
24*ebb5671cSchristos /*
25*ebb5671cSchristos * If FILS Cache Identifier is included (fils_cache_id_set), this PMKSA
26*ebb5671cSchristos * cache entry is applicable to all BSSs (any BSSID/aa[]) that
27*ebb5671cSchristos * advertise the same FILS Cache Identifier within the same ESS.
28*ebb5671cSchristos */
29*ebb5671cSchristos u8 fils_cache_id[2];
30*ebb5671cSchristos unsigned int fils_cache_id_set:1;
31*ebb5671cSchristos
328dbcf02cSchristos os_time_t reauth_time;
338dbcf02cSchristos
348dbcf02cSchristos /**
358dbcf02cSchristos * network_ctx - Network configuration context
368dbcf02cSchristos *
378dbcf02cSchristos * This field is only used to match PMKSA cache entries to a specific
388dbcf02cSchristos * network configuration (e.g., a specific SSID and security policy).
398dbcf02cSchristos * This can be a pointer to the configuration entry, but PMKSA caching
408dbcf02cSchristos * code does not dereference the value and this could be any kind of
418dbcf02cSchristos * identifier.
428dbcf02cSchristos */
438dbcf02cSchristos void *network_ctx;
448dbcf02cSchristos int opportunistic;
458dbcf02cSchristos };
468dbcf02cSchristos
478dbcf02cSchristos struct rsn_pmksa_cache;
488dbcf02cSchristos
4962a52023Schristos enum pmksa_free_reason {
5062a52023Schristos PMKSA_FREE,
5162a52023Schristos PMKSA_REPLACE,
5262a52023Schristos PMKSA_EXPIRE,
5362a52023Schristos };
5462a52023Schristos
55928750b6Schristos #if defined(IEEE8021X_EAPOL) && !defined(CONFIG_NO_WPA)
568dbcf02cSchristos
578dbcf02cSchristos struct rsn_pmksa_cache *
588dbcf02cSchristos pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
5962a52023Schristos void *ctx, enum pmksa_free_reason reason),
608dbcf02cSchristos void *ctx, struct wpa_sm *sm);
618dbcf02cSchristos void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
628dbcf02cSchristos struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
6362a52023Schristos const u8 *aa, const u8 *pmkid,
64*ebb5671cSchristos const void *network_ctx,
65*ebb5671cSchristos int akmp);
668dbcf02cSchristos int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len);
67*ebb5671cSchristos struct rsn_pmksa_cache_entry * pmksa_cache_head(struct rsn_pmksa_cache *pmksa);
688dbcf02cSchristos struct rsn_pmksa_cache_entry *
698dbcf02cSchristos pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
70928750b6Schristos const u8 *pmkid, const u8 *kck, size_t kck_len,
71*ebb5671cSchristos const u8 *aa, const u8 *spa, void *network_ctx, int akmp,
72*ebb5671cSchristos const u8 *cache_id);
73*ebb5671cSchristos struct rsn_pmksa_cache_entry *
74*ebb5671cSchristos pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa,
75*ebb5671cSchristos struct rsn_pmksa_cache_entry *entry);
768dbcf02cSchristos struct rsn_pmksa_cache_entry * pmksa_cache_get_current(struct wpa_sm *sm);
778dbcf02cSchristos void pmksa_cache_clear_current(struct wpa_sm *sm);
788dbcf02cSchristos int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
798dbcf02cSchristos const u8 *bssid, void *network_ctx,
80*ebb5671cSchristos int try_opportunistic, const u8 *fils_cache_id,
81*ebb5671cSchristos int akmp);
828dbcf02cSchristos struct rsn_pmksa_cache_entry *
838dbcf02cSchristos pmksa_cache_get_opportunistic(struct rsn_pmksa_cache *pmksa,
84*ebb5671cSchristos void *network_ctx, const u8 *aa, int akmp);
8536d97821Schristos void pmksa_cache_flush(struct rsn_pmksa_cache *pmksa, void *network_ctx,
8636d97821Schristos const u8 *pmk, size_t pmk_len);
878dbcf02cSchristos
8836d97821Schristos #else /* IEEE8021X_EAPOL */
898dbcf02cSchristos
908dbcf02cSchristos static inline struct rsn_pmksa_cache *
pmksa_cache_init(void (* free_cb)(struct rsn_pmksa_cache_entry * entry,void * ctx,enum pmksa_free_reason reason),void * ctx,struct wpa_sm * sm)918dbcf02cSchristos pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
9236d97821Schristos void *ctx, enum pmksa_free_reason reason),
938dbcf02cSchristos void *ctx, struct wpa_sm *sm)
948dbcf02cSchristos {
958dbcf02cSchristos return (void *) -1;
968dbcf02cSchristos }
978dbcf02cSchristos
pmksa_cache_deinit(struct rsn_pmksa_cache * pmksa)988dbcf02cSchristos static inline void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa)
998dbcf02cSchristos {
1008dbcf02cSchristos }
1018dbcf02cSchristos
1028dbcf02cSchristos static inline struct rsn_pmksa_cache_entry *
pmksa_cache_get(struct rsn_pmksa_cache * pmksa,const u8 * aa,const u8 * pmkid,const void * network_ctx,int akmp)10362a52023Schristos pmksa_cache_get(struct rsn_pmksa_cache *pmksa, const u8 *aa, const u8 *pmkid,
104*ebb5671cSchristos const void *network_ctx, int akmp)
1058dbcf02cSchristos {
1068dbcf02cSchristos return NULL;
1078dbcf02cSchristos }
1088dbcf02cSchristos
1098dbcf02cSchristos static inline struct rsn_pmksa_cache_entry *
pmksa_cache_get_current(struct wpa_sm * sm)1108dbcf02cSchristos pmksa_cache_get_current(struct wpa_sm *sm)
1118dbcf02cSchristos {
1128dbcf02cSchristos return NULL;
1138dbcf02cSchristos }
1148dbcf02cSchristos
pmksa_cache_list(struct rsn_pmksa_cache * pmksa,char * buf,size_t len)1158dbcf02cSchristos static inline int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf,
1168dbcf02cSchristos size_t len)
1178dbcf02cSchristos {
1188dbcf02cSchristos return -1;
1198dbcf02cSchristos }
1208dbcf02cSchristos
1218dbcf02cSchristos static inline struct rsn_pmksa_cache_entry *
pmksa_cache_head(struct rsn_pmksa_cache * pmksa)122*ebb5671cSchristos pmksa_cache_head(struct rsn_pmksa_cache *pmksa)
123*ebb5671cSchristos {
124*ebb5671cSchristos return NULL;
125*ebb5671cSchristos }
126*ebb5671cSchristos
127*ebb5671cSchristos static inline struct rsn_pmksa_cache_entry *
pmksa_cache_add_entry(struct rsn_pmksa_cache * pmksa,struct rsn_pmksa_cache_entry * entry)128*ebb5671cSchristos pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa,
129*ebb5671cSchristos struct rsn_pmksa_cache_entry *entry)
130*ebb5671cSchristos {
131*ebb5671cSchristos return NULL;
132*ebb5671cSchristos }
133*ebb5671cSchristos
134*ebb5671cSchristos static inline struct rsn_pmksa_cache_entry *
pmksa_cache_add(struct rsn_pmksa_cache * pmksa,const u8 * pmk,size_t pmk_len,const u8 * pmkid,const u8 * kck,size_t kck_len,const u8 * aa,const u8 * spa,void * network_ctx,int akmp,const u8 * cache_id)1358dbcf02cSchristos pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
136928750b6Schristos const u8 *pmkid, const u8 *kck, size_t kck_len,
137*ebb5671cSchristos const u8 *aa, const u8 *spa, void *network_ctx, int akmp,
138*ebb5671cSchristos const u8 *cache_id)
1398dbcf02cSchristos {
1408dbcf02cSchristos return NULL;
1418dbcf02cSchristos }
1428dbcf02cSchristos
pmksa_cache_clear_current(struct wpa_sm * sm)1438dbcf02cSchristos static inline void pmksa_cache_clear_current(struct wpa_sm *sm)
1448dbcf02cSchristos {
1458dbcf02cSchristos }
1468dbcf02cSchristos
pmksa_cache_set_current(struct wpa_sm * sm,const u8 * pmkid,const u8 * bssid,void * network_ctx,int try_opportunistic,const u8 * fils_cache_id,int akmp)1478dbcf02cSchristos static inline int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
1488dbcf02cSchristos const u8 *bssid,
1498dbcf02cSchristos void *network_ctx,
150*ebb5671cSchristos int try_opportunistic,
151*ebb5671cSchristos const u8 *fils_cache_id,
152*ebb5671cSchristos int akmp)
1538dbcf02cSchristos {
1548dbcf02cSchristos return -1;
1558dbcf02cSchristos }
1568dbcf02cSchristos
pmksa_cache_flush(struct rsn_pmksa_cache * pmksa,void * network_ctx,const u8 * pmk,size_t pmk_len)15742669be3Schristos static inline void pmksa_cache_flush(struct rsn_pmksa_cache *pmksa,
15836d97821Schristos void *network_ctx,
15936d97821Schristos const u8 *pmk, size_t pmk_len)
16042669be3Schristos {
16142669be3Schristos }
16242669be3Schristos
16336d97821Schristos #endif /* IEEE8021X_EAPOL */
1648dbcf02cSchristos
1658dbcf02cSchristos #endif /* PMKSA_CACHE_H */
166