rndis_host.c 17 KB

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