diff options
author | Andre Eisenbach <andre@broadcom.com> | 2012-02-22 13:18:21 -0800 |
---|---|---|
committer | Matthew Xie <mattx@google.com> | 2012-07-14 11:19:11 -0700 |
commit | e448862a47c08eb23185aaed574b39264f5005fc (patch) | |
tree | 2bc6246e3091315e77224fd798ea2fe8074ef972 /btif/co | |
parent | a2ca4b83ab8bbbfd8d5f6693e927ed4b82094624 (diff) | |
download | external_bluetooth_bluedroid-e448862a47c08eb23185aaed574b39264f5005fc.zip external_bluetooth_bluedroid-e448862a47c08eb23185aaed574b39264f5005fc.tar.gz external_bluetooth_bluedroid-e448862a47c08eb23185aaed574b39264f5005fc.tar.bz2 |
Initial Bluedroid stack commit
Diffstat (limited to 'btif/co')
-rw-r--r-- | btif/co/bta_ag_co.c | 161 | ||||
-rw-r--r-- | btif/co/bta_dm_co.c | 424 | ||||
-rw-r--r-- | btif/co/bta_fs_co.c | 1212 | ||||
-rw-r--r-- | btif/co/bta_sys_co.c | 86 |
4 files changed, 1883 insertions, 0 deletions
diff --git a/btif/co/bta_ag_co.c b/btif/co/bta_ag_co.c new file mode 100644 index 0000000..ec1d5bb --- /dev/null +++ b/btif/co/bta_ag_co.c @@ -0,0 +1,161 @@ +/************************************************************************************ + * + * Copyright (C) 2009-2011 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. + * + ************************************************************************************/ +#include "gki.h" +#include "bta_api.h" +#include "bta_sys.h" +#include "bta_ag_api.h" +#include "bta_ag_co.h" +#include "bte_appl.h" + +#define LOG_TAG "BTA_AG_CO: " + +#ifndef LINUX_NATIVE +#include <cutils/properties.h> +#include <cutils/log.h> +#else +#include <stdio.h> +#define LOGI(format, ...) fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__) +#define LOGD(format, ...) fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__) +#define LOGV(format, ...) fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__) +#define LOGE(format, ...) fprintf (stderr, LOG_TAG format"\n", ## __VA_ARGS__) +#endif + + +/******************************************************************************* +** +** Function bta_ag_co_init +** +** Description This callout function is executed by AG when it is +** started by calling BTA_AgEnable(). This function can be +** used by the phone to initialize audio paths or for other +** initialization purposes. +** +** +** Returns Void. +** +*******************************************************************************/ +void bta_ag_co_init(void) +{ + BTM_WriteVoiceSettings(AG_VOICE_SETTINGS); +} + + +/******************************************************************************* +** +** Function bta_ag_co_audio_state +** +** Description This function is called by the AG before the audio connection +** is brought up, after it comes up, and after it goes down. +** +** Parameters handle - handle of the AG instance +** state - Audio state +** BTA_AG_CO_AUD_STATE_OFF - Audio has been turned off +** BTA_AG_CO_AUD_STATE_OFF_XFER - Audio has been turned off (xfer) +** BTA_AG_CO_AUD_STATE_ON - Audio has been turned on +** BTA_AG_CO_AUD_STATE_SETUP - Audio is about to be turned on +** +** Returns void +** +*******************************************************************************/ +void bta_ag_co_audio_state(UINT16 handle, UINT8 app_id, UINT8 state) +{ + BTIF_TRACE_DEBUG2("bta_ag_co_audio_state: handle %d, state %d", handle, state); +} + + +/******************************************************************************* +** +** Function bta_ag_co_data_open +** +** Description This function is executed by AG when a service level connection +** is opened. The phone can use this function to set +** up data paths or perform any required initialization or +** set up particular to the connected service. +** +** +** Returns void +** +*******************************************************************************/ +void bta_ag_co_data_open(UINT16 handle, tBTA_SERVICE_ID service) +{ + BTIF_TRACE_DEBUG2("bta_ag_co_data_open handle:%d service:%d", handle, service); +} + +/******************************************************************************* +** +** Function bta_ag_co_data_close +** +** Description This function is called by AG when a service level +** connection is closed +** +** +** Returns void +** +*******************************************************************************/ +void bta_ag_co_data_close(UINT16 handle) +{ + BTIF_TRACE_DEBUG1("bta_ag_co_data_close handle:%d", handle); +} + + +/******************************************************************************* + ** + ** Function bta_ag_co_tx_write + ** + ** Description This function is called by the AG to send data to the + ** phone when the AG is configured for AT command pass-through. + ** The implementation of this function must copy the data to + ** the phones memory. + ** + ** Returns void + ** + *******************************************************************************/ +void bta_ag_co_tx_write(UINT16 handle, UINT8 * p_data, UINT16 len) +{ + BTIF_TRACE_DEBUG2( "bta_ag_co_tx_write: handle: %d, len: %d", handle, len ); +} + diff --git a/btif/co/bta_dm_co.c b/btif/co/bta_dm_co.c new file mode 100644 index 0000000..b4c893c --- /dev/null +++ b/btif/co/bta_dm_co.c @@ -0,0 +1,424 @@ +/************************************************************************************ + * + * Copyright (C) 2009-2011 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. + * + ************************************************************************************/ +#include <stdio.h> +#include <stdlib.h> + +#include "bta_api.h" +#include "bta_sys.h" +#include "bta_dm_co.h" +#include "bta_dm_ci.h" + + +/******************************************************************************* +** +** Function bta_dm_co_get_compress_memory +** +** Description This callout function is executed by DM to get memory for compression + +** Parameters id - BTA SYS ID +** memory_p - memory return by callout +** memory_size - memory size +** +** Returns TRUE for success, FALSE for fail. +** +*******************************************************************************/ +BOOLEAN bta_dm_co_get_compress_memory(tBTA_SYS_ID id, UINT8 **memory_p, UINT32 *memory_size) +{ + return TRUE; +} + +/******************************************************************************* +** +** Function bta_dm_co_io_req +** +** Description This callout function is executed by DM to get IO capabilities +** of the local device for the Simple Pairing process +** +** Parameters bd_addr - The peer device +** *p_io_cap - The local Input/Output capabilities +** *p_oob_data - TRUE, if OOB data is available for the peer device. +** *p_auth_req - TRUE, if MITM protection is required. +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, tBTA_OOB_DATA *p_oob_data, + tBTA_AUTH_REQ *p_auth_req, BOOLEAN is_orig) +{ +} + +/******************************************************************************* +** +** Function bta_dm_co_io_rsp +** +** Description This callout function is executed by DM to report IO capabilities +** of the peer device for the Simple Pairing process +** +** Parameters bd_addr - The peer device +** io_cap - The remote Input/Output capabilities +** oob_data - TRUE, if OOB data is available for the peer device. +** auth_req - TRUE, if MITM protection is required. +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_io_rsp(BD_ADDR bd_addr, tBTA_IO_CAP io_cap, + tBTA_OOB_DATA oob_data, tBTA_AUTH_REQ auth_req) +{ +} + +/******************************************************************************* +** +** Function bta_dm_co_lk_upgrade +** +** Description This callout function is executed by DM to check if the +** platform wants allow link key upgrade +** +** Parameters bd_addr - The peer device +** *p_upgrade - TRUE, if link key upgrade is desired. +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_lk_upgrade(BD_ADDR bd_addr, BOOLEAN *p_upgrade ) +{ +} + +#if (BTM_OOB_INCLUDED == TRUE) +/******************************************************************************* +** +** Function bta_dm_co_loc_oob +** +** Description This callout function is executed by DM to report the OOB +** data of the local device for the Simple Pairing process +** +** Parameters valid - TRUE, if the local OOB data is retrieved from LM +** c - Simple Pairing Hash C +** r - Simple Pairing Randomnizer R +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_loc_oob(BOOLEAN valid, BT_OCTET16 c, BT_OCTET16 r) +{ +} + +/******************************************************************************* +** +** Function bta_dm_co_rmt_oob +** +** Description This callout function is executed by DM to request the OOB +** data for the remote device for the Simple Pairing process +** Need to call bta_dm_ci_rmt_oob() in response +** +** Parameters bd_addr - The peer device +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_rmt_oob(BD_ADDR bd_addr) +{ +} + +#endif /* BTM_OOB_INCLUDED */ + + +// REMOVE FOR BLUEDROID ? + +#if (BTM_SCO_HCI_INCLUDED == TRUE ) && (BTM_SCO_INCLUDED == TRUE) + +/******************************************************************************* +** +** Function btui_sco_codec_callback +** +** Description Callback for btui codec. +** +** +** Returns void +** +*******************************************************************************/ +static void btui_sco_codec_callback(UINT16 event, UINT16 sco_handle) +{ + bta_dm_sco_ci_data_ready(event, sco_handle); +} +/******************************************************************************* +** +** Function bta_dm_sco_co_init +** +** Description This function can be used by the phone to initialize audio +** codec or for other initialization purposes before SCO connection +** is opened. +** +** +** Returns tBTA_DM_SCO_ROUTE_TYPE: SCO routing configuration type. +** +*******************************************************************************/ +tBTA_DM_SCO_ROUTE_TYPE bta_dm_sco_co_init(UINT32 rx_bw, UINT32 tx_bw, + tBTA_CODEC_INFO * p_codec_type, UINT8 app_id) +{ + tBTM_SCO_ROUTE_TYPE route = BTA_DM_SCO_ROUTE_PCM; + + BTIF_TRACE_DEBUG0("bta_dm_sco_co_init"); + + /* set up SCO routing configuration if SCO over HCI app ID is used and run time + configuration is set to SCO over HCI */ + /* HS invoke this call-out */ + if ( +#if (BTA_HS_INCLUDED == TRUE ) && (BTA_HS_INCLUDED == TRUE) + (app_id == BTUI_DM_SCO_4_HS_APP_ID && btui_cfg.hs_sco_over_hci) || +#endif + /* AG invoke this call-out */ + (app_id != BTUI_DM_SCO_4_HS_APP_ID && btui_cfg.ag_sco_over_hci )) + { + route = btui_cb.sco_hci = BTA_DM_SCO_ROUTE_HCI; + } + /* no codec is is used for the SCO data */ + if (p_codec_type->codec_type == BTA_SCO_CODEC_PCM && route == BTA_DM_SCO_ROUTE_HCI) + { + /* initialize SCO codec */ + if (!btui_sco_codec_init(rx_bw, tx_bw)) + { + BTIF_TRACE_ERROR0("codec initialization exception!"); + } + } + + return route; +} + + + +/******************************************************************************* +** +** Function bta_dm_sco_co_open +** +** Description This function is executed when a SCO connection is open. +** +** +** Returns void +** +*******************************************************************************/ +void bta_dm_sco_co_open(UINT16 handle, UINT8 pkt_size, UINT16 event) +{ + tBTUI_SCO_CODEC_CFG cfg; + + if (btui_cb.sco_hci) + { + BTIF_TRACE_DEBUG2("bta_dm_sco_co_open handle:%d pkt_size:%d", handle, pkt_size); + /* use dedicated SCO buffer pool for SCO TX data */ + cfg.pool_id = HCI_SCO_POOL_ID; + cfg.p_cback = btui_sco_codec_callback; + cfg.pkt_size = pkt_size; + cfg.cb_event = event; + /* open and start the codec */ + btui_sco_codec_open(&cfg); + btui_sco_codec_start(handle); + } +} + +/******************************************************************************* +** +** Function bta_dm_sco_co_close +** +** Description This function is called when a SCO connection is closed +** +** +** Returns void +** +*******************************************************************************/ +void bta_dm_sco_co_close(void) +{ + if (btui_cb.sco_hci) + { + BTIF_TRACE_DEBUG0("bta_dm_sco_co_close close codec"); + /* close sco codec */ + btui_sco_codec_close(); + + btui_cb.sco_hci = FALSE; + } +} + +/******************************************************************************* +** +** Function bta_dm_sco_co_in_data +** +** Description This function is called to send incoming SCO data to application. +** +** Returns void +** +*******************************************************************************/ +void bta_dm_sco_co_in_data(BT_HDR *p_buf) +{ + if (btui_cfg.sco_use_mic) + btui_sco_codec_inqdata (p_buf); + else + GKI_freebuf(p_buf); +} + +/******************************************************************************* +** +** Function bta_dm_sco_co_out_data +** +** Description This function is called to send SCO data over HCI. +** +** Returns void +** +*******************************************************************************/ +void bta_dm_sco_co_out_data(BT_HDR **p_buf) +{ + btui_sco_codec_readbuf(p_buf); +} + +#endif /* #if (BTM_SCO_HCI_INCLUDED == TRUE ) && (BTM_SCO_INCLUDED == TRUE)*/ + + +#if (defined BLE_INCLUDED && BLE_INCLUDED == TRUE) +/******************************************************************************* +** +** Function bta_dm_co_le_io_key_req +** +** Description This callout function is executed by DM to get BLE key information +** before SMP pairing gets going. +** +** Parameters bd_addr - The peer device +** *p_max_key_size - max key size local device supported. +** *p_init_key - initiator keys. +** *p_resp_key - responder keys. +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_le_io_key_req(BD_ADDR bd_addr, UINT8 *p_max_key_size, + tBTA_LE_KEY_TYPE *p_init_key, + tBTA_LE_KEY_TYPE *p_resp_key ) +{ + BTIF_TRACE_ERROR0("##################################"); + BTIF_TRACE_ERROR0("bta_dm_co_le_io_key_req: only setting max size to 16"); + BTIF_TRACE_ERROR0("##################################"); + *p_max_key_size = 16; + *p_init_key = *p_resp_key = + (BTA_LE_KEY_PENC|BTA_LE_KEY_PID|BTA_LE_KEY_PCSRK|BTA_LE_KEY_LENC|BTA_LE_KEY_LID|BTA_LE_KEY_LCSRK); +} + + +/******************************************************************************* +** +** Function bta_dm_co_ble_local_key_reload +** +** Description This callout function is to load the local BLE keys if available +** on the device. +** +** Parameters none +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_ble_load_local_keys(tBTA_DM_BLE_LOCAL_KEY_MASK *p_key_mask, BT_OCTET16 er, + tBTA_BLE_LOCAL_ID_KEYS *p_id_keys) +{ + BTIF_TRACE_ERROR0("##################################"); + BTIF_TRACE_ERROR0("bta_dm_co_ble_load_local_keys: TBD Load local keys if any are persisted"); + BTIF_TRACE_ERROR0("##################################"); +} + +/******************************************************************************* +** +** Function bta_dm_co_ble_io_req +** +** Description This callout function is executed by DM to get BLE IO capabilities +** before SMP pairing gets going. +** +** Parameters bd_addr - The peer device +** *p_io_cap - The local Input/Output capabilities +** *p_oob_data - TRUE, if OOB data is available for the peer device. +** *p_auth_req - Auth request setting (Bonding and MITM required or not) +** *p_max_key_size - max key size local device supported. +** *p_init_key - initiator keys. +** *p_resp_key - responder keys. +** +** Returns void. +** +*******************************************************************************/ +void bta_dm_co_ble_io_req(BD_ADDR bd_addr, tBTA_IO_CAP *p_io_cap, + tBTA_OOB_DATA *p_oob_data, + tBTA_LE_AUTH_REQ *p_auth_req, + UINT8 *p_max_key_size, + tBTA_LE_KEY_TYPE *p_init_key, + tBTA_LE_KEY_TYPE *p_resp_key ) +{ + /* if OOB is not supported, this call-out function does not need to do anything + * otherwise, look for the OOB data associated with the address and set *p_oob_data accordingly + * If the answer can not be obtained right away, + * set *p_oob_data to BTA_OOB_UNKNOWN and call bta_dm_ci_io_req() when the answer is available */ + + /* *p_auth_req by default is FALSE for devices with NoInputNoOutput; TRUE for other devices. */ + BTIF_TRACE_ERROR2("bta_dm_co_ble_io_req. p_auth_req=%d ble_authereq=%d", *p_auth_req, bte_appl_cfg.ble_auth_req); + BTIF_TRACE_ERROR2("bta_dm_co_ble_io_req. p_io_cap=%d ble_io_cap=%d", *p_io_cap, bte_appl_cfg.ble_io_cap); + BTIF_TRACE_ERROR2("bta_dm_co_ble_io_req. p_init_key=%d ble_init_key=%d", *p_init_key, bte_appl_cfg.ble_init_key); + BTIF_TRACE_ERROR2("bta_dm_co_ble_io_req. p_resp_key=%d ble_resp_key=%d", *p_resp_key, bte_appl_cfg.ble_resp_key ); + BTIF_TRACE_ERROR2("bta_dm_co_ble_io_req. p_max_key_size=%d ble_max_key_size=%d", *p_max_key_size, bte_appl_cfg.ble_max_key_size ); + + *p_oob_data = FALSE; + if (bte_appl_cfg.ble_auth_req) + *p_auth_req = bte_appl_cfg.ble_auth_req | (bte_appl_cfg.ble_auth_req & 0x04) | ((*p_auth_req) & 0x04); + + if (bte_appl_cfg.ble_io_cap <=4) + *p_io_cap = bte_appl_cfg.ble_io_cap; + + if (bte_appl_cfg.ble_init_key<=7) + *p_init_key = bte_appl_cfg.ble_init_key; + + if (bte_appl_cfg.ble_resp_key<=7) + *p_resp_key = bte_appl_cfg.ble_resp_key; + + if (bte_appl_cfg.ble_max_key_size<=16) + *p_max_key_size = bte_appl_cfg.ble_max_key_size; + +} + + +#endif + diff --git a/btif/co/bta_fs_co.c b/btif/co/bta_fs_co.c new file mode 100644 index 0000000..9b0ab0a --- /dev/null +++ b/btif/co/bta_fs_co.c @@ -0,0 +1,1212 @@ +/************************************************************************************ + * + * Copyright (C) 2009-2011 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. + * + ************************************************************************************/ +#include <stdio.h> +#include <errno.h> +#include <fcntl.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/statfs.h> +#include <sys/vfs.h> +#include <unistd.h> +#include <dirent.h> +#include <time.h> +#include <limits.h> +#include "gki.h" +#include "bta_fs_co.h" +#include "bta_fs_ci.h" +//#include "btui.h" +//#include "btui_int.h" +#include <inttypes.h> + +#ifndef AID_SYSTEM +#define AID_SYSTEM 1000 +#define AID_BLUETOOTH 1002 +#define AID_SDCARD_RW 1015 +#define AID_MISC 9998 +#endif + +#define FAT_FS 0x4d44 +const unsigned short BT_UID= AID_BLUETOOTH; +const unsigned short BT_GID= AID_BLUETOOTH; + +/* enable additional debugging traces that should be compiled out by default! */ +#ifndef BTA_FS_DEBUG +#define BTA_FS_DEBUG TRUE +#define LOG_TAG "BTA_FS_CO" +#define LOGI(format, ...) fprintf (stdout, LOG_TAG format"\n", ## __VA_ARGS__) +#endif + +#if (defined BTA_PBS_INCLUDED) && (BTA_PBS_INCLUDED == TRUE) +extern const tBTA_PBS_CFG bta_pbs_cfg; +#endif + + + +static int del_path (const char *path) +{ + DIR *dir; + struct dirent *de; + int ret = 0; + char nameBuffer[PATH_MAX] = {0}; + struct stat statBuffer; + BTIF_TRACE_DEBUG1("in del_path for path:%s", path); + dir = opendir(path); + + if (dir == NULL) { + BTIF_TRACE_DEBUG1("opendir failed on path:%s", path); + return -1; + } + + char *filenameOffset; + + strncpy(nameBuffer, path, PATH_MAX - 1); + strcat(nameBuffer, "/"); + int nameLen = strlen(nameBuffer); + filenameOffset = nameBuffer + nameLen; + + for (;;) { + de = readdir(dir); + + if (de == NULL) { + BTIF_TRACE_DEBUG1("readdir failed for path:%s", path); + //ret = -1; + break; + } + + if (0 == strcmp(de->d_name, ".") || 0 == strcmp(de->d_name, "..")) + continue; + + if((int)strlen(de->d_name) > PATH_MAX - nameLen) { + BTIF_TRACE_DEBUG1("d_name len:%d is too big", strlen(de->d_name)); + ret = -1; + break; + } + + strcpy(filenameOffset, de->d_name); + + ret = lstat (nameBuffer, &statBuffer); + + if (ret != 0) { + BTIF_TRACE_DEBUG1("lstat failed for path:%s", nameBuffer); + break; + } + + if(S_ISDIR(statBuffer.st_mode)) { + + ret = del_path(nameBuffer); + if(ret != 0) + break; + } else { + ret = unlink(nameBuffer); + if (ret != 0) { + BTIF_TRACE_DEBUG1("unlink failed for path:%s", nameBuffer); + break; + } + } + } + + closedir(dir); + if(ret == 0) { + ret = rmdir(path); + BTIF_TRACE_DEBUG2("rmdir return:%d for path:%s", ret, path); + } + + return ret; + +} + +inline int getAccess(int accType, struct stat *buffer, char *p_path) +{ + + struct statfs fsbuffer; + int idType; + + if(! buffer) + return BTA_FS_CO_FAIL; + + //idType= (buffer->st_uid== BT_UID) ? 1 : (buffer->st_uid== BT_GID) ? 2 : 3; + if(buffer->st_uid == BT_UID) + idType = 1; + else if(buffer->st_gid == BT_GID || + buffer->st_gid == AID_SYSTEM || + buffer->st_gid == AID_MISC || + buffer->st_gid == AID_SDCARD_RW) + idType = 2; + else idType = 3; + + if(statfs(p_path, &fsbuffer)==0) + { + if(fsbuffer.f_type == FAT_FS) + return BTA_FS_CO_OK; + } + else { + return BTA_FS_CO_FAIL; + } + + switch(accType) { + case 4: + if(idType== 1) { //Id is User Id + if(buffer-> st_mode & S_IRUSR) + return BTA_FS_CO_OK; + } + else if(idType==2) { //Id is Group Id + if(buffer-> st_mode & S_IRGRP) + return BTA_FS_CO_OK; + } + else { //Id is Others + if(buffer-> st_mode & S_IROTH) + return BTA_FS_CO_OK; + } + break; + + case 6: + if(idType== 1) { //Id is User Id + if((buffer-> st_mode & S_IRUSR) && (buffer-> st_mode & S_IWUSR)) + return BTA_FS_CO_OK; + } + else if(idType==2) { //Id is Group Id + if((buffer-> st_mode & S_IRGRP) && (buffer-> st_mode & S_IWGRP)) + return BTA_FS_CO_OK; + } + else { //Id is Others + if((buffer-> st_mode & S_IROTH) && (buffer-> st_mode & S_IWOTH)) + return BTA_FS_CO_OK; + } + break; + + default: + return BTA_FS_CO_OK; + } + BTIF_TRACE_DEBUG0("*************FTP- Access Failed **********"); + return BTA_FS_CO_EACCES; +} + + +/***************************************************************************** +** Function Declarations +*****************************************************************************/ + +/******************************************************************************* +** +** Function bta_fs_convert_oflags +** +** Description This function converts the open flags from BTA into MFS. +** +** Returns BTA FS status value. +** +*******************************************************************************/ +int bta_fs_convert_bta_oflags(int bta_oflags) +{ + int oflags = 0; /* Initially read only */ + + /* Only one of these can be set: Read Only, Read/Write, or Write Only */ + if (bta_oflags & BTA_FS_O_RDWR) + oflags |= O_RDWR; + else if (bta_oflags & BTA_FS_O_WRONLY) + oflags |= O_WRONLY; + + /* OR in any other flags that are set by BTA */ + if (bta_oflags & BTA_FS_O_CREAT) + oflags |= O_CREAT; + + if (bta_oflags & BTA_FS_O_EXCL) + oflags |= O_EXCL; + + if (bta_oflags & BTA_FS_O_TRUNC) + oflags |= O_TRUNC; + + return (oflags); +} + + + +/******************************************************************************* + ** + ** Function btapp_fs_check_space + ** + ** Description determines access and if there is enough space for given files size on given path + ** + ** Parameters p_path - Fully qualified path and file name. + ** WARNING: file name is stripped off! so it must be present! + ** size - size of file to put (0 if unavailable or not applicable) + ** app_id - in case application specific treatement is required (e.g opp versus ftp) + ** Returns 0 if enough space, otherwise errno failure codes + ** + *******************************************************************************/ +static int btapp_fs_check_space( const char *p_path, const UINT32 size, const UINT8 app_id ) +{ + + unsigned long long max_space; + struct statfs fs_buffer; + int err = 0; + char *p_dir; + char *p_end; + + if(size==BTA_FS_LEN_UNKNOWN) + return 0; + /* fail silently in case of no memory. write will catch if not enough space */ + + if (NULL != (p_dir = (char *) GKI_getbuf(strlen(p_path) + 1))) + { + strcpy(p_dir, p_path); + if (NULL != (p_end = strrchr(p_dir, '/'))) + { + + *p_end = '\0'; + /* get fs info and calculate available space. if not enough, the fs error EFBIG is returned */ + + if (0 == statfs(p_dir, &fs_buffer)) + { + + max_space = fs_buffer.f_bavail * fs_buffer.f_bsize; +#if (BTA_FS_DEBUG==TRUE) + BTIF_TRACE_DEBUG2("btapp_fs_enough_space(file size: %d): (uint)max_size: %u", size, (UINT32)max_space); +#endif + if (max_space < size) + err = EFBIG; + } + else + { + err = errno; + BTIF_TRACE_WARNING1("btapp_fs_enough_space(): statfs() failed with err: %d", err); + } + } + else + { + err = ENOENT; + } + GKI_freebuf(p_dir); + } + else + { + err = ENOMEM; + } + return err; + +} /* btapp_fs_check_access_space() */ + + +/******************************************************************************* +** +** Function bta_fs_co_open +** +** Description This function is executed by BTA when a file is opened. +** The phone uses this function to open +** a file for reading or writing. +** +** Parameters p_path - Fully qualified path and file name. +** oflags - permissions and mode (see constants above) +** size - size of file to put (0 if unavailable or not applicable) +** evt - event that must be passed into the call-in function. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +** Note: Upon completion of the request, a file descriptor (int), +** if successful, and an error code (tBTA_FS_CO_STATUS) +** are returned in the call-in function, bta_fs_ci_open(). +** +*******************************************************************************/ + +void bta_fs_co_open(const char *p_path, int oflags, UINT32 size, UINT16 evt, + UINT8 app_id) +{ + + tBTA_FS_CO_STATUS status; + UINT32 file_size = 0; + struct stat file_stat; + int fd = -1; + int err = 0; + + /* Convert BTA oflags into os specific flags */ + oflags = bta_fs_convert_bta_oflags(oflags); + + /* check available space in case of write access. oflags are in OS format! */ + if (oflags & (O_RDWR|O_WRONLY)) + { + err = btapp_fs_check_space(p_path, size, app_id); + } + + if ( 0==err ) + { + if ((fd = open(p_path, oflags | O_NONBLOCK, 0666)) >= 0) + { + if (fstat(fd, &file_stat) == 0) + { + file_size = file_stat.st_size; + if (oflags & O_CREAT) + { + fchown(fd, BT_UID, BT_GID); + BTIF_TRACE_DEBUG0("\n ******CHANGED OWNERSHIP SUCCESSFULLY**********"); + } + } + } + + else + { + err = errno; + } + } + + BTIF_TRACE_DEBUG4("[CO] bta_fs_co_open: handle:%d err:%d, flags:%x, app id:%d", + fd, err, oflags, app_id); + BTIF_TRACE_DEBUG1("file=%s", p_path); + + /* convert fs error into bta_fs err. erro is set by first call to enough space to a valid value + * and needs only updating in case of error. This reports correct failure to remote obex! */ + + switch (err) + { + + case 0: + status = BTA_FS_CO_OK; + break; + case EACCES: + status = BTA_FS_CO_EACCES; + break; + case EFBIG: /* file to big for available fs space */ + status = BTA_FS_CO_ENOSPACE; + break; + default: + status = BTA_FS_CO_FAIL; + break; + } + bta_fs_ci_open(fd, status, file_size, evt); +} + +/******************************************************************************* +** +** Function bta_fs_co_close +** +** Description This function is called by BTA when a connection to a +** client is closed. +** +** Parameters fd - file descriptor of file to close. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if successful], +** [BTA_FS_CO_FAIL if failed ] +** +*******************************************************************************/ +tBTA_FS_CO_STATUS bta_fs_co_close(int fd, UINT8 app_id) +{ + tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; + int err; + + BTIF_TRACE_DEBUG2("[CO] bta_fs_co_close: handle:%d, app id:%d", + fd, app_id); + if (close (fd) < 0) + { + err = errno; + status = BTA_FS_CO_FAIL; + BTIF_TRACE_WARNING3("[CO] bta_fs_co_close: handle:%d error=%d app_id:%d", fd, err, app_id); + } + + return (status); +} + +/******************************************************************************* +** +** Function bta_fs_co_read +** +** Description This function is called by BTA to read in data from the +** previously opened file on the phone. +** +** Parameters fd - file descriptor of file to read from. +** p_buf - buffer to read the data into. +** nbytes - number of bytes to read into the buffer. +** evt - event that must be passed into the call-in function. +** ssn - session sequence number. Ignored, if bta_fs_co_open +** was not called with BTA_FS_CO_RELIABLE. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +** Note: Upon completion of the request, bta_fs_ci_read() is +** called with the buffer of data, along with the number +** of bytes read into the buffer, and a status. The +** call-in function should only be called when ALL requested +** bytes have been read, the end of file has been detected, +** or an error has occurred. +** +*******************************************************************************/ +void bta_fs_co_read(int fd, UINT8 *p_buf, UINT16 nbytes, UINT16 evt, UINT8 ssn, UINT8 app_id) +{ + tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; + INT32 num_read; + int err; + + if ((num_read = read (fd, p_buf, nbytes)) < 0) + { + err = errno; + status = BTA_FS_CO_FAIL; + BTIF_TRACE_WARNING3("[CO] bta_fs_co_read: handle:%d error=%d app_id:%d", + fd, err, app_id); + } + else if (num_read < nbytes) + status = BTA_FS_CO_EOF; + + bta_fs_ci_read(fd, (UINT16)num_read, status, evt); +} + +/******************************************************************************* +** +** Function bta_fs_co_write +** +** Description This function is called by io to send file data to the +** phone. +** +** Parameters fd - file descriptor of file to write to. +** p_buf - buffer to read the data from. +** nbytes - number of bytes to write out to the file. +** evt - event that must be passed into the call-in function. +** ssn - session sequence number. Ignored, if bta_fs_co_open +** was not called with BTA_FS_CO_RELIABLE. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +** Note: Upon completion of the request, bta_fs_ci_write() is +** called with the file descriptor and the status. The +** call-in function should only be called when ALL requested +** bytes have been written, or an error has been detected, +** +*******************************************************************************/ +void bta_fs_co_write(int fd, const UINT8 *p_buf, UINT16 nbytes, UINT16 evt, + UINT8 ssn, UINT8 app_id) +{ + tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; + INT32 num_written; + int err=0; + + if ((num_written = write (fd, p_buf, nbytes)) < 0) + { + err = errno; + status = BTA_FS_CO_FAIL; + } +/* BTIF_TRACE_DEBUG3("[CO] bta_fs_co_write: handle:%d error=%d, num_written:%d", fd, err, num_written);*/ + + bta_fs_ci_write(fd, status, evt); +} + +/******************************************************************************* +** +** Function bta_fs_co_seek +** +** Description This function is called by io to move the file pointer +** of a previously opened file to the specified location for +** the next read or write operation. +** +** Parameters fd - file descriptor of file. +** offset - Number of bytes from origin. +** origin - Initial position. +** +** Returns void +** +*******************************************************************************/ +void bta_fs_co_seek (int fd, INT32 offset, INT16 origin, UINT8 app_id) +{ + lseek(fd, offset, origin); +} + +/******************************************************************************* +** +** Function bta_fs_co_access +** +** Description This function is called to check the existence of +** a file or directory, and return whether or not it is a +** directory or length of the file. +** +** Parameters p_path - (input) file or directory to access (fully qualified path). +** mode - (input) [BTA_FS_ACC_EXIST, BTA_FS_ACC_READ, or BTA_FS_ACC_RDWR] +** p_is_dir - (output) returns TRUE if p_path specifies a directory. +** app_id - (input) application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if it exists] +** [BTA_FS_CO_EACCES if permissions are wrong] +** [BTA_FS_CO_FAIL if it does not exist] +** +*******************************************************************************/ +tBTA_FS_CO_STATUS bta_fs_co_access(const char *p_path, int mode, BOOLEAN *p_is_dir, + UINT8 app_id) +{ + int err; + int os_mode = 0; + tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; + struct stat buffer; + + #if (TRUE==BTA_FS_DEBUG) + LOGI("***********CHECKING ACCESS TO = %s", p_path); + #endif + + #if (defined BTA_PBS_INCLUDED) && (BTA_PBS_INCLUDED == TRUE) + + if (app_id == UI_PBS_ID) + { + + *p_is_dir = TRUE; + + #if (TRUE==BTA_FS_DEBUG) + LOGI("***********SUPPORTED REPO = %d", bta_pbs_cfg.supported_repositories); + #endif + //Check if SIM contact requested, and if so if it's supported. + //If not, return error! + if (strstr(p_path,"SIM1") && !(bta_pbs_cfg.supported_repositories & 0x2)) { + LOGI("***********RETURNING FAIL!"); + return BTA_FS_CO_FAIL; + } + + #if (TRUE==BTA_FS_DEBUG) + LOGI("***********RETURNING success!"); + #endif + return (status); + } + #endif + + + *p_is_dir = FALSE; + + if (mode == BTA_FS_ACC_RDWR) + os_mode = 6; + else if (mode == BTA_FS_ACC_READ) + os_mode = 4; + + if (stat(p_path, &buffer) == 0) + { + /* Determine if the object is a file or directory */ + if (S_ISDIR(buffer.st_mode)) + *p_is_dir = TRUE; + } + else + { + BTIF_TRACE_DEBUG0("stat() failed! "); + return BTA_FS_CO_FAIL; + } + + status=getAccess (os_mode, &buffer, (char*)p_path); + return (status); +} + +/******************************************************************************* +** +** Function bta_fs_co_mkdir +** +** Description This function is called to create a directory with +** the pathname given by path. The pathname is a null terminated +** string. All components of the path must already exist. +** +** Parameters p_path - (input) name of directory to create (fully qualified path). +** app_id - (input) application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if successful] +** [BTA_FS_CO_FAIL if unsuccessful] +** +*******************************************************************************/ +tBTA_FS_CO_STATUS bta_fs_co_mkdir(const char *p_path, UINT8 app_id) +{ + int err; + tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; + + if ((mkdir (p_path, 0666)) != 0) + { + err = errno; + status = BTA_FS_CO_FAIL; + BTIF_TRACE_WARNING3("[CO] bta_fs_co_mkdir: error=%d, path [%s] app_id:%d", + err, p_path, app_id); + } + return (status); +} + +/******************************************************************************* +** +** Function bta_fs_co_rmdir +** +** Description This function is called to remove a directory whose +** name is given by path. The directory must be empty. +** +** Parameters p_path - (input) name of directory to remove (fully qualified path). +** app_id - (input) application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if successful] +** [BTA_FS_CO_EACCES if read-only] +** [BTA_FS_CO_ENOTEMPTY if directory is not empty] +** [BTA_FS_CO_FAIL otherwise] +** +*******************************************************************************/ +tBTA_FS_CO_STATUS bta_fs_co_rmdir(const char *p_path, UINT8 app_id) +{ + int err, path_len; + tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; + struct stat buffer; + char *dirName, *tmp = NULL; + + path_len = strlen( p_path )+1; + BTIF_TRACE_DEBUG2( "bta_fs_co_rmdir( app_id: %d ): path_len: %d", app_id, path_len ); +#if (TRUE==BTA_FS_DEBUG) + BTIF_TRACE_DEBUG1( "bta_fs_co_rmdir():path_len: %d, p_path", app_id ); + BTIF_TRACE_DEBUG0( p_path ); +#endif + + /* allocate a temp buffer for path with 0 char. make sure not to crash if path is too big! */ + dirName = (char*) calloc(1, path_len+1); + if ( NULL != dirName ) + { + strcpy( dirName, p_path ); + } + else + { + BTIF_TRACE_WARNING2( "bta_fs_co_rmdir( app_id: %d ) for path_len: %d::out of memory", + app_id, path_len ); + return BTA_FS_CO_FAIL; + } + + if (NULL!= (tmp = strrchr(dirName, '/'))) + { + *tmp = '\0'; + } + if (stat(dirName, &buffer) == 0) + { + status = getAccess(6, &buffer, dirName); + } + else + { + free(dirName); +#if (TRUE==BTA_FS_DEBUG) + BTIF_TRACE_WARNING0( "bta_fs_co_rmdir()::stat(dirName) failed" ); +#endif + return BTA_FS_CO_FAIL; + } + + free(dirName); + if (status != BTA_FS_CO_OK) + { +#if (TRUE==BTA_FS_DEBUG) + BTIF_TRACE_WARNING0( "bta_fs_co_rmdir()::getAccess(dirName) FAILED"); +#endif + return status; + } + + if (stat(p_path, &buffer) == 0) + { + status = getAccess(6, &buffer, (char*)p_path); + } + else + { +#if (TRUE==BTA_FS_DEBUG) + BTIF_TRACE_WARNING0( "bta_fs_co_rmdir()::stat(p_path) FAILED"); +#endif + return BTA_FS_CO_FAIL; + } + + if (status != BTA_FS_CO_OK) + { +#if (TRUE==BTA_FS_DEBUG) + BTIF_TRACE_DEBUG0( "bta_fs_co_rmdir()::getAccess(p_path) FAILED"); +#endif + return status; + } + //if ((rmdir (p_path)) != 0) + if (del_path(p_path) != 0) + { + err = errno; + BTIF_TRACE_WARNING1( "bta_fs_co_rmdir():rmdir/del_path FAILED with err: %d", err ); + if (err == EACCES) + status = BTA_FS_CO_EACCES; + else if (err == ENOTEMPTY) + status = BTA_FS_CO_ENOTEMPTY; + else + status = BTA_FS_CO_FAIL; + } + return (status); +} + +/******************************************************************************* +** +** Function bta_fs_co_unlink +** +** Description This function is called to remove a file whose name +** is given by p_path. +** +** Parameters p_path - (input) name of file to remove (fully qualified path). +** app_id - (input) application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if successful] +** [BTA_FS_CO_EACCES if read-only] +** [BTA_FS_CO_FAIL otherwise] +** +*******************************************************************************/ +tBTA_FS_CO_STATUS bta_fs_co_unlink(const char *p_path, UINT8 app_id) +{ + BTIF_TRACE_DEBUG0("bta_fs_co_unlink"); + int err; + tBTA_FS_CO_STATUS status = BTA_FS_CO_OK; + char *dirName, *tmp=NULL; + struct stat buffer; + + if(! p_path) + return BTA_FS_CO_FAIL; + + /* buffer needs to be NULL terminated - so add one more byte to be zero'd out */ +#if 0 + dirName= (char*) calloc(1, strlen(p_path)); /* <--- this can cause problems */ +#else + dirName= (char*) calloc(1, strlen(p_path) + 1); +#endif + + strncpy(dirName, p_path, strlen(p_path)); + if((tmp=strrchr(dirName, '/'))) + { + *tmp='\0'; + } + if (stat(dirName, &buffer) == 0) + { + status=getAccess (6, &buffer, dirName); + free(dirName); + } + else + { + BTIF_TRACE_DEBUG0("stat() failed! "); + free(dirName); + return BTA_FS_CO_FAIL; + } + + if(status!= BTA_FS_CO_OK) + return status; + + if ((unlink (p_path)) != 0) + { + err = errno; + if (err == EACCES) + status = BTA_FS_CO_EACCES; + else + status = BTA_FS_CO_FAIL; + } + return (status); + +} + +/******************************************************************************* +** +** Function bta_fs_co_getdirentry +** +** Description This function is called to get a directory entry for the +** specified p_path. The first/next directory should be filled +** into the location specified by p_entry. +** +** Parameters p_path - directory to search (Fully qualified path) +** first_item - TRUE if first search, FALSE if next search +** (p_cur contains previous) +** p_entry (input/output) - Points to last entry data (valid when +** first_item is FALSE) +** evt - event that must be passed into the call-in function. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +** Note: Upon completion of the request, the status is passed +** in the bta_fs_ci_direntry() call-in function. +** BTA_FS_CO_OK is returned when p_entry is valid, +** BTA_FS_CO_EODIR is returned when no more entries [finished] +** BTA_FS_CO_FAIL is returned if an error occurred +** +*******************************************************************************/ +void bta_fs_co_getdirentry(const char *p_path, BOOLEAN first_item, + tBTA_FS_DIRENTRY *p_entry, UINT16 evt, UINT8 app_id) +{ + tBTA_FS_CO_STATUS co_status = BTA_FS_CO_FAIL; + int status = -1; /* '0' - success, '-1' - fail */ + struct tm *p_tm; + DIR *dir; + struct dirent *dirent; + struct stat buf; + char fullname[500]; + + BTIF_TRACE_DEBUG0("Entered bta_fs_co_getdirentry"); + + /* First item is to be retrieved */ + if (first_item) + { + BTIF_TRACE_DEBUG1("bta_fs_co_getdirentry: path = %s", p_path); + + dir = opendir(p_path); + if(dir == NULL) + { + BTIF_TRACE_DEBUG1("bta_fs_co_getdirentry: dir is NULL so error out with errno=%d", errno); + co_status = BTA_FS_CO_EODIR; + bta_fs_ci_direntry(co_status, evt); + return; + } + + BTIF_TRACE_DEBUG1("bta_fs_co_getdirentry: dir = %p", dir); + if((dirent = readdir(dir)) != NULL) + { + p_entry->refdata = (UINT32) dir; /* Save this for future searches */ + status = 0; + BTIF_TRACE_DEBUG1("bta_fs_co_getdirentry: dirent = %p", dirent); + } + else + { + BTIF_TRACE_DEBUG1("bta_fs_co_getdirentry: dirent = %p", dirent); + /* Close the search if there are no more items */ + closedir( (DIR*) p_entry->refdata); + co_status = BTA_FS_CO_EODIR; + } + } + else /* Get the next entry based on the p_ref data from previous search */ + { + if ((dirent = readdir((DIR*)p_entry->refdata)) == NULL) + { + /* Close the search if there are no more items */ + closedir( (DIR*) p_entry->refdata); + co_status = BTA_FS_CO_EODIR; + BTIF_TRACE_DEBUG1("bta_fs_co_getdirentry: dirent = %p", dirent); + } + else + { + BTIF_TRACE_DEBUG1("bta_fs_co_getdirentry: dirent = %p", dirent); + status = 0; + } + } + + if (status == 0) + { + BTIF_TRACE_DEBUG0("bta_fs_co_getdirentry: status = 0"); + + sprintf(fullname, "%s/%s", p_path, dirent->d_name); + + /* Load new values into the return structure (refdata is left untouched) */ + if (stat(fullname, &buf) == 0) { + p_entry->filesize = buf.st_size; + p_entry->mode = 0; /* Default is normal read/write file access */ + + if (S_ISDIR(buf.st_mode)) + p_entry->mode |= BTA_FS_A_DIR; + else + p_entry->mode |= BTA_FS_A_RDONLY; + + strcpy(p_entry->p_name, dirent->d_name); +#if 0 + fprintf(stderr, "bta_fs_co_getdirentry(): %s %9d %d\n", + dirent->d_name, + buf.st_size, + p_entry->mode); +#endif + p_tm = localtime((const time_t*)&buf.st_mtime); + if (p_tm != NULL) + { + sprintf(p_entry->crtime, "%04d%02d%02dT%02d%02d%02dZ", + p_tm->tm_year + 1900, /* Base Year ISO 6201 */ + p_tm->tm_mon + 1, /* month starts at 0 */ + p_tm->tm_mday, + p_tm->tm_hour, + p_tm->tm_min, + p_tm->tm_sec); + } + else + p_entry->crtime[0] = '\0'; /* No valid time */ +#if 0 + fprintf(stderr, "bta_fs_co_getdirentry(): %s %9d %d %s\n", + dirent->d_name, + p_entry->filesize, + p_entry->mode, + p_entry->crtime); +#endif + co_status = BTA_FS_CO_OK; + } else { + BTIF_TRACE_WARNING0("stat() failed! "); + co_status = BTA_FS_CO_EACCES; + } + } + BTIF_TRACE_DEBUG0("bta_fs_co_getdirentry: calling bta_fs_ci_getdirentry"); + + bta_fs_ci_direntry(co_status, evt); +} + + + + +/******************************************************************************* +** +** Function bta_fs_co_setdir +** +** Description This function is executed by BTA when the server changes the +** local path +** +** Parameters p_path - the new path. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +*******************************************************************************/ +void bta_fs_co_setdir(const char *p_path, UINT8 app_id) +{ + BTIF_TRACE_DEBUG2("Entered %s. New path: %s", __FUNCTION__, p_path); +} + +/******************************************************************************* +** OBEX14 Reliable Session not supported. Stub associated callouts. +******************************************************************************/ + +/******************************************************************************* +** +** Function bta_fs_co_resume +** +** Description This function is executed by BTA when resuming a session. +** This is used to retrieve the session ID and related information +** +** Parameters evt - event that must be passed into the call-in function. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +** Note: Upon completion of the request, the related session information, +** if successful, and an error code (tBTA_FS_CO_STATUS) +** are returned in the call-in function, bta_fs_ci_resume(). +** +*******************************************************************************/ +void bta_fs_co_resume(UINT16 evt, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_resume - NOT implemented"); +} + +/******************************************************************************* +** +** Function bta_fs_co_set_perms +** +** Description This function is called to set the permission a file/directory +** with name as p_src_path. +** +** Parameters p_src_path - (input) name of file/directory to set permission (fully qualified path). +** p_perms - the permission . +** app_id - (input) application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if successful] +** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); +** or p_src_path is a directory and p_dest_path specifies a different path. ] +** [BTA_FS_CO_FAIL otherwise] +** +*******************************************************************************/ +void bta_fs_co_set_perms(const char *p_src_path, UINT8 *p_perms, UINT16 evt, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_set_perms - NOT implemented"); +} + +/******************************************************************************* +** +** Function bta_fs_co_rename +** +** Description This function is called to move a file/directory whose +** name is given by p_src_path to p_dest_path. +** +** Parameters p_src_path - (input) name of file/directory to be moved (fully qualified path). +** p_dest_path - (input) new name of file/directory(fully qualified path). +** p_perms - the permission of the new object. +** app_id - (input) application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if successful] +** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); +** or p_src_path is a directory and p_dest_path specifies a different path. ] +** [BTA_FS_CO_FAIL otherwise] +** +*******************************************************************************/ +void bta_fs_co_rename(const char *p_src_path, const char *p_dest_path, UINT8 *p_perms, UINT16 evt, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_rename - NOT implemented"); +} + +/******************************************************************************* +** +** Function bta_fs_co_copy +** +** Description This function is called to copy a file/directory whose +** name is given by p_src_path to p_dest_path. +** +** Parameters p_src_path - (input) name of file/directory to be copied (fully qualified path). +** p_dest_path - (input) new name of file/directory(fully qualified path). +** p_perms - the permission of the new object. +** evt - event that must be passed into the call-in function. +** app_id - (input) application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns (tBTA_FS_CO_STATUS) status of the call. +** [BTA_FS_CO_OK if successful] +** [BTA_FS_CO_EIS_DIR if p_src_path is a folder] +** [BTA_FS_CO_EACCES if p_dest_path already exists or could not be created (invalid path); +** or p_src_path is a directory and p_dest_path specifies a different path. ] +** [BTA_FS_CO_FAIL otherwise] +** +*******************************************************************************/ +void bta_fs_co_copy(const char *p_src_path, const char *p_dest_path, UINT8 *p_perms, UINT16 evt, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_copy - NOT implemented"); +} + +/******************************************************************************* +** +** Function bta_fs_co_resume_op +** +** Description This function is executed by BTA when a reliable session is +** resumed and there was an interrupted operation. +** +** Parameters offset - the session ID and related information. +** evt - event that must be passed into the call-in function. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +*******************************************************************************/ +void bta_fs_co_resume_op(UINT32 offset, UINT16 evt, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_resume_op - NOT implemented"); +} + + +/******************************************************************************* +** +** Function bta_fs_co_session_info +** +** Description This function is executed by BTA when a reliable session is +** established (p_sess_info != NULL) or ended (p_sess_info == NULL). +** +** Parameters bd_addr - the peer address +** p_sess_info - the session ID and related information. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +*******************************************************************************/ +void bta_fs_co_session_info(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn, + tBTA_FS_CO_SESS_ST new_st, char *p_path, UINT8 *p_info, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_session_info - NOT implemented"); +} + + +/******************************************************************************* +** +** Function bta_fs_co_suspend +** +** Description This function is executed by BTA when a reliable session is +** suspended. +** +** Parameters bd_addr - the peer address +** ssn - the session sequence number. +** info - the BTA specific information (like last active operation). +** p_offset- the location to receive object offset of the suspended session +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +*******************************************************************************/ +void bta_fs_co_suspend(BD_ADDR bd_addr, UINT8 *p_sess_info, UINT8 ssn, + UINT32 *p_timeout, UINT32 *p_offset, UINT8 info, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_suspend - NOT implemented"); +} + +/******************************************************************************* +** +** Function bta_fs_co_sess_ssn +** +** Description This function is executed by BTA when resuming a session. +** This is used to inform call-out module if the ssn/file offset +** needs to be adjusted. +** +** Parameters ssn - the session sequence number of the first request +** after resume. +** app_id - application ID specified in the enable functions. +** It can be used to identify which profile is the caller +** of the call-out function. +** +** Returns void +** +*******************************************************************************/ +void bta_fs_co_sess_ssn(int fd, UINT8 ssn, UINT8 app_id) +{ + BTIF_TRACE_WARNING0("[CO] bta_fs_co_suspend - NOT implemented"); +} + diff --git a/btif/co/bta_sys_co.c b/btif/co/bta_sys_co.c new file mode 100644 index 0000000..66643bf --- /dev/null +++ b/btif/co/bta_sys_co.c @@ -0,0 +1,86 @@ +/************************************************************************************ + * + * Copyright (C) 2009-2011 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. + * + ************************************************************************************/ +#include "bta_sys.h" +#include "bta_sys_ci.h" + +/******************************************************************************* +** +** Function bta_sys_hw_co_enable +** +** Description This function is called by the stack to power up the HW +** +** Returns void +** +*******************************************************************************/ +void bta_sys_hw_co_enable( tBTA_SYS_HW_MODULE module ) +{ + /* platform specific implementation to power-up the HW */ + + + /* if no client/server asynchronous system like linux-based OS, directly call the ci here */ + bta_sys_hw_ci_enabled( module ); +} + + +/******************************************************************************* +** +** Function bta_sys_hw_co_disable +** +** Description This function is called by the stack to power down the HW +** +** Returns void +** +*******************************************************************************/ +void bta_sys_hw_co_disable( tBTA_SYS_HW_MODULE module ) +{ + /* platform specific implementation to power-down the HW */ + + + /* if no client/server asynchronous system like linux-based OS, directly call the ci here */ + bta_sys_hw_ci_disabled( module ); + +} |