interworking.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. /*
  2. * Interworking (IEEE 802.11u)
  3. * Copyright (c) 2011, Qualcomm Atheros
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "includes.h"
  9. #include "common.h"
  10. #include "common/ieee802_11_defs.h"
  11. #include "common/gas.h"
  12. #include "common/wpa_ctrl.h"
  13. #include "drivers/driver.h"
  14. #include "eap_common/eap_defs.h"
  15. #include "eap_peer/eap_methods.h"
  16. #include "wpa_supplicant_i.h"
  17. #include "config.h"
  18. #include "bss.h"
  19. #include "scan.h"
  20. #include "notify.h"
  21. #include "gas_query.h"
  22. #include "interworking.h"
  23. #if defined(EAP_SIM) | defined(EAP_SIM_DYNAMIC)
  24. #define INTERWORKING_3GPP
  25. #else
  26. #if defined(EAP_AKA) | defined(EAP_AKA_DYNAMIC)
  27. #define INTERWORKING_3GPP
  28. #else
  29. #if defined(EAP_AKA_PRIME) | defined(EAP_AKA_PRIME_DYNAMIC)
  30. #define INTERWORKING_3GPP
  31. #endif
  32. #endif
  33. #endif
  34. static void interworking_next_anqp_fetch(struct wpa_supplicant *wpa_s);
  35. static struct wpabuf * anqp_build_req(u16 info_ids[], size_t num_ids,
  36. struct wpabuf *extra)
  37. {
  38. struct wpabuf *buf;
  39. size_t i;
  40. u8 *len_pos;
  41. buf = gas_anqp_build_initial_req(0, 4 + num_ids * 2 +
  42. (extra ? wpabuf_len(extra) : 0));
  43. if (buf == NULL)
  44. return NULL;
  45. len_pos = gas_anqp_add_element(buf, ANQP_QUERY_LIST);
  46. for (i = 0; i < num_ids; i++)
  47. wpabuf_put_le16(buf, info_ids[i]);
  48. gas_anqp_set_element_len(buf, len_pos);
  49. if (extra)
  50. wpabuf_put_buf(buf, extra);
  51. gas_anqp_set_len(buf);
  52. return buf;
  53. }
  54. static void interworking_anqp_resp_cb(void *ctx, const u8 *dst,
  55. u8 dialog_token,
  56. enum gas_query_result result,
  57. const struct wpabuf *adv_proto,
  58. const struct wpabuf *resp,
  59. u16 status_code)
  60. {
  61. struct wpa_supplicant *wpa_s = ctx;
  62. anqp_resp_cb(wpa_s, dst, dialog_token, result, adv_proto, resp,
  63. status_code);
  64. interworking_next_anqp_fetch(wpa_s);
  65. }
  66. static int interworking_anqp_send_req(struct wpa_supplicant *wpa_s,
  67. struct wpa_bss *bss)
  68. {
  69. struct wpabuf *buf;
  70. int ret = 0;
  71. int res;
  72. u16 info_ids[] = {
  73. ANQP_CAPABILITY_LIST,
  74. ANQP_VENUE_NAME,
  75. ANQP_NETWORK_AUTH_TYPE,
  76. ANQP_ROAMING_CONSORTIUM,
  77. ANQP_IP_ADDR_TYPE_AVAILABILITY,
  78. ANQP_NAI_REALM,
  79. ANQP_3GPP_CELLULAR_NETWORK,
  80. ANQP_DOMAIN_NAME
  81. };
  82. struct wpabuf *extra = NULL;
  83. wpa_printf(MSG_DEBUG, "Interworking: ANQP Query Request to " MACSTR,
  84. MAC2STR(bss->bssid));
  85. buf = anqp_build_req(info_ids, sizeof(info_ids) / sizeof(info_ids[0]),
  86. extra);
  87. wpabuf_free(extra);
  88. if (buf == NULL)
  89. return -1;
  90. res = gas_query_req(wpa_s->gas, bss->bssid, bss->freq, buf,
  91. interworking_anqp_resp_cb, wpa_s);
  92. if (res < 0) {
  93. wpa_printf(MSG_DEBUG, "ANQP: Failed to send Query Request");
  94. ret = -1;
  95. } else
  96. wpa_printf(MSG_DEBUG, "ANQP: Query started with dialog token "
  97. "%u", res);
  98. wpabuf_free(buf);
  99. return ret;
  100. }
  101. struct nai_realm_eap {
  102. u8 method;
  103. u8 inner_method;
  104. enum nai_realm_eap_auth_inner_non_eap inner_non_eap;
  105. u8 cred_type;
  106. u8 tunneled_cred_type;
  107. };
  108. struct nai_realm {
  109. u8 encoding;
  110. char *realm;
  111. u8 eap_count;
  112. struct nai_realm_eap *eap;
  113. };
  114. static void nai_realm_free(struct nai_realm *realms, u16 count)
  115. {
  116. u16 i;
  117. if (realms == NULL)
  118. return;
  119. for (i = 0; i < count; i++) {
  120. os_free(realms[i].eap);
  121. os_free(realms[i].realm);
  122. }
  123. os_free(realms);
  124. }
  125. static const u8 * nai_realm_parse_eap(struct nai_realm_eap *e, const u8 *pos,
  126. const u8 *end)
  127. {
  128. u8 elen, auth_count, a;
  129. const u8 *e_end;
  130. if (pos + 3 > end) {
  131. wpa_printf(MSG_DEBUG, "No room for EAP Method fixed fields");
  132. return NULL;
  133. }
  134. elen = *pos++;
  135. if (pos + elen > end || elen < 2) {
  136. wpa_printf(MSG_DEBUG, "No room for EAP Method subfield");
  137. return NULL;
  138. }
  139. e_end = pos + elen;
  140. e->method = *pos++;
  141. auth_count = *pos++;
  142. wpa_printf(MSG_DEBUG, "EAP Method: len=%u method=%u auth_count=%u",
  143. elen, e->method, auth_count);
  144. for (a = 0; a < auth_count; a++) {
  145. u8 id, len;
  146. if (pos + 2 > end || pos + 2 + pos[1] > end) {
  147. wpa_printf(MSG_DEBUG, "No room for Authentication "
  148. "Parameter subfield");
  149. return NULL;
  150. }
  151. id = *pos++;
  152. len = *pos++;
  153. switch (id) {
  154. case NAI_REALM_EAP_AUTH_NON_EAP_INNER_AUTH:
  155. if (len < 1)
  156. break;
  157. e->inner_non_eap = *pos;
  158. if (e->method != EAP_TYPE_TTLS)
  159. break;
  160. switch (*pos) {
  161. case NAI_REALM_INNER_NON_EAP_PAP:
  162. wpa_printf(MSG_DEBUG, "EAP-TTLS/PAP");
  163. break;
  164. case NAI_REALM_INNER_NON_EAP_CHAP:
  165. wpa_printf(MSG_DEBUG, "EAP-TTLS/CHAP");
  166. break;
  167. case NAI_REALM_INNER_NON_EAP_MSCHAP:
  168. wpa_printf(MSG_DEBUG, "EAP-TTLS/MSCHAP");
  169. break;
  170. case NAI_REALM_INNER_NON_EAP_MSCHAPV2:
  171. wpa_printf(MSG_DEBUG, "EAP-TTLS/MSCHAPV2");
  172. break;
  173. }
  174. break;
  175. case NAI_REALM_EAP_AUTH_INNER_AUTH_EAP_METHOD:
  176. if (len < 1)
  177. break;
  178. e->inner_method = *pos;
  179. wpa_printf(MSG_DEBUG, "Inner EAP method: %u",
  180. e->inner_method);
  181. break;
  182. case NAI_REALM_EAP_AUTH_CRED_TYPE:
  183. if (len < 1)
  184. break;
  185. e->cred_type = *pos;
  186. wpa_printf(MSG_DEBUG, "Credential Type: %u",
  187. e->cred_type);
  188. break;
  189. case NAI_REALM_EAP_AUTH_TUNNELED_CRED_TYPE:
  190. if (len < 1)
  191. break;
  192. e->tunneled_cred_type = *pos;
  193. wpa_printf(MSG_DEBUG, "Tunneled EAP Method Credential "
  194. "Type: %u", e->tunneled_cred_type);
  195. break;
  196. default:
  197. wpa_printf(MSG_DEBUG, "Unsupported Authentication "
  198. "Parameter: id=%u len=%u", id, len);
  199. wpa_hexdump(MSG_DEBUG, "Authentication Parameter "
  200. "Value", pos, len);
  201. break;
  202. }
  203. pos += len;
  204. }
  205. return e_end;
  206. }
  207. static const u8 * nai_realm_parse_realm(struct nai_realm *r, const u8 *pos,
  208. const u8 *end)
  209. {
  210. u16 len;
  211. const u8 *f_end;
  212. u8 realm_len, e;
  213. if (end - pos < 4) {
  214. wpa_printf(MSG_DEBUG, "No room for NAI Realm Data "
  215. "fixed fields");
  216. return NULL;
  217. }
  218. len = WPA_GET_LE16(pos); /* NAI Realm Data field Length */
  219. pos += 2;
  220. if (pos + len > end || len < 3) {
  221. wpa_printf(MSG_DEBUG, "No room for NAI Realm Data "
  222. "(len=%u; left=%u)",
  223. len, (unsigned int) (end - pos));
  224. return NULL;
  225. }
  226. f_end = pos + len;
  227. r->encoding = *pos++;
  228. realm_len = *pos++;
  229. if (pos + realm_len > f_end) {
  230. wpa_printf(MSG_DEBUG, "No room for NAI Realm "
  231. "(len=%u; left=%u)",
  232. realm_len, (unsigned int) (f_end - pos));
  233. return NULL;
  234. }
  235. wpa_hexdump_ascii(MSG_DEBUG, "NAI Realm", pos, realm_len);
  236. r->realm = os_malloc(realm_len + 1);
  237. if (r->realm == NULL)
  238. return NULL;
  239. os_memcpy(r->realm, pos, realm_len);
  240. r->realm[realm_len] = '\0';
  241. pos += realm_len;
  242. if (pos + 1 > f_end) {
  243. wpa_printf(MSG_DEBUG, "No room for EAP Method Count");
  244. return NULL;
  245. }
  246. r->eap_count = *pos++;
  247. wpa_printf(MSG_DEBUG, "EAP Count: %u", r->eap_count);
  248. if (pos + r->eap_count * 3 > f_end) {
  249. wpa_printf(MSG_DEBUG, "No room for EAP Methods");
  250. return NULL;
  251. }
  252. r->eap = os_zalloc(r->eap_count * sizeof(struct nai_realm_eap));
  253. if (r->eap == NULL)
  254. return NULL;
  255. for (e = 0; e < r->eap_count; e++) {
  256. pos = nai_realm_parse_eap(&r->eap[e], pos, f_end);
  257. if (pos == NULL)
  258. return NULL;
  259. }
  260. return f_end;
  261. }
  262. static struct nai_realm * nai_realm_parse(struct wpabuf *anqp, u16 *count)
  263. {
  264. struct nai_realm *realm;
  265. const u8 *pos, *end;
  266. u16 i, num;
  267. if (anqp == NULL || wpabuf_len(anqp) < 2)
  268. return NULL;
  269. pos = wpabuf_head_u8(anqp);
  270. end = pos + wpabuf_len(anqp);
  271. num = WPA_GET_LE16(pos);
  272. wpa_printf(MSG_DEBUG, "NAI Realm Count: %u", num);
  273. pos += 2;
  274. if (num * 5 > end - pos) {
  275. wpa_printf(MSG_DEBUG, "Invalid NAI Realm Count %u - not "
  276. "enough data (%u octets) for that many realms",
  277. num, (unsigned int) (end - pos));
  278. return NULL;
  279. }
  280. realm = os_zalloc(num * sizeof(struct nai_realm));
  281. if (realm == NULL)
  282. return NULL;
  283. for (i = 0; i < num; i++) {
  284. pos = nai_realm_parse_realm(&realm[i], pos, end);
  285. if (pos == NULL) {
  286. nai_realm_free(realm, num);
  287. return NULL;
  288. }
  289. }
  290. *count = num;
  291. return realm;
  292. }
  293. static int nai_realm_match(struct nai_realm *realm, const char *home_realm)
  294. {
  295. char *tmp, *pos, *end;
  296. int match = 0;
  297. if (realm->realm == NULL || home_realm == NULL)
  298. return 0;
  299. if (os_strchr(realm->realm, ';') == NULL)
  300. return os_strcasecmp(realm->realm, home_realm) == 0;
  301. tmp = os_strdup(realm->realm);
  302. if (tmp == NULL)
  303. return 0;
  304. pos = tmp;
  305. while (*pos) {
  306. end = os_strchr(pos, ';');
  307. if (end)
  308. *end = '\0';
  309. if (os_strcasecmp(pos, home_realm) == 0) {
  310. match = 1;
  311. break;
  312. }
  313. if (end == NULL)
  314. break;
  315. pos = end + 1;
  316. }
  317. os_free(tmp);
  318. return match;
  319. }
  320. static int nai_realm_cred_username(struct nai_realm_eap *eap)
  321. {
  322. if (eap_get_name(EAP_VENDOR_IETF, eap->method) == NULL)
  323. return 0; /* method not supported */
  324. if (eap->method != EAP_TYPE_TTLS && eap->method != EAP_TYPE_PEAP) {
  325. /* Only tunneled methods with username/password supported */
  326. return 0;
  327. }
  328. if (eap->method == EAP_TYPE_PEAP &&
  329. eap_get_name(EAP_VENDOR_IETF, eap->inner_method) == NULL)
  330. return 0;
  331. if (eap->method == EAP_TYPE_TTLS) {
  332. if (eap->inner_method == 0 && eap->inner_non_eap == 0)
  333. return 0;
  334. if (eap->inner_method &&
  335. eap_get_name(EAP_VENDOR_IETF, eap->inner_method) == NULL)
  336. return 0;
  337. if (eap->inner_non_eap &&
  338. eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_PAP &&
  339. eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_CHAP &&
  340. eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_MSCHAP &&
  341. eap->inner_non_eap != NAI_REALM_INNER_NON_EAP_MSCHAPV2)
  342. return 0;
  343. }
  344. if (eap->inner_method &&
  345. eap->inner_method != EAP_TYPE_GTC &&
  346. eap->inner_method != EAP_TYPE_MSCHAPV2)
  347. return 0;
  348. return 1;
  349. }
  350. static struct nai_realm_eap * nai_realm_find_eap(struct wpa_cred *cred,
  351. struct nai_realm *realm)
  352. {
  353. u8 e;
  354. if (cred == NULL ||
  355. cred->username == NULL ||
  356. cred->username[0] == '\0' ||
  357. cred->password == NULL ||
  358. cred->password[0] == '\0')
  359. return NULL;
  360. for (e = 0; e < realm->eap_count; e++) {
  361. struct nai_realm_eap *eap = &realm->eap[e];
  362. if (nai_realm_cred_username(eap))
  363. return eap;
  364. }
  365. return NULL;
  366. }
  367. #ifdef INTERWORKING_3GPP
  368. static int plmn_id_match(struct wpabuf *anqp, const char *imsi)
  369. {
  370. const char *sep;
  371. u8 plmn[3];
  372. const u8 *pos, *end;
  373. u8 udhl;
  374. sep = os_strchr(imsi, '-');
  375. if (sep == NULL || (sep - imsi != 5 && sep - imsi != 6))
  376. return 0;
  377. /* See Annex A of 3GPP TS 24.234 v8.1.0 for description */
  378. plmn[0] = (imsi[0] - '0') | ((imsi[1] - '0') << 4);
  379. plmn[1] = imsi[2] - '0';
  380. if (sep - imsi == 6)
  381. plmn[1] |= (imsi[5] - '0') << 4;
  382. else
  383. plmn[1] |= 0xf0;
  384. plmn[2] = (imsi[3] - '0') | ((imsi[4] - '0') << 4);
  385. if (anqp == NULL)
  386. return 0;
  387. pos = wpabuf_head_u8(anqp);
  388. end = pos + wpabuf_len(anqp);
  389. if (pos + 2 > end)
  390. return 0;
  391. if (*pos != 0) {
  392. wpa_printf(MSG_DEBUG, "Unsupported GUD version 0x%x", *pos);
  393. return 0;
  394. }
  395. pos++;
  396. udhl = *pos++;
  397. if (pos + udhl > end) {
  398. wpa_printf(MSG_DEBUG, "Invalid UDHL");
  399. return 0;
  400. }
  401. end = pos + udhl;
  402. while (pos + 2 <= end) {
  403. u8 iei, len;
  404. const u8 *l_end;
  405. iei = *pos++;
  406. len = *pos++ & 0x7f;
  407. if (pos + len > end)
  408. break;
  409. l_end = pos + len;
  410. if (iei == 0 && len > 0) {
  411. /* PLMN List */
  412. u8 num, i;
  413. num = *pos++;
  414. for (i = 0; i < num; i++) {
  415. if (pos + 3 > end)
  416. break;
  417. if (os_memcmp(pos, plmn, 3) == 0)
  418. return 1; /* Found matching PLMN */
  419. }
  420. }
  421. pos = l_end;
  422. }
  423. return 0;
  424. }
  425. static int build_root_nai(char *nai, const char *imsi, char prefix)
  426. {
  427. const char *sep, *msin;
  428. char *end, *pos;
  429. size_t msin_len, plmn_len;
  430. /*
  431. * TS 23.003, Clause 14 (3GPP to WLAN Interworking)
  432. * Root NAI:
  433. * <aka:0|sim:1><IMSI>@wlan.mnc<MNC>.mcc<MCC>.3gppnetwork.org
  434. * <MNC> is zero-padded to three digits in case two-digit MNC is used
  435. */
  436. if (imsi == NULL || os_strlen(imsi) > 16) {
  437. wpa_printf(MSG_DEBUG, "No valid IMSI available");
  438. return -1;
  439. }
  440. sep = os_strchr(imsi, '-');
  441. if (sep == NULL)
  442. return -1;
  443. plmn_len = sep - imsi;
  444. if (plmn_len != 5 && plmn_len != 6)
  445. return -1;
  446. msin = sep + 1;
  447. msin_len = os_strlen(msin);
  448. pos = nai;
  449. end = pos + sizeof(nai);
  450. if (prefix)
  451. *pos++ = prefix;
  452. os_memcpy(pos, imsi, plmn_len);
  453. pos += plmn_len;
  454. os_memcpy(pos, msin, msin_len);
  455. pos += msin_len;
  456. pos += os_snprintf(pos, end - pos, "@wlan.mnc");
  457. if (plmn_len == 5) {
  458. *pos++ = '0';
  459. *pos++ = imsi[3];
  460. *pos++ = imsi[4];
  461. } else {
  462. *pos++ = imsi[3];
  463. *pos++ = imsi[4];
  464. *pos++ = imsi[5];
  465. }
  466. pos += os_snprintf(pos, end - pos, ".mcc%c%c%c.3gppnetwork.org",
  467. imsi[0], imsi[1], imsi[2]);
  468. return 0;
  469. }
  470. static int set_root_nai(struct wpa_ssid *ssid, const char *imsi, char prefix)
  471. {
  472. char nai[100];
  473. if (build_root_nai(nai, imsi, prefix) < 0)
  474. return -1;
  475. return wpa_config_set_quoted(ssid, "identity", nai);
  476. }
  477. #endif /* INTERWORKING_3GPP */
  478. static int interworking_connect_3gpp(struct wpa_supplicant *wpa_s,
  479. struct wpa_bss *bss)
  480. {
  481. #ifdef INTERWORKING_3GPP
  482. struct wpa_cred *cred;
  483. struct wpa_ssid *ssid;
  484. const u8 *ie;
  485. if (bss->anqp_3gpp == NULL)
  486. return -1;
  487. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  488. if (cred->imsi == NULL || !cred->imsi[0] ||
  489. cred->milenage == NULL || !cred->milenage[0])
  490. continue;
  491. if (plmn_id_match(bss->anqp_3gpp, cred->imsi))
  492. break;
  493. }
  494. if (cred == NULL)
  495. return -1;
  496. ie = wpa_bss_get_ie(bss, WLAN_EID_SSID);
  497. if (ie == NULL)
  498. return -1;
  499. wpa_printf(MSG_DEBUG, "Interworking: Connect with " MACSTR " (3GPP)",
  500. MAC2STR(bss->bssid));
  501. ssid = wpa_config_add_network(wpa_s->conf);
  502. if (ssid == NULL)
  503. return -1;
  504. wpas_notify_network_added(wpa_s, ssid);
  505. wpa_config_set_network_defaults(ssid);
  506. ssid->temporary = 1;
  507. ssid->ssid = os_zalloc(ie[1] + 1);
  508. if (ssid->ssid == NULL)
  509. goto fail;
  510. os_memcpy(ssid->ssid, ie + 2, ie[1]);
  511. ssid->ssid_len = ie[1];
  512. /* TODO: figure out whether to use EAP-SIM, EAP-AKA, or EAP-AKA' */
  513. if (wpa_config_set(ssid, "eap", "SIM", 0) < 0) {
  514. wpa_printf(MSG_DEBUG, "EAP-SIM not supported");
  515. goto fail;
  516. }
  517. if (set_root_nai(ssid, cred->imsi, '1') < 0) {
  518. wpa_printf(MSG_DEBUG, "Failed to set Root NAI");
  519. goto fail;
  520. }
  521. if (cred->milenage && cred->milenage[0]) {
  522. if (wpa_config_set_quoted(ssid, "password",
  523. cred->milenage) < 0)
  524. goto fail;
  525. } else {
  526. /* TODO: PIN */
  527. if (wpa_config_set_quoted(ssid, "pcsc", "") < 0)
  528. goto fail;
  529. }
  530. if (cred->password && cred->password[0] &&
  531. wpa_config_set_quoted(ssid, "password", cred->password) < 0)
  532. goto fail;
  533. wpa_s->disconnected = 0;
  534. wpa_s->reassociate = 1;
  535. wpa_supplicant_req_scan(wpa_s, 0, 0);
  536. return 0;
  537. fail:
  538. wpas_notify_network_removed(wpa_s, ssid);
  539. wpa_config_remove_network(wpa_s->conf, ssid->id);
  540. #endif /* INTERWORKING_3GPP */
  541. return -1;
  542. }
  543. int interworking_connect(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
  544. {
  545. struct wpa_cred *cred;
  546. struct wpa_ssid *ssid;
  547. struct nai_realm *realm;
  548. struct nai_realm_eap *eap = NULL;
  549. u16 count, i;
  550. char buf[100];
  551. const u8 *ie;
  552. if (wpa_s->conf->cred == NULL || bss == NULL)
  553. return -1;
  554. ie = wpa_bss_get_ie(bss, WLAN_EID_SSID);
  555. if (ie == NULL || ie[1] == 0) {
  556. wpa_printf(MSG_DEBUG, "Interworking: No SSID known for "
  557. MACSTR, MAC2STR(bss->bssid));
  558. return -1;
  559. }
  560. realm = nai_realm_parse(bss->anqp_nai_realm, &count);
  561. if (realm == NULL) {
  562. wpa_printf(MSG_DEBUG, "Interworking: Could not parse NAI "
  563. "Realm list from " MACSTR, MAC2STR(bss->bssid));
  564. count = 0;
  565. }
  566. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  567. for (i = 0; i < count; i++) {
  568. if (!nai_realm_match(&realm[i], cred->realm))
  569. continue;
  570. eap = nai_realm_find_eap(cred, &realm[i]);
  571. if (eap)
  572. break;
  573. }
  574. if (eap)
  575. break;
  576. }
  577. if (!eap) {
  578. if (interworking_connect_3gpp(wpa_s, bss) == 0) {
  579. if (realm)
  580. nai_realm_free(realm, count);
  581. return 0;
  582. }
  583. wpa_printf(MSG_DEBUG, "Interworking: No matching credentials "
  584. "and EAP method found for " MACSTR,
  585. MAC2STR(bss->bssid));
  586. nai_realm_free(realm, count);
  587. return -1;
  588. }
  589. wpa_printf(MSG_DEBUG, "Interworking: Connect with " MACSTR,
  590. MAC2STR(bss->bssid));
  591. ssid = wpa_config_add_network(wpa_s->conf);
  592. if (ssid == NULL) {
  593. nai_realm_free(realm, count);
  594. return -1;
  595. }
  596. wpas_notify_network_added(wpa_s, ssid);
  597. wpa_config_set_network_defaults(ssid);
  598. ssid->temporary = 1;
  599. ssid->ssid = os_zalloc(ie[1] + 1);
  600. if (ssid->ssid == NULL)
  601. goto fail;
  602. os_memcpy(ssid->ssid, ie + 2, ie[1]);
  603. ssid->ssid_len = ie[1];
  604. if (wpa_config_set(ssid, "eap", eap_get_name(EAP_VENDOR_IETF,
  605. eap->method), 0) < 0)
  606. goto fail;
  607. if (eap->method == EAP_TYPE_TTLS &&
  608. cred->username && cred->username[0]) {
  609. const char *pos;
  610. char *anon;
  611. /* Use anonymous NAI in Phase 1 */
  612. pos = os_strchr(cred->username, '@');
  613. if (pos) {
  614. size_t buflen = 9 + os_strlen(pos) + 1;
  615. anon = os_malloc(buflen);
  616. if (anon == NULL)
  617. goto fail;
  618. os_snprintf(anon, buflen, "anonymous%s", pos);
  619. } else {
  620. anon = os_strdup("anonymous");
  621. if (anon == NULL)
  622. goto fail;
  623. }
  624. if (wpa_config_set_quoted(ssid, "anonymous_identity", anon) <
  625. 0) {
  626. os_free(anon);
  627. goto fail;
  628. }
  629. os_free(anon);
  630. }
  631. if (cred->username && cred->username[0] &&
  632. wpa_config_set_quoted(ssid, "identity", cred->username) < 0)
  633. goto fail;
  634. if (cred->password && cred->password[0] &&
  635. wpa_config_set_quoted(ssid, "password", cred->password) < 0)
  636. goto fail;
  637. switch (eap->method) {
  638. case EAP_TYPE_TTLS:
  639. if (eap->inner_method) {
  640. os_snprintf(buf, sizeof(buf), "\"autheap=%s\"",
  641. eap_get_name(EAP_VENDOR_IETF,
  642. eap->inner_method));
  643. if (wpa_config_set(ssid, "phase2", buf, 0) < 0)
  644. goto fail;
  645. break;
  646. }
  647. switch (eap->inner_non_eap) {
  648. case NAI_REALM_INNER_NON_EAP_PAP:
  649. if (wpa_config_set(ssid, "phase2", "\"auth=PAP\"", 0) <
  650. 0)
  651. goto fail;
  652. break;
  653. case NAI_REALM_INNER_NON_EAP_CHAP:
  654. if (wpa_config_set(ssid, "phase2", "\"auth=CHAP\"", 0)
  655. < 0)
  656. goto fail;
  657. break;
  658. case NAI_REALM_INNER_NON_EAP_MSCHAP:
  659. if (wpa_config_set(ssid, "phase2", "\"auth=MSCHAP\"",
  660. 0) < 0)
  661. goto fail;
  662. break;
  663. case NAI_REALM_INNER_NON_EAP_MSCHAPV2:
  664. if (wpa_config_set(ssid, "phase2", "\"auth=MSCHAPV2\"",
  665. 0) < 0)
  666. goto fail;
  667. break;
  668. }
  669. break;
  670. case EAP_TYPE_PEAP:
  671. os_snprintf(buf, sizeof(buf), "\"auth=%s\"",
  672. eap_get_name(EAP_VENDOR_IETF, eap->inner_method));
  673. if (wpa_config_set(ssid, "phase2", buf, 0) < 0)
  674. goto fail;
  675. break;
  676. }
  677. if (cred->ca_cert && cred->ca_cert[0] &&
  678. wpa_config_set_quoted(ssid, "ca_cert", cred->ca_cert) < 0)
  679. goto fail;
  680. nai_realm_free(realm, count);
  681. wpa_s->disconnected = 0;
  682. wpa_s->reassociate = 1;
  683. wpa_supplicant_req_scan(wpa_s, 0, 0);
  684. return 0;
  685. fail:
  686. wpas_notify_network_removed(wpa_s, ssid);
  687. wpa_config_remove_network(wpa_s->conf, ssid->id);
  688. nai_realm_free(realm, count);
  689. return -1;
  690. }
  691. static int interworking_credentials_available_3gpp(
  692. struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
  693. {
  694. struct wpa_cred *cred;
  695. int ret;
  696. #ifdef INTERWORKING_3GPP
  697. if (bss->anqp_3gpp == NULL)
  698. return 0;
  699. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  700. if (cred->imsi == NULL || !cred->imsi[0] ||
  701. cred->milenage == NULL || !cred->milenage[0])
  702. continue;
  703. wpa_printf(MSG_DEBUG, "Interworking: Parsing 3GPP info from "
  704. MACSTR, MAC2STR(bss->bssid));
  705. ret = plmn_id_match(bss->anqp_3gpp, cred->imsi);
  706. wpa_printf(MSG_DEBUG, "PLMN match %sfound", ret ? "" : "not ");
  707. if (ret)
  708. return 1;
  709. }
  710. #endif /* INTERWORKING_3GPP */
  711. return 0;
  712. }
  713. static int interworking_credentials_available_realm(
  714. struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
  715. {
  716. struct wpa_cred *cred;
  717. struct nai_realm *realm;
  718. u16 count, i;
  719. int found = 0;
  720. if (bss->anqp_nai_realm == NULL)
  721. return 0;
  722. if (wpa_s->conf->cred == NULL)
  723. return 0;
  724. wpa_printf(MSG_DEBUG, "Interworking: Parsing NAI Realm list from "
  725. MACSTR, MAC2STR(bss->bssid));
  726. realm = nai_realm_parse(bss->anqp_nai_realm, &count);
  727. if (realm == NULL) {
  728. wpa_printf(MSG_DEBUG, "Interworking: Could not parse NAI "
  729. "Realm list from " MACSTR, MAC2STR(bss->bssid));
  730. return 0;
  731. }
  732. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  733. if (cred->realm == NULL)
  734. continue;
  735. for (i = 0; i < count; i++) {
  736. if (!nai_realm_match(&realm[i], cred->realm))
  737. continue;
  738. if (nai_realm_find_eap(cred, &realm[i])) {
  739. found++;
  740. break;
  741. }
  742. }
  743. if (found)
  744. break;
  745. }
  746. nai_realm_free(realm, count);
  747. return found;
  748. }
  749. static int interworking_credentials_available(struct wpa_supplicant *wpa_s,
  750. struct wpa_bss *bss)
  751. {
  752. return interworking_credentials_available_realm(wpa_s, bss) ||
  753. interworking_credentials_available_3gpp(wpa_s, bss);
  754. }
  755. static int domain_name_list_contains(struct wpabuf *domain_names,
  756. const char *domain)
  757. {
  758. const u8 *pos, *end;
  759. size_t len;
  760. len = os_strlen(domain);
  761. pos = wpabuf_head(domain_names);
  762. end = pos + wpabuf_len(domain_names);
  763. while (pos + 1 < end) {
  764. if (pos + 1 + pos[0] > end)
  765. break;
  766. wpa_hexdump_ascii(MSG_DEBUG, "Interworking: AP domain name",
  767. pos + 1, pos[0]);
  768. if (pos[0] == len &&
  769. os_strncasecmp(domain, (const char *) (pos + 1), len) == 0)
  770. return 1;
  771. pos += 1 + pos[0];
  772. }
  773. return 0;
  774. }
  775. static int interworking_home_sp(struct wpa_supplicant *wpa_s,
  776. struct wpabuf *domain_names)
  777. {
  778. struct wpa_cred *cred;
  779. #ifdef INTERWORKING_3GPP
  780. char nai[100], *realm;
  781. #endif /* INTERWORKING_3GPP */
  782. if (domain_names == NULL || wpa_s->conf->cred == NULL)
  783. return -1;
  784. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  785. #ifdef INTERWORKING_3GPP
  786. if (cred->imsi &&
  787. build_root_nai(nai, cred->imsi, 0) == 0) {
  788. realm = os_strchr(nai, '@');
  789. if (realm)
  790. realm++;
  791. wpa_printf(MSG_DEBUG, "Interworking: Search for match "
  792. "with SIM/USIM domain %s", realm);
  793. if (realm &&
  794. domain_name_list_contains(domain_names, realm))
  795. return 1;
  796. }
  797. #endif /* INTERWORKING_3GPP */
  798. if (cred->domain == NULL)
  799. continue;
  800. wpa_printf(MSG_DEBUG, "Interworking: Search for match with "
  801. "home SP FQDN %s", cred->domain);
  802. if (domain_name_list_contains(domain_names, cred->domain))
  803. return 1;
  804. }
  805. return 0;
  806. }
  807. static void interworking_select_network(struct wpa_supplicant *wpa_s)
  808. {
  809. struct wpa_bss *bss, *selected = NULL, *selected_home = NULL;
  810. unsigned int count = 0;
  811. const char *type;
  812. int res;
  813. wpa_s->network_select = 0;
  814. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  815. if (!interworking_credentials_available(wpa_s, bss))
  816. continue;
  817. count++;
  818. res = interworking_home_sp(wpa_s, bss->anqp_domain_name);
  819. if (res > 0)
  820. type = "home";
  821. else if (res == 0)
  822. type = "roaming";
  823. else
  824. type = "unknown";
  825. wpa_msg(wpa_s, MSG_INFO, INTERWORKING_AP MACSTR " type=%s",
  826. MAC2STR(bss->bssid), type);
  827. if (wpa_s->auto_select) {
  828. if (selected == NULL)
  829. selected = bss;
  830. if (selected_home == NULL && res > 0)
  831. selected_home = bss;
  832. }
  833. }
  834. if (selected_home && selected_home != selected) {
  835. /* Prefer network operated by the Home SP */
  836. selected = selected_home;
  837. }
  838. if (count == 0) {
  839. wpa_msg(wpa_s, MSG_INFO, INTERWORKING_NO_MATCH "No network "
  840. "with matching credentials found");
  841. }
  842. if (selected)
  843. interworking_connect(wpa_s, selected);
  844. }
  845. static void interworking_next_anqp_fetch(struct wpa_supplicant *wpa_s)
  846. {
  847. struct wpa_bss *bss;
  848. int found = 0;
  849. const u8 *ie;
  850. if (!wpa_s->fetch_anqp_in_progress)
  851. return;
  852. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  853. if (!(bss->caps & IEEE80211_CAP_ESS))
  854. continue;
  855. ie = wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB);
  856. if (ie == NULL || ie[1] < 4 || !(ie[5] & 0x80))
  857. continue; /* AP does not support Interworking */
  858. if (!(bss->flags & WPA_BSS_ANQP_FETCH_TRIED)) {
  859. found++;
  860. bss->flags |= WPA_BSS_ANQP_FETCH_TRIED;
  861. wpa_msg(wpa_s, MSG_INFO, "Starting ANQP fetch for "
  862. MACSTR, MAC2STR(bss->bssid));
  863. interworking_anqp_send_req(wpa_s, bss);
  864. break;
  865. }
  866. }
  867. if (found == 0) {
  868. wpa_msg(wpa_s, MSG_INFO, "ANQP fetch completed");
  869. wpa_s->fetch_anqp_in_progress = 0;
  870. if (wpa_s->network_select)
  871. interworking_select_network(wpa_s);
  872. }
  873. }
  874. static void interworking_start_fetch_anqp(struct wpa_supplicant *wpa_s)
  875. {
  876. struct wpa_bss *bss;
  877. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list)
  878. bss->flags &= ~WPA_BSS_ANQP_FETCH_TRIED;
  879. wpa_s->fetch_anqp_in_progress = 1;
  880. interworking_next_anqp_fetch(wpa_s);
  881. }
  882. int interworking_fetch_anqp(struct wpa_supplicant *wpa_s)
  883. {
  884. if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select)
  885. return 0;
  886. wpa_s->network_select = 0;
  887. interworking_start_fetch_anqp(wpa_s);
  888. return 0;
  889. }
  890. void interworking_stop_fetch_anqp(struct wpa_supplicant *wpa_s)
  891. {
  892. if (!wpa_s->fetch_anqp_in_progress)
  893. return;
  894. wpa_s->fetch_anqp_in_progress = 0;
  895. }
  896. int anqp_send_req(struct wpa_supplicant *wpa_s, const u8 *dst,
  897. u16 info_ids[], size_t num_ids)
  898. {
  899. struct wpabuf *buf;
  900. int ret = 0;
  901. int freq;
  902. struct wpa_bss *bss;
  903. int res;
  904. freq = wpa_s->assoc_freq;
  905. bss = wpa_bss_get_bssid(wpa_s, dst);
  906. if (bss)
  907. freq = bss->freq;
  908. if (freq <= 0)
  909. return -1;
  910. wpa_printf(MSG_DEBUG, "ANQP: Query Request to " MACSTR " for %u id(s)",
  911. MAC2STR(dst), (unsigned int) num_ids);
  912. buf = anqp_build_req(info_ids, num_ids, NULL);
  913. if (buf == NULL)
  914. return -1;
  915. res = gas_query_req(wpa_s->gas, dst, freq, buf, anqp_resp_cb, wpa_s);
  916. if (res < 0) {
  917. wpa_printf(MSG_DEBUG, "ANQP: Failed to send Query Request");
  918. ret = -1;
  919. } else
  920. wpa_printf(MSG_DEBUG, "ANQP: Query started with dialog token "
  921. "%u", res);
  922. wpabuf_free(buf);
  923. return ret;
  924. }
  925. static void interworking_parse_rx_anqp_resp(struct wpa_supplicant *wpa_s,
  926. const u8 *sa, u16 info_id,
  927. const u8 *data, size_t slen)
  928. {
  929. const u8 *pos = data;
  930. struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, sa);
  931. switch (info_id) {
  932. case ANQP_CAPABILITY_LIST:
  933. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  934. " ANQP Capability list", MAC2STR(sa));
  935. break;
  936. case ANQP_VENUE_NAME:
  937. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  938. " Venue Name", MAC2STR(sa));
  939. wpa_hexdump_ascii(MSG_DEBUG, "ANQP: Venue Name", pos, slen);
  940. if (bss) {
  941. wpabuf_free(bss->anqp_venue_name);
  942. bss->anqp_venue_name = wpabuf_alloc_copy(pos, slen);
  943. }
  944. break;
  945. case ANQP_NETWORK_AUTH_TYPE:
  946. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  947. " Network Authentication Type information",
  948. MAC2STR(sa));
  949. wpa_hexdump_ascii(MSG_DEBUG, "ANQP: Network Authentication "
  950. "Type", pos, slen);
  951. if (bss) {
  952. wpabuf_free(bss->anqp_network_auth_type);
  953. bss->anqp_network_auth_type =
  954. wpabuf_alloc_copy(pos, slen);
  955. }
  956. break;
  957. case ANQP_ROAMING_CONSORTIUM:
  958. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  959. " Roaming Consortium list", MAC2STR(sa));
  960. wpa_hexdump_ascii(MSG_DEBUG, "ANQP: Roaming Consortium",
  961. pos, slen);
  962. if (bss) {
  963. wpabuf_free(bss->anqp_roaming_consortium);
  964. bss->anqp_roaming_consortium =
  965. wpabuf_alloc_copy(pos, slen);
  966. }
  967. break;
  968. case ANQP_IP_ADDR_TYPE_AVAILABILITY:
  969. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  970. " IP Address Type Availability information",
  971. MAC2STR(sa));
  972. wpa_hexdump(MSG_MSGDUMP, "ANQP: IP Address Availability",
  973. pos, slen);
  974. if (bss) {
  975. wpabuf_free(bss->anqp_ip_addr_type_availability);
  976. bss->anqp_ip_addr_type_availability =
  977. wpabuf_alloc_copy(pos, slen);
  978. }
  979. break;
  980. case ANQP_NAI_REALM:
  981. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  982. " NAI Realm list", MAC2STR(sa));
  983. wpa_hexdump_ascii(MSG_DEBUG, "ANQP: NAI Realm", pos, slen);
  984. if (bss) {
  985. wpabuf_free(bss->anqp_nai_realm);
  986. bss->anqp_nai_realm = wpabuf_alloc_copy(pos, slen);
  987. }
  988. break;
  989. case ANQP_3GPP_CELLULAR_NETWORK:
  990. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  991. " 3GPP Cellular Network information", MAC2STR(sa));
  992. wpa_hexdump_ascii(MSG_DEBUG, "ANQP: 3GPP Cellular Network",
  993. pos, slen);
  994. if (bss) {
  995. wpabuf_free(bss->anqp_3gpp);
  996. bss->anqp_3gpp = wpabuf_alloc_copy(pos, slen);
  997. }
  998. break;
  999. case ANQP_DOMAIN_NAME:
  1000. wpa_msg(wpa_s, MSG_INFO, "RX-ANQP " MACSTR
  1001. " Domain Name list", MAC2STR(sa));
  1002. wpa_hexdump_ascii(MSG_MSGDUMP, "ANQP: Domain Name", pos, slen);
  1003. if (bss) {
  1004. wpabuf_free(bss->anqp_domain_name);
  1005. bss->anqp_domain_name = wpabuf_alloc_copy(pos, slen);
  1006. }
  1007. break;
  1008. case ANQP_VENDOR_SPECIFIC:
  1009. if (slen < 3)
  1010. return;
  1011. switch (WPA_GET_BE24(pos)) {
  1012. default:
  1013. wpa_printf(MSG_DEBUG, "Interworking: Unsupported "
  1014. "vendor-specific ANQP OUI %06x",
  1015. WPA_GET_BE24(pos));
  1016. return;
  1017. }
  1018. break;
  1019. default:
  1020. wpa_printf(MSG_DEBUG, "Interworking: Unsupported ANQP Info ID "
  1021. "%u", info_id);
  1022. break;
  1023. }
  1024. }
  1025. void anqp_resp_cb(void *ctx, const u8 *dst, u8 dialog_token,
  1026. enum gas_query_result result,
  1027. const struct wpabuf *adv_proto,
  1028. const struct wpabuf *resp, u16 status_code)
  1029. {
  1030. struct wpa_supplicant *wpa_s = ctx;
  1031. const u8 *pos;
  1032. const u8 *end;
  1033. u16 info_id;
  1034. u16 slen;
  1035. if (result != GAS_QUERY_SUCCESS)
  1036. return;
  1037. pos = wpabuf_head(adv_proto);
  1038. if (wpabuf_len(adv_proto) < 4 || pos[0] != WLAN_EID_ADV_PROTO ||
  1039. pos[1] < 2 || pos[3] != ACCESS_NETWORK_QUERY_PROTOCOL) {
  1040. wpa_printf(MSG_DEBUG, "ANQP: Unexpected Advertisement "
  1041. "Protocol in response");
  1042. return;
  1043. }
  1044. pos = wpabuf_head(resp);
  1045. end = pos + wpabuf_len(resp);
  1046. while (pos < end) {
  1047. if (pos + 4 > end) {
  1048. wpa_printf(MSG_DEBUG, "ANQP: Invalid element");
  1049. break;
  1050. }
  1051. info_id = WPA_GET_LE16(pos);
  1052. pos += 2;
  1053. slen = WPA_GET_LE16(pos);
  1054. pos += 2;
  1055. if (pos + slen > end) {
  1056. wpa_printf(MSG_DEBUG, "ANQP: Invalid element length "
  1057. "for Info ID %u", info_id);
  1058. break;
  1059. }
  1060. interworking_parse_rx_anqp_resp(wpa_s, dst, info_id, pos,
  1061. slen);
  1062. pos += slen;
  1063. }
  1064. }
  1065. static void interworking_scan_res_handler(struct wpa_supplicant *wpa_s,
  1066. struct wpa_scan_results *scan_res)
  1067. {
  1068. wpa_printf(MSG_DEBUG, "Interworking: Scan results available - start "
  1069. "ANQP fetch");
  1070. interworking_start_fetch_anqp(wpa_s);
  1071. }
  1072. int interworking_select(struct wpa_supplicant *wpa_s, int auto_select)
  1073. {
  1074. interworking_stop_fetch_anqp(wpa_s);
  1075. wpa_s->network_select = 1;
  1076. wpa_s->auto_select = !!auto_select;
  1077. wpa_printf(MSG_DEBUG, "Interworking: Start scan for network "
  1078. "selection");
  1079. wpa_s->scan_res_handler = interworking_scan_res_handler;
  1080. wpa_s->scan_req = 2;
  1081. wpa_supplicant_req_scan(wpa_s, 0, 0);
  1082. return 0;
  1083. }