The Art and Science of NFC Programming
Intellectual Technologies Set
coordinated by
Jean-Max Noyer and Maryse Carmes
Volume 3
The Art and Science of
NFC Programming
Anne-Marie Lesas
Serge Miranda
First published 2017 in Great Britain and the United States by ISTE Ltd and John Wiley & Sons, Inc.
Apart from any fair dealing for the purposes of research or private study, or criticism or review, as
permitted under the Copyright, Designs and Patents Act 1988, this publication may only be reproduced,
stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers,
or in the case of reprographic reproduction in accordance with the terms and licenses issued by the
CLA. Enquiries concerning reproduction outside these terms should be sent to the publishers at the
undermentioned address:
ISTE Ltd
27-37 St George’s Road
London SW19 4EU
UK
www.iste.co.uk
John Wiley & Sons, Inc.
111 River Street
Hoboken, NJ 07030
USA
www.wiley.com
© ISTE Ltd 2017
The rights of Anne-Marie Lesas and Serge Miranda to be identified as the authors of this work have been
asserted by them in accordance with the Copyright, Designs and Patents Act 1988.
Library of Congress Control Number: 2016954190
British Library Cataloguing-in-Publication Data
A CIP record for this book is available from the British Library
ISBN 978-1-78630-057-7
Contents
Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vii
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xi
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
1
2
3
Chapter 1. State-of-the-Art of NFC . . . . . . . . . . . . . . . . . .
1.1. Future mobiquitous digital services . . . . . . . . . . . . . . . .
1.1.1. The era of mobiquity . . . . . . . . . . . . . . . . . . . . . .
1.1.2. Toward a world of contactless
6
communicating objects . . . . . . . . . . . . . . . . . . . . . . . . .
7
1.2. NFC equipment . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
1.2.1. NFC tag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2.2. NFC smart card . . . . . . . . . . . . . . . . . . . . . . . . . .
8
1.2.3. NFC smartphone . . . . . . . . . . . . . . . . . . . . . . . . . 13
1.2.4. Reader/encoder: NFC transaction terminals . . . . . . . . . 14
1.2.5. “Smart cities” and sustainable development . . . . . . . . . 14
1.2.6. Cashless payment with NFC . . . . . . . . . . . . . . . . . . 15
1.3. NFC standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
1.3.1. Analog signal and NFC digital transposition . . . . . . . . 18
1.3.2. The three standardized modes of NFC . . . . . . . . . . . . 21
1.3.3. NFC forum standards . . . . . . . . . . . . . . . . . . . . . . 25
1.3.4. GlobalPlatform (GP) . . . . . . . . . . . . . . . . . . . . . . 36
1.3.5. SIMAlliance and open mobile API . . . . . . . . . . . . . . 42
vi The Art and Science of NFC Programming
Chapter 2. Developing NFC
Applications with Android . . . . . . . . . . . . . . . . . . . . . . . . 45
2.1. Introduction to Android programming
using Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.1.1. Android in a nutshell . . . . . . . . . . . . . . . . . . . . . . . 46
2.1.2. Android in Eclipse IDE . . . . . . . . . . . . . . . . . . . . . 49
2.1.3. Intents and Android context . . . . . . . . . . . . . . . . . . . 60
2.1.4. The Activity class of Android . . . . . . . . . . . . . . . . . . 61
2.1.5. Android graphical interface: “layout” files . . . . . . . . . . 64
2.1.6. Compiling and testing an Android application . . . . . . . . 67
2.2. Implementing NFC with Android . . . . . . . . . . . . . . . . . . 70
2.2.1. Android manifest declarations . . . . . . . . . . . . . . . . . 71
2.2.2. Implementing the NFC reader/writer mode . . . . . . . . . . 71
2.2.3. Implementing the NFC P2P mode with Android . . . . . . 83
2.2.4. Implementing the NFC card emulation
mode with Android . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
2.2.5. Developing NFC services with Android HCE . . . . . . . . 97
Chapter 3. NFC Use Cases . . . . . . . . . . . . . . . . . . . . . . . . 107
3.1. Usage of the NFC reader/writer mode . . . . . . . . . . . . . . . 107
3.1.1. Use case: management of equipment loans . . . . . . . . . . 108
3.2. Usage of the NFC P2P mode . . . . . . . . . . . . . . . . . . . . . 112
3.2.1. Use case: NFC pairing . . . . . . . . . . . . . . . . . . . . . . 112
3.3. Usage of NFC card emulation mode . . . . . . . . . . . . . . . . 114
3.3.1. Use case: digital wallet in the SE . . . . . . . . . . . . . . . . 115
3.4. Usage of the HCE mode . . . . . . . . . . . . . . . . . . . . . . . 118
3.4.1. Use case: SE in the Cloud with HCE . . . . . . . . . . . . . 119
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Foreword
“The main rule is to please and touch.
All others are made only to achieve this first one”.
MOLIERE
Even if the NFC standard is young (developed in 2004), I have
been asked to write this book for several years now, due to the
pioneering role played in France (and in Europe) by our Computer
Science Master’s degree MBDS (www.mbds-fr.org) at the University
of Nice – Sophia-Antipolis around the prototyping of innovative
services using this standard. MBDS prototyped NFC services in
all sectors of economic life: from tourism and culture in Nice, to
social payment in India, via campuses in Haiti, museums, airports,
hotels, connected houses in Morocco and electric cars in Sophia
Antipolis. In 2009, the city of Nice was the first for the deployment of
NFC standard in Europe, because of the MBDS innovation research
lab.
After half a dozen books published on databases, I was not really
eager to write a new book. My first collection of books, following
Knuth’s book (The Art of Computer Programming), my bedside
reading as a fellowship student in California, was entitled “The Art of
Databases”.
viii The Art and Science of NFC Programming
What changed my mind was the enthusiasm of Anne-Marie Lesas,
who was working on her PhD on NFC secure services with our
industrial partner Gemalto under a CIFRE convention1 from the
ANRT2 and of an IFCPAR contract3 (www.cefipra.org) on NFC
virtual social currency in India with TATA Consultancy Services (CS)
and Bangalore University, as well as a scientific expertise on NFC
patent infringement in the United States in 2015. As a brilliant former
MBDS student after a professional career, Anne-Marie first showed
passion for mobiquitous new technologies (NFC cars, and means of
detecting earthquakes by using smartphone sensors). What a delight
for a professor, who is nothing but a dream purveyor, to see a student
take over.
The title of this book implies the duality of “Art” and “Science”,
which are the two approaches to perception and understanding of the
world; in prefaces to database books, I would write: “the word art
refers to a way of investigation, recreation and interpretation of the
real world in opposition to the science which bears an abstract
interpretation, based on formal concepts, models and tools”. Creativity
on NFC applications is unlimited with mobiquitous usages that
reinvent the real world by creating new bridges toward the virtual
world; these applications are based on strict standardized concepts that
we explain, along with their implementation methods. Dealing with
this duality is the double purpose of this book.
In this way, this book is the result of a pedagogical encounter
between a professor and a researcher in order to allow other IT
developers to contribute to changing the world by touching it! I would
thus like to thank Anne-Marie for her professional and human skills
and, through her, all students who, by their enthusiasm, lead me
toward a process of never-ending, spiral innovation. Creativity on
content and services is a beautiful spiralist adventure that brings life
1 Industrial contracts for training through research.
2 The French Association Nationale de la Recherche et de la Technologie.
3 Indo-French Centre for the Promotion of Advanced Research.
Foreword ix
(special thanks to Franketienne for this beautiful concept of spiralism,
which we shared and discussed in Port au Prince).
I would like to invite readers to dream about their life, to have big
dreams while keeping in mind that new technologies must first and
foremost serve the good of humankind and the improvement of shared
environments, and of the lives of each of us. “Always put man at the
center” and do not hesitate to be “a nonconformist, even an innovation
anarchist” as shown by Pierre Laffite, the founder of Sophia-Antipolis
Science park.
I also have a thought for my friend and colleague, pioneer of all
types of databases (and Big Data), Mike Stonebraker, godfather of one
of the first MBDS classes and winner of the Turing Award in 2014,
who would always stress applied research in information systems,
with the obsession of always trying to solve concrete problems and
not to only stick to simple theoretical intellectual constructions
disconnected from reality.
This book has a double purpose, which corresponds to its two main
parts; it aims both toward:
– an exhaustive, theoretical approach of the NFC standard,
the
the future of smartphones, as much
in
unavoidable
informational as in the transactional world;
in
– a pragmatic and systematic approach of the development of NFC
applications, based on numerous prototypes of innovative services
created within our MBDS Master’s program since the birth of the
standard in 2004.
This book is for IT engineers (IT generalists as much as students in
Bachelor’s or Master’s programs) who are passionate about new
technologies and curious about the use of NFC, particularly in mobile
applications; our goal is to explain the technical and functional
specificities of the NFC standard through notions essential to the
understanding of the ecosystem, its mobile implementation (with
Android) and its main applications.