rbs_sabm: Add support for user-specified SAPI/TEI and DAHDI events
This commit is contained in:
parent
60b67604f6
commit
b8d8e6c835
|
@ -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 $@ $^
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue