diff --git a/src/agent.c b/src/agent.c index daeaa1b1d42e90cce38f26d402468557041a8c28..4cc2725ec96b882fb993a1e98375295a056e4213 100644 --- a/src/agent.c +++ b/src/agent.c @@ -8584,6 +8584,76 @@ out: return UBUS_STATUS_UNKNOWN_ERROR; } +void initiate_wpspbc(struct agent *a, const char *ifname, bool is_bsta) +{ + struct blob_buf bb; + uint32_t obj_id; + int ret; + const char *role = is_bsta ? "bsta" : "registrar"; + + memset(&bb, 0, sizeof(bb)); + blob_buf_init(&bb, 0); + blobmsg_add_string(&bb, "ifname", ifname); + blobmsg_add_string(&bb, "role", role); + + obj_id = ubus_get_object(a->ubus_ctx, "wifi.wps"); + if (obj_id == WIFI_OBJECT_INVALID) { + trace("WiFi WPS object not found on ubus\n"); + blob_buf_free(&bb); + return; + } + + ret = ubus_call_object_args(a, obj_id, &bb, "start", NULL, NULL); + if (ret != 0) { + trace("WPS start failed on %s (ret=%d)\n", ifname, ret); + } else { + trace("WPS started via ubus on %s\n", ifname); + } + + blob_buf_free(&bb); +} + +int wifiagent_initiate_wpspbc(struct ubus_context *ctx, + struct ubus_request_data *req) +{ + trace("%s: --->\n", __func__); + struct agent *a = this_agent; + struct wifi_radio_element *re; + struct netif_ap *ap; + struct netif_bk *bk; + int triggered = 0; + + list_for_each_entry(re, &a->radiolist, list) { + if (!re->has_bsta) + continue; + + bk = &re->bk; + if (bk->cfg && bk->cfg->enabled) { + trace("Triggering WPS on bSTA: %s\n", bk->ifname); + initiate_wpspbc(a, bk->ifname, true); + bk->wps_active = true; + triggered++; + } + } + + list_for_each_entry(re, &a->radiolist, list) { + list_for_each_entry(ap, &re->aplist, list) { + if (ap->cfg && ap->cfg->enabled) { + trace("Triggering WPS on AP: %s\n", ap->ifname); + initiate_wpspbc(a, ap->ifname, false); + triggered++; + } + } + } + + if (triggered == 0) { + trace("%s: No interfaces matched WPS trigger conditions.\n", __func__); + return UBUS_STATUS_UNKNOWN_ERROR; + } + + return UBUS_STATUS_OK; +} + int agent_switch_according_to_pref(struct agent *a) { uint32_t channel = 0; diff --git a/src/agent.h b/src/agent.h index 138409f5057d2cefa9ec62aa6b867411f8e96c53..23665c5b178a3215abcff8e4b525cd63879297b0 100644 --- a/src/agent.h +++ b/src/agent.h @@ -1052,6 +1052,8 @@ extern int wifiagent_get_info(struct ubus_context *ctx, struct ubus_request_data *req); int wifiagent_get_bk_info(struct ubus_context *ctx, struct ubus_request_data *req); +int wifiagent_initiate_wpspbc(struct ubus_context *ctx, + struct ubus_request_data *req); #ifdef NOTIFY_EVENTS extern void wifiagent_notify_event(struct agent *a, void *ev_type, void *ev_data); diff --git a/src/agent_ubus.c b/src/agent_ubus.c index 7c38ae6d74bd34fc5a0128294ea998c046630f29..07d01025bb30045337e31fb2f7b7d5dfce081746 100644 --- a/src/agent_ubus.c +++ b/src/agent_ubus.c @@ -1151,6 +1151,14 @@ static int agent_bk_info(struct ubus_context *ctx, struct ubus_object *obj, return wifiagent_get_bk_info(ctx, req); } +static int agent_wpspbc(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + return wifiagent_initiate_wpspbc(ctx, req); +} + + #if 0 static int agent_config_ap(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -1417,6 +1425,7 @@ int agent_publish_object(struct agent *a, const char *objname) UBUS_METHOD_NOARG("info", agent_info), UBUS_METHOD("assoc_notify", assoc_notify, assoc_notify_params), + UBUS_METHOD_NOARG("WPSPBC", agent_wpspbc), #ifdef AGENT_SYNC_DYNAMIC_CNTLR_CONFIG UBUS_METHOD_NOARG("sync", sync_dyn_controller_config), #endif