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
|
/*
* Copyright (c) 2013 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_KAPI_SESSION_H_
#define _MC_KAPI_SESSION_H_
#include "common.h"
#include <linux/list.h>
#include "connection.h"
struct bulk_buffer_descriptor {
void *virt_addr; /* The VA of the Bulk buffer */
uint32_t len; /* Length of the Bulk buffer */
uint32_t handle;
/* The list param for using the kernel lists*/
struct list_head list;
};
struct bulk_buffer_descriptor *bulk_buffer_descriptor_create(
void *virt_addr,
uint32_t len,
uint32_t handle
);
/*
* Session states.
* At the moment not used !!
*/
enum session_state {
SESSION_STATE_INITIAL,
SESSION_STATE_OPEN,
SESSION_STATE_TRUSTLET_DEAD
};
#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.
*/
struct session_information {
enum session_state state; /* Session state */
int32_t last_error; /* Last error of session */
};
struct session {
struct mc_instance *instance;
/* Descriptors of additional bulk buffer of a session */
struct list_head bulk_buffer_descriptors;
/* Information about session */
struct session_information session_info;
uint32_t session_id;
struct connection *notification_connection;
/* The list param for using the kernel lists */
struct list_head list;
};
struct session *session_create(
uint32_t session_id,
void *instance,
struct connection *connection
);
void session_cleanup(struct session *session);
/*
* session_add_bulk_buf() - Add address information of additional bulk
* buffer memory to session and register virtual
* memory in kernel module
* @session: Session information structure
* @buf: The virtual address of bulk buffer.
* @len: Length of bulk buffer.
*
* The virtual address can only be added one time. If the virtual
* address already exist, NULL is returned.
*
* On success the actual Bulk buffer descriptor with all address information
* is returned, NULL if an error occurs.
*/
struct bulk_buffer_descriptor *session_add_bulk_buf(
struct session *session, void *buf, uint32_t len);
/*
* session_remove_bulk_buf() - Remove address information of additional bulk
* buffer memory from session and unregister
* virtual memory in kernel module
* @session: Session information structure
* @buf: The virtual address of the bulk buffer
*
* Returns true on success
*/
bool session_remove_bulk_buf(struct session *session, void *buf);
/*
* session_find_bulk_buf() - Find the handle of the bulk buffer for this
* session
*
* @session: Session information structure
* @buf: The virtual address of bulk buffer.
*
* On success the actual Bulk buffer handle is returned, 0
* if an error occurs.
*/
uint32_t session_find_bulk_buf(struct session *session, void *virt_addr);
/*
* session_set_error_info() - Set additional error information of the last
* error that occurred.
* @session: Session information structure
* @err: The actual error
*/
void session_set_error_info(struct session *session, int32_t err);
/*
* session_get_last_err() - Get additional error information of the last
* error that occurred.
* @session: Session information structure
*
* After request the information is set to SESSION_ERR_NO.
*
* Returns the last stored error code or SESSION_ERR_NO
*/
int32_t session_get_last_err(struct session *session);
#endif /* _MC_KAPI_SESSION_H_ */
|