1 /* 2 * Internal WPA/RSN supplicant state machine definitions 3 * Copyright (c) 2004-2010, Jouni Malinen <j@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_I_H 16 #define WPA_I_H 17 18 struct install_key { 19 int mic_errors_seen; /* Michael MIC errors with the current PTK */ 20 int keys_cleared; 21 enum wpa_alg alg; 22 u8 addr[ETH_ALEN]; 23 int key_idx; 24 int set_tx; 25 u8 seq[10]; 26 u8 key[32]; 27 }; 28 29 /** 30 * struct wpa_sm - Internal WPA state machine data 31 */ 32 struct wpa_sm { 33 u8 pmk[PMK_LEN_MAX]; 34 size_t pmk_len; 35 36 struct wpa_ptk ptk, tptk; 37 int ptk_set, tptk_set; 38 u8 snonce[WPA_NONCE_LEN]; 39 u8 anonce[WPA_NONCE_LEN]; /* ANonce from the last 1/4 msg */ 40 int renew_snonce; 41 u8 rx_replay_counter[WPA_REPLAY_COUNTER_LEN]; 42 int rx_replay_counter_set; 43 u8 request_counter[WPA_REPLAY_COUNTER_LEN]; 44 struct rsn_pmksa_cache *pmksa; /* PMKSA cache */ 45 struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */ 46 47 unsigned int pairwise_cipher; 48 unsigned int group_cipher; 49 unsigned int key_mgmt; 50 unsigned int mgmt_group_cipher; 51 void *network_ctx; 52 53 int rsn_enabled; /* Whether RSN is enabled in configuration */ 54 55 int countermeasures; /*TKIP countermeasures state flag, 1:in countermeasures state*/ 56 ETSTimer cm_timer; 57 58 u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */ 59 size_t assoc_wpa_ie_len; 60 61 u8 eapol_version; 62 63 int wpa_ptk_rekey; 64 u8 own_addr[ETH_ALEN]; 65 66 u8 bssid[ETH_ALEN]; 67 68 unsigned int proto; 69 enum wpa_states wpa_state; 70 71 u8 *ap_wpa_ie, *ap_rsn_ie; 72 size_t ap_wpa_ie_len, ap_rsn_ie_len; 73 74 bool key_install; 75 76 struct install_key install_ptk; 77 struct install_key install_gtk; 78 79 void (* sendto) (void *buffer, uint16_t len); 80 void (*config_assoc_ie) (u8 proto, u8 *assoc_buf, u32 assoc_wpa_ie_len); 81 void (*install_ppkey) (enum wpa_alg alg, u8 *addr, int key_idx, int set_tx, 82 u8 *seq, unsigned int seq_len, u8 *key, unsigned int key_len, enum key_flag key_flag); 83 int (*get_ppkey) (uint8_t *ifx, int *alg, uint8_t *addr, int *key_idx, 84 uint8_t *key, size_t key_len, enum key_flag key_flag); 85 void (*wpa_deauthenticate)(u8 reason_code); 86 void (*wpa_neg_complete)(void); 87 struct wpa_gtk_data gd; //used for calllback save param 88 u16 key_info; //used for txcallback param 89 u16 txcb_flags; 90 bool ap_notify_completed_rsne; 91 wifi_pmf_config_t pmf_cfg; 92 u8 eapol1_count; 93 struct rsn_sppamsdu_sup spp_sup; 94 }; 95 96 /** 97 * set_key - Configure encryption key 98 * @ifname: Interface name (for multi-SSID/VLAN support) 99 * @priv: private driver interface data 100 * @alg: encryption algorithm (%WPA_ALG_NONE, %WPA_ALG_WEP, 101 * %WPA_ALG_TKIP, %WPA_ALG_CCMP, %WPA_ALG_IGTK, %WPA_ALG_PMK); 102 * %WPA_ALG_NONE clears the key. 103 * @addr: address of the peer STA or ff:ff:ff:ff:ff:ff for 104 * broadcast/default keys 105 * @key_idx: key index (0..3), usually 0 for unicast keys; 0..4095 for 106 * IGTK 107 * @set_tx: configure this key as the default Tx key (only used when 108 * driver does not support separate unicast/individual key 109 * @seq: sequence number/packet number, seq_len octets, the next 110 * packet number to be used for in replay protection; configured 111 * for Rx keys (in most cases, this is only used with broadcast 112 * keys and set to zero for unicast keys) 113 * @seq_len: length of the seq, depends on the algorithm: 114 * TKIP: 6 octets, CCMP: 6 octets, IGTK: 6 octets 115 * @key: key buffer; TKIP: 16-byte temporal key, 8-byte Tx Mic key, 116 * 8-byte Rx Mic Key 117 * @key_len: length of the key buffer in octets (WEP: 5 or 13, 118 * TKIP: 32, CCMP: 16, IGTK: 16) 119 * 120 * Returns: 0 on success, -1 on failure 121 * 122 * Configure the given key for the kernel driver. If the driver 123 * supports separate individual keys (4 default keys + 1 individual), 124 * addr can be used to determine whether the key is default or 125 * individual. If only 4 keys are supported, the default key with key 126 * index 0 is used as the individual key. STA must be configured to use 127 * it as the default Tx key (set_tx is set) and accept Rx for all the 128 * key indexes. In most cases, WPA uses only key indexes 1 and 2 for 129 * broadcast keys, so key index 0 is available for this kind of 130 * configuration. 131 * 132 * Please note that TKIP keys include separate TX and RX MIC keys and 133 * some drivers may expect them in different order than wpa_supplicant 134 * is using. If the TX/RX keys are swapped, all TKIP encrypted packets 135 * will tricker Michael MIC errors. This can be fixed by changing the 136 * order of MIC keys by swapping te bytes 16..23 and 24..31 of the key 137 * in driver_*.c set_key() implementation, see driver_ndis.c for an 138 * example on how this can be done. 139 */ 140 141 142 typedef void (* WPA_SEND_FUNC)(void *buffer, u16 len); 143 144 typedef void (* WPA_SET_ASSOC_IE)(u8 proto, u8 *assoc_buf, u32 assoc_wpa_ie_len); 145 146 typedef void (*WPA_INSTALL_KEY) (enum wpa_alg alg, u8 *addr, int key_idx, int set_tx, 147 u8 *seq, size_t seq_len, u8 *key, size_t key_len, enum key_flag key_flag); 148 149 typedef int (*WPA_GET_KEY) (u8 *ifx, int *alg, u8 *addt, int *keyidx, u8 *key, size_t key_len, enum key_flag key_flag); 150 151 typedef void (*WPA_DEAUTH_FUNC)(u8 reason_code); 152 153 typedef void (*WPA_NEG_COMPLETE)(void); 154 155 bool wpa_sm_init(char * payload, WPA_SEND_FUNC snd_func, \ 156 WPA_SET_ASSOC_IE set_assoc_ie_func, \ 157 WPA_INSTALL_KEY ppinstallkey, \ 158 WPA_GET_KEY ppgetkey, \ 159 WPA_DEAUTH_FUNC wpa_deauth, \ 160 WPA_NEG_COMPLETE wpa_neg_complete); 161 162 void wpa_sm_deinit(void); 163 164 void eapol_txcb(void *eb); 165 166 void wpa_set_profile(u32 wpa_proto, u8 auth_mode); 167 168 int wpa_set_bss(char *macddr, char * bssid, u8 pairwise_cipher, u8 group_cipher, char *passphrase, u8 *ssid, size_t ssid_len); 169 170 int wpa_sm_rx_eapol(u8 *src_addr, u8 *buf, u32 len); 171 #endif /* WPA_I_H */ 172