tipc_msg.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. * include/net/tipc/tipc_msg.h: Include file for privileged access to TIPC message headers
  3. *
  4. * Copyright (c) 2003-2005, Ericsson Research Canada
  5. * Copyright (c) 2005, Wind River Systems
  6. * Copyright (c) 2005-2006, Ericsson AB
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #ifndef _NET_TIPC_MSG_H_
  34. #define _NET_TIPC_MSG_H_
  35. #ifdef __KERNEL__
  36. struct tipc_msg {
  37. u32 hdr[15];
  38. };
  39. /*
  40. TIPC user data message header format, version 2:
  41. 1 0 9 8 7 6 5 4|3 2 1 0 9 8 7 6|5 4 3 2 1 0 9 8|7 6 5 4 3 2 1 0
  42. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  43. w0:|vers | user |hdr sz |n|d|s|-| message size |
  44. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  45. w1:|mstyp| error |rer cnt|lsc|opt p| broadcast ack no |
  46. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  47. w2:| link level ack no | broadcast/link level seq no |
  48. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  49. w3:| previous node |
  50. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  51. w4:| originating port |
  52. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  53. w5:| destination port |
  54. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  55. w6:| originating node |
  56. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  57. w7:| destination node |
  58. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  59. w8:| name type / transport sequence number |
  60. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  61. w9:| name instance/multicast lower bound |
  62. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  63. wA:| multicast upper bound |
  64. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  65. / /
  66. \ options \
  67. / /
  68. +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  69. */
  70. #define TIPC_CONN_MSG 0
  71. #define TIPC_MCAST_MSG 1
  72. #define TIPC_NAMED_MSG 2
  73. #define TIPC_DIRECT_MSG 3
  74. static inline u32 msg_word(struct tipc_msg *m, u32 pos)
  75. {
  76. return ntohl(m->hdr[pos]);
  77. }
  78. static inline u32 msg_bits(struct tipc_msg *m, u32 w, u32 pos, u32 mask)
  79. {
  80. return (msg_word(m, w) >> pos) & mask;
  81. }
  82. static inline u32 msg_importance(struct tipc_msg *m)
  83. {
  84. return msg_bits(m, 0, 25, 0xf);
  85. }
  86. static inline u32 msg_hdr_sz(struct tipc_msg *m)
  87. {
  88. return msg_bits(m, 0, 21, 0xf) << 2;
  89. }
  90. static inline int msg_short(struct tipc_msg *m)
  91. {
  92. return (msg_hdr_sz(m) == 24);
  93. }
  94. static inline u32 msg_size(struct tipc_msg *m)
  95. {
  96. return msg_bits(m, 0, 0, 0x1ffff);
  97. }
  98. static inline u32 msg_data_sz(struct tipc_msg *m)
  99. {
  100. return (msg_size(m) - msg_hdr_sz(m));
  101. }
  102. static inline unchar *msg_data(struct tipc_msg *m)
  103. {
  104. return ((unchar *)m) + msg_hdr_sz(m);
  105. }
  106. static inline u32 msg_type(struct tipc_msg *m)
  107. {
  108. return msg_bits(m, 1, 29, 0x7);
  109. }
  110. static inline u32 msg_direct(struct tipc_msg *m)
  111. {
  112. return (msg_type(m) == TIPC_DIRECT_MSG);
  113. }
  114. static inline u32 msg_named(struct tipc_msg *m)
  115. {
  116. return (msg_type(m) == TIPC_NAMED_MSG);
  117. }
  118. static inline u32 msg_mcast(struct tipc_msg *m)
  119. {
  120. return (msg_type(m) == TIPC_MCAST_MSG);
  121. }
  122. static inline u32 msg_connected(struct tipc_msg *m)
  123. {
  124. return (msg_type(m) == TIPC_CONN_MSG);
  125. }
  126. static inline u32 msg_errcode(struct tipc_msg *m)
  127. {
  128. return msg_bits(m, 1, 25, 0xf);
  129. }
  130. static inline u32 msg_prevnode(struct tipc_msg *m)
  131. {
  132. return msg_word(m, 3);
  133. }
  134. static inline u32 msg_origport(struct tipc_msg *m)
  135. {
  136. return msg_word(m, 4);
  137. }
  138. static inline u32 msg_destport(struct tipc_msg *m)
  139. {
  140. return msg_word(m, 5);
  141. }
  142. static inline u32 msg_mc_netid(struct tipc_msg *m)
  143. {
  144. return msg_word(m, 5);
  145. }
  146. static inline u32 msg_orignode(struct tipc_msg *m)
  147. {
  148. if (likely(msg_short(m)))
  149. return msg_prevnode(m);
  150. return msg_word(m, 6);
  151. }
  152. static inline u32 msg_destnode(struct tipc_msg *m)
  153. {
  154. return msg_word(m, 7);
  155. }
  156. static inline u32 msg_nametype(struct tipc_msg *m)
  157. {
  158. return msg_word(m, 8);
  159. }
  160. static inline u32 msg_nameinst(struct tipc_msg *m)
  161. {
  162. return msg_word(m, 9);
  163. }
  164. static inline u32 msg_namelower(struct tipc_msg *m)
  165. {
  166. return msg_nameinst(m);
  167. }
  168. static inline u32 msg_nameupper(struct tipc_msg *m)
  169. {
  170. return msg_word(m, 10);
  171. }
  172. static inline char *msg_options(struct tipc_msg *m, u32 *len)
  173. {
  174. u32 pos = msg_bits(m, 1, 16, 0x7);
  175. if (!pos)
  176. return 0;
  177. pos = (pos * 4) + 28;
  178. *len = msg_hdr_sz(m) - pos;
  179. return (char *)&m->hdr[pos/4];
  180. }
  181. #endif
  182. #endif