rndis.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * RNDIS Definitions for Remote NDIS
  3. *
  4. * Authors: Benedikt Spranger, Pengutronix
  5. * Robert Schwebel, Pengutronix
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This software was originally developed in conformance with
  12. * Microsoft's Remote NDIS Specification License Agreement.
  13. */
  14. #ifndef _USBGADGET_RNDIS_H
  15. #define _USBGADGET_RNDIS_H
  16. #include "ndis.h"
  17. /*
  18. * By default rndis_signal_disconnect does not send status message about
  19. * RNDIS disconnection to USB host (indicated as cable disconnected).
  20. * Define RNDIS_COMPLETE_SIGNAL_DISCONNECT to send it.
  21. * However, this will cause 1 sec delay on Ethernet device halt.
  22. * Usually you do not need to define it. Mostly usable for debugging.
  23. */
  24. #define RNDIS_MAXIMUM_FRAME_SIZE 1518
  25. #define RNDIS_MAX_TOTAL_SIZE 1558
  26. /* Remote NDIS Versions */
  27. #define RNDIS_MAJOR_VERSION 1
  28. #define RNDIS_MINOR_VERSION 0
  29. /* Status Values */
  30. #define RNDIS_STATUS_SUCCESS 0x00000000U /* Success */
  31. #define RNDIS_STATUS_FAILURE 0xC0000001U /* Unspecified error */
  32. #define RNDIS_STATUS_INVALID_DATA 0xC0010015U /* Invalid data */
  33. #define RNDIS_STATUS_NOT_SUPPORTED 0xC00000BBU /* Unsupported request */
  34. #define RNDIS_STATUS_MEDIA_CONNECT 0x4001000BU /* Device connected */
  35. #define RNDIS_STATUS_MEDIA_DISCONNECT 0x4001000CU /* Device disconnected */
  36. /*
  37. * For all not specified status messages:
  38. * RNDIS_STATUS_Xxx -> NDIS_STATUS_Xxx
  39. */
  40. /* Message Set for Connectionless (802.3) Devices */
  41. #define REMOTE_NDIS_PACKET_MSG 0x00000001U
  42. #define REMOTE_NDIS_INITIALIZE_MSG 0x00000002U /* Initialize device */
  43. #define REMOTE_NDIS_HALT_MSG 0x00000003U
  44. #define REMOTE_NDIS_QUERY_MSG 0x00000004U
  45. #define REMOTE_NDIS_SET_MSG 0x00000005U
  46. #define REMOTE_NDIS_RESET_MSG 0x00000006U
  47. #define REMOTE_NDIS_INDICATE_STATUS_MSG 0x00000007U
  48. #define REMOTE_NDIS_KEEPALIVE_MSG 0x00000008U
  49. /* Message completion */
  50. #define REMOTE_NDIS_INITIALIZE_CMPLT 0x80000002U
  51. #define REMOTE_NDIS_QUERY_CMPLT 0x80000004U
  52. #define REMOTE_NDIS_SET_CMPLT 0x80000005U
  53. #define REMOTE_NDIS_RESET_CMPLT 0x80000006U
  54. #define REMOTE_NDIS_KEEPALIVE_CMPLT 0x80000008U
  55. /* Device Flags */
  56. #define RNDIS_DF_CONNECTIONLESS 0x00000001U
  57. #define RNDIS_DF_CONNECTION_ORIENTED 0x00000002U
  58. #define RNDIS_MEDIUM_802_3 0x00000000U
  59. /* from drivers/net/sk98lin/h/skgepnmi.h */
  60. #define OID_PNP_CAPABILITIES 0xFD010100
  61. #define OID_PNP_SET_POWER 0xFD010101
  62. #define OID_PNP_QUERY_POWER 0xFD010102
  63. #define OID_PNP_ADD_WAKE_UP_PATTERN 0xFD010103
  64. #define OID_PNP_REMOVE_WAKE_UP_PATTERN 0xFD010104
  65. #define OID_PNP_ENABLE_WAKE_UP 0xFD010106
  66. typedef struct rndis_init_msg_type {
  67. __le32 MessageType;
  68. __le32 MessageLength;
  69. __le32 RequestID;
  70. __le32 MajorVersion;
  71. __le32 MinorVersion;
  72. __le32 MaxTransferSize;
  73. } rndis_init_msg_type;
  74. typedef struct rndis_init_cmplt_type {
  75. __le32 MessageType;
  76. __le32 MessageLength;
  77. __le32 RequestID;
  78. __le32 Status;
  79. __le32 MajorVersion;
  80. __le32 MinorVersion;
  81. __le32 DeviceFlags;
  82. __le32 Medium;
  83. __le32 MaxPacketsPerTransfer;
  84. __le32 MaxTransferSize;
  85. __le32 PacketAlignmentFactor;
  86. __le32 AFListOffset;
  87. __le32 AFListSize;
  88. } rndis_init_cmplt_type;
  89. typedef struct rndis_halt_msg_type {
  90. __le32 MessageType;
  91. __le32 MessageLength;
  92. __le32 RequestID;
  93. } rndis_halt_msg_type;
  94. typedef struct rndis_query_msg_type {
  95. __le32 MessageType;
  96. __le32 MessageLength;
  97. __le32 RequestID;
  98. __le32 OID;
  99. __le32 InformationBufferLength;
  100. __le32 InformationBufferOffset;
  101. __le32 DeviceVcHandle;
  102. } rndis_query_msg_type;
  103. typedef struct rndis_query_cmplt_type {
  104. __le32 MessageType;
  105. __le32 MessageLength;
  106. __le32 RequestID;
  107. __le32 Status;
  108. __le32 InformationBufferLength;
  109. __le32 InformationBufferOffset;
  110. } rndis_query_cmplt_type;
  111. typedef struct rndis_set_msg_type {
  112. __le32 MessageType;
  113. __le32 MessageLength;
  114. __le32 RequestID;
  115. __le32 OID;
  116. __le32 InformationBufferLength;
  117. __le32 InformationBufferOffset;
  118. __le32 DeviceVcHandle;
  119. } rndis_set_msg_type;
  120. typedef struct rndis_set_cmplt_type {
  121. __le32 MessageType;
  122. __le32 MessageLength;
  123. __le32 RequestID;
  124. __le32 Status;
  125. } rndis_set_cmplt_type;
  126. typedef struct rndis_reset_msg_type {
  127. __le32 MessageType;
  128. __le32 MessageLength;
  129. __le32 Reserved;
  130. } rndis_reset_msg_type;
  131. typedef struct rndis_reset_cmplt_type {
  132. __le32 MessageType;
  133. __le32 MessageLength;
  134. __le32 Status;
  135. __le32 AddressingReset;
  136. } rndis_reset_cmplt_type;
  137. typedef struct rndis_indicate_status_msg_type {
  138. __le32 MessageType;
  139. __le32 MessageLength;
  140. __le32 Status;
  141. __le32 StatusBufferLength;
  142. __le32 StatusBufferOffset;
  143. } rndis_indicate_status_msg_type;
  144. typedef struct rndis_keepalive_msg_type {
  145. __le32 MessageType;
  146. __le32 MessageLength;
  147. __le32 RequestID;
  148. } rndis_keepalive_msg_type;
  149. typedef struct rndis_keepalive_cmplt_type {
  150. __le32 MessageType;
  151. __le32 MessageLength;
  152. __le32 RequestID;
  153. __le32 Status;
  154. } rndis_keepalive_cmplt_type;
  155. struct rndis_packet_msg_type {
  156. __le32 MessageType;
  157. __le32 MessageLength;
  158. __le32 DataOffset;
  159. __le32 DataLength;
  160. __le32 OOBDataOffset;
  161. __le32 OOBDataLength;
  162. __le32 NumOOBDataElements;
  163. __le32 PerPacketInfoOffset;
  164. __le32 PerPacketInfoLength;
  165. __le32 VcHandle;
  166. __le32 Reserved;
  167. } __attribute__ ((packed));
  168. struct rndis_config_parameter {
  169. __le32 ParameterNameOffset;
  170. __le32 ParameterNameLength;
  171. __le32 ParameterType;
  172. __le32 ParameterValueOffset;
  173. __le32 ParameterValueLength;
  174. };
  175. /* implementation specific */
  176. enum rndis_state {
  177. RNDIS_UNINITIALIZED,
  178. RNDIS_INITIALIZED,
  179. RNDIS_DATA_INITIALIZED,
  180. };
  181. typedef struct rndis_resp_t {
  182. struct list_head list;
  183. u8 *buf;
  184. u32 length;
  185. int send;
  186. } rndis_resp_t;
  187. typedef struct rndis_params {
  188. u8 confignr;
  189. u8 used;
  190. u16 saved_filter;
  191. enum rndis_state state;
  192. u32 medium;
  193. u32 speed;
  194. u32 media_state;
  195. const u8 *host_mac;
  196. u16 *filter;
  197. struct eth_device *dev;
  198. struct net_device_stats *stats;
  199. int mtu;
  200. u32 vendorID;
  201. const char *vendorDescr;
  202. int (*ack)(struct eth_device *);
  203. struct list_head resp_queue;
  204. } rndis_params;
  205. /* RNDIS Message parser and other useless functions */
  206. int rndis_msg_parser(u8 configNr, u8 *buf);
  207. enum rndis_state rndis_get_state(int configNr);
  208. int rndis_register(int (*rndis_control_ack)(struct eth_device *));
  209. void rndis_deregister(int configNr);
  210. int rndis_set_param_dev(u8 configNr, struct eth_device *dev, int mtu,
  211. struct net_device_stats *stats, u16 *cdc_filter);
  212. int rndis_set_param_vendor(u8 configNr, u32 vendorID,
  213. const char *vendorDescr);
  214. int rndis_set_param_medium(u8 configNr, u32 medium, u32 speed);
  215. void rndis_add_hdr(void *bug, int length);
  216. int rndis_rm_hdr(void *bug, int length);
  217. u8 *rndis_get_next_response(int configNr, u32 *length);
  218. void rndis_free_response(int configNr, u8 *buf);
  219. void rndis_uninit(int configNr);
  220. int rndis_signal_connect(int configNr);
  221. int rndis_signal_disconnect(int configNr);
  222. extern void rndis_set_host_mac(int configNr, const u8 *addr);
  223. int rndis_init(void);
  224. void rndis_exit(void);
  225. #endif /* _USBGADGET_RNDIS_H */