1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef LNN_NETWORK_MANAGER_H 17 #define LNN_NETWORK_MANAGER_H 18 19 #include "bus_center_info_key.h" 20 #include "softbus_conn_interface.h" 21 22 #ifdef __cplusplus 23 #if __cplusplus 24 extern "C" { 25 #endif 26 #endif 27 28 #define LNN_LOOPBACK_IFNAME "lo" 29 30 // netif type 31 #define LNN_NETIF_TYPE_ETH (0x1) 32 #define LNN_NETIF_TYPE_WLAN (0x1 << 1) 33 #define LNN_NETIF_TYPE_BR (0x1 << 2) 34 #define LNN_NETIF_TYPE_BLE (0x1 << 3) 35 typedef uint16_t LnnNetIfType; 36 37 #define LNN_NETWORK_MAX_PROTOCOL_COUNT 3 38 39 typedef struct { 40 ListNode node; 41 LnnNetIfType type; 42 char ifName[NET_IF_NAME_LEN]; 43 } LnnNetIfMgr; 44 45 typedef LnnNetIfMgr *(*LnnNetIfManagerBuilder)(const char *ifName); 46 47 typedef enum { 48 CHOICE_VISIT_NEXT, 49 CHOICE_FINISH_VISITING 50 } VisitNextChoice; 51 52 typedef VisitNextChoice (*VisitNetifCallback)(const LnnNetIfMgr *, void *); 53 54 typedef enum { 55 LNN_LISTENER_MODE_PROXY, 56 LNN_LISTENER_MODE_DIRECT, 57 LNN_LISTENER_MODE_AUTH 58 } ListenerMode; 59 60 typedef struct LnnProtocolManager { 61 int32_t (*init)(struct LnnProtocolManager *self); 62 void (*deinit)(struct LnnProtocolManager *self); 63 int32_t (*enable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); 64 int32_t (*disable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); 65 ListenerModule (*getListenerModule)(ListenerMode mode); 66 ProtocolType id; 67 LnnNetIfType supportedNetif; 68 uint16_t pri; 69 } LnnProtocolManager; 70 71 typedef VisitNextChoice (*VisitProtocolCallback)(const LnnProtocolManager *, void *); 72 73 int32_t LnnRegistProtocol(LnnProtocolManager *impl); 74 75 int32_t LnnInitNetworkManager(void); 76 int32_t LnnInitNetworkManagerDelay(void); 77 void LnnDeinitNetworkManager(void); 78 79 int32_t LnnGetNetIfTypeByName(const char *ifName, LnnNetIfType *type); 80 int32_t LnnGetAddrTypeByIfName(const char *ifName, ConnectionAddrType *type); 81 82 ListenerModule LnnGetProtocolListenerModule(ProtocolType protocol, ListenerMode mode); 83 84 void RestartCoapDiscovery(void); 85 bool LnnIsAutoNetWorkingEnabled(void); 86 87 bool LnnVisitNetif(VisitNetifCallback callback, void *data); 88 bool LnnVisitProtocol(VisitProtocolCallback callback, void *data); 89 int32_t RegistIPProtocolManager(void); 90 void LnnSetUnlockState(void); 91 void LnnGetDataShareInitResult(bool *isDataShareInit); 92 93 #ifdef __cplusplus 94 #if __cplusplus 95 } 96 #endif /* __cplusplus */ 97 #endif /* __cplusplus */ 98 99 #endif /* LNN_NETWORK_MANAGER_H */ 100