1 /* 2 * wpa_supplicant - WPA definitions 3 * Copyright (c) 2003-2006, Jouni Malinen <j (at) w1.fi> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation. 8 * 9 * Alternatively, this software may be distributed under the terms of BSD 10 * license. 11 * 12 * See README and COPYING for more details. 13 */ 14 15 #ifndef WPA_H 16 #define WPA_H 17 18 #include "defs.h" 19 #include "wpa_common.h" 20 21 #ifndef BIT 22 #define BIT(n) (1 << (n)) 23 #endif 24 25 #define WPA_CAPABILITY_PREAUTH BIT(0) 26 #define WPA_CAPABILITY_MGMT_FRAME_PROTECTION BIT(6) 27 #define WPA_CAPABILITY_PEERKEY_ENABLED BIT(9) 28 29 #define GENERIC_INFO_ELEM 0xdd 30 #define RSN_INFO_ELEM 0x30 31 32 enum { 33 REASON_UNSPECIFIED = 1, 34 REASON_DEAUTH_LEAVING = 3, 35 REASON_INVALID_IE = 13, 36 REASON_MICHAEL_MIC_FAILURE = 14, 37 REASON_4WAY_HANDSHAKE_TIMEOUT = 15, 38 REASON_GROUP_KEY_UPDATE_TIMEOUT = 16, 39 REASON_IE_IN_4WAY_DIFFERS = 17, 40 REASON_GROUP_CIPHER_NOT_VALID = 18, 41 REASON_PAIRWISE_CIPHER_NOT_VALID = 19, 42 REASON_AKMP_NOT_VALID = 20, 43 REASON_UNSUPPORTED_RSN_IE_VERSION = 21, 44 REASON_INVALID_RSN_IE_CAPAB = 22, 45 REASON_IEEE_802_1X_AUTH_FAILED = 23, 46 REASON_CIPHER_SUITE_REJECTED = 24 47 }; 48 49 #define PMKID_LEN 16 50 51 52 struct wpa_sm; 53 struct wpa_ssid; 54 struct eapol_sm; 55 struct wpa_config_blob; 56 57 struct wpa_sm_ctx { 58 void *ctx; /* pointer to arbitrary upper level context */ 59 60 void (*set_state)(void *ctx, wpa_states state); 61 wpa_states (*get_state)(void *ctx); 62 void (*deauthenticate)(void * ctx, int reason_code); 63 void (*disassociate)(void *ctx, int reason_code); 64 int (*set_key)(void *ctx, wpa_alg alg, 65 const u8 *addr, int key_idx, int set_tx, 66 const u8 *seq, size_t seq_len, 67 const u8 *key, size_t key_len); 68 void (*scan)(void *eloop_ctx, void *timeout_ctx); 69 struct wpa_ssid * (*get_ssid)(void *ctx); 70 int (*get_bssid)(void *ctx, u8 *bssid); 71 int (*ether_send)(void *ctx, const u8 *dest, u16 proto, const u8 *buf, 72 size_t len); 73 int (*get_beacon_ie)(void *ctx); 74 void (*cancel_auth_timeout)(void *ctx); 75 u8 * (*alloc_eapol)(void *ctx, u8 type, const void *data, u16 data_len, 76 size_t *msg_len, void **data_pos); 77 int (*add_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid); 78 int (*remove_pmkid)(void *ctx, const u8 *bssid, const u8 *pmkid); 79 void (*set_config_blob)(void *ctx, struct wpa_config_blob *blob); 80 const struct wpa_config_blob * (*get_config_blob)(void *ctx, 81 const char *name); 82 int (*mlme_setprotection)(void *ctx, const u8 *addr, 83 int protection_type, int key_type); 84 }; 85 86 87 enum wpa_sm_conf_params { 88 RSNA_PMK_LIFETIME /* dot11RSNAConfigPMKLifetime */, 89 RSNA_PMK_REAUTH_THRESHOLD /* dot11RSNAConfigPMKReauthThreshold */, 90 RSNA_SA_TIMEOUT /* dot11RSNAConfigSATimeout */, 91 WPA_PARAM_PROTO, 92 WPA_PARAM_PAIRWISE, 93 WPA_PARAM_GROUP, 94 WPA_PARAM_KEY_MGMT, 95 WPA_PARAM_MGMT_GROUP 96 }; 97 98 struct wpa_ie_data { 99 int proto; 100 int pairwise_cipher; 101 int group_cipher; 102 int key_mgmt; 103 int capabilities; 104 int num_pmkid; 105 const u8 *pmkid; 106 int mgmt_group_cipher; 107 }; 108 109 #ifndef CONFIG_NO_WPA 110 111 struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx); 112 void wpa_sm_deinit(struct wpa_sm *sm); 113 void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid); 114 void wpa_sm_notify_disassoc(struct wpa_sm *sm); 115 void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, size_t pmk_len); 116 void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm); 117 void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth); 118 void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx); 119 void wpa_sm_set_config(struct wpa_sm *sm, struct wpa_ssid *config); 120 void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr); 121 void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname, 122 const char *bridge_ifname); 123 void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol); 124 int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len); 125 int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie, 126 size_t *wpa_ie_len); 127 int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len); 128 int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, size_t len); 129 int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen); 130 131 int wpa_sm_set_param(struct wpa_sm *sm, enum wpa_sm_conf_params param, 132 unsigned int value); 133 unsigned int wpa_sm_get_param(struct wpa_sm *sm, 134 enum wpa_sm_conf_params param); 135 136 int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen, 137 int verbose); 138 139 void wpa_sm_key_request(struct wpa_sm *sm, int error, int pairwise); 140 141 int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer); 142 143 int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len, 144 struct wpa_ie_data *data); 145 146 void wpa_sm_aborted_cached(struct wpa_sm *sm); 147 int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr, 148 const u8 *buf, size_t len); 149 int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data); 150 151 #else /* CONFIG_NO_WPA */ 152 153 static inline struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx) 154 { 155 return (struct wpa_sm *) 1; 156 } 157 158 static inline void wpa_sm_deinit(struct wpa_sm *sm) 159 { 160 } 161 162 static inline void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid) 163 { 164 } 165 166 static inline void wpa_sm_notify_disassoc(struct wpa_sm *sm) 167 { 168 } 169 170 static inline void wpa_sm_set_pmk(struct wpa_sm *sm, const u8 *pmk, 171 size_t pmk_len) 172 { 173 } 174 175 static inline void wpa_sm_set_pmk_from_pmksa(struct wpa_sm *sm) 176 { 177 } 178 179 static inline void wpa_sm_set_fast_reauth(struct wpa_sm *sm, int fast_reauth) 180 { 181 } 182 183 static inline void wpa_sm_set_scard_ctx(struct wpa_sm *sm, void *scard_ctx) 184 { 185 } 186 187 static inline void wpa_sm_set_config(struct wpa_sm *sm, 188 struct wpa_ssid *config) 189 { 190 } 191 192 static inline void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr) 193 { 194 } 195 196 static inline void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname, 197 const char *bridge_ifname) 198 { 199 } 200 201 static inline void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol) 202 { 203 } 204 205 static inline int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, 206 size_t len) 207 { 208 return -1; 209 } 210 211 static inline int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, 212 u8 *wpa_ie, 213 size_t *wpa_ie_len) 214 { 215 return -1; 216 } 217 218 static inline int wpa_sm_set_ap_wpa_ie(struct wpa_sm *sm, const u8 *ie, 219 size_t len) 220 { 221 return -1; 222 } 223 224 static inline int wpa_sm_set_ap_rsn_ie(struct wpa_sm *sm, const u8 *ie, 225 size_t len) 226 { 227 return -1; 228 } 229 230 static inline int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen) 231 { 232 return 0; 233 } 234 235 static inline int wpa_sm_set_param(struct wpa_sm *sm, 236 enum wpa_sm_conf_params param, 237 unsigned int value) 238 { 239 return -1; 240 } 241 242 static inline unsigned int wpa_sm_get_param(struct wpa_sm *sm, 243 enum wpa_sm_conf_params param) 244 { 245 return 0; 246 } 247 248 static inline int wpa_sm_get_status(struct wpa_sm *sm, char *buf, 249 size_t buflen, int verbose) 250 { 251 return 0; 252 } 253 254 static inline void wpa_sm_key_request(struct wpa_sm *sm, int error, 255 int pairwise) 256 { 257 } 258 259 static inline int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer) 260 { 261 return -1; 262 } 263 264 static inline int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len, 265 struct wpa_ie_data *data) 266 { 267 return -1; 268 } 269 270 static inline void wpa_sm_aborted_cached(struct wpa_sm *sm) 271 { 272 } 273 274 static inline int wpa_sm_rx_eapol(struct wpa_sm *sm, const u8 *src_addr, 275 const u8 *buf, size_t len) 276 { 277 return -1; 278 } 279 280 static inline int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, 281 struct wpa_ie_data *data) 282 { 283 return -1; 284 } 285 286 #endif /* CONFIG_NO_WPA */ 287 288 #endif /* WPA_H */ 289