Removed duplicated authenticator yes/no from wps_config and wps_data
[libeap.git] / src / wps / wps.h
1 /*
2  * Wi-Fi Protected Setup
3  * Copyright (c) 2007-2008, 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_Start = 0x01,
25         WSC_ACK = 0x02,
26         WSC_NACK = 0x03,
27         WSC_MSG = 0x04,
28         WSC_Done = 0x05,
29         WSC_FRAG_ACK = 0x06
30 };
31
32 struct wps_registrar;
33
34 /**
35  * struct wps_credential - WPS Credential
36  * @ssid: SSID
37  * @ssid_len: Length of SSID
38  * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
39  * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
40  * @key_idx: Key index
41  * @key: Key
42  * @key_len: Key length in octets
43  * @mac_addr: MAC address of the peer
44  */
45 struct wps_credential {
46         u8 ssid[32];
47         size_t ssid_len;
48         u16 auth_type;
49         u16 encr_type;
50         u8 key_idx;
51         u8 key[64];
52         size_t key_len;
53         u8 mac_addr[ETH_ALEN];
54 };
55
56 /**
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)
69  */
70 struct wps_device_data {
71         u8 mac_addr[ETH_ALEN];
72         char *device_name;
73         char *manufacturer;
74         char *model_name;
75         char *model_number;
76         char *serial_number;
77         u16 categ;
78         u32 oui;
79         u16 sub_categ;
80         u32 os_version;
81         u8 rf_bands;
82 };
83
84 /**
85  * struct wps_config - WPS configuration for a single registration protocol run
86  */
87 struct wps_config {
88         /**
89          * wps - Pointer to long term WPS context
90          */
91         struct wps_context *wps;
92
93         /**
94          * registrar - Pointer to WPS registrar data from wps_registrar_init()
95          * This is only used if the local end is Registrar; set to %NULL for
96          * Enrollee.
97          */
98         struct wps_registrar *registrar;
99
100         /**
101          * pin - Enrollee Device Password (%NULL for Registrar or PBC)
102          */
103         const u8 *pin;
104
105         /**
106          * pin_len - Length on pin in octets
107          */
108         size_t pin_len;
109
110         /**
111          * pbc - Whether this is protocol run uses PBC
112          */
113         int pbc;
114
115         /**
116          * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
117          */
118         const struct wpabuf *assoc_wps_ie;
119 };
120
121 struct wps_data * wps_init(const struct wps_config *cfg);
122
123 void wps_deinit(struct wps_data *data);
124
125 /**
126  * enum wps_process_res - WPS message processing result
127  */
128 enum wps_process_res {
129         /**
130          * WPS_DONE - Processing done
131          */
132         WPS_DONE,
133
134         /**
135          * WPS_CONTINUE - Processing continues
136          */
137         WPS_CONTINUE,
138
139         /**
140          * WPS_FAILURE - Processing failed
141          */
142         WPS_FAILURE
143 };
144 enum wps_process_res wps_process_msg(struct wps_data *wps,
145                                      enum wsc_op_code op_code,
146                                      const struct wpabuf *msg);
147
148 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
149
150 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
151 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
152 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
153
154 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
155 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
156                                        const u8 *uuid,
157                                        enum wps_request_type req_type);
158
159
160 /**
161  * struct wps_registrar_config - WPS Registrar configuration
162  */
163 struct wps_registrar_config {
164         /**
165          * new_psk_cb - Callback for new PSK
166          * @ctx: Higher layer context data (cb_ctx)
167          * @mac_addr: MAC address of the Enrollee
168          * @psk: The new PSK
169          * @psk_len: The length of psk in octets
170          * Returns: 0 on success, -1 on failure
171          *
172          * This callback is called when a new per-device PSK is provisioned.
173          */
174         int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
175                           size_t psk_len);
176
177         /**
178          * set_ie_cb - Callback for WPS IE changes
179          * @ctx: Higher layer context data (cb_ctx)
180          * @beacon_ie: WPS IE for Beacon
181          * @beacon_ie_len: WPS IE length for Beacon
182          * @probe_resp_ie: WPS IE for Probe Response
183          * @probe_resp_ie_len: WPS IE length for Probe Response
184          * Returns: 0 on success, -1 on failure
185          *
186          * This callback is called whenever the WPS IE in Beacon or Probe
187          * Response frames needs to be changed (AP only).
188          */
189         int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
190                          const u8 *probe_resp_ie, size_t probe_resp_ie_len);
191
192         /**
193          * pin_needed_cb - Callback for requesting a PIN
194          * @ctx: Higher layer context data (cb_ctx)
195          * @uuid_e: UUID-E of the unknown Enrollee
196          * @dev: Device Data from the unknown Enrollee
197          *
198          * This callback is called whenever an unknown Enrollee requests to use
199          * PIN method and a matching PIN (Device Password) is not found in
200          * Registrar data.
201          */
202         void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
203                               const struct wps_device_data *dev);
204
205         /**
206          * cb_ctx: Higher layer context data for Registrar callbacks
207          */
208         void *cb_ctx;
209 };
210
211
212 /**
213  * enum wps_event - WPS event types
214  */
215 enum wps_event {
216         /**
217          * WPS_EV_M2D - M2D received (Registrar did not know us)
218          */
219         WPS_EV_M2D,
220
221         /**
222          * WPS_EV_FAIL - Registration failed
223          */
224         WPS_EV_FAIL,
225
226         /**
227          * WPS_EV_SUCCESS - Registration succeeded
228          */
229         WPS_EV_SUCCESS
230 };
231
232 /**
233  * union wps_event_data - WPS event data
234  */
235 union wps_event_data {
236         /**
237          * struct wps_event_m2d - M2D event data
238          */
239         struct wps_event_m2d {
240                 u16 config_methods;
241                 const u8 *manufacturer;
242                 size_t manufacturer_len;
243                 const u8 *model_name;
244                 size_t model_name_len;
245                 const u8 *model_number;
246                 size_t model_number_len;
247                 const u8 *serial_number;
248                 size_t serial_number_len;
249                 const u8 *dev_name;
250                 size_t dev_name_len;
251                 const u8 *primary_dev_type; /* 8 octets */
252                 u16 config_error;
253                 u16 dev_password_id;
254         } m2d;
255
256         /**
257          * struct wps_event_fail - Registration failure information
258          * @msg: enum wps_msg_type
259          */
260         struct wps_event_fail {
261                 int msg;
262         } fail;
263 };
264
265 /**
266  * struct wps_context - Long term WPS context data
267  *
268  * This data is stored at the higher layer Authenticator or Supplicant data
269  * structures and it is maintained over multiple registration protocol runs.
270  */
271 struct wps_context {
272         /**
273          * ap - Whether the local end is an access point
274          */
275         int ap;
276
277         /**
278          * registrar - Pointer to WPS registrar data from wps_registrar_init()
279          */
280         struct wps_registrar *registrar;
281
282         /**
283          * wps_state - Current WPS state
284          */
285         enum wps_state wps_state;
286
287         /**
288          * ap_setup_locked - Whether AP setup is locked (only used at AP)
289          */
290         int ap_setup_locked;
291
292         /**
293          * uuid - Own UUID
294          */
295         u8 uuid[16];
296
297         /**
298          * ssid - SSID
299          *
300          * This SSID is used by the Registrar to fill in information for
301          * Credentials. In addition, AP uses it when acting as an Enrollee to
302          * notify Registrar of the current configuration.
303          */
304         u8 ssid[32];
305
306         /**
307          * ssid_len - Length of ssid in octets
308          */
309         size_t ssid_len;
310
311         /**
312          * dev - Own WPS device data
313          */
314         struct wps_device_data dev;
315
316         /**
317          * config_methods - Enabled configuration methods
318          *
319          * Bit field of WPS_CONFIG_*
320          */
321         u16 config_methods;
322
323         /**
324          * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
325          */
326         u16 encr_types;
327
328         /**
329          * auth_types - Authentication types (bit field of WPS_AUTH_*)
330          */
331         u16 auth_types;
332
333         /**
334          * network_key - The current Network Key (PSK) or %NULL to generate new
335          *
336          * If %NULL, Registrar will generate per-device PSK. In addition, AP
337          * uses this when acting as an Enrollee to notify Registrar of the
338          * current configuration.
339          */
340         u8 *network_key;
341
342         /**
343          * network_key_len - Length of network_key in octets
344          */
345         size_t network_key_len;
346
347         /**
348          * cred_cb - Callback to notify that new Credentials were received
349          * @ctx: Higher layer context data (cb_ctx)
350          * @cred: The received Credential
351          * Return: 0 on success, -1 on failure
352          */
353         int (*cred_cb)(void *ctx, const struct wps_credential *cred);
354
355         /**
356          * event_cb - Event callback (state information about progress)
357          * @ctx: Higher layer context data (cb_ctx)
358          * @event: Event type
359          * @data: Event data
360          */
361         void (*event_cb)(void *ctx, enum wps_event event,
362                          union wps_event_data *data);
363
364         /**
365          * cb_ctx: Higher layer context data for callbacks
366          */
367         void *cb_ctx;
368 };
369
370
371 struct wps_registrar *
372 wps_registrar_init(struct wps_context *wps,
373                    const struct wps_registrar_config *cfg);
374 void wps_registrar_deinit(struct wps_registrar *reg);
375 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
376                           const u8 *pin, size_t pin_len);
377 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
378 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
379 int wps_registrar_button_pushed(struct wps_registrar *reg);
380 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
381                                 const struct wpabuf *wps_data);
382
383 unsigned int wps_pin_checksum(unsigned int pin);
384 unsigned int wps_pin_valid(unsigned int pin);
385 unsigned int wps_generate_pin(void);
386
387 #endif /* WPS_H */