Problem retrieving physical mac address on Windows 2000.

Hi folks!
I’m writing a ndis driver to retrieve the physical mac address from the
ethernet adapters installed on the system.
My driver works fine on Windows XP but fails on Windows 2000. I didn’t have
a chance to test it on Windows Vista x86 yet.

This is part of the code I wrote:

*//-------------------------------------------------------------------
NTSTATUS ConfigureAndRegisterProtocol( NDIS50_PROTOCOL_CHARACTERISTICS*
pProtChar )
{
ULONG MajorVersion;
ULONG MinorVersion;
UINT ProtocolSize;
NTSTATUS Status = STATUS_UNSUCCESSFUL;

PsGetVersion( &MajorVersion, &MinorVersion, NULL, NULL );
NdisZeroMemory( pProtChar, sizeof ( NDIS50_PROTOCOL_CHARACTERISTICS ) );

if ( MajorVersion == 4 )
{
ProtocolSize = sizeof( NDIS30_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 3;
}

if ( MajorVersion == 5 )
{
if ( MinorVersion == 0 )
{
ProtocolSize = sizeof( NDIS40_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 4;
}

if ( MinorVersion == 1 || MinorVersion == 2 )
{
ProtocolSize = sizeof( NDIS50_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 5;
}

if ( MinorVersion > 2 )
{
return STATUS_UNSUCCESSFUL;
}
}

pProtChar->OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
pProtChar->CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
pProtChar->RequestCompleteHandler = NdisProtRequestComplete;
pProtChar->Name = g_ProtoName;

pProtChar->BindAdapterHandler = NdisProtBindAdapter;
pProtChar->UnbindAdapterHandler = NdisProtUnbindAdapter;

NdisRegisterProtocol( (PNDIS_STATUS)&Status, &g_NdisProtHandle,
pProtChar, ProtocolSize );
if ( Status != NDIS_STATUS_SUCCESS )
{
return STATUS_UNSUCCESSFUL;
}
else
{
g_AdapterProtocolRegistered = TRUE;
return STATUS_SUCCESS;
}

return STATUS_SUCCESS;
}*

*//-------------------------------------------------------------------
VOID UtilOpenAdapter( IN PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status, OpenError;
UINT MediumIndex, ArraySize;
NDIS_MEDIUM MediumArray;
LARGE_INTEGER timeout;

timeout.QuadPart = -5 * 10 * 1000 * 100;
MediumArray = NdisMedium802_3;
ArraySize = 0x1;

NdisOpenAdapter( &Status, &OpenError, &pAdapter->AdapterBindingHandle,
&MediumIndex, &MediumArray, ArraySize,
g_NdisProtHandle, (NDIS_HANDLE)pAdapter,
(PNDIS_STRING)&pAdapter->AdapterName, 0x0, NULL);

if ( Status != STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_OPEN_PENDING;
Status = KeWaitForSingleObject( &pAdapter->AdapterEvent,
Executive, KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_SUCCESS;
}
}*

*//-------------------------------------------------------------------
VOID UtilRequestMacAddress( PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status;
LARGE_INTEGER timeout;
PNDIS_REQUEST pAdapterRequest = &pAdapter->AdapterReq;

timeout.QuadPart = -5 * 10 * 1000 * 100;

// Inicializa evento de espera
KeInitializeEvent( &pAdapter->AdapterEvent, NotificationEvent, FALSE );

// Preencha a estrutura NDIS_REQUEST
pAdapterRequest->RequestType = NdisRequestQueryInformation;

pAdapterRequest->DATA.QUERY_INFORMATION.Oid =
OID_802_3_PERMANENT_ADDRESS;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBuffer =
&pAdapter->AdapterMacAddress;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBufferLength =
sizeof( pAdapter->AdapterMacAddress );

NdisRequest( &Status, pAdapter->AdapterBindingHandle, pAdapterRequest );
if ( Status != NDIS_STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive,
KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
}*

On the function *UtilRequestMacAddress *when I execute the NdisRequest
Function on Windows 2000 the Status always returns *NDIS_STATUS_PENDING *(*
*0x06 ).
Even if I call *KeWaitForSingleObject *with NULL at the timeout to wait
infinitely, I keep getting 0x06 and the request does not succeed.
I’m new to driver development so I’m really stuck on this problem. So I
decided to ask the experts some hints.

Can you guys point me the mistakes I made in this code?
Thanks in advance!
Silvio.

Where do you set the pAdapter->AdapterEvent? Can you post the code of
NdisProtRequestComplete?

Have a nice day
GV


Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com

----- Original Message -----
From: Silvio Reis Junior
To: Windows System Software Devs Interest List
Sent: Thursday, July 24, 2008 7:08 AM
Subject: [ntdev] Problem retrieving physical mac address on Windows 2000.

Hi folks!
I’m writing a ndis driver to retrieve the physical mac address from the
ethernet adapters installed on the system.
My driver works fine on Windows XP but fails on Windows 2000. I didn’t have
a chance to test it on Windows Vista x86 yet.

This is part of the code I wrote:

//-------------------------------------------------------------------
NTSTATUS ConfigureAndRegisterProtocol( NDIS50_PROTOCOL_CHARACTERISTICS*
pProtChar )
{
ULONG MajorVersion;
ULONG MinorVersion;
UINT ProtocolSize;
NTSTATUS Status = STATUS_UNSUCCESSFUL;

PsGetVersion( &MajorVersion, &MinorVersion, NULL, NULL );
NdisZeroMemory( pProtChar, sizeof ( NDIS50_PROTOCOL_CHARACTERISTICS ) );

if ( MajorVersion == 4 )
{
ProtocolSize = sizeof( NDIS30_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 3;
}

if ( MajorVersion == 5 )
{
if ( MinorVersion == 0 )
{
ProtocolSize = sizeof( NDIS40_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 4;
}

if ( MinorVersion == 1 || MinorVersion == 2 )
{
ProtocolSize = sizeof( NDIS50_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 5;
}

if ( MinorVersion > 2 )
{
return STATUS_UNSUCCESSFUL;
}
}

pProtChar->OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
pProtChar->CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
pProtChar->RequestCompleteHandler = NdisProtRequestComplete;
pProtChar->Name = g_ProtoName;

pProtChar->BindAdapterHandler = NdisProtBindAdapter;
pProtChar->UnbindAdapterHandler = NdisProtUnbindAdapter;

NdisRegisterProtocol( (PNDIS_STATUS)&Status, &g_NdisProtHandle,
pProtChar, ProtocolSize );
if ( Status != NDIS_STATUS_SUCCESS )
{
return STATUS_UNSUCCESSFUL;
}
else
{
g_AdapterProtocolRegistered = TRUE;
return STATUS_SUCCESS;
}

return STATUS_SUCCESS;
}

//-------------------------------------------------------------------
VOID UtilOpenAdapter( IN PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status, OpenError;
UINT MediumIndex, ArraySize;
NDIS_MEDIUM MediumArray;
LARGE_INTEGER timeout;

timeout.QuadPart = -5 * 10 * 1000 * 100;
MediumArray = NdisMedium802_3;
ArraySize = 0x1;

NdisOpenAdapter( &Status, &OpenError, &pAdapter->AdapterBindingHandle,
&MediumIndex, &MediumArray, ArraySize,
g_NdisProtHandle, (NDIS_HANDLE)pAdapter,
(PNDIS_STRING)&pAdapter->AdapterName, 0x0, NULL);

if ( Status != STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_OPEN_PENDING;
Status = KeWaitForSingleObject( &pAdapter->AdapterEvent,
Executive, KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_SUCCESS;
}
}

//-------------------------------------------------------------------
VOID UtilRequestMacAddress( PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status;
LARGE_INTEGER timeout;
PNDIS_REQUEST pAdapterRequest = &pAdapter->AdapterReq;

timeout.QuadPart = -5 * 10 * 1000 * 100;

// Inicializa evento de espera
KeInitializeEvent( &pAdapter->AdapterEvent, NotificationEvent, FALSE );

// Preencha a estrutura NDIS_REQUEST
pAdapterRequest->RequestType = NdisRequestQueryInformation;

pAdapterRequest->DATA.QUERY_INFORMATION.Oid =
OID_802_3_PERMANENT_ADDRESS;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBuffer =
&pAdapter->AdapterMacAddress;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBufferLength =
sizeof( pAdapter->AdapterMacAddress );

NdisRequest( &Status, pAdapter->AdapterBindingHandle, pAdapterRequest );
if ( Status != NDIS_STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive,
KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
}

On the function UtilRequestMacAddress when I execute the NdisRequest
Function on Windows 2000 the Status always returns NDIS_STATUS_PENDING (
0x06 ).
Even if I call KeWaitForSingleObject with NULL at the timeout to wait
infinitely, I keep getting 0x06 and the request does not succeed.
I’m new to driver development so I’m really stuck on this problem. So I
decided to ask the experts some hints.

Can you guys point me the mistakes I made in this code?
Thanks in advance!
Silvio.

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Sure!
*
VOID NdisProtRequestComplete( IN NDIS_HANDLE ProtocolBindingContext, IN
PNDIS_REQUEST NdisRequest,IN NDIS_STATUS Status )
{
PADAPTER_INFORMATION pAdapter =
(PADAPTER_INFORMATION)ProtocolBindingContext;
if ( Status == NDIS_STATUS_SUCCESS )
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
KeSetEvent( &pAdapter->AdapterEvent, IO_NO_INCREMENT, FALSE );
}*

On Thu, Jul 24, 2008 at 12:49 PM, Gianluca Varenni <
xxxxx@gmail.com> wrote:

Where do you set the pAdapter->AdapterEvent? Can you post the code of
NdisProtRequestComplete?

Have a nice day
GV


Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com

----- Original Message ----- From: Silvio Reis Junior
To: Windows System Software Devs Interest List
Sent: Thursday, July 24, 2008 7:08 AM
Subject: [ntdev] Problem retrieving physical mac address on Windows 2000.

Hi folks!
I’m writing a ndis driver to retrieve the physical mac address from the
ethernet adapters installed on the system.
My driver works fine on Windows XP but fails on Windows 2000. I didn’t have
a chance to test it on Windows Vista x86 yet.

This is part of the code I wrote:

//-------------------------------------------------------------------
NTSTATUS ConfigureAndRegisterProtocol( NDIS50_PROTOCOL_CHARACTERISTICS*
pProtChar )
{
ULONG MajorVersion;
ULONG MinorVersion;
UINT ProtocolSize;
NTSTATUS Status = STATUS_UNSUCCESSFUL;

PsGetVersion( &MajorVersion, &MinorVersion, NULL, NULL );
NdisZeroMemory( pProtChar, sizeof ( NDIS50_PROTOCOL_CHARACTERISTICS ) );

if ( MajorVersion == 4 )
{
ProtocolSize = sizeof( NDIS30_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 3;
}

if ( MajorVersion == 5 )
{
if ( MinorVersion == 0 )
{
ProtocolSize = sizeof( NDIS40_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 4;
}

if ( MinorVersion == 1 || MinorVersion == 2 )
{
ProtocolSize = sizeof( NDIS50_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 5;
}

if ( MinorVersion > 2 )
{
return STATUS_UNSUCCESSFUL;
}
}

pProtChar->OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
pProtChar->CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
pProtChar->RequestCompleteHandler = NdisProtRequestComplete;
pProtChar->Name = g_ProtoName;

pProtChar->BindAdapterHandler = NdisProtBindAdapter;
pProtChar->UnbindAdapterHandler = NdisProtUnbindAdapter;

NdisRegisterProtocol( (PNDIS_STATUS)&Status, &g_NdisProtHandle,
pProtChar, ProtocolSize );
if ( Status != NDIS_STATUS_SUCCESS )
{
return STATUS_UNSUCCESSFUL;
}
else
{
g_AdapterProtocolRegistered = TRUE;
return STATUS_SUCCESS;
}

return STATUS_SUCCESS;
}

//-------------------------------------------------------------------
VOID UtilOpenAdapter( IN PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status, OpenError;
UINT MediumIndex, ArraySize;
NDIS_MEDIUM MediumArray;
LARGE_INTEGER timeout;

timeout.QuadPart = -5 * 10 * 1000 * 100;
MediumArray = NdisMedium802_3;
ArraySize = 0x1;

NdisOpenAdapter( &Status, &OpenError, &pAdapter->AdapterBindingHandle,
&MediumIndex, &MediumArray, ArraySize,
g_NdisProtHandle, (NDIS_HANDLE)pAdapter,
(PNDIS_STRING)&pAdapter->AdapterName, 0x0, NULL);

if ( Status != STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_OPEN_PENDING;
Status = KeWaitForSingleObject( &pAdapter->AdapterEvent,
Executive, KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_SUCCESS;
}
}

//-------------------------------------------------------------------
VOID UtilRequestMacAddress( PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status;
LARGE_INTEGER timeout;
PNDIS_REQUEST pAdapterRequest = &pAdapter->AdapterReq;

timeout.QuadPart = -5 * 10 * 1000 * 100;

// Inicializa evento de espera
KeInitializeEvent( &pAdapter->AdapterEvent, NotificationEvent, FALSE );

// Preencha a estrutura NDIS_REQUEST
pAdapterRequest->RequestType = NdisRequestQueryInformation;

pAdapterRequest->DATA.QUERY_INFORMATION.Oid =
OID_802_3_PERMANENT_ADDRESS;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBuffer =
&pAdapter->AdapterMacAddress;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBufferLength = sizeof(
pAdapter->AdapterMacAddress );

NdisRequest( &Status, pAdapter->AdapterBindingHandle, pAdapterRequest );
if ( Status != NDIS_STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive,
KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
}

On the function UtilRequestMacAddress when I execute the NdisRequest
Function on Windows 2000 the Status always returns NDIS_STATUS_PENDING (
0x06 ).
Even if I call KeWaitForSingleObject with NULL at the timeout to wait
infinitely, I keep getting 0x06 and the request does not succeed.
I’m new to driver development so I’m really stuck on this problem. So I
decided to ask the experts some hints.

Can you guys point me the mistakes I made in this code?
Thanks in advance!
Silvio.

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Does NdisProtRequestComplete get called when you issue the NdisRequest to get the MAC address?

Have a nice day
GV
----- Original Message -----
From: Silvio Reis Junior
To: Windows System Software Devs Interest List
Sent: Thursday, July 24, 2008 9:44 AM
Subject: Re: [ntdev] Problem retrieving physical mac address on Windows 2000.

Sure!

VOID NdisProtRequestComplete( IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_REQUEST NdisRequest,IN NDIS_STATUS Status )
{
PADAPTER_INFORMATION pAdapter = (PADAPTER_INFORMATION)ProtocolBindingContext;
if ( Status == NDIS_STATUS_SUCCESS )
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
KeSetEvent( &pAdapter->AdapterEvent, IO_NO_INCREMENT, FALSE );
}

On Thu, Jul 24, 2008 at 12:49 PM, Gianluca Varenni wrote:

Where do you set the pAdapter->AdapterEvent? Can you post the code of NdisProtRequestComplete?

Have a nice day
GV


Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com

----- Original Message ----- From: Silvio Reis Junior
To: Windows System Software Devs Interest List
Sent: Thursday, July 24, 2008 7:08 AM
Subject: [ntdev] Problem retrieving physical mac address on Windows 2000.

Hi folks!
I’m writing a ndis driver to retrieve the physical mac address from the ethernet adapters installed on the system.
My driver works fine on Windows XP but fails on Windows 2000. I didn’t have a chance to test it on Windows Vista x86 yet.

This is part of the code I wrote:

//-------------------------------------------------------------------
NTSTATUS ConfigureAndRegisterProtocol( NDIS50_PROTOCOL_CHARACTERISTICS* pProtChar )
{
ULONG MajorVersion;
ULONG MinorVersion;
UINT ProtocolSize;
NTSTATUS Status = STATUS_UNSUCCESSFUL;

PsGetVersion( &MajorVersion, &MinorVersion, NULL, NULL );
NdisZeroMemory( pProtChar, sizeof ( NDIS50_PROTOCOL_CHARACTERISTICS ) );

if ( MajorVersion == 4 )
{
ProtocolSize = sizeof( NDIS30_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 3;
}

if ( MajorVersion == 5 )
{
if ( MinorVersion == 0 )
{
ProtocolSize = sizeof( NDIS40_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 4;
}

if ( MinorVersion == 1 || MinorVersion == 2 )
{
ProtocolSize = sizeof( NDIS50_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 5;
}

if ( MinorVersion > 2 )
{
return STATUS_UNSUCCESSFUL;
}
}

pProtChar->OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
pProtChar->CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
pProtChar->RequestCompleteHandler = NdisProtRequestComplete;
pProtChar->Name = g_ProtoName;

pProtChar->BindAdapterHandler = NdisProtBindAdapter;
pProtChar->UnbindAdapterHandler = NdisProtUnbindAdapter;

NdisRegisterProtocol( (PNDIS_STATUS)&Status, &g_NdisProtHandle, pProtChar, ProtocolSize );
if ( Status != NDIS_STATUS_SUCCESS )
{
return STATUS_UNSUCCESSFUL;
}
else
{
g_AdapterProtocolRegistered = TRUE;
return STATUS_SUCCESS;
}

return STATUS_SUCCESS;
}

//-------------------------------------------------------------------
VOID UtilOpenAdapter( IN PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status, OpenError;
UINT MediumIndex, ArraySize;
NDIS_MEDIUM MediumArray;
LARGE_INTEGER timeout;

timeout.QuadPart = -5 * 10 * 1000 * 100;
MediumArray = NdisMedium802_3;
ArraySize = 0x1;

NdisOpenAdapter( &Status, &OpenError, &pAdapter->AdapterBindingHandle, &MediumIndex, &MediumArray, ArraySize,
g_NdisProtHandle, (NDIS_HANDLE)pAdapter, (PNDIS_STRING)&pAdapter->AdapterName, 0x0, NULL);

if ( Status != STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_OPEN_PENDING;
Status = KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive, KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_SUCCESS;
}
}

//-------------------------------------------------------------------
VOID UtilRequestMacAddress( PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status;
LARGE_INTEGER timeout;
PNDIS_REQUEST pAdapterRequest = &pAdapter->AdapterReq;

timeout.QuadPart = -5 * 10 * 1000 * 100;

// Inicializa evento de espera
KeInitializeEvent( &pAdapter->AdapterEvent, NotificationEvent, FALSE );

// Preencha a estrutura NDIS_REQUEST
pAdapterRequest->RequestType = NdisRequestQueryInformation;

pAdapterRequest->DATA.QUERY_INFORMATION.Oid = OID_802_3_PERMANENT_ADDRESS;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBuffer = &pAdapter->AdapterMacAddress;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBufferLength = sizeof( pAdapter->AdapterMacAddress );

NdisRequest( &Status, pAdapter->AdapterBindingHandle, pAdapterRequest );
if ( Status != NDIS_STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive, KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
}

On the function UtilRequestMacAddress when I execute the NdisRequest Function on Windows 2000 the Status always returns NDIS_STATUS_PENDING ( 0x06 ).
Even if I call KeWaitForSingleObject with NULL at the timeout to wait infinitely, I keep getting 0x06 and the request does not succeed.
I’m new to driver development so I’m really stuck on this problem. So I decided to ask the experts some hints.

Can you guys point me the mistakes I made in this code?
Thanks in advance!
Silvio.

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi Gianluca!
First of all thanks for replying this thread.
Yes, the function NdisProtRequestComplete* *is always called when
NdisRequest is executed.

On Thu, Jul 24, 2008 at 2:08 PM, Gianluca Varenni <
xxxxx@gmail.com> wrote:

Does *NdisProtRequestComplete *get called when you issue the NdisRequest
to get the MAC address?

Have a nice day
GV

----- Original Message -----
*From:* Silvio Reis Junior
> To: Windows System Software Devs Interest List
> Sent: Thursday, July 24, 2008 9:44 AM
> Subject: Re: [ntdev] Problem retrieving physical mac address on Windows
> 2000.
>
> Sure!
>
> VOID NdisProtRequestComplete( IN NDIS_HANDLE ProtocolBindingContext, IN
> PNDIS_REQUEST NdisRequest,IN NDIS_STATUS Status )
> {
> PADAPTER_INFORMATION pAdapter =
> (PADAPTER_INFORMATION)ProtocolBindingContext;
> if ( Status == NDIS_STATUS_SUCCESS )
> {
> pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
> }
> else
> {
> pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
> }
> KeSetEvent( &pAdapter->AdapterEvent, IO_NO_INCREMENT, FALSE );
> }

>
> On Thu, Jul 24, 2008 at 12:49 PM, Gianluca Varenni <
> xxxxx@gmail.com> wrote:
>
>> Where do you set the pAdapter->AdapterEvent? Can you post the code of
>> NdisProtRequestComplete?
>>
>> Have a nice day
>> GV
>>
>> –
>> Gianluca Varenni, Windows DDK MVP
>>
>> CACE Technologies
>> http://www.cacetech.com
>>
>> ----- Original Message ----- From: Silvio Reis Junior
>> To: Windows System Software Devs Interest List
>> Sent: Thursday, July 24, 2008 7:08 AM
>> Subject: [ntdev] Problem retrieving physical mac address on Windows 2000.
>>
>>
>>
>> Hi folks!
>> I’m writing a ndis driver to retrieve the physical mac address from the
>> ethernet adapters installed on the system.
>> My driver works fine on Windows XP but fails on Windows 2000. I didn’t
>> have a chance to test it on Windows Vista x86 yet.
>>
>> This is part of the code I wrote:
>>
>> //-------------------------------------------------------------------
>> NTSTATUS ConfigureAndRegisterProtocol( NDIS50_PROTOCOL_CHARACTERISTICS*
>> pProtChar )
>> {
>> ULONG MajorVersion;
>> ULONG MinorVersion;
>> UINT ProtocolSize;
>> NTSTATUS Status = STATUS_UNSUCCESSFUL;
>>
>> PsGetVersion( &MajorVersion, &MinorVersion, NULL, NULL );
>> NdisZeroMemory( pProtChar, sizeof ( NDIS50_PROTOCOL_CHARACTERISTICS ) );
>>
>> if ( MajorVersion == 4 )
>> {
>> ProtocolSize = sizeof( NDIS30_PROTOCOL_CHARACTERISTICS );
>> pProtChar->MajorNdisVersion = 3;
>> }
>>
>> if ( MajorVersion == 5 )
>> {
>> if ( MinorVersion == 0 )
>> {
>> ProtocolSize = sizeof( NDIS40_PROTOCOL_CHARACTERISTICS );
>> pProtChar->MajorNdisVersion = 4;
>> }
>>
>> if ( MinorVersion == 1 || MinorVersion == 2 )
>> {
>> ProtocolSize = sizeof( NDIS50_PROTOCOL_CHARACTERISTICS );
>> pProtChar->MajorNdisVersion = 5;
>> }
>>
>> if ( MinorVersion > 2 )
>> {
>> return STATUS_UNSUCCESSFUL;
>> }
>> }
>>
>> pProtChar->OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
>> pProtChar->CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
>> pProtChar->RequestCompleteHandler = NdisProtRequestComplete;
>> pProtChar->Name = g_ProtoName;
>>
>> pProtChar->BindAdapterHandler = NdisProtBindAdapter;
>> pProtChar->UnbindAdapterHandler = NdisProtUnbindAdapter;
>>
>> NdisRegisterProtocol( (PNDIS_STATUS)&Status, &g_NdisProtHandle,
>> pProtChar, ProtocolSize );
>> if ( Status != NDIS_STATUS_SUCCESS )
>> {
>> return STATUS_UNSUCCESSFUL;
>> }
>> else
>> {
>> g_AdapterProtocolRegistered = TRUE;
>> return STATUS_SUCCESS;
>> }
>>
>> return STATUS_SUCCESS;
>> }
>>
>> //-------------------------------------------------------------------
>> VOID UtilOpenAdapter( IN PADAPTER_INFORMATION pAdapter )
>> {
>> NTSTATUS Status, OpenError;
>> UINT MediumIndex, ArraySize;
>> NDIS_MEDIUM MediumArray;
>> LARGE_INTEGER timeout;
>>
>>
>> timeout.QuadPart = -5 * 10 * 1000 * 100;
>> MediumArray = NdisMedium802_3;
>> ArraySize = 0x1;
>>
>> NdisOpenAdapter( &Status, &OpenError, &pAdapter->AdapterBindingHandle,
>> &MediumIndex, &MediumArray, ArraySize,
>> g_NdisProtHandle, (NDIS_HANDLE)pAdapter,
>> (PNDIS_STRING)&pAdapter->AdapterName, 0x0, NULL);
>>
>> if ( Status != STATUS_SUCCESS )
>> {
>> if ( Status == NDIS_STATUS_PENDING )
>> {
>> pAdapter->AdapterState = ADAPTER_OPEN_PENDING;
>> Status = KeWaitForSingleObject( &pAdapter->AdapterEvent,
>> Executive, KernelMode, FALSE, &timeout );
>> }
>> else
>> {
>> pAdapter->AdapterState = ADAPTER_OPEN_ERROR;
>> }
>> }
>> else
>> {
>> pAdapter->AdapterState = ADAPTER_OPEN_SUCCESS;
>> }
>> }
>>
>> //-------------------------------------------------------------------
>> VOID UtilRequestMacAddress( PADAPTER_INFORMATION pAdapter )
>> {
>> NTSTATUS Status;
>> LARGE_INTEGER timeout;
>> PNDIS_REQUEST pAdapterRequest = &pAdapter->AdapterReq;
>>
>> timeout.QuadPart = -5 * 10 * 1000 * 100;
>>
>> // Inicializa evento de espera
>> KeInitializeEvent( &pAdapter->AdapterEvent, NotificationEvent, FALSE );
>>
>> // Preencha a estrutura NDIS_REQUEST
>> pAdapterRequest->RequestType = NdisRequestQueryInformation;
>>
>> pAdapterRequest->DATA.QUERY_INFORMATION.Oid =
>> OID_802_3_PERMANENT_ADDRESS;
>> pAdapterRequest->DATA.QUERY_INFORMATION.InformationBuffer =
>> &pAdapter->AdapterMacAddress;
>> pAdapterRequest->DATA.QUERY_INFORMATION.InformationBufferLength =
>> sizeof( pAdapter->AdapterMacAddress );
>>
>> NdisRequest( &Status, pAdapter->AdapterBindingHandle, pAdapterRequest );
>> if ( Status != NDIS_STATUS_SUCCESS )
>> {
>> if ( Status == NDIS_STATUS_PENDING )
>> {
>> pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
>> KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive,
>> KernelMode, FALSE, &timeout );
>> }
>> else
>> {
>> pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
>> }
>> }
>> else
>> {
>> pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
>> }
>> }
>>
>> On the function UtilRequestMacAddress when I execute the NdisRequest
>> Function on Windows 2000 the Status always returns NDIS_STATUS_PENDING (
>> 0x06 ).
>> Even if I call KeWaitForSingleObject with NULL at the timeout to wait
>> infinitely, I keep getting 0x06 and the request does not succeed.
>> I’m new to driver development so I’m really stuck on this problem. So I
>> decided to ask the experts some hints.
>>
>> Can you guys point me the mistakes I made in this code?
>> Thanks in advance!
>> Silvio.
>>
>>
>>
>>
>> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
>> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
>> the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>

So I suppose that KeWaitForSingleObject eventually returns.
From what I see in the code the error is that after you wait for the event to be signalled you need to change the value of pAdapter->AdapterState to success (or in any case, do not leave it as pending).


if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive, KernelMode, FALSE, &timeout );

>>here you need to do something like pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;

}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}

Have a nice day
GV


Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com
----- Original Message -----
From: Silvio Reis Junior
To: Windows System Software Devs Interest List
Sent: Thursday, July 24, 2008 10:53 AM
Subject: Re: [ntdev] Problem retrieving physical mac address on Windows 2000.

Hi Gianluca!
First of all thanks for replying this thread.
Yes, the function NdisProtRequestComplete is always called when NdisRequest is executed.

On Thu, Jul 24, 2008 at 2:08 PM, Gianluca Varenni wrote:

Does NdisProtRequestComplete get called when you issue the NdisRequest to get the MAC address?

Have a nice day
GV
----- Original Message -----
From: Silvio Reis Junior
To: Windows System Software Devs Interest List
Sent: Thursday, July 24, 2008 9:44 AM
Subject: Re: [ntdev] Problem retrieving physical mac address on Windows 2000.

Sure!

VOID NdisProtRequestComplete( IN NDIS_HANDLE ProtocolBindingContext, IN PNDIS_REQUEST NdisRequest,IN NDIS_STATUS Status )
{
PADAPTER_INFORMATION pAdapter = (PADAPTER_INFORMATION)ProtocolBindingContext;
if ( Status == NDIS_STATUS_SUCCESS )
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
KeSetEvent( &pAdapter->AdapterEvent, IO_NO_INCREMENT, FALSE );
}

On Thu, Jul 24, 2008 at 12:49 PM, Gianluca Varenni wrote:

Where do you set the pAdapter->AdapterEvent? Can you post the code of NdisProtRequestComplete?

Have a nice day
GV


Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com

----- Original Message ----- From: Silvio Reis Junior
To: Windows System Software Devs Interest List
Sent: Thursday, July 24, 2008 7:08 AM
Subject: [ntdev] Problem retrieving physical mac address on Windows 2000.

Hi folks!
I’m writing a ndis driver to retrieve the physical mac address from the ethernet adapters installed on the system.
My driver works fine on Windows XP but fails on Windows 2000. I didn’t have a chance to test it on Windows Vista x86 yet.

This is part of the code I wrote:

//-------------------------------------------------------------------
NTSTATUS ConfigureAndRegisterProtocol( NDIS50_PROTOCOL_CHARACTERISTICS* pProtChar )
{
ULONG MajorVersion;
ULONG MinorVersion;
UINT ProtocolSize;
NTSTATUS Status = STATUS_UNSUCCESSFUL;

PsGetVersion( &MajorVersion, &MinorVersion, NULL, NULL );
NdisZeroMemory( pProtChar, sizeof ( NDIS50_PROTOCOL_CHARACTERISTICS ) );

if ( MajorVersion == 4 )
{
ProtocolSize = sizeof( NDIS30_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 3;
}

if ( MajorVersion == 5 )
{
if ( MinorVersion == 0 )
{
ProtocolSize = sizeof( NDIS40_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 4;
}

if ( MinorVersion == 1 || MinorVersion == 2 )
{
ProtocolSize = sizeof( NDIS50_PROTOCOL_CHARACTERISTICS );
pProtChar->MajorNdisVersion = 5;
}

if ( MinorVersion > 2 )
{
return STATUS_UNSUCCESSFUL;
}
}

pProtChar->OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
pProtChar->CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
pProtChar->RequestCompleteHandler = NdisProtRequestComplete;
pProtChar->Name = g_ProtoName;

pProtChar->BindAdapterHandler = NdisProtBindAdapter;
pProtChar->UnbindAdapterHandler = NdisProtUnbindAdapter;

NdisRegisterProtocol( (PNDIS_STATUS)&Status, &g_NdisProtHandle, pProtChar, ProtocolSize );
if ( Status != NDIS_STATUS_SUCCESS )
{
return STATUS_UNSUCCESSFUL;
}
else
{
g_AdapterProtocolRegistered = TRUE;
return STATUS_SUCCESS;
}

return STATUS_SUCCESS;
}

//-------------------------------------------------------------------
VOID UtilOpenAdapter( IN PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status, OpenError;
UINT MediumIndex, ArraySize;
NDIS_MEDIUM MediumArray;
LARGE_INTEGER timeout;

timeout.QuadPart = -5 * 10 * 1000 * 100;
MediumArray = NdisMedium802_3;
ArraySize = 0x1;

NdisOpenAdapter( &Status, &OpenError, &pAdapter->AdapterBindingHandle, &MediumIndex, &MediumArray, ArraySize,
g_NdisProtHandle, (NDIS_HANDLE)pAdapter, (PNDIS_STRING)&pAdapter->AdapterName, 0x0, NULL);

if ( Status != STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_OPEN_PENDING;
Status = KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive, KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_OPEN_SUCCESS;
}
}

//-------------------------------------------------------------------
VOID UtilRequestMacAddress( PADAPTER_INFORMATION pAdapter )
{
NTSTATUS Status;
LARGE_INTEGER timeout;
PNDIS_REQUEST pAdapterRequest = &pAdapter->AdapterReq;

timeout.QuadPart = -5 * 10 * 1000 * 100;

// Inicializa evento de espera
KeInitializeEvent( &pAdapter->AdapterEvent, NotificationEvent, FALSE );

// Preencha a estrutura NDIS_REQUEST
pAdapterRequest->RequestType = NdisRequestQueryInformation;

pAdapterRequest->DATA.QUERY_INFORMATION.Oid = OID_802_3_PERMANENT_ADDRESS;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBuffer = &pAdapter->AdapterMacAddress;
pAdapterRequest->DATA.QUERY_INFORMATION.InformationBufferLength = sizeof( pAdapter->AdapterMacAddress );

NdisRequest( &Status, pAdapter->AdapterBindingHandle, pAdapterRequest );
if ( Status != NDIS_STATUS_SUCCESS )
{
if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive, KernelMode, FALSE, &timeout );
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
}
}

On the function UtilRequestMacAddress when I execute the NdisRequest Function on Windows 2000 the Status always returns NDIS_STATUS_PENDING ( 0x06 ).
Even if I call KeWaitForSingleObject with NULL at the timeout to wait infinitely, I keep getting 0x06 and the request does not succeed.
I’m new to driver development so I’m really stuck on this problem. So I decided to ask the experts some hints.

Can you guys point me the mistakes I made in this code?
Thanks in advance!
Silvio.

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Hi Gianluca!
It works now! Thanks very much friend!

My best regards.
Silvio.

On Thu, Jul 24, 2008 at 3:01 PM, Gianluca Varenni <
xxxxx@gmail.com> wrote:

So I suppose that KeWaitForSingleObject eventually returns.
From what I see in the code the error is that after you wait for the event
to be signalled you need to change the value of pAdapter->AdapterState to
success (or in any case, do not leave it as pending).


if ( Status == NDIS_STATUS_PENDING )
{
pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive,
KernelMode, FALSE, &timeout );
>>>here you need to do something like pAdapter->AdapterState =
ADAPTER_REQUEST_SUCCESS;
}
else
{
pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
}

Have a nice day
GV


Gianluca Varenni, Windows DDK MVP

CACE Technologies
http://www.cacetech.com

----- Original Message -----
*From:* Silvio Reis Junior
> To: Windows System Software Devs Interest List
> Sent: Thursday, July 24, 2008 10:53 AM
> Subject: Re: [ntdev] Problem retrieving physical mac address on Windows
> 2000.
>
> Hi Gianluca!
> First of all thanks for replying this thread.
> Yes, the function NdisProtRequestComplete* *is always called when
> NdisRequest is executed.
>
> On Thu, Jul 24, 2008 at 2:08 PM, Gianluca Varenni <
> xxxxx@gmail.com> wrote:
>
>> Does *NdisProtRequestComplete get called when you issue the NdisRequest
>> to get the MAC address?
>>
>> Have a nice day
>> GV
>>
>> ----- Original Message -----
>> From: Silvio Reis Junior
>> To: Windows System Software Devs Interest List
>> Sent: Thursday, July 24, 2008 9:44 AM
>> Subject: Re: [ntdev] Problem retrieving physical mac address on Windows
>> 2000.
>>
>> Sure!
>>
>> VOID NdisProtRequestComplete( IN NDIS_HANDLE ProtocolBindingContext, IN
>> PNDIS_REQUEST NdisRequest,IN NDIS_STATUS Status )
>> {
>> PADAPTER_INFORMATION pAdapter =
>> (PADAPTER_INFORMATION)ProtocolBindingContext;
>> if ( Status == NDIS_STATUS_SUCCESS )
>> {
>> pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
>> }
>> else
>> {
>> pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
>> }
>> KeSetEvent( &pAdapter->AdapterEvent, IO_NO_INCREMENT, FALSE );
>> }

>>
>> On Thu, Jul 24, 2008 at 12:49 PM, Gianluca Varenni <
>> xxxxx@gmail.com> wrote:
>>
>>> Where do you set the pAdapter->AdapterEvent? Can you post the code of
>>> NdisProtRequestComplete?
>>>
>>> Have a nice day
>>> GV
>>>
>>> –
>>> Gianluca Varenni, Windows DDK MVP
>>>
>>> CACE Technologies
>>> http://www.cacetech.com
>>>
>>> ----- Original Message ----- From: Silvio Reis Junior
>>> To: Windows System Software Devs Interest List
>>> Sent: Thursday, July 24, 2008 7:08 AM
>>> Subject: [ntdev] Problem retrieving physical mac address on Windows 2000.
>>>
>>>
>>>
>>>
>>> Hi folks!
>>> I’m writing a ndis driver to retrieve the physical mac address from the
>>> ethernet adapters installed on the system.
>>> My driver works fine on Windows XP but fails on Windows 2000. I didn’t
>>> have a chance to test it on Windows Vista x86 yet.
>>>
>>> This is part of the code I wrote:
>>>
>>> //-------------------------------------------------------------------
>>> NTSTATUS ConfigureAndRegisterProtocol( NDIS50_PROTOCOL_CHARACTERISTICS

>>> pProtChar )
>>> {
>>> ULONG MajorVersion;
>>> ULONG MinorVersion;
>>> UINT ProtocolSize;
>>> NTSTATUS Status = STATUS_UNSUCCESSFUL;
>>>
>>> PsGetVersion( &MajorVersion, &MinorVersion, NULL, NULL );
>>> NdisZeroMemory( pProtChar, sizeof ( NDIS50_PROTOCOL_CHARACTERISTICS )
>>> );
>>>
>>> if ( MajorVersion == 4 )
>>> {
>>> ProtocolSize = sizeof( NDIS30_PROTOCOL_CHARACTERISTICS );
>>> pProtChar->MajorNdisVersion = 3;
>>> }
>>>
>>> if ( MajorVersion == 5 )
>>> {
>>> if ( MinorVersion == 0 )
>>> {
>>> ProtocolSize = sizeof( NDIS40_PROTOCOL_CHARACTERISTICS );
>>> pProtChar->MajorNdisVersion = 4;
>>> }
>>>
>>> if ( MinorVersion == 1 || MinorVersion == 2 )
>>> {
>>> ProtocolSize = sizeof( NDIS50_PROTOCOL_CHARACTERISTICS );
>>> pProtChar->MajorNdisVersion = 5;
>>> }
>>>
>>> if ( MinorVersion > 2 )
>>> {
>>> return STATUS_UNSUCCESSFUL;
>>> }
>>> }
>>>
>>> pProtChar->OpenAdapterCompleteHandler = NdisProtOpenAdapterComplete;
>>> pProtChar->CloseAdapterCompleteHandler = NdisProtCloseAdapterComplete;
>>> pProtChar->RequestCompleteHandler = NdisProtRequestComplete;
>>> pProtChar->Name = g_ProtoName;
>>>
>>> pProtChar->BindAdapterHandler = NdisProtBindAdapter;
>>> pProtChar->UnbindAdapterHandler = NdisProtUnbindAdapter;
>>>
>>> NdisRegisterProtocol( (PNDIS_STATUS)&Status, &g_NdisProtHandle,
>>> pProtChar, ProtocolSize );
>>> if ( Status != NDIS_STATUS_SUCCESS )
>>> {
>>> return STATUS_UNSUCCESSFUL;
>>> }
>>> else
>>> {
>>> g_AdapterProtocolRegistered = TRUE;
>>> return STATUS_SUCCESS;
>>> }
>>>
>>> return STATUS_SUCCESS;
>>> }
>>>
>>> //-------------------------------------------------------------------
>>> VOID UtilOpenAdapter( IN PADAPTER_INFORMATION pAdapter )
>>> {
>>> NTSTATUS Status, OpenError;
>>> UINT MediumIndex, ArraySize;
>>> NDIS_MEDIUM MediumArray;
>>> LARGE_INTEGER timeout;
>>>
>>>
>>> timeout.QuadPart = -5 * 10 * 1000 * 100;
>>> MediumArray = NdisMedium802_3;
>>> ArraySize = 0x1;
>>>
>>> NdisOpenAdapter( &Status, &OpenError, &pAdapter->AdapterBindingHandle,
>>> &MediumIndex, &MediumArray, ArraySize,
>>> g_NdisProtHandle, (NDIS_HANDLE)pAdapter,
>>> (PNDIS_STRING)&pAdapter->AdapterName, 0x0, NULL);
>>>
>>> if ( Status != STATUS_SUCCESS )
>>> {
>>> if ( Status == NDIS_STATUS_PENDING )
>>> {
>>> pAdapter->AdapterState = ADAPTER_OPEN_PENDING;
>>> Status = KeWaitForSingleObject( &pAdapter->AdapterEvent,
>>> Executive, KernelMode, FALSE, &timeout );
>>> }
>>> else
>>> {
>>> pAdapter->AdapterState = ADAPTER_OPEN_ERROR;
>>> }
>>> }
>>> else
>>> {
>>> pAdapter->AdapterState = ADAPTER_OPEN_SUCCESS;
>>> }
>>> }
>>>
>>> //-------------------------------------------------------------------
>>> VOID UtilRequestMacAddress( PADAPTER_INFORMATION pAdapter )
>>> {
>>> NTSTATUS Status;
>>> LARGE_INTEGER timeout;
>>> PNDIS_REQUEST pAdapterRequest = &pAdapter->AdapterReq;
>>>
>>> timeout.QuadPart = -5 * 10 * 1000 * 100;
>>>
>>> // Inicializa evento de espera
>>> KeInitializeEvent( &pAdapter->AdapterEvent, NotificationEvent, FALSE );
>>>
>>> // Preencha a estrutura NDIS_REQUEST
>>> pAdapterRequest->RequestType = NdisRequestQueryInformation;
>>>
>>> pAdapterRequest->DATA.QUERY_INFORMATION.Oid =
>>> OID_802_3_PERMANENT_ADDRESS;
>>> pAdapterRequest->DATA.QUERY_INFORMATION.InformationBuffer =
>>> &pAdapter->AdapterMacAddress;
>>> pAdapterRequest->DATA.QUERY_INFORMATION.InformationBufferLength =
>>> sizeof( pAdapter->AdapterMacAddress );
>>>
>>> NdisRequest( &Status, pAdapter->AdapterBindingHandle, pAdapterRequest
>>> );
>>> if ( Status != NDIS_STATUS_SUCCESS )
>>> {
>>> if ( Status == NDIS_STATUS_PENDING )
>>> {
>>> pAdapter->AdapterState = ADAPTER_REQUEST_PENDING;
>>> KeWaitForSingleObject( &pAdapter->AdapterEvent, Executive,
>>> KernelMode, FALSE, &timeout );
>>> }
>>> else
>>> {
>>> pAdapter->AdapterState = ADAPTER_REQUEST_ERROR;
>>> }
>>> }
>>> else
>>> {
>>> pAdapter->AdapterState = ADAPTER_REQUEST_SUCCESS;
>>> }
>>> }
>>>
>>> On the function UtilRequestMacAddress when I execute the NdisRequest
>>> Function on Windows 2000 the Status always returns NDIS_STATUS_PENDING (
>>> 0x06 ).
>>> Even if I call KeWaitForSingleObject with NULL at the timeout to wait
>>> infinitely, I keep getting 0x06 and the request does not succeed.
>>> I’m new to driver development so I’m really stuck on this problem. So I
>>> decided to ask the experts some hints.
>>>
>>> Can you guys point me the mistakes I made in this code?
>>> Thanks in advance!
>>> Silvio.
>>>
>>>
>>>
>>>
>>> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
>>> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
>>> the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>>
>>> —
>>> NTDEV is sponsored by OSR
>>>
>>> For our schedule of WDF, WDM, debugging and other seminars visit:
>>> http://www.osr.com/seminars
>>>
>>> To unsubscribe, visit the List Server section of OSR Online at
>>> http://www.osronline.com/page.cfm?name=ListServer
>>>
>>
>> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
>> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
>> the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>>
>> —
>> NTDEV is sponsored by OSR
>>
>> For our schedule of WDF, WDM, debugging and other seminars visit:
>> http://www.osr.com/seminars
>>
>> To unsubscribe, visit the List Server section of OSR Online at
>> http://www.osronline.com/page.cfm?name=ListServer
>>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>