Merge "Add the exception case for audio initialize" into tizen
authorPyun DoHyun <dh79.pyun@samsung.com>
Thu, 21 Nov 2019 08:27:22 +0000 (08:27 +0000)
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>
Thu, 21 Nov 2019 08:27:22 +0000 (08:27 +0000)
21 files changed:
bt-oal/CMakeLists.txt
bt-oal/bluez_hal/CMakeLists.txt
bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/inc/bt-hal.h
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.c
bt-oal/bluez_hal/src/bt-hal-event-receiver.h
bt-oal/bluez_hal/src/bt-hal-hiddevice.c [new file with mode: 0644]
bt-oal/bluez_hal/src/bt-hal-hiddevice.h [new file with mode: 0644]
bt-oal/bluez_hal/src/bt-hal-internal.h
bt-oal/hardware/bluetooth.h
bt-oal/hardware/bt_hd.h [new file with mode: 0644]
bt-oal/include/oal-event.h
bt-oal/include/oal-hid-device.h [new file with mode: 0644]
bt-oal/oal-hid-device.c [new file with mode: 0644]
bt-service-adaptation/CMakeLists.txt
bt-service-adaptation/services/adapter/bt-service-core-adapter.c
bt-service-adaptation/services/bt-service-event-receiver.c
bt-service-adaptation/services/hid/bt-service-hiddevice.c [new file with mode: 0644]
bt-service-adaptation/services/include/bt-service-event-receiver.h
bt-service-adaptation/services/include/bt-service-hiddevice.h [new file with mode: 0644]

index f8dbf7a..4d95d2c 100755 (executable)
@@ -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
index d0216c9..07cbebb 100644 (file)
@@ -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
index baa7977..19ea3b7 100644 (file)
@@ -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;
index 38c55f9..7f789ad 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <hardware/bluetooth.h>
 #include <hardware/bt_hh.h>
+#include <hardware/bt_hd.h>
 #include <hardware/bt_av.h>
 #include <hardware/bt_hf.h>
 #include <hardware/bt_sock.h>
index 3394a28..dedc067 100644 (file)
@@ -33,6 +33,7 @@
 #include <bt-hal-adapter-dbus-handler.h>
 #include <bt-hal-device-dbus-handler.h>
 #include <bt-hal-hidhost.h>
+#include <bt-hal-hiddevice.h>
 #include <bt-hal-socket.h>
 #include <bt-hal-av.h>
 #include <bt-hal-hf.h>
@@ -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();
 
index a8fe539..35627d7 100644 (file)
@@ -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;
@@ -870,7 +871,7 @@ static void __bt_hal_handle_device_event(GVariant *value, GVariant *parameters)
 }
 
 static void __bt_hal_send_hid_connection_state_event(
-               gboolean connected, char *address)
+               gboolean connected, const char *address)
 {
        struct hal_ev_hidhost_conn_state ev;
 
@@ -886,6 +887,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, const 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;
@@ -2016,15 +2034,23 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                DBG("Address: %s", address);
                DBG("Profile UUID: %s", profile_uuid);
                DBG("State: %d", state);
-               if (strncmp(profile_uuid, HID_UUID, strlen(HID_UUID)) == 0) {
+               if (strcmp(profile_uuid, 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);
-
-               } else if ((strncmp(profile_uuid, A2DP_SINK_UUID, strlen(A2DP_SINK_UUID)) == 0)) {
+                               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 ((strcmp(profile_uuid, A2DP_SINK_UUID) == 0)) {
                        if (state == BT_HAL_PROFILE_STATE_CONNECTED) {
                                DBG("A2DP Profile state changed: BT_PROFILE_STATE_CONNECTED");
                                __bt_hal_send_av_connection_state_event(TRUE, address);
@@ -2038,7 +2064,7 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                        } else {
                                ERR("A2DP Profile state: Invalid");
                        }
-               } else if ((strncmp(profile_uuid, A2DP_SOURCE_UUID, strlen(A2DP_SOURCE_UUID)) == 0)) {
+               } else if ((strcmp(profile_uuid, A2DP_SOURCE_UUID) == 0)) {
                        if (state == BT_HAL_PROFILE_STATE_CONNECTED) {
                                DBG("A2DP Sink Profile state changed: BT_HAL_PROFILE_STATE_CONNECTED");
                                __bt_hal_send_a2dp_sink_connection_state_event(TRUE, address);
@@ -2064,7 +2090,7 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                        } else {
                                ERR("HFP Profile state: Invalid");
                        }
-               } else if (strncmp(profile_uuid, HFP_AG_UUID, strlen(HFP_AG_UUID)) == 0) {
+               } else if (strcmp(profile_uuid, HFP_AG_UUID) == 0) {
                        if (state == BT_HAL_PROFILE_STATE_CONNECTING)
                                DBG("HFP Client Profile state changed: BT_PROFILE_STATE_CONNECTING");
                        else if (state == BT_HAL_PROFILE_STATE_CONNECTED) {
@@ -2078,7 +2104,7 @@ static void __bt_hal_handle_device_specific_events(GVariant *msg, const char *me
                        } else {
                                ERR("HFP Client Profile state: Invalid");
                        }
-               } else if ((strncmp(profile_uuid, AVRCP_TARGET_UUID, strlen(AVRCP_TARGET_UUID)) == 0)) {
+               } else if ((strcmp(profile_uuid, AVRCP_TARGET_UUID) == 0)) {
                        if (state == BT_HAL_PROFILE_STATE_CONNECTED) {
                                DBG("AVRCP Controller Profile state changed: BT_HAL_PROFILE_STATE_CONNECTED");
                                __bt_hal_send_avrcp_ctrl_connection_state_event(TRUE, address);
@@ -2621,6 +2647,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;
index 2996266..2998fad 100644 (file)
@@ -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 (file)
index 0000000..7a5739f
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * bluetooth-frwk
+ *
+ * Copyright (c) 2019 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 <stdbool.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlog.h>
+
+#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 (file)
index 0000000..57fad58
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * bluetooth-frwk
+ *
+ * Copyright (c) 2019 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__
+
+bthd_interface_t *bt_get_hiddevice_interface(void);
+
+#endif /* __BT_HAL_HIDDEVICE_H__ */
+
index 5746e60..55430c8 100644 (file)
@@ -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"
index d48dc47..a803394 100644 (file)
@@ -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 (file)
index 0000000..644c416
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ * Copyright (C) 2019 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 ANDROID_INCLUDE_BT_HD_H
+#define ANDROID_INCLUDE_BT_HD_H
+
+#include <stdint.h>
+
+__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 */
index 330d1e3..96e93e6 100644 (file)
@@ -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 (file)
index 0000000..5587813
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2019 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 <oal-manager.h>
+
+#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 (file)
index 0000000..62a93ef
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2019 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 <stdio.h>
+#include <dlog.h>
+#include <string.h>
+
+#include <bluetooth.h>
+#include <bt_hd.h>
+
+#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) {
+               BT_ERR("event is NULL");
+               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;
+}
+
index d8c3e44..699b7d8 100644 (file)
@@ -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
index 581c1b6..8698fcb 100644 (file)
@@ -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");
index d030450..c2eae2b 100644 (file)
@@ -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 (file)
index 0000000..213e52f
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * bluetooth-frwk
+ *
+ * Copyright (c) 2019 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 <stdio.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <dlog.h>
+#include <string.h>
+
+#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();
+}
+
index ffbdfe4..c4c48d5 100644 (file)
@@ -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 (file)
index 0000000..f1ce3e9
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * bluetooth-frwk
+ *
+ * Copyright (c) 2019 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 "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__ */