[Adapt: HAL] Added bluetooth socket interface 09/79809/1
authorAtul Rai <a.rai@samsung.com>
Wed, 13 Jul 2016 05:31:30 +0000 (14:31 +0900)
committerAtul Rai <a.rai@samsung.com>
Wed, 13 Jul 2016 05:31:30 +0000 (14:31 +0900)
This patch adds implementation of HAL bluetooth socket
interface for BlueZ stack.

Change-Id: I49b31f18e87960aea090e0b8f653cb25c920c50c
Signed-off-by: Atul Rai <a.rai@samsung.com>
bt-oal/bluez_hal/CMakeLists.txt
bt-oal/bluez_hal/inc/bt-hal.h
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/bluez_hal/src/bt-hal-socket.c [new file with mode: 0644]
bt-oal/bluez_hal/src/bt-hal-socket.h [new file with mode: 0644]

index 32c8502..d37b579 100644 (file)
@@ -12,6 +12,7 @@ SET(SRCS
 ./src/bt-hal-agent.c
 ./src/bt-hal-hidhost.c
 ./src/bt-hal-hid-dbus-handler.c
+./src/bt-hal-socket.c
 )
 
 SET(PREFIX ${CMAKE_INSTALL_PREFIX})
index ae7d99e..8a148ca 100644 (file)
@@ -24,6 +24,7 @@
 
 #include <hardware/bluetooth.h>
 #include <hardware/bt_hh.h>
+#include <hardware/bt_sock.h>
 
 /*TODO: Profile interfaces headers and exposed methods of Android HAL framework to be included in next patches */
 #endif //_BT_HAL_H
index 875c0bf..9334c0c 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-socket.h>
 
 #define enum_prop_to_hal(prop, hal_prop, type) do { \
        static type e; \
@@ -209,6 +210,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_SOCKETS_ID))
+               return bt_get_socket_interface();
+
        if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
                return NULL;
 
diff --git a/bt-oal/bluez_hal/src/bt-hal-socket.c b/bt-oal/bluez_hal/src/bt-hal-socket.c
new file mode 100644 (file)
index 0000000..21f5586
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Atul Rai <a.rai@samsung.com>
+ *
+ * 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"
+
+static bt_status_t listen(btsock_type_t type, const char *service_name,
+               const uint8_t *uuid, int channel, int *sock_fd, int flags)
+{
+       DBG("");
+       return BT_STATUS_UNSUPPORTED;
+}
+
+static bt_status_t connect(const bt_bdaddr_t *bd_addr, btsock_type_t type,
+               const uint8_t *uuid, int channel, int *sock_fd, int flags)
+{
+       bt_status_t status;
+
+       DBG("+");
+
+       if (bd_addr == NULL || sock_fd == NULL) {
+               ERR("invalid parameters, bd_addr:%p, uuid:%p, channel:%d, sock_fd:%p",
+                               bd_addr, uuid, channel, sock_fd);
+               return BT_STATUS_PARM_INVALID;
+       }
+
+       if (!uuid) {
+               ERR("Currently we only support to connect using UUID");
+               return BT_STATUS_UNSUPPORTED;
+       }
+
+       INFO("channel: %d, sock_fd: %d, type: %d", channel, sock_fd, type);
+
+       switch (type) {
+       case BTSOCK_RFCOMM:
+               ERR("bt rfcomm socket type not supported");
+               status = BT_STATUS_UNSUPPORTED;
+               goto failed;
+       case BTSOCK_L2CAP:
+               ERR("bt l2cap socket type not supported");
+               status = BT_STATUS_UNSUPPORTED;
+               goto failed;
+       case BTSOCK_SCO:
+               ERR("bt sco socket not supported");
+               status = BT_STATUS_UNSUPPORTED;
+               goto failed;
+       default:
+               ERR("unknown bt socket type:%d", type);
+               status = BT_STATUS_UNSUPPORTED;
+               goto failed;
+       }
+
+       DBG("-");
+       return status;
+
+failed:
+       *sock_fd = -1;
+       return status;
+}
+
+static btsock_interface_t socket_if = {
+       .size = sizeof(socket_if),
+       .listen = listen,
+       .connect = connect
+};
+
+btsock_interface_t *bt_get_socket_interface(void)
+{
+       return &socket_if;
+}
diff --git a/bt-oal/bluez_hal/src/bt-hal-socket.h b/bt-oal/bluez_hal/src/bt-hal-socket.h
new file mode 100644 (file)
index 0000000..12cbc20
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact:  Atul Kumar Rai <a.rai@samsung.com>
+ *
+ * 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_SOCKET_H__
+#define __BT_HAL_SOCKET_H__
+
+#include <stdint.h>
+#include <glib.h>
+#include <unistd.h>
+#include <dlog.h>
+#include <stdio.h>
+
+btsock_interface_t *bt_get_socket_interface(void);
+
+#endif //__BT_HAL_SOCKET_H__