diff options
Diffstat (limited to 'usb-eth/usb-eth.c')
-rw-r--r-- | usb-eth/usb-eth.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/usb-eth/usb-eth.c b/usb-eth/usb-eth.c index 59bf963..b0d6eda 100644 --- a/usb-eth/usb-eth.c +++ b/usb-eth/usb-eth.c @@ -24,6 +24,7 @@ #include <avr/wdt.h> #include <avr/interrupt.h> #include <avr/power.h> +#include <string.h> #include "util.h" #include "led.h" @@ -39,6 +40,9 @@ #include <LUFA/Drivers/USB/USB.h> #include "lufa-descriptor-rndis.h" +#define ADAPTER_MAC_ADDR {0x02, 0x00, 0x02, 0x00, 0x02, 0x00} +#define MY_MAC_ADDR {0x01, 0x02, 0x03, 0x04, 0x05, 0x06} + /** LUFA RNDIS Class driver interface configuration and state information. This structure is * passed to all RNDIS Class driver functions, so that multiple instances of the same class * within a device can be differentiated from one another. @@ -62,7 +66,7 @@ USB_ClassInfo_RNDIS_Device_t Ethernet_RNDIS_Interface = .NotificationEndpointDoubleBank = false, .AdapterVendorDescription = "LUFA RNDIS Adapter", - .AdapterMACAddress = {{0x02, 0x00, 0x02, 0x00, 0x02, 0x00}}, + .AdapterMACAddress = {ADAPTER_MAC_ADDR}, }, }; @@ -80,7 +84,24 @@ void EVENT_USB_Device_ControlRequest(void) /* end LUFA RNDIS Class driver specific definitions*/ -uint8_t recv_buf[1514]; + +typedef uint8_t mac_addr_t[6]; +typedef struct __attribute__((__packed__)) +{ + mac_addr_t dest; + mac_addr_t src; + uint16_t ether_type; +} ethernet_frame_header_t; + +typedef struct { + uint8_t data[1550]; + uint16_t len; +} ethernet_buf_t; + +ethernet_buf_t eth_recv_buf; +ethernet_frame_header_t* eth_recv_hdr = (ethernet_frame_header_t*)eth_recv_buf.data; +mac_addr_t my_mac = MY_MAC_ADDR; + int main(void) { @@ -97,8 +118,12 @@ int main(void) if (RNDIS_Device_IsPacketReceived(&Ethernet_RNDIS_Interface)) { led_on(); - uint16_t len = sizeof(recv_buf); - RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface, &recv_buf, &len); + RNDIS_Device_ReadPacket(&Ethernet_RNDIS_Interface, eth_recv_buf.data, &(eth_recv_buf.len)); + + memcpy(eth_recv_hdr->dest, eth_recv_hdr->src, sizeof(mac_addr_t)); + memcpy(eth_recv_hdr->src, my_mac, sizeof(mac_addr_t)); + + RNDIS_Device_SendPacket(&Ethernet_RNDIS_Interface, eth_recv_buf.data, eth_recv_buf.len); led_off(); } |