diff options
Diffstat (limited to 'btif/src/bluetooth.c')
-rw-r--r-- | btif/src/bluetooth.c | 381 |
1 files changed, 381 insertions, 0 deletions
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c new file mode 100644 index 0000000..766f685 --- /dev/null +++ b/btif/src/bluetooth.c @@ -0,0 +1,381 @@ +/************************************************************************************ + * + * Copyright (C) 2009-2012 Broadcom Corporation + * + * This program is the proprietary software of Broadcom Corporation and/or its + * licensors, and may only be used, duplicated, modified or distributed + * pursuant to the terms and conditions of a separate, written license + * agreement executed between you and Broadcom (an "Authorized License"). + * Except as set forth in an Authorized License, Broadcom grants no license + * (express or implied), right to use, or waiver of any kind with respect to + * the Software, and Broadcom expressly reserves all rights in and to the + * Software and all intellectual property rights therein. + * IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE NO RIGHT TO USE THIS + * SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY BROADCOM AND DISCONTINUE + * ALL USE OF THE SOFTWARE. + * + * Except as expressly set forth in the Authorized License, + * + * 1. This program, including its structure, sequence and organization, + * constitutes the valuable trade secrets of Broadcom, and you shall + * use all reasonable efforts to protect the confidentiality thereof, + * and to use this information only in connection with your use of + * Broadcom integrated circuit products. + * + * 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED + * "AS IS" AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, + * REPRESENTATIONS OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, + * OR OTHERWISE, WITH RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY + * DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, + * NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, + * ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR + * CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT + * OF USE OR PERFORMANCE OF THE SOFTWARE. + * + * 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR + * ITS LICENSORS BE LIABLE FOR + * (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR EXEMPLARY + * DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO + * YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM + * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; OR + * (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE + * SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE + * LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF + * ESSENTIAL PURPOSE OF ANY LIMITED REMEDY. + * + ************************************************************************************/ + +/************************************************************************************ + * + * Filename: bluetooth.c + * + * Description: Bluetooth HAL implementation + * + ***********************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <hardware/bluetooth.h> +#include <hardware/bt_hf.h> + +#define LOG_NDDEBUG 0 +#define LOG_TAG "bluedroid" + +#include "btif_api.h" + +/************************************************************************************ +** Constants & Macros +************************************************************************************/ + +#define is_profile(profile, str) ((strlen(str) == strlen(profile)) && strncmp((const char *)profile, str, strlen(str)) == 0) + +/************************************************************************************ +** Local type definitions +************************************************************************************/ + +/************************************************************************************ +** Static variables +************************************************************************************/ + +bt_callbacks_t *bt_hal_cbacks = NULL; + +/************************************************************************************ +** Static functions +************************************************************************************/ + +/************************************************************************************ +** Externs +************************************************************************************/ + +/* list all extended interfaces here */ + +/* handsfree profile */ +extern bthf_interface_t *btif_hf_get_interface(); + +/************************************************************************************ +** Functions +************************************************************************************/ + +static uint8_t interface_ready(void) +{ + /* add checks here that would prevent API calls other than init to be executed */ + if (bt_hal_cbacks == NULL) + return FALSE; + + return TRUE; +} + + +/***************************************************************************** +** +** BLUETOOTH HAL INTERFACE FUNCTIONS +** +*****************************************************************************/ + +static int init(bt_callbacks_t* callbacks ) +{ + LOGI("init"); + + /* store reference to user callbacks */ + bt_hal_cbacks = callbacks; + + /* add checks for individual callbacks ? */ + + /* init btif */ + btif_init_bluetooth(); + + return BT_STATUS_SUCCESS; +} + +static int enable( void ) +{ + LOGI("enable"); + + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_enable_bluetooth(); +} + +static int disable(void) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_disable_bluetooth(); +} + +static void cleanup( void ) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return; + + btif_shutdown_bluetooth(); + + /* hal callbacks reset upon shutdown complete callback */ + + return; +} + +static int get_adapter_properties(void) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_get_adapter_properties(); +} + +static int get_adapter_property(bt_property_type_t type) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_get_adapter_property(type); +} + +static int set_adapter_property(const bt_property_t *property) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_set_adapter_property(property); +} + +int get_remote_device_properties(bt_bdaddr_t *remote_addr) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_get_remote_device_properties(remote_addr); +} + +int get_remote_device_property(bt_bdaddr_t *remote_addr, bt_property_type_t type) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_get_remote_device_property(remote_addr, type); +} + +int set_remote_device_property(bt_bdaddr_t *remote_addr, const bt_property_t *property) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_set_remote_device_property(remote_addr, property); +} + +int get_remote_service_record(bt_bdaddr_t *remote_addr, bt_uuid_t *uuid) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_get_remote_service_record(remote_addr, uuid); +} + +static int start_discovery(void) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_start_discovery(); +} + +static int cancel_discovery(void) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_cancel_discovery(); +} + +static int create_bond(const bt_bdaddr_t *bd_addr) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_create_bond(bd_addr); +} + +static int cancel_bond(const bt_bdaddr_t *bd_addr) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_cancel_bond(bd_addr); +} + +static int remove_bond(const bt_bdaddr_t *bd_addr) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_remove_bond(bd_addr); +} + +static int pin_reply(const bt_bdaddr_t *bd_addr, uint8_t accept, + uint8_t pin_len, bt_pin_code_t *pin_code) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_pin_reply(bd_addr, accept, pin_len, pin_code); +} + +static int passkey_reply(const bt_bdaddr_t *bd_addr, uint8_t accept, + uint32_t passkey) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_passkey_reply(bd_addr, accept, passkey); +} + +static int ssp_reply(const bt_bdaddr_t *bd_addr, uint8_t accept) +{ + /* sanity check */ + if (interface_ready() == FALSE) + return BT_STATUS_NOT_READY; + + return btif_dm_ssp_reply(bd_addr, accept); +} + +static const void* get_profile_interface (const char *profile_id) +{ + LOGI("get_profile_interface %s", profile_id); + + /* check for supported profile interfaces */ + if (is_profile(profile_id, BT_PROFILE_HANDSFREE_ID)) + return btif_hf_get_interface(); + + if (is_profile(profile_id, BT_PROFILE_ADVANCED_AUDIO_ID)) + return NULL; + + return NULL; +} + +static const bt_interface_t bluetoothInterface = { + sizeof(bt_interface_t), + init, + enable, + disable, + cleanup, + get_adapter_properties, + get_adapter_property, + set_adapter_property, + get_remote_device_properties, + get_remote_device_property, + set_remote_device_property, + get_remote_service_record, + start_discovery, + cancel_discovery, + create_bond, + remove_bond, + cancel_bond, + pin_reply, + passkey_reply, + ssp_reply, + get_profile_interface +}; + +const bt_interface_t* bluetooth__get_bluetooth_interface () +{ + /* fixme -- add property to disable bt interface ? */ + + return &bluetoothInterface; +} + +static int close_bluetooth_stack(struct hw_device_t* device) +{ + cleanup(); + return 0; +} + +static int open_bluetooth_stack (const struct hw_module_t* module, char const* name, +struct hw_device_t** abstraction) +{ + bluetooth_device_t *stack = malloc(sizeof(bluetooth_device_t) ); + memset(stack, 0, sizeof(bluetooth_device_t) ); + stack->common.tag = HARDWARE_DEVICE_TAG; + stack->common.version = 0; + stack->common.module = (struct hw_module_t*)module; + stack->common.close = close_bluetooth_stack; + stack->get_bluetooth_interface = bluetooth__get_bluetooth_interface; + *abstraction = (struct hw_device_t*)stack; + return 0; +} + + +static struct hw_module_methods_t bt_stack_module_methods = { + .open = open_bluetooth_stack, +}; + +const 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 = "The Android Open Source Project", + .methods = &bt_stack_module_methods +}; + |