rndis_host.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * Host Side support for RNDIS Networking Links
  3. * Copyright (C) 2005 by David Brownell
  4. *
  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. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __RNDIS_HOST_H
  20. #define __RNDIS_HOST_H
  21. /*
  22. * CONTROL uses CDC "encapsulated commands" with funky notifications.
  23. * - control-out: SEND_ENCAPSULATED
  24. * - interrupt-in: RESPONSE_AVAILABLE
  25. * - control-in: GET_ENCAPSULATED
  26. *
  27. * We'll try to ignore the RESPONSE_AVAILABLE notifications.
  28. *
  29. * REVISIT some RNDIS implementations seem to have curious issues still
  30. * to be resolved.
  31. */
  32. struct rndis_msg_hdr {
  33. __le32 msg_type; /* RNDIS_MSG_* */
  34. __le32 msg_len;
  35. // followed by data that varies between messages
  36. __le32 request_id;
  37. __le32 status;
  38. // ... and more
  39. } __attribute__ ((packed));
  40. /* MS-Windows uses this strange size, but RNDIS spec says 1024 minimum */
  41. #define CONTROL_BUFFER_SIZE 1025
  42. /* RNDIS defines an (absurdly huge) 10 second control timeout,
  43. * but ActiveSync seems to use a more usual 5 second timeout
  44. * (which matches the USB 2.0 spec).
  45. */
  46. #define RNDIS_CONTROL_TIMEOUT_MS (5 * 1000)
  47. #define ccpu2 __constant_cpu_to_le32
  48. #define RNDIS_MSG_COMPLETION ccpu2(0x80000000)
  49. /* codes for "msg_type" field of rndis messages;
  50. * only the data channel uses packet messages (maybe batched);
  51. * everything else goes on the control channel.
  52. */
  53. #define RNDIS_MSG_PACKET ccpu2(0x00000001) /* 1-N packets */
  54. #define RNDIS_MSG_INIT ccpu2(0x00000002)
  55. #define RNDIS_MSG_INIT_C (RNDIS_MSG_INIT|RNDIS_MSG_COMPLETION)
  56. #define RNDIS_MSG_HALT ccpu2(0x00000003)
  57. #define RNDIS_MSG_QUERY ccpu2(0x00000004)
  58. #define RNDIS_MSG_QUERY_C (RNDIS_MSG_QUERY|RNDIS_MSG_COMPLETION)
  59. #define RNDIS_MSG_SET ccpu2(0x00000005)
  60. #define RNDIS_MSG_SET_C (RNDIS_MSG_SET|RNDIS_MSG_COMPLETION)
  61. #define RNDIS_MSG_RESET ccpu2(0x00000006)
  62. #define RNDIS_MSG_RESET_C (RNDIS_MSG_RESET|RNDIS_MSG_COMPLETION)
  63. #define RNDIS_MSG_INDICATE ccpu2(0x00000007)
  64. #define RNDIS_MSG_KEEPALIVE ccpu2(0x00000008)
  65. #define RNDIS_MSG_KEEPALIVE_C (RNDIS_MSG_KEEPALIVE|RNDIS_MSG_COMPLETION)
  66. /* codes for "status" field of completion messages */
  67. #define RNDIS_STATUS_SUCCESS ccpu2(0x00000000)
  68. #define RNDIS_STATUS_FAILURE ccpu2(0xc0000001)
  69. #define RNDIS_STATUS_INVALID_DATA ccpu2(0xc0010015)
  70. #define RNDIS_STATUS_NOT_SUPPORTED ccpu2(0xc00000bb)
  71. #define RNDIS_STATUS_MEDIA_CONNECT ccpu2(0x4001000b)
  72. #define RNDIS_STATUS_MEDIA_DISCONNECT ccpu2(0x4001000c)
  73. struct rndis_data_hdr {
  74. __le32 msg_type; /* RNDIS_MSG_PACKET */
  75. __le32 msg_len; // rndis_data_hdr + data_len + pad
  76. __le32 data_offset; // 36 -- right after header
  77. __le32 data_len; // ... real packet size
  78. __le32 oob_data_offset; // zero
  79. __le32 oob_data_len; // zero
  80. __le32 num_oob; // zero
  81. __le32 packet_data_offset; // zero
  82. __le32 packet_data_len; // zero
  83. __le32 vc_handle; // zero
  84. __le32 reserved; // zero
  85. } __attribute__ ((packed));
  86. struct rndis_init { /* OUT */
  87. // header and:
  88. __le32 msg_type; /* RNDIS_MSG_INIT */
  89. __le32 msg_len; // 24
  90. __le32 request_id;
  91. __le32 major_version; // of rndis (1.0)
  92. __le32 minor_version;
  93. __le32 max_transfer_size;
  94. } __attribute__ ((packed));
  95. struct rndis_init_c { /* IN */
  96. // header and:
  97. __le32 msg_type; /* RNDIS_MSG_INIT_C */
  98. __le32 msg_len;
  99. __le32 request_id;
  100. __le32 status;
  101. __le32 major_version; // of rndis (1.0)
  102. __le32 minor_version;
  103. __le32 device_flags;
  104. __le32 medium; // zero == 802.3
  105. __le32 max_packets_per_message;
  106. __le32 max_transfer_size;
  107. __le32 packet_alignment; // max 7; (1<<n) bytes
  108. __le32 af_list_offset; // zero
  109. __le32 af_list_size; // zero
  110. } __attribute__ ((packed));
  111. struct rndis_halt { /* OUT (no reply) */
  112. // header and:
  113. __le32 msg_type; /* RNDIS_MSG_HALT */
  114. __le32 msg_len;
  115. __le32 request_id;
  116. } __attribute__ ((packed));
  117. struct rndis_query { /* OUT */
  118. // header and:
  119. __le32 msg_type; /* RNDIS_MSG_QUERY */
  120. __le32 msg_len;
  121. __le32 request_id;
  122. __le32 oid;
  123. __le32 len;
  124. __le32 offset;
  125. /*?*/ __le32 handle; // zero
  126. } __attribute__ ((packed));
  127. struct rndis_query_c { /* IN */
  128. // header and:
  129. __le32 msg_type; /* RNDIS_MSG_QUERY_C */
  130. __le32 msg_len;
  131. __le32 request_id;
  132. __le32 status;
  133. __le32 len;
  134. __le32 offset;
  135. } __attribute__ ((packed));
  136. struct rndis_set { /* OUT */
  137. // header and:
  138. __le32 msg_type; /* RNDIS_MSG_SET */
  139. __le32 msg_len;
  140. __le32 request_id;
  141. __le32 oid;
  142. __le32 len;
  143. __le32 offset;
  144. /*?*/ __le32 handle; // zero
  145. } __attribute__ ((packed));
  146. struct rndis_set_c { /* IN */
  147. // header and:
  148. __le32 msg_type; /* RNDIS_MSG_SET_C */
  149. __le32 msg_len;
  150. __le32 request_id;
  151. __le32 status;
  152. } __attribute__ ((packed));
  153. struct rndis_reset { /* IN */
  154. // header and:
  155. __le32 msg_type; /* RNDIS_MSG_RESET */
  156. __le32 msg_len;
  157. __le32 reserved;
  158. } __attribute__ ((packed));
  159. struct rndis_reset_c { /* OUT */
  160. // header and:
  161. __le32 msg_type; /* RNDIS_MSG_RESET_C */
  162. __le32 msg_len;
  163. __le32 status;
  164. __le32 addressing_lost;
  165. } __attribute__ ((packed));
  166. struct rndis_indicate { /* IN (unrequested) */
  167. // header and:
  168. __le32 msg_type; /* RNDIS_MSG_INDICATE */
  169. __le32 msg_len;
  170. __le32 status;
  171. __le32 length;
  172. __le32 offset;
  173. /**/ __le32 diag_status;
  174. __le32 error_offset;
  175. /**/ __le32 message;
  176. } __attribute__ ((packed));
  177. struct rndis_keepalive { /* OUT (optionally IN) */
  178. // header and:
  179. __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */
  180. __le32 msg_len;
  181. __le32 request_id;
  182. } __attribute__ ((packed));
  183. struct rndis_keepalive_c { /* IN (optionally OUT) */
  184. // header and:
  185. __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */
  186. __le32 msg_len;
  187. __le32 request_id;
  188. __le32 status;
  189. } __attribute__ ((packed));
  190. /* NOTE: about 30 OIDs are "mandatory" for peripherals to support ... and
  191. * there are gobs more that may optionally be supported. We'll avoid as much
  192. * of that mess as possible.
  193. */
  194. #define OID_802_3_PERMANENT_ADDRESS ccpu2(0x01010101)
  195. #define OID_GEN_MAXIMUM_FRAME_SIZE ccpu2(0x00010106)
  196. #define OID_GEN_CURRENT_PACKET_FILTER ccpu2(0x0001010e)
  197. /* packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */
  198. #define RNDIS_PACKET_TYPE_DIRECTED ccpu2(0x00000001)
  199. #define RNDIS_PACKET_TYPE_MULTICAST ccpu2(0x00000002)
  200. #define RNDIS_PACKET_TYPE_ALL_MULTICAST ccpu2(0x00000004)
  201. #define RNDIS_PACKET_TYPE_BROADCAST ccpu2(0x00000008)
  202. #define RNDIS_PACKET_TYPE_SOURCE_ROUTING ccpu2(0x00000010)
  203. #define RNDIS_PACKET_TYPE_PROMISCUOUS ccpu2(0x00000020)
  204. #define RNDIS_PACKET_TYPE_SMT ccpu2(0x00000040)
  205. #define RNDIS_PACKET_TYPE_ALL_LOCAL ccpu2(0x00000080)
  206. #define RNDIS_PACKET_TYPE_GROUP ccpu2(0x00001000)
  207. #define RNDIS_PACKET_TYPE_ALL_FUNCTIONAL ccpu2(0x00002000)
  208. #define RNDIS_PACKET_TYPE_FUNCTIONAL ccpu2(0x00004000)
  209. #define RNDIS_PACKET_TYPE_MAC_FRAME ccpu2(0x00008000)
  210. /* default filter used with RNDIS devices */
  211. #define RNDIS_DEFAULT_FILTER ( \
  212. RNDIS_PACKET_TYPE_DIRECTED | \
  213. RNDIS_PACKET_TYPE_BROADCAST | \
  214. RNDIS_PACKET_TYPE_ALL_MULTICAST | \
  215. RNDIS_PACKET_TYPE_PROMISCUOUS)
  216. extern void rndis_status(struct usbnet *dev, struct urb *urb);
  217. extern int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf);
  218. extern int generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf);
  219. extern void rndis_unbind(struct usbnet *dev, struct usb_interface *intf);
  220. extern int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb);
  221. extern struct sk_buff *
  222. rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags);
  223. #endif /* __RNDIS_HOST_H */