plugntrust  2.0.0.0
plugntrust.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef PLUGNTRUST_H
29 #define PLUGNTRUST_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_i2c_master.h"
48 
70 #define PLUGNTRUST_NAD_WRITE 0x5A
71 #define PLUGNTRUST_NAD_READ 0xA5
72 
78 #define PLUGNTRUST_PCB_BLOCK_I 0x00
79 #define PLUGNTRUST_PCB_BLOCK_I_NS_ENCODE 0x40
80 #define PLUGNTRUST_PCB_BLOCK_I_M_CHAIN 0x20
81 
87 #define PLUGNTRUST_PCB_BLOCK_R 0x80
88 #define PLUGNTRUST_PCB_BLOCK_R_NR_ENCODE 0x10
89 #define PLUGNTRUST_PCB_BLOCK_R_ERROR_CRC 0x01
90 #define PLUGNTRUST_PCB_BLOCK_R_ERROR_OTHER 0x02
91 
97 #define PLUGNTRUST_PCB_BLOCK_S 0xC0
98 #define PLUGNTRUST_PCB_BLOCK_S_RESYNC_REQ 0x00
99 #define PLUGNTRUST_PCB_BLOCK_S_RESYNC_RSP 0x20
100 #define PLUGNTRUST_PCB_BLOCK_S_IFS_REQ 0x01
101 #define PLUGNTRUST_PCB_BLOCK_S_IFS_RSP 0x21
102 #define PLUGNTRUST_PCB_BLOCK_S_ABORT_REQ 0x02
103 #define PLUGNTRUST_PCB_BLOCK_S_ABORT_RSP 0x22
104 #define PLUGNTRUST_PCB_BLOCK_S_WTX_REQ 0x03
105 #define PLUGNTRUST_PCB_BLOCK_S_WTX_RSP 0x23
106 #define PLUGNTRUST_PCB_BLOCK_S_SOFT_RESET_REQ 0x0F
107 #define PLUGNTRUST_PCB_BLOCK_S_SOFT_RESET_RSP 0x2F
108 #define PLUGNTRUST_PCB_BLOCK_S_END_APDU_SESSION_REQ 0x05
109 #define PLUGNTRUST_PCB_BLOCK_S_END_APDU_SESSION_RSP 0x25
110 #define PLUGNTRUST_PCB_BLOCK_S_SE_RESET_REQ 0x06
111 #define PLUGNTRUST_PCB_BLOCK_S_SE_RESET_RSP 0x26
112 #define PLUGNTRUST_PCB_BLOCK_S_GET_ATR_REQ 0x07
113 #define PLUGNTRUST_PCB_BLOCK_S_GET_ATR_RSP 0x27
114  // pcb
116 
117 
132 #define PLUGNTRUST_CLA_SECURE 0x84
133 #define PLUGNTRUST_CLA_NOT_SECURE 0x80
134 
139 #define PLUGNTRUST_INS_MASK_INS_CHAR 0xE0
140 #define PLUGNTRUST_INS_MASK_INSTRUCTION 0x1F
141 #define PLUGNTRUST_INS_TRANSIENT 0x80
142 #define PLUGNTRUST_INS_AUTH_OBJECT 0x40
143 #define PLUGNTRUST_INS_ATTEST 0x20
144 #define PLUGNTRUST_INS_WRITE 0x01
145 #define PLUGNTRUST_INS_READ 0x02
146 #define PLUGNTRUST_INS_CRYPTO 0x03
147 #define PLUGNTRUST_INS_MGMT 0x04
148 #define PLUGNTRUST_INS_PROCESS 0x05
149 #define PLUGNTRUST_INS_IMPORT_EXTERNAL 0x06
150 
155 #define PLUGNTRUST_P1_UNUSED 0x80
156 #define PLUGNTRUST_P1_MASK_KEY_TYPE 0x60
157 #define PLUGNTRUST_P1_MASK_CRED_TYPE 0x1F
158 #define PLUGNTRUST_P1_KEY_PAIR 0x60
159 #define PLUGNTRUST_P1_PRIVATE 0x40
160 #define PLUGNTRUST_P1_PUBLIC 0x20
161 #define PLUGNTRUST_P1_DEFAULT 0x00
162 #define PLUGNTRUST_P1_EC 0x01
163 #define PLUGNTRUST_P1_RSA 0x02
164 #define PLUGNTRUST_P1_AES 0x03
165 #define PLUGNTRUST_P1_DES 0x04
166 #define PLUGNTRUST_P1_HMAC 0x05
167 #define PLUGNTRUST_P1_BINARY 0x06
168 #define PLUGNTRUST_P1_USERID 0x07
169 #define PLUGNTRUST_P1_COUNTER 0x08
170 #define PLUGNTRUST_P1_PCR 0x09
171 #define PLUGNTRUST_P1_CURVE 0x0B
172 #define PLUGNTRUST_P1_SIGNATURE 0x0C
173 #define PLUGNTRUST_P1_MAC 0x0D
174 #define PLUGNTRUST_P1_CIPHER 0x0E
175 #define PLUGNTRUST_P1_TLS 0x0F
176 #define PLUGNTRUST_P1_CRYPTO_OBJ 0x10
177 
178 #define PLUGNTRUST_P2_DEFAULT 0x00
179 #define PLUGNTRUST_P2_GENERATE 0x03
180 #define PLUGNTRUST_P2_CREATE 0x04
181 #define PLUGNTRUST_P2_SIZE 0x07
182 #define PLUGNTRUST_P2_SIGN 0x09
183 #define PLUGNTRUST_P2_VERIFY 0x0A
184 #define PLUGNTRUST_P2_INIT 0x0B
185 #define PLUGNTRUST_P2_UPDATE 0x0C
186 #define PLUGNTRUST_P2_FINAL 0x0D
187 #define PLUGNTRUST_P2_ONESHOT 0x0E
188 #define PLUGNTRUST_P2_DH 0x0F
189 #define PLUGNTRUST_P2_DIVERSIFY 0x10
190 #define PLUGNTRUST_P2_AUTH_FIRST_PART2 0x12
191 #define PLUGNTRUST_P2_AUTH_NONFIRST_PART2 0x13
192 #define PLUGNTRUST_P2_DUMP_KEY 0x14
193 #define PLUGNTRUST_P2_CHANGE_KEY_PART1 0x15
194 #define PLUGNTRUST_P2_CHANGE_KEY_PART2 0x16
195 #define PLUGNTRUST_P2_KILL_AUTH 0x17
196 #define PLUGNTRUST_P2_IMPORT 0x18
197 #define PLUGNTRUST_P2_EXPORT 0x19
198 #define PLUGNTRUST_P2_SESSION_CREATE 0x1B
199 #define PLUGNTRUST_P2_SESSION_CLOSE 0x1C
200 #define PLUGNTRUST_P2_SESSION_REFRESH 0x1E
201 #define PLUGNTRUST_P2_SESSION_POLICY 0x1F
202 #define PLUGNTRUST_P2_VERSION 0x20
203 #define PLUGNTRUST_P2_MEMORY 0x22
204 #define PLUGNTRUST_P2_LIST 0x25
205 #define PLUGNTRUST_P2_TYPE 0x26
206 #define PLUGNTRUST_P2_EXIST 0x27
207 #define PLUGNTRUST_P2_DELETE_OBJECT 0x28
208 #define PLUGNTRUST_P2_DELETE_ALL 0x2A
209 #define PLUGNTRUST_P2_SESSION_USERID 0x2C
210 #define PLUGNTRUST_P2_HKDF 0x2D
211 #define PLUGNTRUST_P2_PBKDF 0x2E
212 #define PLUGNTRUST_P2_I2CM 0x30
213 #define PLUGNTRUST_P2_I2CM_ATTESTED 0x31
214 #define PLUGNTRUST_P2_MAC 0x32
215 #define PLUGNTRUST_P2_UNLOCK_CHALLENGE 0x33
216 #define PLUGNTRUST_P2_CURVE_LIST 0x34
217 #define PLUGNTRUST_P2_SIGN_ECDAA 0x35
218 #define PLUGNTRUST_P2_ID 0x36
219 #define PLUGNTRUST_P2_ENCRYPT_ONESHOT 0x37
220 #define PLUGNTRUST_P2_DECRYPT_ONESHOT 0x38
221 #define PLUGNTRUST_P2_ATTEST 0x3A
222 #define PLUGNTRUST_P2_ATTRIBUTES 0x3B
223 #define PLUGNTRUST_P2_CPLC 0x3C
224 #define PLUGNTRUST_P2_TIME 0x3D
225 #define PLUGNTRUST_P2_TRANSPORT 0x3E
226 #define PLUGNTRUST_P2_VARIANT 0x3F
227 #define PLUGNTRUST_P2_PARAM 0x40
228 #define PLUGNTRUST_P2_DELETE_CURVE 0x41
229 #define PLUGNTRUST_P2_ENCRYPT 0x42
230 #define PLUGNTRUST_P2_DECRYPT 0x43
231 #define PLUGNTRUST_P2_VALIDATE 0x44
232 #define PLUGNTRUST_P2_GENERATE_ONESHOT 0x45
233 #define PLUGNTRUST_P2_VALIDATE_ONESHOT 0x46
234 #define PLUGNTRUST_P2_CRYPTO_LIST 0x47
235 #define PLUGNTRUST_P2_RANDOM 0x49
236 #define PLUGNTRUST_P2_TLS_PMS 0x4A
237 #define PLUGNTRUST_P2_TLS_PRF_CLI_HELLO 0x4B
238 #define PLUGNTRUST_P2_TLS_PRF_SRV_HELLO 0x4C
239 #define PLUGNTRUST_P2_TLS_PRF_CLI_RND 0x4D
240 #define PLUGNTRUST_P2_TLS_PRF_SRV_RND 0x4E
241 #define PLUGNTRUST_P2_RAW 0x4F
242 #define PLUGNTRUST_P2_IMPORT_EXT 0x51
243 #define PLUGNTRUST_P2_SCP 0x52
244 #define PLUGNTRUST_P2_AUTH_FIRST_PART1 0x53
245 #define PLUGNTRUST_P2_AUTH_NONFIRST_PART1 0x54
246 
251 #define PLUGNTRUST_SECURE_OBJECT_TYPE_EC_KEY_PAIR 0x01
252 #define PLUGNTRUST_SECURE_OBJECT_TYPE_EC_PRIV_KEY 0x02
253 #define PLUGNTRUST_SECURE_OBJECT_TYPE_EC_PUB_KEY 0x03
254 #define PLUGNTRUST_SECURE_OBJECT_TYPE_RSA_KEY_PAIR 0x04
255 #define PLUGNTRUST_SECURE_OBJECT_TYPE_RSA_KEY_PAIR_CRT 0x05
256 #define PLUGNTRUST_SECURE_OBJECT_TYPE_RSA_PRIV_KEY 0x06
257 #define PLUGNTRUST_SECURE_OBJECT_TYPE_RSA_PRIV_KEY_CRT 0x07
258 #define PLUGNTRUST_SECURE_OBJECT_TYPE_RSA_PUB_KEY 0x08
259 #define PLUGNTRUST_SECURE_OBJECT_TYPE_AES_KEY 0x09
260 #define PLUGNTRUST_SECURE_OBJECT_TYPE_DES_KEY 0x0A
261 #define PLUGNTRUST_SECURE_OBJECT_TYPE_BINARY_FILE 0x0B
262 #define PLUGNTRUST_SECURE_OBJECT_TYPE_USERID 0x0C
263 #define PLUGNTRUST_SECURE_OBJECT_TYPE_COUNTER 0x0D
264 #define PLUGNTRUST_SECURE_OBJECT_TYPE_PCR 0x0F
265 #define PLUGNTRUST_SECURE_OBJECT_TYPE_CURVE 0x10
266 #define PLUGNTRUST_SECURE_OBJECT_TYPE_HMAC_KEY 0x11
267 
272 #define PLUGNTRUST_MEM_PERSISTENT 0x01
273 #define PLUGNTRUST_MEM_TRANSIENT_RESET 0x02
274 #define PLUGNTRUST_MEM_TRANSIENT_DESELECT 0x03
275 
280 #define PLUGNTRUST_ORIGIN_EXTERNAL 0x01
281 #define PLUGNTRUST_ORIGIN_INTERNAL 0x02
282 #define PLUGNTRUST_ORIGIN_PROVISIONED 0x03
283 
288 #define PLUGNTRUST_TLV_TAG_SESSION_ID 0x10
289 #define PLUGNTRUST_TLV_TAG_POLICY 0x11
290 #define PLUGNTRUST_TLV_TAG_MAX_ATTEMPTS 0x12
291 #define PLUGNTRUST_TLV_TAG_IMPORT_AUTH_DATA 0x13
292 #define PLUGNTRUST_TLV_TAG_IMPORT_AUTH_KEY_ID 0x14
293 #define PLUGNTRUST_TLV_TAG_1 0x41
294 #define PLUGNTRUST_TLV_TAG_2 0x42
295 #define PLUGNTRUST_TLV_TAG_3 0x43
296 #define PLUGNTRUST_TLV_TAG_4 0x44
297 #define PLUGNTRUST_TLV_TAG_5 0x45
298 #define PLUGNTRUST_TLV_TAG_6 0x46
299 #define PLUGNTRUST_TLV_TAG_7 0x47
300 #define PLUGNTRUST_TLV_TAG_8 0x48
301 #define PLUGNTRUST_TLV_TAG_9 0x49
302 #define PLUGNTRUST_TLV_TAG_10 0x4A
303 
308 #define PLUGNTRUST_ECS_SIG_ECDSA_PLAIN 0x09
309 #define PLUGNTRUST_ECS_SIG_ECDSA_SHA 0x11
310 #define PLUGNTRUST_ECS_SIG_ECDSA_SHA_224 0x25
311 #define PLUGNTRUST_ECS_SIG_ECDSA_SHA_256 0x21
312 #define PLUGNTRUST_ECS_SIG_ECDSA_SHA_384 0x22
313 #define PLUGNTRUST_ECS_SIG_ECDSA_SHA_512 0x26
314 #define PLUGNTRUST_ECS_SIG_ED25519PH_SHA_512 0xA3
315 #define PLUGNTRUST_ECS_SIG_ECDAA 0xF4
316 
321 #define PLUGNTRUST_RSA_SHA1_PKCS1_PSS 0x15
322 #define PLUGNTRUST_RSA_SHA224_PKCS1_PSS 0x2B
323 #define PLUGNTRUST_RSA_SHA256_PKCS1_PSS 0x2C
324 #define PLUGNTRUST_RSA_SHA384_PKCS1_PSS 0x2D
325 #define PLUGNTRUST_RSA_SHA512_PKCS1_PSS 0x2E
326 #define PLUGNTRUST_RSA_SHA1_PKCS1 0x0A
327 #define PLUGNTRUST_RSA_SHA_224_PKCS1 0x27
328 #define PLUGNTRUST_RSA_SHA_256_PKCS1 0x28
329 #define PLUGNTRUST_RSA_SHA_384_PKCS1 0x29
330 #define PLUGNTRUST_RSA_SHA_512_PKCS1 0x2A
331 #define PLUGNTRUST_RSA_NO_PAD 0x0C
332 #define PLUGNTRUST_RSA_PKCS1 0x0A
333 #define PLUGNTRUST_RSA_PKCS1_OAEP 0x0F
334 #define PLUGNTRUST_RSA_512 512
335 #define PLUGNTRUST_RSA_1024 1024
336 #define PLUGNTRUST_RSA_1152 1152
337 #define PLUGNTRUST_RSA_2048 2048
338 #define PLUGNTRUST_RSA_3072 3072
339 #define PLUGNTRUST_RSA_4096 4096
340 #define PLUGNTRUST_RSA_COMP_MOD 0x00
341 #define PLUGNTRUST_RSA_COMP_PUB_EXP 0x01
342 #define PLUGNTRUST_RSA_COMP_PRIV_EXP 0x02
343 #define PLUGNTRUST_RSA_COMP_P 0x03
344 #define PLUGNTRUST_RSA_COMP_Q 0x04
345 #define PLUGNTRUST_RSA_COMP_DP 0x05
346 #define PLUGNTRUST_RSA_COMP_DQ 0x06
347 #define PLUGNTRUST_RSA_COMP_INVQ 0x07
348 
353 #define PLUGNTRUST_DIGEST_NO_HASH 0x00
354 #define PLUGNTRUST_DIGEST_SHA 0x01
355 #define PLUGNTRUST_DIGEST_SHA224 0x07
356 #define PLUGNTRUST_DIGEST_SHA256 0x04
357 #define PLUGNTRUST_DIGEST_SHA384 0x05
358 #define PLUGNTRUST_DIGEST_SHA512 0x06
359 
364 #define PLUGNTRUST_HMAC_SHA1 0x18
365 #define PLUGNTRUST_HMAC_SHA256 0x19
366 #define PLUGNTRUST_HMAC_SHA384 0x1A
367 #define PLUGNTRUST_HMAC_SHA512 0x1B
368 #define PLUGNTRUST_CMAC_128 0x31
369 
374 #define PLUGNTRUST_ECC_UNUSED 0x00
375 #define PLUGNTRUST_ECC_NIST_P192 0x01
376 #define PLUGNTRUST_ECC_NIST_P224 0x02
377 #define PLUGNTRUST_ECC_NIST_P256 0x03
378 #define PLUGNTRUST_ECC_NIST_P384 0x04
379 #define PLUGNTRUST_ECC_NIST_P521 0x05
380 #define PLUGNTRUST_ECC_Brainpool160 0x06
381 #define PLUGNTRUST_ECC_Brainpool192 0x07
382 #define PLUGNTRUST_ECC_Brainpool224 0x08
383 #define PLUGNTRUST_ECC_Brainpool256 0x09
384 #define PLUGNTRUST_ECC_Brainpool320 0x0A
385 #define PLUGNTRUST_ECC_Brainpool384 0x0B
386 #define PLUGNTRUST_ECC_Brainpool512 0x0C
387 #define PLUGNTRUST_ECC_Secp160k1 0x0D
388 #define PLUGNTRUST_ECC_Secp192k1 0x0E
389 #define PLUGNTRUST_ECC_Secp224k1 0x0F
390 #define PLUGNTRUST_ECC_Secp256k1 0x10
391 #define PLUGNTRUST_ECC_TPM_ECC_BN_P256 0x11
392 #define PLUGNTRUST_ECC_ID_ECC_ED_25519 0x40
393 #define PLUGNTRUST_ECC_ID_ECC_MONT_DH_25519 0x41
394 #define PLUGNTRUST_ECC_CURVE_PARAM_A 0x01
395 #define PLUGNTRUST_ECC_CURVE_PARAM_B 0x02
396 #define PLUGNTRUST_ECC_CURVE_PARAM_G 0x04
397 #define PLUGNTRUST_ECC_CURVE_PARAM_N 0x08
398 #define PLUGNTRUST_ECC_CURVE_PARAM_PRIME 0x10
399 
404 #define PLUGNTRUST_CIPHER_DES_CBC_NOPAD 0x01
405 #define PLUGNTRUST_CIPHER_DES_CBC_ISO9797_M1 0x02
406 #define PLUGNTRUST_CIPHER_DES_CBC_ISO9797_M2 0x03
407 #define PLUGNTRUST_CIPHER_DES_CBC_PKCS5 0x04
408 #define PLUGNTRUST_CIPHER_DES_ECB_NOPAD 0x05
409 #define PLUGNTRUST_CIPHER_DES_ECB_ISO9797_M1 0x06
410 #define PLUGNTRUST_CIPHER_DES_ECB_ISO9797_M2 0x07
411 #define PLUGNTRUST_CIPHER_DES_ECB_PKCS5 0x08
412 #define PLUGNTRUST_CIPHER_AES_ECB_NOPAD 0x0E
413 #define PLUGNTRUST_CIPHER_AES_CBC_NOPAD 0x0D
414 #define PLUGNTRUST_CIPHER_AES_CBC_ISO9797_M1 0x16
415 #define PLUGNTRUST_CIPHER_AES_CBC_ISO9797_M2 0x17
416 #define PLUGNTRUST_CIPHER_AES_CBC_PKCS5 0x18
417 #define PLUGNTRUST_CIPHER_AES_CTR 0xF0
418 
423 #define PLUGNTRUST_CONFIG_ECDAA 0x0001
424 #define PLUGNTRUST_CONFIG_ECDSA_ECDH_ECDHE 0x0002
425 #define PLUGNTRUST_CONFIG_EDDSA 0x0004
426 #define PLUGNTRUST_CONFIG_DH_MONT 0x0008
427 #define PLUGNTRUST_CONFIG_HMAC 0x0010
428 #define PLUGNTRUST_CONFIG_RSA_PLAIN 0x0020
429 #define PLUGNTRUST_CONFIG_RSA_CRT 0x0040
430 #define PLUGNTRUST_CONFIG_AES 0x0080
431 #define PLUGNTRUST_CONFIG_DES 0x0100
432 #define PLUGNTRUST_CONFIG_PBKDF 0x0200
433 #define PLUGNTRUST_CONFIG_TLS 0x0400
434 #define PLUGNTRUST_CONFIG_MIFARE 0x0800
435 #define PLUGNTRUST_CONFIG_FIPS_MODE_DISABLED 0x1000
436 #define PLUGNTRUST_CONFIG_I2CM 0x2000
437 #define PLUGNTRUST_CONFIG_ECC_ALL 0x000F
438 #define PLUGNTRUST_CONFIG_RSA_ALL 0x0060
439 #define PLUGNTRUST_CONFIG_ALL 0x3FFF
440 
445 #define PLUGNTRUST_TRANSIENT_LOCK 0x01
446 #define PLUGNTRUST_PERSISTENT_LOCK 0x02
447 
452 #define PLUGNTRUST_LOCKED 0x01
453 
458 #define PLUGNTRUST_CC_DIGEST 0x01
459 #define PLUGNTRUST_CC_CIPHER 0x02
460 #define PLUGNTRUST_CC_SIGNATURE 0x03
461 
466 #define PLUGNTRUST_RESULT_SUCCESS 0x01
467 #define PLUGNTRUST_RESULT_FAILURE 0x02
468 
473 #define PLUGNTRUST_PERSISTENT 0x01
474 #define PLUGNTRUST_TRANSIENT 0x02
475 
480 #define PLUGNTRUST_NOT_SET 0x01
481 #define PLUGNTRUST_SET 0x02
482 
487 #define PLUGNTRUST_NO_MORE 0x01
488 #define PLUGNTRUST_MORE 0x02
489 
494 #define PLUGNTRUST_SCP_REQUIRED 0x01
495 #define PLUGNTRUST_SCP_NOT_REQUIRED 0x02
496 
501 #define PLUGNTRUST_APPLET_RES_ID_TRANSPORT 0x7FFF0200ul
502 #define PLUGNTRUST_APPLET_RES_ID_KP_FASTSCP_USER 0x7FFF0201ul
503 #define PLUGNTRUST_APPLET_RES_ID_KP_FASTSCP_IMPORT 0x7FFF0202ul
504 #define PLUGNTRUST_APPLET_RES_ID_PUB_FASTSCP_IMPORT 0x7FFF0203ul
505 #define PLUGNTRUST_APPLET_RES_ID_FEATURE 0x7FFF0204ul
506 #define PLUGNTRUST_APPLET_RES_ID_FACTORY_RESET 0x7FFF0205ul
507 #define PLUGNTRUST_APPLET_RES_ID_UNIQUE_ID 0x7FFF0206ul
508 #define PLUGNTRUST_APPLET_RES_ID_PLATFORM_SCP 0x7FFF0207ul
509 
514 #define PLUGNTRUST_SW_NOERROR 0x9000
515 #define PLUGNTRUST_SW_CONDITIONS_NOT_SATISFIED 0x6985
516 #define PLUGNTRUST_SW_SECURITY_STATUS 0x6982
517 #define PLUGNTRUST_SW_WRONG_DATA 0x6A80
518 #define PLUGNTRUST_SW_DATA_INVALID 0x6984
519 #define PLUGNTRUST_SW_COMMAND_NOT_ALLOWED 0x6986
520 
525 #define PLUGNTRUST_OBJECT_DOES_EXISTS 1
526 #define PLUGNTRUST_OBJECT_DOESNT_EXIST 2
527 
532 #define PLUGNTRUST_OBJID_SE05X_APPLET_RES_START 0x7FFF0000ul
533 #define PLUGNTRUST_SSS_OBJID_DEMO_AUTH_START 0x7DA00000ul
534 #define PLUGNTRUST_SSS_OBJID_IOT_HUB_A_START 0xF0000000ul
535 
540 #define PLUGNTRUST_OBJID_APPLET_MASK 0xFFFF0000ul
541 #define PLUGNTRUST_OBJID_IOT_MASK 0xF0000000ul
542 
543  // apdu
545 
561 #define PLUGNTRUST_SET_DEV_ADDR 0x48
562 
567 #define PLUGNTRUST_INTERFACE_ISO14443 0
568 #define PLUGNTRUST_INTERFACE_I2C 1
569 
574 #define PLUGNTRUST_CARD_MANAGER_WITH_RSP 1
575 #define PLUGNTRUST_CARD_MANAGER_WITHOUT_RSP 0
576  // plugntrust_set
578 
593 #define PLUGNTRUST_MAP_MIKROBUS( cfg, mikrobus ) \
594  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
595  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
596  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
597  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
598 
599  // plugntrust_map // plugntrust
601 
606 typedef struct
607 {
608  // Output pins
609  digital_out_t en;
610  digital_out_t rst;
611 
612  // Modules
613  i2c_master_t i2c;
615  // I2C slave address
616  uint8_t slave_address;
618  uint8_t interface;
620 } plugntrust_t;
621 
626 typedef struct
627 {
628  pin_name_t scl;
629  pin_name_t sda;
631  pin_name_t en;
632  pin_name_t rst;
633 
634  uint32_t i2c_speed;
635  uint8_t i2c_address;
638 
643 typedef struct
644 {
645  uint8_t cla;
646  uint8_t ins;
647  uint8_t p1;
648  uint8_t p2;
649  uint8_t payload_len;
650  uint8_t payload[ 0xFF ];
651  uint16_t rsp_len;
652  uint16_t status;
654 
659 typedef struct
660 {
661  uint8_t nad;
662  uint8_t pcb;
663  uint8_t len;
665  uint16_t crc16;
667 
672 typedef struct
673 {
675  uint8_t vendor_id[ 5 ];
676 
678  uint8_t data_link_layer_parameters[ 0x04 ];
679 
681 
683  uint8_t physical_layer_parameters[ 0x0B ];
684 
685  uint8_t historical_len;
686  uint8_t historical[ 0x0A ];
687 
689 
694 typedef struct
695 {
696  uint8_t major_version;
697  uint8_t minor_version;
698  uint8_t patch_version;
699 
700  uint16_t applet_config;
701  uint16_t secure_box;
702 
704 
709 typedef enum
710 {
715 
717 
734 
749 
763 
777 
791 
805 
815 void plugntrust_set_en ( plugntrust_t *ctx, uint8_t state );
816 
826 void plugntrust_set_rst ( plugntrust_t *ctx, uint8_t state );
827 
838 
855 void plugntrust_set_tlv_u8 ( uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint8_t value );
856 
874 void plugntrust_set_tlv_u16 ( uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint16_t value );
875 
893 void plugntrust_set_tlv_u16_optional ( uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint16_t value );
894 
912 void plugntrust_set_tlv_u32 ( uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint32_t value );
913 
935 err_t plugntrust_set_tlv_u8buf ( uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint8_t *cmd, uint32_t cmd_len );
936 
958 err_t plugntrust_set_tlv_u8buf_optional ( uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint8_t *cmd, uint32_t cmd_len );
959 
979 err_t plugntrust_get_tlv_u8 ( uint8_t *buf, uint32_t *buf_index, uint8_t tag, uint8_t *rsp );
980 
1000 err_t plugntrust_get_tlv_u16 ( uint8_t *buf, uint32_t *buf_index, uint8_t tag, uint16_t *rsp );
1001 
1025 err_t plugntrust_get_tlv_u8buf ( uint8_t *buf, uint32_t *buf_index, uint8_t buf_len, uint8_t tag, uint8_t *rsp, uint32_t *rsp_len );
1026 
1036 
1048 
1061 err_t plugntrust_object_id_list ( plugntrust_t *ctx, uint32_t *id_list, uint8_t *list_len );
1062 
1076 
1090 err_t plugntrust_select_applet ( plugntrust_t *ctx, uint8_t ns_encode, plugntrust_version_info_t *ver_info );
1091 
1105 err_t plugntrust_select_card_manager ( plugntrust_t *ctx, uint8_t rsp, uint8_t *cardmanager_rsp, uint8_t *cardmanager_rsp_len );
1106 
1123 err_t plugntrust_get_free_memory ( plugntrust_t *ctx, uint8_t memory_type, uint16_t *free_memory );
1124 
1140 err_t plugntrust_get_random_numbers ( plugntrust_t *ctx, uint8_t *random_buf, uint8_t buf_len );
1141 
1157 err_t plugntrust_check_object_exist ( plugntrust_t *ctx, uint32_t object_id );
1158 
1173 err_t plugntrust_delete_object ( plugntrust_t *ctx, uint32_t object_id );
1174 
1193 err_t plugntrust_read_object ( plugntrust_t *ctx, uint32_t object_id, uint16_t offset, uint16_t read_len, uint8_t *data_buf, uint32_t *data_len );
1194 
1213 err_t plugntrust_write_binary_object ( plugntrust_t *ctx, uint32_t object_id, uint16_t offset, uint16_t data_len, uint8_t *data_buf );
1214 
1231 
1232 #ifdef __cplusplus
1233 }
1234 #endif
1235 #endif // PLUGNTRUST_H
1236  // plugntrust
1238 
1239 // ------------------------------------------------------------------------ END
plugntrust_set_tlv_u8buf_optional
err_t plugntrust_set_tlv_u8buf_optional(uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint8_t *cmd, uint32_t cmd_len)
Add TLV data buffer in payload buffer if TLV data buffer length greater then 0.
plugntrust_frame_data_t::pcb
uint8_t pcb
Definition: plugntrust.h:662
PLUGNTRUST_ERROR_TIMEOUT
@ PLUGNTRUST_ERROR_TIMEOUT
Definition: plugntrust.h:713
plugntrust_apdu_transfer
err_t plugntrust_apdu_transfer(plugntrust_t *ctx, plugntrust_frame_data_t *frame_data)
Write-Read frame data function.
plugntrust_atr_t::protocol_version
uint8_t protocol_version
Definition: plugntrust.h:674
plugntrust_apdu_t::ins
uint8_t ins
Definition: plugntrust.h:646
plugntrust_t::interface
uint8_t interface
Definition: plugntrust.h:618
plugntrust_apdu_t::p1
uint8_t p1
Definition: plugntrust.h:647
plugntrust_init
err_t plugntrust_init(plugntrust_t *ctx, plugntrust_cfg_t *cfg)
Plug n Trust initialization function.
plugntrust_cfg_t::rst
pin_name_t rst
Definition: plugntrust.h:632
plugntrust_atr_t
Data after reset.
Definition: plugntrust.h:673
plugntrust_t::rst
digital_out_t rst
Definition: plugntrust.h:610
plugntrust_cfg_t::sda
pin_name_t sda
Definition: plugntrust.h:629
plugntrust_set_en
void plugntrust_set_en(plugntrust_t *ctx, uint8_t state)
Set Enable pin state.
plugntrust_t
Plug n Trust Click context object.
Definition: plugntrust.h:607
plugntrust_sw_reset
err_t plugntrust_sw_reset(plugntrust_t *ctx, plugntrust_atr_t *atr_data)
Sends request to reset device and reads ATR data.
plugntrust_delete_object
err_t plugntrust_delete_object(plugntrust_t *ctx, uint32_t object_id)
Delete object.
plugntrust_set_tlv_u8
void plugntrust_set_tlv_u8(uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint8_t value)
Add TLV data of 1 byte value in payload buffer.
plugntrust_cfg_t::scl
pin_name_t scl
Definition: plugntrust.h:628
plugntrust_apdu_t::rsp_len
uint16_t rsp_len
Definition: plugntrust.h:651
plugntrust_frame_data_t::crc16
uint16_t crc16
Definition: plugntrust.h:665
plugntrust_get_tlv_u16
err_t plugntrust_get_tlv_u16(uint8_t *buf, uint32_t *buf_index, uint8_t tag, uint16_t *rsp)
Parses TLV data from payload buffer to find data for desired tag.
plugntrust_get_tlv_u8buf
err_t plugntrust_get_tlv_u8buf(uint8_t *buf, uint32_t *buf_index, uint8_t buf_len, uint8_t tag, uint8_t *rsp, uint32_t *rsp_len)
Parses TLV data from payload buffer to find data for desired tag.
plugntrust_set_tlv_u32
void plugntrust_set_tlv_u32(uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint32_t value)
Add TLV data of 4 bytes value in payload buffer.
PLUGNTRUST_ERROR
@ PLUGNTRUST_ERROR
Definition: plugntrust.h:712
plugntrust_version_info_t::secure_box
uint16_t secure_box
Definition: plugntrust.h:701
plugntrust_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: plugntrust.h:634
plugntrust_select_card_manager
err_t plugntrust_select_card_manager(plugntrust_t *ctx, uint8_t rsp, uint8_t *cardmanager_rsp, uint8_t *cardmanager_rsp_len)
Select card manager.
plugntrust_version_info_t::major_version
uint8_t major_version
Definition: plugntrust.h:696
plugntrust_set_rst
void plugntrust_set_rst(plugntrust_t *ctx, uint8_t state)
Set Reset pin state.
plugntrust_return_value_t
plugntrust_return_value_t
Plug n Trust Click return value data.
Definition: plugntrust.h:710
plugntrust_select_applet
err_t plugntrust_select_applet(plugntrust_t *ctx, uint8_t ns_encode, plugntrust_version_info_t *ver_info)
Selects Clicks Applet and returns info that device sends back to host.
plugntrust_version_info_t::applet_config
uint16_t applet_config
Definition: plugntrust.h:700
plugntrust_frame_data_t::apdu
plugntrust_apdu_t * apdu
Definition: plugntrust.h:664
plugntrust_read_object
err_t plugntrust_read_object(plugntrust_t *ctx, uint32_t object_id, uint16_t offset, uint16_t read_len, uint8_t *data_buf, uint32_t *data_len)
Read object data.
plugntrust_t::slave_address
uint8_t slave_address
Definition: plugntrust.h:616
plugntrust_version_info_t::patch_version
uint8_t patch_version
Definition: plugntrust.h:698
plugntrust_cfg_setup
void plugntrust_cfg_setup(plugntrust_cfg_t *cfg)
Plug n Trust configuration object setup function.
plugntrust_frame_data_t
Communication frame data object.
Definition: plugntrust.h:660
PLUGNTRUST_ERROR_DATA_OVF
@ PLUGNTRUST_ERROR_DATA_OVF
Definition: plugntrust.h:714
plugntrust_get_tlv_u8
err_t plugntrust_get_tlv_u8(uint8_t *buf, uint32_t *buf_index, uint8_t tag, uint8_t *rsp)
Parses TLV data from payload buffer to find data for desired tag.
plugntrust_set_tlv_u16_optional
void plugntrust_set_tlv_u16_optional(uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint16_t value)
Add TLV data of 2 bytes value in payload buffer if value is greater then 0.
plugntrust_t::i2c
i2c_master_t i2c
Definition: plugntrust.h:613
plugntrust_frame_data_t::nad
uint8_t nad
Definition: plugntrust.h:661
plugntrust_get_free_memory
err_t plugntrust_get_free_memory(plugntrust_t *ctx, uint8_t memory_type, uint16_t *free_memory)
Reads Applet free memory.
plugntrust_cfg_t::i2c_address
uint8_t i2c_address
Definition: plugntrust.h:635
plugntrust_apdu_read
err_t plugntrust_apdu_read(plugntrust_t *ctx, plugntrust_frame_data_t *frame_data)
Reading frame data function function.
plugntrust_apdu_t::status
uint16_t status
Definition: plugntrust.h:652
plugntrust_apdu_t::cla
uint8_t cla
Definition: plugntrust.h:645
plugntrust_get_applet_info
err_t plugntrust_get_applet_info(plugntrust_t *ctx, plugntrust_version_info_t *ver_info)
Get Version info from Applet.
plugntrust_calculate_apdu_size
uint8_t plugntrust_calculate_apdu_size(plugntrust_apdu_t *apdu_data)
Calculates APDU object size.
plugntrust_frame_data_t::len
uint8_t len
Definition: plugntrust.h:663
plugntrust_apdu_write
err_t plugntrust_apdu_write(plugntrust_t *ctx, plugntrust_frame_data_t *frame_data)
Writing frame data function.
plugntrust_cfg_t::en
pin_name_t en
Definition: plugntrust.h:631
plugntrust_apdu_t::payload_len
uint8_t payload_len
Definition: plugntrust.h:649
plugntrust_write_binary_object
err_t plugntrust_write_binary_object(plugntrust_t *ctx, uint32_t object_id, uint16_t offset, uint16_t data_len, uint8_t *data_buf)
Create/Write to binary object.
plugntrust_end_apdu_session
err_t plugntrust_end_apdu_session(plugntrust_t *ctx)
Sends command for ending APDU session.
plugntrust_object_id_list
err_t plugntrust_object_id_list(plugntrust_t *ctx, uint32_t *id_list, uint8_t *list_len)
Reads all Object ID's from Applet.
plugntrust_version_info_t
Version info data.
Definition: plugntrust.h:695
plugntrust_set_tlv_u16
void plugntrust_set_tlv_u16(uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint16_t value)
Add TLV data of 2 bytes value in payload buffer.
plugntrust_reset
void plugntrust_reset(plugntrust_t *ctx)
Reset function.
plugntrust_atr_t::physical_layer_id
uint8_t physical_layer_id
Definition: plugntrust.h:680
plugntrust_atr_t::historical_len
uint8_t historical_len
Definition: plugntrust.h:685
plugntrust_t::en
digital_out_t en
Definition: plugntrust.h:609
plugntrust_apdu_t
APDU data object.
Definition: plugntrust.h:644
plugntrust_set_tlv_u8buf
err_t plugntrust_set_tlv_u8buf(uint8_t *buf, uint8_t *buf_len, uint8_t tag, uint8_t *cmd, uint32_t cmd_len)
Add TLV data buffer in payload buffer.
plugntrust_apdu_t::p2
uint8_t p2
Definition: plugntrust.h:648
plugntrust_atr_t::data_link_layer_parameters_len
uint8_t data_link_layer_parameters_len
Definition: plugntrust.h:677
PLUGNTRUST_OK
@ PLUGNTRUST_OK
Definition: plugntrust.h:711
plugntrust_atr_t::physical_layer_parameters_len
uint8_t physical_layer_parameters_len
Definition: plugntrust.h:682
plugntrust_check_object_exist
err_t plugntrust_check_object_exist(plugntrust_t *ctx, uint32_t object_id)
Check if object exists.
plugntrust_default_cfg
err_t plugntrust_default_cfg(plugntrust_t *ctx)
Plug n Trust default configuration function.
plugntrust_get_random_numbers
err_t plugntrust_get_random_numbers(plugntrust_t *ctx, uint8_t *random_buf, uint8_t buf_len)
Get random data.
plugntrust_version_info_t::minor_version
uint8_t minor_version
Definition: plugntrust.h:697
plugntrust_cfg_t
Plug n Trust Click configuration object.
Definition: plugntrust.h:627