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 <stdbool.h> 20 #include <stdint.h> 21 22 #include "bus_center_info_key.h" 23 #include "common_list.h" 24 #include "softbus_bus_center.h" 25 #include "softbus_conn_interface.h" 26 #include "softbus_protocol_def.h" 27 28 #ifdef __cplusplus 29 #if __cplusplus 30 extern "C" { 31 #endif 32 #endif 33 34 #define LNN_LOOPBACK_IFNAME "lo" 35 36 // netif type 37 #define LNN_NETIF_TYPE_ETH (0x1) 38 #define LNN_NETIF_TYPE_WLAN (0x1 << 1) 39 #define LNN_NETIF_TYPE_BR (0x1 << 2) 40 #define LNN_NETIF_TYPE_BLE (0x1 << 3) 41 typedef uint16_t LnnNetIfType; 42 43 #define LNN_NETWORK_MAX_PROTOCOL_COUNT 3 44 45 typedef struct { 46 ListNode node; 47 LnnNetIfType type; 48 char ifName[NET_IF_NAME_LEN]; 49 } LnnNetIfMgr; 50 51 typedef LnnNetIfMgr *(*LnnNetIfManagerBuilder)(const char *ifName); 52 53 typedef enum { 54 CHOICE_VISIT_NEXT, 55 CHOICE_FINISH_VISITING 56 } VisitNextChoice; 57 58 typedef VisitNextChoice (*VisitNetifCallback)(const LnnNetIfMgr *, void *); 59 60 typedef enum { 61 LNN_LISTENER_MODE_PROXY, 62 LNN_LISTENER_MODE_DIRECT, 63 LNN_LISTENER_MODE_AUTH 64 } ListenerMode; 65 66 typedef struct LnnProtocolManager { 67 int32_t (*init)(struct LnnProtocolManager *self); 68 void (*deinit)(struct LnnProtocolManager *self); 69 int32_t (*enable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); 70 int32_t (*disable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr); 71 ListenerModule (*getListenerModule)(ListenerMode mode); 72 ProtocolType id; 73 LnnNetIfType supportedNetif; 74 uint16_t pri; 75 } LnnProtocolManager; 76 77 typedef VisitNextChoice (*VisitProtocolCallback)(const LnnProtocolManager *, void *); 78 79 int32_t LnnRegistProtocol(LnnProtocolManager *impl); 80 81 int32_t LnnInitNetworkManager(void); 82 int32_t LnnInitNetworkManagerDelay(void); 83 void LnnDeinitNetworkManager(void); 84 85 int32_t LnnGetNetIfTypeByName(const char *ifName, LnnNetIfType *type); 86 int32_t LnnGetAddrTypeByIfName(const char *ifName, ConnectionAddrType *type); 87 88 ListenerModule LnnGetProtocolListenerModule(ProtocolType protocol, ListenerMode mode); 89 90 void RestartCoapDiscovery(void); 91 bool LnnIsAutoNetWorkingEnabled(void); 92 93 bool LnnVisitNetif(VisitNetifCallback callback, void *data); 94 bool LnnVisitProtocol(VisitProtocolCallback callback, void *data); 95 int32_t RegistIPProtocolManager(void); 96 void LnnSetUnlockState(void); 97 98 #ifdef __cplusplus 99 #if __cplusplus 100 } 101 #endif /* __cplusplus */ 102 #endif /* __cplusplus */ 103 104 #endif /* LNN_NETWORK_MANAGER_H */ 105