Fixed l1oipctrl. It is tested and works.

Fixed port number in isdnbridge.

	modified:   Makefile
	modified:   bridge/bridge.c
	modified:   include/mISDNif.h
	modified:   l1oip/l1oipctrl.c
	modified:   tools/info.c
This commit is contained in:
Andreas Eversberg 2008-09-14 12:31:43 +02:00
parent e45757122e
commit 7c532c75f3
5 changed files with 95 additions and 25 deletions

View File

@ -36,7 +36,7 @@ endif
export CFLAGS
SUBDIRS := lib bridge tools example
SUBDIRS := lib bridge tools example l1oip
all:

View File

@ -575,7 +575,7 @@ struct mISDNport *mISDN_port_open(int port, int nt_mode, int hdlc)
/* bind socket to dchannel */
memset(&addr, 0, sizeof(addr));
addr.family = AF_ISDN;
addr.dev = mISDNport->portnum-1;
addr.dev = mISDNport->portnum;
addr.channel = 0;
ret = bind(mISDNport->d_sock, (struct sockaddr *)&addr, sizeof(addr));
if (ret < 0)
@ -611,7 +611,7 @@ struct mISDNport *mISDN_port_open(int port, int nt_mode, int hdlc)
/* bind socket to bchannel */
memset(&addr, 0, sizeof(addr));
addr.family = AF_ISDN;
addr.dev = mISDNport->portnum-1;
addr.dev = mISDNport->portnum;
addr.channel = i+1+(i>=15);
ret = bind(mISDNport->b_sock[i], (struct sockaddr *)&addr, sizeof(addr));
if (ret < 0)
@ -688,7 +688,7 @@ int main(int argc, char *argv[])
usage:
printf("Usage: %s [--<option> [...]] te|nt <port a> te|nt <port b> \\\n"
" [te|nt <port c> te|nt <port d> [...]]\n\n", argv[0]);
printf("Example: %s --traffic te 1 nt 2 # bridges port 1 (TE-mode) with port 2 (NT-mode)\n", argv[0]);
printf("Example: %s --traffic te 0 nt 1 # bridges port 0 (TE-mode) with port 1 (NT-mode)\n", argv[0]);
printf("Bridges given pairs of ports. The number of given ports must be even.\n");
printf("Each pair of ports must be the same interface size (equal channel number).\n");
printf("Both ports may have same mode, e.g. 'te', to bridge ISDN leased line.\n");

View File

@ -204,9 +204,9 @@
#define ISDN_P_NT_UP0 0x06
#define IS_ISDN_P_TE(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_TE_E1) || \
(p == ISDN_P_TE_UP0))
(p == ISDN_P_TE_UP0) || (p == ISDN_P_LAPD_TE))
#define IS_ISDN_P_NT(p) ((p == ISDN_P_NT_S0) || (p == ISDN_P_NT_E1) || \
(p == ISDN_P_NT_UP0))
(p == ISDN_P_NT_UP0) || (p == ISDN_P_LAPD_NT))
#define IS_ISDN_P_S0(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_NT_S0))
#define IS_ISDN_P_E1(p) ((p == ISDN_P_TE_E1) || (p == ISDN_P_NT_E1))
#define IS_ISDN_P_UP0(p) ((p == ISDN_P_TE_UP0) || (p == ISDN_P_NT_UP0))
@ -334,6 +334,7 @@ clear_channelmap(u_int nr, u_char *map)
#define MISDN_CTRL_UNSETPEER 0x0080
#define MISDN_CTRL_RX_OFF 0x0100
#define MISDN_CTRL_FILL_EMPTY 0x0200
#define MISDN_CTRL_GETPEER 0x0400
#define MISDN_CTRL_HW_FEATURES_OP 0x2000
#define MISDN_CTRL_HW_FEATURES 0x2001
#define MISDN_CTRL_HFC_OP 0x4000

View File

@ -20,24 +20,33 @@
#include <mlayer3.h>
#include <mbuffer.h>
#include <errno.h>
#define AF_COMPATIBILITY_FUNC
#include <compat_af_isdn.h>
int main(int argc, char *argv[])
{
int ret;
int count;
int sock;
struct hostent *hostent;
struct servent *servent;
struct mISDN_ctrl_req crq;
int ret;
int count;
int sock;
int port;
int try = 0, pri = 0;
struct hostent *hostent;
struct servent *servent;
struct mISDN_ctrl_req crq;
struct sockaddr_mISDN addr;
struct mISDN_devinfo devinfo;
memset(&crq, 0, sizeof(crq));
init_af_isdn();
/* usage */
if (argc <= 1) {
usage:
printf(
"Usage: %s <port> [param]\n"
"Param is:\n"
" getpeer -> gets current peer IP setting\n"
" unsetpeer -> releases current peer IP\n"
" setpeer <remote host> <remote port> [<local port>]\n"
, argv[0]);
@ -47,7 +56,7 @@ usage:
fprintf(stderr, "Missing parameter.\n");
goto usage;
}
crq.dev = atoi(argv[1]);
port = atoi(argv[1]);
if (!strcmp(argv[2], "setpeer")) {
crq.op = MISDN_CTRL_SETPEER;
if (argc <= 3) {
@ -68,23 +77,33 @@ usage:
fprintf(stderr, "Missing remote port.\n");
goto usage;
}
servent = getservbyname(argv[3], "udp");
if (!servent) {
fprintf(stderr, "Given port %s not found.\n", argv[4]);
return(0);
}
crq.p2 = ntohs(servent->s_port);
if (argc > 4) {
if (argv[4][0] < '0' || argv[4][0] > '9') {
servent = getservbyname(argv[4], "udp");
if (!servent) {
fprintf(stderr, "Given port %s not found.\n", argv[5]);
fprintf(stderr, "Given port %s not found.\n", argv[4]);
return(0);
}
crq.p2 |= ntohs(servent->s_port) << 16;
crq.p2 = ntohs(servent->s_port);
} else
crq.p2 = atoi(argv[4]);
if (argc > 5) {
if (argv[5][0] < '0' || argv[5][0] > '9') {
servent = getservbyname(argv[5], "udp");
if (!servent) {
fprintf(stderr, "Given port %s not found.\n", argv[5]);
return(0);
}
crq.p2 |= ntohs(servent->s_port) << 16;
} else
crq.p2 |= atoi(argv[5]) << 16;
}
} else
if (!strcmp(argv[2], "unsetpeer")) {
crq.op = MISDN_CTRL_UNSETPEER;
crq.p1 = 0;
} else
if (!strcmp(argv[2], "getpeer")) {
crq.op = MISDN_CTRL_GETPEER;
} else {
fprintf(stderr, "Unknown parameter.\n");
goto usage;
@ -107,15 +126,65 @@ usage:
printf("Found no card. Please be sure to load card drivers.\n");
goto done;
}
if (count <= port) {
printf("Given port %d is out of range.\n", port);
goto done;
}
devinfo.id = port;
ret = ioctl(sock, IMGETDEVINFO, &devinfo);
if (ret < 0) {
fprintf(stderr, "Cannot get devinfo of mISDN devices. (ioctl IMGETDEVINFO failed ret=%d)\n", ret);
goto done;
}
if (devinfo.Dprotocols & (1 << ISDN_P_TE_E1))
pri = 1;
if (devinfo.Dprotocols & (1 << ISDN_P_NT_E1))
pri = 1;
close(sock);
/* open device */
again:
if (try == 0)
sock = socket(PF_ISDN, SOCK_DGRAM, pri?ISDN_P_TE_E1:ISDN_P_TE_S0);
else
sock = socket(PF_ISDN, SOCK_DGRAM, pri?ISDN_P_NT_E1:ISDN_P_NT_S0);
if (sock < 0) {
fprintf(stderr, "Cannot open mISDN device due to %s.\n", strerror(errno));
goto done;
}
addr.family = AF_ISDN;
addr.dev = port;
addr.channel = 0;
ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr));
if (ret < 0 && errno == EBUSY && try == 0) {
close(sock);
try = 1;
goto again;
}
if (ret < 0) {
fprintf(stderr, "Bind failed due to %s.\n", strerror(errno));
goto done;
}
ret = ioctl(sock, IMCTRLREQ, &crq);
if (ret < 0) {
fprintf(stderr, "IMCTRLREQ failed for port %d. (ret=%d)\n", crq.dev, ret);
fprintf(stderr, "IMCTRLREQ failed for port %d. Port seems not to be a layer1-over-ip device.\n", port);
goto done;
}
/* output the port info */
printf("Done.");
printf("Peer settings for port %d (%s)\n", port, devinfo.name);
if (crq.p1 == 0)
printf("No peer set.\n");
else {
printf("remote IP : %d.%d.%d.%d\n", (unsigned int)crq.p1 >> 24, (crq.p1 >> 16) & 0xff, (crq.p1 >> 8) & 0xff, crq.p1 & 0xff);
printf("remote port: %d\n", crq.p2 & 0xffff);
if (crq.p2 >> 16)
printf("local port : %d\n", (unsigned int)crq.p2 >> 16);
else
printf("local port : set automatically\n");
}
done:
close(sock);

View File

@ -1,6 +1,6 @@
/*****************************************************************************\
** **
** isdnbridge **
** isdninfo **
** **
**---------------------------------------------------------------------------**
** Copyright: Andreas Eversberg (GPL) **