1 // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <stdlib.h> 16 #include <string.h> 17 #include "esp_bt_device.h" 18 #include "esp_bt_main.h" 19 #include "device/controller.h" 20 #include "btc/btc_task.h" 21 #include "btc/btc_dev.h" 22 esp_bt_dev_get_address(void)23const uint8_t *esp_bt_dev_get_address(void) 24 { 25 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { 26 return NULL; 27 } 28 return controller_get_interface()->get_address()->address; 29 } 30 esp_bt_dev_set_device_name(const char * name)31esp_err_t esp_bt_dev_set_device_name(const char *name) 32 { 33 btc_msg_t msg = {0}; 34 btc_dev_args_t arg; 35 36 if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { 37 return ESP_ERR_INVALID_STATE; 38 } 39 if (!name){ 40 return ESP_ERR_INVALID_ARG; 41 } 42 if (strlen(name) > ESP_DEV_DEVICE_NAME_MAX) { 43 return ESP_ERR_INVALID_ARG; 44 } 45 46 msg.sig = BTC_SIG_API_CALL; 47 msg.pid = BTC_PID_DEV; 48 msg.act = BTC_DEV_ACT_SET_DEVICE_NAME; 49 strcpy(arg.set_dev_name.device_name, name); 50 51 return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); 52 } 53