• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @addtogroup MCD_IMPL_LIB
2  * @{
3  * @file
4  *
5  * Client library device management.
6  *
7  * Device and Trustlet Session management Functions.
8  *
9  * <!-- Copyright Giesecke & Devrient GmbH 2009 - 2012 -->
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote
20  *    products derived from this software without specific prior
21  *    written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
24  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
27  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
29  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 #ifndef DEVICE_H_
36 #define DEVICE_H_
37 
38 #include <stdint.h>
39 #include <vector>
40 
41 #include "public/MobiCoreDriverApi.h"
42 #include "Session.h"
43 #include "CWsm.h"
44 
45 
46 class Device
47 {
48 
49 private:
50     sessionList_t   sessionList; /**< MobiCore Trustlet session associated with the device */
51     wsmList_t       wsmL2List; /**< WSM L2 Table  */
52 
53 
54 public:
55     uint32_t     deviceId; /**< Device identifier */
56     Connection   *connection; /**< The device connection */
57     CMcKMod_ptr  pMcKMod;
58 
59     Device(
60         uint32_t    deviceId,
61         Connection  *connection
62     );
63 
64     virtual ~Device(
65         void
66     );
67 
68     /**
69      * Open the device.
70      * @param deviceName Name of the kernel modules device file.
71      * @return true if the device has been opened successfully
72      */
73     bool open(
74         const char *deviceName
75     );
76 
77     /**
78      * Closes the device.
79      */
80     void close(
81         void
82     );
83 
84     /**
85      * Check if the device has open sessions.
86      * @return true if the device has one or more open sessions.
87      */
88     bool hasSessions(
89         void
90     );
91 
92     /**
93      * Add a session to the device.
94      * @param sessionId session ID
95      * @param connection session connection
96      */
97     void createNewSession(
98         uint32_t    sessionId,
99         Connection  *connection
100     );
101 
102     /**
103      * Remove the specified session from the device.
104      * The session object will be destroyed and all resources associated with it will be freed.
105      *
106      * @param sessionId Session of the session to remove.
107      * @return true if a session has been found and removed.
108      */
109     bool removeSession(
110         uint32_t sessionId
111     );
112 
113     /**
114      * Get as session object for a given session ID.
115      * @param sessionId Identified of a previously opened session.
116      * @return Session object if available or NULL if no session has been found.
117      */
118     Session *resolveSessionId(
119         uint32_t sessionId
120     );
121 
122     /**
123      * Allocate a block of contiguous WSM.
124      * @param len The virtual address to be registered.
125      * @param wsm The CWsm object of the allocated memory.
126      * @return MC_DRV_OK if successful.
127      */
128     mcResult_t allocateContiguousWsm(
129         uint32_t len,
130         CWsm **wsm
131     );
132 
133     /**
134      * Unregister a vaddr from a device.
135      * @param vaddr The virtual address to be registered.
136      * @param paddr The physical address to be registered.
137      */
138     mcResult_t freeContiguousWsm(
139         CWsm_ptr  pWsm
140     );
141 
142     /**
143      * Get a WSM object for a given virtual address.
144      * @param vaddr The virtual address which has been allocate with mcMallocWsm() in advance.
145      * @return the WSM object or NULL if no address has been found.
146      */
147     CWsm_ptr findContiguousWsm(
148         addr_t  virtAddr
149     );
150 
151 };
152 
153 #endif /* DEVICE_H_ */
154 
155 /** @} */
156