4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hocheol Seo <hocheol.seo@samsung.com>
7 * Girishashok Joshi <girish.joshi@samsung.com>
8 * Chanyeol Park <chanyeol.park@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 #include "bluetooth-api.h"
25 #include "bt-internal-types.h"
27 #include "bt-common.h"
28 #include "bt-request-sender.h"
29 #include "bt-event-handler.h"
31 BT_EXPORT_API int bluetooth_network_activate_server()
35 BT_CHECK_ENABLED(return);
38 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
40 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_ACTIVATE,
41 in_param1, in_param2, in_param3, in_param4, &out_param);
43 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
48 BT_EXPORT_API int bluetooth_network_deactivate_server(void)
52 BT_CHECK_ENABLED(return);
55 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
57 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_DEACTIVATE,
58 in_param1, in_param2, in_param3, in_param4, &out_param);
60 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
65 BT_EXPORT_API int bluetooth_network_connect(const bluetooth_device_address_t *device_address,
66 bluetooth_network_role_t role,
70 bt_user_info_t *user_info;
72 BT_CHECK_PARAMETER(device_address, return);
73 BT_CHECK_ENABLED(return);
75 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_CONNECT)
76 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
77 BT_ERR("Don't have a privilege to use this API");
78 return BLUETOOTH_ERROR_PERMISSION_DEINED;
81 user_info = _bt_get_user_data(BT_COMMON);
82 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
85 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
87 g_array_append_vals(in_param1, device_address,
88 sizeof(bluetooth_device_address_t));
89 g_array_append_vals(in_param2, &role, sizeof(int));
91 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_CONNECT,
92 in_param1, in_param2, in_param3, in_param4,
93 user_info->cb, user_info->user_data);
95 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
100 BT_EXPORT_API int bluetooth_network_disconnect(const bluetooth_device_address_t *device_address)
103 bt_user_info_t *user_info;
105 BT_CHECK_PARAMETER(device_address, return);
106 BT_CHECK_ENABLED(return);
108 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_DISCONNECT)
109 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
110 BT_ERR("Don't have a privilege to use this API");
111 return BLUETOOTH_ERROR_PERMISSION_DEINED;
114 user_info = _bt_get_user_data(BT_COMMON);
115 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
118 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
120 g_array_append_vals(in_param1, device_address,
121 sizeof(bluetooth_device_address_t));
123 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_DISCONNECT,
124 in_param1, in_param2, in_param3, in_param4,
125 user_info->cb, user_info->user_data);
127 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
132 BT_EXPORT_API int bluetooth_network_server_disconnect(const bluetooth_device_address_t *device_address)
135 bt_user_info_t *user_info;
137 BT_CHECK_PARAMETER(device_address, return);
138 BT_CHECK_ENABLED(return);
140 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_SERVER_DISCONNECT)
141 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
142 BT_ERR("Don't have a privilege to use this API");
143 return BLUETOOTH_ERROR_PERMISSION_DEINED;
146 user_info = _bt_get_user_data(BT_COMMON);
147 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
150 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
152 g_array_append_vals(in_param1, device_address,
153 sizeof(bluetooth_device_address_t));
155 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
156 BT_NETWORK_SERVER_DISCONNECT,
157 in_param1, in_param2, in_param3, in_param4,
158 user_info->cb, user_info->user_data);
160 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);