Harald Welte | faea754 | 2016-12-24 01:21:03 +0100 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | #include <stdio.h> |
| 3 | |
| 4 | #include <libqmi-glib.h> |
| 5 | |
| 6 | #include "diag_log.h" |
Harald Welte | 84ec50f | 2016-12-24 10:16:00 +0100 | [diff] [blame] | 7 | #include "protocol/diag_log_qmi.h" |
Harald Welte | faea754 | 2016-12-24 01:21:03 +0100 | [diff] [blame] | 8 | |
| 9 | /* A small wrapper around libqmi-glib to give us a human-readable string |
| 10 | * representation of QMI messages that we receive from DIAG */ |
| 11 | static int dump_qmi_msg(const uint8_t *data, unsigned int len) |
| 12 | { |
| 13 | GByteArray *buffer; |
| 14 | GError *error = NULL; |
| 15 | QmiMessage *message; |
| 16 | gchar *printable; |
| 17 | |
| 18 | buffer = g_byte_array_sized_new(len); |
| 19 | g_byte_array_append(buffer, data, len); |
| 20 | |
| 21 | message = qmi_message_new_from_raw(buffer, &error); |
| 22 | if (!message) { |
| 23 | fprintf(stderr, "qmi_message_new_from_raw() returned NULL\n"); |
| 24 | return -1; |
| 25 | } |
| 26 | |
| 27 | printable = qmi_message_get_printable(message, "QMI "); |
| 28 | fputs(printable, stdout); |
| 29 | g_free(printable); |
| 30 | |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static void handle_qmi_msg(struct log_hdr *lh, struct msgb *msg) |
| 35 | { |
| 36 | dump_qmi_msg(lh->data, lh->len); |
| 37 | } |
| 38 | |
| 39 | #define CORE(x) (0x1000 + x) |
| 40 | |
| 41 | /* Tx and Rx might be switched */ |
| 42 | #define LOG_QMI_PORT_RX(i) CORE(LOG_QMI_RESERVED_CODES_BASE_C+(i*2)) |
| 43 | #define LOG_QMI_PORT_TX(i) CORE(LOG_QMI_RESERVED_CODES_BASE_C+(i*2)+1) |
| 44 | |
| 45 | static const struct diag_log_dispatch_tbl log_tbl[] = { |
| 46 | { CORE(LOG_QMI_CALL_FLOW_C), handle_qmi_msg }, |
| 47 | { CORE(LOG_QMI_SUPPORTED_INTERFACES_C), handle_qmi_msg }, |
| 48 | { LOG_QMI_PORT_RX(0), handle_qmi_msg }, |
| 49 | { LOG_QMI_PORT_RX(1), handle_qmi_msg }, |
| 50 | { LOG_QMI_PORT_RX(2), handle_qmi_msg }, |
| 51 | { LOG_QMI_PORT_RX(3), handle_qmi_msg }, |
| 52 | { LOG_QMI_PORT_RX(4), handle_qmi_msg }, |
| 53 | { LOG_QMI_PORT_RX(5), handle_qmi_msg }, |
| 54 | { LOG_QMI_PORT_RX(6), handle_qmi_msg }, |
| 55 | { LOG_QMI_PORT_RX(7), handle_qmi_msg }, |
| 56 | { LOG_QMI_PORT_RX(8), handle_qmi_msg }, |
| 57 | { LOG_QMI_PORT_RX(9), handle_qmi_msg }, |
| 58 | { LOG_QMI_PORT_RX(10), handle_qmi_msg }, |
| 59 | { LOG_QMI_PORT_RX(11), handle_qmi_msg }, |
| 60 | { LOG_QMI_PORT_RX(12), handle_qmi_msg }, |
| 61 | { LOG_QMI_PORT_RX(13), handle_qmi_msg }, |
| 62 | { LOG_QMI_PORT_RX(14), handle_qmi_msg }, |
| 63 | { LOG_QMI_PORT_RX(15), handle_qmi_msg }, |
| 64 | { LOG_QMI_PORT_TX(0), handle_qmi_msg }, |
| 65 | { LOG_QMI_PORT_TX(1), handle_qmi_msg }, |
| 66 | { LOG_QMI_PORT_TX(2), handle_qmi_msg }, |
| 67 | { LOG_QMI_PORT_TX(3), handle_qmi_msg }, |
| 68 | { LOG_QMI_PORT_TX(4), handle_qmi_msg }, |
| 69 | { LOG_QMI_PORT_TX(5), handle_qmi_msg }, |
| 70 | { LOG_QMI_PORT_TX(6), handle_qmi_msg }, |
| 71 | { LOG_QMI_PORT_TX(7), handle_qmi_msg }, |
| 72 | { LOG_QMI_PORT_TX(8), handle_qmi_msg }, |
| 73 | { LOG_QMI_PORT_TX(9), handle_qmi_msg }, |
| 74 | { LOG_QMI_PORT_TX(10), handle_qmi_msg }, |
| 75 | { LOG_QMI_PORT_TX(11), handle_qmi_msg }, |
| 76 | { LOG_QMI_PORT_TX(12), handle_qmi_msg }, |
| 77 | { LOG_QMI_PORT_TX(13), handle_qmi_msg }, |
| 78 | { LOG_QMI_PORT_TX(14), handle_qmi_msg }, |
| 79 | { LOG_QMI_PORT_TX(15), handle_qmi_msg }, |
| 80 | }; |
| 81 | |
| 82 | static __attribute__((constructor)) void on_dso_load_qmi(void) |
| 83 | { |
| 84 | diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl)); |
| 85 | } |