xref: /dragonfly/contrib/wpa_supplicant/src/wps/wps.h (revision 9348a738)
1 /*
2  * Wi-Fi Protected Setup
3  * Copyright (c) 2007-2013, 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_H
10 #define WPS_H
11 
12 #include "wps_defs.h"
13 
14 /**
15  * enum wsc_op_code - EAP-WSC OP-Code values
16  */
17 enum wsc_op_code {
18 	WSC_UPnP = 0 /* No OP Code in UPnP transport */,
19 	WSC_Start = 0x01,
20 	WSC_ACK = 0x02,
21 	WSC_NACK = 0x03,
22 	WSC_MSG = 0x04,
23 	WSC_Done = 0x05,
24 	WSC_FRAG_ACK = 0x06
25 };
26 
27 struct wps_registrar;
28 struct upnp_wps_device_sm;
29 struct wps_er;
30 struct wps_parse_attr;
31 
32 /**
33  * struct wps_credential - WPS Credential
34  * @ssid: SSID
35  * @ssid_len: Length of SSID
36  * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
37  * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
38  * @key_idx: Key index
39  * @key: Key
40  * @key_len: Key length in octets
41  * @mac_addr: MAC address of the Credential receiver
42  * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
43  *	this may be %NULL, if not used
44  * @cred_attr_len: Length of cred_attr in octets
45  * @ap_channel: AP channel
46  */
47 struct wps_credential {
48 	u8 ssid[32];
49 	size_t ssid_len;
50 	u16 auth_type;
51 	u16 encr_type;
52 	u8 key_idx;
53 	u8 key[64];
54 	size_t key_len;
55 	u8 mac_addr[ETH_ALEN];
56 	const u8 *cred_attr;
57 	size_t cred_attr_len;
58 	u16 ap_channel;
59 };
60 
61 #define WPS_DEV_TYPE_LEN 8
62 #define WPS_DEV_TYPE_BUFSIZE 21
63 #define WPS_SEC_DEV_TYPE_MAX_LEN 128
64 /* maximum number of advertised WPS vendor extension attributes */
65 #define MAX_WPS_VENDOR_EXTENSIONS 10
66 /* maximum size of WPS Vendor extension attribute */
67 #define WPS_MAX_VENDOR_EXT_LEN 1024
68 /* maximum number of parsed WPS vendor extension attributes */
69 #define MAX_WPS_PARSE_VENDOR_EXT 10
70 
71 /**
72  * struct wps_device_data - WPS Device Data
73  * @mac_addr: Device MAC address
74  * @device_name: Device Name (0..32 octets encoded in UTF-8)
75  * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
76  * @model_name: Model Name (0..32 octets encoded in UTF-8)
77  * @model_number: Model Number (0..32 octets encoded in UTF-8)
78  * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
79  * @pri_dev_type: Primary Device Type
80  * @sec_dev_type: Array of secondary device types
81  * @num_sec_dev_type: Number of secondary device types
82  * @os_version: OS Version
83  * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
84  * @p2p: Whether the device is a P2P device
85  */
86 struct wps_device_data {
87 	u8 mac_addr[ETH_ALEN];
88 	char *device_name;
89 	char *manufacturer;
90 	char *model_name;
91 	char *model_number;
92 	char *serial_number;
93 	u8 pri_dev_type[WPS_DEV_TYPE_LEN];
94 #define WPS_SEC_DEVICE_TYPES 5
95 	u8 sec_dev_type[WPS_SEC_DEVICE_TYPES][WPS_DEV_TYPE_LEN];
96 	u8 num_sec_dev_types;
97 	u32 os_version;
98 	u8 rf_bands;
99 	u16 config_methods;
100 	struct wpabuf *vendor_ext_m1;
101 	struct wpabuf *vendor_ext[MAX_WPS_VENDOR_EXTENSIONS];
102 
103 	int p2p;
104 };
105 
106 /**
107  * struct wps_config - WPS configuration for a single registration protocol run
108  */
109 struct wps_config {
110 	/**
111 	 * wps - Pointer to long term WPS context
112 	 */
113 	struct wps_context *wps;
114 
115 	/**
116 	 * registrar - Whether this end is a Registrar
117 	 */
118 	int registrar;
119 
120 	/**
121 	 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
122 	 */
123 	const u8 *pin;
124 
125 	/**
126 	 * pin_len - Length on pin in octets
127 	 */
128 	size_t pin_len;
129 
130 	/**
131 	 * pbc - Whether this is protocol run uses PBC
132 	 */
133 	int pbc;
134 
135 	/**
136 	 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
137 	 */
138 	const struct wpabuf *assoc_wps_ie;
139 
140 	/**
141 	 * new_ap_settings - New AP settings (%NULL if not used)
142 	 *
143 	 * This parameter provides new AP settings when using a wireless
144 	 * stations as a Registrar to configure the AP. %NULL means that AP
145 	 * will not be reconfigured, i.e., the station will only learn the
146 	 * current AP settings by using AP PIN.
147 	 */
148 	const struct wps_credential *new_ap_settings;
149 
150 	/**
151 	 * peer_addr: MAC address of the peer in AP; %NULL if not AP
152 	 */
153 	const u8 *peer_addr;
154 
155 	/**
156 	 * use_psk_key - Use PSK format key in Credential
157 	 *
158 	 * Force PSK format to be used instead of ASCII passphrase when
159 	 * building Credential for an Enrollee. The PSK value is set in
160 	 * struct wpa_context::psk.
161 	 */
162 	int use_psk_key;
163 
164 	/**
165 	 * dev_pw_id - Device Password ID for Enrollee when PIN is used
166 	 */
167 	u16 dev_pw_id;
168 
169 	/**
170 	 * p2p_dev_addr - P2P Device Address from (Re)Association Request
171 	 *
172 	 * On AP/GO, this is set to the P2P Device Address of the associating
173 	 * P2P client if a P2P IE is included in the (Re)Association Request
174 	 * frame and the P2P Device Address is included. Otherwise, this is set
175 	 * to %NULL to indicate the station does not have a P2P Device Address.
176 	 */
177 	const u8 *p2p_dev_addr;
178 
179 	/**
180 	 * pbc_in_m1 - Do not remove PushButton config method in M1 (AP)
181 	 *
182 	 * This can be used to enable a workaround to allow Windows 7 to use
183 	 * PBC with the AP.
184 	 */
185 	int pbc_in_m1;
186 
187 	/**
188 	 * peer_pubkey_hash - Peer public key hash or %NULL if not known
189 	 */
190 	const u8 *peer_pubkey_hash;
191 };
192 
193 struct wps_data * wps_init(const struct wps_config *cfg);
194 
195 void wps_deinit(struct wps_data *data);
196 
197 /**
198  * enum wps_process_res - WPS message processing result
199  */
200 enum wps_process_res {
201 	/**
202 	 * WPS_DONE - Processing done
203 	 */
204 	WPS_DONE,
205 
206 	/**
207 	 * WPS_CONTINUE - Processing continues
208 	 */
209 	WPS_CONTINUE,
210 
211 	/**
212 	 * WPS_FAILURE - Processing failed
213 	 */
214 	WPS_FAILURE,
215 
216 	/**
217 	 * WPS_PENDING - Processing continues, but waiting for an external
218 	 *	event (e.g., UPnP message from an external Registrar)
219 	 */
220 	WPS_PENDING
221 };
222 enum wps_process_res wps_process_msg(struct wps_data *wps,
223 				     enum wsc_op_code op_code,
224 				     const struct wpabuf *msg);
225 
226 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
227 
228 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
229 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
230 int wps_ap_priority_compar(const struct wpabuf *wps_a,
231 			   const struct wpabuf *wps_b);
232 int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
233 			   int ver1_compat);
234 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
235 int wps_is_20(const struct wpabuf *msg);
236 
237 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
238 struct wpabuf * wps_build_assoc_resp_ie(void);
239 struct wpabuf * wps_build_probe_req_ie(u16 pw_id, struct wps_device_data *dev,
240 				       const u8 *uuid,
241 				       enum wps_request_type req_type,
242 				       unsigned int num_req_dev_types,
243 				       const u8 *req_dev_types);
244 
245 
246 /**
247  * struct wps_registrar_config - WPS Registrar configuration
248  */
249 struct wps_registrar_config {
250 	/**
251 	 * new_psk_cb - Callback for new PSK
252 	 * @ctx: Higher layer context data (cb_ctx)
253 	 * @mac_addr: MAC address of the Enrollee
254 	 * @p2p_dev_addr: P2P Device Address of the Enrollee or all zeros if not
255 	 * @psk: The new PSK
256 	 * @psk_len: The length of psk in octets
257 	 * Returns: 0 on success, -1 on failure
258 	 *
259 	 * This callback is called when a new per-device PSK is provisioned.
260 	 */
261 	int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *p2p_dev_addr,
262 			  const u8 *psk, size_t psk_len);
263 
264 	/**
265 	 * set_ie_cb - Callback for WPS IE changes
266 	 * @ctx: Higher layer context data (cb_ctx)
267 	 * @beacon_ie: WPS IE for Beacon
268 	 * @probe_resp_ie: WPS IE for Probe Response
269 	 * Returns: 0 on success, -1 on failure
270 	 *
271 	 * This callback is called whenever the WPS IE in Beacon or Probe
272 	 * Response frames needs to be changed (AP only). Callee is responsible
273 	 * for freeing the buffers.
274 	 */
275 	int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
276 			 struct wpabuf *probe_resp_ie);
277 
278 	/**
279 	 * pin_needed_cb - Callback for requesting a PIN
280 	 * @ctx: Higher layer context data (cb_ctx)
281 	 * @uuid_e: UUID-E of the unknown Enrollee
282 	 * @dev: Device Data from the unknown Enrollee
283 	 *
284 	 * This callback is called whenever an unknown Enrollee requests to use
285 	 * PIN method and a matching PIN (Device Password) is not found in
286 	 * Registrar data.
287 	 */
288 	void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
289 			      const struct wps_device_data *dev);
290 
291 	/**
292 	 * reg_success_cb - Callback for reporting successful registration
293 	 * @ctx: Higher layer context data (cb_ctx)
294 	 * @mac_addr: MAC address of the Enrollee
295 	 * @uuid_e: UUID-E of the Enrollee
296 	 * @dev_pw: Device Password (PIN) used during registration
297 	 * @dev_pw_len: Length of dev_pw in octets
298 	 *
299 	 * This callback is called whenever an Enrollee completes registration
300 	 * successfully.
301 	 */
302 	void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
303 			       const u8 *uuid_e, const u8 *dev_pw,
304 			       size_t dev_pw_len);
305 
306 	/**
307 	 * set_sel_reg_cb - Callback for reporting selected registrar changes
308 	 * @ctx: Higher layer context data (cb_ctx)
309 	 * @sel_reg: Whether the Registrar is selected
310 	 * @dev_passwd_id: Device Password ID to indicate with method or
311 	 *	specific password the Registrar intends to use
312 	 * @sel_reg_config_methods: Bit field of active config methods
313 	 *
314 	 * This callback is called whenever the Selected Registrar state
315 	 * changes (e.g., a new PIN becomes available or PBC is invoked). This
316 	 * callback is only used by External Registrar implementation;
317 	 * set_ie_cb() is used by AP implementation in similar caes, but it
318 	 * provides the full WPS IE data instead of just the minimal Registrar
319 	 * state information.
320 	 */
321 	void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
322 			       u16 sel_reg_config_methods);
323 
324 	/**
325 	 * enrollee_seen_cb - Callback for reporting Enrollee based on ProbeReq
326 	 * @ctx: Higher layer context data (cb_ctx)
327 	 * @addr: MAC address of the Enrollee
328 	 * @uuid_e: UUID of the Enrollee
329 	 * @pri_dev_type: Primary device type
330 	 * @config_methods: Config Methods
331 	 * @dev_password_id: Device Password ID
332 	 * @request_type: Request Type
333 	 * @dev_name: Device Name (if available)
334 	 */
335 	void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
336 				 const u8 *pri_dev_type, u16 config_methods,
337 				 u16 dev_password_id, u8 request_type,
338 				 const char *dev_name);
339 
340 	/**
341 	 * cb_ctx: Higher layer context data for Registrar callbacks
342 	 */
343 	void *cb_ctx;
344 
345 	/**
346 	 * skip_cred_build: Do not build credential
347 	 *
348 	 * This option can be used to disable internal code that builds
349 	 * Credential attribute into M8 based on the current network
350 	 * configuration and Enrollee capabilities. The extra_cred data will
351 	 * then be used as the Credential(s).
352 	 */
353 	int skip_cred_build;
354 
355 	/**
356 	 * extra_cred: Additional Credential attribute(s)
357 	 *
358 	 * This optional data (set to %NULL to disable) can be used to add
359 	 * Credential attribute(s) for other networks into M8. If
360 	 * skip_cred_build is set, this will also override the automatically
361 	 * generated Credential attribute.
362 	 */
363 	const u8 *extra_cred;
364 
365 	/**
366 	 * extra_cred_len: Length of extra_cred in octets
367 	 */
368 	size_t extra_cred_len;
369 
370 	/**
371 	 * disable_auto_conf - Disable auto-configuration on first registration
372 	 *
373 	 * By default, the AP that is started in not configured state will
374 	 * generate a random PSK and move to configured state when the first
375 	 * registration protocol run is completed successfully. This option can
376 	 * be used to disable this functionality and leave it up to an external
377 	 * program to take care of configuration. This requires the extra_cred
378 	 * to be set with a suitable Credential and skip_cred_build being used.
379 	 */
380 	int disable_auto_conf;
381 
382 	/**
383 	 * static_wep_only - Whether the BSS supports only static WEP
384 	 */
385 	int static_wep_only;
386 
387 	/**
388 	 * dualband - Whether this is a concurrent dualband AP
389 	 */
390 	int dualband;
391 
392 	/**
393 	 * force_per_enrollee_psk - Force per-Enrollee random PSK
394 	 *
395 	 * This forces per-Enrollee random PSK to be generated even if a default
396 	 * PSK is set for a network.
397 	 */
398 	int force_per_enrollee_psk;
399 };
400 
401 
402 /**
403  * enum wps_event - WPS event types
404  */
405 enum wps_event {
406 	/**
407 	 * WPS_EV_M2D - M2D received (Registrar did not know us)
408 	 */
409 	WPS_EV_M2D,
410 
411 	/**
412 	 * WPS_EV_FAIL - Registration failed
413 	 */
414 	WPS_EV_FAIL,
415 
416 	/**
417 	 * WPS_EV_SUCCESS - Registration succeeded
418 	 */
419 	WPS_EV_SUCCESS,
420 
421 	/**
422 	 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
423 	 */
424 	WPS_EV_PWD_AUTH_FAIL,
425 
426 	/**
427 	 * WPS_EV_PBC_OVERLAP - PBC session overlap detected
428 	 */
429 	WPS_EV_PBC_OVERLAP,
430 
431 	/**
432 	 * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
433 	 */
434 	WPS_EV_PBC_TIMEOUT,
435 
436 	/**
437 	 * WPS_EV_PBC_ACTIVE - PBC mode was activated
438 	 */
439 	WPS_EV_PBC_ACTIVE,
440 
441 	/**
442 	 * WPS_EV_PBC_DISABLE - PBC mode was disabled
443 	 */
444 	WPS_EV_PBC_DISABLE,
445 
446 	/**
447 	 * WPS_EV_ER_AP_ADD - ER: AP added
448 	 */
449 	WPS_EV_ER_AP_ADD,
450 
451 	/**
452 	 * WPS_EV_ER_AP_REMOVE - ER: AP removed
453 	 */
454 	WPS_EV_ER_AP_REMOVE,
455 
456 	/**
457 	 * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added
458 	 */
459 	WPS_EV_ER_ENROLLEE_ADD,
460 
461 	/**
462 	 * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed
463 	 */
464 	WPS_EV_ER_ENROLLEE_REMOVE,
465 
466 	/**
467 	 * WPS_EV_ER_AP_SETTINGS - ER: AP Settings learned
468 	 */
469 	WPS_EV_ER_AP_SETTINGS,
470 
471 	/**
472 	 * WPS_EV_ER_SET_SELECTED_REGISTRAR - ER: SetSelectedRegistrar event
473 	 */
474 	WPS_EV_ER_SET_SELECTED_REGISTRAR,
475 
476 	/**
477 	 * WPS_EV_AP_PIN_SUCCESS - External Registrar used correct AP PIN
478 	 */
479 	WPS_EV_AP_PIN_SUCCESS
480 };
481 
482 /**
483  * union wps_event_data - WPS event data
484  */
485 union wps_event_data {
486 	/**
487 	 * struct wps_event_m2d - M2D event data
488 	 */
489 	struct wps_event_m2d {
490 		u16 config_methods;
491 		const u8 *manufacturer;
492 		size_t manufacturer_len;
493 		const u8 *model_name;
494 		size_t model_name_len;
495 		const u8 *model_number;
496 		size_t model_number_len;
497 		const u8 *serial_number;
498 		size_t serial_number_len;
499 		const u8 *dev_name;
500 		size_t dev_name_len;
501 		const u8 *primary_dev_type; /* 8 octets */
502 		u16 config_error;
503 		u16 dev_password_id;
504 	} m2d;
505 
506 	/**
507 	 * struct wps_event_fail - Registration failure information
508 	 * @msg: enum wps_msg_type
509 	 */
510 	struct wps_event_fail {
511 		int msg;
512 		u16 config_error;
513 		u16 error_indication;
514 		u8 peer_macaddr[ETH_ALEN];
515 	} fail;
516 
517 	struct wps_event_success {
518 		u8 peer_macaddr[ETH_ALEN];
519 	} success;
520 
521 	struct wps_event_pwd_auth_fail {
522 		int enrollee;
523 		int part;
524 		u8 peer_macaddr[ETH_ALEN];
525 	} pwd_auth_fail;
526 
527 	struct wps_event_er_ap {
528 		const u8 *uuid;
529 		const u8 *mac_addr;
530 		const char *friendly_name;
531 		const char *manufacturer;
532 		const char *manufacturer_url;
533 		const char *model_description;
534 		const char *model_name;
535 		const char *model_number;
536 		const char *model_url;
537 		const char *serial_number;
538 		const char *upc;
539 		const u8 *pri_dev_type;
540 		u8 wps_state;
541 	} ap;
542 
543 	struct wps_event_er_enrollee {
544 		const u8 *uuid;
545 		const u8 *mac_addr;
546 		int m1_received;
547 		u16 config_methods;
548 		u16 dev_passwd_id;
549 		const u8 *pri_dev_type;
550 		const char *dev_name;
551 		const char *manufacturer;
552 		const char *model_name;
553 		const char *model_number;
554 		const char *serial_number;
555 	} enrollee;
556 
557 	struct wps_event_er_ap_settings {
558 		const u8 *uuid;
559 		const struct wps_credential *cred;
560 	} ap_settings;
561 
562 	struct wps_event_er_set_selected_registrar {
563 		const u8 *uuid;
564 		int sel_reg;
565 		u16 dev_passwd_id;
566 		u16 sel_reg_config_methods;
567 		enum {
568 			WPS_ER_SET_SEL_REG_START,
569 			WPS_ER_SET_SEL_REG_DONE,
570 			WPS_ER_SET_SEL_REG_FAILED
571 		} state;
572 	} set_sel_reg;
573 };
574 
575 /**
576  * struct upnp_pending_message - Pending PutWLANResponse messages
577  * @next: Pointer to next pending message or %NULL
578  * @addr: NewWLANEventMAC
579  * @msg: NewMessage
580  * @type: Message Type
581  */
582 struct upnp_pending_message {
583 	struct upnp_pending_message *next;
584 	u8 addr[ETH_ALEN];
585 	struct wpabuf *msg;
586 	enum wps_msg_type type;
587 };
588 
589 /**
590  * struct wps_context - Long term WPS context data
591  *
592  * This data is stored at the higher layer Authenticator or Supplicant data
593  * structures and it is maintained over multiple registration protocol runs.
594  */
595 struct wps_context {
596 	/**
597 	 * ap - Whether the local end is an access point
598 	 */
599 	int ap;
600 
601 	/**
602 	 * registrar - Pointer to WPS registrar data from wps_registrar_init()
603 	 */
604 	struct wps_registrar *registrar;
605 
606 	/**
607 	 * wps_state - Current WPS state
608 	 */
609 	enum wps_state wps_state;
610 
611 	/**
612 	 * ap_setup_locked - Whether AP setup is locked (only used at AP)
613 	 */
614 	int ap_setup_locked;
615 
616 	/**
617 	 * uuid - Own UUID
618 	 */
619 	u8 uuid[16];
620 
621 	/**
622 	 * ssid - SSID
623 	 *
624 	 * This SSID is used by the Registrar to fill in information for
625 	 * Credentials. In addition, AP uses it when acting as an Enrollee to
626 	 * notify Registrar of the current configuration.
627 	 */
628 	u8 ssid[32];
629 
630 	/**
631 	 * ssid_len - Length of ssid in octets
632 	 */
633 	size_t ssid_len;
634 
635 	/**
636 	 * dev - Own WPS device data
637 	 */
638 	struct wps_device_data dev;
639 
640 	/**
641 	 * dh_ctx - Context data for Diffie-Hellman operation
642 	 */
643 	void *dh_ctx;
644 
645 	/**
646 	 * dh_privkey - Diffie-Hellman private key
647 	 */
648 	struct wpabuf *dh_privkey;
649 
650 	/**
651 	 * dh_pubkey_oob - Diffie-Hellman public key
652 	 */
653 	struct wpabuf *dh_pubkey;
654 
655 	/**
656 	 * config_methods - Enabled configuration methods
657 	 *
658 	 * Bit field of WPS_CONFIG_*
659 	 */
660 	u16 config_methods;
661 
662 	/**
663 	 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
664 	 */
665 	u16 encr_types;
666 
667 	/**
668 	 * auth_types - Authentication types (bit field of WPS_AUTH_*)
669 	 */
670 	u16 auth_types;
671 
672 	/**
673 	 * network_key - The current Network Key (PSK) or %NULL to generate new
674 	 *
675 	 * If %NULL, Registrar will generate per-device PSK. In addition, AP
676 	 * uses this when acting as an Enrollee to notify Registrar of the
677 	 * current configuration.
678 	 *
679 	 * When using WPA/WPA2-Person, this key can be either the ASCII
680 	 * passphrase (8..63 characters) or the 32-octet PSK (64 hex
681 	 * characters). When this is set to the ASCII passphrase, the PSK can
682 	 * be provided in the psk buffer and used per-Enrollee to control which
683 	 * key type is included in the Credential (e.g., to reduce calculation
684 	 * need on low-powered devices by provisioning PSK while still allowing
685 	 * other devices to get the passphrase).
686 	 */
687 	u8 *network_key;
688 
689 	/**
690 	 * network_key_len - Length of network_key in octets
691 	 */
692 	size_t network_key_len;
693 
694 	/**
695 	 * psk - The current network PSK
696 	 *
697 	 * This optional value can be used to provide the current PSK if
698 	 * network_key is set to the ASCII passphrase.
699 	 */
700 	u8 psk[32];
701 
702 	/**
703 	 * psk_set - Whether psk value is set
704 	 */
705 	int psk_set;
706 
707 	/**
708 	 * ap_settings - AP Settings override for M7 (only used at AP)
709 	 *
710 	 * If %NULL, AP Settings attributes will be generated based on the
711 	 * current network configuration.
712 	 */
713 	u8 *ap_settings;
714 
715 	/**
716 	 * ap_settings_len - Length of ap_settings in octets
717 	 */
718 	size_t ap_settings_len;
719 
720 	/**
721 	 * friendly_name - Friendly Name (required for UPnP)
722 	 */
723 	char *friendly_name;
724 
725 	/**
726 	 * manufacturer_url - Manufacturer URL (optional for UPnP)
727 	 */
728 	char *manufacturer_url;
729 
730 	/**
731 	 * model_description - Model Description (recommended for UPnP)
732 	 */
733 	char *model_description;
734 
735 	/**
736 	 * model_url - Model URL (optional for UPnP)
737 	 */
738 	char *model_url;
739 
740 	/**
741 	 * upc - Universal Product Code (optional for UPnP)
742 	 */
743 	char *upc;
744 
745 	/**
746 	 * cred_cb - Callback to notify that new Credentials were received
747 	 * @ctx: Higher layer context data (cb_ctx)
748 	 * @cred: The received Credential
749 	 * Return: 0 on success, -1 on failure
750 	 */
751 	int (*cred_cb)(void *ctx, const struct wps_credential *cred);
752 
753 	/**
754 	 * event_cb - Event callback (state information about progress)
755 	 * @ctx: Higher layer context data (cb_ctx)
756 	 * @event: Event type
757 	 * @data: Event data
758 	 */
759 	void (*event_cb)(void *ctx, enum wps_event event,
760 			 union wps_event_data *data);
761 
762 	/**
763 	 * rf_band_cb - Fetch currently used RF band
764 	 * @ctx: Higher layer context data (cb_ctx)
765 	 * Return: Current used RF band or 0 if not known
766 	 */
767 	int (*rf_band_cb)(void *ctx);
768 
769 	/**
770 	 * cb_ctx: Higher layer context data for callbacks
771 	 */
772 	void *cb_ctx;
773 
774 	struct upnp_wps_device_sm *wps_upnp;
775 
776 	/* Pending messages from UPnP PutWLANResponse */
777 	struct upnp_pending_message *upnp_msgs;
778 
779 	u16 ap_nfc_dev_pw_id;
780 	struct wpabuf *ap_nfc_dh_pubkey;
781 	struct wpabuf *ap_nfc_dh_privkey;
782 	struct wpabuf *ap_nfc_dev_pw;
783 };
784 
785 struct wps_registrar *
786 wps_registrar_init(struct wps_context *wps,
787 		   const struct wps_registrar_config *cfg);
788 void wps_registrar_deinit(struct wps_registrar *reg);
789 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr,
790 			  const u8 *uuid, const u8 *pin, size_t pin_len,
791 			  int timeout);
792 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
793 int wps_registrar_wps_cancel(struct wps_registrar *reg);
794 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
795 int wps_registrar_button_pushed(struct wps_registrar *reg,
796 				const u8 *p2p_dev_addr);
797 void wps_registrar_complete(struct wps_registrar *registrar, const u8 *uuid_e,
798 			    const u8 *dev_pw, size_t dev_pw_len);
799 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
800 				const struct wpabuf *wps_data,
801 				int p2p_wildcard);
802 int wps_registrar_update_ie(struct wps_registrar *reg);
803 int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
804 			   char *buf, size_t buflen);
805 int wps_registrar_config_ap(struct wps_registrar *reg,
806 			    struct wps_credential *cred);
807 int wps_registrar_add_nfc_pw_token(struct wps_registrar *reg,
808 				   const u8 *pubkey_hash, u16 pw_id,
809 				   const u8 *dev_pw, size_t dev_pw_len,
810 				   int pk_hash_provided_oob);
811 int wps_registrar_add_nfc_password_token(struct wps_registrar *reg,
812 					 const u8 *oob_dev_pw,
813 					 size_t oob_dev_pw_len);
814 
815 int wps_build_credential_wrap(struct wpabuf *msg,
816 			      const struct wps_credential *cred);
817 
818 unsigned int wps_pin_checksum(unsigned int pin);
819 unsigned int wps_pin_valid(unsigned int pin);
820 unsigned int wps_generate_pin(void);
821 int wps_pin_str_valid(const char *pin);
822 void wps_free_pending_msgs(struct upnp_pending_message *msgs);
823 
824 struct wpabuf * wps_get_oob_cred(struct wps_context *wps, int rf_band,
825 				 int channel);
826 int wps_oob_use_cred(struct wps_context *wps, struct wps_parse_attr *attr);
827 int wps_attr_text(struct wpabuf *data, char *buf, char *end);
828 const char * wps_ei_str(enum wps_error_indication ei);
829 
830 struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname,
831 			    const char *filter);
832 void wps_er_refresh(struct wps_er *er);
833 void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx);
834 void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
835 			u16 sel_reg_config_methods);
836 int wps_er_pbc(struct wps_er *er, const u8 *uuid, const u8 *addr);
837 const u8 * wps_er_get_sta_uuid(struct wps_er *er, const u8 *addr);
838 int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *addr,
839 		 const u8 *pin, size_t pin_len);
840 int wps_er_set_config(struct wps_er *er, const u8 *uuid, const u8 *addr,
841 		      const struct wps_credential *cred);
842 int wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *addr,
843 		  const u8 *pin, size_t pin_len,
844 		  const struct wps_credential *cred);
845 struct wpabuf * wps_er_config_token_from_cred(struct wps_context *wps,
846 					      struct wps_credential *cred);
847 struct wpabuf * wps_er_nfc_config_token(struct wps_er *er, const u8 *uuid,
848 					const u8 *addr);
849 struct wpabuf * wps_er_nfc_handover_sel(struct wps_er *er,
850 					struct wps_context *wps, const u8 *uuid,
851 					const u8 *addr, struct wpabuf *pubkey);
852 
853 int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
854 char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
855 			    size_t buf_len);
856 void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
857 u16 wps_config_methods_str2bin(const char *str);
858 struct wpabuf * wps_build_nfc_pw_token(u16 dev_pw_id,
859 				       const struct wpabuf *pubkey,
860 				       const struct wpabuf *dev_pw);
861 struct wpabuf * wps_nfc_token_build(int ndef, int id, struct wpabuf *pubkey,
862 				    struct wpabuf *dev_pw);
863 int wps_nfc_gen_dh(struct wpabuf **pubkey, struct wpabuf **privkey);
864 struct wpabuf * wps_nfc_token_gen(int ndef, int *id, struct wpabuf **pubkey,
865 				  struct wpabuf **privkey,
866 				  struct wpabuf **dev_pw);
867 struct wpabuf * wps_build_nfc_handover_req(struct wps_context *ctx,
868 					   struct wpabuf *nfc_dh_pubkey);
869 struct wpabuf * wps_build_nfc_handover_sel(struct wps_context *ctx,
870 					   struct wpabuf *nfc_dh_pubkey,
871 					   const u8 *bssid, int freq);
872 struct wpabuf * wps_build_nfc_handover_req_p2p(struct wps_context *ctx,
873 					       struct wpabuf *nfc_dh_pubkey);
874 struct wpabuf * wps_build_nfc_handover_sel_p2p(struct wps_context *ctx,
875 					       int nfc_dev_pw_id,
876 					       struct wpabuf *nfc_dh_pubkey,
877 					       struct wpabuf *nfc_dev_pw);
878 
879 /* ndef.c */
880 struct wpabuf * ndef_parse_wifi(const struct wpabuf *buf);
881 struct wpabuf * ndef_build_wifi(const struct wpabuf *buf);
882 struct wpabuf * ndef_parse_p2p(const struct wpabuf *buf);
883 struct wpabuf * ndef_build_p2p(const struct wpabuf *buf);
884 
885 #ifdef CONFIG_WPS_STRICT
886 int wps_validate_beacon(const struct wpabuf *wps_ie);
887 int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe,
888 				   const u8 *addr);
889 int wps_validate_probe_req(const struct wpabuf *wps_ie, const u8 *addr);
890 int wps_validate_assoc_req(const struct wpabuf *wps_ie);
891 int wps_validate_assoc_resp(const struct wpabuf *wps_ie);
892 int wps_validate_m1(const struct wpabuf *tlvs);
893 int wps_validate_m2(const struct wpabuf *tlvs);
894 int wps_validate_m2d(const struct wpabuf *tlvs);
895 int wps_validate_m3(const struct wpabuf *tlvs);
896 int wps_validate_m4(const struct wpabuf *tlvs);
897 int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2);
898 int wps_validate_m5(const struct wpabuf *tlvs);
899 int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2);
900 int wps_validate_m6(const struct wpabuf *tlvs);
901 int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2);
902 int wps_validate_m7(const struct wpabuf *tlvs);
903 int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap, int wps2);
904 int wps_validate_m8(const struct wpabuf *tlvs);
905 int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap, int wps2);
906 int wps_validate_wsc_ack(const struct wpabuf *tlvs);
907 int wps_validate_wsc_nack(const struct wpabuf *tlvs);
908 int wps_validate_wsc_done(const struct wpabuf *tlvs);
909 int wps_validate_upnp_set_selected_registrar(const struct wpabuf *tlvs);
910 #else /* CONFIG_WPS_STRICT */
911 static inline int wps_validate_beacon(const struct wpabuf *wps_ie){
912 	return 0;
913 }
914 
915 static inline int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie,
916 						 int probe, const u8 *addr)
917 {
918 	return 0;
919 }
920 
921 static inline int wps_validate_probe_req(const struct wpabuf *wps_ie,
922 					 const u8 *addr)
923 {
924 	return 0;
925 }
926 
927 static inline int wps_validate_assoc_req(const struct wpabuf *wps_ie)
928 {
929 	return 0;
930 }
931 
932 static inline int wps_validate_assoc_resp(const struct wpabuf *wps_ie)
933 {
934 	return 0;
935 }
936 
937 static inline int wps_validate_m1(const struct wpabuf *tlvs)
938 {
939 	return 0;
940 }
941 
942 static inline int wps_validate_m2(const struct wpabuf *tlvs)
943 {
944 	return 0;
945 }
946 
947 static inline int wps_validate_m2d(const struct wpabuf *tlvs)
948 {
949 	return 0;
950 }
951 
952 static inline int wps_validate_m3(const struct wpabuf *tlvs)
953 {
954 	return 0;
955 }
956 
957 static inline int wps_validate_m4(const struct wpabuf *tlvs)
958 {
959 	return 0;
960 }
961 
962 static inline int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2)
963 {
964 	return 0;
965 }
966 
967 static inline int wps_validate_m5(const struct wpabuf *tlvs)
968 {
969 	return 0;
970 }
971 
972 static inline int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2)
973 {
974 	return 0;
975 }
976 
977 static inline int wps_validate_m6(const struct wpabuf *tlvs)
978 {
979 	return 0;
980 }
981 
982 static inline int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2)
983 {
984 	return 0;
985 }
986 
987 static inline int wps_validate_m7(const struct wpabuf *tlvs)
988 {
989 	return 0;
990 }
991 
992 static inline int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap,
993 				       int wps2)
994 {
995 	return 0;
996 }
997 
998 static inline int wps_validate_m8(const struct wpabuf *tlvs)
999 {
1000 	return 0;
1001 }
1002 
1003 static inline int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap,
1004 				       int wps2)
1005 {
1006 	return 0;
1007 }
1008 
1009 static inline int wps_validate_wsc_ack(const struct wpabuf *tlvs)
1010 {
1011 	return 0;
1012 }
1013 
1014 static inline int wps_validate_wsc_nack(const struct wpabuf *tlvs)
1015 {
1016 	return 0;
1017 }
1018 
1019 static inline int wps_validate_wsc_done(const struct wpabuf *tlvs)
1020 {
1021 	return 0;
1022 }
1023 
1024 static inline int wps_validate_upnp_set_selected_registrar(
1025 	const struct wpabuf *tlvs)
1026 {
1027 	return 0;
1028 }
1029 #endif /* CONFIG_WPS_STRICT */
1030 
1031 #endif /* WPS_H */
1032