예제 #1
0
/*
** Send data from session buffer to client.
**
** IN:
**      HTTPSRV_SESSION_STRUCT *session - session to use.
**
** OUT:
**      none
**
** Return Value:
**      int - number of bytes send.
*/
uint32_t httpsrv_ses_flush(HTTPSRV_SESSION_STRUCT *session)
{
    uint32_t length = 0;
    
    while (length != session->buffer.offset)
    {
        uint32_t remaining;

        length = send(session->sock, session->buffer.data, session->buffer.offset, 0);
    
        if (length == RTCS_ERROR)
        {
            session->state = HTTPSRV_SES_CLOSE;
            length = 0;
            break;
        }
        remaining = session->buffer.offset - length;

        if (remaining > 0)
        {
            _mem_zero(session->buffer.data, length);
            memmove(session->buffer.data, session->buffer.data+length, remaining);
            session->buffer.offset = remaining;
        }
        else
        {
            _mem_zero(session->buffer.data, session->buffer.offset);
            session->buffer.offset = 0;
            break;
        }
    }

    return(length);
}
예제 #2
0
파일: pa_zallo.c 프로젝트: gxliu/MQX_3.8.0
pointer _partition_alloc_zero
   (
      /* [IN] the partition from which to obtin the memory block */
      _partition_id partition
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR kernel_data;
   PARTPOOL_STRUCT_PTR    partpool_ptr = (PARTPOOL_STRUCT_PTR)partition;
   pointer                result;

   _GET_KERNEL_DATA(kernel_data);

   _KLOGE2(KLOG_partition_alloc_zero, partition);

   result = _partition_alloc_internal(partpool_ptr, kernel_data->ACTIVE_PTR);
#if MQX_CHECK_MEMORY_ALLOCATION_ERRORS
   if ( result == NULL ) {
      _KLOGX2(KLOG_partition_alloc_zero, result);
      return (result);
   } /* Endif */
#endif

   _mem_zero(result, (_mem_size)(partpool_ptr->BLOCK_SIZE -
      sizeof(INTERNAL_PARTITION_BLOCK_STRUCT)));

   _KLOGX2(KLOG_partition_alloc_zero, result);
   return (result);

} /* Endbody */
예제 #3
0
파일: adc.c 프로젝트: gxliu/MQX_3.8.0
/*FUNCTION*****************************************************************
* 
* Function Name    : _adc_install
* Returned Value   : _mqx_uint a task error code or MQX_OK
* Comments         :
*    Install a adc driver.
*
*END*********************************************************************/
_mqx_uint _io_adc_install
   (
      /* [IN] A string that identifies the device for fopen */
      char_ptr  identifier,
      /* pointer to a HW specific structure */
      pointer   init
   ) 
   
{ /* Body */
   ADC_DRIVER_BUNDLE_PTR adc_driver_bundle;
   _mqx_uint result;

   if (NULL == (adc_driver_bundle = (ADC_DRIVER_BUNDLE_PTR) _mem_alloc(sizeof(ADC_DRIVER_BUNDLE))))
      return ADC_ERROR_ALLOC; /* memory allocation error */

   _mem_zero(adc_driver_bundle, sizeof(ADC_DRIVER_BUNDLE));

   if (IO_OK == (result = _adc_hw_install(identifier, adc_driver_bundle, init)))
      if (IO_OK == (result = _adt_hw_install(identifier, adc_driver_bundle, init)))
         result = _io_dev_install(identifier,
            _adc_open,
            _adc_close,
            _adc_read,
            _adc_write,
            _adc_ioctl,
            adc_driver_bundle);

   if (result != IO_OK)
      _mem_free(adc_driver_bundle); 

   return result;
} /* Endbody */
예제 #4
0
void RIP_init_static_rt
(
    IP_ROUTE_INDIRECT_PTR gate,   /* [IN] the route to init */
    uint16_t metric                /* [IN] metric of this route. [0,65535] */
)
{ /* Body */
    RIP_CFG_STRUCT_PTR  ripcfg = RTCS_getcfg(RIP);

    _mem_zero(&gate->RIP, sizeof(gate->RIP));
    gate->RIP.METRIC = metric / 4096;
    /* sanity check */
    if (gate->RIP.METRIC < RIP_MIN_METRIC) {
        gate->RIP.METRIC = RIP_MIN_METRIC;
    } /* Endif */
    if (gate->RIP.METRIC > RIP_MAX_METRIC) {
        gate->RIP.METRIC = RIP_MAX_METRIC;
    } /* Endif */
    /* no src interface for a static route */
    gate->RIP.IPIFSRC = NULL;
    gate->RIP.CHANGED_F = TRUE;
    if (ripcfg){
        ripcfg->RT_CHANGED_F = TRUE;
        RIP_trig_upd();
    }
} /* Endbody */
예제 #5
0
static void IP_route_insert
   (
      pointer _PTR_  node,
      pointer        data
   )
{ /* Body */
   struct ip_route_insert _PTR_     insertdata = data;
   IP_ROUTE_PRV_PTR                 route;
   IP_ROUTE_DIRECT_PTR              new_route = insertdata->route;
   uint_32                          i = insertdata->index;

   /* Make sure the node is initialized */
   if (!*node) {
      *node = node;
      _mem_zero(((IP_ROUTE_PRV_PTR)*node)->ROUTETYPE, sizeof(route->ROUTETYPE));
   } /* endif */

   route = *node;
   if (!route->ROUTETYPE[i]) {
      new_route->NEXT = new_route;
      route->ROUTETYPE[i] = new_route;
   } else if (insertdata->sort) {
      insertdata->sort(&route->ROUTETYPE[i], new_route);
   } else {
      new_route->NEXT = route->ROUTETYPE[i]->NEXT;
      route->ROUTETYPE[i]->NEXT = new_route;
   } /* Endif */

   insertdata->error = RTCS_OK;

} /* Endbody */
예제 #6
0
파일: mcf5441.c 프로젝트: Vinhuit/Freescale
/*!
 * \brief Initialize the mmu and set default properties for regions not mapped by 
 *  the ACR registers.
 * 
 * \param[in] mmu_init default properties
 */
void _mmu_init
   (
      // [IN] default properties
      void   *mmu_init
   )
{ /* Body */

   PSP_MMU_INIT_STRUCT_PTR mmu = mmu_init;
   KERNEL_DATA_STRUCT_PTR  kernel_data;
   PSP_SUPPORT_STRUCT_PTR  psp_support_ptr;
   uint32_t  mode;
   uint32_t  tmp;
   _mqx_int i;

   _GET_KERNEL_DATA(kernel_data);
   psp_support_ptr = (PSP_SUPPORT_STRUCT_PTR)kernel_data->PSP_SUPPORT_PTR;

   if (psp_support_ptr == NULL || mmu == 0) {
      _mqx_fatal_error(MQX_INVALID_POINTER);
   } /* Endif */

   /* Stop and invalidate the cache */
   _DCACHE_DISABLE();
   _ICACHE_DISABLE();

   _mem_zero(psp_support_ptr->ACR_VALS, sizeof(psp_support_ptr->ACR_VALS));

   mode = mmu->INITIAL_CACR_ENABLE_BITS & ~(MCF54XX_CACR_EUSP) | MCF54XX_CACR_SPA;  // do not remove SPA flag - fn for flush/invalidate cache use phy address features
   tmp = _PSP_GET_CACR();
   tmp |= mode;
   _PSP_SET_CACR(tmp);

} /* Endbody */
예제 #7
0
/*
** Function used to free session structure
**
** IN:
**      FTPSRV_SESSION_STRUCT* session - session structure pointer
**
** OUT:
**      none
**
** Return Value: 
**      none
*/
static void ftpsrv_ses_free(FTPSRV_SESSION_STRUCT *session)
{
    if (session)
    {
        if(session->buffer)
        {
            _mem_free(session->buffer);
            session->buffer = NULL;
        }
        if(session->auth_input.uid)
        {
            _mem_free(session->auth_input.uid);
            session->auth_input.uid = NULL;
        }
        if(session->auth_input.pass && strcmp(session->auth_input.pass, ""))
        {
            _mem_free(session->auth_input.pass);
            session->auth_input.pass = NULL;
        }
        if(session->cur_dir)
        {
            _mem_free(session->cur_dir);
        }
        if (session->msg_queue != NULL)
        {
            _lwmsgq_deinit(session->msg_queue);
            _mem_zero(session->msg_queue, sizeof(LWMSGQ_STRUCT) + FTPSRV_NUM_MESSAGES*sizeof(FTPSRV_TRANSFER_MSG)*sizeof(_mqx_max_type));
            _mem_free(session->msg_queue);
        }
        _mem_free(session);
    }
}
예제 #8
0
/*
** Read data from HTTP server.
**
** First copy data from session buffer if there are any and than read rest from socket if required.
**
** IN:
**      HTTPSRV_SESSION_STRUCT *session - session to use for reading.
**      char                   *dst - user buffer to read to.
**      _mqx_int               len - size of user buffer.
**
** OUT:
**      none
**
** Return Value:
**      int - number of bytes read.
*/
_mqx_int httpsrv_read(HTTPSRV_SESSION_STRUCT *session, char *dst, _mqx_int len)
{
    int read = 0;
    uint_32 data_size = session->buffer.offset;
    uint_32 length = (data_size < len) ? data_size : len;
    uint_32 received = 0;

    /* If there are any data in buffer copy them to user buffer */
    if (data_size > 0)
    {
        uint_32 tail = (HTTPSRVCFG_SES_BUFFER_SIZE & PSP_MEMORY_ALIGNMENT_MASK)-length;
        _mem_copy(session->buffer.data, dst, length);
        memmove(session->buffer.data, session->buffer.data+length, tail);
        _mem_zero(session->buffer.data+tail, length);
        session->buffer.offset -= length;
        read = length;
    }

    /* If there is some space remaining in user buffer try to read from socket */
    while (read < len)
    {
        received = recv(session->sock, dst+read, len-read, 0);
        
        if (RTCS_ERROR != received)
        {
            read += received;
        }
        else
        {
            break;
        }
    }
    
    return read;
}
예제 #9
0
_mfs_error  MFS_Clear_cluster
    (
    MFS_DRIVE_STRUCT_PTR    drive_ptr,  /*[IN] the drive on which to operate */
    uint_32                 cluster     /*[IN]  the # of the cluster to clear*/
    )
{
    uint_32      sector,i;
    _mfs_error   error_code;

#if MFSCFG_READ_ONLY_CHECK
    if (MFS_is_read_only (NULL, drive_ptr))
    {
        return MFS_DISK_IS_WRITE_PROTECTED;
    }
#endif

    error_code = MFS_Flush_directory_sector_buffer(drive_ptr);
    sector = CLUSTER_TO_SECTOR(cluster);

    _mem_zero(drive_ptr->DIR_SECTOR_PTR, drive_ptr->BPB.SECTOR_SIZE);
    for ( i = 0; ((i<drive_ptr->BPB.SECTORS_PER_CLUSTER) && (error_code==MFS_NO_ERROR));i++ )
    {
        error_code = MFS_Write_device_sector(drive_ptr,sector+i,drive_ptr->DIR_SECTOR_PTR);
    } 
    drive_ptr->DIR_SECTOR_NUMBER = sector;
    return(error_code);
}  
예제 #10
0
static void RIP_create_rt(
    RTCSPCB_PTR    pcb,          /* [IN] incoming packet */
    RIP_ENTRY_PTR   rte,
    uint8_t      rip_vers
)
{ /* Body */
    uint32_t                nmetric= RIP_cpu_metric(pcb,mqx_ntohl(rte->METRIC));
    RIP_CFG_STRUCT_PTR     ripcfg = RTCS_getcfg(RIP);
    IP_CFG_STRUCT_PTR      IP_cfg_ptr = RTCS_getcfg(IP);
    IP_ROUTE_INDIRECT_PTR  gate;
    _ip_address            network, netmask;

    gate = RTCS_part_alloc(IP_cfg_ptr->GATE_PARTID);
    if (!gate)  return;
    _mem_zero(gate, sizeof(*gate));

    /* init the route */
    RIP_adopt_rt(pcb, gate, rte, nmetric, &network, &netmask);

    /* insert it in the table */
    ROUTE_insert(gate, network, netmask);

    /* flag it as changed */
    ripcfg->RT_CHANGED_F = TRUE;
} /* Endbody */
예제 #11
0
파일: rtcs_init.c 프로젝트: gxliu/MQX_3.8.0
/*FUNCTION*------------------------------------------------
* 
* Function Name: PPP_start
* Comments     :
*    
*
*END*-----------------------------------------------------*/
void PPP_start(void)
{
    uint_32           error;

    _rtcs_if_handle   ihandle;
    MQX_FILE_PTR      pfile;
    _iopcb_handle     pio;
    _ppp_handle       phandle;
    IPCP_DATA_STRUCT  ipcp_data;

    _PPP_PAP_RSECRETS = rsecrets;    /* Require authentication, allow PAP */
    _PPP_PAP_LSECRET = &lsecret;     /* Allow peer to request PAP */
    _PPP_CHAP_LNAME = localname;     /* Needed by CHAP */
    _PPP_CHAP_RSECRETS = rsecrets;   /* Require authentication, allow CHAP */
    _PPP_CHAP_LSECRETS = lsecrets;   /* Allow peer to request CHAP */

    /* Install a route for a default gateway */
    RTCS_gate_add(GATE_ADDR, INADDR_ANY, INADDR_ANY);

    pfile = fopen(PPP_DEVICE, NULL);
#ifdef PPP_DEVICE_DUN
    _io_dun_install("dun:");
    pfile = fopen("dun:", (char_ptr)pfile);
#endif
 
    pio = _iopcb_ppphdlc_init(pfile);
    _PPP_ACCM = 0;
    error = PPP_initialize(pio, &phandle);
    if (error) {
       printf("\nPPP initialize: %lx", error);
       _task_block();
    } /* Endif */

    _iopcb_open(pio, PPP_lowerup, PPP_lowerdown, phandle);
    error = RTCS_if_add(phandle, RTCS_IF_PPP, &ihandle);
    if (error) {
       printf("\nIF add failed, error = %lx", error);
       _task_block();
    } /* Endif */
    _lwsem_create(&ppp_sem, 0);
    _mem_zero(&ipcp_data, sizeof(ipcp_data));
    ipcp_data.IP_UP              = PPP_linkup;
    ipcp_data.IP_DOWN            = NULL;
    ipcp_data.IP_PARAM           = &ppp_sem;
    ipcp_data.ACCEPT_LOCAL_ADDR  = FALSE;
    ipcp_data.ACCEPT_REMOTE_ADDR = FALSE;
    ipcp_data.LOCAL_ADDR         = PPP_LOCADDR;
    ipcp_data.REMOTE_ADDR        = PPP_PEERADDR;
    ipcp_data.DEFAULT_NETMASK    = TRUE;
    ipcp_data.DEFAULT_ROUTE      = TRUE;
    error = RTCS_if_bind_IPCP(ihandle, &ipcp_data);
    if (error) {
       printf("\nIF bind failed, error = %lx", error);
       _task_block();
    } /* Endif */
    printf("\nPlease initiate PPP connection.  Waiting...");
    _lwsem_wait(&ppp_sem);
    printf("\nPPP device %s bound to %d.%d.%d.%d", PPP_DEVICE, IPBYTES(ipcp_data.LOCAL_ADDR));
}
예제 #12
0
void OS_Mem_zero(void* ptr, uint32_t length)
{
#if MEM_ZERO_ENHANCEMENT
        _mem_zero(ptr, length);
#else
        memset(ptr, 0, length);
#endif
}
예제 #13
0
/*!
 * \brief  This function sets up the stack frame of a new task descriptor.
 * 
 * \param[in] td_ptr the address of the task descriptor
 * \param[in] stack_ptr the address of the stack memory block
 * \param[in] stack_size the size of the stack
 * \param[in] template_ptr the task's template
 * \param[in] status_register the status register to use in creating the task
 * \param[in] create_parameter the task creation parameter
 */
bool _psp_build_stack_frame
   (
      /* [IN] the address of the task descriptor */
      TD_STRUCT_PTR    td_ptr,

      /* [IN] the address of the stack memory block */
      void            *stack_ptr,

      /* [IN] the size of the stack */
      _mem_size        stack_size,

      /* [IN] the task's template */
      TASK_TEMPLATE_STRUCT_PTR template_ptr,

      /* [IN] the status register to use in creating the task */
      _mqx_uint        status_register,

      /* [IN] the task creation parameter */
      uint32_t          create_parameter
   )
{
   unsigned char *stack_base_ptr;
   PSP_STACK_START_STRUCT_PTR stack_start_ptr;
   bool res = TRUE;

   stack_base_ptr  = (unsigned char *)_GET_STACK_BASE(stack_ptr, stack_size);
   stack_start_ptr = (PSP_STACK_START_STRUCT_PTR)(stack_base_ptr - sizeof(PSP_STACK_START_STRUCT));

   td_ptr->STACK_BASE  = (void *)stack_base_ptr;
   td_ptr->STACK_LIMIT = _GET_STACK_LIMIT(stack_ptr, stack_size);
   td_ptr->STACK_PTR   = stack_start_ptr;

   /*
   ** Build the task's initial stack frame. This contains the initialized
   ** registers, and an exception frame which will cause the task to
   ** "return" to the start of the task when it is dispatched.
   */
   _mem_zero(stack_start_ptr, (_mem_size)sizeof(PSP_STACK_START_STRUCT));
   stack_start_ptr->INITIAL_CONTEXT.LR = (uint32_t)_task_exit_function_internal;
   stack_start_ptr->INITIAL_CONTEXT.R0 = (uint32_t)create_parameter;
   stack_start_ptr->INITIAL_CONTEXT.PC = (uint32_t)(template_ptr->TASK_ADDRESS) | 1;
   stack_start_ptr->INITIAL_CONTEXT.PSR = 0x01000000;
   stack_start_ptr->PARAMETER = create_parameter;
#if PSP_MQX_CPU_IS_ARM_CORTEX_M4
   stack_start_ptr->INITIAL_CONTEXT.PENDSVPRIOR = 0;
   stack_start_ptr->INITIAL_CONTEXT.BASEPRI     = status_register;
   stack_start_ptr->INITIAL_CONTEXT.LR2         = 0xfffffffd;
#endif


#if MQXCFG_ENABLE_FP && PSP_HAS_FPU
   if (td_ptr->FLAGS & MQX_FLOATING_POINT_TASK) {
      res = _psp_build_float_context(td_ptr);
   }
#endif /* MQXCFG_ENABLE_FP && PSP_HAS_FPU */

   return res;
}
예제 #14
0
/*
 * Accept connection from client.
 */
uint32_t ftpsrv_accept(uint32_t sock)
{
    struct sockaddr  remote_addr;
    unsigned short   length;

    RTCS_ASSERT(sock != RTCS_SOCKET_ERROR);
    _mem_zero(&remote_addr, sizeof(remote_addr));
    length = sizeof(remote_addr);
    return(accept(sock, (sockaddr *) &remote_addr, &length));
}
예제 #15
0
static void RIP_build_header(
    unsigned char   *buf,        /* [OUT] the rip header */
    uint8_t      cmd,        /* [IN] the commande */
    uint8_t      version     /* [IN] the version */
)
{ /* Body */
    RIP_HEADER_PTR  hd = (RIP_HEADER_PTR)buf;
    _mem_zero(buf, sizeof(RIP_HEADER));
    mqx_htonc(hd->COMMAND, cmd);
    mqx_htonc(hd->VERSION, version);
    mqx_htons(hd->MBZ, 0);
} /* Endbody */
예제 #16
0
/* Run command, check authentication first */
static void ftpsrv_process_cmd(FTPSRV_SESSION_STRUCT* session)
{
    const FTPSRV_COMMAND_STRUCT* row = ftpsrv_commands;
    int result = 1;
    char* cp = session->command;
    uint32_t auth_valid;

    /* Convert command to upper case */
    while (*cp)
    {
        *cp = toupper(*cp);
        cp++;
    }

    /* Find function corresponding to command */
    while ((row->command != NULL) && strncmp(session->command, row->command, strlen(row->command)))
    {
        row++;
    }
    
    /* Process authentication sequence if required */
    auth_valid = ftpsrv_process_auth(session, row->auth_req);
    
    /* Run command if authentication is valid */
    if (auth_valid)
    {
        if (row->function != NULL)
        {
            row->function(session);
        }
        else
        {
            session->message = (char*) ftpsrvmsg_unimp;
        }
    }
    else
    {
        if (session->message == NULL)
        {
            session->message = (char*) ftpsrvmsg_not_logged;
        }
        if (session->auth_input.uid != NULL)
        {
            _mem_free(session->auth_input.uid);
            session->auth_input.uid = NULL;
        }
    }

    ftpsrv_send_msg(session, session->message);
    session->message = NULL;
    _mem_zero(session->buffer, FTPSRV_BUF_SIZE);
}
예제 #17
0
파일: bootp.c 프로젝트: gxliu/MQX_3.8.0
void BOOTP_open
   (
      TCPIP_PARM_BOOTP _PTR_ parms
   )
{ /* Body */
   IP_IF_PTR      if_ptr = (IP_IF_PTR)parms->handle;
   BOOTP_CFG_PTR  bootp = (BOOTP_CFG_PTR) &parms->config;
   uint_32        error;

   error = BOOT_open(BOOT_service);
   if (error) {
      RTCSCMD_complete(parms, error);
      return;
   } /* Endif */

   if_ptr->BOOTFN = BOOTP_service;

   /* Pick a random transaction ID */
   bootp->XID = RTCS_rand();

   /* Set initial timeout */
   bootp->TIMEOUT = BOOTP_TIMEOUT_MIN;
   bootp->SECS = 0;

   /* Build a BOOTREQUEST packet */
   htonc(bootp->PACKET.OP,    BOOTPOP_BOOTREQUEST);
   htonc(bootp->PACKET.HTYPE, if_ptr->DEV_TYPE);
   htonc(bootp->PACKET.HLEN,  if_ptr->DEV_ADDRLEN);
   htonc(bootp->PACKET.HOPS,  0);
   htonl(bootp->PACKET.XID,   bootp->XID);
   htons(bootp->PACKET.FLAGS, 0x8000);
   htonl(bootp->PACKET.CIADDR, INADDR_ANY);
   htonl(bootp->PACKET.YIADDR, INADDR_ANY);
   htonl(bootp->PACKET.SIADDR, INADDR_ANY);
   htonl(bootp->PACKET.GIADDR, INADDR_ANY);

   _mem_zero(bootp->PACKET.CHADDR, sizeof(bootp->PACKET.CHADDR));
   _mem_copy(if_ptr->DEV_ADDR, bootp->PACKET.CHADDR, if_ptr->DEV_ADDRLEN);

   /* Start the retransmission timer to start sending immediately */
   bootp->RESEND.TIME    = 0;
   bootp->RESEND.EVENT   = BOOTP_send;
   bootp->RESEND.PRIVATE = if_ptr;
   TCPIP_Event_add(&bootp->RESEND);

   if_ptr->BOOT = (pointer)parms;

} /* Endbody */
예제 #18
0
/*
** Send data from session buffer to client.
**
** IN:
**      HTTPSRV_SESSION_STRUCT *session - session to use.
**
** OUT:
**      none
**
** Return Value:
**      int - number of bytes send.
*/
uint_32 httpsrv_send_buffer(HTTPSRV_SESSION_STRUCT *session)
{
    uint_32 length = 0;

    length = send(session->sock, session->buffer.data, session->buffer.offset, 0);
    
    if (length != RTCS_ERROR)
    {
        _mem_zero(session->buffer.data, session->buffer.offset);
        session->buffer.offset = 0;
    }
    else
    {
        length = 0;
    }
    return(length);
}
예제 #19
0
static unsigned char  *DNS_parse_answer_name_to_dotted_form
   (
   unsigned char  *buffer_ptr,
   unsigned char  *name,
   uint32_t     loc
   )

{  /* Body */

   unsigned char        *compressed_name;
   unsigned char        *fill_ptr;
   unsigned char         label_size;
   uint32_t       i;
   uint16_t       new_location;

   fill_ptr = RTCS_HOST_NAMES[loc];
   _mem_zero(fill_ptr, DNS_MAX_CHARS_IN_NAME);

   compressed_name = name;

   while ( mqx_ntohc(compressed_name) != '\0' ) {

      if ( mqx_ntohc(compressed_name) & DNS_COMPRESSED_NAME_MASK ) {
         new_location = mqx_ntohs(compressed_name)
                        & DNS_COMPRESSED_LOCATION_MASK;
         compressed_name = buffer_ptr + new_location;
      }/* Endif */

      label_size  = mqx_ntohc(compressed_name);
      compressed_name++;

      for ( i = 0; i < label_size; i++ ) {
           *fill_ptr++ = mqx_ntohc(compressed_name);
            compressed_name++;
      } /* Endfor */

      if ( mqx_ntohc(compressed_name) != '\0' ) {
         *fill_ptr++ = '.';
      }/* Endif */
   } /* Endwhile */

   *fill_ptr = '\0';

   return( RTCS_HOST_NAMES[loc] );

}  /* Endbody */
예제 #20
0
파일: dma.c 프로젝트: NeoXiong/MP3
/* prepares TCD for register to memory copy */
int dma_tcd_reg2mem(DMA_TCD_STRUCT *tcd, volatile void *reg, int regw, void *dst, uint_32 size)
{
    uint_32 dst_alignment;
    uint_32 reg_alignment;
    int endian_swap;
    int dstw;

    endian_swap = (regw < -1);
    regw = (regw < 0) ? -regw : regw;

    if ((regw != 1) && (regw != 2) && (regw != 4)) {
        return MQX_INVALID_PARAMETER;
    }

    reg_alignment = alignment_tab[((uint_32)reg | (uint_32)size) & 3];

    if (reg_alignment < regw) {
        return MQX_INVALID_PARAMETER;
    }

    _mem_zero(tcd, sizeof(*tcd));

    tcd->SRC_ADDR = (uint_32)reg; /* periodic read from the same address */
    tcd->SRC_WIDTH = regw;
    tcd->SRC_OFFSET = 0;

    if (endian_swap) {
        tcd->DST_ADDR = (uint_32)dst + regw - 1;
        tcd->DST_WIDTH = 1;
        tcd->DST_OFFSET = -1;    
        tcd->LOOP_DST_OFFSET = 2*regw;
    }
    else {
        dst_alignment = alignment_tab[((uint_32)dst | (uint_32)size) & 3];
        dstw = (dst_alignment > regw) ? regw : dst_alignment;
        tcd->DST_ADDR = (uint_32)dst;
        tcd->DST_WIDTH = dstw;
        tcd->DST_OFFSET = dstw;
    }

    tcd->LOOP_BYTES = regw;
    tcd->LOOP_COUNT = (size >> (regw/2));

    return MQX_OK;
}
예제 #21
0
파일: dma.c 프로젝트: NeoXiong/MP3
/* prepares TCD for memory to register copy */
int dma_tcd_mem2reg(DMA_TCD_STRUCT *tcd, volatile void *reg, int regw, void *src, uint_32 size)
{
    uint_32 src_alignment;
    uint_32 reg_alignment;
    int endian_swap;
    int srcw;
    
    endian_swap = (regw < 0);
    regw = (regw < 0) ? -regw : regw;

    if ((regw != 1) && (regw != 2) && (regw != 4)) {
        return MQX_INVALID_PARAMETER;
    }

    reg_alignment = alignment_tab[((uint_32)reg | (uint_32)size) & 3];

    if (reg_alignment < regw) {
        return MQX_INVALID_PARAMETER;
    }

    _mem_zero(tcd, sizeof(*tcd));

    if (endian_swap) {
        tcd->SRC_ADDR = (uint_32)src + regw - 1;
        tcd->SRC_WIDTH = 1;
        tcd->SRC_OFFSET = -1;
        tcd->LOOP_SRC_OFFSET = 2*regw;
    }
    else {
        src_alignment = alignment_tab[((uint_32)src | (uint_32)size) & 3];
        srcw = (src_alignment > regw) ? regw : src_alignment;
        tcd->SRC_ADDR = (uint_32)src;
        tcd->SRC_WIDTH = srcw;
        tcd->SRC_OFFSET = srcw;
    }

    tcd->DST_ADDR = (uint_32)reg;
    tcd->DST_WIDTH = regw;
    tcd->DST_OFFSET = 0; /* periodic write to the same address */

    tcd->LOOP_BYTES = regw;
    tcd->LOOP_COUNT = (size >> (regw/2));

    return MQX_OK;
}
예제 #22
0
int32_t ftpsrv_help(FTPSRV_SESSION_STRUCT* session)
{
    const FTPSRV_COMMAND_STRUCT* cmd_ptr = ftpsrv_commands;
    uint32_t                     length = 0;
    uint32_t                     n = 1;
    uint32_t                     space = FTPSRV_BUF_SIZE;
    uint32_t                     max_cmd_length = ftpsrv_max_cmd_length();
    char*                        separator;
    char*                        buffer = session->buffer;

    ftpsrv_send_msg(session, ftpsrvmsg_help_start);

    while(cmd_ptr->command != NULL)
    {
        /* After every fifth command print a new line. Commands are separated by spaces */
        separator = (n % 4) ? " " : "\r\n";
        n++;
        length += snprintf(buffer+length, space, "%s%s", cmd_ptr->command, separator);
        space = FTPSRV_BUF_SIZE-length;
        
        /* If there is not enough space in the buffer flush it to client and repeat printing */
        if (space < (max_cmd_length + sizeof("\r\n")))
        {
            send(session->control_sock, buffer, FTPSRV_BUF_SIZE-space, 0);
            _mem_zero(buffer, length);
            space = FTPSRV_BUF_SIZE;
            length = 0;
        }

        cmd_ptr++;
    }

    if (n)
    {
        space -= snprintf(buffer+length, space, "\r\n");
    }
    
    /* Send command list from the buffer and set message to HELP end text */
    send(session->control_sock, buffer, FTPSRV_BUF_SIZE-space, 0);

    session->message = (char*) ftpsrvmsg_help_end;
    return(FTPSRV_OK);
}
void usb_class_mass_q_init
   (
      /* [IN] interface structure pointer */
      USB_MASS_CLASS_INTF_STRUCT_PTR intf_ptr
   )
{ /* Body */
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_q_init");
   #endif

//   intf_ptr->QUEUE.FIRST  = 0;
//   intf_ptr->QUEUE.LAST   = 0;
//   intf_ptr->QUEUE.AVAILABLE  = TRUE;
   _mem_zero(&intf_ptr->QUEUE, sizeof(intf_ptr->QUEUE));
   #ifdef _HOST_DEBUG_
      DEBUG_LOG_TRACE("usb_class_mass_q_init, SUCCESSFUL");
   #endif
   
} /* Endbody */
예제 #24
0
파일: mem_allz.c 프로젝트: gxliu/MQX_3.8.0
pointer _mem_alloc_zero
   (
      /* [IN] the size of the memory block */
      _mem_size size
   )
{ /* Body */
   KERNEL_DATA_STRUCT_PTR  kernel_data;
   _mqx_uint               error;
   pointer                 result;

   _GET_KERNEL_DATA(kernel_data);
   _KLOGE2(KLOG_mem_alloc_zero, size);

   _INT_DISABLE();
      
   result = _mem_alloc_internal(size, kernel_data->ACTIVE_PTR, 
      (MEMPOOL_STRUCT_PTR)&kernel_data->KD_POOL, &error);

   /* update the memory allocation pointer in case a lower priority
   ** task was preempted inside _mem_alloc_internal
   */
   kernel_data->KD_POOL.POOL_ALLOC_CURRENT_BLOCK = 
      kernel_data->KD_POOL.POOL_FREE_LIST_PTR;

   _INT_ENABLE();

#if MQX_CHECK_ERRORS
   if (error != MQX_OK) {
      _task_set_error(error);
   } /* Endif */
#endif

   if (result != NULL) {
      _mem_zero(result, size);
   } /* Endif */

   _KLOGX3(KLOG_mem_alloc_zero, result, 
      kernel_data->KD_POOL.POOL_BLOCK_IN_ERROR);
   return(result);

} /* Endbody */
예제 #25
0
RTCSPCB_PTR RTCSPCB_alloc( void )
{ 
    RTCS_DATA_PTR     RTCS_data_ptr;
    RTCSPCB_PTR       rtcs_pcb;

    RTCS_data_ptr = RTCS_get_data();

    rtcs_pcb = RTCS_part_alloc(RTCS_data_ptr->RTCS_PCB_partition);

    if (rtcs_pcb != NULL)
    {
        /* Set default values.*/
        rtcs_pcb->IP_SUM_PTR = NULL;
        _mem_zero(&rtcs_pcb->LINK_OPTIONS, sizeof(rtcs_pcb->LINK_OPTIONS));
        RTCSPCB_SET_TRANS_PROTL(rtcs_pcb, 0);
    }

    RTCSLOG_PCB_ALLOC(rtcs_pcb);

    return rtcs_pcb;
}
예제 #26
0
파일: rtcspcb.c 프로젝트: gxliu/MQX_3.8.0
RTCSPCB_PTR RTCSPCB_alloc
   (
      void
   )
{ 
   RTCS_DATA_PTR     RTCS_data_ptr;
   RTCSPCB_PTR       rtcs_pcb;

   RTCS_data_ptr = RTCS_get_data();

   rtcs_pcb = RTCS_part_alloc(RTCS_data_ptr->RTCS_PCB_partition);

   if (rtcs_pcb != NULL) {
      rtcs_pcb->IP_SUM_PTR = NULL;
      _mem_zero(&rtcs_pcb->LINK_OPTIONS, sizeof(rtcs_pcb->LINK_OPTIONS));
   } /* Endif */

   RTCSLOG_PCB_ALLOC(rtcs_pcb);

   return rtcs_pcb;

}
예제 #27
0
static void RIP_build_rte(
    unsigned char   *buf,    /* [OUT] the route entry */
    uint16_t     family,
    uint16_t     rt_tag,
    _ip_address net_addr,
    _ip_address net_mask,
    _ip_address next_hop,
    uint32_t     metric,
    uint32_t     rip_vers
)
{ /* Body */
    RIP_ENTRY_PTR   rte = (RIP_ENTRY_PTR)buf;
    if (rip_vers == RIP_V2){
        mqx_htons(rte->RT_TAG, rt_tag);
        mqx_htonl(rte->NETMASK, net_mask);
        mqx_htonl(rte->NEXTHOP, next_hop);
    }else{
        _mem_zero(buf, sizeof(RIP_ENTRY));
    }
    mqx_htons(rte->FAMILY, family);
    mqx_htonl(rte->NETADDR, net_addr);
    mqx_htonl(rte->METRIC, metric);
} /* Endbody */
예제 #28
0
파일: dma.c 프로젝트: NeoXiong/MP3
/* prepares TCD for memory to memory copy */
void dma_tcd_memcpy(DMA_TCD_STRUCT *tcd, void *src, void *dst, uint_32 size)
{
    int src_alignment;
    int dst_alignment;
    int loop_alignment;

    src_alignment = alignment_tab[((uint_32)src | (uint_32)size) & 3];
    dst_alignment = alignment_tab[((uint_32)src | (uint_32)size) & 3];

    loop_alignment = (src_alignment > dst_alignment) ? src_alignment : dst_alignment;

    _mem_zero(tcd, sizeof(*tcd));

    tcd->SRC_ADDR = (uint_32)src;
    tcd->SRC_WIDTH = src_alignment;
    tcd->SRC_OFFSET = src_alignment;

    tcd->DST_ADDR = (uint_32)dst;
    tcd->DST_WIDTH = dst_alignment;
    tcd->DST_OFFSET = dst_alignment;

    tcd->LOOP_BYTES = loop_alignment;
    tcd->LOOP_COUNT = (size >> (loop_alignment/2)); /* loop_alignment is one of 1, 2 or 4, more efficient than plain division */
}
예제 #29
0
파일: dhcpsrv.c 프로젝트: gxliu/MQX_3.8.0
static void DHCPSRV_write_header
   (
      DHCPSRV_STATE_STRUCT_PTR   state,
      DHCPSRV_ADDR_STRUCT_PTR    lease_ptr,
      uint_32                    lease_time,
      uchar                      msgtype
   )
{ /* Body */
   DHCP_HEADER_PTR   outp;
   DHCP_HEADER_PTR   inp;
   uchar_ptr         optptr;
   volatile uint_32           optlen;
   uint_32           temp_long;
   uint_16           temp_short;
   uchar             temp_char;

   outp = (DHCP_HEADER_PTR)state->SND_BUFFER;
   inp  = (DHCP_HEADER_PTR)state->RCV_BUFFER;

   /* Build a DHCPOFFER, DHCPACK, or DHCPNAK packet */
   htonc(outp->OP, DHCPOP_BOOTREPLY);
   htonc(outp->HTYPE, ARPLINK_ETHERNET);
   temp_char = ntohc(inp->HLEN);
   htonc(outp->HLEN, temp_char);
   htonc(outp->HOPS, 0);

   /* Use client's existing transaction ID */
   temp_long = ntohl(inp->XID);
   htonl(outp->XID, temp_long);

   htons(outp->SECS, 0);

   if (ntohl(inp->GIADDR) == 0) {
      htons(outp->FLAGS, 0);
   } else {
      temp_short = ntohs(inp->FLAGS);
      htons(outp->FLAGS, temp_short);
   } /* Endif */

   if (msgtype == DHCPTYPE_DHCPOFFER) {
      htonl(outp->CIADDR, 0);
   } else {
      temp_long = ntohl(inp->CIADDR);
      htonl(outp->CIADDR, temp_long);
   } /* Endif */

   if (msgtype == DHCPTYPE_DHCPNAK) {
      htonl(outp->YIADDR, 0);
      htonl(outp->SIADDR, 0);
   } else {
      htonl(outp->YIADDR, lease_ptr->IP_ADDR);
      htonl(outp->SIADDR, lease_ptr->OPTIONS->SADDR);
   } /* Endif */

   htonl(outp->GIADDR, 0);

   _mem_copy(inp->CHADDR, outp->CHADDR, sizeof(outp->CHADDR));

   if (msgtype == DHCPTYPE_DHCPNAK) {
      _mem_zero(outp->SNAME, sizeof(outp->SNAME));
      _mem_zero(outp->FILE,  sizeof(outp->FILE));
   } else {
      _mem_copy(lease_ptr->OPTIONS->SNAME, outp->SNAME, sizeof(outp->SNAME));
      _mem_copy(lease_ptr->OPTIONS->FILE,  outp->FILE,  sizeof(outp->FILE));
   } /* Endif */

   /*
   ** Fill in the required response options. These are message type,
   ** subnet mask, and server id.
   */

   optlen = sizeof(DHCP_HEADER);
   optptr = state->SND_BUFFER + optlen;

   /* The Magic Cookie must always be the first thing in the OPTIONS */
   htonl(optptr, DHCP_MAGIC);
   optptr += DHCPSIZE_MAGIC;
   optlen += DHCPSIZE_MAGIC;

#define DHCP_OPTION(type,len,val) \
            htonc(optptr, DHCPOPT_  ## type); optptr++; optlen++; \
            htonc(optptr, DHCPSIZE_ ## type); optptr++; optlen++; \
            hton ## len(optptr, val);                             \
            optptr += DHCPSIZE_ ## type;                          \
            optlen += DHCPSIZE_ ## type

   DHCP_OPTION(MSGTYPE,  c, msgtype);
   if (msgtype != DHCPTYPE_DHCPNAK) {
      DHCP_OPTION(SERVERID, l, lease_ptr->OPTIONS->SERVERID);
      DHCP_OPTION(MASK,     l, lease_ptr->OPTIONS->MASK);
      DHCP_OPTION(LEASE,    l, lease_time);
   } /* Endif */

   state->SND_BUFFER_LEN = optlen;

} /* Endbody */
예제 #30
0
_ppp_handle PPP_init
   (
        PPP_PARAM_STRUCT*     params
   )
{ /* Body */

#if RTCSCFG_ENABLE_IP4 
    PPP_CFG_PTR          ppp_ptr;
    uint32_t             error;
    IPCP_DATA_STRUCT     ipcp_data;
    int stage = 0;

    /* Allocate the state structure */
    ppp_ptr = _mem_alloc_zero(sizeof(PPP_CFG));
    
    if (!ppp_ptr)
    {
        return(NULL);
    }
    ppp_ptr->DEVICE_NAME = _mem_alloc_zero(strlen(params->device)+1);
    if (ppp_ptr->DEVICE_NAME == NULL)
    {
        _mem_free(ppp_ptr);
        return(NULL);
    }
    strcpy(ppp_ptr->DEVICE_NAME, params->device);
    /* Stage 0 - Open low level device */
    ppp_ptr->IOPCB_DEVICE = fopen(params->device, NULL);
    if (ppp_ptr->IOPCB_DEVICE == NULL)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 1 - Initialize HDLC and lwsem */
    ppp_ptr->DEVICE = _iopcb_ppphdlc_init(ppp_ptr->IOPCB_DEVICE);
    if (ppp_ptr->DEVICE == NULL)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }

    ppp_ptr->RECV_OPTIONS = &PPP_DEFAULT_OPTIONS;
    ppp_ptr->SEND_OPTIONS = &PPP_DEFAULT_OPTIONS;

    if (_lwsem_create(&ppp_ptr->MUTEX, 1))
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 2 - Initialize LCP */
    error = LCP_init(ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 3 - Initialize and open CCP */
    /*
    error = CCP_init(ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return error;
    }
    CCP_open(ppp_ptr);
    */
    stage++;

    /* Stage 4 - Create a pool of message buffers */
    ppp_ptr->MSG_POOL = RTCS_msgpool_create(sizeof(PPP_MESSAGE), PPP_MESSAGE_INITCOUNT, PPP_MESSAGE_GROWTH, PPP_MESSAGE_LIMIT);
    if (ppp_ptr->MSG_POOL == MSGPOOL_NULL_POOL_ID)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 5 - Create the Tx Task */
    error = RTCS_task_create("PPP tx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_tx_task, ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    } 
    stage++;

    /* Stage 6 - Create the Rx Task */
    ppp_ptr->STOP_RX = FALSE; 

    error = RTCS_task_create("PPP rx", _PPPTASK_priority, _PPPTASK_stacksize + 1000, PPP_rx_task, ppp_ptr);
    if (error)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 7 - Open HDLC layer */
    error = _iopcb_open(ppp_ptr->DEVICE, PPP_lowerup, PPP_lowerdown, ppp_ptr);
    if (error != PPPHDLC_OK)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    ppp_ptr->VALID = PPP_VALID;
    stage++;

    /* Stage 8 - Add PPP interface to RTCS */
    error = RTCS_if_add(ppp_ptr, RTCS_IF_PPP, &ppp_ptr->IF_HANDLE);
    if (error != RTCS_OK)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    stage++;

    /* Stage 9 - Bind IP address to PPP interface */
    _mem_zero(&ipcp_data, sizeof(ipcp_data));
    ipcp_data.IP_UP              = params->up;
    ipcp_data.IP_DOWN            = params->down;
    ipcp_data.IP_PARAM           = params->callback_param;

    if(params->listen_flag == 0)
    {
        ipcp_data.ACCEPT_LOCAL_ADDR  = TRUE;
        ipcp_data.ACCEPT_REMOTE_ADDR = TRUE;
    }
    else
    {
        ipcp_data.ACCEPT_LOCAL_ADDR  = FALSE;
        ipcp_data.ACCEPT_REMOTE_ADDR = FALSE;
    }
    ipcp_data.LOCAL_ADDR         = params->local_addr;
    ipcp_data.REMOTE_ADDR        = params->remote_addr;
    ipcp_data.DEFAULT_NETMASK    = TRUE;
    ipcp_data.DEFAULT_ROUTE      = TRUE;

    error = RTCS_if_bind_IPCP(ppp_ptr->IF_HANDLE, &ipcp_data);
    if (error != RTCS_OK)
    {
        PPP_init_fail(ppp_ptr, stage);
        return(NULL);
    }
    params->if_handle = ppp_ptr->IF_HANDLE;
    stage++;

    /* Stage 10 - Init complete, return handle */
    return(ppp_ptr);

#else

    return(NULL);    

#endif /* RTCSCFG_ENABLE_IP4 */

} /* Endbody */