1 /*
2 * wpa_supplicant - WPA2/RSN PMKSA cache functions
3 * Copyright (c) 2003-2009, 2011-2012, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #ifndef PMKSA_CACHE_H
10 #define PMKSA_CACHE_H
11
12 /**
13 * struct rsn_pmksa_cache_entry - PMKSA cache entry
14 */
15 struct rsn_pmksa_cache_entry {
16 struct rsn_pmksa_cache_entry *next;
17 u8 pmkid[PMKID_LEN];
18 u8 pmk[PMK_LEN_MAX];
19 size_t pmk_len;
20 u8 kck[WPA_KCK_MAX_LEN];
21 size_t kck_len;
22 os_time_t expiration;
23 int akmp; /* WPA_KEY_MGMT_* */
24 u8 aa[ETH_ALEN];
25 u8 spa[ETH_ALEN];
26
27 /*
28 * If FILS Cache Identifier is included (fils_cache_id_set), this PMKSA
29 * cache entry is applicable to all BSSs (any BSSID/aa[]) that
30 * advertise the same FILS Cache Identifier within the same ESS.
31 */
32 u8 fils_cache_id[2];
33 unsigned int fils_cache_id_set:1;
34 unsigned int dpp_pfs:1;
35
36 os_time_t reauth_time;
37
38 /**
39 * network_ctx - Network configuration context
40 *
41 * This field is only used to match PMKSA cache entries to a specific
42 * network configuration (e.g., a specific SSID and security policy).
43 * This can be a pointer to the configuration entry, but PMKSA caching
44 * code does not dereference the value and this could be any kind of
45 * identifier.
46 */
47 void *network_ctx;
48 int opportunistic;
49 bool external;
50
51 /**
52 * This field is used to avoid duplicate pmksa_cache_reauth() calls for
53 * every 10 minutes during the periodic expiration check of the current
54 * PMKSA for SAE.
55 */
56 bool sae_reauth_scheduled;
57 };
58
59 struct rsn_pmksa_cache;
60
61 enum pmksa_free_reason {
62 PMKSA_FREE,
63 PMKSA_REPLACE,
64 PMKSA_EXPIRE,
65 };
66
67 #if defined(IEEE8021X_EAPOL) && !defined(CONFIG_NO_WPA)
68
69 struct rsn_pmksa_cache *
70 pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
71 void *ctx, enum pmksa_free_reason reason),
72 bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
73 void *ctx),
74 void (*notify_cb)(struct rsn_pmksa_cache_entry *entry,
75 void *ctx),
76 void *ctx, struct wpa_sm *sm);
77 void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
78 struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
79 const u8 *aa, const u8 *spa,
80 const u8 *pmkid,
81 const void *network_ctx,
82 int akmp);
83 int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len);
84 struct rsn_pmksa_cache_entry * pmksa_cache_head(struct rsn_pmksa_cache *pmksa);
85 struct rsn_pmksa_cache_entry *
86 pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
87 const u8 *pmkid, const u8 *kck, size_t kck_len,
88 const u8 *aa, const u8 *spa, void *network_ctx, int akmp,
89 const u8 *cache_id);
90 struct rsn_pmksa_cache_entry *
91 pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa,
92 struct rsn_pmksa_cache_entry *entry);
93 struct rsn_pmksa_cache_entry * pmksa_cache_get_current(struct wpa_sm *sm);
94 void pmksa_cache_clear_current(struct wpa_sm *sm);
95 int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
96 const u8 *bssid, void *network_ctx,
97 int try_opportunistic, const u8 *fils_cache_id,
98 int akmp, bool associated);
99 struct rsn_pmksa_cache_entry *
100 pmksa_cache_get_opportunistic(struct rsn_pmksa_cache *pmksa,
101 void *network_ctx, const u8 *aa, int akmp);
102 void pmksa_cache_flush(struct rsn_pmksa_cache *pmksa, void *network_ctx,
103 const u8 *pmk, size_t pmk_len, bool external_only);
104 void pmksa_cache_remove(struct rsn_pmksa_cache *pmksa,
105 struct rsn_pmksa_cache_entry *entry);
106 void pmksa_cache_reconfig(struct rsn_pmksa_cache *pmksa);
107
108 #else /* IEEE8021X_EAPOL */
109
110 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),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)111 pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
112 void *ctx, enum pmksa_free_reason reason),
113 bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
114 void *ctx),
115 void (*notify_cb)(struct rsn_pmksa_cache_entry *entry,
116 void *ctx),
117 void *ctx, struct wpa_sm *sm)
118 {
119 return (void *) -1;
120 }
121
pmksa_cache_deinit(struct rsn_pmksa_cache * pmksa)122 static inline void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa)
123 {
124 }
125
126 static inline struct rsn_pmksa_cache_entry *
pmksa_cache_get(struct rsn_pmksa_cache * pmksa,const u8 * aa,const u8 * spa,const u8 * pmkid,const void * network_ctx,int akmp)127 pmksa_cache_get(struct rsn_pmksa_cache *pmksa, const u8 *aa, const u8 *spa,
128 const u8 *pmkid, const void *network_ctx, int akmp)
129 {
130 return NULL;
131 }
132
133 static inline struct rsn_pmksa_cache_entry *
pmksa_cache_get_current(struct wpa_sm * sm)134 pmksa_cache_get_current(struct wpa_sm *sm)
135 {
136 return NULL;
137 }
138
pmksa_cache_list(struct rsn_pmksa_cache * pmksa,char * buf,size_t len)139 static inline int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf,
140 size_t len)
141 {
142 return -1;
143 }
144
145 static inline struct rsn_pmksa_cache_entry *
pmksa_cache_head(struct rsn_pmksa_cache * pmksa)146 pmksa_cache_head(struct rsn_pmksa_cache *pmksa)
147 {
148 return NULL;
149 }
150
151 static inline struct rsn_pmksa_cache_entry *
pmksa_cache_add_entry(struct rsn_pmksa_cache * pmksa,struct rsn_pmksa_cache_entry * entry)152 pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa,
153 struct rsn_pmksa_cache_entry *entry)
154 {
155 return NULL;
156 }
157
158 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)159 pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
160 const u8 *pmkid, const u8 *kck, size_t kck_len,
161 const u8 *aa, const u8 *spa, void *network_ctx, int akmp,
162 const u8 *cache_id)
163 {
164 return NULL;
165 }
166
pmksa_cache_clear_current(struct wpa_sm * sm)167 static inline void pmksa_cache_clear_current(struct wpa_sm *sm)
168 {
169 }
170
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,bool associated)171 static inline int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
172 const u8 *bssid,
173 void *network_ctx,
174 int try_opportunistic,
175 const u8 *fils_cache_id,
176 int akmp, bool associated)
177 {
178 return -1;
179 }
180
pmksa_cache_flush(struct rsn_pmksa_cache * pmksa,void * network_ctx,const u8 * pmk,size_t pmk_len,bool external_only)181 static inline void pmksa_cache_flush(struct rsn_pmksa_cache *pmksa,
182 void *network_ctx,
183 const u8 *pmk, size_t pmk_len,
184 bool external_only)
185 {
186 }
187
pmksa_cache_remove(struct rsn_pmksa_cache * pmksa,struct rsn_pmksa_cache_entry * entry)188 static inline void pmksa_cache_remove(struct rsn_pmksa_cache *pmksa,
189 struct rsn_pmksa_cache_entry *entry)
190 {
191 }
192
pmksa_cache_reconfig(struct rsn_pmksa_cache * pmksa)193 static inline void pmksa_cache_reconfig(struct rsn_pmksa_cache *pmksa)
194 {
195 }
196
197 #endif /* IEEE8021X_EAPOL */
198
199 #endif /* PMKSA_CACHE_H */
200