601-ucode_support.patch 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  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. @@ -6037,6 +6037,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. @@ -6138,6 +6139,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,7 +1438,13 @@ 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. + } else
  142. +#endif /* CONFIG_IEEE80211BE */
  143. if (!is_zero_ether_addr(conf->bssid)) {
  144. /* Allocate the configured BSSID. */
  145. os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
  146. @@ -1469,6 +1479,7 @@ static int hostapd_setup_bss(struct host
  147. hapd->mld_link_id, hapd->conf->iface);
  148. goto setup_mld;
  149. }
  150. + use_existing = true;
  151. }
  152. #endif /* CONFIG_IEEE80211BE */
  153. @@ -1477,7 +1488,7 @@ static int hostapd_setup_bss(struct host
  154. conf->iface, addr, hapd,
  155. &hapd->drv_priv, force_ifname, if_addr,
  156. conf->bridge[0] ? conf->bridge : NULL,
  157. - first == -1)) {
  158. + use_existing)) {
  159. wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
  160. MACSTR ")", MAC2STR(hapd->own_addr));
  161. hapd->interface_added = 0;
  162. @@ -1500,7 +1511,7 @@ static int hostapd_setup_bss(struct host
  163. #ifdef CONFIG_IEEE80211BE
  164. setup_mld:
  165. - if (hapd->conf->mld_ap && !first) {
  166. + if (hapd->conf->mld_ap && first != 1) {
  167. wpa_printf(MSG_DEBUG,
  168. "MLD: Set link_id=%u, mld_addr=" MACSTR
  169. ", own_addr=" MACSTR,
  170. @@ -1518,6 +1529,8 @@ setup_mld:
  171. }
  172. #endif /* CONFIG_IEEE80211BE */
  173. + hostapd_ucode_create_bss(hapd);
  174. +
  175. if (conf->wmm_enabled < 0)
  176. conf->wmm_enabled = hapd->iconf->ieee80211n |
  177. hapd->iconf->ieee80211ax;
  178. @@ -1843,7 +1856,7 @@ int hostapd_set_acl(struct hostapd_data
  179. }
  180. -static int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd)
  181. +int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd)
  182. {
  183. #ifdef CONFIG_IEEE80211BE
  184. int ret;
  185. @@ -2516,7 +2529,7 @@ static int hostapd_owe_iface_iter2(struc
  186. #endif /* CONFIG_OWE */
  187. -static void hostapd_owe_update_trans(struct hostapd_iface *iface)
  188. +void hostapd_owe_update_trans(struct hostapd_iface *iface)
  189. {
  190. #ifdef CONFIG_OWE
  191. /* Check whether the enabled BSS can complete OWE transition mode
  192. @@ -2986,7 +2999,7 @@ hostapd_alloc_bss_data(struct hostapd_if
  193. }
  194. -static void hostapd_bss_deinit(struct hostapd_data *hapd)
  195. +void hostapd_bss_deinit(struct hostapd_data *hapd)
  196. {
  197. if (!hapd)
  198. return;
  199. @@ -3194,7 +3207,7 @@ fail:
  200. }
  201. -static void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces)
  202. +void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces)
  203. {
  204. #ifdef CONFIG_IEEE80211BE
  205. struct hostapd_mld *mld, **all_mld;
  206. @@ -4074,7 +4087,8 @@ int hostapd_remove_iface(struct hapd_int
  207. hapd_iface = interfaces->iface[i];
  208. if (hapd_iface == NULL)
  209. return -1;
  210. - if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  211. + if (!os_strcmp(hapd_iface->phy, buf) ||
  212. + !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  213. wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
  214. hapd_iface->driver_ap_teardown =
  215. !!(hapd_iface->drv_flags &
  216. --- a/src/ap/hostapd.h
  217. +++ b/src/ap/hostapd.h
  218. @@ -19,6 +19,7 @@
  219. #include "ap_config.h"
  220. #include "drivers/driver.h"
  221. #include "ubus.h"
  222. +#include "ucode.h"
  223. #define OCE_STA_CFON_ENABLED(hapd) \
  224. ((hapd->conf->oce & OCE_STA_CFON) && \
  225. @@ -52,6 +53,10 @@ struct hapd_interfaces {
  226. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  227. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  228. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  229. + int (*ctrl_iface_recv)(struct hostapd_data *hapd,
  230. + char *buf, char *reply, int reply_size,
  231. + struct sockaddr_storage *from,
  232. + socklen_t fromlen);
  233. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  234. int (*cb)(struct hostapd_iface *iface,
  235. void *ctx), void *ctx);
  236. @@ -208,6 +213,7 @@ struct hostapd_data {
  237. struct hostapd_config *iconf;
  238. struct hostapd_bss_config *conf;
  239. struct hostapd_ubus_bss ubus;
  240. + struct hostapd_ucode_bss ucode;
  241. int interface_added; /* virtual interface added for this BSS */
  242. unsigned int started:1;
  243. unsigned int disabled:1;
  244. @@ -577,6 +583,7 @@ struct hostapd_mld {
  245. */
  246. struct hostapd_iface {
  247. struct hapd_interfaces *interfaces;
  248. + struct hostapd_ucode_iface ucode;
  249. void *owner;
  250. char *config_fname;
  251. struct hostapd_config *conf;
  252. @@ -787,11 +794,16 @@ struct hostapd_iface * hostapd_init(stru
  253. struct hostapd_iface *
  254. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  255. const char *config_fname, int debug);
  256. +int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd);
  257. +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon);
  258. +void hostapd_bss_link_deinit(struct hostapd_data *hapd);
  259. +void hostapd_bss_deinit(struct hostapd_data *hapd);
  260. void hostapd_bss_setup_multi_link(struct hostapd_data *hapd,
  261. struct hapd_interfaces *interfaces);
  262. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  263. int reassoc);
  264. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  265. +void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces);
  266. int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
  267. int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
  268. int hostapd_reload_bss_only(struct hostapd_data *bss);
  269. @@ -817,6 +829,7 @@ hostapd_switch_channel_fallback(struct h
  270. void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
  271. void hostapd_periodic_iface(struct hostapd_iface *iface);
  272. int hostapd_owe_trans_get_info(struct hostapd_data *hapd);
  273. +void hostapd_owe_update_trans(struct hostapd_iface *iface);;
  274. void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx);
  275. void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap);
  276. --- a/src/drivers/driver.h
  277. +++ b/src/drivers/driver.h
  278. @@ -4067,6 +4067,25 @@ struct wpa_driver_ops {
  279. const char *ifname);
  280. /**
  281. + * if_rename - Rename a virtual interface
  282. + * @priv: Private driver interface data
  283. + * @type: Interface type
  284. + * @ifname: Interface name of the virtual interface to be renamed
  285. + * (NULL when renaming the AP BSS interface)
  286. + * @new_name: New interface name of the virtual interface
  287. + * Returns: 0 on success, -1 on failure
  288. + */
  289. + int (*if_rename)(void *priv, enum wpa_driver_if_type type,
  290. + const char *ifname, const char *new_name);
  291. +
  292. + /**
  293. + * set_first_bss - Make a virtual interface the first (primary) bss
  294. + * @priv: Private driver interface data
  295. + * Returns: 0 on success, -1 on failure
  296. + */
  297. + int (*set_first_bss)(void *priv);
  298. +
  299. + /**
  300. * set_sta_vlan - Bind a station into a specific interface (AP only)
  301. * @priv: Private driver interface data
  302. * @ifname: Interface (main or virtual BSS or VLAN)
  303. @@ -6896,6 +6915,7 @@ union wpa_event_data {
  304. /**
  305. * struct ch_switch
  306. + * @count: Count until channel switch activates
  307. * @freq: Frequency of new channel in MHz
  308. * @ht_enabled: Whether this is an HT channel
  309. * @ch_offset: Secondary channel offset
  310. @@ -6906,6 +6926,7 @@ union wpa_event_data {
  311. * @punct_bitmap: Puncturing bitmap
  312. */
  313. struct ch_switch {
  314. + int count;
  315. int freq;
  316. int ht_enabled;
  317. int ch_offset;
  318. --- a/src/drivers/driver_nl80211.c
  319. +++ b/src/drivers/driver_nl80211.c
  320. @@ -77,6 +77,16 @@ enum nlmsgerr_attrs {
  321. #endif /* ANDROID */
  322. +static void handle_nl_debug_hook(struct nl_msg *msg, int tx)
  323. +{
  324. + const struct nlmsghdr *nlh;
  325. +
  326. + if (!wpa_netlink_hook)
  327. + return;
  328. +
  329. + nlh = nlmsg_hdr(msg);
  330. + wpa_netlink_hook(tx, nlh, nlh->nlmsg_len);
  331. +}
  332. static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
  333. {
  334. @@ -437,6 +447,11 @@ static int no_seq_check(struct nl_msg *m
  335. return NL_OK;
  336. }
  337. +static int debug_handler(struct nl_msg *msg, void *arg)
  338. +{
  339. + handle_nl_debug_hook(msg, 0);
  340. + return NL_OK;
  341. +}
  342. static void nl80211_nlmsg_clear(struct nl_msg *msg)
  343. {
  344. @@ -511,6 +526,8 @@ int send_and_recv_glb(struct nl80211_glo
  345. if (!msg)
  346. return -ENOMEM;
  347. + handle_nl_debug_hook(msg, 1);
  348. +
  349. err.err = -ENOMEM;
  350. s_nl_cb = nl_socket_get_cb(nl_handle);
  351. @@ -552,6 +569,7 @@ int send_and_recv_glb(struct nl80211_glo
  352. err.err_info = err_info;
  353. err.drv = drv;
  354. + nl_cb_set(cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  355. nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
  356. nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err.err);
  357. if (ack_handler_custom) {
  358. @@ -973,6 +991,7 @@ nl80211_get_wiphy_data_ap(struct i802_bs
  359. os_free(w);
  360. return NULL;
  361. }
  362. + nl_cb_set(w->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  363. nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  364. no_seq_check, NULL);
  365. nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  366. @@ -1401,7 +1420,7 @@ static void wpa_driver_nl80211_event_rtm
  367. }
  368. wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
  369. namebuf, ifname);
  370. - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
  371. + if (drv->first_bss->ifindex != ifi->ifi_index) {
  372. wpa_printf(MSG_DEBUG,
  373. "nl80211: Not the main interface (%s) - do not indicate interface down",
  374. drv->first_bss->ifname);
  375. @@ -1437,7 +1456,7 @@ static void wpa_driver_nl80211_event_rtm
  376. }
  377. wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
  378. namebuf, ifname);
  379. - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
  380. + if (drv->first_bss->ifindex != ifi->ifi_index) {
  381. wpa_printf(MSG_DEBUG,
  382. "nl80211: Not the main interface (%s) - do not indicate interface up",
  383. drv->first_bss->ifname);
  384. @@ -2130,6 +2149,7 @@ static int wpa_driver_nl80211_init_nl_gl
  385. genl_family_put(family);
  386. nl_cache_free(cache);
  387. + nl_cb_set(global->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  388. nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  389. no_seq_check, NULL);
  390. nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  391. @@ -2300,6 +2320,7 @@ static int nl80211_init_bss(struct i802_
  392. if (!bss->nl_cb)
  393. return -1;
  394. + nl_cb_set(bss->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  395. nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  396. no_seq_check, NULL);
  397. nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  398. @@ -8851,6 +8872,7 @@ static void *i802_init(struct hostapd_da
  399. char master_ifname[IFNAMSIZ];
  400. int ifindex, br_ifindex = 0;
  401. int br_added = 0;
  402. + int err;
  403. bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
  404. params->global_priv, 1,
  405. @@ -8911,21 +8933,17 @@ static void *i802_init(struct hostapd_da
  406. (params->num_bridge == 0 || !params->bridge[0]))
  407. add_ifidx(drv, br_ifindex, drv->ifindex);
  408. - if (bss->added_if_into_bridge || bss->already_in_bridge) {
  409. - int err;
  410. -
  411. - drv->rtnl_sk = nl_socket_alloc();
  412. - if (drv->rtnl_sk == NULL) {
  413. - wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  414. - goto failed;
  415. - }
  416. + drv->rtnl_sk = nl_socket_alloc();
  417. + if (drv->rtnl_sk == NULL) {
  418. + wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  419. + goto failed;
  420. + }
  421. - err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  422. - if (err) {
  423. - wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  424. - nl_geterror(err));
  425. - goto failed;
  426. - }
  427. + err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  428. + if (err) {
  429. + wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  430. + nl_geterror(err));
  431. + goto failed;
  432. }
  433. if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
  434. @@ -9304,6 +9322,50 @@ static int wpa_driver_nl80211_if_remove(
  435. return 0;
  436. }
  437. +static int wpa_driver_nl80211_if_rename(struct i802_bss *bss,
  438. + enum wpa_driver_if_type type,
  439. + const char *ifname, const char *new_name)
  440. +{
  441. + struct wpa_driver_nl80211_data *drv = bss->drv;
  442. + struct ifinfomsg ifi = {
  443. + .ifi_family = AF_UNSPEC,
  444. + .ifi_index = bss->ifindex,
  445. + };
  446. + struct nl_msg *msg;
  447. + int res = -ENOMEM;
  448. +
  449. + if (ifname)
  450. + ifi.ifi_index = if_nametoindex(ifname);
  451. +
  452. + msg = nlmsg_alloc_simple(RTM_SETLINK, 0);
  453. + if (!msg)
  454. + return res;
  455. +
  456. + if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0)
  457. + goto out;
  458. +
  459. + if (nla_put_string(msg, IFLA_IFNAME, new_name))
  460. + goto out;
  461. +
  462. + res = nl_send_auto_complete(drv->rtnl_sk, msg);
  463. + if (res < 0)
  464. + goto out;
  465. +
  466. + res = nl_wait_for_ack(drv->rtnl_sk);
  467. + if (res) {
  468. + wpa_printf(MSG_INFO,
  469. + "nl80211: Renaming device %s to %s failed: %s",
  470. + ifname ? ifname : bss->ifname, new_name, nl_geterror(res));
  471. + goto out;
  472. + }
  473. +
  474. + if (type == WPA_IF_AP_BSS && !ifname)
  475. + os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname));
  476. +
  477. +out:
  478. + nlmsg_free(msg);
  479. + return res;
  480. +}
  481. static int cookie_handler(struct nl_msg *msg, void *arg)
  482. {
  483. @@ -11182,6 +11244,37 @@ static bool nl80211_is_drv_shared(void *
  484. #endif /* CONFIG_IEEE80211BE */
  485. +static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type,
  486. + const char *ifname, const char *new_name)
  487. +{
  488. + struct i802_bss *bss = priv;
  489. + return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name);
  490. +}
  491. +
  492. +
  493. +static int driver_nl80211_set_first_bss(void *priv)
  494. +{
  495. + struct i802_bss *bss = priv, *tbss;
  496. + struct wpa_driver_nl80211_data *drv = bss->drv;
  497. +
  498. + if (drv->first_bss == bss)
  499. + return 0;
  500. +
  501. + for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
  502. + if (tbss->next != bss)
  503. + continue;
  504. +
  505. + tbss->next = bss->next;
  506. + bss->next = drv->first_bss;
  507. + drv->first_bss = bss;
  508. + drv->ctx = bss->ctx;
  509. + return 0;
  510. + }
  511. +
  512. + return -1;
  513. +}
  514. +
  515. +
  516. static int driver_nl80211_send_mlme(void *priv, const u8 *data,
  517. size_t data_len, int noack,
  518. unsigned int freq,
  519. @@ -15001,6 +15094,8 @@ const struct wpa_driver_ops wpa_driver_n
  520. .set_acl = wpa_driver_nl80211_set_acl,
  521. .if_add = wpa_driver_nl80211_if_add,
  522. .if_remove = driver_nl80211_if_remove,
  523. + .if_rename = driver_nl80211_if_rename,
  524. + .set_first_bss = driver_nl80211_set_first_bss,
  525. .send_mlme = driver_nl80211_send_mlme,
  526. .get_hw_feature_data = nl80211_get_hw_feature_data,
  527. .sta_add = wpa_driver_nl80211_sta_add,
  528. --- a/src/drivers/driver_nl80211_event.c
  529. +++ b/src/drivers/driver_nl80211_event.c
  530. @@ -1254,6 +1254,7 @@ static void mlme_event_ch_switch(struct
  531. struct nlattr *bw, struct nlattr *cf1,
  532. struct nlattr *cf2,
  533. struct nlattr *punct_bitmap,
  534. + struct nlattr *count,
  535. int finished)
  536. {
  537. struct i802_bss *bss;
  538. @@ -1319,6 +1320,8 @@ static void mlme_event_ch_switch(struct
  539. data.ch_switch.cf1 = nla_get_u32(cf1);
  540. if (cf2)
  541. data.ch_switch.cf2 = nla_get_u32(cf2);
  542. + if (count)
  543. + data.ch_switch.count = nla_get_u32(count);
  544. if (link) {
  545. data.ch_switch.link_id = nla_get_u8(link);
  546. @@ -4279,6 +4282,7 @@ static void do_process_drv_event(struct
  547. tb[NL80211_ATTR_CENTER_FREQ1],
  548. tb[NL80211_ATTR_CENTER_FREQ2],
  549. tb[NL80211_ATTR_PUNCT_BITMAP],
  550. + tb[NL80211_ATTR_CH_SWITCH_COUNT],
  551. 0);
  552. break;
  553. case NL80211_CMD_CH_SWITCH_NOTIFY:
  554. @@ -4291,6 +4295,7 @@ static void do_process_drv_event(struct
  555. tb[NL80211_ATTR_CENTER_FREQ1],
  556. tb[NL80211_ATTR_CENTER_FREQ2],
  557. tb[NL80211_ATTR_PUNCT_BITMAP],
  558. + NULL,
  559. 1);
  560. break;
  561. case NL80211_CMD_DISCONNECT:
  562. --- a/src/utils/wpa_debug.c
  563. +++ b/src/utils/wpa_debug.c
  564. @@ -26,6 +26,10 @@ static FILE *wpa_debug_tracing_file = NU
  565. #define WPAS_TRACE_PFX "wpas <%d>: "
  566. #endif /* CONFIG_DEBUG_LINUX_TRACING */
  567. +void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  568. +void (*wpa_hexdump_hook)(int level, const char *title, const void *buf,
  569. + size_t len);
  570. +void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  571. int wpa_debug_level = MSG_INFO;
  572. int wpa_debug_show_keys = 0;
  573. @@ -210,6 +214,12 @@ void _wpa_printf(int level, const char *
  574. {
  575. va_list ap;
  576. + if (wpa_printf_hook) {
  577. + va_start(ap, fmt);
  578. + wpa_printf_hook(level, fmt, ap);
  579. + va_end(ap);
  580. + }
  581. +
  582. if (level >= wpa_debug_level) {
  583. #ifdef CONFIG_ANDROID_LOG
  584. va_start(ap, fmt);
  585. @@ -260,6 +270,9 @@ void _wpa_hexdump(int level, const char
  586. {
  587. size_t i;
  588. + if (wpa_hexdump_hook)
  589. + wpa_hexdump_hook(level, title, buf, len);
  590. +
  591. #ifdef CONFIG_DEBUG_LINUX_TRACING
  592. if (wpa_debug_tracing_file != NULL) {
  593. fprintf(wpa_debug_tracing_file,
  594. --- a/src/utils/wpa_debug.h
  595. +++ b/src/utils/wpa_debug.h
  596. @@ -11,6 +11,10 @@
  597. #include "wpabuf.h"
  598. +extern void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  599. +extern void (*wpa_hexdump_hook)(int level, const char *title,
  600. + const void *buf, size_t len);
  601. +extern void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  602. extern int wpa_debug_level;
  603. extern int wpa_debug_show_keys;
  604. extern int wpa_debug_timestamp;
  605. --- a/wpa_supplicant/Makefile
  606. +++ b/wpa_supplicant/Makefile
  607. @@ -194,8 +194,20 @@ endif
  608. ifdef CONFIG_UBUS
  609. CFLAGS += -DUBUS_SUPPORT
  610. OBJS += ubus.o
  611. +LIBS += -lubus
  612. +NEED_ULOOP:=y
  613. +endif
  614. +
  615. +ifdef CONFIG_UCODE
  616. +CFLAGS += -DUCODE_SUPPORT
  617. +OBJS += ../src/utils/ucode.o
  618. +OBJS += ucode.o
  619. +NEED_ULOOP:=y
  620. +endif
  621. +
  622. +ifdef NEED_ULOOP
  623. OBJS += ../src/utils/uloop.o
  624. -LIBS += -lubox -lubus
  625. +LIBS += -lubox
  626. endif
  627. ifdef CONFIG_CODE_COVERAGE
  628. @@ -1056,6 +1068,9 @@ OBJS += ../src/ap/ctrl_iface_ap.o
  629. ifdef CONFIG_UBUS
  630. OBJS += ../src/ap/ubus.o
  631. endif
  632. +ifdef CONFIG_UCODE
  633. +OBJS += ../src/ap/ucode.o
  634. +endif
  635. endif
  636. CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
  637. --- a/wpa_supplicant/events.c
  638. +++ b/wpa_supplicant/events.c
  639. @@ -6291,6 +6291,7 @@ void supplicant_event(void *ctx, enum wp
  640. event_to_string(event), event);
  641. #endif /* CONFIG_NO_STDOUT_DEBUG */
  642. + wpas_ucode_event(wpa_s, event, data);
  643. switch (event) {
  644. case EVENT_AUTH:
  645. #ifdef CONFIG_FST
  646. --- a/wpa_supplicant/wpa_supplicant.c
  647. +++ b/wpa_supplicant/wpa_supplicant.c
  648. @@ -1276,6 +1276,7 @@ void wpa_supplicant_set_state(struct wpa
  649. sme_sched_obss_scan(wpa_s, 0);
  650. }
  651. wpa_s->wpa_state = state;
  652. + wpas_ucode_update_state(wpa_s);
  653. #ifndef CONFIG_NO_ROBUST_AV
  654. if (state == WPA_COMPLETED && dl_list_len(&wpa_s->active_scs_ids) &&
  655. @@ -8262,6 +8263,7 @@ struct wpa_supplicant * wpa_supplicant_a
  656. #endif /* CONFIG_P2P */
  657. wpas_ubus_add_bss(wpa_s);
  658. + wpas_ucode_add_bss(wpa_s);
  659. return wpa_s;
  660. }
  661. @@ -8289,6 +8291,7 @@ int wpa_supplicant_remove_iface(struct w
  662. struct wpa_supplicant *parent = wpa_s->parent;
  663. #endif /* CONFIG_MESH */
  664. + wpas_ucode_free_bss(wpa_s);
  665. wpas_ubus_free_bss(wpa_s);
  666. /* Remove interface from the global list of interfaces */
  667. @@ -8599,6 +8602,7 @@ struct wpa_global * wpa_supplicant_init(
  668. eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
  669. wpas_periodic, global, NULL);
  670. + wpas_ucode_init(global);
  671. return global;
  672. }
  673. @@ -8637,12 +8641,8 @@ int wpa_supplicant_run(struct wpa_global
  674. eloop_register_signal_terminate(wpa_supplicant_terminate, global);
  675. eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
  676. - wpas_ubus_add(global);
  677. -
  678. eloop_run();
  679. - wpas_ubus_free(global);
  680. -
  681. return 0;
  682. }
  683. @@ -8675,6 +8675,8 @@ void wpa_supplicant_deinit(struct wpa_gl
  684. wpas_notify_supplicant_deinitialized(global);
  685. + wpas_ucode_free();
  686. +
  687. eap_peer_unregister_methods();
  688. #ifdef CONFIG_AP
  689. eap_server_unregister_methods();
  690. --- a/wpa_supplicant/wpa_supplicant_i.h
  691. +++ b/wpa_supplicant/wpa_supplicant_i.h
  692. @@ -22,6 +22,7 @@
  693. #include "wmm_ac.h"
  694. #include "pasn/pasn_common.h"
  695. #include "ubus.h"
  696. +#include "ucode.h"
  697. extern const char *const wpa_supplicant_version;
  698. extern const char *const wpa_supplicant_license;
  699. @@ -701,6 +702,7 @@ struct wpa_supplicant {
  700. unsigned char perm_addr[ETH_ALEN];
  701. char ifname[100];
  702. struct wpas_ubus_bss ubus;
  703. + struct wpas_ucode_bss ucode;
  704. #ifdef CONFIG_MATCH_IFACE
  705. int matched;
  706. #endif /* CONFIG_MATCH_IFACE */
  707. --- a/src/ap/ieee802_11.c
  708. +++ b/src/ap/ieee802_11.c
  709. @@ -631,12 +631,17 @@ const char * sae_get_password(struct hos
  710. struct sae_pt **s_pt,
  711. const struct sae_pk **s_pk)
  712. {
  713. + struct hostapd_bss_config *conf = hapd->conf;
  714. + struct hostapd_ssid *ssid = &conf->ssid;
  715. const char *password = NULL;
  716. - struct sae_password_entry *pw;
  717. + struct sae_password_entry *pw = NULL;
  718. struct sae_pt *pt = NULL;
  719. const struct sae_pk *pk = NULL;
  720. struct hostapd_sta_wpa_psk_short *psk = NULL;
  721. + if (sta && sta->use_sta_psk)
  722. + goto use_sta_psk;
  723. +
  724. /* With sae_track_password functionality enabled, try to first find the
  725. * next viable wildcard-address password if a password identifier was
  726. * not used. Select an wildcard-addr entry if the STA is known to have
  727. @@ -697,12 +702,30 @@ const char * sae_get_password(struct hos
  728. pt = hapd->conf->ssid.pt;
  729. }
  730. +use_sta_psk:
  731. if (!password && sta && !rx_id) {
  732. for (psk = sta->psk; psk; psk = psk->next) {
  733. - if (psk->is_passphrase) {
  734. - password = psk->passphrase;
  735. + if (!psk->is_passphrase)
  736. + continue;
  737. +
  738. + password = psk->passphrase;
  739. + if (!sta->use_sta_psk)
  740. + break;
  741. +
  742. +#ifdef CONFIG_SAE
  743. + if (sta->sae_pt) {
  744. + pt = sta->sae_pt;
  745. break;
  746. }
  747. +
  748. + pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
  749. + ssid->ssid_len,
  750. + (const u8 *) password,
  751. + os_strlen(password),
  752. + NULL);
  753. + sta->sae_pt = pt;
  754. + break;
  755. +#endif
  756. }
  757. }
  758. @@ -3446,6 +3469,12 @@ static void handle_auth(struct hostapd_d
  759. goto fail;
  760. }
  761. + res = hostapd_ucode_sta_auth(hapd, sta);
  762. + if (res) {
  763. + resp = res;
  764. + goto fail;
  765. + }
  766. +
  767. sta->flags &= ~WLAN_STA_PREAUTH;
  768. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  769. --- a/src/ap/sta_info.c
  770. +++ b/src/ap/sta_info.c
  771. @@ -477,6 +477,11 @@ void ap_free_sta(struct hostapd_data *ha
  772. forced_memzero(sta->last_tk, WPA_TK_MAX_LEN);
  773. #endif /* CONFIG_TESTING_OPTIONS */
  774. +#ifdef CONFIG_SAE
  775. + if (sta->sae_pt)
  776. + sae_deinit_pt(sta->sae_pt);
  777. +#endif
  778. +
  779. os_free(sta);
  780. }
  781. @@ -1576,6 +1581,8 @@ void ap_sta_set_authorized_event(struct
  782. #endif /* CONFIG_P2P */
  783. const u8 *ip_ptr = NULL;
  784. + if (authorized)
  785. + hostapd_ucode_sta_connected(hapd, sta);
  786. #ifdef CONFIG_P2P
  787. if (hapd->p2p_group == NULL) {
  788. if (sta->p2p_ie != NULL &&
  789. --- a/src/ap/sta_info.h
  790. +++ b/src/ap/sta_info.h
  791. @@ -180,6 +180,9 @@ struct sta_info {
  792. int vlan_id_bound; /* updated by ap_sta_bind_vlan() */
  793. /* PSKs from RADIUS authentication server */
  794. struct hostapd_sta_wpa_psk_short *psk;
  795. + struct sae_pt *sae_pt;
  796. + int use_sta_psk;
  797. + int psk_idx;
  798. char *identity; /* User-Name from RADIUS */
  799. char *radius_cui; /* Chargeable-User-Identity from RADIUS */
  800. --- a/src/ap/wpa_auth_glue.c
  801. +++ b/src/ap/wpa_auth_glue.c
  802. @@ -392,6 +392,7 @@ static const u8 * hostapd_wpa_auth_get_p
  803. struct sta_info *sta = ap_get_sta(hapd, addr);
  804. const u8 *psk;
  805. + sta->psk_idx = 0;
  806. if (vlan_id)
  807. *vlan_id = 0;
  808. if (psk_len)
  809. @@ -438,13 +439,18 @@ static const u8 * hostapd_wpa_auth_get_p
  810. * returned psk which should not be returned again.
  811. * logic list (all hostapd_get_psk; all sta->psk)
  812. */
  813. + if (sta && sta->use_sta_psk)
  814. + psk = NULL;
  815. if (sta && sta->psk && !psk) {
  816. struct hostapd_sta_wpa_psk_short *pos;
  817. + int psk_idx = 1;
  818. if (vlan_id)
  819. *vlan_id = 0;
  820. psk = sta->psk->psk;
  821. - for (pos = sta->psk; pos; pos = pos->next) {
  822. + if (vlan_id)
  823. + sta->psk_idx = psk_idx;
  824. + for (pos = sta->psk; pos; pos = pos->next, psk_idx++) {
  825. if (pos->is_passphrase) {
  826. if (pbkdf2_sha1(pos->passphrase,
  827. hapd->conf->ssid.ssid,
  828. @@ -458,9 +464,13 @@ static const u8 * hostapd_wpa_auth_get_p
  829. }
  830. if (pos->psk == prev_psk) {
  831. psk = pos->next ? pos->next->psk : NULL;
  832. + if (vlan_id)
  833. + sta->psk_idx = psk_idx + 1;
  834. break;
  835. }
  836. }
  837. + if (vlan_id && !psk)
  838. + sta->psk_idx = 0;
  839. }
  840. return psk;
  841. }