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#ifndef OHOS_DHCP_CLIENT_DEF_H 16518678f8Sopenharmony_ci#define OHOS_DHCP_CLIENT_DEF_H 17518678f8Sopenharmony_ci 18518678f8Sopenharmony_ci#include <stdbool.h> 19518678f8Sopenharmony_ci#include <stdint.h> 20518678f8Sopenharmony_ci#include <netinet/udp.h> 21518678f8Sopenharmony_ci#include <netinet/ip.h> 22518678f8Sopenharmony_ci#include <string> 23518678f8Sopenharmony_ci 24518678f8Sopenharmony_ci#define DHCP_GET_TIMEOUT 15 25518678f8Sopenharmony_ci#define MAXRETRYTIMEOUT 10 26518678f8Sopenharmony_ci#define USECOND_CONVERT 1000 27518678f8Sopenharmony_ci#define MAX_READ_EVENT_SIZE 512 28518678f8Sopenharmony_ci#define NUMBER_ONE 1 29518678f8Sopenharmony_ci#define NUMBER_TWO 2 30518678f8Sopenharmony_ci#define NUMBER_THREE 3 31518678f8Sopenharmony_ci#define NUMBER_FOUR 4 32518678f8Sopenharmony_ci#define NUMBER_FIVE 5 33518678f8Sopenharmony_ci#define NUMBER_FIFTY_FOUR 54 34518678f8Sopenharmony_ci#define FIRST_TIMEOUT_SEC 1 35518678f8Sopenharmony_ci#define MAX_TIMEOUT_SEC 6 36518678f8Sopenharmony_ci#define DOUBLE_TIME 2 37518678f8Sopenharmony_ci#define RENEWAL_SEC_MULTIPLE 0.5 38518678f8Sopenharmony_ci#define REBIND_SEC_MULTIPLE 0.875 39518678f8Sopenharmony_ci#define TIME_INTERVAL_MAX 1 40518678f8Sopenharmony_ci#define TIMEOUT_TIMES_MAX 15 41518678f8Sopenharmony_ci#define MAX_WAIT_TIMES 32 42518678f8Sopenharmony_ci#define TIMEOUT_WAIT_SEC 1 43518678f8Sopenharmony_ci#define TIMEOUT_MORE_WAIT_SEC 60 44518678f8Sopenharmony_ci#define ONE_HOURS_SEC 3600 45518678f8Sopenharmony_ci#define LEASETIME_DEFAULT 1 46518678f8Sopenharmony_ci#define SLEEP_TIME_200_MS (200 * 1000) 47518678f8Sopenharmony_ci#define SLEEP_TIME_500_MS (500 * 1000) 48518678f8Sopenharmony_ci#define DHCP_FAILE_TIMEOUT_THR 6 49518678f8Sopenharmony_ci#define MAX_CONFLICTS_COUNT 2 50518678f8Sopenharmony_ci 51518678f8Sopenharmony_ci#define MAC_ADDR_LEN 6 52518678f8Sopenharmony_ci#define MAC_ADDR_CHAR_NUM 3 53518678f8Sopenharmony_ci#define ETHERNET_TYPE 0x01 54518678f8Sopenharmony_ci#define ETHERNET_LEN 6 55518678f8Sopenharmony_ci#define VENDOR_MAX_LEN 64 56518678f8Sopenharmony_ci#define MAGIC_COOKIE 0x63825363 57518678f8Sopenharmony_ci#define BROADCAST_FLAG 0x8000 58518678f8Sopenharmony_ci#define MAC_BCAST_ADDR "\xff\xff\xff\xff\xff\xff" 59518678f8Sopenharmony_ci#define SIGNED_INTEGER_MAX 0x7FFFFFFF 60518678f8Sopenharmony_ci#define PID_MAX_LEN 16 61518678f8Sopenharmony_ci#define DEFAULT_UMASK 027 62518678f8Sopenharmony_ci#define DIR_MAX_LEN 256 63518678f8Sopenharmony_ci#define INFNAME_SIZE 16 /* Length of interface name */ 64518678f8Sopenharmony_ci#define RWMODE 0600 65518678f8Sopenharmony_ci#define MAX_MSG_SIZE 1500 66518678f8Sopenharmony_ci#define DHCP_FILE_MAX_BYTES 128 67518678f8Sopenharmony_ci#define STRING_MAX_LEN 1024 68518678f8Sopenharmony_ci#define EVENT_GET_IPV4 "usual.event.wifi.dhcp.GET_IPV4" 69518678f8Sopenharmony_ci 70518678f8Sopenharmony_ci/* UDP port numbers for BOOTP */ 71518678f8Sopenharmony_ci#define BOOTP_SERVER 67 72518678f8Sopenharmony_ci#define BOOTP_CLIENT 68 73518678f8Sopenharmony_ci 74518678f8Sopenharmony_ci/* BOOTP message type */ 75518678f8Sopenharmony_ci#define BOOT_REQUEST 1 76518678f8Sopenharmony_ci#define BOOT_REPLY 2 77518678f8Sopenharmony_ci 78518678f8Sopenharmony_ci/* DHCP packet type */ 79518678f8Sopenharmony_ci#define DHCP_DISCOVER 1 80518678f8Sopenharmony_ci#define DHCP_OFFER 2 81518678f8Sopenharmony_ci#define DHCP_REQUEST 3 82518678f8Sopenharmony_ci#define DHCP_DECLINE 4 83518678f8Sopenharmony_ci#define DHCP_ACK 5 84518678f8Sopenharmony_ci#define DHCP_NAK 6 85518678f8Sopenharmony_ci#define DHCP_RELEASE 7 86518678f8Sopenharmony_ci#define DHCP_INFORM 8 87518678f8Sopenharmony_ci#define DHCP_FORCERENEW 9 88518678f8Sopenharmony_ci 89518678f8Sopenharmony_ci/* Sizes for DhcpPacket Fields */ 90518678f8Sopenharmony_ci#define DHCP_HWADDR_LENGTH 16 91518678f8Sopenharmony_ci#define DHCP_HOST_NAME_LENGTH 64 92518678f8Sopenharmony_ci#define DHCP_BOOT_FILE_LENGTH 128 93518678f8Sopenharmony_ci#define DHCP_OPT_SIZE 308 94518678f8Sopenharmony_ci#define DHCP_OPT_CODE_INDEX 0 95518678f8Sopenharmony_ci#define DHCP_OPT_LEN_INDEX 1 96518678f8Sopenharmony_ci#define DHCP_OPT_DATA_INDEX 2 97518678f8Sopenharmony_ci#define DHCP_OPT_CODE_BYTES 1 98518678f8Sopenharmony_ci#define DHCP_OPT_LEN_BYTES 1 99518678f8Sopenharmony_ci#define DHCP_UINT8_BYTES 1 100518678f8Sopenharmony_ci#define DHCP_UINT16_BYTES 2 101518678f8Sopenharmony_ci#define DHCP_UINT32_BYTES 4 102518678f8Sopenharmony_ci#define DHCP_UINT32_DOUBLE_BYTES 8 103518678f8Sopenharmony_ci#define DHCP_UINT16_BITS 16 104518678f8Sopenharmony_ci#define DHCP_REQ_CODE_NUM 12 105518678f8Sopenharmony_ci#define OPTION_FIELD 0 106518678f8Sopenharmony_ci#define FILE_FIELD 1 107518678f8Sopenharmony_ci#define SNAME_FIELD 2 108518678f8Sopenharmony_ci#define DHCP_DNS_FIRST 1 109518678f8Sopenharmony_ci#define DHCP_DNS_SECOND 2 110518678f8Sopenharmony_ci#define DHCP_APPEND_LEN 2 111518678f8Sopenharmony_ci 112518678f8Sopenharmony_ci#ifdef OHOS_EUPDATER 113518678f8Sopenharmony_ci#define WORKDIR "/tmp/service/el1/public/dhcp/" 114518678f8Sopenharmony_ci#else 115518678f8Sopenharmony_ci#define WORKDIR "/data/service/el1/public/dhcp/" 116518678f8Sopenharmony_ci#endif // OHOS_EUPDATER 117518678f8Sopenharmony_ci 118518678f8Sopenharmony_ci#define DHCPC_NAME "dhcp_client_service" 119518678f8Sopenharmony_ci#define DHCPC_CONF "dhcp_client_service.conf" 120518678f8Sopenharmony_ci#define DHCPC_PID "dhcp_client_service.pid" 121518678f8Sopenharmony_ci#define DHCPC_VERSION "1.0" 122518678f8Sopenharmony_ci#define DHCPC_LEASE "dhcp_client_service-%s.lease" 123518678f8Sopenharmony_ci#define DHCP_CACHE_FILE WORKDIR"/dhcp_cache.conf" 124518678f8Sopenharmony_ci/* netmanager ipv6 */ 125518678f8Sopenharmony_ciconstexpr int DHCP_IPV6_ENABLE = 1; 126518678f8Sopenharmony_ciconstexpr int DHCP_IPV6_DISENABLE = 0; 127518678f8Sopenharmony_ci 128518678f8Sopenharmony_ci/* dhcp action mode */ 129518678f8Sopenharmony_cienum ActionMode { 130518678f8Sopenharmony_ci ACTION_START_NEW = 0, 131518678f8Sopenharmony_ci ACTION_START_OLD, 132518678f8Sopenharmony_ci ACTION_RENEW_T1, 133518678f8Sopenharmony_ci ACTION_RENEW_T2, 134518678f8Sopenharmony_ci ACTION_RENEW_T3, 135518678f8Sopenharmony_ci ACTION_INVALID 136518678f8Sopenharmony_ci}; 137518678f8Sopenharmony_ci 138518678f8Sopenharmony_ci/* dhcp signal mode */ 139518678f8Sopenharmony_cienum SigMode { 140518678f8Sopenharmony_ci SIG_START = 0, 141518678f8Sopenharmony_ci SIG_STOP, 142518678f8Sopenharmony_ci SIG_RENEW, 143518678f8Sopenharmony_ci SIG_INVALID 144518678f8Sopenharmony_ci}; 145518678f8Sopenharmony_ci 146518678f8Sopenharmony_ci/* dhcp state code */ 147518678f8Sopenharmony_cienum EnumDhcpStateCode { 148518678f8Sopenharmony_ci DHCP_STATE_INIT = 0, 149518678f8Sopenharmony_ci DHCP_STATE_SELECTING, 150518678f8Sopenharmony_ci DHCP_STATE_REQUESTING, 151518678f8Sopenharmony_ci DHCP_STATE_BOUND, 152518678f8Sopenharmony_ci DHCP_STATE_RENEWING, 153518678f8Sopenharmony_ci DHCP_STATE_REBINDING, 154518678f8Sopenharmony_ci DHCP_STATE_INITREBOOT, 155518678f8Sopenharmony_ci DHCP_STATE_RELEASED, 156518678f8Sopenharmony_ci DHCP_STATE_RENEWED, 157518678f8Sopenharmony_ci DHCP_STATE_FAST_ARP, 158518678f8Sopenharmony_ci DHCP_STATE_SLOW_ARP, 159518678f8Sopenharmony_ci DHCP_STATE_DECLINE, 160518678f8Sopenharmony_ci}; 161518678f8Sopenharmony_ci 162518678f8Sopenharmony_ci/* dhcp return code */ 163518678f8Sopenharmony_cienum EnumErrCode { 164518678f8Sopenharmony_ci DHCP_OPT_SUCCESS = 0, /* success */ 165518678f8Sopenharmony_ci DHCP_OPT_FAILED, /* failed */ 166518678f8Sopenharmony_ci DHCP_OPT_NULL, /* null pointer */ 167518678f8Sopenharmony_ci DHCP_OPT_TIMEOUT, /* timeout */ 168518678f8Sopenharmony_ci DHCP_OPT_ERROR, /* error */ 169518678f8Sopenharmony_ci DHCP_OPT_NOT_SUPPORTED, /* not supported */ 170518678f8Sopenharmony_ci DHCP_OPT_NONE, /* none */ 171518678f8Sopenharmony_ci}; 172518678f8Sopenharmony_ci 173518678f8Sopenharmony_ci/* socket return code */ 174518678f8Sopenharmony_cienum EnumSocketErrCode { 175518678f8Sopenharmony_ci SOCKET_OPT_SUCCESS = 0, 176518678f8Sopenharmony_ci SOCKET_OPT_FAILED = -1, 177518678f8Sopenharmony_ci SOCKET_OPT_ERROR = -2 178518678f8Sopenharmony_ci}; 179518678f8Sopenharmony_ci 180518678f8Sopenharmony_ci/* socket mode */ 181518678f8Sopenharmony_cienum EnumSocketMode { 182518678f8Sopenharmony_ci SOCKET_MODE_INVALID = 0, 183518678f8Sopenharmony_ci SOCKET_MODE_RAW = 1, 184518678f8Sopenharmony_ci SOCKET_MODE_KERNEL = 2 185518678f8Sopenharmony_ci}; 186518678f8Sopenharmony_ci 187518678f8Sopenharmony_ci// See: RFC 2132 DHCP Options and BOOTP Vendor Extensions March 1997 188518678f8Sopenharmony_cienum DhcpOptions { 189518678f8Sopenharmony_ci /* 190518678f8Sopenharmony_ci * 3. RFC 1497 Vendor Extensions 191518678f8Sopenharmony_ci * This section lists the vendor extensions as defined in RFC 1497. 192518678f8Sopenharmony_ci * They are defined here for completeness. 193518678f8Sopenharmony_ci */ 194518678f8Sopenharmony_ci PAD_OPTION = 0, 195518678f8Sopenharmony_ci END_OPTION = 255, 196518678f8Sopenharmony_ci 197518678f8Sopenharmony_ci SUBNET_MASK_OPTION = 1, 198518678f8Sopenharmony_ci TIME_OFFSET_OPTION = 2, 199518678f8Sopenharmony_ci ROUTER_OPTION = 3, 200518678f8Sopenharmony_ci TIME_SERVER_OPTION = 4, 201518678f8Sopenharmony_ci NAME_SERVER_OPTION = 5, 202518678f8Sopenharmony_ci DOMAIN_NAME_SERVER_OPTION = 6, 203518678f8Sopenharmony_ci LOG_SERVER_OPTION = 7, 204518678f8Sopenharmony_ci COOKIE_SERVER_OPTION = 8, 205518678f8Sopenharmony_ci LPR_SERVER_OPTION = 9, 206518678f8Sopenharmony_ci IMPRESS_SERVER_OPTION = 10, 207518678f8Sopenharmony_ci RESOURCE_LOCATION_SERVER_OPTION = 11, 208518678f8Sopenharmony_ci HOST_NAME_OPTION = 12, 209518678f8Sopenharmony_ci BOOT_FILE_SIZE_OPTION = 13, 210518678f8Sopenharmony_ci MERIT_DUMP_FILE_OPTION = 14, 211518678f8Sopenharmony_ci DOMAIN_NAME_OPTION = 15, 212518678f8Sopenharmony_ci SWAP_SERVER_OPTION = 16, 213518678f8Sopenharmony_ci ROOT_PATH_OPTION = 17, 214518678f8Sopenharmony_ci EXTENSIONS_PATH_OPTION = 18, 215518678f8Sopenharmony_ci 216518678f8Sopenharmony_ci /* 217518678f8Sopenharmony_ci * IP Layer Parameters per Host 218518678f8Sopenharmony_ci * This section details the options that affect the operation of the IP layer on a per-host basis. 219518678f8Sopenharmony_ci */ 220518678f8Sopenharmony_ci IP_FORWARDING_OPTION = 19, 221518678f8Sopenharmony_ci NON_LOCAL_SOURCE_ROUTING_OPTION = 20, 222518678f8Sopenharmony_ci POLICY_FILTER_OPTION = 21, 223518678f8Sopenharmony_ci MAXIMUM_DATAGRAM_REASSEMBLY_SIZE_OPTION = 22, 224518678f8Sopenharmony_ci DEFAULT_IP_TIME_TO_LIVE_OPTION = 23, 225518678f8Sopenharmony_ci PATH_MTU_AGING_TIMEOUT_OPTION = 24, 226518678f8Sopenharmony_ci PATH_MTU_PLATEAU_TABLE_OPTION = 25, 227518678f8Sopenharmony_ci 228518678f8Sopenharmony_ci /* 229518678f8Sopenharmony_ci * 5. IP Layer Parameters per Interface 230518678f8Sopenharmony_ci * This section details the options that affect the operation of the IP layer on a per-interface basis. It is 231518678f8Sopenharmony_ci * expected that a client can issue multiple requests, one per interface, in order to configure interfaces with 232518678f8Sopenharmony_ci * their specific parameters. 233518678f8Sopenharmony_ci */ 234518678f8Sopenharmony_ci INTERFACE_MTU_OPTION = 26, 235518678f8Sopenharmony_ci ALL_SUBNETS_ARE_LOCAL_OPTION = 27, 236518678f8Sopenharmony_ci BROADCAST_ADDRESS_OPTION = 28, 237518678f8Sopenharmony_ci PERFORM_MASK_DISCOVERY_OPTION = 29, 238518678f8Sopenharmony_ci MASK_SUPPLIER_OPTION = 30, 239518678f8Sopenharmony_ci PERFORM_ROUTER_DISCOVERY_OPTION = 31, 240518678f8Sopenharmony_ci ROUTER_SOLICITATION_ADDRESS_OPTION = 32, 241518678f8Sopenharmony_ci STATIC_ROUTE_OPTION = 33, 242518678f8Sopenharmony_ci 243518678f8Sopenharmony_ci /* 244518678f8Sopenharmony_ci * 6. Link Layer Parameters per Interface 245518678f8Sopenharmony_ci * This section lists the options that affect the operation of the data link layer on a per-interface basis. 246518678f8Sopenharmony_ci */ 247518678f8Sopenharmony_ci TRAILER_ENCAPSULATION_OPTION = 34, // 6.1. Trailer Encapsulation Option 248518678f8Sopenharmony_ci ARP_CACHE_TIMEOUT_OPTION = 35, // 6.2. ARP Cache Timeout Option 249518678f8Sopenharmony_ci ETHERNET_ENCAPSULATION_OPTION = 36, // 6.3. Ethernet Encapsulation Option 250518678f8Sopenharmony_ci 251518678f8Sopenharmony_ci /* 252518678f8Sopenharmony_ci * 7. TCP Parameters 253518678f8Sopenharmony_ci * This section lists the options that affect the operation of the TCP layer on a per-interface basis. 254518678f8Sopenharmony_ci */ 255518678f8Sopenharmony_ci TCP_DEFAULT_TTL_OPTION = 37, // 7.1. TCP Default TTL Option 256518678f8Sopenharmony_ci TCP_KEEPALIVE_INTERVAL_OPTION = 38, // 7.2. TCP Keepalive Interval Option 257518678f8Sopenharmony_ci TCP_KEEPALIVE_GARBAGE_OPTION = 39, // 7.3. TCP Keepalive Garbage Option 258518678f8Sopenharmony_ci 259518678f8Sopenharmony_ci /* 260518678f8Sopenharmony_ci * 8. Application and Service Parameters 261518678f8Sopenharmony_ci * This section details some miscellaneous options used to configure miscellaneous applications and services. 262518678f8Sopenharmony_ci */ 263518678f8Sopenharmony_ci NETWORK_INFO_SERVICE_DOMAIN_OPTION = 40, // 8.1. Network Information Service Domain Option 264518678f8Sopenharmony_ci NETWORK_INFO_SERVERS_OPTION = 41, // 8.2. Network Information Servers Option 265518678f8Sopenharmony_ci NETWORK_TIME_PROTOCOL_SERVERS_OPTION = 42, // 8.3. Network Time Protocol Servers Option 266518678f8Sopenharmony_ci VENDOR_SPECIFIC_INFO_OPTION = 43, // 8.4. Vendor Specific Information 267518678f8Sopenharmony_ci NETBIOS_OVER_IP_NAME_SERVER_OPTION = 44, // 8.5. NetBIOS over TCP/IP Name Server Option 268518678f8Sopenharmony_ci NETBIOS_OVER_IP_DATAGRAM_DIST_SERVER_OPTION = 45, // 8.6. NetBIOS over TCP/IP Datagram Distribution Server Option 269518678f8Sopenharmony_ci NETBIOS_OVER_IP_NODE_TYPE_OPTION = 46, // 8.7. NetBIOS over TCP/IP Node Type Option 270518678f8Sopenharmony_ci NETBIOS_OVER_IP_SCOPE_OPTION = 47, // 8.8. NetBIOS over TCP/IP Scope Option 271518678f8Sopenharmony_ci X_WINDOW_SYSTEM_FONT_SERVER_OPTION = 48, // 8.9. X Window System Font Server Option 272518678f8Sopenharmony_ci X_WINDOW_SYSTEM_DISPLAY_MANAGER_OPTION = 49, // 8.10. X Window System Display Manager Option 273518678f8Sopenharmony_ci NETWORK_INFO_SERVICE_PLUS_DOMAIN_OPTION = 64, // 8.11. Network Information Service+ Domain Option 274518678f8Sopenharmony_ci NETWORK_INFO_SERVICE_PLUS_SERVERS_OPTION = 65, // 8.12. Network Information Service+ Servers Option 275518678f8Sopenharmony_ci MOBILE_IP_HOME_AGENT_OPTION = 68, // 8.13. Mobile IP Home Agent option 276518678f8Sopenharmony_ci SMTP_SERVER_OPTION = 69, // 8.14. Simple Mail Transport Protocol (SMTP) Server Option 277518678f8Sopenharmony_ci POP3_SERVER_OPTION = 70, // 8.15. Post Office Protocol (POP3) Server Option 278518678f8Sopenharmony_ci NNTP_SERVER_OPTION = 71, // 8.16. Network News Transport Protocol (NNTP) Server Option 279518678f8Sopenharmony_ci DEFAULT_WEB_SERVER_OPTION = 72, // 8.17. Default World Wide Web (WWW) Server Option 280518678f8Sopenharmony_ci DEFAULT_FINGER_SERVER_OPTION = 73, // 8.18. Default Finger Server Option 281518678f8Sopenharmony_ci DEFAULT_IRC_SERVER_OPTION = 74, // 8.19. Default Internet Relay Chat (IRC) Server Option 282518678f8Sopenharmony_ci STREETTALK_SERVER_OPTION = 75, // 8.20. StreetTalk Server Option 283518678f8Sopenharmony_ci STDA_SERVER_OPTION = 76, // 8.21. StreetTalk Directory Assistance (STDA) Server Option 284518678f8Sopenharmony_ci 285518678f8Sopenharmony_ci /* 286518678f8Sopenharmony_ci * 9. DHCP Extensions 287518678f8Sopenharmony_ci * This section details the options that are specific to DHCP. 288518678f8Sopenharmony_ci */ 289518678f8Sopenharmony_ci REQUESTED_IP_ADDRESS_OPTION = 50, 290518678f8Sopenharmony_ci IP_ADDRESS_LEASE_TIME_OPTION = 51, 291518678f8Sopenharmony_ci OPTION_OVERLOAD_OPTION = 52, 292518678f8Sopenharmony_ci TFTP_SERVER_NAME_OPTION = 66, 293518678f8Sopenharmony_ci BOOTFILE_NAME_OPTION = 67, 294518678f8Sopenharmony_ci DHCP_MESSAGE_TYPE_OPTION = 53, 295518678f8Sopenharmony_ci SERVER_IDENTIFIER_OPTION = 54, 296518678f8Sopenharmony_ci PARAMETER_REQUEST_LIST_OPTION = 55, 297518678f8Sopenharmony_ci MESSAGE_OPTION = 56, 298518678f8Sopenharmony_ci MAXIMUM_DHCP_MESSAGE_SIZE_OPTION = 57, 299518678f8Sopenharmony_ci RENEWAL_TIME_VALUE_OPTION = 58, 300518678f8Sopenharmony_ci REBINDING_TIME_VALUE_OPTION = 59, 301518678f8Sopenharmony_ci VENDOR_CLASS_IDENTIFIER_OPTION = 60, 302518678f8Sopenharmony_ci CLIENT_IDENTIFIER_OPTION = 61, 303518678f8Sopenharmony_ci IPV6_ONLY_PREFERRED_OPTION = 108, 304518678f8Sopenharmony_ci CAPTIVE_PORTAL_OPTION = 114, 305518678f8Sopenharmony_ci /* RFC 6704 */ 306518678f8Sopenharmony_ci FORCERENEW_NONCE_OPTION = 145, /* Forcerenew Nonce Authentication */ 307518678f8Sopenharmony_ci}; 308518678f8Sopenharmony_ci 309518678f8Sopenharmony_cienum DHCP_OPTION_DATA_TYPE { 310518678f8Sopenharmony_ci DHCP_OPTION_DATA_INVALID = 0, 311518678f8Sopenharmony_ci DHCP_OPTION_DATA_U8, 312518678f8Sopenharmony_ci DHCP_OPTION_DATA_U16, 313518678f8Sopenharmony_ci DHCP_OPTION_DATA_S16, 314518678f8Sopenharmony_ci DHCP_OPTION_DATA_U32, 315518678f8Sopenharmony_ci DHCP_OPTION_DATA_S32, 316518678f8Sopenharmony_ci DHCP_OPTION_DATA_IP, 317518678f8Sopenharmony_ci DHCP_OPTION_DATA_IP_PAIR, 318518678f8Sopenharmony_ci DHCP_OPTION_DATA_IP_LIST, 319518678f8Sopenharmony_ci DHCP_OPTION_DATA_IP_STRING 320518678f8Sopenharmony_ci}; 321518678f8Sopenharmony_ci 322518678f8Sopenharmony_ci 323518678f8Sopenharmony_ci/* publish event code */ 324518678f8Sopenharmony_citypedef enum EnumPublishEventCode { 325518678f8Sopenharmony_ci /* success */ 326518678f8Sopenharmony_ci PUBLISH_CODE_SUCCESS = 0, 327518678f8Sopenharmony_ci /* failed */ 328518678f8Sopenharmony_ci PUBLISH_CODE_FAILED = -1, 329518678f8Sopenharmony_ci /* timeout */ 330518678f8Sopenharmony_ci PUBLISH_CODE_TIMEOUT = -2, 331518678f8Sopenharmony_ci /* lease expired */ 332518678f8Sopenharmony_ci PUBLISH_CODE_EXPIRED = -3, 333518678f8Sopenharmony_ci /* dhcp offer report*/ 334518678f8Sopenharmony_ci PUBLISH_DHCP_OFFER_REPORT = -4 335518678f8Sopenharmony_ci} DhcpEventCode; 336518678f8Sopenharmony_ci 337518678f8Sopenharmony_ci/* DhcpPacket Fields */ 338518678f8Sopenharmony_cistruct DhcpPacket { 339518678f8Sopenharmony_ci uint8_t op; 340518678f8Sopenharmony_ci uint8_t htype; 341518678f8Sopenharmony_ci uint8_t hlen; 342518678f8Sopenharmony_ci uint8_t hops; 343518678f8Sopenharmony_ci uint32_t xid; 344518678f8Sopenharmony_ci uint16_t secs; 345518678f8Sopenharmony_ci uint16_t flags; 346518678f8Sopenharmony_ci uint32_t ciaddr; 347518678f8Sopenharmony_ci uint32_t yiaddr; 348518678f8Sopenharmony_ci uint32_t siaddr; 349518678f8Sopenharmony_ci uint32_t giaddr; 350518678f8Sopenharmony_ci uint8_t chaddr[DHCP_HWADDR_LENGTH]; 351518678f8Sopenharmony_ci uint8_t sname[DHCP_HOST_NAME_LENGTH]; 352518678f8Sopenharmony_ci uint8_t file[DHCP_BOOT_FILE_LENGTH]; 353518678f8Sopenharmony_ci int32_t cookie; 354518678f8Sopenharmony_ci uint8_t options[DHCP_OPT_SIZE]; 355518678f8Sopenharmony_ci}; 356518678f8Sopenharmony_ci 357518678f8Sopenharmony_cistruct UdpDhcpPacket { 358518678f8Sopenharmony_ci struct iphdr ip; 359518678f8Sopenharmony_ci struct udphdr udp; 360518678f8Sopenharmony_ci struct DhcpPacket data; 361518678f8Sopenharmony_ci}; 362518678f8Sopenharmony_ci 363518678f8Sopenharmony_cistruct DhcpIpResult{ 364518678f8Sopenharmony_ci int32_t code; /* get result code */ 365518678f8Sopenharmony_ci std::string ifname; /* ifname */ 366518678f8Sopenharmony_ci uint32_t uAddTime; /* addTime */ 367518678f8Sopenharmony_ci uint32_t uOptLeasetime; /* dhcp option IP_ADDRESS_LEASE_TIME_OPTION */ 368518678f8Sopenharmony_ci char strYiaddr[INET_ADDRSTRLEN]; /* your (client) IP */ 369518678f8Sopenharmony_ci char strOptServerId[INET_ADDRSTRLEN]; /* dhcp option SERVER_IDENTIFIER_OPTION */ 370518678f8Sopenharmony_ci char strOptSubnet[INET_ADDRSTRLEN]; /* dhcp option SUBNET_MASK_OPTION */ 371518678f8Sopenharmony_ci char strOptDns1[INET_ADDRSTRLEN]; /* dhcp option DOMAIN_NAME_SERVER_OPTION */ 372518678f8Sopenharmony_ci char strOptDns2[INET_ADDRSTRLEN]; /* dhcp option DOMAIN_NAME_SERVER_OPTION */ 373518678f8Sopenharmony_ci char strOptRouter1[INET_ADDRSTRLEN]; /* dhcp option ROUTER_OPTION */ 374518678f8Sopenharmony_ci char strOptRouter2[INET_ADDRSTRLEN]; /* dhcp option ROUTER_OPTION */ 375518678f8Sopenharmony_ci char strOptVendor[DHCP_FILE_MAX_BYTES]; /* dhcp option VENDOR_SPECIFIC_INFO_OPTION */ 376518678f8Sopenharmony_ci std::vector<std::string> dnsAddr; /* dhcp option MULTI DOMAIN_NAME_SERVER_OPTION */ 377518678f8Sopenharmony_ci}; 378518678f8Sopenharmony_ci 379518678f8Sopenharmony_cienum DHCP_IP_TYPE { 380518678f8Sopenharmony_ci DHCP_IP_TYPE_NONE = 0, 381518678f8Sopenharmony_ci DHCP_IP_TYPE_ALL = 1, 382518678f8Sopenharmony_ci DHCP_IP_TYPE_V4 = 2, 383518678f8Sopenharmony_ci DHCP_IP_TYPE_V6 = 3 384518678f8Sopenharmony_ci}; 385518678f8Sopenharmony_ci 386518678f8Sopenharmony_citypedef struct{ 387518678f8Sopenharmony_ci int ifaceIndex; /* Index of the network interface used by the current process. */ 388518678f8Sopenharmony_ci bool isIpv6; /* IPv6 address of the network interface used to get. */ 389518678f8Sopenharmony_ci unsigned int ifaceIpv4; /* IPv4 of the network interface used by the current process. */ 390518678f8Sopenharmony_ci unsigned int getMode; /* Current process obtaining IPv4 address mode. */ 391518678f8Sopenharmony_ci unsigned char ifaceMac[MAC_ADDR_LEN]; /* Mac addr of the network interface used by the current process. */ 392518678f8Sopenharmony_ci char ifaceName[INFNAME_SIZE]; /* Name of the network interface used by the current process. */ 393518678f8Sopenharmony_ci char workDir[DIR_MAX_LEN]; /* Current process working directory. */ 394518678f8Sopenharmony_ci char confFile[DIR_MAX_LEN]; /* Current process Configuration Directory. */ 395518678f8Sopenharmony_ci char leaseFile[DIR_MAX_LEN]; 396518678f8Sopenharmony_ci char resultFile[DIR_MAX_LEN]; /* Save the obtained IPv4 result. */ 397518678f8Sopenharmony_ci char result6File[DIR_MAX_LEN]; 398518678f8Sopenharmony_ci}DhcpClientCfg; 399518678f8Sopenharmony_ci 400518678f8Sopenharmony_cistruct IpInfoCached { 401518678f8Sopenharmony_ci std::string bssid; 402518678f8Sopenharmony_ci int64_t absoluteLeasetime; 403518678f8Sopenharmony_ci struct DhcpIpResult ipResult; 404518678f8Sopenharmony_ci}; 405518678f8Sopenharmony_ci 406518678f8Sopenharmony_ci/* timer type */ 407518678f8Sopenharmony_cienum TimerType { 408518678f8Sopenharmony_ci TIMER_GET_IP = 0, 409518678f8Sopenharmony_ci TIMER_RENEW_DELAY, 410518678f8Sopenharmony_ci TIMER_REBIND_DELAY, 411518678f8Sopenharmony_ci TIMER_REMAINING_DELAY, 412518678f8Sopenharmony_ci}; 413518678f8Sopenharmony_ci 414518678f8Sopenharmony_cistruct RouterCfg { 415518678f8Sopenharmony_ci std::string bssid; 416518678f8Sopenharmony_ci bool prohibitUseCacheIp; 417518678f8Sopenharmony_ci}; 418518678f8Sopenharmony_ci#endif