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"
27 BT_EXPORT_API int bluetooth_hid_init(hid_cb_func_ptr callback_ptr, void *user_data)
31 /* Register AVRCP events */
32 ret = _bt_register_event(BT_HID_EVENT , (void *)callback_ptr, user_data);
34 if (ret != BLUETOOTH_ERROR_NONE &&
35 ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
36 BT_ERR("Fail to init the event handler");
40 _bt_set_user_data(BT_HID, (void *)callback_ptr, user_data);
42 return BLUETOOTH_ERROR_NONE;
45 BT_EXPORT_API int bluetooth_hid_deinit(void)
49 ret = _bt_unregister_event(BT_HID_EVENT);
51 if (ret != BLUETOOTH_ERROR_NONE) {
52 BT_ERR("Fail to deinit the event handler");
56 _bt_set_user_data(BT_HID, NULL, NULL);
58 return BLUETOOTH_ERROR_NONE;
61 BT_EXPORT_API int bluetooth_hid_connect(hid_device_address_t *device_address)
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_HID_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 if (_bt_check_dpm(BT_DPM_ADDRESS, device_address) == BT_DPM_RESTRICTED) {
76 BT_ERR("Blacklist device");
77 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
80 if (_bt_check_dpm(BT_DPM_UUID, BT_HID_UUID) == BT_DPM_RESTRICTED) {
81 BT_ERR("Blacklist uuid");
82 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
85 user_info = _bt_get_user_data(BT_HID);
86 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
89 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
91 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
93 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_CONNECT,
94 in_param1, in_param2, in_param3, in_param4,
95 user_info->cb, user_info->user_data);
97 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
102 BT_EXPORT_API int bluetooth_hid_disconnect(hid_device_address_t *device_address)
105 bt_user_info_t *user_info;
107 BT_CHECK_PARAMETER(device_address, return);
108 BT_CHECK_ENABLED(return);
110 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_HID_DISCONNECT)
111 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
112 BT_ERR("Don't have a privilege to use this API");
113 return BLUETOOTH_ERROR_PERMISSION_DEINED;
116 user_info = _bt_get_user_data(BT_HID);
117 retv_if(user_info->cb == NULL, BLUETOOTH_ERROR_INTERNAL);
120 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
122 g_array_append_vals(in_param1, device_address, sizeof(bluetooth_device_address_t));
124 result = _bt_send_request_async(BT_BLUEZ_SERVICE, BT_HID_DISCONNECT,
125 in_param1, in_param2, in_param3, in_param4,
126 user_info->cb, user_info->user_data);
128 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
133 BT_EXPORT_API int bluetooth_hid_enable_barcode_feature(void)
138 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
140 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_HID_ENABLE_BARCODE_FEATURE,
141 in_param1, in_param2, in_param3, in_param4, &out_param);
143 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);