// See the License for the specific language governing permissions and
// limitations under the License.
-
+#include <stdlib.h>
+#include <string.h>
#include "esp_bt_device.h"
#include "esp_bt_main.h"
#include "controller.h"
+#include "btc_task.h"
+#include "btc_dev.h"
const uint8_t *esp_bt_dev_get_address(void)
{
}
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);
+}
// limitations under the License.
#include <string.h>
-
+#include "esp_bt_device.h"
#include "esp_bt_main.h"
#include "esp_gap_ble_api.h"
#include "bta_api.h"
esp_err_t esp_ble_gap_set_device_name(const char *name)
{
- btc_msg_t msg;
- 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);
+ return esp_bt_dev_set_device_name(name);
}
uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *length)
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 */
#include <stdint.h>
#include <stdbool.h>
+#include "esp_err.h"
+#include "esp_bt_defs.h"
#ifdef __cplusplus
extern "C" {
*/
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
}
#endif
#endif
-#define ESP_BT_GAP_DEVICE_NAME_MAX (32)
-
/// Discoverability and Connectability mode
typedef enum {
ESP_BT_SCAN_MODE_NONE = 0, /*!< Neither discoverable nor connectable */
*/
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
}
#endif
--- /dev/null
+// 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;
+ }
+}
#include "gki.h"
#include "bt_defs.h"
#include "btc_main.h"
+#include "btc_dev.h"
#include "btc_gatts.h"
#include "btc_gattc.h"
#include "btc_gap_ble.h"
static btc_func_t profile_tab[BTC_PID_NUM] = {
[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_GATTC] = {btc_gattc_call_handler, btc_gattc_cb_handler },
[BTC_PID_GAP_BLE] = {btc_gap_ble_call_handler, btc_gap_ble_cb_handler },
--- /dev/null
+// 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__ */
+
typedef enum {
BTC_PID_MAIN_INIT = 0,
+ BTC_PID_DEV,
BTC_PID_GATTS,
BTC_PID_GATTC,
BTC_PID_GAP_BLE,
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable);
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:
btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
arg->cfg_adv_data_raw.raw_adv_len,
btc_bt_set_scan_mode(arg->set_scan_mode.mode);
break;
}
- case BTC_GAP_BT_ACT_SET_DEV_NAME: {
- BTA_DmSetDeviceName(arg->set_dev_name.device_name);
- break;
- }
default:
break;
}
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_SET_DEV_NAME,
BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW,
BTC_GAP_BLE_ACT_CFG_SCAN_RSP_DATA_RAW,
} btc_gap_ble_act_t;
struct cfg_local_privacy_args {
bool privacy_enable;
} 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,
struct config_adv_data_raw_args {
uint8_t *raw_adv;
typedef enum {
BTC_GAP_BT_ACT_SET_SCAN_MODE = 0,
- BTC_GAP_BT_ACT_SET_DEV_NAME
} btc_gap_bt_act_t;
/* btc_bt_gap_args_t */
struct set_bt_scan_mode_args {
esp_bt_scan_mode_t 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;
void btc_gap_bt_call_handler(btc_msg_t *msg);