Loading...
1#ifndef _NET_DN_NSP_H
2#define _NET_DN_NSP_H
3/******************************************************************************
4 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15*******************************************************************************/
16/* dn_nsp.c functions prototyping */
17
18void dn_nsp_send_data_ack(struct sock *sk);
19void dn_nsp_send_oth_ack(struct sock *sk);
20void dn_send_conn_ack(struct sock *sk);
21void dn_send_conn_conf(struct sock *sk, gfp_t gfp);
22void dn_nsp_send_disc(struct sock *sk, unsigned char type,
23 unsigned short reason, gfp_t gfp);
24void dn_nsp_return_disc(struct sk_buff *skb, unsigned char type,
25 unsigned short reason);
26void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval);
27void dn_nsp_send_conninit(struct sock *sk, unsigned char flags);
28
29void dn_nsp_output(struct sock *sk);
30int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb,
31 struct sk_buff_head *q, unsigned short acknum);
32void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb, gfp_t gfp,
33 int oob);
34unsigned long dn_nsp_persist(struct sock *sk);
35int dn_nsp_xmit_timeout(struct sock *sk);
36
37int dn_nsp_rx(struct sk_buff *);
38int dn_nsp_backlog_rcv(struct sock *sk, struct sk_buff *skb);
39
40struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri);
41struct sk_buff *dn_alloc_send_skb(struct sock *sk, size_t *size, int noblock,
42 long timeo, int *err);
43
44#define NSP_REASON_OK 0 /* No error */
45#define NSP_REASON_NR 1 /* No resources */
46#define NSP_REASON_UN 2 /* Unrecognised node name */
47#define NSP_REASON_SD 3 /* Node shutting down */
48#define NSP_REASON_ID 4 /* Invalid destination end user */
49#define NSP_REASON_ER 5 /* End user lacks resources */
50#define NSP_REASON_OB 6 /* Object too busy */
51#define NSP_REASON_US 7 /* Unspecified error */
52#define NSP_REASON_TP 8 /* Third-Party abort */
53#define NSP_REASON_EA 9 /* End user has aborted the link */
54#define NSP_REASON_IF 10 /* Invalid node name format */
55#define NSP_REASON_LS 11 /* Local node shutdown */
56#define NSP_REASON_LL 32 /* Node lacks logical-link resources */
57#define NSP_REASON_LE 33 /* End user lacks logical-link resources */
58#define NSP_REASON_UR 34 /* Unacceptable RQSTRID or PASSWORD field */
59#define NSP_REASON_UA 36 /* Unacceptable ACCOUNT field */
60#define NSP_REASON_TM 38 /* End user timed out logical link */
61#define NSP_REASON_NU 39 /* Node unreachable */
62#define NSP_REASON_NL 41 /* No-link message */
63#define NSP_REASON_DC 42 /* Disconnect confirm */
64#define NSP_REASON_IO 43 /* Image data field overflow */
65
66#define NSP_DISCINIT 0x38
67#define NSP_DISCCONF 0x48
68
69/*------------------------- NSP - messages ------------------------------*/
70/* Data Messages */
71/*---------------*/
72
73/* Data Messages (data segment/interrupt/link service) */
74
75struct nsp_data_seg_msg {
76 __u8 msgflg;
77 __le16 dstaddr;
78 __le16 srcaddr;
79} __packed;
80
81struct nsp_data_opt_msg {
82 __le16 acknum;
83 __le16 segnum;
84 __le16 lsflgs;
85} __packed;
86
87struct nsp_data_opt_msg1 {
88 __le16 acknum;
89 __le16 segnum;
90} __packed;
91
92
93/* Acknowledgment Message (data/other data) */
94struct nsp_data_ack_msg {
95 __u8 msgflg;
96 __le16 dstaddr;
97 __le16 srcaddr;
98 __le16 acknum;
99} __packed;
100
101/* Connect Acknowledgment Message */
102struct nsp_conn_ack_msg {
103 __u8 msgflg;
104 __le16 dstaddr;
105} __packed;
106
107
108/* Connect Initiate/Retransmit Initiate/Connect Confirm */
109struct nsp_conn_init_msg {
110 __u8 msgflg;
111#define NSP_CI 0x18 /* Connect Initiate */
112#define NSP_RCI 0x68 /* Retrans. Conn Init */
113 __le16 dstaddr;
114 __le16 srcaddr;
115 __u8 services;
116#define NSP_FC_NONE 0x00 /* Flow Control None */
117#define NSP_FC_SRC 0x04 /* Seg Req. Count */
118#define NSP_FC_SCMC 0x08 /* Sess. Control Mess */
119#define NSP_FC_MASK 0x0c /* FC type mask */
120 __u8 info;
121 __le16 segsize;
122} __packed;
123
124/* Disconnect Initiate/Disconnect Confirm */
125struct nsp_disconn_init_msg {
126 __u8 msgflg;
127 __le16 dstaddr;
128 __le16 srcaddr;
129 __le16 reason;
130} __packed;
131
132
133
134struct srcobj_fmt {
135 __u8 format;
136 __u8 task;
137 __le16 grpcode;
138 __le16 usrcode;
139 __u8 dlen;
140} __packed;
141
142/*
143 * A collection of functions for manipulating the sequence
144 * numbers used in NSP. Similar in operation to the functions
145 * of the same name in TCP.
146 */
147static __inline__ int dn_before(__u16 seq1, __u16 seq2)
148{
149 seq1 &= 0x0fff;
150 seq2 &= 0x0fff;
151
152 return (int)((seq1 - seq2) & 0x0fff) > 2048;
153}
154
155
156static __inline__ int dn_after(__u16 seq1, __u16 seq2)
157{
158 seq1 &= 0x0fff;
159 seq2 &= 0x0fff;
160
161 return (int)((seq2 - seq1) & 0x0fff) > 2048;
162}
163
164static __inline__ int dn_equal(__u16 seq1, __u16 seq2)
165{
166 return ((seq1 ^ seq2) & 0x0fff) == 0;
167}
168
169static __inline__ int dn_before_or_equal(__u16 seq1, __u16 seq2)
170{
171 return (dn_before(seq1, seq2) || dn_equal(seq1, seq2));
172}
173
174static __inline__ void seq_add(__u16 *seq, __u16 off)
175{
176 (*seq) += off;
177 (*seq) &= 0x0fff;
178}
179
180static __inline__ int seq_next(__u16 seq1, __u16 seq2)
181{
182 return dn_equal(seq1 + 1, seq2);
183}
184
185/*
186 * Can we delay the ack ?
187 */
188static __inline__ int sendack(__u16 seq)
189{
190 return (int)((seq & 0x1000) ? 0 : 1);
191}
192
193/*
194 * Is socket congested ?
195 */
196static __inline__ int dn_congested(struct sock *sk)
197{
198 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
199}
200
201#define DN_MAX_NSP_DATA_HEADER (11)
202
203#endif /* _NET_DN_NSP_H */
1#ifndef _NET_DN_NSP_H
2#define _NET_DN_NSP_H
3/******************************************************************************
4 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15*******************************************************************************/
16/* dn_nsp.c functions prototyping */
17
18extern void dn_nsp_send_data_ack(struct sock *sk);
19extern void dn_nsp_send_oth_ack(struct sock *sk);
20extern void dn_nsp_delayed_ack(struct sock *sk);
21extern void dn_send_conn_ack(struct sock *sk);
22extern void dn_send_conn_conf(struct sock *sk, gfp_t gfp);
23extern void dn_nsp_send_disc(struct sock *sk, unsigned char type,
24 unsigned short reason, gfp_t gfp);
25extern void dn_nsp_return_disc(struct sk_buff *skb, unsigned char type,
26 unsigned short reason);
27extern void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval);
28extern void dn_nsp_send_conninit(struct sock *sk, unsigned char flags);
29
30extern void dn_nsp_output(struct sock *sk);
31extern int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb, struct sk_buff_head *q, unsigned short acknum);
32extern void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb, gfp_t gfp, int oob);
33extern unsigned long dn_nsp_persist(struct sock *sk);
34extern int dn_nsp_xmit_timeout(struct sock *sk);
35
36extern int dn_nsp_rx(struct sk_buff *);
37extern int dn_nsp_backlog_rcv(struct sock *sk, struct sk_buff *skb);
38
39extern struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri);
40extern struct sk_buff *dn_alloc_send_skb(struct sock *sk, size_t *size, int noblock, long timeo, int *err);
41
42#define NSP_REASON_OK 0 /* No error */
43#define NSP_REASON_NR 1 /* No resources */
44#define NSP_REASON_UN 2 /* Unrecognised node name */
45#define NSP_REASON_SD 3 /* Node shutting down */
46#define NSP_REASON_ID 4 /* Invalid destination end user */
47#define NSP_REASON_ER 5 /* End user lacks resources */
48#define NSP_REASON_OB 6 /* Object too busy */
49#define NSP_REASON_US 7 /* Unspecified error */
50#define NSP_REASON_TP 8 /* Third-Party abort */
51#define NSP_REASON_EA 9 /* End user has aborted the link */
52#define NSP_REASON_IF 10 /* Invalid node name format */
53#define NSP_REASON_LS 11 /* Local node shutdown */
54#define NSP_REASON_LL 32 /* Node lacks logical-link resources */
55#define NSP_REASON_LE 33 /* End user lacks logical-link resources */
56#define NSP_REASON_UR 34 /* Unacceptable RQSTRID or PASSWORD field */
57#define NSP_REASON_UA 36 /* Unacceptable ACCOUNT field */
58#define NSP_REASON_TM 38 /* End user timed out logical link */
59#define NSP_REASON_NU 39 /* Node unreachable */
60#define NSP_REASON_NL 41 /* No-link message */
61#define NSP_REASON_DC 42 /* Disconnect confirm */
62#define NSP_REASON_IO 43 /* Image data field overflow */
63
64#define NSP_DISCINIT 0x38
65#define NSP_DISCCONF 0x48
66
67/*------------------------- NSP - messages ------------------------------*/
68/* Data Messages */
69/*---------------*/
70
71/* Data Messages (data segment/interrupt/link service) */
72
73struct nsp_data_seg_msg {
74 __u8 msgflg;
75 __le16 dstaddr;
76 __le16 srcaddr;
77} __packed;
78
79struct nsp_data_opt_msg {
80 __le16 acknum;
81 __le16 segnum;
82 __le16 lsflgs;
83} __packed;
84
85struct nsp_data_opt_msg1 {
86 __le16 acknum;
87 __le16 segnum;
88} __packed;
89
90
91/* Acknowledgment Message (data/other data) */
92struct nsp_data_ack_msg {
93 __u8 msgflg;
94 __le16 dstaddr;
95 __le16 srcaddr;
96 __le16 acknum;
97} __packed;
98
99/* Connect Acknowledgment Message */
100struct nsp_conn_ack_msg {
101 __u8 msgflg;
102 __le16 dstaddr;
103} __packed;
104
105
106/* Connect Initiate/Retransmit Initiate/Connect Confirm */
107struct nsp_conn_init_msg {
108 __u8 msgflg;
109#define NSP_CI 0x18 /* Connect Initiate */
110#define NSP_RCI 0x68 /* Retrans. Conn Init */
111 __le16 dstaddr;
112 __le16 srcaddr;
113 __u8 services;
114#define NSP_FC_NONE 0x00 /* Flow Control None */
115#define NSP_FC_SRC 0x04 /* Seg Req. Count */
116#define NSP_FC_SCMC 0x08 /* Sess. Control Mess */
117#define NSP_FC_MASK 0x0c /* FC type mask */
118 __u8 info;
119 __le16 segsize;
120} __packed;
121
122/* Disconnect Initiate/Disconnect Confirm */
123struct nsp_disconn_init_msg {
124 __u8 msgflg;
125 __le16 dstaddr;
126 __le16 srcaddr;
127 __le16 reason;
128} __packed;
129
130
131
132struct srcobj_fmt {
133 __u8 format;
134 __u8 task;
135 __le16 grpcode;
136 __le16 usrcode;
137 __u8 dlen;
138} __packed;
139
140/*
141 * A collection of functions for manipulating the sequence
142 * numbers used in NSP. Similar in operation to the functions
143 * of the same name in TCP.
144 */
145static __inline__ int dn_before(__u16 seq1, __u16 seq2)
146{
147 seq1 &= 0x0fff;
148 seq2 &= 0x0fff;
149
150 return (int)((seq1 - seq2) & 0x0fff) > 2048;
151}
152
153
154static __inline__ int dn_after(__u16 seq1, __u16 seq2)
155{
156 seq1 &= 0x0fff;
157 seq2 &= 0x0fff;
158
159 return (int)((seq2 - seq1) & 0x0fff) > 2048;
160}
161
162static __inline__ int dn_equal(__u16 seq1, __u16 seq2)
163{
164 return ((seq1 ^ seq2) & 0x0fff) == 0;
165}
166
167static __inline__ int dn_before_or_equal(__u16 seq1, __u16 seq2)
168{
169 return (dn_before(seq1, seq2) || dn_equal(seq1, seq2));
170}
171
172static __inline__ void seq_add(__u16 *seq, __u16 off)
173{
174 (*seq) += off;
175 (*seq) &= 0x0fff;
176}
177
178static __inline__ int seq_next(__u16 seq1, __u16 seq2)
179{
180 return dn_equal(seq1 + 1, seq2);
181}
182
183/*
184 * Can we delay the ack ?
185 */
186static __inline__ int sendack(__u16 seq)
187{
188 return (int)((seq & 0x1000) ? 0 : 1);
189}
190
191/*
192 * Is socket congested ?
193 */
194static __inline__ int dn_congested(struct sock *sk)
195{
196 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
197}
198
199#define DN_MAX_NSP_DATA_HEADER (11)
200
201#endif /* _NET_DN_NSP_H */