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