032de6e56d08522e9e8c68ede67a3f2da5d0789f
[strongswan.git] / src / charon / 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 * $Id$
18 */
19
20
21 #include "payload.h"
22
23 #include <encoding/payloads/ike_header.h>
24 #include <encoding/payloads/sa_payload.h>
25 #include <encoding/payloads/nonce_payload.h>
26 #include <encoding/payloads/id_payload.h>
27 #include <encoding/payloads/ke_payload.h>
28 #include <encoding/payloads/notify_payload.h>
29 #include <encoding/payloads/auth_payload.h>
30 #include <encoding/payloads/cert_payload.h>
31 #include <encoding/payloads/certreq_payload.h>
32 #include <encoding/payloads/encryption_payload.h>
33 #include <encoding/payloads/ts_payload.h>
34 #include <encoding/payloads/delete_payload.h>
35 #include <encoding/payloads/vendor_id_payload.h>
36 #include <encoding/payloads/cp_payload.h>
37 #include <encoding/payloads/configuration_attribute.h>
38 #include <encoding/payloads/eap_payload.h>
39 #include <encoding/payloads/unknown_payload.h>
40
41
42 ENUM_BEGIN(payload_type_names, NO_PAYLOAD, NO_PAYLOAD,
43 "NO_PAYLOAD");
44 ENUM_NEXT(payload_type_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
45 "SECURITY_ASSOCIATION",
46 "KEY_EXCHANGE",
47 "ID_INITIATOR",
48 "ID_RESPONDER",
49 "CERTIFICATE",
50 "CERTIFICATE_REQUEST",
51 "AUTHENTICATION",
52 "NONCE",
53 "NOTIFY",
54 "DELETE",
55 "VENDOR_ID",
56 "TRAFFIC_SELECTOR_INITIATOR",
57 "TRAFFIC_SELECTOR_RESPONDER",
58 "ENCRYPTED",
59 "CONFIGURATION",
60 "EXTENSIBLE_AUTHENTICATION");
61 #ifdef ME
62 ENUM_NEXT(payload_type_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
63 "ID_PEER");
64 ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
65 #else
66 ENUM_NEXT(payload_type_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
67 #endif /* ME */
68 "HEADER",
69 "PROPOSAL_SUBSTRUCTURE",
70 "TRANSFORM_SUBSTRUCTURE",
71 "TRANSFORM_ATTRIBUTE",
72 "TRAFFIC_SELECTOR_SUBSTRUCTURE",
73 "CONFIGURATION_ATTRIBUTE",
74 "UNKNOWN_PAYLOAD");
75 ENUM_END(payload_type_names, UNKNOWN_PAYLOAD);
76
77 /* short forms of payload names */
78 ENUM_BEGIN(payload_type_short_names, NO_PAYLOAD, NO_PAYLOAD,
79 "--");
80 ENUM_NEXT(payload_type_short_names, SECURITY_ASSOCIATION, EXTENSIBLE_AUTHENTICATION, NO_PAYLOAD,
81 "SA",
82 "KE",
83 "IDi",
84 "IDr",
85 "CERT",
86 "CERTREQ",
87 "AUTH",
88 "No",
89 "N",
90 "D",
91 "V",
92 "TSi",
93 "TSr",
94 "E",
95 "CP",
96 "EAP");
97 #ifdef ME
98 ENUM_NEXT(payload_type_short_names, ID_PEER, ID_PEER, EXTENSIBLE_AUTHENTICATION,
99 "IDp");
100 ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, ID_PEER,
101 #else
102 ENUM_NEXT(payload_type_short_names, HEADER, UNKNOWN_PAYLOAD, EXTENSIBLE_AUTHENTICATION,
103 #endif /* ME */
104 "HDR",
105 "PROP",
106 "TRANS",
107 "TRANSATTR",
108 "TSSUB",
109 "CPATTR",
110 "??");
111 ENUM_END(payload_type_short_names, UNKNOWN_PAYLOAD);
112
113 /*
114 * see header
115 */
116 payload_t *payload_create(payload_type_t type)
117 {
118 switch (type)
119 {
120 case HEADER:
121 return (payload_t*)ike_header_create();
122 case SECURITY_ASSOCIATION:
123 return (payload_t*)sa_payload_create();
124 case PROPOSAL_SUBSTRUCTURE:
125 return (payload_t*)proposal_substructure_create();
126 case TRANSFORM_SUBSTRUCTURE:
127 return (payload_t*)transform_substructure_create();
128 case TRANSFORM_ATTRIBUTE:
129 return (payload_t*)transform_attribute_create();
130 case NONCE:
131 return (payload_t*)nonce_payload_create();
132 case ID_INITIATOR:
133 return (payload_t*)id_payload_create(ID_INITIATOR);
134 case ID_RESPONDER:
135 return (payload_t*)id_payload_create(ID_RESPONDER);
136 #ifdef ME
137 case ID_PEER:
138 return (payload_t*)id_payload_create(ID_PEER);
139 #endif /* ME */
140 case AUTHENTICATION:
141 return (payload_t*)auth_payload_create();
142 case CERTIFICATE:
143 return (payload_t*)cert_payload_create();
144 case CERTIFICATE_REQUEST:
145 return (payload_t*)certreq_payload_create();
146 case TRAFFIC_SELECTOR_SUBSTRUCTURE:
147 return (payload_t*)traffic_selector_substructure_create();
148 case TRAFFIC_SELECTOR_INITIATOR:
149 return (payload_t*)ts_payload_create(TRUE);
150 case TRAFFIC_SELECTOR_RESPONDER:
151 return (payload_t*)ts_payload_create(FALSE);
152 case KEY_EXCHANGE:
153 return (payload_t*)ke_payload_create();
154 case NOTIFY:
155 return (payload_t*)notify_payload_create();
156 case DELETE:
157 return (payload_t*)delete_payload_create(0);
158 case VENDOR_ID:
159 return (payload_t*)vendor_id_payload_create();
160 case CONFIGURATION:
161 return (payload_t*)cp_payload_create();
162 case CONFIGURATION_ATTRIBUTE:
163 return (payload_t*)configuration_attribute_create();
164 case EXTENSIBLE_AUTHENTICATION:
165 return (payload_t*)eap_payload_create();
166 case ENCRYPTED:
167 return (payload_t*)encryption_payload_create();
168 default:
169 return (payload_t*)unknown_payload_create();
170 }
171 }
172