oal-adapter-mgr.c
oal-device-mgr.c
oal-hid-host.c
+oal-socket.c
common/oal-utils.c
common/oal-common.c
common/oal-event-dispatcher.c
--- /dev/null
+/*
+ * 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_SOCK_H
+#define ANDROID_INCLUDE_BT_SOCK_H
+
+__BEGIN_DECLS
+
+#define BTSOCK_FLAG_ENCRYPT 1
+#define BTSOCK_FLAG_AUTH (1 << 1)
+
+typedef enum {
+ BTSOCK_RFCOMM = 1,
+ BTSOCK_SCO = 2,
+ BTSOCK_L2CAP = 3
+} btsock_type_t;
+
+/** Represents the standard BT SOCKET interface. */
+typedef struct {
+ short size;
+ bt_bdaddr_t bd_addr;
+ int channel;
+ int status;
+} __attribute__((packed)) sock_connect_signal_t;
+
+typedef struct {
+
+ /** set to size of this struct*/
+ size_t size;
+ /**
+ * listen to a rfcomm uuid or channel. It returns the socket fd from which
+ * btsock_connect_signal can be read out when a remote device connected
+ */
+ bt_status_t (*listen)(btsock_type_t type, const char* service_name, const uint8_t* service_uuid, int channel, int* sock_fd, int flags);
+ /*
+ * connect to a rfcomm uuid channel of remote device, It returns the socket fd from which
+ * the btsock_connect_signal and a new socket fd to be accepted can be read out when connected
+ */
+ 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);
+
+} btsock_interface_t;
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BT_SOCK_H */
--- /dev/null
+/*
+* 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_SOCKET_HOST_H_
+#define _OAL_SOCKET_HOST_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @fn oal_status_t socket_enable(void);
+ * @brief Enables the rfcomm profile
+ *
+ * This API will register the callback function, when any response/data are received from
+ * bluetooth RFCOMM remote device. @n
+ * this registered callback function will be get called with fd of remote device, data buffer and its length.
+ * This function is a synchronous call.
+ *
+ * @param[in] data_cb A pointer to the callback function
+ * @return BLUETOOTH_ERROR_NONE - Success
+ * @remark None
+ * @see None
+ * */
+oal_status_t socket_enable(void);
+
+/**
+ * @fn oal_status_t socket_disable(void);
+ * @brief Disables the rfcomm profile
+ *
+ * This API will disable RFCOMM profile. Before disabling it's better to ensure
+ * all the connections are closed
+ * This function is a synchronous call.
+ *
+ * @return BLUETOOTH_ERROR_NONE - Success
+ * @remark None
+ * @see socket_disconnect
+ * */
+oal_status_t socket_disable(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_SOCKET_HOST_H_*/
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <glib.h>
+#include <dlog.h>
+#include <sys/socket.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include <oal-event.h>
+#include <oal-manager.h>
+#include "oal-internal.h"
+
+#include "bluetooth.h"
+#include "bt_sock.h"
+#include "oal-socket.h"
+#include "oal-utils.h"
+
+#define CHECK_OAL_SOCKET_ENABLED() \
+ do { \
+ if (socket_api == NULL) { \
+ BT_ERR("Socket is not Initialized"); \
+ return OAL_STATUS_NOT_READY; \
+ } \
+ } while (0)
+
+/*
+ * Global variables
+ */
+static const btsock_interface_t* socket_api = NULL;
+
+oal_status_t socket_enable()
+{
+ const bt_interface_t *blued_api;
+
+ API_TRACE("Socket Init");
+
+ blued_api = adapter_get_stack_interface();
+ if(blued_api == NULL) {
+ BT_ERR("Stack is not initialized");
+ return OAL_STATUS_NOT_READY;
+ }
+
+ if(socket_api != NULL) {
+ BT_WARN("Socket Interface is already initialized...");
+ return OAL_STATUS_ALREADY_DONE;
+ }
+
+ socket_api = (const btsock_interface_t*)blued_api->get_profile_interface(BT_PROFILE_SOCKETS_ID);
+ if (!socket_api){
+ BT_ERR("OAL Socket failed to initialize");
+ return OAL_STATUS_INTERNAL_ERROR;
+ }
+
+ BT_DBG("Socket successfully initiated");
+ return OAL_STATUS_SUCCESS ;
+}
+
+oal_status_t socket_disable(void)
+{
+
+ API_TRACE("Socket Deinit");
+
+ CHECK_OAL_SOCKET_ENABLED();
+ socket_api = NULL;
+ return OAL_STATUS_SUCCESS;
+}
./services/bt-service-dpm.c
./services/bt-service-agent-util.c
./services/hid/bt-service-hidhost.c
+./services/socket/bt-service-socket.c
)
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
#include "bt-service-dpm.h"
#endif
#include "bt-service-hidhost.h"
+#include "bt-service-socket.h"
/* OAL headers */
#include <oal-event.h>
BT_ERR("_bt_hidhost_initialize Failed");
return ret;
}
+ ret = _bt_socket_init();
+ if (ret != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("_bt_socket_init Failed");
+ return ret;
+ }
return BLUETOOTH_ERROR_NONE;
}
_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 socket_cb;
void _bt_service_register_event_handler_callback(
bt_service_module_t module, _bt_service_event_handler_callback cb)
BT_INFO("Register BT_HID_MODULE Callback");
hid_cb = cb;
break;
+ case BT_SOCKET_MODULE:
+ BT_INFO("Register BT_SOCKET_MODULE Callback");
+ socket_cb = cb;
+ break;
default:
BT_INFO("Unknown module");
}
BT_INFO("Un-Register BT_HID_MODULE Callback");
hid_cb = NULL;
break;
+ case BT_SOCKET_MODULE:
+ BT_INFO("Un-Register BT_SOCKET_MODULE Callback");
+ socket_cb = NULL;
+ break;
default:
BT_INFO("Unknown module");
}
BT_ADAPTER_MODULE,
BT_DEVICE_MODULE,
BT_HID_MODULE,
+ BT_SOCKET_MODULE,
} bt_service_module_t;
void _bt_service_oal_event_receiver(int event_type, gpointer event_data, gsize len);
--- /dev/null
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2015 - 2016 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_SERVICE_SOCKET_H__
+#define __BT_SERVICE_SOCKET_H__
+
+#include <glib.h>
+#include <sys/types.h>
+#include "bluetooth-api.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _bt_socket_init(void);
+void _bt_socket_deinit(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* __BT_SERVICE_SOCKET_H__ */
--- /dev/null
+/*
+ * Bluetooth-frwk
+ *
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Author: 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 <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <glib.h>
+#include <dlog.h>
+
+/* OAL headers */
+#include <oal-event.h>
+#include <oal-socket.h>
+
+/* bt-service headers */
+#include "bt-internal-types.h"
+#include "bt-service-common.h"
+#include "bt-service-util.h"
+#include "bt-service-event-receiver.h"
+
+static void __bt_socket_event_handler(int event_type, gpointer event_data)
+{
+ BT_INFO("OAL event = 0x%x, \n", event_type);
+
+ switch(event_type) {
+ default:
+ BT_ERR("Invalid event:%d\n", event_type);
+ break;
+ }
+}
+
+int _bt_socket_init(void)
+{
+ BT_INFO("Socket Init");
+
+ if(OAL_STATUS_SUCCESS != socket_enable()) {
+ BT_ERR("Socket init failed");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ /* Register SOCKET event handler */
+ _bt_service_register_event_handler_callback(BT_SOCKET_MODULE, __bt_socket_event_handler);
+ return BLUETOOTH_ERROR_NONE;
+}
+
+void _bt_socket_deinit(void)
+{
+ BT_INFO("Socket de-init");
+
+ if(OAL_STATUS_SUCCESS != socket_disable())
+ BT_ERR("Socket de-init failed");
+
+ /* Un-register SOCKET event handler */
+ _bt_service_unregister_event_handler_callback(BT_SOCKET_MODULE);
+}