blob: 31bcff6b2dd7049611a522a1005335cd84084cf4 [file] [log] [blame]
Harald Weltece2f3962016-12-30 15:48:22 +01001/* Utility code for Diag Packet Logging */
2/*
3 * (C) 2016 by Harald Welte <laforge@gnumonks.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20#include <osmocom/core/utils.h>
21#include <osmocom/core/msgb.h>
22
Harald Welte9a3cd092016-12-31 20:50:30 +010023#include "diag_log.h"
Harald Weltedc2cafc2017-01-01 11:15:35 +010024#include "diag_io.h"
Harald Weltece2f3962016-12-30 15:48:22 +010025#include "protocol/diagcmd.h"
26#include "protocol/diag_log_1x.h"
27#include "protocol/dpl.h"
28
29/* iface-id 0..99 */
30/* every interface has multiple physical links */
31/* iid contains flag info: 16bits LDFx IFNA PROT LINS, see struct
32 * dpl_iid
33 */
34
35int diag_dpl_reset_logging(struct diag_instance *di)
36{
Harald Weltedc2cafc2017-01-01 11:15:35 +010037 struct msgb *msg = msgb_alloc_diag();
38 struct msgb *rx;
Harald Weltece2f3962016-12-30 15:48:22 +010039 diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING,
40 DIAG_DPL_RESET_LOGGING);
Harald Weltedc2cafc2017-01-01 11:15:35 +010041 rx = diag_transceive_msg(di, msg);
42 /* FIXME */
43 msgb_free(rx);
Harald Weltece2f3962016-12-30 15:48:22 +010044 return 0;
45}
46
47int diag_dpl_get_sup_if(struct diag_instance *di)
48{
Harald Welte9a3cd092016-12-31 20:50:30 +010049 struct msgb *msg = msgb_alloc_diag();
Harald Weltedc2cafc2017-01-01 11:15:35 +010050 struct msgb *rx;
Harald Weltece2f3962016-12-30 15:48:22 +010051 diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING,
52 DIAG_DPL_GET_SUPPORTED_IFACES);
Harald Weltedc2cafc2017-01-01 11:15:35 +010053 rx = diag_transceive_msg(di, msg);
54 /* FIXME */
55 msgb_free(rx);
Harald Weltece2f3962016-12-30 15:48:22 +010056 return 0;
57}
58
59int diag_dpl_get_if_desc(struct diag_instance *di, uint8_t iface_id)
60{
Harald Welte9a3cd092016-12-31 20:50:30 +010061 struct msgb *msg = msgb_alloc_diag();
Harald Weltedc2cafc2017-01-01 11:15:35 +010062 struct msgb *rx;
Harald Weltece2f3962016-12-30 15:48:22 +010063 struct dpl_get_if_desc_req *gidr;
64
Harald Welte9a3cd092016-12-31 20:50:30 +010065 gidr = (struct dpl_get_if_desc_req *) msgb_put(msg, sizeof(*gidr));
Harald Weltece2f3962016-12-30 15:48:22 +010066 gidr->iface_id = iface_id;
67 diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING,
68 DIAG_DPL_GET_SUPPORTED_IFACES);
Harald Weltedc2cafc2017-01-01 11:15:35 +010069 rx = diag_transceive_msg(di, msg);
70 /* FIXME */
71 msgb_free(rx);
Harald Weltece2f3962016-12-30 15:48:22 +010072 return 0;
73}
74
Harald Weltedc2cafc2017-01-01 11:15:35 +010075int diag_dpl_set_if_log(struct diag_instance *di, uint8_t iface_id,
76 uint32_t iid, uint32_t link_type)
Harald Weltece2f3962016-12-30 15:48:22 +010077{
Harald Welte9a3cd092016-12-31 20:50:30 +010078 struct msgb *msg = msgb_alloc_diag();
Harald Weltece2f3962016-12-30 15:48:22 +010079 struct dpl_set_if_log_req *silr;
Harald Weltedc2cafc2017-01-01 11:15:35 +010080 struct msgb *rx;
Harald Weltece2f3962016-12-30 15:48:22 +010081
Harald Weltedc2cafc2017-01-01 11:15:35 +010082 silr = (struct dpl_set_if_log_req *) msgb_put(msg, sizeof(*silr));
Harald Weltece2f3962016-12-30 15:48:22 +010083 silr->iface_id = iface_id;
84 silr->num_log_flags = 1;
Harald Weltedc2cafc2017-01-01 11:15:35 +010085 msgb_put(msg, sizeof(silr->log_flags[0]));
86 silr->log_flags[0].iid = iid;
87 silr->log_flags[0].link_type = link_type;
Harald Weltece2f3962016-12-30 15:48:22 +010088
Harald Weltedc2cafc2017-01-01 11:15:35 +010089 rx = diag_transceive_msg(di, msg);
90 /* FIXME */
91 msgb_free(rx);
Harald Weltece2f3962016-12-30 15:48:22 +010092
93 return 0;
94}
95
96/* LOG_DATA_PROTOCOL_LOGGING_C must be enabled */
97/* dpli_log_full_packet() used to log packet; maximum of 256 bytes per
98 * diag message; DPLI_BUILD_LOG_PACKET */
99static void handle_pcap_msg(struct log_hdr *lh, struct msgb *msg)
100{
101 struct dpl_hdr *dh = (struct dpl_hdr *) msgb_data(msg);
102 printf("(fl=0x%02x, ifn=0x%02x, prot=0x%02x, inst=%u, seq=%u, seg=%u): %s",
103 dh->iid.flags, dh->iid.if_name, dh->iid.protocol,
Harald Weltedc2cafc2017-01-01 11:15:35 +0100104 dh->iid.link_instance, dh->seq_nr, dh->seg_num,
105 osmo_hexdump(dh->data, msgb_length(msg)-sizeof(*dh)));
Harald Weltece2f3962016-12-30 15:48:22 +0100106}
107
108static const struct diag_log_dispatch_tbl log_tbl[] = {
109 { L1X(LOG_DATA_PROTOCOL_LOGGING_C), handle_pcap_msg },
110};
111
112static __attribute__((constructor)) void on_dso_load_gsm(void)
113{
114 diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl));
115}