Skip to content
This repository was archived by the owner on Sep 7, 2020. It is now read-only.
Draft
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseClass> 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<BaseClass> 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_
Original file line number Diff line number Diff line change
Expand Up @@ -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<BaseClass> 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<uint8_t*>(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<sMacAddr*>(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<BaseClass> 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<uint8_t*>(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<uint8_t*>(m_buff_ptr__);
if (!buffPtrIncrementSafe(sizeof(uint8_t))) {
LOG(ERROR) << "buffPtrIncrementSafe(" << std::dec << sizeof(uint8_t) << ") Failed!";
return false;
}
m_client = reinterpret_cast<sClient*>(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;
}


Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions controller/src/beerocks/bml/bml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,3 +716,14 @@ int bml_client_get_client(BML_CTX ctx, const char *sta_mac, struct BML_CLIENT *c
auto pBML = static_cast<bml_internal *>(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<bml_internal *>(ctx);
return pBML->client_del_client_persistent_info(tlvf::mac_from_string(std::string(sta_mac)), client);
}
10 changes: 10 additions & 0 deletions controller/src/beerocks/bml/bml.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
110 changes: 110 additions & 0 deletions controller/src/beerocks/bml/internal/bml_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,38 @@ int bml_internal::process_cmdu_header(std::shared_ptr<beerocks_header> 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<beerocks_message::cACTION_BML_CLIENT_DEL_PERSISTENT_DB_RESPONSE>();
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());
Expand Down Expand Up @@ -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<bool> prmClientGet;
m_prmClientGet = &prmClientGet;
int iOpTimeout = RESPONSE_TIMEOUT; // Default timeout
m_client = client;

auto request =
message_com::create_vs_message<beerocks_message::cACTION_BML_CLIENT_DEL_PERSISTENT_DB_REQUEST>(
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) {
Expand Down
Loading