blob: bad63df4b16472fad88e922183b7d1b8aaf47c69 [file] [log] [blame]
Harald Welteccea8dd2016-12-24 10:27:55 +01001/*
2 * (C) 2013-2016 by Harald Welte <laforge@gnumonks.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
Harald Weltefaea7542016-12-24 01:21:03 +010019#include <stdint.h>
20#include <stdio.h>
21
22#include <libqmi-glib.h>
23
24#include "diag_log.h"
Harald Welte84ec50f2016-12-24 10:16:00 +010025#include "protocol/diag_log_qmi.h"
Harald Weltefaea7542016-12-24 01:21:03 +010026
27/* A small wrapper around libqmi-glib to give us a human-readable string
28 * representation of QMI messages that we receive from DIAG */
29static int dump_qmi_msg(const uint8_t *data, unsigned int len)
30{
31 GByteArray *buffer;
32 GError *error = NULL;
33 QmiMessage *message;
34 gchar *printable;
35
36 buffer = g_byte_array_sized_new(len);
37 g_byte_array_append(buffer, data, len);
38
39 message = qmi_message_new_from_raw(buffer, &error);
40 if (!message) {
41 fprintf(stderr, "qmi_message_new_from_raw() returned NULL\n");
42 return -1;
43 }
44
45 printable = qmi_message_get_printable(message, "QMI ");
46 fputs(printable, stdout);
47 g_free(printable);
48
49 return 0;
50}
51
52static void handle_qmi_msg(struct log_hdr *lh, struct msgb *msg)
53{
54 dump_qmi_msg(lh->data, lh->len);
55}
56
57#define CORE(x) (0x1000 + x)
58
59/* Tx and Rx might be switched */
60#define LOG_QMI_PORT_RX(i) CORE(LOG_QMI_RESERVED_CODES_BASE_C+(i*2))
61#define LOG_QMI_PORT_TX(i) CORE(LOG_QMI_RESERVED_CODES_BASE_C+(i*2)+1)
62
63static const struct diag_log_dispatch_tbl log_tbl[] = {
64 { CORE(LOG_QMI_CALL_FLOW_C), handle_qmi_msg },
65 { CORE(LOG_QMI_SUPPORTED_INTERFACES_C), handle_qmi_msg },
66 { LOG_QMI_PORT_RX(0), handle_qmi_msg },
67 { LOG_QMI_PORT_RX(1), handle_qmi_msg },
68 { LOG_QMI_PORT_RX(2), handle_qmi_msg },
69 { LOG_QMI_PORT_RX(3), handle_qmi_msg },
70 { LOG_QMI_PORT_RX(4), handle_qmi_msg },
71 { LOG_QMI_PORT_RX(5), handle_qmi_msg },
72 { LOG_QMI_PORT_RX(6), handle_qmi_msg },
73 { LOG_QMI_PORT_RX(7), handle_qmi_msg },
74 { LOG_QMI_PORT_RX(8), handle_qmi_msg },
75 { LOG_QMI_PORT_RX(9), handle_qmi_msg },
76 { LOG_QMI_PORT_RX(10), handle_qmi_msg },
77 { LOG_QMI_PORT_RX(11), handle_qmi_msg },
78 { LOG_QMI_PORT_RX(12), handle_qmi_msg },
79 { LOG_QMI_PORT_RX(13), handle_qmi_msg },
80 { LOG_QMI_PORT_RX(14), handle_qmi_msg },
81 { LOG_QMI_PORT_RX(15), handle_qmi_msg },
82 { LOG_QMI_PORT_TX(0), handle_qmi_msg },
83 { LOG_QMI_PORT_TX(1), handle_qmi_msg },
84 { LOG_QMI_PORT_TX(2), handle_qmi_msg },
85 { LOG_QMI_PORT_TX(3), handle_qmi_msg },
86 { LOG_QMI_PORT_TX(4), handle_qmi_msg },
87 { LOG_QMI_PORT_TX(5), handle_qmi_msg },
88 { LOG_QMI_PORT_TX(6), handle_qmi_msg },
89 { LOG_QMI_PORT_TX(7), handle_qmi_msg },
90 { LOG_QMI_PORT_TX(8), handle_qmi_msg },
91 { LOG_QMI_PORT_TX(9), handle_qmi_msg },
92 { LOG_QMI_PORT_TX(10), handle_qmi_msg },
93 { LOG_QMI_PORT_TX(11), handle_qmi_msg },
94 { LOG_QMI_PORT_TX(12), handle_qmi_msg },
95 { LOG_QMI_PORT_TX(13), handle_qmi_msg },
96 { LOG_QMI_PORT_TX(14), handle_qmi_msg },
97 { LOG_QMI_PORT_TX(15), handle_qmi_msg },
98};
99
100static __attribute__((constructor)) void on_dso_load_qmi(void)
101{
102 diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl));
103}