-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathprotocol_t0.c
559 lines (490 loc) · 17.5 KB
/
protocol_t0.c
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
/*
protocol_t0.c
Handling of ISO 7816 T=0 protocol
This file is part of the Unix driver for Towitoko smartcard readers
Copyright (C) 2000 Carlos Prados <[email protected]>
This version is modified by doz21 to work in a special manner ;)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../globals.h"
#ifdef WITH_CARDREADER
#include "../oscam-time.h"
#include "icc_async.h"
#include "protocol_t0.h"
/*
* Not exported constants definition
*/
#define OK 0
#define ERROR 1
#define PROTOCOL_T0_MAX_NULLS 200
#define PROTOCOL_T0_DEFAULT_WI 10
#define PROTOCOL_T0_MAX_SHORT_COMMAND 260
#define PROTOCOL_T0_MAX_SHORT_RESPONSE 258
#define PROTOCOL_T14_MAX_NULLS 200
#define PROTOCOL_T14_DEFAULT_WI 10
#define PROTOCOL_T14_MAX_SHORT_COMMAND 260
#define PROTOCOL_T14_MAX_SHORT_RESPONSE 258
/* Types of APDU's */
#define APDU_CASE_1 0x0001 /* Nor send neither receive data */
#define APDU_CASE_2S 0x0002 /* Receive data (1..256) */
#define APDU_CASE_3S 0x0003 /* Send data (1..255) */
#define APDU_CASE_4S 0x0004 /* Send data (1..255) and receive data (1..256) */
#define APDU_CASE_2E 0x0102 /* Receive data (1..65536) */
#define APDU_CASE_3E 0x0103 /* Send data (1..65535) */
#define APDU_CASE_4E 0x0104 /* Send data (1..65535) and receive data (1..65536) */
#define APDU_MALFORMED 5 /* Malformed APDU */
/* Timings in ATR are not used in T=0 cards */
/* #undef PROTOCOL_T0_USE_DEFAULT_TIMINGS */
/*
* Not exported functions declaration
*/
static int32_t Protocol_T0_Case2E(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr);
static int32_t Protocol_T0_Case3E(struct s_reader *reader, unsigned char *command, unsigned char *rsp, uint16_t *lr);
static int32_t Protocol_T0_Case4E(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr);
static int32_t Protocol_T0_ExchangeTPDU(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr);
static int32_t APDU_Cmd_Case(unsigned char *command, uint16_t command_len)
{
unsigned char B1;
uint16_t B2B3;
uint32_t L;
int32_t res;
/* Calculate length of body */
L = MAX(command_len - 4, 0);
/* Case 1 */
if(L == 0)
{ res = APDU_CASE_1; }
else
{
/* Get first byte of body */
B1 = command[4];
if((B1 != 0) && (L == (uint32_t)B1 + 1))
{ res = APDU_CASE_2S; }
else if(L == 1)
{ res = APDU_CASE_3S; }
else if((B1 != 0) && (L == (uint32_t)B1 + 2))
{ res = APDU_CASE_4S; }
else if((B1 == 0) && (L > 2))
{
/* Get second and third byte of body */
B2B3 = (((uint16_t)(command[5]) << 8) | command[6]);
if((B2B3 != 0) && (L == (uint32_t)B2B3 + 3))
{ res = APDU_CASE_2E; }
else if(L == 3)
{ res = APDU_CASE_3E; }
else if((B2B3 != 0) && (L == (uint32_t)B2B3 + 5))
{ res = APDU_CASE_4E; }
else
{ res = APDU_MALFORMED; }
}
else
{ res = APDU_MALFORMED; }
}
return res;
}
/*
* Exported funtions definition
*/
int32_t Protocol_T0_Command(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr)
{
*lr = 0; //will be returned in case of error
if(command_len < 5) //APDU_CASE_1 or malformed
{ return ERROR; }
int32_t cmd_case = APDU_Cmd_Case(command, command_len);
switch(cmd_case)
{
case APDU_CASE_2E:
return Protocol_T0_Case2E(reader, command, command_len, rsp, lr);
case APDU_CASE_3E:
return Protocol_T0_Case3E(reader, command, rsp, lr);
case APDU_CASE_4E:
return Protocol_T0_Case4E(reader, command, command_len, rsp, lr);
case APDU_CASE_4S:
command_len--; //FIXME this should change 4S to 2S/3S command
case APDU_CASE_2S:
case APDU_CASE_3S:
return Protocol_T0_ExchangeTPDU(reader, command, command_len, rsp, lr);
default:
rdr_log_dbg(reader, D_IFD, "Protocol: T=0: Invalid APDU");
return ERROR;
}
}
/*
* Not exported functions definition
*/
static int32_t Protocol_T0_Case2E(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr)
{
unsigned char buffer[PROTOCOL_T0_MAX_SHORT_COMMAND];
unsigned char tpdu_rsp[CTA_RES_LEN];
uint16_t tpdu_lr = 0;
uint32_t i;
uint32_t Lc = (((uint32_t)(command[5]) << 8) | command[6]);
if(Lc < 256)
{
/* MAP APDU onto command TPDU */
memcpy(buffer, command, 4);
buffer[4] = (unsigned char) Lc;
memcpy(buffer + 5, command + 7, buffer[4]);
return Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, rsp, lr);
}
/* Prepare envelope TPDU */
buffer[0] = command[0];
buffer[1] = 0xC2;
buffer[2] = 0x00;
buffer[3] = 0x00;
for(i = 0; i < command_len; i += buffer[4])
{
/* Create envelope command TPDU */
buffer[4] = MIN(255, command_len - i);
memcpy(buffer + 5, command + i, buffer[4]);
call(Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, &tpdu_lr));
/* Card does support envelope command */
if(tpdu_rsp[tpdu_lr - 2] == 0x90)
{
/* This is not the last segment */
if(buffer[4] + i < command_len)
{ tpdu_lr = 0; }
else
{
memcpy(rsp, tpdu_rsp, tpdu_lr); // Map response TPDU onto APDU
*lr = tpdu_lr;
}
}
else /* Card does not support envelope command or error */
{
memcpy(rsp, tpdu_rsp, tpdu_lr); // Map response TPDU onto APDU
*lr = tpdu_lr;
break;
}
}
return OK;
}
static int32_t Protocol_T0_Case3E(struct s_reader *reader, unsigned char *command, unsigned char *rsp, uint16_t *lr)
{
int32_t ret;
unsigned char buffer[5];
unsigned char tpdu_rsp[CTA_RES_LEN];
uint16_t tpdu_lr = 0;
int32_t Lm, Lx;
uint32_t Le = ((((uint32_t)(command[5]) << 8) | command[6]) == 0 ? 65536 : (((uint32_t)(command[5]) << 8) | command[6]));
memcpy(buffer, command, 4);//Map APDU command onto TPDU
if(Le <= 256)
{
buffer[4] = (unsigned char)Le;
return Protocol_T0_ExchangeTPDU(reader, buffer, 5, rsp, lr); //this was Case3S !!!
}
/* Map APDU onto command TPDU */
buffer[4] = 0x00;
call(Protocol_T0_ExchangeTPDU(reader, buffer, 5 , tpdu_rsp, &tpdu_lr));
if(tpdu_rsp[tpdu_lr - 2] == 0x6C) /* Le not accepted, La indicated */
{
/* Map command APDU onto TPDU */
memcpy(buffer, command, 4);
buffer[4] = tpdu_rsp[tpdu_lr - 1];
/* Delete response TPDU */
tpdu_lr = 0;
return Protocol_T0_ExchangeTPDU(reader, buffer, 5, rsp, lr); //Reissue command
}
memcpy(rsp, tpdu_rsp, tpdu_lr);//Map response TPDU onto APDU without change , also for SW1 = 0x67
*lr = tpdu_lr;
ret = OK;
if(tpdu_rsp[tpdu_lr - 2] == 0x61) /* Command processed, Lx indicated */
{
Lx = (tpdu_rsp[tpdu_lr - 1] == 0x00) ? 256 : tpdu_rsp[tpdu_lr - 1];
Lm = Le - (*lr - 2);
/* Prepare Get Response TPDU */
buffer[0] = command[0];
buffer[1] = 0xC0;
buffer[2] = 0x00;
buffer[3] = 0x00;
while(Lm > 0)
{
buffer[4] = (unsigned char) MIN(Lm, Lx);
call(Protocol_T0_ExchangeTPDU(reader, buffer, 5, tpdu_rsp, &tpdu_lr));
/* Append response TPDU to APDU */
if((*lr + tpdu_lr) > CTA_RES_LEN)
{
rdr_log(reader, "TPDU Append error, new length %i exceeds max length %i", *lr + tpdu_lr, CTA_RES_LEN);
return ERROR;
}
memcpy(rsp + (*lr - 2), tpdu_rsp, tpdu_lr);
*lr += tpdu_lr;
/* Delete response TPDU */
tpdu_lr = 0;
Lm = Le - (*lr - 2);
}/* Lm == 0 */
}
return ret;
}
static int32_t Protocol_T0_Case4E(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr)
{
int32_t ret;
unsigned char buffer[PROTOCOL_T0_MAX_SHORT_COMMAND];
unsigned char tpdu_rsp[CTA_RES_LEN];
memset(tpdu_rsp, 0, sizeof(tpdu_rsp));
uint16_t tpdu_lr = 0;
int32_t Le;
uint32_t Lc = (((uint32_t)(command[5]) << 8) | command[6]);
/* 4E1 */
if(Lc < 256)
{
/* Map APDU onto command TPDU */
memcpy(buffer, command, 4);
buffer[4] = (unsigned char) Lc;
memcpy(buffer + 5, command, buffer[4]);
ret = Protocol_T0_ExchangeTPDU(reader, buffer, buffer[4] + 5, tpdu_rsp, &tpdu_lr);
}
else /* 4E2 */
{ ret = Protocol_T0_Case2E(reader, command, command_len, tpdu_rsp, &tpdu_lr); }
/* 4E1 a) b) and c) */
if(ret == OK)
{
Le = ((((uint32_t)(command[command_len - 2]) << 8) | command[command_len - 1]) == 0 ? 65536 : (((uint32_t)(command[command_len - 2]) << 8) | command[command_len - 1]));
if(tpdu_lr > 1 && tpdu_rsp[tpdu_lr - 2] == 0x61)
{
/* Lm == (Le - APDU_Rsp_RawLen (tpdu_rsp)) == 0 */
if(tpdu_rsp[tpdu_lr - 1] != 0x00)
{ Le = MIN(tpdu_rsp[tpdu_lr - 1], Le); }
/* Delete response TPDU */
tpdu_lr = 0;
/* Prepare extended Get Response APDU command */
buffer[0] = command[0];
buffer[1] = 0xC0;
buffer[2] = 0x00;
buffer[3] = 0x00;
buffer[4] = 0x00; /* B1 = 0x00 */
buffer[5] = (unsigned char)(Le >> 8); /* B2 = BL-1 */
buffer[6] = (unsigned char)(Le & 0x00FF); /* B3 = BL */
ret = Protocol_T0_Case3E(reader, buffer, rsp, lr);
}
else if(tpdu_lr > 1 && (tpdu_rsp[tpdu_lr - 2] & 0xF0) == 0x60)
{
/* Map response TPDU onto APDU without change */
memcpy(rsp, tpdu_rsp, tpdu_lr);
*lr = tpdu_lr;
}
else
{
/* Delete response TPDU */
tpdu_lr = 0;
/* Prepare extended Get Response APDU command */
buffer[0] = command[0];
buffer[1] = 0xC0;
buffer[2] = 0x00;
buffer[3] = 0x00;
buffer[4] = 0x00; /* B1 = 0x00 */
buffer[5] = (unsigned char) Le >> 8; /* B2 = BL-1 */
buffer[6] = (unsigned char) Le & 0x00FF; /* B3 = BL */
ret = Protocol_T0_Case3E(reader, buffer, rsp, lr);
}
}
return ret;
}
static int32_t Protocol_T0_ExchangeTPDU(struct s_reader *reader, unsigned char *command, uint16_t command_len, unsigned char *rsp, uint16_t *lr)
{
unsigned char buffer[PROTOCOL_T0_MAX_SHORT_RESPONSE];
unsigned char *data;
int32_t Lc, Le, sent, recved, expectedlen;
int32_t nulls, cmd_case;
int32_t timeout;
*lr = 0; //in case of error this will be returned
cmd_case = APDU_Cmd_Case(command, command_len);
switch(cmd_case)
{
case APDU_CASE_2S:
Lc = command[4];
Le = 0;
expectedlen = 1;
data = command + 5;
break;
case APDU_CASE_3S:
Lc = 0;
Le = command[4];
if(!Le)
{ expectedlen = 2; }
else
{ expectedlen = 1 + Le + 2; }
data = NULL;
break;
default:
rdr_log_dbg(reader, D_TRACE, "ERROR: invalid cmd_case = %i in Protocol_T0_ExchangeTPDU", cmd_case);
return ERROR;
}
timeout = ICC_Async_GetTimings(reader, reader->char_delay); // we are going to send: char delay timeout
if(ICC_Async_Transmit(reader, 5, expectedlen, command, 0, timeout) != OK) { return ERROR; } //Send header bytes
/* Initialise counters */
nulls = 0;
sent = 0;
recved = 0;
/*
* Let's be a bit paranoid with buffer sizes within this loop
* so it doesn't overflow reception and transmission buffers
* if card does not strictly respect the protocol
*/
while(recved < PROTOCOL_T0_MAX_SHORT_RESPONSE)
{
timeout = ICC_Async_GetTimings(reader, reader->read_timeout); // we are going to receive: WWT timeout
if(ICC_Async_Receive(reader, 1, buffer + recved, 0, timeout) != OK) { return ERROR; } //Read one procedure byte
/* NULL byte received */
if(buffer[recved] == 0x60)
{
nulls++;
if(nulls >= PROTOCOL_T0_MAX_NULLS) //Maximum number of nulls reached
{
rdr_log_dbg(reader, D_TRACE, "ERROR: %s: Maximum number of nulls reached: %d", __func__, nulls);
return ERROR;
}
}
else if((buffer[recved] & 0xF0) == 0x60 || (buffer[recved] & 0xF0) == 0x90) /* SW1 byte received */
{
rdr_log_dbg(reader, D_TRACE, "SW1: %02X", buffer[recved] & 0xf0);
recved++;
if(recved >= PROTOCOL_T0_MAX_SHORT_RESPONSE)
{
rdr_log_dbg(reader, D_TRACE, "ERROR: %s: Maximum short response exceeded: %d", __func__, recved);
return ERROR;
}
timeout = ICC_Async_GetTimings(reader, reader->read_timeout); // we are going to receive: WWT timeout
if(ICC_Async_Receive(reader, 1, buffer + recved, 0, timeout) != OK) { return ERROR; } //Read SW2 byte
rdr_log_dbg(reader, D_TRACE, "SW2: %02X", buffer[recved] & 0xf0);
recved++;
break;
}
else if((buffer[recved] & 0x0E) == (command[1] & 0x0E)) /* ACK byte received */
{
//printf("ack\n");
/* Reset null's counter */
nulls = 0;
/* Case 2 command: send data */
if(cmd_case == APDU_CASE_2S)
{
if(sent >= Lc)
{
rdr_log_dbg(reader, D_TRACE, "ERROR: %s: ACK byte: sent=%d exceeds Lc=%d", __func__, sent, Lc);
return ERROR;
}
timeout = ICC_Async_GetTimings(reader, reader->char_delay); // we are going to send: char delay timeout
if(ICC_Async_Transmit(reader, MAX(Lc - sent, 0), 2, data + sent, 0, timeout) != OK) { return ERROR; } /* Send remaining data bytes */
sent = Lc;
continue;
}
else /* Case 3 command: receive data */
{
if(recved > PROTOCOL_T0_MAX_SHORT_RESPONSE)
{
rdr_log_dbg(reader, D_TRACE, "ERROR: %s: Case 3 ACK - maximum short response exceeded: %d", __func__, recved);
return ERROR;
}
/*
* Le <= PROTOCOL_T0_MAX_SHORT_RESPONSE - 2 for short commands
*/
/* Read remaining data bytes */
timeout = ICC_Async_GetTimings(reader, reader->read_timeout); // we are going to receive: WWT timeout
if(ICC_Async_Receive(reader, MAX(Le - recved, 0), buffer + recved, 0, timeout) != OK) { return ERROR; }
recved = Le;
continue;
}
}
else if((buffer[recved] & 0x0E) == ((~command[1]) & 0x0E)) /* ~ACK byte received */
{
//printf("~ack\n");
nulls = 0; //Reset null's counter
/* Case 2 command: send data */
if(cmd_case == APDU_CASE_2S)
{
if(sent >= Lc)
{
rdr_log_dbg(reader, D_TRACE, "ERROR: %s: ~ACK byte: sent=%d exceeds Lc=%d", __func__, sent, Lc);
return ERROR;
}
timeout = ICC_Async_GetTimings(reader, reader->char_delay); // we are going to send: char delay timeout
if(ICC_Async_Transmit(reader, 1, 1, data + sent, 0, timeout) != OK) { return ERROR; } //Send next data byte
sent++;
continue;
}
else /* Case 3 command: receive data */
{
if(recved > PROTOCOL_T0_MAX_SHORT_RESPONSE)
{
rdr_log_dbg(reader, D_TRACE, "ERROR: %s: Case 3 ~ACK - maximum short response exceeded: %d", __func__, recved);
return ERROR;
}
timeout = ICC_Async_GetTimings(reader, reader->read_timeout); // we are going to receive: WWT timeout
if(ICC_Async_Receive(reader, 1, buffer + recved, 0, timeout) != OK) { return ERROR; } //Read next data byte
recved++;
continue;
}
}
else /* Anything else received */
{
rdr_log_dbg(reader, D_TRACE, "ERROR: %s: Received unexpected character: %02X", __func__, buffer[recved]);
return ERROR;
}
}//while
memcpy(rsp, buffer, recved);
*lr = recved;
return OK;
}
int32_t Protocol_T14_ExchangeTPDU(struct s_reader *reader, unsigned char *cmd_raw, uint16_t command_len, unsigned char *rsp, uint16_t *lr)
{
unsigned char buffer[PROTOCOL_T14_MAX_SHORT_RESPONSE];
int32_t recved;
int32_t cmd_case;
int32_t timeout;
unsigned char ixor = 0x3E;
unsigned char ixor1 = 0x3F;
int32_t i;
int32_t cmd_len = (int32_t) command_len;
*lr = 0; //in case of error this is returned
/* Parse APDU */
cmd_case = APDU_Cmd_Case(cmd_raw, cmd_len);
for(i = 0; i < cmd_len; i++)
{ ixor ^= cmd_raw[i]; }
/* Check case of command */
if((cmd_case != APDU_CASE_2S) && (cmd_case != APDU_CASE_3S))
{
rdr_log_dbg(reader, D_TRACE, "ERROR: invalid cmd_case = %i in Protocol_T14_ExchangeTPDU", cmd_case);
return ERROR;
}
buffer[0] = 0x01; //send 0x01 byte
memcpy(buffer + 1, cmd_raw, cmd_len); // apdu
buffer[cmd_len + 1] = ixor; // xor byte
/* Send apdu */
timeout = ICC_Async_GetTimings(reader, reader->char_delay); // we are going to send: char delay timeout
if(ICC_Async_Transmit(reader, cmd_len + 2, 0, buffer, 0, timeout) != OK) { return ERROR; } //send apdu
if(cmd_raw[0] == 0x02 && cmd_raw[1] == 0x09) { cs_sleepms(2500); } //FIXME why wait? -> needed for init on overclocked T14 cards
timeout = ICC_Async_GetTimings(reader, reader->read_timeout); // we are going to receive: WWT timeout
// if ((reader->typ == R_SMART) && (reader->smart_type >= 2)) timeout *= 1.1;
if(ICC_Async_Receive(reader, 8, buffer, 0, timeout) != OK) { return ERROR; } //Read one procedure byte
recved = (int32_t)buffer[7];
if(recved)
{
timeout = ICC_Async_GetTimings(reader, reader->read_timeout); // we are going to receive: WWT timeout
// if ((reader->typ == R_SMART) && (reader->smart_type >= 2)) timeout *= 1.1;
if(ICC_Async_Receive(reader, recved, buffer + 8, 0 , timeout) != OK) {return ERROR; }
}
timeout = ICC_Async_GetTimings(reader, reader->read_timeout); // we are going to receive: WWT timeout
// if ((reader->typ == R_SMART) && (reader->smart_type >= 2)) timeout *= 1.1;
if(ICC_Async_Receive(reader, 1, &ixor, 0, timeout) != OK) {return ERROR; }
for(i = 0; i < 8 + recved; i++)
{ ixor1 ^= buffer[i]; }
if(ixor1 != ixor)
{
rdr_log_dbg(reader, D_TRACE, "ERROR: invalid checksum = %02X expected %02X", ixor1, ixor);
return ERROR;
}
memcpy(buffer + 8 + recved, buffer + 2, 2);
*lr = recved + 2;
memcpy(rsp, buffer + 8, *lr);
return OK;
}
#endif