forked from w3c/web-nfc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
2740 lines (2685 loc) · 109 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Web NFC API</title>
<meta charset="UTF-8">
<script src='https://www.w3.org/Tools/respec/respec-w3c-common'
class='remove'>
</script>
<script class="remove">
var respecConfig = {
specStatus: "CG-DRAFT",
shortName: "web-nfc",
noLegacyStyle: true,
publishDate: "",
previousPublishDate: "",
previousMaturity: "",
edDraftURI: "https://w3c.github.io/web-nfc/",
crEnd: "",
editors: [
{ name: "Kenneth Rohde Christiansen", company: "Intel",
companyURL: "http://www.intel.com/" },
{ name: "Zoltan Kis", company: "Intel",
companyURL: "http://www.intel.com/" },
],
inlineCSS: true,
noIDLIn: true,
// extraCSS: ["../ReSpec.js/css/respec.css"],
wg: "Web NFC Community Group",
wgURI: "https://www.w3.org/community/web-nfc/",
wgPublicList: "public-web-nfc",
issueBase: "https://www.github.com/w3c/web-nfc/issues/",
githubAPI: "https://api.github.com/repos/w3c/web-nfc",
otherLinks: [
{
key: "Repository",
data: [{
value: "We are on Github.",
href: "https://github.com/w3c/web-nfc"
}, {
value: "File a bug.",
href: "https://github.com/w3c/web-nfc/issues"
}, {
value: "Commit history.",
href: "https://github.com/w3c/web-nfc/commits/gh-pages"
}, {
value: "Usage scenarios",
href: "https://w3c.github.io/web-nfc/use-cases.html"
}
]
},
{
key: "Contributors",
data: [{
value: "In the github repository",
href: "https://github.com/w3c/web-nfc/graphs/contributors"
}
]
},
],
localBiblio: {
"NFC-SECURITY": {
href: "https://github.com/w3c/web-nfc/security-privacy.html",
title: "Web NFC Security and Privacy",
publisher: "W3C",
date: "25 April 2015",
},
"NFC-USECASES": {
href: "https://github.com/w3c/web-nfc/use-cases.html",
title: "Web NFC Use Cases",
publisher: "W3C",
date: "25 April 2015",
},
"NFC-STANDARDS": {
href: "http://members.nfc-forum.org/specs/spec_list/",
title: "NFC Forum Technical Specifications",
publisher: "NFC Forum",
date: "24 July 2006"
},
"ISO-639.2": {
href: "https://www.loc.gov/standards/iso639-2/php/code_list.php",
title: "Codes for the Representation of Names of Languages",
publisher: "ISO",
date: "18 March 2014"
},
"WEBAPPSEC": {
href:"https://w3c.github.io/webappsec/specs/powerfulfeatures",
title: "Secure Contexts",
publisher: "W3C",
date: "17 July 2015"
},
},
};
</script>
<style>
table.simple { border: 1px solid #000; }
table.simple td { border-right: 1px solid #000; }
</style>
</head>
<body>
<!-- - - - - - - - - - - - - - - - Abstract - - - - - - - - - - - - - - - - -->
<section id="abstract">
<p>
Near Field Communication (NFC) enables wireless communication between two
devices at close proximity, usually less than a few centimeters.
NFC is an international standard (ISO/IEC 18092) defining an interface and
protocol for simple wireless interconnection of closely coupled devices
operating at 13.56 MHz
(see <a href="https://www.nfc-forum.org/specs/spec_list/">
https://www.nfc-forum.org/specs/spec_list/</a>).
</p>
<p>
This document defines an API to enable selected use-cases based on
NFC technology.
</p>
</section>
<!-- - - - - - - - - - - - Status of this document - - - - - - - - - - - - -->
<section id="sotd">
<p>
Implementers need to be aware that this specification is considered
unstable.
Implementers who are not taking part in the discussions will find the
specification changing out from under them in incompatible ways. Vendors
interested in implementing this specification before it eventually reaches
the Candidate Recommendation phase should subscribe to the repository on
GitHub and take part in the discussions.
</p>
<p>
Significant changes to this document since last publication are
documented in the <a href="#Changes">Changes section</a>.
</p>
</section>
<!-- - - - - - - - - - - - - - - Conformance - - - - - - - - - - - - - - - -->
<section id="conformance">
<p>
This document defines conformance criteria that apply to a single
product: the <dfn>UA</dfn> that implements the interfaces it contains.
</p>
<p>
Implementations that use ECMAScript to implement the APIs defined in
this document MUST implement them in a manner consistent with the
ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as
this document uses that specification and terminology.
</p>
</section>
<!-- - - - - - - - - - - - - - - Terminology - - - - - - - - - - - - - - - -->
<section> <h2>Terminology and conventions</h2>
<p>
The term <a href="https://html.spec.whatwg.org/#browsing-context">
<dfn>browsing context</dfn></a> refers to the environment in which
<a href="https://html.spec.whatwg.org/#document"><dfn>Document</dfn></a>
objects are presented to the user. A given <a>browsing context</a> has a
single <a>origin</a> and a single <code>WindowProxy</code> object, but it
can have many <code>Document</code> objects, with their associated
<code>Window</code> objects. The <i>browsing context</i> identifies
the entity which invokes this API, which can be a <i>web app</i>, a
<i>web page</i>, or an
<a href="https://html.spec.whatwg.org/#the-iframe-element">iframe</a>.
</p>
<p>
Inspired by the <a href="https://streams.spec.whatwg.org/#conventions">
Streams specification</a>, we use the notation x@[[\y]] to refer to
<a href="http://ecma-international.org/ecma-262/6.0/#sec-object-internal-methods-and-internal-slots">
internal slots</a> of an object, instead of saying "the [[\y]] internal slot of x."
</p>
<p>
The Augmented Backus-Naur Form (ABNF) notation used is specified in RFC5234. [[ABNF]]
</p>
<p>
The term
<a href="https://html.spec.whatwg.org/#script-execution-environment">
<dfn>script execution environment</dfn></a> is defined in [[!HTML5]].
</p>
<p>
The term <a href="https://html.spec.whatwg.org/#top-level-browsing-context">
<dfn>top-level browsing context</dfn></a> is defined in [[!HTML5]].
</p>
<p>
The term
<a href="http://www.w3.org/TR/html5/webappapis.html#incumbent-settings-object">
<dfn>incumbent settings object</dfn></a> is defined in [[!HTML5]].
</p>
<p>
The term
<a href="https://w3c.github.io/webappsec/specs/powerfulfeatures/#secure-context">
<dfn>secure context</dfn></a> is defined in [[!WEBAPPSEC]].
</p>
<p>
The term of executing algorithms
<a href="https://html.spec.whatwg.org/#in-parallel"><dfn>in parallel</dfn></a>
is defined in [[!HTML5]].
</p>
<p>
<a href="http://www.w3.org/TR/url-1/"><dfn>URL</dfn></a>
is defined in [[!URL]].
</p>
<p>
The term
<a href="http://www.w3.org/TR/2011/WD-html5-20110113/urls.html#document-base-url">
<dfn>document base URL</dfn></a> is defined in [[!HTML5]].
</p>
<p>
The term <a href="https://url.spec.whatwg.org/#concept-url-path">
<dfn>URL path</dfn></a> is defined in [[!URL]].
</p>
<p>
The term
<a href="https://html.spec.whatwg.org/#origin">
<dfn>origin</dfn></a> is defined in [[!HTML5]].
</p>
<p>
The term <a href="https://html.spec.whatwg.org/#ascii-serialisation-of-an-origin">
<dfn>ASCII serialized origin</dfn></a> is defined in [[!HTML5]].
</p>
<p>
<a href="http://heycam.github.io/webidl/#idl-DOMString">
<code><dfn>DOMString</dfn></code></a>,
<a href="http://heycam.github.io/webidl/#idl-ArrayBuffer">
<code><dfn>ArrayBuffer</dfn></code></a>,
<a href="http://heycam.github.io/webidl/#common-BufferSource">
<code><dfn>BufferSource</dfn></code></a> and
<a href="http://www.w3.org/TR/WebIDL/#idl-any">
<code><dfn>any</dfn></code></a>
are defined in [[!WEBIDL]].
</p>
<p>
<!--a href="http://www.w3.org/TR/dom/#eventinit">
<dfn>EventInit</dfn></a>,-->
<a href="http://www.w3.org/TR/dom/#domexception">
<dfn>DOMException</dfn></a>,
<a href="http://www.w3.org/TR/dom/#aborterror">
<dfn>AbortError</dfn></a>,
<a href="http://www.w3.org/TR/dom/#syntaxerror">
<dfn>SyntaxError</dfn></a>,
<a href="http://www.w3.org/TR/dom/#notsupportederror">
<dfn>NotSupportedError</dfn></a>,
<a href="http://www.w3.org/TR/dom/#notfounderror">
<dfn>NotFoundError</dfn></a>,
<a href="http://www.w3.org/TR/dom/#networkerror">
<dfn>NetworkError</dfn></a>,
<a href="http://www.w3.org/TR/dom/#securityerror">
<dfn>SecurityError</dfn></a>
are defined in [[!DOM4]].
</p>
<p>
<a href="http://www.ecma-international.org/ecma-262/6.0/#sec-promise-objects">
<dfn>Promise</dfn></a>,
<a href="http://www.ecma-international.org/ecma-262/6.0/#sec-json-object">
<dfn>JSON</dfn></a>,
<a href="http://www.ecma-international.org/ecma-262/6.0/#sec-json.stringify">
<dfn>JSON.stringify</dfn></a> and
<a href="http://www.ecma-international.org/ecma-262/6.0/#sec-json.parse">
<dfn>JSON.parse</dfn></a>
are defined in [[!ECMASCRIPT]].
</p>
<p>
The algorithms <a href="http://www.w3.org/TR/encoding/#utf-8-encode">
<dfn>utf-8 encode</dfn></a>, and
<a href="http://www.w3.org/TR/encoding/#utf-8-decode">
<dfn>utf-8 decode</dfn></a> are defined in [[!ENCODING]].
</p>
<p>
<dfn>IANA media type</dfn>s (formerly known as MIME types) are defined in
<a href="http://tools.ietf.org/html/rfc2046">RFC2046</a>.
</p>
<p>
A <a href="https://html.spec.whatwg.org/#valid-mime-type">
<dfn>valid MIME type</dfn></a> is defined in [[!HTML5]].
</p>
<p>
The term <dfn><a href="https://html.spec.whatwg.org/#queue-a-task">queue
a task</a></dfn> is defined in [[!HTML5]].
</p>
<p>
The term <dfn><a href="https://html.spec.whatwg.org/#task-source">task
source</a></dfn> is defined in [[!HTML5]].
</p>
<section> <h3>Security</h3>
<p>
The term <dfn>expressed permission</dfn> refers to an act by the user, e.g.
via user interface or setting or host device platform features, using which
the user approves the permission of a <a>browsing context</a> to access the
given functionality.
</p>
<p>
The term <dfn id="askforgiveness">ask for forgiveness</dfn> refers to some
form of unobtrusive notification that informs the user of an operation
while it is running.
UAs SHOULD provide the user with means to ignore similar future
operations from the same <a>origin</a> and advertise this to the user.
</p>
<p>
The term <dfn>prearranged trust relationship</dfn> means that the
UA has already established a trust relationship for a
certain operation using a platform specific mechanism, so that an
<a>expressed permission</a> from the user is not any more needed.
See also this
<a href="http://w3c.github.io/web-nfc/security-privacy.html#prearranged-trust-relationship">
section</a> in the Security and Privacy document.
</p>
<p>
The term <dfn>obtain permission</dfn> for a certain operation indicates
that the UA has either obtained <a>expressed permission</a>, or
<a href="#askforgiveness">asks for forgiveness</a>, or ensured a
<a>prearranged trust relationship</a> exists.
</p>
</section>
<section> <h3>NFC specific</h3>
<p>
<b>NFC</b> stands for Near Field Communications, short-range wireless
technology operating at 13.56 MHz which enables communication between
devices at a distance less than 10 cm. The NFC communications protocols and
data exchange formats, and are based on existing radio-frequency
identification (RFID) standards, including ISO/IEC 14443 and FeliCa.
The NFC standards include ISO/IEC 18092[5] and those defined by the NFC
Forum. See https://www.nfc-forum.org/specs/spec_list/ for a complete
listing.
</p>
<p>
An <dfn>NFC adapter</dfn> is the software entity in the underlying
platform which provides access to NFC functionality implemented in a
given hardware element (NFC chip). A device may have multiple NFC
adapters, for instance a built-in one, and one attached via USB.
</p>
<p>
An <dfn>NFC tag</dfn> is a passive NFC device.
The <a>NFC tag</a> is powered by magnetic induction when an active NFC
device is in proximity range. An <a>NFC tag</a> contains a single
<a>NDEF message</a>.
<p class="note">
The way of reading the message may happen through proprietary
technologies, which require the reader and the tag to be of the same
manufacturer. Implementations are expected to encapsulate this.
</p>
</p>
<p>
An <dfn>NFC peer</dfn> is an active, powered device, which can interact
with other devices in order to exchange data using NFC.
</p>
<p>
An <dfn>NFC device</dfn> is either an <a>NFC peer</a>, or an <a>NFC tag</a>.
</p>
<p>
An <dfn>NDEF message</dfn> encapsulates one or more application-defined
<a>NDEF record</a>s. <dfn>NDEF</dfn> is an abbreviation for NFC Forum
Data Exchange Format, a lightweight binary message format. NDEF messages
can be stored on an <a>NFC tag</a> or exchanged between NFC-enabled devices.
</p>
<p>
The term <dfn>NFC content</dfn> is a synonym for <a>NDEF message</a>,
which can originate either from an <a>NFC tag</a> or an <a>NFC peer</a>.
</p>
<p>
An <dfn>NDEF record</dfn> is a part of an <a>NDEF message</a> that has a
single associated type information to its payload. It contains a
Type Name Format (TNF) field, the payload size, the payload type, an
optional identifier which is a URL, and a payload of maximum size of
2^32-1 bytes.
The NFC Forum has standardized a small set of useful data types for
use in <a>NDEF record</a>s, for instance text, URL, and binary data such as
media. In addition, there are record types designed for more complex
interactions, such as Smart Poster, and handover records.
</p>
<p>
The <dfn>TNF</dfn> (Type Name Format) field of the <a>NDEF record</a> can
take binary values denoting the following <a>NDEF record</a> payload
types:
<table class="simple">
<tr>
<th><strong>TNF value</strong></th>
<th><strong>NDEF record type</strong></th>
</tr>
<tr>
<td>0</td>
<td><dfn>Empty</dfn></td>
</tr>
<tr>
<td>1</td>
<td>NFC Forum <dfn>Well-Known Type</dfn>
</td>
</tr>
<tr>
<td>2</td>
<td><dfn>Media Type</dfn></td>
</tr>
<tr>
<td>3</td>
<td><dfn>Absolute URI</dfn></td>
</tr>
<tr>
<td>4</td>
<td>NFC Forum <dfn>External Type</dfn></td>
</tr>
<tr>
<td>5</td>
<td><dfn>Unknown</dfn></td>
</tr>
<tr>
<td>6</td>
<td><dfn>Unchanged</dfn></td>
</tr>
<tr>
<td>7</td>
<td><dfn>Reserved</dfn></td>
</tr>
</table>
<br>
NFC Forum <a>Well-Known Type</a> includes record types <i>text</i>,
<i>URI</i>, <i>Smart Poster</i> (containing an URL or other
data, and possible actions).
</p>
<p>
An <strong><a>NFC watch</a></strong> is a mechanism used to watch for
available <a>Web NFC message</a>s fulfilling certain criteria.
It is defined in more detail in <a href="#dfn-nfc-watch">The watch()
method</a> section.
</p>
<p>
A <dfn>Web NFC record</dfn> is an <a>NDEF record</a> of External Type,
specific to Web NFC. It indicates that the containing <a>NDEF message</a>
is targeted for <a>browsing context</a>s using this API
and contains information useful for handling the <a>NDEF message</a> with
the algorithms defined in this specification.
The format of a <a>Web NFC record</a> is as follows:
<ul>
<li>
Uses NFC Forum External Type record (<a>TNF</a>=4) with the External
Type field set to <code>urn:nfc:ext:w3.org:webnfc</code>.
</li>
<li>
The payload contains the <a>Web NFC Id</a> of the
<a>Web NFC message</a>.
</li>
</ul>
</p>
<p>
The <dfn id="web-nfc-id">Web NFC Id</dfn> is a <a>URL</a> according to
[[RFC3986]], specifically an <a>ASCII serialized origin</a> with
<code>"https"</code> scheme, and optionally followed by a <a>URL path</a>.
This allows matching <a>Web NFC content</a> with <a>URL pattern</a>s
specified by <a>NFC watch</a>es.
</p>
<p>
A <dfn>Web NFC message</dfn> consists of a set of the <a>NDEF record</a>s
and a single <a>Web NFC record</a>.
</p>
<p class="note">
The position of the <a>Web NFC record</a> within the <a>Web NFC message</a>
is implementation specific, this specification only mandates its existence
for a <a>Web NFC message</a>. It is not mandatory to a <a>NDEF message</a>.
</p>
<p>
The term <dfn>Web NFC content</dfn> denotes all <a>Web NFC message</a>s
contained within an <a>NDEF message</a>, identified by the <a>Web NFC Id</a>
within the <a>NDEF message</a>. This version of the specification
supports one <a>Web NFC message</a> per <a>NDEF message</a>.
</p>
<p class="note">
As part of the <a>NDEF record</a>, an <dfn>NDEF Id</dfn> field may be
present for application specific usages. According to the
[[!NFC-STANDARDS]] it contains a URL with the maximum length of 256 octets.
This URL is used for identifying the payload in an application specific
way. Although the <a>NDEF Id</a> could be used for containing e.g. an
<a>ASCII serialized origin</a> associated with the <a>NDEF record</a>,
<strong>it is not used in this version of the specification</strong> for
record-level identification, since the message-level identification is
handled by the <a>Web NFC Id</a>. Also, the content of the <a>NDEF Id</a>
is also contained in the <a>Web NFC Id</a>, and since <a>NFC tag</a>s are
rather small storage units, this duplication is avoided in this version.
When multiple <a>Web NFC message</a>s eventually will be supported within a
single <a>NDEF message</a>, it would likely use the <a>NDEF Id</a> to store
the same identifier for each <a>NDEF record</a> which is part of a given
<a>Web NFC message</a>, which identifier will likely be an
<a>ASCII serialized origin</a> associated with the <a>Web NFC content</a>.
</p>
<p>
The term <dfn>trusted integrity NFC content</dfn> refers to an
<a>NDEF message</a>, or an <a>NDEF record</a>, which can be trusted for
data integrity, i.e. the content is not changed by third parties between
writing and reading.
</p>
<p>
An <dfn>NFC handover</dfn> defines NFC Forum Well Known Types and the
corresponding message structure that allows negotiation and activation of
an alternative communication carrier, such as Bluetooth or WiFi.
The negotiated communication carrier would then be used (separately) to
perform certain activities between the two devices, such as sending photos
to the other device, printing to a Bluetooth printer or streaming video to
a television set.
</p>
</section>
</section> <!-- Terminology -->
<!-- - - - - - - - - - - - - - - Introduction - - - - - - - - - - - - - - -->
<section class="informative"> <h2>Introduction</h2>
<p>
In general, there are three groups of user scenarios for NFC:
<ul>
<li>
Hold a device in close proximity of a passively powered tag, such as
a plastic card or sticker, in order to read and/or write data.
</li>
<li>
Hold two active devices, e.g. phones or tablets, in close proximity
in order to push a <a>Web NFC message</a> from one device to the other.
</li>
<li>
Hold two active devices, e.g. phones or tablets, in close proximity
in order to initiate a connection using another wireless carrier such
as Bluetooth or WiFi.
</li>
<li>Card emulation
<ol>
<li>
With a secure element: for payments by holding your phone close to a
point-of-sales terminal, instead of swiping a payment card.
</li>
<li>With host card emulation: for allowing use-cases like using a phone
acting as a hotel room keycard.
</li>
</ol>
</li>
</ul>
</p>
<p>
NFC works using magnetic induction, meaning that the reader will emit a
small electric charge which then creates a magnetic field. This field powers
the passive device which turns it into electrical impulses to communicate
data. Thus, when the devices are within range, a read is always performed
(see NFC Analog Specification and NFC Digital Protocol, NFC Forum, 2006).
The peer-to-peer connection works in a similar way, as the device
periodically switches into a so-called initiator mode in order to scan for
targets, then later to fall back into target mode. If a target is found, the
data is read the same way as for tags.
</p>
<p>
As NFC is based on existing RFID standards, many NFC chipsets support
reading RFIDs tags, but many of these are only supported by single
vendors and not part of the NFC standards. Though certain devices support
reading and writing to these, it is not a goal of this document to
support proprietary tags or support interoperability with legacy systems.
</p>
<p>
The NFC Forum has mandated the support of four different tag types to be
operable with NFC devices. The same is required on operating systems such as
Android.
<ol>
<li>
<b>NFC Forum Type 1</b>: This tag is based on the ISO/IEC 14443-3A
(also known as NFC-A, as defined in ISO/IEC 14443-3:2011, Part 3:
Initialization and anticollision). The tags are rewritable and can be
configured to become read-only. Memory size can be between 96 bytes and
2 Kbytes. Communication speed is 106 kbit/sec.
</li>
<li><b>NFC Forum Type 2</b>: This tag is also based on the
ISO/IEC 14443-3A (NFC-A). The tags are rewritable and can be configured
to become read-only. Memory size can be between 48 bytes and 2 Kbytes.
Communication speed is 106 kbit/sec. In contrast to Type 1, Type 2 has
anti-collision protection for dealing with multiple tags within the NFC
field.
</li>
<li><b>NFC Forum Type 3</b>: This tag is based on the Japanese Industrial
Standard (JIS) X 6319-4, commonly known as FeliCa. The tags are
preconfigured to be either rewritable or read-only. Memory availability
is variable, theoretical memory limit is 1MByte per service.
Communication speed is 106 kbit/sec. Like Type 2, it supports
anti-collision protection.
</li>
<li><b>NFC Forum Type 4</b> (November 2010): This tag is based on the
ISO/IEC 14443 like Type 1 and 2, but it support either NFC-A or NFC-B
for communication. On top of that the tag may support the Data Exchange
Protocol (aka ISO-DEP) defined in ISO/IEC 14443 (ISO/IEC 14443-4:2008
Part 4: Transmission protocol). Like Type 3, the tags are preconfigured
to be either rewritable or read-only. Variable memory, up to 32 KB per
service. Supports three different communication speeds 106 or 212 or
424 Kbits/s.
</li>
</ol>
</p>
<p>
In addition to data types standardized for <a>NDEF record</a>s by the NFC
Forum, many commercial products such as bus cards, door openers etc use
different card specific data and protocol extensions which require specific
NFC chips (same vendor of card and reader) in order to function.
</p>
<p>
Card emulation mode capabilities also depend on the NFC chip in the device.
For payments, a Secure Element is often needed.
</p>
<p class="note">
This document does not aim supporting all possible use cases of NFC
technology, but only a few use cases which are considered relevant to be
used by web pages in browsers, using the browser security model.
</p>
</section> <!-- Introduction -->
<!-- - - - - - - - - - - - - - Usage Examples - - - - - - - - - - - - - - -->
<section class="informative"> <h2>Examples</h2>
<p>
This section shows how developers can make use of the various features of
this specification.
</p>
<pre title="Read and update data stored on tag" class="example highlight">
navigator.nfc.requestAdapter().then((adapter) => {
adapter.watch({}, (message, url) => {
console.log("NDEF message received from URL " + url);
if (message[0].kind == 'empty') {
adapter.pushMessage([
{
kind: "text",
type: "",
data: "Initializing tag"
}
]);
}
processMessage(message);
});
});
function processMessage(message) {
message.forEach((record) => {
if (record.kind == "string") {
console.log(“Data is string: “ + data);
} else if (record.kind == "json") {
processJSON(record.data);
} else if (record.kind == "url") {
console.log("Data is URL: " + record.data;
} else if (record.kind == "opaque") {
processBinary(data);
});
};
function processBinary(data) {
console.log("Known (string) binary data: ");
console.log(String.fromCharCode.apply(null, new Uint16Array(data)));
};
function processJSON(data) {
var obj = JSON.parse(data);
console.log("JSON data: " + obj.myProperty.toString());
};
</pre>
<pre title="Sending data to a peer device" class="example highlight">
navigator.nfc.requestAdapter().then((adapter) => {
adapter.pushMessage([
{
kind: "text",
type: "",
data: "Data meant for peers"
}
]).then(() => {
console.log("Message sent.")
}).catch(() => {
console.log("Send failed :-( try again.")
});
});
</pre>
<pre title="Save and restore game progress with another device"
class="example highlight">
navigator.nfc.requestAdapter().then((adapter) => {
console.log("Awaiting game state");
adapter.watch({ url: "*://mydomain/mygame/*" }, (message, url) => {
console.log("Game state received from: " + url;
console.log("Stored state: " + message.data);
// Now do some calculations and then update the state.
// ...
adapter.pushMessage([ data: { level: 3, points: 4500, lives: 3 } ])
.then(() => { console.log("We have stored your current game state.") })
.catch(() => { console.log("Failed updating game state, try again.") });
};
});
</pre>
</section> <!-- Usage examples -->
<section class="informative"> <h3>Use Cases</h3>
<p>
A few Web NFC user scenarios are described in the
<a href="https://w3c.github.io/web-nfc/use-cases.html">Use Cases</a>
document. These user scenarios can be grouped by criteria based on
security, privacy and feature categories, resulting in generic flows as
follows.
</p>
<section> <h3>Reading <a>NFC tag</a>s</h3>
<ol>
<li>
Reading <a>NFC tag</a>s containing a <a>Web NFC message</a>, when a
web page using the Web NFC API is open and in focus.
For instance, a web page instructs the user to tap an NFC tag, and
then receives information from the tag.
</li>
<li>
Reading <a>NFC tag</a>s containing other than <a>Web NFC message</a>,
when a web page using the Web NFC API is open and in focus.
</li>
<li>
Reading <a>NFC tag</a>s when no web site using the Web NFC API is
open or in focus.
This use case is not supported in this version of the specification,
and is has low priority for future versions as well.
</li>
</ol>
</section>
<section> <h3>Writing to <a>NFC tag</a>s</h3>
<p>
The user opens a web page which can write an <a>NFC tag</a>. The write
operations may be one of the following:
<ol>
<li>
Writing to an empty <a>NFC tag</a>.
</li>
<li>
Writing to <a>NFC tag</a>s which already contains a
<a>Web NFC message</a> with a different <a>Web NFC Id</a>
(i.e. overwriting a web-specific tag).
</li>
<li>
Writing to <a>NFC tag</a>s which already contains a
<a>Web NFC message</a> with the same <a>Web NFC Id</a>
(i.e. updating own tag).
</li>
<li>
Writing to other, writable <a>NFC tag</a>s (i.e. overwriting a
generic tag).
</li>
</ol>
</p>
<p class-"note">
Note that an NFC write operation to an <a>NFC tag</a> always involves
also a read operation.
</p>
</section>
<section> <h3>Sending data to <a>NFC peer</a> devices</h3>
<p>
In general, sending data to another Web NFC capable device requires that
on the initiating device the user would first have to navigate to a web
site. The user would then touch the device against another Web NFC
equipped device, and data transfer would occur. On the receiving device
the UA will dispatch the content to an application registered
and eligible to handle the content, and if that application is a browser
which has a web page open and in focus that uses the Web NFC API and has
set up a <a>NFC watch</a> to listen to <a>Web NFC content</a>, then the
content is delivered to the web page through the parameters of an
<code>NFCMessageCallback</code>.
</p>
</section>
<section> <h3>Handover to another wireless connection type</h3>
<p>
NFC supports handover protocols to Bluetooth or WiFi connectivity for
the purpose of larger volume data transfer. The user touches another
NFC capable device, and as a result configuration data is sent for a
new Bluetooth or WiFi connection, which is then established between the
devices.
This use case is not supported in this version of the specification.
</p>
</section>
<section> <h3>Payment scenarios</h3>
<p>
The user buys goods in a store, and payments options include NFC.
In general, touching the device to the point of sales terminal receiver
area will result in a transaction between the secure element from the
device and the point of sales terminal. With the Web NFC API, if the
user navigates to a web site before paying, there may be interaction
with that site regarding the payment, e.g. the user could get points and
discounts, or get delivered application or service specific data (e.g.
tickets, keys, etc) to the device.
This use case is not supported in this version of the specification.
</p>
</section>
</section> <!-- Use Cases -->
<section class="informative"> <h3>Features</h3>
<p>High level features for the Web NFC specification include the following:
<ol>
<li>
Support devices with single or multiple NFC adapters.
If there are multiple adapters present when requesting an NFC adapter
then the UA MAY display a dialog for selecting one of them,
or MAY otherwise choose a default adapter based on user settings or
internal policy.
</li>
<li>
Support communication with active (powered devices such as readers,
phones) and passive (smart cards, tags, etc) devices.
</li>
<li>
Allow users to act on (e.g. read, write or transceive) discovered
NFC devices (passive and active) as well as access the payload
which were read in the process as <a>Web NFC message</a>s.
</li>
<li>
Allow users to write a payload via NDEF records to compatible
devices, such as writeable tags, when they come in range, as
<a>Web NFC message</a>s.
</li>
<li>
[future] Allow manual connection for various technologies such as
NFC-A and NFC-F depending on the secondary device.
</li>
<li>
[future] Allow <a>NFC handover</a> to Bluetooth or WiFi.
</li>
<li>
[future] Allow card emulation with secure element or host card
emulation.
</li>
</ol>
</p>
<p>
NFC is usually deeply integrated into device platforms (e.g. Android,
Windows, etc), because end-to-end user experience implications (e.g.
users need to be presented platform specific dialogs for selecting
applications and actions). Also, privacy and security related issues
require platform specific solutions.
</p>
<p>
The various integrated technologies, wide variety of use cases, and
platform integration issues make standardization of NFC for the web a
challenge.
Therefore this document makes a few simplifications in what use cases
and data types are possible to handle by users of this API:
<ul>
<li>
Expose data types already known to web browsers as
<a>IANA media type</a>s.
</li>
<li>Use the web security model.</li>
<li>
Implementations encapsulate <a>NDEF record</a> handling and the API
exposes only data and control events.
</li>
</ul>
</p>
</section> <!-- Features -->
</section> <!-- Introduction -->
<!-- - - - - - - - - - - - - Security and Privacy - - - - - - - - - - - - - -->
<section> <h2 id="security">Security and Privacy</h2>
<p>
The trust model, attacker model, threat model and possible mitigation
proposals for the Web NFC API are presented in the
<a href="http://w3c.github.io/web-nfc/security-privacy.html">
Security and Privacy</a> document. This section presents the chosen
security and privacy model through normative requirements to
implementations.
</p>
<section> <h3>Chain of trust</h3>
<p>
Web pages using the Web NFC API are not trusted.
This means that the user needs to be aware of exactly what a web page is
intending to do with NFC at any given moment. Implementations need to
make sure that when the user authorizes a method of this API, then only that
action is run, without side effects, and exactly in the context and the
number of times the user allows the execution of NFC related operations,
according to the algorithmic steps detailed in this specification.
</p>
<p>
The integrity of <a>NFC content</a> SHOULD NOT be trusted when
used for implementing security policies, for instance the authenticity of
<a>origin</a>s saved in the <a>NDEF Id</a> field, unless a
<a>prearranged trust relationship</a> (such as encryption and other means)
exists.
</p>
</section>
<section> <h3>Threats</h3>
<p>
The main threats are summarized in the
<a href="http://w3c.github.io/web-nfc/security-privacy.html#threats-and-possible-solutions">Security and Privacy</a> document.
</p>
<p>
In this specification the following threats are handled with the highest
priority:
<ul>
<li>
User data privacy: involuntary sharing of user data (such as location,
contacts, personal data, etc) from an NFC-capable device such as a
phone, tablet, or PC.
</li>
<li>
Protecting existing <a>NFC tag</a>s from being overwritten by malicious
web pages.
</li>
</ul>
</p>
</section>
<section> <h3>Permissions and user prompts</h3>
<p>
This specification attempts to help minimizing the user prompts needed to
use the Web NFC API and tries to involve implicit policies which can
address the
<a href="http://w3c.github.io/web-nfc/security-privacy.html#threats-and-possible-solutions">
threats</a>.
However, this specification does not describe, nor does it
mandate specific user prompting policies. The term <a>obtain permission</a>
is used for acquiring trust for a given operation.
</p>
<p class="note">
The <a href="http://www.w3.org/TR/permissions/">Permissions API</a> is
suggested to be used by UAs for implementing NFC related
[[permissions]] in order to minimize the need for user prompting.
The suggested
<a href="https://w3c.github.io/permissions/#idl-def-PermissionName">
permission name</a> is
<code><a href="https://github.com/w3c/permissions/issues/47">"nfc"</a></code>.
This allows saving user permissions for a given <a>origin</a> in a
persistent database until revocation.
</p>
<p>
All <a>expressed permission</a>s that are preserved beyond the current
browsing session MUST be revocable.
</p>
</section>
<section class="informative"> <h3>Security policies</h3>
<p>
This section summarizes the security policies which are specified as
normative requirements in the respective algorithms of this
specification:
</p>
<ul>
<li>
Only <a>script execution environment</a>s of <code>
<a href="https://html.spec.whatwg.org/#document">Document</a></code>s
with a <a>browsing context</a>, and an <a>incumbent settings object</a>
which is a <a>secure context</a> are allowed to access
<a>NFC content</a>.
Browsers may ignore this rule for development purposes only.
</li>
<li>
In order to use NFC, the <code>Window</code> object associated with the
<code><a>Document</a></code> contained by the
<a href="http://www.w3.org/TR/html5/browsers.html#top-level-browsing-context">
top level browsing context</a> using
the Web NFC API must be
<a href="http://www.w3.org/TR/page-visibility/#now-visible-algorithm">
visible</a> and in
<a href="https://html.spec.whatwg.org/#focus">focus</a>.
This also means that UAs should block access to the NFC radio if
the display is off or the device is locked.
For backgrounded web pages, receiving and sending <a>NFC content</a>
must be <a id="#nfc-suspended">suspended</a>.
</li>
<li>
When sending (i.e. writing or pushing) <a>Web NFC content</a>, the
<a>ASCII serialized origin</a> of the <a>browsing context</a> requesting
the operation may be recorded in each sent <a>NDEF record</a>'s
<a>NDEF Id</a> field.
For details see the <a>Writing or pushing content</a> section.
</li>
<li>
When sending (i.e. writing or pushing) <a>Web NFC content</a>, the
<a>URL path</a> of the <a>browsing context</a> requesting
the operation must be recorded in each sent <a>NDEF message</a>'s
<a>Web NFC record</a> field.
For details see the <a>Writing or pushing content</a> section.
</li>
<li>
When requesting an NFC adapter by the <code>requestAdapter</code>
method, or when setting up listeners for reading, or when sending
<a>NFC content</a>, the UA may warn the user that
physical location may be inferred from the act of using NFC by the
given <a>origin</a>.
</li>
<li>
Writing <a>Web NFC content</a> to an <a>NFC tag</a> does not need to
<a>obtain permission</a>, if the <a>NFC tag</a> contains
<a>trusted integrity NFC content</a> and the value of the <a>NDEF Id</a>
field is equal to the <a>ASCII serialized origin</a> of the
<a>incumbent settings object</a>.
Otherwise the UA must <a>obtain permission</a> for
sending <a>NFC content</a> which overwrites existing information.
See also the <a>Writing or pushing content</a> section.
</li>
<li>
Sending <a>NFC content</a> to an <a>NFC peer</a> does not need to
<a>obtain permission</a>, but the previous rules apply.
See the <a>Writing or pushing content</a> section.
</li>
<li>
Making an <a>NFC tag</a> read-only must <a>obtain permission</a>, or
otherwise fail.
</li>
<li>
Setting up listeners for reading <a>NFC content</a> should
<a>obtain permission</a>.
</li>
<li>
The process of reading an <a>NDEF message</a>does not need to
<a>obtain permission</a>.
</li>
<li>
The payload data on NFC content is untrusted, and must not be used