]> git.ipfire.org Git - thirdparty/hostap.git/blob - src/wps/wps.h
WPS UFD: Remove oob_dev pointer from wps_context
[thirdparty/hostap.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_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
36 /**
37 * struct wps_credential - WPS Credential
38 * @ssid: SSID
39 * @ssid_len: Length of SSID
40 * @auth_type: Authentication Type (WPS_AUTH_OPEN, .. flags)
41 * @encr_type: Encryption Type (WPS_ENCR_NONE, .. flags)
42 * @key_idx: Key index
43 * @key: Key
44 * @key_len: Key length in octets
45 * @mac_addr: MAC address of the peer
46 * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
47 * this may be %NULL, if not used
48 * @cred_attr_len: Length of cred_attr in octets
49 */
50 struct wps_credential {
51 u8 ssid[32];
52 size_t ssid_len;
53 u16 auth_type;
54 u16 encr_type;
55 u8 key_idx;
56 u8 key[64];
57 size_t key_len;
58 u8 mac_addr[ETH_ALEN];
59 const u8 *cred_attr;
60 size_t cred_attr_len;
61 };
62
63 /**
64 * struct wps_device_data - WPS Device Data
65 * @mac_addr: Device MAC address
66 * @device_name: Device Name (0..32 octets encoded in UTF-8)
67 * @manufacturer: Manufacturer (0..64 octets encoded in UTF-8)
68 * @model_name: Model Name (0..32 octets encoded in UTF-8)
69 * @model_number: Model Number (0..32 octets encoded in UTF-8)
70 * @serial_number: Serial Number (0..32 octets encoded in UTF-8)
71 * @categ: Primary Device Category
72 * @oui: Primary Device OUI
73 * @sub_categ: Primary Device Sub-Category
74 * @os_version: OS Version
75 * @rf_bands: RF bands (WPS_RF_24GHZ, WPS_RF_50GHZ flags)
76 */
77 struct wps_device_data {
78 u8 mac_addr[ETH_ALEN];
79 char *device_name;
80 char *manufacturer;
81 char *model_name;
82 char *model_number;
83 char *serial_number;
84 u16 categ;
85 u32 oui;
86 u16 sub_categ;
87 u32 os_version;
88 u8 rf_bands;
89 };
90
91 struct oob_conf_data {
92 enum {
93 OOB_METHOD_UNKNOWN = 0,
94 OOB_METHOD_DEV_PWD_E,
95 OOB_METHOD_DEV_PWD_R,
96 OOB_METHOD_CRED,
97 } oob_method;
98 struct wpabuf *dev_password;
99 struct wpabuf *pubkey_hash;
100 };
101
102 /**
103 * struct wps_config - WPS configuration for a single registration protocol run
104 */
105 struct wps_config {
106 /**
107 * wps - Pointer to long term WPS context
108 */
109 struct wps_context *wps;
110
111 /**
112 * registrar - Whether this end is a Registrar
113 */
114 int registrar;
115
116 /**
117 * pin - Enrollee Device Password (%NULL for Registrar or PBC)
118 */
119 const u8 *pin;
120
121 /**
122 * pin_len - Length on pin in octets
123 */
124 size_t pin_len;
125
126 /**
127 * pbc - Whether this is protocol run uses PBC
128 */
129 int pbc;
130
131 /**
132 * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
133 */
134 const struct wpabuf *assoc_wps_ie;
135 };
136
137 struct wps_data * wps_init(const struct wps_config *cfg);
138
139 void wps_deinit(struct wps_data *data);
140
141 /**
142 * enum wps_process_res - WPS message processing result
143 */
144 enum wps_process_res {
145 /**
146 * WPS_DONE - Processing done
147 */
148 WPS_DONE,
149
150 /**
151 * WPS_CONTINUE - Processing continues
152 */
153 WPS_CONTINUE,
154
155 /**
156 * WPS_FAILURE - Processing failed
157 */
158 WPS_FAILURE,
159
160 /**
161 * WPS_PENDING - Processing continues, but waiting for an external
162 * event (e.g., UPnP message from an external Registrar)
163 */
164 WPS_PENDING
165 };
166 enum wps_process_res wps_process_msg(struct wps_data *wps,
167 enum wsc_op_code op_code,
168 const struct wpabuf *msg);
169
170 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
171
172 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
173 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
174 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
175
176 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
177 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
178 const u8 *uuid,
179 enum wps_request_type req_type);
180
181
182 /**
183 * struct wps_registrar_config - WPS Registrar configuration
184 */
185 struct wps_registrar_config {
186 /**
187 * new_psk_cb - Callback for new PSK
188 * @ctx: Higher layer context data (cb_ctx)
189 * @mac_addr: MAC address of the Enrollee
190 * @psk: The new PSK
191 * @psk_len: The length of psk in octets
192 * Returns: 0 on success, -1 on failure
193 *
194 * This callback is called when a new per-device PSK is provisioned.
195 */
196 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
197 size_t psk_len);
198
199 /**
200 * set_ie_cb - Callback for WPS IE changes
201 * @ctx: Higher layer context data (cb_ctx)
202 * @beacon_ie: WPS IE for Beacon
203 * @beacon_ie_len: WPS IE length for Beacon
204 * @probe_resp_ie: WPS IE for Probe Response
205 * @probe_resp_ie_len: WPS IE length for Probe Response
206 * Returns: 0 on success, -1 on failure
207 *
208 * This callback is called whenever the WPS IE in Beacon or Probe
209 * Response frames needs to be changed (AP only).
210 */
211 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
212 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
213
214 /**
215 * pin_needed_cb - Callback for requesting a PIN
216 * @ctx: Higher layer context data (cb_ctx)
217 * @uuid_e: UUID-E of the unknown Enrollee
218 * @dev: Device Data from the unknown Enrollee
219 *
220 * This callback is called whenever an unknown Enrollee requests to use
221 * PIN method and a matching PIN (Device Password) is not found in
222 * Registrar data.
223 */
224 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
225 const struct wps_device_data *dev);
226
227 /**
228 * reg_success_cb - Callback for reporting successful registration
229 * @ctx: Higher layer context data (cb_ctx)
230 * @mac_addr: MAC address of the Enrollee
231 * @uuid_e: UUID-E of the Enrollee
232 *
233 * This callback is called whenever an Enrollee completes registration
234 * successfully.
235 */
236 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
237 const u8 *uuid_e);
238
239 /**
240 * cb_ctx: Higher layer context data for Registrar callbacks
241 */
242 void *cb_ctx;
243
244 /**
245 * skip_cred_build: Do not build credential
246 *
247 * This option can be used to disable internal code that builds
248 * Credential attribute into M8 based on the current network
249 * configuration and Enrollee capabilities. The extra_cred data will
250 * then be used as the Credential(s).
251 */
252 int skip_cred_build;
253
254 /**
255 * extra_cred: Additional Credential attribute(s)
256 *
257 * This optional data (set to %NULL to disable) can be used to add
258 * Credential attribute(s) for other networks into M8. If
259 * skip_cred_build is set, this will also override the automatically
260 * generated Credential attribute.
261 */
262 const u8 *extra_cred;
263
264 /**
265 * extra_cred_len: Length of extra_cred in octets
266 */
267 size_t extra_cred_len;
268
269 /**
270 * disable_auto_conf - Disable auto-configuration on first registration
271 *
272 * By default, the AP that is started in not configured state will
273 * generate a random PSK and move to configured state when the first
274 * registration protocol run is completed successfully. This option can
275 * be used to disable this functionality and leave it up to an external
276 * program to take care of configuration. This requires the extra_cred
277 * to be set with a suitable Credential and skip_cred_build being used.
278 */
279 int disable_auto_conf;
280 };
281
282
283 /**
284 * enum wps_event - WPS event types
285 */
286 enum wps_event {
287 /**
288 * WPS_EV_M2D - M2D received (Registrar did not know us)
289 */
290 WPS_EV_M2D,
291
292 /**
293 * WPS_EV_FAIL - Registration failed
294 */
295 WPS_EV_FAIL,
296
297 /**
298 * WPS_EV_SUCCESS - Registration succeeded
299 */
300 WPS_EV_SUCCESS,
301
302 /**
303 * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
304 */
305 WPS_EV_PWD_AUTH_FAIL
306 };
307
308 /**
309 * union wps_event_data - WPS event data
310 */
311 union wps_event_data {
312 /**
313 * struct wps_event_m2d - M2D event data
314 */
315 struct wps_event_m2d {
316 u16 config_methods;
317 const u8 *manufacturer;
318 size_t manufacturer_len;
319 const u8 *model_name;
320 size_t model_name_len;
321 const u8 *model_number;
322 size_t model_number_len;
323 const u8 *serial_number;
324 size_t serial_number_len;
325 const u8 *dev_name;
326 size_t dev_name_len;
327 const u8 *primary_dev_type; /* 8 octets */
328 u16 config_error;
329 u16 dev_password_id;
330 } m2d;
331
332 /**
333 * struct wps_event_fail - Registration failure information
334 * @msg: enum wps_msg_type
335 */
336 struct wps_event_fail {
337 int msg;
338 } fail;
339
340 struct wps_event_pwd_auth_fail {
341 int enrollee;
342 int part;
343 } pwd_auth_fail;
344 };
345
346 /**
347 * struct upnp_pending_message - Pending PutWLANResponse messages
348 * @next: Pointer to next pending message or %NULL
349 * @addr: NewWLANEventMAC
350 * @msg: NewMessage
351 * @type: Message Type
352 */
353 struct upnp_pending_message {
354 struct upnp_pending_message *next;
355 u8 addr[ETH_ALEN];
356 struct wpabuf *msg;
357 enum wps_msg_type type;
358 };
359
360 /**
361 * struct wps_context - Long term WPS context data
362 *
363 * This data is stored at the higher layer Authenticator or Supplicant data
364 * structures and it is maintained over multiple registration protocol runs.
365 */
366 struct wps_context {
367 /**
368 * ap - Whether the local end is an access point
369 */
370 int ap;
371
372 /**
373 * registrar - Pointer to WPS registrar data from wps_registrar_init()
374 */
375 struct wps_registrar *registrar;
376
377 /**
378 * wps_state - Current WPS state
379 */
380 enum wps_state wps_state;
381
382 /**
383 * ap_setup_locked - Whether AP setup is locked (only used at AP)
384 */
385 int ap_setup_locked;
386
387 /**
388 * uuid - Own UUID
389 */
390 u8 uuid[16];
391
392 /**
393 * ssid - SSID
394 *
395 * This SSID is used by the Registrar to fill in information for
396 * Credentials. In addition, AP uses it when acting as an Enrollee to
397 * notify Registrar of the current configuration.
398 */
399 u8 ssid[32];
400
401 /**
402 * ssid_len - Length of ssid in octets
403 */
404 size_t ssid_len;
405
406 /**
407 * dev - Own WPS device data
408 */
409 struct wps_device_data dev;
410
411 /**
412 * oob_conf - OOB Config data
413 */
414 struct oob_conf_data oob_conf;
415
416 /**
417 * oob_dev_pw_id - OOB Device password id
418 */
419 u16 oob_dev_pw_id;
420
421 /**
422 * dh_privkey - Diffie-Hellman private key
423 */
424 struct wpabuf *dh_privkey;
425
426 /**
427 * dh_pubkey_oob - Diffie-Hellman public key
428 */
429 struct wpabuf *dh_pubkey;
430
431 /**
432 * config_methods - Enabled configuration methods
433 *
434 * Bit field of WPS_CONFIG_*
435 */
436 u16 config_methods;
437
438 /**
439 * encr_types - Enabled encryption types (bit field of WPS_ENCR_*)
440 */
441 u16 encr_types;
442
443 /**
444 * auth_types - Authentication types (bit field of WPS_AUTH_*)
445 */
446 u16 auth_types;
447
448 /**
449 * network_key - The current Network Key (PSK) or %NULL to generate new
450 *
451 * If %NULL, Registrar will generate per-device PSK. In addition, AP
452 * uses this when acting as an Enrollee to notify Registrar of the
453 * current configuration.
454 */
455 u8 *network_key;
456
457 /**
458 * network_key_len - Length of network_key in octets
459 */
460 size_t network_key_len;
461
462 /**
463 * ap_settings - AP Settings override for M7 (only used at AP)
464 *
465 * If %NULL, AP Settings attributes will be generated based on the
466 * current network configuration.
467 */
468 u8 *ap_settings;
469
470 /**
471 * ap_settings_len - Length of ap_settings in octets
472 */
473 size_t ap_settings_len;
474
475 /**
476 * friendly_name - Friendly Name (required for UPnP)
477 */
478 char *friendly_name;
479
480 /**
481 * manufacturer_url - Manufacturer URL (optional for UPnP)
482 */
483 char *manufacturer_url;
484
485 /**
486 * model_description - Model Description (recommended for UPnP)
487 */
488 char *model_description;
489
490 /**
491 * model_url - Model URL (optional for UPnP)
492 */
493 char *model_url;
494
495 /**
496 * upc - Universal Product Code (optional for UPnP)
497 */
498 char *upc;
499
500 /**
501 * cred_cb - Callback to notify that new Credentials were received
502 * @ctx: Higher layer context data (cb_ctx)
503 * @cred: The received Credential
504 * Return: 0 on success, -1 on failure
505 */
506 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
507
508 /**
509 * event_cb - Event callback (state information about progress)
510 * @ctx: Higher layer context data (cb_ctx)
511 * @event: Event type
512 * @data: Event data
513 */
514 void (*event_cb)(void *ctx, enum wps_event event,
515 union wps_event_data *data);
516
517 /**
518 * cb_ctx: Higher layer context data for callbacks
519 */
520 void *cb_ctx;
521
522 struct upnp_wps_device_sm *wps_upnp;
523
524 /* Pending messages from UPnP PutWLANResponse */
525 struct upnp_pending_message *upnp_msgs;
526 };
527
528 struct oob_device_data {
529 char *device_path;
530 void * (*init_func)(struct wps_context *, struct oob_device_data *,
531 int);
532 struct wpabuf * (*read_func)(void *);
533 int (*write_func)(void *, struct wpabuf *);
534 void (*deinit_func)(void *);
535 };
536
537 struct wps_registrar *
538 wps_registrar_init(struct wps_context *wps,
539 const struct wps_registrar_config *cfg);
540 void wps_registrar_deinit(struct wps_registrar *reg);
541 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
542 const u8 *pin, size_t pin_len);
543 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
544 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
545 int wps_registrar_button_pushed(struct wps_registrar *reg);
546 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
547 const struct wpabuf *wps_data);
548 int wps_registrar_update_ie(struct wps_registrar *reg);
549 int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
550 const struct wpabuf *msg);
551
552 unsigned int wps_pin_checksum(unsigned int pin);
553 unsigned int wps_pin_valid(unsigned int pin);
554 unsigned int wps_generate_pin(void);
555 void wps_free_pending_msgs(struct upnp_pending_message *msgs);
556
557 struct oob_device_data * wps_get_oob_device(char *device_type);
558 int wps_get_oob_method(char *method);
559 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
560 int registrar);
561
562 #endif /* WPS_H */