4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Atul Kumar Rai <a.rai@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
29 #include "bt-hal-log.h"
30 #include "bt-hal-msg.h"
31 #include "bt-hal-utils.h"
33 #include "bt-hal-hid-dbus-handler.h"
34 #include "bt-hal-event-receiver.h"
36 static const bthh_callbacks_t *bt_hal_hid_cbacks;
38 static bool interface_ready(void)
40 return bt_hal_hid_cbacks != NULL;
43 static void __bt_hal_handle_conn_state(void *buf, uint16_t len)
45 struct hal_ev_hidhost_conn_state *ev = buf;
47 if (bt_hal_hid_cbacks->connection_state_cb)
48 bt_hal_hid_cbacks->connection_state_cb((bt_bdaddr_t *) ev->bdaddr,
52 static void __bt_hal_handle_hidhost_info(void *buf, uint16_t len)
54 struct hal_ev_hidhost_info *ev = buf;
57 info.attr_mask = ev->attr;
58 info.sub_class = ev->subclass;
59 info.app_id = ev->app_id;
60 info.vendor_id = ev->vendor;
61 info.product_id = ev->product;
62 info.version = ev->version;
63 info.ctry_code = ev->country;
64 info.dl_len = ev->descr_len;
65 memcpy(info.dsc_list, ev->descr, info.dl_len);
67 if (bt_hal_hid_cbacks->hid_info_cb)
68 bt_hal_hid_cbacks->hid_info_cb((bt_bdaddr_t *) ev->bdaddr, &info);
71 static void __bt_hal_handle_proto_mode(void *buf, uint16_t len)
73 struct hal_ev_hidhost_proto_mode *ev = buf;
75 if (bt_hal_hid_cbacks->protocol_mode_cb)
76 bt_hal_hid_cbacks->protocol_mode_cb((bt_bdaddr_t *) ev->bdaddr,
77 ev->status, ev->mode);
80 static void __bt_hal_handle_idle_time(void *buf, uint16_t len)
82 struct hal_ev_hidhost_idle_time *ev = buf;
84 if (bt_hal_hid_cbacks->idle_time_cb)
85 bt_hal_hid_cbacks->idle_time_cb((bt_bdaddr_t *) ev->bdaddr, ev->status,
89 static void __bt_hal_handle_get_report(void *buf, uint16_t len)
91 struct hal_ev_hidhost_get_report *ev = buf;
93 if (len != sizeof(*ev) + ev->len) {
94 ERR("invalid get report event");
98 if (bt_hal_hid_cbacks->get_report_cb)
99 bt_hal_hid_cbacks->get_report_cb((bt_bdaddr_t *) ev->bdaddr, ev->status,
103 static void __bt_hal_handle_virtual_unplug(void *buf, uint16_t len)
105 struct hal_ev_hidhost_virtual_unplug *ev = buf;
107 if (bt_hal_hid_cbacks->virtual_unplug_cb)
108 bt_hal_hid_cbacks->virtual_unplug_cb((bt_bdaddr_t *) ev->bdaddr,
112 static void __bt_hal_handle_handshake(void *buf, uint16_t len)
114 struct hal_ev_hidhost_handshake *ev = buf;
116 if (bt_hal_hid_cbacks->handshake_cb)
117 bt_hal_hid_cbacks->handshake_cb((bt_bdaddr_t *) ev->bdaddr, ev->status);
120 static bt_status_t hidhost_connect(bt_bdaddr_t *bd_addr)
123 return _bt_hal_dbus_handler_hidhost_connect(bd_addr);
126 static bt_status_t hidhost_disconnect(bt_bdaddr_t *bd_addr)
129 return _bt_hal_dbus_handler_hidhost_disconnect(bd_addr);
132 static bt_status_t virtual_unplug(bt_bdaddr_t *bd_addr)
135 return BT_STATUS_UNSUPPORTED;
138 static bt_status_t hidhost_set_info(bt_bdaddr_t *bd_addr, bthh_hid_info_t *hid_info)
141 return BT_STATUS_UNSUPPORTED;
144 static bt_status_t get_protocol(bt_bdaddr_t *bd_addr,
145 bthh_protocol_mode_t protocol_mode)
148 return BT_STATUS_UNSUPPORTED;
151 static bt_status_t set_protocol(bt_bdaddr_t *bd_addr,
152 bthh_protocol_mode_t protocol_mode)
155 return BT_STATUS_UNSUPPORTED;
158 static bt_status_t get_report(bt_bdaddr_t *bd_addr,
159 bthh_report_type_t report_type,
164 return BT_STATUS_UNSUPPORTED;
167 static bt_status_t set_report(bt_bdaddr_t *bd_addr,
168 bthh_report_type_t report_type,
172 return BT_STATUS_UNSUPPORTED;
175 static bt_status_t hidhost_send_data(bt_bdaddr_t *bd_addr, char *data)
178 return BT_STATUS_UNSUPPORTED;
181 static void __bt_hal_handle_hid_events(int message, void *buf, uint16_t len)
185 if (!interface_ready())
189 case HAL_EV_HIDHOST_CONN_STATE:
190 DBG("Event: HAL_EV_HIDHOST_CONN_STATE");
191 __bt_hal_handle_conn_state(buf, len);
193 case HAL_EV_HIDHOST_INFO:
194 DBG("Event: HAL_EV_HIDHOST_INFO");
195 __bt_hal_handle_hidhost_info(buf, len);
197 case HAL_EV_HIDHOST_PROTO_MODE:
198 DBG("Event: HAL_EV_HIDHOST_PROTO_MODE");
199 __bt_hal_handle_proto_mode(buf, len);
201 case HAL_EV_HIDHOST_IDLE_TIME:
202 DBG("Event: HAL_EV_HIDHOST_IDLE_TIME");
203 __bt_hal_handle_idle_time(buf, len);
205 case HAL_EV_HIDHOST_GET_REPORT:
206 DBG("Event: HAL_EV_HIDHOST_GET_REPORT");
207 __bt_hal_handle_get_report(buf, len);
209 case HAL_EV_HIDHOST_VIRTUAL_UNPLUG:
210 DBG("Event: HAL_EV_HIDHOST_VIRTUAL_UNPLUG");
211 __bt_hal_handle_virtual_unplug(buf, len);
213 case HAL_EV_HIDHOST_HANDSHAKE:
214 DBG("Event: HAL_EV_HIDHOST_HANDSHAKE");
215 __bt_hal_handle_handshake(buf, len);
218 DBG("Event Currently not handled!!");
225 static bt_status_t init(bthh_callbacks_t *callbacks)
229 if (interface_ready())
230 return BT_STATUS_DONE;
232 bt_hal_hid_cbacks = callbacks;
233 DBG("Register HID events callback function");
234 _bt_hal_register_hid_dbus_handler_cb(__bt_hal_handle_hid_events);
235 _bt_hal_register_event_handler_cb(HAL_HIDHOST, __bt_hal_handle_hid_events);
237 return BT_STATUS_SUCCESS;
240 static void cleanup(void)
244 if (!interface_ready())
247 _bt_hal_unregister_hid_dbus_handler_cb();
248 _bt_hal_unregister_event_handler_cb(HAL_HIDHOST);
250 bt_hal_hid_cbacks = NULL;
253 static bthh_interface_t hidhost_if = {
254 .size = sizeof(hidhost_if),
256 .connect = hidhost_connect,
257 .disconnect = hidhost_disconnect,
258 .virtual_unplug = virtual_unplug,
259 .set_info = hidhost_set_info,
260 .get_protocol = get_protocol,
261 .set_protocol = set_protocol,
262 .get_report = get_report,
263 .set_report = set_report,
264 .send_data = hidhost_send_data,
268 bthh_interface_t *bt_get_hidhost_interface(void)