WiFi.DataElements.: Add support for ChannelScanRequest() operate

This commit is contained in:
Amin Ben Ramdhane 2022-03-22 18:47:11 +01:00
parent 2425cfee53
commit 5a2aba3430
4 changed files with 95 additions and 9 deletions

View file

@ -885,7 +885,7 @@ static int ubus_set_operate(json_object *mapping_obj, int json_version, char *re
}
}
dmubus_operate_blob_set(buf_object, buf_method, in_args, &res);
dmubus_call_blob(buf_object, buf_method, in_args, &res);
if (in_args)
json_object_put(in_args);

View file

@ -6025,7 +6025,7 @@ static int operate_WiFiDataElementsNetworkDevice_SetDFSState(char *refparam, str
{
//TODO
return CMD_SUCCESS;
}
}*/
static operation_args wifidataelementsnetworkdeviceradio_channelscanrequest_args = {
.in = (const char *[]) {
@ -6047,11 +6047,57 @@ static int get_operate_args_WiFiDataElementsNetworkDeviceRadio_ChannelScanReques
static int operate_WiFiDataElementsNetworkDeviceRadio_ChannelScanRequest(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
//TODO
char *status = "Success";
char *agent_id = NULL;
char *macaddr = NULL;
char *pch = NULL;
char *spch = NULL;
dmuci_get_value_by_section_string((((struct wifi_data_element_args *)data)->uci_s)->config_section, "agent_id", &agent_id);
dmuci_get_value_by_section_string((((struct wifi_data_element_args *)data)->uci_s)->config_section, "macaddr", &macaddr);
if ((dm_validate_string(agent_id, -1, 17, NULL, MACAddress)) ||
(dm_validate_string(macaddr, -1, 17, NULL, MACAddress))) {
status = "Error_Invalid_Input";
goto end;
}
char *channel_list = dmjson_get_value((json_object *)value, 1, "ChannelList");
if (dm_validate_unsignedInt_list(channel_list, -1, -1, -1, RANGE_ARGS{{NULL,"255"}}, 1)) {
status = "Error_Invalid_Input";
goto end;
}
struct json_object *in_args = json_object_new_object();
json_object_object_add(in_args, "agent", json_object_new_string(agent_id));
struct json_object *radio_array = json_object_new_array();
json_object_array_add(radio_array, json_object_new_string(macaddr));
json_object_object_add(in_args, "radio", radio_array);
struct json_object *channel_array = json_object_new_array();
for (pch = strtok_r(channel_list, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) {
struct json_object *val_array = json_object_new_array();
json_object_array_add(val_array, json_object_new_int(DM_STRTOL(pch)));
json_object_array_add(channel_array, val_array);
}
json_object_object_add(in_args, "channel", channel_array);
int res = dmubus_call_blob_set("map.controller", "scan", in_args);
if (res)
status = "Error_Invalid_Input";
json_object_put(in_args);
end:
add_list_parameter(ctx, dmstrdup("Status"), dmstrdup(status), DMT_TYPE[DMT_STRING], NULL);
return CMD_SUCCESS;
}
static operation_args wifidataelementsnetworkdeviceradio_wifirestart_args = {
/*static operation_args wifidataelementsnetworkdeviceradio_wifirestart_args = {
.out = (const char *[]) {
"Status",
NULL
@ -6068,8 +6114,7 @@ static int operate_WiFiDataElementsNetworkDeviceRadio_WiFiRestart(char *refparam
{
//TODO
return CMD_SUCCESS;
}
*/
}*/
/*************************************************************
* EVENTS
@ -6796,7 +6841,7 @@ DMLEAF tWiFiDataElementsNetworkDeviceRadioParams[] = {
{"BSSNumberOfEntries", &DMREAD, DMT_UNINT, get_WiFiDataElementsNetworkDeviceRadio_BSSNumberOfEntries, NULL, BBFDM_BOTH, "2.13"},
{"ScanResultNumberOfEntries", &DMREAD, DMT_UNINT, get_WiFiDataElementsNetworkDeviceRadio_ScanResultNumberOfEntries, NULL, BBFDM_BOTH, "2.13"},
{"DisAllowedOpClassChannelsNumberOfEntries", &DMREAD, DMT_UNINT, get_WiFiDataElementsNetworkDeviceRadio_DisAllowedOpClassChannelsNumberOfEntries, NULL, BBFDM_BOTH, "2.15"},
//{"ChannelScanRequest()", &DMASYNC, DMT_COMMAND, get_operate_args_WiFiDataElementsNetworkDeviceRadio_ChannelScanRequest, operate_WiFiDataElementsNetworkDeviceRadio_ChannelScanRequest, BBFDM_USP, "2.15"},
{"ChannelScanRequest()", &DMASYNC, DMT_COMMAND, get_operate_args_WiFiDataElementsNetworkDeviceRadio_ChannelScanRequest, operate_WiFiDataElementsNetworkDeviceRadio_ChannelScanRequest, BBFDM_USP, "2.15"},
//{"RadioEnable()", &DMASYNC, DMT_COMMAND, get_operate_args_WiFiDataElementsNetworkDeviceRadio_RadioEnable, operate_WiFiDataElementsNetworkDeviceRadio_RadioEnable, BBFDM_USP, "2.15"},
//{"SetTxPowerLimit()", &DMASYNC, DMT_COMMAND, get_operate_args_WiFiDataElementsNetworkDeviceRadio_SetTxPowerLimit, operate_WiFiDataElementsNetworkDeviceRadio_SetTxPowerLimit, BBFDM_USP, "2.15"},
//{"SetSpatialReuse()", &DMASYNC, DMT_COMMAND, get_operate_args_WiFiDataElementsNetworkDeviceRadio_SetSpatialReuse, operate_WiFiDataElementsNetworkDeviceRadio_SetSpatialReuse, BBFDM_USP, "2.15"},

View file

@ -364,7 +364,7 @@ static int ubus_call_req_async(const char *obj, const char *method, const unsign
return 0;
}
int dmubus_operate_blob_set(char *obj, char *method, void *value, json_object **resp)
int dmubus_call_blob(char *obj, char *method, void *value, json_object **resp)
{
uint32_t id;
struct blob_buf blob;
@ -401,6 +401,46 @@ int dmubus_operate_blob_set(char *obj, char *method, void *value, json_object **
return rc;
}
int dmubus_call_blob_set(char *obj, char *method, void *value)
{
uint32_t id;
struct blob_buf blob;
int rc = -1;
json_res = NULL;
if (ubus_ctx == NULL) {
ubus_ctx = dm_libubus_init();
if (ubus_ctx == NULL) {
printf("UBUS context is null\n\r");
return -1;
}
}
memset(&blob, 0, sizeof(struct blob_buf));
blob_buf_init(&blob, 0);
if (value != NULL) {
if (!blobmsg_add_object(&blob, (json_object *)value)) {
blob_buf_free(&blob);
return rc;
}
}
if (!ubus_lookup_id(ubus_ctx, obj, &id)) {
rc = ubus_invoke(ubus_ctx, id, method, blob.head,
receive_call_result_data, NULL, UBUS_TIMEOUT);
}
if (json_res != NULL) {
json_object_put(json_res);
json_res = NULL;
}
blob_buf_free(&blob);
return rc;
}
/* Based on an efficient hash function published by D. J. Bernstein
*/
static unsigned int djbhash(unsigned hash, const char *data, unsigned len)

View file

@ -21,7 +21,8 @@
int dmubus_call(char *obj, char *method, struct ubus_arg u_args[], int u_args_size, json_object **req_res);
int dmubus_call_set(char *obj, char *method, struct ubus_arg u_args[], int u_args_size);
int dmubus_operate_blob_set(char *obj, char *method, void *value, json_object **resp);
int dmubus_call_blob(char *obj, char *method, void *value, json_object **resp);
int dmubus_call_blob_set(char *obj, char *method, void *value);
bool dmubus_object_method_exists(const char *obj);
void dmubus_free();
void dmubus_configure(struct ubus_context *ctx);