iPXE
Data Structures | Defines | 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...

Defines

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

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.
int ecm_fetch_mac (struct usb_device *usb, struct ecm_ethernet_descriptor *desc, uint8_t *hw_addr)
 Get hardware MAC address.

Detailed Description

CDC-ECM USB Ethernet driver.

Definition in file ecm.h.


Define Documentation

#define USB_SUBCLASS_CDC_ECM   0x06

CDC-ECM subclass.

Definition at line 17 of file ecm.h.

Value:
( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
          USB_REQUEST_TYPE ( 0x43 ) )

Set Ethernet packet filter.

Definition at line 20 of file ecm.h.

Referenced by ecm_open().

#define ECM_INTR_MAX_FILL   2

Interrupt maximum fill level.

This is a policy decision.

Definition at line 72 of file ecm.h.

Referenced by ecm_probe().

#define ECM_IN_MAX_FILL   8

Bulk IN maximum fill level.

This is a policy decision.

Definition at line 78 of file ecm.h.

Referenced by ecm_probe().

#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.

Referenced by ecm_probe().


Enumeration Type Documentation

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.

                                {
        /** Promiscuous mode */
        ECM_PACKET_TYPE_PROMISCUOUS = 0x0001,
        /** All multicast packets */
        ECM_PACKET_TYPE_ALL_MULTICAST = 0x0002,
        /** Unicast packets */
        ECM_PACKET_TYPE_DIRECTED = 0x0004,
        /** Broadcast packets */
        ECM_PACKET_TYPE_BROADCAST = 0x0008,
        /** Specified multicast packets */
        ECM_PACKET_TYPE_MULTICAST = 0x0010,
};

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
struct ecm_ethernet_descriptor* ecm_ethernet_descriptor ( struct usb_configuration_descriptor config,
struct usb_interface_descriptor interface 
) [read]

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.

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().

                                                                       {
        struct ecm_ethernet_descriptor *desc;

        for_each_interface_descriptor ( desc, config, interface ) {
                if ( ( desc->header.type == USB_CS_INTERFACE_DESCRIPTOR ) &&
                     ( desc->subtype == CDC_SUBTYPE_ETHERNET ) )
                        return desc;
        }
        return NULL;
}
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.

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().

                                                                             {
        char buf[ base16_encoded_len ( ETH_ALEN ) + 1 /* NUL */ ];
        int len;
        int rc;

        /* Fetch MAC address string */
        len = usb_get_string_descriptor ( usb, desc->mac, 0, buf,
                                          sizeof ( buf ) );
        if ( len < 0 ) {
                rc = len;
                return rc;
        }

        /* Sanity check */
        if ( len != ( ( int ) ( sizeof ( buf ) - 1 /* NUL */ ) ) ) {
                DBGC ( usb, "USB %s has invalid ECM MAC \"%s\"\n",
                       usb->name, buf );
                return -EINVAL;
        }

        /* Decode MAC address */
        len = base16_decode ( buf, hw_addr, ETH_ALEN );
        if ( len < 0 ) {
                rc = len;
                DBGC ( usb, "USB %s could not decode ECM MAC \"%s\": %s\n",
                       usb->name, buf, strerror ( rc ) );
                return rc;
        }

        return 0;
}