This
sample demonstrates how to use the User-Mode Driver Framework to write a Near
Field Proximity driver and demonstrates best practices. Typically, a Near Field
Proximity driver would use Near Field technologies like “NFC”, “TransferJet”, or “Bump”. However, this sample uses a
TCP/IPv6 network connection and a static configuration between two machines to
allow simulation of Near Field interaction.
Load the NetNfpProvider Visual Studio project file in to Visual
Studio. Use Visual Studio to build the sample. If the build succeeds, you will
find the driver, NetNfpProvider.dll in the binary output directory specified
for the build environment.
To install the NetNfpProvider driver:
- First copy the driver binary and the NetNfpProvider.inf file to a directory on your test machine (for example c:\NetNfpProvider.)
- Change to the directory containing the inf and binaries (for example cd /d c:\NetNfpProvider.)
- Next run devcon.exe as follows:
devcon.exe install NetNfpProvider.inf WUDF\NetNfpProvider
DevCon can be found in the tools directory of your WDK enlistment (for example: c:\winddk\<bld>\tools\devcon\i386\devcon.exe.)
- Create a Windows Firewall rule to allow the NetNfpProvider to receive proximity simulation requests over the network:
Run WF.msc
Create a new inbound rule that opens port 9299
To update the NetNfpProvider driver after making any changes:
- Increment the version number found in the INF. While this is not strictly necessary, it will help ensure PnP selects your new driver as a better match for the device.
- Copy the updated driver binary and the NetNfpProvider.inf file to a directory on your test machine (for example c:\ NetNfpProvider.)
- Change to the directory containing the inf and binaries (for example cd /d c:\ NetNfpProvider.)
- Next run devcon.exe as follows:
devcon.exe update NetNfpProvider.inf WUDF\NetNfpProvider
To test
the NetNfpProvider driver, you can run
NetNfpControl.exe which is built from the src\nfp\net\exe.
First
install the device as described above. Then run NetNfpControl.exe from one
command window.
NetNfpControl console app allows
control of the NetNfpProvider test driver. Both the
local and remote machine must have the NetNfpProvider
driver installed.
USAGE:
Windows Near-field
Proximity Test tool. Designed for simulating proximity hardware.
NetNfpControl.exe
[<remoteMachine>] [/k]
Example: NetNfpControl.exe John-PC1
The first operating mode allows the user to specify a remote machine name (or
IPv6 address) that the local machine should connect to and simulate proximity
with. After it's connected, a simple key-press ends the simulated proximity
link. The console app then exits.
Example: NetNfpControl.exe John-PC1
/k
A second operating mode keeps the console app running with a Ctrl-F1 hotkey
registered (even when running in the background). When the hot key is
intercepted, a near-field proximity event is simulated directly with the
specified remote machine.
Note: The console app needs to be running (only on one machine) to intercept
the system hot key.
Example: NetNfpControl.exe /k
A third operating mode also keeps the console app running with a Ctrl-F1 hotkey
registered. However, you'll have to run this on two or more machines at the
same time. Pressing Ctrl-F1 on any two machines at the same time causes the
machines to exchange their network name via a file on a private share with a
special file name.
·
The
server share used is hard coded to: \\scratch2\scratch\travm\proxrendezvous\
o
Either
create a file server with these folders shared, or change this to match yours.
·
The
file has an effective lifetime of 2 seconds.
·
In
the event of a collision (two clients posting an event during the same
interval), only one client 'wins'.
|
File |
Description |
|
NetNfpProvider.htm |
Documentation for this sample
(this file). |
|
dllsup.cpp |
DLL
Support code - provides the DLL's entry point as well as the single required
export (DllGetClassObject). |
|
Exports.def |
This file lists the functions that
the driver DLL exports. |
|
Internal.h |
This is the main header file for
this driver. |
|
Driver.cpp & Driver.h |
DriverEntry and events on the Driver Object. |
|
Device.cpp & Device.h |
Events on the Device Object. |
|
Queue.cpp & Queue.h |
Contains events on the I/O Queue
Objects. IOCTL handlers and filename parsing. |
|
connection.cpp & connection.h |
Contains events on the connection
object created per simulated proximity link. This contains the code for
socket client. |
|
Socketlistener.cpp & Socketlistener.h |
Contains
a socket listener for accepting inbound proximity simulation requests. |
|
FileContext.cpp and FileContext.h |
Defines the context associated with the file object. Per file context
stores per connection information, publications, and subscriptions. |
|
NetNfpProvider.rc |
Resource file for the driver. |
|
NetNfpProvider.inx |
File that describes the
installation of this driver. The build process converts this into an INF
file. |
|
WppDefs.h |
A header used to generate WPP
Macros for this project. Note, with WPP, some comments are actually compiled
by the pre-processor. Thread Local Storage is used to properly indent logs. |
© 2012 Microsoft Corporation