2
* Copyright (C) 2008 Martin Willi
3
* Hochschule fuer Technik Rapperswil
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>.
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
18
#include "eap_sim_file_card.h"
20
typedef struct private_eap_sim_file_card_t private_eap_sim_file_card_t;
23
* Private data of an eap_sim_file_card_t object.
25
struct private_eap_sim_file_card_t {
28
* Public eap_sim_file_card_t interface.
30
eap_sim_file_card_t public;
33
* IMSI, is ID_ANY for file implementation
35
identification_t *imsi;
40
eap_sim_file_triplets_t *triplets;
46
* Implementation of sim_card_t.get_triplet
48
static bool get_triplet(private_eap_sim_file_card_t *this,
49
char *rand, char *sres, char *kc)
51
enumerator_t *enumerator;
53
char *c_rand, *c_sres, *c_kc;
56
DBG1(DBG_CFG, "looking for rand: %b", rand, RAND_LEN);
58
enumerator = this->triplets->create_enumerator(this->triplets);
59
while (enumerator->enumerate(enumerator, &id, &c_rand, &c_sres, &c_kc))
61
DBG1(DBG_CFG, "found triplet: %b %b %b", c_rand, RAND_LEN, c_sres, SRES_LEN, c_kc, KC_LEN);
62
if (memeq(c_rand, rand, RAND_LEN))
64
memcpy(sres, c_sres, SRES_LEN);
65
memcpy(kc, c_kc, KC_LEN);
66
enumerator->destroy(enumerator);
70
enumerator->destroy(enumerator);
75
* Implementation of sim_card_t.get_imsi
77
static identification_t* get_imsi(private_eap_sim_file_card_t *this)
83
* Implementation of eap_sim_file_card_t.destroy.
85
static void destroy(private_eap_sim_file_card_t *this)
87
this->imsi->destroy(this->imsi);
94
eap_sim_file_card_t *eap_sim_file_card_create(eap_sim_file_triplets_t *triplets)
96
private_eap_sim_file_card_t *this = malloc_thing(private_eap_sim_file_card_t);
98
this->public.card.get_triplet = (bool(*)(sim_card_t*, char *rand, char *sres, char *kc))get_triplet;
99
this->public.card.get_imsi = (identification_t*(*)(sim_card_t*))get_imsi;
100
this->public.destroy = (void(*)(eap_sim_file_card_t*))destroy;
102
/* this SIM card implementation does not have an ID, serve ID_ANY */
103
this->imsi = identification_create_from_encoding(ID_ANY, chunk_empty);
104
this->triplets = triplets;
106
return &this->public;