Пример #1
0
/**
 * \brief RNDIS Process
 *
 *   This is the link between USB and the "good stuff". In this routine data
 *   is received and processed by RNDIS, CDC-ECM, or CDC-EEM
 */
PROCESS_THREAD(usb_eth_process, ev, data_proc)
{
	static struct etimer et;

	PROCESS_BEGIN();

	while(1) {
		rxtx_led_update();

#if USB_ETH_CONF_MASS_STORAGE_FALLBACK
		usb_eth_setup_timeout_fallback_check();
#endif
		
		switch(usb_configuration_nb) {
			case USB_CONFIG_RNDIS_DEBUG:
			case USB_CONFIG_RNDIS:
				if(Is_device_enumerated()) {
					if(rndis_process()) {
						etimer_set(&et, CLOCK_SECOND/80);
					} else {
						Led0_toggle();
						etimer_set(&et, CLOCK_SECOND/8);
					}
				}
				break;
			case USB_CONFIG_EEM:
				if(Is_device_enumerated())
					cdc_eem_process();
				etimer_set(&et, CLOCK_SECOND/80);
				break;
			case USB_CONFIG_ECM:
			case USB_CONFIG_ECM_DEBUG:
				if(Is_device_enumerated()) {
					if(cdc_ecm_process()) {
						etimer_set(&et, CLOCK_SECOND/80);
					} else {
						Led0_toggle();
						etimer_set(&et, CLOCK_SECOND/8);
					}
				}
				break;
			default:
				Led0_toggle();
				etimer_set(&et, CLOCK_SECOND/4);
				break;
		}


		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et)||(usb_eth_packet_is_available()&&usb_eth_ready_for_next_packet()));
	} // while(1)

	PROCESS_END();
}
Пример #2
0
uint8_t
cdc_ecm_process(void) {
	static uint8_t doInit = 1;
	
	Usb_select_endpoint(RX_EP);

	if(!Is_usb_endpoint_enabled()) {
		return 0;
	}

	if (doInit) {
#ifdef USB_ETH_HOOK_INIT
		USB_ETH_HOOK_INIT();
#endif
		cdc_ecm_notify_network_connection(1);
		cdc_ecm_notify_connection_speed_change(250000,250000);
		doInit = 0;
		if(usb_ecm_packet_filter & PACKET_TYPE_PROMISCUOUS) {
#if RF230BB
			rf230_set_promiscuous_mode(true);
#else		
			radio_set_trx_state(RX_ON);
#endif
		}

		// Select again, just to make sure.
		Usb_select_endpoint(RX_EP);
	}

	if(!usb_eth_is_active) {
		// If we aren't active, just eat the packets.
		if(Is_usb_read_enabled()) {
			Usb_ack_receive_out();
		}
		return 0;
	}

	//Connected!
	Led0_on();

	if(Is_usb_read_enabled()) {
		uint16_t bytecounter;
		uint16_t bytes_received = 0;
		U8 * buffer = uip_buf;

		if(!usb_eth_ready_for_next_packet()) {
			// Since we aren't ready for a packet yet,
			// just return.
			goto bail;
		}

#ifdef USB_ETH_HOOK_RX_START
		USB_ETH_HOOK_RX_START();
#endif

		while((bytecounter=Usb_byte_counter_8())==CDC_ECM_DATA_ENDPOINT_SIZE) {
			while((bytes_received<USB_ETH_MTU) && (bytecounter--)) {
				*buffer++ = Usb_read_byte();
				bytes_received++;
			}
			bytes_received+=bytecounter+1;

			//ACK previous data
			Usb_ack_receive_out();

			//Wait for new data
			if(usb_endpoint_wait_for_read_enabled()!=0) {
				USB_ETH_HOOK_RX_ERROR("Timeout: read enabled");
				goto bail;
			}
		}
		bytecounter = Usb_byte_counter_8();
		while((bytes_received<USB_ETH_MTU) && (bytecounter--)) {
			*buffer++ = Usb_read_byte();
			bytes_received++;
		}
		bytes_received+=bytecounter+1;
		
		//Ack final data packet
		Usb_ack_receive_out();

		//PRINTF_P(PSTR("cdc_ecm: Got packet %d bytes long\n"),bytes_received);

#ifdef USB_ETH_HOOK_RX_END
		USB_ETH_HOOK_RX_END();
#endif
		
		//Send data over RF or to local stack
		if(bytes_received<=USB_ETH_MTU) {

			USB_ETH_HOOK_HANDLE_INBOUND_PACKET(uip_buf,bytes_received);
		} else {
			USB_ETH_HOOK_RX_ERROR("Oversized packet");
		}
	}
bail:
	return 1;
}