mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-14 08:21:15 +00:00
Merge branch 'feature/btdm_prf_task' into feature/btdm_bluedroid
# Conflicts: # components/bt/bluedroid/profiles/core/bt_prf_sys_main.c # components/bt/bluedroid/profiles/core/bt_prf_task.c # components/bt/bluedroid/profiles/core/include/bt_prf_sys.h # components/bt/bluedroid/profiles/core/include/bt_prf_task.h # components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h # components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c # components/bt/bluedroid/stack/btm/btm_sec.c
This commit is contained in:
1236
components/bt/bluedroid/stack_api/bt_app_api.c
Normal file
1236
components/bt/bluedroid/stack_api/bt_app_api.c
Normal file
File diff suppressed because it is too large
Load Diff
108
components/bt/bluedroid/stack_api/bt_app_sec.c
Normal file
108
components/bt/bluedroid/stack_api/bt_app_sec.c
Normal file
@@ -0,0 +1,108 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file bt_app_sec.c
|
||||
*
|
||||
* @brief Application entry point
|
||||
*
|
||||
* Copyright (C) Espressif 2016
|
||||
* Created by Yulong at 2016/10/13
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#include "bt_app_sec.h"
|
||||
#include <stdlib.h> // standard library
|
||||
#include <string.h>
|
||||
|
||||
|
||||
|
||||
extern void srand (unsigned int seed);
|
||||
extern int random (void);
|
||||
|
||||
/// Application Security Environment Structure
|
||||
tAPP_SEC_ENV app_sec_env;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_gen_tk
|
||||
**
|
||||
** Description This function is called to generate the ble tk
|
||||
**
|
||||
** Returns the generate tk value
|
||||
**
|
||||
*******************************************************************************/
|
||||
UINT32 app_ble_sec_gen_tk(void)
|
||||
{
|
||||
// Generate a PIN Code (Between 100000 and 999999)
|
||||
return (100000 + (random()%900000));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_gen_ltk
|
||||
**
|
||||
** Description This function is called to generate the ble ltk
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_sec_gen_ltk(UINT8 key_size)
|
||||
{
|
||||
// Counter
|
||||
UINT8 i;
|
||||
app_sec_env.key_size = key_size;
|
||||
|
||||
// Randomly generate the LTK and the Random Number
|
||||
for (i = 0; i < RAND_NB_LEN; i++)
|
||||
{
|
||||
app_sec_env.rand_nb.nb[i] = random()%256;
|
||||
}
|
||||
|
||||
// Randomly generate the end of the LTK
|
||||
for (i = 0; i < SEC_KEY_LEN; i++)
|
||||
{
|
||||
app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random()%256);
|
||||
}
|
||||
|
||||
// Randomly generate the EDIV
|
||||
app_sec_env.ediv = random()%65536;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_init
|
||||
**
|
||||
** Description This function is init the security env and function
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_sec_init()
|
||||
{
|
||||
// Reset Security Environment
|
||||
memset(&app_sec_env, 0, sizeof(app_sec_env));
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_security_start
|
||||
**
|
||||
** Description This function is called by the slave when the seurity start
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_security_start(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
924
components/bt/bluedroid/stack_api/include/bt_app_api.h
Normal file
924
components/bt/bluedroid/stack_api/include/bt_app_api.h
Normal file
@@ -0,0 +1,924 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file bt_app_api.h
|
||||
*
|
||||
* @brief Application entry point
|
||||
*
|
||||
* Copyright (C) Espressif 2016
|
||||
* Created by Yulong at 2016/10/13
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#include "bt_types.h"
|
||||
#include "bt_app_defs.h"
|
||||
#include "bta_gatt_api.h"
|
||||
#include "bt_prf_sys.h"
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_config_adv_data
|
||||
**
|
||||
** @brief This function is called to override the BTA default ADV parameters.
|
||||
**
|
||||
** @param[in] adv_data: Pointer to User defined ADV data structure. This
|
||||
** memory space can not be freed until p_adv_data_cback
|
||||
** is received.
|
||||
** @param[in|out] adv_data_cback: set adv data complete callback.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_config_adv_data (esp_ble_adv_data_cfg_t *adv_data,
|
||||
esp_ble_set_adv_data_cmpl_cb_t *adv_data_cback);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_set_scan_params
|
||||
**
|
||||
** @brief This function is called to set scan parameters
|
||||
**
|
||||
** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
|
||||
** memory space can not be freed until scan_param_setup_cback
|
||||
** @param[in] client_if: Client interface ID
|
||||
** @param[in|out] scan_param_setup_status_cback - Set scan param status callback
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_set_scan_params (esp_ble_scan_params *scan_params, esp_gattc_if_t client_if,
|
||||
esp_scan_param_setup_cb_t scan_param_setup_cback);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_start_scanning
|
||||
**
|
||||
** @brief This procedure keep the device scanning the peer device whith advertising on the air
|
||||
**
|
||||
** @param[in] duration: Keeping the scaning time, the unit is second.
|
||||
** @param[in|out] results_cb: The scanning function callback when the peer device has been scan
|
||||
** which advertising on the air
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_start_scanning (UINT8 duration, esp_dm_search_cb_t *results_cb);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_start_advertising
|
||||
**
|
||||
** @brief This function is called to start advertising.
|
||||
**
|
||||
** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_start_advertising (esp_ble_adv_params_all_t *ble_adv_params);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_stop_advertising
|
||||
**
|
||||
** @brief This function is called to stop advertising.
|
||||
**
|
||||
** @param None
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_stop_advertising (void);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_update_conn_params
|
||||
**
|
||||
** @brief Update connection parameters, can only be used when connection is up.
|
||||
**
|
||||
** @param[in] bd_addr - BD address of the peer
|
||||
** @param[in] min_int - minimum connection interval, [0x0004~ 0x4000]
|
||||
** @param[in] max_int - maximum connection interval, [0x0004~ 0x4000]
|
||||
** @param[in] latency - slave latency [0 ~ 500]
|
||||
** @param[in] timeout - supervision timeout [0x000a ~ 0xc80]
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_update_conn_params (BD_ADDR bd_addr, uint16_t min_int,
|
||||
uint16_t max_int, uint16_t latency, uint16_t timeout);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_set_pkt_data_len
|
||||
**
|
||||
** @brief This function is to set maximum LE data packet size
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_set_pkt_data_len (BD_ADDR remote_device, uint16_t tx_data_length);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_set_rand_addr
|
||||
**
|
||||
** @brief This function set the random address for the appliction
|
||||
**
|
||||
** @param[in] rand_addr: the random address whith should be setting
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_set_rand_addr (BD_ADDR rand_addr);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_config_local_privacy
|
||||
**
|
||||
** @brief Enable/disable privacy on the local device
|
||||
**
|
||||
** @param[in] privacy_enable - enable/disabe privacy on remote device.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_config_local_privacy (BOOLEAN privacy_enable);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
** @function esp_gattc_disable
|
||||
** @brief This function is called by application to disable GATTC module
|
||||
**
|
||||
** @param NULL
|
||||
**
|
||||
** @return None.
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_gattc_disable(void);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] app_uuid - applicaiton UUID
|
||||
** @param[in] client_cb - pointer to the application callback function.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_app_register(esp_bt_uuid_t *app_uuid, esp_gattc_cb_t *client_cb);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_unregister
|
||||
**
|
||||
** @brief This function is called to unregister an application
|
||||
** from GATTC module.
|
||||
**
|
||||
** @param[in] client_if - client interface identifier.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_app_unregister(esp_gattc_if_t client_if);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_conn
|
||||
**
|
||||
** @brief Open a direct connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] client_if: server interface.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_conn(esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_cancel_conn
|
||||
**
|
||||
** @brief Cancel a direct open connection or remove a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] client_if: server interface.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_cancel_conn (esp_gattc_if_t client_if, BD_ADDR remote_bda, BOOLEAN is_direct);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_close
|
||||
**
|
||||
** @brief Close a connection to a GATT server.
|
||||
**
|
||||
** @param[in] conn_id: connectino ID to be closed.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_close (uint16_t conn_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_config_mtu
|
||||
**
|
||||
** @brief Configure the MTU size in the GATT channel. This can be done
|
||||
** only once per connection.
|
||||
**
|
||||
** @param[in] conn_id: connection ID.
|
||||
** mtu: desired MTU size to use.
|
||||
**
|
||||
** @return Command status code:
|
||||
** - @ref ESP_GATT_OK: If request succeeds
|
||||
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the mtu value invalid
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_svc_search_req
|
||||
**
|
||||
** @brief This function is called to request a GATT service discovery
|
||||
** on a GATT server. This function report service search result
|
||||
** by a callback event, and followed by a service search complete
|
||||
** event.
|
||||
**
|
||||
** @param[in] conn_id: connection ID.
|
||||
** @param[in] srvc_uuid: a UUID of the service application is interested in.
|
||||
** If Null, discover for all services.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_svc_search_req (uint16_t conn_id, esp_bt_uuid_t *srvc_uuid);
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_first_char
|
||||
**
|
||||
** @brief This function is called to find the first characteristic of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] char_result: output parameter which will store the GATT
|
||||
** characteristic ID.
|
||||
** @param[in] property: output parameter to carry the characteristic property.
|
||||
**
|
||||
** @return Command status code:
|
||||
** - @ref ESP_GATT_OK: If request succeeds
|
||||
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or char_result parameter is NULL.
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_get_first_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_bt_uuid_t *char_uuid_cond,
|
||||
esp_gattc_char_id_t *char_result,
|
||||
esp_gatt_char_prop_t *property);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_first_char_descr
|
||||
**
|
||||
** @brief This function is called to find the first characteristic descriptor of the
|
||||
** characteristic on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] char_id: the characteristic ID of which the descriptor is belonged to.
|
||||
** @param[in] descr_uuid_cond: Characteristic Descr UUID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] descr_result: output parameter which will store the GATT
|
||||
** characteristic descriptor ID.
|
||||
**
|
||||
** @return Command status code:
|
||||
** - @ref ESP_GATT_OK: If request succeeds
|
||||
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the char_id or descr_result parameter is NULL.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_get_first_char_descr (uint16_t conn_id, esp_gattc_char_id_t *char_id,
|
||||
esp_bt_uuid_t *descr_uuid_cond,
|
||||
esp_gattc_char_descr_id_t *descr_result);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_next_inclu_srvc
|
||||
**
|
||||
** @brief This function is called to find the next included service of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] start_id: start the search from the next record
|
||||
** after the one identified by p_start_id.
|
||||
** @param[in] uuid_cond: Included service UUID, if NULL find the first available
|
||||
** included service.
|
||||
** @param[in] result: output parameter which will store the GATT ID
|
||||
** of the included service found.
|
||||
**
|
||||
** @return Command status code:
|
||||
** - @ref ESP_GATT_OK: If request succeeds
|
||||
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the p_char_id or p_descr_result parameter is NULL.
|
||||
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_get_next_inclu_srvc (uint16_t conn_id,
|
||||
esp_gattc_incl_srvc_id_t *start_id,
|
||||
esp_bt_uuid_t *uuid_cond,
|
||||
esp_gattc_incl_srvc_id_t *result);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_next_char
|
||||
**
|
||||
** @brief This function is called to find the next characteristic of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] start_char_id: start the characteristic search from the next record
|
||||
** after the one identified by char_id.
|
||||
** @param[in] char_uuid_cond: Characteristic UUID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] char_result: output parameter which will store the GATT
|
||||
** characteristic ID.
|
||||
** @param[in] property: output parameter to carry the characteristic property.
|
||||
**
|
||||
** @return Command status code:
|
||||
** - @ref ESP_GATT_OK: If request succeeds
|
||||
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_char_id or char_result parameter is NULL.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_get_next_char (uint16_t conn_id,
|
||||
esp_gattc_char_id_t *start_char_id,
|
||||
esp_bt_uuid_t *char_uuid_cond,
|
||||
esp_gattc_char_id_t *char_result,
|
||||
esp_gatt_char_prop_t *property);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_next_char_descr
|
||||
**
|
||||
** @brief This function is called to find the next characteristic descriptor
|
||||
** of the characterisctic.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] start_descr_id: start the descriptor search from the next record
|
||||
** after the one identified by p_start_descr_id.
|
||||
** @param[in] descr_uuid_cond: Characteristic descriptor UUID, if NULL find
|
||||
** the first available characteristic descriptor.
|
||||
** @param[in] descr_result: output parameter which will store the GATT
|
||||
** characteristic descriptor ID.
|
||||
**
|
||||
** @return Command status code:
|
||||
** - @ref ESP_GATT_OK: If request succeeds
|
||||
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the start_descr_id or descr_result parameter is NULL.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_get_next_char_descr (uint16_t conn_id,
|
||||
esp_gattc_char_descr_id_t *start_descr_id,
|
||||
esp_bt_uuid_t *descr_uuid_cond,
|
||||
esp_gattc_char_descr_id_t *descr_result);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_first_inclu_srvc
|
||||
**
|
||||
** @brief This function is called to find the first included service of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
** @param[in] uuid_cond: Characteristic UUID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] result: output parameter which will store the GATT ID
|
||||
** of the included service found.
|
||||
**
|
||||
** @return Command status code:
|
||||
** - @ref ESP_GATT_OK: If request succeeds
|
||||
** - @ref ESP_GATT_ILLEGAL_PARAMETER: If the srvc_id or result parameter is NULL.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_get_first_inclu_srvc (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_bt_uuid_t *uuid_cond, esp_gattc_incl_srvc_id_t *result);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char
|
||||
**
|
||||
** @brief This function is called to read a service's characteristics of
|
||||
** the given characteritisc ID.
|
||||
**
|
||||
** @param[in] conn_id - connectino ID.
|
||||
** @param[in] char_id - characteritic ID to read.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_read_char (uint16_t conn_id, esp_gattc_char_id_t *char_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char_descr
|
||||
**
|
||||
** @brief This function is called to read a characteristics descriptor.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] descr_id - characteritic descriptor ID to read.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
esp_gattc_char_descr_id_t *descr_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_multi
|
||||
**
|
||||
** @brief This function is called to read multiple characteristic or
|
||||
** characteristic descriptors.
|
||||
**
|
||||
** @param[in] conn_id - connectino ID.
|
||||
** @param[in] read_multi - pointer to the read multiple parameter.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_read_multi (uint16_t conn_id, esp_gattc_multi_t *read_multi,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char_val
|
||||
**
|
||||
** @brief This function is called to write characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] char_id - characteristic ID to write.
|
||||
** @param[in] write_type - type of write.
|
||||
** @param[in] len: length of the data to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_write_char_val ( uint16_t conn_id,
|
||||
esp_gattc_char_id_t *char_id,
|
||||
esp_gattc_write_type_t write_type,
|
||||
uint16_t len,
|
||||
uint8_t *value,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char_descr
|
||||
**
|
||||
** @brief This function is called to write characteristic descriptor value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID
|
||||
** @param[in] char_descr_id - characteristic descriptor ID to write.
|
||||
** @param[in] write_type - write type.
|
||||
** @param[in] data - the value to be written.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
esp_gattc_char_descr_id_t *char_descr_id,
|
||||
esp_gattc_write_type_t write_type,
|
||||
esp_gatt_unfmt_t *data,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_prepa_write
|
||||
**
|
||||
** @brief This function is called to prepare write a characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] char_id - GATT characteritic ID of the service.
|
||||
** @param[in] offset - offset of the write value.
|
||||
** @param[in] len: length of the data to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_prepa_write (uint16_t conn_id, esp_gattc_char_id_t *char_id,
|
||||
uint16_t offset, uint16_t len, uint8_t *value,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_execu_write
|
||||
**
|
||||
** @brief This function is called to execute write a prepare write sequence.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] is_execute - execute or cancel.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_execu_write (uint16_t conn_id, BOOLEAN is_execute);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_send_ind_cfm
|
||||
**
|
||||
** @brief This function is called to send handle value confirmation.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] char_id - characteristic ID to confirm.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gattc_send_ind_cfm (uint16_t conn_id, esp_gattc_char_id_t *char_id);
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_register_ntf
|
||||
**
|
||||
** @brief This function is called to register for notification of a service.
|
||||
**
|
||||
** @param[in] client_if - client interface.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if registration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_register_ntf (esp_gattc_if_t client_if,
|
||||
BD_ADDR bda,
|
||||
esp_gattc_char_id_t *char_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_unregister_ntf
|
||||
**
|
||||
** @brief This function is called to de-register for notification of a service.
|
||||
**
|
||||
** @param[in] client_if - client interface.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if deregistration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
tBTA_GATT_STATUS esp_ble_gattc_unregister_ntf (esp_gattc_if_t client_if,
|
||||
BD_ADDR bda,
|
||||
esp_gattc_char_id_t *char_id);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_disale
|
||||
**
|
||||
** @brief This function is called to disable GATTS module
|
||||
**
|
||||
** @param[in] None.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_disale(void);
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_app_register
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with BTA GATTS module.
|
||||
**
|
||||
** @param[in] app_uuid - applicaiton UUID
|
||||
** @param[in] cback - pointer to the application callback function.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_app_register(esp_bt_uuid_t *app_uuid, esp_gatts_cb_t *cback);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_app_unregister
|
||||
**
|
||||
** @brief un-register with GATT Server.
|
||||
**
|
||||
** @param[in] server_if: service interface id.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_app_unregister(esp_gatts_if_t server_if);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_create_srvc
|
||||
**
|
||||
** @brief Create a service. When service creation is done, a callback
|
||||
** event BTA_GATTS_CREATE_SRVC_EVT is called to report status
|
||||
** and service ID to the profile. The service ID obtained in
|
||||
** the callback function needs to be used when adding included
|
||||
** service and characteristics/descriptors into the service.
|
||||
**
|
||||
** @param[in] server_if: Profile ID this service is belonged to.
|
||||
** @param[in] service_uuid: service UUID.
|
||||
** @param[in] inst: instance ID number of this service.
|
||||
** @param[in] num_handle: numble of handle requessted for this service.
|
||||
** @param[in] is_primary: is this service a primary one or not.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_create_srvc(esp_gatts_if_t server_if, esp_bt_uuid_t *service_uuid, uint8_t inst,
|
||||
uint16_t num_handle, BOOLEAN is_primary);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_inclu_srvc
|
||||
**
|
||||
** @brief This function is called to add an included service. After included
|
||||
** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
|
||||
** is reported the included service ID.
|
||||
**
|
||||
** @param[in] service_id: service ID to which this included service is to
|
||||
** be added.
|
||||
** @param[in] included_service_id: the service ID to be included.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_add_inclu_srvc (uint16_t service_id, uint16_t included_service_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_char
|
||||
**
|
||||
** @brief This function is called to add a characteristic into a service.
|
||||
**
|
||||
** @param[in] service_id: service ID to which this included service is to
|
||||
** be added.
|
||||
** @param[in] char_uuid : Characteristic UUID.
|
||||
** @param[in] perm : Characteristic value declaration attribute permission.
|
||||
** @param[in] property : Characteristic Properties
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_add_char (uint16_t service_id, esp_bt_uuid_t *char_uuid,
|
||||
esp_gatt_perm_t perm, esp_gatt_char_prop_t property);
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_char_descr
|
||||
**
|
||||
** @brief This function is called to add characteristic descriptor. When
|
||||
** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
|
||||
** to report the status and an ID number for this descriptor.
|
||||
**
|
||||
** @param[in] service_id: service ID to which this charatceristic descriptor is to
|
||||
** be added.
|
||||
** @param[in] perm: descriptor access permission.
|
||||
** @param[in] descr_uuid: descriptor UUID.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_add_char_descr (uint16_t service_id,
|
||||
esp_gatt_perm_t perm,
|
||||
esp_bt_uuid_t * descr_uuid);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_dele_srvc
|
||||
**
|
||||
** @brief This function is called to delete a service. When this is done,
|
||||
** a callback event BTA_GATTS_DELETE_EVT is report with the status.
|
||||
**
|
||||
** @param[in] service_id: service_id to be deleted.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_dele_srvc (uint16_t service_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_start_srvc
|
||||
**
|
||||
** @brief This function is called to start a service.
|
||||
**
|
||||
** @param[in] service_id: the service ID to be started.
|
||||
** @param[in] sup_transport: supported trasnport.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_start_srvc(uint16_t service_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_stop_srvc
|
||||
**
|
||||
** @brief This function is called to stop a service.
|
||||
**
|
||||
** @param[in] service_id - service to be topped.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_stop_srvc(uint16_t service_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_hdl_val_indica
|
||||
**
|
||||
** @brief This function is called to read a characteristics descriptor.
|
||||
**
|
||||
** @param[in] bda - remote device bd address to indicate.
|
||||
** @param[in] attr_id - attribute ID to indicate.
|
||||
** @param[in] data_len - indicate data length.
|
||||
** @param[in] data: data to indicate.
|
||||
** @param[in] need_confirm - if this indication expects a confirmation or not.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_hdl_val_indica (uint16_t conn_id, uint16_t attr_id, uint16_t data_len,
|
||||
uint8_t *data, BOOLEAN need_confirm);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_send_rsp
|
||||
**
|
||||
** @brief This function is called to send a response to a request.
|
||||
**
|
||||
** @param[in] conn_id - connection identifier.
|
||||
** @param[in] trans_id - transaction ID.
|
||||
** @param[in] status - response status
|
||||
** @param[in] msg - response data.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_send_rsp (uint16_t conn_id, uint32_t trans_id,
|
||||
esp_gatt_status_t status, esp_gatts_rsp_t *msg);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_conn
|
||||
**
|
||||
** @brief Open a direct open connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] server_if: server interface.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_cancel_conn
|
||||
**
|
||||
** @brief Cancel a direct open connection or remove a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] server_if: server interface.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_cancel_conn (esp_gatts_if_t server_if, BD_ADDR remote_bda, BOOLEAN is_direct);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_close
|
||||
**
|
||||
** @brief Close a connection a remote device.
|
||||
**
|
||||
** @param[in] conn_id: connectino ID to be closed.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_ble_gatts_close(uint16_t conn_id);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_prf_app_register
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with BTA GATTS module.
|
||||
**
|
||||
** @param[in] prf_id - the profile identification
|
||||
** @param[in] p_cback - pointer to the application callback function.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
void esp_prf_app_register(uint8_t prf_id, void *p_cback);
|
||||
|
||||
|
||||
|
31
components/bt/bluedroid/stack_api/include/bt_app_common.h
Normal file
31
components/bt/bluedroid/stack_api/include/bt_app_common.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef __BT_APP_COMMON_H__
|
||||
#define __BT_APP_COMMON_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "osi.h"
|
||||
#include "bt_common_types.h"
|
||||
#include "bt_defs.h"
|
||||
|
||||
/* BT APP Events */
|
||||
#define BT_EVT_APP (0xB000)
|
||||
#define BT_EVT_APP_CONTEXT_SWITCH (0x0001 | BT_EVT_APP)
|
||||
|
||||
typedef void (tBTAPP_CBACK) (uint16_t event, char *p_param);
|
||||
typedef void (tBTAPP_COPY_CBACK) (uint16_t event, char *p_dest, char *p_src);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
BT_HDR hdr;
|
||||
tBTAPP_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 */
|
||||
} tBTAPP_CONTEXT_SWITCH_CBACK;
|
||||
|
||||
bt_status_t bt_app_transfer_context (tBTAPP_CBACK *p_cback, UINT16 event, char* p_params, int param_len, tBTAPP_COPY_CBACK *p_copy_cback);
|
||||
|
||||
void bt_app_init_ok(UNUSED_ATTR uint16_t event, UNUSED_ATTR char *p_param);
|
||||
|
||||
void bt_app_task_start_up(void);
|
||||
#endif /* __BT_APP_COMMON_H__ */
|
332
components/bt/bluedroid/stack_api/include/bt_app_defs.h
Normal file
332
components/bt/bluedroid/stack_api/include/bt_app_defs.h
Normal file
@@ -0,0 +1,332 @@
|
||||
|
||||
#ifndef _BT_APP_DEFS_H__
|
||||
#define _BT_APP_DEFS_H__
|
||||
|
||||
|
||||
#include "bta_api.h"
|
||||
#include "btm_ble_api.h"
|
||||
#include "bta_gatt_api.h"
|
||||
|
||||
#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */
|
||||
|
||||
#define ESP_BLE_ADV_CHNL_MAP (ESP_BLE_ADV_CHNL_37|ESP_BLE_ADV_CHNL_38|ESP_BLE_ADV_CHNL_39)
|
||||
|
||||
/* advertising channel map */
|
||||
#define ESP_BLE_ADV_CHNL_37 (0x01 << 0)
|
||||
#define ESP_BLE_ADV_CHNL_38 (0x01 << 1)
|
||||
#define ESP_BLE_ADV_CHNL_39 (0x01 << 2)
|
||||
|
||||
typedef tBTA_GATT_STATUS esp_gatt_status_t;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef UINT16 gatt_size_t;
|
||||
typedef tBT_UUID esp_bt_uuid_t;
|
||||
typedef tBTA_GATT_ID esp_gatt_id_t;
|
||||
|
||||
typedef tBTA_BLE_AD_MASK esp_ble_ad_mask_t;
|
||||
typedef tGATT_IF esp_gatt_if_t;
|
||||
typedef tBTA_GATT_SRVC_ID esp_gatt_srvc_id_t;
|
||||
typedef tBTA_GATTC_CHAR_ID esp_gattc_char_id_t;
|
||||
typedef tBTA_GATTC_CHAR_DESCR_ID esp_gattc_char_descr_id_t;
|
||||
typedef tBTA_GATTC_INCL_SVC_ID esp_gattc_incl_srvc_id_t;
|
||||
typedef tBTA_GATT_AUTH_REQ esp_gatt_auth_req_t;
|
||||
typedef tBTA_GATTC_MULTI esp_gattc_multi_t;
|
||||
typedef tBTA_GATTC_WRITE_TYPE esp_gattc_write_type_t;
|
||||
typedef tBTA_GATT_UNFMT esp_gatt_unfmt_t;
|
||||
typedef tBTA_GATT_PERM esp_gatt_perm_t;
|
||||
typedef tBTA_GATT_CHAR_PROP esp_gatt_char_prop_t;
|
||||
typedef tBTA_GATTC esp_gattc_t;
|
||||
|
||||
typedef tBTA_GATTC_EVT esp_gattc_evt_t;
|
||||
|
||||
typedef tBTA_GATTC_IF esp_gattc_if_t;
|
||||
|
||||
|
||||
|
||||
/* Client callback function events */
|
||||
#define ESP_GATTC_REG_EVT 0 /* GATT client is registered. */
|
||||
#define ESP_GATTC_DEREG_EVT 1 /* GATT client deregistered event */
|
||||
#define ESP_GATTC_OPEN_EVT 2 /* GATTC open request status event */
|
||||
#define ESP_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */
|
||||
#define ESP_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */
|
||||
#define ESP_GATTC_CLOSE_EVT 5 /* GATTC close request status event */
|
||||
#define ESP_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */
|
||||
#define ESP_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */
|
||||
#define ESP_GATTC_READ_DESCR_EVT 8 /* GATT read characterisitc descriptor event */
|
||||
#define ESP_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */
|
||||
#define ESP_GATTC_NOTIF_EVT 10 /* GATT attribute notification event */
|
||||
#define ESP_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */
|
||||
#define ESP_GATTC_EXEC_EVT 12 /* execute write complete event */
|
||||
#define ESP_GATTC_ACL_EVT 13 /* ACL up event */
|
||||
#define ESP_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
|
||||
#define ESP_GATTC_SRVC_CHG_EVT 15 /* service change event */
|
||||
#define ESP_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
|
||||
#define ESP_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */
|
||||
#define ESP_GATTC_ADV_DATA_EVT 19 /* ADV data event */
|
||||
#define ESP_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */
|
||||
#define ESP_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */
|
||||
#define ESP_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */
|
||||
#define ESP_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */
|
||||
#define ESP_GATTC_CONGEST_EVT 24 /* Congestion event */
|
||||
#define ESP_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */
|
||||
#define ESP_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */
|
||||
#define ESP_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */
|
||||
#define ESP_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */
|
||||
#define ESP_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */
|
||||
#define ESP_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */
|
||||
#define ESP_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */
|
||||
#define ESP_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */
|
||||
#define ESP_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */
|
||||
#define ESP_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
|
||||
|
||||
|
||||
/* GATT Server Data Structure */
|
||||
/* Server callback function events */
|
||||
#define ESP_GATTS_REG_EVT 0
|
||||
#define ESP_GATTS_READ_EVT GATTS_REQ_TYPE_READ /* 1 */
|
||||
#define ESP_GATTS_WRITE_EVT GATTS_REQ_TYPE_WRITE /* 2 */
|
||||
#define ESP_GATTS_EXEC_WRITE_EVT GATTS_REQ_TYPE_WRITE_EXEC /* 3 */
|
||||
#define ESP_GATTS_MTU_EVT GATTS_REQ_TYPE_MTU /* 4 */
|
||||
#define ESP_GATTS_CFM_EVT GATTS_REQ_TYPE_CONF /* 5 */
|
||||
#define ESP_GATTS_DEREG_EVT 6
|
||||
#define ESP_GATTS_CREATE_EVT 7
|
||||
#define ESP_GATTS_ADD_INCL_SRVC_EVT 8
|
||||
#define ESP_GATTS_ADD_CHAR_EVT 9
|
||||
#define ESP_GATTS_ADD_CHAR_DESCR_EVT 10
|
||||
#define ESP_GATTS_DELELTE_EVT 11
|
||||
#define ESP_GATTS_START_EVT 12
|
||||
#define ESP_GATTS_STOP_EVT 13
|
||||
#define ESP_GATTS_CONNECT_EVT 14
|
||||
#define ESP_GATTS_DISCONNECT_EVT 15
|
||||
#define ESP_GATTS_OPEN_EVT 16
|
||||
#define ESP_GATTS_CANCEL_OPEN_EVT 17
|
||||
#define ESP_GATTS_CLOSE_EVT 18
|
||||
#define ESP_GATTS_CONGEST_EVT 20
|
||||
|
||||
/* Attribute permissions
|
||||
*/
|
||||
#define ESP_GATT_PERM_READ BTA_GATT_PERM_READ /* bit 0 - 0x0001 */
|
||||
#define ESP_GATT_PERM_READ_ENCRYPTED BTA_GATT_PERM_READ_ENCRYPTED /* bit 1 - 0x0002 */
|
||||
#define ESP_GATT_PERM_READ_ENC_MITM BTA_GATT_PERM_READ_ENC_MITM /* bit 2 - 0x0004 */
|
||||
#define ESP_GATT_PERM_WRITE BTA_GATT_PERM_WRITE /* bit 4 - 0x0010 */
|
||||
#define ESP_GATT_PERM_WRITE_ENCRYPTED BTA_GATT_PERM_WRITE_ENCRYPTED /* bit 5 - 0x0020 */
|
||||
#define ESP_GATT_PERM_WRITE_ENC_MITM BTA_GATT_PERM_WRITE_ENC_MITM /* bit 6 - 0x0040 */
|
||||
#define ESP_GATT_PERM_WRITE_SIGNED BTA_GATT_PERM_WRITE_SIGNED /* bit 7 - 0x0080 */
|
||||
#define ESP_GATT_PERM_WRITE_SIGNED_MITM BTA_GATT_PERM_WRITE_SIGNED_MITM /* bit 8 - 0x0100 */
|
||||
|
||||
#define ESP_GATTS_INVALID_APP 0xff
|
||||
|
||||
#define ESP_GATTS_INVALID_IF 0
|
||||
|
||||
/* definition of characteristic properties */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_BROADCAST BTA_GATT_CHAR_PROP_BIT_BROADCAST /* 0x01 */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_READ BTA_GATT_CHAR_PROP_BIT_READ /* 0x02 */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_WRITE_NR BTA_GATT_CHAR_PROP_BIT_WRITE_NR /* 0x04 */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_WRITE BTA_GATT_CHAR_PROP_BIT_WRITE /* 0x08 */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_NOTIFY BTA_GATT_CHAR_PROP_BIT_NOTIFY /* 0x10 */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_INDICATE BTA_GATT_CHAR_PROP_BIT_INDICATE /* 0x20 */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_AUTH BTA_GATT_CHAR_PROP_BIT_AUTH /* 0x40 */
|
||||
#define ESP_GATT_CHAR_PROP_BIT_EXT_PROP BTA_GATT_CHAR_PROP_BIT_EXT_PROP /* 0x80 */
|
||||
|
||||
typedef tBTA_GATTS_EVT esp_gatts_evt_t;
|
||||
typedef tBTA_GATTS_IF esp_gatts_if_t;
|
||||
|
||||
/* attribute value */
|
||||
typedef tBTA_GATT_VALUE esp_gatt_value_t;
|
||||
|
||||
/* attribute response data */
|
||||
typedef tBTA_GATTS_RSP esp_gatts_rsp_t;
|
||||
|
||||
typedef tBTA_GATTS esp_gatts_t;
|
||||
|
||||
/* attribute request data from the client */
|
||||
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
|
||||
#define ESP_GATT_PREP_WRITE_EXEC 0x01
|
||||
typedef tBTA_GATT_EXEC_FLAG esp_gatt_exec_flag_t;
|
||||
|
||||
/* read request always based on UUID */
|
||||
typedef tBTA_GATT_READ_REQ esp_gatt_read_req_t;
|
||||
|
||||
/* write request data */
|
||||
typedef tBTA_GATT_WRITE_REQ esp_gatt_write_req_t;
|
||||
|
||||
/* callback data for server access request from client */
|
||||
typedef tBTA_GATTS_REQ_DATA esp_gatts_req_data_t;
|
||||
|
||||
|
||||
/* Search callback */
|
||||
typedef tBTA_DM_SEARCH_CBACK esp_dm_search_cb_t;
|
||||
|
||||
typedef tBLE_SCAN_PARAM_SETUP_CBACK esp_scan_param_setup_cb_t;
|
||||
|
||||
|
||||
typedef tBTA_SET_ADV_DATA_CMPL_CBACK esp_ble_set_adv_data_cmpl_cb_t;
|
||||
|
||||
/* GATTC enable callback function */
|
||||
typedef void (esp_gattc_enb_cb_t)(esp_gatt_status_t status);
|
||||
|
||||
/* Client callback function */
|
||||
typedef void (esp_gattc_cb_t)(esp_gattc_evt_t event, esp_gattc_t *cb_data);
|
||||
|
||||
|
||||
/* GATTS enable callback function */
|
||||
typedef void (esp_gatts_enb_cb_t)(esp_gatt_status_t status);
|
||||
|
||||
/* Server callback function */
|
||||
typedef void (esp_gatts_cb_t)(esp_gatts_evt_t event, esp_gatts_t *cb_data);
|
||||
|
||||
|
||||
/* Success code and error codes */
|
||||
#define ESP_GATT_OK BTA_GATT_OK
|
||||
#define ESP_GATT_INVALID_HANDLE BTA_GATT_INVALID_HANDLE /* 0x0001 */
|
||||
#define ESP_GATT_READ_NOT_PERMIT BTA_GATT_READ_NOT_PERMIT /* 0x0002 */
|
||||
#define ESP_GATT_WRITE_NOT_PERMIT BTA_GATT_WRITE_NOT_PERMIT /* 0x0003 */
|
||||
#define ESP_GATT_INVALID_PDU BTA_GATT_INVALID_PDU /* 0x0004 */
|
||||
#define ESP_GATT_INSUF_AUTHENTICATION BTA_GATT_INSUF_AUTHENTICATION /* 0x0005 */
|
||||
#define ESP_GATT_REQ_NOT_SUPPORTED BTA_GATT_REQ_NOT_SUPPORTED /* 0x0006 */
|
||||
#define ESP_GATT_INVALID_OFFSET BTA_GATT_INVALID_OFFSET /* 0x0007 */
|
||||
#define ESP_GATT_INSUF_AUTHORIZATION BTA_GATT_INSUF_AUTHORIZATION /* 0x0008 */
|
||||
#define ESP_GATT_PREPARE_Q_FULL BTA_GATT_PREPARE_Q_FULL /* 0x0009 */
|
||||
#define ESP_GATT_NOT_FOUND BTA_GATT_NOT_FOUND /* 0x000a */
|
||||
#define ESP_GATT_NOT_LONG BTA_GATT_NOT_LONG /* 0x000b */
|
||||
#define ESP_GATT_INSUF_KEY_SIZE BTA_GATT_INSUF_KEY_SIZE /* 0x000c */
|
||||
#define ESP_GATT_INVALID_ATTR_LEN BTA_GATT_INVALID_ATTR_LEN /* 0x000d */
|
||||
#define ESP_GATT_ERR_UNLIKELY BTA_GATT_ERR_UNLIKELY /* 0x000e */
|
||||
#define ESP_GATT_INSUF_ENCRYPTION BTA_GATT_INSUF_ENCRYPTION /* 0x000f */
|
||||
#define ESP_GATT_UNSUPPORT_GRP_TYPE BTA_GATT_UNSUPPORT_GRP_TYPE /* 0x0010 */
|
||||
#define ESP_GATT_INSUF_RESOURCE BTA_GATT_INSUF_RESOURCE /* 0x0011 */
|
||||
|
||||
|
||||
#define ESP_GATT_NO_RESOURCES BTA_GATT_NO_RESOURCES /* 0x80 */
|
||||
#define ESP_GATT_INTERNAL_ERROR BTA_GATT_INTERNAL_ERROR /* 0x81 */
|
||||
#define ESP_GATT_WRONG_STATE BTA_GATT_WRONG_STATE /* 0x82 */
|
||||
#define ESP_GATT_DB_FULL BTA_GATT_DB_FULL /* 0x83 */
|
||||
#define ESP_GATT_BUSY BTA_GATT_BUSY /* 0x84 */
|
||||
#define ESP_GATT_ERROR BTA_GATT_ERROR /* 0x85 */
|
||||
#define ESP_GATT_CMD_STARTED BTA_GATT_CMD_STARTED /* 0x86 */
|
||||
#define ESP_GATT_ILLEGAL_PARAMETER BTA_GATT_ILLEGAL_PARAMETER /* 0x87 */
|
||||
#define ESP_GATT_PENDING BTA_GATT_PENDING /* 0x88 */
|
||||
#define ESP_GATT_AUTH_FAIL BTA_GATT_AUTH_FAIL /* 0x89 */
|
||||
#define ESP_GATT_MORE BTA_GATT_MORE /* 0x8a */
|
||||
#define ESP_GATT_INVALID_CFG BTA_GATT_INVALID_CFG /* 0x8b */
|
||||
#define ESP_GATT_SERVICE_STARTED BTA_GATT_SERVICE_STARTED /* 0x8c */
|
||||
#define ESP_GATT_ENCRYPED_MITM BTA_GATT_ENCRYPED_MITM /* GATT_SUCCESS */
|
||||
#define ESP_GATT_ENCRYPED_NO_MITM BTA_GATT_ENCRYPED_NO_MITM /* 0x8d */
|
||||
#define ESP_GATT_NOT_ENCRYPTED BTA_GATT_NOT_ENCRYPTED /* 0x8e */
|
||||
#define ESP_GATT_CONGESTED BTA_GATT_CONGESTED /* 0x8f */
|
||||
|
||||
#define ESP_GATT_DUP_REG BTA_GATT_DUP_REG /* 0x90 */
|
||||
#define ESP_GATT_ALREADY_OPEN BTA_GATT_ALREADY_OPEN /* 0x91 */
|
||||
#define ESP_GATT_CANCEL BTA_GATT_CANCEL /* 0x92 */
|
||||
|
||||
/* 0xE0 ~ 0xFC reserved for future use */
|
||||
#define ESP_GATT_CCC_CFG_ERR BTA_GATT_CCC_CFG_ERR /* 0xFD Client Characteristic Configuration Descriptor Improperly Configured */
|
||||
#define ESP_GATT_PRC_IN_PROGRESS BTA_GATT_PRC_IN_PROGRESS /* 0xFE Procedure Already in progress */
|
||||
#define ESP_GATT_OUT_OF_RANGE BTA_GATT_OUT_OF_RANGE /* 0xFFAttribute value out of range */
|
||||
|
||||
|
||||
|
||||
#define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
|
||||
|
||||
|
||||
enum
|
||||
{
|
||||
BLE_ADV_DATA_IDX,
|
||||
BLE_SCAN_RSP_DATA_IDX,
|
||||
ADV_SCAN_IDX_MAX
|
||||
};
|
||||
|
||||
/// Advertising mode
|
||||
enum api_adv_type
|
||||
{
|
||||
/// Mode in non-discoverable
|
||||
API_NON_DISCOVERABLE,
|
||||
/// Mode in general discoverable
|
||||
API_GEN_DISCOVERABLE,
|
||||
/// Mode in limited discoverable
|
||||
API_LIM_DISCOVERABLE,
|
||||
/// Broadcaster mode which is a non discoverable and non connectable mode.
|
||||
API_BROADCASTER_MODE,
|
||||
};
|
||||
|
||||
enum api_adv_filter
|
||||
{
|
||||
///Allow both scan and connection requests from anyone
|
||||
ADV_ALLOW_SCAN_ANY_CON_ANY = 0x00,
|
||||
///Allow both scan req from White List devices only and connection req from anyone
|
||||
ADV_ALLOW_SCAN_WLST_CON_ANY,
|
||||
///Allow both scan req from anyone and connection req from White List devices only
|
||||
ADV_ALLOW_SCAN_ANY_CON_WLST,
|
||||
///Allow scan and connection requests from White List devices only
|
||||
ADV_ALLOW_SCAN_WLST_CON_WLST,
|
||||
///Enumeration end value for advertising filter policy value check
|
||||
ADV_ALLOW_SCAN_END
|
||||
};
|
||||
|
||||
/// Own BD address source of the device
|
||||
enum api_own_addr_src
|
||||
{
|
||||
/// Public Address
|
||||
API_PUBLIC_ADDR,
|
||||
/// Provided random address
|
||||
API_PROVIDED_RND_ADDR,
|
||||
/// Provided static random address
|
||||
API_GEN_STATIC_RND_ADDR,
|
||||
/// Generated resolvable private random address
|
||||
API_GEN_RSLV_ADDR,
|
||||
/// Generated non-resolvable private random address
|
||||
API_GEN_NON_RSLV_ADDR,
|
||||
/// Provided Reconnection address
|
||||
API_PROVIDED_RECON_ADDR,
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *adv_name; //set the device name to be sent on the advertising
|
||||
tBTA_BLE_ADV_DATA ble_adv_data;
|
||||
}esp_ble_adv_data_cfg_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT16 adv_int_min;
|
||||
UINT16 adv_int_max;
|
||||
tBLE_BD_ADDR *p_dir_bda;
|
||||
}esp_ble_adv_params_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT16 adv_int_min;
|
||||
UINT16 adv_int_max;
|
||||
UINT8 adv_type;
|
||||
tBLE_ADDR_TYPE addr_type_own;
|
||||
tBTM_BLE_ADV_CHNL_MAP channel_map;
|
||||
tBTM_BLE_AFP adv_filter_policy;
|
||||
tBLE_BD_ADDR *p_dir_bda;
|
||||
}esp_ble_adv_params_all_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UINT8 scan_type;
|
||||
UINT16 scan_intv;
|
||||
UINT16 scan_win;
|
||||
UINT8 addr_type_own;
|
||||
UINT8 scan_fil_policy;
|
||||
}esp_ble_scan_params;
|
||||
|
||||
|
||||
extern void ble_config_adv_data(esp_ble_adv_data_cfg_t *adv_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK *p_adv_data_cback);
|
||||
|
||||
extern void ble_set_scan_rsp(esp_ble_adv_data_cfg_t *scan_rsp_data,
|
||||
tBTA_SET_ADV_DATA_CMPL_CBACK *p_scan_rsp_data_cback);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif ///_BT_APP_DEFS_H__
|
78
components/bt/bluedroid/stack_api/include/bt_app_sec.h
Normal file
78
components/bt/bluedroid/stack_api/include/bt_app_sec.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
****************************************************************************************
|
||||
*
|
||||
* @file bt_app_sec.h
|
||||
*
|
||||
* @brief Application entry point
|
||||
*
|
||||
* Copyright (C) Espressif 2016
|
||||
* Created by Yulong at 2016/10/13
|
||||
*
|
||||
*
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
#include "bt_types.h"
|
||||
|
||||
#define APP_SEC_IRK_FLAG (0)
|
||||
#define RAND_NB_LEN 0x08
|
||||
#define SEC_KEY_LEN 0x10
|
||||
|
||||
/*
|
||||
* STRUCTURES DEFINITIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/// Generic Security key structure
|
||||
typedef struct
|
||||
{
|
||||
/// Key value MSB -> LSB
|
||||
UINT8 key[SEC_KEY_LEN];
|
||||
}smp_sec_key;
|
||||
|
||||
///Random number structure
|
||||
typedef struct
|
||||
{
|
||||
///8-byte array for random number
|
||||
UINT8 nb[RAND_NB_LEN];
|
||||
}rand_nb;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
// LTK
|
||||
smp_sec_key ltk;
|
||||
// Random Number
|
||||
rand_nb rand_nb;
|
||||
// EDIV
|
||||
UINT16 ediv;
|
||||
// LTK key size
|
||||
UINT8 key_size;
|
||||
|
||||
// Last paired peer address type
|
||||
UINT8 peer_addr_type;
|
||||
// Last paired peer address
|
||||
BD_ADDR peer_addr;
|
||||
|
||||
// authentication level
|
||||
UINT8 auth;
|
||||
|
||||
}tAPP_SEC_ENV;
|
||||
|
||||
extern tAPP_SEC_ENV app_sec_env;
|
||||
|
||||
/*
|
||||
* GLOBAL FUNCTIONS DECLARATIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
void app_ble_sec_init(void);
|
||||
|
||||
void app_ble_sec_pairing_cmp_evt_send(UINT8);
|
||||
|
||||
UINT32 app_ble_sec_gen_tk(void);
|
||||
|
||||
void app_ble_sec_gen_ltk(UINT8 key_size);
|
||||
|
||||
void app_ble_security_start(void);
|
||||
|
Reference in New Issue
Block a user