clang-format in src/network/
This commit is contained in:
@@ -89,11 +89,9 @@ typedef struct {
|
||||
int dma_channel;
|
||||
} threec503_t;
|
||||
|
||||
|
||||
#ifdef ENABLE_3COM503_LOG
|
||||
int threec503_do_log = ENABLE_3COM503_LOG;
|
||||
|
||||
|
||||
static void
|
||||
threec503_log(const char *fmt, ...)
|
||||
{
|
||||
@@ -106,10 +104,9 @@ threec503_log(const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define threec503_log(fmt, ...)
|
||||
# define threec503_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
threec503_interrupt(void *priv, int set)
|
||||
{
|
||||
@@ -139,11 +136,10 @@ threec503_interrupt(void *priv, int set)
|
||||
picintc(1 << dev->base_irq);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
threec503_ram_write(uint32_t addr, uint8_t val, void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
|
||||
if ((addr & 0x3fff) >= 0x2000)
|
||||
return;
|
||||
@@ -151,11 +147,10 @@ threec503_ram_write(uint32_t addr, uint8_t val, void *priv)
|
||||
dev->dp8390->mem[addr & 0x1fff] = val;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
threec503_ram_read(uint32_t addr, void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
|
||||
if ((addr & 0x3fff) >= 0x2000)
|
||||
return 0xff;
|
||||
@@ -163,7 +158,6 @@ threec503_ram_read(uint32_t addr, void *priv)
|
||||
return dev->dp8390->mem[addr & 0x1fff];
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
threec503_set_drq(threec503_t *dev)
|
||||
{
|
||||
@@ -182,12 +176,11 @@ threec503_set_drq(threec503_t *dev)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* reset - restore state to power-up, cancelling all i/o */
|
||||
static void
|
||||
threec503_reset(void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
|
||||
#ifdef ENABLE_3COM503_LOG
|
||||
threec503_log("3Com503: reset\n");
|
||||
@@ -200,11 +193,10 @@ threec503_reset(void *priv)
|
||||
dev->regs.ctrl = 0x0a;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
threec503_nic_lo_read(uint16_t addr, void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
uint8_t retval = 0;
|
||||
int off = addr - dev->base_address;
|
||||
|
||||
@@ -213,7 +205,8 @@ threec503_nic_lo_read(uint16_t addr, void *priv)
|
||||
threec503_log("Read offset=%04x\n", off);
|
||||
if (off == 0x00)
|
||||
retval = dp8390_read_cr(dev->dp8390);
|
||||
else switch(dev->dp8390->CR.pgsel) {
|
||||
else
|
||||
switch (dev->dp8390->CR.pgsel) {
|
||||
case 0x00:
|
||||
retval = dp8390_page0_read(dev->dp8390, off, 1);
|
||||
break;
|
||||
@@ -245,14 +238,13 @@ threec503_nic_lo_read(uint16_t addr, void *priv)
|
||||
break;
|
||||
}
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
threec503_nic_lo_write(uint16_t addr, uint8_t val, void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
int off = addr - dev->base_address;
|
||||
|
||||
switch ((dev->regs.ctrl >> 2) & 3) {
|
||||
@@ -263,7 +255,8 @@ threec503_nic_lo_write(uint16_t addr, uint8_t val, void *priv)
|
||||
command register */
|
||||
if (off == 0x00)
|
||||
dp8390_write_cr(dev->dp8390, val);
|
||||
else switch(dev->dp8390->CR.pgsel) {
|
||||
else
|
||||
switch (dev->dp8390->CR.pgsel) {
|
||||
case 0x00:
|
||||
dp8390_page0_write(dev->dp8390, off, val, 1);
|
||||
break;
|
||||
@@ -290,11 +283,10 @@ threec503_nic_lo_write(uint16_t addr, uint8_t val, void *priv)
|
||||
threec503_log("3Com503: write addr %x, value %x\n", addr, val);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
threec503_nic_hi_read(uint16_t addr, void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
|
||||
threec503_log("3Com503: Read GA address=%04x\n", addr);
|
||||
|
||||
@@ -409,11 +401,10 @@ threec503_nic_hi_read(uint16_t addr, void *priv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
threec503_nic_hi_write(uint16_t addr, uint8_t val, void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
|
||||
threec503_log("3Com503: Write GA address=%04x, val=%04x\n", addr, val);
|
||||
|
||||
@@ -538,7 +529,6 @@ threec503_nic_hi_write(uint16_t addr, uint8_t val, void *priv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
threec503_nic_ioset(threec503_t *dev, uint16_t addr)
|
||||
{
|
||||
@@ -546,12 +536,11 @@ threec503_nic_ioset(threec503_t *dev, uint16_t addr)
|
||||
threec503_nic_lo_read, NULL, NULL,
|
||||
threec503_nic_lo_write, NULL, NULL, dev);
|
||||
|
||||
io_sethandler(addr+0x400, 0x10,
|
||||
io_sethandler(addr + 0x400, 0x10,
|
||||
threec503_nic_hi_read, NULL, NULL,
|
||||
threec503_nic_hi_write, NULL, NULL, dev);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
threec503_nic_init(const device_t *info)
|
||||
{
|
||||
@@ -589,8 +578,8 @@ threec503_nic_init(const device_t *info)
|
||||
mac |= ((int) dev->maclocal[5]);
|
||||
device_set_config_mac("mac", mac);
|
||||
} else {
|
||||
dev->maclocal[3] = (mac>>16) & 0xff;
|
||||
dev->maclocal[4] = (mac>>8) & 0xff;
|
||||
dev->maclocal[3] = (mac >> 16) & 0xff;
|
||||
dev->maclocal[4] = (mac >> 8) & 0xff;
|
||||
dev->maclocal[5] = (mac & 0xff);
|
||||
}
|
||||
|
||||
@@ -621,14 +610,13 @@ threec503_nic_init(const device_t *info)
|
||||
/* Attach ourselves to the network module. */
|
||||
dev->dp8390->card = network_attach(dev->dp8390, dev->dp8390->physaddr, dp8390_rx, NULL);
|
||||
|
||||
return(dev);
|
||||
return (dev);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
threec503_nic_close(void *priv)
|
||||
{
|
||||
threec503_t *dev = (threec503_t *)priv;
|
||||
threec503_t *dev = (threec503_t *) priv;
|
||||
|
||||
#ifdef ENABLE_3COM503_LOG
|
||||
threec503_log("3Com503: closed\n");
|
||||
@@ -638,7 +626,7 @@ threec503_nic_close(void *priv)
|
||||
}
|
||||
|
||||
static const device_config_t threec503_config[] = {
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
{
|
||||
.name = "base",
|
||||
.description = "Address",
|
||||
|
@@ -30,7 +30,6 @@
|
||||
#include <86box/network.h>
|
||||
#include <86box/net_dp8390.h>
|
||||
|
||||
|
||||
static void dp8390_tx(dp8390_t *dev, uint32_t val);
|
||||
static int dp8390_rx_common(void *priv, uint8_t *buf, int io_len);
|
||||
int dp8390_rx(void *priv, uint8_t *buf, int io_len);
|
||||
@@ -45,17 +44,16 @@ dp8390_log(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
// if (dp8390_do_log >= lvl) {
|
||||
// if (dp8390_do_log >= lvl) {
|
||||
va_start(ap, fmt);
|
||||
pclog_ex(fmt, ap);
|
||||
va_end(ap);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
#else
|
||||
#define dp8390_log(lvl, fmt, ...)
|
||||
# define dp8390_log(lvl, fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Return the 6-bit index into the multicast
|
||||
* table. Stolen unashamedly from FreeBSD's if_ed.c
|
||||
@@ -67,9 +65,9 @@ mcast_index(const void *dst)
|
||||
uint32_t crc = 0xffffffffL;
|
||||
int carry, i, j;
|
||||
uint8_t b;
|
||||
uint8_t *ep = (uint8_t *)dst;
|
||||
uint8_t *ep = (uint8_t *) dst;
|
||||
|
||||
for (i=6; --i>=0;) {
|
||||
for (i = 6; --i >= 0;) {
|
||||
b = *ep++;
|
||||
for (j = 8; --j >= 0;) {
|
||||
carry = ((crc & 0x80000000L) ? 1 : 0) ^ (b & 0x01);
|
||||
@@ -79,11 +77,10 @@ mcast_index(const void *dst)
|
||||
crc = ((crc ^ POLYNOMIAL) | carry);
|
||||
}
|
||||
}
|
||||
return(crc >> 26);
|
||||
return (crc >> 26);
|
||||
#undef POLYNOMIAL
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Access the 32K private RAM.
|
||||
*
|
||||
@@ -119,10 +116,9 @@ dp8390_chipmem_read(dp8390_t *dev, uint32_t addr, unsigned int len)
|
||||
addr++;
|
||||
}
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_chipmem_write(dp8390_t *dev, uint32_t addr, uint32_t val, unsigned len)
|
||||
{
|
||||
@@ -147,24 +143,18 @@ dp8390_chipmem_write(dp8390_t *dev, uint32_t addr, uint32_t val, unsigned len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Routines for handling reads/writes to the Command Register. */
|
||||
uint32_t
|
||||
dp8390_read_cr(dp8390_t *dev)
|
||||
{
|
||||
uint32_t retval;
|
||||
|
||||
retval = (((dev->CR.pgsel & 0x03) << 6) |
|
||||
((dev->CR.rdma_cmd & 0x07) << 3) |
|
||||
(dev->CR.tx_packet << 2) |
|
||||
(dev->CR.start << 1) |
|
||||
(dev->CR.stop));
|
||||
retval = (((dev->CR.pgsel & 0x03) << 6) | ((dev->CR.rdma_cmd & 0x07) << 3) | (dev->CR.tx_packet << 2) | (dev->CR.start << 1) | (dev->CR.stop));
|
||||
dp8390_log("DP8390: read CR returns 0x%02x\n", retval);
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_write_cr(dp8390_t *dev, uint32_t val)
|
||||
{
|
||||
@@ -244,8 +234,7 @@ dp8390_write_cr(dp8390_t *dev, uint32_t val)
|
||||
/* Linux probes for an interrupt by setting up a remote-DMA read
|
||||
* of 0 bytes with remote-DMA completion interrupts enabled.
|
||||
* Detect this here */
|
||||
if ((dev->CR.rdma_cmd == 0x01) && dev->CR.start &&
|
||||
(dev->remote_bytes == 0)) {
|
||||
if ((dev->CR.rdma_cmd == 0x01) && dev->CR.start && (dev->remote_bytes == 0)) {
|
||||
dev->ISR.rdma_done = 1;
|
||||
if (dev->IMR.rdma_inte && dev->interrupt) {
|
||||
dev->interrupt(dev->priv, 1);
|
||||
@@ -255,7 +244,6 @@ dp8390_write_cr(dp8390_t *dev, uint32_t val)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dp8390_tx(dp8390_t *dev, uint32_t val)
|
||||
{
|
||||
@@ -269,7 +257,6 @@ dp8390_tx(dp8390_t *dev, uint32_t val)
|
||||
dev->tx_timer_active = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Called by the platform-specific code when an Ethernet frame
|
||||
* has been received. The destination address is tested to see
|
||||
@@ -279,8 +266,8 @@ dp8390_tx(dp8390_t *dev, uint32_t val)
|
||||
static int
|
||||
dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
{
|
||||
dp8390_t *dev = (dp8390_t *)priv;
|
||||
static uint8_t bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
|
||||
dp8390_t *dev = (dp8390_t *) priv;
|
||||
static uint8_t bcast_addr[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
uint8_t pkthdr[4];
|
||||
uint8_t *startptr;
|
||||
int pages, avail;
|
||||
@@ -299,12 +286,11 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
* Add the pkt header + CRC to the length, and work
|
||||
* out how many 256-byte pages the frame would occupy.
|
||||
*/
|
||||
pages = (io_len + sizeof(pkthdr) + sizeof(uint32_t) + 255)/256;
|
||||
pages = (io_len + sizeof(pkthdr) + sizeof(uint32_t) + 255) / 256;
|
||||
if (dev->curr_page < dev->bound_ptr) {
|
||||
avail = dev->bound_ptr - dev->curr_page;
|
||||
} else {
|
||||
avail = (dev->page_stop - dev->page_start) -
|
||||
(dev->curr_page - dev->bound_ptr);
|
||||
avail = (dev->page_stop - dev->page_start) - (dev->curr_page - dev->bound_ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -324,7 +310,7 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((io_len < 40/*60*/) && !dev->RCR.runts_ok) {
|
||||
if ((io_len < 40 /*60*/) && !dev->RCR.runts_ok) {
|
||||
#ifdef ENABLE_DP8390_LOG
|
||||
dp8390_log("DP8390: rejected small packet, length %d\n", io_len);
|
||||
#endif
|
||||
@@ -342,11 +328,11 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
io_len);
|
||||
|
||||
/* Do address filtering if not in promiscuous mode. */
|
||||
if (! dev->RCR.promisc) {
|
||||
if (!dev->RCR.promisc) {
|
||||
/* If this is a broadcast frame.. */
|
||||
if (! memcmp(buf, bcast_addr, 6)) {
|
||||
if (!memcmp(buf, bcast_addr, 6)) {
|
||||
/* Broadcast not enabled, we're done. */
|
||||
if (! dev->RCR.broadcast) {
|
||||
if (!dev->RCR.broadcast) {
|
||||
#ifdef ENABLE_DP8390_LOG
|
||||
dp8390_log("DP8390: RX BC disabled\n");
|
||||
#endif
|
||||
@@ -357,7 +343,7 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
/* If this is a multicast frame.. */
|
||||
else if (buf[0] & 0x01) {
|
||||
/* Multicast not enabled, we're done. */
|
||||
if (! dev->RCR.multicast) {
|
||||
if (!dev->RCR.multicast) {
|
||||
#ifdef ENABLE_DP8390_LOG
|
||||
dp8390_log("DP8390: RX MC disabled\n");
|
||||
#endif
|
||||
@@ -366,7 +352,7 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
|
||||
/* Are we listening to this multicast address? */
|
||||
idx = mcast_index(buf);
|
||||
if (! (dev->mchash[idx>>3] & (1<<(idx&0x7)))) {
|
||||
if (!(dev->mchash[idx >> 3] & (1 << (idx & 0x7)))) {
|
||||
#ifdef ENABLE_DP8390_LOG
|
||||
dp8390_log("DP8390: RX MC not listed\n");
|
||||
#endif
|
||||
@@ -392,22 +378,21 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
if (buf[0] & 0x01)
|
||||
pkthdr[0] |= 0x20; /* MULTICAST packet */
|
||||
pkthdr[1] = nextpage; /* ptr to next packet */
|
||||
pkthdr[2] = (io_len + sizeof(pkthdr))&0xff; /* length-low */
|
||||
pkthdr[3] = (io_len + sizeof(pkthdr))>>8; /* length-hi */
|
||||
pkthdr[2] = (io_len + sizeof(pkthdr)) & 0xff; /* length-low */
|
||||
pkthdr[3] = (io_len + sizeof(pkthdr)) >> 8; /* length-hi */
|
||||
dp8390_log("DP8390: RX pkthdr [%02x %02x %02x %02x]\n",
|
||||
pkthdr[0], pkthdr[1], pkthdr[2], pkthdr[3]);
|
||||
|
||||
/* Copy into buffer, update curpage, and signal interrupt if config'd */
|
||||
startptr = &dev->mem[(dev->curr_page * 256) - dev->mem_start];
|
||||
memcpy(startptr, pkthdr, sizeof(pkthdr));
|
||||
if ((nextpage > dev->curr_page) ||
|
||||
((dev->curr_page + pages) == dev->page_stop)) {
|
||||
memcpy(startptr+sizeof(pkthdr), buf, io_len);
|
||||
if ((nextpage > dev->curr_page) || ((dev->curr_page + pages) == dev->page_stop)) {
|
||||
memcpy(startptr + sizeof(pkthdr), buf, io_len);
|
||||
} else {
|
||||
endbytes = (dev->page_stop - dev->curr_page) * 256;
|
||||
memcpy(startptr+sizeof(pkthdr), buf, endbytes-sizeof(pkthdr));
|
||||
memcpy(startptr + sizeof(pkthdr), buf, endbytes - sizeof(pkthdr));
|
||||
startptr = &dev->mem[(dev->page_start * 256) - dev->mem_start];
|
||||
memcpy(startptr, buf+endbytes-sizeof(pkthdr), io_len-endbytes+8);
|
||||
memcpy(startptr, buf + endbytes - sizeof(pkthdr), io_len - endbytes + 8);
|
||||
}
|
||||
dev->curr_page = nextpage;
|
||||
|
||||
@@ -421,11 +406,10 @@ dp8390_rx_common(void *priv, uint8_t *buf, int io_len)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
dp8390_rx(void *priv, uint8_t *buf, int io_len)
|
||||
{
|
||||
dp8390_t *dev = (dp8390_t *)priv;
|
||||
dp8390_t *dev = (dp8390_t *) priv;
|
||||
|
||||
if ((dev->DCR.loop == 0) || (dev->TCR.loop_cntl != 0))
|
||||
return 0;
|
||||
@@ -433,7 +417,6 @@ dp8390_rx(void *priv, uint8_t *buf, int io_len)
|
||||
return dp8390_rx_common(priv, buf, io_len);
|
||||
}
|
||||
|
||||
|
||||
/* Handle reads/writes to the 'zeroth' page of the DS8390 register file. */
|
||||
uint32_t
|
||||
dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
@@ -444,10 +427,10 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
/* encountered with win98 hardware probe */
|
||||
dp8390_log("DP8390: bad length! Page0 read from register 0x%02x, len=%u\n",
|
||||
off, len);
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x01: /* CLDA0 */
|
||||
retval = (dev->local_dma & 0xff);
|
||||
break;
|
||||
@@ -461,13 +444,7 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
break;
|
||||
|
||||
case 0x04: /* TSR */
|
||||
retval = ((dev->TSR.ow_coll << 7) |
|
||||
(dev->TSR.cd_hbeat << 6) |
|
||||
(dev->TSR.fifo_ur << 5) |
|
||||
(dev->TSR.no_carrier << 4) |
|
||||
(dev->TSR.aborted << 3) |
|
||||
(dev->TSR.collided << 2) |
|
||||
(dev->TSR.tx_ok));
|
||||
retval = ((dev->TSR.ow_coll << 7) | (dev->TSR.cd_hbeat << 6) | (dev->TSR.fifo_ur << 5) | (dev->TSR.no_carrier << 4) | (dev->TSR.aborted << 3) | (dev->TSR.collided << 2) | (dev->TSR.tx_ok));
|
||||
break;
|
||||
|
||||
case 0x05: /* NCR */
|
||||
@@ -483,14 +460,7 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
break;
|
||||
|
||||
case 0x07: /* ISR */
|
||||
retval = ((dev->ISR.reset << 7) |
|
||||
(dev->ISR.rdma_done << 6) |
|
||||
(dev->ISR.cnt_oflow << 5) |
|
||||
(dev->ISR.overwrite << 4) |
|
||||
(dev->ISR.tx_err << 3) |
|
||||
(dev->ISR.rx_err << 2) |
|
||||
(dev->ISR.pkt_tx << 1) |
|
||||
(dev->ISR.pkt_rx));
|
||||
retval = ((dev->ISR.reset << 7) | (dev->ISR.rdma_done << 6) | (dev->ISR.cnt_oflow << 5) | (dev->ISR.overwrite << 4) | (dev->ISR.tx_err << 3) | (dev->ISR.rx_err << 2) | (dev->ISR.pkt_tx << 1) | (dev->ISR.pkt_rx));
|
||||
break;
|
||||
|
||||
case 0x08: /* CRDA0 */
|
||||
@@ -510,14 +480,7 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
break;
|
||||
|
||||
case 0x0c: /* RSR */
|
||||
retval = ((dev->RSR.deferred << 7) |
|
||||
(dev->RSR.rx_disabled << 6) |
|
||||
(dev->RSR.rx_mbit << 5) |
|
||||
(dev->RSR.rx_missed << 4) |
|
||||
(dev->RSR.fifo_or << 3) |
|
||||
(dev->RSR.bad_falign << 2) |
|
||||
(dev->RSR.bad_crc << 1) |
|
||||
(dev->RSR.rx_ok));
|
||||
retval = ((dev->RSR.deferred << 7) | (dev->RSR.rx_disabled << 6) | (dev->RSR.rx_mbit << 5) | (dev->RSR.rx_missed << 4) | (dev->RSR.fifo_or << 3) | (dev->RSR.bad_falign << 2) | (dev->RSR.bad_crc << 1) | (dev->RSR.rx_ok));
|
||||
break;
|
||||
|
||||
case 0x0d: /* CNTR0 */
|
||||
@@ -540,10 +503,9 @@ dp8390_page0_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
dp8390_log("DP8390: Page0 read from register 0x%02x, value=0x%02x\n", off,
|
||||
retval);
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
{
|
||||
@@ -552,7 +514,7 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
dp8390_log("DP839: Page0 write to register 0x%02x, value=0x%02x\n",
|
||||
off, val);
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x01: /* PSTART */
|
||||
dev->page_start = val;
|
||||
dp8390_log("DP8390: Starting RAM address: %04X\n", val << 8);
|
||||
@@ -586,27 +548,15 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
case 0x07: /* ISR */
|
||||
val &= 0x7f; /* clear RST bit - status-only bit */
|
||||
/* All other values are cleared iff the ISR bit is 1 */
|
||||
dev->ISR.pkt_rx &= !((int)((val & 0x01) == 0x01));
|
||||
dev->ISR.pkt_tx &= !((int)((val & 0x02) == 0x02));
|
||||
dev->ISR.rx_err &= !((int)((val & 0x04) == 0x04));
|
||||
dev->ISR.tx_err &= !((int)((val & 0x08) == 0x08));
|
||||
dev->ISR.overwrite &= !((int)((val & 0x10) == 0x10));
|
||||
dev->ISR.cnt_oflow &= !((int)((val & 0x20) == 0x20));
|
||||
dev->ISR.rdma_done &= !((int)((val & 0x40) == 0x40));
|
||||
val = ((dev->ISR.rdma_done << 6) |
|
||||
(dev->ISR.cnt_oflow << 5) |
|
||||
(dev->ISR.overwrite << 4) |
|
||||
(dev->ISR.tx_err << 3) |
|
||||
(dev->ISR.rx_err << 2) |
|
||||
(dev->ISR.pkt_tx << 1) |
|
||||
(dev->ISR.pkt_rx));
|
||||
val &= ((dev->IMR.rdma_inte << 6) |
|
||||
(dev->IMR.cofl_inte << 5) |
|
||||
(dev->IMR.overw_inte << 4) |
|
||||
(dev->IMR.txerr_inte << 3) |
|
||||
(dev->IMR.rxerr_inte << 2) |
|
||||
(dev->IMR.tx_inte << 1) |
|
||||
(dev->IMR.rx_inte));
|
||||
dev->ISR.pkt_rx &= !((int) ((val & 0x01) == 0x01));
|
||||
dev->ISR.pkt_tx &= !((int) ((val & 0x02) == 0x02));
|
||||
dev->ISR.rx_err &= !((int) ((val & 0x04) == 0x04));
|
||||
dev->ISR.tx_err &= !((int) ((val & 0x08) == 0x08));
|
||||
dev->ISR.overwrite &= !((int) ((val & 0x10) == 0x10));
|
||||
dev->ISR.cnt_oflow &= !((int) ((val & 0x20) == 0x20));
|
||||
dev->ISR.rdma_done &= !((int) ((val & 0x40) == 0x40));
|
||||
val = ((dev->ISR.rdma_done << 6) | (dev->ISR.cnt_oflow << 5) | (dev->ISR.overwrite << 4) | (dev->ISR.tx_err << 3) | (dev->ISR.rx_err << 2) | (dev->ISR.pkt_tx << 1) | (dev->ISR.pkt_rx));
|
||||
val &= ((dev->IMR.rdma_inte << 6) | (dev->IMR.cofl_inte << 5) | (dev->IMR.overw_inte << 4) | (dev->IMR.txerr_inte << 3) | (dev->IMR.rxerr_inte << 2) | (dev->IMR.tx_inte << 1) | (dev->IMR.rx_inte));
|
||||
if ((val == 0x00) && dev->interrupt)
|
||||
dev->interrupt(dev->priv, 0);
|
||||
break;
|
||||
@@ -693,7 +643,7 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
case 0x0e: /* DCR */
|
||||
/* the loopback mode is not suppported yet */
|
||||
#ifdef ENABLE_DP8390_LOG
|
||||
if (! (val & 0x08))
|
||||
if (!(val & 0x08))
|
||||
dp8390_log("DP8390: DCR write, loopback mode selected\n");
|
||||
#endif
|
||||
|
||||
@@ -731,13 +681,7 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
dev->IMR.overw_inte = ((val & 0x10) == 0x10);
|
||||
dev->IMR.cofl_inte = ((val & 0x20) == 0x20);
|
||||
dev->IMR.rdma_inte = ((val & 0x40) == 0x40);
|
||||
val2 = ((dev->ISR.rdma_done << 6) |
|
||||
(dev->ISR.cnt_oflow << 5) |
|
||||
(dev->ISR.overwrite << 4) |
|
||||
(dev->ISR.tx_err << 3) |
|
||||
(dev->ISR.rx_err << 2) |
|
||||
(dev->ISR.pkt_tx << 1) |
|
||||
(dev->ISR.pkt_rx));
|
||||
val2 = ((dev->ISR.rdma_done << 6) | (dev->ISR.cnt_oflow << 5) | (dev->ISR.overwrite << 4) | (dev->ISR.tx_err << 3) | (dev->ISR.rx_err << 2) | (dev->ISR.pkt_tx << 1) | (dev->ISR.pkt_rx));
|
||||
if (dev->interrupt) {
|
||||
if (((val & val2) & 0x7f) == 0)
|
||||
dev->interrupt(dev->priv, 0);
|
||||
@@ -752,7 +696,6 @@ dp8390_page0_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Handle reads/writes to the first page of the DS8390 register file. */
|
||||
uint32_t
|
||||
dp8390_page1_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
@@ -760,19 +703,19 @@ dp8390_page1_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
dp8390_log("DP8390: Page1 read from register 0x%02x, len=%u\n",
|
||||
off, len);
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x01: /* PAR0-5 */
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
case 0x04:
|
||||
case 0x05:
|
||||
case 0x06:
|
||||
return(dev->physaddr[off - 1]);
|
||||
return (dev->physaddr[off - 1]);
|
||||
|
||||
case 0x07: /* CURR */
|
||||
dp8390_log("DP8390: returning current page: 0x%02x\n",
|
||||
(dev->curr_page));
|
||||
return(dev->curr_page);
|
||||
return (dev->curr_page);
|
||||
|
||||
case 0x08: /* MAR0-7 */
|
||||
case 0x09:
|
||||
@@ -782,23 +725,22 @@ dp8390_page1_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
case 0x0d:
|
||||
case 0x0e:
|
||||
case 0x0f:
|
||||
return(dev->mchash[off - 8]);
|
||||
return (dev->mchash[off - 8]);
|
||||
|
||||
default:
|
||||
dp8390_log("DP8390: Page1 read register 0x%02x out of range\n",
|
||||
off);
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
{
|
||||
dp8390_log("DP8390: Page1 write to register 0x%02x, len=%u, value=0x%04x\n",
|
||||
off, len, val);
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x01: /* PAR0-5 */
|
||||
case 0x02:
|
||||
case 0x03:
|
||||
@@ -835,7 +777,6 @@ dp8390_page1_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Handle reads/writes to the second page of the DS8390 register file. */
|
||||
uint32_t
|
||||
dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
@@ -843,27 +784,27 @@ dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
dp8390_log("DP8390: Page2 read from register 0x%02x, len=%u\n",
|
||||
off, len);
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x01: /* PSTART */
|
||||
return(dev->page_start);
|
||||
return (dev->page_start);
|
||||
|
||||
case 0x02: /* PSTOP */
|
||||
return(dev->page_stop);
|
||||
return (dev->page_stop);
|
||||
|
||||
case 0x03: /* Remote Next-packet pointer */
|
||||
return(dev->rempkt_ptr);
|
||||
return (dev->rempkt_ptr);
|
||||
|
||||
case 0x04: /* TPSR */
|
||||
return(dev->tx_page_start);
|
||||
return (dev->tx_page_start);
|
||||
|
||||
case 0x05: /* Local Next-packet pointer */
|
||||
return(dev->localpkt_ptr);
|
||||
return (dev->localpkt_ptr);
|
||||
|
||||
case 0x06: /* Address counter (upper) */
|
||||
return(dev->address_cnt >> 8);
|
||||
return (dev->address_cnt >> 8);
|
||||
|
||||
case 0x07: /* Address counter (lower) */
|
||||
return(dev->address_cnt & 0xff);
|
||||
return (dev->address_cnt & 0xff);
|
||||
|
||||
case 0x08: /* Reserved */
|
||||
case 0x09:
|
||||
@@ -871,38 +812,19 @@ dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
case 0x0b:
|
||||
dp8390_log("DP8390: reserved Page2 read - register 0x%02x\n",
|
||||
off);
|
||||
return(0xff);
|
||||
return (0xff);
|
||||
|
||||
case 0x0c: /* RCR */
|
||||
return ((dev->RCR.monitor << 5) |
|
||||
(dev->RCR.promisc << 4) |
|
||||
(dev->RCR.multicast << 3) |
|
||||
(dev->RCR.broadcast << 2) |
|
||||
(dev->RCR.runts_ok << 1) |
|
||||
(dev->RCR.errors_ok));
|
||||
return ((dev->RCR.monitor << 5) | (dev->RCR.promisc << 4) | (dev->RCR.multicast << 3) | (dev->RCR.broadcast << 2) | (dev->RCR.runts_ok << 1) | (dev->RCR.errors_ok));
|
||||
|
||||
case 0x0d: /* TCR */
|
||||
return ((dev->TCR.coll_prio << 4) |
|
||||
(dev->TCR.ext_stoptx << 3) |
|
||||
((dev->TCR.loop_cntl & 0x3) << 1) |
|
||||
(dev->TCR.crc_disable));
|
||||
return ((dev->TCR.coll_prio << 4) | (dev->TCR.ext_stoptx << 3) | ((dev->TCR.loop_cntl & 0x3) << 1) | (dev->TCR.crc_disable));
|
||||
|
||||
case 0x0e: /* DCR */
|
||||
return (((dev->DCR.fifo_size & 0x3) << 5) |
|
||||
(dev->DCR.auto_rx << 4) |
|
||||
(dev->DCR.loop << 3) |
|
||||
(dev->DCR.longaddr << 2) |
|
||||
(dev->DCR.endian << 1) |
|
||||
(dev->DCR.wdsize));
|
||||
return (((dev->DCR.fifo_size & 0x3) << 5) | (dev->DCR.auto_rx << 4) | (dev->DCR.loop << 3) | (dev->DCR.longaddr << 2) | (dev->DCR.endian << 1) | (dev->DCR.wdsize));
|
||||
|
||||
case 0x0f: /* IMR */
|
||||
return ((dev->IMR.rdma_inte << 6) |
|
||||
(dev->IMR.cofl_inte << 5) |
|
||||
(dev->IMR.overw_inte << 4) |
|
||||
(dev->IMR.txerr_inte << 3) |
|
||||
(dev->IMR.rxerr_inte << 2) |
|
||||
(dev->IMR.tx_inte << 1) |
|
||||
(dev->IMR.rx_inte));
|
||||
return ((dev->IMR.rdma_inte << 6) | (dev->IMR.cofl_inte << 5) | (dev->IMR.overw_inte << 4) | (dev->IMR.txerr_inte << 3) | (dev->IMR.rxerr_inte << 2) | (dev->IMR.tx_inte << 1) | (dev->IMR.rx_inte));
|
||||
|
||||
default:
|
||||
dp8390_log("DP8390: Page2 register 0x%02x out of range\n",
|
||||
@@ -910,20 +832,19 @@ dp8390_page2_read(dp8390_t *dev, uint32_t off, unsigned int len)
|
||||
break;
|
||||
}
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
{
|
||||
/* Maybe all writes here should be BX_PANIC()'d, since they
|
||||
/* Maybe all writes here should be BX_PANIC()'d, since they
|
||||
affect internal operation, but let them through for now
|
||||
and print a warning. */
|
||||
dp8390_log("DP8390: Page2 write to register 0x%02x, len=%u, value=0x%04x\n",
|
||||
off, len, val);
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x01: /* CLDA0 */
|
||||
/* Clear out low byte and re-insert */
|
||||
dev->local_dma &= 0xff00;
|
||||
@@ -981,7 +902,6 @@ dp8390_page2_write(dp8390_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_set_defaults(dp8390_t *dev, uint8_t flags)
|
||||
{
|
||||
@@ -990,7 +910,6 @@ dp8390_set_defaults(dp8390_t *dev, uint8_t flags)
|
||||
dev->flags = flags;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_mem_alloc(dp8390_t *dev, uint32_t start, uint32_t size)
|
||||
{
|
||||
@@ -1002,7 +921,6 @@ dp8390_mem_alloc(dp8390_t *dev, uint32_t start, uint32_t size)
|
||||
dp8390_log("DP8390: Mapped %i bytes of memory at address %04X in the address space\n", size, start);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_set_id(dp8390_t *dev, uint8_t id0, uint8_t id1)
|
||||
{
|
||||
@@ -1010,7 +928,6 @@ dp8390_set_id(dp8390_t *dev, uint8_t id0, uint8_t id1)
|
||||
dev->id1 = id1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_reset(dp8390_t *dev)
|
||||
{
|
||||
@@ -1030,7 +947,7 @@ dp8390_reset(dp8390_t *dev)
|
||||
}
|
||||
|
||||
/* Zero out registers and memory */
|
||||
memset(&dev->CR, 0x00, sizeof(dev->CR) );
|
||||
memset(&dev->CR, 0x00, sizeof(dev->CR));
|
||||
memset(&dev->ISR, 0x00, sizeof(dev->ISR));
|
||||
memset(&dev->IMR, 0x00, sizeof(dev->IMR));
|
||||
memset(&dev->DCR, 0x00, sizeof(dev->DCR));
|
||||
@@ -1073,7 +990,6 @@ dp8390_reset(dp8390_t *dev)
|
||||
dev->interrupt(dev->priv, 0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
dp8390_soft_reset(dp8390_t *dev)
|
||||
{
|
||||
@@ -1081,7 +997,6 @@ dp8390_soft_reset(dp8390_t *dev)
|
||||
dev->ISR.reset = 1;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
dp8390_init(const device_t *info)
|
||||
{
|
||||
@@ -1100,7 +1015,6 @@ dp8390_init(const device_t *info)
|
||||
return dp8390;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
dp8390_close(void *priv)
|
||||
{
|
||||
|
@@ -1,16 +1,16 @@
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#include <86box/net_event.h>
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
static void setup_fd(int fd)
|
||||
static void
|
||||
setup_fd(int fd)
|
||||
{
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||
|
@@ -69,7 +69,6 @@
|
||||
#include <86box/bswap.h>
|
||||
#include <86box/isapnp.h>
|
||||
|
||||
|
||||
/* ROM BIOS file paths. */
|
||||
#define ROM_PATH_NE1000 "roms/network/ne1000/ne1000.rom"
|
||||
#define ROM_PATH_NE2000 "roms/network/ne2000/ne2000.rom"
|
||||
@@ -81,7 +80,6 @@
|
||||
#define PCI_DEVID 0x8029 /* RTL8029AS */
|
||||
#define PCI_REGSIZE 256 /* size of PCI space */
|
||||
|
||||
|
||||
static uint8_t rtl8019as_pnp_rom[] = {
|
||||
0x4a, 0x8c, 0x80, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, /* RTL8019, dummy checksum (filled in by isapnp_add_card) */
|
||||
0x0a, 0x10, 0x10, /* PnP version 1.0, vendor version 1.0 */
|
||||
@@ -95,7 +93,6 @@ static uint8_t rtl8019as_pnp_rom[] = {
|
||||
0x79, 0x00 /* end tag, dummy checksum (filled in by isapnp_add_card) */
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
dp8390_t *dp8390;
|
||||
const char *name;
|
||||
@@ -125,7 +122,6 @@ typedef struct {
|
||||
uint8_t pos_regs[8];
|
||||
} nic_t;
|
||||
|
||||
|
||||
#ifdef ENABLE_NE2K_LOG
|
||||
int ne2k_do_log = ENABLE_NE2K_LOG;
|
||||
|
||||
@@ -141,10 +137,9 @@ nelog(int lvl, const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define nelog(lvl, fmt, ...)
|
||||
# define nelog(lvl, fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
nic_interrupt(void *priv, int set)
|
||||
{
|
||||
@@ -157,34 +152,31 @@ nic_interrupt(void *priv, int set)
|
||||
pci_clear_irq(dev->card, PCI_INTA);
|
||||
} else {
|
||||
if (set)
|
||||
picint(1<<dev->base_irq);
|
||||
picint(1 << dev->base_irq);
|
||||
else
|
||||
picintc(1<<dev->base_irq);
|
||||
picintc(1 << dev->base_irq);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* reset - restore state to power-up, cancelling all i/o */
|
||||
static void
|
||||
nic_reset(void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
|
||||
nelog(1, "%s: reset\n", dev->name);
|
||||
|
||||
dp8390_reset(dev->dp8390);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_soft_reset(void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
|
||||
dp8390_soft_reset(dev->dp8390);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Access the ASIC I/O space.
|
||||
*
|
||||
@@ -203,7 +195,7 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len)
|
||||
{
|
||||
uint32_t retval = 0;
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x00: /* Data register */
|
||||
/* A read remote-DMA command must have been issued,
|
||||
and the source-address and length registers must
|
||||
@@ -214,7 +206,7 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len)
|
||||
}
|
||||
|
||||
nelog(3, "%s: DMA read: addr=%4x remote_bytes=%d\n",
|
||||
dev->name, dev->dp8390->remote_dma,dev->dp8390->remote_bytes);
|
||||
dev->name, dev->dp8390->remote_dma, dev->dp8390->remote_bytes);
|
||||
retval = dp8390_chipmem_read(dev->dp8390, dev->dp8390->remote_dma, len);
|
||||
|
||||
/* The 8390 bumps the address and decreases the byte count
|
||||
@@ -255,20 +247,20 @@ asic_read(nic_t *dev, uint32_t off, unsigned int len)
|
||||
|
||||
default:
|
||||
nelog(3, "%s: ASIC read invalid address %04x\n",
|
||||
dev->name, (unsigned)off);
|
||||
dev->name, (unsigned) off);
|
||||
break;
|
||||
}
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
static void
|
||||
asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
{
|
||||
nelog(3, "%s: ASIC write addr=0x%02x, value=0x%04x\n",
|
||||
dev->name, (unsigned)off, (unsigned) val);
|
||||
dev->name, (unsigned) off, (unsigned) val);
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x00: /* Data register - see asic_read for a description */
|
||||
if ((len > 1) && (dev->dp8390->DCR.wdsize == 0)) {
|
||||
nelog(3, "%s: DMA write length %d on byte mode operation\n",
|
||||
@@ -309,40 +301,40 @@ asic_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
|
||||
default: /* this is invalid, but happens under win95 device detection */
|
||||
nelog(3, "%s: ASIC write invalid address %04x, ignoring\n",
|
||||
dev->name, (unsigned)off);
|
||||
dev->name, (unsigned) off);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Writes to this page are illegal. */
|
||||
static uint32_t
|
||||
page3_read(nic_t *dev, uint32_t off, unsigned int len)
|
||||
{
|
||||
if (dev->board >= NE2K_RTL8019AS) switch(off) {
|
||||
if (dev->board >= NE2K_RTL8019AS)
|
||||
switch (off) {
|
||||
case 0x1: /* 9346CR */
|
||||
return(dev->_9346cr);
|
||||
return (dev->_9346cr);
|
||||
|
||||
case 0x3: /* CONFIG0 */
|
||||
return(0x00); /* Cable not BNC */
|
||||
return (0x00); /* Cable not BNC */
|
||||
|
||||
case 0x5: /* CONFIG2 */
|
||||
return(dev->config2 & 0xe0);
|
||||
return (dev->config2 & 0xe0);
|
||||
|
||||
case 0x6: /* CONFIG3 */
|
||||
return(dev->config3 & 0x46);
|
||||
return (dev->config3 & 0x46);
|
||||
|
||||
case 0x8: /* CSNSAV */
|
||||
return((dev->board == NE2K_RTL8019AS) ? dev->pnp_csnsav : 0x00);
|
||||
return ((dev->board == NE2K_RTL8019AS) ? dev->pnp_csnsav : 0x00);
|
||||
|
||||
case 0xe: /* 8029ASID0 */
|
||||
if (dev->board == NE2K_RTL8029AS)
|
||||
return(0x29);
|
||||
return (0x29);
|
||||
break;
|
||||
|
||||
case 0xf: /* 8029ASID1 */
|
||||
if (dev->board == NE2K_RTL8029AS)
|
||||
return(0x80);
|
||||
return (0x80);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -350,10 +342,9 @@ page3_read(nic_t *dev, uint32_t off, unsigned int len)
|
||||
}
|
||||
|
||||
nelog(3, "%s: Page3 read register 0x%02x attempted\n", dev->name, off);
|
||||
return(0x00);
|
||||
return (0x00);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
{
|
||||
@@ -361,7 +352,7 @@ page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
nelog(3, "%s: Page2 write to register 0x%02x, len=%u, value=0x%04x\n",
|
||||
dev->name, off, len, val);
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x01: /* 9346CR */
|
||||
dev->_9346cr = (val & 0xfe);
|
||||
break;
|
||||
@@ -386,7 +377,6 @@ page3_write(nic_t *dev, uint32_t off, uint32_t val, unsigned len)
|
||||
nelog(3, "%s: Page3 write register 0x%02x attempted\n", dev->name, off);
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
nic_read(nic_t *dev, uint32_t addr, unsigned len)
|
||||
{
|
||||
@@ -399,7 +389,8 @@ nic_read(nic_t *dev, uint32_t addr, unsigned len)
|
||||
retval = asic_read(dev, off - 0x10, len);
|
||||
else if (off == 0x00)
|
||||
retval = dp8390_read_cr(dev->dp8390);
|
||||
else switch(dev->dp8390->CR.pgsel) {
|
||||
else
|
||||
switch (dev->dp8390->CR.pgsel) {
|
||||
case 0x00:
|
||||
retval = dp8390_page0_read(dev->dp8390, off, len);
|
||||
break;
|
||||
@@ -418,31 +409,27 @@ nic_read(nic_t *dev, uint32_t addr, unsigned len)
|
||||
break;
|
||||
}
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
nic_readb(uint16_t addr, void *priv)
|
||||
{
|
||||
return(nic_read((nic_t *)priv, addr, 1));
|
||||
return (nic_read((nic_t *) priv, addr, 1));
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
nic_readw(uint16_t addr, void *priv)
|
||||
{
|
||||
return(nic_read((nic_t *)priv, addr, 2));
|
||||
return (nic_read((nic_t *) priv, addr, 2));
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
nic_readl(uint16_t addr, void *priv)
|
||||
{
|
||||
return(nic_read((nic_t *)priv, addr, 4));
|
||||
return (nic_read((nic_t *) priv, addr, 4));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len)
|
||||
{
|
||||
@@ -458,7 +445,8 @@ nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len)
|
||||
asic_write(dev, off - 0x10, val, len);
|
||||
else if (off == 0x00)
|
||||
dp8390_write_cr(dev->dp8390, val);
|
||||
else switch(dev->dp8390->CR.pgsel) {
|
||||
else
|
||||
switch (dev->dp8390->CR.pgsel) {
|
||||
case 0x00:
|
||||
dp8390_page0_write(dev->dp8390, off, val, len);
|
||||
break;
|
||||
@@ -478,32 +466,27 @@ nic_write(nic_t *dev, uint32_t addr, uint32_t val, unsigned len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_writeb(uint16_t addr, uint8_t val, void *priv)
|
||||
{
|
||||
nic_write((nic_t *)priv, addr, val, 1);
|
||||
nic_write((nic_t *) priv, addr, val, 1);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_writew(uint16_t addr, uint16_t val, void *priv)
|
||||
{
|
||||
nic_write((nic_t *)priv, addr, val, 2);
|
||||
nic_write((nic_t *) priv, addr, val, 2);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_writel(uint16_t addr, uint32_t val, void *priv)
|
||||
{
|
||||
nic_write((nic_t *)priv, addr, val, 4);
|
||||
nic_write((nic_t *) priv, addr, val, 4);
|
||||
}
|
||||
|
||||
|
||||
static void nic_ioset(nic_t *dev, uint16_t addr);
|
||||
static void nic_ioremove(nic_t *dev, uint16_t addr);
|
||||
|
||||
|
||||
static void
|
||||
nic_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv)
|
||||
{
|
||||
@@ -524,7 +507,6 @@ nic_pnp_config_changed(uint8_t ld, isapnp_device_config_t *config, void *priv)
|
||||
nic_ioset(dev, dev->base_address);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_pnp_csn_changed(uint8_t csn, void *priv)
|
||||
{
|
||||
@@ -533,7 +515,6 @@ nic_pnp_csn_changed(uint8_t csn, void *priv)
|
||||
dev->pnp_csnsav = csn;
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
nic_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv)
|
||||
{
|
||||
@@ -559,7 +540,6 @@ nic_pnp_read_vendor_reg(uint8_t ld, uint8_t reg, void *priv)
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_pnp_write_vendor_reg(uint8_t ld, uint8_t reg, uint8_t val, void *priv)
|
||||
{
|
||||
@@ -572,7 +552,6 @@ nic_pnp_write_vendor_reg(uint8_t ld, uint8_t reg, uint8_t val, void *priv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_ioset(nic_t *dev, uint16_t addr)
|
||||
{
|
||||
@@ -585,18 +564,17 @@ nic_ioset(nic_t *dev, uint16_t addr)
|
||||
nic_readb, NULL, NULL,
|
||||
nic_writeb, NULL, NULL, dev);
|
||||
if (dev->is_8bit) {
|
||||
io_sethandler(addr+16, 16,
|
||||
io_sethandler(addr + 16, 16,
|
||||
nic_readb, NULL, NULL,
|
||||
nic_writeb, NULL, NULL, dev);
|
||||
} else {
|
||||
io_sethandler(addr+16, 16,
|
||||
io_sethandler(addr + 16, 16,
|
||||
nic_readb, nic_readw, NULL,
|
||||
nic_writeb, nic_writew, NULL, dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_ioremove(nic_t *dev, uint16_t addr)
|
||||
{
|
||||
@@ -609,18 +587,17 @@ nic_ioremove(nic_t *dev, uint16_t addr)
|
||||
nic_readb, NULL, NULL,
|
||||
nic_writeb, NULL, NULL, dev);
|
||||
if (dev->is_8bit) {
|
||||
io_removehandler(addr+16, 16,
|
||||
io_removehandler(addr + 16, 16,
|
||||
nic_readb, NULL, NULL,
|
||||
nic_writeb, NULL, NULL, dev);
|
||||
} else {
|
||||
io_removehandler(addr+16, 16,
|
||||
io_removehandler(addr + 16, 16,
|
||||
nic_readb, nic_readw, NULL,
|
||||
nic_writeb, nic_writew, NULL, dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_update_bios(nic_t *dev)
|
||||
{
|
||||
@@ -628,7 +605,8 @@ nic_update_bios(nic_t *dev)
|
||||
|
||||
reg_bios_enable = 1;
|
||||
|
||||
if (! dev->has_bios) return;
|
||||
if (!dev->has_bios)
|
||||
return;
|
||||
|
||||
if (dev->is_pci)
|
||||
reg_bios_enable = dev->pci_bar[1].addr_regs[0] & 0x01;
|
||||
@@ -644,14 +622,13 @@ nic_update_bios(nic_t *dev)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
nic_pci_read(int func, int addr, void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
uint8_t ret = 0x00;
|
||||
|
||||
switch(addr) {
|
||||
switch (addr) {
|
||||
case 0x00: /* PCI_VID_LO */
|
||||
case 0x01: /* PCI_VID_HI */
|
||||
ret = dev->pci_regs[addr];
|
||||
@@ -734,26 +711,23 @@ nic_pci_read(int func, int addr, void *priv)
|
||||
|
||||
nelog(2, "%s: PCI_Read(%d, %04x) = %02x\n", dev->name, func, addr, ret);
|
||||
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_pci_write(int func, int addr, uint8_t val, void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
uint8_t valxor;
|
||||
|
||||
nelog(2, "%s: PCI_Write(%d, %04x, %02x)\n", dev->name, func, addr, val);
|
||||
|
||||
switch(addr) {
|
||||
switch (addr) {
|
||||
case 0x04: /* PCI_COMMAND_LO */
|
||||
valxor = (val & 0x03) ^ dev->pci_regs[addr];
|
||||
if (valxor & PCI_COMMAND_IO)
|
||||
{
|
||||
if (valxor & PCI_COMMAND_IO) {
|
||||
nic_ioremove(dev, dev->base_address);
|
||||
if ((dev->base_address != 0) && (val & PCI_COMMAND_IO))
|
||||
{
|
||||
if ((dev->base_address != 0) && (val & PCI_COMMAND_IO)) {
|
||||
nic_ioset(dev, dev->base_address);
|
||||
}
|
||||
}
|
||||
@@ -781,10 +755,8 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv)
|
||||
nelog(1, "%s: PCI: new I/O base is %04X\n",
|
||||
dev->name, dev->base_address);
|
||||
/* We're done, so get out of the here. */
|
||||
if (dev->pci_regs[4] & PCI_COMMAND_IO)
|
||||
{
|
||||
if (dev->base_address != 0)
|
||||
{
|
||||
if (dev->pci_regs[4] & PCI_COMMAND_IO) {
|
||||
if (dev->base_address != 0) {
|
||||
nic_ioset(dev, dev->base_address);
|
||||
}
|
||||
}
|
||||
@@ -809,16 +781,17 @@ nic_pci_write(int func, int addr, uint8_t val, void *priv)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_rom_init(nic_t *dev, char *s)
|
||||
{
|
||||
uint32_t temp;
|
||||
FILE *f;
|
||||
|
||||
if (s == NULL) return;
|
||||
if (s == NULL)
|
||||
return;
|
||||
|
||||
if (dev->bios_addr == 0) return;
|
||||
if (dev->bios_addr == 0)
|
||||
return;
|
||||
|
||||
if ((f = rom_fopen(s, "rb")) != NULL) {
|
||||
fseek(f, 0L, SEEK_END);
|
||||
@@ -841,7 +814,7 @@ nic_rom_init(nic_t *dev, char *s)
|
||||
|
||||
/* Create a memory mapping for the space. */
|
||||
rom_init(&dev->bios_rom, s, dev->bios_addr,
|
||||
dev->bios_size, dev->bios_size-1, 0, MEM_MAPPING_EXTERNAL);
|
||||
dev->bios_size, dev->bios_size - 1, 0, MEM_MAPPING_EXTERNAL);
|
||||
|
||||
nelog(1, "%s: BIOS configured at %06lX (size %ld)\n",
|
||||
dev->name, dev->bios_addr, dev->bios_size);
|
||||
@@ -850,25 +823,32 @@ nic_rom_init(nic_t *dev, char *s)
|
||||
static uint8_t
|
||||
nic_mca_read(int port, void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
|
||||
return(dev->pos_regs[port & 7]);
|
||||
return (dev->pos_regs[port & 7]);
|
||||
}
|
||||
|
||||
#define MCA_611F_IO_PORTS { 0x300, 0x340, 0x320, 0x360, 0x1300, 0x1340, \
|
||||
0x1320, 0x1360 }
|
||||
#define MCA_611F_IO_PORTS \
|
||||
{ \
|
||||
0x300, 0x340, 0x320, 0x360, 0x1300, 0x1340, \
|
||||
0x1320, 0x1360 \
|
||||
}
|
||||
|
||||
#define MCA_611F_IRQS { 2, 3, 4, 5, 10, 11, 12, 15 }
|
||||
#define MCA_611F_IRQS \
|
||||
{ \
|
||||
2, 3, 4, 5, 10, 11, 12, 15 \
|
||||
}
|
||||
|
||||
static void
|
||||
nic_mca_write(int port, uint8_t val, void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
uint16_t base[] = MCA_611F_IO_PORTS;
|
||||
int8_t irq[] = MCA_611F_IRQS;
|
||||
|
||||
/* MCA does not write registers below 0x0100. */
|
||||
if (port < 0x0102) return;
|
||||
if (port < 0x0102)
|
||||
return;
|
||||
|
||||
/* Save the MCA register value. */
|
||||
dev->pos_regs[port & 7] = val;
|
||||
@@ -902,20 +882,17 @@ nic_mca_write(int port, uint8_t val, void *priv)
|
||||
nic_reset(dev);
|
||||
|
||||
nelog(2, "EtherNext/MC: Port=%04x, IRQ=%d\n", dev->base_address, dev->base_irq);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
nic_mca_feedb(void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
|
||||
return (dev->pos_regs[2] & 0x01);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
nic_init(const device_t *info)
|
||||
{
|
||||
@@ -950,8 +927,7 @@ nic_init(const device_t *info)
|
||||
dev->bios_addr = 0x00000;
|
||||
dev->has_bios = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
mca_add(nic_mca_read, nic_mca_write, nic_mca_feedb, NULL, dev);
|
||||
}
|
||||
}
|
||||
@@ -970,8 +946,8 @@ nic_init(const device_t *info)
|
||||
mac |= ((int) dev->maclocal[5]);
|
||||
device_set_config_mac("mac", mac);
|
||||
} else {
|
||||
dev->maclocal[3] = (mac>>16) & 0xff;
|
||||
dev->maclocal[4] = (mac>>8) & 0xff;
|
||||
dev->maclocal[3] = (mac >> 16) & 0xff;
|
||||
dev->maclocal[4] = (mac >> 8) & 0xff;
|
||||
dev->maclocal[5] = (mac & 0xff);
|
||||
}
|
||||
|
||||
@@ -979,7 +955,7 @@ nic_init(const device_t *info)
|
||||
dev->dp8390->priv = dev;
|
||||
dev->dp8390->interrupt = nic_interrupt;
|
||||
|
||||
switch(dev->board) {
|
||||
switch (dev->board) {
|
||||
case NE2K_NE1000:
|
||||
dev->maclocal[0] = 0x00; /* 00:00:D8 (Novell OID) */
|
||||
dev->maclocal[1] = 0x00;
|
||||
@@ -995,8 +971,7 @@ nic_init(const device_t *info)
|
||||
dev->maclocal[1] = 0x00;
|
||||
dev->maclocal[2] = 0xD8;
|
||||
rom = ROM_PATH_NE2000;
|
||||
dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CHECK_CR |
|
||||
DP8390_FLAG_CLEAR_IRQ);
|
||||
dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CHECK_CR | DP8390_FLAG_CLEAR_IRQ);
|
||||
dp8390_mem_alloc(dev->dp8390, 0x4000, 0x4000);
|
||||
break;
|
||||
|
||||
@@ -1007,8 +982,7 @@ nic_init(const device_t *info)
|
||||
dev->pos_regs[0] = 0x1F;
|
||||
dev->pos_regs[1] = 0x61;
|
||||
rom = NULL;
|
||||
dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CHECK_CR |
|
||||
DP8390_FLAG_CLEAR_IRQ);
|
||||
dp8390_set_defaults(dev->dp8390, DP8390_FLAG_EVEN_MAC | DP8390_FLAG_CHECK_CR | DP8390_FLAG_CLEAR_IRQ);
|
||||
dp8390_mem_alloc(dev->dp8390, 0x4000, 0x4000);
|
||||
break;
|
||||
|
||||
@@ -1054,10 +1028,10 @@ nic_init(const device_t *info)
|
||||
*/
|
||||
memset(dev->pci_regs, 0, PCI_REGSIZE);
|
||||
|
||||
dev->pci_regs[0x00] = (PCI_VENDID&0xff);
|
||||
dev->pci_regs[0x01] = (PCI_VENDID>>8);
|
||||
dev->pci_regs[0x02] = (PCI_DEVID&0xff);
|
||||
dev->pci_regs[0x03] = (PCI_DEVID>>8);
|
||||
dev->pci_regs[0x00] = (PCI_VENDID & 0xff);
|
||||
dev->pci_regs[0x01] = (PCI_VENDID >> 8);
|
||||
dev->pci_regs[0x02] = (PCI_DEVID & 0xff);
|
||||
dev->pci_regs[0x03] = (PCI_DEVID >> 8);
|
||||
|
||||
dev->pci_regs[0x04] = 0x03; /* IOEN */
|
||||
dev->pci_regs[0x05] = 0x00;
|
||||
@@ -1068,10 +1042,10 @@ nic_init(const device_t *info)
|
||||
dev->pci_regs[0x0B] = 0x02; /* BCR: Network Controller */
|
||||
dev->pci_regs[0x0A] = 0x00; /* SCR: Ethernet */
|
||||
|
||||
dev->pci_regs[0x2C] = (PCI_VENDID&0xff);
|
||||
dev->pci_regs[0x2D] = (PCI_VENDID>>8);
|
||||
dev->pci_regs[0x2E] = (PCI_DEVID&0xff);
|
||||
dev->pci_regs[0x2F] = (PCI_DEVID>>8);
|
||||
dev->pci_regs[0x2C] = (PCI_VENDID & 0xff);
|
||||
dev->pci_regs[0x2D] = (PCI_VENDID >> 8);
|
||||
dev->pci_regs[0x2E] = (PCI_DEVID & 0xff);
|
||||
dev->pci_regs[0x2F] = (PCI_DEVID >> 8);
|
||||
|
||||
dev->pci_regs[0x3D] = PCI_INTA; /* PCI_IPR */
|
||||
|
||||
@@ -1100,16 +1074,10 @@ nic_init(const device_t *info)
|
||||
if (dev->board == NE2K_RTL8029AS) {
|
||||
memcpy(&dev->eeprom[0x02], dev->maclocal, 6);
|
||||
|
||||
dev->eeprom[0x76] =
|
||||
dev->eeprom[0x7A] =
|
||||
dev->eeprom[0x7E] = (PCI_DEVID&0xff);
|
||||
dev->eeprom[0x77] =
|
||||
dev->eeprom[0x7B] =
|
||||
dev->eeprom[0x7F] = (PCI_DEVID>>8);
|
||||
dev->eeprom[0x78] =
|
||||
dev->eeprom[0x7C] = (PCI_VENDID&0xff);
|
||||
dev->eeprom[0x79] =
|
||||
dev->eeprom[0x7D] = (PCI_VENDID>>8);
|
||||
dev->eeprom[0x76] = dev->eeprom[0x7A] = dev->eeprom[0x7E] = (PCI_DEVID & 0xff);
|
||||
dev->eeprom[0x77] = dev->eeprom[0x7B] = dev->eeprom[0x7F] = (PCI_DEVID >> 8);
|
||||
dev->eeprom[0x78] = dev->eeprom[0x7C] = (PCI_VENDID & 0xff);
|
||||
dev->eeprom[0x79] = dev->eeprom[0x7D] = (PCI_VENDID >> 8);
|
||||
} else {
|
||||
memcpy(&dev->eeprom[0x12], rtl8019as_pnp_rom, sizeof(rtl8019as_pnp_rom));
|
||||
|
||||
@@ -1125,16 +1093,15 @@ nic_init(const device_t *info)
|
||||
dev->dp8390->card = network_attach(dev->dp8390, dev->dp8390->physaddr, dp8390_rx, NULL);
|
||||
|
||||
nelog(1, "%s: %s attached IO=0x%X IRQ=%d\n", dev->name,
|
||||
dev->is_pci?"PCI":"ISA", dev->base_address, dev->base_irq);
|
||||
dev->is_pci ? "PCI" : "ISA", dev->base_address, dev->base_irq);
|
||||
|
||||
return(dev);
|
||||
return (dev);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
nic_close(void *priv)
|
||||
{
|
||||
nic_t *dev = (nic_t *)priv;
|
||||
nic_t *dev = (nic_t *) priv;
|
||||
|
||||
nelog(1, "%s: closed\n", dev->name);
|
||||
|
||||
|
@@ -52,14 +52,14 @@
|
||||
#include <wchar.h>
|
||||
#include <stdbool.h>
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <winsock2.h>
|
||||
#else
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/select.h>
|
||||
# include <poll.h>
|
||||
# include <unistd.h>
|
||||
# include <fcntl.h>
|
||||
# include <sys/select.h>
|
||||
#endif
|
||||
|
||||
#define HAVE_STDARG_H
|
||||
@@ -82,7 +82,7 @@ enum {
|
||||
};
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <pcap/pcap.h>
|
||||
# include <pcap/pcap.h>
|
||||
#else
|
||||
typedef int bpf_int32;
|
||||
typedef unsigned int bpf_u_int32;
|
||||
@@ -107,7 +107,7 @@ struct bpf_program {
|
||||
|
||||
typedef struct pcap_if pcap_if_t;
|
||||
|
||||
#define PCAP_ERRBUF_SIZE 256
|
||||
# define PCAP_ERRBUF_SIZE 256
|
||||
|
||||
struct pcap_pkthdr {
|
||||
struct timeval ts;
|
||||
@@ -158,21 +158,21 @@ static volatile void *libpcap_handle; /* handle to WinPcap DLL */
|
||||
|
||||
/* Pointers to the real functions. */
|
||||
static const char *(*f_pcap_lib_version)(void);
|
||||
static int (*f_pcap_findalldevs)(pcap_if_t **,char *);
|
||||
static int (*f_pcap_findalldevs)(pcap_if_t **, char *);
|
||||
static void (*f_pcap_freealldevs)(void *);
|
||||
static void *(*f_pcap_open_live)(const char *,int,int,int,char *);
|
||||
static int (*f_pcap_compile)(void *,void *, const char *,int,bpf_u_int32);
|
||||
static int (*f_pcap_setfilter)(void *,void *);
|
||||
static void *(*f_pcap_open_live)(const char *, int, int, int, char *);
|
||||
static int (*f_pcap_compile)(void *, void *, const char *, int, bpf_u_int32);
|
||||
static int (*f_pcap_setfilter)(void *, void *);
|
||||
static const unsigned char
|
||||
*(*f_pcap_next)(void *,void *);
|
||||
static int (*f_pcap_sendpacket)(void *,const unsigned char *,int);
|
||||
*(*f_pcap_next)(void *, void *);
|
||||
static int (*f_pcap_sendpacket)(void *, const unsigned char *, int);
|
||||
static void (*f_pcap_close)(void *);
|
||||
static int (*f_pcap_setnonblock)(void*, int, char*);
|
||||
static int (*f_pcap_setnonblock)(void *, int, char *);
|
||||
static int (*f_pcap_set_immediate_mode)(void *, int);
|
||||
static int (*f_pcap_set_promisc)(void *, int);
|
||||
static int (*f_pcap_set_snaplen)(void *, int);
|
||||
static int (*f_pcap_dispatch)(void *, int, pcap_handler callback, u_char *user);
|
||||
static void *(*f_pcap_create)(const char *, char*);
|
||||
static void *(*f_pcap_create)(const char *, char *);
|
||||
static int (*f_pcap_activate)(void *);
|
||||
static void *(*f_pcap_geterr)(void *);
|
||||
#ifdef _WIN32
|
||||
@@ -186,7 +186,7 @@ static int (*f_pcap_get_selectable_fd)(void *);
|
||||
#endif
|
||||
|
||||
static dllimp_t pcap_imports[] = {
|
||||
{ "pcap_lib_version", &f_pcap_lib_version },
|
||||
{"pcap_lib_version", &f_pcap_lib_version },
|
||||
{ "pcap_findalldevs", &f_pcap_findalldevs },
|
||||
{ "pcap_freealldevs", &f_pcap_freealldevs },
|
||||
{ "pcap_open_live", &f_pcap_open_live },
|
||||
@@ -230,14 +230,13 @@ pcap_log(const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define pcap_log(fmt, ...)
|
||||
# define pcap_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
net_pcap_rx_handler(uint8_t *user, const struct pcap_pkthdr *h, const uint8_t *bytes)
|
||||
{
|
||||
net_pcap_t *pcap = (net_pcap_t*)user;
|
||||
net_pcap_t *pcap = (net_pcap_t *) user;
|
||||
memcpy(pcap->pkt.data, bytes, h->caplen);
|
||||
pcap->pkt.len = h->caplen;
|
||||
network_rx_put_pkt(pcap->card, &pcap->pkt);
|
||||
@@ -250,13 +249,13 @@ net_pcap_in(void *pcap, uint8_t *bufp, int len)
|
||||
if (pcap == NULL)
|
||||
return;
|
||||
|
||||
f_pcap_sendpacket((void *)pcap, bufp, len);
|
||||
f_pcap_sendpacket((void *) pcap, bufp, len);
|
||||
}
|
||||
|
||||
void
|
||||
net_pcap_in_available(void *priv)
|
||||
{
|
||||
net_pcap_t *pcap = (net_pcap_t *)priv;
|
||||
net_pcap_t *pcap = (net_pcap_t *) priv;
|
||||
net_event_set(&pcap->tx_event);
|
||||
}
|
||||
|
||||
@@ -264,14 +263,14 @@ net_pcap_in_available(void *priv)
|
||||
static void
|
||||
net_pcap_thread(void *priv)
|
||||
{
|
||||
net_pcap_t *pcap = (net_pcap_t*)priv;
|
||||
net_pcap_t *pcap = (net_pcap_t *) priv;
|
||||
|
||||
pcap_log("PCAP: polling started.\n");
|
||||
|
||||
HANDLE events[NET_EVENT_MAX];
|
||||
events[NET_EVENT_STOP] = net_event_get_handle(&pcap->stop_event);
|
||||
events[NET_EVENT_TX] = net_event_get_handle(&pcap->tx_event);
|
||||
events[NET_EVENT_RX] = f_pcap_getevent((void *)pcap->pcap);
|
||||
events[NET_EVENT_RX] = f_pcap_getevent((void *) pcap->pcap);
|
||||
|
||||
bool run = true;
|
||||
|
||||
@@ -297,7 +296,7 @@ net_pcap_thread(void *priv)
|
||||
break;
|
||||
|
||||
case NET_EVENT_RX:
|
||||
f_pcap_dispatch(pcap->pcap, PCAP_PKT_BATCH, net_pcap_rx_handler, (u_char *)pcap);
|
||||
f_pcap_dispatch(pcap->pcap, PCAP_PKT_BATCH, net_pcap_rx_handler, (u_char *) pcap);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -308,7 +307,7 @@ net_pcap_thread(void *priv)
|
||||
static void
|
||||
net_pcap_thread(void *priv)
|
||||
{
|
||||
net_pcap_t *pcap = (net_pcap_t*)priv;
|
||||
net_pcap_t *pcap = (net_pcap_t *) priv;
|
||||
|
||||
pcap_log("PCAP: polling started.\n");
|
||||
|
||||
@@ -341,9 +340,8 @@ net_pcap_thread(void *priv)
|
||||
}
|
||||
|
||||
if (pfd[NET_EVENT_RX].revents & POLLIN) {
|
||||
f_pcap_dispatch(pcap->pcap, PCAP_PKT_BATCH, net_pcap_rx_handler, (u_char *)pcap);
|
||||
f_pcap_dispatch(pcap->pcap, PCAP_PKT_BATCH, net_pcap_rx_handler, (u_char *) pcap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
pcap_log("PCAP: polling stopped.\n");
|
||||
@@ -374,16 +372,16 @@ net_pcap_prepare(netdev_t *list)
|
||||
#endif
|
||||
if (libpcap_handle == NULL) {
|
||||
pcap_log("PCAP: error loading pcap module\n");
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Retrieve the device list from the local machine */
|
||||
if (f_pcap_findalldevs(&devlist, errbuf) == -1) {
|
||||
pcap_log("PCAP: error in pcap_findalldevs: %s\n", errbuf);
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (dev=devlist; dev!=NULL; dev=dev->next) {
|
||||
for (dev = devlist; dev != NULL; dev = dev->next) {
|
||||
if (i >= (NET_HOST_INTF_MAX - 1))
|
||||
break;
|
||||
|
||||
@@ -402,16 +400,16 @@ net_pcap_prepare(netdev_t *list)
|
||||
strncpy(list->description, dev->name, sizeof(list->description) - 1);
|
||||
}
|
||||
|
||||
list++; i++;
|
||||
list++;
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Release the memory. */
|
||||
f_pcap_freealldevs(devlist);
|
||||
|
||||
return(i);
|
||||
return (i);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize (Win)Pcap for use.
|
||||
*
|
||||
@@ -427,7 +425,7 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv)
|
||||
char filter_exp[255];
|
||||
struct bpf_program fp;
|
||||
|
||||
char *intf_name = (char*)priv;
|
||||
char *intf_name = (char *) priv;
|
||||
|
||||
/* Did we already load the library? */
|
||||
if (libpcap_handle == NULL) {
|
||||
@@ -451,7 +449,7 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv)
|
||||
pcap_log("PCAP: interface: %s\n", intf_name);
|
||||
|
||||
net_pcap_t *pcap = calloc(1, sizeof(net_pcap_t));
|
||||
pcap->card = (netcard_t *)card;
|
||||
pcap->card = (netcard_t *) card;
|
||||
memcpy(pcap->mac_addr, mac_addr, sizeof(pcap->mac_addr));
|
||||
|
||||
if ((pcap->pcap = f_pcap_create(intf_name, errbuf)) == NULL) {
|
||||
@@ -494,7 +492,7 @@ net_pcap_init(const netcard_t *card, const uint8_t *mac_addr, void *priv)
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
pcap_log("PCAP: could not compile filter (%s) : %s!\n", filter_exp, f_pcap_geterr((void*)pcap->pcap));
|
||||
pcap_log("PCAP: could not compile filter (%s) : %s!\n", filter_exp, f_pcap_geterr((void *) pcap->pcap));
|
||||
f_pcap_close((void *) pcap->pcap);
|
||||
free(pcap);
|
||||
return NULL;
|
||||
@@ -523,7 +521,7 @@ net_pcap_close(void *priv)
|
||||
if (!priv)
|
||||
return;
|
||||
|
||||
net_pcap_t *pcap = (net_pcap_t *)priv;
|
||||
net_pcap_t *pcap = (net_pcap_t *) priv;
|
||||
|
||||
pcap_log("PCAP: closing.\n");
|
||||
|
||||
@@ -541,10 +539,10 @@ net_pcap_close(void *priv)
|
||||
free(pcap->pkt.data);
|
||||
|
||||
#ifdef _WIN32
|
||||
f_pcap_sendqueue_destroy((void*)pcap->pcap_queue);
|
||||
f_pcap_sendqueue_destroy((void *) pcap->pcap_queue);
|
||||
#endif
|
||||
/* OK, now shut down Pcap itself. */
|
||||
f_pcap_close((void*)pcap->pcap);
|
||||
f_pcap_close((void *) pcap->pcap);
|
||||
|
||||
net_event_close(&pcap->tx_event);
|
||||
net_event_close(&pcap->stop_event);
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -36,7 +36,6 @@
|
||||
#include <86box/network.h>
|
||||
#include <86box/net_plip.h>
|
||||
|
||||
|
||||
enum {
|
||||
PLIP_START = 0x00,
|
||||
PLIP_TX_LEN_LSB_LOW = 0x10,
|
||||
@@ -75,12 +74,10 @@ typedef struct
|
||||
netcard_t *card;
|
||||
} plip_t;
|
||||
|
||||
|
||||
static void plip_receive_packet(plip_t *dev);
|
||||
|
||||
plip_t *instance;
|
||||
|
||||
|
||||
#ifdef ENABLE_PLIP_LOG
|
||||
int plip_do_log = ENABLE_PLIP_LOG;
|
||||
|
||||
@@ -96,10 +93,9 @@ plip_log(uint8_t lvl, const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define plip_log(lvl, fmt, ...)
|
||||
# define plip_log(lvl, fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
timeout_timer(void *priv)
|
||||
{
|
||||
@@ -123,7 +119,6 @@ timeout_timer(void *priv)
|
||||
timer_disable(&dev->timeout_timer);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
plip_write_data(uint8_t val, void *priv)
|
||||
{
|
||||
@@ -345,7 +340,6 @@ plip_write_data(uint8_t val, void *priv)
|
||||
timer_set_delay_u64(&dev->timeout_timer, 1000000 * TIMER_USEC);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
plip_write_ctrl(uint8_t val, void *priv)
|
||||
{
|
||||
@@ -359,7 +353,6 @@ plip_write_ctrl(uint8_t val, void *priv)
|
||||
timer_set_delay_u64(&dev->rx_timer, ISACONST);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
plip_read_status(void *priv)
|
||||
{
|
||||
@@ -370,7 +363,6 @@ plip_read_status(void *priv)
|
||||
return dev->status;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
plip_receive_packet(plip_t *dev)
|
||||
{
|
||||
@@ -403,7 +395,6 @@ plip_receive_packet(plip_t *dev)
|
||||
lpt_irq(dev->lpt, 1);
|
||||
}
|
||||
|
||||
|
||||
/* This timer defers a call to plip_receive_packet to
|
||||
the next ISA clock, in order to avoid IRQ weirdness. */
|
||||
static void
|
||||
@@ -416,7 +407,6 @@ rx_timer(void *priv)
|
||||
timer_disable(&dev->rx_timer);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
plip_rx(void *priv, uint8_t *buf, int io_len)
|
||||
{
|
||||
@@ -442,7 +432,6 @@ plip_rx(void *priv, uint8_t *buf, int io_len)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
plip_lpt_init(void *lpt)
|
||||
{
|
||||
@@ -464,7 +453,6 @@ plip_lpt_init(void *lpt)
|
||||
return dev;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
plip_net_init(const device_t *info)
|
||||
{
|
||||
@@ -481,7 +469,6 @@ plip_net_init(const device_t *info)
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
plip_close(void *priv)
|
||||
{
|
||||
|
@@ -39,10 +39,10 @@
|
||||
#include <86box/config.h>
|
||||
#include <86box/video.h>
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
#else
|
||||
#include <poll.h>
|
||||
# include <poll.h>
|
||||
#endif
|
||||
#include <86box/net_event.h>
|
||||
|
||||
@@ -75,7 +75,6 @@ typedef struct {
|
||||
#ifdef ENABLE_SLIRP_LOG
|
||||
int slirp_do_log = ENABLE_SLIRP_LOG;
|
||||
|
||||
|
||||
static void
|
||||
slirp_log(const char *fmt, ...)
|
||||
{
|
||||
@@ -88,24 +87,21 @@ slirp_log(const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define slirp_log(fmt, ...)
|
||||
# define slirp_log(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static void
|
||||
net_slirp_guest_error(const char *msg, void *opaque)
|
||||
{
|
||||
slirp_log("SLiRP: guest_error(): %s\n", msg);
|
||||
}
|
||||
|
||||
|
||||
static int64_t
|
||||
net_slirp_clock_get_ns(void *opaque)
|
||||
{
|
||||
return (int64_t)((double)tsc / cpuclock * 1000000000.0);
|
||||
return (int64_t) ((double) tsc / cpuclock * 1000000000.0);
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, void *opaque)
|
||||
{
|
||||
@@ -114,7 +110,6 @@ net_slirp_timer_new(SlirpTimerCb cb, void *cb_opaque, void *opaque)
|
||||
return timer;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
net_slirp_timer_free(void *timer, void *opaque)
|
||||
{
|
||||
@@ -122,14 +117,12 @@ net_slirp_timer_free(void *timer, void *opaque)
|
||||
free(timer);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
net_slirp_timer_mod(void *timer, int64_t expire_timer, void *opaque)
|
||||
{
|
||||
timer_on_auto(timer, expire_timer * 1000);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
net_slirp_register_poll_fd(int fd, void *opaque)
|
||||
{
|
||||
@@ -137,7 +130,6 @@ net_slirp_register_poll_fd(int fd, void *opaque)
|
||||
(void) opaque;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
net_slirp_unregister_poll_fd(int fd, void *opaque)
|
||||
{
|
||||
@@ -145,14 +137,12 @@ net_slirp_unregister_poll_fd(int fd, void *opaque)
|
||||
(void) opaque;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
net_slirp_notify(void *opaque)
|
||||
{
|
||||
(void) opaque;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
net_slirp_send_packet(const void *qp, size_t pkt_len, void *opaque)
|
||||
{
|
||||
@@ -160,14 +150,13 @@ net_slirp_send_packet(const void *qp, size_t pkt_len, void *opaque)
|
||||
|
||||
slirp_log("SLiRP: received %d-byte packet\n", pkt_len);
|
||||
|
||||
memcpy(slirp->pkt.data, (uint8_t*) qp, pkt_len);
|
||||
memcpy(slirp->pkt.data, (uint8_t *) qp, pkt_len);
|
||||
slirp->pkt.len = pkt_len;
|
||||
network_rx_put_pkt(slirp->card, &slirp->pkt);
|
||||
|
||||
return pkt_len;
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
static int
|
||||
net_slirp_add_poll(int fd, int events, void *opaque)
|
||||
@@ -299,7 +288,7 @@ net_slirp_in(net_slirp_t *slirp, uint8_t *pkt, int pkt_len)
|
||||
void
|
||||
net_slirp_in_available(void *priv)
|
||||
{
|
||||
net_slirp_t *slirp = (net_slirp_t *)priv;
|
||||
net_slirp_t *slirp = (net_slirp_t *) priv;
|
||||
net_event_set(&slirp->tx_event);
|
||||
}
|
||||
|
||||
@@ -323,7 +312,7 @@ net_slirp_thread(void *priv)
|
||||
if (timeout < 0)
|
||||
timeout = INFINITE;
|
||||
|
||||
int ret = WaitForMultipleObjects(3, events, FALSE, (DWORD)timeout);
|
||||
int ret = WaitForMultipleObjects(3, events, FALSE, (DWORD) timeout);
|
||||
switch (ret - WAIT_OBJECT_0) {
|
||||
case NET_EVENT_STOP:
|
||||
run = false;
|
||||
@@ -341,7 +330,6 @@ net_slirp_thread(void *priv)
|
||||
default:
|
||||
slirp_pollfds_poll(slirp->slirp, ret == WAIT_FAILED, net_slirp_get_revents, slirp);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,7 +386,7 @@ net_slirp_init(const netcard_t *card, const uint8_t *mac_addr, void *priv)
|
||||
slirp_log("SLiRP: initializing...\n");
|
||||
net_slirp_t *slirp = calloc(1, sizeof(net_slirp_t));
|
||||
memcpy(slirp->mac_addr, mac_addr, sizeof(slirp->mac_addr));
|
||||
slirp->card = (netcard_t*)card;
|
||||
slirp->card = (netcard_t *) card;
|
||||
|
||||
#ifndef _WIN32
|
||||
slirp->pfd_size = 16 * sizeof(struct pollfd);
|
||||
|
@@ -120,7 +120,6 @@ typedef struct {
|
||||
if_chip, board_chip;
|
||||
} wd_t;
|
||||
|
||||
|
||||
#ifdef ENABLE_WD_LOG
|
||||
int wd_do_log = ENABLE_WD_LOG;
|
||||
|
||||
@@ -136,12 +135,10 @@ wdlog(const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define wdlog(fmt, ...)
|
||||
# define wdlog(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
static const int we_int_table[4] = {2, 3, 4, 7};
|
||||
|
||||
static const int we_int_table[4] = { 2, 3, 4, 7 };
|
||||
|
||||
static void
|
||||
wd_interrupt(void *priv, int set)
|
||||
@@ -157,32 +154,29 @@ wd_interrupt(void *priv, int set)
|
||||
picintc(1 << dev->irq);
|
||||
}
|
||||
|
||||
|
||||
/* reset - restore state to power-up, cancelling all i/o */
|
||||
static void
|
||||
wd_reset(void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
wdlog("%s: reset\n", dev->name);
|
||||
|
||||
dp8390_reset(dev->dp8390);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_soft_reset(void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
dp8390_soft_reset(dev->dp8390);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
wd_ram_read(uint32_t addr, void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
wdlog("WD80x3: RAM Read: addr=%06x, val=%02x\n", addr & (dev->ram_size - 1), dev->dp8390->mem[addr & (dev->ram_size - 1)]);
|
||||
return dev->dp8390->mem[addr & (dev->ram_size - 1)];
|
||||
@@ -191,13 +185,12 @@ wd_ram_read(uint32_t addr, void *priv)
|
||||
static void
|
||||
wd_ram_write(uint32_t addr, uint8_t val, void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
dev->dp8390->mem[addr & (dev->ram_size - 1)] = val;
|
||||
wdlog("WD80x3: RAM Write: addr=%06x, val=%02x\n", addr & (dev->ram_size - 1), val);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
wd_get_irq_index(wd_t *dev)
|
||||
{
|
||||
@@ -214,7 +207,6 @@ wd_get_irq_index(wd_t *dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static uint32_t
|
||||
wd_smc_read(wd_t *dev, uint32_t off)
|
||||
{
|
||||
@@ -224,7 +216,7 @@ wd_smc_read(wd_t *dev, uint32_t off)
|
||||
if (dev->board == WD8003E)
|
||||
off |= 0x08;
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
case 0x00:
|
||||
if (dev->board_chip & WE_ID_BUS_MCA)
|
||||
retval = (dev->msr & 0xc0) | ((dev->ram_addr >> 13) & 0x3f);
|
||||
@@ -284,21 +276,18 @@ wd_smc_read(wd_t *dev, uint32_t off)
|
||||
|
||||
case 0x0f:
|
||||
/*This has to return the byte that adds up to 0xFF*/
|
||||
checksum = (dev->dp8390->physaddr[0] + dev->dp8390->physaddr[1] + dev->dp8390->physaddr[2] +
|
||||
dev->dp8390->physaddr[3] + dev->dp8390->physaddr[4] + dev->dp8390->physaddr[5] +
|
||||
dev->board_chip);
|
||||
checksum = (dev->dp8390->physaddr[0] + dev->dp8390->physaddr[1] + dev->dp8390->physaddr[2] + dev->dp8390->physaddr[3] + dev->dp8390->physaddr[4] + dev->dp8390->physaddr[5] + dev->board_chip);
|
||||
|
||||
retval = 0xff - (checksum & 0xff);
|
||||
break;
|
||||
}
|
||||
|
||||
wdlog("%s: ASIC read addr=0x%02x, value=0x%04x\n",
|
||||
dev->name, (unsigned)off, (unsigned) retval);
|
||||
dev->name, (unsigned) off, (unsigned) retval);
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_set_ram(wd_t *dev)
|
||||
{
|
||||
@@ -320,19 +309,18 @@ wd_set_ram(wd_t *dev)
|
||||
wdlog("%s: RAM now %sabled\n", dev->name, (dev->msr & WE_MSR_ENABLE_RAM) ? "en" : "dis");
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_smc_write(wd_t *dev, uint32_t off, uint32_t val)
|
||||
{
|
||||
uint8_t old;
|
||||
|
||||
wdlog("%s: ASIC write addr=0x%02x, value=0x%04x\n",
|
||||
dev->name, (unsigned)off, (unsigned) val);
|
||||
dev->name, (unsigned) off, (unsigned) val);
|
||||
|
||||
if (off && (dev->board == WD8003E))
|
||||
return;
|
||||
|
||||
switch(off) {
|
||||
switch (off) {
|
||||
/* Bits 0-5: Bits 13-18 of memory address (writable?):
|
||||
Windows 98 requires this to be preloaded with the initial
|
||||
addresss to work correctly;
|
||||
@@ -398,16 +386,15 @@ wd_smc_write(wd_t *dev, uint32_t off, uint32_t val)
|
||||
maybe some clone cards implement writing for some other
|
||||
registers? */
|
||||
wdlog("%s: ASIC write invalid address %04x, ignoring\n",
|
||||
dev->name, (unsigned)off);
|
||||
dev->name, (unsigned) off);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
wd_read(uint16_t addr, void *priv, int len)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
uint8_t retval = 0;
|
||||
int off = addr - dev->base_address;
|
||||
@@ -419,7 +406,7 @@ wd_read(uint16_t addr, void *priv, int len)
|
||||
else if ((off >= 0x00) && (off <= 0x0f))
|
||||
retval = wd_smc_read(dev, off);
|
||||
else {
|
||||
switch(dev->dp8390->CR.pgsel) {
|
||||
switch (dev->dp8390->CR.pgsel) {
|
||||
case 0x00:
|
||||
retval = dp8390_page0_read(dev->dp8390, off - 0x10, len);
|
||||
break;
|
||||
@@ -436,32 +423,29 @@ wd_read(uint16_t addr, void *priv, int len)
|
||||
}
|
||||
}
|
||||
|
||||
return(retval);
|
||||
return (retval);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
wd_readb(uint16_t addr, void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
return(wd_read(addr, dev, 1));
|
||||
return (wd_read(addr, dev, 1));
|
||||
}
|
||||
|
||||
|
||||
static uint16_t
|
||||
wd_readw(uint16_t addr, void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
return(wd_read(addr, dev, 2));
|
||||
return (wd_read(addr, dev, 2));
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_write(uint16_t addr, uint8_t val, void *priv, unsigned int len)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
int off = addr - dev->base_address;
|
||||
|
||||
wdlog("%s: write addr %x, value %x\n", dev->name, addr, val);
|
||||
@@ -471,7 +455,7 @@ wd_write(uint16_t addr, uint8_t val, void *priv, unsigned int len)
|
||||
else if ((off >= 0x00) && (off <= 0x0f))
|
||||
wd_smc_write(dev, off, val);
|
||||
else {
|
||||
switch(dev->dp8390->CR.pgsel) {
|
||||
switch (dev->dp8390->CR.pgsel) {
|
||||
case 0x00:
|
||||
dp8390_page0_write(dev->dp8390, off - 0x10, val, len);
|
||||
break;
|
||||
@@ -486,21 +470,18 @@ wd_write(uint16_t addr, uint8_t val, void *priv, unsigned int len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_writeb(uint16_t addr, uint8_t val, void *priv)
|
||||
{
|
||||
wd_write(addr, val, priv, 1);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_writew(uint16_t addr, uint16_t val, void *priv)
|
||||
{
|
||||
wd_write(addr, val & 0xff, priv, 2);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_io_set(wd_t *dev, uint16_t addr)
|
||||
{
|
||||
@@ -515,7 +496,6 @@ wd_io_set(wd_t *dev, uint16_t addr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_io_remove(wd_t *dev, uint16_t addr)
|
||||
{
|
||||
@@ -530,26 +510,28 @@ wd_io_remove(wd_t *dev, uint16_t addr)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
wd_mca_read(int port, void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
return(dev->pos_regs[port & 7]);
|
||||
return (dev->pos_regs[port & 7]);
|
||||
}
|
||||
|
||||
|
||||
#define MCA_6FC0_IRQS { 3, 4, 10, 15 }
|
||||
#define MCA_6FC0_IRQS \
|
||||
{ \
|
||||
3, 4, 10, 15 \
|
||||
}
|
||||
|
||||
static void
|
||||
wd_mca_write(int port, uint8_t val, void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
int8_t irq[4] = MCA_6FC0_IRQS;
|
||||
|
||||
/* MCA does not write registers below 0x0100. */
|
||||
if (port < 0x0102) return;
|
||||
if (port < 0x0102)
|
||||
return;
|
||||
|
||||
/* Save the MCA register value. */
|
||||
dev->pos_regs[port & 7] = val;
|
||||
@@ -586,10 +568,11 @@ wd_mca_write(int port, uint8_t val, void *priv)
|
||||
static void
|
||||
wd_8013epa_mca_write(int port, uint8_t val, void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
/* MCA does not write registers below 0x0100. */
|
||||
if (port < 0x0102) return;
|
||||
if (port < 0x0102)
|
||||
return;
|
||||
|
||||
/* Save the MCA register value. */
|
||||
dev->pos_regs[port & 7] = val;
|
||||
@@ -645,14 +628,12 @@ wd_8013epa_mca_write(int port, uint8_t val, void *priv)
|
||||
dev->base_address, dev->irq, dev->ram_addr);
|
||||
}
|
||||
|
||||
|
||||
static uint8_t
|
||||
wd_mca_feedb(void *priv)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static void *
|
||||
wd_init(const device_t *info)
|
||||
{
|
||||
@@ -682,8 +663,8 @@ wd_init(const device_t *info)
|
||||
mac |= ((int) dev->maclocal[5]);
|
||||
device_set_config_mac("mac", mac);
|
||||
} else {
|
||||
dev->maclocal[3] = (mac>>16) & 0xff;
|
||||
dev->maclocal[4] = (mac>>8) & 0xff;
|
||||
dev->maclocal[3] = (mac >> 16) & 0xff;
|
||||
dev->maclocal[4] = (mac >> 8) & 0xff;
|
||||
dev->maclocal[5] = (mac & 0xff);
|
||||
}
|
||||
|
||||
@@ -703,7 +684,7 @@ wd_init(const device_t *info)
|
||||
dev->dp8390->interrupt = wd_interrupt;
|
||||
dp8390_set_defaults(dev->dp8390, DP8390_FLAG_CHECK_CR | DP8390_FLAG_CLEAR_IRQ);
|
||||
|
||||
switch(dev->board) {
|
||||
switch (dev->board) {
|
||||
/* Ethernet, ISA, no interface chip, RAM 8k */
|
||||
case WD8003E:
|
||||
dev->board_chip = WE_TYPE_WD8003E;
|
||||
@@ -795,14 +776,13 @@ wd_init(const device_t *info)
|
||||
dev->base_address, dev->irq, dev->ram_addr);
|
||||
}
|
||||
|
||||
return(dev);
|
||||
return (dev);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
wd_close(void *priv)
|
||||
{
|
||||
wd_t *dev = (wd_t *)priv;
|
||||
wd_t *dev = (wd_t *) priv;
|
||||
|
||||
wdlog("%s: closed\n", dev->name);
|
||||
|
||||
|
@@ -73,9 +73,9 @@
|
||||
#include <86box/net_wd8003.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
|
||||
static const device_t net_none_device = {
|
||||
@@ -92,7 +92,6 @@ static const device_t net_none_device = {
|
||||
.config = NULL
|
||||
};
|
||||
|
||||
|
||||
static const device_t *net_cards[] = {
|
||||
&net_none_device,
|
||||
&threec503_device,
|
||||
@@ -124,7 +123,6 @@ int net_card_current = 0;
|
||||
int network_ndev;
|
||||
netdev_t network_devs[NET_HOST_INTF_MAX];
|
||||
|
||||
|
||||
/* Local variables. */
|
||||
|
||||
#ifdef ENABLE_NETWORK_LOG
|
||||
@@ -132,7 +130,6 @@ int network_do_log = ENABLE_NETWORK_LOG;
|
||||
static FILE *network_dump = NULL;
|
||||
static mutex_t *network_dump_mutex;
|
||||
|
||||
|
||||
static void
|
||||
network_log(const char *fmt, ...)
|
||||
{
|
||||
@@ -145,7 +142,6 @@ network_log(const char *fmt, ...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
network_dump_packet(netpkt_t *pkt)
|
||||
{
|
||||
@@ -179,11 +175,10 @@ network_dump_packet(netpkt_t *pkt)
|
||||
thread_release_mutex(network_dump_mutex);
|
||||
}
|
||||
#else
|
||||
#define network_log(fmt, ...)
|
||||
#define network_dump_packet(pkt)
|
||||
# define network_log(fmt, ...)
|
||||
# define network_dump_packet(pkt)
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
static void
|
||||
network_winsock_clean(void)
|
||||
@@ -244,11 +239,10 @@ void
|
||||
network_queue_init(netqueue_t *queue)
|
||||
{
|
||||
queue->head = queue->tail = 0;
|
||||
for (int i=0; i<NET_QUEUE_LEN; i++) {
|
||||
for (int i = 0; i < NET_QUEUE_LEN; i++) {
|
||||
queue->packets[i].data = calloc(1, NET_MAX_FRAME);
|
||||
queue->packets[i].len = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static bool
|
||||
@@ -300,7 +294,8 @@ network_queue_put_swap(netqueue_t *queue, netpkt_t *src_pkt)
|
||||
}
|
||||
|
||||
static int
|
||||
network_queue_get_swap(netqueue_t *queue, netpkt_t *dst_pkt) {
|
||||
network_queue_get_swap(netqueue_t *queue, netpkt_t *dst_pkt)
|
||||
{
|
||||
if (network_queue_empty(queue))
|
||||
return 0;
|
||||
|
||||
@@ -333,18 +328,17 @@ network_queue_move(netqueue_t *dst_q, netqueue_t *src_q)
|
||||
void
|
||||
network_queue_clear(netqueue_t *queue)
|
||||
{
|
||||
for (int i=0; i<NET_QUEUE_LEN; i++) {
|
||||
for (int i = 0; i < NET_QUEUE_LEN; i++) {
|
||||
free(queue->packets[i].data);
|
||||
queue->packets[i].len = 0;
|
||||
}
|
||||
queue->tail = queue->head = 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
network_rx_queue(void *priv)
|
||||
{
|
||||
netcard_t *card = (netcard_t *)priv;
|
||||
netcard_t *card = (netcard_t *) priv;
|
||||
|
||||
uint32_t new_link_state = net_cards_conf[card->card_num].link_state;
|
||||
if (new_link_state != card->link_state) {
|
||||
@@ -402,7 +396,6 @@ network_rx_queue(void *priv)
|
||||
card->led_timer += timer_period;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Attach a network card to the system.
|
||||
*
|
||||
@@ -423,7 +416,7 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin
|
||||
card->card_num = net_card_current;
|
||||
card->byte_period = NET_PERIOD_10M;
|
||||
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
network_queue_init(&card->queues[i]);
|
||||
}
|
||||
|
||||
@@ -443,7 +436,7 @@ network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETSETLINKSTATE set_lin
|
||||
if (!card->host_drv.priv) {
|
||||
thread_close_mutex(card->tx_mutex);
|
||||
thread_close_mutex(card->rx_mutex);
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
network_queue_clear(&card->queues[i]);
|
||||
}
|
||||
|
||||
@@ -466,7 +459,7 @@ netcard_close(netcard_t *card)
|
||||
|
||||
thread_close_mutex(card->tx_mutex);
|
||||
thread_close_mutex(card->rx_mutex);
|
||||
for (int i=0; i<3; i++) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
network_queue_clear(&card->queues[i]);
|
||||
}
|
||||
|
||||
@@ -474,7 +467,6 @@ netcard_close(netcard_t *card)
|
||||
free(card);
|
||||
}
|
||||
|
||||
|
||||
/* Stop any network activity. */
|
||||
void
|
||||
network_close(void)
|
||||
@@ -487,7 +479,6 @@ network_close(void)
|
||||
network_log("NETWORK: closed.\n");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Reset the network card(s).
|
||||
*
|
||||
@@ -517,7 +508,6 @@ network_reset(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Queue a packet for transmission to one of the network providers. */
|
||||
void
|
||||
network_tx(netcard_t *card, uint8_t *bufp, int len)
|
||||
@@ -525,7 +515,8 @@ network_tx(netcard_t *card, uint8_t *bufp, int len)
|
||||
network_queue_put(&card->queues[NET_QUEUE_TX_VM], bufp, len);
|
||||
}
|
||||
|
||||
int network_tx_pop(netcard_t *card, netpkt_t *out_pkt)
|
||||
int
|
||||
network_tx_pop(netcard_t *card, netpkt_t *out_pkt)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -536,7 +527,8 @@ int network_tx_pop(netcard_t *card, netpkt_t *out_pkt)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int network_tx_popv(netcard_t *card, netpkt_t *pkt_vec, int vec_size)
|
||||
int
|
||||
network_tx_popv(netcard_t *card, netpkt_t *pkt_vec, int vec_size)
|
||||
{
|
||||
int pkt_count = 0;
|
||||
|
||||
@@ -553,7 +545,8 @@ int network_tx_popv(netcard_t *card, netpkt_t *pkt_vec, int vec_size)
|
||||
return pkt_count;
|
||||
}
|
||||
|
||||
int network_rx_put(netcard_t *card, uint8_t *bufp, int len)
|
||||
int
|
||||
network_rx_put(netcard_t *card, uint8_t *bufp, int len)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -564,7 +557,8 @@ int network_rx_put(netcard_t *card, uint8_t *bufp, int len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int network_rx_put_pkt(netcard_t *card, netpkt_t *pkt)
|
||||
int
|
||||
network_rx_put_pkt(netcard_t *card, netpkt_t *pkt)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -602,16 +596,15 @@ network_dev_to_id(char *devname)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i=0; i<network_ndev; i++) {
|
||||
if (! strcmp((char *)network_devs[i].device, devname)) {
|
||||
return(i);
|
||||
for (i = 0; i < network_ndev; i++) {
|
||||
if (!strcmp((char *) network_devs[i].device, devname)) {
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
|
||||
return(-1);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
/* UI */
|
||||
int
|
||||
network_dev_available(int id)
|
||||
@@ -629,43 +622,40 @@ network_available(void)
|
||||
{
|
||||
int available = 0;
|
||||
|
||||
for (int i = 0; i < NET_CARD_MAX; i ++) {
|
||||
for (int i = 0; i < NET_CARD_MAX; i++) {
|
||||
available |= network_dev_available(i);
|
||||
}
|
||||
|
||||
return available;
|
||||
}
|
||||
|
||||
|
||||
/* UI */
|
||||
int
|
||||
network_card_available(int card)
|
||||
{
|
||||
if (net_cards[card])
|
||||
return(device_available(net_cards[card]));
|
||||
return (device_available(net_cards[card]));
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
/* UI */
|
||||
const device_t *
|
||||
network_card_getdevice(int card)
|
||||
{
|
||||
return(net_cards[card]);
|
||||
return (net_cards[card]);
|
||||
}
|
||||
|
||||
|
||||
/* UI */
|
||||
int
|
||||
network_card_has_config(int card)
|
||||
{
|
||||
if (!net_cards[card]) return(0);
|
||||
if (!net_cards[card])
|
||||
return (0);
|
||||
|
||||
return(device_has_config(net_cards[card]) ? 1 : 0);
|
||||
return (device_has_config(net_cards[card]) ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
/* UI */
|
||||
char *
|
||||
network_card_get_internal_name(int card)
|
||||
@@ -673,7 +663,6 @@ network_card_get_internal_name(int card)
|
||||
return device_get_internal_name(net_cards[card]);
|
||||
}
|
||||
|
||||
|
||||
/* UI */
|
||||
int
|
||||
network_card_get_from_internal_name(char *s)
|
||||
@@ -681,8 +670,8 @@ network_card_get_from_internal_name(char *s)
|
||||
int c = 0;
|
||||
|
||||
while (net_cards[c] != NULL) {
|
||||
if (! strcmp((char *)net_cards[c]->internal_name, s))
|
||||
return(c);
|
||||
if (!strcmp((char *) net_cards[c]->internal_name, s))
|
||||
return (c);
|
||||
c++;
|
||||
}
|
||||
|
||||
|
@@ -58,34 +58,30 @@
|
||||
#include <86box/plat.h>
|
||||
#include <86box/plat_dynld.h>
|
||||
|
||||
|
||||
static void *pcap_handle; /* handle to WinPcap DLL */
|
||||
|
||||
|
||||
/* Pointers to the real functions. */
|
||||
static int (*f_pcap_findalldevs)(pcap_if_t **,char *);
|
||||
static int (*f_pcap_findalldevs)(pcap_if_t **, char *);
|
||||
static void (*f_pcap_freealldevs)(pcap_if_t *);
|
||||
static pcap_t *(*f_pcap_open_live)(const char *,int,int,int,char *);
|
||||
static int (*f_pcap_next_ex)(pcap_t*,struct pcap_pkthdr**,const unsigned char**);
|
||||
static pcap_t *(*f_pcap_open_live)(const char *, int, int, int, char *);
|
||||
static int (*f_pcap_next_ex)(pcap_t *, struct pcap_pkthdr **, const unsigned char **);
|
||||
static void (*f_pcap_close)(pcap_t *);
|
||||
static dllimp_t pcap_imports[] = {
|
||||
// clang-format off
|
||||
// clang-format off
|
||||
{ "pcap_findalldevs", &f_pcap_findalldevs },
|
||||
{ "pcap_freealldevs", &f_pcap_freealldevs },
|
||||
{ "pcap_open_live", &f_pcap_open_live },
|
||||
{ "pcap_next_ex", &f_pcap_next_ex },
|
||||
{ "pcap_close", &f_pcap_close },
|
||||
{ NULL, NULL },
|
||||
// clang-format on
|
||||
// clang-format on
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
char device[128];
|
||||
char description[128];
|
||||
} capdev_t;
|
||||
|
||||
|
||||
/* Retrieve an easy-to-use list of devices. */
|
||||
static int
|
||||
get_devlist(capdev_t *list)
|
||||
@@ -96,11 +92,11 @@ get_devlist(capdev_t *list)
|
||||
|
||||
/* Retrieve the device list from the local machine */
|
||||
if (f_pcap_findalldevs(&devlist, errbuf) == -1) {
|
||||
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
|
||||
return(-1);
|
||||
fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
for (dev=devlist; dev!=NULL; dev=dev->next) {
|
||||
for (dev = devlist; dev != NULL; dev = dev->next) {
|
||||
strcpy(list->device, dev->name);
|
||||
if (dev->description)
|
||||
strcpy(list->description, dev->description);
|
||||
@@ -113,10 +109,9 @@ get_devlist(capdev_t *list)
|
||||
/* Release the memory. */
|
||||
f_pcap_freealldevs(devlist);
|
||||
|
||||
return(i);
|
||||
return (i);
|
||||
}
|
||||
|
||||
|
||||
/* Simple HEXDUMP routine for raw data. */
|
||||
static void
|
||||
hex_dump(unsigned char *bufp, int len)
|
||||
@@ -132,7 +127,7 @@ hex_dump(unsigned char *bufp, int len)
|
||||
printf("%04lx %02x", addr, c);
|
||||
else
|
||||
printf(" %02x", c);
|
||||
asci[(addr & 15)] = (uint8_t)isprint(c) ? c : '.';
|
||||
asci[(addr & 15)] = (uint8_t) isprint(c) ? c : '.';
|
||||
if ((++addr % 16) == 0) {
|
||||
asci[16] = '\0';
|
||||
printf(" | %s |\n", asci);
|
||||
@@ -150,7 +145,6 @@ hex_dump(unsigned char *bufp, int len)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Print a standard Ethernet MAC address. */
|
||||
static void
|
||||
eth_praddr(unsigned char *ptr)
|
||||
@@ -159,7 +153,6 @@ eth_praddr(unsigned char *ptr)
|
||||
ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5]);
|
||||
}
|
||||
|
||||
|
||||
/* Print a standard Ethernet header. */
|
||||
static int
|
||||
eth_prhdr(unsigned char *ptr)
|
||||
@@ -167,16 +160,15 @@ eth_prhdr(unsigned char *ptr)
|
||||
unsigned short type;
|
||||
|
||||
printf("Ethernet ");
|
||||
eth_praddr(ptr+6);
|
||||
eth_praddr(ptr + 6);
|
||||
printf(" > ");
|
||||
eth_praddr(ptr);
|
||||
type = (ptr[12] << 8) | ptr[13];
|
||||
printf(" type %04x\n", type);
|
||||
|
||||
return(14);
|
||||
return (14);
|
||||
}
|
||||
|
||||
|
||||
/* Capture packets from the network, and print them. */
|
||||
static int
|
||||
start_cap(char *dev)
|
||||
@@ -197,16 +189,18 @@ start_cap(char *dev)
|
||||
temp);
|
||||
if (pcap == NULL) {
|
||||
fprintf(stderr, "Pcap: open_live(%s): %s\n", dev, temp);
|
||||
return(2);
|
||||
return (2);
|
||||
}
|
||||
|
||||
printf("Listening on '%s'..\n", dev);
|
||||
for (;;) {
|
||||
rc = f_pcap_next_ex(pcap, &hdr, &pkt);
|
||||
if (rc < 0) break;
|
||||
if (rc < 0)
|
||||
break;
|
||||
|
||||
/* Did we time out? */
|
||||
if (rc == 0) continue;
|
||||
if (rc == 0)
|
||||
continue;
|
||||
|
||||
/* Convert the timestamp to readable format. */
|
||||
now = hdr->ts.tv_sec;
|
||||
@@ -216,17 +210,16 @@ start_cap(char *dev)
|
||||
/* Process and print the packet. */
|
||||
printf("\n<< %s,%.6ld len=%u\n",
|
||||
temp, hdr->ts.tv_usec, hdr->len);
|
||||
rc = eth_prhdr((unsigned char *)pkt);
|
||||
hex_dump((unsigned char *)pkt+rc, hdr->len-rc);
|
||||
rc = eth_prhdr((unsigned char *) pkt);
|
||||
hex_dump((unsigned char *) pkt + rc, hdr->len - rc);
|
||||
}
|
||||
|
||||
/* All done, close up. */
|
||||
f_pcap_close(pcap);
|
||||
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
/* Show a list of available network interfaces. */
|
||||
static void
|
||||
show_devs(capdev_t *list, int num)
|
||||
@@ -236,8 +229,8 @@ show_devs(capdev_t *list, int num)
|
||||
if (num > 0) {
|
||||
printf("Available network interfaces:\n\n");
|
||||
|
||||
for (i=0; i<num; i++) {
|
||||
printf(" %d - %s\n", i+1, list->device);
|
||||
for (i = 0; i < num; i++) {
|
||||
printf(" %d - %s\n", i + 1, list->device);
|
||||
if (list->description[0] != '\0')
|
||||
printf(" (%s)\n", list->description);
|
||||
else
|
||||
@@ -250,7 +243,6 @@ show_devs(capdev_t *list, int num)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
pclog(const char *fmt, ...)
|
||||
{
|
||||
@@ -261,7 +253,6 @@ pclog(const char *fmt, ...)
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@@ -282,7 +273,7 @@ main(int argc, char **argv)
|
||||
#else
|
||||
fprintf(stderr, "Unable to load libpcap.so !\n");
|
||||
#endif
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Get the list. */
|
||||
@@ -294,7 +285,7 @@ main(int argc, char **argv)
|
||||
|
||||
dynld_close(pcap_handle);
|
||||
|
||||
return(numdev);
|
||||
return (numdev);
|
||||
}
|
||||
|
||||
/* Assume argument to be the interface number to listen on. */
|
||||
@@ -304,13 +295,13 @@ main(int argc, char **argv)
|
||||
|
||||
dynld_close(pcap_handle);
|
||||
|
||||
return(1);
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Looks good, go and listen.. */
|
||||
i = start_cap(interfaces[i-1].device);
|
||||
/* Looks good, go and listen.. */
|
||||
i = start_cap(interfaces[i - 1].device);
|
||||
|
||||
dynld_close(pcap_handle);
|
||||
|
||||
return(i);
|
||||
return (i);
|
||||
}
|
||||
|
Reference in New Issue
Block a user