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