diff options
Diffstat (limited to 'firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c')
-rw-r--r-- | firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c b/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c new file mode 100644 index 0000000000..ac01525500 --- /dev/null +++ b/firmware/target/arm/tms320dm320/sansa-connect/cryptomem-sansaconnect.c | |||
@@ -0,0 +1,80 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: $ | ||
9 | * | ||
10 | * Copyright (C) 2021 by Tomasz Moń | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <ctype.h> | ||
23 | #include "cryptomem-sansaconnect.h" | ||
24 | #include "i2c-dm320.h" | ||
25 | |||
26 | /* Command values */ | ||
27 | #define WRITE_USER_ZONE 0xB0 | ||
28 | #define READ_USER_ZONE 0xB2 | ||
29 | #define SYSTEM_WRITE 0xB4 | ||
30 | #define SYSTEM_READ 0xB6 | ||
31 | #define VERIFY_CRYPTO 0xB8 | ||
32 | #define VERIFY_PASSWORD 0xBA | ||
33 | |||
34 | /* SYSTEM_WRITE ADDR 1 values */ | ||
35 | #define WRITE_CONFIG 0x00 | ||
36 | #define WRITE_FUSES 0x01 | ||
37 | #define SEND_CHECKSUM 0x02 | ||
38 | #define SET_USER_ZONE 0x03 | ||
39 | |||
40 | int cryptomem_read_deviceid(char deviceid[32]) | ||
41 | { | ||
42 | int ret; | ||
43 | unsigned int i; | ||
44 | unsigned char cmd_data[3]; | ||
45 | |||
46 | /* It is assumed that other I2C communication has already taken place | ||
47 | * (e.g. power_init()) before this function is called and thus we don't | ||
48 | * have to send atleast 5 dummy clock cycles here. | ||
49 | */ | ||
50 | |||
51 | cmd_data[0] = SET_USER_ZONE; | ||
52 | cmd_data[1] = 0; | ||
53 | cmd_data[2] = 0; | ||
54 | ret = i2c_write(SYSTEM_WRITE, cmd_data, sizeof(cmd_data)); | ||
55 | if (ret < 0) | ||
56 | { | ||
57 | return ret; | ||
58 | } | ||
59 | |||
60 | cmd_data[0] = 0; | ||
61 | cmd_data[1] = 0; | ||
62 | cmd_data[2] = 32; | ||
63 | ret = i2c_write_read_bytes(READ_USER_ZONE, cmd_data, sizeof(cmd_data), | ||
64 | deviceid, 32); | ||
65 | if (ret < 0) | ||
66 | { | ||
67 | return ret; | ||
68 | } | ||
69 | |||
70 | /* Verify that deviceid contains only printable ASCII characters */ | ||
71 | for (i = 0; i < 32; i++) | ||
72 | { | ||
73 | if (!isprint(deviceid[i])) | ||
74 | { | ||
75 | return -1; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | return 0; | ||
80 | } | ||