Added an IKEv1 main mode task stub
[strongswan.git] / src / libcharon / sa / tasks / main_mode.c
1 /*
2 * Copyright (C) 2011 Martin Willi
3 * Copyright (C) 2011 revosec AG
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "main_mode.h"
17
18 #include <string.h>
19
20 #include <daemon.h>
21 #include <crypto/diffie_hellman.h>
22 #include <encoding/payloads/sa_payload.h>
23 #include <encoding/payloads/ke_payload.h>
24 #include <encoding/payloads/nonce_payload.h>
25
26
27 typedef struct private_main_mode_t private_main_mode_t;
28
29 /**
30 * Private members of a main_mode_t task.
31 */
32 struct private_main_mode_t {
33
34 /**
35 * Public methods and task_t interface.
36 */
37 main_mode_t public;
38
39 /**
40 * Assigned IKE_SA.
41 */
42 ike_sa_t *ike_sa;
43
44 /**
45 * Are we the initiator?
46 */
47 bool initiator;
48
49 /**
50 * IKE config to establish
51 */
52 ike_cfg_t *config;
53 };
54
55 METHOD(task_t, build_i, status_t,
56 private_main_mode_t *this, message_t *message)
57 {
58 /* TODO-IKEv1: initiate mainmode */
59 return FAILED;
60 }
61
62 METHOD(task_t, process_r, status_t,
63 private_main_mode_t *this, message_t *message)
64 {
65 this->config = this->ike_sa->get_ike_cfg(this->ike_sa);
66 DBG0(DBG_IKE, "%H is initiating a Main Mode", message->get_source(message));
67 this->ike_sa->set_state(this->ike_sa, IKE_CONNECTING);
68
69 /* TODO-IKEv1: process mainmode request */
70 return NEED_MORE;
71 }
72
73 METHOD(task_t, build_r, status_t,
74 private_main_mode_t *this, message_t *message)
75 {
76 /* TODO-IKEv1: build mainmode response */
77 return FAILED;
78 }
79
80 METHOD(task_t, process_i, status_t,
81 private_main_mode_t *this, message_t *message)
82 {
83 /* TODO-IKEv1: process main mode as initiator */
84 return FAILED;
85 }
86
87 METHOD(task_t, get_type, task_type_t,
88 private_main_mode_t *this)
89 {
90 return MAIN_MODE;
91 }
92
93 METHOD(task_t, migrate, void,
94 private_main_mode_t *this, ike_sa_t *ike_sa)
95 {
96 this->ike_sa = ike_sa;
97 }
98
99 METHOD(task_t, destroy, void,
100 private_main_mode_t *this)
101 {
102 free(this);
103 }
104
105 /*
106 * Described in header.
107 */
108 main_mode_t *main_mode_create(ike_sa_t *ike_sa, bool initiator)
109 {
110 private_main_mode_t *this;
111
112 INIT(this,
113 .public = {
114 .task = {
115 .get_type = _get_type,
116 .migrate = _migrate,
117 .destroy = _destroy,
118 },
119 },
120 .ike_sa = ike_sa,
121 .initiator = initiator,
122 );
123
124 if (initiator)
125 {
126 this->public.task.build = _build_i;
127 this->public.task.process = _process_i;
128 }
129 else
130 {
131 this->public.task.build = _build_r;
132 this->public.task.process = _process_r;
133 }
134
135 return &this->public;
136 }