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"
26 BT_EXPORT_API int bluetooth_network_activate_server()
30 BT_CHECK_ENABLED(return);
33 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
35 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_ACTIVATE,
36 in_param1, in_param2, in_param3, in_param4, &out_param);
38 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
43 BT_EXPORT_API int bluetooth_network_deactivate_server(void)
47 BT_CHECK_ENABLED(return);
50 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
52 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_DEACTIVATE,
53 in_param1, in_param2, in_param3, in_param4, &out_param);
55 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
60 BT_EXPORT_API int bluetooth_network_connect(const bluetooth_device_address_t *device_address,
61 bluetooth_network_role_t role,
65 bt_user_info_t *user_info;
67 BT_CHECK_PARAMETER(device_address, return);
68 BT_CHECK_ENABLED(return);
70 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_CONNECT)
71 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
72 BT_ERR("Don't have a privilege to use this API");
73 return BLUETOOTH_ERROR_PERMISSION_DEINED;
77 if (_bt_check_dpm(BT_DPM_ADDRESS, (void *)device_address) == BT_DPM_RESTRICTED) {
78 BT_ERR("Blacklist device");
79 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
83 case BLUETOOTH_NETWORK_PANU_ROLE:
84 uuid = g_strdup(BT_PAN_PANU_UUID);
86 case BLUETOOTH_NETWORK_NAP_ROLE:
87 uuid = g_strdup(BT_PAN_NAP_UUID);
89 case BLUETOOTH_NETWORK_GN_ROLE:
90 uuid = g_strdup(BT_PAN_GN_UUID);
96 if (_bt_check_dpm(BT_DPM_UUID, uuid) == BT_DPM_RESTRICTED) {
97 BT_ERR("Blacklist uuid");
99 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
102 if (_bt_check_dpm(BT_DPM_DESKTOP, NULL) == BT_DPM_RESTRICTED) {
103 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
104 bluetooth_device_class_t dev_class;
106 _bt_convert_addr_type_to_string(address, (unsigned char *)device_address->addr);
107 _bt_get_cod_by_address(address, &dev_class);
109 if (dev_class.major_class == BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
110 BT_ERR("Reject a authorization due to MDM Policy");
112 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
117 user_info = _bt_get_user_data(BT_COMMON);
118 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
121 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
123 g_array_append_vals(in_param1, device_address,
124 sizeof(bluetooth_device_address_t));
125 g_array_append_vals(in_param2, &role, sizeof(int));
127 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_CONNECT,
128 in_param1, in_param2, in_param3, in_param4,
129 user_info->cb, user_info->user_data);
131 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
136 BT_EXPORT_API int bluetooth_network_disconnect(const bluetooth_device_address_t *device_address)
139 bt_user_info_t *user_info;
141 BT_CHECK_PARAMETER(device_address, return);
142 BT_CHECK_ENABLED(return);
144 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_DISCONNECT)
145 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
146 BT_ERR("Don't have a privilege to use this API");
147 return BLUETOOTH_ERROR_PERMISSION_DEINED;
150 user_info = _bt_get_user_data(BT_COMMON);
151 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
154 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
156 g_array_append_vals(in_param1, device_address,
157 sizeof(bluetooth_device_address_t));
159 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_DISCONNECT,
160 in_param1, in_param2, in_param3, in_param4,
161 user_info->cb, user_info->user_data);
163 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
168 BT_EXPORT_API int bluetooth_network_server_disconnect(const bluetooth_device_address_t *device_address)
171 bt_user_info_t *user_info;
173 BT_CHECK_PARAMETER(device_address, return);
174 BT_CHECK_ENABLED(return);
176 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_SERVER_DISCONNECT)
177 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
178 BT_ERR("Don't have a privilege to use this API");
179 return BLUETOOTH_ERROR_PERMISSION_DEINED;
182 user_info = _bt_get_user_data(BT_COMMON);
183 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
186 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
188 g_array_append_vals(in_param1, device_address,
189 sizeof(bluetooth_device_address_t));
191 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
192 BT_NETWORK_SERVER_DISCONNECT,
193 in_param1, in_param2, in_param3, in_param4,
194 user_info->cb, user_info->user_data);
196 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);