304
306
wps->event_cb(wps->cb_ctx, WPS_EV_PBC_TIMEOUT, NULL);
310
#ifdef CONFIG_WPS_OOB
312
static struct wpabuf * wps_get_oob_cred(struct wps_context *wps)
314
struct wps_data data;
315
struct wpabuf *plain;
317
plain = wpabuf_alloc(500);
319
wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
324
os_memset(&data, 0, sizeof(data));
326
data.auth_type = wps->auth_types;
327
data.encr_type = wps->encr_types;
328
if (wps_build_version(plain) || wps_build_cred(&data, plain)) {
337
static struct wpabuf * wps_get_oob_dev_pwd(struct wps_context *wps)
341
data = wpabuf_alloc(9 + WPS_OOB_DEVICE_PASSWORD_ATTR_LEN);
343
wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
344
"device password attribute");
348
wpabuf_free(wps->oob_conf.dev_password);
349
wps->oob_conf.dev_password =
350
wpabuf_alloc(WPS_OOB_DEVICE_PASSWORD_LEN * 2 + 1);
351
if (wps->oob_conf.dev_password == NULL) {
352
wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
358
if (wps_build_version(data) ||
359
wps_build_oob_dev_password(data, wps)) {
360
wpa_printf(MSG_ERROR, "WPS: Build OOB device password "
370
static int wps_parse_oob_dev_pwd(struct wps_context *wps,
373
struct oob_conf_data *oob_conf = &wps->oob_conf;
374
struct wps_parse_attr attr;
377
if (wps_parse_msg(data, &attr) < 0 ||
378
attr.oob_dev_password == NULL) {
379
wpa_printf(MSG_ERROR, "WPS: OOB device password not found");
383
pos = attr.oob_dev_password;
385
oob_conf->pubkey_hash =
386
wpabuf_alloc_copy(pos, WPS_OOB_PUBKEY_HASH_LEN);
387
if (oob_conf->pubkey_hash == NULL) {
388
wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
392
pos += WPS_OOB_PUBKEY_HASH_LEN;
394
wps->oob_dev_pw_id = WPA_GET_BE16(pos);
395
pos += sizeof(wps->oob_dev_pw_id);
397
oob_conf->dev_password =
398
wpabuf_alloc(WPS_OOB_DEVICE_PASSWORD_LEN * 2 + 1);
399
if (oob_conf->dev_password == NULL) {
400
wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
404
wpa_snprintf_hex_uppercase(wpabuf_put(oob_conf->dev_password,
405
wpabuf_size(oob_conf->dev_password)),
406
wpabuf_size(oob_conf->dev_password), pos,
407
WPS_OOB_DEVICE_PASSWORD_LEN);
413
static int wps_parse_oob_cred(struct wps_context *wps, struct wpabuf *data)
416
struct wps_parse_attr attr;
419
if (wps_parse_msg(data, &attr) < 0 || attr.num_cred <= 0) {
420
wpa_printf(MSG_ERROR, "WPS: OOB credential not found");
424
for (i = 0; i < attr.num_cred; i++) {
425
struct wps_credential local_cred;
426
struct wps_parse_attr cattr;
428
os_memset(&local_cred, 0, sizeof(local_cred));
429
wpabuf_set(&msg, attr.cred[i], attr.cred_len[i]);
430
if (wps_parse_msg(&msg, &cattr) < 0 ||
431
wps_process_cred(&cattr, &local_cred)) {
432
wpa_printf(MSG_ERROR, "WPS: Failed to parse OOB "
436
wps->cred_cb(wps->cb_ctx, &local_cred);
443
int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
447
int ret, write_f, oob_method = wps->oob_conf.oob_method;
450
write_f = oob_method == OOB_METHOD_DEV_PWD_E ? !registrar : registrar;
452
oob_priv = oob_dev->init_func(wps, oob_dev, registrar);
453
if (oob_priv == NULL) {
454
wpa_printf(MSG_ERROR, "WPS: Failed to initialize OOB device");
459
if (oob_method == OOB_METHOD_CRED)
460
data = wps_get_oob_cred(wps);
462
data = wps_get_oob_dev_pwd(wps);
465
if (data == NULL || oob_dev->write_func(oob_priv, data) < 0)
468
data = oob_dev->read_func(oob_priv);
472
if (oob_method == OOB_METHOD_CRED)
473
ret = wps_parse_oob_cred(wps, data);
475
ret = wps_parse_oob_dev_pwd(wps, data);
479
oob_dev->deinit_func(oob_priv);
482
wpa_printf(MSG_ERROR, "WPS: Failed to process OOB data");
490
struct oob_device_data * wps_get_oob_device(char *device_type)
492
#ifdef CONFIG_WPS_UFD
493
if (os_strstr(device_type, "ufd") != NULL)
494
return &oob_ufd_device_data;
495
#endif /* CONFIG_WPS_UFD */
496
#ifdef CONFIG_WPS_NFC
497
if (os_strstr(device_type, "nfc") != NULL)
498
return &oob_nfc_device_data;
499
#endif /* CONFIG_WPS_NFC */
505
#ifdef CONFIG_WPS_NFC
506
struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name)
508
if (device_name == NULL)
510
#ifdef CONFIG_WPS_NFC_PN531
511
if (os_strstr(device_name, "pn531") != NULL)
512
return &oob_nfc_pn531_device_data;
513
#endif /* CONFIG_WPS_NFC_PN531 */
517
#endif /* CONFIG_WPS_NFC */
520
int wps_get_oob_method(char *method)
522
if (os_strstr(method, "pin-e") != NULL)
523
return OOB_METHOD_DEV_PWD_E;
524
if (os_strstr(method, "pin-r") != NULL)
525
return OOB_METHOD_DEV_PWD_R;
526
if (os_strstr(method, "cred") != NULL)
527
return OOB_METHOD_CRED;
528
return OOB_METHOD_UNKNOWN;
531
#endif /* CONFIG_WPS_OOB */
534
int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN])
538
/* <categ>-<OUI>-<subcateg> */
539
WPA_PUT_BE16(dev_type, atoi(str));
540
pos = os_strchr(str, '-');
544
if (hexstr2bin(pos, &dev_type[2], 4))
546
pos = os_strchr(pos, '-');
550
WPA_PUT_BE16(&dev_type[6], atoi(pos));
557
char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
562
ret = os_snprintf(buf, buf_len, "%u-%08X-%u",
563
WPA_GET_BE16(dev_type), WPA_GET_BE32(&dev_type[2]),
564
WPA_GET_BE16(&dev_type[6]));
565
if (ret < 0 || (unsigned int) ret >= buf_len)
572
void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid)
576
u8 hash[SHA1_MAC_LEN];
578
0x52, 0x64, 0x80, 0xf8,
582
0x58, 0xed, 0x5f, 0x5d, 0x60, 0x84
586
len[0] = sizeof(nsid);
589
sha1_vector(2, addr, len, hash);
590
os_memcpy(uuid, hash, 16);
592
/* Version: 5 = named-based version using SHA-1 */
593
uuid[6] = (5 << 4) | (uuid[6] & 0x0f);
595
/* Variant specified in RFC 4122 */
596
uuid[8] = 0x80 | (uuid[8] & 0x3f);
600
u16 wps_config_methods_str2bin(const char *str)
605
/* Default to enabling methods based on build configuration */
606
methods |= WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD;
607
#ifdef CONFIG_WPS_UFD
608
methods |= WPS_CONFIG_USBA;
609
#endif /* CONFIG_WPS_UFD */
610
#ifdef CONFIG_WPS_NFC
611
methods |= WPS_CONFIG_NFC_INTERFACE;
612
#endif /* CONFIG_WPS_NFC */
614
if (os_strstr(str, "usba"))
615
methods |= WPS_CONFIG_USBA;
616
if (os_strstr(str, "ethernet"))
617
methods |= WPS_CONFIG_ETHERNET;
618
if (os_strstr(str, "label"))
619
methods |= WPS_CONFIG_LABEL;
620
if (os_strstr(str, "display"))
621
methods |= WPS_CONFIG_DISPLAY;
622
if (os_strstr(str, "ext_nfc_token"))
623
methods |= WPS_CONFIG_EXT_NFC_TOKEN;
624
if (os_strstr(str, "int_nfc_token"))
625
methods |= WPS_CONFIG_INT_NFC_TOKEN;
626
if (os_strstr(str, "nfc_interface"))
627
methods |= WPS_CONFIG_NFC_INTERFACE;
628
if (os_strstr(str, "push_button"))
629
methods |= WPS_CONFIG_PUSHBUTTON;
630
if (os_strstr(str, "keypad"))
631
methods |= WPS_CONFIG_KEYPAD;