summaryrefslogtreecommitdiff
path: root/src/libtnccs/plugins/tnccs_20/batch/pb_tnc_batch.h
blob: 6089c7d2eee4009759d6994173423d5ce0827435 (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
/*
 * Copyright (C) 2010-2015 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_batch pb_tnc_batch
 * @{ @ingroup tnccs_20
 */

#ifndef PB_TNC_BATCH_H_
#define PB_TNC_BATCH_H_

typedef enum pb_tnc_batch_type_t pb_tnc_batch_type_t;
typedef struct pb_tnc_batch_t pb_tnc_batch_t;

#include "messages/pb_tnc_msg.h"
#include "state_machine/pb_tnc_state_machine.h"

#include <library.h>

#define PB_TNC_BATCH_HEADER_SIZE	 8
#define PB_TNC_MSG_HEADER_SIZE		12

/**
  * PB-TNC Batch Types as defined in section 4.1 of RFC 5793
 */
enum pb_tnc_batch_type_t {
	PB_BATCH_NONE =		0,	/* for internal use only */
	PB_BATCH_CDATA =	1,
	PB_BATCH_SDATA =	2,
	PB_BATCH_RESULT =	3,
	PB_BATCH_CRETRY =	4,
	PB_BATCH_SRETRY =	5,
	PB_BATCH_CLOSE =	6,
	PB_BATCH_ROOF =		6
};

/**
 * enum name for pb_tnc_batch_type_t.
 */
extern enum_name_t *pb_tnc_batch_type_names;

/**
 * Interface for all PB-TNC Batch Types.
 */
struct pb_tnc_batch_t {

	/**
	 * Get the PB-TNC Message Type
	 *
	 * @return				PB-TNC batch type
	 */
	pb_tnc_batch_type_t (*get_type)(pb_tnc_batch_t *this);

	/**
	 * Get the encoding of the PB-TNC Batch
	 *
	 * @return				encoded PB-TNC batch
	 */
	chunk_t (*get_encoding)(pb_tnc_batch_t *this);

	/**
	 * Add a PB-TNC Message
	 *
	 * @param msg			PB-TNC message to be addedd
	 * @return				TRUE if message fit into batch and was added
	 */
	bool (*add_msg)(pb_tnc_batch_t *this, pb_tnc_msg_t* msg);

	/**
	 * Build the PB-TNC Batch
	 */
	void (*build)(pb_tnc_batch_t *this);

	/**
	 * Process the PB-TNC Batch header
	 *
	 * @param directionality	TRUE if no mutual TNC measurements
	 * @param is_server			TRUE if called by TNC server
	 * @param from_server		TRUE if sent by TNC server
	 * @return					return processing status
	 */
	status_t (*process_header)(pb_tnc_batch_t *this, bool directionality,
							   bool is_server, bool *from_server);

	/**
	 * Process the PB-TNC Batch
	 *
	 * @param state_machine		PB-TNC state machine
	 * @return					return processing status
	 */
	status_t (*process)(pb_tnc_batch_t *this,
						pb_tnc_state_machine_t *state_machine);

	/**
	 * Enumerates over all PB-TNC Messages
	 *
	 * @return					return message enumerator
	 */
	enumerator_t* (*create_msg_enumerator)(pb_tnc_batch_t *this);

	/**
	 * Enumerates over all parsing errors
	 *
	 * @return					return error enumerator
	 */
	enumerator_t* (*create_error_enumerator)(pb_tnc_batch_t *this);

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

/**
 * Create an empty PB-TNC Batch of a given type
 *
 * @param is_server				TRUE if server, FALSE if client
 * @param type					PB-TNC batch type
 * @param max_batch_len			maximum size the PB-TNC batch
 */
pb_tnc_batch_t* pb_tnc_batch_create(bool is_server, pb_tnc_batch_type_t type,
									size_t max_batch_len);

/**
 * Create an unprocessed PB-TNC Batch from data
 *
 * @param  data				encoded PB-TNC batch
 */
pb_tnc_batch_t* pb_tnc_batch_create_from_data(chunk_t data);

#endif /** PB_TNC_BATCH_H_ @}*/