xref: /freebsd/contrib/wpa/src/rsn_supp/pmksa_cache.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
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 	bool external;
47 };
48 
49 struct rsn_pmksa_cache;
50 
51 enum pmksa_free_reason {
52 	PMKSA_FREE,
53 	PMKSA_REPLACE,
54 	PMKSA_EXPIRE,
55 };
56 
57 #if defined(IEEE8021X_EAPOL) && !defined(CONFIG_NO_WPA)
58 
59 struct rsn_pmksa_cache *
60 pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
61 				 void *ctx, enum pmksa_free_reason reason),
62 		 bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
63 				       void *ctx),
64 		 void *ctx, struct wpa_sm *sm);
65 void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa);
66 struct rsn_pmksa_cache_entry * pmksa_cache_get(struct rsn_pmksa_cache *pmksa,
67 					       const u8 *aa, const u8 *pmkid,
68 					       const void *network_ctx,
69 					       int akmp);
70 int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf, size_t len);
71 struct rsn_pmksa_cache_entry * pmksa_cache_head(struct rsn_pmksa_cache *pmksa);
72 struct rsn_pmksa_cache_entry *
73 pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
74 		const u8 *pmkid, const u8 *kck, size_t kck_len,
75 		const u8 *aa, const u8 *spa, void *network_ctx, int akmp,
76 		const u8 *cache_id);
77 struct rsn_pmksa_cache_entry *
78 pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa,
79 		      struct rsn_pmksa_cache_entry *entry);
80 struct rsn_pmksa_cache_entry * pmksa_cache_get_current(struct wpa_sm *sm);
81 void pmksa_cache_clear_current(struct wpa_sm *sm);
82 int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
83 			    const u8 *bssid, void *network_ctx,
84 			    int try_opportunistic, const u8 *fils_cache_id,
85 			    int akmp);
86 struct rsn_pmksa_cache_entry *
87 pmksa_cache_get_opportunistic(struct rsn_pmksa_cache *pmksa,
88 			      void *network_ctx, const u8 *aa, int akmp);
89 void pmksa_cache_flush(struct rsn_pmksa_cache *pmksa, void *network_ctx,
90 		       const u8 *pmk, size_t pmk_len, bool external_only);
91 void pmksa_cache_reconfig(struct rsn_pmksa_cache *pmksa);
92 
93 #else /* IEEE8021X_EAPOL */
94 
95 static inline struct rsn_pmksa_cache *
96 pmksa_cache_init(void (*free_cb)(struct rsn_pmksa_cache_entry *entry,
97 				 void *ctx, enum pmksa_free_reason reason),
98 		 bool (*is_current_cb)(struct rsn_pmksa_cache_entry *entry,
99 				       void *ctx),
100 		 void *ctx, struct wpa_sm *sm)
101 {
102 	return (void *) -1;
103 }
104 
105 static inline void pmksa_cache_deinit(struct rsn_pmksa_cache *pmksa)
106 {
107 }
108 
109 static inline struct rsn_pmksa_cache_entry *
110 pmksa_cache_get(struct rsn_pmksa_cache *pmksa, const u8 *aa, const u8 *pmkid,
111 		const void *network_ctx, int akmp)
112 {
113 	return NULL;
114 }
115 
116 static inline struct rsn_pmksa_cache_entry *
117 pmksa_cache_get_current(struct wpa_sm *sm)
118 {
119 	return NULL;
120 }
121 
122 static inline int pmksa_cache_list(struct rsn_pmksa_cache *pmksa, char *buf,
123 				   size_t len)
124 {
125 	return -1;
126 }
127 
128 static inline struct rsn_pmksa_cache_entry *
129 pmksa_cache_head(struct rsn_pmksa_cache *pmksa)
130 {
131 	return NULL;
132 }
133 
134 static inline struct rsn_pmksa_cache_entry *
135 pmksa_cache_add_entry(struct rsn_pmksa_cache *pmksa,
136 		      struct rsn_pmksa_cache_entry *entry)
137 {
138 	return NULL;
139 }
140 
141 static inline struct rsn_pmksa_cache_entry *
142 pmksa_cache_add(struct rsn_pmksa_cache *pmksa, const u8 *pmk, size_t pmk_len,
143 		const u8 *pmkid, const u8 *kck, size_t kck_len,
144 		const u8 *aa, const u8 *spa, void *network_ctx, int akmp,
145 		const u8 *cache_id)
146 {
147 	return NULL;
148 }
149 
150 static inline void pmksa_cache_clear_current(struct wpa_sm *sm)
151 {
152 }
153 
154 static inline int pmksa_cache_set_current(struct wpa_sm *sm, const u8 *pmkid,
155 					  const u8 *bssid,
156 					  void *network_ctx,
157 					  int try_opportunistic,
158 					  const u8 *fils_cache_id,
159 					  int akmp)
160 {
161 	return -1;
162 }
163 
164 static inline void pmksa_cache_flush(struct rsn_pmksa_cache *pmksa,
165 				     void *network_ctx,
166 				     const u8 *pmk, size_t pmk_len,
167 				     bool external_only)
168 {
169 }
170 
171 static inline void pmksa_cache_reconfig(struct rsn_pmksa_cache *pmksa)
172 {
173 }
174 
175 #endif /* IEEE8021X_EAPOL */
176 
177 #endif /* PMKSA_CACHE_H */
178