23676a9f4335c2fc576709b7eb36729a9be3c2a5
[strongswan.git] / src / libimcv / seg / seg_contract.h
1 /*
2 * Copyright (C) 2014 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 /**
17 * @defgroup seg_contract seg_contract
18 * @{ @ingroup libimcv_seg
19 */
20
21 #ifndef SEG_CONTRACT_H_
22 #define SEG_CONTRACT_H_
23
24 typedef struct seg_contract_t seg_contract_t;
25
26 #include "pa_tnc/pa_tnc_attr.h"
27
28 #include <library.h>
29 #include <pen/pen.h>
30
31 #include <tncif.h>
32
33 #define SEG_CONTRACT_MAX_SIZE_VALUE 0xffffffff
34 #define SEG_CONTRACT_NO_FRAGMENTATION SEG_CONTRACT_MAX_SIZE_VALUE
35
36 /**
37 * Interface for a PA-TNC attribute segmentation contract
38 *
39 */
40 struct seg_contract_t {
41
42 /**
43 * Get the PA-TNC message type.
44 *
45 * @return PA-TNC Message type
46 */
47 pen_type_t (*get_msg_type)(seg_contract_t *this);
48
49 /**
50 * Set maximum PA-TNC attribute and segment size in octets
51 *
52 * @param max_attr_size Maximum PA-TNC attribute size in octets
53 * @param max_seg_size Maximum PA-TNC attribute segment size in octets
54 */
55 void (*set_max_size)(seg_contract_t *this, uint32_t max_attr_size,
56 uint32_t max_seg_size);
57
58 /**
59 * Get maximum PA-TNC attribute and segment size in octets
60 *
61 * @param max_attr_size Maximum PA-TNC attribute size in octets
62 * @param max_seg_size Maximum PA-TNC attribute segment size in octets
63 */
64 void (*get_max_size)(seg_contract_t *this, uint32_t *max_attr_size,
65 uint32_t *max_seg_size);
66
67 /**
68 * Check if a PA-TNC attribute must be segmented or is oversized
69 *
70 * @param attr PA-TNC attribute to be checked
71 * @param oversize PA-TNC attribute is larger than maximum size
72 * @return TRUE if PA-TNC attribute must be segmented
73 */
74 bool (*check_size)(seg_contract_t *this, pa_tnc_attr_t *attr,
75 bool *oversize);
76
77 /**
78 * Generate first segment of a PA-TNC attribute according to the contract
79 *
80 * @param attr PA-TNC attribute to be segmented
81 * @return First segment envelope attribute
82 */
83 pa_tnc_attr_t* (*first_segment)(seg_contract_t *this, pa_tnc_attr_t *attr);
84
85 /**
86 * Generate next segment of a PA-TNC attribute according to the contract
87 *
88 * @param base_attr_id Base Attribute ID
89 * @return Next segment envelope attribute
90 */
91 pa_tnc_attr_t* (*next_segment)(seg_contract_t *this, uint32_t base_attr_id);
92
93 /**
94 * Add an attribute segments until the PA-TNC attribute is reconstructed
95 *
96 * @param attr Segment envelope attribute
97 * @param error Error attribute if an error occurred or NULL
98 * @param more Need more segments
99 * @return Completed PA-TNC attribute or NULL
100 */
101 pa_tnc_attr_t* (*add_segment)(seg_contract_t *this,
102 pa_tnc_attr_t *attr, pa_tnc_attr_t **error,
103 bool *more);
104
105 /**
106 * Get contract role
107 *
108 * @return TRUE: contracting party (issuer),
109 * FALSE: contracted party
110 */
111 bool (*is_issuer)(seg_contract_t *this);
112
113 /**
114 * Is this a null contract ?
115 *
116 * @return TRUE if null contract
117 */
118 bool (*is_null)(seg_contract_t *this);
119
120 /**
121 * Set the responder ID
122 *
123 * @param responder IMC or IMV ID of responder
124 */
125 void (*set_responder)(seg_contract_t *this, TNC_UInt32 responder);
126
127 /**
128 * Get the responder ID
129 *
130 * @return IMC or IMV ID of responder
131 */
132 TNC_UInt32 (*get_responder)(seg_contract_t *this);
133
134 /**
135 * Get the issuer ID
136 *
137 * @return IMC or IMV ID of issuer
138 */
139 TNC_UInt32 (*get_issuer)(seg_contract_t *this);
140
141 /**
142 * Clone a contract
143 *
144 * @return Cloned contract
145 */
146 seg_contract_t* (*clone)(seg_contract_t *this);
147
148 /**
149 * Get an info string about the contract
150 *
151 * @param buf String buffer of at least size len
152 * @param len Size of string buffer
153 * @param request TRUE if contract request, FALSE if response
154 */
155 void (*get_info_string)(seg_contract_t *this, char *buf, size_t len,
156 bool request);
157
158 /**
159 * Destroys a seg_contract_t object.
160 */
161 void (*destroy)(seg_contract_t *this);
162 };
163
164 /**
165 * Create a PA-TNC attribute segmentation contract
166 *
167 * @param msg_type PA-TNC message type
168 * @param max_attr_size Maximum PA-TNC attribute size in octets
169 * @param max_seg_size Maximum PA-TNC attribute segment size in octets
170 * @param is_issuer TRUE if issuer of the contract
171 * @param issuer_id IMC or IMV ID of issuer
172 * @param is_imc TRUE if IMC, FALSE if IMV
173 */
174 seg_contract_t* seg_contract_create(pen_type_t msg_type,
175 uint32_t max_attr_size,
176 uint32_t max_seg_size,
177 bool is_issuer, TNC_UInt32 issuer_id,
178 bool is_imc);
179
180 #endif /** SEG_CONTRACT_H_ @}*/