/** \brief Virtually press the power button of the device */ int qRemotePowerButton(DWORD, BYTE*, DWORD*, BYTE**, IRAPIStream* stream) { if (!stream) return -1; DWORD bytesRead; int toggleVal = 0; int returnValue = S_OK; if (S_OK != stream->Read(&toggleVal, sizeof(toggleVal), &bytesRead)) return -2; //PPN_REEVALUATESTATE 0x0001 Reserved. Set dwData to zero (0). //PPN_POWERCHANGE 0x0002 Reserved. Set dwData to zero (0). //PPN_UNATTENDEDMODE 0x0003 Set dwData to TRUE or FALSE. //PPN_SUSPENDKEYPRESSED or //PPN_POWERBUTTONPRESSED 0x0004 Reserved. Set dwData to zero (0). //PPN_SUSPENDKEYRELEASED 0x0005 Reserved. Set dwData to zero (0). //PPN_APPBUTTONPRESSED 0x0006 Reserved. Set dwData to zero (0). //PPN_OEMBASE Greater than or equal to 0x10000 //You can define higher values, such as 0x10001, 0x10002, and so on. // Reserved. Set dwData to zero (0). returnValue = PowerPolicyNotify(PPN_SUSPENDKEYPRESSED, 0); if (S_OK != stream->Write(&returnValue, sizeof(returnValue), &bytesRead)) return -3; else return S_OK; }
void CMobileOpalDlg::HandleMessage(OpalMessage & message) { switch (message.m_type) { case OpalIndRegistration : switch (message.m_param.m_registrationStatus.m_status) { case OpalRegisterSuccessful : case OpalRegisterRestored : SetStatusText(IDS_REGISTERED); break; case OpalRegisterRemoved : SetStatusText(IDS_UNREGISTERED, message.m_param.m_registrationStatus.m_error); break; case OpalRegisterRetrying : SetStatusText(IDS_REGISTERING); break; case OpalRegisterFailed : SetStatusText(0, message.m_param.m_registrationStatus.m_error); } break; case OpalIndMessageWaiting : if (message.m_param.m_messageWaiting.m_type != NULL && *message.m_param.m_messageWaiting.m_type != '\0') { CStringA msg; msg.Format(IDS_MESSAGE_WAITING, message.m_param.m_messageWaiting.m_type, message.m_param.m_messageWaiting.m_party); SetStatusText(0, msg); } break; case OpalIndIncomingCall : if (m_incomingCallToken.IsEmpty() && m_currentCallToken.IsEmpty()) { m_incomingCallToken = message.m_param.m_incomingCall.m_callToken; SetStatusText(IDS_INCOMING_CALL); SetCallButton(true, IDS_ANSWER); m_ctrlCallAddress.EnableWindow(false); ShowWindow(true); BringWindowToTop(); EnableFullPower(); } else { OpalMessage command; memset(&command, 0, sizeof(command)); command.m_type = OpalCmdClearCall; command.m_param.m_clearCall.m_callToken = message.m_param.m_incomingCall.m_callToken; command.m_param.m_clearCall.m_reason = OpalCallEndedByAnswerDenied; OpalMessage * response = OpalSendMessage(m_opal, &command); if (response != NULL) OpalFreeMessage(response); SetStatusText(IDS_BUSY); } break; case OpalIndAlerting : SetStatusText(IDS_RINGING); break; case OpalIndEstablished : SetSpeakerMode(m_speakerphone); SetStatusText(IDS_ESTABLISHED); break; case OpalIndUserInput : SetStatusText(0, message.m_param.m_userInput.m_userInput); break; case OpalIndCallCleared : if (m_currentCallToken == message.m_param.m_callCleared.m_callToken || m_incomingCallToken == message.m_param.m_callCleared.m_callToken) { m_incomingCallToken.Empty(); m_currentCallToken.Empty(); SetCallButton(true, IDS_CALL); m_ctrlCallAddress.EnableWindow(true); SetStatusText(IDS_READY, message.m_param.m_callCleared.m_reason); if (m_hPowerRequirement != NULL) { ReleasePowerRequirement(m_hPowerRequirement); m_hPowerRequirement = NULL; } PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE); } } }
void CMobileOpalDlg::InitialiseOPAL() { ///////////////////////////////////////////////////////////////////// // Start up and initialise OPAL if (m_opal == NULL) { m_opal = OpalInitialise(&m_opalVersion, "pc h323 sip " TRACE_OPTIONS); if (m_opal == NULL) { ErrorBox(IDS_INIT_FAIL); EndDialog(IDCANCEL); return; } } OpalMessage command; OpalMessage * response; // SIP registrar un-regisration CStringA strAOR = GetOptionStringA(RegistrarAorKey); CStringA strHost = GetOptionStringA(RegistrarHostKey); if (!m_currentAOR.IsEmpty() && (m_currentAOR != strAOR || m_currentHost != strHost)) { // Registration changed, so unregister the previous name memset(&command, 0, sizeof(command)); command.m_type = OpalCmdRegistration; command.m_param.m_registrationInfo.m_protocol = "sip"; command.m_param.m_registrationInfo.m_identifier = m_currentAOR; command.m_param.m_registrationInfo.m_hostName = m_currentHost; response = OpalSendMessage(m_opal, &command); if (response != NULL && response->m_type == OpalCmdRegistration) { OpalFreeMessage(response); UpdateWindow(); // Wait for unregister to complete. while ((response = OpalGetMessage(m_opal, 30000)) != NULL) { HandleMessage(*response); if (response->m_type == OpalIndRegistration && response->m_param.m_registrationStatus.m_status == OpalRegisterRemoved) break; } } OpalFreeMessage(response); m_currentAOR.Empty(); m_currentHost.Empty(); } /* Calucalte some configuration strings, determine position of a QCIF window so is in bottom left corner, and a preview window for camera in lower right corner, scaled to fit remaining space. */ static const unsigned videoWidth = 176; static const unsigned videoHeight = 144; CRect box; GetClientRect(&box); CRect commandBox; m_dlgCommandBar.GetWindowRect(&commandBox); box.bottom -= commandBox.Height(); CStringA strVideoOutputDevice; strVideoOutputDevice.Format("MSWIN STYLE=0x%08X PARENT=0x%08X X=%i Y=%i WIDTH=%u HEIGHT=%u", WS_CHILD|WS_BORDER, GetSafeHwnd(), 0, box.Height()-videoHeight, videoWidth, videoHeight); unsigned previewWidth = box.Width() - videoWidth - 2; unsigned previewHeight = previewWidth*videoHeight/videoWidth; CStringA strVideoPreviewDevice; strVideoPreviewDevice.Format("MSWIN STYLE=0x%08X PARENT=0x%08X X=%i Y=%i WIDTH=%u HEIGHT=%u", WS_CHILD|WS_BORDER, GetSafeHwnd(), videoWidth+2, box.Height()-previewHeight, previewWidth, previewHeight); CStringA strMediaOptions; strMediaOptions.Format("Video:Max Bit Rate=128000\n" "Video:Target Bit Rate=128000\n" "Video:Frame Time=9000\n" // 10 frames/second "Video:Frame Width=%u\n" "Video:Frame Height=%u\n" "Video:Max Rx Frame Width=%u\n" "Video:Max Rx Frame Height=%u\n" "H.264:Level=1b\n", videoWidth, videoHeight, videoWidth, videoHeight); // General options memset(&command, 0, sizeof(command)); command.m_type = OpalCmdSetGeneralParameters; CStringA strStunServer = GetOptionStringA(STUNServerKey); command.m_param.m_general.m_stunServer = strStunServer; command.m_param.m_general.m_audioPlayerDevice = "Audio Output"; command.m_param.m_general.m_audioRecordDevice = "Audio Input"; command.m_param.m_general.m_videoInputDevice = "CAM1:"; command.m_param.m_general.m_videoOutputDevice = strVideoOutputDevice; command.m_param.m_general.m_videoPreviewDevice = strVideoPreviewDevice; command.m_param.m_general.m_mediaMask = "RFC4175*\nMPEG4"; command.m_param.m_general.m_mediaOptions = strMediaOptions; command.m_param.m_general.m_autoTxMedia = GetOptionInt(AutoStartTxVideoKey, true) != 0 ? "audio video" : "audio"; command.m_param.m_general.m_rtpMaxPayloadSize = 1400; if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError) ErrorBox(IDS_CONFIGURATION_FAIL, response); OpalFreeMessage(response); // Options across all protocols memset(&command, 0, sizeof(command)); command.m_type = OpalCmdSetProtocolParameters; CStringA strUserName = GetOptionStringA(UserNameKey); command.m_param.m_protocol.m_userName = strUserName; CStringA strDisplayName = GetOptionStringA(UserNameKey); command.m_param.m_protocol.m_displayName = strDisplayName; CStringA interfaceAddress = GetOptionStringA(InterfaceAddressKey, L"*"); command.m_param.m_protocol.m_interfaceAddresses = interfaceAddress; if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError) ErrorBox(IDS_LISTEN_FAIL, response); OpalFreeMessage(response); // H.323 gatekeeper registration memset(&command, 0, sizeof(command)); command.m_type = OpalCmdRegistration; UINT gkType = GetOptionInt(GkTypeKey); if (gkType > 0) { command.m_param.m_registrationInfo.m_protocol = "h323"; CStringA strAliasName = GetOptionStringA(GkAliasKey); command.m_param.m_registrationInfo.m_identifier = strAliasName; CStringA strGkId = GetOptionStringA(GkIdKey); command.m_param.m_registrationInfo.m_adminEntity = strGkId; CStringA strGkHost = GetOptionStringA(GkHostKey); command.m_param.m_registrationInfo.m_hostName = strGkHost; CStringA strGkAuthUser = GetOptionStringA(GkAuthUserKey); command.m_param.m_registrationInfo.m_authUserName = strGkAuthUser; CStringA strGkPassword = GetOptionStringA(GkPasswordKey); command.m_param.m_registrationInfo.m_password = strGkPassword; SetStatusText(IDS_REGISTERING); if ((response = OpalSendMessage(m_opal, &command)) == NULL || response->m_type == OpalIndCommandError) ErrorBox(IDS_REGISTRATION_FAIL, response); OpalFreeMessage(response); } // SIP registrar registration if (strAOR.IsEmpty()) SetStatusText(IDS_READY); else { memset(&command, 0, sizeof(command)); command.m_type = OpalCmdRegistration; command.m_param.m_registrationInfo.m_protocol = "sip"; command.m_param.m_registrationInfo.m_identifier = strAOR; command.m_param.m_registrationInfo.m_hostName = strHost; CStringA strAuthUser = GetOptionStringA(RegistrarUserKey); command.m_param.m_registrationInfo.m_authUserName = strAuthUser; CStringA strPassword = GetOptionStringA(RegistrarPassKey); command.m_param.m_registrationInfo.m_password = strPassword; CStringA strRealm = GetOptionStringA(RegistrarRealmKey); command.m_param.m_registrationInfo.m_adminEntity = strRealm; command.m_param.m_registrationInfo.m_timeToLive = 300; SetStatusText(IDS_REGISTERING); if ((response = OpalSendMessage(m_opal, &command)) != NULL && response->m_type != OpalIndCommandError) { m_currentAOR = strAOR; m_currentHost = strHost; } else { ErrorBox(IDS_REGISTRATION_FAIL, response); SetStatusText(IDS_READY); } OpalFreeMessage(response); } PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE); }
//------------------------------------------------------------------------------ // // Function: PressedReleasedKeys // // Find keys pressed, by comparing old and new state. // Send key events for all changed keys. // VOID PressedReleasedKeys( KeypadDevice_t *pDevice, const DWORD vkState[], const DWORD vkNewState[]) { UINT8 vk; int ic; for (ic = 0, vk = 0; ic < VK_KEYS/DWORD_BITS; ic++) { DWORD change = vkState[ic] ^ vkNewState[ic]; if (change == 0) { vk += DWORD_BITS; } else { DWORD mask; for (mask = 1; mask != 0; mask <<= 1, vk++) { // Check for change if ((change & mask) != 0) { if ((vkNewState[ic] & mask) != 0) { RETAILMSG(1, (L" PressedReleasedKeys: Key Down: 0x%x\r\n", vk)); // Send key down event if (vk != VK_OFF) { SendKeyPadEvent(vk, 0, 0, 0); } } else { RETAILMSG(1, (L" PressedReleasedKeys: Key Up: 0x%x\r\n", vk)); // Need to send the keydown as well as keyup for // device to suspend under cebase. if (pDevice->bEnableOffKey == TRUE && vk == VK_OFF) { SendKeyPadEvent(vk, 0, 0, 0); } // Send key down event if (pDevice->bEnableOffKey != FALSE || vk != VK_OFF) { SendKeyPadEvent(vk, 0, KEYEVENTF_KEYUP, 0); } // send PowerPolicyNotify notification switch (vk) { case VK_TPOWER: case VK_OFF: // only disable interrupts if we are about to enter // a suspend state RETAILMSG(1, (L" PressedReleasedKeys: 0x%02X\r\n", vk)); PowerPolicyNotify(PPN_SUSPENDKEYPRESSED, 0); break; case VK_APPS: case VK_APP1: case VK_APP2: case VK_APP3: case VK_APP4: case VK_APP5: case VK_APP6: PowerPolicyNotify(PPN_APPBUTTONPRESSED, 0); break; } } } } } } }
BOOL WSM_IOControl(DWORD hOpenContext, DWORD dwCode, LPVOID pBufIn, DWORD dwLenIn, LPVOID pBufOut, DWORD dwLenOut, PDWORD pdwActualOut) { DWORD dwSize = 0; BOOL bRet = TRUE; RETAILMSG(1, (TEXT("[WSM] WSM_IOControl : 0x%X \r\n"), dwCode )); switch( dwCode ) { ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Log ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case IOCTL_WIFISVCMGR_LOG_SET_BUFFERSIZE: { DWORD *pdwData = (DWORD*)pBufIn; dwSize = *pdwData; if( WSM_SetLogBufSize(dwSize) == TRUE ) { if( pdwActualOut != NULL ) { *pdwActualOut = g_dwBufSize; } } else { bRet = FALSE; if( pdwActualOut != NULL ) { *pdwActualOut = 0; } } } break; case IOCTL_WIFISVCMGR_LOG_GET_BUFFERSIZE: { DWORD *pdwData = (DWORD*)pBufOut; *pdwData = g_dwBufSize; if( pdwActualOut != NULL ) { *pdwActualOut = g_dwBufSize; } } break; case IOCTL_WIFISVCMGR_LOG_ADD_LOGDATA: if( pBufIn == NULL) { bRet = FALSE; } else { WSM_AddLogData((LPTSTR)pBufIn); } break; case IOCTL_WIFISVCMGR_LOG_FLUSH: if(g_pBuffer) { g_pBuffer[0] = L'\0'; if(g_hFileMap) { if(g_pBuffer) { UnmapViewOfFile(g_pBuffer); g_pBuffer = NULL; } CloseHandle(g_hFileMap); g_hFileMap = NULL; } } else { bRet = FALSE; } break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Ping Checker ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case IOCTL_WIFISVCMGR_PINGCHECKER_START: { if( dwLenIn != sizeof(BBS_BKG_PINGCHECK_OPT) ) { // Invalid Option Size bRet = FALSE; break; } else { PBBS_BKG_PINGCHECK_OPT pPingCheckOpt = (PBBS_BKG_PINGCHECK_OPT)pBufIn; if( WSM_PingCheckerStart(*pPingCheckOpt) == FALSE ) { // Error Ping Start bRet = FALSE; break; } } } break; case IOCTL_WIFISVCMGR_PINGCHECKER_GET_STATUS: { BOOL *pbStatus = (BOOL*)pBufOut; *pbStatus = WSM_IsPingCheckerOperating(); } break; case IOCTL_WIFISVCMGR_PINGCHECKER_STOP: { if( WSM_PingCheckerStop() == FALSE ) { // Error Ping Stop bRet = FALSE; break; } } break; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Unattended Mode Ref ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// case IOCTL_WIFISVCMGR_SET_UNATTENDEDMODE: { BOOL *pbData = (BOOL*)pBufIn; TCHAR tszLogBuf[128] = {0,}; if( *pbData == TRUE ) { // UnattendedMode 를 해제시킨경우만 세팅 if( g_bCheckedUnattendedMode == FALSE ) { if( PowerPolicyNotify(PPN_UNATTENDEDMODE, TRUE) == TRUE ) { g_bCheckedUnattendedMode = TRUE; wsprintf(tszLogBuf, L"UNATTENDEDMODE TRUE \r\n" ); WSM_AddLogData(tszLogBuf); } else { bRet = FALSE; } } } else { // UnattendedMode 를 설정 시킨경우만 해제 if( g_bCheckedUnattendedMode == TRUE ) { if( PowerPolicyNotify(PPN_UNATTENDEDMODE, FALSE) == TRUE ) { DWORD dwCode = 0; g_bCheckedUnattendedMode = FALSE; wsprintf(tszLogBuf, L"UNATTENDEDMODE FALSE \r\n" ); WSM_AddLogData(tszLogBuf); } else { bRet = FALSE; } } } } break; default: break; } return bRet; }
INT WINAPI PowerButtonThread(void) { DWORD nBtnCount = 0; WCHAR state[1024] = {0}; LPWSTR pState = &state[0]; DWORD dwBufChars = (sizeof(state) / sizeof(state[0])); DWORD dwStateFlags = 0; DWORD dwErr; PWRBTN_INF((_T("[PWR:INF] ++PowerButtonThread()\r\n"))); while(!g_bExitThread) { WaitForSingleObject(g_hEventPowerBtn, INFINITE); if(g_bExitThread) { break; } Button_pwrbtn_disable_interrupt(); // Mask EINT Button_pwrbtn_clear_interrupt_pending(); // Clear Interrupt Pending dwErr = GetSystemPowerState(pState, dwBufChars, &dwStateFlags); if (ERROR_SUCCESS != dwErr) { RETAILMSG(1, (TEXT("PMGET!GetSystemPowerState:ERROR:%d\n"), dwErr)); } else { RETAILMSG(1, (TEXT("PMGET! System Power state is '%s', flags 0x%08x\n"), state, dwStateFlags)); } InterruptDone(g_dwSysIntrPowerBtn); #ifndef SLEEP_AGING_TEST while(Button_pwrbtn_is_pushed()) { // Wait for Button Released... Sleep(10); } #endif nBtnCount++; PWRBTN_INF((_T("[PWR] Power Button Event [%d]\r\n"), nBtnCount)); //SetSystemPowerState(NULL, POWER_STATE_SUSPEND, POWER_FORCE); //PowerPolicyNotify(PPN_POWERBUTTONPRESSED,0); if ( wcscmp(state,TEXT("screenoff")) == 0 ) { RETAILMSG(1,(TEXT("setsystempowerstate to ON from screen off\r\n"))); SetSystemPowerState( NULL, POWER_STATE_ON, POWER_FORCE ); } else if ( wcscmp(state,TEXT("backlightoff")) == 0 ) { #ifdef WPC RETAILMSG(1,(TEXT("setsystempowerstate to ON from backlight off\r\n"))); SetSystemPowerState( NULL, POWER_STATE_ON, POWER_FORCE ); #endif #ifdef SMARTFON RETAILMSG(1,(TEXT("setsystempowerstate to IDLE from backlight off\r\n"))); SetSystemPowerState( TEXT("useridle"), POWER_STATE_IDLE, POWER_FORCE ); #endif } else { #ifdef WPC //SetSystemPowerState( NULL, POWER_STATE_SUSPEND, POWER_FORCE ); PowerPolicyNotify(PPN_POWERBUTTONPRESSED,0); #endif #ifdef SMARTFON RETAILMSG(1,(TEXT("setsystempowerstate to IDLE from on\r\n"))); SetSystemPowerState( TEXT("useridle"), POWER_STATE_IDLE, POWER_FORCE ); #endif } Button_pwrbtn_enable_interrupt(); // UnMask EINT #ifdef SLEEP_AGING_TEST Sleep(2000); SetEvent(g_hEventPowerBtn); #endif } PWRBTN_INF((_T("[PWR:INF] --PowerButtonThread()\r\n"))); return 0; }