1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef WIFI_CHIP_H 17094332d3Sopenharmony_ci#define WIFI_CHIP_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include <list> 20094332d3Sopenharmony_ci#include <map> 21094332d3Sopenharmony_ci#include <mutex> 22094332d3Sopenharmony_ci#include "v1_0/iconcrete_chip.h" 23094332d3Sopenharmony_ci#include "v1_0/chip_types.h" 24094332d3Sopenharmony_ci#include "iface_tool.h" 25094332d3Sopenharmony_ci#include "wifi_vendor_hal_list.h" 26094332d3Sopenharmony_ci#include "wifi_chip_modes.h" 27094332d3Sopenharmony_ci#include "callback_handler.h" 28094332d3Sopenharmony_ci#include "v1_0/ichip_iface.h" 29094332d3Sopenharmony_ci#include "wifi_ap_iface.h" 30094332d3Sopenharmony_ci#include "wifi_sta_iface.h" 31094332d3Sopenharmony_ci#include "wifi_p2p_iface.h" 32094332d3Sopenharmony_ci#include "wifi_ext_iface.h" 33094332d3Sopenharmony_ci#include "iface_util.h" 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_cinamespace OHOS { 36094332d3Sopenharmony_cinamespace HDI { 37094332d3Sopenharmony_cinamespace Wlan { 38094332d3Sopenharmony_cinamespace Chip { 39094332d3Sopenharmony_cinamespace V1_0 { 40094332d3Sopenharmony_ciclass WifiChip : public IConcreteChip { 41094332d3Sopenharmony_cipublic: 42094332d3Sopenharmony_ci WifiChip(int32_t chipId, bool isPrimary, 43094332d3Sopenharmony_ci const std::weak_ptr<WifiVendorHal> vendorHal, 44094332d3Sopenharmony_ci const std::shared_ptr<IfaceUtil> ifaceUtil, 45094332d3Sopenharmony_ci const std::function<void(const std::string&)> &subsystemCallbackHandler); 46094332d3Sopenharmony_ci ~WifiChip(); 47094332d3Sopenharmony_ci void Invalidate(); 48094332d3Sopenharmony_ci bool IsValid(); 49094332d3Sopenharmony_ci int32_t GetChipId(int32_t& id) override; 50094332d3Sopenharmony_ci int32_t RegisterChipEventCallback(const sptr<IConcreteChipCallback>& chipEventcallback) override; 51094332d3Sopenharmony_ci int32_t GetChipCaps(uint32_t& capabilities) override; 52094332d3Sopenharmony_ci int32_t GetChipModes(std::vector<UsableMode>& modes) override; 53094332d3Sopenharmony_ci int32_t GetCurrentMode(uint32_t& modeId) override; 54094332d3Sopenharmony_ci int32_t SetChipMode(uint32_t modeId) override; 55094332d3Sopenharmony_ci int32_t CreateApService(sptr<IChipIface>& iface) override; 56094332d3Sopenharmony_ci int32_t GetApServiceIfNames(std::vector<std::string>& ifnames) override; 57094332d3Sopenharmony_ci int32_t GetApService(const std::string& ifname, sptr<IChipIface>& iface) override; 58094332d3Sopenharmony_ci int32_t RemoveApService(const std::string& ifname) override; 59094332d3Sopenharmony_ci int32_t CreateP2pService(sptr<IChipIface>& iface) override; 60094332d3Sopenharmony_ci int32_t GetP2pServiceIfNames(std::vector<std::string>& ifnames) override; 61094332d3Sopenharmony_ci int32_t GetP2pService(const std::string& ifname, sptr<IChipIface>& iface) override; 62094332d3Sopenharmony_ci int32_t RemoveP2pService(const std::string& ifname) override; 63094332d3Sopenharmony_ci int32_t CreateStaService(sptr<IChipIface>& iface) override; 64094332d3Sopenharmony_ci int32_t GetStaServiceIfNames(std::vector<std::string>& ifnames) override; 65094332d3Sopenharmony_ci int32_t GetStaService(const std::string& ifname, sptr<IChipIface>& iface) override; 66094332d3Sopenharmony_ci int32_t RemoveStaService(const std::string& ifname) override; 67094332d3Sopenharmony_ci int32_t CreateExtService(const std::string& ifName, sptr<IChipIface>& iface) override; 68094332d3Sopenharmony_ci int32_t GetExtService(const std::string& ifName, sptr<IChipIface>& iface) override; 69094332d3Sopenharmony_ci int32_t RemoveExtService(const std::string& ifName) override; 70094332d3Sopenharmony_ci 71094332d3Sopenharmony_ciprivate: 72094332d3Sopenharmony_ci std::string GetIfaceName(IfaceType type, unsigned idx); 73094332d3Sopenharmony_ci std::string GetUsedIfaceName(); 74094332d3Sopenharmony_ci bool CanSupportIfaceType(IfaceType type); 75094332d3Sopenharmony_ci bool CanExpandedIfaceSupportIfaceType( 76094332d3Sopenharmony_ci const std::map<IfaceType, size_t>& expandedCombo, IfaceType type); 77094332d3Sopenharmony_ci std::vector<ComboIface> GetCurrentCombinations(); 78094332d3Sopenharmony_ci std::map<IfaceType, size_t> GetCurrentIfaceCombo(); 79094332d3Sopenharmony_ci std::vector<std::map<IfaceType, size_t>> ExpandIfaceCombinations( 80094332d3Sopenharmony_ci const ComboIface& combination); 81094332d3Sopenharmony_ci bool IsValidModeId(uint32_t modeId); 82094332d3Sopenharmony_ci std::string AllocIfaceName(IfaceType type, uint32_t startIdx); 83094332d3Sopenharmony_ci bool CanExpandedIfaceComboSupportIfaceCombo( 84094332d3Sopenharmony_ci const std::map<IfaceType, size_t>& expandedCombo, 85094332d3Sopenharmony_ci const std::map<IfaceType, size_t>& reqCombo); 86094332d3Sopenharmony_ci bool CanCurrentModeSupportIfaceCombo( 87094332d3Sopenharmony_ci const std::map<IfaceType, size_t>& reqCombo); 88094332d3Sopenharmony_ci bool IsDualStaSupportInCurrentMode(); 89094332d3Sopenharmony_ci bool IsStaApCoexInCurrentMode(); 90094332d3Sopenharmony_ci uint32_t IdxOfApIface(); 91094332d3Sopenharmony_ci std::string AllocateApIfaceName(); 92094332d3Sopenharmony_ci sptr<WifiApIface> NewApIface(std::string& ifname); 93094332d3Sopenharmony_ci void SetUsedIfaceNameProperty(const std::string& ifname); 94094332d3Sopenharmony_ci int32_t CreateVirtualApInterface(const std::string& apVirtIf); 95094332d3Sopenharmony_ci std::string GetDefaultP2pIfaceName(); 96094332d3Sopenharmony_ci std::string AllocateStaIfaceName(); 97094332d3Sopenharmony_ci int32_t HandleChipConfiguration(int32_t modeId); 98094332d3Sopenharmony_ci int32_t chipId_; 99094332d3Sopenharmony_ci std::weak_ptr<WifiVendorHal> vendorHal_; 100094332d3Sopenharmony_ci std::vector<sptr<WifiApIface>> apIfaces_; 101094332d3Sopenharmony_ci std::vector<sptr<WifiP2pIface>> p2pIfaces_; 102094332d3Sopenharmony_ci std::vector<sptr<WifiStaIface>> staIfaces_; 103094332d3Sopenharmony_ci std::vector<sptr<WifiExtIface>> extIfaces_; 104094332d3Sopenharmony_ci bool isValid_; 105094332d3Sopenharmony_ci uint32_t currentModeId_; 106094332d3Sopenharmony_ci std::shared_ptr<IfaceUtil> ifaceUtil_; 107094332d3Sopenharmony_ci CallbackHandler<IConcreteChipCallback> cbHandler_; 108094332d3Sopenharmony_ci const std::function<void(const std::string&)> subsystemCallbackHandler_; 109094332d3Sopenharmony_ci}; 110094332d3Sopenharmony_ci} 111094332d3Sopenharmony_ci} 112094332d3Sopenharmony_ci} 113094332d3Sopenharmony_ci} 114094332d3Sopenharmony_ci} 115094332d3Sopenharmony_ci#endif