Browse Source

MITM ATR

develop
Robin Thoni 7 years ago
parent
commit
6f7970554f
1 changed files with 24 additions and 16 deletions
  1. 24
    16
      main.ino

+ 24
- 16
main.ino View File

1
 #include <Arduino.h>
1
 #include <Arduino.h>
2
 #include <pins_arduino.h>
2
 #include <pins_arduino.h>
3
 #include <SoftwareSerial.h>
3
 #include <SoftwareSerial.h>
4
+#include <SCLib.h>
4
 
5
 
5
 #define ledPin 13
6
 #define ledPin 13
6
 
7
 
11
 #define READER_VPP
12
 #define READER_VPP
12
 #define READER_IO  2
13
 #define READER_IO  2
13
 
14
 
14
-#define CARD_VCC
15
-#define CARD_RST
16
-#define CARD_CLK
15
+#define CARD_VCC   11
16
+#define CARD_RST   7
17
+#define CARD_CLK   9
17
 #define CARD_GND
18
 #define CARD_GND
18
 #define CARD_VPP
19
 #define CARD_VPP
19
-#define CARD_IO
20
+#define CARD_IO    10
21
+#define CARD_PRE   12
22
+
23
+SmartCardReader cardReader(CARD_IO, CARD_RST, CARD_VCC, CARD_PRE, CARD_CLK, true);
24
+uint8_t atr[MAX_ATR_BYTES];
25
+int atr_size;
20
 
26
 
21
 bool readerReset = false;
27
 bool readerReset = false;
22
 int baudRate = -1;
28
 int baudRate = -1;
23
 int etu = -1;
29
 int etu = -1;
24
-
30
+#ifndef digitalPinToInterrupt
25
 int digitalPinToInterrupt(int pin)
31
 int digitalPinToInterrupt(int pin)
26
 {
32
 {
27
     if (pin == 2)
33
     if (pin == 2)
35
     return -1;
41
     return -1;
36
 }
42
 }
37
 
43
 
44
+#endif
45
+
38
 void onReaderReset()
46
 void onReaderReset()
39
 {
47
 {
40
     readerReset = true;
48
     readerReset = true;
81
     }
89
     }
82
 }
90
 }
83
 
91
 
84
-void sendAtr()
92
+void sendAtr(const uint8_t* atr, size_t size)
85
 {
93
 {
86
-    const char atr[] = {0x3B, 0x65, 0x00, 0x00, 0x20, 0x63, 0xCB, 0x6C, 0x81};
87
-    int size = sizeof(atr);
88
     pinMode(READER_IO, OUTPUT);
94
     pinMode(READER_IO, OUTPUT);
89
     for (int i = 0; i < size; ++i)
95
     for (int i = 0; i < size; ++i)
90
     {
96
     {
103
     digitalWrite(READER_IO, HIGH);
109
     digitalWrite(READER_IO, HIGH);
104
 
110
 
105
     pinMode(ledPin, OUTPUT);
111
     pinMode(ledPin, OUTPUT);
106
-
107
     digitalWrite (ledPin, LOW);
112
     digitalWrite (ledPin, LOW);
108
     Serial.println("Initialized");
113
     Serial.println("Initialized");
109
-}
110
 
114
 
111
-void delayMs(unsigned int ms)
112
-{
113
-    for (unsigned i = 0; i < ms; i++) {
114
-        delayMicroseconds(1000);
115
-    }
115
+
116
+    atr_size = cardReader.activate(atr, sizeof(atr));
117
+    cardReader.deactivate();
116
 }
118
 }
117
 
119
 
118
 void loop() {
120
 void loop() {
121
     {
123
     {
122
         if (!readerReset)
124
         if (!readerReset)
123
         {
125
         {
126
+//            atr_size = cardReader.activate(atr, sizeof(atr));
127
+
128
+//            uint8_t atr[] = {0x3B, 0x65, 0x00, 0x00, 0x20, 0x63, 0xCB, 0x6C, 0x80};
129
+//            int atr_size = sizeof(atr);
124
             computeEtu();
130
             computeEtu();
125
-            sendAtr();
131
+            sendAtr(atr, atr_size);
126
             readerReset = true;
132
             readerReset = true;
127
             digitalWrite(ledPin, !digitalRead(ledPin));
133
             digitalWrite(ledPin, !digitalRead(ledPin));
134
+
135
+//            cardReader.deactivate();
128
         }
136
         }
129
     }
137
     }
130
     else
138
     else

Loading…
Cancel
Save