2017-05-09 22:09:55 -04:00
|
|
|
/*
|
2018-03-19 01:02:04 +01:00
|
|
|
* VARCem Virtual ARchaeological Computer EMulator.
|
|
|
|
|
* An emulator of (mostly) x86-based PC systems and devices,
|
|
|
|
|
* using the ISA,EISA,VLB,MCA and PCI system buses, roughly
|
|
|
|
|
* spanning the era between 1981 and 1995.
|
2017-05-09 22:09:55 -04:00
|
|
|
*
|
2018-03-19 01:02:04 +01:00
|
|
|
* This file is part of the VARCem Project.
|
2017-05-09 22:09:55 -04:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2020-03-25 00:46:02 +02:00
|
|
|
*
|
2017-05-09 22:09:55 -04:00
|
|
|
*
|
2017-06-04 02:11:19 -04:00
|
|
|
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
2017-10-10 03:07:29 -04:00
|
|
|
*
|
2019-11-14 20:59:51 +01:00
|
|
|
* Copyright 2017-2019 Fred N. van Kempen.
|
2018-03-19 01:02:04 +01:00
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with
|
|
|
|
|
* or without modification, are permitted provided that the
|
|
|
|
|
* following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the entire
|
|
|
|
|
* above notice, this list of conditions and the following
|
|
|
|
|
* disclaimer.
|
|
|
|
|
*
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* 3. Neither the name of the copyright holder nor the names
|
|
|
|
|
* of its contributors may be used to endorse or promote
|
|
|
|
|
* products derived from this software without specific
|
|
|
|
|
* prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
|
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2017-05-09 22:09:55 -04:00
|
|
|
*/
|
2018-05-21 19:04:05 +02:00
|
|
|
#include <stdarg.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdint.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
#include <stdio.h>
|
2017-05-06 17:48:33 +02:00
|
|
|
#include <string.h>
|
2017-09-25 04:31:20 -04:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <wchar.h>
|
2018-05-21 19:04:05 +02:00
|
|
|
#define HAVE_STDARG_H
|
2020-02-29 19:12:23 +01:00
|
|
|
#include "86box.h"
|
|
|
|
|
#include "device.h"
|
|
|
|
|
#include "plat.h"
|
|
|
|
|
#include "ui.h"
|
2017-05-09 22:09:55 -04:00
|
|
|
#include "network.h"
|
2018-07-15 01:41:53 +02:00
|
|
|
#include "net_3c503.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
#include "net_ne2000.h"
|
2019-12-02 18:27:40 +01:00
|
|
|
#include "net_pcnet.h"
|
2018-07-19 16:01:31 +02:00
|
|
|
#include "net_wd8003.h"
|
2017-05-06 17:48:33 +02:00
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
static netcard_t net_cards[] = {
|
2018-03-19 01:02:04 +01:00
|
|
|
{ "None", "none", NULL,
|
|
|
|
|
NULL },
|
2018-07-15 01:41:53 +02:00
|
|
|
{ "[ISA] 3Com EtherLink II (3C503)","3c503", &threec503_device,
|
|
|
|
|
NULL },
|
2020-03-24 01:02:41 +01:00
|
|
|
{ "[ISA] AMD PCnet-ISA", "pcnetisa", &pcnet_am79c960_device,
|
2019-12-02 18:27:40 +01:00
|
|
|
NULL },
|
2018-01-28 03:15:01 +01:00
|
|
|
{ "[ISA] Novell NE1000", "ne1k", &ne1000_device,
|
2018-03-19 01:02:04 +01:00
|
|
|
NULL },
|
2018-01-28 03:15:01 +01:00
|
|
|
{ "[ISA] Novell NE2000", "ne2k", &ne2000_device,
|
2018-03-19 01:02:04 +01:00
|
|
|
NULL },
|
2020-03-24 01:02:41 +01:00
|
|
|
{ "[ISA] Racal Interlan EtherBlaster", "pcnetracal", &pcnet_am79c960_eb_device,
|
|
|
|
|
NULL },
|
2018-01-28 03:15:01 +01:00
|
|
|
{ "[ISA] Realtek RTL8019AS", "ne2kpnp", &rtl8019as_device,
|
2018-03-19 01:02:04 +01:00
|
|
|
NULL },
|
2018-10-23 01:06:00 +02:00
|
|
|
{ "[ISA] Western Digital WD8003E", "wd8003e", &wd8003e_device,
|
|
|
|
|
NULL },
|
|
|
|
|
{ "[ISA] Western Digital WD8003EB", "wd8003eb", &wd8003eb_device,
|
2018-07-19 16:01:31 +02:00
|
|
|
NULL },
|
|
|
|
|
{ "[ISA] Western Digital WD8013EBT","wd8013ebt", &wd8013ebt_device,
|
|
|
|
|
NULL },
|
2018-10-23 01:06:00 +02:00
|
|
|
{ "[MCA] NetWorth Ethernet/MC", "ethernextmc", ðernext_mc_device,
|
|
|
|
|
NULL },
|
|
|
|
|
{ "[MCA] Western Digital WD8003ET/A","wd8003eta", &wd8003eta_device,
|
2018-07-19 16:01:31 +02:00
|
|
|
NULL },
|
2018-10-23 01:06:00 +02:00
|
|
|
{ "[MCA] Western Digital WD8003E/A", "wd8003ea", &wd8003ea_device,
|
2018-07-19 16:01:31 +02:00
|
|
|
NULL },
|
2020-03-24 01:02:41 +01:00
|
|
|
{ "[PCI] AMD PCnet-FAST III", "pcnetfast", &pcnet_am79c973_device,
|
|
|
|
|
NULL },
|
|
|
|
|
{ "[PCI] AMD PCnet-PCI II", "pcnetpci", &pcnet_am79c970a_device,
|
2019-12-02 18:27:40 +01:00
|
|
|
NULL },
|
2018-01-28 03:15:01 +01:00
|
|
|
{ "[PCI] Realtek RTL8029AS", "ne2kpci", &rtl8029as_device,
|
2018-03-19 01:02:04 +01:00
|
|
|
NULL },
|
2020-03-24 01:02:41 +01:00
|
|
|
{ "[VLB] AMD PCnet-VL", "pcnetvlb", &pcnet_am79c960_vlb_device,
|
2019-12-02 18:27:40 +01:00
|
|
|
NULL },
|
2018-03-19 01:02:04 +01:00
|
|
|
{ "", "", NULL,
|
|
|
|
|
NULL }
|
2017-05-12 05:05:20 -04:00
|
|
|
};
|
2017-05-06 17:48:33 +02:00
|
|
|
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
/* Global variables. */
|
|
|
|
|
int network_type;
|
|
|
|
|
int network_ndev;
|
2017-10-07 00:46:54 -04:00
|
|
|
int network_card;
|
2019-11-14 21:22:54 +01:00
|
|
|
static volatile int net_wait = 0;
|
2019-02-06 03:34:39 +01:00
|
|
|
char network_host[522];
|
2018-03-18 20:48:10 +01:00
|
|
|
netdev_t network_devs[32];
|
2017-10-19 21:08:34 -04:00
|
|
|
#ifdef ENABLE_NIC_LOG
|
|
|
|
|
int nic_do_log = ENABLE_NIC_LOG;
|
|
|
|
|
#endif
|
2017-10-29 04:20:20 -05:00
|
|
|
static mutex_t *network_mutex;
|
2018-03-18 20:48:10 +01:00
|
|
|
static uint8_t *network_mac;
|
2017-10-16 21:19:51 +02:00
|
|
|
|
|
|
|
|
|
2017-10-29 04:20:20 -05:00
|
|
|
static struct {
|
|
|
|
|
volatile int busy,
|
|
|
|
|
queue_in_use;
|
|
|
|
|
|
|
|
|
|
event_t *wake_poll_thread,
|
|
|
|
|
*poll_complete,
|
|
|
|
|
*queue_not_in_use;
|
2017-10-16 21:19:51 +02:00
|
|
|
} poll_data;
|
|
|
|
|
|
|
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
#ifdef ENABLE_NETWORK_LOG
|
|
|
|
|
int network_do_log = ENABLE_NETWORK_LOG;
|
2018-03-19 01:02:04 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2018-10-19 00:37:25 +02:00
|
|
|
network_log(const char *fmt, ...)
|
2018-03-19 01:02:04 +01:00
|
|
|
{
|
2018-05-21 19:04:05 +02:00
|
|
|
va_list ap;
|
2018-03-19 01:02:04 +01:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
if (network_do_log) {
|
2018-10-19 00:37:25 +02:00
|
|
|
va_start(ap, fmt);
|
|
|
|
|
pclog_ex(fmt, ap);
|
2018-05-21 19:04:05 +02:00
|
|
|
va_end(ap);
|
2018-03-19 01:02:04 +01:00
|
|
|
}
|
2018-05-21 19:04:05 +02:00
|
|
|
}
|
2018-10-19 00:37:25 +02:00
|
|
|
#else
|
|
|
|
|
#define network_log(fmt, ...)
|
|
|
|
|
#endif
|
2018-03-19 01:02:04 +01:00
|
|
|
|
|
|
|
|
|
2017-10-16 21:19:51 +02:00
|
|
|
void
|
2017-10-29 04:20:20 -05:00
|
|
|
network_wait(uint8_t wait)
|
2017-10-16 21:19:51 +02:00
|
|
|
{
|
2017-10-17 05:15:53 +02:00
|
|
|
if (wait)
|
2017-10-29 04:20:20 -05:00
|
|
|
thread_wait_mutex(network_mutex);
|
|
|
|
|
else
|
|
|
|
|
thread_release_mutex(network_mutex);
|
2017-10-16 21:19:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-10-29 04:20:20 -05:00
|
|
|
network_poll(void)
|
2017-10-16 21:19:51 +02:00
|
|
|
{
|
|
|
|
|
while (poll_data.busy)
|
2017-10-29 04:20:20 -05:00
|
|
|
thread_wait_event(poll_data.wake_poll_thread, -1);
|
2017-10-19 23:55:51 +02:00
|
|
|
|
2017-10-29 04:20:20 -05:00
|
|
|
thread_reset_event(poll_data.wake_poll_thread);
|
2017-10-16 21:19:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2017-10-17 05:15:53 +02:00
|
|
|
network_busy(uint8_t set)
|
2017-10-16 21:19:51 +02:00
|
|
|
{
|
2017-10-17 05:15:53 +02:00
|
|
|
poll_data.busy = !!set;
|
2017-10-29 04:20:20 -05:00
|
|
|
|
|
|
|
|
if (! set)
|
|
|
|
|
thread_set_event(poll_data.wake_poll_thread);
|
2017-10-19 23:55:51 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
|
2017-10-19 23:55:51 +02:00
|
|
|
void
|
|
|
|
|
network_end(void)
|
|
|
|
|
{
|
2017-10-29 04:20:20 -05:00
|
|
|
thread_set_event(poll_data.poll_complete);
|
2017-10-16 21:19:51 +02:00
|
|
|
}
|
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-10-07 00:46:54 -04:00
|
|
|
/* Initialize to a known state. */
|
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. */
|
2017-10-29 04:20:20 -05:00
|
|
|
i = net_pcap_prepare(&network_devs[network_ndev]);
|
2017-05-22 00:21:22 -04:00
|
|
|
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.
|
|
|
|
|
*/
|
2017-10-29 04:20:20 -05:00
|
|
|
void
|
2020-02-29 19:12:23 +01:00
|
|
|
network_attach(void *dev, uint8_t *mac, NETRXCB rx, NETWAITCB wait)
|
2017-05-06 17:48:33 +02:00
|
|
|
{
|
2017-10-29 04:20:20 -05:00
|
|
|
if (network_card == 0) return;
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-10-29 04:20:20 -05:00
|
|
|
/* Save the card's info. */
|
2017-10-16 04:54:41 -04:00
|
|
|
net_cards[network_card].priv = dev;
|
2017-05-12 05:05:20 -04:00
|
|
|
net_cards[network_card].rx = rx;
|
2020-02-29 19:12:23 +01:00
|
|
|
net_cards[network_card].wait = wait;
|
2018-03-18 20:48:10 +01:00
|
|
|
network_mac = mac;
|
2017-05-12 05:05:20 -04:00
|
|
|
|
2019-11-14 21:22:54 +01:00
|
|
|
network_set_wait(0);
|
2019-11-14 21:00:52 +01:00
|
|
|
|
2017-10-29 04:20:20 -05:00
|
|
|
/* Create the network events. */
|
|
|
|
|
poll_data.wake_poll_thread = thread_create_event();
|
|
|
|
|
poll_data.poll_complete = thread_create_event();
|
2017-10-17 05:15:53 +02:00
|
|
|
|
2017-10-29 04:20:20 -05:00
|
|
|
/* Activate the platform module. */
|
2017-05-12 05:05:20 -04:00
|
|
|
switch(network_type) {
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_PCAP:
|
2018-03-18 20:48:10 +01:00
|
|
|
(void)net_pcap_reset(&net_cards[network_card], network_mac);
|
2017-05-12 05:05:20 -04:00
|
|
|
break;
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_SLIRP:
|
2018-03-18 20:48:10 +01:00
|
|
|
(void)net_slirp_reset(&net_cards[network_card], network_mac);
|
2017-05-12 05:05:20 -04:00
|
|
|
break;
|
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-10-29 04:20:20 -05:00
|
|
|
/* If already closed, do nothing. */
|
|
|
|
|
if (network_mutex == NULL) return;
|
|
|
|
|
|
|
|
|
|
/* Force-close the PCAP module. */
|
|
|
|
|
net_pcap_close();
|
|
|
|
|
|
|
|
|
|
/* Force-close the SLIRP module. */
|
|
|
|
|
net_slirp_close();
|
|
|
|
|
|
|
|
|
|
/* Close the network events. */
|
|
|
|
|
if (poll_data.wake_poll_thread != NULL) {
|
|
|
|
|
thread_destroy_event(poll_data.wake_poll_thread);
|
|
|
|
|
poll_data.wake_poll_thread = NULL;
|
2017-05-12 05:05:20 -04:00
|
|
|
}
|
2017-10-29 04:20:20 -05:00
|
|
|
if (poll_data.poll_complete != NULL) {
|
|
|
|
|
thread_destroy_event(poll_data.poll_complete);
|
|
|
|
|
poll_data.poll_complete = NULL;
|
2017-08-22 02:16:15 +02:00
|
|
|
}
|
2017-05-12 05:05:20 -04:00
|
|
|
|
2017-10-29 04:20:20 -05:00
|
|
|
/* Close the network thread mutex. */
|
|
|
|
|
thread_close_mutex(network_mutex);
|
|
|
|
|
network_mutex = NULL;
|
2018-03-18 20:48:10 +01:00
|
|
|
network_mac = NULL;
|
2017-10-29 04:20:20 -05:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
network_log("NETWORK: closed.\n");
|
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-10-29 04:20:20 -05:00
|
|
|
int i = -1;
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
#ifdef ENABLE_NIC_LOG
|
2018-05-21 19:04:05 +02:00
|
|
|
network_log("NETWORK: reset (type=%d, card=%d) debug=%d\n",
|
2018-03-19 01:02:04 +01:00
|
|
|
network_type, network_card, nic_do_log);
|
|
|
|
|
#else
|
2018-05-21 19:04:05 +02:00
|
|
|
network_log("NETWORK: reset (type=%d, card=%d)\n",
|
2018-03-19 01:02:04 +01:00
|
|
|
network_type, network_card);
|
|
|
|
|
#endif
|
2017-10-29 04:20:20 -05:00
|
|
|
ui_sb_update_icon(SB_NETWORK, 0);
|
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
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
network_mutex = thread_create_mutex(L"VARCem.NetMutex");
|
2017-10-29 04:20:20 -05:00
|
|
|
|
|
|
|
|
/* Initialize the platform module. */
|
|
|
|
|
switch(network_type) {
|
|
|
|
|
case NET_TYPE_PCAP:
|
|
|
|
|
i = net_pcap_init();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case NET_TYPE_SLIRP:
|
|
|
|
|
i = net_slirp_init();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i < 0) {
|
|
|
|
|
/* Tell user we can't do this (at the moment.) */
|
2018-07-15 01:41:53 +02:00
|
|
|
ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2102);
|
2017-10-29 04:20:20 -05:00
|
|
|
|
|
|
|
|
// FIXME: we should ask in the dialog if they want to
|
|
|
|
|
// reconfigure or quit, and throw them into the
|
|
|
|
|
// Settings dialog if yes.
|
|
|
|
|
|
|
|
|
|
/* Disable network. */
|
|
|
|
|
network_type = NET_TYPE_NONE;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2017-05-27 03:53:32 +02:00
|
|
|
|
2018-05-21 19:04:05 +02:00
|
|
|
network_log("NETWORK: set up for %s, card='%s'\n",
|
2017-10-29 04:20:20 -05:00
|
|
|
(network_type==NET_TYPE_SLIRP)?"SLiRP":"Pcap",
|
|
|
|
|
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) {
|
2018-05-21 19:04:05 +02:00
|
|
|
network_log("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-10-29 04:20:20 -05:00
|
|
|
ui_sb_update_icon(SB_NETWORK, 1);
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
switch(network_type) {
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_PCAP:
|
2017-10-29 04:20:20 -05:00
|
|
|
net_pcap_in(bufp, len);
|
2017-05-12 05:05:20 -04:00
|
|
|
break;
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
case NET_TYPE_SLIRP:
|
2017-10-29 04:20:20 -05:00
|
|
|
net_slirp_in(bufp, len);
|
2017-05-12 05:05:20 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2017-10-29 04:20:20 -05:00
|
|
|
|
|
|
|
|
ui_sb_update_icon(SB_NETWORK, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
network_dev_to_id(char *devname)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
|
|
for (i=0; i<network_ndev; i++) {
|
2018-03-19 01:02:04 +01:00
|
|
|
if (! strcmp((char *)network_devs[i].device, devname)) {
|
2017-10-29 04:20:20 -05:00
|
|
|
return(i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If no match found, assume "none". */
|
|
|
|
|
return(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* UI */
|
|
|
|
|
int
|
|
|
|
|
network_available(void)
|
|
|
|
|
{
|
|
|
|
|
if ((network_type == NET_TYPE_NONE) || (network_card == 0)) return(0);
|
|
|
|
|
|
|
|
|
|
return(1);
|
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)
|
|
|
|
|
{
|
2018-03-19 01:02:04 +01:00
|
|
|
return((char *)net_cards[card].name);
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* UI */
|
2018-03-19 01:02:04 +01:00
|
|
|
const device_t *
|
2017-05-06 17:48:33 +02:00
|
|
|
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)
|
|
|
|
|
{
|
2018-03-19 01:02:04 +01:00
|
|
|
return((char *)net_cards[card].internal_name);
|
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_get_from_internal_name(char *s)
|
|
|
|
|
{
|
|
|
|
|
int c = 0;
|
|
|
|
|
|
2018-03-19 01:02:04 +01:00
|
|
|
while (strlen((char *)net_cards[c].internal_name)) {
|
|
|
|
|
if (! strcmp((char *)net_cards[c].internal_name, s))
|
2017-05-06 17:48:33 +02:00
|
|
|
return(c);
|
|
|
|
|
c++;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 21:56:31 +02:00
|
|
|
return(-1);
|
2017-05-06 17:48:33 +02:00
|
|
|
}
|
2019-11-14 20:59:51 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
network_set_wait(int wait)
|
|
|
|
|
{
|
2019-11-14 21:22:54 +01:00
|
|
|
network_wait(1);
|
|
|
|
|
net_wait = wait;
|
|
|
|
|
network_wait(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
network_get_wait(void)
|
|
|
|
|
{
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
network_wait(1);
|
|
|
|
|
ret = net_wait;
|
|
|
|
|
network_wait(0);
|
|
|
|
|
return ret;
|
2019-11-14 20:59:51 +01:00
|
|
|
}
|