601-ucode_support.patch 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. From: Felix Fietkau <[email protected]>
  2. Date: Fri, 26 May 2023 10:23:59 +0200
  3. Subject: [PATCH] Add ucode support, use ucode for the main ubus object
  4. This implements vastly improved dynamic configuration reload support.
  5. It can handle configuration changes on individual wifi interfaces, as well
  6. as adding/removing interfaces.
  7. --- a/wpa_supplicant/wpa_supplicant.c
  8. +++ b/wpa_supplicant/wpa_supplicant.c
  9. @@ -1278,6 +1278,7 @@ void wpa_supplicant_set_state(struct wpa
  10. sme_sched_obss_scan(wpa_s, 0);
  11. }
  12. wpa_s->wpa_state = state;
  13. + wpas_ucode_update_state(wpa_s);
  14. #ifndef CONFIG_NO_ROBUST_AV
  15. if (state == WPA_COMPLETED && dl_list_len(&wpa_s->active_scs_ids) &&
  16. @@ -8289,6 +8290,8 @@ struct wpa_supplicant * wpa_supplicant_a
  17. }
  18. #endif /* CONFIG_P2P */
  19. + wpas_ucode_add_bss(wpa_s);
  20. +
  21. return wpa_s;
  22. }
  23. @@ -8315,6 +8318,8 @@ int wpa_supplicant_remove_iface(struct w
  24. struct wpa_supplicant *parent = wpa_s->parent;
  25. #endif /* CONFIG_MESH */
  26. + wpas_ucode_free_bss(wpa_s);
  27. +
  28. /* Remove interface from the global list of interfaces */
  29. prev = global->ifaces;
  30. if (prev == wpa_s) {
  31. @@ -8623,6 +8628,7 @@ struct wpa_global * wpa_supplicant_init(
  32. eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
  33. wpas_periodic, global, NULL);
  34. + wpas_ucode_init(global);
  35. return global;
  36. }
  37. @@ -8695,6 +8701,8 @@ void wpa_supplicant_deinit(struct wpa_gl
  38. wpas_notify_supplicant_deinitialized(global);
  39. + wpas_ucode_free();
  40. +
  41. eap_peer_unregister_methods();
  42. #ifdef CONFIG_AP
  43. eap_server_unregister_methods();
  44. --- a/wpa_supplicant/wpa_supplicant_i.h
  45. +++ b/wpa_supplicant/wpa_supplicant_i.h
  46. @@ -15,12 +15,14 @@
  47. #include "common/sae.h"
  48. #include "common/wpa_ctrl.h"
  49. #include "common/dpp.h"
  50. +#include "common/ieee802_11_common.h"
  51. #include "crypto/sha384.h"
  52. #include "eapol_supp/eapol_supp_sm.h"
  53. #include "wps/wps_defs.h"
  54. #include "config_ssid.h"
  55. #include "wmm_ac.h"
  56. #include "pasn/pasn_common.h"
  57. +#include "ucode.h"
  58. extern const char *const wpa_supplicant_version;
  59. extern const char *const wpa_supplicant_license;
  60. @@ -697,6 +699,7 @@ struct wpa_supplicant {
  61. unsigned char own_addr[ETH_ALEN];
  62. unsigned char perm_addr[ETH_ALEN];
  63. char ifname[100];
  64. + struct wpas_ucode_bss ucode;
  65. #ifdef CONFIG_MATCH_IFACE
  66. int matched;
  67. #endif /* CONFIG_MATCH_IFACE */
  68. @@ -1564,6 +1567,8 @@ struct wpa_supplicant {
  69. unsigned int enabled_4addr_mode:1;
  70. unsigned int multi_bss_support:1;
  71. unsigned int drv_authorized_port:1;
  72. +
  73. + struct multi_ap_params multi_ap;
  74. unsigned int multi_ap_ie:1;
  75. unsigned int multi_ap_backhaul:1;
  76. unsigned int multi_ap_fronthaul:1;
  77. --- a/wpa_supplicant/wps_supplicant.c
  78. +++ b/wpa_supplicant/wps_supplicant.c
  79. @@ -33,6 +33,7 @@
  80. #include "p2p/p2p.h"
  81. #include "p2p_supplicant.h"
  82. #include "wps_supplicant.h"
  83. +#include "ucode.h"
  84. #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
  85. @@ -401,6 +402,8 @@ static int wpa_supplicant_wps_cred(void
  86. wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
  87. cred->cred_attr, cred->cred_attr_len);
  88. + wpas_ucode_wps_complete(wpa_s, cred);
  89. +
  90. if (wpa_s->conf->wps_cred_processing == 1)
  91. return 0;
  92. --- a/hostapd/Makefile
  93. +++ b/hostapd/Makefile
  94. @@ -169,9 +169,21 @@ OBJS += ../src/eapol_auth/eapol_auth_sm.
  95. ifdef CONFIG_UBUS
  96. CFLAGS += -DUBUS_SUPPORT
  97. -OBJS += ../src/utils/uloop.o
  98. OBJS += ../src/ap/ubus.o
  99. -LIBS += -lubox -lubus
  100. +LIBS += -lubus
  101. +NEED_ULOOP:=y
  102. +endif
  103. +
  104. +ifdef CONFIG_UCODE
  105. +CFLAGS += -DUCODE_SUPPORT
  106. +OBJS += ../src/utils/ucode.o
  107. +OBJS += ../src/ap/ucode.o
  108. +NEED_ULOOP:=y
  109. +endif
  110. +
  111. +ifdef NEED_ULOOP
  112. +OBJS += ../src/utils/uloop.o
  113. +LIBS += -lubox
  114. endif
  115. ifdef CONFIG_CODE_COVERAGE
  116. --- a/hostapd/ctrl_iface.c
  117. +++ b/hostapd/ctrl_iface.c
  118. @@ -6061,6 +6061,7 @@ try_again:
  119. return -1;
  120. }
  121. + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
  122. wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
  123. return 0;
  124. @@ -6162,6 +6163,7 @@ fail:
  125. os_free(fname);
  126. interface->global_ctrl_sock = s;
  127. + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
  128. eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
  129. interface, NULL);
  130. --- a/hostapd/main.c
  131. +++ b/hostapd/main.c
  132. @@ -1074,6 +1074,7 @@ int main(int argc, char *argv[])
  133. }
  134. hostapd_global_ctrl_iface_init(&interfaces);
  135. + hostapd_ucode_init(&interfaces);
  136. if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
  137. wpa_printf(MSG_ERROR, "Failed to start eloop");
  138. @@ -1083,6 +1084,7 @@ int main(int argc, char *argv[])
  139. ret = 0;
  140. out:
  141. + hostapd_ucode_free();
  142. hostapd_global_ctrl_iface_deinit(&interfaces);
  143. /* Deinitialize all interfaces */
  144. for (i = 0; i < interfaces.count; i++) {
  145. --- a/src/ap/ap_drv_ops.h
  146. +++ b/src/ap/ap_drv_ops.h
  147. @@ -410,6 +410,23 @@ static inline int hostapd_drv_stop_ap(st
  148. return hapd->driver->stop_ap(hapd->drv_priv, link_id);
  149. }
  150. +static inline int hostapd_drv_if_rename(struct hostapd_data *hapd,
  151. + enum wpa_driver_if_type type,
  152. + const char *ifname,
  153. + const char *new_name)
  154. +{
  155. + if (!hapd->driver || !hapd->driver->if_rename || !hapd->drv_priv)
  156. + return -1;
  157. + return hapd->driver->if_rename(hapd->drv_priv, type, ifname, new_name);
  158. +}
  159. +
  160. +static inline int hostapd_drv_set_first_bss(struct hostapd_data *hapd)
  161. +{
  162. + if (!hapd->driver || !hapd->driver->set_first_bss || !hapd->drv_priv)
  163. + return 0;
  164. + return hapd->driver->set_first_bss(hapd->drv_priv);
  165. +}
  166. +
  167. static inline int hostapd_drv_channel_info(struct hostapd_data *hapd,
  168. struct wpa_channel_info *ci)
  169. {
  170. --- a/src/ap/hostapd.c
  171. +++ b/src/ap/hostapd.c
  172. @@ -259,6 +259,8 @@ int hostapd_reload_config(struct hostapd
  173. struct hostapd_config *newconf, *oldconf;
  174. size_t j;
  175. + hostapd_ucode_reload_bss(hapd);
  176. +
  177. if (iface->config_fname == NULL) {
  178. /* Only in-memory config in use - assume it has been updated */
  179. hostapd_clear_old(iface);
  180. @@ -479,6 +481,7 @@ void hostapd_free_hapd_data(struct hosta
  181. hapd->beacon_set_done = 0;
  182. wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
  183. + hostapd_ucode_free_bss(hapd);
  184. hostapd_ubus_free_bss(hapd);
  185. accounting_deinit(hapd);
  186. hostapd_deinit_wpa(hapd);
  187. @@ -625,7 +628,7 @@ void hostapd_free_hapd_data(struct hosta
  188. * If the BSS being removed is the first link, the next link becomes the first
  189. * link.
  190. */
  191. -static void hostapd_bss_link_deinit(struct hostapd_data *hapd)
  192. +void hostapd_bss_link_deinit(struct hostapd_data *hapd)
  193. {
  194. #ifdef CONFIG_IEEE80211BE
  195. int i;
  196. @@ -737,6 +740,7 @@ void hostapd_cleanup_iface_partial(struc
  197. static void hostapd_cleanup_iface(struct hostapd_iface *iface)
  198. {
  199. wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
  200. + hostapd_ucode_free_iface(iface);
  201. eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
  202. NULL);
  203. @@ -1326,6 +1330,7 @@ static int hostapd_start_beacon(struct h
  204. hapd->driver->set_operstate(hapd->drv_priv, 1);
  205. hostapd_ubus_add_bss(hapd);
  206. + hostapd_ucode_add_bss(hapd);
  207. return 0;
  208. }
  209. @@ -1401,8 +1406,7 @@ static int hostapd_bss_radius_init(struc
  210. * initialized. Most of the modules that are initialized here will be
  211. * deinitialized in hostapd_cleanup().
  212. */
  213. -static int hostapd_setup_bss(struct hostapd_data *hapd, int first,
  214. - bool start_beacon)
  215. +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon)
  216. {
  217. struct hostapd_bss_config *conf = hapd->conf;
  218. u8 ssid[SSID_MAX_LEN + 1];
  219. @@ -1434,12 +1438,17 @@ static int hostapd_setup_bss(struct host
  220. if (!first || first == -1) {
  221. u8 *addr = hapd->own_addr;
  222. + bool use_existing = first == -1;
  223. +#ifdef CONFIG_IEEE80211BE
  224. + if (hapd->conf->mld_ap)
  225. + addr = NULL;
  226. +#endif /* CONFIG_IEEE80211BE */
  227. if (!is_zero_ether_addr(conf->bssid)) {
  228. /* Allocate the configured BSSID. */
  229. os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
  230. - if (hostapd_mac_comp(hapd->own_addr,
  231. + if (0 && hostapd_mac_comp(hapd->own_addr,
  232. hapd->iface->bss[0]->own_addr) ==
  233. 0) {
  234. wpa_printf(MSG_ERROR, "BSS '%s' may not have "
  235. @@ -1469,6 +1478,7 @@ static int hostapd_setup_bss(struct host
  236. hapd->mld_link_id, hapd->conf->iface);
  237. goto setup_mld;
  238. }
  239. + use_existing = true;
  240. }
  241. #endif /* CONFIG_IEEE80211BE */
  242. @@ -1477,7 +1487,7 @@ static int hostapd_setup_bss(struct host
  243. conf->iface, addr, hapd,
  244. &hapd->drv_priv, force_ifname, if_addr,
  245. conf->bridge[0] ? conf->bridge : NULL,
  246. - first == -1)) {
  247. + use_existing)) {
  248. wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
  249. MACSTR ")", MAC2STR(hapd->own_addr));
  250. hapd->interface_added = 0;
  251. @@ -1500,7 +1510,7 @@ static int hostapd_setup_bss(struct host
  252. #ifdef CONFIG_IEEE80211BE
  253. setup_mld:
  254. - if (hapd->conf->mld_ap && !first) {
  255. + if (hapd->conf->mld_ap && first != 1) {
  256. wpa_printf(MSG_DEBUG,
  257. "MLD: Set link_id=%u, mld_addr=" MACSTR
  258. ", own_addr=" MACSTR,
  259. @@ -1518,6 +1528,8 @@ setup_mld:
  260. }
  261. #endif /* CONFIG_IEEE80211BE */
  262. + hostapd_ucode_create_bss(hapd);
  263. +
  264. if (conf->wmm_enabled < 0)
  265. conf->wmm_enabled = hapd->iconf->ieee80211n |
  266. hapd->iconf->ieee80211ax;
  267. @@ -1843,7 +1855,7 @@ int hostapd_set_acl(struct hostapd_data
  268. }
  269. -static int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd)
  270. +int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd)
  271. {
  272. #ifdef CONFIG_IEEE80211BE
  273. int ret;
  274. @@ -2516,7 +2528,7 @@ static int hostapd_owe_iface_iter2(struc
  275. #endif /* CONFIG_OWE */
  276. -static void hostapd_owe_update_trans(struct hostapd_iface *iface)
  277. +void hostapd_owe_update_trans(struct hostapd_iface *iface)
  278. {
  279. #ifdef CONFIG_OWE
  280. /* Check whether the enabled BSS can complete OWE transition mode
  281. @@ -2986,7 +2998,7 @@ hostapd_alloc_bss_data(struct hostapd_if
  282. }
  283. -static void hostapd_bss_deinit(struct hostapd_data *hapd)
  284. +void hostapd_bss_deinit(struct hostapd_data *hapd)
  285. {
  286. if (!hapd)
  287. return;
  288. @@ -3194,7 +3206,7 @@ fail:
  289. }
  290. -static void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces)
  291. +void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces)
  292. {
  293. #ifdef CONFIG_IEEE80211BE
  294. struct hostapd_mld *mld, **all_mld;
  295. @@ -4074,7 +4086,8 @@ int hostapd_remove_iface(struct hapd_int
  296. hapd_iface = interfaces->iface[i];
  297. if (hapd_iface == NULL)
  298. return -1;
  299. - if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  300. + if (!os_strcmp(hapd_iface->phy, buf) ||
  301. + !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  302. wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
  303. hapd_iface->driver_ap_teardown =
  304. !!(hapd_iface->drv_flags &
  305. --- a/src/ap/hostapd.h
  306. +++ b/src/ap/hostapd.h
  307. @@ -19,6 +19,7 @@
  308. #include "ap_config.h"
  309. #include "drivers/driver.h"
  310. #include "ubus.h"
  311. +#include "ucode.h"
  312. #define OCE_STA_CFON_ENABLED(hapd) \
  313. ((hapd->conf->oce & OCE_STA_CFON) && \
  314. @@ -52,6 +53,10 @@ struct hapd_interfaces {
  315. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  316. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  317. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  318. + int (*ctrl_iface_recv)(struct hostapd_data *hapd,
  319. + char *buf, char *reply, int reply_size,
  320. + struct sockaddr_storage *from,
  321. + socklen_t fromlen);
  322. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  323. int (*cb)(struct hostapd_iface *iface,
  324. void *ctx), void *ctx);
  325. @@ -208,6 +213,7 @@ struct hostapd_data {
  326. struct hostapd_config *iconf;
  327. struct hostapd_bss_config *conf;
  328. struct hostapd_ubus_bss ubus;
  329. + struct hostapd_ucode_bss ucode;
  330. int interface_added; /* virtual interface added for this BSS */
  331. unsigned int started:1;
  332. unsigned int disabled:1;
  333. @@ -577,6 +583,7 @@ struct hostapd_mld {
  334. */
  335. struct hostapd_iface {
  336. struct hapd_interfaces *interfaces;
  337. + struct hostapd_ucode_iface ucode;
  338. void *owner;
  339. char *config_fname;
  340. struct hostapd_config *conf;
  341. @@ -787,11 +794,16 @@ struct hostapd_iface * hostapd_init(stru
  342. struct hostapd_iface *
  343. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  344. const char *config_fname, int debug);
  345. +int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd);
  346. +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon);
  347. +void hostapd_bss_link_deinit(struct hostapd_data *hapd);
  348. +void hostapd_bss_deinit(struct hostapd_data *hapd);
  349. void hostapd_bss_setup_multi_link(struct hostapd_data *hapd,
  350. struct hapd_interfaces *interfaces);
  351. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  352. int reassoc);
  353. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  354. +void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces);
  355. int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
  356. int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
  357. int hostapd_reload_bss_only(struct hostapd_data *bss);
  358. @@ -817,6 +829,7 @@ hostapd_switch_channel_fallback(struct h
  359. void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
  360. void hostapd_periodic_iface(struct hostapd_iface *iface);
  361. int hostapd_owe_trans_get_info(struct hostapd_data *hapd);
  362. +void hostapd_owe_update_trans(struct hostapd_iface *iface);;
  363. void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx);
  364. void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap);
  365. --- a/src/ap/ieee802_11.c
  366. +++ b/src/ap/ieee802_11.c
  367. @@ -659,12 +659,17 @@ const char * sae_get_password(struct hos
  368. struct sae_pt **s_pt,
  369. const struct sae_pk **s_pk)
  370. {
  371. + struct hostapd_bss_config *conf = hapd->conf;
  372. + struct hostapd_ssid *ssid = &conf->ssid;
  373. const char *password = NULL;
  374. - struct sae_password_entry *pw;
  375. + struct sae_password_entry *pw = NULL;
  376. struct sae_pt *pt = NULL;
  377. const struct sae_pk *pk = NULL;
  378. struct hostapd_sta_wpa_psk_short *psk = NULL;
  379. + if (sta && sta->use_sta_psk)
  380. + goto use_sta_psk;
  381. +
  382. /* With sae_track_password functionality enabled, try to first find the
  383. * next viable wildcard-address password if a password identifier was
  384. * not used. Select an wildcard-addr entry if the STA is known to have
  385. @@ -725,12 +730,30 @@ const char * sae_get_password(struct hos
  386. pt = hapd->conf->ssid.pt;
  387. }
  388. +use_sta_psk:
  389. if (!password && sta && !rx_id) {
  390. for (psk = sta->psk; psk; psk = psk->next) {
  391. - if (psk->is_passphrase) {
  392. - password = psk->passphrase;
  393. + if (!psk->is_passphrase)
  394. + continue;
  395. +
  396. + password = psk->passphrase;
  397. + if (!sta->use_sta_psk)
  398. + break;
  399. +
  400. +#ifdef CONFIG_SAE
  401. + if (sta->sae_pt) {
  402. + pt = sta->sae_pt;
  403. break;
  404. }
  405. +
  406. + pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
  407. + ssid->ssid_len,
  408. + (const u8 *) password,
  409. + os_strlen(password),
  410. + NULL);
  411. + sta->sae_pt = pt;
  412. + break;
  413. +#endif
  414. }
  415. }
  416. @@ -3489,6 +3512,12 @@ static void handle_auth(struct hostapd_d
  417. goto fail;
  418. }
  419. + res = hostapd_ucode_sta_auth(hapd, sta);
  420. + if (res) {
  421. + resp = res;
  422. + goto fail;
  423. + }
  424. +
  425. sta->flags &= ~WLAN_STA_PREAUTH;
  426. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  427. --- a/src/ap/sta_info.c
  428. +++ b/src/ap/sta_info.c
  429. @@ -477,6 +477,11 @@ void ap_free_sta(struct hostapd_data *ha
  430. forced_memzero(sta->last_tk, WPA_TK_MAX_LEN);
  431. #endif /* CONFIG_TESTING_OPTIONS */
  432. +#ifdef CONFIG_SAE
  433. + if (sta->sae_pt)
  434. + sae_deinit_pt(sta->sae_pt);
  435. +#endif
  436. +
  437. os_free(sta);
  438. }
  439. @@ -1576,6 +1581,8 @@ void ap_sta_set_authorized_event(struct
  440. #endif /* CONFIG_P2P */
  441. const u8 *ip_ptr = NULL;
  442. + if (authorized)
  443. + hostapd_ucode_sta_connected(hapd, sta);
  444. #ifdef CONFIG_P2P
  445. if (hapd->p2p_group == NULL) {
  446. if (sta->p2p_ie != NULL &&
  447. --- a/src/ap/sta_info.h
  448. +++ b/src/ap/sta_info.h
  449. @@ -180,6 +180,9 @@ struct sta_info {
  450. int vlan_id_bound; /* updated by ap_sta_bind_vlan() */
  451. /* PSKs from RADIUS authentication server */
  452. struct hostapd_sta_wpa_psk_short *psk;
  453. + struct sae_pt *sae_pt;
  454. + int use_sta_psk;
  455. + int psk_idx;
  456. char *identity; /* User-Name from RADIUS */
  457. char *radius_cui; /* Chargeable-User-Identity from RADIUS */
  458. --- a/src/ap/wpa_auth_glue.c
  459. +++ b/src/ap/wpa_auth_glue.c
  460. @@ -392,6 +392,7 @@ static const u8 * hostapd_wpa_auth_get_p
  461. struct sta_info *sta = ap_get_sta(hapd, addr);
  462. const u8 *psk;
  463. + sta->psk_idx = 0;
  464. if (vlan_id)
  465. *vlan_id = 0;
  466. if (psk_len)
  467. @@ -442,13 +443,18 @@ static const u8 * hostapd_wpa_auth_get_p
  468. * returned psk which should not be returned again.
  469. * logic list (all hostapd_get_psk; all sta->psk)
  470. */
  471. + if (sta && sta->use_sta_psk)
  472. + psk = NULL;
  473. if (sta && sta->psk && !psk) {
  474. struct hostapd_sta_wpa_psk_short *pos;
  475. + int psk_idx = 1;
  476. if (vlan_id)
  477. *vlan_id = 0;
  478. psk = sta->psk->psk;
  479. - for (pos = sta->psk; pos; pos = pos->next) {
  480. + if (vlan_id)
  481. + sta->psk_idx = psk_idx;
  482. + for (pos = sta->psk; pos; pos = pos->next, psk_idx++) {
  483. if (pos->is_passphrase) {
  484. if (pbkdf2_sha1(pos->passphrase,
  485. hapd->conf->ssid.ssid,
  486. @@ -462,9 +468,13 @@ static const u8 * hostapd_wpa_auth_get_p
  487. }
  488. if (pos->psk == prev_psk) {
  489. psk = pos->next ? pos->next->psk : NULL;
  490. + if (vlan_id)
  491. + sta->psk_idx = psk_idx + 1;
  492. break;
  493. }
  494. }
  495. + if (vlan_id && !psk)
  496. + sta->psk_idx = 0;
  497. }
  498. return psk;
  499. }
  500. --- a/src/drivers/driver.h
  501. +++ b/src/drivers/driver.h
  502. @@ -4072,6 +4072,25 @@ struct wpa_driver_ops {
  503. const char *ifname);
  504. /**
  505. + * if_rename - Rename a virtual interface
  506. + * @priv: Private driver interface data
  507. + * @type: Interface type
  508. + * @ifname: Interface name of the virtual interface to be renamed
  509. + * (NULL when renaming the AP BSS interface)
  510. + * @new_name: New interface name of the virtual interface
  511. + * Returns: 0 on success, -1 on failure
  512. + */
  513. + int (*if_rename)(void *priv, enum wpa_driver_if_type type,
  514. + const char *ifname, const char *new_name);
  515. +
  516. + /**
  517. + * set_first_bss - Make a virtual interface the first (primary) bss
  518. + * @priv: Private driver interface data
  519. + * Returns: 0 on success, -1 on failure
  520. + */
  521. + int (*set_first_bss)(void *priv);
  522. +
  523. + /**
  524. * set_sta_vlan - Bind a station into a specific interface (AP only)
  525. * @priv: Private driver interface data
  526. * @ifname: Interface (main or virtual BSS or VLAN)
  527. @@ -6901,6 +6920,7 @@ union wpa_event_data {
  528. /**
  529. * struct ch_switch
  530. + * @count: Count until channel switch activates
  531. * @freq: Frequency of new channel in MHz
  532. * @ht_enabled: Whether this is an HT channel
  533. * @ch_offset: Secondary channel offset
  534. @@ -6911,6 +6931,7 @@ union wpa_event_data {
  535. * @punct_bitmap: Puncturing bitmap
  536. */
  537. struct ch_switch {
  538. + int count;
  539. int freq;
  540. int ht_enabled;
  541. int ch_offset;
  542. --- a/src/drivers/driver_nl80211.c
  543. +++ b/src/drivers/driver_nl80211.c
  544. @@ -77,6 +77,16 @@ enum nlmsgerr_attrs {
  545. #endif /* ANDROID */
  546. +static void handle_nl_debug_hook(struct nl_msg *msg, int tx)
  547. +{
  548. + const struct nlmsghdr *nlh;
  549. +
  550. + if (!wpa_netlink_hook)
  551. + return;
  552. +
  553. + nlh = nlmsg_hdr(msg);
  554. + wpa_netlink_hook(tx, nlh, nlh->nlmsg_len);
  555. +}
  556. static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
  557. {
  558. @@ -437,6 +447,11 @@ static int no_seq_check(struct nl_msg *m
  559. return NL_OK;
  560. }
  561. +static int debug_handler(struct nl_msg *msg, void *arg)
  562. +{
  563. + handle_nl_debug_hook(msg, 0);
  564. + return NL_OK;
  565. +}
  566. static void nl80211_nlmsg_clear(struct nl_msg *msg)
  567. {
  568. @@ -511,6 +526,8 @@ int send_and_recv_glb(struct nl80211_glo
  569. if (!msg)
  570. return -ENOMEM;
  571. + handle_nl_debug_hook(msg, 1);
  572. +
  573. err.err = -ENOMEM;
  574. s_nl_cb = nl_socket_get_cb(nl_handle);
  575. @@ -552,6 +569,7 @@ int send_and_recv_glb(struct nl80211_glo
  576. err.err_info = err_info;
  577. err.drv = drv;
  578. + nl_cb_set(cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  579. nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
  580. nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err.err);
  581. if (ack_handler_custom) {
  582. @@ -973,6 +991,7 @@ nl80211_get_wiphy_data_ap(struct i802_bs
  583. os_free(w);
  584. return NULL;
  585. }
  586. + nl_cb_set(w->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  587. nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  588. no_seq_check, NULL);
  589. nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  590. @@ -1401,7 +1420,7 @@ static void wpa_driver_nl80211_event_rtm
  591. }
  592. wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
  593. namebuf, ifname);
  594. - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
  595. + if (drv->first_bss->ifindex != ifi->ifi_index) {
  596. wpa_printf(MSG_DEBUG,
  597. "nl80211: Not the main interface (%s) - do not indicate interface down",
  598. drv->first_bss->ifname);
  599. @@ -1437,7 +1456,7 @@ static void wpa_driver_nl80211_event_rtm
  600. }
  601. wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
  602. namebuf, ifname);
  603. - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
  604. + if (drv->first_bss->ifindex != ifi->ifi_index) {
  605. wpa_printf(MSG_DEBUG,
  606. "nl80211: Not the main interface (%s) - do not indicate interface up",
  607. drv->first_bss->ifname);
  608. @@ -2130,6 +2149,7 @@ static int wpa_driver_nl80211_init_nl_gl
  609. genl_family_put(family);
  610. nl_cache_free(cache);
  611. + nl_cb_set(global->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  612. nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  613. no_seq_check, NULL);
  614. nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  615. @@ -2300,6 +2320,7 @@ static int nl80211_init_bss(struct i802_
  616. if (!bss->nl_cb)
  617. return -1;
  618. + nl_cb_set(bss->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  619. nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  620. no_seq_check, NULL);
  621. nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  622. @@ -8854,6 +8875,7 @@ static void *i802_init(struct hostapd_da
  623. char master_ifname[IFNAMSIZ];
  624. int ifindex, br_ifindex = 0;
  625. int br_added = 0;
  626. + int err;
  627. bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
  628. params->global_priv, 1,
  629. @@ -8914,21 +8936,17 @@ static void *i802_init(struct hostapd_da
  630. (params->num_bridge == 0 || !params->bridge[0]))
  631. add_ifidx(drv, br_ifindex, drv->ifindex);
  632. - if (bss->added_if_into_bridge || bss->already_in_bridge) {
  633. - int err;
  634. -
  635. - drv->rtnl_sk = nl_socket_alloc();
  636. - if (drv->rtnl_sk == NULL) {
  637. - wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  638. - goto failed;
  639. - }
  640. + drv->rtnl_sk = nl_socket_alloc();
  641. + if (drv->rtnl_sk == NULL) {
  642. + wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  643. + goto failed;
  644. + }
  645. - err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  646. - if (err) {
  647. - wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  648. - nl_geterror(err));
  649. - goto failed;
  650. - }
  651. + err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  652. + if (err) {
  653. + wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  654. + nl_geterror(err));
  655. + goto failed;
  656. }
  657. if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
  658. @@ -9310,6 +9328,50 @@ static int wpa_driver_nl80211_if_remove(
  659. return 0;
  660. }
  661. +static int wpa_driver_nl80211_if_rename(struct i802_bss *bss,
  662. + enum wpa_driver_if_type type,
  663. + const char *ifname, const char *new_name)
  664. +{
  665. + struct wpa_driver_nl80211_data *drv = bss->drv;
  666. + struct ifinfomsg ifi = {
  667. + .ifi_family = AF_UNSPEC,
  668. + .ifi_index = bss->ifindex,
  669. + };
  670. + struct nl_msg *msg;
  671. + int res = -ENOMEM;
  672. +
  673. + if (ifname)
  674. + ifi.ifi_index = if_nametoindex(ifname);
  675. +
  676. + msg = nlmsg_alloc_simple(RTM_SETLINK, 0);
  677. + if (!msg)
  678. + return res;
  679. +
  680. + if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0)
  681. + goto out;
  682. +
  683. + if (nla_put_string(msg, IFLA_IFNAME, new_name))
  684. + goto out;
  685. +
  686. + res = nl_send_auto_complete(drv->rtnl_sk, msg);
  687. + if (res < 0)
  688. + goto out;
  689. +
  690. + res = nl_wait_for_ack(drv->rtnl_sk);
  691. + if (res) {
  692. + wpa_printf(MSG_INFO,
  693. + "nl80211: Renaming device %s to %s failed: %s",
  694. + ifname ? ifname : bss->ifname, new_name, nl_geterror(res));
  695. + goto out;
  696. + }
  697. +
  698. + if (type == WPA_IF_AP_BSS && !ifname)
  699. + os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname));
  700. +
  701. +out:
  702. + nlmsg_free(msg);
  703. + return res;
  704. +}
  705. static int cookie_handler(struct nl_msg *msg, void *arg)
  706. {
  707. @@ -11195,6 +11257,37 @@ static bool nl80211_is_drv_shared(void *
  708. #endif /* CONFIG_IEEE80211BE */
  709. +static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type,
  710. + const char *ifname, const char *new_name)
  711. +{
  712. + struct i802_bss *bss = priv;
  713. + return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name);
  714. +}
  715. +
  716. +
  717. +static int driver_nl80211_set_first_bss(void *priv)
  718. +{
  719. + struct i802_bss *bss = priv, *tbss;
  720. + struct wpa_driver_nl80211_data *drv = bss->drv;
  721. +
  722. + if (drv->first_bss == bss)
  723. + return 0;
  724. +
  725. + for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
  726. + if (tbss->next != bss)
  727. + continue;
  728. +
  729. + tbss->next = bss->next;
  730. + bss->next = drv->first_bss;
  731. + drv->first_bss = bss;
  732. + drv->ctx = bss->ctx;
  733. + return 0;
  734. + }
  735. +
  736. + return -1;
  737. +}
  738. +
  739. +
  740. static int driver_nl80211_send_mlme(void *priv, const u8 *data,
  741. size_t data_len, int noack,
  742. unsigned int freq,
  743. @@ -15014,6 +15107,8 @@ const struct wpa_driver_ops wpa_driver_n
  744. .set_acl = wpa_driver_nl80211_set_acl,
  745. .if_add = wpa_driver_nl80211_if_add,
  746. .if_remove = driver_nl80211_if_remove,
  747. + .if_rename = driver_nl80211_if_rename,
  748. + .set_first_bss = driver_nl80211_set_first_bss,
  749. .send_mlme = driver_nl80211_send_mlme,
  750. .get_hw_feature_data = nl80211_get_hw_feature_data,
  751. .sta_add = wpa_driver_nl80211_sta_add,
  752. --- a/src/drivers/driver_nl80211_event.c
  753. +++ b/src/drivers/driver_nl80211_event.c
  754. @@ -1254,6 +1254,7 @@ static void mlme_event_ch_switch(struct
  755. struct nlattr *bw, struct nlattr *cf1,
  756. struct nlattr *cf2,
  757. struct nlattr *punct_bitmap,
  758. + struct nlattr *count,
  759. int finished)
  760. {
  761. struct i802_bss *bss;
  762. @@ -1319,6 +1320,8 @@ static void mlme_event_ch_switch(struct
  763. data.ch_switch.cf1 = nla_get_u32(cf1);
  764. if (cf2)
  765. data.ch_switch.cf2 = nla_get_u32(cf2);
  766. + if (count)
  767. + data.ch_switch.count = nla_get_u32(count);
  768. if (link) {
  769. data.ch_switch.link_id = nla_get_u8(link);
  770. @@ -4279,6 +4282,7 @@ static void do_process_drv_event(struct
  771. tb[NL80211_ATTR_CENTER_FREQ1],
  772. tb[NL80211_ATTR_CENTER_FREQ2],
  773. tb[NL80211_ATTR_PUNCT_BITMAP],
  774. + tb[NL80211_ATTR_CH_SWITCH_COUNT],
  775. 0);
  776. break;
  777. case NL80211_CMD_CH_SWITCH_NOTIFY:
  778. @@ -4291,6 +4295,7 @@ static void do_process_drv_event(struct
  779. tb[NL80211_ATTR_CENTER_FREQ1],
  780. tb[NL80211_ATTR_CENTER_FREQ2],
  781. tb[NL80211_ATTR_PUNCT_BITMAP],
  782. + NULL,
  783. 1);
  784. break;
  785. case NL80211_CMD_DISCONNECT:
  786. --- a/src/utils/wpa_debug.c
  787. +++ b/src/utils/wpa_debug.c
  788. @@ -26,6 +26,10 @@ static FILE *wpa_debug_tracing_file = NU
  789. #define WPAS_TRACE_PFX "wpas <%d>: "
  790. #endif /* CONFIG_DEBUG_LINUX_TRACING */
  791. +void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  792. +void (*wpa_hexdump_hook)(int level, const char *title, const void *buf,
  793. + size_t len);
  794. +void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  795. int wpa_debug_level = MSG_INFO;
  796. int wpa_debug_show_keys = 0;
  797. @@ -210,6 +214,12 @@ void _wpa_printf(int level, const char *
  798. {
  799. va_list ap;
  800. + if (wpa_printf_hook) {
  801. + va_start(ap, fmt);
  802. + wpa_printf_hook(level, fmt, ap);
  803. + va_end(ap);
  804. + }
  805. +
  806. if (level >= wpa_debug_level) {
  807. #ifdef CONFIG_ANDROID_LOG
  808. va_start(ap, fmt);
  809. @@ -260,6 +270,9 @@ void _wpa_hexdump(int level, const char
  810. {
  811. size_t i;
  812. + if (wpa_hexdump_hook)
  813. + wpa_hexdump_hook(level, title, buf, len);
  814. +
  815. #ifdef CONFIG_DEBUG_LINUX_TRACING
  816. if (wpa_debug_tracing_file != NULL) {
  817. fprintf(wpa_debug_tracing_file,
  818. --- a/src/utils/wpa_debug.h
  819. +++ b/src/utils/wpa_debug.h
  820. @@ -11,6 +11,10 @@
  821. #include "wpabuf.h"
  822. +extern void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  823. +extern void (*wpa_hexdump_hook)(int level, const char *title,
  824. + const void *buf, size_t len);
  825. +extern void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  826. extern int wpa_debug_level;
  827. extern int wpa_debug_show_keys;
  828. extern int wpa_debug_timestamp;
  829. --- a/wpa_supplicant/Makefile
  830. +++ b/wpa_supplicant/Makefile
  831. @@ -191,6 +191,14 @@ ifdef CONFIG_EAPOL_TEST
  832. CFLAGS += -Werror -DEAPOL_TEST
  833. endif
  834. +ifdef CONFIG_UCODE
  835. +CFLAGS += -DUCODE_SUPPORT
  836. +OBJS += ../src/utils/ucode.o
  837. +OBJS += ../src/utils/uloop.o
  838. +OBJS += ucode.o
  839. +LIBS += -lubox
  840. +endif
  841. +
  842. ifdef CONFIG_CODE_COVERAGE
  843. CFLAGS += -O0 -fprofile-arcs -ftest-coverage -U_FORTIFY_SOURCE
  844. LIBS += -lgcov
  845. @@ -1046,6 +1054,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
  846. CFLAGS += -DCONFIG_CTRL_IFACE_MIB
  847. endif
  848. OBJS += ../src/ap/ctrl_iface_ap.o
  849. +ifdef CONFIG_UCODE
  850. +OBJS += ../src/ap/ucode.o
  851. +endif
  852. endif
  853. CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
  854. --- a/wpa_supplicant/events.c
  855. +++ b/wpa_supplicant/events.c
  856. @@ -53,6 +53,7 @@
  857. #include "wmm_ac.h"
  858. #include "nan_usd.h"
  859. #include "dpp_supplicant.h"
  860. +#include "ucode.h"
  861. #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
  862. @@ -1706,6 +1707,12 @@ struct wpa_ssid * wpa_scan_res_match(str
  863. return NULL;
  864. }
  865. + if (!wpas_ucode_bss_allowed(wpa_s, bss)) {
  866. + if (debug_print)
  867. + wpa_dbg(wpa_s, MSG_DEBUG, " skip - denied by ucode handler");
  868. + return NULL;
  869. + }
  870. +
  871. for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
  872. if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
  873. bss, bssid_ignore_count, debug_print, link))
  874. @@ -3117,8 +3124,8 @@ fail:
  875. static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
  876. const u8 *ies, size_t ies_len)
  877. {
  878. + struct multi_ap_params *multi_ap = &wpa_s->multi_ap;
  879. struct ieee802_11_elems elems;
  880. - struct multi_ap_params multi_ap;
  881. u16 status;
  882. wpa_s->multi_ap_ie = 0;
  883. @@ -3129,13 +3136,13 @@ static void multi_ap_process_assoc_resp(
  884. return;
  885. status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
  886. - &multi_ap);
  887. + multi_ap);
  888. if (status != WLAN_STATUS_SUCCESS)
  889. return;
  890. - wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
  891. + wpa_s->multi_ap_backhaul = !!(multi_ap->capability &
  892. MULTI_AP_BACKHAUL_BSS);
  893. - wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
  894. + wpa_s->multi_ap_fronthaul = !!(multi_ap->capability &
  895. MULTI_AP_FRONTHAUL_BSS);
  896. wpa_s->multi_ap_ie = 1;
  897. }
  898. @@ -6293,6 +6300,7 @@ void supplicant_event(void *ctx, enum wp
  899. event_to_string(event), event);
  900. #endif /* CONFIG_NO_STDOUT_DEBUG */
  901. + wpas_ucode_event(wpa_s, event, data);
  902. switch (event) {
  903. case EVENT_AUTH:
  904. #ifdef CONFIG_FST
  905. --- a/wpa_supplicant/ctrl_iface_unix.c
  906. +++ b/wpa_supplicant/ctrl_iface_unix.c
  907. @@ -28,6 +28,7 @@
  908. #include "config.h"
  909. #include "wpa_supplicant_i.h"
  910. #include "ctrl_iface.h"
  911. +#include "ucode.h"
  912. /* Per-interface ctrl_iface */
  913. @@ -436,6 +437,7 @@ static void wpa_supplicant_ctrl_iface_ms
  914. if (wpa_s == NULL)
  915. return;
  916. + wpas_ucode_ctrl_event(wpa_s, txt, len);
  917. gpriv = wpa_s->global->ctrl_iface;
  918. if (type != WPA_MSG_NO_GLOBAL && gpriv &&