reintegrated two-sim branch providing SIM card plugin API
[strongswan.git] / src / charon / plugins / eap_sim_file / eap_sim_file_plugin.c
1 /*
2 * Copyright (C) 2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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 * $Id$
16 */
17
18 #include "eap_sim_file_plugin.h"
19 #include "eap_sim_file_card.h"
20 #include "eap_sim_file_provider.h"
21 #include "eap_sim_file_triplets.h"
22
23 #include <daemon.h>
24
25 #define TRIPLET_FILE IPSEC_CONFDIR "/ipsec.d/triplets.dat"
26
27 typedef struct private_eap_sim_file_t private_eap_sim_file_t;
28
29 /**
30 * Private data of an eap_sim_file_t object.
31 */
32 struct private_eap_sim_file_t {
33
34 /**
35 * Public eap_sim_file_plugin_t interface.
36 */
37 eap_sim_file_plugin_t public;
38
39 /**
40 * SIM card
41 */
42 eap_sim_file_card_t *card;
43
44 /**
45 * SIM provider
46 */
47 eap_sim_file_provider_t *provider;
48
49 /**
50 * Triplet source
51 */
52 eap_sim_file_triplets_t *triplets;
53 };
54
55 /**
56 * Implementation of eap_sim_file_t.destroy.
57 */
58 static void destroy(private_eap_sim_file_t *this)
59 {
60 charon->sim->remove_card(charon->sim, &this->card->card);
61 charon->sim->remove_provider(charon->sim, &this->provider->provider);
62 this->card->destroy(this->card);
63 this->provider->destroy(this->provider);
64 this->triplets->destroy(this->triplets);
65 free(this);
66 }
67
68 /**
69 * See header
70 */
71 plugin_t *plugin_create()
72 {
73 private_eap_sim_file_t *this = malloc_thing(private_eap_sim_file_t);
74
75 this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
76
77 this->triplets = eap_sim_file_triplets_create(TRIPLET_FILE);
78 this->card = eap_sim_file_card_create(this->triplets);
79 this->provider = eap_sim_file_provider_create(this->triplets);
80
81 charon->sim->add_card(charon->sim, &this->card->card);
82 charon->sim->add_provider(charon->sim, &this->provider->provider);
83
84 return &this->public.plugin;
85 }
86