2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
2011-02-25 01:05:47 +03:00
|
|
|
// $Id$
|
2001-10-03 17:10:38 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
2013-08-20 21:43:24 +04:00
|
|
|
// Copyright (C) 2001-2013 The Bochs Project
|
2001-04-10 05:04:59 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
2009-02-08 12:05:52 +03:00
|
|
|
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2009-02-08 00:05:31 +03:00
|
|
|
//
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-08-16 21:31:16 +04:00
|
|
|
// Peter Grehan (grehan@iprg.nokia.com) coded the initial version of the
|
2001-04-10 05:04:59 +04:00
|
|
|
// NE2000/ether stuff.
|
|
|
|
|
2011-08-16 21:31:16 +04:00
|
|
|
// netmod.h - see eth_null.cc for implementation details
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-08-16 21:31:16 +04:00
|
|
|
#ifndef BX_NETMOD_H
|
|
|
|
#define BX_NETMOD_H
|
|
|
|
|
2017-02-28 01:26:43 +03:00
|
|
|
#ifndef BXHUB
|
2011-08-16 21:31:16 +04:00
|
|
|
// Pseudo device that loads the lowlevel networking module
|
|
|
|
class bx_netmod_ctl_c : public bx_netmod_ctl_stub_c {
|
|
|
|
public:
|
2013-12-29 16:56:52 +04:00
|
|
|
bx_netmod_ctl_c();
|
2011-08-16 21:31:16 +04:00
|
|
|
virtual ~bx_netmod_ctl_c() {}
|
2011-12-17 12:22:33 +04:00
|
|
|
virtual void* init_module(bx_list_c *base, void* rxh, void* rxstat, bx_devmodel_c *dev);
|
2011-08-16 21:31:16 +04:00
|
|
|
};
|
2017-02-28 01:26:43 +03:00
|
|
|
#endif
|
2004-10-03 23:30:36 +04:00
|
|
|
|
2004-10-07 21:38:03 +04:00
|
|
|
#define BX_PACKET_BUFSIZE 2048 // Enough for an ether frame
|
|
|
|
|
2011-12-17 12:22:33 +04:00
|
|
|
// device receive status definitions
|
|
|
|
#define BX_NETDEV_RXREADY 0x0001
|
2011-12-18 13:12:38 +04:00
|
|
|
#define BX_NETDEV_SPEED 0x000e
|
2011-12-17 12:22:33 +04:00
|
|
|
#define BX_NETDEV_10MBIT 0x0002
|
|
|
|
#define BX_NETDEV_100MBIT 0x0004
|
2011-12-18 13:12:38 +04:00
|
|
|
#define BX_NETDEV_1GBIT 0x0008
|
2011-12-17 12:22:33 +04:00
|
|
|
|
2013-08-20 21:43:24 +04:00
|
|
|
// this should not be smaller than an arp reply with an ethernet header
|
|
|
|
#define MIN_RX_PACKET_LEN 60
|
|
|
|
|
|
|
|
#define ETHERNET_MAC_ADDR_LEN 6
|
|
|
|
#define ETHERNET_TYPE_IPV4 0x0800
|
|
|
|
#define ETHERNET_TYPE_ARP 0x0806
|
|
|
|
|
2013-09-29 13:08:24 +04:00
|
|
|
#define TFTP_BUFFER_SIZE 1024
|
2012-08-16 15:59:44 +04:00
|
|
|
|
2013-08-20 21:43:24 +04:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma pack(push, 1)
|
|
|
|
#elif defined(__MWERKS__) && defined(macintosh)
|
|
|
|
#pragma options align=packed
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct ethernet_header {
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER>=1300)
|
|
|
|
__declspec(align(1))
|
|
|
|
#endif
|
|
|
|
Bit8u dst_mac_addr[ETHERNET_MAC_ADDR_LEN];
|
|
|
|
Bit8u src_mac_addr[ETHERNET_MAC_ADDR_LEN];
|
|
|
|
Bit16u type;
|
|
|
|
}
|
|
|
|
#if !defined(_MSC_VER)
|
|
|
|
GCC_ATTRIBUTE((packed))
|
|
|
|
#endif
|
|
|
|
ethernet_header_t;
|
|
|
|
|
2013-08-22 15:53:40 +04:00
|
|
|
typedef struct ip_header {
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER>=1300)
|
|
|
|
__declspec(align(1))
|
|
|
|
#endif
|
|
|
|
#ifdef BX_LITTLE_ENDIAN
|
|
|
|
Bit8u header_len : 4;
|
|
|
|
Bit8u version : 4;
|
|
|
|
#else
|
|
|
|
Bit8u version : 4;
|
|
|
|
Bit8u header_len : 4;
|
|
|
|
#endif
|
|
|
|
Bit8u tos;
|
|
|
|
Bit16u total_len;
|
|
|
|
Bit16u id;
|
|
|
|
Bit16u frag_offs;
|
|
|
|
Bit8u ttl;
|
|
|
|
Bit8u protocol;
|
|
|
|
Bit16u checksum;
|
|
|
|
Bit32u src_addr;
|
|
|
|
Bit32u dst_addr;
|
|
|
|
}
|
|
|
|
#if !defined(_MSC_VER)
|
|
|
|
GCC_ATTRIBUTE((packed))
|
|
|
|
#endif
|
|
|
|
ip_header_t;
|
|
|
|
|
|
|
|
typedef struct udp_header {
|
|
|
|
#if defined(_MSC_VER) && (_MSC_VER>=1300)
|
|
|
|
__declspec(align(1))
|
|
|
|
#endif
|
|
|
|
Bit16u src_port;
|
|
|
|
Bit16u dst_port;
|
|
|
|
Bit16u length;
|
|
|
|
Bit16u checksum;
|
|
|
|
}
|
|
|
|
#if !defined(_MSC_VER)
|
|
|
|
GCC_ATTRIBUTE((packed))
|
|
|
|
#endif
|
|
|
|
udp_header_t;
|
|
|
|
|
2013-08-20 21:43:24 +04:00
|
|
|
#if defined(_MSC_VER)
|
|
|
|
#pragma pack(pop)
|
|
|
|
#elif defined(__MWERKS__) && defined(macintosh)
|
|
|
|
#pragma options align=reset
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 05:04:59 +04:00
|
|
|
typedef void (*eth_rx_handler_t)(void *arg, const void *buf, unsigned len);
|
2011-12-17 12:22:33 +04:00
|
|
|
typedef Bit32u (*eth_rx_status_t)(void *arg);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
2011-03-01 23:47:12 +03:00
|
|
|
typedef struct {
|
|
|
|
Bit8u host_macaddr[6];
|
|
|
|
Bit8u guest_macaddr[6];
|
|
|
|
Bit8u host_ipv4addr[4];
|
|
|
|
const Bit8u *default_guest_ipv4addr;
|
|
|
|
Bit8u guest_ipv4addr[4];
|
|
|
|
Bit8u dns_ipv4addr[4];
|
|
|
|
} dhcp_cfg_t;
|
|
|
|
|
2004-09-18 16:35:13 +04:00
|
|
|
static const Bit8u broadcast_macaddr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
|
|
|
|
|
2017-02-28 01:26:43 +03:00
|
|
|
#ifndef BXHUB
|
2011-03-01 23:47:12 +03:00
|
|
|
int execute_script(bx_devmodel_c *netdev, const char *name, char* arg1);
|
2009-04-19 21:25:40 +04:00
|
|
|
void write_pktlog_txt(FILE *pktlog_txt, const Bit8u *buf, unsigned len, bx_bool host_to_guest);
|
2017-02-28 01:26:43 +03:00
|
|
|
#endif
|
2011-03-01 23:47:12 +03:00
|
|
|
|
2011-12-14 00:53:44 +04:00
|
|
|
BX_CPP_INLINE Bit16u get_net2(const Bit8u *buf)
|
|
|
|
{
|
|
|
|
return (((Bit16u)*buf) << 8) |
|
|
|
|
((Bit16u)*(buf+1));
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE void put_net2(Bit8u *buf,Bit16u data)
|
|
|
|
{
|
|
|
|
*buf = (Bit8u)(data >> 8);
|
|
|
|
*(buf+1) = (Bit8u)(data & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE Bit32u get_net4(const Bit8u *buf)
|
|
|
|
{
|
|
|
|
return (((Bit32u)*buf) << 24) |
|
|
|
|
(((Bit32u)*(buf+1)) << 16) |
|
|
|
|
(((Bit32u)*(buf+2)) << 8) |
|
|
|
|
((Bit32u)*(buf+3));
|
|
|
|
}
|
|
|
|
|
|
|
|
BX_CPP_INLINE void put_net4(Bit8u *buf,Bit32u data)
|
|
|
|
{
|
|
|
|
*buf = (Bit8u)((data >> 24) & 0xff);
|
|
|
|
*(buf+1) = (Bit8u)((data >> 16) & 0xff);
|
|
|
|
*(buf+2) = (Bit8u)((data >> 8) & 0xff);
|
|
|
|
*(buf+3) = (Bit8u)(data & 0xff);
|
|
|
|
}
|
|
|
|
|
2011-02-28 00:04:09 +03:00
|
|
|
Bit16u ip_checksum(const Bit8u *buf, unsigned buf_len);
|
2017-02-28 01:26:43 +03:00
|
|
|
#ifdef BXHUB
|
|
|
|
int process_dhcp(const Bit8u *data, unsigned data_len, Bit8u *reply, dhcp_cfg_t *dhcp);
|
|
|
|
int process_tftp(const Bit8u *data, unsigned data_len, Bit16u req_tid, Bit8u *reply, const char *tftp_rootdir);
|
|
|
|
#else
|
2011-03-01 23:47:12 +03:00
|
|
|
int process_dhcp(bx_devmodel_c *netdev, const Bit8u *data, unsigned data_len, Bit8u *reply, dhcp_cfg_t *dhcp);
|
2013-09-27 15:47:59 +04:00
|
|
|
int process_tftp(bx_devmodel_c *netdev, const Bit8u *data, unsigned data_len, Bit16u req_tid, Bit8u *reply, const char *tftp_rootdir);
|
2001-04-10 05:04:59 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// The eth_pktmover class is used by ethernet chip emulations
|
|
|
|
// to interface to the outside world. An instance of this
|
|
|
|
// would allow frames to be sent to and received from some
|
|
|
|
// entity. An example would be the packet filter on a Unix
|
|
|
|
// system, an NDIS driver in promisc mode on WinNT, or maybe
|
|
|
|
// a simulated network that talks to another process.
|
|
|
|
//
|
2002-09-02 20:56:24 +04:00
|
|
|
class eth_pktmover_c {
|
2001-04-10 05:04:59 +04:00
|
|
|
public:
|
|
|
|
virtual void sendpkt(void *buf, unsigned io_len) = 0;
|
2006-03-08 00:11:20 +03:00
|
|
|
virtual ~eth_pktmover_c () {}
|
2001-04-10 05:04:59 +04:00
|
|
|
protected:
|
2009-04-13 17:33:11 +04:00
|
|
|
bx_devmodel_c *netdev;
|
2001-04-10 05:04:59 +04:00
|
|
|
eth_rx_handler_t rxh; // receive callback
|
2011-12-17 12:22:33 +04:00
|
|
|
eth_rx_status_t rxstat; // receive status callback
|
2001-04-10 05:04:59 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// The eth_locator class is used by pktmover classes to register
|
|
|
|
// their name. Chip emulations use the static 'create' method
|
|
|
|
// to locate and instantiate a pktmover class.
|
|
|
|
//
|
|
|
|
class eth_locator_c {
|
|
|
|
public:
|
|
|
|
static eth_pktmover_c *create(const char *type, const char *netif,
|
2009-04-13 17:33:11 +04:00
|
|
|
const char *macaddr,
|
|
|
|
eth_rx_handler_t rxh,
|
2011-12-17 12:22:33 +04:00
|
|
|
eth_rx_status_t rxstat,
|
2009-04-13 17:33:11 +04:00
|
|
|
bx_devmodel_c *dev,
|
|
|
|
const char *script);
|
2001-04-10 05:04:59 +04:00
|
|
|
protected:
|
|
|
|
eth_locator_c(const char *type);
|
2006-12-27 18:21:03 +03:00
|
|
|
virtual ~eth_locator_c() {}
|
2001-04-10 05:04:59 +04:00
|
|
|
virtual eth_pktmover_c *allocate(const char *netif,
|
2009-04-13 17:33:11 +04:00
|
|
|
const char *macaddr,
|
|
|
|
eth_rx_handler_t rxh,
|
2011-12-17 12:22:33 +04:00
|
|
|
eth_rx_status_t rxstat,
|
2009-04-13 17:33:11 +04:00
|
|
|
bx_devmodel_c *dev,
|
|
|
|
const char *script) = 0;
|
2001-04-10 05:04:59 +04:00
|
|
|
private:
|
|
|
|
static eth_locator_c *all;
|
|
|
|
eth_locator_c *next;
|
|
|
|
const char *type;
|
|
|
|
};
|
|
|
|
|
2004-10-03 23:30:36 +04:00
|
|
|
#endif
|
2017-02-28 01:26:43 +03:00
|
|
|
|
|
|
|
#endif
|