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

📄 rilhandndis.cpp

📁 windows mobile RIL软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    CloseHandle ( m_rgpNdisEvents.hNdisAddChannelEvent );
    
    return 0;
}

// **************************************************************************
// Function Name: NdisAddNotifyEvent
// 
// Purpose:       Locate an event created when an NDIS channel is opened. Add the
//                event to the update event list and signal the NDIS thread that
//                there are more events to wait for.
//
// Arguments:     IN Handle of the newly created NDIS channel.
//
// Return Values: S_OK if event was found.
//
// Side effects:  
// 
// Description:   
// **************************************************************************

HRESULT CRilNDIS:: NdisAddNotifyEvent(HANDLE hNdisHandle)
{
    TCHAR *pszEventName = NULL;
    HANDLE hHandle;
    HRESULT hr = E_FAIL;

    if ( hNdisHandle )
    {   
        pszEventName = new TCHAR[MAX_NDIS_EVENT_NAME];
    
        if ( pszEventName )
        {
            hr = StringCchPrintf(pszEventName, MAX_NDIS_EVENT_NAME, TEXT("%s%08x"),
                                 TEXT(NDIS_EVENT_PREFIX), hNdisHandle);
        
            if ( SUCCEEDED(hr) )
            {
                hr = E_FAIL; // Reset 
                // Find the event associated with this handle suffix
                hHandle = CreateEvent( NULL, FALSE, FALSE, pszEventName);
                if ( hHandle )
                {  
                    // The event should already exist. If it doesn't, something is wrong.
                    if ( ERROR_ALREADY_EXISTS == GetLastError ())
                    {                
                        EnterCriticalSection(&m_csNdisEventList);
                        // Now we can add the event to the structure and notify the event thread
                        for (int i=0;i<MAX_OEMNDIS_EVENTS;i++)
                        {
                          if (!m_rgpNdisEvents.lpNdisEventHandlesUpdate[i] )
                          {
                            hr = S_OK;
                            m_rgpNdisEvents.lpNdisEventHandlesUpdate[i] = hHandle; // store the handles used for WaitForMultipleObjects
                            m_rgpNdisEvents.lpNdisHandles[i] = hNdisHandle; // store the quick (NDIS) handle parallel to it.
                            SetEvent(m_rgpNdisEvents.hNdisAddChannelEvent );
                            break;
                          }
                        }
                        LeaveCriticalSection(&m_csNdisEventList);
                    }
                    if ( S_OK != hr )
                    {
                        CloseHandle(hHandle);
                    }
                }
            }
            delete [] pszEventName;
        }
    }
    return hr;    
}


// **************************************************************************
// Function Name:   NdisRemoveNotifyEvent
// 
// Purpose:    Locate and remove the event associated with an NDIS channel. This
//             function is called when when the NDIS channel is closed. Remove
//             the event from the update list and signal the NDIS thread that 
//             the list is updated. After the event is removed from the list,
//             shift the list to eliminate any holes.
//                                 
//
// Arguments:  handle associated with the NDIS channel that has been closed.
//
// Return Values:  
//
// Side effects:  
// 
// Description:   
// **************************************************************************  
HRESULT CRilNDIS:: NdisRemoveNotifyEvent(HANDLE hNdisHandle)
{
    HRESULT hr = S_OK;
    BOOL fFound = FALSE;
    
    if ( !hNdisHandle ) 
    {
      hr = E_FAIL;
      goto Error;
    }

    EnterCriticalSection(&m_csNdisEventList);
    
    for (int i=0;i<MAX_OEMNDIS_EVENTS;i++)
    {
        // We search the NDIS handle list, not the event handle list.
        if ( m_rgpNdisEvents.lpNdisHandles[i] == hNdisHandle ) 
        {
            // We don't worry about destroying the object because NDIS radio support does it for us.
            m_rgpNdisEvents.lpNdisEventHandlesUpdate[i] = 0;  // the event handle.
            m_rgpNdisEvents.lpNdisHandles[i] = 0;          // the ndis handle.
            m_rgpNdisEvents.nObjectCount--; // One more thing to wait for.
            fFound = TRUE;
            break;
        }
    }
    
    // Now we have a list of object handles that may have a hole in it. Make a new list without holes.
    // Now we can add the event to the structure and notify the event thread
    for (int i=0;i<MAX_OEMNDIS_EVENTS-1;i++)
    {
        if ( !m_rgpNdisEvents.lpNdisEventHandlesUpdate[i]  )
        {
            if ( m_rgpNdisEvents.lpNdisEventHandlesUpdate[i+1] )
            {
                m_rgpNdisEvents.lpNdisEventHandlesUpdate[i] = m_rgpNdisEvents.lpNdisEventHandlesUpdate[i+1] ;
                m_rgpNdisEvents.lpNdisHandles[i] = m_rgpNdisEvents.lpNdisHandles[i+1];
                m_rgpNdisEvents.lpNdisHandles[i+1] = 0;
                m_rgpNdisEvents.lpNdisEventHandlesUpdate[i+1] = 0;
            }
        }
    }
    
    // Notify the NDIS thread to update the waiting list.
    if ( fFound )
        SetEvent(m_rgpNdisEvents.hNdisAddChannelEvent );
    
    LeaveCriticalSection(&m_csNdisEventList);

Error:
    return hr;
}

// **************************************************************************
// Function Name: NdisInterfaceInitialise
// 
// Purpose:       Emulate a single NDIS Channel
//
// Arguments: 
//
// Return Values:  
//
// Side effects:  
// 
// Description:   
// **************************************************************************
HANDLE  CRilNDIS::NdisInterfaceInitialise (DWORD index)
{
    if ( index >= FIRST_VALID_NDIS_INDEX )
    {
        DEBUGMSG( ZONE_NDIS, (TEXT("RILNDIS: NdisInterfaceInitialise index = %x\r\n"), index));
        return(g_pfnNdisInitialize ( index));
    }
    else
        return NULL;
};

// **************************************************************************
// Function Name:  NdisInterfaceShutdown
// 
// Purpose:        Emulate a single NDIS Channel
//
// Arguments: 
//
// Return Values:  
//
// Side effects:  
// 
// Description:   
// **************************************************************************
BOOL CRilNDIS::NdisInterfaceShutdown (HANDLE handle)
{
    if ( handle )
    {
        DEBUGMSG( ZONE_NDIS, (TEXT("RILNDIS: NdisInterfaceShutdown handle = %x\r\n"),handle));
        return(g_pfnNdisShutdown(handle));
    }
    else
        return FALSE;
};

// **************************************************************************
// Function Name: NdisInterfaceReceiveEvent
// 
// Purpose:       Emulate a single NDIS Channel
//
// Arguments: 
//
// Return Values:  
//
// Side effects:  
// 
// Description:   
// **************************************************************************
BOOL CRilNDIS::NdisInterfaceReceiveEvent(HANDLE handle, OEMNDISEVENT *event_p, BOOL *moreEvents_p)
{
    if ( handle && event_p && moreEvents_p )    
    {
        DEBUGMSG(ZONE_NDIS, (TEXT("RILNDIS: NdisInterfaceReceiveEvent handle = %x\r\n"),handle));
        return(g_pfnNdisReceiveEvent(handle,event_p,moreEvents_p));
    }
    else
        return FALSE;
};

// **************************************************************************
// Function Name:   NdisInterfaceTransmitEvent
// 
// Purpose:         Simulate the operation of and NDIS radio.
//
// Arguments:       IN handle - unique to NDIS channel opened.
//                  IN event_p - defintion of the event being sent.
//
// Return Values:   TRUE if successful.
//
// Side effects:  
// 
// Description:   
// **************************************************************************
 BOOL CRilNDIS::NdisInterfaceTransmitEvent(HANDLE handle, const OEMNDISEVENT *event_p)
{
    BOOL fReturn = FALSE;
    
    if ( handle && event_p )
    {
        fReturn = g_pfnNdisTransmitEvent(handle,event_p);
    
        DEBUGMSG(ZONE_NDIS, (TEXT("RILNDIS: NdisInterfaceTransmitEvent handle = %x Return = %x\r\n"),handle, fReturn));
    }
    
    return fReturn;
};
 
// **************************************************************************
// Function Name:   NdisAllocateCommand
// 
// Purpose:    Allocate an asynchronous command. This method is used
//             when the response will key off of the event type.
//
// Arguments:  IN eType: expected event.
//
// Return Values:  
//
// Side effects:  
// 
// Description:   
// **************************************************************************
void CRilNDIS::NdisAllocateCommand (  OEMNDISEVENTTYPE eType, HANDLE hNdisChannelHandle, LPVOID lpCrilInstance, HRESULT CommandID, DWORD ContextID )
{
    if ( hNdisChannelHandle && lpCrilInstance )
    {
        OEMNDISAPIREFERENCE OemNdisApiReference;
        memset(&OemNdisApiReference,0,sizeof(OemNdisApiReference));
    
        OemNdisApiReference.dwCrilInstance = lpCrilInstance;
        OemNdisApiReference.eEventType = eType;
        OemNdisApiReference.hNdisHandle = hNdisChannelHandle;
        OemNdisApiReference.hrCommandID = CommandID; 
        OemNdisApiReference.ContextID = ContextID;
        m_NdisAsyncCommandList.AddCommand ( &OemNdisApiReference );
    }
}

void
CRilNDIS:: NdisRemoveCommand ( HRESULT hrCommandID )
{
    if ( hrCommandID )
        {
        m_NdisAsyncCommandList.RemoveCommand ( hrCommandID );
        }
}

inline void
CRilNDIS::PdpContextLock()
{
    EnterCriticalSection(&m_PdpContextCriticalSection);
}

inline void
CRilNDIS::PdpContextUnlock()
{
    LeaveCriticalSection(&m_PdpContextCriticalSection);
}

inline BOOL
CRilNDIS::IsPdpContextLocked()
{
    return m_PdpContextCriticalSection.OwnerThread == (HANDLE)GetCurrentThreadId();
}

PPDP_CONTEXT_ENTRY
CRilNDIS::PdpContextEntryGet()
{
    PPDP_CONTEXT_ENTRY pEntry = NULL;

    ASSERT(IsPdpContextLocked());

    if (!IsListEmpty(&m_PdpContextFreeList))
        {
        pEntry = (PPDP_CONTEXT_ENTRY)RemoveHeadList(&m_PdpContextFreeList);
     

⌨️ 快捷键说明

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