• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 } ListenerMode;
64 
65 typedef struct LnnProtocolManager {
66     int32_t (*Init)(struct LnnProtocolManager *self);
67     void (*Deinit)(struct LnnProtocolManager *self);
68     int32_t (*Enable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr);
69     int32_t (*Disable)(struct LnnProtocolManager *self, LnnNetIfMgr *netifMgr);
70     ListenerModule (*GetListenerModule)(ListenerMode mode);
71     ProtocolType id;
72     LnnNetIfType supportedNetif;
73     uint16_t pri;
74 } LnnProtocolManager;
75 
76 typedef VisitNextChoice (*VisitProtocolCallback)(const LnnProtocolManager *, void *);
77 
78 int32_t LnnRegistProtocol(LnnProtocolManager *impl);
79 
80 int32_t LnnInitNetworkManager(void);
81 int32_t LnnInitNetworkManagerDelay(void);
82 void LnnDeinitNetworkManager(void);
83 
84 int32_t LnnGetNetIfTypeByName(const char *ifName, LnnNetIfType *type);
85 int32_t LnnGetAddrTypeByIfName(const char *ifName, ConnectionAddrType *type);
86 
87 ListenerModule LnnGetProtocolListenerModule(ProtocolType protocol, ListenerMode mode);
88 
89 bool LnnIsAutoNetWorkingEnabled(void);
90 
91 bool LnnVisitNetif(VisitNetifCallback callback, void *data);
92 bool LnnVisitProtocol(VisitProtocolCallback callback, void *data);
93 
94 #ifdef __cplusplus
95 #if __cplusplus
96 }
97 #endif /* __cplusplus */
98 #endif /* __cplusplus */
99 
100 #endif /* LNN_NETWORK_MANAGER_H */
101