summaryrefslogtreecommitdiff
path: root/src/libimcv/seg/seg_contract.h
blob: afbf309340e6761d359c1e58d6ada0b2390c6a19 (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
179
180
181
182
/*
 * Copyright (C) 2014-2015 Andreas Steffen
 * HSR Hochschule fuer Technik Rapperswil
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
 *
 * 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.
 */

/**
 * @defgroup seg_contract seg_contract
 * @{ @ingroup libimcv_seg
 */

#ifndef SEG_CONTRACT_H_
#define SEG_CONTRACT_H_

typedef struct seg_contract_t seg_contract_t;

#include "pa_tnc/pa_tnc_attr.h"

#include <library.h>
#include <pen/pen.h>

#include <tncif.h>

#define SEG_CONTRACT_MAX_SIZE_VALUE		0xffffffff
#define SEG_CONTRACT_NO_FRAGMENTATION	SEG_CONTRACT_MAX_SIZE_VALUE

/**
 * Interface for a PA-TNC attribute segmentation contract
 *
 */
struct seg_contract_t {

	/**
	 * Get the PA-TNC message type.
	 *
	 * @return					PA-TNC Message type
	 */
	pen_type_t (*get_msg_type)(seg_contract_t *this);

	/**
	 * Set maximum PA-TNC attribute and segment size in octets
	 *
	 * @param max_attr_size	Maximum PA-TNC attribute size in octets
	 * @param max_seg_size	Maximum PA-TNC attribute segment size in octets
	 */
	void (*set_max_size)(seg_contract_t *this, uint32_t max_attr_size,
											   uint32_t max_seg_size);

	/**
	 * Get maximum PA-TNC attribute and segment size in octets
	 *
	 * @param max_attr_size	Maximum PA-TNC attribute size in octets
	 * @param max_seg_size	Maximum PA-TNC attribute segment size in octets
	 */
	void (*get_max_size)(seg_contract_t *this, uint32_t *max_attr_size,
											   uint32_t *max_seg_size);

	/**
	 * Check if a PA-TNC attribute must be segmented or is oversized
	 *
	 * @param attr			PA-TNC attribute to be checked
	 * @param oversize		PA-TNC attribute is larger than maximum size
	 * @return				TRUE if PA-TNC attribute must be segmented
	 */
	bool (*check_size)(seg_contract_t *this, pa_tnc_attr_t *attr,
											 bool *oversize);

	/**
	 * Generate first segment of a PA-TNC attribute according to the contract
	 *
	 * @param attr			PA-TNC attribute to be segmented
	 * @param max_attr_len	Maximum size of first segment envelope attribute
	 * @return				First segment envelope attribute
	 */
	pa_tnc_attr_t* (*first_segment)(seg_contract_t *this, pa_tnc_attr_t *attr,
									size_t max_attr_len);

	/**
	 * Generate next segment of a PA-TNC attribute according to the contract
	 *
	 * @param base_attr_id	Base Attribute ID
	 * @return				Next segment envelope attribute
	 */
	pa_tnc_attr_t* (*next_segment)(seg_contract_t *this, uint32_t base_attr_id);

	/**
	 * Add an attribute segments until the PA-TNC attribute is reconstructed
	 *
	 * @param attr			Segment envelope attribute
	 * @param error			Error attribute if an error occurred or NULL
	 * @param more			Need more segments
	 * @return				Completed PA-TNC attribute or NULL
	 */
	pa_tnc_attr_t* (*add_segment)(seg_contract_t *this,
								 pa_tnc_attr_t *attr, pa_tnc_attr_t **error,
								 bool *more);

	/**
	 * Get contract role
	 *
	 * @return				TRUE:  contracting party (issuer),
	 *						FALSE: contracted party
	 */
	bool (*is_issuer)(seg_contract_t *this);

	/**
	 * Is this a null contract ?
	 *
	 * @return				TRUE if null contract
	 */
	bool (*is_null)(seg_contract_t *this);

	/**
	 * Set the responder ID
	 *
	 * @param responder		IMC or IMV ID of responder
	 */
	void (*set_responder)(seg_contract_t *this, TNC_UInt32 responder);

	/**
	 * Get the responder ID
	 *
	 * @return				IMC or IMV ID of responder
	 */
	TNC_UInt32 (*get_responder)(seg_contract_t *this);

	/**
	 * Get the issuer ID
	 *
	 * @return				IMC or IMV ID of issuer
	 */
	TNC_UInt32 (*get_issuer)(seg_contract_t *this);

	/**
	 * Clone a contract
	 *
	 * @return				Cloned contract
	 */
	seg_contract_t* (*clone)(seg_contract_t *this);

	/**
	 * Get an info string about the contract
	 *
	 * @param buf			String buffer of at least size len
	 * @param len			Size of string buffer
	 * @param request		TRUE if contract request, FALSE if response
	 */
	void (*get_info_string)(seg_contract_t *this, char *buf, size_t len,
							bool request);

	/**
	 * Destroys a seg_contract_t object.
	 */
	void (*destroy)(seg_contract_t *this);
};

/**
 * Create a PA-TNC attribute segmentation contract
 *
 * @param msg_type			PA-TNC message type
 * @param max_attr_size		Maximum PA-TNC attribute size in octets
 * @param max_seg_size		Maximum PA-TNC attribute segment size in octets
 * @param is_issuer			TRUE if issuer of the contract
 * @param issuer_id			IMC or IMV ID of issuer
 * @param is_imc			TRUE if IMC, FALSE if IMV
 */
seg_contract_t* seg_contract_create(pen_type_t msg_type,
									uint32_t max_attr_size,
									uint32_t max_seg_size,
									bool is_issuer, TNC_UInt32 issuer_id,
									bool is_imc);

#endif /** SEG_CONTRACT_H_ @}*/