OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uClinux-2.0.x/] [net/] [netrom/] [nr_timer.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *      NET/ROM release 006
3
 *
4
 *      This code REQUIRES 1.2.1 or higher/ NET3.029
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
 *      History
13
 *      NET/ROM 001     Jonathan(G4KLX) Cloned from ax25_timer.c
14
 */
15
 
16
#include <linux/config.h>
17
#if defined(CONFIG_NETROM) || defined(CONFIG_NETROM_MODULE)
18
#include <linux/errno.h>
19
#include <linux/types.h>
20
#include <linux/socket.h>
21
#include <linux/in.h>
22
#include <linux/kernel.h>
23
#include <linux/sched.h>
24
#include <linux/timer.h>
25
#include <linux/string.h>
26
#include <linux/sockios.h>
27
#include <linux/net.h>
28
#include <net/ax25.h>
29
#include <linux/inet.h>
30
#include <linux/netdevice.h>
31
#include <linux/skbuff.h>
32
#include <net/sock.h>
33
#include <asm/segment.h>
34
#include <asm/system.h>
35
#include <linux/fcntl.h>
36
#include <linux/mm.h>
37
#include <linux/interrupt.h>
38
#include <net/netrom.h>
39
 
40
static void nr_timer(unsigned long);
41
 
42
/*
43
 *      Linux set timer
44
 */
45
void nr_set_timer(struct sock *sk)
46
{
47
        unsigned long flags;
48
 
49
        save_flags(flags); cli();
50
        del_timer(&sk->timer);
51
        restore_flags(flags);
52
 
53
        sk->timer.data     = (unsigned long)sk;
54
        sk->timer.function = &nr_timer;
55
        sk->timer.expires  = jiffies+10;
56
 
57
        add_timer(&sk->timer);
58
}
59
 
60
/*
61
 *      NET/ROM TIMER
62
 *
63
 *      This routine is called every 100ms. Decrement timer by this
64
 *      amount - if expired then process the event.
65
 */
66
static void nr_timer(unsigned long param)
67
{
68
        struct sock *sk = (struct sock *)param;
69
 
70
        switch (sk->protinfo.nr->state) {
71
                case NR_STATE_0:
72
                        /* Magic here: If we listen() and a new link dies before it
73
                           is accepted() it isn't 'dead' so doesn't get removed. */
74
                        if (sk->destroy || (sk->state == TCP_LISTEN && sk->dead)) {
75
                                del_timer(&sk->timer);
76
                                nr_destroy_socket(sk);
77
                                return;
78
                        }
79
                        break;
80
 
81
                case NR_STATE_3:
82
                        /*
83
                         * Check for the state of the receive buffer.
84
                         */
85
                        if (sk->rmem_alloc < (sk->rcvbuf / 2) && (sk->protinfo.nr->condition & NR_COND_OWN_RX_BUSY)) {
86
                                sk->protinfo.nr->condition &= ~NR_COND_OWN_RX_BUSY;
87
                                sk->protinfo.nr->condition &= ~NR_COND_ACK_PENDING;
88
                                sk->protinfo.nr->vl         = sk->protinfo.nr->vr;
89
                                nr_write_internal(sk, NR_INFOACK);
90
                                break;
91
                        }
92
                        /*
93
                         * Check for frames to transmit.
94
                         */
95
                        nr_kick(sk);
96
                        break;
97
 
98
                default:
99
                        break;
100
        }
101
 
102
        if (sk->protinfo.nr->t2timer > 0 && --sk->protinfo.nr->t2timer == 0) {
103
                if (sk->protinfo.nr->state == NR_STATE_3) {
104
                        if (sk->protinfo.nr->condition & NR_COND_ACK_PENDING) {
105
                                sk->protinfo.nr->condition &= ~NR_COND_ACK_PENDING;
106
                                nr_enquiry_response(sk);
107
                        }
108
                }
109
        }
110
 
111
        if (sk->protinfo.nr->t4timer > 0 && --sk->protinfo.nr->t4timer == 0) {
112
                sk->protinfo.nr->condition &= ~NR_COND_PEER_RX_BUSY;
113
        }
114
 
115
        if (sk->protinfo.nr->t1timer == 0 || --sk->protinfo.nr->t1timer > 0) {
116
                nr_set_timer(sk);
117
                return;
118
        }
119
 
120
        switch (sk->protinfo.nr->state) {
121
                case NR_STATE_1:
122
                        if (sk->protinfo.nr->n2count == sk->protinfo.nr->n2) {
123
                                nr_clear_queues(sk);
124
                                sk->protinfo.nr->state = NR_STATE_0;
125
                                sk->state              = TCP_CLOSE;
126
                                sk->err                = ETIMEDOUT;
127
                                sk->shutdown          |= SEND_SHUTDOWN;
128
                                if (!sk->dead)
129
                                        sk->state_change(sk);
130
                                sk->dead               = 1;
131
                        } else {
132
                                sk->protinfo.nr->n2count++;
133
                                nr_write_internal(sk, NR_CONNREQ);
134
                        }
135
                        break;
136
 
137
                case NR_STATE_2:
138
                        if (sk->protinfo.nr->n2count == sk->protinfo.nr->n2) {
139
                                nr_clear_queues(sk);
140
                                sk->protinfo.nr->state = NR_STATE_0;
141
                                sk->state              = TCP_CLOSE;
142
                                sk->err                = ETIMEDOUT;
143
                                sk->shutdown          |= SEND_SHUTDOWN;
144
                                if (!sk->dead)
145
                                        sk->state_change(sk);
146
                                sk->dead               = 1;
147
                        } else {
148
                                sk->protinfo.nr->n2count++;
149
                                nr_write_internal(sk, NR_DISCREQ);
150
                        }
151
                        break;
152
 
153
                case NR_STATE_3:
154
                        if (sk->protinfo.nr->n2count == sk->protinfo.nr->n2) {
155
                                nr_clear_queues(sk);
156
                                sk->protinfo.nr->state = NR_STATE_0;
157
                                sk->state              = TCP_CLOSE;
158
                                sk->err                = ETIMEDOUT;
159
                                sk->shutdown          |= SEND_SHUTDOWN;
160
                                if (!sk->dead)
161
                                        sk->state_change(sk);
162
                                sk->dead               = 1;
163
                        } else {
164
                                sk->protinfo.nr->n2count++;
165
                                nr_requeue_frames(sk);
166
                        }
167
                        break;
168
        }
169
 
170
        sk->protinfo.nr->t1timer = sk->protinfo.nr->t1;
171
 
172
        nr_set_timer(sk);
173
}
174
 
175
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.