-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.html
More file actions
2045 lines (1964 loc) · 96.6 KB
/
index.html
File metadata and controls
2045 lines (1964 loc) · 96.6 KB
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>
<meta charset='utf-8'>
<script src='https://www.w3.org/Tools/respec/respec-w3c' async class='remove'></script>
<script class='remove'>
var respecConfig = {
group: "wicg",
specStatus: "unofficial",
editors: [
{
name: "Daniel d'Andrada",
company: "Google",
companyURL: "https://google.com/",
mailto: "dandrader@google.com",
w3cid: 139380,
},
{
name: "Luke Klimek",
company: "Google",
companyURL: "https://google.com/",
mailto: "zgroza@chromium.org",
w3cid: 158577,
}
],
github: {
branch: "main",
repoURL: "WICG/web-smart-card",
},
xref: ["dom", "hr-time-3", "html", "infra", "isolated-contexts", "permissions", "permissions-policy", "webidl"],
};
</script>
</head>
<body>
<h1 id="title">Web Smart Card API</h1>
<section id='abstract'>
<p>
The objective of this API is to enable smart card (PC/SC) applications
to move to the Web Platform. It gives them access to the PC/SC
implementation (and card reader drivers) available in the host OS.
There is also a companion <a href="https://github.com/WICG/web-smart-card/blob/main/README.md">explainer</a> document.
</section>
</p>
</section>
<section id='sotd'>
<!-- This section is filled automatically by ReSpec. -->
</section>
<section data-dfn-for="Navigator">
<h2>Extensions to the {{Navigator}} interface</h2>
<pre class="idl">
[Exposed=Window, SecureContext, IsolatedContext]
partial interface Navigator {
[SameObject] readonly attribute SmartCardResourceManager smartCard;
};
</pre>
<h3><dfn>smartCard</dfn> attribute</h3>
<p>When getting, the {{Navigator/smartCard}} attribute always returns the same
instance of the {{SmartCardResourceManager}} object.</p>
</section>
<section data-dfn-for="WorkerNavigator">
<h2>Extensions to the {{WorkerNavigator}} interface</h2>
<pre class="idl">
[Exposed=(DedicatedWorker, SharedWorker), SecureContext, IsolatedContext]
partial interface WorkerNavigator {
[SameObject] readonly attribute SmartCardResourceManager smartCard;
};
</pre>
<h3><dfn>smartCard</dfn> attribute</h3>
<p>When getting, the {{Navigator/smartCard}} attribute always returns the same
instance of the {{SmartCardResourceManager}} object.</p>
</section>
<section data-dfn-for="SmartCardResourceManager">
<h2><dfn>SmartCardResourceManager</dfn> interface</h2>
<pre class="idl">
[Exposed=(DedicatedWorker, SharedWorker, Window), SecureContext, IsolatedContext]
interface SmartCardResourceManager {
Promise<SmartCardContext> establishContext();
};
</pre>
<p>Methods on this interface complete asynchronously, queuing
work on the <dfn>smart card task source</dfn>.</p>
<section>
<h3><dfn>establishContext()</dfn> method</h3>
<p>Requests a PC/SC context from the platform's PC/SC stack.</p>
The {{SmartCardResourceManager/establishContext()}} method steps are:
<ol>
<li>
If [=this=]'s [=relevant global object=]'s [=associated Document=] is
not [=allowed to use=] the [=policy-controlled feature=] named
"[=policy-controlled feature/smart-card=]", [=exception/throw=] a
"{{SecurityError}}" {{DOMException}}.
</li>
<li>Let |promise:Promise| be [=a new promise=].</li>
<li>Run the following steps [=in parallel=]:
<ol>
<li>Let |resourceManager:RESOURCEMANAGER| be a new instance of the
platform's [[PCSC5]] `RESOURCEMANAGER` class.</li>
<li>Invoke the `EstablishContext` method of |resourceManager| with
a "system" `Scope` parameter.</li>
<li>If the returned `RESPONSECODE` is not `SCARD_S_SUCCESS`, perform
the following steps:
<ol>
<li>Destroy |resourceManager|.</li>
<li>[=Queue a global task=] on the [=relevant global object=] of
[=this=] using the [=smart card task source=] to [=reject=]
|promise| with a {{SmartCardError/corresponding}}
[=exception=].</li>
</ol>
</li>
<li>Otherwise, perform the following steps:
<ol>
<li>Let |context:SmartCardContext| be a [=new=]
{{SmartCardContext}} whose
{{SmartCardContext/[[resourceManager]]}} internal slot is set
to |resourceManager|.</li>
<li>[=Queue a global task=] on the [=relevant global object=]
of [=this=] using the [=smart card task source=] to
[=resolve=] |promise| with |context|.</li>
</ol>
</li>
</ol>
</li>
<li>Return |promise|.</li>
</ol>
</section>
</section>
<section data-dfn-for="SmartCardContext">
<h2><dfn>SmartCardContext</dfn> interface</h2>
<p>A context for communicating with the PC/SC resource manager.</p>
<pre class="idl">
[Exposed=(DedicatedWorker, SharedWorker, Window), SecureContext, IsolatedContext]
interface SmartCardContext {
Promise<sequence<DOMString>> listReaders();
Promise<sequence<SmartCardReaderStateOut>> getStatusChange(
sequence<SmartCardReaderStateIn> readerStates,
optional SmartCardGetStatusChangeOptions options = {});
Promise<SmartCardConnectResult> connect(
DOMString readerName,
SmartCardAccessMode accessMode,
optional SmartCardConnectOptions options = {});
};
</pre>
<p>Instances of {{SmartCardContext}} are created with the internal slots
described in the following table:</p>
<table class="simple" data-dfn-for="SmartCardContext">
<tr>
<th>Internal slot
<th>Initial value
<th>Description (non-normative)
</tr>
<tr>
<td><dfn>[[\resourceManager]]</dfn></td>
<td>`null`</td>
<td>The platform's [[PCSC5]] `RESOURCEMANAGER` to be used.</td>
</tr>
<tr>
<td><dfn>[[\operationInProgress]]</dfn></td>
<td>`false`</td>
<td>Whether there is an ongoing PC/SC operation in this context.</td>
</tr>
<tr>
<td><dfn>[[\activeReaderTransactions]]</dfn></td>
<td>An empty <a data-cite="infra#map">map</a></td>
<td>A <a data-cite="infra#map">map</a> of reader names to the {{SmartCardConnection}} that
currently holds an active transaction on that reader in this
context, if any.</td>
</tr>
<tr>
<td><dfn>[[\connections]]</dfn></td>
<td>An empty [=ordered set=]</td>
<td>The existing {{SmartCardConnection}}s created by this context.</td>
</tr>
<tr>
<td><dfn>[[\tracker]]</dfn></td>
<td>`null`</td>
<td>A [[PCSC5]] `SCARDTRACK` instance.</td>
</tr>
<tr>
<td><dfn>[[\signal]]</dfn></td>
<td>`null`</td>
<td>The {{AbortSignal}} of the outstanding
{{SmartCardContext/getStatusChange()}} call, if any.</td>
</tr>
</table>
<aside class="note" title="Lack of reader groups support">
<p>This API does not include an equivalent for the "reader groups"
concept found in [[PCSC5]]. The primary reason for this omission is
that PC/SC Lite does not support it—and thus, it's unavailable
on most platforms.</p>
</aside>
<section>
<h3><dfn>listReaders()</dfn> method</h3>
<p>The {{SmartCardContext/listReaders()}} method steps
are:</p>
<ol>
<li>Let |promise:Promise| be [=a new promise=].</li>
<li>If [=this=].{{SmartCardContext/[[operationInProgress]]}} is
`true`, [=reject=] |promise| with a "{{InvalidStateError}}"
{{DOMException}} and return |promise|.</li>
<li>Set [=this=].{{SmartCardContext/[[operationInProgress]]}} to
`true`.</li>
<li>Run the following steps [=in parallel=]:
<ol>
<li>Let |resourceQuery:RESOURCEQUERY| be a new instance of the
platform's [[PCSC5]] `RESOURCEQUERY` class, with
[=this=].{{SmartCardContext/[[resourceManager]]}} as its
constructor input parameter.</li>
<! –– NB: Can't have "[]" in the data type part of a variable declaration. ––>
<li>Let |groups:array of STR| be the platform's [[PCSC5]] `STR[]`
containing the list of group names that is equivalent to "all
readers in the system" in that platform.
<aside class="note">This could be an empty `STR[]` in some
[[PCSC5]] implementations.</aside>
</li>
<li>Let |pcscReaders:array of STR| be an empty `STR[]`.
<li>Invoke the `ListReaders` method of |resourceQuery| with
|groups| as input and |pcscReaders| as output parameters.</li>
<li>Let |responseCode:RESPONSECODE| be the returned
`RESPONSECODE`.</li>
<li>Destroy |resourceQuery|.</li>
<li>[=Queue a global task=] on the [=relevant global object=] of
[=this=] using the [=smart card task source=] which performs the
following steps:
<ol>
<li>[=Clear the operationInProgress=] of [=this=].</li>
<li>If |responseCode| is not `SCARD_S_SUCCESS`:
<ol>
<li>If |responseCode| is `SCARD_E_NO_READERS_AVAILABLE`,
[=resolve=] |promise| with an empty `sequence` of
{{DOMString}}.
<aside class="note">
<p>`SCARD_E_NO_READERS_AVAILABLE` is not part of
[[PCSC5]] but it is still considered in this
specification as existing PC/SC implementations use
it.</p>
</aside>
</li>
<li>Otherwise, [=reject=] |promise| with an
[=exception=] {{SmartCardError/corresponding}} to
|responseCode|.</li>
</ol>
</li>
<li>Otherwise, [=resolve=] |promise| with a `sequence` of
{{DOMString}} equivalent to |pcscReaders|.</li>
</ol>
</li>
</ol>
</li>
<li>Return |promise|.</li>
</ol>
</section>
<section>
<h3><dfn>getStatusChange()</dfn> method</h3>
<p>The {{SmartCardContext/getStatusChange(readerStates, options)}} method steps
are:</p>
<ol>
<li>Let |promise:Promise| be [=a new promise=].</li>
<li>If [=this=].{{SmartCardContext/[[operationInProgress]]}} is
`true`, [=reject=] |promise| with a "{{InvalidStateError}}"
{{DOMException}} and return |promise|.</li>
<li>If
|options:SmartCardGetStatusChangeOptions|["{{SmartCardGetStatusChangeOptions/signal}}"]
[=map/exists=], run the following steps:
<ol>
<li>Let |signal:AbortSignal| be
|options|["{{SmartCardGetStatusChangeOptions/signal}}"].</li>
<li>If |signal| is [=AbortSignal/aborted=], [=reject=] |promise|
with |signal|'s [=AbortSignal/abort reason=] and return
|promise|.</li>
<li>Set [=this=].{{SmartCardContext/[[signal]]}} to |signal|</li>
<li>[=AbortSignal/Add=] the {{SmartCardContext/Cancel the outstanding
GetStatusChange}} algorithm to |signal|.</li>
</ol>
</li>
<li>Let |pcscTimeout:DWORD| be a [[PCSC5]] `DWORD` set to [[PCSC5]]
`INFINITE`.</li>
<li>If
|options|["{{SmartCardGetStatusChangeOptions/timeout}}"]
[=map/exists=], set |pcscTimeout| to
|options|["{{SmartCardGetStatusChangeOptions/timeout}}"].</li>
<li>Let |pcscReaderStates:array of SCARD_READERSTATE| be a [[PCSC5]]
`SCARD_READERSTATE[]` [=SmartCardReaderStateIn/corresponding=] to
|readerStates:sequence<SmartCardReaderStateIn>|.</li>
<li>Set [=this=].{{SmartCardContext/[[operationInProgress]]}} to
`true`.</li>
<li>Set [=this=].{{SmartCardContext/[[tracker]]}} to a new instance of the
platform's [[PCSC5]] `SCARDTRACK` class, with
[=this=].{{SmartCardContext/[[resourceManager]]}} as its
constructor input parameter.</li>
<li>Run the following steps [=in parallel=]:
<ol>
<li>Call
[=this=].{{SmartCardContext/[[tracker]]}}.`GetStatusChange()`
with |pcscReaderStates| and |pcscTimeout| as input parameters.</li>
<li>Let |responseCode:RESPONSECODE| be the returned
[[PCSC5]] `RESPONSECODE`.</li>
<li>[=Queue a global task=] on the [=relevant global object=] of
[=this=] using the [=smart card task source=] which performs the
following steps:
<ol>
<li>Set [=this=].{{SmartCardContext/[[tracker]]}} to `null`.</li>
<li>[=Clear the operationInProgress=] of [=this=].</li>
<li>Let |abortReason| be {{undefined}}.</li>
<li>If [=this=].{{SmartCardContext/[[signal]]}} is not `null`,
run the following steps:
<ol>
<li>If [=this=].{{SmartCardContext/[[signal]]}} is
[=AbortSignal/aborted=] then set |abortReason| to
[=this=].{{SmartCardContext/[[signal]]}}'s
[=AbortSignal/abort reason=].</li>
<li>[=AbortSignal/Remove=] the {{SmartCardContext/cancel the
outstanding GetStatusChange}} algorithm from
[=this=].{{SmartCardContext/[[signal]]}}.</li>
<li>Set [=this=].{{SmartCardContext/[[signal]]}} to
`null`.</li>
</ol>
</li>
<li>If |responseCode| is not `SCARD_S_SUCCESS`, run the
following steps:
<ol>
<li>If |responseCode| is `SCARD_E_CANCELLED` and
|abortReason| is not {{undefined}} then [=reject=]
|promise| with |abortReason|.</li>
<li>Otherwise, [=reject=] |promise| with an [=exception=]
{{SmartCardError/corresponding}} to |responseCode|.</li>
<li>Return.</li>
</ol>
</li>
<li>Let
|readerStatesOut:sequence<SmartCardReaderStateOut>| be
a sequence of {{SmartCardReaderStateOut}}
[=SmartCardReaderStateOut/corresponding=] to
|pcscReaderStates|.</li>
<li>[=Resolve=] |promise| with |readerStatesOut|.</li>
</ol>
</li>
</ol>
</li>
<li>Return |promise|.</li>
</ol>
<section data-dfn-for="SmartCardReaderStateIn">
<h4><dfn>SmartCardReaderStateIn</dfn> dictionary</h4>
<pre class="idl">
dictionary SmartCardReaderStateIn {
required DOMString readerName;
required SmartCardReaderStateFlagsIn currentState;
unsigned long currentCount;
};
</pre>
<dl>
<dt><dfn>readerName</dfn> member</dt>
<dd>Name of the smart card reader.</dd>
<dt><dfn>currentState</dfn> member</dt>
<dd>The current state of that smart card reader as known by the
application.</dd>
<dt><dfn>currentCount</dfn> member</dt>
<dd>The current number of card insertion and removal events in this
reader, as known by the application.</dd>
</dl>
<p>Given a sequence of {{SmartCardReaderStateIn}} named
|readerStates:sequence<SmartCardReaderStateIn>|, a
<dfn data-dfn-for="SmartCardReaderStateIn">corresponding</dfn>
[[PCSC5]] `SCARD_READERSTATE[]` is created with the following
steps:</p>
<ol>
<li>Let |pcscReaderStates:array of SCARD_READERSTATE| be an empty
`SCARD_READERSTATE[]`.</li>
<li>[=list/For each=] |stateIn:SmartCardReaderStateIn| in |readerStates|:
<ol>
<li>Let |pcscState:SCARD_READERSTATE| be a `SCARD_READERSTATE`.</li>
<li>Set |pcscState|.`Reader` to
|stateIn|["{{SmartCardReaderStateIn/readerName}}"].</li>
<li>Set |pcscState|.`CurrentState` to the `DWORD`
[=SmartCardReaderStateFlagsIn/corresponding=]
to |stateIn|["{{SmartCardReaderStateIn/currentState}}"].</li>
<li>If |stateIn|["{{SmartCardReaderStateIn/currentCount}}"]
[=map/exists=], [=SmartCardContext/set the high word=] of
|pcscState|.`CurrentState` to
|stateIn|["{{SmartCardReaderStateIn/currentCount}}"].</li>
<li>Set |pcscState|.`EventState` to zero.</li>
<li>[=list/Append=] |pcscState| to |pcscReaderStates|.</li>
</ol>
</li>
<li>Return |pcscReaderStates|.</li>
</ol>
<section data-dfn-for="SmartCardReaderStateFlagsIn">
<h5><dfn>SmartCardReaderStateFlagsIn</dfn> dictionary</h4>
<pre class="idl">
dictionary SmartCardReaderStateFlagsIn {
boolean unaware = false;
boolean ignore = false;
boolean unavailable = false;
boolean empty = false;
boolean present = false;
boolean exclusive = false;
boolean inuse = false;
boolean mute = false;
boolean unpowered = false;
};
</pre>
<dl>
<dt><dfn>unaware</dfn> member</dt>
<dd>The application is unaware of the current state, and would like
to know.</dd>
<dt><dfn>ignore</dfn> member</dt>
<dd>The application is not interested in this reader, and it should
not be considered during monitoring operations.</dd>
<dt><dfn>unavailable</dfn> member</dt>
<dd>The application believes that this reader is not available for
use.</dd>
<dt><dfn>empty</dfn> member</dt>
<dd>The application believes that there is not a card in the
reader.</dd>
<dt><dfn>present</dfn> member</dt>
<dd>The application believes that there is a card in the
reader.</dd>
<dt><dfn>exclusive</dfn> member</dt>
<dd>The application believes that the card in the reader is
allocated for exclusive use by another application.</dd>
<dt><dfn>inuse</dfn> member</dt>
<dd>The application believes that the card in the reader is in use
by one or more other applications, but may be connected to in
shared mode. </dd>
<dt><dfn>mute</dfn> member</dt>
<dd>The application believes that there is an unresponsive card in
the reader.</dd>
<dt><dfn>unpowered</dfn> member</dt>
<dd>The application believes that the card in the reader has not
been powered up.</dd>
</dl>
<p>The [[PCSC5]] `DWORD`
<dfn data-dfn-for=SmartCardReaderStateFlagsIn>corresponding</dfn>
to a given {{SmartCardReaderStateFlagsIn}} is created with the
following steps:</p>
<ol>
<li>Let |flagsIn:SmartCardReaderStateFlagsIn| be the given
{{SmartCardReaderStateFlagsIn}}.</li>
<li>Let |pcscFlags:DWORD| be a `DWORD` set to zero.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/unaware}}"] is
`true`, [=add a flag|add=] [[PCSC5]] `SCARD_STATE_UNAWARE` to
|pcscFlags|.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/ignore}}"] is
`true`, [=add a flag|add=] [[PCSC5]] `SCARD_STATE_IGNORE` to
|pcscFlags|.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/unavailable}}"]
is `true`, [=add a flag|add=] [[PCSC5]]
`SCARD_STATE_UNAVAILABLE` to |pcscFlags|.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/empty}}"] is
`true`, [=add a flag|add=] [[PCSC5]] `SCARD_STATE_EMPTY` to
|pcscFlags|.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/present}}"] is
`true`, [=add a flag|add=] [[PCSC5]] `SCARD_STATE_PRESENT` to
|pcscFlags|.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/exclusive}}"] is
`true`, [=add a flag|add=] [[PCSC5]] `SCARD_STATE_EXCLUSIVE` to
|pcscFlags|.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/inuse}}"] is
`true`, [=add a flag|add=] [[PCSC5]] `SCARD_STATE_INUSE` to
|pcscFlags|.</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/mute}}"] is
`true`, [=add a flag|add=] `SCARD_STATE_MUTE` to
|pcscFlags|.
</li>
<li>If |flagsIn|["{{SmartCardReaderStateFlagsIn/unpowered}}"] is
`true`, [=add a flag|add=] `SCARD_STATE_UNPOWERED` to
|pcscFlags|.</li>
<li>Return |pcscFlags|.</li>
</ol>
<aside class="note">
<p>`SCARD_STATE_MUTE` and `SCARD_STATE_UNPOWERED` are not part of
[[PCSC5]] but are still considered in this specification as
existing PC/SC implementations use it.</p>
</aside>
</section>
</section>
<section data-dfn-for="SmartCardReaderStateOut">
<h4><dfn>SmartCardReaderStateOut</dfn> dictionary</h4>
<p>The actual state of a smart card reader.</p>
<pre class="idl">
dictionary SmartCardReaderStateOut {
required DOMString readerName;
required SmartCardReaderStateFlagsOut eventState;
required unsigned long eventCount;
ArrayBuffer answerToReset;
};
</pre>
<dl>
<dt><dfn>readerName</dfn> member</dt>
<dd>Name of the smart card reader.</dd>
<dt><dfn>eventState</dfn> member</dt>
<dd>The actual state of that smart card reader.</dd>
<dt><dfn>eventCount</dfn> member</dt>
<dd>The actual number of card insertion and removal events in this
reader.</dd>
<dt><dfn>answerToReset</dfn> member</dt>
<dd>The inserted card's [[ISO7816-3]] Answer To Reset (ATR), if
applicable.</dd>
</dl>
<p>Given a [[PCSC5]] `SCARD_READERSTATE[]` named
|pcscReaderStates:array of SCARD_READERSTATE|, a <dfn
data-dfn-for="SmartCardReaderStateOut">corresponding</dfn> sequence of
{{SmartCardReaderStateOut}} is created with the following steps:</p>
<ol>
<li>Let |readerStatesOut:sequence<SmartCardReaderStateOut>| be
an empty sequence of {{SmartCardReaderStateOut}}.</li>
<li>[=list/For each=] |pcscState:SCARD_READERSTATE| in
|pcscReaderStates|:
<ol>
<li>Let |stateOut:SmartCardReaderStateOut| be a
{{SmartCardReaderStateOut}}.</li>
<li>Set |stateOut|["{{SmartCardReaderStateOut/readerName}}"] to
|pcscState|.`Reader`.</li>
<li>Set |stateOut|["{{SmartCardReaderStateOut/eventState}}"] to
the {{SmartCardReaderStateFlagsOut}} dictionary
[=SmartCardReaderStateFlagsOut/corresponding=]
to |pcscState|.`EventState`.</li>
<li>Set |stateOut|["{{SmartCardReaderStateOut/eventCount}}"] to
the [=SmartCardContext/high word=] of |pcscState|.`EventState`.
<aside class="note" title="Number of card insertion and removal
events">
<p>Having the number of card insertion and removal events
stored in the upper 2 bytes of the `EventState` and
`CurrentState` `DWORD`s is not part of [[PCSC5]] but it is
still considered in this specification as several existing
PC/SC implementations use it.</p>
<p>In PC/SC implementations where this information is not
available, the upper two bytes of `EventState` will always
be zero and so the resulting
"{{SmartCardReaderStateOut/eventCount}}" will be zero.</p>
<p>The algorithms in this specification assume that PC/SC
implementations will define all [[PCSC5]] `SCARD_STATE_*`
flags to be `DWORD` values no higher than `0xFFFF`.</p>
</aside>
</li>
<li>If the platform's `SCARD_READERSTATE` structure has a member
containing the card's [[ISO7816-3]] Answer To Reset, set
|stateOut|["{{SmartCardReaderStateOut/answerToReset}}"] to
that value.</li>
<li>[=list/Append=] |stateOut| to |readerStatesOut|.</li>
</ol>
</li>
<li>Return |readerStatesOut|.</li>
</ol>
<section data-dfn-for="SmartCardReaderStateFlagsOut">
<h5><dfn>SmartCardReaderStateFlagsOut</dfn> dictionary</h4>
<pre class="idl">
dictionary SmartCardReaderStateFlagsOut {
boolean ignore = false;
boolean changed = false;
boolean unavailable = false;
boolean unknown = false;
boolean empty = false;
boolean present = false;
boolean exclusive = false;
boolean inuse = false;
boolean mute = false;
boolean unpowered = false;
};
</pre>
<dl>
<dt><dfn>ignore</dfn> member</dt>
<dd>The application requested that this reader be ignored.</dd>
<dt><dfn>changed</dfn> member</dt>
<dd>There is a difference between the state input by the calling
application, and the actual state.</dd>
<dt><dfn>unavailable</dfn> member</dt>
<dd>This reader is not available for use.</dd>
<dt><dfn>unknown</dfn> member</dt>
<dd>The reader name given by the application is not known.</dd>
<dt><dfn>empty</dfn> member</dt>
<dd>There is no card in the reader.</dd>
<dt><dfn>present</dfn> member</dt>
<dd>There is a card in the reader.</dd>
<dt><dfn>exclusive</dfn> member</dt>
<dd>The card in the reader is allocated for exclusive use by
another application.</dd>
<dt><dfn>inuse</dfn> member</dt>
<dd>The card in the reader is in use by one or more other
applications, but may be connected to in shared mode. </dd>
<dt><dfn>mute</dfn> member</dt>
<dd>There is an unresponsive card in the reader.</dd>
<dt><dfn>unpowered</dfn> member</dt>
<dd>The card in the reader has not been powered up.</dd>
</dl>
<p>Given a [[PCSC5]] `DWORD` named |pcscFlags:DWORD|, a <dfn
data-dfn-for="SmartCardReaderStateFlagsOut">corresponding</dfn>
{{SmartCardReaderStateFlagsOut}} dictionary is created with the
following steps:</p>
<ol>
<li>Let |flagsOut:SmartCardReaderStateFlagsOut| be a
{{SmartCardReaderStateFlagsOut}} dictionary with [=dictionary
member/default value|default members=].</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_IGNORE`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/ignore}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_CHANGED`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/changed}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_UNAVAILABLE`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/unavailable}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_UNKNOWN`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/unknown}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_EMPTY`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/empty}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_PRESENT`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/present}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_EXCLUSIVE`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/exclusive}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] [[PCSC5]]
`SCARD_STATE_INUSE`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/inuse}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] `SCARD_STATE_MUTE`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/mute}}"] to
`true`.</li>
<li>If |pcscFlags| [=has a flag|has=] `SCARD_STATE_UNPOWERED`, set
|flagsOut|["{{SmartCardReaderStateFlagsOut/unpowered}}"] to
`true`.</li>
<li>Return |flagsOut|.</li>
</ol>
<aside class="note">
<p>`SCARD_STATE_MUTE` and `SCARD_STATE_UNPOWERED` are not part of
[[PCSC5]] but are still considered in this specification as
existing PC/SC implementations use it.</p>
</aside>
</section>
</section>
<section data-dfn-for="SmartCardGetStatusChangeOptions">
<h4><dfn>SmartCardGetStatusChangeOptions</dfn> dictionary</h4>
<pre class="idl">
dictionary SmartCardGetStatusChangeOptions {
DOMHighResTimeStamp timeout;
AbortSignal signal;
};
</pre>
<dl>
<dt><dfn>timeout</dfn> member</dt>
<dd>Timeout parameter for the GetStatusChange() [[PCSC5]] method. If
not specified, a timeout value of INFINITE (which is defined system
dependent) will be used.</dd>
<dt><dfn>signal</dfn> member</dt>
<dd>When triggered, the platform's [[PCSC5]] Cancel() method is
called.</dd>
</dl>
</section>
</section>
<section>
<h3><dfn>connect()</dfn> method</h3>
<p>The {{SmartCardContext/connect(readerName, accessMode, options)}}
method steps are:</p>
<ol>
<li>Let |promise:Promise| be [=a new promise=].</li>
<li>If [=this=].{{SmartCardContext/[[operationInProgress]]}} is
`true`, [=reject=] |promise| with a "{{InvalidStateError}}"
{{DOMException}} and return |promise|.</li>
<li>If [=this=].{{SmartCardContext/[[activeReaderTransactions]]}}[|readerName|]
[=map/exists=], [=reject=] |promise| with a "{{InvalidStateError}}"
{{DOMException}} and return |promise|.</li>
<li>Set [=this=].{{SmartCardContext/[[operationInProgress]]}} to
`true`.</li>
<li>Run the following steps [=in parallel=]:
<ol>
<li>Let |accessFlags:DWORD| be a [[PCSC5]] `DWORD`
[=SmartCardAccessMode/corresponding=] to
|accessMode:SmartCardAccessMode|.</li>
<li>Let |protocolFlags:DWORD| be a `DWORD` set to `0`.</li>
<li>If
|options:SmartCardConnectOptions|["{{SmartCardConnectOptions/preferredProtocols}}"]
[=map/exists=], set |protocolFlags| to its
[=SmartCardProtocol/corresponding flags=].</li>
<li>Let |activeProtocol:DWORD| be a `DWORD` set to `0`.</li>
<li>Let |comm:SCARDCOMM| be a new instance of the platform's
[[PCSC5]] `SCARDCOMM` class, with
[=this=].{{SmartCardContext/[[resourceManager]]}} as its
constructor parameter.</li>
<li>Call |comm|.`Connect()` with |readerName|, |accessFlags|
and |protocolFlags| as input and |activeProtocol| as output parameters.</li>
<li>Let |responseCode:RESPONSECODE| be the returned
`RESPONSECODE`.</li>
<li>[=Queue a global task=] on the [=relevant global object=] of
[=this=] using the [=smart card task source=] which performs the
following steps:
<ol>
<li>[=Clear the operationInProgress=] of [=this=].</li>
<li>If |responseCode| is not `SCARD_S_SUCCESS`:
<ol>
<li>Destroy |comm|.</li>
<li>[=Reject=] |promise| with an [=exception=]
{{SmartCardError/corresponding}} to |responseCode| and abort these steps.</li>
</ol>
</li>
<li>Let |result:SmartCardConnectResult| be an empty
{{SmartCardConnectResult}} dictionary.</li>
<li>Let |connection:SmartCardConnection| be a new
{{SmartCardConnection}}.</li>
<li>[=set/Append=] |connection| to
[=this=].{{SmartCardContext/[[connections]]}}.</li>
<li>Set |connection|.{{SmartCardConnection/[[comm]]}} to |comm|.
<li>Set |connection|.{{SmartCardConnection/[[readerName]]}} to
|readerName|.
<li>Set |connection|.{{SmartCardConnection/[[context]]}} to
[=this=].
<li>Set |connection|.{{SmartCardConnection/[[activeProtocol]]}} to
|activeProtocol|.
<li>Set |result|["{{SmartCardConnectResult/connection}}"] to
|connection|.</li>
<li>If |activeProtocol| is a [=SmartCardProtocol/valid
protocol value=], set
|result|["{{SmartCardConnectResult/activeProtocol}}"] to the
corresponding {{SmartCardProtocol}}.</li>
<li>[=Resolve=] |promise| with |result|.</li>
</ol>
</li>
</ol>
</li>
<li>Return |promise|.</li>
</ol>
<section data-dfn-for="SmartCardProtocol">
<h4><dfn>SmartCardProtocol</dfn> enum</h4>
<pre class="idl">
enum SmartCardProtocol {
"raw",
"t0",
"t1"
};
</pre>
<dl>
<dt><dfn>raw</dfn></dt>
<dd>"Raw" mode. May be used to support arbitrary data exchange
protocols for special-purpose requirements. Corresponds to a
[[PCSC5]] `SCARD_PROTOCOL_RAW` `DWORD`.</dd>
<dt><dfn>t0</dfn></dt>
<dd>[[ISO7816-3]] T=0. Asynchronous half duplex character
transmission protocol. Corresponds to a [[PCSC5]]
`SCARD_PROTOCOL_T0` `DWORD`.</dd>
<dt><dfn>t1</dfn></dt>
<dd>[[ISO7816-3]] T=1. Asynchronous half duplex block transmission
protocol. Corresponds to a [[PCSC5]] `SCARD_PROTOCOL_T1`
`DWORD`.</dd>
</dl>
<p>A [[PCSC5]] `DWORD` is a <dfn data-dfn-for="SmartCardProtocol">valid protocol value</dfn> if it is either
[[PCSC5]] `SCARD_PROTOCOL_T0`, [[PCSC5]] `SCARD_PROTOCOL_T1` or
[[PCSC5]] `SCARD_PROTOCOL_RAW`.</p>
<p>Given a sequence of {{SmartCardProtocol}} named
|protocols:sequence<SmartCardProtocol>|, a [[PCSC5]] `DWORD`
with the <dfn data-dfn-for="SmartCardProtocol">corresponding
flags</dfn> is created with the following steps:</p>
<ol>
<li>Let |flags:DWORD| be a `DWORD` set to `0`.</li>
<li>[=list/For each=] |protocol:SmartCardProtocol| in |protocols|,
[=add a flag|add=] the corresponding `DWORD` of |protocol| to |flags|.
</li>
<li>Return |flags|.</li>
</ol>
</section>
<section data-dfn-for="SmartCardConnectResult">
<h4><dfn>SmartCardConnectResult</dfn> dictionary</h4>
<pre class="idl">
dictionary SmartCardConnectResult {
required SmartCardConnection connection;
SmartCardProtocol activeProtocol;
};
</pre>
<dl>
<dt><dfn>connection</dfn> member</dt>
<dd>An interface to the connection created.</dd>
<dt><dfn>activeProtocol</dfn> member</dt>
<dd>The protocol actually in use.</dd>
</dl>
</section>
<section data-dfn-for="SmartCardAccessMode">
<h4><dfn>SmartCardAccessMode</dfn> enum</h5>
<pre class="idl">
enum SmartCardAccessMode {
"shared",
"exclusive",
"direct"
};
</pre>
<dl>
<dt><dfn>shared</dfn></dt>
<dd>Application is willing to share access to card with other
applications.</dd>
<dt><dfn>exclusive</dfn></dt>
<dd>Application requires exclusive access to the card.</dd>
<dt><dfn>direct</dfn></dt>
<dd>Application requires connection to reader whether or not card
is present. Implies exclusive access.</dd>
</dl>
<p>Given a {{SmartCardAccessMode}} enum named
|accessMode:SmartCardAccessMode|, a <dfn
data-dfn-for="SmartCardAccessMode">corresponding</dfn> [[PCSC5]]
`DWORD` is created with the following steps:</p>
<ol>
<li>Let |dword:DWORD| be a `DWORD` set to `0`.
<li>If |accessMode| is "{{SmartCardAccessMode/shared}}", set |dword| to [[PCSC5]]
`SCARD_SHARE_SHARED`.</li>
<li>If |accessMode| is "{{SmartCardAccessMode/exclusive}}", set |dword| to [[PCSC5]]
`SCARD_SHARE_EXCLUSIVE`.</li>
<li>If |accessMode| is "{{SmartCardAccessMode/direct}}", set |dword| to [[PCSC5]]
`SCARD_SHARE_DIRECT`.</li>
<li>Return |dword|.</li>
</ol>
</section>
<section data-dfn-for="SmartCardConnectOptions">
<h4><dfn>SmartCardConnectOptions</dfn> dictionary</h5>
<pre class="idl">
dictionary SmartCardConnectOptions {
sequence<SmartCardProtocol> preferredProtocols;
};
</pre>
<dl>
<dt><dfn>preferredProtocols</dfn></dt>
<dd>Card communication protocols that may be used.</dd>
</dl>
</section>
</section>
<section>
<h3>Auxiliary algorithms and definitions</h4>
<p>To <dfn>clear the operationInProgress</dfn> of a
{{SmartCardContext}} |context:SmartCardContext|, perform the following steps:</p>
<ol>
<li>[=Assert=]: |context|.{{SmartCardContext/[[operationInProgress]]}}
is `true`.</li>
<li>Set |context|.{{SmartCardContext/[[operationInProgress]]}} to
`false`.</li>
<li>[=set/For each=] |connection:SmartCardConnection| of
|context|.{{SmartCardContext/[[connections]]}}:
<ol>
<li>[=SmartCardConnection/End any settled transaction=] of
|connection|.</li>
<li>If |context|.{{SmartCardContext/[[operationInProgress]]}} is
`true`, abort there steps.</li>
</ol>
</li>
</ol>
<aside class="note">
<p>A transaction ends when the {{Promise}} returned by the
{{SmartCardTransactionCallback}} passed to
{{SmartCardConnection/startTransaction()}} settles. At this
point the user agent should call [[PCSC5]] `EndTransaction()` to
effect that on the platform's PC/SC stack. But that won't be
possible if at that moment there's already another PC/SC
operation taking place in the connection's PC/SC context. The
user agent then has to wait until this ongoing PC/SC operation
finishes before ending that settled transaction.</p>
</aside>
<p>The <dfn>cancel the outstanding GetStatusChange</dfn>
algorithm steps are:</p>
<ol>
<li>Call [=this=].{{SmartCardContext/[[tracker]]}}.`Cancel()`.</li>
</ol>
<p>The <dfn>high word</dfn> of a [[PCSC5]] `DWORD` is the result of an
unsigned right shift of 16 bits on that `DWORD`.</p>
<p>To <dfn>set the high word</dfn> of a [[PCSC5]] `DWORD` named
|dword:DWORD| to a given number |n|, perform the following steps.</p>
<ol>
<li>Set |dword| to |dword| bitwise AND `0xFFFF`.</li>
<li>Let |shiftedN| be the result of a left shift of 16 bits on |n|.</li>
<li>Set |dword| to |dword| bitwise OR |shiftedN|.</li>
</ol>
<p>To <dfn>add a flag</dfn> |f:DWORD| to a [[PCSC5]] `DWORD`
|flags:DWORD|, set |flags| to |flags| bitwise OR |f|.</p>
<p>A [[PCSC5]] `DWORD` |flags:DWORD| <dfn>has a flag</dfn> |f:DWORD|
if |flags| bitwise AND |f| is |f|.</p>
</section>
</section>
<section data-dfn-for="SmartCardConnection">
<h2><dfn>SmartCardConnection</dfn> interface</h2>
<pre class="idl">
[Exposed=(DedicatedWorker, SharedWorker, Window), SecureContext, IsolatedContext]
interface SmartCardConnection {
Promise<undefined> disconnect(optional SmartCardDisposition disposition = "leave");
Promise<ArrayBuffer> transmit(BufferSource sendBuffer,
optional SmartCardTransmitOptions options = {});
Promise<undefined> startTransaction(SmartCardTransactionCallback transaction,
optional SmartCardTransactionOptions options = {});
Promise<SmartCardConnectionStatus> status();
Promise<ArrayBuffer> control([EnforceRange] unsigned long controlCode,
BufferSource data);
Promise<ArrayBuffer> getAttribute([EnforceRange] unsigned long tag);
Promise<undefined> setAttribute([EnforceRange] unsigned long tag, BufferSource value);
};
callback SmartCardTransactionCallback = Promise<SmartCardDisposition?> ();
</pre>
<p>Instances of {{SmartCardConnection}} are created with the internal slots
described in the following table:</p>
<table class="simple" data-dfn-for="SmartCardConnection">
<tr>
<th>Internal slot
<th>Initial value
<th>Description (non-normative)
</tr>
<tr>
<td><dfn>[[\comm]]</dfn></td>
<td>`null`</td>
<td>The platform's [[PCSC5]] `SCARDCOMM` to be used.</td>
</tr>
<tr>
<td><dfn>[[\readerName]]</dfn></td>
<td>`null`</td>
<td>The name of the reader this connection is associated with.</td>
</tr>
<tr>
<td><dfn>[[\context]]</dfn></td>
<td>`null`</td>
<td>The {{SmartCardContext}} that created this instance.</td>
</tr>
<tr>
<td><dfn>[[\activeProtocol]]</dfn></td>
<td>0</td>
<td>The active protocol `DWORD`, as returned by the platform's
[[PCSC5]] implementation.</td>
</tr>
<tr>
<td><dfn>[[\transactionState]]</dfn></td>
<td>`null`</td>
<td>Holds the [=transaction state|state=] of an ongoing transaction
started with {{SmartCardConnection/startTransaction()}}, if
any.</td>
</tr>
</table>
<aside class="note" title="Lack of the reconnect method">
<p>[[PCSC5]] mentions also the `Reconnect` method, which has no equivalent here.
This is because its behavior differs between implementations—PC/SC Lite does
not release the transactions held by the process, while Microsoft's WinSCard