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@makrotopia.org>
This commit is contained in:
Daniel Golle 2020-10-10 23:04:13 +01:00
parent 5666ca913a
commit 63e2e086be
3 changed files with 57 additions and 1 deletions

View 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

View 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

View 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;
}