Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
usbd_vreq_node Struct Reference

USBD vendor request node. More...

#include <zephyr/usb/usbd.h>

Data Fields

sys_dnode_t node
 Node information for the dlist.
const uint8_t code
 Vendor code (bRequest value).
struct net_buf *(* to_host )(const struct usbd_context *const ctx, const struct usb_setup_packet *const setup)
 Vendor request callback for device-to-host direction.
int(* to_dev )(const struct usbd_context *const ctx, const struct usb_setup_packet *const setup, const struct net_buf *const buf)
 Vendor request callback for host-to-device direction.

Detailed Description

USBD vendor request node.

Vendor request node is identified by the vendor code and is used to register callbacks to handle the vendor request with the receiving device. When the device stack receives a request with type Vendor and recipient Device, and bRequest value equal to the vendor request code, it will call the vendor callbacks depending on the direction of the request.

Example callback code fragment:

static struct net_buf *foo_to_host_cb(const struct usbd_context *const ctx,
const struct usb_setup_packet *const setup)
{
if (setup->wIndex == WEBUSB_REQ_GET_URL) {
struct net_buf *buf;
uint16_t len;
if (index != SAMPLE_WEBUSB_LANDING_PAGE) {
return NULL;
}
len = MIN(setup->wLength, sizeof(webusb_origin_url));
buf = usbd_ep_ctrl_data_in_alloc(ctx, len);
if (buf == NULL) {
return NULL;
}
net_buf_add_mem(buf, &webusb_origin_url, len);
return buf;
}
return NULL;
}
static void * net_buf_add_mem(struct net_buf *buf, const void *mem, size_t len)
Copies the given number of bytes to the end of the buffer.
Definition net_buf.h:1774
#define MIN(a, b)
Obtain the minimum of two values.
Definition util.h:406
struct net_buf * usbd_ep_ctrl_data_in_alloc(const struct usbd_context *const uds_ctx, const size_t size)
Allocate buffer for USB control transfer data stage.
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Network buffer representation.
Definition net_buf.h:1015
USB Setup Data packet.
Definition usb_ch9.h:49
uint16_t wLength
Expected data length.
Definition usb_ch9.h:64
uint16_t wValue
Request-specific value.
Definition usb_ch9.h:60
uint16_t wIndex
Request-specific index.
Definition usb_ch9.h:62
USB device support runtime context.
Definition usbd.h:294
#define USB_GET_DESCRIPTOR_INDEX(wValue)
Obtain descriptor index from USB_SREQ_GET_DESCRIPTOR request value.
Definition usb_ch9.h:567

Field Documentation

◆ code

const uint8_t usbd_vreq_node::code

Vendor code (bRequest value).

◆ node

sys_dnode_t usbd_vreq_node::node

Node information for the dlist.

◆ to_dev

int(* usbd_vreq_node::to_dev) (const struct usbd_context *const ctx, const struct usb_setup_packet *const setup, const struct net_buf *const buf)

Vendor request callback for host-to-device direction.

For requests with Data OUT stage (wLength != 0), the callback will be called first with NULL buf before Data OUT stage is received to check if data should be received. The callback will be called second time, with non-NULL buf, after data is received.

For requests without Data Stage (wLength == 0), the callback is called just once with NULL buf.

◆ to_host

struct net_buf *(* usbd_vreq_node::to_host) (const struct usbd_context *const ctx, const struct usb_setup_packet *const setup)

Vendor request callback for device-to-host direction.


The documentation for this struct was generated from the following file: