usb_specific_request.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 #include "radio.h"
00047 #include "contiki.h"
00048 #include "config.h"
00049 #include "usb_drv.h"
00050 #include "usb_descriptors.h"
00051 #include "usb_specific_request.h"
00052 #include "rndis/rndis_protocol.h"
00053 #include "rndis/cdc_ecm.h"
00054 #include "rndis/rndis_task.h"
00055 #include "serial/uart_usb_lib.h"
00056 #include "storage/ctrl_access.h"
00057 #include "uip.h"
00058 #include <avr/pgmspace.h>
00059 #include <avr/eeprom.h>
00060 #include <string.h>
00061
00062
00063
00064
00065 #if USB_CONF_STORAGE
00066 bit ms_multiple_drive;
00067 #endif
00068
00069
00070 extern PGM_VOID_P pbuffer;
00071 extern U8 data_to_transfer;
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 Bool usb_user_read_request(U8 type, U8 request)
00090 {
00091 U16 wLength;
00092
00093 switch(request)
00094 {
00095 case SEND_ENCAPSULATED_COMMAND:
00096 Usb_read_byte();
00097 Usb_read_byte();
00098 Usb_read_byte();
00099 Usb_read_byte();
00100
00101 LSB(wLength) = Usb_read_byte();
00102 MSB(wLength) = Usb_read_byte();
00103 if((usb_configuration_nb==USB_CONFIG_RNDIS)||(usb_configuration_nb==USB_CONFIG_RNDIS_DEBUG))
00104 return rndis_send_encapsulated_command(wLength);
00105 else
00106 return FALSE;
00107 break;
00108
00109 case GET_ENCAPSULATED_COMMAND:
00110 Usb_read_byte();
00111 Usb_read_byte();
00112 Usb_read_byte();
00113 Usb_read_byte();
00114
00115 LSB(wLength) = Usb_read_byte();
00116 MSB(wLength) = Usb_read_byte();
00117 if((usb_configuration_nb==USB_CONFIG_RNDIS)||(usb_configuration_nb==USB_CONFIG_RNDIS_DEBUG))
00118 return rndis_get_encapsulated_command();
00119 else
00120 return FALSE;
00121 break;
00122
00123 case SET_ETHERNET_PACKET_FILTER:
00124 if((usb_configuration_nb==USB_CONFIG_ECM) || (usb_configuration_nb==USB_CONFIG_ECM_DEBUG)) {
00125 cdc_ecm_set_ethernet_packet_filter();
00126 return TRUE;
00127 } else
00128 return FALSE;
00129 break;
00130
00131 #if USB_CONF_STORAGE
00132 case MASS_STORAGE_RESET:
00133 Usb_ack_receive_setup();
00134 Usb_send_control_in();
00135 return TRUE;
00136 break;
00137
00138
00139 case GET_MAX_LUN:
00140 Usb_ack_receive_setup();
00141 Usb_write_byte( (get_nb_lun()-1) );
00142 Usb_send_control_in();
00143 ms_multiple_drive = 1;
00144 return TRUE;
00145 break;
00146 #endif
00147
00148 #if USB_CONF_SERIAL
00149
00150
00151 case GET_LINE_CODING:
00152 Usb_read_byte();
00153 Usb_read_byte();
00154 if(USB_CONFIG_HAS_DEBUG_PORT(usb_configuration_nb)) {
00155 cdc_get_line_coding();
00156 return TRUE;
00157 } else {
00158 return FALSE;
00159 }
00160 break;
00161
00162 case SET_LINE_CODING:
00163 Usb_read_byte();
00164 Usb_read_byte();
00165 if(USB_CONFIG_HAS_DEBUG_PORT(usb_configuration_nb)) {
00166 cdc_set_line_coding();
00167 return TRUE;
00168 } else {
00169 return FALSE;
00170 }
00171 break;
00172
00173 case SET_CONTROL_LINE_STATE:
00174 if(USB_CONFIG_HAS_DEBUG_PORT(usb_configuration_nb)) {
00175 cdc_set_control_line_state();
00176 return TRUE;
00177 } else {
00178 return FALSE;
00179 }
00180 break;
00181 #endif
00182 default:
00183 break;
00184
00185 }
00186
00187 return FALSE;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 Bool usb_user_get_descriptor(U8 type, U8 string)
00201 {
00202 switch(type)
00203 {
00204 case STRING_DESCRIPTOR:
00205 switch (string)
00206 {
00207 case LANG_ID:
00208 data_to_transfer = sizeof (usb_user_language_id);
00209 pbuffer = &(usb_user_language_id.bLength);
00210 return TRUE;
00211 break;
00212 default:
00213 return FALSE;
00214 }
00215 default:
00216 return FALSE;
00217 }
00218
00219 return FALSE;
00220 }
00221 static char itoh(unsigned char i) {
00222 char ret;
00223 ret = pgm_read_byte_near(PSTR("0123456789abcdef")+(i&0xF));
00224 return ret;
00225 }
00226 const char* usb_user_get_string_sram(U8 string_type) {
00227 static char serial[13];
00228 uint8_t i;
00229
00230 switch (string_type)
00231 {
00232 case USB_STRING_SERIAL:
00233 case USB_STRING_MAC_ADDRESS:
00234 {
00235 uint8_t mac_address[6];
00236 usb_eth_get_mac_address(mac_address);
00237
00238 for(i=0;i<6;i++) {
00239 serial[i*2] = itoh(mac_address[i]>>4);
00240 serial[i*2+1] = itoh(mac_address[i]);
00241 }
00242 }
00243 break;
00244 default:
00245 serial[0] = 0;
00246 break;
00247 }
00248
00249 return serial;
00250 }
00251
00252 PGM_P usb_user_get_string(U8 string_type) {
00253 switch (string_type)
00254 {
00255 case USB_STRING_MAN:
00256 return PSTR("Atmel");
00257
00258 case USB_STRING_PRODUCT:
00259 return PSTR("Jackdaw 6LoWPAN Adaptor");
00260
00261 case USB_STRING_CONFIG_COMPOSITE:
00262 return PSTR("RNDIS+Debug");
00263
00264 case USB_STRING_CONFIG_RNDIS:
00265 case USB_STRING_INTERFACE_RNDIS:
00266 return PSTR("RNDIS");
00267
00268 case USB_STRING_CONFIG_EEM:
00269 case USB_STRING_INTERFACE_EEM:
00270 return PSTR("CDC-EEM");
00271
00272 case USB_STRING_CONFIG_ECM:
00273 case USB_STRING_INTERFACE_ECM:
00274 return PSTR("CDC-ECM");
00275
00276 case USB_STRING_CONFIG_ECM_DEBUG:
00277 return PSTR("CDC-ECM+DEBUG");
00278
00279 case USB_STRING_INTERFACE_SERIAL:
00280 return PSTR("Debug Port");
00281
00282
00283
00284
00285
00286
00287 #if USB_CONF_STORAGE
00288 case USB_STRING_CONFIG_MS:
00289 case USB_STRING_INTERFACE_MS:
00290 return PSTR("Mass Storage");
00291 #endif
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304 default:
00305 return NULL;
00306 }
00307 }
00308
00309
00310
00311
00312
00313
00314
00315 void usb_user_endpoint_init(U8 conf_nb)
00316 {
00317 if(USB_CONFIG_HAS_DEBUG_PORT(conf_nb)) {
00318 uart_usb_configure_endpoints();
00319 }
00320
00321 switch(conf_nb) {
00322 case USB_CONFIG_ECM:
00323 case USB_CONFIG_ECM_DEBUG:
00324 cdc_ecm_configure_endpoints();
00325 break;
00326
00327 case USB_CONFIG_RNDIS_DEBUG:
00328 case USB_CONFIG_RNDIS:
00329 rndis_configure_endpoints();
00330 break;
00331 case USB_CONFIG_EEM:
00332 cdc_ecm_configure_endpoints();
00333
00334 break;
00335 #if USB_CONF_STORAGE
00336 case USB_CONFIG_MS:
00337 usb_configure_endpoint(VCP_INT_EP, \
00338 TYPE_INTERRUPT, \
00339 DIRECTION_IN, \
00340 SIZE_32, \
00341 ONE_BANK, \
00342 NYET_ENABLED);
00343
00344 usb_configure_endpoint(VCP_TX_EP, \
00345 TYPE_BULK, \
00346 DIRECTION_IN, \
00347 SIZE_32, \
00348 TWO_BANKS, \
00349 NYET_ENABLED);
00350
00351 usb_configure_endpoint(VCP_RX_EP, \
00352 TYPE_BULK, \
00353 DIRECTION_OUT, \
00354 SIZE_32, \
00355 TWO_BANKS, \
00356 NYET_ENABLED);
00357 Usb_reset_endpoint(VCP_INT_EP);
00358 Usb_reset_endpoint(VCP_TX_EP);
00359 Usb_reset_endpoint(VCP_RX_EP);
00360
00361 break;
00362 #endif
00363 }
00364 Led0_on();
00365 }
00366
00367 #if USB_CONF_SERIAL
00368
00369
00370 extern S_line_coding line_coding;
00371
00372
00373
00374
00375
00376 void cdc_get_line_coding(void)
00377 {
00378 Usb_ack_receive_setup();
00379 Usb_write_byte(LSB0(line_coding.dwDTERate));
00380 Usb_write_byte(LSB1(line_coding.dwDTERate));
00381 Usb_write_byte(LSB2(line_coding.dwDTERate));
00382 Usb_write_byte(LSB3(line_coding.dwDTERate));
00383 Usb_write_byte(line_coding.bCharFormat);
00384 Usb_write_byte(line_coding.bParityType);
00385 Usb_write_byte(line_coding.bDataBits);
00386
00387 Usb_send_control_in();
00388 }
00389
00390
00391
00392
00393
00394
00395 void cdc_set_line_coding (void)
00396 {
00397 Usb_ack_receive_setup();
00398 if(usb_endpoint_wait_for_receive_out()==0) {
00399 LSB0(line_coding.dwDTERate) = Usb_read_byte();
00400 LSB1(line_coding.dwDTERate) = Usb_read_byte();
00401 LSB2(line_coding.dwDTERate) = Usb_read_byte();
00402 LSB3(line_coding.dwDTERate) = Usb_read_byte();
00403 line_coding.bCharFormat = Usb_read_byte();
00404 line_coding.bParityType = Usb_read_byte();
00405 line_coding.bDataBits = Usb_read_byte();
00406 Usb_ack_receive_out();
00407
00408 Usb_send_control_in();
00409 usb_endpoint_wait_for_read_control_enabled();
00410 }
00411 }
00412
00413
00414
00415
00416
00417
00418
00419 void cdc_set_control_line_state (void)
00420 {
00421 U8 controlLineState = Usb_read_byte();
00422
00423 if (Usb_read_byte()) {};
00424 U8 interface = Usb_read_byte();
00425
00426 Usb_ack_receive_setup();
00427 Usb_send_control_in();
00428 usb_endpoint_wait_for_read_control_enabled();
00429
00430 if(interface == INTERFACE2_NB) {
00431 uart_usb_set_control_line_state(controlLineState);
00432 }
00433 }
00434 #endif
00435
00436 Bool usb_user_set_alt_interface(U8 interface, U8 alt_setting) {
00437 return FALSE;
00438 if((interface==ECM_INTERFACE0_NB) && ((usb_configuration_nb==USB_CONFIG_ECM) || (usb_configuration_nb==USB_CONFIG_ECM_DEBUG))) {
00439
00440
00441 usb_eth_set_active(alt_setting);
00442 }
00443 return TRUE;
00444 }
00445