2 * Wi-Fi Protected Setup
3 * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
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.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
21 * enum wsc_op_code - EAP-WSC OP-Code values
24 WSC_UPnP
= 0 /* No OP Code in UPnP transport */,
34 struct upnp_wps_device_sm
;
38 * struct wps_credential - WPS Credential
40 * @ssid_len: Length of SSID
41 * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
42 * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
45 * @key_len: Key length in octets
46 * @mac_addr: MAC address of the peer
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
51 struct wps_credential
{
59 u8 mac_addr
[ETH_ALEN
];
65 * struct wps_device_data - WPS Device Data
66 * @mac_addr: Device MAC address
67 * @device_name: Device Name (0..32 octets encoded in UTF-8)
68 * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
69 * @model_name: Model Name (0..32 octets encoded in UTF-8)
70 * @model_number: Model Number (0..32 octets encoded in UTF-8)
71 * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
72 * @categ: Primary Device Category
73 * @oui: Primary Device OUI
74 * @sub_categ: Primary Device Sub-Category
75 * @os_version: OS Version
76 * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
78 struct wps_device_data
{
79 u8 mac_addr
[ETH_ALEN
];
92 struct oob_conf_data
{
94 OOB_METHOD_UNKNOWN
= 0,
99 struct wpabuf
*dev_password
;
100 struct wpabuf
*pubkey_hash
;
104 * struct wps_config - WPS configuration for a single registration protocol run
108 * wps - Pointer to long term WPS context
110 struct wps_context
*wps
;
113 * registrar - Whether this end is a Registrar
118 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
123 * pin_len - Length on pin in octets
128 * pbc - Whether this is protocol run uses PBC
133 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
135 const struct wpabuf
*assoc_wps_ie
;
138 * new_ap_settings - New AP settings (%NULL if not used)
140 * This parameter provides new AP settings when using a wireless
141 * stations as a Registrar to configure the AP. %NULL means that AP
142 * will not be reconfigured, i.e., the station will only learn the
143 * current AP settings by using AP PIN.
145 const struct wps_credential
*new_ap_settings
;
148 * peer_addr: MAC address of the peer in AP; %NULL if not AP
153 struct wps_data
* wps_init(const struct wps_config
*cfg
);
155 void wps_deinit(struct wps_data
*data
);
158 * enum wps_process_res - WPS message processing result
160 enum wps_process_res
{
162 * WPS_DONE - Processing done
167 * WPS_CONTINUE - Processing continues
172 * WPS_FAILURE - Processing failed
177 * WPS_PENDING - Processing continues, but waiting for an external
178 * event (e.g., UPnP message from an external Registrar)
182 enum wps_process_res
wps_process_msg(struct wps_data
*wps
,
183 enum wsc_op_code op_code
,
184 const struct wpabuf
*msg
);
186 struct wpabuf
* wps_get_msg(struct wps_data
*wps
, enum wsc_op_code
*op_code
);
188 int wps_is_selected_pbc_registrar(const struct wpabuf
*msg
);
189 int wps_is_selected_pin_registrar(const struct wpabuf
*msg
);
190 const u8
* wps_get_uuid_e(const struct wpabuf
*msg
);
192 struct wpabuf
* wps_build_assoc_req_ie(enum wps_request_type req_type
);
193 struct wpabuf
* wps_build_probe_req_ie(int pbc
, struct wps_device_data
*dev
,
195 enum wps_request_type req_type
);
199 * struct wps_registrar_config - WPS Registrar configuration
201 struct wps_registrar_config
{
203 * new_psk_cb - Callback for new PSK
204 * @ctx: Higher layer context data (cb_ctx)
205 * @mac_addr: MAC address of the Enrollee
207 * @psk_len: The length of psk in octets
208 * Returns: 0 on success, -1 on failure
210 * This callback is called when a new per-device PSK is provisioned.
212 int (*new_psk_cb
)(void *ctx
, const u8
*mac_addr
, const u8
*psk
,
216 * set_ie_cb - Callback for WPS IE changes
217 * @ctx: Higher layer context data (cb_ctx)
218 * @beacon_ie: WPS IE for Beacon
219 * @beacon_ie_len: WPS IE length for Beacon
220 * @probe_resp_ie: WPS IE for Probe Response
221 * @probe_resp_ie_len: WPS IE length for Probe Response
222 * Returns: 0 on success, -1 on failure
224 * This callback is called whenever the WPS IE in Beacon or Probe
225 * Response frames needs to be changed (AP only).
227 int (*set_ie_cb
)(void *ctx
, const u8
*beacon_ie
, size_t beacon_ie_len
,
228 const u8
*probe_resp_ie
, size_t probe_resp_ie_len
);
231 * pin_needed_cb - Callback for requesting a PIN
232 * @ctx: Higher layer context data (cb_ctx)
233 * @uuid_e: UUID-E of the unknown Enrollee
234 * @dev: Device Data from the unknown Enrollee
236 * This callback is called whenever an unknown Enrollee requests to use
237 * PIN method and a matching PIN (Device Password) is not found in
240 void (*pin_needed_cb
)(void *ctx
, const u8
*uuid_e
,
241 const struct wps_device_data
*dev
);
244 * reg_success_cb - Callback for reporting successful registration
245 * @ctx: Higher layer context data (cb_ctx)
246 * @mac_addr: MAC address of the Enrollee
247 * @uuid_e: UUID-E of the Enrollee
249 * This callback is called whenever an Enrollee completes registration
252 void (*reg_success_cb
)(void *ctx
, const u8
*mac_addr
,
256 * set_sel_reg_cb - Callback for reporting selected registrar changes
257 * @ctx: Higher layer context data (cb_ctx)
258 * @sel_reg: Whether the Registrar is selected
259 * @dev_passwd_id: Device Password ID to indicate with method or
260 * specific password the Registrar intends to use
261 * @sel_reg_config_methods: Bit field of active config methods
263 * This callback is called whenever the Selected Registrar state
264 * changes (e.g., a new PIN becomes available or PBC is invoked). This
265 * callback is only used by External Registrar implementation;
266 * set_ie_cb() is used by AP implementation in similar caes, but it
267 * provides the full WPS IE data instead of just the minimal Registrar
270 void (*set_sel_reg_cb
)(void *ctx
, int sel_reg
, u16 dev_passwd_id
,
271 u16 sel_reg_config_methods
);
274 * cb_ctx: Higher layer context data for Registrar callbacks
279 * skip_cred_build: Do not build credential
281 * This option can be used to disable internal code that builds
282 * Credential attribute into M8 based on the current network
283 * configuration and Enrollee capabilities. The extra_cred data will
284 * then be used as the Credential(s).
289 * extra_cred: Additional Credential attribute(s)
291 * This optional data (set to %NULL to disable) can be used to add
292 * Credential attribute(s) for other networks into M8. If
293 * skip_cred_build is set, this will also override the automatically
294 * generated Credential attribute.
296 const u8
*extra_cred
;
299 * extra_cred_len: Length of extra_cred in octets
301 size_t extra_cred_len
;
304 * disable_auto_conf - Disable auto-configuration on first registration
306 * By default, the AP that is started in not configured state will
307 * generate a random PSK and move to configured state when the first
308 * registration protocol run is completed successfully. This option can
309 * be used to disable this functionality and leave it up to an external
310 * program to take care of configuration. This requires the extra_cred
311 * to be set with a suitable Credential and skip_cred_build being used.
313 int disable_auto_conf
;
316 * static_wep_only - Whether the BSS supports only static WEP
323 * enum wps_event - WPS event types
327 * WPS_EV_M2D - M2D received (Registrar did not know us)
332 * WPS_EV_FAIL - Registration failed
337 * WPS_EV_SUCCESS - Registration succeeded
342 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
344 WPS_EV_PWD_AUTH_FAIL
,
347 * WPS_EV_PBC_OVERLAP - PBC session overlap detected
352 * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
358 * union wps_event_data - WPS event data
360 union wps_event_data
{
362 * struct wps_event_m2d - M2D event data
364 struct wps_event_m2d
{
366 const u8
*manufacturer
;
367 size_t manufacturer_len
;
368 const u8
*model_name
;
369 size_t model_name_len
;
370 const u8
*model_number
;
371 size_t model_number_len
;
372 const u8
*serial_number
;
373 size_t serial_number_len
;
376 const u8
*primary_dev_type
; /* 8 octets */
382 * struct wps_event_fail - Registration failure information
383 * @msg: enum wps_msg_type
385 struct wps_event_fail
{
389 struct wps_event_pwd_auth_fail
{
396 * struct upnp_pending_message - Pending PutWLANResponse messages
397 * @next: Pointer to next pending message or %NULL
398 * @addr: NewWLANEventMAC
400 * @type: Message Type
402 struct upnp_pending_message
{
403 struct upnp_pending_message
*next
;
406 enum wps_msg_type type
;
410 * struct wps_context - Long term WPS context data
412 * This data is stored at the higher layer Authenticator or Supplicant data
413 * structures and it is maintained over multiple registration protocol runs.
417 * ap - Whether the local end is an access point
422 * registrar - Pointer to WPS registrar data from wps_registrar_init()
424 struct wps_registrar
*registrar
;
427 * wps_state - Current WPS state
429 enum wps_state wps_state
;
432 * ap_setup_locked - Whether AP setup is locked (only used at AP)
444 * This SSID is used by the Registrar to fill in information for
445 * Credentials. In addition, AP uses it when acting as an Enrollee to
446 * notify Registrar of the current configuration.
451 * ssid_len - Length of ssid in octets
456 * dev - Own WPS device data
458 struct wps_device_data dev
;
461 * oob_conf - OOB Config data
463 struct oob_conf_data oob_conf
;
466 * oob_dev_pw_id - OOB Device password id
471 * dh_ctx - Context data for Diffie-Hellman operation
476 * dh_privkey - Diffie-Hellman private key
478 struct wpabuf
*dh_privkey
;
481 * dh_pubkey_oob - Diffie-Hellman public key
483 struct wpabuf
*dh_pubkey
;
486 * config_methods - Enabled configuration methods
488 * Bit field of WPS_CONFIG_*
493 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
498 * auth_types - Authentication types (bit field of WPS_AUTH_*)
503 * network_key - The current Network Key (PSK) or %NULL to generate new
505 * If %NULL, Registrar will generate per-device PSK. In addition, AP
506 * uses this when acting as an Enrollee to notify Registrar of the
507 * current configuration.
512 * network_key_len - Length of network_key in octets
514 size_t network_key_len
;
517 * ap_settings - AP Settings override for M7 (only used at AP)
519 * If %NULL, AP Settings attributes will be generated based on the
520 * current network configuration.
525 * ap_settings_len - Length of ap_settings in octets
527 size_t ap_settings_len
;
530 * friendly_name - Friendly Name (required for UPnP)
535 * manufacturer_url - Manufacturer URL (optional for UPnP)
537 char *manufacturer_url
;
540 * model_description - Model Description (recommended for UPnP)
542 char *model_description
;
545 * model_url - Model URL (optional for UPnP)
550 * upc - Universal Product Code (optional for UPnP)
555 * cred_cb - Callback to notify that new Credentials were received
556 * @ctx: Higher layer context data (cb_ctx)
557 * @cred: The received Credential
558 * Return: 0 on success, -1 on failure
560 int (*cred_cb
)(void *ctx
, const struct wps_credential
*cred
);
563 * event_cb - Event callback (state information about progress)
564 * @ctx: Higher layer context data (cb_ctx)
568 void (*event_cb
)(void *ctx
, enum wps_event event
,
569 union wps_event_data
*data
);
572 * cb_ctx: Higher layer context data for callbacks
576 struct upnp_wps_device_sm
*wps_upnp
;
578 /* Pending messages from UPnP PutWLANResponse */
579 struct upnp_pending_message
*upnp_msgs
;
582 struct oob_device_data
{
585 void * (*init_func
)(struct wps_context
*, struct oob_device_data
*,
587 struct wpabuf
* (*read_func
)(void *);
588 int (*write_func
)(void *, struct wpabuf
*);
589 void (*deinit_func
)(void *);
592 struct oob_nfc_device_data
{
593 int (*init_func
)(char *);
594 void * (*read_func
)(size_t *);
595 int (*write_func
)(void *, size_t);
596 void (*deinit_func
)(void);
599 struct wps_registrar
*
600 wps_registrar_init(struct wps_context
*wps
,
601 const struct wps_registrar_config
*cfg
);
602 void wps_registrar_deinit(struct wps_registrar
*reg
);
603 int wps_registrar_add_pin(struct wps_registrar
*reg
, const u8
*uuid
,
604 const u8
*pin
, size_t pin_len
, int timeout
);
605 int wps_registrar_invalidate_pin(struct wps_registrar
*reg
, const u8
*uuid
);
606 int wps_registrar_unlock_pin(struct wps_registrar
*reg
, const u8
*uuid
);
607 int wps_registrar_button_pushed(struct wps_registrar
*reg
);
608 void wps_registrar_probe_req_rx(struct wps_registrar
*reg
, const u8
*addr
,
609 const struct wpabuf
*wps_data
);
610 int wps_registrar_update_ie(struct wps_registrar
*reg
);
611 int wps_registrar_set_selected_registrar(struct wps_registrar
*reg
,
612 const struct wpabuf
*msg
);
613 int wps_registrar_get_info(struct wps_registrar
*reg
, const u8
*addr
,
614 char *buf
, size_t buflen
);
616 unsigned int wps_pin_checksum(unsigned int pin
);
617 unsigned int wps_pin_valid(unsigned int pin
);
618 unsigned int wps_generate_pin(void);
619 void wps_free_pending_msgs(struct upnp_pending_message
*msgs
);
621 struct oob_device_data
* wps_get_oob_device(char *device_type
);
622 struct oob_nfc_device_data
* wps_get_oob_nfc_device(char *device_name
);
623 int wps_get_oob_method(char *method
);
624 int wps_process_oob(struct wps_context
*wps
, struct oob_device_data
*oob_dev
,
626 int wps_attr_text(struct wpabuf
*data
, char *buf
, char *end
);
628 struct wps_er
* wps_er_init(struct wps_context
*wps
, const char *ifname
);
629 void wps_er_deinit(struct wps_er
*er
);
630 void wps_er_set_sel_reg(struct wps_er
*er
, int sel_reg
, u16 dev_passwd_id
,
631 u16 sel_reg_config_methods
);