File: se_tee.h

package info (click to toggle)
optee-client 4.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 932 kB
  • sloc: ansic: 11,409; makefile: 410; xml: 113; sh: 33
file content (90 lines) | stat: -rw-r--r-- 2,407 bytes parent folder | download | duplicates (4)
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
/* SPDX-License-Identifier: BSD-2-Clause */
/*
 * Copyright (c) 2021, Foundries.io
 * Jorge Ramirez-Ortiz <jorge@foundries.io>
 */

#ifndef SE_TEE_H
#define SE_TEE_H

#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef unsigned long SE_ULONG;
typedef SE_ULONG SE_RV;

/* Values for type SR_RV */
#define SER_OK					0x0000
#define SER_CANT_OPEN_SESSION			0x0001
#define SER_ERROR_GENERIC			0x0002

/*
 * Type identifier for the APDU message as described by Smart Card Standard ISO7816-4
 * about ADPU message bodies decoding convention:
 *
 * https://cardwerk.com/smart-card-standard-iso7816-4-section-5-basic-organizations/#chap5_3_2
 */
enum se_apdu_type {
	SE_APDU_NO_HINT,
	SE_APDU_CASE_1,
	SE_APDU_CASE_2,
	SE_APDU_CASE_2E,
	SE_APDU_CASE_3,
	SE_APDU_CASE_3E,
	SE_APDU_CASE_4,
	SE_APDU_CASE_4E,
};

/**
 * se_apdu_request() - Send an APDU message and get response.
 *
 * @param type		Type of the APDU command.
 * @param hdr		Pointer to APDU message header.
 * @param hdr_len	Byte length of message header @hdr.
 * @param src		Pointer to APDU message payload.
 * @param src_len	Byte length of message payload @src.
 * @param dst		Pointer to APDU message reponse buffer.
 * @param dst_len	Byte length of reponse buffer @dst.
 *
 * @return SER_CANT_OPEN_SESSION	Error opening the TEE session.
 * @return SER_ERROR_GENERIC		Error unspecified.
 * @return SER_OK			On success.
 */
SE_RV se_apdu_request(enum se_apdu_type type,
		    unsigned char *hdr, size_t hdr_len,
		    unsigned char *src, size_t src_len,
		    unsigned char *dst, size_t *dst_len);

/**
 * se_scp03_enable() - Enable the SCP03 protocol using the keys active in the
 * Secure Element.
 *
 * Enables the SCP03 session with the Secure Element.
 *
 * @return SER_CANT_OPEN_SESSION	Error opening the TEE session.
 * @return SER_ERROR_GENERIC		Error unspecified.
 * @return SER_OK			On success.
 */
SE_RV se_scp03_enable(void);

/**
 * se_scp03_rotate_keys_and_enable() - Attempt to replace the active SCP03 keys
 * and enable the SCP03 session.
 *
 * Generates secure keys for the board and writes them in the Secure Element non
 * volatile memory. Then re-enables the session.
 *
 * @return SER_CANT_OPEN_SESSION	Error opening the TEE session.
 * @return SER_ERROR_GENERIC		Error unspecified.
 * @return SER_OK			On success.
 */
SE_RV se_scp03_rotate_keys_and_enable(void);

#ifdef __cplusplus
}
#endif

#endif /*SE_TEE_H*/