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