Near fied communication (NFC) is a breakthrough technology aimed at facilitating communication between two devices in close proximity, within a 4-cm distance. In Windows 8 the support for this technology has been included in a broader application scope that Microsoft named Near Field Proximity. This article will give you a general view of NFC explaining how Microsoft has reinterpreted it, and we will learn how to build an environment by using 2 virtual machines to test the classes contained in the namespace Windows.Networking.Proximity.
What is NFC?
In a nutshell NFC is a short range wireless communication system between two NFC enabled devices. The communication occurs at a 13.56 Mhz frequency, the same as the Radio Frequency Identification (RFID). As opposed to RFID, NFC works only in conditions of proximity, i.e. few centimeters.
The difference lies in the fact that NFC enabled devices can be mobile phones, tablets, PCs, NFC readers and NFC passive tags. This variety of devices opens the door to various applications and services like identification, access control, e-payment, e-ticketing, health data access and so on. In other words Near fied communication (NFC) is a technology with a potentially major impact on people’s economic and social life. It can be seen as something that simplifies the daily human life.
Let me describe a possible scenario: imagine to wake up in the morning for another workday, take your NFC enabled mobile phone and go to the train station, and to open the turnstile just put your mobile phone close to a NFC reader. To enter your office building you simply use your mobile to punch the clock. In the morning you have a meeting with a new customer: you can swap your business cards by simply approaching your card to his/her NFC-enabled mobile. Then if you wish to offer him/her a coffee from a vending machine, simply approach your phone to the NFC symbol exposed on the machine and you can process the payment
One of the primary information source on NFC is the NFC Forum (http://www.nfc-forum.org).
The NFC Forum was established to specify the NFC standards based on ISO/IEC standards and to promote the NFC technology thus providing guidance on the interoperability among devices and services. In the “specifications” section of the forum you can find all the technical documents which describe protocols, data exchange format and so on.
Regarding the NFC core capabilities, and consequently the interoperability amongst devices, three methods are foreseen for applications using NFC:
- Card emulation Mode
This mode allows a NFC device to work as a contact-less smart card (i.e. a credit card). This feature can be used in applications for payments, e-ticketing and so on.
- Peer-to-Peer Mode
This mode enables two NFC devices to exchange data using a bidirectional half duplex communication. From the point of view of the users, this mode simplifies information sharing: they just have to tap together their NFC devices with no need for any prior setup.
- Reader/Writer Mode
This mode allows an active NFC device to read from/write to a passive NFC tag. Typical examples are applications for smart posters.
The image below shows the underlying layers:
(source: http://www.nfc-forum.org)
The question that may come to mind is now: is this technology widely adopted, or will it be? is it worth learning more about this topic from the point of view of a developer? Judging from the list of
NFC phones already on the market (http://www.nfcworld.com/nfc-phones-list/#available) and the list of newer phones coming soon (http://www.nfcworld.com/nfc-phones-list/#soon) the answer is yes. Let’s learn how Microsoft is addressing this topic in the next paragraph.
The Microsoft interpretation: “Tap and Do”
According to first rumors Microsoft may be including NFC support in Windows 8 raised in September 2011 as announced by NXP. Later, in February 2012, Microsoft published a document entitled “Windows 8 Near Field Proximity Implementation Specification”, available here. It is mainly intended for system integrators and it provides guidelines and requirements that reveal the “Microsoft vision” on NFC. It is worth giving it a read. In this white paper Microsoft defines the communication between two devices in close proximity using a level of abstraction called “Tap and Do”.
Literally the definition of “Tap and Do” is:
“A gesture that is a natural interaction between people in close proximity used to trigger doing something together between the devices they are holding.”
It sounds very similar to the general concept of NFC but in the vision of Microsoft it is something more general. It stands on a system called Near Field Proximity (NFP) provider model. This NFP provider model is a common surface for all the NFP scenarios and use cases, and hides the underlying technology which could be NFC, WI-Direct, Bluetooth or something else. the image below shows the three layers:
The NFP scenarios taken into consideration are the “Ad-Hoch interaction in the Real World” and the “peripheral Wireless Device Setup”. The first fills a gap of Windows and provides an easy way to make two devices communicate together. The second one regards the user experience while installing wireless peripheral devices in Windows. With “Tap and Do” it is stated that this has been extremely simplified.
What about the use cases? “Tap and Do” gesture is the “compendium” of the case uses in the table below:
Use case |
Description |
Tap and Setup |
Tap and pair and set up a peripheral wireless device with Windows |
Tap and Reconnect |
Tap and reconnect a previously paired and set-up device with Windows |
Tap and Use |
Tap and connect your app with one running on another machine |
Tap and Launch |
Tap and invite a user on another machine to launch an app you’re running |
Tap and Acquire |
Tap and invite a user on another machine to obtain an app you’re running |
Tap and Share |
Tap and share content you have selected to another device |
Tap and Receive |
Tap and receive content from another device or poster |
Here is a short description of each of these:
Tap and Setup e Tab and Reconnect -> two use cases for installation and unidirectional pairing of wireless peripherals; placing a peripheral (a wireless keyboard or headphone etc) near a PC triggers the device setup or reconnection.
Tap and Use -> it occurs when for instance two users are running the same app (say a battleship game) and tap their PCs toghether; this action triggers an event that can be handled by the two apps to communicate toghether.
Tap and Launch -> this case is particularly intriguing because, when in proximity, one app running on one PC can invite the user of the other PC to start the same app, if installed.
Tap and Acquire -> similar to the previous case but here the second user does not have the app installed and so he is invited to acquire and install the app.
Tap and Share -> imagine you are visiting a website and want to share it with your friend; just tap your PC to the PC (or phone or tablet) of your friend and he will receive a confirmation request to accept the shared
URL.
Tap and Receive -> with this user case a user can tap his PC to another device (a PC, phone or even a passive tag) which is exposing content, and he is invited to receive that content.
The Windows.Networking.Proximity namespace
In the previous paragraph we have seen that a unique Near Field proximity (NFP) provider model is expected for all the underlying wireless technology used. For developers this means good news: there is a common API set to deal with all these technologies (including NFC) and it is available in all the languages that can use WinRT, currently C#, C++ and JS.
Windows.Network.Proximity namespace includes six classes that we can use to realize the use cases described above:
- ProximityDevice
- ProximityMessage
- PeerFinder
- PeerInformation
- ConnectionRequestedEventArgs
In the second part of this article we will give a close look at the proximity API and we will provide some examples. But before that we need to build a test environment, and this is what the next paragraph is about.
A simulation environment to test Proximity API
At the time of writing this article there is just one device, to my knowledge, available on the market with NFC enabled: Samsung slate PC. Does that mean that we should buy two of these devices for trialling the Proximity API? Fortunately not, there is another way to get a kick out of it. We can use a proximity driver sample included in Windows Driver Kit (WDK) to simulate a tap gesture over a network connection. To do this we can use two virtual machines with Windows 8 onboard and install the driver on both machines. In the following pages you find all the necessary steps to realize that. But before that let's take a look at the recipe needed to build the environment:
- Windows 8 Release Preview build
→ I suggest a 64-bit version, you can download it here
- Virtualization software capable of running the above build
→ I used VirtualBox 4.1.8 available here
- Visual Studio 2012 RC
→ available here
- Windows Driver Kit 8.0 (WDK)
→ available here
- Windows 8 Driver samples
→ download the full package (C# & C++) from here
- Windows Driver Frameworks (WDF) Co-Installers
→ download from here
1. Setup of virtual machines
Using VirtualBox is fairly easy to set up a virtual machine. Just pay attention to name the two VM differently and to choose network settings that allow the VM to communicate together. I used “Bridged adapter” as network adapter as in figure:
Then install Windows 8 and proceed with the installation of Visual Studio 2012, Windows Driver Kit 8.0 and the WDF coinstallers on both VM.
The Windows 8 Driver samples includes a sample called NetNfpProvider which contains the proximity driver. In sample description page there is some guidance for installing and using the proximity driver but the installation is a bit tricky because some steps are skipped. To bring it to a successful conclusion I suggest you follow the steps below.
2. Extract NetNfpProvider sample package
Unzip Windows 8 Driver Samples package in a directory and explore it to locate “NetNfpControl” subdirectory. Open the “netnfp” solution that you will find in the “C++” subdirectory. The solution contains 3 projects:
- NetNfpProvider that contains the driver
- NetNfpControl that contains a command-line executable to interact with the driver
- Package contains driver package
In the Solution Explorer window, right-click Solution 'netnfp' and choose Configuration Manager: make sure that all the projects are configured for x64 platform, as in figure below:
3. Sign the driver
To install a driver on a 64-bit version of Windows, you must sign the driver package. The following procedure helps you to test signing the driver, which is a simplified procedure useful for testing purposes.
Right-click the driver package project, and choose Properties as in figure below:
In the Properties window expand the “Configuration Properties” branch in the tree on the left, click on “Driver Signing” and select Test Sign in the Sign Mode drop-down list as below:
Then click on Inf2Cat > General. In the Run Inf2Cat drop-down list, select Yes as below:
If we now try to build the solution, a catalog file (.CER) will be created.
4. Export the certificate
Now we have to share our signing certificate. Still in Properties, for the package select Configuration Properties > Driver Signing > General and in the Test Certificate choose Select From Store as below:
In the Select Certificate dialog box, select the certificate named “WDKTestCertyourUserName” as in figure below:
Click on Properties of the certificate selected and from the “Details” tab click “Copy to File” as in figure below:
An export wizard will open to guide you to export a .pbx file :
Click on Next to proceed; then you will be asked to choose the export format of the file; choose .PFX as in figure below:
Click Next and protect your private key with a password. Don’t forget your password since you will need it when you import the certificate into your local machine:
Click Next and name the file to be exported as below:
click Save to get the final summary view:
5. Import the certificate into your local machine
Obviously the local machine is one of the 2 VM. Go to the directory where you exported your pfx file and right-click the file; the contextual menu should look like in figure below:
Click Install PFX and in the “certificate Import wizard” dialog box select “Local Machine” as Store location as below:
Click Next and in the next screen , browse for the .pbx file you previously created:
Click Next and type in the password you previously set for your private key:
Click on “Browse” to specify a location for the certificate:
Click on “Show physical stores” check box as in figure below then select “Trusted Root Certification Authorities\Registry” and click OK.
Finally, click the Finish button to complete the import:
5. Install the driver
To sum up, we have test signed the driver, exported the certificate and imported it into the local VM. Now we can install the driver. Create a directory (for instance c:\NetNfpprovider) and copy the following files from the output directory of the VS solution ( i.e. : ..\NetNfpProvider\C++\Package\x64\Win8Release\Package):
- driver binary and inf: NetNfpProvider.dll, NetNfpProvider.inf
- coinstaller: WdfCoinstaller01011.dll
- wdfupdate: WudfUpdate_01011.dll
since you have to run the device console devcon.exe, copy it from \Program Files (x86)\Windows Kits\8.0\Tools\x64 or add the path to the environment variables.
Disable the Windows Firewall or, as suggested by the official guide create an inbound rule to allow incoming requests to NetNfpProvider to the port 9929.
Open a command-line windows as Administrator in the directory in which you copied the files and launch the following command:
“devcon.exe install NetNfpProvider.inf WUDF\NetNfpProvider”
If everything is OK you should be notified that the driver has been succesfully installed as in figure below:
You can now install the driver onto the second virtual machine by importing the certificate driver, copy the directory you created above and launch devcon.exe with the same parameters as above.
In the second part we will learn how to use the driver.
Summary
We have introduced Near field Communication technology highlighting how it could be applied to the everyday life. We have then seen the Microsoft concept of Proximity intended as something more general. With “Tap and Do” Microsoft has summed up with a slogan the communication between two devices in close proximity. In this first part we have minutely described how to install a sample driver onto two virtual machines in order to simulate a tap gesture over the network and have the possibility to test the Proximity API. In the second part we will see how to use the driver and how easy it is to use the Proximity API.
Want to test your understanding of this article? Walter Ferrari challenges you to prove you got it all right! Take the challenge below:
|
Create Two Virtual Machines with Windows 8
|
Challenges powered by
|