dn_nsp.h 5.8 KB

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