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 #include "negotiate_message.h"
16
17 #include "conn_log.h"
18 #include "softbus_error_code.h"
19
20 #include "protocol/wifi_direct_protocol_factory.h"
21 #include "utils/wifi_direct_utils.h"
22
23 namespace OHOS::SoftBus {
24 std::set<NegotiateMessageKey> NegotiateMessage::keyIgnoreTable_ = {
25 NegotiateMessageKey::REMOTE_DEVICE_ID,
26 };
27
28 std::map<NegotiateMessageKey, std::string> NegotiateMessage::keyStringTable_ = {
29 /* old p2p */
30 { NegotiateMessageKey::GC_CHANNEL_LIST, "KEY_GC_CHANNEL_LIST" },
31 { NegotiateMessageKey::STATION_FREQUENCY, "KEY_STATION_FREQUENCY" },
32 { NegotiateMessageKey::ROLE, "KEY_ROLE" },
33 { NegotiateMessageKey::EXPECTED_ROLE, "KEY_EXPECTED_ROLE" },
34 { NegotiateMessageKey::VERSION, "KEY_VERSION" },
35 { NegotiateMessageKey::GC_IP, "KEY_GC_IP" },
36 { NegotiateMessageKey::WIDE_BAND_SUPPORTED, "KEY_WIDE_BAND_SUPPORTED" },
37 { NegotiateMessageKey::GROUP_CONFIG, "KEY_GROUP_CONFIG" },
38 { NegotiateMessageKey::MAC, "KEY_MAC" },
39 { NegotiateMessageKey::BRIDGE_SUPPORTED, "KEY_BRIDGE_SUPPORTED" },
40 { NegotiateMessageKey::GO_IP, "KEY_GO_IP" },
41 { NegotiateMessageKey::GO_MAC, "KEY_GO_MAC" },
42 { NegotiateMessageKey::GO_PORT, "KEY_GO_PORT" },
43 { NegotiateMessageKey::IP, "KEY_IP" },
44 { NegotiateMessageKey::RESULT, "KEY_RESULT" },
45 { NegotiateMessageKey::CONTENT_TYPE, "KEY_CONTENT_TYPE" },
46 { NegotiateMessageKey::GC_MAC, "KEY_GC_MAC" },
47 { NegotiateMessageKey::SELF_WIFI_CONFIG, "KEY_SELF_WIFI_CONFIG" },
48 { NegotiateMessageKey::GC_CHANNEL_SCORE, "KEY_GC_CHANNEL_SCORE" },
49 { NegotiateMessageKey::COMMAND_TYPE, "KEY_COMMAND_TYPE" },
50 { NegotiateMessageKey::INTERFACE_NAME, "KEY_INTERFACE_NAME" },
51 };
52
53 template <>
54 InfoContainer<NegotiateMessageKey>::KeyTypeTable InfoContainer<NegotiateMessageKey>::keyTypeTable_ = {
55 { NegotiateMessageKey::MSG_TYPE, Serializable::ValueType::INT },
56 { NegotiateMessageKey::SESSION_ID, Serializable::ValueType::UINT },
57 { NegotiateMessageKey::WIFI_CFG_TYPE, Serializable::ValueType::INT },
58 { NegotiateMessageKey::WIFI_CFG_INFO, Serializable::ValueType::BYTE_ARRAY },
59 { NegotiateMessageKey::IPV4_INFO_ARRAY, Serializable::ValueType::IPV4_INFO_ARRAY },
60 { NegotiateMessageKey::PREFER_LINK_MODE, Serializable::ValueType::INT },
61 { NegotiateMessageKey::IS_MODE_STRICT, Serializable::ValueType::BOOL },
62 { NegotiateMessageKey::PREFER_LINK_BANDWIDTH, Serializable::ValueType::INT },
63 { NegotiateMessageKey::IS_BRIDGE_SUPPORTED, Serializable::ValueType::BOOL },
64 { NegotiateMessageKey::LINK_INFO, Serializable::ValueType::LINK_INFO },
65 { NegotiateMessageKey::RESULT_CODE, Serializable::ValueType::INT },
66 { NegotiateMessageKey::INTERFACE_INFO_ARRAY, Serializable::ValueType::INTERFACE_INFO_ARRAY },
67 { NegotiateMessageKey::REMOTE_DEVICE_ID, Serializable::ValueType::STRING },
68 { NegotiateMessageKey::EXTRA_DATA_ARRAY, Serializable::ValueType::BYTE_ARRAY },
69 { NegotiateMessageKey::INNER_LINK, Serializable::ValueType::INNER_LINK },
70 { NegotiateMessageKey::IS_PROXY_ENABLE, Serializable::ValueType::BOOL },
71 { NegotiateMessageKey::CHANNEL_5G_LIST, Serializable::ValueType::STRING },
72 { NegotiateMessageKey::CHANNEL_5G_SCORE, Serializable::ValueType::STRING },
73 { NegotiateMessageKey::CHALLENGE_CODE, Serializable::ValueType::UINT },
74
75 /* old p2p */
76 { NegotiateMessageKey::GC_CHANNEL_LIST, Serializable::ValueType::STRING },
77 { NegotiateMessageKey::STATION_FREQUENCY, Serializable::ValueType::INT },
78 { NegotiateMessageKey::ROLE, Serializable::ValueType::INT },
79 { NegotiateMessageKey::EXPECTED_ROLE, Serializable::ValueType::INT },
80 { NegotiateMessageKey::VERSION, Serializable::ValueType::INT },
81 { NegotiateMessageKey::GC_IP, Serializable::ValueType::STRING },
82 { NegotiateMessageKey::WIDE_BAND_SUPPORTED, Serializable::ValueType::BOOL },
83 { NegotiateMessageKey::GROUP_CONFIG, Serializable::ValueType::STRING },
84 { NegotiateMessageKey::MAC, Serializable::ValueType::STRING },
85 { NegotiateMessageKey::BRIDGE_SUPPORTED, Serializable::ValueType::BOOL },
86 { NegotiateMessageKey::GO_IP, Serializable::ValueType::STRING },
87 { NegotiateMessageKey::GO_MAC, Serializable::ValueType::STRING },
88 { NegotiateMessageKey::GO_PORT, Serializable::ValueType::INT },
89 { NegotiateMessageKey::IP, Serializable::ValueType::STRING },
90 { NegotiateMessageKey::RESULT, Serializable::ValueType::INT },
91 { NegotiateMessageKey::CONTENT_TYPE, Serializable::ValueType::INT },
92 { NegotiateMessageKey::GC_MAC, Serializable::ValueType::STRING },
93 { NegotiateMessageKey::SELF_WIFI_CONFIG, Serializable::ValueType::STRING },
94 { NegotiateMessageKey::GC_CHANNEL_SCORE, Serializable::ValueType::STRING },
95 { NegotiateMessageKey::COMMAND_TYPE, Serializable::ValueType::INT },
96 { NegotiateMessageKey::INTERFACE_NAME, Serializable::ValueType::STRING },
97 };
98
99 static std::map<NegotiateMessageType, std::string> g_messageNameMap = {
100 { NegotiateMessageType::CMD_INVALID, "CMD_INVALID" },
101 { NegotiateMessageType::CMD_CONN_V2_REQ_1, "CMD_CONN_V2_REQ_1" },
102 { NegotiateMessageType::CMD_CONN_V2_REQ_2, "CMD_CONN_V2_REQ_2" },
103 { NegotiateMessageType::CMD_CONN_V2_REQ_3, "CMD_CONN_V2_REQ_3" },
104 { NegotiateMessageType::CMD_CONN_V2_RESP_1, "CMD_CONN_V2_RESP_1" },
105 { NegotiateMessageType::CMD_CONN_V2_RESP_2, "CMD_CONN_V2_RESP_2" },
106 { NegotiateMessageType::CMD_CONN_V2_RESP_3, "CMD_CONN_V2_RESP_3" },
107 { NegotiateMessageType::CMD_DISCONNECT_V2_REQ, "CMD_DISCONNECT_V2_REQ" },
108 { NegotiateMessageType::CMD_DISCONNECT_V2_RESP, "CMD_DISCONNECT_V2_RESP" },
109 { NegotiateMessageType::CMD_FORCE_DISCONNECT_REQ, "CMD_FORCE_DISCONNECT_REQ" },
110 { NegotiateMessageType::CMD_CLIENT_JOIN_FAIL_NOTIFY, "CMD_CLIENT_JOIN_FAIL_NOTIFY" },
111 { NegotiateMessageType::CMD_TRIGGER_REQ, "CMD_TRIGGER_REQ" },
112 { NegotiateMessageType::CMD_TRIGGER_RESP, "CMD_TRIGGER_RESP" },
113 { NegotiateMessageType::CMD_AUTH_LISTEN_RESP, "CMD_AUTH_LISTEN_RESP" },
114 { NegotiateMessageType::CMD_RENEGOTIATE_REQ, "CMD_RENEGOTIATE_REQ" },
115 { NegotiateMessageType::CMD_RENEGOTIATE_RESP, "CMD_RENEGOTIATE_RESP" },
116 { NegotiateMessageType::CMD_AUTH_HAND_SHAKE, "CMD_AUTH_HAND_SHAKE" },
117 { NegotiateMessageType::CMD_AUTH_HAND_SHAKE_RSP, "CMD_AUTH_HAND_SHAKE_RSP" },
118 { NegotiateMessageType::CMD_DETECT_LINK_REQ, "CMD_DETECT_LINK_REQ" },
119 { NegotiateMessageType::CMD_DETECT_LINK_RSP, "CMD_DETECT_LINK_RSP" },
120 { NegotiateMessageType::CMD_V3_REQ, "CMD_V3_REQ" },
121 { NegotiateMessageType::CMD_V3_RSP, "CMD_V3_RSP" },
122 { NegotiateMessageType::CMD_V3_CUSTOM_PORT_REQ, "CMD_V3_CUSTOM_PORT_REQ" },
123 { NegotiateMessageType::CMD_V3_CUSTOM_PORT_RSP, "CMD_V3_CUSTOM_PORT_RSP" },
124 };
125
126 static std::map<LegacyCommandType, std::string> g_legacyMessageNameMap = {
127 { LegacyCommandType::CMD_INVALID, "CMD_INVALID" },
128 { LegacyCommandType::CMD_DISCONNECT_V1_REQ, "CMD_DISCONNECT_V1_REQ" },
129 { LegacyCommandType::CMD_CONN_V1_REQ, "CMD_CONN_V1_REQ" },
130 { LegacyCommandType::CMD_CONN_V1_RESP, "CMD_CONN_V1_RESP" },
131 { LegacyCommandType::CMD_REUSE_REQ, "CMD_REUSE_REQ" },
132 { LegacyCommandType::CMD_CTRL_CHL_HANDSHAKE, "CMD_CTRL_CHL_HANDSHAKE" },
133 { LegacyCommandType::CMD_GC_WIFI_CONFIG_CHANGED, "CMD_GC_WIFI_CONFIG_CHANGED" },
134 { LegacyCommandType::CMD_REUSE_RESP, "CMD_REUSE_RESP" },
135 { LegacyCommandType::CMD_PC_GET_INTERFACE_INFO_REQ, "CMD_PC_GET_INTERFACE_INFO_REQ" },
136 { LegacyCommandType::CMD_PC_GET_INTERFACE_INFO_RESP, "CMD_PC_GET_INTERFACE_INFO_RESP" },
137 { LegacyCommandType::CMD_FORCE_DISCONNECT_V1_REQ, "CMD_FORCE_DISCONNECT_V1_REQ" },
138 };
139
NegotiateMessage()140 NegotiateMessage::NegotiateMessage() { }
141
NegotiateMessage(NegotiateMessageType type)142 NegotiateMessage::NegotiateMessage(NegotiateMessageType type)
143 {
144 SetMessageType(type);
145 }
146
NegotiateMessage(LegacyCommandType type)147 NegotiateMessage::NegotiateMessage(LegacyCommandType type)
148 {
149 SetMessageType(type);
150 }
151
~NegotiateMessage()152 NegotiateMessage::~NegotiateMessage() { }
153
Marshalling(WifiDirectProtocol & protocol,std::vector<uint8_t> & output) const154 int NegotiateMessage::Marshalling(WifiDirectProtocol &protocol, std::vector<uint8_t> &output) const
155 {
156 for (const auto &[key, value] : values_) {
157 if (keyIgnoreTable_.find(key) != keyIgnoreTable_.end()) {
158 continue;
159 }
160 auto type = keyTypeTable_[key];
161 switch (type) {
162 case Serializable::ValueType::BOOL: {
163 uint8_t data = std::any_cast<bool>(value);
164 protocol.Write(static_cast<int>(key), type, &data, sizeof(data));
165 }
166 break;
167 case Serializable::ValueType::INT: {
168 std::vector<uint8_t> data;
169 WifiDirectUtils::IntToBytes(std::any_cast<int>(value), sizeof(int), data);
170 protocol.Write(static_cast<int>(key), type, data.data(), data.size());
171 }
172 break;
173 case Serializable::ValueType::UINT: {
174 std::vector<uint8_t> data;
175 WifiDirectUtils::IntToBytes(std::any_cast<uint32_t>(value), sizeof(uint32_t), data);
176 protocol.Write(static_cast<int>(key), type, data.data(), data.size());
177 }
178 break;
179 case Serializable::ValueType::STRING: {
180 auto data = std::any_cast<std::string>(value);
181 protocol.Write(static_cast<int>(key), type, (uint8_t *)data.c_str(), data.length());
182 }
183 break;
184 case Serializable::ValueType::BYTE_ARRAY: {
185 const auto &data = std::any_cast<const std::vector<uint8_t> &>(value);
186 protocol.Write(static_cast<int>(key), type, data.data(), data.size());
187 }
188 break;
189 case Serializable::ValueType::IPV4_INFO_ARRAY:
190 MarshallingIpv4Array(protocol);
191 break;
192 case Serializable::ValueType::INTERFACE_INFO_ARRAY:
193 MarshallingInterfaceArray(protocol);
194 break;
195 case Serializable::ValueType::LINK_INFO:
196 MarshallingLinkInfo(protocol);
197 break;
198 default:
199 continue;
200 }
201 }
202 protocol.GetOutput(output);
203 return SOFTBUS_OK;
204 }
205
MarshallingIpv4Array(WifiDirectProtocol & protocol) const206 void NegotiateMessage::MarshallingIpv4Array(WifiDirectProtocol &protocol) const
207 {
208 std::vector<uint8_t> output;
209 auto ipv4Array = GetIpv4InfoArray();
210 for (const auto &ipv4 : ipv4Array) {
211 std::vector<uint8_t> ipv4Output;
212 ipv4.Marshalling(ipv4Output);
213 output.insert(output.end(), ipv4Output.begin(), ipv4Output.end());
214 }
215 protocol.Write((int)NegotiateMessageKey::IPV4_INFO_ARRAY, Serializable::ValueType::IPV4_INFO_ARRAY, output.data(),
216 output.size());
217 }
218
MarshallingInterfaceArray(WifiDirectProtocol & protocol) const219 void NegotiateMessage::MarshallingInterfaceArray(WifiDirectProtocol &protocol) const
220 {
221 auto interfaceArray = GetInterfaceInfoArray();
222 for (const auto &interface : interfaceArray) {
223 auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
224 if (pro != nullptr) {
225 std::vector<uint8_t> interfaceOutput;
226 pro->SetFormat(protocol.GetFormat());
227 interface.Marshalling(*pro, interfaceOutput);
228 protocol.Write(static_cast<int>(NegotiateMessageKey::INTERFACE_INFO_ARRAY),
229 Serializable::ValueType::INTERFACE_INFO_ARRAY, interfaceOutput.data(), interfaceOutput.size());
230 }
231 }
232 }
233
MarshallingLinkInfo(WifiDirectProtocol & protocol) const234 void NegotiateMessage::MarshallingLinkInfo(WifiDirectProtocol &protocol) const
235 {
236 auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
237 if (pro == nullptr) {
238 CONN_LOGE(CONN_WIFI_DIRECT, "create protocol failed");
239 return;
240 }
241 pro->SetFormat(protocol.GetFormat());
242
243 auto linkInfo = GetLinkInfo();
244 std::vector<uint8_t> output;
245 linkInfo.Marshalling(*pro, output);
246 protocol.Write(static_cast<int>(NegotiateMessageKey::LINK_INFO), Serializable::ValueType::LINK_INFO, output.data(),
247 output.size());
248 }
249
Unmarshalling(WifiDirectProtocol & protocol,const std::vector<uint8_t> & input)250 int NegotiateMessage::Unmarshalling(WifiDirectProtocol &protocol, const std::vector<uint8_t> &input)
251 {
252 int key = 0;
253 uint8_t *data = nullptr;
254 size_t size = 0;
255
256 protocol.SetInput(input);
257 while (protocol.Read(key, data, size)) {
258 auto type = keyTypeTable_[static_cast<NegotiateMessageKey>(key)];
259 switch (Serializable::ValueType(type)) {
260 case Serializable::ValueType::BOOL:
261 Set(NegotiateMessageKey(key), *reinterpret_cast<bool *>(data));
262 break;
263 case Serializable::ValueType::INT:
264 Set(NegotiateMessageKey(key), *reinterpret_cast<int *>(data));
265 break;
266 case Serializable::ValueType::UINT:
267 Set(NegotiateMessageKey(key), *reinterpret_cast<uint32_t *>(data));
268 break;
269 case Serializable::ValueType::STRING:
270 size = WifiDirectUtils::CalculateStringLength((char *)data, size);
271 Set(NegotiateMessageKey(key), std::string(reinterpret_cast<const char *>(data), size));
272 break;
273 case Serializable::ValueType::BYTE_ARRAY:
274 Set(NegotiateMessageKey(key), std::vector<uint8_t>(data, data + size));
275 break;
276 case Serializable::ValueType::IPV4_INFO_ARRAY:
277 UnmarshallingIpv4Array(data, size);
278 break;
279 case Serializable::ValueType::INTERFACE_INFO_ARRAY:
280 UnmarshallingInterfaceArray(protocol, data, size);
281 break;
282 case Serializable::ValueType::LINK_INFO:
283 UnmarshallingLinkInfo(protocol, data, size);
284 break;
285 default:
286 continue;
287 }
288 }
289
290 return SOFTBUS_OK;
291 }
292
UnmarshallingIpv4Array(uint8_t * data,size_t size)293 void NegotiateMessage::UnmarshallingIpv4Array(uint8_t *data, size_t size)
294 {
295 std::vector<Ipv4Info> ipv4Array;
296 for (size_t pos = 0; pos + Ipv4Info::Ipv4InfoSize() <= size; pos += Ipv4Info::Ipv4InfoSize()) {
297 Ipv4Info ipv4;
298 ipv4.Unmarshalling(data + pos, Ipv4Info::Ipv4InfoSize());
299 ipv4Array.push_back(ipv4);
300 }
301 if (!ipv4Array.empty()) {
302 SetIpv4InfoArray(ipv4Array);
303 }
304 }
305
UnmarshallingInterfaceArray(WifiDirectProtocol & protocol,uint8_t * data,size_t size)306 void NegotiateMessage::UnmarshallingInterfaceArray(WifiDirectProtocol &protocol, uint8_t *data, size_t size)
307 {
308 auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
309 if (pro == nullptr) {
310 return;
311 }
312 pro->SetFormat(protocol.GetFormat());
313
314 InterfaceInfo info;
315 std::vector<uint8_t> input(data, data + size);
316 info.Unmarshalling(*pro, input);
317 auto interfaceArray = GetInterfaceInfoArray();
318 interfaceArray.push_back(info);
319 SetInterfaceInfoArray(interfaceArray);
320 }
321
UnmarshallingLinkInfo(WifiDirectProtocol & protocol,uint8_t * data,size_t size)322 void NegotiateMessage::UnmarshallingLinkInfo(WifiDirectProtocol &protocol, uint8_t *data, size_t size)
323 {
324 auto pro = WifiDirectProtocolFactory::CreateProtocol(protocol.GetType());
325 if (pro == nullptr) {
326 return;
327 }
328 pro->SetFormat(protocol.GetFormat());
329
330 LinkInfo info;
331 std::vector<uint8_t> input(data, data + size);
332 info.Unmarshalling(*pro, input);
333 SetLinkInfo(info);
334 }
335
SetMessageType(NegotiateMessageType value)336 void NegotiateMessage::SetMessageType(NegotiateMessageType value)
337 {
338 Set(NegotiateMessageKey::MSG_TYPE, static_cast<int>(value));
339 }
340
SetMessageType(LegacyCommandType value)341 void NegotiateMessage::SetMessageType(LegacyCommandType value)
342 {
343 Set(NegotiateMessageKey::MSG_TYPE, static_cast<int>(value));
344 }
345
GetMessageType() const346 NegotiateMessageType NegotiateMessage::GetMessageType() const
347 {
348 auto value = Get(NegotiateMessageKey::MSG_TYPE, static_cast<int>(NegotiateMessageType::CMD_INVALID));
349 return static_cast<NegotiateMessageType>(value);
350 }
351
MessageTypeToString() const352 std::string NegotiateMessage::MessageTypeToString() const
353 {
354 auto legacyCmdType = GetLegacyP2pCommandType();
355 if (legacyCmdType != LegacyCommandType::CMD_INVALID) {
356 auto it = g_legacyMessageNameMap.find(legacyCmdType);
357 if (it == g_legacyMessageNameMap.end()) {
358 CONN_LOGE(CONN_WIFI_DIRECT, "not find legacy %{public}d", static_cast<int>(GetMessageType()));
359 return "";
360 }
361 return it->second;
362 }
363
364 auto it = g_messageNameMap.find(GetMessageType());
365 if (it == g_messageNameMap.end()) {
366 CONN_LOGE(CONN_WIFI_DIRECT, "not find %{public}d", static_cast<int>(GetMessageType()));
367 return "";
368 }
369 return it->second;
370 }
371
SetSessionId(uint32_t value)372 void NegotiateMessage::SetSessionId(uint32_t value)
373 {
374 Set(NegotiateMessageKey::SESSION_ID, value);
375 }
376
GetSessionId() const377 uint32_t NegotiateMessage::GetSessionId() const
378 {
379 return Get(NegotiateMessageKey::SESSION_ID, static_cast<uint32_t>(SESSION_ID_INVALID));
380 }
381
SetWifiConfigInfo(const std::vector<uint8_t> & value)382 void NegotiateMessage::SetWifiConfigInfo(const std::vector<uint8_t> &value)
383 {
384 Set(NegotiateMessageKey::WIFI_CFG_INFO, value);
385 }
386
GetWifiConfigInfo() const387 std::vector<uint8_t> NegotiateMessage::GetWifiConfigInfo() const
388 {
389 return Get(NegotiateMessageKey::WIFI_CFG_INFO, std::vector<uint8_t>());
390 }
391
SetIpv4InfoArray(const std::vector<Ipv4Info> & value)392 void NegotiateMessage::SetIpv4InfoArray(const std::vector<Ipv4Info> &value)
393 {
394 Set(NegotiateMessageKey::IPV4_INFO_ARRAY, value);
395 }
396
GetIpv4InfoArray() const397 std::vector<Ipv4Info> NegotiateMessage::GetIpv4InfoArray() const
398 {
399 return Get(NegotiateMessageKey::IPV4_INFO_ARRAY, std::vector<Ipv4Info>());
400 }
401
SetPreferLinkMode(LinkInfo::LinkMode value)402 void NegotiateMessage::SetPreferLinkMode(LinkInfo::LinkMode value)
403 {
404 Set(NegotiateMessageKey::PREFER_LINK_MODE, static_cast<int>(value));
405 }
406
GetPreferLinkMode() const407 LinkInfo::LinkMode NegotiateMessage::GetPreferLinkMode() const
408 {
409 auto value = Get(NegotiateMessageKey::PREFER_LINK_MODE, static_cast<int>(LinkInfo::LinkMode::INVALID));
410 return static_cast<LinkInfo::LinkMode>(value);
411 }
412
SetIsModeStrict(bool value)413 void NegotiateMessage::SetIsModeStrict(bool value)
414 {
415 Set(NegotiateMessageKey::IS_MODE_STRICT, value);
416 }
417
GetIsModeStrict() const418 bool NegotiateMessage::GetIsModeStrict() const
419 {
420 return Get(NegotiateMessageKey::IS_MODE_STRICT, false);
421 }
422
SetPreferLinkBandWidth(int value)423 void NegotiateMessage::SetPreferLinkBandWidth(int value)
424 {
425 Set(NegotiateMessageKey::PREFER_LINK_BANDWIDTH, value);
426 }
427
GetPreferLinkBandWidth() const428 int NegotiateMessage::GetPreferLinkBandWidth() const
429 {
430 return Get(NegotiateMessageKey::PREFER_LINK_BANDWIDTH, 0);
431 }
432
SetIsBridgeSupported(bool value)433 void NegotiateMessage::SetIsBridgeSupported(bool value)
434 {
435 Set(NegotiateMessageKey::IS_BRIDGE_SUPPORTED, value);
436 }
437
GetIsBridgeSupported() const438 bool NegotiateMessage::GetIsBridgeSupported() const
439 {
440 return Get(NegotiateMessageKey::IS_BRIDGE_SUPPORTED, false);
441 }
442
SetLinkInfo(const LinkInfo & value)443 void NegotiateMessage::SetLinkInfo(const LinkInfo &value)
444 {
445 Set(NegotiateMessageKey::LINK_INFO, value);
446 }
447
GetLinkInfo() const448 LinkInfo NegotiateMessage::GetLinkInfo() const
449 {
450 return Get(NegotiateMessageKey::LINK_INFO, LinkInfo());
451 }
452
SetResultCode(int value)453 void NegotiateMessage::SetResultCode(int value)
454 {
455 Set(NegotiateMessageKey::RESULT_CODE, value);
456 }
457
GetResultCode() const458 int NegotiateMessage::GetResultCode() const
459 {
460 return Get(NegotiateMessageKey::RESULT_CODE, RESULT_CODE_INVALID);
461 }
462
SetInterfaceInfoArray(const std::vector<InterfaceInfo> & value)463 void NegotiateMessage::SetInterfaceInfoArray(const std::vector<InterfaceInfo> &value)
464 {
465 Set(NegotiateMessageKey::INTERFACE_INFO_ARRAY, value);
466 }
467
GetInterfaceInfoArray() const468 std::vector<InterfaceInfo> NegotiateMessage::GetInterfaceInfoArray() const
469 {
470 return Get(NegotiateMessageKey::INTERFACE_INFO_ARRAY, std::vector<InterfaceInfo>());
471 }
472
SetRemoteDeviceId(const std::string & value)473 void NegotiateMessage::SetRemoteDeviceId(const std::string &value)
474 {
475 Set(NegotiateMessageKey::REMOTE_DEVICE_ID, value);
476 }
477
GetRemoteDeviceId() const478 std::string NegotiateMessage::GetRemoteDeviceId() const
479 {
480 return Get(NegotiateMessageKey::REMOTE_DEVICE_ID, std::string());
481 }
482
SetExtraData(const std::vector<uint8_t> & value)483 void NegotiateMessage::SetExtraData(const std::vector<uint8_t> &value)
484 {
485 Set(NegotiateMessageKey::EXTRA_DATA_ARRAY, value);
486 }
487
GetExtraData() const488 std::vector<uint8_t> NegotiateMessage::GetExtraData() const
489 {
490 return Get(NegotiateMessageKey::EXTRA_DATA_ARRAY, std::vector<uint8_t>());
491 }
492
SetIsProxyEnable(bool value)493 void NegotiateMessage::SetIsProxyEnable(bool value)
494 {
495 Set(NegotiateMessageKey::IS_PROXY_ENABLE, value);
496 }
497
GetIsProxyEnable() const498 bool NegotiateMessage::GetIsProxyEnable() const
499 {
500 return Get(NegotiateMessageKey::IS_PROXY_ENABLE, false);
501 }
502
Set5GChannelList(const std::string & value)503 void NegotiateMessage::Set5GChannelList(const std::string &value)
504 {
505 Set(NegotiateMessageKey::CHANNEL_5G_LIST, value);
506 }
507
Get5GChannelList() const508 std::string NegotiateMessage::Get5GChannelList() const
509 {
510 return Get(NegotiateMessageKey::CHANNEL_5G_LIST, std::string());
511 }
512
Set5GChannelScore(const std::string & value)513 void NegotiateMessage::Set5GChannelScore(const std::string &value)
514 {
515 Set(NegotiateMessageKey::CHANNEL_5G_SCORE, value);
516 }
517
Get5GChannelScore() const518 std::string NegotiateMessage::Get5GChannelScore() const
519 {
520 return Get(NegotiateMessageKey::CHANNEL_5G_SCORE, std::string());
521 }
522
SetChallengeCode(uint32_t value)523 void NegotiateMessage::SetChallengeCode(uint32_t value)
524 {
525 Set(NegotiateMessageKey::CHALLENGE_CODE, value);
526 }
527
GetChallengeCode() const528 uint32_t NegotiateMessage::GetChallengeCode() const
529 {
530 return Get(NegotiateMessageKey::CHALLENGE_CODE, static_cast<uint32_t>(0));
531 }
532
SetNewPtkFrame(bool value)533 void NegotiateMessage::SetNewPtkFrame(bool value)
534 {
535 Set(NegotiateMessageKey::NEW_PTK_FRAME, value);
536 }
537
GetNewPtkFrame() const538 bool NegotiateMessage::GetNewPtkFrame() const
539 {
540 return Get(NegotiateMessageKey::NEW_PTK_FRAME, false);
541 }
542
SetLegacyP2pGcChannelList(const std::string & value)543 void NegotiateMessage::SetLegacyP2pGcChannelList(const std::string &value)
544 {
545 Set(NegotiateMessageKey::GC_CHANNEL_LIST, value);
546 }
547
GetLegacyP2pGcChannelList() const548 std::string NegotiateMessage::GetLegacyP2pGcChannelList() const
549 {
550 return Get(NegotiateMessageKey::GC_CHANNEL_LIST, std::string());
551 }
552
SetLegacyP2pStationFrequency(int value)553 void NegotiateMessage::SetLegacyP2pStationFrequency(int value)
554 {
555 Set(NegotiateMessageKey::STATION_FREQUENCY, value);
556 }
557
GetLegacyP2pStationFrequency() const558 int NegotiateMessage::GetLegacyP2pStationFrequency() const
559 {
560 return Get(NegotiateMessageKey::STATION_FREQUENCY, 0);
561 }
562
SetLegacyP2pRole(WifiDirectRole value)563 void NegotiateMessage::SetLegacyP2pRole(WifiDirectRole value)
564 {
565 Set(NegotiateMessageKey::ROLE, static_cast<int>(value));
566 }
567
GetLegacyP2pRole() const568 WifiDirectRole NegotiateMessage::GetLegacyP2pRole() const
569 {
570 auto value = Get(NegotiateMessageKey::ROLE, static_cast<int>(WifiDirectRole::WIFI_DIRECT_ROLE_INVALID));
571 return static_cast<WifiDirectRole>(value);
572 }
573
SetLegacyP2pExpectedRole(WifiDirectRole value)574 void NegotiateMessage::SetLegacyP2pExpectedRole(WifiDirectRole value)
575 {
576 Set(NegotiateMessageKey::EXPECTED_ROLE, static_cast<int>(value));
577 }
578
GetLegacyP2pExpectedRole() const579 WifiDirectRole NegotiateMessage::GetLegacyP2pExpectedRole() const
580 {
581 auto value = Get(NegotiateMessageKey::EXPECTED_ROLE, static_cast<int>(WifiDirectRole::WIFI_DIRECT_ROLE_INVALID));
582 return static_cast<WifiDirectRole>(value);
583 }
584
SetLegacyP2pVersion(int value)585 void NegotiateMessage::SetLegacyP2pVersion(int value)
586 {
587 Set(NegotiateMessageKey::VERSION, value);
588 }
589
GetLegacyP2pVersion() const590 int NegotiateMessage::GetLegacyP2pVersion() const
591 {
592 return Get(NegotiateMessageKey::VERSION, 0);
593 }
594
SetLegacyP2pGcIp(const std::string & value)595 void NegotiateMessage::SetLegacyP2pGcIp(const std::string &value)
596 {
597 Set(NegotiateMessageKey::GC_IP, value);
598 }
599
GetLegacyP2pGcIp() const600 std::string NegotiateMessage::GetLegacyP2pGcIp() const
601 {
602 return Get(NegotiateMessageKey::GC_IP, std::string());
603 }
604
SetLegacyP2pWideBandSupported(bool value)605 void NegotiateMessage::SetLegacyP2pWideBandSupported(bool value)
606 {
607 Set(NegotiateMessageKey::WIDE_BAND_SUPPORTED, value);
608 }
609
GetLegacyP2pWideBandSupported() const610 bool NegotiateMessage::GetLegacyP2pWideBandSupported() const
611 {
612 return Get(NegotiateMessageKey::WIDE_BAND_SUPPORTED, false);
613 }
614
SetLegacyP2pGroupConfig(const std::string & value)615 void NegotiateMessage::SetLegacyP2pGroupConfig(const std::string &value)
616 {
617 Set(NegotiateMessageKey::GROUP_CONFIG, value);
618 }
619
GetLegacyP2pGroupConfig() const620 std::string NegotiateMessage::GetLegacyP2pGroupConfig() const
621 {
622 return Get(NegotiateMessageKey::GROUP_CONFIG, std::string());
623 }
624
SetLegacyP2pMac(const std::string & value)625 void NegotiateMessage::SetLegacyP2pMac(const std::string &value)
626 {
627 Set(NegotiateMessageKey::MAC, value);
628 }
629
GetLegacyP2pMac() const630 std::string NegotiateMessage::GetLegacyP2pMac() const
631 {
632 return Get(NegotiateMessageKey::MAC, std::string());
633 }
634
SetLegacyP2pBridgeSupport(bool value)635 void NegotiateMessage::SetLegacyP2pBridgeSupport(bool value)
636 {
637 Set(NegotiateMessageKey::BRIDGE_SUPPORTED, value);
638 }
639
GetLegacyP2pBridgeSupport() const640 bool NegotiateMessage::GetLegacyP2pBridgeSupport() const
641 {
642 return Get(NegotiateMessageKey::BRIDGE_SUPPORTED, false);
643 }
644
SetLegacyP2pGoIp(const std::string & value)645 void NegotiateMessage::SetLegacyP2pGoIp(const std::string &value)
646 {
647 Set(NegotiateMessageKey::GO_IP, value);
648 }
649
GetLegacyP2pGoIp() const650 std::string NegotiateMessage::GetLegacyP2pGoIp() const
651 {
652 return Get(NegotiateMessageKey::GO_IP, std::string());
653 }
654
SetLegacyP2pGoMac(const std::string & value)655 void NegotiateMessage::SetLegacyP2pGoMac(const std::string &value)
656 {
657 Set(NegotiateMessageKey::GO_MAC, value);
658 }
659
GetLegacyP2pGoMac() const660 std::string NegotiateMessage::GetLegacyP2pGoMac() const
661 {
662 return Get(NegotiateMessageKey::GO_MAC, std::string());
663 }
664
SetLegacyP2pGoPort(int value)665 void NegotiateMessage::SetLegacyP2pGoPort(int value)
666 {
667 Set(NegotiateMessageKey::GO_PORT, value);
668 }
669
GetLegacyP2pGoPort() const670 int NegotiateMessage::GetLegacyP2pGoPort() const
671 {
672 return Get(NegotiateMessageKey::GO_PORT, 0);
673 }
674
SetLegacyP2pIp(const std::string & value)675 void NegotiateMessage::SetLegacyP2pIp(const std::string &value)
676 {
677 Set(NegotiateMessageKey::IP, value);
678 }
679
GetLegacyP2pIp() const680 std::string NegotiateMessage::GetLegacyP2pIp() const
681 {
682 return Get(NegotiateMessageKey::IP, std::string());
683 }
684
SetLegacyP2pResult(LegacyResult value)685 void NegotiateMessage::SetLegacyP2pResult(LegacyResult value)
686 {
687 Set(NegotiateMessageKey::RESULT, static_cast<int>(value));
688 }
689
GetLegacyP2pResult() const690 LegacyResult NegotiateMessage::GetLegacyP2pResult() const
691 {
692 auto value = Get(NegotiateMessageKey::RESULT, static_cast<int>(LegacyResult::OK));
693 return static_cast<LegacyResult>(value);
694 }
695
SetLegacyP2pContentType(LegacyContentType value)696 void NegotiateMessage::SetLegacyP2pContentType(LegacyContentType value)
697 {
698 Set(NegotiateMessageKey::CONTENT_TYPE, static_cast<int>(value));
699 }
700
GetLegacyP2pContentType() const701 LegacyContentType NegotiateMessage::GetLegacyP2pContentType() const
702 {
703 auto value = Get(NegotiateMessageKey::CONTENT_TYPE, static_cast<int>(LegacyContentType::INVALID));
704 return static_cast<LegacyContentType>(value);
705 }
706
SetLegacyP2pGcMac(const std::string & value)707 void NegotiateMessage::SetLegacyP2pGcMac(const std::string &value)
708 {
709 Set(NegotiateMessageKey::GC_MAC, value);
710 }
711
GetLegacyP2pGcMac() const712 std::string NegotiateMessage::GetLegacyP2pGcMac() const
713 {
714 return Get(NegotiateMessageKey::GC_MAC, std::string());
715 }
716
SetLegacyP2pWifiConfigInfo(const std::string & value)717 void NegotiateMessage::SetLegacyP2pWifiConfigInfo(const std::string &value)
718 {
719 Set(NegotiateMessageKey::SELF_WIFI_CONFIG, value);
720 }
721
GetLegacyP2pWifiConfigInfo() const722 std::string NegotiateMessage::GetLegacyP2pWifiConfigInfo() const
723 {
724 return Get(NegotiateMessageKey::SELF_WIFI_CONFIG, std::string());
725 }
726
SetLegacyP2pCommandType(LegacyCommandType value)727 void NegotiateMessage::SetLegacyP2pCommandType(LegacyCommandType value)
728 {
729 Set(NegotiateMessageKey::COMMAND_TYPE, static_cast<int>(value));
730 }
731
GetLegacyP2pCommandType() const732 LegacyCommandType NegotiateMessage::GetLegacyP2pCommandType() const
733 {
734 auto value = Get(NegotiateMessageKey::COMMAND_TYPE, static_cast<int>(LegacyCommandType::CMD_INVALID));
735 return static_cast<LegacyCommandType>(value);
736 }
737
SetLegacyInterfaceName(const std::string & value)738 void NegotiateMessage::SetLegacyInterfaceName(const std::string &value)
739 {
740 Set(NegotiateMessageKey::INTERFACE_NAME, value);
741 }
GetLegacyInterfaceName() const742 std::string NegotiateMessage::GetLegacyInterfaceName() const
743 {
744 return Get(NegotiateMessageKey::INTERFACE_NAME, std::string(""));
745 }
746
747 } // namespace OHOS::SoftBus
748