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
|
|
|
*
|
|
|
|
|
* Definitions for the network module.
|
|
|
|
|
*
|
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>
|
2018-03-19 01:02:04 +01: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
|
|
|
*/
|
2022-02-18 19:42:21 -05:00
|
|
|
|
2017-06-04 02:11:19 -04:00
|
|
|
#ifndef EMU_NETWORK_H
|
|
|
|
|
# define EMU_NETWORK_H
|
2017-05-06 17:48:33 +02:00
|
|
|
# include <stdint.h>
|
|
|
|
|
|
|
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
/* Network provider types. */
|
|
|
|
|
#define NET_TYPE_NONE 0 /* networking disabled */
|
2022-08-21 16:55:47 +02:00
|
|
|
#define NET_TYPE_SLIRP 1 /* use the SLiRP port forwarder */
|
|
|
|
|
#define NET_TYPE_PCAP 2 /* use the (Win)Pcap API */
|
|
|
|
|
|
|
|
|
|
#define NET_MAX_FRAME 1518
|
|
|
|
|
#define NET_QUEUE_LEN 8
|
|
|
|
|
#define NET_CARD_MAX 4
|
2022-08-25 00:43:48 +02:00
|
|
|
#define NET_HOST_INTF_MAX 64
|
2017-05-18 01:57:16 -04:00
|
|
|
|
|
|
|
|
/* Supported network cards. */
|
2018-01-28 03:15:01 +01:00
|
|
|
enum {
|
2018-03-19 01:02:04 +01:00
|
|
|
NONE = 0,
|
|
|
|
|
NE1000,
|
|
|
|
|
NE2000,
|
|
|
|
|
RTL8019AS,
|
|
|
|
|
RTL8029AS
|
2018-01-28 03:15:01 +01:00
|
|
|
};
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2022-08-21 16:55:47 +02:00
|
|
|
enum {
|
|
|
|
|
NET_QUEUE_RX,
|
|
|
|
|
NET_QUEUE_TX_VM,
|
|
|
|
|
NET_QUEUE_TX_HOST
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
|
int device_num;
|
|
|
|
|
int net_type;
|
|
|
|
|
char host_dev_name[128];
|
|
|
|
|
} netcard_conf_t;
|
|
|
|
|
|
|
|
|
|
extern netcard_conf_t net_cards_conf[NET_CARD_MAX];
|
|
|
|
|
extern int net_card_current;
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2020-11-16 00:01:21 +01:00
|
|
|
typedef int (*NETRXCB)(void *, uint8_t *, int);
|
2020-02-29 19:12:23 +01:00
|
|
|
typedef int (*NETWAITCB)(void *);
|
2020-04-20 19:02:13 +02:00
|
|
|
typedef int (*NETSETLINKSTATE)(void *);
|
2017-05-08 04:54:17 +02:00
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2020-04-29 23:39:54 +02:00
|
|
|
typedef struct netpkt {
|
2022-08-21 16:55:47 +02:00
|
|
|
uint8_t *data;
|
2020-04-29 23:39:54 +02:00
|
|
|
int len;
|
2022-08-21 16:55:47 +02:00
|
|
|
uint64_t tsc;
|
2020-04-29 23:39:54 +02:00
|
|
|
} netpkt_t;
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
typedef struct {
|
2022-08-21 16:55:47 +02:00
|
|
|
netpkt_t packets[NET_QUEUE_LEN];
|
|
|
|
|
int size;
|
|
|
|
|
int head;
|
|
|
|
|
int tail;
|
|
|
|
|
} netqueue_t;
|
|
|
|
|
|
|
|
|
|
typedef struct _netcard_t netcard_t;
|
|
|
|
|
|
|
|
|
|
typedef struct netdrv_t {
|
|
|
|
|
void (*notify_in)(void *priv);
|
|
|
|
|
void *(*init)(const netcard_t *card, const uint8_t *mac_addr, void *priv);
|
|
|
|
|
void (*close)(void *priv);
|
|
|
|
|
void *priv;
|
|
|
|
|
} netdrv_t;
|
|
|
|
|
|
|
|
|
|
extern const netdrv_t net_pcap_drv;
|
|
|
|
|
extern const netdrv_t net_slirp_drv;
|
|
|
|
|
|
|
|
|
|
struct _netcard_t {
|
|
|
|
|
const device_t *device;
|
|
|
|
|
void *card_drv;
|
|
|
|
|
struct netdrv_t host_drv;
|
|
|
|
|
int (*poll)(void *);
|
|
|
|
|
NETRXCB rx;
|
|
|
|
|
NETWAITCB wait;
|
|
|
|
|
NETSETLINKSTATE set_link_state;
|
|
|
|
|
netqueue_t queues[3];
|
|
|
|
|
netpkt_t queued_pkt;
|
|
|
|
|
mutex_t *tx_mutex;
|
|
|
|
|
mutex_t *rx_mutex;
|
|
|
|
|
pc_timer_t timer;
|
|
|
|
|
};
|
2017-05-12 05:05:20 -04:00
|
|
|
|
|
|
|
|
typedef struct {
|
2018-03-19 01:02:04 +01:00
|
|
|
char device[128];
|
|
|
|
|
char description[128];
|
2017-05-12 05:05:20 -04:00
|
|
|
} netdev_t;
|
|
|
|
|
|
|
|
|
|
|
2017-11-02 02:28:00 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
extern "C" {
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
/* Global variables. */
|
2017-10-29 04:20:20 -05:00
|
|
|
extern int nic_do_log; /* config */
|
2017-05-18 01:57:16 -04:00
|
|
|
extern int network_ndev;
|
2022-08-25 00:43:48 +02:00
|
|
|
extern netdev_t network_devs[NET_HOST_INTF_MAX];
|
2017-05-17 21:56:31 +02:00
|
|
|
|
2017-05-12 05:05:20 -04:00
|
|
|
|
|
|
|
|
/* Function prototypes. */
|
2017-05-06 17:48:33 +02:00
|
|
|
extern void network_init(void);
|
2022-08-21 16:55:47 +02:00
|
|
|
extern netcard_t *network_attach(void *card_drv, uint8_t *mac, NETRXCB rx, NETWAITCB wait, NETSETLINKSTATE set_link_state);
|
|
|
|
|
extern void netcard_close(netcard_t *card);
|
2017-05-12 05:05:20 -04:00
|
|
|
extern void network_close(void);
|
2017-05-06 17:48:33 +02:00
|
|
|
extern void network_reset(void);
|
2017-10-29 04:20:20 -05:00
|
|
|
extern int network_available(void);
|
2022-08-21 16:55:47 +02:00
|
|
|
extern void network_tx(netcard_t *card, uint8_t *, int);
|
2017-05-12 05:05:20 -04:00
|
|
|
|
2017-10-29 04:20:20 -05:00
|
|
|
extern int net_pcap_prepare(netdev_t *);
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-05-18 01:57:16 -04:00
|
|
|
extern int network_dev_to_id(char *);
|
2017-05-12 05:05:20 -04:00
|
|
|
extern int network_card_available(int);
|
|
|
|
|
extern int network_card_has_config(int);
|
|
|
|
|
extern char *network_card_get_internal_name(int);
|
|
|
|
|
extern int network_card_get_from_internal_name(char *);
|
2018-03-19 01:02:04 +01:00
|
|
|
extern const device_t *network_card_getdevice(int);
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2022-08-21 16:55:47 +02:00
|
|
|
extern int network_tx_pop(netcard_t *card, netpkt_t *out_pkt);
|
|
|
|
|
extern int network_rx_put(netcard_t *card, uint8_t *bufp, int len);
|
2017-11-02 02:28:00 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-05-06 17:48:33 +02:00
|
|
|
|
2017-06-04 02:11:19 -04:00
|
|
|
#endif /*EMU_NETWORK_H*/
|