add a command line tool for dumping the contents of a capture file

This commit is contained in:
Harald Welte 2016-10-18 23:51:54 +02:00
parent 232b972035
commit dbb0f5ae99
4 changed files with 98 additions and 1 deletions

View File

@ -1,11 +1,14 @@
CFLAGS=-g -Wall
LDFLAGS=-losmocore -losmogsm -losmovty -losmoabis -ltalloc
all: osmo-e1-recorder
all: osmo-e1-recorder osmo-e1cap-dump
osmo-e1-recorder: e1_recorder.o storage.o vty.o
$(CC) $(LDFLAGS) -o$@ $^
osmo-e1cap-dump: e1cap_dump.o storage.o
$(CC) $(LDFLAGS) -o$@ $^
%.o: %.c
$(CC) $(CFLAGS) -o $@ -c $^

36
src/e1cap_dump.c Normal file
View File

@ -0,0 +1,36 @@
#include <stdio.h>
#include <sys/time.h>
#include <osmocom/core/signal.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/application.h>
#include "storage.h"
#include "recorder.h"
struct e1_recorder g_recorder;
int main(int argc, char **argv)
{
struct osmo_e1cap_file *f;
struct osmo_e1cap_pkthdr *pkt;
printf("sizeof(timeval) = %zu\n", sizeof(struct timeval));
printf("sizeof(osmo_e1cap_pkthdr) = %zu\n", sizeof(*pkt));
if (argc < 2)
exit(2);
f = osmo_e1cap_open(NULL, argv[1]);
if (!f)
exit(1);
while ((pkt = osmo_e1cap_read_next(f))) {
printf("%lu:%lu %02u/%02u %u (%u): %s\n",
pkt->ts.tv_sec, pkt->ts.tv_usec,
pkt->line_nr, pkt->ts_nr, pkt->capture_mode,
pkt->len,
osmo_hexdump_nospc(pkt->data, pkt->len));
talloc_free(pkt);
}
}

View File

@ -6,6 +6,7 @@
#include <sys/stat.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/talloc.h>
#include <osmocom/abis/e1_input.h>
#include "storage.h"
@ -84,3 +85,56 @@ int e1frame_store(struct e1inp_ts *ts, struct msgb *msg, enum osmo_e1cap_capture
return 0;
}
/* reading */
struct osmo_e1cap_file {
int fd;
};
#define OSMO_E1REC_ALLOC_SIZE 1024
struct osmo_e1cap_file *osmo_e1cap_open(void *ctx, const char *path)
{
struct osmo_e1cap_file *f = talloc_zero(ctx, struct osmo_e1cap_file);
if (!f)
return NULL;
f->fd = open(path, O_RDONLY);
if (f->fd < 0) {
talloc_free(f);
return NULL;
}
return f;
}
struct osmo_e1cap_pkthdr *osmo_e1cap_read_next(struct osmo_e1cap_file *f)
{
struct osmo_e1cap_pkthdr *pkt = talloc_zero_size(f, OSMO_E1REC_ALLOC_SIZE);
int rc;
if (!pkt)
return NULL;
/* read header */
rc = read(f->fd, (uint8_t *)pkt, sizeof(*pkt));
if (rc < sizeof(*pkt)) {
talloc_free(pkt);
return NULL;
}
pkt->len = ntohl(pkt->len);
printf("len=%u\n", pkt->len);
/* read data */
if (pkt->len > OSMO_E1REC_ALLOC_SIZE - sizeof(*pkt)) {
pkt = talloc_realloc_size(f, pkt, sizeof(*pkt) + pkt->len);
if (!pkt)
return NULL;
}
rc = read(f->fd, (uint8_t*)(pkt+1), pkt->len);
if (rc < pkt->len) {
talloc_free(pkt);
return NULL;
}
return pkt;
}

View File

@ -30,3 +30,7 @@ struct msgb;
struct e1inp_ts;
int e1frame_store(struct e1inp_ts *ts, struct msgb *msg, enum osmo_e1cap_capture_mode mode);
struct osmo_e1cap_file;
struct osmo_e1cap_file *osmo_e1cap_open(void *ctx, const char *path);
struct osmo_e1cap_pkthdr *osmo_e1cap_read_next(struct osmo_e1cap_file *f);