xref: /freebsd/contrib/wpa/src/wps/wps.h (revision 325151a32e114f02699a301c1e74080e7c1f1a26)
139beb93cSSam Leffler /*
239beb93cSSam Leffler  * Wi-Fi Protected Setup
35b9c547cSRui Paulo  * Copyright (c) 2007-2013, Jouni Malinen <j@w1.fi>
439beb93cSSam Leffler  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
739beb93cSSam Leffler  */
839beb93cSSam Leffler 
939beb93cSSam Leffler #ifndef WPS_H
1039beb93cSSam Leffler #define WPS_H
1139beb93cSSam Leffler 
12*325151a3SRui Paulo #include "common/ieee802_11_defs.h"
1339beb93cSSam Leffler #include "wps_defs.h"
1439beb93cSSam Leffler 
1539beb93cSSam Leffler /**
1639beb93cSSam Leffler  * enum wsc_op_code - EAP-WSC OP-Code values
1739beb93cSSam Leffler  */
1839beb93cSSam Leffler enum wsc_op_code {
1939beb93cSSam Leffler 	WSC_UPnP = 0 /* No OP Code in UPnP transport */,
2039beb93cSSam Leffler 	WSC_Start = 0x01,
2139beb93cSSam Leffler 	WSC_ACK = 0x02,
2239beb93cSSam Leffler 	WSC_NACK = 0x03,
2339beb93cSSam Leffler 	WSC_MSG = 0x04,
2439beb93cSSam Leffler 	WSC_Done = 0x05,
2539beb93cSSam Leffler 	WSC_FRAG_ACK = 0x06
2639beb93cSSam Leffler };
2739beb93cSSam Leffler 
2839beb93cSSam Leffler struct wps_registrar;
2939beb93cSSam Leffler struct upnp_wps_device_sm;
30e28a4053SRui Paulo struct wps_er;
31f05cddf9SRui Paulo struct wps_parse_attr;
3239beb93cSSam Leffler 
3339beb93cSSam Leffler /**
3439beb93cSSam Leffler  * struct wps_credential - WPS Credential
3539beb93cSSam Leffler  * @ssid: SSID
3639beb93cSSam Leffler  * @ssid_len: Length of SSID
3739beb93cSSam Leffler  * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
3839beb93cSSam Leffler  * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
3939beb93cSSam Leffler  * @key_idx: Key index
4039beb93cSSam Leffler  * @key: Key
4139beb93cSSam Leffler  * @key_len: Key length in octets
423157ba21SRui Paulo  * @mac_addr: MAC address of the Credential receiver
4339beb93cSSam Leffler  * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
4439beb93cSSam Leffler  *	this may be %NULL, if not used
4539beb93cSSam Leffler  * @cred_attr_len: Length of cred_attr in octets
4639beb93cSSam Leffler  */
4739beb93cSSam Leffler struct wps_credential {
48*325151a3SRui Paulo 	u8 ssid[SSID_MAX_LEN];
4939beb93cSSam Leffler 	size_t ssid_len;
5039beb93cSSam Leffler 	u16 auth_type;
5139beb93cSSam Leffler 	u16 encr_type;
5239beb93cSSam Leffler 	u8 key_idx;
5339beb93cSSam Leffler 	u8 key[64];
5439beb93cSSam Leffler 	size_t key_len;
5539beb93cSSam Leffler 	u8 mac_addr[ETH_ALEN];
5639beb93cSSam Leffler 	const u8 *cred_attr;
5739beb93cSSam Leffler 	size_t cred_attr_len;
5839beb93cSSam Leffler };
5939beb93cSSam Leffler 
60e28a4053SRui Paulo #define WPS_DEV_TYPE_LEN 8
61e28a4053SRui Paulo #define WPS_DEV_TYPE_BUFSIZE 21
62f05cddf9SRui Paulo #define WPS_SEC_DEV_TYPE_MAX_LEN 128
63f05cddf9SRui Paulo /* maximum number of advertised WPS vendor extension attributes */
64f05cddf9SRui Paulo #define MAX_WPS_VENDOR_EXTENSIONS 10
65f05cddf9SRui Paulo /* maximum size of WPS Vendor extension attribute */
66f05cddf9SRui Paulo #define WPS_MAX_VENDOR_EXT_LEN 1024
67f05cddf9SRui Paulo /* maximum number of parsed WPS vendor extension attributes */
68f05cddf9SRui Paulo #define MAX_WPS_PARSE_VENDOR_EXT 10
69e28a4053SRui Paulo 
7039beb93cSSam Leffler /**
7139beb93cSSam Leffler  * struct wps_device_data - WPS Device Data
7239beb93cSSam Leffler  * @mac_addr: Device MAC address
7339beb93cSSam Leffler  * @device_name: Device Name (0..32 octets encoded in UTF-8)
7439beb93cSSam Leffler  * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
7539beb93cSSam Leffler  * @model_name: Model Name (0..32 octets encoded in UTF-8)
7639beb93cSSam Leffler  * @model_number: Model Number (0..32 octets encoded in UTF-8)
7739beb93cSSam Leffler  * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
78e28a4053SRui Paulo  * @pri_dev_type: Primary Device Type
79f05cddf9SRui Paulo  * @sec_dev_type: Array of secondary device types
80f05cddf9SRui Paulo  * @num_sec_dev_type: Number of secondary device types
8139beb93cSSam Leffler  * @os_version: OS Version
82*325151a3SRui Paulo  * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ, WPS_RF_60GHZ flags)
83f05cddf9SRui Paulo  * @p2p: Whether the device is a P2P device
8439beb93cSSam Leffler  */
8539beb93cSSam Leffler struct wps_device_data {
8639beb93cSSam Leffler 	u8 mac_addr[ETH_ALEN];
8739beb93cSSam Leffler 	char *device_name;
8839beb93cSSam Leffler 	char *manufacturer;
8939beb93cSSam Leffler 	char *model_name;
9039beb93cSSam Leffler 	char *model_number;
9139beb93cSSam Leffler 	char *serial_number;
92e28a4053SRui Paulo 	u8 pri_dev_type[WPS_DEV_TYPE_LEN];
93f05cddf9SRui Paulo #define WPS_SEC_DEVICE_TYPES 5
94f05cddf9SRui Paulo 	u8 sec_dev_type[WPS_SEC_DEVICE_TYPES][WPS_DEV_TYPE_LEN];
95f05cddf9SRui Paulo 	u8 num_sec_dev_types;
9639beb93cSSam Leffler 	u32 os_version;
9739beb93cSSam Leffler 	u8 rf_bands;
98f05cddf9SRui Paulo 	u16 config_methods;
99f05cddf9SRui Paulo 	struct wpabuf *vendor_ext_m1;
100f05cddf9SRui Paulo 	struct wpabuf *vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];
10139beb93cSSam Leffler 
102f05cddf9SRui Paulo 	int p2p;
103e28a4053SRui Paulo };
104e28a4053SRui Paulo 
10539beb93cSSam Leffler /**
10639beb93cSSam Leffler  * struct wps_config - WPS configuration for a single registration protocol run
10739beb93cSSam Leffler  */
10839beb93cSSam Leffler struct wps_config {
10939beb93cSSam Leffler 	/**
11039beb93cSSam Leffler 	 * wps - Pointer to long term WPS context
11139beb93cSSam Leffler 	 */
11239beb93cSSam Leffler 	struct wps_context *wps;
11339beb93cSSam Leffler 
11439beb93cSSam Leffler 	/**
11539beb93cSSam Leffler 	 * registrar - Whether this end is a Registrar
11639beb93cSSam Leffler 	 */
11739beb93cSSam Leffler 	int registrar;
11839beb93cSSam Leffler 
11939beb93cSSam Leffler 	/**
12039beb93cSSam Leffler 	 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
12139beb93cSSam Leffler 	 */
12239beb93cSSam Leffler 	const u8 *pin;
12339beb93cSSam Leffler 
12439beb93cSSam Leffler 	/**
12539beb93cSSam Leffler 	 * pin_len - Length on pin in octets
12639beb93cSSam Leffler 	 */
12739beb93cSSam Leffler 	size_t pin_len;
12839beb93cSSam Leffler 
12939beb93cSSam Leffler 	/**
13039beb93cSSam Leffler 	 * pbc - Whether this is protocol run uses PBC
13139beb93cSSam Leffler 	 */
13239beb93cSSam Leffler 	int pbc;
13339beb93cSSam Leffler 
13439beb93cSSam Leffler 	/**
13539beb93cSSam Leffler 	 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
13639beb93cSSam Leffler 	 */
13739beb93cSSam Leffler 	const struct wpabuf *assoc_wps_ie;
138e28a4053SRui Paulo 
139e28a4053SRui Paulo 	/**
140e28a4053SRui Paulo 	 * new_ap_settings - New AP settings (%NULL if not used)
141e28a4053SRui Paulo 	 *
142e28a4053SRui Paulo 	 * This parameter provides new AP settings when using a wireless
143e28a4053SRui Paulo 	 * stations as a Registrar to configure the AP. %NULL means that AP
144e28a4053SRui Paulo 	 * will not be reconfigured, i.e., the station will only learn the
145e28a4053SRui Paulo 	 * current AP settings by using AP PIN.
146e28a4053SRui Paulo 	 */
147e28a4053SRui Paulo 	const struct wps_credential *new_ap_settings;
148e28a4053SRui Paulo 
149e28a4053SRui Paulo 	/**
150e28a4053SRui Paulo 	 * peer_addr: MAC address of the peer in AP; %NULL if not AP
151e28a4053SRui Paulo 	 */
152e28a4053SRui Paulo 	const u8 *peer_addr;
153e28a4053SRui Paulo 
154e28a4053SRui Paulo 	/**
155e28a4053SRui Paulo 	 * use_psk_key - Use PSK format key in Credential
156e28a4053SRui Paulo 	 *
157e28a4053SRui Paulo 	 * Force PSK format to be used instead of ASCII passphrase when
158e28a4053SRui Paulo 	 * building Credential for an Enrollee. The PSK value is set in
159e28a4053SRui Paulo 	 * struct wpa_context::psk.
160e28a4053SRui Paulo 	 */
161e28a4053SRui Paulo 	int use_psk_key;
162f05cddf9SRui Paulo 
163f05cddf9SRui Paulo 	/**
164f05cddf9SRui Paulo 	 * dev_pw_id - Device Password ID for Enrollee when PIN is used
165f05cddf9SRui Paulo 	 */
166f05cddf9SRui Paulo 	u16 dev_pw_id;
167f05cddf9SRui Paulo 
168f05cddf9SRui Paulo 	/**
169f05cddf9SRui Paulo 	 * p2p_dev_addr - P2P Device Address from (Re)Association Request
170f05cddf9SRui Paulo 	 *
171f05cddf9SRui Paulo 	 * On AP/GO, this is set to the P2P Device Address of the associating
172f05cddf9SRui Paulo 	 * P2P client if a P2P IE is included in the (Re)Association Request
173f05cddf9SRui Paulo 	 * frame and the P2P Device Address is included. Otherwise, this is set
174f05cddf9SRui Paulo 	 * to %NULL to indicate the station does not have a P2P Device Address.
175f05cddf9SRui Paulo 	 */
176f05cddf9SRui Paulo 	const u8 *p2p_dev_addr;
177f05cddf9SRui Paulo 
178f05cddf9SRui Paulo 	/**
179f05cddf9SRui Paulo 	 * pbc_in_m1 - Do not remove PushButton config method in M1 (AP)
180f05cddf9SRui Paulo 	 *
181f05cddf9SRui Paulo 	 * This can be used to enable a workaround to allow Windows 7 to use
182f05cddf9SRui Paulo 	 * PBC with the AP.
183f05cddf9SRui Paulo 	 */
184f05cddf9SRui Paulo 	int pbc_in_m1;
1855b9c547cSRui Paulo 
1865b9c547cSRui Paulo 	/**
1875b9c547cSRui Paulo 	 * peer_pubkey_hash - Peer public key hash or %NULL if not known
1885b9c547cSRui Paulo 	 */
1895b9c547cSRui Paulo 	const u8 *peer_pubkey_hash;
19039beb93cSSam Leffler };
19139beb93cSSam Leffler 
19239beb93cSSam Leffler struct wps_data * wps_init(const struct wps_config *cfg);
19339beb93cSSam Leffler 
19439beb93cSSam Leffler void wps_deinit(struct wps_data *data);
19539beb93cSSam Leffler 
19639beb93cSSam Leffler /**
19739beb93cSSam Leffler  * enum wps_process_res - WPS message processing result
19839beb93cSSam Leffler  */
19939beb93cSSam Leffler enum wps_process_res {
20039beb93cSSam Leffler 	/**
20139beb93cSSam Leffler 	 * WPS_DONE - Processing done
20239beb93cSSam Leffler 	 */
20339beb93cSSam Leffler 	WPS_DONE,
20439beb93cSSam Leffler 
20539beb93cSSam Leffler 	/**
20639beb93cSSam Leffler 	 * WPS_CONTINUE - Processing continues
20739beb93cSSam Leffler 	 */
20839beb93cSSam Leffler 	WPS_CONTINUE,
20939beb93cSSam Leffler 
21039beb93cSSam Leffler 	/**
21139beb93cSSam Leffler 	 * WPS_FAILURE - Processing failed
21239beb93cSSam Leffler 	 */
21339beb93cSSam Leffler 	WPS_FAILURE,
21439beb93cSSam Leffler 
21539beb93cSSam Leffler 	/**
21639beb93cSSam Leffler 	 * WPS_PENDING - Processing continues, but waiting for an external
21739beb93cSSam Leffler 	 *	event (e.g., UPnP message from an external Registrar)
21839beb93cSSam Leffler 	 */
21939beb93cSSam Leffler 	WPS_PENDING
22039beb93cSSam Leffler };
22139beb93cSSam Leffler enum wps_process_res wps_process_msg(struct wps_data *wps,
22239beb93cSSam Leffler 				     enum wsc_op_code op_code,
22339beb93cSSam Leffler 				     const struct wpabuf *msg);
22439beb93cSSam Leffler 
22539beb93cSSam Leffler struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
22639beb93cSSam Leffler 
22739beb93cSSam Leffler int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
22839beb93cSSam Leffler int wps_is_selected_pin_registrar(const struct wpabuf *msg);
229f05cddf9SRui Paulo int wps_ap_priority_compar(const struct wpabuf *wps_a,
230f05cddf9SRui Paulo 			   const struct wpabuf *wps_b);
231f05cddf9SRui Paulo int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
232f05cddf9SRui Paulo 			   int ver1_compat);
23339beb93cSSam Leffler const u8 * wps_get_uuid_e(const struct wpabuf *msg);
234f05cddf9SRui Paulo int wps_is_20(const struct wpabuf *msg);
23539beb93cSSam Leffler 
23639beb93cSSam Leffler struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
237e28a4053SRui Paulo struct wpabuf * wps_build_assoc_resp_ie(void);
238f05cddf9SRui Paulo struct wpabuf * wps_build_probe_req_ie(u16 pw_id, struct wps_device_data *dev,
23939beb93cSSam Leffler 				       const u8 *uuid,
240f05cddf9SRui Paulo 				       enum wps_request_type req_type,
241f05cddf9SRui Paulo 				       unsigned int num_req_dev_types,
242f05cddf9SRui Paulo 				       const u8 *req_dev_types);
24339beb93cSSam Leffler 
24439beb93cSSam Leffler 
24539beb93cSSam Leffler /**
24639beb93cSSam Leffler  * struct wps_registrar_config - WPS Registrar configuration
24739beb93cSSam Leffler  */
24839beb93cSSam Leffler struct wps_registrar_config {
24939beb93cSSam Leffler 	/**
25039beb93cSSam Leffler 	 * new_psk_cb - Callback for new PSK
25139beb93cSSam Leffler 	 * @ctx: Higher layer context data (cb_ctx)
25239beb93cSSam Leffler 	 * @mac_addr: MAC address of the Enrollee
2535b9c547cSRui Paulo 	 * @p2p_dev_addr: P2P Device Address of the Enrollee or all zeros if not
25439beb93cSSam Leffler 	 * @psk: The new PSK
25539beb93cSSam Leffler 	 * @psk_len: The length of psk in octets
25639beb93cSSam Leffler 	 * Returns: 0 on success, -1 on failure
25739beb93cSSam Leffler 	 *
25839beb93cSSam Leffler 	 * This callback is called when a new per-device PSK is provisioned.
25939beb93cSSam Leffler 	 */
2605b9c547cSRui Paulo 	int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
2615b9c547cSRui Paulo 			  const u8 *psk, size_t psk_len);
26239beb93cSSam Leffler 
26339beb93cSSam Leffler 	/**
26439beb93cSSam Leffler 	 * set_ie_cb - Callback for WPS IE changes
26539beb93cSSam Leffler 	 * @ctx: Higher layer context data (cb_ctx)
26639beb93cSSam Leffler 	 * @beacon_ie: WPS IE for Beacon
26739beb93cSSam Leffler 	 * @probe_resp_ie: WPS IE for Probe Response
26839beb93cSSam Leffler 	 * Returns: 0 on success, -1 on failure
26939beb93cSSam Leffler 	 *
27039beb93cSSam Leffler 	 * This callback is called whenever the WPS IE in Beacon or Probe
271e28a4053SRui Paulo 	 * Response frames needs to be changed (AP only). Callee is responsible
272e28a4053SRui Paulo 	 * for freeing the buffers.
27339beb93cSSam Leffler 	 */
274e28a4053SRui Paulo 	int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
275e28a4053SRui Paulo 			 struct wpabuf *probe_resp_ie);
27639beb93cSSam Leffler 
27739beb93cSSam Leffler 	/**
27839beb93cSSam Leffler 	 * pin_needed_cb - Callback for requesting a PIN
27939beb93cSSam Leffler 	 * @ctx: Higher layer context data (cb_ctx)
28039beb93cSSam Leffler 	 * @uuid_e: UUID-E of the unknown Enrollee
28139beb93cSSam Leffler 	 * @dev: Device Data from the unknown Enrollee
28239beb93cSSam Leffler 	 *
28339beb93cSSam Leffler 	 * This callback is called whenever an unknown Enrollee requests to use
28439beb93cSSam Leffler 	 * PIN method and a matching PIN (Device Password) is not found in
28539beb93cSSam Leffler 	 * Registrar data.
28639beb93cSSam Leffler 	 */
28739beb93cSSam Leffler 	void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
28839beb93cSSam Leffler 			      const struct wps_device_data *dev);
28939beb93cSSam Leffler 
29039beb93cSSam Leffler 	/**
29139beb93cSSam Leffler 	 * reg_success_cb - Callback for reporting successful registration
29239beb93cSSam Leffler 	 * @ctx: Higher layer context data (cb_ctx)
29339beb93cSSam Leffler 	 * @mac_addr: MAC address of the Enrollee
29439beb93cSSam Leffler 	 * @uuid_e: UUID-E of the Enrollee
295f05cddf9SRui Paulo 	 * @dev_pw: Device Password (PIN) used during registration
296f05cddf9SRui Paulo 	 * @dev_pw_len: Length of dev_pw in octets
29739beb93cSSam Leffler 	 *
29839beb93cSSam Leffler 	 * This callback is called whenever an Enrollee completes registration
29939beb93cSSam Leffler 	 * successfully.
30039beb93cSSam Leffler 	 */
30139beb93cSSam Leffler 	void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
302f05cddf9SRui Paulo 			       const u8 *uuid_e, const u8 *dev_pw,
303f05cddf9SRui Paulo 			       size_t dev_pw_len);
30439beb93cSSam Leffler 
30539beb93cSSam Leffler 	/**
306e28a4053SRui Paulo 	 * set_sel_reg_cb - Callback for reporting selected registrar changes
307e28a4053SRui Paulo 	 * @ctx: Higher layer context data (cb_ctx)
308e28a4053SRui Paulo 	 * @sel_reg: Whether the Registrar is selected
309e28a4053SRui Paulo 	 * @dev_passwd_id: Device Password ID to indicate with method or
310e28a4053SRui Paulo 	 *	specific password the Registrar intends to use
311e28a4053SRui Paulo 	 * @sel_reg_config_methods: Bit field of active config methods
312e28a4053SRui Paulo 	 *
313e28a4053SRui Paulo 	 * This callback is called whenever the Selected Registrar state
314e28a4053SRui Paulo 	 * changes (e.g., a new PIN becomes available or PBC is invoked). This
315e28a4053SRui Paulo 	 * callback is only used by External Registrar implementation;
316e28a4053SRui Paulo 	 * set_ie_cb() is used by AP implementation in similar caes, but it
317e28a4053SRui Paulo 	 * provides the full WPS IE data instead of just the minimal Registrar
318e28a4053SRui Paulo 	 * state information.
319e28a4053SRui Paulo 	 */
320e28a4053SRui Paulo 	void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
321e28a4053SRui Paulo 			       u16 sel_reg_config_methods);
322e28a4053SRui Paulo 
323e28a4053SRui Paulo 	/**
324e28a4053SRui Paulo 	 * enrollee_seen_cb - Callback for reporting Enrollee based on ProbeReq
325e28a4053SRui Paulo 	 * @ctx: Higher layer context data (cb_ctx)
326e28a4053SRui Paulo 	 * @addr: MAC address of the Enrollee
327e28a4053SRui Paulo 	 * @uuid_e: UUID of the Enrollee
328e28a4053SRui Paulo 	 * @pri_dev_type: Primary device type
329e28a4053SRui Paulo 	 * @config_methods: Config Methods
330e28a4053SRui Paulo 	 * @dev_password_id: Device Password ID
331e28a4053SRui Paulo 	 * @request_type: Request Type
332e28a4053SRui Paulo 	 * @dev_name: Device Name (if available)
333e28a4053SRui Paulo 	 */
334e28a4053SRui Paulo 	void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
335e28a4053SRui Paulo 				 const u8 *pri_dev_type, u16 config_methods,
336e28a4053SRui Paulo 				 u16 dev_password_id, u8 request_type,
337e28a4053SRui Paulo 				 const char *dev_name);
338e28a4053SRui Paulo 
339e28a4053SRui Paulo 	/**
34039beb93cSSam Leffler 	 * cb_ctx: Higher layer context data for Registrar callbacks
34139beb93cSSam Leffler 	 */
34239beb93cSSam Leffler 	void *cb_ctx;
34339beb93cSSam Leffler 
34439beb93cSSam Leffler 	/**
34539beb93cSSam Leffler 	 * skip_cred_build: Do not build credential
34639beb93cSSam Leffler 	 *
34739beb93cSSam Leffler 	 * This option can be used to disable internal code that builds
34839beb93cSSam Leffler 	 * Credential attribute into M8 based on the current network
34939beb93cSSam Leffler 	 * configuration and Enrollee capabilities. The extra_cred data will
35039beb93cSSam Leffler 	 * then be used as the Credential(s).
35139beb93cSSam Leffler 	 */
35239beb93cSSam Leffler 	int skip_cred_build;
35339beb93cSSam Leffler 
35439beb93cSSam Leffler 	/**
35539beb93cSSam Leffler 	 * extra_cred: Additional Credential attribute(s)
35639beb93cSSam Leffler 	 *
35739beb93cSSam Leffler 	 * This optional data (set to %NULL to disable) can be used to add
35839beb93cSSam Leffler 	 * Credential attribute(s) for other networks into M8. If
35939beb93cSSam Leffler 	 * skip_cred_build is set, this will also override the automatically
36039beb93cSSam Leffler 	 * generated Credential attribute.
36139beb93cSSam Leffler 	 */
36239beb93cSSam Leffler 	const u8 *extra_cred;
36339beb93cSSam Leffler 
36439beb93cSSam Leffler 	/**
36539beb93cSSam Leffler 	 * extra_cred_len: Length of extra_cred in octets
36639beb93cSSam Leffler 	 */
36739beb93cSSam Leffler 	size_t extra_cred_len;
36839beb93cSSam Leffler 
36939beb93cSSam Leffler 	/**
37039beb93cSSam Leffler 	 * disable_auto_conf - Disable auto-configuration on first registration
37139beb93cSSam Leffler 	 *
37239beb93cSSam Leffler 	 * By default, the AP that is started in not configured state will
37339beb93cSSam Leffler 	 * generate a random PSK and move to configured state when the first
37439beb93cSSam Leffler 	 * registration protocol run is completed successfully. This option can
37539beb93cSSam Leffler 	 * be used to disable this functionality and leave it up to an external
37639beb93cSSam Leffler 	 * program to take care of configuration. This requires the extra_cred
37739beb93cSSam Leffler 	 * to be set with a suitable Credential and skip_cred_build being used.
37839beb93cSSam Leffler 	 */
37939beb93cSSam Leffler 	int disable_auto_conf;
3803157ba21SRui Paulo 
3813157ba21SRui Paulo 	/**
3823157ba21SRui Paulo 	 * static_wep_only - Whether the BSS supports only static WEP
3833157ba21SRui Paulo 	 */
3843157ba21SRui Paulo 	int static_wep_only;
385f05cddf9SRui Paulo 
386f05cddf9SRui Paulo 	/**
387f05cddf9SRui Paulo 	 * dualband - Whether this is a concurrent dualband AP
388f05cddf9SRui Paulo 	 */
389f05cddf9SRui Paulo 	int dualband;
3905b9c547cSRui Paulo 
3915b9c547cSRui Paulo 	/**
3925b9c547cSRui Paulo 	 * force_per_enrollee_psk - Force per-Enrollee random PSK
3935b9c547cSRui Paulo 	 *
3945b9c547cSRui Paulo 	 * This forces per-Enrollee random PSK to be generated even if a default
3955b9c547cSRui Paulo 	 * PSK is set for a network.
3965b9c547cSRui Paulo 	 */
3975b9c547cSRui Paulo 	int force_per_enrollee_psk;
39839beb93cSSam Leffler };
39939beb93cSSam Leffler 
40039beb93cSSam Leffler 
40139beb93cSSam Leffler /**
40239beb93cSSam Leffler  * enum wps_event - WPS event types
40339beb93cSSam Leffler  */
40439beb93cSSam Leffler enum wps_event {
40539beb93cSSam Leffler 	/**
40639beb93cSSam Leffler 	 * WPS_EV_M2D - M2D received (Registrar did not know us)
40739beb93cSSam Leffler 	 */
40839beb93cSSam Leffler 	WPS_EV_M2D,
40939beb93cSSam Leffler 
41039beb93cSSam Leffler 	/**
41139beb93cSSam Leffler 	 * WPS_EV_FAIL - Registration failed
41239beb93cSSam Leffler 	 */
41339beb93cSSam Leffler 	WPS_EV_FAIL,
41439beb93cSSam Leffler 
41539beb93cSSam Leffler 	/**
41639beb93cSSam Leffler 	 * WPS_EV_SUCCESS - Registration succeeded
41739beb93cSSam Leffler 	 */
41839beb93cSSam Leffler 	WPS_EV_SUCCESS,
41939beb93cSSam Leffler 
42039beb93cSSam Leffler 	/**
42139beb93cSSam Leffler 	 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
42239beb93cSSam Leffler 	 */
4233157ba21SRui Paulo 	WPS_EV_PWD_AUTH_FAIL,
4243157ba21SRui Paulo 
4253157ba21SRui Paulo 	/**
4263157ba21SRui Paulo 	 * WPS_EV_PBC_OVERLAP - PBC session overlap detected
4273157ba21SRui Paulo 	 */
4283157ba21SRui Paulo 	WPS_EV_PBC_OVERLAP,
4293157ba21SRui Paulo 
4303157ba21SRui Paulo 	/**
4313157ba21SRui Paulo 	 * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
4323157ba21SRui Paulo 	 */
433e28a4053SRui Paulo 	WPS_EV_PBC_TIMEOUT,
434e28a4053SRui Paulo 
435e28a4053SRui Paulo 	/**
4365b9c547cSRui Paulo 	 * WPS_EV_PBC_ACTIVE - PBC mode was activated
4375b9c547cSRui Paulo 	 */
4385b9c547cSRui Paulo 	WPS_EV_PBC_ACTIVE,
4395b9c547cSRui Paulo 
4405b9c547cSRui Paulo 	/**
4415b9c547cSRui Paulo 	 * WPS_EV_PBC_DISABLE - PBC mode was disabled
4425b9c547cSRui Paulo 	 */
4435b9c547cSRui Paulo 	WPS_EV_PBC_DISABLE,
4445b9c547cSRui Paulo 
4455b9c547cSRui Paulo 	/**
446e28a4053SRui Paulo 	 * WPS_EV_ER_AP_ADD - ER: AP added
447e28a4053SRui Paulo 	 */
448e28a4053SRui Paulo 	WPS_EV_ER_AP_ADD,
449e28a4053SRui Paulo 
450e28a4053SRui Paulo 	/**
451e28a4053SRui Paulo 	 * WPS_EV_ER_AP_REMOVE - ER: AP removed
452e28a4053SRui Paulo 	 */
453e28a4053SRui Paulo 	WPS_EV_ER_AP_REMOVE,
454e28a4053SRui Paulo 
455e28a4053SRui Paulo 	/**
456e28a4053SRui Paulo 	 * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added
457e28a4053SRui Paulo 	 */
458e28a4053SRui Paulo 	WPS_EV_ER_ENROLLEE_ADD,
459e28a4053SRui Paulo 
460e28a4053SRui Paulo 	/**
461e28a4053SRui Paulo 	 * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed
462e28a4053SRui Paulo 	 */
463f05cddf9SRui Paulo 	WPS_EV_ER_ENROLLEE_REMOVE,
464f05cddf9SRui Paulo 
465f05cddf9SRui Paulo 	/**
466f05cddf9SRui Paulo 	 * WPS_EV_ER_AP_SETTINGS - ER: AP Settings learned
467f05cddf9SRui Paulo 	 */
468f05cddf9SRui Paulo 	WPS_EV_ER_AP_SETTINGS,
469f05cddf9SRui Paulo 
470f05cddf9SRui Paulo 	/**
471f05cddf9SRui Paulo 	 * WPS_EV_ER_SET_SELECTED_REGISTRAR - ER: SetSelectedRegistrar event
472f05cddf9SRui Paulo 	 */
473f05cddf9SRui Paulo 	WPS_EV_ER_SET_SELECTED_REGISTRAR,
474f05cddf9SRui Paulo 
475f05cddf9SRui Paulo 	/**
476f05cddf9SRui Paulo 	 * WPS_EV_AP_PIN_SUCCESS - External Registrar used correct AP PIN
477f05cddf9SRui Paulo 	 */
478f05cddf9SRui Paulo 	WPS_EV_AP_PIN_SUCCESS
47939beb93cSSam Leffler };
48039beb93cSSam Leffler 
48139beb93cSSam Leffler /**
48239beb93cSSam Leffler  * union wps_event_data - WPS event data
48339beb93cSSam Leffler  */
48439beb93cSSam Leffler union wps_event_data {
48539beb93cSSam Leffler 	/**
48639beb93cSSam Leffler 	 * struct wps_event_m2d - M2D event data
48739beb93cSSam Leffler 	 */
48839beb93cSSam Leffler 	struct wps_event_m2d {
48939beb93cSSam Leffler 		u16 config_methods;
49039beb93cSSam Leffler 		const u8 *manufacturer;
49139beb93cSSam Leffler 		size_t manufacturer_len;
49239beb93cSSam Leffler 		const u8 *model_name;
49339beb93cSSam Leffler 		size_t model_name_len;
49439beb93cSSam Leffler 		const u8 *model_number;
49539beb93cSSam Leffler 		size_t model_number_len;
49639beb93cSSam Leffler 		const u8 *serial_number;
49739beb93cSSam Leffler 		size_t serial_number_len;
49839beb93cSSam Leffler 		const u8 *dev_name;
49939beb93cSSam Leffler 		size_t dev_name_len;
50039beb93cSSam Leffler 		const u8 *primary_dev_type; /* 8 octets */
50139beb93cSSam Leffler 		u16 config_error;
50239beb93cSSam Leffler 		u16 dev_password_id;
50339beb93cSSam Leffler 	} m2d;
50439beb93cSSam Leffler 
50539beb93cSSam Leffler 	/**
50639beb93cSSam Leffler 	 * struct wps_event_fail - Registration failure information
50739beb93cSSam Leffler 	 * @msg: enum wps_msg_type
50839beb93cSSam Leffler 	 */
50939beb93cSSam Leffler 	struct wps_event_fail {
51039beb93cSSam Leffler 		int msg;
511f05cddf9SRui Paulo 		u16 config_error;
512f05cddf9SRui Paulo 		u16 error_indication;
5135b9c547cSRui Paulo 		u8 peer_macaddr[ETH_ALEN];
51439beb93cSSam Leffler 	} fail;
51539beb93cSSam Leffler 
5165b9c547cSRui Paulo 	struct wps_event_success {
5175b9c547cSRui Paulo 		u8 peer_macaddr[ETH_ALEN];
5185b9c547cSRui Paulo 	} success;
5195b9c547cSRui Paulo 
52039beb93cSSam Leffler 	struct wps_event_pwd_auth_fail {
52139beb93cSSam Leffler 		int enrollee;
52239beb93cSSam Leffler 		int part;
5235b9c547cSRui Paulo 		u8 peer_macaddr[ETH_ALEN];
52439beb93cSSam Leffler 	} pwd_auth_fail;
525e28a4053SRui Paulo 
526e28a4053SRui Paulo 	struct wps_event_er_ap {
527e28a4053SRui Paulo 		const u8 *uuid;
528e28a4053SRui Paulo 		const u8 *mac_addr;
529e28a4053SRui Paulo 		const char *friendly_name;
530e28a4053SRui Paulo 		const char *manufacturer;
531e28a4053SRui Paulo 		const char *manufacturer_url;
532e28a4053SRui Paulo 		const char *model_description;
533e28a4053SRui Paulo 		const char *model_name;
534e28a4053SRui Paulo 		const char *model_number;
535e28a4053SRui Paulo 		const char *model_url;
536e28a4053SRui Paulo 		const char *serial_number;
537e28a4053SRui Paulo 		const char *upc;
538e28a4053SRui Paulo 		const u8 *pri_dev_type;
539e28a4053SRui Paulo 		u8 wps_state;
540e28a4053SRui Paulo 	} ap;
541e28a4053SRui Paulo 
542e28a4053SRui Paulo 	struct wps_event_er_enrollee {
543e28a4053SRui Paulo 		const u8 *uuid;
544e28a4053SRui Paulo 		const u8 *mac_addr;
545e28a4053SRui Paulo 		int m1_received;
546e28a4053SRui Paulo 		u16 config_methods;
547e28a4053SRui Paulo 		u16 dev_passwd_id;
548e28a4053SRui Paulo 		const u8 *pri_dev_type;
549e28a4053SRui Paulo 		const char *dev_name;
550e28a4053SRui Paulo 		const char *manufacturer;
551e28a4053SRui Paulo 		const char *model_name;
552e28a4053SRui Paulo 		const char *model_number;
553e28a4053SRui Paulo 		const char *serial_number;
554e28a4053SRui Paulo 	} enrollee;
555f05cddf9SRui Paulo 
556f05cddf9SRui Paulo 	struct wps_event_er_ap_settings {
557f05cddf9SRui Paulo 		const u8 *uuid;
558f05cddf9SRui Paulo 		const struct wps_credential *cred;
559f05cddf9SRui Paulo 	} ap_settings;
560f05cddf9SRui Paulo 
561f05cddf9SRui Paulo 	struct wps_event_er_set_selected_registrar {
562f05cddf9SRui Paulo 		const u8 *uuid;
563f05cddf9SRui Paulo 		int sel_reg;
564f05cddf9SRui Paulo 		u16 dev_passwd_id;
565f05cddf9SRui Paulo 		u16 sel_reg_config_methods;
566f05cddf9SRui Paulo 		enum {
567f05cddf9SRui Paulo 			WPS_ER_SET_SEL_REG_START,
568f05cddf9SRui Paulo 			WPS_ER_SET_SEL_REG_DONE,
569f05cddf9SRui Paulo 			WPS_ER_SET_SEL_REG_FAILED
570f05cddf9SRui Paulo 		} state;
571f05cddf9SRui Paulo 	} set_sel_reg;
57239beb93cSSam Leffler };
57339beb93cSSam Leffler 
57439beb93cSSam Leffler /**
57539beb93cSSam Leffler  * struct upnp_pending_message - Pending PutWLANResponse messages
57639beb93cSSam Leffler  * @next: Pointer to next pending message or %NULL
57739beb93cSSam Leffler  * @addr: NewWLANEventMAC
57839beb93cSSam Leffler  * @msg: NewMessage
57939beb93cSSam Leffler  * @type: Message Type
58039beb93cSSam Leffler  */
58139beb93cSSam Leffler struct upnp_pending_message {
58239beb93cSSam Leffler 	struct upnp_pending_message *next;
58339beb93cSSam Leffler 	u8 addr[ETH_ALEN];
58439beb93cSSam Leffler 	struct wpabuf *msg;
58539beb93cSSam Leffler 	enum wps_msg_type type;
58639beb93cSSam Leffler };
58739beb93cSSam Leffler 
58839beb93cSSam Leffler /**
58939beb93cSSam Leffler  * struct wps_context - Long term WPS context data
59039beb93cSSam Leffler  *
59139beb93cSSam Leffler  * This data is stored at the higher layer Authenticator or Supplicant data
59239beb93cSSam Leffler  * structures and it is maintained over multiple registration protocol runs.
59339beb93cSSam Leffler  */
59439beb93cSSam Leffler struct wps_context {
59539beb93cSSam Leffler 	/**
59639beb93cSSam Leffler 	 * ap - Whether the local end is an access point
59739beb93cSSam Leffler 	 */
59839beb93cSSam Leffler 	int ap;
59939beb93cSSam Leffler 
60039beb93cSSam Leffler 	/**
60139beb93cSSam Leffler 	 * registrar - Pointer to WPS registrar data from wps_registrar_init()
60239beb93cSSam Leffler 	 */
60339beb93cSSam Leffler 	struct wps_registrar *registrar;
60439beb93cSSam Leffler 
60539beb93cSSam Leffler 	/**
60639beb93cSSam Leffler 	 * wps_state - Current WPS state
60739beb93cSSam Leffler 	 */
60839beb93cSSam Leffler 	enum wps_state wps_state;
60939beb93cSSam Leffler 
61039beb93cSSam Leffler 	/**
61139beb93cSSam Leffler 	 * ap_setup_locked - Whether AP setup is locked (only used at AP)
61239beb93cSSam Leffler 	 */
61339beb93cSSam Leffler 	int ap_setup_locked;
61439beb93cSSam Leffler 
61539beb93cSSam Leffler 	/**
61639beb93cSSam Leffler 	 * uuid - Own UUID
61739beb93cSSam Leffler 	 */
61839beb93cSSam Leffler 	u8 uuid[16];
61939beb93cSSam Leffler 
62039beb93cSSam Leffler 	/**
62139beb93cSSam Leffler 	 * ssid - SSID
62239beb93cSSam Leffler 	 *
62339beb93cSSam Leffler 	 * This SSID is used by the Registrar to fill in information for
62439beb93cSSam Leffler 	 * Credentials. In addition, AP uses it when acting as an Enrollee to
62539beb93cSSam Leffler 	 * notify Registrar of the current configuration.
62639beb93cSSam Leffler 	 */
627*325151a3SRui Paulo 	u8 ssid[SSID_MAX_LEN];
62839beb93cSSam Leffler 
62939beb93cSSam Leffler 	/**
63039beb93cSSam Leffler 	 * ssid_len - Length of ssid in octets
63139beb93cSSam Leffler 	 */
63239beb93cSSam Leffler 	size_t ssid_len;
63339beb93cSSam Leffler 
63439beb93cSSam Leffler 	/**
63539beb93cSSam Leffler 	 * dev - Own WPS device data
63639beb93cSSam Leffler 	 */
63739beb93cSSam Leffler 	struct wps_device_data dev;
63839beb93cSSam Leffler 
63939beb93cSSam Leffler 	/**
640e28a4053SRui Paulo 	 * dh_ctx - Context data for Diffie-Hellman operation
641e28a4053SRui Paulo 	 */
642e28a4053SRui Paulo 	void *dh_ctx;
643e28a4053SRui Paulo 
644e28a4053SRui Paulo 	/**
645e28a4053SRui Paulo 	 * dh_privkey - Diffie-Hellman private key
646e28a4053SRui Paulo 	 */
647e28a4053SRui Paulo 	struct wpabuf *dh_privkey;
648e28a4053SRui Paulo 
649e28a4053SRui Paulo 	/**
650e28a4053SRui Paulo 	 * dh_pubkey_oob - Diffie-Hellman public key
651e28a4053SRui Paulo 	 */
652e28a4053SRui Paulo 	struct wpabuf *dh_pubkey;
653e28a4053SRui Paulo 
654e28a4053SRui Paulo 	/**
65539beb93cSSam Leffler 	 * config_methods - Enabled configuration methods
65639beb93cSSam Leffler 	 *
65739beb93cSSam Leffler 	 * Bit field of WPS_CONFIG_*
65839beb93cSSam Leffler 	 */
65939beb93cSSam Leffler 	u16 config_methods;
66039beb93cSSam Leffler 
66139beb93cSSam Leffler 	/**
66239beb93cSSam Leffler 	 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
66339beb93cSSam Leffler 	 */
66439beb93cSSam Leffler 	u16 encr_types;
66539beb93cSSam Leffler 
66639beb93cSSam Leffler 	/**
66739beb93cSSam Leffler 	 * auth_types - Authentication types (bit field of WPS_AUTH_*)
66839beb93cSSam Leffler 	 */
66939beb93cSSam Leffler 	u16 auth_types;
67039beb93cSSam Leffler 
67139beb93cSSam Leffler 	/**
6725b9c547cSRui Paulo 	 * encr_types - Current AP encryption type (WPS_ENCR_*)
6735b9c547cSRui Paulo 	 */
6745b9c547cSRui Paulo 	u16 ap_encr_type;
6755b9c547cSRui Paulo 
6765b9c547cSRui Paulo 	/**
6775b9c547cSRui Paulo 	 * ap_auth_type - Current AP authentication types (WPS_AUTH_*)
6785b9c547cSRui Paulo 	 */
6795b9c547cSRui Paulo 	u16 ap_auth_type;
6805b9c547cSRui Paulo 
6815b9c547cSRui Paulo 	/**
68239beb93cSSam Leffler 	 * network_key - The current Network Key (PSK) or %NULL to generate new
68339beb93cSSam Leffler 	 *
68439beb93cSSam Leffler 	 * If %NULL, Registrar will generate per-device PSK. In addition, AP
68539beb93cSSam Leffler 	 * uses this when acting as an Enrollee to notify Registrar of the
68639beb93cSSam Leffler 	 * current configuration.
687e28a4053SRui Paulo 	 *
688e28a4053SRui Paulo 	 * When using WPA/WPA2-Person, this key can be either the ASCII
689e28a4053SRui Paulo 	 * passphrase (8..63 characters) or the 32-octet PSK (64 hex
690e28a4053SRui Paulo 	 * characters). When this is set to the ASCII passphrase, the PSK can
691e28a4053SRui Paulo 	 * be provided in the psk buffer and used per-Enrollee to control which
692e28a4053SRui Paulo 	 * key type is included in the Credential (e.g., to reduce calculation
693e28a4053SRui Paulo 	 * need on low-powered devices by provisioning PSK while still allowing
694e28a4053SRui Paulo 	 * other devices to get the passphrase).
69539beb93cSSam Leffler 	 */
69639beb93cSSam Leffler 	u8 *network_key;
69739beb93cSSam Leffler 
69839beb93cSSam Leffler 	/**
69939beb93cSSam Leffler 	 * network_key_len - Length of network_key in octets
70039beb93cSSam Leffler 	 */
70139beb93cSSam Leffler 	size_t network_key_len;
70239beb93cSSam Leffler 
70339beb93cSSam Leffler 	/**
704e28a4053SRui Paulo 	 * psk - The current network PSK
705e28a4053SRui Paulo 	 *
706e28a4053SRui Paulo 	 * This optional value can be used to provide the current PSK if
707e28a4053SRui Paulo 	 * network_key is set to the ASCII passphrase.
708e28a4053SRui Paulo 	 */
709e28a4053SRui Paulo 	u8 psk[32];
710e28a4053SRui Paulo 
711e28a4053SRui Paulo 	/**
712e28a4053SRui Paulo 	 * psk_set - Whether psk value is set
713e28a4053SRui Paulo 	 */
714e28a4053SRui Paulo 	int psk_set;
715e28a4053SRui Paulo 
716e28a4053SRui Paulo 	/**
71739beb93cSSam Leffler 	 * ap_settings - AP Settings override for M7 (only used at AP)
71839beb93cSSam Leffler 	 *
71939beb93cSSam Leffler 	 * If %NULL, AP Settings attributes will be generated based on the
72039beb93cSSam Leffler 	 * current network configuration.
72139beb93cSSam Leffler 	 */
72239beb93cSSam Leffler 	u8 *ap_settings;
72339beb93cSSam Leffler 
72439beb93cSSam Leffler 	/**
72539beb93cSSam Leffler 	 * ap_settings_len - Length of ap_settings in octets
72639beb93cSSam Leffler 	 */
72739beb93cSSam Leffler 	size_t ap_settings_len;
72839beb93cSSam Leffler 
72939beb93cSSam Leffler 	/**
73039beb93cSSam Leffler 	 * friendly_name - Friendly Name (required for UPnP)
73139beb93cSSam Leffler 	 */
73239beb93cSSam Leffler 	char *friendly_name;
73339beb93cSSam Leffler 
73439beb93cSSam Leffler 	/**
73539beb93cSSam Leffler 	 * manufacturer_url - Manufacturer URL (optional for UPnP)
73639beb93cSSam Leffler 	 */
73739beb93cSSam Leffler 	char *manufacturer_url;
73839beb93cSSam Leffler 
73939beb93cSSam Leffler 	/**
74039beb93cSSam Leffler 	 * model_description - Model Description (recommended for UPnP)
74139beb93cSSam Leffler 	 */
74239beb93cSSam Leffler 	char *model_description;
74339beb93cSSam Leffler 
74439beb93cSSam Leffler 	/**
74539beb93cSSam Leffler 	 * model_url - Model URL (optional for UPnP)
74639beb93cSSam Leffler 	 */
74739beb93cSSam Leffler 	char *model_url;
74839beb93cSSam Leffler 
74939beb93cSSam Leffler 	/**
75039beb93cSSam Leffler 	 * upc - Universal Product Code (optional for UPnP)
75139beb93cSSam Leffler 	 */
75239beb93cSSam Leffler 	char *upc;
75339beb93cSSam Leffler 
75439beb93cSSam Leffler 	/**
75539beb93cSSam Leffler 	 * cred_cb - Callback to notify that new Credentials were received
75639beb93cSSam Leffler 	 * @ctx: Higher layer context data (cb_ctx)
75739beb93cSSam Leffler 	 * @cred: The received Credential
75839beb93cSSam Leffler 	 * Return: 0 on success, -1 on failure
75939beb93cSSam Leffler 	 */
76039beb93cSSam Leffler 	int (*cred_cb)(void *ctx, const struct wps_credential *cred);
76139beb93cSSam Leffler 
76239beb93cSSam Leffler 	/**
76339beb93cSSam Leffler 	 * event_cb - Event callback (state information about progress)
76439beb93cSSam Leffler 	 * @ctx: Higher layer context data (cb_ctx)
76539beb93cSSam Leffler 	 * @event: Event type
76639beb93cSSam Leffler 	 * @data: Event data
76739beb93cSSam Leffler 	 */
76839beb93cSSam Leffler 	void (*event_cb)(void *ctx, enum wps_event event,
76939beb93cSSam Leffler 			 union wps_event_data *data);
77039beb93cSSam Leffler 
77139beb93cSSam Leffler 	/**
7725b9c547cSRui Paulo 	 * rf_band_cb - Fetch currently used RF band
7735b9c547cSRui Paulo 	 * @ctx: Higher layer context data (cb_ctx)
7745b9c547cSRui Paulo 	 * Return: Current used RF band or 0 if not known
7755b9c547cSRui Paulo 	 */
7765b9c547cSRui Paulo 	int (*rf_band_cb)(void *ctx);
7775b9c547cSRui Paulo 
7785b9c547cSRui Paulo 	/**
77939beb93cSSam Leffler 	 * cb_ctx: Higher layer context data for callbacks
78039beb93cSSam Leffler 	 */
78139beb93cSSam Leffler 	void *cb_ctx;
78239beb93cSSam Leffler 
78339beb93cSSam Leffler 	struct upnp_wps_device_sm *wps_upnp;
78439beb93cSSam Leffler 
78539beb93cSSam Leffler 	/* Pending messages from UPnP PutWLANResponse */
78639beb93cSSam Leffler 	struct upnp_pending_message *upnp_msgs;
78739beb93cSSam Leffler 
788f05cddf9SRui Paulo 	u16 ap_nfc_dev_pw_id;
789f05cddf9SRui Paulo 	struct wpabuf *ap_nfc_dh_pubkey;
790f05cddf9SRui Paulo 	struct wpabuf *ap_nfc_dh_privkey;
791f05cddf9SRui Paulo 	struct wpabuf *ap_nfc_dev_pw;
792e28a4053SRui Paulo };
79339beb93cSSam Leffler 
79439beb93cSSam Leffler struct wps_registrar *
79539beb93cSSam Leffler wps_registrar_init(struct wps_context *wps,
79639beb93cSSam Leffler 		   const struct wps_registrar_config *cfg);
79739beb93cSSam Leffler void wps_registrar_deinit(struct wps_registrar *reg);
798f05cddf9SRui Paulo int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr,
799f05cddf9SRui Paulo 			  const u8 *uuid, const u8 *pin, size_t pin_len,
800f05cddf9SRui Paulo 			  int timeout);
80139beb93cSSam Leffler int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
802f05cddf9SRui Paulo int wps_registrar_wps_cancel(struct wps_registrar *reg);
80339beb93cSSam Leffler int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
804f05cddf9SRui Paulo int wps_registrar_button_pushed(struct wps_registrar *reg,
805f05cddf9SRui Paulo 				const u8 *p2p_dev_addr);
806f05cddf9SRui Paulo void wps_registrar_complete(struct wps_registrar *registrar, const u8 *uuid_e,
807f05cddf9SRui Paulo 			    const u8 *dev_pw, size_t dev_pw_len);
80839beb93cSSam Leffler void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
809f05cddf9SRui Paulo 				const struct wpabuf *wps_data,
810f05cddf9SRui Paulo 				int p2p_wildcard);
81139beb93cSSam Leffler int wps_registrar_update_ie(struct wps_registrar *reg);
812e28a4053SRui Paulo int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
813e28a4053SRui Paulo 			   char *buf, size_t buflen);
814f05cddf9SRui Paulo int wps_registrar_config_ap(struct wps_registrar *reg,
815f05cddf9SRui Paulo 			    struct wps_credential *cred);
816f05cddf9SRui Paulo int wps_registrar_add_nfc_pw_token(struct wps_registrar *reg,
817f05cddf9SRui Paulo 				   const u8 *pubkey_hash, u16 pw_id,
8185b9c547cSRui Paulo 				   const u8 *dev_pw, size_t dev_pw_len,
8195b9c547cSRui Paulo 				   int pk_hash_provided_oob);
820f05cddf9SRui Paulo int wps_registrar_add_nfc_password_token(struct wps_registrar *reg,
821f05cddf9SRui Paulo 					 const u8 *oob_dev_pw,
822f05cddf9SRui Paulo 					 size_t oob_dev_pw_len);
8235b9c547cSRui Paulo void wps_registrar_flush(struct wps_registrar *reg);
824f05cddf9SRui Paulo 
825f05cddf9SRui Paulo int wps_build_credential_wrap(struct wpabuf *msg,
826f05cddf9SRui Paulo 			      const struct wps_credential *cred);
82739beb93cSSam Leffler 
82839beb93cSSam Leffler unsigned int wps_pin_checksum(unsigned int pin);
82939beb93cSSam Leffler unsigned int wps_pin_valid(unsigned int pin);
83039beb93cSSam Leffler unsigned int wps_generate_pin(void);
831f05cddf9SRui Paulo int wps_pin_str_valid(const char *pin);
83239beb93cSSam Leffler void wps_free_pending_msgs(struct upnp_pending_message *msgs);
83339beb93cSSam Leffler 
8345b9c547cSRui Paulo struct wpabuf * wps_get_oob_cred(struct wps_context *wps, int rf_band,
8355b9c547cSRui Paulo 				 int channel);
836f05cddf9SRui Paulo int wps_oob_use_cred(struct wps_context *wps, struct wps_parse_attr *attr);
837e28a4053SRui Paulo int wps_attr_text(struct wpabuf *data, char *buf, char *end);
8385b9c547cSRui Paulo const char * wps_ei_str(enum wps_error_indication ei);
839e28a4053SRui Paulo 
840f05cddf9SRui Paulo struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname,
841f05cddf9SRui Paulo 			    const char *filter);
842e28a4053SRui Paulo void wps_er_refresh(struct wps_er *er);
843e28a4053SRui Paulo void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx);
844e28a4053SRui Paulo void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
845e28a4053SRui Paulo 			u16 sel_reg_config_methods);
8465b9c547cSRui Paulo int wps_er_pbc(struct wps_er *er, const u8 *uuid, const u8 *addr);
8475b9c547cSRui Paulo const u8 * wps_er_get_sta_uuid(struct wps_er *er, const u8 *addr);
8485b9c547cSRui Paulo int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *addr,
8495b9c547cSRui Paulo 		 const u8 *pin, size_t pin_len);
8505b9c547cSRui Paulo int wps_er_set_config(struct wps_er *er, const u8 *uuid, const u8 *addr,
851f05cddf9SRui Paulo 		      const struct wps_credential *cred);
8525b9c547cSRui Paulo int wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *addr,
8535b9c547cSRui Paulo 		  const u8 *pin, size_t pin_len,
8545b9c547cSRui Paulo 		  const struct wps_credential *cred);
8555b9c547cSRui Paulo struct wpabuf * wps_er_config_token_from_cred(struct wps_context *wps,
8565b9c547cSRui Paulo 					      struct wps_credential *cred);
8575b9c547cSRui Paulo struct wpabuf * wps_er_nfc_config_token(struct wps_er *er, const u8 *uuid,
8585b9c547cSRui Paulo 					const u8 *addr);
8595b9c547cSRui Paulo struct wpabuf * wps_er_nfc_handover_sel(struct wps_er *er,
8605b9c547cSRui Paulo 					struct wps_context *wps, const u8 *uuid,
8615b9c547cSRui Paulo 					const u8 *addr, struct wpabuf *pubkey);
862e28a4053SRui Paulo 
863e28a4053SRui Paulo int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
864e28a4053SRui Paulo char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
865e28a4053SRui Paulo 			    size_t buf_len);
866e28a4053SRui Paulo void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
867e28a4053SRui Paulo u16 wps_config_methods_str2bin(const char *str);
868f05cddf9SRui Paulo struct wpabuf * wps_build_nfc_pw_token(u16 dev_pw_id,
869f05cddf9SRui Paulo 				       const struct wpabuf *pubkey,
870f05cddf9SRui Paulo 				       const struct wpabuf *dev_pw);
8715b9c547cSRui Paulo struct wpabuf * wps_nfc_token_build(int ndef, int id, struct wpabuf *pubkey,
8725b9c547cSRui Paulo 				    struct wpabuf *dev_pw);
8735b9c547cSRui Paulo int wps_nfc_gen_dh(struct wpabuf **pubkey, struct wpabuf **privkey);
874f05cddf9SRui Paulo struct wpabuf * wps_nfc_token_gen(int ndef, int *id, struct wpabuf **pubkey,
875f05cddf9SRui Paulo 				  struct wpabuf **privkey,
876f05cddf9SRui Paulo 				  struct wpabuf **dev_pw);
8775b9c547cSRui Paulo struct wpabuf * wps_build_nfc_handover_req(struct wps_context *ctx,
8785b9c547cSRui Paulo 					   struct wpabuf *nfc_dh_pubkey);
8795b9c547cSRui Paulo struct wpabuf * wps_build_nfc_handover_sel(struct wps_context *ctx,
8805b9c547cSRui Paulo 					   struct wpabuf *nfc_dh_pubkey,
8815b9c547cSRui Paulo 					   const u8 *bssid, int freq);
8825b9c547cSRui Paulo struct wpabuf * wps_build_nfc_handover_req_p2p(struct wps_context *ctx,
8835b9c547cSRui Paulo 					       struct wpabuf *nfc_dh_pubkey);
8845b9c547cSRui Paulo struct wpabuf * wps_build_nfc_handover_sel_p2p(struct wps_context *ctx,
8855b9c547cSRui Paulo 					       int nfc_dev_pw_id,
8865b9c547cSRui Paulo 					       struct wpabuf *nfc_dh_pubkey,
8875b9c547cSRui Paulo 					       struct wpabuf *nfc_dev_pw);
888f05cddf9SRui Paulo 
889f05cddf9SRui Paulo /* ndef.c */
890f05cddf9SRui Paulo struct wpabuf * ndef_parse_wifi(const struct wpabuf *buf);
891f05cddf9SRui Paulo struct wpabuf * ndef_build_wifi(const struct wpabuf *buf);
8925b9c547cSRui Paulo struct wpabuf * ndef_parse_p2p(const struct wpabuf *buf);
8935b9c547cSRui Paulo struct wpabuf * ndef_build_p2p(const struct wpabuf *buf);
894f05cddf9SRui Paulo 
895f05cddf9SRui Paulo #ifdef CONFIG_WPS_STRICT
896f05cddf9SRui Paulo int wps_validate_beacon(const struct wpabuf *wps_ie);
897f05cddf9SRui Paulo int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe,
898f05cddf9SRui Paulo 				   const u8 *addr);
899f05cddf9SRui Paulo int wps_validate_probe_req(const struct wpabuf *wps_ie, const u8 *addr);
900f05cddf9SRui Paulo int wps_validate_assoc_req(const struct wpabuf *wps_ie);
901f05cddf9SRui Paulo int wps_validate_assoc_resp(const struct wpabuf *wps_ie);
902f05cddf9SRui Paulo int wps_validate_m1(const struct wpabuf *tlvs);
903f05cddf9SRui Paulo int wps_validate_m2(const struct wpabuf *tlvs);
904f05cddf9SRui Paulo int wps_validate_m2d(const struct wpabuf *tlvs);
905f05cddf9SRui Paulo int wps_validate_m3(const struct wpabuf *tlvs);
906f05cddf9SRui Paulo int wps_validate_m4(const struct wpabuf *tlvs);
907f05cddf9SRui Paulo int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2);
908f05cddf9SRui Paulo int wps_validate_m5(const struct wpabuf *tlvs);
909f05cddf9SRui Paulo int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2);
910f05cddf9SRui Paulo int wps_validate_m6(const struct wpabuf *tlvs);
911f05cddf9SRui Paulo int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2);
912f05cddf9SRui Paulo int wps_validate_m7(const struct wpabuf *tlvs);
913f05cddf9SRui Paulo int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap, int wps2);
914f05cddf9SRui Paulo int wps_validate_m8(const struct wpabuf *tlvs);
915f05cddf9SRui Paulo int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap, int wps2);
916f05cddf9SRui Paulo int wps_validate_wsc_ack(const struct wpabuf *tlvs);
917f05cddf9SRui Paulo int wps_validate_wsc_nack(const struct wpabuf *tlvs);
918f05cddf9SRui Paulo int wps_validate_wsc_done(const struct wpabuf *tlvs);
919f05cddf9SRui Paulo int wps_validate_upnp_set_selected_registrar(const struct wpabuf *tlvs);
920f05cddf9SRui Paulo #else /* CONFIG_WPS_STRICT */
921f05cddf9SRui Paulo static inline int wps_validate_beacon(const struct wpabuf *wps_ie){
922f05cddf9SRui Paulo 	return 0;
923f05cddf9SRui Paulo }
924f05cddf9SRui Paulo 
925f05cddf9SRui Paulo static inline int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie,
926f05cddf9SRui Paulo 						 int probe, const u8 *addr)
927f05cddf9SRui Paulo {
928f05cddf9SRui Paulo 	return 0;
929f05cddf9SRui Paulo }
930f05cddf9SRui Paulo 
931f05cddf9SRui Paulo static inline int wps_validate_probe_req(const struct wpabuf *wps_ie,
932f05cddf9SRui Paulo 					 const u8 *addr)
933f05cddf9SRui Paulo {
934f05cddf9SRui Paulo 	return 0;
935f05cddf9SRui Paulo }
936f05cddf9SRui Paulo 
937f05cddf9SRui Paulo static inline int wps_validate_assoc_req(const struct wpabuf *wps_ie)
938f05cddf9SRui Paulo {
939f05cddf9SRui Paulo 	return 0;
940f05cddf9SRui Paulo }
941f05cddf9SRui Paulo 
942f05cddf9SRui Paulo static inline int wps_validate_assoc_resp(const struct wpabuf *wps_ie)
943f05cddf9SRui Paulo {
944f05cddf9SRui Paulo 	return 0;
945f05cddf9SRui Paulo }
946f05cddf9SRui Paulo 
947f05cddf9SRui Paulo static inline int wps_validate_m1(const struct wpabuf *tlvs)
948f05cddf9SRui Paulo {
949f05cddf9SRui Paulo 	return 0;
950f05cddf9SRui Paulo }
951f05cddf9SRui Paulo 
952f05cddf9SRui Paulo static inline int wps_validate_m2(const struct wpabuf *tlvs)
953f05cddf9SRui Paulo {
954f05cddf9SRui Paulo 	return 0;
955f05cddf9SRui Paulo }
956f05cddf9SRui Paulo 
957f05cddf9SRui Paulo static inline int wps_validate_m2d(const struct wpabuf *tlvs)
958f05cddf9SRui Paulo {
959f05cddf9SRui Paulo 	return 0;
960f05cddf9SRui Paulo }
961f05cddf9SRui Paulo 
962f05cddf9SRui Paulo static inline int wps_validate_m3(const struct wpabuf *tlvs)
963f05cddf9SRui Paulo {
964f05cddf9SRui Paulo 	return 0;
965f05cddf9SRui Paulo }
966f05cddf9SRui Paulo 
967f05cddf9SRui Paulo static inline int wps_validate_m4(const struct wpabuf *tlvs)
968f05cddf9SRui Paulo {
969f05cddf9SRui Paulo 	return 0;
970f05cddf9SRui Paulo }
971f05cddf9SRui Paulo 
972f05cddf9SRui Paulo static inline int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2)
973f05cddf9SRui Paulo {
974f05cddf9SRui Paulo 	return 0;
975f05cddf9SRui Paulo }
976f05cddf9SRui Paulo 
977f05cddf9SRui Paulo static inline int wps_validate_m5(const struct wpabuf *tlvs)
978f05cddf9SRui Paulo {
979f05cddf9SRui Paulo 	return 0;
980f05cddf9SRui Paulo }
981f05cddf9SRui Paulo 
982f05cddf9SRui Paulo static inline int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2)
983f05cddf9SRui Paulo {
984f05cddf9SRui Paulo 	return 0;
985f05cddf9SRui Paulo }
986f05cddf9SRui Paulo 
987f05cddf9SRui Paulo static inline int wps_validate_m6(const struct wpabuf *tlvs)
988f05cddf9SRui Paulo {
989f05cddf9SRui Paulo 	return 0;
990f05cddf9SRui Paulo }
991f05cddf9SRui Paulo 
992f05cddf9SRui Paulo static inline int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2)
993f05cddf9SRui Paulo {
994f05cddf9SRui Paulo 	return 0;
995f05cddf9SRui Paulo }
996f05cddf9SRui Paulo 
997f05cddf9SRui Paulo static inline int wps_validate_m7(const struct wpabuf *tlvs)
998f05cddf9SRui Paulo {
999f05cddf9SRui Paulo 	return 0;
1000f05cddf9SRui Paulo }
1001f05cddf9SRui Paulo 
1002f05cddf9SRui Paulo static inline int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap,
1003f05cddf9SRui Paulo 				       int wps2)
1004f05cddf9SRui Paulo {
1005f05cddf9SRui Paulo 	return 0;
1006f05cddf9SRui Paulo }
1007f05cddf9SRui Paulo 
1008f05cddf9SRui Paulo static inline int wps_validate_m8(const struct wpabuf *tlvs)
1009f05cddf9SRui Paulo {
1010f05cddf9SRui Paulo 	return 0;
1011f05cddf9SRui Paulo }
1012f05cddf9SRui Paulo 
1013f05cddf9SRui Paulo static inline int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap,
1014f05cddf9SRui Paulo 				       int wps2)
1015f05cddf9SRui Paulo {
1016f05cddf9SRui Paulo 	return 0;
1017f05cddf9SRui Paulo }
1018f05cddf9SRui Paulo 
1019f05cddf9SRui Paulo static inline int wps_validate_wsc_ack(const struct wpabuf *tlvs)
1020f05cddf9SRui Paulo {
1021f05cddf9SRui Paulo 	return 0;
1022f05cddf9SRui Paulo }
1023f05cddf9SRui Paulo 
1024f05cddf9SRui Paulo static inline int wps_validate_wsc_nack(const struct wpabuf *tlvs)
1025f05cddf9SRui Paulo {
1026f05cddf9SRui Paulo 	return 0;
1027f05cddf9SRui Paulo }
1028f05cddf9SRui Paulo 
1029f05cddf9SRui Paulo static inline int wps_validate_wsc_done(const struct wpabuf *tlvs)
1030f05cddf9SRui Paulo {
1031f05cddf9SRui Paulo 	return 0;
1032f05cddf9SRui Paulo }
1033f05cddf9SRui Paulo 
1034f05cddf9SRui Paulo static inline int wps_validate_upnp_set_selected_registrar(
1035f05cddf9SRui Paulo 	const struct wpabuf *tlvs)
1036f05cddf9SRui Paulo {
1037f05cddf9SRui Paulo 	return 0;
1038f05cddf9SRui Paulo }
1039f05cddf9SRui Paulo #endif /* CONFIG_WPS_STRICT */
1040e28a4053SRui Paulo 
104139beb93cSSam Leffler #endif /* WPS_H */
1042