Include dev9ghzdrk into the main plugins folder, and integrate it into the build system (windows only).

Most of the work done by Rama, I just integrated the vcxproj.

Only done for vs2010, vs2008 or vs2012 will have to wait.

git-svn-id: http://pcsx2.googlecode.com/svn/trunk@5595 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
gigaherz 2013-03-19 22:01:41 +00:00
parent 6d456b8a69
commit 90f0da8ec2
62 changed files with 16314 additions and 0 deletions

View File

@ -114,6 +114,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "USBqemu", "plugins\USBqemu\
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZZOgl-cg", "plugins\zzogl-pg-cg\opengl\Win32\zerogsogl-cg.vcxproj", "{019773FA-2DAA-4C12-9511-BD2D4EB2A718}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ZZOgl-cg", "plugins\zzogl-pg-cg\opengl\Win32\zerogsogl-cg.vcxproj", "{019773FA-2DAA-4C12-9511-BD2D4EB2A718}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DEV9ghzdrk", "plugins\dev9ghzdrk\Win32\DEV9ghzdrk.vcxproj", "{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug AVX|Win32 = Debug AVX|Win32 Debug AVX|Win32 = Debug AVX|Win32
@ -1221,6 +1223,39 @@ Global
{019773FA-2DAA-4C12-9511-BD2D4EB2A718}.Release|Win32.ActiveCfg = Release|Win32 {019773FA-2DAA-4C12-9511-BD2D4EB2A718}.Release|Win32.ActiveCfg = Release|Win32
{019773FA-2DAA-4C12-9511-BD2D4EB2A718}.Release|Win32.Build.0 = Release|Win32 {019773FA-2DAA-4C12-9511-BD2D4EB2A718}.Release|Win32.Build.0 = Release|Win32
{019773FA-2DAA-4C12-9511-BD2D4EB2A718}.Release|x64.ActiveCfg = Release|Win32 {019773FA-2DAA-4C12-9511-BD2D4EB2A718}.Release|x64.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug AVX|Win32.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug AVX|Win32.Build.0 = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug AVX|x64.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSE2|Win32.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSE2|Win32.Build.0 = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSE2|x64.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSE4|Win32.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSE4|Win32.Build.0 = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSE4|x64.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSSE3|Win32.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSSE3|Win32.Build.0 = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug SSSE3|x64.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug|Win32.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug|Win32.Build.0 = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Debug|x64.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Devel|Win32.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Devel|Win32.Build.0 = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Devel|x64.ActiveCfg = Debug|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release AVX|Win32.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release AVX|Win32.Build.0 = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release AVX|x64.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSE2|Win32.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSE2|Win32.Build.0 = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSE2|x64.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSE4|Win32.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSE4|Win32.Build.0 = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSE4|x64.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSSE3|Win32.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSSE3|Win32.Build.0 = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release SSSE3|x64.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release|Win32.ActiveCfg = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release|Win32.Build.0 = Release|Win32
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}.Release|x64.ActiveCfg = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -1240,6 +1275,7 @@ Global
{2D4E85B2-F47F-4D65-B091-701E5C031DAC} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF} {2D4E85B2-F47F-4D65-B091-701E5C031DAC} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF}
{E613DA9F-41B4-4613-9911-E418EF5533BC} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF} {E613DA9F-41B4-4613-9911-E418EF5533BC} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF}
{019773FA-2DAA-4C12-9511-BD2D4EB2A718} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF} {019773FA-2DAA-4C12-9511-BD2D4EB2A718} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF}
{BBE4E5FB-530A-4D18-A633-35AF0577B7F3} = {703FD00B-D7A0-41E3-BD03-CEC86B385DAF}
{E9B51944-7E6D-4BCD-83F2-7BBD5A46182D} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38} {E9B51944-7E6D-4BCD-83F2-7BBD5A46182D} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{2F6C0388-20CB-4242-9F6C-A6EBB6A83F47} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38} {2F6C0388-20CB-4242-9F6C-A6EBB6A83F47} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}
{F4EB4AB2-C595-4B05-8BC0-059024BC796C} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38} {F4EB4AB2-C595-4B05-8BC0-059024BC796C} = {78EBE642-7A4D-4EA7-86BE-5639C6646C38}

612
plugins/dev9ghzdrk/DEV9.cpp Normal file
View File

@ -0,0 +1,612 @@
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <winsock2.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <Winioctl.h>
#include <fcntl.h>
#include <windows.h>
#include <stdarg.h>
#define EXTERN
#include "DEV9.h"
#undef EXTERN
#include "Config.h"
#include "smap.h"
#include "ata.h"
#ifdef __WIN32__
#pragma warning(disable:4244)
HINSTANCE hInst=NULL;
#endif
//#define HDD_48BIT
u8 eeprom[] = {
//0x6D, 0x76, 0x63, 0x61, 0x31, 0x30, 0x08, 0x01,
0x76, 0x6D, 0x61, 0x63, 0x30, 0x31, 0x07, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
int Log = 1;
u32 *iopPC;
const unsigned char version = PS2E_DEV9_VERSION;
const unsigned char revision = 0;
const unsigned char build = 3; // increase that with each version
static char *libraryName = "GiGaHeRz's DEV9 Driver"
#ifdef _DEBUG
"(debug)"
#endif
;
HANDLE hEeprom;
HANDLE mapping;
u32 CALLBACK PS2EgetLibType() {
return PS2E_LT_DEV9;
}
char* CALLBACK PS2EgetLibName() {
return libraryName;
}
u32 CALLBACK PS2EgetLibVersion2(u32 type) {
return (version<<16) | (revision<<8) | build;
}
void __Log(char *fmt, ...) {
va_list list;
static int ticks=-1;
int nticks=GetTickCount();
if(ticks==-1) ticks=nticks;
// if (!Log) return;
if(iopPC!=NULL)
{
fprintf(dev9Log,"[%10d + %4d, IOP PC = %08x] ",nticks,nticks-ticks,*iopPC);
}
else
{
fprintf(dev9Log,"[%10d + %4d] ",nticks,nticks-ticks);
}
ticks=nticks;
va_start(list, fmt);
vfprintf(dev9Log, fmt, list);
va_end(list);
}
s32 CALLBACK DEV9init()
{
#ifdef DEV9_LOG_ENABLE
dev9Log = fopen("logs/dev9Log.txt", "w");
setvbuf(dev9Log, NULL, _IONBF, 0);
DEV9_LOG("DEV9init\n");
#endif
memset(&dev9, 0, sizeof(dev9));
DEV9_LOG("DEV9init2\n");
DEV9_LOG("DEV9init3\n");
FLASHinit();
hEeprom = CreateFile(
"eeprom.dat",
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_FLAG_WRITE_THROUGH,
NULL
);
if(hEeprom==INVALID_HANDLE_VALUE)
{
dev9.eeprom=(u16*)eeprom;
}
else
{
mapping=CreateFileMapping(hEeprom,NULL,PAGE_READWRITE,0,0,NULL);
if(mapping==INVALID_HANDLE_VALUE)
{
CloseHandle(hEeprom);
dev9.eeprom=(u16*)eeprom;
}
else
{
dev9.eeprom = (u16*)MapViewOfFile(mapping,FILE_MAP_WRITE,0,0,0);
if(dev9.eeprom==NULL)
{
CloseHandle(mapping);
CloseHandle(hEeprom);
dev9.eeprom=(u16*)eeprom;
}
}
}
{
int rxbi;
for(rxbi=0;rxbi<(SMAP_BD_SIZE/8);rxbi++)
{
smap_bd_t *pbd = (smap_bd_t *)&dev9.dev9R[SMAP_BD_RX_BASE & 0xffff];
pbd = &pbd[rxbi];
pbd->ctrl_stat = SMAP_BD_RX_EMPTY;
pbd->length = 0;
}
}
DEV9_LOG("DEV9init ok\n");
return 0;
}
void CALLBACK DEV9shutdown() {
DEV9_LOG("DEV9shutdown\n");
#ifdef DEV9_LOG_ENABLE
fclose(dev9Log);
#endif
}
s32 CALLBACK DEV9open(void *pDsp)
{
DEV9_LOG("DEV9open\n");
LoadConf();
DEV9_LOG("open r+: %s\n", config.Hdd);
config.HddSize = 8*1024;
iopPC = (u32*)pDsp;
#ifdef ENABLE_ATA
ata_init();
#endif
return _DEV9open();
}
void CALLBACK DEV9close()
{
DEV9_LOG("DEV9close\n");
#ifdef ENABLE_ATA
ata_term();
#endif
_DEV9close();
}
int CALLBACK _DEV9irqHandler(void)
{
//dev9Ru16(SPD_R_INTR_STAT)|= dev9.irqcause;
DEV9_LOG("_DEV9irqHandler %x, %x\n", dev9.irqcause, dev9Ru16(SPD_R_INTR_MASK));
if (dev9.irqcause & dev9Ru16(SPD_R_INTR_MASK))
return 1;
return 0;
}
DEV9handler CALLBACK DEV9irqHandler(void) {
return (DEV9handler)_DEV9irqHandler;
}
void _DEV9irq(int cause, int cycles)
{
DEV9_LOG("_DEV9irq %x, %x\n", cause, dev9Ru16(SPD_R_INTR_MASK));
dev9.irqcause|= cause;
if(cycles<1)
DEV9irq(1);
else
DEV9irq(cycles);
}
u8 CALLBACK DEV9read8(u32 addr) {
u8 hard;
if (addr>=ATA_DEV9_HDD_BASE && addr<ATA_DEV9_HDD_END)
{
#ifdef ENABLE_ATA
return ata_read<1>(addr);
#else
return 0;
#endif
}
if (addr>=SMAP_REGBASE && addr<FLASH_REGBASE)
{
//smap
return smap_read8(addr);
}
switch (addr)
{
case SPD_R_PIO_DATA:
/*if(dev9.eeprom_dir!=1)
{
hard=0;
break;
}*/
if(dev9.eeprom_state==EEPROM_TDATA)
{
if(dev9.eeprom_command==2) //read
{
if(dev9.eeprom_bit==0xFF)
hard=0;
else
hard=((dev9.eeprom[dev9.eeprom_address]<<dev9.eeprom_bit)&0x8000)>>11;
dev9.eeprom_bit++;
if(dev9.eeprom_bit==16)
{
dev9.eeprom_address++;
dev9.eeprom_bit=0;
}
}
else hard=0;
}
else hard=0;
return hard;
case DEV9_R_REV:
hard = 0x32; // expansion bay
break;
default:
if ((addr >= FLASH_REGBASE) && (addr < (FLASH_REGBASE + FLASH_REGSIZE))) {
return (u8)FLASHread32(addr, 1);
}
hard = dev9Ru8(addr);
DEV9_LOG("*Unknown 8bit read at address %lx value %x\n", addr, hard);
return hard;
}
DEV9_LOG("*Known 8bit read at address %lx value %x\n", addr, hard);
return hard;
}
u16 CALLBACK DEV9read16(u32 addr)
{
u16 hard;
if (addr>=ATA_DEV9_HDD_BASE && addr<ATA_DEV9_HDD_END)
{
#ifdef ENABLE_ATA
return ata_read<2>(addr);
#else
return 0;
#endif
}
if (addr>=SMAP_REGBASE && addr<FLASH_REGBASE)
{
//smap
return smap_read16(addr);
}
switch (addr)
{
case SPD_R_INTR_STAT:
return dev9.irqcause;
case DEV9_R_REV:
hard = 0x0030; // expansion bay
break;
case SPD_R_REV_1:
hard = 0x0011;
DEV9_LOG("STD_R_REV_1 16bit read %x\n", hard);
return hard;
case SPD_R_REV_3:
// bit 0: smap
// bit 1: hdd
// bit 5: flash
hard = 0;
/*if (config.hddEnable) {
hard|= 0x2;
}*/
if (config.ethEnable) {
hard|= 0x1;
}
hard|= 0x20;//flash
break;
case SPD_R_0e:
hard = 0x0002;
break;
default:
if ((addr >= FLASH_REGBASE) && (addr < (FLASH_REGBASE + FLASH_REGSIZE))) {
return (u16)FLASHread32(addr, 2);
}
hard = dev9Ru16(addr);
DEV9_LOG("*Unknown 16bit read at address %lx value %x\n", addr, hard);
return hard;
}
DEV9_LOG("*Known 16bit read at address %lx value %x\n", addr, hard);
return hard;
}
u32 CALLBACK DEV9read32(u32 addr)
{
u32 hard;
if (addr>=ATA_DEV9_HDD_BASE && addr<ATA_DEV9_HDD_END)
{
#ifdef ENABLE_ATA
return ata_read<4>(addr);
#else
return 0;
#endif
}
if (addr>=SMAP_REGBASE && addr<FLASH_REGBASE)
{
//smap
return smap_read32(addr);
}
switch (addr) {
default:
if ((addr >= FLASH_REGBASE) && (addr < (FLASH_REGBASE + FLASH_REGSIZE))) {
return (u32)FLASHread32(addr, 4);
}
hard = dev9Ru32(addr);
DEV9_LOG("*Unknown 32bit read at address %lx value %x\n", addr, hard);
return hard;
}
DEV9_LOG("*Known 32bit read at address %lx: %lx\n", addr, hard);
return hard;
}
void CALLBACK DEV9write8(u32 addr, u8 value)
{
if (addr>=ATA_DEV9_HDD_BASE && addr<ATA_DEV9_HDD_END)
{
#ifdef ENABLE_ATA
ata_write<1>(addr,value);
#endif
return;
}
if (addr>=SMAP_REGBASE && addr<FLASH_REGBASE)
{
//smap
smap_write8(addr,value);
return;
}
switch (addr) {
case 0x10000020:
dev9.irqcause = 0xff;
break;
case SPD_R_INTR_STAT:
emu_printf("SPD_R_INTR_STAT , WTFH ?\n");
dev9.irqcause=value;
return;
case SPD_R_INTR_MASK:
emu_printf("SPD_R_INTR_MASK8 , WTFH ?\n");
break;
case SPD_R_PIO_DIR:
//DEV9_LOG("SPD_R_PIO_DIR 8bit write %x\n", value);
if((value&0xc0)!=0xc0)
return;
if((value&0x30)==0x20)
{
dev9.eeprom_state=0;
}
dev9.eeprom_dir=(value>>4)&3;
return;
case SPD_R_PIO_DATA:
//DEV9_LOG("SPD_R_PIO_DATA 8bit write %x\n", value);
if((value&0xc0)!=0xc0)
return;
switch(dev9.eeprom_state)
{
case EEPROM_READY:
dev9.eeprom_command=0;
dev9.eeprom_state++;
break;
case EEPROM_OPCD0:
dev9.eeprom_command = (value>>4)&2;
dev9.eeprom_state++;
dev9.eeprom_bit=0xFF;
break;
case EEPROM_OPCD1:
dev9.eeprom_command |= (value>>5)&1;
dev9.eeprom_state++;
break;
case EEPROM_ADDR0:
case EEPROM_ADDR1:
case EEPROM_ADDR2:
case EEPROM_ADDR3:
case EEPROM_ADDR4:
case EEPROM_ADDR5:
dev9.eeprom_address =
(dev9.eeprom_address&(63^(1<<(dev9.eeprom_state-EEPROM_ADDR0))))|
((value>>(dev9.eeprom_state-EEPROM_ADDR0))&(0x20>>(dev9.eeprom_state-EEPROM_ADDR0)));
dev9.eeprom_state++;
break;
case EEPROM_TDATA:
{
if(dev9.eeprom_command==1) //write
{
dev9.eeprom[dev9.eeprom_address] =
(dev9.eeprom[dev9.eeprom_address]&(63^(1<<dev9.eeprom_bit)))|
((value>>dev9.eeprom_bit)&(0x8000>>dev9.eeprom_bit));
dev9.eeprom_bit++;
if(dev9.eeprom_bit==16)
{
dev9.eeprom_address++;
dev9.eeprom_bit=0;
}
}
}
break;
}
return;
default:
if ((addr >= FLASH_REGBASE) && (addr < (FLASH_REGBASE + FLASH_REGSIZE))) {
FLASHwrite32(addr, (u32)value, 1);
return;
}
dev9Ru8(addr) = value;
DEV9_LOG("*Unknown 8bit write at address %lx value %x\n", addr, value);
return;
}
dev9Ru8(addr) = value;
DEV9_LOG("*Known 8bit write at address %lx value %x\n", addr, value);
}
void CALLBACK DEV9write16(u32 addr, u16 value)
{
if (addr>=ATA_DEV9_HDD_BASE && addr<ATA_DEV9_HDD_END)
{
#ifdef ENABLE_ATA
ata_write<2>(addr,value);
#endif
return;
}
if (addr>=SMAP_REGBASE && addr<FLASH_REGBASE)
{
//smap
smap_write16(addr,value);
return;
}
switch (addr)
{
case SPD_R_INTR_MASK:
if ((dev9Ru16(SPD_R_INTR_MASK)!=value) && ((dev9Ru16(SPD_R_INTR_MASK)|value) & dev9.irqcause))
{
DEV9_LOG("SPD_R_INTR_MASK16=0x%X , checking for masked/unmasked interrupts\n",value);
DEV9irq(1);
}
break;
default:
if ((addr >= FLASH_REGBASE) && (addr < (FLASH_REGBASE + FLASH_REGSIZE))) {
FLASHwrite32(addr, (u32)value, 2);
return;
}
dev9Ru16(addr) = value;
DEV9_LOG("*Unknown 16bit write at address %lx value %x\n", addr, value);
return;
}
dev9Ru16(addr) = value;
DEV9_LOG("*Known 16bit write at address %lx value %x\n", addr, value);
}
void CALLBACK DEV9write32(u32 addr, u32 value)
{
if (addr>=ATA_DEV9_HDD_BASE && addr<ATA_DEV9_HDD_END)
{
#ifdef ENABLE_ATA
ata_write<4>(addr,value);
#endif
return;
}
if (addr>=SMAP_REGBASE && addr<FLASH_REGBASE)
{
//smap
smap_write32(addr,value);
return;
}
switch (addr)
{
case SPD_R_INTR_MASK:
emu_printf("SPD_R_INTR_MASK , WTFH ?\n");
break;
default:
if ((addr >= FLASH_REGBASE) && (addr < (FLASH_REGBASE + FLASH_REGSIZE))) {
FLASHwrite32(addr, (u32)value, 4);
return;
}
dev9Ru32(addr) = value;
DEV9_LOG("*Unknown 32bit write at address %lx write %x\n", addr, value);
return;
}
dev9Ru32(addr) = value;
DEV9_LOG("*Known 32bit write at address %lx value %lx\n", addr, value);
}
void CALLBACK DEV9readDMA8Mem(u32 *pMem, int size)
{
DEV9_LOG("*DEV9readDMA8Mem: size %x\n", size);
emu_printf("rDMA\n");
smap_readDMA8Mem(pMem,size);
#ifdef ENABLE_ATA
ata_readDMA8Mem(pMem,size);
#endif
}
void CALLBACK DEV9writeDMA8Mem(u32* pMem, int size)
{
DEV9_LOG("*DEV9writeDMA8Mem: size %x\n", size);
emu_printf("wDMA\n");
smap_writeDMA8Mem(pMem,size);
#ifdef ENABLE_ATA
ata_writeDMA8Mem(pMem,size);
#endif
}
//plugin interface
void CALLBACK DEV9irqCallback(void (*callback)(int cycles)) {
DEV9irq = callback;
}
// extended funcs
s32 CALLBACK DEV9test() {
return 0;
}
void CALLBACK DEV9setSettingsDir(const char* dir)
{
// Grab the ini directory.
// TODO: Use
// s_strIniPath = (dir == NULL) ? "inis" : dir;
}
int emu_printf(const char *fmt, ...)
{
va_list vl;
int ret;
va_start(vl,fmt);
ret = vfprintf(stderr,fmt,vl);
va_end(vl);
fflush(stderr);
return ret;
}

629
plugins/dev9ghzdrk/DEV9.h Normal file
View File

@ -0,0 +1,629 @@
#ifndef __DEV9_H__
#define __DEV9_H__
#include <stdio.h>
#ifndef EXTERN
#define EXTERN extern
#endif
#define DEV9defs
//#define WINVER 0x0600
//#define _WIN32_WINNT 0x0500
#include "PS2Edefs.h"
#include "net.h"
#ifdef __WIN32__
#define usleep(x) Sleep(x / 1000)
#include <windows.h>
#include <windowsx.h>
#include <winioctl.h>
#else
#include <gtk/gtk.h>
#define __inline inline
#endif
#define DEV9_LOG_ENABLE
#ifdef DEV9_LOG_ENABLE
#define DEV9_LOG __Log
#else
#define DEV9_LOG(...) ()
#endif
void rx_process(NetPacket* pk);
bool rx_fifo_can_rx();
#define ETH_DEF "eth0"
#define HDD_DEF "DEV9hdd.raw"
typedef struct {
char Eth[256];
char Hdd[256];
int HddSize;
int hddEnable;
int ethEnable;
} Config;
EXTERN Config config;
typedef struct {
s8 dev9R[0x10000];
u8 eeprom_state;
u8 eeprom_command;
u8 eeprom_address;
u8 eeprom_bit;
u8 eeprom_dir;
u16 *eeprom;//[32];
u32 rxbdi;
u8 rxfifo[16*1024];
u16 rxfifo_wr_ptr;
u32 txbdi;
u8 txfifo[16*1024];
u16 txfifo_rd_ptr;
u8 bd_swap;
u16 atabuf[1024];
u32 atacount;
u32 atasize;
u16 phyregs[32];
int irqcause;
u8 atacmd;
u32 atasector;
u32 atansector;
} dev9Struct;
//EEPROM states
#define EEPROM_READY 0
#define EEPROM_OPCD0 1 //waiting for first bit of opcode
#define EEPROM_OPCD1 2 //waiting for second bit of opcode
#define EEPROM_ADDR0 3 //waiting for address bits
#define EEPROM_ADDR1 4
#define EEPROM_ADDR2 5
#define EEPROM_ADDR3 6
#define EEPROM_ADDR4 7
#define EEPROM_ADDR5 8
#define EEPROM_TDATA 9 //ready to send/receive data
EXTERN dev9Struct dev9;
#define dev9_rxfifo_write(x) (dev9.rxfifo[dev9.rxfifo_wr_ptr++]=x)
#define dev9Rs8(mem) dev9.dev9R[(mem) & 0xffff]
#define dev9Rs16(mem) (*(s16*)&dev9.dev9R[(mem) & 0xffff])
#define dev9Rs32(mem) (*(s32*)&dev9.dev9R[(mem) & 0xffff])
#define dev9Ru8(mem) (*(u8*) &dev9.dev9R[(mem) & 0xffff])
#define dev9Ru16(mem) (*(u16*)&dev9.dev9R[(mem) & 0xffff])
#define dev9Ru32(mem) (*(u32*)&dev9.dev9R[(mem) & 0xffff])
EXTERN int ThreadRun;
s32 _DEV9open();
void _DEV9close();
EXTERN DEV9callback DEV9irq;
//void DEV9thread();
EXTERN FILE *dev9Log;
void __Log(char *fmt, ...);
void SysMessage(char *fmt, ...);
#define DEV9_R_REV 0x1f80146e
/*
* SPEED (ASIC on SMAP) register definitions.
*
* Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
*
* * code included from the ps2smap iop driver, modified by linuzappz *
*/
#define SPD_REGBASE 0x10000000
#define SPD_R_REV (SPD_REGBASE + 0x00)
#define SPD_R_REV_1 (SPD_REGBASE + 0x02)
// bit 0: smap
// bit 1: hdd
// bit 5: flash
#define SPD_R_REV_3 (SPD_REGBASE + 0x04)
#define SPD_R_0e (SPD_REGBASE + 0x0e)
#define SPD_R_DMA_CTRL (SPD_REGBASE + 0x24)
#define SPD_R_INTR_STAT (SPD_REGBASE + 0x28)
#define SPD_R_INTR_MASK (SPD_REGBASE + 0x2a)
#define SPD_R_PIO_DIR (SPD_REGBASE + 0x2c)
#define SPD_R_PIO_DATA (SPD_REGBASE + 0x2e)
#define SPD_PP_DOUT (1<<4) /* Data output, read port */
#define SPD_PP_DIN (1<<5) /* Data input, write port */
#define SPD_PP_SCLK (1<<6) /* Clock, write port */
#define SPD_PP_CSEL (1<<7) /* Chip select, write port */
/* Operation codes */
#define SPD_PP_OP_READ 2
#define SPD_PP_OP_WRITE 1
#define SPD_PP_OP_EWEN 0
#define SPD_PP_OP_EWDS 0
#define SPD_R_XFR_CTRL (SPD_REGBASE + 0x32)
#define SPD_R_IF_CTRL (SPD_REGBASE + 0x64)
#define SPD_IF_ATA_RESET 0x80
#define SPD_IF_DMA_ENABLE 0x04
#define SPD_R_PIO_MODE (SPD_REGBASE + 0x70)
#define SPD_R_MWDMA_MODE (SPD_REGBASE + 0x72)
#define SPD_R_UDMA_MODE (SPD_REGBASE + 0x74)
/*
* SMAP (PS2 Network Adapter) register definitions.
*
* Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
*
* * code included from the ps2smap iop driver, modified by linuzappz *
*/
/* SMAP interrupt status bits (selected from the SPEED device). */
#define SMAP_INTR_EMAC3 (1<<6)
#define SMAP_INTR_RXEND (1<<5)
#define SMAP_INTR_TXEND (1<<4)
#define SMAP_INTR_RXDNV (1<<3) /* descriptor not valid */
#define SMAP_INTR_TXDNV (1<<2) /* descriptor not valid */
#define SMAP_INTR_CLR_ALL (SMAP_INTR_RXEND|SMAP_INTR_TXEND|SMAP_INTR_RXDNV)
#define SMAP_INTR_ENA_ALL (SMAP_INTR_EMAC3|SMAP_INTR_CLR_ALL)
#define SMAP_INTR_BITMSK 0x7C
/* SMAP Register Definitions. */
#define SMAP_REGBASE (SPD_REGBASE + 0x100)
#define SMAP_R_BD_MODE (SMAP_REGBASE + 0x02)
#define SMAP_BD_SWAP (1<<0)
#define SMAP_R_INTR_CLR (SMAP_REGBASE + 0x28)
/* SMAP FIFO Registers. */
#define SMAP_R_TXFIFO_CTRL (SMAP_REGBASE + 0xf00)
#define SMAP_TXFIFO_RESET (1<<0)
#define SMAP_TXFIFO_DMAEN (1<<1)
#define SMAP_R_TXFIFO_WR_PTR (SMAP_REGBASE + 0xf04)
#define SMAP_R_TXFIFO_SIZE (SMAP_REGBASE + 0xf08)
#define SMAP_R_TXFIFO_FRAME_CNT (SMAP_REGBASE + 0xf0C)
#define SMAP_R_TXFIFO_FRAME_INC (SMAP_REGBASE + 0xf10)
#define SMAP_R_TXFIFO_DATA (SMAP_REGBASE + 0x1000)
#define SMAP_R_RXFIFO_CTRL (SMAP_REGBASE + 0xf30)
#define SMAP_RXFIFO_RESET (1<<0)
#define SMAP_RXFIFO_DMAEN (1<<1)
#define SMAP_R_RXFIFO_RD_PTR (SMAP_REGBASE + 0xf34)
#define SMAP_R_RXFIFO_SIZE (SMAP_REGBASE + 0xf38)
#define SMAP_R_RXFIFO_FRAME_CNT (SMAP_REGBASE + 0xf3C)
#define SMAP_R_RXFIFO_FRAME_DEC (SMAP_REGBASE + 0xf40)
#define SMAP_R_RXFIFO_DATA (SMAP_REGBASE + 0x1100)
#define SMAP_R_FIFO_ADDR (SMAP_REGBASE + 0x1200)
#define SMAP_FIFO_CMD_READ (1<<1)
#define SMAP_FIFO_DATA_SWAP (1<<0)
#define SMAP_R_FIFO_DATA (SMAP_REGBASE + 0x1208)
/* EMAC3 Registers. */
#define SMAP_EMAC3_REGBASE (SMAP_REGBASE + 0x1f00)
#define SMAP_R_EMAC3_MODE0_L (SMAP_EMAC3_REGBASE + 0x00)
#define SMAP_E3_RXMAC_IDLE (1<<(15+16))
#define SMAP_E3_TXMAC_IDLE (1<<(14+16))
#define SMAP_E3_SOFT_RESET (1<<(13+16))
#define SMAP_E3_TXMAC_ENABLE (1<<(12+16))
#define SMAP_E3_RXMAC_ENABLE (1<<(11+16))
#define SMAP_E3_WAKEUP_ENABLE (1<<(10+16))
#define SMAP_R_EMAC3_MODE0_H (SMAP_EMAC3_REGBASE + 0x02)
#define SMAP_R_EMAC3_MODE1 (SMAP_EMAC3_REGBASE + 0x04)
#define SMAP_R_EMAC3_MODE1_L (SMAP_EMAC3_REGBASE + 0x04)
#define SMAP_R_EMAC3_MODE1_H (SMAP_EMAC3_REGBASE + 0x06)
#define SMAP_E3_FDX_ENABLE (1<<31)
#define SMAP_E3_INLPBK_ENABLE (1<<30) /* internal loop back */
#define SMAP_E3_VLAN_ENABLE (1<<29)
#define SMAP_E3_FLOWCTRL_ENABLE (1<<28) /* integrated flow ctrl(pause frame) */
#define SMAP_E3_ALLOW_PF (1<<27) /* allow pause frame */
#define SMAP_E3_ALLOW_EXTMNGIF (1<<25) /* allow external management IF */
#define SMAP_E3_IGNORE_SQE (1<<24)
#define SMAP_E3_MEDIA_FREQ_BITSFT (22)
#define SMAP_E3_MEDIA_10M (0<<22)
#define SMAP_E3_MEDIA_100M (1<<22)
#define SMAP_E3_MEDIA_1000M (2<<22)
#define SMAP_E3_MEDIA_MSK (3<<22)
#define SMAP_E3_RXFIFO_SIZE_BITSFT (20)
#define SMAP_E3_RXFIFO_512 (0<<20)
#define SMAP_E3_RXFIFO_1K (1<<20)
#define SMAP_E3_RXFIFO_2K (2<<20)
#define SMAP_E3_RXFIFO_4K (3<<20)
#define SMAP_E3_TXFIFO_SIZE_BITSFT (18)
#define SMAP_E3_TXFIFO_512 (0<<18)
#define SMAP_E3_TXFIFO_1K (1<<18)
#define SMAP_E3_TXFIFO_2K (2<<18)
#define SMAP_E3_TXREQ0_BITSFT (15)
#define SMAP_E3_TXREQ0_SINGLE (0<<15)
#define SMAP_E3_TXREQ0_MULTI (1<<15)
#define SMAP_E3_TXREQ0_DEPEND (2<<15)
#define SMAP_E3_TXREQ1_BITSFT (13)
#define SMAP_E3_TXREQ1_SINGLE (0<<13)
#define SMAP_E3_TXREQ1_MULTI (1<<13)
#define SMAP_E3_TXREQ1_DEPEND (2<<13)
#define SMAP_E3_JUMBO_ENABLE (1<<12)
#define SMAP_R_EMAC3_TxMODE0_L (SMAP_EMAC3_REGBASE + 0x08)
#define SMAP_E3_TX_GNP_0 (1<<(15+16)) /* get new packet */
#define SMAP_E3_TX_GNP_1 (1<<(14+16)) /* get new packet */
#define SMAP_E3_TX_GNP_DEPEND (1<<(13+16)) /* get new packet */
#define SMAP_E3_TX_FIRST_CHANNEL (1<<(12+16))
#define SMAP_R_EMAC3_TxMODE0_H (SMAP_EMAC3_REGBASE + 0x0A)
#define SMAP_R_EMAC3_TxMODE1_L (SMAP_EMAC3_REGBASE + 0x0C)
#define SMAP_R_EMAC3_TxMODE1_H (SMAP_EMAC3_REGBASE + 0x0E)
#define SMAP_E3_TX_LOW_REQ_MSK (0x1F) /* low priority request */
#define SMAP_E3_TX_LOW_REQ_BITSFT (27) /* low priority request */
#define SMAP_E3_TX_URG_REQ_MSK (0xFF) /* urgent priority request */
#define SMAP_E3_TX_URG_REQ_BITSFT (16) /* urgent priority request */
#define SMAP_R_EMAC3_RxMODE (SMAP_EMAC3_REGBASE + 0x10)
#define SMAP_R_EMAC3_RxMODE_L (SMAP_EMAC3_REGBASE + 0x10)
#define SMAP_R_EMAC3_RxMODE_H (SMAP_EMAC3_REGBASE + 0x12)
#define SMAP_E3_RX_STRIP_PAD (1<<31)
#define SMAP_E3_RX_STRIP_FCS (1<<30)
#define SMAP_E3_RX_RX_RUNT_FRAME (1<<29)
#define SMAP_E3_RX_RX_FCS_ERR (1<<28)
#define SMAP_E3_RX_RX_TOO_LONG_ERR (1<<27)
#define SMAP_E3_RX_RX_IN_RANGE_ERR (1<<26)
#define SMAP_E3_RX_PROP_PF (1<<25) /* propagate pause frame */
#define SMAP_E3_RX_PROMISC (1<<24)
#define SMAP_E3_RX_PROMISC_MCAST (1<<23)
#define SMAP_E3_RX_INDIVID_ADDR (1<<22)
#define SMAP_E3_RX_INDIVID_HASH (1<<21)
#define SMAP_E3_RX_BCAST (1<<20)
#define SMAP_E3_RX_MCAST (1<<19)
#define SMAP_R_EMAC3_INTR_STAT (SMAP_EMAC3_REGBASE + 0x14)
#define SMAP_R_EMAC3_INTR_STAT_L (SMAP_EMAC3_REGBASE + 0x14)
#define SMAP_R_EMAC3_INTR_STAT_H (SMAP_EMAC3_REGBASE + 0x16)
#define SMAP_R_EMAC3_INTR_ENABLE (SMAP_EMAC3_REGBASE + 0x18)
#define SMAP_R_EMAC3_INTR_ENABLE_L (SMAP_EMAC3_REGBASE + 0x18)
#define SMAP_R_EMAC3_INTR_ENABLE_H (SMAP_EMAC3_REGBASE + 0x1A)
#define SMAP_E3_INTR_OVERRUN (1<<25) /* this bit does NOT WORKED */
#define SMAP_E3_INTR_PF (1<<24)
#define SMAP_E3_INTR_BAD_FRAME (1<<23)
#define SMAP_E3_INTR_RUNT_FRAME (1<<22)
#define SMAP_E3_INTR_SHORT_EVENT (1<<21)
#define SMAP_E3_INTR_ALIGN_ERR (1<<20)
#define SMAP_E3_INTR_BAD_FCS (1<<19)
#define SMAP_E3_INTR_TOO_LONG (1<<18)
#define SMAP_E3_INTR_OUT_RANGE_ERR (1<<17)
#define SMAP_E3_INTR_IN_RANGE_ERR (1<<16)
#define SMAP_E3_INTR_DEAD_DEPEND (1<<9)
#define SMAP_E3_INTR_DEAD_0 (1<<8)
#define SMAP_E3_INTR_SQE_ERR_0 (1<<7)
#define SMAP_E3_INTR_TX_ERR_0 (1<<6)
#define SMAP_E3_INTR_DEAD_1 (1<<5)
#define SMAP_E3_INTR_SQE_ERR_1 (1<<4)
#define SMAP_E3_INTR_TX_ERR_1 (1<<3)
#define SMAP_E3_INTR_MMAOP_SUCCESS (1<<1)
#define SMAP_E3_INTR_MMAOP_FAIL (1<<0)
#define SMAP_E3_INTR_ALL \
(SMAP_E3_INTR_OVERRUN|SMAP_E3_INTR_PF|SMAP_E3_INTR_BAD_FRAME| \
SMAP_E3_INTR_RUNT_FRAME|SMAP_E3_INTR_SHORT_EVENT| \
SMAP_E3_INTR_ALIGN_ERR|SMAP_E3_INTR_BAD_FCS| \
SMAP_E3_INTR_TOO_LONG|SMAP_E3_INTR_OUT_RANGE_ERR| \
SMAP_E3_INTR_IN_RANGE_ERR| \
SMAP_E3_INTR_DEAD_DEPEND|SMAP_E3_INTR_DEAD_0| \
SMAP_E3_INTR_SQE_ERR_0|SMAP_E3_INTR_TX_ERR_0| \
SMAP_E3_INTR_DEAD_1|SMAP_E3_INTR_SQE_ERR_1| \
SMAP_E3_INTR_TX_ERR_1| \
SMAP_E3_INTR_MMAOP_SUCCESS|SMAP_E3_INTR_MMAOP_FAIL)
#define SMAP_E3_DEAD_ALL \
(SMAP_E3_INTR_DEAD_DEPEND|SMAP_E3_INTR_DEAD_0| \
SMAP_E3_INTR_DEAD_1)
#define SMAP_R_EMAC3_ADDR_HI (SMAP_EMAC3_REGBASE + 0x1C)
#define SMAP_R_EMAC3_ADDR_LO (SMAP_EMAC3_REGBASE + 0x20)
#define SMAP_R_EMAC3_ADDR_HI_L (SMAP_EMAC3_REGBASE + 0x1C)
#define SMAP_R_EMAC3_ADDR_HI_H (SMAP_EMAC3_REGBASE + 0x1E)
#define SMAP_R_EMAC3_ADDR_LO_L (SMAP_EMAC3_REGBASE + 0x20)
#define SMAP_R_EMAC3_ADDR_LO_H (SMAP_EMAC3_REGBASE + 0x22)
#define SMAP_R_EMAC3_VLAN_TPID (SMAP_EMAC3_REGBASE + 0x24)
#define SMAP_E3_VLAN_ID_MSK 0xFFFF
#define SMAP_R_EMAC3_VLAN_TCI (SMAP_EMAC3_REGBASE + 0x28)
#define SMAP_E3_VLAN_TCITAG_MSK 0xFFFF
#define SMAP_R_EMAC3_PAUSE_TIMER (SMAP_EMAC3_REGBASE + 0x2C)
#define SMAP_R_EMAC3_PAUSE_TIMER_L (SMAP_EMAC3_REGBASE + 0x2C)
#define SMAP_R_EMAC3_PAUSE_TIMER_H (SMAP_EMAC3_REGBASE + 0x2E)
#define SMAP_E3_PTIMER_MSK 0xFFFF
#define SMAP_R_EMAC3_INDIVID_HASH1 (SMAP_EMAC3_REGBASE + 0x30)
#define SMAP_R_EMAC3_INDIVID_HASH2 (SMAP_EMAC3_REGBASE + 0x34)
#define SMAP_R_EMAC3_INDIVID_HASH3 (SMAP_EMAC3_REGBASE + 0x38)
#define SMAP_R_EMAC3_INDIVID_HASH4 (SMAP_EMAC3_REGBASE + 0x3C)
#define SMAP_R_EMAC3_GROUP_HASH1 (SMAP_EMAC3_REGBASE + 0x40)
#define SMAP_R_EMAC3_GROUP_HASH2 (SMAP_EMAC3_REGBASE + 0x44)
#define SMAP_R_EMAC3_GROUP_HASH3 (SMAP_EMAC3_REGBASE + 0x48)
#define SMAP_R_EMAC3_GROUP_HASH4 (SMAP_EMAC3_REGBASE + 0x4C)
#define SMAP_E3_HASH_MSK 0xFFFF
#define SMAP_R_EMAC3_LAST_SA_HI (SMAP_EMAC3_REGBASE + 0x50)
#define SMAP_R_EMAC3_LAST_SA_LO (SMAP_EMAC3_REGBASE + 0x54)
#define SMAP_R_EMAC3_INTER_FRAME_GAP (SMAP_EMAC3_REGBASE + 0x58)
#define SMAP_R_EMAC3_INTER_FRAME_GAP_L (SMAP_EMAC3_REGBASE + 0x58)
#define SMAP_R_EMAC3_INTER_FRAME_GAP_H (SMAP_EMAC3_REGBASE + 0x5A)
#define SMAP_E3_IFGAP_MSK 0x3F
#define SMAP_R_EMAC3_STA_CTRL_L (SMAP_EMAC3_REGBASE + 0x5C)
#define SMAP_R_EMAC3_STA_CTRL_H (SMAP_EMAC3_REGBASE + 0x5E)
#define SMAP_E3_PHY_DATA_MSK (0xFFFF)
#define SMAP_E3_PHY_DATA_BITSFT (16)
#define SMAP_E3_PHY_OP_COMP (1<<15) /* operation complete */
#define SMAP_E3_PHY_ERR_READ (1<<14)
#define SMAP_E3_PHY_STA_CMD_BITSFT (12)
#define SMAP_E3_PHY_READ (1<<12)
#define SMAP_E3_PHY_WRITE (2<<12)
#define SMAP_E3_PHY_OPBCLCK_BITSFT (10)
#define SMAP_E3_PHY_50M (0<<10)
#define SMAP_E3_PHY_66M (1<<10)
#define SMAP_E3_PHY_83M (2<<10)
#define SMAP_E3_PHY_100M (3<<10)
#define SMAP_E3_PHY_ADDR_MSK (0x1F)
#define SMAP_E3_PHY_ADDR_BITSFT (5)
#define SMAP_E3_PHY_REG_ADDR_MSK (0x1F)
#define SMAP_R_EMAC3_TX_THRESHOLD (SMAP_EMAC3_REGBASE + 0x60)
#define SMAP_R_EMAC3_TX_THRESHOLD_L (SMAP_EMAC3_REGBASE + 0x60)
#define SMAP_R_EMAC3_TX_THRESHOLD_H (SMAP_EMAC3_REGBASE + 0x62)
#define SMAP_E3_TX_THRESHLD_MSK (0x1F)
#define SMAP_E3_TX_THRESHLD_BITSFT (27)
#define SMAP_R_EMAC3_RX_WATERMARK (SMAP_EMAC3_REGBASE + 0x64)
#define SMAP_R_EMAC3_RX_WATERMARK_L (SMAP_EMAC3_REGBASE + 0x64)
#define SMAP_R_EMAC3_RX_WATERMARK_H (SMAP_EMAC3_REGBASE + 0x66)
#define SMAP_E3_RX_LO_WATER_MSK (0x1FF)
#define SMAP_E3_RX_LO_WATER_BITSFT (23)
#define SMAP_E3_RX_HI_WATER_MSK (0x1FF)
#define SMAP_E3_RX_HI_WATER_BITSFT (7)
#define SMAP_R_EMAC3_TX_OCTETS (SMAP_EMAC3_REGBASE + 0x68)
#define SMAP_R_EMAC3_RX_OCTETS (SMAP_EMAC3_REGBASE + 0x6C)
#define SMAP_EMAC3_REGEND (SMAP_EMAC3_REGBASE + 0x6C + 4)
/* Buffer descriptors. */
typedef struct _smap_bd {
u16 ctrl_stat;
u16 reserved; /* must be zero */
u16 length; /* number of bytes in pkt */
u16 pointer;
} smap_bd_t;
#define SMAP_BD_REGBASE (SMAP_REGBASE + 0x2f00)
#define SMAP_BD_TX_BASE (SMAP_BD_REGBASE + 0x0000)
#define SMAP_BD_RX_BASE (SMAP_BD_REGBASE + 0x0200)
#define SMAP_BD_SIZE 512
#define SMAP_BD_MAX_ENTRY 64
#define SMAP_TX_BASE (SMAP_REGBASE + 0x1000)
#define SMAP_TX_BUFSIZE 4096
/* TX Control */
#define SMAP_BD_TX_READY (1<<15) /* set:driver, clear:HW */
#define SMAP_BD_TX_GENFCS (1<<9) /* generate FCS */
#define SMAP_BD_TX_GENPAD (1<<8) /* generate padding */
#define SMAP_BD_TX_INSSA (1<<7) /* insert source address */
#define SMAP_BD_TX_RPLSA (1<<6) /* replace source address */
#define SMAP_BD_TX_INSVLAN (1<<5) /* insert VLAN Tag */
#define SMAP_BD_TX_RPLVLAN (1<<4) /* replace VLAN Tag */
/* TX Status */
#define SMAP_BD_TX_READY (1<<15) /* set:driver, clear:HW */
#define SMAP_BD_TX_BADFCS (1<<9) /* bad FCS */
#define SMAP_BD_TX_BADPKT (1<<8) /* bad previous pkt in dependent mode */
#define SMAP_BD_TX_LOSSCR (1<<7) /* loss of carrior sense */
#define SMAP_BD_TX_EDEFER (1<<6) /* excessive deferal */
#define SMAP_BD_TX_ECOLL (1<<5) /* excessive collision */
#define SMAP_BD_TX_LCOLL (1<<4) /* late collision */
#define SMAP_BD_TX_MCOLL (1<<3) /* multiple collision */
#define SMAP_BD_TX_SCOLL (1<<2) /* single collision */
#define SMAP_BD_TX_UNDERRUN (1<<1) /* underrun */
#define SMAP_BD_TX_SQE (1<<0) /* SQE */
#define SMAP_BD_TX_ERROR (SMAP_BD_TX_LOSSCR|SMAP_BD_TX_EDEFER|SMAP_BD_TX_ECOLL| \
SMAP_BD_TX_LCOLL|SMAP_BD_TX_UNDERRUN)
/* RX Control */
#define SMAP_BD_RX_EMPTY (1<<15) /* set:driver, clear:HW */
/* RX Status */
#define SMAP_BD_RX_EMPTY (1<<15) /* set:driver, clear:HW */
#define SMAP_BD_RX_OVERRUN (1<<9) /* overrun */
#define SMAP_BD_RX_PFRM (1<<8) /* pause frame */
#define SMAP_BD_RX_BADFRM (1<<7) /* bad frame */
#define SMAP_BD_RX_RUNTFRM (1<<6) /* runt frame */
#define SMAP_BD_RX_SHORTEVNT (1<<5) /* short event */
#define SMAP_BD_RX_ALIGNERR (1<<4) /* alignment error */
#define SMAP_BD_RX_BADFCS (1<<3) /* bad FCS */
#define SMAP_BD_RX_FRMTOOLONG (1<<2) /* frame too long */
#define SMAP_BD_RX_OUTRANGE (1<<1) /* out of range error */
#define SMAP_BD_RX_INRANGE (1<<0) /* in range error */
#define SMAP_BD_RX_ERROR (SMAP_BD_RX_OVERRUN|SMAP_BD_RX_RUNTFRM|SMAP_BD_RX_SHORTEVNT| \
SMAP_BD_RX_ALIGNERR|SMAP_BD_RX_BADFCS|SMAP_BD_RX_FRMTOOLONG| \
SMAP_BD_RX_OUTRANGE|SMAP_BD_RX_INRANGE)
/* PHY registers (National Semiconductor DP83846A). */
#define SMAP_NS_OUI 0x080017
#define SMAP_DsPHYTER_ADDRESS 0x1
#define SMAP_DsPHYTER_BMCR 0x00
#define SMAP_PHY_BMCR_RST (1<<15) /* ReSeT */
#define SMAP_PHY_BMCR_LPBK (1<<14) /* LooPBacK */
#define SMAP_PHY_BMCR_100M (1<<13) /* speed select, 1:100M, 0:10M */
#define SMAP_PHY_BMCR_10M (0<<13) /* speed select, 1:100M, 0:10M */
#define SMAP_PHY_BMCR_ANEN (1<<12) /* Auto-Negotiation ENable */
#define SMAP_PHY_BMCR_PWDN (1<<11) /* PoWer DowN */
#define SMAP_PHY_BMCR_ISOL (1<<10) /* ISOLate */
#define SMAP_PHY_BMCR_RSAN (1<<9) /* ReStart Auto-Negotiation */
#define SMAP_PHY_BMCR_DUPM (1<<8) /* DUPlex Mode, 1:FDX, 0:HDX */
#define SMAP_PHY_BMCR_COLT (1<<7) /* COLlision Test */
#define SMAP_DsPHYTER_BMSR 0x01
#define SMAP_PHY_BMSR_ANCP (1<<5) /* Auto-Negotiation ComPlete */
#define SMAP_PHY_BMSR_LINK (1<<2) /* LINK status */
#define SMAP_DsPHYTER_PHYIDR1 0x02
#define SMAP_PHY_IDR1_VAL (((SMAP_NS_OUI<<2)>>8)&0xffff)
#define SMAP_DsPHYTER_PHYIDR2 0x03
#define SMAP_PHY_IDR2_VMDL 0x2 /* Vendor MoDeL number */
#define SMAP_PHY_IDR2_VAL \
(((SMAP_NS_OUI<<10)&0xFC00)|((SMAP_PHY_IDR2_VMDL<<4)&0x3F0))
#define SMAP_PHY_IDR2_MSK 0xFFF0
#define SMAP_PHY_IDR2_REV_MSK 0x000F
#define SMAP_DsPHYTER_ANAR 0x04
#define SMAP_DsPHYTER_ANLPAR 0x05
#define SMAP_DsPHYTER_ANLPARNP 0x05
#define SMAP_DsPHYTER_ANER 0x06
#define SMAP_DsPHYTER_ANNPTR 0x07
/* Extended registers. */
#define SMAP_DsPHYTER_PHYSTS 0x10
#define SMAP_PHY_STS_REL (1<<13) /* Receive Error Latch */
#define SMAP_PHY_STS_POST (1<<12) /* POlarity STatus */
#define SMAP_PHY_STS_FCSL (1<<11) /* False Carrier Sense Latch */
#define SMAP_PHY_STS_SD (1<<10) /* 100BT unconditional Signal Detect */
#define SMAP_PHY_STS_DSL (1<<9) /* 100BT DeScrambler Lock */
#define SMAP_PHY_STS_PRCV (1<<8) /* Page ReCeiVed */
#define SMAP_PHY_STS_RFLT (1<<6) /* Remote FauLT */
#define SMAP_PHY_STS_JBDT (1<<5) /* JaBber DetecT */
#define SMAP_PHY_STS_ANCP (1<<4) /* Auto-Negotiation ComPlete */
#define SMAP_PHY_STS_LPBK (1<<3) /* LooPBacK status */
#define SMAP_PHY_STS_DUPS (1<<2) /* DUPlex Status,1:FDX,0:HDX */
#define SMAP_PHY_STS_FDX (1<<2) /* Full Duplex */
#define SMAP_PHY_STS_HDX (0<<2) /* Half Duplex */
#define SMAP_PHY_STS_SPDS (1<<1) /* SPeeD Status */
#define SMAP_PHY_STS_10M (1<<1) /* 10Mbps */
#define SMAP_PHY_STS_100M (0<<1) /* 100Mbps */
#define SMAP_PHY_STS_LINK (1<<0) /* LINK status */
#define SMAP_DsPHYTER_FCSCR 0x14
#define SMAP_DsPHYTER_RECR 0x15
#define SMAP_DsPHYTER_PCSR 0x16
#define SMAP_DsPHYTER_PHYCTRL 0x19
#define SMAP_DsPHYTER_10BTSCR 0x1A
#define SMAP_DsPHYTER_CDCTRL 0x1B
/*
* ATA hardware types and definitions.
*
* Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
*
* * code included from the ps2drv iop driver, modified by linuzappz *
*/
#define ATA_DEV9_HDD_BASE (SPD_REGBASE + 0x40)
/* AIF on T10Ks - Not supported yet. */
#define ATA_AIF_HDD_BASE (SPD_REGBASE + 0x4000000 + 0x60)
#define ATA_R_DATA (ATA_DEV9_HDD_BASE + 0x00)
#define ATA_R_ERROR (ATA_DEV9_HDD_BASE + 0x02)
#define ATA_R_NSECTOR (ATA_DEV9_HDD_BASE + 0x04)
#define ATA_R_SECTOR (ATA_DEV9_HDD_BASE + 0x06)
#define ATA_R_LCYL (ATA_DEV9_HDD_BASE + 0x08)
#define ATA_R_HCYL (ATA_DEV9_HDD_BASE + 0x0a)
#define ATA_R_SELECT (ATA_DEV9_HDD_BASE + 0x0c)
#define ATA_R_STATUS (ATA_DEV9_HDD_BASE + 0x0e)
#define ATA_R_CONTROL (ATA_DEV9_HDD_BASE + 0x1c)
#define ATA_DEV9_INT (0x01)
#define ATA_DEV9_INT_DMA (0x02) //not sure rly
#define ATA_DEV9_HDD_END (ATA_R_CONTROL+4)
/*
* NAND Flash via Dev9 driver definitions
*
* Copyright (c) 2003 Marcus R. Brown <mrbrown@0xd6.org>
*
* * code included from the ps2sdk iop driver *
*/
#define FLASH_ID_64MBIT 0xe6
#define FLASH_ID_128MBIT 0x73
#define FLASH_ID_256MBIT 0x75
#define FLASH_ID_512MBIT 0x76
#define FLASH_ID_1024MBIT 0x79
/* SmartMedia commands. */
#define SM_CMD_READ1 0x00
#define SM_CMD_READ2 0x01
#define SM_CMD_READ3 0x50
#define SM_CMD_RESET 0xff
#define SM_CMD_WRITEDATA 0x80
#define SM_CMD_PROGRAMPAGE 0x10
#define SM_CMD_ERASEBLOCK 0x60
#define SM_CMD_ERASECONFIRM 0xd0
#define SM_CMD_GETSTATUS 0x70
#define SM_CMD_READID 0x90
typedef struct {
u32 id;
u32 mbits;
u32 page_bytes; /* bytes/page */
u32 block_pages; /* pages/block */
u32 blocks;
} flash_info_t;
/*
static flash_info_t devices[] = {
{ FLASH_ID_64MBIT, 64, 528, 16, 1024 },
{ FLASH_ID_128MBIT, 128, 528, 32, 1024 },
{ FLASH_ID_256MBIT, 256, 528, 32, 2048 },
{ FLASH_ID_512MBIT, 512, 528, 32, 4096 },
{ FLASH_ID_1024MBIT, 1024, 528, 32, 8192 }
};
#define NUM_DEVICES (sizeof(devices)/sizeof(flash_info_t))
*/
// definitions added by Florin
#define FLASH_REGBASE 0x10004800
#define FLASH_R_DATA (FLASH_REGBASE + 0x00)
#define FLASH_R_CMD (FLASH_REGBASE + 0x04)
#define FLASH_R_ADDR (FLASH_REGBASE + 0x08)
#define FLASH_R_CTRL (FLASH_REGBASE + 0x0C)
#define FLASH_PP_READY (1<<0) // r/w /BUSY
#define FLASH_PP_WRITE (1<<7) // -/w WRITE data
#define FLASH_PP_CSEL (1<<8) // -/w CS
#define FLASH_PP_READ (1<<11) // -/w READ data
#define FLASH_PP_NOECC (1<<12) // -/w ECC disabled
//#define FLASH_R_10 (FLASH_REGBASE + 0x10)
#define FLASH_R_ID (FLASH_REGBASE + 0x14)
#define FLASH_REGSIZE 0x20
void CALLBACK FLASHinit();
u32 CALLBACK FLASHread32(u32 addr, int size);
void CALLBACK FLASHwrite32(u32 addr, u32 value, int size);
void _DEV9irq(int cause, int cycles);
int emu_printf(const char *fmt, ...);
#pragma warning(error:4013)
#endif

View File

@ -0,0 +1,684 @@
#ifndef __PS2EDEFS_H__
#define __PS2EDEFS_H__
/*
* PS2E Definitions v0.5.5 (beta)
*
* Author: linuzappz@hotmail.com
* shadowpcsx2@yahoo.gr
* florinsasu@hotmail.com
*/
/*
Notes:
* Since this is still beta things may change.
* OSflags:
__LINUX__ (linux OS)
__WIN32__ (win32 OS)
* common return values (for ie. GSinit):
0 - success
-1 - error
* reserved keys:
F1 to F10 are reserved for the emulator
* plugins should NOT change the current
working directory.
(on win32, add flag OFN_NOCHANGEDIR for
GetOpenFileName)
*/
#include "PS2Etypes.h"
#ifdef __LINUX__
#define CALLBACK
#else
#include <windows.h>
#endif
/* common defines */
#if defined(GSdefs) || defined(PADdefs) || \
defined(SPU2defs)|| defined(CDVDdefs)
#define COMMONdefs
#endif
// PS2EgetLibType returns (may be OR'd)
#define PS2E_LT_GS 0x01
#define PS2E_LT_PAD 0x02
#define PS2E_LT_SPU2 0x04
#define PS2E_LT_CDVD 0x08
#define PS2E_LT_DEV9 0x10
#define PS2E_LT_USB 0x20
#define PS2E_LT_FIREWIRE 0x40
// PS2EgetLibVersion2 (high 16 bits)
#define PS2E_GS_VERSION 0x0005
#define PS2E_PAD_VERSION 0x0002
#define PS2E_SPU2_VERSION 0x0004
#define PS2E_CDVD_VERSION 0x0003
#define PS2E_DEV9_VERSION 0x0003
#define PS2E_USB_VERSION 0x0003
#define PS2E_FIREWIRE_VERSION 0x0002
#ifdef COMMONdefs
u32 CALLBACK PS2EgetLibType(void);
u32 CALLBACK PS2EgetLibVersion2(u32 type);
char* CALLBACK PS2EgetLibName(void);
#endif
// key values:
/* key values must be OS dependant:
win32: the VK_XXX will be used (WinUser)
linux: the XK_XXX will be used (XFree86)
*/
// event values:
#define KEYPRESS 1
#define KEYRELEASE 2
typedef struct {
u32 key;
u32 event;
} keyEvent;
typedef struct { // NOT bcd coded
u8 minute;
u8 second;
u8 frame;
u8 type;
} cdvdTD;
typedef struct {
u8 strack; //number of the first track (usualy 1)
u8 etrack; //number of the last track
} cdvdTN;
// CDVDreadTrack mode values:
#define CDVD_MODE_2352 0 // full 2352 bytes
#define CDVD_MODE_2340 1 // skip sync (12) bytes
#define CDVD_MODE_2328 2 // skip sync+head+sub (24) bytes
#define CDVD_MODE_2048 3 // skip sync+head+sub (24) bytes
#define CDVD_MODE_2368 4 // full 2352 bytes + 16 subq
// CDVDgetType returns:
#define CDVD_TYPE_ILLEGAL 0xff // Illegal Disc
#define CDVD_TYPE_DVDV 0xfe // DVD Video
#define CDVD_TYPE_CDDA 0xfd // Audio CD
#define CDVD_TYPE_PS2DVD 0x14 // PS2 DVD
#define CDVD_TYPE_PS2CDDA 0x13 // PS2 CD (with audio)
#define CDVD_TYPE_PS2CD 0x12 // PS2 CD
#define CDVD_TYPE_PSCDDA 0x11 // PS CD (with audio)
#define CDVD_TYPE_PSCD 0x10 // PS CD
#define CDVD_TYPE_UNKNOWN 0x05 // Unknown
#define CDVD_TYPE_DETCTDVDD 0x04 // Detecting Dvd Dual Sided
#define CDVD_TYPE_DETCTDVDS 0x03 // Detecting Dvd Single Sided
#define CDVD_TYPE_DETCTCD 0x02 // Detecting Cd
#define CDVD_TYPE_DETCT 0x01 // Detecting
#define CDVD_TYPE_NODISC 0x00 // No Disc
// CDVDgetTrayStatus returns:
#define CDVD_TRAY_CLOSE 0x00
#define CDVD_TRAY_OPEN 0x01
// cdvdLoc:track type
#define CDVD_AUDIO_TRACK 0x01
#define CDVD_MODE1_TRACK 0x41
#define CDVD_MODE2_TRACK 0x61
#define CDVD_AUDIO_MASK 0x00
#define CDVD_DATA_MASK 0x40
// CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel)
typedef void (*DEV9callback)(int cycles);
typedef int (*DEV9handler)(void);
typedef void (*USBcallback)(int cycles);
typedef int (*USBhandler)(void);
// freeze modes:
#define FREEZE_LOAD 0
#define FREEZE_SAVE 1
#define FREEZE_SIZE 2
typedef struct {
int size;
s8 *data;
} freezeData;
typedef struct {
char name[8];
void *common;
} GSdriverInfo;
#ifdef __WIN32__
typedef struct { // unsupported values must be set to zero
HWND hWnd;
HMENU hMenu;
HWND hStatusWnd;
} winInfo;
#endif
/* GS plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef GSdefs
// basic funcs
s32 CALLBACK GSinit();
s32 CALLBACK GSopen(void *pDsp, char *Title);
void CALLBACK GSclose();
void CALLBACK GSshutdown();
void CALLBACK GSvsync();
void CALLBACK GSgifTransfer1(u32 *pMem);
void CALLBACK GSgifTransfer2(u32 *pMem, u32 size);
void CALLBACK GSgifTransfer3(u32 *pMem, u32 size);
void CALLBACK GSwrite32(u32 mem, u32 value);
void CALLBACK GSwrite64(u32 mem, u64 value);
u32 CALLBACK GSread32(u32 mem);
u64 CALLBACK GSread64(u32 mem);
void CALLBACK GSreadFIFO(u64 *mem);
// extended funcs
// GSkeyEvent gets called when there is a keyEvent from the PAD plugin
void CALLBACK GSkeyEvent(keyEvent *ev);
void CALLBACK GSmakeSnapshot(char *path);
void CALLBACK GSirqCallback(void (*callback)());
void CALLBACK GSprintf(int timeout, char *fmt, ...);
void CALLBACK GSgetDriverInfo(GSdriverInfo *info);
#ifdef __WIN32__
s32 CALLBACK GSsetWindowInfo(winInfo *info);
#endif
s32 CALLBACK GSfreeze(int mode, freezeData *data);
void CALLBACK GSconfigure();
void CALLBACK GSabout();
s32 CALLBACK GStest();
#endif
/* PAD plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef PADdefs
// basic funcs
s32 CALLBACK PADinit(u32 flags);
s32 CALLBACK PADopen(void *pDsp);
void CALLBACK PADclose();
void CALLBACK PADshutdown();
// PADkeyEvent is called every vsync (return NULL if no event)
keyEvent* CALLBACK PADkeyEvent();
u8 CALLBACK PADstartPoll(int pad);
u8 CALLBACK PADpoll(u8 value);
// returns: 1 if supported pad1
// 2 if supported pad2
// 3 if both are supported
u32 CALLBACK PADquery();
// extended funcs
void CALLBACK PADgsDriverInfo(GSdriverInfo *info);
void CALLBACK PADconfigure();
void CALLBACK PADabout();
s32 CALLBACK PADtest();
#endif
/* SPU2 plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef SPU2defs
// basic funcs
s32 CALLBACK SPU2init();
s32 CALLBACK SPU2open(void *pDsp);
void CALLBACK SPU2close();
void CALLBACK SPU2shutdown();
void CALLBACK SPU2write(u32 mem, u16 value);
u16 CALLBACK SPU2read(u32 mem);
void CALLBACK SPU2readDMA4Mem(u16 *pMem, int size);
void CALLBACK SPU2writeDMA4Mem(u16 *pMem, int size);
void CALLBACK SPU2interruptDMA4();
void CALLBACK SPU2readDMA7Mem(u16* pMem, int size);
void CALLBACK SPU2writeDMA7Mem(u16 *pMem, int size);
void CALLBACK SPU2interruptDMA7();
void CALLBACK SPU2irqCallback(void (*callback)());
// extended funcs
void CALLBACK SPU2async(u32 cycles);
s32 CALLBACK SPU2freeze(int mode, freezeData *data);
void CALLBACK SPU2configure();
void CALLBACK SPU2about();
s32 CALLBACK SPU2test();
#endif
/* CDVD plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef CDVDdefs
// basic funcs
s32 CALLBACK CDVDinit();
s32 CALLBACK CDVDopen();
void CALLBACK CDVDclose();
void CALLBACK CDVDshutdown();
s32 CALLBACK CDVDreadTrack(u32 lsn, int mode);
// return can be NULL (for async modes)
u8* CALLBACK CDVDgetBuffer();
s32 CALLBACK CDVDgetTN(cdvdTN *Buffer); //disk information
s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type
s32 CALLBACK CDVDgetType(); //CDVD_TYPE_xxxx
s32 CALLBACK CDVDgetTrayStatus(); //CDVD_TRAY_xxxx
// extended funcs
void CALLBACK CDVDconfigure();
void CALLBACK CDVDabout();
s32 CALLBACK CDVDtest();
#endif
/* DEV9 plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef DEV9defs
// basic funcs
s32 CALLBACK DEV9init();
s32 CALLBACK DEV9open(void *pDsp);
void CALLBACK DEV9close();
void CALLBACK DEV9shutdown();
u8 CALLBACK DEV9read8(u32 addr);
u16 CALLBACK DEV9read16(u32 addr);
u32 CALLBACK DEV9read32(u32 addr);
void CALLBACK DEV9write8(u32 addr, u8 value);
void CALLBACK DEV9write16(u32 addr, u16 value);
void CALLBACK DEV9write32(u32 addr, u32 value);
void CALLBACK DEV9readDMA8Mem(u32 *pMem, int size);
void CALLBACK DEV9writeDMA8Mem(u32 *pMem, int size);
// cycles = IOP cycles before calling callback,
// if callback returns 1 the irq is triggered, else not
void CALLBACK DEV9irqCallback(DEV9callback callback);
DEV9handler CALLBACK DEV9irqHandler(void);
// extended funcs
s32 CALLBACK DEV9freeze(int mode, freezeData *data);
void CALLBACK DEV9configure();
void CALLBACK DEV9about();
s32 CALLBACK DEV9test();
#endif
/* USB plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef USBdefs
// basic funcs
s32 CALLBACK USBinit();
s32 CALLBACK USBopen(void *pDsp);
void CALLBACK USBclose();
void CALLBACK USBshutdown();
u8 CALLBACK USBread8(u32 addr);
u16 CALLBACK USBread16(u32 addr);
u32 CALLBACK USBread32(u32 addr);
void CALLBACK USBwrite8(u32 addr, u8 value);
void CALLBACK USBwrite16(u32 addr, u16 value);
void CALLBACK USBwrite32(u32 addr, u32 value);
// cycles = IOP cycles before calling callback,
// if callback returns 1 the irq is triggered, else not
void CALLBACK USBirqCallback(USBcallback callback);
USBhandler CALLBACK USBirqHandler(void);
void CALLBACK USBsetRAM(void *mem);
// extended funcs
s32 CALLBACK USBfreeze(int mode, freezeData *data);
void CALLBACK USBconfigure();
void CALLBACK USBabout();
s32 CALLBACK USBtest();
#endif
/* Firewire plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef FIREWIREdefs
// basic funcs
s32 CALLBACK FireWireinit();
s32 CALLBACK FireWireopen(void *pDsp);
void CALLBACK FireWireclose();
void CALLBACK FireWireshutdown();
u32 CALLBACK FireWireread32(u32 addr);
void CALLBACK FireWirewrite32(u32 addr, u32 value);
void CALLBACK FireWireirqCallback(void (*callback)());
// extended funcs
s32 CALLBACK FireWirefreeze(int mode, freezeData *data);
void CALLBACK FireWireconfigure();
void CALLBACK FireWireabout();
s32 CALLBACK FireWiretest();
#endif
// might be useful for emulators
#ifdef PLUGINtypedefs
typedef u32 (CALLBACK* _PS2EgetLibType)(void);
typedef u32 (CALLBACK* _PS2EgetLibVersion2)(u32 type);
typedef char*(CALLBACK* _PS2EgetLibName)(void);
// GS
typedef s32 (CALLBACK* _GSinit)();
typedef s32 (CALLBACK* _GSopen)(void *pDsp, char *Title);
typedef void (CALLBACK* _GSclose)();
typedef void (CALLBACK* _GSshutdown)();
typedef void (CALLBACK* _GSvsync)();
typedef void (CALLBACK* _GSwrite32)(u32 mem, u32 value);
typedef void (CALLBACK* _GSwrite64)(u32 mem, u64 value);
typedef u32 (CALLBACK* _GSread32)(u32 mem);
typedef u64 (CALLBACK* _GSread64)(u32 mem);
typedef void (CALLBACK* _GSgifTransfer1)(u32 *pMem);
typedef void (CALLBACK* _GSgifTransfer2)(u32 *pMem, u32 size);
typedef void (CALLBACK* _GSgifTransfer3)(u32 *pMem, u32 size);
typedef void (CALLBACK* _GSreadFIFO)(u64 *pMem);
typedef void (CALLBACK* _GSkeyEvent)(keyEvent* ev);
typedef void (CALLBACK* _GSirqCallback)(void (*callback)());
typedef void (CALLBACK* _GSprintf)(int timeout, char *fmt, ...);
typedef void (CALLBACK* _GSgetDriverInfo)(GSdriverInfo *info);
#ifdef __WIN32__
typedef s32 (CALLBACK* _GSsetWindowInfo)(winInfo *info);
#endif
typedef void (CALLBACK* _GSmakeSnapshot)(char *path);
typedef s32 (CALLBACK* _GSfreeze)(int mode, freezeData *data);
typedef void (CALLBACK* _GSconfigure)();
typedef s32 (CALLBACK* _GStest)();
typedef void (CALLBACK* _GSabout)();
// PAD
typedef s32 (CALLBACK* _PADinit)(u32 flags);
typedef s32 (CALLBACK* _PADopen)(void *pDsp);
typedef void (CALLBACK* _PADclose)();
typedef void (CALLBACK* _PADshutdown)();
typedef keyEvent* (CALLBACK* _PADkeyEvent)();
typedef u8 (CALLBACK* _PADstartPoll)(int pad);
typedef u8 (CALLBACK* _PADpoll)(u8 value);
typedef u32 (CALLBACK* _PADquery)();
typedef void (CALLBACK* _PADgsDriverInfo)(GSdriverInfo *info);
typedef void (CALLBACK* _PADconfigure)();
typedef s32 (CALLBACK* _PADtest)();
typedef void (CALLBACK* _PADabout)();
// SPU2
typedef s32 (CALLBACK* _SPU2init)();
typedef s32 (CALLBACK* _SPU2open)(void *pDsp);
typedef void (CALLBACK* _SPU2close)();
typedef void (CALLBACK* _SPU2shutdown)();
typedef void (CALLBACK* _SPU2write)(u32 mem, u16 value);
typedef u16 (CALLBACK* _SPU2read)(u32 mem);
typedef void (CALLBACK* _SPU2readDMA4Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2writeDMA4Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2interruptDMA4)();
typedef void (CALLBACK* _SPU2readDMA7Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2writeDMA7Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2interruptDMA7)();
typedef void (CALLBACK* _SPU2irqCallback)(void (*callback)());
typedef void (CALLBACK* _SPU2async)(u32 cycles);
typedef s32 (CALLBACK* _SPU2freeze)(int mode, freezeData *data);
typedef void (CALLBACK* _SPU2configure)();
typedef s32 (CALLBACK* _SPU2test)();
typedef void (CALLBACK* _SPU2about)();
// CDVD
typedef s32 (CALLBACK* _CDVDinit)();
typedef s32 (CALLBACK* _CDVDopen)();
typedef void (CALLBACK* _CDVDclose)();
typedef void (CALLBACK* _CDVDshutdown)();
typedef s32 (CALLBACK* _CDVDreadTrack)(u32 lsn, int mode);
typedef u8* (CALLBACK* _CDVDgetBuffer)();
typedef s32 (CALLBACK* _CDVDgetTN)(cdvdTN *Buffer);
typedef s32 (CALLBACK* _CDVDgetTD)(u8 Track, cdvdTD *Buffer);
typedef s32 (CALLBACK* _CDVDgetType)();
typedef s32 (CALLBACK* _CDVDgetTrayStatus)();
typedef void (CALLBACK* _CDVDconfigure)();
typedef s32 (CALLBACK* _CDVDtest)();
typedef void (CALLBACK* _CDVDabout)();
// DEV9
typedef s32 (CALLBACK* _DEV9init)();
typedef s32 (CALLBACK* _DEV9open)(void *pDsp);
typedef void (CALLBACK* _DEV9close)();
typedef void (CALLBACK* _DEV9shutdown)();
typedef u8 (CALLBACK* _DEV9read8)(u32 mem);
typedef u16 (CALLBACK* _DEV9read16)(u32 mem);
typedef u32 (CALLBACK* _DEV9read32)(u32 mem);
typedef void (CALLBACK* _DEV9write8)(u32 mem, u8 value);
typedef void (CALLBACK* _DEV9write16)(u32 mem, u16 value);
typedef void (CALLBACK* _DEV9write32)(u32 mem, u32 value);
typedef void (CALLBACK* _DEV9readDMA8Mem)(u32 *pMem, int size);
typedef void (CALLBACK* _DEV9writeDMA8Mem)(u32 *pMem, int size);
typedef void (CALLBACK* _DEV9irqCallback)(DEV9callback callback);
typedef DEV9handler (CALLBACK* _DEV9irqHandler)(void);
typedef s32 (CALLBACK* _DEV9freeze)(int mode, freezeData *data);
typedef void (CALLBACK* _DEV9configure)();
typedef s32 (CALLBACK* _DEV9test)();
typedef void (CALLBACK* _DEV9about)();
// USB
typedef s32 (CALLBACK* _USBinit)();
typedef s32 (CALLBACK* _USBopen)(void *pDsp);
typedef void (CALLBACK* _USBclose)();
typedef void (CALLBACK* _USBshutdown)();
typedef u8 (CALLBACK* _USBread8)(u32 mem);
typedef u16 (CALLBACK* _USBread16)(u32 mem);
typedef u32 (CALLBACK* _USBread32)(u32 mem);
typedef void (CALLBACK* _USBwrite8)(u32 mem, u8 value);
typedef void (CALLBACK* _USBwrite16)(u32 mem, u16 value);
typedef void (CALLBACK* _USBwrite32)(u32 mem, u32 value);
typedef void (CALLBACK* _USBirqCallback)(USBcallback callback);
typedef USBhandler (CALLBACK* _USBirqHandler)(void);
typedef void (CALLBACK* _USBsetRAM)(void *mem);
typedef s32 (CALLBACK* _USBfreeze)(int mode, freezeData *data);
typedef void (CALLBACK* _USBconfigure)();
typedef s32 (CALLBACK* _USBtest)();
typedef void (CALLBACK* _USBabout)();
//FireWire
typedef s32 (CALLBACK* _FireWireinit)();
typedef s32 (CALLBACK* _FireWireopen)(void *pDsp);
typedef void (CALLBACK* _FireWireclose)();
typedef void (CALLBACK* _FireWireshutdown)();
typedef u32 (CALLBACK* _FireWireread32)(u32 mem);
typedef void (CALLBACK* _FireWirewrite32)(u32 mem, u32 value);
typedef void (CALLBACK* _FireWireirqCallback)(void (*callback)());
typedef s32 (CALLBACK* _FireWirefreeze)(int mode, freezeData *data);
typedef void (CALLBACK* _FireWireconfigure)();
typedef s32 (CALLBACK* _FireWiretest)();
typedef void (CALLBACK* _FireWireabout)();
#endif
#ifdef PLUGINfuncs
// GS
_GSinit GSinit;
_GSopen GSopen;
_GSclose GSclose;
_GSshutdown GSshutdown;
_GSvsync GSvsync;
_GSwrite32 GSwrite32;
_GSwrite64 GSwrite64;
_GSread32 GSread32;
_GSread64 GSread64;
_GSgifTransfer1 GSgifTransfer1;
_GSgifTransfer2 GSgifTransfer2;
_GSgifTransfer3 GSgifTransfer3;
_GSreadFIFO GSreadFIFO;
_GSkeyEvent GSkeyEvent;
_GSmakeSnapshot GSmakeSnapshot;
_GSirqCallback GSirqCallback;
_GSprintf GSprintf;
_GSgetDriverInfo GSgetDriverInfo;
#ifdef __WIN32__
_GSsetWindowInfo GSsetWindowInfo;
#endif
_GSfreeze GSfreeze;
_GSconfigure GSconfigure;
_GStest GStest;
_GSabout GSabout;
// PAD1
_PADinit PAD1init;
_PADopen PAD1open;
_PADclose PAD1close;
_PADshutdown PAD1shutdown;
_PADkeyEvent PAD1keyEvent;
_PADstartPoll PAD1startPoll;
_PADpoll PAD1poll;
_PADquery PAD1query;
_PADgsDriverInfo PAD1gsDriverInfo;
_PADconfigure PAD1configure;
_PADtest PAD1test;
_PADabout PAD1about;
// PAD2
_PADinit PAD2init;
_PADopen PAD2open;
_PADclose PAD2close;
_PADshutdown PAD2shutdown;
_PADkeyEvent PAD2keyEvent;
_PADstartPoll PAD2startPoll;
_PADpoll PAD2poll;
_PADquery PAD2query;
_PADgsDriverInfo PAD2gsDriverInfo;
_PADconfigure PAD2configure;
_PADtest PAD2test;
_PADabout PAD2about;
// SPU2
_SPU2init SPU2init;
_SPU2open SPU2open;
_SPU2close SPU2close;
_SPU2shutdown SPU2shutdown;
_SPU2write SPU2write;
_SPU2read SPU2read;
_SPU2readDMA4Mem SPU2readDMA4Mem;
_SPU2writeDMA4Mem SPU2writeDMA4Mem;
_SPU2interruptDMA4 SPU2interruptDMA4;
_SPU2readDMA7Mem SPU2readDMA7Mem;
_SPU2writeDMA7Mem SPU2writeDMA7Mem;
_SPU2interruptDMA7 SPU2interruptDMA7;
_SPU2irqCallback SPU2irqCallback;
_SPU2async SPU2async;
_SPU2freeze SPU2freeze;
_SPU2configure SPU2configure;
_SPU2test SPU2test;
_SPU2about SPU2about;
// CDVD
_CDVDinit CDVDinit;
_CDVDopen CDVDopen;
_CDVDclose CDVDclose;
_CDVDshutdown CDVDshutdown;
_CDVDreadTrack CDVDreadTrack;
_CDVDgetBuffer CDVDgetBuffer;
_CDVDgetTN CDVDgetTN;
_CDVDgetTD CDVDgetTD;
_CDVDgetType CDVDgetType;
_CDVDgetTrayStatus CDVDgetTrayStatus;
_CDVDconfigure CDVDconfigure;
_CDVDtest CDVDtest;
_CDVDabout CDVDabout;
// DEV9
_DEV9init DEV9init;
_DEV9open DEV9open;
_DEV9close DEV9close;
_DEV9shutdown DEV9shutdown;
_DEV9read8 DEV9read8;
_DEV9read16 DEV9read16;
_DEV9read32 DEV9read32;
_DEV9write8 DEV9write8;
_DEV9write16 DEV9write16;
_DEV9write32 DEV9write32;
_DEV9readDMA8Mem DEV9readDMA8Mem;
_DEV9writeDMA8Mem DEV9writeDMA8Mem;
_DEV9irqCallback DEV9irqCallback;
_DEV9irqHandler DEV9irqHandler;
_DEV9configure DEV9configure;
_DEV9freeze DEV9freeze;
_DEV9test DEV9test;
_DEV9about DEV9about;
// USB
_USBinit USBinit;
_USBopen USBopen;
_USBclose USBclose;
_USBshutdown USBshutdown;
_USBread8 USBread8;
_USBread16 USBread16;
_USBread32 USBread32;
_USBwrite8 USBwrite8;
_USBwrite16 USBwrite16;
_USBwrite32 USBwrite32;
_USBirqCallback USBirqCallback;
_USBirqHandler USBirqHandler;
_USBsetRAM USBsetRAM;
_USBconfigure USBconfigure;
_USBfreeze USBfreeze;
_USBtest USBtest;
_USBabout USBabout;
// FireWire
_FireWireinit FireWireinit;
_FireWireopen FireWireopen;
_FireWireclose FireWireclose;
_FireWireshutdown FireWireshutdown;
_FireWireread32 FireWireread32;
_FireWirewrite32 FireWirewrite32;
_FireWireirqCallback FireWireirqCallback;
_FireWireconfigure FireWireconfigure;
_FireWirefreeze FireWirefreeze;
_FireWiretest FireWiretest;
_FireWireabout FireWireabout;
#endif
#endif /* __PS2EDEFS_H__ */

View File

@ -0,0 +1,31 @@
#ifndef __PS2ETYPES_H__
#define __PS2ETYPES_H__
// Basic types
#if defined(__WIN32__)
typedef __int8 s8;
typedef __int16 s16;
typedef __int32 s32;
typedef __int64 s64;
typedef unsigned __int8 u8;
typedef unsigned __int16 u16;
typedef unsigned __int32 u32;
typedef unsigned __int64 u64;
#elif defined(__LINUX__)
typedef char s8;
typedef short s16;
typedef long s32;
typedef long long s64;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned long u32;
typedef unsigned long long u64;
#endif
#endif /* __PS2ETYPES_H__ */

View File

@ -0,0 +1,359 @@
/*
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 - 2007 CACE Technologies, Davis (California)
* All rights reserved.
*
* 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 above copyright
* 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 Politecnico di Torino, CACE Technologies
* 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
* OWNER 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.
*
*/
/** @ingroup packetapi
* @{
*/
/** @defgroup packet32h Packet.dll definitions and data structures
* Packet32.h contains the data structures and the definitions used by packet.dll.
* The file is used both by the Win9x and the WinNTx versions of packet.dll, and can be included
* by the applications that use the functions of this library
* @{
*/
#ifndef __PACKET32
#define __PACKET32
#include <winsock2.h>
#ifdef HAVE_AIRPCAP_API
#include <airpcap.h>
#else
#if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
#define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
typedef struct _AirpcapHandle *PAirpcapHandle;
#endif /* AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ */
#endif /* HAVE_AIRPCAP_API */
#ifdef HAVE_DAG_API
#include <dagc.h>
#endif /* HAVE_DAG_API */
// Working modes
#define PACKET_MODE_CAPT 0x0 ///< Capture mode
#define PACKET_MODE_STAT 0x1 ///< Statistical mode
#define PACKET_MODE_MON 0x2 ///< Monitoring mode
#define PACKET_MODE_DUMP 0x10 ///< Dump mode
#define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT ///< Statistical dump Mode
/// Alignment macro. Defines the alignment size.
#define Packet_ALIGNMENT sizeof(int)
/// Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT.
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
#define NdisMediumNull -1 ///< Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumCHDLC -2 ///< Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumPPPSerial -3 ///< Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumBare80211 -4 ///< Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumRadio80211 -5 ///< Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumPpi -6 ///< Custom linktype: NDIS doesn't provide an equivalent
// Loopback behaviour definitions
#define NPF_DISABLE_LOOPBACK 1 ///< Drop the packets sent by the NPF driver
#define NPF_ENABLE_LOOPBACK 2 ///< Capture the packets sent by the NPF driver
/*!
\brief Network type structure.
This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.
*/
typedef struct NetType
{
UINT LinkType; ///< The MAC of the current network adapter (see function PacketGetNetType() for more information)
ULONGLONG LinkSpeed; ///< The speed of the network in bits per second
}NetType;
//some definitions stolen from libpcap
#ifndef BPF_MAJOR_VERSION
/*!
\brief A BPF pseudo-assembly program.
The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet.
*/
struct bpf_program
{
UINT bf_len; ///< Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow.
struct bpf_insn *bf_insns; ///< A pointer to the first instruction of the program.
};
/*!
\brief A single BPF pseudo-instruction.
bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver.
*/
struct bpf_insn
{
USHORT code; ///< Instruction type and addressing mode.
UCHAR jt; ///< Jump if true
UCHAR jf; ///< Jump if false
int k; ///< Generic field used for various purposes.
};
/*!
\brief Structure that contains a couple of statistics values on the current capture.
It is used by packet.dll to return statistics about a capture session.
*/
struct bpf_stat
{
UINT bs_recv; ///< Number of packets that the driver received from the network adapter
///< from the beginning of the current capture. This value includes the packets
///< lost by the driver.
UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture.
///< Basically, a packet is lost when the the buffer of the driver is full.
///< In this situation the packet cannot be stored and the driver rejects it.
UINT ps_ifdrop; ///< drops by interface. XXX not yet supported
UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and
///< thus reach the application.
};
/*!
\brief Packet header.
This structure defines the header associated with every packet delivered to the application.
*/
struct bpf_hdr
{
struct timeval bh_tstamp; ///< The timestamp associated with the captured packet.
///< It is stored in a TimeVal structure.
UINT bh_caplen; ///< Length of captured portion. The captured portion <b>can be different</b>
///< from the original packet, because it is possible (with a proper filter)
///< to instruct the driver to capture only a portion of the packets.
UINT bh_datalen; ///< Original length of packet
USHORT bh_hdrlen; ///< Length of bpf header (this struct plus alignment padding). In some cases,
///< a padding could be added between the end of this structure and the packet
///< data for performance reasons. This filed can be used to retrieve the actual data
///< of the packet.
};
/*!
\brief Dump packet header.
This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets().
It is simpler than the bpf_hdr, because it corresponds to the header associated by WinPcap and libpcap to a
packet in a dump file. This makes straightforward sending WinPcap dump files to the network.
*/
struct dump_bpf_hdr{
struct timeval ts; ///< Time stamp of the packet
UINT caplen; ///< Length of captured portion. The captured portion can smaller than the
///< the original packet, because it is possible (with a proper filter) to
///< instruct the driver to capture only a portion of the packets.
UINT len; ///< Length of the original packet (off wire).
};
#endif
struct bpf_stat;
#define DOSNAMEPREFIX TEXT("Packet_") ///< Prefix added to the adapters device names to create the WinPcap devices
#define MAX_LINK_NAME_LENGTH 64 //< Maximum length of the devices symbolic links
#define NMAX_PACKET 65535
/*!
\brief Addresses of a network adapter.
This structure is used by the PacketGetNetInfoEx() function to return the IP addresses associated with
an adapter.
*/
typedef struct npf_if_addr {
struct sockaddr_storage IPAddress; ///< IP address.
struct sockaddr_storage SubnetMask; ///< Netmask for that address.
struct sockaddr_storage Broadcast; ///< Broadcast address.
}npf_if_addr;
#define ADAPTER_NAME_LENGTH 256 + 12 ///< Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
#define ADAPTER_DESC_LENGTH 128 ///< Maximum length for the description of an adapter. The value is the same used by the IP Helper API.
#define MAX_MAC_ADDR_LENGTH 8 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
#define MAX_NETWORK_ADDRESSES 16 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
typedef struct WAN_ADAPTER_INT WAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
typedef WAN_ADAPTER *PWAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
#define INFO_FLAG_NDIS_ADAPTER 0 ///< Flag for ADAPTER_INFO: this is a traditional ndis adapter
#define INFO_FLAG_NDISWAN_ADAPTER 1 ///< Flag for ADAPTER_INFO: this is a NdisWan adapter, and it's managed by WANPACKET
#define INFO_FLAG_DAG_CARD 2 ///< Flag for ADAPTER_INFO: this is a DAG card
#define INFO_FLAG_DAG_FILE 6 ///< Flag for ADAPTER_INFO: this is a DAG file
#define INFO_FLAG_DONT_EXPORT 8 ///< Flag for ADAPTER_INFO: when this flag is set, the adapter will not be listed or openend by winpcap. This allows to prevent exporting broken network adapters, like for example FireWire ones.
#define INFO_FLAG_AIRPCAP_CARD 16 ///< Flag for ADAPTER_INFO: this is an airpcap card
#define INFO_FLAG_NPFIM_DEVICE 32
/*!
\brief Describes an opened network adapter.
This structure is the most important for the functioning of packet.dll, but the great part of its fields
should be ignored by the user, since the library offers functions that avoid to cope with low-level parameters
*/
typedef struct _ADAPTER {
HANDLE hFile; ///< \internal Handle to an open instance of the NPF driver.
CHAR SymbolicLink[MAX_LINK_NAME_LENGTH]; ///< \internal A string containing the name of the network adapter currently opened.
int NumWrites; ///< \internal Number of times a packets written on this adapter will be repeated
///< on the wire.
HANDLE ReadEvent; ///< A notification event associated with the read calls on the adapter.
///< It can be passed to standard Win32 functions (like WaitForSingleObject
///< or WaitForMultipleObjects) to wait until the driver's buffer contains some
///< data. It is particularly useful in GUI applications that need to wait
///< concurrently on several events. In Windows NT/2000 the PacketSetMinToCopy()
///< function can be used to define the minimum amount of data in the kernel buffer
///< that will cause the event to be signalled.
UINT ReadTimeOut; ///< \internal The amount of time after which a read on the driver will be released and
///< ReadEvent will be signaled, also if no packets were captured
CHAR Name[ADAPTER_NAME_LENGTH];
PWAN_ADAPTER pWanAdapter;
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
#ifdef HAVE_AIRPCAP_API
PAirpcapHandle AirpcapAd;
#endif // HAVE_AIRPCAP_API
#ifdef HAVE_NPFIM_API
void* NpfImHandle;
#endif // HAVE_NPFIM_API
#ifdef HAVE_DAG_API
dagc_t *pDagCard; ///< Pointer to the dagc API adapter descriptor for this adapter
PCHAR DagBuffer; ///< Pointer to the buffer with the packets that is received from the DAG card
struct timeval DagReadTimeout; ///< Read timeout. The dagc API requires a timeval structure
unsigned DagFcsLen; ///< Length of the frame check sequence attached to any packet by the card. Obtained from the registry
DWORD DagFastProcess; ///< True if the user requests fast capture processing on this card. Higher level applications can use this value to provide a faster but possibly unprecise capture (for example, libpcap doesn't convert the timestamps).
#endif // HAVE_DAG_API
} ADAPTER, *LPADAPTER;
/*!
\brief Structure that contains a group of packets coming from the driver.
This structure defines the header associated with every packet delivered to the application.
*/
typedef struct _PACKET {
HANDLE hEvent; ///< \deprecated Still present for compatibility with old applications.
OVERLAPPED OverLapped; ///< \deprecated Still present for compatibility with old applications.
PVOID Buffer; ///< Buffer with containing the packets. See the PacketReceivePacket() for
///< details about the organization of the data in this buffer
UINT Length; ///< Length of the buffer
DWORD ulBytesReceived; ///< Number of valid bytes present in the buffer, i.e. amount of data
///< received by the last call to PacketReceivePacket()
BOOLEAN bIoComplete; ///< \deprecated Still present for compatibility with old applications.
} PACKET, *LPPACKET;
/*!
\brief Structure containing an OID request.
It is used by the PacketRequest() function to send an OID to the interface card driver.
It can be used, for example, to retrieve the status of the error counters on the adapter, its MAC address,
the list of the multicast groups defined on it, and so on.
*/
struct _PACKET_OID_DATA {
ULONG Oid; ///< OID code. See the Microsoft DDK documentation or the file ntddndis.h
///< for a complete list of valid codes.
ULONG Length; ///< Length of the data field
UCHAR Data[1]; ///< variable-lenght field that contains the information passed to or received
///< from the adapter.
};
typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
#ifdef __cplusplus
extern "C" {
#endif
/**
* @}
*/
/*
BOOLEAN QueryWinPcapRegistryStringA(CHAR *SubKeyName,
CHAR *Value,
UINT *pValueLen,
CHAR *DefaultVal);
BOOLEAN QueryWinPcapRegistryStringW(WCHAR *SubKeyName,
WCHAR *Value,
UINT *pValueLen,
WCHAR *DefaultVal);
*/
//---------------------------------------------------------------------------
// EXPORTED FUNCTIONS
//---------------------------------------------------------------------------
PCHAR PacketGetVersion();
PCHAR PacketGetDriverVersion();
BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
BOOLEAN PacketSetLoopbackBehavior(LPADAPTER AdapterObject, UINT LoopbackBehavior);
INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);
BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
LPPACKET PacketAllocatePacket(void);
VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length);
VOID PacketFreePacket(LPPACKET lpPacket);
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);
BOOLEAN PacketRequest(LPADAPTER AdapterObject,BOOLEAN Set,PPACKET_OID_DATA OidData);
HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
BOOL PacketStopDriver();
VOID PacketCloseAdapter(LPADAPTER lpAdapter);
BOOLEAN PacketStartOem(PCHAR errorString, UINT errorStringLength);
BOOLEAN PacketStartOemEx(PCHAR errorString, UINT errorStringLength, ULONG flags);
PAirpcapHandle PacketGetAirPcapHandle(LPADAPTER AdapterObject);
//
// Used by PacketStartOemEx
//
#define PACKET_START_OEM_NO_NETMON 0x00000001
#ifdef __cplusplus
}
#endif
#endif //__PACKET32

View File

@ -0,0 +1,113 @@
/*
* Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 - 2006 CACE Technologies, Davis (California)
* All rights reserved.
*
* 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 above copyright
* 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 Politecnico di Torino, CACE Technologies
* 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
* OWNER 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.
*
*/
#ifndef __WIN32_EXTENSIONS_H__
#define __WIN32_EXTENSIONS_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Definitions */
/*!
\brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit().
*/
struct pcap_send_queue
{
u_int maxlen; ///< Maximum size of the the queue, in bytes. This variable contains the size of the buffer field.
u_int len; ///< Current size of the queue, in bytes.
char *buffer; ///< Buffer containing the packets to be sent.
};
typedef struct pcap_send_queue pcap_send_queue;
/*!
\brief This typedef is a support for the pcap_get_airpcap_handle() function
*/
#if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_)
#define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_
typedef struct _AirpcapHandle *PAirpcapHandle;
#endif
#define BPF_MEM_EX_IMM 0xc0
#define BPF_MEM_EX_IND 0xe0
/*used for ST*/
#define BPF_MEM_EX 0xc0
#define BPF_TME 0x08
#define BPF_LOOKUP 0x90
#define BPF_EXECUTE 0xa0
#define BPF_INIT 0xb0
#define BPF_VALIDATE 0xc0
#define BPF_SET_ACTIVE 0xd0
#define BPF_RESET 0xe0
#define BPF_SET_MEMORY 0x80
#define BPF_GET_REGISTER_VALUE 0x70
#define BPF_SET_REGISTER_VALUE 0x60
#define BPF_SET_WORKING 0x50
#define BPF_SET_ACTIVE_READ 0x40
#define BPF_SET_AUTODELETION 0x30
#define BPF_SEPARATION 0xff
/* Prototypes */
pcap_send_queue* pcap_sendqueue_alloc(u_int memsize);
void pcap_sendqueue_destroy(pcap_send_queue* queue);
int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data);
u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync);
HANDLE pcap_getevent(pcap_t *p);
struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size);
int pcap_setuserbuffer(pcap_t *p, int size);
int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks);
int pcap_live_dump_ended(pcap_t *p, int sync);
int pcap_offline_filter(struct bpf_program *prog, const struct pcap_pkthdr *header, const u_char *pkt_data);
int pcap_start_oem(char* err_str, int flags);
PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p);
#ifdef __cplusplus
}
#endif
#endif //__WIN32_EXTENSIONS_H__

View File

@ -0,0 +1,54 @@
#include <stdlib.h>
#include <winsock2.h>
#include "DEV9.h"
#define GetKeyV(name, var, s, t) \
size = s; type = t; \
RegQueryValueEx(myKey, name, 0, &type, (LPBYTE) var, &size);
#define GetKeyVdw(name, var) \
GetKeyV(name, var, 4, REG_DWORD);
#define SetKeyV(name, var, s, t) \
RegSetValueEx(myKey, name, 0, t, (LPBYTE) var, s);
#define SetKeyVdw(name, var) \
SetKeyV(name, var, 4, REG_DWORD);
void SaveConf() {
HKEY myKey;
DWORD myDisp;
RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &myKey, &myDisp);
SetKeyV("Eth", config.Eth, strlen(config.Eth), REG_SZ);
SetKeyV("Hdd", config.Hdd, strlen(config.Hdd), REG_SZ);
SetKeyVdw("HddSize", &config.HddSize);
SetKeyVdw("ethEnable", &config.ethEnable);
SetKeyVdw("hddEnable", &config.hddEnable);
RegCloseKey(myKey);
}
void LoadConf() {
HKEY myKey;
DWORD type, size;
memset(&config, 0, sizeof(config));
strcpy(config.Hdd, HDD_DEF);
config.HddSize=8*1024;
strcpy(config.Eth, ETH_DEF);
if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PS2Eplugin\\DEV9\\DEV9linuz", 0, KEY_ALL_ACCESS, &myKey)!=ERROR_SUCCESS) {
SaveConf(); return;
}
GetKeyV("Eth", config.Eth, sizeof(config.Eth), REG_SZ);
GetKeyV("Hdd", config.Hdd, sizeof(config.Hdd), REG_SZ);
GetKeyVdw("HddSize", &config.HddSize);
GetKeyVdw("ethEnable", &config.ethEnable);
GetKeyVdw("hddEnable", &config.hddEnable);
RegCloseKey(myKey);
}

View File

@ -0,0 +1,2 @@
void SaveConf();
void LoadConf();

View File

@ -0,0 +1,28 @@
; DEV9null.def : Declares the module parameters for the DLL.
EXPORTS
; Explicit exports can go here
PS2EgetLibType @2
PS2EgetLibName @3
PS2EgetLibVersion2 @4
DEV9init @5
DEV9shutdown @6
DEV9open @7
DEV9close @8
DEV9read8 @9
DEV9read16 @10
DEV9read32 @11
DEV9write8 @12
DEV9write16 @13
DEV9write32 @14
DEV9readDMA8Mem @15
DEV9writeDMA8Mem @16
DEV9configure @17
DEV9test @18
DEV9about @19
DEV9irqCallback @20
DEV9irqHandler @21
DEV9setSettingsDir

View File

@ -0,0 +1,126 @@
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Spanish (Argentina) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ESS)
#ifdef _WIN32
LANGUAGE LANG_SPANISH, SUBLANG_SPANISH_ARGENTINA
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_CONFIG DIALOGEX 0, 0, 290, 170
STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "HDD Configure"
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,115,150,50,14
PUSHBUTTON "Cancel",IDCANCEL,233,150,50,14
COMBOBOX IDC_BAYTYPE,60,10,223,47,CBS_DROPDOWNLIST | CBS_SORT | WS_DISABLED
LTEXT "DEV9 Type",IDC_STATIC,15,10,41,11,SS_CENTERIMAGE
LTEXT "Ethernet Device",IDC_STATIC,15,60,60,10,SS_CENTERIMAGE
COMBOBOX IDC_ETHDEV,83,60,193,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Ethernet",IDC_STATIC,7,30,276,50
CONTROL "Enabled",IDC_ETHENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,15,45,42,10
LTEXT "HDD File",IDC_STATIC,15,115,60,10,SS_CENTERIMAGE | WS_DISABLED
GROUPBOX "Hard Disk Drive (not yet properly implemented)",IDC_STATIC,7,90,276,50
CONTROL "Enabled",IDC_HDDENABLED,"Button",BS_AUTOCHECKBOX | WS_DISABLED | WS_TABSTOP,15,100,42,10
EDITTEXT IDC_HDDFILE,85,115,191,12,ES_AUTOHSCROLL | WS_DISABLED
END
IDD_ABOUT DIALOGEX 0, 0, 177, 106
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "DEV9 About"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,65,85,50,14
LTEXT "DEV9 Driver",IDC_NAME,59,7,42,8
LTEXT "Original Authors:\n\tlinuzappz <linuzappz@hotmail.com>\n\tShadow <shadow@pcsx2.net>",IDC_STATIC,7,18,141,30
LTEXT "Fixed and improved by:\n\tgigahez <gigaherz@pcsx2.net>\n\tdrk||Raziel",IDC_STATIC,7,49,155,27
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_CONFIG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 283
TOPMARGIN, 7
BOTTOMMARGIN, 164
END
IDD_ABOUT, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 170
TOPMARGIN, 7
BOTTOMMARGIN, 99
END
END
#endif // APSTUDIO_INVOKED
#endif // Spanish (Argentina) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View File

@ -0,0 +1,136 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>DEV9ghzdrk</ProjectName>
<ProjectGuid>{BBE4E5FB-530A-4D18-A633-35AF0577B7F3}</ProjectGuid>
<RootNamespace>DEV9ghzdrk</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\common\vsprops\plugin_svnroot.props" />
<Import Project="ProjectRootDir.props" />
<Import Project="..\..\..\common\vsprops\BaseProperties.props" />
<Import Project="..\..\..\common\vsprops\CodeGen_Release.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\..\common\vsprops\plugin_svnroot.props" />
<Import Project="ProjectRootDir.props" />
<Import Project="..\..\..\common\vsprops\BaseProperties.props" />
<Import Project="..\..\..\common\vsprops\IncrementalLinking.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<AdditionalIncludeDirectories>$(ProjectDir)\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0408</Culture>
</ResourceCompile>
<Link>
<OutputFile>$(OutDir)$(TargetName)$(TargetExt)</OutputFile>
<ModuleDefinitionFile>.\DEV9ghzdrk.def</ModuleDefinitionFile>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalDependencies>ws2_32.lib;iphlpapi.lib;wpcap.lib;packet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>$(ProjectDir)../pcap/wpcap_32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>
</PrecompiledHeader>
<AdditionalIncludeDirectories>$(ProjectDir)\..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0408</Culture>
</ResourceCompile>
<Link>
<ModuleDefinitionFile>DEV9ghzdrk.def</ModuleDefinitionFile>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
<AdditionalLibraryDirectories>$(ProjectDir)../pcap/wpcap_32;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>ws2_32.lib;iphlpapi.lib;wpcap.lib;packet.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\DEV9.cpp" />
<ClCompile Include="..\flash.cpp" />
<ClCompile Include="..\pcap_io.cpp" />
<ClCompile Include="Config.cpp" />
<ClCompile Include="Win32.cpp" />
<ClCompile Include="smap.cpp" />
<ClCompile Include="net.cpp" />
<ClCompile Include="tap-win32.cpp" />
<ClCompile Include="icmp.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="socket_io.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="DEV9ghzdrk.def" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="mtfifo.h" />
<ClInclude Include="smap.h" />
<ClInclude Include="net.h" />
<ClInclude Include="pcap_io.h" />
<ClInclude Include="tap.h" />
<ClInclude Include="..\DEV9.h" />
<ClInclude Include="..\PS2Edefs.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DEV9ghzdrk.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{c269b350-967d-41e2-9e0e-e454d5bc53c4}</UniqueIdentifier>
<Extensions>cpp;c;cxx;rc;def;r;odl;idl;hpj;bat</Extensions>
</Filter>
<Filter Include="Source Files\smap">
<UniqueIdentifier>{c19bd699-ac94-4cd8-bb19-c8c47a0a4608}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\ethernet i/o">
<UniqueIdentifier>{02c8fe11-fda9-4bc5-80c0-399198b16979}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\ethernet i/o\pcap">
<UniqueIdentifier>{1c0eef21-bc05-4eaa-9984-27d43ea85743}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\ethernet i/o\tap">
<UniqueIdentifier>{8768cdfe-28b8-4cc5-a92e-c4f3f77d7660}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\ethernet i/o\sock">
<UniqueIdentifier>{63c91c1b-ddb1-49de-b9e1-198780595d23}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{068d3325-67a3-42e1-9091-91d5b4228dea}</UniqueIdentifier>
<Extensions>h;hpp;hxx;hm;inl</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{30994d8f-3093-437c-8bb0-5d22f02f59ef}</UniqueIdentifier>
<Extensions>ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Config.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Win32.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="smap.cpp">
<Filter>Source Files\smap</Filter>
</ClCompile>
<ClCompile Include="net.cpp">
<Filter>Source Files\ethernet i/o</Filter>
</ClCompile>
<ClCompile Include="tap-win32.cpp">
<Filter>Source Files\ethernet i/o\tap</Filter>
</ClCompile>
<ClCompile Include="icmp.cpp">
<Filter>Source Files\ethernet i/o\sock</Filter>
</ClCompile>
<ClCompile Include="socket_io.cpp">
<Filter>Source Files\ethernet i/o\sock</Filter>
</ClCompile>
<ClCompile Include="..\DEV9.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\flash.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\pcap_io.cpp">
<Filter>Source Files\ethernet i/o\pcap</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="DEV9ghzdrk.def">
<Filter>Source Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ClInclude Include="mtfifo.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="smap.h">
<Filter>Source Files\smap</Filter>
</ClInclude>
<ClInclude Include="net.h">
<Filter>Source Files\ethernet i/o</Filter>
</ClInclude>
<ClInclude Include="pcap_io.h">
<Filter>Source Files\ethernet i/o\pcap</Filter>
</ClInclude>
<ClInclude Include="tap.h">
<Filter>Source Files\ethernet i/o\tap</Filter>
</ClInclude>
<ClInclude Include="..\DEV9.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\PS2Edefs.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="DEV9ghzdrk.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,90 @@
/*++ BUILD Version: 0004 // Increment this if a change has global effects
Copyright (c) 1992-1993 Microsoft Corporation
Module Name:
devioctl.h
Revision History:
-- */
// begin_winioctl
#ifndef _DEVIOCTL_
#define _DEVIOCTL_
// begin_ntddk begin_nthal begin_ntifs
//
// Define the various device type values. Note that values used by Microsoft
// Corporation are in the range 0-32767, and 32768-65535 are reserved for use
// by customers.
//
#define DEVICE_TYPE ULONG
#define FILE_DEVICE_BEEP 0x00000001
#define FILE_DEVICE_CD_ROM 0x00000002
#define FILE_DEVICE_CD_ROM_FILE_SYSTEM 0x00000003
#define FILE_DEVICE_CONTROLLER 0x00000004
#define FILE_DEVICE_DATALINK 0x00000005
#define FILE_DEVICE_DFS 0x00000006
#define FILE_DEVICE_DISK 0x00000007
#define FILE_DEVICE_DISK_FILE_SYSTEM 0x00000008
#define FILE_DEVICE_FILE_SYSTEM 0x00000009
#define FILE_DEVICE_INPORT_PORT 0x0000000a
#define FILE_DEVICE_KEYBOARD 0x0000000b
#define FILE_DEVICE_MAILSLOT 0x0000000c
#define FILE_DEVICE_MIDI_IN 0x0000000d
#define FILE_DEVICE_MIDI_OUT 0x0000000e
#define FILE_DEVICE_MOUSE 0x0000000f
#define FILE_DEVICE_MULTI_UNC_PROVIDER 0x00000010
#define FILE_DEVICE_NAMED_PIPE 0x00000011
#define FILE_DEVICE_NETWORK 0x00000012
#define FILE_DEVICE_NETWORK_BROWSER 0x00000013
#define FILE_DEVICE_NETWORK_FILE_SYSTEM 0x00000014
#define FILE_DEVICE_NULL 0x00000015
#define FILE_DEVICE_PARALLEL_PORT 0x00000016
#define FILE_DEVICE_PHYSICAL_NETCARD 0x00000017
#define FILE_DEVICE_PRINTER 0x00000018
#define FILE_DEVICE_SCANNER 0x00000019
#define FILE_DEVICE_SERIAL_MOUSE_PORT 0x0000001a
#define FILE_DEVICE_SERIAL_PORT 0x0000001b
#define FILE_DEVICE_SCREEN 0x0000001c
#define FILE_DEVICE_SOUND 0x0000001d
#define FILE_DEVICE_STREAMS 0x0000001e
#define FILE_DEVICE_TAPE 0x0000001f
#define FILE_DEVICE_TAPE_FILE_SYSTEM 0x00000020
#define FILE_DEVICE_TRANSPORT 0x00000021
#define FILE_DEVICE_UNKNOWN 0x00000022
#define FILE_DEVICE_VIDEO 0x00000023
#define FILE_DEVICE_VIRTUAL_DISK 0x00000024
#define FILE_DEVICE_WAVE_IN 0x00000025
#define FILE_DEVICE_WAVE_OUT 0x00000026
#define FILE_DEVICE_8042_PORT 0x00000027
#define FILE_DEVICE_NETWORK_REDIRECTOR 0x00000028
#define FILE_DEVICE_BATTERY 0x00000029
#define FILE_DEVICE_BUS_EXTENDER 0x0000002a
#define FILE_DEVICE_MODEM 0x0000002b
#define FILE_DEVICE_VDM 0x0000002c
#define FILE_DEVICE_MASS_STORAGE 0x0000002d
//
// Macro definition for defining IOCTL and FSCTL function control codes. Note
// that function codes 0-2047 are reserved for Microsoft Corporation, and
// 2048-4095 are reserved for customers.
//
#define CTL_CODE( DeviceType, Function, Method, Access ) ( \
((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
)
//
// Define the method codes for how buffers are passed for I/O and FS controls
//
#define METHOD_BUFFERED 0
#define METHOD_IN_DIRECT 1
#define METHOD_OUT_DIRECT 2
#define METHOD_NEITHER 3
//
// Define the access check value for any access
//
//
// The FILE_READ_ACCESS and FILE_WRITE_ACCESS constants are also defined in
// ntioapi.h as FILE_READ_DATA and FILE_WRITE_DATA. The values for these
// constants *MUST* always be in sync.
//
#define FILE_ANY_ACCESS 0
#define FILE_READ_ACCESS ( 0x0001 ) // file & pipe
#define FILE_WRITE_ACCESS ( 0x0002 ) // file & pipe
// end_ntddk end_nthal end_ntifs
#endif // _DEVIOCTL_
// end_winioctl

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="UserMacros">
<SvnRootDir>$(ProjectRootDir)\..\..</SvnRootDir>
<SvnCommonDir>$(SvnRootDir)\common</SvnCommonDir>
</PropertyGroup>
<PropertyGroup>
<_ProjectFileVersion>10.0.30128.1</_ProjectFileVersion>
</PropertyGroup>
<ItemGroup>
<BuildMacro Include="SvnRootDir">
<Value>$(SvnRootDir)</Value>
</BuildMacro>
</ItemGroup>
</Project>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioPropertySheet
ProjectType="Visual C++"
Version="8.00"
Name="ProjectRootDir"
>
<UserMacro
Name="SvnRootDir"
Value="$(ProjectRootDir)\..\.."
/>
</VisualStudioPropertySheet>

View File

@ -0,0 +1,168 @@
#include <stdio.h>
#include <winsock2.h>
#include <windows.h>
#include <windowsx.h>
#include "Config.h"
#include "resource.h"
#include "DEV9.h"
#include "pcap.h"
#include "pcap_io.h"
#include "net.h"
#include "tap.h"
extern HINSTANCE hInst;
//HANDLE handleDEV9Thread = NULL;
//DWORD dwThreadId, dwThrdParam;
void SysMessage(char *fmt, ...) {
va_list list;
char tmp[512];
va_start(list,fmt);
vsprintf(tmp,fmt,list);
va_end(list);
MessageBox(0, tmp, "Dev9linuz Msg", 0);
}
void OnInitDialog(HWND hW) {
char *dev;
//int i;
LoadConf();
ComboBox_AddString(GetDlgItem(hW, IDC_BAYTYPE), "Expansion");
ComboBox_AddString(GetDlgItem(hW, IDC_BAYTYPE), "PC Card");
for (int j=0;j<2;j++)
{
for (int i=0; i<pcap_io_get_dev_num(); i++) {
dev = pcap_io_get_dev_desc(i,j);
int itm=ComboBox_AddString(GetDlgItem(hW, IDC_ETHDEV), dev);
ComboBox_SetItemData(GetDlgItem(hW, IDC_ETHDEV),itm,strdup(pcap_io_get_dev_name(i,j)));
if (strcmp(pcap_io_get_dev_name(i,j), config.Eth) == 0) {
ComboBox_SetCurSel(GetDlgItem(hW, IDC_ETHDEV), itm);
}
}
}
vector<tap_adapter> * al=GetTapAdapters();
for (int i=0; i<al->size(); i++) {
int itm=ComboBox_AddString(GetDlgItem(hW, IDC_ETHDEV), al[0][i].name.c_str());
ComboBox_SetItemData(GetDlgItem(hW, IDC_ETHDEV),itm,strdup( al[0][i].guid.c_str()));
if (strcmp(al[0][i].guid.c_str(), config.Eth) == 0) {
ComboBox_SetCurSel(GetDlgItem(hW, IDC_ETHDEV), itm);
}
}
Edit_SetText(GetDlgItem(hW, IDC_HDDFILE), config.Hdd);
Button_SetCheck(GetDlgItem(hW, IDC_ETHENABLED), config.ethEnable);
Button_SetCheck(GetDlgItem(hW, IDC_HDDENABLED), config.hddEnable);
}
void OnOk(HWND hW) {
int i = ComboBox_GetCurSel(GetDlgItem(hW, IDC_ETHDEV));
char* ptr=(char*)ComboBox_GetItemData(GetDlgItem(hW, IDC_ETHDEV),i);
strcpy(config.Eth, ptr);
Edit_GetText(GetDlgItem(hW, IDC_HDDFILE), config.Hdd, 256);
config.ethEnable = Button_GetCheck(GetDlgItem(hW, IDC_ETHENABLED));
config.hddEnable = Button_GetCheck(GetDlgItem(hW, IDC_HDDENABLED));
SaveConf();
EndDialog(hW, TRUE);
}
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
case WM_INITDIALOG:
OnInitDialog(hW);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDCANCEL:
EndDialog(hW, FALSE);
return TRUE;
case IDOK:
OnOk(hW);
return TRUE;
}
}
return FALSE;
}
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
case IDOK:
EndDialog(hW, FALSE);
return TRUE;
}
}
return FALSE;
}
void CALLBACK DEV9configure() {
DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG),
GetActiveWindow(),
(DLGPROC)ConfigureDlgProc);
//SysMessage("Nothing to Configure");
}
void CALLBACK DEV9about() {
DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(),
(DLGPROC)AboutDlgProc);
}
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason,
LPVOID lpReserved) {
hInst = (HINSTANCE)hModule;
return TRUE; // very quick :)
}
/*
UINT DEV9ThreadProc() {
DEV9thread();
return 0;
}*/
NetAdapter* GetNetAdapter()
{
if(config.Eth[0]=='p')
{
return new PCAPAdapter();
}
else if (config.Eth[0]=='t')
{
return new TAPAdapter();
}
else
return 0;
}
s32 _DEV9open()
{
//handleDEV9Thread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) DEV9ThreadProc, &dwThrdParam, CREATE_SUSPENDED, &dwThreadId);
//SetThreadPriority(handleDEV9Thread,THREAD_PRIORITY_HIGHEST);
//ResumeThread (handleDEV9Thread);
NetAdapter* na=GetNetAdapter();
if (!na)
emu_printf("Failed to GetNetAdapter()\n");
InitNet( na);
return 0;
}
void _DEV9close() {
//TerminateThread(handleDEV9Thread,0);
//handleDEV9Thread = NULL;
TermNet();
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,5 @@
#include <windows.h>
#include <winuser.h>
#define IDC_STATIC (-1)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
#pragma once
#include "dev9.h"
void ata_init();
void ata_term();
template<int sz>
void CALLBACK ata_write(u32 addr, u32 value);
template<int sz>
u8 CALLBACK ata_read(u32 addr);
void CALLBACK ata_readDMA8Mem(u32 *pMem, int size);
void CALLBACK ata_writeDMA8Mem(u32 *pMem, int size);

View File

@ -0,0 +1,105 @@
#include <winsock2.h>
#include <windows.h>
#include <windowsx.h>
#include <iphlpapi.h>
#include <icmpapi.h>
#include <stdio.h>
#include <list>
struct pending_icmp_request
{
char ipaddress[4];
HANDLE hEvent;
DWORD sTick;
DWORD timeOut; //ttl in ms
DWORD replyBufferSize;
char *replyBuffer;
char *requestData;
void *userdata;
pending_icmp_request()
{
memset(this,0,sizeof(pending_icmp_request));
}
pending_icmp_request(pending_icmp_request&p)
{
memcpy(this,&p,sizeof(p));
}
};
typedef std::list<pending_icmp_request> request_list;
request_list ping_list;
HANDLE hIP;
int icmp_init()
{
hIP = IcmpCreateFile();
if(hIP==INVALID_HANDLE_VALUE)
return -1;
return 0;
}
void icmp_start(unsigned char *ipaddr, int ttl, void *data, int datasize, void *udata)
{
pending_icmp_request req;
req.hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
req.sTick = GetTickCount();
req.timeOut = ttl;
req.requestData = (char*)malloc(datasize);
memcpy(req.requestData,data,datasize);
memcpy(req.ipaddress,ipaddr,4);
req.replyBufferSize = (sizeof(ICMP_ECHO_REPLY) + sizeof(datasize));
req.replyBuffer = (char*)malloc(replyBufferSize);
req.userdata=udata;
ping_list.push_back(req);
IcmpSendEcho2(hIP,req.hEvent,NULL,NULL,*(DWORD*)ipaddr,req.requestData,58,
NULL,req.replyBuffer,replyBufferSize,ttl);
}
int icmp_check_replies(char *ipaddress, void **udata)
{
for(request_list::iterator rit=ping_list.begin();rit!=ping_list.end();rit++)
{
if(WaitForSingleObject(rit->hEvent,0)==0) //handle is signaled, reply received.
{
if(IcmpParseReplies(rit->replyBuffer,rit->replyBufferSize)>0)
{
memcpy(ipaddress,rit->ipaddress,4);
ping_list.remove(rit);
return 1; //reply received
}
ResetEvent(rit->hEvent);
}
if(GetTickCount() >= (rit->sTick+rit->timeOut))
{
memcpy(ipaddress,rit->ipaddress,4);
*udata = rit->userdata;
ping_list.remove(rit);
return 2; //timeout
}
}
return 0;
}
void icmp_close()
{
IcmpCloseHandle(hIP);
}

View File

@ -0,0 +1,70 @@
#pragma once
#include <windows.h>
//a simple, mt-safe fifo template class
template<typename T>
class mtfifo
{
struct container
{
container(container* n,T d)
{
next=n;
data=d;
}
container* next;T data;
};
container* start;
container* end;
CRITICAL_SECTION cs;
public:
mtfifo()
{
InitializeCriticalSection(&cs);
}
~mtfifo()
{
//no need to destroy the CS? i cant remember realy .. ;p
}
void put(T data)
{
EnterCriticalSection(&cs);
if (end==0)
{
end=start=new container(0,data);
}
else
{
end=end->next=new container(0,data);
}
LeaveCriticalSection(&cs);
}
//Note, this is partialy mt-safe, the get may fail even if that returned false
bool empty(){ return start==0;}
bool get(T& rvi)
{
container* rv;
EnterCriticalSection(&cs);
if (start==0)
{
rv=0; //error
}
else
{
rv=start;
start=rv->next;
if (!start)
end=0; //last item
}
LeaveCriticalSection(&cs);
if(!rv)
return false;
rvi=rv->data;
delete rv;
return true;
}
};

View File

@ -0,0 +1,51 @@
#include "net.h"
#include "Dev9.h"
//mtfifo<NetPacket*> rx_fifo;
//mtfifo<NetPacket*> tx_fifo;
NetAdapter* nif;
HANDLE rx_thread;
volatile bool RxRunning=false;
//rx thread
DWORD WINAPI NetRxThread(LPVOID lpThreadParameter)
{
NetPacket tmp;
while(RxRunning)
{
while(rx_fifo_can_rx() && nif->recv(&tmp))
{
rx_process(&tmp);
}
Sleep(10);
}
return 0;
}
void tx_put(NetPacket* pkt)
{
nif->send(pkt);
//pkt must be copied if its not processed by here, since it can be allocated on the callers stack
}
void InitNet(NetAdapter* ad)
{
nif=ad;
RxRunning=true;
rx_thread=CreateThread(0,0,NetRxThread,0,CREATE_SUSPENDED,0);
SetThreadPriority(rx_thread,THREAD_PRIORITY_HIGHEST);
ResumeThread(rx_thread);
}
void TermNet()
{
RxRunning=false;
emu_printf("Waiting for RX-net thread to terminate..");
WaitForSingleObject(rx_thread,-1);
emu_printf(".done\n");
delete nif;
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <stdlib.h>
#include <string.h> //uh isnt memcpy @ stdlib ?
struct NetPacket
{
NetPacket() {size=0;}
NetPacket(void* ptr,int sz) {size=sz;memcpy(buffer,ptr,sz);}
int size;
char buffer[2048-sizeof(int)];//1536 is realy needed, just pad up to 2048 bytes :)
};
/*
extern mtfifo<NetPacket*> rx_fifo;
extern mtfifo<NetPacket*> tx_fifo;
*/
class NetAdapter
{
public:
virtual bool blocks()=0;
virtual bool recv(NetPacket* pkt)=0; //gets a packet
virtual bool send(NetPacket* pkt)=0; //sends the packet and deletes it when done
virtual ~NetAdapter(){}
};
void tx_put(NetPacket* ptr);
void InitNet(NetAdapter* adapter);
void TermNet();

View File

@ -0,0 +1,450 @@
/*
* Copyright (c) 1999 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* 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 above copyright
* 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 Politecnico di Torino 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
* OWNER 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.
*
*/
/** @ingroup packetapi
* @{
*/
/** @defgroup packet32h Packet.dll definitions and data structures
* Packet32.h contains the data structures and the definitions used by packet.dll.
* The file is used both by the Win9x and the WinNTx versions of packet.dll, and can be included
* by the applications that use the functions of this library
* @{
*/
#ifndef __PACKET32
#define __PACKET32
#include <winsock2.h>
#include "devioctl.h"
#ifdef HAVE_DAG_API
#include <dagc.h>
#endif /* HAVE_DAG_API */
// Working modes
#define PACKET_MODE_CAPT 0x0 ///< Capture mode
#define PACKET_MODE_STAT 0x1 ///< Statistical mode
#define PACKET_MODE_MON 0x2 ///< Monitoring mode
#define PACKET_MODE_DUMP 0x10 ///< Dump mode
#define PACKET_MODE_STAT_DUMP MODE_DUMP | MODE_STAT ///< Statistical dump Mode
// ioctls
#define FILE_DEVICE_PROTOCOL 0x8000
#define IOCTL_PROTOCOL_STATISTICS CTL_CODE(FILE_DEVICE_PROTOCOL, 2 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_RESET CTL_CODE(FILE_DEVICE_PROTOCOL, 3 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_READ CTL_CODE(FILE_DEVICE_PROTOCOL, 4 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_WRITE CTL_CODE(FILE_DEVICE_PROTOCOL, 5 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PROTOCOL_MACNAME CTL_CODE(FILE_DEVICE_PROTOCOL, 6 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_OPEN CTL_CODE(FILE_DEVICE_PROTOCOL, 7 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_CLOSE CTL_CODE(FILE_DEVICE_PROTOCOL, 8 , METHOD_BUFFERED, FILE_ANY_ACCESS)
#define pBIOCSETBUFFERSIZE 9592 ///< IOCTL code: set kernel buffer size.
#define pBIOCSETF 9030 ///< IOCTL code: set packet filtering program.
#define pBIOCGSTATS 9031 ///< IOCTL code: get the capture stats.
#define pBIOCSRTIMEOUT 7416 ///< IOCTL code: set the read timeout.
#define pBIOCSMODE 7412 ///< IOCTL code: set working mode.
#define pBIOCSWRITEREP 7413 ///< IOCTL code: set number of physical repetions of every packet written by the app.
#define pBIOCSMINTOCOPY 7414 ///< IOCTL code: set minimum amount of data in the kernel buffer that unlocks a read call.
#define pBIOCSETOID 2147483648 ///< IOCTL code: set an OID value.
#define pBIOCQUERYOID 2147483652 ///< IOCTL code: get an OID value.
#define pATTACHPROCESS 7117 ///< IOCTL code: attach a process to the driver. Used in Win9x only.
#define pDETACHPROCESS 7118 ///< IOCTL code: detach a process from the driver. Used in Win9x only.
#define pBIOCSETDUMPFILENAME 9029 ///< IOCTL code: set the name of a the file used by kernel dump mode.
#define pBIOCEVNAME 7415 ///< IOCTL code: get the name of the event that the driver signals when some data is present in the buffer.
#define pBIOCSENDPACKETSNOSYNC 9032 ///< IOCTL code: Send a buffer containing multiple packets to the network, ignoring the timestamps associated with the packets.
#define pBIOCSENDPACKETSSYNC 9033 ///< IOCTL code: Send a buffer containing multiple packets to the network, respecting the timestamps associated with the packets.
#define pBIOCSETDUMPLIMITS 9034 ///< IOCTL code: Set the dump file limits. See the PacketSetDumpLimits() function.
#define pBIOCISDUMPENDED 7411 ///< IOCTL code: Get the status of the kernel dump process. See the PacketIsDumpEnded() function.
#define pBIOCSTIMEZONE 7471 ///< IOCTL code: set time zone. Used in Win9x only.
/// Alignment macro. Defines the alignment size.
#define Packet_ALIGNMENT sizeof(int)
/// Alignment macro. Rounds up to the next even multiple of Packet_ALIGNMENT.
#define Packet_WORDALIGN(x) (((x)+(Packet_ALIGNMENT-1))&~(Packet_ALIGNMENT-1))
#define NdisMediumNull -1 // Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumCHDLC -2 // Custom linktype: NDIS doesn't provide an equivalent
#define NdisMediumPPPSerial -3 // Custom linktype: NDIS doesn't provide an equivalent
/*!
\brief Network type structure.
This structure is used by the PacketGetNetType() function to return information on the current adapter's type and speed.
*/
typedef struct NetType
{
UINT LinkType; ///< The MAC of the current network adapter (see function PacketGetNetType() for more information)
ULONGLONG LinkSpeed; ///< The speed of the network in bits per second
}NetType;
//some definitions stolen from libpcap
#ifndef BPF_MAJOR_VERSION
/*!
\brief A BPF pseudo-assembly program.
The program will be injected in the kernel by the PacketSetBPF() function and applied to every incoming packet.
*/
struct bpf_program
{
UINT bf_len; ///< Indicates the number of instructions of the program, i.e. the number of struct bpf_insn that will follow.
struct bpf_insn *bf_insns; ///< A pointer to the first instruction of the program.
};
/*!
\brief A single BPF pseudo-instruction.
bpf_insn contains a single instruction for the BPF register-machine. It is used to send a filter program to the driver.
*/
struct bpf_insn
{
USHORT code; ///< Instruction type and addressing mode.
UCHAR jt; ///< Jump if true
UCHAR jf; ///< Jump if false
int k; ///< Generic field used for various purposes.
};
/*!
\brief Structure that contains a couple of statistics values on the current capture.
It is used by packet.dll to return statistics about a capture session.
*/
struct bpf_stat
{
UINT bs_recv; ///< Number of packets that the driver received from the network adapter
///< from the beginning of the current capture. This value includes the packets
///< lost by the driver.
UINT bs_drop; ///< number of packets that the driver lost from the beginning of a capture.
///< Basically, a packet is lost when the the buffer of the driver is full.
///< In this situation the packet cannot be stored and the driver rejects it.
UINT ps_ifdrop; ///< drops by interface. XXX not yet supported
UINT bs_capt; ///< number of packets that pass the filter, find place in the kernel buffer and
///< thus reach the application.
};
/*!
\brief Packet header.
This structure defines the header associated with every packet delivered to the application.
*/
struct bpf_hdr
{
struct timeval bh_tstamp; ///< The timestamp associated with the captured packet.
///< It is stored in a TimeVal structure.
UINT bh_caplen; ///< Length of captured portion. The captured portion <b>can be different</b>
///< from the original packet, because it is possible (with a proper filter)
///< to instruct the driver to capture only a portion of the packets.
UINT bh_datalen; ///< Original length of packet
USHORT bh_hdrlen; ///< Length of bpf header (this struct plus alignment padding). In some cases,
///< a padding could be added between the end of this structure and the packet
///< data for performance reasons. This filed can be used to retrieve the actual data
///< of the packet.
};
/*!
\brief Dump packet header.
This structure defines the header associated with the packets in a buffer to be used with PacketSendPackets().
It is simpler than the bpf_hdr, because it corresponds to the header associated by WinPcap and libpcap to a
packet in a dump file. This makes straightforward sending WinPcap dump files to the network.
*/
struct dump_bpf_hdr{
struct timeval ts; ///< Time stamp of the packet
UINT caplen; ///< Length of captured portion. The captured portion can smaller than the
///< the original packet, because it is possible (with a proper filter) to
///< instruct the driver to capture only a portion of the packets.
UINT len; ///< Length of the original packet (off wire).
};
#endif
#define DOSNAMEPREFIX TEXT("Packet_") ///< Prefix added to the adapters device names to create the WinPcap devices
#define MAX_LINK_NAME_LENGTH 64 //< Maximum length of the devices symbolic links
#define NMAX_PACKET 65535
/*
* Desired design of maximum size and alignment.
* These are implementation specific.
*/
#define _SS_MAXSIZE 128 // Maximum size.
#define _SS_ALIGNSIZE (sizeof(__int64)) // Desired alignment.
/*
* Definitions used for sockaddr_storage structure paddings design.
*/
#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof (short))
#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof (short) + _SS_PAD1SIZE \
+ _SS_ALIGNSIZE))
/*
struct sockaddr_storage {
short ss_family; // Address family.
char __ss_pad1[_SS_PAD1SIZE]; // 6 byte pad, this is to make
// implementation specific pad up to
// alignment field that follows explicit
// in the data structure.
__int64 __ss_align; // Field to force desired structure.
char __ss_pad2[_SS_PAD2SIZE]; // 112 byte pad to achieve desired size;
// _SS_MAXSIZE value minus size of
// ss_family, __ss_pad1, and
// __ss_align fields is 112.
};
*/
/*!
\brief Addresses of a network adapter.
This structure is used by the PacketGetNetInfoEx() function to return the IP addresses associated with
an adapter.
*/
typedef struct npf_if_addr {
struct sockaddr_storage IPAddress; ///< IP address.
struct sockaddr_storage SubnetMask; ///< Netmask for that address.
struct sockaddr_storage Broadcast; ///< Broadcast address.
}npf_if_addr;
#define ADAPTER_NAME_LENGTH 256 + 12 ///< Maximum length for the name of an adapter. The value is the same used by the IP Helper API.
#define ADAPTER_DESC_LENGTH 128 ///< Maximum length for the description of an adapter. The value is the same used by the IP Helper API.
#define MAX_MAC_ADDR_LENGTH 8 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
#define MAX_NETWORK_ADDRESSES 16 ///< Maximum length for the link layer address of an adapter. The value is the same used by the IP Helper API.
typedef struct WAN_ADAPTER_INT WAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
typedef WAN_ADAPTER *PWAN_ADAPTER; ///< Describes an opened wan (dialup, VPN...) network adapter using the NetMon API
#define INFO_FLAG_NDIS_ADAPTER 0 ///< Flag for ADAPTER_INFO: this is a traditional ndis adapter
#define INFO_FLAG_NDISWAN_ADAPTER 1 ///< Flag for ADAPTER_INFO: this is a NdisWan adapter
#define INFO_FLAG_DAG_CARD 2 ///< Flag for ADAPTER_INFO: this is a DAG card
#define INFO_FLAG_DAG_FILE 6 ///< Flag for ADAPTER_INFO: this is a DAG file
#define INFO_FLAG_DONT_EXPORT 8 ///< Flag for ADAPTER_INFO: when this flag is set, the adapter will not be listed or openend by winpcap. This allows to prevent exporting broken network adapters, like for example FireWire ones.
/*!
\brief Contains comprehensive information about a network adapter.
This structure is filled with all the accessory information that the user can need about an adapter installed
on his system.
*/
typedef struct _ADAPTER_INFO
{
struct _ADAPTER_INFO *Next; ///< Pointer to the next adapter in the list.
CHAR Name[ADAPTER_NAME_LENGTH + 1]; ///< Name of the device representing the adapter.
CHAR Description[ADAPTER_DESC_LENGTH + 1]; ///< Human understandable description of the adapter
UINT MacAddressLen; ///< Length of the link layer address.
UCHAR MacAddress[MAX_MAC_ADDR_LENGTH]; ///< Link layer address.
NetType LinkLayer; ///< Physical characteristics of this adapter. This NetType structure contains the link type and the speed of the adapter.
INT NNetworkAddresses; ///< Number of network layer addresses of this adapter.
npf_if_addr *NetworkAddresses; ///< Pointer to an array of npf_if_addr, each of which specifies a network address of this adapter.
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
}
ADAPTER_INFO, *PADAPTER_INFO;
/*!
\brief Describes an opened network adapter.
This structure is the most important for the functioning of packet.dll, but the great part of its fields
should be ignored by the user, since the library offers functions that avoid to cope with low-level parameters
*/
typedef struct _ADAPTER {
HANDLE hFile; ///< \internal Handle to an open instance of the NPF driver.
CHAR SymbolicLink[MAX_LINK_NAME_LENGTH]; ///< \internal A string containing the name of the network adapter currently opened.
int NumWrites; ///< \internal Number of times a packets written on this adapter will be repeated
///< on the wire.
HANDLE ReadEvent; ///< A notification event associated with the read calls on the adapter.
///< It can be passed to standard Win32 functions (like WaitForSingleObject
///< or WaitForMultipleObjects) to wait until the driver's buffer contains some
///< data. It is particularly useful in GUI applications that need to wait
///< concurrently on several events. In Windows NT/2000 the PacketSetMinToCopy()
///< function can be used to define the minimum amount of data in the kernel buffer
///< that will cause the event to be signalled.
UINT ReadTimeOut; ///< \internal The amount of time after which a read on the driver will be released and
///< ReadEvent will be signaled, also if no packets were captured
CHAR Name[ADAPTER_NAME_LENGTH];
PWAN_ADAPTER pWanAdapter;
UINT Flags; ///< Adapter's flags. Tell if this adapter must be treated in a different way, using the Netmon API or the dagc API.
#ifdef HAVE_DAG_API
dagc_t *pDagCard; ///< Pointer to the dagc API adapter descriptor for this adapter
PCHAR DagBuffer; ///< Pointer to the buffer with the packets that is received from the DAG card
struct timeval DagReadTimeout; ///< Read timeout. The dagc API requires a timeval structure
unsigned DagFcsLen; ///< Length of the frame check sequence attached to any packet by the card. Obtained from the registry
DWORD DagFastProcess; ///< True if the user requests fast capture processing on this card. Higher level applications can use this value to provide a faster but possibly unprecise capture (for example, libpcap doesn't convert the timestamps).
#endif // HAVE_DAG_API
} ADAPTER, *LPADAPTER;
/*!
\brief Structure that contains a group of packets coming from the driver.
This structure defines the header associated with every packet delivered to the application.
*/
typedef struct _PACKET {
HANDLE hEvent; ///< \deprecated Still present for compatibility with old applications.
OVERLAPPED OverLapped; ///< \deprecated Still present for compatibility with old applications.
PVOID Buffer; ///< Buffer with containing the packets. See the PacketReceivePacket() for
///< details about the organization of the data in this buffer
UINT Length; ///< Length of the buffer
DWORD ulBytesReceived; ///< Number of valid bytes present in the buffer, i.e. amount of data
///< received by the last call to PacketReceivePacket()
BOOLEAN bIoComplete; ///< \deprecated Still present for compatibility with old applications.
} PACKET, *LPPACKET;
/*!
\brief Structure containing an OID request.
It is used by the PacketRequest() function to send an OID to the interface card driver.
It can be used, for example, to retrieve the status of the error counters on the adapter, its MAC address,
the list of the multicast groups defined on it, and so on.
*/
struct _PACKET_OID_DATA {
ULONG Oid; ///< OID code. See the Microsoft DDK documentation or the file ntddndis.h
///< for a complete list of valid codes.
ULONG Length; ///< Length of the data field
UCHAR Data[1]; ///< variable-lenght field that contains the information passed to or received
///< from the adapter.
};
typedef struct _PACKET_OID_DATA PACKET_OID_DATA, *PPACKET_OID_DATA;
#if _DBG
#define ODS(_x) OutputDebugString(TEXT(_x))
#define ODSEx(_x, _y)
#else
#ifdef _DEBUG_TO_FILE
/*!
\brief Macro to print a debug string. The behavior differs depending on the debug level
*/
#define ODS(_x) { \
FILE *f; \
f = fopen("winpcap_debug.txt", "a"); \
fprintf(f, "%s", _x); \
fclose(f); \
}
/*!
\brief Macro to print debug data with the printf convention. The behavior differs depending on
the debug level
*/
#define ODSEx(_x, _y) { \
FILE *f; \
f = fopen("winpcap_debug.txt", "a"); \
fprintf(f, _x, _y); \
fclose(f); \
}
LONG PacketDumpRegistryKey(PCHAR KeyName, PCHAR FileName);
#else
#define ODS(_x)
#define ODSEx(_x, _y)
#endif
#endif
/* We load dinamically the dag library in order link it only when it's present on the system */
#ifdef HAVE_DAG_API
typedef dagc_t* (*dagc_open_handler)(const char *source, unsigned flags, char *ebuf); ///< prototype used to dynamically load the dag dll
typedef void (*dagc_close_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_getlinktype_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_getlinkspeed_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_setsnaplen_handler)(dagc_t *dagcfd, unsigned snaplen); ///< prototype used to dynamically load the dag dll
typedef unsigned (*dagc_getfcslen_handler)(dagc_t *dagcfd); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_receive_handler)(dagc_t *dagcfd, u_char **buffer, u_int *bufsize); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_stats_handler)(dagc_t *dagcfd, dagc_stats_t *ps); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_wait_handler)(dagc_t *dagcfd, struct timeval *timeout); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_finddevs_handler)(dagc_if_t **alldevsp, char *ebuf); ///< prototype used to dynamically load the dag dll
typedef int (*dagc_freedevs_handler)(dagc_if_t *alldevsp); ///< prototype used to dynamically load the dag dll
#endif // HAVE_DAG_API
#ifdef __cplusplus
extern "C" {
#endif
/**
* @}
*/
// The following is used to check the adapter name in PacketOpenAdapterNPF and prevent
// opening of firewire adapters
#define FIREWIRE_SUBSTR L"1394"
void PacketPopulateAdaptersInfoList();
PWCHAR SChar2WChar(PCHAR string);
PCHAR WChar2SChar(PWCHAR string);
BOOL PacketGetFileVersion(LPTSTR FileName, PCHAR VersionBuff, UINT VersionBuffLen);
PADAPTER_INFO PacketFindAdInfo(PCHAR AdapterName);
BOOLEAN PacketUpdateAdInfo(PCHAR AdapterName);
BOOLEAN IsFireWire(TCHAR *AdapterDesc);
//---------------------------------------------------------------------------
// EXPORTED FUNCTIONS
//---------------------------------------------------------------------------
PCHAR PacketGetVersion();
PCHAR PacketGetDriverVersion();
BOOLEAN PacketSetMinToCopy(LPADAPTER AdapterObject,int nbytes);
BOOLEAN PacketSetNumWrites(LPADAPTER AdapterObject,int nwrites);
BOOLEAN PacketSetMode(LPADAPTER AdapterObject,int mode);
BOOLEAN PacketSetReadTimeout(LPADAPTER AdapterObject,int timeout);
BOOLEAN PacketSetBpf(LPADAPTER AdapterObject,struct bpf_program *fp);
INT PacketSetSnapLen(LPADAPTER AdapterObject,int snaplen);
BOOLEAN PacketGetStats(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketGetStatsEx(LPADAPTER AdapterObject,struct bpf_stat *s);
BOOLEAN PacketSetBuff(LPADAPTER AdapterObject,int dim);
BOOLEAN PacketGetNetType (LPADAPTER AdapterObject,NetType *type);
LPADAPTER PacketOpenAdapter(PCHAR AdapterName);
BOOLEAN PacketSendPacket(LPADAPTER AdapterObject,LPPACKET pPacket,BOOLEAN Sync);
INT PacketSendPackets(LPADAPTER AdapterObject,PVOID PacketBuff,ULONG Size, BOOLEAN Sync);
LPPACKET PacketAllocatePacket(void);
VOID PacketInitPacket(LPPACKET lpPacket,PVOID Buffer,UINT Length);
VOID PacketFreePacket(LPPACKET lpPacket);
BOOLEAN PacketReceivePacket(LPADAPTER AdapterObject,LPPACKET lpPacket,BOOLEAN Sync);
BOOLEAN PacketSetHwFilter(LPADAPTER AdapterObject,ULONG Filter);
BOOLEAN PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
BOOLEAN PacketGetNetInfoEx(PCHAR AdapterName, npf_if_addr* buffer, PLONG NEntries);
BOOLEAN PacketRequest(LPADAPTER AdapterObject,BOOLEAN Set,PPACKET_OID_DATA OidData);
HANDLE PacketGetReadEvent(LPADAPTER AdapterObject);
BOOLEAN PacketSetDumpName(LPADAPTER AdapterObject, void *name, int len);
BOOLEAN PacketSetDumpLimits(LPADAPTER AdapterObject, UINT maxfilesize, UINT maxnpacks);
BOOLEAN PacketIsDumpEnded(LPADAPTER AdapterObject, BOOLEAN sync);
BOOL PacketStopDriver();
VOID PacketCloseAdapter(LPADAPTER lpAdapter);
#ifdef __cplusplus
}
#endif
#endif //__PACKET32

View File

@ -0,0 +1,161 @@
#pragma once
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
#pragma pack(push,1)
typedef struct _ip_address
{
u_char bytes[4];
} ip_address;
typedef struct _mac_address
{
u_char bytes[6];
} mac_address;
typedef struct _ethernet_header
{
mac_address dst;
mac_address src;
u_short protocol;
} ethernet_header;
typedef struct _arp_packet
{
u_short hw_type;
u_short protocol;
u_char h_addr_len;
u_char p_addr_len;
u_short operation;
mac_address h_src;
ip_address p_src;
mac_address h_dst;
ip_address p_dst;
} arp_packet;
typedef struct _ip_header {
u_char ver_hlen; /* version << 4 | header length >> 2 */
u_char type; /* type of service */
u_short len; /* total length */
u_short id; /* identification */
u_short offset; /* fragment offset field */
u_char ttl; /* time to live */
u_char proto; /* protocol */
u_short hdr_csum; /* checksum */
ip_address src; /* source and dest address */
ip_address dst;
} ip_header;
/* Internet Control Message Protocol Constants and Packet Format */
/* ic_type field */
#define ICT_ECHORP 0 /* Echo reply */
#define ICT_DESTUR 3 /* Destination unreachable */
#define ICT_SRCQ 4 /* Source quench */
#define ICT_REDIRECT 5 /* Redirect message type */
#define ICT_ECHORQ 8 /* Echo request */
#define ICT_TIMEX 11 /* Time exceeded */
#define ICT_PARAMP 12 /* Parameter Problem */
#define ICT_TIMERQ 13 /* Timestamp request */
#define ICT_TIMERP 14 /* Timestamp reply */
#define ICT_INFORQ 15 /* Information request */
#define ICT_INFORP 16 /* Information reply */
#define ICT_MASKRQ 17 /* Mask request */
#define ICT_MASKRP 18 /* Mask reply */
/* ic_code field */
#define ICC_NETUR 0 /* dest unreachable, net unreachable */
#define ICC_HOSTUR 1 /* dest unreachable, host unreachable */
#define ICC_PROTOUR 2 /* dest unreachable, proto unreachable */
#define ICC_PORTUR 3 /* dest unreachable, port unreachable */
#define ICC_FNADF 4 /* dest unr, frag needed & don't frag */
#define ICC_SRCRT 5 /* dest unreachable, src route failed */
#define ICC_NETRD 0 /* redirect: net */
#define ICC_HOSTRD 1 /* redirect: host */
#define IC_TOSNRD 2 /* redirect: type of service, net */
#define IC_TOSHRD 3 /* redirect: type of service, host */
#define ICC_TIMEX 0 /* time exceeded, ttl */
#define ICC_FTIMEX 1 /* time exceeded, frag */
#define IC_HLEN 8 /* octets */
#define IC_PADLEN 3 /* pad length (octets) */
#define IC_RDTTL 300 /* ttl for redirect routes */
/* ICMP packet format (following the IP header) */
typedef struct _icmp_header { /* ICMP packet */
char type; /* type of message (ICT_* above)*/
char code; /* code (ICC_* above) */
short csum; /* checksum of ICMP header+data */
union {
struct {
int ic1_id:16; /* echo type, a message id */
int ic1_seq:16;/* echo type, a seq. number */
} ic1;
ip_address ic2_gw; /* for redirect, gateway */
struct {
char ic3_ptr;/* pointer, for ICT_PARAMP */
char ic3_pad[IC_PADLEN];
} ic3;
int ic4_mbz; /* must be zero */
} icu;
} icmp_header;
/*typedef struct _udp_header {
u16 src_port;
u16 dst_port;
u16 len;
u16 csum;
} udp_header;*/
typedef struct _full_arp_packet
{
ethernet_header header;
arp_packet arp;
} full_arp_packet;
#pragma pack(pop)
#define ARP_REQUEST 0x0100 //values are big-endian
extern mac_address virtual_mac;
extern mac_address broadcast_mac;
extern ip_address virtual_ip;
#define mac_compare(a,b) (memcmp(&(a),&(b),6))
#define ip_compare(a,b) (memcmp(&(a),&(b),4))
/*
int pcap_io_init(char *adapter);
int pcap_io_send(void* packet, int plen);
int pcap_io_recv(void* packet, int max_len);
void pcap_io_close();
*/
int pcap_io_get_dev_num();
char* pcap_io_get_dev_desc(int num,int md);
char* pcap_io_get_dev_name(int num,int md);
#ifdef __cplusplus
}
#endif
class PCAPAdapter : public NetAdapter
{
public:
PCAPAdapter();
virtual bool blocks();
//gets a packet.rv :true success
virtual bool recv(NetPacket* pkt);
//sends the packet and deletes it when done (if successful).rv :true success
virtual bool send(NetPacket* pkt);
virtual ~PCAPAdapter();
};

View File

@ -0,0 +1,50 @@
::@echo off
::
:: Usage: postBuild.cmd SourcePath DestFile DestExt {plugins}
::
:: SourcePath - $(TargetPath) - Fully qualified path of the generated target file.
:: DestFile - Base filename of the target/dest, without extension!
:: DestExt - Extension of the target/dest!
:: plugins - optional parameter used to generate plugins into the /plugins folder
::
:: The destination file is determined by the PCSX2_TARGET_DIR environment var.
SETLOCAL ENABLEEXTENSIONS
if defined PCSX2_TARGET_COPY CALL :TestAndCopy "%PCSX2_TARGET_COPY%" %1 %2 %3 %4
ENDLOCAL
exit 0
:TestAndCopy
:: Subroutine. First parameter is our Target Dir. Since it's a parameter into
:: the subroutine, we can use tilda expansion to handle quotes correctly. :)
if NOT EXIST "%~1" (
md "%~1"
)
:: Error checking. Try to change to the dir. If it fails, it means the dir is
:: actually a file, and we should cancel the script.
set mycwd="%CD%"
cd "%~1"
if %ERRORLEVEL% NEQ 0 goto :eof
cd %mycwd%
set pcsxoutdir=%~1\%~5
set pcsxoutname=%pcsxoutdir%\%~3%4
set pcsxnewname=%pcsxoutdir%\%~3-r0%4
IF NOT EXIST "%pcsxoutdir%" (
md "%pcsxoutdir%"
)
copy /Y "%~2" "%pcsxoutname%"
copy /Y "%~2" "%pcsxnewname%"
if %ERRORLEVEL% EQU 0 (
echo Target copied to %pcsxnewname%
)
goto :eof
:quit

View File

@ -0,0 +1,25 @@
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by DEV9linuz.rc
//
#define IDD_CONFDLG 101
#define IDD_CONFIG 101
#define IDD_ABOUT 103
#define IDC_NAME 1000
#define IDC_COMBO1 1007
#define IDC_ETHDEV 1007
#define IDC_BAYTYPE 1008
#define IDC_ETHENABLED 1009
#define IDC_HDDFILE 1010
#define IDC_HDDENABLED 1011
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1011
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -0,0 +1,874 @@
#define WINVER 0x0600
#define _WIN32_WINNT 0x0600
#include <winsock2.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <Winioctl.h>
#include <fcntl.h>
#include <windows.h>
#include <stdarg.h>
#include "smap.h"
#include "net.h"
#include "pcap.h"
#include "pcap_io.h"
#include "tap.h"
bool has_link=true;
/*
#define SMAP_BASE 0xb0000000
#define SMAP_REG8(Offset) (*(u8 volatile*)(SMAP_BASE+(Offset)))
#define SMAP_REG16(Offset) (*(u16 volatile*)(SMAP_BASE+(Offset)))
#define SMAP_REG32(Offset) (*(u32 volatile*)(SMAP_BASE+(Offset)))
u32 EMAC3REG_READ(u32 u32Offset)
{
u32 hi=SMAP_REG16(u32Offset);
u32 lo=SMAP_REG16(u32Offset+2);
return (hi<<16)|lo;
}
void EMAC3REG_WRITE(u32 u32Offset,u32 u32V)
{
SMAP_REG16(u32Offset)=((u32V>>16)&0xFFFF);
SMAP_REG16(u32Offset+2)=(u32V&0xFFFF);
}
#define SMAP_EMAC3_BASE 0x2000
#define SMAP_EMAC3_STA_CTRL (SMAP_EMAC3_BASE+0x5C)
void test()
{
printf ("EMAC3R 0x%08X raw read 0x%08X\n",EMAC3REG_READ(SMAP_EMAC3_STA_CTRL),SMAP_REG32(SMAP_EMAC3_STA_CTRL));
}*/
//this can return a false positive, but its not problem since it may say it cant recv while it can (no harm done, just delay on packets)
bool rx_fifo_can_rx()
{
//check if RX is on & stuff like that here
//Check if there is space on RXBD
if (dev9Ru8(SMAP_R_RXFIFO_FRAME_CNT)==64)
return false;
//Check if there is space on fifo
int rd_ptr = dev9Ru32(SMAP_R_RXFIFO_RD_PTR);
int space = sizeof(dev9.rxfifo) -
((dev9.rxfifo_wr_ptr-rd_ptr)&16383);
if(space==0)
space = sizeof(dev9.rxfifo);
if (space<1514)
return false;
//we can recv a packet !
return true;
}
void rx_process(NetPacket* pk)
{
if (!rx_fifo_can_rx())
{
emu_printf("ERROR : !rx_fifo_can_rx at rx_process\n");
return;
}
smap_bd_t *pbd= ((smap_bd_t *)&dev9.dev9R[SMAP_BD_RX_BASE & 0xffff])+dev9.rxbdi;
int bytes=(pk->size+3)&(~3);
if (!(pbd->ctrl_stat & SMAP_BD_RX_EMPTY))
{
emu_printf("ERROR : Discarding %d bytes (RX%d not ready)\n", bytes, dev9.rxbdi);
return;
}
int pstart=(dev9.rxfifo_wr_ptr)&16383;
int i=0;
while(i<bytes)
{
dev9_rxfifo_write(pk->buffer[i++]);
dev9.rxfifo_wr_ptr&=16383;
}
//increase RXBD
dev9.rxbdi++;
dev9.rxbdi&=(SMAP_BD_SIZE/8)-1;
//Fill the BD with info !
pbd->length = pk->size;
pbd->pointer = 0x4000 + pstart;
pbd->ctrl_stat&= ~SMAP_BD_RX_EMPTY;
//increase frame count
u8* cntptr=&dev9Ru8(SMAP_R_RXFIFO_FRAME_CNT);
#ifdef WIN_X64
*cntptr++; //no asm inline in x64
#else
__asm
{
//this is silly
mov eax,[cntptr];
lock inc byte ptr [eax]
}
#endif
//spams// emu_printf("Got packet, %d bytes (%d fifo)\n", pk->size,bytes);
_DEV9irq(SMAP_INTR_RXEND,0);//now ? or when the fifo is full ? i guess now atm
//note that this _is_ wrong since the IOP interrupt system is not thread safe.. but nothing i can do about that
}
bool tx_p_first=false;
u32 wswap(u32 d)
{
return (d>>16)|(d<<16);
}
void tx_process()
{
//we loop based on count ? or just *use* it ?
u32 cnt=dev9Ru8(SMAP_R_TXFIFO_FRAME_CNT);
//spams// printf("tx_process : %d cnt frames !\n",cnt);
// this hack worsens OPL performance. Is it really needed? OPL works fine without. (rama)
if (!tx_p_first)
{
dev9Ru8(SMAP_R_TXFIFO_FRAME_CNT)=0;
tx_p_first=true;
//THIS IS A HACK.without that the stack wont init, i guess its missing e3/emac emulation ..
emu_printf("WARN : First packet interrupt hack ..\n");
_DEV9irq(SMAP_INTR_RXEND|SMAP_INTR_TXEND|SMAP_INTR_TXDNV,100);
return;
}
NetPacket pk;
int fc=0;
for (fc=0;fc<cnt;fc++)
{
smap_bd_t *pbd= ((smap_bd_t *)&dev9.dev9R[SMAP_BD_TX_BASE & 0xffff])+dev9.txbdi;
if (! (pbd->ctrl_stat&SMAP_BD_TX_READY))
{
emu_printf("ERROR : !pbd->ctrl_stat&SMAP_BD_TX_READY\n");
break;
}
if (pbd->length&3)
{
//spams// emu_printf("WARN : pbd->length not alligned %d\n",pbd->length);
}
if(pbd->length>1514)
{
emu_printf("ERROR : Trying to send packet too big.\n");
}
else
{
u32 base=(pbd->pointer-0x1000)&16383;
DEV9_LOG("Sending Packet from base %x, size %d\n", base, pbd->length);
//spams// emu_printf("Sending Packet from base %x, size %d\n", base, pbd->length);
pk.size=pbd->length;
if (!(pbd->pointer>=0x1000))
{
emu_printf("ERROR: odd , !pbd->pointer>0x1000 | 0x%X %d\n", pbd->pointer, pbd->length);
}
//increase fifo pointer(s)
//uh does that even exist on real h/w ?
/*
if(dev9.txfifo_rd_ptr+pbd->length >= 16383)
{
//warp around !
//first part
u32 was=16384-dev9.txfifo_rd_ptr;
memcpy(pk.buffer,dev9.txfifo+dev9.txfifo_rd_ptr,was);
//warp
dev9.txfifo_rd_ptr+=pbd->length;
dev9.txfifo_rd_ptr&=16383;
if (pbd->length!=was+dev9.txfifo_rd_ptr)
{
emu_printf("ERROR ON TX FIFO HANDLING, %x\n", dev9.txfifo_rd_ptr);
}
//second part
memcpy(pk.buffer+was,dev9.txfifo,pbd->length-was);
}
else
{ //no warp or 'perfect' warp (reads end, resets to start
memcpy(pk.buffer,dev9.txfifo+dev9.txfifo_rd_ptr,pbd->length);
dev9.txfifo_rd_ptr+=pbd->length;
if (dev9.txfifo_rd_ptr==16384)
dev9.txfifo_rd_ptr=0;
}
if (dev9.txfifo_rd_ptr&(~16383))
{
emu_printf("ERROR ON TX FIFO HANDLING, %x\n", dev9.txfifo_rd_ptr);
}
*/
if(base+pbd->length > 16384)
{
u32 was=16384-base;
memcpy(pk.buffer,dev9.txfifo+base,was);
memcpy(pk.buffer,dev9.txfifo,pbd->length-was);
printf("Warped read, was=%d, sz=%d, sz-was=%d\n",was,pbd->length,pbd->length-was);
}
else
{
memcpy(pk.buffer,dev9.txfifo+base,pbd->length);
}
tx_put(&pk);
}
pbd->ctrl_stat&= ~SMAP_BD_TX_READY;
//increase TXBD
dev9.txbdi++;
dev9.txbdi&=(SMAP_BD_SIZE/8)-1;
//decrease frame count -- this is not thread safe
dev9Ru8(SMAP_R_TXFIFO_FRAME_CNT)--;
}
//spams// emu_printf("processed %d frames, %d count, cnt = %d\n",fc,dev9Ru8(SMAP_R_TXFIFO_FRAME_CNT),cnt);
//if some error/early exit signal TXDNV
if (fc!=cnt || cnt==0)
{
printf("WARN : (fc!=cnt || cnt==0) but packet send request was made oO..\n");
_DEV9irq(SMAP_INTR_TXDNV,0);
}
//if we actualy send something send TXEND
if(fc!=0)
_DEV9irq(SMAP_INTR_TXEND,100);//now ? or when the fifo is empty ? i guess now atm
}
void emac3_write(u32 addr)
{
u32 value=wswap(dev9Ru32(addr));
switch(addr)
{
case SMAP_R_EMAC3_MODE0_L:
DEV9_LOG("SMAP: SMAP_R_EMAC3_MODE0 write %x\n", value);
value = (value & (~SMAP_E3_SOFT_RESET)) | SMAP_E3_TXMAC_IDLE | SMAP_E3_RXMAC_IDLE;
dev9Ru16(SMAP_R_EMAC3_STA_CTRL_H)|= SMAP_E3_PHY_OP_COMP;
break;
case SMAP_R_EMAC3_TxMODE0_L:
DEV9_LOG("SMAP: SMAP_R_EMAC3_TxMODE0_L write %x\n", value);
//spams// emu_printf("SMAP: SMAP_R_EMAC3_TxMODE0_L write %x\n", value);
//Process TX here ?
if (!value&SMAP_E3_TX_GNP_0)
emu_printf("SMAP_R_EMAC3_TxMODE0_L: SMAP_E3_TX_GNP_0 not set\n");
tx_process();
value = value& ~SMAP_E3_TX_GNP_0;
if (value)
emu_printf("SMAP_R_EMAC3_TxMODE0_L: extra bits set !\n");
break;
case SMAP_R_EMAC3_TxMODE1_L:
emu_printf("SMAP_R_EMAC3_TxMODE1_L 32bit write %x\n", value);
break;
case SMAP_R_EMAC3_STA_CTRL_L:
DEV9_LOG("SMAP: SMAP_R_EMAC3_STA_CTRL write %x\n", value);
{
if (value & (SMAP_E3_PHY_READ))
{
value|= SMAP_E3_PHY_OP_COMP;
int reg = value & (SMAP_E3_PHY_REG_ADDR_MSK);
u16 val = dev9.phyregs[reg];
switch (reg)
{
case SMAP_DsPHYTER_BMSR:
if (has_link)
val|= SMAP_PHY_BMSR_LINK | SMAP_PHY_BMSR_ANCP;
break;
case SMAP_DsPHYTER_PHYSTS:
if (has_link)
val|= SMAP_PHY_STS_LINK |SMAP_PHY_STS_100M | SMAP_PHY_STS_FDX | SMAP_PHY_STS_ANCP;
break;
}
DEV9_LOG("phy_read %d: %x\n", reg, val);
value=(value&0xFFFF)|(val<<16);
}
if (value & (SMAP_E3_PHY_WRITE))
{
value|= SMAP_E3_PHY_OP_COMP;
int reg = value & (SMAP_E3_PHY_REG_ADDR_MSK);
u16 val = value>>16;
switch (reg)
{
case SMAP_DsPHYTER_BMCR:
val&= ~SMAP_PHY_BMCR_RST;
val|= 0x1;
break;
}
DEV9_LOG("phy_write %d: %x\n", reg, val);
dev9.phyregs[reg] = val;
}
}
break;
default:
DEV9_LOG("SMAP: emac3 write %x=%x\n",addr, value);
}
dev9Ru32(addr)=wswap(value);
}
u8 CALLBACK smap_read8(u32 addr)
{
switch(addr)
{
case SMAP_R_TXFIFO_FRAME_CNT:
printf("SMAP_R_TXFIFO_FRAME_CNT read 8\n");
break;
case SMAP_R_RXFIFO_FRAME_CNT:
printf("SMAP_R_RXFIFO_FRAME_CNT read 8\n");
break;
case SMAP_R_BD_MODE:
return dev9.bd_swap;
default:
DEV9_LOG("SMAP : Unknown 8 bit read @ %X,v=%X\n",addr,dev9Ru8(addr));
return dev9Ru8(addr);
}
DEV9_LOG("SMAP : error , 8 bit read @ %X,v=%X\n",addr,dev9Ru8(addr));
return dev9Ru8(addr);
}
u16 CALLBACK smap_read16(u32 addr)
{
if (addr >= SMAP_BD_TX_BASE && addr < (SMAP_BD_TX_BASE + SMAP_BD_SIZE))
{
int rv = dev9Ru16(addr);
if(dev9.bd_swap)
return (rv<<8)|(rv>>8);
return rv;
/*
switch (addr & 0x7)
{
case 0: // ctrl_stat
hard = dev9Ru16(addr);
//DEV9_LOG("TX_CTRL_STAT[%d]: read %x\n", (addr - SMAP_BD_TX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
case 2: // unknown
hard = dev9Ru16(addr);
//DEV9_LOG("TX_UNKNOWN[%d]: read %x\n", (addr - SMAP_BD_TX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
case 4: // length
hard = dev9Ru16(addr);
DEV9_LOG("TX_LENGTH[%d]: read %x\n", (addr - SMAP_BD_TX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
case 6: // pointer
hard = dev9Ru16(addr);
DEV9_LOG("TX_POINTER[%d]: read %x\n", (addr - SMAP_BD_TX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
}
*/
}
else if (addr >= SMAP_BD_RX_BASE && addr < (SMAP_BD_RX_BASE + SMAP_BD_SIZE))
{
int rv = dev9Ru16(addr);
if(dev9.bd_swap)
return (rv<<8)|(rv>>8);
return rv;
/*
switch (addr & 0x7)
{
case 0: // ctrl_stat
hard = dev9Ru16(addr);
//DEV9_LOG("RX_CTRL_STAT[%d]: read %x\n", (addr - SMAP_BD_RX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
case 2: // unknown
hard = dev9Ru16(addr);
//DEV9_LOG("RX_UNKNOWN[%d]: read %x\n", (addr - SMAP_BD_RX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
case 4: // length
hard = dev9Ru16(addr);
DEV9_LOG("RX_LENGTH[%d]: read %x\n", (addr - SMAP_BD_RX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
case 6: // pointer
hard = dev9Ru16(addr);
DEV9_LOG("RX_POINTER[%d]: read %x\n", (addr - SMAP_BD_RX_BASE) / 8, hard);
if(dev9.bd_swap)
return (hard<<8)|(hard>>8);
return hard;
}
*/
}
switch(addr)
{
#ifdef DEV9_LOG_ENABLE
case SMAP_R_TXFIFO_FRAME_CNT:
printf("SMAP_R_TXFIFO_FRAME_CNT read 16\n");
return dev9Ru16(addr);
case SMAP_R_RXFIFO_FRAME_CNT:
printf("SMAP_R_RXFIFO_FRAME_CNT read 16\n");
return dev9Ru16(addr);
case SMAP_R_EMAC3_MODE0_L:
DEV9_LOG("SMAP_R_EMAC3_MODE0_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_MODE0_H:
DEV9_LOG("SMAP_R_EMAC3_MODE0_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_MODE1_L:
DEV9_LOG("SMAP_R_EMAC3_MODE1_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_MODE1_H:
DEV9_LOG("SMAP_R_EMAC3_MODE1_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_RxMODE_L:
DEV9_LOG("SMAP_R_EMAC3_RxMODE_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_RxMODE_H:
DEV9_LOG("SMAP_R_EMAC3_RxMODE_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_INTR_STAT_L:
DEV9_LOG("SMAP_R_EMAC3_INTR_STAT_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_INTR_STAT_H:
DEV9_LOG("SMAP_R_EMAC3_INTR_STAT_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_INTR_ENABLE_L:
DEV9_LOG("SMAP_R_EMAC3_INTR_ENABLE_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_INTR_ENABLE_H:
DEV9_LOG("SMAP_R_EMAC3_INTR_ENABLE_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_TxMODE0_L:
DEV9_LOG("SMAP_R_EMAC3_TxMODE0_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_TxMODE0_H:
DEV9_LOG("SMAP_R_EMAC3_TxMODE0_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_TxMODE1_L:
DEV9_LOG("SMAP_R_EMAC3_TxMODE1_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_TxMODE1_H:
DEV9_LOG("SMAP_R_EMAC3_TxMODE1_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_STA_CTRL_L:
DEV9_LOG("SMAP_R_EMAC3_STA_CTRL_L 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
case SMAP_R_EMAC3_STA_CTRL_H:
DEV9_LOG("SMAP_R_EMAC3_STA_CTRL_H 16bit read %x\n", dev9Ru16(addr));
return dev9Ru16(addr);
#endif
default:
DEV9_LOG("SMAP : Unknown 16 bit read @ %X,v=%X\n",addr,dev9Ru16(addr));
return dev9Ru16(addr);
}
DEV9_LOG("SMAP : error , 16 bit read @ %X,v=%X\n",addr,dev9Ru16(addr));
return dev9Ru16(addr);
}
u32 CALLBACK smap_read32(u32 addr)
{
if (addr>=SMAP_EMAC3_REGBASE && addr<SMAP_EMAC3_REGEND)
{
u32 hi=smap_read16(addr);
u32 lo=smap_read16(addr+2)<<16;
return hi|lo;
}
switch(addr)
{
case SMAP_R_TXFIFO_FRAME_CNT:
printf("SMAP_R_TXFIFO_FRAME_CNT read 32\n");
return dev9Ru32(addr);
case SMAP_R_RXFIFO_FRAME_CNT:
printf("SMAP_R_RXFIFO_FRAME_CNT read 32\n");
return dev9Ru32(addr);
case SMAP_R_EMAC3_STA_CTRL_L:
DEV9_LOG("SMAP_R_EMAC3_STA_CTRL_L 32bit read value %x\n", dev9Ru32(addr));
return dev9Ru32(addr);
case SMAP_R_RXFIFO_DATA:
{
int rd_ptr = dev9Ru32(SMAP_R_RXFIFO_RD_PTR)&16383;
int rv = *((u32*)(dev9.rxfifo + rd_ptr));
dev9Ru32(SMAP_R_RXFIFO_RD_PTR) = ((rd_ptr+4)&16383);
if(dev9.bd_swap)
rv=(rv<<24)|(rv>>24)|((rv>>8)&0xFF00)|((rv<<8)&0xFF0000);
DEV9_LOG("SMAP_R_RXFIFO_DATA 32bit read %x\n", rv);
return rv;
}
default:
DEV9_LOG("SMAP : Unknown 32 bit read @ %X,v=%X\n",addr,dev9Ru32(addr));
return dev9Ru32(addr);
}
DEV9_LOG("SMAP : error , 32 bit read @ %X,v=%X\n",addr,dev9Ru32(addr));
return dev9Ru32(addr);
}
void CALLBACK smap_write8(u32 addr, u8 value)
{
switch(addr)
{
case SMAP_R_TXFIFO_FRAME_INC:
DEV9_LOG("SMAP_R_TXFIFO_FRAME_INC 8bit write %x\n", value);
{
dev9Ru8(SMAP_R_TXFIFO_FRAME_CNT)++;
}
return;
case SMAP_R_RXFIFO_FRAME_DEC:
DEV9_LOG("SMAP_R_RXFIFO_FRAME_DEC 8bit write %x\n", value);
dev9Ru8(addr) = value;
{
u8* cntptr=&dev9Ru8(SMAP_R_RXFIFO_FRAME_CNT);
#ifdef WIN_X64
*cntptr--; //no asm inline in x64
#else
__asm
{
//this is silly
mov eax,[cntptr];
lock dec byte ptr [eax]
}
#endif
}
return;
case SMAP_R_TXFIFO_CTRL:
DEV9_LOG("SMAP_R_TXFIFO_CTRL 8bit write %x\n", value);
if(value&SMAP_TXFIFO_RESET)
{
dev9.txbdi=0;
dev9.txfifo_rd_ptr=0;
dev9Ru8(SMAP_R_TXFIFO_FRAME_CNT)=0; //this actualy needs to be atomic (lock mov ...)
dev9Ru32(SMAP_R_TXFIFO_WR_PTR)=0;
dev9Ru32(SMAP_R_TXFIFO_SIZE)=16384;
}
value&= ~SMAP_TXFIFO_RESET;
dev9Ru8(addr) = value;
return;
case SMAP_R_RXFIFO_CTRL:
DEV9_LOG("SMAP_R_RXFIFO_CTRL 8bit write %x\n", value);
if(value&SMAP_RXFIFO_RESET)
{
dev9.rxbdi=0;
dev9.rxfifo_wr_ptr=0;
dev9Ru8(SMAP_R_RXFIFO_FRAME_CNT)=0;
dev9Ru32(SMAP_R_RXFIFO_RD_PTR)=0;
dev9Ru32(SMAP_R_RXFIFO_SIZE)=16384;
}
value&= ~SMAP_RXFIFO_RESET;
dev9Ru8(addr) = value;
return;
case SMAP_R_BD_MODE:
if(value&SMAP_BD_SWAP)
{
DEV9_LOG("SMAP_R_BD_MODE: byteswapped.\n");
emu_printf("BD Byteswapping enabled.\n");
dev9.bd_swap=1;
}
else
{
DEV9_LOG("SMAP_R_BD_MODE: NOT byteswapped.\n");
emu_printf("BD Byteswapping disabled.\n");
dev9.bd_swap=0;
}
return;
default :
DEV9_LOG("SMAP : Unknown 8 bit write @ %X,v=%X\n",addr,value);
dev9Ru8(addr) = value;
return;
}
DEV9_LOG("SMAP : error , 8 bit write @ %X,v=%X\n",addr,value);
dev9Ru8(addr) = value;
}
void CALLBACK smap_write16(u32 addr, u16 value)
{
if (addr >= SMAP_BD_TX_BASE && addr < (SMAP_BD_TX_BASE + SMAP_BD_SIZE)) {
if(dev9.bd_swap)
value = (value>>8)|(value<<8);
dev9Ru16(addr) = value;
/*
switch (addr & 0x7)
{
case 0: // ctrl_stat
DEV9_LOG("TX_CTRL_STAT[%d]: write %x\n", (addr - SMAP_BD_TX_BASE) / 8, value);
//hacky
dev9Ru16(addr) = value;
return;
case 2: // unknown
//DEV9_LOG("TX_UNKNOWN[%d]: write %x\n", (addr - SMAP_BD_TX_BASE) / 8, value);
dev9Ru16(addr) = value;
return;
case 4: // length
DEV9_LOG("TX_LENGTH[%d]: write %x\n", (addr - SMAP_BD_TX_BASE) / 8, value);
dev9Ru16(addr) = value;
return;
case 6: // pointer
DEV9_LOG("TX_POINTER[%d]: write %x\n", (addr - SMAP_BD_TX_BASE) / 8, value);
dev9Ru16(addr) = value;
return;
}
*/
return;
}
else if (addr >= SMAP_BD_RX_BASE && addr < (SMAP_BD_RX_BASE + SMAP_BD_SIZE))
{
int rx_index=(addr - SMAP_BD_RX_BASE)>>3;
if(dev9.bd_swap)
value = (value>>8)|(value<<8);
dev9Ru16(addr) = value;
/*
switch (addr & 0x7)
{
case 0: // ctrl_stat
DEV9_LOG("RX_CTRL_STAT[%d]: write %x\n", rx_index, value);
dev9Ru16(addr) = value;
if(value&0x8000)
{
DEV9_LOG(" * * PACKET READ COMPLETE: rd_ptr=%d, wr_ptr=%d\n", dev9Ru32(SMAP_R_RXFIFO_RD_PTR), dev9.rxfifo_wr_ptr);
}
return;
case 2: // unknown
//DEV9_LOG("RX_UNKNOWN[%d]: write %x\n", rx_index, value);
dev9Ru16(addr) = value;
return;
case 4: // length
DEV9_LOG("RX_LENGTH[%d]: write %x\n", rx_index, value);
dev9Ru16(addr) = value;
return;
case 6: // pointer
DEV9_LOG("RX_POINTER[%d]: write %x\n", rx_index, value);
dev9Ru16(addr) = value;
return;
}
*/
return;
}
switch(addr)
{
case SMAP_R_INTR_CLR:
DEV9_LOG("SMAP: SMAP_R_INTR_CLR 16bit write %x\n", value);
dev9.irqcause&= ~value;
return;
case SMAP_R_TXFIFO_WR_PTR:
DEV9_LOG("SMAP: SMAP_R_TXFIFO_WR_PTR 16bit write %x\n", value);
dev9Ru16(addr) = value;
return;
#define EMAC3_L_WRITE(name) \
case name: \
DEV9_LOG("SMAP: " #name " 16 bit write %x\n", value); \
dev9Ru16(addr) = value; \
return;
//handle L writes
EMAC3_L_WRITE(SMAP_R_EMAC3_MODE0_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_MODE1_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_TxMODE0_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_TxMODE1_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_RxMODE_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_INTR_STAT_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_INTR_ENABLE_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_ADDR_HI_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_ADDR_LO_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_VLAN_TPID )
EMAC3_L_WRITE( SMAP_R_EMAC3_PAUSE_TIMER_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_INDIVID_HASH1 )
EMAC3_L_WRITE( SMAP_R_EMAC3_INDIVID_HASH2 )
EMAC3_L_WRITE( SMAP_R_EMAC3_INDIVID_HASH3 )
EMAC3_L_WRITE( SMAP_R_EMAC3_INDIVID_HASH4 )
EMAC3_L_WRITE( SMAP_R_EMAC3_GROUP_HASH1 )
EMAC3_L_WRITE( SMAP_R_EMAC3_GROUP_HASH2 )
EMAC3_L_WRITE( SMAP_R_EMAC3_GROUP_HASH3 )
EMAC3_L_WRITE( SMAP_R_EMAC3_GROUP_HASH4 )
EMAC3_L_WRITE( SMAP_R_EMAC3_LAST_SA_HI )
EMAC3_L_WRITE( SMAP_R_EMAC3_LAST_SA_LO )
EMAC3_L_WRITE( SMAP_R_EMAC3_INTER_FRAME_GAP_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_STA_CTRL_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_TX_THRESHOLD_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_RX_WATERMARK_L )
EMAC3_L_WRITE( SMAP_R_EMAC3_TX_OCTETS )
EMAC3_L_WRITE( SMAP_R_EMAC3_RX_OCTETS )
#define EMAC3_H_WRITE(name) \
case name: \
DEV9_LOG("SMAP: " #name " 16 bit write %x\n", value); \
dev9Ru16(addr) = value; \
emac3_write(addr-2); \
return;
//handle H writes
EMAC3_H_WRITE(SMAP_R_EMAC3_MODE0_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_MODE1_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_TxMODE0_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_TxMODE1_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_RxMODE_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_INTR_STAT_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_INTR_ENABLE_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_ADDR_HI_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_ADDR_LO_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_VLAN_TPID+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_PAUSE_TIMER_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_INDIVID_HASH1+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_INDIVID_HASH2+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_INDIVID_HASH3+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_INDIVID_HASH4+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_GROUP_HASH1+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_GROUP_HASH2+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_GROUP_HASH3+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_GROUP_HASH4+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_LAST_SA_HI+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_LAST_SA_LO+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_INTER_FRAME_GAP_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_STA_CTRL_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_TX_THRESHOLD_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_RX_WATERMARK_H )
EMAC3_H_WRITE( SMAP_R_EMAC3_TX_OCTETS+2 )
EMAC3_H_WRITE( SMAP_R_EMAC3_RX_OCTETS+2 )
/*
case SMAP_R_EMAC3_MODE0_L:
DEV9_LOG("SMAP: SMAP_R_EMAC3_MODE0 write %x\n", value);
dev9Ru16(addr) = value;
return;
case SMAP_R_EMAC3_TxMODE0_L:
DEV9_LOG("SMAP: SMAP_R_EMAC3_TxMODE0_L 16bit write %x\n", value);
dev9Ru16(addr) = value;
return;
case SMAP_R_EMAC3_TxMODE1_L:
emu_printf("SMAP: SMAP_R_EMAC3_TxMODE1_L 16bit write %x\n", value);
dev9Ru16(addr) = value;
return;
case SMAP_R_EMAC3_TxMODE0_H:
emu_printf("SMAP: SMAP_R_EMAC3_TxMODE0_H 16bit write %x\n", value);
dev9Ru16(addr) = value;
return;
case SMAP_R_EMAC3_TxMODE1_H:
emu_printf("SMAP: SMAP_R_EMAC3_TxMODE1_H 16bit write %x\n", value);
dev9Ru16(addr) = value;
return;
case SMAP_R_EMAC3_STA_CTRL_H:
DEV9_LOG("SMAP: SMAP_R_EMAC3_STA_CTRL_H 16bit write %x\n", value);
dev9Ru16(addr) = value;
return;
*/
default :
DEV9_LOG("SMAP : Unknown 16 bit write @ %X,v=%X\n",addr,value);
dev9Ru16(addr) = value;
return;
}
DEV9_LOG("SMAP : error , 16 bit write @ %X,v=%X\n",addr,value);
dev9Ru16(addr) = value;
}
void CALLBACK smap_write32(u32 addr, u32 value)
{
if (addr>=SMAP_EMAC3_REGBASE && addr<SMAP_EMAC3_REGEND)
{
smap_write16(addr,value&0xFFFF);
smap_write16(addr+2,value>>16);
return;
}
switch(addr)
{
case SMAP_R_TXFIFO_DATA:
if(dev9.bd_swap)
value=(value<<24)|(value>>24)|((value>>8)&0xFF00)|((value<<8)&0xFF0000);
DEV9_LOG("SMAP_R_TXFIFO_DATA 32bit write %x\n", value);
*((u32*)(dev9.txfifo+dev9Ru32(SMAP_R_TXFIFO_WR_PTR)))=value;
dev9Ru32(SMAP_R_TXFIFO_WR_PTR) = (dev9Ru32(SMAP_R_TXFIFO_WR_PTR)+4)&16383;
return;
default :
DEV9_LOG("SMAP : Unknown 32 bit write @ %X,v=%X\n",addr,value);
dev9Ru32(addr) = value;
return;
}
DEV9_LOG("SMAP : error , 32 bit write @ %X,v=%X\n",addr,value);
dev9Ru32(addr) = value;
}
void CALLBACK smap_readDMA8Mem(u32 *pMem, int size)
{
if(dev9Ru16(SMAP_R_RXFIFO_CTRL)&SMAP_RXFIFO_DMAEN)
{
dev9Ru32(SMAP_R_RXFIFO_RD_PTR)&=16383;
size>>=1;
DEV9_LOG(" * * SMAP DMA READ START: rd_ptr=%d, wr_ptr=%d\n", dev9Ru32(SMAP_R_RXFIFO_RD_PTR), dev9.rxfifo_wr_ptr);
while(size>0)
{
*pMem = *((u32*)(dev9.rxfifo+dev9Ru32(SMAP_R_RXFIFO_RD_PTR)));
pMem++;
dev9Ru32(SMAP_R_RXFIFO_RD_PTR) = (dev9Ru32(SMAP_R_RXFIFO_RD_PTR)+4)&16383;
size-=4;
}
DEV9_LOG(" * * SMAP DMA READ END: rd_ptr=%d, wr_ptr=%d\n", dev9Ru32(SMAP_R_RXFIFO_RD_PTR), dev9.rxfifo_wr_ptr);
dev9Ru16(SMAP_R_RXFIFO_CTRL) &= ~SMAP_RXFIFO_DMAEN;
}
}
void CALLBACK smap_writeDMA8Mem(u32* pMem, int size)
{
if(dev9Ru16(SMAP_R_TXFIFO_CTRL)&SMAP_TXFIFO_DMAEN)
{
dev9Ru32(SMAP_R_TXFIFO_WR_PTR)&=16383;
size>>=1;
DEV9_LOG(" * * SMAP DMA WRITE START: wr_ptr=%d, rd_ptr=%d\n", dev9Ru32(SMAP_R_TXFIFO_WR_PTR), dev9.txfifo_rd_ptr);
while(size>0)
{
int value=*pMem;
// value=(value<<24)|(value>>24)|((value>>8)&0xFF00)|((value<<8)&0xFF0000);
pMem++;
*((u32*)(dev9.txfifo+dev9Ru32(SMAP_R_TXFIFO_WR_PTR)))=value;
dev9Ru32(SMAP_R_TXFIFO_WR_PTR) = (dev9Ru32(SMAP_R_TXFIFO_WR_PTR)+4)&16383;
size-=4;
}
DEV9_LOG(" * * SMAP DMA WRITE END: wr_ptr=%d, rd_ptr=%d\n", dev9Ru32(SMAP_R_TXFIFO_WR_PTR), dev9.txfifo_rd_ptr);
dev9Ru16(SMAP_R_TXFIFO_CTRL) &= ~SMAP_TXFIFO_DMAEN;
}
}

View File

@ -0,0 +1,13 @@
#pragma once
#include "dev9.h"
u8 CALLBACK smap_read8(u32 addr);
u16 CALLBACK smap_read16(u32 addr);
u32 CALLBACK smap_read32(u32 addr);
void CALLBACK smap_write8(u32 addr, u8 value);
void CALLBACK smap_write16(u32 addr, u16 value);
void CALLBACK smap_write32(u32 addr, u32 value);
void CALLBACK smap_readDMA8Mem(u32 *pMem, int size);
void CALLBACK smap_writeDMA8Mem(u32 *pMem, int size);

View File

@ -0,0 +1,294 @@
#include <stdio.h>
#include <stdarg.h>
#include <winsock2.h>
extern "C" {
#include "dev9.h"
}
#include <Iphlpapi.h>
#include "pcap_io.h"
#include <deque>
#include <queue>
#include <vector>
//extern "C" int emu_printf(const char *fmt, ...);
mac_address gateway_mac = { 0x76, 0x6D, 0x61, 0x63, 0x30, 0x32 };
mac_address virtual_mac = { 0x76, 0x6D, 0x61, 0x63, 0x30, 0x31 };
mac_address broadcast_mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
//mac_address host_mac = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
ip_address virtual_gway_ip = { 192, 168, 1, 1};
ip_address virtual_host_ip = { 192, 168, 1, 2};
char namebuff[256];
FILE*packet_log;
int pcap_io_running=0;
class packet_info
{
public:
int length;
s8 data[2048];
packet_info()
{
length=0;
memset(data,0,2048);
}
packet_info(const packet_info& pkt)
{
length=pkt.length;
memcpy(data,pkt.data,length);
}
packet_info(int l, void*d)
{
length=l;
memcpy(data,d,l);
}
};
std::queue<packet_info> recv_queue;
int ip_checksum(u16 *data, int length)
{
int n=(length+1)>>1;
int s=0;
for(int i=0;i<n;i++)
{
int v=data[i];
s=s+v;
}
s = (s&0xFFFF)+(s>>16);
return s;
}
//
int pcap_io_init(char *adapter)
{
WSADATA wsaData;
emu_printf(" * Socket IO: Initializing virtual gateway...",adapter);
WSAStartup(0x0200,&wsaData);
packet_log=fopen("logs/packet.log","w");
pcap_io_running=1;
emu_printf("Ok.\n");
return 0;
}
int pcap_io_send(void* packet, int plen)
{
emu_printf(" * Socket IO: Sending %d byte packet.\n",plen);
if(packet_log)
{
int i=0;
int n=0;
fprintf(packet_log,"PACKET SEND: %d BYTES\n",plen);
for(i=0,n=0;i<plen;i++)
{
fprintf(packet_log,"%02x",((unsigned char*)packet)[i]);
n++;
if(n==16)
{
fprintf(packet_log,"\n");
n=0;
}
else
fprintf(packet_log," ");
}
fprintf(packet_log,"\n");
}
ethernet_header *eth = (ethernet_header*)packet;
if(mac_compare(eth->dst,broadcast_mac)==0) //broadcast packets
{
if(eth->protocol == 0x0608) //ARP
{
arp_packet *arp = (arp_packet*)((s8*)packet+sizeof(ethernet_header));
if(arp->operation == 0x0100) //ARP request
{
if(ip_compare(arp->p_dst,virtual_gway_ip)==0) //it's trying to resolve the virtual gateway's mac addr
{
full_arp_packet p;
p.header.src = gateway_mac;
p.header.dst = eth->src;
p.header.protocol = 0x0608;
p.arp.h_addr_len=6;
p.arp.h_dst = eth->src;
p.arp.h_src = gateway_mac;
p.arp.p_addr_len = 4;
p.arp.p_dst = arp->p_src;
p.arp.p_src = virtual_gway_ip;
p.arp.protocol = 0x0008;
p.arp.operation = 0x0200;
//packet_info pkt(sizeof(p),&p)
recv_queue.push(packet_info(sizeof(p),&p));
}
}
}
}
else if(mac_compare(eth->dst,gateway_mac)==0)
{
if(eth->protocol == 0x0008) //IP
{
ip_header *ip = (ip_header*)((s8*)packet+sizeof(ethernet_header));
if((ip->proto == 0x11) && (ip->dst.bytes[0]!=192)) //UDP (non-local)
{
//
//if(ip->
}
else
if(ip->proto == 0x01) //ICMP
{
if (ip_compare(ip->dst,virtual_gway_ip)==0) //PING to gateway
{
static u8 icmp_packet[1024];
memcpy(icmp_packet,packet,plen);
ethernet_header *eh = (ethernet_header *)icmp_packet;
eh->dst=eth->src;
eh->src=gateway_mac;
ip_header *iph = (ip_header*)(eh+1);
iph->dst = ip->src;
iph->src = virtual_gway_ip;
iph->hdr_csum = 0;
int sum = ip_checksum((u16*)iph,sizeof(ip_header));
iph->hdr_csum = sum;
icmp_header *ich = (icmp_header*)(iph+1);
ich->type=0;
ich->code=0;
ich->csum=0;
sum = ip_checksum((u16*)ich,iph->len-sizeof(ip_header));
ich->csum = sum;
recv_queue.push(packet_info(plen,&icmp_packet));
}
else if (ip->dst.bytes[0] != 192) //PING to external
{
static u8 icmp_packet[1024];
memcpy(icmp_packet,packet,plen);
ethernet_header *eh = (ethernet_header *)icmp_packet;
eh->dst=eth->src;
eh->src=gateway_mac;
ip_header *iph = (ip_header*)(eh+1);
iph->dst = ip->src;
iph->src = virtual_gway_ip;
iph->hdr_csum = 0;
int sum = ip_checksum((u16*)iph,sizeof(ip_header));
iph->hdr_csum = sum;
icmp_header *ich = (icmp_header*)(iph+1);
ich->type=0;
ich->code=0;
ich->csum=0;
sum = ip_checksum((u16*)ich,iph->len-sizeof(ip_header));
ich->csum = sum;
recv_queue.push(packet_info(plen,&icmp_packet));
}
}
}
}
return 0;
}
int pcap_io_recv(void* packet, int max_len)
{
if(pcap_io_running<=0)
return -1;
if(!recv_queue.empty())
{
packet_info pkt(recv_queue.front());
recv_queue.pop();
memcpy(packet,pkt.data,pkt.length);
if(packet_log)
{
int i=0;
int n=0;
int plen=pkt.length;
fprintf(packet_log,"PACKET RECV: %d BYTES\n",plen);
for(i=0,n=0;i<plen;i++)
{
fprintf(packet_log,"%02x",((unsigned char*)packet)[i]);
n++;
if(n==16)
{
fprintf(packet_log,"\n");
n=0;
}
else
fprintf(packet_log," ");
}
fprintf(packet_log,"\n");
}
return pkt.length;
}
return -1;
}
void pcap_io_close()
{
if(packet_log)
fclose(packet_log);
pcap_io_running=0;
WSACleanup();
}
int pcap_io_get_dev_num()
{
return 1;
}
char* pcap_io_get_dev_name(int num)
{
return "SockIO";
}
char* pcap_io_get_dev_desc(int num)
{
return "Simulated Ethernet Adapter";
}

View File

@ -0,0 +1,191 @@
#include <stdio.h>
#include <conio.h>
#include "packet32.h"
#include "ntddndis.h"
#include "socks.h"
#include "DEV9.h"
#define BUFFER_SIZE (2048)
LPADAPTER lpAdapter;
LPPACKET lpSendPacket;
LPPACKET lpRecvPacket;
u8 buffer[BUFFER_SIZE];
u8 *buf;
int lbytes;
int tbytes;
typedef struct {
char name[256];
char desc[256];
} _Adapter;
_Adapter AdapterList[16];
long sockOpen(char *Device) {
lpAdapter = PacketOpenAdapter(Device);
if (lpAdapter == NULL) return -1;
#ifdef DEV9_LOG
DEV9_LOG("PacketOpenAdapter %s: %p\n", Device, lpAdapter);
#endif
if(PacketSetHwFilter(lpAdapter,NDIS_PACKET_TYPE_PROMISCUOUS)==FALSE){
SysMessage("Warning: unable to set promiscuous mode!");
}
if(PacketSetBuff(lpAdapter,512000)==FALSE){
SysMessage("Unable to set the kernel buffer!");
return -1;
}
if(PacketSetReadTimeout(lpAdapter,100)==FALSE){
SysMessage("Warning: unable to set the read tiemout!");
}
if((lpRecvPacket = PacketAllocatePacket())==NULL){
SysMessage("Error: failed to allocate the LPPACKET structure.");
return (-1);
}
if((lpSendPacket = PacketAllocatePacket())==NULL){
SysMessage("Error: failed to allocate the LPPACKET structure.");
return (-1);
}
lbytes=0;
tbytes=0;
return 0;
}
void sockClose() {
PacketCloseAdapter(lpAdapter);
}
long sockSendData(void *pData, int Size) {
u8 *data = (u8*)pData;
// printf("_sendPacket %d (time=%d)\n", Size, timeGetTime());
while (Size > 0) {
PacketInitPacket(lpSendPacket, data, Size > 1024 ? 1024 : Size);
if(PacketSendPacket(lpAdapter,lpSendPacket,FALSE)==FALSE){
printf("Error: PacketSendPacket failed\n");
return (-1);
}
data+= 1024; Size-= 1024;
PacketFreePacket(lpSendPacket);
}
return 0;
}
int _filterPacket(u8 *_buf) {
/* DEV9_LOG("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", _buf[5], _buf[4], _buf[3], _buf[2], _buf[1], _buf[0]);
DEV9_LOG("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", _buf[11], _buf[10], _buf[9], _buf[8], _buf[7], _buf[6]);
DEV9_LOG("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", _buf[17], _buf[16], _buf[15], _buf[14], _buf[13], _buf[12]);
DEV9_LOG("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", _buf[23], _buf[22], _buf[21], _buf[20], _buf[19], _buf[18]);
*/
if (_buf[0] == 0xff && _buf[1] == 0xff && _buf[2] == 0xff &&
_buf[3] == 0xff && _buf[4] == 0xff && _buf[5] == 0xff) {
return 1;
} else
if (_buf[0] == 0x00 && _buf[1] == 0x00 && _buf[2] == 0x00 &&
_buf[3] == 0x00 && _buf[4] == 0x00 && _buf[5] == 0x00) {
return 1;
} else
if (*((u16*)&_buf[12]) == 0x0806) {
printf("ARP\n");
return 1;
}
return 0;
}
int _recvPacket(void *pData) {
struct bpf_hdr *hdr;
u8 *data;
int ret=0;
int size;
while (lbytes > 0) {
hdr = (struct bpf_hdr *)buf;
// DEV9_LOG("hdr %d,%d,%d\n", hdr->bh_hdrlen, hdr->bh_caplen, hdr->bh_datalen);
// DEV9_LOG("lbytes %d\n", lbytes);
data = buf+hdr->bh_hdrlen;
size = Packet_WORDALIGN(hdr->bh_hdrlen+hdr->bh_datalen);
buf+= size; lbytes-= size;
if (_filterPacket(data)) {
struct bpf_stat stat;
ret = hdr->bh_datalen;
memcpy(pData, data, ret);
if(PacketGetStats(lpAdapter,&stat)==FALSE){
printf("Warning: unable to get stats from the kernel!\n");
}
// printf("_recvPacket %d (tbytes=%d, packets=%d, lost=%d, time=%d)\n", ret, tbytes, stat.bs_recv,stat.bs_drop, timeGetTime());
// printf("%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", data[5], data[4], data[3], data[2], data[1], data[0]);
break;
}
}
return ret;
}
long sockRecvData(void *pData, int Size) {
int ret;
ret = _recvPacket(pData);
if (ret > 0) return ret;
PacketInitPacket(lpRecvPacket, buffer, BUFFER_SIZE);
if(PacketReceivePacket(lpAdapter,lpRecvPacket,TRUE)==FALSE){
printf("Error: PacketReceivePacket failed");
return (-1);
}
lbytes = lpRecvPacket->ulBytesReceived;
tbytes+= lbytes;
// DEV9_LOG("PacketReceivePacket %d:\n", lbytes);
if (lbytes == 0) return 0;
memcpy(buffer, lpRecvPacket->Buffer, lbytes);
buf = buffer;
PacketFreePacket(lpRecvPacket);
return _recvPacket(pData);
}
long sockGetDevicesNum() {
char AdapterName[8192]; // string that contains a list of the network adapters
ULONG AdapterLength;
char *temp,*temp1;
int i;
AdapterLength = sizeof(AdapterName);
if(PacketGetAdapterNames(AdapterName,&AdapterLength)==FALSE){
printf("Unable to retrieve the list of the adapters!\n");
return -1;
}
temp=AdapterName;
temp1=AdapterName;
i=0;
while (temp[0] != 0) {
strcpy(AdapterList[i++].name, temp);
temp+= strlen(temp)+1;
}
i=0; temp++;
while (temp[0] != 0) {
strcpy(AdapterList[i++].desc, temp);
temp+= strlen(temp)+1;
}
return i;
}
char *sockGetDevice(int index) {
return AdapterList[index].name;
}
char *sockGetDeviceDesc(int index) {
return AdapterList[index].desc;
}

View File

@ -0,0 +1,12 @@
#ifndef __SOCKS_H__
#define __SOCKS_H__
long sockOpen(char *Device);
void sockClose();
long sockSendData(void *pData, int Size);
long sockRecvData(void *pData, int Size);
long sockGetDevicesNum();
char *sockGetDevice(int index);
char *sockGetDeviceDesc(int index);
#endif /* __SOCKS_H__*/

View File

@ -0,0 +1,33 @@
/* PCSX2 - PS2 Emulator for PCs
* Copyright (C) 2002-2010 PCSX2 Dev Team
*
* PCSX2 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 Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* PCSX2 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with PCSX2.
* If not, see <http://www.gnu.org/licenses/>.
*/
// svnrev_template.h --> svnrev.h
//
// This file acts as a template for the automatic SVN revision/version tag.
// It is used by the utility SubWCrev.exe to create an "svnrev.h" file for
// whichever project is being compiled (as indicated by command line options
// passed to SubWCRev.exe during the project's pre-build step).
//
// The SubWCRev.exe utility is part of TortoiseSVN and requires several DLLs
// installed by TortoiseSVN, so it will only be available if you have TortoiseSVN
// installed on your system. If you do not have it installed, a generic template
// is used instead (see svnrev_generic.h). Having TortoiseSVN is handy but not
// necessary. If you do not have it installed, everything will still compile
// fine except without the SVN revision tagged to the application/dll version.
//
// TortoiseSVN can be downloaded from http://tortoisesvn.tigris.org
#define SVN_REV 0
#define SVN_MODS 0

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
#pragma once
#include <vector>
#include "net.h"
using namespace std;
struct tap_adapter
{
string name;
string guid;
};
vector<tap_adapter>* GetTapAdapters();
class TAPAdapter : public NetAdapter
{
HANDLE htap;
OVERLAPPED read,write;
public:
TAPAdapter();
virtual bool blocks();
//gets a packet.rv :true success
virtual bool recv(NetPacket* pkt);
//sends the packet and deletes it when done (if successful).rv :true success
virtual bool send(NetPacket* pkt);
virtual ~TAPAdapter();
};

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,137 @@
/*
* Copyright (C) 1999 WIDE Project.
* All rights reserved.
*
* 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 above copyright
* 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 project 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 PROJECT 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 PROJECT 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.
*/
#ifndef _BITTYPES_H
#define _BITTYPES_H
#ifndef HAVE_U_INT8_T
#if SIZEOF_CHAR == 1
typedef unsigned char u_int8_t;
typedef signed char int8_t;
#elif SIZEOF_INT == 1
typedef unsigned int u_int8_t;
typedef signed int int8_t;
#else /* XXX */
#error "there's no appropriate type for u_int8_t"
#endif
#define HAVE_U_INT8_T 1
#define HAVE_INT8_T 1
#endif /* HAVE_U_INT8_T */
#ifndef HAVE_U_INT16_T
#if SIZEOF_SHORT == 2
typedef unsigned short u_int16_t;
typedef signed short int16_t;
#elif SIZEOF_INT == 2
typedef unsigned int u_int16_t;
typedef signed int int16_t;
#elif SIZEOF_CHAR == 2
typedef unsigned char u_int16_t;
typedef signed char int16_t;
#else /* XXX */
#error "there's no appropriate type for u_int16_t"
#endif
#define HAVE_U_INT16_T 1
#define HAVE_INT16_T 1
#endif /* HAVE_U_INT16_T */
#ifndef HAVE_U_INT32_T
#if SIZEOF_INT == 4
typedef unsigned int u_int32_t;
typedef signed int int32_t;
#elif SIZEOF_LONG == 4
typedef unsigned long u_int32_t;
typedef signed long int32_t;
#elif SIZEOF_SHORT == 4
typedef unsigned short u_int32_t;
typedef signed short int32_t;
#else /* XXX */
#error "there's no appropriate type for u_int32_t"
#endif
#define HAVE_U_INT32_T 1
#define HAVE_INT32_T 1
#endif /* HAVE_U_INT32_T */
#ifndef HAVE_U_INT64_T
#if SIZEOF_LONG_LONG == 8
typedef unsigned long long u_int64_t;
typedef long long int64_t;
#elif defined(_MSC_EXTENSIONS)
typedef unsigned _int64 u_int64_t;
typedef _int64 int64_t;
#elif SIZEOF_INT == 8
typedef unsigned int u_int64_t;
#elif SIZEOF_LONG == 8
typedef unsigned long u_int64_t;
#elif SIZEOF_SHORT == 8
typedef unsigned short u_int64_t;
#else /* XXX */
#error "there's no appropriate type for u_int64_t"
#endif
#endif /* HAVE_U_INT64_T */
#ifndef PRId64
#ifdef _MSC_EXTENSIONS
#define PRId64 "I64d"
#else /* _MSC_EXTENSIONS */
#define PRId64 "lld"
#endif /* _MSC_EXTENSIONS */
#endif /* PRId64 */
#ifndef PRIo64
#ifdef _MSC_EXTENSIONS
#define PRIo64 "I64o"
#else /* _MSC_EXTENSIONS */
#define PRIo64 "llo"
#endif /* _MSC_EXTENSIONS */
#endif /* PRIo64 */
#ifndef PRIx64
#ifdef _MSC_EXTENSIONS
#define PRIx64 "I64x"
#else /* _MSC_EXTENSIONS */
#define PRIx64 "llx"
#endif /* _MSC_EXTENSIONS */
#endif /* PRIx64 */
#ifndef PRIu64
#ifdef _MSC_EXTENSIONS
#define PRIu64 "I64u"
#else /* _MSC_EXTENSIONS */
#define PRIu64 "llu"
#endif /* _MSC_EXTENSIONS */
#endif /* PRIu64 */
#endif /* _BITTYPES_H */

View File

@ -0,0 +1,249 @@
// The code has been designed for 64Mb flash and uses as file support the second memory card
#include <stdio.h>
#include <winsock2.h>
#include "DEV9.h"
#define PAGE_SIZE_BITS 9
#define PAGE_SIZE (1<<PAGE_SIZE_BITS)
#define ECC_SIZE (16)
#define PAGE_SIZE_ECC (PAGE_SIZE+ECC_SIZE)
#define BLOCK_SIZE (16 * PAGE_SIZE)
#define BLOCK_SIZE_ECC (16 * PAGE_SIZE_ECC)
#define CARD_SIZE (1024 * BLOCK_SIZE)
#define CARD_SIZE_ECC (1024 * BLOCK_SIZE_ECC)
static volatile u32 ctrl, cmd= (u32)-1, address, id, counter, addrbyte;
static u8 data[PAGE_SIZE_ECC], file[CARD_SIZE_ECC];
static void xfromman_call20_calculateXors(unsigned char buffer[128], unsigned char xor[4]);
static void calculateECC(u8 page[PAGE_SIZE_ECC]){
memset(page+PAGE_SIZE, 0x00, ECC_SIZE);
xfromman_call20_calculateXors(page + 0*(PAGE_SIZE>>2), page+PAGE_SIZE+0*3);//(ECC_SIZE>>2));
xfromman_call20_calculateXors(page + 1*(PAGE_SIZE>>2), page+PAGE_SIZE+1*3);//(ECC_SIZE>>2));
xfromman_call20_calculateXors(page + 2*(PAGE_SIZE>>2), page+PAGE_SIZE+2*3);//(ECC_SIZE>>2));
xfromman_call20_calculateXors(page + 3*(PAGE_SIZE>>2), page+PAGE_SIZE+3*3);//(ECC_SIZE>>2));
}
static char* getCmdName(u32 cmd){
switch(cmd) {
case SM_CMD_READ1: return "READ1";
case SM_CMD_READ2: return "READ2";
case SM_CMD_READ3: return "READ3";
case SM_CMD_RESET: return "RESET";
case SM_CMD_WRITEDATA: return "WRITEDATA";
case SM_CMD_PROGRAMPAGE: return "PROGRAMPAGE";
case SM_CMD_ERASEBLOCK: return "ERASEBLOCK";
case SM_CMD_ERASECONFIRM: return "ERASECONFIRM";
case SM_CMD_GETSTATUS: return "GETSTATUS";
case SM_CMD_READID: return "READID";
default: return "unknown";
}
}
void CALLBACK FLASHinit(){
FILE *fd;
id= FLASH_ID_64MBIT;
counter= 0;
addrbyte= 0;
address = 0;
memset(data, 0xFF, PAGE_SIZE);
calculateECC(data);
ctrl = FLASH_PP_READY;
if (fd=fopen("flash.dat", "rb")){
fread(file, 1, CARD_SIZE_ECC, fd);
fclose(fd);
}else
memset(file, 0xFF, CARD_SIZE_ECC);
}
u32 CALLBACK FLASHread32(u32 addr, int size) {
u32 value, refill= 0;
switch(addr) {
case FLASH_R_DATA:
memcpy(&value, &data[counter], size);
counter += size;
DEV9_LOG("*FLASH DATA %dbit read 0x%08lX %s\n", size*8, value, (ctrl & FLASH_PP_READ) ? "READ_ENABLE" : "READ_DISABLE");
if (cmd == SM_CMD_READ3){
if (counter >= PAGE_SIZE_ECC){
counter= PAGE_SIZE;
refill= 1;
}
}else{
if ( (ctrl & FLASH_PP_NOECC) && (counter >= PAGE_SIZE)){
counter %= PAGE_SIZE;
refill= 1;
}else
if (!(ctrl & FLASH_PP_NOECC) && (counter >= PAGE_SIZE_ECC)){
counter %= PAGE_SIZE_ECC;
refill= 1;
}
}
if (refill){
ctrl &= ~FLASH_PP_READY;
address += PAGE_SIZE;
address %= CARD_SIZE;
memcpy(data, file+(address>>PAGE_SIZE_BITS)*PAGE_SIZE_ECC, PAGE_SIZE);
calculateECC(data); // calculate ECC; should be in the file already
ctrl |= FLASH_PP_READY;
}
return value;
case FLASH_R_CMD:
DEV9_LOG("*FLASH CMD %dbit read %s DENIED\n", size*8, getCmdName(cmd));
return cmd;
case FLASH_R_ADDR:
DEV9_LOG("*FLASH ADDR %dbit read DENIED\n", size*8);
return 0;
case FLASH_R_CTRL:
DEV9_LOG("*FLASH CTRL %dbit read 0x%08lX\n", size*8, ctrl);
return ctrl;
case FLASH_R_ID:
if (cmd == SM_CMD_READID){
DEV9_LOG("*FLASH ID %dbit read 0x%08lX\n", size*8, id);
return id;//0x98=Toshiba/0xEC=Samsung maker code should be returned first
}else
if (cmd == SM_CMD_GETSTATUS){
value= 0x80 | ((ctrl & 1) << 6); // 0:0=pass, 6:ready/busy, 7:1=not protected
DEV9_LOG("*FLASH STATUS %dbit read 0x%08lX\n", size*8, value);
return value;
}//else fall off
default:
DEV9_LOG("*FLASH Unkwnown %dbit read at address %lx\n", size*8, addr);
return 0;
}
}
void CALLBACK FLASHwrite32(u32 addr, u32 value, int size) {
switch(addr & 0x1FFFFFFF) {
case FLASH_R_DATA:
DEV9_LOG("*FLASH DATA %dbit write 0x%08lX %s\n", size*8, value, (ctrl & FLASH_PP_WRITE) ? "WRITE_ENABLE" : "WRITE_DISABLE");
memcpy(&data[counter], &value, size);
counter += size;
counter %= PAGE_SIZE_ECC;//should not get past the last byte, but at the end
break;
case FLASH_R_CMD:
if (!(ctrl & FLASH_PP_READY)){
if ((value != SM_CMD_GETSTATUS) && (value != SM_CMD_RESET)){
DEV9_LOG("*FLASH CMD %dbit write %s ILLEGAL in busy mode - IGNORED\n", size*8, getCmdName(value));
break;
}
}
if (cmd == SM_CMD_WRITEDATA){
if ((value != SM_CMD_PROGRAMPAGE) && (value != SM_CMD_RESET)){
DEV9_LOG("*FLASH CMD %dbit write %s ILLEGAL after WRITEDATA cmd - IGNORED\n", size*8, getCmdName(value));
ctrl &= ~FLASH_PP_READY;//go busy, reset is needed
break;
}
}
DEV9_LOG("*FLASH CMD %dbit write %s\n", size*8, getCmdName(value));
switch (value){ // A8 bit is encoded in READ cmd;)
case SM_CMD_READ1: counter= 0; if (cmd != SM_CMD_GETSTATUS) address= counter; addrbyte= 0; break;
case SM_CMD_READ2: counter= PAGE_SIZE/2; if (cmd != SM_CMD_GETSTATUS) address= counter; addrbyte= 0; break;
case SM_CMD_READ3: counter= PAGE_SIZE; if (cmd != SM_CMD_GETSTATUS) address= counter; addrbyte= 0; break;
case SM_CMD_RESET: FLASHinit(); break;
case SM_CMD_WRITEDATA: counter= 0; address= counter; addrbyte= 0; break;
case SM_CMD_ERASEBLOCK: counter= 0; memset(data, 0xFF, PAGE_SIZE); address= counter; addrbyte= 1; break;
case SM_CMD_PROGRAMPAGE: //fall
case SM_CMD_ERASECONFIRM:
ctrl &= ~FLASH_PP_READY;
calculateECC(data);
memcpy(file+(address/PAGE_SIZE)*PAGE_SIZE_ECC, data, PAGE_SIZE_ECC);
/*write2file*/
ctrl |= FLASH_PP_READY; break;
case SM_CMD_GETSTATUS: break;
case SM_CMD_READID: counter= 0; address= counter; addrbyte= 0; break;
default:
ctrl &= ~FLASH_PP_READY;
return;//ignore any other command; go busy, reset is needed
}
cmd= value;
break;
case FLASH_R_ADDR:
DEV9_LOG("*FLASH ADDR %dbit write 0x%08lX\n", size*8, value);
address |= (value & 0xFF) << (addrbyte == 0 ? 0 : (1 + 8 * addrbyte));
addrbyte++;
DEV9_LOG("*FLASH ADDR = 0x%08lX (addrbyte=%d)\n", address, addrbyte);
if (!(value & 0x100)){ // address is complete
if ((cmd == SM_CMD_READ1) || (cmd == SM_CMD_READ2) || (cmd == SM_CMD_READ3)) {
ctrl &= ~FLASH_PP_READY;
memcpy(data, file+(address>>PAGE_SIZE_BITS)*PAGE_SIZE_ECC, PAGE_SIZE);
calculateECC(data); // calculate ECC; should be in the file already
ctrl |= FLASH_PP_READY;
}
addrbyte= 0; // address reset
{
u32 bytes, pages, blocks;
blocks = address / BLOCK_SIZE;
pages = address-(blocks*BLOCK_SIZE);
bytes = pages % PAGE_SIZE;
pages = pages / PAGE_SIZE;
DEV9_LOG("*FLASH ADDR = 0x%08lX (%d:%d:%d) (addrbyte=%d) FINAL\n", address, blocks, pages, bytes, addrbyte);
}
}
break;
case FLASH_R_CTRL:
DEV9_LOG("*FLASH CTRL %dbit write 0x%08lX\n", size*8, value);
ctrl = (ctrl & FLASH_PP_READY) | (value & ~FLASH_PP_READY);
break;
case FLASH_R_ID:
DEV9_LOG("*FLASH ID %dbit write 0x%08lX DENIED :P\n", size*8, value);
break;
default:
DEV9_LOG("*FLASH Unkwnown %dbit write at address 0x%08lX= 0x%08lX IGNORED\n", size*8, addr, value);
break;
}
}
static unsigned char xor_table[256]={
0x00, 0x87, 0x96, 0x11, 0xA5, 0x22, 0x33, 0xB4, 0xB4, 0x33, 0x22, 0xA5, 0x11, 0x96, 0x87, 0x00,
0xC3, 0x44, 0x55, 0xD2, 0x66, 0xE1, 0xF0, 0x77, 0x77, 0xF0, 0xE1, 0x66, 0xD2, 0x55, 0x44, 0xC3,
0xD2, 0x55, 0x44, 0xC3, 0x77, 0xF0, 0xE1, 0x66, 0x66, 0xE1, 0xF0, 0x77, 0xC3, 0x44, 0x55, 0xD2,
0x11, 0x96, 0x87, 0x00, 0xB4, 0x33, 0x22, 0xA5, 0xA5, 0x22, 0x33, 0xB4, 0x00, 0x87, 0x96, 0x11,
0xE1, 0x66, 0x77, 0xF0, 0x44, 0xC3, 0xD2, 0x55, 0x55, 0xD2, 0xC3, 0x44, 0xF0, 0x77, 0x66, 0xE1,
0x22, 0xA5, 0xB4, 0x33, 0x87, 0x00, 0x11, 0x96, 0x96, 0x11, 0x00, 0x87, 0x33, 0xB4, 0xA5, 0x22,
0x33, 0xB4, 0xA5, 0x22, 0x96, 0x11, 0x00, 0x87, 0x87, 0x00, 0x11, 0x96, 0x22, 0xA5, 0xB4, 0x33,
0xF0, 0x77, 0x66, 0xE1, 0x55, 0xD2, 0xC3, 0x44, 0x44, 0xC3, 0xD2, 0x55, 0xE1, 0x66, 0x77, 0xF0,
0xF0, 0x77, 0x66, 0xE1, 0x55, 0xD2, 0xC3, 0x44, 0x44, 0xC3, 0xD2, 0x55, 0xE1, 0x66, 0x77, 0xF0,
0x33, 0xB4, 0xA5, 0x22, 0x96, 0x11, 0x00, 0x87, 0x87, 0x00, 0x11, 0x96, 0x22, 0xA5, 0xB4, 0x33,
0x22, 0xA5, 0xB4, 0x33, 0x87, 0x00, 0x11, 0x96, 0x96, 0x11, 0x00, 0x87, 0x33, 0xB4, 0xA5, 0x22,
0xE1, 0x66, 0x77, 0xF0, 0x44, 0xC3, 0xD2, 0x55, 0x55, 0xD2, 0xC3, 0x44, 0xF0, 0x77, 0x66, 0xE1,
0x11, 0x96, 0x87, 0x00, 0xB4, 0x33, 0x22, 0xA5, 0xA5, 0x22, 0x33, 0xB4, 0x00, 0x87, 0x96, 0x11,
0xD2, 0x55, 0x44, 0xC3, 0x77, 0xF0, 0xE1, 0x66, 0x66, 0xE1, 0xF0, 0x77, 0xC3, 0x44, 0x55, 0xD2,
0xC3, 0x44, 0x55, 0xD2, 0x66, 0xE1, 0xF0, 0x77, 0x77, 0xF0, 0xE1, 0x66, 0xD2, 0x55, 0x44, 0xC3,
0x00, 0x87, 0x96, 0x11, 0xA5, 0x22, 0x33, 0xB4, 0xB4, 0x33, 0x22, 0xA5, 0x11, 0x96, 0x87, 0x00};
static void xfromman_call20_calculateXors(unsigned char buffer[128], unsigned char xor[4]){
register unsigned char a=0, b=0, c=0, i;
for (i=0; i<128; i++){
a ^= xor_table[buffer[i]];
if (xor_table[buffer[i]] & 0x80){
b ^= ~i;
c ^= i;
}
}
xor[0]=(~a) & 0x77;
xor[1]=(~b) & 0x7F;
xor[2]=(~c) & 0x7F;
}

View File

@ -0,0 +1,163 @@
/*
* Copyright (c) 1993, 1994, 1997
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that: (1) source code distributions
* retain the above copyright notice and this paragraph in its entirety, (2)
* distributions including binary code include the above copyright notice and
* this paragraph in its entirety in the documentation or other materials
* provided with the distribution, and (3) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* @(#) $Header: /tcpdump/master/libpcap/Win32/Include/ip6_misc.h,v 1.5 2006-01-22 18:02:18 gianluca Exp $ (LBL)
*/
/*
* This file contains a collage of declarations for IPv6 from FreeBSD not present in Windows
*/
#include <winsock2.h>
#include <ws2tcpip.h>
#ifndef __MINGW32__
#define IN_MULTICAST(a) IN_CLASSD(a)
#endif
#define IN_EXPERIMENTAL(a) ((((u_int32_t) (a)) & 0xf0000000) == 0xf0000000)
#define IN_LOOPBACKNET 127
#if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)
/* IPv6 address */
struct in6_addr
{
union
{
u_int8_t u6_addr8[16];
u_int16_t u6_addr16[8];
u_int32_t u6_addr32[4];
} in6_u;
#define s6_addr in6_u.u6_addr8
#define s6_addr16 in6_u.u6_addr16
#define s6_addr32 in6_u.u6_addr32
#define s6_addr64 in6_u.u6_addr64
};
#define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
#define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
#endif /* __MINGW32__ */
#if (defined _MSC_VER) || (defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF))
typedef unsigned short sa_family_t;
#endif
#if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)
#define __SOCKADDR_COMMON(sa_prefix) \
sa_family_t sa_prefix##family
/* Ditto, for IPv6. */
struct sockaddr_in6
{
__SOCKADDR_COMMON (sin6_);
u_int16_t sin6_port; /* Transport layer port # */
u_int32_t sin6_flowinfo; /* IPv6 flow information */
struct in6_addr sin6_addr; /* IPv6 address */
};
#define IN6_IS_ADDR_V4MAPPED(a) \
((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
(((u_int32_t *) (a))[2] == htonl (0xffff)))
#define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff)
#define IN6_IS_ADDR_LINKLOCAL(a) \
((((u_int32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000))
#define IN6_IS_ADDR_LOOPBACK(a) \
(((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \
((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1))
#endif /* __MINGW32__ */
#define ip6_vfc ip6_ctlun.ip6_un2_vfc
#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow
#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen
#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt
#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim
#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim
#define nd_rd_type nd_rd_hdr.icmp6_type
#define nd_rd_code nd_rd_hdr.icmp6_code
#define nd_rd_cksum nd_rd_hdr.icmp6_cksum
#define nd_rd_reserved nd_rd_hdr.icmp6_data32[0]
/*
* IPV6 extension headers
*/
#define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */
#define IPPROTO_IPV6 41 /* IPv6 header. */
#define IPPROTO_ROUTING 43 /* IPv6 routing header */
#define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */
#define IPPROTO_ESP 50 /* encapsulating security payload */
#define IPPROTO_AH 51 /* authentication header */
#define IPPROTO_ICMPV6 58 /* ICMPv6 */
#define IPPROTO_NONE 59 /* IPv6 no next header */
#define IPPROTO_DSTOPTS 60 /* IPv6 destination options */
#define IPPROTO_PIM 103 /* Protocol Independent Multicast. */
#define IPV6_RTHDR_TYPE_0 0
/* Option types and related macros */
#define IP6OPT_PAD1 0x00 /* 00 0 00000 */
#define IP6OPT_PADN 0x01 /* 00 0 00001 */
#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */
#define IP6OPT_JUMBO_LEN 6
#define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */
#define IP6OPT_RTALERT_LEN 4
#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */
#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */
#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */
#define IP6OPT_MINLEN 2
#define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */
#define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */
#define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */
#define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */
#define IP6OPT_EID 0x8a /* 10 0 01010 */
#define IP6OPT_TYPE(o) ((o) & 0xC0)
#define IP6OPT_TYPE_SKIP 0x00
#define IP6OPT_TYPE_DISCARD 0x40
#define IP6OPT_TYPE_FORCEICMP 0x80
#define IP6OPT_TYPE_ICMP 0xC0
#define IP6OPT_MUTABLE 0x20
#if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)
#ifndef EAI_ADDRFAMILY
struct addrinfo {
int ai_flags; /* AI_PASSIVE, AI_CANONNAME */
int ai_family; /* PF_xxx */
int ai_socktype; /* SOCK_xxx */
int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */
size_t ai_addrlen; /* length of ai_addr */
char *ai_canonname; /* canonical name for hostname */
struct sockaddr *ai_addr; /* binary address */
struct addrinfo *ai_next; /* next structure in linked list */
};
#endif
#endif /* __MINGW32__ */

View File

@ -0,0 +1,47 @@
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.50 2007/04/01 21:43:55 guy Exp $ (LBL)
*/
/*
* For backwards compatibility.
*
* Note to OS vendors: do NOT get rid of this file! Some applications
* might expect to be able to include <pcap-bpf.h>.
*/
#include <pcap/bpf.h>

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 1994, 1996
* The Regents of the University of California. All rights reserved.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.13 2006/10/04 18:13:32 guy Exp $ (LBL)
*/
/*
* For backwards compatibility.
*
* Note to OS vendors: do NOT get rid of this file! Some applications
* might expect to be able to include <pcap-namedb.h>.
*/
#include <pcap/namedb.h>

View File

@ -0,0 +1,93 @@
/*
* Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy)
* Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California)
* All rights reserved.
*
* 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 above copyright
* 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 Politecnico di Torino 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
* OWNER 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.10.2.1 2008-10-06 15:38:39 gianluca Exp $ (LBL)
*/
#define SIZEOF_CHAR 1
#define SIZEOF_SHORT 2
#define SIZEOF_INT 4
#ifndef _MSC_EXTENSIONS
#define SIZEOF_LONG_LONG 8
#endif
/*
* Avoids a compiler warning in case this was already defined
* (someone defined _WINSOCKAPI_ when including 'windows.h', in order
* to prevent it from including 'winsock.h')
*/
#ifdef _WINSOCKAPI_
#undef _WINSOCKAPI_
#endif
#include <winsock2.h>
#include <fcntl.h>
#include "bittypes.h"
#include <time.h>
#include <io.h>
#ifndef __MINGW32__
#include "IP6_misc.h"
#endif
#define caddr_t char*
#if _MSC_VER < 1500
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define strdup _strdup
#endif
#define inline __inline
#ifdef __MINGW32__
#include <stdint.h>
#else /*__MINGW32__*/
/* MSVC compiler */
#ifndef _UINTPTR_T_DEFINED
#ifdef _WIN64
typedef unsigned __int64 uintptr_t;
#else
typedef _W64 unsigned int uintptr_t;
#endif
#define _UINTPTR_T_DEFINED
#endif
#ifndef _INTPTR_T_DEFINED
#ifdef _WIN64
typedef __int64 intptr_t;
#else
typedef _W64 int intptr_t;
#endif
#define _INTPTR_T_DEFINED
#endif
#endif /*__MINGW32__*/

45
plugins/dev9ghzdrk/pcap.h Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.59 2006/10/04 18:09:22 guy Exp $ (LBL)
*/
/*
* For backwards compatibility.
*
* Note to OS vendors: do NOT get rid of this file! Many applications
* expect to be able to include <pcap.h>, and at least some of them
* go through contortions in their configure scripts to try to detect
* OSes that have "helpfully" moved pcap.h to <pcap/pcap.h> without
* leaving behind a <pcap.h> file.
*/
#include <pcap/pcap.h>

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
* All rights reserved.
*
* 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 above copyright
* 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. The name of the author may not 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
* OWNER 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.
*
* bluetooth data struct
* By Paolo Abeni <paolo.abeni@email.it>
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/bluetooth.h,v 1.1 2007/09/22 02:10:17 guy Exp $
*/
#ifndef _PCAP_BLUETOOTH_STRUCTS_H__
#define _PCAP_BLUETOOTH_STRUCTS_H__
/*
* Header prepended libpcap to each bluetooth h:4 frame.
* fields are in network byte order
*/
typedef struct _pcap_bluetooth_h4_header {
u_int32_t direction; /* if first bit is set direction is incoming */
} pcap_bluetooth_h4_header;
#endif

View File

@ -0,0 +1,934 @@
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/bpf.h,v 1.19.2.8 2008-09-22 20:16:01 guy Exp $ (LBL)
*/
/*
* This is libpcap's cut-down version of bpf.h; it includes only
* the stuff needed for the code generator and the userland BPF
* interpreter, and the libpcap APIs for setting filters, etc..
*
* "pcap-bpf.c" will include the native OS version, as it deals with
* the OS's BPF implementation.
*
* XXX - should this all just be moved to "pcap.h"?
*/
#ifndef BPF_MAJOR_VERSION
#ifdef __cplusplus
extern "C" {
#endif
/* BSD style release date */
#define BPF_RELEASE 199606
#ifdef MSDOS /* must be 32-bit */
typedef long bpf_int32;
typedef unsigned long bpf_u_int32;
#else
typedef int bpf_int32;
typedef u_int bpf_u_int32;
#endif
/*
* Alignment macros. BPF_WORDALIGN rounds up to the next
* even multiple of BPF_ALIGNMENT.
*/
#ifndef __NetBSD__
#define BPF_ALIGNMENT sizeof(bpf_int32)
#else
#define BPF_ALIGNMENT sizeof(long)
#endif
#define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
#define BPF_MAXBUFSIZE 0x8000
#define BPF_MINBUFSIZE 32
/*
* Structure for "pcap_compile()", "pcap_setfilter()", etc..
*/
struct bpf_program {
u_int bf_len;
struct bpf_insn *bf_insns;
};
/*
* Struct return by BIOCVERSION. This represents the version number of
* the filter language described by the instruction encodings below.
* bpf understands a program iff kernel_major == filter_major &&
* kernel_minor >= filter_minor, that is, if the value returned by the
* running kernel has the same major number and a minor number equal
* equal to or less than the filter being downloaded. Otherwise, the
* results are undefined, meaning an error may be returned or packets
* may be accepted haphazardly.
* It has nothing to do with the source code version.
*/
struct bpf_version {
u_short bv_major;
u_short bv_minor;
};
/* Current version number of filter architecture. */
#define BPF_MAJOR_VERSION 1
#define BPF_MINOR_VERSION 1
/*
* Data-link level type codes.
*
* Do *NOT* add new values to this list without asking
* "tcpdump-workers@lists.tcpdump.org" for a value. Otherwise, you run
* the risk of using a value that's already being used for some other
* purpose, and of having tools that read libpcap-format captures not
* being able to handle captures with your new DLT_ value, with no hope
* that they will ever be changed to do so (as that would destroy their
* ability to read captures using that value for that other purpose).
*/
/*
* These are the types that are the same on all platforms, and that
* have been defined by <net/bpf.h> for ages.
*/
#define DLT_NULL 0 /* BSD loopback encapsulation */
#define DLT_EN10MB 1 /* Ethernet (10Mb) */
#define DLT_EN3MB 2 /* Experimental Ethernet (3Mb) */
#define DLT_AX25 3 /* Amateur Radio AX.25 */
#define DLT_PRONET 4 /* Proteon ProNET Token Ring */
#define DLT_CHAOS 5 /* Chaos */
#define DLT_IEEE802 6 /* 802.5 Token Ring */
#define DLT_ARCNET 7 /* ARCNET, with BSD-style header */
#define DLT_SLIP 8 /* Serial Line IP */
#define DLT_PPP 9 /* Point-to-point Protocol */
#define DLT_FDDI 10 /* FDDI */
/*
* These are types that are different on some platforms, and that
* have been defined by <net/bpf.h> for ages. We use #ifdefs to
* detect the BSDs that define them differently from the traditional
* libpcap <net/bpf.h>
*
* XXX - DLT_ATM_RFC1483 is 13 in BSD/OS, and DLT_RAW is 14 in BSD/OS,
* but I don't know what the right #define is for BSD/OS.
*/
#define DLT_ATM_RFC1483 11 /* LLC-encapsulated ATM */
#ifdef __OpenBSD__
#define DLT_RAW 14 /* raw IP */
#else
#define DLT_RAW 12 /* raw IP */
#endif
/*
* Given that the only OS that currently generates BSD/OS SLIP or PPP
* is, well, BSD/OS, arguably everybody should have chosen its values
* for DLT_SLIP_BSDOS and DLT_PPP_BSDOS, which are 15 and 16, but they
* didn't. So it goes.
*/
#if defined(__NetBSD__) || defined(__FreeBSD__)
#ifndef DLT_SLIP_BSDOS
#define DLT_SLIP_BSDOS 13 /* BSD/OS Serial Line IP */
#define DLT_PPP_BSDOS 14 /* BSD/OS Point-to-point Protocol */
#endif
#else
#define DLT_SLIP_BSDOS 15 /* BSD/OS Serial Line IP */
#define DLT_PPP_BSDOS 16 /* BSD/OS Point-to-point Protocol */
#endif
/*
* 17 is used for DLT_OLD_PFLOG in OpenBSD;
* OBSOLETE: DLT_PFLOG is 117 in OpenBSD now as well. See below.
* 18 is used for DLT_PFSYNC in OpenBSD; don't use it for anything else.
*/
#define DLT_ATM_CLIP 19 /* Linux Classical-IP over ATM */
/*
* Apparently Redback uses this for its SmartEdge 400/800. I hope
* nobody else decided to use it, too.
*/
#define DLT_REDBACK_SMARTEDGE 32
/*
* These values are defined by NetBSD; other platforms should refrain from
* using them for other purposes, so that NetBSD savefiles with link
* types of 50 or 51 can be read as this type on all platforms.
*/
#define DLT_PPP_SERIAL 50 /* PPP over serial with HDLC encapsulation */
#define DLT_PPP_ETHER 51 /* PPP over Ethernet */
/*
* The Axent Raptor firewall - now the Symantec Enterprise Firewall - uses
* a link-layer type of 99 for the tcpdump it supplies. The link-layer
* header has 6 bytes of unknown data, something that appears to be an
* Ethernet type, and 36 bytes that appear to be 0 in at least one capture
* I've seen.
*/
#define DLT_SYMANTEC_FIREWALL 99
/*
* Values between 100 and 103 are used in capture file headers as
* link-layer types corresponding to DLT_ types that differ
* between platforms; don't use those values for new DLT_ new types.
*/
/*
* This value was defined by libpcap 0.5; platforms that have defined
* it with a different value should define it here with that value -
* a link type of 104 in a save file will be mapped to DLT_C_HDLC,
* whatever value that happens to be, so programs will correctly
* handle files with that link type regardless of the value of
* DLT_C_HDLC.
*
* The name DLT_C_HDLC was used by BSD/OS; we use that name for source
* compatibility with programs written for BSD/OS.
*
* libpcap 0.5 defined it as DLT_CHDLC; we define DLT_CHDLC as well,
* for source compatibility with programs written for libpcap 0.5.
*/
#define DLT_C_HDLC 104 /* Cisco HDLC */
#define DLT_CHDLC DLT_C_HDLC
#define DLT_IEEE802_11 105 /* IEEE 802.11 wireless */
/*
* 106 is reserved for Linux Classical IP over ATM; it's like DLT_RAW,
* except when it isn't. (I.e., sometimes it's just raw IP, and
* sometimes it isn't.) We currently handle it as DLT_LINUX_SLL,
* so that we don't have to worry about the link-layer header.)
*/
/*
* Frame Relay; BSD/OS has a DLT_FR with a value of 11, but that collides
* with other values.
* DLT_FR and DLT_FRELAY packets start with the Q.922 Frame Relay header
* (DLCI, etc.).
*/
#define DLT_FRELAY 107
/*
* OpenBSD DLT_LOOP, for loopback devices; it's like DLT_NULL, except
* that the AF_ type in the link-layer header is in network byte order.
*
* DLT_LOOP is 12 in OpenBSD, but that's DLT_RAW in other OSes, so
* we don't use 12 for it in OSes other than OpenBSD.
*/
#ifdef __OpenBSD__
#define DLT_LOOP 12
#else
#define DLT_LOOP 108
#endif
/*
* Encapsulated packets for IPsec; DLT_ENC is 13 in OpenBSD, but that's
* DLT_SLIP_BSDOS in NetBSD, so we don't use 13 for it in OSes other
* than OpenBSD.
*/
#ifdef __OpenBSD__
#define DLT_ENC 13
#else
#define DLT_ENC 109
#endif
/*
* Values between 110 and 112 are reserved for use in capture file headers
* as link-layer types corresponding to DLT_ types that might differ
* between platforms; don't use those values for new DLT_ types
* other than the corresponding DLT_ types.
*/
/*
* This is for Linux cooked sockets.
*/
#define DLT_LINUX_SLL 113
/*
* Apple LocalTalk hardware.
*/
#define DLT_LTALK 114
/*
* Acorn Econet.
*/
#define DLT_ECONET 115
/*
* Reserved for use with OpenBSD ipfilter.
*/
#define DLT_IPFILTER 116
/*
* OpenBSD DLT_PFLOG; DLT_PFLOG is 17 in OpenBSD, but that's DLT_LANE8023
* in SuSE 6.3, so we can't use 17 for it in capture-file headers.
*
* XXX: is there a conflict with DLT_PFSYNC 18 as well?
*/
#ifdef __OpenBSD__
#define DLT_OLD_PFLOG 17
#define DLT_PFSYNC 18
#endif
#define DLT_PFLOG 117
/*
* Registered for Cisco-internal use.
*/
#define DLT_CISCO_IOS 118
/*
* For 802.11 cards using the Prism II chips, with a link-layer
* header including Prism monitor mode information plus an 802.11
* header.
*/
#define DLT_PRISM_HEADER 119
/*
* Reserved for Aironet 802.11 cards, with an Aironet link-layer header
* (see Doug Ambrisko's FreeBSD patches).
*/
#define DLT_AIRONET_HEADER 120
/*
* Reserved for Siemens HiPath HDLC.
*/
#define DLT_HHDLC 121
/*
* This is for RFC 2625 IP-over-Fibre Channel.
*
* This is not for use with raw Fibre Channel, where the link-layer
* header starts with a Fibre Channel frame header; it's for IP-over-FC,
* where the link-layer header starts with an RFC 2625 Network_Header
* field.
*/
#define DLT_IP_OVER_FC 122
/*
* This is for Full Frontal ATM on Solaris with SunATM, with a
* pseudo-header followed by an AALn PDU.
*
* There may be other forms of Full Frontal ATM on other OSes,
* with different pseudo-headers.
*
* If ATM software returns a pseudo-header with VPI/VCI information
* (and, ideally, packet type information, e.g. signalling, ILMI,
* LANE, LLC-multiplexed traffic, etc.), it should not use
* DLT_ATM_RFC1483, but should get a new DLT_ value, so tcpdump
* and the like don't have to infer the presence or absence of a
* pseudo-header and the form of the pseudo-header.
*/
#define DLT_SUNATM 123 /* Solaris+SunATM */
/*
* Reserved as per request from Kent Dahlgren <kent@praesum.com>
* for private use.
*/
#define DLT_RIO 124 /* RapidIO */
#define DLT_PCI_EXP 125 /* PCI Express */
#define DLT_AURORA 126 /* Xilinx Aurora link layer */
/*
* Header for 802.11 plus a number of bits of link-layer information
* including radio information, used by some recent BSD drivers as
* well as the madwifi Atheros driver for Linux.
*/
#define DLT_IEEE802_11_RADIO 127 /* 802.11 plus radiotap radio header */
/*
* Reserved for the TZSP encapsulation, as per request from
* Chris Waters <chris.waters@networkchemistry.com>
* TZSP is a generic encapsulation for any other link type,
* which includes a means to include meta-information
* with the packet, e.g. signal strength and channel
* for 802.11 packets.
*/
#define DLT_TZSP 128 /* Tazmen Sniffer Protocol */
/*
* BSD's ARCNET headers have the source host, destination host,
* and type at the beginning of the packet; that's what's handed
* up to userland via BPF.
*
* Linux's ARCNET headers, however, have a 2-byte offset field
* between the host IDs and the type; that's what's handed up
* to userland via PF_PACKET sockets.
*
* We therefore have to have separate DLT_ values for them.
*/
#define DLT_ARCNET_LINUX 129 /* ARCNET */
/*
* Juniper-private data link types, as per request from
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
* for passing on chassis-internal metainformation such as
* QOS profiles, etc..
*/
#define DLT_JUNIPER_MLPPP 130
#define DLT_JUNIPER_MLFR 131
#define DLT_JUNIPER_ES 132
#define DLT_JUNIPER_GGSN 133
#define DLT_JUNIPER_MFR 134
#define DLT_JUNIPER_ATM2 135
#define DLT_JUNIPER_SERVICES 136
#define DLT_JUNIPER_ATM1 137
/*
* Apple IP-over-IEEE 1394, as per a request from Dieter Siegmund
* <dieter@apple.com>. The header that's presented is an Ethernet-like
* header:
*
* #define FIREWIRE_EUI64_LEN 8
* struct firewire_header {
* u_char firewire_dhost[FIREWIRE_EUI64_LEN];
* u_char firewire_shost[FIREWIRE_EUI64_LEN];
* u_short firewire_type;
* };
*
* with "firewire_type" being an Ethernet type value, rather than,
* for example, raw GASP frames being handed up.
*/
#define DLT_APPLE_IP_OVER_IEEE1394 138
/*
* Various SS7 encapsulations, as per a request from Jeff Morriss
* <jeff.morriss[AT]ulticom.com> and subsequent discussions.
*/
#define DLT_MTP2_WITH_PHDR 139 /* pseudo-header with various info, followed by MTP2 */
#define DLT_MTP2 140 /* MTP2, without pseudo-header */
#define DLT_MTP3 141 /* MTP3, without pseudo-header or MTP2 */
#define DLT_SCCP 142 /* SCCP, without pseudo-header or MTP2 or MTP3 */
/*
* DOCSIS MAC frames.
*/
#define DLT_DOCSIS 143
/*
* Linux-IrDA packets. Protocol defined at http://www.irda.org.
* Those packets include IrLAP headers and above (IrLMP...), but
* don't include Phy framing (SOF/EOF/CRC & byte stuffing), because Phy
* framing can be handled by the hardware and depend on the bitrate.
* This is exactly the format you would get capturing on a Linux-IrDA
* interface (irdaX), but not on a raw serial port.
* Note the capture is done in "Linux-cooked" mode, so each packet include
* a fake packet header (struct sll_header). This is because IrDA packet
* decoding is dependant on the direction of the packet (incomming or
* outgoing).
* When/if other platform implement IrDA capture, we may revisit the
* issue and define a real DLT_IRDA...
* Jean II
*/
#define DLT_LINUX_IRDA 144
/*
* Reserved for IBM SP switch and IBM Next Federation switch.
*/
#define DLT_IBM_SP 145
#define DLT_IBM_SN 146
/*
* Reserved for private use. If you have some link-layer header type
* that you want to use within your organization, with the capture files
* using that link-layer header type not ever be sent outside your
* organization, you can use these values.
*
* No libpcap release will use these for any purpose, nor will any
* tcpdump release use them, either.
*
* Do *NOT* use these in capture files that you expect anybody not using
* your private versions of capture-file-reading tools to read; in
* particular, do *NOT* use them in products, otherwise you may find that
* people won't be able to use tcpdump, or snort, or Ethereal, or... to
* read capture files from your firewall/intrusion detection/traffic
* monitoring/etc. appliance, or whatever product uses that DLT_ value,
* and you may also find that the developers of those applications will
* not accept patches to let them read those files.
*
* Also, do not use them if somebody might send you a capture using them
* for *their* private type and tools using them for *your* private type
* would have to read them.
*
* Instead, ask "tcpdump-workers@lists.tcpdump.org" for a new DLT_ value,
* as per the comment above, and use the type you're given.
*/
#define DLT_USER0 147
#define DLT_USER1 148
#define DLT_USER2 149
#define DLT_USER3 150
#define DLT_USER4 151
#define DLT_USER5 152
#define DLT_USER6 153
#define DLT_USER7 154
#define DLT_USER8 155
#define DLT_USER9 156
#define DLT_USER10 157
#define DLT_USER11 158
#define DLT_USER12 159
#define DLT_USER13 160
#define DLT_USER14 161
#define DLT_USER15 162
/*
* For future use with 802.11 captures - defined by AbsoluteValue
* Systems to store a number of bits of link-layer information
* including radio information:
*
* http://www.shaftnet.org/~pizza/software/capturefrm.txt
*
* but it might be used by some non-AVS drivers now or in the
* future.
*/
#define DLT_IEEE802_11_RADIO_AVS 163 /* 802.11 plus AVS radio header */
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
* for passing on chassis-internal metainformation such as
* QOS profiles, etc..
*/
#define DLT_JUNIPER_MONITOR 164
/*
* Reserved for BACnet MS/TP.
*/
#define DLT_BACNET_MS_TP 165
/*
* Another PPP variant as per request from Karsten Keil <kkeil@suse.de>.
*
* This is used in some OSes to allow a kernel socket filter to distinguish
* between incoming and outgoing packets, on a socket intended to
* supply pppd with outgoing packets so it can do dial-on-demand and
* hangup-on-lack-of-demand; incoming packets are filtered out so they
* don't cause pppd to hold the connection up (you don't want random
* input packets such as port scans, packets from old lost connections,
* etc. to force the connection to stay up).
*
* The first byte of the PPP header (0xff03) is modified to accomodate
* the direction - 0x00 = IN, 0x01 = OUT.
*/
#define DLT_PPP_PPPD 166
/*
* Names for backwards compatibility with older versions of some PPP
* software; new software should use DLT_PPP_PPPD.
*/
#define DLT_PPP_WITH_DIRECTION DLT_PPP_PPPD
#define DLT_LINUX_PPP_WITHDIRECTION DLT_PPP_PPPD
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>. The DLT_s are used
* for passing on chassis-internal metainformation such as
* QOS profiles, cookies, etc..
*/
#define DLT_JUNIPER_PPPOE 167
#define DLT_JUNIPER_PPPOE_ATM 168
#define DLT_GPRS_LLC 169 /* GPRS LLC */
#define DLT_GPF_T 170 /* GPF-T (ITU-T G.7041/Y.1303) */
#define DLT_GPF_F 171 /* GPF-F (ITU-T G.7041/Y.1303) */
/*
* Requested by Oolan Zimmer <oz@gcom.com> for use in Gcom's T1/E1 line
* monitoring equipment.
*/
#define DLT_GCOM_T1E1 172
#define DLT_GCOM_SERIAL 173
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>. The DLT_ is used
* for internal communication to Physical Interface Cards (PIC)
*/
#define DLT_JUNIPER_PIC_PEER 174
/*
* Link types requested by Gregor Maier <gregor@endace.com> of Endace
* Measurement Systems. They add an ERF header (see
* http://www.endace.com/support/EndaceRecordFormat.pdf) in front of
* the link-layer header.
*/
#define DLT_ERF_ETH 175 /* Ethernet */
#define DLT_ERF_POS 176 /* Packet-over-SONET */
/*
* Requested by Daniele Orlandi <daniele@orlandi.com> for raw LAPD
* for vISDN (http://www.orlandi.com/visdn/). Its link-layer header
* includes additional information before the LAPD header, so it's
* not necessarily a generic LAPD header.
*/
#define DLT_LINUX_LAPD 177
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ are used for prepending meta-information
* like interface index, interface name
* before standard Ethernet, PPP, Frelay & C-HDLC Frames
*/
#define DLT_JUNIPER_ETHER 178
#define DLT_JUNIPER_PPP 179
#define DLT_JUNIPER_FRELAY 180
#define DLT_JUNIPER_CHDLC 181
/*
* Multi Link Frame Relay (FRF.16)
*/
#define DLT_MFR 182
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for internal communication with a
* voice Adapter Card (PIC)
*/
#define DLT_JUNIPER_VP 183
/*
* Arinc 429 frames.
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
* Every frame contains a 32bit A429 label.
* More documentation on Arinc 429 can be found at
* http://www.condoreng.com/support/downloads/tutorials/ARINCTutorial.pdf
*/
#define DLT_A429 184
/*
* Arinc 653 Interpartition Communication messages.
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
* Please refer to the A653-1 standard for more information.
*/
#define DLT_A653_ICM 185
/*
* USB packets, beginning with a USB setup header; requested by
* Paolo Abeni <paolo.abeni@email.it>.
*/
#define DLT_USB 186
/*
* Bluetooth HCI UART transport layer (part H:4); requested by
* Paolo Abeni.
*/
#define DLT_BLUETOOTH_HCI_H4 187
/*
* IEEE 802.16 MAC Common Part Sublayer; requested by Maria Cruz
* <cruz_petagay@bah.com>.
*/
#define DLT_IEEE802_16_MAC_CPS 188
/*
* USB packets, beginning with a Linux USB header; requested by
* Paolo Abeni <paolo.abeni@email.it>.
*/
#define DLT_USB_LINUX 189
/*
* Controller Area Network (CAN) v. 2.0B packets.
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
* Used to dump CAN packets coming from a CAN Vector board.
* More documentation on the CAN v2.0B frames can be found at
* http://www.can-cia.org/downloads/?269
*/
#define DLT_CAN20B 190
/*
* IEEE 802.15.4, with address fields padded, as is done by Linux
* drivers; requested by Juergen Schimmer.
*/
#define DLT_IEEE802_15_4_LINUX 191
/*
* Per Packet Information encapsulated packets.
* DLT_ requested by Gianluca Varenni <gianluca.varenni@cacetech.com>.
*/
#define DLT_PPI 192
/*
* Header for 802.16 MAC Common Part Sublayer plus a radiotap radio header;
* requested by Charles Clancy.
*/
#define DLT_IEEE802_16_MAC_CPS_RADIO 193
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for internal communication with a
* integrated service module (ISM).
*/
#define DLT_JUNIPER_ISM 194
/*
* IEEE 802.15.4, exactly as it appears in the spec (no padding, no
* nothing); requested by Mikko Saarnivala <mikko.saarnivala@sensinode.com>.
*/
#define DLT_IEEE802_15_4 195
/*
* Various link-layer types, with a pseudo-header, for SITA
* (http://www.sita.aero/); requested by Fulko Hew (fulko.hew@gmail.com).
*/
#define DLT_SITA 196
/*
* Various link-layer types, with a pseudo-header, for Endace DAG cards;
* encapsulates Endace ERF records. Requested by Stephen Donnelly
* <stephen@endace.com>.
*/
#define DLT_ERF 197
/*
* Special header prepended to Ethernet packets when capturing from a
* u10 Networks board. Requested by Phil Mulholland
* <phil@u10networks.com>.
*/
#define DLT_RAIF1 198
/*
* IPMB packet for IPMI, beginning with the I2C slave address, followed
* by the netFn and LUN, etc.. Requested by Chanthy Toeung
* <chanthy.toeung@ca.kontron.com>.
*/
#define DLT_IPMB 199
/*
* Juniper-private data link type, as per request from
* Hannes Gredler <hannes@juniper.net>.
* The DLT_ is used for capturing data on a secure tunnel interface.
*/
#define DLT_JUNIPER_ST 200
/*
* Bluetooth HCI UART transport layer (part H:4), with pseudo-header
* that includes direction information; requested by Paolo Abeni.
*/
#define DLT_BLUETOOTH_HCI_H4_WITH_PHDR 201
/*
* AX.25 packet with a 1-byte KISS header; see
*
* http://www.ax25.net/kiss.htm
*
* as per Richard Stearn <richard@rns-stearn.demon.co.uk>.
*/
#define DLT_AX25_KISS 202
/*
* LAPD packets from an ISDN channel, starting with the address field,
* with no pseudo-header.
* Requested by Varuna De Silva <varunax@gmail.com>.
*/
#define DLT_LAPD 203
/*
* Variants of various link-layer headers, with a one-byte direction
* pseudo-header prepended - zero means "received by this host",
* non-zero (any non-zero value) means "sent by this host" - as per
* Will Barker <w.barker@zen.co.uk>.
*/
#define DLT_PPP_WITH_DIR 204 /* PPP - don't confuse with DLT_PPP_WITH_DIRECTION */
#define DLT_C_HDLC_WITH_DIR 205 /* Cisco HDLC */
#define DLT_FRELAY_WITH_DIR 206 /* Frame Relay */
#define DLT_LAPB_WITH_DIR 207 /* LAPB */
/*
* 208 is reserved for an as-yet-unspecified proprietary link-layer
* type, as requested by Will Barker.
*/
/*
* IPMB with a Linux-specific pseudo-header; as requested by Alexey Neyman
* <avn@pigeonpoint.com>.
*/
#define DLT_IPMB_LINUX 209
/*
* FlexRay automotive bus - http://www.flexray.com/ - as requested
* by Hannes Kaelber <hannes.kaelber@x2e.de>.
*/
#define DLT_FLEXRAY 210
/*
* Media Oriented Systems Transport (MOST) bus for multimedia
* transport - http://www.mostcooperation.com/ - as requested
* by Hannes Kaelber <hannes.kaelber@x2e.de>.
*/
#define DLT_MOST 211
/*
* Local Interconnect Network (LIN) bus for vehicle networks -
* http://www.lin-subbus.org/ - as requested by Hannes Kaelber
* <hannes.kaelber@x2e.de>.
*/
#define DLT_LIN 212
/*
* X2E-private data link type used for serial line capture,
* as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
*/
#define DLT_X2E_SERIAL 213
/*
* X2E-private data link type used for the Xoraya data logger
* family, as requested by Hannes Kaelber <hannes.kaelber@x2e.de>.
*/
#define DLT_X2E_XORAYA 214
/*
* IEEE 802.15.4, exactly as it appears in the spec (no padding, no
* nothing), but with the PHY-level data for non-ASK PHYs (4 octets
* of 0 as preamble, one octet of SFD, one octet of frame length+
* reserved bit, and then the MAC-layer data, starting with the
* frame control field).
*
* Requested by Max Filippov <jcmvbkbc@gmail.com>.
*/
#define DLT_IEEE802_15_4_NONASK_PHY 215
/*
* DLT and savefile link type values are split into a class and
* a member of that class. A class value of 0 indicates a regular
* DLT_/LINKTYPE_ value.
*/
#define DLT_CLASS(x) ((x) & 0x03ff0000)
/*
* NetBSD-specific generic "raw" link type. The class value indicates
* that this is the generic raw type, and the lower 16 bits are the
* address family we're dealing with. Those values are NetBSD-specific;
* do not assume that they correspond to AF_ values for your operating
* system.
*/
#define DLT_CLASS_NETBSD_RAWAF 0x02240000
#define DLT_NETBSD_RAWAF(af) (DLT_CLASS_NETBSD_RAWAF | (af))
#define DLT_NETBSD_RAWAF_AF(x) ((x) & 0x0000ffff)
#define DLT_IS_NETBSD_RAWAF(x) (DLT_CLASS(x) == DLT_CLASS_NETBSD_RAWAF)
/*
* The instruction encodings.
*/
/* instruction classes */
#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
/* 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
/*
* The instruction data structure.
*/
struct bpf_insn {
u_short code;
u_char jt;
u_char jf;
bpf_u_int32 k;
};
/*
* Macros for insn array initializers.
*/
#define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
#define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
#if __STDC__ || defined(__cplusplus)
extern int bpf_validate(const struct bpf_insn *, int);
extern u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
#else
extern int bpf_validate();
extern u_int bpf_filter();
#endif
/*
* Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
*/
#define BPF_MEMWORDS 16
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 1994, 1996
* The Regents of the University of California. All rights reserved.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/namedb.h,v 1.1 2006/10/04 18:09:22 guy Exp $ (LBL)
*/
#ifndef lib_pcap_namedb_h
#define lib_pcap_namedb_h
#ifdef __cplusplus
extern "C" {
#endif
/*
* As returned by the pcap_next_etherent()
* XXX this stuff doesn't belong in this interface, but this
* library already must do name to address translation, so
* on systems that don't have support for /etc/ethers, we
* export these hooks since they'll
*/
struct pcap_etherent {
u_char addr[6];
char name[122];
};
#ifndef PCAP_ETHERS_FILE
#define PCAP_ETHERS_FILE "/etc/ethers"
#endif
struct pcap_etherent *pcap_next_etherent(FILE *);
u_char *pcap_ether_hostton(const char*);
u_char *pcap_ether_aton(const char *);
bpf_u_int32 **pcap_nametoaddr(const char *);
#ifdef INET6
struct addrinfo *pcap_nametoaddrinfo(const char *);
#endif
bpf_u_int32 pcap_nametonetaddr(const char *);
int pcap_nametoport(const char *, int *, int *);
int pcap_nametoportrange(const char *, int *, int *, int *);
int pcap_nametoproto(const char *);
int pcap_nametoeproto(const char *);
int pcap_nametollc(const char *);
/*
* If a protocol is unknown, PROTO_UNDEF is returned.
* Also, pcap_nametoport() returns the protocol along with the port number.
* If there are ambiguous entried in /etc/services (i.e. domain
* can be either tcp or udp) PROTO_UNDEF is returned.
*/
#define PROTO_UNDEF -1
/* XXX move these to pcap-int.h? */
int __pcap_atodn(const char *, bpf_u_int32 *);
int __pcap_atoin(const char *, bpf_u_int32 *);
u_short __pcap_nametodnaddr(const char *);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,407 @@
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: 1; c-basic-offset: 8; -*- */
/*
* Copyright (c) 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the Computer Systems
* Engineering Group at Lawrence Berkeley Laboratory.
* 4. Neither the name of the University nor of the Laboratory may be used
* to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/pcap.h,v 1.4.2.11 2008-10-06 15:38:39 gianluca Exp $ (LBL)
*/
#ifndef lib_pcap_pcap_h
#define lib_pcap_pcap_h
#if defined(WIN32)
#include <pcap-stdinc.h>
#elif defined(MSDOS)
#include <sys/types.h>
#include <sys/socket.h> /* u_int, u_char etc. */
#else /* UN*X */
#include <sys/types.h>
#include <sys/time.h>
#endif /* WIN32/MSDOS/UN*X */
#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
#include <pcap/bpf.h>
#endif
#include <stdio.h>
#ifdef HAVE_REMOTE
// We have to define the SOCKET here, although it has been defined in sockutils.h
// This is to avoid the distribution of the 'sockutils.h' file around
// (for example in the WinPcap developer's pack)
#ifndef SOCKET
#ifdef WIN32
#define SOCKET unsigned int
#else
#define SOCKET int
#endif
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
#define PCAP_VERSION_MAJOR 2
#define PCAP_VERSION_MINOR 4
#define PCAP_ERRBUF_SIZE 256
/*
* Compatibility for systems that have a bpf.h that
* predates the bpf typedefs for 64-bit support.
*/
#if BPF_RELEASE - 0 < 199406
typedef int bpf_int32;
typedef u_int bpf_u_int32;
#endif
typedef struct pcap pcap_t;
typedef struct pcap_dumper pcap_dumper_t;
typedef struct pcap_if pcap_if_t;
typedef struct pcap_addr pcap_addr_t;
/*
* The first record in the file contains saved values for some
* of the flags used in the printout phases of tcpdump.
* Many fields here are 32 bit ints so compilers won't insert unwanted
* padding; these files need to be interchangeable across architectures.
*
* Do not change the layout of this structure, in any way (this includes
* changes that only affect the length of fields in this structure).
*
* Also, do not change the interpretation of any of the members of this
* structure, in any way (this includes using values other than
* LINKTYPE_ values, as defined in "savefile.c", in the "linktype"
* field).
*
* Instead:
*
* introduce a new structure for the new format, if the layout
* of the structure changed;
*
* send mail to "tcpdump-workers@lists.tcpdump.org", requesting
* a new magic number for your new capture file format, and, when
* you get the new magic number, put it in "savefile.c";
*
* use that magic number for save files with the changed file
* header;
*
* make the code in "savefile.c" capable of reading files with
* the old file header as well as files with the new file header
* (using the magic number to determine the header format).
*
* Then supply the changes as a patch at
*
* http://sourceforge.net/projects/libpcap/
*
* so that future versions of libpcap and programs that use it (such as
* tcpdump) will be able to read your new capture file format.
*/
struct pcap_file_header {
bpf_u_int32 magic;
u_short version_major;
u_short version_minor;
bpf_int32 thiszone; /* gmt to local correction */
bpf_u_int32 sigfigs; /* accuracy of timestamps */
bpf_u_int32 snaplen; /* max length saved portion of each pkt */
bpf_u_int32 linktype; /* data link type (LINKTYPE_*) */
};
/*
* Macros for the value returned by pcap_datalink_ext().
*
* If LT_FCS_LENGTH_PRESENT(x) is true, the LT_FCS_LENGTH(x) macro
* gives the FCS length of packets in the capture.
*/
#define LT_FCS_LENGTH_PRESENT(x) ((x) & 0x04000000)
#define LT_FCS_LENGTH(x) (((x) & 0xF0000000) >> 28)
#define LT_FCS_DATALINK_EXT(x) ((((x) & 0xF) << 28) | 0x04000000)
typedef enum {
PCAP_D_INOUT = 0,
PCAP_D_IN,
PCAP_D_OUT
} pcap_direction_t;
/*
* Generic per-packet information, as supplied by libpcap.
*
* The time stamp can and should be a "struct timeval", regardless of
* whether your system supports 32-bit tv_sec in "struct timeval",
* 64-bit tv_sec in "struct timeval", or both if it supports both 32-bit
* and 64-bit applications. The on-disk format of savefiles uses 32-bit
* tv_sec (and tv_usec); this structure is irrelevant to that. 32-bit
* and 64-bit versions of libpcap, even if they're on the same platform,
* should supply the appropriate version of "struct timeval", even if
* that's not what the underlying packet capture mechanism supplies.
*/
struct pcap_pkthdr {
struct timeval ts; /* time stamp */
bpf_u_int32 caplen; /* length of portion present */
bpf_u_int32 len; /* length this packet (off wire) */
};
/*
* As returned by the pcap_stats()
*/
struct pcap_stat {
u_int ps_recv; /* number of packets received */
u_int ps_drop; /* number of packets dropped */
u_int ps_ifdrop; /* drops by interface XXX not yet supported */
#ifdef HAVE_REMOTE
u_int ps_capt; /* number of packets that are received by the application; please get rid off the Win32 ifdef */
u_int ps_sent; /* number of packets sent by the server on the network */
u_int ps_netdrop; /* number of packets lost on the network */
#endif /* HAVE_REMOTE */
};
#ifdef MSDOS
/*
* As returned by the pcap_stats_ex()
*/
struct pcap_stat_ex {
u_long rx_packets; /* total packets received */
u_long tx_packets; /* total packets transmitted */
u_long rx_bytes; /* total bytes received */
u_long tx_bytes; /* total bytes transmitted */
u_long rx_errors; /* bad packets received */
u_long tx_errors; /* packet transmit problems */
u_long rx_dropped; /* no space in Rx buffers */
u_long tx_dropped; /* no space available for Tx */
u_long multicast; /* multicast packets received */
u_long collisions;
/* detailed rx_errors: */
u_long rx_length_errors;
u_long rx_over_errors; /* receiver ring buff overflow */
u_long rx_crc_errors; /* recv'd pkt with crc error */
u_long rx_frame_errors; /* recv'd frame alignment error */
u_long rx_fifo_errors; /* recv'r fifo overrun */
u_long rx_missed_errors; /* recv'r missed packet */
/* detailed tx_errors */
u_long tx_aborted_errors;
u_long tx_carrier_errors;
u_long tx_fifo_errors;
u_long tx_heartbeat_errors;
u_long tx_window_errors;
};
#endif
/*
* Item in a list of interfaces.
*/
struct pcap_if {
struct pcap_if *next;
char *name; /* name to hand to "pcap_open_live()" */
char *description; /* textual description of interface, or NULL */
struct pcap_addr *addresses;
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
};
#define PCAP_IF_LOOPBACK 0x00000001 /* interface is loopback */
/*
* Representation of an interface address.
*/
struct pcap_addr {
struct pcap_addr *next;
struct sockaddr *addr; /* address */
struct sockaddr *netmask; /* netmask for that address */
struct sockaddr *broadaddr; /* broadcast address for that address */
struct sockaddr *dstaddr; /* P2P destination address for that address */
};
typedef void (*pcap_handler)(u_char *, const struct pcap_pkthdr *,
const u_char *);
/*
* Error codes for the pcap API.
* These will all be negative, so you can check for the success or
* failure of a call that returns these codes by checking for a
* negative value.
*/
#define PCAP_ERROR -1 /* generic error code */
#define PCAP_ERROR_BREAK -2 /* loop terminated by pcap_breakloop */
#define PCAP_ERROR_NOT_ACTIVATED -3 /* the capture needs to be activated */
#define PCAP_ERROR_ACTIVATED -4 /* the operation can't be performed on already activated captures */
#define PCAP_ERROR_NO_SUCH_DEVICE -5 /* no such device exists */
#define PCAP_ERROR_RFMON_NOTSUP -6 /* this device doesn't support rfmon (monitor) mode */
#define PCAP_ERROR_NOT_RFMON -7 /* operation supported only in monitor mode */
#define PCAP_ERROR_PERM_DENIED -8 /* no permission to open the device */
#define PCAP_ERROR_IFACE_NOT_UP -9 /* interface isn't up */
/*
* Warning codes for the pcap API.
* These will all be positive and non-zero, so they won't look like
* errors.
*/
#define PCAP_WARNING 1 /* generic warning code */
#define PCAP_WARNING_PROMISC_NOTSUP 2 /* this device doesn't support promiscuous mode */
char *pcap_lookupdev(char *);
int pcap_lookupnet(const char *, bpf_u_int32 *, bpf_u_int32 *, char *);
pcap_t *pcap_create(const char *, char *);
int pcap_set_snaplen(pcap_t *, int);
int pcap_set_promisc(pcap_t *, int);
int pcap_can_set_rfmon(pcap_t *);
int pcap_set_rfmon(pcap_t *, int);
int pcap_set_timeout(pcap_t *, int);
int pcap_set_buffer_size(pcap_t *, int);
int pcap_activate(pcap_t *);
pcap_t *pcap_open_live(const char *, int, int, int, char *);
pcap_t *pcap_open_dead(int, int);
pcap_t *pcap_open_offline(const char *, char *);
#if defined(WIN32)
pcap_t *pcap_hopen_offline(intptr_t, char *);
#if !defined(LIBPCAP_EXPORTS)
#define pcap_fopen_offline(f,b) \
pcap_hopen_offline(_get_osfhandle(_fileno(f)), b)
#else /*LIBPCAP_EXPORTS*/
static pcap_t *pcap_fopen_offline(FILE *, char *);
#endif
#else /*WIN32*/
pcap_t *pcap_fopen_offline(FILE *, char *);
#endif /*WIN32*/
void pcap_close(pcap_t *);
int pcap_loop(pcap_t *, int, pcap_handler, u_char *);
int pcap_dispatch(pcap_t *, int, pcap_handler, u_char *);
const u_char*
pcap_next(pcap_t *, struct pcap_pkthdr *);
int pcap_next_ex(pcap_t *, struct pcap_pkthdr **, const u_char **);
void pcap_breakloop(pcap_t *);
int pcap_stats(pcap_t *, struct pcap_stat *);
int pcap_setfilter(pcap_t *, struct bpf_program *);
int pcap_setdirection(pcap_t *, pcap_direction_t);
int pcap_getnonblock(pcap_t *, char *);
int pcap_setnonblock(pcap_t *, int, char *);
int pcap_inject(pcap_t *, const void *, size_t);
int pcap_sendpacket(pcap_t *, const u_char *, int);
const char *pcap_statustostr(int);
const char *pcap_strerror(int);
char *pcap_geterr(pcap_t *);
void pcap_perror(pcap_t *, char *);
int pcap_compile(pcap_t *, struct bpf_program *, const char *, int,
bpf_u_int32);
int pcap_compile_nopcap(int, int, struct bpf_program *,
const char *, int, bpf_u_int32);
void pcap_freecode(struct bpf_program *);
int pcap_offline_filter(struct bpf_program *, const struct pcap_pkthdr *,
const u_char *);
int pcap_datalink(pcap_t *);
int pcap_datalink_ext(pcap_t *);
int pcap_list_datalinks(pcap_t *, int **);
int pcap_set_datalink(pcap_t *, int);
void pcap_free_datalinks(int *);
int pcap_datalink_name_to_val(const char *);
const char *pcap_datalink_val_to_name(int);
const char *pcap_datalink_val_to_description(int);
int pcap_snapshot(pcap_t *);
int pcap_is_swapped(pcap_t *);
int pcap_major_version(pcap_t *);
int pcap_minor_version(pcap_t *);
/* XXX */
FILE *pcap_file(pcap_t *);
int pcap_fileno(pcap_t *);
pcap_dumper_t *pcap_dump_open(pcap_t *, const char *);
pcap_dumper_t *pcap_dump_fopen(pcap_t *, FILE *fp);
FILE *pcap_dump_file(pcap_dumper_t *);
long pcap_dump_ftell(pcap_dumper_t *);
int pcap_dump_flush(pcap_dumper_t *);
void pcap_dump_close(pcap_dumper_t *);
void pcap_dump(u_char *, const struct pcap_pkthdr *, const u_char *);
int pcap_findalldevs(pcap_if_t **, char *);
void pcap_freealldevs(pcap_if_t *);
const char *pcap_lib_version(void);
/* XXX this guy lives in the bpf tree */
u_int bpf_filter(const struct bpf_insn *, const u_char *, u_int, u_int);
int bpf_validate(const struct bpf_insn *f, int len);
char *bpf_image(const struct bpf_insn *, int);
void bpf_dump(const struct bpf_program *, int);
#if defined(WIN32)
/*
* Win32 definitions
*/
int pcap_setbuff(pcap_t *p, int dim);
int pcap_setmode(pcap_t *p, int mode);
int pcap_setmintocopy(pcap_t *p, int size);
#ifdef WPCAP
/* Include file with the wpcap-specific extensions */
#include <Win32-Extensions.h>
#endif /* WPCAP */
#define MODE_CAPT 0
#define MODE_STAT 1
#define MODE_MON 2
#elif defined(MSDOS)
/*
* MS-DOS definitions
*/
int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
u_long pcap_mac_packets (void);
#else /* UN*X */
/*
* UN*X definitions
*/
int pcap_get_selectable_fd(pcap_t *);
#endif /* WIN32/MSDOS/UN*X */
#ifdef HAVE_REMOTE
/* Includes most of the public stuff that is needed for the remote capture */
#include <remote-ext.h>
#endif /* HAVE_REMOTE */
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,129 @@
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* This code is derived from the Stanford/CMU enet packet filter,
* (net/enet.c) distributed as part of 4.3BSD, and code contributed
* to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
* Berkeley Laboratory.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/sll.h,v 1.2.2.1 2008-05-30 01:36:06 guy Exp $ (LBL)
*/
/*
* For captures on Linux cooked sockets, we construct a fake header
* that includes:
*
* a 2-byte "packet type" which is one of:
*
* LINUX_SLL_HOST packet was sent to us
* LINUX_SLL_BROADCAST packet was broadcast
* LINUX_SLL_MULTICAST packet was multicast
* LINUX_SLL_OTHERHOST packet was sent to somebody else
* LINUX_SLL_OUTGOING packet was sent *by* us;
*
* a 2-byte Ethernet protocol field;
*
* a 2-byte link-layer type;
*
* a 2-byte link-layer address length;
*
* an 8-byte source link-layer address, whose actual length is
* specified by the previous value.
*
* All fields except for the link-layer address are in network byte order.
*
* DO NOT change the layout of this structure, or change any of the
* LINUX_SLL_ values below. If you must change the link-layer header
* for a "cooked" Linux capture, introduce a new DLT_ type (ask
* "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it
* a value that collides with a value already being used), and use the
* new header in captures of that type, so that programs that can
* handle DLT_LINUX_SLL captures will continue to handle them correctly
* without any change, and so that capture files with different headers
* can be told apart and programs that read them can dissect the
* packets in them.
*/
#ifndef lib_pcap_sll_h
#define lib_pcap_sll_h
/*
* A DLT_LINUX_SLL fake link-layer header.
*/
#define SLL_HDR_LEN 16 /* total header length */
#define SLL_ADDRLEN 8 /* length of address field */
struct sll_header {
u_int16_t sll_pkttype; /* packet type */
u_int16_t sll_hatype; /* link-layer address type */
u_int16_t sll_halen; /* link-layer address length */
u_int8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */
u_int16_t sll_protocol; /* protocol */
};
/*
* The LINUX_SLL_ values for "sll_pkttype"; these correspond to the
* PACKET_ values on Linux, but are defined here so that they're
* available even on systems other than Linux, and so that they
* don't change even if the PACKET_ values change.
*/
#define LINUX_SLL_HOST 0
#define LINUX_SLL_BROADCAST 1
#define LINUX_SLL_MULTICAST 2
#define LINUX_SLL_OTHERHOST 3
#define LINUX_SLL_OUTGOING 4
/*
* The LINUX_SLL_ values for "sll_protocol"; these correspond to the
* ETH_P_ values on Linux, but are defined here so that they're
* available even on systems other than Linux. We assume, for now,
* that the ETH_P_ values won't change in Linux; if they do, then:
*
* if we don't translate them in "pcap-linux.c", capture files
* won't necessarily be readable if captured on a system that
* defines ETH_P_ values that don't match these values;
*
* if we do translate them in "pcap-linux.c", that makes life
* unpleasant for the BPF code generator, as the values you test
* for in the kernel aren't the values that you test for when
* reading a capture file, so the fixup code run on BPF programs
* handed to the kernel ends up having to do more work.
*
* Add other values here as necessary, for handling packet types that
* might show up on non-Ethernet, non-802.x networks. (Not all the ones
* in the Linux "if_ether.h" will, I suspect, actually show up in
* captures.)
*/
#define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */
#define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */
#endif

View File

@ -0,0 +1,90 @@
/*
* Copyright (c) 2006 Paolo Abeni (Italy)
* All rights reserved.
*
* 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 above copyright
* 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. The name of the author may not 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
* OWNER 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.
*
* Basic USB data struct
* By Paolo Abeni <paolo.abeni@email.it>
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/usb.h,v 1.6 2007/09/22 02:06:08 guy Exp $
*/
#ifndef _PCAP_USB_STRUCTS_H__
#define _PCAP_USB_STRUCTS_H__
/*
* possible transfer mode
*/
#define URB_TRANSFER_IN 0x80
#define URB_ISOCHRONOUS 0x0
#define URB_INTERRUPT 0x1
#define URB_CONTROL 0x2
#define URB_BULK 0x3
/*
* possible event type
*/
#define URB_SUBMIT 'S'
#define URB_COMPLETE 'C'
#define URB_ERROR 'E'
/*
* USB setup header as defined in USB specification.
* Appears at the front of each packet in DLT_USB captures.
*/
typedef struct _usb_setup {
u_int8_t bmRequestType;
u_int8_t bRequest;
u_int16_t wValue;
u_int16_t wIndex;
u_int16_t wLength;
} pcap_usb_setup;
/*
* Header prepended by linux kernel to each event.
* Appears at the front of each packet in DLT_USB_LINUX captures.
*/
typedef struct _usb_header {
u_int64_t id;
u_int8_t event_type;
u_int8_t transfer_type;
u_int8_t endpoint_number;
u_int8_t device_address;
u_int16_t bus_id;
char setup_flag;/*if !=0 the urb setup header is not present*/
char data_flag; /*if !=0 no urb data is present*/
int64_t ts_sec;
int32_t ts_usec;
int32_t status;
u_int32_t urb_len;
u_int32_t data_len; /* amount of urb data really present in this event*/
pcap_usb_setup setup;
} pcap_usb_header;
#endif

View File

@ -0,0 +1,46 @@
/*-
* Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
* The Regents of the University of California. All rights reserved.
*
* 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 above copyright
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*
* @(#) $Header: /tcpdump/master/libpcap/pcap/vlan.h,v 1.1.2.2 2008-08-06 07:45:59 guy Exp $
*/
#ifndef lib_pcap_vlan_h
#define lib_pcap_vlan_h
struct vlan_tag {
u_int16_t vlan_tpid; /* ETH_P_8021Q */
u_int16_t vlan_tci; /* VLAN TCI */
};
#define VLAN_TAG_LEN 4
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,419 @@
#include <stdio.h>
#include <stdarg.h>
#include "pcap.h"
#include "pcap_io.h"
#include "dev9.h"
#include "net.h"
#include <Iphlpapi.h>
enum pcap_m_e
{
switched,
bridged
};
pcap_m_e pcap_mode=switched;
mac_address virtual_mac = { 0x76, 0x6D, 0x61, 0x63, 0x30, 0x31 };
//mac_address virtual_mac = { 0x6D, 0x76, 0x63, 0x61, 0x31, 0x30 };
mac_address broadcast_mac = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
ip_address virtual_ip = { 192, 168, 1, 4};
pcap_t *adhandle;
int pcap_io_running=0;
char errbuf[PCAP_ERRBUF_SIZE];
char namebuff[256];
FILE*packet_log;
pcap_dumper_t *dump_pcap;
mac_address host_mac = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
// Fetches the MAC address and prints it
int GetMACAddress(char *adapter, mac_address* addr)
{
static IP_ADAPTER_INFO AdapterInfo[128]; // Allocate information
// for up to 128 NICs
static PIP_ADAPTER_INFO pAdapterInfo;
ULONG dwBufLen = sizeof(AdapterInfo); // Save memory size of buffer
DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
AdapterInfo, // [out] buffer to receive data
&dwBufLen); // [in] size of receive data buffer
if(dwStatus != ERROR_SUCCESS) // Verify return value is
return 0; // valid, no buffer overflow
pAdapterInfo = AdapterInfo; // Contains pointer to
// current adapter info
do {
if(strcmp(pAdapterInfo->AdapterName,adapter+12)==0)
{
memcpy(addr,pAdapterInfo->Address,6);
return 1;
}
pAdapterInfo = pAdapterInfo->Next; // Progress through
}
while(pAdapterInfo); // Terminate if last adapter
return 0;
}
int pcap_io_init(char *adapter)
{
int dlt;
char *dlt_name;
emu_printf("Opening adapter '%s'...",adapter);
GetMACAddress(adapter,&host_mac);
/* Open the adapter */
if ((adhandle= pcap_open_live(adapter, // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs.
pcap_mode==switched?1:0, // promiscuous mode (nonzero means promiscuous)
1, // read timeout
errbuf // error buffer
)) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n", adapter);
return -1;
}
dlt = pcap_datalink(adhandle);
dlt_name = (char*)pcap_datalink_val_to_name(dlt);
fprintf(stderr,"Device uses DLT %d: %s\n",dlt,dlt_name);
switch(dlt)
{
case DLT_EN10MB :
//case DLT_IEEE802_11:
break;
default:
SysMessage("ERROR: Unsupported DataLink Type (%d): %s",dlt,dlt_name);
pcap_close(adhandle);
return -1;
}
if(pcap_setnonblock(adhandle,1,errbuf)==-1)
{
fprintf(stderr,"WARNING: Error setting non-blocking mode. Default mode will be used.\n");
}
packet_log=fopen("logs/packet.log","w");
dump_pcap = pcap_dump_open(adhandle,"logs/pkt_log.pcap");
pcap_io_running=1;
emu_printf("Ok.\n");
return 0;
}
int gettimeofday (struct timeval *tv, void* tz)
{
unsigned __int64 ns100; /*time since 1 Jan 1601 in 100ns units */
GetSystemTimeAsFileTime((LPFILETIME)&ns100);
tv->tv_usec = (long) ((ns100 / 10L) % 1000000L);
tv->tv_sec = (long) ((ns100 - 116444736000000000L) / 10000000L);
return (0);
}
int pcap_io_send(void* packet, int plen)
{
struct pcap_pkthdr ph;
if(pcap_io_running<=0)
return -1;
emu_printf(" * pcap io: Sending %d byte packet.\n",plen);
if (pcap_mode==bridged)
{
if(((ethernet_header*)packet)->protocol == 0x0008) //IP
{
#ifndef PLOT_VERSION
virtual_ip = ((ip_header*)((u8*)packet+sizeof(ethernet_header)))->src;
#endif
virtual_mac = ((ethernet_header*)packet)->src;
}
if(((ethernet_header*)packet)->protocol == 0x0608) //ARP
{
#ifndef PLOT_VERSION
virtual_ip = ((arp_packet*)((u8*)packet+sizeof(ethernet_header)))->p_src;
#endif
virtual_mac = ((ethernet_header*)packet)->src;
((arp_packet*)((u8*)packet+sizeof(ethernet_header)))->h_src = host_mac;
}
((ethernet_header*)packet)->src = host_mac;
}
if(dump_pcap)
{
gettimeofday(&ph.ts,NULL);
ph.caplen=plen;
ph.len=plen;
pcap_dump((u_char*)dump_pcap,&ph,(u_char*)packet);
}
if(packet_log)
{
int i=0;
int n=0;
fprintf(packet_log,"PACKET SEND: %d BYTES\n",plen);
for(i=0,n=0;i<plen;i++)
{
fprintf(packet_log,"%02x",((unsigned char*)packet)[i]);
n++;
if(n==16)
{
fprintf(packet_log,"\n");
n=0;
}
else
fprintf(packet_log," ");
}
fprintf(packet_log,"\n");
}
if (pcap_mode==switched)
{
if(mac_compare(((ethernet_header*)packet)->dst,broadcast_mac)==0)
{
static char pack[65536];
memcpy(pack,packet,plen);
((ethernet_header*)packet)->dst=host_mac;
pcap_sendpacket(adhandle, (u_char*)pack, plen);
}
}
return pcap_sendpacket(adhandle, (u_char*)packet, plen);
}
int pcap_io_recv(void* packet, int max_len)
{
int res;
struct pcap_pkthdr *header;
const u_char *pkt_data1;
static u_char pkt_data[32768];
if(pcap_io_running<=0)
return -1;
if((res = pcap_next_ex(adhandle, &header, &pkt_data1)) > 0)
{
ethernet_header *ph=(ethernet_header*)pkt_data;
memcpy(pkt_data,pkt_data1,header->len);
if (pcap_mode==bridged)
{
if(((ethernet_header*)pkt_data)->protocol == 0x0008)
{
ip_header *iph=((ip_header*)((u8*)pkt_data+sizeof(ethernet_header)));
if(ip_compare(iph->dst,virtual_ip)==0)
{
((ethernet_header*)pkt_data)->dst = virtual_mac;
}
}
if(((ethernet_header*)pkt_data)->protocol == 0x0608)
{
arp_packet *aph=((arp_packet*)((u8*)pkt_data+sizeof(ethernet_header)));
if(ip_compare(aph->p_dst,virtual_ip)==0)
{
((ethernet_header*)pkt_data)->dst = virtual_mac;
((arp_packet*)((u8*)packet+sizeof(ethernet_header)))->h_dst = virtual_mac;
}
}
}
if((memcmp(pkt_data,dev9.eeprom,6)!=0)&&(memcmp(pkt_data,&broadcast_mac,6)!=0))
{
//ignore strange packets
return 0;
}
if(memcmp(pkt_data+6,dev9.eeprom,6)==0)
{
//avoid pcap looping packets
return 0;
}
memcpy(packet,pkt_data,header->len);
if(dump_pcap)
pcap_dump((u_char*)dump_pcap,header,(u_char*)packet);
if(packet_log)
{
int i=0;
int n=0;
int plen=header->len;
fprintf(packet_log,"PACKET RECV: %d BYTES\n",plen);
for(i=0,n=0;i<plen;i++)
{
fprintf(packet_log,"%02x",((unsigned char*)packet)[i]);
n++;
if(n==16)
{
fprintf(packet_log,"\n");
n=0;
}
else
fprintf(packet_log," ");
}
fprintf(packet_log,"\n");
}
return header->len;
}
return -1;
}
void pcap_io_close()
{
if(packet_log)
fclose(packet_log);
if(dump_pcap)
pcap_dump_close(dump_pcap);
pcap_close(adhandle);
pcap_io_running=0;
}
int pcap_io_get_dev_num()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
if(pcap_findalldevs(&alldevs, errbuf) == -1)
{
return 0;
}
d=alldevs;
while(d!=NULL) {d=d->next; i++;}
pcap_freealldevs(alldevs);
return i;
}
char* pcap_io_get_dev_name(int num,int md)
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
if(pcap_findalldevs(&alldevs, errbuf) == -1)
{
return NULL;
}
d=alldevs;
while(d!=NULL) {
if(num==i)
{
if (!md)
strcpy(namebuff,"pcap switch:");
else
strcpy(namebuff,"pcap bridge:");
strcat(namebuff,d->name);
pcap_freealldevs(alldevs);
return namebuff;
}
d=d->next; i++;
}
pcap_freealldevs(alldevs);
return NULL;
}
char* pcap_io_get_dev_desc(int num,int md)
{
pcap_if_t *alldevs;
pcap_if_t *d;
int i=0;
if(pcap_findalldevs(&alldevs, errbuf) == -1)
{
return NULL;
}
d=alldevs;
while(d!=NULL) {
if(num==i)
{
if (!md)
strcpy(namebuff,"pcap switch:");
else
strcpy(namebuff,"pcap bridge:");
strcat(namebuff,d->description);
pcap_freealldevs(alldevs);
return namebuff;
}
d=d->next; i++;
}
pcap_freealldevs(alldevs);
return NULL;
}
PCAPAdapter::PCAPAdapter()
{
//if (config.ethEnable == 0) return; //whut? nada!
if (config.Eth[5]=='s')
pcap_mode=switched;
else
pcap_mode=bridged;
if (pcap_io_init(config.Eth+12) == -1) {
SysMessage("Can't open Device '%s'\n", config.Eth);
}
}
bool PCAPAdapter::blocks()
{
return false;
}
//gets a packet.rv :true success
bool PCAPAdapter::recv(NetPacket* pkt)
{
int size=pcap_io_recv(pkt->buffer,sizeof(pkt->buffer));
if(size<=0)
{
return false;
}
else
{
pkt->size=size;
return true;
}
}
//sends the packet .rv :true success
bool PCAPAdapter::send(NetPacket* pkt)
{
if(pcap_io_send(pkt->buffer,pkt->size))
{
return false;
}
else
{
return true;
}
}
PCAPAdapter::~PCAPAdapter()
{
pcap_io_close();
}

View File

@ -0,0 +1,444 @@
/*
* Copyright (c) 2002 - 2003
* NetGroup, Politecnico di Torino (Italy)
* All rights reserved.
*
* 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 above copyright
* 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 Politecnico di Torino 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
* OWNER 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.
*
*/
#ifndef __REMOTE_EXT_H__
#define __REMOTE_EXT_H__
#ifndef HAVE_REMOTE
#error Please do not include this file directly. Just define HAVE_REMOTE and then include pcap.h
#endif
// Definition for Microsoft Visual Studio
#if _MSC_VER > 1000
#pragma once
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*!
\file remote-ext.h
The goal of this file it to include most of the new definitions that should be
placed into the pcap.h file.
It includes all new definitions (structures and functions like pcap_open().
Some of the functions are not really a remote feature, but, right now,
they are placed here.
*/
// All this stuff is public
/*! \addtogroup remote_struct
\{
*/
/*!
\brief Defines the maximum buffer size in which address, port, interface names are kept.
In case the adapter name or such is larger than this value, it is truncated.
This is not used by the user; however it must be aware that an hostname / interface
name longer than this value will be truncated.
*/
#define PCAP_BUF_SIZE 1024
/*! \addtogroup remote_source_ID
\{
*/
/*!
\brief Internal representation of the type of source in use (file,
remote/local interface).
This indicates a file, i.e. the user want to open a capture from a local file.
*/
#define PCAP_SRC_FILE 2
/*!
\brief Internal representation of the type of source in use (file,
remote/local interface).
This indicates a local interface, i.e. the user want to open a capture from
a local interface. This does not involve the RPCAP protocol.
*/
#define PCAP_SRC_IFLOCAL 3
/*!
\brief Internal representation of the type of source in use (file,
remote/local interface).
This indicates a remote interface, i.e. the user want to open a capture from
an interface on a remote host. This does involve the RPCAP protocol.
*/
#define PCAP_SRC_IFREMOTE 4
/*!
\}
*/
/*! \addtogroup remote_source_string
The formats allowed by the pcap_open() are the following:
- file://path_and_filename [opens a local file]
- rpcap://devicename [opens the selected device devices available on the local host, without using the RPCAP protocol]
- rpcap://host/devicename [opens the selected device available on a remote host]
- rpcap://host:port/devicename [opens the selected device available on a remote host, using a non-standard port for RPCAP]
- adaptername [to open a local adapter; kept for compability, but it is strongly discouraged]
- (NULL) [to open the first local adapter; kept for compability, but it is strongly discouraged]
The formats allowed by the pcap_findalldevs_ex() are the following:
- file://folder/ [lists all the files in the given folder]
- rpcap:// [lists all local adapters]
- rpcap://host:port/ [lists the devices available on a remote host]
Referring to the 'host' and 'port' paramters, they can be either numeric or literal. Since
IPv6 is fully supported, these are the allowed formats:
- host (literal): e.g. host.foo.bar
- host (numeric IPv4): e.g. 10.11.12.13
- host (numeric IPv4, IPv6 style): e.g. [10.11.12.13]
- host (numeric IPv6): e.g. [1:2:3::4]
- port: can be either numeric (e.g. '80') or literal (e.g. 'http')
Here you find some allowed examples:
- rpcap://host.foo.bar/devicename [everything literal, no port number]
- rpcap://host.foo.bar:1234/devicename [everything literal, with port number]
- rpcap://10.11.12.13/devicename [IPv4 numeric, no port number]
- rpcap://10.11.12.13:1234/devicename [IPv4 numeric, with port number]
- rpcap://[10.11.12.13]:1234/devicename [IPv4 numeric with IPv6 format, with port number]
- rpcap://[1:2:3::4]/devicename [IPv6 numeric, no port number]
- rpcap://[1:2:3::4]:1234/devicename [IPv6 numeric, with port number]
- rpcap://[1:2:3::4]:http/devicename [IPv6 numeric, with literal port number]
\{
*/
/*!
\brief String that will be used to determine the type of source in use (file,
remote/local interface).
This string will be prepended to the interface name in order to create a string
that contains all the information required to open the source.
This string indicates that the user wants to open a capture from a local file.
*/
#define PCAP_SRC_FILE_STRING "file://"
/*!
\brief String that will be used to determine the type of source in use (file,
remote/local interface).
This string will be prepended to the interface name in order to create a string
that contains all the information required to open the source.
This string indicates that the user wants to open a capture from a network interface.
This string does not necessarily involve the use of the RPCAP protocol. If the
interface required resides on the local host, the RPCAP protocol is not involved
and the local functions are used.
*/
#define PCAP_SRC_IF_STRING "rpcap://"
/*!
\}
*/
/*!
\addtogroup remote_open_flags
\{
*/
/*!
\brief Defines if the adapter has to go in promiscuous mode.
It is '1' if you have to open the adapter in promiscuous mode, '0' otherwise.
Note that even if this parameter is false, the interface could well be in promiscuous
mode for some other reason (for example because another capture process with
promiscuous mode enabled is currently using that interface).
On on Linux systems with 2.2 or later kernels (that have the "any" device), this
flag does not work on the "any" device; if an argument of "any" is supplied,
the 'promisc' flag is ignored.
*/
#define PCAP_OPENFLAG_PROMISCUOUS 1
/*!
\brief Defines if the data trasfer (in case of a remote
capture) has to be done with UDP protocol.
If it is '1' if you want a UDP data connection, '0' if you want
a TCP data connection; control connection is always TCP-based.
A UDP connection is much lighter, but it does not guarantee that all
the captured packets arrive to the client workstation. Moreover,
it could be harmful in case of network congestion.
This flag is meaningless if the source is not a remote interface.
In that case, it is simply ignored.
*/
#define PCAP_OPENFLAG_DATATX_UDP 2
/*!
\brief Defines if the remote probe will capture its own generated traffic.
In case the remote probe uses the same interface to capture traffic and to send
data back to the caller, the captured traffic includes the RPCAP traffic as well.
If this flag is turned on, the RPCAP traffic is excluded from the capture, so that
the trace returned back to the collector is does not include this traffic.
*/
#define PCAP_OPENFLAG_NOCAPTURE_RPCAP 4
/*!
\brief Defines if the local adapter will capture its own generated traffic.
This flag tells the underlying capture driver to drop the packets that were sent by itself.
This is usefult when building applications like bridges, that should ignore the traffic
they just sent.
*/
#define PCAP_OPENFLAG_NOCAPTURE_LOCAL 8
/*!
\brief This flag configures the adapter for maximum responsiveness.
In presence of a large value for nbytes, WinPcap waits for the arrival of several packets before
copying the data to the user. This guarantees a low number of system calls, i.e. lower processor usage,
i.e. better performance, which is good for applications like sniffers. If the user sets the
PCAP_OPENFLAG_MAX_RESPONSIVENESS flag, the capture driver will copy the packets as soon as the application
is ready to receive them. This is suggested for real time applications (like, for example, a bridge)
that need the best responsiveness.*/
#define PCAP_OPENFLAG_MAX_RESPONSIVENESS 16
/*!
\}
*/
/*!
\addtogroup remote_samp_methods
\{
*/
/*!
\brief No sampling has to be done on the current capture.
In this case, no sampling algorithms are applied to the current capture.
*/
#define PCAP_SAMP_NOSAMP 0
/*!
\brief It defines that only 1 out of N packets must be returned to the user.
In this case, the 'value' field of the 'pcap_samp' structure indicates the
number of packets (minus 1) that must be discarded before one packet got accepted.
In other words, if 'value = 10', the first packet is returned to the caller, while
the following 9 are discarded.
*/
#define PCAP_SAMP_1_EVERY_N 1
/*!
\brief It defines that we have to return 1 packet every N milliseconds.
In this case, the 'value' field of the 'pcap_samp' structure indicates the 'waiting
time' in milliseconds before one packet got accepted.
In other words, if 'value = 10', the first packet is returned to the caller; the next
returned one will be the first packet that arrives when 10ms have elapsed.
*/
#define PCAP_SAMP_FIRST_AFTER_N_MS 2
/*!
\}
*/
/*!
\addtogroup remote_auth_methods
\{
*/
/*!
\brief It defines the NULL authentication.
This value has to be used within the 'type' member of the pcap_rmtauth structure.
The 'NULL' authentication has to be equal to 'zero', so that old applications
can just put every field of struct pcap_rmtauth to zero, and it does work.
*/
#define RPCAP_RMTAUTH_NULL 0
/*!
\brief It defines the username/password authentication.
With this type of authentication, the RPCAP protocol will use the username/
password provided to authenticate the user on the remote machine. If the
authentication is successful (and the user has the right to open network devices)
the RPCAP connection will continue; otherwise it will be dropped.
This value has to be used within the 'type' member of the pcap_rmtauth structure.
*/
#define RPCAP_RMTAUTH_PWD 1
/*!
\}
*/
/*!
\brief This structure keeps the information needed to autheticate
the user on a remote machine.
The remote machine can either grant or refuse the access according
to the information provided.
In case the NULL authentication is required, both 'username' and
'password' can be NULL pointers.
This structure is meaningless if the source is not a remote interface;
in that case, the functions which requires such a structure can accept
a NULL pointer as well.
*/
struct pcap_rmtauth
{
/*!
\brief Type of the authentication required.
In order to provide maximum flexibility, we can support different types
of authentication based on the value of this 'type' variable. The currently
supported authentication methods are defined into the
\link remote_auth_methods Remote Authentication Methods Section\endlink.
*/
int type;
/*!
\brief Zero-terminated string containing the username that has to be
used on the remote machine for authentication.
This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
and it can be NULL.
*/
char *username;
/*!
\brief Zero-terminated string containing the password that has to be
used on the remote machine for authentication.
This field is meaningless in case of the RPCAP_RMTAUTH_NULL authentication
and it can be NULL.
*/
char *password;
};
/*!
\brief This structure defines the information related to sampling.
In case the sampling is requested, the capturing device should read
only a subset of the packets coming from the source. The returned packets depend
on the sampling parameters.
\warning The sampling process is applied <strong>after</strong> the filtering process.
In other words, packets are filtered first, then the sampling process selects a
subset of the 'filtered' packets and it returns them to the caller.
*/
struct pcap_samp
{
/*!
Method used for sampling. Currently, the supported methods are listed in the
\link remote_samp_methods Sampling Methods Section\endlink.
*/
int method;
/*!
This value depends on the sampling method defined. For its meaning, please check
at the \link remote_samp_methods Sampling Methods Section\endlink.
*/
int value;
};
//! Maximum lenght of an host name (needed for the RPCAP active mode)
#define RPCAP_HOSTLIST_SIZE 1024
/*!
\}
*/ // end of public documentation
// Exported functions
/** \name New WinPcap functions
This section lists the new functions that are able to help considerably in writing
WinPcap programs because of their easiness of use.
*/
//\{
pcap_t *pcap_open(const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *errbuf);
int pcap_createsrcstr(char *source, int type, const char *host, const char *port, const char *name, char *errbuf);
int pcap_parsesrcstr(const char *source, int *type, char *host, char *port, char *name, char *errbuf);
int pcap_findalldevs_ex(char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf);
struct pcap_samp *pcap_setsampling(pcap_t *p);
//\}
// End of new winpcap functions
/** \name Remote Capture functions
*/
//\{
SOCKET pcap_remoteact_accept(const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, char *errbuf);
int pcap_remoteact_list(char *hostlist, char sep, int size, char *errbuf);
int pcap_remoteact_close(const char *host, char *errbuf);
void pcap_remoteact_cleanup();
//\}
// End of remote capture functions
#ifdef __cplusplus
}
#endif
#endif