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