601-ucode_support.patch 29 KB

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