Jenaro
Интересующийся
Offline
|
|
« : 18-04-2012 21:25 » |
|
Здравствуйте. Вот заготовка для протокольного драйвера NDIS 6.0. Многие процедуры - просто заглушки, выводящие dbg сообщение. (click to show) #include "ndis.h" #include "ntddk.h"
#define DBG 1
typedef struct _SRP_DX { NDIS_HANDLE hProtocol; } SRP_DX, *PSRP_DX;
VOID DriverUnload(IN PDRIVER_OBJECT DriverObject) {
#ifdef DBG DbgPrint("SRP : DriverUnload called..."); #endif }
NTSTATUS AddDevice(IN PDRIVER_OBJECT DriverObject, PDEVICE_OBJECT pdo) { DbgPrint("SRP : AddDevice started..."); return STATUS_SUCCESS; }
VOID ProtocolDirectOidRequestComplete(IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_OID_REQUEST OidRequest, IN NDIS_STATUS Status) { #ifdef DBG DbgPrint("ProtocolDirectOidRequestComplete called..."); #endif }
VOID ProtocolSendNetBufferListsComplete(IN NDIS_HANDLE ProtocolBindingContext, IN PNET_BUFFER_LIST NetBufferLists, IN ULONG SendCompleteFlags) { #ifdef DBG DbgPrint("ProtocolSendNetBufferListsComplete called..."); #endif }
VOID ProtocolReceiveNetBufferLists(IN NDIS_HANDLE ProtocolBindingContext, IN PNET_BUFFER_LIST NetBufferLists, IN NDIS_PORT_NUMBER PortNumber, IN ULONG NumberOfNetBufferLists, IN ULONG ReceiveFlags) { #ifdef DBG DbgPrint("ProtocolReceiveNetBufferLists called..."); #endif }
VOID ProtocolStatusEx(IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_STATUS_INDICATION StatusIndication) { #ifdef DBG DbgPrint("ProtocolStatusEx called..."); #endif }
VOID ProtocolOidRequestComplete(IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_OID_REQUEST OidRequest, IN NDIS_STATUS Status) { #ifdef DBG DbgPrint("ProtocolOidRequestComplete called..."); #endif }
VOID ProtocolUninstall(VOID) { #ifdef DBG DbgPrint("ProtocolUninstall called..."); #endif
}
NDIS_STATUS ProtocolNetPnPEvent(IN NDIS_HANDLE ProtocolBindingContext, IN PNET_PNP_EVENT_NOTIFICATION NetPnPEvent) { #ifdef DBG DbgPrint("ProtocolNetPnPEvent called..."); #endif return NDIS_STATUS_SUCCESS; }
VOID ProtocolCloseAdapterCompleteEx(IN NDIS_HANDLE ProtocolBindingContext) { #ifdef DBG DbgPrint("ProtocolCloseAdapterComplete called..."); #endif
}
VOID ProtocolOpenAdapterCompleteEx(IN NDIS_HANDLE ProtocolBindingContext, IN NDIS_STATUS Status) { #ifdef DBG DbgPrint("ProtocolOpenAdapterComplete called..."); #endif
}
NDIS_STATUS ProtocolUnbindAdapterEx(IN NDIS_HANDLE UnbindContext, IN NDIS_HANDLE ProtocolBindingContext) { #ifdef DBG DbgPrint("ProtocolUnbindAdapterEx called..."); #endif return NDIS_STATUS_SUCCESS; }
NDIS_STATUS ProtocolBindAdapterEx(IN NDIS_HANDLE ProtocolDriverContext, IN NDIS_HANDLE BindContext, IN PNDIS_BIND_PARAMETERS BindParameters) { NDIS_STATUS status; NDIS_OPEN_PARAMETERS op; NDIS_MEDIUM MediumArray[1] = {NdisMedium802_3}; NET_FRAME_TYPE FrameTypeArray[2] = {NDIS_ETH_TYPE_802_1X, NDIS_ETH_TYPE_802_1Q}; UINT SelectedMediumIndex; NDIS_STRING AdapterName; NDIS_HANDLE hProtocol; NDIS_HANDLE hBinding; NdisInitUnicodeString(&AdapterName, L"\\Device\\{2617D684-898C-4A27-8D6F-8BD15D12430E}"); hProtocol = ((PSRP_DX) ProtocolDriverContext)->hProtocol; #ifdef DBG DbgPrint("ProtocolBindAdapterEx called..."); #endif
NdisZeroMemory(&op, sizeof(NDIS_OPEN_PARAMETERS)); op.Header.Revision = NDIS_OPEN_PARAMETERS_REVISION_1; op.Header.Size = sizeof(NDIS_OPEN_PARAMETERS); op.Header.Type = NDIS_OBJECT_TYPE_OPEN_PARAMETERS; op.AdapterName = &AdapterName; op.MediumArray = &MediumArray[0]; op.MediumArraySize = sizeof(MediumArray) / sizeof(NDIS_MEDIUM); op.SelectedMediumIndex = &SelectedMediumIndex; op.FrameTypeArray = &FrameTypeArray[0]; op.FrameTypeArraySize = sizeof(FrameTypeArray) / sizeof(NET_FRAME_TYPE); //NdisOpenAdapter(&status, &OpenErrorStatus, &hBinding, &SelectedMediumIndex, &MediumArray[0], // sizeof(MediumArray) / sizeof(NDIS_MEDIUM), hProtocol, NULL, &AdapterName, 0, NULL); status = NdisOpenAdapterEx(hProtocol, NULL, &op, NULL, &hBinding); if(status == NDIS_STATUS_PENDING) { DbgPrint("SRP : NdisOpenAdapterEx success."); } else { DbgPrint("SRP : NdisOpenAdapterEx failed."); } return NDIS_STATUS_SUCCESS; }
NDIS_STATUS ProtocolSetOptions(IN NDIS_HANDLE NdisDriverHandle, IN NDIS_HANDLE DriverContext) { #ifdef DBG DbgPrint("SRP : ProtocolSetOptions called..."); #endif return NDIS_STATUS_SUCCESS; }
NDIS_STATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { NDIS_STATUS status; NDIS_STATUS OpenErrorStatus; NDIS_HANDLE hProtocol; NDIS_PROTOCOL_DRIVER_CHARACTERISTICS ch;
NDIS_STRING ProtocolName;
PDEVICE_OBJECT ProtocolDeviceObject; UNICODE_STRING ProtocolDeviceName; PSRP_DX pdx; NDIS_HANDLE ProtocolDriverContext={0};
NdisInitUnicodeString(&ProtocolName, L"SRP1"); NdisInitUnicodeString(&ProtocolDeviceName, L"\\Device\\srp_dev");
DriverObject->DriverExtension->AddDevice = AddDevice; DriverObject->DriverUnload = DriverUnload; status = IoCreateDevice(DriverObject, sizeof(SRP_DX), &ProtocolDeviceName, FILE_DEVICE_NETWORK, 0, FALSE, &ProtocolDeviceObject); if(status == STATUS_SUCCESS) { DbgPrint("SRP : protocol device created successful."); } else { DbgPrint("SRP : protocol device creating failed. status %08X", status); } ch.Header.Type = NDIS_OBJECT_TYPE_PROTOCOL_DRIVER_CHARACTERISTICS; ch.Header.Revision = NDIS_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_1; ch.Header.Size = NDIS_SIZEOF_PROTOCOL_DRIVER_CHARACTERISTICS_REVISION_1; ch.MajorNdisVersion = 6; ch.MinorNdisVersion = 0; ch.MajorDriverVersion = 1; ch.MinorDriverVersion = 0; ch.Flags = 0; ch.Name = ProtocolName; ch.SetOptionsHandler = 0; ch.BindAdapterHandlerEx = ProtocolBindAdapterEx; ch.UnbindAdapterHandlerEx = ProtocolUnbindAdapterEx; ch.OpenAdapterCompleteHandlerEx = ProtocolOpenAdapterCompleteEx; ch.CloseAdapterCompleteHandlerEx = ProtocolCloseAdapterCompleteEx; ch.NetPnPEventHandler = ProtocolNetPnPEvent; ch.UninstallHandler = ProtocolUninstall; ch.OidRequestCompleteHandler = ProtocolOidRequestComplete; ch.StatusHandlerEx = ProtocolStatusEx; ch.ReceiveNetBufferListsHandler = ProtocolReceiveNetBufferLists; ch.SendNetBufferListsCompleteHandler = ProtocolSendNetBufferListsComplete;
pdx = (PSRP_DX) DriverObject->DeviceObject->DeviceExtension; status = NdisRegisterProtocolDriver(pdx, &ch, &hProtocol); if(status != NDIS_STATUS_SUCCESS) { #ifdef DBG DbgPrint("SRP : protocol registering failed. %08X", status); status = STATUS_UNSUCCESSFUL; #endif } else { #ifdef DBG DbgPrint("SRP : protocol registered successful."); #endif pdx->hProtocol = hProtocol; }
return status; }
При запуске сервиса (стандартными средствами win 7) происходит вызов DriverEntry, а затем сразу ProtocolNetPnPEvent, а ProtocolBindAdapterEx не вызывается вовсе. Хотелось бы знать , почему так происходит, чего не хватает?
|