bool Wlan::StartHostedNet( const char * ssid, const char * key, int maxPeers ) { bool result = false; if (OpenHandle()) { WLAN_HOSTED_NETWORK_REASON reason = {}; WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS settings = {}; settings.dwMaxNumberOfPeers = maxPeers; size_t ssidLen = strlen( ssid ); settings.hostedNetworkSSID.uSSIDLength = ssidLen; memcpy( settings.hostedNetworkSSID.ucSSID, (void*) ssid, ssidLen ); if (WlanHostedNetworkSetProperty( m_handle, WLAN_HOSTED_NETWORK_OPCODE::wlan_hosted_network_opcode_connection_settings, sizeof( WLAN_HOSTED_NETWORK_CONNECTION_SETTINGS ), &settings, &reason, NULL ) == ERROR_SUCCESS) { size_t keyLength = strlen( key ) + 1; if (WlanHostedNetworkSetSecondaryKey( m_handle, keyLength, (PUCHAR) key, TRUE, TRUE, &reason, NULL ) == ERROR_SUCCESS) { result = (WlanHostedNetworkStartUsing( m_handle, &reason, NULL ) == ERROR_SUCCESS); } } } return result; }
int clone_area(const char name[], void **clone_addr, int searchFlags, PageProtection protection, int sourceArea) { Area *area = static_cast<Area*>(GetResource(sourceArea, OBJ_AREA)); if (area == 0) { printf("clone_area: source area id %08x is invalid\n", sourceArea); return E_BAD_HANDLE; } unsigned int addr = INVALID_PAGE; if (searchFlags & EXACT_ADDRESS) addr = reinterpret_cast<unsigned int>(*clone_addr); // It is important that CreateArea not incur a fault! char nameCopy[OS_NAME_LENGTH]; if (!CopyUser(nameCopy, name, OS_NAME_LENGTH)) return E_BAD_ADDRESS; Area *newArea = AddressSpace::GetCurrentAddressSpace()->CreateArea(nameCopy, area->GetSize(), AREA_NOT_WIRED, protection | USER_READ | SYSTEM_READ | ((protection & USER_WRITE) ? SYSTEM_WRITE : 0), area->GetPageCache(), 0, addr, searchFlags); area->ReleaseRef(); if (newArea == 0) return E_ERROR; *clone_addr = reinterpret_cast<void*>(newArea->GetBaseAddress()); return OpenHandle(newArea); }
bool Wlan::IsNetAvailable( const char * ssid ) { bool result = false; if (OpenHandle()) { PWLAN_INTERFACE_INFO_LIST wlanInterfaces; if (WlanEnumInterfaces( m_handle, NULL, &wlanInterfaces ) == ERROR_SUCCESS) { for (int i = 0; i < wlanInterfaces->dwNumberOfItems; i++) { if (wlanInterfaces->InterfaceInfo[i].isState == wlan_interface_state_connected) { PWLAN_AVAILABLE_NETWORK_LIST wlanNetworks; if (WlanGetAvailableNetworkList( m_handle, &wlanInterfaces->InterfaceInfo[i].InterfaceGuid, 0, NULL, &wlanNetworks ) == ERROR_SUCCESS) { for (int j = 0; j < wlanNetworks->dwNumberOfItems; j++) { if (_strnicmp( (const char *) wlanNetworks->Network[j].dot11Ssid.ucSSID, ssid, strlen(ssid) ) == 0) { result = true; break; } } WlanFreeMemory( wlanNetworks ); } } } WlanFreeMemory( wlanInterfaces ); } } return result; }
int create_area(const char name[], void **requestAddr, int flags, unsigned int size, AreaWiring lock, PageProtection protection) { unsigned int va = INVALID_PAGE; if (flags & EXACT_ADDRESS) va = reinterpret_cast<unsigned int>(*requestAddr); PageCache *cache = new PageCache; if (cache == 0) return E_NO_MEMORY; // It is important that CreateArea not incur a fault! char nameCopy[OS_NAME_LENGTH]; if (!CopyUser(nameCopy, name, OS_NAME_LENGTH)) return E_BAD_ADDRESS; Area *newArea = AddressSpace::GetCurrentAddressSpace()->CreateArea(nameCopy, size, lock, protection | USER_READ | SYSTEM_READ | ((protection & USER_WRITE) ? SYSTEM_WRITE : 0), cache, 0, va, flags); if (newArea == 0) { delete cache; return E_NO_MEMORY; } *requestAddr = reinterpret_cast<void*>(newArea->GetBaseAddress()); return OpenHandle(newArea); }
void Wlan::StopHostedNet() { if (OpenHandle()) { WLAN_HOSTED_NETWORK_REASON reason = {}; WlanHostedNetworkStopUsing( m_handle, &reason, NULL ); } }
int create_sem(const char name[], int count) { Semaphore *sem = new Semaphore(name, count); if (sem == 0) return E_NO_MEMORY; return OpenHandle(sem); }
int _tmain(int argc, _TCHAR* argv[]) { TestWlanApi( argc, argv ); HANDLE DeviceHandle = OpenHandle(pNdisProtDevice); if( DeviceHandle == INVALID_HANDLE_VALUE ) { _tprintf((_T("Failed to open %s\n"), pNdisProtDevice)); return -1; } wstring strDeviceName[256][2]; int nCount = EnumerateDevices( DeviceHandle, strDeviceName ); if( nCount == 0 ) { puts( "no device bind." ); return -1; } for( int i = 0; i < nCount; ++i ) { printf( "%2d.%S\n %S\n\n", i, strDeviceName[i][0].c_str(), strDeviceName[i][1].c_str() ); } TCHAR szBuffer[256]; DWORD dwRead = 0; //if( ReadConsole( GetStdHandle(STD_INPUT_HANDLE), szBuffer, _countof(szBuffer), &dwRead, NULL ) == FALSE ) //{ // puts( "error input" ); // return -1; //} //szBuffer[dwRead] = 0; //int nChoice = _ttoi( szBuffer ); int nChoice = 0; if( nChoice > nCount ) { puts( "error input." ); return -1; } InitializeDevice( DeviceHandle, strDeviceName[nChoice][0].c_str(), strDeviceName[nChoice][0].length()*sizeof(WCHAR) ); for( int i = 0; i < 3; ++i ) { if( ReadFile( DeviceHandle, szBuffer, sizeof(szBuffer), &dwRead, NULL ) ) { } } TerminateDevice( DeviceHandle ); }
int open(const char path[], int) { VNode *node; int error = FileSystem::WalkPath(path, strlen(path), &node); if (error < 0) return error; FileDescriptor *desc; error = node->Open(&desc); if (error < 0) { node->ReleaseRef(); return error; } desc->SetName(path); return OpenHandle(desc); }
RTDevice::RTDevice(ULONG DeviceIndex) { LibHandle = NULL ; Handle=INVALID_HANDLE_VALUE; NrOfDevices=0; DidAttach = FALSE; InitOk = FALSE; dp = NULL; DeviceRegKey = NULL; // Initialize selected device if(!Init()) return; if( OpenHandle(DeviceIndex) ) { InitOk = TRUE; return ; } return; }
static int StatGetCpuLimit(void) { int exitStatus = EXIT_SUCCESS; uint32 cpuLimit; VMGuestLibHandle glHandle; VMGuestLibError glError; exitStatus = OpenHandle(&glHandle, &glError); if (exitStatus) { return exitStatus; } glError = VMGuestLib_GetCpuLimitMHz(glHandle, &cpuLimit); if (glError != VMGUESTLIB_ERROR_SUCCESS) { ToolsCmd_PrintErr(SU_(stat.cpumax.failed, "Failed to get CPU limit: %s\n"), VMGuestLib_GetErrorText(glError)); exitStatus = EX_TEMPFAIL; } else { g_print(SU_(stat.cpuLimit.info, "%u MHz\n"), cpuLimit); } VMGuestLib_CloseHandle(glHandle); return exitStatus; }
static int StatGetMemorySwapped(void) { int exitStatus = EXIT_SUCCESS; uint32 memSwapped; VMGuestLibHandle glHandle; VMGuestLibError glError; exitStatus = OpenHandle(&glHandle, &glError); if (exitStatus) { return exitStatus; } glError = VMGuestLib_GetMemSwappedMB(glHandle, &memSwapped); if (glError != VMGUESTLIB_ERROR_SUCCESS) { ToolsCmd_PrintErr(SU_(stat.memswap.failed, "Failed to get swapped memory: %s\n"), VMGuestLib_GetErrorText(glError)); exitStatus = EX_TEMPFAIL; } else { g_print(SU_(stat.memorySwapped.info, "%u MB\n"), memSwapped); } VMGuestLib_CloseHandle(glHandle); return exitStatus; }
static int StatGetSessionID(void) { int exitStatus = EXIT_SUCCESS; uint64 session; VMGuestLibHandle glHandle; VMGuestLibError glError; exitStatus = OpenHandle(&glHandle, &glError); if (exitStatus) { return exitStatus; } glError = VMGuestLib_GetSessionId(glHandle, &session); if (glError != VMGUESTLIB_ERROR_SUCCESS) { ToolsCmd_PrintErr(SU_(stat.getsession.failed, "Failed to get session ID: %s\n"), VMGuestLib_GetErrorText(glError)); exitStatus = EX_TEMPFAIL; } else { g_print("0x%"FMT64"x\n", session); } VMGuestLib_CloseHandle(glHandle); return exitStatus; }
FileInputStream::FileInputStream(const FilePath& path) : m_path(path) { OpenHandle(); }