[PATCH BlueZ v3 3/6] monitor: Add support for Mgmt Security Level changed event
Frédéric Danis <[email protected]>
| Newsgroups | org.kernel.vger.linux-bluetooth |
|---|---|
| Message-ID | <[email protected]> |
@ MGMT Event: Security Level Changed (0x0034) plen 16
BR/EDR Address: 00:AA:01:01:00:00 (Intel Corporation)
Count: 2
Security Level: No security (0x00000000)
Encryption Type: No encryption (0x00000000)
---
monitor/packet.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 117 insertions(+)
diff --git a/monitor/packet.c b/monitor/packet.c
index 0d3b23cc3..217fcdad1 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -17680,6 +17680,121 @@ static void mgmt_conn_subrate_evt(const void *data, uint16_t size)
print_field("Supervision timeout: %u", supv_timeout);
}
+static void mgmt_print_security_level(const char *desc, uint32_t value)
+{
+ const char *level;
+
+ switch (value) {
+ case BT_SECURITY_SDP:
+ level = "No security";
+ break;
+ case BT_SECURITY_LOW:
+ level = "Unauthenticated pairing with encryption not required";
+ break;
+ case BT_SECURITY_MEDIUM:
+ level = "Unauthenticated pairing with encryption desired";
+ break;
+ case BT_SECURITY_HIGH:
+ level = "Authenticated pairing with encryption";
+ break;
+ case BT_SECURITY_FIPS:
+ level = "FIPS authenticated pairing with encryption";
+ break;
+ default:
+ level = "Reserved";
+ break;
+ }
+
+ print_field("%s: %s (0x%8.8x)", desc, level, value);
+}
+
+static void mgmt_print_encryption_type(const char *desc, uint32_t value)
+{
+ const char *type;
+
+ switch (value) {
+ case MGMT_CONN_SEC_ENCRYPT_NONE:
+ type = "No encryption";
+ break;
+ case MGMT_CONN_SEC_ENCRYPT_E0:
+ type = "E0";
+ break;
+ case MGMT_CONN_SEC_ENCRYPT_AES_CCM:
+ type = "AES-CCM";
+ break;
+ default:
+ type = "Reserved";
+ break;
+ }
+
+ print_field("%s: %s (0x%8.8x)", desc, type, value);
+}
+
+static void mgmt_print_sec_level_tlv(void *data, void *user_data)
+{
+ const struct mgmt_tlv *entry = data;
+ uint16_t type = get_le16(&entry->type);
+ const char *desc = default_system_config(type);
+ uint32_t value;
+ char buf[8];
+
+ switch (type) {
+ case MGMT_SEC_LEVEL_CHANGED_PARAM_LEVEL:
+ desc = "Security Level";
+ break;
+ case MGMT_SEC_LEVEL_CHANGED_PARAM_ENC_TYPE:
+ desc = "Encryption Type";
+ break;
+ default:
+ snprintf(buf, sizeof(buf), "0x%4.4x", entry->type);
+ desc = buf;
+ break;
+ }
+
+ if (entry->length == 1 || entry->length == 2 || entry->length == 4) {
+ if (entry->length == 1)
+ value = get_u8(entry->value);
+ else if (entry->length == 2)
+ value = get_le16(entry->value);
+ else
+ value = get_le32(entry->value);
+
+ switch (type) {
+ case MGMT_SEC_LEVEL_CHANGED_PARAM_LEVEL:
+ mgmt_print_security_level(desc, value);
+ break;
+ case MGMT_SEC_LEVEL_CHANGED_PARAM_ENC_TYPE:
+ mgmt_print_encryption_type(desc, value);
+ break;
+ default:
+ print_field("%s: %u", desc, value);
+ break;
+ }
+ } else {
+ print_hex_field(desc, entry->value, entry->length);
+ }
+}
+
+static void mgmt_security_level_changed_evt(const void *data, uint16_t size)
+{
+ const uint8_t *addr = data;
+ uint8_t addr_type = get_u8(data + 6);
+ uint8_t count = get_u8(data + 7);
+ struct mgmt_tlv_list *tlv_list;
+
+ mgmt_print_address(addr, addr_type);
+ print_field("Count: %d", count);
+
+ tlv_list = mgmt_tlv_list_load_from_buf(data + 8, size - 8);
+ if (!tlv_list) {
+ print_text(COLOR_ERROR, " Unable to parse security level "
+ "changed event");
+ return;
+ }
+ mgmt_tlv_list_foreach(tlv_list, mgmt_print_sec_level_tlv, NULL);
+ mgmt_tlv_list_free(tlv_list);
+}
+
static const struct mgmt_data mgmt_event_table[] = {
{ 0x0001, "Command Complete",
mgmt_command_complete_evt, 3, false },
@@ -17779,6 +17894,8 @@ static const struct mgmt_data mgmt_event_table[] = {
mgmt_mesh_packet_cmplt_evt, 1, true },
{ 0x0033, "Connection Subrate",
mgmt_conn_subrate_evt, 18, true },
+ { 0x0034, "Security Level Changed",
+ mgmt_security_level_changed_evt, 8, false },
{ }
};
--
2.43.0