X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=mISDN.cpp;h=d67d0e8770d33a41086f9932a51dfeec3210a1b3;hp=ab25d3be784592a5e886c3e6986d1f9071f18a7f;hb=79bd731c0db3e3202cfeed2af3fb217ae744b70f;hpb=a296b797ba03cb0716fbba841b26041a80ca4ce7 diff --git a/mISDN.cpp b/mISDN.cpp index ab25d3b..d67d0e8 100644 --- a/mISDN.cpp +++ b/mISDN.cpp @@ -63,7 +63,6 @@ static struct mi_ext_fn_s myfn; int mISDN_initialize(void) { char filename[256]; - int ver; /* try to open raw socket to check kernel */ mISDNsocket = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE); @@ -76,7 +75,7 @@ int mISDN_initialize(void) // set debug printout function myfn.prt_debug = my_mISDNlib_debug; - ver = init_layer3(4, &myfn); // buffer of 4 + init_layer3(4, &myfn); // buffer of 4 /* open debug, if enabled and not only stack debugging */ if (options.deb) { @@ -117,7 +116,7 @@ void mISDN_deinitialize(void) upqueue_avail = 0; } -int load_timer(struct lcr_timer *timer, void *instance, int index); +static int load_timer(struct lcr_timer *timer, void *instance, int index); /* * constructor @@ -147,6 +146,7 @@ PmISDN::PmISDN(int type, mISDNport *mISDNport, char *portname, struct port_setti p_m_inband_send_on = 0; p_m_inband_receive_on = 0; p_m_dtmf = !mISDNport->ifport->nodtmf; + p_m_dtmf_threshold = mISDNport->ifport->dtmf_threshold; memset(&p_m_timeout, 0, sizeof(p_m_timeout)); add_timer(&p_m_timeout, mISDN_timeout, this, 0); SCPY(p_m_pipeline, mISDNport->ifport->interface->pipeline); @@ -348,15 +348,20 @@ void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, int sock, u struct mISDNhead *ctrl = (struct mISDNhead *)buffer; unsigned int *d = (unsigned int *)(buffer+MISDN_HEADER_LEN); int ret; + int len = 8; if (sock < 0) return; + if (c1 == DTMF_TONE_START && c2 == 0) { + len = 4; + } + ctrl->prim = PH_CONTROL_REQ; ctrl->id = 0; *d++ = c1; *d++ = c2; - ret = sendto(sock, buffer, MISDN_HEADER_LEN+sizeof(int)*2, 0, NULL, 0); + ret = sendto(sock, buffer, MISDN_HEADER_LEN+len, 0, NULL, 0); if (ret <= 0) PERROR("Failed to send to socket %d\n", sock); chan_trace_header(mISDNport, isdnport, "BCHANNEL control", DIRECTION_OUT); @@ -400,6 +405,8 @@ static int _bchannel_create(struct mISDNport *mISDNport, int i) int ret; struct sockaddr_mISDN addr; + memset(&addr, 0, sizeof(addr)); + if (mISDNport->b_sock[i].inuse) { PERROR("Error: Socket already created for index %d\n", i); return(0); @@ -507,7 +514,7 @@ static void _bchannel_configure(struct mISDNport *mISDNport, int i) // if (port->p_m_txmix && mode == B_MODE_TRANSPARENT) // ph_control(mISDNport, port, handle, DSP_MIX_ON, 0, "DSP-MIX", 1); if (port->p_m_dtmf && mode == B_MODE_TRANSPARENT) - ph_control(mISDNport, port, handle, DTMF_TONE_START, 0, "DSP-DTMF", 1); + ph_control(mISDNport, port, handle, DTMF_TONE_START, port->p_m_dtmf_threshold, "DSP-DTMF", 1); if (port->p_m_crypt && mode == B_MODE_TRANSPARENT) ph_control_block(mISDNport, port, handle, DSP_BF_ENABLE_KEY, port->p_m_crypt_key, port->p_m_crypt_key_len, "DSP-CRYPT", port->p_m_crypt_key_len); } @@ -598,6 +605,7 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) class PmISDN *b_port = mISDNport->b_port[i]; int state = mISDNport->b_state[i]; int timer = -1; // no change +#if 0 int p_m_tx_gain = 0; int p_m_rx_gain = 0; char *p_m_pipeline = NULL; @@ -613,6 +621,7 @@ void bchannel_event(struct mISDNport *mISDNport, int i, int event) p_m_crypt_key_len = b_port->p_m_crypt_key_len; p_m_crypt_key_type = /*b_port->p_m_crypt_key_type*/1; } +#endif switch(event) { case B_EVENT_USE: @@ -921,7 +930,7 @@ void PmISDN::update_load(void) schedule_timer(&p_m_loadtimer, 0, 0); /* no delay the first time */ } -int load_timer(struct lcr_timer *timer, void *instance, int index) +static int load_timer(struct lcr_timer *timer, void *instance, int index) { class PmISDN *isdnport = (class PmISDN *)instance; @@ -958,7 +967,7 @@ void PmISDN::load_tx(void) p_m_load = 0; /* to send data, tone must be on */ - if ((p_tone_name[0] || p_m_crypt_msg_loops || p_m_inband_send_on) /* what tones? */ + if ((p_tone_name[0] || p_dov_tx || p_m_crypt_msg_loops || p_m_inband_send_on) /* what tones? */ && (p_m_load < p_m_preload) /* not too much load? */ && (p_state==PORT_STATE_CONNECT || p_m_mISDNport->tones || p_m_inband_send_on)) { /* connected or inband-tones? */ int tosend = p_m_preload - p_m_load, length; @@ -998,6 +1007,11 @@ void PmISDN::load_tx(void) tosend -= length; } + /* copy dov */ + if (p_dov_tx) { + tosend -= dov_tx(p, tosend); + } + /* copy tones */ if (p_tone_name[0] && tosend) { tosend -= read_audio(p, tosend); @@ -1057,10 +1071,23 @@ void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len end_trace(); if (!p_m_dtmf) return; - message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DTMF); - message->param.dtmf = cont & DTMF_TONE_MASK; - PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION DTMF digit '%c'\n", p_name, message->param.dtmf); - message_put(message); + if (p_type == PORT_TYPE_POTS_FXS_IN && p_state == PORT_STATE_IN_OVERLAP) { + class Pfxs *pfxs = (class Pfxs *)this; + if (!pfxs->p_m_fxs_allow_dtmf) { + PDEBUG(DEBUG_PORT, "PmISDN(%s) DTMF for FXS currently disabled\n", p_name); + return; + } + SCCAT(p_dialinginfo.id, cont & DTMF_TONE_MASK); + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION); + message->param.information.id[0] = cont & DTMF_TONE_MASK; + PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION INFORMATION digit '%s'\n", p_name, message->param.information.id); + message_put(message); + } else { + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_DTMF); + message->param.dtmf = cont & DTMF_TONE_MASK; + PDEBUG(DEBUG_PORT, "PmISDN(%s) PH_CONTROL INDICATION DTMF digit '%c'\n", p_name, message->param.dtmf); + message_put(message); + } return; } switch(cont) { @@ -1113,6 +1140,8 @@ void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len // printf(".");fflush(stdout);return; if (p_record) record(data, len, 1); // from up + if (p_tap) + tap(data, len, 1); // from up return; } if (hh->prim != PH_DATA_IND && hh->prim != DL_DATA_IND) { @@ -1120,6 +1149,10 @@ void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len return; } + /* dov is processed */ + if (p_dov_rx) + dov_rx(data, len); + /* inband is processed */ if (p_m_inband_receive_on) inband_receive(data, len); @@ -1153,6 +1186,8 @@ void PmISDN::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len /* record data */ if (p_record) record(data, len, 0); // from down + if (p_tap) + tap(data, len, 0); // from down /* randomize and listen to crypt message if enabled */ if (p_m_crypt_listen) { @@ -1191,9 +1226,9 @@ void PmISDN::set_tone(const char *dir, const char *tone) /* if no directory is given (by extension), we use interface.conf or options.conf */ if (!dir || !dir[0]) { - if (p_m_mISDNport->ifport->tones_dir[0]) - dir = p_m_mISDNport->ifport->tones_dir; - else if (options.tones_dir[0]) + if (p_tones_interface[0]) + dir = p_tones_interface; + else dir = options.tones_dir; } @@ -1411,17 +1446,44 @@ void PmISDN::message_crypt(unsigned int epoint_id, int message_id, union paramet } +/* MESSAGE_VOOTP */ +void PmISDN::message_vootp(unsigned int epoint_id, int message_id, union parameter *param) +{ + struct lcr_msg *message; + + message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_UPDATEBRIDGE); + message_put(message); + +#if 0 +does not make sense, since remote port may dejitter + if (param->vootp.enable) { + PDEBUG(DEBUG_ISDN, "PmISDN(%s) received vootp enable order, so we disable de-jitter.\n", p_name); + p_m_disable_dejitter = 1; + } +#endif + update_rxoff(); +} + /* * endpoint sends messages to the port */ int PmISDN::message_epoint(unsigned int epoint_id, int message_id, union parameter *param) { + /* messages also handled by base class */ + switch(message_id) { + case MESSAGE_VOOTP: /* crypt control command */ + PDEBUG(DEBUG_ISDN, "PmISDN(%s) received VoOTP encryption\n", p_name); + message_vootp(epoint_id, message_id, param); + break; + } + if (Port::message_epoint(epoint_id, message_id, param)) { if (message_id == MESSAGE_BRIDGE) update_rxoff(); return 1; } + /* messages not handled by base class */ switch(message_id) { case MESSAGE_mISDNSIGNAL: /* user command */ PDEBUG(DEBUG_ISDN, "PmISDN(%s) received special ISDN SIGNAL %d.\n", p_name, param->mISDNsignal.message); @@ -1449,7 +1511,7 @@ void PmISDN::update_rxoff(void) int tx_dejitter = 0; /* call bridges in user space OR crypto OR recording */ - if (p_bridge || p_m_crypt_msg_loops || p_m_crypt_listen || p_record || p_m_inband_receive_on) { + if (p_bridge || p_m_crypt_msg_loops || p_m_crypt_listen || p_record || p_tap || p_m_inband_receive_on || p_dov_rx) { /* rx IS required */ if (p_m_rxoff) { /* turn on RX */ @@ -1470,8 +1532,8 @@ void PmISDN::update_rxoff(void) ph_control(p_m_mISDNport, this, p_m_mISDNport->b_sock[p_m_b_index].fd, DSP_RECEIVE_OFF, 0, "DSP-RXOFF", 1); } } - /* recording */ - if (p_record) { + /* recording / tapping */ + if (p_record || p_tap) { /* txdata IS required */ if (!p_m_txdata) { /* turn on RX */ @@ -1510,7 +1572,7 @@ static int mISDN_upqueue(struct lcr_fd *fd, unsigned int what, void *instance, i struct mbuffer *mb; struct l3_msg *l3m; char byte; - int ret; + int __attribute__((__unused__)) ret; /* unset global semaphore */ upqueue_avail = 0; @@ -1746,7 +1808,7 @@ int do_layer3(struct mlayer3 *ml3, unsigned int cmd, unsigned int pid, struct l3 // this is no problem. upqueue_avail = 1; char byte = 0; - int ret; + int __attribute__((__unused__)) ret; ret = write(upqueue_pipe[1], &byte, 1); } return 0; @@ -1757,6 +1819,8 @@ int mISDN_getportbyname(int sock, int cnt, char *portname) struct mISDN_devinfo devinfo; int port = 0, ret; + memset(&devinfo, 0, sizeof(devinfo)); + /* resolve name */ while (port < cnt) { devinfo.id = port; @@ -1773,6 +1837,45 @@ int mISDN_getportbyname(int sock, int cnt, char *portname) return (port); } +#ifdef ISDN_P_FXS_POTS +/* handle frames from pots */ +static int pots_sock_callback(struct lcr_fd *fd, unsigned int what, void *instance, int i) +{ + struct mISDNport *mISDNport = (struct mISDNport *)instance; + unsigned char buffer[2048+MISDN_HEADER_LEN]; + struct mISDNhead *hh = (struct mISDNhead *)buffer; + unsigned int cont; + int ret; + + ret = recv(fd->fd, buffer, sizeof(buffer), 0); + if (ret < 0) { + PERROR("read error frame, errno %d\n", errno); + return 0; + } + if (ret < (int)MISDN_HEADER_LEN) { + PERROR("read short frame, got %d, expected %d\n", ret, (int)MISDN_HEADER_LEN); + return 0; + } + switch(hh->prim) { + case PH_CONTROL_IND: + cont = *((unsigned int *)(buffer + MISDN_HEADER_LEN)); + /* l1-control is sent to LCR */ + if (mISDNport->ntmode) + stack2manager_fxs(mISDNport, cont); + else + PERROR("FXO not supported!\n"); + break; + case PH_ACTIVATE_REQ: + break; + + default: + PERROR("child message not handled: prim(0x%x) socket(%d) msg->len(%d)\n", hh->prim, fd->fd, ret-MISDN_HEADER_LEN); + } + + return 0; +} +#endif + /* * global function to add a new card (port) */ @@ -1793,6 +1896,8 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport) struct mISDN_devinfo devinfo; unsigned int protocol, prop; + memset(&devinfo, 0, sizeof(devinfo)); + /* check port counts */ ret = ioctl(mISDNsocket, IMGETCOUNT, &cnt); if (ret < 0) { @@ -1841,32 +1946,29 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport) pri = 1; nt = 1; } -#ifdef ISDN_P_FXS - if (devinfo.Dprotocols & (1 << ISDN_P_FXS)) { +#ifdef ISDN_P_FXS_POTS + if (devinfo.Dprotocols & (1 << ISDN_P_FXO_POTS)) { pots = 1; te = 1; } -#endif -#ifdef ISDN_P_FXO - if (devinfo.Dprotocols & (1 << ISDN_P_FXO)) { + if (devinfo.Dprotocols & (1 << ISDN_P_FXS_POTS)) { pots = 1; nt = 1; } #endif if (force_nt && !nt) { - PERROR_RUNTIME("Port %d does not support NT-mode\n", port); + if (!pots) + PERROR_RUNTIME("Port %d does not support NT-mode\n", port); + else + PERROR_RUNTIME("Port %d does not support FXS-mode\n", port); return(NULL); } if (bri && pri) { PERROR_RUNTIME("Port %d supports BRI and PRI?? What kind of controller is that?. (Can't use this!)\n", port); return(NULL); } - if (pots && !bri && !pri) { - PERROR_RUNTIME("Port %d supports POTS, LCR does not!\n", port); - return(NULL); - } - if (!bri && !pri) { - PERROR_RUNTIME("Port %d does not support BRI nor PRI!\n", port); + if (!bri && !pri && !pots) { + PERROR_RUNTIME("Port %d does not support BRI nor PRI nor POTS!\n", port); return(NULL); } if (!nt && !te) { @@ -1879,6 +1981,10 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport) /* if TE an NT is supported (and not forced to NT), turn off NT */ if (te && nt) nt = 0; + if (pots && te) { + PERROR_RUNTIME("Port %d uses FXO-mode, but not supported by LCR!\n", port); + return(NULL); + } /* check for double use of port */ if (nt) { @@ -1959,40 +2065,85 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport) } /* allocate ressources of port */ - protocol = (nt)?L3_PROTOCOL_DSS1_NET:L3_PROTOCOL_DSS1_USER; - prop = (1 << MISDN_FLG_L2_CLEAN); - if (ptp) // ptp forced - 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); - /* open layer 3 and init upqueue */ - /* queue must be initializes, because l3-thread may send messages during open_layer3() */ - mqueue_init(&mISDNport->upqueue); - mISDNport->ml3 = open_layer3(port, protocol, prop , do_layer3, mISDNport); - if (!mISDNport->ml3) { - mqueue_purge(&mISDNport->upqueue); - PERROR_RUNTIME("open_layer3() failed for port %d\n", port); - start_trace(port, - ifport->interface, - NULL, - NULL, - DIRECTION_NONE, - CATEGORY_CH, - 0, - "PORT (open failed)"); - end_trace(); - mISDNport_close(mISDNport); - return(NULL); + if (!pots) { + /* ISDN */ + protocol = (nt)?L3_PROTOCOL_DSS1_NET:L3_PROTOCOL_DSS1_USER; + prop = (1 << MISDN_FLG_L2_CLEAN); + if (ptp) // ptp forced + 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); + /* open layer 3 and init upqueue */ + /* queue must be initializes, because l3-thread may send messages during open_layer3() */ + mqueue_init(&mISDNport->upqueue); + mISDNport->ml3 = open_layer3(port, protocol, prop , do_layer3, mISDNport); + if (!mISDNport->ml3) { + mqueue_purge(&mISDNport->upqueue); + PERROR_RUNTIME("open_layer3() failed for port %d\n", port); + start_trace(port, + ifport->interface, + NULL, + NULL, + DIRECTION_NONE, + CATEGORY_CH, + 0, + "PORT (open failed)"); + end_trace(); + mISDNport_close(mISDNport); + return(NULL); + } + } else { +#ifdef ISDN_P_FXS_POTS + /* POTS */ + int sock, ret; + struct sockaddr_mISDN addr; + struct mISDNhead act; + + /* open socket */ + /* queue must be initializes, because even pots interfaces are checked at mISDN_upqueue loop */ + mqueue_init(&mISDNport->upqueue); + sock = socket(PF_ISDN, SOCK_DGRAM, (nt) ? ISDN_P_FXS_POTS : ISDN_P_FXO_POTS); + if (sock < 0) { + PERROR_RUNTIME("Cannot open mISDN due to '%s'.\n", strerror(errno)); + return NULL; + } + /* bind socket to dchannel */ + addr.family = AF_ISDN; + addr.dev = port; + addr.channel = 0; + ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + if (ret < 0) { + PERROR_RUNTIME("Error: Failed to bind pots control channel\n"); + start_trace(port, + ifport->interface, + NULL, + NULL, + DIRECTION_NONE, + CATEGORY_CH, + 0, + "PORT (open failed)"); + end_trace(); + return(NULL); + } + act.prim = PH_ACTIVATE_REQ; + act.id = 0; + ret = sendto(sock, &act, MISDN_HEADER_LEN, 0, NULL, 0); + if (ret <= 0) + PERROR("Failed to send to socket %d\n", sock); + mISDNport->pots_sock.fd = sock; + register_fd(&mISDNport->pots_sock, LCR_FD_READ, pots_sock_callback, mISDNport, i); +#endif } SCPY(mISDNport->name, devinfo.name); mISDNport->b_num = devinfo.nrbchan; mISDNport->portnum = port; mISDNport->ntmode = nt; + mISDNport->pots = pots; mISDNport->tespecial = ifport->tespecial; mISDNport->pri = pri; mISDNport->ptp = ptp; @@ -2008,7 +2159,7 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport) } /* if ptp, pull up the link */ - if (mISDNport->l2hold && (mISDNport->ptp || !mISDNport->ntmode)) { + if (!pots && mISDNport->l2hold && (mISDNport->ptp || !mISDNport->ntmode)) { mISDNport->ml3->to_layer3(mISDNport->ml3, MT_L2ESTABLISH, 0, NULL); l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_REQ, DIRECTION_OUT); add_trace("tei", NULL, "%d", 0); @@ -2016,8 +2167,8 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport) schedule_timer(&mISDNport->l2establish, 5, 0); /* 5 seconds */ } - /* for nt-mode ptmp the link is always up */ - if (mISDNport->ntmode && !mISDNport->ptp) + /* for POTS or nt-mode ptmp the link is always up */ + if (pots || (mISDNport->ntmode && !mISDNport->ptp)) mISDNport->l2link = 1; PDEBUG(DEBUG_BCHANNEL, "using 'mISDN_dsp.o' module\n"); @@ -2030,7 +2181,10 @@ struct mISDNport *mISDNport_open(struct interface_port *ifport) CATEGORY_CH, 0, "PORT (open)"); - add_trace("mode", NULL, (mISDNport->ntmode)?"network":"terminal"); + if (!pots) + add_trace("mode", NULL, (mISDNport->ntmode)?"network":"terminal"); + else + add_trace("mode", NULL, (mISDNport->ntmode)?"FXS":"FXO"); add_trace("channels", NULL, "%d", mISDNport->b_num); if (mISDNport->ss5) add_trace("ccitt#5", NULL, "enabled"); @@ -2125,6 +2279,12 @@ void mISDNport_close(struct mISDNport *mISDNport) close_layer3(mISDNport->ml3); } + /* close layer 1, if open */ + if (mISDNport->pots_sock.fd) { + unregister_fd(&mISDNport->pots_sock); + close(mISDNport->pots_sock.fd); + } + /* purge upqueue */ mqueue_purge(&mISDNport->upqueue); @@ -2157,6 +2317,9 @@ int PmISDN::bridge_rx(unsigned char *data, int length) struct mISDNhead *hh = (struct mISDNhead *)buf; int ret; + if ((ret = Port::bridge_rx(data, length))) + return ret; + if (p_m_b_index < 0) return -EIO; if (p_m_mISDNport->b_state[p_m_b_index] != B_STATE_ACTIVE) @@ -2165,7 +2328,7 @@ int PmISDN::bridge_rx(unsigned char *data, int length) /* check if high priority tones exist * ignore data in this case */ - if (p_tone_name[0] || p_m_crypt_msg_loops || p_m_inband_send_on) + if (p_tone_name[0] || p_dov_tx || p_m_crypt_msg_loops || p_m_inband_send_on) return -EBUSY; /* preload procedure