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