blob: f83932b864a93f9fb21b6c03e50f7c0964818de5 [file] [log] [blame]
Thomas Gleixnerfd9871f2019-05-19 15:51:54 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _NET_DN_NSP_H
3#define _NET_DN_NSP_H
4/******************************************************************************
5 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007*******************************************************************************/
8/* dn_nsp.c functions prototyping */
9
Joe Perches59ddd962013-09-20 11:23:20 -070010void dn_nsp_send_data_ack(struct sock *sk);
11void dn_nsp_send_oth_ack(struct sock *sk);
Joe Perches59ddd962013-09-20 11:23:20 -070012void dn_send_conn_ack(struct sock *sk);
13void dn_send_conn_conf(struct sock *sk, gfp_t gfp);
14void dn_nsp_send_disc(struct sock *sk, unsigned char type,
15 unsigned short reason, gfp_t gfp);
16void dn_nsp_return_disc(struct sk_buff *skb, unsigned char type,
17 unsigned short reason);
18void dn_nsp_send_link(struct sock *sk, unsigned char lsflags, char fcval);
19void dn_nsp_send_conninit(struct sock *sk, unsigned char flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Joe Perches59ddd962013-09-20 11:23:20 -070021void dn_nsp_output(struct sock *sk);
22int dn_nsp_check_xmit_queue(struct sock *sk, struct sk_buff *skb,
23 struct sk_buff_head *q, unsigned short acknum);
24void dn_nsp_queue_xmit(struct sock *sk, struct sk_buff *skb, gfp_t gfp,
25 int oob);
26unsigned long dn_nsp_persist(struct sock *sk);
27int dn_nsp_xmit_timeout(struct sock *sk);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perches59ddd962013-09-20 11:23:20 -070029int dn_nsp_rx(struct sk_buff *);
30int dn_nsp_backlog_rcv(struct sock *sk, struct sk_buff *skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Joe Perches59ddd962013-09-20 11:23:20 -070032struct sk_buff *dn_alloc_skb(struct sock *sk, int size, gfp_t pri);
33struct sk_buff *dn_alloc_send_skb(struct sock *sk, size_t *size, int noblock,
34 long timeo, int *err);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36#define NSP_REASON_OK 0 /* No error */
37#define NSP_REASON_NR 1 /* No resources */
38#define NSP_REASON_UN 2 /* Unrecognised node name */
39#define NSP_REASON_SD 3 /* Node shutting down */
40#define NSP_REASON_ID 4 /* Invalid destination end user */
41#define NSP_REASON_ER 5 /* End user lacks resources */
42#define NSP_REASON_OB 6 /* Object too busy */
43#define NSP_REASON_US 7 /* Unspecified error */
44#define NSP_REASON_TP 8 /* Third-Party abort */
45#define NSP_REASON_EA 9 /* End user has aborted the link */
46#define NSP_REASON_IF 10 /* Invalid node name format */
47#define NSP_REASON_LS 11 /* Local node shutdown */
48#define NSP_REASON_LL 32 /* Node lacks logical-link resources */
49#define NSP_REASON_LE 33 /* End user lacks logical-link resources */
50#define NSP_REASON_UR 34 /* Unacceptable RQSTRID or PASSWORD field */
51#define NSP_REASON_UA 36 /* Unacceptable ACCOUNT field */
52#define NSP_REASON_TM 38 /* End user timed out logical link */
53#define NSP_REASON_NU 39 /* Node unreachable */
54#define NSP_REASON_NL 41 /* No-link message */
55#define NSP_REASON_DC 42 /* Disconnect confirm */
56#define NSP_REASON_IO 43 /* Image data field overflow */
57
58#define NSP_DISCINIT 0x38
59#define NSP_DISCCONF 0x48
60
61/*------------------------- NSP - messages ------------------------------*/
62/* Data Messages */
63/*---------------*/
64
65/* Data Messages (data segment/interrupt/link service) */
66
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000067struct nsp_data_seg_msg {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080068 __u8 msgflg;
69 __le16 dstaddr;
70 __le16 srcaddr;
Eric Dumazetbc105022010-06-03 03:21:52 -070071} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000073struct nsp_data_opt_msg {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080074 __le16 acknum;
75 __le16 segnum;
76 __le16 lsflgs;
Eric Dumazetbc105022010-06-03 03:21:52 -070077} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000079struct nsp_data_opt_msg1 {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080080 __le16 acknum;
81 __le16 segnum;
Eric Dumazetbc105022010-06-03 03:21:52 -070082} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84
85/* Acknowledgment Message (data/other data) */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000086struct nsp_data_ack_msg {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080087 __u8 msgflg;
88 __le16 dstaddr;
89 __le16 srcaddr;
90 __le16 acknum;
Eric Dumazetbc105022010-06-03 03:21:52 -070091} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/* Connect Acknowledgment Message */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000094struct nsp_conn_ack_msg {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -080095 __u8 msgflg;
96 __le16 dstaddr;
Eric Dumazetbc105022010-06-03 03:21:52 -070097} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99
100/* Connect Initiate/Retransmit Initiate/Connect Confirm */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000101struct nsp_conn_init_msg {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800102 __u8 msgflg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#define NSP_CI 0x18 /* Connect Initiate */
104#define NSP_RCI 0x68 /* Retrans. Conn Init */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800105 __le16 dstaddr;
106 __le16 srcaddr;
107 __u8 services;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108#define NSP_FC_NONE 0x00 /* Flow Control None */
109#define NSP_FC_SRC 0x04 /* Seg Req. Count */
110#define NSP_FC_SCMC 0x08 /* Sess. Control Mess */
111#define NSP_FC_MASK 0x0c /* FC type mask */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800112 __u8 info;
113 __le16 segsize;
Eric Dumazetbc105022010-06-03 03:21:52 -0700114} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116/* Disconnect Initiate/Disconnect Confirm */
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000117struct nsp_disconn_init_msg {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800118 __u8 msgflg;
119 __le16 dstaddr;
120 __le16 srcaddr;
121 __le16 reason;
Eric Dumazetbc105022010-06-03 03:21:52 -0700122} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124
125
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +0000126struct srcobj_fmt {
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800127 __u8 format;
128 __u8 task;
129 __le16 grpcode;
130 __le16 usrcode;
131 __u8 dlen;
Eric Dumazetbc105022010-06-03 03:21:52 -0700132} __packed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134/*
135 * A collection of functions for manipulating the sequence
136 * numbers used in NSP. Similar in operation to the functions
137 * of the same name in TCP.
138 */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800139static __inline__ int dn_before(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 seq1 &= 0x0fff;
142 seq2 &= 0x0fff;
143
144 return (int)((seq1 - seq2) & 0x0fff) > 2048;
145}
146
147
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800148static __inline__ int dn_after(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
150 seq1 &= 0x0fff;
151 seq2 &= 0x0fff;
152
153 return (int)((seq2 - seq1) & 0x0fff) > 2048;
154}
155
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800156static __inline__ int dn_equal(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157{
158 return ((seq1 ^ seq2) & 0x0fff) == 0;
159}
160
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800161static __inline__ int dn_before_or_equal(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
163 return (dn_before(seq1, seq2) || dn_equal(seq1, seq2));
164}
165
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800166static __inline__ void seq_add(__u16 *seq, __u16 off)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
168 (*seq) += off;
169 (*seq) &= 0x0fff;
170}
171
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800172static __inline__ int seq_next(__u16 seq1, __u16 seq2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
174 return dn_equal(seq1 + 1, seq2);
175}
176
177/*
178 * Can we delay the ack ?
179 */
Steven Whitehousec4ea94a2006-03-20 22:42:39 -0800180static __inline__ int sendack(__u16 seq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
182 return (int)((seq & 0x1000) ? 0 : 1);
183}
184
185/*
186 * Is socket congested ?
187 */
188static __inline__ int dn_congested(struct sock *sk)
189{
190 return atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf >> 1);
191}
192
193#define DN_MAX_NSP_DATA_HEADER (11)
194
195#endif /* _NET_DN_NSP_H */