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