summaryrefslogtreecommitdiff
path: root/src/libtnccs/plugins/tnccs_20/messages/pb_tnc_msg.h
blob: 35b0b7c26e9a770c2945b9910817df7fa5d3428a (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
/*
 * Copyright (C) 2010-213 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 pb_tnc_msg pb_tnc_msg
 * @{ @ingroup tnccs_20
 */

#ifndef PB_TNC_MSG_H_
#define PB_TNC_MSG_H_

typedef enum pb_tnc_msg_type_t pb_tnc_msg_type_t;
typedef struct pb_tnc_msg_info_t pb_tnc_msg_info_t;
typedef struct pb_tnc_msg_t pb_tnc_msg_t;

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

#define PB_TNC_VERSION		2

/**
 * PB-TNC Message Types as defined in section 4.3 of RFC 5793
 */
enum pb_tnc_msg_type_t {
	PB_MSG_EXPERIMENTAL =				0,
	PB_MSG_PA =							1,
	PB_MSG_ASSESSMENT_RESULT =			2,
	PB_MSG_ACCESS_RECOMMENDATION =		3,
	PB_MSG_REMEDIATION_PARAMETERS =		4,
	PB_MSG_ERROR =						5,
	PB_MSG_LANGUAGE_PREFERENCE =		6,
	PB_MSG_REASON_STRING =				7,
	PB_MSG_ROOF =						7
};

/**
 * enum name for pb_tnc_msg_type_t.
 */
extern enum_name_t *pb_tnc_msg_type_names;

/**
 * PB-TNC Message Type defined in the TCG namespace
 */
enum pb_tnc_tcg_msg_type_t {
	PB_TCG_MSG_RESERVED =				0,
	PB_TCG_MSG_PDP_REFERRAL =			1,
	PB_TCG_MSG_ROOF =					1
};

/**
 * enum name for pb_tnc_tcg_msg_type_t.
 */
extern enum_name_t *pb_tnc_tcg_msg_type_names;

/**
 * PB-TNC Message Type defined in the ITA namespace
 */
enum pb_tnc_ita_msg_type_t {
	PB_ITA_MSG_NOSKIP_TEST =			0,
	PB_ITA_MSG_MUTUAL_CAPABILITY =		1,
	PB_ITA_MSG_ROOF =					1
};

/**
 * enum name for pb_tnc_tcg_msg_type_t.
 */
extern enum_name_t *pb_tnc_ita_msg_type_names;

/**
 * Information entry describing a PB-TNC Message Type
 */
struct pb_tnc_msg_info_t {
	u_int32_t min_size;
	bool exact_size;
	bool in_result_batch;
	signed char has_noskip_flag;
};

#define	TRUE_OR_FALSE	2

/**
 * Information on PB-TNC Message Types
 */
extern pb_tnc_msg_info_t pb_tnc_msg_infos[];

/**
 * Information on PB-TNC TCG Message Types
 */
extern pb_tnc_msg_info_t pb_tnc_tcg_msg_infos[];

/**
 * Information on PB-TNC ITA Message Types
 */
extern pb_tnc_msg_info_t pb_tnc_ita_msg_infos[];

/**
 * Generic interface for all PB-TNC message types.
 *
 * To handle all messages in a generic way, this interface
 * must be implemented by each message type.
 */
struct pb_tnc_msg_t {

	/**
	 * Get the PB-TNC Message Type
	 *
	 * @return					 PB-TNC Message Type
	 */
	pen_type_t (*get_type)(pb_tnc_msg_t *this);

	/**
	 * Get the encoding of the PB-TNC Message Value
	 *
	 * @return					encoded PB-TNC Message Value
	 */
	chunk_t (*get_encoding)(pb_tnc_msg_t *this);

	/**
	 * Build the PB-TNC Message Value
	 */
	void (*build)(pb_tnc_msg_t *this);

	/**
	 * Process the PB-TNC Message Value
	 *
	 * @param					relative offset where an error occurred
	 * @return					return processing status
	 */
	status_t (*process)(pb_tnc_msg_t *this, u_int32_t *offset);

	/**
	 * Get a new reference to the message.
	 *
	 * @return			this, with an increased refcount
	 */
	pb_tnc_msg_t* (*get_ref)(pb_tnc_msg_t *this);

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

/**
 * Create an unprocessed PB-TNC message
 *
 * Useful for the parser which wants a generic constructor for all
 * pb_tnc_message_t types.
 *
 * @param msg_type			PB-TNC message type
 * @param value				PB-TNC message value
 */
pb_tnc_msg_t* pb_tnc_msg_create_from_data(pen_type_t msg_type, chunk_t value);

#endif /** PB_TNC_MSG_H_ @}*/