diff options
author | laforge <laflocal@goeller.de.gnumonks.org> | 2011-02-13 14:13:15 +0100 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2011-02-13 14:10:18 +0100 |
commit | b8d8e6c835a20678b0659e52ae0ba08c0dd7becd (patch) | |
tree | 7c3524bbaa60f56e942cb63fc06d3b6ba00f4e05 | |
parent | 60b67604f613245b5a9826f87534c12f8619404b (diff) |
rbs_sabm: Add support for user-specified SAPI/TEI and DAHDI events
-rw-r--r-- | rbs_lapd/Makefile | 2 | ||||
-rw-r--r-- | rbs_lapd/rbs_sabm.c | 56 |
2 files changed, 52 insertions, 6 deletions
diff --git a/rbs_lapd/Makefile b/rbs_lapd/Makefile index 4a266f4..556d673 100644 --- a/rbs_lapd/Makefile +++ b/rbs_lapd/Makefile @@ -2,7 +2,7 @@ all: rbs_sabm rbs_lapd rbs_sabm: rbs_sabm.o - $(CC) -o $@ $^ + $(CC) -losmocore -o $@ $^ rbs_lapd: rbs_lapd.o $(CC) -o $@ $^ diff --git a/rbs_lapd/rbs_sabm.c b/rbs_lapd/rbs_sabm.c index 9605f3b..731a2d0 100644 --- a/rbs_lapd/rbs_sabm.c +++ b/rbs_lapd/rbs_sabm.c @@ -4,14 +4,40 @@ #include <string.h> #include <fcntl.h> +#include <dahdi/user.h> + +#include <osmocore/utils.h> + /* this program wants to be called with 'strace -s1024 -x' so you see the data * betewen DAHDI and it */ -const uint8_t sabme_frame_nonraw[] = { 0xFA, 0x7D, 0x7F, 0x00, 0x00 }; +uint8_t sabme_frame_nonraw[] = { 0xFA, 0x7D, 0x7F, 0x00, 0x00 }; static int fd; static uint8_t dummy_buf[8192]; +static const struct value_string dahdi_evt_names[] = { + { DAHDI_EVENT_NONE, "NONE" }, + { DAHDI_EVENT_ALARM, "ALARM" }, + { DAHDI_EVENT_NOALARM, "NOALARM" }, + { DAHDI_EVENT_ABORT, "HDLC ABORT" }, + { DAHDI_EVENT_OVERRUN, "HDLC OVERRUN" }, + { DAHDI_EVENT_BADFCS, "HDLC BAD FCS" }, + { DAHDI_EVENT_REMOVED, "REMOVED" }, + { 0, NULL } +}; + +static void handle_dahdi_exception(int fd) +{ + int rc, evt; + + rc = ioctl(fd, DAHDI_GETEVENT, &evt); + if (rc < 0) + return; + + printf("DAHDI EVENT %s\n", get_value_string(dahdi_evt_names, evt)); +} + static void dummy_read(int fd, unsigned int len) { int rc; @@ -20,11 +46,17 @@ static void dummy_read(int fd, unsigned int len) len = sizeof(dummy_buf); rc = read(fd, dummy_buf, len); + if (rc == -1) + handle_dahdi_exception(fd); + else if (rc > 0) + printf("Received %u bytes (%s)\n", rc, hexdump(dummy_buf, rc)); } int main(int argc, char **argv) { int rc; + uint8_t tei = 62, sapi = 62; + int one = 1; if (argc < 2) exit(2); @@ -34,7 +66,19 @@ int main(int argc, char **argv) perror("open"); exit(1); } - + rc = ioctl(fd, DAHDI_HDLCFCSMODE, &one); + if (rc < 0) + printf("unable to set channel into HDLC/FCS mode ?!?\n"); + + if (argc >= 3) + tei = atoi(argv[2]); + if (argc >= 4) + sapi = atoi(argv[3]); + + printf("dev = %s, TEI = %u, SAPI = %u\n", argv[1], tei, sapi); + sabme_frame_nonraw[0] = (sapi << 2) | 2; + sabme_frame_nonraw[1] = (tei << 1) | 1; + while (1) { fd_set read_fd; struct timeval timeout; @@ -42,8 +86,8 @@ int main(int argc, char **argv) FD_ZERO(&read_fd); FD_SET(fd, &read_fd); - timeout.tv_sec = 1; - timeout.tv_usec = 0; + timeout.tv_sec = 0; + timeout.tv_usec = 300000; rc = select(fd+1, &read_fd, NULL, NULL, &timeout); if (rc < 0) { @@ -52,7 +96,9 @@ int main(int argc, char **argv) } else if (rc) { dummy_read(fd, 16); } else { - write(fd, sabme_frame_nonraw, sizeof(sabme_frame_nonraw)); + rc = write(fd, sabme_frame_nonraw, sizeof(sabme_frame_nonraw)); + if (rc == -1) + handle_dahdi_exception(fd); } } } |