diff --git a/inc/dm_easy_mesh_ctrl.h b/inc/dm_easy_mesh_ctrl.h index e58fa16..9d57d60 100644 --- a/inc/dm_easy_mesh_ctrl.h +++ b/inc/dm_easy_mesh_ctrl.h @@ -97,6 +97,7 @@ class dm_easy_mesh_ctrl_t : int get_network_ssid_config(cJSON *parent, char *key); int get_channel_config(cJSON *parent, char *key, em_get_channel_list_reason_t reason = em_get_channel_list_reason_none); int get_policy_config(cJSON *parent, char *key); + int get_reference_config(cJSON *parent, char *key); int get_config(em_long_string_t net_id, em_subdoc_info_t *subdoc); int set_config(dm_easy_mesh_t *dm); int copy_config(dm_easy_mesh_t *dm, em_long_string_t net_id); diff --git a/inc/em.h b/inc/em.h index ff3414c..d08b9d9 100644 --- a/inc/em.h +++ b/inc/em.h @@ -91,6 +91,8 @@ class em_t : bool is_matching_freq_band(em_freq_band_t *band); void set_al_type(bool is_al_mac) {m_is_al_em = is_al_mac;} + em_mgr_t *get_mgr() { return m_mgr; } + void orch_execute(em_cmd_t *pcmd); em_orch_state_t get_orch_state() { return m_orch_state; } void set_orch_state(em_orch_state_t state); diff --git a/inc/em_agent.h b/inc/em_agent.h index e49df5e..070729f 100644 --- a/inc/em_agent.h +++ b/inc/em_agent.h @@ -95,7 +95,6 @@ class em_agent_t : public em_mgr_t { static int mgmt_action_frame_cb(char *event_name, raw_data_t *data); void *get_assoc(void*); void io(void *data, bool input = true); - bool agent_input(void *data); bool agent_output(void *data); em_agent_t(); diff --git a/inc/em_base.h b/inc/em_base.h index eaab64d..65bc36c 100644 --- a/inc/em_base.h +++ b/inc/em_base.h @@ -77,9 +77,7 @@ extern "C" #define EM_MAX_STA_PER_STEER_POLICY 16 #define EM_MAX_STA_PER_AGENT (EM_MAX_RADIO_PER_AGENT * EM_MAX_STA_PER_BSS) -//#define EM_SUBDOC_BUFF_SZ 4096*100 -#define EM_BUFF_SZ_MUL 20 -#define EM_SUBDOC_BUFF_SZ EM_IO_BUFF_SZ*EM_BUFF_SZ_MUL +#define EM_MAX_EVENT_DATA_LEN 4096*100 #define EM_MAX_CHANNELS_IN_LIST 9 #define EM_MAX_CMD_GEN_TTL 10 #define EM_MAX_CMD_EXT_TTL 30 @@ -208,9 +206,9 @@ typedef char em_string_t[16]; typedef char em_small_string_t[8]; typedef char em_tiny_string_t[4]; typedef char em_subdoc_name_space_t[64]; -typedef char em_subdoc_data_buff_t[EM_SUBDOC_BUFF_SZ]; +typedef char em_subdoc_data_buff_t[0]; typedef char em_status_string_t[EM_IO_BUFF_SZ]; -typedef unsigned char em_raw_data_t[EM_SUBDOC_BUFF_SZ]; +typedef unsigned char em_raw_data_t[0]; typedef struct { @@ -1849,8 +1847,8 @@ typedef enum { } em_event_type_t; typedef struct { + unsigned int frame_len; unsigned char *frame; - unsigned int len; } __attribute__((__packed__)) em_frame_info_t; typedef struct { @@ -2426,7 +2424,6 @@ typedef enum { typedef struct { em_subdoc_name_space_t name; em_subdoc_data_buff_t buff; - int sz; } __attribute__((__packed__)) em_subdoc_info_t; typedef struct { @@ -2690,6 +2687,7 @@ typedef struct { typedef struct { em_bus_event_type_t type; em_cmd_params_t params; + unsigned int data_len; union { em_subdoc_info_t subdoc; em_commit_info_t commit; diff --git a/inc/em_channel.h b/inc/em_channel.h index b935e82..28cf4cc 100644 --- a/inc/em_channel.h +++ b/inc/em_channel.h @@ -28,6 +28,7 @@ class em_channel_t { virtual int push_event(em_event_t *evt) = 0; public: + virtual em_mgr_t *get_mgr() = 0; virtual dm_easy_mesh_t *get_data_model() = 0; virtual unsigned char *get_radio_interface_mac() = 0; virtual em_state_t get_state() = 0; diff --git a/inc/em_cmd.h b/inc/em_cmd.h index c1e50f4..7ab3c1e 100644 --- a/inc/em_cmd.h +++ b/inc/em_cmd.h @@ -29,7 +29,7 @@ class em_cmd_t { em_cmd_type_t m_type; em_service_type_t m_svc; em_cmd_params_t m_param; - em_event_t m_evt; + em_event_t *m_evt; em_string_t m_name; queue_t *m_em_candidates; dm_easy_mesh_t m_data_model; @@ -45,18 +45,22 @@ class em_cmd_t { public: bool validate(); - char *status_to_string(em_cmd_out_status_t status, em_status_string_t str); + char *status_to_string(em_cmd_out_status_t status, char *str); em_cmd_type_t get_type() { return m_type; } const char *get_cmd_name() { return m_name; } const char *get_arg() { return m_param.u.args.fixed_args; } em_service_type_t get_svc() { return m_svc; } - em_event_t *get_event() { return &m_evt; } + em_event_t *get_event() { return m_evt; } + unsigned int get_event_length() { return (sizeof(em_event_t) + get_event_data_length()); } + unsigned int get_event_data_length(); + void set_event_data_length(unsigned int len); em_cmd_params_t *get_param() { return &m_param; } - em_bus_event_t *get_bus_event() { return &m_evt.u.bevt; } + em_bus_event_t *get_bus_event() { return &m_evt->u.bevt; } dm_easy_mesh_t *get_data_model() { return &m_data_model; } - void copy_bus_event(em_bus_event_t *evt) { m_evt.type = em_event_type_bus; memcpy(&m_evt.u.bevt, evt, sizeof(em_bus_event_t)); } + void copy_bus_event(em_bus_event_t *evt); + void copy_frame_event(em_frame_event_t *evt); em_orch_desc_t *get_orch_desc() { return &m_orch_desc[m_orch_op_idx]; } dm_orch_type_t get_orch_op() { return m_orch_desc[m_orch_op_idx].op; } @@ -91,7 +95,7 @@ class em_cmd_t { void set_start_time() { gettimeofday(&m_start_time, NULL);} - void reset() { memset(&m_evt, 0, sizeof(em_event_t)); memset(&m_param, 0, sizeof(em_cmd_params_t));; } + void reset() { memset(m_evt, 0, sizeof(em_event_t)); memset(&m_param, 0, sizeof(em_cmd_params_t));; } void init(dm_easy_mesh_t *dm); void init(); void deinit(); diff --git a/inc/em_cmd_cli.h b/inc/em_cmd_cli.h index c5a068d..be053d7 100644 --- a/inc/em_cmd_cli.h +++ b/inc/em_cmd_cli.h @@ -32,7 +32,7 @@ class em_cmd_cli_t : public em_cmd_exec_t { static em_cmd_t m_client_cmd_spec[]; public: int get_edited_node(em_network_node_t *node, const char *header, char *buff); - int execute(em_long_string_t result); + int execute(char *result); int update_platform_defaults(em_subdoc_info_t *info, em_cmd_params_t *param, em_cmd_type_t cmd_type); em_cmd_cli_t(em_cmd_t& obj); diff --git a/inc/em_cmd_ctrl.h b/inc/em_cmd_ctrl.h index 643092d..1499d98 100644 --- a/inc/em_cmd_ctrl.h +++ b/inc/em_cmd_ctrl.h @@ -27,7 +27,7 @@ class em_cmd_ctrl_t : public em_cmd_exec_t { em_ctrl_t& m_ctrl = g_ctrl; int m_dsock; public: - int execute(em_long_string_t result); + int execute(char *result); int send_result(em_cmd_out_status_t status); em_cmd_ctrl_t(); diff --git a/inc/em_cmd_exec.h b/inc/em_cmd_exec.h index be370d4..a6db955 100644 --- a/inc/em_cmd_exec.h +++ b/inc/em_cmd_exec.h @@ -36,6 +36,9 @@ class em_cmd_exec_t { //char *get_result() { return m_cmd.get_result(); } bool validate() { return m_cmd.validate(); } em_event_t *get_event() { return m_cmd.get_event(); } + unsigned int get_event_length() { return m_cmd.get_event_length(); } + unsigned int get_event_data_length() { return m_cmd.get_event_data_length(); } + void set_event_data_length(unsigned int len) { m_cmd.set_event_data_length(len); } em_cmd_t *get_cmd() { return &m_cmd; } em_cmd_params_t *get_param() { return m_cmd.get_param(); } em_cmd_type_t get_type() { return m_cmd.m_type; } @@ -50,7 +53,7 @@ class em_cmd_exec_t { static char *get_path_from_dst_service(em_service_type_t to_svc, em_long_string_t sock_path); static int load_params_file(const char *filename, char *buff); - virtual int execute(em_long_string_t result) = 0; + virtual int execute(char *result) = 0; void release_wait(); void wait(struct timespec *time_to_wait); diff --git a/inc/em_configuration.h b/inc/em_configuration.h index c224021..3ab3744 100644 --- a/inc/em_configuration.h +++ b/inc/em_configuration.h @@ -24,6 +24,7 @@ #include "dm_easy_mesh.h" class em_cmd_t; +class em_mgr_t; class em_configuration_t { int create_autoconfig_resp_msg(unsigned char *buff, em_freq_band_t band, unsigned char *dst); @@ -73,6 +74,7 @@ class em_configuration_t { // helpers void fill_media_data(em_media_spec_data_t *spec); + virtual em_mgr_t *get_mgr() = 0; virtual dm_easy_mesh_t *get_data_model() = 0; virtual em_state_t get_state() = 0; virtual void set_state(em_state_t state) = 0; diff --git a/inc/em_ctrl.h b/inc/em_ctrl.h index 146f9dd..2739a58 100644 --- a/inc/em_ctrl.h +++ b/inc/em_ctrl.h @@ -73,7 +73,6 @@ class em_ctrl_t : public em_mgr_t { void handle_sta_assoc_event(em_bus_event_t *evt); void io(void *data, bool input = true); - bool io_process(em_event_t *evt); dm_easy_mesh_t *get_data_model(const char *net_id, const unsigned char *al_mac = NULL) { return m_data_model.get_data_model(net_id, al_mac); } dm_easy_mesh_t *create_data_model(const char *net_id, const unsigned char *al_mac, em_profile_type_t profile = em_profile_type_3) { return m_data_model.create_data_model(net_id, al_mac, profile); } diff --git a/inc/em_mgr.h b/inc/em_mgr.h index 4b37350..61e4367 100644 --- a/inc/em_mgr.h +++ b/inc/em_mgr.h @@ -78,6 +78,10 @@ class em_mgr_t { virtual em_service_type_t get_service_type() = 0; + bool io_process(em_event_t *evt); + void io_process(em_bus_event_type_t type, char *data, unsigned int len); + void io_process(em_bus_event_type_t type, unsigned char *data, unsigned int len); + em_mgr_t(); ~em_mgr_t(); }; diff --git a/inc/em_steering.h b/inc/em_steering.h index 20e7b08..922e122 100644 --- a/inc/em_steering.h +++ b/inc/em_steering.h @@ -39,6 +39,7 @@ class em_steering_t { short create_btm_request_tlv(unsigned char *buff); public: + virtual em_mgr_t *get_mgr() = 0; virtual int send_frame(unsigned char *buff, unsigned int len, bool multicast = false) = 0; virtual dm_easy_mesh_t *get_data_model() = 0; virtual unsigned char *get_radio_interface_mac() = 0; diff --git a/src/agent/em_agent.cpp b/src/agent/em_agent.cpp index a112065..9f49f16 100644 --- a/src/agent/em_agent.cpp +++ b/src/agent/em_agent.cpp @@ -400,8 +400,6 @@ void em_agent_t::input_listener() { wifi_bus_desc_t *desc; dm_easy_mesh_t dm; - em_event_t evt; - em_bus_event_t *bevt; raw_data_t data; bus_init(&m_bus_hdl); @@ -426,11 +424,7 @@ void em_agent_t::input_listener() printf("%s:%d recv data:\r\n%s\r\n", __func__, __LINE__, (char *)data.raw_data.bytes); } - bevt = &evt.u.bevt; - bevt->type = em_bus_event_type_dev_init; - memcpy(bevt->u.raw_buff, data.raw_data.bytes, data.raw_data_len); - - g_agent.agent_input(&evt); + g_agent.io_process(em_bus_event_type_dev_init, (unsigned char *)data.raw_data.bytes, data.raw_data_len); if (desc->bus_event_subs_fn(&m_bus_hdl, WIFI_WEBCONFIG_DOC_DATA_NORTH, (void *)&em_agent_t::onewifi_cb, NULL, 0) != 0) { printf("%s:%d bus get failed\n", __func__, __LINE__); @@ -457,18 +451,11 @@ void em_agent_t::input_listener() int em_agent_t::mgmt_action_frame_cb(char *event_name, raw_data_t *data) { - em_bus_event_t *bevt; - em_event_t evt; struct ieee80211_mgmt *btm_frame = (struct ieee80211_mgmt *)data->raw_data.bytes; //printf("Received Frame data for event %s \n", event_name); - if(btm_frame->u.action.u.bss_tm_resp.action == WLAN_WNM_BTM_RESPONSE) - { - bevt = &evt.u.bevt; - bevt->type = em_bus_event_type_btm_response; - memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len); - - g_agent.agent_input(&evt); + if (btm_frame->u.action.u.bss_tm_resp.action == WLAN_WNM_BTM_RESPONSE) { + g_agent.io_process(em_bus_event_type_btm_response, (unsigned char *)data->raw_data.bytes, data->raw_data_len); return 1; } @@ -479,8 +466,6 @@ int em_agent_t::mgmt_action_frame_cb(char *event_name, raw_data_t *data) int em_agent_t::assoc_stats_cb(char *event_name, raw_data_t *data) { //printf("%s:%d recv data:\r\n%s\r\n", __func__, __LINE__, (char *)data->raw_data.bytes); - em_event_t evt; - em_bus_event_t *bevt; cJSON *json, *assoc_stats_arr; json = cJSON_Parse((const char *)data->raw_data.bytes); @@ -495,11 +480,7 @@ int em_agent_t::assoc_stats_cb(char *event_name, raw_data_t *data) } } - bevt = &evt.u.bevt; - bevt->type = em_bus_event_type_sta_link_metrics; - memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len); - - g_agent.agent_input(&evt); + g_agent.io_process(em_bus_event_type_sta_link_metrics, (unsigned char *)data->raw_data.bytes, data->raw_data_len); return 1; } @@ -507,21 +488,12 @@ int em_agent_t::assoc_stats_cb(char *event_name, raw_data_t *data) int em_agent_t::sta_cb(char *event_name, raw_data_t *data) { //printf("%s:%d Recv data from onewifi:\r\n%s\r\n", __func__, __LINE__, (char *)data->raw_data.bytes); - em_event_t evt; - em_bus_event_t *bevt; - - bevt = &evt.u.bevt; - bevt->type = em_bus_event_type_sta_list; - memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len); - - g_agent.agent_input(&evt); + g_agent.io_process(em_bus_event_type_sta_list, (unsigned char *)data->raw_data.bytes, data->raw_data_len); } int em_agent_t::onewifi_cb(char *event_name, raw_data_t *data) { - em_event_t evt; - em_bus_event_t *bevt; const char *json_data = (char *)data->raw_data.bytes; cJSON *json = cJSON_Parse(json_data); @@ -535,16 +507,12 @@ int em_agent_t::onewifi_cb(char *event_name, raw_data_t *data) if ((strcmp(subdoc_name->valuestring, "private") == 0) || (strcmp(subdoc_name->valuestring, "Vap_5G") == 0) || (strcmp(subdoc_name->valuestring, "Vap_2.4G") == 0)) { printf("%s:%d Found SubDocName: private\n", __func__, __LINE__); - bevt = &evt.u.bevt; - bevt->type = em_bus_event_type_onewifi_private_cb; - memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len); + g_agent.io_process(em_bus_event_type_onewifi_private_cb, (unsigned char *)data->raw_data.bytes, data->raw_data_len); } else if ((strcmp(subdoc_name->valuestring, "radio") == 0) || (strcmp(subdoc_name->valuestring, "radio_5G") == 0) || (strcmp(subdoc_name->valuestring, "radio_2.4G") == 0)) { printf("%s:%d Found SubDocName: radio\n", __func__, __LINE__); - bevt = &evt.u.bevt; - bevt->type = em_bus_event_type_onewifi_radio_cb; - memcpy(bevt->u.raw_buff, data->raw_data.bytes, data->raw_data_len); + g_agent.io_process(em_bus_event_type_onewifi_radio_cb, (unsigned char *)data->raw_data.bytes, data->raw_data_len); } else { printf("%s:%d SubDocName not matching private or radio \n", __func__, __LINE__); @@ -557,8 +525,6 @@ int em_agent_t::onewifi_cb(char *event_name, raw_data_t *data) cJSON_Delete(json); } - g_agent.agent_input(&evt); - } int em_agent_t::data_model_init(const char *data_model_path) diff --git a/src/agent/em_agent_io.cpp b/src/agent/em_agent_io.cpp index f5867fd..ff7fde0 100644 --- a/src/agent/em_agent_io.cpp +++ b/src/agent/em_agent_io.cpp @@ -40,37 +40,6 @@ #include "util.h" -bool em_agent_t::agent_input(void *data) -{ - em_event_t *evt; - em_bus_event_t *inp; - bool ret = true; - em_bus_event_t *bevt; - - inp = &((em_event_t *)data)->u.bevt; - - if ((inp->type == em_bus_event_type_dev_init) || (inp->type == em_bus_event_type_sta_list) || (inp->type == em_bus_event_type_onewifi_private_cb) || (inp->type == em_bus_event_type_m2ctrl_configuration) || (inp->type == em_bus_event_type_cfg_renew) || (inp->type == em_bus_event_type_channel_pref_query) || (inp->type == em_bus_event_type_channel_sel_req) || (inp->type == em_bus_event_type_onewifi_radio_cb) - || (inp->type == em_bus_event_type_sta_link_metrics) - || (inp->type == em_bus_event_type_bss_tm_req) - || (inp->type == em_bus_event_type_btm_response)) { - evt = (em_event_t *)malloc(sizeof(em_event_t)); - evt->type = em_event_type_bus; - bevt = &evt->u.bevt; - bevt->type = inp->type; - memcpy(&bevt->u.raw_buff, inp->u.raw_buff, sizeof(inp->u.raw_buff)); - } else { - evt = em_cmd_agent_t::create_event((char *)inp->u.subdoc.buff); - } - if (evt != NULL) { - push_to_queue(evt); - } else { - if (strncmp(m_data_model_path, "sim", strlen("sim")) == 0) { - ret = false; - } - } - return ret; -} - bool em_agent_t::agent_output(void *data) { // send configuration to OneWifi after translating diff --git a/src/agent/em_cmd_agent.cpp b/src/agent/em_cmd_agent.cpp index fffd77b..af0c5ef 100644 --- a/src/agent/em_cmd_agent.cpp +++ b/src/agent/em_cmd_agent.cpp @@ -55,9 +55,8 @@ int em_cmd_agent_t::execute(em_long_string_t result) { struct sockaddr_un addr; int ret, lsock, dsock; - unsigned int sz = sizeof(em_event_t), i, offset, iter; + unsigned int sz = EM_MAX_EVENT_DATA_LEN, i, offset, iter; unsigned char *tmp; - bool wait = false; m_cmd.reset(); @@ -90,32 +89,28 @@ int em_cmd_agent_t::execute(em_long_string_t result) continue; } - setsockopt(m_dsock, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)); // Send buffer 1K - setsockopt(m_dsock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)); // Receive buffer 1K + setsockopt(m_dsock, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)); // Send buffer EM_MAX_EVENT_DATA_LEN + setsockopt(m_dsock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)); // Receive buffer EM_MAX_EVENT_DATA_LEN printf("%s:%d: Connection accepted from client\n", __func__, __LINE__); tmp = (unsigned char *)get_event(); - if ((ret = recv(m_dsock, tmp, sizeof(em_event_t), 0)) <= 0) { + if ((ret = recv(m_dsock, tmp, sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN, 0)) <= 0) { printf("%s:%d: listen error on socket, err:%d\n", __func__, __LINE__, errno); break; } switch (get_event()->type) { case em_event_type_bus: - wait = m_agent.agent_input(get_event()); + //assert(0); + m_agent.io_process(get_event()); break; default: - wait = false; break; } - if (wait == false) { - send_result(em_cmd_out_status_other); - } - m_cmd.reset(); } @@ -218,8 +213,8 @@ em_event_t *em_cmd_agent_t::create_event(char *buff) } memcpy(&bevt->params, &cmd->m_param, sizeof(em_cmd_params_t)); - memcpy(&bevt->u.subdoc.buff, buff, EM_SUBDOC_BUFF_SZ-1); - bevt->u.subdoc.sz = strlen(buff); + memcpy(&bevt->u.subdoc.buff, buff, EM_MAX_EVENT_DATA_LEN); + bevt->data_len = strlen(buff) + 1; return evt; } diff --git a/src/cli/em_cli.cpp b/src/cli/em_cli.cpp index e592769..3096ad7 100644 --- a/src/cli/em_cli.cpp +++ b/src/cli/em_cli.cpp @@ -179,7 +179,8 @@ em_cmd_t& em_cli_t::get_command(char *in, size_t in_len, em_network_node_t *node em_network_node_t *em_cli_t::exec(char *in, size_t sz, em_network_node_t *node) { em_long_string_t cmd; - em_status_string_t res; + char *result; + em_network_node_t *new_node; em_cmd_cli_t *cli_cmd; snprintf(cmd, sizeof(cmd), "%s", in); @@ -187,18 +188,24 @@ em_network_node_t *em_cli_t::exec(char *in, size_t sz, em_network_node_t *node) cli_cmd->init(); + result = (char *)malloc(EM_MAX_EVENT_DATA_LEN); + memset(result, 0, EM_MAX_EVENT_DATA_LEN); + if (cli_cmd->validate() == false) { - cli_cmd->m_cmd.status_to_string(em_cmd_out_status_invalid_input, res); + cli_cmd->m_cmd.status_to_string(em_cmd_out_status_invalid_input, result); } else { - if (cli_cmd->execute(res) != 0) { - cli_cmd->m_cmd.status_to_string(em_cmd_out_status_invalid_input, res); + if (cli_cmd->execute(result) != 0) { + cli_cmd->m_cmd.status_to_string(em_cmd_out_status_invalid_input, result); } } delete cli_cmd; - return em_net_node_t::get_network_tree(res); + new_node = em_net_node_t::get_network_tree(result); + free(result); + + return new_node; } void em_cli_t::init_lib_dbg(char *file_name) diff --git a/src/cli/em_cmd_cli.cpp b/src/cli/em_cmd_cli.cpp index 4117aa5..2a44c02 100644 --- a/src/cli/em_cmd_cli.cpp +++ b/src/cli/em_cmd_cli.cpp @@ -48,7 +48,7 @@ em_cmd_params_t spec_params[] = { {.u = {.args = {0, {"", "", "", "", ""}, "none"}}}, {.u = {.args = {3, {"", "", "", "", ""}, "Reset.json"}}}, {.u = {.args = {1, {"", "", "", "", ""}, "Radiocap.json"}}}, - {.u = {.args = {1, {"", "", "", "", ""}, "DevTest.json"}}}, + {.u = {.args = {1, {"", "", "", "", ""}, "DevTest"}}}, {.u = {.args = {1, {"", "", "", "", ""}, "CfgRenew.json"}}}, {.u = {.args = {1, {"", "", "", "", ""}, "VapConfig.json"}}}, {.u = {.args = {2, {"", "", "", "", ""}, "Network"}}}, @@ -132,8 +132,7 @@ int em_cmd_cli_t::update_platform_defaults(em_subdoc_info_t *subdoc, em_cmd_para //dm.print_config(); // Now empty the buffer and encode again - memset(subdoc->buff, 0, EM_SUBDOC_BUFF_SZ); - subdoc->sz = EM_SUBDOC_BUFF_SZ; + memset(subdoc->buff, 0, strlen(subdoc->buff) + 1); dm.encode_config(subdoc, key); return 0; @@ -158,7 +157,6 @@ int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, c } if (found_result == false) { - printf("%s:%d: Could not find child with Result\n", __func__, __LINE__); child = em_net_node_t::clone_network_tree(node);; } @@ -188,19 +186,16 @@ int em_cmd_cli_t::get_edited_node(em_network_node_t *node, const char *header, c node_str = em_net_node_t::get_network_tree_string(new_node); m_cli.dump_lib_dbg(node_str); em_net_node_t::free_network_tree_string(node_str); - obj = (cJSON *)em_net_node_t::network_tree_to_json(new_node); - formatted = cJSON_Print((cJSON *)em_net_node_t::network_tree_to_json(new_node)); + formatted = cJSON_Print(obj); strncpy(buff, formatted, strlen(formatted) + 1); cJSON_Delete(obj); - em_net_node_t::free_network_tree(new_node); - return strlen(formatted) + 1; } -int em_cmd_cli_t::execute(em_string_t res) +int em_cmd_cli_t::execute(char *result) { struct sockaddr_un addr; int dsock, ret; @@ -209,7 +204,7 @@ int em_cmd_cli_t::execute(em_string_t res) em_event_t *evt; em_cmd_params_t *param; dm_easy_mesh_t dm; - unsigned int sz = sizeof(em_event_t); + unsigned int sz = sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN; unsigned char *tmp; em_long_string_t in, sock_path; em_status_string_t out; @@ -236,22 +231,13 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_dev_test; info = &bevt->u.subdoc; snprintf(info->name, sizeof(info->name), "%s", param->u.args.fixed_args); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { - printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, - param->u.args.fixed_args, errno); - return -1; - } - if (update_platform_defaults(info, param, em_cmd_type_dev_test) != 0) { - printf("%s:%d: failed to update default parameters\n", __func__, __LINE__); - return -1; - } break; case em_cmd_type_cfg_renew: bevt->type = em_bus_event_type_cfg_renew; info = &bevt->u.subdoc; snprintf(info->name, sizeof(info->name), "%s", param->u.args.fixed_args); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((bevt->data_len = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; @@ -262,7 +248,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_ap_cap_query; info = &bevt->u.subdoc; snprintf(info->name, sizeof(info->name), "%s", param->u.args.fixed_args); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((bevt->data_len = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; @@ -273,7 +259,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_client_cap_query; info = &bevt->u.subdoc; snprintf(info->name, sizeof(info->name), "%s", param->u.args.fixed_args); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((bevt->data_len = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; @@ -284,7 +270,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_reset; info = &bevt->u.subdoc; snprintf(info->name, sizeof(info->name), "%s", param->u.args.fixed_args); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((bevt->data_len = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; @@ -315,7 +301,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_remove_device; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "RemoveDevice", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "RemoveDevice", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -335,7 +321,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_set_radio; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "RadioEnable", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "RadioEnable", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -361,7 +347,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_set_ssid; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "SetSSID", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "SetSSID", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -374,14 +360,20 @@ int em_cmd_cli_t::execute(em_string_t res) break; case em_cmd_type_set_channel: - snprintf(in, sizeof(in), "get_channel %s 1", m_cmd.m_param.u.args.args[1]); - if ((node = m_cli.exec(in, strlen(in), NULL)) == NULL) { - return -1; - } + if (m_cli.m_params.cli_type == em_cli_type_cmd) { + snprintf(in, sizeof(in), "get_channel %s 1", m_cmd.m_param.u.args.args[1]); + if ((node = m_cli.exec(in, strlen(in), NULL)) == NULL) { + return -1; + } + } else { + if ((node = m_cmd.m_param.net_node) == NULL) { + return -1; + } + } bevt->type = em_bus_event_type_set_channel; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "SetAnticipatedChannelPreference", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "SetAnticipatedChannelPreference", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -395,7 +387,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_scan_channel; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "ChannelScanRequest", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "ChannelScanRequest", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -405,7 +397,6 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_get_policy; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - printf("%s:%d: Name: %s\n", __func__, __LINE__, info->name); break; case em_cmd_type_set_policy: @@ -416,7 +407,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_set_policy; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "SetPolicy", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "SetPolicy", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -442,7 +433,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_steer_sta; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "ClientSteer", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "ClientSteer", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -456,7 +447,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_disassoc_sta; info = &bevt->u.subdoc; strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = get_edited_node(node, "Disassociate", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "Disassociate", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -469,12 +460,12 @@ int em_cmd_cli_t::execute(em_string_t res) } bevt->type = em_bus_event_type_btm_sta; info = &bevt->u.subdoc; - if ((info->sz = get_edited_node(node, "BTMRequest", info->buff)) < 0) { + if ((bevt->data_len = get_edited_node(node, "BTMRequest", info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } strncpy(info->name, param->u.args.fixed_args, strlen(param->u.args.fixed_args) + 1); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((bevt->data_len = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; } @@ -484,7 +475,7 @@ int em_cmd_cli_t::execute(em_string_t res) bevt->type = em_bus_event_type_start_dpp; info = &bevt->u.subdoc; snprintf(info->name, sizeof(info->name), "%s", param->u.args.fixed_args); - if ((info->sz = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { + if ((bevt->data_len = load_params_file(m_cmd.m_param.u.args.fixed_args, info->buff)) < 0) { printf("%s:%d: failed to open file at location:%s error:%d\n", __func__, __LINE__, param->u.args.fixed_args, errno); return -1; @@ -495,33 +486,34 @@ int em_cmd_cli_t::execute(em_string_t res) break; } + //printf("%s:%d: Length: %d Event len: %d\n", __func__, __LINE__, bevt->data_len, get_event_length()); + get_cmd()->init(&dm); if ((dsock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - snprintf(res, sizeof(em_long_string_t), "%s:%d: error opening socket, err:%d\n", __func__, __LINE__, errno); return -1; } - setsockopt(dsock, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)); // Send buffer 1K - setsockopt(dsock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)); // Receive buffer 1K + setsockopt(dsock, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)); // Send buffer EM_MAX_EVENT_DATA_LEN + setsockopt(dsock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)); // Receive buffer EM_MAX_EVENT_DATA_LEN memset(&addr, 0, sizeof(struct sockaddr_un)); addr.sun_family = AF_UNIX; snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", sock_path); if ((ret = connect(dsock, (const struct sockaddr *) &addr, sizeof(struct sockaddr_un))) != 0) { - snprintf(res, sizeof(em_long_string_t), "%s:%d: connect error on socket, err:%d\n", __func__, __LINE__, errno); + snprintf(result, sizeof(em_long_string_t), "%s:%d: connect error on socket, err:%d\n", __func__, __LINE__, errno); return -1; } tmp = (unsigned char *)get_event(); - if ((ret = send(dsock, tmp, sizeof(em_event_t), 0)) <= 0) { + if ((ret = send(dsock, tmp, get_event_length(), 0)) <= 0) { return -1; } /* Receive result. */ - if ((ret = recv(dsock, (unsigned char *)res, sizeof(em_status_string_t), 0)) <= 0) { - snprintf(res, sizeof(em_long_string_t), "%s:%d: result read error on socket, err:%d\n", __func__, __LINE__, errno); + if ((ret = recv(dsock, (unsigned char *)result, EM_MAX_EVENT_DATA_LEN, 0)) <= 0) { + printf("%s:%d: result read error on socket, err:%d\n", __func__, __LINE__, errno); return -1; } diff --git a/src/cli/etree/go.sum b/src/cli/etree/go.sum new file mode 100644 index 0000000..9c0c43f --- /dev/null +++ b/src/cli/etree/go.sum @@ -0,0 +1,43 @@ +github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= +github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= +github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= +github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= +github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= +github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= +github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= +github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E= +github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= +github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= +github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= +github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= +github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= +github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= +github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= +github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34= +github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho= +github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= +github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= +github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s= +github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8= +github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs= +github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ= +github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw= +golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= +golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= diff --git a/src/cli/main.go b/src/cli/main.go index feae44d..48fbd22 100644 --- a/src/cli/main.go +++ b/src/cli/main.go @@ -28,16 +28,19 @@ import ( const ( linesToDisplay int = 38 - NetworkTopologyCmd = 1 - NetworkSSIDListCmd = 2 - RadioListCmd = 3 - ChannelsListCmd = 4 - ClientDevicesCmd = 5 - NetworkPolicyCmd = 6 - NeighborsListCmd = 7 - SteerDevicesCmd = 8 - NetworkMetricsCmd = 9 - DeviceOnboardingCmd = 10 + NetworkTopologyCmd = "Network Topology" + NetworkSSIDListCmd = "SSID List" + RadioListCmd = "WiFi Radios" + ChannelsListCmd = "WiFi Channels" + ClientDevicesCmd = "Client Connections" + NetworkPolicyCmd = "Network Policy" + NeighborsListCmd = "WiFi Neighbors" + SteerDevicesCmd = "Optimize Client Connections" + NetworkMetricsCmd = "Network Metrics" + DeviceOnboardingCmd = "Onboarding & Provisioning" + WiFiEventsCmd = "WiFi Events" + WiFiResetCmd = "WiFi Reset" + DebugCmd = "Debugging & Testing" GET = 0 GETX = 1 @@ -59,7 +62,7 @@ var ( menuBodyStyle = lipgloss.NewStyle(). Background(lipgloss.Color("#ffffff")) - viewBodyStyle = lipgloss.NewStyle(). + canvasStyle = lipgloss.NewStyle(). Background(lipgloss.Color("#ebebeb")) jsonStyle = lipgloss.NewStyle(). @@ -108,24 +111,27 @@ func (i item) FilterValue() string { return i.title } type EasyMeshCmd struct { Title string + LoadOrder int GetCommand string GetCommandEx string SetCommand string Help string } -var emCommands = map[int]EasyMeshCmd { - NetworkTopologyCmd: {"Network Topology", "get_bss OneWifiMesh", "", "", ""}, - NetworkPolicyCmd: {"Network Policy", "get_policy OneWifiMesh", "get_policy OneWifiMesh", "set_policy OneWifiMesh", ""}, - NetworkSSIDListCmd: {"SSID List", "get_ssid OneWifiMesh", "get_ssid OneWifiMesh", "set_ssid OneWifiMesh", ""}, - RadioListCmd: {"WiFi Radios", "get_radio OneWifiMesh", "", "", ""}, - ChannelsListCmd: {"WiFi Channels", "get_channel OneWifiMesh", "get_channel OneWifiMesh 1", "set_channel OneWifiMesh", ""}, - NeighborsListCmd: {"WiFi Neighbors", "get_channel OneWifiMesh", "get_channel OneWifiMesh 2", "scan_channel OneWifiMesh", ""}, - ClientDevicesCmd: {"Client Connections", "get_sta OneWifiMesh", "", "", ""}, - SteerDevicesCmd: {"Optimize Connections", "get_sta OneWifiMesh", "get_sta OneWifiMesh 1", "steer_sta OneWifiMesh", ""}, - NetworkMetricsCmd: {"Network Metrics", "", "", "", ""}, - DeviceOnboardingCmd: {"Onboarding & Provisioning", "", "", "", ""}, - +var easyMeshCommands = map[string]EasyMeshCmd { + NetworkTopologyCmd: {NetworkTopologyCmd, 0, "get_bss OneWifiMesh", "", "", ""}, + NetworkPolicyCmd: {NetworkPolicyCmd, 1, "get_policy OneWifiMesh", "get_policy OneWifiMesh", "set_policy OneWifiMesh", ""}, + NetworkSSIDListCmd: {NetworkSSIDListCmd, 2, "get_ssid OneWifiMesh", "get_ssid OneWifiMesh", "set_ssid OneWifiMesh", ""}, + RadioListCmd: {RadioListCmd, 3, "get_radio OneWifiMesh", "", "", ""}, + ChannelsListCmd: {ChannelsListCmd, 4, "get_channel OneWifiMesh", "get_channel OneWifiMesh 1", "set_channel OneWifiMesh", ""}, + NeighborsListCmd: {NeighborsListCmd, 5, "get_channel OneWifiMesh", "get_channel OneWifiMesh 2", "scan_channel OneWifiMesh", ""}, + ClientDevicesCmd: {ClientDevicesCmd, 6, "get_sta OneWifiMesh", "", "", ""}, + SteerDevicesCmd: {SteerDevicesCmd, 7, "get_sta OneWifiMesh", "get_sta OneWifiMesh 1", "steer_sta OneWifiMesh", ""}, + NetworkMetricsCmd: {NetworkMetricsCmd, 8, "", "", "", ""}, + DeviceOnboardingCmd: {DeviceOnboardingCmd, 9, "", "", "", ""}, + WiFiEventsCmd: {WiFiEventsCmd, 10, "", "", "", ""}, + WiFiResetCmd: {WiFiResetCmd, 11, "get_network OneWifiMesh", "", "", ""}, + DebugCmd: {DebugCmd, 12, "dev_test OneWifiMesh", "", "", ""}, } type model struct { @@ -137,6 +143,8 @@ type model struct { activeButton int viewWidth int viewHeight int + canvasWidth int + canvasHeight int menuWidth int menuHeight int menuInstructionsHeight int @@ -145,7 +153,6 @@ type model struct { tree etree.Model currentNetNode *C.em_network_node_t displayedNetNode *C.em_network_node_t - cursor int quit chan bool ticker *time.Ticker timer *time.Timer @@ -156,8 +163,13 @@ func newModel() model { var items []list.Item - for _, value := range emCommands { - items = append(items, item{title: value.Title}) + for i := 0; i < len(easyMeshCommands); i++ { + for _, value := range easyMeshCommands { + if i == value.LoadOrder { + items = append(items, item{title: value.Title}) + break + } + } } commandList := list.New(items, list.NewDefaultDelegate(), 0, 0) @@ -237,7 +249,7 @@ func (m *model) timerHandler() { case <- m.ticker.C: - spew.Fdump(m.dump, "5 second ticker fired") + //spew.Fdump(m.dump, "5 second ticker fired") case <- m.quit: m.ticker.Stop() @@ -257,7 +269,7 @@ func (m model) treeToNodes(treeNode *etree.Node) *C.em_network_node_t { if value == "" { value = treeNode.Value.Placeholder } - + if treeNode.Type == etree.NodeTypeArrayStr || treeNode.Type == etree.NodeTypeArrayNum { C.set_node_array_value(netNode, C.CString(value)) } else { @@ -305,7 +317,10 @@ func (m model) nodesToTree(netNode *C.em_network_node_t, treeNode *etree.Node) { m.nodesToTree(childNetNode, &treeNode.Children[i]) } } - } + } else { + treeNode.Type = int(C.em_network_node_data_type_array_obj) + treeNode.Value.Placeholder = "[]" + } } else if ((nodeType == C.em_network_node_data_type_string) || (nodeType == C.em_network_node_data_type_number) || (nodeType == C.em_network_node_data_type_false) || (nodeType == C.em_network_node_data_type_true)) { @@ -328,21 +343,23 @@ func (m model) nodesToTree(netNode *C.em_network_node_t, treeNode *etree.Node) { } func (m *model) execSelectedCommand(cmdStr string, cmdType int) { - for _, value := range emCommands { + for _, value := range easyMeshCommands { if cmdStr == value.Title { switch cmdType { case GET: m.currentNetNode = C.exec(C.CString(value.GetCommand), C.strlen(C.CString(value.GetCommand)), nil) - spew.Fdump(m.dump, value.GetCommand) + //spew.Fdump(m.dump, value.GetCommand) treeNode := make([]etree.Node, 1) m.displayedNetNode = C.clone_network_tree_for_display(m.currentNetNode, nil, 0xffff, false) m.nodesToTree(m.displayedNetNode, &treeNode[0]) m.tree.SetNodes(treeNode) + //str := C.get_network_tree_string(m.displayedNetNode) + //C.dump_lib_dbg(str) case GETX: if value.GetCommandEx != "" { m.currentNetNode = C.exec(C.CString(value.GetCommandEx), C.strlen(C.CString(value.GetCommandEx)), nil) - spew.Fdump(m.dump, value.GetCommandEx) + //spew.Fdump(m.dump, value.GetCommandEx) treeNode := make([]etree.Node, 1) m.displayedNetNode = C.clone_network_tree_for_display(m.currentNetNode, nil, 0xffff, false) m.nodesToTree(m.displayedNetNode, &treeNode[0]) @@ -357,10 +374,13 @@ func (m *model) execSelectedCommand(cmdStr string, cmdType int) { } } } + + m.scrollIndex = 0 } func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { var cmds []tea.Cmd + var cmd tea.Cmd switch msg := msg.(type) { case tea.WindowSizeMsg: @@ -369,8 +389,8 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { w, h, msg.Width, msg.Height) m.menuHeight = msg.Height - m.bottomSpace - m.menuInstructionsHeight - m.viewWidth = msg.Width - m.menuWidth - m.rightSpace - m.viewHeight = msg.Height - m.bottomSpace + m.canvasWidth = msg.Width - m.menuWidth - m.rightSpace + m.canvasHeight = msg.Height - m.bottomSpace case tea.KeyMsg: switch msg.String() { @@ -395,24 +415,19 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.execSelectedCommand(selectedItem.title, GET) } } -/* - case "down": - if m.cursor > 0 { - m.cursor-- - if m.cursor < m.scrollIndex { - m.scrollIndex-- - } - } + + case "down": + if m.scrollIndex < m.tree.Cursor() { + m.scrollIndex++ + } + spew.Fprintf(m.dump, "down: %d\n", m.scrollIndex); case "up": - if m.cursor < len(m.scrollContent) - 1 { - m.cursor++ - if m.cursor >= m.scrollIndex + linesToDisplay { - m.scrollIndex++ - } - } -*/ - + if m.scrollIndex > 0 { + m.scrollIndex-- + } + spew.Fprintf(m.dump, "up: %d\n", m.scrollIndex); + case "enter": if m.activeButton == BTN_UPDATE { m.currentOperatingInstructions = "\n\n\t Editor Mode: Press 'OK' to apply settings, 'Cancel' to leave" @@ -477,7 +492,6 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds = append(cmds, cmd) } } - var cmd tea.Cmd m.tree, cmd = m.tree.Update(msg) cmds = append(cmds, cmd) @@ -496,24 +510,36 @@ func (m model) View() string { Render("↑/k up ● ↓/j down ● q quit") menuViewWithInstructions := lipgloss.JoinVertical(lipgloss.Left, menuView, instructions) - - content := m.tree.TreeView() - m.scrollContent = splitIntoLines(content) + + m.viewWidth = m.canvasWidth - 10 + + if m.canvasHeight > 10 { + m.viewHeight = m.canvasHeight - 10 + } else { + m.viewHeight = m.canvasHeight + } + + m.tree.SetSize(m.viewWidth, m.viewHeight) + + m.scrollContent = splitIntoLines(m.tree.TreeView()) var statusView string - if len(m.scrollContent) > 0 { - end := m.scrollIndex + linesToDisplay - if end > len(m.scrollContent) { - end = len(m.scrollContent) - } - styledContent := jsonStyle.Width(m.viewWidth - 10).Render(strings.Join(m.scrollContent[m.scrollIndex:end], "\n")) + start := 0 - //statusView = styledContent + "\n\n\t Press 'w' to scroll up, 's' to scroll down" - statusView = styledContent + m.currentOperatingInstructions - } else { - statusView = m.statusMessage - } + if m.scrollIndex > m.viewHeight { + start = m.scrollIndex - m.viewHeight + } + + end := len(m.scrollContent) - 1 + if end > start + m.viewHeight { + end = start + m.viewHeight + } + + spew.Fprintf(m.dump, "start: %d end: %d\n", start, end) + + styledContent := jsonStyle.Width(m.viewWidth).Height(m.viewHeight).Render(strings.Join(m.scrollContent[start:end], "\n")) + statusView = styledContent + m.currentOperatingInstructions updateButton := buttonStyle.Render("Update") okButton := buttonStyle.Render("OK") @@ -537,7 +563,7 @@ func (m model) View() string { combinedView := lipgloss.JoinHorizontal( lipgloss.Top, menuBodyStyle.Width(m.menuWidth).Height(m.menuHeight).Render(menuViewWithInstructions), - viewBodyStyle.Width(m.viewWidth).Height(m.viewHeight).Render(statusView), + canvasStyle.Width(m.canvasWidth).Height(m.canvasHeight).Render(statusView), ) commonBorderStyle := lipgloss.NewStyle(). diff --git a/src/cmd/em_cmd.cpp b/src/cmd/em_cmd.cpp index 1551762..6d554f0 100644 --- a/src/cmd/em_cmd.cpp +++ b/src/cmd/em_cmd.cpp @@ -50,7 +50,67 @@ bool em_cmd_t::validate() } -char *em_cmd_t::status_to_string(em_cmd_out_status_t status, em_status_string_t str) +unsigned int em_cmd_t::get_event_data_length() +{ + em_frame_event_t *fevt; + em_bus_event_t *bevt; + unsigned int sz = 0; + + switch (m_evt->type) { + case em_event_type_frame: + fevt = &m_evt->u.fevt; + sz = fevt->frame_len; + break; + + case em_event_type_bus: + bevt = &m_evt->u.bevt; + sz = bevt->data_len; + break; + } + + return sz; +} + +void em_cmd_t::set_event_data_length(unsigned int len) +{ + em_frame_event_t *fevt; + em_bus_event_t *bevt; + unsigned int sz = 0; + + switch (m_evt->type) { + case em_event_type_frame: + fevt = &m_evt->u.fevt; + fevt->frame_len = len; + break; + + case em_event_type_bus: + bevt = &m_evt->u.bevt; + bevt->data_len = len; + break; + } +} + +void em_cmd_t::copy_bus_event(em_bus_event_t *evt) +{ + em_bus_event_t *bevt; + + m_evt->type = em_event_type_bus; + bevt = &m_evt->u.bevt; + memcpy(bevt, evt, sizeof(em_bus_event_t)); + memcpy(bevt->u.subdoc.buff, evt->u.subdoc.buff, evt->data_len); +} + +void em_cmd_t::copy_frame_event(em_frame_event_t *evt) +{ + em_frame_event_t *fevt; + + m_evt->type = em_event_type_frame; + fevt = &m_evt->u.fevt; + memcpy(fevt, evt, sizeof(em_frame_event_t)); + memcpy(fevt->frame, evt->frame, evt->frame_len); +} + +char *em_cmd_t::status_to_string(em_cmd_out_status_t status, char *str) { cJSON *obj, *res = NULL; em_long_string_t status_str; @@ -120,6 +180,7 @@ void em_cmd_t::deinit() { queue_destroy(m_em_candidates); m_data_model.deinit(); + //free(m_evt); } void em_cmd_t::init(dm_easy_mesh_t *dm) @@ -192,6 +253,8 @@ void em_cmd_t::override_op(unsigned int index, em_orch_desc_t *desc) void em_cmd_t::init() { + //m_evt = (em_event_t *)malloc(sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN); + switch (m_type) { case em_cmd_type_none: snprintf(m_name, sizeof(m_name), "%s", "none"); @@ -711,11 +774,11 @@ em_cmd_t::em_cmd_t(em_cmd_type_t type, em_cmd_params_t param) em_cmd_t::em_cmd_t() { - + m_evt = (em_event_t *)malloc(sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN); } em_cmd_t::~em_cmd_t() { - + free(m_evt); } diff --git a/src/cmd/em_cmd_exec.cpp b/src/cmd/em_cmd_exec.cpp index d33a00c..b673261 100644 --- a/src/cmd/em_cmd_exec.cpp +++ b/src/cmd/em_cmd_exec.cpp @@ -90,7 +90,6 @@ int em_cmd_exec_t::execute(em_cmd_type_t type, em_service_type_t to_svc, unsigne bevt->type = em_cmd_t::cmd_2_bus_event_type(type); info = &bevt->u.subdoc; memcpy(info->buff, in, len); - info->sz = len; return send_cmd(to_svc, (unsigned char *)&ev, sizeof(em_event_t));; } @@ -164,7 +163,6 @@ void em_cmd_exec_t::init() { pthread_cond_init(&m_cond, NULL); pthread_mutex_init(&m_lock, NULL); - } em_cmd_exec_t::em_cmd_exec_t() diff --git a/src/ctrl/dm_easy_mesh_ctrl.cpp b/src/ctrl/dm_easy_mesh_ctrl.cpp index 49ed3e4..815c488 100644 --- a/src/ctrl/dm_easy_mesh_ctrl.cpp +++ b/src/ctrl/dm_easy_mesh_ctrl.cpp @@ -39,6 +39,7 @@ #include "dm_easy_mesh_ctrl.h" #include "dm_easy_mesh.h" #include +#include "em_cmd_exec.h" #include "em_cmd_reset.h" #include "em_cmd_dev_test.h" #include "em_cmd_remove_device.h" @@ -1083,6 +1084,32 @@ int dm_easy_mesh_ctrl_t::get_bss_config(cJSON *parent, char *key) return 0; } +int dm_easy_mesh_ctrl_t::get_reference_config(cJSON *parent, char *net_id) +{ + char *buff; + cJSON *obj; + + buff = (char *)malloc(EM_MAX_EVENT_DATA_LEN); + + if (em_cmd_exec_t::load_params_file("DevTest.json", buff) < 0) { + printf("%s:%d: Failed to load test file\n", __func__, __LINE__); + free(buff); + return -1; + } + + if ((obj = cJSON_Parse(buff)) == NULL) { + printf("%s:%d: Failed to load test file\n", __func__, __LINE__); + free(buff); + return -1; + } + + free(buff); + + cJSON_AddItemToObject(parent, "Reference", obj); + + return 0; +} + int dm_easy_mesh_ctrl_t::get_policy_config(cJSON *parent, char *net_id) { cJSON *net_obj, *dev_list_obj, *dev_obj, *policy_obj; @@ -1244,18 +1271,17 @@ int dm_easy_mesh_ctrl_t::get_network_config(cJSON *parent, char *key) netssid_list_obj = cJSON_AddArrayToObject(net_obj, "NetworkSSIDList"); dm_network_ssid_list_t::get_config(netssid_list_obj, key); -#ifdef FIX_B num = cJSON_GetArraySize(dev_list_obj); for (i = 0; i < num; i++) { - if (((dev_obj = cJSON_GetArrayItem(dev_list_obj, i)) != NULL) && - ((obj = cJSON_GetObjectItem(dev_obj, "ID")) != NULL)) { - radio_list_obj = cJSON_AddArrayToObject(dev_obj, "RadioList"); - dm_easy_mesh_t::string_to_macbytes(cJSON_GetStringValue(obj), dev_mac); - dm_radio_list_t::get_config(radio_list_obj, &dev_mac); - } + if (((dev_obj = cJSON_GetArrayItem(dev_list_obj, i)) != NULL) && + ((obj = cJSON_GetObjectItem(dev_obj, "ID")) != NULL)) { + radio_list_obj = cJSON_AddArrayToObject(dev_obj, "RadioList"); + dm_easy_mesh_t::string_to_macbytes(cJSON_GetStringValue(obj), dev_mac); + dm_radio_list_t::get_config(radio_list_obj, &dev_mac); + } } -#endif // FIX_B - return 0; + + return 0; } int dm_easy_mesh_ctrl_t::get_config(em_long_string_t net_id, em_subdoc_info_t *subdoc) @@ -1296,6 +1322,8 @@ int dm_easy_mesh_ctrl_t::get_config(em_long_string_t net_id, em_subdoc_info_t *s get_sta_config(parent, net_id, em_get_sta_list_reason_btm); } else if (strncmp(subdoc->name, "Policy", strlen(subdoc->name)) == 0) { get_policy_config(parent, net_id); + } else if (strncmp(subdoc->name, "DevTest", strlen(subdoc->name)) == 0) { + get_reference_config(parent, net_id); } tmp = cJSON_Print(parent); diff --git a/src/ctrl/em_cmd_ctrl.cpp b/src/ctrl/em_cmd_ctrl.cpp index 8b51240..e6e840f 100644 --- a/src/ctrl/em_cmd_ctrl.cpp +++ b/src/ctrl/em_cmd_ctrl.cpp @@ -40,11 +40,11 @@ #include #include "em_cmd_ctrl.h" -int em_cmd_ctrl_t::execute(em_long_string_t result) +int em_cmd_ctrl_t::execute(char *result) { struct sockaddr_un addr; int ret, lsock, dsock; - unsigned int sz = sizeof(em_event_t); + unsigned int sz = sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN; unsigned char *tmp; bool wait = false; @@ -81,21 +81,19 @@ int em_cmd_ctrl_t::execute(em_long_string_t result) continue; } - setsockopt(m_dsock, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)); // Send buffer 1K - setsockopt(m_dsock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)); // Receive buffer 1K + setsockopt(m_dsock, SOL_SOCKET, SO_SNDBUF, &sz, sizeof(sz)); // Send buffer EM_MAX_EVENT_DATA_LEN + setsockopt(m_dsock, SOL_SOCKET, SO_RCVBUF, &sz, sizeof(sz)); // Receive buffer EM_MAX_EVENT_DATA_LEN //printf("%s:%d: Connection accepted from client\n", __func__, __LINE__); tmp = (unsigned char *)get_event(); - if ((ret = recv(m_dsock, tmp, sizeof(em_event_t), 0)) <= 0) { - printf("%s:%d: listen error on socket, err:%d\n", __func__, __LINE__, errno); - } - + if ((ret = recv(m_dsock, tmp, sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN, 0)) <= 0) { + printf("%s:%d: listen error on socket, err:%d\n", __func__, __LINE__, errno); + } //printf("%s:%d: Read bytes: %d Size: %d Name: %s Buff: %s\n", __func__, __LINE__, ret, - //get_event()->u.bevt.u.subdoc.sz, get_event()->u.bevt.u.subdoc.name, get_event()->u.bevt.u.subdoc.buff); - //printf("%s:%d: Read bytes: %d\n", __func__, __LINE__, ret); + //get_event()->u.bevt.data_len, get_event()->u.bevt.u.subdoc.name, get_event()->u.bevt.u.subdoc.buff); switch (get_event()->type) { case em_event_type_bus: @@ -124,16 +122,22 @@ int em_cmd_ctrl_t::execute(em_long_string_t result) int em_cmd_ctrl_t::send_result(em_cmd_out_status_t status) { int ret; - em_status_string_t str; + char *str; unsigned char *tmp; + str = (char *)malloc(EM_MAX_EVENT_DATA_LEN); + memset(str, 0, EM_MAX_EVENT_DATA_LEN); + tmp = (unsigned char *)m_cmd.status_to_string(status, str); - if ((ret = send(m_dsock, tmp, sizeof(em_status_string_t), 0)) <= 0) { + if ((ret = send(m_dsock, tmp, strlen(str) + 1, 0)) <= 0) { printf("%s:%d: write error on socket, err:%d\n", __func__, __LINE__, errno); } + //printf("%s:%d: Send success bytes sent:%d\n", __func__, __LINE__, ret); + close(m_dsock); + free(str); return 0; } diff --git a/src/ctrl/em_ctrl.cpp b/src/ctrl/em_ctrl.cpp index 15d96e3..24a559f 100644 --- a/src/ctrl/em_ctrl.cpp +++ b/src/ctrl/em_ctrl.cpp @@ -276,6 +276,7 @@ void em_ctrl_t::handle_get_dm_data(em_bus_event_t *evt) } m_data_model.get_config(params->u.args.args[1], &evt->u.subdoc); + evt->data_len = strlen(evt->u.subdoc.buff) + 1; m_ctrl_cmd->copy_bus_event(evt); m_ctrl_cmd->send_result(em_cmd_out_status_success); } @@ -391,9 +392,6 @@ void em_ctrl_t::handle_bus_event(em_bus_event_t *evt) break; case em_bus_event_type_dev_test: - handle_dev_test(evt); - break; - case em_bus_event_type_get_network: case em_bus_event_type_get_ssid: case em_bus_event_type_get_channel: diff --git a/src/ctrl/em_ctrl_io.cpp b/src/ctrl/em_ctrl_io.cpp index 73b8f6d..527e6b5 100644 --- a/src/ctrl/em_ctrl_io.cpp +++ b/src/ctrl/em_ctrl_io.cpp @@ -37,35 +37,6 @@ #include "em_ctrl.h" #include "em_cmd_ctrl.h" -bool em_ctrl_t::io_process(em_event_t *evt) -{ - em_event_t *e; - em_bus_event_t *bevt; - bool should_wait; - - bevt = &evt->u.bevt; - //em_cmd_t::dump_bus_event(bevt); - - e = (em_event_t *)malloc(sizeof(em_event_t)); - memcpy(e, evt, sizeof(em_event_t)); - - push_to_queue(e); - - // check if the server should wait - should_wait = false; - - switch (evt->type) { - case em_event_type_bus: - bevt = &evt->u.bevt; - if (bevt->type != em_bus_event_type_dm_commit) { - should_wait = true; - } - break; - } - - return should_wait; -} - void em_ctrl_t::io(void *data, bool input) { char *str = (char *)data; diff --git a/src/em/channel/em_channel.cpp b/src/em/channel/em_channel.cpp index 51e9e63..d918fc4 100644 --- a/src/em/channel/em_channel.cpp +++ b/src/em/channel/em_channel.cpp @@ -1341,21 +1341,17 @@ int em_channel_t::handle_eht_operations_tlv(unsigned char *buff, em_eht_operatio int em_channel_t::handle_channel_pref_query(unsigned char *buff, unsigned int len) { - em_event_t ev; - em_bus_event_t *bev; em_cmdu_t *cmdu; - em_bus_event_type_channel_pref_query_params_t *params; + em_bus_event_type_channel_pref_query_params_t params; cmdu = (em_cmdu_t *)(buff + sizeof(em_raw_hdr_t)); - ev.type = em_event_type_bus; - bev = &ev.u.bevt; - bev->type = em_bus_event_type_channel_pref_query; - params = (em_bus_event_type_channel_pref_query_params_t *) &bev->u.raw_buff; - memcpy(params->mac, get_radio_interface_mac(), sizeof(mac_address_t)); - params->msg_id = ntohs(cmdu->id); - em_cmd_exec_t::send_cmd(em_service_type_agent, (unsigned char *)&ev, sizeof(em_event_t)); - return 0; + memcpy(params.mac, get_radio_interface_mac(), sizeof(mac_address_t)); + params.msg_id = ntohs(cmdu->id); + + get_mgr()->io_process(em_bus_event_type_channel_pref_query, (unsigned char *)¶ms, sizeof(em_bus_event_type_channel_pref_query_params_t)); + + return 0; } int em_channel_t::handle_channel_sel_req(unsigned char *buff, unsigned int len) @@ -1363,32 +1359,23 @@ int em_channel_t::handle_channel_sel_req(unsigned char *buff, unsigned int len) em_tlv_t *tlv; int tlv_len; - op_class_channel_sel *op_class; - - em_event_t ev; - em_bus_event_t *bev; - unsigned char* tmp = (unsigned char *) &ev.u.bevt.u.raw_buff; - - ev.type = em_event_type_bus; - bev = &ev.u.bevt; - bev->type = em_bus_event_type_channel_sel_req; - op_class = (op_class_channel_sel *)&bev->u.raw_buff; + op_class_channel_sel op_class; tlv = (em_tlv_t *)(buff + sizeof(em_raw_hdr_t) + sizeof(em_cmdu_t)); tlv_len = len - (sizeof(em_raw_hdr_t) + sizeof(em_cmdu_t)); while ((tlv->type != em_tlv_type_eom) && (len > 0)) { if (tlv->type == em_tlv_type_channel_pref) { - handle_channel_pref_tlv(tlv->value, op_class); + handle_channel_pref_tlv(tlv->value, &op_class); } if (tlv->type == em_tlv_type_tx_power) { - memcpy(&op_class->tx_power, tlv->value, sizeof(em_tx_power_limit_t)); + memcpy(&op_class.tx_power, tlv->value, sizeof(em_tx_power_limit_t)); } if (tlv->type == em_tlv_type_spatial_reuse_req) { - memcpy(&op_class->spatial_reuse_req, tlv->value, sizeof(em_spatial_reuse_req_t)); + memcpy(&op_class.spatial_reuse_req, tlv->value, sizeof(em_spatial_reuse_req_t)); } if (tlv->type == em_tlv_eht_operations) { - handle_eht_operations_tlv(tlv->value, &op_class->eht_ops); + handle_eht_operations_tlv(tlv->value, &op_class.eht_ops); break; } @@ -1396,9 +1383,11 @@ int em_channel_t::handle_channel_sel_req(unsigned char *buff, unsigned int len) tlv = (em_tlv_t *)((unsigned char *)tlv + sizeof(em_tlv_t) + htons(tlv->len)); } - op_class->freq_band = get_band(); - em_cmd_exec_t::send_cmd(em_service_type_agent, (unsigned char *)&ev, sizeof(em_event_t)); - printf("%s:%d Received channel selection request \n",__func__, __LINE__); + op_class.freq_band = get_band(); + + get_mgr()->io_process(em_bus_event_type_channel_sel_req, (unsigned char *)&op_class, sizeof(op_class_channel_sel)); + + printf("%s:%d Received channel selection request \n",__func__, __LINE__); return 0; } diff --git a/src/em/config/em_configuration.cpp b/src/em/config/em_configuration.cpp index bd723b9..489cedc 100644 --- a/src/em/config/em_configuration.cpp +++ b/src/em/config/em_configuration.cpp @@ -1011,9 +1011,7 @@ int em_configuration_t::handle_topology_notification(unsigned char *buff, unsign dm_sta_t *sta; em_client_assoc_event_t *assoc_evt_tlv; em_sta_info_t sta_info; - em_event_t ev; - em_bus_event_t *bev; - em_bus_event_type_client_assoc_params_t *raw; + em_bus_event_type_client_assoc_params_t raw; char *errors[EM_MAX_TLV_MEMBERS] = {0}; bool eligible_to_req_cap = false; @@ -1067,14 +1065,11 @@ int em_configuration_t::handle_topology_notification(unsigned char *buff, unsign // if associated for first time, orchestrate a client capability query/response if(eligible_to_req_cap == true) { - ev.type = em_event_type_bus; - bev = &ev.u.bevt; - bev->type = em_bus_event_type_sta_assoc; - raw = (em_bus_event_type_client_assoc_params_t *)bev->u.raw_buff; - memcpy(raw->dev, dev_mac, sizeof(mac_address_t)); - memcpy((unsigned char *)&raw->assoc, (unsigned char *)assoc_evt_tlv, sizeof(em_client_assoc_event_t)); - - em_cmd_exec_t::send_cmd(em_service_type_ctrl, (unsigned char *)&ev, sizeof(em_event_t)); + memcpy(raw.dev, dev_mac, sizeof(mac_address_t)); + memcpy((unsigned char *)&raw.assoc, (unsigned char *)assoc_evt_tlv, sizeof(em_client_assoc_event_t)); + + get_mgr()->io_process(em_bus_event_type_sta_assoc, (unsigned char *)&raw, sizeof(em_bus_event_type_client_assoc_params_t)); + } else { memset(&sta_info, 0, sizeof(em_sta_info_t)); memcpy(sta_info.id, assoc_evt_tlv->cli_mac_address, sizeof(mac_address_t)); @@ -2374,13 +2369,9 @@ int em_configuration_t::handle_encrypted_settings() unsigned short plain_len; unsigned short authtype; unsigned int index = 0; - m2ctrl_vapconfig *vapconfig; - em_event_t ev; - em_bus_event_t *bev; + m2ctrl_vapconfig vapconfig; plain = m_m2_encrypted_settings + AES_BLOCK_SIZE; plain_len = m_m2_encrypted_settings_len - AES_BLOCK_SIZE; - //ev = (em_event_t *)malloc(sizeof(em_event_t)); - memset(&ev,0,sizeof(em_event_t)); // first decrypt the encrypted m2 data if (em_crypto_t::platform_aes_128_cbc_decrypt(m_key_wrap_key, m_m2_encrypted_settings, plain, plain_len) != 1) { @@ -2388,14 +2379,10 @@ int em_configuration_t::handle_encrypted_settings() return 0; } - ev.type = em_event_type_bus; - bev = &ev.u.bevt; - bev->type = em_bus_event_type_m2ctrl_configuration; - vapconfig = (m2ctrl_vapconfig *)&bev->u.raw_buff; attr = (data_elem_attr_t *)plain; tmp_len = plain_len; - memcpy(vapconfig->mac, get_radio_interface_mac(), sizeof(mac_address_t)); - vapconfig->freq = get_band(); + memcpy(vapconfig.mac, get_radio_interface_mac(), sizeof(mac_address_t)); + vapconfig.freq = get_band(); while (tmp_len > 0) { @@ -2403,34 +2390,36 @@ int em_configuration_t::handle_encrypted_settings() if (id == attr_id_ssid) { memcpy(ssid, attr->val, htons(attr->len)); - memcpy(vapconfig->ssid, attr->val, htons(attr->len)); - vapconfig->enable = true; + memcpy(vapconfig.ssid, attr->val, htons(attr->len)); + vapconfig.enable = true; printf("%s:%d: ssid attrib: %s\n", __func__, __LINE__, ssid); } else if (id == attr_id_auth_type) { printf("%s:%d: auth type attrib\n", __func__, __LINE__); authtype = attr->val[0]; - vapconfig->authtype = attr->val[0]; + vapconfig.authtype = attr->val[0]; } else if (id == attr_id_encryption_type) { printf("%s:%d: encr type attrib\n", __func__, __LINE__); } else if (id == attr_id_network_key) { memcpy(pass, attr->val, htons(attr->len)); - memcpy(vapconfig->password, attr->val, htons(attr->len)); + memcpy(vapconfig.password, attr->val, htons(attr->len)); printf("%s:%d: network key attrib: %s\n", __func__, __LINE__, pass); } else if (id == attr_id_mac_address) { dm_easy_mesh_t::macbytes_to_string(attr->val, mac_str); printf("%s:%d: mac address attrib: %s\n", __func__, __LINE__, mac_str); - memcpy(vapconfig->mac, attr->val, sizeof(mac_address_t)); + memcpy(vapconfig.mac, attr->val, sizeof(mac_address_t)); } else if (id == attr_id_key_wrap_authenticator) { printf("%s:%d: key wrap auth attrib\n", __func__, __LINE__); - vapconfig->key_wrap_authenticator = attr->val[0]; + vapconfig.key_wrap_authenticator = attr->val[0]; } tmp_len -= (sizeof(data_elem_attr_t) + htons(attr->len)); attr = (data_elem_attr_t *)((unsigned char *)attr + sizeof(data_elem_attr_t) + htons(attr->len)); } - printf("%s:%d Recived new config ssid=%s mode=%d pass=%s \n", __func__, __LINE__,vapconfig->ssid,vapconfig->authtype,vapconfig->password); - em_cmd_exec_t::send_cmd(em_service_type_agent, (unsigned char *)&ev, sizeof(em_event_t)); + printf("%s:%d Recived new config ssid=%s mode=%d pass=%s \n", __func__, __LINE__,vapconfig.ssid,vapconfig.authtype,vapconfig.password); + + get_mgr()->io_process(em_bus_event_type_m2ctrl_configuration, (unsigned char *)&vapconfig, sizeof(vapconfig)); + set_state(em_state_agent_owconfig_pending); return ret; } @@ -2677,11 +2666,7 @@ int em_configuration_t::handle_autoconfig_wsc_m1(unsigned char *buff, unsigned i mac_addr_str_t mac_str; em_tlv_t *tlv; int tlv_len; - //dm_easy_mesh_t *dm; - //dm_device_t *dev; - em_event_t ev; - em_bus_event_t *bev; - em_bus_event_type_m2_tx_params_t *raw; + em_bus_event_type_m2_tx_params_t raw; em_haul_type_t haul_type[1]; //dm = get_data_model(); @@ -2725,14 +2710,11 @@ int em_configuration_t::handle_autoconfig_wsc_m1(unsigned char *buff, unsigned i return -1; } - ev.type = em_event_type_bus; - bev = &ev.u.bevt; - bev->type = em_bus_event_type_m2_tx; - raw = (em_bus_event_type_m2_tx_params_t *)bev->u.raw_buff; - memcpy(raw->al, (unsigned char *)get_peer_mac(), sizeof(mac_address_t)); - memcpy(raw->radio, get_radio_interface_mac(), sizeof(mac_address_t)); + memcpy(raw.al, (unsigned char *)get_peer_mac(), sizeof(mac_address_t)); + memcpy(raw.radio, get_radio_interface_mac(), sizeof(mac_address_t)); + + get_mgr()->io_process(em_bus_event_type_m2_tx, (unsigned char *)&raw, sizeof(em_bus_event_type_m2_tx_params_t)); - em_cmd_exec_t::send_cmd(em_service_type_ctrl, (unsigned char *)&ev, sizeof(em_event_t)); set_state(em_state_ctrl_wsc_m2_sent); return 0; @@ -2833,9 +2815,7 @@ int em_configuration_t::handle_autoconfig_renew(unsigned char *buff, unsigned in em_tlv_t *tlv; em_raw_hdr_t *hdr; char* errors[EM_MAX_TLV_MEMBERS]; - em_bus_event_t *bevt; - em_event_t evt; - em_bus_event_type_cfg_renew_params_t *raw; + em_bus_event_type_cfg_renew_params_t raw; if (em_msg_t(em_msg_type_autoconf_renew, em_profile_type_2, buff, len).validate(errors) == 0) { @@ -2846,13 +2826,10 @@ int em_configuration_t::handle_autoconfig_renew(unsigned char *buff, unsigned in hdr = (em_raw_hdr_t *)buff; - evt.type = em_event_type_bus; - bevt = &evt.u.bevt; - bevt->type = em_bus_event_type_cfg_renew; - raw = (em_bus_event_type_cfg_renew_params_t *)bevt->u.raw_buff; - memcpy(raw->radio, get_radio_interface_mac(), sizeof(mac_address_t)); - memcpy(raw->ctrl_src, hdr->src, sizeof(mac_address_t)); - em_cmd_exec_t::send_cmd(em_service_type_agent, (unsigned char *)&evt, sizeof(em_event_t)); + memcpy(raw.radio, get_radio_interface_mac(), sizeof(mac_address_t)); + memcpy(raw.ctrl_src, hdr->src, sizeof(mac_address_t)); + + get_mgr()->io_process(em_bus_event_type_cfg_renew, (unsigned char *)&raw, sizeof(em_bus_event_type_cfg_renew_params_t)); return 0; } diff --git a/src/em/em.cpp b/src/em/em.cpp index af96bb7..f517dcb 100644 --- a/src/em/em.cpp +++ b/src/em/em.cpp @@ -392,7 +392,7 @@ void em_t::proto_run() } pthread_mutex_unlock(&m_iq.lock); assert(evt->type == em_event_type_frame); - proto_process(evt->u.fevt.frame, evt->u.fevt.len); + proto_process(evt->u.fevt.frame, evt->u.fevt.frame_len); free(evt); pthread_mutex_lock(&m_iq.lock); } diff --git a/src/em/em_mgr.cpp b/src/em/em_mgr.cpp index 7f713d6..38e65a0 100644 --- a/src/em/em_mgr.cpp +++ b/src/em/em_mgr.cpp @@ -46,6 +46,65 @@ extern char *global_netid; +void em_mgr_t::io_process(em_bus_event_type_t type, char *data, unsigned int len) +{ + em_event_t *evt; + em_bus_event_t *bevt; + + evt = (em_event_t *)malloc(sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN); + evt->type = em_event_type_bus; + bevt = &evt->u.bevt; + bevt->type = type; + bevt->data_len = len; + memcpy(bevt->u.subdoc.buff, data, len); + + push_to_queue(evt); +} + +void em_mgr_t::io_process(em_bus_event_type_t type, unsigned char *data, unsigned int len) +{ + em_event_t *evt; + em_bus_event_t *bevt; + + evt = (em_event_t *)malloc(sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN); + evt->type = em_event_type_bus; + bevt = &evt->u.bevt; + bevt->type = type; + bevt->data_len = len; + memcpy(bevt->u.raw_buff, data, len); + + push_to_queue(evt); +} + +bool em_mgr_t::io_process(em_event_t *evt) +{ + em_event_t *e; + em_bus_event_t *bevt; + bool should_wait; + + bevt = &evt->u.bevt; + //em_cmd_t::dump_bus_event(bevt); + + e = (em_event_t *)malloc(sizeof(em_event_t) + EM_MAX_EVENT_DATA_LEN); + memcpy((unsigned char *)e, (unsigned char *)evt, EM_MAX_EVENT_DATA_LEN); + + push_to_queue(e); + + // check if the server should wait + should_wait = false; + + switch (evt->type) { + case em_event_type_bus: + bevt = &evt->u.bevt; + if (bevt->type != em_bus_event_type_dm_commit) { + should_wait = true; + } + break; + } + + return should_wait; +} + void em_mgr_t::proto_process(unsigned char *data, unsigned int len, em_t *al_em) { em_event_t *evt; @@ -60,7 +119,7 @@ void em_mgr_t::proto_process(unsigned char *data, unsigned int len, em_t *al_em) evt->type = em_event_type_frame; evt->u.fevt.frame = (unsigned char *)malloc(len); memcpy(evt->u.fevt.frame, data, len); - evt->u.fevt.len = len; + evt->u.fevt.frame_len = len; em->push_to_queue(evt); } diff --git a/src/em/em_net_node.cpp b/src/em/em_net_node.cpp index c3a3579..f914328 100644 --- a/src/em/em_net_node.cpp +++ b/src/em/em_net_node.cpp @@ -61,6 +61,8 @@ char *em_net_node_t::get_node_array_value(em_network_node_t *node, em_network_no memset(str, 0, sizeof(em_long_string_t)); if (node->num_children == 0) { + snprintf(str, sizeof(em_long_string_t), "[]"); + *type = em_network_node_data_type_array_str; return str; } @@ -105,8 +107,13 @@ void em_net_node_t::set_node_array_value(em_network_node_t *node, char *fmt) } tmp++; + + if (*tmp == ']') { + node->num_children = 0; + return; + } + strncpy(value, tmp, strlen(tmp) + 1); - value[strlen(value) - 2] = 0; tmp = value; remain = value; @@ -129,6 +136,9 @@ void em_net_node_t::set_node_array_value(em_network_node_t *node, char *fmt) remain = tmp + 2; } + if ((tmp = strchr(remain, ']')) != NULL) { + *tmp = 0; + } node->child[node->num_children] = (em_network_node_t *)malloc(sizeof(em_network_node_t)); memset(node->child[node->num_children], 0, sizeof(em_network_node_t)); @@ -419,8 +429,6 @@ void *em_net_node_t::network_tree_to_json(em_network_node_t *root) network_tree_node_to_json(root->child[i], obj); } - //printf("%s:%d: %s\n", __func__, __LINE__, cJSON_Print(obj)); - return obj; } @@ -491,6 +499,10 @@ em_network_node_t *em_net_node_t::get_network_tree(char *buff) em_network_node_t *root; unsigned int node_display_ctr = 0; + if ((buff == NULL) || (*buff == 0)) { + return NULL; + } + if ((root_obj = cJSON_Parse(buff)) == NULL) { return NULL; } diff --git a/src/em/steering/em_steering.cpp b/src/em/steering/em_steering.cpp index 5ffa6a5..86a092b 100644 --- a/src/em/steering/em_steering.cpp +++ b/src/em/steering/em_steering.cpp @@ -440,8 +440,6 @@ int em_steering_t::handle_client_steering_req(unsigned char *buff, unsigned int char *errors[EM_MAX_TLV_MEMBERS] = {0}; em_steering_req_t *steer_req; mac_addr_str_t mac_str; - em_event_t ev; - em_bus_event_t *bev; int tlv_len = 0; if (em_msg_t(em_msg_type_client_steering_req, em_profile_type_2, buff, len).validate(errors) == 0) { @@ -453,14 +451,10 @@ int em_steering_t::handle_client_steering_req(unsigned char *buff, unsigned int tlv_len = ntohs(tlv->len); steer_req = (em_steering_req_t *)&tlv->value; - ev.type = em_event_type_bus; - bev = &ev.u.bevt; - bev->type = em_bus_event_type_bss_tm_req; - memcpy(bev->u.raw_buff, steer_req, tlv_len); - dm_easy_mesh_t::macbytes_to_string(steer_req->sta_mac_addr, mac_str); printf("%s:%d Recived steer req for sta=%s\n", __func__, __LINE__, mac_str); - em_cmd_exec_t::send_cmd(em_service_type_agent, (unsigned char *)&ev, sizeof(em_event_t)); + + get_mgr()->io_process(em_bus_event_type_bss_tm_req, (unsigned char *)steer_req, sizeof(em_steering_req_t)); send_1905_ack_message(steer_req->sta_mac_addr); @@ -568,4 +562,4 @@ em_steering_t::em_steering_t() em_steering_t::~em_steering_t() { -} \ No newline at end of file +}