lcr work (soon done :)
[lcr.git] / mISDN.cpp
index f50abb6..b44049f 100644 (file)
--- a/mISDN.cpp
+++ b/mISDN.cpp
@@ -456,7 +456,7 @@ void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, unsigned lo
        *d++ = c1;
        *d++ = c2;
        ret = sendto(sock, buffer, MISDN_HEADER_LEN+sizeof(int)*2, 0, NULL, 0);
-       if (!ret)
+       if (ret <= 0)
                PERROR("Failed to send to socket %d\n", sock);
 #else
 void ph_control(struct mISDNport *mISDNport, class PmISDN *isdnport, unsigned long addr, unsigned long c1, unsigned long c2, char *trace_name, int trace_value)
@@ -504,7 +504,7 @@ void ph_control_block(struct mISDNport *mISDNport, class PmISDN *isdnport, int s
        *d++ = c1;
        memcpy(d, c2, c2_len);
        ret = sendto(sock, buffer, MISDN_HEADER_LEN+sizeof(int)+c2_len, 0, NULL, 0);
-       if (!ret)
+       if (ret <= 0)
                PERROR("Failed to send to socket %d\n", sock);
 #else
 void ph_control_block(struct mISDNport *mISDNport, class PmISDN *isdnport, unsigned long addr, unsigned long c1, void *c2, int c2_len, char *trace_name, int trace_value)
@@ -678,7 +678,7 @@ static void _bchannel_activate(struct mISDNport *mISDNport, int i, int activate)
        act.prim = (activate)?PH_ACTIVATE_REQ:PH_DEACTIVATE_REQ; 
        act.id = 0;
        ret = sendto(mISDNport->b_socket[i], &act, MISDN_HEADER_LEN, 0, NULL, 0);
-       if (!ret)
+       if (ret <= 0)
                PERROR("Failed to send to socket %d\n", mISDNport->b_socket[i]);
 #else
        iframe_t act;
@@ -1613,14 +1613,14 @@ int PmISDN::handler(void)
                        }
 
                        /* send data */
-                       if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE)
+                       if (p_m_mISDNport->b_state[p_m_b_index] == B_STATE_ACTIVE && ISDN_LOAD-p_m_load-tosend > 0)
                        {
 #ifdef SOCKET_MISDN
                                frm->prim = PH_DATA_REQ;
                                frm->id = 0;
                                ret = sendto(p_m_mISDNport->b_socket[p_m_b_index], buf, MISDN_HEADER_LEN+ISDN_LOAD-p_m_load-tosend, 0, NULL, 0);
-                               if (!ret)
-                                       PERROR("Failed to send to socket %d\n", p_m_mISDNport->b_socket[p_m_b_index]);
+                               if (ret <= 0)
+                                       PERROR("Failed to send to socket %d (samples = %d)\n", p_m_mISDNport->b_socket[p_m_b_index], ISDN_LOAD-p_m_load-tosend);
 #else
                                frm->prim = DL_DATA | REQUEST; 
                                frm->addr = p_m_mISDNport->b_addr[p_m_b_index] | FLG_MSG_DOWN;
@@ -1746,11 +1746,8 @@ void PmISDN::bchannel_receive(iframe_t *frm)
 #endif
                {
 #ifndef OLD_MISDN
-#ifdef SOCKET_MISDN
-                       case DSP_TX_DATA:
-#else
+#ifndef SOCKET_MISDN
                        case CMX_TX_DATA:
-#endif
                        if (!p_m_txdata)
                        {
                                /* if tx is off, it may happen that fifos send us pending informations, we just ignore them */
@@ -1766,6 +1763,7 @@ void PmISDN::bchannel_receive(iframe_t *frm)
                                record(data, len, 1); // from up
                        break;
 #endif
+#endif
 
                        default:
                        chan_trace_header(p_m_mISDNport, this, "BCHANNEL control", DIRECTION_IN);
@@ -1779,6 +1777,23 @@ void PmISDN::bchannel_receive(iframe_t *frm)
                return;
        }
 #ifdef SOCKET_MISDN
+       if (hh->prim == PH_DATA_REQ || hh->prim == DL_DATA_REQ)
+       {
+               if (!p_m_txdata)
+               {
+                       /* if tx is off, it may happen that fifos send us pending informations, we just ignore them */
+                       PDEBUG(DEBUG_BCHANNEL, "PmISDN(%s) ignoring tx data, because 'txdata' is turned off\n", p_name);
+                       return;
+               }
+               /* see below (same condition) */
+               if (p_state!=PORT_STATE_CONNECT
+                        && !p_m_mISDNport->tones)
+                       return;
+//             printf(".");fflush(stdout);return;
+               if (p_record)
+                       record(data, len, 1); // from up
+               return;
+       }
        if (hh->prim != PH_DATA_IND && hh->prim != DL_DATA_IND)
        {
                PERROR("Bchannel received unknown primitve: 0x%x\n", hh->prim);
@@ -2365,6 +2380,7 @@ int mISDN_handler(void)
 
                                case MT_L2ESTABLISH:
                                l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_IND, DIRECTION_IN);
+                               add_trace("tei", NULL, "%d", l3m->pid);
                                end_trace();
                                if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127)
                                {
@@ -2379,6 +2395,7 @@ int mISDN_handler(void)
 
                                case MT_L2RELEASE:
                                l1l2l3_trace_header(mISDNport, NULL, L2_RELEASE_IND, DIRECTION_IN);
+                               add_trace("tei", NULL, "%d", l3m->pid);
                                end_trace();
                                if ((!mISDNport->ntmode || mISDNport->ptp) && l3m->pid < 127)
                                {
@@ -2418,6 +2435,7 @@ int mISDN_handler(void)
                                        PDEBUG(DEBUG_ISDN, "the L2 establish timer expired, we try to establish the link portnum=%d.\n", mISDNport->portnum);
                                        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);
                                        end_trace();
                                        time(&mISDNport->l2establish);
                                        return(1);
@@ -2557,6 +2575,7 @@ int mISDN_handler(void)
                                                mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
                                        }
                                        l1l2l3_trace_header(mISDNport, NULL, L2_ESTABLISH_REQ, DIRECTION_OUT);
+                                       add_trace("tei", NULL, "%d", 0);
                                        end_trace();
                                        time(&mISDNport->l2establish);
                                        return(1);
@@ -3338,6 +3357,7 @@ struct mISDNport *mISDNport_open(int port, int ptp, int force_nt, int l2hold, st
        {
                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);
                end_trace();
                time(&mISDNport->l2establish);
        }
@@ -3845,7 +3865,7 @@ void PmISDN::txfromup(unsigned char *data, int length)
                hh->id = 0;
                memset(buf+MISDN_HEADER_LEN, (options.law=='a')?0x2a:0xff, ISDN_LOAD);
                ret = sendto(p_m_mISDNport->b_socket[p_m_b_index], buf, MISDN_HEADER_LEN+ISDN_LOAD, 0, NULL, 0);
-               if (!ret)
+               if (ret <= 0)
                        PERROR("Failed to send to socket %d\n", p_m_mISDNport->b_socket[p_m_b_index]);
 #else
                frm->prim = DL_DATA | REQUEST; 
@@ -3870,7 +3890,7 @@ void PmISDN::txfromup(unsigned char *data, int length)
        hh->id = 0;
        memcpy(buf+MISDN_HEADER_LEN, data, length);
        ret = sendto(p_m_mISDNport->b_socket[p_m_b_index], buf, MISDN_HEADER_LEN+length, 0, NULL, 0);
-       if (!ret)
+       if (ret <= 0)
                PERROR("Failed to send to socket %d\n", p_m_mISDNport->b_socket[p_m_b_index]);
 #else
        frm->prim = DL_DATA | REQUEST;