root/net/ax25/ax25_timer.c

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

DEFINITIONS

This source file includes following definitions.
  1. ax25_set_timer
  2. ax25_reset_timer
  3. ax25_timer
  4. ax25_t1_timeout

   1 /*
   2  *      AX.25 release 031
   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  *      AX.25 028a      Jonathan(G4KLX) New state machine based on SDL diagrams.
  17  *      AX.25 028b      Jonathan(G4KLX) Extracted AX25 control block from the
  18  *                                      sock structure.
  19  *      AX.25 029       Alan(GW4PTS)    Switched to KA9Q constant names.
  20  */
  21 
  22 #include <linux/config.h>
  23 #ifdef CONFIG_AX25
  24 #include <linux/errno.h>
  25 #include <linux/types.h>
  26 #include <linux/socket.h>
  27 #include <linux/in.h>
  28 #include <linux/kernel.h>
  29 #include <linux/sched.h>
  30 #include <linux/timer.h>
  31 #include <linux/string.h>
  32 #include <linux/sockios.h>
  33 #include <linux/net.h>
  34 #include <net/ax25.h>
  35 #include <linux/inet.h>
  36 #include <linux/netdevice.h>
  37 #include <linux/skbuff.h>
  38 #include <net/sock.h>
  39 #include <asm/segment.h>
  40 #include <asm/system.h>
  41 #include <linux/fcntl.h>
  42 #include <linux/mm.h>
  43 #include <linux/interrupt.h>
  44 #ifdef CONFIG_NETROM
  45 #include <net/netrom.h>
  46 #endif
  47 
  48 static void ax25_timer(unsigned long);
  49 
  50 /*
  51  *      Linux set/reset timer routines
  52  */
  53 void ax25_set_timer(ax25_cb *ax25)
     /* [previous][next][first][last][top][bottom][index][help] */
  54 {
  55         unsigned long flags;    
  56 
  57         save_flags(flags);
  58         cli();
  59         del_timer(&ax25->timer);
  60         restore_flags(flags);
  61 
  62         ax25->timer.next     = ax25->timer.prev = NULL; 
  63         ax25->timer.data     = (unsigned long)ax25;
  64         ax25->timer.function = &ax25_timer;
  65 
  66         ax25->timer.expires = jiffies + 10;
  67         add_timer(&ax25->timer);
  68 }
  69 
  70 static void ax25_reset_timer(ax25_cb *ax25)
     /* [previous][next][first][last][top][bottom][index][help] */
  71 {
  72         unsigned long flags;
  73         
  74         save_flags(flags);
  75         cli();
  76         del_timer(&ax25->timer);
  77         restore_flags(flags);
  78 
  79         ax25->timer.data     = (unsigned long)ax25;
  80         ax25->timer.function = &ax25_timer;
  81         ax25->timer.expires  = jiffies + 10;
  82         add_timer(&ax25->timer);
  83 }
  84 
  85 /*
  86  *      AX.25 TIMER 
  87  *
  88  *      This routine is called every 500ms. Decrement timer by this
  89  *      amount - if expired then process the event.
  90  */
  91 static void ax25_timer(unsigned long param)
     /* [previous][next][first][last][top][bottom][index][help] */
  92 {
  93         ax25_cb *ax25 = (ax25_cb *)param;
  94 
  95         switch (ax25->state) {
  96                 case AX25_STATE_0:
  97                         /* Magic here: If we listen() and a new link dies before it
  98                            is accepted() it isnt 'dead' so doesnt get removed. */
  99                         if (ax25->sk == NULL || ax25->sk->destroy || (ax25->sk->state == TCP_LISTEN && ax25->sk->dead)) {
 100                                 del_timer(&ax25->timer);
 101                                 ax25_destroy_socket(ax25);
 102                                 return;
 103                         }
 104                         break;
 105 
 106                 case AX25_STATE_3:
 107                 case AX25_STATE_4:
 108                         /*
 109                          * Check the state of the receive buffer.
 110                          */
 111                         if (ax25->sk != NULL) {
 112                                 if (ax25->sk->rmem_alloc < (ax25->sk->rcvbuf / 2) && (ax25->condition & OWN_RX_BUSY_CONDITION)) {
 113                                         ax25->condition &= ~OWN_RX_BUSY_CONDITION;
 114                                         if (!ax25->dama_slave) /* dl1bke */
 115                                         ax25_send_control(ax25, RR, POLLOFF, C_RESPONSE);
 116                                         ax25->condition &= ~ACK_PENDING_CONDITION;
 117                                         break;
 118                                 }
 119                         }
 120                         /*
 121                          * Check for frames to transmit.
 122                          */
 123                         if (!ax25->dama_slave)
 124                                 ax25_kick(ax25);        /* dl1bke 960114 */
 125                         break;
 126 
 127                 default:
 128                         break;
 129         }
 130 
 131         if (ax25->t2timer > 0 && --ax25->t2timer == 0) {
 132                 if (ax25->state == AX25_STATE_3 || ax25->state == AX25_STATE_4) {
 133                         if (ax25->condition & ACK_PENDING_CONDITION) {
 134                                 ax25->condition &= ~ACK_PENDING_CONDITION;
 135                                 if (!ax25->dama_slave)                  /* dl1bke 960114 */
 136                                 ax25_timeout_response(ax25);
 137                         }
 138                 }
 139         }
 140 
 141         if (ax25->t3timer > 0 && --ax25->t3timer == 0) 
 142         {
 143         
 144                 /* dl1bke 960114: T3 expires and we are in DAMA mode:  */
 145                 /*                send a DISC and abort the connection */
 146                  
 147                 if (ax25->dama_slave)
 148                 {
 149 #ifdef CONFIG_NETROM
 150                         nr_link_failed(&ax25->dest_addr, ax25->device);
 151 #endif
 152                         ax25_clear_queues(ax25);
 153                         ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
 154                                 
 155                         ax25->state = AX25_STATE_0;
 156                         if (ax25->sk != NULL)
 157                         {
 158                                 if (ax25->sk->debug)
 159                                         printk("T3 Timeout\n");
 160                                 ax25->sk->state = TCP_CLOSE;
 161                                 ax25->sk->err   = ETIMEDOUT;
 162                                 if (!ax25->sk->dead)
 163                                         ax25->sk->state_change(ax25->sk);
 164                                 ax25->sk->dead  = 1;
 165                         }
 166                         
 167                         return;
 168                 }
 169                 
 170                 if (ax25->state == AX25_STATE_3) {
 171                         ax25->n2count = 0;
 172                         ax25_transmit_enquiry(ax25);
 173                         ax25->state   = AX25_STATE_4;
 174                 }
 175                 ax25->t3timer = ax25->t3;
 176         }
 177 
 178         /* dl1bke 960114: DAMA T1 timeouts are handled in ax25_dama_slave_transmit */
 179         /*                nevertheless we have to re-enqueue the timer struct...   */
 180         
 181         if (ax25->t1timer == 0 || --ax25->t1timer > 0) {
 182         
 183                 ax25_reset_timer(ax25);
 184                 return;
 185         }
 186 
 187         if (!ax25_dev_is_dama_slave(ax25->device))
 188         {
 189                 if (ax25->dama_slave) ax25->dama_slave = 0;
 190                 ax25_t1_timeout(ax25);
 191         }
 192 }
 193 
 194 
 195 /* dl1bke 960114: The DAMA protocol requires to send data and SABM/DISC
 196  *                within the poll of any connected channel. Remember 
 197  *                that we are not allowed to send anything unless we
 198  *                get polled by the Master.
 199  *                
 200  *                Thus we'll have to do parts of our T1 handling in
 201  *                ax25_enquiry_response().
 202  */
 203 
 204 
 205 void ax25_t1_timeout(ax25_cb * ax25)
     /* [previous][next][first][last][top][bottom][index][help] */
 206 {       
 207         switch (ax25->state) {
 208                 case AX25_STATE_1: 
 209                         if (ax25->n2count == ax25->n2) {
 210                                 if (ax25->modulus == MODULUS) {
 211 #ifdef CONFIG_NETROM
 212                                         nr_link_failed(&ax25->dest_addr, ax25->device);
 213 #endif
 214                                         ax25_clear_queues(ax25);
 215                                         ax25->state = AX25_STATE_0;
 216                                         if (ax25->sk != NULL) {
 217                                                 ax25->sk->state = TCP_CLOSE;
 218                                                 ax25->sk->err   = ETIMEDOUT;
 219                                                 if (!ax25->sk->dead)
 220                                                         ax25->sk->state_change(ax25->sk);
 221                                                 ax25->sk->dead  = 1;
 222                                         }
 223                                 } else {
 224                                         ax25->modulus = MODULUS;
 225                                         ax25->window  = ax25_dev_get_value(ax25->device, AX25_VALUES_WINDOW);
 226                                         ax25->n2count = 0;
 227                                         ax25_send_control(ax25, SABM, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
 228                                 }
 229                         } else {
 230                                 ax25->n2count++;
 231                                 if (ax25->modulus == MODULUS) {
 232                                         ax25_send_control(ax25, SABM, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
 233                                 } else {
 234                                         ax25_send_control(ax25, SABME, ax25_dev_is_dama_slave(ax25->device)? POLLOFF : POLLON, C_COMMAND);
 235                                 }
 236                         }
 237                         break;
 238 
 239                 case AX25_STATE_2:
 240                         if (ax25->n2count == ax25->n2) {
 241 #ifdef CONFIG_NETROM
 242                                 nr_link_failed(&ax25->dest_addr, ax25->device);
 243 #endif
 244                                 ax25_clear_queues(ax25);
 245                                 ax25->state = AX25_STATE_0;
 246                                 ax25_send_control(ax25, DISC, POLLON, C_COMMAND); /* dl1bke */
 247                                 
 248                                 if (ax25->sk != NULL) {
 249                                         ax25->sk->state = TCP_CLOSE;
 250                                         ax25->sk->err   = ETIMEDOUT;
 251                                         if (!ax25->sk->dead)
 252                                                 ax25->sk->state_change(ax25->sk);
 253                                         ax25->sk->dead  = 1;
 254                                 }
 255                         } else {
 256                                 ax25->n2count++;
 257                                 if (!ax25_dev_is_dama_slave(ax25->device))      /* dl1bke */
 258                                 ax25_send_control(ax25, DISC, POLLON, C_COMMAND);
 259                         }
 260                         break;
 261 
 262                 case AX25_STATE_3: 
 263                         ax25->n2count = 1;
 264                         if (!ax25->dama_slave)                  /* dl1bke 960114 */
 265                         ax25_transmit_enquiry(ax25);
 266                         ax25->state   = AX25_STATE_4;
 267                         break;
 268 
 269                 case AX25_STATE_4:
 270                         if (ax25->n2count == ax25->n2) {
 271 #ifdef CONFIG_NETROM
 272                                 nr_link_failed(&ax25->dest_addr, ax25->device);
 273 #endif
 274                                 ax25_clear_queues(ax25);
 275                                 ax25_send_control(ax25, DM, POLLON, C_RESPONSE);
 276                                 ax25->state = AX25_STATE_0;
 277                                 if (ax25->sk != NULL) {
 278                                         if (ax25->sk->debug)
 279                                                 printk("Link Failure\n");
 280                                         ax25->sk->state = TCP_CLOSE;
 281                                         ax25->sk->err   = ETIMEDOUT;
 282                                         if (!ax25->sk->dead)
 283                                                 ax25->sk->state_change(ax25->sk);
 284                                         ax25->sk->dead  = 1;
 285                                 }
 286                         } else {
 287                                 ax25->n2count++;
 288                                 if (!ax25->dama_slave)          /* dl1bke 960114 */
 289                                 ax25_transmit_enquiry(ax25);
 290                         }
 291                         break;
 292         }
 293 
 294         ax25->t1timer = ax25->t1 = ax25_calculate_t1(ax25);
 295 
 296         ax25_set_timer(ax25);
 297 }
 298 
 299 #endif

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