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