diff mbox series

[OpenWrt-Devel] hostapd: expose beacon reports through ubus

Message ID 20200322105640.13705-1-vincent@systemli.org
State New
Headers show
Series [OpenWrt-Devel] hostapd: expose beacon reports through ubus | expand

Commit Message

Nick March 22, 2020, 10:56 a.m. UTC
Subscribe to beacon reports through ubus.
Can be used for hearing map and client steering purposes.

First enable rrm:
    ubus call hostapd.wlan0 bss_mgmt_enable '{"beacon_report":True}'

Subscribe to the hostapd notifications via ubus.

Request beacon report:
    ubus call hostapd.wlan0 rrm_beacon_req '{"addr":"00:xx:xx:xx:xx:xx", "op_class":0, "channel":1,"duration":1,"mode":2,"bssid":"ff:ff:ff:ff:ff:ff", "ssid":""}'

Signed-off-by: Nick Hainke <vincent@systemli.org>
---
 .../hostapd/patches/600-ubus_support.patch    | 12 ++++++++++
 .../services/hostapd/src/src/ap/ubus.c        | 24 +++++++++++++++++++
 .../services/hostapd/src/src/ap/ubus.h        |  6 +++++
 3 files changed, 42 insertions(+)

Comments

Nick March 22, 2020, 11:02 a.m. UTC | #1
The Github PR: https://github.com/openwrt/openwrt/pull/2597
If you look in the comments, another person tested the PR already.

I would appreciate, if that could be merged.

Until now, you only can send beacon request via ubus, but not receive
the actual answer from the client via ubus.
I changed that with the patch.

On 22.03.20 11:56, Nick Hainke wrote:
> Subscribe to beacon reports through ubus.
> Can be used for hearing map and client steering purposes.
>
> First enable rrm:
>     ubus call hostapd.wlan0 bss_mgmt_enable '{"beacon_report":True}'
>
> Subscribe to the hostapd notifications via ubus.
>
> Request beacon report:
>     ubus call hostapd.wlan0 rrm_beacon_req '{"addr":"00:xx:xx:xx:xx:xx", "op_class":0, "channel":1,"duration":1,"mode":2,"bssid":"ff:ff:ff:ff:ff:ff", "ssid":""}'
>
> Signed-off-by: Nick Hainke <vincent@systemli.org>
> ---
>  .../hostapd/patches/600-ubus_support.patch    | 12 ++++++++++
>  .../services/hostapd/src/src/ap/ubus.c        | 24 +++++++++++++++++++
>  .../services/hostapd/src/src/ap/ubus.h        |  6 +++++
>  3 files changed, 42 insertions(+)
>
> diff --git a/package/network/services/hostapd/patches/600-ubus_support.patch b/package/network/services/hostapd/patches/600-ubus_support.patch
> index 6842c0e63e..b2860780eb 100644
> --- a/package/network/services/hostapd/patches/600-ubus_support.patch
> +++ b/package/network/services/hostapd/patches/600-ubus_support.patch
> @@ -458,3 +458,15 @@
>   		case 'o':
>   			params.override_driver = optarg;
>   			break;
> +--- a/src/ap/rrm.c
> ++++ b/src/ap/rrm.c
> +@@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
> + 		return;
> + 	wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
> + 		MAC2STR(addr), token, rep_mode, report);
> ++	if (len < sizeof(struct rrm_measurement_beacon_report))
> ++		return;
> ++	hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);
> + }
> + 
> + 
> diff --git a/package/network/services/hostapd/src/src/ap/ubus.c b/package/network/services/hostapd/src/src/ap/ubus.c
> index e25c3294ee..eb26c14972 100644
> --- a/package/network/services/hostapd/src/src/ap/ubus.c
> +++ b/package/network/services/hostapd/src/src/ap/ubus.c
> @@ -1269,3 +1269,27 @@ void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *
>  
>  	ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1);
>  }
> +
> +void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, struct rrm_measurement_beacon_report *rep, size_t len)
> +{
> +	if (!hapd->ubus.obj.has_subscribers)
> +		return;
> +
> +	if (!addr)
> +		return;
> +
> +	blob_buf_init(&b, 0);
> +	blobmsg_add_macaddr(&b, "address", addr);
> +	blobmsg_add_u16(&b, "op-class", rep->op_class);
> +	blobmsg_add_u16(&b, "channel", rep->channel);
> +	blobmsg_add_u64(&b, "start-time", rep->start_time);
> +	blobmsg_add_u16(&b, "duration", rep->duration);
> +	blobmsg_add_u16(&b, "report-info", rep->report_info);
> +	blobmsg_add_u16(&b, "rcpi", rep->rcpi);
> +	blobmsg_add_u16(&b, "rsni", rep->rsni);
> +	blobmsg_add_macaddr(&b, "bssid", rep->bssid);
> +	blobmsg_add_u16(&b, "atenna-id", rep->antenna_id);
> +	blobmsg_add_u16(&b, "parent-tsf", rep->parent_tsf);
> +
> +	ubus_notify(ctx, &hapd->ubus.obj, "beacon-report", b.head, -1);
> +}
> diff --git a/package/network/services/hostapd/src/src/ap/ubus.h b/package/network/services/hostapd/src/src/ap/ubus.h
> index 27acd32659..64ff7f5787 100644
> --- a/package/network/services/hostapd/src/src/ap/ubus.h
> +++ b/package/network/services/hostapd/src/src/ap/ubus.h
> @@ -26,6 +26,7 @@ struct hostapd_ubus_request {
>  struct hostapd_iface;
>  struct hostapd_data;
>  struct hapd_interfaces;
> +struct rrm_measurement_beacon_report;
>  
>  #ifdef UBUS_SUPPORT
>  
> @@ -45,6 +46,7 @@ void hostapd_ubus_free_bss(struct hostapd_data *hapd);
>  
>  int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req);
>  void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *mac);
> +void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, struct rrm_measurement_beacon_report *rep, size_t len);
>  
>  void hostapd_ubus_add(struct hapd_interfaces *interfaces);
>  void hostapd_ubus_free(struct hapd_interfaces *interfaces);
> @@ -78,6 +80,10 @@ static inline void hostapd_ubus_notify(struct hostapd_data *hapd, const char *ty
>  {
>  }
>  
> +static inline void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, struct rrm_measurement_beacon_report *rep, size_t len)
> +{
> +}
> +
>  static inline void hostapd_ubus_add(struct hapd_interfaces *interfaces)
>  {
>  }
diff mbox series

Patch

diff --git a/package/network/services/hostapd/patches/600-ubus_support.patch b/package/network/services/hostapd/patches/600-ubus_support.patch
index 6842c0e63e..b2860780eb 100644
--- a/package/network/services/hostapd/patches/600-ubus_support.patch
+++ b/package/network/services/hostapd/patches/600-ubus_support.patch
@@ -458,3 +458,15 @@ 
  		case 'o':
  			params.override_driver = optarg;
  			break;
+--- a/src/ap/rrm.c
++++ b/src/ap/rrm.c
+@@ -89,6 +89,9 @@ static void hostapd_handle_beacon_report
+ 		return;
+ 	wpa_msg(hapd->msg_ctx, MSG_INFO, BEACON_RESP_RX MACSTR " %u %02x %s",
+ 		MAC2STR(addr), token, rep_mode, report);
++	if (len < sizeof(struct rrm_measurement_beacon_report))
++		return;
++	hostapd_ubus_notify_beacon_report(hapd, addr, token, rep_mode, (struct rrm_measurement_beacon_report*) pos, len);
+ }
+ 
+ 
diff --git a/package/network/services/hostapd/src/src/ap/ubus.c b/package/network/services/hostapd/src/src/ap/ubus.c
index e25c3294ee..eb26c14972 100644
--- a/package/network/services/hostapd/src/src/ap/ubus.c
+++ b/package/network/services/hostapd/src/src/ap/ubus.c
@@ -1269,3 +1269,27 @@  void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *
 
 	ubus_notify(ctx, &hapd->ubus.obj, type, b.head, -1);
 }
+
+void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, struct rrm_measurement_beacon_report *rep, size_t len)
+{
+	if (!hapd->ubus.obj.has_subscribers)
+		return;
+
+	if (!addr)
+		return;
+
+	blob_buf_init(&b, 0);
+	blobmsg_add_macaddr(&b, "address", addr);
+	blobmsg_add_u16(&b, "op-class", rep->op_class);
+	blobmsg_add_u16(&b, "channel", rep->channel);
+	blobmsg_add_u64(&b, "start-time", rep->start_time);
+	blobmsg_add_u16(&b, "duration", rep->duration);
+	blobmsg_add_u16(&b, "report-info", rep->report_info);
+	blobmsg_add_u16(&b, "rcpi", rep->rcpi);
+	blobmsg_add_u16(&b, "rsni", rep->rsni);
+	blobmsg_add_macaddr(&b, "bssid", rep->bssid);
+	blobmsg_add_u16(&b, "atenna-id", rep->antenna_id);
+	blobmsg_add_u16(&b, "parent-tsf", rep->parent_tsf);
+
+	ubus_notify(ctx, &hapd->ubus.obj, "beacon-report", b.head, -1);
+}
diff --git a/package/network/services/hostapd/src/src/ap/ubus.h b/package/network/services/hostapd/src/src/ap/ubus.h
index 27acd32659..64ff7f5787 100644
--- a/package/network/services/hostapd/src/src/ap/ubus.h
+++ b/package/network/services/hostapd/src/src/ap/ubus.h
@@ -26,6 +26,7 @@  struct hostapd_ubus_request {
 struct hostapd_iface;
 struct hostapd_data;
 struct hapd_interfaces;
+struct rrm_measurement_beacon_report;
 
 #ifdef UBUS_SUPPORT
 
@@ -45,6 +46,7 @@  void hostapd_ubus_free_bss(struct hostapd_data *hapd);
 
 int hostapd_ubus_handle_event(struct hostapd_data *hapd, struct hostapd_ubus_request *req);
 void hostapd_ubus_notify(struct hostapd_data *hapd, const char *type, const u8 *mac);
+void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, struct rrm_measurement_beacon_report *rep, size_t len);
 
 void hostapd_ubus_add(struct hapd_interfaces *interfaces);
 void hostapd_ubus_free(struct hapd_interfaces *interfaces);
@@ -78,6 +80,10 @@  static inline void hostapd_ubus_notify(struct hostapd_data *hapd, const char *ty
 {
 }
 
+static inline void hostapd_ubus_notify_beacon_report(struct hostapd_data *hapd, const u8 *addr, u8 token, u8 rep_mode, struct rrm_measurement_beacon_report *rep, size_t len)
+{
+}
+
 static inline void hostapd_ubus_add(struct hapd_interfaces *interfaces)
 {
 }