You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rndis.h 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. #ifndef _IPXE_RNDIS_H
  2. #define _IPXE_RNDIS_H
  3. /** @file
  4. *
  5. * Remote Network Driver Interface Specification
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER );
  9. #include <stdint.h>
  10. #include <ipxe/netdevice.h>
  11. #include <ipxe/iobuf.h>
  12. /** Maximum time to wait for a transaction to complete
  13. *
  14. * This is a policy decision.
  15. */
  16. #define RNDIS_MAX_WAIT_MS 1000
  17. /** RNDIS message header */
  18. struct rndis_header {
  19. /** Message type */
  20. uint32_t type;
  21. /** Message length */
  22. uint32_t len;
  23. } __attribute__ (( packed ));
  24. /** RNDIS initialise message */
  25. #define RNDIS_INITIALIZE_MSG 0x00000002UL
  26. /** RNDIS initialise message */
  27. struct rndis_initialize_message {
  28. /** Request ID */
  29. uint32_t id;
  30. /** Major version */
  31. uint32_t major;
  32. /** Minor version */
  33. uint32_t minor;
  34. /** Maximum transfer size */
  35. uint32_t mtu;
  36. } __attribute__ (( packed ));
  37. /** RNDIS initialise completion */
  38. #define RNDIS_INITIALISE_CMPLT 0x80000002UL
  39. /** RNDIS initialise completion */
  40. struct rndis_initialise_completion {
  41. /** Request ID */
  42. uint32_t id;
  43. /** Status */
  44. uint32_t status;
  45. /** Major version */
  46. uint32_t major;
  47. /** Minor version */
  48. uint32_t minor;
  49. /** Device flags */
  50. uint32_t flags;
  51. /** Medium */
  52. uint32_t medium;
  53. /** Maximum packets per transfer */
  54. uint32_t max_pkts;
  55. /** Maximum transfer size */
  56. uint32_t mtu;
  57. /** Packet alignment factor */
  58. uint32_t align;
  59. /** Reserved */
  60. uint32_t reserved;
  61. } __attribute__ (( packed ));
  62. /** RNDIS halt message */
  63. #define RNIS_HALT_MSG 0x00000003UL
  64. /** RNDIS halt message */
  65. struct rndis_halt_message {
  66. /** Request ID */
  67. uint32_t id;
  68. } __attribute__ (( packed ));
  69. /** RNDIS query OID message */
  70. #define RNDIS_QUERY_MSG 0x00000004UL
  71. /** RNDIS set OID message */
  72. #define RNDIS_SET_MSG 0x00000005UL
  73. /** RNDIS query or set OID message */
  74. struct rndis_oid_message {
  75. /** Request ID */
  76. uint32_t id;
  77. /** Object ID */
  78. uint32_t oid;
  79. /** Information buffer length */
  80. uint32_t len;
  81. /** Information buffer offset */
  82. uint32_t offset;
  83. /** Reserved */
  84. uint32_t reserved;
  85. } __attribute__ (( packed ));
  86. /** RNDIS query OID completion */
  87. #define RNDIS_QUERY_CMPLT 0x80000004UL
  88. /** RNDIS query OID completion */
  89. struct rndis_query_completion {
  90. /** Request ID */
  91. uint32_t id;
  92. /** Status */
  93. uint32_t status;
  94. /** Information buffer length */
  95. uint32_t len;
  96. /** Information buffer offset */
  97. uint32_t offset;
  98. } __attribute__ (( packed ));
  99. /** RNDIS set OID completion */
  100. #define RNDIS_SET_CMPLT 0x80000005UL
  101. /** RNDIS set OID completion */
  102. struct rndis_set_completion {
  103. /** Request ID */
  104. uint32_t id;
  105. /** Status */
  106. uint32_t status;
  107. } __attribute__ (( packed ));
  108. /** RNDIS reset message */
  109. #define RNDIS_RESET_MSG 0x00000006UL
  110. /** RNDIS reset message */
  111. struct rndis_reset_message {
  112. /** Reserved */
  113. uint32_t reserved;
  114. } __attribute__ (( packed ));
  115. /** RNDIS reset completion */
  116. #define RNDIS_RESET_CMPLT 0x80000006UL
  117. /** RNDIS reset completion */
  118. struct rndis_reset_completion {
  119. /** Status */
  120. uint32_t status;
  121. /** Addressing reset */
  122. uint32_t addr;
  123. } __attribute__ (( packed ));
  124. /** RNDIS indicate status message */
  125. #define RNDIS_INDICATE_STATUS_MSG 0x00000007UL
  126. /** RNDIS diagnostic information */
  127. struct rndis_diagnostic_info {
  128. /** Status */
  129. uint32_t status;
  130. /** Error offset */
  131. uint32_t offset;
  132. } __attribute__ (( packed ));
  133. /** RNDIS indicate status message */
  134. struct rndis_indicate_status_message {
  135. /** Status */
  136. uint32_t status;
  137. /** Status buffer length */
  138. uint32_t len;
  139. /** Status buffer offset */
  140. uint32_t offset;
  141. /** Diagnostic information (optional) */
  142. struct rndis_diagnostic_info diag[0];
  143. } __attribute__ (( packed ));
  144. /** RNDIS status codes */
  145. enum rndis_status {
  146. /** Device is connected to a network medium */
  147. RNDIS_STATUS_MEDIA_CONNECT = 0x4001000bUL,
  148. /** Device is disconnected from the medium */
  149. RNDIS_STATUS_MEDIA_DISCONNECT = 0x4001000cUL,
  150. };
  151. /** RNDIS keepalive message */
  152. #define RNDIS_KEEPALIVE_MSG 0x00000008UL
  153. /** RNDIS keepalive message */
  154. struct rndis_keepalive_message {
  155. /** Request ID */
  156. uint32_t id;
  157. } __attribute__ (( packed ));
  158. /** RNDIS keepalive completion */
  159. #define RNDIS_KEEPALIVE_CMPLT 0x80000008UL
  160. /** RNDIS keepalive completion */
  161. struct rndis_keepalive_completion {
  162. /** Request ID */
  163. uint32_t id;
  164. /** Status */
  165. uint32_t status;
  166. } __attribute__ (( packed ));
  167. /** RNDIS packet message */
  168. #define RNDIS_PACKET_MSG 0x00000001UL
  169. /** RNDIS packet field */
  170. struct rndis_packet_field {
  171. /** Offset */
  172. uint32_t offset;
  173. /** Length */
  174. uint32_t len;
  175. } __attribute__ (( packed ));
  176. /** RNDIS packet message */
  177. struct rndis_packet_message {
  178. /** Data */
  179. struct rndis_packet_field data;
  180. /** Out-of-band data records */
  181. struct rndis_packet_field oob;
  182. /** Number of out-of-band data records */
  183. uint32_t oob_count;
  184. /** Per-packet information record */
  185. struct rndis_packet_field ppi;
  186. /** Reserved */
  187. uint32_t reserved;
  188. } __attribute__ (( packed ));
  189. /** RNDIS packet record */
  190. struct rndis_packet_record {
  191. /** Length */
  192. uint32_t len;
  193. /** Type */
  194. uint32_t type;
  195. /** Offset */
  196. uint32_t offset;
  197. } __attribute__ (( packed ));
  198. /** OID for packet filter */
  199. #define RNDIS_OID_GEN_CURRENT_PACKET_FILTER 0x0001010eUL
  200. /** Packet filter bits */
  201. enum rndis_packet_filter {
  202. /** Unicast packets */
  203. RNDIS_FILTER_UNICAST = 0x00000001UL,
  204. /** Multicast packets */
  205. RNDIS_FILTER_MULTICAST = 0x00000002UL,
  206. /** All multicast packets */
  207. RNDIS_FILTER_ALL_MULTICAST = 0x00000004UL,
  208. /** Broadcast packets */
  209. RNDIS_FILTER_BROADCAST = 0x00000008UL,
  210. /** All packets */
  211. RNDIS_FILTER_PROMISCUOUS = 0x00000020UL
  212. };
  213. /** OID for media status */
  214. #define RNDIS_OID_GEN_MEDIA_CONNECT_STATUS 0x00010114UL
  215. /** OID for permanent MAC address */
  216. #define RNDIS_OID_802_3_PERMANENT_ADDRESS 0x01010101UL
  217. /** OID for current MAC address */
  218. #define RNDIS_OID_802_3_CURRENT_ADDRESS 0x01010102UL
  219. struct rndis_device;
  220. /** RNDIS device operations */
  221. struct rndis_operations {
  222. /**
  223. * Open RNDIS device
  224. *
  225. * @v rndis RNDIS device
  226. * @ret rc Return status code
  227. */
  228. int ( * open ) ( struct rndis_device *rndis );
  229. /**
  230. * Close RNDIS device
  231. *
  232. * @v rndis RNDIS device
  233. */
  234. void ( * close ) ( struct rndis_device *rndis );
  235. /**
  236. * Transmit packet
  237. *
  238. * @v rndis RNDIS device
  239. * @v iobuf I/O buffer
  240. * @ret rc Return status code
  241. *
  242. * If this method returns success then the RNDIS device must
  243. * eventually report completion via rndis_tx_complete().
  244. */
  245. int ( * transmit ) ( struct rndis_device *rndis,
  246. struct io_buffer *iobuf );
  247. /**
  248. * Poll for completed and received packets
  249. *
  250. * @v rndis RNDIS device
  251. */
  252. void ( * poll ) ( struct rndis_device *rndis );
  253. };
  254. /** An RNDIS device */
  255. struct rndis_device {
  256. /** Network device */
  257. struct net_device *netdev;
  258. /** Device name */
  259. const char *name;
  260. /** RNDIS operations */
  261. struct rndis_operations *op;
  262. /** Driver private data */
  263. void *priv;
  264. /** Request ID for current blocking request */
  265. unsigned int wait_id;
  266. /** Return status code for current blocking request */
  267. int wait_rc;
  268. };
  269. /**
  270. * Initialise an RNDIS device
  271. *
  272. * @v rndis RNDIS device
  273. * @v op RNDIS device operations
  274. */
  275. static inline void rndis_init ( struct rndis_device *rndis,
  276. struct rndis_operations *op ) {
  277. rndis->op = op;
  278. }
  279. extern void rndis_tx_complete_err ( struct rndis_device *rndis,
  280. struct io_buffer *iobuf, int rc );
  281. extern int rndis_tx_defer ( struct rndis_device *rndis,
  282. struct io_buffer *iobuf );
  283. extern void rndis_rx ( struct rndis_device *rndis, struct io_buffer *iobuf );
  284. extern struct rndis_device * alloc_rndis ( size_t priv_len );
  285. extern int register_rndis ( struct rndis_device *rndis );
  286. extern void unregister_rndis ( struct rndis_device *rndis );
  287. extern void free_rndis ( struct rndis_device *rndis );
  288. /**
  289. * Complete message transmission
  290. *
  291. * @v rndis RNDIS device
  292. * @v iobuf I/O buffer
  293. */
  294. static inline void rndis_tx_complete ( struct rndis_device *rndis,
  295. struct io_buffer *iobuf ) {
  296. rndis_tx_complete_err ( rndis, iobuf, 0 );
  297. }
  298. #endif /* _IPXE_RNDIS_H */