10 #define INTERRUPT_IN 0x83
13 struct uip_eth_addr default_uip_ethaddr = {{0x02,0x00,0x00,0x00,0x00,0x02}};
16 handle_cdc_eth_requests()
21 static const struct USBRequestHandler cdc_eth_request_handler =
25 handle_cdc_eth_requests
28 static struct USBRequestHandlerHook cdc_eth_request_hook =
31 &cdc_eth_request_handler
34 static USBBuffer recv_buffer;
37 static USBBuffer xmit_buffer[3];
43 recv_buffer.next =
NULL;
44 recv_buffer.data = recv_data;
46 recv_buffer.flags = USB_BUFFER_SHORT_END | USB_BUFFER_NOTIFY;
54 memcpy(xmit_data, uip_buf,
uip_len);
55 xmit_buffer[0].next =
NULL;
57 xmit_buffer[0].flags = USB_BUFFER_NOTIFY | USB_BUFFER_SHORT_END;
58 xmit_buffer[0].data = xmit_data;
61 usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]);
66 {
UIP_FW_NETIF(172,16,0,1, 255,255,255,255, usbeth_send)};
68 #define BUF ((struct uip_eth_hdr *)&uip_buf[0])
70 PROCESS(usb_eth_process,
"USB ethernet");
75 usb_register_request_handler(&cdc_eth_request_hook);
77 usb_set_ep_event_process(DATA_OUT, process_current);
78 usb_set_global_event_process(process_current);
85 if (ev == PROCESS_EVENT_EXIT)
break;
86 if (ev == PROCESS_EVENT_POLL) {
87 unsigned int events = usb_get_global_events();
89 if (events & USB_EVENT_CONFIG) {
90 if (usb_get_current_configuration() != 0) {
91 printf(
"Configured\n");
92 usb_setup_bulk_endpoint(DATA_IN);
93 usb_setup_bulk_endpoint(DATA_OUT);
94 usb_setup_interrupt_endpoint(INTERRUPT_IN);
96 usb_submit_recv_buffer(DATA_OUT, &recv_buffer);
99 static const uint8_t foo[4] = {0x12,0x34,0x56,0x78};
100 xmit_buffer[0].next =
NULL;
101 xmit_buffer[0].left =
sizeof(foo);
102 xmit_buffer[0].flags = USB_BUFFER_SHORT_END;
103 xmit_buffer[0].data = &foo;
105 usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]);
109 usb_disable_endpoint(DATA_IN);
110 usb_disable_endpoint(DATA_OUT);
111 usb_disable_endpoint(INTERRUPT_IN);
115 events = usb_get_ep_events(DATA_OUT);
116 if (events & USB_EP_EVENT_NOTIFICATION) {
117 uip_len =
sizeof(recv_data) - recv_buffer.left;
119 memcpy(uip_buf, recv_data,
uip_len);
121 if(BUF->type ==
uip_htons(UIP_ETHTYPE_IPV6)) {
122 uip_neighbor_add(&IPBUF->srcipaddr, &BUF->src);
126 if(BUF->type ==
uip_htons(UIP_ETHTYPE_IP)) {
129 }
else if(BUF->type ==
uip_htons(UIP_ETHTYPE_ARP)) {
135 memcpy(xmit_data, uip_buf,
uip_len);
136 xmit_buffer[0].next =
NULL;
137 xmit_buffer[0].data = xmit_data;
139 xmit_buffer[0].flags = USB_BUFFER_SHORT_END;
141 usb_submit_xmit_buffer(DATA_IN, &xmit_buffer[0]);
147 usb_submit_recv_buffer(DATA_OUT, &recv_buffer);