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

📄 ndisloader.cpp

📁 此压缩包为杰得开发得z228的BSP的源代码,可以实现很多功能,尤其是视频解码有很好的效果.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
///////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2002 BSQUARE Corporation.  All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT 
// WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 
// INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
// MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
//
// Module Name:
//
//    NDISLoader.cpp
//
// Abstract:
//
//    Streams portion of the NDIS sample
//
// Notes:
//
///////////////////////////////////////////////////////////////////////////////

#ifdef IF_SDIO

#include "SDCardDDK.h"
#include "sdndis.h"

#define MAX_MINIPORT_NAME_PATH  256
#define MAX_NUMBER_OF_ADAPTERS  8
#define LOADER_INSTANCE_KEY TEXT("Instance")
#include "precomp.h"

//#define MRV_DRV_LOGFILE

// this was in driver entry file of the NDISSample
// initialize debug zones
SD_DEBUG_INSTANTIATE_ZONES(
     TEXT("Marvell SDIO"), // module name
     ZONE_ENABLE_INIT | ZONE_ENABLE_ERROR | ZONE_ENABLE_WARN | ENABLE_ZONE_SEND,    // initial settings
     TEXT(""),
     TEXT(""), 
     TEXT(""), 
     TEXT(""),                  
     TEXT(""), 
     TEXT(""), 
     TEXT(""), 
     TEXT(""),
     TEXT(""),
     TEXT(""),
     TEXT(""));

    // miniport instance information
typedef struct _MINIPORT_INSTANCE_INFO {
    WCHAR  MiniportName[MAX_MINIPORT_NAME_PATH];
    WCHAR  MiniportInstance[MAX_MINIPORT_NAME_PATH];
    WCHAR  RegPath[MAX_MINIPORT_NAME_PATH];
    WCHAR  ActiveKeyPath[MAX_MINIPORT_NAME_PATH];
    ULONG  InstanceNumber;
}MINIPORT_INSTANCE_INFO, *PMINIPORT_INSTANCE_INFO;

BOOL AllocatedInstance[MAX_NUMBER_OF_ADAPTERS];

CRITICAL_SECTION    LoaderCriticalSection;

///////////////////////////////////////////////////////////////////////////////
//  LoaderEntry - init loader
//  Input:  hInstance - the instance that is attaching
//          Reason - the reason for attaching
//          pReserved - not much
//  Output: 
//  Return: Always returns TRUE
//  Notes:  this is only used to initialize the zones
///////////////////////////////////////////////////////////////////////////////
BOOL LoaderEntry(HINSTANCE  hInstance,
                 ULONG      Reason,
                 LPVOID     pReserved)
{
    if ( Reason == DLL_PROCESS_ATTACH ) {
        DEBUGREGISTER(hInstance);
        InitializeCriticalSection(&LoaderCriticalSection);
        memset(&AllocatedInstance,0, sizeof(AllocatedInstance));
    }

    if ( Reason == DLL_PROCESS_DETACH ) {
        DeleteCriticalSection(&LoaderCriticalSection);
    }

    return(TRUE);
}


///////////////////////////////////////////////////////////////////////////////
//  LoadMiniport - load the miniport for this instance
//  Input:  pInstance - information for this instance
//  Output: 
//  Return: TRUE if successful
//  Notes:  
///////////////////////////////////////////////////////////////////////////////
BOOL LoadMiniport(PMINIPORT_INSTANCE_INFO pInstance)
{
    HKEY     hKey;              // registry key
    DWORD    win32Status;       // status  
    DWORD    dataSize;          // data size for query
    WCHAR    stringBuff[128];   // string buffer
    WCHAR    instanceKey[32];   // instance name
    WCHAR    instanceNumber[10];    // instance number
    WCHAR    *token;                // tokenizer
    NDIS_STATUS NdisStatus;         // ndis status
    
 //  MessageBox(NULL, TEXT("SDIO init"), TEXT("LoadMiniport"), MB_OK);

        // open the registry path for this instance
    if ((win32Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                                    pInstance->RegPath,
                                    0,
                                    KEY_ALL_ACCESS,
                                    &hKey)) != ERROR_SUCCESS) {
        DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR:Failed to open path %s; %d \n"), 
                   pInstance->RegPath, win32Status));

        
        return FALSE;
    }

//    MessageBox(NULL, TEXT("SDIO init"), TEXT("1"), MB_OK);
    dataSize = sizeof(stringBuff);

        // build up the instance key
    wcscpy(instanceKey,LOADER_INSTANCE_KEY);
    _ultow(pInstance->InstanceNumber, instanceNumber, 10);
    wcscat(instanceKey, instanceNumber);

        // retrieve the real reg path to the device parameters
    if (RegQueryValueEx(hKey, 
                        instanceKey, 
                        0, 
                        NULL, 
                        (PUCHAR)stringBuff, 
                        &dataSize) != ERROR_SUCCESS) {
        DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to get the instance key : %d \n"), instanceKey));
        RegCloseKey(hKey);
        return FALSE;
    }

//    MessageBox(NULL, TEXT("SDIO init"), TEXT("2"), MB_OK);
        // don't need this anymore
    RegCloseKey(hKey);

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Tokenizing instance information: %s \n"), stringBuff));
      
        // extract the miniport name and instance name, in the form of "<Miniport Name>:<Miniport Instance>
    token = wcstok(stringBuff, TEXT(":"));

    if (token != NULL) {

        wcscpy(pInstance->MiniportName, token);
        
            // search for the next one
        token = wcstok( NULL, TEXT(":"));

        if (token != NULL) {
            wcscpy(pInstance->MiniportInstance, token);
        } else {
             DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to get miniport instance \n")));
             return FALSE;
        }

    } else {
        DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to get miniport name \n")));
        return FALSE;
    }
   
//    MessageBox(NULL, TEXT("SDIO init"), TEXT("3"), MB_OK);
        // build up the miniport instance path in order to stick in the "ActivePath" key
    wcscpy(stringBuff,TEXT("\\Comm\\"));
    wcscat(stringBuff,pInstance->MiniportInstance);
    wcscat(stringBuff,TEXT("\\Parms"));

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Miniport instance path %s \n"), stringBuff));
   
    if ((win32Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                                    stringBuff,
                                    0,
                                    KEY_ALL_ACCESS,
                                    &hKey)) != ERROR_SUCCESS) {
        DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR:Failed to open path %s; %d \n"), 
                   stringBuff, win32Status));
        return FALSE;
    }

//    MessageBox(NULL, TEXT("SDIO init"), TEXT("4"), MB_OK);
        // make sure the key is deleted first
    RegDeleteKey(hKey, TEXT("ActivePath")); 
//    RegDeleteValue(hKey, TEXT("ActivePath")); 
//    MessageBox(NULL, TEXT("SDIO init"), TEXT("4"), MB_OK);

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Storing ActiveKey Path %s \n"), pInstance->ActiveKeyPath));

        // save the active ActivePath in the registry path for the miniport.  The miniport
        // portion will look up this key
    if (RegSetValueEx(hKey, 
                      TEXT("ActivePath"), 
                      0, 
                      REG_SZ, 
                      (PUCHAR)pInstance->ActiveKeyPath, 
                      ((sizeof(WCHAR))*(wcslen(pInstance->ActiveKeyPath) + 1))) != ERROR_SUCCESS) { 
        DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR: Failed to set ActiveKey path \n")));
        RegCloseKey(hKey);
        return FALSE;
    }

//    MessageBox(NULL, TEXT("SDIO init"), TEXT("5"), MB_OK);
        // close the key
    RegCloseKey(hKey);

//    MessageBox(NULL, pInstance->MiniportName, pInstance->MiniportInstance, MB_OK);

        // register the adapter
    NdisRegisterAdapter(&NdisStatus,
                        pInstance->MiniportName,
                        pInstance->MiniportInstance);

    if (!NDIS_SUCCESS(NdisStatus)) {
        return FALSE;
    }

	DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: NdisRegisterAdapter Returned.\n")));

//    MessageBox(NULL, TEXT("SDIO init"), TEXT("6"), MB_OK);
    return TRUE;
   
}

///////////////////////////////////////////////////////////////////////////////
//  UnloadMiniport - unload the miniport
//  Input:   pInstance - the instance to unload
//  Output: 
//  Return: 
//  Notes:  
///////////////////////////////////////////////////////////////////////////////
VOID UnloadMiniport(PMINIPORT_INSTANCE_INFO pInstance)
{
    NDIS_STATUS NdisStatus;
	HKEY     hKey;              // registry key
    DWORD    win32Status;       // status  
    WCHAR    stringBuff[128];   // string buffer

    DbgPrintZo(SDCARD_ZONE_INIT, 
        (TEXT("SDNDISLDR: Unloading Miniport Instance %s \n"), 
        pInstance->MiniportInstance));
   
    NdisDeregisterAdapter(&NdisStatus, pInstance->MiniportInstance);

    DbgPrintZo(SDCARD_ZONE_INIT, 
        (TEXT("SDNDISLDR: Miniport Unloaded 0x%08X \n"), 
        NdisStatus));

	    wcscpy(stringBuff,TEXT("\\Comm\\"));
    wcscat(stringBuff,pInstance->MiniportInstance);
    wcscat(stringBuff,TEXT("\\Parms"));

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Miniport instance path %s \n"), stringBuff));
   
    if ((win32Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                                    stringBuff,
                                    0,
                                    KEY_ALL_ACCESS,
                                    &hKey)) != ERROR_SUCCESS) {
        DbgPrintZo(SDCARD_ZONE_ERROR, (TEXT("SDNDISLDR:Failed to open path %s; %d \n"), 
                   stringBuff, win32Status));
        return;
    }

//    MessageBox(NULL, TEXT("SDIO init"), TEXT("4"), MB_OK);
        // make sure the key is deleted first
    RegDeleteValue(hKey, TEXT("ActivePath")); 

    DbgPrintZo(SDCARD_ZONE_INIT, (TEXT("SDNDISLDR: Storing ActiveKey Path %s \n"), pInstance->ActiveKeyPath));
	
	RegCloseKey(hKey);
}

⌨️ 快捷键说明

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