]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add more couters, better process vs and vr
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 23 May 2007 18:19:04 +0000 (18:19 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 23 May 2007 18:19:04 +0000 (18:19 +0000)
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@110 a93c3328-9c30-0410-af19-c9cd2b2d52af

libs/openzap/src/isdn/Q921.c
libs/openzap/src/isdn/include/Q921.h

index afabf833ada9fd5d1d35d7b0dbb42771404e9c6c..e1e326acd92940561bb6daf9c0925ff0d99734c9 100644 (file)
@@ -64,8 +64,9 @@ void Q921_InitTrunk(L2TRUNK trunk,
                MFIFOCreate(trunk->HDLCInQueue, Q921MAXHDLCSPACE, 10);
                trunk->initialized = INITIALIZED_MAGIC;
        }
+       trunk->va = 0;
+       trunk->vs = 0;  
        trunk->vr = 0;
-       trunk->vs = 0;
        trunk->state = 0;
        trunk->sapi = sapi;
        trunk->tei = tei;
@@ -355,6 +356,7 @@ int Q921ProcSABME(L2TRUNK trunk, L2UCHAR *mes, L2INT size)
 
     trunk->vr=0;
     trunk->vs=0;
+       trunk->va=0;
 
     return 1;
 }
@@ -382,29 +384,46 @@ int Q921Rx12(L2TRUNK trunk)
     L2UCHAR *mes;
     L2INT rs,size;     /* receive size & Q921 frame size*/
     L2UCHAR *smes = MFIFOGetMesPtr(trunk->HDLCInQueue, &size);
-       
+       L2UCHAR nr;
+
     if(smes != NULL)
     {
+               if ((mes[2] & 3) != 3) {
+                       /* we have an S or I frame */
+                       /* if nr is between va and vs, update our va counter */
+                       nr = (mes[3] >> 1);
+                       if (nr >= trunk->va && nr <= trunk->vs) {
+                               trunk->va = nr;
+                       }
+               }
+
         rs = size - trunk->Q921HeaderSpace;
         mes = &smes[trunk->Q921HeaderSpace];
 
         /* check for I frame */
         if((mes[2] & 0x01) == 0)
         {
-            if(Q921Tx23Proc(trunk, smes, size-2)) /* -2 to clip away CRC */
+                       L2INT vs = trunk->vs;
+                       /* we increment before we "really" know its good so that if we send in the callback, we use the right nr */
+                       trunk->vr++;
+            if(Q921Tx23Proc(trunk, smes, size-2) >= 0) /* -2 to clip away CRC */
             {
-                trunk->vr++;
-                Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01);
-            }
+                               if (vs == trunk->vs) {
+                                       Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[3]&0x01);
+                               }        
+                       }
             else
             {
                 /* todo: whatever*/
-            }
+                               trunk->vr--;
+           }
         }
 
         /* check for RR */
         else if(mes[2] ==0x01)
         {
+                       
+                       /* todo: we probably should schedule to send RR at timeout here */
             /* todo: check if RR is responce to I */
             Q921SendRR(trunk, (mes[0]&0xfc)>>2, (mes[0]>>1)&0x01,mes[1]>>1, mes[2]&0x01);
         }
index 1f7f53a99bd0e30390fb53f5789b5b1b04dc5a66..89061c2fdc13c4616e1336e7fbd458c12c7865e3 100644 (file)
@@ -98,6 +98,7 @@ struct Q921Data
 {
     L2UCHAR HDLCInQueue[Q921MAXHDLCSPACE];
        L2INT initialized;
+       L2UCHAR va;
     L2UCHAR vs;
     L2UCHAR vr;
     L2INT state;