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