2 * Wi-Fi Protected Setup
3 * Copyright (c) 2007-2008, 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
35 * struct wps_credential - WPS Credential
37 * @ssid_len: Length of SSID
38 * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
39 * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
42 * @key_len: Key length in octets
43 * @mac_addr: MAC address of the peer
44 * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
45 * this may be %NULL, if not used
46 * @cred_attr_len: Length of cred_attr in octets
48 struct wps_credential {
56 u8 mac_addr[ETH_ALEN];
62 * struct wps_device_data - WPS Device Data
63 * @mac_addr: Device MAC address
64 * @device_name: Device Name (0..32 octets encoded in UTF-8)
65 * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
66 * @model_name: Model Name (0..32 octets encoded in UTF-8)
67 * @model_number: Model Number (0..32 octets encoded in UTF-8)
68 * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
69 * @categ: Primary Device Category
70 * @oui: Primary Device OUI
71 * @sub_categ: Primary Device Sub-Category
72 * @os_version: OS Version
73 * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
75 struct wps_device_data {
76 u8 mac_addr[ETH_ALEN];
90 * struct wps_config - WPS configuration for a single registration protocol run
94 * wps - Pointer to long term WPS context
96 struct wps_context *wps;
99 * registrar - Whether this end is a Registrar
104 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
109 * pin_len - Length on pin in octets
114 * pbc - Whether this is protocol run uses PBC
119 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
121 const struct wpabuf *assoc_wps_ie;
124 struct wps_data * wps_init(const struct wps_config *cfg);
126 void wps_deinit(struct wps_data *data);
129 * enum wps_process_res - WPS message processing result
131 enum wps_process_res {
133 * WPS_DONE - Processing done
138 * WPS_CONTINUE - Processing continues
143 * WPS_FAILURE - Processing failed
147 enum wps_process_res wps_process_msg(struct wps_data *wps,
148 enum wsc_op_code op_code,
149 const struct wpabuf *msg);
151 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
153 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
154 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
155 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
157 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
158 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
160 enum wps_request_type req_type);
164 * struct wps_registrar_config - WPS Registrar configuration
166 struct wps_registrar_config {
168 * new_psk_cb - Callback for new PSK
169 * @ctx: Higher layer context data (cb_ctx)
170 * @mac_addr: MAC address of the Enrollee
172 * @psk_len: The length of psk in octets
173 * Returns: 0 on success, -1 on failure
175 * This callback is called when a new per-device PSK is provisioned.
177 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
181 * set_ie_cb - Callback for WPS IE changes
182 * @ctx: Higher layer context data (cb_ctx)
183 * @beacon_ie: WPS IE for Beacon
184 * @beacon_ie_len: WPS IE length for Beacon
185 * @probe_resp_ie: WPS IE for Probe Response
186 * @probe_resp_ie_len: WPS IE length for Probe Response
187 * Returns: 0 on success, -1 on failure
189 * This callback is called whenever the WPS IE in Beacon or Probe
190 * Response frames needs to be changed (AP only).
192 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
193 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
196 * pin_needed_cb - Callback for requesting a PIN
197 * @ctx: Higher layer context data (cb_ctx)
198 * @uuid_e: UUID-E of the unknown Enrollee
199 * @dev: Device Data from the unknown Enrollee
201 * This callback is called whenever an unknown Enrollee requests to use
202 * PIN method and a matching PIN (Device Password) is not found in
205 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
206 const struct wps_device_data *dev);
209 * reg_success_cb - Callback for reporting successful registration
210 * @ctx: Higher layer context data (cb_ctx)
211 * @mac_addr: MAC address of the Enrollee
212 * @uuid_e: UUID-E of the Enrollee
214 * This callback is called whenever an Enrollee completes registration
217 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
221 * cb_ctx: Higher layer context data for Registrar callbacks
226 * skip_cred_build: Do not build credential
228 * This option can be used to disable internal code that builds
229 * Credential attribute into M8 based on the current network
230 * configuration and Enrollee capabilities. The extra_cred data will
231 * then be used as the Credential(s).
236 * extra_cred: Additional Credential attribute(s)
238 * This optional data (set to %NULL to disable) can be used to add
239 * Credential attribute(s) for other networks into M8. If
240 * skip_cred_build is set, this will also override the automatically
241 * generated Credential attribute.
243 const u8 *extra_cred;
246 * extra_cred_len: Length of extra_cred in octets
248 size_t extra_cred_len;
251 * disable_auto_conf - Disable auto-configuration on first registration
253 * By default, the AP that is started in not configured state will
254 * generate a random PSK and move to configured state when the first
255 * registration protocol run is completed successfully. This option can
256 * be used to disable this functionality and leave it up to an external
257 * program to take care of configuration. This requires the extra_cred
258 * to be set with a suitable Credential and skip_cred_build being used.
260 int disable_auto_conf;
265 * enum wps_event - WPS event types
269 * WPS_EV_M2D - M2D received (Registrar did not know us)
274 * WPS_EV_FAIL - Registration failed
279 * WPS_EV_SUCCESS - Registration succeeded
284 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
290 * union wps_event_data - WPS event data
292 union wps_event_data {
294 * struct wps_event_m2d - M2D event data
296 struct wps_event_m2d {
298 const u8 *manufacturer;
299 size_t manufacturer_len;
300 const u8 *model_name;
301 size_t model_name_len;
302 const u8 *model_number;
303 size_t model_number_len;
304 const u8 *serial_number;
305 size_t serial_number_len;
308 const u8 *primary_dev_type; /* 8 octets */
314 * struct wps_event_fail - Registration failure information
315 * @msg: enum wps_msg_type
317 struct wps_event_fail {
321 struct wps_event_pwd_auth_fail {
328 * struct wps_context - Long term WPS context data
330 * This data is stored at the higher layer Authenticator or Supplicant data
331 * structures and it is maintained over multiple registration protocol runs.
335 * ap - Whether the local end is an access point
340 * registrar - Pointer to WPS registrar data from wps_registrar_init()
342 struct wps_registrar *registrar;
345 * wps_state - Current WPS state
347 enum wps_state wps_state;
350 * ap_setup_locked - Whether AP setup is locked (only used at AP)
362 * This SSID is used by the Registrar to fill in information for
363 * Credentials. In addition, AP uses it when acting as an Enrollee to
364 * notify Registrar of the current configuration.
369 * ssid_len - Length of ssid in octets
374 * dev - Own WPS device data
376 struct wps_device_data dev;
379 * config_methods - Enabled configuration methods
381 * Bit field of WPS_CONFIG_*
386 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
391 * auth_types - Authentication types (bit field of WPS_AUTH_*)
396 * network_key - The current Network Key (PSK) or %NULL to generate new
398 * If %NULL, Registrar will generate per-device PSK. In addition, AP
399 * uses this when acting as an Enrollee to notify Registrar of the
400 * current configuration.
405 * network_key_len - Length of network_key in octets
407 size_t network_key_len;
410 * ap_settings - AP Settings override for M7 (only used at AP)
412 * If %NULL, AP Settings attributes will be generated based on the
413 * current network configuration.
418 * ap_settings_len - Length of ap_settings in octets
420 size_t ap_settings_len;
423 * cred_cb - Callback to notify that new Credentials were received
424 * @ctx: Higher layer context data (cb_ctx)
425 * @cred: The received Credential
426 * Return: 0 on success, -1 on failure
428 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
431 * event_cb - Event callback (state information about progress)
432 * @ctx: Higher layer context data (cb_ctx)
436 void (*event_cb)(void *ctx, enum wps_event event,
437 union wps_event_data *data);
440 * cb_ctx: Higher layer context data for callbacks
446 struct wps_registrar *
447 wps_registrar_init(struct wps_context *wps,
448 const struct wps_registrar_config *cfg);
449 void wps_registrar_deinit(struct wps_registrar *reg);
450 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
451 const u8 *pin, size_t pin_len);
452 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
453 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
454 int wps_registrar_button_pushed(struct wps_registrar *reg);
455 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
456 const struct wpabuf *wps_data);
457 int wps_registrar_update_ie(struct wps_registrar *reg);
459 unsigned int wps_pin_checksum(unsigned int pin);
460 unsigned int wps_pin_valid(unsigned int pin);
461 unsigned int wps_generate_pin(void);