From 0617d63fc24ef147420de825de358cc74eceb276 Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 17:40:42 +0000 Subject: [PATCH 1/8] common: tlvf: add yaml for removal of client from persistentDB Preparation commit Currently there's only accesor or mutator fns, to communicate with a client's persistent DB. I am adding the missing delete function so the cli could execute a routine to delete a record off the persistent DB using a mac address as an indentifier. Here i add the require .YAML changes PPM-385 Signed-off-by: DanielEdriPurpl --- .../yaml/beerocks/tlvf/beerocks_message_action.yaml | 3 ++- .../tlvf/yaml/beerocks/tlvf/beerocks_message_bml.yaml | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_action.yaml b/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_action.yaml index 32be33f1f6..267252a335 100755 --- a/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_action.yaml +++ b/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_action.yaml @@ -460,5 +460,6 @@ eActionOp_BML: ACTION_BML_CLIENT_SET_CLIENT_RESPONSE: 218 ACTION_BML_CLIENT_GET_CLIENT_REQUEST: 219 ACTION_BML_CLIENT_GET_CLIENT_RESPONSE: 220 - + ACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST: 221 + ACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE: 222 ACTION_BML_ENUM_END: 225 diff --git a/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_bml.yaml b/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_bml.yaml index 85b6c05152..d66e77ce53 100755 --- a/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_bml.yaml +++ b/common/beerocks/tlvf/yaml/beerocks/tlvf/beerocks_message_bml.yaml @@ -529,3 +529,14 @@ cACTION_BML_CLIENT_GET_CLIENT_RESPONSE: _type: uint8_t _comment: # 0 - Failure, 1 - Success client: sClient + +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST: + _type: class + sta_mac: sMacAddr + +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE: + _type: class + result: + _type: uint8_t + _comment: # 0 - Failure, 1 - Success + client: sClient From aaa9fbd70204a96ddc89c099cf1125eed61409a9 Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 17:49:00 +0000 Subject: [PATCH 2/8] common: tlvf: add generated code related to persistentDB del fn Here i add the auto generated code related to the persistentDB delete method PPM-385 Signed-off-by: DanielEdriPurpl --- .../beerocks/tlvf/beerocks_message_action.h | 2 + .../beerocks/tlvf/beerocks_message_bml.h | 44 +++++ .../beerocks/tlvf/beerocks_message_bml.cpp | 150 ++++++++++++++++++ 3 files changed, 196 insertions(+) diff --git a/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_action.h b/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_action.h index a940d478a6..cd5c09a626 100644 --- a/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_action.h +++ b/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_action.h @@ -396,6 +396,8 @@ enum eActionOp_BML: uint8_t { ACTION_BML_CLIENT_SET_CLIENT_RESPONSE = 0xda, ACTION_BML_CLIENT_GET_CLIENT_REQUEST = 0xdb, ACTION_BML_CLIENT_GET_CLIENT_RESPONSE = 0xdc, + ACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST = 0xdd, + ACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE = 0xde, ACTION_BML_ENUM_END = 0xe1, }; diff --git a/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_bml.h b/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_bml.h index 588fb4b6fb..9dcc0a3515 100644 --- a/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_bml.h +++ b/common/beerocks/tlvf/AutoGenerated/include/beerocks/tlvf/beerocks_message_bml.h @@ -2354,6 +2354,50 @@ class cACTION_BML_CLIENT_GET_CLIENT_RESPONSE : public BaseClass sClient* m_client = nullptr; }; +class cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST : public BaseClass +{ + public: + cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST(uint8_t* buff, size_t buff_len, bool parse = false); + explicit cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST(std::shared_ptr base, bool parse = false); + ~cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST(); + + static eActionOp_BML get_action_op(){ + return (eActionOp_BML)(ACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST); + } + sMacAddr& sta_mac(); + void class_swap() override; + bool finalize() override; + static size_t get_initial_size(); + + private: + bool init(); + eActionOp_BML* m_action_op = nullptr; + sMacAddr* m_sta_mac = nullptr; +}; + +class cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE : public BaseClass +{ + public: + cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE(uint8_t* buff, size_t buff_len, bool parse = false); + explicit cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE(std::shared_ptr base, bool parse = false); + ~cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE(); + + static eActionOp_BML get_action_op(){ + return (eActionOp_BML)(ACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE); + } + uint8_t& result(); + sClient& client(); + void class_swap() override; + bool finalize() override; + static size_t get_initial_size(); + + private: + bool init(); + eActionOp_BML* m_action_op = nullptr; + uint8_t* m_result = nullptr; + sClient* m_client = nullptr; +}; + }; // close namespace: beerocks_message #endif //_BEEROCKS/TLVF_BEEROCKS_MESSAGE_BML_H_ diff --git a/common/beerocks/tlvf/AutoGenerated/src/beerocks/tlvf/beerocks_message_bml.cpp b/common/beerocks/tlvf/AutoGenerated/src/beerocks/tlvf/beerocks_message_bml.cpp index 9f8d17c275..a05b2a208f 100644 --- a/common/beerocks/tlvf/AutoGenerated/src/beerocks/tlvf/beerocks_message_bml.cpp +++ b/common/beerocks/tlvf/AutoGenerated/src/beerocks/tlvf/beerocks_message_bml.cpp @@ -8021,4 +8021,154 @@ bool cACTION_BML_CLIENT_GET_CLIENT_RESPONSE::init() return true; } +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST(uint8_t* buff, size_t buff_len, bool parse) : + BaseClass(buff, buff_len, parse) { + m_init_succeeded = init(); +} +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST(std::shared_ptr base, bool parse) : +BaseClass(base->getBuffPtr(), base->getBuffRemainingBytes(), parse){ + m_init_succeeded = init(); +} +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::~cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST() { +} +sMacAddr& cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::sta_mac() { + return (sMacAddr&)(*m_sta_mac); +} + +void cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::class_swap() +{ + tlvf_swap(8*sizeof(eActionOp_BML), reinterpret_cast(m_action_op)); + m_sta_mac->struct_swap(); +} + +bool cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::finalize() +{ + if (m_parse__) { + TLVF_LOG(DEBUG) << "finalize() called but m_parse__ is set"; + return true; + } + if (m_finalized__) { + TLVF_LOG(DEBUG) << "finalize() called for already finalized class"; + return true; + } + if (!isPostInitSucceeded()) { + TLVF_LOG(ERROR) << "post init check failed"; + return false; + } + if (m_inner__) { + if (!m_inner__->finalize()) { + TLVF_LOG(ERROR) << "m_inner__->finalize() failed"; + return false; + } + auto tailroom = m_inner__->getMessageBuffLength() - m_inner__->getMessageLength(); + m_buff_ptr__ -= tailroom; + } + class_swap(); + m_finalized__ = true; + return true; +} + +size_t cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::get_initial_size() +{ + size_t class_size = 0; + class_size += sizeof(sMacAddr); // sta_mac + return class_size; +} + +bool cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST::init() +{ + if (getBuffRemainingBytes() < get_initial_size()) { + TLVF_LOG(ERROR) << "Not enough available space on buffer. Class init failed"; + return false; + } + m_sta_mac = reinterpret_cast(m_buff_ptr__); + if (!buffPtrIncrementSafe(sizeof(sMacAddr))) { + LOG(ERROR) << "buffPtrIncrementSafe(" << std::dec << sizeof(sMacAddr) << ") Failed!"; + return false; + } + if (!m_parse__) { m_sta_mac->struct_init(); } + if (m_parse__) { class_swap(); } + return true; +} + +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE(uint8_t* buff, size_t buff_len, bool parse) : + BaseClass(buff, buff_len, parse) { + m_init_succeeded = init(); +} +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE(std::shared_ptr base, bool parse) : +BaseClass(base->getBuffPtr(), base->getBuffRemainingBytes(), parse){ + m_init_succeeded = init(); +} +cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::~cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE() { +} +uint8_t& cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::result() { + return (uint8_t&)(*m_result); +} + +sClient& cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::client() { + return (sClient&)(*m_client); +} + +void cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::class_swap() +{ + tlvf_swap(8*sizeof(eActionOp_BML), reinterpret_cast(m_action_op)); + m_client->struct_swap(); +} + +bool cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::finalize() +{ + if (m_parse__) { + TLVF_LOG(DEBUG) << "finalize() called but m_parse__ is set"; + return true; + } + if (m_finalized__) { + TLVF_LOG(DEBUG) << "finalize() called for already finalized class"; + return true; + } + if (!isPostInitSucceeded()) { + TLVF_LOG(ERROR) << "post init check failed"; + return false; + } + if (m_inner__) { + if (!m_inner__->finalize()) { + TLVF_LOG(ERROR) << "m_inner__->finalize() failed"; + return false; + } + auto tailroom = m_inner__->getMessageBuffLength() - m_inner__->getMessageLength(); + m_buff_ptr__ -= tailroom; + } + class_swap(); + m_finalized__ = true; + return true; +} + +size_t cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::get_initial_size() +{ + size_t class_size = 0; + class_size += sizeof(uint8_t); // result + class_size += sizeof(sClient); // client + return class_size; +} + +bool cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE::init() +{ + if (getBuffRemainingBytes() < get_initial_size()) { + TLVF_LOG(ERROR) << "Not enough available space on buffer. Class init failed"; + return false; + } + m_result = reinterpret_cast(m_buff_ptr__); + if (!buffPtrIncrementSafe(sizeof(uint8_t))) { + LOG(ERROR) << "buffPtrIncrementSafe(" << std::dec << sizeof(uint8_t) << ") Failed!"; + return false; + } + m_client = reinterpret_cast(m_buff_ptr__); + if (!buffPtrIncrementSafe(sizeof(sClient))) { + LOG(ERROR) << "buffPtrIncrementSafe(" << std::dec << sizeof(sClient) << ") Failed!"; + return false; + } + if (!m_parse__) { m_client->struct_init(); } + if (m_parse__) { class_swap(); } + return true; +} + From 759bcc1ff4364ebfa78adadf638b335ad2486a7c Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 17:54:55 +0000 Subject: [PATCH 3/8] controller: bml: cli: add BML/CLI code to persistentDB erase fn Here i add the required changes to BML/CLI to be used with the del function from persistentDB PPM-385 Signed-off-by: DanielEdriPurpl --- controller/src/beerocks/bml/bml.h | 10 ++++++++++ controller/src/beerocks/cli/beerocks_cli_bml.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/controller/src/beerocks/bml/bml.h b/controller/src/beerocks/bml/bml.h index c17056b790..d78bf98b8b 100644 --- a/controller/src/beerocks/bml/bml.h +++ b/controller/src/beerocks/bml/bml.h @@ -657,6 +657,16 @@ int bml_client_set_client(BML_CTX ctx, const char *sta_mac, */ int bml_client_get_client(BML_CTX ctx, const char *sta_mac, struct BML_CLIENT *client); +/** + * Delete client persistent DB info. + * + * @param [in] ctx BML Context. + * @param [in] sta_mac MAC address of a station. + * @param [in] client Client information. + * @return BML_RET_OK on success. + */ +int bml_client_del_persistent_db(BML_CTX ctx, const char *sta_mac, struct BML_CLIENT *client); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/controller/src/beerocks/cli/beerocks_cli_bml.h b/controller/src/beerocks/cli/beerocks_cli_bml.h index a3055e77db..6a58d0b0df 100644 --- a/controller/src/beerocks/cli/beerocks_cli_bml.h +++ b/controller/src/beerocks/cli/beerocks_cli_bml.h @@ -151,6 +151,7 @@ class cli_bml : public cli { int client_get_client_list_caller(int numOfArgs); int client_set_client_caller(int numOfArgs); int client_get_client_caller(int numOfArgs); + int client_del_persistent_info_caller(int numOfArgs); // Functions int onboard_status(); int ping(); @@ -218,6 +219,7 @@ class cli_bml : public cli { int client_set_client(const std::string &sta_mac, int8_t selected_bands, int8_t stay_on_initial_radio); int client_get_client(const std::string &sta_mac); + int client_del_persistent_info(const std::string &sta_mac); template const std::string string_from_int_array(T *arr, size_t arr_max_size); // Variable std::string beerocks_conf_path; From 4c5234158ab5b22f70bd8687a948dc937e04466c Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 17:57:47 +0000 Subject: [PATCH 4/8] controller: bml: cli: use BML/CLI code to persistentDB erase fn Here i use the code of CLI/BML i declared in the previous commit PPM-385 Signed-off-by: DanielEdriPurpl --- controller/src/beerocks/bml/bml.cpp | 11 ++++++ .../src/beerocks/cli/beerocks_cli_bml.cpp | 39 +++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/controller/src/beerocks/bml/bml.cpp b/controller/src/beerocks/bml/bml.cpp index 59b5755df8..6db4d064d3 100644 --- a/controller/src/beerocks/bml/bml.cpp +++ b/controller/src/beerocks/bml/bml.cpp @@ -716,3 +716,14 @@ int bml_client_get_client(BML_CTX ctx, const char *sta_mac, struct BML_CLIENT *c auto pBML = static_cast(ctx); return pBML->client_get_client(tlvf::mac_from_string(std::string(sta_mac)), client); } + +int bml_client_del_persistent_db(BML_CTX ctx, const char *sta_mac, struct BML_CLIENT *client) +{ + // Validate input parameters + if (!ctx || !sta_mac || !client) { + return (-BML_RET_INVALID_ARGS); + } + + auto pBML = static_cast(ctx); + return pBML->client_del_client_persistent_info(tlvf::mac_from_string(std::string(sta_mac)), client); +} diff --git a/controller/src/beerocks/cli/beerocks_cli_bml.cpp b/controller/src/beerocks/cli/beerocks_cli_bml.cpp index 8b9f517676..5ee23eb58b 100644 --- a/controller/src/beerocks/cli/beerocks_cli_bml.cpp +++ b/controller/src/beerocks/cli/beerocks_cli_bml.cpp @@ -567,6 +567,9 @@ void cli_bml::setFunctionsMapAndArray() insertCommandToMap("bml_client_get_client", "", "Get client with the given STA MAC.", static_cast(&cli_bml::client_get_client_caller), 1, 1, STRING_ARG); + insertCommandToMap("bml_client_del_persistent_info", "", "Delete client persistent info with the given STA MAC.", + static_cast(&cli_bml::client_del_persistent_info_caller), 1, 1, + STRING_ARG); //bool insertCommandToMap(std::string command, std::string help_args, std::string help, pFunction funcPtr, uint8_t minNumOfArgs, uint8_t maxNumOfArgs, } @@ -1380,6 +1383,20 @@ int cli_bml::client_get_client_caller(int numOfArgs) return -1; } +/** + * Caller function for client_del_persistent_info_caller. + * + * @param [in] numOfArgs Number of received arguments + * @return 0 on success. + */ +int cli_bml::client_del_persistent_info_caller(int numOfArgs) +{ + if (numOfArgs == 1) { + return client_del_persistent_info(args.stringArgs[0]); + } + return -1; +} + // // Functions // @@ -2302,6 +2319,28 @@ int cli_bml::client_get_client(const std::string &sta_mac) return 0; } +/** + * get specific client according to MAC. + * + * @param [in] sta_mac MAC address of requested client + * + * @return 0 on success. + */ +int cli_bml::client_del_persistent_info(const std::string &sta_mac) +{ + BML_CLIENT client; + int ret = bml_client_del_persistent_db(ctx, sta_mac.c_str(), &client); + + if (ret == BML_RET_OK) { + std::cout << "the designated client records will be removed the persistent DB" << std::endl; + std::cout << "client: " << tlvf::mac_to_string(client.sta_mac) << std::endl; + } + + printBmlReturnVals("bml_client_del_persistent_info", ret); + + return 0; +} + template const std::string cli_bml::string_from_int_array(T *arr, size_t arr_max_size) { std::stringstream ss; From baee12761d8cdec8085bb9c555d641a60bfffa23 Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 18:02:10 +0000 Subject: [PATCH 5/8] controller: bml: internal: add impl to persistentDB removal fn Here i add the required implementation to the bml internal for the introduction of a new method for persistentDB removal PPM-385 Signed-off-by: DanielEdriPurpl --- controller/src/beerocks/bml/internal/bml_internal.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/controller/src/beerocks/bml/internal/bml_internal.h b/controller/src/beerocks/bml/internal/bml_internal.h index 16945c81c4..6691d9f25a 100644 --- a/controller/src/beerocks/bml/internal/bml_internal.h +++ b/controller/src/beerocks/bml/internal/bml_internal.h @@ -288,6 +288,16 @@ class bml_internal : public beerocks::socket_thread { */ int client_get_client(const sMacAddr &sta_mac, BML_CLIENT *client); + /** + * Delete client persistent DB info. + * + * @param [in] sta_mac MAC address of a station. + * @param [in] client Client information. + * @return BML_RET_OK on success. + */ + int client_del_client_persistent_info(const sMacAddr &sta_mac, BML_CLIENT *client); + + /* * Public static methods: */ From 130b415fa4ccb0b0308b7b70b5f542e06b5db18c Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 18:03:28 +0000 Subject: [PATCH 6/8] controller: bml: internal: use impl to persistentDB removal fn Here i used the impl i've added in the previous commit, to support the new delete persistentDB records via cli PPM-385 Signed-off-by: DanielEdriPurpl --- .../beerocks/bml/internal/bml_internal.cpp | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/controller/src/beerocks/bml/internal/bml_internal.cpp b/controller/src/beerocks/bml/internal/bml_internal.cpp index afc7cd712e..3781f6bcf7 100644 --- a/controller/src/beerocks/bml/internal/bml_internal.cpp +++ b/controller/src/beerocks/bml/internal/bml_internal.cpp @@ -1248,6 +1248,38 @@ int bml_internal::process_cmdu_header(std::shared_ptr beerocks_ //Resolve promise to "true" m_prmClientGet->set_value(true); } break; + case beerocks_message::ACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE: { + LOG(DEBUG) << "ACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE received"; + + if (!m_prmClientGet) { + LOG(WARNING) << "Received ACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE response, " + << "but no one is waiting..."; + break; + } + + auto response = + beerocks_header + ->addClass(); + if (!response) { + LOG(ERROR) << "addClass ACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE failed"; + return (-BML_RET_OP_FAILED); + } + + if (response->result() != 0) { + LOG(ERROR) << "cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE failed with error: " << response->result(); + m_prmClientGet->set_value(false); + break; + } + + if (!m_client) { + LOG(ERROR) << "The pointer to the user client data is null!"; + m_prmClientGet->set_value(false); + break; + } + + //Resolve promise to "true" + m_prmClientGet->set_value(true); + } break; default: { LOG(WARNING) << "unhandled header BML action type 0x" << std::hex << int(beerocks_header->action_op()); @@ -2180,6 +2212,84 @@ int bml_internal::register_nw_map_update_cb(BML_NW_MAP_QUERY_CB pCB) return (BML_RET_OK); } +int bml_internal::client_del_client_persistent_info(const sMacAddr &sta_mac, BML_CLIENT *client) +{ + LOG(DEBUG) << "client_del_client_persistent_info"; + + // If the socket is not valid, attempt to re-establish the connection + if (!m_sockMaster) { + int iRet = connect_to_master(); + if (iRet != BML_RET_OK) { + LOG(ERROR) << " Unable to create context, connect_to_master failed!"; + return iRet; + } + } + + // Initialize the promise for receiving the response + beerocks::promise prmClientGet; + m_prmClientGet = &prmClientGet; + int iOpTimeout = RESPONSE_TIMEOUT; // Default timeout + m_client = client; + + auto request = + message_com::create_vs_message( + cmdu_tx); + + if (!request) { + LOG(ERROR) << "Failed building cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST message!"; + return (-BML_RET_OP_FAILED); + } + + request->sta_mac() = sta_mac; + + // Build and send the message + if (!message_com::send_cmdu(m_sockMaster, cmdu_tx)) { + LOG(ERROR) << "Failed sending param get message!"; + m_prmClientGet = nullptr; + m_client = nullptr; + return (-BML_RET_OP_FAILED); + } + + LOG(DEBUG) << "cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST sent"; + + int iRet = BML_RET_OK; + + if (!m_prmClientGet->wait_for(iOpTimeout)) { + LOG(WARNING) << "Timeout while waiting for client response.."; + iRet = -BML_RET_TIMEOUT; + } + + // Clear the get client members + m_client = nullptr; + + // Clear the promise holder + m_prmClientGet = nullptr; + + if (iRet != BML_RET_OK) { + LOG(ERROR) << "delete client request returned" + " with error code:" << iRet; + return (iRet); + } + + if (!prmClientGet.get_value()) { + LOG(ERROR) << "Get client request failed"; + return (-BML_RET_OP_FAILED); + } + /* + else if (prmClientGet.get_value() == 2) { + LOG(ERROR) << "delete client request returned" + << " with an error code: ("<< iRet << + ") sta_mac is not found"; + } + else if (prmClientGet.get_value() == 1){ + LOG(WARNING) << "Delete client persistent DB" + << " info has completed succesfully"; + } + */ + + return BML_RET_OK; +} + int bml_internal::device_oper_radios_query(BML_DEVICE_DATA *device_data) { if (!device_data) { From 70e1bb618104cfc31acd5580a3e500b0f26f8bfe Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 18:05:19 +0000 Subject: [PATCH 7/8] controller: master: add db support for persistentdb removal Here i add the missing implementation for the removal function off persistentDB PPM-385 Signed-off-by: DanielEdriPurpl --- controller/src/beerocks/master/db/db.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/controller/src/beerocks/master/db/db.h b/controller/src/beerocks/master/db/db.h index ddf9f8cfd3..fc72e7340d 100644 --- a/controller/src/beerocks/master/db/db.h +++ b/controller/src/beerocks/master/db/db.h @@ -787,6 +787,13 @@ class db { */ std::deque get_clients_with_persistent_data_configured(); + /** + * @brief Del the client presistent data (is used with CLI) + * + * @return true on success, otherwise if client doesn't exist return false and prompt an error + */ + bool del_clients_persistent_data(const sMacAddr& mac); + // // CLI // From 27e6bbffb20cafe3a728fd4e6181be56fcd4dd2d Mon Sep 17 00:00:00 2001 From: DanielEdriPurpl Date: Sat, 15 Aug 2020 18:09:58 +0000 Subject: [PATCH 8/8] controller: master: db: son: removal of persistentDB records Here i use the impl introducted in the previous commit, and adds the support for the son_management to be used with the new delete fn of persistentDB PPM-385 Signed-off-by: DanielEdriPurpl --- controller/src/beerocks/master/db/db.cpp | 25 +++++++++++ .../src/beerocks/master/son_management.cpp | 43 +++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/controller/src/beerocks/master/db/db.cpp b/controller/src/beerocks/master/db/db.cpp index 2d94bfbd54..c415e6d252 100644 --- a/controller/src/beerocks/master/db/db.cpp +++ b/controller/src/beerocks/master/db/db.cpp @@ -3002,6 +3002,31 @@ std::deque db::get_clients_with_persistent_data_configured() return configured_clients; } +bool db::del_clients_persistent_data(const sMacAddr& mac) +{ + if (get_node_verify_type(mac, beerocks::TYPE_CLIENT)) { + LOG(ERROR) << "client node not found for mac " << mac; + return false; + } + + // if persistent db is enabled + if (config.persistent_db) { + auto db_entry = client_db_entry_from_mac(mac); + if (!bpl::db_has_entry(type_to_string(beerocks::eType::TYPE_CLIENT), db_entry)) { + LOG(DEBUG) << "client entry does not exist in persistent-db for " << db_entry; + return true; + } + + LOG(DEBUG) << "removing client entry " << db_entry << " from persistent db"; + if (!remove_client_entry_and_update_counter(db_entry)) { + LOG(ERROR) << "failed to remove client entry " << db_entry; + return false; + } + } + + return true; +} + // // CLI // diff --git a/controller/src/beerocks/master/son_management.cpp b/controller/src/beerocks/master/son_management.cpp index 6f174a8014..4d6509e5d5 100644 --- a/controller/src/beerocks/master/son_management.cpp +++ b/controller/src/beerocks/master/son_management.cpp @@ -2259,6 +2259,49 @@ void son_management::handle_bml_message(Socket *sd, message_com::send_cmdu(sd, cmdu_tx); break; } + case beerocks_message::ACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST: { + LOG(TRACE) << "ACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST"; + + auto request = + beerocks_header->addClass(); + if (!request) { + LOG(ERROR) << "addClass ACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST failed"; + break; + } + + auto response = message_com::create_vs_message< + beerocks_message::cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE>(cmdu_tx); + if (!response) { + LOG(ERROR) << "Failed building message " + "cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE !"; + break; + } + + auto client_mac = request->sta_mac(); + if (!database.has_node(client_mac)) { + LOG(DEBUG) << "Requested client " << client_mac << " is not listed in the DB"; + response->result() = 1; //Fail. + message_com::send_cmdu(sd, cmdu_tx); + break; + } + + // A configured client must have a valid timestamp configured + auto client_timestamp = database.get_client_parameters_last_edit(client_mac); + if (client_timestamp == std::chrono::steady_clock::time_point::min()) { + LOG(DEBUG) << "Requested client " << client_mac + << " doesn't have a valid timestamp listed in the DB"; + response->result() = 1; //Fail. + message_com::send_cmdu(sd, cmdu_tx); + break; + } + + // Client mac + response->client().sta_mac = client_mac; + response->result() = 0; //Success. + + message_com::send_cmdu(sd, cmdu_tx); + break; + } default: { LOG(ERROR) << "Unsupported BML action_op:" << int(beerocks_header->action_op()); break;