• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_DHCP_DEFINE_H
17 #define OHOS_DHCP_DEFINE_H
18 
19 #include <string>
20 #include <cstdint>
21 #include <netinet/ip.h>
22 #include <sys/stat.h>
23 
24 namespace OHOS {
25 namespace Wifi {
26 const int ETH_MAC_ADDR_INDEX_0  = 0;
27 const int ETH_MAC_ADDR_INDEX_1  = 1;
28 const int ETH_MAC_ADDR_INDEX_2  = 2;
29 const int ETH_MAC_ADDR_INDEX_3  = 3;
30 const int ETH_MAC_ADDR_INDEX_4  = 4;
31 const int ETH_MAC_ADDR_INDEX_5  = 5;
32 const int ETH_MAC_ADDR_LEN      = 6;
33 const int ETH_MAC_ADDR_CHAR_NUM = 3;
34 const int IP_SIZE               = 18;
35 const int LEASETIME_DEFAULT     = 6;
36 const int ONE_HOURS_SEC         = 3600;
37 const int RECEIVER_TIMEOUT      = 6;
38 const int EVENT_DATA_NUM        = 11;
39 const int DHCP_NUM_ZERO         = 0;
40 const int DHCP_NUM_ONE          = 1;
41 const int DHCP_NUM_TWO          = 2;
42 const int DHCP_NUM_THREE        = 3;
43 const int DHCP_NUM_FOUR         = 4;
44 const int DHCP_NUM_FIVE         = 5;
45 const int DHCP_NUM_SIX          = 6;
46 const int DHCP_NUM_SEVEN        = 7;
47 const int DHCP_NUM_EIGHT        = 8;
48 const int DHCP_NUM_NINE         = 9;
49 const int DHCP_NUM_TEN          = 10;
50 const int DHCP_FILE_MAX_BYTES   = 128;
51 const int FILE_LINE_MAX_SIZE    = 1024;
52 const int DHCP_SER_ARGSNUM      = 6;
53 const int DHCP_CLI_ARGSNUM      = 5;
54 const int SLEEP_TIME_200_MS     = 200 * 1000;
55 const int SLEEP_TIME_500_MS     = 500 * 1000;
56 const int PID_MAX_LEN           = 16;
57 const int PARAM_MAX_SIZE        = 40;
58 const int DEFAULT_UMASK         = 027;
59 const int DIR_MAX_LEN           = 256;
60 const int DIR_DEFAULT_MODE      = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
61 const std::string IP4_SEPARATOR(".");
62 const std::string IP6_SEPARATOR(":");
63 const std::string INVALID_STRING("*");
64 const std::string EVENT_DATA_DELIMITER(",");
65 const std::string EVENT_DATA_IPV4("ipv4");
66 const std::string EVENT_DATA_IPV6("ipv6");
67 const std::string DHCP_WORK_DIR("/data/service/el1/public/dhcp/");
68 const std::string DHCP_CLIENT_PID_FILETYPE(".pid");
69 const std::string DHCP_RESULT_FILETYPE(".result");
70 #ifdef OHOS_ARCH_LITE
71 const std::string DHCP_CLIENT_FILE("/bin/dhcp_client_service");
72 const std::string DHCP_SERVER_FILE("/bin/dhcp_server");
73 #else
74 const std::string DHCP_CLIENT_FILE("/system/bin/dhcp_client_service");
75 const std::string DHCP_SERVER_FILE("/system/bin/dhcp_server");
76 #endif
77 const std::string DHCP_SERVER_CONFIG_FILE(DHCP_WORK_DIR + "etc/dhcpd.conf");
78 const std::string DHCP_SERVER_CONFIG_DIR(DHCP_WORK_DIR + "etc/");
79 const std::string DHCP_SERVER_LEASES_FILE(DHCP_WORK_DIR + "dhcpd_lease.lease");
80 const std::string DHCP_SERVER_CFG_IPV4("#ipv4");
81 const std::string DHCP_SERVER_CFG_IPV6("#ipv6");
82 const std::string COMMON_EVENT_DHCP_GET_IPV4 = "usual.event.wifi.dhcp.GET_IPV4";
83 const std::string IP_V4_MASK("255.255.255.0");
84 const std::string IP_V4_DEFAULT("192.168.1.2");
85 
86 typedef enum EnumErrCode {
87     /* success */
88     DHCP_OPT_SUCCESS = 0,
89     /* failed */
90     DHCP_OPT_FAILED,
91     /* null pointer */
92     DHCP_OPT_NULL,
93     /* timeout */
94     DHCP_OPT_TIMEOUT,
95     /* error */
96     DHCP_OPT_ERROR,
97 } DhcpErrCode;
98 
99 /* publish event code */
100 typedef enum EnumPublishEventCode {
101     /* success */
102     PUBLISH_CODE_SUCCESS = 0,
103     /* failed */
104     PUBLISH_CODE_FAILED = -1
105 } DhcpEventCode;
106 
107 typedef enum EnumServiceStatus {
108     SERVICE_STATUS_INVALID  = 0,
109     SERVICE_STATUS_START    = 1,
110     SERVICE_STATUS_STOP     = 2
111 } DhcpServiceStatus;
112 
113 struct DhcpResult {
114     int iptype;             /* 0-ipv4,1-ipv6 */
115     bool isOptSuc;          /* get result */
116     std::string strYourCli; /* your (client) IP */
117     std::string strServer;  /* dhcp server IP */
118     std::string strSubnet;  /* your (client) subnet mask */
119     std::string strDns1;    /* your (client) DNS server1 */
120     std::string strDns2;    /* your (client) DNS server2 */
121     std::string strRouter1; /* your (client) router1 */
122     std::string strRouter2; /* your (client) router2 */
123     std::string strVendor;  /* your (client) vendor */
124     uint32_t uLeaseTime;    /* your (client) IP lease time (s) */
125     uint32_t uAddTime;      /* dhcp result add time */
126     uint32_t uGetTime;      /* dhcp result get time */
127 
DhcpResultDhcpResult128     DhcpResult()
129     {
130         iptype      = -1;
131         isOptSuc    = false;
132         strYourCli  = "";
133         strServer   = "";
134         strSubnet   = "";
135         strDns1     = "";
136         strDns2     = "";
137         strRouter1  = "";
138         strRouter2  = "";
139         strVendor   = "";
140         uLeaseTime  = 0;
141         uAddTime    = 0;
142         uGetTime    = 0;
143     }
144 };
145 
146 struct DhcpPacketResult {
147     char strYiaddr[INET_ADDRSTRLEN];        /* your (client) IP */
148     char strOptServerId[INET_ADDRSTRLEN];   /* dhcp option DHO_SERVERID */
149     char strOptSubnet[INET_ADDRSTRLEN];     /* dhcp option DHO_SUBNETMASK */
150     char strOptDns1[INET_ADDRSTRLEN];       /* dhcp option DHO_DNSSERVER */
151     char strOptDns2[INET_ADDRSTRLEN];       /* dhcp option DHO_DNSSERVER */
152     char strOptRouter1[INET_ADDRSTRLEN];    /* dhcp option DHO_ROUTER */
153     char strOptRouter2[INET_ADDRSTRLEN];    /* dhcp option DHO_ROUTER */
154     char strOptVendor[DHCP_FILE_MAX_BYTES]; /* dhcp option DHO_VENDOR */
155     uint32_t uOptLeasetime;                 /* dhcp option DHO_LEASETIME */
156     uint32_t uAddTime;                      /* dhcp result add time */
157 };
158 
159 struct DhcpServiceInfo {
160     bool enableIPv6;        /* true:ipv4 and ipv6,false:ipv4 */
161     int clientRunStatus;    /* dhcp client service status */
162     pid_t clientProPid;     /* dhcp client process pid */
163     std::string serverIp;   /* dhcp server IP */
164 
DhcpServiceInfoDhcpServiceInfo165     DhcpServiceInfo()
166     {
167         enableIPv6 = true;
168         clientRunStatus = -1;
169         clientProPid = 0;
170         serverIp = "";
171     }
172 };
173 
174 struct DhcpServerInfo {
175     pid_t proPid;           /* dhcp server process id */
176     bool normalExit;        /* dhcp server process normal exit */
177     bool exitSig;           /* dhcp server process exit signal */
178 
DhcpServerInfoDhcpServerInfo179     DhcpServerInfo()
180     {
181         proPid = 0;
182         normalExit = false;
183         exitSig = false;
184     }
185 };
186 
187 struct DhcpRange {
188     int iptype;             /* 0-ipv4,1-ipv6 */
189     int leaseHours;         /* lease hours */
190     std::string strTagName; /* dhcp-range tag name */
191     std::string strStartip; /* dhcp-range start ip */
192     std::string strEndip;   /* dhcp-range end ip */
193     std::string strSubnet;  /* dhcp-range subnet */
194 
DhcpRangeDhcpRange195     DhcpRange()
196     {
197         iptype = -1;
198         leaseHours = LEASETIME_DEFAULT;
199         strTagName = "";
200         strStartip = "";
201         strEndip = "";
202         strSubnet = "";
203     }
204 };
205 }  // namespace Wifi
206 }  // namespace OHOS
207 #endif /* OHOS_DHCP_DEFINE_H */
208