2013-10-18 18:47:58 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
2013-10-22 20:16:16 +08:00
|
|
|
#include <string.h>
|
2013-11-08 21:23:03 +08:00
|
|
|
#include <stdlib.h>
|
2013-10-18 18:47:58 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
#include "hal-log.h"
|
2013-10-18 18:47:58 +08:00
|
|
|
#include "hal.h"
|
2013-10-22 20:16:16 +08:00
|
|
|
#include "hal-msg.h"
|
2014-02-25 00:05:03 +08:00
|
|
|
#include "ipc-common.h"
|
2013-10-22 20:16:16 +08:00
|
|
|
#include "hal-ipc.h"
|
2013-10-18 18:47:58 +08:00
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static const bthh_callbacks_t *cbacks;
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
static bool interface_ready(void)
|
|
|
|
{
|
2013-11-08 00:17:04 +08:00
|
|
|
return cbacks != NULL;
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 21:53:06 +08:00
|
|
|
static void handle_conn_state(void *buf, uint16_t len, int fd)
|
2013-10-31 20:19:47 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_ev_hidhost_conn_state *ev = buf;
|
2013-10-31 20:19:47 +08:00
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
if (cbacks->connection_state_cb)
|
|
|
|
cbacks->connection_state_cb((bt_bdaddr_t *) ev->bdaddr,
|
2013-10-31 20:19:47 +08:00
|
|
|
ev->state);
|
|
|
|
}
|
|
|
|
|
2014-06-11 21:53:06 +08:00
|
|
|
static void handle_info(void *buf, uint16_t len, int fd)
|
2013-11-01 21:08:40 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_ev_hidhost_info *ev = buf;
|
2013-11-01 21:08:40 +08:00
|
|
|
bthh_hid_info_t info;
|
|
|
|
|
|
|
|
info.attr_mask = ev->attr;
|
|
|
|
info.sub_class = ev->subclass;
|
|
|
|
info.app_id = ev->app_id;
|
|
|
|
info.vendor_id = ev->vendor;
|
|
|
|
info.product_id = ev->product;
|
|
|
|
info.version = ev->version;
|
|
|
|
info.ctry_code = ev->country;
|
|
|
|
info.dl_len = ev->descr_len;
|
|
|
|
memcpy(info.dsc_list, ev->descr, info.dl_len);
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
if (cbacks->hid_info_cb)
|
|
|
|
cbacks->hid_info_cb((bt_bdaddr_t *) ev->bdaddr, info);
|
2013-11-01 21:08:40 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 21:53:06 +08:00
|
|
|
static void handle_proto_mode(void *buf, uint16_t len, int fd)
|
2013-11-06 05:09:09 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_ev_hidhost_proto_mode *ev = buf;
|
2013-11-06 05:09:09 +08:00
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
if (cbacks->protocol_mode_cb)
|
|
|
|
cbacks->protocol_mode_cb((bt_bdaddr_t *) ev->bdaddr,
|
2013-11-06 05:09:09 +08:00
|
|
|
ev->status, ev->mode);
|
|
|
|
}
|
|
|
|
|
2014-06-11 21:53:06 +08:00
|
|
|
static void handle_idle_time(void *buf, uint16_t len, int fd)
|
2014-02-18 18:05:20 +08:00
|
|
|
{
|
|
|
|
struct hal_ev_hidhost_idle_time *ev = buf;
|
|
|
|
|
|
|
|
if (cbacks->idle_time_cb)
|
|
|
|
cbacks->idle_time_cb((bt_bdaddr_t *) ev->bdaddr, ev->status,
|
|
|
|
ev->idle_rate);
|
|
|
|
}
|
|
|
|
|
2014-06-11 21:53:06 +08:00
|
|
|
static void handle_get_report(void *buf, uint16_t len, int fd)
|
2013-11-06 05:09:14 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_ev_hidhost_get_report *ev = buf;
|
2013-11-06 05:09:14 +08:00
|
|
|
|
2013-11-19 22:02:39 +08:00
|
|
|
if (len != sizeof(*ev) + ev->len) {
|
|
|
|
error("invalid get report event, aborting");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
if (cbacks->get_report_cb)
|
|
|
|
cbacks->get_report_cb((bt_bdaddr_t *) ev->bdaddr, ev->status,
|
|
|
|
ev->data, ev->len);
|
2013-11-06 05:09:14 +08:00
|
|
|
}
|
|
|
|
|
2014-06-11 21:53:06 +08:00
|
|
|
static void handle_virtual_unplug(void *buf, uint16_t len, int fd)
|
2013-11-08 06:10:18 +08:00
|
|
|
{
|
|
|
|
struct hal_ev_hidhost_virtual_unplug *ev = buf;
|
|
|
|
|
|
|
|
if (cbacks->virtual_unplug_cb)
|
|
|
|
cbacks->virtual_unplug_cb((bt_bdaddr_t *) ev->bdaddr,
|
|
|
|
ev->status);
|
|
|
|
}
|
|
|
|
|
2014-11-20 19:18:49 +08:00
|
|
|
static void handle_handshake(void *buf, uint16_t len, int fd)
|
|
|
|
{
|
|
|
|
#if ANDROID_VERSION >= PLATFORM_VER(5, 0, 0)
|
|
|
|
struct hal_ev_hidhost_handshake *ev = buf;
|
|
|
|
|
|
|
|
if (cbacks->handshake_cb)
|
|
|
|
cbacks->handshake_cb((bt_bdaddr_t *) ev->bdaddr, ev->status);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2014-04-29 19:17:25 +08:00
|
|
|
/*
|
|
|
|
* handlers will be called from notification thread context,
|
|
|
|
* index in table equals to 'opcode - HAL_MINIMUM_EVENT'
|
|
|
|
*/
|
2013-11-19 22:02:39 +08:00
|
|
|
static const struct hal_ipc_handler ev_handlers[] = {
|
2014-06-10 20:50:56 +08:00
|
|
|
/* HAL_EV_HIDHOST_CONN_STATE */
|
|
|
|
{ handle_conn_state, false, sizeof(struct hal_ev_hidhost_conn_state) },
|
|
|
|
/* HAL_EV_HIDHOST_INFO */
|
|
|
|
{ handle_info, false, sizeof(struct hal_ev_hidhost_info) },
|
|
|
|
/* HAL_EV_HIDHOST_PROTO_MODE */
|
|
|
|
{ handle_proto_mode, false, sizeof(struct hal_ev_hidhost_proto_mode) },
|
|
|
|
/* HAL_EV_HIDHOST_IDLE_TIME */
|
|
|
|
{ handle_idle_time, false, sizeof(struct hal_ev_hidhost_idle_time) },
|
|
|
|
/* HAL_EV_HIDHOST_GET_REPORT */
|
|
|
|
{ handle_get_report, true, sizeof(struct hal_ev_hidhost_get_report) },
|
|
|
|
/* HAL_EV_HIDHOST_VIRTUAL_UNPLUG */
|
|
|
|
{ handle_virtual_unplug, false,
|
|
|
|
sizeof(struct hal_ev_hidhost_virtual_unplug) },
|
2014-11-20 19:18:49 +08:00
|
|
|
{ handle_handshake, false, sizeof(struct hal_ev_hidhost_handshake) },
|
2013-11-19 22:02:39 +08:00
|
|
|
};
|
2013-10-31 20:19:47 +08:00
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t hidhost_connect(bt_bdaddr_t *bd_addr)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_cmd_hidhost_connect cmd;
|
2013-10-22 20:16:16 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-10-22 20:16:16 +08:00
|
|
|
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
|
|
|
|
|
2013-11-08 00:17:02 +08:00
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_CONNECT,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t disconnect(bt_bdaddr_t *bd_addr)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_cmd_hidhost_disconnect cmd;
|
2013-10-22 20:16:16 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-10-22 20:16:16 +08:00
|
|
|
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
|
|
|
|
|
2013-11-08 00:17:02 +08:00
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_DISCONNECT,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t virtual_unplug(bt_bdaddr_t *bd_addr)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-11-08 06:10:16 +08:00
|
|
|
struct hal_cmd_hidhost_virtual_unplug cmd;
|
2013-10-23 15:41:55 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-10-23 15:41:55 +08:00
|
|
|
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
|
|
|
|
|
2013-11-08 06:10:16 +08:00
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
|
|
|
|
HAL_OP_HIDHOST_VIRTUAL_UNPLUG,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t set_info(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_cmd_hidhost_set_info cmd;
|
2013-10-23 15:41:59 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-10-23 15:41:59 +08:00
|
|
|
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
|
|
|
|
cmd.attr = hid_info.attr_mask;
|
|
|
|
cmd.subclass = hid_info.sub_class;
|
|
|
|
cmd.app_id = hid_info.app_id;
|
|
|
|
cmd.vendor = hid_info.vendor_id;
|
|
|
|
cmd.product = hid_info.product_id;
|
|
|
|
cmd.country = hid_info.ctry_code;
|
|
|
|
cmd.descr_len = hid_info.dl_len;
|
|
|
|
memcpy(cmd.descr, hid_info.dsc_list, cmd.descr_len);
|
|
|
|
|
2013-11-08 00:17:02 +08:00
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_INFO,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t get_protocol(bt_bdaddr_t *bd_addr,
|
2013-11-06 16:29:25 +08:00
|
|
|
bthh_protocol_mode_t protocol_mode)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_cmd_hidhost_get_protocol cmd;
|
2013-10-23 15:41:56 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-10-23 15:41:56 +08:00
|
|
|
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
|
|
|
|
|
2013-12-31 06:56:17 +08:00
|
|
|
/* type match IPC type */
|
|
|
|
cmd.mode = protocol_mode;
|
2013-10-23 15:41:56 +08:00
|
|
|
|
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
|
2013-11-08 00:17:02 +08:00
|
|
|
HAL_OP_HIDHOST_GET_PROTOCOL,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t set_protocol(bt_bdaddr_t *bd_addr,
|
2013-11-06 16:29:25 +08:00
|
|
|
bthh_protocol_mode_t protocol_mode)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_cmd_hidhost_set_protocol cmd;
|
2013-10-23 15:41:56 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-10-23 15:41:56 +08:00
|
|
|
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
|
|
|
|
|
2013-12-31 06:56:18 +08:00
|
|
|
/* type match IPC type */
|
|
|
|
cmd.mode = protocol_mode;
|
2013-10-23 15:41:56 +08:00
|
|
|
|
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
|
2013-11-08 00:17:02 +08:00
|
|
|
HAL_OP_HIDHOST_SET_PROTOCOL,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t get_report(bt_bdaddr_t *bd_addr,
|
2013-11-06 16:29:25 +08:00
|
|
|
bthh_report_type_t report_type,
|
|
|
|
uint8_t report_id,
|
|
|
|
int buffer_size)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-11-08 00:17:02 +08:00
|
|
|
struct hal_cmd_hidhost_get_report cmd;
|
2013-10-23 15:41:57 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-10-23 15:41:57 +08:00
|
|
|
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
|
2013-11-06 16:29:25 +08:00
|
|
|
cmd.id = report_id;
|
2013-11-06 16:31:31 +08:00
|
|
|
cmd.buf_size = buffer_size;
|
2013-10-23 15:41:57 +08:00
|
|
|
|
2013-12-31 06:56:19 +08:00
|
|
|
/* type match IPC type */
|
|
|
|
cmd.type = report_type;
|
2013-10-23 15:41:57 +08:00
|
|
|
|
2013-11-08 00:17:02 +08:00
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_REPORT,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t set_report(bt_bdaddr_t *bd_addr,
|
2013-11-06 16:29:25 +08:00
|
|
|
bthh_report_type_t report_type,
|
2013-10-18 18:47:58 +08:00
|
|
|
char *report)
|
|
|
|
{
|
2014-02-25 00:05:03 +08:00
|
|
|
uint8_t buf[IPC_MTU];
|
2013-11-08 21:23:03 +08:00
|
|
|
struct hal_cmd_hidhost_set_report *cmd = (void *) buf;
|
2013-10-23 15:41:57 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr || !report)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-11-08 21:23:03 +08:00
|
|
|
memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
|
|
|
|
cmd->len = strlen(report);
|
|
|
|
memcpy(cmd->data, report, cmd->len);
|
2013-10-23 15:41:57 +08:00
|
|
|
|
2013-12-31 06:56:20 +08:00
|
|
|
/* type match IPC type */
|
|
|
|
cmd->type = report_type;
|
2013-10-23 15:41:57 +08:00
|
|
|
|
2013-11-08 00:17:02 +08:00
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(*cmd) + cmd->len, buf, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2014-02-25 00:05:03 +08:00
|
|
|
uint8_t buf[IPC_MTU];
|
2013-11-08 21:23:04 +08:00
|
|
|
struct hal_cmd_hidhost_send_data *cmd = (void *) buf;
|
2013-10-23 15:41:58 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return BT_STATUS_NOT_READY;
|
|
|
|
|
|
|
|
if (!bd_addr || !data)
|
|
|
|
return BT_STATUS_PARM_INVALID;
|
|
|
|
|
2013-11-08 21:23:04 +08:00
|
|
|
memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
|
|
|
|
cmd->len = strlen(data);
|
|
|
|
memcpy(cmd->data, data, cmd->len);
|
2013-10-23 15:41:58 +08:00
|
|
|
|
2013-11-08 00:17:02 +08:00
|
|
|
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(*cmd) + cmd->len, buf, NULL, NULL, NULL);
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bt_status_t init(bthh_callbacks_t *callbacks)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-10-23 19:14:09 +08:00
|
|
|
struct hal_cmd_register_module cmd;
|
2013-12-05 18:37:13 +08:00
|
|
|
int ret;
|
2013-10-23 18:16:17 +08:00
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
2013-12-05 18:37:13 +08:00
|
|
|
if (interface_ready())
|
|
|
|
return BT_STATUS_DONE;
|
|
|
|
|
2013-10-18 18:47:58 +08:00
|
|
|
/* store reference to user callbacks */
|
2013-11-08 00:17:04 +08:00
|
|
|
cbacks = callbacks;
|
2013-10-18 18:47:58 +08:00
|
|
|
|
2013-11-19 22:02:39 +08:00
|
|
|
hal_ipc_register(HAL_SERVICE_ID_HIDHOST, ev_handlers,
|
|
|
|
sizeof(ev_handlers)/sizeof(ev_handlers[0]));
|
|
|
|
|
2013-10-22 20:16:16 +08:00
|
|
|
cmd.service_id = HAL_SERVICE_ID_HIDHOST;
|
2014-03-03 07:50:43 +08:00
|
|
|
cmd.mode = HAL_MODE_DEFAULT;
|
2014-11-17 17:23:44 +08:00
|
|
|
cmd.max_clients = 1;
|
2013-10-18 18:47:58 +08:00
|
|
|
|
2013-12-05 18:37:13 +08:00
|
|
|
ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-12-05 18:37:13 +08:00
|
|
|
|
|
|
|
if (ret != BT_STATUS_SUCCESS) {
|
|
|
|
cbacks = NULL;
|
|
|
|
hal_ipc_unregister(HAL_SERVICE_ID_HIDHOST);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static void cleanup(void)
|
2013-10-18 18:47:58 +08:00
|
|
|
{
|
2013-10-31 22:45:04 +08:00
|
|
|
struct hal_cmd_unregister_module cmd;
|
|
|
|
|
2013-10-21 01:45:43 +08:00
|
|
|
DBG("");
|
2013-10-18 18:47:58 +08:00
|
|
|
|
|
|
|
if (!interface_ready())
|
|
|
|
return;
|
|
|
|
|
2013-10-31 22:45:04 +08:00
|
|
|
cmd.service_id = HAL_SERVICE_ID_HIDHOST;
|
|
|
|
|
|
|
|
hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE,
|
2014-07-01 19:06:36 +08:00
|
|
|
sizeof(cmd), &cmd, NULL, NULL, NULL);
|
2013-11-19 22:02:39 +08:00
|
|
|
|
|
|
|
hal_ipc_unregister(HAL_SERVICE_ID_HIDHOST);
|
2014-12-03 19:53:25 +08:00
|
|
|
|
|
|
|
cbacks = NULL;
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|
|
|
|
|
2013-11-08 00:17:04 +08:00
|
|
|
static bthh_interface_t hidhost_if = {
|
|
|
|
.size = sizeof(hidhost_if),
|
|
|
|
.init = init,
|
|
|
|
.connect = hidhost_connect,
|
|
|
|
.disconnect = disconnect,
|
|
|
|
.virtual_unplug = virtual_unplug,
|
|
|
|
.set_info = set_info,
|
|
|
|
.get_protocol = get_protocol,
|
|
|
|
.set_protocol = set_protocol,
|
|
|
|
.get_report = get_report,
|
|
|
|
.set_report = set_report,
|
|
|
|
.send_data = send_data,
|
|
|
|
.cleanup = cleanup
|
2013-10-18 18:47:58 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
bthh_interface_t *bt_get_hidhost_interface(void)
|
|
|
|
{
|
2013-11-08 00:17:04 +08:00
|
|
|
return &hidhost_if;
|
2013-10-18 18:47:58 +08:00
|
|
|
}
|