Exemplo n.º 1
0
int_32  Shell_i2c_read(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean              print_usage, shorthelp = FALSE;
   int_32               result,return_code = SHELL_EXIT_SUCCESS;
   uint_32              addr, bytes,i;
   MQX_FILE_PTR         fd;
   char_ptr             buf;
   
      
   print_usage = Shell_check_help_request(argc, argv, &shorthelp );

   if (!print_usage)  {
      if (argc==4)  {
         if ( Shell_parse_hexnum(argv[2], &addr) && Shell_parse_uint_32(argv[3], &bytes)) {

            fd = fopen(argv[1],0);
            buf = _mem_alloc(bytes);
            if ((fd!=NULL) && (buf !=NULL)) {
               if (I2C_OK != ioctl(fd, IO_IOCTL_I2C_SET_RX_REQUEST, &bytes))
               {
                  printf("ERROR during set rx request\n");
               } else {
                  result = fread(buf, bytes, 1, fd);
                  if (I2C_OK==result) {
                     for (i=0;i<bytes;i++) {
                        printf("%02x ", buf[i]);
                     }
                     printf("\n");
                  } else {
                     printf ("ERROR during read\n");
                  }
                  bytes=0;
                  if (I2C_OK != ioctl(fd, IO_IOCTL_FLUSH_OUTPUT, &bytes)) {
                     printf ("ERROR during flush\n");
                  }
                  if (I2C_OK != ioctl(fd, IO_IOCTL_I2C_STOP, NULL)) {
                     printf ("ERROR during stop\n");
                  }
               }
            }
            if (fd) fclose(fd);
            if (buf) _mem_free(buf);              
         } else {
            printf("Error, invalid parameter\n");
         }         
         
      } 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 <device> <address> <bytes>\n", argv[0]);
      } else  {
         printf("Usage: %s <device> <address> <bytes>\n", argv[0]);
         printf("   <device>   = I2C device name (eg: i2c0:)\n");
         printf("   <address>  = i2c device address in hex\n");
         printf("   <bytes>    = bytes to read (decimal)\n");
      }
   }
   return return_code;
} /* Endbody */
Exemplo n.º 2
0
int32_t  Shell_disect(int32_t argc, char *argv[] )
{ /* Body */
   int32_t            return_code = SHELL_EXIT_SUCCESS;
   bool           print_usage, shorthelp = FALSE;
   uint32_t           sector,num_sectors;
   int32_t            offset=0;
   MQX_FILE_PTR      fd, fs;
   uint32_t           e,i;
   unsigned char         *buffer;

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

   if (!print_usage)  {
      if ((argc < 2) || (argc > 5)) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else if ( !Shell_parse_uint_32(argv[1], (uint32_t *) &offset ))  {
         printf("Error, invalid length\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         num_sectors = 1;
         
         if (argc >= 3) {
            if ( !Shell_parse_uint_32(argv[2], (uint32_t *) &num_sectors )) {
               num_sectors = 1;
            }
         }      
         if (argc >= 4) {
            fd = fopen(argv[3], "r");
            if (!fd) { 
               printf("Error, unable to open file %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
         } else {
            fs = Shell_get_current_filesystem(argv);
            _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd);
         }
         
         if (fd)  {
            buffer = _mem_alloc(SECTOR_SIZE);
            if (buffer) {
               for(sector=0;sector<num_sectors;sector++) {
                  if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR)  {
                     printf("Error, unable to seek to sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (_io_read(fd, (char *) buffer, 1) != 1) {
                     printf("Error, unable to read sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else { 
                     printf("\nSector # %d\n",offset+sector);
                     for (e=0;e<16;e++)  {
                        for (i=0;i<32;i++) {
                           printf("%02x ",(uint32_t) buffer[e*32+i]);
                        }
                        printf("\n");
                     }
                  }
               }
               _mem_free(buffer);
            }
         }
         printf("\n");
         if (argc >= 4) {
            fclose(fd);
         }
      }
   }
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <sector> [<device>]\n", argv[0]);
      } else  {
         printf("Usage: %s <sector> [<device>]\n", argv[0]);
         printf("   <sector>     = sector number\n");
         printf("   <device>     = low level device\n");
      }
   }
   
   return return_code;
} /* Endbody */
Exemplo n.º 3
0
int_32  Shell_dirent(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   uint_32           sector,num_sectors;
   int_32            offset;
   MQX_FILE_PTR      fd, fs;
   uint_32           e;
   uchar_ptr         buffer;
   MFS_DIR_ENTRY_PTR dirents;

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

   if (!print_usage)  {
      if ((argc < 2) || (argc > 4)) {
         printf("Error, invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset ))  {
         printf("Error, invalid length\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         num_sectors = 1;
         
         if (argc >= 3) {
            if ( !Shell_parse_uint_32(argv[2], (uint_32_ptr) &num_sectors )) {
               num_sectors = 1;
            }
         }      
         if (argc == 4) {
            fd = fopen(argv[3], "r");
            if (!fd) { 
               printf("Error, unable to open file %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
         } else {
            fs = Shell_get_current_filesystem(argv);
            _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd);
         }

         if (fd)  {
            buffer = _mem_alloc(SECTOR_SIZE);
            if (buffer) {
               for(sector=0;sector<num_sectors;sector++) {
                  if (fseek(fd, offset+sector, IO_SEEK_SET) == IO_ERROR)  {
                     printf("Error, unable to seek to sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else  if (_io_read(fd, (char_ptr) buffer, 1) !=1) {
                     printf("Error, unable to read sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (!is_zero(buffer, SECTOR_SIZE)) {
                     printf("\nEntry # %d",offset+sector);
                     dirents = (MFS_DIR_ENTRY_PTR) buffer;

                     for (e=0;e<DIRENTS_PER_SECTOR;e++)  {
                        print_dirent(&dirents[e]);
                     }
                     printf("\n");
                  }
               }
               _mem_free(buffer);
            } else {
               printf("Error, unable to allocate sector buffer.\n" );
               return_code = SHELL_EXIT_ERROR;
            }
            if (argc >= 4) {
               fclose(fd);
            }
         }
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <sector> [<device>]\n", argv[0]);
      } else  {
         printf("Usage: %s <sector> [<device>]\n", argv[0]);
         printf("   <sector>     = sector number\n");
         printf("   <device>     = low level device\n");
      }
   }
   return return_code;
} /* Endbody */
Exemplo n.º 4
0
int_32  Shell_di(int_32 argc, char_ptr argv[] )
{ /* Body */
   boolean           print_usage, shorthelp = FALSE;
   int_32            return_code = SHELL_EXIT_SUCCESS;
   int_32            offset;

   MQX_FILE_PTR      fd, fs;

   uint_32           backup=0;
   uchar_ptr         buffer=NULL;

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

   if (!print_usage)  {
      if ((argc < 2 ) || (argc > 3)) {
         printf("Invalid number of parameters\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else if ( !Shell_parse_uint_32(argv[1], (uint_32_ptr) &offset ))  {
         printf("Error, invalid length\n");
         return_code = SHELL_EXIT_ERROR;
         print_usage=TRUE;
      } else {
         buffer = _mem_alloc(SECTOR_SIZE);
         if (buffer==NULL) {
            printf("Error, unable to allocate sector buffer\n");
            return  SHELL_EXIT_ERROR;
         }

         if (argc==3) {
            fd = fopen(argv[2], "b");
         } else {   
            fs = Shell_get_current_filesystem(argv);
            _io_ioctl(fs, IO_IOCTL_GET_DEVICE_HANDLE, &fd);
         }
              

         if (fd)  {
            if (fseek(fd, offset, IO_SEEK_SET) == IO_ERROR)  {
               printf("Error, unable to seek to sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
               printf("Error, unable to read sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }
            
            if (return_code == SHELL_EXIT_SUCCESS) {
               printf("\n");
               backup = print_bpb(buffer);
               if (backup) {
                  if (fseek(fd, backup, IO_SEEK_SET) == IO_ERROR)  {
                     printf("Error, unable to seek to sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
                     printf("Error, unable to read sector %s.\n", argv[1] );
                     return_code = SHELL_EXIT_ERROR;
                  }  
                  if (return_code == SHELL_EXIT_SUCCESS) {
                     printf("\n");
                     print_bpb(buffer);
                  }
               }
            }
            if (fseek(fd, 1, IO_SEEK_SET) == IO_ERROR)  {
               printf("Error, unable to seek to sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            } else if (_io_read(fd, (char_ptr) buffer, 1) != 1) {
               printf("Error, unable to read sector %s.\n", argv[1] );
               return_code = SHELL_EXIT_ERROR;
            }  
            if (return_code == SHELL_EXIT_SUCCESS) {
               printf("\n");
               print_fsi(buffer);
            }
            if (argc==3) {
               fclose(fd);
            }
         }
         _mem_free(buffer);
      }
   }
   
   
   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <sector> [<device>]\n", argv[0]);
      } else  {
         printf("Usage: %s <sector> [<device>]\n", argv[0]);
         printf("   <sector>     = sector number\n");
         printf("   <device>     = low level device\n");
      }
   }
   return return_code;
} /* Endbody */
Exemplo n.º 5
0
int_32  Shell_dnat(int_32 argc, char_ptr argv[] )
{
   uint_32              error;
   boolean              print_usage, shorthelp = FALSE;
   int_32               return_code = SHELL_EXIT_SUCCESS;
   uint_32              priority=0;     
   uint_16              protocol=0;
   uint_16              start_port=0;   
   uint_16              end_port=0;     
   _ip_address          target_ip=0;      
   uint_16              target_port=0;  

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

   if (!print_usage)  {
      if (argc == 7)  {
         if (!Shell_parse_uint_32(argv[1], &priority  )) {
            printf("Error, invalid rule priority\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[3], &start_port  )) {
            printf("Error, invalid start port\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[4], &end_port  )) {
            printf("Error, invalid end port\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (! Shell_parse_ip_address( argv[5], &target_ip  ))  {
            printf("Error, invalid ip address\n");
            return_code = SHELL_EXIT_ERROR;
         } else if (!Shell_parse_uint_16(argv[6], &target_port  )) {
            printf("Error, invalid target port\n");
            return_code = SHELL_EXIT_ERROR;
         } else {
            if (strcmp(argv[2],"TCP")==0) {
               protocol = IPPROTO_TCP;
            } else if (strcmp(argv[2],"UDP")==0) {
               protocol = IPPROTO_UDP;
            } else {
               printf("Error, invalid protocol\n");
               return_code = SHELL_EXIT_ERROR;
            }
         }
         if (return_code == SHELL_EXIT_SUCCESS) {
            printf("Adding rule:\n");
            printf("%d: %s (%d-%d) -> %03d.%03d.%03d.%03d:%d",
               priority, protocol==IPPROTO_TCP?"TCP":"UDP",start_port,end_port, 
               IPBYTES(target_ip), target_port);

            error = DNAT_add_rule(priority, protocol, start_port, end_port, target_ip, target_port );
            if (error != RTCS_OK) {
               printf("   Error: %s\n",NAT_err_str(error));
               return_code = SHELL_EXIT_ERROR;
            } else {
               printf("   OK\n");
            }
         }
      } else {
         print_usage = TRUE;
         return_code = SHELL_EXIT_ERROR;
      }
   }

   if (print_usage)  {
      if (shorthelp)  {
         printf("%s <priority> TCP|UDP <start_port> <end_port> <target_ip> <target_port>\n", argv[0]);
      } else  {
         printf("Usage: %s <priority> TCP|UDP <start_port> <end_port> <target_ip> <target_port>\n",argv[0]);
      }
   }
   return return_code;
} /* Endbody */