1 /* 2 * Copyright (c) 2024 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 WIFI_CHIP_H 17 #define WIFI_CHIP_H 18 19 #include <list> 20 #include <map> 21 #include <mutex> 22 #include "v1_0/iconcrete_chip.h" 23 #include "v1_0/chip_types.h" 24 #include "iface_tool.h" 25 #include "wifi_vendor_hal_list.h" 26 #include "wifi_chip_modes.h" 27 #include "callback_handler.h" 28 #include "v1_0/ichip_iface.h" 29 #include "wifi_ap_iface.h" 30 #include "wifi_sta_iface.h" 31 #include "wifi_p2p_iface.h" 32 #include "iface_util.h" 33 34 namespace OHOS { 35 namespace HDI { 36 namespace Wlan { 37 namespace Chip { 38 namespace V1_0 { 39 class WifiChip : public IConcreteChip { 40 public: 41 WifiChip(int32_t chipId, bool isPrimary, 42 const std::weak_ptr<WifiVendorHal> vendorHal, 43 const std::shared_ptr<IfaceUtil> ifaceUtil, 44 const std::function<void(const std::string&)> &subsystemCallbackHandler); 45 ~WifiChip(); 46 void Invalidate(); 47 bool IsValid(); 48 int32_t GetChipId(int32_t& id) override; 49 int32_t RegisterChipEventCallback(const sptr<IConcreteChipCallback>& chipEventcallback) override; 50 int32_t GetChipCaps(uint32_t& capabilities) override; 51 int32_t GetChipModes(std::vector<UsableMode>& modes) override; 52 int32_t GetCurrentMode(uint32_t& modeId) override; 53 int32_t SetChipMode(uint32_t modeId) override; 54 int32_t CreateApService(sptr<IChipIface>& iface) override; 55 int32_t GetApServiceIfNames(std::vector<std::string>& ifnames) override; 56 int32_t GetApService(const std::string& ifname, sptr<IChipIface>& iface) override; 57 int32_t RemoveApService(const std::string& ifname) override; 58 int32_t CreateP2pService(sptr<IChipIface>& iface) override; 59 int32_t GetP2pServiceIfNames(std::vector<std::string>& ifnames) override; 60 int32_t GetP2pService(const std::string& ifname, sptr<IChipIface>& iface) override; 61 int32_t RemoveP2pService(const std::string& ifname) override; 62 int32_t CreateStaService(sptr<IChipIface>& iface) override; 63 int32_t GetStaServiceIfNames(std::vector<std::string>& ifnames) override; 64 int32_t GetStaService(const std::string& ifname, sptr<IChipIface>& iface) override; 65 int32_t RemoveStaService(const std::string& ifname) override; 66 67 private: 68 std::string GetIfaceName(IfaceType type, unsigned idx); 69 std::string GetUsedIfaceName(); 70 bool CanSupportIfaceType(IfaceType type); 71 bool CanExpandedIfaceSupportIfaceType( 72 const std::map<IfaceType, size_t>& expandedCombo, IfaceType type); 73 std::vector<ComboIface> GetCurrentCombinations(); 74 std::map<IfaceType, size_t> GetCurrentIfaceCombo(); 75 std::vector<std::map<IfaceType, size_t>> ExpandIfaceCombinations( 76 const ComboIface& combination); 77 bool IsValidModeId(uint32_t modeId); 78 std::string AllocIfaceName(IfaceType type, uint32_t startIdx); 79 bool CanExpandedIfaceComboSupportIfaceCombo( 80 const std::map<IfaceType, size_t>& expandedCombo, 81 const std::map<IfaceType, size_t>& reqCombo); 82 bool CanCurrentModeSupportIfaceCombo( 83 const std::map<IfaceType, size_t>& reqCombo); 84 bool IsDualStaSupportInCurrentMode(); 85 bool IsStaApCoexInCurrentMode(); 86 uint32_t IdxOfApIface(); 87 std::string AllocateApIfaceName(); 88 sptr<WifiApIface> NewApIface(std::string& ifname); 89 void SetUsedIfaceNameProperty(const std::string& ifname); 90 int32_t CreateVirtualApInterface(const std::string& apVirtIf); 91 std::string GetDefaultP2pIfaceName(); 92 std::string AllocateStaIfaceName(); 93 int32_t HandleChipConfiguration(int32_t modeId); 94 int32_t chipId_; 95 std::weak_ptr<WifiVendorHal> vendorHal_; 96 std::vector<sptr<WifiApIface>> apIfaces_; 97 std::vector<sptr<WifiP2pIface>> p2pIfaces_; 98 std::vector<sptr<WifiStaIface>> staIfaces_; 99 bool isValid_; 100 uint32_t currentModeId_; 101 std::shared_ptr<IfaceUtil> ifaceUtil_; 102 CallbackHandler<IConcreteChipCallback> cbHandler_; 103 const std::function<void(const std::string&)> subsystemCallbackHandler_; 104 }; 105 } 106 } 107 } 108 } 109 } 110 #endif