home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include "kernel.h"
- #include "global.h"
-
- void Receive_Upcall(_kernel_swi_regs *r)
- {
- struct mbuf *rxdata = (struct mbuf *)r->r[1];
- register int portno = r->r[3];
- int type = r->r[4];
- char *hwaddr;
- int bcast;
-
- if (port[portno].status != STATUS_UP || type == 0)
- {
- free_rx_mbuf(rxdata);
- return;
- }
-
- hwaddr = rxdata->m_dat + rxdata->m_off - MMINOFF + 4;
-
- bcast = (hwaddr[0] == bcast_hwaddr[0] &&
- hwaddr[1] == bcast_hwaddr[1] &&
- hwaddr[2] == bcast_hwaddr[2] &&
- hwaddr[3] == bcast_hwaddr[3] &&
- hwaddr[4] == bcast_hwaddr[4] &&
- hwaddr[5] == bcast_hwaddr[5]);
-
- switch (type)
- {
- case FRAME_IP:
- Receive_IP(bcast, portno, rxdata);
- break;
- case FRAME_ARP:
- Receive_ARP(bcast, portno, rxdata);
- break;
- default:
- free_rx_mbuf(rxdata);
- break;
- }
- }
-
- void Read_Port(_kernel_swi_regs *r)
- {
- char *data = (char *)r->r[1];
- int size = r->r[2];
- int portno = r->r[0];
- struct packet *packet;
-
- if (portno < 0 || portno >= nounits)
- {
- r->r[4] = SWI_INVPORT;
- return;
- }
-
- if (port[portno].status != STATUS_UP)
- {
- r->r[4] = SWI_CLOSED;
- return;
- }
-
- r->r[2] = 0;
- r->r[3] = 0;
- r->r[4] = SWI_OK;
-
- packet = port[portno].rx_first;
-
- if (packet != NULLPACKET)
- {
- if (size < len_mbuf(packet->data->m_next))
- {
- r->r[4] = SWI_TOOSMALL;
- return;
- }
-
- r->r[2] = dqdata(packet->data, size, data);
- r->r[3] = packet->type;
-
- port[portno].rx_first = packet->next;
- if (port[portno].rx_first == NULLPACKET)
- port[portno].rx_last = NULLPACKET;
-
- free_rx_mbuf(packet->data);
- free_packet(packet);
- }
- }
-
- void Receive_IP(int bcast, int portno, struct mbuf *mbuf)
- {
- struct packet *packet;
-
- port[portno].iprx++;
-
- if (len_q(port[portno].rx_first) > MAX_Q_LEN)
- {
- rxqfull++;
- free_rx_mbuf(mbuf);
- return;
- }
-
- if ((packet = alloc_packet()) == NULLPACKET)
- {
- memout++;
- free_rx_mbuf(mbuf);
- return;
- }
-
- packet->next = NULLPACKET;
- packet->port = portno;
- packet->type = bcast;
- packet->data = mbuf;
-
- if (port[portno].rx_first == NULLPACKET)
- {
- port[portno].rx_first = packet;
- port[portno].rx_last = packet;
- }
- else
- {
- port[portno].rx_last->next = packet;
- port[portno].rx_last = packet;
- }
- }
-
-