33
1 NFC – For Next Generation Smart Phone Apps Ashutosh Tripathi Talentica Softwares

Near Field Communication (NFC) For Next Generation Smart Phone Apps

Embed Size (px)

DESCRIPTION

Presented By Ashutosh Tripathi at the 2nd IndicThreads.com Conference On Mobile Application Development, August 2011

Citation preview

Page 1: Near Field Communication (NFC) For Next Generation Smart Phone Apps

1

NFC – For Next Generation Smart Phone Apps

Ashutosh TripathiTalentica Softwares

Page 2: Near Field Communication (NFC) For Next Generation Smart Phone Apps

2

Agenda

• What is NFC ?

• Why NFC ?

• How NFC works

• NFC & Mobiles

• Building NFC App – Android

• Security Aspects

Page 3: Near Field Communication (NFC) For Next Generation Smart Phone Apps

3

What is NFC ?

Page 4: Near Field Communication (NFC) For Next Generation Smart Phone Apps

4

• 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

Page 5: Near Field Communication (NFC) For Next Generation Smart Phone Apps

5

Why NFC ?

Page 6: Near Field Communication (NFC) For Next Generation Smart Phone Apps

6

To Read Smart Posters

As Event Tickets

Sharing Business Card

Easy Printing

Mobile Payment

Transport Ticketing

File Sharing

ID Cards

Page 7: Near Field Communication (NFC) For Next Generation Smart Phone Apps

7

Enhanced Wireless experience

•Instant Bluetooth Pairing

•Instant Wi-Fi Configuration

Wireless Nirvana

Page 8: Near Field Communication (NFC) For Next Generation Smart Phone Apps

8

Google Wallet

• Stores virtual version of your existing cards

• Tap and pay

• Receive loyalty cards, recipiets

• Secure

Page 9: Near Field Communication (NFC) For Next Generation Smart Phone Apps

9

Its just the beginning….

• Peer 2 Peer Payment

• Electronic Keys

• Social Networking

• Smart Mobility

• Entertainment

• Secure PC Login

• More…..

Page 10: Near Field Communication (NFC) For Next Generation Smart Phone Apps

10

How NFC Works

Page 11: Near Field Communication (NFC) For Next Generation Smart Phone Apps

11

Communication Modes

Active• Both Initiator and target is powered devices

Passive• Target device may draw its operating power from the initiator-

provided electromagnetic field

Initiator

Initiate Communication by generating RF field

Active Device Active/Passive Device

Page 12: Near Field Communication (NFC) For Next Generation Smart Phone Apps

12

Operating modes

Reader/Writer

Peer to Peer

Card Emulation

Card Emulation Mode

Peer 2 Peer Mode

Reader/WriterMode

Application

RTD&

NDEFLLCP

NFC Forum protocol bindingsCard emulation

Smart Card capability for

mobile devices Tag types 1-4

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

Page 13: Near Field Communication (NFC) For Next Generation Smart Phone Apps

13

NDEF – NFC Data Exchange Format

• Message Encapsulation format to exchange information between NFC devices/tags

• Lightweight, binary

• Supports URI,MIME or NFC specific types

Page 14: Near Field Communication (NFC) For Next Generation Smart Phone Apps

14

NDEF Record

Flags

• MB,ME,CF,SR

Type Name Format

Type

ID

Payload

Page 15: Near Field Communication (NFC) For Next Generation Smart Phone Apps

15

Type Name Format Value

Empty 0x00

NFC Forum Well Known Type 0x01

MIME Type 0x02

Absolute URI 0x03

NFC Forum External Type 0x04

Unknown 0x05

Unchanged 0x06

Reserved 0x07

Page 16: Near Field Communication (NFC) For Next Generation Smart Phone Apps

16

NFC & Mobiles

Page 17: Near Field Communication (NFC) For Next Generation Smart Phone Apps

17

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)

Page 18: Near Field Communication (NFC) For Next Generation Smart Phone Apps

18

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…

Page 19: Near Field Communication (NFC) For Next Generation Smart Phone Apps

19

Future Market

Page 20: Near Field Communication (NFC) For Next Generation Smart Phone Apps

20

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

Page 21: Near Field Communication (NFC) For Next Generation Smart Phone Apps

21

Building NFC App - Android

Page 22: Near Field Communication (NFC) For Next Generation Smart Phone Apps

22

What we can do with Android (for now)

• Reading Tags

• Writing Tags

• Peer 2 Peer Communication (limited)

Page 23: Near Field Communication (NFC) For Next Generation Smart Phone Apps

23

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

Page 24: Near Field Communication (NFC) For Next Generation Smart Phone Apps

24

Page 25: Near Field Communication (NFC) For Next Generation Smart Phone Apps

25

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>

Page 26: Near Field Communication (NFC) For Next Generation Smart Phone Apps

26

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>

Page 27: Near Field Communication (NFC) For Next Generation Smart Phone Apps

27

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>

Page 28: Near Field Communication (NFC) For Next Generation Smart Phone Apps

28

Handle Intent : MainActivity.java

NdefMessage[] getNdefMessages(Intent intent) {

NdefMessage msg = null;

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;

}

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

NdefMessage msg = getNdefMessage(getIntent());

// process msg

}

Page 29: Near Field Communication (NFC) For Next Generation Smart Phone Apps

29

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);

Page 30: Near Field Communication (NFC) For Next Generation Smart Phone Apps

30

Security Aspects

Page 31: Near Field Communication (NFC) For Next Generation Smart Phone Apps

31

1. Eavesdropping

2. Data Modifications

3. Data Insertion

4. Man-in-the-middle Attack

5. Lost Property

Page 32: Near Field Communication (NFC) For Next Generation Smart Phone Apps

32

Page 33: Near Field Communication (NFC) For Next Generation Smart Phone Apps

33

Thanks