Ejemplo n.º 1
0
_mqx_int _io_pcb_shm_open
    (
        /* [IN] the file handle */
        FILE_DEVICE_STRUCT_PTR fd_ptr,

        /* [IN] the rest of the filename used to open the device */
        char _PTR_             open_name_ptr,

        /* [IN] the open flags for this device */
        char _PTR_             open_mode_flags
    )
{
    IO_PCB_SHM_INFO_STRUCT_PTR  info_ptr;
    IO_PCB_DEVICE_STRUCT_PTR    dev_ptr;

    dev_ptr = (IO_PCB_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR;
    fd_ptr->DEV_DATA_PTR = dev_ptr->DRIVER_INIT_PTR;
    info_ptr = (IO_PCB_SHM_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR;

    fd_ptr->FLAGS |= IO_FLAG_IS_PCB_DEVICE;
    info_ptr->READ_CALLBACK_FUNCTION = NULL;
    _lwsem_create(&info_ptr->READ_LWSEM, 0);
    _lwsem_create(&info_ptr->WRITE_LWSEM, 0);
    _queue_init(&info_ptr->READ_QUEUE, 0);
    _queue_init(&info_ptr->WRITE_QUEUE, 0);

    return(MQX_OK);

}
Ejemplo n.º 2
0
_mqx_int _io_pcb_mqxa_open
   (
      /* [IN] the file handle */
      FILE_DEVICE_STRUCT_PTR fd_ptr, 

      /* [IN] the rest of the filename used to open the device */
      char _PTR_             open_name_ptr,

      /* [IN] the open flags for this device */
      char _PTR_             open_mode_flags
   )
{ /* Body */
   IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr;
   IO_PCB_DEVICE_STRUCT_PTR    dev_ptr;
   _mqx_uint                   flags;

   dev_ptr = (IO_PCB_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR;
   fd_ptr->DEV_DATA_PTR = dev_ptr->DRIVER_INIT_PTR;
   info_ptr = (IO_PCB_MQXA_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR;
   if (info_ptr->FD) {
      fd_ptr->ERROR = IO_PCB_MQXA_DEVICE_ALREADY_OPEN;
      return(IO_ERROR);
   }/* Endif */
   info_ptr->FD = fopen(info_ptr->INIT.IO_PORT_NAME, (char_ptr)0);
   if (info_ptr->FD == NULL) {
      fd_ptr->ERROR = IO_PCB_MQXA_INCORRECT_SERIAL_DEVICE;
      return(IO_ERROR);
   } /* Endif */

   /* Set the baud rate on the serial device, if a non zero value for baud is supplied. Otherwise, used default rate */
   if (info_ptr->INIT.BAUD_RATE) {
       if (ioctl(info_ptr->FD, IO_IOCTL_SERIAL_SET_BAUD,
          (pointer)&info_ptr->INIT.BAUD_RATE) != MQX_OK)
       {
          fclose(info_ptr->FD);
          info_ptr->FD = NULL;
          fd_ptr->ERROR = IO_PCB_MQXA_INCORRECT_SERIAL_DEVICE;
          return(IO_ERROR);
       }
   }

   /* Turn off xon/xoff, translation and echo on the serial device */
   ioctl(info_ptr->FD, IO_IOCTL_SERIAL_GET_FLAGS, (pointer)&flags);
   flags &= ~(IO_SERIAL_XON_XOFF | IO_SERIAL_TRANSLATION | IO_SERIAL_ECHO);
   ioctl(info_ptr->FD, IO_IOCTL_SERIAL_SET_FLAGS, &flags);

   fd_ptr->DEV_DATA_PTR = info_ptr;
   fd_ptr->FLAGS       |= IO_FLAG_IS_PCB_DEVICE;
   
   info_ptr->READ_CALLBACK_FUNCTION = NULL;
   _lwsem_create(&info_ptr->READ_LWSEM, 0);
   _lwsem_create(&info_ptr->WRITE_LWSEM, 0);
   _queue_init(&info_ptr->READ_QUEUE, 0);
   _queue_init(&info_ptr->WRITE_QUEUE, 0);

   return(MQX_OK);
   
} /* Endbody */
Ejemplo n.º 3
0
_mqx_uint _mmu_create_vcontext
   (
      /* [IN] the task to which a virtual context is to be added */
      _task_id task_id
   )
{ /* Body */
   TD_STRUCT_PTR                  td_ptr;
   PSP_VIRTUAL_CONTEXT_STRUCT_PTR context_ptr;

   td_ptr = _task_get_td(task_id);
   if (td_ptr == NULL) {
      return(MQX_INVALID_TASK_ID);
   }/* Endif */
   context_ptr = _mem_alloc_system_zero(sizeof(PSP_VIRTUAL_CONTEXT_STRUCT));
   if (context_ptr == NULL) {
      return(MQX_OUT_OF_MEMORY);
   }/* Endif */
   _queue_init(&context_ptr->PAGE_INFO,0);
   _int_disable();
   if (td_ptr->FLAGS & TASK_MMU_CONTEXT_EXISTS) {
      _int_enable();
      _mem_free(context_ptr);
      return(MQX_MMU_CONTEXT_EXISTS);
   } /* Endif */

   td_ptr->MMU_VIRTUAL_CONTEXT_PTR = context_ptr;
   td_ptr->FLAGS |= TASK_MMU_CONTEXT_EXISTS;
   _int_enable();
   return(MQX_OK);

} /* Endbody */
Ejemplo n.º 4
0
static uint_32 NAT_init_internal2
   (
      NAT_PARM_PTR   parm_ptr   /* [IN] Initialization parameters */
   )
{ /* Body */
   NAT_CFG_STRUCT_PTR      nat_cfg_ptr = RTCS_getcfg(NAT);
   uint_32                 error;

   /* 
   ** Make sure the netmask is valid. We use the fact that 
   ** (x & x+1) == 0 <=> x = 2^n-1.
   */
   if (~parm_ptr->IP_MASK & (~parm_ptr->IP_MASK + 1)) {
      return RTCSERR_INVALID_PARAMETER;
   } /* Endif */

   /* Make sure other parameters have been supplied */
   if (!parm_ptr->IP_PRV) {
      return RTCSERR_INVALID_PARAMETER;
   } /* Endif */


   /*
   ** If the configuration structure has already been allocated, 
   ** just add another private network and return 
   */
   if (nat_cfg_ptr) {
      error = NAT_add_private_network(&nat_cfg_ptr->PRIVATE_NETWORKS, parm_ptr->IP_PRV, parm_ptr->IP_MASK);
      if (error == RTCS_OK) {
         nat_cfg_ptr->NAT_EXEC = NAT_apply;
      }
      return error;
   } /* Endif */
   

   // First time through the initialization,
   // Allocate the NAT configuration structure
   nat_cfg_ptr = _mem_alloc_system_zero(sizeof(NAT_CFG_STRUCT));
   if (nat_cfg_ptr == NULL) {
      return RTCSERR_OUT_OF_MEMORY;
   } /* Endif */
   
   /* Record the private network information */
   error = NAT_add_private_network(&nat_cfg_ptr->PRIVATE_NETWORKS, parm_ptr->IP_PRV, parm_ptr->IP_MASK);

   if (error == RTCS_OK) {
      nat_cfg_ptr->NAT_EXEC = NAT_apply;
         
      nat_cfg_ptr->INITIAL_PRV_NET  = parm_ptr->IP_PRV;
      nat_cfg_ptr->INITIAL_PRV_MASK = parm_ptr->IP_MASK;

      nat_cfg_ptr->TCP_TOUT.PRIVATE = &nat_cfg_ptr->TCP_HEAD;
      nat_cfg_ptr->UDP_TOUT.PRIVATE = &nat_cfg_ptr->UDP_HEAD;
      nat_cfg_ptr->FIN_TOUT.PRIVATE = &nat_cfg_ptr->FIN_HEAD;
      nat_cfg_ptr->ICMP_TOUT.PRIVATE = &nat_cfg_ptr->ICMP_HEAD;
      
      /* Initialize radix trees */
      IPRADIX_init(&nat_cfg_ptr->ROOT_IN);
      IPRADIX_init(&nat_cfg_ptr->ROOT_OUT);
      
      /* Initialize timeout functions */
      nat_cfg_ptr->UDP_TOUT.EVENT = NAT_expire;
      nat_cfg_ptr->TCP_TOUT.EVENT = NAT_expire;
      nat_cfg_ptr->FIN_TOUT.EVENT = NAT_expire;
      nat_cfg_ptr->ICMP_TOUT.EVENT = NAT_expire;
      nat_cfg_ptr->TIMEOUT_TCP = NAT_DEFAULT_TIMEOUT_TCP;
      nat_cfg_ptr->TIMEOUT_UDP = NAT_DEFAULT_TIMEOUT_UDP;
      nat_cfg_ptr->TIMEOUT_FIN = NAT_DEFAULT_TIMEOUT_FIN;
      nat_cfg_ptr->TIMEOUT_ICMP = NAT_DEFAULT_TIMEOUT_ICMP;
      
      /* Initialize last used port numbers */
      nat_cfg_ptr->TCP_PORT = NAT_DEFAULT_PORT_MIN;
      nat_cfg_ptr->UDP_PORT = NAT_DEFAULT_PORT_MIN;
      nat_cfg_ptr->ICMP_ID = NAT_DEFAULT_PORT_MIN;
      nat_cfg_ptr->PORT_MAX = NAT_DEFAULT_PORT_MAX;
      nat_cfg_ptr->PORT_MIN = NAT_DEFAULT_PORT_MIN;

      /* Inititalize ALGs */
      error = NAT_init_algs(nat_cfg_ptr);
   }

   /* Allocate partitions */
   if (error == RTCS_OK)  {
      nat_cfg_ptr->SESSION_PART = RTCS_part_create(sizeof(NAT_SESSION_STRUCT),
         NAT_SESSION_INITIAL_COUNT, NAT_SESSION_GROW_COUNT, NAT_SESSION_MAX,
         NULL, NULL);
      if (nat_cfg_ptr->SESSION_PART == NULL) {
         error = RTCSERR_OUT_OF_MEMORY;
      } /* Endif */
   } /* Endif */

   if (error == RTCS_OK)  {
      nat_cfg_ptr->RADIX_IN = RTCS_part_create(sizeof(IPRADIX_NODE), 
         NAT_SESSION_INITIAL_COUNT, NAT_SESSION_GROW_COUNT, NAT_SESSION_MAX,
         NULL, NULL);
      if (nat_cfg_ptr->RADIX_IN == NULL) {
         error = RTCSERR_OUT_OF_MEMORY;
      } /* Endif */
   } /* Endif */


   if (error == RTCS_OK)  {
      nat_cfg_ptr->RADIX_OUT = RTCS_part_create(sizeof(IPRADIX_NODE), 
         NAT_SESSION_INITIAL_COUNT, NAT_SESSION_GROW_COUNT, NAT_SESSION_MAX,
         NULL, NULL);
      if (nat_cfg_ptr->RADIX_OUT == NULL) {
         error = RTCSERR_OUT_OF_MEMORY;
      } /* Endif */
   } /* Endif */

   if (error == RTCS_OK)  {
      // Initialize queue of DNAT Rules
      _queue_init( &nat_cfg_ptr->RULE_QUEUE, 0 );
         
      RTCS_setcfg(NAT, nat_cfg_ptr);

   } else {
      if (nat_cfg_ptr != NULL) {
         if (nat_cfg_ptr->RADIX_IN != NULL) RTCS_part_destroy(nat_cfg_ptr->RADIX_IN);
         if (nat_cfg_ptr->RADIX_OUT != NULL) RTCS_part_destroy(nat_cfg_ptr->RADIX_OUT);
         if (nat_cfg_ptr->SESSION_PART != NULL) RTCS_part_destroy(nat_cfg_ptr->SESSION_PART);
         _mem_free(nat_cfg_ptr);
      }
   } /* Endif */

   return error;                     
} /* Endbody */
Ejemplo n.º 5
0
int_32 MFS_Open_Device
    (
    MQX_FILE_PTR             fd_ptr,        /* [IN] the MFS file handle for the device being opened */
    MFS_DRIVE_STRUCT_PTR     drive_ptr
    )
{
    MQX_FILE_PTR dev_fd;
    uint_32     sector_size, k;
    int_32      error_code;

    dev_fd = drive_ptr->DEV_FILE_PTR;

    fd_ptr->DEV_DATA_PTR = NULL;
    drive_ptr->MFS_FILE_PTR = fd_ptr;

    /* Select partition, if desired */
    if (drive_ptr->DRV_NUM)
    {
        error_code = ioctl(dev_fd, IO_IOCTL_SEL_PART, &drive_ptr->DRV_NUM);
        if (error_code)
        {
            return error_code;
        }
    }

    /*
    ** obtain the buffer for configuration data and for storing general
    ** sector reads
    */
    error_code = _mfs_validate_device(dev_fd, &sector_size, &drive_ptr->BLOCK_MODE);

    if ( error_code )
    {
        /* Device isn't valid */
        drive_ptr->MFS_FILE_PTR = NULL;      
        return error_code;
    }

    _lwsem_wait(&drive_ptr->SEM);

    drive_ptr->BPB.SECTOR_SIZE = (uint_16) sector_size; 
    drive_ptr->DIR_SECTOR_PTR = MFS_mem_alloc_system_zero(sector_size);
    MFS_Invalidate_directory_sector(drive_ptr);

    if ( drive_ptr->DIR_SECTOR_PTR == NULL )
    {
        _lwsem_post(&drive_ptr->SEM);
        drive_ptr->MFS_FILE_PTR = NULL;      
        return MFS_INSUFFICIENT_MEMORY;
    }

    _mem_set_type(drive_ptr->DIR_SECTOR_PTR, MEM_TYPE_MFS_DIRECTORY_SECTOR); 
    _queue_init(&drive_ptr->HANDLE_LIST, 0);

    k = drive_ptr->BPB.SECTOR_SIZE;
    for ( drive_ptr->SECTOR_POWER = 0; !(k & 1);
        drive_ptr->SECTOR_POWER++ )
    {
        k>>=1;
    } 

    /*
    ** read boot sector and get the BIOS Parameter Block
    */
    error_code = MFS_Read_device_sector(drive_ptr, BOOT_SECTOR, drive_ptr->DIR_SECTOR_PTR);

    if ( error_code == MFS_NO_ERROR )
    {
        drive_ptr->DIR_SECTOR_NUMBER = BOOT_SECTOR;
        error_code = MFS_Mount_drive_internal(drive_ptr);
    }

    if ( !error_code )
    {
        /* Determine the real sector size */
        if ( sector_size != drive_ptr->BPB.SECTOR_SIZE )
        {
            _mem_free(drive_ptr->DIR_SECTOR_PTR);
            drive_ptr->DIR_SECTOR_PTR = MFS_mem_alloc_system_zero(drive_ptr->BPB.SECTOR_SIZE);
            MFS_Invalidate_directory_sector(drive_ptr);
            if ( drive_ptr->DIR_SECTOR_PTR == NULL )
            {
                error_code = MFS_INSUFFICIENT_MEMORY;
                drive_ptr->MFS_FILE_PTR = NULL;
            }
            else
            {
                _mem_set_type(drive_ptr->DIR_SECTOR_PTR, MEM_TYPE_MFS_DIRECTORY_SECTOR); 
            }
        }

        /* Calculate the free space on disk */
#if MFSCFG_CALCULATE_FREE_SPACE_ON_OPEN
        if ( !error_code )
        {
            MFS_Get_disk_free_space_internal(drive_ptr,(uint_32_ptr)&error_code);
        }
#endif
    }
    else {
    	printf(" open fs read secotor err+\n");
    	drive_ptr->MFS_FILE_PTR = NULL;
    	if(drive_ptr->DIR_SECTOR_PTR) {
    		_mem_free(drive_ptr->DIR_SECTOR_PTR);
    		drive_ptr->DIR_SECTOR_PTR = NULL;
    		
    	}
    	printf(" open fs read secotor err+\n");
    }

    _lwsem_post(&drive_ptr->SEM);

    return(error_code);
}