601-ucode_support.patch 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328
  1. From: Felix Fietkau <[email protected]>
  2. Date: Fri, 26 May 2023 10:23:59 +0200
  3. Subject: [PATCH] Add ucode support, use ucode for the main ubus object
  4. This implements vastly improved dynamic configuration reload support.
  5. It can handle configuration changes on individual wifi interfaces, as well
  6. as adding/removing interfaces.
  7. --- a/wpa_supplicant/wpa_supplicant.c
  8. +++ b/wpa_supplicant/wpa_supplicant.c
  9. @@ -1267,6 +1267,7 @@ void wpa_supplicant_set_state(struct wpa
  10. sme_sched_obss_scan(wpa_s, 0);
  11. }
  12. wpa_s->wpa_state = state;
  13. + wpas_ucode_update_state(wpa_s);
  14. #ifndef CONFIG_NO_ROBUST_AV
  15. if (state == WPA_COMPLETED && dl_list_len(&wpa_s->active_scs_ids) &&
  16. @@ -8392,6 +8393,8 @@ struct wpa_supplicant * wpa_supplicant_a
  17. }
  18. #endif /* CONFIG_P2P */
  19. + wpas_ucode_add_bss(wpa_s);
  20. +
  21. return wpa_s;
  22. }
  23. @@ -8418,6 +8421,8 @@ int wpa_supplicant_remove_iface(struct w
  24. struct wpa_supplicant *parent = wpa_s->parent;
  25. #endif /* CONFIG_MESH */
  26. + wpas_ucode_free_bss(wpa_s);
  27. +
  28. /* Remove interface from the global list of interfaces */
  29. prev = global->ifaces;
  30. if (prev == wpa_s) {
  31. @@ -8737,6 +8742,7 @@ struct wpa_global * wpa_supplicant_init(
  32. eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
  33. wpas_periodic, global, NULL);
  34. + wpas_ucode_init(global);
  35. return global;
  36. }
  37. @@ -8809,6 +8815,8 @@ void wpa_supplicant_deinit(struct wpa_gl
  38. wpas_notify_supplicant_deinitialized(global);
  39. + wpas_ucode_free();
  40. +
  41. eap_peer_unregister_methods();
  42. #ifdef CONFIG_AP
  43. eap_server_unregister_methods();
  44. --- a/wpa_supplicant/wpa_supplicant_i.h
  45. +++ b/wpa_supplicant/wpa_supplicant_i.h
  46. @@ -15,12 +15,14 @@
  47. #include "common/sae.h"
  48. #include "common/wpa_ctrl.h"
  49. #include "common/dpp.h"
  50. +#include "common/ieee802_11_common.h"
  51. #include "crypto/sha384.h"
  52. #include "eapol_supp/eapol_supp_sm.h"
  53. #include "wps/wps_defs.h"
  54. #include "config_ssid.h"
  55. #include "wmm_ac.h"
  56. #include "pasn/pasn_common.h"
  57. +#include "ucode.h"
  58. extern const char *const wpa_supplicant_version;
  59. extern const char *const wpa_supplicant_license;
  60. @@ -756,6 +758,7 @@ struct wpa_supplicant {
  61. unsigned char own_addr[ETH_ALEN];
  62. unsigned char perm_addr[ETH_ALEN];
  63. char ifname[100];
  64. + struct wpas_ucode_bss ucode;
  65. u8 hw_dfs_domain;
  66. #ifdef CONFIG_MATCH_IFACE
  67. int matched;
  68. @@ -1633,6 +1636,8 @@ struct wpa_supplicant {
  69. unsigned int enabled_4addr_mode:1;
  70. unsigned int multi_bss_support:1;
  71. unsigned int drv_authorized_port:1;
  72. +
  73. + struct multi_ap_params multi_ap;
  74. unsigned int multi_ap_ie:1;
  75. unsigned int multi_ap_backhaul:1;
  76. unsigned int multi_ap_fronthaul:1;
  77. --- a/wpa_supplicant/wps_supplicant.c
  78. +++ b/wpa_supplicant/wps_supplicant.c
  79. @@ -33,6 +33,7 @@
  80. #include "p2p/p2p.h"
  81. #include "p2p_supplicant.h"
  82. #include "wps_supplicant.h"
  83. +#include "ucode.h"
  84. #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
  85. @@ -371,6 +372,14 @@ static void wpas_wps_remove_dup_network(
  86. }
  87. +static int wpa_supplicant_wps_m8_rx(void *ctx, const u8 *data,
  88. + size_t data_len)
  89. +{
  90. + struct wpa_supplicant *wpa_s = ctx;
  91. + return wpas_ucode_wps_m8_rx(wpa_s, data, data_len);
  92. +}
  93. +
  94. +
  95. static int wpa_supplicant_wps_cred(void *ctx,
  96. const struct wps_credential *cred)
  97. {
  98. @@ -401,6 +410,8 @@ static int wpa_supplicant_wps_cred(void
  99. wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
  100. cred->cred_attr, cred->cred_attr_len);
  101. + wpas_ucode_wps_complete(wpa_s, cred);
  102. +
  103. if (wpa_s->conf->wps_cred_processing == 1)
  104. return 0;
  105. @@ -1596,6 +1607,7 @@ int wpas_wps_init(struct wpa_supplicant
  106. wps->cred_cb = wpa_supplicant_wps_cred;
  107. wps->event_cb = wpa_supplicant_wps_event;
  108. wps->rf_band_cb = wpa_supplicant_wps_rf_band;
  109. + wps->m8_rx_cb = wpa_supplicant_wps_m8_rx;
  110. wps->cb_ctx = wpa_s;
  111. wps->dev.device_name = wpa_s->conf->device_name;
  112. @@ -1713,6 +1725,7 @@ void wpas_wps_deinit(struct wpa_supplica
  113. wpabuf_free(wpa_s->wps->dh_pubkey);
  114. wpabuf_free(wpa_s->wps->dh_privkey);
  115. wpabuf_free(wpa_s->wps->dev.vendor_ext_m1);
  116. + wpabuf_free(wpa_s->wps->m7_encr_extra);
  117. os_free(wpa_s->wps->network_key);
  118. os_free(wpa_s->wps);
  119. wpa_s->wps = NULL;
  120. --- a/hostapd/Makefile
  121. +++ b/hostapd/Makefile
  122. @@ -169,9 +169,22 @@ OBJS += ../src/eapol_auth/eapol_auth_sm.
  123. ifdef CONFIG_UBUS
  124. CFLAGS += -DUBUS_SUPPORT
  125. -OBJS += ../src/utils/uloop.o
  126. OBJS += ../src/ap/ubus.o
  127. -LIBS += -lubox -lubus
  128. +LIBS += -lubus
  129. +NEED_ULOOP:=y
  130. +NEED_BASE64=y
  131. +endif
  132. +
  133. +ifdef CONFIG_UCODE
  134. +CFLAGS += -DUCODE_SUPPORT
  135. +OBJS += ../src/utils/ucode.o
  136. +OBJS += ../src/ap/ucode.o
  137. +NEED_ULOOP:=y
  138. +endif
  139. +
  140. +ifdef NEED_ULOOP
  141. +OBJS += ../src/utils/uloop.o
  142. +LIBS += -lubox
  143. endif
  144. ifdef CONFIG_CODE_COVERAGE
  145. --- a/hostapd/ctrl_iface.c
  146. +++ b/hostapd/ctrl_iface.c
  147. @@ -5951,6 +5951,7 @@ try_again:
  148. return -1;
  149. }
  150. + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
  151. wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
  152. return 0;
  153. @@ -6052,6 +6053,7 @@ fail:
  154. os_free(fname);
  155. interface->global_ctrl_sock = s;
  156. + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
  157. eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
  158. interface, NULL);
  159. --- a/hostapd/main.c
  160. +++ b/hostapd/main.c
  161. @@ -1097,6 +1097,7 @@ int main(int argc, char *argv[])
  162. }
  163. hostapd_global_ctrl_iface_init(&interfaces);
  164. + hostapd_ucode_init(&interfaces);
  165. if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
  166. wpa_printf(MSG_ERROR, "Failed to start eloop");
  167. @@ -1106,6 +1107,7 @@ int main(int argc, char *argv[])
  168. ret = 0;
  169. out:
  170. + hostapd_ucode_free();
  171. hostapd_global_ctrl_iface_deinit(&interfaces);
  172. /* Deinitialize all interfaces */
  173. for (i = 0; i < interfaces.count; i++) {
  174. --- a/src/ap/ap_drv_ops.h
  175. +++ b/src/ap/ap_drv_ops.h
  176. @@ -405,6 +405,23 @@ static inline int hostapd_drv_stop_ap(st
  177. return 0;
  178. }
  179. +static inline int hostapd_drv_if_rename(struct hostapd_data *hapd,
  180. + enum wpa_driver_if_type type,
  181. + const char *ifname,
  182. + const char *new_name)
  183. +{
  184. + if (!hapd->driver || !hapd->driver->if_rename || !hapd->drv_priv)
  185. + return -1;
  186. + return hapd->driver->if_rename(hapd->drv_priv, type, ifname, new_name);
  187. +}
  188. +
  189. +static inline int hostapd_drv_set_first_bss(struct hostapd_data *hapd)
  190. +{
  191. + if (!hapd->driver || !hapd->driver->set_first_bss || !hapd->drv_priv)
  192. + return 0;
  193. + return hapd->driver->set_first_bss(hapd->drv_priv);
  194. +}
  195. +
  196. static inline int hostapd_drv_channel_info(struct hostapd_data *hapd,
  197. struct wpa_channel_info *ci)
  198. {
  199. --- a/src/ap/hostapd.c
  200. +++ b/src/ap/hostapd.c
  201. @@ -263,6 +263,8 @@ int hostapd_reload_config(struct hostapd
  202. struct hostapd_config *newconf, *oldconf;
  203. size_t j;
  204. + hostapd_ucode_reload_bss(hapd);
  205. +
  206. if (iface->config_fname == NULL) {
  207. /* Only in-memory config in use - assume it has been updated */
  208. hostapd_clear_old(iface);
  209. @@ -488,6 +490,7 @@ void hostapd_free_hapd_data(struct hosta
  210. hapd->beacon_set_done = 0;
  211. wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
  212. + hostapd_ucode_free_bss(hapd);
  213. hostapd_ubus_free_bss(hapd);
  214. accounting_deinit(hapd);
  215. hostapd_deinit_wpa(hapd);
  216. @@ -649,7 +652,7 @@ static void hostapd_mld_move_vlan_list(s
  217. * If the BSS being removed is the first link, the next link becomes the first
  218. * link.
  219. */
  220. -static void hostapd_bss_link_deinit(struct hostapd_data *hapd)
  221. +void hostapd_bss_link_deinit(struct hostapd_data *hapd)
  222. {
  223. #ifdef CONFIG_IEEE80211BE
  224. int i;
  225. @@ -757,6 +760,7 @@ void hostapd_cleanup_iface_partial(struc
  226. static void hostapd_cleanup_iface(struct hostapd_iface *iface)
  227. {
  228. wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
  229. + hostapd_ucode_free_iface(iface);
  230. eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
  231. NULL);
  232. @@ -1340,6 +1344,7 @@ static int hostapd_start_beacon(struct h
  233. hapd->driver->set_operstate(hapd->drv_priv, 1);
  234. hostapd_ubus_add_bss(hapd);
  235. + hostapd_ucode_add_bss(hapd);
  236. return 0;
  237. }
  238. @@ -1415,8 +1420,7 @@ static int hostapd_bss_radius_init(struc
  239. * initialized. Most of the modules that are initialized here will be
  240. * deinitialized in hostapd_cleanup().
  241. */
  242. -static int hostapd_setup_bss(struct hostapd_data *hapd, int first,
  243. - bool start_beacon)
  244. +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon)
  245. {
  246. struct hostapd_bss_config *conf = hapd->conf;
  247. u8 ssid[SSID_MAX_LEN + 1];
  248. @@ -1458,12 +1462,17 @@ static int hostapd_setup_bss(struct host
  249. if (!first || first == -1) {
  250. u8 *addr = hapd->own_addr;
  251. + bool use_existing = first == -1;
  252. +#ifdef CONFIG_IEEE80211BE
  253. + if (hapd->conf->mld_ap)
  254. + addr = NULL;
  255. +#endif /* CONFIG_IEEE80211BE */
  256. if (!is_zero_ether_addr(conf->bssid)) {
  257. /* Allocate the configured BSSID. */
  258. os_memcpy(hapd->own_addr, conf->bssid, ETH_ALEN);
  259. - if (hostapd_mac_comp(hapd->own_addr,
  260. + if (0 && hostapd_mac_comp(hapd->own_addr,
  261. hapd->iface->bss[0]->own_addr) ==
  262. 0) {
  263. wpa_printf(MSG_ERROR, "BSS '%s' may not have "
  264. @@ -1493,6 +1502,7 @@ static int hostapd_setup_bss(struct host
  265. hapd->mld_link_id, hapd->conf->iface);
  266. goto setup_mld;
  267. }
  268. + use_existing = true;
  269. }
  270. #endif /* CONFIG_IEEE80211BE */
  271. @@ -1501,7 +1511,7 @@ static int hostapd_setup_bss(struct host
  272. conf->iface, addr, hapd,
  273. &hapd->drv_priv, force_ifname, if_addr,
  274. conf->bridge[0] ? conf->bridge : NULL,
  275. - first == -1)) {
  276. + use_existing)) {
  277. wpa_printf(MSG_ERROR, "Failed to add BSS (BSSID="
  278. MACSTR ")", MAC2STR(hapd->own_addr));
  279. hapd->interface_added = 0;
  280. @@ -1524,7 +1534,7 @@ static int hostapd_setup_bss(struct host
  281. #ifdef CONFIG_IEEE80211BE
  282. setup_mld:
  283. - if (hapd->conf->mld_ap && !first) {
  284. + if (hapd->conf->mld_ap && first != 1) {
  285. wpa_printf(MSG_DEBUG,
  286. "MLD: Set link_id=%u, mld_addr=" MACSTR
  287. ", own_addr=" MACSTR,
  288. @@ -1542,6 +1552,8 @@ setup_mld:
  289. }
  290. #endif /* CONFIG_IEEE80211BE */
  291. + hostapd_ucode_create_bss(hapd);
  292. +
  293. if (conf->wmm_enabled < 0)
  294. conf->wmm_enabled = hapd->iconf->ieee80211n |
  295. hapd->iconf->ieee80211ax;
  296. @@ -1870,7 +1882,7 @@ int hostapd_set_acl(struct hostapd_data
  297. }
  298. -static int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd)
  299. +int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd)
  300. {
  301. #ifdef CONFIG_IEEE80211BE
  302. int ret;
  303. @@ -2543,7 +2555,7 @@ static int hostapd_owe_iface_iter2(struc
  304. #endif /* CONFIG_OWE */
  305. -static void hostapd_owe_update_trans(struct hostapd_iface *iface)
  306. +void hostapd_owe_update_trans(struct hostapd_iface *iface)
  307. {
  308. #ifdef CONFIG_OWE
  309. /* Check whether the enabled BSS can complete OWE transition mode
  310. @@ -3000,7 +3012,7 @@ hostapd_alloc_bss_data(struct hostapd_if
  311. }
  312. -static void hostapd_bss_deinit(struct hostapd_data *hapd)
  313. +void hostapd_bss_deinit(struct hostapd_data *hapd)
  314. {
  315. if (!hapd)
  316. return;
  317. @@ -3208,7 +3220,7 @@ fail:
  318. }
  319. -static void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces)
  320. +void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces)
  321. {
  322. #ifdef CONFIG_IEEE80211BE
  323. struct hostapd_mld *mld, **all_mld;
  324. @@ -4089,7 +4101,8 @@ int hostapd_remove_iface(struct hapd_int
  325. hapd_iface = interfaces->iface[i];
  326. if (hapd_iface == NULL)
  327. return -1;
  328. - if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  329. + if (!os_strcmp(hapd_iface->phy, buf) ||
  330. + !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
  331. wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
  332. hapd_iface->driver_ap_teardown =
  333. !!(hapd_iface->drv_flags &
  334. --- a/src/ap/hostapd.h
  335. +++ b/src/ap/hostapd.h
  336. @@ -19,6 +19,7 @@
  337. #include "ap_config.h"
  338. #include "drivers/driver.h"
  339. #include "ubus.h"
  340. +#include "ucode.h"
  341. #define OCE_STA_CFON_ENABLED(hapd) \
  342. ((hapd->conf->oce & OCE_STA_CFON) && \
  343. @@ -53,6 +54,10 @@ struct hapd_interfaces {
  344. struct hostapd_config * (*config_read_cb)(const char *config_fname);
  345. int (*ctrl_iface_init)(struct hostapd_data *hapd);
  346. void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
  347. + int (*ctrl_iface_recv)(struct hostapd_data *hapd,
  348. + char *buf, char *reply, int reply_size,
  349. + struct sockaddr_storage *from,
  350. + socklen_t fromlen);
  351. int (*for_each_interface)(struct hapd_interfaces *interfaces,
  352. int (*cb)(struct hostapd_iface *iface,
  353. void *ctx), void *ctx);
  354. @@ -213,6 +218,7 @@ struct hostapd_data {
  355. struct hostapd_config *iconf;
  356. struct hostapd_bss_config *conf;
  357. struct hostapd_ubus_bss ubus;
  358. + struct hostapd_ucode_bss ucode;
  359. int interface_added; /* virtual interface added for this BSS */
  360. unsigned int started:1;
  361. unsigned int disabled:1;
  362. @@ -595,6 +601,7 @@ struct hostapd_mld {
  363. */
  364. struct hostapd_iface {
  365. struct hapd_interfaces *interfaces;
  366. + struct hostapd_ucode_iface ucode;
  367. void *owner;
  368. char *config_fname;
  369. struct hostapd_config *conf;
  370. @@ -804,11 +811,16 @@ struct hostapd_iface * hostapd_init(stru
  371. struct hostapd_iface *
  372. hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
  373. const char *config_fname, int debug);
  374. +int hostapd_set_ctrl_sock_iface(struct hostapd_data *hapd);
  375. +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon);
  376. +void hostapd_bss_link_deinit(struct hostapd_data *hapd);
  377. +void hostapd_bss_deinit(struct hostapd_data *hapd);
  378. void hostapd_bss_setup_multi_link(struct hostapd_data *hapd,
  379. struct hapd_interfaces *interfaces);
  380. void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
  381. int reassoc);
  382. void hostapd_interface_deinit_free(struct hostapd_iface *iface);
  383. +void hostapd_cleanup_unused_mlds(struct hapd_interfaces *interfaces);
  384. int hostapd_enable_iface(struct hostapd_iface *hapd_iface);
  385. int hostapd_reload_iface(struct hostapd_iface *hapd_iface);
  386. int hostapd_reload_bss_only(struct hostapd_data *bss);
  387. @@ -834,6 +846,7 @@ hostapd_switch_channel_fallback(struct h
  388. void hostapd_cleanup_cs_params(struct hostapd_data *hapd);
  389. void hostapd_periodic_iface(struct hostapd_iface *iface);
  390. int hostapd_owe_trans_get_info(struct hostapd_data *hapd);
  391. +void hostapd_owe_update_trans(struct hostapd_iface *iface);;
  392. void hostapd_ocv_check_csa_sa_query(void *eloop_ctx, void *timeout_ctx);
  393. void hostapd_switch_color(struct hostapd_data *hapd, u64 bitmap);
  394. --- a/src/ap/ieee802_11.c
  395. +++ b/src/ap/ieee802_11.c
  396. @@ -763,12 +763,17 @@ const char * sae_get_password(struct hos
  397. struct sae_pt **s_pt,
  398. const struct sae_pk **s_pk)
  399. {
  400. + struct hostapd_bss_config *conf = hapd->conf;
  401. + struct hostapd_ssid *ssid = &conf->ssid;
  402. const char *password = NULL;
  403. - struct sae_password_entry *pw;
  404. + struct sae_password_entry *pw = NULL;
  405. struct sae_pt *pt = NULL;
  406. const struct sae_pk *pk = NULL;
  407. struct hostapd_sta_wpa_psk_short *psk = NULL;
  408. + if (sta && sta->use_sta_psk)
  409. + goto use_sta_psk;
  410. +
  411. /* With sae_track_password functionality enabled, try to first find the
  412. * next viable wildcard-address password if a password identifier was
  413. * not used. Select an wildcard-addr entry if the STA is known to have
  414. @@ -830,12 +835,30 @@ const char * sae_get_password(struct hos
  415. pt = hapd->conf->ssid.pt;
  416. }
  417. +use_sta_psk:
  418. if (!password && sta && !rx_id) {
  419. for (psk = sta->psk; psk; psk = psk->next) {
  420. - if (psk->is_passphrase) {
  421. - password = psk->passphrase;
  422. + if (!psk->is_passphrase)
  423. + continue;
  424. +
  425. + password = psk->passphrase;
  426. + if (!sta->use_sta_psk)
  427. + break;
  428. +
  429. +#ifdef CONFIG_SAE
  430. + if (sta->sae_pt) {
  431. + pt = sta->sae_pt;
  432. break;
  433. }
  434. +
  435. + pt = sae_derive_pt(conf->sae_groups, ssid->ssid,
  436. + ssid->ssid_len,
  437. + (const u8 *) password,
  438. + os_strlen(password),
  439. + NULL, 0);
  440. + sta->sae_pt = pt;
  441. + break;
  442. +#endif
  443. }
  444. }
  445. @@ -4466,6 +4489,12 @@ static void handle_auth(struct hostapd_d
  446. goto fail;
  447. }
  448. + res = hostapd_ucode_sta_auth(hapd, sta);
  449. + if (res) {
  450. + resp = res;
  451. + goto fail;
  452. + }
  453. +
  454. sta->flags &= ~WLAN_STA_PREAUTH;
  455. ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
  456. --- a/src/ap/sta_info.c
  457. +++ b/src/ap/sta_info.c
  458. @@ -541,6 +541,11 @@ void ap_free_sta(struct hostapd_data *ha
  459. os_free(sta->eap_auth_data.rsnxe);
  460. #endif /* CONFIG_IEEE8021X_AUTH */
  461. +#ifdef CONFIG_SAE
  462. + if (sta->sae_pt)
  463. + sae_deinit_pt(sta->sae_pt);
  464. +#endif
  465. +
  466. os_free(sta);
  467. }
  468. @@ -1764,6 +1769,8 @@ void ap_sta_set_authorized_event(struct
  469. #endif /* CONFIG_P2P */
  470. const u8 *ip_ptr = NULL;
  471. + if (authorized)
  472. + hostapd_ucode_sta_connected(hapd, sta);
  473. #ifdef CONFIG_P2P
  474. if (hapd->p2p_group == NULL) {
  475. if (sta->p2p_ie != NULL &&
  476. --- a/src/ap/sta_info.h
  477. +++ b/src/ap/sta_info.h
  478. @@ -209,6 +209,9 @@ struct sta_info {
  479. int vlan_id_bound; /* updated by ap_sta_bind_vlan() */
  480. /* PSKs from RADIUS authentication server */
  481. struct hostapd_sta_wpa_psk_short *psk;
  482. + struct sae_pt *sae_pt;
  483. + int use_sta_psk;
  484. + int psk_idx;
  485. char *identity; /* User-Name from RADIUS */
  486. char *radius_cui; /* Chargeable-User-Identity from RADIUS */
  487. --- a/src/ap/wpa_auth_glue.c
  488. +++ b/src/ap/wpa_auth_glue.c
  489. @@ -484,6 +484,7 @@ static const u8 * hostapd_wpa_auth_get_p
  490. struct sta_info *sta = ap_get_sta(hapd, addr);
  491. const u8 *psk;
  492. + sta->psk_idx = 0;
  493. if (vlan_id)
  494. *vlan_id = 0;
  495. if (psk_len)
  496. @@ -534,13 +535,18 @@ static const u8 * hostapd_wpa_auth_get_p
  497. * returned psk which should not be returned again.
  498. * logic list (all hostapd_get_psk; all sta->psk)
  499. */
  500. + if (sta && sta->use_sta_psk)
  501. + psk = NULL;
  502. if (sta && sta->psk && !psk) {
  503. struct hostapd_sta_wpa_psk_short *pos;
  504. + int psk_idx = 1;
  505. if (vlan_id)
  506. *vlan_id = 0;
  507. psk = sta->psk->psk;
  508. - for (pos = sta->psk; pos; pos = pos->next) {
  509. + if (vlan_id)
  510. + sta->psk_idx = psk_idx;
  511. + for (pos = sta->psk; pos; pos = pos->next, psk_idx++) {
  512. if (pos->is_passphrase) {
  513. if (pbkdf2_sha1(pos->passphrase,
  514. hapd->conf->ssid.ssid,
  515. @@ -554,9 +560,13 @@ static const u8 * hostapd_wpa_auth_get_p
  516. }
  517. if (pos->psk == prev_psk) {
  518. psk = pos->next ? pos->next->psk : NULL;
  519. + if (vlan_id)
  520. + sta->psk_idx = psk_idx + 1;
  521. break;
  522. }
  523. }
  524. + if (vlan_id && !psk)
  525. + sta->psk_idx = 0;
  526. }
  527. return psk;
  528. }
  529. --- a/src/drivers/driver.h
  530. +++ b/src/drivers/driver.h
  531. @@ -4176,6 +4176,25 @@ struct wpa_driver_ops {
  532. const char *ifname);
  533. /**
  534. + * if_rename - Rename a virtual interface
  535. + * @priv: Private driver interface data
  536. + * @type: Interface type
  537. + * @ifname: Interface name of the virtual interface to be renamed
  538. + * (NULL when renaming the AP BSS interface)
  539. + * @new_name: New interface name of the virtual interface
  540. + * Returns: 0 on success, -1 on failure
  541. + */
  542. + int (*if_rename)(void *priv, enum wpa_driver_if_type type,
  543. + const char *ifname, const char *new_name);
  544. +
  545. + /**
  546. + * set_first_bss - Make a virtual interface the first (primary) bss
  547. + * @priv: Private driver interface data
  548. + * Returns: 0 on success, -1 on failure
  549. + */
  550. + int (*set_first_bss)(void *priv);
  551. +
  552. + /**
  553. * set_sta_vlan - Bind a station into a specific interface (AP only)
  554. * @priv: Private driver interface data
  555. * @ifname: Interface (main or virtual BSS or VLAN)
  556. @@ -7027,6 +7046,7 @@ union wpa_event_data {
  557. /**
  558. * struct ch_switch
  559. + * @count: Count until channel switch activates
  560. * @freq: Frequency of new channel in MHz
  561. * @ht_enabled: Whether this is an HT channel
  562. * @ch_offset: Secondary channel offset
  563. @@ -7037,6 +7057,7 @@ union wpa_event_data {
  564. * @punct_bitmap: Puncturing bitmap
  565. */
  566. struct ch_switch {
  567. + int count;
  568. int freq;
  569. int ht_enabled;
  570. int ch_offset;
  571. --- a/src/drivers/driver_nl80211.c
  572. +++ b/src/drivers/driver_nl80211.c
  573. @@ -77,6 +77,16 @@ enum nlmsgerr_attrs {
  574. #endif /* ANDROID */
  575. +static void handle_nl_debug_hook(struct nl_msg *msg, int tx)
  576. +{
  577. + const struct nlmsghdr *nlh;
  578. +
  579. + if (!wpa_netlink_hook)
  580. + return;
  581. +
  582. + nlh = nlmsg_hdr(msg);
  583. + wpa_netlink_hook(tx, nlh, nlh->nlmsg_len);
  584. +}
  585. static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
  586. {
  587. @@ -449,6 +459,11 @@ static int no_seq_check(struct nl_msg *m
  588. return NL_OK;
  589. }
  590. +static int debug_handler(struct nl_msg *msg, void *arg)
  591. +{
  592. + handle_nl_debug_hook(msg, 0);
  593. + return NL_OK;
  594. +}
  595. static void nl80211_nlmsg_clear(struct nl_msg *msg)
  596. {
  597. @@ -633,6 +648,8 @@ int send_and_recv_glb(struct nl80211_glo
  598. if (!msg)
  599. return -ENOMEM;
  600. + handle_nl_debug_hook(msg, 1);
  601. +
  602. err.err = -ENOMEM;
  603. s_nl_cb = nl_socket_get_cb(nl_handle);
  604. @@ -677,6 +694,7 @@ int send_and_recv_glb(struct nl80211_glo
  605. err.err_info = err_info;
  606. err.drv = drv;
  607. + nl_cb_set(cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  608. nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
  609. nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err.err);
  610. if (ack_handler_custom) {
  611. @@ -1105,6 +1123,7 @@ nl80211_get_wiphy_data_ap(struct i802_bs
  612. os_free(w);
  613. return NULL;
  614. }
  615. + nl_cb_set(w->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  616. nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  617. no_seq_check, NULL);
  618. nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  619. @@ -2212,6 +2231,7 @@ static int wpa_driver_nl80211_init_nl_gl
  620. /* Needs to be registered early so that process_global_event() calls
  621. * the sync reply handler hook.
  622. */
  623. + nl_cb_set(global->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  624. nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  625. no_seq_check, NULL);
  626. nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  627. @@ -2445,6 +2465,7 @@ static int nl80211_init_bss(struct i802_
  628. if (!bss->nl_cb)
  629. return -1;
  630. + nl_cb_set(bss->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
  631. nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  632. no_seq_check, NULL);
  633. nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  634. @@ -9180,6 +9201,7 @@ static void *i802_init(struct hostapd_da
  635. char master_ifname[IFNAMSIZ];
  636. int ifindex, br_ifindex = 0;
  637. int br_added = 0;
  638. + int err;
  639. bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
  640. params->global_priv, 1,
  641. @@ -9240,21 +9262,17 @@ static void *i802_init(struct hostapd_da
  642. (params->num_bridge == 0 || !params->bridge[0]))
  643. add_ifidx(drv, br_ifindex, drv->ifindex);
  644. - if (bss->added_if_into_bridge || bss->already_in_bridge) {
  645. - int err;
  646. -
  647. - drv->rtnl_sk = nl_socket_alloc();
  648. - if (drv->rtnl_sk == NULL) {
  649. - wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  650. - goto failed;
  651. - }
  652. + drv->rtnl_sk = nl_socket_alloc();
  653. + if (drv->rtnl_sk == NULL) {
  654. + wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  655. + goto failed;
  656. + }
  657. - err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  658. - if (err) {
  659. - wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  660. - nl_geterror(err));
  661. - goto failed;
  662. - }
  663. + err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
  664. + if (err) {
  665. + wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  666. + nl_geterror(err));
  667. + goto failed;
  668. }
  669. if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
  670. @@ -9641,6 +9659,50 @@ static int wpa_driver_nl80211_if_remove(
  671. return 0;
  672. }
  673. +static int wpa_driver_nl80211_if_rename(struct i802_bss *bss,
  674. + enum wpa_driver_if_type type,
  675. + const char *ifname, const char *new_name)
  676. +{
  677. + struct wpa_driver_nl80211_data *drv = bss->drv;
  678. + struct ifinfomsg ifi = {
  679. + .ifi_family = AF_UNSPEC,
  680. + .ifi_index = bss->ifindex,
  681. + };
  682. + struct nl_msg *msg;
  683. + int res = -ENOMEM;
  684. +
  685. + if (ifname)
  686. + ifi.ifi_index = if_nametoindex(ifname);
  687. +
  688. + msg = nlmsg_alloc_simple(RTM_SETLINK, 0);
  689. + if (!msg)
  690. + return res;
  691. +
  692. + if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0)
  693. + goto out;
  694. +
  695. + if (nla_put_string(msg, IFLA_IFNAME, new_name))
  696. + goto out;
  697. +
  698. + res = nl_send_auto_complete(drv->rtnl_sk, msg);
  699. + if (res < 0)
  700. + goto out;
  701. +
  702. + res = nl_wait_for_ack(drv->rtnl_sk);
  703. + if (res) {
  704. + wpa_printf(MSG_INFO,
  705. + "nl80211: Renaming device %s to %s failed: %s",
  706. + ifname ? ifname : bss->ifname, new_name, nl_geterror(res));
  707. + goto out;
  708. + }
  709. +
  710. + if (type == WPA_IF_AP_BSS && !ifname)
  711. + os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname));
  712. +
  713. +out:
  714. + nlmsg_free(msg);
  715. + return res;
  716. +}
  717. static int cookie_handler(struct nl_msg *msg, void *arg)
  718. {
  719. @@ -11540,6 +11602,37 @@ static bool nl80211_is_drv_shared(void *
  720. #endif /* CONFIG_IEEE80211BE */
  721. +static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type,
  722. + const char *ifname, const char *new_name)
  723. +{
  724. + struct i802_bss *bss = priv;
  725. + return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name);
  726. +}
  727. +
  728. +
  729. +static int driver_nl80211_set_first_bss(void *priv)
  730. +{
  731. + struct i802_bss *bss = priv, *tbss;
  732. + struct wpa_driver_nl80211_data *drv = bss->drv;
  733. +
  734. + if (drv->first_bss == bss)
  735. + return 0;
  736. +
  737. + for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
  738. + if (tbss->next != bss)
  739. + continue;
  740. +
  741. + tbss->next = bss->next;
  742. + bss->next = drv->first_bss;
  743. + drv->first_bss = bss;
  744. + drv->ctx = bss->ctx;
  745. + return 0;
  746. + }
  747. +
  748. + return -1;
  749. +}
  750. +
  751. +
  752. static int driver_nl80211_send_mlme(void *priv, const u8 *data,
  753. size_t data_len, int noack,
  754. unsigned int freq,
  755. @@ -15546,6 +15639,8 @@ const struct wpa_driver_ops wpa_driver_n
  756. .set_acl = wpa_driver_nl80211_set_acl,
  757. .if_add = wpa_driver_nl80211_if_add,
  758. .if_remove = driver_nl80211_if_remove,
  759. + .if_rename = driver_nl80211_if_rename,
  760. + .set_first_bss = driver_nl80211_set_first_bss,
  761. .send_mlme = driver_nl80211_send_mlme,
  762. .get_hw_feature_data = nl80211_get_hw_feature_data,
  763. .sta_add = wpa_driver_nl80211_sta_add,
  764. --- a/src/drivers/driver_nl80211_event.c
  765. +++ b/src/drivers/driver_nl80211_event.c
  766. @@ -1263,6 +1263,7 @@ static void mlme_event_ch_switch(struct
  767. struct nlattr *bw, struct nlattr *cf1,
  768. struct nlattr *cf2,
  769. struct nlattr *punct_bitmap,
  770. + struct nlattr *count,
  771. int finished)
  772. {
  773. struct i802_bss *bss;
  774. @@ -1328,6 +1329,8 @@ static void mlme_event_ch_switch(struct
  775. data.ch_switch.cf1 = nla_get_u32(cf1);
  776. if (cf2)
  777. data.ch_switch.cf2 = nla_get_u32(cf2);
  778. + if (count)
  779. + data.ch_switch.count = nla_get_u32(count);
  780. if (link) {
  781. data.ch_switch.link_id = nla_get_u8(link);
  782. @@ -4423,6 +4426,7 @@ static void do_process_drv_event(struct
  783. tb[NL80211_ATTR_CENTER_FREQ1],
  784. tb[NL80211_ATTR_CENTER_FREQ2],
  785. tb[NL80211_ATTR_PUNCT_BITMAP],
  786. + tb[NL80211_ATTR_CH_SWITCH_COUNT],
  787. 0);
  788. break;
  789. case NL80211_CMD_CH_SWITCH_NOTIFY:
  790. @@ -4435,6 +4439,7 @@ static void do_process_drv_event(struct
  791. tb[NL80211_ATTR_CENTER_FREQ1],
  792. tb[NL80211_ATTR_CENTER_FREQ2],
  793. tb[NL80211_ATTR_PUNCT_BITMAP],
  794. + NULL,
  795. 1);
  796. break;
  797. case NL80211_CMD_DISCONNECT:
  798. --- a/src/utils/wpa_debug.c
  799. +++ b/src/utils/wpa_debug.c
  800. @@ -26,6 +26,10 @@ static FILE *wpa_debug_tracing_file = NU
  801. #define WPAS_TRACE_PFX "wpas <%d>: "
  802. #endif /* CONFIG_DEBUG_LINUX_TRACING */
  803. +void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  804. +void (*wpa_hexdump_hook)(int level, const char *title, const void *buf,
  805. + size_t len);
  806. +void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  807. int wpa_debug_level = MSG_INFO;
  808. int wpa_debug_show_keys = 0;
  809. @@ -224,6 +228,12 @@ void _wpa_printf(int level, const char *
  810. {
  811. va_list ap;
  812. + if (wpa_printf_hook) {
  813. + va_start(ap, fmt);
  814. + wpa_printf_hook(level, fmt, ap);
  815. + va_end(ap);
  816. + }
  817. +
  818. if (level >= wpa_debug_level) {
  819. #ifdef CONFIG_ANDROID_LOG
  820. va_start(ap, fmt);
  821. @@ -274,6 +284,9 @@ void _wpa_hexdump(int level, const char
  822. {
  823. size_t i;
  824. + if (wpa_hexdump_hook)
  825. + wpa_hexdump_hook(level, title, buf, len);
  826. +
  827. #ifdef CONFIG_DEBUG_LINUX_TRACING
  828. if (wpa_debug_tracing_file != NULL) {
  829. fprintf(wpa_debug_tracing_file,
  830. --- a/src/utils/wpa_debug.h
  831. +++ b/src/utils/wpa_debug.h
  832. @@ -11,6 +11,10 @@
  833. #include "wpabuf.h"
  834. +extern void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
  835. +extern void (*wpa_hexdump_hook)(int level, const char *title,
  836. + const void *buf, size_t len);
  837. +extern void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
  838. extern int wpa_debug_level;
  839. extern int wpa_debug_show_keys;
  840. extern int wpa_debug_timestamp;
  841. --- a/wpa_supplicant/Makefile
  842. +++ b/wpa_supplicant/Makefile
  843. @@ -191,6 +191,14 @@ ifdef CONFIG_EAPOL_TEST
  844. CFLAGS += -Werror -DEAPOL_TEST
  845. endif
  846. +ifdef CONFIG_UCODE
  847. +CFLAGS += -DUCODE_SUPPORT
  848. +OBJS += ../src/utils/ucode.o
  849. +OBJS += ../src/utils/uloop.o
  850. +OBJS += ucode.o
  851. +LIBS += -lubox
  852. +endif
  853. +
  854. ifdef CONFIG_CODE_COVERAGE
  855. CFLAGS += -O0 -fprofile-arcs -ftest-coverage -U_FORTIFY_SOURCE
  856. LIBS += -lgcov
  857. @@ -1082,6 +1090,9 @@ ifdef CONFIG_CTRL_IFACE_MIB
  858. CFLAGS += -DCONFIG_CTRL_IFACE_MIB
  859. endif
  860. OBJS += ../src/ap/ctrl_iface_ap.o
  861. +ifdef CONFIG_UCODE
  862. +OBJS += ../src/ap/ucode.o
  863. +endif
  864. endif
  865. CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
  866. --- a/wpa_supplicant/events.c
  867. +++ b/wpa_supplicant/events.c
  868. @@ -54,6 +54,7 @@
  869. #include "dpp_supplicant.h"
  870. #include "pr_supplicant.h"
  871. #include "nan_supplicant.h"
  872. +#include "ucode.h"
  873. #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5
  874. @@ -1729,6 +1730,12 @@ struct wpa_ssid * wpa_scan_res_match(str
  875. return NULL;
  876. }
  877. + if (!wpas_ucode_bss_allowed(wpa_s, bss)) {
  878. + if (debug_print)
  879. + wpa_dbg(wpa_s, MSG_DEBUG, " skip - denied by ucode handler");
  880. + return NULL;
  881. + }
  882. +
  883. for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) {
  884. if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len,
  885. bss, bssid_ignore_count, debug_print, link))
  886. @@ -3139,8 +3146,8 @@ fail:
  887. static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s,
  888. const u8 *ies, size_t ies_len)
  889. {
  890. + struct multi_ap_params *multi_ap = &wpa_s->multi_ap;
  891. struct ieee802_11_elems elems;
  892. - struct multi_ap_params multi_ap;
  893. u16 status;
  894. wpa_s->multi_ap_ie = 0;
  895. @@ -3151,13 +3158,13 @@ static void multi_ap_process_assoc_resp(
  896. return;
  897. status = check_multi_ap_ie(elems.multi_ap + 4, elems.multi_ap_len - 4,
  898. - &multi_ap);
  899. + multi_ap);
  900. if (status != WLAN_STATUS_SUCCESS)
  901. return;
  902. - wpa_s->multi_ap_backhaul = !!(multi_ap.capability &
  903. + wpa_s->multi_ap_backhaul = !!(multi_ap->capability &
  904. MULTI_AP_BACKHAUL_BSS);
  905. - wpa_s->multi_ap_fronthaul = !!(multi_ap.capability &
  906. + wpa_s->multi_ap_fronthaul = !!(multi_ap->capability &
  907. MULTI_AP_FRONTHAUL_BSS);
  908. wpa_s->multi_ap_ie = 1;
  909. }
  910. @@ -5857,6 +5864,13 @@ static void wpas_event_rx_mgmt_action(st
  911. }
  912. #endif /* CONFIG_WNM */
  913. +#if defined(CONFIG_GAS) && defined(CONFIG_DPP)
  914. + if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
  915. + mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
  916. + wpas_ucode_dpp_gas_rx(wpa_s, mgmt->sa, payload, plen, freq))
  917. + return;
  918. +#endif /* CONFIG_GAS && CONFIG_DPP */
  919. +
  920. #ifdef CONFIG_GAS
  921. if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC ||
  922. mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) &&
  923. @@ -6663,6 +6677,7 @@ void supplicant_event(void *ctx, enum wp
  924. event_to_string(event), event);
  925. #endif /* CONFIG_NO_STDOUT_DEBUG */
  926. + wpas_ucode_event(wpa_s, event, data);
  927. switch (event) {
  928. case EVENT_AUTH:
  929. #ifdef CONFIG_FST
  930. --- a/wpa_supplicant/ctrl_iface_unix.c
  931. +++ b/wpa_supplicant/ctrl_iface_unix.c
  932. @@ -28,6 +28,7 @@
  933. #include "config.h"
  934. #include "wpa_supplicant_i.h"
  935. #include "ctrl_iface.h"
  936. +#include "ucode.h"
  937. /* Per-interface ctrl_iface */
  938. @@ -436,6 +437,7 @@ static void wpa_supplicant_ctrl_iface_ms
  939. if (wpa_s == NULL)
  940. return;
  941. + wpas_ucode_ctrl_event(wpa_s, txt, len);
  942. gpriv = wpa_s->global->ctrl_iface;
  943. if (type != WPA_MSG_NO_GLOBAL && gpriv &&
  944. --- a/src/ap/dpp_hostapd.c
  945. +++ b/src/ap/dpp_hostapd.c
  946. @@ -23,6 +23,7 @@
  947. #include "wpa_auth.h"
  948. #include "beacon.h"
  949. #include "dpp_hostapd.h"
  950. +#include "ucode.h"
  951. static void hostapd_dpp_reply_wait_timeout(void *eloop_ctx, void *timeout_ctx);
  952. @@ -3017,6 +3018,9 @@ void hostapd_dpp_rx_action(struct hostap
  953. wpa_msg(hapd->msg_ctx, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  954. " freq=%u type=%d", MAC2STR(src), freq, type);
  955. + if (hostapd_ucode_dpp_rx_action(hapd, src, type, freq, hdr, len + 6))
  956. + return;
  957. +
  958. #ifdef CONFIG_DPP2
  959. if (dpp_relay_rx_action(hapd->iface->interfaces->dpp,
  960. src, hdr, buf, len, freq, NULL, NULL,
  961. @@ -3116,13 +3120,19 @@ void hostapd_dpp_rx_action(struct hostap
  962. struct wpabuf *
  963. hostapd_dpp_gas_req_handler(struct hostapd_data *hapd, const u8 *sa,
  964. - const u8 *query, size_t query_len,
  965. + u8 dialog_token, const u8 *query, size_t query_len,
  966. const u8 *data, size_t data_len)
  967. {
  968. struct dpp_authentication *auth = hapd->dpp_auth;
  969. struct wpabuf *resp;
  970. wpa_printf(MSG_DEBUG, "DPP: GAS request from " MACSTR, MAC2STR(sa));
  971. +
  972. + resp = hostapd_ucode_dpp_gas_req(hapd, sa, dialog_token,
  973. + query, query_len);
  974. + if (resp)
  975. + return resp;
  976. +
  977. eloop_cancel_timeout(hostapd_gas_req_wait, hapd, NULL);
  978. if (!auth || (!auth->auth_success && !auth->reconfig_success) ||
  979. !ether_addr_equal(sa, auth->peer_mac_addr)) {
  980. --- a/src/ap/dpp_hostapd.h
  981. +++ b/src/ap/dpp_hostapd.h
  982. @@ -25,7 +25,7 @@ void hostapd_dpp_tx_status(struct hostap
  983. const u8 *data, size_t data_len, int ok);
  984. struct wpabuf *
  985. hostapd_dpp_gas_req_handler(struct hostapd_data *hapd, const u8 *sa,
  986. - const u8 *query, size_t query_len,
  987. + u8 dialog_token, const u8 *query, size_t query_len,
  988. const u8 *data, size_t data_len);
  989. void hostapd_dpp_gas_status_handler(struct hostapd_data *hapd, int ok);
  990. int hostapd_dpp_configurator_add(struct hostapd_data *hapd, const char *cmd);
  991. --- a/src/ap/gas_serv.c
  992. +++ b/src/ap/gas_serv.c
  993. @@ -1402,8 +1402,8 @@ static void gas_serv_rx_gas_initial_req(
  994. if (dpp) {
  995. struct wpabuf *msg;
  996. - msg = hostapd_dpp_gas_req_handler(hapd, sa, pos, slen,
  997. - data, len);
  998. + msg = hostapd_dpp_gas_req_handler(hapd, sa, dialog_token,
  999. + pos, slen, data, len);
  1000. if (!msg)
  1001. return;
  1002. gas_serv_req_dpp_processing(hapd, sa, dialog_token, prot, msg,
  1003. --- a/wpa_supplicant/dpp_supplicant.c
  1004. +++ b/wpa_supplicant/dpp_supplicant.c
  1005. @@ -29,6 +29,7 @@
  1006. #include "scan.h"
  1007. #include "notify.h"
  1008. #include "dpp_supplicant.h"
  1009. +#include "ucode.h"
  1010. static int wpas_dpp_listen_start(struct wpa_supplicant *wpa_s,
  1011. @@ -4119,6 +4120,9 @@ void wpas_dpp_rx_action(struct wpa_suppl
  1012. return;
  1013. }
  1014. wpa_hexdump(MSG_MSGDUMP, "DPP: Received message attributes", buf, len);
  1015. + if (wpas_ucode_dpp_rx_action(wpa_s, src, type, freq, hdr, len + DPP_HDR_LEN))
  1016. + return;
  1017. +
  1018. if (dpp_check_attrs(buf, len) < 0) {
  1019. wpa_msg(wpa_s, MSG_INFO, DPP_EVENT_RX "src=" MACSTR
  1020. " freq=%u type=%d ignore=invalid-attributes",
  1021. --- a/src/ap/wps_hostapd.c
  1022. +++ b/src/ap/wps_hostapd.c
  1023. @@ -27,6 +27,7 @@
  1024. #include "beacon.h"
  1025. #include "sta_info.h"
  1026. #include "wps_hostapd.h"
  1027. +#include "ucode.h"
  1028. #ifdef CONFIG_WPS_UPNP
  1029. @@ -719,6 +720,17 @@ static int hostapd_wps_cred_cb(void *ctx
  1030. }
  1031. +static void hostapd_wps_m7_rx_cb(void *ctx, const u8 *addr,
  1032. + const u8 *data, size_t data_len,
  1033. + struct wpabuf **m8_encr_extra,
  1034. + int *skip_cred)
  1035. +{
  1036. + struct hostapd_data *hapd = ctx;
  1037. + hostapd_ucode_wps_m7_rx(hapd, addr, data, data_len,
  1038. + m8_encr_extra, skip_cred);
  1039. +}
  1040. +
  1041. +
  1042. static void hostapd_wps_reenable_ap_pin(void *eloop_data, void *user_ctx)
  1043. {
  1044. struct hostapd_data *hapd = eloop_data;
  1045. @@ -1096,6 +1108,7 @@ int hostapd_init_wps(struct hostapd_data
  1046. return -1;
  1047. wps->cred_cb = hostapd_wps_cred_cb;
  1048. + wps->m7_rx_cb = hostapd_wps_m7_rx_cb;
  1049. wps->event_cb = hostapd_wps_event_cb;
  1050. wps->rf_band_cb = hostapd_wps_rf_band_cb;
  1051. wps->cb_ctx = hapd;
  1052. --- a/src/wps/wps.c
  1053. +++ b/src/wps/wps.c
  1054. @@ -182,6 +182,7 @@ void wps_deinit(struct wps_data *data)
  1055. bin_clear_free(data->new_psk, data->new_psk_len);
  1056. wps_device_data_free(&data->peer_dev);
  1057. bin_clear_free(data->new_ap_settings, sizeof(*data->new_ap_settings));
  1058. + wpabuf_free(data->m8_encr_extra);
  1059. dh5_free(data->dh_ctx);
  1060. os_free(data);
  1061. }
  1062. --- a/src/wps/wps.h
  1063. +++ b/src/wps/wps.h
  1064. @@ -850,6 +850,14 @@ struct wps_context {
  1065. /* Whether to send WPA2-PSK passphrase as a passphrase instead of PSK
  1066. * for WPA3-Personal transition mode needs. */
  1067. bool use_passphrase;
  1068. +
  1069. + struct wpabuf *m7_encr_extra;
  1070. +
  1071. + void (*m7_rx_cb)(void *ctx, const u8 *addr,
  1072. + const u8 *data, size_t data_len,
  1073. + struct wpabuf **m8_encr_extra, int *skip_cred);
  1074. +
  1075. + int (*m8_rx_cb)(void *ctx, const u8 *data, size_t data_len);
  1076. };
  1077. struct wps_registrar *
  1078. --- a/src/wps/wps_enrollee.c
  1079. +++ b/src/wps/wps_enrollee.c
  1080. @@ -377,14 +377,17 @@ static int wps_build_ap_settings(struct
  1081. static struct wpabuf * wps_build_m7(struct wps_data *wps)
  1082. {
  1083. struct wpabuf *msg, *plain;
  1084. + size_t extra_len;
  1085. wpa_printf(MSG_DEBUG, "WPS: Building Message M7");
  1086. - plain = wpabuf_alloc(500 + wps->wps->ap_settings_len);
  1087. + extra_len = wps->wps->m7_encr_extra ?
  1088. + wpabuf_len(wps->wps->m7_encr_extra) : 0;
  1089. + plain = wpabuf_alloc(500 + wps->wps->ap_settings_len + extra_len);
  1090. if (plain == NULL)
  1091. return NULL;
  1092. - msg = wpabuf_alloc(1000 + wps->wps->ap_settings_len);
  1093. + msg = wpabuf_alloc(1000 + wps->wps->ap_settings_len + extra_len);
  1094. if (msg == NULL) {
  1095. wpabuf_free(plain);
  1096. return NULL;
  1097. @@ -394,8 +397,16 @@ static struct wpabuf * wps_build_m7(stru
  1098. wps_build_msg_type(msg, WPS_M7) ||
  1099. wps_build_registrar_nonce(wps, msg) ||
  1100. wps_build_e_snonce2(wps, plain) ||
  1101. - (wps->wps->ap && wps_build_ap_settings(wps, plain)) ||
  1102. - wps_build_key_wrap_auth(wps, plain) ||
  1103. + (wps->wps->ap && wps_build_ap_settings(wps, plain))) {
  1104. + wpabuf_clear_free(plain);
  1105. + wpabuf_free(msg);
  1106. + return NULL;
  1107. + }
  1108. +
  1109. + if (wps->wps->m7_encr_extra)
  1110. + wpabuf_put_buf(plain, wps->wps->m7_encr_extra);
  1111. +
  1112. + if (wps_build_key_wrap_auth(wps, plain) ||
  1113. wps_build_encr_settings(wps, msg, plain) ||
  1114. wps_build_wfa_ext(msg, 0, NULL, 0, 0) ||
  1115. wps_build_authenticator(wps, msg)) {
  1116. @@ -1258,8 +1269,22 @@ static enum wps_process_res wps_process_
  1117. wpa_printf(MSG_DEBUG, "WPS: Processing decrypted Encrypted Settings "
  1118. "attribute");
  1119. if (wps_parse_msg(decrypted, &eattr) < 0 ||
  1120. - wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth) ||
  1121. - wps_process_creds(wps, eattr.cred, eattr.cred_len,
  1122. + wps_process_key_wrap_auth(wps, decrypted, eattr.key_wrap_auth)) {
  1123. + wpabuf_clear_free(decrypted);
  1124. + wps->state = SEND_WSC_NACK;
  1125. + return WPS_CONTINUE;
  1126. + }
  1127. +
  1128. + if (wps->wps->m8_rx_cb &&
  1129. + wps->wps->m8_rx_cb(wps->wps->cb_ctx,
  1130. + wpabuf_head(decrypted),
  1131. + wpabuf_len(decrypted))) {
  1132. + wpabuf_clear_free(decrypted);
  1133. + wps->state = WPS_MSG_DONE;
  1134. + return WPS_CONTINUE;
  1135. + }
  1136. +
  1137. + if (wps_process_creds(wps, eattr.cred, eattr.cred_len,
  1138. eattr.num_cred, attr->version2 != NULL) ||
  1139. wps_process_ap_settings_e(wps, &eattr, decrypted,
  1140. attr->version2 != NULL)) {
  1141. --- a/src/wps/wps_i.h
  1142. +++ b/src/wps/wps_i.h
  1143. @@ -128,6 +128,9 @@ struct wps_data {
  1144. int multi_ap_backhaul_sta;
  1145. int multi_ap_profile;
  1146. +
  1147. + struct wpabuf *m8_encr_extra;
  1148. + int skip_cred;
  1149. };
  1150. --- a/src/wps/wps_registrar.c
  1151. +++ b/src/wps/wps_registrar.c
  1152. @@ -2064,14 +2064,17 @@ static struct wpabuf * wps_build_m6(stru
  1153. static struct wpabuf * wps_build_m8(struct wps_data *wps)
  1154. {
  1155. struct wpabuf *msg, *plain;
  1156. + size_t extra_len;
  1157. wpa_printf(MSG_DEBUG, "WPS: Building Message M8");
  1158. - plain = wpabuf_alloc(500);
  1159. + extra_len = wps->m8_encr_extra ?
  1160. + wpabuf_len(wps->m8_encr_extra) : 0;
  1161. + plain = wpabuf_alloc(500 + extra_len);
  1162. if (plain == NULL)
  1163. return NULL;
  1164. - msg = wpabuf_alloc(1000);
  1165. + msg = wpabuf_alloc(1000 + extra_len);
  1166. if (msg == NULL) {
  1167. wpabuf_free(plain);
  1168. return NULL;
  1169. @@ -2080,9 +2083,19 @@ static struct wpabuf * wps_build_m8(stru
  1170. if (wps_build_version(msg) ||
  1171. wps_build_msg_type(msg, WPS_M8) ||
  1172. wps_build_enrollee_nonce(wps, msg) ||
  1173. - ((wps->wps->ap || wps->er) && wps_build_cred(wps, plain)) ||
  1174. - (!wps->wps->ap && !wps->er && wps_build_ap_settings(wps, plain)) ||
  1175. - wps_build_key_wrap_auth(wps, plain) ||
  1176. + (!wps->skip_cred && (wps->wps->ap || wps->er) &&
  1177. + wps_build_cred(wps, plain)) ||
  1178. + (!wps->skip_cred && !wps->wps->ap && !wps->er &&
  1179. + wps_build_ap_settings(wps, plain))) {
  1180. + wpabuf_clear_free(plain);
  1181. + wpabuf_clear_free(msg);
  1182. + return NULL;
  1183. + }
  1184. +
  1185. + if (wps->m8_encr_extra)
  1186. + wpabuf_put_buf(plain, wps->m8_encr_extra);
  1187. +
  1188. + if (wps_build_key_wrap_auth(wps, plain) ||
  1189. wps_build_encr_settings(wps, msg, plain) ||
  1190. wps_build_wfa_ext(msg, 0, NULL, 0, 0) ||
  1191. wps_build_authenticator(wps, msg)) {
  1192. @@ -3019,6 +3032,13 @@ static enum wps_process_res wps_process_
  1193. return WPS_CONTINUE;
  1194. }
  1195. + if (wps->wps->m7_rx_cb)
  1196. + wps->wps->m7_rx_cb(wps->wps->cb_ctx, wps->mac_addr_e,
  1197. + wpabuf_head(decrypted),
  1198. + wpabuf_len(decrypted),
  1199. + &wps->m8_encr_extra,
  1200. + &wps->skip_cred);
  1201. +
  1202. wpabuf_clear_free(decrypted);
  1203. wps->state = SEND_M8;