This adds wide information about current channel of interface to
hostapd.iface_state event. Additional event sent when interface
completes csa operation.

Signed-off-by: Yury Shvedov <yshve...@wimarksystems.com>
---
 .../hostapd/patches/600-ubus_support.patch    |  8 +++
 .../services/hostapd/src/src/ap/ubus.c        | 69 +++++++++++++++++--
 .../services/hostapd/src/src/ap/ubus.h        |  4 ++
 3 files changed, 77 insertions(+), 4 deletions(-)

diff --git a/package/network/services/hostapd/patches/600-ubus_support.patch 
b/package/network/services/hostapd/patches/600-ubus_support.patch
index c0db5be4e9..0bba0ba752 100644
--- a/package/network/services/hostapd/patches/600-ubus_support.patch
+++ b/package/network/services/hostapd/patches/600-ubus_support.patch
@@ -354,6 +354,14 @@
  #ifdef CONFIG_P2P
        if (elems.p2p) {
                wpabuf_free(sta->p2p_ie);
+@@ -816,6 +827,7 @@ void hostapd_event_ch_switch(struct host
+               wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
+                       "freq=%d dfs=%d", freq, is_dfs);
+       }
++    hostapd_ubus_event_ch_switch(hapd->iface);
+ #endif /* NEED_AP_MLME */
+ }
+ 
 --- a/src/ap/sta_info.c
 +++ b/src/ap/sta_info.c
 @@ -162,6 +162,7 @@ void ap_free_sta(struct hostapd_data *ha
diff --git a/package/network/services/hostapd/src/src/ap/ubus.c 
b/package/network/services/hostapd/src/src/ap/ubus.c
index 2ceb2de159..abbe3fac88 100644
--- a/package/network/services/hostapd/src/src/ap/ubus.c
+++ b/package/network/services/hostapd/src/src/ap/ubus.c
@@ -1300,6 +1300,53 @@ void hostapd_ubus_notify(struct hostapd_data *hapd, 
const char *type, const u8 *
        ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1);
 }
 
+static void blobmsg_add_iface_state(struct blob_buf *buff,
+               struct hostapd_iface *iface, int cur, int old)
+{
+       blobmsg_add_u32(buff, "oldstate_num", old);
+       blobmsg_add_string(buff, "oldstate", hostapd_state_text(old));
+       blobmsg_add_u32(buff, "state_num", cur);
+       blobmsg_add_string(buff, "state", hostapd_state_text(cur));
+}
+static void blobmsg_add_iface_channel(struct blob_buf *buff,
+               struct hostapd_iface *iface)
+{
+       struct hostapd_config *conf = iface->conf;
+       int width = 20;
+       void *chan;
+
+       if (!iface->freq) {
+               return;
+       }
+
+       chan = blobmsg_open_table(buff, "channel");
+
+       blobmsg_add_u32(buff, "freq", iface->freq);
+       blobmsg_add_u32(buff, "channel", conf->channel);
+       blobmsg_add_u8(buff, "ht", conf->ieee80211n);
+       blobmsg_add_u8(buff, "vht", conf->ieee80211ac);
+       blobmsg_add_u32(buff, "secondary_channel", conf->secondary_channel);
+       switch (conf->vht_oper_chwidth) {
+               case VHT_CHANWIDTH_USE_HT:
+                       width = conf->secondary_channel ? 40 : 20;
+                       break;
+               case VHT_CHANWIDTH_80MHZ:
+                       width = 80;
+                       break;
+               case VHT_CHANWIDTH_160MHZ:
+                       width = 160;
+                       break;
+               case VHT_CHANWIDTH_80P80MHZ:
+                       width = 8080;
+                       break;
+       }
+       blobmsg_add_u32(buff, "width", width);
+       blobmsg_add_u32(buff, "center_idx0", 
conf->vht_oper_centr_freq_seg0_idx);
+       blobmsg_add_u32(buff, "center_idx1", 
conf->vht_oper_centr_freq_seg1_idx);
+       blobmsg_add_u8(buff, "is_dfs", ieee80211_is_dfs(iface->freq,
+                               iface->hw_features, iface->num_hw_features));
+       blobmsg_close_table(buff, chan);
+}
 /* Send ubus event in case new event differs. */
 void hostapd_ubus_event_iface_state(struct hostapd_iface *iface, int s)
 {
@@ -1316,10 +1363,24 @@ void hostapd_ubus_event_iface_state(struct 
hostapd_iface *iface, int s)
                blobmsg_add_string(&b, "device", hapd->conf->uci_device);
        if (iface->ubus.obj.id)
                blobmsg_add_string(&b, "uobject", iface->ubus.obj.name);
-       blobmsg_add_u32(&b, "oldstate_num", iface->state);
-       blobmsg_add_string(&b, "oldstate", hostapd_state_text(iface->state));
-       blobmsg_add_u32(&b, "state_num", s);
-       blobmsg_add_string(&b, "state", hostapd_state_text(s));
+       blobmsg_add_iface_state(&b, iface, s, iface->state);
+       blobmsg_add_iface_channel(&b, iface);
+       ubus_send_event(ctx, "hostapd.iface_state", b.head);
+}
+void hostapd_ubus_event_ch_switch(struct hostapd_iface *iface)
+{
+       struct hostapd_data *hapd = iface->bss[0];
+
+       if (!hostapd_ubus_init())
+               return;
+       hostapd_ubus_add_iface(iface);
+       blob_buf_init(&b, 0);
+       if (hapd && hapd->conf->uci_device)
+               blobmsg_add_string(&b, "device", hapd->conf->uci_device);
+       if (iface->ubus.obj.id)
+               blobmsg_add_string(&b, "uobject", iface->ubus.obj.name);
+       blobmsg_add_iface_state(&b, iface, iface->state, iface->state);
+       blobmsg_add_iface_channel(&b, iface);
        ubus_send_event(ctx, "hostapd.iface_state", b.head);
 }
 static void
diff --git a/package/network/services/hostapd/src/src/ap/ubus.h 
b/package/network/services/hostapd/src/src/ap/ubus.h
index cc4b5fcb0f..6d2e1c7bcd 100644
--- a/package/network/services/hostapd/src/src/ap/ubus.h
+++ b/package/network/services/hostapd/src/src/ap/ubus.h
@@ -58,6 +58,7 @@ void hostapd_ubus_event_sta_account_start(struct hostapd_data 
*hapd,
                struct sta_info *sta);
 void hostapd_ubus_event_sta_account_stop(struct hostapd_data *hapd,
                struct sta_info *sta);
+void hostapd_ubus_event_ch_switch(struct hostapd_iface *iface);
 
 #else
 
@@ -92,6 +93,9 @@ static inline void hostapd_ubus_notify(struct hostapd_data 
*hapd, const char *ty
 static inline void hostapd_ubus_event_iface_state(struct hostapd_iface *iface, 
int s)
 {
 }
+static inline void hostapd_ubus_event_ch_switch(struct hostapd_iface *iface)
+{
+}
 static inline void hostapd_ubus_event_sta_account_start(struct hostapd_data 
*hapd,
                struct sta_info *sta)
 {
-- 
2.19.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to