Re: ndisuio question

From: Boyd D. Mills (BMills_at_VCIControls.ca)
Date: 10/28/04


Date: Thu, 28 Oct 2004 17:46:59 -0400

Thanks.

I have applied the changes you suggested ( I think ). Below is the complete
source code for the Win CE 4.1 CEPC application.
It still hangs on the read.

Help would be greatly appreciated.

I hope this isn't a ce 4.1 restriction!
===============
#include "stdafx.h"

#include "Windev.h"

//#undef ARCNET

#include "Ndis.h"
#include "Nuiouser.h"
#include "Ntddndis.h"

static void VCIWideCharToMultiByte( LPTSTR wcIn, LPSTR acOut )
{
 while ( *wcIn )
  *acOut++ = (char)*wcIn++;
}

int main(int argc, char *argv[], char *envp[])
{
    DWORD dwBytesOut;
 HANDLE hLAN;
 printf( " starting up \n" );
 hLAN = CreateFile( NDISUIO_DEVICE_NAME,//L"UIO1:",
                  GENERIC_READ|GENERIC_WRITE,
      FILE_SHARE_READ | FILE_SHARE_WRITE,
      NULL,
      OPEN_EXISTING,
      FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
      INVALID_HANDLE_VALUE );
 printf("hLAN %d ", hLAN );
 if ( hLAN != INVALID_HANDLE_VALUE )
 {
   char t[2048];
   static int icount = 0;
   DWORD dwIn;

   char Buf[1024];
   char aname[ 1024];
   TCHAR tcDevName[ 1024 ];
   DWORD dwReturnedBytes;
   PNDISUIO_QUERY_BINDING pQueryBinding;
   USHORT usNewType = 0x0800;

   NDISUIO_SET_OID set_oid;
   ULONG ulData = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;

   pQueryBinding = (PNDISUIO_QUERY_BINDING)Buf;

   DeviceIoControl(
     hLAN, IOCTL_NDISUIO_QUERY_BINDING,
     pQueryBinding, sizeof(NDISUIO_QUERY_BINDING),
     NULL, 1024,
     &dwReturnedBytes, NULL);

   printf( "index %d\n", pQueryBinding->BindingIndex );
   ZeroMemory( tcDevName, sizeof( tcDevName ) );
   memcpy(tcDevName, &Buf[pQueryBinding->DeviceNameOffset ],
       pQueryBinding->DeviceNameLength );

   VCIWideCharToMultiByte( tcDevName , aname);
   printf("name %s\n", aname );

   set_oid.Oid = OID_GEN_CURRENT_PACKET_FILTER;
   CopyMemory( &set_oid.Data[0], &ulData, sizeof( ulData) );
   set_oid.ptcDeviceName = NULL;

   if ( ! DeviceIoControl(
    hLAN, IOCTL_NDISUIO_OPEN_DEVICE,
    tcDevName, wcslen(tcDevName) * sizeof(TCHAR),
                NULL, 0,
                &dwReturnedBytes, NULL) )
   {
    printf( "deviceiocontrol failed OPEN_DEVICE %d\n", GetLastError());
   }
   else if ( ! DeviceIoControl(
    hLAN, IOCTL_NDISUIO_SET_OID_VALUE,
    &set_oid, sizeof( set_oid ),
                NULL, 0,
                &dwReturnedBytes, NULL) )
   {
    printf( "deviceiocontrol failed SET_OID_VALUE %d\n", GetLastError());
   }
   else if ( ! DeviceIoControl(
    hLAN, IOCTL_NDISUIO_SET_ETHER_TYPE,
    &usNewType, sizeof(usNewType),
                NULL, 0,
                &dwReturnedBytes, NULL) )
   {
    printf( "deviceiocontrol failed SET_ETHER_TYPE %d\n", GetLastError());
   }
   else
   {
    printf("we are away\n" );
    while ( icount++ < 12 )
    {
     if ( ReadFile( hLAN, t, 2048, &dwIn, NULL ) && dwIn )
     {
      printf( "0x%x ", t[0] );
     }
     else Sleep( 5000 );
    }
    printf("\n" );
   }
  CloseHandle( hLAN );
 }

 Sleep( 5000 );
 return( 0 );

}
============================
"Jeff Kelley [MS]" <jeffkel@online.microsoft.com> wrote in message
news:41815a3d$1@news.microsoft.com...
> You need to set the binding's current packet filter. See my reply to your
> other post for more details.
>
> --
> Jeff Kelley
> Microsoft / Windows CE Networking
>
>



Relevant Pages

  • Re: How to pass a structture to a driver using Deviceiocontrol
    ... The IOCTL is just a nr for the switch. ... DWORD GBS_IOControl( ... dwRet = GetHandlerValues; ... DeviceIoControl to a service from C# application. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: How to pass a structture to a driver using Deviceiocontrol
    ... I have defined my ioctl code in the stream driver's .h file as ... DWORD GBS_IOControl( ... dwRet = GetHandlerValues; ... DeviceIoControl to a service from C# application. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Proper use of GetOverlappedResult?
    ... But it really does seem to work (when I don't call WaitforSingleObject first) so I am confused. ... I discovered that you do not need to even call GetOverLapped result but you can read the number of bytes in the Overlapped stucture passed to ReadFile and DeviceIoControl. ... MyDeviceIoControl(DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer,DWORD nOutBufferSize,LPDWORD lpBytesReturned,DWORD dwWaitMilliseconds) ... BOOL bComplete = ...
    (microsoft.public.win32.programmer.kernel)
  • Re: How to pass a structture to a driver using Deviceiocontrol
    ... wince stream interface driverusing ... DWORD GBS_IOControl( ... dwRet = GetHandlerValues; ... I guess you have imported the DeviceIOControl API into your C# application. ...
    (microsoft.public.windowsce.platbuilder)
  • How to pass a structture to a driver using Deviceiocontrol
    ... deviceiocontrol method. ... DWORD GBS_IOControl( ... dwRet = GetHandlerValues; ...
    (microsoft.public.windowsce.platbuilder)