mbo.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * wpa_supplicant - MBO
  3. *
  4. * Copyright(c) 2015 Intel Deutschland GmbH
  5. * Contact Information:
  6. * Intel Linux Wireless <ilw@linux.intel.com>
  7. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  8. *
  9. * This software may be distributed under the terms of the BSD license.
  10. * See README for more details.
  11. */
  12. #include "utils/includes.h"
  13. #include "utils/common.h"
  14. #include "common/ieee802_11_defs.h"
  15. #include "config.h"
  16. #include "wpa_supplicant_i.h"
  17. #include "driver_i.h"
  18. #include "bss.h"
  19. /* type + length + oui + oui type */
  20. #define MBO_IE_HEADER 6
  21. static int wpas_mbo_validate_non_pref_chan(u8 oper_class, u8 chan, u8 reason)
  22. {
  23. if (reason > MBO_NON_PREF_CHAN_REASON_INT_INTERFERENCE)
  24. return -1;
  25. /* Only checking the validity of the channel and oper_class */
  26. if (ieee80211_chan_to_freq(NULL, oper_class, chan) == -1)
  27. return -1;
  28. return 0;
  29. }
  30. const u8 * wpas_mbo_get_bss_attr(struct wpa_bss *bss, enum mbo_attr_id attr)
  31. {
  32. const u8 *mbo, *end;
  33. if (!bss)
  34. return NULL;
  35. mbo = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE);
  36. if (!mbo)
  37. return NULL;
  38. end = mbo + 2 + mbo[1];
  39. mbo += MBO_IE_HEADER;
  40. return get_ie(mbo, end - mbo, attr);
  41. }
  42. static void wpas_mbo_non_pref_chan_attr_body(struct wpa_supplicant *wpa_s,
  43. struct wpabuf *mbo,
  44. u8 start, u8 end)
  45. {
  46. u8 i;
  47. wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].oper_class);
  48. for (i = start; i < end; i++)
  49. wpabuf_put_u8(mbo, wpa_s->non_pref_chan[i].chan);
  50. wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].preference);
  51. wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason);
  52. wpabuf_put_u8(mbo, wpa_s->non_pref_chan[start].reason_detail);
  53. }
  54. static void wpas_mbo_non_pref_chan_attr(struct wpa_supplicant *wpa_s,
  55. struct wpabuf *mbo, u8 start, u8 end)
  56. {
  57. size_t size = end - start + 4;
  58. if (size + 2 > wpabuf_tailroom(mbo))
  59. return;
  60. wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
  61. wpabuf_put_u8(mbo, size); /* Length */
  62. wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
  63. }
  64. static void wpas_mbo_non_pref_chan_subelem_hdr(struct wpabuf *mbo, u8 len)
  65. {
  66. wpabuf_put_u8(mbo, WLAN_EID_VENDOR_SPECIFIC);
  67. wpabuf_put_u8(mbo, len); /* Length */
  68. wpabuf_put_be24(mbo, OUI_WFA);
  69. wpabuf_put_u8(mbo, MBO_ATTR_ID_NON_PREF_CHAN_REPORT);
  70. }
  71. static void wpas_mbo_non_pref_chan_subelement(struct wpa_supplicant *wpa_s,
  72. struct wpabuf *mbo, u8 start,
  73. u8 end)
  74. {
  75. size_t size = end - start + 8;
  76. if (size + 2 > wpabuf_tailroom(mbo))
  77. return;
  78. wpas_mbo_non_pref_chan_subelem_hdr(mbo, size);
  79. wpas_mbo_non_pref_chan_attr_body(wpa_s, mbo, start, end);
  80. }
  81. static void wpas_mbo_non_pref_chan_attrs(struct wpa_supplicant *wpa_s,
  82. struct wpabuf *mbo, int subelement)
  83. {
  84. u8 i, start = 0;
  85. struct wpa_mbo_non_pref_channel *start_pref;
  86. if (!wpa_s->non_pref_chan || !wpa_s->non_pref_chan_num) {
  87. if (subelement)
  88. wpas_mbo_non_pref_chan_subelem_hdr(mbo, 4);
  89. return;
  90. }
  91. start_pref = &wpa_s->non_pref_chan[0];
  92. for (i = 1; i <= wpa_s->non_pref_chan_num; i++) {
  93. struct wpa_mbo_non_pref_channel *non_pref = NULL;
  94. if (i < wpa_s->non_pref_chan_num)
  95. non_pref = &wpa_s->non_pref_chan[i];
  96. if (!non_pref ||
  97. non_pref->oper_class != start_pref->oper_class ||
  98. non_pref->reason != start_pref->reason ||
  99. non_pref->reason_detail != start_pref->reason_detail ||
  100. non_pref->preference != start_pref->preference) {
  101. if (subelement)
  102. wpas_mbo_non_pref_chan_subelement(wpa_s, mbo,
  103. start, i);
  104. else
  105. wpas_mbo_non_pref_chan_attr(wpa_s, mbo, start,
  106. i);
  107. if (!non_pref)
  108. return;
  109. start = i;
  110. start_pref = non_pref;
  111. }
  112. }
  113. }
  114. int wpas_mbo_ie(struct wpa_supplicant *wpa_s, u8 *buf, size_t len)
  115. {
  116. struct wpabuf *mbo;
  117. int res;
  118. if (len < MBO_IE_HEADER + 3 + 7)
  119. return 0;
  120. /* Leave room for the MBO IE header */
  121. mbo = wpabuf_alloc(len - MBO_IE_HEADER);
  122. if (!mbo)
  123. return 0;
  124. /* Add non-preferred channels attribute */
  125. wpas_mbo_non_pref_chan_attrs(wpa_s, mbo, 0);
  126. /*
  127. * Send cellular capabilities attribute even if AP does not advertise
  128. * cellular capabilities.
  129. */
  130. wpabuf_put_u8(mbo, MBO_ATTR_ID_CELL_DATA_CAPA);
  131. wpabuf_put_u8(mbo, 1);
  132. wpabuf_put_u8(mbo, wpa_s->conf->mbo_cell_capa);
  133. res = mbo_add_ie(buf, len, wpabuf_head_u8(mbo), wpabuf_len(mbo));
  134. if (!res)
  135. wpa_printf(MSG_ERROR, "Failed to add MBO IE");
  136. wpabuf_free(mbo);
  137. return res;
  138. }
  139. static void wpas_mbo_send_wnm_notification(struct wpa_supplicant *wpa_s)
  140. {
  141. struct wpabuf *buf;
  142. int res;
  143. /*
  144. * Send WNM-Notification Request frame only in case of a change in
  145. * non-preferred channels list during association, if the AP supports
  146. * MBO.
  147. */
  148. if (wpa_s->wpa_state != WPA_COMPLETED || !wpa_s->current_bss ||
  149. !wpa_bss_get_vendor_ie(wpa_s->current_bss, MBO_IE_VENDOR_TYPE))
  150. return;
  151. buf = wpabuf_alloc(512);
  152. if (!buf)
  153. return;
  154. wpabuf_put_u8(buf, WLAN_ACTION_WNM);
  155. wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ);
  156. wpa_s->mbo_wnm_token++;
  157. if (wpa_s->mbo_wnm_token == 0)
  158. wpa_s->mbo_wnm_token++;
  159. wpabuf_put_u8(buf, wpa_s->mbo_wnm_token);
  160. wpabuf_put_u8(buf, WLAN_EID_VENDOR_SPECIFIC); /* Type */
  161. wpas_mbo_non_pref_chan_attrs(wpa_s, buf, 1);
  162. res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid,
  163. wpa_s->own_addr, wpa_s->bssid,
  164. wpabuf_head(buf), wpabuf_len(buf), 0);
  165. if (res < 0)
  166. wpa_printf(MSG_DEBUG,
  167. "Failed to send WNM-Notification Request frame with non-preferred channel list");
  168. wpabuf_free(buf);
  169. }
  170. static int wpa_non_pref_chan_is_eq(struct wpa_mbo_non_pref_channel *a,
  171. struct wpa_mbo_non_pref_channel *b)
  172. {
  173. return a->oper_class == b->oper_class && a->chan == b->chan;
  174. }
  175. /*
  176. * wpa_non_pref_chan_cmp - Compare two channels for sorting
  177. *
  178. * In MBO IE non-preferred channel subelement we can put many channels in an
  179. * attribute if they are in the same operating class and have the same
  180. * preference, reason, and reason detail. To make it easy for the functions that
  181. * build the IE attributes and WNM Request subelements, save the channels sorted
  182. * by their oper_class, reason, and reason_detail.
  183. */
  184. static int wpa_non_pref_chan_cmp(const void *_a, const void *_b)
  185. {
  186. const struct wpa_mbo_non_pref_channel *a = _a, *b = _b;
  187. if (a->oper_class != b->oper_class)
  188. return a->oper_class - b->oper_class;
  189. if (a->reason != b->reason)
  190. return a->reason - b->reason;
  191. if (a->reason_detail != b->reason_detail)
  192. return a->reason_detail - b->reason_detail;
  193. return a->preference - b->preference;
  194. }
  195. int wpas_mbo_update_non_pref_chan(struct wpa_supplicant *wpa_s,
  196. const char *non_pref_chan)
  197. {
  198. char *cmd, *token, *context = NULL;
  199. struct wpa_mbo_non_pref_channel *chans = NULL, *tmp_chans;
  200. size_t num = 0, size = 0;
  201. unsigned i;
  202. wpa_printf(MSG_DEBUG, "MBO: Update non-preferred channels, non_pref_chan=%s",
  203. non_pref_chan ? non_pref_chan : "N/A");
  204. /*
  205. * The shortest channel configuration is 10 characters - commas, 3
  206. * colons, and 4 values that one of them (oper_class) is 2 digits or
  207. * more.
  208. */
  209. if (!non_pref_chan || os_strlen(non_pref_chan) < 10)
  210. goto update;
  211. cmd = os_strdup(non_pref_chan);
  212. if (!cmd)
  213. return -1;
  214. while ((token = str_token(cmd, " ", &context))) {
  215. struct wpa_mbo_non_pref_channel *chan;
  216. int ret;
  217. unsigned int _oper_class;
  218. unsigned int _chan;
  219. unsigned int _preference;
  220. unsigned int _reason;
  221. unsigned int _reason_detail;
  222. if (num == size) {
  223. size = size ? size * 2 : 1;
  224. tmp_chans = os_realloc_array(chans, size,
  225. sizeof(*chans));
  226. if (!tmp_chans) {
  227. wpa_printf(MSG_ERROR,
  228. "Couldn't reallocate non_pref_chan");
  229. goto fail;
  230. }
  231. chans = tmp_chans;
  232. }
  233. chan = &chans[num];
  234. ret = sscanf(token, "%u:%u:%u:%u:%u", &_oper_class,
  235. &_chan, &_preference, &_reason,
  236. &_reason_detail);
  237. if ((ret != 4 && ret != 5) ||
  238. _oper_class > 255 || _chan > 255 ||
  239. _preference > 255 || _reason > 65535 ||
  240. (ret == 5 && _reason_detail > 255)) {
  241. wpa_printf(MSG_ERROR, "Invalid non-pref chan input %s",
  242. token);
  243. goto fail;
  244. }
  245. chan->oper_class = _oper_class;
  246. chan->chan = _chan;
  247. chan->preference = _preference;
  248. chan->reason = _reason;
  249. chan->reason_detail = ret == 4 ? 0 : _reason_detail;
  250. if (wpas_mbo_validate_non_pref_chan(chan->oper_class,
  251. chan->chan, chan->reason)) {
  252. wpa_printf(MSG_ERROR,
  253. "Invalid non_pref_chan: oper class %d chan %d reason %d",
  254. chan->oper_class, chan->chan, chan->reason);
  255. goto fail;
  256. }
  257. for (i = 0; i < num; i++)
  258. if (wpa_non_pref_chan_is_eq(chan, &chans[i]))
  259. break;
  260. if (i != num) {
  261. wpa_printf(MSG_ERROR,
  262. "oper class %d chan %d is duplicated",
  263. chan->oper_class, chan->chan);
  264. goto fail;
  265. }
  266. num++;
  267. }
  268. os_free(cmd);
  269. if (chans) {
  270. qsort(chans, num, sizeof(struct wpa_mbo_non_pref_channel),
  271. wpa_non_pref_chan_cmp);
  272. }
  273. update:
  274. os_free(wpa_s->non_pref_chan);
  275. wpa_s->non_pref_chan = chans;
  276. wpa_s->non_pref_chan_num = num;
  277. wpas_mbo_send_wnm_notification(wpa_s);
  278. return 0;
  279. fail:
  280. os_free(chans);
  281. os_free(cmd);
  282. return -1;
  283. }
  284. void wpas_mbo_scan_ie(struct wpa_supplicant *wpa_s, struct wpabuf *ie)
  285. {
  286. wpabuf_put_u8(ie, WLAN_EID_VENDOR_SPECIFIC);
  287. wpabuf_put_u8(ie, 7);
  288. wpabuf_put_be24(ie, OUI_WFA);
  289. wpabuf_put_u8(ie, MBO_OUI_TYPE);
  290. wpabuf_put_u8(ie, MBO_ATTR_ID_CELL_DATA_CAPA);
  291. wpabuf_put_u8(ie, 1);
  292. wpabuf_put_u8(ie, wpa_s->conf->mbo_cell_capa);
  293. }
  294. enum chan_allowed {
  295. NOT_ALLOWED, ALLOWED
  296. };
  297. static enum chan_allowed allow_channel(struct hostapd_hw_modes *mode, u8 chan,
  298. unsigned int *flags)
  299. {
  300. int i;
  301. for (i = 0; i < mode->num_channels; i++) {
  302. if (mode->channels[i].chan == chan)
  303. break;
  304. }
  305. if (i == mode->num_channels ||
  306. (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED))
  307. return NOT_ALLOWED;
  308. if (flags)
  309. *flags = mode->channels[i].flag;
  310. return ALLOWED;
  311. }
  312. static int get_center_80mhz(struct hostapd_hw_modes *mode, u8 channel)
  313. {
  314. u8 center_channels[] = {42, 58, 106, 122, 138, 155};
  315. size_t i;
  316. if (mode->mode != HOSTAPD_MODE_IEEE80211A)
  317. return 0;
  318. for (i = 0; i < ARRAY_SIZE(center_channels); i++) {
  319. /*
  320. * In 80 MHz, the bandwidth "spans" 12 channels (e.g., 36-48),
  321. * so the center channel is 6 channels away from the start/end.
  322. */
  323. if (channel >= center_channels[i] - 6 &&
  324. channel <= center_channels[i] + 6)
  325. return center_channels[i];
  326. }
  327. return 0;
  328. }
  329. static enum chan_allowed verify_80mhz(struct hostapd_hw_modes *mode, u8 channel)
  330. {
  331. u8 center_chan;
  332. unsigned int i;
  333. center_chan = get_center_80mhz(mode, channel);
  334. if (!center_chan)
  335. return NOT_ALLOWED;
  336. /* check all the channels are available */
  337. for (i = 0; i < 4; i++) {
  338. unsigned int flags;
  339. u8 adj_chan = center_chan - 6 + i * 4;
  340. if (allow_channel(mode, adj_chan, &flags) == NOT_ALLOWED)
  341. return NOT_ALLOWED;
  342. if ((i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_70)) ||
  343. (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_50)) ||
  344. (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_30)) ||
  345. (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_10)))
  346. return NOT_ALLOWED;
  347. }
  348. return ALLOWED;
  349. }
  350. static int get_center_160mhz(struct hostapd_hw_modes *mode, u8 channel)
  351. {
  352. u8 center_channels[] = { 50, 114 };
  353. unsigned int i;
  354. if (mode->mode != HOSTAPD_MODE_IEEE80211A)
  355. return 0;
  356. for (i = 0; i < ARRAY_SIZE(center_channels); i++) {
  357. /*
  358. * In 160 MHz, the bandwidth "spans" 28 channels (e.g., 36-64),
  359. * so the center channel is 14 channels away from the start/end.
  360. */
  361. if (channel >= center_channels[i] - 14 &&
  362. channel <= center_channels[i] + 14)
  363. return center_channels[i];
  364. }
  365. return 0;
  366. }
  367. static enum chan_allowed verify_160mhz(struct hostapd_hw_modes *mode,
  368. u8 channel)
  369. {
  370. u8 center_chan;
  371. unsigned int i;
  372. center_chan = get_center_160mhz(mode, channel);
  373. if (!center_chan)
  374. return NOT_ALLOWED;
  375. /* Check all the channels are available */
  376. for (i = 0; i < 8; i++) {
  377. unsigned int flags;
  378. u8 adj_chan = center_chan - 14 + i * 4;
  379. if (allow_channel(mode, adj_chan, &flags) == NOT_ALLOWED)
  380. return NOT_ALLOWED;
  381. if ((i == 0 && !(flags & HOSTAPD_CHAN_VHT_10_150)) ||
  382. (i == 1 && !(flags & HOSTAPD_CHAN_VHT_30_130)) ||
  383. (i == 2 && !(flags & HOSTAPD_CHAN_VHT_50_110)) ||
  384. (i == 3 && !(flags & HOSTAPD_CHAN_VHT_70_90)) ||
  385. (i == 4 && !(flags & HOSTAPD_CHAN_VHT_90_70)) ||
  386. (i == 5 && !(flags & HOSTAPD_CHAN_VHT_110_50)) ||
  387. (i == 6 && !(flags & HOSTAPD_CHAN_VHT_130_30)) ||
  388. (i == 7 && !(flags & HOSTAPD_CHAN_VHT_150_10)))
  389. return NOT_ALLOWED;
  390. }
  391. return ALLOWED;
  392. }
  393. enum chan_allowed verify_channel(struct hostapd_hw_modes *mode, u8 channel,
  394. u8 bw)
  395. {
  396. unsigned int flag = 0;
  397. enum chan_allowed res, res2;
  398. res2 = res = allow_channel(mode, channel, &flag);
  399. if (bw == BW40MINUS) {
  400. if (!(flag & HOSTAPD_CHAN_HT40MINUS))
  401. return NOT_ALLOWED;
  402. res2 = allow_channel(mode, channel - 4, NULL);
  403. } else if (bw == BW40PLUS) {
  404. if (!(flag & HOSTAPD_CHAN_HT40PLUS))
  405. return NOT_ALLOWED;
  406. res2 = allow_channel(mode, channel + 4, NULL);
  407. } else if (bw == BW80) {
  408. res2 = verify_80mhz(mode, channel);
  409. } else if (bw == BW160) {
  410. res2 = verify_160mhz(mode, channel);
  411. }
  412. if (res == NOT_ALLOWED || res2 == NOT_ALLOWED)
  413. return NOT_ALLOWED;
  414. return ALLOWED;
  415. }
  416. static int wpas_op_class_supported(struct wpa_supplicant *wpa_s,
  417. const struct oper_class_map *op_class)
  418. {
  419. int chan;
  420. size_t i;
  421. struct hostapd_hw_modes *mode;
  422. mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, op_class->mode);
  423. if (!mode)
  424. return 0;
  425. if (op_class->op_class == 128 || op_class->op_class == 130) {
  426. u8 channels[] = { 42, 58, 106, 122, 138, 155 };
  427. for (i = 0; i < ARRAY_SIZE(channels); i++) {
  428. if (verify_channel(mode, channels[i], op_class->bw) ==
  429. NOT_ALLOWED)
  430. return 0;
  431. }
  432. return 1;
  433. }
  434. if (op_class->op_class == 129) {
  435. if (verify_channel(mode, 50, op_class->bw) == NOT_ALLOWED ||
  436. verify_channel(mode, 114, op_class->bw) == NOT_ALLOWED)
  437. return 0;
  438. return 1;
  439. }
  440. for (chan = op_class->min_chan; chan <= op_class->max_chan;
  441. chan += op_class->inc) {
  442. if (verify_channel(mode, chan, op_class->bw) == NOT_ALLOWED)
  443. return 0;
  444. }
  445. return 1;
  446. }
  447. int wpas_mbo_supp_op_class_ie(struct wpa_supplicant *wpa_s, int freq, u8 *pos,
  448. size_t len)
  449. {
  450. struct wpabuf *buf;
  451. u8 op, current, chan;
  452. u8 *ie_len;
  453. int res;
  454. /*
  455. * Assume 20 MHz channel for now.
  456. * TODO: Use the secondary channel and VHT channel width that will be
  457. * used after association.
  458. */
  459. if (ieee80211_freq_to_channel_ext(freq, 0, VHT_CHANWIDTH_USE_HT,
  460. &current, &chan) == NUM_HOSTAPD_MODES)
  461. return 0;
  462. /*
  463. * Need 3 bytes for EID, length, and current operating class, plus
  464. * 1 byte for every other supported operating class.
  465. */
  466. buf = wpabuf_alloc(global_op_class_size + 3);
  467. if (!buf)
  468. return 0;
  469. wpabuf_put_u8(buf, WLAN_EID_SUPPORTED_OPERATING_CLASSES);
  470. /* Will set the length later, putting a placeholder */
  471. ie_len = wpabuf_put(buf, 1);
  472. wpabuf_put_u8(buf, current);
  473. for (op = 0; global_op_class[op].op_class; op++) {
  474. if (wpas_op_class_supported(wpa_s, &global_op_class[op]))
  475. wpabuf_put_u8(buf, global_op_class[op].op_class);
  476. }
  477. *ie_len = wpabuf_len(buf) - 2;
  478. if (*ie_len < 2 || wpabuf_len(buf) > len) {
  479. wpa_printf(MSG_ERROR,
  480. "Failed to add supported operating classes IE");
  481. res = 0;
  482. } else {
  483. os_memcpy(pos, wpabuf_head(buf), wpabuf_len(buf));
  484. res = wpabuf_len(buf);
  485. wpa_hexdump_buf(MSG_DEBUG,
  486. "MBO: Added supported operating classes IE",
  487. buf);
  488. }
  489. wpabuf_free(buf);
  490. return res;
  491. }
  492. void wpas_mbo_ie_trans_req(struct wpa_supplicant *wpa_s, const u8 *mbo_ie,
  493. size_t len)
  494. {
  495. const u8 *pos, *cell_pref = NULL, *reason = NULL;
  496. u8 id, elen;
  497. u16 disallowed_sec = 0;
  498. if (len <= 4 || WPA_GET_BE24(mbo_ie) != OUI_WFA ||
  499. mbo_ie[3] != MBO_OUI_TYPE)
  500. return;
  501. pos = mbo_ie + 4;
  502. len -= 4;
  503. while (len >= 2) {
  504. id = *pos++;
  505. elen = *pos++;
  506. len -= 2;
  507. if (elen > len)
  508. goto fail;
  509. switch (id) {
  510. case MBO_ATTR_ID_CELL_DATA_PREF:
  511. if (elen != 1)
  512. goto fail;
  513. if (wpa_s->conf->mbo_cell_capa ==
  514. MBO_CELL_CAPA_AVAILABLE)
  515. cell_pref = pos;
  516. else
  517. wpa_printf(MSG_DEBUG,
  518. "MBO: Station does not support Cellular data connection");
  519. break;
  520. case MBO_ATTR_ID_TRANSITION_REASON:
  521. if (elen != 1)
  522. goto fail;
  523. reason = pos;
  524. break;
  525. case MBO_ATTR_ID_ASSOC_RETRY_DELAY:
  526. if (elen != 2)
  527. goto fail;
  528. if (wpa_s->wnm_mode &
  529. WNM_BSS_TM_REQ_BSS_TERMINATION_INCLUDED) {
  530. wpa_printf(MSG_DEBUG,
  531. "MBO: Unexpected association retry delay, BSS is terminating");
  532. goto fail;
  533. } else if (wpa_s->wnm_mode &
  534. WNM_BSS_TM_REQ_DISASSOC_IMMINENT) {
  535. disallowed_sec = WPA_GET_LE16(pos);
  536. } else {
  537. wpa_printf(MSG_DEBUG,
  538. "MBO: Association retry delay attribute not in disassoc imminent mode");
  539. }
  540. break;
  541. case MBO_ATTR_ID_AP_CAPA_IND:
  542. case MBO_ATTR_ID_NON_PREF_CHAN_REPORT:
  543. case MBO_ATTR_ID_CELL_DATA_CAPA:
  544. case MBO_ATTR_ID_ASSOC_DISALLOW:
  545. case MBO_ATTR_ID_TRANSITION_REJECT_REASON:
  546. wpa_printf(MSG_DEBUG,
  547. "MBO: Attribute %d should not be included in BTM Request frame",
  548. id);
  549. break;
  550. default:
  551. wpa_printf(MSG_DEBUG, "MBO: Unknown attribute id %u",
  552. id);
  553. return;
  554. }
  555. pos += elen;
  556. len -= elen;
  557. }
  558. if (cell_pref)
  559. wpa_msg(wpa_s, MSG_INFO, MBO_CELL_PREFERENCE "preference=%u",
  560. *cell_pref);
  561. if (reason)
  562. wpa_msg(wpa_s, MSG_INFO, MBO_TRANSITION_REASON "reason=%u",
  563. *reason);
  564. if (disallowed_sec && wpa_s->current_bss)
  565. wpa_bss_tmp_disallow(wpa_s, wpa_s->current_bss->bssid,
  566. disallowed_sec);
  567. return;
  568. fail:
  569. wpa_printf(MSG_DEBUG, "MBO IE parsing failed (id=%u len=%u left=%zu)",
  570. id, elen, len);
  571. }
  572. size_t wpas_mbo_ie_bss_trans_reject(struct wpa_supplicant *wpa_s, u8 *pos,
  573. size_t len,
  574. enum mbo_transition_reject_reason reason)
  575. {
  576. u8 reject_attr[3];
  577. reject_attr[0] = MBO_ATTR_ID_TRANSITION_REJECT_REASON;
  578. reject_attr[1] = 1;
  579. reject_attr[2] = reason;
  580. return mbo_add_ie(pos, len, reject_attr, sizeof(reject_attr));
  581. }