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