bluez/android/hal-hidhost.c
Tedd Ho-Jeong An 44b4662529 android: Add SPDX License Identifier
This patch adds SPDX License Identifier and removes the license text.

-------------------------------------
       License            COUNT
-------------------------------------
 Apache-2.0           :     80
 LGPL-2.1-or-later    :     42
 GPL-2.0-or-later     :      9

License: Apache-2.0
   android/bluetoothd-wrapper.c
   android/tester-hidhost.c
   android/tester-map-client.c
   android/hal-audio-aptx.c
   android/hal-audio.c
   android/hal-handsfree-client.c
   android/tester-gatt.c
   android/hal-pan.c
   android/hal-socket.c
   android/tester-hdp.c
   android/tester-pan.c
   android/tester-avrcp.c
   android/hal-a2dp-sink.c
   android/hal-gatt.c
   android/hal-avrcp.c
   android/tester-a2dp.c
   android/hal-audio.h
   android/hal-bluetooth.c
   android/tester-socket.c
   android/hal-health.c
   android/hal-a2dp.c
   android/hal-ipc.c
   android/hal-avrcp-ctrl.c
   android/hal-sco.c
   android/hal-ipc.h
   android/tester-main.c
   android/hal-audio-sbc.c
   android/hal-utils.c
   android/hal-map-client.c
   android/hal-handsfree.c
   android/hal-log.h
   android/hal.h
   android/hal-utils.h
   android/tester-bluetooth.c
   android/hal-hidhost.c
   android/audio_utils/resampler.h
   android/audio_utils/resampler.c
   android/system/audio.h
   android/hardware/bt_sock.h
   android/hardware/bt_gatt_client.h
   android/hardware/bt_hh.h
   android/hardware/bluetooth.h
   android/hardware/hardware.h
   android/hardware/bt_hf_client.h
   android/hardware/bt_rc.h
   android/hardware/bt_hf.h
   android/hardware/bt_pan.h
   android/hardware/bt_gatt_types.h
   android/hardware/hardware.c
   android/hardware/audio_effect.h
   android/hardware/audio.h
   android/hardware/bt_gatt_server.h
   android/hardware/bt_gatt.h
   android/hardware/bt_hl.h
   android/hardware/bt_mce.h
   android/hardware/bt_av.h
   android/client/if-hh.c
   android/client/if-sco.c
   android/client/pollhandler.h
   android/client/haltest.c
   android/client/tabcompletion.c
   android/client/if-hf-client.c
   android/client/history.h
   android/client/if-audio.c
   android/client/terminal.h
   android/client/if-av.c
   android/client/if-main.h
   android/client/if-av-sink.c
   android/client/terminal.c
   android/client/if-mce.c
   android/client/if-hf.c
   android/client/pollhandler.c
   android/client/if-sock.c
   android/client/if-rc-ctrl.c
   android/client/if-rc.c
   android/client/history.c
   android/client/if-pan.c
   android/client/if-gatt.c
   android/client/if-bt.c
   android/client/if-hl.c

License: LGPL-2.1-or-later
   android/sco.h
   android/socket.c
   android/tester-main.h
   android/hidhost.h
   android/map-client.h
   android/utils.h
   android/hal-msg.h
   android/health.h
   android/avrcp-lib.c
   android/bluetoothd-snoop.c
   android/a2dp.c
   android/bluetooth.h
   android/a2dp-sink.c
   android/handsfree-client.c
   android/audio-msg.h
   android/main.c
   android/pan.c
   android/ipc-tester.c
   android/health.c
   android/socket.h
   android/handsfree.h
   android/avrcp-lib.h
   android/a2dp-sink.h
   android/system-emulator.c
   android/gatt.c
   android/avrcp.h
   android/pan.h
   android/test-ipc.c
   android/hidhost.c
   android/a2dp.h
   android/avrcp.c
   android/sco-msg.h
   android/bluetooth.c
   android/map-client.c
   android/handsfree-client.h
   android/ipc.c
   android/handsfree.c
   android/gatt.h
   android/ipc.h
   android/ipc-common.h
   android/compat/wordexp.h
   android/cutils/properties.h

License: GPL-2.0-or-later
   android/avdtp.h
   android/avctp.c
   android/avdtptest.c
   android/sco.c
   android/log.c
   android/avdtp.c
   android/avctp.h
   android/compat/readline/history.h
   android/compat/readline/readline.h
2020-09-21 16:19:33 -07:00

394 lines
9.0 KiB
C

// SPDX-License-Identifier: Apache-2.0
/*
* Copyright (C) 2013 Intel Corporation
*
*/
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include "hal-log.h"
#include "hal.h"
#include "hal-msg.h"
#include "ipc-common.h"
#include "hal-ipc.h"
static const bthh_callbacks_t *cbacks;
static bool interface_ready(void)
{
return cbacks != NULL;
}
static void handle_conn_state(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_conn_state *ev = buf;
if (cbacks->connection_state_cb)
cbacks->connection_state_cb((bt_bdaddr_t *) ev->bdaddr,
ev->state);
}
static void handle_info(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_info *ev = buf;
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);
if (cbacks->hid_info_cb)
cbacks->hid_info_cb((bt_bdaddr_t *) ev->bdaddr, info);
}
static void handle_proto_mode(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_proto_mode *ev = buf;
if (cbacks->protocol_mode_cb)
cbacks->protocol_mode_cb((bt_bdaddr_t *) ev->bdaddr,
ev->status, ev->mode);
}
static void handle_idle_time(void *buf, uint16_t len, int fd)
{
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);
}
static void handle_get_report(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_get_report *ev = buf;
if (len != sizeof(*ev) + ev->len) {
error("invalid get report event, aborting");
exit(EXIT_FAILURE);
}
if (cbacks->get_report_cb)
cbacks->get_report_cb((bt_bdaddr_t *) ev->bdaddr, ev->status,
ev->data, ev->len);
}
static void handle_virtual_unplug(void *buf, uint16_t len, int fd)
{
struct hal_ev_hidhost_virtual_unplug *ev = buf;
if (cbacks->virtual_unplug_cb)
cbacks->virtual_unplug_cb((bt_bdaddr_t *) ev->bdaddr,
ev->status);
}
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
}
/*
* handlers will be called from notification thread context,
* index in table equals to 'opcode - HAL_MINIMUM_EVENT'
*/
static const struct hal_ipc_handler ev_handlers[] = {
/* 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) },
{ handle_handshake, false, sizeof(struct hal_ev_hidhost_handshake) },
};
static bt_status_t hidhost_connect(bt_bdaddr_t *bd_addr)
{
struct hal_cmd_hidhost_connect cmd;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr)
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_CONNECT,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
static bt_status_t disconnect(bt_bdaddr_t *bd_addr)
{
struct hal_cmd_hidhost_disconnect cmd;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr)
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_DISCONNECT,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
static bt_status_t virtual_unplug(bt_bdaddr_t *bd_addr)
{
struct hal_cmd_hidhost_virtual_unplug cmd;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr)
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
HAL_OP_HIDHOST_VIRTUAL_UNPLUG,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
static bt_status_t set_info(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info)
{
struct hal_cmd_hidhost_set_info cmd;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr)
return BT_STATUS_PARM_INVALID;
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);
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_INFO,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
static bt_status_t get_protocol(bt_bdaddr_t *bd_addr,
bthh_protocol_mode_t protocol_mode)
{
struct hal_cmd_hidhost_get_protocol cmd;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr)
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
/* type match IPC type */
cmd.mode = protocol_mode;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
HAL_OP_HIDHOST_GET_PROTOCOL,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
static bt_status_t set_protocol(bt_bdaddr_t *bd_addr,
bthh_protocol_mode_t protocol_mode)
{
struct hal_cmd_hidhost_set_protocol cmd;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr)
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
/* type match IPC type */
cmd.mode = protocol_mode;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST,
HAL_OP_HIDHOST_SET_PROTOCOL,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
static bt_status_t get_report(bt_bdaddr_t *bd_addr,
bthh_report_type_t report_type,
uint8_t report_id,
int buffer_size)
{
struct hal_cmd_hidhost_get_report cmd;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr)
return BT_STATUS_PARM_INVALID;
memcpy(cmd.bdaddr, bd_addr, sizeof(cmd.bdaddr));
cmd.id = report_id;
cmd.buf_size = buffer_size;
/* type match IPC type */
cmd.type = report_type;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_GET_REPORT,
sizeof(cmd), &cmd, NULL, NULL, NULL);
}
static bt_status_t set_report(bt_bdaddr_t *bd_addr,
bthh_report_type_t report_type,
char *report)
{
uint8_t buf[IPC_MTU];
struct hal_cmd_hidhost_set_report *cmd = (void *) buf;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr || !report)
return BT_STATUS_PARM_INVALID;
memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
cmd->len = strlen(report);
memcpy(cmd->data, report, cmd->len);
/* type match IPC type */
cmd->type = report_type;
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SET_REPORT,
sizeof(*cmd) + cmd->len, buf, NULL, NULL, NULL);
}
static bt_status_t send_data(bt_bdaddr_t *bd_addr, char *data)
{
uint8_t buf[IPC_MTU];
struct hal_cmd_hidhost_send_data *cmd = (void *) buf;
DBG("");
if (!interface_ready())
return BT_STATUS_NOT_READY;
if (!bd_addr || !data)
return BT_STATUS_PARM_INVALID;
memcpy(cmd->bdaddr, bd_addr, sizeof(cmd->bdaddr));
cmd->len = strlen(data);
memcpy(cmd->data, data, cmd->len);
return hal_ipc_cmd(HAL_SERVICE_ID_HIDHOST, HAL_OP_HIDHOST_SEND_DATA,
sizeof(*cmd) + cmd->len, buf, NULL, NULL, NULL);
}
static bt_status_t init(bthh_callbacks_t *callbacks)
{
struct hal_cmd_register_module cmd;
int ret;
DBG("");
if (interface_ready())
return BT_STATUS_DONE;
/* store reference to user callbacks */
cbacks = callbacks;
hal_ipc_register(HAL_SERVICE_ID_HIDHOST, ev_handlers,
sizeof(ev_handlers)/sizeof(ev_handlers[0]));
cmd.service_id = HAL_SERVICE_ID_HIDHOST;
cmd.mode = HAL_MODE_DEFAULT;
cmd.max_clients = 1;
ret = hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_REGISTER_MODULE,
sizeof(cmd), &cmd, NULL, NULL, NULL);
if (ret != BT_STATUS_SUCCESS) {
cbacks = NULL;
hal_ipc_unregister(HAL_SERVICE_ID_HIDHOST);
}
return ret;
}
static void cleanup(void)
{
struct hal_cmd_unregister_module cmd;
DBG("");
if (!interface_ready())
return;
cmd.service_id = HAL_SERVICE_ID_HIDHOST;
hal_ipc_cmd(HAL_SERVICE_ID_CORE, HAL_OP_UNREGISTER_MODULE,
sizeof(cmd), &cmd, NULL, NULL, NULL);
hal_ipc_unregister(HAL_SERVICE_ID_HIDHOST);
cbacks = NULL;
}
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
};
bthh_interface_t *bt_get_hidhost_interface(void)
{
return &hidhost_if;
}