tps.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /** @file
  2. * @brief GATT TX Power Service
  3. */
  4. /*
  5. * Copyright (c) 2020 Nordic Semiconductor ASA
  6. *
  7. * SPDX-License-Identifier: Apache-2.0
  8. */
  9. #include <errno.h>
  10. #include <zephyr/types.h>
  11. #include <acts_bluetooth/bluetooth.h>
  12. #include <acts_bluetooth/conn.h>
  13. #include <acts_bluetooth/gatt.h>
  14. #include <acts_bluetooth/uuid.h>
  15. #include <acts_bluetooth/hci.h>
  16. #define LOG_LEVEL CONFIG_BT_TPS_LOG_LEVEL
  17. #include <logging/log.h>
  18. LOG_MODULE_REGISTER(tps);
  19. static ssize_t read_tx_power_level(struct bt_conn *conn,
  20. const struct bt_gatt_attr *attr, void *buf,
  21. uint16_t len, uint16_t offset)
  22. {
  23. int err;
  24. struct bt_conn_le_tx_power tx_power_level = {0};
  25. if (offset) {
  26. return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET);
  27. }
  28. err = bt_conn_le_get_tx_power_level(conn, &tx_power_level);
  29. if (err) {
  30. LOG_ERR("Failed to read Tx Power Level over HCI: %d", err);
  31. return BT_GATT_ERR(BT_ATT_ERR_UNLIKELY);
  32. }
  33. LOG_INF("TPS Tx Power Level read %d", tx_power_level.current_level);
  34. return bt_gatt_attr_read(conn, attr, buf, len, offset,
  35. &tx_power_level.current_level,
  36. sizeof(tx_power_level.current_level));
  37. }
  38. BT_GATT_SERVICE_DEFINE(tps_svc,
  39. BT_GATT_PRIMARY_SERVICE(BT_UUID_TPS),
  40. BT_GATT_CHARACTERISTIC(BT_UUID_TPS_TX_POWER_LEVEL,
  41. BT_GATT_CHRC_READ, BT_GATT_PERM_READ,
  42. read_tx_power_level, NULL, NULL),
  43. );