xref: /dflybsd-src/contrib/wpa_supplicant/src/wps/wps_i.h (revision 3a84a4273475ed07d0ab1c2dfeffdfedef35d9cd)
16d49e1aeSJan Lentfer /*
26d49e1aeSJan Lentfer  * Wi-Fi Protected Setup - internal definitions
33ff40c12SJohn Marino  * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
46d49e1aeSJan Lentfer  *
53ff40c12SJohn Marino  * This software may be distributed under the terms of the BSD license.
63ff40c12SJohn Marino  * See README for more details.
76d49e1aeSJan Lentfer  */
86d49e1aeSJan Lentfer 
96d49e1aeSJan Lentfer #ifndef WPS_I_H
106d49e1aeSJan Lentfer #define WPS_I_H
116d49e1aeSJan Lentfer 
126d49e1aeSJan Lentfer #include "wps.h"
133ff40c12SJohn Marino #include "wps_attr_parse.h"
143ff40c12SJohn Marino 
153ff40c12SJohn Marino struct wps_nfc_pw_token;
166d49e1aeSJan Lentfer 
176d49e1aeSJan Lentfer /**
186d49e1aeSJan Lentfer  * struct wps_data - WPS registration protocol data
196d49e1aeSJan Lentfer  *
206d49e1aeSJan Lentfer  * This data is stored at the EAP-WSC server/peer method and it is kept for a
216d49e1aeSJan Lentfer  * single registration protocol run.
226d49e1aeSJan Lentfer  */
236d49e1aeSJan Lentfer struct wps_data {
246d49e1aeSJan Lentfer 	/**
256d49e1aeSJan Lentfer 	 * wps - Pointer to long term WPS context
266d49e1aeSJan Lentfer 	 */
276d49e1aeSJan Lentfer 	struct wps_context *wps;
286d49e1aeSJan Lentfer 
296d49e1aeSJan Lentfer 	/**
306d49e1aeSJan Lentfer 	 * registrar - Whether this end is a Registrar
316d49e1aeSJan Lentfer 	 */
326d49e1aeSJan Lentfer 	int registrar;
336d49e1aeSJan Lentfer 
343ff40c12SJohn Marino 	/**
353ff40c12SJohn Marino 	 * er - Whether the local end is an external registrar
363ff40c12SJohn Marino 	 */
373ff40c12SJohn Marino 	int er;
383ff40c12SJohn Marino 
396d49e1aeSJan Lentfer 	enum {
406d49e1aeSJan Lentfer 		/* Enrollee states */
416d49e1aeSJan Lentfer 		SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7,
426d49e1aeSJan Lentfer 		RECV_M8, RECEIVED_M2D, WPS_MSG_DONE, RECV_ACK, WPS_FINISHED,
436d49e1aeSJan Lentfer 		SEND_WSC_NACK,
446d49e1aeSJan Lentfer 
456d49e1aeSJan Lentfer 		/* Registrar states */
466d49e1aeSJan Lentfer 		RECV_M1, SEND_M2, RECV_M3, SEND_M4, RECV_M5, SEND_M6,
476d49e1aeSJan Lentfer 		RECV_M7, SEND_M8, RECV_DONE, SEND_M2D, RECV_M2D_ACK
486d49e1aeSJan Lentfer 	} state;
496d49e1aeSJan Lentfer 
506d49e1aeSJan Lentfer 	u8 uuid_e[WPS_UUID_LEN];
516d49e1aeSJan Lentfer 	u8 uuid_r[WPS_UUID_LEN];
526d49e1aeSJan Lentfer 	u8 mac_addr_e[ETH_ALEN];
536d49e1aeSJan Lentfer 	u8 nonce_e[WPS_NONCE_LEN];
546d49e1aeSJan Lentfer 	u8 nonce_r[WPS_NONCE_LEN];
556d49e1aeSJan Lentfer 	u8 psk1[WPS_PSK_LEN];
566d49e1aeSJan Lentfer 	u8 psk2[WPS_PSK_LEN];
576d49e1aeSJan Lentfer 	u8 snonce[2 * WPS_SECRET_NONCE_LEN];
586d49e1aeSJan Lentfer 	u8 peer_hash1[WPS_HASH_LEN];
596d49e1aeSJan Lentfer 	u8 peer_hash2[WPS_HASH_LEN];
606d49e1aeSJan Lentfer 
616d49e1aeSJan Lentfer 	struct wpabuf *dh_privkey;
626d49e1aeSJan Lentfer 	struct wpabuf *dh_pubkey_e;
636d49e1aeSJan Lentfer 	struct wpabuf *dh_pubkey_r;
646d49e1aeSJan Lentfer 	u8 authkey[WPS_AUTHKEY_LEN];
656d49e1aeSJan Lentfer 	u8 keywrapkey[WPS_KEYWRAPKEY_LEN];
666d49e1aeSJan Lentfer 	u8 emsk[WPS_EMSK_LEN];
676d49e1aeSJan Lentfer 
686d49e1aeSJan Lentfer 	struct wpabuf *last_msg;
696d49e1aeSJan Lentfer 
706d49e1aeSJan Lentfer 	u8 *dev_password;
716d49e1aeSJan Lentfer 	size_t dev_password_len;
726d49e1aeSJan Lentfer 	u16 dev_pw_id;
736d49e1aeSJan Lentfer 	int pbc;
743ff40c12SJohn Marino 	u8 *alt_dev_password;
753ff40c12SJohn Marino 	size_t alt_dev_password_len;
763ff40c12SJohn Marino 	u16 alt_dev_pw_id;
773ff40c12SJohn Marino 
783ff40c12SJohn Marino 	u8 peer_pubkey_hash[WPS_OOB_PUBKEY_HASH_LEN];
793ff40c12SJohn Marino 	int peer_pubkey_hash_set;
806d49e1aeSJan Lentfer 
816d49e1aeSJan Lentfer 	/**
826d49e1aeSJan Lentfer 	 * request_type - Request Type attribute from (Re)AssocReq
836d49e1aeSJan Lentfer 	 */
846d49e1aeSJan Lentfer 	u8 request_type;
856d49e1aeSJan Lentfer 
866d49e1aeSJan Lentfer 	/**
876d49e1aeSJan Lentfer 	 * encr_type - Available encryption types
886d49e1aeSJan Lentfer 	 */
896d49e1aeSJan Lentfer 	u16 encr_type;
906d49e1aeSJan Lentfer 
916d49e1aeSJan Lentfer 	/**
926d49e1aeSJan Lentfer 	 * auth_type - Available authentication types
936d49e1aeSJan Lentfer 	 */
946d49e1aeSJan Lentfer 	u16 auth_type;
956d49e1aeSJan Lentfer 
966d49e1aeSJan Lentfer 	u8 *new_psk;
976d49e1aeSJan Lentfer 	size_t new_psk_len;
986d49e1aeSJan Lentfer 
996d49e1aeSJan Lentfer 	int wps_pin_revealed;
1006d49e1aeSJan Lentfer 	struct wps_credential cred;
1016d49e1aeSJan Lentfer 
1026d49e1aeSJan Lentfer 	struct wps_device_data peer_dev;
1036d49e1aeSJan Lentfer 
1046d49e1aeSJan Lentfer 	/**
1056d49e1aeSJan Lentfer 	 * config_error - Configuration Error value to be used in NACK
1066d49e1aeSJan Lentfer 	 */
1076d49e1aeSJan Lentfer 	u16 config_error;
1083ff40c12SJohn Marino 	u16 error_indication;
1096d49e1aeSJan Lentfer 
1106d49e1aeSJan Lentfer 	int ext_reg;
1113ff40c12SJohn Marino 	int int_reg;
1123ff40c12SJohn Marino 
1133ff40c12SJohn Marino 	struct wps_credential *new_ap_settings;
1143ff40c12SJohn Marino 
1153ff40c12SJohn Marino 	void *dh_ctx;
1163ff40c12SJohn Marino 
1173ff40c12SJohn Marino 	void (*ap_settings_cb)(void *ctx, const struct wps_credential *cred);
1183ff40c12SJohn Marino 	void *ap_settings_cb_ctx;
1193ff40c12SJohn Marino 
1203ff40c12SJohn Marino 	struct wps_credential *use_cred;
1213ff40c12SJohn Marino 
1223ff40c12SJohn Marino 	int use_psk_key;
1233ff40c12SJohn Marino 	u8 p2p_dev_addr[ETH_ALEN]; /* P2P Device Address of the client or
1243ff40c12SJohn Marino 				    * 00:00:00:00:00:00 if not a P2p client */
1253ff40c12SJohn Marino 	int pbc_in_m1;
1263ff40c12SJohn Marino 
1273ff40c12SJohn Marino 	struct wps_nfc_pw_token *nfc_pw_token;
128*a1157835SDaniel Fojt 
129*a1157835SDaniel Fojt 	int multi_ap_backhaul_sta;
1306d49e1aeSJan Lentfer };
1316d49e1aeSJan Lentfer 
1326d49e1aeSJan Lentfer 
1336d49e1aeSJan Lentfer /* wps_common.c */
1346d49e1aeSJan Lentfer void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
1356d49e1aeSJan Lentfer 	     const char *label, u8 *res, size_t res_len);
1366d49e1aeSJan Lentfer int wps_derive_keys(struct wps_data *wps);
137*a1157835SDaniel Fojt int wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
1386d49e1aeSJan Lentfer 		   size_t dev_passwd_len);
1396d49e1aeSJan Lentfer struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
1406d49e1aeSJan Lentfer 					  size_t encr_len);
1413ff40c12SJohn Marino void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg,
1423ff40c12SJohn Marino 		    u16 config_error, u16 error_indication, const u8 *mac_addr);
1433ff40c12SJohn Marino void wps_success_event(struct wps_context *wps, const u8 *mac_addr);
1443ff40c12SJohn Marino void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part,
1453ff40c12SJohn Marino 			     const u8 *mac_addr);
1466d49e1aeSJan Lentfer void wps_pbc_overlap_event(struct wps_context *wps);
1476d49e1aeSJan Lentfer void wps_pbc_timeout_event(struct wps_context *wps);
1483ff40c12SJohn Marino void wps_pbc_active_event(struct wps_context *wps);
1493ff40c12SJohn Marino void wps_pbc_disable_event(struct wps_context *wps);
1506d49e1aeSJan Lentfer 
1513ff40c12SJohn Marino struct wpabuf * wps_build_wsc_ack(struct wps_data *wps);
1523ff40c12SJohn Marino struct wpabuf * wps_build_wsc_nack(struct wps_data *wps);
1536d49e1aeSJan Lentfer 
1546d49e1aeSJan Lentfer /* wps_attr_build.c */
1556d49e1aeSJan Lentfer int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
1566d49e1aeSJan Lentfer int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
1573ff40c12SJohn Marino int wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type);
1586d49e1aeSJan Lentfer int wps_build_config_methods(struct wpabuf *msg, u16 methods);
1596d49e1aeSJan Lentfer int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
1606d49e1aeSJan Lentfer int wps_build_dev_password_id(struct wpabuf *msg, u16 id);
1616d49e1aeSJan Lentfer int wps_build_config_error(struct wpabuf *msg, u16 err);
1626d49e1aeSJan Lentfer int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
1636d49e1aeSJan Lentfer int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
1646d49e1aeSJan Lentfer int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
1656d49e1aeSJan Lentfer 			    struct wpabuf *plain);
1666d49e1aeSJan Lentfer int wps_build_version(struct wpabuf *msg);
1673ff40c12SJohn Marino int wps_build_wfa_ext(struct wpabuf *msg, int req_to_enroll,
168*a1157835SDaniel Fojt 		      const u8 *auth_macs, size_t auth_macs_count,
169*a1157835SDaniel Fojt 		      u8 multi_ap_subelem);
1706d49e1aeSJan Lentfer int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
1716d49e1aeSJan Lentfer int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
1726d49e1aeSJan Lentfer int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
1736d49e1aeSJan Lentfer int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
1746d49e1aeSJan Lentfer int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
1756d49e1aeSJan Lentfer int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
1766d49e1aeSJan Lentfer int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
1773ff40c12SJohn Marino int wps_build_oob_dev_pw(struct wpabuf *msg, u16 dev_pw_id,
1783ff40c12SJohn Marino 			 const struct wpabuf *pubkey, const u8 *dev_pw,
1793ff40c12SJohn Marino 			 size_t dev_pw_len);
1803ff40c12SJohn Marino struct wpabuf * wps_ie_encapsulate(struct wpabuf *data);
1813ff40c12SJohn Marino int wps_build_mac_addr(struct wpabuf *msg, const u8 *addr);
1823ff40c12SJohn Marino int wps_build_rf_bands_attr(struct wpabuf *msg, u8 rf_bands);
1833ff40c12SJohn Marino int wps_build_ap_channel(struct wpabuf *msg, u16 ap_channel);
1846d49e1aeSJan Lentfer 
1856d49e1aeSJan Lentfer /* wps_attr_process.c */
1866d49e1aeSJan Lentfer int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
1876d49e1aeSJan Lentfer 			      const struct wpabuf *msg);
1886d49e1aeSJan Lentfer int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
1896d49e1aeSJan Lentfer 			      const u8 *key_wrap_auth);
1906d49e1aeSJan Lentfer int wps_process_cred(struct wps_parse_attr *attr,
1916d49e1aeSJan Lentfer 		     struct wps_credential *cred);
1926d49e1aeSJan Lentfer int wps_process_ap_settings(struct wps_parse_attr *attr,
1936d49e1aeSJan Lentfer 			    struct wps_credential *cred);
1946d49e1aeSJan Lentfer 
1956d49e1aeSJan Lentfer /* wps_enrollee.c */
1966d49e1aeSJan Lentfer struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
1976d49e1aeSJan Lentfer 				     enum wsc_op_code *op_code);
1986d49e1aeSJan Lentfer enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
1996d49e1aeSJan Lentfer 					      enum wsc_op_code op_code,
2006d49e1aeSJan Lentfer 					      const struct wpabuf *msg);
2016d49e1aeSJan Lentfer 
2026d49e1aeSJan Lentfer /* wps_registrar.c */
2036d49e1aeSJan Lentfer struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
2046d49e1aeSJan Lentfer 				      enum wsc_op_code *op_code);
2056d49e1aeSJan Lentfer enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
2066d49e1aeSJan Lentfer 					       enum wsc_op_code op_code,
2076d49e1aeSJan Lentfer 					       const struct wpabuf *msg);
2083ff40c12SJohn Marino int wps_build_cred(struct wps_data *wps, struct wpabuf *msg);
2093ff40c12SJohn Marino int wps_device_store(struct wps_registrar *reg,
2103ff40c12SJohn Marino 		     struct wps_device_data *dev, const u8 *uuid);
2113ff40c12SJohn Marino void wps_registrar_selected_registrar_changed(struct wps_registrar *reg,
2123ff40c12SJohn Marino 					      u16 dev_pw_id);
2133ff40c12SJohn Marino const u8 * wps_authorized_macs(struct wps_registrar *reg, size_t *count);
2143ff40c12SJohn Marino int wps_registrar_pbc_overlap(struct wps_registrar *reg,
2153ff40c12SJohn Marino 			      const u8 *addr, const u8 *uuid_e);
2163ff40c12SJohn Marino void wps_registrar_remove_nfc_pw_token(struct wps_registrar *reg,
2173ff40c12SJohn Marino 				       struct wps_nfc_pw_token *token);
218*a1157835SDaniel Fojt int wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
219*a1157835SDaniel Fojt 		   const u8 *p2p_dev_addr, const u8 *psk, size_t psk_len);
2206d49e1aeSJan Lentfer 
2216d49e1aeSJan Lentfer #endif /* WPS_I_H */
222