0001
0002
0003
0004
0005
0006
0007 #include <linux/errno.h>
0008 #include <linux/types.h>
0009 #include <linux/socket.h>
0010 #include <linux/in.h>
0011 #include <linux/kernel.h>
0012 #include <linux/jiffies.h>
0013 #include <linux/timer.h>
0014 #include <linux/string.h>
0015 #include <linux/sockios.h>
0016 #include <linux/net.h>
0017 #include <net/ax25.h>
0018 #include <linux/inet.h>
0019 #include <linux/netdevice.h>
0020 #include <linux/skbuff.h>
0021 #include <net/sock.h>
0022 #include <net/tcp_states.h>
0023 #include <linux/fcntl.h>
0024 #include <linux/mm.h>
0025 #include <linux/interrupt.h>
0026 #include <net/rose.h>
0027
0028 static void rose_heartbeat_expiry(struct timer_list *t);
0029 static void rose_timer_expiry(struct timer_list *);
0030 static void rose_idletimer_expiry(struct timer_list *);
0031
0032 void rose_start_heartbeat(struct sock *sk)
0033 {
0034 sk_stop_timer(sk, &sk->sk_timer);
0035
0036 sk->sk_timer.function = rose_heartbeat_expiry;
0037 sk->sk_timer.expires = jiffies + 5 * HZ;
0038
0039 sk_reset_timer(sk, &sk->sk_timer, sk->sk_timer.expires);
0040 }
0041
0042 void rose_start_t1timer(struct sock *sk)
0043 {
0044 struct rose_sock *rose = rose_sk(sk);
0045
0046 sk_stop_timer(sk, &rose->timer);
0047
0048 rose->timer.function = rose_timer_expiry;
0049 rose->timer.expires = jiffies + rose->t1;
0050
0051 sk_reset_timer(sk, &rose->timer, rose->timer.expires);
0052 }
0053
0054 void rose_start_t2timer(struct sock *sk)
0055 {
0056 struct rose_sock *rose = rose_sk(sk);
0057
0058 sk_stop_timer(sk, &rose->timer);
0059
0060 rose->timer.function = rose_timer_expiry;
0061 rose->timer.expires = jiffies + rose->t2;
0062
0063 sk_reset_timer(sk, &rose->timer, rose->timer.expires);
0064 }
0065
0066 void rose_start_t3timer(struct sock *sk)
0067 {
0068 struct rose_sock *rose = rose_sk(sk);
0069
0070 sk_stop_timer(sk, &rose->timer);
0071
0072 rose->timer.function = rose_timer_expiry;
0073 rose->timer.expires = jiffies + rose->t3;
0074
0075 sk_reset_timer(sk, &rose->timer, rose->timer.expires);
0076 }
0077
0078 void rose_start_hbtimer(struct sock *sk)
0079 {
0080 struct rose_sock *rose = rose_sk(sk);
0081
0082 sk_stop_timer(sk, &rose->timer);
0083
0084 rose->timer.function = rose_timer_expiry;
0085 rose->timer.expires = jiffies + rose->hb;
0086
0087 sk_reset_timer(sk, &rose->timer, rose->timer.expires);
0088 }
0089
0090 void rose_start_idletimer(struct sock *sk)
0091 {
0092 struct rose_sock *rose = rose_sk(sk);
0093
0094 sk_stop_timer(sk, &rose->idletimer);
0095
0096 if (rose->idle > 0) {
0097 rose->idletimer.function = rose_idletimer_expiry;
0098 rose->idletimer.expires = jiffies + rose->idle;
0099
0100 sk_reset_timer(sk, &rose->idletimer, rose->idletimer.expires);
0101 }
0102 }
0103
0104 void rose_stop_heartbeat(struct sock *sk)
0105 {
0106 sk_stop_timer(sk, &sk->sk_timer);
0107 }
0108
0109 void rose_stop_timer(struct sock *sk)
0110 {
0111 sk_stop_timer(sk, &rose_sk(sk)->timer);
0112 }
0113
0114 void rose_stop_idletimer(struct sock *sk)
0115 {
0116 sk_stop_timer(sk, &rose_sk(sk)->idletimer);
0117 }
0118
0119 static void rose_heartbeat_expiry(struct timer_list *t)
0120 {
0121 struct sock *sk = from_timer(sk, t, sk_timer);
0122 struct rose_sock *rose = rose_sk(sk);
0123
0124 bh_lock_sock(sk);
0125 switch (rose->state) {
0126 case ROSE_STATE_0:
0127
0128
0129 if (sock_flag(sk, SOCK_DESTROY) ||
0130 (sk->sk_state == TCP_LISTEN && sock_flag(sk, SOCK_DEAD))) {
0131 bh_unlock_sock(sk);
0132 rose_destroy_socket(sk);
0133 sock_put(sk);
0134 return;
0135 }
0136 break;
0137
0138 case ROSE_STATE_3:
0139
0140
0141
0142 if (atomic_read(&sk->sk_rmem_alloc) < (sk->sk_rcvbuf / 2) &&
0143 (rose->condition & ROSE_COND_OWN_RX_BUSY)) {
0144 rose->condition &= ~ROSE_COND_OWN_RX_BUSY;
0145 rose->condition &= ~ROSE_COND_ACK_PENDING;
0146 rose->vl = rose->vr;
0147 rose_write_internal(sk, ROSE_RR);
0148 rose_stop_timer(sk);
0149 break;
0150 }
0151 break;
0152 }
0153
0154 rose_start_heartbeat(sk);
0155 bh_unlock_sock(sk);
0156 sock_put(sk);
0157 }
0158
0159 static void rose_timer_expiry(struct timer_list *t)
0160 {
0161 struct rose_sock *rose = from_timer(rose, t, timer);
0162 struct sock *sk = &rose->sock;
0163
0164 bh_lock_sock(sk);
0165 switch (rose->state) {
0166 case ROSE_STATE_1:
0167 case ROSE_STATE_4:
0168 rose_write_internal(sk, ROSE_CLEAR_REQUEST);
0169 rose->state = ROSE_STATE_2;
0170 rose_start_t3timer(sk);
0171 break;
0172
0173 case ROSE_STATE_2:
0174 rose->neighbour->use--;
0175 rose_disconnect(sk, ETIMEDOUT, -1, -1);
0176 break;
0177
0178 case ROSE_STATE_3:
0179 if (rose->condition & ROSE_COND_ACK_PENDING) {
0180 rose->condition &= ~ROSE_COND_ACK_PENDING;
0181 rose_enquiry_response(sk);
0182 }
0183 break;
0184 }
0185 bh_unlock_sock(sk);
0186 sock_put(sk);
0187 }
0188
0189 static void rose_idletimer_expiry(struct timer_list *t)
0190 {
0191 struct rose_sock *rose = from_timer(rose, t, idletimer);
0192 struct sock *sk = &rose->sock;
0193
0194 bh_lock_sock(sk);
0195 rose_clear_queues(sk);
0196
0197 rose_write_internal(sk, ROSE_CLEAR_REQUEST);
0198 rose_sk(sk)->state = ROSE_STATE_2;
0199
0200 rose_start_t3timer(sk);
0201
0202 sk->sk_state = TCP_CLOSE;
0203 sk->sk_err = 0;
0204 sk->sk_shutdown |= SEND_SHUTDOWN;
0205
0206 if (!sock_flag(sk, SOCK_DEAD)) {
0207 sk->sk_state_change(sk);
0208 sock_set_flag(sk, SOCK_DEAD);
0209 }
0210 bh_unlock_sock(sk);
0211 sock_put(sk);
0212 }