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_SERVER_H 17 #define OHOS_DHCP_SERVER_H 18 19 #include "dhcp_config.h" 20 #include "dhcp_s_define.h" 21 #include "dhcp_message.h" 22 23 enum DhcpServerState { ST_IDEL = 0, ST_STARTING, ST_RUNNING, ST_RELOADNG, ST_STOPING, ST_STOPED }; 24 typedef int (*DhcpServerCallback)(int, int, const char *ifname); 25 typedef void(*DeviceConnectFun)(const char *ifname); 26 #ifdef __cplusplus 27 extern "C" { 28 #endif 29 30 typedef struct ServerContext ServerContext; 31 typedef struct { 32 char ifname[IFACE_NAME_SIZE]; 33 ServerContext *instance; 34 } DhcpServerContext, *PDhcpServerContext; 35 36 PDhcpServerContext InitializeServer(DhcpConfig *config); 37 int StartDhcpServer(PDhcpServerContext ctx); 38 int StopDhcpServer(PDhcpServerContext ctx); 39 int GetServerStatus(PDhcpServerContext ctx); 40 void RegisterDhcpCallback(PDhcpServerContext ctx, DhcpServerCallback callback); 41 void RegisterDeviceChangedCallback(PDhcpServerContext ctx, DeviceConnectFun func); 42 int FreeServerContext(PDhcpServerContext *ctx); 43 int SaveLease(PDhcpServerContext ctx); 44 int ReceiveDhcpMessage(int sock, PDhcpMsgInfo msgInfo); 45 void NotifyConnetDeviceChanged(int replyType, PDhcpServerContext ctx); 46 int ReceiveDhcpMessage(int sock, PDhcpMsgInfo msgInfo); 47 int GetVendorIdentifierOption(PDhcpMsgInfo received); 48 int GetHostNameOption(PDhcpMsgInfo received, AddressBinding *bindin); 49 int ReplyCommontOption(PDhcpServerContext ctx, PDhcpMsgInfo reply); 50 int ParseDhcpOption(PDhcpMsgInfo received, AddressBinding *bindin); 51 int GetUserClassOption(PDhcpMsgInfo received, AddressBinding *bindin); 52 int GetRapidCommitOption(PDhcpMsgInfo received, AddressBinding *bindin); 53 int GetOnlyIpv6Option(PDhcpMsgInfo received, AddressBinding *bindin); 54 int GetPortalUrlOption(PDhcpMsgInfo received, AddressBinding *bindin); 55 #ifdef __cplusplus 56 } 57 #endif 58 #endif 59