summaryrefslogtreecommitdiff
path: root/src/libtnccs/plugins/tnccs_20/state_machine/pb_tnc_state_machine.h
blob: aa317041e971d2e6e214beccb6806d08e2149016 (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
/*
 * Copyright (C) 2010 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_state_machine pb_tnc_state_machine
 * @{ @ingroup tnccs_20
 */

#ifndef PB_TNC_STATE_MACHINE_H_
#define PB_TNC_STATE_MACHINE_H_

typedef struct pb_tnc_state_machine_t pb_tnc_state_machine_t;
typedef enum pb_tnc_state_t pb_tnc_state_t;

#include "batch/pb_tnc_batch.h"

#include <library.h>

/**
 * PB-TNC States (state machine) as defined in section 3.2 of RFC 5793
 */
enum pb_tnc_state_t {
	PB_STATE_INIT,
	PB_STATE_SERVER_WORKING,
	PB_STATE_CLIENT_WORKING,
	PB_STATE_DECIDED,
	PB_STATE_END,
};

/**
 * enum name for pb_tnc_state_t.
 */
extern enum_name_t *pb_tnc_state_names;

/**
 * Interface for the PB-TNC state machine.
 */
struct pb_tnc_state_machine_t {

	/**
	 * Get the current PB-TNC STATE
	 *
	 * @return				current state
	 */
	pb_tnc_state_t (*get_state)(pb_tnc_state_machine_t *this);

	/**
	 * Compute state transition due to received PB-TNC Batch
	 *
	 * @param type			type of received batch
	 * @result				TRUE if a valid transition was found, FALSE otherwise
	 */
	bool (*receive_batch)(pb_tnc_state_machine_t *this, pb_tnc_batch_type_t type);

	/**
	 * Compute state transition due to sent PB-TNC Batch
	 *
	 * @param type			type of sent batch
	 * @result				TRUE if a valid transition was found, FALSE otherwise
	 */
	bool (*send_batch)(pb_tnc_state_machine_t *this, pb_tnc_batch_type_t type);

	/**
	 * Informs whether the last received PB-TNC CDATA Batch was empty
	 *
	 * @result				TRUE if last received PB-TNC CDATA Batch was empty
	 */
	bool (*get_empty_cdata)(pb_tnc_state_machine_t *this);

	/**
	 * Store information whether the received PB-TNC CDATA Batch was empty
	 *
	 * @param empty			set to TRUE if received PB-TNC CDATA Batch was empty
	 */
	void (*set_empty_cdata)(pb_tnc_state_machine_t *this, bool empty);

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

/**
 * Create and initialize a PB-TNC state machine
 *
 * @param is_server		TRUE if PB-TNC server, FALSE if PB-TNC client
 */
pb_tnc_state_machine_t* pb_tnc_state_machine_create(bool is_server);

#endif /** PB_TNC_STATE_MACHINE_H_ @}*/