esp_bt_device.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "esp_bt_device.h"
  16. #include "esp_bt_main.h"
  17. #include "device/controller.h"
  18. #include "btc/btc_task.h"
  19. #include "btc/btc_dev.h"
  20. const uint8_t *esp_bt_dev_get_address(void)
  21. {
  22. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  23. return NULL;
  24. }
  25. return controller_get_interface()->get_address()->address;
  26. }
  27. esp_err_t esp_bt_dev_set_device_name(const char *name)
  28. {
  29. btc_msg_t msg = {0};
  30. btc_dev_args_t arg;
  31. if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
  32. return ESP_ERR_INVALID_STATE;
  33. }
  34. if (!name){
  35. return ESP_ERR_INVALID_ARG;
  36. }
  37. if (strlen(name) > BTC_MAX_LOC_BD_NAME_LEN) {
  38. return ESP_ERR_INVALID_ARG;
  39. }
  40. msg.sig = BTC_SIG_API_CALL;
  41. msg.pid = BTC_PID_DEV;
  42. msg.act = BTC_DEV_ACT_SET_DEVICE_NAME;
  43. arg.set_dev_name.device_name = (char *)malloc((BTC_MAX_LOC_BD_NAME_LEN + 1) * sizeof(char));
  44. if (!arg.set_dev_name.device_name) {
  45. return ESP_ERR_NO_MEM;
  46. }
  47. strcpy(arg.set_dev_name.device_name, name);
  48. return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  49. }