2017-05-09 22:09:55 -04:00
|
|
|
/*
|
|
|
|
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
|
|
|
|
* running old operating systems and software designed for IBM
|
|
|
|
|
* PC systems and compatibles from 1981 through fairly recent
|
|
|
|
|
* system designs based on the PCI bus.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
|
|
|
|
* Implementation of the network module.
|
|
|
|
|
*
|
2017-05-09 22:59:01 -04:00
|
|
|
* Version: @(#)network.c 1.0.2 2017/05/09
|
2017-05-09 22:09:55 -04:00
|
|
|
*
|
|
|
|
|
* Authors: Kotori, <oubattler@gmail.com>
|
|
|
|
|
* Fred N. van Kempen, <decwiz@yahoo.com>
|
|
|
|
|
*/
|
2017-05-06 17:48:33 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "ibm.h"
|
|
|
|
|
#include "device.h"
|
|
|
|
|
#include "timer.h"
|
|
|
|
|
#include "thread.h"
|
2017-05-09 22:09:55 -04:00
|
|
|
#include "network.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
#include "net_ne2000.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
char name[64];
|
|
|
|
|
char internal_name[32];
|
|
|
|
|
device_t *device;
|
|
|
|
|
} NETCARD;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2017-05-09 22:09:55 -04:00
|
|
|
void (*poller)(void *);
|
2017-05-06 17:48:33 +02:00
|
|
|
void *priv;
|
|
|
|
|
} NETPOLL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int net_handlers_num;
|
2017-05-10 04:36:19 +02:00
|
|
|
static int net_poll_time = 0;
|
2017-05-09 22:59:01 -04:00
|
|
|
static int net_poll_time;
|
2017-05-06 17:48:33 +02:00
|
|
|
static NETPOLL net_handlers[8];
|
|
|
|
|
static NETCARD net_cards[] = {
|
|
|
|
|
{ "None", "none", NULL },
|
|
|
|
|
{ "Novell NE2000", "ne2k", &ne2000_device },
|
|
|
|
|
{ "Realtek RTL8029AS", "ne2kpci", &rtl8029as_device },
|
|
|
|
|
{ "", "", NULL }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2017-05-09 22:09:55 -04:00
|
|
|
int network_card_current = 0;
|
2017-05-08 04:54:17 +02:00
|
|
|
uint8_t ethif;
|
|
|
|
|
int inum;
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
net_poll(void *priv)
|
|
|
|
|
{
|
|
|
|
|
int c;
|
|
|
|
|
|
|
|
|
|
/* Reset the poll timer. */
|
2017-05-10 04:36:19 +02:00
|
|
|
net_poll_time += (int)((double)TIMER_USEC * (1000000.0/8.0/3000.0));
|
2017-05-06 17:48:33 +02:00
|
|
|
|
|
|
|
|
/* If we have active cards.. */
|
|
|
|
|
if (net_handlers_num) {
|
|
|
|
|
/* .. poll each of them. */
|
|
|
|
|
for (c=0; c<net_handlers_num; c++) {
|
|
|
|
|
net_handlers[c].poller(net_handlers[c].priv);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the configured network cards. */
|
|
|
|
|
void
|
|
|
|
|
network_init(void)
|
|
|
|
|
{
|
2017-05-09 22:09:55 -04:00
|
|
|
network_card_current = 0;
|
|
|
|
|
net_handlers_num = 0;
|
2017-05-09 22:59:01 -04:00
|
|
|
net_poll_time = 0;
|
2017-05-09 22:09:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Reset the network card(s). */
|
|
|
|
|
void
|
|
|
|
|
network_reset(void)
|
|
|
|
|
{
|
|
|
|
|
pclog("NETWORK: reset (card=%d)\n", network_card_current);
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-09 22:09:55 -04:00
|
|
|
if (! network_card_current) return;
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-09 22:09:55 -04:00
|
|
|
if (net_cards[network_card_current].device) {
|
|
|
|
|
pclog("NETWORK: adding device '%s'\n",
|
|
|
|
|
net_cards[network_card_current].name);
|
|
|
|
|
device_add(net_cards[network_card_current].device);
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
2017-05-09 22:09:55 -04:00
|
|
|
|
|
|
|
|
pclog("NETWORK: adding timer...\n");
|
|
|
|
|
timer_add(net_poll, &net_poll_time, TIMER_ALWAYS_ENABLED, NULL);
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Add a handler for a network card. */
|
|
|
|
|
void
|
2017-05-09 22:09:55 -04:00
|
|
|
network_add_handler(void (*poller)(void *), void *p)
|
2017-05-06 17:48:33 +02:00
|
|
|
{
|
|
|
|
|
net_handlers[net_handlers_num].poller = poller;
|
|
|
|
|
net_handlers[net_handlers_num].priv = p;
|
|
|
|
|
net_handlers_num++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
network_card_available(int card)
|
|
|
|
|
{
|
|
|
|
|
if (net_cards[card].device)
|
|
|
|
|
return(device_available(net_cards[card].device));
|
|
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
network_card_getname(int card)
|
|
|
|
|
{
|
|
|
|
|
return(net_cards[card].name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
device_t *
|
|
|
|
|
network_card_getdevice(int card)
|
|
|
|
|
{
|
|
|
|
|
return(net_cards[card].device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
network_card_has_config(int card)
|
|
|
|
|
{
|
|
|
|
|
if (! net_cards[card].device) return(0);
|
|
|
|
|
|
|
|
|
|
return(net_cards[card].device->config ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
network_card_get_internal_name(int card)
|
|
|
|
|
{
|
|
|
|
|
return(net_cards[card].internal_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
network_card_get_from_internal_name(char *s)
|
|
|
|
|
{
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
|
|
|
|
while (strlen(net_cards[c].internal_name)) {
|
|
|
|
|
if (! strcmp(net_cards[c].internal_name, s))
|
|
|
|
|
return(c);
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(0);
|
|
|
|
|
}
|