Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab89d1f4 authored by Chris Manton's avatar Chris Manton
Browse files

stack::bt_psm_types::tBT_PSM enum format

Bug: 339735662
Test: m .
Flag: EXEMPT, Logging Change

Change-Id: I76d2ce22311008000a5b836bff12f3980fee65b3
parent 470b5baf
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -30,6 +30,11 @@
    return fmt::format(#enumerator "(0x{:x})", \
                       static_cast<uint64_t>(enumerator))

#define CASE_RETURN_STRING_HEX04(enumerator)     \
  case enumerator:                               \
    return fmt::format(#enumerator "(0x{:04x})", \
                       static_cast<uint64_t>(enumerator))

#define RETURN_UNKNOWN_TYPE_STRING(type, variable) \
  return fmt::format("Unknown {}(0x{:x})", #type,  \
                     static_cast<uint64_t>(variable))
+30 −1
Original line number Diff line number Diff line
@@ -16,7 +16,14 @@

#pragma once

enum {
#include <bluetooth/log.h>

#include <cstdint>
#include <string>

#include "include/macros.h"

enum tBT_PSM : uint16_t {
  BT_PSM_SDP = 0x0001,
  BT_PSM_RFCOMM = 0x0003,
  BT_PSM_TCS = 0x0005,
@@ -38,3 +45,25 @@ enum {
  BRCM_RESERVED_PSM_START = 0x5AE1,
  BRCM_RESERVED_PSM_END = 0x5AFF,
};

inline std::string bt_psm_text(const tBT_PSM& psm) {
  switch (psm) {
    CASE_RETURN_STRING_HEX04(BT_PSM_SDP);
    CASE_RETURN_STRING_HEX04(BT_PSM_RFCOMM);
    CASE_RETURN_STRING_HEX04(BT_PSM_TCS);
    CASE_RETURN_STRING_HEX04(BT_PSM_CTP);
    CASE_RETURN_STRING_HEX04(BT_PSM_BNEP);
    CASE_RETURN_STRING_HEX04(BT_PSM_HIDC);
    CASE_RETURN_STRING_HEX04(BT_PSM_HIDI);
    CASE_RETURN_STRING_HEX04(BT_PSM_UPNP);
    CASE_RETURN_STRING_HEX04(BT_PSM_AVCTP);
    CASE_RETURN_STRING_HEX04(BT_PSM_AVDTP);
    CASE_RETURN_STRING_HEX04(BT_PSM_AVCTP_13);
    CASE_RETURN_STRING_HEX04(BT_PSM_UDI_CP);
    CASE_RETURN_STRING_HEX04(BT_PSM_ATT);
    CASE_RETURN_STRING_HEX04(BT_PSM_EATT);
    CASE_RETURN_STRING_HEX04(BRCM_RESERVED_PSM_START);
    CASE_RETURN_STRING_HEX04(BRCM_RESERVED_PSM_END);
  };
  RETURN_UNKNOWN_TYPE_STRING(type, psm);
}
+29 −0
Original line number Diff line number Diff line
@@ -14,11 +14,13 @@
 * limitations under the License.
 */

#include <bluetooth/log.h>
#include <fcntl.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <sys/socket.h>

#include "bt_psm_types.h"
#include "common/init_flags.h"
#include "hci/controller_interface_mock.h"
#include "osi/include/allocator.h"
@@ -266,3 +268,30 @@ TEST_F(StackL2capTest, L2CA_Dumpsys) {
  while (read(sv[1], buf, sizeof(buf)) != -1) {
  }
}

TEST_F(StackL2capTest, bt_psm_text) {
  std::map<tBT_PSM, std::string> map = {
      {BT_PSM_SDP, "BT_PSM_SDP"},
      {BT_PSM_RFCOMM, "BT_PSM_RFCOMM"},
      {BT_PSM_TCS, "BT_PSM_TCS"},
      {BT_PSM_CTP, "BT_PSM_CTP"},
      {BT_PSM_BNEP, "BT_PSM_BNEP"},
      {BT_PSM_HIDC, "BT_PSM_HIDC"},
      {HID_PSM_CONTROL, "HID_PSM_CONTROL"},
      {BT_PSM_HIDI, "BT_PSM_HIDI"},
      {HID_PSM_INTERRUPT, "HID_PSM_INTERRUPT"},
      {BT_PSM_UPNP, "BT_PSM_UPNP"},
      {BT_PSM_AVCTP, "BT_PSM_AVCTP"},
      {BT_PSM_AVDTP, "BT_PSM_AVDTP"},
      {BT_PSM_AVCTP_13, "BT_PSM_AVCTP_13"},
      {BT_PSM_UDI_CP, "BT_PSM_UDI_CP"},
      {BT_PSM_ATT, "BT_PSM_ATT"},
      {BT_PSM_EATT, "BT_PSM_EATT"},
      {BRCM_RESERVED_PSM_START, "BRCM_RESERVED_PSM_START"},
      {BRCM_RESERVED_PSM_END, "BRCM_RESERVED_PSM_END"},
  };

  for (const auto& it : map) {
    bluetooth::log::info("{} {} ", bt_psm_text(it.first), it.second);
  }
}