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