2 * Copyright (C) 2010 Sansar Choinyanbuu
3 * HSR Hochschule fuer Technik Rapperswil
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>.
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
20 #include <tnc/tncif.h>
21 #include <tnc/tnccs/tnccs.h>
23 typedef struct private_tnccs_20_t private_tnccs_20_t
;
26 * Private data of a tnccs_20_t object.
28 struct private_tnccs_20_t
{
31 * Public tls_t interface.
36 * TNCC if TRUE, TNCS if FALSE
41 * Connection ID assigned to this TNCCS connection
43 TNC_ConnectionID connection_id
;
46 METHOD(tls_t
, process
, status_t
,
47 private_tnccs_20_t
*this, void *buf
, size_t buflen
)
49 if (this->is_server
&& !this->connection_id
)
51 this->connection_id
= charon
->tnccs
->create_connection(charon
->tnccs
,
53 charon
->imvs
->notify_connection_change(charon
->imvs
,
54 this->connection_id
, TNC_CONNECTION_STATE_CREATE
);
56 DBG1(DBG_TNC
, "received TNCCS Batch (%u bytes) for Connection ID %u",
57 buflen
, this->connection_id
);
58 DBG3(DBG_TNC
, "%.*s", buflen
, buf
);
63 METHOD(tls_t
, build
, status_t
,
64 private_tnccs_20_t
*this, void *buf
, size_t *buflen
, size_t *msglen
)
68 if (!this->is_server
&& !this->connection_id
)
70 this->connection_id
= charon
->tnccs
->create_connection(charon
->tnccs
,
72 charon
->imcs
->notify_connection_change(charon
->imcs
,
73 this->connection_id
, TNC_CONNECTION_STATE_CREATE
);
74 charon
->imcs
->notify_connection_change(charon
->imcs
,
75 this->connection_id
, TNC_CONNECTION_STATE_HANDSHAKE
);
76 charon
->imcs
->begin_handshake(charon
->imcs
, this->connection_id
);
79 msg
= this->is_server ?
"tncs-tncc 2.0" : "tncc-tncs 2.0";
80 DBG1(DBG_TNC
, "sending TNCCS Batch (%d bytes) for Connection ID %u",
81 strlen(msg
), this->connection_id
);
82 DBG3(DBG_TNC
, "%s", msg
);
83 *msglen
= strlen(msg
);
84 memcpy(buf
, msg
, *msglen
);
90 METHOD(tls_t
, is_server
, bool,
91 private_tnccs_20_t
*this)
93 return this->is_server
;
96 METHOD(tls_t
, get_purpose
, tls_purpose_t
,
97 private_tnccs_20_t
*this)
99 return TLS_PURPOSE_EAP_TNC
;
102 METHOD(tls_t
, is_complete
, bool,
103 private_tnccs_20_t
*this)
108 METHOD(tls_t
, get_eap_msk
, chunk_t
,
109 private_tnccs_20_t
*this)
114 METHOD(tls_t
, destroy
, void,
115 private_tnccs_20_t
*this)
117 charon
->tnccs
->remove_connection(charon
->tnccs
, this->connection_id
);
124 tls_t
*tnccs_20_create(bool is_server
)
126 private_tnccs_20_t
*this;
132 .is_server
= _is_server
,
133 .get_purpose
= _get_purpose
,
134 .is_complete
= _is_complete
,
135 .get_eap_msk
= _get_eap_msk
,
138 .is_server
= is_server
,
141 return &this->public;