1189251Ssam/* 2189251Ssam * Wi-Fi Protected Setup 3252726Srpaulo * Copyright (c) 2007-2012, Jouni Malinen <j@w1.fi> 4189251Ssam * 5252726Srpaulo * This software may be distributed under the terms of the BSD license. 6252726Srpaulo * See README for more details. 7189251Ssam */ 8189251Ssam 9189251Ssam#ifndef WPS_H 10189251Ssam#define WPS_H 11189251Ssam 12189251Ssam#include "wps_defs.h" 13189251Ssam 14189251Ssam/** 15189251Ssam * enum wsc_op_code - EAP-WSC OP-Code values 16189251Ssam */ 17189251Ssamenum wsc_op_code { 18189251Ssam WSC_UPnP = 0 /* No OP Code in UPnP transport */, 19189251Ssam WSC_Start = 0x01, 20189251Ssam WSC_ACK = 0x02, 21189251Ssam WSC_NACK = 0x03, 22189251Ssam WSC_MSG = 0x04, 23189251Ssam WSC_Done = 0x05, 24189251Ssam WSC_FRAG_ACK = 0x06 25189251Ssam}; 26189251Ssam 27189251Ssamstruct wps_registrar; 28189251Ssamstruct upnp_wps_device_sm; 29214734Srpaulostruct wps_er; 30252726Srpaulostruct wps_parse_attr; 31189251Ssam 32189251Ssam/** 33189251Ssam * struct wps_credential - WPS Credential 34189251Ssam * @ssid: SSID 35189251Ssam * @ssid_len: Length of SSID 36189251Ssam * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags) 37189251Ssam * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags) 38189251Ssam * @key_idx: Key index 39189251Ssam * @key: Key 40189251Ssam * @key_len: Key length in octets 41209158Srpaulo * @mac_addr: MAC address of the Credential receiver 42189251Ssam * @cred_attr: Unparsed Credential attribute data (used only in cred_cb()); 43189251Ssam * this may be %NULL, if not used 44189251Ssam * @cred_attr_len: Length of cred_attr in octets 45252726Srpaulo * @ap_channel: AP channel 46189251Ssam */ 47189251Ssamstruct wps_credential { 48189251Ssam u8 ssid[32]; 49189251Ssam size_t ssid_len; 50189251Ssam u16 auth_type; 51189251Ssam u16 encr_type; 52189251Ssam u8 key_idx; 53189251Ssam u8 key[64]; 54189251Ssam size_t key_len; 55189251Ssam u8 mac_addr[ETH_ALEN]; 56189251Ssam const u8 *cred_attr; 57189251Ssam size_t cred_attr_len; 58252726Srpaulo u16 ap_channel; 59189251Ssam}; 60189251Ssam 61214734Srpaulo#define WPS_DEV_TYPE_LEN 8 62214734Srpaulo#define WPS_DEV_TYPE_BUFSIZE 21 63252726Srpaulo#define WPS_SEC_DEV_TYPE_MAX_LEN 128 64252726Srpaulo/* maximum number of advertised WPS vendor extension attributes */ 65252726Srpaulo#define MAX_WPS_VENDOR_EXTENSIONS 10 66252726Srpaulo/* maximum size of WPS Vendor extension attribute */ 67252726Srpaulo#define WPS_MAX_VENDOR_EXT_LEN 1024 68252726Srpaulo/* maximum number of parsed WPS vendor extension attributes */ 69252726Srpaulo#define MAX_WPS_PARSE_VENDOR_EXT 10 70214734Srpaulo 71189251Ssam/** 72189251Ssam * struct wps_device_data - WPS Device Data 73189251Ssam * @mac_addr: Device MAC address 74189251Ssam * @device_name: Device Name (0..32 octets encoded in UTF-8) 75189251Ssam * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8) 76189251Ssam * @model_name: Model Name (0..32 octets encoded in UTF-8) 77189251Ssam * @model_number: Model Number (0..32 octets encoded in UTF-8) 78189251Ssam * @serial_number: Serial Number (0..32 octets encoded in UTF-8) 79214734Srpaulo * @pri_dev_type: Primary Device Type 80252726Srpaulo * @sec_dev_type: Array of secondary device types 81252726Srpaulo * @num_sec_dev_type: Number of secondary device types 82189251Ssam * @os_version: OS Version 83189251Ssam * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags) 84252726Srpaulo * @p2p: Whether the device is a P2P device 85189251Ssam */ 86189251Ssamstruct wps_device_data { 87189251Ssam u8 mac_addr[ETH_ALEN]; 88189251Ssam char *device_name; 89189251Ssam char *manufacturer; 90189251Ssam char *model_name; 91189251Ssam char *model_number; 92189251Ssam char *serial_number; 93214734Srpaulo u8 pri_dev_type[WPS_DEV_TYPE_LEN]; 94252726Srpaulo#define WPS_SEC_DEVICE_TYPES 5 95252726Srpaulo u8 sec_dev_type[WPS_SEC_DEVICE_TYPES][WPS_DEV_TYPE_LEN]; 96252726Srpaulo u8 num_sec_dev_types; 97189251Ssam u32 os_version; 98189251Ssam u8 rf_bands; 99252726Srpaulo u16 config_methods; 100252726Srpaulo struct wpabuf *vendor_ext_m1; 101252726Srpaulo struct wpabuf *vendor_ext[MAX_WPS_VENDOR_EXTENSIONS]; 102189251Ssam 103252726Srpaulo int p2p; 104214734Srpaulo}; 105214734Srpaulo 106189251Ssam/** 107189251Ssam * struct wps_config - WPS configuration for a single registration protocol run 108189251Ssam */ 109189251Ssamstruct wps_config { 110189251Ssam /** 111189251Ssam * wps - Pointer to long term WPS context 112189251Ssam */ 113189251Ssam struct wps_context *wps; 114189251Ssam 115189251Ssam /** 116189251Ssam * registrar - Whether this end is a Registrar 117189251Ssam */ 118189251Ssam int registrar; 119189251Ssam 120189251Ssam /** 121189251Ssam * pin - Enrollee Device Password (%NULL for Registrar or PBC) 122189251Ssam */ 123189251Ssam const u8 *pin; 124189251Ssam 125189251Ssam /** 126189251Ssam * pin_len - Length on pin in octets 127189251Ssam */ 128189251Ssam size_t pin_len; 129189251Ssam 130189251Ssam /** 131189251Ssam * pbc - Whether this is protocol run uses PBC 132189251Ssam */ 133189251Ssam int pbc; 134189251Ssam 135189251Ssam /** 136189251Ssam * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP) 137189251Ssam */ 138189251Ssam const struct wpabuf *assoc_wps_ie; 139214734Srpaulo 140214734Srpaulo /** 141214734Srpaulo * new_ap_settings - New AP settings (%NULL if not used) 142214734Srpaulo * 143214734Srpaulo * This parameter provides new AP settings when using a wireless 144214734Srpaulo * stations as a Registrar to configure the AP. %NULL means that AP 145214734Srpaulo * will not be reconfigured, i.e., the station will only learn the 146214734Srpaulo * current AP settings by using AP PIN. 147214734Srpaulo */ 148214734Srpaulo const struct wps_credential *new_ap_settings; 149214734Srpaulo 150214734Srpaulo /** 151214734Srpaulo * peer_addr: MAC address of the peer in AP; %NULL if not AP 152214734Srpaulo */ 153214734Srpaulo const u8 *peer_addr; 154214734Srpaulo 155214734Srpaulo /** 156214734Srpaulo * use_psk_key - Use PSK format key in Credential 157214734Srpaulo * 158214734Srpaulo * Force PSK format to be used instead of ASCII passphrase when 159214734Srpaulo * building Credential for an Enrollee. The PSK value is set in 160214734Srpaulo * struct wpa_context::psk. 161214734Srpaulo */ 162214734Srpaulo int use_psk_key; 163252726Srpaulo 164252726Srpaulo /** 165252726Srpaulo * dev_pw_id - Device Password ID for Enrollee when PIN is used 166252726Srpaulo */ 167252726Srpaulo u16 dev_pw_id; 168252726Srpaulo 169252726Srpaulo /** 170252726Srpaulo * p2p_dev_addr - P2P Device Address from (Re)Association Request 171252726Srpaulo * 172252726Srpaulo * On AP/GO, this is set to the P2P Device Address of the associating 173252726Srpaulo * P2P client if a P2P IE is included in the (Re)Association Request 174252726Srpaulo * frame and the P2P Device Address is included. Otherwise, this is set 175252726Srpaulo * to %NULL to indicate the station does not have a P2P Device Address. 176252726Srpaulo */ 177252726Srpaulo const u8 *p2p_dev_addr; 178252726Srpaulo 179252726Srpaulo /** 180252726Srpaulo * pbc_in_m1 - Do not remove PushButton config method in M1 (AP) 181252726Srpaulo * 182252726Srpaulo * This can be used to enable a workaround to allow Windows 7 to use 183252726Srpaulo * PBC with the AP. 184252726Srpaulo */ 185252726Srpaulo int pbc_in_m1; 186189251Ssam}; 187189251Ssam 188189251Ssamstruct wps_data * wps_init(const struct wps_config *cfg); 189189251Ssam 190189251Ssamvoid wps_deinit(struct wps_data *data); 191189251Ssam 192189251Ssam/** 193189251Ssam * enum wps_process_res - WPS message processing result 194189251Ssam */ 195189251Ssamenum wps_process_res { 196189251Ssam /** 197189251Ssam * WPS_DONE - Processing done 198189251Ssam */ 199189251Ssam WPS_DONE, 200189251Ssam 201189251Ssam /** 202189251Ssam * WPS_CONTINUE - Processing continues 203189251Ssam */ 204189251Ssam WPS_CONTINUE, 205189251Ssam 206189251Ssam /** 207189251Ssam * WPS_FAILURE - Processing failed 208189251Ssam */ 209189251Ssam WPS_FAILURE, 210189251Ssam 211189251Ssam /** 212189251Ssam * WPS_PENDING - Processing continues, but waiting for an external 213189251Ssam * event (e.g., UPnP message from an external Registrar) 214189251Ssam */ 215189251Ssam WPS_PENDING 216189251Ssam}; 217189251Ssamenum wps_process_res wps_process_msg(struct wps_data *wps, 218189251Ssam enum wsc_op_code op_code, 219189251Ssam const struct wpabuf *msg); 220189251Ssam 221189251Ssamstruct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code); 222189251Ssam 223189251Ssamint wps_is_selected_pbc_registrar(const struct wpabuf *msg); 224189251Ssamint wps_is_selected_pin_registrar(const struct wpabuf *msg); 225252726Srpauloint wps_ap_priority_compar(const struct wpabuf *wps_a, 226252726Srpaulo const struct wpabuf *wps_b); 227252726Srpauloint wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr, 228252726Srpaulo int ver1_compat); 229189251Ssamconst u8 * wps_get_uuid_e(const struct wpabuf *msg); 230252726Srpauloint wps_is_20(const struct wpabuf *msg); 231189251Ssam 232189251Ssamstruct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type); 233214734Srpaulostruct wpabuf * wps_build_assoc_resp_ie(void); 234252726Srpaulostruct wpabuf * wps_build_probe_req_ie(u16 pw_id, struct wps_device_data *dev, 235189251Ssam const u8 *uuid, 236252726Srpaulo enum wps_request_type req_type, 237252726Srpaulo unsigned int num_req_dev_types, 238252726Srpaulo const u8 *req_dev_types); 239189251Ssam 240189251Ssam 241189251Ssam/** 242189251Ssam * struct wps_registrar_config - WPS Registrar configuration 243189251Ssam */ 244189251Ssamstruct wps_registrar_config { 245189251Ssam /** 246189251Ssam * new_psk_cb - Callback for new PSK 247189251Ssam * @ctx: Higher layer context data (cb_ctx) 248189251Ssam * @mac_addr: MAC address of the Enrollee 249189251Ssam * @psk: The new PSK 250189251Ssam * @psk_len: The length of psk in octets 251189251Ssam * Returns: 0 on success, -1 on failure 252189251Ssam * 253189251Ssam * This callback is called when a new per-device PSK is provisioned. 254189251Ssam */ 255189251Ssam int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk, 256189251Ssam size_t psk_len); 257189251Ssam 258189251Ssam /** 259189251Ssam * set_ie_cb - Callback for WPS IE changes 260189251Ssam * @ctx: Higher layer context data (cb_ctx) 261189251Ssam * @beacon_ie: WPS IE for Beacon 262189251Ssam * @probe_resp_ie: WPS IE for Probe Response 263189251Ssam * Returns: 0 on success, -1 on failure 264189251Ssam * 265189251Ssam * This callback is called whenever the WPS IE in Beacon or Probe 266214734Srpaulo * Response frames needs to be changed (AP only). Callee is responsible 267214734Srpaulo * for freeing the buffers. 268189251Ssam */ 269214734Srpaulo int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie, 270214734Srpaulo struct wpabuf *probe_resp_ie); 271189251Ssam 272189251Ssam /** 273189251Ssam * pin_needed_cb - Callback for requesting a PIN 274189251Ssam * @ctx: Higher layer context data (cb_ctx) 275189251Ssam * @uuid_e: UUID-E of the unknown Enrollee 276189251Ssam * @dev: Device Data from the unknown Enrollee 277189251Ssam * 278189251Ssam * This callback is called whenever an unknown Enrollee requests to use 279189251Ssam * PIN method and a matching PIN (Device Password) is not found in 280189251Ssam * Registrar data. 281189251Ssam */ 282189251Ssam void (*pin_needed_cb)(void *ctx, const u8 *uuid_e, 283189251Ssam const struct wps_device_data *dev); 284189251Ssam 285189251Ssam /** 286189251Ssam * reg_success_cb - Callback for reporting successful registration 287189251Ssam * @ctx: Higher layer context data (cb_ctx) 288189251Ssam * @mac_addr: MAC address of the Enrollee 289189251Ssam * @uuid_e: UUID-E of the Enrollee 290252726Srpaulo * @dev_pw: Device Password (PIN) used during registration 291252726Srpaulo * @dev_pw_len: Length of dev_pw in octets 292189251Ssam * 293189251Ssam * This callback is called whenever an Enrollee completes registration 294189251Ssam * successfully. 295189251Ssam */ 296189251Ssam void (*reg_success_cb)(void *ctx, const u8 *mac_addr, 297252726Srpaulo const u8 *uuid_e, const u8 *dev_pw, 298252726Srpaulo size_t dev_pw_len); 299189251Ssam 300189251Ssam /** 301214734Srpaulo * set_sel_reg_cb - Callback for reporting selected registrar changes 302214734Srpaulo * @ctx: Higher layer context data (cb_ctx) 303214734Srpaulo * @sel_reg: Whether the Registrar is selected 304214734Srpaulo * @dev_passwd_id: Device Password ID to indicate with method or 305214734Srpaulo * specific password the Registrar intends to use 306214734Srpaulo * @sel_reg_config_methods: Bit field of active config methods 307214734Srpaulo * 308214734Srpaulo * This callback is called whenever the Selected Registrar state 309214734Srpaulo * changes (e.g., a new PIN becomes available or PBC is invoked). This 310214734Srpaulo * callback is only used by External Registrar implementation; 311214734Srpaulo * set_ie_cb() is used by AP implementation in similar caes, but it 312214734Srpaulo * provides the full WPS IE data instead of just the minimal Registrar 313214734Srpaulo * state information. 314214734Srpaulo */ 315214734Srpaulo void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id, 316214734Srpaulo u16 sel_reg_config_methods); 317214734Srpaulo 318214734Srpaulo /** 319214734Srpaulo * enrollee_seen_cb - Callback for reporting Enrollee based on ProbeReq 320214734Srpaulo * @ctx: Higher layer context data (cb_ctx) 321214734Srpaulo * @addr: MAC address of the Enrollee 322214734Srpaulo * @uuid_e: UUID of the Enrollee 323214734Srpaulo * @pri_dev_type: Primary device type 324214734Srpaulo * @config_methods: Config Methods 325214734Srpaulo * @dev_password_id: Device Password ID 326214734Srpaulo * @request_type: Request Type 327214734Srpaulo * @dev_name: Device Name (if available) 328214734Srpaulo */ 329214734Srpaulo void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e, 330214734Srpaulo const u8 *pri_dev_type, u16 config_methods, 331214734Srpaulo u16 dev_password_id, u8 request_type, 332214734Srpaulo const char *dev_name); 333214734Srpaulo 334214734Srpaulo /** 335189251Ssam * cb_ctx: Higher layer context data for Registrar callbacks 336189251Ssam */ 337189251Ssam void *cb_ctx; 338189251Ssam 339189251Ssam /** 340189251Ssam * skip_cred_build: Do not build credential 341189251Ssam * 342189251Ssam * This option can be used to disable internal code that builds 343189251Ssam * Credential attribute into M8 based on the current network 344189251Ssam * configuration and Enrollee capabilities. The extra_cred data will 345189251Ssam * then be used as the Credential(s). 346189251Ssam */ 347189251Ssam int skip_cred_build; 348189251Ssam 349189251Ssam /** 350189251Ssam * extra_cred: Additional Credential attribute(s) 351189251Ssam * 352189251Ssam * This optional data (set to %NULL to disable) can be used to add 353189251Ssam * Credential attribute(s) for other networks into M8. If 354189251Ssam * skip_cred_build is set, this will also override the automatically 355189251Ssam * generated Credential attribute. 356189251Ssam */ 357189251Ssam const u8 *extra_cred; 358189251Ssam 359189251Ssam /** 360189251Ssam * extra_cred_len: Length of extra_cred in octets 361189251Ssam */ 362189251Ssam size_t extra_cred_len; 363189251Ssam 364189251Ssam /** 365189251Ssam * disable_auto_conf - Disable auto-configuration on first registration 366189251Ssam * 367189251Ssam * By default, the AP that is started in not configured state will 368189251Ssam * generate a random PSK and move to configured state when the first 369189251Ssam * registration protocol run is completed successfully. This option can 370189251Ssam * be used to disable this functionality and leave it up to an external 371189251Ssam * program to take care of configuration. This requires the extra_cred 372189251Ssam * to be set with a suitable Credential and skip_cred_build being used. 373189251Ssam */ 374189251Ssam int disable_auto_conf; 375209158Srpaulo 376209158Srpaulo /** 377209158Srpaulo * static_wep_only - Whether the BSS supports only static WEP 378209158Srpaulo */ 379209158Srpaulo int static_wep_only; 380252726Srpaulo 381252726Srpaulo /** 382252726Srpaulo * dualband - Whether this is a concurrent dualband AP 383252726Srpaulo */ 384252726Srpaulo int dualband; 385189251Ssam}; 386189251Ssam 387189251Ssam 388189251Ssam/** 389189251Ssam * enum wps_event - WPS event types 390189251Ssam */ 391189251Ssamenum wps_event { 392189251Ssam /** 393189251Ssam * WPS_EV_M2D - M2D received (Registrar did not know us) 394189251Ssam */ 395189251Ssam WPS_EV_M2D, 396189251Ssam 397189251Ssam /** 398189251Ssam * WPS_EV_FAIL - Registration failed 399189251Ssam */ 400189251Ssam WPS_EV_FAIL, 401189251Ssam 402189251Ssam /** 403189251Ssam * WPS_EV_SUCCESS - Registration succeeded 404189251Ssam */ 405189251Ssam WPS_EV_SUCCESS, 406189251Ssam 407189251Ssam /** 408189251Ssam * WPS_EV_PWD_AUTH_FAIL - Password authentication failed 409189251Ssam */ 410209158Srpaulo WPS_EV_PWD_AUTH_FAIL, 411209158Srpaulo 412209158Srpaulo /** 413209158Srpaulo * WPS_EV_PBC_OVERLAP - PBC session overlap detected 414209158Srpaulo */ 415209158Srpaulo WPS_EV_PBC_OVERLAP, 416209158Srpaulo 417209158Srpaulo /** 418209158Srpaulo * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start 419209158Srpaulo */ 420214734Srpaulo WPS_EV_PBC_TIMEOUT, 421214734Srpaulo 422214734Srpaulo /** 423214734Srpaulo * WPS_EV_ER_AP_ADD - ER: AP added 424214734Srpaulo */ 425214734Srpaulo WPS_EV_ER_AP_ADD, 426214734Srpaulo 427214734Srpaulo /** 428214734Srpaulo * WPS_EV_ER_AP_REMOVE - ER: AP removed 429214734Srpaulo */ 430214734Srpaulo WPS_EV_ER_AP_REMOVE, 431214734Srpaulo 432214734Srpaulo /** 433214734Srpaulo * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added 434214734Srpaulo */ 435214734Srpaulo WPS_EV_ER_ENROLLEE_ADD, 436214734Srpaulo 437214734Srpaulo /** 438214734Srpaulo * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed 439214734Srpaulo */ 440252726Srpaulo WPS_EV_ER_ENROLLEE_REMOVE, 441252726Srpaulo 442252726Srpaulo /** 443252726Srpaulo * WPS_EV_ER_AP_SETTINGS - ER: AP Settings learned 444252726Srpaulo */ 445252726Srpaulo WPS_EV_ER_AP_SETTINGS, 446252726Srpaulo 447252726Srpaulo /** 448252726Srpaulo * WPS_EV_ER_SET_SELECTED_REGISTRAR - ER: SetSelectedRegistrar event 449252726Srpaulo */ 450252726Srpaulo WPS_EV_ER_SET_SELECTED_REGISTRAR, 451252726Srpaulo 452252726Srpaulo /** 453252726Srpaulo * WPS_EV_AP_PIN_SUCCESS - External Registrar used correct AP PIN 454252726Srpaulo */ 455252726Srpaulo WPS_EV_AP_PIN_SUCCESS 456189251Ssam}; 457189251Ssam 458189251Ssam/** 459189251Ssam * union wps_event_data - WPS event data 460189251Ssam */ 461189251Ssamunion wps_event_data { 462189251Ssam /** 463189251Ssam * struct wps_event_m2d - M2D event data 464189251Ssam */ 465189251Ssam struct wps_event_m2d { 466189251Ssam u16 config_methods; 467189251Ssam const u8 *manufacturer; 468189251Ssam size_t manufacturer_len; 469189251Ssam const u8 *model_name; 470189251Ssam size_t model_name_len; 471189251Ssam const u8 *model_number; 472189251Ssam size_t model_number_len; 473189251Ssam const u8 *serial_number; 474189251Ssam size_t serial_number_len; 475189251Ssam const u8 *dev_name; 476189251Ssam size_t dev_name_len; 477189251Ssam const u8 *primary_dev_type; /* 8 octets */ 478189251Ssam u16 config_error; 479189251Ssam u16 dev_password_id; 480189251Ssam } m2d; 481189251Ssam 482189251Ssam /** 483189251Ssam * struct wps_event_fail - Registration failure information 484189251Ssam * @msg: enum wps_msg_type 485189251Ssam */ 486189251Ssam struct wps_event_fail { 487189251Ssam int msg; 488252726Srpaulo u16 config_error; 489252726Srpaulo u16 error_indication; 490189251Ssam } fail; 491189251Ssam 492189251Ssam struct wps_event_pwd_auth_fail { 493189251Ssam int enrollee; 494189251Ssam int part; 495189251Ssam } pwd_auth_fail; 496214734Srpaulo 497214734Srpaulo struct wps_event_er_ap { 498214734Srpaulo const u8 *uuid; 499214734Srpaulo const u8 *mac_addr; 500214734Srpaulo const char *friendly_name; 501214734Srpaulo const char *manufacturer; 502214734Srpaulo const char *manufacturer_url; 503214734Srpaulo const char *model_description; 504214734Srpaulo const char *model_name; 505214734Srpaulo const char *model_number; 506214734Srpaulo const char *model_url; 507214734Srpaulo const char *serial_number; 508214734Srpaulo const char *upc; 509214734Srpaulo const u8 *pri_dev_type; 510214734Srpaulo u8 wps_state; 511214734Srpaulo } ap; 512214734Srpaulo 513214734Srpaulo struct wps_event_er_enrollee { 514214734Srpaulo const u8 *uuid; 515214734Srpaulo const u8 *mac_addr; 516214734Srpaulo int m1_received; 517214734Srpaulo u16 config_methods; 518214734Srpaulo u16 dev_passwd_id; 519214734Srpaulo const u8 *pri_dev_type; 520214734Srpaulo const char *dev_name; 521214734Srpaulo const char *manufacturer; 522214734Srpaulo const char *model_name; 523214734Srpaulo const char *model_number; 524214734Srpaulo const char *serial_number; 525214734Srpaulo } enrollee; 526252726Srpaulo 527252726Srpaulo struct wps_event_er_ap_settings { 528252726Srpaulo const u8 *uuid; 529252726Srpaulo const struct wps_credential *cred; 530252726Srpaulo } ap_settings; 531252726Srpaulo 532252726Srpaulo struct wps_event_er_set_selected_registrar { 533252726Srpaulo const u8 *uuid; 534252726Srpaulo int sel_reg; 535252726Srpaulo u16 dev_passwd_id; 536252726Srpaulo u16 sel_reg_config_methods; 537252726Srpaulo enum { 538252726Srpaulo WPS_ER_SET_SEL_REG_START, 539252726Srpaulo WPS_ER_SET_SEL_REG_DONE, 540252726Srpaulo WPS_ER_SET_SEL_REG_FAILED 541252726Srpaulo } state; 542252726Srpaulo } set_sel_reg; 543189251Ssam}; 544189251Ssam 545189251Ssam/** 546189251Ssam * struct upnp_pending_message - Pending PutWLANResponse messages 547189251Ssam * @next: Pointer to next pending message or %NULL 548189251Ssam * @addr: NewWLANEventMAC 549189251Ssam * @msg: NewMessage 550189251Ssam * @type: Message Type 551189251Ssam */ 552189251Ssamstruct upnp_pending_message { 553189251Ssam struct upnp_pending_message *next; 554189251Ssam u8 addr[ETH_ALEN]; 555189251Ssam struct wpabuf *msg; 556189251Ssam enum wps_msg_type type; 557189251Ssam}; 558189251Ssam 559189251Ssam/** 560189251Ssam * struct wps_context - Long term WPS context data 561189251Ssam * 562189251Ssam * This data is stored at the higher layer Authenticator or Supplicant data 563189251Ssam * structures and it is maintained over multiple registration protocol runs. 564189251Ssam */ 565189251Ssamstruct wps_context { 566189251Ssam /** 567189251Ssam * ap - Whether the local end is an access point 568189251Ssam */ 569189251Ssam int ap; 570189251Ssam 571189251Ssam /** 572189251Ssam * registrar - Pointer to WPS registrar data from wps_registrar_init() 573189251Ssam */ 574189251Ssam struct wps_registrar *registrar; 575189251Ssam 576189251Ssam /** 577189251Ssam * wps_state - Current WPS state 578189251Ssam */ 579189251Ssam enum wps_state wps_state; 580189251Ssam 581189251Ssam /** 582189251Ssam * ap_setup_locked - Whether AP setup is locked (only used at AP) 583189251Ssam */ 584189251Ssam int ap_setup_locked; 585189251Ssam 586189251Ssam /** 587189251Ssam * uuid - Own UUID 588189251Ssam */ 589189251Ssam u8 uuid[16]; 590189251Ssam 591189251Ssam /** 592189251Ssam * ssid - SSID 593189251Ssam * 594189251Ssam * This SSID is used by the Registrar to fill in information for 595189251Ssam * Credentials. In addition, AP uses it when acting as an Enrollee to 596189251Ssam * notify Registrar of the current configuration. 597189251Ssam */ 598189251Ssam u8 ssid[32]; 599189251Ssam 600189251Ssam /** 601189251Ssam * ssid_len - Length of ssid in octets 602189251Ssam */ 603189251Ssam size_t ssid_len; 604189251Ssam 605189251Ssam /** 606189251Ssam * dev - Own WPS device data 607189251Ssam */ 608189251Ssam struct wps_device_data dev; 609189251Ssam 610189251Ssam /** 611214734Srpaulo * dh_ctx - Context data for Diffie-Hellman operation 612214734Srpaulo */ 613214734Srpaulo void *dh_ctx; 614214734Srpaulo 615214734Srpaulo /** 616214734Srpaulo * dh_privkey - Diffie-Hellman private key 617214734Srpaulo */ 618214734Srpaulo struct wpabuf *dh_privkey; 619214734Srpaulo 620214734Srpaulo /** 621214734Srpaulo * dh_pubkey_oob - Diffie-Hellman public key 622214734Srpaulo */ 623214734Srpaulo struct wpabuf *dh_pubkey; 624214734Srpaulo 625214734Srpaulo /** 626189251Ssam * config_methods - Enabled configuration methods 627189251Ssam * 628189251Ssam * Bit field of WPS_CONFIG_* 629189251Ssam */ 630189251Ssam u16 config_methods; 631189251Ssam 632189251Ssam /** 633189251Ssam * encr_types - Enabled encryption types (bit field of WPS_ENCR_*) 634189251Ssam */ 635189251Ssam u16 encr_types; 636189251Ssam 637189251Ssam /** 638189251Ssam * auth_types - Authentication types (bit field of WPS_AUTH_*) 639189251Ssam */ 640189251Ssam u16 auth_types; 641189251Ssam 642189251Ssam /** 643189251Ssam * network_key - The current Network Key (PSK) or %NULL to generate new 644189251Ssam * 645189251Ssam * If %NULL, Registrar will generate per-device PSK. In addition, AP 646189251Ssam * uses this when acting as an Enrollee to notify Registrar of the 647189251Ssam * current configuration. 648214734Srpaulo * 649214734Srpaulo * When using WPA/WPA2-Person, this key can be either the ASCII 650214734Srpaulo * passphrase (8..63 characters) or the 32-octet PSK (64 hex 651214734Srpaulo * characters). When this is set to the ASCII passphrase, the PSK can 652214734Srpaulo * be provided in the psk buffer and used per-Enrollee to control which 653214734Srpaulo * key type is included in the Credential (e.g., to reduce calculation 654214734Srpaulo * need on low-powered devices by provisioning PSK while still allowing 655214734Srpaulo * other devices to get the passphrase). 656189251Ssam */ 657189251Ssam u8 *network_key; 658189251Ssam 659189251Ssam /** 660189251Ssam * network_key_len - Length of network_key in octets 661189251Ssam */ 662189251Ssam size_t network_key_len; 663189251Ssam 664189251Ssam /** 665214734Srpaulo * psk - The current network PSK 666214734Srpaulo * 667214734Srpaulo * This optional value can be used to provide the current PSK if 668214734Srpaulo * network_key is set to the ASCII passphrase. 669214734Srpaulo */ 670214734Srpaulo u8 psk[32]; 671214734Srpaulo 672214734Srpaulo /** 673214734Srpaulo * psk_set - Whether psk value is set 674214734Srpaulo */ 675214734Srpaulo int psk_set; 676214734Srpaulo 677214734Srpaulo /** 678189251Ssam * ap_settings - AP Settings override for M7 (only used at AP) 679189251Ssam * 680189251Ssam * If %NULL, AP Settings attributes will be generated based on the 681189251Ssam * current network configuration. 682189251Ssam */ 683189251Ssam u8 *ap_settings; 684189251Ssam 685189251Ssam /** 686189251Ssam * ap_settings_len - Length of ap_settings in octets 687189251Ssam */ 688189251Ssam size_t ap_settings_len; 689189251Ssam 690189251Ssam /** 691189251Ssam * friendly_name - Friendly Name (required for UPnP) 692189251Ssam */ 693189251Ssam char *friendly_name; 694189251Ssam 695189251Ssam /** 696189251Ssam * manufacturer_url - Manufacturer URL (optional for UPnP) 697189251Ssam */ 698189251Ssam char *manufacturer_url; 699189251Ssam 700189251Ssam /** 701189251Ssam * model_description - Model Description (recommended for UPnP) 702189251Ssam */ 703189251Ssam char *model_description; 704189251Ssam 705189251Ssam /** 706189251Ssam * model_url - Model URL (optional for UPnP) 707189251Ssam */ 708189251Ssam char *model_url; 709189251Ssam 710189251Ssam /** 711189251Ssam * upc - Universal Product Code (optional for UPnP) 712189251Ssam */ 713189251Ssam char *upc; 714189251Ssam 715189251Ssam /** 716189251Ssam * cred_cb - Callback to notify that new Credentials were received 717189251Ssam * @ctx: Higher layer context data (cb_ctx) 718189251Ssam * @cred: The received Credential 719189251Ssam * Return: 0 on success, -1 on failure 720189251Ssam */ 721189251Ssam int (*cred_cb)(void *ctx, const struct wps_credential *cred); 722189251Ssam 723189251Ssam /** 724189251Ssam * event_cb - Event callback (state information about progress) 725189251Ssam * @ctx: Higher layer context data (cb_ctx) 726189251Ssam * @event: Event type 727189251Ssam * @data: Event data 728189251Ssam */ 729189251Ssam void (*event_cb)(void *ctx, enum wps_event event, 730189251Ssam union wps_event_data *data); 731189251Ssam 732189251Ssam /** 733189251Ssam * cb_ctx: Higher layer context data for callbacks 734189251Ssam */ 735189251Ssam void *cb_ctx; 736189251Ssam 737189251Ssam struct upnp_wps_device_sm *wps_upnp; 738189251Ssam 739189251Ssam /* Pending messages from UPnP PutWLANResponse */ 740189251Ssam struct upnp_pending_message *upnp_msgs; 741189251Ssam 742252726Srpaulo u16 ap_nfc_dev_pw_id; 743252726Srpaulo struct wpabuf *ap_nfc_dh_pubkey; 744252726Srpaulo struct wpabuf *ap_nfc_dh_privkey; 745252726Srpaulo struct wpabuf *ap_nfc_dev_pw; 746214734Srpaulo}; 747189251Ssam 748189251Ssamstruct wps_registrar * 749189251Ssamwps_registrar_init(struct wps_context *wps, 750189251Ssam const struct wps_registrar_config *cfg); 751189251Ssamvoid wps_registrar_deinit(struct wps_registrar *reg); 752252726Srpauloint wps_registrar_add_pin(struct wps_registrar *reg, const u8 *addr, 753252726Srpaulo const u8 *uuid, const u8 *pin, size_t pin_len, 754252726Srpaulo int timeout); 755189251Ssamint wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid); 756252726Srpauloint wps_registrar_wps_cancel(struct wps_registrar *reg); 757189251Ssamint wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid); 758252726Srpauloint wps_registrar_button_pushed(struct wps_registrar *reg, 759252726Srpaulo const u8 *p2p_dev_addr); 760252726Srpaulovoid wps_registrar_complete(struct wps_registrar *registrar, const u8 *uuid_e, 761252726Srpaulo const u8 *dev_pw, size_t dev_pw_len); 762189251Ssamvoid wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr, 763252726Srpaulo const struct wpabuf *wps_data, 764252726Srpaulo int p2p_wildcard); 765189251Ssamint wps_registrar_update_ie(struct wps_registrar *reg); 766214734Srpauloint wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr, 767214734Srpaulo char *buf, size_t buflen); 768252726Srpauloint wps_registrar_config_ap(struct wps_registrar *reg, 769252726Srpaulo struct wps_credential *cred); 770252726Srpauloint wps_registrar_add_nfc_pw_token(struct wps_registrar *reg, 771252726Srpaulo const u8 *pubkey_hash, u16 pw_id, 772252726Srpaulo const u8 *dev_pw, size_t dev_pw_len); 773252726Srpauloint wps_registrar_add_nfc_password_token(struct wps_registrar *reg, 774252726Srpaulo const u8 *oob_dev_pw, 775252726Srpaulo size_t oob_dev_pw_len); 776189251Ssam 777252726Srpauloint wps_build_credential_wrap(struct wpabuf *msg, 778252726Srpaulo const struct wps_credential *cred); 779252726Srpaulo 780189251Ssamunsigned int wps_pin_checksum(unsigned int pin); 781189251Ssamunsigned int wps_pin_valid(unsigned int pin); 782189251Ssamunsigned int wps_generate_pin(void); 783252726Srpauloint wps_pin_str_valid(const char *pin); 784189251Ssamvoid wps_free_pending_msgs(struct upnp_pending_message *msgs); 785189251Ssam 786252726Srpaulostruct wpabuf * wps_get_oob_cred(struct wps_context *wps); 787252726Srpauloint wps_oob_use_cred(struct wps_context *wps, struct wps_parse_attr *attr); 788214734Srpauloint wps_attr_text(struct wpabuf *data, char *buf, char *end); 789214734Srpaulo 790252726Srpaulostruct wps_er * wps_er_init(struct wps_context *wps, const char *ifname, 791252726Srpaulo const char *filter); 792214734Srpaulovoid wps_er_refresh(struct wps_er *er); 793214734Srpaulovoid wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx); 794214734Srpaulovoid wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id, 795214734Srpaulo u16 sel_reg_config_methods); 796214734Srpauloint wps_er_pbc(struct wps_er *er, const u8 *uuid); 797214734Srpauloint wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin, 798214734Srpaulo size_t pin_len); 799252726Srpauloint wps_er_set_config(struct wps_er *er, const u8 *uuid, 800252726Srpaulo const struct wps_credential *cred); 801252726Srpauloint wps_er_config(struct wps_er *er, const u8 *uuid, const u8 *pin, 802252726Srpaulo size_t pin_len, const struct wps_credential *cred); 803252726Srpaulostruct wpabuf * wps_er_nfc_config_token(struct wps_er *er, const u8 *uuid); 804214734Srpaulo 805214734Srpauloint wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]); 806214734Srpaulochar * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf, 807214734Srpaulo size_t buf_len); 808214734Srpaulovoid uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid); 809214734Srpaulou16 wps_config_methods_str2bin(const char *str); 810252726Srpaulostruct wpabuf * wps_build_nfc_pw_token(u16 dev_pw_id, 811252726Srpaulo const struct wpabuf *pubkey, 812252726Srpaulo const struct wpabuf *dev_pw); 813252726Srpaulostruct wpabuf * wps_nfc_token_gen(int ndef, int *id, struct wpabuf **pubkey, 814252726Srpaulo struct wpabuf **privkey, 815252726Srpaulo struct wpabuf **dev_pw); 816214734Srpaulo 817252726Srpaulo/* ndef.c */ 818252726Srpaulostruct wpabuf * ndef_parse_wifi(const struct wpabuf *buf); 819252726Srpaulostruct wpabuf * ndef_build_wifi(const struct wpabuf *buf); 820252726Srpaulostruct wpabuf * ndef_build_wifi_hr(void); 821252726Srpaulo 822252726Srpaulo#ifdef CONFIG_WPS_STRICT 823252726Srpauloint wps_validate_beacon(const struct wpabuf *wps_ie); 824252726Srpauloint wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, int probe, 825252726Srpaulo const u8 *addr); 826252726Srpauloint wps_validate_probe_req(const struct wpabuf *wps_ie, const u8 *addr); 827252726Srpauloint wps_validate_assoc_req(const struct wpabuf *wps_ie); 828252726Srpauloint wps_validate_assoc_resp(const struct wpabuf *wps_ie); 829252726Srpauloint wps_validate_m1(const struct wpabuf *tlvs); 830252726Srpauloint wps_validate_m2(const struct wpabuf *tlvs); 831252726Srpauloint wps_validate_m2d(const struct wpabuf *tlvs); 832252726Srpauloint wps_validate_m3(const struct wpabuf *tlvs); 833252726Srpauloint wps_validate_m4(const struct wpabuf *tlvs); 834252726Srpauloint wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2); 835252726Srpauloint wps_validate_m5(const struct wpabuf *tlvs); 836252726Srpauloint wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2); 837252726Srpauloint wps_validate_m6(const struct wpabuf *tlvs); 838252726Srpauloint wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2); 839252726Srpauloint wps_validate_m7(const struct wpabuf *tlvs); 840252726Srpauloint wps_validate_m7_encr(const struct wpabuf *tlvs, int ap, int wps2); 841252726Srpauloint wps_validate_m8(const struct wpabuf *tlvs); 842252726Srpauloint wps_validate_m8_encr(const struct wpabuf *tlvs, int ap, int wps2); 843252726Srpauloint wps_validate_wsc_ack(const struct wpabuf *tlvs); 844252726Srpauloint wps_validate_wsc_nack(const struct wpabuf *tlvs); 845252726Srpauloint wps_validate_wsc_done(const struct wpabuf *tlvs); 846252726Srpauloint wps_validate_upnp_set_selected_registrar(const struct wpabuf *tlvs); 847252726Srpaulo#else /* CONFIG_WPS_STRICT */ 848252726Srpaulostatic inline int wps_validate_beacon(const struct wpabuf *wps_ie){ 849252726Srpaulo return 0; 850252726Srpaulo} 851252726Srpaulo 852252726Srpaulostatic inline int wps_validate_beacon_probe_resp(const struct wpabuf *wps_ie, 853252726Srpaulo int probe, const u8 *addr) 854252726Srpaulo{ 855252726Srpaulo return 0; 856252726Srpaulo} 857252726Srpaulo 858252726Srpaulostatic inline int wps_validate_probe_req(const struct wpabuf *wps_ie, 859252726Srpaulo const u8 *addr) 860252726Srpaulo{ 861252726Srpaulo return 0; 862252726Srpaulo} 863252726Srpaulo 864252726Srpaulostatic inline int wps_validate_assoc_req(const struct wpabuf *wps_ie) 865252726Srpaulo{ 866252726Srpaulo return 0; 867252726Srpaulo} 868252726Srpaulo 869252726Srpaulostatic inline int wps_validate_assoc_resp(const struct wpabuf *wps_ie) 870252726Srpaulo{ 871252726Srpaulo return 0; 872252726Srpaulo} 873252726Srpaulo 874252726Srpaulostatic inline int wps_validate_m1(const struct wpabuf *tlvs) 875252726Srpaulo{ 876252726Srpaulo return 0; 877252726Srpaulo} 878252726Srpaulo 879252726Srpaulostatic inline int wps_validate_m2(const struct wpabuf *tlvs) 880252726Srpaulo{ 881252726Srpaulo return 0; 882252726Srpaulo} 883252726Srpaulo 884252726Srpaulostatic inline int wps_validate_m2d(const struct wpabuf *tlvs) 885252726Srpaulo{ 886252726Srpaulo return 0; 887252726Srpaulo} 888252726Srpaulo 889252726Srpaulostatic inline int wps_validate_m3(const struct wpabuf *tlvs) 890252726Srpaulo{ 891252726Srpaulo return 0; 892252726Srpaulo} 893252726Srpaulo 894252726Srpaulostatic inline int wps_validate_m4(const struct wpabuf *tlvs) 895252726Srpaulo{ 896252726Srpaulo return 0; 897252726Srpaulo} 898252726Srpaulo 899252726Srpaulostatic inline int wps_validate_m4_encr(const struct wpabuf *tlvs, int wps2) 900252726Srpaulo{ 901252726Srpaulo return 0; 902252726Srpaulo} 903252726Srpaulo 904252726Srpaulostatic inline int wps_validate_m5(const struct wpabuf *tlvs) 905252726Srpaulo{ 906252726Srpaulo return 0; 907252726Srpaulo} 908252726Srpaulo 909252726Srpaulostatic inline int wps_validate_m5_encr(const struct wpabuf *tlvs, int wps2) 910252726Srpaulo{ 911252726Srpaulo return 0; 912252726Srpaulo} 913252726Srpaulo 914252726Srpaulostatic inline int wps_validate_m6(const struct wpabuf *tlvs) 915252726Srpaulo{ 916252726Srpaulo return 0; 917252726Srpaulo} 918252726Srpaulo 919252726Srpaulostatic inline int wps_validate_m6_encr(const struct wpabuf *tlvs, int wps2) 920252726Srpaulo{ 921252726Srpaulo return 0; 922252726Srpaulo} 923252726Srpaulo 924252726Srpaulostatic inline int wps_validate_m7(const struct wpabuf *tlvs) 925252726Srpaulo{ 926252726Srpaulo return 0; 927252726Srpaulo} 928252726Srpaulo 929252726Srpaulostatic inline int wps_validate_m7_encr(const struct wpabuf *tlvs, int ap, 930252726Srpaulo int wps2) 931252726Srpaulo{ 932252726Srpaulo return 0; 933252726Srpaulo} 934252726Srpaulo 935252726Srpaulostatic inline int wps_validate_m8(const struct wpabuf *tlvs) 936252726Srpaulo{ 937252726Srpaulo return 0; 938252726Srpaulo} 939252726Srpaulo 940252726Srpaulostatic inline int wps_validate_m8_encr(const struct wpabuf *tlvs, int ap, 941252726Srpaulo int wps2) 942252726Srpaulo{ 943252726Srpaulo return 0; 944252726Srpaulo} 945252726Srpaulo 946252726Srpaulostatic inline int wps_validate_wsc_ack(const struct wpabuf *tlvs) 947252726Srpaulo{ 948252726Srpaulo return 0; 949252726Srpaulo} 950252726Srpaulo 951252726Srpaulostatic inline int wps_validate_wsc_nack(const struct wpabuf *tlvs) 952252726Srpaulo{ 953252726Srpaulo return 0; 954252726Srpaulo} 955252726Srpaulo 956252726Srpaulostatic inline int wps_validate_wsc_done(const struct wpabuf *tlvs) 957252726Srpaulo{ 958252726Srpaulo return 0; 959252726Srpaulo} 960252726Srpaulo 961252726Srpaulostatic inline int wps_validate_upnp_set_selected_registrar( 962252726Srpaulo const struct wpabuf *tlvs) 963252726Srpaulo{ 964252726Srpaulo return 0; 965252726Srpaulo} 966252726Srpaulo#endif /* CONFIG_WPS_STRICT */ 967252726Srpaulo 968189251Ssam#endif /* WPS_H */ 969