[openwrt/openwrt] hostapd: ubus: add handler for wps_status and guard WPS calls
LEDE Commits
lede-commits at lists.infradead.org
Thu Oct 15 20:54:14 EDT 2020
dangole pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/63e2e086bea2280fee47385e172d09e4eb86fc78
commit 63e2e086bea2280fee47385e172d09e4eb86fc78
Author: Daniel Golle <daniel at makrotopia.org>
AuthorDate: Sat Oct 10 23:04:13 2020 +0100
hostapd: ubus: add handler for wps_status and guard WPS calls
Expose WPS ubus API only if compiled with WPS support and add new
handler for wps_status call.
Also add '-v wps' option to check whether WPS support is present in
hostapd.
Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
package/network/services/hostapd/Makefile | 2 +-
package/network/services/hostapd/src/src/ap/ubus.c | 52 ++++++++++++++++++++++
.../hostapd/src/src/utils/build_features.h | 4 ++
3 files changed, 57 insertions(+), 1 deletion(-)
diff --git a/package/network/services/hostapd/Makefile b/package/network/services/hostapd/Makefile
index 6966ebdb89..9ae72e7c28 100644
--- a/package/network/services/hostapd/Makefile
+++ b/package/network/services/hostapd/Makefile
@@ -7,7 +7,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=hostapd
-PKG_RELEASE:=11
+PKG_RELEASE:=12
PKG_SOURCE_URL:=http://w1.fi/hostap.git
PKG_SOURCE_PROTO:=git
diff --git a/package/network/services/hostapd/src/src/ap/ubus.c b/package/network/services/hostapd/src/src/ap/ubus.c
index d816f2c030..5a5dd1a889 100644
--- a/package/network/services/hostapd/src/src/ap/ubus.c
+++ b/package/network/services/hostapd/src/src/ap/ubus.c
@@ -395,6 +395,7 @@ hostapd_bss_list_bans(struct ubus_context *ctx, struct ubus_object *obj,
return 0;
}
+#ifdef CONFIG_WPS
static int
hostapd_bss_wps_start(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
@@ -411,6 +412,53 @@ hostapd_bss_wps_start(struct ubus_context *ctx, struct ubus_object *obj,
return 0;
}
+
+static const char * pbc_status_enum_str(enum pbc_status status)
+{
+ switch (status) {
+ case WPS_PBC_STATUS_DISABLE:
+ return "Disabled";
+ case WPS_PBC_STATUS_ACTIVE:
+ return "Active";
+ case WPS_PBC_STATUS_TIMEOUT:
+ return "Timed-out";
+ case WPS_PBC_STATUS_OVERLAP:
+ return "Overlap";
+ default:
+ return "Unknown";
+ }
+}
+
+static int
+hostapd_bss_wps_status(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ int rc;
+ struct hostapd_data *hapd = container_of(obj, struct hostapd_data, ubus.obj);
+
+ blob_buf_init(&b, 0);
+
+ blobmsg_add_string(&b, "pbc_status", pbc_status_enum_str(hapd->wps_stats.pbc_status));
+ blobmsg_add_string(&b, "last_wps_result",
+ (hapd->wps_stats.status == WPS_STATUS_SUCCESS ?
+ "Success":
+ (hapd->wps_stats.status == WPS_STATUS_FAILURE ?
+ "Failed" : "None")));
+
+ /* If status == Failure - Add possible Reasons */
+ if(hapd->wps_stats.status == WPS_STATUS_FAILURE &&
+ hapd->wps_stats.failure_reason > 0)
+ blobmsg_add_string(&b, "reason", wps_ei_str(hapd->wps_stats.failure_reason));
+
+ if (hapd->wps_stats.status)
+ blobmsg_printf(&b, "peer_address", MACSTR, MAC2STR(hapd->wps_stats.peer_addr));
+
+ ubus_send_reply(ctx, req, b.head);
+
+ return 0;
+}
+
static int
hostapd_bss_wps_cancel(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
@@ -426,6 +474,7 @@ hostapd_bss_wps_cancel(struct ubus_context *ctx, struct ubus_object *obj,
return 0;
}
+#endif /* CONFIG_WPS */
static int
hostapd_bss_update_beacon(struct ubus_context *ctx, struct ubus_object *obj,
@@ -1100,8 +1149,11 @@ static const struct ubus_method bss_methods[] = {
UBUS_METHOD_NOARG("get_clients", hostapd_bss_get_clients),
UBUS_METHOD("del_client", hostapd_bss_del_client, del_policy),
UBUS_METHOD_NOARG("list_bans", hostapd_bss_list_bans),
+#ifdef CONFIG_WPS
UBUS_METHOD_NOARG("wps_start", hostapd_bss_wps_start),
+ UBUS_METHOD_NOARG("wps_status", hostapd_bss_wps_status),
UBUS_METHOD_NOARG("wps_cancel", hostapd_bss_wps_cancel),
+#endif
UBUS_METHOD_NOARG("update_beacon", hostapd_bss_update_beacon),
UBUS_METHOD_NOARG("get_features", hostapd_bss_get_features),
#ifdef NEED_AP_MLME
diff --git a/package/network/services/hostapd/src/src/utils/build_features.h b/package/network/services/hostapd/src/src/utils/build_features.h
index 9856756d95..7ca65fa391 100644
--- a/package/network/services/hostapd/src/src/utils/build_features.h
+++ b/package/network/services/hostapd/src/src/utils/build_features.h
@@ -50,6 +50,10 @@ static inline int has_feature(const char *feat)
#ifdef CONFIG_HS20
if (!strcmp(feat, "hs20"))
return 1;
+#endif
+#ifdef CONFIG_WPS
+ if (!strcmp(feat, "wps"))
+ return 1;
#endif
return 0;
}
More information about the lede-commits
mailing list