add TUD_EPBUF_DEF for ecm rndis, also separate notify and control buffer, use edpt_claim() to prevent race condition

This commit is contained in:
hathach 2024-11-22 20:09:29 +07:00
parent 1eb72af433
commit 5c18a32aaa
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
2 changed files with 129 additions and 183 deletions

View File

@ -43,8 +43,6 @@ static usb_eth_stat_t usb_eth_stat = { 0, 0, 0, 0 };
static uint32_t oid_packet_filter = 0x0000000; static uint32_t oid_packet_filter = 0x0000000;
static rndis_state_t rndis_state; static rndis_state_t rndis_state;
CFG_TUD_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t ndis_report[8] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
static const uint32_t OIDSupportedList[] = static const uint32_t OIDSupportedList[] =
{ {
OID_GEN_SUPPORTED_LIST, OID_GEN_SUPPORTED_LIST,
@ -76,8 +74,8 @@ static const uint32_t OIDSupportedList[] =
static void *encapsulated_buffer; static void *encapsulated_buffer;
static void rndis_report(void) static void rndis_report(void) {
{ uint8_t ndis_report[8] = { 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
netd_report(ndis_report, sizeof(ndis_report)); netd_report(ndis_report, sizeof(ndis_report));
} }

View File

@ -35,13 +35,18 @@
#include "net_device.h" #include "net_device.h"
#include "rndis_protocol.h" #include "rndis_protocol.h"
void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networking/rndis_reports.c */ extern void rndis_class_set_handler(uint8_t *data, int size); /* found in ./misc/networking/rndis_reports.c */
#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t)
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
#define NETD_PACKET_SIZE (CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN)
#define NETD_CONTROL_SIZE 120
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF // MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
typedef struct typedef struct {
{
uint8_t itf_num; // Index number of Management Interface, +1 for Data Interface 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 itf_data_alt; // Alternate setting of Data Interface. 0 : inactive, 1 : active
@ -55,78 +60,44 @@ typedef struct
// TODO since configuration descriptor may not be long-lived memory, we should // TODO since configuration descriptor may not be long-lived memory, we should
// keep a copy of endpoint attribute instead // keep a copy of endpoint attribute instead
uint8_t const * ecm_desc_epdata; uint8_t const * ecm_desc_epdata;
} netd_interface_t; } netd_interface_t;
#define CFG_TUD_NET_PACKET_PREFIX_LEN sizeof(rndis_data_packet_t) typedef struct ecm_notify_struct {
#define CFG_TUD_NET_PACKET_SUFFIX_LEN 0
CFG_TUD_MEM_SECTION CFG_TUSB_MEM_ALIGN tu_static
uint8_t received[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
CFG_TUD_MEM_SECTION CFG_TUSB_MEM_ALIGN tu_static
uint8_t transmitted[CFG_TUD_NET_PACKET_PREFIX_LEN + CFG_TUD_NET_MTU + CFG_TUD_NET_PACKET_PREFIX_LEN];
struct ecm_notify_struct
{
tusb_control_request_t header; tusb_control_request_t header;
uint32_t downlink, uplink; uint32_t downlink, uplink;
}; } ecm_notify_t;
tu_static const struct ecm_notify_struct ecm_notify_nc = typedef struct {
{ TUD_EPBUF_DEF(rx, NETD_PACKET_SIZE);
.header = { TUD_EPBUF_DEF(tx, NETD_PACKET_SIZE);
.bmRequestType = 0xA1,
.bRequest = 0 /* NETWORK_CONNECTION aka NetworkConnection */,
.wValue = 1 /* Connected */,
.wLength = 0,
},
};
tu_static const struct ecm_notify_struct ecm_notify_csc = TUD_EPBUF_DEF(notify, sizeof(ecm_notify_t));
{ TUD_EPBUF_DEF(ctrl, NETD_CONTROL_SIZE);
.header = { } netd_epbuf_t;
.bmRequestType = 0xA1,
.bRequest = 0x2A /* CONNECTION_SPEED_CHANGE aka ConnectionSpeedChange */,
.wLength = 8,
},
.downlink = 9728000,
.uplink = 9728000,
};
// TODO remove CFG_TUD_MEM_SECTION, control internal buffer is already in this special section
CFG_TUD_MEM_SECTION CFG_TUSB_MEM_ALIGN tu_static union
{
uint8_t rndis_buf[120];
struct ecm_notify_struct ecm_buf;
} notify;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION // INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// TODO remove CFG_TUD_MEM_SECTION static netd_interface_t _netd_itf;
CFG_TUD_MEM_SECTION tu_static netd_interface_t _netd_itf; CFG_TUD_MEM_SECTION static netd_epbuf_t _netd_epbuf;
static bool can_xmit;
tu_static bool can_xmit; void tud_network_recv_renew(void) {
usbd_edpt_xfer(0, _netd_itf.ep_out, _netd_epbuf.rx, NETD_PACKET_SIZE);
void tud_network_recv_renew(void)
{
usbd_edpt_xfer(0, _netd_itf.ep_out, received, sizeof(received));
} }
static void do_in_xfer(uint8_t *buf, uint16_t len) static void do_in_xfer(uint8_t *buf, uint16_t len) {
{
can_xmit = false; can_xmit = false;
usbd_edpt_xfer(0, _netd_itf.ep_in, buf, len); usbd_edpt_xfer(0, _netd_itf.ep_in, buf, len);
} }
void netd_report(uint8_t *buf, uint16_t len) void netd_report(uint8_t *buf, uint16_t len) {
{ const uint8_t rhport = 0;
uint8_t const rhport = 0; len = tu_min16(len, sizeof(ecm_notify_t));
// skip if previous report not yet acknowledged by host TU_VERIFY(usbd_edpt_claim(rhport, _netd_itf.ep_notif), );
if ( usbd_edpt_busy(rhport, _netd_itf.ep_notif) ) return; memcpy(_netd_epbuf.notify, buf, len);
usbd_edpt_xfer(rhport, _netd_itf.ep_notif, buf, len); usbd_edpt_xfer(rhport, _netd_itf.ep_notif, _netd_epbuf.notify, len);
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@ -140,15 +111,12 @@ bool netd_deinit(void) {
return true; return true;
} }
void netd_reset(uint8_t rhport) void netd_reset(uint8_t rhport) {
{
(void) rhport; (void) rhport;
netd_init(); netd_init();
} }
uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len) {
{
bool const is_rndis = (TUD_RNDIS_ITF_CLASS == itf_desc->bInterfaceClass && bool const is_rndis = (TUD_RNDIS_ITF_CLASS == itf_desc->bInterfaceClass &&
TUD_RNDIS_ITF_SUBCLASS == itf_desc->bInterfaceSubClass && TUD_RNDIS_ITF_SUBCLASS == itf_desc->bInterfaceSubClass &&
TUD_RNDIS_ITF_PROTOCOL == itf_desc->bInterfaceProtocol); TUD_RNDIS_ITF_PROTOCOL == itf_desc->bInterfaceProtocol);
@ -172,18 +140,16 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
uint8_t const * p_desc = tu_desc_next( itf_desc ); uint8_t const * p_desc = tu_desc_next( itf_desc );
// Communication Functional Descriptors // Communication Functional Descriptors
while ( TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len ) while (TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && drv_len <= max_len) {
{
drv_len += tu_desc_len(p_desc); drv_len += tu_desc_len(p_desc);
p_desc = tu_desc_next(p_desc); p_desc = tu_desc_next(p_desc);
} }
// notification endpoint (if any) // notification endpoint (if any)
if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) ) if (TUSB_DESC_ENDPOINT == tu_desc_type(p_desc)) {
{ TU_ASSERT(usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), 0);
TU_ASSERT( usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), 0 );
_netd_itf.ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress; _netd_itf.ep_notif = ((tusb_desc_endpoint_t const*)p_desc)->bEndpointAddress;
drv_len += tu_desc_len(p_desc); drv_len += tu_desc_len(p_desc);
p_desc = tu_desc_next(p_desc); p_desc = tu_desc_next(p_desc);
@ -196,27 +162,24 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
// - 1 : IN & OUT endpoints for active networking // - 1 : IN & OUT endpoints for active networking
TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc), 0); TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc), 0);
do do {
{
tusb_desc_interface_t const * data_itf_desc = (tusb_desc_interface_t const *) p_desc; 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, 0); TU_ASSERT(TUSB_CLASS_CDC_DATA == data_itf_desc->bInterfaceClass, 0);
drv_len += tu_desc_len(p_desc); drv_len += tu_desc_len(p_desc);
p_desc = tu_desc_next(p_desc); p_desc = tu_desc_next(p_desc);
}while( _netd_itf.ecm_mode && (TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) && (drv_len <= max_len) ); } while (_netd_itf.ecm_mode && (TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) && (drv_len <= max_len));
// Pair of endpoints // Pair of endpoints
TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc), 0); TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc), 0);
if ( _netd_itf.ecm_mode ) if (_netd_itf.ecm_mode) {
{
// ECM by default is in-active, save the endpoint attribute // ECM by default is in-active, save the endpoint attribute
// to open later when received setInterface // to open later when received setInterface
_netd_itf.ecm_desc_epdata = p_desc; _netd_itf.ecm_desc_epdata = p_desc;
}else } else {
{
// Open endpoint pair for RNDIS // 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), 0 ); TU_ASSERT(usbd_open_edpt_pair(rhport, p_desc, 2, TUSB_XFER_BULK, &_netd_itf.ep_out, &_netd_itf.ep_in), 0);
tud_network_init_cb(); tud_network_init_cb();
@ -232,38 +195,50 @@ uint16_t netd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint1
return drv_len; return drv_len;
} }
static void ecm_report(bool nc) static void ecm_report(bool nc) {
{ const ecm_notify_t ecm_notify_nc = {
notify.ecm_buf = (nc) ? ecm_notify_nc : ecm_notify_csc; .header = {
notify.ecm_buf.header.wIndex = _netd_itf.itf_num; .bmRequestType = 0xA1,
netd_report((uint8_t *)&notify.ecm_buf, (nc) ? sizeof(notify.ecm_buf.header) : sizeof(notify.ecm_buf)); .bRequest = 0, /* NETWORK_CONNECTION aka NetworkConnection */
.wValue = 1, /* Connected */
.wLength = 0,
},
};
const ecm_notify_t ecm_notify_csc = {
.header = {
.bmRequestType = 0xA1,
.bRequest = 0x2A, /* CONNECTION_SPEED_CHANGE aka ConnectionSpeedChange */
.wLength = 8,
},
.downlink = 9728000,
.uplink = 9728000,
};
ecm_notify_t notify = (nc) ? ecm_notify_nc : ecm_notify_csc;
notify.header.wIndex = _netd_itf.itf_num;
netd_report((uint8_t *)&notify, (nc) ? sizeof(notify.header) : sizeof(notify));
} }
// Invoked when a control transfer occurred on an interface of this class // Invoked when a control transfer occurred on an interface of this class
// Driver response accordingly to the request and the transfer stage (setup/data/ack) // Driver response accordingly to the request and the transfer stage (setup/data/ack)
// return false to stall control endpoint (e.g unsupported request) // return false to stall control endpoint (e.g unsupported request)
bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t const * request) {
{ if (stage == CONTROL_STAGE_SETUP) {
if ( stage == CONTROL_STAGE_SETUP ) switch (request->bmRequestType_bit.type) {
{
switch ( request->bmRequestType_bit.type )
{
case TUSB_REQ_TYPE_STANDARD: case TUSB_REQ_TYPE_STANDARD:
switch ( request->bRequest ) switch (request->bRequest) {
{ case TUSB_REQ_GET_INTERFACE: {
case TUSB_REQ_GET_INTERFACE: uint8_t const req_itfnum = (uint8_t)request->wIndex;
{
uint8_t const req_itfnum = (uint8_t) request->wIndex;
TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum); TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum);
tud_control_xfer(rhport, request, &_netd_itf.itf_data_alt, 1); tud_control_xfer(rhport, request, &_netd_itf.itf_data_alt, 1);
} }
break; break;
case TUSB_REQ_SET_INTERFACE: case TUSB_REQ_SET_INTERFACE: {
{ uint8_t const req_itfnum = (uint8_t)request->wIndex;
uint8_t const req_itfnum = (uint8_t) request->wIndex; uint8_t const req_alt = (uint8_t)request->wValue;
uint8_t const req_alt = (uint8_t) request->wValue;
// Only valid for Data Interface with Alternate is either 0 or 1 // Only valid for Data Interface with Alternate is either 0 or 1
TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum && req_alt < 2); TU_VERIFY(_netd_itf.itf_num+1 == req_itfnum && req_alt < 2);
@ -273,14 +248,14 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
_netd_itf.itf_data_alt = req_alt; _netd_itf.itf_data_alt = req_alt;
if ( _netd_itf.itf_data_alt ) if (_netd_itf.itf_data_alt) {
{
// TODO since we don't actually close endpoint // TODO since we don't actually close endpoint
// hack here to not re-open it // hack here to not re-open it
if ( _netd_itf.ep_in == 0 && _netd_itf.ep_out == 0 ) if (_netd_itf.ep_in == 0 && _netd_itf.ep_out == 0) {
{
TU_ASSERT(_netd_itf.ecm_desc_epdata); 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) ); 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 // TODO should be merge with RNDIS's after endpoint opened
// Also should have opposite callback for application to disable network !! // Also should have opposite callback for application to disable network !!
@ -288,8 +263,7 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
can_xmit = true; // we are ready to transmit a packet can_xmit = true; // we are ready to transmit a packet
tud_network_recv_renew(); // prepare for incoming packets tud_network_recv_renew(); // prepare for incoming packets
} }
}else } else {
{
// TODO close the endpoint pair // TODO close the endpoint pair
// For now pretend that we did, this should have no harm since host won't try to // For now pretend that we did, this should have no harm since host won't try to
// communicate with the endpoints again // communicate with the endpoints again
@ -306,29 +280,22 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
break; break;
case TUSB_REQ_TYPE_CLASS: case TUSB_REQ_TYPE_CLASS:
TU_VERIFY (_netd_itf.itf_num == request->wIndex); TU_VERIFY(_netd_itf.itf_num == request->wIndex);
if (_netd_itf.ecm_mode) if (_netd_itf.ecm_mode) {
{
/* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */ /* the only required CDC-ECM Management Element Request is SetEthernetPacketFilter */
if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest) if (0x43 /* SET_ETHERNET_PACKET_FILTER */ == request->bRequest) {
{
tud_control_xfer(rhport, request, NULL, 0); tud_control_xfer(rhport, request, NULL, 0);
ecm_report(true); ecm_report(true);
} }
} } else {
else if (request->bmRequestType_bit.direction == TUSB_DIR_IN) {
{ rndis_generic_msg_t* rndis_msg = (rndis_generic_msg_t*)((void*)_netd_epbuf.ctrl);
if (request->bmRequestType_bit.direction == TUSB_DIR_IN)
{
rndis_generic_msg_t *rndis_msg = (rndis_generic_msg_t *) ((void*) notify.rndis_buf);
uint32_t msglen = tu_le32toh(rndis_msg->MessageLength); uint32_t msglen = tu_le32toh(rndis_msg->MessageLength);
TU_ASSERT(msglen <= sizeof(notify.rndis_buf)); TU_ASSERT(msglen <= NETD_CONTROL_SIZE);
tud_control_xfer(rhport, request, notify.rndis_buf, (uint16_t) msglen); tud_control_xfer(rhport, request, _netd_epbuf.ctrl, (uint16_t)msglen);
} } else {
else tud_control_xfer(rhport, request, _netd_epbuf.ctrl, NETD_CONTROL_SIZE);
{
tud_control_xfer(rhport, request, notify.rndis_buf, (uint16_t) sizeof(notify.rndis_buf));
} }
} }
break; break;
@ -336,17 +303,13 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
// unsupported request // unsupported request
default: return false; default: return false;
} }
} } else if (stage == CONTROL_STAGE_DATA) {
else if ( stage == CONTROL_STAGE_DATA )
{
// Handle RNDIS class control OUT only // Handle RNDIS class control OUT only
if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS && if (request->bmRequestType_bit.type == TUSB_REQ_TYPE_CLASS &&
request->bmRequestType_bit.direction == TUSB_DIR_OUT && request->bmRequestType_bit.direction == TUSB_DIR_OUT &&
_netd_itf.itf_num == request->wIndex) _netd_itf.itf_num == request->wIndex) {
{ if (!_netd_itf.ecm_mode) {
if ( !_netd_itf.ecm_mode ) rndis_class_set_handler(_netd_epbuf.ctrl, request->wLength);
{
rndis_class_set_handler(notify.rndis_buf, request->wLength);
} }
} }
} }
@ -354,92 +317,77 @@ bool netd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t
return true; return true;
} }
static void handle_incoming_packet(uint32_t len) static void handle_incoming_packet(uint32_t len) {
{ uint8_t* pnt = _netd_epbuf.rx;
uint8_t *pnt = received;
uint32_t size = 0; uint32_t size = 0;
if (_netd_itf.ecm_mode) if (_netd_itf.ecm_mode) {
{
size = len; size = len;
} } else {
else rndis_data_packet_t* r = (rndis_data_packet_t*)((void*)pnt);
{ if (len >= sizeof(rndis_data_packet_t)) {
rndis_data_packet_t *r = (rndis_data_packet_t *) ((void*) pnt); if ((r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len)) {
if (len >= sizeof(rndis_data_packet_t)) if ((r->DataOffset + offsetof(rndis_data_packet_t, DataOffset) + r->DataLength) <= len) {
if ( (r->MessageType == REMOTE_NDIS_PACKET_MSG) && (r->MessageLength <= len)) pnt = &_netd_epbuf.rx[r->DataOffset + offsetof(rndis_data_packet_t, DataOffset)];
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; size = r->DataLength;
} }
} }
}
}
if (!tud_network_recv_cb(pnt, (uint16_t) size)) if (!tud_network_recv_cb(pnt, (uint16_t)size)) {
{
/* if a buffer was never handled by user code, we must renew on the user's behalf */ /* if a buffer was never handled by user code, we must renew on the user's behalf */
tud_network_recv_renew(); tud_network_recv_renew();
} }
} }
bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) bool netd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes) {
{ (void)rhport;
(void) rhport; (void)result;
(void) result;
/* new packet received */ /* new packet received */
if ( ep_addr == _netd_itf.ep_out ) if (ep_addr == _netd_itf.ep_out) {
{
handle_incoming_packet(xferred_bytes); handle_incoming_packet(xferred_bytes);
} }
/* data transmission finished */ /* data transmission finished */
if ( ep_addr == _netd_itf.ep_in ) if (ep_addr == _netd_itf.ep_in) {
{
/* TinyUSB requires the class driver to implement ZLP (since ZLP usage is class-specific) */ /* TinyUSB requires the class driver to implement ZLP (since ZLP usage is class-specific) */
if ( xferred_bytes && (0 == (xferred_bytes % CFG_TUD_NET_ENDPOINT_SIZE)) ) if (xferred_bytes && (0 == (xferred_bytes % CFG_TUD_NET_ENDPOINT_SIZE))) {
{
do_in_xfer(NULL, 0); /* a ZLP is needed */ do_in_xfer(NULL, 0); /* a ZLP is needed */
} } else {
else
{
/* we're finally finished */ /* we're finally finished */
can_xmit = true; can_xmit = true;
} }
} }
if ( _netd_itf.ecm_mode && (ep_addr == _netd_itf.ep_notif) ) if (_netd_itf.ecm_mode && (ep_addr == _netd_itf.ep_notif)) {
{ if (sizeof(tusb_control_request_t) == xferred_bytes) {
if (sizeof(notify.ecm_buf.header) == xferred_bytes) ecm_report(false); ecm_report(false);
}
} }
return true; return true;
} }
bool tud_network_can_xmit(uint16_t size) bool tud_network_can_xmit(uint16_t size) {
{
(void)size; (void)size;
return can_xmit; return can_xmit;
} }
void tud_network_xmit(void *ref, uint16_t arg) void tud_network_xmit(void *ref, uint16_t arg) {
{ if (!can_xmit) {
uint8_t *data;
uint16_t len;
if (!can_xmit)
return; return;
}
len = (_netd_itf.ecm_mode) ? 0 : CFG_TUD_NET_PACKET_PREFIX_LEN; uint16_t len = (_netd_itf.ecm_mode) ? 0 : CFG_TUD_NET_PACKET_PREFIX_LEN;
data = transmitted + len; uint8_t* data = _netd_epbuf.tx + len;
len += tud_network_xmit_cb(data, ref, arg); len += tud_network_xmit_cb(data, ref, arg);
if (!_netd_itf.ecm_mode) if (!_netd_itf.ecm_mode) {
{ rndis_data_packet_t *hdr = (rndis_data_packet_t *) ((void*) _netd_epbuf.tx);
rndis_data_packet_t *hdr = (rndis_data_packet_t *) ((void*) transmitted);
memset(hdr, 0, sizeof(rndis_data_packet_t)); memset(hdr, 0, sizeof(rndis_data_packet_t));
hdr->MessageType = REMOTE_NDIS_PACKET_MSG; hdr->MessageType = REMOTE_NDIS_PACKET_MSG;
hdr->MessageLength = len; hdr->MessageLength = len;
@ -447,7 +395,7 @@ void tud_network_xmit(void *ref, uint16_t arg)
hdr->DataLength = len - sizeof(rndis_data_packet_t); hdr->DataLength = len - sizeof(rndis_data_packet_t);
} }
do_in_xfer(transmitted, len); do_in_xfer(_netd_epbuf.tx, len);
} }
#endif #endif