From 8d0af578b99c20a5a59b71e639eb5dd7f5d180c6 Mon Sep 17 00:00:00 2001 From: jeosif Date: Wed, 16 Nov 2022 09:59:48 +0800 Subject: [PATCH 1/2] get brmac if reinit Signed-off-by: jeosif Change-Id: I532b0e50138e7565a21c2aa064b62617c0ee30fb --- .../include/lnn_network_manager.h | 10 +-- .../include/lnn_physical_subnet_manager.h | 10 +-- .../net_buscenter/src/lnn_bt_network_impl.c | 87 ++++++++++++++----- .../net_buscenter/src/lnn_ip_network_impl.c | 36 ++++---- .../net_buscenter/src/lnn_network_manager.c | 22 ++--- .../src/lnn_physical_subnet_manager.c | 20 ++--- .../monitor/include/lnn_event_monitor.h | 1 + 7 files changed, 116 insertions(+), 70 deletions(-) diff --git a/core/bus_center/lnn/net_buscenter/include/lnn_network_manager.h b/core/bus_center/lnn/net_buscenter/include/lnn_network_manager.h index a2270ed630..fb3578fa4a 100644 --- a/core/bus_center/lnn/net_buscenter/include/lnn_network_manager.h +++ b/core/bus_center/lnn/net_buscenter/include/lnn_network_manager.h @@ -63,11 +63,11 @@ typedef enum { } ListenerMode; typedef struct LnnProtocolManager { - int32_t (*Init)(struct LnnProtocolManager *self); - void (*Deinit)(struct LnnProtocolManager *self); - int32_t (*Enable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); - int32_t (*Disable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); - ListenerModule (*GetListenerModule)(ListenerMode mode); + int32_t (*init)(struct LnnProtocolManager *self); + void (*deinit)(struct LnnProtocolManager *self); + int32_t (*enable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); + int32_t (*disable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); + ListenerModule (*getListenerModule)(ListenerMode mode); ProtocolType id; LnnNetIfType supportedNetif; uint16_t pri; diff --git a/core/bus_center/lnn/net_buscenter/include/lnn_physical_subnet_manager.h b/core/bus_center/lnn/net_buscenter/include/lnn_physical_subnet_manager.h index 9478e9f4aa..d048289257 100644 --- a/core/bus_center/lnn/net_buscenter/include/lnn_physical_subnet_manager.h +++ b/core/bus_center/lnn/net_buscenter/include/lnn_physical_subnet_manager.h @@ -29,8 +29,8 @@ extern "C" { typedef enum { LNN_SUBNET_IDLE, // can be enable LNN_SUBNET_RUNNING, - LNN_SUBNET_SHUTDOWN, // will not be auto Enable - LNN_SUBNET_RESETTING, // Will be auto Enable in high pri + LNN_SUBNET_SHUTDOWN, // will not be auto enable + LNN_SUBNET_RESETTING, // Will be auto enable in high pri LNN_SUBNET_STATUS_MAX } LnnPhysicalSubnetStatus; @@ -38,9 +38,9 @@ typedef struct LnnPhysicalSubnet { char ifName[NET_IF_NAME_LEN]; const LnnProtocolManager *protocol; LnnPhysicalSubnetStatus status; - void (*Destroy)(struct LnnPhysicalSubnet *); - void (*OnNetifStatusChanged)(struct LnnPhysicalSubnet *); - void (*OnSoftbusNetworkDisconnected)(struct LnnPhysicalSubnet *); + void (*destroy)(struct LnnPhysicalSubnet *); + void (*onNetifStatusChanged)(struct LnnPhysicalSubnet *); + void (*onSoftbusNetworkDisconnected)(struct LnnPhysicalSubnet *); } LnnPhysicalSubnet; typedef int16_t PhysicalSubnetId; diff --git a/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c b/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c index 39360df2b9..fafde15295 100644 --- a/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c +++ b/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c @@ -53,33 +53,38 @@ static void TransactBtSubnetState(LnnPhysicalSubnet *subnet, BtSubnetManagerEven lastStatus, subnet->status); } -static int32_t EnableBrSubnet(LnnPhysicalSubnet *subnet) +static int32_t GetAvailableBtMac(char *macStr, uint32_t len) { int32_t ret; SoftBusBtAddr mac; - char macStr[BT_MAC_LEN] = {0}; - if (subnet->status == LNN_SUBNET_RUNNING) { - return SOFTBUS_OK; - } ret = SoftBusGetBtMacAddr(&mac); if (ret != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get bt mac addr fail"); return ret; } - ret = ConvertBtMacToStr(macStr, sizeof(macStr), mac.addr, sizeof(mac.addr)); + ret = ConvertBtMacToStr(macStr, len, mac.addr, sizeof(mac.addr)); if (ret != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "convert bt mac to str fail"); return ret; } - ret = LnnSetLocalStrInfo(STRING_KEY_BT_MAC, macStr); - if (ret != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "set bt mac to local ledger fail"); - return ret; - } return SOFTBUS_OK; } +static int32_t EnableBrSubnet(LnnPhysicalSubnet *subnet) +{ + char macStr[BT_MAC_LEN] = {0}; + + if (subnet->status == LNN_SUBNET_RUNNING) { + return SOFTBUS_OK; + } + if (GetAvailableBtMac(macStr, sizeof(macStr)) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get available bt mac fail"); + return SOFTBUS_ERR; + } + return LnnSetLocalStrInfo(STRING_KEY_BT_MAC, macStr); +} + static int32_t EnableBleSubnet(LnnPhysicalSubnet *subnet) { (void)subnet; @@ -137,6 +142,46 @@ static void DestroyBtSubnetManager(LnnPhysicalSubnet *subnet) SoftBusFree(subnet); } +static BtSubnetManagerEvent GetBtRegistEvent(void) +{ + char macStr[BT_MAC_LEN] = {0}; + + if (!SoftBusGetBtState()) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "bluetooth is not enabled yet"); + return BT_SUBNET_MANAGER_EVENT_MAX; + } + return GetAvailableBtMac(macStr, sizeof(macStr)) == SOFTBUS_OK ? + BT_SUBNET_MANAGER_EVENT_IF_READY : BT_SUBNET_MANAGER_EVENT_IF_DOWN; +} + +static void OnBtNetifStatusChanged(LnnPhysicalSubnet *subnet) +{ + /* Only used for initialization process to obtain bt subnet status */ + if (subnet->status == LNN_SUBNET_RUNNING) { + return; + } + BtSubnetManagerEvent event = GetBtRegistEvent(); + if (event != BT_SUBNET_MANAGER_EVENT_IF_READY) { + return; + } + + int32_t ret; + LnnNetIfType type; + LnnGetNetIfTypeByName(subnet->ifName, &type); + switch (type) { + case LNN_NETIF_TYPE_BR: + ret = EnableBrSubnet(subnet); + break; + case LNN_NETIF_TYPE_BLE: + ret = EnableBleSubnet(subnet); + break; + default: + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "discard unexpected type %d", type); + return; + } + TransactBtSubnetState(subnet, event, (ret == SOFTBUS_OK)); +} + static LnnPhysicalSubnet *CreateBtSubnetManager(struct LnnProtocolManager *self, const char *ifName) { LnnNetIfType type; @@ -148,11 +193,11 @@ static LnnPhysicalSubnet *CreateBtSubnetManager(struct LnnProtocolManager *self, } do { - subnet->Destroy = DestroyBtSubnetManager; + subnet->destroy = DestroyBtSubnetManager; subnet->protocol = self; subnet->status = LNN_SUBNET_IDLE; - subnet->OnNetifStatusChanged = NULL; - subnet->OnSoftbusNetworkDisconnected = NULL; + subnet->onNetifStatusChanged = OnBtNetifStatusChanged; + subnet->onSoftbusNetworkDisconnected = NULL; int32_t ret = strcpy_s(subnet->ifName, sizeof(subnet->ifName), ifName); if (ret != EOK) { @@ -162,7 +207,7 @@ static LnnPhysicalSubnet *CreateBtSubnetManager(struct LnnProtocolManager *self, return subnet; } while (false); - subnet->Destroy(subnet); + subnet->destroy(subnet); return NULL; } @@ -288,7 +333,7 @@ int32_t LnnEnableBtProtocol(struct LnnProtocolManager *self, LnnNetIfMgr *netifM int ret = LnnRegistPhysicalSubnet(manager); if (ret != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:regist subnet manager failed! ret=%d", __func__, ret); - manager->Destroy(manager); + manager->destroy(manager); return ret; } return SOFTBUS_OK; @@ -312,11 +357,11 @@ static LnnProtocolManager g_btProtocol = { .id = LNN_PROTOCOL_BR | LNN_PROTOCOL_BLE, .pri = LNN_BT_PROTOCOL_PRI, .supportedNetif = LNN_NETIF_TYPE_BR | LNN_NETIF_TYPE_BLE, - .Init = LnnInitBtProtocol, - .Deinit = LnnDeinitBtNetwork, - .Enable = LnnEnableBtProtocol, - .Disable = NULL, - .GetListenerModule = LnnGetBtListenerModule, + .init = LnnInitBtProtocol, + .deinit = LnnDeinitBtNetwork, + .enable = LnnEnableBtProtocol, + .disable = NULL, + .getListenerModule = LnnGetBtListenerModule, }; int32_t RegistBtProtocolManager(void) diff --git a/core/bus_center/lnn/net_buscenter/src/lnn_ip_network_impl.c b/core/bus_center/lnn/net_buscenter/src/lnn_ip_network_impl.c index c5c55b6ebd..46221bc493 100644 --- a/core/bus_center/lnn/net_buscenter/src/lnn_ip_network_impl.c +++ b/core/bus_center/lnn/net_buscenter/src/lnn_ip_network_impl.c @@ -295,7 +295,7 @@ static int32_t EnableIpSubnet(LnnPhysicalSubnet *subnet) } if (RequestMainPort(subnet->ifName, address)) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "request main port failed!ifName=%s", subnet->ifName); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "request main port failed! ifName=%s", subnet->ifName); return SOFTBUS_ERR; } @@ -371,7 +371,7 @@ static void TransactIpSubnetState(LnnPhysicalSubnet *subnet, IpSubnetManagerEven subnet->protocol->id, subnet->status); } -static IpSubnetManagerEvent GetEventInOther(LnnPhysicalSubnet *subnet) +static IpSubnetManagerEvent GetIpEventInOther(LnnPhysicalSubnet *subnet) { char currentIfAddress[IP_LEN] = {0}; int32_t ret = GetAvailableIpAddr(subnet->ifName, currentIfAddress, sizeof(currentIfAddress)); @@ -382,7 +382,7 @@ static IpSubnetManagerEvent GetEventInOther(LnnPhysicalSubnet *subnet) } } -static IpSubnetManagerEvent GetEventInRunning(LnnPhysicalSubnet *subnet) +static IpSubnetManagerEvent GetIpEventInRunning(LnnPhysicalSubnet *subnet) { char currentIfAddress[IP_LEN] = {0}; int32_t ret = GetAvailableIpAddr(subnet->ifName, currentIfAddress, sizeof(currentIfAddress)); @@ -416,14 +416,14 @@ static void OnSoftbusIpNetworkDisconnected(LnnPhysicalSubnet *subnet) } } -static void OnNetifStatusChanged(LnnPhysicalSubnet *subnet) +static void OnIpNetifStatusChanged(LnnPhysicalSubnet *subnet) { IpSubnetManagerEvent event = SUBNET_MANAGER_EVENT_MAX; if (subnet->status == LNN_SUBNET_RUNNING) { - event = GetEventInRunning(subnet); + event = GetIpEventInRunning(subnet); } else { - event = GetEventInOther(subnet); + event = GetIpEventInOther(subnet); } int32_t ret = SOFTBUS_ERR; @@ -458,21 +458,21 @@ static LnnPhysicalSubnet *CreateIpSubnetManager(const struct LnnProtocolManager } do { - subnet->Destroy = DestroyIpSubnetManager; + subnet->destroy = DestroyIpSubnetManager; subnet->protocol = self; subnet->status = LNN_SUBNET_IDLE; - subnet->OnNetifStatusChanged = OnNetifStatusChanged; - subnet->OnSoftbusNetworkDisconnected = OnSoftbusIpNetworkDisconnected; + subnet->onNetifStatusChanged = OnIpNetifStatusChanged; + subnet->onSoftbusNetworkDisconnected = OnSoftbusIpNetworkDisconnected; int32_t ret = strcpy_s(subnet->ifName, sizeof(subnet->ifName), ifName); if (ret != EOK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:copy ifName failed!ret=%d", __func__, ret); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:copy ifName failed! ret=%d", __func__, ret); break; } return subnet; } while (false); - subnet->Destroy((LnnPhysicalSubnet *)subnet); + subnet->destroy((LnnPhysicalSubnet *)subnet); return NULL; } @@ -548,8 +548,8 @@ int32_t LnnEnableIpProtocol(struct LnnProtocolManager *self, LnnNetIfMgr *netifM int ret = LnnRegistPhysicalSubnet(manager); if (ret != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:regist subnet manager failed!ret=%d", __func__, ret); - manager->Destroy(manager); + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:regist subnet manager failed! ret=%d", __func__, ret); + manager->destroy(manager); return ret; } return SOFTBUS_OK; @@ -579,11 +579,11 @@ static LnnProtocolManager g_ipProtocol = { .id = LNN_PROTOCOL_IP, .pri = 10, .supportedNetif = LNN_NETIF_TYPE_ETH | LNN_NETIF_TYPE_WLAN, - .Init = LnnInitIpProtocol, - .Deinit = LnnDeinitIpNetwork, - .Enable = LnnEnableIpProtocol, - .Disable = NULL, - .GetListenerModule = LnnGetIpListenerModule + .init = LnnInitIpProtocol, + .deinit = LnnDeinitIpNetwork, + .enable = LnnEnableIpProtocol, + .disable = NULL, + .getListenerModule = LnnGetIpListenerModule }; int32_t RegistIPProtocolManager(void) diff --git a/core/bus_center/lnn/net_buscenter/src/lnn_network_manager.c b/core/bus_center/lnn/net_buscenter/src/lnn_network_manager.c index e6de754b36..9196cf8b2e 100644 --- a/core/bus_center/lnn/net_buscenter/src/lnn_network_manager.c +++ b/core/bus_center/lnn/net_buscenter/src/lnn_network_manager.c @@ -223,8 +223,8 @@ int32_t LnnRegistProtocol(LnnProtocolManager *protocolMgr) { int32_t ret = SOFTBUS_OK; - if (protocolMgr == NULL || protocolMgr->GetListenerModule == NULL || protocolMgr->Init == NULL || - protocolMgr->Enable == NULL) { + if (protocolMgr == NULL || protocolMgr->getListenerModule == NULL || protocolMgr->init == NULL || + protocolMgr->enable == NULL) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s:bad input protocol!", __func__); return SOFTBUS_ERR; } @@ -233,8 +233,8 @@ int32_t LnnRegistProtocol(LnnProtocolManager *protocolMgr) if (g_networkProtocols[i] != NULL) { continue; } - if (protocolMgr->Init != NULL) { - ret = protocolMgr->Init(protocolMgr); + if (protocolMgr->init != NULL) { + ret = protocolMgr->init(protocolMgr); if (ret != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "init network protocol failed! ret=%d", ret); break; @@ -260,8 +260,8 @@ int32_t UnregistProtocol(LnnProtocolManager *protocolMgr) for (i = 0; i < LNN_NETWORK_MAX_PROTOCOL_COUNT; i++) { if (g_networkProtocols[i] == protocolMgr) { g_networkProtocols[i] = NULL; - if (protocolMgr->Deinit != NULL) { - protocolMgr->Deinit(protocolMgr); + if (protocolMgr->deinit != NULL) { + protocolMgr->deinit(protocolMgr); } return SOFTBUS_OK; } @@ -435,7 +435,7 @@ int32_t LnnInitNetworkManagerDelay(void) continue; } if ((g_networkProtocols[i]->supportedNetif & item->type) != 0) { - int32_t ret = g_networkProtocols[i]->Enable(g_networkProtocols[i], item); + int32_t ret = g_networkProtocols[i]->enable(g_networkProtocols[i], item); if (ret != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "enable protocol (%d) for netif %s failed", i, item->ifName); @@ -469,10 +469,10 @@ void LnnDeinitNetworkManager(void) LnnDeinitPhysicalSubnetManager(); for (i = 0; i < LNN_NETWORK_MAX_PROTOCOL_COUNT; ++i) { - if (g_networkProtocols[i] == NULL || g_networkProtocols[i]->Deinit == NULL) { + if (g_networkProtocols[i] == NULL || g_networkProtocols[i]->deinit == NULL) { continue; } - g_networkProtocols[i]->Deinit(g_networkProtocols[i]); + g_networkProtocols[i]->deinit(g_networkProtocols[i]); g_networkProtocols[i] = NULL; } } @@ -546,10 +546,10 @@ ListenerModule LnnGetProtocolListenerModule(ProtocolType protocol, ListenerMode SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s: not such protocol! protocolId=%d", __func__, protocol); return UNUSE_BUTT; } - if (request.manager == NULL || request.manager->GetListenerModule == NULL) { + if (request.manager == NULL || request.manager->getListenerModule == NULL) { SoftBusLog( SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "%s: protocol manager is null! protocolId=%d", __func__, protocol); return UNUSE_BUTT; } - return request.manager->GetListenerModule(mode); + return request.manager->getListenerModule(mode); } diff --git a/core/bus_center/lnn/net_buscenter/src/lnn_physical_subnet_manager.c b/core/bus_center/lnn/net_buscenter/src/lnn_physical_subnet_manager.c index 749e17c96c..548e700d2a 100644 --- a/core/bus_center/lnn/net_buscenter/src/lnn_physical_subnet_manager.c +++ b/core/bus_center/lnn/net_buscenter/src/lnn_physical_subnet_manager.c @@ -57,8 +57,8 @@ static void ClearSubnetManager(void) { for (uint8_t i = 0; i < MAX_SUPPORTED_PHYSICAL_SUBNET; i++) { if (g_physicalSubnets[i] != NULL) { - if (g_physicalSubnets[i]->Destroy != NULL) { - g_physicalSubnets[i]->Destroy(g_physicalSubnets[i]); + if (g_physicalSubnets[i]->destroy != NULL) { + g_physicalSubnets[i]->destroy(g_physicalSubnets[i]); } g_physicalSubnets[i] = NULL; } @@ -80,8 +80,8 @@ static int32_t DoRegistSubnet(LnnPhysicalSubnet *subnet) continue; } g_physicalSubnets[i] = subnet; - if (g_physicalSubnets[i]->OnNetifStatusChanged != NULL) { - g_physicalSubnets[i]->OnNetifStatusChanged(g_physicalSubnets[i]); + if (g_physicalSubnets[i]->onNetifStatusChanged != NULL) { + g_physicalSubnets[i]->onNetifStatusChanged(g_physicalSubnets[i]); } return SOFTBUS_OK; } @@ -104,8 +104,8 @@ static int32_t DoUnregistSubnetByType(ProtocolType type) { for (uint8_t i = 0; i < MAX_SUPPORTED_PHYSICAL_SUBNET; i++) { if (g_physicalSubnets[i] != NULL && g_physicalSubnets[i]->protocol->id == type) { - if (g_physicalSubnets[i]->Destroy != NULL) { - g_physicalSubnets[i]->Destroy(g_physicalSubnets[i]); + if (g_physicalSubnets[i]->destroy != NULL) { + g_physicalSubnets[i]->destroy(g_physicalSubnets[i]); } g_physicalSubnets[i] = NULL; } @@ -132,8 +132,8 @@ void DoNotifyAddressChange(const char *ifName, ProtocolType protocolType) continue; } - if (g_physicalSubnets[i]->OnNetifStatusChanged != NULL) { - g_physicalSubnets[i]->OnNetifStatusChanged(g_physicalSubnets[i]); + if (g_physicalSubnets[i]->onNetifStatusChanged != NULL) { + g_physicalSubnets[i]->onNetifStatusChanged(g_physicalSubnets[i]); } } } @@ -149,8 +149,8 @@ static void EnableResetingSubnetByType(ProtocolType protocolType) if (g_physicalSubnets[i] == NULL || g_physicalSubnets[i]->protocol->id != protocolType) { continue; } - if (g_physicalSubnets[i]->OnSoftbusNetworkDisconnected != NULL) { - g_physicalSubnets[i]->OnSoftbusNetworkDisconnected(g_physicalSubnets[i]); + if (g_physicalSubnets[i]->onSoftbusNetworkDisconnected != NULL) { + g_physicalSubnets[i]->onSoftbusNetworkDisconnected(g_physicalSubnets[i]); } } } diff --git a/core/bus_center/monitor/include/lnn_event_monitor.h b/core/bus_center/monitor/include/lnn_event_monitor.h index 95fb74690c..afb74f0f22 100644 --- a/core/bus_center/monitor/include/lnn_event_monitor.h +++ b/core/bus_center/monitor/include/lnn_event_monitor.h @@ -23,6 +23,7 @@ extern "C" { #endif int32_t LnnInitEventMonitor(void); +void LnnDeinitEventMonitor(); #ifdef __cplusplus } -- Gitee From 7fc46f96d9319b7c4823987aba7cebb3252c14dc Mon Sep 17 00:00:00 2001 From: jeosif Date: Wed, 16 Nov 2022 17:56:57 +0800 Subject: [PATCH 2/2] dbkey debug and fix mem leak Signed-off-by: jeosif Change-Id: I652b88a00e7a45327fe1b85a5c5a369b08c4b328 --- .../net_buscenter/src/lnn_bt_network_impl.c | 5 ++- .../net_ledger/common/src/lnn_huks_utils.c | 4 ++ .../decision_db/src/lnn_decision_db.c | 38 +++++++++++++++---- .../monitor/src/lnn_event_monitor_virtual.c | 4 ++ .../service/src/bus_center_manager.c | 1 + 5 files changed, 43 insertions(+), 9 deletions(-) diff --git a/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c b/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c index fafde15295..229d69fe97 100644 --- a/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c +++ b/core/bus_center/lnn/net_buscenter/src/lnn_bt_network_impl.c @@ -58,6 +58,9 @@ static int32_t GetAvailableBtMac(char *macStr, uint32_t len) int32_t ret; SoftBusBtAddr mac; + if (len != BT_MAC_LEN) { + return SOFTBUS_INVALID_PARAM; + } ret = SoftBusGetBtMacAddr(&mac); if (ret != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get bt mac addr fail"); @@ -148,7 +151,7 @@ static BtSubnetManagerEvent GetBtRegistEvent(void) if (!SoftBusGetBtState()) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_DBG, "bluetooth is not enabled yet"); - return BT_SUBNET_MANAGER_EVENT_MAX; + return BT_SUBNET_MANAGER_EVENT_IF_DOWN; } return GetAvailableBtMac(macStr, sizeof(macStr)) == SOFTBUS_OK ? BT_SUBNET_MANAGER_EVENT_IF_READY : BT_SUBNET_MANAGER_EVENT_IF_DOWN; diff --git a/core/bus_center/lnn/net_ledger/common/src/lnn_huks_utils.c b/core/bus_center/lnn/net_ledger/common/src/lnn_huks_utils.c index 85cbbe9fa6..e06dfb0d09 100644 --- a/core/bus_center/lnn/net_ledger/common/src/lnn_huks_utils.c +++ b/core/bus_center/lnn/net_ledger/common/src/lnn_huks_utils.c @@ -285,11 +285,13 @@ int32_t LnnEncryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlo struct HksBlob cipherText = {LNN_HUKS_AES_COMMON_SIZE, cipher}; if (UpdateLoopFinishByHuks(&handleEncrypt, g_encryptParamSet, inData, &cipherText) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks encrypt data update and finish fail"); + (void)memset_s(cipher, sizeof(cipher), 0x0, sizeof(cipher)); return SOFTBUS_ERR; } outData->size = cipherText.size; if (memcpy_s(outData->data, cipherText.size, cipherText.data, cipherText.size) != EOK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks memcpy_s encrypt data fail"); + (void)memset_s(cipher, sizeof(cipher), 0x0, sizeof(cipher)); return SOFTBUS_MEM_ERR; } (void)memset_s(cipher, sizeof(cipher), 0x0, sizeof(cipher)); @@ -313,11 +315,13 @@ int32_t LnnDecryptDataByHuks(const struct HksBlob *keyAlias, const struct HksBlo struct HksBlob plainText = {LNN_HUKS_AES_COMMON_SIZE, plain}; if (UpdateLoopFinishByHuks(&handleDecrypt, g_decryptParamSet, inData, &plainText) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks decrypt data update and finish fail"); + (void)memset_s(plain, sizeof(plain), 0x0, sizeof(plain)); return SOFTBUS_ERR; } outData->size = plainText.size; if (memcpy_s(outData->data, plainText.size, plainText.data, plainText.size) != EOK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "huks memcpy_s decrypt data fail"); + (void)memset_s(plain, sizeof(plain), 0x0, sizeof(plain)); return SOFTBUS_MEM_ERR; } (void)memset_s(plain, sizeof(plain), 0x0, sizeof(plain)); diff --git a/core/bus_center/lnn/net_ledger/decision_db/src/lnn_decision_db.c b/core/bus_center/lnn/net_ledger/decision_db/src/lnn_decision_db.c index 7c5f413456..2e71546374 100644 --- a/core/bus_center/lnn/net_ledger/decision_db/src/lnn_decision_db.c +++ b/core/bus_center/lnn/net_ledger/decision_db/src/lnn_decision_db.c @@ -51,6 +51,7 @@ static int32_t EncryptDecisionDbKey(uint8_t *dbKey, uint32_t len) plainData.data = dbKey; if (LnnEncryptDataByHuks(&g_keyAlias, &plainData, &encryptData) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt dbKey by huks fail"); + (void)memset_s(plainData.data, len, 0x0, len); SoftBusFree(encryptData.data); return SOFTBUS_ERR; } @@ -67,6 +68,7 @@ static int32_t EncryptDecisionDbKey(uint8_t *dbKey, uint32_t len) static int32_t DecryptDecisionDbKey(uint8_t *dbKey, uint32_t len) { + int32_t ret; struct HksBlob encryptData = {0}; struct HksBlob decryptData = {0}; @@ -77,11 +79,22 @@ static int32_t DecryptDecisionDbKey(uint8_t *dbKey, uint32_t len) } encryptData.size = len; encryptData.data = dbKey; - if (LnnDecryptDataByHuks(&g_keyAlias, &encryptData, &decryptData) != SOFTBUS_OK) { - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "decrypt dbKey by huks fail"); - return SOFTBUS_ERR; - } - SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "decrypt dbKey log for audit"); + do { + if (LnnDecryptDataByHuks(&g_keyAlias, &encryptData, &decryptData) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "decrypt dbKey by huks fail"); + ret = SOFTBUS_ERR; + break; + } + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "decrypt dbKey log for audit"); + if (memcpy_s(dbKey, len, decryptData.data, decryptData.size) != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "memcpy_s dbKey fail"); + ret = SOFTBUS_MEM_ERR; + break; + } + ret = SOFTBUS_OK; + } while (false); + (void)memset_s(decryptData.data, decryptData.size, 0x0, decryptData.size); + SoftBusFree(decryptData.data); return SOFTBUS_OK; } @@ -128,10 +141,12 @@ static int32_t EncryptDecisionDb(DbContext *ctx) if (GetDecisionDbKey(dbKey, sizeof(dbKey), false) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get decision dbKey fail"); + (void)memset_s(dbKey, sizeof(dbKey), 0x0, sizeof(dbKey)); return SOFTBUS_ERR; } if (EncryptedDb(ctx, dbKey, sizeof(dbKey)) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt decision db fail"); + (void)memset_s(dbKey, sizeof(dbKey), 0x0, sizeof(dbKey)); return SOFTBUS_ERR; } (void)memset_s(dbKey, sizeof(dbKey), 0x0, sizeof(dbKey)); @@ -149,10 +164,12 @@ static int32_t UpdateDecisionDbKey(DbContext *ctx) } if (GetDecisionDbKey(dbKey, sizeof(dbKey), true) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get decision dbKey fail"); + (void)memset_s(dbKey, sizeof(dbKey), 0x0, sizeof(dbKey)); return SOFTBUS_ERR; } if (UpdateDbPassword(ctx, dbKey, sizeof(dbKey)) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "encrypt decision db fail"); + (void)memset_s(dbKey, sizeof(dbKey), 0x0, sizeof(dbKey)); return SOFTBUS_ERR; } SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_WARN, "update dbKey log for audit"); @@ -352,6 +369,9 @@ static int32_t GetTrustedDevInfoRecord(DbContext *ctx, const char *accountHexHas if (QueryRecordByKey(ctx, TABLE_TRUSTED_DEV_INFO, (uint8_t *)accountHexHash, (uint8_t **)udidArray, *num) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "query udidArray failed."); + SoftBusFree(*udidArray); + *udidArray = NULL; + *num = 0; return SOFTBUS_ERR; } return SOFTBUS_OK; @@ -379,12 +399,14 @@ int32_t LnnGetTrustedDevInfoFromDb(char **udidArray, uint32_t *num) return SOFTBUS_ERR; } int32_t rc = GetTrustedDevInfoRecord(ctx, accountHexHash, udidArray, num); - if (rc != SOFTBUS_OK && *udidArray != NULL) { - SoftBusFree(*udidArray); - *udidArray = NULL; + if (rc != SOFTBUS_OK) { + SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "get trusted dev info failed."); } if (CloseDatabase(ctx) != SOFTBUS_OK) { SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "close database failed."); + SoftBusFree(*udidArray); + *udidArray = NULL; + *num = 0; return SOFTBUS_ERR; } return rc; diff --git a/core/bus_center/monitor/src/lnn_event_monitor_virtual.c b/core/bus_center/monitor/src/lnn_event_monitor_virtual.c index 081ba12b90..b94b28beb3 100644 --- a/core/bus_center/monitor/src/lnn_event_monitor_virtual.c +++ b/core/bus_center/monitor/src/lnn_event_monitor_virtual.c @@ -23,3 +23,7 @@ int32_t LnnInitEventMonitor(void) SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "init virtual event monitor"); return SOFTBUS_OK; } + +void LnnDeinitEventMonitor(void) +{ +} diff --git a/core/bus_center/service/src/bus_center_manager.c b/core/bus_center/service/src/bus_center_manager.c index 7d341e1ff7..b138db1ed2 100644 --- a/core/bus_center/service/src/bus_center_manager.c +++ b/core/bus_center/service/src/bus_center_manager.c @@ -186,6 +186,7 @@ void BusCenterServerDeinit(void) LnnDeinitLaneHub(); LnnDeinitNetBuilder(); LnnDeinitNetworkManager(); + LnnDeinitEventMonitor(); LnnDeinitBusCenterEvent(); LnnDeinitNetLedger(); SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "bus center server deinit"); -- Gitee