rndis_host.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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 __LINUX_USB_RNDIS_HOST_H
  20. #define __LINUX_USB_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 RNDIS_MSG_COMPLETION cpu_to_le32(0x80000000)
  48. /* codes for "msg_type" field of rndis messages;
  49. * only the data channel uses packet messages (maybe batched);
  50. * everything else goes on the control channel.
  51. */
  52. #define RNDIS_MSG_PACKET cpu_to_le32(0x00000001) /* 1-N packets */
  53. #define RNDIS_MSG_INIT cpu_to_le32(0x00000002)
  54. #define RNDIS_MSG_INIT_C (RNDIS_MSG_INIT|RNDIS_MSG_COMPLETION)
  55. #define RNDIS_MSG_HALT cpu_to_le32(0x00000003)
  56. #define RNDIS_MSG_QUERY cpu_to_le32(0x00000004)
  57. #define RNDIS_MSG_QUERY_C (RNDIS_MSG_QUERY|RNDIS_MSG_COMPLETION)
  58. #define RNDIS_MSG_SET cpu_to_le32(0x00000005)
  59. #define RNDIS_MSG_SET_C (RNDIS_MSG_SET|RNDIS_MSG_COMPLETION)
  60. #define RNDIS_MSG_RESET cpu_to_le32(0x00000006)
  61. #define RNDIS_MSG_RESET_C (RNDIS_MSG_RESET|RNDIS_MSG_COMPLETION)
  62. #define RNDIS_MSG_INDICATE cpu_to_le32(0x00000007)
  63. #define RNDIS_MSG_KEEPALIVE cpu_to_le32(0x00000008)
  64. #define RNDIS_MSG_KEEPALIVE_C (RNDIS_MSG_KEEPALIVE|RNDIS_MSG_COMPLETION)
  65. /* codes for "status" field of completion messages */
  66. #define RNDIS_STATUS_SUCCESS cpu_to_le32(0x00000000)
  67. #define RNDIS_STATUS_FAILURE cpu_to_le32(0xc0000001)
  68. #define RNDIS_STATUS_INVALID_DATA cpu_to_le32(0xc0010015)
  69. #define RNDIS_STATUS_NOT_SUPPORTED cpu_to_le32(0xc00000bb)
  70. #define RNDIS_STATUS_MEDIA_CONNECT cpu_to_le32(0x4001000b)
  71. #define RNDIS_STATUS_MEDIA_DISCONNECT cpu_to_le32(0x4001000c)
  72. #define RNDIS_STATUS_MEDIA_SPECIFIC_INDICATION cpu_to_le32(0x40010012)
  73. /* codes for OID_GEN_PHYSICAL_MEDIUM */
  74. #define RNDIS_PHYSICAL_MEDIUM_UNSPECIFIED cpu_to_le32(0x00000000)
  75. #define RNDIS_PHYSICAL_MEDIUM_WIRELESS_LAN cpu_to_le32(0x00000001)
  76. #define RNDIS_PHYSICAL_MEDIUM_CABLE_MODEM cpu_to_le32(0x00000002)
  77. #define RNDIS_PHYSICAL_MEDIUM_PHONE_LINE cpu_to_le32(0x00000003)
  78. #define RNDIS_PHYSICAL_MEDIUM_POWER_LINE cpu_to_le32(0x00000004)
  79. #define RNDIS_PHYSICAL_MEDIUM_DSL cpu_to_le32(0x00000005)
  80. #define RNDIS_PHYSICAL_MEDIUM_FIBRE_CHANNEL cpu_to_le32(0x00000006)
  81. #define RNDIS_PHYSICAL_MEDIUM_1394 cpu_to_le32(0x00000007)
  82. #define RNDIS_PHYSICAL_MEDIUM_WIRELESS_WAN cpu_to_le32(0x00000008)
  83. #define RNDIS_PHYSICAL_MEDIUM_MAX cpu_to_le32(0x00000009)
  84. struct rndis_data_hdr {
  85. __le32 msg_type; /* RNDIS_MSG_PACKET */
  86. __le32 msg_len; // rndis_data_hdr + data_len + pad
  87. __le32 data_offset; // 36 -- right after header
  88. __le32 data_len; // ... real packet size
  89. __le32 oob_data_offset; // zero
  90. __le32 oob_data_len; // zero
  91. __le32 num_oob; // zero
  92. __le32 packet_data_offset; // zero
  93. __le32 packet_data_len; // zero
  94. __le32 vc_handle; // zero
  95. __le32 reserved; // zero
  96. } __attribute__ ((packed));
  97. struct rndis_init { /* OUT */
  98. // header and:
  99. __le32 msg_type; /* RNDIS_MSG_INIT */
  100. __le32 msg_len; // 24
  101. __le32 request_id;
  102. __le32 major_version; // of rndis (1.0)
  103. __le32 minor_version;
  104. __le32 max_transfer_size;
  105. } __attribute__ ((packed));
  106. struct rndis_init_c { /* IN */
  107. // header and:
  108. __le32 msg_type; /* RNDIS_MSG_INIT_C */
  109. __le32 msg_len;
  110. __le32 request_id;
  111. __le32 status;
  112. __le32 major_version; // of rndis (1.0)
  113. __le32 minor_version;
  114. __le32 device_flags;
  115. __le32 medium; // zero == 802.3
  116. __le32 max_packets_per_message;
  117. __le32 max_transfer_size;
  118. __le32 packet_alignment; // max 7; (1<<n) bytes
  119. __le32 af_list_offset; // zero
  120. __le32 af_list_size; // zero
  121. } __attribute__ ((packed));
  122. struct rndis_halt { /* OUT (no reply) */
  123. // header and:
  124. __le32 msg_type; /* RNDIS_MSG_HALT */
  125. __le32 msg_len;
  126. __le32 request_id;
  127. } __attribute__ ((packed));
  128. struct rndis_query { /* OUT */
  129. // header and:
  130. __le32 msg_type; /* RNDIS_MSG_QUERY */
  131. __le32 msg_len;
  132. __le32 request_id;
  133. __le32 oid;
  134. __le32 len;
  135. __le32 offset;
  136. /*?*/ __le32 handle; // zero
  137. } __attribute__ ((packed));
  138. struct rndis_query_c { /* IN */
  139. // header and:
  140. __le32 msg_type; /* RNDIS_MSG_QUERY_C */
  141. __le32 msg_len;
  142. __le32 request_id;
  143. __le32 status;
  144. __le32 len;
  145. __le32 offset;
  146. } __attribute__ ((packed));
  147. struct rndis_set { /* OUT */
  148. // header and:
  149. __le32 msg_type; /* RNDIS_MSG_SET */
  150. __le32 msg_len;
  151. __le32 request_id;
  152. __le32 oid;
  153. __le32 len;
  154. __le32 offset;
  155. /*?*/ __le32 handle; // zero
  156. } __attribute__ ((packed));
  157. struct rndis_set_c { /* IN */
  158. // header and:
  159. __le32 msg_type; /* RNDIS_MSG_SET_C */
  160. __le32 msg_len;
  161. __le32 request_id;
  162. __le32 status;
  163. } __attribute__ ((packed));
  164. struct rndis_reset { /* IN */
  165. // header and:
  166. __le32 msg_type; /* RNDIS_MSG_RESET */
  167. __le32 msg_len;
  168. __le32 reserved;
  169. } __attribute__ ((packed));
  170. struct rndis_reset_c { /* OUT */
  171. // header and:
  172. __le32 msg_type; /* RNDIS_MSG_RESET_C */
  173. __le32 msg_len;
  174. __le32 status;
  175. __le32 addressing_lost;
  176. } __attribute__ ((packed));
  177. struct rndis_indicate { /* IN (unrequested) */
  178. // header and:
  179. __le32 msg_type; /* RNDIS_MSG_INDICATE */
  180. __le32 msg_len;
  181. __le32 status;
  182. __le32 length;
  183. __le32 offset;
  184. /**/ __le32 diag_status;
  185. __le32 error_offset;
  186. /**/ __le32 message;
  187. } __attribute__ ((packed));
  188. struct rndis_keepalive { /* OUT (optionally IN) */
  189. // header and:
  190. __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */
  191. __le32 msg_len;
  192. __le32 request_id;
  193. } __attribute__ ((packed));
  194. struct rndis_keepalive_c { /* IN (optionally OUT) */
  195. // header and:
  196. __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */
  197. __le32 msg_len;
  198. __le32 request_id;
  199. __le32 status;
  200. } __attribute__ ((packed));
  201. /* NOTE: about 30 OIDs are "mandatory" for peripherals to support ... and
  202. * there are gobs more that may optionally be supported. We'll avoid as much
  203. * of that mess as possible.
  204. */
  205. #define OID_802_3_PERMANENT_ADDRESS cpu_to_le32(0x01010101)
  206. #define OID_GEN_MAXIMUM_FRAME_SIZE cpu_to_le32(0x00010106)
  207. #define OID_GEN_CURRENT_PACKET_FILTER cpu_to_le32(0x0001010e)
  208. #define OID_GEN_PHYSICAL_MEDIUM cpu_to_le32(0x00010202)
  209. /* packet filter bits used by OID_GEN_CURRENT_PACKET_FILTER */
  210. #define RNDIS_PACKET_TYPE_DIRECTED cpu_to_le32(0x00000001)
  211. #define RNDIS_PACKET_TYPE_MULTICAST cpu_to_le32(0x00000002)
  212. #define RNDIS_PACKET_TYPE_ALL_MULTICAST cpu_to_le32(0x00000004)
  213. #define RNDIS_PACKET_TYPE_BROADCAST cpu_to_le32(0x00000008)
  214. #define RNDIS_PACKET_TYPE_SOURCE_ROUTING cpu_to_le32(0x00000010)
  215. #define RNDIS_PACKET_TYPE_PROMISCUOUS cpu_to_le32(0x00000020)
  216. #define RNDIS_PACKET_TYPE_SMT cpu_to_le32(0x00000040)
  217. #define RNDIS_PACKET_TYPE_ALL_LOCAL cpu_to_le32(0x00000080)
  218. #define RNDIS_PACKET_TYPE_GROUP cpu_to_le32(0x00001000)
  219. #define RNDIS_PACKET_TYPE_ALL_FUNCTIONAL cpu_to_le32(0x00002000)
  220. #define RNDIS_PACKET_TYPE_FUNCTIONAL cpu_to_le32(0x00004000)
  221. #define RNDIS_PACKET_TYPE_MAC_FRAME cpu_to_le32(0x00008000)
  222. /* default filter used with RNDIS devices */
  223. #define RNDIS_DEFAULT_FILTER ( \
  224. RNDIS_PACKET_TYPE_DIRECTED | \
  225. RNDIS_PACKET_TYPE_BROADCAST | \
  226. RNDIS_PACKET_TYPE_ALL_MULTICAST | \
  227. RNDIS_PACKET_TYPE_PROMISCUOUS)
  228. /* Flags to require specific physical medium type for generic_rndis_bind() */
  229. #define FLAG_RNDIS_PHYM_NOT_WIRELESS 0x0001
  230. #define FLAG_RNDIS_PHYM_WIRELESS 0x0002
  231. extern void rndis_status(struct usbnet *dev, struct urb *urb);
  232. extern int
  233. rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf, int buflen);
  234. extern int
  235. generic_rndis_bind(struct usbnet *dev, struct usb_interface *intf, int flags);
  236. extern void rndis_unbind(struct usbnet *dev, struct usb_interface *intf);
  237. extern int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb);
  238. extern struct sk_buff *
  239. rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags);
  240. #endif /* __LINUX_USB_RNDIS_HOST_H */