-
Notifications
You must be signed in to change notification settings - Fork 0
/
device.cpp
2863 lines (2125 loc) · 67.6 KB
/
device.cpp
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
/*
* Author: Copyright (C) Andrzej Surowiec 2012
*
*
* This file is part of GPF Crypto Stick.
*
* GPF Crypto Stick is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* GPF Crypto Stick 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GPF Crypto Stick. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QDateTime>
#include "response.h"
#include "string.h"
#include "crc32.h"
#include "sleep.h"
#include "device.h"
/*******************************************************************************
External declarations
*******************************************************************************/
/*******************************************************************************
Local defines
*******************************************************************************/
//#define LOCAL_DEBUG // activate for debugging
/*******************************************************************************
Device
Constructor Device
Changes
Date Author Info
25.03.14 RB Dynamic slot counts
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
Device::Device(int vid, int pid,int vidStick20, int pidStick20,int vidStick20UpdateMode, int pidStick20UpdateMode)
{
int i;
LastStickError = OUTPUT_CMD_STICK20_STATUS_OK;
dev_hid_handle=NULL;
isConnected=false;
this->vid=vid;
this->pid=pid;
validPassword =false;
passwordSet =false;
validUserPassword = false;
memset(password,0,50);
memset(userPassword,0,50);
// Vars for password safe
passwordSafeUnlocked = FALSE;
memset(passwordSafeStatusDisplayed,0,PWS_SLOT_COUNT);
for (i=0;i<PWS_SLOT_COUNT;i++)
{
passwordSafeSlotNames[i][0] = 0;
}
//handle = hid_open(vid,pid, NULL);
HOTP_SlotCount = HOTP_SLOT_COUNT; // For stick 1.0
TOTP_SlotCount = TOTP_SLOT_COUNT;
for (i=0;i<HOTP_SLOT_COUNT_MAX;i++)
{
HOTPSlots[i] = new HOTPSlot();
HOTPSlots[i]->slotNumber = 0x10 + i;
}
for (i=0;i<TOTP_SLOT_COUNT_MAX;i++)
{
TOTPSlots[i] = new TOTPSlot();
TOTPSlots[i]->slotNumber = 0x20 + i;
}
newConnection=true;
// Init data for stick 20
this->vidStick20 = vidStick20;
this->pidStick20 = pidStick20;
this->vidStick20UpdateMode = vidStick20UpdateMode;
this->pidStick20UpdateMode = pidStick20UpdateMode;
// this->vidStick20 = 0x046d;
// this->pidStick20 = 0xc315;
activStick20 = false;
waitForAckStick20 = false;
lastBlockNrStick20 = 0;
}
/*******************************************************************************
checkConnection
Check the presents of stick 1.0 or 2.0
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::checkConnection()
{
uint8_t buf[65];
buf[0]=0;
int res;
//handle = hid_open(vid,pid, NULL);
if (!dev_hid_handle)
{
isConnected = false;
newConnection = true;
return -1;
}
else{
res = hid_get_feature_report (dev_hid_handle, buf, 65);
if (res < 0){ // Check it twice to avoid connection problem
res = hid_get_feature_report (dev_hid_handle, buf, 65);
if (res < 0){
isConnected = false;
newConnection = true;
return -1;
}
}
if (newConnection)
{
isConnected = true;
newConnection = false;
passwordSet = false;
validPassword = false;
validUserPassword = false;
HOTP_SlotCount = HOTP_SLOT_COUNT; // For stick 1.0
TOTP_SlotCount = TOTP_SLOT_COUNT;
// stick 20 with no OTP
if (true == activStick20)
{
HOTP_SlotCount = HOTP_SLOT_COUNT_MAX;
TOTP_SlotCount = TOTP_SLOT_COUNT_MAX;
passwordSafeUnlocked = FALSE;
}
initializeConfig(); // init data for OTP
return 1;
}
return 0;
}
}
/*******************************************************************************
connect
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
void Device::connect()
{
// Disable stick 20
activStick20 = false;
dev_hid_handle = hid_open(vid,pid, NULL);
// Check for stick 20
if (NULL == dev_hid_handle)
{
dev_hid_handle = hid_open(vidStick20,pidStick20, NULL);
if (NULL != dev_hid_handle)
{
// Stick 20 found
activStick20 = true;
}
}
}
/*******************************************************************************
sendCommand
Send a command to the stick via the send feature report HID message
Report size is 64 byte
Command data size COMMAND_SIZE = 59 byte (should 58 ???)
Byte 0 = 0
Byte 1 = cmd type
Byte 2-59 = payload (To do check length)
Byte 60-63 = CRC 32 from byte 0-59 = 15 long words
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::sendCommand(Command *cmd)
{
uint8_t report[REPORT_SIZE+1];
int i;
int err;
memset(report,0,sizeof(report));
report[1]=cmd->commandType;
memcpy(report+2,cmd->data,COMMAND_SIZE);
uint32_t crc=0xffffffff;
for (i=0;i<15;i++){
crc=Crc32(crc,((uint32_t *)(report+1))[i]);
}
((uint32_t *)(report+1))[15]=crc;
cmd->crc=crc;
/*
{
char text[1000];
sprintf(text,"computed crc :%08x:\n",crc );
DebugAppendText (text);
}
*/
err = hid_send_feature_report(dev_hid_handle, report, sizeof(report));
{
char text[1000];
int i;
static int Counter = 0;
sprintf(text,"%6d :sendCommand0: ",Counter);
Counter++;
DebugAppendText (text);
for (i=0;i<=64;i++)
{
sprintf(text,"%02x ",(unsigned char)report[i]);
DebugAppendText (text);
}
sprintf(text,"\n");
DebugAppendText (text);
}
return err;
}
int Device::sendCommandGetResponse(Command *cmd, Response *resp)
{
uint8_t report[REPORT_SIZE+1];
int i;
int err;
if (!isConnected)
return ERR_NOT_CONNECTED;
memset(report,0,sizeof(report));
report[1]=cmd->commandType;
memcpy(report+2,cmd->data,COMMAND_SIZE);
uint32_t crc=0xffffffff;
for (i=0;i<15;i++){
crc=Crc32(crc,((uint32_t *)(report+1))[i]);
}
((uint32_t *)(report+1))[15]=crc;
cmd->crc=crc;
err = hid_send_feature_report(dev_hid_handle, report, sizeof(report));
{
char text[1000];
int i;
static int Counter = 0;
sprintf(text,"%6d :sendCommand1: ",Counter);
Counter++;
DebugAppendText (text);
for (i=0;i<=64;i++)
{
sprintf(text,"%02x ",(unsigned char)report[i]);
DebugAppendText (text);
}
sprintf(text,"\n");
DebugAppendText (text);
}
if (err==-1)
return ERR_SENDING;
Sleep::msleep(100);
//Response *resp=new Response();
resp->getResponse(this);
if (cmd->crc!=resp->lastCommandCRC)
return ERR_WRONG_RESPONSE_CRC;
if (resp->lastCommandStatus==CMD_STATUS_OK)
return 0;
return ERR_STATUS_NOT_OK;
}
/*******************************************************************************
getSlotName
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::getSlotName(uint8_t slotNo){
int res;
uint8_t data[1];
data[0]=slotNo;
if (isConnected){
Command *cmd=new Command(CMD_READ_SLOT_NAME,data,1);
res=sendCommand(cmd);
if (res==-1)
return -1;
else{ //sending the command was successful
//return cmd->crc;
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
// qDebug() << cmd->crc;
// qDebug() << resp->lastCommandCRC;
if (cmd->crc==resp->lastCommandCRC){ //the response was for the last command
if (resp->lastCommandStatus==CMD_STATUS_OK)
{
if ((slotNo >= 0x10) && (slotNo < 0x10 + HOTP_SlotCount)){
memcpy(HOTPSlots[slotNo&0x0F]->slotName,resp->data,15);
HOTPSlots[slotNo&0x0F]->isProgrammed=true;
}
else if ((slotNo >= 0x20) && (slotNo < 0x20 + TOTP_SlotCount)){
memcpy(TOTPSlots[slotNo&0x0F]->slotName,resp->data,15);
TOTPSlots[slotNo&0x0F]->isProgrammed=true;
}
}
else if (resp->lastCommandStatus==CMD_STATUS_SLOT_NOT_PROGRAMMED)
{
if ((slotNo >= 0x10) && (slotNo < 0x10 + HOTP_SlotCount))
{
HOTPSlots[slotNo&0x0F]->isProgrammed=false;
HOTPSlots[slotNo&0x0F]->slotName[0] = 0;
}
else if ((slotNo >= 0x20) && (slotNo < 0x20 + TOTP_SlotCount))
{
TOTPSlots[slotNo&0x0F]->isProgrammed=false;
TOTPSlots[slotNo&0x0F]->slotName[0] = 0;
}
}
}
/*
{
QMessageBox message;
QString str;
QByteArray *data =new QByteArray((char*)resp->reportBuffer,REPORT_SIZE+1);
// str.append(QString::number(testResponse->lastCommandCRC,16));
str.append(QString(data->toHex()));
message.setText(str);
message.exec();
str.clear();
}
*/
return 0;
}
}
return -1;
}
/*******************************************************************************
eraseSlot
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::eraseSlot(uint8_t slotNo)
{
int res;
uint8_t data[1];
data[0]=slotNo;
if (isConnected){
Command *cmd=new Command(CMD_ERASE_SLOT,data,1);
authorize(cmd);
res=sendCommand(cmd);
if (res==-1)
return -1;
else{ //sending the command was successful
//return cmd->crc;
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
// qDebug() << cmd->crc;
// qDebug() << resp->lastCommandCRC;
}
return 0;
}
return -1;
}
/*******************************************************************************
setTime
reset = 0 Get time
1 Set time
Reviews
Date Reviewer Info
27.07.14 SN First review
*******************************************************************************/
int Device::setTime(int reset){
int res;
uint8_t data[30];
uint64_t time = QDateTime::currentDateTime().toTime_t();
memset(data,0,30);
data[0] = reset;
memcpy(data+1,&time,8);
if (isConnected){
Command *cmd=new Command(CMD_SET_TIME,data,9);
res=sendCommand(cmd);
if (res==-1)
return -1;
else{ //sending the command was successful
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
if (cmd->crc==resp->lastCommandCRC){ //the response was for the last command
if (resp->lastCommandStatus==CMD_STATUS_OK)
{
}
else if (resp->lastCommandStatus==CMD_STATUS_TIMESTAMP_WARNING)
{
return -2;
}
}
return 0;
}
}
return -1;
}
/*******************************************************************************
writeToHOTPSlot
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::writeToHOTPSlot(HOTPSlot *slot)
{
// qDebug() << "preparing to send";
// qDebug() << slot->slotNumber;
// qDebug() << QString((char *)slot->slotName);
if ((slot->slotNumber >= 0x10) && (slot->slotNumber < 0x10 + HOTP_SlotCount)){
int res;
uint8_t data[COMMAND_SIZE];
memset(data,0,COMMAND_SIZE);
// qDebug() << "prepared data array";
data[0]=slot->slotNumber;
memcpy(data+1,slot->slotName,15);
memcpy(data+16,slot->secret,20);
data[36]=slot->config;
memcpy(data+37,slot->tokenID,13);
memcpy(data+50,slot->counter,8);
// qDebug() << "copied data to array";
if (isConnected)
{
Command *cmd=new Command(CMD_WRITE_TO_SLOT,data,COMMAND_SIZE);
// qDebug() << "sending";
authorize(cmd);
res=sendCommand(cmd);
// qDebug() << "sent";
if (res==-1)
return -1;
else{ //sending the command was successful
//return cmd->crc;
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
if (cmd->crc==resp->lastCommandCRC&&resp->lastCommandStatus==CMD_STATUS_OK){
// qDebug() << "sent sucessfully!";
return 0;
} else if (cmd->crc==resp->lastCommandCRC&&resp->lastCommandStatus==CMD_STATUS_NO_NAME_ERROR){
return -3;
}
}
return -2;
}
}
return -1;
}
/*******************************************************************************
writeToTOTPSlot
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::writeToTOTPSlot(TOTPSlot *slot)
{
if ((slot->slotNumber >= 0x20) && (slot->slotNumber < 0x20 + TOTP_SlotCount))
{
int res;
uint8_t data[COMMAND_SIZE];
memset(data,0,COMMAND_SIZE);
// qDebug() << "prepared data array";
data[0]=slot->slotNumber;
memcpy(data+1,slot->slotName,15);
memcpy(data+16,slot->secret,20);
data[36]=slot->config;
memcpy(data+37,slot->tokenID,13);
memcpy(data+50,&(slot->interval),2);
// qDebug() << "copied data to array";
if (isConnected){
Command *cmd=new Command(CMD_WRITE_TO_SLOT,data,COMMAND_SIZE);
// qDebug() << "sending";
authorize(cmd);
res=sendCommand(cmd);
// qDebug() << "sent";
if (res==-1)
return -1;
else{ //sending the command was successful
//return cmd->crc;
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
if (cmd->crc==resp->lastCommandCRC&&resp->lastCommandStatus==CMD_STATUS_OK){
// qDebug() << "sent sucessfully!";
return 0;
} else if (cmd->crc==resp->lastCommandCRC&&resp->lastCommandStatus==CMD_STATUS_NO_NAME_ERROR){
return -3;
}
}
return -2;
}
}
return -1;
}
/*******************************************************************************
getCode
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::getCode(uint8_t slotNo, uint64_t challenge,uint64_t lastTOTPTime,uint8_t lastInterval,uint8_t result[18])
{
// qDebug() << "getting code" << slotNo;
int res;
uint8_t data[30];
data[0]=slotNo;
memcpy(data+ 1,&challenge,8);
memcpy(data+ 9,&lastTOTPTime,8); // Time of challenge: Warning: it's better to tranfer time and interval, to avoid attacks with wrong timestamps
memcpy(data+17,&lastInterval,1);
if (isConnected){
// qDebug() << "sending command";
Command *cmd=new Command(CMD_GET_CODE,data,18);
userAuthorize(cmd);
res=sendCommand(cmd);
if (res==-1)
return -1;
else{ //sending the command was successful
//return cmd->crc;
// qDebug() << "command sent";
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
if (cmd->crc==resp->lastCommandCRC){ //the response was for the last command
if (resp->lastCommandStatus==CMD_STATUS_OK){
memcpy(result,resp->data,18);
}
}
return 0;
}
}
return -1;
}
int Device::getHOTP(uint8_t slotNo)
{
// qDebug() << "getting code" << slotNo;
int res;
uint8_t data[9];
data[0]=slotNo;
//memcpy(data+1,&challenge,8);
Command *cmd=new Command(CMD_GET_CODE,data,9);
Response *resp=new Response();
res=sendCommandGetResponse(cmd,resp);
// if (res==0)
// memcpy(result,resp->data,18);
return res;
}
/*******************************************************************************
readSlot
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::readSlot(uint8_t slotNo)
{
int res;
uint8_t data[1];
data[0]=slotNo;
if (isConnected){
Command *cmd=new Command(CMD_READ_SLOT,data,1);
res=sendCommand(cmd);
if (res==-1)
return -1;
else{ //sending the command was successful
//return cmd->crc;
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
// qDebug() << cmd->crc;
// qDebug() << resp->lastCommandCRC;
if (cmd->crc==resp->lastCommandCRC){ //the response was for the last command
if (resp->lastCommandStatus==CMD_STATUS_OK)
{
if ((slotNo >= 0x10) && (slotNo < 0x10 + HOTP_SlotCount))
{
memcpy(HOTPSlots[slotNo&0x0F]->slotName,resp->data,15);
HOTPSlots[slotNo&0x0F]->config = resp->data[15];
memcpy(HOTPSlots[slotNo&0x0F]->tokenID,resp->data+16,13);
memcpy(HOTPSlots[slotNo&0x0F]->counter,resp->data+29,8);
HOTPSlots[slotNo&0x0F]->isProgrammed=true;
/*
qDebug() << "Get HOTP counter slot " << (slotNo&0x0F);
qDebug() << QString ((char*)HOTPSlots[slotNo&0x0F]->counter);
*/
}
else if ((slotNo >= 0x20) && (slotNo < 0x20 + TOTP_SlotCount))
{
memcpy(TOTPSlots[slotNo&0x0F]->slotName,resp->data,15);
TOTPSlots[slotNo&0x0F]->config = resp->data[15];
memcpy(TOTPSlots[slotNo&0x0F]->tokenID,resp->data+16,13);
memcpy(&(TOTPSlots[slotNo&0x0F]->interval),resp->data+29,2);
TOTPSlots[slotNo&0x0F]->isProgrammed=true;
}
}
else if (resp->lastCommandStatus==CMD_STATUS_SLOT_NOT_PROGRAMMED)
{
if ((slotNo >= 0x10) && (slotNo < 0x10 + HOTP_SlotCount))
{
HOTPSlots[slotNo&0x0F]->isProgrammed=false;
HOTPSlots[slotNo&0x0F]->slotName[0] = 0;
}
else if ((slotNo >= 0x20) && (slotNo < 0x20 + TOTP_SlotCount))
{
TOTPSlots[slotNo&0x0F]->isProgrammed=false;
TOTPSlots[slotNo&0x0F]->slotName[0] = 0;
}
}
}
/*
{
QMessageBox message;
QString str;
QByteArray *data =new QByteArray((char*)resp->reportBuffer,REPORT_SIZE+1);
// str.append(QString::number(testResponse->lastCommandCRC,16));
str.append(QString(data->toHex()));
message.setText(str);
message.exec();
str.clear();
}
*/
return 0;
}
}
return -1;
}
/*******************************************************************************
initializeConfig
Changes
Date Author Info
25.03.14 RB Slot count by define
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
void Device::initializeConfig()
{
int i;
unsigned int currentTime;
for (i=0;i<HOTP_SlotCount;i++)
{
readSlot(0x10 + i);
}
for (i=0;i<TOTP_SlotCount;i++)
{
readSlot(0x20 + i);
}
if (true == activStick20)
{
currentTime = QDateTime::currentDateTime().toTime_t();
stick20SendStartup ((unsigned long long)currentTime);
}
}
/*******************************************************************************
getSlotConfigs
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
void Device::getSlotConfigs()
{
/* Removed from firmware
readSlot(0x10);
readSlot(0x11);
readSlot(0x20);
readSlot(0x21);
readSlot(0x22);
readSlot(0x23);*/
}
/*******************************************************************************
getStatus
Reviews
Date Reviewer Info
12.08.13 RB First review
*******************************************************************************/
int Device::getStatus()
{
int res;
uint8_t data[1];
if (isConnected){
Command *cmd=new Command(CMD_GET_STATUS,data,0);
res=sendCommand(cmd);
if (res==-1)
return -1;
else{ //sending the command was successful
Sleep::msleep(100);
Response *resp=new Response();
resp->getResponse(this);
if (cmd->crc==resp->lastCommandCRC){
memcpy(firmwareVersion,resp->data,2);
memcpy(cardSerial,resp->data+2,4);
memcpy(generalConfig,resp->data+6,3);
memcpy(otpPasswordConfig,resp->data+9,2);
}
}
return 0;
}
return -2;
}
/*******************************************************************************
getPasswordRetryCount
Reviews
Date Reviewer Info
*******************************************************************************/
int Device::getPasswordRetryCount()
{
int res;
uint8_t data[1];
if (isConnected){
Command *cmd=new Command(CMD_GET_PASSWORD_RETRY_COUNT,data,0);
res=sendCommand(cmd);
if (res==-1)
return ERR_SENDING;
else{ //sending the command was successful
Sleep::msleep(1000);
Response *resp=new Response();
resp->getResponse(this);
if (cmd->crc==resp->lastCommandCRC)
{
passwordRetryCount=resp->data[0];
HID_Stick20Configuration_st.AdminPwRetryCount = passwordRetryCount;
}
else
return ERR_WRONG_RESPONSE_CRC;
}
}
return ERR_NOT_CONNECTED;
}
/*******************************************************************************
getUserPasswordRetryCount
Changes
Date Reviewer Info
10.08.14 SN Function created
*******************************************************************************/
int Device::getUserPasswordRetryCount()
{
int res;
uint8_t data[1];
if (isConnected){
Command *cmd=new Command(CMD_GET_USER_PASSWORD_RETRY_COUNT,data,0);
res=sendCommand(cmd);
if (res==-1)
return ERR_SENDING;
else{ //sending the command was successful
Sleep::msleep(1000);
Response *resp=new Response();