rndis.h 7.0 KB

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