Пример #1
0
void
Init_System( NU_MEMORY_POOL  *Memory_Pool)
{
        VOID *Stack_Pointer;
        STATUS sts;

        if ( NU_Create_Event_Group(&Buffers_Available, "BUFAVA") != NU_SUCCESS) {
                printf("Error Creating the Event Group\n\r");
                return;
        }

    /* Create Test_Task 0 */
    NU_Allocate_Memory(Memory_Pool, &Stack_Pointer, 50000, NU_NO_SUSPEND);
    NU_Create_Task(&Test_Task0, "Test0", test_0, 0, NU_NULL, 
                                        Stack_Pointer, 10000, 3, 20, NU_PREEMPT, NU_START);
    /* Create Test_Task 1 */
    NU_Allocate_Memory(Memory_Pool, &Stack_Pointer, 50000, NU_NO_SUSPEND);
    NU_Create_Task(&Test_Task1, "Test1", test_1, 0, NU_NULL, 
                                        Stack_Pointer, 10000, 3, 20, NU_PREEMPT, NU_START);

    /* Create Test_Task 2 */
    NU_Allocate_Memory(Memory_Pool, &Stack_Pointer, 50000, NU_NO_SUSPEND);
    NU_Create_Task(&Test_Task2, "Test2", test_2, 0, NU_NULL, 
                                        Stack_Pointer, 10000, 3, 20, NU_PREEMPT, NU_START);
    /* Create Test_Task 3 */
    NU_Allocate_Memory(Memory_Pool, &Stack_Pointer, 50000, NU_NO_SUSPEND);
    NU_Create_Task(&Test_Task3, "Test3", test_3, 0, NU_NULL, 
                                        Stack_Pointer, 10000, 3, 20, NU_PREEMPT, NU_START);
}
Пример #2
0
void
Init_System( NU_MEMORY_POOL  *Memory_Pool)
{
	VOID *Stack_Pointer;
	STATUS sts;

    /* Create IOPMaster_Task */
    NU_Allocate_Memory(Memory_Pool, &Stack_Pointer, 10000, NU_NO_SUSPEND);
    NU_Create_Task(&Test_Task0, "Test0", test_0, 0, NU_NULL, 
					Stack_Pointer, 10000, 3, 20, NU_PREEMPT, NU_START);
    NU_Allocate_Memory(Memory_Pool, &Stack_Pointer, 10000, NU_NO_SUSPEND);
    NU_Create_Task(&Test_Task1, "Test1", test_1, 0, NU_NULL, 
					Stack_Pointer, 10000, 3, 20, NU_PREEMPT, NU_START);
}
Пример #3
0
int
dsx_addintr(void (*pintr)())
{
	STATUS  status;

	if( dsx_hisr_stack )
		return(DSX_SUCCESS);
	
	status = NU_Register_LISR(DSX_INT_VECTOR, dsx_lih, &old_lisr_dsx);
	if ( status != NU_SUCCESS ) {
		goto dsx_addintr_abort;
	}
	
	status = NU_Allocate_Memory(&System_Memory,(void **)&(dsx_hisr_stack),
				   DSX_HISR_STACK_SIZE, NU_NO_SUSPEND);	
	if ( status != NU_SUCCESS ) {
		goto dsx_addintr_abort;
	}
		
	status = NU_Create_HISR(&DSX_HISR, "dsx_hisr", pintr, 2,
							dsx_hisr_stack, DSX_HISR_STACK_SIZE);
	if ( status != NU_SUCCESS ) {
		goto dsx_addintr_abort;
	}
	return(DSX_SUCCESS);
	
dsx_addintr_abort:
	
	if ( dsx_hisr_stack)
		NU_Deallocate_Memory(dsx_hisr_stack);
	return(DSX_FAIL);

}
Пример #4
0
STATUS Ether_Add_Multi(DV_DEVICE_ENTRY *dev, uint8 *multi_addr)
{
    INT         irq_level;
    NET_MULTI   *em;
        int                     i;

    irq_level = NU_Control_Interrupts(NU_DISABLE_INTERRUPTS);

    /* Verify that the ethernet multicast address is valid. */
    if (((multi_addr[0] & 0xFF) != 1) || ((multi_addr[2] & 0xFF) != 0x5e))
    {
        NU_Control_Interrupts(irq_level);
                printf("Invalid Address\n\r");
        return (-1);
    }

    /* Has this address already been added to the list. */
    for ( em = dev->dev_ethermulti;
          em != NU_NULL && (bcmp(em->nm_addr, multi_addr, 6) != 0);
          em = em->nm_next);

    if(em != NU_NULL)
    {
        /* Found a match. Increment the reference count. */
        em->nm_refcount++;
        NU_Control_Interrupts(irq_level);
                printf("Entry Exists\n\r");
        return (NU_SUCCESS);
    }

    /* This is a new address. Allocate some memory for it. */
    if (NU_Allocate_Memory(&System_Memory, (VOID **)&em,
                         sizeof (*em), (UNSIGNED)NU_NO_SUSPEND) != NU_SUCCESS)
    {
                printf("Mem Alloc Error\n\r");
        NU_Control_Interrupts(irq_level);
        return(NU_MEM_ALLOC);
    }

    /* Initialize the new entry. */
    bcopy(multi_addr, em->nm_addr, 6);
    em->nm_device = dev;
    em->nm_refcount = 1;

    /* Link it into the list. */
    em->nm_next = dev->dev_ethermulti;
    dev->dev_ethermulti = em;

    /*  Restore the previous interrupt lockout level.  */
    NU_Control_Interrupts(irq_level);

        printf("\n\rEntry Added----");
        for(i=0; i < 6; i++)
                printf("%02X:", multi_addr[i]);
        printf("\n\r");
    return(NU_SUCCESS);

} /* NET_Add_Multi */
Пример #5
0
STATUS FF_Sim_Device::Open(FF_Mem *p_mem)
{
	// When simulating with memory, we must not initialize
	// the device twice; otherwise we will wipe out our memory.
	if (FT_device_initialized)
		return OK;

	FT_device_initialized = 1;

	// Initialize the interrupt service routine.
	Status status = FF_ISR_Open(p_mem, &Interrupt_Callback);
	if (status != OK)
		return status;
		
	// Initialize the watchdog routine.
	status = FF_watchdog.Open(p_mem, Flash_Address::Num_Units() );
	if (status != OK)
		return status;
		
	// We need to initialize the device before we can ask it how many
	// device blocks it has, so Flash_Address has not been initialized.
	//U32 num_bytes = Flash_Address::Num_Units() * Flash_Address::Pages_Per_Unit() * Flash_Address::Bytes_Per_Page();
	U32 num_bytes = SIM_NUM_UNITS * SIM_PAGES_PER_UNIT * SIM_BYTES_PER_PAGE;

#ifndef _WINDOWS
#ifdef THREADX
    // Allocate memory for simulating file system.
    STATUS status = tx_byte_allocate(&System_Memory, (void **)&p_mem_file, num_bytes, TX_WAIT_FOREVER);
#else
    // Allocate memory for simulating file system.
    STATUS status = NU_Allocate_Memory(&System_Memory, (void **)&p_mem_file, num_bytes, NU_NO_SUSPEND);
#endif
	if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize_Test", 
			"Allocate memory failed",
			status,
			0);
	}
#else
	p_mem_file = (char*)FT_p_mem_file;
#endif
	p_mem_file_last = p_mem_file + num_bytes;
	
	// Set file to all erased.
	memset(p_mem_file, 0XFF, num_bytes);

	Set_Bad_Spots();
	return OK;
}
Пример #6
0
static void *rtNucleusMalloc (size_t size)
{
   VOID   *pointer;
   STATUS sts;

   if (nuPool == 0)  
      NU_Memory_Pool_Pointers (&nuPool, 1);

   sts = NU_Allocate_Memory (nuPool, &pointer, size,
                             NU_NO_SUSPEND);
   if (sts != NU_SUCCESS) {
      ERC_System_Error(sts);
      return NULL;
   }    
   return pointer;
}
Пример #7
0
void    Application_Initialize(void *first_available_memory)
{
    VOID    *pointer;

    /* Create a system memory pool that will be used to allocate task stacks,
       queue areas, etc.  */
#ifdef  INCLUDE_ODYSSEY
    NU_Create_Memory_Pool(&System_Memory, "SYSMEM", 
                        first_available_memory, 100000000, 56, NU_FIFO);
#else
    NU_Create_Memory_Pool(&System_Memory, "SYSMEM", 
                        first_available_memory, 2000000, 56, NU_FIFO);
#endif
                        
    /* Create IOPMaster_Task */
    NU_Allocate_Memory(&System_Memory, &pointer, 10000, NU_NO_SUSPEND);
    NU_Create_Task(&IOPMaster_Task, "IOPMaster", IOPMaster, 0, NU_NULL, 
                                        pointer, 10000, 1, 20, NU_PREEMPT, NU_START);

}
Пример #8
0
STATUS DEV_Init_Devices (DEV_DEVICE *devices, INT dev_count)
{
    STATUS                  status;
    DV_DEVICE_ENTRY         *dev_ptr;
    INT                     i;
    static INT              next_index = 0;
#if (INCLUDE_RIP2)
    static INT              need_rip2 = 0;
#endif


    for ( i = 0; i < dev_count; i++)
    {
        /*  Allocate memory for this device entry.  */
        if ((status = NU_Allocate_Memory(&System_Memory, (VOID **)&dev_ptr,
                                (UNSIGNED)(sizeof(struct _DV_DEVICE_ENTRY)),
                                (UNSIGNED)NU_NO_SUSPEND)) != NU_SUCCESS)
        {
            return (status);
        }

        /*  Clear out the structure.  */
        UTL_Zero(dev_ptr, sizeof(struct _DV_DEVICE_ENTRY));

        /* Adde the new device entry to the list of devices. */
        dll_enqueue((tqe_t *)&DEV_Table, (tqe_t *)dev_ptr);

#if (INCLUDE_RIP2)
        /* Should RIP2 be used on this device. */
        if( devices[i].dv_use_rip2 )
        {
            if (!need_rip2)
                NU_Resume_Task(&rip2_task_ptr);

            need_rip2++;

            /* Set the routing metric for this device. */
            if (devices[i].dv_ifmetric)
                dev_ptr->dev_metric = devices[i].dv_ifmetric;
            else
                dev_ptr->dev_metric = 1;

            dev_ptr->dev_rip2_recvmode = devices[i].dv_recvmode;
            dev_ptr->dev_rip2_sendmode = devices[i].dv_sendmode;
        }
#endif /* INCLUDE_RIP2 */


        /* Now initialize the fields that we can.  The rest will be initialized
           by the driver. */

        /* Set the unit number.  This number will be unique for all devices.
           The first will be numbered at 0 each succeeding device will be
           numbered contiguously. */
        dev_ptr->dev_index = next_index++;

        /* Initialize the device's name. */
        dev_ptr->dev_net_if_name = devices[i].dv_name;

        /* Get the flags set by the application */
        dev_ptr->dev_flags = devices[i].dv_flags;

        /* Is this a serial link? */
        if (devices[i].dv_flags & DV_POINTTOPOINT)
        {
            /* Store the options that pertain only to a serial link. All of
               these may not be used. It depends on the UART. */
            dev_ptr->dev_com_port  = devices[i].dv_hw.uart.com_port;
            dev_ptr->dev_baud_rate = devices[i].dv_hw.uart.baud_rate;
            dev_ptr->dev_data_mode = devices[i].dv_hw.uart.data_mode;
            dev_ptr->dev_parity    = devices[i].dv_hw.uart.parity;
            dev_ptr->dev_stop_bits = devices[i].dv_hw.uart.stop_bits;
            dev_ptr->dev_data_bits = devices[i].dv_hw.uart.data_bits;
        }
        else
        {
            /* Store the options that pertain only to an ethernet link */
            dev_ptr->dev_irq     = devices[i].dv_hw.ether.dv_irq;
            dev_ptr->dev_sm_addr = devices[i].dv_hw.ether.dv_shared_addr;
            dev_ptr->dev_io_addr = devices[i].dv_hw.ether.dv_io_addr;
        }

        if( (status = (devices[i].dv_init)(dev_ptr)) != NU_SUCCESS)
            return status;

        /* Indicate that the device is Running. */
        dev_ptr->dev_flags |= DV_RUNNING;

        /* If an IP address was specified and this is not a PPP device then
           go ahead and attach the IP address and the subnet mask.  Otherwise
           it is assumed Bootp will be used to discover the IP address and
           attach it at a later time. */
        if (( *(uint32 *)devices[i].dv_ip_addr != 0 ) &&
                (!(devices[i].dv_flags & DV_POINTTOPOINT)))
        {

            if ((status = DEV_Attach_IP_To_Device(dev_ptr->dev_net_if_name,
                                         (uint8 *)devices[i].dv_ip_addr,
                                         (uint8 *)devices[i].dv_subnet_mask))
                                         != NU_SUCCESS)
            {
                return (status);
            }
        }
        else
            /* Clear the devices IP address. */
            memcpy(dev_ptr->dev_addr.dev_ip_addr, IP_Null, 4);
    }

    /*  Everything is OK.  */
    return( NU_SUCCESS );

}  /* DEV_Init_Devices. */
Пример #9
0
int BOOTP_Process_Packets(int16 socketd, BOOTP_STRUCT *bp, uint16 timeout)
{
    int                 ret;
    sint                x, items, len;
    int16               flen;
    char                *inbuf;
    int16               found = 0;
    uint8               bootp_cookie[4] = BOOTP_COOKIE;
    uint32              vend_cookie;
    ulint               local_xid;
    BOOTPLAYER          *bootp_ptr;          /* Bootp struct pointer*/
    FD_SET              readfs, writefs, exceptfs;
    STATUS              status;
    struct addr_struct  fromaddr;
    uchar               *ptr;
    uint8 message[80];

    /*   Allocate Memory for input Buffer */

    status = NU_Allocate_Memory(&System_Memory, (VOID **)&inbuf, IOSIZE,
				(UNSIGNED)NU_NO_SUSPEND);

    /*   Check if an error occured during NU_Allocate_Memory */
    if (status != NU_SUCCESS)
    {
        NU_Tcp_Log_Error( DHCP_NO_MEMORY, TCP_FATAL, __FILE__, __LINE__);
        return (NU_NO_SOCK_MEMORY);
    }

    /*   Do While to process received data */
    do 
    { /*  do while */
	 
        NU_FD_Init(&readfs);
        NU_FD_Set(socketd, &readfs);

        ret = NU_Select(NSOCKETS, &readfs, &writefs, &exceptfs,
                (timeout * TICKS_PER_SECOND));

        if( ret == NU_NO_DATA )
           break;

        if(NU_FD_Check(socketd, &readfs) == NU_FALSE)
           break;

        fromaddr.family = NU_FAMILY_IP;
        fromaddr.port = 0;

        ret = NU_Recv_From(socketd, inbuf, IOSIZE, 0, &fromaddr, &flen);

        if( ret < 0 )
        {
              NU_Tcp_Log_Error( BOOTP_RECV_FAILED, TCP_FATAL,
                   __FILE__, __LINE__);
              break;
        }

        /* get pointer to BOOTP packet. */
        bootp_ptr = (BOOTPLAYER *)inbuf;

        /*  Retrieve the unique ID from the packet  */
        memcpy(&local_xid, &bootp_ptr->bp_xid, sizeof(ulint) );


        /* see if packet is the returning response to the packet I sent */
        if( local_xid != bootp_xid )
           continue;


        /* Accept the very first packet */

        /*  Get the Server address */
        bp->bp_siaddr[0] = bootp_ptr->bp_siaddr.is_ip_addrs[0];
        bp->bp_siaddr[1] = bootp_ptr->bp_siaddr.is_ip_addrs[1];
        bp->bp_siaddr[2] = bootp_ptr->bp_siaddr.is_ip_addrs[2];
        bp->bp_siaddr[3] = bootp_ptr->bp_siaddr.is_ip_addrs[3];

        /*  Get the gateway address */
        bp->bp_giaddr[0] = bootp_ptr->bp_giaddr.is_ip_addrs[0];
        bp->bp_giaddr[1] = bootp_ptr->bp_giaddr.is_ip_addrs[1];
        bp->bp_giaddr[2] = bootp_ptr->bp_giaddr.is_ip_addrs[2];
        bp->bp_giaddr[3] = bootp_ptr->bp_giaddr.is_ip_addrs[3];

        /*  Get my IP address */
        bp->bp_yiaddr[0] = bootp_ptr->bp_yiaddr.is_ip_addrs[0];
        bp->bp_yiaddr[1] = bootp_ptr->bp_yiaddr.is_ip_addrs[1];
        bp->bp_yiaddr[2] = bootp_ptr->bp_yiaddr.is_ip_addrs[2];
        bp->bp_yiaddr[3] = bootp_ptr->bp_yiaddr.is_ip_addrs[3];

        /*  Get the Server Name */
        memcpy(bp->bp_sname, bootp_ptr->bp_sname, sizeof(bp->bp_sname) );

        /* Get the Bootp file name.  */
        memcpy(bp->bp_file, bootp_ptr->bp_file, sizeof(bp->bp_file) );

        /*  Get the Vnedor specific cookie.  */
        memcpy( &vend_cookie, bootp_ptr->bp_vend, 4);

        /* test to see if cookie is a vendor cookie */
        if (comparen (bootp_ptr->bp_vend, VM_RFC1048,4))
        {

            if( vend_cookie == *(uint32 *)bootp_cookie )
            {
             /* Now loop thur vendor options, passing them to user */
            /* callback function. */
            ptr = bootp_ptr->bp_vend + 4;
            found = 1;
            while ((*ptr != 255) && ((ptr - bootp_ptr->bp_vend) < 64))
            {
                 switch (*ptr)
                 {
                  case BOOTP_PAD:           /* nop padding, used to align fields to word */
                          ptr++;    /* boundries.                                */
                          break;

                  case BOOTP_SUBNET:       /* subnet mask */
                          len = (*(ptr + 1));
                          ptr += 2;
                          bp->bp_net_mask[0] = (*ptr);
                          bp->bp_net_mask[1] = (*(ptr + 1));
                          bp->bp_net_mask[2] = (*(ptr + 2));
                          bp->bp_net_mask[3] = (*(ptr + 3));
                          ptr += len;
                          break;

                  case BOOTP_TIMEOFF:       /* time offset */
                          ptr += 3;
                          break;

                  case BOOTP_GATEWAY:       /* gateways  */
                          len = (*(ptr + 1));
                          items = len/4;
                          ptr += 2;
                          for (x = 0; x < items; x++)
                          {
                              ptr += 4;
                          }
                          break;

                  case BOOTP_TIMESERV:             /* time servers */
                  case BOOTP_NAMESERV:            /* IEN = 116 name server */
                          ptr += 3;
                          break;

                  case BOOTP_DOMNAME:             /* domain name server */
                          len = (*(ptr + 1));
                          items = len / 4;
                          ptr += 2;
                          for (x = 0; x < items; x++)
                          {

                              ptr += 4;
                          }
                          break;

                  case BOOTP_LOGSERV:       /* log server */
                                /* Place your code here. */
                  case BOOTP_COOKSRV:       /* cookie server */
                                /* Place your code here. */
                  case BOOTP_LPRSRV:        /* lpr server */
                                /* Place your code here. */
                  case BOOTP_IMPRSRV:       /* impress server */
                                /* Place your code here. */
                  case BOOTP_RLPSRV:        /* rlp server */
                                /* Place your code here. */
                          ptr += 3;
                          break;

                  case BOOTP_HOSTNAME:      /* client host name */
                          len = (*(ptr + 1));
                          strncpy ((int8 *)message, (const int8 *)ptr + 2, (uint16)len);
                          message[len] = 0;
                          ptr += len+2;
                          break;

                  case BOOTP_BFILSZ:        /* Bootp File Size */
                          ptr += 2;
                          break;

                  case BOOTP_END:
                          break;

                  default:
                          ptr += 3;
                          break;
                 }    /* end switch */
            }             /* end while    */
            }
        }

    } while( found == 0 );

    NU_Deallocate_Memory(inbuf);

    return(found);
}   /* end BOOTP_Process_Packets */
Пример #10
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 */
Пример #11
0
STATUS
init_buf(int slot_no)
{
	STATUS rc;
	buf_t	*dmabuf, *pcibuf;
	int		i;
	U32		pci_start_phys;
	
	
	if ( lbufs[0] )
		return(NU_SUCCESS);

	printf("Initalizing Buffers...");
	/* Allocate the Local Buffers */
	rc = NU_Allocate_Memory(&Local_Memory, (VOID **)&dmabuf,
		((sizeof(buf_t) * MAX_PCI_SLOTS) + DMABUF_ALIGN_SIZE), NU_NO_SUSPEND);
	
	if ( rc != NU_SUCCESS) {
		printf("Error in Allocating Local Bufs\n\r");
		return(rc);
	}
	
	/* Align the Address */
	dmabuf = (buf_t *)(ALIGN((U32)dmabuf, DMABUF_ALIGN_SIZE));
	for(i=0; i < MAX_PCI_SLOTS; i++) {
		lbufs[i] = dmabuf;
		dmabuf++;
	}
	/* Allocate PCI Buffers */
	rc = NU_Allocate_Memory(&System_Memory, (VOID **)&pcibuf,
		((sizeof(buf_t) * MAX_PCI_SLOTS) + DMABUF_ALIGN_SIZE), NU_NO_SUSPEND);
	
	if ( rc != NU_SUCCESS) {
		printf("Error in Allocating Pci Bufs\n\r");
		return(rc);
	}
	
	/* Align the Address */
	pcibuf = (buf_t *)(ALIGN((U32)pcibuf, DMABUF_ALIGN_SIZE));

	for(i=0; i < MAX_PCI_SLOTS; i++) {
		pbufs[i] = pcibuf;
		pcibuf++;
	}
	
	mem_write((U32)(lbufs[0]), 0, 0);
	mem_write((U32)(pbufs[0]), 0, 0);
	/* Initialize the Buffers */
	for(i=1; i < MAX_PCI_SLOTS; i++) {
		DMASTARTED(0);
		gt_dmachain(0, VTOP((U32)(lbufs[0])), VTOP((U32)(lbufs[i])), 
						sizeof(buf_t), 0, 0);
		while(!(DMADONE(0))) ;
		DMASTARTED(0);
		gt_dmachain(0, VTOP((U32)(pbufs[0])), VTOP((U32)(pbufs[i])), 
						sizeof(buf_t), 0, 0);
		while(!(DMADONE(0))) ;
		lbufs[i]->flag = slot_no;
		pbufs[i]->flag = slot_no;
	}
	printf("Done\n\r");
	return(NU_SUCCESS);
}
Пример #12
0
void   Initialize_Test(UNSIGNED argc, VOID *argv)
{
 	TRACE_ENTRY(Initialize_Test);
 	STATUS status;
 	
    // Allocate memory for callback contexts.
    void *p_memory;
    NU_Allocate_Memory(&system_memory, &p_memory, MEMORY_FOR_CALLBACKS, NU_NO_SUSPEND);
    
    // Initialize callbacks.
	status = Callback_Context::Initialize(p_memory, MEMORY_FOR_CALLBACKS, sizeof(FF_Bat_Context) + 16);
	if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize_Test", 
			"Callback_Context::Initialize failed",
			status,
			0);
	}
	
    // Allocate memory for buffer for reading and writing pages.
    NU_Allocate_Memory(&system_memory, &p_page_buffer, MAX_PAGE_SIZE + 64, NU_NO_SUSPEND);
    p_page_buffer = (void *)ALIGN(p_page_buffer, 64);
    
    NU_Allocate_Memory(&system_memory, &p_read_buffer, MAX_PAGE_SIZE + 64, NU_NO_SUSPEND);
    p_read_buffer = (void *)ALIGN(p_read_buffer, 64);
    
    NU_Allocate_Memory(&system_memory, &p_write_buffer, MAX_PAGE_SIZE + 64, NU_NO_SUSPEND);
    p_write_buffer = (void *)ALIGN(p_write_buffer, 64);
    
    NU_Allocate_Memory(&system_memory, &p_verify_buffer, MAX_PAGE_SIZE + 64, NU_NO_SUSPEND);
    p_verify_buffer = (void *)ALIGN(p_verify_buffer, 64);
    
    // Allocate memory for buffer for statistics reporting.
    NU_Allocate_Memory(&system_memory, (void **)&p_string_buffer, 8000, NU_NO_SUSPEND);
    
	// Find out how much memory is left.
	CHAR 		pool_name[8];
	VOID		*start_address;
	UNSIGNED	pool_size;
	UNSIGNED	min_allocation;
	UNSIGNED	memory_available;
	OPTION		suspend_type;
	UNSIGNED	tasks_suspended;
	NU_TASK		*first_task;
	NU_Memory_Pool_Information(&system_memory,
		pool_name,
		&start_address,
		&pool_size,
		&min_allocation,
		&memory_available,
		&suspend_type,
		&tasks_suspended,
		&first_task);
	
    // Allocate the rest of memory for the file system.
    status = NU_Allocate_Memory(&system_memory, &FT_p_memory, 
    	memory_available - 100, NU_NO_SUSPEND);
	if (status != OK)
	{
		CT_Log_Error(CT_ERROR_TYPE_FATAL,
			"Initialize_Test", 
			"Allocate memory failed",
			status,
			0);
	}
    
    // How much is left now.
    U32 available_now;
	NU_Memory_Pool_Information(&system_memory,
		pool_name,
		&start_address,
		&pool_size,
		&min_allocation,
		&available_now,
		&suspend_type,
		&tasks_suspended,
		&first_task);
	
	// Initialize config structures.
	Init_Config(memory_available);
	
	// Create a parent context.
    FT_Test_Context *p_test_context = 
		(FT_Test_Context *)Callback_Context::Allocate(sizeof(FT_Test_Context));
	p_test_context->Set_Callback(&Run_Test);
	p_test_context->Make_Ready();
	Show_Version();
	
#if 0

	Tracef("\nSize of FF_SGL = %d", sizeof(FF_SGL));
	Tracef("\nSize of SGE_SIMPLE_ELEMENT = %d", sizeof(SGE_SIMPLE_ELEMENT));
	Tracef("\nSize of FF_Controller_Context = %d", sizeof(FF_Controller_Context));
	Tracef("\nSize of Flash_Device_Status = %d", sizeof(Flash_Device_Status));
	Tracef("\nSize of Flash_Address = %d", sizeof(Flash_Address));
#endif
	
	
} // Initialize_Test
Пример #13
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