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