3 /******************************************************************************
4 (c) 1995-1998 E.M. Serrat emserrat@geocities.com
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
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 */
18 extern void dn_nsp_send_data_ack(struct sock
*sk
);
19 extern void dn_nsp_send_oth_ack(struct sock
*sk
);
20 extern void dn_nsp_delayed_ack(struct sock
*sk
);
21 extern void dn_send_conn_ack(struct sock
*sk
);
22 extern void dn_send_conn_conf(struct sock
*sk
);
23 extern void dn_send_disc(struct sock
*sk
, unsigned char type
, unsigned short reason
);
24 extern void dn_nsp_send_lnk(struct sock
*sk
, unsigned short flags
);
25 extern void dn_nsp_send_conninit(struct sock
*sk
, unsigned char flags
);
27 extern void dn_nsp_output(struct sock
*sk
);
28 extern int dn_nsp_check_xmit_queue(struct sock
*sk
, struct sk_buff
*skb
, struct sk_buff_head
*q
, unsigned short acknum
);
29 extern void dn_nsp_queue_xmit(struct sock
*sk
, struct sk_buff
*skb
, int oob
);
30 extern unsigned long dn_nsp_persist(struct sock
*sk
);
31 extern int dn_nsp_xmit_timeout(struct sock
*sk
);
33 extern int dn_nsp_rx(struct sk_buff
*);
34 extern int dn_nsp_backlog_rcv(struct sock
*sk
, struct sk_buff
*skb
);
36 extern struct sk_buff
*dn_alloc_skb(struct sock
*sk
, int size
, int pri
);
37 extern struct sk_buff
*dn_alloc_send_skb(struct sock
*sk
, int *size
, int noblock
, int *err
);
39 #define NSP_REASON_NR 1
40 #define NSP_REASON_DC 42
41 #define NSP_REASON_NL 41
43 #define NSP_DISCINIT 0x38
44 #define NSP_DISCCONF 0x48
46 /*------------------------- NSP - messages ------------------------------*/
50 /* Data Messages (data segment/interrupt/link service) */
52 struct nsp_data_seg_msg
54 unsigned char msgflg
__attribute__((packed
));
55 unsigned short dstaddr
__attribute__((packed
));
56 unsigned short srcaddr
__attribute__((packed
));
59 struct nsp_data_opt_msg
61 unsigned short acknum
__attribute__((packed
));
62 unsigned short segnum
__attribute__((packed
));
63 unsigned short lsflgs
__attribute__((packed
));
66 struct nsp_data_opt_msg1
68 unsigned short acknum
__attribute__((packed
));
69 unsigned short segnum
__attribute__((packed
));
72 /* Acknowledgment Messages */
73 /*-------------------------*/
75 /* Acknowledgment Messages (data/other data) */
77 struct nsp_data_ack_msg
79 unsigned char msgflg
__attribute__((packed
));
80 unsigned short dstaddr
__attribute__((packed
));
81 unsigned short srcaddr
__attribute__((packed
));
82 unsigned short acknum
__attribute__((packed
));
85 /* Connect Acknowledgment Message */
87 struct nsp_conn_ack_msg
89 unsigned char msgflg
__attribute__((packed
));
90 unsigned short dstaddr
__attribute__((packed
));
93 /* Control Messages */
94 /*------------------*/
96 /* Connect Initiate/Retransmit Initiate/Connect Confirm */
98 struct nsp_conn_init_msg
100 unsigned char msgflg
__attribute__((packed
));
101 #define NSP_CI 0x18 /* Connect Initiate */
102 #define NSP_RCI 0x68 /* Retrans. Conn Init */
103 unsigned short dstaddr
__attribute__((packed
));
104 unsigned short srcaddr
__attribute__((packed
));
105 unsigned char services
__attribute__((packed
));
106 #define NSP_FC_NONE 0x00 /* Flow Control None */
107 #define NSP_FC_SRC 0x04 /* Seg Req. Count */
108 #define NSP_FC_SCMC 0x08 /* Sess. Control Mess */
109 unsigned char info
__attribute__((packed
));
110 unsigned short segsize
__attribute__((packed
));
113 /* Disconnect Initiate/Disconnect Confirm */
115 struct nsp_disconn_init_msg
117 unsigned char msgflg
__attribute__((packed
));
118 unsigned short dstaddr
__attribute__((packed
));
119 unsigned short srcaddr
__attribute__((packed
));
120 unsigned short reason
__attribute__((packed
));
124 /*------------------------- SCP - messages ------------------------------*/
128 char format
__attribute__((packed
));
129 unsigned char task
__attribute__((packed
));
130 unsigned short grpcode
__attribute__((packed
));
131 unsigned short usrcode
__attribute__((packed
));
132 char dlen
__attribute__((packed
));
136 * A collection of functions for manipulating the sequence
137 * numbers used in NSP. Similar in operation to the functions
138 * of the same name in TCP.
140 static __inline__
int before(unsigned short seq1
, unsigned short seq2
)
145 return (int)((seq1
- seq2
) & 0x0fff) > 2048;
149 static __inline__
int after(unsigned short seq1
, unsigned short seq2
)
154 return (int)((seq2
- seq1
) & 0x0fff) > 2048;
157 static __inline__
int equal(unsigned short seq1
, unsigned short seq2
)
159 return ((seq1
^ seq2
) & 0x0fff) == 0;
162 static __inline__
int before_or_equal(unsigned short seq1
, unsigned short seq2
)
164 return (before(seq1
, seq2
) || equal(seq1
, seq2
));
167 static __inline__
void seq_add(unsigned short *seq
, unsigned short off
)
173 static __inline__
int seq_next(unsigned short seq1
, unsigned short seq2
)
175 return (((seq2
&0x0fff) - (seq1
&0x0fff)) == 1);
179 * Can we delay the ack ?
181 static __inline__
int sendack(unsigned short seq
)
183 return (int)((seq
& 0x1000) ? 0 : 1);
187 * Is socket congested ?
189 static __inline__
int dn_congested(struct sock
*sk
)
191 return atomic_read(&sk
->rmem_alloc
) > (sk
->rcvbuf
>> 1);
194 #endif /* _NET_DN_NSP_H */