hs20_supplicant.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  1. /*
  2. * Copyright (c) 2009, Atheros Communications, Inc.
  3. * Copyright (c) 2011-2013, Qualcomm Atheros, Inc.
  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 <sys/stat.h>
  10. #include "common.h"
  11. #include "eloop.h"
  12. #include "common/ieee802_11_common.h"
  13. #include "common/ieee802_11_defs.h"
  14. #include "common/gas.h"
  15. #include "common/wpa_ctrl.h"
  16. #include "rsn_supp/wpa.h"
  17. #include "wpa_supplicant_i.h"
  18. #include "driver_i.h"
  19. #include "config.h"
  20. #include "scan.h"
  21. #include "bss.h"
  22. #include "blacklist.h"
  23. #include "gas_query.h"
  24. #include "interworking.h"
  25. #include "hs20_supplicant.h"
  26. #include "base64.h"
  27. #define OSU_MAX_ITEMS 10
  28. struct osu_lang_string {
  29. char lang[4];
  30. char text[253];
  31. };
  32. struct osu_icon {
  33. u16 width;
  34. u16 height;
  35. char lang[4];
  36. char icon_type[256];
  37. char filename[256];
  38. unsigned int id;
  39. unsigned int failed:1;
  40. };
  41. struct osu_provider {
  42. u8 bssid[ETH_ALEN];
  43. u8 osu_ssid[SSID_MAX_LEN];
  44. u8 osu_ssid_len;
  45. char server_uri[256];
  46. u32 osu_methods; /* bit 0 = OMA-DM, bit 1 = SOAP-XML SPP */
  47. char osu_nai[256];
  48. struct osu_lang_string friendly_name[OSU_MAX_ITEMS];
  49. size_t friendly_name_count;
  50. struct osu_lang_string serv_desc[OSU_MAX_ITEMS];
  51. size_t serv_desc_count;
  52. struct osu_icon icon[OSU_MAX_ITEMS];
  53. size_t icon_count;
  54. };
  55. void hs20_configure_frame_filters(struct wpa_supplicant *wpa_s)
  56. {
  57. struct wpa_bss *bss = wpa_s->current_bss;
  58. u8 *bssid = wpa_s->bssid;
  59. const u8 *ie;
  60. const u8 *ext_capa;
  61. u32 filter = 0;
  62. if (!bss || !is_hs20_network(wpa_s, wpa_s->current_ssid, bss)) {
  63. wpa_printf(MSG_DEBUG,
  64. "Not configuring frame filtering - BSS " MACSTR
  65. " is not a Hotspot 2.0 network", MAC2STR(bssid));
  66. return;
  67. }
  68. ie = wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE);
  69. /* Check if DGAF disabled bit is zero (5th byte in the IE) */
  70. if (!ie || ie[1] < 5)
  71. wpa_printf(MSG_DEBUG,
  72. "Not configuring frame filtering - Can't extract DGAF bit");
  73. else if (!(ie[6] & HS20_DGAF_DISABLED))
  74. filter |= WPA_DATA_FRAME_FILTER_FLAG_GTK;
  75. ext_capa = wpa_bss_get_ie(bss, WLAN_EID_EXT_CAPAB);
  76. if (!ext_capa || ext_capa[1] < 2) {
  77. wpa_printf(MSG_DEBUG,
  78. "Not configuring frame filtering - Can't extract Proxy ARP bit");
  79. return;
  80. }
  81. /* Check if Proxy ARP is enabled (2nd byte in the IE) */
  82. if (ext_capa[3] & BIT(4))
  83. filter |= WPA_DATA_FRAME_FILTER_FLAG_ARP |
  84. WPA_DATA_FRAME_FILTER_FLAG_NA;
  85. wpa_drv_configure_frame_filters(wpa_s, filter);
  86. }
  87. void wpas_hs20_add_indication(struct wpabuf *buf, int pps_mo_id)
  88. {
  89. u8 conf;
  90. wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC);
  91. wpabuf_put_u8(buf, pps_mo_id >= 0 ? 7 : 5);
  92. wpabuf_put_be24(buf, OUI_WFA);
  93. wpabuf_put_u8(buf, HS20_INDICATION_OUI_TYPE);
  94. conf = HS20_VERSION;
  95. if (pps_mo_id >= 0)
  96. conf |= HS20_PPS_MO_ID_PRESENT;
  97. wpabuf_put_u8(buf, conf);
  98. if (pps_mo_id >= 0)
  99. wpabuf_put_le16(buf, pps_mo_id);
  100. }
  101. int is_hs20_network(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  102. struct wpa_bss *bss)
  103. {
  104. if (!wpa_s->conf->hs20 || !ssid)
  105. return 0;
  106. if (ssid->parent_cred)
  107. return 1;
  108. if (bss && !wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE))
  109. return 0;
  110. /*
  111. * This may catch some non-Hotspot 2.0 cases, but it is safer to do that
  112. * than cause Hotspot 2.0 connections without indication element getting
  113. * added. Non-Hotspot 2.0 APs should ignore the unknown vendor element.
  114. */
  115. if (!(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X))
  116. return 0;
  117. if (!(ssid->pairwise_cipher & WPA_CIPHER_CCMP))
  118. return 0;
  119. if (ssid->proto != WPA_PROTO_RSN)
  120. return 0;
  121. return 1;
  122. }
  123. int hs20_get_pps_mo_id(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
  124. {
  125. struct wpa_cred *cred;
  126. if (ssid == NULL)
  127. return 0;
  128. if (ssid->update_identifier)
  129. return ssid->update_identifier;
  130. if (ssid->parent_cred == NULL)
  131. return 0;
  132. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  133. if (ssid->parent_cred == cred)
  134. return cred->update_identifier;
  135. }
  136. return 0;
  137. }
  138. void hs20_put_anqp_req(u32 stypes, const u8 *payload, size_t payload_len,
  139. struct wpabuf *buf)
  140. {
  141. u8 *len_pos;
  142. if (buf == NULL)
  143. return;
  144. len_pos = gas_anqp_add_element(buf, ANQP_VENDOR_SPECIFIC);
  145. wpabuf_put_be24(buf, OUI_WFA);
  146. wpabuf_put_u8(buf, HS20_ANQP_OUI_TYPE);
  147. if (stypes == BIT(HS20_STYPE_NAI_HOME_REALM_QUERY)) {
  148. wpabuf_put_u8(buf, HS20_STYPE_NAI_HOME_REALM_QUERY);
  149. wpabuf_put_u8(buf, 0); /* Reserved */
  150. if (payload)
  151. wpabuf_put_data(buf, payload, payload_len);
  152. } else if (stypes == BIT(HS20_STYPE_ICON_REQUEST)) {
  153. wpabuf_put_u8(buf, HS20_STYPE_ICON_REQUEST);
  154. wpabuf_put_u8(buf, 0); /* Reserved */
  155. if (payload)
  156. wpabuf_put_data(buf, payload, payload_len);
  157. } else {
  158. u8 i;
  159. wpabuf_put_u8(buf, HS20_STYPE_QUERY_LIST);
  160. wpabuf_put_u8(buf, 0); /* Reserved */
  161. for (i = 0; i < 32; i++) {
  162. if (stypes & BIT(i))
  163. wpabuf_put_u8(buf, i);
  164. }
  165. }
  166. gas_anqp_set_element_len(buf, len_pos);
  167. gas_anqp_set_len(buf);
  168. }
  169. static struct wpabuf * hs20_build_anqp_req(u32 stypes, const u8 *payload,
  170. size_t payload_len)
  171. {
  172. struct wpabuf *buf;
  173. buf = gas_anqp_build_initial_req(0, 100 + payload_len);
  174. if (buf == NULL)
  175. return NULL;
  176. hs20_put_anqp_req(stypes, payload, payload_len, buf);
  177. return buf;
  178. }
  179. int hs20_anqp_send_req(struct wpa_supplicant *wpa_s, const u8 *dst, u32 stypes,
  180. const u8 *payload, size_t payload_len, int inmem)
  181. {
  182. struct wpabuf *buf;
  183. int ret = 0;
  184. int freq;
  185. struct wpa_bss *bss;
  186. int res;
  187. struct icon_entry *icon_entry;
  188. bss = wpa_bss_get_bssid(wpa_s, dst);
  189. if (!bss) {
  190. wpa_printf(MSG_WARNING,
  191. "ANQP: Cannot send query to unknown BSS "
  192. MACSTR, MAC2STR(dst));
  193. return -1;
  194. }
  195. wpa_bss_anqp_unshare_alloc(bss);
  196. freq = bss->freq;
  197. wpa_printf(MSG_DEBUG, "HS20: ANQP Query Request to " MACSTR " for "
  198. "subtypes 0x%x", MAC2STR(dst), stypes);
  199. buf = hs20_build_anqp_req(stypes, payload, payload_len);
  200. if (buf == NULL)
  201. return -1;
  202. res = gas_query_req(wpa_s->gas, dst, freq, 0, buf, anqp_resp_cb, wpa_s);
  203. if (res < 0) {
  204. wpa_printf(MSG_DEBUG, "ANQP: Failed to send Query Request");
  205. wpabuf_free(buf);
  206. return -1;
  207. } else
  208. wpa_printf(MSG_DEBUG, "ANQP: Query started with dialog token "
  209. "%u", res);
  210. if (inmem) {
  211. icon_entry = os_zalloc(sizeof(struct icon_entry));
  212. if (!icon_entry)
  213. return -1;
  214. os_memcpy(icon_entry->bssid, dst, ETH_ALEN);
  215. icon_entry->file_name = os_malloc(payload_len + 1);
  216. if (!icon_entry->file_name) {
  217. os_free(icon_entry);
  218. return -1;
  219. }
  220. os_memcpy(icon_entry->file_name, payload, payload_len);
  221. icon_entry->file_name[payload_len] = '\0';
  222. icon_entry->dialog_token = res;
  223. dl_list_add(&wpa_s->icon_head, &icon_entry->list);
  224. }
  225. return ret;
  226. }
  227. static struct icon_entry * hs20_find_icon(struct wpa_supplicant *wpa_s,
  228. const u8 *bssid,
  229. const char *file_name)
  230. {
  231. struct icon_entry *icon;
  232. dl_list_for_each(icon, &wpa_s->icon_head, struct icon_entry, list) {
  233. if (os_memcmp(icon->bssid, bssid, ETH_ALEN) == 0 &&
  234. os_strcmp(icon->file_name, file_name) == 0 && icon->image)
  235. return icon;
  236. }
  237. return NULL;
  238. }
  239. int hs20_get_icon(struct wpa_supplicant *wpa_s, const u8 *bssid,
  240. const char *file_name, size_t offset, size_t size,
  241. char *reply, size_t buf_len)
  242. {
  243. struct icon_entry *icon;
  244. size_t out_size;
  245. unsigned char *b64;
  246. size_t b64_size;
  247. int reply_size;
  248. wpa_printf(MSG_DEBUG, "HS20: Get icon " MACSTR " %s @ %u +%u (%u)",
  249. MAC2STR(bssid), file_name, (unsigned int) offset,
  250. (unsigned int) size, (unsigned int) buf_len);
  251. icon = hs20_find_icon(wpa_s, bssid, file_name);
  252. if (!icon || !icon->image || offset >= icon->image_len)
  253. return -1;
  254. if (size > icon->image_len - offset)
  255. size = icon->image_len - offset;
  256. out_size = buf_len - 3 /* max base64 padding */;
  257. if (size * 4 > out_size * 3)
  258. size = out_size * 3 / 4;
  259. if (size == 0)
  260. return -1;
  261. b64 = base64_encode(&icon->image[offset], size, &b64_size);
  262. if (b64 && buf_len >= b64_size) {
  263. os_memcpy(reply, b64, b64_size);
  264. reply_size = b64_size;
  265. } else {
  266. reply_size = -1;
  267. }
  268. os_free(b64);
  269. return reply_size;
  270. }
  271. static void hs20_free_icon_entry(struct icon_entry *icon)
  272. {
  273. wpa_printf(MSG_DEBUG, "HS20: Free stored icon from " MACSTR
  274. " dialog_token=%u file_name=%s image_len=%u",
  275. MAC2STR(icon->bssid), icon->dialog_token,
  276. icon->file_name ? icon->file_name : "N/A",
  277. (unsigned int) icon->image_len);
  278. os_free(icon->file_name);
  279. os_free(icon->image);
  280. os_free(icon);
  281. }
  282. int hs20_del_icon(struct wpa_supplicant *wpa_s, const u8 *bssid,
  283. const char *file_name)
  284. {
  285. struct icon_entry *icon, *tmp;
  286. int count = 0;
  287. if (!bssid)
  288. wpa_printf(MSG_DEBUG, "HS20: Delete all stored icons");
  289. else if (!file_name)
  290. wpa_printf(MSG_DEBUG, "HS20: Delete all stored icons for "
  291. MACSTR, MAC2STR(bssid));
  292. else
  293. wpa_printf(MSG_DEBUG, "HS20: Delete stored icons for "
  294. MACSTR " file name %s", MAC2STR(bssid), file_name);
  295. dl_list_for_each_safe(icon, tmp, &wpa_s->icon_head, struct icon_entry,
  296. list) {
  297. if ((!bssid || os_memcmp(icon->bssid, bssid, ETH_ALEN) == 0) &&
  298. (!file_name ||
  299. os_strcmp(icon->file_name, file_name) == 0)) {
  300. dl_list_del(&icon->list);
  301. hs20_free_icon_entry(icon);
  302. count++;
  303. }
  304. }
  305. return count == 0 ? -1 : 0;
  306. }
  307. static void hs20_set_osu_access_permission(const char *osu_dir,
  308. const char *fname)
  309. {
  310. struct stat statbuf;
  311. /* Get OSU directory information */
  312. if (stat(osu_dir, &statbuf) < 0) {
  313. wpa_printf(MSG_WARNING, "Cannot stat the OSU directory %s",
  314. osu_dir);
  315. return;
  316. }
  317. if (chmod(fname, statbuf.st_mode) < 0) {
  318. wpa_printf(MSG_WARNING,
  319. "Cannot change the permissions for %s", fname);
  320. return;
  321. }
  322. if (chown(fname, statbuf.st_uid, statbuf.st_gid) < 0) {
  323. wpa_printf(MSG_WARNING, "Cannot change the ownership for %s",
  324. fname);
  325. }
  326. }
  327. static void hs20_remove_duplicate_icons(struct wpa_supplicant *wpa_s,
  328. struct icon_entry *new_icon)
  329. {
  330. struct icon_entry *icon, *tmp;
  331. dl_list_for_each_safe(icon, tmp, &wpa_s->icon_head, struct icon_entry,
  332. list) {
  333. if (icon == new_icon)
  334. continue;
  335. if (os_memcmp(icon->bssid, new_icon->bssid, ETH_ALEN) == 0 &&
  336. os_strcmp(icon->file_name, new_icon->file_name) == 0) {
  337. dl_list_del(&icon->list);
  338. hs20_free_icon_entry(icon);
  339. }
  340. }
  341. }
  342. static int hs20_process_icon_binary_file(struct wpa_supplicant *wpa_s,
  343. const u8 *sa, const u8 *pos,
  344. size_t slen, u8 dialog_token)
  345. {
  346. char fname[256];
  347. int png;
  348. FILE *f;
  349. u16 data_len;
  350. struct icon_entry *icon;
  351. dl_list_for_each(icon, &wpa_s->icon_head, struct icon_entry, list) {
  352. if (icon->dialog_token == dialog_token && !icon->image &&
  353. os_memcmp(icon->bssid, sa, ETH_ALEN) == 0) {
  354. icon->image = os_memdup(pos, slen);
  355. if (!icon->image)
  356. return -1;
  357. icon->image_len = slen;
  358. hs20_remove_duplicate_icons(wpa_s, icon);
  359. wpa_msg(wpa_s, MSG_INFO,
  360. RX_HS20_ICON MACSTR " %s %u",
  361. MAC2STR(sa), icon->file_name,
  362. (unsigned int) icon->image_len);
  363. return 0;
  364. }
  365. }
  366. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR " Icon Binary File",
  367. MAC2STR(sa));
  368. if (slen < 4) {
  369. wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
  370. "value from " MACSTR, MAC2STR(sa));
  371. return -1;
  372. }
  373. wpa_printf(MSG_DEBUG, "HS 2.0: Download Status Code %u", *pos);
  374. if (*pos != 0)
  375. return -1;
  376. pos++;
  377. slen--;
  378. if ((size_t) 1 + pos[0] > slen) {
  379. wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
  380. "value from " MACSTR, MAC2STR(sa));
  381. return -1;
  382. }
  383. wpa_hexdump_ascii(MSG_DEBUG, "Icon Type", pos + 1, pos[0]);
  384. png = os_strncasecmp((char *) pos + 1, "image/png", 9) == 0;
  385. slen -= 1 + pos[0];
  386. pos += 1 + pos[0];
  387. if (slen < 2) {
  388. wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
  389. "value from " MACSTR, MAC2STR(sa));
  390. return -1;
  391. }
  392. data_len = WPA_GET_LE16(pos);
  393. pos += 2;
  394. slen -= 2;
  395. if (data_len > slen) {
  396. wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short Icon Binary File "
  397. "value from " MACSTR, MAC2STR(sa));
  398. return -1;
  399. }
  400. wpa_printf(MSG_DEBUG, "Icon Binary Data: %u bytes", data_len);
  401. if (wpa_s->conf->osu_dir == NULL)
  402. return -1;
  403. wpa_s->osu_icon_id++;
  404. if (wpa_s->osu_icon_id == 0)
  405. wpa_s->osu_icon_id++;
  406. snprintf(fname, sizeof(fname), "%s/osu-icon-%u.%s",
  407. wpa_s->conf->osu_dir, wpa_s->osu_icon_id,
  408. png ? "png" : "icon");
  409. f = fopen(fname, "wb");
  410. if (f == NULL)
  411. return -1;
  412. hs20_set_osu_access_permission(wpa_s->conf->osu_dir, fname);
  413. if (fwrite(pos, slen, 1, f) != 1) {
  414. fclose(f);
  415. unlink(fname);
  416. return -1;
  417. }
  418. fclose(f);
  419. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP_ICON "%s", fname);
  420. return 0;
  421. }
  422. static void hs20_continue_icon_fetch(void *eloop_ctx, void *sock_ctx)
  423. {
  424. struct wpa_supplicant *wpa_s = eloop_ctx;
  425. if (wpa_s->fetch_osu_icon_in_progress)
  426. hs20_next_osu_icon(wpa_s);
  427. }
  428. static void hs20_osu_icon_fetch_result(struct wpa_supplicant *wpa_s, int res)
  429. {
  430. size_t i, j;
  431. struct os_reltime now, tmp;
  432. int dur;
  433. os_get_reltime(&now);
  434. os_reltime_sub(&now, &wpa_s->osu_icon_fetch_start, &tmp);
  435. dur = tmp.sec * 1000 + tmp.usec / 1000;
  436. wpa_printf(MSG_DEBUG, "HS 2.0: Icon fetch dur=%d ms res=%d",
  437. dur, res);
  438. for (i = 0; i < wpa_s->osu_prov_count; i++) {
  439. struct osu_provider *osu = &wpa_s->osu_prov[i];
  440. for (j = 0; j < osu->icon_count; j++) {
  441. struct osu_icon *icon = &osu->icon[j];
  442. if (icon->id || icon->failed)
  443. continue;
  444. if (res < 0)
  445. icon->failed = 1;
  446. else
  447. icon->id = wpa_s->osu_icon_id;
  448. return;
  449. }
  450. }
  451. }
  452. void hs20_parse_rx_hs20_anqp_resp(struct wpa_supplicant *wpa_s,
  453. struct wpa_bss *bss, const u8 *sa,
  454. const u8 *data, size_t slen, u8 dialog_token)
  455. {
  456. const u8 *pos = data;
  457. u8 subtype;
  458. struct wpa_bss_anqp *anqp = NULL;
  459. int ret;
  460. if (slen < 2)
  461. return;
  462. if (bss)
  463. anqp = bss->anqp;
  464. subtype = *pos++;
  465. slen--;
  466. pos++; /* Reserved */
  467. slen--;
  468. switch (subtype) {
  469. case HS20_STYPE_CAPABILITY_LIST:
  470. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
  471. " HS Capability List", MAC2STR(sa));
  472. wpa_hexdump_ascii(MSG_DEBUG, "HS Capability List", pos, slen);
  473. if (anqp) {
  474. wpabuf_free(anqp->hs20_capability_list);
  475. anqp->hs20_capability_list =
  476. wpabuf_alloc_copy(pos, slen);
  477. }
  478. break;
  479. case HS20_STYPE_OPERATOR_FRIENDLY_NAME:
  480. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
  481. " Operator Friendly Name", MAC2STR(sa));
  482. wpa_hexdump_ascii(MSG_DEBUG, "oper friendly name", pos, slen);
  483. if (anqp) {
  484. wpabuf_free(anqp->hs20_operator_friendly_name);
  485. anqp->hs20_operator_friendly_name =
  486. wpabuf_alloc_copy(pos, slen);
  487. }
  488. break;
  489. case HS20_STYPE_WAN_METRICS:
  490. wpa_hexdump(MSG_DEBUG, "WAN Metrics", pos, slen);
  491. if (slen < 13) {
  492. wpa_dbg(wpa_s, MSG_DEBUG, "HS 2.0: Too short WAN "
  493. "Metrics value from " MACSTR, MAC2STR(sa));
  494. break;
  495. }
  496. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
  497. " WAN Metrics %02x:%u:%u:%u:%u:%u", MAC2STR(sa),
  498. pos[0], WPA_GET_LE32(pos + 1), WPA_GET_LE32(pos + 5),
  499. pos[9], pos[10], WPA_GET_LE16(pos + 11));
  500. if (anqp) {
  501. wpabuf_free(anqp->hs20_wan_metrics);
  502. anqp->hs20_wan_metrics = wpabuf_alloc_copy(pos, slen);
  503. }
  504. break;
  505. case HS20_STYPE_CONNECTION_CAPABILITY:
  506. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
  507. " Connection Capability", MAC2STR(sa));
  508. wpa_hexdump_ascii(MSG_DEBUG, "conn capability", pos, slen);
  509. if (anqp) {
  510. wpabuf_free(anqp->hs20_connection_capability);
  511. anqp->hs20_connection_capability =
  512. wpabuf_alloc_copy(pos, slen);
  513. }
  514. break;
  515. case HS20_STYPE_OPERATING_CLASS:
  516. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
  517. " Operating Class", MAC2STR(sa));
  518. wpa_hexdump_ascii(MSG_DEBUG, "Operating Class", pos, slen);
  519. if (anqp) {
  520. wpabuf_free(anqp->hs20_operating_class);
  521. anqp->hs20_operating_class =
  522. wpabuf_alloc_copy(pos, slen);
  523. }
  524. break;
  525. case HS20_STYPE_OSU_PROVIDERS_LIST:
  526. wpa_msg(wpa_s, MSG_INFO, RX_HS20_ANQP MACSTR
  527. " OSU Providers list", MAC2STR(sa));
  528. wpa_s->num_prov_found++;
  529. if (anqp) {
  530. wpabuf_free(anqp->hs20_osu_providers_list);
  531. anqp->hs20_osu_providers_list =
  532. wpabuf_alloc_copy(pos, slen);
  533. }
  534. break;
  535. case HS20_STYPE_ICON_BINARY_FILE:
  536. ret = hs20_process_icon_binary_file(wpa_s, sa, pos, slen,
  537. dialog_token);
  538. if (wpa_s->fetch_osu_icon_in_progress) {
  539. hs20_osu_icon_fetch_result(wpa_s, ret);
  540. eloop_cancel_timeout(hs20_continue_icon_fetch,
  541. wpa_s, NULL);
  542. eloop_register_timeout(0, 0, hs20_continue_icon_fetch,
  543. wpa_s, NULL);
  544. }
  545. break;
  546. default:
  547. wpa_printf(MSG_DEBUG, "HS20: Unsupported subtype %u", subtype);
  548. break;
  549. }
  550. }
  551. void hs20_notify_parse_done(struct wpa_supplicant *wpa_s)
  552. {
  553. if (!wpa_s->fetch_osu_icon_in_progress)
  554. return;
  555. if (eloop_is_timeout_registered(hs20_continue_icon_fetch, wpa_s, NULL))
  556. return;
  557. /*
  558. * We are going through icon fetch, but no icon response was received.
  559. * Assume this means the current AP could not provide an answer to avoid
  560. * getting stuck in fetch iteration.
  561. */
  562. hs20_icon_fetch_failed(wpa_s);
  563. }
  564. static void hs20_free_osu_prov_entry(struct osu_provider *prov)
  565. {
  566. }
  567. void hs20_free_osu_prov(struct wpa_supplicant *wpa_s)
  568. {
  569. size_t i;
  570. for (i = 0; i < wpa_s->osu_prov_count; i++)
  571. hs20_free_osu_prov_entry(&wpa_s->osu_prov[i]);
  572. os_free(wpa_s->osu_prov);
  573. wpa_s->osu_prov = NULL;
  574. wpa_s->osu_prov_count = 0;
  575. }
  576. static void hs20_osu_fetch_done(struct wpa_supplicant *wpa_s)
  577. {
  578. char fname[256];
  579. FILE *f;
  580. size_t i, j;
  581. wpa_s->fetch_osu_info = 0;
  582. wpa_s->fetch_osu_icon_in_progress = 0;
  583. if (wpa_s->conf->osu_dir == NULL) {
  584. hs20_free_osu_prov(wpa_s);
  585. wpa_s->fetch_anqp_in_progress = 0;
  586. return;
  587. }
  588. snprintf(fname, sizeof(fname), "%s/osu-providers.txt",
  589. wpa_s->conf->osu_dir);
  590. f = fopen(fname, "w");
  591. if (f == NULL) {
  592. wpa_msg(wpa_s, MSG_INFO,
  593. "Could not write OSU provider information");
  594. hs20_free_osu_prov(wpa_s);
  595. wpa_s->fetch_anqp_in_progress = 0;
  596. return;
  597. }
  598. hs20_set_osu_access_permission(wpa_s->conf->osu_dir, fname);
  599. for (i = 0; i < wpa_s->osu_prov_count; i++) {
  600. struct osu_provider *osu = &wpa_s->osu_prov[i];
  601. if (i > 0)
  602. fprintf(f, "\n");
  603. fprintf(f, "OSU-PROVIDER " MACSTR "\n"
  604. "uri=%s\n"
  605. "methods=%08x\n",
  606. MAC2STR(osu->bssid), osu->server_uri, osu->osu_methods);
  607. if (osu->osu_ssid_len) {
  608. fprintf(f, "osu_ssid=%s\n",
  609. wpa_ssid_txt(osu->osu_ssid,
  610. osu->osu_ssid_len));
  611. }
  612. if (osu->osu_nai[0])
  613. fprintf(f, "osu_nai=%s\n", osu->osu_nai);
  614. for (j = 0; j < osu->friendly_name_count; j++) {
  615. fprintf(f, "friendly_name=%s:%s\n",
  616. osu->friendly_name[j].lang,
  617. osu->friendly_name[j].text);
  618. }
  619. for (j = 0; j < osu->serv_desc_count; j++) {
  620. fprintf(f, "desc=%s:%s\n",
  621. osu->serv_desc[j].lang,
  622. osu->serv_desc[j].text);
  623. }
  624. for (j = 0; j < osu->icon_count; j++) {
  625. struct osu_icon *icon = &osu->icon[j];
  626. if (icon->failed)
  627. continue; /* could not fetch icon */
  628. fprintf(f, "icon=%u:%u:%u:%s:%s:%s\n",
  629. icon->id, icon->width, icon->height, icon->lang,
  630. icon->icon_type, icon->filename);
  631. }
  632. }
  633. fclose(f);
  634. hs20_free_osu_prov(wpa_s);
  635. wpa_msg(wpa_s, MSG_INFO, "OSU provider fetch completed");
  636. wpa_s->fetch_anqp_in_progress = 0;
  637. }
  638. void hs20_next_osu_icon(struct wpa_supplicant *wpa_s)
  639. {
  640. size_t i, j;
  641. wpa_printf(MSG_DEBUG, "HS 2.0: Ready to fetch next icon");
  642. for (i = 0; i < wpa_s->osu_prov_count; i++) {
  643. struct osu_provider *osu = &wpa_s->osu_prov[i];
  644. for (j = 0; j < osu->icon_count; j++) {
  645. struct osu_icon *icon = &osu->icon[j];
  646. if (icon->id || icon->failed)
  647. continue;
  648. wpa_printf(MSG_DEBUG, "HS 2.0: Try to fetch icon '%s' "
  649. "from " MACSTR, icon->filename,
  650. MAC2STR(osu->bssid));
  651. os_get_reltime(&wpa_s->osu_icon_fetch_start);
  652. if (hs20_anqp_send_req(wpa_s, osu->bssid,
  653. BIT(HS20_STYPE_ICON_REQUEST),
  654. (u8 *) icon->filename,
  655. os_strlen(icon->filename),
  656. 0) < 0) {
  657. icon->failed = 1;
  658. continue;
  659. }
  660. return;
  661. }
  662. }
  663. wpa_printf(MSG_DEBUG, "HS 2.0: No more icons to fetch");
  664. hs20_osu_fetch_done(wpa_s);
  665. }
  666. static void hs20_osu_add_prov(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  667. const u8 *osu_ssid, u8 osu_ssid_len,
  668. const u8 *pos, size_t len)
  669. {
  670. struct osu_provider *prov;
  671. const u8 *end = pos + len;
  672. u16 len2;
  673. const u8 *pos2;
  674. u8 uri_len, osu_method_len, osu_nai_len;
  675. wpa_hexdump(MSG_DEBUG, "HS 2.0: Parsing OSU Provider", pos, len);
  676. prov = os_realloc_array(wpa_s->osu_prov,
  677. wpa_s->osu_prov_count + 1,
  678. sizeof(*prov));
  679. if (prov == NULL)
  680. return;
  681. wpa_s->osu_prov = prov;
  682. prov = &prov[wpa_s->osu_prov_count];
  683. os_memset(prov, 0, sizeof(*prov));
  684. os_memcpy(prov->bssid, bss->bssid, ETH_ALEN);
  685. os_memcpy(prov->osu_ssid, osu_ssid, osu_ssid_len);
  686. prov->osu_ssid_len = osu_ssid_len;
  687. /* OSU Friendly Name Length */
  688. if (end - pos < 2) {
  689. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
  690. "Friendly Name Length");
  691. return;
  692. }
  693. len2 = WPA_GET_LE16(pos);
  694. pos += 2;
  695. if (len2 > end - pos) {
  696. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
  697. "Friendly Name Duples");
  698. return;
  699. }
  700. pos2 = pos;
  701. pos += len2;
  702. /* OSU Friendly Name Duples */
  703. while (pos - pos2 >= 4 && prov->friendly_name_count < OSU_MAX_ITEMS) {
  704. struct osu_lang_string *f;
  705. if (1 + pos2[0] > pos - pos2 || pos2[0] < 3) {
  706. wpa_printf(MSG_DEBUG, "Invalid OSU Friendly Name");
  707. break;
  708. }
  709. f = &prov->friendly_name[prov->friendly_name_count++];
  710. os_memcpy(f->lang, pos2 + 1, 3);
  711. os_memcpy(f->text, pos2 + 1 + 3, pos2[0] - 3);
  712. pos2 += 1 + pos2[0];
  713. }
  714. /* OSU Server URI */
  715. if (end - pos < 1) {
  716. wpa_printf(MSG_DEBUG,
  717. "HS 2.0: Not enough room for OSU Server URI length");
  718. return;
  719. }
  720. uri_len = *pos++;
  721. if (uri_len > end - pos) {
  722. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Server "
  723. "URI");
  724. return;
  725. }
  726. os_memcpy(prov->server_uri, pos, uri_len);
  727. pos += uri_len;
  728. /* OSU Method list */
  729. if (end - pos < 1) {
  730. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Method "
  731. "list length");
  732. return;
  733. }
  734. osu_method_len = pos[0];
  735. if (osu_method_len > end - pos - 1) {
  736. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU Method "
  737. "list");
  738. return;
  739. }
  740. pos2 = pos + 1;
  741. pos += 1 + osu_method_len;
  742. while (pos2 < pos) {
  743. if (*pos2 < 32)
  744. prov->osu_methods |= BIT(*pos2);
  745. pos2++;
  746. }
  747. /* Icons Available Length */
  748. if (end - pos < 2) {
  749. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for Icons "
  750. "Available Length");
  751. return;
  752. }
  753. len2 = WPA_GET_LE16(pos);
  754. pos += 2;
  755. if (len2 > end - pos) {
  756. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for Icons "
  757. "Available");
  758. return;
  759. }
  760. pos2 = pos;
  761. pos += len2;
  762. /* Icons Available */
  763. while (pos2 < pos) {
  764. struct osu_icon *icon = &prov->icon[prov->icon_count];
  765. u8 flen;
  766. if (2 + 2 + 3 + 1 + 1 > pos - pos2) {
  767. wpa_printf(MSG_DEBUG, "HS 2.0: Invalid Icon Metadata");
  768. break;
  769. }
  770. icon->width = WPA_GET_LE16(pos2);
  771. pos2 += 2;
  772. icon->height = WPA_GET_LE16(pos2);
  773. pos2 += 2;
  774. os_memcpy(icon->lang, pos2, 3);
  775. pos2 += 3;
  776. flen = *pos2++;
  777. if (flen > pos - pos2) {
  778. wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon Type");
  779. break;
  780. }
  781. os_memcpy(icon->icon_type, pos2, flen);
  782. pos2 += flen;
  783. if (pos - pos2 < 1) {
  784. wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon "
  785. "Filename length");
  786. break;
  787. }
  788. flen = *pos2++;
  789. if (flen > pos - pos2) {
  790. wpa_printf(MSG_DEBUG, "HS 2.0: Not room for Icon "
  791. "Filename");
  792. break;
  793. }
  794. os_memcpy(icon->filename, pos2, flen);
  795. pos2 += flen;
  796. prov->icon_count++;
  797. }
  798. /* OSU_NAI */
  799. if (end - pos < 1) {
  800. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU_NAI");
  801. return;
  802. }
  803. osu_nai_len = *pos++;
  804. if (osu_nai_len > end - pos) {
  805. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU_NAI");
  806. return;
  807. }
  808. os_memcpy(prov->osu_nai, pos, osu_nai_len);
  809. pos += osu_nai_len;
  810. /* OSU Service Description Length */
  811. if (end - pos < 2) {
  812. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
  813. "Service Description Length");
  814. return;
  815. }
  816. len2 = WPA_GET_LE16(pos);
  817. pos += 2;
  818. if (len2 > end - pos) {
  819. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for OSU "
  820. "Service Description Duples");
  821. return;
  822. }
  823. pos2 = pos;
  824. pos += len2;
  825. /* OSU Service Description Duples */
  826. while (pos - pos2 >= 4 && prov->serv_desc_count < OSU_MAX_ITEMS) {
  827. struct osu_lang_string *f;
  828. u8 descr_len;
  829. descr_len = *pos2++;
  830. if (descr_len > pos - pos2 || descr_len < 3) {
  831. wpa_printf(MSG_DEBUG, "Invalid OSU Service "
  832. "Description");
  833. break;
  834. }
  835. f = &prov->serv_desc[prov->serv_desc_count++];
  836. os_memcpy(f->lang, pos2, 3);
  837. os_memcpy(f->text, pos2 + 3, descr_len - 3);
  838. pos2 += descr_len;
  839. }
  840. wpa_printf(MSG_DEBUG, "HS 2.0: Added OSU Provider through " MACSTR,
  841. MAC2STR(bss->bssid));
  842. wpa_s->osu_prov_count++;
  843. }
  844. void hs20_osu_icon_fetch(struct wpa_supplicant *wpa_s)
  845. {
  846. struct wpa_bss *bss;
  847. struct wpabuf *prov_anqp;
  848. const u8 *pos, *end;
  849. u16 len;
  850. const u8 *osu_ssid;
  851. u8 osu_ssid_len;
  852. u8 num_providers;
  853. hs20_free_osu_prov(wpa_s);
  854. dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) {
  855. if (bss->anqp == NULL)
  856. continue;
  857. prov_anqp = bss->anqp->hs20_osu_providers_list;
  858. if (prov_anqp == NULL)
  859. continue;
  860. wpa_printf(MSG_DEBUG, "HS 2.0: Parsing OSU Providers list from "
  861. MACSTR, MAC2STR(bss->bssid));
  862. wpa_hexdump_buf(MSG_DEBUG, "HS 2.0: OSU Providers list",
  863. prov_anqp);
  864. pos = wpabuf_head(prov_anqp);
  865. end = pos + wpabuf_len(prov_anqp);
  866. /* OSU SSID */
  867. if (end - pos < 1)
  868. continue;
  869. if (1 + pos[0] > end - pos) {
  870. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for "
  871. "OSU SSID");
  872. continue;
  873. }
  874. osu_ssid_len = *pos++;
  875. if (osu_ssid_len > SSID_MAX_LEN) {
  876. wpa_printf(MSG_DEBUG, "HS 2.0: Invalid OSU SSID "
  877. "Length %u", osu_ssid_len);
  878. continue;
  879. }
  880. osu_ssid = pos;
  881. pos += osu_ssid_len;
  882. if (end - pos < 1) {
  883. wpa_printf(MSG_DEBUG, "HS 2.0: Not enough room for "
  884. "Number of OSU Providers");
  885. continue;
  886. }
  887. num_providers = *pos++;
  888. wpa_printf(MSG_DEBUG, "HS 2.0: Number of OSU Providers: %u",
  889. num_providers);
  890. /* OSU Providers */
  891. while (end - pos > 2 && num_providers > 0) {
  892. num_providers--;
  893. len = WPA_GET_LE16(pos);
  894. pos += 2;
  895. if (len > (unsigned int) (end - pos))
  896. break;
  897. hs20_osu_add_prov(wpa_s, bss, osu_ssid,
  898. osu_ssid_len, pos, len);
  899. pos += len;
  900. }
  901. if (pos != end) {
  902. wpa_printf(MSG_DEBUG, "HS 2.0: Ignored %d bytes of "
  903. "extra data after OSU Providers",
  904. (int) (end - pos));
  905. }
  906. }
  907. wpa_s->fetch_osu_icon_in_progress = 1;
  908. hs20_next_osu_icon(wpa_s);
  909. }
  910. static void hs20_osu_scan_res_handler(struct wpa_supplicant *wpa_s,
  911. struct wpa_scan_results *scan_res)
  912. {
  913. wpa_printf(MSG_DEBUG, "OSU provisioning fetch scan completed");
  914. if (!wpa_s->fetch_osu_waiting_scan) {
  915. wpa_printf(MSG_DEBUG, "OSU fetch have been canceled");
  916. return;
  917. }
  918. wpa_s->network_select = 0;
  919. wpa_s->fetch_all_anqp = 1;
  920. wpa_s->fetch_osu_info = 1;
  921. wpa_s->fetch_osu_icon_in_progress = 0;
  922. interworking_start_fetch_anqp(wpa_s);
  923. }
  924. int hs20_fetch_osu(struct wpa_supplicant *wpa_s, int skip_scan)
  925. {
  926. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  927. wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
  928. "interface disabled");
  929. return -1;
  930. }
  931. if (wpa_s->scanning) {
  932. wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
  933. "scanning");
  934. return -1;
  935. }
  936. if (wpa_s->conf->osu_dir == NULL) {
  937. wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
  938. "osu_dir not configured");
  939. return -1;
  940. }
  941. if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
  942. wpa_printf(MSG_DEBUG, "HS 2.0: Cannot start fetch_osu - "
  943. "fetch in progress (%d, %d)",
  944. wpa_s->fetch_anqp_in_progress,
  945. wpa_s->network_select);
  946. return -1;
  947. }
  948. wpa_msg(wpa_s, MSG_INFO, "Starting OSU provisioning information fetch");
  949. wpa_s->num_osu_scans = 0;
  950. wpa_s->num_prov_found = 0;
  951. if (skip_scan) {
  952. wpa_s->network_select = 0;
  953. wpa_s->fetch_all_anqp = 1;
  954. wpa_s->fetch_osu_info = 1;
  955. wpa_s->fetch_osu_icon_in_progress = 0;
  956. interworking_start_fetch_anqp(wpa_s);
  957. } else {
  958. hs20_start_osu_scan(wpa_s);
  959. }
  960. return 0;
  961. }
  962. void hs20_start_osu_scan(struct wpa_supplicant *wpa_s)
  963. {
  964. wpa_s->fetch_osu_waiting_scan = 1;
  965. wpa_s->num_osu_scans++;
  966. wpa_s->scan_req = MANUAL_SCAN_REQ;
  967. wpa_s->scan_res_handler = hs20_osu_scan_res_handler;
  968. wpa_supplicant_req_scan(wpa_s, 0, 0);
  969. }
  970. void hs20_cancel_fetch_osu(struct wpa_supplicant *wpa_s)
  971. {
  972. wpa_printf(MSG_DEBUG, "Cancel OSU fetch");
  973. interworking_stop_fetch_anqp(wpa_s);
  974. wpa_s->fetch_osu_waiting_scan = 0;
  975. wpa_s->network_select = 0;
  976. wpa_s->fetch_osu_info = 0;
  977. wpa_s->fetch_osu_icon_in_progress = 0;
  978. }
  979. void hs20_icon_fetch_failed(struct wpa_supplicant *wpa_s)
  980. {
  981. hs20_osu_icon_fetch_result(wpa_s, -1);
  982. eloop_cancel_timeout(hs20_continue_icon_fetch, wpa_s, NULL);
  983. eloop_register_timeout(0, 0, hs20_continue_icon_fetch, wpa_s, NULL);
  984. }
  985. void hs20_rx_subscription_remediation(struct wpa_supplicant *wpa_s,
  986. const char *url, u8 osu_method)
  987. {
  988. if (url)
  989. wpa_msg(wpa_s, MSG_INFO, HS20_SUBSCRIPTION_REMEDIATION "%u %s",
  990. osu_method, url);
  991. else
  992. wpa_msg(wpa_s, MSG_INFO, HS20_SUBSCRIPTION_REMEDIATION);
  993. }
  994. void hs20_rx_deauth_imminent_notice(struct wpa_supplicant *wpa_s, u8 code,
  995. u16 reauth_delay, const char *url)
  996. {
  997. if (!wpa_sm_pmf_enabled(wpa_s->wpa)) {
  998. wpa_printf(MSG_DEBUG, "HS 2.0: Ignore deauthentication imminent notice since PMF was not enabled");
  999. return;
  1000. }
  1001. wpa_msg(wpa_s, MSG_INFO, HS20_DEAUTH_IMMINENT_NOTICE "%u %u %s",
  1002. code, reauth_delay, url);
  1003. if (code == HS20_DEAUTH_REASON_CODE_BSS) {
  1004. wpa_printf(MSG_DEBUG, "HS 2.0: Add BSS to blacklist");
  1005. wpa_blacklist_add(wpa_s, wpa_s->bssid);
  1006. /* TODO: For now, disable full ESS since some drivers may not
  1007. * support disabling per BSS. */
  1008. if (wpa_s->current_ssid) {
  1009. struct os_reltime now;
  1010. os_get_reltime(&now);
  1011. if (now.sec + reauth_delay <=
  1012. wpa_s->current_ssid->disabled_until.sec)
  1013. return;
  1014. wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds (BSS)",
  1015. reauth_delay);
  1016. wpa_s->current_ssid->disabled_until.sec =
  1017. now.sec + reauth_delay;
  1018. }
  1019. }
  1020. if (code == HS20_DEAUTH_REASON_CODE_ESS && wpa_s->current_ssid) {
  1021. struct os_reltime now;
  1022. os_get_reltime(&now);
  1023. if (now.sec + reauth_delay <=
  1024. wpa_s->current_ssid->disabled_until.sec)
  1025. return;
  1026. wpa_printf(MSG_DEBUG, "HS 2.0: Disable network for %u seconds",
  1027. reauth_delay);
  1028. wpa_s->current_ssid->disabled_until.sec =
  1029. now.sec + reauth_delay;
  1030. }
  1031. }
  1032. void hs20_init(struct wpa_supplicant *wpa_s)
  1033. {
  1034. dl_list_init(&wpa_s->icon_head);
  1035. }
  1036. void hs20_deinit(struct wpa_supplicant *wpa_s)
  1037. {
  1038. eloop_cancel_timeout(hs20_continue_icon_fetch, wpa_s, NULL);
  1039. hs20_free_osu_prov(wpa_s);
  1040. if (wpa_s->icon_head.next)
  1041. hs20_del_icon(wpa_s, NULL, NULL);
  1042. }