home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR3 / KA9Q212.ZIP / LAPBTIME.C < prev    next >
C/C++ Source or Header  |  1993-07-16  |  3KB  |  122 lines

  1. /* LAPB (AX25) timer recovery routines
  2.  * Copyright 1991 Phil Karn, KA9Q
  3.  */
  4.  
  5. /****************************************************************************
  6. *    $Id: lapbtime.c 1.2 93/07/16 11:46:17 ROOT_DOS Exp $
  7. *    15 Jul 93    1.2        GT    AX25 conditional.                                *
  8. ****************************************************************************/
  9.  
  10. #include "global.h"
  11. #include "mbuf.h"
  12. #include "ax25.h"
  13. #include "timer.h"
  14. #include "lapb.h"
  15. #include "ip.h"
  16. #include "config.h"
  17.  
  18. #if    AX25
  19.  
  20. static void tx_enq __ARGS((struct ax25_cb *axp));
  21.  
  22. /* Called whenever timer T1 expires */
  23. void
  24. recover(p)
  25. void *p;
  26. {
  27.     register struct ax25_cb *axp = (struct ax25_cb *)p;
  28.  
  29.     axp->flags.retrans = 1;
  30.     axp->retries++;
  31.     if((1L << axp->retries) < Blimit)
  32.         /* Back off retransmit timer */
  33.         set_timer(&axp->t1,dur_timer(&axp->t1)*2);
  34.  
  35.     switch(axp->state){
  36.     case LAPB_SETUP:
  37.         if(axp->n2 != 0 && axp->retries > axp->n2){
  38.             free_q(&axp->txq);
  39.             axp->reason = LB_TIMEOUT;
  40.             lapbstate(axp,LAPB_DISCONNECTED);
  41.         } else {
  42.             sendctl(axp,LAPB_COMMAND,SABM|PF);
  43.             start_timer(&axp->t1);
  44.         }
  45.         break;
  46.     case LAPB_DISCPENDING:
  47.         if(axp->n2 != 0 && axp->retries > axp->n2){
  48.             axp->reason = LB_TIMEOUT;
  49.             lapbstate(axp,LAPB_DISCONNECTED);
  50.         } else {
  51.             sendctl(axp,LAPB_COMMAND,DISC|PF);
  52.             start_timer(&axp->t1);
  53.         }
  54.         break;
  55.     case LAPB_CONNECTED:
  56.     case LAPB_RECOVERY:
  57.         if(axp->n2 != 0 && axp->retries > axp->n2){
  58.             /* Give up */
  59.             sendctl(axp,LAPB_RESPONSE,DM|PF);
  60.             free_q(&axp->txq);
  61.             axp->reason = LB_TIMEOUT;
  62.             lapbstate(axp,LAPB_DISCONNECTED);
  63.         } else {
  64.             /* Transmit poll */
  65.             tx_enq(axp);
  66.             lapbstate(axp,LAPB_RECOVERY);
  67.         }
  68.         break;
  69.     }
  70. }
  71.  
  72.  
  73. /* Send a poll (S-frame command with the poll bit set) */
  74. void
  75. pollthem(p)
  76. void *p;
  77. {
  78.     register struct ax25_cb *axp;
  79.  
  80.     axp = (struct ax25_cb *)p;
  81.     if(axp->proto == V1)
  82.         return;    /* Not supported in the old protocol */
  83.     switch(axp->state){
  84.     case LAPB_CONNECTED:
  85.         axp->retries = 0;
  86.         tx_enq(axp);
  87.         lapbstate(axp,LAPB_RECOVERY);
  88.         break;
  89.     }
  90. }
  91. /* Transmit query */
  92. static void
  93. tx_enq(axp)
  94. register struct ax25_cb *axp;
  95. {
  96.     char ctl;
  97.     struct mbuf *bp;
  98.  
  99.     /* I believe that retransmitting the oldest unacked
  100.      * I-frame tends to give better performance than polling,
  101.      * as long as the frame isn't too "large", because
  102.      * chances are that the I frame got lost anyway.
  103.      * This is an option in LAPB, but not in the official AX.25.
  104.      */
  105.     if(axp->txq != NULLBUF
  106.      && (len_p(axp->txq) < axp->pthresh || axp->proto == V1)){
  107.         /* Retransmit oldest unacked I-frame */
  108.         dup_p(&bp,axp->txq,0,len_p(axp->txq));
  109.         ctl = PF | I | (((axp->vs - axp->unack) & MMASK) << 1)
  110.          | (axp->vr << 5);
  111.         sendframe(axp,LAPB_COMMAND,ctl,bp);
  112.     } else {
  113.         ctl = len_p(axp->rxq) >= axp->window ? RNR|PF : RR|PF;    
  114.         sendctl(axp,LAPB_COMMAND,ctl);
  115.     }
  116.     axp->response = 0;    
  117.     stop_timer(&axp->t3);
  118.     start_timer(&axp->t1);
  119. }
  120.  
  121. #endif    /* AX25 */
  122.