mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 03:34:32 +02:00
component/bt: move API to set device name that can be used by both bt and ble applications
This commit is contained in:
@@ -12,10 +12,13 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include "esp_bt_device.h"
|
#include "esp_bt_device.h"
|
||||||
#include "esp_bt_main.h"
|
#include "esp_bt_main.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
|
#include "btc_task.h"
|
||||||
|
#include "btc_dev.h"
|
||||||
|
|
||||||
const uint8_t *esp_bt_dev_get_address(void)
|
const uint8_t *esp_bt_dev_get_address(void)
|
||||||
{
|
{
|
||||||
@@ -24,3 +27,24 @@ const uint8_t *esp_bt_dev_get_address(void)
|
|||||||
}
|
}
|
||||||
return controller_get_interface()->get_address()->address;
|
return controller_get_interface()->get_address()->address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t esp_bt_dev_set_device_name(const char *name)
|
||||||
|
{
|
||||||
|
btc_msg_t msg;
|
||||||
|
btc_dev_args_t arg;
|
||||||
|
|
||||||
|
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||||
|
return ESP_ERR_INVALID_STATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(name) > ESP_DEV_DEVICE_NAME_MAX) {
|
||||||
|
return ESP_ERR_INVALID_ARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
msg.sig = BTC_SIG_API_CALL;
|
||||||
|
msg.pid = BTC_PID_DEV;
|
||||||
|
msg.act = BTC_DEV_ACT_SET_DEVICE_NAME;
|
||||||
|
strcpy(arg.set_dev_name.device_name, name);
|
||||||
|
|
||||||
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||||
|
}
|
||||||
|
@@ -13,7 +13,7 @@
|
|||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include "esp_bt_device.h"
|
||||||
#include "esp_bt_main.h"
|
#include "esp_bt_main.h"
|
||||||
#include "esp_gap_ble_api.h"
|
#include "esp_gap_ble_api.h"
|
||||||
#include "bta_api.h"
|
#include "bta_api.h"
|
||||||
@@ -217,23 +217,7 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
|
|||||||
|
|
||||||
esp_err_t esp_ble_gap_set_device_name(const char *name)
|
esp_err_t esp_ble_gap_set_device_name(const char *name)
|
||||||
{
|
{
|
||||||
btc_msg_t msg;
|
return esp_bt_dev_set_device_name(name);
|
||||||
btc_ble_gap_args_t arg;
|
|
||||||
|
|
||||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
||||||
return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (strlen(name) > ESP_GAP_DEVICE_NAME_MAX) {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.sig = BTC_SIG_API_CALL;
|
|
||||||
msg.pid = BTC_PID_GAP_BLE;
|
|
||||||
msg.act = BTC_GAP_BLE_ACT_SET_DEV_NAME;
|
|
||||||
strcpy(arg.set_dev_name.device_name, name);
|
|
||||||
|
|
||||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *length)
|
uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *length)
|
||||||
|
@@ -39,32 +39,4 @@ esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode)
|
|||||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
esp_err_t esp_bt_gap_set_device_name(const char *name)
|
|
||||||
{
|
|
||||||
btc_msg_t msg;
|
|
||||||
btc_gap_bt_args_t arg;
|
|
||||||
|
|
||||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
|
||||||
return ESP_ERR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (name != NULL) {
|
|
||||||
size_t len = strlen(name);
|
|
||||||
if (len > 0 || len <= ESP_BT_GAP_DEVICE_NAME_MAX) {
|
|
||||||
strcpy(arg.set_dev_name.device_name, name);
|
|
||||||
} else {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return ESP_ERR_INVALID_ARG;
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.sig = BTC_SIG_API_CALL;
|
|
||||||
msg.pid = BTC_PID_GAP_BT;
|
|
||||||
msg.act = BTC_GAP_BT_ACT_SET_DEV_NAME;
|
|
||||||
|
|
||||||
|
|
||||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_gap_bt_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif /* #if BTC_GAP_BT_INCLUDED */
|
#endif /* #if BTC_GAP_BT_INCLUDED */
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "esp_err.h"
|
||||||
|
#include "esp_bt_defs.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@@ -30,6 +32,21 @@ extern "C" {
|
|||||||
*/
|
*/
|
||||||
const uint8_t *esp_bt_dev_get_address(void);
|
const uint8_t *esp_bt_dev_get_address(void);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set bluetooth device name. This function should be called after esp_bluedroid_enable()
|
||||||
|
* completes successfully
|
||||||
|
*
|
||||||
|
* @param[in] name : device name to be set
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK : Succeed
|
||||||
|
* - ESP_ERR_INVALID_ARG : if name is NULL pointer or empty, or string length out of limit
|
||||||
|
* - ESP_INVALID_STATE : if bluetooth stack is not yet enabled
|
||||||
|
* - ESP_FAIL : others
|
||||||
|
*/
|
||||||
|
esp_err_t esp_bt_dev_set_device_name(const char *name);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -24,8 +24,6 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define ESP_BT_GAP_DEVICE_NAME_MAX (32)
|
|
||||||
|
|
||||||
/// Discoverability and Connectability mode
|
/// Discoverability and Connectability mode
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ESP_BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
|
ESP_BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
|
||||||
@@ -47,22 +45,6 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode);
|
esp_err_t esp_bt_gap_set_scan_mode(esp_bt_scan_mode_t mode);
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Set bluetooth device name. This function should be called after esp_bluedroid_enable()
|
|
||||||
* completes successfully
|
|
||||||
*
|
|
||||||
* @param[in] name : device name to be set, string length should not exceed ESP_BT_GAP_DEVICE_NAME_MAX
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
* - ESP_OK : Succeed
|
|
||||||
* - ESP_ERR_INVALID_ARG : if name is NULL pointer or empty, or string length out of limit
|
|
||||||
* - ESP_INVALID_STATE : if bluetooth stack is not yet enabled
|
|
||||||
* - ESP_FAIL : others
|
|
||||||
*/
|
|
||||||
esp_err_t esp_bt_gap_set_device_name(const char *name);
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
34
components/bt/bluedroid/btc/core/btc_dev.c
Normal file
34
components/bt/bluedroid/btc/core/btc_dev.c
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
// 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 <string.h>
|
||||||
|
#include "bta_api.h"
|
||||||
|
#include "btc_task.h"
|
||||||
|
#include "btc_manage.h"
|
||||||
|
#include "btc_dev.h"
|
||||||
|
|
||||||
|
void btc_dev_call_handler(btc_msg_t *msg)
|
||||||
|
{
|
||||||
|
btc_dev_args_t *arg = (btc_dev_args_t *)msg->arg;
|
||||||
|
|
||||||
|
LOG_DEBUG("%s act %d\n", __FUNCTION__, msg->act);
|
||||||
|
|
||||||
|
switch (msg->act) {
|
||||||
|
case BTC_DEV_ACT_SET_DEVICE_NAME:
|
||||||
|
BTA_DmSetDeviceName(arg->set_dev_name.device_name);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
@@ -20,6 +20,7 @@
|
|||||||
#include "gki.h"
|
#include "gki.h"
|
||||||
#include "bt_defs.h"
|
#include "bt_defs.h"
|
||||||
#include "btc_main.h"
|
#include "btc_main.h"
|
||||||
|
#include "btc_dev.h"
|
||||||
#include "btc_gatts.h"
|
#include "btc_gatts.h"
|
||||||
#include "btc_gattc.h"
|
#include "btc_gattc.h"
|
||||||
#include "btc_gap_ble.h"
|
#include "btc_gap_ble.h"
|
||||||
@@ -39,6 +40,7 @@ static xQueueHandle xBtcQueue = 0;
|
|||||||
|
|
||||||
static btc_func_t profile_tab[BTC_PID_NUM] = {
|
static btc_func_t profile_tab[BTC_PID_NUM] = {
|
||||||
[BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
|
[BTC_PID_MAIN_INIT] = {btc_main_call_handler, NULL },
|
||||||
|
[BTC_PID_DEV] = {btc_dev_call_handler, NULL },
|
||||||
[BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
|
[BTC_PID_GATTS] = {btc_gatts_call_handler, btc_gatts_cb_handler },
|
||||||
[BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
|
[BTC_PID_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
|
||||||
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
|
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
|
||||||
|
38
components/bt/bluedroid/btc/include/btc_dev.h
Normal file
38
components/bt/bluedroid/btc/include/btc_dev.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// 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_DEV_H__
|
||||||
|
#define __BTC_DEV_H__
|
||||||
|
|
||||||
|
#include "esp_bt_defs.h"
|
||||||
|
#include "esp_bt_device.h"
|
||||||
|
#include "btc_task.h"
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
BTC_DEV_ACT_SET_DEVICE_NAME
|
||||||
|
} btc_dev_act_t;
|
||||||
|
|
||||||
|
/* btc_dev_args_t */
|
||||||
|
typedef union {
|
||||||
|
// BTC_BT_GAP_ACT_SET_DEV_NAME
|
||||||
|
struct set_bt_dev_name_args {
|
||||||
|
#define ESP_DEV_DEVICE_NAME_MAX (32)
|
||||||
|
char device_name[ESP_DEV_DEVICE_NAME_MAX + 1];
|
||||||
|
} set_dev_name;
|
||||||
|
} btc_dev_args_t;
|
||||||
|
|
||||||
|
void btc_dev_call_handler(btc_msg_t *msg);
|
||||||
|
|
||||||
|
#endif /* __BTC_DEV_H__ */
|
||||||
|
|
@@ -36,6 +36,7 @@ typedef enum {
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BTC_PID_MAIN_INIT = 0,
|
BTC_PID_MAIN_INIT = 0,
|
||||||
|
BTC_PID_DEV,
|
||||||
BTC_PID_GATTS,
|
BTC_PID_GATTS,
|
||||||
BTC_PID_GATTC,
|
BTC_PID_GATTC,
|
||||||
BTC_PID_GAP_BLE,
|
BTC_PID_GAP_BLE,
|
||||||
|
@@ -768,9 +768,6 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
|||||||
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
|
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
|
||||||
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable);
|
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable);
|
||||||
break;
|
break;
|
||||||
case BTC_GAP_BLE_ACT_SET_DEV_NAME:
|
|
||||||
BTA_DmSetDeviceName(arg->set_dev_name.device_name);
|
|
||||||
break;
|
|
||||||
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW:
|
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW:
|
||||||
btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
|
btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
|
||||||
arg->cfg_adv_data_raw.raw_adv_len,
|
arg->cfg_adv_data_raw.raw_adv_len,
|
||||||
|
@@ -78,10 +78,6 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
|
|||||||
btc_bt_set_scan_mode(arg->set_scan_mode.mode);
|
btc_bt_set_scan_mode(arg->set_scan_mode.mode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case BTC_GAP_BT_ACT_SET_DEV_NAME: {
|
|
||||||
BTA_DmSetDeviceName(arg->set_dev_name.device_name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -31,7 +31,6 @@ typedef enum {
|
|||||||
BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN,
|
BTC_GAP_BLE_ACT_SET_PKT_DATA_LEN,
|
||||||
BTC_GAP_BLE_ACT_SET_RAND_ADDRESS,
|
BTC_GAP_BLE_ACT_SET_RAND_ADDRESS,
|
||||||
BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY,
|
BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY,
|
||||||
BTC_GAP_BLE_ACT_SET_DEV_NAME,
|
|
||||||
BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW,
|
BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW,
|
||||||
BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW,
|
BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW,
|
||||||
} btc_gap_ble_act_t;
|
} btc_gap_ble_act_t;
|
||||||
@@ -73,11 +72,6 @@ typedef union {
|
|||||||
struct cfg_local_privacy_args {
|
struct cfg_local_privacy_args {
|
||||||
bool privacy_enable;
|
bool privacy_enable;
|
||||||
} cfg_local_privacy;
|
} cfg_local_privacy;
|
||||||
//BTC_GAP_BLE_ACT_SET_DEV_NAME,
|
|
||||||
struct set_dev_name_args {
|
|
||||||
#define ESP_GAP_DEVICE_NAME_MAX (32)
|
|
||||||
char device_name[ESP_GAP_DEVICE_NAME_MAX + 1];
|
|
||||||
} set_dev_name;
|
|
||||||
//BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW,
|
//BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW,
|
||||||
struct config_adv_data_raw_args {
|
struct config_adv_data_raw_args {
|
||||||
uint8_t *raw_adv;
|
uint8_t *raw_adv;
|
||||||
|
@@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BTC_GAP_BT_ACT_SET_SCAN_MODE = 0,
|
BTC_GAP_BT_ACT_SET_SCAN_MODE = 0,
|
||||||
BTC_GAP_BT_ACT_SET_DEV_NAME
|
|
||||||
} btc_gap_bt_act_t;
|
} btc_gap_bt_act_t;
|
||||||
|
|
||||||
/* btc_bt_gap_args_t */
|
/* btc_bt_gap_args_t */
|
||||||
@@ -30,11 +29,6 @@ typedef union {
|
|||||||
struct set_bt_scan_mode_args {
|
struct set_bt_scan_mode_args {
|
||||||
esp_bt_scan_mode_t mode;
|
esp_bt_scan_mode_t mode;
|
||||||
} set_scan_mode;
|
} set_scan_mode;
|
||||||
|
|
||||||
// BTC_BT_GAP_ACT_SET_DEV_NAME
|
|
||||||
struct set_bt_dev_name_args {
|
|
||||||
char device_name[ESP_BT_GAP_DEVICE_NAME_MAX + 1];
|
|
||||||
} set_dev_name;
|
|
||||||
} btc_gap_bt_args_t;
|
} btc_gap_bt_args_t;
|
||||||
|
|
||||||
void btc_gap_bt_call_handler(btc_msg_t *msg);
|
void btc_gap_bt_call_handler(btc_msg_t *msg);
|
||||||
|
Reference in New Issue
Block a user