near field communication (nfc) for next generation smart phone apps

Post on 06-Mar-2015

115 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

1

NFC – For Next Generation Smart Phone Apps

Ashutosh TripathiTalentica Softwares

2

Agenda

• What is NFC ?

• Why NFC ?

• How NFC works

• NFC & Mobiles

• Building NFC App – Android

• Security Aspects

3

What is NFC ?

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

5

Why NFC ?

6

To Read Smart Posters

As Event Tickets

Sharing Business Card

Easy Printing

Mobile Payment

Transport Ticketing

File Sharing

ID Cards

7

Enhanced Wireless experience

•Instant Bluetooth Pairing

•Instant Wi-Fi Configuration

Wireless Nirvana

8

Google Wallet

• Stores virtual version of your existing cards

• Tap and pay

• Receive loyalty cards, recipiets

• Secure

9

Its just the beginning….

• Peer 2 Peer Payment

• Electronic Keys

• Social Networking

• Smart Mobility

• Entertainment

• Secure PC Login

• More…..

10

How NFC Works

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

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

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

14

NDEF Record

Flags

• MB,ME,CF,SR

Type Name Format

Type

ID

Payload

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

16

NFC & Mobiles

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)

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…

19

Future Market

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

21

Building NFC App - Android

22

What we can do with Android (for now)

• Reading Tags

• Writing Tags

• Peer 2 Peer Communication (limited)

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

24

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>

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>

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>

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

}

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

30

Security Aspects

31

1. Eavesdropping

2. Data Modifications

3. Data Insertion

4. Man-in-the-middle Attack

5. Lost Property

32

33

Thanks

top related