iPXE
Data Structures | Macros | Enumerations | Functions
ecm.h File Reference

CDC-ECM USB Ethernet driver. More...

#include <ipxe/usb.h>
#include <ipxe/usbnet.h>
#include <ipxe/cdc.h>

Go to the source code of this file.

Data Structures

struct  ecm_ethernet_descriptor
 An Ethernet Functional Descriptor. More...
 
struct  ecm_device
 A CDC-ECM network device. More...
 

Macros

#define USB_SUBCLASS_CDC_ECM   0x06
 CDC-ECM subclass. More...
 
#define ECM_SET_ETHERNET_PACKET_FILTER
 Set Ethernet packet filter. More...
 
#define ECM_INTR_MAX_FILL   2
 Interrupt maximum fill level. More...
 
#define ECM_IN_MAX_FILL   8
 Bulk IN maximum fill level. More...
 
#define ECM_IN_MTU   ( ETH_FRAME_LEN + 4 /* possible VLAN header */ )
 Bulk IN buffer size. More...
 

Enumerations

enum  ecm_ethernet_packet_filter {
  ECM_PACKET_TYPE_PROMISCUOUS = 0x0001, ECM_PACKET_TYPE_ALL_MULTICAST = 0x0002, ECM_PACKET_TYPE_DIRECTED = 0x0004, ECM_PACKET_TYPE_BROADCAST = 0x0008,
  ECM_PACKET_TYPE_MULTICAST = 0x0010
}
 Ethernet packet types. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
struct ecm_ethernet_descriptorecm_ethernet_descriptor (struct usb_configuration_descriptor *config, struct usb_interface_descriptor *interface)
 Locate Ethernet functional descriptor. More...
 
int ecm_fetch_mac (struct usb_device *usb, struct ecm_ethernet_descriptor *desc, uint8_t *hw_addr)
 Get hardware MAC address. More...
 

Detailed Description

CDC-ECM USB Ethernet driver.

Definition in file ecm.h.

Macro Definition Documentation

◆ USB_SUBCLASS_CDC_ECM

#define USB_SUBCLASS_CDC_ECM   0x06

CDC-ECM subclass.

Definition at line 17 of file ecm.h.

◆ ECM_SET_ETHERNET_PACKET_FILTER

#define ECM_SET_ETHERNET_PACKET_FILTER
Value:
USB_REQUEST_TYPE ( 0x43 ) )
#define USB_RECIP_INTERFACE
Request recipient is an interface.
Definition: usb.h:101
#define USB_DIR_OUT
Data transfer is from host to device.
Definition: usb.h:80
#define USB_TYPE_CLASS
Class-specific request type.
Definition: usb.h:89

Set Ethernet packet filter.

Definition at line 20 of file ecm.h.

◆ ECM_INTR_MAX_FILL

#define ECM_INTR_MAX_FILL   2

Interrupt maximum fill level.

This is a policy decision.

Definition at line 72 of file ecm.h.

◆ ECM_IN_MAX_FILL

#define ECM_IN_MAX_FILL   8

Bulk IN maximum fill level.

This is a policy decision.

Definition at line 78 of file ecm.h.

◆ ECM_IN_MTU

#define ECM_IN_MTU   ( ETH_FRAME_LEN + 4 /* possible VLAN header */ )

Bulk IN buffer size.

This is a policy decision.

Definition at line 84 of file ecm.h.

Enumeration Type Documentation

◆ ecm_ethernet_packet_filter

Ethernet packet types.

Enumerator
ECM_PACKET_TYPE_PROMISCUOUS 

Promiscuous mode.

ECM_PACKET_TYPE_ALL_MULTICAST 

All multicast packets.

ECM_PACKET_TYPE_DIRECTED 

Unicast packets.

ECM_PACKET_TYPE_BROADCAST 

Broadcast packets.

ECM_PACKET_TYPE_MULTICAST 

Specified multicast packets.

Definition at line 25 of file ecm.h.

25  {
26  /** Promiscuous mode */
28  /** All multicast packets */
30  /** Unicast packets */
31  ECM_PACKET_TYPE_DIRECTED = 0x0004,
32  /** Broadcast packets */
34  /** Specified multicast packets */
36 };
Unicast packets.
Definition: ecm.h:31
Promiscuous mode.
Definition: ecm.h:27
Specified multicast packets.
Definition: ecm.h:35
All multicast packets.
Definition: ecm.h:29
Broadcast packets.
Definition: ecm.h:33

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ecm_ethernet_descriptor()

Locate Ethernet functional descriptor.

Parameters
configConfiguration descriptor
interfaceInterface descriptor
Return values
descDescriptor, or NULL if not found

Definition at line 69 of file ecm.c.

70  {
71  struct ecm_ethernet_descriptor *desc;
72 
73  for_each_interface_descriptor ( desc, config, interface ) {
74  if ( ( desc->header.type == USB_CS_INTERFACE_DESCRIPTOR ) &&
75  ( desc->subtype == CDC_SUBTYPE_ETHERNET ) )
76  return desc;
77  }
78  return NULL;
79 }
An Ethernet Functional Descriptor.
Definition: ecm.h:39
#define CDC_SUBTYPE_ETHERNET
Ethernet descriptor subtype.
Definition: cdc.h:41
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:379
uint8_t subtype
Descriptor subtype.
Definition: ecm.h:43
An object interface.
Definition: interface.h:109
#define USB_CS_INTERFACE_DESCRIPTOR
A class-specific interface descriptor.
Definition: usb.h:331
uint8_t type
Descriptor type.
Definition: usb.h:162
struct usb_descriptor_header header
Descriptor header.
Definition: ecm.h:41
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References CDC_SUBTYPE_ETHERNET, for_each_interface_descriptor, ecm_ethernet_descriptor::header, NULL, ecm_ethernet_descriptor::subtype, usb_descriptor_header::type, and USB_CS_INTERFACE_DESCRIPTOR.

Referenced by ecm_probe(), and ncm_probe().

◆ ecm_fetch_mac()

int ecm_fetch_mac ( struct usb_device usb,
struct ecm_ethernet_descriptor desc,
uint8_t hw_addr 
)

Get hardware MAC address.

Parameters
usbUSB device
descEthernet functional descriptor
hw_addrHardware address to fill in
Return values
rcReturn status code

Definition at line 89 of file ecm.c.

90  {
91  char buf[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
92  int len;
93  int rc;
94 
95  /* Fetch MAC address string */
96  len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
97  sizeof ( buf ) );
98  if ( len < 0 ) {
99  rc = len;
100  return rc;
101  }
102 
103  /* Sanity check */
104  if ( len != ( ( int ) ( sizeof ( buf ) - 1 /* NUL */ ) ) ) {
105  DBGC ( usb, "USB %s has invalid ECM MAC \"%s\"\n",
106  usb->name, buf );
107  return -EINVAL;
108  }
109 
110  /* Decode MAC address */
111  len = base16_decode ( buf, hw_addr, ETH_ALEN );
112  if ( len < 0 ) {
113  rc = len;
114  DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
115  usb->name, buf, strerror ( rc ) );
116  return rc;
117  }
118 
119  return 0;
120 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static size_t base16_encoded_len(size_t raw_len)
Calculate length of base16-encoded data.
Definition: base16.h:21
char name[32]
Name.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
uint8_t mac
MAC address string.
Definition: ecm.h:45
#define ETH_ALEN
Definition: if_ether.h:8
uint32_t len
Length.
Definition: ena.h:14
int usb_get_string_descriptor(struct usb_device *usb, unsigned int index, unsigned int language, char *buf, size_t len)
Get USB string descriptor.
Definition: usb.c:884

References base16_encoded_len(), DBGC, EINVAL, ETH_ALEN, len, ecm_ethernet_descriptor::mac, usb_device::name, rc, strerror(), and usb_get_string_descriptor().

Referenced by ecm_probe(), and ncm_probe().