iPXE
Data Structures | Macros | Enumerations | Functions | Variables
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)
 
 FILE_SECBOOT (PERMITTED)
 
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_function *func, struct ecm_ethernet_descriptor *desc, struct net_device *netdev)
 Get hardware MAC address. More...
 

Variables

enum ecm_ethernet_packet_filter __attribute__
 

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 18 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:116
#define USB_DIR_OUT
Data transfer is from host to device.
Definition: usb.h:95
#define USB_TYPE_CLASS
Class-specific request type.
Definition: usb.h:104

Set Ethernet packet filter.

Definition at line 21 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 73 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 79 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 85 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 26 of file ecm.h.

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

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ ecm_ethernet_descriptor()

Locate Ethernet functional descriptor.

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

Definition at line 71 of file ecm.c.

72  {
74 
76  if ( ( desc->header.type == USB_CS_INTERFACE_DESCRIPTOR ) &&
77  ( desc->subtype == CDC_SUBTYPE_ETHERNET ) )
78  return desc;
79  }
80  return NULL;
81 }
An Ethernet Functional Descriptor.
Definition: ecm.h:40
#define CDC_SUBTYPE_ETHERNET
Ethernet descriptor subtype.
Definition: cdc.h:42
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:394
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
An object interface.
Definition: interface.h:125
#define USB_CS_INTERFACE_DESCRIPTOR
A class-specific interface descriptor.
Definition: usb.h:346
#define NULL
NULL pointer (VOID *)
Definition: Base.h:322

References CDC_SUBTYPE_ETHERNET, desc, for_each_interface_descriptor, NULL, and USB_CS_INTERFACE_DESCRIPTOR.

Referenced by ecm_probe(), and ncm_probe().

◆ ecm_fetch_mac()

int ecm_fetch_mac ( struct usb_function func,
struct ecm_ethernet_descriptor desc,
struct net_device netdev 
)

Get hardware MAC address.

Parameters
funcUSB function
descEthernet functional descriptor
netdevNetwork device
Return values
rcReturn status code

Definition at line 91 of file ecm.c.

93  {
94  struct usb_device *usb = func->usb;
95  char buf[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
96  uint8_t amac[ETH_ALEN];
97  int len;
98  int rc;
99 
100  /* Fetch MAC address string */
101  buf[ sizeof ( buf ) - 1 ] = '\0';
102  len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
103  ( sizeof ( buf ) - 1 ) );
104  if ( len < 0 ) {
105  rc = len;
106  return rc;
107  }
108 
109  /* Sanity check */
110  if ( len != ( ( int ) ( sizeof ( buf ) - 1 /* NUL */ ) ) ) {
111  DBGC ( usb, "USB %s has invalid ECM MAC \"%s\"\n",
112  func->name, buf );
113  return -EINVAL;
114  }
115 
116  /* Decode MAC address */
117  len = base16_decode ( buf, netdev->hw_addr, ETH_ALEN );
118  if ( len < 0 ) {
119  rc = len;
120  DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
121  func->name, buf, strerror ( rc ) );
122  return rc;
123  }
124 
125  /* Apply system-specific MAC address as current link-layer
126  * address, if present.
127  */
128  if ( ( rc = acpi_mac ( amac ) ) == 0 ) {
129  memcpy ( netdev->ll_addr, amac, ETH_ALEN );
130  DBGC ( usb, "USB %s using system-specific MAC %s\n",
131  func->name, eth_ntoa ( netdev->ll_addr ) );
132  }
133 
134  return 0;
135 }
#define EINVAL
Invalid argument.
Definition: errno.h:429
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: usb.h:676
#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:25
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
void * memcpy(void *dest, const void *src, size_t len) __nonnull
int acpi_mac(uint8_t *hw_addr)
Extract MAC address from DSDT/SSDT.
Definition: acpimac.c:235
ring len
Length.
Definition: dwmac.h:231
static struct net_device * netdev
Definition: gdbudp.c:52
A USB device.
Definition: usb.h:723
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
const char * eth_ntoa(const void *ll_addr)
Transcribe Ethernet address.
Definition: ethernet.c:176
unsigned char uint8_t
Definition: stdint.h:10
#define ETH_ALEN
Definition: if_ether.h:9
struct usb_device * usb
USB device.
Definition: usb.h:678
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:382
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:916

References acpi_mac(), base16_encoded_len(), DBGC, desc, EINVAL, ETH_ALEN, eth_ntoa(), net_device::hw_addr, len, net_device::ll_addr, memcpy(), usb_function::name, netdev, rc, strerror(), usb_function::usb, and usb_get_string_descriptor().

Referenced by ecm_probe(), and ncm_probe().

Variable Documentation

◆ __attribute__