rndis_host.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * Host Side support for RNDIS Networking Links
  3. * Copyright (C) 2005 by David Brownell
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. // #define DEBUG // error path messages, extra info
  20. // #define VERBOSE // more; success messages
  21. #include <linux/config.h>
  22. #include <linux/module.h>
  23. #include <linux/sched.h>
  24. #include <linux/init.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/etherdevice.h>
  27. #include <linux/ethtool.h>
  28. #include <linux/workqueue.h>
  29. #include <linux/mii.h>
  30. #include <linux/usb.h>
  31. #include <linux/usb_cdc.h>
  32. #include "usbnet.h"
  33. /*
  34. * RNDIS is NDIS remoted over USB. It's a MSFT variant of CDC ACM ... of
  35. * course ACM was intended for modems, not Ethernet links! USB's standard
  36. * for Ethernet links is "CDC Ethernet", which is significantly simpler.
  37. *
  38. * NOTE that Microsoft's "RNDIS 1.0" specification is incomplete. Issues
  39. * include:
  40. * - Power management in particular relies on information that's scattered
  41. * through other documentation, and which is incomplete or incorrect even
  42. * there.
  43. * - There are various undocumented protocol requirements, such as the
  44. * need to send unused garbage in control-OUT messages.
  45. * - In some cases, MS-Windows will emit undocumented requests; this
  46. * matters more to peripheral implementations than host ones.
  47. *
  48. * For these reasons and others, ** USE OF RNDIS IS STRONGLY DISCOURAGED ** in
  49. * favor of such non-proprietary alternatives as CDC Ethernet or the newer (and
  50. * currently rare) "Ethernet Emulation Model" (EEM).
  51. */
  52. /*
  53. * CONTROL uses CDC "encapsulated commands" with funky notifications.
  54. * - control-out: SEND_ENCAPSULATED
  55. * - interrupt-in: RESPONSE_AVAILABLE
  56. * - control-in: GET_ENCAPSULATED
  57. *
  58. * We'll try to ignore the RESPONSE_AVAILABLE notifications.
  59. */
  60. struct rndis_msg_hdr {
  61. __le32 msg_type; /* RNDIS_MSG_* */
  62. __le32 msg_len;
  63. // followed by data that varies between messages
  64. __le32 request_id;
  65. __le32 status;
  66. // ... and more
  67. } __attribute__ ((packed));
  68. /* RNDIS defines this (absurdly huge) control timeout */
  69. #define RNDIS_CONTROL_TIMEOUT_MS (10 * 1000)
  70. #define ccpu2 __constant_cpu_to_le32
  71. #define RNDIS_MSG_COMPLETION ccpu2(0x80000000)
  72. /* codes for "msg_type" field of rndis messages;
  73. * only the data channel uses packet messages (maybe batched);
  74. * everything else goes on the control channel.
  75. */
  76. #define RNDIS_MSG_PACKET ccpu2(0x00000001) /* 1-N packets */
  77. #define RNDIS_MSG_INIT ccpu2(0x00000002)
  78. #define RNDIS_MSG_INIT_C (RNDIS_MSG_INIT|RNDIS_MSG_COMPLETION)
  79. #define RNDIS_MSG_HALT ccpu2(0x00000003)
  80. #define RNDIS_MSG_QUERY ccpu2(0x00000004)
  81. #define RNDIS_MSG_QUERY_C (RNDIS_MSG_QUERY|RNDIS_MSG_COMPLETION)
  82. #define RNDIS_MSG_SET ccpu2(0x00000005)
  83. #define RNDIS_MSG_SET_C (RNDIS_MSG_SET|RNDIS_MSG_COMPLETION)
  84. #define RNDIS_MSG_RESET ccpu2(0x00000006)
  85. #define RNDIS_MSG_RESET_C (RNDIS_MSG_RESET|RNDIS_MSG_COMPLETION)
  86. #define RNDIS_MSG_INDICATE ccpu2(0x00000007)
  87. #define RNDIS_MSG_KEEPALIVE ccpu2(0x00000008)
  88. #define RNDIS_MSG_KEEPALIVE_C (RNDIS_MSG_KEEPALIVE|RNDIS_MSG_COMPLETION)
  89. /* codes for "status" field of completion messages */
  90. #define RNDIS_STATUS_SUCCESS ccpu2(0x00000000)
  91. #define RNDIS_STATUS_FAILURE ccpu2(0xc0000001)
  92. #define RNDIS_STATUS_INVALID_DATA ccpu2(0xc0010015)
  93. #define RNDIS_STATUS_NOT_SUPPORTED ccpu2(0xc00000bb)
  94. #define RNDIS_STATUS_MEDIA_CONNECT ccpu2(0x4001000b)
  95. #define RNDIS_STATUS_MEDIA_DISCONNECT ccpu2(0x4001000c)
  96. struct rndis_data_hdr {
  97. __le32 msg_type; /* RNDIS_MSG_PACKET */
  98. __le32 msg_len; // rndis_data_hdr + data_len + pad
  99. __le32 data_offset; // 36 -- right after header
  100. __le32 data_len; // ... real packet size
  101. __le32 oob_data_offset; // zero
  102. __le32 oob_data_len; // zero
  103. __le32 num_oob; // zero
  104. __le32 packet_data_offset; // zero
  105. __le32 packet_data_len; // zero
  106. __le32 vc_handle; // zero
  107. __le32 reserved; // zero
  108. } __attribute__ ((packed));
  109. struct rndis_init { /* OUT */
  110. // header and:
  111. __le32 msg_type; /* RNDIS_MSG_INIT */
  112. __le32 msg_len; // 24
  113. __le32 request_id;
  114. __le32 major_version; // of rndis (1.0)
  115. __le32 minor_version;
  116. __le32 max_transfer_size;
  117. } __attribute__ ((packed));
  118. struct rndis_init_c { /* IN */
  119. // header and:
  120. __le32 msg_type; /* RNDIS_MSG_INIT_C */
  121. __le32 msg_len;
  122. __le32 request_id;
  123. __le32 status;
  124. __le32 major_version; // of rndis (1.0)
  125. __le32 minor_version;
  126. __le32 device_flags;
  127. __le32 medium; // zero == 802.3
  128. __le32 max_packets_per_message;
  129. __le32 max_transfer_size;
  130. __le32 packet_alignment; // max 7; (1<<n) bytes
  131. __le32 af_list_offset; // zero
  132. __le32 af_list_size; // zero
  133. } __attribute__ ((packed));
  134. struct rndis_halt { /* OUT (no reply) */
  135. // header and:
  136. __le32 msg_type; /* RNDIS_MSG_HALT */
  137. __le32 msg_len;
  138. __le32 request_id;
  139. } __attribute__ ((packed));
  140. struct rndis_query { /* OUT */
  141. // header and:
  142. __le32 msg_type; /* RNDIS_MSG_QUERY */
  143. __le32 msg_len;
  144. __le32 request_id;
  145. __le32 oid;
  146. __le32 len;
  147. __le32 offset;
  148. /*?*/ __le32 handle; // zero
  149. } __attribute__ ((packed));
  150. struct rndis_query_c { /* IN */
  151. // header and:
  152. __le32 msg_type; /* RNDIS_MSG_QUERY_C */
  153. __le32 msg_len;
  154. __le32 request_id;
  155. __le32 status;
  156. __le32 len;
  157. __le32 offset;
  158. } __attribute__ ((packed));
  159. struct rndis_set { /* OUT */
  160. // header and:
  161. __le32 msg_type; /* RNDIS_MSG_SET */
  162. __le32 msg_len;
  163. __le32 request_id;
  164. __le32 oid;
  165. __le32 len;
  166. __le32 offset;
  167. /*?*/ __le32 handle; // zero
  168. } __attribute__ ((packed));
  169. struct rndis_set_c { /* IN */
  170. // header and:
  171. __le32 msg_type; /* RNDIS_MSG_SET_C */
  172. __le32 msg_len;
  173. __le32 request_id;
  174. __le32 status;
  175. } __attribute__ ((packed));
  176. struct rndis_reset { /* IN */
  177. // header and:
  178. __le32 msg_type; /* RNDIS_MSG_RESET */
  179. __le32 msg_len;
  180. __le32 reserved;
  181. } __attribute__ ((packed));
  182. struct rndis_reset_c { /* OUT */
  183. // header and:
  184. __le32 msg_type; /* RNDIS_MSG_RESET_C */
  185. __le32 msg_len;
  186. __le32 status;
  187. __le32 addressing_lost;
  188. } __attribute__ ((packed));
  189. struct rndis_indicate { /* IN (unrequested) */
  190. // header and:
  191. __le32 msg_type; /* RNDIS_MSG_INDICATE */
  192. __le32 msg_len;
  193. __le32 status;
  194. __le32 length;
  195. __le32 offset;
  196. /**/ __le32 diag_status;
  197. __le32 error_offset;
  198. /**/ __le32 message;
  199. } __attribute__ ((packed));
  200. struct rndis_keepalive { /* OUT (optionally IN) */
  201. // header and:
  202. __le32 msg_type; /* RNDIS_MSG_KEEPALIVE */
  203. __le32 msg_len;
  204. __le32 request_id;
  205. } __attribute__ ((packed));
  206. struct rndis_keepalive_c { /* IN (optionally OUT) */
  207. // header and:
  208. __le32 msg_type; /* RNDIS_MSG_KEEPALIVE_C */
  209. __le32 msg_len;
  210. __le32 request_id;
  211. __le32 status;
  212. } __attribute__ ((packed));
  213. /* NOTE: about 30 OIDs are "mandatory" for peripherals to support ... and
  214. * there are gobs more that may optionally be supported. We'll avoid as much
  215. * of that mess as possible.
  216. */
  217. #define OID_802_3_PERMANENT_ADDRESS ccpu2(0x01010101)
  218. #define OID_GEN_CURRENT_PACKET_FILTER ccpu2(0x0001010e)
  219. /*
  220. * RNDIS notifications from device: command completion; "reverse"
  221. * keepalives; etc
  222. */
  223. static void rndis_status(struct usbnet *dev, struct urb *urb)
  224. {
  225. devdbg(dev, "rndis status urb, len %d stat %d",
  226. urb->actual_length, urb->status);
  227. // FIXME for keepalives, respond immediately (asynchronously)
  228. // if not an RNDIS status, do like cdc_status(dev,urb) does
  229. }
  230. /*
  231. * RPC done RNDIS-style. Caller guarantees:
  232. * - message is properly byteswapped
  233. * - there's no other request pending
  234. * - buf can hold up to 1KB response (required by RNDIS spec)
  235. * On return, the first few entries are already byteswapped.
  236. *
  237. * Call context is likely probe(), before interface name is known,
  238. * which is why we won't try to use it in the diagnostics.
  239. */
  240. static int rndis_command(struct usbnet *dev, struct rndis_msg_hdr *buf)
  241. {
  242. struct cdc_state *info = (void *) &dev->data;
  243. int retval;
  244. unsigned count;
  245. __le32 rsp;
  246. u32 xid = 0, msg_len, request_id;
  247. /* REVISIT when this gets called from contexts other than probe() or
  248. * disconnect(): either serialize, or dispatch responses on xid
  249. */
  250. /* Issue the request; don't bother byteswapping our xid */
  251. if (likely(buf->msg_type != RNDIS_MSG_HALT
  252. && buf->msg_type != RNDIS_MSG_RESET)) {
  253. xid = dev->xid++;
  254. if (!xid)
  255. xid = dev->xid++;
  256. buf->request_id = (__force __le32) xid;
  257. }
  258. retval = usb_control_msg(dev->udev,
  259. usb_sndctrlpipe(dev->udev, 0),
  260. USB_CDC_SEND_ENCAPSULATED_COMMAND,
  261. USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  262. 0, info->u->bMasterInterface0,
  263. buf, le32_to_cpu(buf->msg_len),
  264. RNDIS_CONTROL_TIMEOUT_MS);
  265. if (unlikely(retval < 0 || xid == 0))
  266. return retval;
  267. // FIXME Seems like some devices discard responses when
  268. // we time out and cancel our "get response" requests...
  269. // so, this is fragile. Probably need to poll for status.
  270. /* ignore status endpoint, just poll the control channel;
  271. * the request probably completed immediately
  272. */
  273. rsp = buf->msg_type | RNDIS_MSG_COMPLETION;
  274. for (count = 0; count < 10; count++) {
  275. memset(buf, 0, 1024);
  276. retval = usb_control_msg(dev->udev,
  277. usb_rcvctrlpipe(dev->udev, 0),
  278. USB_CDC_GET_ENCAPSULATED_RESPONSE,
  279. USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  280. 0, info->u->bMasterInterface0,
  281. buf, 1024,
  282. RNDIS_CONTROL_TIMEOUT_MS);
  283. if (likely(retval >= 8)) {
  284. msg_len = le32_to_cpu(buf->msg_len);
  285. request_id = (__force u32) buf->request_id;
  286. if (likely(buf->msg_type == rsp)) {
  287. if (likely(request_id == xid)) {
  288. if (unlikely(rsp == RNDIS_MSG_RESET_C))
  289. return 0;
  290. if (likely(RNDIS_STATUS_SUCCESS
  291. == buf->status))
  292. return 0;
  293. dev_dbg(&info->control->dev,
  294. "rndis reply status %08x\n",
  295. le32_to_cpu(buf->status));
  296. return -EL3RST;
  297. }
  298. dev_dbg(&info->control->dev,
  299. "rndis reply id %d expected %d\n",
  300. request_id, xid);
  301. /* then likely retry */
  302. } else switch (buf->msg_type) {
  303. case RNDIS_MSG_INDICATE: { /* fault */
  304. // struct rndis_indicate *msg = (void *)buf;
  305. dev_info(&info->control->dev,
  306. "rndis fault indication\n");
  307. }
  308. break;
  309. case RNDIS_MSG_KEEPALIVE: { /* ping */
  310. struct rndis_keepalive_c *msg = (void *)buf;
  311. msg->msg_type = RNDIS_MSG_KEEPALIVE_C;
  312. msg->msg_len = ccpu2(sizeof *msg);
  313. msg->status = RNDIS_STATUS_SUCCESS;
  314. retval = usb_control_msg(dev->udev,
  315. usb_sndctrlpipe(dev->udev, 0),
  316. USB_CDC_SEND_ENCAPSULATED_COMMAND,
  317. USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  318. 0, info->u->bMasterInterface0,
  319. msg, sizeof *msg,
  320. RNDIS_CONTROL_TIMEOUT_MS);
  321. if (unlikely(retval < 0))
  322. dev_dbg(&info->control->dev,
  323. "rndis keepalive err %d\n",
  324. retval);
  325. }
  326. break;
  327. default:
  328. dev_dbg(&info->control->dev,
  329. "unexpected rndis msg %08x len %d\n",
  330. le32_to_cpu(buf->msg_type), msg_len);
  331. }
  332. } else {
  333. /* device probably issued a protocol stall; ignore */
  334. dev_dbg(&info->control->dev,
  335. "rndis response error, code %d\n", retval);
  336. }
  337. msleep(2);
  338. }
  339. dev_dbg(&info->control->dev, "rndis response timeout\n");
  340. return -ETIMEDOUT;
  341. }
  342. static int rndis_bind(struct usbnet *dev, struct usb_interface *intf)
  343. {
  344. int retval;
  345. struct net_device *net = dev->net;
  346. union {
  347. void *buf;
  348. struct rndis_msg_hdr *header;
  349. struct rndis_init *init;
  350. struct rndis_init_c *init_c;
  351. struct rndis_query *get;
  352. struct rndis_query_c *get_c;
  353. struct rndis_set *set;
  354. struct rndis_set_c *set_c;
  355. } u;
  356. u32 tmp;
  357. /* we can't rely on i/o from stack working, or stack allocation */
  358. u.buf = kmalloc(1024, GFP_KERNEL);
  359. if (!u.buf)
  360. return -ENOMEM;
  361. retval = usbnet_generic_cdc_bind(dev, intf);
  362. if (retval < 0)
  363. goto done;
  364. net->hard_header_len += sizeof (struct rndis_data_hdr);
  365. /* initialize; max transfer is 16KB at full speed */
  366. u.init->msg_type = RNDIS_MSG_INIT;
  367. u.init->msg_len = ccpu2(sizeof *u.init);
  368. u.init->major_version = ccpu2(1);
  369. u.init->minor_version = ccpu2(0);
  370. u.init->max_transfer_size = ccpu2(net->mtu + net->hard_header_len);
  371. retval = rndis_command(dev, u.header);
  372. if (unlikely(retval < 0)) {
  373. /* it might not even be an RNDIS device!! */
  374. dev_err(&intf->dev, "RNDIS init failed, %d\n", retval);
  375. fail:
  376. usb_driver_release_interface(driver_of(intf),
  377. ((struct cdc_state *)&(dev->data))->data);
  378. goto done;
  379. }
  380. dev->hard_mtu = le32_to_cpu(u.init_c->max_transfer_size);
  381. /* REVISIT: peripheral "alignment" request is ignored ... */
  382. dev_dbg(&intf->dev, "hard mtu %u, align %d\n", dev->hard_mtu,
  383. 1 << le32_to_cpu(u.init_c->packet_alignment));
  384. /* get designated host ethernet address */
  385. memset(u.get, 0, sizeof *u.get);
  386. u.get->msg_type = RNDIS_MSG_QUERY;
  387. u.get->msg_len = ccpu2(sizeof *u.get);
  388. u.get->oid = OID_802_3_PERMANENT_ADDRESS;
  389. retval = rndis_command(dev, u.header);
  390. if (unlikely(retval < 0)) {
  391. dev_err(&intf->dev, "rndis get ethaddr, %d\n", retval);
  392. goto fail;
  393. }
  394. tmp = le32_to_cpu(u.get_c->offset);
  395. if (unlikely((tmp + 8) > (1024 - ETH_ALEN)
  396. || u.get_c->len != ccpu2(ETH_ALEN))) {
  397. dev_err(&intf->dev, "rndis ethaddr off %d len %d ?\n",
  398. tmp, le32_to_cpu(u.get_c->len));
  399. retval = -EDOM;
  400. goto fail;
  401. }
  402. memcpy(net->dev_addr, tmp + (char *)&u.get_c->request_id, ETH_ALEN);
  403. /* set a nonzero filter to enable data transfers */
  404. memset(u.set, 0, sizeof *u.set);
  405. u.set->msg_type = RNDIS_MSG_SET;
  406. u.set->msg_len = ccpu2(4 + sizeof *u.set);
  407. u.set->oid = OID_GEN_CURRENT_PACKET_FILTER;
  408. u.set->len = ccpu2(4);
  409. u.set->offset = ccpu2((sizeof *u.set) - 8);
  410. *(__le32 *)(u.buf + sizeof *u.set) = ccpu2(DEFAULT_FILTER);
  411. retval = rndis_command(dev, u.header);
  412. if (unlikely(retval < 0)) {
  413. dev_err(&intf->dev, "rndis set packet filter, %d\n", retval);
  414. goto fail;
  415. }
  416. retval = 0;
  417. done:
  418. kfree(u.buf);
  419. return retval;
  420. }
  421. static void rndis_unbind(struct usbnet *dev, struct usb_interface *intf)
  422. {
  423. struct rndis_halt *halt;
  424. /* try to clear any rndis state/activity (no i/o from stack!) */
  425. halt = kcalloc(1, sizeof *halt, SLAB_KERNEL);
  426. if (halt) {
  427. halt->msg_type = RNDIS_MSG_HALT;
  428. halt->msg_len = ccpu2(sizeof *halt);
  429. (void) rndis_command(dev, (void *)halt);
  430. kfree(halt);
  431. }
  432. return usbnet_cdc_unbind(dev, intf);
  433. }
  434. /*
  435. * DATA -- host must not write zlps
  436. */
  437. static int rndis_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
  438. {
  439. /* peripheral may have batched packets to us... */
  440. while (likely(skb->len)) {
  441. struct rndis_data_hdr *hdr = (void *)skb->data;
  442. struct sk_buff *skb2;
  443. u32 msg_len, data_offset, data_len;
  444. msg_len = le32_to_cpu(hdr->msg_len);
  445. data_offset = le32_to_cpu(hdr->data_offset);
  446. data_len = le32_to_cpu(hdr->data_len);
  447. /* don't choke if we see oob, per-packet data, etc */
  448. if (unlikely(hdr->msg_type != RNDIS_MSG_PACKET
  449. || skb->len < msg_len
  450. || (data_offset + data_len + 8) > msg_len)) {
  451. dev->stats.rx_frame_errors++;
  452. devdbg(dev, "bad rndis message %d/%d/%d/%d, len %d",
  453. le32_to_cpu(hdr->msg_type),
  454. msg_len, data_offset, data_len, skb->len);
  455. return 0;
  456. }
  457. skb_pull(skb, 8 + data_offset);
  458. /* at most one packet left? */
  459. if (likely((data_len - skb->len) <= sizeof *hdr)) {
  460. skb_trim(skb, data_len);
  461. break;
  462. }
  463. /* try to return all the packets in the batch */
  464. skb2 = skb_clone(skb, GFP_ATOMIC);
  465. if (unlikely(!skb2))
  466. break;
  467. skb_pull(skb, msg_len - sizeof *hdr);
  468. skb_trim(skb2, data_len);
  469. usbnet_skb_return(dev, skb2);
  470. }
  471. /* caller will usbnet_skb_return the remaining packet */
  472. return 1;
  473. }
  474. static struct sk_buff *
  475. rndis_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
  476. {
  477. struct rndis_data_hdr *hdr;
  478. struct sk_buff *skb2;
  479. unsigned len = skb->len;
  480. if (likely(!skb_cloned(skb))) {
  481. int room = skb_headroom(skb);
  482. /* enough head room as-is? */
  483. if (unlikely((sizeof *hdr) <= room))
  484. goto fill;
  485. /* enough room, but needs to be readjusted? */
  486. room += skb_tailroom(skb);
  487. if (likely((sizeof *hdr) <= room)) {
  488. skb->data = memmove(skb->head + sizeof *hdr,
  489. skb->data, len);
  490. skb->tail = skb->data + len;
  491. goto fill;
  492. }
  493. }
  494. /* create a new skb, with the correct size (and tailpad) */
  495. skb2 = skb_copy_expand(skb, sizeof *hdr, 1, flags);
  496. dev_kfree_skb_any(skb);
  497. if (unlikely(!skb2))
  498. return skb2;
  499. skb = skb2;
  500. /* fill out the RNDIS header. we won't bother trying to batch
  501. * packets; Linux minimizes wasted bandwidth through tx queues.
  502. */
  503. fill:
  504. hdr = (void *) __skb_push(skb, sizeof *hdr);
  505. memset(hdr, 0, sizeof *hdr);
  506. hdr->msg_type = RNDIS_MSG_PACKET;
  507. hdr->msg_len = cpu_to_le32(skb->len);
  508. hdr->data_offset = ccpu2(sizeof(*hdr) - 8);
  509. hdr->data_len = cpu_to_le32(len);
  510. /* FIXME make the last packet always be short ... */
  511. return skb;
  512. }
  513. static const struct driver_info rndis_info = {
  514. .description = "RNDIS device",
  515. .flags = FLAG_ETHER | FLAG_FRAMING_RN,
  516. .bind = rndis_bind,
  517. .unbind = rndis_unbind,
  518. .status = rndis_status,
  519. .rx_fixup = rndis_rx_fixup,
  520. .tx_fixup = rndis_tx_fixup,
  521. };
  522. #undef ccpu2
  523. /*-------------------------------------------------------------------------*/
  524. static const struct usb_device_id products [] = {
  525. {
  526. /* RNDIS is MSFT's un-official variant of CDC ACM */
  527. USB_INTERFACE_INFO(USB_CLASS_COMM, 2 /* ACM */, 0x0ff),
  528. .driver_info = (unsigned long) &rndis_info,
  529. },
  530. { }, // END
  531. };
  532. MODULE_DEVICE_TABLE(usb, products);
  533. static struct usb_driver rndis_driver = {
  534. .name = "rndis_host",
  535. .id_table = products,
  536. .probe = usbnet_probe,
  537. .disconnect = usbnet_disconnect,
  538. .suspend = usbnet_suspend,
  539. .resume = usbnet_resume,
  540. };
  541. static int __init rndis_init(void)
  542. {
  543. return usb_register(&rndis_driver);
  544. }
  545. module_init(rndis_init);
  546. static void __exit rndis_exit(void)
  547. {
  548. usb_deregister(&rndis_driver);
  549. }
  550. module_exit(rndis_exit);
  551. MODULE_AUTHOR("David Brownell");
  552. MODULE_DESCRIPTION("USB Host side RNDIS driver");
  553. MODULE_LICENSE("GPL");