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