1 /* 2 * Copyright (C) 2021 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_WIFI_HOTSPOT_SERVICE_IMPL_H 17 #define OHOS_WIFI_HOTSPOT_SERVICE_IMPL_H 18 19 #include "wifi_ap_msg.h" 20 #include "wifi_config_center.h" 21 #include "wifi_errcode.h" 22 #include "wifi_hotspot_stub.h" 23 24 namespace OHOS { 25 namespace Wifi { 26 constexpr int MAX_IPV4_SPLIT_LEN = 4; 27 constexpr int MAX_IPV4_VALUE = 255; 28 class WifiHotspotServiceImpl : public WifiHotspotStub { 29 public: 30 WifiHotspotServiceImpl(); 31 explicit WifiHotspotServiceImpl(int id); 32 virtual ~WifiHotspotServiceImpl(); 33 /** 34 * @Description Check whether the hotspot is active. 35 * 36 * @param bActive - hotspot state 37 * @return ErrCode - operation result 38 */ 39 ErrCode IsHotspotActive(bool &bActive) override; 40 41 /** 42 * @Description Check whether the hotspot supports dual band. 43 * 44 * @param isSpuported - Supported / NOT supported 45 * @return ErrCode - operation result 46 */ 47 ErrCode IsHotspotDualBandSupported(bool &isSpuported) override; 48 49 /** 50 * @Description Get the Hotspot Config object 51 * 52 * @param state - Result of obtaining the hotspot status 53 * @return ErrCode - operation result 54 */ 55 ErrCode GetHotspotState(int &state) override; 56 57 /** 58 * @Description Get the Hotspot State object 59 * 60 * @param config - Current hotspot configuration 61 * @return ErrCode - operation result 62 */ 63 ErrCode GetHotspotConfig(HotspotConfig &config) override; 64 65 /** 66 * @Description Set the configuration of Hotspot 67 * 68 * @param config - HotspotConfig object, 69 * @return ErrCode - operation result 70 */ 71 ErrCode SetHotspotConfig(const HotspotConfig &config) override; 72 73 /** 74 * @Description Set the idel timeout of Hotspot 75 * 76 * @param time -input time, 77 * @return ErrCode - operation result 78 */ 79 ErrCode SetHotspotIdleTimeout(int time) override; 80 81 /** 82 * @Description Get the Station List object 83 * 84 * @param result - Get result vector of connect Station Info 85 * @return ErrCode - operation result 86 */ 87 ErrCode GetStationList(std::vector<StationInfo> &result) override; 88 89 /** 90 * @Description Disconnects a specified sta connection when ap is opened 91 * 92 * @param info - StationInfo object 93 * @return ErrCode - operation result 94 */ 95 ErrCode DisassociateSta(const StationInfo &info) override; 96 97 /** 98 * @Description Enable Hotspot 99 * 100 * @return ErrCode - operation result 101 */ 102 ErrCode EnableHotspot(const ServiceType type = ServiceType::DEFAULT) override; 103 104 /** 105 * @Description Disable Hotspot 106 * 107 * @return ErrCode - operation result 108 */ 109 ErrCode DisableHotspot(const ServiceType type = ServiceType::DEFAULT) override; 110 111 /** 112 * @Description Get the Block Lists object 113 * 114 * @param infos - Get Blocklist result vector of StationInfo 115 * @return ErrCode - operation result 116 */ 117 ErrCode GetBlockLists(std::vector<StationInfo> &infos) override; 118 119 /** 120 * @Description Add a StationInfo object to Blocklist when ap is opened 121 * 122 * @param info - StationInfo object 123 * @return ErrCode - operation result 124 */ 125 ErrCode AddBlockList(const StationInfo &info) override; 126 127 /** 128 * @Description Del a StationInfo object from Blocklist 129 * 130 * @param info - StationInfo object 131 * @return ErrCode - operation result 132 */ 133 ErrCode DelBlockList(const StationInfo &info) override; 134 135 /** 136 * @Description Get the Valid Bands object 137 * 138 * @param bands - Get result vector of BandType when ap is opened 139 * @return ErrCode - operation result 140 */ 141 ErrCode GetValidBands(std::vector<BandType> &bands) override; 142 143 /** 144 * @Description Get the Valid Channels object when ap is opened 145 * 146 * @param band - Specified Valid Band. 147 * @param validchannels - Obtains the channels corresponding to the specified band 148 * @return ErrCode - operation result 149 */ 150 ErrCode GetValidChannels(BandType band, std::vector<int32_t> &validchannels) override; 151 152 /** 153 * @Description Register callback client 154 * 155 * @param callback - callback struct 156 * @return ErrCode - operation result 157 */ 158 ErrCode RegisterCallBack(const sptr<IWifiHotspotCallback> &callback, 159 const std::vector<std::string> &event) override; 160 161 /** 162 * @Description Get supported feature 163 * 164 * @param features - return supported feature 165 * @return ErrCode - operation result 166 */ 167 ErrCode GetSupportedFeatures(long &features) override; 168 169 /** 170 * @Description Get supported power model list 171 * 172 * @param setPowerModelList - supported power model list 173 * @return ErrCode - operation result 174 */ 175 ErrCode GetSupportedPowerModel(std::set<PowerModel>& setPowerModelList) override; 176 177 /** 178 * @Description Get power model 179 * 180 * @param model - current power model 181 * @return ErrCode - operation result 182 */ 183 ErrCode GetPowerModel(PowerModel& model) override; 184 185 /** 186 * @Description Get supported power model list 187 * 188 * @param model - the model to be set 189 * @return ErrCode - operation result 190 */ 191 ErrCode SetPowerModel(const PowerModel& model) override; 192 193 /** 194 * @Description Dump sa basic information 195 * 196 * @param result[out] - dump result 197 */ 198 static void SaBasicDump(std::string& result); 199 200 /** 201 * @Description Check whether service is died. 202 * 203 * @return bool - true: service is died, false: service is not died. 204 */ 205 bool IsRemoteDied(void) override; 206 207 /** 208 * @Description Check valid ssid config 209 * 210 * @param cfg - HotspotConfig 211 * @return ErrCode - WIFI_OPT_SUCCESS or others 212 */ 213 ErrCode CfgCheckSsid(const HotspotConfig &cfg); 214 215 /** 216 * @Description Check valid psk config 217 * 218 * @param cfg - HotspotConfig 219 * @return ErrCode - WIFI_OPT_SUCCESS or others 220 */ 221 ErrCode CfgCheckPsk(const HotspotConfig &cfg); 222 223 /** 224 * @Description Check valid band config 225 * 226 * @param cfg - HotspotConfig 227 * @param bandsFromCenter - vector of BandType 228 * @return ErrCode - WIFI_OPT_SUCCESS or others 229 */ 230 ErrCode CfgCheckBand(const HotspotConfig &cfg, std::vector<BandType> &bandsFromCenter); 231 232 /** 233 * @Description Check valid channel config 234 * 235 * @param cfg - HotspotConfig 236 * @param channInfoFromCenter - ChannelsTable object 237 * @return ErrCode - WIFI_OPT_SUCCESS or others 238 */ 239 ErrCode CfgCheckChannel(const HotspotConfig &cfg, ChannelsTable &channInfoFromCenter); 240 241 /** 242 * @Description Check dhcp server ip address 243 * 244 * @param ipAddress - string 245 * @return ErrCode - WIFI_OPT_SUCCESS or others 246 */ 247 ErrCode CfgCheckIpAddress(const std::string &ipAddress); 248 249 /** 250 * @Description Check valid hotspot config 251 * 252 * @param cfg - HotspotConfig 253 * @param cfgFromCenter - Get HotspotConfig from config center 254 * @param bandsFromCenter - vector of BandType 255 * @param channInfoFromCenter - ChannelsTable object 256 * @return ErrCode - WIFI_OPT_SUCCESS or others 257 */ 258 ErrCode IsValidHotspotConfig(const HotspotConfig &cfg, const HotspotConfig &cfgFromCenter, 259 std::vector<BandType> &bandsFromCenter, ChannelsTable &channInfoFromCenter); 260 261 /** 262 * @Description Get ap iface name 263 * 264 * @param ifaceName - the ifaceName to be set 265 * @return ErrCode - operation result 266 */ 267 ErrCode GetApIfaceName(std::string& ifaceName) override; 268 /** 269 * @Description convert randomMac to realMac 270 * 271 * @param ifaceName - the ifaceName to be set 272 * @return ErrCode - operation result 273 */ 274 ErrCode TransRandomToRealMac(StationInfo &updateInfo, const StationInfo &info); 275 private: 276 ErrCode CheckCanEnableHotspot(const ServiceType type); 277 int CheckOperHotspotSwitchPermission(const ServiceType type); 278 bool IsApServiceRunning(); 279 static void ConfigInfoDump(std::string& result); 280 static void StationsInfoDump(std::string& result); 281 282 private: 283 bool mGetChannels = false; 284 }; 285 } // namespace Wifi 286 } // namespace OHOS 287 #endif 288