-
Notifications
You must be signed in to change notification settings - Fork 19
/
demo.html
250 lines (230 loc) · 10.4 KB
/
demo.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
<!DOCTYPE html>
<!--
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
-->
<html lang="ja">
<head>
<meta charset="utf-8">
<title>WebUSBでFeliCaリーダーにかざしたFeliCaのIDmを表示</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/uikit/3.0.0-beta.30/css/uikit.min.css" />
</head>
<body>
<div class="uk-navbar-container uk-margin">
<div class="uk-container uk-container-expand">
<div class="uk-navbar">
<div class="uk-navbar-left">
<span class="uk-navbar-item uk-logo">WebUSBでFeliCa IDmを読むテスト</span>
</div>
</div>
</div>
</div>
<div class="uk-container">
<div class="uk-margin">
USB接続のFeliCaリーダー経由でFeliCaのIDmを読み、表示します。
<span class="uk-text-danger">注意:チャージ済みだったり、オートチャージが有効なカードでは絶対に実験しないでください。勝手に決済が発生してお金が無くなっても責任はとれません。</span>
</div>
<button id="start" class="uk-button uk-button-large uk-button-default uk-width-1-1 uk-text-capitalize">FeliCaリーダーに接続</button>
<div id="waiting" class="uk-margin" style="display: none;">
<button class="uk-button uk-button-large uk-button-default uk-width-1-1" disabled>
<span uk-spinner="" class="uk-spinner uk-icon">
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 30 30" ratio="1">
<circle fill="none" stroke="#000" cx="15" cy="15" r="14"></circle>
</svg>
</span>
FeliCaリーダーにカードをかざしてください
</button>
</div>
<div id="idm" class="uk-alert uk-alert-success uk-text-center" uk-alert style="display: none;"></div>
</div>
<script>
let startButton = document.getElementById('start');
let idmMessage = document.getElementById('idm');
let waitingMessage = document.getElementById('waiting');
async function sleep(msec) {
return new Promise(resolve => setTimeout(resolve, msec));
}
async function send(device, data) {
let uint8a = new Uint8Array(data);
console.log(">>>>>>>>>>");
console.log(uint8a);
await device.transferOut(2, uint8a);
await sleep(10);
}
async function receive(device, len) {
console.log("<<<<<<<<<<" + len);
let data = await device.transferIn(1, len);
console.log(data);
await sleep(10);
let arr = [];
for (let i = data.data.byteOffset; i < data.data.byteLength; i++) {
arr.push(data.data.getUint8(i));
}
console.log(arr);
return arr;
}
async function session(device) {
// INFO:nfc.clf:searching for reader on path usb:054c:06c3
// DEBUG:nfc.clf.transport:using libusb-1.0.21
// DEBUG:nfc.clf.transport:path matches '^usb(:[0-9a-fA-F]{4})(:[0-9a-fA-F]{4})?$'
// DEBUG:nfc.clf.device:loading rcs380 driver for usb:054c:06c3
// Level 9:nfc.clf.transport:>>> 0000ff00ff00
await send(device, [0x00, 0x00, 0xff, 0x00, 0xff, 0x00]);
// Level 9:nfc.clf.rcs380:SetCommandType 01
// Level 9:nfc.clf.transport:>>> 0000ffffff0300fdd62a01ff00
await send(device, [0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0x00, 0xfd, 0xd6, 0x2a, 0x01, 0xff, 0x00]);
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
await receive(device, 6);
// Level 9:nfc.clf.transport:<<< 0000ffffff0300fdd72b00fe00
await receive(device, 13);
// Level 9:nfc.clf.rcs380:GetFirmwareVersion
// Level 9:nfc.clf.transport:>>> 0000ffffff0200fed6200a00
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
// Level 9:nfc.clf.transport:<<< 0000ffffff0400fcd7211101f600
// DEBUG:nfc.clf.rcs380:firmware version 1.11
// Level 9:nfc.clf.rcs380:GetPDDataVersion
// Level 9:nfc.clf.transport:>>> 0000ffffff0200fed6220800
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
// Level 9:nfc.clf.transport:<<< 0000ffffff0400fcd72300010500
// DEBUG:nfc.clf.rcs380:package data format 1.00
// Level 9:nfc.clf.rcs380:SwitchRF 00
// Level 9:nfc.clf.transport:>>> 0000ffffff0300fdd606002400
await send(device, [0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0x00, 0xfd, 0xd6, 0x06, 0x00, 0x24, 0x00]);
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
await receive(device, 6);
// Level 9:nfc.clf.transport:<<< 0000ffffff0300fdd707002200
await receive(device, 13);
// Level 9:nfc.clf.rcs380:GetFirmwareVersion
// Level 9:nfc.clf.transport:>>> 0000ffffff0200fed6200a00
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
// Level 9:nfc.clf.transport:<<< 0000ffffff0400fcd7211101f600
// DEBUG:nfc.clf.rcs380:firmware version 1.11
// INFO:nfc.clf:using SONY RC-S380/P NFC Port-100 v1.11 at usb:020:014
// Level 9:nfc.clf.rcs380:SwitchRF 00
// Level 9:nfc.clf.transport:>>> 0000ffffff0300fdd606002400
await send(device, [0x00, 0x00, 0xff, 0xff, 0xff, 0x03, 0x00, 0xfd, 0xd6, 0x06, 0x00, 0x24, 0x00]);
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
await receive(device, 6);
// Level 9:nfc.clf.transport:<<< 0000ffffff0300fdd707002200
await receive(device, 13);
// DEBUG:nfc.clf:sense 212F
// DEBUG:nfc.clf.rcs380:polling for NFC-F technology
// Level 9:nfc.clf.rcs380:InSetRF 01010f01
// Level 9:nfc.clf.transport:>>> 0000ffffff0600fad60001010f011800
await send(device, [0x00, 0x00, 0xff, 0xff, 0xff, 0x06, 0x00, 0xfa, 0xd6, 0x00, 0x01, 0x01, 0x0f, 0x01, 0x18, 0x00]);
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
await receive(device, 6);
// Level 9:nfc.clf.transport:<<< 0000ffffff0300fdd701002800
await receive(device, 13);
// Level 9:nfc.clf.rcs380:InSetProtocol 00180101020103000400050006000708080009000a000b000c000e040f001000110012001306
// Level 9:nfc.clf.transport:>>> 0000ffffff2800d8d60200180101020103000400050006000708080009000a000b000c000e040f0010001100120013064b00
await send(device, [0x00, 0x00, 0xff, 0xff, 0xff, 0x28, 0x00, 0xd8, 0xd6, 0x02, 0x00, 0x18, 0x01, 0x01, 0x02, 0x01, 0x03, 0x00, 0x04, 0x00, 0x05, 0x00, 0x06, 0x00, 0x07, 0x08, 0x08, 0x00, 0x09, 0x00, 0x0a, 0x00, 0x0b, 0x00, 0x0c, 0x00, 0x0e, 0x04, 0x0f, 0x00, 0x10, 0x00, 0x11, 0x00, 0x12, 0x00, 0x13, 0x06, 0x4b, 0x00]);
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
await receive(device, 6);
// Level 9:nfc.clf.transport:<<< 0000ffffff0300fdd703002600
await receive(device, 13);
// Level 9:nfc.clf.rcs380:InSetProtocol 0018
// Level 9:nfc.clf.transport:>>> 0000ffffff0400fcd60200181000
await send(device, [0x00, 0x00, 0xff, 0xff, 0xff, 0x04, 0x00, 0xfc, 0xd6, 0x02, 0x00, 0x18, 0x10, 0x00]);
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
await receive(device, 6);
// Level 9:nfc.clf.transport:<<< 0000ffffff0300fdd703002600
await receive(device, 13);
// DEBUG:nfc.clf.rcs380:send SENSF_REQ 00ffff0100
// Level 9:nfc.clf.rcs380:InCommRF 6e000600ffff0100
// Level 9:nfc.clf.transport:>>> 0000ffffff0a00f6d6046e000600ffff0100b300
await send(device, [0x00, 0x00, 0xff, 0xff, 0xff, 0x0a, 0x00, 0xf6, 0xd6, 0x04, 0x6e, 0x00, 0x06, 0x00, 0xff, 0xff, 0x01, 0x00, 0xb3, 0x00]);
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
await receive(device, 6);
// Level 9:nfc.clf.transport:<<< 0000ffffff1b00e5d70500000000081401000000000000000000000000000000000000f700
let idm = (await receive(device, 37)).slice(17, 24);
if (idm.length > 0) {
let idmStr = '';
for (let i = 0; i < idm.length; i++) {
if (idm[i] < 16) {
idmStr += '0';
}
idmStr += idm[i].toString(16);
}
idmMessage.innerText = "カードのIDm: " + idmStr;
idmMessage.style.display = 'block';
waitingMessage.style.display = 'none';
} else {
idmMessage.style.display = 'none';
waitingMessage.style.display = 'block';
}
// DEBUG:nfc.clf.rcs380:rcvd SENSF_RES 01000000000000000000000000000000000000
// DEBUG:nfc.clf:found 212F sensf_res=01000000000000000000000000000000000000
// 212F sensf_res=01000000000000000000000000000000000000
// DEBUG:nfc.tag:trying to activate 212F sensf_res=01000000000000000000000000000000000000
// DEBUG:nfc.tag:trying type 3 tag activation for 212F
// Type3Tag 'FeliCa Standard' ID=000000000000000 PMM=0000000000000000 SYS=0000
// 0000000000000000
// Level 9:nfc.clf.rcs380:SwitchRF 00
// Level 9:nfc.clf.transport:>>> 0000ffffff0300fdd606002400
// Level 9:nfc.clf.transport:<<< 0000ff00ff00
// Level 9:nfc.clf.transport:<<< 0000ffffff0300fdd707002200
// Level 9:nfc.clf.transport:>>> 0000ff00ff00
}
startButton.addEventListener('click', async () => {
let device;
try {
device = await navigator.usb.requestDevice({ filters: [{
vendorId: 0x054c,
protocolCode: 0x01
}]});
console.log("open");
await device.open();
} catch (e) {
console.log(e);
alert(e);
throw e;
}
try {
console.log("selectConfiguration");
await device.selectConfiguration(1);
console.log("claimInterface");
await device.claimInterface(0);
console.log(device);
startButton.style.display = 'none';
waitingMessage.style.display = 'block';
do {
await session(device);
await sleep(500);
} while (true);
} catch (e) {
console.log(e);
alert(e);
try {
device.close();
} catch (e) {
console.log(e);
}
startButton.style.display = 'block';
waitingMessage.style.display = 'none';
idmMessage.style.display = 'none';
throw e;
}
});
</script>
</body>
</html>