From 8185f7616268855e50d8a9d306518d790ff3a0ed Mon Sep 17 00:00:00 2001 From: "marcin.matula@cognizant.com" Date: Thu, 12 Dec 2024 16:30:32 +0100 Subject: [PATCH] RDKBWIFI-13 Using std::vector for channels in em_op_class_info_t --- inc/db_easy_mesh.h | 4 ++++ inc/em_base.h | 4 +++- src/db/db_easy_mesh.cpp | 31 +++++++++++++++++++++++++++++++ src/dm/dm_op_class.cpp | 15 +++++++++++---- src/dm/dm_op_class_list.cpp | 24 +++++++++++------------- src/em/em.cpp | 2 +- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/inc/db_easy_mesh.h b/inc/db_easy_mesh.h index c21d26c..3773c7b 100644 --- a/inc/db_easy_mesh.h +++ b/inc/db_easy_mesh.h @@ -24,6 +24,9 @@ #include "db_client.h" #include +#include +#include + class db_easy_mesh_t { public: @@ -44,6 +47,7 @@ class db_easy_mesh_t { char *get_column_format(db_fmt_t fmt, unsigned int pos); int get_strings_by_token(char *parent, int token, unsigned int argc, char *argv[]); + std::vector get_strings_by_token(char *parent, int token); int create_table(db_client_t& db_client); int load_table(db_client_t& db_client); diff --git a/inc/em_base.h b/inc/em_base.h index e969200..0208c69 100644 --- a/inc/em_base.h +++ b/inc/em_base.h @@ -24,6 +24,8 @@ #include #include "ec_base.h" +#include + #define EM_MAX_NETWORKS 5 #define EM_MAX_NET_SSIDS 4 #define EM_MAX_DEVICES 16 @@ -1944,7 +1946,7 @@ typedef struct { int tx_power; int max_tx_power; unsigned int num_channels; - unsigned int channels[EM_MAX_CHANNELS_IN_LIST]; + std::vector channels; unsigned short mins_since_cac_comp; unsigned short sec_remain_non_occ_dur; unsigned int countdown_cac_comp; diff --git a/src/db/db_easy_mesh.cpp b/src/db/db_easy_mesh.cpp index 9f06b8c..eb7500a 100644 --- a/src/db/db_easy_mesh.cpp +++ b/src/db/db_easy_mesh.cpp @@ -102,6 +102,37 @@ int db_easy_mesh_t::get_strings_by_token(char *parent, int token, unsigned int a return num; } +std::vector db_easy_mesh_t::get_strings_by_token(char *parent, int token) +{ + unsigned int num = 0, i; + em_long_string_t str_copy; + char *tmp, *orig; + + std::vector output; + + if (*parent == 0) { + return {}; + } + + snprintf(str_copy, sizeof(str_copy), "%s", parent); + tmp = str_copy; + orig = str_copy; + + while (tmp != NULL) { + if ((tmp = strchr(orig, token)) != NULL) { + *tmp = 0; + output.push_back(orig); + tmp++; num++; + orig = tmp; + } + } + + output.push_back(orig); + num++; + + return output; +} + int db_easy_mesh_t::insert_row(db_client_t& db_client, ...) { unsigned int i; diff --git a/src/dm/dm_op_class.cpp b/src/dm/dm_op_class.cpp index e81f076..cc1e800 100644 --- a/src/dm/dm_op_class.cpp +++ b/src/dm/dm_op_class.cpp @@ -146,7 +146,10 @@ bool dm_op_class_t::operator == (const dm_op_class_t& obj) } else if (this->m_op_class_info.id.type == em_op_class_type_capability) { ret += !(this->m_op_class_info.max_tx_power == obj.m_op_class_info.max_tx_power); ret += !(this->m_op_class_info.num_channels == obj.m_op_class_info.num_channels); - ret += (memcmp(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST) != 0); + bool isVecEqual = (this->m_op_class_info.channels == obj.m_op_class_info.channels); + if (!isVecEqual) { + ret += 1; + } } else if (this->m_op_class_info.id.type == em_op_class_type_cac_available) { ret += !(this->m_op_class_info.mins_since_cac_comp == obj.m_op_class_info.mins_since_cac_comp); } else if (this->m_op_class_info.id.type == em_op_class_type_cac_non_occ) { @@ -157,7 +160,10 @@ bool dm_op_class_t::operator == (const dm_op_class_t& obj) (this->m_op_class_info.id.type == em_op_class_type_anticipated) || (this->m_op_class_info.id.type == em_op_class_type_scan_param)) { ret += !(this->m_op_class_info.num_channels == obj.m_op_class_info.num_channels); - ret += (memcmp(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST) != 0); + bool isVecEqual = (this->m_op_class_info.channels == obj.m_op_class_info.channels); + if (!isVecEqual) { + ret += 1; + } } if (ret > 0) @@ -176,12 +182,13 @@ void dm_op_class_t::operator = (const dm_op_class_t& obj) this->m_op_class_info.tx_power = obj.m_op_class_info.tx_power; this->m_op_class_info.max_tx_power = obj.m_op_class_info.max_tx_power; this->m_op_class_info.num_channels = obj.m_op_class_info.num_channels; - memcpy(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST); + this->m_op_class_info.channels = obj.m_op_class_info.channels; this->m_op_class_info.mins_since_cac_comp = obj.m_op_class_info.mins_since_cac_comp; this->m_op_class_info.sec_remain_non_occ_dur = obj.m_op_class_info.sec_remain_non_occ_dur; this->m_op_class_info.countdown_cac_comp = obj.m_op_class_info.countdown_cac_comp; this->m_op_class_info.num_channels = obj.m_op_class_info.num_channels; - memcpy(this->m_op_class_info.channels, obj.m_op_class_info.channels, sizeof(unsigned int) * EM_MAX_CHANNELS_IN_LIST); + + this->m_op_class_info.channels = obj.m_op_class_info.channels; // std::vector c++ copying } int dm_op_class_t::parse_op_class_id_from_key(const char *key, em_op_class_id_t *id) diff --git a/src/dm/dm_op_class_list.cpp b/src/dm/dm_op_class_list.cpp index 90df740..6f1b397 100644 --- a/src/dm/dm_op_class_list.cpp +++ b/src/dm/dm_op_class_list.cpp @@ -39,6 +39,8 @@ #include "dm_easy_mesh.h" #include "dm_easy_mesh_ctrl.h" +#include + int dm_op_class_list_t::get_config(cJSON *obj_arr, void *parent, bool summary) { dm_op_class_t *pop_class; @@ -288,8 +290,7 @@ int dm_op_class_list_t::sync_db(db_client_t& db_client, void *ctx) em_op_class_info_t info; em_long_string_t str, id; mac_addr_str_t mac_str; - em_short_string_t ch_str[EM_MAX_CHANNELS_IN_LIST]; - char *token_parts[EM_MAX_CHANNELS_IN_LIST], *tmp; + char *tmp; unsigned int i = 0; int rc = 0; @@ -300,18 +301,15 @@ int dm_op_class_list_t::sync_db(db_client_t& db_client, void *ctx) dm_op_class_t::parse_op_class_id_from_key(id, &info.id); info.op_class = db_client.get_number(ctx, 2); info.channel = db_client.get_number(ctx, 3); - - db_client.get_string(ctx, str, 4); - for (i = 0; i < EM_MAX_CHANNELS_IN_LIST; i++) { - token_parts[i] = ch_str[i]; - } - if ((str != NULL) && (*str != 0)) { - info.num_channels = get_strings_by_token(str, ',', EM_MAX_CHANNELS_IN_LIST, token_parts); - for (i = 0; i < info.num_channels; i++) { - info.channels[i] = atoi(token_parts[i]); - } - } + db_client.get_string(ctx, str, 4); + if ((str != NULL) && (*str != 0)) { + const auto& channels = get_strings_by_token(str, ','); + info.num_channels = channels.size(); + for (i = 0; i < info.num_channels; i++) { + info.channels[i] = atoi(channels[i].c_str()); + } + } info.tx_power = db_client.get_number(ctx, 5); info.max_tx_power = db_client.get_number(ctx, 6); diff --git a/src/em/em.cpp b/src/em/em.cpp index 8ec4b69..c377ac6 100644 --- a/src/em/em.cpp +++ b/src/em/em.cpp @@ -462,7 +462,7 @@ int em_t::start_al_interface() slen = sizeof(struct sockaddr_ll); if ((sock_fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) { - printf("%s:%d: Error opening socket, err:%d\n", __func__, __LINE__, errno); + printf("%s:%d: Error opening socket, err:%d name: %s\n", __func__, __LINE__, errno, m_ruid.name); return -1; }