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 | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 24 | #include "diag_io.h" |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 25 | #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 | |
| 35 | int diag_dpl_reset_logging(struct diag_instance *di) |
| 36 | { |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 37 | struct msgb *msg = msgb_alloc_diag(); |
| 38 | struct msgb *rx; |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 39 | diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING, |
| 40 | DIAG_DPL_RESET_LOGGING); |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 41 | rx = diag_transceive_msg(di, msg); |
| 42 | /* FIXME */ |
| 43 | msgb_free(rx); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | int diag_dpl_get_sup_if(struct diag_instance *di) |
| 48 | { |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame] | 49 | struct msgb *msg = msgb_alloc_diag(); |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 50 | struct msgb *rx; |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 51 | diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING, |
| 52 | DIAG_DPL_GET_SUPPORTED_IFACES); |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 53 | rx = diag_transceive_msg(di, msg); |
| 54 | /* FIXME */ |
| 55 | msgb_free(rx); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | int diag_dpl_get_if_desc(struct diag_instance *di, uint8_t iface_id) |
| 60 | { |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame] | 61 | struct msgb *msg = msgb_alloc_diag(); |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 62 | struct msgb *rx; |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 63 | struct dpl_get_if_desc_req *gidr; |
| 64 | |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame] | 65 | gidr = (struct dpl_get_if_desc_req *) msgb_put(msg, sizeof(*gidr)); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 66 | gidr->iface_id = iface_id; |
| 67 | diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING, |
| 68 | DIAG_DPL_GET_SUPPORTED_IFACES); |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 69 | rx = diag_transceive_msg(di, msg); |
| 70 | /* FIXME */ |
| 71 | msgb_free(rx); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 75 | int diag_dpl_set_if_log(struct diag_instance *di, uint8_t iface_id, |
| 76 | uint32_t iid, uint32_t link_type) |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 77 | { |
Harald Welte | 9a3cd09 | 2016-12-31 20:50:30 +0100 | [diff] [blame] | 78 | struct msgb *msg = msgb_alloc_diag(); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 79 | struct dpl_set_if_log_req *silr; |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 80 | struct msgb *rx; |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 81 | |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 82 | silr = (struct dpl_set_if_log_req *) msgb_put(msg, sizeof(*silr)); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 83 | silr->iface_id = iface_id; |
| 84 | silr->num_log_flags = 1; |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 85 | 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 Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 88 | |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 89 | rx = diag_transceive_msg(di, msg); |
| 90 | /* FIXME */ |
| 91 | msgb_free(rx); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 92 | |
| 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 */ |
| 99 | static 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 Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 104 | dh->iid.link_instance, dh->seq_nr, dh->seg_num, |
| 105 | osmo_hexdump(dh->data, msgb_length(msg)-sizeof(*dh))); |
Harald Welte | ce2f396 | 2016-12-30 15:48:22 +0100 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static const struct diag_log_dispatch_tbl log_tbl[] = { |
| 109 | { L1X(LOG_DATA_PROTOCOL_LOGGING_C), handle_pcap_msg }, |
| 110 | }; |
| 111 | |
| 112 | static __attribute__((constructor)) void on_dso_load_gsm(void) |
| 113 | { |
| 114 | diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl)); |
| 115 | } |