beacon.c 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488
  1. /*
  2. * hostapd / IEEE 802.11 Management: Beacon and Probe Request/Response
  3. * Copyright (c) 2002-2004, Instant802 Networks, Inc.
  4. * Copyright (c) 2005-2006, Devicescape Software, Inc.
  5. * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
  6. *
  7. * This software may be distributed under the terms of the BSD license.
  8. * See README for more details.
  9. */
  10. #include "utils/includes.h"
  11. #ifndef CONFIG_NATIVE_WINDOWS
  12. #include "utils/common.h"
  13. #include "common/ieee802_11_defs.h"
  14. #include "common/ieee802_11_common.h"
  15. #include "common/hw_features_common.h"
  16. #include "common/wpa_ctrl.h"
  17. #include "wps/wps_defs.h"
  18. #include "p2p/p2p.h"
  19. #include "hostapd.h"
  20. #include "ieee802_11.h"
  21. #include "wpa_auth.h"
  22. #include "wmm.h"
  23. #include "ap_config.h"
  24. #include "sta_info.h"
  25. #include "p2p_hostapd.h"
  26. #include "ap_drv_ops.h"
  27. #include "beacon.h"
  28. #include "hs20.h"
  29. #include "dfs.h"
  30. #include "taxonomy.h"
  31. #ifdef NEED_AP_MLME
  32. static u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid,
  33. size_t len)
  34. {
  35. size_t i;
  36. for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) {
  37. if (hapd->conf->radio_measurements[i])
  38. break;
  39. }
  40. if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN)
  41. return eid;
  42. *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES;
  43. *eid++ = RRM_CAPABILITIES_IE_LEN;
  44. os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN);
  45. return eid + RRM_CAPABILITIES_IE_LEN;
  46. }
  47. static u8 * hostapd_eid_bss_load(struct hostapd_data *hapd, u8 *eid, size_t len)
  48. {
  49. if (len < 2 + 5)
  50. return eid;
  51. #ifdef CONFIG_TESTING_OPTIONS
  52. if (hapd->conf->bss_load_test_set) {
  53. *eid++ = WLAN_EID_BSS_LOAD;
  54. *eid++ = 5;
  55. os_memcpy(eid, hapd->conf->bss_load_test, 5);
  56. eid += 5;
  57. return eid;
  58. }
  59. #endif /* CONFIG_TESTING_OPTIONS */
  60. if (hapd->conf->bss_load_update_period) {
  61. *eid++ = WLAN_EID_BSS_LOAD;
  62. *eid++ = 5;
  63. WPA_PUT_LE16(eid, hapd->num_sta);
  64. eid += 2;
  65. *eid++ = hapd->iface->channel_utilization;
  66. WPA_PUT_LE16(eid, 0); /* no available admission capabity */
  67. eid += 2;
  68. }
  69. return eid;
  70. }
  71. static u8 ieee802_11_erp_info(struct hostapd_data *hapd)
  72. {
  73. u8 erp = 0;
  74. if (hapd->iface->current_mode == NULL ||
  75. hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
  76. return 0;
  77. if (hapd->iface->olbc)
  78. erp |= ERP_INFO_USE_PROTECTION;
  79. if (hapd->iface->num_sta_non_erp > 0) {
  80. erp |= ERP_INFO_NON_ERP_PRESENT |
  81. ERP_INFO_USE_PROTECTION;
  82. }
  83. if (hapd->iface->num_sta_no_short_preamble > 0 ||
  84. hapd->iconf->preamble == LONG_PREAMBLE)
  85. erp |= ERP_INFO_BARKER_PREAMBLE_MODE;
  86. return erp;
  87. }
  88. static u8 * hostapd_eid_ds_params(struct hostapd_data *hapd, u8 *eid)
  89. {
  90. *eid++ = WLAN_EID_DS_PARAMS;
  91. *eid++ = 1;
  92. *eid++ = hapd->iconf->channel;
  93. return eid;
  94. }
  95. static u8 * hostapd_eid_erp_info(struct hostapd_data *hapd, u8 *eid)
  96. {
  97. if (hapd->iface->current_mode == NULL ||
  98. hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211G)
  99. return eid;
  100. /* Set NonERP_present and use_protection bits if there
  101. * are any associated NonERP stations. */
  102. /* TODO: use_protection bit can be set to zero even if
  103. * there are NonERP stations present. This optimization
  104. * might be useful if NonERP stations are "quiet".
  105. * See 802.11g/D6 E-1 for recommended practice.
  106. * In addition, Non ERP present might be set, if AP detects Non ERP
  107. * operation on other APs. */
  108. /* Add ERP Information element */
  109. *eid++ = WLAN_EID_ERP_INFO;
  110. *eid++ = 1;
  111. *eid++ = ieee802_11_erp_info(hapd);
  112. return eid;
  113. }
  114. static u8 * hostapd_eid_pwr_constraint(struct hostapd_data *hapd, u8 *eid)
  115. {
  116. u8 *pos = eid;
  117. u8 local_pwr_constraint = 0;
  118. int dfs;
  119. if (hapd->iface->current_mode == NULL ||
  120. hapd->iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
  121. return eid;
  122. /* Let host drivers add this IE if DFS support is offloaded */
  123. if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD)
  124. return eid;
  125. /*
  126. * There is no DFS support and power constraint was not directly
  127. * requested by config option.
  128. */
  129. if (!hapd->iconf->ieee80211h &&
  130. hapd->iconf->local_pwr_constraint == -1)
  131. return eid;
  132. /* Check if DFS is required by regulatory. */
  133. dfs = hostapd_is_dfs_required(hapd->iface);
  134. if (dfs < 0) {
  135. wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d",
  136. dfs);
  137. dfs = 0;
  138. }
  139. if (dfs == 0 && hapd->iconf->local_pwr_constraint == -1)
  140. return eid;
  141. /*
  142. * ieee80211h (DFS) is enabled so Power Constraint element shall
  143. * be added when running on DFS channel whenever local_pwr_constraint
  144. * is configured or not. In order to meet regulations when TPC is not
  145. * implemented using a transmit power that is below the legal maximum
  146. * (including any mitigation factor) should help. In this case,
  147. * indicate 3 dB below maximum allowed transmit power.
  148. */
  149. if (hapd->iconf->local_pwr_constraint == -1)
  150. local_pwr_constraint = 3;
  151. /*
  152. * A STA that is not an AP shall use a transmit power less than or
  153. * equal to the local maximum transmit power level for the channel.
  154. * The local maximum transmit power can be calculated from the formula:
  155. * local max TX pwr = max TX pwr - local pwr constraint
  156. * Where max TX pwr is maximum transmit power level specified for
  157. * channel in Country element and local pwr constraint is specified
  158. * for channel in this Power Constraint element.
  159. */
  160. /* Element ID */
  161. *pos++ = WLAN_EID_PWR_CONSTRAINT;
  162. /* Length */
  163. *pos++ = 1;
  164. /* Local Power Constraint */
  165. if (local_pwr_constraint)
  166. *pos++ = local_pwr_constraint;
  167. else
  168. *pos++ = hapd->iconf->local_pwr_constraint;
  169. return pos;
  170. }
  171. static u8 * hostapd_eid_country_add(u8 *pos, u8 *end, int chan_spacing,
  172. struct hostapd_channel_data *start,
  173. struct hostapd_channel_data *prev)
  174. {
  175. if (end - pos < 3)
  176. return pos;
  177. /* first channel number */
  178. *pos++ = start->chan;
  179. /* number of channels */
  180. *pos++ = (prev->chan - start->chan) / chan_spacing + 1;
  181. /* maximum transmit power level */
  182. *pos++ = start->max_tx_power;
  183. return pos;
  184. }
  185. static u8 * hostapd_eid_country(struct hostapd_data *hapd, u8 *eid,
  186. int max_len)
  187. {
  188. u8 *pos = eid;
  189. u8 *end = eid + max_len;
  190. int i;
  191. struct hostapd_hw_modes *mode;
  192. struct hostapd_channel_data *start, *prev;
  193. int chan_spacing = 1;
  194. if (!hapd->iconf->ieee80211d || max_len < 6 ||
  195. hapd->iface->current_mode == NULL)
  196. return eid;
  197. *pos++ = WLAN_EID_COUNTRY;
  198. pos++; /* length will be set later */
  199. os_memcpy(pos, hapd->iconf->country, 3); /* e.g., 'US ' */
  200. pos += 3;
  201. mode = hapd->iface->current_mode;
  202. if (mode->mode == HOSTAPD_MODE_IEEE80211A)
  203. chan_spacing = 4;
  204. start = prev = NULL;
  205. for (i = 0; i < mode->num_channels; i++) {
  206. struct hostapd_channel_data *chan = &mode->channels[i];
  207. if (chan->flag & HOSTAPD_CHAN_DISABLED)
  208. continue;
  209. if (start && prev &&
  210. prev->chan + chan_spacing == chan->chan &&
  211. start->max_tx_power == chan->max_tx_power) {
  212. prev = chan;
  213. continue; /* can use same entry */
  214. }
  215. if (start && prev) {
  216. pos = hostapd_eid_country_add(pos, end, chan_spacing,
  217. start, prev);
  218. start = NULL;
  219. }
  220. /* Start new group */
  221. start = prev = chan;
  222. }
  223. if (start) {
  224. pos = hostapd_eid_country_add(pos, end, chan_spacing,
  225. start, prev);
  226. }
  227. if ((pos - eid) & 1) {
  228. if (end - pos < 1)
  229. return eid;
  230. *pos++ = 0; /* pad for 16-bit alignment */
  231. }
  232. eid[1] = (pos - eid) - 2;
  233. return pos;
  234. }
  235. static u8 * hostapd_eid_wpa(struct hostapd_data *hapd, u8 *eid, size_t len)
  236. {
  237. const u8 *ie;
  238. size_t ielen;
  239. ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen);
  240. if (ie == NULL || ielen > len)
  241. return eid;
  242. os_memcpy(eid, ie, ielen);
  243. return eid + ielen;
  244. }
  245. static u8 * hostapd_eid_csa(struct hostapd_data *hapd, u8 *eid)
  246. {
  247. #ifdef CONFIG_TESTING_OPTIONS
  248. if (hapd->iface->cs_oper_class && hapd->iconf->ecsa_ie_only)
  249. return eid;
  250. #endif /* CONFIG_TESTING_OPTIONS */
  251. if (!hapd->cs_freq_params.channel)
  252. return eid;
  253. *eid++ = WLAN_EID_CHANNEL_SWITCH;
  254. *eid++ = 3;
  255. *eid++ = hapd->cs_block_tx;
  256. *eid++ = hapd->cs_freq_params.channel;
  257. *eid++ = hapd->cs_count;
  258. return eid;
  259. }
  260. static u8 * hostapd_eid_ecsa(struct hostapd_data *hapd, u8 *eid)
  261. {
  262. if (!hapd->cs_freq_params.channel || !hapd->iface->cs_oper_class)
  263. return eid;
  264. *eid++ = WLAN_EID_EXT_CHANSWITCH_ANN;
  265. *eid++ = 4;
  266. *eid++ = hapd->cs_block_tx;
  267. *eid++ = hapd->iface->cs_oper_class;
  268. *eid++ = hapd->cs_freq_params.channel;
  269. *eid++ = hapd->cs_count;
  270. return eid;
  271. }
  272. static u8 * hostapd_eid_supported_op_classes(struct hostapd_data *hapd, u8 *eid)
  273. {
  274. u8 op_class, channel;
  275. if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) ||
  276. !hapd->iface->freq)
  277. return eid;
  278. if (ieee80211_freq_to_channel_ext(hapd->iface->freq,
  279. hapd->iconf->secondary_channel,
  280. hapd->iconf->vht_oper_chwidth,
  281. &op_class, &channel) ==
  282. NUM_HOSTAPD_MODES)
  283. return eid;
  284. *eid++ = WLAN_EID_SUPPORTED_OPERATING_CLASSES;
  285. *eid++ = 2;
  286. /* Current Operating Class */
  287. *eid++ = op_class;
  288. /* TODO: Advertise all the supported operating classes */
  289. *eid++ = 0;
  290. return eid;
  291. }
  292. #ifdef CONFIG_OWE
  293. static int hostapd_eid_owe_trans_enabled(struct hostapd_data *hapd)
  294. {
  295. return hapd->conf->owe_transition_ssid_len > 0 &&
  296. !is_zero_ether_addr(hapd->conf->owe_transition_bssid);
  297. }
  298. #endif /* CONFIG_OWE */
  299. static size_t hostapd_eid_owe_trans_len(struct hostapd_data *hapd)
  300. {
  301. #ifdef CONFIG_OWE
  302. if (!hostapd_eid_owe_trans_enabled(hapd))
  303. return 0;
  304. return 6 + ETH_ALEN + 1 + hapd->conf->owe_transition_ssid_len;
  305. #else /* CONFIG_OWE */
  306. return 0;
  307. #endif /* CONFIG_OWE */
  308. }
  309. static u8 * hostapd_eid_owe_trans(struct hostapd_data *hapd, u8 *eid,
  310. size_t len)
  311. {
  312. #ifdef CONFIG_OWE
  313. u8 *pos = eid;
  314. size_t elen;
  315. if (hapd->conf->owe_transition_ifname[0] &&
  316. !hostapd_eid_owe_trans_enabled(hapd))
  317. hostapd_owe_trans_get_info(hapd);
  318. if (!hostapd_eid_owe_trans_enabled(hapd))
  319. return pos;
  320. elen = hostapd_eid_owe_trans_len(hapd);
  321. if (len < elen) {
  322. wpa_printf(MSG_DEBUG,
  323. "OWE: Not enough room in the buffer for OWE IE");
  324. return pos;
  325. }
  326. *pos++ = WLAN_EID_VENDOR_SPECIFIC;
  327. *pos++ = elen - 2;
  328. WPA_PUT_BE24(pos, OUI_WFA);
  329. pos += 3;
  330. *pos++ = OWE_OUI_TYPE;
  331. os_memcpy(pos, hapd->conf->owe_transition_bssid, ETH_ALEN);
  332. pos += ETH_ALEN;
  333. *pos++ = hapd->conf->owe_transition_ssid_len;
  334. os_memcpy(pos, hapd->conf->owe_transition_ssid,
  335. hapd->conf->owe_transition_ssid_len);
  336. pos += hapd->conf->owe_transition_ssid_len;
  337. return pos;
  338. #else /* CONFIG_OWE */
  339. return eid;
  340. #endif /* CONFIG_OWE */
  341. }
  342. static u8 * hostapd_gen_probe_resp(struct hostapd_data *hapd,
  343. const struct ieee80211_mgmt *req,
  344. int is_p2p, size_t *resp_len)
  345. {
  346. struct ieee80211_mgmt *resp;
  347. u8 *pos, *epos, *csa_pos;
  348. size_t buflen;
  349. #define MAX_PROBERESP_LEN 768
  350. buflen = MAX_PROBERESP_LEN;
  351. #ifdef CONFIG_WPS
  352. if (hapd->wps_probe_resp_ie)
  353. buflen += wpabuf_len(hapd->wps_probe_resp_ie);
  354. #endif /* CONFIG_WPS */
  355. #ifdef CONFIG_P2P
  356. if (hapd->p2p_probe_resp_ie)
  357. buflen += wpabuf_len(hapd->p2p_probe_resp_ie);
  358. #endif /* CONFIG_P2P */
  359. #ifdef CONFIG_FST
  360. if (hapd->iface->fst_ies)
  361. buflen += wpabuf_len(hapd->iface->fst_ies);
  362. #endif /* CONFIG_FST */
  363. if (hapd->conf->vendor_elements)
  364. buflen += wpabuf_len(hapd->conf->vendor_elements);
  365. if (hapd->conf->vendor_vht) {
  366. buflen += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
  367. 2 + sizeof(struct ieee80211_vht_operation);
  368. }
  369. #ifdef CONFIG_IEEE80211AX
  370. if (hapd->iconf->ieee80211ax) {
  371. buflen += 3 + sizeof(struct ieee80211_he_capabilities) +
  372. 3 + sizeof(struct ieee80211_he_operation);
  373. }
  374. #endif /* CONFIG_IEEE80211AX */
  375. buflen += hostapd_mbo_ie_len(hapd);
  376. buflen += hostapd_eid_owe_trans_len(hapd);
  377. resp = os_zalloc(buflen);
  378. if (resp == NULL)
  379. return NULL;
  380. epos = ((u8 *) resp) + MAX_PROBERESP_LEN;
  381. resp->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  382. WLAN_FC_STYPE_PROBE_RESP);
  383. if (req)
  384. os_memcpy(resp->da, req->sa, ETH_ALEN);
  385. os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN);
  386. os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN);
  387. resp->u.probe_resp.beacon_int =
  388. host_to_le16(hapd->iconf->beacon_int);
  389. /* hardware or low-level driver will setup seq_ctrl and timestamp */
  390. resp->u.probe_resp.capab_info =
  391. host_to_le16(hostapd_own_capab_info(hapd));
  392. pos = resp->u.probe_resp.variable;
  393. *pos++ = WLAN_EID_SSID;
  394. *pos++ = hapd->conf->ssid.ssid_len;
  395. os_memcpy(pos, hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len);
  396. pos += hapd->conf->ssid.ssid_len;
  397. /* Supported rates */
  398. pos = hostapd_eid_supp_rates(hapd, pos);
  399. /* DS Params */
  400. pos = hostapd_eid_ds_params(hapd, pos);
  401. pos = hostapd_eid_country(hapd, pos, epos - pos);
  402. /* Power Constraint element */
  403. pos = hostapd_eid_pwr_constraint(hapd, pos);
  404. /* CSA IE */
  405. csa_pos = hostapd_eid_csa(hapd, pos);
  406. if (csa_pos != pos)
  407. hapd->cs_c_off_proberesp = csa_pos - (u8 *) resp - 1;
  408. pos = csa_pos;
  409. /* ERP Information element */
  410. pos = hostapd_eid_erp_info(hapd, pos);
  411. /* Extended supported rates */
  412. pos = hostapd_eid_ext_supp_rates(hapd, pos);
  413. /* RSN, MDIE, WPA */
  414. pos = hostapd_eid_wpa(hapd, pos, epos - pos);
  415. pos = hostapd_eid_bss_load(hapd, pos, epos - pos);
  416. pos = hostapd_eid_rm_enabled_capab(hapd, pos, epos - pos);
  417. /* eCSA IE */
  418. csa_pos = hostapd_eid_ecsa(hapd, pos);
  419. if (csa_pos != pos)
  420. hapd->cs_c_off_ecsa_proberesp = csa_pos - (u8 *) resp - 1;
  421. pos = csa_pos;
  422. pos = hostapd_eid_supported_op_classes(hapd, pos);
  423. #ifdef CONFIG_IEEE80211N
  424. /* Secondary Channel Offset element */
  425. /* TODO: The standard doesn't specify a position for this element. */
  426. pos = hostapd_eid_secondary_channel(hapd, pos);
  427. pos = hostapd_eid_ht_capabilities(hapd, pos);
  428. pos = hostapd_eid_ht_operation(hapd, pos);
  429. #endif /* CONFIG_IEEE80211N */
  430. pos = hostapd_eid_ext_capab(hapd, pos);
  431. pos = hostapd_eid_time_adv(hapd, pos);
  432. pos = hostapd_eid_time_zone(hapd, pos);
  433. pos = hostapd_eid_interworking(hapd, pos);
  434. pos = hostapd_eid_adv_proto(hapd, pos);
  435. pos = hostapd_eid_roaming_consortium(hapd, pos);
  436. #ifdef CONFIG_FST
  437. if (hapd->iface->fst_ies) {
  438. os_memcpy(pos, wpabuf_head(hapd->iface->fst_ies),
  439. wpabuf_len(hapd->iface->fst_ies));
  440. pos += wpabuf_len(hapd->iface->fst_ies);
  441. }
  442. #endif /* CONFIG_FST */
  443. #ifdef CONFIG_IEEE80211AC
  444. if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
  445. pos = hostapd_eid_vht_capabilities(hapd, pos, 0);
  446. pos = hostapd_eid_vht_operation(hapd, pos);
  447. pos = hostapd_eid_txpower_envelope(hapd, pos);
  448. pos = hostapd_eid_wb_chsw_wrapper(hapd, pos);
  449. }
  450. #endif /* CONFIG_IEEE80211AC */
  451. pos = hostapd_eid_fils_indic(hapd, pos, 0);
  452. #ifdef CONFIG_IEEE80211AX
  453. if (hapd->iconf->ieee80211ax) {
  454. pos = hostapd_eid_he_capab(hapd, pos);
  455. pos = hostapd_eid_he_operation(hapd, pos);
  456. }
  457. #endif /* CONFIG_IEEE80211AX */
  458. #ifdef CONFIG_IEEE80211AC
  459. if (hapd->conf->vendor_vht)
  460. pos = hostapd_eid_vendor_vht(hapd, pos);
  461. #endif /* CONFIG_IEEE80211AC */
  462. /* Wi-Fi Alliance WMM */
  463. pos = hostapd_eid_wmm(hapd, pos);
  464. #ifdef CONFIG_WPS
  465. if (hapd->conf->wps_state && hapd->wps_probe_resp_ie) {
  466. os_memcpy(pos, wpabuf_head(hapd->wps_probe_resp_ie),
  467. wpabuf_len(hapd->wps_probe_resp_ie));
  468. pos += wpabuf_len(hapd->wps_probe_resp_ie);
  469. }
  470. #endif /* CONFIG_WPS */
  471. #ifdef CONFIG_P2P
  472. if ((hapd->conf->p2p & P2P_ENABLED) && is_p2p &&
  473. hapd->p2p_probe_resp_ie) {
  474. os_memcpy(pos, wpabuf_head(hapd->p2p_probe_resp_ie),
  475. wpabuf_len(hapd->p2p_probe_resp_ie));
  476. pos += wpabuf_len(hapd->p2p_probe_resp_ie);
  477. }
  478. #endif /* CONFIG_P2P */
  479. #ifdef CONFIG_P2P_MANAGER
  480. if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
  481. P2P_MANAGE)
  482. pos = hostapd_eid_p2p_manage(hapd, pos);
  483. #endif /* CONFIG_P2P_MANAGER */
  484. #ifdef CONFIG_HS20
  485. pos = hostapd_eid_hs20_indication(hapd, pos);
  486. pos = hostapd_eid_osen(hapd, pos);
  487. #endif /* CONFIG_HS20 */
  488. pos = hostapd_eid_mbo(hapd, pos, (u8 *) resp + buflen - pos);
  489. pos = hostapd_eid_owe_trans(hapd, pos, (u8 *) resp + buflen - pos);
  490. if (hapd->conf->vendor_elements) {
  491. os_memcpy(pos, wpabuf_head(hapd->conf->vendor_elements),
  492. wpabuf_len(hapd->conf->vendor_elements));
  493. pos += wpabuf_len(hapd->conf->vendor_elements);
  494. }
  495. *resp_len = pos - (u8 *) resp;
  496. return (u8 *) resp;
  497. }
  498. enum ssid_match_result {
  499. NO_SSID_MATCH,
  500. EXACT_SSID_MATCH,
  501. WILDCARD_SSID_MATCH
  502. };
  503. static enum ssid_match_result ssid_match(struct hostapd_data *hapd,
  504. const u8 *ssid, size_t ssid_len,
  505. const u8 *ssid_list,
  506. size_t ssid_list_len)
  507. {
  508. const u8 *pos, *end;
  509. int wildcard = 0;
  510. if (ssid_len == 0)
  511. wildcard = 1;
  512. if (ssid_len == hapd->conf->ssid.ssid_len &&
  513. os_memcmp(ssid, hapd->conf->ssid.ssid, ssid_len) == 0)
  514. return EXACT_SSID_MATCH;
  515. if (ssid_list == NULL)
  516. return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
  517. pos = ssid_list;
  518. end = ssid_list + ssid_list_len;
  519. while (end - pos >= 1) {
  520. if (2 + pos[1] > end - pos)
  521. break;
  522. if (pos[1] == 0)
  523. wildcard = 1;
  524. if (pos[1] == hapd->conf->ssid.ssid_len &&
  525. os_memcmp(pos + 2, hapd->conf->ssid.ssid, pos[1]) == 0)
  526. return EXACT_SSID_MATCH;
  527. pos += 2 + pos[1];
  528. }
  529. return wildcard ? WILDCARD_SSID_MATCH : NO_SSID_MATCH;
  530. }
  531. void sta_track_expire(struct hostapd_iface *iface, int force)
  532. {
  533. struct os_reltime now;
  534. struct hostapd_sta_info *info;
  535. if (!iface->num_sta_seen)
  536. return;
  537. os_get_reltime(&now);
  538. while ((info = dl_list_first(&iface->sta_seen, struct hostapd_sta_info,
  539. list))) {
  540. if (!force &&
  541. !os_reltime_expired(&now, &info->last_seen,
  542. iface->conf->track_sta_max_age))
  543. break;
  544. force = 0;
  545. wpa_printf(MSG_MSGDUMP, "%s: Expire STA tracking entry for "
  546. MACSTR, iface->bss[0]->conf->iface,
  547. MAC2STR(info->addr));
  548. dl_list_del(&info->list);
  549. iface->num_sta_seen--;
  550. sta_track_del(info);
  551. }
  552. }
  553. static struct hostapd_sta_info * sta_track_get(struct hostapd_iface *iface,
  554. const u8 *addr)
  555. {
  556. struct hostapd_sta_info *info;
  557. dl_list_for_each(info, &iface->sta_seen, struct hostapd_sta_info, list)
  558. if (os_memcmp(addr, info->addr, ETH_ALEN) == 0)
  559. return info;
  560. return NULL;
  561. }
  562. void sta_track_add(struct hostapd_iface *iface, const u8 *addr, int ssi_signal)
  563. {
  564. struct hostapd_sta_info *info;
  565. info = sta_track_get(iface, addr);
  566. if (info) {
  567. /* Move the most recent entry to the end of the list */
  568. dl_list_del(&info->list);
  569. dl_list_add_tail(&iface->sta_seen, &info->list);
  570. os_get_reltime(&info->last_seen);
  571. info->ssi_signal = ssi_signal;
  572. return;
  573. }
  574. /* Add a new entry */
  575. info = os_zalloc(sizeof(*info));
  576. if (info == NULL)
  577. return;
  578. os_memcpy(info->addr, addr, ETH_ALEN);
  579. os_get_reltime(&info->last_seen);
  580. info->ssi_signal = ssi_signal;
  581. if (iface->num_sta_seen >= iface->conf->track_sta_max_num) {
  582. /* Expire oldest entry to make room for a new one */
  583. sta_track_expire(iface, 1);
  584. }
  585. wpa_printf(MSG_MSGDUMP, "%s: Add STA tracking entry for "
  586. MACSTR, iface->bss[0]->conf->iface, MAC2STR(addr));
  587. dl_list_add_tail(&iface->sta_seen, &info->list);
  588. iface->num_sta_seen++;
  589. }
  590. struct hostapd_data *
  591. sta_track_seen_on(struct hostapd_iface *iface, const u8 *addr,
  592. const char *ifname)
  593. {
  594. struct hapd_interfaces *interfaces = iface->interfaces;
  595. size_t i, j;
  596. for (i = 0; i < interfaces->count; i++) {
  597. struct hostapd_data *hapd = NULL;
  598. iface = interfaces->iface[i];
  599. for (j = 0; j < iface->num_bss; j++) {
  600. hapd = iface->bss[j];
  601. if (os_strcmp(ifname, hapd->conf->iface) == 0)
  602. break;
  603. hapd = NULL;
  604. }
  605. if (hapd && sta_track_get(iface, addr))
  606. return hapd;
  607. }
  608. return NULL;
  609. }
  610. #ifdef CONFIG_TAXONOMY
  611. void sta_track_claim_taxonomy_info(struct hostapd_iface *iface, const u8 *addr,
  612. struct wpabuf **probe_ie_taxonomy)
  613. {
  614. struct hostapd_sta_info *info;
  615. info = sta_track_get(iface, addr);
  616. if (!info)
  617. return;
  618. wpabuf_free(*probe_ie_taxonomy);
  619. *probe_ie_taxonomy = info->probe_ie_taxonomy;
  620. info->probe_ie_taxonomy = NULL;
  621. }
  622. #endif /* CONFIG_TAXONOMY */
  623. void handle_probe_req(struct hostapd_data *hapd,
  624. const struct ieee80211_mgmt *mgmt, size_t len,
  625. int ssi_signal)
  626. {
  627. u8 *resp;
  628. struct ieee802_11_elems elems;
  629. const u8 *ie;
  630. size_t ie_len;
  631. size_t i, resp_len;
  632. int noack;
  633. enum ssid_match_result res;
  634. int ret;
  635. u16 csa_offs[2];
  636. size_t csa_offs_len;
  637. if (len < IEEE80211_HDRLEN)
  638. return;
  639. ie = ((const u8 *) mgmt) + IEEE80211_HDRLEN;
  640. if (hapd->iconf->track_sta_max_num)
  641. sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
  642. ie_len = len - IEEE80211_HDRLEN;
  643. for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++)
  644. if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
  645. mgmt->sa, mgmt->da, mgmt->bssid,
  646. ie, ie_len, ssi_signal) > 0)
  647. return;
  648. if (!hapd->iconf->send_probe_response)
  649. return;
  650. if (ieee802_11_parse_elems(ie, ie_len, &elems, 0) == ParseFailed) {
  651. wpa_printf(MSG_DEBUG, "Could not parse ProbeReq from " MACSTR,
  652. MAC2STR(mgmt->sa));
  653. return;
  654. }
  655. if ((!elems.ssid || !elems.supp_rates)) {
  656. wpa_printf(MSG_DEBUG, "STA " MACSTR " sent probe request "
  657. "without SSID or supported rates element",
  658. MAC2STR(mgmt->sa));
  659. return;
  660. }
  661. /*
  662. * No need to reply if the Probe Request frame was sent on an adjacent
  663. * channel. IEEE Std 802.11-2012 describes this as a requirement for an
  664. * AP with dot11RadioMeasurementActivated set to true, but strictly
  665. * speaking does not allow such ignoring of Probe Request frames if
  666. * dot11RadioMeasurementActivated is false. Anyway, this can help reduce
  667. * number of unnecessary Probe Response frames for cases where the STA
  668. * is less likely to see them (Probe Request frame sent on a
  669. * neighboring, but partially overlapping, channel).
  670. */
  671. if (elems.ds_params &&
  672. hapd->iface->current_mode &&
  673. (hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G ||
  674. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211B) &&
  675. hapd->iconf->channel != elems.ds_params[0]) {
  676. wpa_printf(MSG_DEBUG,
  677. "Ignore Probe Request due to DS Params mismatch: chan=%u != ds.chan=%u",
  678. hapd->iconf->channel, elems.ds_params[0]);
  679. return;
  680. }
  681. #ifdef CONFIG_P2P
  682. if (hapd->p2p && hapd->p2p_group && elems.wps_ie) {
  683. struct wpabuf *wps;
  684. wps = ieee802_11_vendor_ie_concat(ie, ie_len, WPS_DEV_OUI_WFA);
  685. if (wps && !p2p_group_match_dev_type(hapd->p2p_group, wps)) {
  686. wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
  687. "due to mismatch with Requested Device "
  688. "Type");
  689. wpabuf_free(wps);
  690. return;
  691. }
  692. wpabuf_free(wps);
  693. }
  694. if (hapd->p2p && hapd->p2p_group && elems.p2p) {
  695. struct wpabuf *p2p;
  696. p2p = ieee802_11_vendor_ie_concat(ie, ie_len, P2P_IE_VENDOR_TYPE);
  697. if (p2p && !p2p_group_match_dev_id(hapd->p2p_group, p2p)) {
  698. wpa_printf(MSG_MSGDUMP, "P2P: Ignore Probe Request "
  699. "due to mismatch with Device ID");
  700. wpabuf_free(p2p);
  701. return;
  702. }
  703. wpabuf_free(p2p);
  704. }
  705. #endif /* CONFIG_P2P */
  706. if (hapd->conf->ignore_broadcast_ssid && elems.ssid_len == 0 &&
  707. elems.ssid_list_len == 0) {
  708. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR " for "
  709. "broadcast SSID ignored", MAC2STR(mgmt->sa));
  710. return;
  711. }
  712. #ifdef CONFIG_P2P
  713. if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
  714. elems.ssid_len == P2P_WILDCARD_SSID_LEN &&
  715. os_memcmp(elems.ssid, P2P_WILDCARD_SSID,
  716. P2P_WILDCARD_SSID_LEN) == 0) {
  717. /* Process P2P Wildcard SSID like Wildcard SSID */
  718. elems.ssid_len = 0;
  719. }
  720. #endif /* CONFIG_P2P */
  721. #ifdef CONFIG_TAXONOMY
  722. {
  723. struct sta_info *sta;
  724. struct hostapd_sta_info *info;
  725. if ((sta = ap_get_sta(hapd, mgmt->sa)) != NULL) {
  726. taxonomy_sta_info_probe_req(hapd, sta, ie, ie_len);
  727. } else if ((info = sta_track_get(hapd->iface,
  728. mgmt->sa)) != NULL) {
  729. taxonomy_hostapd_sta_info_probe_req(hapd, info,
  730. ie, ie_len);
  731. }
  732. }
  733. #endif /* CONFIG_TAXONOMY */
  734. res = ssid_match(hapd, elems.ssid, elems.ssid_len,
  735. elems.ssid_list, elems.ssid_list_len);
  736. if (res == NO_SSID_MATCH) {
  737. if (!(mgmt->da[0] & 0x01)) {
  738. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
  739. " for foreign SSID '%s' (DA " MACSTR ")%s",
  740. MAC2STR(mgmt->sa),
  741. wpa_ssid_txt(elems.ssid, elems.ssid_len),
  742. MAC2STR(mgmt->da),
  743. elems.ssid_list ? " (SSID list)" : "");
  744. }
  745. return;
  746. }
  747. #ifdef CONFIG_INTERWORKING
  748. if (hapd->conf->interworking &&
  749. elems.interworking && elems.interworking_len >= 1) {
  750. u8 ant = elems.interworking[0] & 0x0f;
  751. if (ant != INTERWORKING_ANT_WILDCARD &&
  752. ant != hapd->conf->access_network_type) {
  753. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
  754. " for mismatching ANT %u ignored",
  755. MAC2STR(mgmt->sa), ant);
  756. return;
  757. }
  758. }
  759. if (hapd->conf->interworking && elems.interworking &&
  760. (elems.interworking_len == 7 || elems.interworking_len == 9)) {
  761. const u8 *hessid;
  762. if (elems.interworking_len == 7)
  763. hessid = elems.interworking + 1;
  764. else
  765. hessid = elems.interworking + 1 + 2;
  766. if (!is_broadcast_ether_addr(hessid) &&
  767. os_memcmp(hessid, hapd->conf->hessid, ETH_ALEN) != 0) {
  768. wpa_printf(MSG_MSGDUMP, "Probe Request from " MACSTR
  769. " for mismatching HESSID " MACSTR
  770. " ignored",
  771. MAC2STR(mgmt->sa), MAC2STR(hessid));
  772. return;
  773. }
  774. }
  775. #endif /* CONFIG_INTERWORKING */
  776. #ifdef CONFIG_P2P
  777. if ((hapd->conf->p2p & P2P_GROUP_OWNER) &&
  778. supp_rates_11b_only(&elems)) {
  779. /* Indicates support for 11b rates only */
  780. wpa_printf(MSG_EXCESSIVE, "P2P: Ignore Probe Request from "
  781. MACSTR " with only 802.11b rates",
  782. MAC2STR(mgmt->sa));
  783. return;
  784. }
  785. #endif /* CONFIG_P2P */
  786. /* TODO: verify that supp_rates contains at least one matching rate
  787. * with AP configuration */
  788. if (hapd->conf->no_probe_resp_if_seen_on &&
  789. is_multicast_ether_addr(mgmt->da) &&
  790. is_multicast_ether_addr(mgmt->bssid) &&
  791. sta_track_seen_on(hapd->iface, mgmt->sa,
  792. hapd->conf->no_probe_resp_if_seen_on)) {
  793. wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
  794. " since STA has been seen on %s",
  795. hapd->conf->iface, MAC2STR(mgmt->sa),
  796. hapd->conf->no_probe_resp_if_seen_on);
  797. return;
  798. }
  799. if (hapd->conf->no_probe_resp_if_max_sta &&
  800. is_multicast_ether_addr(mgmt->da) &&
  801. is_multicast_ether_addr(mgmt->bssid) &&
  802. hapd->num_sta >= hapd->conf->max_num_sta &&
  803. !ap_get_sta(hapd, mgmt->sa)) {
  804. wpa_printf(MSG_MSGDUMP, "%s: Ignore Probe Request from " MACSTR
  805. " since no room for additional STA",
  806. hapd->conf->iface, MAC2STR(mgmt->sa));
  807. return;
  808. }
  809. #ifdef CONFIG_TESTING_OPTIONS
  810. if (hapd->iconf->ignore_probe_probability > 0.0 &&
  811. drand48() < hapd->iconf->ignore_probe_probability) {
  812. wpa_printf(MSG_INFO,
  813. "TESTING: ignoring probe request from " MACSTR,
  814. MAC2STR(mgmt->sa));
  815. return;
  816. }
  817. #endif /* CONFIG_TESTING_OPTIONS */
  818. wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, RX_PROBE_REQUEST "sa=" MACSTR
  819. " signal=%d", MAC2STR(mgmt->sa), ssi_signal);
  820. resp = hostapd_gen_probe_resp(hapd, mgmt, elems.p2p != NULL,
  821. &resp_len);
  822. if (resp == NULL)
  823. return;
  824. /*
  825. * If this is a broadcast probe request, apply no ack policy to avoid
  826. * excessive retries.
  827. */
  828. noack = !!(res == WILDCARD_SSID_MATCH &&
  829. is_broadcast_ether_addr(mgmt->da));
  830. csa_offs_len = 0;
  831. if (hapd->csa_in_progress) {
  832. if (hapd->cs_c_off_proberesp)
  833. csa_offs[csa_offs_len++] =
  834. hapd->cs_c_off_proberesp;
  835. if (hapd->cs_c_off_ecsa_proberesp)
  836. csa_offs[csa_offs_len++] =
  837. hapd->cs_c_off_ecsa_proberesp;
  838. }
  839. ret = hostapd_drv_send_mlme_csa(hapd, resp, resp_len, noack,
  840. csa_offs_len ? csa_offs : NULL,
  841. csa_offs_len);
  842. if (ret < 0)
  843. wpa_printf(MSG_INFO, "handle_probe_req: send failed");
  844. os_free(resp);
  845. wpa_printf(MSG_EXCESSIVE, "STA " MACSTR " sent probe request for %s "
  846. "SSID", MAC2STR(mgmt->sa),
  847. elems.ssid_len == 0 ? "broadcast" : "our");
  848. }
  849. static u8 * hostapd_probe_resp_offloads(struct hostapd_data *hapd,
  850. size_t *resp_len)
  851. {
  852. /* check probe response offloading caps and print warnings */
  853. if (!(hapd->iface->drv_flags & WPA_DRIVER_FLAGS_PROBE_RESP_OFFLOAD))
  854. return NULL;
  855. #ifdef CONFIG_WPS
  856. if (hapd->conf->wps_state && hapd->wps_probe_resp_ie &&
  857. (!(hapd->iface->probe_resp_offloads &
  858. (WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS |
  859. WPA_DRIVER_PROBE_RESP_OFFLOAD_WPS2))))
  860. wpa_printf(MSG_WARNING, "Device is trying to offload WPS "
  861. "Probe Response while not supporting this");
  862. #endif /* CONFIG_WPS */
  863. #ifdef CONFIG_P2P
  864. if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_probe_resp_ie &&
  865. !(hapd->iface->probe_resp_offloads &
  866. WPA_DRIVER_PROBE_RESP_OFFLOAD_P2P))
  867. wpa_printf(MSG_WARNING, "Device is trying to offload P2P "
  868. "Probe Response while not supporting this");
  869. #endif /* CONFIG_P2P */
  870. if (hapd->conf->interworking &&
  871. !(hapd->iface->probe_resp_offloads &
  872. WPA_DRIVER_PROBE_RESP_OFFLOAD_INTERWORKING))
  873. wpa_printf(MSG_WARNING, "Device is trying to offload "
  874. "Interworking Probe Response while not supporting "
  875. "this");
  876. /* Generate a Probe Response template for the non-P2P case */
  877. return hostapd_gen_probe_resp(hapd, NULL, 0, resp_len);
  878. }
  879. #endif /* NEED_AP_MLME */
  880. void sta_track_del(struct hostapd_sta_info *info)
  881. {
  882. #ifdef CONFIG_TAXONOMY
  883. wpabuf_free(info->probe_ie_taxonomy);
  884. info->probe_ie_taxonomy = NULL;
  885. #endif /* CONFIG_TAXONOMY */
  886. os_free(info);
  887. }
  888. int ieee802_11_build_ap_params(struct hostapd_data *hapd,
  889. struct wpa_driver_ap_params *params)
  890. {
  891. struct ieee80211_mgmt *head = NULL;
  892. u8 *tail = NULL;
  893. size_t head_len = 0, tail_len = 0;
  894. u8 *resp = NULL;
  895. size_t resp_len = 0;
  896. #ifdef NEED_AP_MLME
  897. u16 capab_info;
  898. u8 *pos, *tailpos, *csa_pos;
  899. #define BEACON_HEAD_BUF_SIZE 256
  900. #define BEACON_TAIL_BUF_SIZE 512
  901. head = os_zalloc(BEACON_HEAD_BUF_SIZE);
  902. tail_len = BEACON_TAIL_BUF_SIZE;
  903. #ifdef CONFIG_WPS
  904. if (hapd->conf->wps_state && hapd->wps_beacon_ie)
  905. tail_len += wpabuf_len(hapd->wps_beacon_ie);
  906. #endif /* CONFIG_WPS */
  907. #ifdef CONFIG_P2P
  908. if (hapd->p2p_beacon_ie)
  909. tail_len += wpabuf_len(hapd->p2p_beacon_ie);
  910. #endif /* CONFIG_P2P */
  911. #ifdef CONFIG_FST
  912. if (hapd->iface->fst_ies)
  913. tail_len += wpabuf_len(hapd->iface->fst_ies);
  914. #endif /* CONFIG_FST */
  915. if (hapd->conf->vendor_elements)
  916. tail_len += wpabuf_len(hapd->conf->vendor_elements);
  917. #ifdef CONFIG_IEEE80211AC
  918. if (hapd->conf->vendor_vht) {
  919. tail_len += 5 + 2 + sizeof(struct ieee80211_vht_capabilities) +
  920. 2 + sizeof(struct ieee80211_vht_operation);
  921. }
  922. #endif /* CONFIG_IEEE80211AC */
  923. #ifdef CONFIG_IEEE80211AX
  924. if (hapd->iconf->ieee80211ax) {
  925. tail_len += 3 + sizeof(struct ieee80211_he_capabilities) +
  926. 3 + sizeof(struct ieee80211_he_operation);
  927. }
  928. #endif /* CONFIG_IEEE80211AX */
  929. tail_len += hostapd_mbo_ie_len(hapd);
  930. tail_len += hostapd_eid_owe_trans_len(hapd);
  931. tailpos = tail = os_malloc(tail_len);
  932. if (head == NULL || tail == NULL) {
  933. wpa_printf(MSG_ERROR, "Failed to set beacon data");
  934. os_free(head);
  935. os_free(tail);
  936. return -1;
  937. }
  938. head->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  939. WLAN_FC_STYPE_BEACON);
  940. head->duration = host_to_le16(0);
  941. os_memset(head->da, 0xff, ETH_ALEN);
  942. os_memcpy(head->sa, hapd->own_addr, ETH_ALEN);
  943. os_memcpy(head->bssid, hapd->own_addr, ETH_ALEN);
  944. head->u.beacon.beacon_int =
  945. host_to_le16(hapd->iconf->beacon_int);
  946. /* hardware or low-level driver will setup seq_ctrl and timestamp */
  947. capab_info = hostapd_own_capab_info(hapd);
  948. head->u.beacon.capab_info = host_to_le16(capab_info);
  949. pos = &head->u.beacon.variable[0];
  950. /* SSID */
  951. *pos++ = WLAN_EID_SSID;
  952. if (hapd->conf->ignore_broadcast_ssid == 2) {
  953. /* clear the data, but keep the correct length of the SSID */
  954. *pos++ = hapd->conf->ssid.ssid_len;
  955. os_memset(pos, 0, hapd->conf->ssid.ssid_len);
  956. pos += hapd->conf->ssid.ssid_len;
  957. } else if (hapd->conf->ignore_broadcast_ssid) {
  958. *pos++ = 0; /* empty SSID */
  959. } else {
  960. *pos++ = hapd->conf->ssid.ssid_len;
  961. os_memcpy(pos, hapd->conf->ssid.ssid,
  962. hapd->conf->ssid.ssid_len);
  963. pos += hapd->conf->ssid.ssid_len;
  964. }
  965. /* Supported rates */
  966. pos = hostapd_eid_supp_rates(hapd, pos);
  967. /* DS Params */
  968. pos = hostapd_eid_ds_params(hapd, pos);
  969. head_len = pos - (u8 *) head;
  970. tailpos = hostapd_eid_country(hapd, tailpos,
  971. tail + BEACON_TAIL_BUF_SIZE - tailpos);
  972. /* Power Constraint element */
  973. tailpos = hostapd_eid_pwr_constraint(hapd, tailpos);
  974. /* CSA IE */
  975. csa_pos = hostapd_eid_csa(hapd, tailpos);
  976. if (csa_pos != tailpos)
  977. hapd->cs_c_off_beacon = csa_pos - tail - 1;
  978. tailpos = csa_pos;
  979. /* ERP Information element */
  980. tailpos = hostapd_eid_erp_info(hapd, tailpos);
  981. /* Extended supported rates */
  982. tailpos = hostapd_eid_ext_supp_rates(hapd, tailpos);
  983. /* RSN, MDIE, WPA */
  984. tailpos = hostapd_eid_wpa(hapd, tailpos, tail + BEACON_TAIL_BUF_SIZE -
  985. tailpos);
  986. tailpos = hostapd_eid_rm_enabled_capab(hapd, tailpos,
  987. tail + BEACON_TAIL_BUF_SIZE -
  988. tailpos);
  989. tailpos = hostapd_eid_bss_load(hapd, tailpos,
  990. tail + BEACON_TAIL_BUF_SIZE - tailpos);
  991. /* eCSA IE */
  992. csa_pos = hostapd_eid_ecsa(hapd, tailpos);
  993. if (csa_pos != tailpos)
  994. hapd->cs_c_off_ecsa_beacon = csa_pos - tail - 1;
  995. tailpos = csa_pos;
  996. tailpos = hostapd_eid_supported_op_classes(hapd, tailpos);
  997. #ifdef CONFIG_IEEE80211N
  998. /* Secondary Channel Offset element */
  999. /* TODO: The standard doesn't specify a position for this element. */
  1000. tailpos = hostapd_eid_secondary_channel(hapd, tailpos);
  1001. tailpos = hostapd_eid_ht_capabilities(hapd, tailpos);
  1002. tailpos = hostapd_eid_ht_operation(hapd, tailpos);
  1003. #endif /* CONFIG_IEEE80211N */
  1004. tailpos = hostapd_eid_ext_capab(hapd, tailpos);
  1005. /*
  1006. * TODO: Time Advertisement element should only be included in some
  1007. * DTIM Beacon frames.
  1008. */
  1009. tailpos = hostapd_eid_time_adv(hapd, tailpos);
  1010. tailpos = hostapd_eid_interworking(hapd, tailpos);
  1011. tailpos = hostapd_eid_adv_proto(hapd, tailpos);
  1012. tailpos = hostapd_eid_roaming_consortium(hapd, tailpos);
  1013. #ifdef CONFIG_FST
  1014. if (hapd->iface->fst_ies) {
  1015. os_memcpy(tailpos, wpabuf_head(hapd->iface->fst_ies),
  1016. wpabuf_len(hapd->iface->fst_ies));
  1017. tailpos += wpabuf_len(hapd->iface->fst_ies);
  1018. }
  1019. #endif /* CONFIG_FST */
  1020. #ifdef CONFIG_IEEE80211AC
  1021. if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) {
  1022. tailpos = hostapd_eid_vht_capabilities(hapd, tailpos, 0);
  1023. tailpos = hostapd_eid_vht_operation(hapd, tailpos);
  1024. tailpos = hostapd_eid_txpower_envelope(hapd, tailpos);
  1025. tailpos = hostapd_eid_wb_chsw_wrapper(hapd, tailpos);
  1026. }
  1027. #endif /* CONFIG_IEEE80211AC */
  1028. tailpos = hostapd_eid_fils_indic(hapd, tailpos, 0);
  1029. #ifdef CONFIG_IEEE80211AX
  1030. if (hapd->iconf->ieee80211ax) {
  1031. tailpos = hostapd_eid_he_capab(hapd, tailpos);
  1032. tailpos = hostapd_eid_he_operation(hapd, tailpos);
  1033. }
  1034. #endif /* CONFIG_IEEE80211AX */
  1035. #ifdef CONFIG_IEEE80211AC
  1036. if (hapd->conf->vendor_vht)
  1037. tailpos = hostapd_eid_vendor_vht(hapd, tailpos);
  1038. #endif /* CONFIG_IEEE80211AC */
  1039. /* Wi-Fi Alliance WMM */
  1040. tailpos = hostapd_eid_wmm(hapd, tailpos);
  1041. #ifdef CONFIG_WPS
  1042. if (hapd->conf->wps_state && hapd->wps_beacon_ie) {
  1043. os_memcpy(tailpos, wpabuf_head(hapd->wps_beacon_ie),
  1044. wpabuf_len(hapd->wps_beacon_ie));
  1045. tailpos += wpabuf_len(hapd->wps_beacon_ie);
  1046. }
  1047. #endif /* CONFIG_WPS */
  1048. #ifdef CONFIG_P2P
  1049. if ((hapd->conf->p2p & P2P_ENABLED) && hapd->p2p_beacon_ie) {
  1050. os_memcpy(tailpos, wpabuf_head(hapd->p2p_beacon_ie),
  1051. wpabuf_len(hapd->p2p_beacon_ie));
  1052. tailpos += wpabuf_len(hapd->p2p_beacon_ie);
  1053. }
  1054. #endif /* CONFIG_P2P */
  1055. #ifdef CONFIG_P2P_MANAGER
  1056. if ((hapd->conf->p2p & (P2P_MANAGE | P2P_ENABLED | P2P_GROUP_OWNER)) ==
  1057. P2P_MANAGE)
  1058. tailpos = hostapd_eid_p2p_manage(hapd, tailpos);
  1059. #endif /* CONFIG_P2P_MANAGER */
  1060. #ifdef CONFIG_HS20
  1061. tailpos = hostapd_eid_hs20_indication(hapd, tailpos);
  1062. tailpos = hostapd_eid_osen(hapd, tailpos);
  1063. #endif /* CONFIG_HS20 */
  1064. tailpos = hostapd_eid_mbo(hapd, tailpos, tail + tail_len - tailpos);
  1065. tailpos = hostapd_eid_owe_trans(hapd, tailpos,
  1066. tail + tail_len - tailpos);
  1067. if (hapd->conf->vendor_elements) {
  1068. os_memcpy(tailpos, wpabuf_head(hapd->conf->vendor_elements),
  1069. wpabuf_len(hapd->conf->vendor_elements));
  1070. tailpos += wpabuf_len(hapd->conf->vendor_elements);
  1071. }
  1072. tail_len = tailpos > tail ? tailpos - tail : 0;
  1073. resp = hostapd_probe_resp_offloads(hapd, &resp_len);
  1074. #endif /* NEED_AP_MLME */
  1075. os_memset(params, 0, sizeof(*params));
  1076. params->head = (u8 *) head;
  1077. params->head_len = head_len;
  1078. params->tail = tail;
  1079. params->tail_len = tail_len;
  1080. params->proberesp = resp;
  1081. params->proberesp_len = resp_len;
  1082. params->dtim_period = hapd->conf->dtim_period;
  1083. params->beacon_int = hapd->iconf->beacon_int;
  1084. params->basic_rates = hapd->iface->basic_rates;
  1085. params->beacon_rate = hapd->iconf->beacon_rate;
  1086. params->rate_type = hapd->iconf->rate_type;
  1087. params->ssid = hapd->conf->ssid.ssid;
  1088. params->ssid_len = hapd->conf->ssid.ssid_len;
  1089. if ((hapd->conf->wpa & (WPA_PROTO_WPA | WPA_PROTO_RSN)) ==
  1090. (WPA_PROTO_WPA | WPA_PROTO_RSN))
  1091. params->pairwise_ciphers = hapd->conf->wpa_pairwise |
  1092. hapd->conf->rsn_pairwise;
  1093. else if (hapd->conf->wpa & WPA_PROTO_RSN)
  1094. params->pairwise_ciphers = hapd->conf->rsn_pairwise;
  1095. else if (hapd->conf->wpa & WPA_PROTO_WPA)
  1096. params->pairwise_ciphers = hapd->conf->wpa_pairwise;
  1097. params->group_cipher = hapd->conf->wpa_group;
  1098. params->key_mgmt_suites = hapd->conf->wpa_key_mgmt;
  1099. params->auth_algs = hapd->conf->auth_algs;
  1100. params->wpa_version = hapd->conf->wpa;
  1101. params->privacy = hapd->conf->ssid.wep.keys_set || hapd->conf->wpa ||
  1102. (hapd->conf->ieee802_1x &&
  1103. (hapd->conf->default_wep_key_len ||
  1104. hapd->conf->individual_wep_key_len));
  1105. switch (hapd->conf->ignore_broadcast_ssid) {
  1106. case 0:
  1107. params->hide_ssid = NO_SSID_HIDING;
  1108. break;
  1109. case 1:
  1110. params->hide_ssid = HIDDEN_SSID_ZERO_LEN;
  1111. break;
  1112. case 2:
  1113. params->hide_ssid = HIDDEN_SSID_ZERO_CONTENTS;
  1114. break;
  1115. }
  1116. params->isolate = hapd->conf->isolate;
  1117. params->smps_mode = hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_MASK;
  1118. #ifdef NEED_AP_MLME
  1119. params->cts_protect = !!(ieee802_11_erp_info(hapd) &
  1120. ERP_INFO_USE_PROTECTION);
  1121. params->preamble = hapd->iface->num_sta_no_short_preamble == 0 &&
  1122. hapd->iconf->preamble == SHORT_PREAMBLE;
  1123. if (hapd->iface->current_mode &&
  1124. hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
  1125. params->short_slot_time =
  1126. hapd->iface->num_sta_no_short_slot_time > 0 ? 0 : 1;
  1127. else
  1128. params->short_slot_time = -1;
  1129. if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
  1130. params->ht_opmode = -1;
  1131. else
  1132. params->ht_opmode = hapd->iface->ht_op_mode;
  1133. #endif /* NEED_AP_MLME */
  1134. params->interworking = hapd->conf->interworking;
  1135. if (hapd->conf->interworking &&
  1136. !is_zero_ether_addr(hapd->conf->hessid))
  1137. params->hessid = hapd->conf->hessid;
  1138. params->access_network_type = hapd->conf->access_network_type;
  1139. params->ap_max_inactivity = hapd->conf->ap_max_inactivity;
  1140. #ifdef CONFIG_P2P
  1141. params->p2p_go_ctwindow = hapd->iconf->p2p_go_ctwindow;
  1142. #endif /* CONFIG_P2P */
  1143. #ifdef CONFIG_HS20
  1144. params->disable_dgaf = hapd->conf->disable_dgaf;
  1145. if (hapd->conf->osen) {
  1146. params->privacy = 1;
  1147. params->osen = 1;
  1148. }
  1149. #endif /* CONFIG_HS20 */
  1150. params->multicast_to_unicast = hapd->conf->multicast_to_unicast;
  1151. params->pbss = hapd->conf->pbss;
  1152. return 0;
  1153. }
  1154. void ieee802_11_free_ap_params(struct wpa_driver_ap_params *params)
  1155. {
  1156. os_free(params->tail);
  1157. params->tail = NULL;
  1158. os_free(params->head);
  1159. params->head = NULL;
  1160. os_free(params->proberesp);
  1161. params->proberesp = NULL;
  1162. }
  1163. int ieee802_11_set_beacon(struct hostapd_data *hapd)
  1164. {
  1165. struct wpa_driver_ap_params params;
  1166. struct hostapd_freq_params freq;
  1167. struct hostapd_iface *iface = hapd->iface;
  1168. struct hostapd_config *iconf = iface->conf;
  1169. struct wpabuf *beacon, *proberesp, *assocresp;
  1170. int res, ret = -1;
  1171. if (hapd->csa_in_progress) {
  1172. wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
  1173. return -1;
  1174. }
  1175. hapd->beacon_set_done = 1;
  1176. if (ieee802_11_build_ap_params(hapd, &params) < 0)
  1177. return -1;
  1178. if (hostapd_build_ap_extra_ies(hapd, &beacon, &proberesp, &assocresp) <
  1179. 0)
  1180. goto fail;
  1181. params.beacon_ies = beacon;
  1182. params.proberesp_ies = proberesp;
  1183. params.assocresp_ies = assocresp;
  1184. params.reenable = hapd->reenable_beacon;
  1185. hapd->reenable_beacon = 0;
  1186. if (iface->current_mode &&
  1187. hostapd_set_freq_params(&freq, iconf->hw_mode, iface->freq,
  1188. iconf->channel, iconf->ieee80211n,
  1189. iconf->ieee80211ac,
  1190. iconf->secondary_channel,
  1191. iconf->vht_oper_chwidth,
  1192. iconf->vht_oper_centr_freq_seg0_idx,
  1193. iconf->vht_oper_centr_freq_seg1_idx,
  1194. iface->current_mode->vht_capab) == 0)
  1195. params.freq = &freq;
  1196. res = hostapd_drv_set_ap(hapd, &params);
  1197. hostapd_free_ap_extra_ies(hapd, beacon, proberesp, assocresp);
  1198. if (res)
  1199. wpa_printf(MSG_ERROR, "Failed to set beacon parameters");
  1200. else
  1201. ret = 0;
  1202. fail:
  1203. ieee802_11_free_ap_params(&params);
  1204. return ret;
  1205. }
  1206. int ieee802_11_set_beacons(struct hostapd_iface *iface)
  1207. {
  1208. size_t i;
  1209. int ret = 0;
  1210. for (i = 0; i < iface->num_bss; i++) {
  1211. if (iface->bss[i]->started &&
  1212. ieee802_11_set_beacon(iface->bss[i]) < 0)
  1213. ret = -1;
  1214. }
  1215. return ret;
  1216. }
  1217. /* only update beacons if started */
  1218. int ieee802_11_update_beacons(struct hostapd_iface *iface)
  1219. {
  1220. size_t i;
  1221. int ret = 0;
  1222. for (i = 0; i < iface->num_bss; i++) {
  1223. if (iface->bss[i]->beacon_set_done && iface->bss[i]->started &&
  1224. ieee802_11_set_beacon(iface->bss[i]) < 0)
  1225. ret = -1;
  1226. }
  1227. return ret;
  1228. }
  1229. #endif /* CONFIG_NATIVE_WINDOWS */