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