hostapd: ubus: add handler for wps_status and guard WPS calls
authorDaniel Golle <daniel@makrotopia.org>
Sat, 10 Oct 2020 22:04:13 +0000 (23:04 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Thu, 15 Oct 2020 23:38:06 +0000 (00:38 +0100)
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@makrotopia.org>
package/network/services/hostapd/Makefile
package/network/services/hostapd/src/src/ap/ubus.c
package/network/services/hostapd/src/src/utils/build_features.h

index 6966ebdb899267fbe63dc0374dce88a2c5859417..9ae72e7c28913e1bb8928649a148c3bab7ddcf69 100644 (file)
@@ -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
index d816f2c03064e17d779d0eeeac8c930175b5f8a0..5a5dd1a8898e6f86da50be4cca9ccc9d14669e0f 100644 (file)
@@ -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
index 9856756d9543add8b9bcc79af987797bd163aec7..7ca65fa39141df29211528bc39cbf9c7bc1a832f 100644 (file)
@@ -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;
 }