1 /* 2 * Wi-Fi Protected Setup - internal definitions 3 * Copyright (c) 2008-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 WPS_I_H 10 #define WPS_I_H 11 12 #include "wps.h" 13 #include "wps_attr_parse.h" 14 15 #ifdef CONFIG_WPS_NFC 16 struct wps_nfc_pw_token; 17 #endif 18 /** 19 * struct wps_data - WPS registration protocol data 20 * 21 * This data is stored at the EAP-WSC server/peer method and it is kept for a 22 * single registration protocol run. 23 */ 24 struct wps_data { 25 /** 26 * wps - Pointer to long term WPS context 27 */ 28 struct wps_context *wps; 29 30 /** 31 * registrar - Whether this end is a Registrar 32 */ 33 int registrar; 34 35 /** 36 * er - Whether the local end is an external registrar 37 */ 38 int er; 39 40 enum { 41 /* Enrollee states */ 42 SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7, 43 RECV_M8, RECEIVED_M2D, WPS_MSG_DONE, RECV_ACK, WPS_FINISHED, 44 SEND_WSC_NACK, 45 46 /* Registrar states */ 47 RECV_M1, SEND_M2, RECV_M3, SEND_M4, RECV_M5, SEND_M6, 48 RECV_M7, SEND_M8, RECV_DONE, SEND_M2D, RECV_M2D_ACK 49 } state; 50 51 u8 uuid_e[WPS_UUID_LEN]; 52 u8 uuid_r[WPS_UUID_LEN]; 53 u8 mac_addr_e[ETH_ALEN]; 54 u8 nonce_e[WPS_NONCE_LEN]; 55 u8 nonce_r[WPS_NONCE_LEN]; 56 u8 psk1[WPS_PSK_LEN]; 57 u8 psk2[WPS_PSK_LEN]; 58 u8 snonce[2 * WPS_SECRET_NONCE_LEN]; 59 u8 peer_hash1[WPS_HASH_LEN]; 60 u8 peer_hash2[WPS_HASH_LEN]; 61 62 struct wpabuf *dh_privkey; 63 struct wpabuf *dh_pubkey_e; 64 struct wpabuf *dh_pubkey_r; 65 u8 authkey[WPS_AUTHKEY_LEN]; 66 u8 keywrapkey[WPS_KEYWRAPKEY_LEN]; 67 u8 emsk[WPS_EMSK_LEN]; 68 69 struct wpabuf *last_msg; 70 71 u8 *dev_password; 72 size_t dev_password_len; 73 u16 dev_pw_id; 74 int pbc; 75 u8 *alt_dev_password; 76 size_t alt_dev_password_len; 77 u16 alt_dev_pw_id; 78 79 u8 peer_pubkey_hash[WPS_OOB_PUBKEY_HASH_LEN]; 80 int peer_pubkey_hash_set; 81 82 /** 83 * request_type - Request Type attribute from (Re)AssocReq 84 */ 85 u8 request_type; 86 87 /** 88 * encr_type - Available encryption types 89 */ 90 u16 encr_type; 91 92 /** 93 * auth_type - Available authentication types 94 */ 95 u16 auth_type; 96 97 u8 *new_psk; 98 size_t new_psk_len; 99 100 int wps_pin_revealed; 101 struct wps_credential cred; 102 103 struct wps_device_data peer_dev; 104 105 /** 106 * config_error - Configuration Error value to be used in NACK 107 */ 108 u16 config_error; 109 u16 error_indication; 110 111 int ext_reg; 112 int int_reg; 113 114 struct wps_credential *new_ap_settings; 115 116 void *dh_ctx; 117 118 void (*ap_settings_cb)(void *ctx, const struct wps_credential *cred); 119 void *ap_settings_cb_ctx; 120 121 struct wps_credential *use_cred; 122 123 int use_psk_key; 124 u8 p2p_dev_addr[ETH_ALEN]; /* P2P Device Address of the client or 125 * 00:00:00:00:00:00 if not a P2p client */ 126 int pbc_in_m1; 127 128 struct wps_nfc_pw_token *nfc_pw_token; 129 130 int multi_ap_backhaul_sta; 131 }; 132 133 134 /* wps_common.c */ 135 void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len, 136 const char *label, u8 *res, size_t res_len); 137 int wps_derive_keys(struct wps_data *wps); 138 int wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd, 139 size_t dev_passwd_len); 140 struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr, 141 size_t encr_len); 142 void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg, 143 u16 config_error, u16 error_indication, const u8 *mac_addr); 144 void wps_success_event(struct wps_context *wps, const u8 *mac_addr); 145 void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part, 146 const u8 *mac_addr); 147 void wps_pbc_overlap_event(struct wps_context *wps); 148 void wps_selected_registrar_timeout_event(struct wps_context *wps); 149 void wps_pbc_timeout_event(struct wps_context *wps); 150 void wps_pbc_active_event(struct wps_context *wps); 151 void wps_pbc_disable_event(struct wps_context *wps); 152 153 struct wpabuf * wps_build_wsc_ack(struct wps_data *wps); 154 struct wpabuf * wps_build_wsc_nack(struct wps_data *wps); 155 156 /* wps_attr_build.c */ 157 int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg); 158 int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type); 159 int wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type); 160 int wps_build_config_methods(struct wpabuf *msg, u16 methods); 161 int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid); 162 int wps_build_dev_password_id(struct wpabuf *msg, u16 id); 163 int wps_build_config_error(struct wpabuf *msg, u16 err); 164 int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg); 165 int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg); 166 int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg, 167 struct wpabuf *plain); 168 int wps_build_version(struct wpabuf *msg); 169 int wps_build_wfa_ext(struct wpabuf *msg, int req_to_enroll, 170 const u8 *auth_macs, size_t auth_macs_count, 171 u8 multi_ap_subelem); 172 int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type); 173 int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg); 174 int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg); 175 int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg); 176 int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg); 177 int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg); 178 int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg); 179 int wps_build_oob_dev_pw(struct wpabuf *msg, u16 dev_pw_id, 180 const struct wpabuf *pubkey, const u8 *dev_pw, 181 size_t dev_pw_len); 182 struct wpabuf * wps_ie_encapsulate(struct wpabuf *data); 183 int wps_build_mac_addr(struct wpabuf *msg, const u8 *addr); 184 int wps_build_rf_bands_attr(struct wpabuf *msg, u8 rf_bands); 185 int wps_build_ap_channel(struct wpabuf *msg, u16 ap_channel); 186 187 /* wps_attr_process.c */ 188 int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator, 189 const struct wpabuf *msg); 190 int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg, 191 const u8 *key_wrap_auth); 192 int wps_process_cred(struct wps_parse_attr *attr, 193 struct wps_credential *cred); 194 int wps_process_ap_settings(struct wps_parse_attr *attr, 195 struct wps_credential *cred); 196 197 /* wps_enrollee.c */ 198 struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps, 199 enum wsc_op_code *op_code); 200 enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps, 201 enum wsc_op_code op_code, 202 const struct wpabuf *msg); 203 204 /* wps_registrar.c */ 205 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps, 206 enum wsc_op_code *op_code); 207 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps, 208 enum wsc_op_code op_code, 209 const struct wpabuf *msg); 210 int wps_build_cred(struct wps_data *wps, struct wpabuf *msg); 211 int wps_device_store(struct wps_registrar *reg, 212 struct wps_device_data *dev, const u8 *uuid); 213 void wps_registrar_selected_registrar_changed(struct wps_registrar *reg, 214 u16 dev_pw_id); 215 const u8 * wps_authorized_macs(struct wps_registrar *reg, size_t *count); 216 int wps_registrar_pbc_overlap(struct wps_registrar *reg, 217 const u8 *addr, const u8 *uuid_e); 218 #ifdef CONFIG_WPS_NFC 219 220 void wps_registrar_remove_nfc_pw_token(struct wps_registrar *reg, 221 struct wps_nfc_pw_token *token); 222 #endif 223 int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr, 224 const u8 *p2p_dev_addr, const u8 *psk, size_t psk_len); 225 226 #endif /* WPS_I_H */ 227