Bochs/bochs/iodev/eth_win32.cc

550 lines
12 KiB
C++
Raw Normal View History

2001-10-03 17:34:55 +04:00
/////////////////////////////////////////////////////////////////////////
2001-11-17 02:10:59 +03:00
// $Id: eth_win32.cc,v 1.5 2001-11-16 23:10:59 vruppert Exp $
2001-10-03 17:34:55 +04:00
/////////////////////////////////////////////////////////////////////////
//
2001-10-01 07:50:50 +04:00
// Copyright (C) 2001 MandrakeSoft S.A.
//
// MandrakeSoft S.A.
// 43, rue d'Aboukir
// 75002 Paris - France
// http://www.linux-mandrake.com/
// http://www.mandrakesoft.com/
//
// 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
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2001-10-03 17:34:55 +04:00
//
2001-10-01 07:50:50 +04:00
// eth_win32.cc - skeleton code for an ethernet pktmover
// All win32 coding by Don Becker <x-odus@iname.com>
//
// Various networking docs:
// http://www.graphcomp.com/info/rfc/
// rfc0826: arp
// rfc0903: rarp
//
2001-10-03 17:38:17 +04:00
// For ethernet support under win32 to work, you must install WinPCap.
// Download it from http://netgroup-serv.polito.it/winpcap
2001-10-01 07:50:50 +04:00
#include <windows.h>
#include "bochs.h"
#define LOG_THIS bx_ne2k.
#define NDIS_PACKET_TYPE_PROMISCUOUS 0x0020
#define Packet_ALIGNMENT sizeof(int)
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
typedef int bpf_int32;
typedef u_int bpf_u_int32;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
/*
* The instruction encondings.
*/
/* instruction classes */
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
#define BPF_CLASS(code) ((code) & 0x07)
#define BPF_LD 0x00
#define BPF_LDX 0x01
#define BPF_ST 0x02
#define BPF_STX 0x03
#define BPF_ALU 0x04
#define BPF_JMP 0x05
#define BPF_RET 0x06
#define BPF_MISC 0x07
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
/* ld/ldx fields */
#define BPF_SIZE(code) ((code) & 0x18)
#define BPF_W 0x00
#define BPF_H 0x08
#define BPF_B 0x10
#define BPF_MODE(code) ((code) & 0xe0)
#define BPF_IMM 0x00
#define BPF_ABS 0x20
#define BPF_IND 0x40
#define BPF_MEM 0x60
#define BPF_LEN 0x80
#define BPF_MSH 0xa0
/* alu/jmp fields */
#define BPF_OP(code) ((code) & 0xf0)
#define BPF_ADD 0x00
#define BPF_SUB 0x10
#define BPF_MUL 0x20
#define BPF_DIV 0x30
#define BPF_OR 0x40
#define BPF_AND 0x50
#define BPF_LSH 0x60
#define BPF_RSH 0x70
#define BPF_NEG 0x80
#define BPF_JA 0x00
#define BPF_JEQ 0x10
#define BPF_JGT 0x20
#define BPF_JGE 0x30
#define BPF_JSET 0x40
#define BPF_SRC(code) ((code) & 0x08)
#define BPF_K 0x00
#define BPF_X 0x08
/* ret - BPF_K and BPF_X also apply */
#define BPF_RVAL(code) ((code) & 0x18)
#define BPF_A 0x10
/* misc */
#define BPF_MISCOP(code) ((code) & 0xf8)
#define BPF_TAX 0x00
#define BPF_TXA 0x80
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
/*
* The instruction data structure.
*/
struct bpf_insn {
u_short code;
u_char jt;
u_char jf;
bpf_int32 k;
};
struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;
};
struct bpf_hdr {
struct timeval bh_tstamp; /* time stamp */
UINT bh_caplen; /* length of captured portion */
UINT bh_datalen; /* original length of packet */
USHORT bh_hdrlen; /* length of bpf header (this struct
plus alignment padding) */
};
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
#define MAX_LINK_NAME_LENGTH 64
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
typedef struct _ADAPTER {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
HANDLE hFile;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
TCHAR SymbolicLink[MAX_LINK_NAME_LENGTH];
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
int NumWrites;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
HANDLE ReadEvent;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
} ADAPTER, *LPADAPTER;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
typedef struct _PACKET {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
HANDLE hEvent;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
OVERLAPPED OverLapped;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PVOID Buffer;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
UINT Length;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
UINT ulBytesReceived;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN bIoComplete;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
} PACKET, *LPPACKET;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
HINSTANCE hPacket;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
LPADAPTER lpAdapterRX = 0;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
LPADAPTER lpAdapterTX = 0;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
LPPACKET pkSend;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
LPPACKET pkRecv;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
char buffer[256000];
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
DWORD dwVersion, dwMajorVersion;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
char AdapterList[10][1024];
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
char cMacAddr[6];
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
void *rx_Arg;
2001-10-03 17:34:55 +04:00
char netdev[512];
2001-10-01 07:50:50 +04:00
eth_rx_handler_t rx_handler;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
LPADAPTER (*PacketOpenAdapter) (LPTSTR);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
VOID (*PacketCloseAdapter) (LPADAPTER);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN (*PacketSetHwFilter) (LPADAPTER, ULONG);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN (*PacketSetBpf) (LPADAPTER, struct bpf_program *);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN (*PacketGetAdapterNames) (PTSTR, PULONG);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN (*PacketSendPacket) (LPADAPTER, LPPACKET, BOOLEAN);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN (*PacketReceivePacket) (LPADAPTER, LPPACKET, BOOLEAN);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN (*PacketSetBuff) (LPADAPTER, int);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BOOLEAN (*PacketSetReadTimeout) (LPADAPTER, int);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
LPPACKET (*PacketAllocatePacket) (void);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
VOID (*PacketInitPacket) (LPPACKET, PVOID, UINT);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
VOID (*PacketFreePacket) (LPPACKET);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// template filter for a unicast mac address and all
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// multicast/broadcast frames
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
static const struct bpf_insn macfilter[] = {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_STMT(BPF_LD|BPF_W|BPF_ABS, 2),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 0xaaaaaaaa, 0, 2),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_STMT(BPF_LD|BPF_H|BPF_ABS, 0),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_JUMP(BPF_JMP|BPF_JEQ|BPF_K, 0x0000aaaa, 2, 0),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_STMT(BPF_LD|BPF_B|BPF_ABS, 0),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_JUMP(BPF_JMP|BPF_JSET|BPF_K, 0x01, 0, 1),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_STMT(BPF_RET, 1514),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BPF_STMT(BPF_RET, 0),
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
};
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
//
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// Define the class. This is private to this module
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
//
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
class bx_win32_pktmover_c : public eth_pktmover_c {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
public:
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
bx_win32_pktmover_c(const char *netif, const char *macaddr,
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
eth_rx_handler_t rxh,
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
void *rxarg);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
void sendpkt(void *buf, unsigned io_len);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
private:
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
struct bpf_insn filter[8];
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
int rx_timer_index;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
static void rx_timer_handler(void *);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
};
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
//
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// Define the static class that registers the derived pktmover class,
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// and allocates one on request.
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
//
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
class bx_win32_locator_c : public eth_locator_c {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
public:
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
bx_win32_locator_c(void) : eth_locator_c("win32") {}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
protected:
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
eth_pktmover_c *allocate(const char *netif, const char *macaddr, eth_rx_handler_t rxh, void *rxarg) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
return (new bx_win32_pktmover_c(netif, macaddr, rxh, rxarg));
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
} bx_win32_match;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
//
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// Define the methods for the bx_win32_pktmover derived class
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
//
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// the constructor
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
bx_win32_pktmover_c::bx_win32_pktmover_c(const char *netif,
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
const char *macaddr,
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
eth_rx_handler_t rxh,
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
void *rxarg)
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
{
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// Open Packet Driver Here.
2001-10-03 17:34:55 +04:00
DWORD dwVersion;
DWORD dwWindowsMajorVersion;
2001-10-01 07:50:50 +04:00
struct bpf_program bp;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BX_INFO(("bx_win32_pktmover_c"));
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
rx_Arg = rxarg;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
rx_handler = rxh;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
hPacket = LoadLibrary("PACKET.DLL");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
memcpy(cMacAddr, macaddr, 6);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
if(hPacket) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketOpenAdapter = (LPADAPTER (*)(LPTSTR)) GetProcAddress(hPacket, "PacketOpenAdapter");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketCloseAdapter = (VOID (*)(LPADAPTER)) GetProcAddress(hPacket, "PacketCloseAdapter");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetHwFilter = (BOOLEAN (*)(LPADAPTER, ULONG)) GetProcAddress(hPacket, "PacketSetHwFilter");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetBpf = (BOOLEAN (*)(LPADAPTER, struct bpf_program *)) GetProcAddress(hPacket, "PacketSetBpf");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketGetAdapterNames = (BOOLEAN (*)(PTSTR, PULONG)) GetProcAddress(hPacket, "PacketGetAdapterNames");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSendPacket = (BOOLEAN (*)(LPADAPTER, LPPACKET, BOOLEAN)) GetProcAddress(hPacket, "PacketSendPacket");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketReceivePacket = (BOOLEAN (*)(LPADAPTER, LPPACKET, BOOLEAN)) GetProcAddress(hPacket, "PacketReceivePacket");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetBuff = (BOOLEAN (*)(LPADAPTER, int)) GetProcAddress(hPacket, "PacketSetBuff");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetReadTimeout = (BOOLEAN (*)(LPADAPTER, int)) GetProcAddress(hPacket, "PacketSetReadTimeout");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketAllocatePacket = (LPPACKET (*)(void)) GetProcAddress(hPacket, "PacketAllocatePacket");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketInitPacket = (VOID (*)(LPPACKET, PVOID, UINT)) GetProcAddress(hPacket, "PacketInitPacket");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketFreePacket = (VOID (*)(LPPACKET)) GetProcAddress(hPacket, "PacketFreePacket");
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
} else {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BX_PANIC(("Could not load WPCap Drivers for ethernet support!"));
2001-10-03 17:34:55 +04:00
}
2001-10-01 07:50:50 +04:00
2001-10-03 17:34:55 +04:00
memset(&netdev, 0, sizeof(netdev));
dwVersion=GetVersion();
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
if (!(dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4))
{ // Windows NT/2k
2001-11-17 02:10:59 +03:00
int nLen = MultiByteToWideChar(CP_ACP, 0, netif, -1, NULL, 0);
MultiByteToWideChar(CP_ACP, 0, netif, -1, (WCHAR *)netdev, nLen);
2001-10-03 17:34:55 +04:00
} else { // Win9x
strcpy(netdev, netif);
}
lpAdapterRX = PacketOpenAdapter(netdev);
2001-10-01 07:50:50 +04:00
if(!lpAdapterRX || (lpAdapterRX->hFile == INVALID_HANDLE_VALUE)) {
BX_PANIC(("Could not open adapter for ethernet reception"));
return;
}
2001-10-03 17:34:55 +04:00
lpAdapterTX = PacketOpenAdapter(netdev);
2001-10-01 07:50:50 +04:00
if(!lpAdapterTX || (lpAdapterTX->hFile == INVALID_HANDLE_VALUE)) {
BX_PANIC(("Could not open adapter for ethernet transmition"));
return;
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetHwFilter(lpAdapterRX, NDIS_PACKET_TYPE_PROMISCUOUS);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetHwFilter(lpAdapterTX, NDIS_PACKET_TYPE_PROMISCUOUS);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
/* The code below sets a BPF mac address filter
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
that seems to really kill performance, for now
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
im just using code to filter, and it works
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
better
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
*/
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// memcpy(&this->filter, macfilter, sizeof(macfilter));
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// this->filter[1].k = (macaddr[2] & 0xff) << 24 | (macaddr[3] & 0xff) << 16 | (macaddr[4] & 0xff) << 8 | (macaddr[5] & 0xff);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// this->filter[3].k = (macaddr[0] & 0xff) << 8 | (macaddr[1] & 0xff);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// bp.bf_len = 8;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// bp.bf_insns = &this->filter[0];
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// if(!PacketSetBpf(lpAdapterRX, &bp)) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// BX_PANIC(("Could not set mac address BPF filter"));
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// }
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetBuff(lpAdapterRX, 512000);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetReadTimeout(lpAdapterRX, 1000);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetBuff(lpAdapterTX, 512000);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketSetReadTimeout(lpAdapterTX, 1000);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
if((pkSend = PacketAllocatePacket()) == NULL) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BX_PANIC(("Could not allocate a send packet"));
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
if((pkRecv = PacketAllocatePacket()) == NULL) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
BX_PANIC(("Could not allocate a recv packet"));
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
rx_timer_index = bx_pc_system.register_timer(this, this->rx_timer_handler, 10000, 1, 1);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
void
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
bx_win32_pktmover_c::sendpkt(void *buf, unsigned io_len)
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
{
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// SendPacket Here.
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
fprintf(stderr, "[ETH-WIN32] Sending Packet: size=%i\n", io_len);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketInitPacket(pkSend, (char *)buf, io_len);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
if(!PacketSendPacket(lpAdapterTX, pkSend, TRUE)) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
fprintf(stderr, "[ETH-WIN32] Error sending packet: %lu\n", GetLastError());
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
void bx_win32_pktmover_c::rx_timer_handler (void *this_ptr)
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
{
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
// Recieve Packet ????
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
char *pBuf;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
unsigned char *pPacket;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
unsigned int iOffset = 0;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
struct bpf_hdr *hdr;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
static unsigned char bcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketInitPacket(pkRecv, (char *)buffer, 256000);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
PacketReceivePacket(lpAdapterRX, pkRecv, TRUE);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
pBuf = (char *)pkRecv->Buffer;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
iOffset = 0;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
while(iOffset < pkRecv->ulBytesReceived) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
hdr = (struct bpf_hdr *)(pBuf + iOffset);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
pPacket = (unsigned char *)(pBuf + iOffset + hdr->bh_hdrlen);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
if(memcmp(pPacket + 6, cMacAddr, 6) == 0) return;
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
if(memcmp(pPacket, cMacAddr, 6) == 0 || memcmp(pPacket, bcast_addr, 6) == 0 || pPacket[0] & 0x01) {
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
fprintf(stderr, "[ETH-WIN32] packet: size=%i, dst=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, src=%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", hdr->bh_caplen, pPacket[0], pPacket[1], pPacket[2], pPacket[3], pPacket[4], pPacket[5], pPacket[6], pPacket[7], pPacket[8], pPacket[9], pPacket[10], pPacket[11]);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
(*rx_handler)(rx_Arg, pPacket, hdr->bh_caplen);
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
iOffset = Packet_WORDALIGN(iOffset + (hdr->bh_hdrlen + hdr->bh_caplen));
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00
2001-10-01 07:50:50 +04:00
}
2001-10-03 17:34:55 +04:00