aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gud/MobiCoreKernelApi/session.h
blob: e0e8d34db11b0253588c77d94e5a0c5a24a5c2c3 (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
/** @addtogroup MCD_IMPL_LIB
 * @{
 * @file
 * <!-- Copyright Giesecke & Devrient GmbH 2009 - 2011 -->
 */
#ifndef SESSION_H_
#define SESSION_H_

#include "common.h"

#include <linux/list.h>
#include "connection.h"


typedef struct {
    addr_t           virtAddr; /**< The virtual address of the Bulk buffer*/
    uint32_t         len;      /**< Length of the Bulk buffer*/
    uint32_t         handle;
    addr_t           physAddrWsmL2; /**< The physical address of the L2 table of the Bulk buffer*/
    struct list_head list;          /**< The list param for using the kernel lists*/
} bulkBufferDescriptor_t;

bulkBufferDescriptor_t* bulkBufferDescriptor_create(
    addr_t    virtAddr,
    uint32_t  len,
    uint32_t  handle,
    addr_t    physAddrWsmL2
);

typedef struct list_head bulkBufferDescrVector_t;

/** Session states.
 * At the moment not used !!.
 */
typedef enum
{
    SESSION_STATE_INITIAL,
    SESSION_STATE_OPEN,
    SESSION_STATE_TRUSTLET_DEAD
} sessionState_t;

#define SESSION_ERR_NO      0 /**< No session error */

/** Session information structure.
 * The information structure is used to hold the state of the session, which will limit further actions for the session.
 * Also the last error code will be stored till it's read.
 */
typedef struct {
    sessionState_t state;       /**< Session state */
    int32_t        lastErr;     /**< Last error of session */
} sessionInformation_t;


typedef struct {
    struct mcInstance        *pInstance;
    bulkBufferDescrVector_t  bulkBufferDescriptors; /**< Descriptors of additional bulk buffer of a session */
    sessionInformation_t     sessionInfo; /**< Informations about session */

    uint32_t         sessionId;
    connection_t     *notificationConnection;

    struct list_head list; /**< The list param for using the kernel lists*/
} session_t;

session_t* session_create(
    uint32_t     sessionId,
	void         *pInstance,
    connection_t *connection
);

void session_cleanup(
    session_t *session
);

/**
  * Add address information of additional bulk buffer memory to session and
  * register virtual memory in kernel module.
  *
  * @attention The virtual address can only be added one time. If the virtual address already exist, NULL is returned.
  *
  * @param buf The virtual address of bulk buffer.
  * @param len Length of bulk buffer.
  *
  * @return On success the actual Bulk buffer descriptor with all address information is retured, NULL if an error occurs.
  */
bulkBufferDescriptor_t * session_addBulkBuf(
    session_t *session,
    addr_t    buf,
    uint32_t  len
);

/**
  * Remove address information of additional bulk buffer memory from session and
  * unregister virtual memory in kernel module
  *
  * @param buf The virtual address of the bulk buffer.
  *
  * @return true on success.
  */
bool session_removeBulkBuf(
    session_t *session,
    addr_t  buf
);

/**
  * Set additional error information of the last error that occured.
  *
  * @param errorCode The actual error.
  */
void session_setErrorInfo(
    session_t *session,
    int32_t err
);

/**
  * Get additional error information of the last error that occured.
  *
  * @attention After request the information is set to SESSION_ERR_NO.
  *
  * @return Last stored error code or SESSION_ERR_NO.
  */
int32_t session_getLastErr(
    session_t *session
);


typedef struct list_head sessionVector_t;

#endif /* SESSION_H_ */

/** @} */