Taesoo Jun <steve.jun@samsung.com>
DoHyun Pyun <dh79.pyun@samsung.com>
+Anupam Roy <anupam.r@samsung.com>
ADD_SUBDIRECTORY(bt-service-emul)
ELSE()
IF("$ENV{BT_INCLUDE_OAL}" STREQUAL "ENABLED")
+ADD_SUBDIRECTORY(bt-oal)
ADD_SUBDIRECTORY(bt-service-adaptation)
ELSE("$ENV{BT_INCLUDE_OAL}" STREQUAL "ENABLED")
ADD_SUBDIRECTORY(bt-service)
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(bt-oal C)
+
+IF("$ENV{BT_INCLUDE_OAL_BLUEZ}" STREQUAL "ENABLED")
+ADD_SUBDIRECTORY(bluez_hal)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/bluez_hal/hardware/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/bluez_hal/)
+#SET(SRCS "${SRCS};./bluez_hal/hardware/hardware.c")
+ELSE("$ENV{BT_INCLUDE_OAL_BLUEZ}" STREQUAL "ENABLED")
+ENDIF("$ENV{BT_INCLUDE_OAL_BLUEZ}" STREQUAL "ENABLED")
+
+SET(SRCS
+oal-hardware.c
+oal-manager.c
+oal-adapter-mgr.c
+common/oal-utils.c
+common/oal-common.c
+common/oal-event-dispatcher.c
+)
+
+IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+ SET(CMAKE_BUILD_TYPE "Release")
+ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
+MESSAGE("Build type: ${CMAKE_BUILD_TYPE}")
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION_MAJOR 1)
+SET(VERSION ${VERSION_MAJOR}.0.0)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/common)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+
+LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib)
+LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/bt-oal)
+
+INCLUDE(FindPkgConfig)
+pkg_check_modules(oal_pkgs REQUIRED vconf aul vconf libudev dbus-glib-1
+alarm-service gio-unix-2.0 systemd dlog gio-2.0 glib-2.0 libtzplatform-config)
+
+FOREACH(flag ${oal_pkgs_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g ")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC")
+
+FIND_PROGRAM(UNAME NAMES uname)
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ MESSAGE("add -DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+#ADD_DEFINITIONS("-DOAL_DEBUG")
+
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
+#SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-DOAL_DEBUG ")
+
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${packages_LDFLAGS} -ldl)
+
+FOREACH(hfile ${HEADERS})
+ INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/${hfile} DESTINATION include/bt-oal)
+ENDFOREACH(hfile)
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+PROJECT(bluetooth.default C)
+
+SET(SRCS
+./src/bt-hal-bluetooth.c
+)
+
+SET(PREFIX ${CMAKE_INSTALL_PREFIX})
+SET(EXEC_PREFIX "\${prefix}")
+SET(LIBDIR "\${prefix}/lib")
+SET(INCLUDEDIR "\${prefix}/include")
+SET(VERSION_MAJOR 1)
+SET(VERSION ${VERSION_MAJOR}.0.0)
+SET(APP_SYSCONFDIR /opt/var/lib/bluetooth)
+
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/hardware/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/src/)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/inc/)
+
+SET(PKG_MODULES
+ dbus-glib-1
+ glib-2.0
+ gio-2.0
+ syspopup-caller
+)
+
+FIND_PROGRAM(MARSHALTOOL NAMES glib-genmarshal)
+EXEC_PROGRAM("${MARSHALTOOL}" ARGS "--prefix=marshal ${CMAKE_CURRENT_SOURCE_DIR}/marshal.list --header > ${CMAKE_CURRENT_SOURCE_DIR}/include/marshal.h")
+EXEC_PROGRAM("${MARSHALTOOL}" ARGS "--prefix=marshal ${CMAKE_CURRENT_SOURCE_DIR}/marshal.list --body > ${CMAKE_CURRENT_SOURCE_DIR}/marshal.c")
+
+FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
+
+FOREACH(flag ${packages_CFLAGS})
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
+ENDFOREACH(flag)
+
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g ")
+
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+
+FIND_PROGRAM(UNAME NAMES uname)
+
+FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
+
+EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH")
+IF("${ARCH}" STREQUAL "arm")
+ ADD_DEFINITIONS("-DTARGET")
+ MESSAGE("add -DTARGET")
+ENDIF("${ARCH}" STREQUAL "arm")
+
+ADD_DEFINITIONS("-DAPP_SYSCONFDIR=\"${APP_SYSCONFDIR}\"")
+
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -ldlog)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -lpthread)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -ldl)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -lgio-2.0)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -lglib-2.0)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -ldbus-1)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -lgobject-2.0)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -lsyspopup_caller)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -lbundle)
+
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT RuntimeLibraries)
--- /dev/null
+/* HAL API Documentation to follow */
--- /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_BLUETOOTH_H
+#define ANDROID_INCLUDE_BLUETOOTH_H
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <sys/cdefs.h>
+#include <sys/types.h>
+
+#include <hardware/hardware.h>
+
+__BEGIN_DECLS
+
+/**
+ * The Bluetooth Hardware Module ID
+ */
+
+#define BT_HARDWARE_MODULE_ID "bluetooth"
+#define BT_STACK_MODULE_ID "bluetooth"
+#define BT_STACK_TEST_MODULE_ID "bluetooth_test"
+
+
+/* Bluetooth profile interface IDs */
+
+#define BT_PROFILE_HANDSFREE_ID "handsfree"
+#define BT_PROFILE_HANDSFREE_CLIENT_ID "handsfree_client"
+#define BT_PROFILE_ADVANCED_AUDIO_ID "a2dp"
+#define BT_PROFILE_ADVANCED_AUDIO_SINK_ID "a2dp_sink"
+#define BT_PROFILE_HEALTH_ID "health"
+#define BT_PROFILE_SOCKETS_ID "socket"
+#define BT_PROFILE_HIDHOST_ID "hidhost"
+#define BT_PROFILE_PAN_ID "pan"
+#define BT_PROFILE_MAP_CLIENT_ID "map_client"
+
+#define BT_PROFILE_GATT_ID "gatt"
+#define BT_PROFILE_AV_RC_ID "avrcp"
+#define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
+
+/** Bluetooth Address */
+typedef struct {
+ uint8_t address[6];
+} __attribute__((packed))bt_bdaddr_t;
+
+/** Bluetooth Device Name */
+typedef struct {
+ uint8_t name[249];
+} __attribute__((packed))bt_bdname_t;
+
+/** Bluetooth Adapter Visibility Modes*/
+typedef enum {
+ BT_SCAN_MODE_NONE,
+ BT_SCAN_MODE_CONNECTABLE,
+ BT_SCAN_MODE_CONNECTABLE_DISCOVERABLE
+} bt_scan_mode_t;
+
+/** Bluetooth Adapter State */
+typedef enum {
+ BT_STATE_OFF,
+ BT_STATE_ON
+} bt_state_t;
+
+/** Bluetooth Error Status */
+/** We need to build on this */
+
+typedef enum {
+ BT_STATUS_SUCCESS,
+ BT_STATUS_FAIL,
+ BT_STATUS_NOT_READY,
+ BT_STATUS_NOMEM,
+ BT_STATUS_BUSY,
+ BT_STATUS_DONE, /* request already completed */
+ BT_STATUS_UNSUPPORTED,
+ BT_STATUS_PARM_INVALID,
+ BT_STATUS_UNHANDLED,
+ BT_STATUS_AUTH_FAILURE,
+ BT_STATUS_RMT_DEV_DOWN,
+ BT_STATUS_AUTH_REJECTED
+
+} bt_status_t;
+
+/** Bluetooth PinKey Code */
+typedef struct {
+ uint8_t pin[16];
+} __attribute__((packed))bt_pin_code_t;
+
+typedef struct {
+ uint8_t status;
+ uint8_t ctrl_state; /* stack reported state */
+ uint64_t tx_time; /* in ms */
+ uint64_t rx_time; /* in ms */
+ uint64_t idle_time; /* in ms */
+ uint64_t energy_used; /* a product of mA, V and ms */
+} __attribute__((packed))bt_activity_energy_info;
+
+/** Bluetooth Adapter Discovery state */
+typedef enum {
+ BT_DISCOVERY_STOPPED,
+ BT_DISCOVERY_STARTED
+} bt_discovery_state_t;
+
+/** Bluetooth ACL connection state */
+typedef enum {
+ BT_ACL_STATE_CONNECTED,
+ BT_ACL_STATE_DISCONNECTED
+} bt_acl_state_t;
+
+/** Bluetooth 128-bit UUID */
+typedef struct {
+ uint8_t uu[16];
+} bt_uuid_t;
+
+/** Bluetooth SDP service record */
+typedef struct
+{
+ bt_uuid_t uuid;
+ uint16_t channel;
+ char name[256]; // what's the maximum length
+} bt_service_record_t;
+
+
+/** Bluetooth Remote Version info */
+typedef struct
+{
+ int version;
+ int sub_ver;
+ int manufacturer;
+} bt_remote_version_t;
+
+typedef struct
+{
+ uint8_t local_privacy_enabled;
+ uint8_t max_adv_instance;
+ uint8_t rpa_offload_supported;
+ uint8_t max_irk_list_size;
+ uint8_t max_adv_filter_supported;
+ uint8_t scan_result_storage_size_lobyte;
+ uint8_t scan_result_storage_size_hibyte;
+ uint8_t activity_energy_info_supported;
+}bt_local_le_features_t;
+
+/* Bluetooth Adapter and Remote Device property types */
+typedef enum {
+ /* Properties common to both adapter and remote device */
+ /**
+ * Description - Bluetooth Device Name
+ * Access mode - Adapter name can be GET/SET. Remote device can be GET
+ * Data type - bt_bdname_t
+ */
+ BT_PROPERTY_BDNAME = 0x1,
+ /**
+ * Description - Bluetooth Device Address
+ * Access mode - Only GET.
+ * Data type - bt_bdaddr_t
+ */
+ BT_PROPERTY_BDADDR,
+ /**
+ * Description - Bluetooth Service 128-bit UUIDs
+ * Access mode - Only GET.
+ * Data type - Array of bt_uuid_t (Array size inferred from property length).
+ */
+ BT_PROPERTY_UUIDS,
+ /**
+ * Description - Bluetooth Class of Device as found in Assigned Numbers
+ * Access mode - Only GET.
+ * Data type - uint32_t.
+ */
+ BT_PROPERTY_CLASS_OF_DEVICE,
+ /**
+ * Description - Device Type - BREDR, BLE or DUAL Mode
+ * Access mode - Only GET.
+ * Data type - bt_device_type_t
+ */
+ BT_PROPERTY_TYPE_OF_DEVICE,
+ /**
+ * Description - Bluetooth Service Record
+ * Access mode - Only GET.
+ * Data type - bt_service_record_t
+ */
+ BT_PROPERTY_SERVICE_RECORD,
+
+ /* Properties unique to adapter */
+ /**
+ * Description - Bluetooth Adapter scan mode
+ * Access mode - GET and SET
+ * Data type - bt_scan_mode_t.
+ */
+ BT_PROPERTY_ADAPTER_SCAN_MODE,
+ /**
+ * Description - List of bonded devices
+ * Access mode - Only GET.
+ * Data type - Array of bt_bdaddr_t of the bonded remote devices
+ * (Array size inferred from property length).
+ */
+ BT_PROPERTY_ADAPTER_BONDED_DEVICES,
+ /**
+ * Description - Bluetooth Adapter Discovery timeout (in seconds)
+ * Access mode - GET and SET
+ * Data type - uint32_t
+ */
+ BT_PROPERTY_ADAPTER_DISCOVERY_TIMEOUT,
+
+ /* Properties unique to remote device */
+ /**
+ * Description - User defined friendly name of the remote device
+ * Access mode - GET and SET
+ * Data type - bt_bdname_t.
+ */
+ BT_PROPERTY_REMOTE_FRIENDLY_NAME,
+ /**
+ * Description - RSSI value of the inquired remote device
+ * Access mode - Only GET.
+ * Data type - int32_t.
+ */
+ BT_PROPERTY_REMOTE_RSSI,
+ /**
+ * Description - Remote version info
+ * Access mode - SET/GET.
+ * Data type - bt_remote_version_t.
+ */
+
+ BT_PROPERTY_REMOTE_VERSION_INFO,
+
+ /**
+ * Description - Local LE features
+ * Access mode - GET.
+ * Data type - bt_local_le_features_t.
+ */
+ BT_PROPERTY_LOCAL_LE_FEATURES,
+
+ BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF,
+} bt_property_type_t;
+
+/** Bluetooth Adapter Property data structure */
+typedef struct
+{
+ bt_property_type_t type;
+ int len;
+ void *val;
+} bt_property_t;
+
+
+/** Bluetooth Device Type */
+typedef enum {
+ BT_DEVICE_DEVTYPE_BREDR = 0x1,
+ BT_DEVICE_DEVTYPE_BLE,
+ BT_DEVICE_DEVTYPE_DUAL
+} bt_device_type_t;
+/** Bluetooth Bond state */
+typedef enum {
+ BT_BOND_STATE_NONE,
+ BT_BOND_STATE_BONDING,
+ BT_BOND_STATE_BONDED
+} bt_bond_state_t;
+
+/** Bluetooth SSP Bonding Variant */
+typedef enum {
+ BT_SSP_VARIANT_PASSKEY_CONFIRMATION,
+ BT_SSP_VARIANT_PASSKEY_ENTRY,
+ BT_SSP_VARIANT_CONSENT,
+ BT_SSP_VARIANT_PASSKEY_NOTIFICATION
+} bt_ssp_variant_t;
+
+#define BT_MAX_NUM_UUIDS 32
+
+/** Bluetooth Interface callbacks */
+
+/** Bluetooth Enable/Disable Callback. */
+typedef void (*adapter_state_changed_callback)(bt_state_t state);
+
+/** GET/SET Adapter Properties callback */
+/* TODO: For the GET/SET property APIs/callbacks, we may need a session
+ * identifier to associate the call with the callback. This would be needed
+ * whenever more than one simultaneous instance of the same adapter_type
+ * is get/set.
+ *
+ * If this is going to be handled in the Java framework, then we do not need
+ * to manage sessions here.
+ */
+typedef void (*adapter_properties_callback)(bt_status_t status,
+ int num_properties,
+ bt_property_t *properties);
+
+/** GET/SET Remote Device Properties callback */
+/** TODO: For remote device properties, do not see a need to get/set
+ * multiple properties - num_properties shall be 1
+ */
+typedef void (*remote_device_properties_callback)(bt_status_t status,
+ bt_bdaddr_t *bd_addr,
+ int num_properties,
+ bt_property_t *properties);
+
+/** New device discovered callback */
+/** If EIR data is not present, then BD_NAME and RSSI shall be NULL and -1
+ * respectively */
+typedef void (*device_found_callback)(int num_properties,
+ bt_property_t *properties);
+
+/** Discovery state changed callback */
+typedef void (*discovery_state_changed_callback)(bt_discovery_state_t state);
+
+/** Bluetooth Legacy PinKey Request callback */
+typedef void (*pin_request_callback)(bt_bdaddr_t *remote_bd_addr,
+ bt_bdname_t *bd_name, uint32_t cod);
+
+/** Bluetooth SSP Request callback - Just Works & Numeric Comparison*/
+/** pass_key - Shall be 0 for BT_SSP_PAIRING_VARIANT_CONSENT &
+ * BT_SSP_PAIRING_PASSKEY_ENTRY */
+/* TODO: Passkey request callback shall not be needed for devices with display
+ * capability. We still need support this in the stack for completeness */
+typedef void (*ssp_request_callback)(bt_bdaddr_t *remote_bd_addr,
+ bt_bdname_t *bd_name,
+ uint32_t cod,
+ bt_ssp_variant_t pairing_variant,
+ uint32_t pass_key);
+
+/** Bluetooth Bond state changed callback */
+/* Invoked in response to create_bond, cancel_bond or remove_bond */
+typedef void (*bond_state_changed_callback)(bt_status_t status,
+ bt_bdaddr_t *remote_bd_addr,
+ bt_bond_state_t state);
+
+/** Bluetooth ACL connection state changed callback */
+typedef void (*acl_state_changed_callback)(bt_status_t status, bt_bdaddr_t *remote_bd_addr,
+ bt_acl_state_t state);
+
+typedef enum {
+ ASSOCIATE_JVM,
+ DISASSOCIATE_JVM
+} bt_cb_thread_evt;
+
+/** Thread Associate/Disassociate JVM Callback */
+/* Callback that is invoked by the callback thread to allow upper layer to attach/detach to/from
+ * the JVM */
+typedef void (*callback_thread_event)(bt_cb_thread_evt evt);
+
+/** Bluetooth Test Mode Callback */
+/* Receive any HCI event from controller. Must be in DUT Mode for this callback to be received */
+typedef void (*dut_mode_recv_callback)(uint16_t opcode, uint8_t *buf, uint8_t len);
+
+/* LE Test mode callbacks
+* This callback shall be invoked whenever the le_tx_test, le_rx_test or le_test_end is invoked
+* The num_packets is valid only for le_test_end command */
+typedef void (*le_test_mode_callback)(bt_status_t status, uint16_t num_packets);
+
+/** Callback invoked when energy details are obtained */
+/* Ctrl_state-Current controller state-Active-1,scan-2,or idle-3 state as defined by HCI spec.
+ * If the ctrl_state value is 0, it means the API call failed
+ * Time values-In milliseconds as returned by the controller
+ * Energy used-Value as returned by the controller
+ * Status-Provides the status of the read_energy_info API call */
+typedef void (*energy_info_callback)(bt_activity_energy_info *energy_info);
+
+/** TODO: Add callbacks for Link Up/Down and other generic
+ * notifications/callbacks */
+
+/** Bluetooth DM callback structure. */
+typedef struct {
+ /** set to sizeof(bt_callbacks_t) */
+ size_t size;
+ adapter_state_changed_callback adapter_state_changed_cb;
+ adapter_properties_callback adapter_properties_cb;
+ remote_device_properties_callback remote_device_properties_cb;
+ device_found_callback device_found_cb;
+ discovery_state_changed_callback discovery_state_changed_cb;
+ pin_request_callback pin_request_cb;
+ ssp_request_callback ssp_request_cb;
+ bond_state_changed_callback bond_state_changed_cb;
+ acl_state_changed_callback acl_state_changed_cb;
+ callback_thread_event thread_evt_cb;
+ dut_mode_recv_callback dut_mode_recv_cb;
+ le_test_mode_callback le_test_mode_cb;
+ energy_info_callback energy_info_cb;
+} bt_callbacks_t;
+
+typedef void (*alarm_cb)(void *data);
+typedef bool (*set_wake_alarm_callout)(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data);
+typedef int (*acquire_wake_lock_callout)(const char *lock_name);
+typedef int (*release_wake_lock_callout)(const char *lock_name);
+
+/** The set of functions required by bluedroid to set wake alarms and
+ * grab wake locks. This struct is passed into the stack through the
+ * |set_os_callouts| function on |bt_interface_t|.
+ */
+typedef struct {
+ /* set to sizeof(bt_os_callouts_t) */
+ size_t size;
+
+ set_wake_alarm_callout set_wake_alarm;
+ acquire_wake_lock_callout acquire_wake_lock;
+ release_wake_lock_callout release_wake_lock;
+} bt_os_callouts_t;
+
+/** NOTE: By default, no profiles are initialized at the time of init/enable.
+ * Whenever the application invokes the 'init' API of a profile, then one of
+ * the following shall occur:
+ *
+ * 1.) If Bluetooth is not enabled, then the Bluetooth core shall mark the
+ * profile as enabled. Subsequently, when the application invokes the
+ * Bluetooth 'enable', as part of the enable sequence the profile that were
+ * marked shall be enabled by calling appropriate stack APIs. The
+ * 'adapter_properties_cb' shall return the list of UUIDs of the
+ * enabled profiles.
+ *
+ * 2.) If Bluetooth is enabled, then the Bluetooth core shall invoke the stack
+ * profile API to initialize the profile and trigger a
+ * 'adapter_properties_cb' with the current list of UUIDs including the
+ * newly added profile's UUID.
+ *
+ * The reverse shall occur whenever the profile 'cleanup' APIs are invoked
+ */
+
+/** Represents the standard Bluetooth DM interface. */
+typedef struct {
+ /** set to sizeof(bt_interface_t) */
+ size_t size;
+ /**
+ * Opens the interface and provides the callback routines
+ * to the implemenation of this interface.
+ */
+ int (*init)(bt_callbacks_t* callbacks );
+
+ /** Enable Bluetooth. */
+ int (*enable)(void);
+
+ /** Disable Bluetooth. */
+ int (*disable)(void);
+
+ /** Closes the interface. */
+ void (*cleanup)(void);
+
+ /** Get all Bluetooth Adapter properties at init */
+ int (*get_adapter_properties)(void);
+
+ /** Get Bluetooth Adapter property of 'type' */
+ int (*get_adapter_property)(bt_property_type_t type);
+
+ /** Set Bluetooth Adapter property of 'type' */
+ /* Based on the type, val shall be one of
+ * bt_bdaddr_t or bt_bdname_t or bt_scanmode_t etc
+ */
+ int (*set_adapter_property)(const bt_property_t *property);
+
+ /** Get all Remote Device properties */
+ int (*get_remote_device_properties)(bt_bdaddr_t *remote_addr);
+
+ /** Get Remote Device property of 'type' */
+ int (*get_remote_device_property)(bt_bdaddr_t *remote_addr,
+ bt_property_type_t type);
+
+ /** Set Remote Device property of 'type' */
+ int (*set_remote_device_property)(bt_bdaddr_t *remote_addr,
+ const bt_property_t *property);
+
+ /** Get Remote Device's service record for the given UUID */
+ int (*get_remote_service_record)(bt_bdaddr_t *remote_addr,
+ bt_uuid_t *uuid);
+
+ /** Start SDP to get remote services */
+ int (*get_remote_services)(bt_bdaddr_t *remote_addr);
+
+ /** Start Discovery */
+ int (*start_discovery)(void);
+
+ /** Cancel Discovery */
+ int (*cancel_discovery)(void);
+
+ /** Create Bluetooth Bonding */
+ int (*create_bond)(const bt_bdaddr_t *bd_addr, int transport);
+
+ /** Remove Bond */
+ int (*remove_bond)(const bt_bdaddr_t *bd_addr);
+
+ /** Cancel Bond */
+ int (*cancel_bond)(const bt_bdaddr_t *bd_addr);
+
+ /**
+ * Get the connection status for a given remote device.
+ * return value of 0 means the device is not connected,
+ * non-zero return status indicates an active connection.
+ */
+ int (*get_connection_state)(const bt_bdaddr_t *bd_addr);
+
+ /** BT Legacy PinKey Reply */
+ /** If accept==FALSE, then pin_len and pin_code shall be 0x0 */
+ int (*pin_reply)(const bt_bdaddr_t *bd_addr, uint8_t accept,
+ uint8_t pin_len, bt_pin_code_t *pin_code);
+
+ /** BT SSP Reply - Just Works, Numeric Comparison and Passkey
+ * passkey shall be zero for BT_SSP_VARIANT_PASSKEY_COMPARISON &
+ * BT_SSP_VARIANT_CONSENT
+ * For BT_SSP_VARIANT_PASSKEY_ENTRY, if accept==FALSE, then passkey
+ * shall be zero */
+ int (*ssp_reply)(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
+ uint8_t accept, uint32_t passkey);
+
+ /** Get Bluetooth profile interface */
+ const void* (*get_profile_interface) (const char *profile_id);
+
+ /** Bluetooth Test Mode APIs - Bluetooth must be enabled for these APIs */
+ /* Configure DUT Mode - Use this mode to enter/exit DUT mode */
+ int (*dut_mode_configure)(uint8_t enable);
+
+ /* Send any test HCI (vendor-specific) command to the controller. Must be in DUT Mode */
+ int (*dut_mode_send)(uint16_t opcode, uint8_t *buf, uint8_t len);
+ /** BLE Test Mode APIs */
+ /* opcode MUST be one of: LE_Receiver_Test, LE_Transmitter_Test, LE_Test_End */
+ int (*le_test_mode)(uint16_t opcode, uint8_t *buf, uint8_t len);
+
+ /* enable or disable bluetooth HCI snoop log */
+ int (*config_hci_snoop_log)(uint8_t enable);
+
+ /** Sets the OS call-out functions that bluedroid needs for alarms and wake locks.
+ * This should be called immediately after a successful |init|.
+ */
+ int (*set_os_callouts)(bt_os_callouts_t *callouts);
+
+ /** Read Energy info details - return value indicates BT_STATUS_SUCCESS or BT_STATUS_NOT_READY
+ * Success indicates that the VSC command was sent to controller
+ */
+ int (*read_energy_info)();
+} bt_interface_t;
+
+/** TODO: Need to add APIs for Service Discovery, Service authorization and
+ * connection management. Also need to add APIs for configuring
+ * properties of remote bonded devices such as name, UUID etc. */
+
+typedef struct {
+ struct hw_device_t common;
+ const bt_interface_t* (*get_bluetooth_interface)();
+} bluetooth_device_t;
+
+typedef bluetooth_device_t bluetooth_module_t;
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_BLUETOOTH_H */
--- /dev/null
+/*
+ * Copyright (C) 2008 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.
+ */
+
+#include <hardware/hardware.h>
+
+#include <dlfcn.h>
+#include <string.h>
+#include <pthread.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdio.h>
+
+#define LOG_TAG "HAL"
+
+#define LOG_INFO " I"
+#define LOG_WARN " W"
+#define LOG_ERROR " E"
+#define LOG_DEBUG " D"
+#define ALOG(pri, tag, fmt, arg...) fprintf(stderr, tag pri": " fmt"\n", ##arg)
+
+#define info(fmt, arg...) ALOG(LOG_INFO, LOG_TAG, fmt, ##arg)
+#define warn(fmt, arg...) ALOG(LOG_WARN, LOG_TAG, fmt, ##arg)
+#define error(fmt, arg...) ALOG(LOG_ERROR, LOG_TAG, fmt, ##arg)
+
+#define HAL_LIBRARY_PATH "/usr/lib"
+
+/**
+ * Load the file defined by the variant and if successful
+ * return the dlopen handle and the hmi.
+ * @return 0 = success, !0 = failure.
+ */
+static int load(const char *id,
+ const char *path,
+ const struct hw_module_t **pHmi)
+{
+ int status;
+ void *handle;
+ struct hw_module_t *hmi;
+ const char *sym = HAL_MODULE_INFO_SYM_AS_STR;
+
+ /*
+ * load the symbols resolving undefined symbols before
+ * dlopen returns. Since RTLD_GLOBAL is not or'd in with
+ * RTLD_NOW the external symbols will not be global
+ */
+ handle = dlopen(path, RTLD_NOW);
+ if (handle == NULL) {
+ char const *err_str = dlerror();
+ error("load: module=%s\n%s", path, err_str?err_str:"unknown");
+ status = -EINVAL;
+ goto done;
+ }
+
+ /* Get the address of the struct hal_module_info. */
+ hmi = (struct hw_module_t *)dlsym(handle, sym);
+ if (hmi == NULL) {
+ error("load: couldn't find symbol %s", sym);
+ status = -EINVAL;
+ goto done;
+ }
+
+ /* Check that the id matches */
+ if (strcmp(id, hmi->id) != 0) {
+ error("load: id=%s != hmi->id=%s", id, hmi->id);
+ status = -EINVAL;
+ goto done;
+ }
+
+ hmi->dso = handle;
+
+ *pHmi = hmi;
+
+ info("loaded HAL id=%s path=%s hmi=%p handle=%p",
+ id, path, *pHmi, handle);
+
+ return 0;
+
+done:
+ hmi = NULL;
+ if (handle != NULL) {
+ dlclose(handle);
+ handle = NULL;
+ }
+
+ return status;
+}
+
+int hw_get_module_by_class(const char *class_id, const char *inst,
+ const struct hw_module_t **module)
+{
+ char path[PATH_MAX];
+ char name[PATH_MAX];
+
+ if (inst)
+ snprintf(name, PATH_MAX, "%s.%s", class_id, inst);
+ else
+ snprintf(name, PATH_MAX, "%s", class_id);
+
+ /*
+ * Here we rely on the fact that calling dlopen multiple times on
+ * the same .so will simply increment a refcount (and not load
+ * a new copy of the library).
+ * We also assume that dlopen() is thread-safe.
+ */
+ snprintf(path, sizeof(path), "%s/%s.default.so", HAL_LIBRARY_PATH, name);
+
+ return load(class_id, path, module);
+}
+
+int hw_get_module(const char *id, const struct hw_module_t **module)
+{
+ return hw_get_module_by_class(id, NULL, module);
+}
--- /dev/null
+/*
+ * Copyright (C) 2008 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_HARDWARE_HARDWARE_H
+#define ANDROID_INCLUDE_HARDWARE_HARDWARE_H
+
+#include <stdint.h>
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+
+/*
+ * Value for the hw_module_t.tag field
+ */
+
+#define MAKE_TAG_CONSTANT(A,B,C,D) (((A) << 24) | ((B) << 16) | ((C) << 8) | (D))
+
+#define HARDWARE_MODULE_TAG MAKE_TAG_CONSTANT('H', 'W', 'M', 'T')
+#define HARDWARE_DEVICE_TAG MAKE_TAG_CONSTANT('H', 'W', 'D', 'T')
+
+#define HARDWARE_MAKE_API_VERSION(maj,min) \
+ ((((maj) & 0xff) << 8) | ((min) & 0xff))
+
+#define HARDWARE_MAKE_API_VERSION_2(maj,min,hdr) \
+ ((((maj) & 0xff) << 24) | (((min) & 0xff) << 16) | ((hdr) & 0xffff))
+#define HARDWARE_API_VERSION_2_MAJ_MIN_MASK 0xffff0000
+#define HARDWARE_API_VERSION_2_HEADER_MASK 0x0000ffff
+
+
+/*
+ * The current HAL API version.
+ *
+ * All module implementations must set the hw_module_t.hal_api_version field
+ * to this value when declaring the module with HAL_MODULE_INFO_SYM.
+ *
+ * Note that previous implementations have always set this field to 0.
+ * Therefore, libhardware HAL API will always consider versions 0.0 and 1.0
+ * to be 100% binary compatible.
+ *
+ */
+#define HARDWARE_HAL_API_VERSION HARDWARE_MAKE_API_VERSION(1, 0)
+
+/*
+ * Helper macros for module implementors.
+ *
+ * The derived modules should provide convenience macros for supported
+ * versions so that implementations can explicitly specify module/device
+ * versions at definition time.
+ *
+ * Use this macro to set the hw_module_t.module_api_version field.
+ */
+#define HARDWARE_MODULE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
+#define HARDWARE_MODULE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
+
+/*
+ * Use this macro to set the hw_device_t.version field
+ */
+#define HARDWARE_DEVICE_API_VERSION(maj,min) HARDWARE_MAKE_API_VERSION(maj,min)
+#define HARDWARE_DEVICE_API_VERSION_2(maj,min,hdr) HARDWARE_MAKE_API_VERSION_2(maj,min,hdr)
+
+struct hw_module_t;
+struct hw_module_methods_t;
+struct hw_device_t;
+
+/**
+ * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
+ * and the fields of this data structure must begin with hw_module_t
+ * followed by module specific information.
+ */
+typedef struct hw_module_t {
+ /** tag must be initialized to HARDWARE_MODULE_TAG */
+ uint32_t tag;
+
+ /**
+ * The API version of the implemented module. The module owner is
+ * responsible for updating the version when a module interface has
+ * changed.
+ *
+ * The derived modules such as gralloc and audio own and manage this field.
+ * The module user must interpret the version field to decide whether or
+ * not to inter-operate with the supplied module implementation.
+ * For example, SurfaceFlinger is responsible for making sure that
+ * it knows how to manage different versions of the gralloc-module API,
+ * and AudioFlinger must know how to do the same for audio-module API.
+ *
+ * The module API version should include a major and a minor component.
+ * For example, version 1.0 could be represented as 0x0100. This format
+ * implies that versions 0x0100-0x01ff are all API-compatible.
+ *
+ * In the future, libhardware will expose a hw_get_module_version()
+ * (or equivalent) function that will take minimum/maximum supported
+ * versions as arguments and would be able to reject modules with
+ * versions outside of the supplied range.
+ */
+ uint16_t module_api_version;
+#define version_major module_api_version
+ /**
+ * version_major/version_minor defines are supplied here for temporary
+ * source code compatibility. They will be removed in the next version.
+ * ALL clients must convert to the new version format.
+ */
+
+ /**
+ * The API version of the HAL module interface. This is meant to
+ * version the hw_module_t, hw_module_methods_t, and hw_device_t
+ * structures and definitions.
+ *
+ * The HAL interface owns this field. Module users/implementations
+ * must NOT rely on this value for version information.
+ *
+ * Presently, 0 is the only valid value.
+ */
+ uint16_t hal_api_version;
+#define version_minor hal_api_version
+
+ /** Identifier of module */
+ const char *id;
+
+ /** Name of this module */
+ const char *name;
+
+ /** Author/owner/implementor of the module */
+ const char *author;
+
+ /** Modules methods */
+ struct hw_module_methods_t* methods;
+
+ /** module's dso */
+ void* dso;
+
+ /** padding to 128 bytes, reserved for future use */
+ uint32_t reserved[32-7];
+
+} hw_module_t;
+
+typedef struct hw_module_methods_t {
+ /** Open a specific device */
+ int (*open)(const struct hw_module_t* module, const char* id,
+ struct hw_device_t** device);
+
+} hw_module_methods_t;
+
+/**
+ * Every device data structure must begin with hw_device_t
+ * followed by module specific public methods and attributes.
+ */
+typedef struct hw_device_t {
+ /** tag must be initialized to HARDWARE_DEVICE_TAG */
+ uint32_t tag;
+
+ /**
+ * Version of the module-specific device API. This value is used by
+ * the derived-module user to manage different device implementations.
+ *
+ * The module user is responsible for checking the module_api_version
+ * and device version fields to ensure that the user is capable of
+ * communicating with the specific module implementation.
+ *
+ * One module can support multiple devices with different versions. This
+ * can be useful when a device interface changes in an incompatible way
+ * but it is still necessary to support older implementations at the same
+ * time. One such example is the Camera 2.0 API.
+ *
+ * This field is interpreted by the module user and is ignored by the
+ * HAL interface itself.
+ */
+ uint32_t version;
+
+ /** reference to the module this device belongs to */
+ struct hw_module_t* module;
+
+ /** padding reserved for future use */
+ uint32_t reserved[12];
+
+ /** Close this device */
+ int (*close)(struct hw_device_t* device);
+
+} hw_device_t;
+
+/**
+ * Name of the hal_module_info
+ */
+#define HAL_MODULE_INFO_SYM HMI
+
+/**
+ * Name of the hal_module_info as a string
+ */
+#define HAL_MODULE_INFO_SYM_AS_STR "HMI"
+
+/**
+ * Get the module info associated with a module by id.
+ *
+ * @return: 0 == success, <0 == error and *module == NULL
+ */
+int hw_get_module(const char *id, const struct hw_module_t **module);
+
+/**
+ * Get the module info associated with a module instance by class 'class_id'
+ * and instance 'inst'.
+ *
+ * Some modules types necessitate multiple instances. For example audio supports
+ * multiple concurrent interfaces and thus 'audio' is the module class
+ * and 'primary' or 'a2dp' are module interfaces. This implies that the files
+ * providing these modules would be named audio.primary.<variant>.so and
+ * audio.a2dp.<variant>.so
+ *
+ * @return: 0 == success, <0 == error and *module == NULL
+ */
+int hw_get_module_by_class(const char *class_id, const char *inst,
+ const struct hw_module_t **module);
+
+__END_DECLS
+
+#endif /* ANDROID_INCLUDE_HARDWARE_HARDWARE_H */
--- /dev/null
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * 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_LOG_H_
+#define _BT_HAL_LOG_H_
+
+#undef LOG_TAG
+#define LOG_TAG "BLUETOOTH_HAL"
+
+#ifdef FUNCTION_TRACE
+#define FN_START BT_DBG("[ENTER FUNC]")
+#define FN_END BT_DBG("[EXIT FUNC]")
+#else
+#define FN_START
+#define FN_END
+#endif
+
+#define LOG_COLOR_RESET "\033[0m"
+#define LOG_COLOR_RED "\033[31m"
+#define LOG_COLOR_YELLOW "\033[33m"
+#define LOG_COLOR_GREEN "\033[32m"
+#define LOG_COLOR_BLUE "\033[36m"
+#define LOG_COLOR_PURPLE "\033[35m"
+
+#define DBG(fmt, args...) \
+ SLOGD(fmt, ##args)
+#define INFO(fmt, args...) \
+ SLOGI(fmt, ##args)
+#define ERR(fmt, args...) \
+ SLOGE(fmt, ##args)
+
+#define INFO_C(fmt, arg...) \
+ SLOGI_IF(TRUE, LOG_COLOR_GREEN" "fmt" "LOG_COLOR_RESET, ##arg)
+#define ERR_C(fmt, arg...) \
+ SLOGI_IF(TRUE, LOG_COLOR_RED" "fmt" "LOG_COLOR_RESET, ##arg)
+
+#define DBG_SECURE(fmt, args...) SECURE_SLOGD(fmt, ##args)
+#define ERR_SECURE(fmt, args...) SECURE_SLOGE(fmt, ##args)
+
+#endif //_BT_HAL_LOG_H_
--- /dev/null
+/*
+ * Copyright (c) 2015 -2016 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * Contact: Anupam Roy <anupam.r@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_MSG_H_
+#define _BT_HAL_MSG_H_
+
+#define HAL_MINIMUM_EVENT 0x81
+/*TODO: More events to be added in subsequent patches */
+
+/* HAL Global Macros */
+#define HAL_POWER_OFF 0x00
+#define HAL_POWER_ON 0x01
+
+#define HAL_PROP_ADAPTER_NAME 0x01
+#define HAL_PROP_ADAPTER_ADDR 0x02
+#define HAL_PROP_ADAPTER_UUIDS 0x03
+#define HAL_PROP_ADAPTER_CLASS 0x04
+#define HAL_PROP_ADAPTER_TYPE 0x05
+#define HAL_PROP_ADAPTER_SERVICE_REC 0x06
+#define HAL_PROP_ADAPTER_SCAN_MODE 0x07
+#define HAL_PROP_ADAPTER_BONDED_DEVICES 0x08
+#define HAL_PROP_ADAPTER_DISC_TIMEOUT 0x09
+
+#define HAL_PROP_ADAPTER_VERSION 0x17
+#define HAL_PROP_ADAPTER_LOCAL_LE_FEAT 0x1c
+
+#define HAL_PROP_DEVICE_NAME 0x01
+#define HAL_PROP_DEVICE_ADDR 0x02
+#define HAL_PROP_DEVICE_UUIDS 0x03
+#define HAL_PROP_DEVICE_CLASS 0x04
+#define HAL_PROP_DEVICE_TYPE 0x05
+#define HAL_PROP_DEVICE_SERVICE_REC 0x06
+
+/* Tizen specific HAL Adapter and Device property types.
+ These properties have to added to HAL bt_property_type_t enums */
+
+struct hal_prop_device_service_rec {
+ uint8_t uuid[16];
+ uint16_t channel;
+ uint8_t name_len;
+ uint8_t name[];
+} __attribute__((packed));
+
+#define HAL_PROP_DEVICE_FRIENDLY_NAME 0x0b
+#define HAL_PROP_DEVICE_RSSI 0x0c
+#define HAL_PROP_DEVICE_DID_INFO 0x0d
+#define HAL_PROP_DEVICE_VERSION_INFO 0x0e
+#define HAL_PROP_DEVICE_INFO 0x0f
+struct hal_prop_device_info {
+ uint8_t version;
+ uint16_t sub_version;
+ uint16_t manufacturer;
+} __attribute__((packed));
+
+#define HAL_PROP_DEVICE_TIMESTAMP 0xFF
+
+#define HAL_EV_ADAPTER_STATE_CHANGED 0x00
+struct hal_ev_adapter_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+
+struct hal_property {
+ uint8_t type;
+ uint16_t len;
+ uint8_t val[0];
+} __attribute__((packed));
+
+#define HAL_EV_ADAPTER_PROPS_CHANGED 0x01
+struct hal_ev_adapter_props_changed {
+ uint8_t status;
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+
+#define HAL_DISCOVERY_STATE_STOPPED 0x00
+#define HAL_DISCOVERY_STATE_STARTED 0x01
+
+#define HAL_EV_DISCOVERY_STATE_CHANGED 0x85
+struct hal_ev_discovery_state_changed {
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_EV_REMOTE_DEVICE_PROPS 0x83
+struct hal_ev_remote_device_props {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+#define HAL_EV_DEVICE_FOUND 0x84
+struct hal_ev_device_found {
+ uint8_t num_props;
+ struct hal_property props[0];
+} __attribute__((packed));
+
+
+/* Device callbacks */
+#define HAL_EV_PIN_REQUEST 0x86
+struct hal_ev_pin_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249];
+ uint32_t class_of_dev;
+} __attribute__((packed));
+
+#define HAL_EV_SSP_REQUEST 0x87
+struct hal_ev_ssp_request {
+ uint8_t bdaddr[6];
+ uint8_t name[249];
+ uint32_t class_of_dev;
+ uint8_t pairing_variant;
+ uint32_t passkey;
+} __attribute__((packed));
+
+#define HAL_BOND_STATE_NONE 0
+#define HAL_BOND_STATE_BONDING 1
+#define HAL_BOND_STATE_BONDED 2
+
+#define HAL_EV_BOND_STATE_CHANGED 0x88
+struct hal_ev_bond_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define HAL_ACL_STATE_CONNECTED 0x00
+#define HAL_ACL_STATE_DISCONNECTED 0x01
+
+#define HAL_EV_ACL_STATE_CHANGED 0x8A
+struct hal_ev_acl_state_changed {
+ uint8_t status;
+ uint8_t bdaddr[6];
+ uint8_t state;
+} __attribute__((packed));
+
+#define BT_TRANSPORT_UNKNOWN 0x00
+#define BT_TRANSPORT_BR_EDR 0x01
+#define BT_TRANSPORT_LE 0x02
+
+#endif //_BT_HAL_MSG_H_
+
--- /dev/null
+/*
+ * Copyright (C) 2013 Intel Corporation
+ *
+ * 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_UTILS_H_
+#define _BT_HAL_UTILS_H_
+
+#include <endian.h>
+
+#include <hardware/bluetooth.h>
+
+#define MAX_UUID_STR_LEN 37
+#define HAL_UUID_LEN 16
+#define MAX_ADDR_STR_LEN 18
+
+static const char BT_BASE_UUID[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb
+};
+
+const char *bt_uuid_t2str(const uint8_t *uuid, char *buf);
+const char *btuuid2str(const uint8_t *uuid);
+const char *bt_bdaddr_t2str(const bt_bdaddr_t *bd_addr, char *buf);
+void str2bt_bdaddr_t(const char *str, bt_bdaddr_t *bd_addr);
+void str2bt_uuid_t(const char *str, bt_uuid_t *uuid);
+const char *btproperty2str(const bt_property_t *property);
+const char *bdaddr2str(const bt_bdaddr_t *bd_addr);
+
+const char* bt_property_type_t2str(bt_property_type_t prop_type);
+const char* bt_device_type_t2str(bt_device_type_t device_type);
+
+struct int2str {
+ int val; /* int value */
+ const char *str; /* corresponding string */
+};
+
+int int2str_findint(int v, const struct int2str m[]);
+int int2str_findstr(const char *str, const struct int2str m[]);
+const char *enum_defines(void *v, int i);
+const char *enum_strings(void *v, int i);
+const char *enum_one_string(void *v, int i);
+
+#endif //_BT_HAL_UTILS_H_
--- /dev/null
+/*
+ * BLUETOOTH HAL
+ *
+ * Copyright (c) 2015 -2016 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * Contact: Anupam Roy <anupam.r@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_H_
+#define _BT_HAL_H_
+
+#include <hardware/bluetooth.h>
+
+/*TODO: Profile interfaces headers and exposed methods of Android HAL framework to be included in next patches */
+#endif //_BT_HAL_H
--- /dev/null
+/*
+ * BLUETOOTH HAL
+ *
+ * Copyright (c) 2015 -2016 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * Contact: Anupam Roy <anupam.r@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 <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+#include <dlog.h>
+
+#include "bt-hal.h"
+#include "bt-hal-log.h"
+#include "bt-hal-msg.h"
+#include "bt-hal-utils.h"
+
+#define enum_prop_to_hal(prop, hal_prop, type) do { \
+ static type e; \
+ prop.val = &e; \
+ prop.len = sizeof(e); \
+ e = *((uint8_t *) (hal_prop->val)); \
+} while (0)
+
+static const bt_callbacks_t *bt_hal_cbacks = NULL;
+
+static bool interface_ready(void)
+{
+ return bt_hal_cbacks != NULL;
+}
+
+static int init(bt_callbacks_t *callbacks)
+{
+ DBG("HAL library Initialization..");
+
+ if (interface_ready())
+ return BT_STATUS_DONE;
+ else {
+ bt_hal_cbacks = callbacks;
+ DBG("Store HAL stack msg handler callback");
+ }
+ return BT_STATUS_SUCCESS;
+}
+
+/* Enable Adapter */
+static int enable(void)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+/* Disable Adapter */
+static int disable(void)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static void cleanup(void)
+{
+ return;
+}
+
+static int get_adapter_properties(void)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+
+static int get_adapter_property(bt_property_type_t type)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_adapter_property(const bt_property_t *property)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_device_property(bt_bdaddr_t *remote_addr,
+ bt_property_type_t type)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_remote_device_property(bt_bdaddr_t *remote_addr,
+ const bt_property_t *property)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid)
+{
+ return BT_STATUS_UNSUPPORTED;
+
+}
+
+static int get_remote_services(bt_bdaddr_t *remote_addr)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int start_discovery(void)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_discovery(void)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int create_bond(const bt_bdaddr_t *bd_addr, int transport)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int cancel_bond(const bt_bdaddr_t *bd_addr)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int remove_bond(const bt_bdaddr_t *bd_addr)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept,
+ uint8_t pin_len, bt_pin_code_t *pin_code)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int ssp_reply(const bt_bdaddr_t *bd_addr, bt_ssp_variant_t variant,
+ uint8_t accept, uint32_t passkey)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const void *get_profile_interface(const char *profile_id)
+{
+ /*TODO: Profile interfaces to be included later*/
+ DBG("%s", profile_id);
+
+ if (!interface_ready())
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_PAN_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_AV_RC_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_GATT_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_HEALTH_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_AV_RC_CTRL_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_HANDSFREE_CLIENT_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_MAP_CLIENT_ID))
+ return NULL;
+
+ if (!strcmp(profile_id, BT_PROFILE_ADVANCED_AUDIO_SINK_ID))
+ return NULL;
+
+ return NULL;
+}
+
+static int dut_mode_configure(uint8_t enable)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int dut_mode_send(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int le_test_mode(uint16_t opcode, uint8_t *buf, uint8_t buf_len)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int config_hci_snoop_log(uint8_t enable)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int get_connection_state(const bt_bdaddr_t *bd_addr)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int set_os_callouts(bt_os_callouts_t *callouts)
+{
+ DBG("callouts: %p", callouts);
+
+ /* TODO: implement */
+
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static int read_energy_info(void)
+{
+ return BT_STATUS_UNSUPPORTED;
+}
+
+static const bt_interface_t bluetooth_if = {
+ .size = sizeof(bt_interface_t),
+ .init = init,
+ .enable = enable,
+ .disable = disable,
+ .cleanup = cleanup,
+ .get_adapter_properties = get_adapter_properties,
+ .get_adapter_property = get_adapter_property,
+ .set_adapter_property = set_adapter_property,
+ .get_remote_device_properties = get_remote_device_properties,
+ .get_remote_device_property = get_remote_device_property,
+ .set_remote_device_property = set_remote_device_property,
+ .get_remote_service_record = get_remote_service_record,
+ .get_remote_services = get_remote_services,
+ .start_discovery = start_discovery,
+ .cancel_discovery = cancel_discovery,
+ .create_bond = create_bond,
+ .remove_bond = remove_bond,
+ .cancel_bond = cancel_bond,
+ .pin_reply = pin_reply,
+ .ssp_reply = ssp_reply,
+ .get_profile_interface = get_profile_interface,
+ .dut_mode_configure = dut_mode_configure,
+ .dut_mode_send = dut_mode_send,
+ .le_test_mode = le_test_mode,
+ .config_hci_snoop_log = config_hci_snoop_log,
+ .get_connection_state = get_connection_state,
+ .set_os_callouts = set_os_callouts,
+ .read_energy_info = read_energy_info,
+};
+
+static const bt_interface_t *get_bluetooth_interface(void)
+{
+ DBG("");
+ return &bluetooth_if;
+}
+
+static int close_bluetooth(struct hw_device_t *device)
+{
+ DBG("");
+ cleanup();
+ free(device);
+ return 0;
+}
+
+static int open_bluetooth(const struct hw_module_t *module, char const *name,
+ struct hw_device_t **device)
+{
+ bluetooth_device_t *dev = malloc(sizeof(bluetooth_device_t));
+
+ DBG("");
+
+ memset(dev, 0, sizeof(bluetooth_device_t));
+ dev->common.tag = HARDWARE_DEVICE_TAG;
+ dev->common.version = 0;
+ dev->common.module = (struct hw_module_t *) module;
+ dev->common.close = close_bluetooth;
+ dev->get_bluetooth_interface = get_bluetooth_interface;
+
+ *device = (struct hw_device_t *) dev;
+
+ return 0;
+}
+
+static struct hw_module_methods_t bluetooth_module_methods = {
+ .open = open_bluetooth,
+};
+
+struct hw_module_t HAL_MODULE_INFO_SYM = {
+ .tag = HARDWARE_MODULE_TAG,
+ .version_major = 1,
+ .version_minor = 0,
+ .id = BT_HARDWARE_MODULE_ID,
+ .name = "Bluetooth stack",
+ .author = "Intel Corporation",
+ .methods = &bluetooth_module_methods
+};
--- /dev/null
+/*
+* Open Adaptation Layer (OAL)
+*
+* Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+*
+* Contact: Anupam Roy <anupam.r@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 <stdlib.h>
+#include <dlog.h>
+#include <string.h>
+#include <vconf.h>
+#include <sys/prctl.h>
+#include <unistd.h>
+#include <arpa/inet.h>
+
+#include <bluetooth.h>
+#include "oal-internal.h"
+#include "oal-common.h"
+
+#define BT_UUID_STRING_SIZE 37
+#define BT_UUID_LENGTH_MAX 16
+
+oal_status_t convert_to_oal_status(bt_status_t status) {
+ oal_status_t ret = OAL_STATUS_INTERNAL_ERROR;
+
+ switch(status) {
+ case BT_STATUS_SUCCESS:
+ case BT_STATUS_DONE:
+ ret = OAL_STATUS_SUCCESS;
+ break;
+ case BT_STATUS_NOT_READY:
+ ret = OAL_STATUS_NOT_READY;
+ break;
+ case BT_STATUS_BUSY:
+ ret = OAL_STATUS_BUSY;
+ break;
+ case BT_STATUS_PARM_INVALID:
+ ret = OAL_STATUS_INVALID_PARAM;
+ break;
+ case BT_STATUS_RMT_DEV_DOWN:
+ ret = OAL_STATUS_RMT_DEVICE_DOWN;
+ break;
+ case BT_STATUS_AUTH_FAILURE:
+ ret = OAL_STATUS_AUTH_FAILED;
+ break;
+ case BT_STATUS_UNSUPPORTED:
+ ret = OAL_STATUS_NOT_SUPPORT;
+ break;
+ case BT_STATUS_UNHANDLED:
+ case BT_STATUS_FAIL:
+ case BT_STATUS_NOMEM:
+ default:
+ ret = OAL_STATUS_INTERNAL_ERROR;
+ break;
+ }
+ return ret;
+}
+
+static const char * status_str[] = {
+ "BT_STATUS_SUCCESS",
+ "BT_STATUS_FAIL",
+ "BT_STATUS_NOT_READY",
+ "BT_STATUS_NOMEM",
+ "BT_STATUS_BUSY",
+ "BT_STATUS_DONE",
+ "BT_STATUS_UNSUPPORTED",
+ "BT_STATUS_PARM_INVALID",
+ "BT_STATUS_UNHANDLED",
+ "BT_STATUS_AUTH_FAILURE",
+ "BT_STATUS_RMT_DEV_DOWN"
+};
+
+const char * status2string(bt_status_t status) {
+ if(status >= BT_STATUS_SUCCESS && status <= BT_STATUS_RMT_DEV_DOWN)
+ return status_str[status];
+ else {
+ BT_ERR("Invalid BT status from stack");
+ return "BT_STATUS_UNKNOWN";
+ }
+}
--- /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_COMMON_H_
+#define _OAL_COMMON_H_
+
+#include <stdint.h>
+#include <sys/types.h>
+
+#include <bluetooth.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+void parse_device_properties(int num_properties, bt_property_t *properties,
+ remote_device_t *dev_info, ble_adv_data_t * adv_info);
+oal_status_t convert_to_oal_status(bt_status_t status);
+
+const char * status2string(bt_status_t status);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_COMMON_H_*/
--- /dev/null
+/*
+ * bluetooth-frwk
+ *
+ * Copyright (c) 2012-2013 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.
+ *
+ */
+#define _OAL_EVENT_DISPATCHER_C_
+
+#include <stdio.h>
+#include <glib.h>
+#include <dlog.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "oal-hardware.h"
+#include "oal-event.h"
+#include "oal-utils.h"
+#include "oal-manager.h"
+
+#define EVENT_TRACE(fmt, args...) {LOG_(LOG_ID_SYSTEM, DLOG_INFO, "OAL_EVENT", GREEN(fmt), ##args); \
+ LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, GREEN("[OAL_EVENT]"fmt), ##args);}
+
+typedef struct {
+ int event;
+ gpointer event_data;
+} event_t;
+
+static GMainContext *event_thread_context;
+static oal_event_callback event_handler_cb;
+
+static gpointer __event_handler_loop(gpointer user_data)
+{
+ gboolean ret = FALSE;
+ GMainLoop *event_loop;
+
+ /* Set up the thread�s context and run it forever. */
+ g_main_context_push_thread_default (event_thread_context);
+
+ event_loop = g_main_loop_new (event_thread_context, FALSE);
+ do {
+ ret = oal_lib_init(NULL);
+ if(ret == FALSE)
+ BT_WARN("oal_lib_init failed, trying again...");
+ } while(ret == FALSE);
+
+ g_main_loop_run (event_loop);
+ g_main_loop_unref (event_loop);
+
+ g_main_context_pop_thread_default (event_thread_context);
+ g_main_context_unref (event_thread_context);
+
+ return NULL;
+}
+
+static void event_data_free(event_t *event_info)
+{
+ if(event_info->event_data)
+ g_free (event_info->event_data);
+ g_slice_free (event_t, event_info);
+}
+
+/* Convert an idle callback into a call to dispatch_idle(). */
+static gboolean dispatch_idle (gpointer user_data)
+{
+ event_t *event_info = user_data;
+ BT_DBG("+");
+
+ if (!event_handler_cb) {
+ BT_ERR("Upstream handler not registered");
+ } else
+ (*event_handler_cb) (event_info->event, event_info->event_data);
+
+ BT_DBG("-");
+ return G_SOURCE_REMOVE;
+}
+
+static gboolean need_same_context(oal_event_t event)
+{
+ gboolean ret;
+
+ switch(event) {
+ default:
+ ret = FALSE;
+ break;
+ }
+ return ret;
+}
+
+void _bt_event_dispatcher_init(oal_event_callback cb)
+{
+ event_handler_cb = cb;
+ BT_DBG("+");
+ /* Spawn a background thread and pass it a reference to its
+ * GMainContext. Retain a reference for use in this thread
+ * too. */
+ event_thread_context = g_main_context_new ();
+ g_thread_new ("OALEventScheduler", __event_handler_loop, NULL);
+}
+
+void send_event_no_trace(oal_event_t event, gpointer event_data)
+{
+ event_t *event_info;
+
+ /* Create a data closure to pass all the desired variables
+ * between threads. */
+ event_info = g_slice_new0 (event_t);
+ event_info->event = event;
+ event_info->event_data = event_data;
+ /* Invoke the function. */
+
+ if (need_same_context(event)) {
+ BT_INFO("Without context change");
+ dispatch_idle(event_info);
+ event_data_free(event_info);
+ } else
+ g_main_context_invoke_full (event_thread_context,
+ G_PRIORITY_DEFAULT, dispatch_idle,
+ event_info,
+ (GDestroyNotify) event_data_free);
+}
+
+void send_event_bda_trace(oal_event_t event, gpointer event_data, bt_address_t *address)
+{
+ send_event_no_trace(event, event_data);
+}
+
+void send_event(oal_event_t event, gpointer event_data)
+{
+ send_event_bda_trace(event, event_data, NULL);
+}
+#undef _OAL_EVENT_DISPATCHER_C_
--- /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 <stdlib.h>
+#include <stdio.h>
+
+#include <dlog.h>
+#include <string.h>
+#include <bluetooth.h>
+#include "oal-utils.h"
+
+char *bdt_bd2str(const bt_address_t *bdaddr, bdstr_t *bdstr)
+{
+ const uint8_t *addr = bdaddr->addr;
+
+ if(bdaddr == NULL) {
+ *bdstr[0] = 0;
+ return *bdstr;
+ }
+
+ snprintf(*bdstr, sizeof(bdstr_t), "%02x:%02x:%02x:%02x:%02x:%02x",
+ addr[0], addr[1], addr[2],
+ addr[3], addr[4], addr[5]);
+ return *bdstr;
+}
+
+void string_to_uuid(char *str, service_uuid_t *p_uuid)
+{
+ uint32_t uuid0, uuid4;
+ uint16_t uuid1, uuid2, uuid3, uuid5;
+
+ sscanf(str, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
+ &uuid0, &uuid1, &uuid2, &uuid3, &uuid4, &uuid5);
+
+ uuid0 = htonl(uuid0);
+ uuid1 = htons(uuid1);
+ uuid2 = htons(uuid2);
+ uuid3 = htons(uuid3);
+ uuid4 = htonl(uuid4);
+ uuid5 = htons(uuid5);
+
+ memcpy(&(p_uuid->uuid[0]), &uuid0, 4);
+ memcpy(&(p_uuid->uuid[4]), &uuid1, 2);
+ memcpy(&(p_uuid->uuid[6]), &uuid2, 2);
+ memcpy(&(p_uuid->uuid[8]), &uuid3, 2);
+ memcpy(&(p_uuid->uuid[10]), &uuid4, 4);
+ memcpy(&(p_uuid->uuid[14]), &uuid5, 2);
+
+ return;
+}
+
+void oal_print_device_address_t(const bt_address_t *addr)
+{
+ BT_INFO("%2.2X:%2.2X:%2.2X:%2.2X:%2.2X:%2.2X\n", addr->addr[0], addr->addr[1], addr->addr[2],
+ addr->addr[3], addr->addr[4], addr->addr[5]);
+}
+
+void oal_convert_addr_string_to_type(unsigned char *addr,
+ const char *address)
+{
+ int i;
+ char *ptr = NULL;
+
+ for (i = 0; i < BT_ADDRESS_BYTES_NUM; i++) {
+ addr[i] = strtol(address, &ptr, 16);
+ if (ptr != NULL) {
+ if (ptr[0] != ':')
+ return;
+ address = ptr + 1;
+ }
+ }
+}
+
+int oal_is_address_zero(unsigned char *addr1)
+{
+ int i;
+ for(i = 0; i < BT_ADDRESS_BYTES_NUM; i++) {
+ if(addr1[i] == 0){
+ continue;
+ }
+ break;
+ }
+ if(i == BT_ADDRESS_BYTES_NUM)
+ return 1;
+ else
+ return 0;
+}
+
+void uuid_to_string(service_uuid_t *p_uuid, char *str)
+{
+ uint32_t uuid0, uuid4;
+ uint16_t uuid1, uuid2, uuid3, uuid5;
+
+ memcpy(&uuid0, &(p_uuid->uuid[0]), 4);
+ memcpy(&uuid1, &(p_uuid->uuid[4]), 2);
+ memcpy(&uuid2, &(p_uuid->uuid[6]), 2);
+ memcpy(&uuid3, &(p_uuid->uuid[8]), 2);
+ memcpy(&uuid4, &(p_uuid->uuid[10]), 4);
+ memcpy(&uuid5, &(p_uuid->uuid[14]), 2);
+
+ snprintf((char *)str, BT_UUID_STRING_MAX, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
+ ntohl(uuid0), ntohs(uuid1),
+ ntohs(uuid2), ntohs(uuid3),
+ ntohl(uuid4), ntohs(uuid5));
+}
+
+
+static int hex2bin( const char *s )
+{
+ int ret=0;
+ int i;
+ for( i=0; i<2; i++ )
+ {
+ char c = *s++;
+ int n=0;
+ if( '0'<=c && c<='9' )
+ n = c-'0';
+ else if( 'a'<=c && c<='f' )
+ n = 10 + c-'a';
+ else if( 'A'<=c && c<='F' )
+ n = 10 + c-'A';
+ ret = n + ret*16;
+ }
+ return ret;
+}
+
+void convert_str_2_hex(char out[],char in[])
+{
+ int i=0;
+ for(i=0; i<62; i++) {
+ out[i] = hex2bin( in ); \
+ in += 2; \
+ }
+}
+
+void convert_hex_2_str(char * hex, int len, char * str_out)
+{
+ int i = 0;
+
+ for(i=0;i<len;i++) {
+ snprintf(str_out + (i * 3),3*(len - i),"%02x ", hex[i]);
+ }
+ str_out[3*len] = 0;
+}
--- /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_UTILS_H_
+#define _OAL_UTILS_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stdint.h>
+#include <arpa/inet.h>
+
+#include <sys/types.h>
+#include "oal-internal.h"
+
+
+#define MENU_PRINT_ERROR(format, arg...) MENUPRINT(RED(format), ##arg)
+
+#define RED(text) "\033[31m"text"\033[0m"
+#define BLUE(text) "\033[34m"text"\033[0m"
+#define YELLOW(text) "\033[33m"text"\033[0m"
+#define GREEN(text) "\033[32m"text"\033[0m"
+#define MAGENTA(text) "\033[35m"text"\033[0m"
+#define CYAN(text) "\033[36m"text"\033[0m"
+
+typedef char bdstr_t[18];
+
+/* Common/util functions */
+char *bdt_bd2str(const bt_address_t *bdaddr, bdstr_t *bdstr);
+void string_to_uuid(char *str, service_uuid_t *p_uuid);
+void uuid_to_string(service_uuid_t *p_uuid, char *str);
+void oal_print_device_address_t(const bt_address_t *addr);
+void oal_convert_addr_string_to_type(unsigned char *addr, const char *address);
+int oal_is_address_zero(unsigned char *addr1);
+void convert_str_2_hex(char out[],char in[]);
+void convert_hex_2_str(char * hex, int len, char * str_out);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_UTILS_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_ADAPTER_MGR_H_
+#define _OAL_ADAPTER_MGR_H_
+
+#include <glib.h>
+#include <sys/types.h>
+
+#include <oal-manager.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define OAL_BT_ADDRESS_STRING_SIZE 18
+
+
+/**
+ * @brief Enable BT chip for usage.
+ *
+ * @remarks Other API can only be used after successful event. \n
+ *
+ * @details EVENT: OAL_EVENT_ADAPTER_ENABLED/OAL_EVENT_ADAPTER_DISABLED
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre OAL API must be initialized with oal_bt_init().
+ *
+ * @see adapter_disable()
+ */
+oal_status_t adapter_enable(void);
+
+
+/**
+ * @brief Disable Adapter.
+ *
+ * @remarks Disables the BT stack and chip. After this, no OAL API is valid except "adapter_enable()"
+ *
+ * @details EVENT: OAL_EVENT_ADAPTER_DISABLED
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
+ *
+ * @see adapter_enable()
+ */
+oal_status_t adapter_disable(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_ADAPTER_MGR_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 <stdint.h>
+
+#ifndef _OAL_EVENT_H_
+#define _OAL_EVENT_H_
+
+#include <glib.h>
+#include <sys/types.h>
+
+#include <oal-manager.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define FOREACH_EVENT(EVENT) \
+ EVENT(OAL_EVENT_ADAPTER_ENABLED) \
+ EVENT(OAL_EVENT_ADAPTER_DISABLED) \
+ EVENT(OAL_EVENT_ADAPTER_HARDWARE_ERROR) \
+ EVENT(OAL_EVENT_ADAPTER_PROPERTY_ADDRESS) /* bt_address_t */ \
+ EVENT(OAL_EVENT_ADAPTER_PROPERTY_NAME) /* char string */\
+ EVENT(OAL_EVENT_ADAPTER_PROPERTY_SERVICES) /* event_adapter_services_t */\
+ EVENT(OAL_EVENT_ADAPTER_MODE_NON_CONNECTABLE) \
+ EVENT(OAL_EVENT_ADAPTER_MODE_CONNECTABLE) \
+ EVENT(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE) \
+ EVENT(OAL_EVENT_ADAPTER_MODE_DISCOVERABLE_TIMEOUT) /* uint32_t */\
+ EVENT(OAL_EVENT_ADAPTER_BONDED_DEVICE_LIST) /* event_device_list_t */\
+ EVENT(OAL_EVENT_ADAPTER_INQUIRY_STARTED) \
+ EVENT(OAL_EVENT_ADAPTER_INQUIRY_RESULT_BREDR_ONLY) /* event_dev_found_t */\
+ EVENT(OAL_EVENT_ADAPTER_INQUIRY_RESULT_BLE) /* event_ble_dev_found_t */\
+ EVENT(OAL_EVENT_ADAPTER_INQUIRY_FINISHED) \
+ EVENT(OAL_EVENT_DEVICE_PROPERTIES) /* remote_device_t */\
+ EVENT(OAL_EVENT_DEVICE_NAME) /* remote_device_t */\
+ EVENT(OAL_EVENT_DEVICE_VIDPID) /* remote_device_t */\
+ EVENT(OAL_EVENT_DEVICE_SERVICES) /* event_dev_services_t */\
+ EVENT(OAL_EVENT_DEVICE_PIN_REQUEST) /* remote_device_t */\
+ EVENT(OAL_EVENT_DEVICE_PASSKEY_ENTRY_REQUEST) /* remote_device_t */\
+ EVENT(OAL_EVENT_DEVICE_PASSKEY_CONFIRMATION_REQUEST)/* event_dev_passkey_t */\
+ EVENT(OAL_EVENT_DEVICE_PASSKEY_DISPLAY) /* event_dev_passkey_t */\
+ EVENT(OAL_EVENT_DEVICE_SSP_CONSENT_REQUEST) /* remote_device_t */\
+ EVENT(OAL_EVENT_DEVICE_BONDING_SUCCESS) /* bt_address_t */\
+ EVENT(OAL_EVENT_DEVICE_BONDING_REMOVED) /* bt_address_t */\
+ EVENT(OAL_EVENT_DEVICE_BONDING_FAILED) /* event_dev_bond_failed_t */\
+ EVENT(OAL_EVENT_DEVICE_AUTHORIZE_REQUEST) /* event_dev_authorize_req_t */\
+ EVENT(OAL_EVENT_DEVICE_ACL_CONNECTED) /* bt_address_t */\
+ EVENT(OAL_EVENT_DEVICE_ACL_DISCONNECTED) /* bt_address_t */\
+ EVENT(OAL_EVENT_OAL_INITIALISED_SUCCESS) /* OAL Initialisation event */ \
+ EVENT(OAL_EVENT_OAL_INITIALISED_FAILED) /* OAL Initialisation event */ \
+ EVENT(OAL_EVENT_END) /* End of event*/\
+
+
+#define GENERATE_ENUM(ENUM) ENUM,
+#define GENERATE_STRING(STRING) #STRING,
+
+typedef enum EVENT_ENUM {
+ FOREACH_EVENT(GENERATE_ENUM)
+} oal_event_t;
+
+#ifdef _OAL_EVENT_DISPATCHER_C_
+const char *str_event[] = {
+ FOREACH_EVENT(GENERATE_STRING)
+};
+#else
+extern const char *str_event[];
+#endif
+
+/*********Datastructures for Local Adapter events ******************/
+typedef struct {
+ int num;
+ bt_address_t devices[0];
+} event_device_list_t;
+
+typedef struct {
+ remote_device_t device_info;
+ uint8_t adv_data[62];
+ int adv_len;
+} event_ble_dev_found_t;
+
+typedef struct {
+ remote_device_t device_info;
+} event_dev_found_t;
+
+typedef struct {
+ int num;
+ service_uuid_t service_list[0];
+} event_adapter_services_t;
+
+
+/*********Datastructures for Remote Device events ******************/
+typedef struct {
+ bt_address_t address;
+ int num;
+ service_uuid_t service_list[0];
+} event_dev_services_t;
+
+typedef struct {
+ remote_device_t device_info;
+ uint32_t pass_key;
+} event_dev_passkey_t;
+
+typedef struct {
+ bt_address_t address;
+ oal_service_t service_id;
+} event_dev_authorize_req_t;
+
+typedef struct {
+ bt_address_t address;
+ oal_status_t status;
+} event_dev_conn_status_t;
+
+typedef event_dev_conn_status_t event_dev_bond_failed_t;
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_EVENT_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_HARDWARE_H_
+#define _OAL_HARDWARE_H_
+
+#include <sys/types.h>
+#include <oal-manager.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define FOREACH_TYPE(FUNC) \
+ FUNC(BT_CHIP_TYPE_PLATFORM, "Tizen Plaftrom BT Chip") \
+ FUNC(BT_CHIP_TYPE_UNKNOWN, "Unknown Chip Type") \
+
+#define GENERATE_TYPE_ENUM(ENUM, STRING) ENUM,
+#define GENERATE_TYPE_STRING(ENUM, STRING) STRING,
+
+typedef enum {
+ FOREACH_TYPE(GENERATE_TYPE_ENUM)
+} bt_chip_type_t;
+
+/**
+ * @brief Upgrade BT Chip Firmware.
+ *
+ * @remarks BT Chip will be reset and oal will start again after upgrade. \n
+ *
+ * @details EVENT: N/A. as this is a blocking call
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise OAL_STATUS_INTERNAL_ERROR.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ * #OAL_STATUS_INTERNAL_ERROR Failure
+ *
+ * @pre N/A, as this is related to hardware, oal need not be initialised.
+ *
+ * @see -
+ */
+oal_status_t hw_chip_firmware_update(void);
+
+/**
+ * @brief Check whether BT chip is connected or not.
+ *
+ * @remarks BT Chip state. \n
+ *
+ * @details EVENT: N/A.
+ *
+ * @return TRUE if chip connected, otherwise FALSE.
+ * @retval #TRUE Successful
+ *
+ * @pre N/A, as this is related to hardware, oal need not be initialised.
+ *
+ * @see -
+ */
+int hw_is_chip_connected(void);
+
+/**
+ * @brief Get Connected BT Chip Type. (Single/Combo)
+ *
+ * @remarks BT Chip Type. \n
+ *
+ * @details EVENT: N/A
+ *
+ * @return BT_CHIP_TYPE_SINGLE if Single BT Chip connected,
+ * BT_CHIP_TYPE_COMBO if BT Combo Chip connected,
+ * otherwise BT_CHIP_TYPE_UNKNOWN on error.
+ * @retval #BT_CHIP_TYPE_SINGLE Single-BT Chip
+ *
+ * @pre N/A, as this is related to hardware, oal need not be initialised.
+ *
+ * @see -
+ */
+bt_chip_type_t hw_get_chip_type(void);
+
+/**
+ * @brief Get driver state.
+ *
+ * @remarks BT Module State \n
+ *
+ * @details EVENT: N/A
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise OAL_STATUS_INTERNAL_ERROR.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ * #OAL_STATUS_INTERNAL_ERROR Failure
+ *
+ * @pre N/A, as this is related to hardware, oal need not be initialised.
+ *
+ * @see -
+ */
+oal_status_t hw_is_module_ready(void);
+
+/**
+ * @brief Firmware Upgrade Required Status
+ *
+ * @remarks whether upgrade firmwares required or not \n
+ * *is_required = TRUE, if upgrade required, else FALSE
+ *
+ * @details EVENT: N/A
+ *
+ * @return OAL_STATUS_SUCCESS
+ *
+ * @pre N/A
+ *
+ * @see N/A
+ */
+oal_status_t hw_is_fwupgrade_required(gboolean *is_required);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_HARDWARE_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_MANAGER_H_
+#define _OAL_MANAGER_H_
+
+#include <glib.h>
+#include <stdint.h>
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define BT_DEVICE_NAME_LENGTH_MAX 248 /**< This specifies maximum device name length */
+
+#define BT_ADDRESS_BYTES_NUM 6 /**< This specifies bluetooth device address length */
+
+#define OAL_UUID_MAX_LENGTH 16/**< This specifies ble service UUID Length */
+
+#define BLE_ADV_DATA_LENGTH 62 /**< This specifies Advertising Data Length */
+
+#define BT_ADDRESS_STR_LEN 18 /**< BT address String length> */
+
+#define BT_MAX_SERVICES_FOR_DEVICE 60 /**< This specifies the Maximum UUID Id mentioned in bta_api.h>*/
+
+#define BLUETOOTH_UUID_STRING_MAX 50
+
+typedef void (*oal_event_callback)(int event, gpointer event_data);
+
+typedef struct {
+ unsigned char addr[BT_ADDRESS_BYTES_NUM];
+} bt_address_t;
+
+typedef struct {
+ char name[BT_DEVICE_NAME_LENGTH_MAX + 1];
+} bt_name_t;
+
+typedef enum {
+ OAL_STATUS_SUCCESS,
+ /* Generic */
+ OAL_STATUS_INTERNAL_ERROR,
+ OAL_STATUS_NOT_READY,
+ OAL_STATUS_BUSY,
+ OAL_STATUS_INVALID_PARAM,
+ OAL_STATUS_RMT_DEVICE_DOWN,
+ OAL_STATUS_AUTH_FAILED,
+ OAL_STATUS_NOT_SUPPORT, //For APIs not supported
+ OAL_STATUS_ALREADY_DONE,
+ OAL_STATUS_PENDING,
+ OAL_STATUS_CONN_TIMEOUT,
+ /* HID */
+ OAL_STATUS_HID_FAILED_MOUSE
+} oal_status_t;
+
+
+
+/* NOTE: If anything changes in bt_service_id_t enum definition of Bluedroid header, change here too */
+typedef enum {
+ A2DP_SRC_SERVICE_ID = 3,
+ AVRCP_CT_SERVICE_ID = 9,
+ A2DP_SERVICE_ID = 18,
+ AVRCP_SERVICE_ID = 19,
+ HID_SERVICE_ID = 20
+} oal_service_t;
+
+/** Bluetooth 128-bit UUID */
+typedef struct {
+ uint8_t uuid[16];
+} oal_uuid_t;
+
+typedef oal_uuid_t service_uuid_t;
+
+typedef enum {
+ DEV_TYPE_BREDR,
+ DEV_TYPE_BLE_ONLY,
+ DEV_TYPE_DUAL
+} device_type_t;
+
+
+typedef struct {
+ char name[BT_DEVICE_NAME_LENGTH_MAX+1];
+ bt_address_t address;
+ int cod;
+ int rssi;
+ int vid;
+ int pid;
+ int is_bonded;
+ int is_connected;
+ device_type_t type;
+ int uuid_count;
+ oal_uuid_t uuid[BT_MAX_SERVICES_FOR_DEVICE];
+} remote_device_t;
+
+/**
+ * @brief Initializes OAL layer
+ *
+ * @remarks Other API can only be used after successful return. \n
+ *
+ * @details EVENT: N/A
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre N/A
+ *
+ * @see oal_bt_deinit()
+ */
+oal_status_t oal_bt_init(oal_event_callback cb);
+
+/**
+ * @brief Deinitializes OAL Layer
+ *
+ * @remarks Other API can only be used after oal_bt_init done again. \n
+ *
+ * @details EVENT: N/A
+ *
+ * @return void.
+ * @retval void
+ *
+ * @pre N/A
+ *
+ * @see oal_bt_init()
+ */
+void oal_bt_deinit(void);
+
+/**
+ * @brief Initialize Stack lib based on chip
+ *
+ * @remarks Other API can only be used after oal_lib_init done. \n
+ *
+ * @details EVENT: OAL_EVENT_OAL_INITIALISED_SUCCESS, OAL_EVENT_OAL_INITIALISED_FAILED
+ *
+ * @return bool.
+ * @retval bool
+ *
+ * @pre N/A
+ *
+ * @see N/A
+ */
+gboolean oal_lib_init(gpointer data);
+
+/**
+ * @brief Set Debug Mode Flag to TRUE
+ *
+ * @remarks OAL will run in exclusive mode, no processing of api-call and no event sending. \n
+ *
+ * @details EVENT: N/A
+ *
+ * @return void
+ * @retval void
+ *
+ * @pre N/A
+ *
+ * @see oal_get_debug_mode()
+ */
+void oal_set_debug_mode(gboolean mode);
+
+/**
+ * @brief Set Debug Mode Flag
+ *
+ * @remarks To check whether Debug mode is running. \n
+ *
+ * @details EVENT: N/A
+ *
+ * @return TRUE if debug mode is on, otherwise FALSE
+ * @retval #TRUE Successful
+ *
+ * @pre N/A
+ *
+ * @see oal_set_debug_mode()
+ */
+gboolean oal_get_debug_mode(void);
+
+#ifdef OAL_DEBUG
+/**
+ * @brief Register the debug mode event catcher
+ *
+ * @remarks handles the incoming events and passes to debug handler. \n
+ *
+ * @details EVENT: N/A
+ *
+ * @return void
+ * @retval void
+ *
+ * @pre N/A
+ *
+ * @see N/A
+ */
+void server_event_catch_register(oal_event_callback dbg_cb);
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_HARDWARE_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 <stdlib.h>
+#include <dlog.h>
+#include <string.h>
+#include <vconf.h>
+#include <sys/wait.h>
+
+#include <bluetooth.h>
+
+#include "oal-event.h"
+#include "oal-internal.h"
+#include "oal-manager.h"
+#include "oal-hardware.h"
+
+#define CHECK_MAX(max, x) (((max) > (x)) ? (x) : (max))
+
+static const bt_interface_t * blued_api;
+
+/* Forward declarations */
+const char * status2string(bt_status_t status);
+oal_status_t convert_to_oal_status(bt_status_t status);
+void parse_device_properties(int num_properties, bt_property_t *properties,
+ remote_device_t *dev_info, ble_adv_data_t * adv_info);
+oal_status_t oal_mgr_init_internal(void);
+
+static bt_callbacks_t callbacks = {
+ sizeof(callbacks),
+ NULL, /* adapter_state_changed_callback */
+ NULL, /* adapter_properties_callback */
+ NULL, /* remote_device_properties_callback */
+ NULL, /* device_found_callback */
+ NULL, /* discovery_state_changed_callback */
+ NULL, /* pin_request_callback */
+ NULL, /* ssp_request_callback */
+ NULL, /* bond_state_changed_callback */
+ NULL, /* acl_state_changed_callback */
+ NULL, /* callback_thread_event */
+ NULL, /* dut_mode_recv_callback */
+ NULL, /* le_test_mode_callback*/
+ NULL, /* energy_info_callback */
+};
+
+oal_status_t adapter_mgr_init(const bt_interface_t * stack_if)
+{
+ int ret;
+ blued_api = stack_if;
+
+ ret = blued_api->init(&callbacks);
+
+ if(ret != BT_STATUS_SUCCESS) {
+ BT_ERR("Adapter callback registration failed: [%s]", status2string(ret));
+ blued_api->cleanup();
+ return convert_to_oal_status(ret);
+ }
+
+ return OAL_STATUS_SUCCESS;
+}
+
+const bt_interface_t* adapter_get_stack_interface(void)
+{
+ return blued_api;
+}
+
+void adapter_mgr_cleanup(void)
+{
+ /* Nothing to clean yet , do not set blued_api NULL as it will be used to clean Bluedroid states */
+ BT_DBG();
+}
+
--- /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 <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <tzplatform_config.h>
+
+#include "oal-hardware.h"
+#include "oal-manager.h"
+#include "oal-internal.h"
+
+#define MAX_LINE_SIZE 256
+#define MAX_STRING_SIZE 128
+
+static bt_chip_type_t try_get_chip_type(void);
+
+static bt_chip_type_t bt_chip_type = BT_CHIP_TYPE_PLATFORM;
+
+const unsigned int nBTVidPidArry[][3] = { /**< list of BT dongle's vid, pid */
+ /* { Vendor ID, Product ID, Chip Vendor } */
+ {0x0000, 0x0001, BT_CHIP_TYPE_PLATFORM}, /* Tizen Platform BT Chip */
+};
+
+static const char *str_chip_type[] = {
+ FOREACH_TYPE(GENERATE_TYPE_STRING)
+};
+
+int hw_is_chip_connected()
+{
+ /* Currently not supported, return TRUE as default */
+ return TRUE;
+}
+
+bt_chip_type_t hw_get_chip_type(void)
+{
+ bt_chip_type_t type;
+
+ type = ((bt_chip_type != BT_CHIP_TYPE_UNKNOWN) ? bt_chip_type : try_get_chip_type());
+
+ API_TRACE("Type: %s", str_chip_type[type]);
+ return type;
+}
+
+oal_status_t hw_chip_firmware_update(void)
+{
+ return OAL_STATUS_NOT_SUPPORT;
+}
+
+oal_status_t hw_is_module_ready(void)
+{
+ /* For Tizen Platform, set HW module ready to TRUE by default */
+ return OAL_STATUS_SUCCESS;
+}
+
+oal_status_t hw_is_fwupgrade_required(gboolean *is_required)
+{
+ return OAL_STATUS_NOT_SUPPORT;
+}
+
+static bt_chip_type_t try_get_chip_type(void)
+{
+ return bt_chip_type;
+}
+
--- /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_INTERNAL_H_
+#define _OAL_INTERNAL_H_
+
+#include <glib.h>
+#include <sys/types.h>
+#include <dlog.h>
+#include <bluetooth.h>
+
+#include <oal-event.h>
+#include "oal-manager.h"
+#include "oal-utils.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define OAL_VERSION_STR "Samsung OAL Version v0.1"
+
+#define PR_TASK_PERF_USER_TRACE 666
+#define BT_ADDRESS_STRING_SIZE 18
+#define BT_UUID_STRING_MAX 50
+
+#undef LOG_TAG
+#define LOG_TAG "BT_OAL"
+
+#define BT_DBG(fmt, args...) \
+ LOGD(fmt, ##args)
+#define BT_ERR(fmt, args...) \
+ LOGE(RED(fmt), ##args);
+#define BT_INFO(fmt, args...) \
+ LOGI(fmt, ##args)
+#define BT_VBS(fmt, args...) \
+ {SLOGI(fmt, ##args);LOGI(fmt, ##args);}
+#define BT_WARN(fmt, args...) \
+ LOGW(YELLOW(fmt), ##args)
+#define NO_SUPP_CHK(status, fmt, args...) do {\
+ if(status == BT_STATUS_UNSUPPORTED) \
+ BT_WARN(fmt, ##args); \
+ else \
+ BT_ERR(fmt, ##args); \
+ } while(0)
+
+
+#define API_TRACE(fmt, args...) {LOG_(LOG_ID_SYSTEM, DLOG_INFO, "OAL_API", GREEN(fmt), ##args); \
+ LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, GREEN("[OAL_API]"fmt), ##args);}
+
+#define send_event_trace(e,d,a, fmt, args...) do {\
+ bdstr_t bdstr;\
+ send_event_no_trace(e, d); \
+ LOG_(LOG_ID_SYSTEM, DLOG_INFO, "OAL_EVENT", GREEN(fmt" [%s] %s"), ##args, bdt_bd2str(a, &bdstr), str_event[event]); \
+ LOG_(LOG_ID_MAIN, DLOG_INFO, LOG_TAG, GREEN("[OAL_EVENT]"fmt" [%s] %s"), ##args, bdt_bd2str(a, &bdstr), str_event[event]);\
+ } while(0)
+
+
+#define ret_if(expr) \
+ do { \
+ if (expr) { \
+ BT_ERR("(%s) return", #expr); \
+ return; \
+ } \
+ } while (0)
+
+#define retv_if(expr, val) \
+ do { \
+ if (expr) { \
+ BT_ERR("(%s) return", #expr); \
+ return (val); \
+ } \
+ } while (0)
+
+#define OAL_CHECK_PARAMETER(arg, func) \
+ do { \
+ if (arg == NULL) \
+ { \
+ BT_ERR("INVALID PARAMETER"); \
+ func OAL_STATUS_INVALID_PARAM; \
+ } \
+ } while (0)
+
+#define CHECK_OAL_INITIALIZED() \
+ do { \
+ if (blued_api == NULL) { \
+ BT_ERR("OAL Not Initialized"); \
+ return OAL_STATUS_NOT_READY; \
+ } \
+ } while (0)
+
+#define BT_ADDRESS_STRING_SIZE 18
+
+typedef struct {
+ int len;
+ uint8_t * adv_data;
+} ble_adv_data_t;
+
+/* Adapter manager */
+void oal_mgr_cleanup(void);
+void oal_mgr_stack_reload(void);
+
+oal_status_t adapter_mgr_init(const bt_interface_t * stack_if);
+
+/* Event Manager */
+/* Use this when Address is to be printed */
+void send_event_bda_trace(oal_event_t event, gpointer event_data, bt_address_t *address);
+
+/* Use this when no address printing is required */
+#define _bt_dispatch_event send_event
+void send_event(oal_event_t event, gpointer event_data);
+void _bt_event_dispatcher_init(oal_event_callback cb);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_OAL_HARDWARE_H_*/
+
--- /dev/null
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2012-2013 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 <vconf.h>
+#include <sys/prctl.h>
+#include <unistd.h>
+#include <dlfcn.h>
+
+#include <bluetooth.h>
+
+#include "oal-internal.h"
+#include "oal-event.h"
+#include <oal-hardware.h>
+
+#define BT_HAL_LIB_NAME "libbluetooth.default.so"
+#define HAL_LIBRARY_PATH "/usr/lib"
+#define LIB_PATH_SIZE 50
+#define LIB_NAME_SIZE 50
+
+static const hw_module_t* module = NULL;
+static const bt_interface_t *blued_api = NULL;
+
+static gboolean unload_libs(gpointer data);
+static bluetooth_device_t* load_hal_lib(void);
+static const bt_interface_t * get_stack_interface(bluetooth_device_t* bt_device);
+static int load(const char *libname, const struct hw_module_t **module);
+static int unload(const struct hw_module_t *module);
+
+oal_status_t oal_mgr_init_internal(void)
+{
+ bluetooth_device_t* bt_device;
+
+ bt_device = load_hal_lib();
+
+ if (bt_device == NULL) {
+ BT_ERR("HAL Library loading failed");
+ return OAL_STATUS_INTERNAL_ERROR;
+ }
+
+ blued_api = get_stack_interface(bt_device);
+
+ if (blued_api == NULL) {
+ BT_ERR("Stack Interface failed");
+ return OAL_STATUS_INTERNAL_ERROR;
+ }
+
+ return adapter_mgr_init(blued_api);
+}
+
+oal_status_t oal_bt_init(oal_event_callback cb)
+{
+ API_TRACE("Version: %s", OAL_VERSION_STR);
+ _bt_event_dispatcher_init(cb);
+ return OAL_STATUS_PENDING;
+}
+
+void oal_bt_deinit(void)
+{
+ BT_INFO("+");
+ blued_api->cleanup();
+ blued_api = NULL;
+ unload_libs(NULL);
+ BT_INFO("-");
+}
+
+void oal_mgr_cleanup(void)
+{
+ /*TODO Unsupported */
+}
+
+void oal_mgr_stack_reload(void)
+{
+ /*TODO Unsupported */
+}
+
+gboolean oal_lib_init(gpointer data)
+{
+ oal_status_t ret;
+ BT_INFO("Going to check Chip Attachment...");
+
+ if (hw_is_module_ready() == OAL_STATUS_SUCCESS) {
+ if(hw_get_chip_type() == BT_CHIP_TYPE_UNKNOWN) {
+ BT_DBG("Chip Type Unknown, starting timer...");
+ } else {
+ ret = oal_mgr_init_internal();
+ if(OAL_STATUS_SUCCESS == ret)
+ send_event(OAL_EVENT_OAL_INITIALISED_SUCCESS, NULL);
+ else
+ send_event(OAL_EVENT_OAL_INITIALISED_FAILED, NULL);
+ }
+ } else {
+ BT_DBG("Chip Not Yet Ready, try again...");
+ return FALSE;
+ }
+ return TRUE;
+}
+
+static gboolean unload_libs(gpointer data)
+{
+ unload((hw_module_t const*)module);
+ module = NULL;
+ return FALSE;
+}
+
+static bluetooth_device_t* load_hal_lib(void)
+{
+ int err = 0;
+ hw_device_t* device;
+ bluetooth_device_t* bt_device = NULL;
+
+ BT_DBG("Loading HAL lib");
+ if (module == NULL) {
+ switch(hw_get_chip_type()) {
+ case BT_CHIP_TYPE_PLATFORM:
+ BT_INFO("Tizen Platform BT chip: Tizen Platform HAL library will be loaded");
+ err = load(BT_HAL_LIB_NAME, (const hw_module_t **)&module);
+ break;
+ default:
+ BT_WARN("Chip type Unknown, So no Library Load");
+ err = -EINVAL;
+ break;
+ }
+ } else
+ BT_WARN("Lib already loaded");
+
+ if (err == 0) {
+ err = module->methods->open(module, BT_HARDWARE_MODULE_ID, &device);
+ if (err == 0) {
+ bt_device = (bluetooth_device_t *)device;
+ BT_INFO("HAL Library loaded successfullly");
+ }
+ }
+
+ if (err != 0)
+ BT_INFO("%d", err);
+ return bt_device;
+}
+
+static const bt_interface_t * get_stack_interface(bluetooth_device_t* bt_device)
+{
+ const bt_interface_t *blued_api = NULL;
+ /* Get the Bluetooth interface */
+ blued_api = bt_device->get_bluetooth_interface();
+
+ return blued_api;
+}
+
+static int load(const char *libname, const struct hw_module_t **module)
+{
+ int status = -ENOENT;
+ char libpath[LIB_PATH_SIZE];
+ void *handle;
+ struct hw_module_t *hmi;
+
+ OAL_CHECK_PARAMETER(libname, return);
+
+ snprintf(libpath, sizeof(libpath), "%s/%s", HAL_LIBRARY_PATH, libname);
+ BT_INFO("Loading Library: %s", libpath);
+
+ /*
+ * load the symbols resolving undefined symbols before
+ * dlopen returns. Since RTLD_GLOBAL is not or'd in with
+ * RTLD_NOW the external symbols will not be global
+ */
+
+ prctl(666, "[bt-service] Load Lib S", strlen("[bt-service] Load Lib S"));
+
+ handle = dlopen(libpath, RTLD_NOW);
+ if (handle == NULL) {
+ char const *err_str = dlerror();
+ BT_ERR("load: module=%s\n%s", libpath, err_str?err_str:"unknown");
+ status = -EINVAL;
+ goto done;
+ }
+
+ prctl(666, "[bt-service] Load Lib E", strlen("[bt-service] Load Lib E"));
+
+ /* Get the address of the struct hal_module_info. */
+ const char *sym = HAL_MODULE_INFO_SYM_AS_STR;
+ hmi = (struct hw_module_t *)dlsym(handle, sym);
+ if (hmi == NULL) {
+ BT_ERR("load: couldn't find symbol %s", sym);
+ status = -EINVAL;
+ goto done;
+ }
+
+ /* Check that the id matches */
+ if (strcmp(BT_HARDWARE_MODULE_ID, hmi->id) != 0) {
+ BT_ERR("load: id=%s != hmi->id=%s", BT_HARDWARE_MODULE_ID, hmi->id);
+ status = -EINVAL;
+ goto done;
+ }
+
+ hmi->dso = handle;
+ status = 0;
+
+done:
+ if (status != 0) {
+ hmi = NULL;
+ if (handle != NULL) {
+ dlclose(handle);
+ handle = NULL;
+ }
+ } else {
+ BT_DBG("loaded HAL id=%s libpath=%s hmi=%p handle=%p",
+ BT_HARDWARE_MODULE_ID, libpath, hmi, handle);
+ }
+ *module = hmi;
+ return status;
+}
+
+static int unload(const struct hw_module_t *module)
+{
+ int ret = 1;
+
+ if(module)
+ ret = dlclose(module->dso);
+
+ if(ret != 0)
+ {
+ BT_ERR("dlclose failed:%d", ret);
+ }
+ BT_WARN("Issues with dl: %s\n", dlerror());
+ return ret;
+}
+
+void oal_set_debug_mode(gboolean mode)
+{
+ /*TODO Unsupported */
+}
+
+gboolean oal_get_debug_mode(void)
+{
+ /*TODO Unsupported */
+ return FALSE;
+}
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(bt-service C)
-#ADD_SUBDIRECTORY(hal_lib)
-
#Include Source files for bluetooth service common files only
SET(SRCS
marshal.c
./services/bt-service-event-sender.c
./services/bt-service-util.c
./services/bt-request-handler.c
+./services/adapter/bt-service-core-adapter.c
+./services/bt-service-event-receiver.c
)
-IF(LIBNOTIFY_SUPPORT)
-LIST(APPEND SRCS
-bt-popup.c
-)
-ENDIF(LIBNOTIFY_SUPPORT)
-
-IF(LIBNOTIFICATION_SUPPORT)
-LIST(APPEND SRCS
-bt-service-agent-notification.c
-)
-ENDIF(LIBNOTIFICATION_SUPPORT)
-
IF("${CMAKE_BUILD_TYPE}" STREQUAL "")
SET(CMAKE_BUILD_TYPE "Release")
ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/services/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal/include)
+LINK_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../bt-oal)
+
SET(PKG_MODULES
vconf
aul
EXEC_PROGRAM("${MARSHALTOOL}" ARGS "--prefix=marshal ${CMAKE_CURRENT_SOURCE_DIR}/marshal.list --body > ${CMAKE_CURRENT_SOURCE_DIR}/marshal.c")
FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool)
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=bt ${CMAKE_CURRENT_SOURCE_DIR}/bt-request-service.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-service-method.h")
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=bt_obex_agent ${CMAKE_CURRENT_SOURCE_DIR}/bt-service-obex-agent.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-obex-agent-method.h")
-
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=gap_agent ${CMAKE_CURRENT_SOURCE_DIR}/bt-service-gap-agent1.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-gap-agent-method.h")
-
-#EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=bt_media_agent ${CMAKE_CURRENT_SOURCE_DIR}/bt-service-media-agent.xml --mode=glib-server --output=${CMAKE_CURRENT_SOURCE_DIR}/include/bt-media-agent-method.h")
ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
ADD_DEFINITIONS("-DVENDOR=\"${APP_VENDOR}\"")
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS})
-TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS})
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS} -lbt-oal)
-# to permit usage of bluetooth_cancel_bonding in bt-popup.c. This build bluetooth-api first.
-IF(LIBNOTIFY_SUPPORT)
- ADD_DEPENDENCIES(${PROJECT_NAME} bluetooth-api)
- TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS} bluetooth-api)
-ELSE(LIBNOTIFY_SUPPORT)
- TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${service_pkgs_LDFLAGS})
-ENDIF(LIBNOTIFY_SUPPORT)
-
-#CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.bt.service.in ${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.bt.service)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/org.projectx.bt.service DESTINATION share/dbus-1/system-services)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION bin)
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth-frwk-service.conf DESTINATION /etc/dbus-1/system.d)
+TARGET_LINK_LIBRARIES(${PROJECT_NAME} -ldl)
+
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
--- /dev/null
+/*
+ * Copyright (c) 2015 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Anupam Roy <anupam.r@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 <gio/gio.h>
+#include <glib.h>
+#include <dlog.h>
+#include <string.h>
+#include <vconf.h>
+#include <vconf-internal-keys.h>
+#include <syspopup_caller.h>
+#include <aul.h>
+#include <eventsystem.h>
+#include <bundle_internal.h>
+
+/*bt-service headers */
+#include "bt-internal-types.h"
+#include "bt-service-common.h"
+#include "bt-service-util.h"
+#include "bt-service-main.h"
+#include "bt-service-core-adapter.h"
+#include "bt-service-event-receiver.h"
+#include "bt-request-handler.h"
+#include "bt-service-event.h"
+
+/* OAL headers */
+#include <oal-event.h>
+#include <oal-manager.h>
+#include <oal-adapter-mgr.h>
+
+#define BT_ENABLE_TIMEOUT 20000 /* 20 seconds */
+
+/*This file will contain state machines related to adapter and remote device */
+
+/* Forward declarations */
+static void __bt_adapter_event_handler(int event_type, gpointer event_data);
+static void __bt_post_oal_init(void);
+static void __bt_handle_oal_initialisation(oal_event_t event);
+
+/* Initialize BT stack (Initialize OAL layer) */
+int _bt_stack_init(void)
+{
+ int ret;
+
+ BT_INFO("[bt-service] Start to initialize BT stack");
+ /* Adapter enable request is successful, setup event handlers */
+ _bt_service_register_event_handler_callback(
+ BT_ADAPTER_MODULE, __bt_adapter_event_handler);
+
+ ret = oal_bt_init(_bt_service_oal_event_receiver);
+
+ if (OAL_STATUS_PENDING == ret) {
+ BT_INFO("OAL Initialisation Pending, Profiles Init will be done once oal initialised...");
+ return BLUETOOTH_ERROR_NONE;
+ } else if (OAL_STATUS_SUCCESS != ret) {
+ _bt_service_unregister_event_handler_callback(BT_ADAPTER_MODULE);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ __bt_post_oal_init();
+ return BLUETOOTH_ERROR_NONE;
+}
+
+static void __bt_adapter_event_handler(int event_type, gpointer event_data)
+{
+ BT_DBG("");
+
+ switch(event_type) {
+ case OAL_EVENT_OAL_INITIALISED_SUCCESS:
+ case OAL_EVENT_OAL_INITIALISED_FAILED:
+ __bt_handle_oal_initialisation(event_type);
+ break;
+ default:
+ BT_ERR("Unhandled event..");
+ break;
+ }
+}
+
+/* OAL post initialization handler */
+static void __bt_post_oal_init(void)
+{
+ BT_DBG("OAL initialized, Init profiles..");
+ /*TODO */
+ return;
+}
+
+/* OAL initialization handler */
+static void __bt_handle_oal_initialisation(oal_event_t event)
+{
+ BT_DBG("");
+
+ switch(event) {
+ case OAL_EVENT_OAL_INITIALISED_SUCCESS:
+ __bt_post_oal_init();
+ break;
+ case OAL_EVENT_OAL_INITIALISED_FAILED:
+ BT_ERR("OAL Initialisation Failed, terminate bt-service daemon..");
+ g_idle_add(_bt_terminate_service, NULL);
+ break;
+ default:
+ BT_ERR("Unknown Event");
+ break;
+ }
+}
#include "bt-service-common.h"
#include "bt-service-util.h"
+#include "bt-service-core-adapter.h"
+
+/* For maintaining Application Sync API call requests */
+GSList *invocation_list = NULL;
+
static GDBusConnection *bt_service_conn;
static guint owner_id = 0;
cynara *p_cynara;
const char *unique_name);
/* Function definitions*/
-static void __bt_fill_garray_from_variant(GVariant *var, GArray *param)
+GSList *_bt_get_invocation_list(void)
+{
+ return invocation_list;
+}
+
+void _bt_free_info_from_invocation_list(invocation_info_t *req_info)
{
- char *data;
- int size;
+ GSList *l;
+ invocation_info_t *info;
- size = g_variant_get_size(var);
- if (size > 0) {
- data = (char *)g_variant_get_data(var);
- if (data)
- param = g_array_append_vals(param, data, size);
+ for (l = invocation_list; l != NULL; l = g_slist_next(l)) {
+ info = l->data;
+ if (info == NULL)
+ continue;
+ /* No two same sync requests from same application can exist */
+ if ((strcasecmp(info->sender, req_info->sender) == 0) &&
+ req_info->service_function == info->service_function) {
+
+ invocation_list = g_slist_remove(invocation_list, req_info);
+ g_free(req_info);
+ break;
+ }
}
+
}
-static void __bt_service_get_parameters(GVariant *in_param,
- void *value, int size)
+/*TODO:Following function will be used in subsequent patch, so ignore warning for now */
+static gboolean __bt_is_sync_function(int service_function)
{
- void *buf = NULL;
- buf = (void *)g_variant_get_data(in_param);
- memcpy(value, buf, size);
+ /*TODO: Keep adding sync methods with expect replies from bluetooth service */
+ if (service_function == BT_GET_LOCAL_ADDRESS
+ || service_function == BT_GET_LOCAL_NAME
+ || service_function == BT_GET_LOCAL_VERSION
+ || service_function == BT_GET_BONDED_DEVICES
+ || service_function == BT_GET_BONDED_DEVICE
+ || service_function == BT_IS_SERVICE_USED)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
+ char *sender, int service_function,
+ gpointer invocation_data)
+{
+ BT_DBG("Saving the invocation context: service_function [%d]", service_function);
+ invocation_info_t *info;
+ info = g_malloc0(sizeof(invocation_info_t));
+ info->context = invocation;
+ info->result = result;
+ info->sender = sender;
+ info->service_function = service_function;
+ info->user_data = invocation_data;
+ invocation_list = g_slist_append(invocation_list, info);
+
}
static void __bt_service_method(GDBusConnection *connection,
int result = BLUETOOTH_ERROR_NONE;
switch (function_name) {
- case BT_ENABLE_ADAPTER:
- /*TODO*/
- break;
- case BT_DISABLE_ADAPTER:
- /*TODO*/
- break;
+ default:
+ BT_INFO("UnSupported function [%d]", function_name);
+ result = BLUETOOTH_ERROR_NOT_SUPPORT;
+ break;
}
return result;
conf = NULL;
}
+void _bt_service_method_return(GDBusMethodInvocation *invocation,
+ GArray *out_param, int result)
+{
+ GVariant *out_var;
+ BT_DBG("+");
+ out_var = g_variant_new_from_data((const GVariantType *)"ay",
+ out_param->data, out_param->len, TRUE, NULL, NULL);
+
+ g_dbus_method_invocation_return_value(invocation,
+ g_variant_new("(iv)", result, out_var));
+ BT_DBG("-");
+}
--- /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.
+ *
+ */
+
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <dbus/dbus.h>
+#include <glib.h>
+#include <string.h>
+#include <dlog.h>
+#include <vconf.h>
+#include <vconf-internal-bt-keys.h>
+
+#include <oal-event.h>
+
+#include "bt-service-common.h"
+#include "bt-service-event-receiver.h"
+
+_bt_service_event_handler_callback adapter_cb;
+
+void _bt_service_register_event_handler_callback(
+ bt_service_module_t module, _bt_service_event_handler_callback cb)
+{
+ switch(module) {
+ case BT_ADAPTER_MODULE:
+ BT_INFO("Register BT_ADAPTER_MODULE Callback");
+ adapter_cb = cb;
+ break;
+ default:
+ BT_INFO("Unknown module");
+ }
+}
+
+void _bt_service_unregister_event_handler_callback(bt_service_module_t module)
+{
+ switch(module) {
+ case BT_ADAPTER_MODULE:
+ BT_INFO("Un-Register BT_ADAPTER_MODULE Callback");
+ adapter_cb = NULL;
+ break;
+ default:
+ BT_INFO("Unknown module");
+ }
+}
+
+void _bt_service_oal_event_receiver(int event_type, gpointer event_data)
+{
+ BT_INFO("event_type: [%d]", event_type);
+
+ switch(event_type) {
+ case OAL_EVENT_OAL_INITIALISED_SUCCESS:
+ case OAL_EVENT_OAL_INITIALISED_FAILED:
+ if (adapter_cb)
+ adapter_cb(event_type, event_data);
+ break;
+ default:
+ BT_ERR("Unhandled Event: %d", event_type);
+ break;
+ }
+}
#include "bt-service-event.h"
#include "bt-service-util.h"
+#include "bt-service-core-adapter.h"
+
+/* OAL headers */
+#include <oal-event.h>
+#include <oal-manager.h>
+
static GMainLoop *main_loop;
static gboolean terminated = FALSE;
gboolean _bt_terminate_service(gpointer user_data)
{
- /* TODO*/
- return FALSE;
+ BT_INFO("+");
+ if (main_loop != NULL) {
+ g_main_loop_quit(main_loop);
+ } else {
+ BT_DBG("main_loop == NULL");
+ }
+
+ terminated = TRUE;
+ BT_INFO("-");
+ return FALSE;
}
gboolean _bt_reliable_terminate_service(gpointer user_data)
/* TODO*/
}
-static int __bt_service_load_hal_lib(void)
-{
- int ret = BLUETOOTH_ERROR_NONE;
- BT_INFO("+");
- /* TODO: Pass oal event receiver handler */
- return ret;
-}
-
int main(void)
{
struct sigaction sa;
_bt_init_request_list();
- /* BT HAL library Load */
- BT_ERR("Attempt to load BT HAL lib");
- if (__bt_service_load_hal_lib() != BLUETOOTH_ERROR_NONE) {
- BT_ERR("Fail to initialize BT HAL");
+
+ /* BT Stack Init */
+ if (_bt_stack_init() != BLUETOOTH_ERROR_NONE) {
+ BT_ERR("Fail to init BT Stack");
return 0;
}
#define BT_SERVICE_NAME "org.projectx.bt"
#define BT_SERVICE_PATH "/org/projectx/bt_service"
+/* Invocation information structure for API's
++ expecting replies from bluetooth service */
+typedef struct {
+ char * sender;
+ int service_function;
+ GDBusMethodInvocation *context;
+ int result;
+ gpointer user_data;
+} invocation_info_t;
+
+GSList *_bt_get_invocation_list(void);
+
+void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
+ char *sender, int service_function,
+ gpointer invocation_data);
+
+void _bt_free_info_from_invocation_list(invocation_info_t *req_info);
+
int _bt_service_register(void);
void _bt_service_unregister(void);
void _bt_service_cynara_deinit(void);
+void _bt_service_method_return(GDBusMethodInvocation *invocation,
+ GArray *out_param, int result);
#ifdef __cplusplus
}
#endif /* __cplusplus */
--- /dev/null
+/*
+ * Copyright (c) 2015 - 2016 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: Anupam Roy <anupam.r@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_CORE_ADAPTER_H_
+#define _BT_SERVICE_CORE_ADAPTER_H_
+
+#include <sys/types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int _bt_stack_init(void);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /*_BT_SERVICE_CORE_ADAPTER_H_*/
+
--- /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_EVENT_RECEIVER_H_
+#define _BT_SERVICE_EVENT_RECEIVER_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef void (*_bt_service_event_handler_callback) (int event_type, gpointer event_data);
+
+typedef enum {
+ BT_ADAPTER_MODULE,
+} bt_service_module_t;
+
+void _bt_service_oal_event_receiver(int event_type, gpointer event_data);
+void _bt_service_register_event_handler_callback(
+ bt_service_module_t module, _bt_service_event_handler_callback cb);
+void _bt_service_unregister_event_handler_callback(bt_service_module_t module);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* _BT_SERVICE_EVENT_RECEIVER_H_ */
%define _varlibdir /opt/var/lib
Name: bluetooth-frwk
-Summary: Bluetooth framework for BlueZ and Obexd. This package is Bluetooth framework based on BlueZ and Obexd stack.
+Summary: Bluetooth framework for BlueZ and Obexd.
Version: 0.2.151
Release: 1
Group: Network & Connectivity/Bluetooth
%package httpproxy
Summary: Bluetooth HTTP Proxy Service daemon
-Group: TO_BE/FILLED
+Group: Network & Connectivity/Bluetooth
Requires: %{name} = %{version}-%{release}
%description httpproxy
%description test
This package is Bluetooth test application.
+%if %{bt_hal} == ENABLED
+%package oal
+Summary: Bluetooth OAL
+Group: Network & Connectivity/Bluetooth
+Requires: %{name} = %{version}-%{release}
+
+%description oal
+This package is BT stack common interface.
+%endif
+
%prep
%setup -q
cp %{SOURCE1001} .
#%attr(0666,-,-) %{_varlibdir}/bluetooth/auto-pair-blacklist
#%attr(0666,-,-) %{_prefix}/etc/bluetooth/stack_info
#%{_dumpdir}/bluetooth_log_dump.sh
+
+
%{_datadir}/license/bluetooth-frwk-service
%if %{with bluetooth_frwk_libnotify} || %{with bluetooth_frwk_libnotification}
%{_datadir}/icons/default/bt-icon.png
%{_bindir}/bluetooth-frwk-test
%{_bindir}/bluetooth-gatt-test
%{_bindir}/bluetooth-advertising-test
+
+%if %{bt_hal} == ENABLED
+%files oal
+%{_libdir}/libbt-oal.so*
+%{_libdir}/libbluetooth.default.so*
+%endif