Upgrade doxygen configuration files to the latest version.
[pub/lufa.git] / Demos / Device / LowLevel / CCID / HostTestApp / test_generic_ccid_libusb.js
index 993c0e5..9416246 100644 (file)
@@ -1,13 +1,13 @@
 #!/usr/bin/env node
 
 //             LUFA Library
-//     Copyright (C) Dean Camera, 2018.
+//     Copyright (C) Dean Camera, 2021.
 //
 //  dean [at] fourwalledcubicle [dot] com
 //
 //           www.lufa-lib.org
 
-// Copyright 2018  Filipe Rodrigues (filipepazrodrigues [at] gmail [dot] com)
+// Copyright 2021  Filipe Rodrigues (filipepazrodrigues [at] gmail [dot] com)
 //
 // LUFA Generic CCID device demo host test script. This script test multiple
 // kinds of CCID messages and shows the result to the console
@@ -23,10 +23,12 @@ var sprintf = require('sprintf');
 var deviceVid = 0x03EB;
 var devicePid = 0x206E;
 
+var CCID_PC_to_RDR_SetParameters        = 0x61;
+var CCID_PC_to_RDR_GetParameters        = 0x6C;
 var CCID_PC_to_RDR_IccPowerOn           = 0x62;
 var CCID_PC_to_RDR_IccPowerOff          = 0x63;
 var CCID_PC_to_RDR_GetSlotStatus        = 0x65;
-var CCID_PC_to_RDR_XfrBlock         = 0x6f;
+var CCID_PC_to_RDR_XfrBlock             = 0x6f;
 
 function getAndInitCcidDeviceAndInterface()
 {
@@ -72,6 +74,30 @@ function write(ccidInterface, message, callback)
 
 //CCID functions
 
+function GetParametersMessage(slot, seq, protocolNum, t0Params)
+{
+    return [
+        CCID_PC_to_RDR_GetParameters, //message type
+        0, 0, 0, 0, //length
+        slot,
+        seq,
+        0, 0, 0 //RFU
+    ];
+}
+
+function SetParametersMessage(slot, seq, protocolNum, t0Params)
+{
+    return [
+        CCID_PC_to_RDR_SetParameters, //message type
+        t0Params.length, 0, 0, 0, //length
+        slot,
+        seq,
+        protocolNum,
+        0, 0 //RFU
+    ].concat(t0Params);
+}
+
+
 function IccPowerOnMessage(slot, seq)
 {
     return [
@@ -106,23 +132,22 @@ function GetSlotStatusMessage(slot, seq)
     ];
 }
 
-function XfrBlockMessage(slot, seq)
+function XfrBlockMessage(slot, seq, apdu)
 {
     return [
         CCID_PC_to_RDR_XfrBlock, //message type
-        5, 0, 0, 0, //length (05)
+        apdu.length, 0, 0, 0, //length: only for < 0xFF
         slot,
         seq,
-        0, //BWI 
-        0, 0, //level parameter
-        0, 0xfd, 0, 0, 0 //message
-    ];
+        0, //BWI
+        0, 0 //level parameter
+    ].concat(apdu);
 
 }
 
-function startTest()
+function testCcidMessages()
 {
-    async.series([
+    return [
         function(callback) {
             write(ccidInterface, new Buffer(IccPowerOnMessage(0, 1)), callback);
         },
@@ -140,8 +165,28 @@ function startTest()
         },
         function(callback) {
             read(ccidInterface, 10, callback);
-        }
-        ]);
+        },
+        function(callback) {
+            write(ccidInterface, new Buffer(SetParametersMessage(0, 4, 0, [0x11, 0x00, 0x00, 0x0a, 0x00])), callback);
+        },
+        function(callback) {
+            //must return 82 05 00 00 00 00 04 00 80 00 11 00 00 0a 00
+            read(ccidInterface, 30, callback);
+        },
+        function(callback) {
+            write(ccidInterface, new Buffer(GetParametersMessage(0, 5, 0)), callback);
+        },
+        function(callback) {
+            //must return 82 05 00 00 00 00 04 00 80 00 11 00 00 0a 00
+            read(ccidInterface, 30, callback);
+        }];
+}
+
+function startTest()
+{
+    async.series([]
+        .concat(testCcidMessages())
+    );
 }
 
 var ccidDeviceAndInterface = getAndInitCcidDeviceAndInterface();