public WinPcapAdapter(DEV9_State parDev9, string parDevice, bool isSwitch) : base(parDev9) { switched = isSwitch; NetworkInterface hostAdapter = GetAdapterFromGuid(parDevice); if (hostAdapter == null) { if (BridgeHelper.IsInBridge(parDevice) == true) { hostAdapter = GetAdapterFromGuid(BridgeHelper.GetBridgeGUID()); } } if (hostAdapter == null) { //System.Windows.Forms.MessageBox.Show("Failed to GetAdapter"); throw new NullReferenceException("Failed to GetAdapter"); } hostMAC = hostAdapter.GetPhysicalAddress().GetAddressBytes(); //DEV9Header.config.Eth.Substring(12, DEV9Header.config.Eth.Length - 12) if (!PcapInitIO(@"\Device\NPF_" + parDevice)) { Log_Error("Can't Open Device " + DEV9Header.config.Eth); System.Windows.Forms.MessageBox.Show("Can't Open Device " + DEV9Header.config.Eth); return; } if (DEV9Header.config.DirectConnectionSettings.InterceptDHCP) { InitDHCP(hostAdapter); } }
public TAPAdapter(DEV9_State parDev9, string parDevice) : base(parDev9) { htap = TAPOpen(parDevice); htapstream = new FileStream(htap, FileAccess.ReadWrite, 16 * 1024, true); if (DEV9Header.config.DirectConnectionSettings.InterceptDHCP) { NetworkInterface hostAdapter = GetAdapterFromGuid(parDevice); if (hostAdapter == null) { if (BridgeHelper.IsInBridge(parDevice) == true) { hostAdapter = GetAdapterFromGuid(BridgeHelper.GetBridgeGUID()); } } if (hostAdapter == null) { //System.Windows.Forms.MessageBox.Show("Failed to GetAdapter"); throw new NullReferenceException("Failed to GetAdapter"); } InitDHCP(hostAdapter); } }
public ATA_State(DEV9_State parDev9) { dev9 = parDev9; //Fillout Command table (inspired from MegaDev9) //This is actully a pretty neat way of doing this for (int i = 0; i < 256; i++) { hddCmds[i] = HDD_Unk; } hddCmds[0x00] = HDD_Nop; hddCmds[0x20] = () => HDD_ReadPIO(false); hddCmds[0x91] = HDD_InitDevParameters; hddCmds[0xB0] = HDD_Smart; hddCmdDoesSeek[0xB0] = true; hddCmds[0xC8] = () => HDD_ReadDMA(false); hddCmds[0xCA] = () => HDD_WriteDMA(false); //HDDcmds[0x25] = HDDreadDMA48; /* HDDcmds[0x35] = HDDwriteDMA_ext;*/ //HDDcmdNames[0x35] = "DMA write (48-bit)"; // 48-bit hddCmds[0xE3] = HDD_Idle; hddCmds[0xE7] = HDD_FlushCache; /* HDDcmds[0xEA] = HDDflushCacheExt;*/ //HDDcmdNames[0xEA] = "flush cache (48-bit)"; // 48-bit hddCmds[0xEC] = HDD_IdentifyDevice; /* HDDcmds[0xA1] = HDDidentifyPktDevice;*/ //HDDcmdNames[0xA1] = "identify ATAPI device"; // For ATAPI devices hddCmds[0xEF] = HDD_SetFeatures; hddCmdDoesSeek[0xEF] = true; ///* HDDcmds[0xF1] = HDDsecSetPassword;*/ //HDDcmdNames[0xF1] = "security set password"; ///* HDDcmds[0xF2] = HDDsecUnlock;*/ //HDDcmdNames[0xF2] = "security unlock"; ///* HDDcmds[0xF3] = HDDsecErasePrepare;*/ //HDDcmdNames[0xF3] = "security erase prepare"; ///* HDDcmds[0xF4] = HDDsecEraseUnit;*/ //HDDcmdNames[0xF4] = "security erase unit"; /* This command is Sony-specific and isn't part of the IDE standard */ /* The Sony HDD has a modified firmware that supports this command */ /* Sending this command to a standard HDD will give an error */ /* We roughly emulate it to make programs think the HDD is a Sony one */ /* However, we only send null, if anyting checks the returned data */ /* it will fail */ hddCmds[0x8E] = HDD_sceSecCtrl; //HDDcmdNames[0x8E] = "SCE security control"; }
public WinPcapAdapter(DEV9_State parDev9, string parDevice, bool isSwitch) : base(parDev9) { switched = isSwitch; NetworkInterface hostAdapter = GetAdapterFromGuid(parDevice); if (hostAdapter == null) { if (BridgeHelper.IsInBridge(parDevice) == true) { hostAdapter = GetAdapterFromGuid(BridgeHelper.GetBridgeGUID()); } } if (hostAdapter == null) { //System.Windows.Forms.MessageBox.Show("Failed to GetAdapter"); throw new NullReferenceException("Failed to GetAdapter"); } hostMAC = hostAdapter.GetPhysicalAddress().GetAddressBytes(); //PcapInitIO needs correct MAC SetMAC(null); byte[] wMAC = (byte[])ps2MAC.Clone(); //wMAC[3] = hostMAC[3]; wMAC[5] = hostMAC[4]; wMAC[4] = hostMAC[5]; SetMAC(wMAC); //If parDevice starts with "{", assume device is given by GUID (as it would be under windows) //else, use the string as is (wine, linux) if (!PcapInitIO(parDevice.StartsWith("{") ? @"\Device\NPF_" + parDevice : parDevice)) { Log_Error("Can't Open Device " + parDevice); #if NETCOREAPP #else System.Windows.Forms.MessageBox.Show("Can't Open Device " + parDevice); #endif return; } if (DEV9Header.config.DirectConnectionSettings.InterceptDHCP) { InitDHCP(hostAdapter); } }
public SMAP_State(DEV9_State parDev9) { dev9 = parDev9; //Init SMAP int rxbi; for (rxbi = 0; rxbi < (DEV9Header.SMAP_BD_SIZE / 8); rxbi++) { SMAP_bd pbd; pbd = new SMAP_bd(dev9.dev9R, (int)((DEV9Header.SMAP_BD_RX_BASE & 0xffff) + (SMAP_bd.GetSize() * rxbi))); pbd.CtrlStat = (UInt16)DEV9Header.SMAP_BD_RX_EMPTY; pbd.Length = 0; } adapter = new AdapterLoader(this, dev9); }
public TAPAdapter(DEV9_State parDev9, string parDevice) : base(parDev9) { htap = TAPOpen(parDevice); htapstream = new FileStream(htap, FileAccess.ReadWrite, 16 * 1024, true); if (DEV9Header.config.DirectConnectionSettings.InterceptDHCP) { NetworkInterface hostAdapter = GetAdapterFromGuid(parDevice); if (hostAdapter == null) { if (BridgeHelper.IsInBridge(parDevice) == true) { hostAdapter = GetAdapterFromGuid(BridgeHelper.GetBridgeGUID()); } } if (hostAdapter == null) { //System.Windows.Forms.MessageBox.Show("Failed to GetAdapter"); throw new NullReferenceException("Failed to GetAdapter"); } InitDHCP(hostAdapter); } SetMAC(null); byte[] hostMAC = TAPGetMac(htap); if (hostMAC == null) { Log_Error("Unable to get host MAC address, using default MAC"); return; } byte[] wMAC = (byte[])ps2MAC.Clone(); //wMAC[3] = hostMAC[3]; wMAC[5] = hostMAC[4]; wMAC[4] = hostMAC[5]; SetMAC(wMAC); }
public AdapterLoader(SMAP_State parSmap, DEV9_State parDev9) { dev9 = parDev9; net = new AdapterManager(parSmap); }
public ATA_State(DEV9_State parDev9) { dev9 = parDev9; //Power on ResetBegin(); //Would do self-Diag + Hardware Init //Fillout Command table (inspired from MegaDev9) //This is actully a pretty neat way of doing this for (int i = 0; i < 256; i++) { hddCmds[i] = HDD_Unk; } hddCmds[0x00] = HDD_Nop; hddCmds[0x20] = () => HDD_ReadSectors(false); //0x21 hddCmds[0x40] = () => HDD_ReadVerifySectors(false); //0x41 hddCmds[0x70] = HDD_SeekCmd; hddCmds[0x90] = HDD_ExecuteDeviceDiag; hddCmds[0x91] = HDD_InitDevParameters; hddCmds[0xB0] = HDD_Smart; hddCmds[0xC4] = () => HDD_ReadMultiple(false); hddCmds[0xC8] = () => HDD_ReadDMA(false); //0xC9 hddCmds[0xCA] = () => HDD_WriteDMA(false); //0xCB //HDDcmds[0x25] = HDDreadDMA48; /* HDDcmds[0x35] = HDDwriteDMA_ext;*/ //HDDcmdNames[0x35] = "DMA write (48-bit)"; // 48-bit hddCmds[0xE3] = HDD_Idle; hddCmds[0xE7] = HDD_FlushCache; /* HDDcmds[0xEA] = HDDflushCacheExt;*/ //HDDcmdNames[0xEA] = "flush cache (48-bit)"; // 48-bit hddCmds[0xEC] = HDD_IdentifyDevice; /* HDDcmds[0xA1] = HDDidentifyPktDevice;*/ //HDDcmdNames[0xA1] = "identify ATAPI device"; // For ATAPI devices hddCmds[0xEF] = HDD_SetFeatures; ///* HDDcmds[0xF1] = HDDsecSetPassword;*/ //HDDcmdNames[0xF1] = "security set password"; ///* HDDcmds[0xF2] = HDDsecUnlock;*/ //HDDcmdNames[0xF2] = "security unlock"; ///* HDDcmds[0xF3] = HDDsecErasePrepare;*/ //HDDcmdNames[0xF3] = "security erase prepare"; ///* HDDcmds[0xF4] = HDDsecEraseUnit;*/ //HDDcmdNames[0xF4] = "security erase unit"; /* This command is Sony-specific and isn't part of the IDE standard */ /* The Sony HDD has a modified firmware that supports this command */ /* Sending this command to a standard HDD will give an error */ /* We roughly emulate it to make programs think the HDD is a Sony one */ /* However, we only send null, if anyting checks the returned data */ /* it will fail */ hddCmds[0x8E] = HDD_SCE; //HDDcmdNames[0x8E] = "SCE security control"; // ResetEnd(true); }
public Winsock(DEV9_State parDev9, string parDevice) : base(parDev9) { //Add allways on connections byte[] dns1 = null; byte[] dns2 = null; Dictionary <string, byte[]> hosts = new Dictionary <string, byte[]>(); NetworkInterface adapter = null; if (parDevice != "Auto") { adapter = GetAdapterFromGuid(parDevice); if (adapter == null) { //System.Windows.Forms.MessageBox.Show("Failed to GetAdapter"); throw new NullReferenceException("Failed to GetAdapter"); } adapterIP = (from ip in adapter.GetIPProperties().UnicastAddresses where ip.Address.AddressFamily == AddressFamily.InterNetwork select ip.Address).SingleOrDefault(); } else { adapter = UDP_DHCPSession.AutoAdapter(); adapterIP = IPAddress.Any; } if (adapter == null) { throw new NullReferenceException("Auto Selection Failed, Check You Connection or Manually Specify Adapter"); } if (!DEV9Header.config.SocketConnectionSettings.AutoDNS1) { dns1 = IPAddress.Parse(DEV9Header.config.SocketConnectionSettings.DNS1).GetAddressBytes(); } if (!DEV9Header.config.SocketConnectionSettings.AutoDNS2) { dns2 = IPAddress.Parse(DEV9Header.config.SocketConnectionSettings.DNS2).GetAddressBytes(); } foreach (Config.ConfigHost host in DEV9Header.config.Hosts) { if (host.Enabled) { hosts.Add(host.URL, IPAddress.Parse(host.IP).GetAddressBytes()); } } //DHCP emulated server ConnectionKey dhcpKey = new ConnectionKey { Protocol = (byte)IPType.UDP, SRVPort = 67 }; dhcpServer = new UDP_DHCPSession(dhcpKey, adapter, dns1, dns2, DEV9Header.config.SocketConnectionSettings.LANMode); dhcpServer.ConnectionClosedEvent += HandleConnectionClosed; dhcpServer.SourceIP = new byte[] { 255, 255, 255, 255 }; dhcpServer.DestIP = DefaultDHCPConfig.DHCP_IP; if (!connections.TryAdd(dhcpServer.Key, dhcpServer)) { throw new Exception("Connection Add Failed"); } //DNS emulated server ConnectionKey dnsKey = new ConnectionKey { Protocol = (byte)IPType.UDP, SRVPort = 53 }; dnsServer = new UDP_DNSSession(dnsKey, hosts); dnsServer.ConnectionClosedEvent += HandleConnectionClosed; dnsServer.SourceIP = dhcpServer.PS2IP; dnsServer.DestIP = DefaultDHCPConfig.DHCP_IP; if (!connections.TryAdd(dnsServer.Key, dnsServer)) { throw new Exception("Connection Add Failed"); } // foreach (Config.ConfigIncomingPort port in DEV9Header.config.SocketConnectionSettings.IncomingPorts) { if (!port.Enabled) { continue; } ConnectionKey Key = new ConnectionKey { Protocol = (byte)port.Protocol, PS2Port = port.Port, SRVPort = port.Port }; Session s = null; if (port.Protocol == IPType.UDP) { //avoid duplicates if (fixedUDPPorts.ContainsKey(port.Port)) { continue; } ConnectionKey fKey = new ConnectionKey { Protocol = (byte)IPType.UDP, PS2Port = port.Port, SRVPort = 0 }; UDPFixedPort fPort = new UDPFixedPort(fKey, adapterIP, port.Port); fPort.ConnectionClosedEvent += HandleFixedPortClosed; fPort.DestIP = new byte[] { 0, 0, 0, 0 }; fPort.SourceIP = dhcpServer.PS2IP; if (!connections.TryAdd(fPort.Key, fPort) | !fixedUDPPorts.TryAdd(port.Port, fPort)) { fPort.Dispose(); throw new Exception("Connection Add Failed"); } s = fPort.NewListenSession(Key); } s.ConnectionClosedEvent += HandleConnectionClosed; s.SourceIP = dhcpServer.PS2IP; s.DestIP = dhcpServer.Broadcast; if (!connections.TryAdd(s.Key, s)) { s.Dispose(); throw new Exception("Connection Add Failed"); } } SetMAC(null); SetMAC(adapter.GetPhysicalAddress().GetAddressBytes()); }
public DirectAdapter(DEV9_State parDev9) : base(parDev9) { }
public SPEED_State(DEV9_State parDev9) { dev9 = parDev9; }
public NetAdapter(DEV9_State parDev9) { dev9 = parDev9; //SetMAC(null); }