1 /*
2 * Copyright (C) 2021-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 #include "bluetooth_socket_server.h"
17 #include "bluetooth_log.h"
18 #include "bluetooth_utils_server.h"
19 #include "bt_def.h"
20 #include "interface_profile_manager.h"
21 #include "interface_profile_socket.h"
22 #include "permission_utils.h"
23
24 using namespace OHOS::bluetooth;
25
26 namespace OHOS {
27 namespace Bluetooth {
Connect(ConnectSocketParam & param,int & fd)28 int BluetoothSocketServer::Connect(ConnectSocketParam ¶m, int &fd)
29 {
30 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
31 HILOGE("false, check permission failed");
32 return RET_NO_SUPPORT;
33 }
34 IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP);
35 if (socket != nullptr) {
36 fd = socket->Connect(param.addr, param.uuid, (int)param.securityFlag, (int)param.type);
37 }
38
39 return NO_ERROR;
40 }
41
Listen(ListenSocketParam & param,int & fd)42 int BluetoothSocketServer::Listen(ListenSocketParam ¶m, int &fd)
43 {
44 if (PermissionUtils::VerifyUseBluetoothPermission() == PERMISSION_DENIED) {
45 HILOGE("false, check permission failed");
46 return RET_NO_SUPPORT;
47 }
48
49 IProfileSocket *socket = (IProfileSocket *)IProfileManager::GetInstance()->GetProfileService(PROFILE_NAME_SPP);
50 if (socket != nullptr) {
51 fd = socket->Listen(param.name, param.uuid, (int)param.securityFlag, (int)param.type);
52 }
53
54 return NO_ERROR;
55 }
56 } // namespace Bluetooth
57 } // namespace OHOS