esp_bt_device.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 "controller.h"
  18. #include "btc_task.h"
  19. #include "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;
  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 (strlen(name) > ESP_DEV_DEVICE_NAME_MAX) {
  35. return ESP_ERR_INVALID_ARG;
  36. }
  37. msg.sig = BTC_SIG_API_CALL;
  38. msg.pid = BTC_PID_DEV;
  39. msg.act = BTC_DEV_ACT_SET_DEVICE_NAME;
  40. strcpy(arg.set_dev_name.device_name, name);
  41. return (btc_transfer_context(&msg, &arg, sizeof(btc_dev_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
  42. }