Moving charon to libcharon.
[strongswan.git] / src / libcharon / encoding / payloads / payload.c
1 /*
2 * Copyright (C) 2007 Tobias Brunner
3 * Copyright (C) 2005-2006 Martin Willi
4 * Copyright (C) 2005 Jan Hutter
5 * Hochschule fuer Technik Rapperswil
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 * for more details.
16 */
17
18
19 #include "payload.h"
20
21 #include <encoding/payloads/ike_header.h>
22 #include <encoding/payloads/sa_payload.h>
23 #include <encoding/payloads/nonce_payload.h>
24 #include <encoding/payloads/id_payload.h>
25 #include <encoding/payloads/ke_payload.h>
26 #include <encoding/payloads/notify_payload.h>
27 #include <encoding/payloads/auth_payload.h>
28 #include <encoding/payloads/cert_payload.h>
29 #include <encoding/payloads/certreq_payload.h>
30 #include <encoding/payloads/encryption_payload.h>
31 #include <encoding/payloads/ts_payload.h>
32 #include <encoding/payloads/delete_payload.h>
33 #include <encoding/payloads/vendor_id_payload.h>
34 #include <encoding/payloads/cp_payload.h>
35 #include <encoding/payloads/configuration_attribute.h>
36 #include <encoding/payloads/eap_payload.h>
37 #include <encoding/payloads/unknown_payload.h>
38
39
40 ENUM_BEGIN(payload_type_names, NO_PAYLOAD, NO_PAYLOAD,
41 "NO_PAYLOAD");
42 ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
43 "SECURITY_ASSOCIATION",
44 "KEY_EXCHANGE",
45 "ID_INITIATOR",
46 "ID_RESPONDER",
47 "CERTIFICATE",
48 "CERTIFICATE_REQUEST",
49 "AUTHENTICATION",
50 "NONCE",
51 "NOTIFY",
52 "DELETE",
53 "VENDOR_ID",
54 "TRAFFIC_SELECTOR_INITIATOR",
55 "TRAFFIC_SELECTOR_RESPONDER",
56 "ENCRYPTED",
57 "CONFIGURATION",
58 "EXTENSIBLE_AUTHENTICATION");
59 #ifdef ME
60 ENUM_NEXT(payload_type_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
61 "ID_PEER");
62 ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
63 "HEADER",
64 "PROPOSAL_SUBSTRUCTURE",
65 "TRANSFORM_SUBSTRUCTURE",
66 "TRANSFORM_ATTRIBUTE",
67 "TRAFFIC_SELECTOR_SUBSTRUCTURE",
68 "CONFIGURATION_ATTRIBUTE",
69 "UNKNOWN_PAYLOAD");
70 #else
71 ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
72 "HEADER",
73 "PROPOSAL_SUBSTRUCTURE",
74 "TRANSFORM_SUBSTRUCTURE",
75 "TRANSFORM_ATTRIBUTE",
76 "TRAFFIC_SELECTOR_SUBSTRUCTURE",
77 "CONFIGURATION_ATTRIBUTE",
78 "UNKNOWN_PAYLOAD");
79 #endif /* ME */
80 ENUM_END(payload_type_names, UNKNOWN_PAYLOAD);
81
82 /* short forms of payload names */
83 ENUM_BEGIN(payload_type_short_names, NO_PAYLOAD, NO_PAYLOAD,
84 "--");
85 ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
86 "SA",
87 "KE",
88 "IDi",
89 "IDr",
90 "CERT",
91 "CERTREQ",
92 "AUTH",
93 "No",
94 "N",
95 "D",
96 "V",
97 "TSi",
98 "TSr",
99 "E",
100 "CP",
101 "EAP");
102 #ifdef ME
103 ENUM_NEXT(payload_type_short_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
104 "IDp");
105 ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
106 "HDR",
107 "PROP",
108 "TRANS",
109 "TRANSATTR",
110 "TSSUB",
111 "CPATTR",
112 "??");
113 #else
114 ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
115 "HDR",
116 "PROP",
117 "TRANS",
118 "TRANSATTR",
119 "TSSUB",
120 "CPATTR",
121 "??");
122 #endif /* ME */
123 ENUM_END(payload_type_short_names, UNKNOWN_PAYLOAD);
124
125 /*
126 * see header
127 */
128 payload_t *payload_create(payload_type_t type)
129 {
130 switch (type)
131 {
132 case HEADER:
133 return (payload_t*)ike_header_create();
134 case SECURITY_ASSOCIATION:
135 return (payload_t*)sa_payload_create();
136 case PROPOSAL_SUBSTRUCTURE:
137 return (payload_t*)proposal_substructure_create();
138 case TRANSFORM_SUBSTRUCTURE:
139 return (payload_t*)transform_substructure_create();
140 case TRANSFORM_ATTRIBUTE:
141 return (payload_t*)transform_attribute_create();
142 case NONCE:
143 return (payload_t*)nonce_payload_create();
144 case ID_INITIATOR:
145 return (payload_t*)id_payload_create(ID_INITIATOR);
146 case ID_RESPONDER:
147 return (payload_t*)id_payload_create(ID_RESPONDER);
148 #ifdef ME
149 case ID_PEER:
150 return (payload_t*)id_payload_create(ID_PEER);
151 #endif /* ME */
152 case AUTHENTICATION:
153 return (payload_t*)auth_payload_create();
154 case CERTIFICATE:
155 return (payload_t*)cert_payload_create();
156 case CERTIFICATE_REQUEST:
157 return (payload_t*)certreq_payload_create();
158 case TRAFFIC_SELECTOR_SUBSTRUCTURE:
159 return (payload_t*)traffic_selector_substructure_create();
160 case TRAFFIC_SELECTOR_INITIATOR:
161 return (payload_t*)ts_payload_create(TRUE);
162 case TRAFFIC_SELECTOR_RESPONDER:
163 return (payload_t*)ts_payload_create(FALSE);
164 case KEY_EXCHANGE:
165 return (payload_t*)ke_payload_create();
166 case NOTIFY:
167 return (payload_t*)notify_payload_create();
168 case DELETE:
169 return (payload_t*)delete_payload_create(0);
170 case VENDOR_ID:
171 return (payload_t*)vendor_id_payload_create();
172 case CONFIGURATION:
173 return (payload_t*)cp_payload_create();
174 case CONFIGURATION_ATTRIBUTE:
175 return (payload_t*)configuration_attribute_create();
176 case EXTENSIBLE_AUTHENTICATION:
177 return (payload_t*)eap_payload_create();
178 case ENCRYPTED:
179 return (payload_t*)encryption_payload_create();
180 default:
181 return (payload_t*)unknown_payload_create();
182 }
183 }
184