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