import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / net / ax25 / ax25_std_subr.c
1 /*
2  *      AX.25 release 037
3  *
4  *      This code REQUIRES 2.1.15 or higher/ NET3.038
5  *
6  *      This module:
7  *              This module is free software; you can redistribute it and/or
8  *              modify it under the terms of the GNU General Public License
9  *              as published by the Free Software Foundation; either version
10  *              2 of the License, or (at your option) any later version.
11  *
12  *      Most of this code is based on the SDL diagrams published in the 7th
13  *      ARRL Computer Networking Conference papers. The diagrams have mistakes
14  *      in them, but are mostly correct. Before you modify the code could you
15  *      read the SDL diagrams as the code is not obvious and probably very
16  *      easy to break;
17  *
18  *      History
19  *      AX.25 036       Jonathan(G4KLX) Split from ax25_out.c.
20  *      AX.25 037       Jonathan(G4KLX) New timer architecture.
21  */
22
23 #include <linux/errno.h>
24 #include <linux/types.h>
25 #include <linux/socket.h>
26 #include <linux/in.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/timer.h>
30 #include <linux/string.h>
31 #include <linux/sockios.h>
32 #include <linux/net.h>
33 #include <net/ax25.h>
34 #include <linux/inet.h>
35 #include <linux/netdevice.h>
36 #include <linux/skbuff.h>
37 #include <net/sock.h>
38 #include <asm/uaccess.h>
39 #include <asm/system.h>
40 #include <linux/fcntl.h>
41 #include <linux/mm.h>
42 #include <linux/interrupt.h>
43
44 /*
45  * The following routines are taken from page 170 of the 7th ARRL Computer
46  * Networking Conference paper, as is the whole state machine.
47  */
48
49 void ax25_std_nr_error_recovery(ax25_cb *ax25)
50 {
51         ax25_std_establish_data_link(ax25);
52 }
53
54 void ax25_std_establish_data_link(ax25_cb *ax25)
55 {
56         ax25->condition = 0x00;
57         ax25->n2count   = 0;
58
59         if (ax25->modulus == AX25_MODULUS)
60                 ax25_send_control(ax25, AX25_SABM, AX25_POLLON, AX25_COMMAND);
61         else
62                 ax25_send_control(ax25, AX25_SABME, AX25_POLLON, AX25_COMMAND);
63
64         ax25_calculate_t1(ax25);
65         ax25_stop_idletimer(ax25);
66         ax25_stop_t3timer(ax25);
67         ax25_stop_t2timer(ax25);
68         ax25_start_t1timer(ax25);
69 }
70
71 void ax25_std_transmit_enquiry(ax25_cb *ax25)
72 {
73         if (ax25->condition & AX25_COND_OWN_RX_BUSY)
74                 ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_COMMAND);
75         else
76                 ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_COMMAND);
77
78         ax25->condition &= ~AX25_COND_ACK_PENDING;
79
80         ax25_calculate_t1(ax25);
81         ax25_start_t1timer(ax25);
82 }
83         
84 void ax25_std_enquiry_response(ax25_cb *ax25)
85 {
86         if (ax25->condition & AX25_COND_OWN_RX_BUSY)
87                 ax25_send_control(ax25, AX25_RNR, AX25_POLLON, AX25_RESPONSE);
88         else
89                 ax25_send_control(ax25, AX25_RR, AX25_POLLON, AX25_RESPONSE);
90
91         ax25->condition &= ~AX25_COND_ACK_PENDING;
92 }
93
94 void ax25_std_timeout_response(ax25_cb *ax25)
95 {
96         if (ax25->condition & AX25_COND_OWN_RX_BUSY)
97                 ax25_send_control(ax25, AX25_RNR, AX25_POLLOFF, AX25_RESPONSE);
98         else
99                 ax25_send_control(ax25, AX25_RR, AX25_POLLOFF, AX25_RESPONSE);
100
101         ax25->condition &= ~AX25_COND_ACK_PENDING;
102 }