summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2020-03-28 14:33:17 +0700
committerGitHub <[email protected]>2020-03-28 14:33:17 +0700
commitdc6f90eaf76fee3961b034e442dbfb81ad01108a (patch)
treef566e9d16a624af93c36e833a574b572f339df53
parent033b295761e6d536e842c8443cd20cae1527a194 (diff)
parent622a6c77a10b3b9278f78c9b597bdfd4efd1dd68 (diff)
Merge pull request #311 from majbthrd/usbnet_ecm_macos
usbnet: tweak CDC-ECM after MacOS testing
-rw-r--r--examples/device/net_lwip_webserver/src/main.c6
-rw-r--r--examples/device/net_lwip_webserver/src/usb_descriptors.c2
-rw-r--r--src/class/net/net_device.c20
3 files changed, 24 insertions, 4 deletions
diff --git a/examples/device/net_lwip_webserver/src/main.c b/examples/device/net_lwip_webserver/src/main.c
index c193aeb0f..fe904e8e8 100644
--- a/examples/device/net_lwip_webserver/src/main.c
+++ b/examples/device/net_lwip_webserver/src/main.c
@@ -53,7 +53,8 @@ static struct pbuf *received_frame;
/* this is used by this code, ./class/net/net_driver.c, and usb_descriptors.c */
/* ideally speaking, this should be generated from the hardware's unique ID (if available) */
-const uint8_t tud_network_mac_address[6] = {0x20,0x89,0x84,0x6A,0x96,0x00};
+/* it is suggested that the first two bytes are 0x02,0x02 to indicate a link-local address */
+const uint8_t tud_network_mac_address[6] = {0x02,0x02,0x84,0x6A,0x96,0x00};
/* network parameters of this MCU */
static const ip_addr_t ipaddr = IPADDR4_INIT_BYTES(192, 168, 7, 1);
@@ -124,8 +125,11 @@ static void init_lwip(void)
struct netif *netif = &netif_data;
lwip_init();
+
+ /* the lwip virtual MAC address must be different from the host's; to ensure this, we toggle the LSbit */
netif->hwaddr_len = sizeof(tud_network_mac_address);
memcpy(netif->hwaddr, tud_network_mac_address, sizeof(tud_network_mac_address));
+ netif->hwaddr[5] ^= 0x01;
netif = netif_add(netif, &ipaddr, &netmask, &gateway, NULL, netif_init_cb, ip_input);
netif_set_default(netif);
diff --git a/examples/device/net_lwip_webserver/src/usb_descriptors.c b/examples/device/net_lwip_webserver/src/usb_descriptors.c
index c7a8cc767..a4eba205f 100644
--- a/examples/device/net_lwip_webserver/src/usb_descriptors.c
+++ b/examples/device/net_lwip_webserver/src/usb_descriptors.c
@@ -112,7 +112,7 @@ uint8_t const desc_configuration[] =
#if CFG_TUD_NET == OPT_NET_ECM
// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
- TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU),
+ TUD_CDC_ECM_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, STRID_MAC, 0x81, 64, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE, CFG_TUD_NET_MTU),
#elif CFG_TUD_NET == OPT_NET_RNDIS
// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
TUD_RNDIS_DESCRIPTOR(ITF_NUM_CDC, STRID_INTERFACE, 0x81, 8, EPNUM_CDC, 0x80 | EPNUM_CDC, CFG_TUD_NET_ENDPOINT_SIZE),
diff --git a/src/class/net/net_device.c b/src/class/net/net_device.c
index 7bb11d57c..68520625a 100644
--- a/src/class/net/net_device.c
+++ b/src/class/net/net_device.c
@@ -63,7 +63,15 @@ typedef struct
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_RNDIS
+#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 */,
+ .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
@@ -197,7 +205,15 @@ 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_RNDIS
+#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 *)&notify, 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;