t_stat i8259_raiseint(I8259* chip,int level) { int32 bit, isr, myprio; TRACE_PRINT1(DBG_PIC_II,"Request INT level=%d",level); if (chip->state != 5) return SCPE_OK; /* not yet initialized, ignore interrupts */ bit = 1<<level; if (chip->imr & bit) return SCPE_OK; /* inhibited */ chip->isr = (chip->isr | bit) & 0xff; /* request this interrupt level */ /* bit7=prio7 => bitN = prioN bit7=prio6 => bitN = prioN-1 ... bit7=prio0 => bitN = prioN-7 */ isr = (chip->isr<<8) | chip->isr; /* simple rotation */ isr = isr << (7-level); /* shift level bit into bit 15 */ myprio = chip->prio - 7 + level; if (myprio < 0) myprio += 8; if (!(isr & priomask[myprio])) { /* higher interrupt is pending */ if (chip->autoint) { TRACE_PRINT1(DBG_PIC_IO,"Raise AUTOINT level=%d",chip->intlevel); return m68k_raise_autoint(chip->intlevel); } else { TRACE_PRINT2(DBG_PIC_IO,"Raise VECTORINT level=%d vector=%x",chip->intlevel,chip->intvector); return m68k_raise_vectorint(chip->intlevel,chip->intvector); } } return SCPE_OK; }
t_stat i8251_read(I8251* chip,int port,uint32* value) { if (port==0) { /* data read */ *value = chip->ibuf; chip->status &= ~I8251_ST_RXRDY; /* mark read buffer as empty */ TRACE_PRINT1(DBG_UART_RD,"RD DATA = 0x%02x",*value); } else { /* status read */ *value = chip->status & 0xff; TRACE_PRINT1(DBG_UART_RD,"RD STATUS = 0x%02x",*value); } return SCPE_OK; }
static t_stat u39_callc(I8255* chip,int rw) { if (rw==1) { if (I8255_FALLEDGE(portc,U39C_STROBE)) { sagelp_output(&sagelp_unit); TRACE_PRINT1(DBG_PP_RDC,"RD PortC: STROBE-=%d",chip->portc&U39C_STROBE?1:0); } if (I8255_RISEEDGE(portc,U39C_SI)) { /* printf("rising edge on SI: PC=%x!\n",PCX);*/ TRACE_PRINT1(DBG_PP_RDC,"RD PortC: SI+=%d",chip->portc&U39C_SI?1:0); sage_raiseint(SI_PICINT); } } return SCPE_OK; }
static t_stat u39_calla(I8255* chip, int rw) { if (rw) { sagelp_unit.buf = chip->porta; TRACE_PRINT1(DBG_PP_WRA,"WR PortA = 0x%x",chip->porta); } return SCPE_OK; }
// enumerate wireless interfaces UINT EnumInterface(HANDLE hClient, WLAN_INTERFACE_INFO sInfo[64]) { TRACE_ENTER(); DWORD dwError = ERROR_SUCCESS; PWLAN_INTERFACE_INFO_LIST pIntfList = NULL; UINT i = 0; __try { // enumerate wireless interfaces if ((dwError = My_WlanEnumInterfaces( hClient, NULL, // reserved &pIntfList )) != ERROR_SUCCESS) { TRACE_PRINT1("My_WlanEnumInterfaces: error, errCode = 0x%08x.", dwError); __leave; } // print out interface information for (i = 0; i < pIntfList->dwNumberOfItems; i++) { memcpy(&sInfo[i], &pIntfList->InterfaceInfo[i], sizeof(WLAN_INTERFACE_INFO)); } TRACE_PRINT1("My_WlanEnumInterfaces: pIntfList->dwNumberOfItems = %d.", pIntfList->dwNumberOfItems); TRACE_EXIT(); return pIntfList->dwNumberOfItems; } __finally { // clean up if (pIntfList != NULL) { My_WlanFreeMemory(pIntfList); } } TRACE_PRINT1("My_WlanEnumInterfaces: pIntfList->dwNumberOfItems = %d.", pIntfList->dwNumberOfItems); TRACE_EXIT(); return 0; }
// open a WLAN client handle and check version DWORD OpenHandleAndCheckVersion( PHANDLE phClient ) { TRACE_ENTER(); DWORD dwError = ERROR_SUCCESS; DWORD dwServiceVersion; HANDLE hClient = NULL; __try { *phClient = NULL; // open a handle to the service if ((dwError = My_WlanOpenHandle( WLAN_API_VERSION, NULL, // reserved &dwServiceVersion, &hClient )) != ERROR_SUCCESS) { TRACE_PRINT1("My_WlanOpenHandle: error, errCode = 0x%08x.", dwError); __leave; } // check service version if (WLAN_API_VERSION_MAJOR(dwServiceVersion) < WLAN_API_VERSION_MAJOR(WLAN_API_VERSION_2_0)) { // No-op, because the version check is for demonstration purpose only. // You can add your own logic here. } *phClient = hClient; // set hClient to NULL so it will not be closed hClient = NULL; } __finally { if (hClient != NULL) { // clean up My_WlanCloseHandle( hClient, NULL // reserved ); } } TRACE_EXIT(); return dwError; }
BOOL initWlanFunctions() { BOOL bRet; TRACE_ENTER(); // Get a handle to the packet DLL module. hinstLib = LoadLibrary(TEXT("wlanapi.dll")); // If the handle is valid, try to get the function address. if (hinstLib != NULL) { My_WlanOpenHandle = (MY_WLANOPENHANDLE)GetProcAddress(hinstLib, "WlanOpenHandle"); My_WlanCloseHandle = (MY_WLANCLOSEHANDLE)GetProcAddress(hinstLib, "WlanCloseHandle"); My_WlanEnumInterfaces = (MY_WLANENUMINTERFACES)GetProcAddress(hinstLib, "WlanEnumInterfaces"); My_WlanFreeMemory = (MY_WLANFREEMEMORY)GetProcAddress(hinstLib, "WlanFreeMemory"); // If the function address is valid, call the function. if (My_WlanOpenHandle != NULL && My_WlanCloseHandle != NULL && My_WlanEnumInterfaces != NULL && My_WlanFreeMemory != NULL) { bRet = TRUE; } else { TRACE_PRINT1("GetProcAddress: error, errCode = 0x%08x.", GetLastError()); bRet = FALSE; } } else { TRACE_PRINT1("LoadLibrary: error, errCode = 0x%08x.", GetLastError()); bRet = FALSE; } TRACE_EXIT(); return bRet; }
NetCfg::NetCfg() : m_pINetCfg(0) { TRACE_ENTER(); HRESULT hr = S_OK; hr = m_pINetCfg.CoCreateInstance(CLSID_CNetCfg); if(!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfg::CoCreateInstance: error, errCode = 0x%08x.", hr); throw 1; } hr = m_pINetCfg.QueryInterface(&m_pLock); if (!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfg::QueryInterface: error, errCode = 0x%08x.", hr); throw 2; } // Note that this call can block. hr = m_pLock->AcquireWriteLock(INFINITE, NPCAP_LOOPBACK_APP_NAME, NULL); if (!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfgLock::AcquireWriteLock: error, errCode = 0x%08x.", hr); throw 3; } hr = m_pINetCfg->Initialize(NULL); if(!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfg::Initialize: error, errCode = 0x%08x.", hr); throw 4; } TRACE_EXIT(); }
COM::COM() { TRACE_ENTER(); HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); if(!SUCCEEDED(hr)) { TRACE_PRINT1("CoInitializeEx: error, errCode = 0x%08x.", hr); } TRACE_EXIT(); }
BOOL EraseLoopbackRecord() { TRACE_ENTER(); BOOL rv = TRUE; #ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE HKEY hKey; DWORD type; char buffer[BUFSIZE]; DWORD size = sizeof(buffer); DWORD dwWinPcapMode = 0; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) { if (RegQueryValueExA(hKey, "WinPcapCompatible", 0, &type, (LPBYTE)buffer, &size) == ERROR_SUCCESS && type == REG_DWORD) { dwWinPcapMode = *((DWORD *) buffer); } else { TRACE_PRINT1("RegQueryValueExA(WinPcapCompatible) failed or not REG_DWORD: %#x\n", GetLastError()); dwWinPcapMode = 0; } RegCloseKey(hKey); } else { TRACE_PRINT2("%s\\Parameters) failed: %#x\n", NPCAP_SERVICE_REG_KEY_NAME, GetLastError()); dwWinPcapMode = 0; } if (dwWinPcapMode != 0 && !DeleteValueFromRegistry(_T("SYSTEM\\CurrentControlSet\\Services\\npf\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME)) { rv = FALSE; } #endif /* ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE */ if (!DeleteValueFromRegistry(NPCAP_REG_KEY_NAME, NPCAP_REG_LOOPBACK_VALUE_NAME)) { rv = FALSE; } if (!DeleteValueFromRegistry(NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME)) { rv = FALSE; } TRACE_EXIT(); return rv; }
NetCfg::~NetCfg() { TRACE_ENTER(); HRESULT hr = S_OK; if(m_pINetCfg) { hr = m_pINetCfg->Uninitialize(); if(!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfg::Uninitialize: error, errCode = 0x%08x.", hr); } hr = m_pLock->ReleaseWriteLock(); if (!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfgLock::ReleaseWriteLock: error, errCode = 0x%08x.", hr); } } TRACE_EXIT(); }
BOOL writeWlanAdapterGuidsToRegistry() { TRACE_ENTER(); vector<tstring> nstrWlanAdapterGuids = getWlanAdapterGuids(); if (nstrWlanAdapterGuids.size() == 0) { TRACE_PRINT1("getWlanAdapterGuids: error, nstrWlanAdapterGuids.size() = %d.", nstrWlanAdapterGuids.size()); TRACE_EXIT(); return FALSE; } for (size_t i = 0; i < nstrWlanAdapterGuids.size(); i++) { nstrWlanAdapterGuids[i] = _T("\\Device\\{") + nstrWlanAdapterGuids[i] + _T("}"); } tstring strGuidText = printAdapterNames(nstrWlanAdapterGuids); TRACE_PRINT1("AddFlagToRegistry_Dot11Adapters: executing, strGuidText = %s.", strGuidText.c_str()); TRACE_EXIT(); return AddFlagToRegistry_Dot11Adapters(strGuidText.c_str()); }
BOOL AddFlagToRegistry_Service(tstring strDeviceName) { TRACE_ENTER(); BOOL rv = TRUE; #ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE /* If this is *not* the WinPcap-API compatible build, then it's the native * build, which is responsible for installing and recording the loopback * interface so that both drivers can access it. */ HKEY hKey; DWORD type; char buffer[BUFSIZE]; DWORD size = sizeof(buffer); DWORD dwWinPcapMode = 0; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), 0, KEY_READ, &hKey) == ERROR_SUCCESS) { if (RegQueryValueExA(hKey, "WinPcapCompatible", 0, &type, (LPBYTE)buffer, &size) == ERROR_SUCCESS && type == REG_DWORD) { dwWinPcapMode = *((DWORD *) buffer); } else { TRACE_PRINT1("RegQueryValueExA(WinPcapCompatible) failed or not REG_DWORD: %#x\n", GetLastError()); dwWinPcapMode = 0; } RegCloseKey(hKey); } else { TRACE_PRINT2("%s\\Parameters) failed: %#x\n", NPCAP_SERVICE_REG_KEY_NAME, GetLastError()); dwWinPcapMode = 0; } if (dwWinPcapMode != 0) { rv = WriteStrToRegistry(_T("SYSTEM\\CurrentControlSet\\Services\\npf\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME, tstring(_T("\\Device\\") + strDeviceName).c_str(), KEY_WRITE); } #endif /* ifndef NPF_NPCAP_RUN_IN_WINPCAP_MODE */ rv = WriteStrToRegistry(NPCAP_SERVICE_REG_KEY_NAME _T("\\Parameters"), NPCAP_REG_LOOPBACK_VALUE_NAME, tstring(_T("\\Device\\") + strDeviceName).c_str(), KEY_WRITE) && rv; TRACE_EXIT(); return rv; }
static t_stat u39_ckmode(I8255* chip,uint32 data) { TRACE_PRINT1(DBG_PP_MODE,"WR Mode: 0x%x",data); /* BIOS initializes port A as input, later LP is initialized to output */ if (!(data==0x82 || data==0x92)) { /* hardwired: * d7=1 -- mode set flag * d6=0 -+ group a mode 0: basic I/O * d5=0 -+ * d4=0 -- port a = output / input * d3=0 -- port c upper = output * d2=0 -- group b mode 0: basic I/O * d1=1 -- port b = input * d0=0 -- port c lower = output */ printf("u39_ckmode: unsupported ctrl=0x%02x\n",data); return STOP_IMPL; } chip->portc = 0; /* reset port */ return SCPE_OK; }
static t_stat u39_callb(I8255* chip, int rw) { if (rw==0) { /* only when reading port */ /* propagate FDC Write Protect */ int portb = 0; I8272_DRIVE_INFO* dip = &u21.drive[u21.fdc_curdrv]; if (dip->uptr && (dip->uptr->flags & UNIT_I8272_WLK)) { portb |= U39B_WP; TRACE_PRINT1(DBG_PP_RDB,"RD PortB: WP+=%d",(portb&U39B_WP)?1:0); } /* propagate FDC interrupt */ if (u21.irqflag) { portb |= U39B_FDI; TRACE_PRINT0(DBG_PP_RDB,"RD PortB: FDI+=1"); } else { TRACE_PRINT0(DBG_PP_RDB,"RD PortB: FDI+=0"); } chip->portb = portb; } return SCPE_OK; }
vector<tstring> getWlanAdapterGuids() { TRACE_ENTER(); HANDLE hClient = NULL; WLAN_INTERFACE_INFO sInfo[64]; RPC_TSTR strGuid = NULL; vector<tstring> nstrWlanAdapterGuids; if (!initWlanFunctions()) { TRACE_PRINT("initWlanFunctions: error."); TRACE_EXIT(); return nstrWlanAdapterGuids; } if (OpenHandleAndCheckVersion(&hClient) != ERROR_SUCCESS) { TRACE_PRINT("OpenHandleAndCheckVersion: error."); TRACE_EXIT(); return nstrWlanAdapterGuids; } UINT nCount = EnumInterface(hClient, sInfo); for (UINT i = 0; i < nCount; ++i) { if (UuidToString(&sInfo[i].InterfaceGuid, &strGuid) == RPC_S_OK) { TRACE_PRINT1("EnumInterface: executing, strGuid = %s.", (TCHAR*) strGuid); nstrWlanAdapterGuids.push_back((TCHAR*) strGuid); RpcStringFree(&strGuid); } } TRACE_EXIT(); return nstrWlanAdapterGuids; }
t_stat i8251_write(I8251* chip,int port,uint32 value) { int bits; if (port==0) { /* data port */ chip->obuf = value & chip->bitmask; TRACE_PRINT1(DBG_UART_WR,"WR DATA = 0x%02x",chip->obuf); if (chip->init==3) { /* is fully initialized */ if ((chip->mode & I8251_MODE_BAUD)==I8251_MODE_SYNC) { sim_printf("i8251: sync mode not implemented\n"); return STOP_IMPL; } if (chip->cmd & I8251_CMD_TXEN) { /* transmit data */ chip->status &= ~(I8251_ST_TXEMPTY|I8251_ST_TXRDY); sim_activate(chip->out,chip->out->wait); } } return SCPE_OK; } else { /* control port */ switch (chip->init) { case 0: /* expect mode word */ chip->mode = value; TRACE_PRINT1(DBG_UART_WR,"WR MODE = 0x%02x",value); chip->init = (value & I8251_MODE_BAUD)==I8251_MODE_SYNC ? 1 : 3; bits = (chip->mode & I8251_AMODE_BITS) >> 2; chip->bitmask = i8251_bitmask[bits]; break; case 1: /* expect sync1 */ chip->sync1 = value; TRACE_PRINT1(DBG_UART_WR,"WR SYNC1 = 0x%02x",value); chip->init = 2; break; case 2: /* expect sync2 */ chip->sync2 = value; TRACE_PRINT1(DBG_UART_WR,"WR SYNC2 = 0x%02x",value); chip->init = 3; break; case 3: /* expect cmd word */ chip->cmd = value; TRACE_PRINT1(DBG_UART_WR,"WR CMD = 0x%02x",value); if (value & I8251_CMD_EH) { sim_printf("i8251: hunt mode not implemented\n"); return STOP_IMPL; } if (value & I8251_CMD_IR) chip->init = 0; if (value & I8251_CMD_ER) chip->status &= ~(I8251_ST_FE|I8251_ST_OE|I8251_ST_PE); if (value & I8251_CMD_SBRK) sim_printf("i8251: BREAK sent\n"); if (value & I8251_CMD_RXE) { sim_activate(chip->in,chip->in->wait); } else { if (!chip->oob) sim_cancel(chip->in); } if (value & I8251_CMD_TXEN) { if (!(chip->status & I8251_ST_TXEMPTY)) sim_activate(chip->out,chip->out->wait); else { chip->status |= I8251_ST_TXRDY; if (chip->txint) chip->txint(chip); } } else { chip->status &= ~I8251_ST_TXRDY; sim_cancel(chip->out); } } return SCPE_OK; } }
BOOL EnumerateComponents(CComPtr<INetCfg>& pINetCfg, const GUID* pguidClass) { TRACE_ENTER(); /* cout << "\n\nEnumerating " << GUID2Str(pguidClass) << " class:\n" << endl;*/ // IEnumNetCfgComponent provides methods that enumerate the INetCfgComponent interfaces // for network components of a particular type installed on the operating system. // Types of network components include network cards, protocols, services, and clients. CComPtr<IEnumNetCfgComponent> pIEnumNetCfgComponent; // get enumeration containing network components of the provided class (GUID) HRESULT hr = pINetCfg->EnumComponents(pguidClass, &pIEnumNetCfgComponent); if(!SUCCEEDED(hr)) { TRACE_PRINT1("INetCfg::EnumComponents: error, errCode = 0x%08x.", hr); throw 1; } // INetCfgComponent interface provides methods that control and retrieve // information about a network component. CComPtr<INetCfgComponent> pINetCfgComponent; unsigned int nIndex = 1; BOOL bFound = FALSE; BOOL bFailed = FALSE; // retrieve the next specified number of INetCfgComponent interfaces in the enumeration sequence. while(pIEnumNetCfgComponent->Next(1, &pINetCfgComponent, 0) == S_OK) { /* cout << GUID2Desc(pguidClass) << " "<< nIndex++ << ":\n";*/ // LPWSTR pszDisplayName = NULL; // pINetCfgComponent->GetDisplayName(&pszDisplayName); // wcout << L"\tDisplay name: " << wstring(pszDisplayName) << L'\n'; // CoTaskMemFree(pszDisplayName); LPWSTR pszBindName = NULL; pINetCfgComponent->GetBindName(&pszBindName); // wcout << L"\tBind name: " << wstring(pszBindName) << L'\n'; // DWORD dwCharacteristics = 0; // pINetCfgComponent->GetCharacteristics(&dwCharacteristics); // cout << "\tCharacteristics: " << dwCharacteristics << '\n'; // // GUID guid; // pINetCfgComponent->GetClassGuid(&guid); // cout << "\tClass GUID: " << guid.Data1 << '-' << guid.Data2 << '-' // << guid.Data3 << '-' << (unsigned int) guid.Data4 << '\n'; // // ULONG ulDeviceStatus = 0; // pINetCfgComponent->GetDeviceStatus(&ulDeviceStatus); // cout << "\tDevice Status: " << ulDeviceStatus << '\n'; // // LPWSTR pszHelpText = NULL; // pINetCfgComponent->GetHelpText(&pszHelpText); // wcout << L"\tHelp Text: " << wstring(pszHelpText) << L'\n'; // CoTaskMemFree(pszHelpText); // // LPWSTR pszID = NULL; // pINetCfgComponent->GetId(&pszID); // wcout << L"\tID: " << wstring(pszID) << L'\n'; // CoTaskMemFree(pszID); // // pINetCfgComponent->GetInstanceGuid(&guid); // cout << "\tInstance GUID: " << guid.Data1 << '-' << guid.Data2 << '-' // << guid.Data3 << '-' << (unsigned int) guid.Data4 << '\n'; LPWSTR pszPndDevNodeId = NULL; hr = pINetCfgComponent->GetPnpDevNodeId(&pszPndDevNodeId); if (!SUCCEEDED(hr)) { TRACE_PRINT1("GetPnpDevNodeId failed: %#x", hr); TRACE_EXIT(); return FALSE; } // wcout << L"\tPNP Device Node ID: " << wstring(pszPndDevNodeId) << L'\n'; int iDevID = getIntDevID(pszPndDevNodeId); TRACE_PRINT4("INetCfgComponent::GetPnpDevNodeId: executing, pszPndDevNodeId = %s, iDevID = %d, g_NpcapAdapterID = %d, pszBindName = %ws.", pszPndDevNodeId, iDevID, g_NpcapAdapterID, pszBindName); if (g_NpcapAdapterID == iDevID) { bFound = TRUE; TRACE_PRINT2("INetCfgComponent::SetDisplayName: executing, g_NpcapAdapterID = iDevID = %d, pszBindName = %ws.", g_NpcapAdapterID, pszBindName); hr = pINetCfgComponent->SetDisplayName(NPCAP_LOOPBACK_ADAPTER_NAME); if (hr != S_OK) { TRACE_PRINT1("INetCfgComponent::SetDisplayName: error, errCode = 0x%08x.", hr); bFailed = TRUE; } if (!AddFlagToRegistry(pszBindName)) { TRACE_PRINT1("AddFlagToRegistry: error, pszBindName = %ws.", pszBindName); bFailed = TRUE; } if (!AddFlagToRegistry_Service(pszBindName)) { TRACE_PRINT1("AddFlagToRegistry_Service: error, pszBindName = %ws.", pszBindName); bFailed = TRUE; } if (!RenameLoopbackNetwork(pszBindName)) { TRACE_PRINT1("RenameLoopbackNetwork: error, pszBindName = %ws.", pszBindName); bFailed = TRUE; } } CoTaskMemFree(pszBindName); CoTaskMemFree(pszPndDevNodeId); pINetCfgComponent.Release(); if (bFound) { TRACE_EXIT(); return !bFailed; } } TRACE_EXIT(); return FALSE; }