mirror of
https://gitee.com/openharmony/communication_dsoftbus
synced 2024-11-24 09:20:04 +00:00
Merge branch 'master' of gitee.com:zgit2021/communication_dsoftbus
This commit is contained in:
commit
726af42101
@ -20,4 +20,7 @@ declare_args() {
|
||||
enable_connection_ble = false
|
||||
|
||||
enable_trans_udp = false
|
||||
enable_auth_account = false
|
||||
|
||||
enable_auto_networking = true
|
||||
}
|
||||
|
@ -20,4 +20,7 @@ declare_args() {
|
||||
enable_connection_ble = false
|
||||
|
||||
enable_trans_udp = false
|
||||
enable_auth_account = false
|
||||
|
||||
enable_auto_networking = true
|
||||
}
|
||||
|
@ -20,4 +20,7 @@ declare_args() {
|
||||
enable_connection_ble = false
|
||||
|
||||
enable_trans_udp = false
|
||||
enable_auth_account = false
|
||||
|
||||
enable_auto_networking = true
|
||||
}
|
||||
|
@ -28,6 +28,10 @@ common_src = [
|
||||
"src/auth_socket.c",
|
||||
]
|
||||
|
||||
if (enable_auth_account == true) {
|
||||
defines = [ "AUTH_ACCOUNT" ]
|
||||
}
|
||||
|
||||
if (defined(ohos_lite)) {
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
|
||||
@ -37,6 +41,7 @@ if (defined(ohos_lite)) {
|
||||
"$dsoftbus_root_path/core/adapter/kernel/include",
|
||||
"$dsoftbus_root_path/core/bus_center/interface",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
||||
"$dsoftbus_root_path/core/bus_center/utils/include",
|
||||
"$dsoftbus_root_path/core/common/include",
|
||||
"$dsoftbus_root_path/core/common/message_handler/include",
|
||||
"$dsoftbus_root_path/core/connection/manager",
|
||||
@ -56,11 +61,13 @@ if (defined(ohos_lite)) {
|
||||
deps = [
|
||||
"$dsoftbus_root_path/core/adapter/kernel:softbus_adapter_kernel",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger:dsoftbus_bus_center_ledger",
|
||||
"$dsoftbus_root_path/core/bus_center/utils:dsoftbus_bus_center_utils",
|
||||
"$dsoftbus_root_path/core/common/json_utils:json_utils",
|
||||
"$dsoftbus_root_path/core/common/softbus_property:softbus_property",
|
||||
"$dsoftbus_root_path/core/common/utils:softbus_utils",
|
||||
"$dsoftbus_root_path/core/connection/tcp:tcp_connection",
|
||||
"$hilog_lite_deps_path",
|
||||
"//base/security/deviceauth/services:deviceauth_sdk",
|
||||
"//third_party/bounds_checking_function:libsec_shared",
|
||||
]
|
||||
}
|
||||
@ -73,6 +80,7 @@ if (defined(ohos_lite)) {
|
||||
"$dsoftbus_root_path/core/adapter/kernel/include",
|
||||
"$dsoftbus_root_path/core/bus_center/interface",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
||||
"$dsoftbus_root_path/core/bus_center/utils/include",
|
||||
"$dsoftbus_root_path/core/common/include",
|
||||
"$dsoftbus_root_path/core/common/message_handler/include",
|
||||
"$dsoftbus_root_path/core/connection/manager",
|
||||
@ -86,6 +94,7 @@ if (defined(ohos_lite)) {
|
||||
deps = [
|
||||
"$dsoftbus_root_path/core/adapter/kernel:softbus_adapter_kernel",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger:dsoftbus_bus_center_ledger",
|
||||
"$dsoftbus_root_path/core/bus_center/utils:dsoftbus_bus_center_utils",
|
||||
"$dsoftbus_root_path/core/common/json_utils:json_utils",
|
||||
"$dsoftbus_root_path/core/common/message_handler",
|
||||
"$dsoftbus_root_path/core/common/security:softbus_crypto",
|
||||
|
@ -70,6 +70,7 @@ typedef struct {
|
||||
|
||||
char peerUdid[UDID_BUF_LEN];
|
||||
char peerUuid[UUID_BUF_LEN];
|
||||
char peerUid[MAX_ACCOUNT_HASH_LEN];
|
||||
int32_t softbusVersion;
|
||||
SoftBusVersion peerVersion;
|
||||
|
||||
|
@ -115,7 +115,7 @@ typedef struct {
|
||||
} VerifyCallback;
|
||||
|
||||
typedef struct {
|
||||
void (*onTransUdpDataRecv)(int64_t authId, ConnectOption *option, AuthTransDataInfo *info);
|
||||
void (*onTransUdpDataRecv)(int64_t authId, const ConnectOption *option, const AuthTransDataInfo *info);
|
||||
} AuthTransCallback;
|
||||
|
||||
uint32_t AuthGetEncryptHeadLen(void);
|
||||
@ -127,7 +127,7 @@ void CloseAuthServer(void);
|
||||
int32_t AuthRegCallback(AuthModuleId moduleId, VerifyCallback *cb);
|
||||
int32_t AuthTransDataRegCallback(AuthModuleId moduleId, AuthTransCallback *cb);
|
||||
|
||||
int64_t AuthVerifyDevice(AuthModuleId moduleId, const ConnectOption *option);
|
||||
int64_t AuthVerifyDevice(AuthModuleId moduleId, const ConnectionAddr *addr);
|
||||
|
||||
int32_t AuthPostData(const AuthDataHead *head, const uint8_t *data, uint32_t len);
|
||||
int32_t AuthHandleLeaveLNN(int64_t authId);
|
||||
|
@ -325,6 +325,14 @@ char *AuthGenDeviceLevelParam(const AuthManager *auth, bool isClient)
|
||||
cJSON_Delete(msg);
|
||||
return NULL;
|
||||
}
|
||||
#ifdef AUTH_ACCOUNT
|
||||
LOG_INFO("in account auth mode");
|
||||
if (!AddStringToJsonObject(msg, FIELD_UID_HASH, auth->peerUid)) {
|
||||
LOG_ERR("AddStringToJsonObject Fail.");
|
||||
cJSON_Delete(msg);
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
char *data = cJSON_PrintUnformatted(msg);
|
||||
if (data == NULL) {
|
||||
LOG_ERR("cJSON_PrintUnformatted failed");
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include "auth_connection.h"
|
||||
#include "auth_sessionkey.h"
|
||||
#include "auth_socket.h"
|
||||
#include "lnn_connection_addr_utils.h"
|
||||
#include "message_handler.h"
|
||||
#include "softbus_base_listener.h"
|
||||
#include "softbus_errcode.h"
|
||||
@ -258,7 +259,8 @@ static void HandleAuthFail(AuthManager *auth)
|
||||
auth->cb->onDeviceVerifyFail(auth->authId);
|
||||
}
|
||||
|
||||
static int32_t InitNewAuthManager(AuthManager *auth, uint32_t moduleId, const ConnectOption *option)
|
||||
static int32_t InitNewAuthManager(AuthManager *auth, uint32_t moduleId, const ConnectOption *option,
|
||||
const ConnectionAddr *addr)
|
||||
{
|
||||
auth->cb = GetAuthCallback(moduleId);
|
||||
if (auth->cb == NULL) {
|
||||
@ -271,12 +273,21 @@ static int32_t InitNewAuthManager(AuthManager *auth, uint32_t moduleId, const Co
|
||||
auth->softbusVersion = SOFT_BUS_NEW_V1;
|
||||
auth->option = *option;
|
||||
auth->hichain = g_hichainGaInstance;
|
||||
if (memcpy_s(auth->peerUid, MAX_ACCOUNT_HASH_LEN, addr->peerUid, MAX_ACCOUNT_HASH_LEN) != 0) {
|
||||
LOG_ERR("memcpy_s faield");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ListNodeInsert(&g_authClientHead, &auth->node);
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int64_t HandleVerifyDevice(AuthModuleId moduleId, const ConnectOption *option)
|
||||
static int64_t HandleVerifyDevice(AuthModuleId moduleId, const ConnectionAddr *addr)
|
||||
{
|
||||
ConnectOption option = {0};
|
||||
if (!LnnConvertAddrToOption(addr, &option)) {
|
||||
LOG_ERR("auth LnnConverAddrToOption failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (pthread_mutex_lock(&g_authLock) != 0) {
|
||||
LOG_ERR("lock mutex failed");
|
||||
return SOFTBUS_ERR;
|
||||
@ -288,7 +299,7 @@ static int64_t HandleVerifyDevice(AuthModuleId moduleId, const ConnectOption *op
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
(void)memset_s(auth, sizeof(AuthManager), 0, sizeof(AuthManager));
|
||||
if (InitNewAuthManager(auth, moduleId, option) != SOFTBUS_OK) {
|
||||
if (InitNewAuthManager(auth, moduleId, &option, addr) != SOFTBUS_OK) {
|
||||
LOG_ERR("auth InitNewAuthManager failed");
|
||||
(void)pthread_mutex_unlock(&g_authLock);
|
||||
SoftBusFree(auth);
|
||||
@ -296,18 +307,18 @@ static int64_t HandleVerifyDevice(AuthModuleId moduleId, const ConnectOption *op
|
||||
}
|
||||
(void)pthread_mutex_unlock(&g_authLock);
|
||||
|
||||
if (option->type == CONNECT_TCP) {
|
||||
if (HandleIpVerifyDevice(auth, option) != SOFTBUS_OK) {
|
||||
if (option.type == CONNECT_TCP) {
|
||||
if (HandleIpVerifyDevice(auth, &option) != SOFTBUS_OK) {
|
||||
LOG_ERR("HandleIpVerifyDevice failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
} else if (option->type == CONNECT_BR) {
|
||||
if (ConnConnectDevice(option, auth->requestId, &g_connResult) != SOFTBUS_OK) {
|
||||
} else if (option.type == CONNECT_BR) {
|
||||
if (ConnConnectDevice(&option, auth->requestId, &g_connResult) != SOFTBUS_OK) {
|
||||
LOG_ERR("auth ConnConnectDevice failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
} else {
|
||||
LOG_ERR("auth conn type %d is not support", option->type);
|
||||
LOG_ERR("auth conn type %d is not support", option.type);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (EventInLooper(auth->authId) != SOFTBUS_OK) {
|
||||
@ -318,11 +329,11 @@ static int64_t HandleVerifyDevice(AuthModuleId moduleId, const ConnectOption *op
|
||||
return auth->authId;
|
||||
}
|
||||
|
||||
int64_t AuthVerifyDevice(AuthModuleId moduleId, const ConnectOption *option)
|
||||
int64_t AuthVerifyDevice(AuthModuleId moduleId, const ConnectionAddr *addr)
|
||||
{
|
||||
int64_t authId;
|
||||
|
||||
if (option == NULL) {
|
||||
if (addr == NULL) {
|
||||
LOG_ERR("invalid parameter");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
@ -330,7 +341,7 @@ int64_t AuthVerifyDevice(AuthModuleId moduleId, const ConnectOption *option)
|
||||
LOG_ERR("need to call HichainServiceInit!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
authId = HandleVerifyDevice(moduleId, option);
|
||||
authId = HandleVerifyDevice(moduleId, addr);
|
||||
if (authId <= 0) {
|
||||
LOG_ERR("auth HandleVerifyDevice failed");
|
||||
return SOFTBUS_ERR;
|
||||
|
@ -33,15 +33,16 @@ if (defined(ohos_lite)) {
|
||||
"ipc/small_system/src/lnn_bus_center_ipc.c",
|
||||
"lnn//net_builder/sync_info/src/lnn_exchange_device_info.c",
|
||||
"lnn//net_builder/sync_info/src/lnn_sync_item_info.c",
|
||||
"lnn/net_builder/src/lnn_coap_discovery_impl.c",
|
||||
"lnn/net_builder/src/lnn_connection_fsm.c",
|
||||
"lnn/net_builder/src/lnn_discovery_manager.c",
|
||||
"lnn/net_builder/src/lnn_net_builder.c",
|
||||
"lnn/net_builder/src/lnn_network_id.c",
|
||||
"lnn/net_builder/src/lnn_state_machine.c",
|
||||
"service/src/bus_center_event.c",
|
||||
"service/src/bus_center_manager.c",
|
||||
]
|
||||
if (enable_auto_networking == true) {
|
||||
sources += [ "lnn/net_builder/src/lnn_coap_discovery_impl.c" ]
|
||||
}
|
||||
include_dirs = [
|
||||
"ipc/small_system/include",
|
||||
"lnn/net_builder/include",
|
||||
@ -104,15 +105,16 @@ if (defined(ohos_lite)) {
|
||||
"ipc/standard_system/src/lnn_bus_center_ipc.cpp",
|
||||
"lnn//net_builder/sync_info/src/lnn_exchange_device_info.c",
|
||||
"lnn//net_builder/sync_info/src/lnn_sync_item_info.c",
|
||||
"lnn/net_builder/src/lnn_coap_discovery_impl.c",
|
||||
"lnn/net_builder/src/lnn_connection_fsm.c",
|
||||
"lnn/net_builder/src/lnn_discovery_manager.c",
|
||||
"lnn/net_builder/src/lnn_net_builder.c",
|
||||
"lnn/net_builder/src/lnn_network_id.c",
|
||||
"lnn/net_builder/src/lnn_state_machine.c",
|
||||
"service/src/bus_center_event.c",
|
||||
"service/src/bus_center_manager.c",
|
||||
]
|
||||
if (enable_auto_networking == true) {
|
||||
sources += [ "lnn/net_builder/src/lnn_coap_discovery_impl.c" ]
|
||||
}
|
||||
include_dirs = [
|
||||
"ipc/standard_system/include",
|
||||
"lnn/net_builder/include",
|
||||
|
@ -32,12 +32,20 @@ typedef struct {
|
||||
|
||||
int32_t LnnInitDiscoveryManager(void);
|
||||
|
||||
int32_t LnnStartDiscovery(void);
|
||||
|
||||
int32_t LnnStopDiscovery(void);
|
||||
|
||||
int32_t __attribute__ ((weak)) LnnInitCoapDiscovery(LnnDiscoveryImplCallback *callback);
|
||||
|
||||
int32_t __attribute__ ((weak)) LnnStartCoapDiscovery(void);
|
||||
|
||||
int32_t __attribute__ ((weak)) LnnStopCoapDiscovery(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* LNN_DISCOVERY_MANAGER_H */
|
||||
#endif /* LNN_DISCOVERY_MANAGER_H */
|
||||
|
@ -17,22 +17,13 @@
|
||||
|
||||
#include <securec.h>
|
||||
|
||||
#include "auth_interface.h"
|
||||
#include "bus_center_info_key.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "disc_interface.h"
|
||||
#include "discovery_service.h"
|
||||
#include "lnn_event_monitor.h"
|
||||
#include "lnn_ip_utils.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
#include "trans_tcp_direct_listener.h"
|
||||
|
||||
#define LNN_DISC_CAPABILITY "ddmpCapability"
|
||||
#define LNN_PUBLISH_ID 0
|
||||
#define LNN_SUBSCRIBE_ID 0
|
||||
#define IP_DEFAULT_PORT 0
|
||||
|
||||
static LnnDiscoveryImplCallback g_callback;
|
||||
|
||||
@ -44,6 +35,8 @@ static DiscInnerCallback g_discCb = {
|
||||
|
||||
static void DeviceFound(const DeviceInfo *device)
|
||||
{
|
||||
ConnectionAddr addr;
|
||||
|
||||
if (device == NULL) {
|
||||
LOG_ERR("device para is null");
|
||||
return;
|
||||
@ -57,125 +50,31 @@ static void DeviceFound(const DeviceInfo *device)
|
||||
LOG_ERR("discovery get port is 0 !");
|
||||
return;
|
||||
}
|
||||
addr.type = device->addr[0].type;
|
||||
if (memcpy_s(addr.info.ip.ip, IP_STR_MAX_LEN, device->addr[0].info.ip.ip, strlen(device->addr[0].info.ip.ip)) != 0) {
|
||||
LOG_ERR("strncpy ip failed");
|
||||
return;
|
||||
}
|
||||
addr.info.ip.port = device->addr[0].info.ip.port;
|
||||
if (memcpy_s(addr.peerUid, MAX_ACCOUNT_HASH_LEN, device->hwAccountHash, MAX_ACCOUNT_HASH_LEN) != 0) {
|
||||
LOG_ERR("memcpy_s peer uid failed");
|
||||
return;
|
||||
}
|
||||
if (g_callback.OnDeviceFound) {
|
||||
g_callback.OnDeviceFound(&device->addr[0]);
|
||||
g_callback.OnDeviceFound(&addr);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t OpenAuthPort(void)
|
||||
int32_t LnnStopCoapDiscovery(void)
|
||||
{
|
||||
int32_t port = OpenAuthServer();
|
||||
if (port < 0) {
|
||||
LOG_ERR("open auth server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return LnnSetLocalNumInfo(NUM_KEY_AUTH_PORT, port);
|
||||
}
|
||||
|
||||
static void CloseAuthPort(void)
|
||||
{
|
||||
CloseAuthServer();
|
||||
(void)LnnSetLocalNumInfo(NUM_KEY_AUTH_PORT, IP_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
static int32_t OpenSessionPort(void)
|
||||
{
|
||||
char ipAddr[IP_LEN] = {0};
|
||||
int32_t port;
|
||||
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr, IP_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ip failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
port = TransTdcStartSessionListener(ipAddr, 0);
|
||||
if (port < 0) {
|
||||
LOG_ERR("open session server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return LnnSetLocalNumInfo(NUM_KEY_SESSION_PORT, port);
|
||||
}
|
||||
|
||||
static void CloseSessionPort(void)
|
||||
{
|
||||
TransTdcStopSessionListener();
|
||||
(void)LnnSetLocalNumInfo(NUM_KEY_SESSION_PORT, IP_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
static int32_t OpenProxyPort(void)
|
||||
{
|
||||
LocalListenerInfo listenerInfo = {0};
|
||||
char ipAddr[IP_LEN] = {0};
|
||||
int32_t port;
|
||||
|
||||
listenerInfo.type = CONNECT_TCP;
|
||||
listenerInfo.info.ipListenerInfo.port = 0;
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr, IP_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ip failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (strncpy_s(listenerInfo.info.ipListenerInfo.ip, IP_LEN, ipAddr, strlen(ipAddr)) != EOK) {
|
||||
LOG_ERR("copy ip failed");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
port = ConnStartLocalListening(&listenerInfo);
|
||||
if (port < 0) {
|
||||
LOG_ERR("open proxy server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return LnnSetLocalNumInfo(NUM_KEY_PROXY_PORT, port);
|
||||
}
|
||||
|
||||
static void CloseProxyPort(void)
|
||||
{
|
||||
LocalListenerInfo listenerInfo = {0};
|
||||
listenerInfo.type = CONNECT_TCP;
|
||||
if (ConnStopLocalListening(&listenerInfo) != SOFTBUS_OK) {
|
||||
LOG_ERR("ConnStopLocalListening fail!");
|
||||
}
|
||||
(void)LnnSetLocalNumInfo(NUM_KEY_PROXY_PORT, IP_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
static int32_t OpenIpLink(void)
|
||||
{
|
||||
int32_t ret = OpenAuthPort();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG_ERR("OpenAuthPort fail!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ret = OpenSessionPort();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG_ERR("OpenSessionPort fail!");
|
||||
CloseAuthPort();
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ret = OpenProxyPort();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG_ERR("OpenProxyPort fail!");
|
||||
CloseAuthPort();
|
||||
CloseSessionPort();
|
||||
if (DiscStopAdvertise(MODULE_LNN, LNN_SUBSCRIBE_ID) != SOFTBUS_OK) {
|
||||
LOG_ERR("DiscStopAdvertise fail!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void CloseIpLink(void)
|
||||
{
|
||||
CloseAuthPort();
|
||||
CloseSessionPort();
|
||||
CloseProxyPort();
|
||||
}
|
||||
|
||||
static void StopCoapDiscovery(void)
|
||||
{
|
||||
if (DiscUnpublish(MODULE_LNN, LNN_PUBLISH_ID) != SOFTBUS_OK) {
|
||||
LOG_ERR("DiscUnpublish fail!");
|
||||
}
|
||||
if (DiscStopAdvertise(MODULE_LNN, LNN_SUBSCRIBE_ID) != SOFTBUS_OK) {
|
||||
LOG_ERR("DiscStopAdvertise fail!");
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t StartCoapDiscovery(void)
|
||||
int32_t LnnStartCoapDiscovery(void)
|
||||
{
|
||||
SubscribeInnerInfo subscribeInfo = {
|
||||
.subscribeId = LNN_SUBSCRIBE_ID,
|
||||
@ -187,18 +86,6 @@ static int32_t StartCoapDiscovery(void)
|
||||
.capabilityData = (unsigned char *)LNN_DISC_CAPABILITY,
|
||||
.dataLen = strlen(LNN_DISC_CAPABILITY) + 1,
|
||||
};
|
||||
PublishInnerInfo publishInfo = {
|
||||
.publishId = LNN_PUBLISH_ID,
|
||||
.medium = COAP,
|
||||
.freq = HIGH,
|
||||
.capability = LNN_DISC_CAPABILITY,
|
||||
.capabilityData = (unsigned char *)LNN_DISC_CAPABILITY,
|
||||
.dataLen = strlen(LNN_DISC_CAPABILITY) + 1,
|
||||
};
|
||||
if (DiscStartScan(MODULE_LNN, &publishInfo) != SOFTBUS_OK) {
|
||||
LOG_ERR("DiscStartScan failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (DiscSetDiscoverCallback(MODULE_LNN, &g_discCb) != SOFTBUS_OK) {
|
||||
LOG_ERR("DiscSetDiscoverCallback failed");
|
||||
return SOFTBUS_ERR;
|
||||
@ -206,125 +93,12 @@ static int32_t StartCoapDiscovery(void)
|
||||
return DiscStartAdvertise(MODULE_LNN, &subscribeInfo);
|
||||
}
|
||||
|
||||
static int32_t SetLocalIpInfo(char *ipAddr, char *ifName)
|
||||
{
|
||||
if (LnnSetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ip error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LnnSetLocalStrInfo(STRING_KEY_NET_IF_NAME, ifName) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ifname error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetLocalIpInfo(char *ipAddr, uint32_t ipAddrLen, char *ifName, uint32_t ifNameLen)
|
||||
{
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr, ipAddrLen) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ip error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_NET_IF_NAME, ifName, ifNameLen) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ifname error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetUpdateLocalIp(char *ipAddr, uint32_t ipAddrLen, char *ifName, uint32_t ifNameLen)
|
||||
{
|
||||
if (LnnGetLocalIp(ipAddr, ipAddrLen, ifName, ifNameLen, CONNECTION_ADDR_ETH) == SOFTBUS_OK) {
|
||||
LOG_INFO("get eth ip success");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (LnnGetLocalIp(ipAddr, ipAddrLen, ifName, ifNameLen, CONNECTION_ADDR_WLAN) == SOFTBUS_OK) {
|
||||
LOG_INFO("get wlan ip success");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (strncpy_s(ipAddr, ipAddrLen, LNN_LOOPBACK_IP, strlen(LNN_LOOPBACK_IP)) != EOK) {
|
||||
LOG_ERR("copy loopback ip addr failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (strncpy_s(ifName, ifNameLen, LNN_LOOPBACK_IFNAME, strlen(LNN_LOOPBACK_IFNAME)) != EOK) {
|
||||
LOG_ERR("copy loopback ifname failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
LOG_INFO("set loopback ip as default");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void IpAddrChangeEventHandler(LnnMonitorEventType event, const void *para)
|
||||
{
|
||||
char ipCurrentAddr[IP_LEN] = {0};
|
||||
char ifCurrentName[NET_IF_NAME_LEN] = {0};
|
||||
char ipNewAddr[IP_LEN] = {0};
|
||||
char ifNewName[NET_IF_NAME_LEN] = {0};
|
||||
|
||||
(void)para;
|
||||
if (event != LNN_MONITOR_EVENT_IP_ADDR_CHANGED) {
|
||||
LOG_ERR("not interest event: %d", event);
|
||||
return;
|
||||
}
|
||||
if (GetLocalIpInfo(ipCurrentAddr, IP_LEN, ifCurrentName, NET_IF_NAME_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get current ip info failed");
|
||||
return;
|
||||
}
|
||||
if (GetUpdateLocalIp(ipNewAddr, IP_LEN, ifNewName, NET_IF_NAME_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get new ip info failed");
|
||||
return;
|
||||
}
|
||||
if (strcmp(ipCurrentAddr, ipNewAddr) == 0 && strcmp(ifCurrentName, ifNewName) == 0) {
|
||||
LOG_INFO("ip info not changed");
|
||||
return;
|
||||
}
|
||||
LOG_INFO("ip info changed, update local ledger");
|
||||
if (SetLocalIpInfo(ipNewAddr, ifNewName) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ip info failed");
|
||||
return;
|
||||
}
|
||||
if (strncmp(ifCurrentName, LNN_LOOPBACK_IFNAME, strlen(LNN_LOOPBACK_IFNAME)) != 0) {
|
||||
LOG_INFO("close previous ip link and stop previous discovery");
|
||||
CloseIpLink();
|
||||
StopCoapDiscovery();
|
||||
}
|
||||
if (strncmp(ifNewName, LNN_LOOPBACK_IFNAME, strlen(LNN_LOOPBACK_IFNAME)) != 0) {
|
||||
LOG_INFO("open ip link and start discovery");
|
||||
DiscLinkStatusChanged(LINK_STATUS_UP, COAP);
|
||||
if (OpenIpLink() != SOFTBUS_OK) {
|
||||
LOG_ERR("open ip link failed");
|
||||
}
|
||||
if (StartCoapDiscovery() != SOFTBUS_OK) {
|
||||
LOG_ERR("start discovery failed");
|
||||
}
|
||||
SetCallLnnStatus(true);
|
||||
} else {
|
||||
DiscLinkStatusChanged(LINK_STATUS_DOWN, COAP);
|
||||
AuthIpChanged(CONNECT_TCP);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t LnnInitCoapDiscovery(LnnDiscoveryImplCallback *callback)
|
||||
{
|
||||
char ipAddr[IP_LEN] = {0};
|
||||
char ifName[NET_IF_NAME_LEN] = {0};
|
||||
|
||||
if (callback == NULL) {
|
||||
LOG_ERR("coap discovery callback is null");
|
||||
return SOFTBUS_INVALID_PARAM;
|
||||
}
|
||||
g_callback.OnDeviceFound = callback->OnDeviceFound;
|
||||
if (LnnRegisterEventHandler(LNN_MONITOR_EVENT_IP_ADDR_CHANGED, IpAddrChangeEventHandler) != SOFTBUS_OK) {
|
||||
LOG_ERR("register ip addr change event handler failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (GetUpdateLocalIp(ipAddr, IP_LEN, ifName, NET_IF_NAME_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get new ip info failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SetLocalIpInfo(ipAddr, ifName) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ip info failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
}
|
||||
|
@ -232,13 +232,6 @@ static int32_t OnJoinLNNInAuth(LnnConnectionFsm *connFsm)
|
||||
{
|
||||
int32_t rc;
|
||||
LnnConntionInfo *connInfo = &connFsm->connInfo;
|
||||
ConnectOption option;
|
||||
|
||||
if (!LnnConvertAddrToOption(&connInfo->addr, &option)) {
|
||||
LOG_ERR("[id=%u]convert addr to option failed", connFsm->id);
|
||||
CompleteJoinLNN(connFsm, NULL, SOFTBUS_ERR);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
|
||||
if ((connInfo->flag & (CONN_INFO_FLAG_JOINING_ACTIVE | CONN_INFO_FLAG_JOINING_PASSIVE)) != 0) {
|
||||
LOG_INFO("[id=%u]join LNN is ongoing, waiting...", connFsm->id);
|
||||
@ -246,7 +239,7 @@ static int32_t OnJoinLNNInAuth(LnnConnectionFsm *connFsm)
|
||||
}
|
||||
LOG_INFO("[id=%u]begin join request", connFsm->id);
|
||||
connInfo->flag |= CONN_INFO_FLAG_JOINING_ACTIVE;
|
||||
connInfo->authId = AuthVerifyDevice(LNN, &option);
|
||||
connInfo->authId = AuthVerifyDevice(LNN, &(connInfo->addr));
|
||||
if (connInfo->authId <= 0) {
|
||||
LOG_ERR("[id=%u]auth verify device failed", connFsm->id);
|
||||
CompleteJoinLNN(connFsm, NULL, SOFTBUS_ERR);
|
||||
|
@ -18,12 +18,17 @@
|
||||
#include <securec.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "disc_interface.h"
|
||||
#include "discovery_service.h"
|
||||
#include "lnn_net_builder.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
#include "softbus_mem_interface.h"
|
||||
|
||||
#define LNN_DISC_CAPABILITY "ddmpCapability"
|
||||
#define LNN_PUBLISH_ID 0
|
||||
|
||||
static void DeviceFound(const ConnectionAddr *addr);
|
||||
|
||||
typedef enum {
|
||||
@ -33,11 +38,15 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
int32_t (*InitDiscoveryImpl)(LnnDiscoveryImplCallback *callback);
|
||||
int32_t (*StartDiscoveryImpl)(void);
|
||||
int32_t (*StopDiscoveryImpl)(void);
|
||||
} DiscoveryImpl;
|
||||
|
||||
static DiscoveryImpl g_discoveryImpl[LNN_DISC_IMPL_TYPE_MAX] = {
|
||||
[LNN_DISC_IMPL_TYPE_COAP] = {
|
||||
.InitDiscoveryImpl = LnnInitCoapDiscovery,
|
||||
.StartDiscoveryImpl = LnnStartCoapDiscovery,
|
||||
.StopDiscoveryImpl = LnnStopCoapDiscovery,
|
||||
},
|
||||
};
|
||||
|
||||
@ -56,6 +65,22 @@ static void DeviceFound(const ConnectionAddr *addr)
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t RestartPublish(void)
|
||||
{
|
||||
PublishInnerInfo publishInfo = {
|
||||
.publishId = LNN_PUBLISH_ID,
|
||||
.medium = COAP,
|
||||
.freq = HIGH,
|
||||
.capability = LNN_DISC_CAPABILITY,
|
||||
.capabilityData = (unsigned char *)LNN_DISC_CAPABILITY,
|
||||
.dataLen = strlen(LNN_DISC_CAPABILITY) + 1,
|
||||
};
|
||||
if (DiscStartScan(MODULE_LNN, &publishInfo) != SOFTBUS_OK) {
|
||||
LOG_ERR("DiscStartScan failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
int32_t LnnInitDiscoveryManager(void)
|
||||
{
|
||||
uint32_t i;
|
||||
@ -70,4 +95,40 @@ int32_t LnnInitDiscoveryManager(void)
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t LnnStartDiscovery(void)
|
||||
{
|
||||
uint32_t i;
|
||||
RestartPublish();
|
||||
for (i = 0; i < LNN_DISC_IMPL_TYPE_MAX; ++i) {
|
||||
if (g_discoveryImpl[i].StartDiscoveryImpl == NULL) {
|
||||
LOG_ERR("not support discovery");
|
||||
continue;
|
||||
}
|
||||
if (g_discoveryImpl[i].StartDiscoveryImpl() != SOFTBUS_OK) {
|
||||
LOG_ERR("init discovery impl(%d) failed", i);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
int32_t LnnStopDiscovery(void)
|
||||
{
|
||||
uint32_t i;
|
||||
if (DiscUnpublish(MODULE_LNN, LNN_PUBLISH_ID) != SOFTBUS_OK) {
|
||||
LOG_ERR("DiscUnpublish fail!");
|
||||
}
|
||||
for (i = 0; i < LNN_DISC_IMPL_TYPE_MAX; ++i) {
|
||||
if (g_discoveryImpl[i].StopDiscoveryImpl == NULL) {
|
||||
LOG_ERR("not support discovery");
|
||||
continue;
|
||||
}
|
||||
if (g_discoveryImpl[i].StopDiscoveryImpl() != SOFTBUS_OK) {
|
||||
LOG_ERR("init discovery impl(%d) failed", i);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
104
core/bus_center/lnn/net_buscenter/BUILD.gn
Executable file
104
core/bus_center/lnn/net_buscenter/BUILD.gn
Executable file
@ -0,0 +1,104 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//foundation/communication/dsoftbus/dsoftbus.gni")
|
||||
|
||||
config("bus_center_center_interface") {
|
||||
include_dirs = [
|
||||
"include",
|
||||
"$dsoftbus_root_path/interfaces/kits",
|
||||
"$dsoftbus_root_path/interfaces/kits/bus_center",
|
||||
"$dsoftbus_root_path/interfaces/kits/common",
|
||||
]
|
||||
}
|
||||
if (defined(ohos_lite)) {
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
} else {
|
||||
shared_library("dsoftbus_bus_center_center") {
|
||||
sources = [
|
||||
"src/lnn_network_manager.c",
|
||||
"src/lnn_ip_network_impl.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct/include",
|
||||
"$dsoftbus_root_path/core/common/include",
|
||||
"$dsoftbus_root_path/core/connection/interface",
|
||||
"$dsoftbus_root_path/interfaces/kits/discovery",
|
||||
"$dsoftbus_root_path/core/discovery/interface",
|
||||
"//third_party/bounds_checking_function/include",
|
||||
"$hilog_lite_include_path",
|
||||
]
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-fPIC",
|
||||
"-fno-builtin",
|
||||
"-std=c99",
|
||||
]
|
||||
public_configs = [ ":bus_center_center_interface" ]
|
||||
deps = [
|
||||
"$dsoftbus_root_path/core/bus_center/utils:dsoftbus_bus_center_utils",
|
||||
"$dsoftbus_root_path/core/bus_center:dsoftbus_bus_center_server",
|
||||
"$dsoftbus_root_path/core/bus_center/monitor:dsoftbus_bus_center_monitor",
|
||||
"$dsoftbus_root_path/core/authentication:dsoftbus_auth_server",
|
||||
"$dsoftbus_root_path/core/connection:softbus_connection",
|
||||
"$dsoftbus_root_path/core/discovery:dsoftbus_disc_server",
|
||||
"$dsoftbus_root_path/core/transmission/session:dsoftbus_trans_session",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/proxy:dsoftbus_trans_proxy_channel",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct:dsoftbus_trans_direct_channel",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger:dsoftbus_bus_center_ledger",
|
||||
"//build/lite/config/component/cJSON:cjson_shared",
|
||||
"$hilog_lite_deps_path",
|
||||
]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_shared_library("dsoftbus_bus_center_center") {
|
||||
sources = [
|
||||
"src/lnn_network_manager.c",
|
||||
"src/lnn_ip_network_impl.c",
|
||||
]
|
||||
include_dirs = [
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct/include",
|
||||
"$dsoftbus_root_path/core/common/include",
|
||||
"$dsoftbus_root_path/core/connection/interface",
|
||||
"$dsoftbus_root_path/interfaces/kits/discovery",
|
||||
"$dsoftbus_root_path/core/discovery/interface",
|
||||
]
|
||||
|
||||
public_configs = [ ":bus_center_center_interface" ]
|
||||
deps = [
|
||||
"$dsoftbus_root_path/core/bus_center/utils:dsoftbus_bus_center_utils",
|
||||
"$dsoftbus_root_path/core/bus_center:dsoftbus_bus_center_server",
|
||||
"$dsoftbus_root_path/core/bus_center/monitor:dsoftbus_bus_center_monitor",
|
||||
"$dsoftbus_root_path/core/authentication:dsoftbus_auth_server",
|
||||
"$dsoftbus_root_path/core/connection:softbus_connection",
|
||||
"$dsoftbus_root_path/core/discovery:dsoftbus_disc_server",
|
||||
"$dsoftbus_root_path/core/transmission/session:dsoftbus_trans_session",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/proxy:dsoftbus_trans_proxy_channel",
|
||||
"$dsoftbus_root_path/core/transmission/trans_channel/tcp_direct:dsoftbus_trans_direct_channel",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger:dsoftbus_bus_center_ledger",
|
||||
"//utils/native/base:utilsecurec_shared",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
}
|
||||
part_name = "dsoftbus_standard"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
}
|
37
core/bus_center/lnn/net_buscenter/include/lnn_network_manager.h
Executable file
37
core/bus_center/lnn/net_buscenter/include/lnn_network_manager.h
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef LNN_NETWORK_MANAGER_H
|
||||
#define LNN_NETWORK_MANAGER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int32_t LnnInitNetworkManager(void);
|
||||
|
||||
int32_t __attribute__ ((weak)) LnnInitIpNetwork(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#endif /* LNN_NETWORK_MANAGER_H */
|
254
core/bus_center/lnn/net_buscenter/src/lnn_ip_network_impl.c
Executable file
254
core/bus_center/lnn/net_buscenter/src/lnn_ip_network_impl.c
Executable file
@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_network_manager.h"
|
||||
|
||||
#include <securec.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "auth_interface.h"
|
||||
#include "bus_center_info_key.h"
|
||||
#include "bus_center_manager.h"
|
||||
#include "disc_interface.h"
|
||||
#include "lnn_discovery_manager.h"
|
||||
#include "lnn_event_monitor.h"
|
||||
#include "lnn_ip_utils.h"
|
||||
#include "softbus_def.h"
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
#include "trans_tcp_direct_listener.h"
|
||||
|
||||
#define IP_DEFAULT_PORT 0
|
||||
|
||||
static int32_t OpenAuthPort(void)
|
||||
{
|
||||
int32_t port = OpenAuthServer();
|
||||
if (port < 0) {
|
||||
LOG_ERR("open auth server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return LnnSetLocalNumInfo(NUM_KEY_AUTH_PORT, port);
|
||||
}
|
||||
|
||||
static void CloseAuthPort(void)
|
||||
{
|
||||
CloseAuthServer();
|
||||
(void)LnnSetLocalNumInfo(NUM_KEY_AUTH_PORT, IP_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
static int32_t OpenSessionPort(void)
|
||||
{
|
||||
char ipAddr[IP_LEN] = {0};
|
||||
int32_t port;
|
||||
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr, IP_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ip failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
port = TransTdcStartSessionListener(ipAddr, 0);
|
||||
if (port < 0) {
|
||||
LOG_ERR("open session server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return LnnSetLocalNumInfo(NUM_KEY_SESSION_PORT, port);
|
||||
}
|
||||
|
||||
static void CloseSessionPort(void)
|
||||
{
|
||||
TransTdcStopSessionListener();
|
||||
(void)LnnSetLocalNumInfo(NUM_KEY_SESSION_PORT, IP_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
static int32_t OpenProxyPort(void)
|
||||
{
|
||||
LocalListenerInfo listenerInfo = {0};
|
||||
char ipAddr[IP_LEN] = {0};
|
||||
int32_t port;
|
||||
|
||||
listenerInfo.type = CONNECT_TCP;
|
||||
listenerInfo.info.ipListenerInfo.port = 0;
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr, IP_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ip failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (strncpy_s(listenerInfo.info.ipListenerInfo.ip, IP_LEN, ipAddr, strlen(ipAddr)) != EOK) {
|
||||
LOG_ERR("copy ip failed");
|
||||
return SOFTBUS_MEM_ERR;
|
||||
}
|
||||
port = ConnStartLocalListening(&listenerInfo);
|
||||
if (port < 0) {
|
||||
LOG_ERR("open proxy server failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return LnnSetLocalNumInfo(NUM_KEY_PROXY_PORT, port);
|
||||
}
|
||||
|
||||
static void CloseProxyPort(void)
|
||||
{
|
||||
LocalListenerInfo listenerInfo = {0};
|
||||
listenerInfo.type = CONNECT_TCP;
|
||||
if (ConnStopLocalListening(&listenerInfo) != SOFTBUS_OK) {
|
||||
LOG_ERR("ConnStopLocalListening fail!");
|
||||
}
|
||||
(void)LnnSetLocalNumInfo(NUM_KEY_PROXY_PORT, IP_DEFAULT_PORT);
|
||||
}
|
||||
|
||||
static int32_t OpenIpLink(void)
|
||||
{
|
||||
int32_t ret = OpenAuthPort();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG_ERR("OpenAuthPort fail!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ret = OpenSessionPort();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG_ERR("OpenSessionPort fail!");
|
||||
CloseAuthPort();
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
ret = OpenProxyPort();
|
||||
if (ret != SOFTBUS_OK) {
|
||||
LOG_ERR("OpenProxyPort fail!");
|
||||
CloseAuthPort();
|
||||
CloseSessionPort();
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void CloseIpLink(void)
|
||||
{
|
||||
CloseAuthPort();
|
||||
CloseSessionPort();
|
||||
CloseProxyPort();
|
||||
}
|
||||
|
||||
static int32_t SetLocalIpInfo(char *ipAddr, char *ifName)
|
||||
{
|
||||
if (LnnSetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ip error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LnnSetLocalStrInfo(STRING_KEY_NET_IF_NAME, ifName) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ifname error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetLocalIpInfo(char *ipAddr, uint32_t ipAddrLen, char *ifName, uint32_t ifNameLen)
|
||||
{
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_WLAN_IP, ipAddr, ipAddrLen) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ip error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LnnGetLocalStrInfo(STRING_KEY_NET_IF_NAME, ifName, ifNameLen) != SOFTBUS_OK) {
|
||||
LOG_ERR("get local ifname error!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static int32_t GetUpdateLocalIp(char *ipAddr, uint32_t ipAddrLen, char *ifName, uint32_t ifNameLen)
|
||||
{
|
||||
if (LnnGetLocalIp(ipAddr, ipAddrLen, ifName, ifNameLen, CONNECTION_ADDR_ETH) == SOFTBUS_OK) {
|
||||
LOG_INFO("get eth ip success");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (LnnGetLocalIp(ipAddr, ipAddrLen, ifName, ifNameLen, CONNECTION_ADDR_WLAN) == SOFTBUS_OK) {
|
||||
LOG_INFO("get wlan ip success");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
if (strncpy_s(ipAddr, ipAddrLen, LNN_LOOPBACK_IP, strlen(LNN_LOOPBACK_IP)) != EOK) {
|
||||
LOG_ERR("copy loopback ip addr failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (strncpy_s(ifName, ifNameLen, LNN_LOOPBACK_IFNAME, strlen(LNN_LOOPBACK_IFNAME)) != EOK) {
|
||||
LOG_ERR("copy loopback ifname failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
LOG_INFO("set loopback ip as default");
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void IpAddrChangeEventHandler(LnnMonitorEventType event, const void *para)
|
||||
{
|
||||
char ipCurrentAddr[IP_LEN] = {0};
|
||||
char ifCurrentName[NET_IF_NAME_LEN] = {0};
|
||||
char ipNewAddr[IP_LEN] = {0};
|
||||
char ifNewName[NET_IF_NAME_LEN] = {0};
|
||||
|
||||
(void)para;
|
||||
if (event != LNN_MONITOR_EVENT_IP_ADDR_CHANGED) {
|
||||
LOG_ERR("not interest event: %d", event);
|
||||
return;
|
||||
}
|
||||
if (GetLocalIpInfo(ipCurrentAddr, IP_LEN, ifCurrentName, NET_IF_NAME_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get current ip info failed");
|
||||
return;
|
||||
}
|
||||
if (GetUpdateLocalIp(ipNewAddr, IP_LEN, ifNewName, NET_IF_NAME_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get new ip info failed");
|
||||
return;
|
||||
}
|
||||
if (strcmp(ipCurrentAddr, ipNewAddr) == 0 && strcmp(ifCurrentName, ifNewName) == 0) {
|
||||
LOG_INFO("ip info not changed");
|
||||
return;
|
||||
}
|
||||
LOG_INFO("ip info changed, update local ledger");
|
||||
if (SetLocalIpInfo(ipNewAddr, ifNewName) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ip info failed");
|
||||
return;
|
||||
}
|
||||
if (strncmp(ifCurrentName, LNN_LOOPBACK_IFNAME, strlen(LNN_LOOPBACK_IFNAME)) != 0) {
|
||||
LOG_INFO("close previous ip link and stop previous discovery");
|
||||
CloseIpLink();
|
||||
LnnStopDiscovery();
|
||||
}
|
||||
if (strncmp(ifNewName, LNN_LOOPBACK_IFNAME, strlen(LNN_LOOPBACK_IFNAME)) != 0) {
|
||||
LOG_INFO("open ip link and start discovery");
|
||||
DiscLinkStatusChanged(LINK_STATUS_UP, COAP);
|
||||
if (OpenIpLink() != SOFTBUS_OK) {
|
||||
LOG_ERR("open ip link failed");
|
||||
}
|
||||
if (LnnStartDiscovery() != SOFTBUS_OK) {
|
||||
LOG_ERR("start discovery failed");
|
||||
}
|
||||
SetCallLnnStatus(true);
|
||||
} else {
|
||||
DiscLinkStatusChanged(LINK_STATUS_DOWN, COAP);
|
||||
AuthIpChanged(CONNECT_TCP);
|
||||
}
|
||||
}
|
||||
|
||||
int32_t LnnInitIpNetwork(void)
|
||||
{
|
||||
char ipAddr[IP_LEN] = {0};
|
||||
char ifName[NET_IF_NAME_LEN] = {0};
|
||||
|
||||
if (LnnRegisterEventHandler(LNN_MONITOR_EVENT_IP_ADDR_CHANGED, IpAddrChangeEventHandler) != SOFTBUS_OK) {
|
||||
LOG_ERR("register ip addr change event handler failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (GetUpdateLocalIp(ipAddr, IP_LEN, ifName, NET_IF_NAME_LEN) != SOFTBUS_OK) {
|
||||
LOG_ERR("get new ip info failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (SetLocalIpInfo(ipAddr, ifName) != SOFTBUS_OK) {
|
||||
LOG_ERR("set local ip info failed");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
50
core/bus_center/lnn/net_buscenter/src/lnn_network_manager.c
Executable file
50
core/bus_center/lnn/net_buscenter/src/lnn_network_manager.c
Executable file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "lnn_network_manager.h"
|
||||
|
||||
#include "softbus_errcode.h"
|
||||
#include "softbus_log.h"
|
||||
|
||||
typedef enum {
|
||||
LNN_NETWORK_IMPL_TYPE_IP,
|
||||
LNN_NETWORK_IMPL_TYPE_MAX,
|
||||
} LnnNetworkImplType;
|
||||
|
||||
typedef struct {
|
||||
int32_t (*InitNetworkImpl)(void);
|
||||
} NetworkImpl;
|
||||
|
||||
static NetworkImpl g_networkImpl[LNN_NETWORK_IMPL_TYPE_MAX] = {
|
||||
[LNN_NETWORK_IMPL_TYPE_IP] = {
|
||||
.InitNetworkImpl = LnnInitIpNetwork,
|
||||
},
|
||||
};
|
||||
|
||||
int32_t LnnInitNetworkManager(void)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < LNN_NETWORK_IMPL_TYPE_MAX; ++i) {
|
||||
if (g_networkImpl[i].InitNetworkImpl == NULL) {
|
||||
continue;
|
||||
}
|
||||
if (g_networkImpl[i].InitNetworkImpl() != SOFTBUS_OK) {
|
||||
LOG_ERR("init network impl(%d) failed", i);
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
}
|
||||
return SOFTBUS_OK;
|
||||
}
|
83
core/bus_center/service/BUILD.gn
Executable file
83
core/bus_center/service/BUILD.gn
Executable file
@ -0,0 +1,83 @@
|
||||
# Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//foundation/communication/dsoftbus/dsoftbus.gni")
|
||||
|
||||
if (defined(ohos_lite)) {
|
||||
import("//build/lite/config/component/lite_component.gni")
|
||||
if (ohos_kernel_type == "liteos_m") {
|
||||
} else {
|
||||
shared_library("dsoftbus_bus_center_service") {
|
||||
sources = [ "src/bus_center_manager.c" ]
|
||||
include_dirs = [
|
||||
"$dsoftbus_root_path/core/adapter/bus_center/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/sync_info/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/local_ledger/include",
|
||||
"$dsoftbus_root_path/core/common/include",
|
||||
"$hilog_lite_include_path",
|
||||
]
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-fPIC",
|
||||
"-fno-builtin",
|
||||
"-std=c99",
|
||||
]
|
||||
deps = [
|
||||
"$dsoftbus_root_path/core/adapter/bus_center:softbus_adapter_bus_center",
|
||||
"$dsoftbus_root_path/core/authentication:dsoftbus_auth_server",
|
||||
"$dsoftbus_root_path/core/bus_center:dsoftbus_bus_center_server",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger:dsoftbus_bus_center_ledger",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager:dsoftbus_bus_center_hub",
|
||||
"$dsoftbus_root_path/core/bus_center/utils:dsoftbus_bus_center_utils",
|
||||
"$dsoftbus_root_path/core/bus_center/monitor:dsoftbus_bus_center_monitor",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter:dsoftbus_bus_center_center",
|
||||
"$hilog_lite_deps_path",
|
||||
]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
import("//build/ohos.gni")
|
||||
|
||||
ohos_shared_library("dsoftbus_bus_center_service") {
|
||||
sources = [ "src/bus_center_manager.c" ]
|
||||
include_dirs = [
|
||||
"$dsoftbus_root_path/core/adapter/bus_center/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_builder/sync_info/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/common/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/distributed_ledger/include",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger/local_ledger/include",
|
||||
"$dsoftbus_root_path/core/common/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"$dsoftbus_root_path/core/adapter/bus_center:softbus_adapter_bus_center",
|
||||
"$dsoftbus_root_path/core/authentication:dsoftbus_auth_server",
|
||||
"$dsoftbus_root_path/core/bus_center:dsoftbus_bus_center_server",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_ledger:dsoftbus_bus_center_ledger",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/lane_hub/lane_manager:dsoftbus_bus_center_hub",
|
||||
"$dsoftbus_root_path/core/bus_center/utils:dsoftbus_bus_center_utils",
|
||||
"$dsoftbus_root_path/core/bus_center/monitor:dsoftbus_bus_center_monitor",
|
||||
"$dsoftbus_root_path/core/bus_center/lnn/net_buscenter:dsoftbus_bus_center_center",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps = [ "hiviewdfx_hilog_native:libhilog" ]
|
||||
}
|
||||
part_name = "dsoftbus_standard"
|
||||
subsystem_name = "communication"
|
||||
}
|
||||
}
|
@ -18,6 +18,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lnn_network_manager.h"
|
||||
#include "lnn_discovery_manager.h"
|
||||
#include "lnn_distributed_net_ledger.h"
|
||||
#include "lnn_event_monitor.h"
|
||||
@ -55,6 +56,10 @@ int32_t BusCenterServerInit(void)
|
||||
LOG_ERR("init lnn discovery manager fail!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LnnInitNetworkManager() != SOFTBUS_OK) {
|
||||
LOG_ERR("init lnn network manager fail!");
|
||||
return SOFTBUS_ERR;
|
||||
}
|
||||
if (LnnInitNetBuilder() != SOFTBUS_OK) {
|
||||
LOG_ERR("init net builder fail!");
|
||||
return SOFTBUS_ERR;
|
||||
|
@ -97,6 +97,7 @@ if (ohos_kernel_type == "liteos_m") {
|
||||
"$hilog_lite_deps_path",
|
||||
"//foundation/communication/ipc_lite:liteipc_adapter",
|
||||
"//foundation/distributedschedule/samgr_lite/samgr:samgr",
|
||||
"$dsoftbus_root_path/core/bus_center/service:dsoftbus_bus_center_service",
|
||||
]
|
||||
}
|
||||
executable("softbus_server") {
|
||||
|
@ -60,6 +60,7 @@ ohos_shared_library("softbus_server") {
|
||||
"$dsoftbus_root_path/core/transmission/session:dsoftbus_trans_session",
|
||||
"$dsoftbus_root_path/core/common/softbus_property:softbus_property",
|
||||
"//utils/native/base:utils",
|
||||
"$dsoftbus_root_path/core/bus_center/service:dsoftbus_bus_center_service",
|
||||
]
|
||||
if (is_standard_system) {
|
||||
external_deps = [
|
||||
|
@ -541,7 +541,7 @@ int32_t TransCloseUdpChannel(int32_t channelId)
|
||||
return SOFTBUS_OK;
|
||||
}
|
||||
|
||||
static void UdpModuleCb(int64_t authId, const ConnectOption *option, AuthTransDataInfo *info)
|
||||
static void UdpModuleCb(int64_t authId, const ConnectOption *option, const AuthTransDataInfo *info)
|
||||
{
|
||||
SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "udp module callback enter.");
|
||||
if (option == NULL || info == NULL) {
|
||||
|
@ -92,6 +92,13 @@ extern "C" {
|
||||
* @version 1.0
|
||||
*/
|
||||
#define IP_STR_MAX_LEN 46
|
||||
|
||||
/**
|
||||
* @brief Indicates the maximum length of the account hash code in <b>IDiscoveryCallback</b>.
|
||||
*
|
||||
*/
|
||||
#define MAX_ACCOUNT_HASH_LEN 96
|
||||
|
||||
/**
|
||||
* @brief Enumerates {@link ConnectionAddr} types of a device that is added to a LNN.
|
||||
*
|
||||
@ -135,6 +142,7 @@ typedef struct {
|
||||
uint16_t port; /**< Port number represented by the host byte order */
|
||||
} ip;
|
||||
} info;
|
||||
char peerUid[MAX_ACCOUNT_HASH_LEN];
|
||||
} ConnectionAddr;
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -38,12 +38,6 @@ extern "C" {
|
||||
*/
|
||||
#define DISC_MAX_DEVICE_ID_LEN 96
|
||||
|
||||
/**
|
||||
* @brief Indicates the maximum length of the account hash code in <b>IDiscoveryCallback</b>.
|
||||
*
|
||||
*/
|
||||
#define DISC_MAX_ACCOUNT_HASH_LEN 96
|
||||
|
||||
/**
|
||||
* @brief Indicates the maximum length of the device name in <b>IDiscoveryCallback</b>.
|
||||
*
|
||||
@ -279,8 +273,8 @@ typedef enum {
|
||||
typedef struct {
|
||||
/** Device ID. Its maximum length is specified by {@link DISC_MAX_DEVICE_ID_LEN}. */
|
||||
char devId[DISC_MAX_DEVICE_ID_LEN];
|
||||
/** Account hash code. Its maximum length is specified by {@link DISC_MAX_ACCOUNT_HASH_LEN}. */
|
||||
char hwAccountHash[DISC_MAX_ACCOUNT_HASH_LEN];
|
||||
/** Account hash code. Its maximum length is specified by {@link MAX_ACCOUNT_HASH_LEN}. */
|
||||
char hwAccountHash[MAX_ACCOUNT_HASH_LEN];
|
||||
/** Device type. For details, see {@link DeviceType}. */
|
||||
DeviceType devType;
|
||||
/** Device name. Its maximum length is specified by {@link DISC_MAX_DEVICE_NAME_LEN}. */
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define TYPE_SEND_BYTE 15
|
||||
#define TYPE_SEND_MESSAGE 16
|
||||
#define SLEEP_TIME 15
|
||||
#define TRANS_UINIT_SIZE 1024
|
||||
#define TRANS_SIZE_NUM 2
|
||||
#define TRANS_SIZE_NUM_DOUBLE 4
|
||||
#define LOOP_COUNT 10
|
||||
@ -292,7 +293,7 @@ void TransFuncTest001(void)
|
||||
void TransFuncTest002(void)
|
||||
{
|
||||
int ret;
|
||||
int size = TRANS_SIZE_NUM * 1024;
|
||||
int size = TRANS_SIZE_NUM * TRANS_UINIT_SIZE;
|
||||
|
||||
ret = CreateSsAndOpenSession();
|
||||
TEST_ASSERT_TRUE(ret == 0);
|
||||
@ -312,7 +313,7 @@ void TransFuncTest002(void)
|
||||
void TransFuncTest003(void)
|
||||
{
|
||||
int ret;
|
||||
int size = TRANS_SIZE_NUM_DOUBLE * 1024;
|
||||
int size = TRANS_SIZE_NUM_DOUBLE * TRANS_UINIT_SIZE;
|
||||
|
||||
ret = CreateSsAndOpenSession();
|
||||
TEST_ASSERT_TRUE(ret == 0);
|
||||
@ -352,7 +353,7 @@ void TransFuncTest004(void)
|
||||
void TransFuncTest005(void)
|
||||
{
|
||||
int ret;
|
||||
int size = 1024;
|
||||
int size = TRANS_UINIT_SIZE;
|
||||
|
||||
ret = CreateSsAndOpenSession();
|
||||
TEST_ASSERT_TRUE(ret == 0);
|
||||
|
Loading…
Reference in New Issue
Block a user