/**
   Nucleus - Get the Lock (not interuptable).

\par Implementation
   - Take the specified semaphore --> LOCKED (see "NU_Obtain_Semaphore").
   - no timeout, wait for ever

\param
   lockId   Provides the pointer to the Lock Object.

\return
   IFX_SUCCESS if getting was successful, else
   IFX_ERROR if something was wrong

\remarks
   Cannot be used on interrupt level.
*/
IFX_int32_t IFXOS_LockGet(
               IFXOS_lock_t *lockId)
{
   if(lockId)
   {
      if (IFXOS_LOCK_INIT_VALID(lockId) == IFX_TRUE)
      {
         IFXOS_SYS_LOCK_RECURSIVE_CALL_COUNT_INC(lockId->pSysObject);
         IFXOS_SYS_LOCK_REQ_THREAD_ID_SET(lockId->pSysObject);

         /* Blocking call */
         if (NU_Obtain_Semaphore(&lockId->object, NU_SUSPEND) == NU_SUCCESS)
         {
            IFXOS_SYSOBJECT_SET_OWNER_THR_INFO(lockId->pSysObject);
            IFXOS_SYS_LOCK_GET_COUNT_INC(lockId->pSysObject);

            return IFX_SUCCESS;
         }

         IFXOS_SYS_LOCK_GET_FAILED_COUNT_INC(lockId->pSysObject);
      }
   }

   return IFX_ERROR;
}
Beispiel #2
0
/** @memo   Wait for a mutex to be available.

    @doc    Wait for a mutex to be available.  If the mutex is
    already available this function returns immediatley,
    otherwise it should block indefinitely or until the mutex
    is available.

    @postconditon For every time this function is successful
    on a designated mutex handle, a respective call to
    rtp_sig_mutex_release must be made.

    @return 0 if successful, -1 otherwise.  For debugging
    purposes; if the cause of the error is obtainable at the
    native Kernel layer, turn on RTP_DEBUG in rtpsignl.c
    to display the native error value.
 */
int rtp_sig_mutex_claim (
    RTP_HANDLE mutexHandle                /** Handle to the mutex to be claimed. */
)
{
    NU_Obtain_Semaphore((NU_SEMAPHORE*)&mutexHandle, NU_SUSPEND);
    /* No error return available, so we simply return success. */

    return (0);
}
VOS_UINT32 VOS_SmP( VOS_SEM Sm_ID, VOS_UINT32 ulTimeOutInMillSec )
{
    SEM_CONTROL_BLOCK  *temp_Ptr;
    UNSIGNED           iTimeOut;
    STATUS             ReturnCode;

    temp_Ptr = (SEM_CONTROL_BLOCK *)Sm_ID;

    if( temp_Ptr != temp_Ptr->SemId )
    {
        VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_IDERR);
        return (VOS_ERRNO_SEMA4_P_IDERR);
    }

    if (VOS_SEM_CTRL_BLK_IDLE == temp_Ptr->Flag)
    {
        VOS_SetErrorNo(VOS_ERRNO_SEMA4_P_NOTACTIVE);
        return(VOS_ERRNO_SEMA4_P_NOTACTIVE);
    }

    iTimeOut = (0 == ulTimeOutInMillSec) ?
        NU_SUSPEND : ulTimeOutInMillSec/MILLISECONDS_PER_TICK;

    ReturnCode = NU_Obtain_Semaphore(&(temp_Ptr->NuSem), iTimeOut);

    if ( NU_SUCCESS == ReturnCode )
    {
        return(VOS_OK);
    }

    LogPrint3("# VOS_SmP ID %x Name %s error %x.\r\n",
        Sm_ID, temp_Ptr->Name, ReturnCode );

    if ( NU_TIMEOUT == ReturnCode )
    {
        VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_TIMEOUT);
        return VOS_ERRNO_SEMA4_P_TIMEOUT;
    }

    VOS_SetErrorNo (VOS_ERRNO_SEMA4_P_CANOTP);
    return VOS_ERRNO_SEMA4_P_CANOTP;

}
Beispiel #4
0
void *BridgeMessageSend(void *func_ptr, int type, void *packed_args)
{
    ThreadInfo *i = (ThreadInfo*) malloc(sizeof(ThreadInfo));
    i->sync = (type == NU_SYNCHRONIZED_PROC);
    i->loked = 1;
    i->ret = 0;


    if(i->sync && NU_Create_Semaphore(&i->loker, "mopi", 0, NU_PRIORITY) != NU_SUCCESS) {
        ShowMSG(1, (int)"ProcB: Semaphore init failed");
        free(i);
        return 0;
    }

    GBS_SendMessage(BridgeMOPI_ID, MOPI_THREAD_PROC, func_ptr, i, packed_args);

    switch(type)
    {
        case NU_SYNCHRONIZED_PROC:
            NU_Obtain_Semaphore(&i->loker, NU_SUSPEND);
            break;

        case NU_ASYNC_PROC:
            /* in async mode return not support */
            return 0;
    }

    if(i->sync)
        NU_Delete_Semaphore(&i->loker);

    /* возвращаемое значение */
    void *ret = i->ret;

    /* больше не нужно оно */
    free(i);

    /* чистим стек аргументов */
    free(packed_args);

    /* возвращаем результат выполнения */
    return ret;
}
/**
   Nucleus - Get the Lock with timeout.

\par Implementation

\param
   lockId   Provides the pointer to the Lock Object.

\param
   timeout_ms  Timeout value [ms]
               - 0: no wait
               - -1: wait forever
               - any other value: waiting for specified amount of milliseconds
\param
   pRetCode    Points to the return code variable. [O]
               - If the pointer is NULL the return code will be ignored, else
                 the corresponding return code will be set
               - For timeout the return code is set to 1.

\return
   IFX_SUCCESS on success.
   IFX_ERROR   on error or timeout.

\note
   To detect timeouts provide the return code varibale, in case of timeout
   the return code is set to 1.
*/
IFX_int32_t IFXOS_LockTimedGet(
               IFXOS_lock_t *lockId,
               IFX_uint32_t timeout_ms,
               IFX_int32_t  *pRetCode)
{
   STATUS sts;

   if (pRetCode)
   {
      *pRetCode = 0;
   }

   if(lockId)
   {
      if (IFXOS_LOCK_INIT_VALID(lockId) == IFX_TRUE)
      {
         IFXOS_SYS_LOCK_RECURSIVE_CALL_COUNT_INC(lockId->pSysObject);
         IFXOS_SYS_LOCK_REQ_THREAD_ID_SET(lockId->pSysObject);

         switch(timeout_ms)
         {
            case 0xFFFFFFFF:
               sts = NU_Obtain_Semaphore(&lockId->object, NU_SUSPEND);
               /* Blocking call */
               if(sts == NU_SUCCESS)
               {
                  IFXOS_SYSOBJECT_SET_OWNER_THR_INFO(lockId->pSysObject);
                  IFXOS_SYS_LOCK_GET_COUNT_INC(lockId->pSysObject);

                  return IFX_SUCCESS;
               }

               IFXOS_SYS_LOCK_GET_FAILED_COUNT_INC(lockId->pSysObject);
               break;

            case 0:
               sts = NU_Obtain_Semaphore(&lockId->object, NU_NO_SUSPEND);
               /* Non Blocking */
               if(sts == NU_SUCCESS)
               {
                  IFXOS_SYSOBJECT_SET_OWNER_THR_INFO(lockId->pSysObject);
                  IFXOS_SYS_LOCK_GET_COUNT_INC(lockId->pSysObject);

                  return IFX_SUCCESS;
               }

               IFXOS_SYS_LOCK_GET_FAILED_COUNT_INC(lockId->pSysObject);
               break;

            default:
               sts = NU_Obtain_Semaphore(&lockId->object, IFXOS_MSEC_TO_TICK(timeout_ms));
               /* Blocking call */
               switch (sts) 
               { 
                  case NU_SUCCESS: 
                     IFXOS_SYSOBJECT_SET_OWNER_THR_INFO(lockId->pSysObject);
                     IFXOS_SYS_LOCK_GET_COUNT_INC(lockId->pSysObject);

                     return IFX_SUCCESS;
                  case NU_TIMEOUT: 
                     if (pRetCode)
                     {
                        *pRetCode = 1;
                     }

                     IFXOS_SYS_LOCK_GET_TOUT_COUNT_INC(lockId->pSysObject);

                     return IFX_ERROR;
                  default:
                     IFXOS_SYS_LOCK_GET_FAILED_COUNT_INC(lockId->pSysObject);
                     break;            
               }
               break;
         }

         switch(sts)
         {
            case NU_INVALID_SUSPEND:
            break;
         };

      }
   }

   return IFX_ERROR;
}
Beispiel #6
0
STATUS NU_Bootp ( CHAR  *dv_name, BOOTP_STRUCT *bp_ptr)
{
    uint16              delay, delay_mask = 3;
    int                 i;
    int                 ret;
    BOOTPLAYER          *bootp_ptr;
    IPLAYER             *ip_ptr;
    UDPLAYER            *udp_pkt;
    NET_BUFFER          *buf_ptr;
    NET_BUFFER          *next_buf=0;
    struct pseudotcp    tcp_chk;
    int16               failed = 0,retval=0;
    DV_DEVICE_ENTRY     *int_face=0;
    int16               socketd;
    uint8               *buffer;
    struct addr_struct  clientaddr;
    uint16              nbytes;
    STATUS              status;
    int16               hlen = sizeof (IPLAYER);
    INT                 length;
    int32               total_size, current_size;
    int                 found = 0;    
    int32               flags;
    SCK_SOCKADDR        sa;
    int32               temp_data_len,temp_total_data_len;
    DLAYER              *ether_header;

	/* Create a socket and bind to it, so that we can receive packets. */
    socketd = NU_Socket(NU_FAMILY_IP, NU_TYPE_DGRAM, NU_NONE);
    if( socketd < 0 )
    {
        NU_Tcp_Log_Error( BOOTP_SOCKET, TCP_FATAL, __FILE__, __LINE__);
        return (NU_BOOTP_INIT_FAILED);
    }

    /* build local address and port to bind to. */
    clientaddr.family = NU_FAMILY_IP;
    clientaddr.port   = IPPORT_BOOTPC;
    clientaddr.id.is_ip_addrs[0] = (uint8) 0;
    clientaddr.id.is_ip_addrs[1] = (uint8) 0;
    clientaddr.id.is_ip_addrs[2] = (uint8) 0;
    clientaddr.id.is_ip_addrs[3] = (uint8) 0;
    clientaddr.name = "ATI";

    /*  Allocate memory for the buffer space */
    status = NU_Allocate_Memory(&System_Memory,(VOID **) &buffer,sizeof(BOOTPLAYER), NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
            return (NU_BOOTP_INIT_FAILED);


    ret = NU_Bind(socketd, &clientaddr, 0);
    if( ret != socketd )
    {
        NU_Tcp_Log_Error( BOOTP_SOCKET_BIND, TCP_FATAL,
                    __FILE__, __LINE__);
        NU_Close_Socket(socketd);
        return (NU_BOOTP_INIT_FAILED);
    }

    UTL_Zero(bp_ptr->bp_mac_addr, sizeof(bp_ptr->bp_mac_addr));
    UTL_Zero(bp_ptr->bp_siaddr,sizeof(bp_ptr->bp_siaddr));
    UTL_Zero(bp_ptr->bp_giaddr,sizeof(bp_ptr->bp_giaddr));
    UTL_Zero(bp_ptr->bp_sname,sizeof(bp_ptr->bp_sname));
    UTL_Zero(bp_ptr->bp_file,sizeof(bp_ptr->bp_file));
	
    /*  Get the device by name to be used on BOOTP for this iteration. */
 
    int_face = DEV_Get_Dev_By_Name(dv_name);

    if (int_face->dev_mtu < BOOTP_MAX_HEADER_SIZE)
        return (NU_BOOTP_INIT_FAILED);

    /* copy the hardware address from the device structure */
    memcpy(bp_ptr->bp_mac_addr, int_face->dev_mac_addr, DADDLEN);

    /*  make sure that the MAC address is a good.  */
    if ( memcmp(bp_ptr->bp_mac_addr, "\0\0\0\0\0\0", 6) == 0)
        return (NU_BOOTP_INIT_FAILED);

    buf_ptr = MEM_Buffer_Chain_Dequeue(&MEM_Buffer_Freelist, BOOTP_MAX_HEADER_SIZE);

    if (buf_ptr == NU_NULL)
        return (NU_NO_BUFFERS);

    buf_ptr->mem_dlist = &BOOTP_List;


    UTL_Zero(buf_ptr->mem_parent_packet, sizeof(NET_PARENT_BUFFER_SIZE));
    
    
    if (buf_ptr->next_buffer != NU_NULL)
    {
        next_buf= buf_ptr->next_buffer;
    }
    
     UTL_Zero(next_buf->mem_packet, sizeof(NET_MAX_BUFFER_SIZE));





    /* Set up pointers to each of the headers that make up a BOOTP Packet.  */
    bootp_ptr = (BOOTPLAYER *)(buf_ptr->mem_parent_packet + (BOOTP_MAX_HEADER_SIZE - (sizeof(BOOTPLAYER))));
    udp_pkt  = (UDPLAYER *) (((char *)bootp_ptr) - sizeof(UDPLAYER));
    ip_ptr   = (IPLAYER *) (((char *)udp_pkt) - sizeof(IPLAYER));

    /*  Build the BOOTP Request Packet  */

    nbytes = BOOTP_init((BOOTPLAYER *)buffer, bp_ptr);

    /*  Initialize the local and foreign port numbers  */

    udp_pkt->source = intswap(IPPORT_BOOTPC);
    udp_pkt->dest   = intswap(IPPORT_BOOTPS);

    /* Set up the UDP Header  */

    udp_pkt->length = intswap ((uint16) (nbytes + sizeof(UDPLAYER)));

    udp_pkt->check = 0;



    buf_ptr->data_ptr = buf_ptr->mem_parent_packet + NET_MAX_UDP_HEADER_SIZE;
    total_size = nbytes;

    /*  Chain the Bootp Request Packet */

    if (total_size > NET_PARENT_BUFFER_SIZE)
    {
       current_size = NET_PARENT_BUFFER_SIZE - sizeof(IPLAYER) - NET_ETHER_HEADER_OFFSET_SIZE;
       total_size =   total_size - current_size;
    }
    else
    {
       current_size =  total_size;
    }

    /*  Copy Bootp Packet into first Buffer */
    memcpy(buf_ptr->data_ptr , buffer, current_size);

    /*  Set the Data Length to the Size of bytes copied.  */
    buf_ptr->data_len = current_size;

    /*  Set the Total data length to the Number of bytes in a Bootp Packet. */
    buf_ptr->mem_total_data_len = nbytes;

    /*  Increment Bootp Buffer to be at the number of bytes copied.  */
    buffer = buffer + current_size;

    /*  Check to make sure there is data to store in the mem_packet */

    while ((total_size) && (next_buf != NU_NULL))
    {

         if (total_size > NET_MAX_BUFFER_SIZE)
         {
             
             current_size = NET_MAX_BUFFER_SIZE;
         }
         else
         {
             current_size = total_size;
         }
         total_size = total_size - current_size;

         /*  Copy the remaining data in the chaining packets  */
         memcpy(next_buf->mem_packet,buffer,current_size);

         /*  Set the Data pointer to the remainder of the packets.  */
         next_buf->data_ptr = next_buf->mem_packet;
         next_buf->next = NU_NULL;
         next_buf->data_len = current_size;


         buffer = buffer + current_size;

         if (next_buf->next_buffer != NU_NULL)
         {
            next_buf = next_buf->next_buffer;
         }

    }

    /* Increment the Packet data pointer to the UDP layer */
    buf_ptr->data_ptr -= sizeof(UDPLAYER);

    /*  Copy the udp_pkt into the parent_packet.  */
    memcpy(buf_ptr->data_ptr,(uint8 *)udp_pkt,sizeof(UDPLAYER));

    /*  Increment the total data length */
    buf_ptr->mem_total_data_len += sizeof(UDPLAYER);

    /*  Increment the data length of this packet.  */
    buf_ptr->data_len += sizeof(UDPLAYER);

    /*  Calculate UDP Checksum  */

    tcp_chk.source  = 0x0;
    tcp_chk.dest    = 0xFFFFFFFF;
    tcp_chk.z       = 0;
    tcp_chk.proto   = IP_UDP_PROT;
    tcp_chk.tcplen  = intswap((uint16)buf_ptr->mem_total_data_len);
    udp_pkt->check =  tcpcheck( (uint16 *)&tcp_chk, buf_ptr);

    /* If a checksum of zero is computed it should be replaced with 0xffff. */
    if (udp_pkt->check == 0)
        udp_pkt->check = 0xFFFF;


   /*  Set up the IP header  */
    ip_ptr->versionandhdrlen = (((hlen >> 2)) | (IP_VERSION << 4));

    /*  Set the IP header to no fragments. */

    ip_ptr->frags = 0;

    /* Set the IP packet ID.  */

    ip_ptr->ident = 0;

    /* Set the type of service. */

    ip_ptr->service = 0;

    length = nbytes +(uint16)sizeof(UDPLAYER);

    /* Set the total length( data and IP header) for this packet. */

    ip_ptr->tlen = intswap((int16)(length + hlen));

    /*  Set the time to live. */

    ip_ptr->ttl = IP_TIME_TO_LIVE;

    /*  Set the protocol. */

    ip_ptr->protocol = IP_UDP_PROT;


    /* We are doing a broadcast, so we do not need this fields. */

    memset(ip_ptr->ipsource,0,4);
    memcpy(ip_ptr->ipdest,"\377\377\377\377",4);


    /*  Compute the IP checksum. */
    ip_ptr->check = 0;
    ip_ptr->check = ipcheck((uint16 *)ip_ptr, (uint16)(hlen >> 1));

    /*  Set the buffer pointer to the IP Layer.  */

    buf_ptr->data_ptr -= sizeof(IPLAYER);

    /*  Add the IPLAYER to the total data length */

    buf_ptr->mem_total_data_len += sizeof(IPLAYER);
    temp_total_data_len =  buf_ptr->mem_total_data_len;

    /*  Set the data length of the current packet.  */

    buf_ptr->data_len += sizeof(IPLAYER);
    temp_data_len =  buf_ptr->data_len;

    /*  Copy the IP header into the parent packet of the buffer chain.  */

    memcpy(buf_ptr->data_ptr,(uint8 *)ip_ptr,sizeof(IPLAYER));

    /*  Set initial Delay for Processing packets.  */

    delay= (delay_mask & NU_rand()) + 1;

    /*  Innitialize the ethernet header.  */

    ether_header = (DLAYER *)sa.sck_data;
    memcpy(ether_header->dest, NET_Ether_Broadaddr, DADDLEN);
    memcpy(ether_header->me, bp_ptr->bp_mac_addr, DADDLEN);
    ether_header->type = EIP;

    sa.sck_family = SK_FAM_UNSPEC;
    sa.sck_len = sizeof(sa);

    /*  Transmit the packet  */

    for(i=0; i< BOOTP_RETRIES; i++)
    {
        
        /* Grab the semaphore because we are about to change the interface
           that the BOOTP request will be sent over. */
        NU_Obtain_Semaphore(&TCP_Resource, NU_SUSPEND);

        /* The device will not send packets until an IP address is attached.
           Temporarily trick it into thinking an IP address is attached so this
           request can be sent.  Then set it back. */
        flags = int_face->dev_flags;
        int_face->dev_flags |= (DV_UP | DV_RUNNING);

        /* Send the packet. */
        status = (*(int_face->dev_output)) (buf_ptr, int_face,
                                            (SCK_SOCKADDR_IP *)&sa, NU_NULL);
        int_face->dev_flags = flags;

        NU_Release_Semaphore(&TCP_Resource);

        if( status != NU_SUCCESS)
        {
            NU_Tcp_Log_Error(BOOTP_SEND_FAILED, TCP_FATAL, __FILE__,__LINE__);
            break;
        }

        /*  Look at each packet on the buffer list to see if it is my reply */
        found = BOOTP_Process_Packets(socketd, bp_ptr, delay);

        if (found)
            break;                           /*  Found the Packet. */

        delay_mask++;


        delay = (delay_mask & NU_rand()) + 1;

        /*  Get the the packet off the Trasmitted list and retrasnmit again. */
        buf_ptr= BOOTP_List.head;
        buf_ptr->data_ptr = BOOTP_List.head->mem_parent_packet + NET_ETHER_HEADER_OFFSET_SIZE;
        buf_ptr->data_len = temp_data_len;
        buf_ptr->mem_total_data_len = temp_total_data_len;
    }  /*  End For Loop */


    if( found == 1 )
    {
        status = DEV_Attach_IP_To_Device( dv_name, bp_ptr->bp_yiaddr,
                                          bp_ptr->bp_net_mask);
        if( status != NU_SUCCESS )
        {
            NU_Tcp_Log_Error( BOOTP_ATTACH_IP, TCP_FATAL,
                  __FILE__, __LINE__);
            failed++;
        }

    }
	
    retval= failed + retval;
	   
    /* Cleanup */
    NU_Close_Socket(socketd);

    /*  Free the Buffer Chain.  */
    MEM_One_Buffer_Chain_Free (buf_ptr, &MEM_Buffer_Freelist);
    NU_Deallocate_Memory(buffer);
    if(!found)
        retval= BOOTP_RECV_FAILED;
    
    return(retval);
    
}  /* NU_Bootp */
Beispiel #7
0
/*************************************************************************/

#ifdef PLUS
VOID NU_EventsDispatcher(UNSIGNED argc, VOID *argv)
#else   /* !PLUS */
VOID NU_EventsDispatcher(VOID)
#endif  /* !PLUS */
{
    struct uport        *uprt;
    struct port         *prt;
    struct sock_struct  *sock_ptr = NU_NULL;  /* Socket pointer. */
#ifdef PLUS
    STATUS              status;
    UNSIGNED            waittime;
#else   /* !PLUS */
    int16               status,
                        waittime;
#endif  /* !PLUS */
    int16               tmoflag;
    UNSIGNED            event = 0,
                        dat = 0;
    tqe_t               *duptqe,
                        *tqe_wait;           /* Timer queue entry */
#ifdef NU_PPP
    DV_DEVICE_ENTRY     *dev_ptr;
#endif


    /*******************************************************************
       Receive_Message points to a single occurence in the event queue.
       The index 3 signals that the structure is 3 words (or 6 bytes)
       long and is formatted as follows:

       struct
       {
          8 bits: the msg_class
          8 bits: the event
          16 bits: pointer to the next event on the queue
          16 bits: the data field
       }
    *******************************************************************/
#ifdef PLUS
    UNSIGNED    Receive_Message[3] = {0, 0, 0};
    UNSIGNED    actual_size;
#else   /* !PLUS */
    unsigned int      Receive_Message[3];
#endif  /* !PLUS */
    tqe_wait = (tqe_t *)0;

#ifdef PLUS
    /*  Remove compilation warnings for unused parameters.  */
    status = (STATUS) argc + (STATUS) argv;
#endif

    while (1)
    {

        /* Retrieve a message from the event queue.  Note that if the source
           queue is empty this task suspends until something becomes
           available. */
#ifdef PLUS
        NU_Obtain_Semaphore(&TCP_Resource, NU_SUSPEND);
#else   /* !PLUS */
        NU_Request_Resource(TCP_Resource, NU_WAIT_FOREVER);
#endif  /* !PLUS */

        /*  If someone is waiting on the timer list, then we need to
            calculate the next hit time for that timer.  */

        if (!tqe_wait)
            tqe_wait = tcp_timerlist.flink;

        if (tqe_wait) {
#ifdef PLUS
            if (tqe_wait->duetime > NU_Retrieve_Clock())
                waittime = ((UNSIGNED) tqe_wait->duetime - NU_Retrieve_Clock());
            else
                waittime = NU_NO_SUSPEND;
#else   /* !PLUS */
            waittime = (tqe_wait->duetime - NU_Read_Time());
            if (waittime <= 0)
                waittime = (-1);
#endif  /* !PLUS */
        }
        else {
            tqe_wait = (tqe_t *)0;
#ifdef PLUS
            waittime = NU_SUSPEND;
#else   /* !PLUS */
            waittime = NU_WAIT_FOREVER;
#endif  /* !PLUS */
        }

#ifdef PLUS
        /*  If waittime is not NU_SUSPEND then there is a timeout value. */
        if (waittime != NU_NO_SUSPEND) {
            NU_Release_Semaphore(&TCP_Resource);
#else   /* !PLUS */
        if (waittime >= 0) {
            NU_Release_Resource(TCP_Resource);
#endif  /* !PLUS */

#ifdef PLUS
            status = NU_Receive_From_Queue(&eQueue, &Receive_Message[0],
                                           (UNSIGNED)3, &actual_size, waittime);

            NU_Obtain_Semaphore(&TCP_Resource, NU_SUSPEND);
#else   /* !PLUS */
            status = NU_Retrieve_Item(eQueue, Receive_Message, waittime);

            NU_Request_Resource(TCP_Resource, NU_WAIT_FOREVER);
#endif  /* !PLUS */

        }
        else

#ifdef PLUS
            status = NU_TIMEOUT;
#else   /* !PLUS */
            status = NU_QUEUE_TIMEOUT;
#endif  /* !PLUS */

#ifndef INTERRUPT
        netsleep(0);
#endif  /* !INTERRUPT */
        /* Determine if the message was received successfully.	*/

#ifdef PLUS
        if (status == NU_TIMEOUT)
#else   /* !PLUS */
        if (status == NU_QUEUE_TIMEOUT)
#endif  /* !PLUS */
        {
            if (tqe_wait == tcp_timerlist.flink) {

                /*  Take off the head of the list. */
                dll_dequeue((tqe_t *) &tcp_timerlist);

                /*  Place any duplicate entries on to the timer list. */
                duptqe = (tqe_t *)dll_dequeue(&tqe_wait->duplist);
                while (duptqe)
                {
                    tqpost((tqe_t *) &tcp_timerlist, duptqe);
                    duptqe = (tqe_t *)dll_dequeue(&tqe_wait->duplist);
                }

                /*  Place the dequeued entry on the free list. */
                dll_enqueue(&tcptimer_freelist, tqe_wait);

                tmoflag = 1;

                /* Take care of event TCPRETRANS here...other events are
                   handled by the CASE statement below... */

                if (tqe_wait->tqe_event == TCPRETRANS)
                {
                    /*  Get a pointer to the porlist entry.  */
                    prt = portlist[tqe_wait->tqe_data];

                    /*  If there is still data to be transmitted and we
                        still have a connection, update the retransmission
                        timeout value.  */
                    if ((prt->out.num_packets > 0) || (prt->state > SEST))
                    {
                        /*  If a retransmission timeout occurs, exponential
                         *  back-off.  This number returns toward the correct
                         *  value by the RTT measurement code in ackcheck. */
                        if (prt->rto < MAXRTO)
                            prt->rto <<= 1;      /* double it */
                    }

                    tcp_retransmit (prt, tqe_wait->tqe_ext_data);
                    tqe_wait = (tqe_t *)0;
#ifdef PLUS
                    NU_Release_Semaphore(&TCP_Resource);
#else   /* !PLUS */
                    NU_Release_Resource(TCP_Resource);
#endif  /* !PLUS */
                    continue;
                }
                else
                {
                    event = tqe_wait->tqe_event;
                    dat = tqe_wait->tqe_data;
                    status = NU_SUCCESS;
                }
            }
            else
            {
                tqe_wait = (tqe_t *)0;
#ifdef PLUS
                NU_Release_Semaphore(&TCP_Resource);
#else   /* !PLUS */
                NU_Release_Resource(TCP_Resource);
#endif  /* !PLUS */
                continue;
            }
        }
        else
        {
            tmoflag = 0;
            tqe_wait = (tqe_t *)NU_NULL;
        }

        /* Determine if the message was received successfully.  */
        if (status == NU_SUCCESS)
        {
            if (!tmoflag)
            {
                event = (int16)Receive_Message[0];
                dat   = (uint16)Receive_Message[2];
            }

            /* switch on the msg_class/event combination */
            switch (event)
            {
            default:
                break;

            case CONNULL:
                break;

            /***********  CONNECTION CLASS  **********************/
            case CONFAIL:  /* connection attempt failed */
            case CONOPEN:  /* successful connect attempt */

                /* Make sure the socket is not NULL, this is possible if a
                   TCP connection is made and immediately RESET by the
                   foreign host. */
                if ((sock_ptr = socket_list[dat]) != NU_NULL)
                {

                    /* return control to the waiting task */
#ifdef PLUS
                    if (sock_ptr->s_TXTask != NU_NULL)
                        NU_Resume_Task(sock_ptr->s_TXTask);
#else   /* !PLUS */
                    if (sock_ptr->s_TXTask != -1)
                        NU_Start(sock_ptr->s_TXTask);
#endif  /* !PLUS */
                }

                break;

            case TCPACK:
                /* An ack needs to be sent. */

                /* Get a pointer to the port. */
                prt = portlist[dat];

                /* Clear the ACK timer flag in the port. */
                prt->portFlags &= (~ACK_TIMER_SET);

                /* Send the ack. */
                tcp_sendack (prt);

                break;


            case CONTX:

                /*  get a pointer into the port list table at the
                    entry pointed to by dat in the event queue */
                prt = portlist[dat];

                if ( (prt->xmitFlag == NU_SET) &&
                        (prt->out.nextPacket != NU_NULL) )
                {
                    prt->tcpout.flags |= TPUSH;

                    tcp_xmit(prt, prt->out.nextPacket);

                    prt->out.nextPacket = (NET_BUFFER *)prt->out.nextPacket->next;

                    prt->xmitFlag = NU_CLEAR;

                }
                break;

            case WINPROBE:

                /* Get a pointer to the socket. */
                if ((sock_ptr = socket_list[dat]) != NU_NULL)
                {

                    /* restart the waiting task */
#ifdef PLUS
                    if (sock_ptr->s_TXTask != NU_NULL)
                        NU_Resume_Task(sock_ptr->s_TXTask);
#else
                    if (sock_ptr->s_TXTask != -1)
                        NU_Start(sock_ptr->s_TXTask);
#endif
                }
                break;


            case SELECT:

                NU_Resume_Task((NU_TASK *)dat);
                break;


            case ARPRESOLVE:
            case RARP_REQUEST:

                ARP_Event((uint16)dat);

                break;

            case CONRX:

                NET_Demux();
                break;

            /**********************  USER CLASS *************************/
            case UDPDATA:
                /* get a pointer into the port list table at the
                   entry pointed to by dat in the event queue */
                uprt = uportlist[dat];

                if (uprt != NU_NULL)
                {
                    /* return control to the waiting task */
#ifdef PLUS
                    if (uprt->RXTask != NU_NULL)
                        NU_Resume_Task(uprt->RXTask);
#else   /* !PLUS */
                    if (uprt->RXTask != -1)
                        NU_Start(uprt->RXTask);
#endif  /* !PLUS */
                }
                break;

#if INCLUDE_IP_MULTICASTING
            case EV_IGMP_REPORT :

                /* Send an IGMP multicast group membership report. */
                IGMP_REPORT_EVENT(dat);
                break;

#endif /* INCLUDE_IP_MULTICASTING */

            case EV_IP_REASSEMBLY :

                /* Clear the fragment list. The whole datagram has not
                   yet been received. */
                IP_Reassembly_Event((IP_QUEUE_ELEMENT *)dat);
                break;

                /*********************** PPP CLASS ************************/
#ifdef NU_PPP
            case LCP_RESEND:

                /* Remove the PPP header that was added the first time
                   this packet was sent. */
                lcp_state.negotiation_pkt->data_ptr += sizeof (PPP_HEADER);
                lcp_state.negotiation_pkt->data_len -= sizeof (PPP_HEADER);
                lcp_state.negotiation_pkt->mem_total_data_len
                -= sizeof (PPP_HEADER);

                /* Send the packet again. */
                PPP_TX_Packet (lcp_state.negotiation_pkt->mem_buf_device,
                               lcp_state.negotiation_pkt);

                break;

            case LCP_SEND_CONFIG:

                /* Send a new configure request packet */
                LCP_Send_Config_Req ();

                break;

            case HANGUP_MDM:

                MDM_Hangup();

                break;

            case LCP_ECHO_REQ:

                /* Send a echo request packet */
                LCP_Send_Echo_Req ((DV_DEVICE_ENTRY *) dat);

                break;

            case NCP_RESEND:

                /* Remove the PPP header that was added the first time
                   this packet was sent. */
                ncp_state.negotiation_pkt->data_ptr += sizeof (PPP_HEADER);
                ncp_state.negotiation_pkt->data_len -= sizeof (PPP_HEADER);
                ncp_state.negotiation_pkt->mem_total_data_len
                -= sizeof (PPP_HEADER);

                /* Send the packet again. */
                PPP_TX_Packet (ncp_state.negotiation_pkt->mem_buf_device,
                               ncp_state.negotiation_pkt);

                break;

            case NCP_SEND_CONFIG:


                /* Get a pointer to the device structure for this device
                   so that the IP address of this device can be found. */
                dev_ptr = (DV_DEVICE_ENTRY *)dat;

                /* Send it to the host */
                NCP_IP_Send_Config_Req (dev_ptr->dev_addr.dev_ip_addr);

                break;

            case LCP_CLOSE_LINK:

                /* Get a pointer to the device structure for this device
                   so that the IP address of this device can be found. */
                dev_ptr = (DV_DEVICE_ENTRY *)dat;

                /* Close the network down. */
                PPP_Kill_All_Open_Sockets(dev_ptr);

                /* Detach the IP address from this device. */
                DEV_Detach_IP_From_Device (dev_ptr->dev_net_if_name);

                /* Send a terminate request */
                LCP_Send_Terminate_Req();

                /* Start the timer */
                NU_Reset_Timer (&LCP_Restart_Timer, LCP_Timer_Expire,
                                LCP_TIMEOUT_VALUE, LCP_TIMEOUT_VALUE, NU_ENABLE_TIMER);

                break;

            case PAP_SEND_AUTH:

                /* Retransmit the authentication pkt */
                PAP_Send_Authentication();

                break;

            case CHAP_RESEND:

                /* Remove the PPP header that was added the first time
                   this packet was sent. */
                lcp_state.negotiation_pkt->data_ptr += sizeof (PPP_HEADER);
                lcp_state.negotiation_pkt->data_len -= sizeof (PPP_HEADER);
                lcp_state.negotiation_pkt->mem_total_data_len
                -= sizeof (PPP_HEADER);

                /* Resend the last sent chap packet */
                PPP_TX_Packet (lcp_state.negotiation_pkt->mem_buf_device,
                               lcp_state.negotiation_pkt);

                break;

            case CHAP_CHALL:

                /* Send the CHAP challenge */
                CHAP_Send_Challenge();

                break;

#endif /* NU_PPP */


            } /* end switch on msg_class/event combination */
        } /* end if status is NU_SUCCESS */

        /* added 11/3/92 - during ATI mods */
#ifdef PLUS
        NU_Release_Semaphore(&TCP_Resource);
#else   /* !PLUS */
        NU_Release_Resource(TCP_Resource);
#endif  /* !PLUS */

    } /* end while */
}  /* end NU_EventDispatcher */
Beispiel #8
0
void    Initialize()
{
    VOID    *pointer;
    
    // Create a semaphore so that this task will not finish.
	NU_SEMAPHORE		m_wait_forever_semaphore;
	STATUS status = NU_Create_Semaphore(&m_wait_forever_semaphore, "ReadySem",
		0, // initial count
		NU_FIFO);
	if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize_SSD", 
			"NU_Create_Semaphore failed",
			status,
			0);
	}

    // Turn on tracing.
    //TraceLevel[TRACE_SSD] = TRACE_ALL_LVL;
   
	char *p_next_available_memory = new (tBIG) char[TEST_PROGRAM_MEMORY_SIZE];
	
    /* Create a system memory pool that will be used to allocate task stacks,
       queue areas, etc.  */
    status = NU_Create_Memory_Pool(&system_memory, "SYSMEM", 
	    p_next_available_memory, 
	    TEST_PROGRAM_MEMORY_SIZE, // # bytes in the pool
	    56, // min # bytes in each allocation,
	    NU_FIFO);
                        
	if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize_SSD_Test", 
			"NU_Create_Memory_Pool failed",
			status,
			0);
	}

    /* Allocate stack space for task.  */
    status = NU_Allocate_Memory(&system_memory, &pointer, THREAD_STACK_SIZE, NU_NO_SUSPEND);
	if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize_SSD_Test", 
			"Allocate stack space failed",
			status,
			0);
	}
    
    /* Create task  */
    status = NU_Create_Task(&Task_0, "TASK 0", Initialize_Test, 
    	0, NU_NULL, pointer,
                   THREAD_STACK_SIZE, 1, 20, NU_PREEMPT, NU_START);
	if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize_SSD_Test", 
			"NU_Create_Task failed",
			status,
			0);
	}

	// Turn on tracing.
	//TraceLevel[TRACE_SSD] = 8;
	
	// Don't let this task finish!
	status = NU_Obtain_Semaphore(
		&m_wait_forever_semaphore,
		NU_SUSPEND);
	// Should never continue!
	//if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize", 
			"ANU_Obtain_Semaphore failed",
			status,
			0);
	}
	
} // Initialize