summaryrefslogtreecommitdiffstats
path: root/mISDN.cpp
diff options
context:
space:
mode:
authorAndreas Eversberg2008-09-07 10:31:58 +0200
committerAndreas Eversberg2008-09-07 10:31:58 +0200
commitb2a665f8f1cdeb7d02c3f665d95e6a80297e21d1 (patch)
tree251018611c3b3f45300ad3f811cbe756fd00e8b9 /mISDN.cpp
parentchanged port attribute to "portnum". (diff)
downloadlcr-b2a665f8f1cdeb7d02c3f665d95e6a80297e21d1.tar.gz
lcr-b2a665f8f1cdeb7d02c3f665d95e6a80297e21d1.tar.xz
lcr-b2a665f8f1cdeb7d02c3f665d95e6a80297e21d1.zip
Ports can now be specified by number or by name.
Names are shown in state-screen also. modified: README modified: default/interface.conf modified: interface.c modified: interface.h modified: lcradmin.c modified: lcrsocket.h modified: mISDN.cpp modified: mISDN.h modified: main.h modified: socket_server.c
Diffstat (limited to 'mISDN.cpp')
-rw-r--r--mISDN.cpp49
1 files changed, 46 insertions, 3 deletions
diff --git a/mISDN.cpp b/mISDN.cpp
index 281ef2a..98e2c6c 100644
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -2117,7 +2117,7 @@ int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3
/*
* global function to add a new card (port)
*/
-struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, struct interface *interface)
+struct mISDNport *mISDNport_open(int port, char *portname, int ptp, int force_nt, int l2hold, struct interface *interface)
{
int ret;
struct mISDNport *mISDNport, **mISDNportp;
@@ -2128,6 +2128,7 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
struct mISDN_devinfo devinfo;
unsigned int protocol, prop;
+ /* check port counts */
ret = ioctl(mISDNsocket, IMGETCOUNT, &cnt);
if (ret < 0)
{
@@ -2140,21 +2141,45 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
PERROR_RUNTIME("Found no card. Please be sure to load card drivers.\n");
return(NULL);
}
+ if (port < 0)
+ {
+ /* resolve name */
+ port = 0;
+ while (port < cnt)
+ {
+ devinfo.id = port;
+ ret = ioctl(mISDNsocket, IMGETDEVINFO, &devinfo);
+ if (ret < 0)
+ {
+ PERROR_RUNTIME("Cannot get device information for port %d. (ioctl IMGETDEVINFO failed ret=%d)\n", port, ret);
+ return(NULL);
+ }
+ if (!strcasecmp(devinfo.name, portname))
+ break;
+ port++;
+ }
+ if (port == cnt)
+ {
+ PERROR_RUNTIME("Port name '%s' no found, use 'isdninfo' tool to list all existing ports.\n", portname);
+ return(NULL);
+ }
+ // note: 'port' has still the port number
+ }
if (port>cnt || port<0)
{
PERROR_RUNTIME("Port (%d) given at 'ports' (options.conf) is out of existing port range (%d-%d)\n", port, 0, cnt);
return(NULL);
}
+ /* get port attributes */
pri = bri = pots = nt = te = 0;
devinfo.id = port;
ret = ioctl(mISDNsocket, IMGETDEVINFO, &devinfo);
if (ret < 0)
{
- PERROR_RUNTIME("Cannot get device information for port %d. (ioctl IMGETDEVINFO failed ret=%d)\n", i, ret);
+ PERROR_RUNTIME("Cannot get device information for port %d. (ioctl IMGETDEVINFO failed ret=%d)\n", port, ret);
return(NULL);
}
- /* output the port info */
if (devinfo.Dprotocols & (1 << ISDN_P_TE_S0))
{
bri = 1;
@@ -2221,6 +2246,24 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
if (te && nt)
nt = 0;
+ /* check for double use of port */
+ if (nt)
+ {
+ mISDNport = mISDNport_first;
+ while(mISDNport)
+ {
+ if (mISDNport->portnum == port)
+ break;
+ mISDNport = mISDNport->next;
+ }
+ if (mISDNport)
+ {
+ PERROR_RUNTIME("Port %d already in use by LCR. You can't use a NT port multiple times.\n", port);
+ return(NULL);
+ }
+ }
+
+
/* add mISDNport structure */
mISDNportp = &mISDNport_first;
while(*mISDNportp)