summaryrefslogtreecommitdiff
path: root/mobicore/MobiCoreDriverLib/ClientLib/Contrib/mc_user.h
blob: 7c2df39014f100538979791abb941773fc17bf38 (plain)
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
/*
 * Copyright (c) 2013-2015 TRUSTONIC LIMITED
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 * This program 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.
 */

#ifndef _MC_USER_H_
#define _MC_USER_H_

#define MCDRVMODULEAPI_VERSION_MAJOR 2
#define MCDRVMODULEAPI_VERSION_MINOR 1

#include <linux/types.h>

#define MC_USER_DEVNODE		"mobicore-user"

/** Maximum length of MobiCore product ID string. */
#define MC_PRODUCT_ID_LEN	64

/** Number of buffers that can be mapped at once */
#define MC_MAP_MAX		4

/** Max length for buffers */
#define BUFFER_LENGTH_MAX	0x100000

/** Flags for buffers to map (aligned on GP) */
#define MC_IO_MAP_INPUT		0x1
#define MC_IO_MAP_OUTPUT	0x2
#define MC_IO_MAP_INPUT_OUTPUT	(MC_IO_MAP_INPUT | MC_IO_MAP_OUTPUT)

/*
 * Universally Unique Identifier (UUID) according to ISO/IEC 11578.
 */
struct mc_uuid_t {
	__u8		value[16];	/* Value of the UUID. */
};

/*
 * GP TA login types.
 */
enum mc_login_type {
	LOGIN_PUBLIC = 0,
	LOGIN_USER,
	LOGIN_GROUP,
	LOGIN_APPLICATION = 4,
	LOGIN_USER_APPLICATION,
	LOGIN_GROUP_APPLICATION,
};

/*
 * GP TA identity structure.
 */
struct mc_identity {
	enum mc_login_type	login_type;
	union {
		__u8		login_data[16];
		gid_t		gid;		/* Requested group id */
		struct {
			uid_t	euid;
			uid_t	ruid;
		} uid;
	};
	pid_t			pid;		/* Client, when using proxy */
};

/*
 * Data exchange structure of the MC_IO_OPEN_SESSION ioctl command.
 */
struct mc_ioctl_open_session {
	struct mc_uuid_t uuid;		/* trustlet uuid */
	__u32		is_gp_uuid;	/* uuid is for GP TA */
	__u32		sid;            /* session id (out) */
	__u64		tci;		/* tci buffer pointer */
	__u32		tcilen;		/* tci length */
	struct mc_identity identity;	/* GP TA identity */
};

/*
 * Data exchange structure of the MC_IO_OPEN_TRUSTLET ioctl command.
 */
struct mc_ioctl_open_trustlet {
	__u32		sid;		/* session id (out) */
	__u32		spid;		/* trustlet spid */
	__u64		buffer;		/* trustlet binary pointer */
	__u32		tlen;		/* binary length  */
	__u64		tci;		/* tci buffer pointer */
	__u32		tcilen;		/* tci length */
};

/*
 * Data exchange structure of the MC_IO_WAIT ioctl command.
 */
struct mc_ioctl_wait {
	__u32		sid;		/* session id (in) */
	__s32		timeout;	/* notification timeout */
	__u32		partial;	/* for proxy server to retry silently */
};

/*
 * Data exchange structure of the MC_IO_ALLOC ioctl command.
 */
struct mc_ioctl_alloc {
	__u32		len;		/* buffer length  */
	__u32		handle;		/* user handle for the buffer (out) */
};

/*
 * Buffer mapping incoming and outgoing information.
 */
struct mc_ioctl_buffer {
	__u64		va;		/* user space address of buffer */
	__u32		len;		/* buffer length  */
	__u64		sva;		/* SWd virt address of buffer (out) */
	__u32		flags;		/* buffer flags  */
};

/*
 * Data exchange structure of the MC_IO_MAP and MC_IO_UNMAP ioctl commands.
 */
struct mc_ioctl_map {
	__u32		sid;		/* session id */
	struct mc_ioctl_buffer bufs[MC_MAP_MAX]; /* buffers info */
};

/*
 * Data exchange structure of the MC_IO_ERR ioctl command.
 */
struct mc_ioctl_geterr {
	__u32		sid;		/* session id */
	__s32		value;		/* error value (out) */
};

/*
 * Global MobiCore Version Information.
 */
struct mc_version_info {
	char product_id[MC_PRODUCT_ID_LEN]; /** Product ID string */
	__u32 version_mci;		/** Mobicore Control Interface */
	__u32 version_so;		/** Secure Objects */
	__u32 version_mclf;		/** MobiCore Load Format */
	__u32 version_container;	/** MobiCore Container Format */
	__u32 version_mc_config;	/** MobiCore Config. Block Format */
	__u32 version_tl_api;		/** MobiCore Trustlet API */
	__u32 version_dr_api;		/** MobiCore Driver API */
	__u32 version_nwd;		/** This Driver */
};

/*
 * defines for the ioctl mobicore driver module function call from user space.
 */
/* MobiCore IOCTL magic number */
#define MC_IOC_MAGIC	'M'

/*
 * Implement corresponding functions from user api
 */
#define MC_IO_OPEN_SESSION	\
	_IOWR(MC_IOC_MAGIC, 0, struct mc_ioctl_open_session)
#define MC_IO_OPEN_TRUSTLET	\
	_IOWR(MC_IOC_MAGIC, 1, struct mc_ioctl_open_trustlet)
#define MC_IO_CLOSE_SESSION	_IO(MC_IOC_MAGIC, 2)
#define MC_IO_NOTIFY		_IO(MC_IOC_MAGIC, 3)
#define MC_IO_WAIT		_IOW(MC_IOC_MAGIC, 4, struct mc_ioctl_wait)
#define MC_IO_MAP		_IOWR(MC_IOC_MAGIC, 5, struct mc_ioctl_map)
#define MC_IO_UNMAP		_IOW(MC_IOC_MAGIC, 6, struct mc_ioctl_map)
#define MC_IO_ERR		_IOWR(MC_IOC_MAGIC, 7, struct mc_ioctl_geterr)
#define MC_IO_HAS_SESSIONS	_IO(MC_IOC_MAGIC, 8)
#define MC_IO_VERSION		_IOR(MC_IOC_MAGIC, 9, struct mc_version_info)

#endif /* _MC_USER_H_ */