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_SERVICE_H 17 #define OHOS_DHCP_SERVICE_H 18 19 #include "i_dhcp_service.h" 20 #include "dhcp_define.h" 21 #include "dhcp_client_service_impl.h" 22 #include "dhcp_server_service.h" 23 24 25 namespace OHOS { 26 namespace Wifi { 27 class DhcpService : public IDhcpService { 28 public: 29 /** 30 * @Description : Construct a new dhcp service object. 31 * 32 */ 33 DhcpService(); 34 35 /** 36 * @Description : Destroy the dhcp service object. 37 * 38 */ 39 ~DhcpService() override; 40 41 /** 42 * @Description : Start dhcp client service of specified interface. 43 * 44 * @param ifname - interface name, eg:wlan0 [in] 45 * @param bIpv6 - can or not get ipv6 [in] 46 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 47 */ 48 int StartDhcpClient(const std::string& ifname, bool bIpv6) override; 49 50 /** 51 * @Description : Stop dhcp client service of specified interface. 52 * 53 * @param ifname - interface name, eg:wlan0 [in] 54 * @param bIpv6 - can or not get ipv6 [in] 55 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 56 */ 57 int StopDhcpClient(const std::string& ifname, bool bIpv6) override; 58 59 /** 60 * @Description : Obtain the dhcp result of specified interface asynchronously. 61 * 62 * @param ifname - interface name, eg:wlan0 [in] 63 * @param dhcp - dhcp result notify [in] 64 * @param timeouts - timeout interval [in] 65 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 66 */ 67 int GetDhcpResult(const std::string& ifname, IDhcpResultNotify *pResultNotify, int timeouts) override; 68 69 /** 70 * @Description : Obtain the dhcp info of specified interface synchronously. 71 * 72 * @param ifname - interface name, eg:wlan0 [in] 73 * @param dhcp - dhcp info [out] 74 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 75 */ 76 int GetDhcpInfo(const std::string& ifname, DhcpServiceInfo& dhcp) override; 77 78 /** 79 * @Description : Renew dhcp client service of specified interface. 80 * 81 * @param ifname - interface name, eg:wlan0 [in] 82 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 83 */ 84 int RenewDhcpClient(const std::string& ifname) override; 85 86 /** 87 * @Description : Release dhcp client service of specified interface. 88 * 89 * @param ifname - interface name, eg:wlan0 [in] 90 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 91 */ 92 int ReleaseDhcpClient(const std::string& ifname) override; 93 94 /** 95 * @Description : Start dhcp server service of specified interface. 96 * 97 * @param ifname - interface name, eg:wlan0 [in] 98 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 99 */ 100 int StartDhcpServer(const std::string& ifname) override; 101 102 /** 103 * @Description : Stop dhcp server service of specified interface. 104 * 105 * @param ifname - interface name, eg:wlan0 [in] 106 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 107 */ 108 int StopDhcpServer(const std::string& ifname) override; 109 110 /** 111 * @Description : Get dhcp server service running status. 112 * 113 * @Return : 0 - not start, 1 - normal started. 114 */ 115 int GetServerStatus(void) override; 116 117 /** 118 * @Description : Add or update dhcp ip address pool. 119 * 120 * @param tagName - ip address pool tag name [in] 121 * @param range - ip address range [in] 122 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 123 */ 124 int PutDhcpRange(const std::string& tagName, const DhcpRange& range) override; 125 126 /** 127 * @Description : Remove dhcp ip address pool. 128 * 129 * @param tagName - ip address pool tag name [in] 130 * @param range - ip address range [in] 131 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 132 */ 133 int RemoveDhcpRange(const std::string& tagName, const DhcpRange& range) override; 134 135 /** 136 * @Description : Remove all dhcp ip address pool. 137 * 138 * @param tagName - ip address pool tag name [in] 139 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 140 */ 141 int RemoveAllDhcpRange(const std::string& tagName) override; 142 143 /** 144 * @Description : Set dhcp ip address pool of specified interface. 145 * 146 * @param ifname - interface name, eg:wlan0 [in] 147 * @param range - ip address range [in] 148 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 149 */ 150 int SetDhcpRange(const std::string& ifname, const DhcpRange& range) override; 151 152 /** 153 * @Description : Set dhcp ip address pool of specified interface. 154 * 155 * @param ifname - interface name, eg:wlan0 [in] 156 * @param tagName - ip address pool tag name [in] 157 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 158 */ 159 int SetDhcpRange(const std::string& ifname, const std::string& tagName) override; 160 161 /** 162 * @Description : Get dhcp server lease info. 163 * 164 * @param ifname - interface name, eg:wlan0 [in] 165 * @param leases - lease info [out] 166 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 167 */ 168 int GetLeases(const std::string& ifname, std::vector<std::string>& leases) override; 169 170 /** 171 * @Description : Obtain the abnormal exit status of dhcp server process. 172 * 173 * @param ifname - interface name, eg:wlan0 [in] 174 * @param pResultNotify - pointer to dhcp result notify [in] 175 * @Return : success - DHCP_OPT_SUCCESS, failed - others. 176 */ 177 int GetDhcpSerProExit(const std::string& ifname, IDhcpResultNotify *pResultNotify) override; 178 179 private: 180 int InitServerService(void); 181 bool CheckIfaceValid(const std::string& ifname); 182 183 private: 184 std::unique_ptr<IDhcpClientService> m_pClientService; 185 std::unique_ptr<IDhcpServerService> m_pServerService; 186 }; 187 } // namespace Wifi 188 } // namespace OHOS 189 #endif 190