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 "bluetooth-hid-api.h"
20 #include "bt-internal-types.h"
22 #include "bt-common.h"
23 #include "bt-request-sender.h"
24 #include "bt-event-handler.h"
26 #ifdef TIZEN_FEATURE_BT_DPM
30 BT_EXPORT_API int bluetooth_hid_init(hid_cb_func_ptr callback_ptr, void *user_data)
34 /* Register AVRCP events */
35 ret = _bt_register_event(BT_HID_EVENT , (void *)callback_ptr, user_data);
37 if (ret != BLUETOOTH_ERROR_NONE &&
38 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
39 BT_ERR("Fail to init the event handler");
43 _bt_set_user_data(BT_HID, (void *)callback_ptr, user_data);
45 return BLUETOOTH_ERROR_NONE;
48 BT_EXPORT_API int bluetooth_hid_deinit(void)
52 ret = _bt_unregister_event(BT_HID_EVENT);
54 if (ret != BLUETOOTH_ERROR_NONE) {
55 BT_ERR("Fail to deinit the event handler");
59 _bt_set_user_data(BT_HID, NULL, NULL);
61 return BLUETOOTH_ERROR_NONE;
64 BT_EXPORT_API int bluetooth_hid_connect(hid_device_address_t *device_address)
67 bt_user_info_t *user_info;
69 BT_CHECK_PARAMETER(device_address, return);
70 BT_CHECK_ENABLED(return);
72 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_CONNECT)
73 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
74 BT_ERR("Don't have a privilege to use this API");
75 return BLUETOOTH_ERROR_PERMISSION_DEINED;
77 #ifdef TIZEN_FEATURE_BT_DPM
78 if (_bt_check_dpm(BT_DPM_ADDRESS, device_address) == BT_DPM_RESTRICTED) {
79 BT_ERR("Blacklist device");
80 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
83 if (_bt_check_dpm(BT_DPM_UUID, BT_HID_UUID) == BT_DPM_RESTRICTED) {
84 BT_ERR("Blacklist uuid");
85 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
89 user_info = _bt_get_user_data(BT_HID);
90 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
93 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
95 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
97 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_CONNECT,
98 in_param1, in_param2, in_param3, in_param4,
99 user_info->cb, user_info->user_data);
101 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
106 BT_EXPORT_API int bluetooth_hid_disconnect(hid_device_address_t *device_address)
109 bt_user_info_t *user_info;
111 BT_CHECK_PARAMETER(device_address, return);
112 BT_CHECK_ENABLED(return);
114 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DISCONNECT)
115 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
116 BT_ERR("Don't have a privilege to use this API");
117 return BLUETOOTH_ERROR_PERMISSION_DEINED;
120 user_info = _bt_get_user_data(BT_HID);
121 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
124 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
126 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
128 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_DISCONNECT,
129 in_param1, in_param2, in_param3, in_param4,
130 user_info->cb, user_info->user_data);
132 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
137 BT_EXPORT_API int bluetooth_hid_enable_barcode_feature(void)
142 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
144 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_HID_ENABLE_BARCODE_FEATURE,
145 in_param1, in_param2, in_param3, in_param4, &out_param);
147 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);