summaryrefslogtreecommitdiff
path: root/src/charon/encoding/payloads/payload.c
blob: 2c51c60dee8248a4a3350d5521a90d8c5b21b93d (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
168
169
170
171
172
173
174
175
176
177
178
/**
 * @file payload.c
 * 
 * @brief Generic constructor to the payload_t interface.
 * 
 * 
 */

/*
 * Copyright (C) 2007 Tobias Brunner
 * Copyright (C) 2005-2006 Martin Willi
 * Copyright (C) 2005 Jan Hutter
 * 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.
 */


#include "payload.h"

#include <encoding/payloads/ike_header.h>
#include <encoding/payloads/sa_payload.h>
#include <encoding/payloads/nonce_payload.h>
#include <encoding/payloads/id_payload.h>
#include <encoding/payloads/ke_payload.h>
#include <encoding/payloads/notify_payload.h>
#include <encoding/payloads/auth_payload.h>
#include <encoding/payloads/cert_payload.h>
#include <encoding/payloads/certreq_payload.h>
#include <encoding/payloads/encryption_payload.h>
#include <encoding/payloads/ts_payload.h>
#include <encoding/payloads/delete_payload.h>
#include <encoding/payloads/vendor_id_payload.h>
#include <encoding/payloads/cp_payload.h>
#include <encoding/payloads/configuration_attribute.h>
#include <encoding/payloads/eap_payload.h>
#include <encoding/payloads/unknown_payload.h>


ENUM_BEGIN(payload_type_names, NO_PAYLOAD, NO_PAYLOAD,
	"NO_PAYLOAD");
ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
	"SECURITY_ASSOCIATION",
	"KEY_EXCHANGE",
	"ID_INITIATOR",
	"ID_RESPONDER",
	"CERTIFICATE",
	"CERTIFICATE_REQUEST",
	"AUTHENTICATION",
	"NONCE",
	"NOTIFY",
	"DELETE",
	"VENDOR_ID",
	"TRAFFIC_SELECTOR_INITIATOR",
	"TRAFFIC_SELECTOR_RESPONDER",
	"ENCRYPTED",
	"CONFIGURATION",
	"EXTENSIBLE_AUTHENTICATION");
#ifdef P2P
ENUM_NEXT(payload_type_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
	"ID_PEER");
ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
#else
ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
#endif /* P2P */
	"HEADER",
	"PROPOSAL_SUBSTRUCTURE",
	"TRANSFORM_SUBSTRUCTURE",
	"TRANSFORM_ATTRIBUTE",
	"TRAFFIC_SELECTOR_SUBSTRUCTURE",
	"CONFIGURATION_ATTRIBUTE",
	"UNKNOWN_PAYLOAD");
ENUM_END(payload_type_names, UNKNOWN_PAYLOAD);

/* short forms of payload names */
ENUM_BEGIN(payload_type_short_names, NO_PAYLOAD, NO_PAYLOAD,
	"--");
ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
	"SA",
	"KE",
	"IDi",
	"IDr",
	"CERT",
	"CERTREQ",
	"AUTH",
	"No",
	"N",
	"D",
	"V",
	"TSi",
	"TSr",
	"E",
	"CP",
	"EAP");
#ifdef P2P
ENUM_NEXT(payload_type_short_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
	"IDp");
ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
#else
ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
#endif /* P2P */
	"HDR",
	"PROP",
	"TRANS",
	"TRANSATTR",
	"TSSUB",
	"CPATTR",
	"??");
ENUM_END(payload_type_short_names, UNKNOWN_PAYLOAD);

/*
 * see header
 */
payload_t *payload_create(payload_type_t type)
{
	switch (type)
	{
		case HEADER:
			return (payload_t*)ike_header_create();
		case SECURITY_ASSOCIATION:
			return (payload_t*)sa_payload_create();
		case PROPOSAL_SUBSTRUCTURE:
			return (payload_t*)proposal_substructure_create();
		case TRANSFORM_SUBSTRUCTURE:
			return (payload_t*)transform_substructure_create();
		case TRANSFORM_ATTRIBUTE:
			return (payload_t*)transform_attribute_create();
		case NONCE:
			return (payload_t*)nonce_payload_create();
		case ID_INITIATOR:
			return (payload_t*)id_payload_create(ID_INITIATOR);
		case ID_RESPONDER:
			return (payload_t*)id_payload_create(ID_RESPONDER);
#ifdef P2P
		case ID_PEER:
			return (payload_t*)id_payload_create(ID_PEER);
#endif /* P2P */
		case AUTHENTICATION:
			return (payload_t*)auth_payload_create();
		case CERTIFICATE:
			return (payload_t*)cert_payload_create();
		case CERTIFICATE_REQUEST:
			return (payload_t*)certreq_payload_create();
		case TRAFFIC_SELECTOR_SUBSTRUCTURE:
			return (payload_t*)traffic_selector_substructure_create();
		case TRAFFIC_SELECTOR_INITIATOR:
			return (payload_t*)ts_payload_create(TRUE);
		case TRAFFIC_SELECTOR_RESPONDER:
			return (payload_t*)ts_payload_create(FALSE);
		case KEY_EXCHANGE:
			return (payload_t*)ke_payload_create();
		case NOTIFY:
			return (payload_t*)notify_payload_create();
		case DELETE:
			return (payload_t*)delete_payload_create(0);
		case VENDOR_ID:
			return (payload_t*)vendor_id_payload_create();
		case CONFIGURATION:
			return (payload_t*)cp_payload_create();
		case CONFIGURATION_ATTRIBUTE:
			return (payload_t*)configuration_attribute_create();
		case EXTENSIBLE_AUTHENTICATION:
			return (payload_t*)eap_payload_create();
		case ENCRYPTED:
			return (payload_t*)encryption_payload_create();
		default:
			return (payload_t*)unknown_payload_create();
	}
}