pep.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * File: pep.h
  3. *
  4. * Phonet Pipe End Point sockets definitions
  5. *
  6. * Copyright (C) 2008 Nokia Corporation.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. #ifndef NET_PHONET_PEP_H
  23. #define NET_PHONET_PEP_H
  24. struct pep_sock {
  25. struct pn_sock pn_sk;
  26. /* XXX: union-ify listening vs connected stuff ? */
  27. /* Listening socket stuff: */
  28. struct hlist_head ackq;
  29. struct hlist_head hlist;
  30. /* Connected socket stuff: */
  31. struct sock *listener;
  32. struct sk_buff_head ctrlreq_queue;
  33. #define PNPIPE_CTRLREQ_MAX 10
  34. atomic_t tx_credits;
  35. int ifindex;
  36. u16 peer_type; /* peer type/subtype */
  37. u8 pipe_handle;
  38. u8 rx_credits;
  39. u8 rx_fc; /* RX flow control */
  40. u8 tx_fc; /* TX flow control */
  41. u8 init_enable; /* auto-enable at creation */
  42. u8 aligned;
  43. #ifdef CONFIG_PHONET_PIPECTRLR
  44. u8 pipe_state;
  45. struct sockaddr_pn remote_pep;
  46. #endif
  47. };
  48. static inline struct pep_sock *pep_sk(struct sock *sk)
  49. {
  50. return (struct pep_sock *)sk;
  51. }
  52. extern const struct proto_ops phonet_stream_ops;
  53. /* Pipe protocol definitions */
  54. struct pnpipehdr {
  55. u8 utid; /* transaction ID */
  56. u8 message_id;
  57. u8 pipe_handle;
  58. union {
  59. u8 state_after_connect; /* connect request */
  60. u8 state_after_reset; /* reset request */
  61. u8 error_code; /* any response */
  62. u8 pep_type; /* status indication */
  63. u8 data[1];
  64. };
  65. };
  66. #define other_pep_type data[1]
  67. static inline struct pnpipehdr *pnp_hdr(struct sk_buff *skb)
  68. {
  69. return (struct pnpipehdr *)skb_transport_header(skb);
  70. }
  71. #define MAX_PNPIPE_HEADER (MAX_PHONET_HEADER + 4)
  72. enum {
  73. PNS_PIPE_CREATE_REQ = 0x00,
  74. PNS_PIPE_CREATE_RESP,
  75. PNS_PIPE_REMOVE_REQ,
  76. PNS_PIPE_REMOVE_RESP,
  77. PNS_PIPE_DATA = 0x20,
  78. PNS_PIPE_ALIGNED_DATA,
  79. PNS_PEP_CONNECT_REQ = 0x40,
  80. PNS_PEP_CONNECT_RESP,
  81. PNS_PEP_DISCONNECT_REQ,
  82. PNS_PEP_DISCONNECT_RESP,
  83. PNS_PEP_RESET_REQ,
  84. PNS_PEP_RESET_RESP,
  85. PNS_PEP_ENABLE_REQ,
  86. PNS_PEP_ENABLE_RESP,
  87. PNS_PEP_CTRL_REQ,
  88. PNS_PEP_CTRL_RESP,
  89. PNS_PEP_DISABLE_REQ = 0x4C,
  90. PNS_PEP_DISABLE_RESP,
  91. PNS_PEP_STATUS_IND = 0x60,
  92. PNS_PIPE_CREATED_IND,
  93. PNS_PIPE_RESET_IND = 0x63,
  94. PNS_PIPE_ENABLED_IND,
  95. PNS_PIPE_REDIRECTED_IND,
  96. PNS_PIPE_DISABLED_IND = 0x66,
  97. };
  98. #define PN_PIPE_INVALID_HANDLE 0xff
  99. #define PN_PEP_TYPE_COMMON 0x00
  100. /* Phonet pipe status indication */
  101. enum {
  102. PN_PEP_IND_FLOW_CONTROL,
  103. PN_PEP_IND_ID_MCFC_GRANT_CREDITS,
  104. };
  105. /* Phonet pipe error codes */
  106. enum {
  107. PN_PIPE_NO_ERROR,
  108. PN_PIPE_ERR_INVALID_PARAM,
  109. PN_PIPE_ERR_INVALID_HANDLE,
  110. PN_PIPE_ERR_INVALID_CTRL_ID,
  111. PN_PIPE_ERR_NOT_ALLOWED,
  112. PN_PIPE_ERR_PEP_IN_USE,
  113. PN_PIPE_ERR_OVERLOAD,
  114. PN_PIPE_ERR_DEV_DISCONNECTED,
  115. PN_PIPE_ERR_TIMEOUT,
  116. PN_PIPE_ERR_ALL_PIPES_IN_USE,
  117. PN_PIPE_ERR_GENERAL,
  118. PN_PIPE_ERR_NOT_SUPPORTED,
  119. };
  120. /* Phonet pipe states */
  121. enum {
  122. PN_PIPE_DISABLE,
  123. PN_PIPE_ENABLE,
  124. };
  125. /* Phonet pipe sub-block types */
  126. enum {
  127. PN_PIPE_SB_CREATE_REQ_PEP_SUB_TYPE,
  128. PN_PIPE_SB_CONNECT_REQ_PEP_SUB_TYPE,
  129. PN_PIPE_SB_REDIRECT_REQ_PEP_SUB_TYPE,
  130. PN_PIPE_SB_NEGOTIATED_FC,
  131. PN_PIPE_SB_REQUIRED_FC_TX,
  132. PN_PIPE_SB_PREFERRED_FC_RX,
  133. PN_PIPE_SB_ALIGNED_DATA,
  134. };
  135. /* Phonet pipe flow control models */
  136. enum {
  137. PN_NO_FLOW_CONTROL,
  138. PN_LEGACY_FLOW_CONTROL,
  139. PN_ONE_CREDIT_FLOW_CONTROL,
  140. PN_MULTI_CREDIT_FLOW_CONTROL,
  141. };
  142. #define pn_flow_safe(fc) ((fc) >> 1)
  143. /* Phonet pipe flow control states */
  144. enum {
  145. PEP_IND_EMPTY,
  146. PEP_IND_BUSY,
  147. PEP_IND_READY,
  148. };
  149. #ifdef CONFIG_PHONET_PIPECTRLR
  150. #define PNS_PEP_CONNECT_UTID 0x02
  151. #define PNS_PIPE_CREATED_IND_UTID 0x04
  152. #define PNS_PIPE_ENABLE_UTID 0x0A
  153. #define PNS_PIPE_ENABLED_IND_UTID 0x0C
  154. #define PNS_PIPE_DISABLE_UTID 0x0F
  155. #define PNS_PIPE_DISABLED_IND_UTID 0x11
  156. #define PNS_PEP_DISCONNECT_UTID 0x06
  157. /* Used for tracking state of a pipe */
  158. enum {
  159. PIPE_IDLE,
  160. PIPE_DISABLED,
  161. PIPE_ENABLED,
  162. };
  163. #endif /* CONFIG_PHONET_PIPECTRLR */
  164. #endif