From 4625209bb946bf78784dbbfdc2175a4306ce4514 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 19 Feb 2010 22:43:51 +0100 Subject: finish GSMTAP output support (and enable it) Layer2 now sends GSMTAP packets to a UDP port on localhost, where wireshark can pick them up in realtime and display them. --- src/host/layer2/src/gsmtap_util.c | 29 ++++++++++++++++++++++++----- src/host/layer2/src/gsmtap_util.h | 2 +- src/host/layer2/src/layer2_main.c | 9 +++++++++ src/host/layer2/src/osmocom_layer2.c | 4 ++++ 4 files changed, 38 insertions(+), 6 deletions(-) (limited to 'src/host') diff --git a/src/host/layer2/src/gsmtap_util.c b/src/host/layer2/src/gsmtap_util.c index 9abc14bb..79c5c5f6 100644 --- a/src/host/layer2/src/gsmtap_util.c +++ b/src/host/layer2/src/gsmtap_util.c @@ -58,11 +58,11 @@ int gsmtap_sendmsg(uint8_t ts, uint16_t arfcn, uint32_t fn, gh->hdr_len = sizeof(*gh)/4; gh->type = GSMTAP_TYPE_UM; gh->timeslot = ts; - gh->arfcn = arfcn; + gh->arfcn = htons(arfcn); gh->noise_db = 0; gh->signal_db = 0; - gh->frame_number = fn; - gh->burst_type = 0; + gh->frame_number = htonl(fn); + gh->burst_type = GSMTAP_BURST_NORMAL; gh->antenna_nr = 0; dst = msgb_put(msg, len); @@ -105,10 +105,29 @@ static int gsmtap_fd_cb(struct bsc_fd *fd, unsigned int flags) return 0; } -int gsmtap_init(struct sockaddr_in *sin) +int gsmtap_init(void) { + int rc; + struct sockaddr_in sin; + + sin.sin_family = AF_INET; + sin.sin_port = htons(GSMTAP_UDP_PORT); + inet_aton("127.0.0.1", &sin.sin_addr); + /* FIXME: create socket */ - //gsmtap_bfd.fd = + rc = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (rc < 0) { + perror("creating UDP socket"); + return rc; + } + gsmtap_bfd.fd = rc; + rc = connect(rc, (struct sockaddr *)&sin, sizeof(sin)); + if (rc < 0) { + perror("connecting UDP socket"); + close(gsmtap_bfd.fd); + gsmtap_bfd.fd = 0; + return rc; + } gsmtap_bfd.when = BSC_FD_WRITE; gsmtap_bfd.cb = gsmtap_fd_cb; diff --git a/src/host/layer2/src/gsmtap_util.h b/src/host/layer2/src/gsmtap_util.h index b71c2e8a..3599c33d 100644 --- a/src/host/layer2/src/gsmtap_util.h +++ b/src/host/layer2/src/gsmtap_util.h @@ -4,7 +4,7 @@ #include #include -int gsmtap_init(struct sockaddr_in *sin); +int gsmtap_init(void); /* receive a message from L1/L2 and put it in GSMTAP */ int gsmtap_sendmsg(uint8_t ts, uint16_t arfcn, uint32_t fn, diff --git a/src/host/layer2/src/layer2_main.c b/src/host/layer2/src/layer2_main.c index c84cce49..5e155223 100644 --- a/src/host/layer2/src/layer2_main.c +++ b/src/host/layer2/src/layer2_main.c @@ -38,6 +38,8 @@ #include #include +#include "gsmtap_util.h" + #define GSM_L2_LENGTH 256 static void *l2_ctx = NULL; @@ -157,6 +159,7 @@ int main(int argc, char **argv) { int rc; struct sockaddr_un local; + struct sockaddr_in gsmtap; l2_ctx = talloc_named_const(NULL, 1, "layer2 context"); @@ -196,6 +199,12 @@ int main(int argc, char **argv) exit(1); } + rc = gsmtap_init(); + if (rc < 0) { + fprintf(stderr, "Failed during gsmtap_init()\n"); + exit(1); + } + while (1) { bsc_select_main(0); } diff --git a/src/host/layer2/src/osmocom_layer2.c b/src/host/layer2/src/osmocom_layer2.c index 0be0a4c4..52b0fdab 100644 --- a/src/host/layer2/src/osmocom_layer2.c +++ b/src/host/layer2/src/osmocom_layer2.c @@ -29,6 +29,7 @@ #include #include +#include "gsmtap_util.h" static struct msgb *osmo_l1_alloc(uint8_t msg_type) { @@ -174,6 +175,9 @@ static int osmo_l2_ccch_data(struct osmocom_ms *ms, struct msgb *msg) hexdump(ccch->data, sizeof(ccch->data)), ccch->data[2]); dump_bcch(dl->time.tc, ccch->data); + /* send CCCH data via GSMTAP */ + gsmtap_sendmsg(0, dl->band_arfcn, dl->time.fn, ccch->data, + sizeof(ccch->data)); return 0; } -- cgit v1.2.3