48828c472a2e74a7e583e869ad22e7bca085485f
[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
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 * Get an info string about the contract
122 *
123 * @param buf String buffer of at least size len
124 * @param len Size of string buffer
125 * @param request TRUE if contract request, FALSE if response
126 */
127 void (*get_info_string)(seg_contract_t *this, char *buf, size_t len,
128 bool request);
129
130 /**
131 * Destroys a seg_contract_t object.
132 */
133 void (*destroy)(seg_contract_t *this);
134 };
135
136 /**
137 * Create a PA-TNC attribute segmentation contract
138 *
139 * @param msg_type PA-TNC message type
140 * @param max_attr_size Maximum PA-TNC attribute size in octets
141 * @param max_seg_size Maximum PA-TNC attribute segment size in octets
142 * @param is_issuer TRUE if issuer of the contract
143 * @param issuer_id IMC or IMV ID of issuer
144 * @param is_imc TRUE if IMC, FALSE if IMV
145 */
146 seg_contract_t* seg_contract_create(pen_type_t msg_type,
147 uint32_t max_attr_size,
148 uint32_t max_seg_size,
149 bool is_issuer, TNC_UInt32 issuer_id,
150 bool is_imc);
151
152 #endif /** SEG_CONTRACT_H_ @}*/