• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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_HID2D_CFG_H
17 #define OHOS_WIFI_HID2D_CFG_H
18 
19 #include <vector>
20 #include <string>
21 #include "wifi_common_util.h"
22 #include "wifi_hid2d_msg.h"
23 
24 namespace OHOS {
25 namespace Wifi {
26 enum class DeviceType {
27     /** phone device type id */
28     DEVICE_TYPE_PHONE_ID = 0,
29     /** pad device type id */
30     DEVICE_TYPE_PAD_ID = 1,
31     /** pad tv type id */
32     DEVICE_TYPE_TV_ID = 2,
33     /** pad pc type id */
34     DEVICE_TYPE_PC_ID = 3,
35     /** pad display type id */
36     DEVICE_TYPE_DISPLAY_ID = 4,
37     /** pad car type id */
38     DEVICE_TYPE_CAR_ID = 5,
39 };
40 
41 enum class DeviceClass {
42     Default,
43     TABLET,
44     TV,
45     CAR
46 };
47 
48 class DeviceWifiInfo {
49 public:
50     DeviceWifiInfo();
51 
52     ~DeviceWifiInfo();
53 
54     DeviceClass GetDeviceClass();
55 
56     void UpdateDeviceCapability();
57 
58     void ResetWifiDeviceCfg();
59 
60     int GetVersion();
61 
62     void SetVerison(int version);
63 
64     bool GetCapsOfChooseP2pChannelOpt();
65 
66     void SetCapsOfChooseP2pChannelOpt(bool isEnabled);
67 
68     bool GetCapsOfDbdc();
69 
70     void SetCapsOfDbdc(bool isSupportDbdc);
71 
72     bool GetCapsOfCsa();
73 
74     void SetCapsOfCsa(bool isSupportCsa);
75 
76     bool GetCapsOfP2pRadarDetect();
77 
78     void SetCapsOfP2pRadarDetect(bool isP2pSupportRadarDetect);
79 
80     bool GetCapsOfP2pDfsChannel();
81 
82     void SetCapsOfP2pDfsChannel(bool isP2pSupportDfsChannel);
83 
84     bool GetCapsOfP2pIndoorChannel();
85 
86     void SetCapsOfP2pIndoorChannel(bool isP2pSupportIndoorChannel);
87 
88     void SetStaChannel(int channel);
89 
90     int GetStaChannel();
91 
92     bool GetApType();
93 
94     void SetApType(bool isPortalAp);
95 
96     std::string GetCurrentApSsid();
97 
98     void SetCurrentApSsid(const std::string& ssid);
99 
100     std::string GetCurrentApBssid();
101 
102     void SetCurrentApBssid(const std::string& bssid);
103 
104     void SetCurrentApHasInternet(bool hasInternet);
105 
106     bool GetCurrentApHasInternet();
107 
108     std::vector<int> GetP2pSupportChannel();
109 
110     void SetP2pSupportChannel(std::vector<int>& channels);
111 
112     std::string GetApPwd();
113 
114     void SetApPwd(const std::string& pwd);
115 
116     int GetApSecurityType();
117 
118     void SetApSecurityType(int securityType);
119 
120     int GetRouterType();
121 
122     std::string GenerateSessionId();
123 
124     std::string GetSessionId();
125 
126     /**
127      * set SessionId of current cast service
128      *
129      * @param sessionId input sessionId generated by p2p go
130      */
131     void SetSessionId(std::string sessionId);
132 
133     /**
134      * clear SessionId of current cast service
135      */
136     void ClearSessionId();
137 
138     void SetRouteType(int routerType);
139 
140     DeviceClass GetDeviceType();
141 
142     /**
143      * set Go or Gc device type
144      *
145      * @param deviceType input Go or Gc device type
146      */
147     void SetDeviceType(DeviceClass deviceType);
148 
149     /**
150      * get device config value from type
151      *
152      * @param type device wifi config type
153      * @return the type value
154      */
155     int GetValueFromType(int type);
156 
157     /**
158      * set device config info according type
159      *
160      * @param type device wifi config type
161      * @param inputValue the value of type
162      */
163     void SetDeviceCfg(int type, int inputValue);
164 
165 private:
166     int m_version; // dual band adaptive concurrent
167     bool m_isChooseP2pChannelOpt;
168     bool m_isSupportDbdc;
169     bool m_isSupportCsa;
170     bool m_isP2pSupportRadarDetect;
171     bool m_isP2pSupportDfsChannel;
172     bool m_isP2pSupportIndoorChannel;
173     bool m_isPortalAp;
174     int m_staChannel;
175     std::string m_currentApSsid;
176     std::string m_currentApBssid;
177     bool m_isCurrentApHasInternet;
178     std::vector<int> m_P2pSupportChannelList;
179     std::string m_pwd;
180     std::string m_sessionId;
181     int m_securityType;
182     int m_routerType;
183     DeviceClass m_deviceType;
184 };
185 
186 class WifiHid2dCfg {
187 public:
188     static WifiHid2dCfg& GetInstance();
189 
190     DeviceWifiInfo& GetSelfDeviceCfgInfo();
191 
192     DeviceWifiInfo& GetPeerDeviceCfgInfo();
193 
194     /**
195      * get self device configuration in TLV format:type + length + value
196      *
197      * @param cfgType self wifi configuration type
198      * @param cfgInfo configuration information
199      * @param getDatValidLen configuration valid length
200      */
201     void GetSelfDeviceCfg(SelfCfgType cfgType, char cfgInfo[CFG_DATA_MAX_BYTES], int& getDatValidLen);
202 
203     /**
204      * set peer wifi p2p config info
205      *
206      * @param cfgType self wifi configuration type
207      * @param cfgData byte array
208      * @param setDataValidLen the valid length of "cfgData"
209      * @return 0: success, -1: fail
210      */
211     int Hid2dSetPeerWifiCfgInfo(PeerCfgType cfgType, char cfgInfo[CFG_DATA_MAX_BYTES], int setDataValidLen);
212 
213 private:
214     WifiHid2dCfg();
215 
216     ~WifiHid2dCfg();
217 
218     std::string ParseStringFromByteArray(char* data, int dataLen, int index, int maxLength);
219 
220     /** 2.4g channel count from channel 1 to channel 11 */
221     void ParseP2pSupportChannelFromByteArray(char* data, int dataLen, int index, std::vector<int>& p2pSupportChannels);
222 
223     void HandlePeerApPassword();
224 
225     void HandleTlvData(int type, char* cfgData, int cfgDataLen, int index);
226 
227     int ParsePeerDeviceCfgInfo(PeerCfgType cfgType, char* cfgData, int cfgDataLen);
228 
229     int ParsePeerDeviceStaChanngeInfo(PeerCfgType cfgType, char* cfgData, int cfgDataLen);
230 
231     /**
232      * find the value of index in byte array
233      *
234      * @param data byte array
235      * @param value intput the value to find index
236      * @return index in byte array
237      */
238     int FindIndexFromByteArray(char* data, int dataLen, int value);
239 
240     int SetBssidByte(int typeBssidValue, char* dataArray, int dataArrayLen, int offset);
241 
242     int SetP2pSupportChannelByte(char* dataArray, int dataArrayLen, int offset);
243 
244     int BuildTlvForIntVal(int type, int Value, char* tlvData, int tlvDataLen, int offset);
245 
246     int BuildTlvForStrVal(int type, std::string value, char* tlvData, int tlvDataLen, int offset);
247 
248     void HandlePeerStaStateChange(char* data, int dataLen, int index);
249 
250 private:
251     static DeviceWifiInfo m_selfDeviceInfo;
252     static DeviceWifiInfo m_peerDeviceInfo;
253 };
254 }  // namespace Wifi
255 }  // namespace OHOS
256 #endif