1 /*
2  * Copyright (c) 2021-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 NETWORKSHARE_STATE_COMMMON_H
17 #define NETWORKSHARE_STATE_COMMMON_H
18 
19 #include "net_all_capabilities.h"
20 #include "net_handle.h"
21 #include "net_link_info.h"
22 
23 namespace OHOS {
24 namespace NetManagerStandard {
25 constexpr int CMD_NETSHARE_REQUESTED = 1;
26 constexpr int CMD_NETSHARE_UNREQUESTED = 2;
27 constexpr int CMD_INTERFACE_DOWN = 3;
28 constexpr int CMD_IP_FORWARDING_ENABLE_ERROR = 4;
29 constexpr int CMD_IP_FORWARDING_DISABLE_ERROR = 5;
30 constexpr int CMD_START_SHARING_ERROR = 6;
31 constexpr int CMD_STOP_SHARING_ERROR = 7;
32 constexpr int CMD_SET_DNS_FORWARDERS_ERROR = 8;
33 constexpr int CMD_NOTIFY_PREFIX_CONFLICT = 9;
34 constexpr int CMD_NEW_PREFIX_REQUEST = 10;
35 constexpr int CMD_NETSHARE_CONNECTION_CHANGED = 11;
36 constexpr int NETWORKSHARING_SHARING_NO_ERROR = 0;
37 
38 // interface sub statemachine has requested
39 constexpr int EVENT_IFACE_SM_STATE_ACTIVE = 20;
40 // interface sub statemachine has unrequested
41 constexpr int EVENT_IFACE_SM_STATE_INACTIVE = 21;
42 constexpr int EVENT_IFACE_UPDATE_LINKPROPERTIES = 22;
43 constexpr int EVENT_UPSTREAM_CALLBACK = 23;
44 // upstream connection change
45 constexpr int CMD_UPSTREAM_CHANGED = 24;
46 // has no valid upstream conn, check again after a delay
47 constexpr int CMD_RETRY_UPSTREAM = 25;
48 // after occur the error and want to clear it
49 constexpr int CMD_CLEAR_ERROR = 26;
50 
51 constexpr int SUB_SM_STATE_AVAILABLE = 0;
52 constexpr int SUB_SM_STATE_UNAVAILABLE = 1;
53 constexpr int SUB_SM_STATE_SHARED = 2;
54 
55 constexpr int EVENT_UPSTREAM_CALLBACK_ON_CAPABILITIES = 0;
56 constexpr int EVENT_UPSTREAM_CALLBACK_ON_LINKPROPERTIES = 1;
57 constexpr int EVENT_UPSTREAM_CALLBACK_ON_LOST = 2;
58 constexpr int EVENT_UPSTREAM_CALLBACK_DEFAULT_SWITCHED = 3;
59 constexpr int EVENT_UPSTREAM_CALLBACK_DEFAULT_SWITCHED_BY_LOST = 4;
60 constexpr int EVENT_UPSTREAM_CALLBACK_LOCAL_PREFIXES = 5;
61 
62 constexpr int32_t CALLBACK_DEFAULT_INTERNET_NETWORK = 1;
63 constexpr int32_t CALLBACK_LISTEN_ALL_NETWORK = 2;
64 constexpr int32_t CALLBACK_MOBILE_REQUEST_NETWORK = 3;
65 
66 // delayTime
67 constexpr int32_t HANDLER_DELAY_TIME_MS = 1000;    // 1 second
68 constexpr int32_t UPSTREAM_HANDLE_TIME_MS = 10000; // 10 second
69 
70 constexpr int32_t PREFIX_LENGTH_16 = 16;
71 constexpr int32_t PREFIX_LENGTH_24 = 24;
72 
73 constexpr int32_t SET_IFACE_UP_NULL = -1;
74 constexpr int32_t SET_IFACE_UP_TRUE = 1;
75 constexpr int32_t SET_IFACE_UP_FALSE = 0;
76 
77 constexpr int32_t SET_WIFI_DEFAULT_CHANNEL = 6;
78 constexpr int32_t SET_WIFI_MAX_CONNECT = 10;
79 
80 constexpr int NO_NEXT_STATE = -1;
81 enum { MAINSTATE_INIT = 1, MAINSTATE_ALIVE, MAINSTATE_ERROR, MAINSTATE_MAX } MainState;
82 
83 enum { SUBSTATE_INIT = 11, SUBSTATE_SHARED, SUBSTATE_RESTART, SUBSTATE_UNAVAILABLE, SUBSTATE_MAX } SubState;
84 
85 enum class TrafficType { TRAFFIC_RX = 1, TRAFFIC_TX = 2, TRAFFIC_ALL = 3 };
86 
87 struct UpstreamNetworkInfo {
88     sptr<NetHandle> netHandle_;
89     sptr<NetAllCapabilities> netAllCap_;
90     sptr<NetLinkInfo> netLinkPro_; // net link property
UpstreamNetworkInfoUpstreamNetworkInfo91     UpstreamNetworkInfo(sptr<NetHandle> &netHandle, sptr<NetAllCapabilities> &netcap, sptr<NetLinkInfo> &netlinkinfo)
92         : netHandle_(netHandle), netAllCap_(netcap), netLinkPro_(netlinkinfo)
93     {
94     }
95 };
96 } // namespace NetManagerStandard
97 } // namespace OHOS
98 #endif // NETWORKSHARE_STATE_COMMMON_H
99