1 /*
2 * Copyright (C) 2023 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 "ohos_bt_socket.h"
17
18 #include <iostream>
19 #include <cstring>
20 #include <vector>
21
22 #include "ohos_bt_adapter_utils.h"
23 #include "bluetooth_def.h"
24 #include "bluetooth_gatt_client.h"
25 #include "bluetooth_socket.h"
26 #include "bluetooth_host.h"
27 #include "bluetooth_log.h"
28 #include "bluetooth_utils.h"
29 #include "bluetooth_object_map.h"
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 using namespace std;
36
37 namespace OHOS {
38 namespace Bluetooth {
39
40 const int MAX_OBJECT_NUM = 10000;
41
42 static BluetoothObjectMap<std::shared_ptr<ServerSocket>, MAX_OBJECT_NUM> g_serverMap;
43 static BluetoothObjectMap<std::shared_ptr<ClientSocket>, MAX_OBJECT_NUM> g_clientMap;
44
45 class BluetoothConnectionObserverWapper : public BluetoothConnectionObserver {
46 public:
BluetoothConnectionObserverWapper(BtSocketConnectionCallback & callback)47 explicit BluetoothConnectionObserverWapper(BtSocketConnectionCallback &callback)
48 {
49 socektConnectCallback = callback;
50 }
51
52 __attribute__((no_sanitize("cfi")))
OnConnectionStateChanged(const CallbackConnectParam & param)53 void OnConnectionStateChanged(const CallbackConnectParam ¶m) override
54 {
55 if (socektConnectCallback.connStateCb == nullptr && socektConnectCallback.bleConnStateCb == nullptr) {
56 HILOGE("callback is null");
57 return;
58 }
59 BdAddr addr;
60 GetAddrFromString(param.addr.GetDeviceAddr(), addr.addr);
61 BtUuid btUuid;
62 string strUuid = param.uuid.ToString();
63 btUuid.uuid = (char *)strUuid.c_str();
64 btUuid.uuidLen = strUuid.size();
65 if (param.type == OHOS_SOCKET_SPP_RFCOMM && socektConnectCallback.connStateCb != nullptr) {
66 socektConnectCallback.connStateCb(&addr, btUuid, param.status, param.result);
67 }
68 if (param.type == OHOS_SOCKET_L2CAP_LE && socektConnectCallback.bleConnStateCb != nullptr) {
69 socektConnectCallback.bleConnStateCb(&addr, param.psm, param.status, param.result);
70 }
71 }
72
73 BtSocketConnectionCallback socektConnectCallback;
74 };
75
76 static std::map<int, std::shared_ptr<BluetoothConnectionObserverWapper>> g_clientCbMap;
77 static std::mutex g_clientCbMapMutex;
78 using ClientCbIterator = std::map<int, std::shared_ptr<BluetoothConnectionObserverWapper>>::iterator;
79
GetSocketUuidPara(const BluetoothCreateSocketPara * socketPara,UUID & serverUuid)80 static bool GetSocketUuidPara(const BluetoothCreateSocketPara *socketPara, UUID &serverUuid)
81 {
82 if (socketPara->socketType == OHOS_SOCKET_SPP_RFCOMM) {
83 if (socketPara->uuid.uuid == nullptr || strlen(socketPara->uuid.uuid) != socketPara->uuid.uuidLen) {
84 HILOGE("param uuid invalid!");
85 return false;
86 }
87 string tmpUuid(socketPara->uuid.uuid);
88 if (!IsValidUuid(tmpUuid)) {
89 HILOGE("match the UUID faild.");
90 return false;
91 }
92 serverUuid = UUID::FromString(tmpUuid);
93 } else if (socketPara->socketType == OHOS_SOCKET_L2CAP_LE) {
94 serverUuid = UUID::RandomUUID();
95 } else {
96 HILOGE("param socketType invalid. socketType: %{public}d", socketPara->socketType);
97 return false;
98 }
99 return true;
100 }
101
102 /**
103 * @brief Creates an server listening socket based on the service record.
104 *
105 * @param socketPara The parameters to create a server socket.
106 * @param name The service's name.
107 * @return Returns a server ID, if create fail return {@link BT_SOCKET_INVALID_ID}.
108 */
SocketServerCreate(const BluetoothCreateSocketPara * socketPara,const char * name)109 int SocketServerCreate(const BluetoothCreateSocketPara *socketPara, const char *name)
110 {
111 HILOGD("SocketServerCreate start!");
112 if (socketPara == nullptr || name == nullptr) {
113 HILOGE("socketPara or name is null.");
114 return BT_SOCKET_INVALID_ID;
115 }
116
117 if (socketPara->socketType == OHOS_SOCKET_L2CAP_LE) {
118 CHECK_AND_RETURN_LOG_RET(IS_BLE_ENABLED(), BT_SOCKET_INVALID_ID, "BLE is not TURN_ON");
119 } else {
120 CHECK_AND_RETURN_LOG_RET(IS_BT_ENABLED(), BT_SOCKET_INVALID_ID, "BR is not TURN_ON");
121 }
122
123 UUID serverUuid;
124 if (!GetSocketUuidPara(socketPara, serverUuid)) {
125 return BT_SOCKET_INVALID_ID;
126 }
127
128 string serverName(name);
129 std::shared_ptr<ServerSocket> server = std::make_shared<ServerSocket>(serverName, serverUuid,
130 BtSocketType(socketPara->socketType), socketPara->isEncrypt);
131 int result = server->Listen();
132 if (result != BT_NO_ERROR) {
133 HILOGE("SocketServerCreate fail, result: %{public}d", result);
134 server->Close();
135 HILOGE("SocketServerCreate closed.");
136 return BT_SOCKET_INVALID_ID;
137 }
138 int serverId = g_serverMap.AddObject(server);
139 HILOGI("success, serverId: %{public}d, socketType: %{public}d, isEncrypt: %{public}d", serverId,
140 socketPara->socketType, socketPara->isEncrypt);
141 return serverId;
142 }
143
144 /**
145 * @brief Waits for a remote device to connect to this server socket.
146 *
147 * This method return a client ID indicates a client socket
148 * can be used to read data from and write data to remote device.
149 * This method will block until a connection is established.
150 *
151 * @param serverId The relative ID used to identify the current server socket, obtain the value by calling
152 * {@link SocketServerCreate}.
153 * @return Returns a client ID, if accept fail return {@link BT_SOCKET_INVALID_ID}.
154 */
SocketServerAccept(int serverId)155 int SocketServerAccept(int serverId)
156 {
157 HILOGI("SocketServerAccept start, serverId: %{public}d", serverId);
158 std::shared_ptr<ServerSocket> server = g_serverMap.GetObject(serverId);
159 if (server == nullptr) {
160 HILOGD("server is null!");
161 return BT_SOCKET_INVALID_ID;
162 }
163
164 std::shared_ptr<ClientSocket> client = server->Accept(0);
165 if (client == nullptr) {
166 HILOGE("client is null!");
167 return BT_SOCKET_INVALID_ID;
168 }
169 int clientId = g_clientMap.AddObject(client);
170 HILOGI("success, clientId: %{public}d", clientId);
171 return clientId;
172 }
173
174 /**
175 * @brief Disables an socket server socket and releases related resources.
176 *
177 * @param serverId The relative ID used to identify the current server socket, obtain the value by calling
178 * {@link SocketServerCreate}.
179 * @return Returns the operation result status {@link BtStatus}.
180 */
SocketServerClose(int serverId)181 int SocketServerClose(int serverId)
182 {
183 HILOGI("SocketServerClose start, serverId: %{public}d", serverId);
184 std::shared_ptr<ServerSocket> server = g_serverMap.GetObject(serverId);
185 if (server == nullptr) {
186 HILOGE("server is null!");
187 return OHOS_BT_STATUS_FAIL;
188 }
189 server->Close();
190 g_serverMap.RemoveObject(serverId);
191 return OHOS_BT_STATUS_SUCCESS;
192 }
193
194 /**
195 * @brief Set fast connection flag
196 *
197 * @param bdAddr The remote device address to connect.
198 * @return Returns the operation result status {@link BtStatus}.
199 */
SocketSetFastConnection(const BdAddr * bdAddr)200 int SocketSetFastConnection(const BdAddr *bdAddr)
201 {
202 string strAddress;
203 int leType = 1;
204 if (bdAddr == nullptr) {
205 HILOGE("bdAddr is nullptr.");
206 return OHOS_BT_STATUS_PARM_INVALID;
207 }
208 ConvertAddr(bdAddr->addr, strAddress);
209 // create a client to reuse requestfastestconn.
210 std::shared_ptr<GattClient> client = nullptr;
211 BluetoothRemoteDevice device(strAddress, leType);
212 client = std::make_shared<GattClient>(device);
213 client->Init();
214 int result = client->RequestFastestConn();
215 if (result != OHOS_BT_STATUS_SUCCESS) {
216 HILOGE("request fastest connect fail.");
217 return OHOS_BT_STATUS_FAIL;
218 }
219 return OHOS_BT_STATUS_SUCCESS;
220 }
221
222 /**
223 * @brief Connects to a remote device over the socket.
224 * This method will block until a connection is made or the connection fails.
225 *
226 * @param socketPara The param to create a client socket and connect to a remote device.
227 * @param bdAddr The remote device address to connect.
228 * @param psm BluetoothSocketType is {@link OHOS_SOCKET_L2CAP_LE} use dynamic PSM value from remote device.
229 * BluetoothSocketType is {@link OHOS_SOCKET_SPP_RFCOMM} use -1.
230 * @return Returns a client ID, if connect fail return {@link BT_SOCKET_INVALID_ID}.
231 */
SocketConnect(const BluetoothCreateSocketPara * socketPara,const BdAddr * bdAddr,int psm)232 int SocketConnect(const BluetoothCreateSocketPara *socketPara, const BdAddr *bdAddr, int psm)
233 {
234 HILOGI("SocketConnect start.");
235 if (socketPara == nullptr || bdAddr == nullptr) {
236 HILOGE("socketPara is nullptr, or bdAddr is nullptr");
237 return BT_SOCKET_INVALID_ID;
238 }
239
240 string strAddress;
241 ConvertAddr(bdAddr->addr, strAddress);
242 std::shared_ptr<BluetoothRemoteDevice> device = std::make_shared<BluetoothRemoteDevice>(strAddress, 0);
243
244 UUID serverUuid;
245 if (!GetSocketUuidPara(socketPara, serverUuid)) {
246 return BT_SOCKET_INVALID_ID;
247 }
248
249 std::shared_ptr<ClientSocket> client = std::make_shared<ClientSocket>(*device, serverUuid,
250 BtSocketType(socketPara->socketType), socketPara->isEncrypt);
251 HILOGI("socketType: %{public}d, isEncrypt: %{public}d", socketPara->socketType, socketPara->isEncrypt);
252 client->Init();
253 int result = client->Connect(psm);
254 if (result != OHOS_BT_STATUS_SUCCESS) {
255 HILOGE("SocketConnect fail, result: %{public}d", result);
256 client->Close();
257 HILOGE("SocketConnect closed.");
258 return BT_SOCKET_INVALID_ID;
259 }
260 int clientId = g_clientMap.AddObject(client);
261 HILOGI("SocketConnect success, clientId: %{public}d", clientId);
262 return clientId;
263 }
264
265 /**
266 * @brief Connects to a remote device over the socket.
267 * This method will block until a connection is made or the connection fails.
268 * @param socketPara The param to create a client socket and connect to a remote device.
269 * @param bdAddr The remote device address to connect.
270 * @param psm BluetoothSocketType is {@link OHOS_SOCKET_L2CAP_LE} use dynamic PSM value from remote device.
271 * BluetoothSocketType is {@link OHOS_SOCKET_SPP_RFCOMM} use -1.
272 * @param callback Reference to the socket state observer
273 * @return Returns a client ID, if connect fail return {@link BT_SOCKET_INVALID_ID}.
274 */
SocketConnectEx(const BluetoothCreateSocketPara * socketPara,const BdAddr * bdAddr,int psm,BtSocketConnectionCallback * callback)275 int SocketConnectEx(const BluetoothCreateSocketPara *socketPara, const BdAddr *bdAddr, int psm,
276 BtSocketConnectionCallback *callback)
277 {
278 HILOGI("SocketConnect start.");
279 if (socketPara == nullptr || bdAddr == nullptr || callback == nullptr) {
280 HILOGE("socketPara is nullptr, or bdAddr is nullptr, or callback is nullptr");
281 return BT_SOCKET_INVALID_ID;
282 }
283
284 string strAddress;
285 ConvertAddr(bdAddr->addr, strAddress);
286 std::shared_ptr<BluetoothRemoteDevice> device = std::make_shared<BluetoothRemoteDevice>(strAddress, 0);
287
288 UUID serverUuid;
289 if (!GetSocketUuidPara(socketPara, serverUuid)) {
290 return BT_SOCKET_INVALID_ID;
291 }
292
293 if (socketPara->socketType != OHOS_SOCKET_SPP_RFCOMM && socketPara->socketType != OHOS_SOCKET_L2CAP_LE) {
294 HILOGE("SocketType is not support");
295 return BT_SOCKET_INVALID_TYPE;
296 }
297
298 std::shared_ptr<BluetoothConnectionObserverWapper> connWrapper =
299 std::make_shared<BluetoothConnectionObserverWapper>(*callback);
300 std::shared_ptr<ClientSocket> client = std::make_shared<ClientSocket>(*device, serverUuid,
301 BtSocketType(socketPara->socketType), socketPara->isEncrypt, connWrapper);
302 HILOGI("socketType: %{public}d, isEncrypt: %{public}d", socketPara->socketType, socketPara->isEncrypt);
303 client->Init();
304 int result = client->Connect(psm);
305 if (result != OHOS_BT_STATUS_SUCCESS) {
306 HILOGE("SocketConnect fail, result: %{public}d", result);
307 client->Close();
308 HILOGE("SocketConnect closed.");
309 return BT_SOCKET_INVALID_ID;
310 }
311 int clientId = g_clientMap.AddObject(client);
312 std::lock_guard<std::mutex> lock(g_clientCbMapMutex);
313 g_clientCbMap.insert(std::pair<int, std::shared_ptr<BluetoothConnectionObserverWapper>>(clientId, connWrapper));
314 HILOGI("SocketConnect success, clientId: %{public}d", clientId);
315 return clientId;
316 }
317
318 /**
319 * @brief Disables a connection and releases related resources.
320 *
321 * @param clientId The relative ID used to identify the current client socket.
322 * @return Returns the operation result status {@link BtStatus}.
323 */
SocketDisconnect(int clientId)324 int SocketDisconnect(int clientId)
325 {
326 HILOGI("SocketDisconnect start, clientId: %{public}d", clientId);
327 std::shared_ptr<ClientSocket> client = g_clientMap.GetObject(clientId);
328 if (client == nullptr) {
329 HILOGE("client is null, clientId: %{public}d", clientId);
330 return OHOS_BT_STATUS_FAIL;
331 }
332 client->Close();
333 g_clientMap.RemoveObject(clientId);
334 std::lock_guard<std::mutex> lock(g_clientCbMapMutex);
335 ClientCbIterator it = g_clientCbMap.find(clientId);
336 if (it != g_clientCbMap.end()) {
337 g_clientCbMap.erase(it);
338 }
339 HILOGI("SocketDisConnect success, clientId: %{public}d", clientId);
340 return OHOS_BT_STATUS_SUCCESS;
341 }
342
343 /**
344 * @brief Socket get remote device's address.
345 *
346 * @param clientId The relative ID used to identify the current client socket.
347 * @param remoteAddr Remote device's address, memory allocated by caller.
348 * @return Returns the operation result status {@link BtStatus}.
349 */
SocketGetRemoteAddr(int clientId,BdAddr * remoteAddr)350 int SocketGetRemoteAddr(int clientId, BdAddr *remoteAddr)
351 {
352 HILOGI("SocketGetRemoteAddr clientId: %{public}d", clientId);
353 if (remoteAddr == nullptr) {
354 HILOGE("remoteAddr is null, clientId: %{public}d", clientId);
355 return OHOS_BT_STATUS_PARM_INVALID;
356 }
357 std::shared_ptr<ClientSocket> client = g_clientMap.GetObject(clientId);
358 if (client == nullptr) {
359 HILOGE("client is null, clientId: %{public}d", clientId);
360 return OHOS_BT_STATUS_FAIL;
361 }
362 string tmpAddr = client->GetRemoteDevice().GetDeviceAddr();
363 GetAddrFromString(tmpAddr, remoteAddr->addr);
364 HILOGI("device: %{public}s", GetEncryptAddr(tmpAddr).c_str());
365 return OHOS_BT_STATUS_SUCCESS;
366 }
367
368 /**
369 * @brief Get the connection status of this socket.
370 *
371 * @param clientId The relative ID used to identify the current client socket.
372 * @return Returns true is connected or false is not connected.
373 */
IsSocketConnected(int clientId)374 bool IsSocketConnected(int clientId)
375 {
376 HILOGI("IsSocketConnected clientId: %{public}d", clientId);
377 std::shared_ptr<ClientSocket> client = g_clientMap.GetObject(clientId);
378 if (client == nullptr) {
379 HILOGE("client is null, clientId: %{public}d", clientId);
380 return false;
381 }
382 bool isConnected = client->IsConnected();
383 HILOGI("clientId: %{public}d, isConnected: %{public}d", clientId, isConnected);
384 return isConnected;
385 }
386
387 /**
388 * @brief Read data from socket.
389 * This method blocks until input data is available.
390 *
391 * @param clientId The relative ID used to identify the current client socket.
392 * @param buf Indicate the buffer which read in, memory allocated by caller.
393 * @param bufLen Indicate the buffer length.
394 * @return Returns the length greater than 0 as read the actual length.
395 * Returns {@link BT_SOCKET_READ_SOCKET_CLOSED} if the socket is closed.
396 * Returns {@link BT_SOCKET_READ_FAILED} if the operation failed.
397 */
SocketRead(int clientId,uint8_t * buf,uint32_t bufLen)398 int SocketRead(int clientId, uint8_t *buf, uint32_t bufLen)
399 {
400 HILOGD("SocketRead start, clientId: %{public}d, bufLen: %{public}d", clientId, bufLen);
401 if (buf == nullptr || bufLen == 0) {
402 HILOGE("buf is null or bufLen is 0! clientId: %{public}d", clientId);
403 return BT_SOCKET_READ_FAILED;
404 }
405 std::shared_ptr<ClientSocket> client = g_clientMap.GetObject(clientId);
406 if (client == nullptr) {
407 HILOGE("client is null, clientId: %{public}d", clientId);
408 return BT_SOCKET_READ_FAILED;
409 }
410 if (client->GetInputStream() == nullptr) {
411 HILOGE("inputStream is null, clientId: %{public}d", clientId);
412 return BT_SOCKET_READ_FAILED;
413 }
414 int readLen = client->GetInputStream()->Read(buf, bufLen);
415 HILOGD("SocketRead ret, clientId: %{public}d, readLen: %{public}d", clientId, readLen);
416 return readLen;
417 }
418
419 /**
420 * @brief Client write data to socket.
421 *
422 * @param clientId The relative ID used to identify the current client socket.
423 * @param data Indicate the data to be written.
424 * @return Returns the actual write length.
425 * Returns {@link BT_SOCKET_WRITE_FAILED} if the operation failed.
426 */
SocketWrite(int clientId,const uint8_t * data,uint32_t len)427 int SocketWrite(int clientId, const uint8_t *data, uint32_t len)
428 {
429 HILOGD("SocketWrite start, clientId: %{public}d, len: %{public}d", clientId, len);
430 if (data == nullptr || len == 0) {
431 HILOGE("data is null or len is 0! clientId: %{public}d", clientId);
432 return BT_SOCKET_WRITE_FAILED;
433 }
434 std::shared_ptr<ClientSocket> client = g_clientMap.GetObject(clientId);
435 if (client == nullptr) {
436 HILOGE("client is null! clientId: %{public}d", clientId);
437 return BT_SOCKET_WRITE_FAILED;
438 }
439 if (client->GetOutputStream() == nullptr) {
440 HILOGE("outputStream is null, clientId: %{public}d", clientId);
441 return BT_SOCKET_READ_FAILED;
442 }
443 int writeLen = client->GetOutputStream()->Write(data, len);
444 HILOGD("end, writeLen: %{public}d", writeLen);
445 return writeLen;
446 }
447
448 /**
449 * @brief Get dynamic PSM value for OHOS_SOCKET_L2CAP.
450 *
451 * @param serverId The relative ID used to identify the current server socket, obtain the value by calling
452 * {@link SocketServerCreate}.
453 * @return Returns the PSM value.
454 * Returns {@link BT_SOCKET_INVALID_PSM} if the operation failed.
455 */
SocketGetPsm(int serverId)456 int SocketGetPsm(int serverId)
457 {
458 HILOGI("serverId: %{public}d", serverId);
459 std::shared_ptr<ServerSocket> server = g_serverMap.GetObject(serverId);
460 CHECK_AND_RETURN_LOG_RET(server, BT_SOCKET_INVALID_PSM, "server is null!");
461 return server->GetL2capPsm();
462 }
463
464 /**
465 * @brief Get server channel number for OHOS_SOCKET_RFCOMM.
466 *
467 * @param serverId The relative ID used to identify the current server socket, obtain the value by calling
468 * {@link SocketServerCreate}.
469 * @return Returns the scn.
470 * Returns {@link BT_SOCKET_INVALID_PSM} if the operation failed.
471 */
SocketGetScn(int serverId)472 int SocketGetScn(int serverId)
473 {
474 HILOGI("serverId: %{public}d", serverId);
475 std::shared_ptr<ServerSocket> server = g_serverMap.GetObject(serverId);
476 CHECK_AND_RETURN_LOG_RET(server, BT_SOCKET_INVALID_SCN, "server is null!");
477 return server->GetRfcommScn();
478 }
479
480 /**
481 * @brief Adjust the socket send and recv buffer size, limit range is 4KB to 50KB
482 *
483 * @param clientId The relative ID used to identify the current client socket.
484 * @param bufferSize The buffer size want to set, unit is byte.
485 * @return Returns the operation result status {@link BtStatus}.
486 */
SetSocketBufferSize(int clientId,uint32_t bufferSize)487 int SetSocketBufferSize(int clientId, uint32_t bufferSize)
488 {
489 HILOGI("start, clientId: %{public}d, bufferSize: %{public}d", clientId, bufferSize);
490 std::shared_ptr<ClientSocket> client = g_clientMap.GetObject(clientId);
491 if (client == nullptr) {
492 HILOGE("client is null! clientId: %{public}d", clientId);
493 return OHOS_BT_STATUS_FAIL;
494 }
495 int ret = client->SetBufferSize(bufferSize);
496 if (ret == RET_BAD_PARAM) {
497 return OHOS_BT_STATUS_PARM_INVALID;
498 } else if (ret == RET_BAD_STATUS) {
499 return OHOS_BT_STATUS_FAIL;
500 }
501 return OHOS_BT_STATUS_SUCCESS;
502 }
503 /**
504 * @brief Update the coc connection params
505 *
506 * @param param CocUpdateSocketParam instance for carry params.
507 * @param bdAddr The remote device address to connect.
508 * @return Returns the operation result status {@link BtStatus}.
509 */
SocketUpdateCocConnectionParams(BluetoothCocUpdateSocketParam * param,const BdAddr * bdAddr)510 int SocketUpdateCocConnectionParams(BluetoothCocUpdateSocketParam* param, const BdAddr *bdAddr)
511 {
512 CocUpdateSocketParam params;
513
514 HILOGI("Socket update coc params start");
515 CHECK_AND_RETURN_LOG_RET(param, OHOS_BT_STATUS_FAIL, "param is null");
516 CHECK_AND_RETURN_LOG_RET(bdAddr, OHOS_BT_STATUS_FAIL, "bdAddr is null");
517 ConvertAddr(bdAddr->addr, params.addr);
518 params.minInterval = param->minInterval;
519 params.maxInterval = param->maxInterval;
520 params.peripheralLatency = param->peripheralLatency;
521 params.supervisionTimeout = param->supervisionTimeout;
522 params.minConnEventLen = param->minConnEventLen;
523 params.maxConnEventLen = param->maxConnEventLen;
524
525 std::shared_ptr<BluetoothRemoteDevice> device = std::make_shared<BluetoothRemoteDevice>(params.addr,
526 OHOS_SOCKET_SPP_RFCOMM);
527 std::shared_ptr<ClientSocket> client = std::make_shared<ClientSocket>(*device, UUID::RandomUUID(),
528 TYPE_L2CAP_LE, false);
529 CHECK_AND_RETURN_LOG_RET(client, OHOS_BT_STATUS_FAIL, "client is null");
530 return client->UpdateCocConnectionParams(params);
531 }
532
533 } // namespace Bluetooth
534 } // namespace OHOS
535 #ifdef __cplusplus
536 }
537 #endif