fixed the occasional no audio issue, still need deeper investigation .. echotraining...
[asterisk/asterisk.git] / channels / misdn / isdn_lib.c
index acd3a9f..13838ff 100644 (file)
@@ -635,6 +635,18 @@ int misdn_lib_get_l2_up(struct misdn_stack *stack)
        return 0;
 }
 
+int misdn_lib_get_l2_te_ptp_up(struct misdn_stack *stack)
+{
+       iframe_t act;
+               
+       act.prim = DL_ESTABLISH | REQUEST;
+       act.addr = (stack->upper_id  & ~LAYER_ID_MASK) | 3 | FLG_MSG_DOWN;
+               
+       act.dinfo = 0;
+       act.len = 0;
+       return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
+       return 0;
+}
 
 int misdn_lib_get_l2_status(struct misdn_stack *stack)
 {
@@ -656,9 +668,9 @@ int misdn_lib_get_short_status(struct misdn_stack *stack)
        
        act.prim = MGR_SHORTSTATUS | REQUEST; 
        
-       act.addr = (stack->upper_id | FLG_MSG_DOWN)  ;
+       act.addr = (stack->upper_id | MSG_BROADCAST)  ;
 
-       act.dinfo = SSTATUS_L1;
+       act.dinfo = SSTATUS_BROADCAST_BIT | SSTATUS_ALL;
        
        act.len = 0;
        return mISDN_write(stack->midev, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
@@ -1126,9 +1138,10 @@ struct misdn_stack* stack_init( int midev, int port, int ptp )
                if (!stack->nt) {
                        /*assume L1 is up, we'll get DEACTIVATES soon, for non
                         * up L1s*/
-                       stack->l1link=1;
+                       stack->l1link=0;
                }
 
+               misdn_lib_get_short_status(stack);
                misdn_lib_get_l1_up(stack);
                misdn_lib_get_l2_up(stack);
                
@@ -2024,7 +2037,8 @@ int handle_bchan(msg_t *msg)
                                
                                int i=cb_event( EVENT_BCHAN_DATA, bc, glob_mgr->user_data);
                                if (i<0) {
-                                       clean_up_bc(bc);
+                                       cb_log(2,stack->port,"cb_event returned <0\n");
+                                       /*clean_up_bc(bc);*/
                                }
                        }
                }
@@ -2306,12 +2320,14 @@ int handle_mgmt(msg_t *msg)
        
        switch(frm->prim) {
        case MGR_SHORTSTATUS | INDICATION:
+       case MGR_SHORTSTATUS | CONFIRM:
                cb_log(2, 0, "MGMT: Short status dinfo %x\n",frm->dinfo);
                
                switch (frm->dinfo) {
                case SSTATUS_L1_ACTIVATED:
                        cb_log(1, 0, "MGMT: SSTATUS: L1_ACTIVATED \n");
                        stack->l1link=1;
+               
                        break;
                case SSTATUS_L1_DEACTIVATED:
                        cb_log(1, 0, "MGMT: SSTATUS: L1_DEACTIVATED \n");
@@ -2327,12 +2343,13 @@ int handle_mgmt(msg_t *msg)
                case SSTATUS_L2_ESTABLISHED:
                        cb_log(1, stack->port, "MGMT: SSTATUS: L2_ESTABLISH \n");
                        stack->l2link=1;
+                       if ( !stack->ptp && !stack->nt )
+                               stack->l1link=2;
                        break;
                        
                case SSTATUS_L2_RELEASED:
                        cb_log(1, stack->port, "MGMT: SSTATUS: L2_RELEASED \n");
                        stack->l2link=0;
-                       stack->l1link=2;
                        break;
                }