X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=mISDN.cpp;h=1bb9362f31b67d1ff7e31140cd9c88983cc33c0a;hp=40d9a9a780a9d63127bf9c76ee03999b15044132;hb=57549529c86785b7ecf5f56d2a3ff42b5e519755;hpb=3a5b34a850db3e4447287f46a40b74e0427eae54 diff --git a/mISDN.cpp b/mISDN.cpp index 40d9a9a..1bb9362 100644 --- a/mISDN.cpp +++ b/mISDN.cpp @@ -64,13 +64,13 @@ int mISDN_initialize(void) /* open debug, if enabled and not only stack debugging */ if (options.deb) { - SPRINT(filename, "%s/debug.log", INSTALL_DATA); + SPRINT(filename, "%s/debug.log", LOG_DIR); debug_fp = fopen(filename, "a"); } if (options.deb & DEBUG_STACK) { - SPRINT(filename, "%s/debug_mISDN.log", INSTALL_DATA); + SPRINT(filename, "%s/debug_mISDN.log", LOG_DIR); mISDN_debug_init(0xffffffff, filename, filename, filename); } else mISDN_debug_init(0, NULL, NULL, NULL); @@ -196,10 +196,10 @@ PmISDN::~PmISDN() /* * trace */ -void chan_trace_header(struct mISDNport *mISDNport, class PmISDN *port, char *msgtext, int direction) +void chan_trace_header(struct mISDNport *mISDNport, class PmISDN *port, const char *msgtext, int direction) { /* init trace with given values */ - start_trace(mISDNport?mISDNport->portnum:0, + start_trace(mISDNport?mISDNport->portnum:-1, (mISDNport)?((mISDNport->ifport)?mISDNport->ifport->interface:NULL):NULL, port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL, port?port->p_dialinginfo.id:NULL, @@ -214,14 +214,14 @@ void chan_trace_header(struct mISDNport *mISDNport, class PmISDN *port, char *ms * layer trace header */ static struct isdn_message { - char *name; + const char *name; unsigned int value; } isdn_message[] = { {"PH_ACTIVATE", L1_ACTIVATE_REQ}, {"PH_DEACTIVATE", L1_DEACTIVATE_REQ}, {"DL_ESTABLISH", L2_ESTABLISH_REQ}, {"DL_RELEASE", L2_RELEASE_REQ}, - {"UNKNOWN", L3_UNKNOWN}, + {"UNKNOWN", L3_UNKNOWN_REQ}, {"MT_TIMEOUT", L3_TIMEOUT_REQ}, {"MT_SETUP", L3_SETUP_REQ}, {"MT_SETUP_ACK", L3_SETUP_ACKNOWLEDGE_REQ}, @@ -254,7 +254,7 @@ static struct isdn_message { {"MT_RELEASE_L3ID", L3_RELEASE_L3ID_REQ}, {NULL, 0}, }; -static char *isdn_prim[4] = { +static const char *isdn_prim[4] = { " REQUEST", " CONFIRM", " INDICATION", @@ -263,12 +263,14 @@ static char *isdn_prim[4] = { void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsigned int msg, int direction) { int i; - char msgtext[64] = "<>"; + char msgtext[64]; + SCPY(msgtext, "<>"); /* select message and primitive text */ i = 0; while(isdn_message[i].name) { +// if (msg == L3_NOTIFY_REQ) printf("val = %x %s\n", isdn_message[i].value, isdn_message[i].name); if (isdn_message[i].value == (msg&0xffffff00)) { SCPY(msgtext, isdn_message[i].name); @@ -300,7 +302,7 @@ void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsign } /* init trace with given values */ - start_trace(mISDNport?mISDNport->portnum:0, + start_trace(mISDNport?mISDNport->portnum:-1, mISDNport?(mISDNport->ifport?mISDNport->ifport->interface:NULL):NULL, port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL, port?port->p_dialinginfo.id:NULL, @@ -314,7 +316,7 @@ void l1l2l3_trace_header(struct mISDNport *mISDNport, class PmISDN *port, unsign /* * send control information to the channel (dsp-module) */ -void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, unsigned int c2, char *trace_name, int trace_value) +void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, unsigned int c2, const char *trace_name, int trace_value) { unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+sizeof(int)]; struct mISDNhead *ctrl = (struct mISDNhead *)buffer; @@ -339,7 +341,7 @@ void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, u end_trace(); } -void ph_control_block(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, void *c2, int c2_len, char *trace_name, int trace_value) +void ph_control_block(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, unsigned int c1, void *c2, int c2_len, const char *trace_name, int trace_value) { unsigned char buffer[MISDN_HEADER_LEN+sizeof(int)+c2_len]; struct mISDNhead *ctrl = (struct mISDNhead *)buffer; @@ -384,7 +386,7 @@ static int _bchannel_create(struct mISDNport *mISDNport, int i) mISDNport->b_socket[i] = socket(PF_ISDN, SOCK_DGRAM, (mISDNport->b_mode[i]==B_MODE_HDLC)?ISDN_P_B_L2DSPHDLC:ISDN_P_B_L2DSP); if (mISDNport->b_socket[i] < 0) { - PERROR("Error: Failed to open bchannel-socket for index %d with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", i); + PERROR("Error: Failed to open bchannel-socket for index %d with mISDN-DSP layer. Did you load mISDN_dsp.ko?\n", i); return(0); } @@ -400,12 +402,12 @@ static int _bchannel_create(struct mISDNport *mISDNport, int i) /* bind socket to bchannel */ addr.family = AF_ISDN; - addr.dev = mISDNport->portnum-1; + addr.dev = mISDNport->portnum; addr.channel = i+1+(i>=15); ret = bind(mISDNport->b_socket[i], (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { - PERROR("Error: Failed to bind bchannel-socket for index %d with mISDN-DSP layer. Did you load mISDNdsp.ko?\n", i); + PERROR("Error: Failed to bind bchannel-socket for index %d with mISDN-DSP layer (errno=%d). Did you load mISDN_dsp.ko?\n", i, errno); close(mISDNport->b_socket[i]); mISDNport->b_socket[i] = -1; return(0); @@ -438,7 +440,7 @@ static void _bchannel_activate(struct mISDNport *mISDNport, int i, int activate) PERROR("Failed to send to socket %d\n", mISDNport->b_socket[i]); /* trace */ - chan_trace_header(mISDNport, mISDNport->b_port[i], activate?(char*)"BCHANNEL activate":(char*)"BCHANNEL deactivate", DIRECTION_OUT); + chan_trace_header(mISDNport, mISDNport->b_port[i], activate ? "BCHANNEL activate" : "BCHANNEL deactivate", DIRECTION_OUT); add_trace("channel", NULL, "%d", i+1+(i>=15)); if (mISDNport->b_timer[i]) add_trace("event", NULL, "timeout recovery"); @@ -1531,9 +1533,9 @@ void PmISDN::set_echotest(int echo) /* * set tone */ -void PmISDN::set_tone(char *dir, char *tone) +void PmISDN::set_tone(const char *dir, const char *tone) { - int id; + int id = TONE_OFF; if (!tone) tone = ""; @@ -1559,11 +1561,9 @@ void PmISDN::set_tone(char *dir, char *tone) Port::set_tone(dir, tone); return; } - if (p_tone_dir[0]) - goto nodsp; /* now we USE dsp-tone, convert name */ - else if (!strcmp(tone, "dialtone")) + if (!strcmp(tone, "dialtone")) { switch(options.dsptones) { case DSP_AMERICAN: id = TONE_AMERICAN_DIALTONE; break; @@ -1953,15 +1953,21 @@ int mISDN_handler(void) switch(l3m->type) { case MPH_ACTIVATE_IND: - l1l2l3_trace_header(mISDNport, NULL, L1_ACTIVATE_IND, DIRECTION_IN); - end_trace(); - mISDNport->l1link = 1; + if (mISDNport->l1link != 1) + { + l1l2l3_trace_header(mISDNport, NULL, L1_ACTIVATE_IND, DIRECTION_IN); + end_trace(); + mISDNport->l1link = 1; + } break; case MPH_DEACTIVATE_IND: - l1l2l3_trace_header(mISDNport, NULL, L1_DEACTIVATE_IND, DIRECTION_IN); - end_trace(); - mISDNport->l1link = 0; + if (mISDNport->l1link != 0) + { + l1l2l3_trace_header(mISDNport, NULL, L1_DEACTIVATE_IND, DIRECTION_IN); + end_trace(); + mISDNport->l1link = 0; + } break; case MPH_INFORMATION_IND: @@ -1999,6 +2005,7 @@ int mISDN_handler(void) l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_IND, DIRECTION_IN); add_trace("tei", NULL, "%d", l3m->pid); end_trace(); + mISDNport->l2link = 1; if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127) { if (mISDNport->l2establish) @@ -2006,7 +2013,6 @@ int mISDN_handler(void) mISDNport->l2establish = 0; PDEBUG(DEBUG_ISDN, "the link became active before l2establish timer expiry.\n"); } - mISDNport->l2link = 1; } break; @@ -2016,10 +2022,12 @@ int mISDN_handler(void) l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN); add_trace("tei", NULL, "%d", l3m->pid); end_trace(); + /* down if not nt-ptmp */ + if (!mISDNport->ntmode || mISDNport->ptp) + mISDNport->l2link = 0; } if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127) { - mISDNport->l2link = 0; if (!mISDNport->l2establish && mISDNport->l2hold) { PDEBUG(DEBUG_ISDN, "set timer and establish.\n"); @@ -2116,7 +2124,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 te_special, int l1hold, int l2hold, struct interface *interface) { int ret; struct mISDNport *mISDNport, **mISDNportp; @@ -2127,6 +2135,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) { @@ -2139,21 +2148,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>cnt || port<1) + if (port < 0) { - PERROR_RUNTIME("Port (%d) given at 'ports' (options.conf) is out of existing port range (%d-%d)\n", port, 1, cnt); + /* 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' not found, use 'misdn_info' 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 - 1; + 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; @@ -2220,12 +2253,31 @@ 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) mISDNportp = &((*mISDNportp)->next); mISDNport = (struct mISDNport *)MALLOC(sizeof(struct mISDNport)); mISDNport->l1link = -1; + mISDNport->l2link = -1; pmemuse++; *mISDNportp = mISDNport; @@ -2258,11 +2310,13 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st prop |= (1 << MISDN_FLG_PTP); if (nt) // supports hold/retrieve on nt-mode prop |= (1 << MISDN_FLG_NET_HOLD); + if (l1hold) // supports layer 1 hold + prop |= (1 << MISDN_FLG_L1_HOLD); if (l2hold) // supports layer 2 hold prop |= (1 << MISDN_FLG_L2_HOLD); /* queue must be initializes, because l3-thread may send messages during open_layer3() */ mqueue_init(&mISDNport->upqueue); - mISDNport->ml3 = open_layer3(port-1, protocol, prop , do_layer3, mISDNport); + mISDNport->ml3 = open_layer3(port, protocol, prop , do_layer3, mISDNport); if (!mISDNport->ml3) { mqueue_purge(&mISDNport->upqueue); @@ -2300,8 +2354,10 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st mISDNport->b_num = devinfo.nrbchan; mISDNport->portnum = port; mISDNport->ntmode = nt; + mISDNport->tespecial = te_special; mISDNport->pri = pri; mISDNport->ptp = ptp; + mISDNport->l1hold = l1hold; mISDNport->l2hold = l2hold; PDEBUG(DEBUG_ISDN, "Port has %d b-channels.\n", mISDNport->b_num); i = 0; @@ -2322,8 +2378,9 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st time(&mISDNport->l2establish); } - /* initially, we assume that the link is down, exept for nt-ptmp */ - mISDNport->l2link = (mISDNport->ntmode && !mISDNport->ptp)?1:0; + /* for nt-mode ptmp the link is always up */ + if (mISDNport->ntmode && !mISDNport->ptp) + mISDNport->l2link = 1; PDEBUG(DEBUG_BCHANNEL, "using 'mISDN_dsp.o' module\n");