600-ubus_support.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. struct wpa_ctrl_dst;
  20. struct radius_server_data;
  21. @@ -122,6 +123,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. @@ -370,6 +372,8 @@ struct hostapd_iface {
  30. struct hostapd_config *conf;
  31. char phy[16]; /* Name of the PHY (radio) */
  32. + struct hostapd_ubus_iface ubus;
  33. +
  34. enum hostapd_iface_state {
  35. HAPD_IFACE_UNINITIALIZED,
  36. HAPD_IFACE_DISABLED,
  37. @@ -518,6 +522,7 @@ hostapd_alloc_bss_data(struct hostapd_if
  38. struct hostapd_bss_config *bss);
  39. int hostapd_setup_interface(struct hostapd_iface *iface);
  40. int hostapd_setup_interface_complete(struct hostapd_iface *iface, int err);
  41. +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd);
  42. void hostapd_interface_deinit(struct hostapd_iface *iface);
  43. void hostapd_interface_free(struct hostapd_iface *iface);
  44. struct hostapd_iface * hostapd_alloc_iface(void);
  45. --- a/src/ap/hostapd.c
  46. +++ b/src/ap/hostapd.c
  47. @@ -309,6 +309,7 @@ static void hostapd_free_hapd_data(struc
  48. hapd->started = 0;
  49. wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
  50. + hostapd_ubus_free_bss(hapd);
  51. iapp_deinit(hapd->iapp);
  52. hapd->iapp = NULL;
  53. accounting_deinit(hapd);
  54. @@ -1186,6 +1187,8 @@ static int hostapd_setup_bss(struct host
  55. if (hapd->driver && hapd->driver->set_operstate)
  56. hapd->driver->set_operstate(hapd->drv_priv, 1);
  57. + hostapd_ubus_add_bss(hapd);
  58. +
  59. return 0;
  60. }
  61. @@ -1600,7 +1603,7 @@ static enum nr_chan_width hostapd_get_nr
  62. #endif /* NEED_AP_MLME */
  63. -static void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
  64. +void hostapd_set_own_neighbor_report(struct hostapd_data *hapd)
  65. {
  66. #ifdef NEED_AP_MLME
  67. u16 capab = hostapd_own_capab_info(hapd);
  68. @@ -1711,6 +1714,7 @@ static int hostapd_setup_interface_compl
  69. if (err)
  70. goto fail;
  71. + hostapd_ubus_add_iface(iface);
  72. wpa_printf(MSG_DEBUG, "Completing interface initialization");
  73. if (iface->conf->channel) {
  74. #ifdef NEED_AP_MLME
  75. @@ -1890,6 +1894,7 @@ dfs_offload:
  76. fail:
  77. wpa_printf(MSG_ERROR, "Interface initialization failed");
  78. + hostapd_ubus_free_iface(iface);
  79. hostapd_set_state(iface, HAPD_IFACE_DISABLED);
  80. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
  81. #ifdef CONFIG_FST
  82. @@ -2344,6 +2349,7 @@ void hostapd_interface_deinit_free(struc
  83. (unsigned int) iface->conf->num_bss);
  84. driver = iface->bss[0]->driver;
  85. drv_priv = iface->bss[0]->drv_priv;
  86. + hostapd_ubus_free_iface(iface);
  87. hostapd_interface_deinit(iface);
  88. wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
  89. __func__, driver, drv_priv);
  90. --- a/src/ap/ieee802_11.c
  91. +++ b/src/ap/ieee802_11.c
  92. @@ -1587,7 +1587,8 @@ ieee802_11_set_radius_info(struct hostap
  93. static void handle_auth(struct hostapd_data *hapd,
  94. - const struct ieee80211_mgmt *mgmt, size_t len)
  95. + const struct ieee80211_mgmt *mgmt, size_t len,
  96. + struct hostapd_frame_info *fi)
  97. {
  98. u16 auth_alg, auth_transaction, status_code;
  99. u16 resp = WLAN_STATUS_SUCCESS;
  100. @@ -1603,6 +1604,11 @@ static void handle_auth(struct hostapd_d
  101. char *identity = NULL;
  102. char *radius_cui = NULL;
  103. u16 seq_ctrl;
  104. + struct hostapd_ubus_request req = {
  105. + .type = HOSTAPD_UBUS_AUTH_REQ,
  106. + .mgmt_frame = mgmt,
  107. + .frame_info = fi,
  108. + };
  109. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  110. wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
  111. @@ -1757,6 +1763,12 @@ static void handle_auth(struct hostapd_d
  112. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  113. goto fail;
  114. }
  115. + if (hostapd_ubus_handle_event(hapd, &req)) {
  116. + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
  117. + MAC2STR(mgmt->sa));
  118. + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  119. + goto fail;
  120. + }
  121. if (res == HOSTAPD_ACL_PENDING)
  122. return;
  123. @@ -2870,7 +2882,7 @@ void fils_hlp_timeout(void *eloop_ctx, v
  124. static void handle_assoc(struct hostapd_data *hapd,
  125. const struct ieee80211_mgmt *mgmt, size_t len,
  126. - int reassoc)
  127. + int reassoc, struct hostapd_frame_info *fi)
  128. {
  129. u16 capab_info, listen_interval, seq_ctrl, fc;
  130. u16 resp = WLAN_STATUS_SUCCESS, reply_res;
  131. @@ -2884,6 +2896,11 @@ static void handle_assoc(struct hostapd_
  132. #ifdef CONFIG_FILS
  133. int delay_assoc = 0;
  134. #endif /* CONFIG_FILS */
  135. + struct hostapd_ubus_request req = {
  136. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  137. + .mgmt_frame = mgmt,
  138. + .frame_info = fi,
  139. + };
  140. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  141. sizeof(mgmt->u.assoc_req))) {
  142. @@ -3051,6 +3068,13 @@ static void handle_assoc(struct hostapd_
  143. }
  144. #endif /* CONFIG_MBO */
  145. + if (hostapd_ubus_handle_event(hapd, &req)) {
  146. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  147. + MAC2STR(mgmt->sa));
  148. + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  149. + goto fail;
  150. + }
  151. +
  152. /*
  153. * sta->capability is used in check_assoc_ies() for RRM enabled
  154. * capability element.
  155. @@ -3258,6 +3282,7 @@ static void handle_disassoc(struct hosta
  156. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  157. MAC2STR(mgmt->sa),
  158. le_to_host16(mgmt->u.disassoc.reason_code));
  159. + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
  160. sta = ap_get_sta(hapd, mgmt->sa);
  161. if (sta == NULL) {
  162. @@ -3323,6 +3348,8 @@ static void handle_deauth(struct hostapd
  163. " reason_code=%d",
  164. MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
  165. + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
  166. +
  167. sta = ap_get_sta(hapd, mgmt->sa);
  168. if (sta == NULL) {
  169. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
  170. @@ -3637,7 +3664,7 @@ int ieee802_11_mgmt(struct hostapd_data
  171. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  172. - handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
  173. + handle_probe_req(hapd, mgmt, len, fi);
  174. return 1;
  175. }
  176. @@ -3657,17 +3684,17 @@ int ieee802_11_mgmt(struct hostapd_data
  177. switch (stype) {
  178. case WLAN_FC_STYPE_AUTH:
  179. wpa_printf(MSG_DEBUG, "mgmt::auth");
  180. - handle_auth(hapd, mgmt, len);
  181. + handle_auth(hapd, mgmt, len, fi);
  182. ret = 1;
  183. break;
  184. case WLAN_FC_STYPE_ASSOC_REQ:
  185. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  186. - handle_assoc(hapd, mgmt, len, 0);
  187. + handle_assoc(hapd, mgmt, len, 0, fi);
  188. ret = 1;
  189. break;
  190. case WLAN_FC_STYPE_REASSOC_REQ:
  191. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  192. - handle_assoc(hapd, mgmt, len, 1);
  193. + handle_assoc(hapd, mgmt, len, 1, fi);
  194. ret = 1;
  195. break;
  196. case WLAN_FC_STYPE_DISASSOC:
  197. --- a/src/ap/beacon.c
  198. +++ b/src/ap/beacon.c
  199. @@ -716,7 +716,7 @@ void sta_track_claim_taxonomy_info(struc
  200. void handle_probe_req(struct hostapd_data *hapd,
  201. const struct ieee80211_mgmt *mgmt, size_t len,
  202. - int ssi_signal)
  203. + struct hostapd_frame_info *fi)
  204. {
  205. u8 *resp;
  206. struct ieee802_11_elems elems;
  207. @@ -725,9 +725,15 @@ void handle_probe_req(struct hostapd_dat
  208. size_t i, resp_len;
  209. int noack;
  210. enum ssid_match_result res;
  211. + int ssi_signal = fi->ssi_signal;
  212. int ret;
  213. u16 csa_offs[2];
  214. size_t csa_offs_len;
  215. + struct hostapd_ubus_request req = {
  216. + .type = HOSTAPD_UBUS_PROBE_REQ,
  217. + .mgmt_frame = mgmt,
  218. + .frame_info = fi,
  219. + };
  220. if (len < IEEE80211_HDRLEN)
  221. return;
  222. @@ -894,6 +900,12 @@ void handle_probe_req(struct hostapd_dat
  223. }
  224. #endif /* CONFIG_P2P */
  225. + if (hostapd_ubus_handle_event(hapd, &req)) {
  226. + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
  227. + MAC2STR(mgmt->sa));
  228. + return;
  229. + }
  230. +
  231. /* TODO: verify that supp_rates contains at least one matching rate
  232. * with AP configuration */
  233. --- a/src/ap/beacon.h
  234. +++ b/src/ap/beacon.h
  235. @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
  236. void handle_probe_req(struct hostapd_data *hapd,
  237. const struct ieee80211_mgmt *mgmt, size_t len,
  238. - int ssi_signal);
  239. + struct hostapd_frame_info *fi);
  240. int ieee802_11_set_beacon(struct hostapd_data *hapd);
  241. int ieee802_11_set_beacons(struct hostapd_iface *iface);
  242. int ieee802_11_update_beacons(struct hostapd_iface *iface);
  243. --- a/src/ap/drv_callbacks.c
  244. +++ b/src/ap/drv_callbacks.c
  245. @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
  246. u16 reason = WLAN_REASON_UNSPECIFIED;
  247. u16 status = WLAN_STATUS_SUCCESS;
  248. const u8 *p2p_dev_addr = NULL;
  249. + struct hostapd_ubus_request req = {
  250. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  251. + .addr = addr,
  252. + };
  253. if (addr == NULL) {
  254. /*
  255. @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
  256. goto fail;
  257. }
  258. + if (hostapd_ubus_handle_event(hapd, &req)) {
  259. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  260. + MAC2STR(req.addr));
  261. + goto fail;
  262. + }
  263. +
  264. #ifdef CONFIG_P2P
  265. if (elems.p2p) {
  266. wpabuf_free(sta->p2p_ie);
  267. --- a/src/ap/sta_info.c
  268. +++ b/src/ap/sta_info.c
  269. @@ -404,6 +404,7 @@ void ap_handle_timer(void *eloop_ctx, vo
  270. HOSTAPD_LEVEL_INFO, "deauthenticated due to "
  271. "local deauth request");
  272. ap_free_sta(hapd, sta);
  273. + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
  274. return;
  275. }
  276. @@ -551,6 +552,7 @@ skip_poll:
  277. hapd, sta,
  278. WLAN_REASON_PREV_AUTH_NOT_VALID);
  279. ap_free_sta(hapd, sta);
  280. + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
  281. break;
  282. }
  283. }
  284. @@ -1212,6 +1214,7 @@ void ap_sta_set_authorized(struct hostap
  285. buf, ip_addr);
  286. } else {
  287. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_DISCONNECTED "%s", buf);
  288. + hostapd_ubus_notify(hapd, "disassoc", sta->addr);
  289. if (hapd->msg_ctx_parent &&
  290. hapd->msg_ctx_parent != hapd->msg_ctx)
  291. --- a/src/ap/wpa_auth_glue.c
  292. +++ b/src/ap/wpa_auth_glue.c
  293. @@ -175,6 +175,7 @@ static void hostapd_wpa_auth_psk_failure
  294. struct hostapd_data *hapd = ctx;
  295. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
  296. MAC2STR(addr));
  297. + hostapd_ubus_notify(hapd, "key-mismatch", addr);
  298. }