600-ubus_support.patch 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. @@ -119,6 +120,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. @@ -328,6 +330,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. --- a/src/ap/hostapd.c
  38. +++ b/src/ap/hostapd.c
  39. @@ -284,6 +284,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. @@ -1142,6 +1143,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. @@ -1665,6 +1668,7 @@ static int hostapd_setup_interface_compl
  54. if (err)
  55. goto fail;
  56. + hostapd_ubus_add_iface(iface);
  57. wpa_printf(MSG_DEBUG, "Completing interface initialization");
  58. if (iface->conf->channel) {
  59. #ifdef NEED_AP_MLME
  60. @@ -1844,6 +1848,7 @@ dfs_offload:
  61. fail:
  62. wpa_printf(MSG_ERROR, "Interface initialization failed");
  63. + hostapd_ubus_free_iface(iface);
  64. hostapd_set_state(iface, HAPD_IFACE_DISABLED);
  65. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_EVENT_DISABLED);
  66. #ifdef CONFIG_FST
  67. @@ -2292,6 +2297,7 @@ void hostapd_interface_deinit_free(struc
  68. (unsigned int) iface->conf->num_bss);
  69. driver = iface->bss[0]->driver;
  70. drv_priv = iface->bss[0]->drv_priv;
  71. + hostapd_ubus_free_iface(iface);
  72. hostapd_interface_deinit(iface);
  73. wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
  74. __func__, driver, drv_priv);
  75. --- a/src/ap/ieee802_11.c
  76. +++ b/src/ap/ieee802_11.c
  77. @@ -1293,7 +1293,8 @@ void ieee802_11_finish_fils_auth(struct
  78. static void handle_auth(struct hostapd_data *hapd,
  79. - const struct ieee80211_mgmt *mgmt, size_t len)
  80. + const struct ieee80211_mgmt *mgmt, size_t len,
  81. + struct hostapd_frame_info *fi)
  82. {
  83. u16 auth_alg, auth_transaction, status_code;
  84. u16 resp = WLAN_STATUS_SUCCESS;
  85. @@ -1309,6 +1310,11 @@ static void handle_auth(struct hostapd_d
  86. char *identity = NULL;
  87. char *radius_cui = NULL;
  88. u16 seq_ctrl;
  89. + struct hostapd_ubus_request req = {
  90. + .type = HOSTAPD_UBUS_AUTH_REQ,
  91. + .mgmt_frame = mgmt,
  92. + .frame_info = fi,
  93. + };
  94. os_memset(&vlan_id, 0, sizeof(vlan_id));
  95. @@ -1466,6 +1472,14 @@ static void handle_auth(struct hostapd_d
  96. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  97. goto fail;
  98. }
  99. +
  100. + if (hostapd_ubus_handle_event(hapd, &req)) {
  101. + wpa_printf(MSG_DEBUG, "Station " MACSTR " rejected by ubus handler.\n",
  102. + MAC2STR(mgmt->sa));
  103. + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  104. + goto fail;
  105. + }
  106. +
  107. if (res == HOSTAPD_ACL_PENDING) {
  108. wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
  109. " waiting for an external authentication",
  110. @@ -2401,7 +2415,7 @@ static u16 send_assoc_resp(struct hostap
  111. static void handle_assoc(struct hostapd_data *hapd,
  112. const struct ieee80211_mgmt *mgmt, size_t len,
  113. - int reassoc)
  114. + int reassoc, struct hostapd_frame_info *fi)
  115. {
  116. u16 capab_info, listen_interval, seq_ctrl, fc;
  117. u16 resp = WLAN_STATUS_SUCCESS, reply_res;
  118. @@ -2409,6 +2423,11 @@ static void handle_assoc(struct hostapd_
  119. int left, i;
  120. struct sta_info *sta;
  121. u8 *tmp = NULL;
  122. + struct hostapd_ubus_request req = {
  123. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  124. + .mgmt_frame = mgmt,
  125. + .frame_info = fi,
  126. + };
  127. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  128. sizeof(mgmt->u.assoc_req))) {
  129. @@ -2528,6 +2547,13 @@ static void handle_assoc(struct hostapd_
  130. }
  131. #endif /* CONFIG_MBO */
  132. + if (hostapd_ubus_handle_event(hapd, &req)) {
  133. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  134. + MAC2STR(mgmt->sa));
  135. + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  136. + goto fail;
  137. + }
  138. +
  139. /*
  140. * sta->capability is used in check_assoc_ies() for RRM enabled
  141. * capability element.
  142. @@ -3035,7 +3061,7 @@ int ieee802_11_mgmt(struct hostapd_data
  143. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  144. - handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
  145. + handle_probe_req(hapd, mgmt, len, fi);
  146. return 1;
  147. }
  148. @@ -3053,17 +3079,17 @@ int ieee802_11_mgmt(struct hostapd_data
  149. switch (stype) {
  150. case WLAN_FC_STYPE_AUTH:
  151. wpa_printf(MSG_DEBUG, "mgmt::auth");
  152. - handle_auth(hapd, mgmt, len);
  153. + handle_auth(hapd, mgmt, len, fi);
  154. ret = 1;
  155. break;
  156. case WLAN_FC_STYPE_ASSOC_REQ:
  157. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  158. - handle_assoc(hapd, mgmt, len, 0);
  159. + handle_assoc(hapd, mgmt, len, 0, fi);
  160. ret = 1;
  161. break;
  162. case WLAN_FC_STYPE_REASSOC_REQ:
  163. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  164. - handle_assoc(hapd, mgmt, len, 1);
  165. + handle_assoc(hapd, mgmt, len, 1, fi);
  166. ret = 1;
  167. break;
  168. case WLAN_FC_STYPE_DISASSOC:
  169. --- a/src/ap/beacon.c
  170. +++ b/src/ap/beacon.c
  171. @@ -702,7 +702,7 @@ void sta_track_claim_taxonomy_info(struc
  172. void handle_probe_req(struct hostapd_data *hapd,
  173. const struct ieee80211_mgmt *mgmt, size_t len,
  174. - int ssi_signal)
  175. + struct hostapd_frame_info *fi)
  176. {
  177. u8 *resp;
  178. struct ieee802_11_elems elems;
  179. @@ -711,9 +711,15 @@ void handle_probe_req(struct hostapd_dat
  180. size_t i, resp_len;
  181. int noack;
  182. enum ssid_match_result res;
  183. + int ssi_signal = fi->ssi_signal;
  184. int ret;
  185. u16 csa_offs[2];
  186. size_t csa_offs_len;
  187. + struct hostapd_ubus_request req = {
  188. + .type = HOSTAPD_UBUS_PROBE_REQ,
  189. + .mgmt_frame = mgmt,
  190. + .frame_info = fi,
  191. + };
  192. if (len < IEEE80211_HDRLEN)
  193. return;
  194. @@ -880,6 +886,12 @@ void handle_probe_req(struct hostapd_dat
  195. }
  196. #endif /* CONFIG_P2P */
  197. + if (hostapd_ubus_handle_event(hapd, &req)) {
  198. + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
  199. + MAC2STR(mgmt->sa));
  200. + return;
  201. + }
  202. +
  203. /* TODO: verify that supp_rates contains at least one matching rate
  204. * with AP configuration */
  205. --- a/src/ap/beacon.h
  206. +++ b/src/ap/beacon.h
  207. @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
  208. void handle_probe_req(struct hostapd_data *hapd,
  209. const struct ieee80211_mgmt *mgmt, size_t len,
  210. - int ssi_signal);
  211. + struct hostapd_frame_info *fi);
  212. int ieee802_11_set_beacon(struct hostapd_data *hapd);
  213. int ieee802_11_set_beacons(struct hostapd_iface *iface);
  214. int ieee802_11_update_beacons(struct hostapd_iface *iface);
  215. --- a/src/ap/drv_callbacks.c
  216. +++ b/src/ap/drv_callbacks.c
  217. @@ -52,6 +52,10 @@ int hostapd_notif_assoc(struct hostapd_d
  218. u16 reason = WLAN_REASON_UNSPECIFIED;
  219. u16 status = WLAN_STATUS_SUCCESS;
  220. const u8 *p2p_dev_addr = NULL;
  221. + struct hostapd_ubus_request req = {
  222. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  223. + .addr = addr,
  224. + };
  225. if (addr == NULL) {
  226. /*
  227. @@ -131,6 +135,12 @@ int hostapd_notif_assoc(struct hostapd_d
  228. goto fail;
  229. }
  230. + if (hostapd_ubus_handle_event(hapd, &req)) {
  231. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  232. + MAC2STR(req.addr));
  233. + goto fail;
  234. + }
  235. +
  236. #ifdef CONFIG_P2P
  237. if (elems.p2p) {
  238. wpabuf_free(sta->p2p_ie);