OSDN Git Service

Add stack/gatt::gatt_security_action_text
authorChris Manton <cmanton@google.com>
Mon, 3 May 2021 16:04:06 +0000 (09:04 -0700)
committerChris Manton <cmanton@google.com>
Tue, 4 May 2021 20:24:51 +0000 (13:24 -0700)
Bug: 163134718
Test: gd/cert/run
Tag: #refactor

Change-Id: Iecae9ca52a8660151de1ea4c4402f75a3790f43f

stack/gatt/gatt_int.h

index ee0716d..01e2811 100644 (file)
@@ -51,6 +51,26 @@ typedef enum : uint8_t {
   GATT_SEC_ENC_PENDING = 6,     /* wait for link encryption pending */
 } tGATT_SEC_ACTION;
 
+#define CASE_RETURN_TEXT(code) \
+  case code:                   \
+    return #code
+
+inline std::string gatt_security_action_text(const tGATT_SEC_ACTION& action) {
+  switch (action) {
+    CASE_RETURN_TEXT(GATT_SEC_NONE);
+    CASE_RETURN_TEXT(GATT_SEC_OK);
+    CASE_RETURN_TEXT(GATT_SEC_SIGN_DATA);
+    CASE_RETURN_TEXT(GATT_SEC_ENCRYPT);
+    CASE_RETURN_TEXT(GATT_SEC_ENCRYPT_NO_MITM);
+    CASE_RETURN_TEXT(GATT_SEC_ENCRYPT_MITM);
+    CASE_RETURN_TEXT(GATT_SEC_ENC_PENDING);
+    default:
+      return std::string("UNKNOWN[%hhu]", action);
+  }
+}
+
+#undef CASE_RETURN_TEXT
+
 #define GATT_INDEX_INVALID 0xff
 
 #define GATT_WRITE_CMD_MASK 0xc0 /*0x1100-0000*/