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.
20 #include "bluetooth-api.h"
21 #include "bt-internal-types.h"
23 #include "bt-common.h"
24 #include "bt-request-sender.h"
25 #include "bt-event-handler.h"
27 #ifdef TIZEN_FEATURE_BT_DPM
31 static void __bt_get_file_size(char **files, unsigned long *file_size, int *count)
34 unsigned long size = 0;
36 while (files[file_count] != NULL) {
37 size = size + strlen(files[file_count]);
45 BT_EXPORT_API int bluetooth_opc_init(void)
47 bt_user_info_t *user_info;
49 user_info = _bt_get_user_data(BT_COMMON);
50 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
52 return _bt_register_event(BT_OPP_CLIENT_EVENT, user_info->cb, user_info->user_data);
55 BT_EXPORT_API int bluetooth_opc_deinit(void)
57 return _bt_unregister_event(BT_OPP_CLIENT_EVENT);
60 BT_EXPORT_API int bluetooth_opc_push_files(bluetooth_device_address_t *remote_address,
61 char **file_name_array)
67 bt_user_info_t *user_info;
68 char filename[BT_FILE_PATH_MAX];
70 BT_CHECK_PARAMETER(remote_address, return);
71 BT_CHECK_PARAMETER(file_name_array, return);
72 BT_CHECK_ENABLED(return);
74 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_OPP_PUSH_FILES)
75 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
76 BT_ERR("Don't have a privilege to use this API");
77 return BLUETOOTH_ERROR_PERMISSION_DEINED;
80 #ifdef TIZEN_FEATURE_BT_DPM
81 if (_bt_check_dpm(BT_DPM_ADDRESS, remote_address) == BT_DPM_RESTRICTED) {
82 BT_ERR("Blacklist device");
83 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
86 if (_bt_check_dpm(BT_DPM_OPP, NULL) == BT_DPM_RESTRICTED) {
87 BT_ERR("Not allow to send files");
88 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
91 if (_bt_check_dpm(BT_DPM_DESKTOP, NULL) == BT_DPM_RESTRICTED) {
92 char address[BT_ADDRESS_STRING_SIZE] = { 0 };
93 bluetooth_device_class_t dev_class;
95 _bt_convert_addr_type_to_string(address, remote_address->addr);
96 _bt_get_cod_by_address(address, &dev_class);
98 if (dev_class.major_class == BLUETOOTH_DEVICE_MAJOR_CLASS_COMPUTER) {
99 BT_ERR("Reject a authorization due to MDM Policy");
100 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
105 __bt_get_file_size(file_name_array, &size, &file_count);
106 retv_if(file_count == 0, BLUETOOTH_ERROR_INVALID_PARAM);
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, remote_address, sizeof(bluetooth_device_address_t));
116 for (i = 0; i < file_count; i++) {
117 if (strlen(file_name_array[i]) >= sizeof(filename)) {
118 BT_ERR("[%s] has too long path.", file_name_array[i]);
119 BT_FREE_PARAMS(in_param1, in_param2, in_param3,
120 in_param4, out_param);
121 return BLUETOOTH_ERROR_INVALID_PARAM;
123 g_strlcpy(filename, file_name_array[i], sizeof(filename));
124 g_array_append_vals(in_param2, filename, BT_FILE_PATH_MAX);
127 g_array_append_vals(in_param3, &file_count, sizeof(int));
129 result = _bt_send_request_async(BT_OBEX_SERVICE, BT_OPP_PUSH_FILES,
130 in_param1, in_param2, in_param3, in_param4,
131 user_info->cb, user_info->user_data);
133 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
138 BT_EXPORT_API int bluetooth_opc_cancel_push(void)
142 BT_CHECK_ENABLED(return);
145 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
147 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_CANCEL_PUSH,
148 in_param1, in_param2, in_param3, in_param4, &out_param);
150 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
155 BT_EXPORT_API gboolean bluetooth_opc_session_is_exist(void)
158 gboolean exist = FALSE;
160 BT_CHECK_ENABLED(return);
163 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
165 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
166 in_param1, in_param2, in_param3, in_param4, &out_param);
168 if (result == BLUETOOTH_ERROR_NONE) {
169 exist = g_array_index(out_param, gboolean, 0);
170 BT_DBG("Exist %d", exist);
172 BT_ERR("Fail to send request");
175 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
180 BT_EXPORT_API int bluetooth_opc_is_sending(gboolean *is_sending)
186 BT_CHECK_ENABLED(return);
189 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
191 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_IS_PUSHING_FILES,
192 in_param1, in_param2, in_param3, in_param4, &out_param);
194 if (result == BLUETOOTH_ERROR_NONE)
195 *is_sending = g_array_index(out_param, gboolean, 0);
197 BT_ERR("Fail to send request");
200 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
205 BT_EXPORT_API int bluetooth_opp_get_transfer_progress(bluetooth_opp_transfer_type_t transfer_type,
206 int transfer_id, unsigned char *progress)
209 int direction = transfer_type;
211 BT_CHECK_ENABLED(return);
214 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
216 g_array_append_vals(in_param1, &direction, sizeof(int));
217 g_array_append_vals(in_param2, &transfer_id, sizeof(int));
219 result = _bt_send_request(BT_OBEX_SERVICE, BT_OPP_GET_TRANSFER_PROGRESS,
220 in_param1, in_param2, in_param3, in_param4, &out_param);
222 if (result == BLUETOOTH_ERROR_NONE) {
223 percentage = g_array_index(out_param, guint8, 0);
224 BT_DBG("Percentage: %d", percentage);
226 BT_ERR("Fail to send request");
230 *progress = percentage;
232 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);