aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtnccs/plugins/tnccs_20/messages/ietf/pb_error_msg.h
blob: 9c0ad82a66a61bb2f88a6edbc2760204da6ca4f4 (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
/*
 * Copyright (C) 2010 Sansar Choinyambuu
 * 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_error_msg pb_error_msg
 * @{ @ingroup tnccs_20
 */

#ifndef PB_ERROR_MSG_H_
#define PB_ERROR_MSG_H_

typedef enum pb_tnc_error_code_t pb_tnc_error_code_t;
typedef struct pb_error_msg_t pb_error_msg_t;

#include "messages/pb_tnc_msg.h"

/**
 * PB-TNC Error Codes as defined in section 4.9.1 of RFC 5793
 */
enum  pb_tnc_error_code_t {
	PB_ERROR_UNEXPECTED_BATCH_TYPE =		0,
	PB_ERROR_INVALID_PARAMETER =			1,
	PB_ERROR_LOCAL_ERROR =					2,
	PB_ERROR_UNSUPPORTED_MANDATORY_MSG =	3,
	PB_ERROR_VERSION_NOT_SUPPORTED =		4
};

/**
 * enum name for pb_tnc_error_code_t.
 */
extern enum_name_t *pb_tnc_error_code_names;

/**
 * Class representing the PB-Error message type.
 */
struct pb_error_msg_t {

	/**
	 * PB-TNC Message interface
	 */
	pb_tnc_msg_t pb_interface;

	/**
	 * Get the fatal flag
	 *
	 * @return				fatal flag
	 */
	bool (*get_fatal_flag)(pb_error_msg_t *this);

	/**
	 * Get PB Error code Vendor ID
	 *
	 * @return				PB Error Code Vendor ID
	 */
	u_int32_t (*get_vendor_id)(pb_error_msg_t *this);

	/**
	 * Get PB Error Code
	 *
	 * @return				PB Error Code
	 */
	u_int16_t (*get_error_code)(pb_error_msg_t *this);

	/**
	 * Get the PB Error Offset
	 *
	 * @return				PB Error Offset
	 */
	u_int32_t (*get_offset)(pb_error_msg_t *this);

	/**
	 * Get the PB Bad Version
	 *
	 * @return				PB Bad Version
	 */
	u_int8_t (*get_bad_version)(pb_error_msg_t *this);

	/**
	 * Set the PB Bad Version
	 *
	 * @param version		PB Bad Version
	 */
	void (*set_bad_version)(pb_error_msg_t *this, u_int8_t version);
};

/**
 * Create a PB-Error message from parameters
 *
 * @param fatal				fatal flag
 * @param vendor_id			Error Code Vendor ID
 * @param error_code		Error Code
 */
pb_tnc_msg_t* pb_error_msg_create(bool fatal, u_int32_t vendor_id,
								  pb_tnc_error_code_t error_code);
	
/**
 * Create a PB-Error message from parameters with offset field
 *
 * @param fatal				fatal flag
 * @param vendor_id			Error Code Vendor ID
 * @param error_code		Error Code
 * @param error_offset		Error Offset
 */
pb_tnc_msg_t* pb_error_msg_create_with_offset(bool fatal, u_int32_t vendor_id,
											  pb_tnc_error_code_t error_code,
											  u_int32_t error_offset);

/**
 * Create an unprocessed PB-Error message from raw data
 *
 * @param data				PB-Error message data
 */
pb_tnc_msg_t* pb_error_msg_create_from_data(chunk_t data);

#endif /** PB_PA_MSG_H_ @}*/