From 7c3064fb746daf713c6dc75aaad2d3ba26e0a133 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 1 Feb 2013 02:23:21 +0000 Subject: send packet works as well git-svn-id: https://svn.spreadspace.org/avr/trunk@113 aa12f405-d877-488e-9caf-2d797e2a1cc7 --- usb-eth/usb-eth.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) (limited to 'usb-eth') 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 #include #include +#include #include "util.h" #include "led.h" @@ -39,6 +40,9 @@ #include #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(); } -- cgit v1.2.3