home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
internet
/
netlite
/
DCI
/
c
/
TRANSMIT
< prev
Wrap
Text File
|
1993-04-27
|
3KB
|
153 lines
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "global.h"
void Transmit_Upcall(_kernel_swi_regs *r)
{
struct packet *packet;
r = r;
packet = tx_first;
if ((tx_first = tx_first->next) == NULLPACKET)
tx_last = NULLPACKET;
free_tx_mbuf(packet->data);
free_packet(packet);
tx = FALSE;
}
void Transmit_Packet(void)
{
_kernel_swi_regs rin, rout;
struct packet *packet;
int portno, type;
tx = TRUE;
packet = tx_first;
portno = packet->port;
type = packet->type;
if (port[portno].status != STATUS_UP)
{
if ((tx_first = tx_first->next) == NULLPACKET)
tx_last = NULLPACKET;
free_tx_mbuf(packet->data);
free_packet(packet);
tx = FALSE;
}
else
{
if (type == FRAME_IP) port[portno].iptx++;
rin.r[1] = portno;
rin.r[2] = type;
rin.r[3] = (int)packet->hwaddr;
rin.r[4] = (int)packet->data;
rin.r[5] = EVENT_TX;
_kernel_swi(XOS_Bit | (swibase + SWI_NetworkIfSend), &rin, &rout);
}
}
void Queue_Transmit_Packet(struct packet *packet)
{
int state;
if (packet == NULLPACKET) return;
state = ensure_irqs_off();
if (tx_first == NULLPACKET)
{
tx_first = packet;
tx_last = packet;
}
else
{
tx_last->next = packet;
tx_last = packet;
}
restore_irqs(state);
}
void Write_Port(_kernel_swi_regs *r)
{
int ipaddr = r->r[3];
int portno = r->r[0];
int length = r->r[2];
char *data = (char *)r->r[1];
struct packet *packet;
struct mbuf *mbuf;
char *hwaddr;
if (portno < 0 || portno >= nounits)
{
r->r[3] = SWI_INVPORT;
return;
}
if (port[portno].status != STATUS_UP)
{
r->r[3] = SWI_OPEN;
return;
}
if (length > 1500)
{
r->r[3] = SWI_TOOBIG;
return;
}
if (len_q(tx_first) > MAX_Q_LEN)
{
txqfull++;
r->r[3] = SWI_NOMEM;
return;
}
if ((mbuf = qdata(length, data)) == NULLMBUF)
{
memout++;
r->r[3] = SWI_NOMEM;
return;
}
if ((packet = alloc_packet()) == NULLPACKET)
{
memout++;
free_tx_mbuf(mbuf);
r->r[3] = SWI_NOMEM;
return;
}
packet->next = NULLPACKET;
packet->port = portno;
packet->type = FRAME_IP;
packet->data = mbuf;
if ((hwaddr = Search_ARP_Cache(portno, ipaddr)) == NULL)
{
Create_ARP_Request(ipaddr, packet);
}
else
{
packet->hwaddr[0] = hwaddr[0];
packet->hwaddr[1] = hwaddr[1];
packet->hwaddr[2] = hwaddr[2];
packet->hwaddr[3] = hwaddr[3];
packet->hwaddr[4] = hwaddr[4];
packet->hwaddr[5] = hwaddr[5];
Queue_Transmit_Packet(packet);
}
r->r[3] = SWI_OK;
}