blob: 96e816b6974d244794782a9db23f6bf4d115a882 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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);
Al Virodd0fc662005-10-07 07:46:04 +010022extern void dn_send_conn_conf(struct sock *sk, gfp_t gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023extern void dn_nsp_send_disc(struct sock *sk, unsigned char type,
Al Virodd0fc662005-10-07 07:46:04 +010024 unsigned short reason, gfp_t gfp);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025extern 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);
Al Virodd0fc662005-10-07 07:46:04 +010032extern void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb, gfp_t gfp, int oob);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033extern 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
Al Virodd0fc662005-10-07 07:46:04 +010039extern struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040extern 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{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080075 __u8 msgflg;
76 __le16 dstaddr;
77 __le16 srcaddr;
Jan Blunck6a878182006-01-08 01:05:07 -080078} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80struct nsp_data_opt_msg
81{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080082 __le16 acknum;
83 __le16 segnum;
84 __le16 lsflgs;
Jan Blunck6a878182006-01-08 01:05:07 -080085} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87struct nsp_data_opt_msg1
88{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080089 __le16 acknum;
90 __le16 segnum;
Jan Blunck6a878182006-01-08 01:05:07 -080091} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93
94/* Acknowledgment Message (data/other data) */
95struct nsp_data_ack_msg
96{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080097 __u8 msgflg;
98 __le16 dstaddr;
99 __le16 srcaddr;
100 __le16 acknum;
Jan Blunck6a878182006-01-08 01:05:07 -0800101} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103/* Connect Acknowledgment Message */
104struct nsp_conn_ack_msg
105{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800106 __u8 msgflg;
107 __le16 dstaddr;
Jan Blunck6a878182006-01-08 01:05:07 -0800108} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110
111/* Connect Initiate/Retransmit Initiate/Connect Confirm */
112struct nsp_conn_init_msg
113{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800114 __u8 msgflg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115#define NSP_CI 0x18 /* Connect Initiate */
116#define NSP_RCI 0x68 /* Retrans. Conn Init */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800117 __le16 dstaddr;
118 __le16 srcaddr;
119 __u8 services;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#define NSP_FC_NONE 0x00 /* Flow Control None */
121#define NSP_FC_SRC 0x04 /* Seg Req. Count */
122#define NSP_FC_SCMC 0x08 /* Sess. Control Mess */
123#define NSP_FC_MASK 0x0c /* FC type mask */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800124 __u8 info;
125 __le16 segsize;
Jan Blunck6a878182006-01-08 01:05:07 -0800126} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/* Disconnect Initiate/Disconnect Confirm */
129struct nsp_disconn_init_msg
130{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800131 __u8 msgflg;
132 __le16 dstaddr;
133 __le16 srcaddr;
134 __le16 reason;
Jan Blunck6a878182006-01-08 01:05:07 -0800135} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137
138
139struct srcobj_fmt
140{
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800141 __u8 format;
142 __u8 task;
143 __le16 grpcode;
144 __le16 usrcode;
145 __u8 dlen;
Jan Blunck6a878182006-01-08 01:05:07 -0800146} __attribute__((packed));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148/*
149 * A collection of functions for manipulating the sequence
150 * numbers used in NSP. Similar in operation to the functions
151 * of the same name in TCP.
152 */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800153static __inline__ int dn_before(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 seq1 &= 0x0fff;
156 seq2 &= 0x0fff;
157
158 return (int)((seq1 - seq2) & 0x0fff) > 2048;
159}
160
161
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800162static __inline__ int dn_after(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163{
164 seq1 &= 0x0fff;
165 seq2 &= 0x0fff;
166
167 return (int)((seq2 - seq1) & 0x0fff) > 2048;
168}
169
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800170static __inline__ int dn_equal(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
172 return ((seq1 ^ seq2) & 0x0fff) == 0;
173}
174
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800175static __inline__ int dn_before_or_equal(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176{
177 return (dn_before(seq1, seq2) || dn_equal(seq1, seq2));
178}
179
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800180static __inline__ void seq_add(__u16 *seq, __u16 off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 (*seq) += off;
183 (*seq) &= 0x0fff;
184}
185
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800186static __inline__ int seq_next(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 return dn_equal(seq1 + 1, seq2);
189}
190
191/*
192 * Can we delay the ack ?
193 */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800194static __inline__ int sendack(__u16 seq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
196 return (int)((seq & 0x1000) ? 0 : 1);
197}
198
199/*
200 * Is socket congested ?
201 */
202static __inline__ int dn_congested(struct sock *sk)
203{
204 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
205}
206
207#define DN_MAX_NSP_DATA_HEADER (11)
208
209#endif /* _NET_DN_NSP_H */