/shark/trunk/drivers/newnet/netbuff.h |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: netbuff.h,v 1.1 2004-04-23 14:30:34 mauro Exp $ |
CVS : $Id: netbuff.h,v 1.2 2004-04-23 18:13:52 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:34 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:52 $ |
------------ |
**/ |
61,11 → 61,11 |
__BEGIN_DECLS |
typedef struct netbuff{ |
BYTE *b; |
BYTE **pb; |
BYTE *free; |
BYTE nbuffs; |
sem_t buffersem; |
BYTE *b; |
BYTE **pb; |
BYTE *free; |
BYTE nbuffs; |
sem_t buffersem; |
} NETBUFF; |
void netbuff_init(struct netbuff *netb, BYTE nbuffs, WORD buffdim); |
/shark/trunk/drivers/newnet/8390.c |
---|
98,8 → 98,9 |
#define ei_get_8390_hdr (ei_local->get_8390_hdr) |
/* use 0 for production, 1 for verification, >2 for debug */ |
//#define VERBOSE_ERROR_DUMP |
#ifndef ei_debug |
int ei_debug = 1; |
int ei_debug = 0; |
#endif |
/* Index to functions. */ |
1058,7 → 1059,8 |
{ |
outb_p(dev->dev_addr[i], e8390_base + EN1_PHYS_SHIFT(i)); |
if(inb_p(e8390_base + EN1_PHYS_SHIFT(i))!=dev->dev_addr[i]) |
printk(KERN_ERR "Hw. address read/write mismap %d\n",i); |
if (ei_debug > 0) |
printk(KERN_ERR "Hw. address read/write mismap %d\n",i); |
} |
outb_p(ei_local->rx_start_page, e8390_base + EN1_CURPAG); |
/shark/trunk/drivers/newnet/3c509.c |
---|
70,10 → 70,11 |
#include <asm/io.h> |
#include <asm/irq.h> |
//#define EL3_DEBUG debug |
#ifdef EL3_DEBUG |
int el3_debug = EL3_DEBUG; |
#else |
int el3_debug = 2; |
int el3_debug = 0; |
#endif |
/* To minimize the size of the driver source I only define operating |
/shark/trunk/drivers/newnet/net_init.c |
---|
190,7 → 190,7 |
} |
else if (dev != ethdev_index[i]) { |
/* Really shouldn't happen! */ |
printk("ether_setup: Ouch! Someone else took %s\n", |
printk(KERN_ERR "ether_setup: Ouch! Someone else took %s\n", |
dev->name); |
} |
} |
320,7 → 320,7 |
for (i = 0; i < MAX_ETH_CARDS; ++i) |
if (ethdev_index[i] == NULL) { |
sprintf(dev->name, "eth%d", i); |
printk("loading device '%s'...\n", dev->name); |
printk(KERN_INFO "Loading device '%s'...\n", dev->name); |
ethdev_index[i] = dev; |
break; |
} |
/shark/trunk/drivers/newnet/3c59x.c |
---|
107,7 → 107,7 |
static int max_interrupt_work = 20; |
/* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */ |
#define vortex_debug debug |
//#define vortex_debug debug |
#ifdef VORTEX_DEBUG |
static int vortex_debug = VORTEX_DEBUG; |
#else |
/shark/trunk/drivers/newnet/eth.c |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: eth.c,v 1.1 2004-04-23 14:30:32 mauro Exp $ |
CVS : $Id: eth.c,v 1.2 2004-04-23 18:13:51 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:32 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:51 $ |
------------ |
**/ |
74,7 → 74,7 |
/*#include "lowlev.h" |
//#include "3com.h" */ |
#define DEBUG_ETH |
//#define DEBUG_ETH |
#define ETH_PAGE 5 |
128,12 → 128,9 |
kern_raise(ETH_NULLPROTOCOL_EXC,NIL); |
} |
void dev_tint(struct device *dev) |
{ |
printk(KERN_WARNING "Warning!!!! dev_tint called!!! (Why?)\n"); |
printk(KERN_WARNING "Warning! dev_tint called. (Why?)\n"); |
sys_abort(201); |
} |
145,7 → 142,7 |
void netif_rx(struct sk_buff *skb) |
{ |
//cprintf("DENTRO netif_rx, skbuf=%p\n",skb->data); |
// cprintf("DENTRO netif_rx, skbuf=%p\n",skb->data); |
if (nettask_pid == NIL) { |
printk(KERN_CRIT "Net receives packets, but the driver doesn't exist.\n"); |
sys_abort(300); |
152,7 → 149,7 |
} |
port_send(NetRxPort,skb,NON_BLOCK); |
/* task_activate(nettask_pid);*/ |
// task_activate(nettask_pid); |
} |
TASK net_extern_driver(void) |
190,7 → 187,7 |
/* debug... */ |
netlev = 20; |
//cprintf("ETH: releasing %p\n", pkt); |
// cprintf("ETH: releasing %p\n", pkt); |
// NOTE changed by PJ because skb.data not always point to the |
// buffer start!!!... it is skb.head that always points there! |
243,7 → 240,7 |
len -= offset; |
for (i = 0; i < len; i += 10) { |
for (j = 0; j < 10; j++) |
cprintf("%2.2x ",pkt[offset+i+j]); |
cprintf("%2.2x ", pkt[offset+i+j]); |
for (j = 0; j < 10; j++) |
cputc(pkt[offset+i+j]); |
cprintf("\n"); |
253,7 → 250,7 |
void eth_copy_and_sum(struct sk_buff *dest, unsigned char *src, int length, int base) |
{ |
memcpy(dest->data,src,length); |
memcpy(dest->data, src, length); |
} |
#if 0 |
361,7 → 358,7 |
printk(KERN_ERR "NET PANIC --> Etherlink not found.\n"); |
return 0; |
case ETH_RXERROR : |
printk(KERN_ERR "Receive error (vero dramma!!!).\n"); |
printk(KERN_ERR "Receive error.\n"); |
return 0; |
case ETH_TXERROR : |
printk(KERN_ERR "Transimit error: N. Max Retry.\n"); |
373,7 → 370,7 |
printk(KERN_ERR "Buffers full: frame lost!\n"); |
return 1; |
case ETH_NULLPROTOCOL_EXC: |
printk(KERN_ERR "Null protocol called!!!\n"); |
printk(KERN_ERR "Null protocol called!\n"); |
for (p = 0; p < ETH_MAX_PROTOCOLS; p++) { |
printk(KERN_ERR "%d: %d\n", p, eth_table[p].type); |
} |
452,7 → 449,7 |
#if 0 |
ndev = pci_scan_bus(pci_devs); |
#ifdef __ETH_DBG__ |
pci_show(pci_devs, ndev); |
pci_show(pci_devs, ndev); |
#endif |
for (i = 0; i < ndev; i++) { |
r = (struct pci_regs *) pci_devs[i].mem; |
484,7 → 481,7 |
if ((cardtype == NONE) || (cardtype == UNKNOWN)) { |
exc_raise(ETH_DRIVER_NOT_FOUND); |
} |
/*PUT HERE THE PFUN INIT!!!*/ |
/*PUT HERE THE PFUN INIT!!!*/ |
if (cardtype == VORTEX) { |
} |
/* |
525,7 → 522,7 |
printk(KERN_INFO "Network card found.\n"); |
} else { |
printk(KERN_INFO "No network card found.\n"); |
/* cprintf("No card found... Installing loopback device\n"); |
/* cprintf("No network card found. Installing loopback device.\n"); |
loopback_init(&device0); |
device0.open(&device0);*/ |
return 0; |
532,8 → 529,8 |
} |
#endif |
// netbuff_init(&rxbuff, ETH_RX_BUFFERS, ETH_MAX_LEN); |
// netbuff_init(&txbuff, ETH_TX_BUFFERS, ETH_MAX_LEN); |
//netbuff_init(&rxbuff, ETH_RX_BUFFERS, ETH_MAX_LEN); |
//netbuff_init(&txbuff, ETH_TX_BUFFERS, ETH_MAX_LEN); |
definedprotocols = 0; |
for (i = 0; i < ETH_MAX_PROTOCOLS; i++) { |
/shark/trunk/drivers/newnet/skbuff.c |
---|
65,50 → 65,49 |
struct sk_buff *skb_realloc_headroom(struct sk_buff *skb, int newheadroom) |
{ |
struct sk_buff *n; |
unsigned long offset; |
int headroom = skb_headroom(skb); |
struct sk_buff *n; |
unsigned long offset; |
int headroom = skb_headroom(skb); |
/* |
* Allocate the copy buffer |
*/ |
/* Allocate the copy buffer */ |
n=alloc_skb(skb->truesize+newheadroom-headroom, GFP_ATOMIC); |
if(n==NULL) |
return NULL; |
n = alloc_skb(skb->truesize + newheadroom-headroom, GFP_ATOMIC); |
if (n == NULL) |
return NULL; |
skb_reserve(n,newheadroom); |
skb_reserve(n, newheadroom); |
/* |
* Shift between the two data areas in bytes |
*/ |
/* |
* Shift between the two data areas in bytes |
*/ |
offset=n->data-skb->data; |
offset = n->data - skb->data; |
/* Set the tail pointer and length */ |
skb_put(n,skb->len); |
/* Copy the bytes */ |
memcpy(n->data,skb->data,skb->len); |
n->list=NULL; |
// n->sk=NULL; |
// n->priority=skb->priority; |
n->protocol=skb->protocol; |
n->dev=skb->dev; |
// n->dst=dst_clone(skb->dst); |
// n->h.raw=skb->h.raw+offset; |
// n->nh.raw=skb->nh.raw+offset; |
// n->mac.raw=skb->mac.raw+offset; |
memcpy(n->cb, skb->cb, sizeof(skb->cb)); |
n->used=skb->used; |
// n->is_clone=0; |
// atomic_set(&n->users, 1); |
// n->pkt_type=skb->pkt_type; |
// n->stamp=skb->stamp; |
// n->destructor = NULL; |
// n->security=skb->security; |
/* Set the tail pointer and length */ |
skb_put(n, skb->len); |
/* Copy the bytes */ |
memcpy(n->data, skb->data, skb->len); |
n->list = NULL; |
// n->sk = NULL; |
// n->priority = skb->priority; |
n->protocol = skb->protocol; |
n->dev = skb->dev; |
// n->dst = dst_clone(skb->dst); |
// n->h.raw = skb->h.raw+offset; |
// n->nh.raw = skb->nh.raw+offset; |
// n->mac.raw = skb->mac.raw+offset; |
memcpy(n->cb, skb->cb, sizeof(skb->cb)); |
n->used = skb->used; |
// n->is_clone = 0; |
// atomic_set(&n->users, 1); |
// n->pkt_type = skb->pkt_type; |
// n->stamp = skb->stamp; |
// n->destructor = NULL; |
// n->security = skb->security; |
#ifdef CONFIG_IP_FIREWALL |
n->fwmark = skb->fwmark; |
n->fwmark = skb->fwmark; |
#endif |
return n; |
return n; |
} |
/shark/trunk/drivers/newnet/udpip.c |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: udpip.c,v 1.1 2004-04-23 14:30:35 mauro Exp $ |
CVS : $Id: udpip.c,v 1.2 2004-04-23 18:13:53 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:35 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:53 $ |
------------ |
**/ |
67,6 → 67,11 |
#include <drivers/udpip.h> |
#include "arp.h" |
//#define __UDP_DBG__ |
//#define __IP_DBG__ |
#define UDP_INFO "[UDP] " |
#define IP_INFO "[IP] " |
/* |
UDP-buffers number and dimension (UDP-buffers are provided by NetBuff |
module |
99,461 → 104,465 |
/* TRUE if the IP addresses ip1 and ip2 are equal, FALSE otherwise */ |
int ip_compAddr(IP_ADDR ip1, IP_ADDR ip2) |
{ |
int i; |
int i; |
for (i=0; i < 4; i++) |
if (ip1.ad[i] != ip2.ad[i]) return FALSE; |
return TRUE; |
for (i=0; i < 4; i++) |
if (ip1.ad[i] != ip2.ad[i]) return FALSE; |
return TRUE; |
} |
/* traslate an IP address from text string to 4 bytes */ |
int ip_str2addr(char *a, IP_ADDR *ip) |
{ |
int ad[6]; |
int i,j; |
char c; |
int ad[6]; |
int i,j; |
char c; |
i = 0; |
for(j = 0; j < 4; j++) { |
ad[j] = 0; |
while((a[i] != '.') && (a[i] != 0)) { |
c = a[i++]; |
if (c <= '9') c = c - '0'; |
else c = c - 'A' + 10; |
ad[j] = ad[j] * 10 + c; |
i = 0; |
for(j = 0; j < 4; j++) { |
ad[j] = 0; |
while((a[i] != '.') && (a[i] != 0)) { |
c = a[i++]; |
if (c <= '9') c = c - '0'; |
else c = c - 'A' + 10; |
ad[j] = ad[j] * 10 + c; |
} |
i++; |
} |
i++; |
} |
for (i=0; i<4; i++) ip->ad[i] = ad[i]; |
return 1; |
for (i=0; i<4; i++) |
ip->ad[i] = ad[i]; |
return 1; |
} |
/* give the body of an IP packet */ |
void *ip_getFDB(void *pkt) |
{ |
return((void *)(((BYTE *)eth_getFDB(pkt)) + sizeof(IP_HEADER))); |
return((void *)(((BYTE *)eth_getFDB(pkt)) + sizeof(IP_HEADER))); |
} |
/* received IP packet CallBack */ |
void ip_server_recv(void *pkt) |
{ |
IP_HEADER *iphd; |
WORD *ptcheck; |
WORD checksum,oldChk; |
int hlen,i; |
int done; |
char dummystr[50]; |
BYTE flag; |
IP_HEADER *iphd; |
WORD *ptcheck; |
WORD checksum,oldChk; |
int hlen,i; |
int done; |
char dummystr[50]; |
BYTE flag; |
UDP_HEADER *udphd; |
struct pseudo_hd ph; |
WORD sum, old; |
WORD *p; |
UDP_MSG usermsg; |
void *b, *s; |
UDP_HEADER *udphd; |
struct pseudo_hd ph; |
WORD sum, old; |
WORD *p; |
UDP_MSG usermsg; |
void *b, *s; |
/* debug...*/ |
netlev = 2; |
/* debug...*/ |
netlev = 2; |
sprintf(dummystr, "Packet arrived!\n"); |
iphd = (IP_HEADER *)eth_getFDB(pkt); |
/* compute the checksum */ |
ptcheck = (WORD *)iphd; |
sprintf(dummystr, "Packet arrived!\n"); |
iphd = (IP_HEADER *)eth_getFDB(pkt); |
/* compute the checksum */ |
ptcheck = (WORD *)iphd; |
#ifdef __IP_DBG__ |
ip_print_header(iphd); |
//!!!ip_print_header(iphd); |
#endif |
hlen = getHlen(iphd->vers_hlen) * 2; |
checksum = oldChk = *ptcheck; |
ptcheck++; |
for (i=1; i<hlen; i++) { |
checksum += *ptcheck; |
if (checksum < oldChk) checksum ++; |
oldChk = checksum; |
hlen = getHlen(iphd->vers_hlen) * 2; |
checksum = oldChk = *ptcheck; |
ptcheck++; |
} |
if (checksum != 0xffff) { |
/* wrong ChkSum */ |
for (i=1; i<hlen; i++) { |
checksum += *ptcheck; |
if (checksum < oldChk) checksum ++; |
oldChk = checksum; |
ptcheck++; |
} |
if (checksum != 0xffff) { |
/* wrong ChkSum */ |
#ifdef __IP_DBG__ |
sprintf(msg, "Wrong checksum! %x\n",checksum); |
win_puts(&wip,msg); |
printk(KERN_DEBUG IP_INFO "Wrong checksum: %x.\n", checksum); |
#endif |
} else if (!ip_compAddr(iphd->dest,myIpAddr)) { |
} else if (!ip_compAddr(iphd->dest,myIpAddr)) { |
#ifdef __IP_DBG__ |
win_puts(&wip,"Packet not addressed to this host!\n"); |
printk(KERN_DEBUG IP_INFO "Packet not addressed to this host.\n"); |
#endif |
} else if (getFlags(ntohs(iphd->flags_frOffset)) & 0x01) { |
} else if (getFlags(ntohs(iphd->flags_frOffset)) & 0x01) { |
#ifdef __IP_DBG__ |
/* fragment? */ |
win_puts(&wip,"Gotta a fragment!\n"); |
/* fragment? */ |
printk(KERN_DEBUG IP_INFO "Gotta a fragment!\n"); |
#endif |
} else if (getFrOffset(ntohs(iphd->flags_frOffset)) != 0) { |
} else if (getFrOffset(ntohs(iphd->flags_frOffset)) != 0) { |
#ifdef __IP_DBG__ |
win_puts(&wip,"Gotta a fragment again!\n"); |
printk(KERN_DEBUG IP_INFO "Gotta a fragment again!\n"); |
#endif |
} else { |
/* OK: the packet is good... */ |
if (iphd->protocol != IP_UDP_TYPE) { |
/* It isn't an UDP packet */ |
done = FALSE; |
i = 0; |
while ((i < IP_MAX_ENTRIES) && !done) { |
if (ipTable[i].protocol == iphd->protocol) done = TRUE; |
else i++; |
} |
if (!done) { |
} else { |
/* OK: the packet is good... */ |
if (iphd->protocol != IP_UDP_TYPE) { |
/* It isn't an UDP packet */ |
done = FALSE; |
i = 0; |
while ((i < IP_MAX_ENTRIES) && !done) { |
if (ipTable[i].protocol == iphd->protocol) done = TRUE; |
else i++; |
} |
if (!done) { |
#ifdef __IP_DBG__ |
/* Unknown transport protocol */ |
win_puts(&wip,"Wrong protocol\n"); |
/* Unknown transport protocol */ |
printk(KERN_DEBUG IP_INFO "Wrong protocol.\n"); |
#endif |
} else { |
/* Call the correct transport protocol CallBack */ |
ipTable[i].rfun((void *)((BYTE *)iphd + 4*getHlen(iphd->vers_hlen))); |
} |
} else { |
/* UDP packet */ |
netlev = 4; |
udphd = (UDP_HEADER *)(void *)((BYTE *)iphd + 4*getHlen(iphd->vers_hlen)); |
/* compute the UDP checksum */ |
for (i = 0; i < 4; i++) { |
ph.source.ad[i] = iphd->source.ad[i]; |
ph.dest.ad[i] = iphd->dest.ad[i]; |
} |
ph.zero = 0; |
ph.protocoll = IP_UDP_TYPE; |
ph.len = udphd->mlen; |
sum = 0; |
old = 0; |
p = (WORD *)&ph; |
for (i = 0; i < (sizeof(ph) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum ++; |
old = sum; |
} |
} else { |
/* Call the correct transport protocol CallBack */ |
ipTable[i].rfun((void *)((BYTE *)iphd + 4*getHlen(iphd->vers_hlen))); |
} |
} else { |
/* UDP packet */ |
netlev = 4; |
udphd = (UDP_HEADER *)(void *)((BYTE *)iphd + 4*getHlen(iphd->vers_hlen)); |
/* compute the UDP checksum */ |
for (i = 0; i < 4; i++) { |
ph.source.ad[i] = iphd->source.ad[i]; |
ph.dest.ad[i] = iphd->dest.ad[i]; |
} |
ph.zero = 0; |
ph.protocoll = IP_UDP_TYPE; |
ph.len = udphd->mlen; |
sum = 0; |
old = 0; |
p = (WORD *)&ph; |
for (i = 0; i < (sizeof(ph) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum ++; |
old = sum; |
} |
#ifdef __UDP_DBG__ |
sprintf(str,"half sum: %x\n",sum); |
win_puts(&dbg,str); |
printk(KERN_DEBUG UDP_INFO "Half sum: %x\n",sum); |
#endif |
p = (WORD *)udphd; |
((BYTE *)udphd)[ntohs(udphd->mlen)] = 0; |
for (i = 0; i < ((ntohs(udphd->mlen) + 1) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum ++; |
old = sum; |
} |
p = (WORD *)udphd; |
((BYTE *)udphd)[ntohs(udphd->mlen)] = 0; |
for (i = 0; i < ((ntohs(udphd->mlen) + 1) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum ++; |
old = sum; |
} |
#ifdef __UDP_DBG__ |
win_puts(&dbg,"UDP packet received!!!\n"); |
sprintf(str,"s_port: %x\n",udphd->s_port); |
win_puts(&dbg,str); |
sprintf(str,"d_port: %x\n",udphd->d_port); |
win_puts(&dbg,str); |
sprintf(str,"m_len: %x %d\n",udphd->mlen, ntohs(udphd->mlen)); |
win_puts(&dbg,str); |
sprintf(str,"checksum: %x\n",udphd->checksum); |
win_puts(&dbg,str); |
sprintf(str,"mysum: %x \n", sum); |
win_puts(&dbg,str); |
printk(KERN_DEBUG UDP_INFO "Packet received.\n"); |
printk(KERN_DEBUG UDP_INFO "s_port: %x\n",udphd->s_port); |
printk(KERN_DEBUG UDP_INFO "d_port: %x\n",udphd->d_port); |
printk(KERN_DEBUG UDP_INFO "m_len: %x %d\n",udphd->mlen, ntohs(udphd->mlen)); |
printk(KERN_DEBUG UDP_INFO "checksum: %x\n",udphd->checksum); |
printk(KERN_DEBUG UDP_INFO "mysum: %x \n", sum); |
#endif |
if(sum != 0xFFFF) { |
/* Wrong UDP ChkSum */ |
cprintf("Error %x!!!!\n",sum); |
kern_raise(XUDP_BADCHK_EXC,exec_shadow); |
} else { |
done = FALSE; |
i = 0; |
/* searching for the destination socket...*/ |
while((i < UDP_MAX_HANDLES) && !done) { |
if ((udpTable[i].valid == TRUE) && |
(udpTable[i].port == ntohs(udphd->d_port))) |
done = TRUE; |
else i++; |
} |
if (done) { |
/*...found! */ |
s = (void *)(((BYTE *)udphd) + sizeof(UDP_HEADER)); |
if (udpTable[i].notify == TRUE) { |
/* notify function associated to the socket: call it */ |
udpTable[i].notify_fun(ntohs(udphd->mlen) - sizeof(UDP_HEADER), |
s, udpTable[i].notify_par); |
} else { |
/* otherwise, send the packet to the correct port */ |
if((b = netbuff_get(&udp_rxbuff, NON_BLOCK)) != 0) { |
memcpy(b,s,ntohs(udphd->mlen) - sizeof(UDP_HEADER) + 1); |
setIpAddr(usermsg.addr.s_addr, iphd->source); |
usermsg.addr.s_port = ntohs(udphd->s_port); |
usermsg.mlen = ntohs(udphd->mlen) - sizeof(UDP_HEADER); |
usermsg.buff = b; |
flag = port_send(udpTable[i].hport,&usermsg,NON_BLOCK); |
if (!flag) { |
netbuff_release(&udp_rxbuff, b); |
if(sum != 0xFFFF) { |
/* Wrong UDP ChkSum */ |
cprintf("Error %x!\n", sum); |
kern_raise(XUDP_BADCHK_EXC,exec_shadow); |
} else { |
done = FALSE; |
i = 0; |
/* searching for the destination socket...*/ |
while((i < UDP_MAX_HANDLES) && !done) { |
if ((udpTable[i].valid == TRUE) && (udpTable[i].port == ntohs(udphd->d_port))) |
done = TRUE; |
else i++; |
} |
if (done) { |
/*...found! */ |
s = (void *)(((BYTE *)udphd) + sizeof(UDP_HEADER)); |
if (udpTable[i].notify == TRUE) { |
/* notify function associated to the socket: call it */ |
udpTable[i].notify_fun(ntohs(udphd->mlen) - sizeof(UDP_HEADER), |
s, udpTable[i].notify_par); |
} else { |
/* otherwise, send the packet to the correct port */ |
if((b = netbuff_get(&udp_rxbuff, NON_BLOCK)) != 0) { |
memcpy(b,s,ntohs(udphd->mlen) - sizeof(UDP_HEADER) + 1); |
setIpAddr(usermsg.addr.s_addr, iphd->source); |
usermsg.addr.s_port = ntohs(udphd->s_port); |
usermsg.mlen = ntohs(udphd->mlen) - sizeof(UDP_HEADER); |
usermsg.buff = b; |
flag = port_send(udpTable[i].hport,&usermsg,NON_BLOCK); |
if (!flag) { |
netbuff_release(&udp_rxbuff, b); |
#ifdef __UDP_DBG__ |
win_puts(&dbg,"Port is filled up "); |
printk(KERN_DEBUG "Port is filled up.\n"); |
#endif |
} |
} |
} |
} else { |
} |
} |
} |
} else { |
#ifdef __UDP_DBG__ |
win_puts(&dbg,"Port not found "); |
printk(KERN_DEBUG UDP_INFO "Port not found.\n"); |
#endif |
} |
} |
} |
} |
} |
} |
} |
/* Send an IP packet */ |
void ip_send(IP_ADDR dest, void *pkt, WORD len) |
{ |
static WORD ip_ident = 0; |
IP_HEADER *iphd; |
WORD check = 0, oldCheck = 0; |
int i, done; |
WORD *pt; |
#ifdef __IP_DBG__ |
char msg[50]; |
#endif |
iphd = (IP_HEADER *)eth_getFDB(pkt); |
iphd->vers_hlen = (4 << 4) + 5; |
iphd->servType = 8; |
iphd->lenght = htons(len + sizeof(IP_HEADER)); |
iphd->ident = htons(ip_ident++); |
iphd->flags_frOffset = 0; |
iphd->ttl = 10; |
iphd->protocol = IP_UDP_TYPE; |
iphd->headChecksum = 0; |
iphd->source = myIpAddr; |
iphd->dest = dest; |
static WORD ip_ident = 0; |
IP_HEADER *iphd; |
WORD check = 0, oldCheck = 0; |
int i, done; |
WORD *pt; |
/* Compute the checksum */ |
pt = (WORD *)iphd; |
check = oldCheck = *pt; |
pt++; |
for (i = 1; i < 10; i++) { |
check += *pt; |
if (oldCheck > check) check++; |
oldCheck = check; |
iphd = (IP_HEADER *)eth_getFDB(pkt); |
iphd->vers_hlen = (4 << 4) + 5; |
iphd->servType = 8; |
iphd->lenght = htons(len + sizeof(IP_HEADER)); |
iphd->ident = htons(ip_ident++); |
iphd->flags_frOffset = 0; |
iphd->ttl = 10; |
iphd->protocol = IP_UDP_TYPE; |
iphd->headChecksum = 0; |
iphd->source = myIpAddr; |
iphd->dest = dest; |
/* Compute the checksum */ |
pt = (WORD *)iphd; |
check = oldCheck = *pt; |
pt++; |
} |
check = ~check; |
iphd->headChecksum = check; |
for (i = 1; i < 10; i++) { |
check += *pt; |
if (oldCheck > check) check++; |
oldCheck = check; |
pt++; |
} |
check = ~check; |
iphd->headChecksum = check; |
#ifdef __IP_DBG__ |
sprintf(msg,"serv type : %d\n",iphd->servType); |
win_puts(&wip,msg); |
printk(KERN_DEBUG IP_INFO "Serv type : %d\n", iphd->servType); |
#endif |
/* Is the destination IP address the broadcast address?*/ |
if (ip_compAddr(dest,IPbroadcastaddress)) { |
/* Send the packet*/ |
eth_setHeader(pkt,broadcast,ETH_IP_TYPE); |
eth_sendPkt(pkt,len + sizeof(IP_HEADER)); |
netbuff_release(&udp_txbuff, (void *)pkt); |
} else { |
/* Is the destination ethernet address in the ARP table? */ |
i = 0; done = 0; |
while (i < ARP_MAX_ENTRIES && !done) |
if (arpTable[i].valid == TRUE) { |
if (ip_compAddr(dest,arpTable[i].ip)) { |
done = TRUE; |
} else i++; |
} else i++; |
if (done == FALSE) { |
/* No: call ARP to get the ethernet address */ |
arp_send(pkt,dest,len + sizeof(IP_HEADER)); |
} else { |
/* Yes: directly send the packet */ |
eth_setHeader(pkt,arpTable[i].eth,ETH_IP_TYPE); |
eth_sendPkt(pkt,len + sizeof(IP_HEADER)); |
netbuff_release(&udp_txbuff, (void *)pkt); |
arpTable[i].used++; |
if (arpTable[i].used > ARP_MAX_USED) arpTable[i].used = ARP_MAX_USED; |
} |
} |
/* Is the destination IP address the broadcast address?*/ |
if (ip_compAddr(dest,IPbroadcastaddress)) { |
/* Send the packet*/ |
eth_setHeader(pkt,broadcast,ETH_IP_TYPE); |
eth_sendPkt(pkt,len + sizeof(IP_HEADER)); |
netbuff_release(&udp_txbuff, (void *)pkt); |
} else { |
/* Is the destination ethernet address in the ARP table? */ |
i = 0; done = 0; |
while (i < ARP_MAX_ENTRIES && !done) |
if (arpTable[i].valid == TRUE) { |
if (ip_compAddr(dest,arpTable[i].ip)) { |
done = TRUE; |
} else i++; |
} else i++; |
if (done == FALSE) { |
/* No: call ARP to get the ethernet address */ |
arp_send(pkt, dest, len + sizeof(IP_HEADER)); |
} else { |
/* Yes: directly send the packet */ |
eth_setHeader(pkt,arpTable[i].eth,ETH_IP_TYPE); |
eth_sendPkt(pkt, len + sizeof(IP_HEADER)); |
netbuff_release(&udp_txbuff, (void *)pkt); |
arpTable[i].used++; |
if (arpTable[i].used > ARP_MAX_USED) arpTable[i].used = ARP_MAX_USED; |
} |
} |
} |
/* let IP manage a new transport protocol */ |
int ip_setProtocol(BYTE proto, void (*recv)(void *m)) |
{ |
BYTE done, i; |
BYTE done, i; |
i = 0; done = 0; |
while (i < IP_MAX_ENTRIES && !done) |
if (ipTable[i].rfun == NULL) done = TRUE; |
else i++; |
if (!done) return FALSE; |
else { |
ipTable[i].protocol = proto; |
ipTable[i].rfun = recv; |
} |
return TRUE; |
i = 0; done = 0; |
while (i < IP_MAX_ENTRIES && !done) |
if (ipTable[i].rfun == NULL) done = TRUE; |
else i++; |
if (!done) |
return FALSE; |
else { |
ipTable[i].protocol = proto; |
ipTable[i].rfun = recv; |
} |
return TRUE; |
} |
//int ip_error(int code) |
//{ |
// cprintf("IP error\n"); |
/* cprintf("Code [%d]\nCause : %s",code,ip_error_msg[code-IP_ERROR_BASE]);*/ |
// return(0); |
//} |
/*int ip_error(int code) |
{ |
cprintf("IP error\n"); |
cprintf("Code [%d]\nCause : %s",code,ip_error_msg[code-IP_ERROR_BASE]); |
return(0); |
}*/ |
/* Initialize the IP layer: it also call the ARP initialization function, pass a struct ip_params* */ |
void ip_init(void *p) |
{ |
int i; |
int i; |
if (!ipIsInstalled) { |
arp_init(((struct ip_params*)p)->localAddr); |
//exc_set(IP_INIT_ERROR,ip_error); |
for (i=0; i < IP_MAX_ENTRIES; i++) ipTable[i].rfun = NULL; |
if (!ipIsInstalled) { |
arp_init(((struct ip_params*)p)->localAddr); |
//exc_set(IP_INIT_ERROR,ip_error); |
for (i=0; i < IP_MAX_ENTRIES; i++) |
ipTable[i].rfun = NULL; |
eth_setProtocol(ETH_IP_TYPE, ip_server_recv); |
ip_str2addr(((struct ip_params*)p)->broadcastAddr,&IPbroadcastaddress); |
ipIsInstalled = TRUE; |
eth_str2Addr("FF:FF:FF:FF:FF:FF",&broadcast); |
} else cprintf("IP: already installed!!!\n"); |
eth_setProtocol(ETH_IP_TYPE, ip_server_recv); |
ip_str2addr(((struct ip_params*)p)->broadcastAddr,&IPbroadcastaddress); |
ipIsInstalled = TRUE; |
eth_str2Addr("FF:FF:FF:FF:FF:FF",&broadcast); |
} else |
cprintf("IP: already installed.\n"); |
} |
/* Receive an UDP packet from a socket */ |
int udp_recvfrom(int s, void *buff, UDP_ADDR *from) |
{ |
UDP_MSG u; |
UDP_MSG u; |
port_receive(udpTable[s].pport,&u,BLOCK); |
memcpy(buff,u.buff,u.mlen); |
netbuff_release(&udp_rxbuff, u.buff); |
*from = u.addr; |
return (u.mlen); |
port_receive(udpTable[s].pport,&u,BLOCK); |
memcpy(buff,u.buff,u.mlen); |
netbuff_release(&udp_rxbuff, u.buff); |
*from = u.addr; |
return (u.mlen); |
} |
/* Associate a notify function to a socket */ |
int udp_notify(int s, int (*f)(int len, BYTE *buff, void *p), void *p) |
{ |
if (f == NULL) { |
udpTable[s].notify = FALSE; |
if (f == NULL) { |
udpTable[s].notify = FALSE; |
return 1; |
} |
if (udpTable[s].valid != TRUE) |
return -1; |
udpTable[s].notify = TRUE; |
udpTable[s].notify_fun = f; |
udpTable[s].notify_par = p; |
return 1; |
} |
if (udpTable[s].valid != TRUE) return -1; |
udpTable[s].notify = TRUE; |
udpTable[s].notify_fun = f; |
udpTable[s].notify_par = p; |
return 1; |
} |
/* Create a new socket binding it to a specified IP port */ |
int udp_bind(UDP_ADDR *local, IP_ADDR *bindlist) |
{ |
int i, j; |
BYTE done; |
char str[30]; |
int i, j; |
BYTE done; |
char str[30]; |
/* Search for a free entry in the socket table */ |
i = 0; done = FALSE; |
while ((i < UDP_MAX_HANDLES) && !done) { |
kern_cli(); |
if ((udpTable[i].valid == FALSE)){ |
done = TRUE; |
udpTable[i].valid = 2; |
} else i++; |
kern_sti(); |
} |
/* No free entries: bind fail! */ |
if (!done) return -1; |
/* Create a receive port for the socket */ |
udpTable[i].port = local->s_port; |
sprintf(str,"UDP%d",i); |
udpTable[i].hport = port_create(str,sizeof(UDP_MSG),4,STREAM,WRITE); |
udpTable[i].pport = port_connect(str,sizeof(UDP_MSG),STREAM,READ); |
udpTable[i].valid = TRUE; |
/* |
Request for the ethernet addresses associated to the IP addressed |
given in the bindlist |
*/ |
if (bindlist != NULL) { |
while (*(int*)bindlist != 0) { |
/* Ignore broadcast IP address */ |
if (!ip_compAddr(*bindlist,IPbroadcastaddress)) { |
j = arp_req(*bindlist); |
arp_sendRequest(j); |
} |
bindlist ++; |
/* Search for a free entry in the socket table */ |
i = 0; done = FALSE; |
while ((i < UDP_MAX_HANDLES) && !done) { |
kern_cli(); |
if ((udpTable[i].valid == FALSE)) { |
done = TRUE; |
udpTable[i].valid = 2; |
} else i++; |
kern_sti(); |
} |
} |
return i; |
/* No free entries: bind fail! */ |
if (!done) |
return -1; |
/* Create a receive port for the socket */ |
udpTable[i].port = local->s_port; |
sprintf(str,"UDP%d",i); |
udpTable[i].hport = port_create(str,sizeof(UDP_MSG),4,STREAM,WRITE); |
udpTable[i].pport = port_connect(str,sizeof(UDP_MSG),STREAM,READ); |
udpTable[i].valid = TRUE; |
/* |
* Request for the ethernet addresses associated to the IP addressed |
* given in the bindlist. |
*/ |
if (bindlist != NULL) { |
while (*(int*)bindlist != 0) { |
/* Ignore broadcast IP address */ |
if (!ip_compAddr(*bindlist,IPbroadcastaddress)) { |
j = arp_req(*bindlist); |
arp_sendRequest(j); |
} |
bindlist ++; |
} |
} |
return i; |
} |
/* Send an UDP packet */ |
int udp_sendto(int s, void *buff, int nbytes, UDP_ADDR *to) |
{ |
void *pkt; |
UDP_HEADER *udphd; |
char *msg; |
void *pkt; |
UDP_HEADER *udphd; |
char *msg; |
#ifdef __UDP_DBG__ |
static int num_pack = 0; |
char str[50]; |
static int num_pack = 0; |
#endif |
WORD sum, old; |
int i; |
struct pseudo_hd ph; |
WORD *p; |
IP_ADDR *source; |
pkt = netbuff_get(&udp_txbuff, BLOCK); |
udphd = (UDP_HEADER *)ip_getFDB(pkt); |
udphd->s_port = htons(udpTable[s].port); |
udphd->d_port = htons(to->s_port); |
udphd->mlen = htons((WORD)nbytes + sizeof(UDP_HEADER)); |
msg = (char *)(((BYTE *)udphd) + sizeof(UDP_HEADER)); |
if (nbytes > UDP_MAX_LEN) nbytes = UDP_MAX_LEN; |
memcpy(msg,buff,nbytes); |
WORD sum, old; |
int i; |
struct pseudo_hd ph; |
WORD *p; |
IP_ADDR *source; |
source = ip_getAddr(); |
/* Compute the CheckSum */ |
udphd->checksum = 0; |
for (i = 0; i < 4; i++) { |
ph.source.ad[i] = source->ad[i]; |
ph.dest.ad[i] = to->s_addr.ad[i]; |
} |
ph.zero = 0; |
ph.protocoll = 17; |
ph.len = udphd->mlen; |
sum = 0; old = 0; |
p = (WORD *)&ph; |
for (i = 0; i < (sizeof(ph) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum ++; |
old = sum; |
} |
p = (WORD *)udphd; |
((BYTE *)udphd)[ntohs(udphd->mlen)] = 0; |
for (i = 0; i < ((ntohs(udphd->mlen) + 1) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum++; |
old = sum; |
} |
udphd->checksum = ~sum; |
pkt = netbuff_get(&udp_txbuff, BLOCK); |
udphd = (UDP_HEADER *)ip_getFDB(pkt); |
udphd->s_port = htons(udpTable[s].port); |
udphd->d_port = htons(to->s_port); |
udphd->mlen = htons((WORD)nbytes + sizeof(UDP_HEADER)); |
msg = (char *)(((BYTE *)udphd) + sizeof(UDP_HEADER)); |
if (nbytes > UDP_MAX_LEN) nbytes = UDP_MAX_LEN; |
memcpy(msg,buff,nbytes); |
source = ip_getAddr(); |
/* Compute the CheckSum */ |
udphd->checksum = 0; |
for (i = 0; i < 4; i++) { |
ph.source.ad[i] = source->ad[i]; |
ph.dest.ad[i] = to->s_addr.ad[i]; |
} |
ph.zero = 0; |
ph.protocoll = 17; |
ph.len = udphd->mlen; |
sum = 0; old = 0; |
p = (WORD *)&ph; |
for (i = 0; i < (sizeof(ph) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum ++; |
old = sum; |
} |
p = (WORD *)udphd; |
((BYTE *)udphd)[ntohs(udphd->mlen)] = 0; |
for (i = 0; i < ((ntohs(udphd->mlen) + 1) >> 1); i++) { |
sum += p[i]; |
if (sum < old) sum++; |
old = sum; |
} |
udphd->checksum = ~sum; |
ip_send(to->s_addr, pkt, ((WORD)nbytes + sizeof(UDP_HEADER))); |
ip_send(to->s_addr, pkt, ((WORD)nbytes + sizeof(UDP_HEADER))); |
#ifdef __UDP_DBG__ |
sprintf(str,"Packet sent %d; ",num_pack++); |
win_puts(&dbg,str); |
printk(KERN_DEBUG UDP_INFO "Packets sent: %d.\n", num_pack++); |
#endif |
return nbytes; |
return nbytes; |
} |
void udp_init(void *dummy) |
{ |
int i; |
int i; |
if (!udpIsInstalled) { |
netbuff_init(&udp_rxbuff, UDP_RX_BUFFERS, UDP_MAX_LEN); |
netbuff_init(&udp_txbuff, UDP_TX_BUFFERS, ETH_MAX_LEN); |
if (!udpIsInstalled) { |
netbuff_init(&udp_rxbuff, UDP_RX_BUFFERS, UDP_MAX_LEN); |
netbuff_init(&udp_txbuff, UDP_TX_BUFFERS, ETH_MAX_LEN); |
for (i = 0; i < UDP_MAX_HANDLES; i++) { |
udpTable[i].valid = FALSE; |
udpTable[i].notify = FALSE; |
} |
udpIsInstalled = TRUE; |
} else cprintf("UDP: Already installed!!!\n"); |
for (i = 0; i < UDP_MAX_HANDLES; i++) { |
udpTable[i].valid = FALSE; |
udpTable[i].notify = FALSE; |
} |
udpIsInstalled = TRUE; |
} else |
printk(KERN_WARNING UDP_INFO ": Already installed.\n"); |
} |
/shark/trunk/drivers/newnet/arp.c |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: arp.c,v 1.1 2004-04-23 14:30:32 mauro Exp $ |
CVS : $Id: arp.c,v 1.2 2004-04-23 18:13:51 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:32 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:51 $ |
------------ |
**/ |
71,6 → 71,9 |
#include "arp.h" |
#include <signal.h> |
//#define __ARP_DBG__ |
#define ARP_INFO "[ARP] " |
#define FALSE 0 |
#define TRUE 1 |
#define PENDING 2 |
87,20 → 90,20 |
locally |
*/ |
typedef struct { |
int len; |
void *next; |
int len; |
void *next; |
} PKT_NXT; |
typedef struct arp_pkt{ |
WORD htype; |
WORD ptype; |
BYTE hlen; |
BYTE plen; |
WORD operation; |
struct eth_addr sha; |
IP_ADDR sip; |
struct eth_addr tha; |
IP_ADDR tip; |
WORD htype; |
WORD ptype; |
BYTE hlen; |
BYTE plen; |
WORD operation; |
struct eth_addr sha; |
IP_ADDR sip; |
struct eth_addr tha; |
IP_ADDR tip; |
} ARP_PKT; |
struct netbuff arp_txbuff; |
126,20 → 129,20 |
*/ |
void arp_exc(int err) |
{ |
int i, j, minused; |
int i, j, minused; |
minused = ARP_MAX_USED; j = -1; |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if ((arpTable[i].valid != PENDING) && (arpTable[i].used <= minused)) { |
j = i; |
minused = arpTable[i].used; |
minused = ARP_MAX_USED; j = -1; |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if ((arpTable[i].valid != PENDING) && (arpTable[i].used <= minused)) { |
j = i; |
minused = arpTable[i].used; |
} |
} |
} |
if (j == -1) { |
cprintf("ARP table overflow!!!\n"); |
sys_abort(AARPFULL); |
} |
arpTable[j].valid = FALSE; |
if (j == -1) { |
cprintf("ARP table overflow.\n"); |
sys_abort(AARPFULL); |
} |
arpTable[j].valid = FALSE; |
} |
/* |
148,100 → 151,91 |
*/ |
void arp_sendRequest(int i) |
{ |
ARP_PKT *pkt; |
BYTE *arpBuff; |
ARP_PKT *pkt; |
BYTE *arpBuff; |
if ((arpBuff= netbuff_get(&arp_txbuff, NON_BLOCK)) != NULL) { |
eth_setHeader(arpBuff,broadcast,ETH_ARP_TYPE); |
pkt = (ARP_PKT *)eth_getFDB(arpBuff); |
pkt->htype = htons(ARP_ETH_TYPE); |
pkt->ptype = htons(ARP_IP_TYPE); |
pkt->hlen = sizeof(struct eth_addr); |
pkt->plen = sizeof(IP_ADDR); |
pkt->operation = htons(ARP_REQUEST); |
setEthAddr(pkt->sha,myEthAddr); |
setEthAddr(pkt->tha,nulladdr); |
setIpAddr(pkt->sip,myIpAddr); |
setIpAddr(pkt->tip,arpTable[i].ip); |
eth_sendPkt(arpBuff,sizeof(ARP_PKT)); |
netbuff_release(&arp_txbuff, (void *)arpBuff); |
} |
if ((arpBuff= netbuff_get(&arp_txbuff, NON_BLOCK)) != NULL) { |
eth_setHeader(arpBuff,broadcast,ETH_ARP_TYPE); |
pkt = (ARP_PKT *)eth_getFDB(arpBuff); |
pkt->htype = htons(ARP_ETH_TYPE); |
pkt->ptype = htons(ARP_IP_TYPE); |
pkt->hlen = sizeof(struct eth_addr); |
pkt->plen = sizeof(IP_ADDR); |
pkt->operation = htons(ARP_REQUEST); |
setEthAddr(pkt->sha,myEthAddr); |
setEthAddr(pkt->tha,nulladdr); |
setIpAddr(pkt->sip,myIpAddr); |
setIpAddr(pkt->tip,arpTable[i].ip); |
eth_sendPkt(arpBuff,sizeof(ARP_PKT)); |
netbuff_release(&arp_txbuff, (void *)arpBuff); |
} |
} |
/* Retry task (periodic) */ |
TASK arp_retry(void) |
{ |
int i; |
PKT_NXT *p, *p1; |
#ifdef __ARP_DBG__ |
char msg[100]; |
#endif |
int i; |
PKT_NXT *p, *p1; |
while (1) { |
/* mutual exclusion on the ARP table */ |
sem_xwait(&arpMutex, 1, BLOCK); |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if (arpTable[i].valid == PENDING) { |
arpTable[i].time--; |
if (arpTable[i].time <= 0) { |
arpTable[i].ntrans++; |
if (arpTable[i].ntrans > ARP_MAX_RETRANS) { |
/* N. Max Retry? If yes, discard all the packets */ |
p = (PKT_NXT *)arpTable[i].pkt; |
while (p != NULL) { |
p1 = p->next; |
netbuff_release(&udp_txbuff, (void *)p); |
while (1) { |
/* mutual exclusion on the ARP table */ |
sem_xwait(&arpMutex, 1, BLOCK); |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if (arpTable[i].valid == PENDING) { |
arpTable[i].time--; |
if (arpTable[i].time <= 0) { |
arpTable[i].ntrans++; |
if (arpTable[i].ntrans > ARP_MAX_RETRANS) { |
/* N. Max Retry? If yes, discard all the packets */ |
p = (PKT_NXT *)arpTable[i].pkt; |
while (p != NULL) { |
p1 = p->next; |
netbuff_release(&udp_txbuff, (void *)p); |
#ifdef __ARP_DBG__ |
sprintf(msg,"Pacchetto : %lp scartato\n",p); |
win_puts(&w1,msg); |
printk(KERN_DEBUG ARP_INFO "Pacchetto : %lp scartato.\n",p); |
#endif |
p = p1; |
p = p1; |
} |
arpTable[i].valid = FALSE; |
} else { |
arp_sendRequest(i); |
arpTable[i].time = ARP_TIMEOUT; |
} |
} |
} |
arpTable[i].valid = FALSE; |
} |
else { |
arp_sendRequest(i); |
arpTable[i].time = ARP_TIMEOUT; |
} |
} |
} |
sem_post(&arpMutex); |
task_endcycle(); |
} |
sem_post(&arpMutex); |
task_endcycle(); |
} |
} |
/* Search for a free entry in the ARP table (if there isn't any, return -1 */ |
int arp_req(IP_ADDR dest) |
{ |
int j, done; |
int j, done; |
done = 0; j = 0; |
while ((j < ARP_MAX_ENTRIES) && !done) { |
if (arpTable[j].valid == FALSE) { |
done = 1; |
arpTable[j].valid = PENDING; |
} else j++; |
} |
done = 0; j = 0; |
while ((j < ARP_MAX_ENTRIES) && !done) { |
if (arpTable[j].valid == FALSE) { |
done = 1; |
arpTable[j].valid = PENDING; |
} else |
j++; |
} |
if (!done) return -1; |
/* Fill the entry */ |
setIpAddr(arpTable[j].ip, dest); |
if (!done) |
return -1; |
/* Fill the entry */ |
setIpAddr(arpTable[j].ip, dest); |
#ifdef __ARP_DBG__ |
sprintf(msg,"Indirizzo : %d.%d.%d.%d\n",dest.ad[0], |
dest.ad[1], |
dest.ad[2], |
dest.ad[3]); |
win_puts(&w1,msg); |
sprintf(msg,"Indirizzo : %d.%d.%d.%d\n",arpTable[j].ip.ad[0], |
arpTable[j].ip.ad[1], |
arpTable[j].ip.ad[2], |
arpTable[j].ip.ad[3]); |
win_puts(&w1,msg); |
printk(KERN_DEBUG ARP_INFO "Indirizzo : %d.%d.%d.%d\n",dest.ad[0], dest.ad[1], dest.ad[2], dest.ad[3]); |
printk(KERN_DEBUG ARP_INFO "Indirizzo : %d.%d.%d.%d\n",arpTable[j].ip.ad[0], arpTable[j].ip.ad[1], arpTable[j].ip.ad[2], arpTable[j].ip.ad[3]); |
#endif |
arpTable[j].time = ARP_TIMEOUT; |
arpTable[j].ntrans = 0; |
return j; |
arpTable[j].time = ARP_TIMEOUT; |
arpTable[j].ntrans = 0; |
return j; |
} |
/* |
250,227 → 244,213 |
*/ |
void arp_send(void *pkt, IP_ADDR dest, int len) |
{ |
int i,j; |
PKT_NXT *p,*p1 = NULL; |
int caso; |
#ifdef __ARP_DBG__ |
char msg[50]; |
#endif |
int i,j; |
PKT_NXT *p,*p1 = NULL; |
int caso; |
sem_xwait(&arpMutex, 1, BLOCK); |
caso = 0; |
j = -1; |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if (ip_compAddr(dest,arpTable[i].ip)) { |
/* found: CASE 1 */ |
if (arpTable[i].valid == TRUE) { |
caso = 1; |
j = i; |
} |
else if (arpTable[i].valid == PENDING) { |
/* Entry found, but the ethernet address is still unknown: CASE 2 */ |
caso = 2; |
j = i; |
} |
sem_xwait(&arpMutex, 1, BLOCK); |
caso = 0; |
j = -1; |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if (ip_compAddr(dest,arpTable[i].ip)) { |
/* found: CASE 1 */ |
if (arpTable[i].valid == TRUE) { |
caso = 1; |
j = i; |
} |
else if (arpTable[i].valid == PENDING) { |
/* Entry found, but the ethernet address is still unknown: CASE 2 */ |
caso = 2; |
j = i; |
} |
} |
} |
} |
if (caso == 1) { |
/* Send the IP packet */ |
eth_setHeader(pkt,arpTable[j].eth,ETH_IP_TYPE); |
eth_sendPkt(pkt,len); |
netbuff_release(&udp_txbuff, (void *)pkt); |
arpTable[j].used++; |
if (arpTable[j].used > ARP_MAX_USED) arpTable[j].used = ARP_MAX_USED; |
} |
else if (caso == 2) { |
/* Enqueue the packet until the ethernet address arrives */ |
p = arpTable[j].pkt; |
while (p != NULL) { |
p1 = p; |
p = p1->next; |
} |
p1->next = pkt; |
((PKT_NXT *)pkt)->next = NULL; |
((PKT_NXT *)pkt)->len = len; |
if (caso == 1) { |
/* Send the IP packet */ |
eth_setHeader(pkt,arpTable[j].eth,ETH_IP_TYPE); |
eth_sendPkt(pkt,len); |
netbuff_release(&udp_txbuff, (void *)pkt); |
arpTable[j].used++; |
if (arpTable[j].used > ARP_MAX_USED) arpTable[j].used = ARP_MAX_USED; |
} else if (caso == 2) { |
/* Enqueue the packet until the ethernet address arrives */ |
p = arpTable[j].pkt; |
while (p != NULL) { |
p1 = p; |
p = p1->next; |
} |
p1->next = pkt; |
((PKT_NXT *)pkt)->next = NULL; |
((PKT_NXT *)pkt)->len = len; |
#ifdef __ARP_DBG__ |
sprintf(msg,"Pacchetto : %lp accodato\n",pkt); |
win_puts(&w1,msg); |
printk(KERN_DEBUG ARP_INFO "Pacchetto : %lp accodato.\n", pkt); |
#endif |
} |
else { |
/* Search for a free entry in the ARP table...*/ |
j = -1; |
while (j == -1) { |
j = arp_req(dest); |
if (j == -1) { |
cprintf("FULL!!!\n"); |
kern_raise(XARP_TABLE_FULL,NIL); |
} |
} |
/*...fill it...*/ |
arpTable[j].pkt = pkt; |
((PKT_NXT *)arpTable[j].pkt)->next = NULL; |
((PKT_NXT *)pkt)->len = len; |
} else { |
/* Search for a free entry in the ARP table...*/ |
j = -1; |
while (j == -1) { |
j = arp_req(dest); |
if (j == -1) { |
cprintf("ARP Table Full.\n"); |
kern_raise(XARP_TABLE_FULL,NIL); |
} |
} |
/*...fill it...*/ |
arpTable[j].pkt = pkt; |
((PKT_NXT *)arpTable[j].pkt)->next = NULL; |
((PKT_NXT *)pkt)->len = len; |
#ifdef __ARP_DBG__ |
sprintf(msg,"Pacchetto : %lp accodato\n",pkt); |
win_puts(&w1,msg); |
printk(KERN_DEBUG ARP_INFO "Pacchetto : %lp accodato\n", pkt); |
#endif |
/*...and send the request!!! */ |
arp_sendRequest(j); |
} |
sem_post(&arpMutex); |
/*...and send the request!!! */ |
arp_sendRequest(j); |
} |
sem_post(&arpMutex); |
} |
/* ARP packet received CallBack*/ |
void arp_server_recv(void *pk) |
{ |
ARP_PKT *pkt,*rpkt; |
PKT_NXT *p1,*q1; |
int len; |
int i,j = 0; |
#ifdef __ARP_DBG__ |
char msg[100]; |
#endif |
BYTE found; |
ARP_PKT *pkt,*rpkt; |
PKT_NXT *p1,*q1; |
int len; |
int i,j = 0; |
BYTE found; |
pkt = (ARP_PKT *)eth_getFDB(pk); |
#if 0 |
{int ii; |
cprintf("Arp PKT...\n"); |
cprintf ("source..."); |
for (ii=0; ii<4; ii++) cprintf("%d ", pkt->sip.ad[ii]); |
cprintf ("\ndest..."); |
for (ii=0; ii<4; ii++) cprintf("%d ", pkt->tip.ad[ii]); |
{ |
int ii; |
cprintf("Arp PKT...\n"); |
cprintf ("source..."); |
for (ii=0; ii<4; ii++) cprintf("%d ", pkt->sip.ad[ii]); |
cprintf ("\ndest..."); |
for (ii=0; ii<4; ii++) cprintf("%d ", pkt->tip.ad[ii]); |
} |
#endif |
/* Check if the packet is directed to this host...*/ |
if (ip_compAddr(pkt->tip,myIpAddr)) { |
sem_xwait(&arpMutex, 1, BLOCK); |
/* 1 : Search an entry with his IP address */ |
found = FALSE; |
for (i = 0; (i < ARP_MAX_ENTRIES) && !found; i++) { |
if ((arpTable[i].valid != FALSE) && |
ip_compAddr(arpTable[i].ip,pkt->sip)) { |
setEthAddr(arpTable[i].eth,pkt->sha); |
found = TRUE; |
sem_xwait(&arpMutex, 1, BLOCK); |
/* 1 : Search an entry with his IP address */ |
found = FALSE; |
for (i = 0; (i < ARP_MAX_ENTRIES) && !found; i++) { |
if ((arpTable[i].valid != FALSE) && ip_compAddr(arpTable[i].ip,pkt->sip)) { |
setEthAddr(arpTable[i].eth,pkt->sha); |
found = TRUE; |
} |
} |
} |
/* |
If there isn't any, fill a new entry (if the table is |
not full) |
*/ |
if (!found) { |
for (i = 0; (i < ARP_MAX_ENTRIES) && !found; i++) |
if (arpTable[i].valid == FALSE) { |
j = i; |
found = TRUE; |
} |
if (found) { |
setIpAddr(arpTable[j].ip,pkt->sip); |
setEthAddr(arpTable[j].eth,pkt->sha); |
arpTable[j].valid = TRUE; |
/* If there isn't any, fill a new entry (if the table is not full) */ |
if (!found) { |
for (i = 0; (i < ARP_MAX_ENTRIES) && !found; i++) |
if (arpTable[i].valid == FALSE) { |
j = i; |
found = TRUE; |
} |
if (found) { |
setIpAddr(arpTable[j].ip,pkt->sip); |
setEthAddr(arpTable[j].eth,pkt->sha); |
arpTable[j].valid = TRUE; |
} |
} |
} |
/* If it is a request, send the reply */ |
if (ntohs(pkt->operation) == ARP_REQUEST) { |
rpkt = (ARP_PKT *)eth_getFDB(reply); |
rpkt->htype = htons(ARP_ETH_TYPE); |
rpkt->ptype = htons(ARP_IP_TYPE); |
rpkt->hlen = sizeof(struct eth_addr); |
rpkt->plen = sizeof(IP_ADDR); |
rpkt->operation = htons(ARP_REPLY); |
setEthAddr(rpkt->sha,myEthAddr); |
setIpAddr(rpkt->sip,myIpAddr); |
setEthAddr(rpkt->tha,pkt->sha); |
setIpAddr(rpkt->tip,pkt->sip); |
eth_setHeader(reply, pkt->sha, ETH_ARP_TYPE); |
eth_sendPkt(reply,sizeof(ARP_PKT)); |
} |
/* If it is a reply, search for his pending request */ |
else { |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if ((arpTable[i].valid == PENDING) && |
ip_compAddr(arpTable[i].ip,pkt->sip)) { |
/* |
the eth field in the ARP table was |
filled previously |
*/ |
arpTable[i].valid = TRUE; |
/* Send pending packets */ |
p1 = (PKT_NXT *)arpTable[i].pkt; |
while (p1 != NULL) { |
q1 = p1; |
p1 = q1->next; |
len = q1->len; |
eth_setHeader((struct ETH_HEADER *)q1,arpTable[i].eth,ETH_IP_TYPE); |
eth_sendPkt(q1,len); |
netbuff_release(&udp_txbuff, (void *)q1); |
/* If it is a request, send the reply */ |
if (ntohs(pkt->operation) == ARP_REQUEST) { |
rpkt = (ARP_PKT *)eth_getFDB(reply); |
rpkt->htype = htons(ARP_ETH_TYPE); |
rpkt->ptype = htons(ARP_IP_TYPE); |
rpkt->hlen = sizeof(struct eth_addr); |
rpkt->plen = sizeof(IP_ADDR); |
rpkt->operation = htons(ARP_REPLY); |
setEthAddr(rpkt->sha,myEthAddr); |
setIpAddr(rpkt->sip,myIpAddr); |
setEthAddr(rpkt->tha,pkt->sha); |
setIpAddr(rpkt->tip,pkt->sip); |
eth_setHeader(reply, pkt->sha, ETH_ARP_TYPE); |
eth_sendPkt(reply,sizeof(ARP_PKT)); |
} |
/* If it is a reply, search for his pending request */ |
else { |
for (i = 0; i < ARP_MAX_ENTRIES; i++) { |
if ((arpTable[i].valid == PENDING) && ip_compAddr(arpTable[i].ip,pkt->sip)) { |
/* the eth field in the ARP table was filled previously */ |
arpTable[i].valid = TRUE; |
/* Send pending packets */ |
p1 = (PKT_NXT *)arpTable[i].pkt; |
while (p1 != NULL) { |
q1 = p1; |
p1 = q1->next; |
len = q1->len; |
eth_setHeader((struct ETH_HEADER *)q1,arpTable[i].eth,ETH_IP_TYPE); |
eth_sendPkt(q1,len); |
netbuff_release(&udp_txbuff, (void *)q1); |
#ifdef __ARP_DBG__ |
sprintf(msg,"Pacchetto : %lp inviato\n",q1); |
win_puts(&w1,msg); |
printk(KERN_DEBUG ARP_INFO "Pacchetto : %lp inviato\n", q1); |
#endif |
} |
} |
} |
} |
} |
} |
} |
sem_post(&arpMutex); |
sem_post(&arpMutex); |
} |
} |
void arp_init(char *localAddr) |
{ |
int i; |
PID s; |
SOFT_TASK_MODEL m; |
int i; |
PID s; |
SOFT_TASK_MODEL m; |
struct sigaction action; |
struct sigaction action; |
if (!arpIsInstalled) { |
for (i = 0; i < ARP_MAX_ENTRIES; i++) arpTable[i].valid = FALSE; |
if (!arpIsInstalled) { |
for (i = 0; i < ARP_MAX_ENTRIES; i++) arpTable[i].valid = FALSE; |
/* ARP table mutex semaphore */ |
sem_init(&arpMutex, 0, 1); |
/* ARP table mutex semaphore */ |
sem_init(&arpMutex, 0, 1); |
netbuff_init(&arp_txbuff, 1, ARP_LEN); |
netbuff_init(&arp_txbuff, 1, ARP_LEN); |
ip_str2addr(localAddr,&myIpAddr); |
ip_str2addr(localAddr,&myIpAddr); |
eth_getAddress(&myEthAddr); |
eth_getAddress(&myEthAddr); |
/* Retry task */ |
soft_task_default_model(m); |
soft_task_def_wcet(m,1000); |
soft_task_def_period(m,1000000); |
soft_task_def_met(m,1000); |
soft_task_def_periodic(m); |
soft_task_def_system(m); |
soft_task_def_nokill(m); |
s = task_create("ArpRetry",arp_retry,&m,NULL); |
if (s == NIL) { |
kern_printf("Cannot create ArpRetry\n"); |
sys_end(); |
l1_exit(-1); |
} |
/* Retry task */ |
soft_task_default_model(m); |
soft_task_def_wcet(m,1000); |
soft_task_def_period(m,1000000); |
soft_task_def_met(m,1000); |
soft_task_def_periodic(m); |
soft_task_def_system(m); |
soft_task_def_nokill(m); |
s = task_create("ArpRetry",arp_retry,&m,NULL); |
if (s == NIL) { |
kern_printf("Cannot create ArpRetry\n"); |
sys_end(); |
l1_exit(-1); |
} |
eth_setProtocol(ETH_ARP_TYPE,arp_server_recv); |
eth_str2Addr("FF:FF:FF:FF:FF:FF",&broadcast); |
eth_str2Addr("00:00:00:00:00:00",&nulladdr); |
eth_setProtocol(ETH_ARP_TYPE,arp_server_recv); |
eth_str2Addr("FF:FF:FF:FF:FF:FF",&broadcast); |
eth_str2Addr("00:00:00:00:00:00",&nulladdr); |
// for (i = ARP_ERROR_BASE; i <= XARP_TABLE_FULL; i++) |
// exc_set(i, arp_exc); |
action.sa_flags = 0; |
action.sa_handler = arp_exc; |
sigfillset(&action.sa_mask); /* we block all the other signals... */ |
// for (i = ARP_ERROR_BASE; i <= XARP_TABLE_FULL; i++) |
// exc_set(i, arp_exc); |
action.sa_flags = 0; |
action.sa_handler = arp_exc; |
sigfillset(&action.sa_mask); /* we block all the other signals... */ |
if (sigaction(SIGARPFULL, &action, NULL) == -1) { |
perror("Error initializing ARP signal..."); |
sys_abort(AARPFULL); |
} |
if (sigaction(SIGARPFULL, &action, NULL) == -1) { |
perror("Error initializing ARP signal..."); |
sys_abort(AARPFULL); |
} |
task_activate(s); |
arpIsInstalled = TRUE; |
} else cprintf("Arp: already installed!!!!"); |
task_activate(s); |
arpIsInstalled = TRUE; |
} else |
cprintf("Arp: already installed."); |
} |
/shark/trunk/drivers/newnet/eth_priv.h |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: eth_priv.h,v 1.1 2004-04-23 14:30:32 mauro Exp $ |
CVS : $Id: eth_priv.h,v 1.2 2004-04-23 18:13:52 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:32 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:52 $ |
------------ |
**/ |
70,19 → 70,19 |
#define ETH_MAX_PROTOCOLS 5 |
typedef struct eth_addr { |
BYTE ad[6]; |
BYTE ad[6]; |
} ETH_ADDR; |
typedef struct eth_header { |
struct eth_addr dest; |
struct eth_addr source; |
WORD type; |
struct eth_addr dest; |
struct eth_addr source; |
WORD type; |
} ETH_HEADER; |
typedef struct eth_device { |
DWORD BaseAddress; |
BYTE IntLine; |
struct eth_addr addr; |
DWORD BaseAddress; |
BYTE IntLine; |
struct eth_addr addr; |
} ETH_DEVICE; |
#define setEthAddr(q,w) memcpy(q.ad,w.ad,sizeof(struct eth_addr)) |
/shark/trunk/drivers/newnet/net.c |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: net.c,v 1.1 2004-04-23 14:30:33 mauro Exp $ |
CVS : $Id: net.c,v 1.2 2004-04-23 18:13:52 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:33 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:52 $ |
------------ |
**/ |
63,38 → 63,38 |
#include <drivers/net.h> |
#include "eth_priv.h" |
#define DEBUG_NET |
//#define DEBUG_NET |
/* OKKIO!!!!! net_base must change if you change NET_MAX_PROTOCOLS!!!! */ |
struct net_model net_base = {0, 0, {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, |
NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, |
{NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}; |
struct net_model net_base = {0, 0, {{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, |
{NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}, {NULL, NULL}}}; |
void net_setprotocol(struct net_model *m, void (*initfun)(void *parm), void *initparms) |
{ |
int i; |
int i; |
i = m->numprotocol++; |
m->protocol[i].initfun=initfun; |
m->protocol[i].initparms=initparms; |
i = m->numprotocol++; |
m->protocol[i].initfun = initfun; |
m->protocol[i].initparms = initparms; |
} |
int net_init(struct net_model *m) |
{ |
int i; |
int i; |
int app; |
/* First, initialize the base layers: eth & lowlev */ |
if ((app = eth_init(m->lowlevparm,NULL)) != 1) { |
/* First, initialize the base layers: eth & lowlev */ |
if ((app = eth_init(m->lowlevparm,NULL)) != 1) { |
return app; |
} |
/* Then, the high level layers */ |
for(i = 0; i < m->numprotocol; i++) { |
/* Then, the high level layers */ |
for(i = 0; i < m->numprotocol; i++) { |
#ifdef DEBUG_NET |
printk(KERN_DEBUG "Protocol %d init \n", i); |
printk(KERN_DEBUG "Protocol %d init.\n", i); |
#endif |
m->protocol[i].initfun(m->protocol[i].initparms); |
} |
m->protocol[i].initfun(m->protocol[i].initparms); |
} |
return 1; |
} |
/shark/trunk/drivers/newnet/rtl8139.c |
---|
25,8 → 25,8 |
/* A few user-configurable values. */ |
/* Maximum events (Rx packets, etc.) to handle at each interrupt. */ |
static int max_interrupt_work = 20; |
#define rtl8129_debug debug |
static int rtl8129_debug = 3; |
//#define rtl8129_debug debug |
static int rtl8129_debug = 0; |
/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
/shark/trunk/drivers/newnet/arp.h |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: arp.h,v 1.1 2004-04-23 14:30:32 mauro Exp $ |
CVS : $Id: arp.h,v 1.2 2004-04-23 18:13:51 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:32 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:51 $ |
------------ |
**/ |
64,7 → 64,7 |
#define ARP_IP_TYPE 0x0800 |
#define ARP_ETH_TYPE 1 |
#define ARP_REQUEST 1 |
#define ARP_REPLY 2 |
76,13 → 76,13 |
typedef struct arp_table{ |
IP_ADDR ip; |
struct eth_addr eth; |
int used; |
int time; |
int ntrans; |
void *pkt; |
BYTE valid; |
IP_ADDR ip; |
struct eth_addr eth; |
int used; |
int time; |
int ntrans; |
void *pkt; |
BYTE valid; |
} ARP_TABLE; |
void arp_send(void *pkt, IP_ADDR dest, int len); |
/shark/trunk/drivers/newnet/netbuff.c |
---|
20,11 → 20,11 |
/** |
------------ |
CVS : $Id: netbuff.c,v 1.1 2004-04-23 14:30:34 mauro Exp $ |
CVS : $Id: netbuff.c,v 1.2 2004-04-23 18:13:52 mauro Exp $ |
File: $File$ |
Revision: $Revision: 1.1 $ |
Last update: $Date: 2004-04-23 14:30:34 $ |
Revision: $Revision: 1.2 $ |
Last update: $Date: 2004-04-23 18:13:52 $ |
------------ |
**/ |
71,22 → 71,22 |
/* Init the buffer structures */ |
void netbuff_init(struct netbuff *netb, BYTE nbuffs, WORD buffdim) |
{ |
int i; |
int i; |
kern_cli(); |
netb->b = kern_alloc(nbuffs * buffdim); |
netb->pb = kern_alloc(nbuffs * sizeof(void *)); |
netb->free = kern_alloc(nbuffs * sizeof(char)); |
kern_sti(); |
if ((netb->b == 0) || (netb->pb ==0) || (netb->free == 0)) { |
kern_raise(XNETBUFF_INIT_EXC,exec_shadow); |
} |
netb->nbuffs = nbuffs; |
for (i = 0; i < nbuffs; i++) { |
netb->pb[i] = netb->b + (i * buffdim); |
netb->free[i] = 1; |
} |
sem_init(&(netb->buffersem), 0, nbuffs); |
kern_cli(); |
netb->b = kern_alloc(nbuffs * buffdim); |
netb->pb = kern_alloc(nbuffs * sizeof(void *)); |
netb->free = kern_alloc(nbuffs * sizeof(char)); |
kern_sti(); |
if ((netb->b == 0) || (netb->pb ==0) || (netb->free == 0)) { |
kern_raise(XNETBUFF_INIT_EXC,exec_shadow); |
} |
netb->nbuffs = nbuffs; |
for (i = 0; i < nbuffs; i++) { |
netb->pb[i] = netb->b + (i * buffdim); |
netb->free[i] = 1; |
} |
sem_init(&(netb->buffersem), 0, nbuffs); |
} |
/* |
95,28 → 95,28 |
*/ |
void *netbuff_get(struct netbuff *netb, BYTE to) |
{ |
int i, done; |
static int mycount = 0; |
int i, done; |
static int mycount = 0; |
if (sem_xwait(&(netb->buffersem), 1, to) != 0) { |
return NULL; |
} else { |
mycount++; |
} |
if (sem_xwait(&(netb->buffersem), 1, to) != 0) { |
return NULL; |
} else { |
mycount++; |
} |
done = 0; i = 0; |
kern_cli(); |
while ((i < netb->nbuffs) && !done) { |
if (netb->free[i]) { |
done = 1; |
netb->free[i] = 0; |
} else i++; |
} |
kern_sti(); |
if (!done) { |
kern_raise(XNETBUFF_GET_EXC,exec_shadow); |
} |
return netb->pb[i]; |
done = 0; i = 0; |
kern_cli(); |
while ((i < netb->nbuffs) && !done) { |
if (netb->free[i]) { |
done = 1; |
netb->free[i] = 0; |
} else i++; |
} |
kern_sti(); |
if (!done) { |
kern_raise(XNETBUFF_GET_EXC,exec_shadow); |
} |
return netb->pb[i]; |
} |
/* |
126,44 → 126,44 |
*/ |
void *netbuff_sequentialget(struct netbuff *netb, BYTE to) |
{ |
int i, done; |
int i, done; |
if (!sem_xwait(&(netb->buffersem), 1, to)) { |
return NULL; |
} |
if (!sem_xwait(&(netb->buffersem), 1, to)) { |
return NULL; |
} |
done = 0; i = 0; |
while ((i < netb->nbuffs) && !done) { |
if (netb->free[i]) { |
done = 1; |
netb->free[i] = 0; |
} else i++; |
} |
if (!done) { |
kern_raise(XNETBUFF_GET_EXC,exec_shadow); |
} |
return netb->pb[i]; |
done = 0; i = 0; |
while ((i < netb->nbuffs) && !done) { |
if (netb->free[i]) { |
done = 1; |
netb->free[i] = 0; |
} else i++; |
} |
if (!done) { |
kern_raise(XNETBUFF_GET_EXC,exec_shadow); |
} |
return netb->pb[i]; |
} |
/* Release the buffer m of the pool netb */ |
void netbuff_release(struct netbuff *netb, void *m) |
{ |
int i, done; |
int i, done; |
done = 0; i = 0; |
while ((i < netb->nbuffs) && !done) { |
if (netb->pb[i] == m) { |
if (netb->free[i] == 1) { |
cprintf("Trying to free a free buffer :( \n"); |
kern_raise(XNETBUFF_ALREADYFREE_EXC,exec_shadow); |
} |
done = 1; |
netb->free[i] = 1; |
} else i++; |
} |
if (!done) { |
cprintf("Trying to free a STRANGE buffer :( \n"); |
kern_raise(XNETBUFF_RELEASE_EXC,exec_shadow); |
} |
sem_post(&(netb->buffersem)); |
done = 0; i = 0; |
while ((i < netb->nbuffs) && !done) { |
if (netb->pb[i] == m) { |
if (netb->free[i] == 1) { |
cprintf("Trying to free a free buffer :( \n"); |
kern_raise(XNETBUFF_ALREADYFREE_EXC,exec_shadow); |
} |
done = 1; |
netb->free[i] = 1; |
} else i++; |
} |
if (!done) { |
cprintf("Trying to free a STRANGE buffer :( \n"); |
kern_raise(XNETBUFF_RELEASE_EXC,exec_shadow); |
} |
sem_post(&(netb->buffersem)); |
} |
/shark/trunk/drivers/newnet/misc.c |
---|
1,33 → 1,6 |
#include <string.h> |
#include <kernel/kern.h> |
#if 0 |
unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base) |
{ |
unsigned long result = 0,value; |
if (!base) { |
base = 10; |
if (*cp == '0') { |
base = 8; |
cp++; |
if ((*cp == 'x') && isxdigit(cp[1])) { |
cp++; |
base = 16; |
} |
} |
} |
while (isxdigit(*cp) && (value = isdigit(*cp) ? *cp-'0' : (islower(*cp) |
? toupper(*cp) : *cp)-'A'+10) < base) { |
result = result*base + value; |
cp++; |
} |
if (endp) |
*endp = (char *)cp; |
return result; |
} |
#endif |
void panic_stub(void) |
{ |
cprintf("Panic: stub called!!!\n"); |
/shark/trunk/drivers/newnet/eepro100.c |
---|
106,7 → 106,7 |
The registers beyond 0x18 only exist on the i82558. */ |
#define SPEEDO3_TOTAL_SIZE 0x20 |
int speedo_debug = 1; |
int speedo_debug = 0; |
/* |
Theory of Operation |
477,7 → 477,8 |
u16 pci_command, new_command; |
printk("Finding Device\n"); |
if (speedo_debug > 0) |
printk("Finding Device\n"); |
if (pci20to26_find_class (PCI_CLASS_NETWORK_ETHERNET << 8, pci_index, |
&pci_bus, &pci_device_fn) |
489,7 → 490,8 |
pci20to26_read_config_word(pci_bus, pci_device_fn, |
PCI_DEVICE_ID, &device); |
printk("Device = %x Vendor = %x\n",(int)device,(int)vendor); |
if (speedo_debug > 0) |
printk("Device = %x Vendor = %x\n",(int)device,(int)vendor); |
if (vendor != PCI_VENDOR_ID_INTEL) |
break; |