diff --git a/README.md b/README.md index f00216f496baff2861ec03f57087fcb431d599d6..58e280b3438d143227e32e2ad46cd311d9b874b3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The wifimngr objects can be used for fetching status and statistics of the Wi-Fi Wifimngr is also responsible for passing the received Netlink events from the "libwifi" layer to the system's bus (f.e. UBUS in the Openwrt based systems). -The radio objects are named as **"wifi.radio.<radioname>"**, while the interface objects are **"wifi.ap.<ifname>"** or **"wifi.backhaul.<ifanme>"** respectively for the AP and STA mode interfaces. +The radio objects are named as **"wifi.radio.<radioname>"**, while the interface objects are **"wifi.ap.<ifname>"** or **"wifi.bsta.<ifanme>"** respectively for the AP and STA mode interfaces. With the Example-1 `"wireless"` config below, wifimngr creates a `"wifi.radio.radio0"` object for the `"wifi-device"` section. @@ -29,7 +29,7 @@ config wifi-device "radio0" ```` -For Example-2 config below, wifimngr creates `"wifi.ap.wlan0"` and `"wifi.backhaul.wlan0-1"` objects for the `"wifi-iface"` 'ap' and 'sta' sections respectively. +For Example-2 config below, wifimngr creates `"wifi.ap.wlan0"` and `"wifi.bsta.wlan0-1"` objects for the `"wifi-iface"` 'ap' and 'sta' sections respectively. Example-2: --------- @@ -76,8 +76,9 @@ config wifi-mld 'mld1' ```` -For the config in Example-3 above, wifimngr creates a `"wifi.mld.wlan-01"` object for the Wi-Fi MLD interface "wlan-01". +For the config in Example-3 above, wifimngr creates a `"wifi.apmld.wlan-01"` object for the Wi-Fi AP MLD interface "wlan-01". Note the Wi-Fi MLD interface 'wlan-01' has two Affiliated AP interfaces - "wlan0" and "wlan1" from radios "radio0" and "radio1" respectively. +For MLD interface of type STA, wifimngr creates `"wifi.bstamld.<mld-ifname>"` object. ## Overview @@ -144,7 +145,7 @@ The Wi-Fi radio, interface (and mld) objects alongwith the APIs supported by eac "set_qos_map":{"set":"Array"} "send_qos_map_conf":{"sta":"String"} -'wifi.mld.wlan1' @eb47f8ed +'wifi.apmld.wlan1' @eb47f8ed "status":{} "stats":{} "assoclist":{} diff --git a/help.json b/help.json index c1e4eda0b9a40f66c0a1adb5bf8c5117118fc5a6..16218c92558bd052e91ad7842b6700fe4f655b7a 100644 --- a/help.json +++ b/help.json @@ -714,9 +714,9 @@ "arguments": [] } ], - "wifi.backhaul": [ + "wifi.bsta": [ ], - "wifi.mld": [ + "wifi.apmld": [ { "command": "status", "description": "show status summary of the MLD interface", diff --git a/ubus.c b/ubus.c index 86bfb13d7144ac6d0252e230bd0cb73c9ffc0973..0d4efe21277830faab816cf5ea227a9248774a92 100644 --- a/ubus.c +++ b/ubus.c @@ -202,12 +202,12 @@ int wifimngr_add_radio_object(struct wifimngr *w, struct wifimngr_device *wdev) { char *radioname = wdev->device; struct wifi_ubus_object *wobj; - char objname[32] = {0}; + char objname[64] = {0}; uint32_t id; int ret; - snprintf(objname, 28, "wifi.radio.%s", radioname); + snprintf(objname, 63, "%s.%s", WIFI_RADIO_OBJECT, radioname); /* Already added */ if (ubus_lookup_id(w->ubus_ctx, objname, &id) == UBUS_STATUS_OK) { @@ -446,15 +446,15 @@ static int add_sta_methods(struct wifimngr *w, struct ubus_object *interface_obj int wifimngr_add_interface_object(struct wifimngr *w, struct wifimngr_iface *iface) { struct wifi_ubus_object *wobj; - char objname[32] = {0}; + char objname[64] = {0}; uint32_t id; int ret; if (iface->mode == WIFI_MODE_AP) { - snprintf(objname, 25, "wifi.ap.%s", iface->iface); + snprintf(objname, 63, "%s.%s", WIFI_AP_OBJECT, iface->iface); } else if (iface->mode == WIFI_MODE_STA) { - snprintf(objname, 31, "wifi.bsta.%s", iface->iface); + snprintf(objname, 63, "%s.%s", WIFI_BSTA_OBJECT, iface->iface); } else { /* unhandled wifi mode */ return -EINVAL; @@ -580,7 +580,6 @@ static int add_mldsta_methods(struct wifimngr *w, return 0; } - int wifimngr_add_mld_interface_object(struct wifimngr *w, struct wifimngr_mld *mldif) { struct wifi_ubus_object *wobj; @@ -589,9 +588,9 @@ int wifimngr_add_mld_interface_object(struct wifimngr *w, struct wifimngr_mld *m int ret; if (mldif->mode == WIFI_MODE_AP) - snprintf(objname, 63, "wifi.apmld.%s", mldif->ifname); + snprintf(objname, 63, "%s.%s", WIFI_APMLD_OBJECT, mldif->ifname); else if (mldif->mode == WIFI_MODE_STA) - snprintf(objname, 63, "wifi.bstamld.%s", mldif->ifname); + snprintf(objname, 63, "%s.%s", WIFI_BSTAMLD_OBJECT, mldif->ifname); else return -EINVAL; @@ -643,17 +642,17 @@ int wifimngr_add_objects(struct wifimngr *w) { int ret; - ret = wifimngr_add_object(w, "wifi", add_wifi_methods, &w->wifi_obj); + ret = wifimngr_add_object(w, WIFI_OBJECT, add_wifi_methods, &w->wifi_obj); if (ret) { - wifimngr_err("Failed to add 'wifi' ubus object: %s\n", - ubus_strerror(ret)); + wifimngr_err("Failed to add '%s' ubus object: %s\n", + WIFI_OBJECT, ubus_strerror(ret)); goto out_exit; } - ret = wifimngr_add_object(w, "wifi.wps", add_wps_methods, &w->wifi_wps_obj); + ret = wifimngr_add_object(w, WIFI_WPS_OBJECT, add_wps_methods, &w->wifi_wps_obj); if (ret) { - wifimngr_err("Failed to add 'wifi.wps' ubus object: %s\n", - ubus_strerror(ret)); + wifimngr_err("Failed to add '%s' ubus object: %s\n", + WIFI_WPS_OBJECT, ubus_strerror(ret)); goto out_exit; } diff --git a/wifimngr.c b/wifimngr.c index e2065963f185556bd5e14269b8607a07e3268687..fccdb4527cc8441be2528ef77e4d76d8d2f69252 100644 --- a/wifimngr.c +++ b/wifimngr.c @@ -354,20 +354,20 @@ struct wifimngr_device *wifimngr_ifname_to_device(struct wifimngr *w, const char const char *ubus_objname_to_ifname(struct ubus_object *obj) { - if (strstr(obj->name, "wifi.radio.")) - return obj->name + strlen("wifi.radio."); + if (strstr(obj->name, WIFI_RADIO_OBJECT_PREFIX)) + return obj->name + strlen(WIFI_RADIO_OBJECT_PREFIX); - if (strstr(obj->name, "wifi.apmld.")) - return obj->name + strlen("wifi.apmld."); + if (strstr(obj->name, WIFI_APMLD_OBJECT_PREFIX)) + return obj->name + strlen(WIFI_APMLD_OBJECT_PREFIX); - if (strstr(obj->name, "wifi.bstamld.")) - return obj->name + strlen("wifi.bstamld."); + if (strstr(obj->name, WIFI_BSTAMLD_OBJECT_PREFIX)) + return obj->name + strlen(WIFI_BSTAMLD_OBJECT_PREFIX); - if (strstr(obj->name, "wifi.ap.")) - return obj->name + strlen("wifi.ap."); + if (strstr(obj->name, WIFI_AP_OBJECT_PREFIX)) + return obj->name + strlen(WIFI_AP_OBJECT_PREFIX); - if (strstr(obj->name, "wifi.bsta.")) - return obj->name + strlen("wifi.bsta."); + if (strstr(obj->name, WIFI_BSTA_OBJECT_PREFIX)) + return obj->name + strlen(WIFI_BSTA_OBJECT_PREFIX); return "\0"; } @@ -1293,7 +1293,7 @@ int wl_radio_help(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - return wl_help_command(ctx, obj, req, method, msg, "wifi.radio"); + return wl_help_command(ctx, obj, req, method, msg, WIFI_RADIO_OBJECT); } int wl_radio_status(struct ubus_context *ctx, struct ubus_object *obj, @@ -1671,7 +1671,7 @@ int wl_ap_help(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - return wl_help_command(ctx, obj, req, method, msg, "wifi.ap"); + return wl_help_command(ctx, obj, req, method, msg, WIFI_AP_OBJECT); } int wl_ap_status(struct ubus_context *ctx, struct ubus_object *obj, @@ -5133,7 +5133,7 @@ int wl_help(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - return wl_help_command(ctx, obj, req, method, msg, "wifi"); + return wl_help_command(ctx, obj, req, method, msg, WIFI_OBJECT); } int wifi_set_debug(struct ubus_context *ctx, struct ubus_object *obj, @@ -5200,7 +5200,7 @@ int wl_apmld_help(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - return wl_help_command(ctx, obj, req, method, msg, "wifi.mld"); + return wl_help_command(ctx, obj, req, method, msg, WIFI_APMLD_OBJECT); } int wl_apmld_status(struct ubus_context *ctx, struct ubus_object *obj, @@ -5581,7 +5581,7 @@ int wifimngr_reconfig(struct wifimngr *w) return -1; } - /* remove wifi.radio.* objects that are no longer valid and + /* remove wifi radio objects that are no longer valid and * update 'priv' context for the ones that are still valid. */ list_for_each_entry_safe(p, tmp, &w->radiolist, list) { @@ -5593,11 +5593,12 @@ int wifimngr_reconfig(struct wifimngr *w) } } - /* add wifi.radio.* objects */ + /* add wifi radio objects */ for (i = 0; i < w->num_wifi_device; i++) { ret = wifimngr_add_radio_object(w, &w->wdev[i]); if (ret) { - wifimngr_err("Failed to add 'wifi.radio' ubus object: %s\n", + wifimngr_err("Failed to add '%s.%s' ubus object: %s\n", + WIFI_RADIO_OBJECT, w->wdev[i].device, ubus_strerror(ret)); return -1; } @@ -5611,11 +5612,11 @@ int wifimngr_reconfig(struct wifimngr *w) ret = wifimngr_get_wifi_mlds(w, w->conffile); if (ret < 0) { - wifimngr_err("get_wifi_interfaces() ret = %d\n", ret); + wifimngr_err("get_wifi_mlds() ret = %d\n", ret); return -1; } - /* remove wifi.ap/backhaul.* objects that are no longer valid and + /* remove wifi.ap* and wifi.bsta* objects that are no longer valid and * update 'priv' context for the ones that are still valid. */ list_for_each_entry_safe(p, tmp, &w->iflist, list) { @@ -5628,7 +5629,7 @@ int wifimngr_reconfig(struct wifimngr *w) } - /* add wifi.ap/backhaul.* objects */ + /* add wifi.ap/bsta.* objects */ for (i = 0; i < w->num_wifi_iface; i++) { if (w->ifs[i].disabled) continue; @@ -5640,18 +5641,20 @@ int wifimngr_reconfig(struct wifimngr *w) #endif ret = wifimngr_add_interface_object(w, &w->ifs[i]); if (ret) { - wifimngr_err("Failed to add 'wifi.iface.' ubus object: %s\n", - ubus_strerror(ret)); + wifimngr_err("Failed to add '%s.%s' ubus object: %s\n", + WIFI_AP_OBJECT, w->ifs[i].iface, ubus_strerror(ret)); return -1; } } - /* add wifi.mld.* objects */ + /* add wifi.apmld.* or wifi.bstamld.* objects */ for (i = 0; i < w->num_wifi_mld; i++) { ret = wifimngr_add_mld_interface_object(w, &w->mld[i]); if (ret) { - wifimngr_err("Failed to add 'wifi.mld.' ubus object: %s\n", - ubus_strerror(ret)); + wifimngr_err("Failed to add '%s.%s' ubus object: %s\n", + w->mld[i].mode == WIFI_MODE_AP ? + WIFI_APMLD_OBJECT : WIFI_BSTAMLD_OBJECT, + w->mld[i].ifname, ubus_strerror(ret)); return -1; } } diff --git a/wifimngr.h b/wifimngr.h index 62be90c16f7f1b7b089e1572824b7c6a9f143161..f68c7ca3da4563f367b26e1960467eaded7fae35 100644 --- a/wifimngr.h +++ b/wifimngr.h @@ -19,6 +19,22 @@ #define WIFI_IF_MAX_NUM 32 #define WIFI_MLD_MAX_NUM 4 +#define WIFI_OBJECT "wifi" +#define WIFI_WPS_OBJECT "wifi.wps" + +#define WIFI_RADIO_OBJECT "wifi.radio" +#define WIFI_AP_OBJECT "wifi.ap" +#define WIFI_BSTA_OBJECT "wifi.bsta" +#define WIFI_APMLD_OBJECT "wifi.apmld" +#define WIFI_BSTAMLD_OBJECT "wifi.bstamld" + +#define WIFI_AP_OBJECT_PREFIX WIFI_AP_OBJECT"." +#define WIFI_RADIO_OBJECT_PREFIX WIFI_RADIO_OBJECT"." +#define WIFI_BSTA_OBJECT_PREFIX WIFI_BSTA_OBJECT"." +#define WIFI_APMLD_OBJECT_PREFIX WIFI_APMLD_OBJECT"." +#define WIFI_BSTAMLD_OBJECT_PREFIX WIFI_BSTAMLD_OBJECT"." + + /* wifi ubus objects */ struct wifi_ubus_object { void *priv; diff --git a/wifimngr_event.c b/wifimngr_event.c index bd5fda3986510c2f4adf1ebfd3134d2d5453572d..07effa51883487a0d85370f232f3f92e4c479bb4 100644 --- a/wifimngr_event.c +++ b/wifimngr_event.c @@ -95,12 +95,12 @@ int wifimngr_event_cb(struct event_struct *e) if (resp->len > 0) { snprintf(evtbuf, MAX_EVENT_RESPONSE_LEN - 1, - "wifi.radio '{\"ifname\":\"%s\", \"event\":\"%s\", \"data\": %s}'", - e->ifname, evtype, resp->data); + "%s '{\"ifname\":\"%s\", \"event\":\"%s\", \"data\": %s}'", + WIFI_RADIO_OBJECT, e->ifname, evtype, resp->data); } else { snprintf(evtbuf, MAX_EVENT_RESPONSE_LEN - 1, - "wifi.radio '{\"ifname\":\"%s\", \"event\":\"%s\"}'", - e->ifname, evtype); + "%s '{\"ifname\":\"%s\", \"event\":\"%s\"}'", + WIFI_RADIO_OBJECT, e->ifname, evtype); } wifimngr_ubus_event(w->ubus_ctx, evtbuf); @@ -117,8 +117,8 @@ int wifimngr_event_cb(struct event_struct *e) break; case WIFI_EVENT_SCAN_ABORT: snprintf(evtbuf, MAX_EVENT_RESPONSE_LEN - 1, - "wifi.radio '{\"ifname\":\"%s\", \"event\":\"scan_aborted\"}'", - e->ifname); + "%s '{\"ifname\":\"%s\", \"event\":\"scan_aborted\"}'", + WIFI_RADIO_OBJECT, e->ifname); wifimngr_ubus_event(w->ubus_ctx, evtbuf); break; default: