From fda08cd4bc450656872c889b083e6825ac8f88fe Mon Sep 17 00:00:00 2001 From: "nevadita.chatterjee" <nevadita.chatterjee@iopsys.eu> Date: Wed, 21 Oct 2020 12:21:42 +0530 Subject: [PATCH] map-controller: Added the channel ubus method --- src/core/cntlr_ubus.c | 52 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/src/core/cntlr_ubus.c b/src/core/cntlr_ubus.c index 2ce015f9..53e9dd9f 100644 --- a/src/core/cntlr_ubus.c +++ b/src/core/cntlr_ubus.c @@ -62,6 +62,15 @@ static const struct blobmsg_policy sta_caps_policy_params[__STA_POLICY_MAX] = { [STA_POLICY_BSSID] = { .name = "bssid", .type = BLOBMSG_TYPE_STRING } }; +enum { + CHANNEL_PREF_POLICY_AGENT, + __CHANNEL_PREF_POLICY_MAX, +}; + +static const struct blobmsg_policy channel_pref_policy_params[__CHANNEL_PREF_POLICY_MAX] = { + [CHANNEL_PREF_POLICY_AGENT] = { .name = "agent", .type = BLOBMSG_TYPE_STRING } +}; + static void send_cmdu_cb(struct ubus_request *req, int type, struct blob_attr *msg) { @@ -304,6 +313,46 @@ static int cntlr_ap_caps(struct ubus_context *ctx, struct ubus_object *obj, return 0; } +static int cntlr_channel_pref(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct blob_attr *tb[__CHANNEL_PREF_POLICY_MAX]; + struct controller *c = container_of(obj, struct controller, obj); + char agent[18] = {0}; + struct cmdu_cstruct *cmdu_data; + + cmdu_data = (struct cmdu_cstruct *)calloc(1, + sizeof(struct cmdu_cstruct)); + if (!cmdu_data) { + fprintf(stderr, "failed to malloc cmdu\n"); + return UBUS_STATUS_UNKNOWN_ERROR; + } + + blobmsg_parse(channel_pref_policy_params, __CHANNEL_PREF_POLICY_MAX, tb, + blob_data(msg), blob_len(msg)); + + + if (tb[CHANNEL_PREF_POLICY_AGENT]) { + strncpy(agent, blobmsg_data(tb[CHANNEL_PREF_POLICY_AGENT]), + sizeof(agent) - 1); + if (!hwaddr_aton(agent, cmdu_data->origin)) + return UBUS_STATUS_UNKNOWN_ERROR; + } + + // TODO: ff:ff:ff:ff:ff:ff = send to all agents + + cmdu_data->message_type = CMDU_CHANNEL_PREFERENCE_QUERY; + cmdu_data->message_id = 1; + + cmdu_data->num_tlvs = 0; + + send_cmdu(c, cmdu_data); + + return 0; +} + + static int cntlr_sta_caps(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -385,10 +434,11 @@ int cntlr_publish_object(struct controller *c, const char *objname) struct ubus_object *obj; struct ubus_object_type *obj_type; struct ubus_method *obj_methods; - struct ubus_method m[3] = { + struct ubus_method m[4] = { UBUS_METHOD_NOARG("status", cntlr_status), UBUS_METHOD("ap_caps", cntlr_ap_caps, ap_caps_policy_params), UBUS_METHOD("sta_caps", cntlr_sta_caps, sta_caps_policy_params), + UBUS_METHOD("channels", cntlr_channel_pref, channel_pref_policy_params) }; int num_methods = ARRAY_SIZE(m); int ret; -- GitLab