601-ucode_support.patch 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845
  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. @@ -5998,6 +5998,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. @@ -6099,6 +6100,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. @@ -1033,6 +1033,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. @@ -1042,6 +1043,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. @@ -409,6 +409,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. @@ -255,6 +255,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. @@ -475,6 +477,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. @@ -729,6 +732,7 @@ void hostapd_cleanup_iface_partial(struc
  103. static void hostapd_cleanup_iface(struct hostapd_iface *iface)
  104. {
  105. wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
  106. + hostapd_ucode_free_iface(iface);
  107. eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
  108. NULL);
  109. @@ -1318,6 +1322,7 @@ static int hostapd_start_beacon(struct h
  110. hapd->driver->set_operstate(hapd->drv_priv, 1);
  111. hostapd_ubus_add_bss(hapd);
  112. + hostapd_ucode_add_bss(hapd);
  113. return 0;
  114. }
  115. @@ -1393,8 +1398,7 @@ static int hostapd_bss_radius_init(struc
  116. * initialized. Most of the modules that are initialized here will be
  117. * deinitialized in hostapd_cleanup().
  118. */
  119. -static int hostapd_setup_bss(struct hostapd_data *hapd, int first,
  120. - bool start_beacon)
  121. +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon)
  122. {
  123. struct hostapd_bss_config *conf = hapd->conf;
  124. u8 ssid[SSID_MAX_LEN + 1];
  125. @@ -1510,6 +1514,8 @@ setup_mld:
  126. }
  127. #endif /* CONFIG_IEEE80211BE */
  128. + hostapd_ucode_create_bss(hapd);
  129. +
  130. if (conf->wmm_enabled < 0)
  131. conf->wmm_enabled = hapd->iconf->ieee80211n |
  132. hapd->iconf->ieee80211ax;
  133. @@ -2487,7 +2493,7 @@ static int hostapd_owe_iface_iter2(struc
  134. #endif /* CONFIG_OWE */
  135. -static void hostapd_owe_update_trans(struct hostapd_iface *iface)
  136. +void hostapd_owe_update_trans(struct hostapd_iface *iface)
  137. {
  138. #ifdef CONFIG_OWE
  139. /* Check whether the enabled BSS can complete OWE transition mode
  140. @@ -2954,7 +2960,7 @@ hostapd_alloc_bss_data(struct hostapd_if
  141. }
  142. -static void hostapd_bss_deinit(struct hostapd_data *hapd)
  143. +void hostapd_bss_deinit(struct hostapd_data *hapd)
  144. {
  145. if (!hapd)
  146. return;
  147. @@ -4015,7 +4021,8 @@ int hostapd_remove_iface(struct hapd_int
  148. hapd_iface = interfaces->iface[i];
  149. if (hapd_iface == NULL)
  150. return -1;
  151. - if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  152. + if (!os_strcmp(hapd_iface->phy, buf) ||
  153. + !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  154. wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
  155. hapd_iface->driver_ap_teardown =
  156. !!(hapd_iface->drv_flags &
  157. --- a/src/ap/hostapd.h
  158. +++ b/src/ap/hostapd.h
  159. @@ -19,6 +19,7 @@
  160. #include "ap_config.h"
  161. #include "drivers/driver.h"
  162. #include "ubus.h"
  163. +#include "ucode.h"
  164. #define OCE_STA_CFON_ENABLED(hapd) \
  165. ((hapd->conf->oce & OCE_STA_CFON) && \
  166. @@ -52,6 +53,10 @@ struct hapd_interfaces {
  167. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  168. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  169. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  170. + int (*ctrl_iface_recv)(struct hostapd_data *hapd,
  171. + char *buf, char *reply, int reply_size,
  172. + struct sockaddr_storage *from,
  173. + socklen_t fromlen);
  174. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  175. int (*cb)(struct hostapd_iface *iface,
  176. void *ctx), void *ctx);
  177. @@ -208,6 +213,7 @@ struct hostapd_data {
  178. struct hostapd_config *iconf;
  179. struct hostapd_bss_config *conf;
  180. struct hostapd_ubus_bss ubus;
  181. + struct hostapd_ucode_bss ucode;
  182. int interface_added; /* virtual interface added for this BSS */
  183. unsigned int started:1;
  184. unsigned int disabled:1;
  185. @@ -577,6 +583,7 @@ struct hostapd_mld {
  186. */
  187. struct hostapd_iface {
  188. struct hapd_interfaces *interfaces;
  189. + struct hostapd_ucode_iface ucode;
  190. void *owner;
  191. char *config_fname;
  192. struct hostapd_config *conf;
  193. @@ -787,6 +794,8 @@ struct hostapd_iface * hostapd_init(stru
  194. struct hostapd_iface *
  195. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  196. const char *config_fname, int debug);
  197. +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon);
  198. +void hostapd_bss_deinit(struct hostapd_data *hapd);
  199. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  200. int reassoc);
  201. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  202. @@ -815,6 +824,7 @@ hostapd_switch_channel_fallback(struct h
  203. void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
  204. void hostapd_periodic_iface(struct hostapd_iface *iface);
  205. int hostapd_owe_trans_get_info(struct hostapd_data *hapd);
  206. +void hostapd_owe_update_trans(struct hostapd_iface *iface);;
  207. void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx);
  208. void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap);
  209. --- a/src/drivers/driver.h
  210. +++ b/src/drivers/driver.h
  211. @@ -3928,6 +3928,25 @@ struct wpa_driver_ops {
  212. const char *ifname);
  213. /**
  214. + * if_rename - Rename a virtual interface
  215. + * @priv: Private driver interface data
  216. + * @type: Interface type
  217. + * @ifname: Interface name of the virtual interface to be renamed
  218. + * (NULL when renaming the AP BSS interface)
  219. + * @new_name: New interface name of the virtual interface
  220. + * Returns: 0 on success, -1 on failure
  221. + */
  222. + int (*if_rename)(void *priv, enum wpa_driver_if_type type,
  223. + const char *ifname, const char *new_name);
  224. +
  225. + /**
  226. + * set_first_bss - Make a virtual interface the first (primary) bss
  227. + * @priv: Private driver interface data
  228. + * Returns: 0 on success, -1 on failure
  229. + */
  230. + int (*set_first_bss)(void *priv);
  231. +
  232. + /**
  233. * set_sta_vlan - Bind a station into a specific interface (AP only)
  234. * @priv: Private driver interface data
  235. * @ifname: Interface (main or virtual BSS or VLAN)
  236. @@ -6720,6 +6739,7 @@ union wpa_event_data {
  237. /**
  238. * struct ch_switch
  239. + * @count: Count until channel switch activates
  240. * @freq: Frequency of new channel in MHz
  241. * @ht_enabled: Whether this is an HT channel
  242. * @ch_offset: Secondary channel offset
  243. @@ -6730,6 +6750,7 @@ union wpa_event_data {
  244. * @punct_bitmap: Puncturing bitmap
  245. */
  246. struct ch_switch {
  247. + int count;
  248. int freq;
  249. int ht_enabled;
  250. int ch_offset;
  251. --- a/src/drivers/driver_nl80211.c
  252. +++ b/src/drivers/driver_nl80211.c
  253. @@ -77,6 +77,16 @@ enum nlmsgerr_attrs {
  254. #endif /* ANDROID */
  255. +static void handle_nl_debug_hook(struct nl_msg *msg, int tx)
  256. +{
  257. + const struct nlmsghdr *nlh;
  258. +
  259. + if (!wpa_netlink_hook)
  260. + return;
  261. +
  262. + nlh = nlmsg_hdr(msg);
  263. + wpa_netlink_hook(tx, nlh, nlh->nlmsg_len);
  264. +}
  265. static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
  266. {
  267. @@ -431,6 +441,11 @@ static int no_seq_check(struct nl_msg *m
  268. return NL_OK;
  269. }
  270. +static int debug_handler(struct nl_msg *msg, void *arg)
  271. +{
  272. + handle_nl_debug_hook(msg, 0);
  273. + return NL_OK;
  274. +}
  275. static void nl80211_nlmsg_clear(struct nl_msg *msg)
  276. {
  277. @@ -504,6 +519,8 @@ int send_and_recv(struct nl80211_global
  278. if (!msg)
  279. return -ENOMEM;
  280. + handle_nl_debug_hook(msg, 1);
  281. +
  282. err.err = -ENOMEM;
  283. s_nl_cb = nl_socket_get_cb(nl_handle);
  284. @@ -538,6 +555,7 @@ int send_and_recv(struct nl80211_global
  285. err.orig_msg = msg;
  286. err.err_info = err_info;
  287. + nl_cb_set(cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  288. nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
  289. nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err.err);
  290. if (ack_handler_custom) {
  291. @@ -941,6 +959,7 @@ nl80211_get_wiphy_data_ap(struct i802_bs
  292. os_free(w);
  293. return NULL;
  294. }
  295. + nl_cb_set(w->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  296. nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  297. no_seq_check, NULL);
  298. nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  299. @@ -1355,7 +1374,7 @@ static void wpa_driver_nl80211_event_rtm
  300. }
  301. wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
  302. namebuf, ifname);
  303. - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
  304. + if (drv->first_bss->ifindex != ifi->ifi_index) {
  305. wpa_printf(MSG_DEBUG,
  306. "nl80211: Not the main interface (%s) - do not indicate interface down",
  307. drv->first_bss->ifname);
  308. @@ -1391,7 +1410,7 @@ static void wpa_driver_nl80211_event_rtm
  309. }
  310. wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
  311. namebuf, ifname);
  312. - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
  313. + if (drv->first_bss->ifindex != ifi->ifi_index) {
  314. wpa_printf(MSG_DEBUG,
  315. "nl80211: Not the main interface (%s) - do not indicate interface up",
  316. drv->first_bss->ifname);
  317. @@ -2037,6 +2056,7 @@ static int wpa_driver_nl80211_init_nl_gl
  318. genl_family_put(family);
  319. nl_cache_free(cache);
  320. + nl_cb_set(global->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  321. nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  322. no_seq_check, NULL);
  323. nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  324. @@ -2207,6 +2227,7 @@ static int nl80211_init_bss(struct i802_
  325. if (!bss->nl_cb)
  326. return -1;
  327. + nl_cb_set(bss->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  328. nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  329. no_seq_check, NULL);
  330. nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  331. @@ -8704,6 +8725,7 @@ static void *i802_init(struct hostapd_da
  332. char master_ifname[IFNAMSIZ];
  333. int ifindex, br_ifindex = 0;
  334. int br_added = 0;
  335. + int err;
  336. bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
  337. params->global_priv, 1,
  338. @@ -8763,21 +8785,17 @@ static void *i802_init(struct hostapd_da
  339. (params->num_bridge == 0 || !params->bridge[0]))
  340. add_ifidx(drv, br_ifindex, drv->ifindex);
  341. - if (bss->added_if_into_bridge || bss->already_in_bridge) {
  342. - int err;
  343. -
  344. - drv->rtnl_sk = nl_socket_alloc();
  345. - if (drv->rtnl_sk == NULL) {
  346. - wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  347. - goto failed;
  348. - }
  349. + drv->rtnl_sk = nl_socket_alloc();
  350. + if (drv->rtnl_sk == NULL) {
  351. + wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  352. + goto failed;
  353. + }
  354. - err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  355. - if (err) {
  356. - wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  357. - nl_geterror(err));
  358. - goto failed;
  359. - }
  360. + err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  361. + if (err) {
  362. + wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  363. + nl_geterror(err));
  364. + goto failed;
  365. }
  366. if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
  367. @@ -9146,6 +9164,50 @@ static int wpa_driver_nl80211_if_remove(
  368. return 0;
  369. }
  370. +static int wpa_driver_nl80211_if_rename(struct i802_bss *bss,
  371. + enum wpa_driver_if_type type,
  372. + const char *ifname, const char *new_name)
  373. +{
  374. + struct wpa_driver_nl80211_data *drv = bss->drv;
  375. + struct ifinfomsg ifi = {
  376. + .ifi_family = AF_UNSPEC,
  377. + .ifi_index = bss->ifindex,
  378. + };
  379. + struct nl_msg *msg;
  380. + int res = -ENOMEM;
  381. +
  382. + if (ifname)
  383. + ifi.ifi_index = if_nametoindex(ifname);
  384. +
  385. + msg = nlmsg_alloc_simple(RTM_SETLINK, 0);
  386. + if (!msg)
  387. + return res;
  388. +
  389. + if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0)
  390. + goto out;
  391. +
  392. + if (nla_put_string(msg, IFLA_IFNAME, new_name))
  393. + goto out;
  394. +
  395. + res = nl_send_auto_complete(drv->rtnl_sk, msg);
  396. + if (res < 0)
  397. + goto out;
  398. +
  399. + res = nl_wait_for_ack(drv->rtnl_sk);
  400. + if (res) {
  401. + wpa_printf(MSG_INFO,
  402. + "nl80211: Renaming device %s to %s failed: %s",
  403. + ifname ? ifname : bss->ifname, new_name, nl_geterror(res));
  404. + goto out;
  405. + }
  406. +
  407. + if (type == WPA_IF_AP_BSS && !ifname)
  408. + os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname));
  409. +
  410. +out:
  411. + nlmsg_free(msg);
  412. + return res;
  413. +}
  414. static int cookie_handler(struct nl_msg *msg, void *arg)
  415. {
  416. @@ -10962,6 +11024,37 @@ static bool nl80211_is_drv_shared(void *
  417. #endif /* CONFIG_IEEE80211BE */
  418. +static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type,
  419. + const char *ifname, const char *new_name)
  420. +{
  421. + struct i802_bss *bss = priv;
  422. + return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name);
  423. +}
  424. +
  425. +
  426. +static int driver_nl80211_set_first_bss(void *priv)
  427. +{
  428. + struct i802_bss *bss = priv, *tbss;
  429. + struct wpa_driver_nl80211_data *drv = bss->drv;
  430. +
  431. + if (drv->first_bss == bss)
  432. + return 0;
  433. +
  434. + for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
  435. + if (tbss->next != bss)
  436. + continue;
  437. +
  438. + tbss->next = bss->next;
  439. + bss->next = drv->first_bss;
  440. + drv->first_bss = bss;
  441. + drv->ctx = bss->ctx;
  442. + return 0;
  443. + }
  444. +
  445. + return -1;
  446. +}
  447. +
  448. +
  449. static int driver_nl80211_send_mlme(void *priv, const u8 *data,
  450. size_t data_len, int noack,
  451. unsigned int freq,
  452. @@ -14510,6 +14603,8 @@ const struct wpa_driver_ops wpa_driver_n
  453. .set_acl = wpa_driver_nl80211_set_acl,
  454. .if_add = wpa_driver_nl80211_if_add,
  455. .if_remove = driver_nl80211_if_remove,
  456. + .if_rename = driver_nl80211_if_rename,
  457. + .set_first_bss = driver_nl80211_set_first_bss,
  458. .send_mlme = driver_nl80211_send_mlme,
  459. .get_hw_feature_data = nl80211_get_hw_feature_data,
  460. .sta_add = wpa_driver_nl80211_sta_add,
  461. --- a/src/drivers/driver_nl80211_event.c
  462. +++ b/src/drivers/driver_nl80211_event.c
  463. @@ -1197,6 +1197,7 @@ static void mlme_event_ch_switch(struct
  464. struct nlattr *bw, struct nlattr *cf1,
  465. struct nlattr *cf2,
  466. struct nlattr *punct_bitmap,
  467. + struct nlattr *count,
  468. int finished)
  469. {
  470. struct i802_bss *bss;
  471. @@ -1260,6 +1261,8 @@ static void mlme_event_ch_switch(struct
  472. data.ch_switch.cf1 = nla_get_u32(cf1);
  473. if (cf2)
  474. data.ch_switch.cf2 = nla_get_u32(cf2);
  475. + if (count)
  476. + data.ch_switch.count = nla_get_u32(count);
  477. if (link) {
  478. data.ch_switch.link_id = nla_get_u8(link);
  479. @@ -4054,6 +4057,7 @@ static void do_process_drv_event(struct
  480. tb[NL80211_ATTR_CENTER_FREQ1],
  481. tb[NL80211_ATTR_CENTER_FREQ2],
  482. tb[NL80211_ATTR_PUNCT_BITMAP],
  483. + tb[NL80211_ATTR_CH_SWITCH_COUNT],
  484. 0);
  485. break;
  486. case NL80211_CMD_CH_SWITCH_NOTIFY:
  487. @@ -4066,6 +4070,7 @@ static void do_process_drv_event(struct
  488. tb[NL80211_ATTR_CENTER_FREQ1],
  489. tb[NL80211_ATTR_CENTER_FREQ2],
  490. tb[NL80211_ATTR_PUNCT_BITMAP],
  491. + NULL,
  492. 1);
  493. break;
  494. case NL80211_CMD_DISCONNECT:
  495. --- a/src/utils/wpa_debug.c
  496. +++ b/src/utils/wpa_debug.c
  497. @@ -26,6 +26,10 @@ static FILE *wpa_debug_tracing_file = NU
  498. #define WPAS_TRACE_PFX "wpas <%d>: "
  499. #endif /* CONFIG_DEBUG_LINUX_TRACING */
  500. +void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  501. +void (*wpa_hexdump_hook)(int level, const char *title, const void *buf,
  502. + size_t len);
  503. +void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  504. int wpa_debug_level = MSG_INFO;
  505. int wpa_debug_show_keys = 0;
  506. @@ -210,6 +214,12 @@ void _wpa_printf(int level, const char *
  507. {
  508. va_list ap;
  509. + if (wpa_printf_hook) {
  510. + va_start(ap, fmt);
  511. + wpa_printf_hook(level, fmt, ap);
  512. + va_end(ap);
  513. + }
  514. +
  515. if (level >= wpa_debug_level) {
  516. #ifdef CONFIG_ANDROID_LOG
  517. va_start(ap, fmt);
  518. @@ -260,6 +270,9 @@ void _wpa_hexdump(int level, const char
  519. {
  520. size_t i;
  521. + if (wpa_hexdump_hook)
  522. + wpa_hexdump_hook(level, title, buf, len);
  523. +
  524. #ifdef CONFIG_DEBUG_LINUX_TRACING
  525. if (wpa_debug_tracing_file != NULL) {
  526. fprintf(wpa_debug_tracing_file,
  527. --- a/src/utils/wpa_debug.h
  528. +++ b/src/utils/wpa_debug.h
  529. @@ -11,6 +11,10 @@
  530. #include "wpabuf.h"
  531. +extern void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  532. +extern void (*wpa_hexdump_hook)(int level, const char *title,
  533. + const void *buf, size_t len);
  534. +extern void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  535. extern int wpa_debug_level;
  536. extern int wpa_debug_show_keys;
  537. extern int wpa_debug_timestamp;
  538. --- a/wpa_supplicant/Makefile
  539. +++ b/wpa_supplicant/Makefile
  540. @@ -194,8 +194,20 @@ endif
  541. ifdef CONFIG_UBUS
  542. CFLAGS += -DUBUS_SUPPORT
  543. OBJS += ubus.o
  544. +LIBS += -lubus
  545. +NEED_ULOOP:=y
  546. +endif
  547. +
  548. +ifdef CONFIG_UCODE
  549. +CFLAGS += -DUCODE_SUPPORT
  550. +OBJS += ../src/utils/ucode.o
  551. +OBJS += ucode.o
  552. +NEED_ULOOP:=y
  553. +endif
  554. +
  555. +ifdef NEED_ULOOP
  556. OBJS += ../src/utils/uloop.o
  557. -LIBS += -lubox -lubus
  558. +LIBS += -lubox
  559. endif
  560. ifdef CONFIG_CODE_COVERAGE
  561. @@ -1053,6 +1065,9 @@ OBJS += ../src/ap/ctrl_iface_ap.o
  562. ifdef CONFIG_UBUS
  563. OBJS += ../src/ap/ubus.o
  564. endif
  565. +ifdef CONFIG_UCODE
  566. +OBJS += ../src/ap/ucode.o
  567. +endif
  568. endif
  569. CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
  570. --- a/wpa_supplicant/events.c
  571. +++ b/wpa_supplicant/events.c
  572. @@ -6167,6 +6167,7 @@ void supplicant_event(void *ctx, enum wp
  573. event_to_string(event), event);
  574. #endif /* CONFIG_NO_STDOUT_DEBUG */
  575. + wpas_ucode_event(wpa_s, event, data);
  576. switch (event) {
  577. case EVENT_AUTH:
  578. #ifdef CONFIG_FST
  579. --- a/wpa_supplicant/wpa_supplicant.c
  580. +++ b/wpa_supplicant/wpa_supplicant.c
  581. @@ -1151,6 +1151,7 @@ void wpa_supplicant_set_state(struct wpa
  582. sme_sched_obss_scan(wpa_s, 0);
  583. }
  584. wpa_s->wpa_state = state;
  585. + wpas_ucode_update_state(wpa_s);
  586. #ifdef CONFIG_BGSCAN
  587. if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid)
  588. @@ -7921,6 +7922,7 @@ struct wpa_supplicant * wpa_supplicant_a
  589. #endif /* CONFIG_P2P */
  590. wpas_ubus_add_bss(wpa_s);
  591. + wpas_ucode_add_bss(wpa_s);
  592. return wpa_s;
  593. }
  594. @@ -7948,6 +7950,7 @@ int wpa_supplicant_remove_iface(struct w
  595. struct wpa_supplicant *parent = wpa_s->parent;
  596. #endif /* CONFIG_MESH */
  597. + wpas_ucode_free_bss(wpa_s);
  598. wpas_ubus_free_bss(wpa_s);
  599. /* Remove interface from the global list of interfaces */
  600. @@ -8258,6 +8261,7 @@ struct wpa_global * wpa_supplicant_init(
  601. eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
  602. wpas_periodic, global, NULL);
  603. + wpas_ucode_init(global);
  604. return global;
  605. }
  606. @@ -8296,12 +8300,8 @@ int wpa_supplicant_run(struct wpa_global
  607. eloop_register_signal_terminate(wpa_supplicant_terminate, global);
  608. eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
  609. - wpas_ubus_add(global);
  610. -
  611. eloop_run();
  612. - wpas_ubus_free(global);
  613. -
  614. return 0;
  615. }
  616. @@ -8334,6 +8334,8 @@ void wpa_supplicant_deinit(struct wpa_gl
  617. wpas_notify_supplicant_deinitialized(global);
  618. + wpas_ucode_free();
  619. +
  620. eap_peer_unregister_methods();
  621. #ifdef CONFIG_AP
  622. eap_server_unregister_methods();
  623. --- a/wpa_supplicant/wpa_supplicant_i.h
  624. +++ b/wpa_supplicant/wpa_supplicant_i.h
  625. @@ -22,6 +22,7 @@
  626. #include "wmm_ac.h"
  627. #include "pasn/pasn_common.h"
  628. #include "ubus.h"
  629. +#include "ucode.h"
  630. extern const char *const wpa_supplicant_version;
  631. extern const char *const wpa_supplicant_license;
  632. @@ -697,6 +698,7 @@ struct wpa_supplicant {
  633. unsigned char perm_addr[ETH_ALEN];
  634. char ifname[100];
  635. struct wpas_ubus_bss ubus;
  636. + struct wpas_ucode_bss ucode;
  637. #ifdef CONFIG_MATCH_IFACE
  638. int matched;
  639. #endif /* CONFIG_MATCH_IFACE */
  640. --- a/src/ap/ieee802_11.c
  641. +++ b/src/ap/ieee802_11.c
  642. @@ -555,12 +555,17 @@ const char * sae_get_password(struct hos
  643. struct sae_pt **s_pt,
  644. const struct sae_pk **s_pk)
  645. {
  646. + struct hostapd_bss_config *conf = hapd->conf;
  647. + struct hostapd_ssid *ssid = &conf->ssid;
  648. const char *password = NULL;
  649. - struct sae_password_entry *pw;
  650. + struct sae_password_entry *pw = NULL;
  651. struct sae_pt *pt = NULL;
  652. const struct sae_pk *pk = NULL;
  653. struct hostapd_sta_wpa_psk_short *psk = NULL;
  654. + if (sta && sta->use_sta_psk)
  655. + goto use_sta_psk;
  656. +
  657. for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) {
  658. if (!is_broadcast_ether_addr(pw->peer_addr) &&
  659. (!sta ||
  660. @@ -582,12 +587,30 @@ const char * sae_get_password(struct hos
  661. pt = hapd->conf->ssid.pt;
  662. }
  663. +use_sta_psk:
  664. if (!password && sta) {
  665. for (psk = sta->psk; psk; psk = psk->next) {
  666. - if (psk->is_passphrase) {
  667. - password = psk->passphrase;
  668. + if (!psk->is_passphrase)
  669. + continue;
  670. +
  671. + password = psk->passphrase;
  672. + if (!sta->use_sta_psk)
  673. + break;
  674. +
  675. +#ifdef CONFIG_SAE
  676. + if (sta->sae_pt) {
  677. + pt = sta->sae_pt;
  678. break;
  679. }
  680. +
  681. + pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
  682. + ssid->ssid_len,
  683. + (const u8 *) password,
  684. + os_strlen(password),
  685. + NULL);
  686. + sta->sae_pt = pt;
  687. + break;
  688. +#endif
  689. }
  690. }
  691. @@ -3229,6 +3252,12 @@ static void handle_auth(struct hostapd_d
  692. goto fail;
  693. }
  694. + res = hostapd_ucode_sta_auth(hapd, sta);
  695. + if (res) {
  696. + resp = res;
  697. + goto fail;
  698. + }
  699. +
  700. sta->flags &= ~WLAN_STA_PREAUTH;
  701. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  702. --- a/src/ap/sta_info.c
  703. +++ b/src/ap/sta_info.c
  704. @@ -474,6 +474,11 @@ void ap_free_sta(struct hostapd_data *ha
  705. forced_memzero(sta->last_tk, WPA_TK_MAX_LEN);
  706. #endif /* CONFIG_TESTING_OPTIONS */
  707. +#ifdef CONFIG_SAE
  708. + if (sta->sae_pt)
  709. + sae_deinit_pt(sta->sae_pt);
  710. +#endif
  711. +
  712. os_free(sta);
  713. }
  714. @@ -1507,6 +1512,8 @@ void ap_sta_set_authorized_event(struct
  715. #endif /* CONFIG_P2P */
  716. const u8 *ip_ptr = NULL;
  717. + if (authorized)
  718. + hostapd_ucode_sta_connected(hapd, sta);
  719. #ifdef CONFIG_P2P
  720. if (hapd->p2p_group == NULL) {
  721. if (sta->p2p_ie != NULL &&
  722. --- a/src/ap/sta_info.h
  723. +++ b/src/ap/sta_info.h
  724. @@ -180,6 +180,9 @@ struct sta_info {
  725. int vlan_id_bound; /* updated by ap_sta_bind_vlan() */
  726. /* PSKs from RADIUS authentication server */
  727. struct hostapd_sta_wpa_psk_short *psk;
  728. + struct sae_pt *sae_pt;
  729. + int use_sta_psk;
  730. + int psk_idx;
  731. char *identity; /* User-Name from RADIUS */
  732. char *radius_cui; /* Chargeable-User-Identity from RADIUS */
  733. --- a/src/ap/wpa_auth_glue.c
  734. +++ b/src/ap/wpa_auth_glue.c
  735. @@ -400,6 +400,7 @@ static const u8 * hostapd_wpa_auth_get_p
  736. struct sta_info *sta = ap_get_sta(hapd, addr);
  737. const u8 *psk;
  738. + sta->psk_idx = 0;
  739. if (vlan_id)
  740. *vlan_id = 0;
  741. if (psk_len)
  742. @@ -446,13 +447,16 @@ static const u8 * hostapd_wpa_auth_get_p
  743. * returned psk which should not be returned again.
  744. * logic list (all hostapd_get_psk; all sta->psk)
  745. */
  746. + if (sta && sta->use_sta_psk)
  747. + psk = NULL;
  748. if (sta && sta->psk && !psk) {
  749. struct hostapd_sta_wpa_psk_short *pos;
  750. + int psk_idx = 1;
  751. if (vlan_id)
  752. *vlan_id = 0;
  753. psk = sta->psk->psk;
  754. - for (pos = sta->psk; pos; pos = pos->next) {
  755. + for (pos = sta->psk; pos; pos = pos->next, psk_idx++) {
  756. if (pos->is_passphrase) {
  757. if (pbkdf2_sha1(pos->passphrase,
  758. hapd->conf->ssid.ssid,
  759. @@ -469,6 +473,8 @@ static const u8 * hostapd_wpa_auth_get_p
  760. break;
  761. }
  762. }
  763. + if (psk)
  764. + sta->psk_idx = psk_idx;
  765. }
  766. return psk;
  767. }