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