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 8.3KB

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