600-ubus_support.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. --- a/hostapd/Makefile
  2. +++ b/hostapd/Makefile
  3. @@ -165,6 +165,11 @@ OBJS += ../src/common/hw_features_common
  4. OBJS += ../src/eapol_auth/eapol_auth_sm.o
  5. +ifdef CONFIG_UBUS
  6. +CFLAGS += -DUBUS_SUPPORT
  7. +OBJS += ../src/ap/ubus.o
  8. +LIBS += -lubox -lubus
  9. +endif
  10. ifdef CONFIG_CODE_COVERAGE
  11. CFLAGS += -O0 -fprofile-arcs -ftest-coverage
  12. --- a/src/ap/hostapd.h
  13. +++ b/src/ap/hostapd.h
  14. @@ -13,6 +13,7 @@
  15. #include "utils/list.h"
  16. #include "ap_config.h"
  17. #include "drivers/driver.h"
  18. +#include "ubus.h"
  19. #define OCE_STA_CFON_ENABLED(hapd) \
  20. ((hapd->conf->oce & OCE_STA_CFON) && \
  21. @@ -136,6 +137,7 @@ struct hostapd_data {
  22. struct hostapd_iface *iface;
  23. struct hostapd_config *iconf;
  24. struct hostapd_bss_config *conf;
  25. + struct hostapd_ubus_bss ubus;
  26. int interface_added; /* virtual interface added for this BSS */
  27. unsigned int started:1;
  28. unsigned int disabled:1;
  29. @@ -547,6 +549,7 @@ hostapd_alloc_bss_data(struct hostapd_if
  30. struct hostapd_bss_config *bss);
  31. int hostapd_setup_interface(struct hostapd_iface *iface);
  32. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  33. +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd);
  34. void hostapd_interface_deinit(struct hostapd_iface *iface);
  35. void hostapd_interface_free(struct hostapd_iface *iface);
  36. struct hostapd_iface * hostapd_alloc_iface(void);
  37. --- a/src/ap/hostapd.c
  38. +++ b/src/ap/hostapd.c
  39. @@ -373,6 +373,7 @@ static void hostapd_free_hapd_data(struc
  40. hapd->started = 0;
  41. wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
  42. + hostapd_ubus_free_bss(hapd);
  43. iapp_deinit(hapd->iapp);
  44. hapd->iapp = NULL;
  45. accounting_deinit(hapd);
  46. @@ -1295,6 +1296,8 @@ static int hostapd_setup_bss(struct host
  47. if (hapd->driver && hapd->driver->set_operstate)
  48. hapd->driver->set_operstate(hapd->drv_priv, 1);
  49. + hostapd_ubus_add_bss(hapd);
  50. +
  51. return 0;
  52. }
  53. @@ -1709,7 +1712,7 @@ static enum nr_chan_width hostapd_get_nr
  54. #endif /* NEED_AP_MLME */
  55. -static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
  56. +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
  57. {
  58. #ifdef NEED_AP_MLME
  59. u16 capab = hostapd_own_capab_info(hapd);
  60. @@ -1930,6 +1933,7 @@ static int hostapd_setup_interface_compl
  61. if (err)
  62. goto fail;
  63. + hostapd_ubus_add_iface(iface);
  64. wpa_printf(MSG_DEBUG, "Completing interface initialization");
  65. if (iface->conf->channel) {
  66. #ifdef NEED_AP_MLME
  67. @@ -2110,6 +2114,7 @@ dfs_offload:
  68. fail:
  69. wpa_printf(MSG_ERROR, "Interface initialization failed");
  70. + hostapd_ubus_free_iface(iface);
  71. hostapd_set_state(iface, HAPD_IFACE_DISABLED);
  72. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
  73. #ifdef CONFIG_FST
  74. @@ -2576,6 +2581,7 @@ void hostapd_interface_deinit_free(struc
  75. (unsigned int) iface->conf->num_bss);
  76. driver = iface->bss[0]->driver;
  77. drv_priv = iface->bss[0]->drv_priv;
  78. + hostapd_ubus_free_iface(iface);
  79. hostapd_interface_deinit(iface);
  80. wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
  81. __func__, driver, drv_priv);
  82. --- a/src/ap/ieee802_11.c
  83. +++ b/src/ap/ieee802_11.c
  84. @@ -1759,12 +1759,13 @@ ieee802_11_set_radius_info(struct hostap
  85. static void handle_auth(struct hostapd_data *hapd,
  86. - const struct ieee80211_mgmt *mgmt, size_t len)
  87. + const struct ieee80211_mgmt *mgmt, size_t len,
  88. + struct hostapd_frame_info *fi)
  89. {
  90. u16 auth_alg, auth_transaction, status_code;
  91. u16 resp = WLAN_STATUS_SUCCESS;
  92. struct sta_info *sta = NULL;
  93. - int res, reply_res;
  94. + int res, reply_res, ubus_resp;
  95. u16 fc;
  96. const u8 *challenge = NULL;
  97. u32 session_timeout, acct_interim_interval;
  98. @@ -1775,6 +1776,11 @@ static void handle_auth(struct hostapd_d
  99. char *identity = NULL;
  100. char *radius_cui = NULL;
  101. u16 seq_ctrl;
  102. + struct hostapd_ubus_request req = {
  103. + .type = HOSTAPD_UBUS_AUTH_REQ,
  104. + .mgmt_frame = mgmt,
  105. + .frame_info = fi,
  106. + };
  107. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  108. wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
  109. @@ -1935,6 +1941,13 @@ static void handle_auth(struct hostapd_d
  110. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  111. goto fail;
  112. }
  113. + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
  114. + if (ubus_resp) {
  115. + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
  116. + MAC2STR(mgmt->sa));
  117. + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
  118. + goto fail;
  119. + }
  120. if (res == HOSTAPD_ACL_PENDING)
  121. return;
  122. @@ -3287,12 +3300,12 @@ void fils_hlp_timeout(void *eloop_ctx, v
  123. static void handle_assoc(struct hostapd_data *hapd,
  124. const struct ieee80211_mgmt *mgmt, size_t len,
  125. - int reassoc)
  126. + int reassoc, struct hostapd_frame_info *fi)
  127. {
  128. u16 capab_info, listen_interval, seq_ctrl, fc;
  129. u16 resp = WLAN_STATUS_SUCCESS, reply_res;
  130. const u8 *pos;
  131. - int left, i;
  132. + int left, i, ubus_resp;
  133. struct sta_info *sta;
  134. u8 *tmp = NULL;
  135. struct hostapd_sta_wpa_psk_short *psk = NULL;
  136. @@ -3301,6 +3314,11 @@ static void handle_assoc(struct hostapd_
  137. #ifdef CONFIG_FILS
  138. int delay_assoc = 0;
  139. #endif /* CONFIG_FILS */
  140. + struct hostapd_ubus_request req = {
  141. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  142. + .mgmt_frame = mgmt,
  143. + .frame_info = fi,
  144. + };
  145. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  146. sizeof(mgmt->u.assoc_req))) {
  147. @@ -3472,6 +3490,14 @@ static void handle_assoc(struct hostapd_
  148. }
  149. #endif /* CONFIG_MBO */
  150. + ubus_resp = hostapd_ubus_handle_event(hapd, &req);
  151. + if (ubus_resp) {
  152. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  153. + MAC2STR(mgmt->sa));
  154. + resp = ubus_resp > 0 ? (u16) ubus_resp : WLAN_STATUS_UNSPECIFIED_FAILURE;
  155. + goto fail;
  156. + }
  157. +
  158. /*
  159. * sta->capability is used in check_assoc_ies() for RRM enabled
  160. * capability element.
  161. @@ -3685,6 +3711,7 @@ static void handle_disassoc(struct hosta
  162. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  163. MAC2STR(mgmt->sa),
  164. le_to_host16(mgmt->u.disassoc.reason_code));
  165. + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
  166. sta = ap_get_sta(hapd, mgmt->sa);
  167. if (sta == NULL) {
  168. @@ -3750,6 +3777,8 @@ static void handle_deauth(struct hostapd
  169. " reason_code=%d",
  170. MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
  171. + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
  172. +
  173. sta = ap_get_sta(hapd, mgmt->sa);
  174. if (sta == NULL) {
  175. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
  176. @@ -4077,7 +4106,7 @@ int ieee802_11_mgmt(struct hostapd_data
  177. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  178. - handle_probe_req(hapd, mgmt, len, ssi_signal);
  179. + handle_probe_req(hapd, mgmt, len, fi);
  180. return 1;
  181. }
  182. @@ -4097,17 +4126,17 @@ int ieee802_11_mgmt(struct hostapd_data
  183. switch (stype) {
  184. case WLAN_FC_STYPE_AUTH:
  185. wpa_printf(MSG_DEBUG, "mgmt::auth");
  186. - handle_auth(hapd, mgmt, len);
  187. + handle_auth(hapd, mgmt, len, fi);
  188. ret = 1;
  189. break;
  190. case WLAN_FC_STYPE_ASSOC_REQ:
  191. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  192. - handle_assoc(hapd, mgmt, len, 0);
  193. + handle_assoc(hapd, mgmt, len, 0, fi);
  194. ret = 1;
  195. break;
  196. case WLAN_FC_STYPE_REASSOC_REQ:
  197. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  198. - handle_assoc(hapd, mgmt, len, 1);
  199. + handle_assoc(hapd, mgmt, len, 1, fi);
  200. ret = 1;
  201. break;
  202. case WLAN_FC_STYPE_DISASSOC:
  203. --- a/src/ap/beacon.c
  204. +++ b/src/ap/beacon.c
  205. @@ -725,7 +725,7 @@ void sta_track_claim_taxonomy_info(struc
  206. void handle_probe_req(struct hostapd_data *hapd,
  207. const struct ieee80211_mgmt *mgmt, size_t len,
  208. - int ssi_signal)
  209. + struct hostapd_frame_info *fi)
  210. {
  211. u8 *resp;
  212. struct ieee802_11_elems elems;
  213. @@ -734,6 +734,7 @@ void handle_probe_req(struct hostapd_dat
  214. size_t i, resp_len;
  215. int noack;
  216. enum ssid_match_result res;
  217. + int ssi_signal = fi->ssi_signal;
  218. int ret;
  219. u16 csa_offs[2];
  220. size_t csa_offs_len;
  221. @@ -742,6 +743,12 @@ void handle_probe_req(struct hostapd_dat
  222. struct hostapd_sta_wpa_psk_short *psk = NULL;
  223. char *identity = NULL;
  224. char *radius_cui = NULL;
  225. + struct hostapd_ubus_request req = {
  226. + .type = HOSTAPD_UBUS_PROBE_REQ,
  227. + .mgmt_frame = mgmt,
  228. + .frame_info = fi,
  229. + .elems = &elems,
  230. + };
  231. if (len < IEEE80211_HDRLEN)
  232. return;
  233. @@ -919,6 +926,12 @@ void handle_probe_req(struct hostapd_dat
  234. }
  235. #endif /* CONFIG_P2P */
  236. + if (hostapd_ubus_handle_event(hapd, &req)) {
  237. + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
  238. + MAC2STR(mgmt->sa));
  239. + return;
  240. + }
  241. +
  242. /* TODO: verify that supp_rates contains at least one matching rate
  243. * with AP configuration */
  244. --- a/src/ap/beacon.h
  245. +++ b/src/ap/beacon.h
  246. @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
  247. void handle_probe_req(struct hostapd_data *hapd,
  248. const struct ieee80211_mgmt *mgmt, size_t len,
  249. - int ssi_signal);
  250. + struct hostapd_frame_info *fi);
  251. int ieee802_11_set_beacon(struct hostapd_data *hapd);
  252. int ieee802_11_set_beacons(struct hostapd_iface *iface);
  253. int ieee802_11_update_beacons(struct hostapd_iface *iface);
  254. --- a/src/ap/drv_callbacks.c
  255. +++ b/src/ap/drv_callbacks.c
  256. @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
  257. u16 reason = WLAN_REASON_UNSPECIFIED;
  258. u16 status = WLAN_STATUS_SUCCESS;
  259. const u8 *p2p_dev_addr = NULL;
  260. + struct hostapd_ubus_request req = {
  261. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  262. + .addr = addr,
  263. + };
  264. if (addr == NULL) {
  265. /*
  266. @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
  267. goto fail;
  268. }
  269. + if (hostapd_ubus_handle_event(hapd, &req)) {
  270. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  271. + MAC2STR(req.addr));
  272. + goto fail;
  273. + }
  274. +
  275. #ifdef CONFIG_P2P
  276. if (elems.p2p) {
  277. wpabuf_free(sta->p2p_ie);
  278. --- a/src/ap/sta_info.c
  279. +++ b/src/ap/sta_info.c
  280. @@ -416,6 +416,7 @@ void ap_handle_timer(void *eloop_ctx, vo
  281. HOSTAPD_LEVEL_INFO, "deauthenticated due to "
  282. "local deauth request");
  283. ap_free_sta(hapd, sta);
  284. + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
  285. return;
  286. }
  287. @@ -563,6 +564,7 @@ skip_poll:
  288. hapd, sta,
  289. WLAN_REASON_PREV_AUTH_NOT_VALID);
  290. ap_free_sta(hapd, sta);
  291. + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
  292. break;
  293. }
  294. }
  295. @@ -1224,6 +1226,7 @@ void ap_sta_set_authorized(struct hostap
  296. buf, ip_addr);
  297. } else {
  298. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
  299. + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
  300. if (hapd->msg_ctx_parent &&
  301. hapd->msg_ctx_parent != hapd->msg_ctx)
  302. --- a/src/ap/wpa_auth_glue.c
  303. +++ b/src/ap/wpa_auth_glue.c
  304. @@ -177,6 +177,7 @@ static void hostapd_wpa_auth_psk_failure
  305. struct hostapd_data *hapd = ctx;
  306. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
  307. MAC2STR(addr));
  308. + hostapd_ubus_notify(hapd, "key-mismatch", addr);
  309. }
  310. --- a/wpa_supplicant/Makefile
  311. +++ b/wpa_supplicant/Makefile
  312. @@ -189,6 +189,12 @@ ifdef CONFIG_EAPOL_TEST
  313. CFLAGS += -Werror -DEAPOL_TEST
  314. endif
  315. +ifdef CONFIG_UBUS
  316. +CFLAGS += -DUBUS_SUPPORT
  317. +OBJS += ubus.o
  318. +LIBS += -lubox -lubus
  319. +endif
  320. +
  321. ifdef CONFIG_CODE_COVERAGE
  322. CFLAGS += -O0 -fprofile-arcs -ftest-coverage
  323. LIBS += -lgcov
  324. @@ -915,6 +921,9 @@ endif
  325. ifdef CONFIG_IEEE80211AX
  326. OBJS += ../src/ap/ieee802_11_he.o
  327. endif
  328. +ifdef CONFIG_UBUS
  329. +OBJS += ../src/ap/ubus.o
  330. +endif
  331. endif
  332. ifdef CONFIG_WNM_AP
  333. CFLAGS += -DCONFIG_WNM_AP
  334. --- a/wpa_supplicant/wpa_supplicant.c
  335. +++ b/wpa_supplicant/wpa_supplicant.c
  336. @@ -6080,6 +6080,8 @@ struct wpa_supplicant * wpa_supplicant_a
  337. }
  338. #endif /* CONFIG_P2P */
  339. + wpas_ubus_add_bss(wpa_s);
  340. +
  341. return wpa_s;
  342. }
  343. @@ -6106,6 +6108,8 @@ int wpa_supplicant_remove_iface(struct w
  344. struct wpa_supplicant *parent = wpa_s->parent;
  345. #endif /* CONFIG_MESH */
  346. + wpas_ubus_free_bss(wpa_s);
  347. +
  348. /* Remove interface from the global list of interfaces */
  349. prev = global->ifaces;
  350. if (prev == wpa_s) {
  351. --- a/wpa_supplicant/wpa_supplicant_i.h
  352. +++ b/wpa_supplicant/wpa_supplicant_i.h
  353. @@ -17,6 +17,7 @@
  354. #include "wps/wps_defs.h"
  355. #include "config_ssid.h"
  356. #include "wmm_ac.h"
  357. +#include "ubus.h"
  358. extern const char *const wpa_supplicant_version;
  359. extern const char *const wpa_supplicant_license;
  360. @@ -500,6 +501,7 @@ struct wpa_supplicant {
  361. unsigned char own_addr[ETH_ALEN];
  362. unsigned char perm_addr[ETH_ALEN];
  363. char ifname[100];
  364. + struct wpas_ubus_bss ubus;
  365. #ifdef CONFIG_MATCH_IFACE
  366. int matched;
  367. #endif /* CONFIG_MATCH_IFACE */
  368. --- a/wpa_supplicant/wps_supplicant.c
  369. +++ b/wpa_supplicant/wps_supplicant.c
  370. @@ -33,6 +33,7 @@
  371. #include "p2p/p2p.h"
  372. #include "p2p_supplicant.h"
  373. #include "wps_supplicant.h"
  374. +#include "ubus.h"
  375. #ifndef WPS_PIN_SCAN_IGNORE_SEL_REG
  376. @@ -388,6 +389,8 @@ static int wpa_supplicant_wps_cred(void
  377. wpa_hexdump_key(MSG_DEBUG, "WPS: Received Credential attribute",
  378. cred->cred_attr, cred->cred_attr_len);
  379. + wpas_ubus_notify(wpa_s, cred);
  380. +
  381. if (wpa_s->conf->wps_cred_processing == 1)
  382. return 0;