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