⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ethman.c

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 C
📖 第 1 页 / 共 2 页
字号:
        DEBUGMSG(ZONE_VERBOSE, (TEXT("EthMan: Connection established. IP = %s.\r\n"), pszIpAddress));        
        
        hCallMonThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CallMonThread, (LPVOID)hNdisUio, 0, NULL);
        if (NULL == hCallMonThread)
        {
            DEBUGMSG(ZONE_ERROR, (TEXT("EthMan: Error creating the call mon thread\r\n")));
            goto Error;
        }

        SetPowerMode(hNdisUio, pszDeviceName, Ndis802_11PowerModeMAX_PSP);

        g_fInitialized = TRUE;
        
        g_hNdisUio = hNdisUio;
        hNdisUio = INVALID_HANDLE_VALUE;

        g_pszDeviceName = pszDeviceName;
        pszDeviceName = NULL;

        g_pszIPAddress = pszIpAddress;
        pszIpAddress = NULL;
    }


Error:

    if (!g_fInitialized)
    {
        if (pszDeviceName != NULL && 
            pszDeviceName[0] != TEXT('\0') && 
            hNdisUio != INVALID_HANDLE_VALUE)
        {
            // Let's put the WiFi card to deep sleep
            RETAILMSG(ZONE_ERROR, (TEXT("EthMan: Unable to initialize - putting WiFi chip into deep sleep\r\n")));
            SetDeepSleep(hNdisUio, pszDeviceName, TRUE);
        }
    }

    if (INVALID_HANDLE_VALUE != hNdisUio)
        CloseHandle(hNdisUio);

    if (NULL != pszDeviceName)
        LocalFree(pszDeviceName);

    if (NULL != pszIpAddress)
        LocalFree(pszIpAddress);
    
    return 1;
}



DWORD
ETM_Init(
  LPCTSTR pContext,
  LPCVOID lpvBusContext)
{
    HANDLE hThread = NULL;
    
    g_fInitialized = FALSE;
    g_dwIpAddress = 0;
    hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)InitThread, NULL, 0, NULL);
    if (NULL != hThread)
    {
        CloseHandle(hThread);
    }
    else
    {
        DEBUGMSG(ZONE_ERROR, (TEXT("Ethman: ETM_Init: Could not create Init thread. Err = %d \r\n"), GetLastError()));
        return 0;
    }

    g_HostWakeSet = FALSE;

    return 1;
}


BOOL
ETM_Deinit(
  DWORD hDeviceContext)
{
    return(TRUE);
}

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

DWORD
ETM_Open(
  DWORD hDeviceContext,
  DWORD AccessCode,
  DWORD ShareMode)

{
    return hDeviceContext;
}

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

BOOL
ETM_Close(
  DWORD hOpenContext )
{
    return TRUE;
}

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

DWORD
ETM_Read(
  DWORD hOpenContext,
  LPVOID pBuffer,
  DWORD Count)
{
    DEBUGMSG(ZONE_VERBOSE, (TEXT("ETM_Read()\r\n")));
    return((DWORD) -1);
}


// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

DWORD
ETM_Write(
  DWORD hOpenContext,
  LPCVOID pBuffer,
  DWORD Count)
{
    DEBUGMSG(ZONE_VERBOSE, (TEXT("ETM_Write()\r\n")));
    return((DWORD) -1);
}



// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

DWORD
ETM_Seek(
  DWORD hOpenContext,
  long Amount,
  WORD Type)
{
    DEBUGMSG(ZONE_VERBOSE, (TEXT("ETM_Seek()\r\n")));
    return((DWORD) -1);
}

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

void
ETM_PowerUp(DWORD hDeviceContext)
{
    DEBUGMSG(ZONE_VERBOSE, (TEXT("ETM_PowerUp()\r\n")));
}

// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

void
ETM_PowerDown(
  DWORD hDeviceContext)
{
    DEBUGMSG(ZONE_VERBOSE, (TEXT("ETM_PowerDown()\r\n")));
}


// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

BOOL
ETM_IOControl(
  DWORD hOpenContext,
  DWORD dwCode,
  PBYTE pBufIn,
  DWORD dwLenIn,
  PBYTE pBufOut,
  DWORD dwLenOut,
  PDWORD pdwActualOut)
{
    BOOL fRetVal = FALSE;
    DWORD dwIpAddr;
    SETFNAME(_T("ETM_IOControl"));
    
    switch(dwCode)
    {
        case IOCTL_POWER_CAPABILITIES:
            // tell the power manager about ourselves.
            DEBUGMSG(ZONE_VERBOSE, (TEXT("%s: IOCTL_POWER_CAPABILITIES\r\n"), pszFname));
            if (pBufOut != NULL 
                && dwLenOut >= sizeof(POWER_CAPABILITIES) 
                && pdwActualOut != NULL) {
                __try {
                    PPOWER_CAPABILITIES ppc = (PPOWER_CAPABILITIES) pBufOut;
                    // the sample driver has:
                    //  no power consumption
                    //  no power & latency
                    //  no device wake caps
                    //  no inrush
                    memset(ppc, 0, sizeof(*ppc));
                    ppc->DeviceDx = 0x1F;   // support D0-D4
                    *pdwActualOut = sizeof(*ppc);
                    fRetVal = TRUE;
                }
                __except(EXCEPTION_EXECUTE_HANDLER) {
                    DEBUGMSG(ZONE_ERROR, (_T("%s: exception in ioctl\r\n")));
                }
            }

            break;
            
        case IOCTL_POWER_QUERY: 
            if(pBufOut != NULL 
                && dwLenOut == sizeof(CEDEVICE_POWER_STATE) 
                && pdwActualOut != NULL) {
                __try {
                    CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE) pBufOut;
                    if(VALID_DX(NewDx)) {
                        // this is a valid Dx state so return a good status
                        *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
                        fRetVal = TRUE;
                    }
                    DEBUGMSG(ZONE_VERBOSE, (_T("%s: IOCTL_POWER_QUERY %u %s\r\n"), pszFname, 
                        NewDx, fRetVal == TRUE ? _T("succeeded") : _T("failed")));
                } 
                __except(EXCEPTION_EXECUTE_HANDLER) {
                    DEBUGMSG(ZONE_ERROR, (_T("%s: exception in ioctl\r\n")));
                }
            }
            break;
            
        case IOCTL_POWER_SET: 
            if(pBufOut != NULL 
                && dwLenOut == sizeof(CEDEVICE_POWER_STATE) 
                && pdwActualOut != NULL) {

                // For this WiFi power manager sample, all we really care about are the transitions
                // to D3 (device going to suspend) and from D3 to D0 (Waking up from suspend into
                // full on mode). This is so that we can configure the WiFi driver/device for HostWakeMode
                // (WiFi Wake-on-LAN equivalent). The reason why HostWakeMode setup has to be
                // done here is that IOCTL_POWER_SET call is the only place where the power manager
                // will wait for the call to return before proceeding with the suspend operation. Other
                // power notifications are not guaranteed to be processed before the device actually
                // goes into suspend.
                //
                __try {
                    CEDEVICE_POWER_STATE NewDx = *(PCEDEVICE_POWER_STATE) pBufOut;
                    DEBUGMSG(ZONE_VERBOSE, (TEXT("%s: IOCTL_POWER_SET\r\n"), pszFname));
                    if(VALID_DX(NewDx)) {

                        if(g_fInitialized && NewDx == D3 && !g_HostWakeSet) 
                        {
                            DEBUGMSG(ZONE_VERBOSE, (TEXT("Ethman: Preparing for suspend.\r\n")));
                            GetIpAddr(&dwIpAddr);
                            QueryPowerMode(g_hNdisUio, g_pszDeviceName, &g_ulOrigPowerMode);
                            PrepareForHostSleep(g_hNdisUio, g_pszDeviceName, dwIpAddr);
                        }

                        if (g_fInitialized && NewDx != D3 && g_CurrentDx == D3 && g_HostWakeSet)
                        {
                            DEBUGMSG(ZONE_VERBOSE, (TEXT("Ethman: Recovering from suspend.\r\n")));
                            RecoverFromHostSleep(g_hNdisUio, g_pszDeviceName);
                            SetPowerMode(g_hNdisUio, g_pszDeviceName, g_ulOrigPowerMode);
                        }
                        
                        g_CurrentDx = NewDx;
                        fRetVal = TRUE;
                    }
                } 
                __except(EXCEPTION_EXECUTE_HANDLER) {
                    DEBUGMSG(ZONE_ERROR, (_T("%s: exception in ioctl\r\n")));
                }

            }
            break;
            
        case IOCTL_POWER_GET: 
            if(pBufOut != NULL 
                && dwLenOut == sizeof(CEDEVICE_POWER_STATE) 
                && pdwActualOut != NULL) {
                // just return our CurrentDx value
                __try {
                    *(PCEDEVICE_POWER_STATE) pBufOut = g_CurrentDx;
                    *pdwActualOut = sizeof(CEDEVICE_POWER_STATE);
                    fRetVal = TRUE;
                    DEBUGMSG(ZONE_VERBOSE, (_T("%s: IOCTL_POWER_GET %s; passing back %u\r\n"), pszFname, 
                        fRetVal == TRUE? _T("succeeded") : _T("failed"), g_CurrentDx));
                }
                __except(EXCEPTION_EXECUTE_HANDLER) {
                    DEBUGMSG(ZONE_ERROR, (_T("%s: exception in ioctl\r\n")));
                }
            }
            break;


        default:
            SetLastError(ERROR_NOT_SUPPORTED);
    }

    return fRetVal;
}


BOOL WINAPI DllMain(HANDLE hinstDLL,
    DWORD dwReason,
    LPVOID lpvReserved)
{
    switch(dwReason)
    {
        case DLL_PROCESS_ATTACH :
            RETAILREGISTERZONES(hinstDLL);

            g_hMod = (HMODULE)hinstDLL;

            // don't need thread attach/detach messages
            DisableThreadLibraryCalls (hinstDLL);              
            break;

        default:
            break;
    }

    return TRUE;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -