1518678f8Sopenharmony_ci/* 2518678f8Sopenharmony_ci * Copyright (C) 2021-2022 Huawei Device Co., Ltd. 3518678f8Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4518678f8Sopenharmony_ci * you may not use this file except in compliance with the License. 5518678f8Sopenharmony_ci * You may obtain a copy of the License at 6518678f8Sopenharmony_ci * 7518678f8Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8518678f8Sopenharmony_ci * 9518678f8Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10518678f8Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11518678f8Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12518678f8Sopenharmony_ci * See the License for the specific language governing permissions and 13518678f8Sopenharmony_ci * limitations under the License. 14518678f8Sopenharmony_ci */ 15518678f8Sopenharmony_ci 16518678f8Sopenharmony_ci#ifndef OHOS_DHCP_DEFINE_H 17518678f8Sopenharmony_ci#define OHOS_DHCP_DEFINE_H 18518678f8Sopenharmony_ci 19518678f8Sopenharmony_ci#include <string> 20518678f8Sopenharmony_ci#include <cstdint> 21518678f8Sopenharmony_ci#include <netinet/ip.h> 22518678f8Sopenharmony_ci#include <sys/stat.h> 23518678f8Sopenharmony_ci 24518678f8Sopenharmony_cinamespace OHOS { 25518678f8Sopenharmony_cinamespace DHCP { 26518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_INDEX_0 = 0; 27518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_INDEX_1 = 1; 28518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_INDEX_2 = 2; 29518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_INDEX_3 = 3; 30518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_INDEX_4 = 4; 31518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_INDEX_5 = 5; 32518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_LEN = 6; 33518678f8Sopenharmony_ciconst int ETH_MAC_ADDR_CHAR_NUM = 3; 34518678f8Sopenharmony_ciconst int IP_SIZE = 18; 35518678f8Sopenharmony_ciconst int LEASETIME_DEFAULT = 6; 36518678f8Sopenharmony_ciconst int ONE_HOURS_SEC = 3600; 37518678f8Sopenharmony_ciconst int RECEIVER_TIMEOUT = 6; 38518678f8Sopenharmony_ciconst int EVENT_DATA_NUM = 11; 39518678f8Sopenharmony_ciconst int IPV6_EVENT_DATA_NUM = 9; 40518678f8Sopenharmony_ciconst int DHCP_NUM_ZERO = 0; 41518678f8Sopenharmony_ciconst int DHCP_NUM_ONE = 1; 42518678f8Sopenharmony_ciconst int DHCP_NUM_TWO = 2; 43518678f8Sopenharmony_ciconst int DHCP_NUM_THREE = 3; 44518678f8Sopenharmony_ciconst int DHCP_NUM_FOUR = 4; 45518678f8Sopenharmony_ciconst int DHCP_NUM_FIVE = 5; 46518678f8Sopenharmony_ciconst int DHCP_NUM_SIX = 6; 47518678f8Sopenharmony_ciconst int DHCP_NUM_SEVEN = 7; 48518678f8Sopenharmony_ciconst int DHCP_NUM_EIGHT = 8; 49518678f8Sopenharmony_ciconst int DHCP_NUM_NINE = 9; 50518678f8Sopenharmony_ciconst int DHCP_NUM_TEN = 10; 51518678f8Sopenharmony_ciconst int DHCP_FILE_MAX_BYTES = 128; 52518678f8Sopenharmony_ciconst int FILE_LINE_MAX_SIZE = 1024; 53518678f8Sopenharmony_ciconst int DHCP_SER_ARGSNUM = 6; 54518678f8Sopenharmony_ciconst int DHCP_CLI_ARGSNUM = 5; 55518678f8Sopenharmony_ciconst int SLEEP_TIME_200_MS = 200 * 1000; 56518678f8Sopenharmony_ciconst int SLEEP_TIME_500_MS = 500 * 1000; 57518678f8Sopenharmony_ciconst int PID_MAX_LEN = 16; 58518678f8Sopenharmony_ciconst int PARAM_MAX_SIZE = 40; 59518678f8Sopenharmony_ciconst int DEFAULT_UMASK = 027; 60518678f8Sopenharmony_ciconst int DIR_MAX_LEN = 256; 61518678f8Sopenharmony_ciconst int DIR_DEFAULT_MODE = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH; 62518678f8Sopenharmony_ciconst int DHCP_IPV4_GETTED = 1; 63518678f8Sopenharmony_ciconst int DHCP_IPV6_GETTED = 2; 64518678f8Sopenharmony_ciconst int DHCP_IPALL_GETED = DHCP_IPV4_GETTED | DHCP_IPV6_GETTED; 65518678f8Sopenharmony_ciconst std::string IP4_SEPARATOR("."); 66518678f8Sopenharmony_ciconst std::string IP6_SEPARATOR(":"); 67518678f8Sopenharmony_ciconst std::string INVALID_STRING("*"); 68518678f8Sopenharmony_ciconst std::string EVENT_DATA_DELIMITER(","); 69518678f8Sopenharmony_ciconst std::string EVENT_DATA_IPV4("ipv4"); 70518678f8Sopenharmony_ciconst std::string EVENT_DATA_IPV6("ipv6"); 71518678f8Sopenharmony_ci 72518678f8Sopenharmony_ci#define DHCP_CLIENT_ABILITY_ID 1126 73518678f8Sopenharmony_ci#define DHCP_SERVER_ABILITY_ID 1127 74518678f8Sopenharmony_ci 75518678f8Sopenharmony_ci#ifdef OHOS_EUPDATER 76518678f8Sopenharmony_ciconst std::string DHCP_WORK_DIR("/tmp/service/el1/public/dhcp/"); 77518678f8Sopenharmony_ci#else 78518678f8Sopenharmony_ciconst std::string DHCP_WORK_DIR("/data/service/el1/public/dhcp/"); 79518678f8Sopenharmony_ci#endif // OHOS_EUPDATER 80518678f8Sopenharmony_ci 81518678f8Sopenharmony_ciconst std::string DHCP_CLIENT_PID_FILETYPE(".pid"); 82518678f8Sopenharmony_ciconst std::string DHCP_RESULT_FILETYPE(".result"); 83518678f8Sopenharmony_ci#ifdef OHOS_ARCH_LITE 84518678f8Sopenharmony_ciconst std::string DHCP_CLIENT_FILE("/bin/dhcp_client_service"); 85518678f8Sopenharmony_ciconst std::string DHCP_SERVER_FILE("/bin/dhcp_server"); 86518678f8Sopenharmony_ci#else 87518678f8Sopenharmony_ciconst std::string DHCP_CLIENT_FILE("/system/bin/dhcp_client_service"); 88518678f8Sopenharmony_ciconst std::string DHCP_SERVER_FILE("/system/bin/dhcp_server"); 89518678f8Sopenharmony_ci#endif 90518678f8Sopenharmony_ciconst std::string DHCP_SERVER_CONFIG_FILE(DHCP_WORK_DIR + "etc/dhcpd.conf"); 91518678f8Sopenharmony_ciconst std::string DHCP_SERVER_CONFIG_DIR(DHCP_WORK_DIR + "etc/"); 92518678f8Sopenharmony_ciconst std::string DHCP_SERVER_LEASES_FILE(DHCP_WORK_DIR + "dhcpd_lease.lease"); 93518678f8Sopenharmony_ciconst std::string DHCP_SERVER_CFG_IPV4("#ipv4"); 94518678f8Sopenharmony_ciconst std::string DHCP_SERVER_CFG_IPV6("#ipv6"); 95518678f8Sopenharmony_ciconst std::string COMMON_EVENT_DHCP_GET_IPV4 = "usual.event.wifi.dhcp.GET_IPV4"; 96518678f8Sopenharmony_ciconst std::string IP_V4_MASK("255.255.255.0"); 97518678f8Sopenharmony_ciconst std::string IP_V4_DEFAULT("192.168.62.1"); 98518678f8Sopenharmony_ci 99518678f8Sopenharmony_citypedef enum EnumErrCode { 100518678f8Sopenharmony_ci /* success */ 101518678f8Sopenharmony_ci DHCP_OPT_SUCCESS = 0, 102518678f8Sopenharmony_ci /* failed */ 103518678f8Sopenharmony_ci DHCP_OPT_FAILED, 104518678f8Sopenharmony_ci /* null pointer */ 105518678f8Sopenharmony_ci DHCP_OPT_NULL, 106518678f8Sopenharmony_ci /* get ip timeout */ 107518678f8Sopenharmony_ci DHCP_OPT_TIMEOUT, 108518678f8Sopenharmony_ci /* renew failed */ 109518678f8Sopenharmony_ci DHCP_OPT_RENEW_FAILED, 110518678f8Sopenharmony_ci /* renew timeout */ 111518678f8Sopenharmony_ci DHCP_OPT_RENEW_TIMEOUT, 112518678f8Sopenharmony_ci /* lease expired */ 113518678f8Sopenharmony_ci DHCP_OPT_LEASE_EXPIRED, 114518678f8Sopenharmony_ci /* dhcp offer */ 115518678f8Sopenharmony_ci DHCP_OPT_OFFER_REPORT, 116518678f8Sopenharmony_ci /* error */ 117518678f8Sopenharmony_ci DHCP_OPT_ERROR, 118518678f8Sopenharmony_ci} DhcpErrCode; 119518678f8Sopenharmony_ci 120518678f8Sopenharmony_cienum DhcpServerState { 121518678f8Sopenharmony_ci DHCP_SERVER_OFF = 0, 122518678f8Sopenharmony_ci DHCP_SERVER_ON, 123518678f8Sopenharmony_ci}; 124518678f8Sopenharmony_ci 125518678f8Sopenharmony_citypedef enum EnumServiceStatus { 126518678f8Sopenharmony_ci SERVICE_STATUS_INVALID = 0, 127518678f8Sopenharmony_ci SERVICE_STATUS_START = 1, 128518678f8Sopenharmony_ci SERVICE_STATUS_STOP = 2 129518678f8Sopenharmony_ci} DhcpServiceStatus; 130518678f8Sopenharmony_ci 131518678f8Sopenharmony_cistruct DhcpResult { 132518678f8Sopenharmony_ci bool isOptSuc; /* get result */ 133518678f8Sopenharmony_ci int iptype; /* 0-ipv4,1-ipv6 */ 134518678f8Sopenharmony_ci std::string strYourCli; /* your (client) IP */ 135518678f8Sopenharmony_ci std::string strServer; /* dhcp server IP */ 136518678f8Sopenharmony_ci std::string strSubnet; /* your (client) subnet mask */ 137518678f8Sopenharmony_ci std::string strDns1; /* your (client) DNS server1 */ 138518678f8Sopenharmony_ci std::string strDns2; /* your (client) DNS server2 */ 139518678f8Sopenharmony_ci std::string strRouter1; /* your (client) router1 */ 140518678f8Sopenharmony_ci std::string strRouter2; /* your (client) router2 */ 141518678f8Sopenharmony_ci std::string strVendor; /* your (client) vendor */ 142518678f8Sopenharmony_ci std::string strLinkIpv6Addr; /* your (client) link ipv6 addr */ 143518678f8Sopenharmony_ci std::string strRandIpv6Addr; /* your (client) rand ipv6 addr */ 144518678f8Sopenharmony_ci std::string strLocalAddr1; /* your (client) unique local ipv6 addr */ 145518678f8Sopenharmony_ci std::string strLocalAddr2; /* your (client) unique local ipv6 addr */ 146518678f8Sopenharmony_ci uint32_t uLeaseTime; /* your (client) IP lease time (s) */ 147518678f8Sopenharmony_ci uint32_t uAddTime; /* dhcp result add time */ 148518678f8Sopenharmony_ci uint32_t uGetTime; /* dhcp result get time */ 149518678f8Sopenharmony_ci std::vector<std::string> vectorDnsAddr; /* your (client) multi dns server */ 150518678f8Sopenharmony_ci 151518678f8Sopenharmony_ci DhcpResult() 152518678f8Sopenharmony_ci { 153518678f8Sopenharmony_ci iptype = -1; 154518678f8Sopenharmony_ci isOptSuc = false; 155518678f8Sopenharmony_ci strYourCli = ""; 156518678f8Sopenharmony_ci strServer = ""; 157518678f8Sopenharmony_ci strSubnet = ""; 158518678f8Sopenharmony_ci strDns1 = ""; 159518678f8Sopenharmony_ci strDns2 = ""; 160518678f8Sopenharmony_ci strRouter1 = ""; 161518678f8Sopenharmony_ci strRouter2 = ""; 162518678f8Sopenharmony_ci strVendor = ""; 163518678f8Sopenharmony_ci strLinkIpv6Addr = ""; 164518678f8Sopenharmony_ci strRandIpv6Addr = ""; 165518678f8Sopenharmony_ci strLocalAddr1 = ""; 166518678f8Sopenharmony_ci strLocalAddr2 = ""; 167518678f8Sopenharmony_ci uLeaseTime = 0; 168518678f8Sopenharmony_ci uAddTime = 0; 169518678f8Sopenharmony_ci uGetTime = 0; 170518678f8Sopenharmony_ci vectorDnsAddr.clear(); 171518678f8Sopenharmony_ci } 172518678f8Sopenharmony_ci}; 173518678f8Sopenharmony_ci 174518678f8Sopenharmony_cistruct DhcpPacketResult { 175518678f8Sopenharmony_ci char strYiaddr[INET_ADDRSTRLEN]; /* your (client) IP */ 176518678f8Sopenharmony_ci char strOptServerId[INET_ADDRSTRLEN]; /* dhcp option DHO_SERVERID */ 177518678f8Sopenharmony_ci char strOptSubnet[INET_ADDRSTRLEN]; /* dhcp option DHO_SUBNETMASK */ 178518678f8Sopenharmony_ci char strOptDns1[INET_ADDRSTRLEN]; /* dhcp option DHO_DNSSERVER */ 179518678f8Sopenharmony_ci char strOptDns2[INET_ADDRSTRLEN]; /* dhcp option DHO_DNSSERVER */ 180518678f8Sopenharmony_ci char strOptRouter1[INET_ADDRSTRLEN]; /* dhcp option DHO_ROUTER */ 181518678f8Sopenharmony_ci char strOptRouter2[INET_ADDRSTRLEN]; /* dhcp option DHO_ROUTER */ 182518678f8Sopenharmony_ci char strOptVendor[DHCP_FILE_MAX_BYTES]; /* dhcp option DHO_VENDOR */ 183518678f8Sopenharmony_ci uint32_t uOptLeasetime; /* dhcp option DHO_LEASETIME */ 184518678f8Sopenharmony_ci uint32_t uAddTime; /* dhcp result add time */ 185518678f8Sopenharmony_ci}; 186518678f8Sopenharmony_ci 187518678f8Sopenharmony_cistruct DhcpServiceInfo { 188518678f8Sopenharmony_ci bool enableIPv6; /* true:ipv4 and ipv6,false:ipv4 */ 189518678f8Sopenharmony_ci int clientRunStatus; /* dhcp client service status */ 190518678f8Sopenharmony_ci pid_t clientProPid; /* dhcp client process pid */ 191518678f8Sopenharmony_ci std::string serverIp; /* dhcp server IP */ 192518678f8Sopenharmony_ci 193518678f8Sopenharmony_ci DhcpServiceInfo() 194518678f8Sopenharmony_ci { 195518678f8Sopenharmony_ci enableIPv6 = true; 196518678f8Sopenharmony_ci clientRunStatus = -1; 197518678f8Sopenharmony_ci clientProPid = 0; 198518678f8Sopenharmony_ci serverIp = ""; 199518678f8Sopenharmony_ci } 200518678f8Sopenharmony_ci}; 201518678f8Sopenharmony_ci 202518678f8Sopenharmony_cistruct DhcpServerInfo { 203518678f8Sopenharmony_ci pid_t proPid; /* dhcp server process id */ 204518678f8Sopenharmony_ci bool normalExit; /* dhcp server process normal exit */ 205518678f8Sopenharmony_ci bool exitSig; /* dhcp server process exit signal */ 206518678f8Sopenharmony_ci 207518678f8Sopenharmony_ci DhcpServerInfo() 208518678f8Sopenharmony_ci { 209518678f8Sopenharmony_ci proPid = 0; 210518678f8Sopenharmony_ci normalExit = false; 211518678f8Sopenharmony_ci exitSig = false; 212518678f8Sopenharmony_ci } 213518678f8Sopenharmony_ci}; 214518678f8Sopenharmony_ci 215518678f8Sopenharmony_cistruct DhcpRange { 216518678f8Sopenharmony_ci int iptype; /* 0-ipv4,1-ipv6 */ 217518678f8Sopenharmony_ci int leaseHours; /* lease hours */ 218518678f8Sopenharmony_ci std::string strTagName; /* dhcp-range tag name */ 219518678f8Sopenharmony_ci std::string strStartip; /* dhcp-range start ip */ 220518678f8Sopenharmony_ci std::string strEndip; /* dhcp-range end ip */ 221518678f8Sopenharmony_ci std::string strSubnet; /* dhcp-range subnet */ 222518678f8Sopenharmony_ci 223518678f8Sopenharmony_ci DhcpRange() 224518678f8Sopenharmony_ci { 225518678f8Sopenharmony_ci iptype = -1; 226518678f8Sopenharmony_ci leaseHours = LEASETIME_DEFAULT; 227518678f8Sopenharmony_ci strTagName = ""; 228518678f8Sopenharmony_ci strStartip = ""; 229518678f8Sopenharmony_ci strEndip = ""; 230518678f8Sopenharmony_ci strSubnet = ""; 231518678f8Sopenharmony_ci } 232518678f8Sopenharmony_ci}; 233518678f8Sopenharmony_ci 234518678f8Sopenharmony_cistruct RouterConfig { 235518678f8Sopenharmony_ci std::string bssid; 236518678f8Sopenharmony_ci bool prohibitUseCacheIp; 237518678f8Sopenharmony_ci}; 238518678f8Sopenharmony_ci} // namespace DHCP 239518678f8Sopenharmony_ci} // namespace OHOS 240518678f8Sopenharmony_ci#endif /* OHOS_DHCP_DEFINE_H */ 241