600-ubus_support.patch 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  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. --- a/src/ap/hostapd.c
  38. +++ b/src/ap/hostapd.c
  39. @@ -309,6 +309,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. @@ -1186,6 +1187,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. @@ -1711,6 +1714,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. @@ -1890,6 +1894,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. @@ -2344,6 +2349,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. @@ -1587,7 +1587,8 @@ ieee802_11_set_radius_info(struct hostap
  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. @@ -1603,6 +1604,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. if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
  95. wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
  96. @@ -1757,6 +1763,12 @@ static void handle_auth(struct hostapd_d
  97. resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  98. goto fail;
  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. if (res == HOSTAPD_ACL_PENDING)
  107. return;
  108. @@ -2860,7 +2872,7 @@ void fils_hlp_timeout(void *eloop_ctx, v
  109. static void handle_assoc(struct hostapd_data *hapd,
  110. const struct ieee80211_mgmt *mgmt, size_t len,
  111. - int reassoc)
  112. + int reassoc, struct hostapd_frame_info *fi)
  113. {
  114. u16 capab_info, listen_interval, seq_ctrl, fc;
  115. u16 resp = WLAN_STATUS_SUCCESS, reply_res;
  116. @@ -2874,6 +2886,11 @@ static void handle_assoc(struct hostapd_
  117. #ifdef CONFIG_FILS
  118. int delay_assoc = 0;
  119. #endif /* CONFIG_FILS */
  120. + struct hostapd_ubus_request req = {
  121. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  122. + .mgmt_frame = mgmt,
  123. + .frame_info = fi,
  124. + };
  125. if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  126. sizeof(mgmt->u.assoc_req))) {
  127. @@ -3041,6 +3058,13 @@ static void handle_assoc(struct hostapd_
  128. }
  129. #endif /* CONFIG_MBO */
  130. + if (hostapd_ubus_handle_event(hapd, &req)) {
  131. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  132. + MAC2STR(mgmt->sa));
  133. + resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  134. + goto fail;
  135. + }
  136. +
  137. /*
  138. * sta->capability is used in check_assoc_ies() for RRM enabled
  139. * capability element.
  140. @@ -3248,6 +3272,7 @@ static void handle_disassoc(struct hosta
  141. wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d",
  142. MAC2STR(mgmt->sa),
  143. le_to_host16(mgmt->u.disassoc.reason_code));
  144. + hostapd_ubus_notify(hapd, "disassoc", mgmt->sa);
  145. sta = ap_get_sta(hapd, mgmt->sa);
  146. if (sta == NULL) {
  147. @@ -3313,6 +3338,8 @@ static void handle_deauth(struct hostapd
  148. " reason_code=%d",
  149. MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code));
  150. + hostapd_ubus_notify(hapd, "deauth", mgmt->sa);
  151. +
  152. sta = ap_get_sta(hapd, mgmt->sa);
  153. if (sta == NULL) {
  154. wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying "
  155. @@ -3627,7 +3654,7 @@ int ieee802_11_mgmt(struct hostapd_data
  156. if (stype == WLAN_FC_STYPE_PROBE_REQ) {
  157. - handle_probe_req(hapd, mgmt, len, fi->ssi_signal);
  158. + handle_probe_req(hapd, mgmt, len, fi);
  159. return 1;
  160. }
  161. @@ -3647,17 +3674,17 @@ int ieee802_11_mgmt(struct hostapd_data
  162. switch (stype) {
  163. case WLAN_FC_STYPE_AUTH:
  164. wpa_printf(MSG_DEBUG, "mgmt::auth");
  165. - handle_auth(hapd, mgmt, len);
  166. + handle_auth(hapd, mgmt, len, fi);
  167. ret = 1;
  168. break;
  169. case WLAN_FC_STYPE_ASSOC_REQ:
  170. wpa_printf(MSG_DEBUG, "mgmt::assoc_req");
  171. - handle_assoc(hapd, mgmt, len, 0);
  172. + handle_assoc(hapd, mgmt, len, 0, fi);
  173. ret = 1;
  174. break;
  175. case WLAN_FC_STYPE_REASSOC_REQ:
  176. wpa_printf(MSG_DEBUG, "mgmt::reassoc_req");
  177. - handle_assoc(hapd, mgmt, len, 1);
  178. + handle_assoc(hapd, mgmt, len, 1, fi);
  179. ret = 1;
  180. break;
  181. case WLAN_FC_STYPE_DISASSOC:
  182. --- a/src/ap/beacon.c
  183. +++ b/src/ap/beacon.c
  184. @@ -716,7 +716,7 @@ void sta_track_claim_taxonomy_info(struc
  185. void handle_probe_req(struct hostapd_data *hapd,
  186. const struct ieee80211_mgmt *mgmt, size_t len,
  187. - int ssi_signal)
  188. + struct hostapd_frame_info *fi)
  189. {
  190. u8 *resp;
  191. struct ieee802_11_elems elems;
  192. @@ -725,9 +725,15 @@ void handle_probe_req(struct hostapd_dat
  193. size_t i, resp_len;
  194. int noack;
  195. enum ssid_match_result res;
  196. + int ssi_signal = fi->ssi_signal;
  197. int ret;
  198. u16 csa_offs[2];
  199. size_t csa_offs_len;
  200. + struct hostapd_ubus_request req = {
  201. + .type = HOSTAPD_UBUS_PROBE_REQ,
  202. + .mgmt_frame = mgmt,
  203. + .frame_info = fi,
  204. + };
  205. if (len < IEEE80211_HDRLEN)
  206. return;
  207. @@ -894,6 +900,12 @@ void handle_probe_req(struct hostapd_dat
  208. }
  209. #endif /* CONFIG_P2P */
  210. + if (hostapd_ubus_handle_event(hapd, &req)) {
  211. + wpa_printf(MSG_DEBUG, "Probe request for " MACSTR " rejected by ubus handler.\n",
  212. + MAC2STR(mgmt->sa));
  213. + return;
  214. + }
  215. +
  216. /* TODO: verify that supp_rates contains at least one matching rate
  217. * with AP configuration */
  218. --- a/src/ap/beacon.h
  219. +++ b/src/ap/beacon.h
  220. @@ -14,7 +14,7 @@ struct ieee80211_mgmt;
  221. void handle_probe_req(struct hostapd_data *hapd,
  222. const struct ieee80211_mgmt *mgmt, size_t len,
  223. - int ssi_signal);
  224. + struct hostapd_frame_info *fi);
  225. int ieee802_11_set_beacon(struct hostapd_data *hapd);
  226. int ieee802_11_set_beacons(struct hostapd_iface *iface);
  227. int ieee802_11_update_beacons(struct hostapd_iface *iface);
  228. --- a/src/ap/drv_callbacks.c
  229. +++ b/src/ap/drv_callbacks.c
  230. @@ -116,6 +116,10 @@ int hostapd_notif_assoc(struct hostapd_d
  231. u16 reason = WLAN_REASON_UNSPECIFIED;
  232. u16 status = WLAN_STATUS_SUCCESS;
  233. const u8 *p2p_dev_addr = NULL;
  234. + struct hostapd_ubus_request req = {
  235. + .type = HOSTAPD_UBUS_ASSOC_REQ,
  236. + .addr = addr,
  237. + };
  238. if (addr == NULL) {
  239. /*
  240. @@ -195,6 +199,12 @@ int hostapd_notif_assoc(struct hostapd_d
  241. goto fail;
  242. }
  243. + if (hostapd_ubus_handle_event(hapd, &req)) {
  244. + wpa_printf(MSG_DEBUG, "Station " MACSTR " assoc rejected by ubus handler.\n",
  245. + MAC2STR(req.addr));
  246. + goto fail;
  247. + }
  248. +
  249. #ifdef CONFIG_P2P
  250. if (elems.p2p) {
  251. wpabuf_free(sta->p2p_ie);
  252. --- a/src/ap/sta_info.c
  253. +++ b/src/ap/sta_info.c
  254. @@ -404,6 +404,7 @@ void ap_handle_timer(void *eloop_ctx, vo
  255. HOSTAPD_LEVEL_INFO, "deauthenticated due to "
  256. "local deauth request");
  257. ap_free_sta(hapd, sta);
  258. + hostapd_ubus_notify(hapd, "local-deauth", sta->addr);
  259. return;
  260. }
  261. @@ -551,6 +552,7 @@ skip_poll:
  262. hapd, sta,
  263. WLAN_REASON_PREV_AUTH_NOT_VALID);
  264. ap_free_sta(hapd, sta);
  265. + hostapd_ubus_notify(hapd, "inactive-deauth", sta->addr);
  266. break;
  267. }
  268. }
  269. --- a/src/ap/wpa_auth_glue.c
  270. +++ b/src/ap/wpa_auth_glue.c
  271. @@ -173,6 +173,7 @@ static void hostapd_wpa_auth_psk_failure
  272. struct hostapd_data *hapd = ctx;
  273. wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POSSIBLE_PSK_MISMATCH MACSTR,
  274. MAC2STR(addr));
  275. + hostapd_ubus_notify(hapd, "key-mismatch", addr);
  276. }