-
Notifications
You must be signed in to change notification settings - Fork 19
/
FlashStorage.c
1437 lines (1011 loc) · 37.9 KB
/
FlashStorage.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
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) Rudolf Boeddeker Date: 2013-07-12
*
* This file is part of Nitrokey
*
* Nitrokey 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.
*
* Nitrokey 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 Nitrokey. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* FlashStorage.c
*
* Created on: 12.07.2013
* Author: RB
*/
#include <avr32/io.h>
#include <stddef.h>
#include "compiler.h"
#include "flashc.h"
#include "string.h"
#include "conf_access.h"
#include "conf_sd_mmc_mci.h"
#include "sd_mmc_mci.h"
#include "sd_mmc_mci_mem.h"
#include "global.h"
#include "tools.h"
#include "OTP/report_protocol.h"
#include "FlashStorage.h"
#include "HiddenVolume.h"
#include "OTP/hotp.h"
#include "password_safe.h"
#include "DFU_test.h"
#include "CCID/USART/ISO7816_USART.h"
#include "CCID/USART/ISO7816_ADPU.h"
#include "CCID/USART/ISO7816_Prot_T1.h"
#include "CCID/LOCAL_ACCESS/OpenPGP_V20.h"
#ifdef FREERTOS_USED
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#endif
typeStick20Configuration_st StickConfiguration_st;
/*******************************************************************************
Local defines
*******************************************************************************/
/*
Userpage layout
Byte
0 - 31 AES Storage key
32 - 51 Matrix columns for user password
52 - 71 Matrix columns for admin password
72 - 101 Stick Configuration
102 - 133 Base for AES key hidden volume (32 byte)
134 - 137 ID of sd card (4 byte)
138 - 141 Last stored real timestamp (4 byte)
142 - 145 ID of sc card (4 byte)
146 - 177 XOR mask for sc tranfered keys (32 byte)
178 - 209 Password safe key (32 byte)
210 - 241 Update PIN (32 byte)
242 - 251 Update PIN SALT (10 byte)
*/
typedef struct {
u8 AES_key[32];
u8 matrix_user[20];
u8 matrix_admin[20];
u8 stick_configuration[30];
u8 hidden_volume_AES_key_base[32];
u8 sdcard_id[4];
u8 last_timestamp_real[4];
u8 sccard_id[4];
u8 xor_mask_for_SC_keys[32];
u8 password_safe_AES_key[32];
u8 update_PIN[32];
u8 update_PIN_salt[10];
} UserPage;
UserPage * user_page = (UserPage * )AVR32_FLASHC_USER_PAGE;
#define TOKENPASTE(a, b) a ## b // "##" is the "Token Pasting Operator"
#define TOKENPASTE2(a,b) TOKENPASTE(a, b) // expand then paste
#define static_assert(x, msg) enum { TOKENPASTE2(ASSERT_line_,__LINE__) \
= 1 / (msg && (x)) }
static_assert(sizeof(UserPage) == 252, "size of conf struct invalid");
static_assert(sizeof(UserPage) <= 512, "size of conf struct is too big");
static_assert(sizeof(user_page->stick_configuration) >= sizeof(typeStick20Configuration_st), "size of conf struct is too big");
/*******************************************************************************
Global declarations
*******************************************************************************/
/*******************************************************************************
External declarations
*******************************************************************************/
/*******************************************************************************
Local declarations
*******************************************************************************/
u8 read_configuration_or_init_u8(void);
#define LOCAL_DEBUG
#define AES_KEYSIZE_256_BIT 32 // 32 * 8 = 256
#define UPDATE_PIN_MAX_SIZE 20
#define UPDATE_PIN_SALT_SIZE 10
/*******************************************************************************
WriteAESStorageKeyToUserPage
Reviews
Date Reviewer Info
03.02.14 RB First review
*******************************************************************************/
u8 WriteAESStorageKeyToUserPage (u8 * data)
{
flashc_memcpy (user_page->AES_key, data, sizeof(user_page->AES_key), TRUE);
return (TRUE);
}
/*******************************************************************************
ReadAESStorageKeyToUserPage
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 ReadAESStorageKeyToUserPage (u8 * data)
{
memcpy (data, (void *) (user_page->AES_key), sizeof(user_page->AES_key));
return (TRUE);
}
/*******************************************************************************
WriteMatrixColumsUserPWToUserPage
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 WriteMatrixColumsUserPWToUserPage (u8 * data)
{
flashc_memcpy (user_page->matrix_user, data, sizeof(user_page->matrix_user), TRUE);
return (TRUE);
}
/*******************************************************************************
ReadMatrixColumsUserPWFromUserPage
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 ReadMatrixColumsUserPWFromUserPage (u8 * data)
{
memcpy (data, (void *) (user_page->matrix_user), sizeof(user_page->matrix_user));
return (TRUE);
}
/*******************************************************************************
WriteMatrixColumsAdminPWFromUserPage
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 WriteMatrixColumsAdminPWFromUserPage (u8 * data)
{
flashc_memcpy (user_page->matrix_admin, data, sizeof(user_page->matrix_admin), TRUE);
return (TRUE);
}
/*******************************************************************************
ReadMatrixColumsAdminPWFromUserPage
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 ReadMatrixColumsAdminPWFromUserPage (u8 * data)
{
memcpy (data, (void *) (user_page->matrix_admin), sizeof(user_page->matrix_admin));
return (TRUE);
}
/*******************************************************************************
WriteStickConfigurationToUserPage
Changes
Date Author Info
03.02.14 RB Change to struct
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 WriteStickConfigurationToUserPage (void)
{
taskENTER_CRITICAL();
// Set actual firmware version
StickConfiguration_st.VersionInfo_au8[0] = VERSION_MAJOR;
StickConfiguration_st.VersionInfo_au8[1] = VERSION_MINOR;
StickConfiguration_st.VersionInfo_au8[2] = 0;
StickConfiguration_st.VersionInfo_au8[3] = INTERNAL_VERSION_NR; // Internal version nr
flashc_memcpy (user_page->stick_configuration, &StickConfiguration_st, sizeof(user_page->stick_configuration), TRUE);
taskEXIT_CRITICAL();
return (TRUE);
}
u8 ReadConfigurationSuccesfull(void) {
if (MAGIC_NUMBER_STICK20_CONFIG != StickConfiguration_st.MagicNumber_StickConfig_u16)
{
return (FALSE);
}
return (TRUE);
}
/*******************************************************************************
ReadStickConfigurationFromUserPage
Changes
Date Author Info
03.02.14 RB Change to struct
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 ReadStickConfigurationFromUserPage (void)
{
// TODO should be mutexed with InitStickConfigurationToUserPage_u8
u8 UserPwRetryCount;
u8 AdminPwRetryCount;
u32 ActiveSmartCardID_u32;
taskENTER_CRITICAL ();
// Save dynamic data
UserPwRetryCount = StickConfiguration_st.UserPwRetryCount;
AdminPwRetryCount = StickConfiguration_st.AdminPwRetryCount;
ActiveSmartCardID_u32 = StickConfiguration_st.ActiveSmartCardID_u32;
memcpy (&StickConfiguration_st, (void *) (user_page->stick_configuration), sizeof (typeStick20Configuration_st));
// Write actual version info
StickConfiguration_st.VersionInfo_au8[0] = VERSION_MAJOR;
StickConfiguration_st.VersionInfo_au8[1] = VERSION_MINOR;
StickConfiguration_st.VersionInfo_au8[2] = 0; // Build number not used
StickConfiguration_st.VersionInfo_au8[3] = INTERNAL_VERSION_NR; // Internal version nr
// Restore dynamic data
StickConfiguration_st.UserPwRetryCount = UserPwRetryCount;
StickConfiguration_st.AdminPwRetryCount = AdminPwRetryCount;
StickConfiguration_st.ActiveSmartCardID_u32 = ActiveSmartCardID_u32;
taskEXIT_CRITICAL();
return ReadConfigurationSuccesfull();
}
/*******************************************************************************
InitStickConfigurationToUserPage_u8
Changes
Date Author Info
03.02.14 RB Function created
Reviews
Date Reviewer Info
*******************************************************************************/
u8 InitStickConfigurationToUserPage_u8 (void)
{
// TODO should be mutexed with ReadStickConfigurationFromUserPage
taskENTER_CRITICAL ();
StickConfiguration_st.MagicNumber_StickConfig_u16 = MAGIC_NUMBER_STICK20_CONFIG;
StickConfiguration_st.ReadWriteFlagUncryptedVolume_u8 = READ_ONLY_ACTIVE;
StickConfiguration_st.ReadWriteFlagCryptedVolume_u8 = READ_WRITE_ACTIVE;
StickConfiguration_st.ReadWriteFlagHiddenVolume_u8 = READ_WRITE_ACTIVE;
StickConfiguration_st.FirmwareLocked_u8 = 0;
StickConfiguration_st.ActiveSD_CardID_u32 = 0;
StickConfiguration_st.VersionInfo_au8[0] = VERSION_MAJOR;
StickConfiguration_st.VersionInfo_au8[1] = VERSION_MINOR;
StickConfiguration_st.VersionInfo_au8[2] = 0; // Build number not used
StickConfiguration_st.VersionInfo_au8[3] = INTERNAL_VERSION_NR; // Internal version nr
StickConfiguration_st.NewSDCardFound_u8 = 0;
StickConfiguration_st.SDFillWithRandomChars_u8 = FALSE;
StickConfiguration_st.VolumeActiceFlag_u8 = 0;
StickConfiguration_st.NewSmartCardFound_u8 = 0;
StickConfiguration_st.ActiveSmartCardID_u32 = 0;
StickConfiguration_st.StickKeysNotInitiated_u8 = TRUE;
WriteStickConfigurationToUserPage ();
InitUpdatePinHashInFlash ();
taskEXIT_CRITICAL();
return (TRUE);
}
/*******************************************************************************
WriteHiddenVolumeSlotKey
Stores the encrypted hidden volume slot key
Byte
Len = 32 Byte
Changes
Date Author Info
14.04.14 RB Renaming
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 WriteHiddenVolumeSlotKey (u8 * data)
{
flashc_memcpy ((void *) (user_page->hidden_volume_AES_key_base), data, sizeof(user_page->hidden_volume_AES_key_base), TRUE);
return (TRUE);
}
/*******************************************************************************
ReadHiddenVolumeSlotsKey
Read the encrypted hidden volume slot key
Changes
Date Author Info
14.04.14 RB Renaming
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
u8 ReadHiddenVolumeSlotsKey (u8 * data)
{
memcpy (data, (void *) (user_page->hidden_volume_AES_key_base), sizeof(user_page->hidden_volume_AES_key_base));
return (TRUE);
}
/*******************************************************************************
SendStickStatusToHID
Changes
Date Author Info
08.02.14 RB Implementation of sending volume status
Reviews
Date Reviewer Info
16.08.13 RB First review
*******************************************************************************/
void SendStickStatusToHID (typeStick20Configuration_st * Status_st)
{
cid_t* cid;
read_configuration_or_init_u8();
memcpy (Status_st, &StickConfiguration_st, sizeof (typeStick20Configuration_st)); // Not the retry counter and sc serial no
// Set the actual volume status
Status_st->VolumeActiceFlag_u8 = 0;
if (TRUE == GetSdUncryptedCardEnableState ())
{
Status_st->VolumeActiceFlag_u8 |= (1 << SD_UNCRYPTED_VOLUME_BIT_PLACE);
}
// Only 1 cypted volume could be active
if (TRUE == GetSdEncryptedCardEnableState ())
{
if (TRUE == GetSdEncryptedHiddenState ())
{
Status_st->VolumeActiceFlag_u8 |= (1 << SD_HIDDEN_VOLUME_BIT_PLACE);
}
else
{
Status_st->VolumeActiceFlag_u8 |= (1 << SD_CRYPTED_VOLUME_BIT_PLACE);
}
}
// Read actual SD id
cid = (cid_t *) GetSdCidInfo ();
Status_st->ActiveSD_CardID_u32 = (cid->psnh << 8) + cid->psnl;
// ReadSdId (&Status_st->ActiveSD_CardID_u32);
Status_st->FirmwareLocked_u8 = FALSE;
if (TRUE == flashc_is_security_bit_active ())
{
Status_st->FirmwareLocked_u8 = TRUE;
}
}
/*******************************************************************************
Read_ReadWriteStatusEncryptedVolume_u8
Changes
Date Author Info
11.12.17 RB Function created
Reviews
Date Reviewer Info
*******************************************************************************/
u8 read_configuration_or_init_u8(void){
taskENTER_CRITICAL();
if (TRUE == ReadConfigurationSuccesfull()){
goto read_configuration_or_init_u8_exit;
}
// If configuration not found then init it
if (FALSE == ReadStickConfigurationFromUserPage ())
{
InitStickConfigurationToUserPage_u8 ();
}
read_configuration_or_init_u8_exit:
taskEXIT_CRITICAL();
return 0;
}
u8 Read_ReadWriteStatusEncryptedVolume_u8 (void)
{
read_configuration_or_init_u8();
return (StickConfiguration_st.ReadWriteFlagCryptedVolume_u8);
}
/*******************************************************************************
Write_ReadWriteStatusEncryptedVolume_u8
Changes
Date Author Info
11.12.17 RB Function created
Reviews
Date Reviewer Info
*******************************************************************************/
u8 Write_ReadWriteStatusEncryptedVolume_u8 (u8 NewStatus_u8)
{
read_configuration_or_init_u8();
StickConfiguration_st.ReadWriteFlagCryptedVolume_u8 = NewStatus_u8;
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
Read_ReadWriteStatusUncryptedVolume_u8
Changes
Date Author Info
03.02.14 RB Function created
Reviews
Date Reviewer Info
*******************************************************************************/
u8 Read_ReadWriteStatusUncryptedVolume_u8 (void)
{
read_configuration_or_init_u8();
return (StickConfiguration_st.ReadWriteFlagUncryptedVolume_u8);
}
/*******************************************************************************
Write_ReadWriteStatusUncryptedVolume_u8
Changes
Date Author Info
03.02.14 RB Function created
Reviews
Date Reviewer Info
*******************************************************************************/
u8 Write_ReadWriteStatusUncryptedVolume_u8 (u8 NewStatus_u8)
{
read_configuration_or_init_u8();
StickConfiguration_st.ReadWriteFlagUncryptedVolume_u8 = NewStatus_u8;
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
WriteSdId
Changes
Date Author Info
08.02.14 RB Implementation of save SD id in CPU flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 WriteSdId (u32 * SdId_u32)
{
flashc_memcpy (user_page->sdcard_id, SdId_u32, sizeof(user_page->sdcard_id), TRUE);
StickConfiguration_st.ActiveSD_CardID_u32 = *SdId_u32;
return (TRUE);
}
/*******************************************************************************
ReadSdId
Changes
Date Author Info
08.02.14 RB Implementation of save SD id in CPU flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 ReadSdId (u32 * SdId_u32)
{
memcpy (SdId_u32, (void *) (user_page->sdcard_id), sizeof(user_page->sdcard_id));
StickConfiguration_st.ActiveSD_CardID_u32 = *SdId_u32;
return (TRUE);
}
/*******************************************************************************
WriteNewSdCardFoundToFlash
NewSDCardFound_u8
Bit 0 = 0 New SD card found
Bit 0 = 1 Previous SD card found
SDFillWithRandomChars_u8
Bit 0 = 0 SD card is *** not *** filled with random chars
Bit 0 = 1 SD card is filled with random chars
Changes
Date Author Info
08.02.14 RB Implementation of save new SD card found
Reviews
Date Reviewer Info
*******************************************************************************/
u8 WriteNewSdCardFoundToFlash (u32 * SdId_u32)
{
read_configuration_or_init_u8();
CI_LocalPrintf ("*** New SD card found *** Serial number 0x%08x\r\n", *SdId_u32);
WriteSdId (SdId_u32);
StickConfiguration_st.NewSDCardFound_u8 |= 0x01; // Bit 0 = new card found
// StickConfiguration_st.NewSDCardFound_u8 += 2; // add change counter +1
StickConfiguration_st.SDFillWithRandomChars_u8 &= 0xFE; // Clear the "card with random chars filled" bit
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
SetSdCardFilledWithRandomsToFlash
Changes
Date Author Info
10.02.14 RB Implementation: New SD card found
Reviews
Date Reviewer Info
*******************************************************************************/
u8 SetSdCardFilledWithRandomsToFlash (void)
{
read_configuration_or_init_u8();
CI_LocalPrintf ("SD is filled with random chars\r\n");
StickConfiguration_st.SDFillWithRandomChars_u8 |= 0x01; // Set the "SD card filled with randoms" bit
// StickConfiguration_st.SDFillWithRandomChars_u8 += 2; // add counter +1
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
ClearNewSdCardFoundToFlash
Changes
Date Author Info
08.02.14 RB Implementation of clear new SD card found
Reviews
Date Reviewer Info
*******************************************************************************/
u8 ClearNewSdCardFoundToFlash (void)
{
read_configuration_or_init_u8();
CI_LocalPrintf ("Clear new SD card found\r\n");
StickConfiguration_st.NewSDCardFound_u8 &= 0xFE; // Clear the "new SD card found" bit
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
SetSdCardFilledWithRandomCharsToFlash
Changes
Date Author Info
06.05.14 RB Implementation of clear new SD card found
Reviews
Date Reviewer Info
*******************************************************************************/
u8 SetSdCardFilledWithRandomCharsToFlash (void)
{
read_configuration_or_init_u8();
CI_LocalPrintf ("Set new SD card filled with random chars\r\n");
StickConfiguration_st.SDFillWithRandomChars_u8 |= 0x01; // Set the "SD card filled with randoms" bit
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
SetSdCardNotFilledWithRandomCharsToFlash
Bit 0 = 0 SD card is *** not *** filled with random chars
Bit 0 = 1 SD card is filled with random chars
Changes
Date Author Info
06.05.14 RB Implementation of clear new SD card found
Reviews
Date Reviewer Info
*******************************************************************************/
u8 SetSdCardNotFilledWithRandomCharsToFlash (void)
{
read_configuration_or_init_u8();
CI_LocalPrintf ("Set new SD card *** not *** filled with random chars\r\n");
StickConfiguration_st.SDFillWithRandomChars_u8 &= 0xFE; // Clear the "card with random chars filled" bit
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
SetStickKeysNotInitatedToFlash
Changes
Date Author Info
05.05.14 RB Implementation of clear new SD card found
Reviews
Date Reviewer Info
*******************************************************************************/
u8 SetStickKeysNotInitatedToFlash (void)
{
read_configuration_or_init_u8();
CI_LocalPrintf ("Set stick keys not initiated\r\n");
StickConfiguration_st.StickKeysNotInitiated_u8 = TRUE;
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
ClearStickKeysNotInitatedToFlash
Changes
Date Author Info
05.05.14 RB Implementation of clear new SD card found
Reviews
Date Reviewer Info
*******************************************************************************/
u8 ClearStickKeysNotInitatedToFlash (void)
{
read_configuration_or_init_u8();
CI_LocalPrintf ("Clear: Stick keys not initiated\r\n");
StickConfiguration_st.StickKeysNotInitiated_u8 = FALSE;
WriteStickConfigurationToUserPage ();
return (TRUE);
}
/*******************************************************************************
CheckForNewFirmwareVersion
Changes
Date Author Info
05.07.14 RB Implementation
Reviews
Date Reviewer Info
*******************************************************************************/
u8 CheckForNewFirmwareVersion (void)
{
static u8 UpdateFlag_u8 = FALSE;
u8 update_u8;
if (TRUE == UpdateFlag_u8)
{
return (TRUE);
}
UpdateFlag_u8 = TRUE; // Run only once
read_configuration_or_init_u8();
update_u8 = FALSE;
if (VERSION_MAJOR != StickConfiguration_st.VersionInfo_au8[0])
{
update_u8 = TRUE;
}
if (VERSION_MINOR != StickConfiguration_st.VersionInfo_au8[1])
{
update_u8 = TRUE;
}
/*
StickConfiguration_st.VersionInfo_au8[2] = 0; // Build number not used StickConfiguration_st.VersionInfo_au8[3] = 0; // Build number not used */
if (TRUE == update_u8)
{
WriteStickConfigurationToUserPage ();
}
return (TRUE);
}
/*******************************************************************************
WriteDatetime
Changes
Date Author Info
08.02.14 RB Implementation of save datetime in flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 WriteDatetime (u32 Datetime_u32)
{
flashc_memcpy (user_page->last_timestamp_real, &Datetime_u32, sizeof(user_page->last_timestamp_real), TRUE);
return (TRUE);
}
/*******************************************************************************
ReadDatetime
Changes
Date Author Info
08.02.14 RB Implementation of read datetime in flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 ReadDatetime (u32 * Datetime_u32)
{
memcpy (Datetime_u32, (void *) (user_page->last_timestamp_real), sizeof(user_page->last_timestamp_real));
return (TRUE);
}
/*******************************************************************************
WriteScId
Changes
Date Author Info
20.05.14 RB Implementation of save SC id in CPU flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 WriteScId (u32 * ScId_u32)
{
flashc_memcpy (user_page->sccard_id, ScId_u32, sizeof(user_page->sccard_id), TRUE);
StickConfiguration_st.ActiveSmartCardID_u32 = *ScId_u32;
return (TRUE);
}
/*******************************************************************************
ReadSdId
Changes
Date Author Info
20.05.14 RB Implementation of save SC id in CPU flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 ReadScId (u32 * ScId_u32)
{
memcpy (ScId_u32, (void *) (user_page->sccard_id), sizeof(user_page->sccard_id));
StickConfiguration_st.ActiveSmartCardID_u32 = *ScId_u32;
return (TRUE);
}
/*******************************************************************************
WriteXorPatternToFlash
Changes
Date Author Info
20.05.14 RB Implementation of save xor pattern to flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 WriteXorPatternToFlash (u8 * XorPattern_pu8)
{
flashc_memcpy (user_page->xor_mask_for_SC_keys, XorPattern_pu8, sizeof(user_page->xor_mask_for_SC_keys), TRUE);
return (TRUE);
}
/*******************************************************************************
ReadXorPatternFromFlash
Changes
Date Author Info
20.05.14 RB Implementation of read xor pattern from flash
Reviews
Date Reviewer Info
*******************************************************************************/
u8 ReadXorPatternFromFlash (u8 * XorPattern_pu8)
{
memcpy (XorPattern_pu8, (void *) (user_page->xor_mask_for_SC_keys), sizeof(user_page->xor_mask_for_SC_keys));
return (TRUE);
}
/*******************************************************************************
WritePasswordSafeKey
Stores the encrypted password safe key
Byte
Len = 32 Byte
Changes
Date Author Info
01.08.14 RB Renaming