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