wps_common.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /*
  2. * Wi-Fi Protected Setup - common functionality
  3. * Copyright (c) 2008-2009, 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. #include "includes.h"
  15. #include "common.h"
  16. #include "crypto/aes_wrap.h"
  17. #include "crypto/crypto.h"
  18. #include "crypto/dh_group5.h"
  19. #include "crypto/sha1.h"
  20. #include "crypto/sha256.h"
  21. #include "wps_i.h"
  22. #include "wps_dev_attr.h"
  23. void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
  24. const char *label, u8 *res, size_t res_len)
  25. {
  26. u8 i_buf[4], key_bits[4];
  27. const u8 *addr[4];
  28. size_t len[4];
  29. int i, iter;
  30. u8 hash[SHA256_MAC_LEN], *opos;
  31. size_t left;
  32. WPA_PUT_BE32(key_bits, res_len * 8);
  33. addr[0] = i_buf;
  34. len[0] = sizeof(i_buf);
  35. addr[1] = label_prefix;
  36. len[1] = label_prefix_len;
  37. addr[2] = (const u8 *) label;
  38. len[2] = os_strlen(label);
  39. addr[3] = key_bits;
  40. len[3] = sizeof(key_bits);
  41. iter = (res_len + SHA256_MAC_LEN - 1) / SHA256_MAC_LEN;
  42. opos = res;
  43. left = res_len;
  44. for (i = 1; i <= iter; i++) {
  45. WPA_PUT_BE32(i_buf, i);
  46. hmac_sha256_vector(key, SHA256_MAC_LEN, 4, addr, len, hash);
  47. if (i < iter) {
  48. os_memcpy(opos, hash, SHA256_MAC_LEN);
  49. opos += SHA256_MAC_LEN;
  50. left -= SHA256_MAC_LEN;
  51. } else
  52. os_memcpy(opos, hash, left);
  53. }
  54. }
  55. int wps_derive_keys(struct wps_data *wps)
  56. {
  57. struct wpabuf *pubkey, *dh_shared;
  58. u8 dhkey[SHA256_MAC_LEN], kdk[SHA256_MAC_LEN];
  59. const u8 *addr[3];
  60. size_t len[3];
  61. u8 keys[WPS_AUTHKEY_LEN + WPS_KEYWRAPKEY_LEN + WPS_EMSK_LEN];
  62. if (wps->dh_privkey == NULL) {
  63. wpa_printf(MSG_DEBUG, "WPS: Own DH private key not available");
  64. return -1;
  65. }
  66. pubkey = wps->registrar ? wps->dh_pubkey_e : wps->dh_pubkey_r;
  67. if (pubkey == NULL) {
  68. wpa_printf(MSG_DEBUG, "WPS: Peer DH public key not available");
  69. return -1;
  70. }
  71. wpa_hexdump_buf_key(MSG_DEBUG, "WPS: DH Private Key", wps->dh_privkey);
  72. wpa_hexdump_buf(MSG_DEBUG, "WPS: DH peer Public Key", pubkey);
  73. dh_shared = dh5_derive_shared(wps->dh_ctx, pubkey, wps->dh_privkey);
  74. dh5_free(wps->dh_ctx);
  75. wps->dh_ctx = NULL;
  76. dh_shared = wpabuf_zeropad(dh_shared, 192);
  77. if (dh_shared == NULL) {
  78. wpa_printf(MSG_DEBUG, "WPS: Failed to derive DH shared key");
  79. return -1;
  80. }
  81. /* Own DH private key is not needed anymore */
  82. wpabuf_free(wps->dh_privkey);
  83. wps->dh_privkey = NULL;
  84. wpa_hexdump_buf_key(MSG_DEBUG, "WPS: DH shared key", dh_shared);
  85. /* DHKey = SHA-256(g^AB mod p) */
  86. addr[0] = wpabuf_head(dh_shared);
  87. len[0] = wpabuf_len(dh_shared);
  88. sha256_vector(1, addr, len, dhkey);
  89. wpa_hexdump_key(MSG_DEBUG, "WPS: DHKey", dhkey, sizeof(dhkey));
  90. wpabuf_free(dh_shared);
  91. /* KDK = HMAC-SHA-256_DHKey(N1 || EnrolleeMAC || N2) */
  92. addr[0] = wps->nonce_e;
  93. len[0] = WPS_NONCE_LEN;
  94. addr[1] = wps->mac_addr_e;
  95. len[1] = ETH_ALEN;
  96. addr[2] = wps->nonce_r;
  97. len[2] = WPS_NONCE_LEN;
  98. hmac_sha256_vector(dhkey, sizeof(dhkey), 3, addr, len, kdk);
  99. wpa_hexdump_key(MSG_DEBUG, "WPS: KDK", kdk, sizeof(kdk));
  100. wps_kdf(kdk, NULL, 0, "Wi-Fi Easy and Secure Key Derivation",
  101. keys, sizeof(keys));
  102. os_memcpy(wps->authkey, keys, WPS_AUTHKEY_LEN);
  103. os_memcpy(wps->keywrapkey, keys + WPS_AUTHKEY_LEN, WPS_KEYWRAPKEY_LEN);
  104. os_memcpy(wps->emsk, keys + WPS_AUTHKEY_LEN + WPS_KEYWRAPKEY_LEN,
  105. WPS_EMSK_LEN);
  106. wpa_hexdump_key(MSG_DEBUG, "WPS: AuthKey",
  107. wps->authkey, WPS_AUTHKEY_LEN);
  108. wpa_hexdump_key(MSG_DEBUG, "WPS: KeyWrapKey",
  109. wps->keywrapkey, WPS_KEYWRAPKEY_LEN);
  110. wpa_hexdump_key(MSG_DEBUG, "WPS: EMSK", wps->emsk, WPS_EMSK_LEN);
  111. return 0;
  112. }
  113. void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
  114. size_t dev_passwd_len)
  115. {
  116. u8 hash[SHA256_MAC_LEN];
  117. hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, dev_passwd,
  118. (dev_passwd_len + 1) / 2, hash);
  119. os_memcpy(wps->psk1, hash, WPS_PSK_LEN);
  120. hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN,
  121. dev_passwd + (dev_passwd_len + 1) / 2,
  122. dev_passwd_len / 2, hash);
  123. os_memcpy(wps->psk2, hash, WPS_PSK_LEN);
  124. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS: Device Password",
  125. dev_passwd, dev_passwd_len);
  126. wpa_hexdump_key(MSG_DEBUG, "WPS: PSK1", wps->psk1, WPS_PSK_LEN);
  127. wpa_hexdump_key(MSG_DEBUG, "WPS: PSK2", wps->psk2, WPS_PSK_LEN);
  128. }
  129. struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
  130. size_t encr_len)
  131. {
  132. struct wpabuf *decrypted;
  133. const size_t block_size = 16;
  134. size_t i;
  135. u8 pad;
  136. const u8 *pos;
  137. /* AES-128-CBC */
  138. if (encr == NULL || encr_len < 2 * block_size || encr_len % block_size)
  139. {
  140. wpa_printf(MSG_DEBUG, "WPS: No Encrypted Settings received");
  141. return NULL;
  142. }
  143. decrypted = wpabuf_alloc(encr_len - block_size);
  144. if (decrypted == NULL)
  145. return NULL;
  146. wpa_hexdump(MSG_MSGDUMP, "WPS: Encrypted Settings", encr, encr_len);
  147. wpabuf_put_data(decrypted, encr + block_size, encr_len - block_size);
  148. if (aes_128_cbc_decrypt(wps->keywrapkey, encr, wpabuf_mhead(decrypted),
  149. wpabuf_len(decrypted))) {
  150. wpabuf_free(decrypted);
  151. return NULL;
  152. }
  153. wpa_hexdump_buf_key(MSG_MSGDUMP, "WPS: Decrypted Encrypted Settings",
  154. decrypted);
  155. pos = wpabuf_head_u8(decrypted) + wpabuf_len(decrypted) - 1;
  156. pad = *pos;
  157. if (pad > wpabuf_len(decrypted)) {
  158. wpa_printf(MSG_DEBUG, "WPS: Invalid PKCS#5 v2.0 pad value");
  159. wpabuf_free(decrypted);
  160. return NULL;
  161. }
  162. for (i = 0; i < pad; i++) {
  163. if (*pos-- != pad) {
  164. wpa_printf(MSG_DEBUG, "WPS: Invalid PKCS#5 v2.0 pad "
  165. "string");
  166. wpabuf_free(decrypted);
  167. return NULL;
  168. }
  169. }
  170. decrypted->used -= pad;
  171. return decrypted;
  172. }
  173. /**
  174. * wps_pin_checksum - Compute PIN checksum
  175. * @pin: Seven digit PIN (i.e., eight digit PIN without the checksum digit)
  176. * Returns: Checksum digit
  177. */
  178. unsigned int wps_pin_checksum(unsigned int pin)
  179. {
  180. unsigned int accum = 0;
  181. while (pin) {
  182. accum += 3 * (pin % 10);
  183. pin /= 10;
  184. accum += pin % 10;
  185. pin /= 10;
  186. }
  187. return (10 - accum % 10) % 10;
  188. }
  189. /**
  190. * wps_pin_valid - Check whether a PIN has a valid checksum
  191. * @pin: Eight digit PIN (i.e., including the checksum digit)
  192. * Returns: 1 if checksum digit is valid, or 0 if not
  193. */
  194. unsigned int wps_pin_valid(unsigned int pin)
  195. {
  196. return wps_pin_checksum(pin / 10) == (pin % 10);
  197. }
  198. /**
  199. * wps_generate_pin - Generate a random PIN
  200. * Returns: Eight digit PIN (i.e., including the checksum digit)
  201. */
  202. unsigned int wps_generate_pin(void)
  203. {
  204. unsigned int val;
  205. /* Generate seven random digits for the PIN */
  206. if (os_get_random((unsigned char *) &val, sizeof(val)) < 0) {
  207. struct os_time now;
  208. os_get_time(&now);
  209. val = os_random() ^ now.sec ^ now.usec;
  210. }
  211. val %= 10000000;
  212. /* Append checksum digit */
  213. return val * 10 + wps_pin_checksum(val);
  214. }
  215. void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg)
  216. {
  217. union wps_event_data data;
  218. if (wps->event_cb == NULL)
  219. return;
  220. os_memset(&data, 0, sizeof(data));
  221. data.fail.msg = msg;
  222. wps->event_cb(wps->cb_ctx, WPS_EV_FAIL, &data);
  223. }
  224. void wps_success_event(struct wps_context *wps)
  225. {
  226. if (wps->event_cb == NULL)
  227. return;
  228. wps->event_cb(wps->cb_ctx, WPS_EV_SUCCESS, NULL);
  229. }
  230. void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part)
  231. {
  232. union wps_event_data data;
  233. if (wps->event_cb == NULL)
  234. return;
  235. os_memset(&data, 0, sizeof(data));
  236. data.pwd_auth_fail.enrollee = enrollee;
  237. data.pwd_auth_fail.part = part;
  238. wps->event_cb(wps->cb_ctx, WPS_EV_PWD_AUTH_FAIL, &data);
  239. }
  240. void wps_pbc_overlap_event(struct wps_context *wps)
  241. {
  242. if (wps->event_cb == NULL)
  243. return;
  244. wps->event_cb(wps->cb_ctx, WPS_EV_PBC_OVERLAP, NULL);
  245. }
  246. void wps_pbc_timeout_event(struct wps_context *wps)
  247. {
  248. if (wps->event_cb == NULL)
  249. return;
  250. wps->event_cb(wps->cb_ctx, WPS_EV_PBC_TIMEOUT, NULL);
  251. }
  252. #ifdef CONFIG_WPS_OOB
  253. static struct wpabuf * wps_get_oob_cred(struct wps_context *wps)
  254. {
  255. struct wps_data data;
  256. struct wpabuf *plain;
  257. plain = wpabuf_alloc(500);
  258. if (plain == NULL) {
  259. wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
  260. "credential");
  261. return NULL;
  262. }
  263. os_memset(&data, 0, sizeof(data));
  264. data.wps = wps;
  265. data.auth_type = wps->auth_types;
  266. data.encr_type = wps->encr_types;
  267. if (wps_build_version(plain) ||
  268. wps_build_cred(&data, plain) ||
  269. wps_build_wfa_ext(plain, 0, NULL, 0)) {
  270. wpabuf_free(plain);
  271. return NULL;
  272. }
  273. return plain;
  274. }
  275. static struct wpabuf * wps_get_oob_dev_pwd(struct wps_context *wps)
  276. {
  277. struct wpabuf *data;
  278. data = wpabuf_alloc(9 + WPS_OOB_DEVICE_PASSWORD_ATTR_LEN);
  279. if (data == NULL) {
  280. wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
  281. "device password attribute");
  282. return NULL;
  283. }
  284. wpabuf_free(wps->oob_conf.dev_password);
  285. wps->oob_conf.dev_password =
  286. wpabuf_alloc(WPS_OOB_DEVICE_PASSWORD_LEN * 2 + 1);
  287. if (wps->oob_conf.dev_password == NULL) {
  288. wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
  289. "device password");
  290. wpabuf_free(data);
  291. return NULL;
  292. }
  293. if (wps_build_version(data) ||
  294. wps_build_oob_dev_password(data, wps) ||
  295. wps_build_wfa_ext(data, 0, NULL, 0)) {
  296. wpa_printf(MSG_ERROR, "WPS: Build OOB device password "
  297. "attribute error");
  298. wpabuf_free(data);
  299. return NULL;
  300. }
  301. return data;
  302. }
  303. static int wps_parse_oob_dev_pwd(struct wps_context *wps,
  304. struct wpabuf *data)
  305. {
  306. struct oob_conf_data *oob_conf = &wps->oob_conf;
  307. struct wps_parse_attr attr;
  308. const u8 *pos;
  309. if (wps_parse_msg(data, &attr) < 0 ||
  310. attr.oob_dev_password == NULL) {
  311. wpa_printf(MSG_ERROR, "WPS: OOB device password not found");
  312. return -1;
  313. }
  314. pos = attr.oob_dev_password;
  315. oob_conf->pubkey_hash =
  316. wpabuf_alloc_copy(pos, WPS_OOB_PUBKEY_HASH_LEN);
  317. if (oob_conf->pubkey_hash == NULL) {
  318. wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
  319. "public key hash");
  320. return -1;
  321. }
  322. pos += WPS_OOB_PUBKEY_HASH_LEN;
  323. wps->oob_dev_pw_id = WPA_GET_BE16(pos);
  324. pos += sizeof(wps->oob_dev_pw_id);
  325. oob_conf->dev_password =
  326. wpabuf_alloc(WPS_OOB_DEVICE_PASSWORD_LEN * 2 + 1);
  327. if (oob_conf->dev_password == NULL) {
  328. wpa_printf(MSG_ERROR, "WPS: Failed to allocate memory for OOB "
  329. "device password");
  330. return -1;
  331. }
  332. wpa_snprintf_hex_uppercase(wpabuf_put(oob_conf->dev_password,
  333. wpabuf_size(oob_conf->dev_password)),
  334. wpabuf_size(oob_conf->dev_password), pos,
  335. WPS_OOB_DEVICE_PASSWORD_LEN);
  336. return 0;
  337. }
  338. static int wps_parse_oob_cred(struct wps_context *wps, struct wpabuf *data)
  339. {
  340. struct wpabuf msg;
  341. struct wps_parse_attr attr;
  342. size_t i;
  343. if (wps_parse_msg(data, &attr) < 0 || attr.num_cred <= 0) {
  344. wpa_printf(MSG_ERROR, "WPS: OOB credential not found");
  345. return -1;
  346. }
  347. for (i = 0; i < attr.num_cred; i++) {
  348. struct wps_credential local_cred;
  349. struct wps_parse_attr cattr;
  350. os_memset(&local_cred, 0, sizeof(local_cred));
  351. wpabuf_set(&msg, attr.cred[i], attr.cred_len[i]);
  352. if (wps_parse_msg(&msg, &cattr) < 0 ||
  353. wps_process_cred(&cattr, &local_cred)) {
  354. wpa_printf(MSG_ERROR, "WPS: Failed to parse OOB "
  355. "credential");
  356. return -1;
  357. }
  358. wps->cred_cb(wps->cb_ctx, &local_cred);
  359. }
  360. return 0;
  361. }
  362. int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
  363. int registrar)
  364. {
  365. struct wpabuf *data;
  366. int ret, write_f, oob_method = wps->oob_conf.oob_method;
  367. void *oob_priv;
  368. write_f = oob_method == OOB_METHOD_DEV_PWD_E ? !registrar : registrar;
  369. oob_priv = oob_dev->init_func(wps, oob_dev, registrar);
  370. if (oob_priv == NULL) {
  371. wpa_printf(MSG_ERROR, "WPS: Failed to initialize OOB device");
  372. return -1;
  373. }
  374. if (write_f) {
  375. if (oob_method == OOB_METHOD_CRED)
  376. data = wps_get_oob_cred(wps);
  377. else
  378. data = wps_get_oob_dev_pwd(wps);
  379. ret = 0;
  380. if (data == NULL || oob_dev->write_func(oob_priv, data) < 0)
  381. ret = -1;
  382. } else {
  383. data = oob_dev->read_func(oob_priv);
  384. if (data == NULL)
  385. ret = -1;
  386. else {
  387. if (oob_method == OOB_METHOD_CRED)
  388. ret = wps_parse_oob_cred(wps, data);
  389. else
  390. ret = wps_parse_oob_dev_pwd(wps, data);
  391. }
  392. }
  393. wpabuf_free(data);
  394. oob_dev->deinit_func(oob_priv);
  395. if (ret < 0) {
  396. wpa_printf(MSG_ERROR, "WPS: Failed to process OOB data");
  397. return -1;
  398. }
  399. return 0;
  400. }
  401. struct oob_device_data * wps_get_oob_device(char *device_type)
  402. {
  403. #ifdef CONFIG_WPS_UFD
  404. if (os_strstr(device_type, "ufd") != NULL)
  405. return &oob_ufd_device_data;
  406. #endif /* CONFIG_WPS_UFD */
  407. #ifdef CONFIG_WPS_NFC
  408. if (os_strstr(device_type, "nfc") != NULL)
  409. return &oob_nfc_device_data;
  410. #endif /* CONFIG_WPS_NFC */
  411. return NULL;
  412. }
  413. #ifdef CONFIG_WPS_NFC
  414. struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name)
  415. {
  416. if (device_name == NULL)
  417. return NULL;
  418. #ifdef CONFIG_WPS_NFC_PN531
  419. if (os_strstr(device_name, "pn531") != NULL)
  420. return &oob_nfc_pn531_device_data;
  421. #endif /* CONFIG_WPS_NFC_PN531 */
  422. return NULL;
  423. }
  424. #endif /* CONFIG_WPS_NFC */
  425. int wps_get_oob_method(char *method)
  426. {
  427. if (os_strstr(method, "pin-e") != NULL)
  428. return OOB_METHOD_DEV_PWD_E;
  429. if (os_strstr(method, "pin-r") != NULL)
  430. return OOB_METHOD_DEV_PWD_R;
  431. if (os_strstr(method, "cred") != NULL)
  432. return OOB_METHOD_CRED;
  433. return OOB_METHOD_UNKNOWN;
  434. }
  435. #endif /* CONFIG_WPS_OOB */
  436. int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN])
  437. {
  438. const char *pos;
  439. /* <categ>-<OUI>-<subcateg> */
  440. WPA_PUT_BE16(dev_type, atoi(str));
  441. pos = os_strchr(str, '-');
  442. if (pos == NULL)
  443. return -1;
  444. pos++;
  445. if (hexstr2bin(pos, &dev_type[2], 4))
  446. return -1;
  447. pos = os_strchr(pos, '-');
  448. if (pos == NULL)
  449. return -1;
  450. pos++;
  451. WPA_PUT_BE16(&dev_type[6], atoi(pos));
  452. return 0;
  453. }
  454. char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
  455. size_t buf_len)
  456. {
  457. int ret;
  458. ret = os_snprintf(buf, buf_len, "%u-%08X-%u",
  459. WPA_GET_BE16(dev_type), WPA_GET_BE32(&dev_type[2]),
  460. WPA_GET_BE16(&dev_type[6]));
  461. if (ret < 0 || (unsigned int) ret >= buf_len)
  462. return NULL;
  463. return buf;
  464. }
  465. void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid)
  466. {
  467. const u8 *addr[2];
  468. size_t len[2];
  469. u8 hash[SHA1_MAC_LEN];
  470. u8 nsid[16] = {
  471. 0x52, 0x64, 0x80, 0xf8,
  472. 0xc9, 0x9b,
  473. 0x4b, 0xe5,
  474. 0xa6, 0x55,
  475. 0x58, 0xed, 0x5f, 0x5d, 0x60, 0x84
  476. };
  477. addr[0] = nsid;
  478. len[0] = sizeof(nsid);
  479. addr[1] = mac_addr;
  480. len[1] = 6;
  481. sha1_vector(2, addr, len, hash);
  482. os_memcpy(uuid, hash, 16);
  483. /* Version: 5 = named-based version using SHA-1 */
  484. uuid[6] = (5 << 4) | (uuid[6] & 0x0f);
  485. /* Variant specified in RFC 4122 */
  486. uuid[8] = 0x80 | (uuid[8] & 0x3f);
  487. }
  488. u16 wps_config_methods_str2bin(const char *str)
  489. {
  490. u16 methods = 0;
  491. if (str == NULL) {
  492. /* Default to enabling methods based on build configuration */
  493. methods |= WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD;
  494. #ifdef CONFIG_WPS2
  495. methods |= WPS_CONFIG_VIRT_DISPLAY;
  496. #endif /* CONFIG_WPS2 */
  497. #ifdef CONFIG_WPS_UFD
  498. methods |= WPS_CONFIG_USBA;
  499. #endif /* CONFIG_WPS_UFD */
  500. #ifdef CONFIG_WPS_NFC
  501. methods |= WPS_CONFIG_NFC_INTERFACE;
  502. #endif /* CONFIG_WPS_NFC */
  503. } else {
  504. if (os_strstr(str, "usba"))
  505. methods |= WPS_CONFIG_USBA;
  506. if (os_strstr(str, "ethernet"))
  507. methods |= WPS_CONFIG_ETHERNET;
  508. if (os_strstr(str, "label"))
  509. methods |= WPS_CONFIG_LABEL;
  510. if (os_strstr(str, "display"))
  511. methods |= WPS_CONFIG_DISPLAY;
  512. if (os_strstr(str, "ext_nfc_token"))
  513. methods |= WPS_CONFIG_EXT_NFC_TOKEN;
  514. if (os_strstr(str, "int_nfc_token"))
  515. methods |= WPS_CONFIG_INT_NFC_TOKEN;
  516. if (os_strstr(str, "nfc_interface"))
  517. methods |= WPS_CONFIG_NFC_INTERFACE;
  518. if (os_strstr(str, "push_button"))
  519. methods |= WPS_CONFIG_PUSHBUTTON;
  520. if (os_strstr(str, "keypad"))
  521. methods |= WPS_CONFIG_KEYPAD;
  522. #ifdef CONFIG_WPS2
  523. if (os_strstr(str, "virtual_display"))
  524. methods |= WPS_CONFIG_VIRT_DISPLAY;
  525. if (os_strstr(str, "physical_display"))
  526. methods |= WPS_CONFIG_PHY_DISPLAY;
  527. if (os_strstr(str, "virtual_push_button"))
  528. methods |= WPS_CONFIG_VIRT_PUSHBUTTON;
  529. if (os_strstr(str, "physical_push_button"))
  530. methods |= WPS_CONFIG_PHY_PUSHBUTTON;
  531. #endif /* CONFIG_WPS2 */
  532. }
  533. return methods;
  534. }