2016-12-30 14:48:22 +00:00
|
|
|
/* Utility code for Diag Packet Logging */
|
|
|
|
/*
|
|
|
|
* (C) 2016 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2017-01-01 18:49:47 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2016-12-30 14:48:22 +00:00
|
|
|
#include <osmocom/core/utils.h>
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
|
2016-12-31 19:50:30 +00:00
|
|
|
#include "diag_log.h"
|
2017-01-01 10:15:35 +00:00
|
|
|
#include "diag_io.h"
|
2017-01-01 23:52:01 +00:00
|
|
|
#include "diag_dpl.h"
|
2016-12-30 14:48:22 +00:00
|
|
|
#include "protocol/diagcmd.h"
|
|
|
|
#include "protocol/diag_log_1x.h"
|
|
|
|
#include "protocol/dpl.h"
|
|
|
|
|
|
|
|
/* iface-id 0..99 */
|
|
|
|
/* every interface has multiple physical links */
|
|
|
|
/* iid contains flag info: 16bits LDFx IFNA PROT LINS, see struct
|
|
|
|
* dpl_iid
|
|
|
|
*/
|
|
|
|
|
|
|
|
int diag_dpl_reset_logging(struct diag_instance *di)
|
|
|
|
{
|
2017-01-01 10:15:35 +00:00
|
|
|
struct msgb *msg = msgb_alloc_diag();
|
|
|
|
struct msgb *rx;
|
2016-12-30 14:48:22 +00:00
|
|
|
diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING,
|
|
|
|
DIAG_DPL_RESET_LOGGING);
|
2017-01-01 10:15:35 +00:00
|
|
|
rx = diag_transceive_msg(di, msg);
|
|
|
|
/* FIXME */
|
|
|
|
msgb_free(rx);
|
2016-12-30 14:48:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int diag_dpl_get_sup_if(struct diag_instance *di)
|
|
|
|
{
|
2016-12-31 19:50:30 +00:00
|
|
|
struct msgb *msg = msgb_alloc_diag();
|
2017-01-01 10:15:35 +00:00
|
|
|
struct msgb *rx;
|
2017-01-01 18:49:47 +00:00
|
|
|
struct dpl_get_sup_if_resp *gsir;
|
|
|
|
rx = diag_subsys_transceive_msg(di, msg, DIAG_SUBSYS_PS_DATA_LOGGING,
|
|
|
|
DIAG_DPL_GET_SUPPORTED_IFACES);
|
|
|
|
if (!rx)
|
|
|
|
return -EINVAL;
|
|
|
|
gsir = (struct dpl_get_sup_if_resp *) msg->l3h;
|
|
|
|
printf("DPL Supported interfaces: %s\n",
|
|
|
|
osmo_hexdump(gsir->iface_id, gsir->num_ifaces));
|
2017-01-01 10:15:35 +00:00
|
|
|
msgb_free(rx);
|
2016-12-30 14:48:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int diag_dpl_get_if_desc(struct diag_instance *di, uint8_t iface_id)
|
|
|
|
{
|
2016-12-31 19:50:30 +00:00
|
|
|
struct msgb *msg = msgb_alloc_diag();
|
2017-01-01 10:15:35 +00:00
|
|
|
struct msgb *rx;
|
2016-12-30 14:48:22 +00:00
|
|
|
struct dpl_get_if_desc_req *gidr;
|
2017-01-01 18:49:47 +00:00
|
|
|
uint8_t if_num, num_links;
|
|
|
|
char *if_name, *link_name;
|
|
|
|
unsigned int i;
|
2016-12-30 14:48:22 +00:00
|
|
|
|
2016-12-31 19:50:30 +00:00
|
|
|
gidr = (struct dpl_get_if_desc_req *) msgb_put(msg, sizeof(*gidr));
|
2016-12-30 14:48:22 +00:00
|
|
|
gidr->iface_id = iface_id;
|
2017-01-01 18:49:47 +00:00
|
|
|
rx = diag_subsys_transceive_msg(di, msg, DIAG_SUBSYS_PS_DATA_LOGGING,
|
|
|
|
DIAG_DPL_GET_IFACE_DESC);
|
|
|
|
if (!rx)
|
|
|
|
return -EINVAL;
|
|
|
|
if_num = rx->l3h[0];
|
|
|
|
if_name = (char *)rx->l3h+1;
|
|
|
|
num_links = *(rx->l3h+1+strlen(if_name)+1);
|
|
|
|
printf("DPL Interface %u \"%s\" num_links=%u\n", if_num, if_name, num_links);
|
|
|
|
link_name = (char *) rx->l3h+1+strlen(if_name)+1+1;
|
|
|
|
for (i = 0; i < num_links; i++) {
|
2017-01-01 23:52:01 +00:00
|
|
|
printf("\tLink %u: \"%s\"\n", i, link_name);
|
2017-01-01 18:49:47 +00:00
|
|
|
link_name += strlen(link_name) + 1;
|
|
|
|
}
|
2017-01-01 10:15:35 +00:00
|
|
|
msgb_free(rx);
|
2016-12-30 14:48:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-01-01 10:15:35 +00:00
|
|
|
int diag_dpl_set_if_log(struct diag_instance *di, uint8_t iface_id,
|
2017-01-01 23:52:01 +00:00
|
|
|
struct dpl_iid iid, uint32_t link_type)
|
2016-12-30 14:48:22 +00:00
|
|
|
{
|
2016-12-31 19:50:30 +00:00
|
|
|
struct msgb *msg = msgb_alloc_diag();
|
2016-12-30 14:48:22 +00:00
|
|
|
struct dpl_set_if_log_req *silr;
|
2017-01-01 10:15:35 +00:00
|
|
|
struct msgb *rx;
|
2017-01-24 16:36:39 +00:00
|
|
|
int i;
|
2016-12-30 14:48:22 +00:00
|
|
|
|
2017-01-01 10:15:35 +00:00
|
|
|
silr = (struct dpl_set_if_log_req *) msgb_put(msg, sizeof(*silr));
|
2016-12-30 14:48:22 +00:00
|
|
|
silr->iface_id = iface_id;
|
2017-01-07 14:54:41 +00:00
|
|
|
silr->num_log_flags = 0;
|
2017-01-24 16:36:39 +00:00
|
|
|
for (i = 0; i < 1; i++) {
|
2017-01-07 14:54:41 +00:00
|
|
|
msgb_put(msg, sizeof(silr->log_flags[0]));
|
|
|
|
silr->num_log_flags++;
|
|
|
|
iid.link_instance = i;
|
|
|
|
silr->log_flags[i].iid = iid;
|
|
|
|
silr->log_flags[i].link_type = link_type;
|
|
|
|
}
|
|
|
|
rx = diag_subsys_transceive_msg(di, msg, DIAG_SUBSYS_PS_DATA_LOGGING,
|
|
|
|
DIAG_DPL_SET_IFACE_LOGGING);
|
2017-01-01 10:15:35 +00:00
|
|
|
/* FIXME */
|
|
|
|
msgb_free(rx);
|
2016-12-30 14:48:22 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LOG_DATA_PROTOCOL_LOGGING_C must be enabled */
|
|
|
|
/* dpli_log_full_packet() used to log packet; maximum of 256 bytes per
|
|
|
|
* diag message; DPLI_BUILD_LOG_PACKET */
|
|
|
|
static void handle_pcap_msg(struct log_hdr *lh, struct msgb *msg)
|
|
|
|
{
|
|
|
|
struct dpl_hdr *dh = (struct dpl_hdr *) msgb_data(msg);
|
2017-01-01 23:52:01 +00:00
|
|
|
printf("PCAP(fl=0x%02x, ifn=0x%02x, prot=0x%02x, inst=%u, seq=%u, seg=%u): %s\n",
|
2016-12-30 14:48:22 +00:00
|
|
|
dh->iid.flags, dh->iid.if_name, dh->iid.protocol,
|
2017-01-01 10:15:35 +00:00
|
|
|
dh->iid.link_instance, dh->seq_nr, dh->seg_num,
|
|
|
|
osmo_hexdump(dh->data, msgb_length(msg)-sizeof(*dh)));
|
2016-12-30 14:48:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct diag_log_dispatch_tbl log_tbl[] = {
|
|
|
|
{ L1X(LOG_DATA_PROTOCOL_LOGGING_C), handle_pcap_msg },
|
|
|
|
};
|
|
|
|
|
|
|
|
static __attribute__((constructor)) void on_dso_load_gsm(void)
|
|
|
|
{
|
|
|
|
diag_log_reg_dispatch(log_tbl, ARRAY_SIZE(log_tbl));
|
|
|
|
}
|