root/net/netrom/nr_timer.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. nr_set_timer
  2. nr_reset_timer
  3. nr_timer

   1 /*
   2  *      NET/ROM release 003
   3  *
   4  *      This is ALPHA test software. This code may break your machine, randomly fail to work with new 
   5  *      releases, misbehave and/or generally screw up. It might even work. 
   6  *
   7  *      This code REQUIRES 1.2.1 or higher/ NET3.029
   8  *
   9  *      This module:
  10  *              This module is free software; you can redistribute it and/or
  11  *              modify it under the terms of the GNU General Public License
  12  *              as published by the Free Software Foundation; either version
  13  *              2 of the License, or (at your option) any later version.
  14  *
  15  *      History
  16  *      NET/ROM 001     Jonathan(G4KLX) Cloned from ax25_timer.c
  17  */
  18 
  19 #include <linux/config.h>
  20 #ifdef CONFIG_NETROM
  21 #include <linux/errno.h>
  22 #include <linux/types.h>
  23 #include <linux/socket.h>
  24 #include <linux/in.h>
  25 #include <linux/kernel.h>
  26 #include <linux/sched.h>
  27 #include <linux/timer.h>
  28 #include <linux/string.h>
  29 #include <linux/sockios.h>
  30 #include <linux/net.h>
  31 #include <net/ax25.h>
  32 #include <linux/inet.h>
  33 #include <linux/netdevice.h>
  34 #include <linux/skbuff.h>
  35 #include <net/sock.h>
  36 #include <asm/segment.h>
  37 #include <asm/system.h>
  38 #include <linux/fcntl.h>
  39 #include <linux/mm.h>
  40 #include <linux/interrupt.h>
  41 #include <net/netrom.h>
  42 
  43 static void nr_timer(unsigned long);
  44 
  45 /*
  46  *      Linux set/reset timer routines
  47  */
  48 void nr_set_timer(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
  49 {
  50         unsigned long flags;
  51         
  52         save_flags(flags);
  53         cli();
  54         del_timer(&sk->timer);
  55         restore_flags(flags);
  56 
  57         sk->timer.next     = sk->timer.prev = NULL;     
  58         sk->timer.data     = (unsigned long)sk;
  59         sk->timer.function = &nr_timer;
  60 
  61         sk->timer.expires = jiffies+10;
  62         add_timer(&sk->timer);
  63 }
  64 
  65 static void nr_reset_timer(struct sock *sk)
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67         unsigned long flags;
  68         
  69         save_flags(flags);
  70         cli();
  71         del_timer(&sk->timer);
  72         restore_flags(flags);
  73 
  74         sk->timer.data     = (unsigned long)sk;
  75         sk->timer.function = &nr_timer;
  76         sk->timer.expires  = jiffies+10;
  77         add_timer(&sk->timer);
  78 }
  79 
  80 /*
  81  *      NET/ROM TIMER 
  82  *
  83  *      This routine is called every 500ms. Decrement timer by this
  84  *      amount - if expired then process the event.
  85  */
  86 static void nr_timer(unsigned long param)
     /* [previous][next][first][last][top][bottom][index][help] */
  87 {
  88         struct sock *sk = (struct sock *)param;
  89 
  90         switch (sk->nr->state) {
  91                 case NR_STATE_0:
  92                         /* Magic here: If we listen() and a new link dies before it
  93                            is accepted() it isn't 'dead' so doesn't get removed. */
  94                         if (sk->destroy || (sk->state == TCP_LISTEN && sk->dead)) {
  95                                 del_timer(&sk->timer);
  96                                 nr_destroy_socket(sk);
  97                                 return;
  98                         }
  99                         break;
 100 
 101                 case NR_STATE_3:
 102                         /*
 103                          * Check for the state of the receive buffer.
 104                          */
 105                         if (sk->rmem_alloc < (sk->rcvbuf / 2) && (sk->nr->condition & OWN_RX_BUSY_CONDITION)) {
 106                                 sk->nr->condition &= ~OWN_RX_BUSY_CONDITION;
 107                                 nr_write_internal(sk, NR_INFOACK);
 108                                 sk->nr->condition &= ~ACK_PENDING_CONDITION;
 109                                 sk->nr->vl = sk->nr->vr;
 110                                 break;
 111                         }
 112                         /*
 113                          * Check for frames to transmit.
 114                          */
 115                         nr_kick(sk);
 116                         break;
 117 
 118                 default:
 119                         break;
 120         }
 121 
 122         if (sk->nr->t2timer > 0 && --sk->nr->t2timer == 0) {
 123                 if (sk->nr->state == NR_STATE_3) {
 124                         if (sk->nr->condition & ACK_PENDING_CONDITION) {
 125                                 sk->nr->condition &= ~ACK_PENDING_CONDITION;
 126                                 nr_enquiry_response(sk);
 127                         }
 128                 }
 129         }
 130 
 131         if (sk->nr->t4timer > 0 && --sk->nr->t4timer == 0) {
 132                 sk->nr->condition &= ~PEER_RX_BUSY_CONDITION;
 133         }
 134 
 135         if (sk->nr->t1timer == 0 || --sk->nr->t1timer > 0) {
 136                 nr_reset_timer(sk);
 137                 return;
 138         }
 139 
 140         switch (sk->nr->state) {
 141                 case NR_STATE_1: 
 142                         if (sk->nr->n2count == sk->nr->n2) {
 143                                 nr_clear_queues(sk);
 144                                 sk->nr->state = NR_STATE_0;
 145                                 sk->state     = TCP_CLOSE;
 146                                 sk->err       = ETIMEDOUT;
 147                                 if (!sk->dead)
 148                                         sk->state_change(sk);
 149                                 sk->dead      = 1;
 150                         } else {
 151                                 sk->nr->n2count++;
 152                                 nr_write_internal(sk, NR_CONNREQ);
 153                         }
 154                         break;
 155 
 156                 case NR_STATE_2:
 157                         if (sk->nr->n2count == sk->nr->n2) {
 158                                 nr_clear_queues(sk);
 159                                 sk->nr->state = NR_STATE_0;
 160                                 sk->state     = TCP_CLOSE;
 161                                 sk->err       = ETIMEDOUT;
 162                                 if (!sk->dead)
 163                                         sk->state_change(sk);
 164                                 sk->dead      = 1;
 165                         } else {
 166                                 sk->nr->n2count++;
 167                                 nr_write_internal(sk, NR_DISCREQ);
 168                         }
 169                         break;
 170 
 171                 case NR_STATE_3:
 172                         if (sk->nr->n2count == sk->nr->n2) {
 173                                 nr_clear_queues(sk);
 174                                 sk->nr->state = NR_STATE_0;
 175                                 sk->state     = TCP_CLOSE;
 176                                 sk->err       = ETIMEDOUT;
 177                                 if (!sk->dead)
 178                                         sk->state_change(sk);
 179                                 sk->dead      = 1;
 180                         } else {
 181                                 sk->nr->n2count++;
 182                                 nr_requeue_frames(sk);
 183                         }
 184                         break;
 185         }
 186 
 187         sk->nr->t1timer = sk->nr->t1 = nr_calculate_t1(sk);
 188 
 189         nr_set_timer(sk);
 190 }
 191 
 192 #endif

/* [previous][next][first][last][top][bottom][index][help] */