home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / internet / netlite2 / DCI / c / RECEIVE < prev    next >
Encoding:
Text File  |  1993-04-27  |  3.0 KB  |  124 lines

  1. #include <stdlib.h>
  2. #include "kernel.h"
  3. #include "global.h"
  4.  
  5. void Receive_Upcall(_kernel_swi_regs *r)
  6. {
  7.        struct mbuf *rxdata = (struct mbuf *)r->r[1];
  8.        register int portno = r->r[3];
  9.        int type = r->r[4];
  10.        char *hwaddr;
  11.        int bcast;
  12.  
  13.        if (port[portno].status != STATUS_UP || type == 0)
  14.        {
  15.               free_rx_mbuf(rxdata);
  16.               return;
  17.        }
  18.  
  19.        hwaddr = rxdata->m_dat + rxdata->m_off - MMINOFF + 4;
  20.  
  21.        bcast = (hwaddr[0] == bcast_hwaddr[0] &&
  22.                 hwaddr[1] == bcast_hwaddr[1] &&
  23.                 hwaddr[2] == bcast_hwaddr[2] &&
  24.                 hwaddr[3] == bcast_hwaddr[3] &&
  25.                 hwaddr[4] == bcast_hwaddr[4] &&
  26.                 hwaddr[5] == bcast_hwaddr[5]);
  27.  
  28.        switch (type)
  29.        {
  30.                case FRAME_IP:
  31.                       Receive_IP(bcast, portno, rxdata);
  32.                       break;
  33.                case FRAME_ARP:
  34.                       Receive_ARP(bcast, portno, rxdata);
  35.                       break;
  36.                default:
  37.                       free_rx_mbuf(rxdata);
  38.                       break;
  39.        }
  40. }
  41.  
  42. void Read_Port(_kernel_swi_regs *r)
  43. {
  44.        char *data = (char *)r->r[1];
  45.        int size   = r->r[2];
  46.        int portno = r->r[0];
  47.        struct packet *packet;
  48.  
  49.        if (portno < 0 || portno >= nounits)
  50.        {
  51.               r->r[4] = SWI_INVPORT;
  52.               return;
  53.        }
  54.  
  55.        if (port[portno].status != STATUS_UP)
  56.        {
  57.               r->r[4] = SWI_CLOSED;
  58.               return;
  59.        }
  60.  
  61.        r->r[2] = 0;
  62.        r->r[3] = 0;
  63.        r->r[4] = SWI_OK;
  64.  
  65.        packet = port[portno].rx_first;
  66.  
  67.        if (packet != NULLPACKET)
  68.        {
  69.                if (size < len_mbuf(packet->data->m_next))
  70.                {
  71.                        r->r[4] = SWI_TOOSMALL;
  72.                        return;
  73.                }
  74.  
  75.                r->r[2] = dqdata(packet->data, size, data);
  76.                r->r[3] = packet->type;
  77.  
  78.                port[portno].rx_first = packet->next;
  79.                if (port[portno].rx_first == NULLPACKET)
  80.                       port[portno].rx_last = NULLPACKET;
  81.  
  82.                free_rx_mbuf(packet->data);
  83.                free_packet(packet);
  84.        }
  85. }
  86.  
  87. void Receive_IP(int bcast, int portno, struct mbuf *mbuf)
  88. {
  89.        struct packet *packet;
  90.  
  91.        port[portno].iprx++;
  92.  
  93.        if (len_q(port[portno].rx_first) > MAX_Q_LEN)
  94.        {
  95.               rxqfull++;
  96.               free_rx_mbuf(mbuf);
  97.               return;
  98.        }
  99.  
  100.        if ((packet = alloc_packet()) == NULLPACKET)
  101.        {
  102.               memout++;
  103.               free_rx_mbuf(mbuf);
  104.               return;
  105.        }
  106.  
  107.        packet->next = NULLPACKET;
  108.        packet->port = portno;
  109.        packet->type = bcast;
  110.        packet->data = mbuf;
  111.  
  112.        if (port[portno].rx_first == NULLPACKET)
  113.        {
  114.               port[portno].rx_first = packet;
  115.               port[portno].rx_last  = packet;
  116.        }
  117.        else
  118.        {
  119.               port[portno].rx_last->next = packet;
  120.               port[portno].rx_last       = packet;
  121.        }
  122. }
  123.  
  124.