iPXE
Functions | Variables
acm.c File Reference

USB RNDIS driver. More...

#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/profile.h>
#include <ipxe/usb.h>
#include <ipxe/usbnet.h>
#include <ipxe/rndis.h>
#include "acm.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static void acm_intr_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete interrupt transfer. More...
 
static void acm_in_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk IN transfer. More...
 
static int acm_out_transmit (struct acm_device *acm, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void acm_out_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete bulk OUT transfer. More...
 
static int acm_control_transmit (struct acm_device *acm, struct io_buffer *iobuf)
 Send control packet. More...
 
static int acm_control_receive (struct acm_device *acm)
 Receive control packet. More...
 
static int acm_open (struct rndis_device *rndis)
 Open RNDIS device. More...
 
static void acm_close (struct rndis_device *rndis)
 Close RNDIS device. More...
 
static int acm_transmit (struct rndis_device *rndis, struct io_buffer *iobuf)
 Transmit packet. More...
 
static void acm_poll (struct rndis_device *rndis)
 Poll for completed and received packets. More...
 
static int acm_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe device. More...
 
static void acm_remove (struct usb_function *func)
 Remove device. More...
 

Variables

static struct profiler acm_intr_profiler __profiler
 Interrupt completion profiler. More...
 
static struct usb_endpoint_driver_operations acm_intr_operations
 Interrupt endpoint operations. More...
 
static struct usb_endpoint_driver_operations acm_in_operations
 Bulk IN endpoint operations. More...
 
static struct usb_endpoint_driver_operations acm_out_operations
 Bulk OUT endpoint operations. More...
 
static struct rndis_operations acm_operations
 USB RNDIS operations. More...
 
static struct usb_device_id cdc_acm_ids []
 USB CDC-ACM device IDs. More...
 
struct usb_driver cdc_acm_driver __usb_driver
 USB CDC-ACM driver. More...
 
static struct usb_device_id rf_rndis_ids []
 USB RF-RNDIS device IDs. More...
 

Detailed Description

USB RNDIS driver.

Definition in file acm.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ acm_intr_complete()

static void acm_intr_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete interrupt transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 68 of file acm.c.

69  {
70  struct acm_device *acm = container_of ( ep, struct acm_device,
71  usbnet.intr );
72  struct rndis_device *rndis = acm->rndis;
73  struct usb_setup_packet *message;
74 
75  /* Profile completions */
76  profile_start ( &acm_intr_profiler );
77 
78  /* Ignore packets cancelled when the endpoint closes */
79  if ( ! ep->open )
80  goto ignore;
81 
82  /* Drop packets with errors */
83  if ( rc != 0 ) {
84  DBGC ( acm, "ACM %p interrupt failed: %s\n",
85  acm, strerror ( rc ) );
86  DBGC_HDA ( acm, 0, iobuf->data, iob_len ( iobuf ) );
87  goto error;
88  }
89 
90  /* Extract message header */
91  if ( iob_len ( iobuf ) < sizeof ( *message ) ) {
92  DBGC ( acm, "ACM %p underlength interrupt:\n", acm );
93  DBGC_HDA ( acm, 0, iobuf->data, iob_len ( iobuf ) );
94  rc = -EINVAL;
95  goto error;
96  }
97  message = iobuf->data;
98 
99  /* Parse message header */
100  switch ( message->request ) {
101 
103  case cpu_to_le16 ( 0x0001 ) : /* qemu seems to use this value */
104  acm->responded = 1;
105  break;
106 
107  default:
108  DBGC ( acm, "ACM %p unrecognised interrupt:\n", acm );
109  DBGC_HDA ( acm, 0, iobuf->data, iob_len ( iobuf ) );
110  rc = -ENOTSUP;
111  goto error;
112  }
113 
114  /* Free I/O buffer */
115  free_iob ( iobuf );
116  profile_stop ( &acm_intr_profiler );
117 
118  return;
119 
120  error:
121  rndis_rx_err ( rndis, iob_disown ( iobuf ), rc );
122  ignore:
123  free_iob ( iobuf );
124  return;
125 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define CDC_RESPONSE_AVAILABLE
Response available.
Definition: cdc.h:44
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:404
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define DBGC_HDA(...)
Definition: compiler.h:506
An RNDIS device.
Definition: rndis.h:317
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
void rndis_rx_err(struct rndis_device *rndis, struct io_buffer *iobuf, int rc)
Discard packet from underlying transport layer.
Definition: rndis.c:866
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
A USB RNDIS network device.
Definition: acm.h:31
A USB setup data packet.
Definition: usb.h:68
void * data
Start of data.
Definition: iobuf.h:44
#define cpu_to_le16(value)
Definition: byteswap.h:106
char message[VMCONSOLE_BUFSIZE]
Definition: vmconsole.c:54
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References CDC_RESPONSE_AVAILABLE, container_of, cpu_to_le16, io_buffer::data, DBGC, DBGC_HDA, EINVAL, ENOTSUP, error, free_iob(), usbnet_device::intr, iob_disown, iob_len(), message, usb_endpoint::open, profile_start(), profile_stop(), rc, acm_device::responded, acm_device::rndis, rndis_rx_err(), strerror(), and acm_device::usbnet.

◆ acm_in_complete()

static void acm_in_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk IN transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 146 of file acm.c.

147  {
148  struct acm_device *acm = container_of ( ep, struct acm_device,
149  usbnet.in );
150  struct rndis_device *rndis = acm->rndis;
151 
152  /* Profile receive completions */
153  profile_start ( &acm_in_profiler );
154 
155  /* Ignore packets cancelled when the endpoint closes */
156  if ( ! ep->open )
157  goto ignore;
158 
159  /* Record USB errors against the RNDIS device */
160  if ( rc != 0 ) {
161  DBGC ( acm, "ACM %p bulk IN failed: %s\n",
162  acm, strerror ( rc ) );
163  goto error;
164  }
165 
166  /* Hand off to RNDIS */
167  rndis_rx ( rndis, iob_disown ( iobuf ) );
168 
169  profile_stop ( &acm_in_profiler );
170  return;
171 
172  error:
173  rndis_rx_err ( rndis, iob_disown ( iobuf ), rc );
174  ignore:
175  free_iob ( iobuf );
176 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
struct arbelprm_completion_with_error error
Definition: arbel.h:12
#define DBGC(...)
Definition: compiler.h:505
int open
Endpoint is open.
Definition: usb.h:404
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An RNDIS device.
Definition: rndis.h:317
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158
void rndis_rx_err(struct rndis_device *rndis, struct io_buffer *iobuf, int rc)
Discard packet from underlying transport layer.
Definition: rndis.c:866
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
A USB RNDIS network device.
Definition: acm.h:31
void rndis_rx(struct rndis_device *rndis, struct io_buffer *iobuf)
Receive packet from underlying transport layer.
Definition: rndis.c:829
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References container_of, DBGC, error, free_iob(), usbnet_device::in, iob_disown, usb_endpoint::open, profile_start(), profile_stop(), rc, acm_device::rndis, rndis_rx(), rndis_rx_err(), strerror(), and acm_device::usbnet.

◆ acm_out_transmit()

static int acm_out_transmit ( struct acm_device acm,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
acmUSB RNDIS device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 190 of file acm.c.

191  {
192  int rc;
193 
194  /* Profile transmissions */
195  profile_start ( &acm_out_profiler );
196 
197  /* Enqueue I/O buffer */
198  if ( ( rc = usb_stream ( &acm->usbnet.out, iobuf, 0 ) ) != 0 )
199  return rc;
200 
201  profile_stop ( &acm_out_profiler );
202  return 0;
203 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:528
static void profile_stop(struct profiler *profiler)
Stop profiling.
Definition: profile.h:171
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
static void profile_start(struct profiler *profiler)
Start profiling.
Definition: profile.h:158

References usbnet_device::out, profile_start(), profile_stop(), rc, usb_stream(), and acm_device::usbnet.

Referenced by acm_transmit().

◆ acm_out_complete()

static void acm_out_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete bulk OUT transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 212 of file acm.c.

213  {
214  struct acm_device *acm = container_of ( ep, struct acm_device,
215  usbnet.out );
216  struct rndis_device *rndis = acm->rndis;
217 
218  /* Report TX completion */
219  rndis_tx_complete_err ( rndis, iobuf, rc );
220 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
struct usb_endpoint out
Bulk OUT endpoint.
Definition: usbnet.h:31
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An RNDIS device.
Definition: rndis.h:317
A USB RNDIS network device.
Definition: acm.h:31
void rndis_tx_complete_err(struct rndis_device *rndis, struct io_buffer *iobuf, int rc)
Complete message transmission.
Definition: rndis.c:127
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References container_of, usbnet_device::out, rc, acm_device::rndis, rndis_tx_complete_err(), and acm_device::usbnet.

◆ acm_control_transmit()

static int acm_control_transmit ( struct acm_device acm,
struct io_buffer iobuf 
)
static

Send control packet.

Parameters
acmUSB RNDIS device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 241 of file acm.c.

242  {
243  struct rndis_device *rndis = acm->rndis;
244  struct usb_device *usb = acm->usb;
245  int rc;
246 
247  /* Send packet as an encapsulated command */
248  if ( ( rc = cdc_send_encapsulated_command ( usb, acm->usbnet.comms,
249  iobuf->data,
250  iob_len ( iobuf ) ) ) != 0){
251  DBGC ( acm, "ACM %p could not send encapsulated command: %s\n",
252  acm, strerror ( rc ) );
253  return rc;
254  }
255 
256  /* Complete packet immediately */
257  rndis_tx_complete ( rndis, iobuf );
258 
259  return 0;
260 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int comms
Communications interface.
Definition: usbnet.h:20
static void rndis_tx_complete(struct rndis_device *rndis, struct io_buffer *iobuf)
Complete message transmission.
Definition: rndis.h:364
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
#define DBGC(...)
Definition: compiler.h:505
An RNDIS device.
Definition: rndis.h:317
static int cdc_send_encapsulated_command(struct usb_device *usb, unsigned int interface, void *data, size_t len)
Send encapsulated command.
Definition: cdc.h:80
struct usb_device * usb
USB device.
Definition: acm.h:33
A USB device.
Definition: usb.h:706
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
void * data
Start of data.
Definition: iobuf.h:44
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References cdc_send_encapsulated_command(), usbnet_device::comms, io_buffer::data, DBGC, iob_len(), rc, acm_device::rndis, rndis_tx_complete(), strerror(), acm_device::usb, and acm_device::usbnet.

Referenced by acm_transmit().

◆ acm_control_receive()

static int acm_control_receive ( struct acm_device acm)
static

Receive control packet.

Parameters
acmUSB RNDIS device
Return values
rcReturn status code

Definition at line 268 of file acm.c.

268  {
269  struct rndis_device *rndis = acm->rndis;
270  struct usb_device *usb = acm->usb;
271  struct io_buffer *iobuf;
272  struct rndis_header *header;
273  size_t mtu = ACM_RESPONSE_MTU;
274  size_t len;
275  int rc;
276 
277  /* Allocate I/O buffer */
278  iobuf = alloc_iob ( mtu );
279  if ( ! iobuf ) {
280  rc = -ENOMEM;
281  goto err_alloc;
282  }
283 
284  /* Get encapsulated response */
285  if ( ( rc = cdc_get_encapsulated_response ( usb, acm->usbnet.comms,
286  iobuf->data, mtu ) ) != 0 ){
287  DBGC ( acm, "ACM %p could not get encapsulated response: %s\n",
288  acm, strerror ( rc ) );
289  goto err_get_response;
290  }
291 
292  /* Fix up buffer length */
293  header = iobuf->data;
294  len = le32_to_cpu ( header->len );
295  if ( len > mtu ) {
296  DBGC ( acm, "ACM %p overlength encapsulated response\n", acm );
297  DBGC_HDA ( acm, 0, iobuf->data, mtu );
298  rc = -EPROTO;
299  goto err_len;
300  }
301  iob_put ( iobuf, len );
302 
303  /* Hand off to RNDIS */
304  rndis_rx ( rndis, iob_disown ( iobuf ) );
305 
306  return 0;
307 
308  err_len:
309  err_get_response:
310  free_iob ( iobuf );
311  err_alloc:
312  return rc;
313 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define ACM_RESPONSE_MTU
Encapsulated response buffer size.
Definition: acm.h:67
#define iob_put(iobuf, len)
Definition: iobuf.h:116
unsigned int comms
Communications interface.
Definition: usbnet.h:20
#define le32_to_cpu(value)
Definition: byteswap.h:113
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
#define DBGC(...)
Definition: compiler.h:505
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:128
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
static int cdc_get_encapsulated_response(struct usb_device *usb, unsigned int interface, void *data, size_t len)
Get encapsulated response.
Definition: cdc.h:97
#define DBGC_HDA(...)
Definition: compiler.h:506
An RNDIS device.
Definition: rndis.h:317
struct usb_device * usb
USB device.
Definition: acm.h:33
A USB device.
Definition: usb.h:706
#define EPROTO
Protocol error.
Definition: errno.h:624
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
void rndis_rx(struct rndis_device *rndis, struct io_buffer *iobuf)
Receive packet from underlying transport layer.
Definition: rndis.c:829
RNDIS message header.
Definition: rndis.h:23
uint32_t len
Length.
Definition: ena.h:14
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
void * data
Start of data.
Definition: iobuf.h:44
struct ena_aq_header header
Header.
Definition: ena.h:12
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37
A persistent I/O buffer.
Definition: iobuf.h:32

References ACM_RESPONSE_MTU, alloc_iob(), cdc_get_encapsulated_response(), usbnet_device::comms, io_buffer::data, DBGC, DBGC_HDA, ENOMEM, EPROTO, free_iob(), header, iob_disown, iob_put, le32_to_cpu, len, mtu, rc, acm_device::rndis, rndis_rx(), strerror(), acm_device::usb, and acm_device::usbnet.

Referenced by acm_poll().

◆ acm_open()

static int acm_open ( struct rndis_device rndis)
static

Open RNDIS device.

Parameters
rndisRNDIS device
Return values
rcReturn status code

Definition at line 328 of file acm.c.

328  {
329  struct acm_device *acm = rndis->priv;
330  int rc;
331 
332  /* Open USB network device */
333  if ( ( rc = usbnet_open ( &acm->usbnet ) ) != 0 )
334  goto err_open;
335 
336  return 0;
337 
338  usbnet_close ( &acm->usbnet );
339  err_open:
340  return rc;
341 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
A USB RNDIS network device.
Definition: acm.h:31
void * priv
Driver private data.
Definition: rndis.h:325
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37
int usbnet_open(struct usbnet_device *usbnet)
Open USB network device.
Definition: usbnet.c:54

References rndis_device::priv, rc, acm_device::rndis, acm_device::usbnet, usbnet_close(), and usbnet_open().

◆ acm_close()

static void acm_close ( struct rndis_device rndis)
static

Close RNDIS device.

Parameters
rndisRNDIS device

Definition at line 348 of file acm.c.

348  {
349  struct acm_device *acm = rndis->priv;
350 
351  /* Close USB network device */
352  usbnet_close ( &acm->usbnet );
353 }
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
A USB RNDIS network device.
Definition: acm.h:31
void * priv
Driver private data.
Definition: rndis.h:325
void usbnet_close(struct usbnet_device *usbnet)
Close USB network device.
Definition: usbnet.c:127
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References rndis_device::priv, acm_device::rndis, acm_device::usbnet, and usbnet_close().

◆ acm_transmit()

static int acm_transmit ( struct rndis_device rndis,
struct io_buffer iobuf 
)
static

Transmit packet.

Parameters
rndisRNDIS device
iobufI/O buffer
Return values
rcReturn status code

Definition at line 362 of file acm.c.

363  {
364  struct acm_device *acm = rndis->priv;
365  struct rndis_header *header = iobuf->data;
366 
367  /* Sanity check */
368  assert ( iob_len ( iobuf ) >= sizeof ( *header ) );
369  assert ( iob_len ( iobuf ) == le32_to_cpu ( header->len ) );
370 
371  /* Transmit packet via appropriate mechanism */
372  if ( header->type == cpu_to_le32 ( RNDIS_PACKET_MSG ) ) {
373  return acm_out_transmit ( acm, iobuf );
374  } else {
375  return acm_control_transmit ( acm, iobuf );
376  }
377 }
#define le32_to_cpu(value)
Definition: byteswap.h:113
static int acm_control_transmit(struct acm_device *acm, struct io_buffer *iobuf)
Send control packet.
Definition: acm.c:241
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define cpu_to_le32(value)
Definition: byteswap.h:107
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
A USB RNDIS network device.
Definition: acm.h:31
RNDIS message header.
Definition: rndis.h:23
void * data
Start of data.
Definition: iobuf.h:44
void * priv
Driver private data.
Definition: rndis.h:325
struct ena_aq_header header
Header.
Definition: ena.h:12
#define RNDIS_PACKET_MSG
RNDIS packet message.
Definition: rndis.h:219
static int acm_out_transmit(struct acm_device *acm, struct io_buffer *iobuf)
Transmit packet.
Definition: acm.c:190
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References acm_control_transmit(), acm_out_transmit(), assert(), cpu_to_le32, io_buffer::data, header, iob_len(), le32_to_cpu, rndis_device::priv, acm_device::rndis, and RNDIS_PACKET_MSG.

◆ acm_poll()

static void acm_poll ( struct rndis_device rndis)
static

Poll for completed and received packets.

Parameters
rndisRNDIS device

Definition at line 384 of file acm.c.

384  {
385  struct acm_device *acm = rndis->priv;
386  int rc;
387 
388  /* Poll USB bus */
389  usb_poll ( acm->bus );
390 
391  /* Refill rings */
392  if ( ( rc = usbnet_refill ( &acm->usbnet ) ) != 0 )
393  rndis_rx_err ( rndis, NULL, rc );
394 
395  /* Retrieve encapsulated response, if applicable */
396  if ( acm->responded ) {
397 
398  /* Clear flag */
399  acm->responded = 0;
400 
401  /* Get encapsulated response */
402  if ( ( rc = acm_control_receive ( acm ) ) != 0 )
403  rndis_rx_err ( rndis, NULL, rc );
404  }
405 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_bus * bus
USB bus.
Definition: acm.h:35
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
int responded
An encapsulated response is available.
Definition: acm.h:42
void rndis_rx_err(struct rndis_device *rndis, struct io_buffer *iobuf, int rc)
Discard packet from underlying transport layer.
Definition: rndis.c:866
int usbnet_refill(struct usbnet_device *usbnet)
Refill USB network device bulk IN and interrupt endpoints.
Definition: usbnet.c:151
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1049
A USB RNDIS network device.
Definition: acm.h:31
void * priv
Driver private data.
Definition: rndis.h:325
static int acm_control_receive(struct acm_device *acm)
Receive control packet.
Definition: acm.c:268
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References acm_control_receive(), acm_device::bus, NULL, rndis_device::priv, rc, acm_device::responded, acm_device::rndis, rndis_rx_err(), usb_poll(), acm_device::usbnet, and usbnet_refill().

◆ acm_probe()

static int acm_probe ( struct usb_function func,
struct usb_configuration_descriptor config 
)
static

Probe device.

Parameters
funcUSB function
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 429 of file acm.c.

430  {
431  struct usb_device *usb = func->usb;
432  struct rndis_device *rndis;
433  struct acm_device *acm;
434  int rc;
435 
436  /* Allocate and initialise structure */
437  rndis = alloc_rndis ( sizeof ( *acm ) );
438  if ( ! rndis ) {
439  rc = -ENOMEM;
440  goto err_alloc;
441  }
443  rndis->netdev->dev = &func->dev;
444  acm = rndis->priv;
445  acm->usb = usb;
446  acm->bus = usb->port->hub->bus;
447  acm->rndis = rndis;
448  usbnet_init ( &acm->usbnet, func, &acm_intr_operations,
450  usb_refill_init ( &acm->usbnet.intr, 0, 0, ACM_INTR_MAX_FILL );
452 
453  /* Describe USB network device */
454  if ( ( rc = usbnet_describe ( &acm->usbnet, config ) ) != 0 ) {
455  DBGC ( acm, "ACM %p could not describe: %s\n",
456  acm, strerror ( rc ) );
457  goto err_describe;
458  }
459 
460  /* Register RNDIS device */
461  if ( ( rc = register_rndis ( rndis ) ) != 0 )
462  goto err_register;
463 
464  usb_func_set_drvdata ( func, acm );
465  return 0;
466 
468  err_register:
469  err_describe:
470  free_rndis ( rndis );
471  err_alloc:
472  return rc;
473 }
struct rndis_device * alloc_rndis(size_t priv_len)
Allocate RNDIS device.
Definition: rndis.c:1000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_bus * bus
USB bus.
Definition: acm.h:35
struct usbnet_device usbnet
USB network device.
Definition: acm.h:39
void unregister_rndis(struct rndis_device *rndis)
Unregister RNDIS device.
Definition: rndis.c:1054
#define ACM_IN_MAX_FILL
Bulk IN maximum fill level.
Definition: acm.h:55
#define DBGC(...)
Definition: compiler.h:505
struct usb_endpoint intr
Interrupt endpoint.
Definition: usbnet.h:27
static struct rndis_operations acm_operations
USB RNDIS operations.
Definition: acm.c:408
#define ENOMEM
Not enough space.
Definition: errno.h:534
struct usb_port * port
USB port.
Definition: usb.h:710
struct net_device * netdev
Network device.
Definition: rndis.h:319
An RNDIS device.
Definition: rndis.h:317
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition: usb.h:601
struct usb_device * usb
USB device.
Definition: acm.h:33
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:690
A USB device.
Definition: usb.h:706
#define ACM_INTR_MAX_FILL
Interrupt maximum fill level.
Definition: acm.h:49
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_rndis(struct rndis_device *rndis)
Register RNDIS device.
Definition: rndis.c:1026
static struct usb_endpoint_driver_operations acm_out_operations
Bulk OUT endpoint operations.
Definition: acm.c:223
struct usb_endpoint in
Bulk IN endpoint.
Definition: usbnet.h:29
#define ACM_IN_MTU
Bulk IN buffer size.
Definition: acm.h:61
static struct usb_endpoint_driver_operations acm_in_operations
Bulk IN endpoint operations.
Definition: acm.c:179
A USB RNDIS network device.
Definition: acm.h:31
struct usb_device * usb
USB device.
Definition: usb.h:661
static void rndis_init(struct rndis_device *rndis, struct rndis_operations *op)
Initialise an RNDIS device.
Definition: rndis.h:339
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
static struct usb_endpoint_driver_operations acm_intr_operations
Interrupt endpoint operations.
Definition: acm.c:128
static void usbnet_init(struct usbnet_device *usbnet, struct usb_function *func, struct usb_endpoint_driver_operations *intr, struct usb_endpoint_driver_operations *in, struct usb_endpoint_driver_operations *out)
Initialise USB network device.
Definition: usbnet.h:44
struct usb_hub * hub
USB hub.
Definition: usb.h:798
void * priv
Driver private data.
Definition: rndis.h:325
int usbnet_describe(struct usbnet_device *usbnet, struct usb_configuration_descriptor *config)
Describe USB network device interfaces.
Definition: usbnet.c:277
struct device dev
Generic device.
Definition: usb.h:665
struct usb_bus * bus
USB bus.
Definition: usb.h:828
void free_rndis(struct rndis_device *rndis)
Free RNDIS device.
Definition: rndis.c:1066
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References ACM_IN_MAX_FILL, ACM_IN_MTU, acm_in_operations, ACM_INTR_MAX_FILL, acm_intr_operations, acm_operations, acm_out_operations, alloc_rndis(), acm_device::bus, usb_hub::bus, DBGC, net_device::dev, usb_function::dev, ENOMEM, free_rndis(), usb_port::hub, usbnet_device::in, usbnet_device::intr, rndis_device::netdev, usb_device::port, rndis_device::priv, rc, register_rndis(), acm_device::rndis, rndis_init(), strerror(), unregister_rndis(), acm_device::usb, usb_function::usb, usb_func_set_drvdata(), usb_refill_init(), acm_device::usbnet, usbnet_describe(), and usbnet_init().

◆ acm_remove()

static void acm_remove ( struct usb_function func)
static

Remove device.

Parameters
funcUSB function

Definition at line 480 of file acm.c.

480  {
481  struct acm_device *acm = usb_func_get_drvdata ( func );
482  struct rndis_device *rndis = acm->rndis;
483 
484  /* Unregister RNDIS device */
485  unregister_rndis ( rndis );
486 
487  /* Free RNDIS device */
488  free_rndis ( rndis );
489 }
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:701
void unregister_rndis(struct rndis_device *rndis)
Unregister RNDIS device.
Definition: rndis.c:1054
An RNDIS device.
Definition: rndis.h:317
A USB RNDIS network device.
Definition: acm.h:31
void free_rndis(struct rndis_device *rndis)
Free RNDIS device.
Definition: rndis.c:1066
struct rndis_device * rndis
RNDIS device.
Definition: acm.h:37

References free_rndis(), acm_device::rndis, unregister_rndis(), and usb_func_get_drvdata().

Variable Documentation

◆ __profiler

struct profiler acm_out_profiler __profiler
static
Initial value:
=
{ .name = "acm.intr" }

Interrupt completion profiler.

Bulk OUT profiler.

Bulk IN completion profiler.

Definition at line 43 of file acm.c.

◆ acm_intr_operations

struct usb_endpoint_driver_operations acm_intr_operations
static
Initial value:
= {
.complete = acm_intr_complete,
}
static void acm_intr_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete interrupt transfer.
Definition: acm.c:68

Interrupt endpoint operations.

Definition at line 128 of file acm.c.

Referenced by acm_probe().

◆ acm_in_operations

struct usb_endpoint_driver_operations acm_in_operations
static
Initial value:
= {
.complete = acm_in_complete,
}
static void acm_in_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk IN transfer.
Definition: acm.c:146

Bulk IN endpoint operations.

Definition at line 179 of file acm.c.

Referenced by acm_probe().

◆ acm_out_operations

struct usb_endpoint_driver_operations acm_out_operations
static
Initial value:
= {
.complete = acm_out_complete,
}
static void acm_out_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete bulk OUT transfer.
Definition: acm.c:212

Bulk OUT endpoint operations.

Definition at line 223 of file acm.c.

Referenced by acm_probe().

◆ acm_operations

struct rndis_operations acm_operations
static
Initial value:
= {
.open = acm_open,
.close = acm_close,
.transmit = acm_transmit,
.poll = acm_poll,
}
static void acm_close(struct rndis_device *rndis)
Close RNDIS device.
Definition: acm.c:348
static void acm_poll(struct rndis_device *rndis)
Poll for completed and received packets.
Definition: acm.c:384
static int acm_open(struct rndis_device *rndis)
Open RNDIS device.
Definition: acm.c:328
static int acm_transmit(struct rndis_device *rndis, struct io_buffer *iobuf)
Transmit packet.
Definition: acm.c:362

USB RNDIS operations.

Definition at line 408 of file acm.c.

Referenced by acm_probe().

◆ cdc_acm_ids

struct usb_device_id cdc_acm_ids[]
static
Initial value:
= {
{
.name = "cdc-acm",
.vendor = USB_ANY_ID,
.product = USB_ANY_ID,
},
}
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1329

USB CDC-ACM device IDs.

Definition at line 492 of file acm.c.

◆ __usb_driver

struct usb_driver rf_rndis_driver __usb_driver
Initial value:
= {
.ids = cdc_acm_ids,
.id_count = ( sizeof ( cdc_acm_ids ) / sizeof ( cdc_acm_ids[0] ) ),
.probe = acm_probe,
.remove = acm_remove,
}
static int acm_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: acm.c:429
Deprecated driver.
Definition: usb.h:1404
#define USB_SUBCLASS_CDC_ACM
CDC-ACM subclass.
Definition: acm.h:16
static struct usb_device_id cdc_acm_ids[]
USB CDC-ACM device IDs.
Definition: acm.c:492
static void acm_remove(struct usb_function *func)
Remove device.
Definition: acm.c:480
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition: usb.h:1345
#define USB_CLASS_CDC
Class code for communications devices.
Definition: cdc.h:15
#define USB_PROTOCOL_ACM_RNDIS
CDC-ACM RNDIS device protocol.
Definition: acm.h:19

USB CDC-ACM driver.

USB RF-RNDIS driver.

Definition at line 501 of file acm.c.

◆ rf_rndis_ids

struct usb_device_id rf_rndis_ids[]
static
Initial value:
= {
{
.name = "rf-rndis",
.vendor = USB_ANY_ID,
.product = USB_ANY_ID,
},
}
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1329

USB RF-RNDIS device IDs.

Definition at line 512 of file acm.c.