Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 1 | /* 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 Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame^] | 23 | #include "diag_log.h" |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 24 | #include "protocol/diagcmd.h" |
| 25 | #include "protocol/diag_log_1x.h" |
| 26 | #include "protocol/dpl.h" |
| 27 | |
| 28 | /* iface-id 0..99 */ |
| 29 | /* every interface has multiple physical links */ |
| 30 | /* iid contains flag info: 16bits LDFx IFNA PROT LINS, see struct |
| 31 | * dpl_iid |
| 32 | */ |
| 33 | |
| 34 | int diag_dpl_reset_logging(struct diag_instance *di) |
| 35 | { |
| 36 | struct msb *msg = msgb_alloc_diag(); |
| 37 | diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING, |
| 38 | DIAG_DPL_RESET_LOGGING); |
| 39 | diag_transmit_msgb(di, msg); |
| 40 | diag_read(di); |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | int diag_dpl_get_sup_if(struct diag_instance *di) |
| 45 | { |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame^] | 46 | struct msgb *msg = msgb_alloc_diag(); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 47 | diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING, |
| 48 | DIAG_DPL_GET_SUPPORTED_IFACES); |
| 49 | diag_transmit_msgb(di, msg); |
| 50 | diag_read(di); |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int diag_dpl_get_if_desc(struct diag_instance *di, uint8_t iface_id) |
| 55 | { |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame^] | 56 | struct msgb *msg = msgb_alloc_diag(); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 57 | struct dpl_get_if_desc_req *gidr; |
| 58 | |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame^] | 59 | gidr = (struct dpl_get_if_desc_req *) msgb_put(msg, sizeof(*gidr)); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 60 | gidr->iface_id = iface_id; |
| 61 | diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING, |
| 62 | DIAG_DPL_GET_SUPPORTED_IFACES); |
| 63 | diag_transmit_msgb(di, msg); |
| 64 | diag_read(di); |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | int diag_dpl_set_if_log(struct diag_instance *di, uint8_t iface_id) |
| 69 | { |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame^] | 70 | struct msgb *msg = msgb_alloc_diag(); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 71 | struct dpl_set_if_log_req *silr; |
| 72 | |
| 73 | silr = (struct dpl_get_if_desc_req *) msgb_put(msg, sizeof(*silr)); |
| 74 | silr->iface_id = iface_id; |
| 75 | silr->num_log_flags = 1; |
| 76 | msgb_put(msg, sizeof(silr->log_flags[0]); |
| 77 | silr->log_flags[0].iid = FIXME; |
| 78 | silr->log_flags[0].link_type = FIXME; |
| 79 | |
| 80 | diag_transmit_msgb(di, msg); |
| 81 | diag_read(di); |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | /* LOG_DATA_PROTOCOL_LOGGING_C must be enabled */ |
| 87 | /* dpli_log_full_packet() used to log packet; maximum of 256 bytes per |
| 88 | * diag message; DPLI_BUILD_LOG_PACKET */ |
| 89 | static void handle_pcap_msg(struct log_hdr *lh, struct msgb *msg) |
| 90 | { |
| 91 | struct dpl_hdr *dh = (struct dpl_hdr *) msgb_data(msg); |
| 92 | printf("(fl=0x%02x, ifn=0x%02x, prot=0x%02x, inst=%u, seq=%u, seg=%u): %s", |
| 93 | dh->iid.flags, dh->iid.if_name, dh->iid.protocol, |
| 94 | dh->iid.link_instance, dh->seeq_nr, sh->seg_num, |
| 95 | osmo_hexdump(dh->data, msgb_len(msg)-sizeof(*dh))); |
| 96 | } |
| 97 | |
| 98 | static const struct diag_log_dispatch_tbl log_tbl[] = { |
| 99 | { L1X(LOG_DATA_PROTOCOL_LOGGING_C), handle_pcap_msg }, |
| 100 | }; |
| 101 | |
| 102 | static __attribute__((constructor)) void on_dso_load_gsm(void) |
| 103 | { |
| 104 | diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl)); |
| 105 | } |