1
+ /**
2
+ * \file atecc608a_utils.c
3
+ * \brief ATECC508A and ATECC509A utility functions.
4
+ */
5
+
6
+ /*
7
+ * Copyright (C) 2019, ARM Limited, All Rights Reserved
8
+ * SPDX-License-Identifier: Apache-2.0
9
+ *
10
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
11
+ * not use this file except in compliance with the License.
12
+ * You may obtain a copy of the License at
13
+ *
14
+ * http://www.apache.org/licenses/LICENSE-2.0
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
18
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ #include "atecc608a_se.h"
23
+ #include "atecc608a_utils.h"
24
+
25
+ #include "atca_basic.h"
26
+
27
+ ATCAIfaceCfg atca_iface_config = {
28
+ .iface_type = ATCA_I2C_IFACE ,
29
+ .devtype = ATECC608A ,
30
+ .atcai2c .slave_address = 0xC0 ,
31
+ .atcai2c .bus = 2 ,
32
+ .atcai2c .baud = 400000 ,
33
+ .wake_delay = 1500 ,
34
+ .rx_retries = 20 ,
35
+ };
36
+
37
+ psa_status_t atecc608a_to_psa_error (ATCA_STATUS ret )
38
+ {
39
+ switch (ret )
40
+ {
41
+ case ATCA_SUCCESS :
42
+ case ATCA_RX_NO_RESPONSE :
43
+ case ATCA_WAKE_SUCCESS :
44
+ return PSA_SUCCESS ;
45
+ case ATCA_BAD_PARAM :
46
+ case ATCA_INVALID_ID :
47
+ return PSA_ERROR_INVALID_ARGUMENT ;
48
+ case ATCA_ASSERT_FAILURE :
49
+ return PSA_ERROR_TAMPERING_DETECTED ;
50
+ case ATCA_SMALL_BUFFER :
51
+ return PSA_ERROR_BUFFER_TOO_SMALL ;
52
+ case ATCA_RX_CRC_ERROR :
53
+ case ATCA_RX_FAIL :
54
+ case ATCA_STATUS_CRC :
55
+ case ATCA_RESYNC_WITH_WAKEUP :
56
+ case ATCA_PARITY_ERROR :
57
+ case ATCA_TX_TIMEOUT :
58
+ case ATCA_RX_TIMEOUT :
59
+ case ATCA_TOO_MANY_COMM_RETRIES :
60
+ case ATCA_COMM_FAIL :
61
+ case ATCA_TIMEOUT :
62
+ case ATCA_TX_FAIL :
63
+ case ATCA_NO_DEVICES :
64
+ return PSA_ERROR_COMMUNICATION_FAILURE ;
65
+ case ATCA_UNIMPLEMENTED :
66
+ return PSA_ERROR_NOT_SUPPORTED ;
67
+ case ATCA_ALLOC_FAILURE :
68
+ return PSA_ERROR_INSUFFICIENT_MEMORY ;
69
+ case ATCA_BAD_OPCODE :
70
+ case ATCA_CONFIG_ZONE_LOCKED :
71
+ case ATCA_DATA_ZONE_LOCKED :
72
+ case ATCA_NOT_LOCKED :
73
+ case ATCA_WAKE_FAILED :
74
+ case ATCA_STATUS_UNKNOWN :
75
+ case ATCA_STATUS_ECC :
76
+ case ATCA_STATUS_SELFTEST_ERROR :
77
+ case ATCA_CHECKMAC_VERIFY_FAILED :
78
+ case ATCA_PARSE_ERROR :
79
+ case ATCA_FUNC_FAIL :
80
+ case ATCA_GEN_FAIL :
81
+ case ATCA_EXECUTION_ERROR :
82
+ case ATCA_HEALTH_TEST_ERROR :
83
+ case ATCA_INVALID_SIZE :
84
+ default :
85
+ return PSA_ERROR_HARDWARE_FAILURE ;
86
+ }
87
+ }
88
+
89
+ psa_status_t atecc608a_get_serial_number (uint8_t * buffer ,
90
+ size_t buffer_size ,
91
+ size_t * buffer_length )
92
+ {
93
+ psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
94
+
95
+ if (buffer_size < ATCA_SERIAL_NUM_SIZE )
96
+ {
97
+ return PSA_ERROR_BUFFER_TOO_SMALL ;
98
+ }
99
+
100
+ ATCAB_INIT ();
101
+
102
+ ASSERT_SUCCESS (atcab_read_serial_number (buffer ));
103
+ * buffer_length = ATCA_SERIAL_NUM_SIZE ;
104
+
105
+ exit :
106
+ ATCAB_DEINIT ();
107
+ return status ;
108
+ }
109
+
110
+ psa_status_t atecc608a_check_config_locked ()
111
+ {
112
+ bool config_locked ;
113
+ psa_status_t status = PSA_ERROR_GENERIC_ERROR ;
114
+
115
+ ATCAB_INIT ();
116
+
117
+ ASSERT_SUCCESS (atcab_is_locked (LOCK_ZONE_CONFIG , & config_locked ));
118
+
119
+ exit :
120
+ ATCAB_DEINIT ();
121
+ if (status == PSA_SUCCESS )
122
+ {
123
+ status = config_locked ? PSA_SUCCESS : PSA_ERROR_HARDWARE_FAILURE ;
124
+ }
125
+ return status ;
126
+ }
0 commit comments