1 /** @addtogroup MCD_MCDIMPL_DAEMON
2  * @{
3  * @file
4  *
5  * <!-- Copyright Giesecke & Devrient GmbH 2009 - 2012 -->
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote
16  *    products derived from this software without specific prior
17  *    written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 #ifndef MCDAEMON_H_
32 #define MCDAEMON_H_
33 
34 #include <inttypes.h>      // ANSI C99
35 
36 
37 #define SOCK_PATH "#mcdaemon"
38 #include "mcUuid.h"
39 #include "mcVersionInfo.h"
40 
41 typedef enum {
42     MC_DRV_CMD_PING                 = 0,
43     MC_DRV_CMD_GET_INFO             = 1,
44     MC_DRV_CMD_OPEN_DEVICE          = 2,
45     MC_DRV_CMD_CLOSE_DEVICE         = 3,
46     MC_DRV_CMD_NQ_CONNECT           = 4,
47     MC_DRV_CMD_OPEN_SESSION         = 5,
48     MC_DRV_CMD_CLOSE_SESSION        = 6,
49     MC_DRV_CMD_NOTIFY               = 7,
50     MC_DRV_CMD_MAP_BULK_BUF         = 8,
51     MC_DRV_CMD_UNMAP_BULK_BUF       = 9,
52     MC_DRV_CMD_GET_VERSION          = 10,
53     MC_DRV_CMD_GET_MOBICORE_VERSION = 11,
54 } mcDrvCmd_t;
55 
56 typedef struct {
57     uint32_t  commandId;
58 } mcDrvCommandHeader_t;
59 
60 typedef struct {
61     /* MobiCore Daemon uses Client API return codes also in commands between Daemon and Client Library. */
62     uint32_t  responseId;
63 } mcDrvResponseHeader_t;
64 
65 #define MC_DEVICE_ID_DEFAULT    0 /**< The default device ID */
66 
67 
68 //--------------------------------------------------------------
69 struct MC_DRV_CMD_OPEN_DEVICE_struct {
70     uint32_t  commandId;
71     uint32_t  deviceId;
72 };
73 
74 typedef struct {
75     mcDrvResponseHeader_t        header;
76 } mcDrvRspOpenDevice_t;
77 
78 //--------------------------------------------------------------
79 struct MC_DRV_CMD_CLOSE_DEVICE_struct {
80     uint32_t  commandId;
81 };
82 
83 typedef struct {
84     mcDrvResponseHeader_t         header;
85 } mcDrvRspCloseDevice_t;
86 
87 //--------------------------------------------------------------
88 struct MC_DRV_CMD_OPEN_SESSION_struct {
89     uint32_t  commandId;
90     uint32_t  deviceId;
91     mcUuid_t  uuid;
92     uint32_t  tci;
93     uint32_t  handle;
94     uint32_t  len;
95 };
96 
97 typedef struct {
98     uint32_t  sessionId;
99     uint32_t  deviceSessionId;
100     uint32_t  sessionMagic;
101 } mcDrvRspOpenSessionPayload_t, *mcDrvRspOpenSessionPayload_ptr;
102 
103 typedef struct {
104     mcDrvResponseHeader_t         header;
105     mcDrvRspOpenSessionPayload_t  payload;
106 } mcDrvRspOpenSession_t;
107 
108 
109 //--------------------------------------------------------------
110 struct MC_DRV_CMD_CLOSE_SESSION_struct {
111     uint32_t  commandId;
112     uint32_t  sessionId;
113 };
114 
115 typedef struct {
116     mcDrvResponseHeader_t         header;
117 } mcDrvRspCloseSession_t;
118 
119 
120 //--------------------------------------------------------------
121 struct MC_DRV_CMD_NOTIFY_struct {
122     uint32_t  commandId;
123     uint32_t  sessionId;
124 };
125 
126 // Notify does not have a response
127 
128 //--------------------------------------------------------------
129 struct MC_DRV_CMD_MAP_BULK_BUF_struct {
130     uint32_t  commandId;
131     uint32_t  sessionId;
132     uint32_t  handle;
133     uint32_t  pAddrL2;
134     uint32_t  offsetPayload;
135     uint32_t  lenBulkMem;
136 };
137 
138 typedef struct {
139     uint32_t  sessionId;
140     uint32_t  secureVirtualAdr;
141 } mcDrvRspMapBulkMemPayload_t, *mcDrvRspMapBulkMemPayload_ptr;
142 
143 typedef struct {
144     mcDrvResponseHeader_t        header;
145     mcDrvRspMapBulkMemPayload_t  payload;
146 } mcDrvRspMapBulkMem_t;
147 
148 
149 //--------------------------------------------------------------
150 struct MC_DRV_CMD_UNMAP_BULK_BUF_struct {
151     uint32_t  commandId;
152     uint32_t  sessionId;
153     uint32_t  handle;
154     uint32_t  secureVirtualAdr;
155     uint32_t  lenBulkMem;
156 };
157 
158 typedef struct {
159     mcDrvResponseHeader_t          header;
160 } mcDrvRspUnmapBulkMem_t;
161 
162 
163 //--------------------------------------------------------------
164 struct MC_DRV_CMD_NQ_CONNECT_struct {
165     uint32_t  commandId;
166     uint32_t  deviceId;
167     uint32_t  sessionId;
168     uint32_t  deviceSessionId;
169     uint32_t  sessionMagic; //Random data
170 };
171 
172 typedef struct {
173     mcDrvResponseHeader_t       header;
174 } mcDrvRspNqConnect_t;
175 
176 //--------------------------------------------------------------
177 struct MC_DRV_CMD_GET_VERSION_struct {
178     uint32_t commandId;
179 };
180 
181 typedef struct {
182     uint32_t responseId;
183     uint32_t version;
184 } mcDrvRspGetVersion_t;
185 
186 //--------------------------------------------------------------
187 struct MC_DRV_CMD_GET_MOBICORE_VERSION_struct {
188     uint32_t  commandId;
189 };
190 
191 
192 typedef struct {
193     mcVersionInfo_t versionInfo;
194 } mcDrvRspGetMobiCoreVersionPayload_t, *mcDrvRspGetMobiCoreVersionPayload_ptr;
195 
196 typedef struct {
197     mcDrvResponseHeader_t       header;
198     mcDrvRspGetMobiCoreVersionPayload_t payload;
199 } mcDrvRspGetMobiCoreVersion_t;
200 
201 //--------------------------------------------------------------
202 typedef union {
203     mcDrvCommandHeader_t                header;
204     MC_DRV_CMD_OPEN_DEVICE_struct       mcDrvCmdOpenDevice;
205     MC_DRV_CMD_CLOSE_DEVICE_struct      mcDrvCmdCloseDevice;
206     MC_DRV_CMD_OPEN_SESSION_struct      mcDrvCmdOpenSession;
207     MC_DRV_CMD_CLOSE_SESSION_struct     mcDrvCmdCloseSession;
208     MC_DRV_CMD_NQ_CONNECT_struct        mcDrvCmdNqConnect;
209     MC_DRV_CMD_NOTIFY_struct            mcDrvCmdNotify;
210     MC_DRV_CMD_MAP_BULK_BUF_struct      mcDrvCmdMapBulkMem;
211     MC_DRV_CMD_UNMAP_BULK_BUF_struct    mcDrvCmdUnmapBulkMem;
212     MC_DRV_CMD_GET_VERSION_struct       mcDrvCmdGetVersion;
213     MC_DRV_CMD_GET_MOBICORE_VERSION_struct  mcDrvCmdGetMobiCoreVersion;
214 } mcDrvCommand_t, *mcDrvCommand_ptr;
215 
216 typedef union {
217     mcDrvResponseHeader_t        header;
218     mcDrvRspOpenDevice_t         mcDrvRspOpenDevice;
219     mcDrvRspCloseDevice_t        mcDrvRspCloseDevice;
220     mcDrvRspOpenSession_t        mcDrvRspOpenSession;
221     mcDrvRspCloseSession_t       mcDrvRspCloseSession;
222     mcDrvRspNqConnect_t          mcDrvRspNqConnect;
223     mcDrvRspMapBulkMem_t         mcDrvRspMapBulkMem;
224     mcDrvRspUnmapBulkMem_t       mcDrvRspUnmapBulkMem;
225     mcDrvRspGetVersion_t         mcDrvRspGetVersion;
226     mcDrvRspGetMobiCoreVersion_t mcDrvRspGetMobiCoreVersion;
227 } mcDrvResponse_t, *mcDrvResponse_ptr;
228 
229 #endif /* MCDAEMON_H_ */
230 
231 /** @} */
232