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_otp_server_init(const char *directory)
34 int result = BLUETOOTH_ERROR_INTERNAL;
35 bt_user_info_t *user_info;
36 char dir_name[BLUETOOTH_MAX_OTP_SERVER_DIR_NAME];
39 BT_CHECK_ENABLED(return);
41 user_info = _bt_get_user_data(BT_COMMON);
42 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
45 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
48 g_strlcpy(dir_name, directory, sizeof(dir_name));
52 g_array_append_vals(in_param1, dir_name,
53 BLUETOOTH_MAX_OTP_SERVER_DIR_NAME);
55 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_SERVER_INIT,
56 in_param1, in_param2, in_param3, in_param4,
57 user_info->cb, user_info->user_data);
59 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
65 BT_EXPORT_API int bluetooth_otp_server_deinit()
67 int result = BLUETOOTH_ERROR_INTERNAL;
68 bt_user_info_t *user_info;
71 BT_CHECK_ENABLED(return);
73 user_info = _bt_get_user_data(BT_COMMON);
74 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
77 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
80 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_SERVER_DEINIT,
81 in_param1, in_param2, in_param3, in_param4,
82 user_info->cb, user_info->user_data);
84 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
90 BT_EXPORT_API int bluetooth_otp_read_characteristic_value(const char *handle)
94 bt_user_info_t *user_info;
95 int result = BLUETOOTH_ERROR_INTERNAL;
98 BT_CHECK_PARAMETER(handle, return);
99 BT_CHECK_ENABLED_LE(return);
101 user_info = _bt_get_user_data(BT_COMMON);
102 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
105 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
107 path = g_strdup(handle);
108 path_len = _bluetooth_handle_get_len(path);
109 g_array_append_vals(in_param1, path, path_len);
112 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_READ_VALUE,
113 in_param1, in_param2, in_param3, in_param4,
114 user_info->cb, user_info->user_data);
116 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
122 BT_EXPORT_API int bluetooth_otp_enable_notification(const char *handle)
126 bt_user_info_t *user_info;
127 int result = BLUETOOTH_ERROR_INTERNAL;
130 BT_CHECK_PARAMETER(handle, return);
131 BT_CHECK_ENABLED_LE(return);
133 user_info = _bt_get_user_data(BT_COMMON);
134 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
137 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
139 path = g_strdup(handle);
140 path_len = _bluetooth_handle_get_len(path);
141 g_array_append_vals(in_param1, path, path_len);
144 result = _bt_send_request_async(
146 BT_OTP_ENABLE_NOTIFICATION,
147 in_param1, in_param2,
148 in_param3, in_param4,
149 user_info->cb, user_info->user_data);
151 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
157 BT_EXPORT_API int bluetooth_otp_write_characteristics_value(const char *handle,
158 unsigned char *buf, int length)
162 bt_user_info_t *user_info;
163 int result = BLUETOOTH_ERROR_INTERNAL;
164 bluetooth_otp_charc_data_t data;
167 BT_CHECK_PARAMETER(handle, return);
168 BT_CHECK_PARAMETER(buf, return);
169 BT_CHECK_ENABLED_LE(return);
171 user_info = _bt_get_user_data(BT_COMMON);
172 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
175 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
177 memset(&data, 0x00, sizeof(bluetooth_otp_charc_data_t));
179 data.length = length;
181 memcpy(data.data, buf, length);
183 path = g_strdup(handle);
184 path_len = _bluetooth_handle_get_len(path);
187 g_array_append_vals(in_param1, path, path_len);
189 g_array_append_vals(in_param2, &data, sizeof(bluetooth_otp_charc_data_t));
192 for (i = 0; i < length; i++)
193 BT_INFO("Value[%d] = %u", i, buf[i]);
194 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_OTP_WRITE_VALUE,
195 in_param1, in_param2, in_param3, in_param4,
196 user_info->cb, user_info->user_data);
198 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);