From 99872beb6a0115430ba39674ae621f03c254557c Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Mon, 26 Mar 2018 17:02:24 +0800 Subject: [PATCH] Component/bt: add set gap icon API --- components/bt/bluedroid/api/esp_gap_ble_api.c | 15 ++++++++++++ .../bluedroid/api/include/esp_gap_ble_api.h | 14 +++++++++++ components/bt/bluedroid/bta/dm/bta_dm_act.c | 13 ++++++++++ components/bt/bluedroid/bta/dm/bta_dm_api.c | 24 +++++++++++++++++++ components/bt/bluedroid/bta/dm/bta_dm_main.c | 1 + components/bt/bluedroid/bta/include/bta_api.h | 13 ++++++++++ .../bt/bluedroid/bta/include/bta_dm_int.h | 8 +++++++ .../btc/profile/std/gap/btc_gap_ble.c | 8 +++++++ .../btc/profile/std/include/btc_gap_ble.h | 5 ++++ .../bt/bluedroid/stack/btm/btm_ble_gap.c | 20 ++++++++++++++++ .../bt/bluedroid/stack/include/btm_ble_api.h | 12 ++++++++++ 11 files changed, 133 insertions(+) diff --git a/components/bt/bluedroid/api/esp_gap_ble_api.c b/components/bt/bluedroid/api/esp_gap_ble_api.c index 84df9d613..ecfccca5b 100644 --- a/components/bt/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/bluedroid/api/esp_gap_ble_api.c @@ -195,6 +195,21 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable) return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } +esp_err_t esp_ble_gap_config_local_icon (uint16_t icon) +{ + btc_msg_t msg; + btc_ble_gap_args_t arg; + + ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_ACT_CONFIG_LOCAL_ICON; + arg.cfg_local_icon.icon = icon; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + esp_err_t esp_ble_gap_update_whitelist(bool add_remove, esp_bd_addr_t remote_bda) { btc_msg_t msg; diff --git a/components/bt/bluedroid/api/include/esp_gap_ble_api.h b/components/bt/bluedroid/api/include/esp_gap_ble_api.h index 3e0c16e34..baba893f1 100644 --- a/components/bt/bluedroid/api/include/esp_gap_ble_api.h +++ b/components/bt/bluedroid/api/include/esp_gap_ble_api.h @@ -775,6 +775,20 @@ esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr); */ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable); +/** + * @brief set local gap appearance icon + * + * + * @param[in] icon - Appearance value, these vlues are Defined by the Bluetooth organization, please refer to + * https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.gap.appearance.xml + * + * @return + * - ESP_OK : success + * - other : failed + * + */ +esp_err_t esp_ble_gap_config_local_icon (uint16_t icon); + /** * @brief Add or remove device from white list * diff --git a/components/bt/bluedroid/bta/dm/bta_dm_act.c b/components/bt/bluedroid/bta/dm/bta_dm_act.c index fb21560bf..7fb3ddac6 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_act.c @@ -4677,6 +4677,19 @@ void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data) } #endif +/******************************************************************************* +** +** Function bta_dm_ble_config_local_privacy +** +** Description This function set the local device LE privacy settings. +** +** +*******************************************************************************/ +void bta_dm_ble_config_local_icon (tBTA_DM_MSG *p_data) +{ + BTM_BleConfigLocalIcon (p_data->ble_local_icon.icon); +} + /******************************************************************************* ** ** Function bta_dm_ble_observe diff --git a/components/bt/bluedroid/bta/dm/bta_dm_api.c b/components/bt/bluedroid/bta/dm/bta_dm_api.c index 060692fcd..7558788be 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_api.c @@ -1629,6 +1629,30 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_ } #if BLE_INCLUDED == TRUE +/******************************************************************************* +** +** Function BTA_DmBleConfigLocalIcon +** +** Description set gap local icon +** +** Parameters: icon - appearance value. +** +** Returns void +** +*******************************************************************************/ +void BTA_DmBleConfigLocalIcon(uint16_t icon) +{ + tBTA_DM_API_LOCAL_ICON *p_msg; + + if ((p_msg = (tBTA_DM_API_LOCAL_ICON *) osi_malloc(sizeof(tBTA_DM_API_LOCAL_ICON))) != NULL) { + memset (p_msg, 0, sizeof(tBTA_DM_API_LOCAL_ICON)); + + p_msg->hdr.event = BTA_DM_API_LOCAL_ICON_EVT; + p_msg->icon = icon; + bta_sys_sendmsg(p_msg); + } +} + /******************************************************************************* ** ** Function BTA_BleEnableAdvInstance diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index ed118adfb..9d3b42d63 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -111,6 +111,7 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { #if BLE_PRIVACY_SPT == TRUE bta_dm_ble_config_local_privacy, /* BTA_DM_API_LOCAL_PRIVACY_EVT */ #endif + bta_dm_ble_config_local_icon, /* BTA_DM_API_LOCAL_ICON_EVT */ bta_dm_ble_set_adv_params, /* BTA_DM_API_BLE_ADV_PARAM_EVT */ bta_dm_ble_set_adv_params_all, /* BTA_DM_API_BLE_ADV_PARAM_All_EVT */ bta_dm_ble_set_adv_config, /* BTA_DM_API_BLE_SET_ADV_CONFIG_EVT */ diff --git a/components/bt/bluedroid/bta/include/bta_api.h b/components/bt/bluedroid/bta/include/bta_api.h index a13c08227..8df5952d6 100644 --- a/components/bt/bluedroid/bta/include/bta_api.h +++ b/components/bt/bluedroid/bta/include/bta_api.h @@ -2081,6 +2081,19 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_ *******************************************************************************/ extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback); +/******************************************************************************* +** +** Function BTA_DmBleConfigLocalIcon +** +** Description set gap local icon +** +** Parameters: icon - appearance value. +** +** Returns void +** +*******************************************************************************/ +extern void BTA_DmBleConfigLocalIcon(uint16_t icon); + /******************************************************************************* ** ** Function BTA_DmBleEnableRemotePrivacy diff --git a/components/bt/bluedroid/bta/include/bta_dm_int.h b/components/bt/bluedroid/bta/include/bta_dm_int.h index a95bb676e..a27c94979 100644 --- a/components/bt/bluedroid/bta/include/bta_dm_int.h +++ b/components/bt/bluedroid/bta/include/bta_dm_int.h @@ -108,6 +108,7 @@ enum { #if BLE_PRIVACY_SPT == TRUE BTA_DM_API_LOCAL_PRIVACY_EVT, #endif + BTA_DM_API_LOCAL_ICON_EVT, BTA_DM_API_BLE_ADV_PARAM_EVT, /*******This event added by Yulong at 2016/10/20 to @@ -468,6 +469,11 @@ typedef struct { tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback; } tBTA_DM_API_LOCAL_PRIVACY; +typedef struct { + BT_HDR hdr; + uint16_t icon; +} tBTA_DM_API_LOCAL_ICON; + /* set scan parameter for BLE connections */ typedef struct { BT_HDR hdr; @@ -775,6 +781,7 @@ typedef union { tBTA_DM_API_BLE_SCAN ble_scan; tBTA_DM_API_ENABLE_PRIVACY ble_remote_privacy; tBTA_DM_API_LOCAL_PRIVACY ble_local_privacy; + tBTA_DM_API_LOCAL_ICON ble_local_icon; tBTA_DM_API_BLE_ADV_PARAMS ble_set_adv_params; tBTA_DM_API_BLE_ADV_PARAMS_ALL ble_set_adv_params_all; tBTA_DM_API_SET_ADV_CONFIG ble_set_adv_data; @@ -1180,6 +1187,7 @@ extern void bta_dm_ble_disconnect (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_rand_address(tBTA_DM_MSG *p_data); extern void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data); extern void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data); +extern void bta_dm_ble_config_local_icon (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_params (tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_params_all(tBTA_DM_MSG *p_data); extern void bta_dm_ble_set_adv_config (tBTA_DM_MSG *p_data); diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index 19c47b607..93df5ba0d 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -848,6 +848,11 @@ static void btc_ble_set_pkt_data_len(BD_ADDR remote_device, uint16_t tx_data_len BTA_DmBleSetDataLength(remote_device, tx_data_length, p_set_pkt_data_cback); } +static void btc_ble_config_local_icon(uint16_t icon) +{ + BTA_DmBleConfigLocalIcon(icon); +} + static void btc_ble_set_rand_addr (BD_ADDR rand_addr, tBTA_SET_RAND_ADDR_CBACK *p_set_rand_addr_cback) { if (rand_addr != NULL) { @@ -1075,6 +1080,9 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY: btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable, btc_set_local_privacy_callback); break; + case BTC_GAP_BLE_ACT_CONFIG_LOCAL_ICON: + btc_ble_config_local_icon(arg->cfg_local_icon.icon); + break; case BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST: BTA_DmUpdateWhiteList(arg->update_white_list.add_remove, arg->update_white_list.remote_bda, btc_add_whitelist_complete_callback); break; diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h index ba744702b..9ee03d411 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -31,6 +31,7 @@ typedef enum { BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN, BTC_GAP_BLE_ACT_SET_RAND_ADDRESS, BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY, + BTC_GAP_BLE_ACT_CONFIG_LOCAL_ICON, BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST, BTC_GAP_BLE_ACT_SET_CONN_PARAMS, BTC_GAP_BLE_ACT_SET_DEV_NAME, @@ -83,6 +84,10 @@ typedef union { struct cfg_local_privacy_args { bool privacy_enable; } cfg_local_privacy; + //BTC_GAP_BLE_ACT_CONFIG_LOCAL_ICON, + struct cfg_local_icon_args { + uint16_t icon; + } cfg_local_icon; //BTC_GAP_BLE_ACT_UPDATE_WHITE_LIST struct update_white_list_args { bool add_remove; diff --git a/components/bt/bluedroid/stack/btm/btm_ble_gap.c b/components/bt/bluedroid/stack/btm/btm_ble_gap.c index b5faafe16..4d1bf10f9 100644 --- a/components/bt/bluedroid/stack/btm/btm_ble_gap.c +++ b/components/bt/bluedroid/stack/btm/btm_ble_gap.c @@ -812,6 +812,26 @@ BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK #endif } +/******************************************************************************* +** +** Function BTM_BleConfigLocalIcon +** +** Description This function is called to set local icon +** +** Parameters icon: appearance value. +** +** +*******************************************************************************/ +void BTM_BleConfigLocalIcon(uint16_t icon) +{ +#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE && GATTS_INCLUDED == TRUE) + tGAP_BLE_ATTR_VALUE p_value; + p_value.icon = icon; + GAP_BleAttrDBUpdate(GATT_UUID_GAP_ICON, &p_value); +#else + BTM_TRACE_ERROR("%s\n", __func__); +#endif +} /******************************************************************************* ** ** Function BTM_BleMaxMultiAdvInstanceCount diff --git a/components/bt/bluedroid/stack/include/btm_ble_api.h b/components/bt/bluedroid/stack/include/btm_ble_api.h index 6d6837a3d..707be455a 100644 --- a/components/bt/bluedroid/stack/include/btm_ble_api.h +++ b/components/bt/bluedroid/stack/include/btm_ble_api.h @@ -1632,6 +1632,18 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start, tBTM_START_STOP_ADV_CMPL_CBACK *p_st //extern BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cabck); +/******************************************************************************* +** +** Function BTM_BleConfigLocalIcon +** +** Description This function is called to set local icon +** +** Parameters icon: appearance value. +** +** +*******************************************************************************/ +void BTM_BleConfigLocalIcon(uint16_t icon); + /******************************************************************************* ** ** Function BTM_BleLocalPrivacyEnabled