62 #define PRINTF_P printf_P
66 static void usb_get_descriptor(
void);
67 static void usb_set_address(
void);
68 static void usb_set_configuration(
void);
69 static void usb_clear_feature(
void);
70 static void usb_set_feature(
void);
71 static void usb_get_status(
void);
72 static void usb_get_configuration(
void);
73 static void usb_get_interface (
void);
74 static void usb_set_interface (
void);
80 static U8 endpoint_status[NB_ENDPOINTS];
91 static U8 bmRequestType;
95 usb_mode_t usb_mode = rndis_debug;
99 extern FLASH S_usb_user_configuration_descriptor_network usb_user_configuration_descriptor_network;
101 extern FLASH S_usb_user_configuration_descriptor_composite usb_user_configuration_descriptor_composite;
128 if (0x80 == bmRequestType) { usb_get_descriptor(); }
132 case GET_CONFIGURATION:
133 if (0x80 == bmRequestType) { usb_get_configuration(); }
138 if (0x00 == bmRequestType) { usb_set_address(); }
142 case SET_CONFIGURATION:
143 if (0x00 == bmRequestType) { usb_set_configuration(); }
148 if (0x02 >= bmRequestType) { usb_clear_feature(); }
153 if (0x02 >= bmRequestType) { usb_set_feature(); }
158 if ((0x7F < bmRequestType) & (0x82 >= bmRequestType))
159 { usb_get_status(); }
164 if (bmRequestType == 0x81) { usb_get_interface(); }
170 if (bmRequestType == 0x01) {usb_set_interface();}
202 void usb_set_address(
void)
223 void usb_set_configuration(
void )
225 U8 configuration_number;
237 Usb_set_configuration_action();
245 U16 requested_length;
247 const char* user_str;
249 user_str = usb_user_get_string_sram(string_type);
259 const U8 actual_descriptor_size = 2+strlen(user_str)*2;
261 if (requested_length > actual_descriptor_size) {
262 zlp = ((actual_descriptor_size % EP_CONTROL_LENGTH) == 0);
263 requested_length = actual_descriptor_size;
268 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
279 requested_length -= 2;
282 if(!requested_length) {
288 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
293 while(requested_length != 0)
295 if(nb_byte==EP_CONTROL_LENGTH)
304 requested_length -=2;
318 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
325 usb_endpoint_wait_for_receive_out();
331 U16 requested_length;
335 user_str = usb_user_get_string(string_type);
348 const U8 actual_descriptor_size = 2+strlen_P(user_str)*2;
350 if (requested_length > actual_descriptor_size) {
351 zlp = ((actual_descriptor_size % EP_CONTROL_LENGTH) == 0);
352 requested_length = actual_descriptor_size;
357 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
364 if(requested_length) {
371 if(requested_length) {
377 if(!requested_length) {
383 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
388 while(requested_length != 0)
390 if(nb_byte==EP_CONTROL_LENGTH) {
398 if(requested_length) {
416 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
423 usb_endpoint_wait_for_receive_out();
438 void usb_get_descriptor(
void)
440 U8 LSBwLength, MSBwLength;
451 switch (descriptor_type)
453 case DEVICE_DESCRIPTOR:
454 data_to_transfer = Usb_get_dev_desc_length();
455 pbuffer = Usb_get_dev_desc_pointer();
457 case CONFIGURATION_DESCRIPTOR:
458 data_to_transfer = Usb_get_conf_desc_length(string_type);
459 pbuffer = Usb_get_conf_desc_pointer(string_type);
462 case STRING_DESCRIPTOR:
463 if(string_type!=LANG_ID) {
481 if (byteswereread==0) {
490 if ((LSBwLength > data_to_transfer) || (MSBwLength)) {
491 if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp =
TRUE; }
492 else { zlp =
FALSE; }
494 LSBwLength = data_to_transfer;
497 data_to_transfer = LSBwLength;
502 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
508 while(data_to_transfer != 0) {
510 if(nb_byte++==EP_CONTROL_LENGTH)
527 if(usb_endpoint_wait_for_read_control_enabled()!=0) {
534 usb_endpoint_wait_for_receive_out();
545 void usb_get_configuration(
void)
552 usb_endpoint_wait_for_receive_out();
563 void usb_get_status(
void)
572 switch(bmRequestType)
583 wIndex = wIndex & MSK_EP_DIR;
595 usb_endpoint_wait_for_receive_out();
606 void usb_set_feature(
void)
612 if (bmRequestType == INTERFACE_TYPE)
616 else if (bmRequestType == ENDPOINT_TYPE)
621 if (wValue == FEATURE_ENDPOINT_HALT)
625 if (wIndex == EP_CONTROL)
635 endpoint_status[wIndex] = 0x01;
658 void usb_clear_feature(
void)
664 if (bmRequestType == ZERO_TYPE)
668 else if (bmRequestType == INTERFACE_TYPE)
672 else if (bmRequestType == ENDPOINT_TYPE)
677 if (wValue == FEATURE_ENDPOINT_HALT)
684 if(wIndex != EP_CONTROL)
691 endpoint_status[wIndex] = 0x00;
714 void usb_get_interface (
void)
725 void usb_set_interface (
void)
735 if(usb_user_set_alt_interface(interface, alt_setting)) {
740 usb_endpoint_wait_for_receive_out();