net.c

来自「mcf5307实验源代码」· C语言 代码 · 共 794 行 · 第 1/3 页

C
794
字号
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      intswap                                                          */
/*                                                                       */
/*************************************************************************/
void statcheck(void )
{
   int16 i;
   struct port *p;
         
   for (i = 0; i < 20; i++)
   {
       printf ("\n%d > ", i);
       p = portlist[i];
       if (p != NU_NULL)
       {
           printf ("state: %d  %5u  %5u  %10ld  %5d  %5d",
                   p->state,intswap(p->tcpout.t.source),
                   intswap(p->tcpout.t.dest),p->out.lasttime,p->rto,
                   p->out.contain);
       }
   } /* end for */
}
#endif  /* NOT_USED */

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      initbuffer                                                       */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*  Initialize the global buffer_list and the global buffer_freelist.    */
/*  A large block of memory is allocated.  This block is broken up into  */
/*  smaller blocks of equal size.  Each of these blocks will be used to  */
/*  to hold an incoming or outgoing packet.   When a block contains no   */
/*  packet it is placed in the buffer_freelist.  All blocks are          */
/*  initially placed in the buffer_freelist.                             */
/*                                                                       */
/*                                                                       */
/* CALLED BY                                                             */
/*      dlayerinit                                                       */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      NU_Allocate_Memory                                               */
/*      dll_enqueue                                                      */
/*                                                                       */
/*************************************************************************/
static int16 initbuffer(void)
{
    static int16 i;
    char HUGE *ptr;
    STATUS status;

    /* Allocate a large block of memory, which will be broken up into
     * blocks of a size appropriate for buffering packets.
     */
#if 0
    status = NU_Allocate_Memory(&System_Memory, (VOID *)&ptr,
                                MAXBUFFERS * (UNSIGNED)(sizeof(struct pqueue)),
                                (UNSIGNED)NU_NO_SUSPEND);
    if (status != NU_SUCCESS)
    {
        printf ("Can not create memory for Partition Pool.\n");
        DOS_Exit (-1);
    }
#endif

    /* Initialize the global trans_list and trans_freelist.   MQ  12/13/96 */
    trans_list.head = trans_list.tail = NU_NULL;
    trans_freelist.head = trans_freelist.tail = NU_NULL;

    /* Initialize the global buffer pointers. */
    buffer_list.head = NU_NULL;
    buffer_list.tail = NU_NULL;
    buffer_freelist.head = NU_NULL;
    buffer_freelist.tail = NU_NULL;

    /* Break the block of memory up and place each block into the
     * buffer_freelist.
     */

    for (i = 0; i < MAXBUFFERS; i++)
    {

#ifdef PLUS
        status = NU_Allocate_Memory(&System_Memory, (VOID *)&ptr,
                                (UNSIGNED)(sizeof(struct pqueue)),
                                (UNSIGNED)NU_NO_SUSPEND);
#else
        status = NU_Alloc_Memory (sizeof(struct pqueue), (unsigned int **)&ptr,
                                  NU_WAIT_FOREVER);
#endif

        ptr = normalize_ptr(ptr);

        if (status != NU_SUCCESS)
        {
            return (-1);
        }
        dll_enqueue((tqe_t *) &buffer_freelist, (tqe_t *) ptr);
       /* ptr += sizeof(struct pqueue); */
    }

    /* Initialize the number of buffers that are currently allocated. */
    Buffers_Used = 0;

    /* New C routine for reading the Ethernet address from the card */
    NU_Get_Address (&nnmyaddr[0], Scon.address, Scon.ioaddr);


   return (0);

}  /* end initbuffer */


/***************************************************************************/
/*  pcgetaddr
*   return results from indirect NU_Get_Address call.
*   This is a pc-specific request for the 48-bit address which was added
*   so that the user program could print the value.
*/
#ifdef PROC_29K
void pcgetaddr (int8 *s, int16 x, int16 y)
{
    if (NU_Get_Address)
    {
        (*NU_Get_Address)((uint8 *)s, x, y);
    }
}
#endif /* PROC_29K */

/*************************************************************************/
/*  config network parameters
*   Set IRQ and DMA parameters for initialization of the 3com adaptor
*/
#ifdef PROC_29K

int16 netparms (uint16 irq, uint16 address, uint16 ioaddr)
{
    nnirq = irq;
    nnaddr = address;
    nnioaddr = ioaddr;

	return (0);
}
#endif /* PROC_29K */

/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      NET_Send                                                         */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      Depending on the mode used this function either queues a packet  */
/*      for transmission, or transmits it directly by calling            */
/*      dlayersend().                                                    */
/*                                                                       */
/* CALLED BY                                                             */
/*      tcpsend                                                          */
/*      tcp_sendack                                                      */
/*      tcpresetfin                                                      */
/*      arp_reply                                                        */
/*      arp_request                                                      */
/*      netusend                                                         */
/*                                                                       */
/* CALLS                                                                 */
/*      dlayersend                                                       */
/*      dll_enqueue                                                      */
/*      dll_transq_alloc                                                 */
/*      NU_Control_Interrupts                                            */
/*                                                                       */
/* INPUTS                                                                */
/*      buf_ptr         Pointer to a buffer that contains the packet     */
/*                      to be transmitted.                               */
/*      packet_len      Length of the packet to be transmitted.          */
/*      packet_type     Type of packet to be transmitted.                */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*         NAME            DATE                    REMARKS               */
/*                                                                       */
/*     G. Johnson        10/05/95             Created Initial version.   */
/*                                                                       */
/*************************************************************************/
int16 NET_Send(struct pqueue HUGE *buf_ptr, int16 packet_len, uchar packet_type)
{
#ifndef PACKET
#ifdef PLUS
    INT             old_int;
#else
    int             old_int;
#endif
    struct transq   *item;
#endif

    /*  We begin the process of sending the buffer.  This includes allocating
        a trinsmit header, filling in the fields and then placing it on the
        transmit list and sending it if necessary.  */

#ifdef PACKET
    dlayersend ((DLAYER *)buf_ptr->packet, packet_len);

    if(packet_type == OTHER_PKT)
        dll_enqueue((tqe_t *)&buffer_freelist, (tqe_t *)buf_ptr);
#else

//    old_int = NU_Control_Interrupts(NU_DISABLE_INTERRUPTS);
    Tao_SaveOldSR();

    /* Allocate an item from the trans_freelist. */
    item = dll_transq_alloc();

    /* Store a pointer to the beginning of the packet. */
    item->pkt = buf_ptr->packet;
    item->buffer = buf_ptr;

    /* Store the length of the data. */
    item->length = packet_len;

    /* Setup the packet type field.  A type of TCP_DATA_PKT prevents the buffer
     * from being deallocated immediately after transmission is complete. */
    item->pkt_type = packet_type;

    /* Place the item on the transmit queue. */
    dll_enqueue((tqe_t *)&trans_list, (tqe_t *)item);


    /* If this is the first item in the transmit queue we need to resume the
     * transmit task.  If not another packet is already being transmitted. */
    if(trans_list.head == item)
    {
//        NU_Control_Interrupts(old_int);
          Tao_LoadOldSR();  

        /* Resume the the transmit task. */
        dlayersend ((DLAYER *)item->pkt, item->length);
    }
    else
//        NU_Control_Interrupts(old_int);
         Tao_LoadOldSR();

#if SNMP_INCLUDED
    /* Increment the number of packets in the transmit queue.  This version of
       NET only supports a single interface.  So the index of 1 should always be
       right.
    */
    SNMP_ifOutQLen_Inc(0);
#endif


#endif

    return(NU_SUCCESS);
}  /* NET_Send */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?