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 BT_EXPORT_API int bluetooth_network_activate_server()
29 BT_CHECK_ENABLED(return);
32 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
34 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_ACTIVATE,
35 in_param1, in_param2, in_param3, in_param4, &out_param);
37 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
42 BT_EXPORT_API int bluetooth_network_deactivate_server(void)
46 BT_CHECK_ENABLED(return);
49 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
51 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_NETWORK_DEACTIVATE,
52 in_param1, in_param2, in_param3, in_param4, &out_param);
54 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
59 BT_EXPORT_API int bluetooth_network_connect(const bluetooth_device_address_t *device_address,
60 bluetooth_network_role_t role,
64 bt_user_info_t *user_info;
66 BT_CHECK_PARAMETER(device_address, return);
67 BT_CHECK_ENABLED(return);
69 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_CONNECT)
70 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
71 BT_ERR("Don't have a privilege to use this API");
72 return BLUETOOTH_ERROR_PERMISSION_DEINED;
75 user_info = _bt_get_user_data(BT_COMMON);
76 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
79 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
81 g_array_append_vals(in_param1, device_address,
82 sizeof(bluetooth_device_address_t));
83 g_array_append_vals(in_param2, &role, sizeof(int));
85 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_CONNECT,
86 in_param1, in_param2, in_param3, in_param4,
87 user_info->cb, user_info->user_data);
89 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
94 BT_EXPORT_API int bluetooth_network_disconnect(const bluetooth_device_address_t *device_address)
97 bt_user_info_t *user_info;
99 BT_CHECK_PARAMETER(device_address, return);
100 BT_CHECK_ENABLED(return);
102 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_DISCONNECT)
103 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
104 BT_ERR("Don't have a privilege to use this API");
105 return BLUETOOTH_ERROR_PERMISSION_DEINED;
108 user_info = _bt_get_user_data(BT_COMMON);
109 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
112 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
114 g_array_append_vals(in_param1, device_address,
115 sizeof(bluetooth_device_address_t));
117 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_NETWORK_DISCONNECT,
118 in_param1, in_param2, in_param3, in_param4,
119 user_info->cb, user_info->user_data);
121 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
126 BT_EXPORT_API int bluetooth_network_server_disconnect(const bluetooth_device_address_t *device_address)
129 bt_user_info_t *user_info;
131 BT_CHECK_PARAMETER(device_address, return);
132 BT_CHECK_ENABLED(return);
134 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_NETWORK_SERVER_DISCONNECT)
135 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
136 BT_ERR("Don't have a privilege to use this API");
137 return BLUETOOTH_ERROR_PERMISSION_DEINED;
140 user_info = _bt_get_user_data(BT_COMMON);
141 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
144 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
146 g_array_append_vals(in_param1, device_address,
147 sizeof(bluetooth_device_address_t));
149 result = _bt_send_request_async(BT_BLUEZ_SERVICE,
150 BT_NETWORK_SERVER_DISCONNECT,
151 in_param1, in_param2, in_param3, in_param4,
152 user_info->cb, user_info->user_data);
154 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);