59 #include "sicslow_ethernet.h"
62 #include <avr/pgmspace.h>
63 #include <util/delay.h>
66 #include "rndis/cdc_ecm.h"
67 #include "rndis/cdc_eem.h"
69 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
71 #define PRINTF_P printf_P
82 #define IAD_TIMEOUT_DETACH 400
83 #define IAD_TIMEOUT_ATTACH 800
85 #define RNDIS_TIMEOUT_DETACH 900
86 #define RNDIS_TIMEOUT_ATTACH 1000
88 #define PBUF ((rndis_data_packet_t *) usb_eth_data_buffer)
93 uint64_t usb_ethernet_addr = 0x010000000002ULL;
101 uint8_t usb_eth_is_active = 1;
104 uint8_t usb_eth_packet_is_available() {
110 uint8_t usb_eth_ready_for_next_packet() {
111 #ifdef USB_ETH_HOOK_IS_READY_FOR_INBOUND_PACKET
112 return USB_ETH_HOOK_IS_READY_FOR_INBOUND_PACKET();
120 void rxtx_led_update(
void)
135 if(led2_timer&(1<<2))
160 if(((led2_timer-1)&(1<<2)))
164 #if USB_ETH_CONF_MASS_STORAGE_FALLBACK
166 usb_eth_setup_timeout_fallback_check() {
167 extern uint8_t fingerPresent;
171 static uint16_t iad_fail_timeout, rndis_fail_timeout;
172 if (usb_mode == rndis_debug) {
174 if (iad_fail_timeout == IAD_TIMEOUT_DETACH) {
180 iad_fail_timeout = 0;
188 }
else if (iad_fail_timeout == IAD_TIMEOUT_ATTACH) {
191 usb_mode = mass_storage;
193 usb_mode = rndis_only;
201 (iad_fail_timeout > IAD_TIMEOUT_DETACH) ||
205 iad_fail_timeout = 0;
213 if (usb_mode == rndis_only) {
215 if (rndis_fail_timeout == RNDIS_TIMEOUT_DETACH) {
218 }
else if (rndis_fail_timeout == RNDIS_TIMEOUT_ATTACH) {
219 usb_mode = mass_storage;
225 if ( ( (rndis_state != rndis_data_initialized)) ||
226 (rndis_fail_timeout > RNDIS_TIMEOUT_DETACH) ) {
227 rndis_fail_timeout++;
229 rndis_fail_timeout = 0;
235 PROCESS(usb_eth_process,
"USB Ethernet process");
252 #if USB_ETH_CONF_MASS_STORAGE_FALLBACK
253 usb_eth_setup_timeout_fallback_check();
257 case USB_CONFIG_RNDIS_DEBUG:
258 case USB_CONFIG_RNDIS:
260 if(rndis_process()) {
274 case USB_CONFIG_ECM_DEBUG:
276 if(cdc_ecm_process()) {
303 uint8_t
usb_eth_send(uint8_t * senddata, uint16_t sendlen, uint8_t led)
307 if(!usb_eth_is_active) {
308 USB_ETH_HOOK_TX_ERROR(
"Inactive");
314 USB_ETH_HOOK_TX_ERROR(
"Device not enumerated");
319 case USB_CONFIG_RNDIS_DEBUG:
320 case USB_CONFIG_RNDIS:
324 ret = eem_send(senddata, sendlen, led);
327 case USB_CONFIG_ECM_DEBUG:
328 ret = ecm_send(senddata, sendlen, led);
341 usb_eth_set_active(uint8_t active) {
342 if(usb_eth_is_active!=active) {
344 case USB_CONFIG_RNDIS_DEBUG:
345 case USB_CONFIG_RNDIS:
346 usb_eth_is_active = active;
352 case USB_CONFIG_ECM_DEBUG:
353 cdc_ecm_set_active(active);
354 usb_eth_is_active = active;
362 usb_eth_get_mac_address(uint8_t dest[6]) {
363 memcpy(dest,&usb_ethernet_addr,6);
367 usb_eth_set_mac_address(
const uint8_t src[6]) {
368 memcpy(&usb_ethernet_addr,src,6);
int etimer_expired(struct etimer *et)
Check if an event timer has expired.
#define Is_device_enumerated()
Returns true when device connected and correctly enumerated with an host.
#define PROCESS_BEGIN()
Define the beginning of a process.
Header file for the uIP TCP/IP stack.
#define Usb_detach()
detaches from USB bus
void rndis_send_interrupt(void)
Send an interrupt over the interrupt endpoint to the host.
This file contains the user callback functions corresponding to the application.
This file contains the USB driver routines.
#define NULL
The null pointer.
U8 usb_configuration_nb
Public : (U8) usb_configuration_nb Store the number of the USB configuration used by the USB device w...
#define Usb_attach()
attaches to USB bus
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
This file manages the RNDIS task.
void watchdog_periodic(void)
Writes the WDT clear sequence.
#define PROCESS_WAIT_EVENT_UNTIL(c)
Wait for an event to be posted to the process, with an extra condition.
void tx_end_led(void)
This will enable the TRX_END LED for a period.
#define PROCESS(name, strname)
Declare a process.
uint8_t usb_eth_send(uint8_t *senddata, uint16_t sendlen, uint8_t led)
Sends a single ethernet frame over USB using appropriate low-level protocol (EEM or RNDIS) ...
uint8_t rndis_send(uint8_t *senddata, uint16_t sendlen, uint8_t led)
Send data over RNDIS interface, data is in uipbuf and length is uiplen.
uint8_t usb_eth_data_buffer[64]
Temp data buffer when adding RNDIS headers.
uint8_t led1_timer
Timers for LEDs.
void etimer_set(struct etimer *et, clock_time_t interval)
Set an event timer.
This file contains the usb parameters that uniquely identify the application through descriptor table...
#define Usb_select_endpoint(ep)
selects the endpoint number to interface with the CPU
#define Is_usb_read_enabled()
tests if endpoint read allowed
#define CLOCK_SECOND
A second, measured in system clock time.
void rx_start_led(void)
This will enable the RX_START LED for a period.