1 /*
2 * Wi-Fi Protected Setup
3 * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9 #include "includes.h"
10
11 #include "common.h"
12 #include "crypto/dh_group5.h"
13 #include "common/ieee802_11_defs.h"
14 #include "wps_i.h"
15 #include "wps_dev_attr.h"
16
17
18 #ifdef CONFIG_WPS_TESTING
19 int wps_version_number = 0x20;
20 int wps_testing_stub_cred = 0;
21 int wps_corrupt_pkhash = 0;
22 int wps_force_auth_types_in_use = 0;
23 u16 wps_force_auth_types = 0;
24 int wps_force_encr_types_in_use = 0;
25 u16 wps_force_encr_types = 0;
26 #endif /* CONFIG_WPS_TESTING */
27
28
29 /**
30 * wps_init - Initialize WPS Registration protocol data
31 * @cfg: WPS configuration
32 * Returns: Pointer to allocated data or %NULL on failure
33 *
34 * This function is used to initialize WPS data for a registration protocol
35 * instance (i.e., each run of registration protocol as a Registrar of
36 * Enrollee. The caller is responsible for freeing this data after the
37 * registration run has been completed by calling wps_deinit().
38 */
wps_init(const struct wps_config * cfg)39 struct wps_data * wps_init(const struct wps_config *cfg)
40 {
41 struct wps_data *data = os_zalloc(sizeof(*data));
42 if (data == NULL)
43 return NULL;
44 data->wps = cfg->wps;
45 data->registrar = cfg->registrar;
46 if (cfg->registrar) {
47 os_memcpy(data->uuid_r, cfg->wps->uuid, WPS_UUID_LEN);
48 } else {
49 os_memcpy(data->mac_addr_e, cfg->wps->dev.mac_addr, ETH_ALEN);
50 os_memcpy(data->uuid_e, cfg->wps->uuid, WPS_UUID_LEN);
51 }
52 if (cfg->pin) {
53 data->dev_pw_id = cfg->dev_pw_id;
54 data->dev_password = os_memdup(cfg->pin, cfg->pin_len);
55 if (data->dev_password == NULL) {
56 os_free(data);
57 return NULL;
58 }
59 data->dev_password_len = cfg->pin_len;
60 wpa_hexdump_key(MSG_DEBUG, "WPS: AP PIN dev_password",
61 data->dev_password, data->dev_password_len);
62 }
63
64 #ifdef CONFIG_WPS_NFC
65 if (cfg->pin == NULL &&
66 cfg->dev_pw_id == DEV_PW_NFC_CONNECTION_HANDOVER)
67 data->dev_pw_id = cfg->dev_pw_id;
68
69 if (cfg->wps->ap && !cfg->registrar && cfg->wps->ap_nfc_dev_pw_id) {
70 /* Keep AP PIN as alternative Device Password */
71 data->alt_dev_pw_id = data->dev_pw_id;
72 data->alt_dev_password = data->dev_password;
73 data->alt_dev_password_len = data->dev_password_len;
74
75 data->dev_pw_id = cfg->wps->ap_nfc_dev_pw_id;
76 data->dev_password =
77 os_memdup(wpabuf_head(cfg->wps->ap_nfc_dev_pw),
78 wpabuf_len(cfg->wps->ap_nfc_dev_pw));
79 if (data->dev_password == NULL) {
80 os_free(data);
81 return NULL;
82 }
83 data->dev_password_len = wpabuf_len(cfg->wps->ap_nfc_dev_pw);
84 wpa_hexdump_key(MSG_DEBUG, "WPS: NFC dev_password",
85 data->dev_password, data->dev_password_len);
86 }
87 #endif /* CONFIG_WPS_NFC */
88
89 data->pbc = cfg->pbc;
90 if (cfg->pbc) {
91 /* Use special PIN '00000000' for PBC */
92 data->dev_pw_id = DEV_PW_PUSHBUTTON;
93 bin_clear_free(data->dev_password, data->dev_password_len);
94 data->dev_password = (u8 *) os_strdup("00000000");
95 if (data->dev_password == NULL) {
96 os_free(data);
97 return NULL;
98 }
99 data->dev_password_len = 8;
100 }
101
102 data->state = data->registrar ? RECV_M1 : SEND_M1;
103
104 if (cfg->assoc_wps_ie) {
105 struct wps_parse_attr attr;
106 wpa_hexdump_buf(MSG_DEBUG, "WPS: WPS IE from (Re)AssocReq",
107 cfg->assoc_wps_ie);
108 if (wps_parse_msg(cfg->assoc_wps_ie, &attr) < 0) {
109 wpa_printf(MSG_DEBUG, "WPS: Failed to parse WPS IE "
110 "from (Re)AssocReq");
111 } else if (attr.request_type == NULL) {
112 wpa_printf(MSG_DEBUG, "WPS: No Request Type attribute "
113 "in (Re)AssocReq WPS IE");
114 } else {
115 wpa_printf(MSG_DEBUG, "WPS: Request Type (from WPS IE "
116 "in (Re)AssocReq WPS IE): %d",
117 *attr.request_type);
118 data->request_type = *attr.request_type;
119 }
120 }
121
122 if (cfg->new_ap_settings) {
123 data->new_ap_settings =
124 os_memdup(cfg->new_ap_settings,
125 sizeof(*data->new_ap_settings));
126 if (data->new_ap_settings == NULL) {
127 bin_clear_free(data->dev_password,
128 data->dev_password_len);
129 os_free(data);
130 return NULL;
131 }
132 }
133
134 if (cfg->peer_addr)
135 os_memcpy(data->peer_dev.mac_addr, cfg->peer_addr, ETH_ALEN);
136 if (cfg->p2p_dev_addr)
137 os_memcpy(data->p2p_dev_addr, cfg->p2p_dev_addr, ETH_ALEN);
138
139 data->use_psk_key = cfg->use_psk_key;
140 #ifndef EXT_CODE_CROP
141 data->pbc_in_m1 = cfg->pbc_in_m1;
142 #endif
143 if (cfg->peer_pubkey_hash) {
144 os_memcpy(data->peer_pubkey_hash, cfg->peer_pubkey_hash,
145 WPS_OOB_PUBKEY_HASH_LEN);
146 data->peer_pubkey_hash_set = 1;
147 }
148 #ifndef EXT_CODE_CROP
149 data->multi_ap_backhaul_sta = cfg->multi_ap_backhaul_sta;
150 #endif /* EXT_CODE_CROP */
151 return data;
152 }
153
154
155 /**
156 * wps_deinit - Deinitialize WPS Registration protocol data
157 * @data: WPS Registration protocol data from wps_init()
158 */
wps_deinit(struct wps_data * data)159 void wps_deinit(struct wps_data *data)
160 {
161 #ifdef CONFIG_WPS_NFC
162 if (data->registrar && data->nfc_pw_token)
163 wps_registrar_remove_nfc_pw_token(data->wps->registrar,
164 data->nfc_pw_token);
165 #endif /* CONFIG_WPS_NFC */
166
167 #ifdef CONFIG_WPS_AP
168 if (data->wps_pin_revealed) {
169 wpa_printf(MSG_DEBUG, "WPS: Full PIN information revealed and "
170 "negotiation failed");
171 if (data->registrar)
172 wps_registrar_invalidate_pin(data->wps->registrar,
173 data->uuid_e);
174 } else if (data->registrar)
175 wps_registrar_unlock_pin(data->wps->registrar, data->uuid_e);
176 #endif /* CONFIG_WPS_AP */
177
178 wpabuf_clear_free(data->dh_privkey);
179 wpabuf_free(data->dh_pubkey_e);
180 wpabuf_free(data->dh_pubkey_r);
181 wpabuf_free(data->last_msg);
182 bin_clear_free(data->dev_password, data->dev_password_len);
183 bin_clear_free(data->alt_dev_password, data->alt_dev_password_len);
184 bin_clear_free(data->new_psk, data->new_psk_len);
185 wps_device_data_free(&data->peer_dev);
186 bin_clear_free(data->new_ap_settings, sizeof(*data->new_ap_settings));
187 dh5_free(data->dh_ctx);
188 os_free(data);
189 }
190
191
192 /**
193 * wps_process_msg - Process a WPS message
194 * @wps: WPS Registration protocol data from wps_init()
195 * @op_code: Message OP Code
196 * @msg: Message data
197 * Returns: Processing result
198 *
199 * This function is used to process WPS messages with OP Codes WSC_ACK,
200 * WSC_NACK, WSC_MSG, and WSC_Done. The caller (e.g., EAP server/peer) is
201 * responsible for reassembling the messages before calling this function.
202 * Response to this message is built by calling wps_get_msg().
203 */
wps_process_msg(struct wps_data * wps,enum wsc_op_code op_code,const struct wpabuf * msg)204 enum wps_process_res wps_process_msg(struct wps_data *wps,
205 enum wsc_op_code op_code,
206 const struct wpabuf *msg)
207 {
208 if (wps->registrar)
209 #ifdef CONFIG_WPS_AP
210 return wps_registrar_process_msg(wps, op_code, msg);
211 #else
212 return WPS_FAILURE;
213 #endif /* CONFIG_WPS_AP */
214 else
215 return wps_enrollee_process_msg(wps, op_code, msg);
216 }
217
218
219 /**
220 * wps_get_msg - Build a WPS message
221 * @wps: WPS Registration protocol data from wps_init()
222 * @op_code: Buffer for returning message OP Code
223 * Returns: The generated WPS message or %NULL on failure
224 *
225 * This function is used to build a response to a message processed by calling
226 * wps_process_msg(). The caller is responsible for freeing the buffer.
227 */
wps_get_msg(struct wps_data * wps,enum wsc_op_code * op_code)228 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code)
229 {
230 if (wps->registrar)
231 #ifdef CONFIG_WPS_AP
232 return wps_registrar_get_msg(wps, op_code);
233 #else
234 return NULL;
235 #endif /* CONFIG_WPS_AP */
236 else
237 return wps_enrollee_get_msg(wps, op_code);
238 }
239
240
241 /**
242 * wps_is_selected_pbc_registrar - Check whether WPS IE indicates active PBC
243 * @msg: WPS IE contents from Beacon or Probe Response frame
244 * Returns: 1 if PBC Registrar is active, 0 if not
245 */
wps_is_selected_pbc_registrar(const struct wpabuf * msg)246 int wps_is_selected_pbc_registrar(const struct wpabuf *msg)
247 {
248 struct wps_parse_attr attr;
249
250 /*
251 * In theory, this could also verify that attr.sel_reg_config_methods
252 * includes WPS_CONFIG_PUSHBUTTON, but some deployed AP implementations
253 * do not set Selected Registrar Config Methods attribute properly, so
254 * it is safer to just use Device Password ID here.
255 */
256
257 if (wps_parse_msg(msg, &attr) < 0 ||
258 !attr.selected_registrar || *attr.selected_registrar == 0 ||
259 !attr.dev_password_id ||
260 WPA_GET_BE16(attr.dev_password_id) != DEV_PW_PUSHBUTTON)
261 return 0;
262
263 #ifdef CONFIG_WPS_STRICT
264 if (!attr.sel_reg_config_methods ||
265 !(WPA_GET_BE16(attr.sel_reg_config_methods) &
266 WPS_CONFIG_PUSHBUTTON))
267 return 0;
268 #endif /* CONFIG_WPS_STRICT */
269
270 return 1;
271 }
272
273
is_selected_pin_registrar(struct wps_parse_attr * attr)274 static int is_selected_pin_registrar(struct wps_parse_attr *attr)
275 {
276 /*
277 * In theory, this could also verify that attr.sel_reg_config_methods
278 * includes WPS_CONFIG_LABEL, WPS_CONFIG_DISPLAY, or WPS_CONFIG_KEYPAD,
279 * but some deployed AP implementations do not set Selected Registrar
280 * Config Methods attribute properly, so it is safer to just use
281 * Device Password ID here.
282 */
283
284 if (!attr->selected_registrar || *attr->selected_registrar == 0)
285 return 0;
286
287 if (attr->dev_password_id != NULL &&
288 WPA_GET_BE16(attr->dev_password_id) == DEV_PW_PUSHBUTTON)
289 return 0;
290
291 #ifdef CONFIG_WPS_STRICT
292 if (!attr->sel_reg_config_methods ||
293 !(WPA_GET_BE16(attr->sel_reg_config_methods) &
294 (WPS_CONFIG_LABEL | WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD)))
295 return 0;
296 #endif /* CONFIG_WPS_STRICT */
297
298 return 1;
299 }
300
301
302 /**
303 * wps_is_selected_pin_registrar - Check whether WPS IE indicates active PIN
304 * @msg: WPS IE contents from Beacon or Probe Response frame
305 * Returns: 1 if PIN Registrar is active, 0 if not
306 */
wps_is_selected_pin_registrar(const struct wpabuf * msg)307 int wps_is_selected_pin_registrar(const struct wpabuf *msg)
308 {
309 struct wps_parse_attr attr;
310
311 if (wps_parse_msg(msg, &attr) < 0)
312 return 0;
313
314 return is_selected_pin_registrar(&attr);
315 }
316
317
318 /**
319 * wps_is_addr_authorized - Check whether WPS IE authorizes MAC address
320 * @msg: WPS IE contents from Beacon or Probe Response frame
321 * @addr: MAC address to search for
322 * @ver1_compat: Whether to use version 1 compatibility mode
323 * Returns: 2 if the specified address is explicit authorized, 1 if address is
324 * authorized (broadcast), 0 if not
325 */
wps_is_addr_authorized(const struct wpabuf * msg,const u8 * addr,int ver1_compat)326 int wps_is_addr_authorized(const struct wpabuf *msg, const u8 *addr,
327 int ver1_compat)
328 {
329 struct wps_parse_attr attr;
330 unsigned int i;
331 const u8 *pos;
332 const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
333
334 if (wps_parse_msg(msg, &attr) < 0)
335 return 0;
336
337 if (!attr.version2 && ver1_compat) {
338 /*
339 * Version 1.0 AP - AuthorizedMACs not used, so revert back to
340 * old mechanism of using SelectedRegistrar.
341 */
342 return is_selected_pin_registrar(&attr);
343 }
344
345 if (!attr.authorized_macs)
346 return 0;
347
348 pos = attr.authorized_macs;
349 for (i = 0; i < attr.authorized_macs_len / ETH_ALEN; i++) {
350 if (os_memcmp(pos, addr, ETH_ALEN) == 0)
351 return 2;
352 if (os_memcmp(pos, bcast, ETH_ALEN) == 0)
353 return 1;
354 pos += ETH_ALEN;
355 }
356
357 return 0;
358 }
359
360
361 /**
362 * wps_ap_priority_compar - Prioritize WPS IE from two APs
363 * @wps_a: WPS IE contents from Beacon or Probe Response frame
364 * @wps_b: WPS IE contents from Beacon or Probe Response frame
365 * Returns: 1 if wps_b is considered more likely selection for WPS
366 * provisioning, -1 if wps_a is considered more like, or 0 if no preference
367 */
wps_ap_priority_compar(const struct wpabuf * wps_a,const struct wpabuf * wps_b)368 int wps_ap_priority_compar(const struct wpabuf *wps_a,
369 const struct wpabuf *wps_b)
370 {
371 struct wps_parse_attr attr;
372 int sel_a, sel_b;
373
374 if (wps_a == NULL || wps_parse_msg(wps_a, &attr) < 0)
375 return 1;
376 sel_a = attr.selected_registrar && *attr.selected_registrar != 0;
377
378 if (wps_b == NULL || wps_parse_msg(wps_b, &attr) < 0)
379 return -1;
380 sel_b = attr.selected_registrar && *attr.selected_registrar != 0;
381
382 if (sel_a && !sel_b)
383 return -1;
384 if (!sel_a && sel_b)
385 return 1;
386
387 return 0;
388 }
389
390
391 /**
392 * wps_get_uuid_e - Get UUID-E from WPS IE
393 * @msg: WPS IE contents from Beacon or Probe Response frame
394 * Returns: Pointer to UUID-E or %NULL if not included
395 *
396 * The returned pointer is to the msg contents and it remains valid only as
397 * long as the msg buffer is valid.
398 */
wps_get_uuid_e(const struct wpabuf * msg)399 const u8 * wps_get_uuid_e(const struct wpabuf *msg)
400 {
401 struct wps_parse_attr attr;
402
403 if (wps_parse_msg(msg, &attr) < 0)
404 return NULL;
405 return attr.uuid_e;
406 }
407
408
409 /**
410 * wps_is_20 - Check whether WPS attributes claim support for WPS 2.0
411 */
wps_is_20(const struct wpabuf * msg)412 int wps_is_20(const struct wpabuf *msg)
413 {
414 struct wps_parse_attr attr;
415
416 if (msg == NULL || wps_parse_msg(msg, &attr) < 0)
417 return 0;
418 return attr.version2 != NULL;
419 }
420
421
422 /**
423 * wps_build_assoc_req_ie - Build WPS IE for (Re)Association Request
424 * @req_type: Value for Request Type attribute
425 * Returns: WPS IE or %NULL on failure
426 *
427 * The caller is responsible for freeing the buffer.
428 */
wps_build_assoc_req_ie(enum wps_request_type req_type)429 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type)
430 {
431 struct wpabuf *ie;
432 u8 *len;
433
434 wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
435 "Request");
436 ie = wpabuf_alloc(100);
437 if (ie == NULL)
438 return NULL;
439
440 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
441 len = wpabuf_put(ie, 1);
442 wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
443
444 if (wps_build_version(ie) ||
445 wps_build_req_type(ie, req_type) ||
446 wps_build_wfa_ext(ie, 0, NULL, 0, 0)) {
447 wpabuf_free(ie);
448 return NULL;
449 }
450
451 *len = wpabuf_len(ie) - 2;
452
453 return ie;
454 }
455
456
457 /**
458 * wps_build_assoc_resp_ie - Build WPS IE for (Re)Association Response
459 * Returns: WPS IE or %NULL on failure
460 *
461 * The caller is responsible for freeing the buffer.
462 */
wps_build_assoc_resp_ie(void)463 struct wpabuf * wps_build_assoc_resp_ie(void)
464 {
465 struct wpabuf *ie;
466 u8 *len;
467
468 wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for (Re)Association "
469 "Response");
470 ie = wpabuf_alloc(100);
471 if (ie == NULL)
472 return NULL;
473
474 wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
475 len = wpabuf_put(ie, 1);
476 wpabuf_put_be32(ie, WPS_DEV_OUI_WFA);
477
478 if (wps_build_version(ie) ||
479 wps_build_resp_type(ie, WPS_RESP_AP) ||
480 wps_build_wfa_ext(ie, 0, NULL, 0, 0)) {
481 wpabuf_free(ie);
482 return NULL;
483 }
484
485 *len = wpabuf_len(ie) - 2;
486
487 return ie;
488 }
489
490
491 /**
492 * wps_build_probe_req_ie - Build WPS IE for Probe Request
493 * @pw_id: Password ID (DEV_PW_PUSHBUTTON for active PBC and DEV_PW_DEFAULT for
494 * most other use cases)
495 * @dev: Device attributes
496 * @uuid: Own UUID
497 * @req_type: Value for Request Type attribute
498 * @num_req_dev_types: Number of requested device types
499 * @req_dev_types: Requested device types (8 * num_req_dev_types octets) or
500 * %NULL if none
501 * Returns: WPS IE or %NULL on failure
502 *
503 * The caller is responsible for freeing the buffer.
504 */
wps_build_probe_req_ie(u16 pw_id,struct wps_device_data * dev,const u8 * uuid,enum wps_request_type req_type,unsigned int num_req_dev_types,const u8 * req_dev_types)505 struct wpabuf * wps_build_probe_req_ie(u16 pw_id, struct wps_device_data *dev,
506 const u8 *uuid,
507 enum wps_request_type req_type,
508 unsigned int num_req_dev_types,
509 const u8 *req_dev_types)
510 {
511 struct wpabuf *ie;
512
513 wpa_printf(MSG_DEBUG, "WPS: Building WPS IE for Probe Request");
514
515 ie = wpabuf_alloc(500);
516 if (ie == NULL)
517 return NULL;
518
519 if (wps_build_version(ie) ||
520 wps_build_req_type(ie, req_type) ||
521 wps_build_config_methods(ie, dev->config_methods) ||
522 wps_build_uuid_e(ie, uuid) ||
523 wps_build_primary_dev_type(dev, ie) ||
524 wps_build_rf_bands(dev, ie, 0) ||
525 wps_build_assoc_state(NULL, ie) ||
526 wps_build_config_error(ie, WPS_CFG_NO_ERROR) ||
527 wps_build_dev_password_id(ie, pw_id) ||
528 wps_build_manufacturer(dev, ie) ||
529 wps_build_model_name(dev, ie) ||
530 wps_build_model_number(dev, ie) ||
531 wps_build_dev_name(dev, ie) ||
532 wps_build_wfa_ext(ie, req_type == WPS_REQ_ENROLLEE, NULL, 0, 0) ||
533 wps_build_req_dev_type(dev, ie, num_req_dev_types, req_dev_types)
534 ||
535 wps_build_secondary_dev_type(dev, ie)
536 ) {
537 wpabuf_free(ie);
538 return NULL;
539 }
540
541 return wps_ie_encapsulate(ie);
542 }
543
544
wps_free_pending_msgs(struct upnp_pending_message * msgs)545 void wps_free_pending_msgs(struct upnp_pending_message *msgs)
546 {
547 struct upnp_pending_message *p, *prev;
548 p = msgs;
549 while (p) {
550 prev = p;
551 p = p->next;
552 wpabuf_free(prev->msg);
553 os_free(prev);
554 }
555 }
556
557
wps_attr_text(struct wpabuf * data,char * buf,char * end)558 int wps_attr_text(struct wpabuf *data, char *buf, char *end)
559 {
560 struct wps_parse_attr attr;
561 char *pos = buf;
562 int ret;
563
564 if (wps_parse_msg(data, &attr) < 0)
565 return -1;
566
567 if (attr.wps_state) {
568 if (*attr.wps_state == WPS_STATE_NOT_CONFIGURED)
569 ret = os_snprintf(pos, end - pos,
570 "wps_state=unconfigured\n");
571 else if (*attr.wps_state == WPS_STATE_CONFIGURED)
572 ret = os_snprintf(pos, end - pos,
573 "wps_state=configured\n");
574 else
575 ret = 0;
576 if (os_snprintf_error(end - pos, ret))
577 return pos - buf;
578 pos += ret;
579 }
580
581 if (attr.ap_setup_locked && *attr.ap_setup_locked) {
582 ret = os_snprintf(pos, end - pos,
583 "wps_ap_setup_locked=1\n");
584 if (os_snprintf_error(end - pos, ret))
585 return pos - buf;
586 pos += ret;
587 }
588
589 if (attr.selected_registrar && *attr.selected_registrar) {
590 ret = os_snprintf(pos, end - pos,
591 "wps_selected_registrar=1\n");
592 if (os_snprintf_error(end - pos, ret))
593 return pos - buf;
594 pos += ret;
595 }
596
597 if (attr.dev_password_id) {
598 ret = os_snprintf(pos, end - pos,
599 "wps_device_password_id=%u\n",
600 WPA_GET_BE16(attr.dev_password_id));
601 if (os_snprintf_error(end - pos, ret))
602 return pos - buf;
603 pos += ret;
604 }
605
606 if (attr.sel_reg_config_methods) {
607 ret = os_snprintf(pos, end - pos,
608 "wps_selected_registrar_config_methods="
609 "0x%04x\n",
610 WPA_GET_BE16(attr.sel_reg_config_methods));
611 if (os_snprintf_error(end - pos, ret))
612 return pos - buf;
613 pos += ret;
614 }
615
616 if (attr.primary_dev_type) {
617 char devtype[WPS_DEV_TYPE_BUFSIZE];
618 ret = os_snprintf(pos, end - pos,
619 "wps_primary_device_type=%s\n",
620 wps_dev_type_bin2str(attr.primary_dev_type,
621 devtype,
622 sizeof(devtype)));
623 if (os_snprintf_error(end - pos, ret))
624 return pos - buf;
625 pos += ret;
626 }
627
628 if (attr.dev_name) {
629 char *str = os_malloc(attr.dev_name_len + 1);
630 size_t i;
631 if (str == NULL)
632 return pos - buf;
633 for (i = 0; i < attr.dev_name_len; i++) {
634 if (attr.dev_name[i] == 0 ||
635 is_ctrl_char(attr.dev_name[i]))
636 str[i] = '_';
637 else
638 str[i] = attr.dev_name[i];
639 }
640 str[i] = '\0';
641 ret = os_snprintf(pos, end - pos, "wps_device_name=%s\n", str);
642 os_free(str);
643 if (os_snprintf_error(end - pos, ret))
644 return pos - buf;
645 pos += ret;
646 }
647
648 if (attr.config_methods) {
649 ret = os_snprintf(pos, end - pos,
650 "wps_config_methods=0x%04x\n",
651 WPA_GET_BE16(attr.config_methods));
652 if (os_snprintf_error(end - pos, ret))
653 return pos - buf;
654 pos += ret;
655 }
656
657 return pos - buf;
658 }
659
660
wps_ei_str(enum wps_error_indication ei)661 const char * wps_ei_str(enum wps_error_indication ei)
662 {
663 switch (ei) {
664 case WPS_EI_NO_ERROR:
665 return "No Error";
666 case WPS_EI_SECURITY_TKIP_ONLY_PROHIBITED:
667 return "TKIP Only Prohibited";
668 case WPS_EI_SECURITY_WEP_PROHIBITED:
669 return "WEP Prohibited";
670 case WPS_EI_AUTH_FAILURE:
671 return "Authentication Failure";
672 default:
673 return "Unknown";
674 }
675 }
676