component/bt: transport the following modules: btif_config, btif_storage, btif_util

This commit is contained in:
wangmengyang 2017-03-07 15:09:52 +08:00
parent c23b66b1de
commit 3acd445f94
16 changed files with 2141 additions and 404 deletions

View file

@ -1,22 +1,16 @@
/******************************************************************************
*
* Copyright (C) 2014 Google, Inc.
*
* 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.
*
******************************************************************************/
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE 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
#define LOG_TAG "bt_btif_config"
// 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 <ctype.h>
#include <stdio.h>
@ -27,8 +21,8 @@
#include "alarm.h"
#include "allocator.h"
#include "bdaddr.h"
#include "btif_config.h"
#include "btif_util.h"
#include "btc_config.h"
#include "btc_util.h"
#include "config.h"
#include "osi.h"
@ -41,7 +35,7 @@ static void timer_config_save(void *data);
// TODO(zachoverflow): Move these two functions out, because they are too specific for this file
// {grumpy-cat/no, monty-python/you-make-me-sad}
bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
{
if (p_device_type == NULL) {
return FALSE;
@ -53,7 +47,7 @@ bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
bdstr_t bd_addr_str;
bdaddr_to_string(&bda, bd_addr_str, sizeof(bd_addr_str));
if (!btif_config_get_int(bd_addr_str, "DevType", p_device_type)) {
if (!btc_config_get_int(bd_addr_str, "DevType", p_device_type)) {
return FALSE;
}
@ -61,7 +55,7 @@ bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type)
return TRUE;
}
bool btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type)
bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type)
{
if (p_addr_type == NULL) {
return FALSE;
@ -73,7 +67,7 @@ bool btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type)
bdstr_t bd_addr_str;
bdaddr_to_string(&bda, bd_addr_str, sizeof(bd_addr_str));
if (!btif_config_get_int(bd_addr_str, "AddrType", p_addr_type)) {
if (!btc_config_get_int(bd_addr_str, "AddrType", p_addr_type)) {
return FALSE;
}
@ -87,7 +81,7 @@ static osi_alarm_t *alarm_timer;
// Module lifecycle functions
bool btif_config_init(void)
bool btc_config_init(void)
{
pthread_mutex_init(&lock, NULL);
config = config_new(CONFIG_FILE_PATH);
@ -107,7 +101,7 @@ bool btif_config_init(void)
// TODO(sharvil): use a non-wake alarm for this once we have
// API support for it. There's no need to wake the system to
// write back to disk.
alarm_timer = osi_alarm_new("btif_config", timer_config_save, NULL, CONFIG_SETTLE_PERIOD_MS, false);
alarm_timer = osi_alarm_new("btc_config", timer_config_save, NULL, CONFIG_SETTLE_PERIOD_MS, false);
if (!alarm_timer) {
LOG_ERROR("%s unable to create alarm.\n", __func__);
goto error;
@ -125,15 +119,15 @@ error:;
return false;
}
bool btif_config_shut_down(void)
bool btc_config_shut_down(void)
{
btif_config_flush();
btc_config_flush();
return true;
}
bool btif_config_clean_up(void)
bool btc_config_clean_up(void)
{
btif_config_flush();
btc_config_flush();
osi_alarm_free(alarm_timer);
config_free(config);
@ -143,7 +137,7 @@ bool btif_config_clean_up(void)
return true;
}
bool btif_config_has_section(const char *section)
bool btc_config_has_section(const char *section)
{
assert(config != NULL);
assert(section != NULL);
@ -155,7 +149,7 @@ bool btif_config_has_section(const char *section)
return ret;
}
bool btif_config_exist(const char *section, const char *key)
bool btc_config_exist(const char *section, const char *key)
{
assert(config != NULL);
assert(section != NULL);
@ -168,7 +162,7 @@ bool btif_config_exist(const char *section, const char *key)
return ret;
}
bool btif_config_get_int(const char *section, const char *key, int *value)
bool btc_config_get_int(const char *section, const char *key, int *value)
{
assert(config != NULL);
assert(section != NULL);
@ -185,7 +179,7 @@ bool btif_config_get_int(const char *section, const char *key, int *value)
return ret;
}
bool btif_config_set_int(const char *section, const char *key, int value)
bool btc_config_set_int(const char *section, const char *key, int value)
{
assert(config != NULL);
assert(section != NULL);
@ -198,7 +192,7 @@ bool btif_config_set_int(const char *section, const char *key, int value)
return true;
}
bool btif_config_get_str(const char *section, const char *key, char *value, int *size_bytes)
bool btc_config_get_str(const char *section, const char *key, char *value, int *size_bytes)
{
assert(config != NULL);
assert(section != NULL);
@ -220,7 +214,7 @@ bool btif_config_get_str(const char *section, const char *key, char *value, int
return true;
}
bool btif_config_set_str(const char *section, const char *key, const char *value)
bool btc_config_set_str(const char *section, const char *key, const char *value)
{
assert(config != NULL);
assert(section != NULL);
@ -234,7 +228,7 @@ bool btif_config_set_str(const char *section, const char *key, const char *value
return true;
}
bool btif_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length)
bool btc_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length)
{
assert(config != NULL);
assert(section != NULL);
@ -269,7 +263,7 @@ bool btif_config_get_bin(const char *section, const char *key, uint8_t *value, s
return true;
}
size_t btif_config_get_bin_length(const char *section, const char *key)
size_t btc_config_get_bin_length(const char *section, const char *key)
{
assert(config != NULL);
assert(section != NULL);
@ -287,7 +281,7 @@ size_t btif_config_get_bin_length(const char *section, const char *key)
return ((value_len % 2) != 0) ? 0 : (value_len / 2);
}
bool btif_config_set_bin(const char *section, const char *key, const uint8_t *value, size_t length)
bool btc_config_set_bin(const char *section, const char *key, const uint8_t *value, size_t length)
{
const char *lookup = "0123456789abcdef";
@ -317,33 +311,33 @@ bool btif_config_set_bin(const char *section, const char *key, const uint8_t *va
return true;
}
const btif_config_section_iter_t *btif_config_section_begin(void)
const btc_config_section_iter_t *btc_config_section_begin(void)
{
assert(config != NULL);
return (const btif_config_section_iter_t *)config_section_begin(config);
return (const btc_config_section_iter_t *)config_section_begin(config);
}
const btif_config_section_iter_t *btif_config_section_end(void)
const btc_config_section_iter_t *btc_config_section_end(void)
{
assert(config != NULL);
return (const btif_config_section_iter_t *)config_section_end(config);
return (const btc_config_section_iter_t *)config_section_end(config);
}
const btif_config_section_iter_t *btif_config_section_next(const btif_config_section_iter_t *section)
const btc_config_section_iter_t *btc_config_section_next(const btc_config_section_iter_t *section)
{
assert(config != NULL);
assert(section != NULL);
return (const btif_config_section_iter_t *)config_section_next((const config_section_node_t *)section);
return (const btc_config_section_iter_t *)config_section_next((const config_section_node_t *)section);
}
const char *btif_config_section_name(const btif_config_section_iter_t *section)
const char *btc_config_section_name(const btc_config_section_iter_t *section)
{
assert(config != NULL);
assert(section != NULL);
return config_section_name((const config_section_node_t *)section);
}
bool btif_config_remove(const char *section, const char *key)
bool btc_config_remove(const char *section, const char *key)
{
assert(config != NULL);
assert(section != NULL);
@ -356,7 +350,7 @@ bool btif_config_remove(const char *section, const char *key)
return ret;
}
void btif_config_save(void)
void btc_config_save(void)
{
assert(alarm_timer != NULL);
assert(config != NULL);
@ -364,7 +358,7 @@ void btif_config_save(void)
osi_alarm_set(alarm_timer, CONFIG_SETTLE_PERIOD_MS);
}
void btif_config_flush(void)
void btc_config_flush(void)
{
assert(config != NULL);
assert(alarm_timer != NULL);
@ -375,7 +369,7 @@ void btif_config_flush(void)
pthread_mutex_unlock(&lock);
}
int btif_config_clear(void)
int btc_config_clear(void)
{
assert(config != NULL);
assert(alarm_timer != NULL);

View file

@ -5,7 +5,7 @@
#include "btc_main.h"
#include "bt_trace.h"
#include "bt_target.h"
#include "btif_storage.h" // TODO: replace with "btc"
#include "btc_storage.h"
#include "bta_api.h"
@ -118,7 +118,7 @@ static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
bt_status_t ret;
LOG_DEBUG("%s: Storing link key. key_type=0x%x",
__FUNCTION__, p_auth_cmpl->key_type);
ret = btif_storage_add_bonded_device(&bd_addr,
ret = btc_storage_add_bonded_device(&bd_addr,
p_auth_cmpl->key, p_auth_cmpl->key_type,
16);
BTC_ASSERTC(ret == BT_STATUS_SUCCESS, "storing link key failed", ret);
@ -158,7 +158,7 @@ static void btc_dm_auth_cmpl_evt (tBTA_DM_AUTH_CMPL *p_auth_cmpl)
/* map the auth failure codes, so we can retry pairing if necessary */
case HCI_ERR_AUTH_FAILURE:
case HCI_ERR_KEY_MISSING:
btif_storage_remove_bonded_device(&bd_addr);
btc_storage_remove_bonded_device(&bd_addr);
case HCI_ERR_HOST_REJECT_SECURITY:
case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
case HCI_ERR_UNIT_KEY_USED:
@ -254,7 +254,7 @@ void btc_dm_sec_cb_handler(btc_msg_t *msg)
}
btif_enable_bluetooth_evt(p_data->enable.status);
#endif /* KARL_NOT_IGNORE */
btif_storage_load_bonded_devices();
btc_storage_load_bonded_devices();
btc_enable_bluetooth_evt(p_data->enable.status);
break;
case BTA_DM_DISABLE_EVT:

View file

@ -17,7 +17,7 @@
#include "btc_dm.h"
#include "future.h"
#include "esp_err.h"
#include "btif_config.h"
#include "btc_config.h"
static future_t *main_future[BTC_MAIN_FUTURE_NUM];
@ -62,7 +62,7 @@ void btc_init_callback(void)
static void btc_init_bluetooth(void)
{
btif_config_init();
btc_config_init();
bte_main_boot_entry(btc_init_callback);
}
@ -70,7 +70,7 @@ static void btc_init_bluetooth(void)
static void btc_deinit_bluetooth(void)
{
bte_main_shutdown();
btif_config_clean_up();
btc_config_clean_up();
future_ready(*btc_main_get_future_p(BTC_MAIN_DEINIT_FUTURE), FUTURE_SUCCESS);
}

View file

@ -1,16 +1,29 @@
#include "btif_storage.h"
#include "btif_util.h"
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE 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 "btc_storage.h"
#include "btc_util.h"
#include "osi.h"
#include "bt_trace.h"
#include "esp_system.h"
#include "nvs_flash.h"
#include "nvs.h"
#include "bta_api.h"
#include "bdaddr.h"
#include "btif_config.h"
#include "btc_config.h"
/*******************************************************************************
**
** Function btif_storage_add_bonded_device
** Function btc_storage_add_bonded_device
**
** Description BTIF storage API - Adds the newly bonded device to NVRAM
** along with the link-key, Key type and Pin key length
@ -20,7 +33,7 @@
**
*******************************************************************************/
bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
LINK_KEY link_key,
uint8_t key_type,
uint8_t pin_length)
@ -28,20 +41,20 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
bdstr_t bdstr;
bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
BTIF_TRACE_EVENT("add to storage: Remote device:%s\n", bdstr);
LOG_INFO("add to storage: Remote device:%s\n", bdstr);
int ret = btif_config_set_int(bdstr, "LinkKeyType", (int)key_type);
ret &= btif_config_set_int(bdstr, "PinLength", (int)pin_length);
ret &= btif_config_set_bin(bdstr, "LinkKey", link_key, sizeof(LINK_KEY));
int ret = btc_config_set_int(bdstr, "LinkKeyType", (int)key_type);
ret &= btc_config_set_int(bdstr, "PinLength", (int)pin_length);
ret &= btc_config_set_bin(bdstr, "LinkKey", link_key, sizeof(LINK_KEY));
/* write bonded info immediately */
btif_config_flush();
BTIF_TRACE_EVENT("Storage add rslt %d\n", ret);
btc_config_flush();
LOG_INFO("Storage add rslt %d\n", ret);
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}
/*******************************************************************************
**
** Function btif_in_fetch_bonded_devices
** Function btc_in_fetch_bonded_devices
**
** Description Internal helper function to fetch the bonded devices
** from NVRAM
@ -49,22 +62,22 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
**
*******************************************************************************/
static bt_status_t btif_in_fetch_bonded_devices(int add)
static bt_status_t btc_in_fetch_bonded_devices(int add)
{
BOOLEAN bt_linkkey_file_found = FALSE;
for (const btif_config_section_iter_t *iter = btif_config_section_begin(); iter != btif_config_section_end(); iter = btif_config_section_next(iter)) {
const char *name = btif_config_section_name(iter);
for (const btc_config_section_iter_t *iter = btc_config_section_begin(); iter != btc_config_section_end(); iter = btc_config_section_next(iter)) {
const char *name = btc_config_section_name(iter);
if (!string_is_bdaddr(name)) {
continue;
}
BTIF_TRACE_EVENT("Remote device:%s\n", name);
LOG_INFO("Remote device:%s\n", name);
LINK_KEY link_key;
size_t size = sizeof(link_key);
if (btif_config_get_bin(name, "LinkKey", link_key, &size)) {
if (btc_config_get_bin(name, "LinkKey", link_key, &size)) {
int linkkey_type;
if (btif_config_get_int(name, "LinkKeyType", &linkkey_type)) {
if (btc_config_get_int(name, "LinkKeyType", &linkkey_type)) {
//int pin_len;
//btif_config_get_int(name, "PinLength", &pin_len))
bt_bdaddr_t bd_addr;
@ -73,20 +86,20 @@ static bt_status_t btif_in_fetch_bonded_devices(int add)
DEV_CLASS dev_class = {0, 0, 0};
int cod;
int pin_length = 0;
if (btif_config_get_int(name, "DevClass", &cod)) {
if (btc_config_get_int(name, "DevClass", &cod)) {
uint2devclass((UINT32)cod, dev_class);
}
btif_config_get_int(name, "PinLength", &pin_length);
btc_config_get_int(name, "PinLength", &pin_length);
BTA_DmAddDevice(bd_addr.address, dev_class, link_key, 0, 0,
(UINT8)linkkey_type, 0, pin_length);
}
bt_linkkey_file_found = TRUE;
} else {
BTIF_TRACE_ERROR("bounded device:%s, LinkKeyType or PinLength is invalid\n", name);
LOG_ERROR("bounded device:%s, LinkKeyType or PinLength is invalid\n", name);
}
}
if (!bt_linkkey_file_found) {
BTIF_TRACE_EVENT("Remote device:%s, no link key\n", name);
LOG_INFO("Remote device:%s, no link key\n", name);
}
}
return BT_STATUS_SUCCESS;
@ -95,7 +108,7 @@ static bt_status_t btif_in_fetch_bonded_devices(int add)
/*******************************************************************************
**
** Function btif_storage_load_bonded_devices
** Function btc_storage_load_bonded_devices
**
** Description BTIF storage API - Loads all the bonded devices from NVRAM
** and adds to the BTA.
@ -105,17 +118,17 @@ static bt_status_t btif_in_fetch_bonded_devices(int add)
** Returns BT_STATUS_SUCCESS if successful, BT_STATUS_FAIL otherwise
**
*******************************************************************************/
bt_status_t btif_storage_load_bonded_devices(void)
bt_status_t btc_storage_load_bonded_devices(void)
{
bt_status_t status;
status = btif_in_fetch_bonded_devices(1);
BTIF_TRACE_EVENT("Storage load rslt %d\n", status);
status = btc_in_fetch_bonded_devices(1);
LOG_INFO("Storage load rslt %d\n", status);
return status;
}
/*******************************************************************************
**
** Function btif_storage_remove_bonded_device
** Function btc_storage_remove_bonded_device
**
** Description BTIF storage API - Deletes the bonded device from NVRAM
**
@ -123,23 +136,23 @@ bt_status_t btif_storage_load_bonded_devices(void)
** BT_STATUS_FAIL otherwise
**
*******************************************************************************/
bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr)
bt_status_t btc_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr)
{
bdstr_t bdstr;
bdaddr_to_string(remote_bd_addr, bdstr, sizeof(bdstr));
BTIF_TRACE_EVENT("Add to storage: Remote device:%s\n", bdstr);
LOG_INFO("Add to storage: Remote device:%s\n", bdstr);
int ret = 1;
if (btif_config_exist(bdstr, "LinkKeyType")) {
ret &= btif_config_remove(bdstr, "LinkKeyType");
if (btc_config_exist(bdstr, "LinkKeyType")) {
ret &= btc_config_remove(bdstr, "LinkKeyType");
}
if (btif_config_exist(bdstr, "PinLength")) {
ret &= btif_config_remove(bdstr, "PinLength");
if (btc_config_exist(bdstr, "PinLength")) {
ret &= btc_config_remove(bdstr, "PinLength");
}
if (btif_config_exist(bdstr, "LinkKey")) {
ret &= btif_config_remove(bdstr, "LinkKey");
if (btc_config_exist(bdstr, "LinkKey")) {
ret &= btc_config_remove(bdstr, "LinkKey");
}
/* write bonded info immediately */
btif_config_flush();
btc_config_flush();
return ret ? BT_STATUS_SUCCESS : BT_STATUS_FAIL;
}

View file

@ -1,54 +1,33 @@
/******************************************************************************
*
* Copyright (c) 2014 The Android Open Source Project
* Copyright (C) 2009-2012 Broadcom 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.
*
******************************************************************************/
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE 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.
/************************************************************************************
*
* Filename: btif_util.c
* Filename: btc_util.c
*
* Description: Miscellaneous helper functions
*
*
***********************************************************************************/
// #include <hardware/bluetooth.h>
// #include <hardware/bt_hf.h>
// #include <hardware/bt_av.h>
// #include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define LOG_TAG "bt_btif_util"
// #include "btif_common.h"
// #include "bta_api.h"
// #include "gki.h"
// #include "btu.h"
// #include "bte.h"
// #include "btif_dm.h"
#include "btif_util.h"
// #include "bta_ag_api.h"
#include "btc_util.h"
#include "bta_av_api.h"
// #include "bta_hh_api.h"
// #include "bta_hf_client_api.h"
// #include "avrc_defs.h"
#include "bt_defs.h"
/************************************************************************************
@ -211,4 +190,3 @@ void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str)
ntohl(uuid4), ntohs(uuid5));
return;
}

View file

@ -0,0 +1,54 @@
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE 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 __BTC_CONFIG_H__
#define __BTC_CONFIG_H__
#include <stdbool.h>
#include <stddef.h>
#include "bt_types.h"
typedef struct btc_config_section_iter_t btc_config_section_iter_t;
bool btc_config_init(void);
bool btc_config_shut_down(void);
bool btc_config_clean_up(void);
bool btc_config_has_section(const char *section);
bool btc_config_exist(const char *section, const char *key);
bool btc_config_get_int(const char *section, const char *key, int *value);
bool btc_config_set_int(const char *section, const char *key, int value);
bool btc_config_get_str(const char *section, const char *key, char *value, int *size_bytes);
bool btc_config_set_str(const char *section, const char *key, const char *value);
bool btc_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length);
bool btc_config_set_bin(const char *section, const char *key, const uint8_t *value, size_t length);
bool btc_config_remove(const char *section, const char *key);
size_t btc_config_get_bin_length(const char *section, const char *key);
const btc_config_section_iter_t *btc_config_section_begin(void);
const btc_config_section_iter_t *btc_config_section_end(void);
const btc_config_section_iter_t *btc_config_section_next(const btc_config_section_iter_t *section);
const char *btc_config_section_name(const btc_config_section_iter_t *section);
void btc_config_save(void);
void btc_config_flush(void);
int btc_config_clear(void);
// TODO(zachoverflow): Eww...we need to move these out. These are peer specific, not config general.
bool btc_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
bool btc_get_device_type(const BD_ADDR bd_addr, int *p_device_type);
#endif

View file

@ -1,29 +1,27 @@
/******************************************************************************
*
* Copyright (C) 2009-2012 Broadcom 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 __BTIF_STORAGE_H__
#define __BTIF_STORAGE_H__
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE 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 __BTC_STORAGE_H__
#define __BTC_STORAGE_H__
#include <stdint.h>
#include "bt_defs.h"
#include "bt_types.h"
/*******************************************************************************
**
** Function btif_storage_add_bonded_device
** Function btc_storage_add_bonded_device
**
** Description BTIF storage API - Adds the newly bonded device to NVRAM
** along with the link-key, Key type and Pin key length
@ -32,14 +30,14 @@
** BT_STATUS_FAIL otherwise
**
*******************************************************************************/
bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
bt_status_t btc_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
LINK_KEY link_key,
uint8_t key_type,
uint8_t pin_length);
/*******************************************************************************
**
** Function btif_storage_remove_bonded_device
** Function btc_storage_remove_bonded_device
**
** Description BTIF storage API - Deletes the bonded device from NVRAM
**
@ -47,11 +45,11 @@ bt_status_t btif_storage_add_bonded_device(bt_bdaddr_t *remote_bd_addr,
** BT_STATUS_FAIL otherwise
**
*******************************************************************************/
bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr);
bt_status_t btc_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr);
/*******************************************************************************
**
** Function btif_storage_remove_bonded_device
** Function btc_storage_remove_bonded_device
**
** Description BTIF storage API - Deletes the bonded device from NVRAM
**
@ -59,8 +57,6 @@ bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr);
** BT_STATUS_FAIL otherwise
**
*******************************************************************************/
bt_status_t btif_storage_load_bonded_devices(void);
bt_status_t btc_storage_load_bonded_devices(void);
#endif /* BTIF_STORAGE_H */
#endif /* BTC_STORAGE_H */

View file

@ -1,42 +1,32 @@
/******************************************************************************
*
* Copyright (c) 2014 The Android Open Source Project
* Copyright (C) 2009-2012 Broadcom 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.
*
******************************************************************************/
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE 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
#ifndef BTIF_UTIL_H
#define BTIF_UTIL_H
// 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 __BTC_UTIL_H__
#define __BTC_UTIL_H__
// #include <hardware/bluetooth.h>
// #include <hardware/bt_hf.h>
#include <stdbool.h>
// #include <sys/time.h>
#include "bt_types.h"
// #include "bt_utils.h"
#include "bt_defs.h"
/*******************************************************************************
** Constants & Macros
********************************************************************************/
#define CASE_RETURN_STR(const) case const: return #const;
/*******************************************************************************
** Type definitions for callback functions
********************************************************************************/
typedef char bdstr_t[18];
@ -54,4 +44,4 @@ void uuid16_to_uuid128(uint16_t uuid16, bt_uuid_t *uuid128);
void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str);
void string_to_uuid(char *str, bt_uuid_t *p_uuid);
#endif /* BTIF_UTIL_H */
#endif /* __BTC_UTIL_H__ */

View file

@ -33,7 +33,7 @@
#include "bta_av_sbc.h"
#include "btc_media.h"
#include "btc_av_co.h"
#include "btif_util.h"
#include "btc_util.h"
/*****************************************************************************
** Constants

View file

@ -28,7 +28,7 @@
#include "btc_dm.h"
#include "btc_av.h"
#include "btc_avrc.h"
#include "btif_util.h"
#include "btc_util.h"
#include "btc_profile_queue.h"
#include "bta_api.h"
#include "btc_media.h"

View file

@ -53,7 +53,7 @@
#include "bt_defs.h"
#include "btc_av.h"
#include "btc_sm.h"
#include "btif_util.h"
#include "btc_util.h"
#if (BTA_AV_SINK_INCLUDED == TRUE)
#include "oi_codec_sbc.h"
#include "oi_status.h"

View file

@ -26,7 +26,7 @@
#include "gki.h"
#include "btc_common.h"
#include "btif_util.h"
#include "btc_util.h"
#include "btc_av.h"
#include "btc_avrc.h"
#include "uinput.h"

File diff suppressed because it is too large Load diff

View file

@ -1,123 +0,0 @@
/******************************************************************************
*
* Copyright (c) 2014 The Android Open Source Project
* Copyright (C) 2009-2012 Broadcom 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 BTIF_COMMON_H
#define BTIF_COMMON_H
#include <stdlib.h>
// #include <hardware/bluetooth.h>
#include "bt_types.h"
#include "bta_api.h"
#include "osi.h"
// #include "osi/include/log.h"
/*******************************************************************************
** Constants & Macros
********************************************************************************/
#define ASSERTC(cond, msg, val) if (!(cond)) { LOG_ERROR( \
"### ASSERT : %s line %d %s (%d) ###", __FILE__, __LINE__, msg, val);}
/* Calculate start of event enumeration; id is top 8 bits of event */
#define BTIF_SIG_START(id) ((id) << 8)
/* For upstream the MSB bit is always SET */
#define BTIF_SIG_CB_BIT (0x8000)
#define BTIF_SIG_CB_START(id) (((id) << 8) | BTIF_SIG_CB_BIT)
/* BTIF sub-systems */
#define BTIF_CORE 0
#define BTIF_DM 1
// #define BTIF_HFP 2
// #define BTIF_AV 3
// #define BTIF_PAN 4
// #define BTIF_HF_CLIENT 5
#define HAL_CBACK(P_CB, P_CBACK, ...)\
if (P_CB && P_CB->P_CBACK) { \
BTIF_TRACE_API("HAL %s->%s", #P_CB, #P_CBACK); \
P_CB->P_CBACK(__VA_ARGS__); \
} \
else { \
ASSERTC(0, "Callback is NULL", 0); \
}
/**
* BTIF events for requests that require context switch to btif task
* on downstreams path
*/
enum {
BTIF_CORE_API_START = BTIF_SIG_START(BTIF_CORE),
/* add here */
BTIF_DM_API_START = BTIF_SIG_START(BTIF_DM),
BTIF_DM_ENABLE_SERVICE,
BTIF_DM_DISABLE_SERVICE,
/* add here */
};
enum {
SIG_BTIF_WORK = 0xff
};
/*******************************************************************************
** Type definitions for callback functions
********************************************************************************/
typedef void (tBTIF_CBACK) (UINT16 event, char *p_param);
typedef void (tBTIF_COPY_CBACK) (UINT16 event, char *p_dest, char *p_src);
/*******************************************************************************
** Type definitions and return values
********************************************************************************/
/* this type handles all btif context switches between BTU and HAL */
typedef struct {
BT_HDR hdr;
tBTIF_CBACK *p_cb; /* context switch callback */
/* parameters passed to callback */
UINT16 event; /* message event id */
char p_param[0]; /* parameter area needs to be last */
} tBTIF_CONTEXT_SWITCH_CBACK;
/*******************************************************************************
** Functions
********************************************************************************/
bt_status_t btif_transfer_context (tBTIF_CBACK *p_cback, UINT16 event, char *p_params,
int param_len, tBTIF_COPY_CBACK *p_copy_cback);
tBTA_SERVICE_MASK btif_get_enabled_services_mask(void);
bt_status_t btif_enable_service(tBTA_SERVICE_ID service_id);
bt_status_t btif_disable_service(tBTA_SERVICE_ID service_id);
int btif_is_enabled(void);
/**
* BTIF_Events
*/
void btif_enable_bluetooth_evt(tBTA_STATUS status);
void btif_disable_bluetooth_evt(void);
#endif /* BTIF_COMMON_H */

View file

@ -1,58 +0,0 @@
/******************************************************************************
*
* Copyright (C) 2014 Google, Inc.
*
* 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.
*
******************************************************************************/
#pragma once
#include <stdbool.h>
#include <stddef.h>
#include "bt_types.h"
static const char BTIF_CONFIG_MODULE[] = "btif_config_module";
typedef struct btif_config_section_iter_t btif_config_section_iter_t;
bool btif_config_init(void);
bool btif_config_shut_down(void);
bool btif_config_clean_up(void);
bool btif_config_has_section(const char *section);
bool btif_config_exist(const char *section, const char *key);
bool btif_config_get_int(const char *section, const char *key, int *value);
bool btif_config_set_int(const char *section, const char *key, int value);
bool btif_config_get_str(const char *section, const char *key, char *value, int *size_bytes);
bool btif_config_set_str(const char *section, const char *key, const char *value);
bool btif_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length);
bool btif_config_set_bin(const char *section, const char *key, const uint8_t *value, size_t length);
bool btif_config_remove(const char *section, const char *key);
size_t btif_config_get_bin_length(const char *section, const char *key);
const btif_config_section_iter_t *btif_config_section_begin(void);
const btif_config_section_iter_t *btif_config_section_end(void);
const btif_config_section_iter_t *btif_config_section_next(const btif_config_section_iter_t *section);
const char *btif_config_section_name(const btif_config_section_iter_t *section);
void btif_config_save(void);
void btif_config_flush(void);
int btif_config_clear(void);
// TODO(zachoverflow): Eww...we need to move these out. These are peer specific, not config general.
bool btif_get_address_type(const BD_ADDR bd_addr, int *p_addr_type);
bool btif_get_device_type(const BD_ADDR bd_addr, int *p_device_type);

View file

@ -1,32 +0,0 @@
/******************************************************************************
*
* Copyright (C) 2009-2012 Broadcom 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 BTIF_DM_H
#define BTIF_DM_H
#include "bta_api.h"
/************************************************************************************
** Functions
********************************************************************************/
/**
* BTIF callback to switch context from bte to btif
*/
void bte_dm_evt(tBTA_DM_SEC_EVT event, tBTA_DM_SEC *p_data);
#endif