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);