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
45 struct wps_credential {
53 u8 mac_addr[ETH_ALEN];
57 * struct wps_device_data - WPS Device Data
58 * @mac_addr: Device MAC address
59 * @device_name: Device Name (0..32 octets encoded in UTF-8)
60 * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
61 * @model_name: Model Name (0..32 octets encoded in UTF-8)
62 * @model_number: Model Number (0..32 octets encoded in UTF-8)
63 * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
64 * @categ: Primary Device Category
65 * @oui: Primary Device OUI
66 * @sub_categ: Primary Device Sub-Category
67 * @os_version: OS Version
68 * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
70 struct wps_device_data {
71 u8 mac_addr[ETH_ALEN];
85 * struct wps_config - WPS configuration for a single registration protocol run
89 * authenticator - Whether the local end is Authenticator
90 * 1 = Authenticator, 0 = Supplicant
95 * wps - Pointer to long term WPS context
97 struct wps_context *wps;
100 * registrar - Pointer to WPS registrar data from wps_registrar_init()
101 * This is only used if the local end is Registrar; set to %NULL for
104 struct wps_registrar *registrar;
107 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
112 * pin_len - Length on pin in octets
117 * pbc - Whether this is protocol run uses PBC
122 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
124 const struct wpabuf *assoc_wps_ie;
127 struct wps_data * wps_init(const struct wps_config *cfg);
129 void wps_deinit(struct wps_data *data);
132 * enum wps_process_res - WPS message processing result
134 enum wps_process_res {
136 * WPS_DONE - Processing done
141 * WPS_CONTINUE - Processing continues
146 * WPS_FAILURE - Processing failed
150 enum wps_process_res wps_process_msg(struct wps_data *wps,
151 enum wsc_op_code op_code,
152 const struct wpabuf *msg);
154 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
156 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
157 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
158 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
160 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
161 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
163 enum wps_request_type req_type);
167 * struct wps_registrar_config - WPS Registrar configuration
169 struct wps_registrar_config {
171 * new_psk_cb - Callback for new PSK
172 * @ctx: Higher layer context data (cb_ctx)
173 * @mac_addr: MAC address of the Enrollee
175 * @psk_len: The length of psk in octets
176 * Returns: 0 on success, -1 on failure
178 * This callback is called when a new per-device PSK is provisioned.
180 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
184 * set_ie_cb - Callback for WPS IE changes
185 * @ctx: Higher layer context data (cb_ctx)
186 * @beacon_ie: WPS IE for Beacon
187 * @beacon_ie_len: WPS IE length for Beacon
188 * @probe_resp_ie: WPS IE for Probe Response
189 * @probe_resp_ie_len: WPS IE length for Probe Response
190 * Returns: 0 on success, -1 on failure
192 * This callback is called whenever the WPS IE in Beacon or Probe
193 * Response frames needs to be changed (AP only).
195 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
196 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
199 * pin_needed_cb - Callback for requesting a PIN
200 * @ctx: Higher layer context data (cb_ctx)
201 * @uuid_e: UUID-E of the unknown Enrollee
202 * @dev: Device Data from the unknown Enrollee
204 * This callback is called whenever an unknown Enrollee requests to use
205 * PIN method and a matching PIN (Device Password) is not found in
208 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
209 const struct wps_device_data *dev);
212 * cb_ctx: Higher layer context data for Registrar callbacks
219 * enum wps_event - WPS event types
223 * WPS_EV_M2D - M2D received (Registrar did not know us)
228 * WPS_EV_FAIL - Registration failed
233 * WPS_EV_SUCCESS - Registration succeeded
239 * union wps_event_data - WPS event data
241 union wps_event_data {
243 * struct wps_event_m2d - M2D event data
245 struct wps_event_m2d {
247 const u8 *manufacturer;
248 size_t manufacturer_len;
249 const u8 *model_name;
250 size_t model_name_len;
251 const u8 *model_number;
252 size_t model_number_len;
253 const u8 *serial_number;
254 size_t serial_number_len;
257 const u8 *primary_dev_type; /* 8 octets */
263 * struct wps_event_fail - Registration failure information
264 * @msg: enum wps_msg_type
266 struct wps_event_fail {
272 * struct wps_context - Long term WPS context data
274 * This data is stored at the higher layer Authenticator or Supplicant data
275 * structures and it is maintained over multiple registration protocol runs.
279 * ap - Whether the local end is an access point
284 * registrar - Pointer to WPS registrar data from wps_registrar_init()
286 struct wps_registrar *registrar;
289 * wps_state - Current WPS state
291 enum wps_state wps_state;
294 * ap_setup_locked - Whether AP setup is locked (only used at AP)
306 * This SSID is used by the Registrar to fill in information for
307 * Credentials. In addition, AP uses it when acting as an Enrollee to
308 * notify Registrar of the current configuration.
313 * ssid_len - Length of ssid in octets
318 * dev - Own WPS device data
320 struct wps_device_data dev;
323 * config_methods - Enabled configuration methods
325 * Bit field of WPS_CONFIG_*
330 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
335 * auth_types - Authentication types (bit field of WPS_AUTH_*)
340 * network_key - The current Network Key (PSK) or %NULL to generate new
342 * If %NULL, Registrar will generate per-device PSK. In addition, AP
343 * uses this when acting as an Enrollee to notify Registrar of the
344 * current configuration.
349 * network_key_len - Length of network_key in octets
351 size_t network_key_len;
354 * cred_cb - Callback to notify that new Credentials were received
355 * @ctx: Higher layer context data (cb_ctx)
356 * @cred: The received Credential
357 * Return: 0 on success, -1 on failure
359 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
362 * event_cb - Event callback (state information about progress)
363 * @ctx: Higher layer context data (cb_ctx)
367 void (*event_cb)(void *ctx, enum wps_event event,
368 union wps_event_data *data);
371 * cb_ctx: Higher layer context data for callbacks
377 struct wps_registrar *
378 wps_registrar_init(struct wps_context *wps,
379 const struct wps_registrar_config *cfg);
380 void wps_registrar_deinit(struct wps_registrar *reg);
381 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
382 const u8 *pin, size_t pin_len);
383 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
384 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
385 int wps_registrar_button_pushed(struct wps_registrar *reg);
386 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
387 const struct wpabuf *wps_data);
389 unsigned int wps_pin_checksum(unsigned int pin);
390 unsigned int wps_pin_valid(unsigned int pin);
391 unsigned int wps_generate_pin(void);