From 27dc87388a6b721e5b661b8a2df12ae1acd3d91f Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Wed, 20 Nov 2019 10:22:36 +0900 Subject: [PATCH] Implement HID Device role event handling logic Change-Id: Ic95a8655b86db1f82e4495a5f6aea9963e614865 --- bt-oal/CMakeLists.txt | 1 + bt-oal/bluez_hal/CMakeLists.txt | 1 + bt-oal/bluez_hal/inc/bt-hal-msg.h | 10 ++ bt-oal/bluez_hal/inc/bt-hal.h | 1 + bt-oal/bluez_hal/src/bt-hal-bluetooth.c | 4 + bt-oal/bluez_hal/src/bt-hal-event-receiver.c | 33 +++++- bt-oal/bluez_hal/src/bt-hal-event-receiver.h | 1 + bt-oal/bluez_hal/src/bt-hal-hiddevice.c | 107 ++++++++++++++++++ bt-oal/bluez_hal/src/bt-hal-hiddevice.h | 31 ++++++ bt-oal/bluez_hal/src/bt-hal-internal.h | 1 + bt-oal/hardware/bluetooth.h | 1 + bt-oal/hardware/bt_hd.h | 62 +++++++++++ bt-oal/include/oal-event.h | 2 + bt-oal/include/oal-hid-device.h | 64 +++++++++++ bt-oal/oal-hid-device.c | 121 +++++++++++++++++++++ bt-service-adaptation/CMakeLists.txt | 1 + .../services/adapter/bt-service-core-adapter.c | 5 + .../services/bt-service-event-receiver.c | 14 +++ .../services/hid/bt-service-hiddevice.c | 95 ++++++++++++++++ .../services/include/bt-service-event-receiver.h | 1 + .../services/include/bt-service-hiddevice.h | 37 +++++++ 21 files changed, 591 insertions(+), 2 deletions(-) create mode 100644 bt-oal/bluez_hal/src/bt-hal-hiddevice.c create mode 100644 bt-oal/bluez_hal/src/bt-hal-hiddevice.h create mode 100644 bt-oal/hardware/bt_hd.h create mode 100644 bt-oal/include/oal-hid-device.h create mode 100644 bt-oal/oal-hid-device.c create mode 100644 bt-service-adaptation/services/hid/bt-service-hiddevice.c create mode 100644 bt-service-adaptation/services/include/bt-service-hiddevice.h diff --git a/bt-oal/CMakeLists.txt b/bt-oal/CMakeLists.txt index f8dbf7a..4d95d2c 100755 --- a/bt-oal/CMakeLists.txt +++ b/bt-oal/CMakeLists.txt @@ -17,6 +17,7 @@ oal-manager.c oal-adapter-mgr.c oal-device-mgr.c oal-hid-host.c +oal-hid-device.c oal-socket.c oal-audio-src.c oal-a2dp-sink.c diff --git a/bt-oal/bluez_hal/CMakeLists.txt b/bt-oal/bluez_hal/CMakeLists.txt index d0216c9..07cbebb 100644 --- a/bt-oal/bluez_hal/CMakeLists.txt +++ b/bt-oal/bluez_hal/CMakeLists.txt @@ -13,6 +13,7 @@ SET(SRCS ./src/bt-hal-gap-agent.c ./src/bt-hal-agent.c ./src/bt-hal-hidhost.c +./src/bt-hal-hiddevice.c ./src/bt-hal-av.c ./src/bt-hal-av-dbus-handler.c ./src/bt-hal-a2dp-sink.c diff --git a/bt-oal/bluez_hal/inc/bt-hal-msg.h b/bt-oal/bluez_hal/inc/bt-hal-msg.h index baa7977..19ea3b7 100644 --- a/bt-oal/bluez_hal/inc/bt-hal-msg.h +++ b/bt-oal/bluez_hal/inc/bt-hal-msg.h @@ -208,6 +208,10 @@ struct hal_ev_device_trust_state_changed { #define HAL_HIDHOST_STATE_FAILED 0x08 #define HAL_HIDHOST_STATE_UNKNOWN 0x09 +/* HID device events */ +#define HAL_HIDDEVICE_STATE_CONNECTED 0x00 +#define HAL_HIDDEVICE_STATE_DISCONNECTED 0x01 + #define HAL_EV_HIDHOST_CONN_STATE 0x81 struct hal_ev_hidhost_conn_state { uint8_t bdaddr[6]; @@ -262,6 +266,12 @@ struct hal_ev_hidhost_handshake { uint8_t status; } __attribute__((packed)); +#define HAL_EV_HIDDEVICE_CONN_STATE 0x88 +struct hal_ev_hiddevice_conn_state { + uint8_t bdaddr[6]; + uint8_t state; +} __attribute__((packed)); + /* Bluetooth Socket HAL events */ struct hal_ev_sock_connect { short size; diff --git a/bt-oal/bluez_hal/inc/bt-hal.h b/bt-oal/bluez_hal/inc/bt-hal.h index 38c55f9..7f789ad 100644 --- a/bt-oal/bluez_hal/inc/bt-hal.h +++ b/bt-oal/bluez_hal/inc/bt-hal.h @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index 3394a28..dedc067 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -252,6 +253,9 @@ static const void *get_profile_interface(const char *profile_id) if (!strncmp(profile_id, BT_PROFILE_HIDHOST_ID, strlen(profile_id))) return bt_get_hidhost_interface(); + if (!strcmp(profile_id, BT_PROFILE_HIDDEVICE_ID)) + return bt_get_hiddevice_interface(); + if (!strcmp(profile_id, BT_PROFILE_SOCKETS_ID)) return bt_get_socket_interface(); diff --git a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c index 2dbfd63..bf8df57 100644 --- a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c +++ b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c @@ -52,6 +52,7 @@ static GDBusConnection *manager_conn; static handle_stack_msg event_cb = NULL; static handle_stack_msg hid_event_cb = NULL; +static handle_stack_msg hid_device_event_cb = NULL; static handle_stack_msg av_event_cb = NULL; static handle_stack_msg a2dp_sink_event_cb = NULL; static handle_stack_msg hf_event_cb = NULL; @@ -887,6 +888,23 @@ static void __bt_hal_send_hid_connection_state_event( hid_event_cb(HAL_EV_HIDHOST_CONN_STATE, &ev, sizeof(ev)); } +static void __bt_hal_send_hid_device_connection_state_event( + gboolean connected, char *address) +{ + struct hal_ev_hiddevice_conn_state ev; + + ev.state = (connected == TRUE) ? + HAL_HIDDEVICE_STATE_CONNECTED : + HAL_HIDDEVICE_STATE_DISCONNECTED; + + _bt_hal_convert_addr_string_to_type(ev.bdaddr, address); + + if (!hid_device_event_cb) + ERR("HID device event handler not registered"); + else + hid_device_event_cb(HAL_EV_HIDDEVICE_CONN_STATE, &ev, sizeof(ev)); +} + static void __bt_hal_handle_input_event(GVariant *msg, const char *path) { gboolean property_flag = FALSE; @@ -2031,13 +2049,21 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me DBG("Profile UUID: %s", profile_uuid); DBG("State: %d", state); if (strncmp(profile_uuid, HID_UUID, strlen(HID_UUID)) == 0) { + DBG("HID Host Profile state: %d", state); if (state == BT_HAL_PROFILE_STATE_CONNECTED) __bt_hal_send_hid_connection_state_event(TRUE, address); else if (state == BT_HAL_PROFILE_STATE_DISCONNECTED) __bt_hal_send_hid_connection_state_event(FALSE, address); else - DBG("Profile state: %d", state); - + DBG("HID Host Profile state: Invalid"); + } else if (strcmp(profile_uuid, HID_DEVICE_UUID) == 0) { + DBG("HID Device Profile state: %d", state); + if (state == BT_HAL_PROFILE_STATE_CONNECTED) + __bt_hal_send_hid_device_connection_state_event(TRUE, address); + else if (state == BT_HAL_PROFILE_STATE_DISCONNECTED) + __bt_hal_send_hid_device_connection_state_event(FALSE, address); + else + DBG("HID Device Profile state: Invalid"); } else if ((strncmp(profile_uuid, A2DP_SINK_UUID, strlen(A2DP_SINK_UUID)) == 0)) { if (state == BT_HAL_PROFILE_STATE_CONNECTED) { DBG("A2DP Profile state changed: BT_PROFILE_STATE_CONNECTED"); @@ -2635,6 +2661,9 @@ void _bt_hal_register_event_handler_cb(bt_hal_module_e module, handle_stack_msg case HAL_HIDHOST: hid_event_cb = cb; break; + case HAL_HIDDEVICE: + hid_device_event_cb = cb; + break; case HAL_A2DP_SRC: av_event_cb = cb; break; diff --git a/bt-oal/bluez_hal/src/bt-hal-event-receiver.h b/bt-oal/bluez_hal/src/bt-hal-event-receiver.h index 2996266..2998fad 100644 --- a/bt-oal/bluez_hal/src/bt-hal-event-receiver.h +++ b/bt-oal/bluez_hal/src/bt-hal-event-receiver.h @@ -42,6 +42,7 @@ int _bt_hal_initialize_event_receiver(handle_stack_msg cb); typedef enum { HAL_HIDHOST, + HAL_HIDDEVICE, HAL_A2DP_SRC, HAL_A2DP_SNK, HAL_HF_AG, diff --git a/bt-oal/bluez_hal/src/bt-hal-hiddevice.c b/bt-oal/bluez_hal/src/bt-hal-hiddevice.c new file mode 100644 index 0000000..f65f2da --- /dev/null +++ b/bt-oal/bluez_hal/src/bt-hal-hiddevice.c @@ -0,0 +1,107 @@ +/* + * bluetooth-frwk + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include +#include +#include +#include + +#include "bt-hal.h" +#include "bt-hal-log.h" +#include "bt-hal-msg.h" +#include "bt-hal-utils.h" + +#include "bt-hal-hid-dbus-handler.h" +#include "bt-hal-event-receiver.h" + +static const bthd_callbacks_t *bt_hal_hid_device_cbacks; + +static bool interface_ready(void) +{ + return bt_hal_hid_device_cbacks != NULL; +} + +static void __bt_hal_handle_conn_state(void *buf, uint16_t len) +{ + struct hal_ev_hiddevice_conn_state *ev = buf; + + if (bt_hal_hid_device_cbacks->connection_state_cb) + bt_hal_hid_device_cbacks->connection_state_cb((bt_bdaddr_t *) ev->bdaddr, + ev->state); +} + +static void __bt_hal_handle_hid_device_events(int message, void *buf, uint16_t len) +{ + DBG("+"); + + if (!interface_ready()) + return; + + switch (message) { + case HAL_EV_HIDDEVICE_CONN_STATE: + DBG("Event: HAL_EV_HIDDEVICE_CONN_STATE"); + __bt_hal_handle_conn_state(buf, len); + break; + default: + DBG("Event Currently not handled!!"); + break; + } + + DBG("-"); +} + +static bt_status_t init(bthd_callbacks_t *callbacks) +{ + DBG(""); + + if (interface_ready()) + return BT_STATUS_DONE; + + bt_hal_hid_device_cbacks = callbacks; + DBG("Register HID events callback function"); + _bt_hal_register_event_handler_cb(HAL_HIDDEVICE, __bt_hal_handle_hid_device_events); + + return BT_STATUS_SUCCESS; +} + +static void cleanup(void) +{ + DBG(""); + + if (!interface_ready()) + return; + + _bt_hal_unregister_hid_dbus_handler_cb(); + _bt_hal_unregister_event_handler_cb(HAL_HIDDEVICE); + + bt_hal_hid_device_cbacks = NULL; +} + +static bthd_interface_t hiddevice_if = { + .size = sizeof(hiddevice_if), + .init = init, + .cleanup = cleanup +}; + +bthd_interface_t *bt_get_hiddevice_interface(void) +{ + return &hiddevice_if; +} + diff --git a/bt-oal/bluez_hal/src/bt-hal-hiddevice.h b/bt-oal/bluez_hal/src/bt-hal-hiddevice.h new file mode 100644 index 0000000..0bae078 --- /dev/null +++ b/bt-oal/bluez_hal/src/bt-hal-hiddevice.h @@ -0,0 +1,31 @@ +/* + * bluetooth-frwk + * + * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + * + */ + +#ifndef __BT_HAL_HIDDEVICE_H__ +#define __BT_HAL_HIDDEVICE_H__ + +#include +#include +#include +#include +#include + +bthd_interface_t *bt_get_hiddevice_interface(void); + +#endif /* __BT_HAL_HIDDEVICE_H__ */ diff --git a/bt-oal/bluez_hal/src/bt-hal-internal.h b/bt-oal/bluez_hal/src/bt-hal-internal.h index 5746e60..55430c8 100644 --- a/bt-oal/bluez_hal/src/bt-hal-internal.h +++ b/bt-oal/bluez_hal/src/bt-hal-internal.h @@ -65,6 +65,7 @@ typedef enum { /* UUIDs */ #define HID_UUID "00001124-0000-1000-8000-00805f9b34fb" +#define HID_DEVICE_UUID "00001124-0000-1000-8000-00805f9b43bf" #define A2DP_SINK_UUID "0000110b-0000-1000-8000-00805f9b34fb" #define A2DP_SOURCE_UUID "0000110a-0000-1000-8000-00805f9b34fb" #define AVRCP_CTRL_UUID "0000110e-0000-1000-8000-00805f9b34fb" diff --git a/bt-oal/hardware/bluetooth.h b/bt-oal/hardware/bluetooth.h index d48dc47..a803394 100644 --- a/bt-oal/hardware/bluetooth.h +++ b/bt-oal/hardware/bluetooth.h @@ -44,6 +44,7 @@ __BEGIN_DECLS #define BT_PROFILE_HEALTH_ID "health" #define BT_PROFILE_SOCKETS_ID "socket" #define BT_PROFILE_HIDHOST_ID "hidhost" +#define BT_PROFILE_HIDDEVICE_ID "hiddevice" #define BT_PROFILE_PAN_ID "pan" #define BT_PROFILE_MAP_CLIENT_ID "map_client" diff --git a/bt-oal/hardware/bt_hd.h b/bt-oal/hardware/bt_hd.h new file mode 100644 index 0000000..94e00c7 --- /dev/null +++ b/bt-oal/hardware/bt_hd.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * 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. + */ + +#ifndef ANDROID_INCLUDE_BT_HD_H +#define ANDROID_INCLUDE_BT_HD_H + +#include + +__BEGIN_DECLS + +/* HID Device connection states */ +typedef enum { + BTHD_CONN_STATE_CONNECTED = 0, + BTHD_CONN_STATE_CONNECTING, + BTHD_CONN_STATE_DISCONNECTED, + BTHD_CONN_STATE_DISCONNECTING, + BTHD_CONN_STATE_UNKNOWN +} bthd_connection_state_t; + +/** Callback for connection state change. + * state will have one of the values from bthd_connection_state_t + */ +typedef void (*bthd_connection_state_callback)(bt_bdaddr_t *bd_addr, bthd_connection_state_t state); + +/** BT-HD callback structure. */ +typedef struct { + /** set to sizeof(BtHdCallbacks) */ + size_t size; + bthd_connection_state_callback connection_state_cb; +} bthd_callbacks_t; + +/** Represents the standard BT-HD interface. */ +typedef struct { + + /** set to sizeof(BtHdInterface) */ + size_t size; + + /** + * Register the BtHd callbacks + */ + bt_status_t (*init)(bthd_callbacks_t* callbacks); + + /** Closes the interface. */ + void (*cleanup)(void); + +} bthd_interface_t; +__END_DECLS + +#endif /* ANDROID_INCLUDE_BT_HD_H */ diff --git a/bt-oal/include/oal-event.h b/bt-oal/include/oal-event.h index 330d1e3..96e93e6 100644 --- a/bt-oal/include/oal-event.h +++ b/bt-oal/include/oal-event.h @@ -78,6 +78,8 @@ extern "C" { EVENT(OAL_EVENT_OAL_INITIALISED_FAILED) /* OAL Initialisation event */ \ EVENT(OAL_EVENT_HID_CONNECTED) /* event_hid_conn_t */\ EVENT(OAL_EVENT_HID_DISCONNECTED) /* event_hid_conn_t */\ + EVENT(OAL_EVENT_HID_DEVICE_CONNECTED) /* event_hid_conn_t */\ + EVENT(OAL_EVENT_HID_DEVICE_DISCONNECTED) /* event_hid_conn_t */\ EVENT(OAL_EVENT_SOCKET_OUTGOING_CONNECTED) /* RFCOMM */ \ EVENT(OAL_EVENT_SOCKET_DISCONNECTED) /* RFCOMM */ \ EVENT(OAL_EVENT_AUDIO_CONNECTING) /* bt_address_t */ \ diff --git a/bt-oal/include/oal-hid-device.h b/bt-oal/include/oal-hid-device.h new file mode 100644 index 0000000..7d3d929 --- /dev/null +++ b/bt-oal/include/oal-hid-device.h @@ -0,0 +1,64 @@ +/* + * Open Adaptation Layer (OAL) + * + * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd. + * + * 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. + * + */ + +#ifndef _OAL_HID_DEVICE_H_ +#define _OAL_HID_DEVICE_H_ + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enable HID Device Feature + * + * @remarks HID Device role will be enabled. + * + * @return OAL_STATUS_SUCCESS on success, otherwise non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre OAL API must be initialized with oal_bt_init(). + * + * @see hid_device_disable() + */ +oal_status_t hid_device_enable(void); + + +/** + * @brief Disable HID Device Feature + * + * @remarks HID Device role will be disabled. + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre HID Device should be enabled with hid_device_enable(). + * + * @see hid_device_enable() + */ +oal_status_t hid_device_disable(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* _OAL_HID_DEVICE_H_ */ diff --git a/bt-oal/oal-hid-device.c b/bt-oal/oal-hid-device.c new file mode 100644 index 0000000..34e4863 --- /dev/null +++ b/bt-oal/oal-hid-device.c @@ -0,0 +1,121 @@ +/* + * Open Adaptation Layer (OAL) + * + * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd. + * + * 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 +#include +#include + +#include +#include + +#include "oal-event.h" +#include "oal-internal.h" +#include "oal-common.h" +#include "oal-manager.h" +#include "oal-hid-device.h" +#include "oal-utils.h" + +#define CHECK_OAL_HID_DEVICE_ENABLED() \ + do { \ + if (hid_device_api == NULL) { \ + BT_ERR("HID Device Not Enabled"); \ + return OAL_STATUS_NOT_READY; \ + } \ + } while (0) + +static const bthd_interface_t *hid_device_api; + +static void connection_state_callback(bt_bdaddr_t *bd_addr, bthd_connection_state_t state) +{ + event_hid_conn_t *event = g_new0(event_hid_conn_t, 1); + int event_type; + + BT_DBG("%d", state); + + if (!event) + return; + memcpy(event->address.addr, bd_addr->address, BT_ADDRESS_BYTES_NUM); + + event->status = OAL_STATUS_SUCCESS; + + switch (state) { + case BTHD_CONN_STATE_CONNECTED: + event_type = OAL_EVENT_HID_DEVICE_CONNECTED; + break; + case BTHD_CONN_STATE_DISCONNECTED: + event_type = OAL_EVENT_HID_DEVICE_DISCONNECTED; + break; + default: + BT_ERR("Unhandled Connection state %d", state); + g_free(event); + return; + } + + send_event_bda_trace(event_type, event, sizeof(event_hid_conn_t), (bt_address_t*)bd_addr); +} + +static bthd_callbacks_t sBluetoothHidDeviceCallbacks = { + .size = sizeof(sBluetoothHidDeviceCallbacks), + .connection_state_cb = connection_state_callback, +}; + +oal_status_t hid_device_enable(void) +{ + const bt_interface_t *blued_api; + int ret; + + API_TRACE(); + blued_api = adapter_get_stack_interface(); + + if (blued_api == NULL) { + BT_ERR("Stack is not initialized"); + return OAL_STATUS_NOT_READY; + } + if (hid_device_api != NULL) { + BT_WARN("HID Device Interface is already initialized..."); + return OAL_STATUS_ALREADY_DONE; + } + + hid_device_api = (const bthd_interface_t *)blued_api->get_profile_interface(BT_PROFILE_HIDDEVICE_ID); + if (hid_device_api == NULL) { + BT_ERR("HID Device interface failed"); + return OAL_STATUS_INTERNAL_ERROR; + } + + if ((ret = hid_device_api->init(&sBluetoothHidDeviceCallbacks)) != BT_STATUS_SUCCESS) { + BT_ERR("HID Device Init failed: %s", status2string(ret)); + hid_device_api->cleanup(); + hid_device_api = NULL; + return convert_to_oal_status(ret); + } + return OAL_STATUS_SUCCESS; +} + +oal_status_t hid_device_disable(void) +{ + API_TRACE(); + + CHECK_OAL_HID_DEVICE_ENABLED(); + + hid_device_api->cleanup(); + + hid_device_api = NULL; + return OAL_STATUS_SUCCESS; +} + diff --git a/bt-service-adaptation/CMakeLists.txt b/bt-service-adaptation/CMakeLists.txt index d8c3e44..699b7d8 100644 --- a/bt-service-adaptation/CMakeLists.txt +++ b/bt-service-adaptation/CMakeLists.txt @@ -18,6 +18,7 @@ SET(SRCS ./services/bt-service-dpm.c ./services/bt-service-agent-util.c ./services/hid/bt-service-hidhost.c +./services/hid/bt-service-hiddevice.c ./services/socket/bt-service-socket.c ./services/rfcomm/bt-service-rfcomm.c ./services/audio/bt-service-audio.c diff --git a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c index 581c1b6..8698fcb 100644 --- a/bt-service-adaptation/services/adapter/bt-service-core-adapter.c +++ b/bt-service-adaptation/services/adapter/bt-service-core-adapter.c @@ -48,6 +48,7 @@ #include "bt-service-dpm.h" #endif #include "bt-service-hidhost.h" +#include "bt-service-hiddevice.h" #include "bt-service-socket.h" #include "bt-service-hdp.h" @@ -969,6 +970,10 @@ int _bt_init_profiles() if (ret != BLUETOOTH_ERROR_NONE) BT_ERR("_bt_hidhost_initialize Failed"); + ret = _bt_hiddevice_initialize(); + if (ret != BLUETOOTH_ERROR_NONE) + BT_ERR("_bt_hiddevice_initialize Failed"); + ret = _bt_socket_init(); if (ret != BLUETOOTH_ERROR_NONE) BT_ERR("_bt_socket_init Failed"); diff --git a/bt-service-adaptation/services/bt-service-event-receiver.c b/bt-service-adaptation/services/bt-service-event-receiver.c index d030450..c2eae2b 100644 --- a/bt-service-adaptation/services/bt-service-event-receiver.c +++ b/bt-service-adaptation/services/bt-service-event-receiver.c @@ -39,6 +39,7 @@ typedef struct { _bt_service_event_handler_callback adapter_cb; _bt_service_event_handler_callback device_cb; _bt_service_event_handler_callback hid_cb; +_bt_service_event_handler_callback hid_device_cb; _bt_service_event_handler_callback socket_cb; _bt_service_event_handler_callback audio_event_cb; _bt_service_event_handler_callback a2dp_source_cb; @@ -67,6 +68,10 @@ void _bt_service_register_event_handler_callback( BT_INFO("Register BT_HID_MODULE Callback"); hid_cb = cb; break; + case BT_HID_DEVICE_MODULE: + BT_INFO("Register BT_HID_DEVICE_MODULE Callback"); + hid_device_cb = cb; + break; case BT_SOCKET_MODULE: BT_INFO("Register BT_SOCKET_MODULE Callback"); socket_cb = cb; @@ -131,6 +136,10 @@ void _bt_service_unregister_event_handler_callback(bt_service_module_t module) BT_INFO("Un-Register BT_HID_MODULE Callback"); hid_cb = NULL; break; + case BT_HID_DEVICE_MODULE: + BT_INFO("Un-Register BT_HID_DEVICE_MODULE Callback"); + hid_device_cb = NULL; + break; case BT_SOCKET_MODULE: BT_INFO("Un-Register BT_SOCKET_MODULE Callback"); socket_cb = NULL; @@ -241,6 +250,11 @@ static gboolean __bt_handle_oal_events(gpointer data) if (hid_cb) hid_cb(event_type, event_data); break; + case OAL_EVENT_HID_DEVICE_CONNECTED: + case OAL_EVENT_HID_DEVICE_DISCONNECTED: + if (hid_device_cb) + hid_device_cb(event_type, event_data); + break; case OAL_EVENT_SOCKET_OUTGOING_CONNECTED: case OAL_EVENT_SOCKET_DISCONNECTED: case OAL_EVENT_SOCKET_AUTHORIZE_REQUEST: diff --git a/bt-service-adaptation/services/hid/bt-service-hiddevice.c b/bt-service-adaptation/services/hid/bt-service-hiddevice.c new file mode 100644 index 0000000..517a874 --- /dev/null +++ b/bt-service-adaptation/services/hid/bt-service-hiddevice.c @@ -0,0 +1,95 @@ +/* + * bluetooth-frwk + * + * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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 +#include +#include +#include +#include + +#include "bt-internal-types.h" +#include "bt-request-handler.h" +#include "bt-service-util.h" +#include "bt-service-event.h" +#include "bt-service-event-receiver.h" +#include "bt-service-common.h" +#include "bt-service-hiddevice.h" +#include "oal-event.h" +#include "oal-hid-device.h" + +static void __bt_hid_device_event_handler(int event_type, gpointer event_data) +{ + char address[BT_ADDRESS_STRING_SIZE]; + int result = BLUETOOTH_ERROR_NONE; + event_hid_conn_t *event = event_data; + + BT_DBG("+"); + + if (event == NULL) + return; + + memset(address, 0x00, BT_ADDRESS_STRING_SIZE); + _bt_convert_addr_type_to_string(address, event->address.addr); + + switch (event_type) { + case OAL_EVENT_HID_DEVICE_CONNECTED: + _bt_send_event(BT_HID_DEVICE_EVENT, + BLUETOOTH_HID_DEVICE_CONNECTED, + g_variant_new("(is)", result, address)); + break; + case OAL_EVENT_HID_DEVICE_DISCONNECTED: + _bt_send_event(BT_HID_DEVICE_EVENT, + BLUETOOTH_HID_DEVICE_DISCONNECTED, + g_variant_new("(is)", result, address)); + break; + default: + BT_ERR("Unhandled event: %d", event_type); + } + + BT_DBG("-"); +} + +int _bt_hiddevice_initialize() +{ + BT_DBG("+"); + + /* Enable HID Device Profile */ + if (OAL_STATUS_SUCCESS != hid_device_enable()) { + BT_ERR("HID Device Enable failed"); + return BLUETOOTH_ERROR_INTERNAL; + } + + /* Register HID Device event handler */ + _bt_service_register_event_handler_callback( + BT_HID_DEVICE_MODULE, __bt_hid_device_event_handler); + + return BLUETOOTH_ERROR_NONE; +} + +void _bt_hiddevice_deinitialize() +{ + BT_DBG("+"); + + /* Unregister HID Device event handler */ + _bt_service_unregister_event_handler_callback(BT_HID_DEVICE_MODULE); + + /* Disable HID Device Profile */ + hid_device_disable(); +} + diff --git a/bt-service-adaptation/services/include/bt-service-event-receiver.h b/bt-service-adaptation/services/include/bt-service-event-receiver.h index ffbdfe4..c4c48d5 100644 --- a/bt-service-adaptation/services/include/bt-service-event-receiver.h +++ b/bt-service-adaptation/services/include/bt-service-event-receiver.h @@ -34,6 +34,7 @@ typedef enum { BT_ADAPTER_MODULE, BT_DEVICE_MODULE, BT_HID_MODULE, + BT_HID_DEVICE_MODULE, BT_SOCKET_MODULE, BT_A2DP_SOURCE_MODULE, BT_A2DP_SINK_MODULE, diff --git a/bt-service-adaptation/services/include/bt-service-hiddevice.h b/bt-service-adaptation/services/include/bt-service-hiddevice.h new file mode 100644 index 0000000..926d164 --- /dev/null +++ b/bt-service-adaptation/services/include/bt-service-hiddevice.h @@ -0,0 +1,37 @@ +/* + * bluetooth-frwk + * + * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved. + * + * 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. + * + */ + +#ifndef __BT_SERVICE_HIDDEVICE_H__ +#define __BT_SERVICE_HIDDEVICE_H__ + +#include +#include +#include "bluetooth-api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +int _bt_hiddevice_initialize(void); +void _bt_hiddevice_deinitialize(void); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ +#endif /* __BT_SERVICE_HIDDEVICE_H__ */ -- 2.7.4