Merge branch 'master' into class-driver-id
This commit is contained in:
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "tusb_option.h"
|
||||
|
||||
#if ( TUSB_OPT_DEVICE_ENABLED && (CFG_TUD_NET != OPT_NET_NONE) )
|
||||
#if ( TUSB_OPT_DEVICE_ENABLED && CFG_TUD_NET )
|
||||
|
||||
#include "net_device.h"
|
||||
#include "device/usbd_pvt.h"
|
||||
@@ -41,21 +41,14 @@ void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networ
|
||||
typedef struct
|
||||
{
|
||||
uint8_t itf_num;
|
||||
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
|
||||
uint8_t ep_notif;
|
||||
bool ecm_mode;
|
||||
#endif
|
||||
uint8_t ep_in;
|
||||
uint8_t ep_out;
|
||||
} netd_interface_t;
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_EEM
|
||||
#define CFG_TUD_NET_PACKET_PREFIX_LEN 2
|
||||
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 4
|
||||
#else
|
||||
#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
|
||||
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
|
||||
#endif
|
||||
#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
|
||||
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
|
||||
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t received[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
|
||||
@@ -113,9 +106,7 @@ static void do_in_xfer(uint8_t *buf, uint16_t len)
|
||||
|
||||
void netd_report(uint8_t *buf, uint16_t len)
|
||||
{
|
||||
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
|
||||
usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_notif, buf, len);
|
||||
#endif
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@@ -137,16 +128,11 @@ void netd_reset(uint8_t rhport)
|
||||
netd_init();
|
||||
}
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
|
||||
bool netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
|
||||
{
|
||||
// sanity check the descriptor
|
||||
#if CFG_TUD_NET == OPT_NET_EEM
|
||||
TU_VERIFY (CDC_COMM_SUBCLASS_ETHERNET_EMULATION_MODEL == itf_desc->bInterfaceSubClass);
|
||||
#else
|
||||
_netd_itf.ecm_mode = (CDC_COMM_SUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL == itf_desc->bInterfaceSubClass);
|
||||
TU_VERIFY ( (TUD_RNDIS_ITF_SUBCLASS == itf_desc->bInterfaceSubClass) || _netd_itf.ecm_mode );
|
||||
#endif
|
||||
|
||||
// confirm interface hasn't already been allocated
|
||||
TU_ASSERT(0 == _netd_itf.ep_notif);
|
||||
@@ -176,7 +162,6 @@ bool netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
|
||||
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool netd_open_data(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
|
||||
{
|
||||
@@ -223,14 +208,12 @@ bool netd_control_complete(uint8_t rhport, tusb_control_request_t const * reques
|
||||
// Handle class request only
|
||||
TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
|
||||
TU_VERIFY (_netd_itf.itf_num == request->wIndex);
|
||||
|
||||
if ( !_netd_itf.ecm_mode && (request->bmRequestType_bit.direction == TUSB_DIR_OUT) )
|
||||
{
|
||||
rndis_class_set_handler(notify.rndis_buf, request->wLength);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -251,9 +234,6 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
|
||||
TU_VERIFY (_netd_itf.itf_num == request->wIndex);
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_EEM
|
||||
(void)rhport;
|
||||
#else
|
||||
if (_netd_itf.ecm_mode)
|
||||
{
|
||||
/* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
|
||||
@@ -277,40 +257,15 @@ bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request
|
||||
tud_control_xfer(rhport, request, notify.rndis_buf, sizeof(notify.rndis_buf));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct cdc_eem_packet_header
|
||||
{
|
||||
uint16_t length:14;
|
||||
uint16_t bmCRC:1;
|
||||
uint16_t bmType:1;
|
||||
};
|
||||
|
||||
static void handle_incoming_packet(uint32_t len)
|
||||
{
|
||||
uint8_t *pnt = received;
|
||||
uint32_t size = 0;
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_EEM
|
||||
struct cdc_eem_packet_header *hdr = (struct cdc_eem_packet_header *)pnt;
|
||||
|
||||
(void)len;
|
||||
|
||||
if (hdr->bmType)
|
||||
{
|
||||
/* EEM Control Packet: discard it */
|
||||
tud_network_recv_renew();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* EEM Data Packet */
|
||||
pnt += CFG_TUD_NET_PACKET_PREFIX_LEN;
|
||||
size = hdr->length - 4; /* discard the unused CRC-32 */
|
||||
}
|
||||
#else
|
||||
if (_netd_itf.ecm_mode)
|
||||
{
|
||||
size = len;
|
||||
@@ -326,7 +281,6 @@ static void handle_incoming_packet(uint32_t len)
|
||||
size = r->DataLength;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
bool accepted = false;
|
||||
|
||||
@@ -378,12 +332,10 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
||||
}
|
||||
}
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_RNDIS_ECM
|
||||
if ( _netd_itf.ecm_mode && (ep_addr == _netd_itf.ep_notif) )
|
||||
{
|
||||
if (sizeof(notify.ecm_buf.header) == xferred_bytes) ecm_report(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -402,11 +354,7 @@ void tud_network_xmit(struct pbuf *p)
|
||||
if (!can_xmit)
|
||||
return;
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_EEM
|
||||
len = CFG_TUD_NET_PACKET_PREFIX_LEN;
|
||||
#else
|
||||
len = (_netd_itf.ecm_mode) ? 0 : CFG_TUD_NET_PACKET_PREFIX_LEN;
|
||||
#endif
|
||||
data = transmitted + len;
|
||||
|
||||
for(q = p; q != NULL; q = q->next)
|
||||
@@ -416,16 +364,6 @@ void tud_network_xmit(struct pbuf *p)
|
||||
len += q->len;
|
||||
}
|
||||
|
||||
#if CFG_TUD_NET == OPT_NET_EEM
|
||||
struct cdc_eem_packet_header *hdr = (struct cdc_eem_packet_header *)transmitted;
|
||||
/* append a fake CRC-32; the standard allows 0xDEADBEEF, which takes less CPU time */
|
||||
data[0] = 0xDE; data[1] = 0xAD; data[2] = 0xBE; data[3] = 0xEF;
|
||||
/* adjust length to reflect added fake CRC-32 */
|
||||
len += 4;
|
||||
hdr->bmType = 0; /* EEM Data Packet */
|
||||
hdr->length = len - sizeof(struct cdc_eem_packet_header);
|
||||
hdr->bmCRC = 0; /* Ethernet Frame CRC-32 set to 0xDEADBEEF */
|
||||
#else
|
||||
if (!_netd_itf.ecm_mode)
|
||||
{
|
||||
rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
|
||||
@@ -435,7 +373,6 @@ void tud_network_xmit(struct pbuf *p)
|
||||
hdr->DataOffset = sizeof(rndis_data_packet_t) - offsetof(rndis_data_packet_t, DataOffset);
|
||||
hdr->DataLength = len - sizeof(rndis_data_packet_t);
|
||||
}
|
||||
#endif
|
||||
|
||||
do_in_xfer(transmitted, len);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user