Merged libpts into libimcv
[strongswan.git] / src / libimcv / imc / imc_msg.h
1 /*
2 * Copyright (C) 2012-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 imc_msg imc_msg
18 * @{ @ingroup libimcv_imc
19 */
20
21 #ifndef IMC_MSG_H_
22 #define IMC_MSG_H_
23
24 #include <imc/imc_agent.h>
25
26 typedef struct imc_msg_t imc_msg_t;
27
28 #include <library.h>
29
30 /**
31 * Interface for a PA-TNC message handled by an IMC.
32 *
33 */
34 struct imc_msg_t {
35
36 /**
37 * Get source ID of PA-TNC message
38 *
39 * @return src ID
40 */
41 TNC_UInt32 (*get_src_id)(imc_msg_t *this);
42
43 /**
44 * Get destination ID of PA-TNC message
45 *
46 * @return destination ID
47 */
48 TNC_UInt32 (*get_dst_id)(imc_msg_t *this);
49
50 /**
51 * Get the PA-TNC message type.
52 *
53 * @return message type
54 */
55 pen_type_t (*get_msg_type)(imc_msg_t *this);
56
57 /**
58 * Sends one or multiple PA-TNC messages
59 *
60 * @param excl set the excl message flag if supported
61 * @return TNC result code
62 */
63 TNC_Result (*send)(imc_msg_t *this, bool excl);
64
65 /**
66 * Processes a received PA-TNC message
67 *
68 * @param out_msg outgoing PA-TN message
69 * @param fatal_error TRUE if IMV sent a fatal error message
70 * @return TNC result code
71 */
72 TNC_Result (*receive)(imc_msg_t *this, imc_msg_t *out_msg,
73 bool *fatal_error);
74
75 /**
76 * Add a PA-TNC attribute to the send queue
77 *
78 * @param attr PA-TNC attribute to be added
79 */
80 void (*add_attribute)(imc_msg_t *this, pa_tnc_attr_t *attr);
81
82 /**
83 * Enumerator over PA-TNC attributes contained in the PA-TNC message
84 *
85 * @return PA-TNC attribute enumerator
86 */
87 enumerator_t* (*create_attribute_enumerator)(imc_msg_t *this);
88
89 /**
90 * Get the encoding of the IMC message.
91 *
92 * @return message encoding, internal data
93 */
94 chunk_t (*get_encoding)(imc_msg_t *this);
95
96 /**
97 * Destroys a imc_msg_t object.
98 */
99 void (*destroy)(imc_msg_t *this);
100 };
101
102 /**
103 * Create a wrapper for an outbound message
104 *
105 * @param agent IMC agent responsible for the message
106 * @param state IMC state for the given connection ID
107 * @param connection_id connection ID
108 * @param src_id source IMC ID
109 * @param dst_id destination IMV ID
110 * @param msg_type PA-TNC message type
111 */
112 imc_msg_t* imc_msg_create(imc_agent_t *agent, imc_state_t *state,
113 TNC_ConnectionID connection_id,
114 TNC_UInt32 src_id, TNC_UInt32 dst_id,
115 pen_type_t msg_type);
116
117 /**
118 * Create a wrapper for an outbound message based on a received message
119 *
120 * @param msg received message the reply is based on
121 */
122 imc_msg_t* imc_msg_create_as_reply(imc_msg_t *msg);
123
124 /**
125 * Create a wrapper around message data received via the legacy IF-IMC interface
126 *
127 * @param agent IMC agent responsible for the message
128 * @param state IMC state for the given connection ID
129 * @param connection_id connection ID
130 * @param msg_type PA-TNC message type
131 * @param msg received PA-TNC message blob
132 */
133 imc_msg_t* imc_msg_create_from_data(imc_agent_t *agent, imc_state_t *state,
134 TNC_ConnectionID connection_id,
135 TNC_MessageType msg_type,
136 chunk_t msg);
137
138 /**
139 * Create a wrapper around message data received via the long IF-IMC interface
140 *
141 * @param agent IMC agent responsible for the message
142 * @param state IMC state for the given connection ID
143 * @param connection_id connection ID
144 * @param src_id source IMV ID
145 * @param dst_id destination IMC ID
146 * @param msg_vid PA-TNC message vendor ID
147 * @param msg_subtype PA-TNC subtype
148 * @param msg received PA-TNC message blob
149 */
150 imc_msg_t* imc_msg_create_from_long_data(imc_agent_t *agent, imc_state_t *state,
151 TNC_ConnectionID connection_id,
152 TNC_UInt32 src_id, TNC_UInt32 dst_id,
153 TNC_VendorID msg_vid,
154 TNC_MessageSubtype msg_subtype,
155 chunk_t msg);
156
157 #endif /** IMC_MSG_H_ @}*/