diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index bf22f102a..b07ff1d08 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -1011,6 +1011,14 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc) return 0; } + +int bt_mesh_gatts_set_local_device_name(const char *name) +{ + BLE_MESH_BTM_CHECK_STATUS(BTM_SetLocalDeviceName((char *)name)); + + return 0; +} + #endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */ #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h index 2c54005d1..563d070fe 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h @@ -34,6 +34,10 @@ #endif +#define BLE_MESH_GAP_ADV_MAX_LEN 31 + +#define BLE_MESH_GATT_DEF_MTU_SIZE 23 + /* BD ADDR types */ #define BLE_MESH_ADDR_PUBLIC 0x00 #define BLE_MESH_ADDR_RANDOM 0x01 @@ -681,6 +685,8 @@ u16_t bt_mesh_gatt_get_mtu(struct bt_mesh_conn *conn); int bt_mesh_gatts_service_stop(struct bt_mesh_gatt_service *svc); int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc); +int bt_mesh_gatts_set_local_device_name(const char *name); + void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb); u8_t bt_mesh_gattc_get_free_conn_count(void); diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index e9ff95019..767c2bace 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -1199,6 +1199,11 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc) return 0; } + +int bt_mesh_gatts_set_local_device_name(const char *name) +{ + return ble_svc_gap_device_name_set(name); +} #endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */ #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c index ba2556d27..f5d361e8f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c @@ -130,7 +130,7 @@ int bt_mesh_set_device_name(const char *name) memset(device_name, 0x0, sizeof(device_name)); memcpy(device_name, name, strlen(name)); - return 0; + return bt_mesh_gatts_set_local_device_name(device_name); } static struct bt_mesh_proxy_client *find_client(struct bt_mesh_conn *conn) @@ -1417,7 +1417,7 @@ int bt_mesh_proxy_init(void) __ASSERT(prov && prov->uuid, "%s, Device UUID is not initialized", __func__); #endif - return 0; + return bt_mesh_gatts_set_local_device_name(device_name); } #endif /* CONFIG_BLE_MESH_NODE */ diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.h b/components/bt/esp_ble_mesh/mesh_core/proxy_server.h index 07120e095..41b89c369 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.h +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.h @@ -19,7 +19,21 @@ #define BLE_MESH_PROXY_CONFIG 0x02 #define BLE_MESH_PROXY_PROV 0x03 -#define DEVICE_NAME_SIZE 29 +#if CONFIG_BLE_MESH_PROXY +/** + * Device Name Characteristic: + * 1. For iOS, when it tries to get the value of Device Name Characteristic, the PDU + * "Read By Type Request" will be used, and the valid length of corresponding + * response is 19 (23 - 1 - 1 - 2). + * 2. For Android, when it tries to get the value of Device Name Characteristic, the + * PDU "Read Request" will be used, and the valid length of corresponding response + * is 22 (23 - 1). + */ +#define DEVICE_NAME_SIZE MIN((BLE_MESH_GATT_DEF_MTU_SIZE - 4), (BLE_MESH_GAP_ADV_MAX_LEN - 2)) +#else +/* For Scan Response Data, the maximum length is 29 (31 - 1 - 1) currently. */ +#define DEVICE_NAME_SIZE (BLE_MESH_GAP_ADV_MAX_LEN - 2) +#endif int bt_mesh_set_device_name(const char *name);