tipc_msg.h 6.1 KB

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