]> granicus.if.org Git - esp-idf/commitdiff
component/bt: move API to set device name that can be used by both bt and ble applica...
authorwangmengyang <wangmengyang@espressif.com>
Fri, 17 Mar 2017 11:16:52 +0000 (19:16 +0800)
committerwangmengyang <wangmengyang@espressif.com>
Fri, 17 Mar 2017 11:16:52 +0000 (19:16 +0800)
13 files changed:
components/bt/bluedroid/api/esp_bt_device.c
components/bt/bluedroid/api/esp_gap_ble_api.c
components/bt/bluedroid/api/esp_gap_bt_api.c
components/bt/bluedroid/api/include/esp_bt_device.h
components/bt/bluedroid/api/include/esp_gap_bt_api.h
components/bt/bluedroid/btc/core/btc_dev.c [new file with mode: 0644]
components/bt/bluedroid/btc/core/btc_task.c
components/bt/bluedroid/btc/include/btc_dev.h [new file with mode: 0644]
components/bt/bluedroid/btc/include/btc_task.h
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
components/bt/bluedroid/btc/profile/std/gap/btc_gap_bt.c
components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h
components/bt/bluedroid/btc/profile/std/include/btc_gap_bt.h

index dffcbe80b20f20d9225c3e0010188e4966e9bf7c..b4885cc0efe4b3d6193fec983edb82f53fff1221 100644 (file)
 // 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)
 {
@@ -24,3 +27,24 @@ 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);
+}
index 2807281aedd1769a3a18852fbf15785ed86ce18f..a89b7da2cd95b6948309c5a7446feed567eeba96 100644 (file)
@@ -13,7 +13,7 @@
 // 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"
@@ -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)
 {
-    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)
index 7c4855e27b5ea226f8246c044c3aba2fdf781209..1f68879663301ecd061a2ec641183411a8c1f5b7 100644 (file)
@@ -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);
 }
 
-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 */
index c84d042d66468341d7da99870ec5f1fb30db3f44..d3c3f79c55cb2169a0352fb8225d51bba197531e 100644 (file)
@@ -17,6 +17,8 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include "esp_err.h"
+#include "esp_bt_defs.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -30,6 +32,21 @@ 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
index 47b669a76dff03828ed4da1004c431da8dbfda2d..5efdd6332666939cdf1ccf733f638afd7d402ce3 100644 (file)
@@ -24,8 +24,6 @@ extern "C" {
 #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 */
@@ -47,22 +45,6 @@ typedef enum {
  */
 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
diff --git a/components/bt/bluedroid/btc/core/btc_dev.c b/components/bt/bluedroid/btc/core/btc_dev.c
new file mode 100644 (file)
index 0000000..b751000
--- /dev/null
@@ -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;
+    }
+}
index 699a8e8d9996c0c829bf969c91bb781f3ed5e3bd..f44d12439c5dced137d547be634d3fcdaba61460 100644 (file)
@@ -20,6 +20,7 @@
 #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"
@@ -39,6 +40,7 @@ static xQueueHandle xBtcQueue = 0;
 
 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  },
diff --git a/components/bt/bluedroid/btc/include/btc_dev.h b/components/bt/bluedroid/btc/include/btc_dev.h
new file mode 100644 (file)
index 0000000..dd2e866
--- /dev/null
@@ -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__ */
+
index 25d2cbe5613610f8a663c1e68cb0d3aff15a03ed..bb8996974681c0f2e119011aec69a926cfc023ca 100644 (file)
@@ -36,6 +36,7 @@ typedef enum {
 
 typedef enum {
     BTC_PID_MAIN_INIT = 0,
+    BTC_PID_DEV,
     BTC_PID_GATTS,
     BTC_PID_GATTC,
     BTC_PID_GAP_BLE,
index 9e158c592edb415304d07f2a6dd6af8ab226d980..4cb05116c742c5b1848b1ed5b2b44ae3b7b55708 100644 (file)
@@ -768,9 +768,6 @@ 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);
         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,
index a9a461679b90ad87b6f9157f9480eba6afb9a35e..07737b7d338e611e78aea4f59d00cb4381aaa37d 100644 (file)
@@ -78,10 +78,6 @@ void btc_gap_bt_call_handler(btc_msg_t *msg)
         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;
     }
index ea639bcde91c0208e4be607e5a3d9b32c5d13d15..cc32eb76bc8da7b213379445831f9a7bd5c31407 100644 (file)
@@ -31,7 +31,6 @@ 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_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;
@@ -73,11 +72,6 @@ typedef union {
     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;
index 6c74522b27e10cc07e8659031bae0a5715df9467..d77a4b9f65d25555d57816b0c2798b90830a7c8f 100644 (file)
@@ -21,7 +21,6 @@
 
 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 */
@@ -30,11 +29,6 @@ typedef union {
     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);