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 static int _bluetooth_handle_get_len(const char *str)
28 for (i = 0; str && str[i] != '\0'; i++);
32 BT_EXPORT_API int bluetooth_tds_provider_register(void)
34 int result = BLUETOOTH_ERROR_INTERNAL;
36 BT_CHECK_ENABLED_LE(return);
39 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
42 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_TDS_PROVIDER_REGISTER,
43 in_param1, in_param2, in_param3, in_param4, &out_param);
45 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
50 BT_EXPORT_API int bluetooth_tds_provider_unregister(void)
52 int result = BLUETOOTH_ERROR_INTERNAL;
54 BT_CHECK_ENABLED_LE(return);
57 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
60 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_TDS_PROVIDER_UNREGISTER,
61 in_param1, in_param2, in_param3, in_param4, &out_param);
63 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
68 BT_EXPORT_API int bluetooth_set_tds_provider_manuf_data(unsigned char *buf, unsigned int length)
71 bluetooth_advertising_data_t manuf_data;
73 BT_CHECK_ENABLED_LE(return);
75 retv_if(length > 0 && NULL == buf, BLUETOOTH_ERROR_INVALID_PARAM);
76 retv_if(length > BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX, BLUETOOTH_ERROR_INVALID_PARAM);
78 memcpy(manuf_data.data, buf, length);
81 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
83 g_array_append_vals(in_param1, &length, sizeof(unsigned int));
84 g_array_append_vals(in_param2, &manuf_data, sizeof(bluetooth_advertising_data_t));
86 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_TDS_PROVIDER_SET_MANUF_DATA,
87 in_param1, in_param2, in_param3, in_param4, &out_param);
89 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
94 BT_EXPORT_API int bluetooth_tds_provider_create(int transport, unsigned int handle)
96 int result = BLUETOOTH_ERROR_INTERNAL;
98 BT_CHECK_ENABLED_LE(return);
101 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
104 g_array_append_vals(in_param1, &handle, sizeof(unsigned int));
105 g_array_append_vals(in_param2, &transport, sizeof(unsigned int));
107 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_TDS_PROVIDER_CREATE,
108 in_param1, in_param2, in_param3, in_param4, &out_param);
110 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
115 BT_EXPORT_API int bluetooth_tds_provider_destroy(unsigned int handle)
117 int result = BLUETOOTH_ERROR_INTERNAL;
119 BT_CHECK_ENABLED_LE(return);
122 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
125 g_array_append_vals(in_param1, &handle, sizeof(unsigned int));
127 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_TDS_PROVIDER_DESTROY,
128 in_param1, in_param2, in_param3, in_param4, &out_param);
130 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
135 BT_EXPORT_API int bluetooth_set_tds_provider_transport_data(unsigned int tds_handle,
136 bluetooth_tds_transport_state_t state, unsigned char *buf, unsigned int length)
139 bluetooth_tds_data_t tds_data;
141 BT_CHECK_ENABLED_LE(return);
143 retv_if(NULL == buf, BLUETOOTH_ERROR_INVALID_PARAM);
144 retv_if(length == 0 || length > BLUETOOTH_TDS_DATA_LENGTH_MAX,
145 BLUETOOTH_ERROR_INVALID_PARAM);
146 tds_data.length = length;
147 memcpy(tds_data.data, buf, length);
150 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
152 g_array_append_vals(in_param1, &tds_handle, sizeof(unsigned int));
153 g_array_append_vals(in_param2, &state, sizeof(int));
154 g_array_append_vals(in_param3, &tds_data, sizeof(bluetooth_tds_data_t));
156 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_TDS_PROVIDER_SET_TRANSPORT_DATA,
157 in_param1, in_param2, in_param3, in_param4, &out_param);
159 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
164 BT_EXPORT_API int bluetooth_send_tds_activation_response(bluetooth_device_address_t *device_address,
165 unsigned int tds_handle, int response, unsigned char *buf, unsigned int length)
168 bluetooth_tds_data_t tds_data;
170 BT_CHECK_PARAMETER(device_address, return);
171 BT_CHECK_ENABLED_LE(return);
173 retv_if(length > 0 && NULL == buf, BLUETOOTH_ERROR_INVALID_PARAM);
174 tds_data.length = length;
175 memcpy(tds_data.data, buf, length);
178 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
180 g_array_append_vals(in_param1, &tds_handle, sizeof(unsigned int));
181 g_array_append_vals(in_param2, &response, sizeof(int));
182 g_array_append_vals(in_param3, device_address, sizeof(bluetooth_device_address_t));
183 g_array_append_vals(in_param4, &tds_data, sizeof(bluetooth_tds_data_t));
185 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_TDS_SEND_ACTIVATION_RESPONSE,
186 in_param1, in_param2, in_param3, in_param4, &out_param);
188 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
193 BT_EXPORT_API int bluetooth_tds_read_transport_data(const bluetooth_device_address_t *device_address,
198 bt_user_info_t *user_info;
199 int result = BLUETOOTH_ERROR_INTERNAL;
202 BT_CHECK_PARAMETER(device_address, return);
203 BT_CHECK_PARAMETER(handle, return);
204 BT_CHECK_ENABLED_LE(return);
206 user_info = _bt_get_user_data(BT_COMMON);
207 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
210 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
212 path = g_strdup(handle);
213 path_len = _bluetooth_handle_get_len(path);
214 g_array_append_vals(in_param1, path, path_len);
217 g_array_append_vals(in_param2, device_address,
218 sizeof(bluetooth_device_address_t));
220 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_TDS_READ_TRANSPORT_DATA,
221 in_param1, in_param2, in_param3, in_param4,
222 user_info->cb, user_info->user_data);
224 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
230 BT_EXPORT_API int bluetooth_tds_enable_control_point(const bluetooth_device_address_t *device_address,
235 bt_user_info_t *user_info;
236 int result = BLUETOOTH_ERROR_INTERNAL;
239 BT_CHECK_PARAMETER(device_address, return);
240 BT_CHECK_PARAMETER(handle, return);
241 BT_CHECK_ENABLED_LE(return);
243 user_info = _bt_get_user_data(BT_COMMON);
244 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
247 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
249 path = g_strdup(handle);
250 path_len = _bluetooth_handle_get_len(path);
251 g_array_append_vals(in_param1, path, path_len);
254 g_array_append_vals(in_param2, device_address,
255 sizeof(bluetooth_device_address_t));
257 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_TDS_ENABLE_CONTROL_POINT,
258 in_param1, in_param2, in_param3, in_param4,
259 user_info->cb, user_info->user_data);
261 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
267 BT_EXPORT_API int bluetooth_tds_activate_control_point(const bluetooth_device_address_t *device_address,
268 const char *handle, unsigned char *buf,
273 bt_user_info_t *user_info;
274 int result = BLUETOOTH_ERROR_INTERNAL;
275 bluetooth_control_point_data_t data;
278 BT_CHECK_PARAMETER(device_address, return);
279 BT_CHECK_PARAMETER(handle, return);
280 BT_CHECK_PARAMETER(buf, return);
281 BT_CHECK_ENABLED_LE(return);
283 user_info = _bt_get_user_data(BT_COMMON);
284 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
287 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
289 memset(&data, 0x00, sizeof(bluetooth_control_point_data_t));
291 data.length = length;
293 memcpy(data.data, buf, length);
295 path = g_strdup(handle);
296 path_len = _bluetooth_handle_get_len(path);
299 g_array_append_vals(in_param1, path, path_len);
301 g_array_append_vals(in_param2, device_address,
302 sizeof(bluetooth_device_address_t));
304 g_array_append_vals(in_param3, &data, sizeof(bluetooth_control_point_data_t));
306 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_TDS_ACTIVATE_CONTROL_POINT,
307 in_param1, in_param2, in_param3, in_param4,
308 user_info->cb, user_info->user_data);
310 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);