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  #include "wifi_chip_modes.h"
17  #include <hdf_log.h>
18  
19  namespace OHOS {
20  namespace HDI {
21  namespace Wlan {
22  namespace Chip {
23  namespace V1_0 {
24  #define STA IfaceType::STA
25  #define AP IfaceType::AP
26  #define P2P IfaceType::P2P
27  constexpr int STA_MAX_NUM = 3;
28  
WifiChipModes(const std::weak_ptr<WifiVendorHal> vendorHal)29  WifiChipModes::WifiChipModes(
30      const std::weak_ptr<WifiVendorHal> vendorHal)
31      : vendorHal_(vendorHal)
32  {}
33  
MakeComModes(int staNum,int apNum,int p2pNum,int modeId)34  UsableMode WifiChipModes::MakeComModes(int staNum, int apNum, int p2pNum, int modeId)
35  {
36      std::vector<IfaceType> staTypes = {};
37      std::vector<IfaceType> apTypes = {};
38      std::vector<IfaceType> p2pTypes = {};
39      std::vector<ComboIface> chipComb = {};
40      IfaceLimit staChipIfaceComb;
41      IfaceLimit apChipIfaceComb;
42      IfaceLimit p2pChipIfaceComb;
43  
44      staTypes.push_back(STA);
45      staChipIfaceComb.types = staTypes;
46      staChipIfaceComb.ifaceNum = staNum;
47      apTypes.push_back(AP);
48      apChipIfaceComb.types = apTypes;
49      apChipIfaceComb.ifaceNum = apNum;
50      p2pTypes.push_back(P2P);
51      p2pChipIfaceComb.types = p2pTypes;
52      p2pChipIfaceComb.ifaceNum = p2pNum;
53      ComboIface comb;
54      if (staNum != 0)
55          comb.limits.push_back(staChipIfaceComb);
56      if (apNum != 0)
57          comb.limits.push_back(apChipIfaceComb);
58      if (p2pNum != 0)
59          comb.limits.push_back(p2pChipIfaceComb);
60      chipComb.push_back(comb);
61      UsableMode chipmode = {};
62      chipmode.modeId = modeId;
63      chipmode.usableCombo = chipComb;
64      return chipmode;
65  }
66  
GetChipModesForPrimary()67  std::vector<UsableMode> WifiChipModes::GetChipModesForPrimary()
68  {
69      std::vector<UsableMode> modes = {};
70      UsableMode mode = MakeComModes(3, 0, 1, 0);
71      modes.push_back(mode);
72      UsableMode modeAp = MakeComModes(0, 1, 0, 1);
73      modes.push_back(modeAp);
74      return modes;
75  }
76  
GetChipModesForTriple()77  std::vector<UsableMode> WifiChipModes::GetChipModesForTriple()
78  {
79      std::vector<UsableMode> modes = {};
80      UsableMode mode = MakeComModes(STA_MAX_NUM, 1, 1, 0);
81      modes.push_back(mode);
82      return modes;
83  }
84  
GetChipModes(bool isPrimary)85  std::vector<UsableMode> WifiChipModes::GetChipModes(bool isPrimary)
86  {
87      bool isCoex;
88      vendorHal_.lock()->IsSupportCoex(isCoex);
89      if (isCoex) {
90          return GetChipModesForTriple();
91      } else {
92          return GetChipModesForPrimary();
93      }
94  }
95  }
96  }
97  }
98  }
99  }