00001
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
00047
00048
00049
00050
00056
00057
00058 #include <string.h>
00059
00060 #include "FreeRTOS.h"
00061 #include "task.h"
00062
00063 #include "conf_usb.h"
00064 #include "usb_drv.h"
00065 #include "usb_task.h"
00066 #if USB_DEVICE_FEATURE == ENABLED
00067 #include "device_mass_storage_task.h"
00068 #endif
00069 #if USB_HOST_FEATURE == ENABLED
00070 #include "host_mass_storage_task.h"
00071 #endif
00072
00073 #include "shell.h"
00074
00075
00076
00077 #define MSG_NO_DEVICE "No supported device connected"CRLF
00078 #define MSG_REMOTE_WAKEUP_OK "Device supports remote wake-up"CRLF
00079 #define MSG_REMOTE_WAKEUP_KO "Device does not support remote wake-up"CRLF
00080 #define MSG_SELF_POWERED "Device is self-powered"CRLF
00081 #define MSG_BUS_POWERED "Device is bus-powered"CRLF
00082 #define MSG_USB_SUSPENDED "USB is suspended!"CRLF
00083 #define MSG_OK "OK"CRLF
00084 #define MSG_KO "KO"CRLF
00085 #define MSG_DEVICE_FULL_SPEED "Device is full-speed"CRLF
00086 #define MSG_DEVICE_LOW_SPEED "Device is low-speed"CRLF
00087
00088 #define MSG_COPY_LOGS_TO_KEY "Copying the log files to the USB key"CRLF
00089 #define MSG_MOVE_LOGS_TO_KEY "Moving the log files to the USB key"CRLF
00090 #define MSG_COPY_CFG_TO_LOCAL "Copying the /CFG directory from the USB key"CRLF
00091 #define MSG_COPY_WEB_TO_LOCAL "Copying the /WEB directory from the USB key"CRLF
00092
00093
00094
00095
00096
00097
00098 extern int sprintf(char *out, const char *format, ...);
00099
00100
00101 static eExecStatus prv_e_usbsys_sync_cp_ukey( eModId xModId, signed short FsNavId,
00102 signed portCHAR **ppcStringReply,
00103 signed portCHAR *pcStringMsgAction,
00104 U8 sync_direction, const char *pcdir_name,
00105 Bool bDeleteSrc );
00106
00112 Bool b_usbsys_start( void )
00113 {
00114
00115 usb_task_init();
00116 #if USB_DEVICE_FEATURE == ENABLED
00117
00118
00119 device_mass_storage_task_init();
00120 #endif
00121 #if USB_HOST_FEATURE == ENABLED
00122
00123
00124 host_mass_storage_task_init();
00125 #endif
00126
00127 return( TRUE );
00128 }
00129
00130
00150 eExecStatus e_usbsys_lsusb( eModId xModId, signed short FsNavId,
00151 int ac, signed portCHAR *av[],
00152 signed portCHAR **ppcStringReply )
00153 {
00154 #if USB_HOST_FEATURE == ENABLED
00155 signed portCHAR *pcStringToPrint;
00156 U8 i, j;
00157
00158
00159 if( NULL != ppcStringReply )
00160 *ppcStringReply = NULL;
00161
00162 if (!Is_host_ready() && !Is_host_suspended())
00163 {
00164 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
00165 return SHELL_EXECSTATUS_KO;
00166 }
00167
00168 pcStringToPrint = (signed portCHAR *)pvPortMalloc( SHELL_MAX_MSGOUT_LEN );
00169 if( NULL == pcStringToPrint )
00170 {
00171 return( SHELL_EXECSTATUS_KO );
00172 }
00173
00174 if (Is_host_suspended())
00175 {
00176 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_USB_SUSPENDED CRLF );
00177 }
00178
00179 sprintf( (char *)pcStringToPrint, "VID: 0x%.4X, PID: 0x%.4X\r\n"
00180 "Device MaxPower is %d mA\r\n"
00181 "%s"
00182 "%s",
00183 Get_VID(), Get_PID(),
00184 2 * Get_maxpower(),
00185 Is_device_self_powered() ? MSG_SELF_POWERED : MSG_BUS_POWERED,
00186 Is_usb_full_speed_mode() ? MSG_DEVICE_FULL_SPEED : MSG_DEVICE_LOW_SPEED );
00187 v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00188 sprintf( (char *)pcStringToPrint, "%s"
00189 "Supported interface(s): %u",
00190 Is_device_supports_remote_wakeup() ? MSG_REMOTE_WAKEUP_OK : MSG_REMOTE_WAKEUP_KO,
00191 Get_nb_supported_interface() );
00192 v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00193
00194 for (i = 0; i < Get_nb_supported_interface(); i++)
00195 {
00196 sprintf( (char *)pcStringToPrint, "\r\nInterface nb: %u, AltS nb: %u, Class: 0x%.2X,"
00197 " SubClass: 0x%.2X, Protocol: 0x%.2X\r\n" "\tAssociated Ep Nbrs:",
00198 Get_interface_number(i), Get_altset_nb(i), Get_class(i),
00199 Get_subclass(i), Get_protocol(i) );
00200 v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00201
00202 if (Get_nb_ep(i))
00203 {
00204 for (j = 0; j < Get_nb_ep(i); j++)
00205 {
00206 sprintf( (char *)pcStringToPrint, " %u", (U16)Get_ep_nbr(i, j) );
00207 v_shell_Print_String_To_Requester_Stream( xModId, pcStringToPrint );
00208 }
00209 }
00210 else
00211 {
00212 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)"None" );
00213 }
00214 }
00215
00216 vPortFree( pcStringToPrint );
00217
00218 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)CRLF );
00219 #else
00220 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
00221 #endif
00222 return( SHELL_EXECSTATUS_OK );
00223 }
00224
00225
00246 eExecStatus e_usbsys_cp_logs_to_key( eModId xModId, signed short FsNavId,
00247 int ac, signed portCHAR *av[],
00248 signed portCHAR **ppcStringReply )
00249 {
00250 return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply,
00251 (signed portCHAR *)MSG_COPY_LOGS_TO_KEY,
00252 HOST_TO_DEVICE, "LOG/", FALSE ) );
00253 }
00254
00255
00276 eExecStatus e_usbsys_mv_logs_to_key( eModId xModId, signed short FsNavId,
00277 int ac, signed portCHAR *av[],
00278 signed portCHAR **ppcStringReply )
00279 {
00280 return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply,
00281 (signed portCHAR *)MSG_MOVE_LOGS_TO_KEY,
00282 HOST_TO_DEVICE, "LOG/", TRUE ) );
00283 }
00284
00285
00307 eExecStatus e_usbsys_cp_cfg_to_local( eModId xModId, signed short FsNavId,
00308 int ac, signed portCHAR *av[],
00309 signed portCHAR **ppcStringReply )
00310 {
00311 return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply,
00312 (signed portCHAR *)MSG_COPY_CFG_TO_LOCAL,
00313 DEVICE_TO_HOST, "CFG/", FALSE ) );
00314 }
00315
00316
00339 eExecStatus e_usbsys_cp_web_to_local( eModId xModId, signed short FsNavId,
00340 int ac, signed portCHAR *av[],
00341 signed portCHAR **ppcStringReply )
00342 {
00343 return( prv_e_usbsys_sync_cp_ukey( xModId, FsNavId, ppcStringReply,
00344 (signed portCHAR *)MSG_COPY_WEB_TO_LOCAL,
00345 DEVICE_TO_HOST, "WEB/", FALSE ) );
00346 }
00347
00348
00349
00350
00351
00372 static eExecStatus prv_e_usbsys_sync_cp_ukey( eModId xModId, signed short FsNavId,
00373 signed portCHAR **ppcStringReply,
00374 signed portCHAR *pcStringMsgAction,
00375 U8 sync_direction, const char *pcdir_name,
00376 Bool bDeleteSrc )
00377 {
00378 if( NULL != ppcStringReply )
00379 *ppcStringReply = NULL;
00380
00381 #if USB_HOST_FEATURE == ENABLED
00382 if (!Is_host_ready() && !Is_host_suspended())
00383 {
00384 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_NO_DEVICE );
00385 return SHELL_EXECSTATUS_KO;
00386 }
00387
00388 v_shell_Print_String_To_Requester_Stream( xModId, pcStringMsgAction );
00389
00390 if( FALSE == host_mass_storage_task_sync_drives( FsNavId, sync_direction, pcdir_name, bDeleteSrc ) )
00391 {
00392 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_KO );
00393 }
00394 else
00395 {
00396 v_shell_Print_String_To_Requester_Stream( xModId, (signed portCHAR *)MSG_OK );
00397 }
00398
00399 #endif
00400 return( SHELL_EXECSTATUS_OK );
00401 }