2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "bluetooth-api.h"
19 #include "bt-internal-types.h"
21 #include "bt-common.h"
22 #include "bt-request-sender.h"
23 #include "bt-event-handler.h"
25 #ifdef TIZEN_FEATURE_BT_DPM
29 BT_EXPORT_API int bluetooth_network_activate_server()
33 BT_CHECK_ENABLED(return);
36 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
38 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_ACTIVATE,
39 in_param1, in_param2, in_param3, in_param4, &out_param);
41 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
46 BT_EXPORT_API int bluetooth_network_deactivate_server(void)
50 BT_CHECK_ENABLED(return);
53 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
55 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_DEACTIVATE,
56 in_param1, in_param2, in_param3, in_param4, &out_param);
58 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
63 BT_EXPORT_API int bluetooth_network_connect(const bluetooth_device_address_t *device_address,
64 bluetooth_network_role_t role,
68 bt_user_info_t *user_info;
70 BT_CHECK_PARAMETER(device_address, return);
71 BT_CHECK_ENABLED(return);
73 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_CONNECT)
74 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
75 BT_ERR("Don't have a privilege to use this API");
76 return BLUETOOTH_ERROR_PERMISSION_DEINED;
79 #ifdef TIZEN_FEATURE_BT_DPM
81 if (_bt_check_dpm(BT_DPM_ADDRESS, (void *)device_address) == BT_DPM_RESTRICTED) {
82 BT_ERR("Blacklist device");
83 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
87 case BLUETOOTH_NETWORK_PANU_ROLE:
88 uuid = g_strdup(BT_PAN_PANU_UUID);
90 case BLUETOOTH_NETWORK_NAP_ROLE:
91 uuid = g_strdup(BT_PAN_NAP_UUID);
93 case BLUETOOTH_NETWORK_GN_ROLE:
94 uuid = g_strdup(BT_PAN_GN_UUID);
100 if (_bt_check_dpm(BT_DPM_UUID, uuid) == BT_DPM_RESTRICTED) {
101 BT_ERR("Blacklist uuid");
103 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
106 if (_bt_check_dpm(BT_DPM_DESKTOP, NULL) == BT_DPM_RESTRICTED) {
107 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
108 bluetooth_device_class_t dev_class;
110 _bt_convert_addr_type_to_string(address, (unsigned char *)device_address->addr);
111 _bt_get_cod_by_address(address, &dev_class);
113 if (dev_class.major_class == BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
114 BT_ERR("Reject a authorization due to MDM Policy");
116 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
122 user_info = _bt_get_user_data(BT_COMMON);
123 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
126 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
128 g_array_append_vals(in_param1, device_address,
129 sizeof(bluetooth_device_address_t));
130 g_array_append_vals(in_param2, &role, sizeof(int));
132 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_CONNECT,
133 in_param1, in_param2, in_param3, in_param4,
134 user_info->cb, user_info->user_data);
136 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
141 BT_EXPORT_API int bluetooth_network_disconnect(const bluetooth_device_address_t *device_address)
144 bt_user_info_t *user_info;
146 BT_CHECK_PARAMETER(device_address, return);
147 BT_CHECK_ENABLED(return);
149 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_DISCONNECT)
150 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
151 BT_ERR("Don't have a privilege to use this API");
152 return BLUETOOTH_ERROR_PERMISSION_DEINED;
155 user_info = _bt_get_user_data(BT_COMMON);
156 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
159 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
161 g_array_append_vals(in_param1, device_address,
162 sizeof(bluetooth_device_address_t));
164 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_DISCONNECT,
165 in_param1, in_param2, in_param3, in_param4,
166 user_info->cb, user_info->user_data);
168 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
173 BT_EXPORT_API int bluetooth_network_server_disconnect(const bluetooth_device_address_t *device_address)
176 bt_user_info_t *user_info;
178 BT_CHECK_PARAMETER(device_address, return);
179 BT_CHECK_ENABLED(return);
181 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_SERVER_DISCONNECT)
182 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
183 BT_ERR("Don't have a privilege to use this API");
184 return BLUETOOTH_ERROR_PERMISSION_DEINED;
187 user_info = _bt_get_user_data(BT_COMMON);
188 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
191 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
193 g_array_append_vals(in_param1, device_address,
194 sizeof(bluetooth_device_address_t));
196 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
197 BT_NETWORK_SERVER_DISCONNECT,
198 in_param1, in_param2, in_param3, in_param4,
199 user_info->cb, user_info->user_data);
201 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);