|
|
@@ -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"
|
|
|
@@ -40,40 +40,60 @@ void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networ
|
|
|
//--------------------------------------------------------------------+
|
|
|
typedef struct
|
|
|
{
|
|
|
- uint8_t itf_num;
|
|
|
+ uint8_t itf_num; // Index number of Management Interface, +1 for Data Interface
|
|
|
+ uint8_t itf_data_alt; // Alternate setting of Data Interface. 0 : inactive, 1 : active
|
|
|
+
|
|
|
uint8_t ep_notif;
|
|
|
uint8_t ep_in;
|
|
|
uint8_t ep_out;
|
|
|
+
|
|
|
+ bool ecm_mode;
|
|
|
+
|
|
|
+ // Endpoint descriptor use to open/close when receving SetInterface
|
|
|
+ // TODO since configuration descriptor may not be long-lived memory, we should
|
|
|
+ // keep a copy of endpoint attribute instead
|
|
|
+ uint8_t const * ecm_desc_epdata;
|
|
|
+
|
|
|
} netd_interface_t;
|
|
|
|
|
|
-#if CFG_TUD_NET == OPT_NET_ECM
|
|
|
- #define CFG_TUD_NET_PACKET_PREFIX_LEN 0
|
|
|
- #define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
|
|
|
- #define CFG_TUD_NET_INTERFACESUBCLASS CDC_COMM_SUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL
|
|
|
-#elif CFG_TUD_NET == OPT_NET_RNDIS
|
|
|
- #define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
|
|
|
- #define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
|
|
|
- #define CFG_TUD_NET_INTERFACESUBCLASS TUD_RNDIS_ITF_SUBCLASS
|
|
|
-#elif CFG_TUD_NET == OPT_NET_EEM
|
|
|
- #define CFG_TUD_NET_PACKET_PREFIX_LEN 2
|
|
|
- #define CFG_TUD_NET_PACKET_SUFFIX_LEN 4
|
|
|
- #define CFG_TUD_NET_INTERFACESUBCLASS CDC_COMM_SUBCLASS_ETHERNET_EMULATION_MODEL
|
|
|
-#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];
|
|
|
|
|
|
-#if CFG_TUD_NET == OPT_NET_ECM
|
|
|
- CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static tusb_control_request_t notify =
|
|
|
- {
|
|
|
- .bmRequestType = 0x21,
|
|
|
- .bRequest = 0 /* NETWORK_CONNECTION */,
|
|
|
+struct ecm_notify_struct
|
|
|
+{
|
|
|
+ tusb_control_request_t header;
|
|
|
+ uint32_t downlink, uplink;
|
|
|
+};
|
|
|
+
|
|
|
+static const struct ecm_notify_struct ecm_notify_nc =
|
|
|
+{
|
|
|
+ .header = {
|
|
|
+ .bmRequestType = 0xA1,
|
|
|
+ .bRequest = 0 /* NETWORK_CONNECTION aka NetworkConnection */,
|
|
|
.wValue = 1 /* Connected */,
|
|
|
.wLength = 0,
|
|
|
- };
|
|
|
-#elif CFG_TUD_NET == OPT_NET_RNDIS
|
|
|
- CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t rndis_buf[120];
|
|
|
-#endif
|
|
|
+ },
|
|
|
+};
|
|
|
+
|
|
|
+static const struct ecm_notify_struct ecm_notify_csc =
|
|
|
+{
|
|
|
+ .header = {
|
|
|
+ .bmRequestType = 0xA1,
|
|
|
+ .bRequest = 0x2A /* CONNECTION_SPEED_CHANGE aka ConnectionSpeedChange */,
|
|
|
+ .wLength = 8,
|
|
|
+ },
|
|
|
+ .downlink = 9728000,
|
|
|
+ .uplink = 9728000,
|
|
|
+};
|
|
|
+
|
|
|
+CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static union
|
|
|
+{
|
|
|
+ uint8_t rndis_buf[120];
|
|
|
+ struct ecm_notify_struct ecm_buf;
|
|
|
+} notify;
|
|
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
// INTERNAL OBJECT & FUNCTION DECLARATION
|
|
|
@@ -115,19 +135,28 @@ void netd_reset(uint8_t rhport)
|
|
|
|
|
|
bool netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
|
|
|
{
|
|
|
- // sanity check the descriptor
|
|
|
- TU_ASSERT (CFG_TUD_NET_INTERFACESUBCLASS == itf_desc->bInterfaceSubClass);
|
|
|
+ bool const is_rndis = (TUD_RNDIS_ITF_CLASS == itf_desc->bInterfaceClass &&
|
|
|
+ TUD_RNDIS_ITF_SUBCLASS == itf_desc->bInterfaceSubClass &&
|
|
|
+ TUD_RNDIS_ITF_PROTOCOL == itf_desc->bInterfaceProtocol);
|
|
|
+
|
|
|
+ bool const is_ecm = (TUSB_CLASS_CDC == itf_desc->bInterfaceClass &&
|
|
|
+ CDC_COMM_SUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL == itf_desc->bInterfaceSubClass &&
|
|
|
+ 0x00 == itf_desc->bInterfaceProtocol);
|
|
|
+
|
|
|
+ TU_VERIFY ( is_rndis || is_ecm );
|
|
|
|
|
|
// confirm interface hasn't already been allocated
|
|
|
- TU_ASSERT(0 == _netd_itf.ep_in);
|
|
|
+ TU_ASSERT(0 == _netd_itf.ep_notif);
|
|
|
|
|
|
- //------------- first Interface -------------//
|
|
|
+ // sanity check the descriptor
|
|
|
+ _netd_itf.ecm_mode = is_ecm;
|
|
|
+
|
|
|
+ //------------- Management Interface -------------//
|
|
|
_netd_itf.itf_num = itf_desc->bInterfaceNumber;
|
|
|
|
|
|
- uint8_t const * p_desc = tu_desc_next( itf_desc );
|
|
|
(*p_length) = sizeof(tusb_desc_interface_t);
|
|
|
+ uint8_t const * p_desc = tu_desc_next( itf_desc );
|
|
|
|
|
|
-#if CFG_TUD_NET != OPT_NET_EEM
|
|
|
// Communication Functional Descriptors
|
|
|
while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) )
|
|
|
{
|
|
|
@@ -142,35 +171,49 @@ bool netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t
|
|
|
|
|
|
_netd_itf.ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
|
|
|
|
|
|
- (*p_length) += p_desc[DESC_OFFSET_LEN];
|
|
|
+ (*p_length) += tu_desc_len(p_desc);
|
|
|
p_desc = tu_desc_next(p_desc);
|
|
|
}
|
|
|
|
|
|
- //------------- second Interface -------------//
|
|
|
- if ( (TUSB_DESC_INTERFACE == p_desc[DESC_OFFSET_TYPE]) &&
|
|
|
- (TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
|
|
|
+ //------------- Data Interface -------------//
|
|
|
+ // - RNDIS Data followed immediately by a pair of endpoints
|
|
|
+ // - CDC-ECM data interface has 2 alternate settings
|
|
|
+ // - 0 : zero endpoints for inactive (default)
|
|
|
+ // - 1 : IN & OUT endpoints for active networking
|
|
|
+ TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc));
|
|
|
+
|
|
|
+ do
|
|
|
{
|
|
|
- // next to endpoint descriptor
|
|
|
+ tusb_desc_interface_t const * data_itf_desc = (tusb_desc_interface_t const *) p_desc;
|
|
|
+ TU_ASSERT(TUSB_CLASS_CDC_DATA == data_itf_desc->bInterfaceClass);
|
|
|
+
|
|
|
+ (*p_length) += tu_desc_len(p_desc);
|
|
|
p_desc = tu_desc_next(p_desc);
|
|
|
- (*p_length) += sizeof(tusb_desc_interface_t);
|
|
|
- }
|
|
|
-#endif
|
|
|
+ }while( _netd_itf.ecm_mode && (TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) );
|
|
|
|
|
|
- if (TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
|
|
|
+ // Pair of endpoints
|
|
|
+ TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc));
|
|
|
+
|
|
|
+ if ( _netd_itf.ecm_mode )
|
|
|
+ {
|
|
|
+ // ECM by default is in-active, save the endpoint attribute
|
|
|
+ // to open later when received setInterface
|
|
|
+ _netd_itf.ecm_desc_epdata = p_desc;
|
|
|
+ }else
|
|
|
{
|
|
|
- // Open endpoint pair
|
|
|
+ // Open endpoint pair for RNDIS
|
|
|
TU_ASSERT( usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &_netd_itf.ep_out, &_netd_itf.ep_in) );
|
|
|
|
|
|
- (*p_length) += 2*sizeof(tusb_desc_endpoint_t);
|
|
|
- }
|
|
|
+ tud_network_init_cb();
|
|
|
|
|
|
- tud_network_init_cb();
|
|
|
+ // we are ready to transmit a packet
|
|
|
+ can_xmit = true;
|
|
|
|
|
|
- // we are ready to transmit a packet
|
|
|
- can_xmit = true;
|
|
|
+ // prepare for incoming packets
|
|
|
+ tud_network_recv_renew();
|
|
|
+ }
|
|
|
|
|
|
- // prepare for incoming packets
|
|
|
- tud_network_recv_renew();
|
|
|
+ (*p_length) += 2*sizeof(tusb_desc_endpoint_t);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
@@ -181,116 +224,167 @@ bool netd_control_complete(uint8_t rhport, tusb_control_request_t const * reques
|
|
|
{
|
|
|
(void) rhport;
|
|
|
|
|
|
- // Handle class request only
|
|
|
- TU_VERIFY (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
|
|
|
-
|
|
|
- TU_VERIFY (_netd_itf.itf_num == request->wIndex);
|
|
|
-
|
|
|
-#if CFG_TUD_NET == OPT_NET_RNDIS
|
|
|
- if (request->bmRequestType_bit.direction == TUSB_DIR_OUT)
|
|
|
+ // Handle RNDIS class control OUT only
|
|
|
+ if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
|
|
|
+ request->bmRequestType_bit.direction == TUSB_DIR_OUT &&
|
|
|
+ _netd_itf.itf_num == request->wIndex)
|
|
|
{
|
|
|
- rndis_class_set_handler(rndis_buf, request->wLength);
|
|
|
+ if ( !_netd_itf.ecm_mode )
|
|
|
+ {
|
|
|
+ rndis_class_set_handler(notify.rndis_buf, request->wLength);
|
|
|
+ }
|
|
|
}
|
|
|
-#endif
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+static void ecm_report(bool nc)
|
|
|
+{
|
|
|
+ notify.ecm_buf = (nc) ? ecm_notify_nc : ecm_notify_csc;
|
|
|
+ notify.ecm_buf.header.wIndex = _netd_itf.itf_num;
|
|
|
+ netd_report((uint8_t *)¬ify.ecm_buf, (nc) ? sizeof(notify.ecm_buf.header) : sizeof(notify.ecm_buf));
|
|
|
+}
|
|
|
+
|
|
|
// Handle class control request
|
|
|
// return false to stall control endpoint (e.g unsupported request)
|
|
|
bool netd_control_request(uint8_t rhport, tusb_control_request_t const * request)
|
|
|
{
|
|
|
- // Handle class request only
|
|
|
- TU_VERIFY(request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS);
|
|
|
+ switch ( request->bmRequestType_bit.type )
|
|
|
+ {
|
|
|
+ case TUSB_REQ_TYPE_STANDARD:
|
|
|
+ switch ( request->bRequest )
|
|
|
+ {
|
|
|
+ case TUSB_REQ_GET_INTERFACE:
|
|
|
+ {
|
|
|
+ uint8_t const req_itfnum = (uint8_t) request->wIndex;
|
|
|
+ TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum);
|
|
|
+
|
|
|
+ tud_control_xfer(rhport, request, &_netd_itf.itf_data_alt, 1);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ case TUSB_REQ_SET_INTERFACE:
|
|
|
+ {
|
|
|
+ uint8_t const req_itfnum = (uint8_t) request->wIndex;
|
|
|
+ uint8_t const req_alt = (uint8_t) request->wValue;
|
|
|
+
|
|
|
+ // Only valid for Data Interface with Alternate is either 0 or 1
|
|
|
+ TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum && req_alt < 2);
|
|
|
+
|
|
|
+ // ACM-ECM only: qequest to enable/disable network activities
|
|
|
+ TU_VERIFY(_netd_itf.ecm_mode);
|
|
|
+
|
|
|
+ _netd_itf.itf_data_alt = req_alt;
|
|
|
+
|
|
|
+ if ( _netd_itf.itf_data_alt )
|
|
|
+ {
|
|
|
+ // TODO since we don't actually close endpoint
|
|
|
+ // hack here to not re-open it
|
|
|
+ if ( _netd_itf.ep_in == 0 && _netd_itf.ep_out == 0 )
|
|
|
+ {
|
|
|
+ TU_ASSERT(_netd_itf.ecm_desc_epdata);
|
|
|
+ TU_ASSERT( usbd_open_edpt_pair(rhport, _netd_itf.ecm_desc_epdata, 2, TUSB_XFER_BULK, &_netd_itf.ep_out, &_netd_itf.ep_in) );
|
|
|
+
|
|
|
+ // TODO should be merge with RNDIS's after endpoint opened
|
|
|
+ // Also should have opposite callback for application to disable network !!
|
|
|
+ tud_network_init_cb();
|
|
|
+ can_xmit = true; // we are ready to transmit a packet
|
|
|
+ tud_network_recv_renew(); // prepare for incoming packets
|
|
|
+ }
|
|
|
+ }else
|
|
|
+ {
|
|
|
+ // TODO close the endpoint pair
|
|
|
+ // For now pretend that we did, this should have no harm since host won't try to
|
|
|
+ // communicate with the endpoints again
|
|
|
+ // _netd_itf.ep_in = _netd_itf.ep_out = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ tud_control_status(rhport, request);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ // unsupported request
|
|
|
+ default: return false;
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
- TU_VERIFY (_netd_itf.itf_num == request->wIndex);
|
|
|
+ case TUSB_REQ_TYPE_CLASS:
|
|
|
+ TU_VERIFY (_netd_itf.itf_num == request->wIndex);
|
|
|
|
|
|
-#if CFG_TUD_NET == OPT_NET_ECM
|
|
|
- /* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
|
|
|
- if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest)
|
|
|
- {
|
|
|
- tud_control_xfer(rhport, request, NULL, 0);
|
|
|
- notify.wIndex = request->wIndex;
|
|
|
- usbd_edpt_xfer(TUD_OPT_RHPORT, _netd_itf.ep_notif, (uint8_t *)¬ify, sizeof(notify));
|
|
|
- }
|
|
|
-#elif CFG_TUD_NET == OPT_NET_RNDIS
|
|
|
- if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
|
|
|
- {
|
|
|
- rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)rndis_buf;
|
|
|
- uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
|
|
|
- TU_ASSERT(msglen <= sizeof(rndis_buf));
|
|
|
- tud_control_xfer(rhport, request, rndis_buf, msglen);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- tud_control_xfer(rhport, request, rndis_buf, sizeof(rndis_buf));
|
|
|
+ if (_netd_itf.ecm_mode)
|
|
|
+ {
|
|
|
+ /* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
|
|
|
+ if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest)
|
|
|
+ {
|
|
|
+ tud_control_xfer(rhport, request, NULL, 0);
|
|
|
+ ecm_report(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
|
|
|
+ {
|
|
|
+ rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *)notify.rndis_buf;
|
|
|
+ uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
|
|
|
+ TU_ASSERT(msglen <= sizeof(notify.rndis_buf));
|
|
|
+ tud_control_xfer(rhport, request, notify.rndis_buf, msglen);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ tud_control_xfer(rhport, request, notify.rndis_buf, sizeof(notify.rndis_buf));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ // unsupported request
|
|
|
+ default: return false;
|
|
|
}
|
|
|
-#else
|
|
|
- (void)rhport;
|
|
|
-#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_ECM
|
|
|
- size = len;
|
|
|
-#elif CFG_TUD_NET == OPT_NET_RNDIS
|
|
|
- rndis_data_packet_t *r = (rndis_data_packet_t *)pnt;
|
|
|
- if (len >= sizeof(rndis_data_packet_t))
|
|
|
- if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
|
|
|
- if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
|
|
|
- {
|
|
|
- pnt = &received[r->DataOffset + offsetof(rndis_data_packet_t, DataOffset)];
|
|
|
- size = r->DataLength;
|
|
|
- }
|
|
|
-#elif CFG_TUD_NET == OPT_NET_EEM
|
|
|
- struct cdc_eem_packet_header *hdr = (struct cdc_eem_packet_header *)pnt;
|
|
|
-
|
|
|
- (void)len;
|
|
|
-
|
|
|
- if (hdr->bmType)
|
|
|
+ if (_netd_itf.ecm_mode)
|
|
|
{
|
|
|
- /* EEM Control Packet: discard it */
|
|
|
- tud_network_recv_renew();
|
|
|
+ size = len;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- /* EEM Data Packet */
|
|
|
- pnt += CFG_TUD_NET_PACKET_PREFIX_LEN;
|
|
|
- size = hdr->length - 4; /* discard the unused CRC-32 */
|
|
|
+ rndis_data_packet_t *r = (rndis_data_packet_t *)pnt;
|
|
|
+ if (len >= sizeof(rndis_data_packet_t))
|
|
|
+ if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len))
|
|
|
+ if ( (r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len)
|
|
|
+ {
|
|
|
+ pnt = &received[r->DataOffset + offsetof(rndis_data_packet_t, DataOffset)];
|
|
|
+ size = r->DataLength;
|
|
|
+ }
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
+ bool accepted = false;
|
|
|
|
|
|
if (size)
|
|
|
{
|
|
|
struct pbuf *p = pbuf_alloc(PBUF_RAW, size, PBUF_POOL);
|
|
|
- bool accepted = true;
|
|
|
|
|
|
if (p)
|
|
|
{
|
|
|
memcpy(p->payload, pnt, size);
|
|
|
p->len = size;
|
|
|
accepted = tud_network_recv_cb(p);
|
|
|
- }
|
|
|
|
|
|
- if (!p || !accepted)
|
|
|
- {
|
|
|
- /* if a buffer couldn't be allocated or accepted by the callback, we must discard this packet */
|
|
|
- tud_network_recv_renew();
|
|
|
+ if (!accepted) pbuf_free(p);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (!accepted)
|
|
|
+ {
|
|
|
+ /* if a buffer was never handled by user code, we must renew on the user's behalf */
|
|
|
+ tud_network_recv_renew();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
|
|
@@ -320,6 +414,11 @@ bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if ( _netd_itf.ecm_mode && (ep_addr == _netd_itf.ep_notif) )
|
|
|
+ {
|
|
|
+ if (sizeof(notify.ecm_buf.header) == xferred_bytes) ecm_report(false);
|
|
|
+ }
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -337,7 +436,7 @@ void tud_network_xmit(struct pbuf *p)
|
|
|
if (!can_xmit)
|
|
|
return;
|
|
|
|
|
|
- len = CFG_TUD_NET_PACKET_PREFIX_LEN;
|
|
|
+ len = (_netd_itf.ecm_mode) ? 0 : CFG_TUD_NET_PACKET_PREFIX_LEN;
|
|
|
data = transmitted + len;
|
|
|
|
|
|
for(q = p; q != NULL; q = q->next)
|
|
|
@@ -347,23 +446,15 @@ void tud_network_xmit(struct pbuf *p)
|
|
|
len += q->len;
|
|
|
}
|
|
|
|
|
|
-#if CFG_TUD_NET == OPT_NET_RNDIS
|
|
|
- rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
|
|
|
- memset(hdr, 0, sizeof(rndis_data_packet_t));
|
|
|
- hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
|
|
|
- hdr->MessageLength = len;
|
|
|
- hdr->DataOffset = sizeof(rndis_data_packet_t) - offsetof(rndis_data_packet_t, DataOffset);
|
|
|
- hdr->DataLength = len - sizeof(rndis_data_packet_t);
|
|
|
-#elif 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 */
|
|
|
-#endif
|
|
|
+ if (!_netd_itf.ecm_mode)
|
|
|
+ {
|
|
|
+ rndis_data_packet_t *hdr = (rndis_data_packet_t *)transmitted;
|
|
|
+ memset(hdr, 0, sizeof(rndis_data_packet_t));
|
|
|
+ hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
|
|
|
+ hdr->MessageLength = len;
|
|
|
+ hdr->DataOffset = sizeof(rndis_data_packet_t) - offsetof(rndis_data_packet_t, DataOffset);
|
|
|
+ hdr->DataLength = len - sizeof(rndis_data_packet_t);
|
|
|
+ }
|
|
|
|
|
|
do_in_xfer(transmitted, len);
|
|
|
}
|