finish GSMTAP output support (and enable it)
authorHarald Welte <laforge@gnumonks.org>
Fri, 19 Feb 2010 21:43:51 +0000 (22:43 +0100)
committerHarald Welte <laforge@gnumonks.org>
Fri, 19 Feb 2010 21:43:51 +0000 (22:43 +0100)
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
src/host/layer2/src/gsmtap_util.h
src/host/layer2/src/layer2_main.c
src/host/layer2/src/osmocom_layer2.c

index 9abc14b..79c5c5f 100644 (file)
@@ -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;
index b71c2e8..3599c33 100644 (file)
@@ -4,7 +4,7 @@
 #include <stdint.h>
 #include <netinet/in.h>
 
-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,
index c84cce4..5e15522 100644 (file)
@@ -38,6 +38,8 @@
 #include <errno.h>
 #include <fcntl.h>
 
+#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);
        }
index 0be0a4c..52b0fda 100644 (file)
@@ -29,6 +29,7 @@
 #include <stdint.h>
 #include <l1a_l23_interface.h>
 
+#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;
 }