int32_t  Shell_exit(int32_t argc, char *argv[] )
{
   bool              print_usage, shorthelp = FALSE;
   int32_t               return_code = SHELL_EXIT_SUCCESS;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv ); 

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      shell_ptr = Shell_get_context( argv );
      shell_ptr->EXIT = TRUE;
      if (shell_ptr->COMMAND_FP != stdin)  {
         fclose(shell_ptr->COMMAND_FP);
      }   
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s\n", argv[0]);
      } else  {
         printf("Usage: %s\n", argv[0]);
      }
   }
   return return_code;
} /* Endbody */
Exemple #2
0
int_32  Shell_command_list(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv ); 
   SHELL_COMMAND_PTR    command_ptr;
   uint_32              i; 

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc==1)  {
         for (i=0,command_ptr = shell_ptr->COMMAND_LIST_PTR; 
              command_ptr->COMMAND != NULL; 
              i++,command_ptr++)  
          {
            printf("%-8s ", command_ptr->COMMAND);
            if ((i&7)==7) printf("\n");
         } /* Endwhile */
         if ((i&7)!=0) printf("\n");        
      } else {  
         print_usage = TRUE;
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s\n", argv[0]);
      } else  {
         printf("Usage: %s\n", argv[0]);
      }
   }
   return return_code;
} /* Endbody */
Exemple #3
0
int_32  Shell_help(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   SHELL_COMMAND_PTR    command_ptr; 

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc==1)  {
         shell_ptr->ARGV[1] = "help";
         shell_ptr->ARGV[2] = "short"; 
         shell_ptr->ARGV[3] = NULL; 
         printf("Available commands:\n");
         command_ptr = shell_ptr->COMMAND_LIST_PTR; 
         while (command_ptr->COMMAND != NULL)  {
            shell_ptr->ARGV[0] = command_ptr->COMMAND;
            printf("   ");
            return_code = (*command_ptr->SHELL_FUNC)(3, shell_ptr->ARGV);
            command_ptr++;        
         } /* Endwhile */        
      } else {
         /* Help on a specific command */
         if (argc==2)  {
            shell_ptr->ARGV[0] = argv[1];
            shell_ptr->ARGV[1] = "help";
            shell_ptr->ARGV[2] = "usage"; 
            shell_ptr->ARGV[3] = NULL; 
            command_ptr = shell_ptr->COMMAND_LIST_PTR; 
            while (command_ptr->COMMAND != NULL)  {
               if (strcmp(argv[0], command_ptr->COMMAND) == 0)  {
                  return_code = (*command_ptr->SHELL_FUNC)(3, shell_ptr->ARGV);
                  break;   
               } 
               command_ptr++;        
            } /* Endwhile */
            if (command_ptr->COMMAND == NULL)  {
               printf("Error, command \"%s\" not registered.\n", argv[1] );
            }
         } else {
            print_usage = TRUE;
         }    
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<command>]\n", argv[0]);
      } else  {
         printf("Usage: %s [<command>]\n", argv[0]);
         printf("   <command> = command to get help on\n");
      }
   }
   return return_code;
} /* Endbody */
Exemple #4
0
int32_t  Shell_flush_cache(int32_t argc, char *argv[] )
{ /* Body */
   bool                    print_usage, shorthelp = FALSE;
   int32_t                     return_code = SHELL_EXIT_SUCCESS;
   int fd;
   char                   *name_ptr = NULL;
   SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv);


   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 2) {
         fprintf(shell_ptr->STDOUT, "Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         if (argc==2) {
            name_ptr = argv[1];
         } else {
            name_ptr = Shell_get_current_filesystem_name(argv);
         }

         if (_nio_supp_validate_device(name_ptr)) {
            fd = open(name_ptr, O_RDWR);
            if (0 > fd)  {
               fprintf(shell_ptr->STDOUT, "Error, unable to access file system\n" );
               return_code = SHELL_EXIT_ERROR;
            } else  {
               write(fd, NULL, 0); //This flushes fd.
               close(fd);
            }
         }
      }
   }


   if (print_usage)  {
      if (shorthelp)  {
         fprintf(shell_ptr->STDOUT, "%s <filesys:>\n", argv[0]);
      } else  {
         fprintf(shell_ptr->STDOUT, "Usage: %s <filesys:>\n", argv[0]);
         fprintf(shell_ptr->STDOUT, "   filesys: = name of MFS file system\n");
      }
   }
   return return_code;
} /* Endbody */
Exemple #5
0
int_32  Shell_erase(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   uint_32           block;

   MQX_FILE_PTR      fd;
   char_ptr          abs_path;   
   boolean           cache_enabled=TRUE;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   char                 buf[SHELL_BLOCK_SIZE];
   
   MQX_FILE_PTR   nandflash_hdl;
    
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
   
    nandflash_hdl = fopen("nandflash:", NULL);
   
    if ((argc < 2) || (argc >= 3)) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      }
      
      block = _io_atoi( argv[1]);
            
      if(MQX_OK != ioctl(nandflash_hdl, NANDFLASH_IOCTL_ERASE_BLOCK, (void*)block))
         printf("\n\nErasing block %d failed.",block);
      else
         printf("\n\nErasing block %d passed.\n",block);
   }
      
 if (print_usage)  {
      if (shorthelp)  {
         printf("%s <block>\n", argv[0]);
      } else  {
         printf("Usage: %s <block> ", argv[0]);
         printf("   <block>      = number of block to erase\n");
      
      }
   }     
} /* Endbody */
Exemple #6
0
int32_t  Shell_abort(int32_t argc, char *argv[] ) {
   SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv);
   bool     print_usage, shorthelp = FALSE;
   int32_t      return_code = SHELL_EXIT_SUCCESS;
   _task_id    task_id;
   uint32_t     result;

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      
      if (argc == 2)  {
         task_id = _task_get_id_from_name( argv[1] );
         if (task_id == MQX_NULL_TASK_ID)  {
            fprintf(shell_ptr->STDOUT, "No task named %s running.\n",argv[1]);
            return_code = SHELL_EXIT_ERROR;
         } else  {
            result = _task_abort(task_id);
            if (result == MQX_OK)  {  
               fprintf(shell_ptr->STDOUT, "Task %s aborted.\n",argv[1]);
            } else  {
               fprintf(shell_ptr->STDOUT, "Unable to abort task %s.\n",argv[1]);
               return_code = SHELL_EXIT_ERROR;
            }
         }
      } else  {
         fprintf(shell_ptr->STDOUT, "Error, %s invoked with incorrect number of arguments\n", argv[0]);
         print_usage = TRUE;
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         fprintf(shell_ptr->STDOUT, "%s <taskname>\n", argv[0]);
      } else  {
         fprintf(shell_ptr->STDOUT, "Usage: %s <taskname>\n", argv[0]);
         fprintf(shell_ptr->STDOUT, "   <taskname> = MQX Task name\n");
      }
   }

   return return_code;
} /* Endbody */
Exemple #7
0
int32_t  Shell_pwd(int32_t argc, char *argv[] )
{ /* Body */
   bool                    print_usage, shorthelp = FALSE;
   int32_t                     error = 0, return_code = SHELL_EXIT_SUCCESS;
   MQX_FILE_PTR               fs_ptr;
   SHELL_CONTEXT_PTR          shell_ptr = Shell_get_context( argv );    

   
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc >  1) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else   {
         fs_ptr = Shell_get_current_filesystem(argv);
         if (fs_ptr == NULL)  {
            printf("Error, file system not mounted\n" );
            return_code = SHELL_EXIT_ERROR;
         } else  {
            printf("%s%s\n", shell_ptr->CURRENT_DEVICE_NAME, shell_ptr->CURRENT_DIR);
         }
      }
   }
      
      
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s \n", argv[0]);
      } else  {
         printf("Usage: %s \n", argv[0]);
      }
   }
   return return_code;
}
Exemple #8
0
/*FUNCTION*-----------------------------------------------------------------
*
* Function Name  : Shell_iwconfig
* Returned Value : ERROR code on error else success
* Comments       :
*
*END------------------------------------------------------------------*/

int32_t Shell_iwconfig(int32_t argc, char *argv[] )
{ /* Body */
    bool                 print_usage, shorthelp = FALSE;
    int32_t                  return_code = SHELL_EXIT_SUCCESS;
    uint32_t                 enet_device = BSP_DEFAULT_ENET_DEVICE, index = 1;
    SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv);

    print_usage = Shell_check_help_request (argc, argv, &shorthelp);

    if (!print_usage)
    {
        if (argc > index)
        {
            if (Shell_parse_number (argv[index], &enet_device))
            {
                index++;
            }
        }

        if (enet_device >= BSP_ENET_DEVICE_COUNT)
        {
            fprintf(shell_ptr->STDOUT, "Wrong number of ethernet device (%d)!\n", enet_device);
            return_code = SHELL_EXIT_ERROR;
        }
        else
        {
            if (argc > index)
            {
                if (strcmp (argv[index], "ssid") == 0)
                {
                    return_code = Shell_iwconfig_set_ssid(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "mode") == 0)
                {
                    return_code = Shell_iwconfig_set_mode(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "commit") == 0)
                {
                    return_code = Shell_iwconfig_commit(shell_ptr->STDOUT, enet_device);
                }
                else if (strcmp (argv[index], "key") == 0)
                {
                    return_code = Shell_iwconfig_set_wep_key(shell_ptr->STDOUT, enet_device,index,argc,argv);
                }
                else if (strcmp (argv[index], "sectype") == 0)
                {
                    return_code = Shell_iwconfig_set_sec_type(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "passphrase") == 0)
                {
                    return_code = Shell_iwconfig_set_passphrase(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "power") == 0)
                {
                    return_code = Shell_iwconfig_set_power(shell_ptr->STDOUT, enet_device,index,argc,argv);
                }
                else if (strcmp (argv[index], "scan") == 0)
                {
                    return_code = Shell_iwconfig_set_scan(shell_ptr->STDOUT, enet_device,index,argc,argv);
                }

                else if (strcmp (argv[index], "help") == 0)
                {
                    return_code = SHELL_EXIT_ERROR;
                }
                else
                {
                    fprintf(shell_ptr->STDOUT, "Unknown iwconfig command!\n");
                    return_code = SHELL_EXIT_ERROR;
                }
            }
            else if (argc == 1)
            {
                char data[32];
                uint32_t error;
                error = iwcfg_get_essid (enet_device,(char *)data);
                if (error != 0)
                   return_code = SHELL_EXIT_ERROR;

                fprintf(shell_ptr->STDOUT, "ssid=%s\n",data);
                iwcfg_get_mode (enet_device,(char *)data);
                fprintf(shell_ptr->STDOUT, "mode=%s\n",data);
                iwcfg_get_sectype (enet_device,(char *)data);
                fprintf(shell_ptr->STDOUT, "security type=%s\n",data);
                if (strcmp(data,"wep") == 0)
                {
                    uint32_t def_key_index;
                    iwcfg_get_wep_key(enet_device,(char *)data,&def_key_index);
                    fprintf(shell_ptr->STDOUT, "wep key=%s\n",data);
                    fprintf(shell_ptr->STDOUT, "default key index=%d\n",def_key_index);
                }
                if (strcmp(data,"wpa") == 0)
                {
                    unsigned char p_phrase[65];
                    iwcfg_get_passphrase(enet_device,(char *)p_phrase);
                    fprintf(shell_ptr->STDOUT, "   passphrase=%s\n",p_phrase);
                }
                if (strcmp(data,"wpa2") == 0)
                {
                    unsigned char p_phrase[65];
                    iwcfg_get_passphrase(enet_device,(char *)p_phrase);
                    fprintf(shell_ptr->STDOUT, "   passphrase=%s\n",p_phrase);
                }
            }
        }
    }
    else
    {
        return_code = SHELL_EXIT_ERROR;
    }

    if ((print_usage) || (return_code != SHELL_EXIT_SUCCESS))
    {
        if (shorthelp)
        {
            fprintf(shell_ptr->STDOUT, "%s [<device>] [<command>]\n", argv[0]);
        }
        else
        {
            fprintf(shell_ptr->STDOUT, "Use iwconfig commands if Wifi device is initialized\n");
            fprintf(shell_ptr->STDOUT, "Usage: %s [<command>]\n", argv[0]);
            fprintf(shell_ptr->STDOUT, "  Commands:\n");
            fprintf(shell_ptr->STDOUT, "    ssid   [<network id>]   = Set SSID on device to associate with AP\n");
            fprintf(shell_ptr->STDOUT, "    mode   [<network mode>] = Set network mode on device\n");
            fprintf(shell_ptr->STDOUT, "    commit                  = Forces the card to apply all pending changes.\n");
            fprintf(shell_ptr->STDOUT, "    key [<WEP Key>],[<key index>]  = Sets WEP Keys and enables WEP security\n");
            fprintf(shell_ptr->STDOUT, "    passphrase [<passphrase string>] = Enables WPA2 security and sets the passphrase\n");
            fprintf(shell_ptr->STDOUT, "    sectype [<security type>]= Sets the Security for WiFi Device    \n");
            fprintf(shell_ptr->STDOUT, "    power   [<on>] [<off>] [period] [<value>] = Enables or disables the power mode and sets the sleep duration.\n");
            fprintf(shell_ptr->STDOUT, "    scan                   = Scan for Access Points and display there infrmation\n");
            fprintf(shell_ptr->STDOUT, "    help                   = Display commands list and parameters.\n");
            fprintf(shell_ptr->STDOUT, "  Parameters:\n");
            fprintf(shell_ptr->STDOUT, "    <network id>   = name of the wireless network\n");
            fprintf(shell_ptr->STDOUT, "    <network mode> = type of Wireless network. Possible values: managed or adhoc\n");
            fprintf(shell_ptr->STDOUT, "    <WEP Key>      = WEP Security Key. If set to none, WEP security is disabled.\n");
            fprintf(shell_ptr->STDOUT, "    <key index>    = Four keys can be set as WEP keys.Set index as [1],[2],[3],[4]\n");
            fprintf(shell_ptr->STDOUT, "                   = To change which key is the currently active key, just enter [index]\n");
            fprintf(shell_ptr->STDOUT, "                   = (without entering any key value).\n");
            fprintf(shell_ptr->STDOUT, "    <security type>= wep,wpa,wpa2 or none\n");
            fprintf(shell_ptr->STDOUT, "    <passphrase string> = pass phrase string\n");
            fprintf(shell_ptr->STDOUT, "    <on>                = enables power mode\n");
            fprintf(shell_ptr->STDOUT, "    <off>               = disables power mode\n");
            fprintf(shell_ptr->STDOUT, "    <value>             = sleep duration\n");
        }
    }

    return return_code;
} /* Endbody */

#else /* (BSP_ENET_DEVICE_COUNT > 0) */
int32_t Shell_iwconfig(int32_t argc, char *argv[] )
{
   SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv);
   fprintf(shell_ptr->STDOUT, "Cannot use this command, no enet device driver available in this BSP.");
   return SHELL_EXIT_ERROR;
}
#endif /* (BSP_ENET_DEVICE_COUNT > 0) */
#else  /* BSP_ENET_DEVICE_COUNT */
int32_t Shell_iwconfig(int32_t argc, char *argv[] )
{
   SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv);
   fprintf(shell_ptr->STDOUT, "Cannot use this command, no enet device driver available in this BSP.");
   return SHELL_EXIT_ERROR;
}
Exemple #9
0
int32_t Shell_iwconfig(int32_t argc, char *argv[] )
{ /* Body */
    bool                 print_usage, shorthelp = FALSE;
    int32_t                  return_code = SHELL_EXIT_SUCCESS;
    uint32_t                 enet_device = BSP_DEFAULT_ENET_DEVICE, index = 1;
    SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv);

    print_usage = Shell_check_help_request (argc, argv, &shorthelp);

    if (!print_usage)
    {
        if (argc > index)
        {
            if (Shell_parse_number (argv[index], &enet_device))
            {
                index++;
            }
        }

        if (enet_device >= BSP_ENET_DEVICE_COUNT)
        {
            fprintf(shell_ptr->STDOUT, "Wrong number of ethernet device (%d)!\n", enet_device);
            return_code = SHELL_EXIT_ERROR;
        }
        else
        {
            if (argc > index)
            {
                if (strcmp (argv[index], "ssid") == 0)
                {
                    return_code = Shell_iwconfig_set_ssid(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "mode") == 0)
                {
                    return_code = Shell_iwconfig_set_mode(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "commit") == 0)
                {
                    return_code = Shell_iwconfig_commit(shell_ptr->STDOUT, enet_device);
                }
                else if (strcmp (argv[index], "key") == 0)
                {
                    return_code = Shell_iwconfig_set_wep_key(shell_ptr->STDOUT, enet_device,index,argc,argv);
                }
                else if (strcmp (argv[index], "sectype") == 0)
                {
                    return_code = Shell_iwconfig_set_sec_type(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "passphrase") == 0)
                {
                    return_code = Shell_iwconfig_set_passphrase(shell_ptr->STDOUT, enet_device,argv[index+1]);
                }
                else if (strcmp (argv[index], "power") == 0)
                {
                    return_code = Shell_iwconfig_set_power(shell_ptr->STDOUT, enet_device,index,argc,argv);
                }
                else if (strcmp (argv[index], "scan") == 0)
                {
                    return_code = Shell_iwconfig_set_scan(shell_ptr->STDOUT, enet_device,index,argc,argv);
                }

                else if (strcmp (argv[index], "help") == 0)
                {
                    return_code = SHELL_EXIT_ERROR;
                }
                else
                {
                    fprintf(shell_ptr->STDOUT, "Unknown iwconfig command!\n");
                    return_code = SHELL_EXIT_ERROR;
                }
            }
            else if (argc == 1)
            {
                char data[32];
                uint32_t error;
                error = iwcfg_get_essid (enet_device,(char *)data);
                if (error != 0)
                   return_code = SHELL_EXIT_ERROR;

                fprintf(shell_ptr->STDOUT, "ssid=%s\n",data);
                iwcfg_get_mode (enet_device,(char *)data);
                fprintf(shell_ptr->STDOUT, "mode=%s\n",data);
                iwcfg_get_sectype (enet_device,(char *)data);
                fprintf(shell_ptr->STDOUT, "security type=%s\n",data);
                if (strcmp(data,"wep") == 0)
                {
                    uint32_t def_key_index;
                    iwcfg_get_wep_key(enet_device,(char *)data,&def_key_index);
                    fprintf(shell_ptr->STDOUT, "wep key=%s\n",data);
                    fprintf(shell_ptr->STDOUT, "default key index=%d\n",def_key_index);
                }
                if (strcmp(data,"wpa") == 0)
                {
                    unsigned char p_phrase[65];
                    iwcfg_get_passphrase(enet_device,(char *)p_phrase);
                    fprintf(shell_ptr->STDOUT, "   passphrase=%s\n",p_phrase);
                }
                if (strcmp(data,"wpa2") == 0)
                {
                    unsigned char p_phrase[65];
                    iwcfg_get_passphrase(enet_device,(char *)p_phrase);
                    fprintf(shell_ptr->STDOUT, "   passphrase=%s\n",p_phrase);
                }
            }
        }
    }
    else
    {
        return_code = SHELL_EXIT_ERROR;
    }

    if ((print_usage) || (return_code != SHELL_EXIT_SUCCESS))
    {
        if (shorthelp)
        {
            fprintf(shell_ptr->STDOUT, "%s [<device>] [<command>]\n", argv[0]);
        }
        else
        {
            fprintf(shell_ptr->STDOUT, "Use iwconfig commands if Wifi device is initialized\n");
            fprintf(shell_ptr->STDOUT, "Usage: %s [<command>]\n", argv[0]);
            fprintf(shell_ptr->STDOUT, "  Commands:\n");
            fprintf(shell_ptr->STDOUT, "    ssid   [<network id>]   = Set SSID on device to associate with AP\n");
            fprintf(shell_ptr->STDOUT, "    mode   [<network mode>] = Set network mode on device\n");
            fprintf(shell_ptr->STDOUT, "    commit                  = Forces the card to apply all pending changes.\n");
            fprintf(shell_ptr->STDOUT, "    key [<WEP Key>],[<key index>]  = Sets WEP Keys and enables WEP security\n");
            fprintf(shell_ptr->STDOUT, "    passphrase [<passphrase string>] = Enables WPA2 security and sets the passphrase\n");
            fprintf(shell_ptr->STDOUT, "    sectype [<security type>]= Sets the Security for WiFi Device    \n");
            fprintf(shell_ptr->STDOUT, "    power   [<on>] [<off>] [period] [<value>] = Enables or disables the power mode and sets the sleep duration.\n");
            fprintf(shell_ptr->STDOUT, "    scan                   = Scan for Access Points and display there infrmation\n");
            fprintf(shell_ptr->STDOUT, "    help                   = Display commands list and parameters.\n");
            fprintf(shell_ptr->STDOUT, "  Parameters:\n");
            fprintf(shell_ptr->STDOUT, "    <network id>   = name of the wireless network\n");
            fprintf(shell_ptr->STDOUT, "    <network mode> = type of Wireless network. Possible values: managed or adhoc\n");
            fprintf(shell_ptr->STDOUT, "    <WEP Key>      = WEP Security Key. If set to none, WEP security is disabled.\n");
            fprintf(shell_ptr->STDOUT, "    <key index>    = Four keys can be set as WEP keys.Set index as [1],[2],[3],[4]\n");
            fprintf(shell_ptr->STDOUT, "                   = To change which key is the currently active key, just enter [index]\n");
            fprintf(shell_ptr->STDOUT, "                   = (without entering any key value).\n");
            fprintf(shell_ptr->STDOUT, "    <security type>= wep,wpa,wpa2 or none\n");
            fprintf(shell_ptr->STDOUT, "    <passphrase string> = pass phrase string\n");
            fprintf(shell_ptr->STDOUT, "    <on>                = enables power mode\n");
            fprintf(shell_ptr->STDOUT, "    <off>               = disables power mode\n");
            fprintf(shell_ptr->STDOUT, "    <value>             = sleep duration\n");
        }
    }

    return return_code;
} /* Endbody */
Exemple #10
0
int32_t  Shell_del(int32_t argc, char *argv[] )
{ /* Body */
   bool                    print_usage, shorthelp = FALSE, temp;
   int32_t                     error = 0, return_code = SHELL_EXIT_SUCCESS;
   MQX_FILE_PTR               fs_ptr;
   SHELL_CONTEXT_PTR          shell_ptr = Shell_get_context( argv );
   char                   *abs_path;
   
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc !=  2) 
      {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } 
      /* check if filesystem is mounted */ 
      else if (NULL == Shell_get_current_filesystem(argv))  
      {
         printf("Error, file system not mounted\n" );
         return_code = SHELL_EXIT_ERROR;
      }
      else  
      {
         if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) {
            printf("Error, unable to allocate memory for paths\n" );
            return_code = SHELL_EXIT_ERROR;
         }
         else
         {
            _io_get_dev_for_path(abs_path,&temp,PATHNAME_SIZE,(char *)argv[1],Shell_get_current_filesystem_name(shell_ptr));
            fs_ptr = _io_get_fs_by_name(abs_path);
            if (fs_ptr == NULL)  {
               printf("Error, file system not mounted\n" );
               return_code = SHELL_EXIT_ERROR;
            } else { 
               error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,Shell_get_current_filesystem_name(shell_ptr));
               if (!error)
               {
                  error = ioctl(fs_ptr, IO_IOCTL_DELETE_FILE, (void *) abs_path);
               }
               if (error)  {
                  printf("Error deleting file %s\n", argv[1]);
               }
            }
         MFS_free_path(abs_path);
         }
      }
   }
      
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <file> \n", argv[0]);
      } else  {
         printf("Usage: %s <file>\n", argv[0]);
         printf("   <file> = name of file to delete\n");
      }
   }
   return return_code;
}
Exemple #11
0
int_32  Shell_search_file_r(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   int_32               len;
   MQX_FILE_PTR         fs_ptr;
   char_ptr             path_ptr, mode_ptr;
   pointer              dir_ptr;
   char_ptr             buffer = NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int_32               error = 0;
   char_ptr             file_name,source_name; 
   MFS_SEARCH_DATA search_data;
   pointer      search_ptr;
   DIR_STRUCT_PTR dir_file; // wk @130405 -->
   dir_file = _mem_alloc_zero( sizeof( DIR_STRUCT ));  // wk @130405 -->
   
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 2)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         path_ptr  ="*.*";
         mode_ptr = "m";

         source_name=argv[1];
         
         fs_ptr = Shell_get_current_filesystem(argv);
         /* check if filesystem is mounted */ 
         if (fs_ptr == NULL)  {
             printf("Error, file system not mounted\n");
             return_code = SHELL_EXIT_ERROR;
         } else  {
            buffer = _mem_alloc(BUFFER_SIZE);
            error = ioctl(fs_ptr, IO_IOCTL_CHANGE_CURRENT_DIR, shell_ptr->CURRENT_DIR);
            if (buffer && !error) {
            
               dir_ptr = _io_mfs_dir_open(fs_ptr, path_ptr, mode_ptr );
            
               if (dir_ptr == NULL)  {
                  printf("File not found.\n");
                  return_code = SHELL_EXIT_ERROR;
               } else {
                 
                 
//                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk(dir_ptr, buffer, BUFFER_SIZE )) > 0) {  // wk @130405-->old
                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read_wk1(dir_ptr, buffer, BUFFER_SIZE,dir_file )) > 0) {
//                    printf ("%-12.12s  %6lu \n"
//                    ,dir_ptr_g->SEARCH_DATA.NAME, dir_ptr_g->SEARCH_DATA.FILE_SIZE);
//                    file_name=dir_ptr_g->SEARCH_DATA.NAME;   // wk @130405-->old                   
                    printf ("%-12.12s  %6lu \n"
                    ,dir_file->SEARCH_DATA.NAME, dir_file->SEARCH_DATA.FILE_SIZE);
//                    file_name=dir_ptr_g->SEARCH_DATA.NAME; // wk @130405-->old
                    file_name=dir_file->SEARCH_DATA.NAME;
                    if(argc==2)
                    {
                      while(*(source_name)!='\0')
                       if(*(file_name++)!= *(source_name++))
                        goto next;
                      
                       error=33;   // WK --> 文件找到
                       break;     
                    }
 next:                 source_name=argv[1];                     
                  } 
                  if(argc==2)
                  printf("error=%d if /t33表示文件找到\n",error);
                  _io_mfs_dir_close(dir_ptr);
               }
               
               _mem_free(buffer);
               _mem_free(dir_file);
            } else {
               if(buffer == NULL){
                 printf("Error, unable to allocate space.\n" );
               } else {
                 printf("Error, directory does not exist.\n" );
               }
               return_code = SHELL_EXIT_ERROR;
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<filename>]\n", argv[0]);
      } else  {
         printf("Usage: %s [<filespec> [<attr>]]\n", argv[0]);
         printf("   <filename>   = filename what want to fine\n");
      }
   }
   return return_code;
} /* Endbody */
Exemple #12
0
int_32  Shell_write_binary(int_32 argc, char_ptr argv[] ,uint_32 num,uchar_ptr data)
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   uint_32           count=0, i;
   int_32            offset=0;
   int_32            seek_mode=0;
   char              c;
   MQX_FILE_PTR      fd = NULL;
   char_ptr          abs_path;   
   boolean           cache_enabled=TRUE;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   char                 buf[SHELL_BLOCK_SIZE];
   char *               argv5_p;
   int_32               error = 0;
   _mqx_int             bi;   

   /* wk @130514 -->  */
   uint_32 nums;uchar left;
   /* wk @130514 -->  */
   print_usage = Shell_check_help_request(argc, argv, &shorthelp ); // wk @130405 --> 简化程序减小时间

   if (!print_usage)  {
      if ((argc < 3)) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } 
      /* check if filesystem is mounted */ 
      else if (NULL == Shell_get_current_filesystem(argv))  
      {
         printf("Error, file system not mounted\n");
         return_code = SHELL_EXIT_ERROR;
      }
      else  {
         count = 0;
         offset = 0;
         seek_mode = IO_SEEK_CUR; // 默认模式
         if (argc >= 4)  {
           
//            if (! Shell_parse_uint_32(argv[2], &count ))  {// 检查输入长度
//               printf("Error, invalid length\n");
//               return_code = SHELL_EXIT_ERROR;
//               print_usage=TRUE;
//            } else  
           
            {
               if (argc >= 4)  {
                  if (strcmp(argv[2], "begin") == 0) {
                     seek_mode = IO_SEEK_SET;
                  } else if (strcmp(argv[2], "end") == 0) { 
                     seek_mode = IO_SEEK_END;
                  } else if (strcmp(argv[2], "current") == 0) { 
                     seek_mode = IO_SEEK_CUR;
                  } else { 
                     printf("Error, invalid seek type\n");
                     return_code = SHELL_EXIT_ERROR;
                     print_usage=TRUE;
                  }
                  
                  if (return_code == SHELL_EXIT_SUCCESS)  {
                     if (! Shell_parse_int_32(argv[3], &offset ))  {
                        printf("Error, invalid seek value\n");
                        return_code = SHELL_EXIT_ERROR;
                        print_usage=TRUE;
                     }
                  }
               }
            }
         }

      }
     
      if (return_code == SHELL_EXIT_SUCCESS)  {
         if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) {
            printf("Error, unable to allocate memory for paths\n" );
            return_code = SHELL_EXIT_ERROR;
         } else {
             error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
             if(!error)
             {
                fd = fopen(abs_path, "a");
             }
             if (fd && !error)  {
                if (fseek(fd, offset, seek_mode ) != IO_ERROR)  {
               
               // generate data to buf
//               argv5_p = (char*)argv[5];// by dx
//               for (i = 0, c = '0', bi = 0; i < count;i++) {// 写入txt,从字符0到z
//                  
//                  buf[bi++] = c;
//                  
//                  if (bi > SHELL_BLOCK_SIZE - 1) {
//                     write(fd, buf, SHELL_BLOCK_SIZE);
//                     bi = 0;
//                  }
//                  
//                  if (c == 'z')
//                     c='0';
//                  else
//                     c++;
//               }
//               
//               if (bi)                  
//                  count = ( strlen(argv5_p)<count )?( strlen(argv5_p) ):(count);// 修改长度,若超过最大长度则用最大长度
//                  write(fd, argv5_p, count);// 写入SD,相应路径
  
                  /* wk @130405 --> 写我二进制数据 */
//                  for(i = 0; i < num; i++)
//                  {
////                    write(fd,data+i,1);
//                  }
                  
                   /* wk @130514 --> */
                   nums=num>>7;
                   left=(uchar)num&0x7f;
                   for(uint_32 i=0;i<nums;i++)
                     write(fd,&data[i<<7],SHELL_BLOCK_SIZE);
                   write(fd,&data[nums<<7],left);
                   /* wk @130514 --> end*/
                   
//                   write(fd,data,num);
                   /* wk @130405 --> 写二进制数据 <--END */
                  
                  fclose(fd);
               } else  {
                  printf("Error, unable to seek file %s.\n", argv[1] );
                  return_code = SHELL_EXIT_ERROR;
               }
            } else  {
                printf("Error, unable to open file %s.\n", argv[1] );
                return_code = SHELL_EXIT_ERROR;
            }
            MFS_free_path(abs_path);
         }
Exemple #13
0
int32_t  Shell_df(int32_t argc, char *argv[])
{ /* Body */
    bool              print_usage;
    bool              shorthelp = FALSE;
    int32_t               return_code = SHELL_EXIT_SUCCESS;
    SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context(argv);
    int fs;
    int64_t               space;
    int32_t               clusters;
    uint32_t              cluster_size;
    int32_t               error = 0;
    char             *fs_name;

    print_usage = Shell_check_help_request(argc, argv, &shorthelp);

    if (!print_usage)  {
        if (argc > 2)  {
            fprintf(shell_ptr->STDOUT, "Error, invalid number of parameters\n");
            return_code = SHELL_EXIT_ERROR;
            print_usage=TRUE;
        }
    }

    if (print_usage)  {
        if (shorthelp)  {
            fprintf(shell_ptr->STDOUT, "%s [<filesystem>]\n", argv[0]);
        }
        else {
            fprintf(shell_ptr->STDOUT, "Usage: %s [filesystem]\n", argv[0]);
            fprintf(shell_ptr->STDOUT, "   <filesystem> = filesystem to query for free space\n");
        }
        return return_code;
    }


    if (argc == 2) {
        fs_name = argv[1];
        fs = _io_get_fs_by_name(fs_name);
    }
    else {
        fs_name = Shell_get_current_filesystem_name(shell_ptr);
        fs = Shell_get_current_filesystem(argv);
    }

    /* check if filesystem is mounted */
    if (0 > fs)  {
        fprintf(shell_ptr->STDOUT, "Error, file system not mounted\n");
        return return_code = SHELL_EXIT_ERROR;
    }


    error = ioctl(fs, IO_IOCTL_FREE_SPACE, &space);
    if (0 > error) {
        fprintf(shell_ptr->STDOUT, "Error, could not get free space\n");
        return return_code = SHELL_EXIT_ERROR;
    }

    error = ioctl(fs, IO_IOCTL_FREE_CLUSTERS, &clusters);
    if (0 > error) {
        fprintf(shell_ptr->STDOUT, "Error, could not get free space\n");
        return return_code = SHELL_EXIT_ERROR;
    }
    error = ioctl(fs, IO_IOCTL_GET_CLUSTER_SIZE, &cluster_size);
    if (0 > error) {
        fprintf(shell_ptr->STDOUT, "Error, could not get free space\n");
        return return_code = SHELL_EXIT_ERROR;
    }

    fprintf(shell_ptr->STDOUT, "Free disk space on %s\n", fs_name);
    fprintf(shell_ptr->STDOUT, "%ld clusters, %ld bytes each\n", (long int)clusters, (long int)cluster_size);
    fprintf(shell_ptr->STDOUT, "%lu KB\n", (unsigned long int)(space>>10));

    return return_code;
} /* Endbody */
Exemple #14
0
int32_t  Shell_cache(int32_t argc, char *argv[] )
{
    SHELL_CONTEXT_PTR shell_ptr = Shell_get_context(argv);
   bool                    print_usage, shorthelp = FALSE;
   int32_t                     return_code = SHELL_EXIT_SUCCESS;
   int32_t                     i;
   int fd;
   char                   *name_ptr = NULL;
   bool                    on = TRUE;


   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc >  3) {
         fprintf(shell_ptr->STDOUT, "Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else  {

         for (i=1;i<argc;i++)  {
            if (strcmp("on", argv[i])==0)  {
               on = TRUE;
            } else if (strcmp("off", argv[i])==0)  {
               on = FALSE;
            } else if (_nio_supp_validate_device(argv[i])) {
               name_ptr = argv[i];
            } else  {
               fprintf(shell_ptr->STDOUT, "Error, invalid parameter\n");
               return_code = SHELL_EXIT_ERROR;
               print_usage = TRUE;
               break;
            }
         }

         if (return_code == SHELL_EXIT_SUCCESS)  {
            if (name_ptr==NULL) {
               name_ptr = Shell_get_current_filesystem_name(argv);
            }

           fd = open(name_ptr, O_RDWR);
            if (0 > fd)  {
               fprintf(shell_ptr->STDOUT, "Error, unable to access file system\n" );
               return_code = SHELL_EXIT_ERROR;
            } else  {
               if (0 > ioctl(fd, (on ? IO_IOCTL_WRITE_CACHE_ON : IO_IOCTL_WRITE_CACHE_OFF), NULL))
               {
                    fprintf(shell_ptr->STDOUT, "Error, unable to set cache\n" );
               }
               close(fd);
            }
         }
      }
   }


   if (print_usage)  {
      if (shorthelp)  {
         fprintf(shell_ptr->STDOUT, "%s [on|off] [<filesys:>]\n", argv[0]);
      } else  {
         fprintf(shell_ptr->STDOUT, "Usage: %s [on|off] [<filesys:>]\n", argv[0]);
         fprintf(shell_ptr->STDOUT, "   <filesys:> = name of MFS file system\n");
      }
   }
   return return_code;
}
Exemple #15
0
int_32  Shell_cd(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean                    print_usage, shorthelp = FALSE, dev_in_path = FALSE;
   int_32                     error = 0, return_code = SHELL_EXIT_SUCCESS;
   MQX_FILE_PTR               fs_ptr;
   char_ptr                   abs_path = NULL;
   SHELL_CONTEXT_PTR          shell_ptr = Shell_get_context( argv ); 
   int_16                     devlen = 0;
   
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc !=  2) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else  {
         if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) {
            printf("Error, unable to allocate memory for paths\n" );
            return_code = SHELL_EXIT_ERROR;
         }
         else
         {
            devlen = _io_get_dev_for_path(abs_path,
                        &dev_in_path,
                        PATHNAME_SIZE,
                        (char *)argv[1],
                        Shell_get_current_filesystem_name(shell_ptr));
            fs_ptr = _io_get_fs_by_name(abs_path);
            if (fs_ptr == NULL)  
            {
               printf("Device \"%s\" not available\n", abs_path);
               return_code = SHELL_EXIT_ERROR;
            } 
            else  
            {
         
               error = _io_rel2abs(abs_path,
                                     shell_ptr->CURRENT_DIR,
                                     (char *)argv[1],
                                     PATHNAME_SIZE,
                                     shell_ptr->CURRENT_DEVICE_NAME);
            
               if(!error)
               {
                  // check if path exist
                 error = ioctl(fs_ptr, IO_IOCTL_CHECK_DIR_EXIST,(pointer)abs_path );
               }
               if (error)  
               {
                  printf("Error changing directory %s\n", argv[1]);
               }
               else
               {
                  
                  if(dev_in_path == TRUE)
                  {
                     // there is device name in input path

                     //separate device name
                     abs_path[devlen] = '\0';

                     Shell_set_current_filesystem_by_name(argv,abs_path);

                     // add "\" back to the string
                     abs_path[devlen] = '\\';                     
                  }

                  // change shell current dir
                  strcpy(shell_ptr->CURRENT_DIR,abs_path+devlen);
               }               
            }
            MFS_free_path(abs_path);
         }
      }
   }


      
      
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <directory> \n", argv[0]);
      } else  {
         printf("Usage: %s <directory>\n", argv[0]);
         printf("   <directory> = name of directory to change to\n");
      }
   }
   return return_code;
}
Exemple #16
0
int_32  Shell_type(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   MQX_FILE_PTR         fd;
   char_ptr             abs_path;   
   _mqx_int             c;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int_32               error = 0;   
   

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc == 2)  {
         /* check if filesystem is mounted */ 
         if (NULL == Shell_get_current_filesystem(argv))    {
            printf("Error, file system not mounted\n" );
            return_code = SHELL_EXIT_ERROR;
         }
         else if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) {
            printf("Error, unable to allocate memory for paths\n" );
            return_code = SHELL_EXIT_ERROR;
         } 
         else {
            error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
            if(!error)
            {
               fd = fopen(abs_path, "r");
            }
            MFS_free_path(abs_path);
            if (fd && !error)  {
               do {
                  c = fgetc(fd);
                  if (c!= IO_EOF) {
                     fputc((char)c, stdout);
                  }
               } while (c!=IO_EOF);
            
               fclose(fd);
               printf("\n");
            } else  {
               printf("Error, unable to open file %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
         }
      } else  {
         printf("Error, %s invoked with incorrect number of arguments\n", argv[0]);
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <filename>\n", argv[0]);
      } else  {
         printf("Usage: %s <filename>\n", argv[0]);
         printf("   <filename>   = filename to display\n");
      }
   }
   return return_code;
} /* Endbody */
Exemple #17
0
/*
 * Download/Upload file from/to TFTP server.
 */
int32_t Shell_tftpcln(int32_t argc, char *argv[])
{
    bool                   shorthelp = FALSE;
    int32_t                return_code = SHELL_EXIT_SUCCESS;
    TFTPCLN_PARAM_STRUCT   params = {0};
    char                   *optstring = ":h:pm:r:l:f:";
    SHELL_GETOPT_CONTEXT   gopt_context;
    int32_t                next_option;
    char                   *host;
    char                   *port;
    char                   *remote_filename;
    char                   *local_filename;
    char                   *mode;
    struct addrinfo        hints = {0};
    struct addrinfo        *getadd_result;
    int                    error;
    uint32_t               handle;
    int32_t                result;
    char*                  result_string;
    SHELL_CONTEXT_PTR      shell_ptr;

    shell_ptr = Shell_get_context(argv);
    Shell_tftpcln_stdout = shell_ptr->STDOUT;
    if (Shell_check_help_request(argc, argv, &shorthelp))
    {
        sh_tftpcln_print_usage(argv[0], shorthelp);
        return(return_code);
    }

    hints.ai_socktype = SOCK_STREAM;
    hints.ai_family = AF_UNSPEC;
    port = SHELL_TFTPCLN_DEFAULT_PORT;
    host = NULL;
    mode = NULL;
    remote_filename = NULL;
    local_filename = NULL;
    params.recv_callback = sh_tftpcln_callback;
    params.send_callback = sh_tftpcln_callback;
    params.error_callback = sh_tftpcln_error;

    /* Parse command line options */
    Shell_getopt_init(&gopt_context);
    do
    {
        next_option = Shell_getopt(argc, argv, optstring, &gopt_context);
        switch (next_option)
        {
            case 'h':
                host = gopt_context.optarg;
                break;
            case 'p':
                if(strtoul(gopt_context.optarg, NULL, 10) != 0)
                {
                    port = gopt_context.optarg;
                }
                break;
            case 'm':
                mode = gopt_context.optarg;
                break;
            case 'r':
                remote_filename = gopt_context.optarg;
                break;
            case 'l':
                local_filename = gopt_context.optarg;
                break;
            case 'f':
                if(strtoul(gopt_context.optarg, NULL, 10) == 4)
                {
                    hints.ai_family = AF_INET;
                }
                else if(strtoul(gopt_context.optarg, NULL, 10) == 6)
                {
                    hints.ai_family = AF_INET6;
                }
                break;
            case '?': /* User specified an invalid option. */
                fprintf(shell_ptr->STDOUT, "Unknown option -%c.\n", next_option);
                sh_tftpcln_print_usage(argv[0], TRUE);
                return_code = SHELL_EXIT_ERROR;
                next_option = -1;
                break;
            case ':': /* Option has a missing parameter. */
                fprintf(shell_ptr->STDOUT, "Option -%c requires a parameter.\n", next_option);
                return_code = SHELL_EXIT_ERROR;
                next_option = -1;
                break;
            case -1: /* Done with options. */
                break;
            default:
                break;
        }
    }while(next_option != -1);
    
    if (return_code == SHELL_EXIT_ERROR)
    {
        return(return_code);
    }

    /* check if we have all required parameters. */
    if (host == NULL)
    {
        fputs("Host not specified!\n", shell_ptr->STDOUT);
        sh_tftpcln_print_usage(argv[0], TRUE);
        return(SHELL_EXIT_ERROR);
    }

    error = getaddrinfo(host, port, &hints, &getadd_result);
    if (error == 0)
    {
        params.sa_remote_host = *getadd_result->ai_addr;

        freeaddrinfo(getadd_result);
        fprintf(shell_ptr->STDOUT, "Connecting to %s, port %s...", host, port);

        handle = TFTPCLN_connect(&params);
        if (handle == 0)
        {
            fputs("FAIL\n", shell_ptr->STDOUT);
            return(SHELL_EXIT_ERROR);
        }
        else
        {
            fputs("OK\n", shell_ptr->STDOUT);
        }
    }
    else
    {
        printf("Failed to resolve %s:%s\n", host, port);
    }

    if (!strcmp(mode, "PUT"))
    {
        if (local_filename == NULL)
        {
            fputs("Local file name not specified!\n", shell_ptr->STDOUT);
            sh_tftpcln_print_usage(argv[0], TRUE);
            return(SHELL_EXIT_ERROR);
        }
        fprintf(shell_ptr->STDOUT, "Uploading local file %s to %s:", local_filename, remote_filename);
        result = TFTPCLN_put(handle, local_filename, remote_filename);
    }
    else if (!strcmp(mode, "GET"))
    {
        if (remote_filename == NULL)
        {
            fputs("Remote file name not specified!\n", shell_ptr->STDOUT);
            sh_tftpcln_print_usage(argv[0], TRUE);
            return(SHELL_EXIT_ERROR);
        }
        fprintf(shell_ptr->STDOUT, "Downloading remote file %s to %s:", remote_filename, local_filename);
        result = TFTPCLN_get(handle, local_filename, remote_filename);
    }
    if (result == RTCS_OK)
    {
        result_string = "successful";
    }
    else
    {
        result_string = "failed";
    }
    fprintf(shell_ptr->STDOUT, "Transaction %s.\n", result_string);
    TFTPCLN_disconnect(handle);
    return(return_code);
}
Exemple #18
0
int32_t  Shell_dir(int32_t argc, char *argv[] )
{ /* Body */
   bool              print_usage, shorthelp = FALSE;
   int32_t               return_code = SHELL_EXIT_SUCCESS;
   int32_t               len;
   MQX_FILE_PTR         fs_ptr;
   char             *path_ptr, *mode_ptr;
   void                *dir_ptr;
   char             *buffer = NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int32_t               error = 0;


   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc > 3)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         path_ptr  ="*.*";
         mode_ptr = "m";
         if (argc >= 2)  {
            path_ptr = argv[1];
            if (argc== 3)  {
               mode_ptr = argv[2];
            }
         }
         
         fs_ptr = Shell_get_current_filesystem(argv);
         /* check if filesystem is mounted */ 
         if (fs_ptr == NULL)  {
             printf("Error, file system not mounted\n");
             return_code = SHELL_EXIT_ERROR;
         } else  {
            buffer = _mem_alloc(BUFFER_SIZE);
            error = ioctl(fs_ptr, IO_IOCTL_CHANGE_CURRENT_DIR, shell_ptr->CURRENT_DIR);
            if (buffer && !error) {
            
               dir_ptr = _io_mfs_dir_open(fs_ptr, path_ptr, mode_ptr );
            
               if (dir_ptr == NULL)  {
                  printf("File not found.\n");
                  return_code = SHELL_EXIT_ERROR;
               } else {
                  while ((_io_is_fs_valid(fs_ptr)) && (len = _io_mfs_dir_read(dir_ptr, buffer, BUFFER_SIZE)) > 0) {
                     printf(buffer);
                  } 
                  _io_mfs_dir_close(dir_ptr);
               }
               _mem_free(buffer);
            } else {
               if(buffer == NULL){
                 printf("Error, unable to allocate space.\n" );
               } else {
                 printf("Error, directory does not exist.\n" );
               }
               return_code = SHELL_EXIT_ERROR;
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s [<filespec>] [<attr>]]\n", argv[0]);
      } else  {
         printf("Usage: %s [<filespec> [<attr>]]\n", argv[0]);
         printf("   <filespec>   = files to list\n");
         printf("   <attr>       = attributes of files: adhrsv*\n");
      }
   }
   return return_code;
} /* Endbody */
int32_t  Shell_compare(int32_t argc, char *argv[] )
{ /* Body */
   bool      print_usage, shorthelp = FALSE;
   int32_t      size1, size2, return_code = SHELL_EXIT_SUCCESS;
   MQX_FILE_PTR in_fd_1=NULL, in_fd_2=NULL;
   char         *file1=NULL, *file2=NULL;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int32_t               error = 0;      

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc != 3)  {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } 
      /* check if filesystem is mounted */ 
      else if (NULL == Shell_get_current_filesystem(argv))  
      {
         printf("Error, file system not mounted\n");
         return_code = SHELL_EXIT_ERROR;
      }
      else if (MFS_alloc_path(&file1) != MFS_NO_ERROR) {
         printf("Error, unable to allocate memory for paths\n" );
         return_code = SHELL_EXIT_ERROR;
      } else {
         error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
         if(!error)
         {
            in_fd_1 = fopen(file1, "r");
         }      

         error = _io_rel2abs(file1,shell_ptr->CURRENT_DIR,(char *) argv[2],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
         if(!error)
         {
            in_fd_2 = fopen(file1, "r");
         }  

         MFS_free_path(file1);         

         if (in_fd_1 == NULL)  {
             printf("Error, unable to open file %s\n", argv[1] );
             return_code = SHELL_EXIT_ERROR;
         } else  if (in_fd_2 == NULL)  {
             printf("Error, unable to open file %s\n", argv[2] );
             return_code = SHELL_EXIT_ERROR;
         } else {
            file1 = _mem_alloc_zero(COMPARE_BLOCK_SIZE);
            file2 = _mem_alloc_zero(COMPARE_BLOCK_SIZE);
            if ((file1==NULL) || (file2==NULL)) {
               printf("Error, unable to allocate buffer space" );
               return_code = SHELL_EXIT_ERROR;
            } else {
               do {
                  size1 = read(in_fd_1, file1, COMPARE_BLOCK_SIZE);
                  size2 = read(in_fd_2, file2, COMPARE_BLOCK_SIZE);
                  if (size1!=size2) {
                     printf("Compare failed, files have different sizes\n" );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (size1 > 0) {
                     if (memcmp(file1,file2,COMPARE_BLOCK_SIZE)!=0) {
                        printf("Compare failed, files are different\n" );
                        return_code = SHELL_EXIT_ERROR;
                     }                     
                  }
               } while ((size1>0) && (return_code == SHELL_EXIT_SUCCESS));
               if (return_code == SHELL_EXIT_SUCCESS) {
                  printf("The files are identical\n" );
               }
            }
            if (file1) _mem_free(file1);
            if (file2) _mem_free(file2);
         }
         if (in_fd_1) fclose(in_fd_1); 
         if (in_fd_2) fclose(in_fd_2); 
      }
   }
      
      
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <file1> <file2> \n", argv[0]);
      } else  {
         printf("Usage: %s <file1> <file2>\n", argv[0]);
         printf("   <file1> = first file to compare\n");
         printf("   <file2> = second file to compare\n");
      }
   }
   return return_code;
} /* Endbody */
Exemple #20
0
int32_t  Shell_create(int32_t argc, char *argv[] )
{ /* Body */
   bool           print_usage, shorthelp = FALSE;
   int32_t            return_code = SHELL_EXIT_SUCCESS;
   char          *mode;
   int fd = -1;
   char          *abs_path;
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int32_t               error = 0;


   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if ((argc < 2) || (argc > 3)) {
         fprintf(shell_ptr->STDOUT, "Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      }
      /* check if filesystem is mounted */
      else if (0 > Shell_get_current_filesystem(argv))
      {
         fprintf(shell_ptr->STDOUT, "Error, file system not mounted\n" );
         return_code = SHELL_EXIT_ERROR;
      }
      else
      {
         /*if (argc != 3)  {
            mode = "a";
         } else {
            mode = argv[2];
         }
          */

         if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) {
            fprintf(shell_ptr->STDOUT, "Error, unable to allocate memory for paths\n" );
            return_code = SHELL_EXIT_ERROR;
         } else {
            error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
            if(!error)
            {
               fd = open(abs_path, O_WRONLY | O_CREAT);
            }
            MFS_free_path(abs_path);
            if (0 <= fd && !error)  {
               close(fd);
            } else  {
               fprintf(shell_ptr->STDOUT, "Error, unable to open file %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         fprintf(shell_ptr->STDOUT, "%s <filename> [<mode>] \n", argv[0]);
      } else  {
         fprintf(shell_ptr->STDOUT, "Usage: %s <filename> [<mode>]\n", argv[0]);
         fprintf(shell_ptr->STDOUT, "   <filename>   = filename to create\n");
         fprintf(shell_ptr->STDOUT, "   <bytes>      = open mode\n");
      }
   }
   return return_code;
} /* Endbody */
Exemple #21
0
int_32  Shell_create(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   char_ptr          mode;
   MQX_FILE_PTR      fd = NULL;
   char_ptr          abs_path;   
   SHELL_CONTEXT_PTR    shell_ptr = Shell_get_context( argv );
   int_32               error = 0;   
  

   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if ((argc < 2) || (argc > 3)) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage = TRUE;
      } 
      /* check if filesystem is mounted */ 
      else if (NULL == Shell_get_current_filesystem(argv))  
      {
         printf("Error, file system not mounted\n" );
         return_code = SHELL_EXIT_ERROR;
      }
      else  
      {
         if (argc != 3)  {
            mode = "a";
         } else {
            mode = argv[2];
         }
         if (MFS_alloc_path(&abs_path) != MFS_NO_ERROR) {
            printf("Error, unable to allocate memory for paths\n" );
            return_code = SHELL_EXIT_ERROR;
         } else {
            error = _io_rel2abs(abs_path,shell_ptr->CURRENT_DIR,(char *) argv[1],PATHNAME_SIZE,shell_ptr->CURRENT_DEVICE_NAME);
            if(!error)
            {
               fd = fopen(abs_path, mode);
            }
            MFS_free_path(abs_path);
            if (fd && !error)  {
               fclose(fd);
            } else  {
               printf("Error, unable to open file %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
         }
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <filename> [<mode>] \n", argv[0]);
      } else  {
         printf("Usage: %s <filename> [<mode>]\n", argv[0]);
         printf("   <filename>   = filename to create\n");
         printf("   <bytes>      = open mode\n");
      }
   }
   return return_code;
} /* Endbody */