rndis.h 7.0 KB

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