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-12 05:05:20 -04:00
|
|
|
* NOTE The definition of the netcard_t is currently not optimal;
|
|
|
|
|
* it should be malloc'ed and then linked to the NETCARD def.
|
|
|
|
|
* Will be done later.
|
|
|
|
|
*
|
2017-05-24 00:27:42 -04:00
|
|
|
* Version: @(#)network.c 1.0.6 2017/05/22
|
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"
|
2017-05-09 22:09:55 -04:00
|
|
|
#include "network.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
#include "net_ne2000.h"
|
2017-05-24 00:27:42 -04:00
|
|
|
#include "win.h"
|
|
|
|
|
#include "win_language.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
static netcard_t net_cards[] = {
|
|
|
|
|
{ "None", "none", NULL,
|
|
|
|
|
NULL, NULL },
|
|
|
|
|
{ "Novell NE1000", "ne1k", &ne1000_device,
|
|
|
|
|
NULL, NULL },
|
|
|
|
|
{ "Novell NE2000", "ne2k", &ne2000_device,
|
|
|
|
|
NULL, NULL },
|
|
|
|
|
{ "Realtek RTL8029AS", "ne2kpci", &rtl8029as_device,
|
|
|
|
|
NULL, NULL },
|
|
|
|
|
{ "", "", NULL,
|
|
|
|
|
NULL, NULL }
|
|
|
|
|
};
|
2017-05-06 17:48:33 +02:00
|
|
|
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
/* Global variables. */
|
|
|
|
|
int network_card;
|
|
|
|
|
int network_type;
|
|
|
|
|
int network_ndev;
|
|
|
|
|
netdev_t network_devs[32];
|
|
|
|
|
char network_pcap[512];
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Initialize the configured network cards.
|
|
|
|
|
*
|
|
|
|
|
* This function gets called only once, from the System
|
|
|
|
|
* Platform initialization code (currently in pc.c) to
|
|
|
|
|
* set our local stuff to a known state.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
network_init(void)
|
|
|
|
|
{
|
2017-05-22 00:21:22 -04:00
|
|
|
int i;
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
network_type = NET_TYPE_NONE;
|
2017-05-12 05:05:20 -04:00
|
|
|
network_card = 0;
|
2017-05-18 01:57:16 -04:00
|
|
|
|
2017-05-22 00:21:22 -04:00
|
|
|
/* Create a first device entry that's always there, as needed by UI. */
|
|
|
|
|
strcpy(network_devs[0].device, "none");
|
|
|
|
|
strcpy(network_devs[0].description, "None");
|
|
|
|
|
network_ndev = 1;
|
|
|
|
|
|
|
|
|
|
/* Initialize the Pcap system module, if present. */
|
|
|
|
|
i = network_pcap_init(&network_devs[network_ndev]);
|
|
|
|
|
if (i > 0)
|
|
|
|
|
network_ndev += i;
|
2017-05-12 05:05:20 -04:00
|
|
|
}
|
2017-05-06 17:48:33 +02:00
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/*
|
|
|
|
|
* Attach a network card to the system.
|
|
|
|
|
*
|
|
|
|
|
* This function is called by a hardware driver ("card") after it has
|
|
|
|
|
* finished initializing itself, to link itself to the platform support
|
|
|
|
|
* modules.
|
|
|
|
|
*/
|
|
|
|
|
int
|
|
|
|
|
network_attach(void *dev, uint8_t *mac, NETRXCB rx)
|
2017-05-06 17:48:33 +02:00
|
|
|
{
|
2017-05-12 05:05:20 -04:00
|
|
|
int ret = -1;
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-22 00:21:22 -04:00
|
|
|
if (network_card == 0) return(ret);
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* Save the card's callback info. */
|
|
|
|
|
net_cards[network_card].private = dev;
|
|
|
|
|
net_cards[network_card].rx = rx;
|
|
|
|
|
|
|
|
|
|
/* Start the platform module. */
|
|
|
|
|
switch(network_type) {
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_PCAP:
|
2017-05-12 05:05:20 -04:00
|
|
|
ret = network_pcap_setup(mac, rx, dev);
|
2017-05-22 00:21:22 -04:00
|
|
|
if (ret < 0) {
|
2017-05-27 03:53:32 +02:00
|
|
|
msgbox_error(ghwnd, 2219);
|
2017-05-22 00:21:22 -04:00
|
|
|
network_type = NET_TYPE_NONE;
|
|
|
|
|
}
|
2017-05-12 05:05:20 -04:00
|
|
|
break;
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_SLIRP:
|
2017-05-12 05:05:20 -04:00
|
|
|
ret = network_slirp_setup(mac, rx, dev);
|
|
|
|
|
break;
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
2017-05-12 05:05:20 -04:00
|
|
|
|
|
|
|
|
return(ret);
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* Stop any network activity. */
|
2017-05-06 17:48:33 +02:00
|
|
|
void
|
2017-05-12 05:05:20 -04:00
|
|
|
network_close(void)
|
2017-05-06 17:48:33 +02:00
|
|
|
{
|
2017-05-12 05:05:20 -04:00
|
|
|
switch(network_type) {
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_PCAP:
|
2017-05-12 05:05:20 -04:00
|
|
|
network_pcap_close();
|
|
|
|
|
break;
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_SLIRP:
|
2017-05-12 05:05:20 -04:00
|
|
|
network_slirp_close();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-09 22:09:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/*
|
|
|
|
|
* Reset the network card(s).
|
|
|
|
|
*
|
|
|
|
|
* This function is called each time the system is reset,
|
|
|
|
|
* either a hard reset (including power-up) or a soft reset
|
|
|
|
|
* including C-A-D reset.) It is responsible for connecting
|
|
|
|
|
* everything together.
|
|
|
|
|
*/
|
2017-05-09 22:09:55 -04:00
|
|
|
void
|
|
|
|
|
network_reset(void)
|
|
|
|
|
{
|
2017-05-27 03:53:32 +02:00
|
|
|
int i = 0;
|
|
|
|
|
|
2017-05-22 00:21:22 -04:00
|
|
|
pclog("NETWORK: reset (type=%d, card=%d)\n", network_type, network_card);
|
2017-05-12 05:05:20 -04:00
|
|
|
|
|
|
|
|
/* Just in case.. */
|
|
|
|
|
network_close();
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* If no active card, we're done. */
|
2017-05-18 01:57:16 -04:00
|
|
|
if ((network_type==NET_TYPE_NONE) || (network_card==0)) return;
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-27 03:53:32 +02:00
|
|
|
i = network_pcap_init(&network_devs[network_ndev]);
|
|
|
|
|
|
2017-05-22 00:21:22 -04:00
|
|
|
pclog("NETWORK: set up for %s, card='%s'\n",
|
2017-05-18 01:57:16 -04:00
|
|
|
(network_type==NET_TYPE_SLIRP)?"SLiRP":"WinPcap",
|
|
|
|
|
net_cards[network_card].name);
|
2017-05-12 17:33:28 -04:00
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* Add the (new?) card to the I/O system. */
|
|
|
|
|
if (net_cards[network_card].device) {
|
2017-05-09 22:09:55 -04:00
|
|
|
pclog("NETWORK: adding device '%s'\n",
|
2017-05-12 05:05:20 -04:00
|
|
|
net_cards[network_card].name);
|
|
|
|
|
device_add(net_cards[network_card].device);
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* Transmit a packet to one of the network providers. */
|
2017-05-06 17:48:33 +02:00
|
|
|
void
|
2017-05-12 05:05:20 -04:00
|
|
|
network_tx(uint8_t *bufp, int len)
|
2017-05-06 17:48:33 +02:00
|
|
|
{
|
2017-05-12 05:05:20 -04:00
|
|
|
switch(network_type) {
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_PCAP:
|
2017-05-12 05:05:20 -04:00
|
|
|
network_pcap_in(bufp, len);
|
|
|
|
|
break;
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_SLIRP:
|
2017-05-12 05:05:20 -04:00
|
|
|
network_slirp_in(bufp, len);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* UI */
|
2017-05-06 17:48:33 +02:00
|
|
|
int
|
|
|
|
|
network_card_available(int card)
|
|
|
|
|
{
|
|
|
|
|
if (net_cards[card].device)
|
|
|
|
|
return(device_available(net_cards[card].device));
|
|
|
|
|
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* UI */
|
2017-05-06 17:48:33 +02:00
|
|
|
char *
|
|
|
|
|
network_card_getname(int card)
|
|
|
|
|
{
|
|
|
|
|
return(net_cards[card].name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* UI */
|
2017-05-06 17:48:33 +02:00
|
|
|
device_t *
|
|
|
|
|
network_card_getdevice(int card)
|
|
|
|
|
{
|
|
|
|
|
return(net_cards[card].device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* UI */
|
2017-05-06 17:48:33 +02:00
|
|
|
int
|
|
|
|
|
network_card_has_config(int card)
|
|
|
|
|
{
|
|
|
|
|
if (! net_cards[card].device) return(0);
|
|
|
|
|
|
|
|
|
|
return(net_cards[card].device->config ? 1 : 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* UI */
|
2017-05-06 17:48:33 +02:00
|
|
|
char *
|
|
|
|
|
network_card_get_internal_name(int card)
|
|
|
|
|
{
|
|
|
|
|
return(net_cards[card].internal_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* UI */
|
2017-05-06 17:48:33 +02:00
|
|
|
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++;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 21:56:31 +02:00
|
|
|
return(-1);
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
2017-05-18 01:57:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
network_dev_to_id(char *dev)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
for (i=0; i<network_ndev; i++) {
|
|
|
|
|
if (! strcmp(network_devs[i].device, dev)) {
|
|
|
|
|
return(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If no match found, assume "none". */
|
|
|
|
|
return(0);
|
|
|
|
|
}
|