1 /*
2  * Copyright (c) 2022 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_SUBNET_MANAGER_H
17 #define LNN_SUBNET_MANAGER_H
18 
19 #include "lnn_network_manager.h"
20 #include "stdint.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif
27 #define LNN_PHYSICAL_SUBNET_ALL_NETIF "*"
28 
29 typedef enum {
30     LNN_SUBNET_IDLE, // can be enable
31     LNN_SUBNET_RUNNING,
32     LNN_SUBNET_SHUTDOWN, // will not be auto enable
33     LNN_SUBNET_RESETTING, // Will be auto enable in high pri
34     LNN_SUBNET_STATUS_MAX
35 } LnnPhysicalSubnetStatus;
36 
37 typedef struct LnnPhysicalSubnet {
38     char ifName[NET_IF_NAME_LEN];
39     const LnnProtocolManager *protocol;
40     LnnPhysicalSubnetStatus status;
41     void (*destroy)(struct LnnPhysicalSubnet *);
42     void (*onNetifStatusChanged)(struct LnnPhysicalSubnet *, void *status);
43     void (*onSoftbusNetworkDisconnected)(struct LnnPhysicalSubnet *);
44 } LnnPhysicalSubnet;
45 
46 typedef int16_t PhysicalSubnetId;
47 #define PHYSICAL_SUBNET_ID_NOT_EXIST (-1)
48 
49 int32_t LnnInitPhysicalSubnetManager(void);
50 
51 void LnnDeinitPhysicalSubnetManager(void);
52 
53 int32_t LnnRegistPhysicalSubnet(LnnPhysicalSubnet *manager);
54 
55 int32_t LnnUnregistPhysicalSubnetByType(ProtocolType type);
56 
57 void LnnNotifyPhysicalSubnetStatusChanged(const char *ifName, ProtocolType type, void *status);
58 
59 typedef VisitNextChoice (*LnnVisitPhysicalSubnetCallback)(const LnnPhysicalSubnet *, void *);
60 bool LnnVisitPhysicalSubnet(LnnVisitPhysicalSubnetCallback callback, void *data);
61 
62 void LnnNotifyAllTypeOffline(ConnectionAddrType type);
63 
64 #ifdef __cplusplus
65 #if __cplusplus
66 }
67 #endif
68 #endif
69 
70 #endif