home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / internet / netlite / DCI / c / TRANSMIT < prev   
Text File  |  1993-04-27  |  3KB  |  153 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "kernel.h"
  4. #include "swis.h"
  5. #include "global.h"
  6.  
  7. void Transmit_Upcall(_kernel_swi_regs *r)
  8. {
  9.        struct packet *packet;
  10.  
  11.        r = r;
  12.  
  13.        packet = tx_first;
  14.  
  15.        if ((tx_first = tx_first->next) == NULLPACKET)
  16.                tx_last = NULLPACKET;
  17.  
  18.        free_tx_mbuf(packet->data);
  19.        free_packet(packet);
  20.  
  21.        tx = FALSE;
  22. }
  23.  
  24. void Transmit_Packet(void)
  25. {
  26.        _kernel_swi_regs rin, rout;
  27.        struct packet *packet;
  28.        int portno, type;
  29.  
  30.        tx = TRUE;
  31.  
  32.        packet = tx_first;
  33.        portno = packet->port;
  34.        type   = packet->type;
  35.  
  36.        if (port[portno].status != STATUS_UP)
  37.        {
  38.                if ((tx_first = tx_first->next) == NULLPACKET)
  39.                        tx_last = NULLPACKET;
  40.  
  41.                free_tx_mbuf(packet->data);
  42.                free_packet(packet);
  43.                tx = FALSE;
  44.        }
  45.        else
  46.        {
  47.                if (type == FRAME_IP) port[portno].iptx++;
  48.  
  49.                rin.r[1] = portno;
  50.                rin.r[2] = type;
  51.                rin.r[3] = (int)packet->hwaddr;
  52.                rin.r[4] = (int)packet->data;
  53.                rin.r[5] = EVENT_TX;
  54.                _kernel_swi(XOS_Bit | (swibase + SWI_NetworkIfSend), &rin, &rout);
  55.        }
  56. }
  57.  
  58. void Queue_Transmit_Packet(struct packet *packet)
  59. {
  60.        int state;
  61.  
  62.        if (packet == NULLPACKET) return;
  63.  
  64.        state = ensure_irqs_off();
  65.  
  66.        if (tx_first == NULLPACKET)
  67.        {
  68.                 tx_first = packet;
  69.                 tx_last  = packet;
  70.        }
  71.        else
  72.        {
  73.                 tx_last->next = packet;
  74.                 tx_last       = packet;
  75.        }
  76.  
  77.        restore_irqs(state);
  78. }
  79.  
  80. void Write_Port(_kernel_swi_regs *r)
  81. {
  82.        int ipaddr = r->r[3];
  83.        int portno = r->r[0];
  84.        int length = r->r[2];
  85.        char *data = (char *)r->r[1];
  86.        struct packet *packet;
  87.        struct mbuf *mbuf;
  88.        char *hwaddr;
  89.  
  90.        if (portno < 0 || portno >= nounits)
  91.        {
  92.                r->r[3] = SWI_INVPORT;
  93.                return;
  94.        }
  95.  
  96.        if (port[portno].status != STATUS_UP)
  97.        {
  98.                r->r[3] = SWI_OPEN;
  99.                return;
  100.        }
  101.  
  102.        if (length > 1500)
  103.        {
  104.                r->r[3] = SWI_TOOBIG;
  105.                return;
  106.        }
  107.  
  108.        if (len_q(tx_first) > MAX_Q_LEN)
  109.        {
  110.                txqfull++;
  111.                r->r[3] = SWI_NOMEM;
  112.                return;
  113.        }
  114.  
  115.        if ((mbuf = qdata(length, data)) == NULLMBUF)
  116.        {
  117.                memout++;
  118.                r->r[3] = SWI_NOMEM;
  119.                return;
  120.        }
  121.  
  122.        if ((packet = alloc_packet()) == NULLPACKET)
  123.        {
  124.                memout++;
  125.                free_tx_mbuf(mbuf);
  126.                r->r[3] = SWI_NOMEM;
  127.                return;
  128.        }
  129.  
  130.        packet->next   = NULLPACKET;
  131.        packet->port   = portno;
  132.        packet->type   = FRAME_IP;
  133.        packet->data   = mbuf;
  134.  
  135.        if ((hwaddr = Search_ARP_Cache(portno, ipaddr)) == NULL)
  136.        {
  137.                Create_ARP_Request(ipaddr, packet);
  138.        }
  139.        else
  140.        {
  141.                packet->hwaddr[0] = hwaddr[0];
  142.                packet->hwaddr[1] = hwaddr[1];
  143.                packet->hwaddr[2] = hwaddr[2];
  144.                packet->hwaddr[3] = hwaddr[3];
  145.                packet->hwaddr[4] = hwaddr[4];
  146.                packet->hwaddr[5] = hwaddr[5];
  147.  
  148.                Queue_Transmit_Packet(packet);
  149.        }
  150.  
  151.        r->r[3] = SWI_OK;
  152. }
  153.