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