You are on page 1of 33

NFC For Next Generation Smart Phone Apps

Ashutosh Tripathi
Talentica Softwares

Agenda
What is NFC ? Why NFC ? How NFC works NFC & Mobiles Building NFC App Android Security Aspects

What is NFC ?
3

Near Field Communication Short Range Wireless (a few centimeters) Operates at frequency 13.56 MHz Less speed (106kbps 414 kbps) Low Friction Setup Passive Targets

Why NFC ?
5

As Event Tickets To Read Smart Posters

Sharing Business Card

Easy Printing ID Cards

Mobile Payment File Sharing Transport Ticketing

Enhanced Wireless experience


Instant Bluetooth Pairing Instant Wi-Fi Configuration

Wireless Nirvana

Google Wallet
Stores virtual version of your existing cards Tap and pay Receive loyalty cards, recipiets Secure

Its just the beginning.


Peer 2 Peer Payment Electronic Keys Social Networking Smart Mobility Entertainment Secure PC Login More..

How NFC Works


10

Initiate Communication by generating RF field

Initiator
Active Device

Target
Active/Passive Device

Communication Modes Active


Both Initiator and target is powered devices

Passive
Target device may draw its operating power from the initiatorprovided electromagnetic field
11

Operating modes
 Reader/Writer  Peer to Peer  Card Emulation
Card emulation Smart Card capability for mobile devices Card Emulation Mode Peer 2 Peer Mode Application Reader/Writer Mode

NFC Forum protocol bindings

RTD & NDEF Tag types 1-4

LLCP

RF layer ISO 18092 + ISO14443 Type A,B + Felica

12

NDEF NFC Data Exchange Format


Message Encapsulation format to exchange information between NFC devices/tags Lightweight, binary Supports URI,MIME or NFC specific types

13

NDEF Record
Flags
MB,ME,CF,SR

Type Name Format Type ID Payload

14

Type Name Format Empty NFC Forum Well Known Type MIME Type Absolute URI NFC Forum External Type Unknown Unchanged Reserved

Value 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07

15

NFC & Mobiles


16

Already in Market..
Google Nexus S (1st NFC Android Phone) Samsung Galaxy SII (android) Nokia C7 Blackberry Bold 9900 and 9930 Nokia 6131 (1st NFC Phone now out of market)

17

Upcoming & Rumored


iPhone 5 (rumored) Nokia N9,N5 Multiple Android OS 2.3.3 based phones LG Optimus NET Samsung BADA OS based phones Many more

18

Future Market

19

What we have learned so far..


NFC is short range wireless communication Works with both active/passive targets Can read/write passive tags Easy sharing ,printing, pairing and transaction Data transaction is done in NDEF format Great future

20

Building NFC App - Android


21

What we can do with Android (for now)


Reading Tags Writing Tags Peer 2 Peer Communication (limited)

22

How we start
Essential
Set required permission in Manifest Add required intent filers in Manifest Handle intent in main Activity to read data

Working approach
Intent Dispatch : identify appropriate application Foreground Dispatch : intercept in your application
23

Setting Permissions : AndroidManifest.xml


Request permission to use NFC hardware
<uses-permission android:name="android.permission.NFC" />

Set Minimum SDK version required . Supported above API level 9 only
<uses-sdk android:minSdkVersion="9" />

Declare your application works on NFC supported device


<uses-feature android:name="android.hardware.nfc" android:required="true" />
24

Defining Intent Filter


<intent-filter> <action android:name="android.nfc.action.NDEF_DISCOVERED"/> <data android:mimeType="mime/type" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.TECH_DISCOVERED"/> <meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_filter.xml" /> </intent-filter> <intent-filter> <action android:name="android.nfc.action.TAG_DISCOVERED"/> </intent-filter>

25

Filtering supported TAG


<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> <tech-list> <tech>android.nfc.tech.IsoDep</tech> <tech>android.nfc.tech.NfcA</tech> <tech>android.nfc.tech.NfcB</tech> <tech>android.nfc.tech.NfcF</tech> <tech>android.nfc.tech.NfcV</tech> <tech>android.nfc.tech.Ndef</tech> <tech>android.nfc.tech.NdefFormatable</tech> <tech>android.nfc.tech.MifareClassic</tech> <tech>android.nfc.tech.MifareUltralight</tech> </tech-list> </resources>

26

Your Manifest Putting all together


<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.android.nfc"> <uses-permission android:name="android.permission.NFC" /> <uses-sdk android:minSdkVersion="9" /> <uses-feature android:name="android.hardware.nfc" android:required="true" /> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name="TagViewer" > <intent-filter> <action android:name="android.nfc.action.TAG_DISCOVERED"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity> </application> </manifest>
27

Handle Intent : MainActivity.java


NdefMessage[] getNdefMessages(Intent intent) { NdefMessage msg = null;

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); NdefMessage msg = getNdefMessage(getIntent()); // process msg }

if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) { msgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0]; if (msg == null) { byte[] empty = new byte[] {}; NdefRecord record = new NdefRecord(NdefRecord.TNF_UNKNOWN, empty, empty, empty); msg = new NdefMessage(new NdefRecord[] {record}); } } else { // Your logic } return msg; }

28

Writing data:
String text; NdefRecord textRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, "text/plain".getBytes(), text.getBytes()); NdefMessage textMessage = new NdefMessage(new NdefRecord[]{textRecord}); Tag tag = getIntent().getExtra(NfcAdapter.EXTRA_TAG); Ndef ndef = Ndef.get(tag); ndef.writeNdefMessage(textMessage);

29

Security Aspects
30

1. Eavesdropping 2. Data Modifications 3. Data Insertion 4. Man-in-the-middle Attack 5. Lost Property

31

32

Thanks

33

You might also like