dn_nsp.h 6.1 KB

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