/* ********************************************************************************************************* * uC/USB-Device * The Embedded USB Device Stack * * Copyright (c) 2021 Semidrive Semiconductor * * All rights reserved. * ********************************************************************************************************* */ /* ********************************************************************************************************* * * USB COMMUNICATIONS DEVICE CLASS (CDC) * NETWORK CONTROL MODEL (NCM) * USB Ethernet * * Filename : usbd_ncm.h * Version : V1.00.00 ********************************************************************************************************* */ /* ********************************************************************************************************* * MODULE ********************************************************************************************************* */ #ifndef USBD_NCM_MODULE_PRESENT #define USBD_NCM_MODULE_PRESENT /* ********************************************************************************************************* * INCLUDE FILES ********************************************************************************************************* */ #include "../usbd_cdc.h" #include /* ********************************************************************************************************* * DEFINES ********************************************************************************************************* */ #define USBD_NCM_NBR_NONE DEF_INT_08U_MAX_VAL /* * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble * and FCS/CRC (frame check sequence). */ #define ETH_ALEN 6 /* Octets in one ethernet addr */ #define ETH_TLEN 2 /* Octets in ethernet type field */ #define ETH_HLEN 14 /* Total octets in header. */ #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */ #define ETH_DATA_LEN 1500u /* Max. octets in payload */ #define ETH_FRAME_LEN 1514u /* Max. octets in frame sans FCS */ #define ETH_FCS_LEN 4 /* Octets in the FCS */ /* CDC NCM subclass 5.2.1 NCM Functional Descriptor, bmNetworkCapabilities */ #define USB_CDC_NCM_NCAP_ETH_FILTER (1 << 0) #define USB_CDC_NCM_NCAP_NET_ADDRESS (1 << 1) #define USB_CDC_NCM_NCAP_ENCAP_COMMAND (1 << 2) #define USB_CDC_NCM_NCAP_MAX_DATAGRAM_SIZE (1 << 3) #define USB_CDC_NCM_NCAP_CRC_MODE (1 << 4) #define USB_CDC_NCM_NCAP_NTB_INPUT_SIZE (1 << 5) /* CDC NCM subclass Table 6-3: NTB Parameter Structure */ #define USB_CDC_NCM_NTB16_SUPPORTED (1 << 0) #define USB_CDC_NCM_NTB32_SUPPORTED (1 << 1) /* CDC NCM subclass 6.2.7 SetNtbInputSize */ #define USB_CDC_NCM_NTB_MIN_IN_SIZE 2048 #define USB_CDC_NCM_NTB_MIN_OUT_SIZE 2048 /* ********************************************************************************************************* * DATA TYPES ********************************************************************************************************* */ /* "Ethernet Networking Functional Descriptor" from CDC spec 5.2.3.16 */ struct usb_cdc_ether_desc { CPU_INT08U bLength; CPU_INT08U bDescriptorType; CPU_INT08U bDescriptorSubType; CPU_INT08U iMACAddress; CPU_INT32U bmEthernetStatistics; CPU_INT16U wMaxSegmentSize; CPU_INT16U wNumberMCFilters; CPU_INT08U bNumberPowerFilters; } __attribute__ ((packed)); /* "NCM Control Model Functional Descriptor" */ struct usb_cdc_ncm_desc { CPU_INT08U bLength; CPU_INT08U bDescriptorType; CPU_INT08U bDescriptorSubType; CPU_INT16U bcdNcmVersion; CPU_INT08U bmNetworkCapabilities; } __attribute__ ((packed)); /* * Class Specific structures and constants * * CDC NCM NTB parameters structure, CDC NCM subclass 6.2.1 * */ struct usb_cdc_ncm_ntb_parameters { CPU_INT16U wLength; CPU_INT16U bmNtbFormatsSupported; CPU_INT32U dwNtbInMaxSize; CPU_INT16U wNdpInDivisor; CPU_INT16U wNdpInPayloadRemainder; CPU_INT16U wNdpInAlignment; CPU_INT16U wPadding1; CPU_INT32U dwNtbOutMaxSize; CPU_INT16U wNdpOutDivisor; CPU_INT16U wNdpOutPayloadRemainder; CPU_INT16U wNdpOutAlignment; CPU_INT16U wNtbOutMaxDatagrams; } __attribute__ ((packed)); /* ********************************************************************************************************* * GLOBAL VARIABLES ********************************************************************************************************* */ /* ********************************************************************************************************* * MACROS ********************************************************************************************************* */ /* ********************************************************************************************************* * FUNCTION PROTOTYPES ********************************************************************************************************* */ void USBD_NCM_Init (USBD_ERR *p_err); CPU_INT08U USBD_NCM_Add (USBD_ERR *p_err); CPU_BOOLEAN USBD_NCM_CfgAdd (CPU_INT08U subclass_nbr, CPU_INT08U dev_nbr, CPU_INT08U cfg_nbr, USBD_ERR *p_err); CPU_BOOLEAN USBD_NCM_Bind (CPU_INT08U subclass_nbr, struct net_driver_s *nd, CPU_INT08U *mac_addr); void USBD_NCM_TxDatagramSubmit(CPU_INT08U subclass_nbr, struct pbuf *p, USBD_ERR *p_err); /* ********************************************************************************************************* * CONFIGURATION ERRORS ********************************************************************************************************* */ #ifndef USBD_CDC_NCM_CFG_MAX_NBR_DEV #error "USBD_CDC_NCM_CFG_MAX_NBR_DEV not #define'd in 'usbd_cfg.h' [MUST be >= 1]" #elif (USBD_CDC_NCM_CFG_MAX_NBR_DEV < 1u) #error "USBD_CDC_NCM_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h'[MUST be >= 1]" #elif (USBD_CDC_NCM_CFG_MAX_NBR_DEV > USBD_CDC_CFG_MAX_NBR_DEV) #error "USBD_CDC_NCM_CFG_MAX_NBR_DEV illegally #define'd in 'usbd_cfg.h' [MUST be <= USBD_CDC_CFG_MAX_NBR_DEV]" #endif #ifndef USBD_CDC_NCM_CFG_TX_DPE_LEN #error "USBD_CDC_NCM_CFG_TX_DPE_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 1]" #elif (USBD_CDC_NCM_CFG_TX_DPE_LEN < 1u) #error "USBD_CDC_NCM_CFG_TX_DPE_LEN illegally #define'd in 'usbd_cfg.h'[MUST be >= 1]" #endif #ifndef USBD_CDC_NCM_CFG_TX_BUF_LEN #error "USBD_CDC_NCM_CFG_TX_BUF_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 2]" #elif (USBD_CDC_NCM_CFG_TX_BUF_LEN < 2u) || (USBD_CDC_NCM_CFG_TX_BUF_LEN > 64u) #error "USBD_CDC_NCM_CFG_TX_BUF_LEN illegally #define'd in 'usbd_cfg.h'[MUST be >= 2 and <=64]" #endif #ifndef USBD_CDC_NCM_CFG_RX_BUF_LEN #error "USBD_CDC_NCM_CFG_RX_BUF_LEN not #define'd in 'usbd_cfg.h' [MUST be >= 2]" #elif (USBD_CDC_NCM_CFG_RX_BUF_LEN < 2u) || (USBD_CDC_NCM_CFG_RX_BUF_LEN > 64u) #error "USBD_CDC_NCM_CFG_RX_BUF_LEN illegally #define'd in 'usbd_cfg.h'[MUST be >= 2 and <=64]" #endif /* ********************************************************************************************************* * MODULE END ********************************************************************************************************* */ #endif