Migrated sim_manager to INIT/METHOD macros

This commit is contained in:
Martin Willi
2011-03-08 16:42:27 +01:00
parent 7b3bfe4b6c
commit 5f47296f22
+91 -149
View File
@@ -52,32 +52,25 @@ struct private_sim_manager_t {
rwlock_t *lock; rwlock_t *lock;
}; };
/** METHOD(sim_manager_t, add_card, void,
* Implementation of sim_manager_t.add_card private_sim_manager_t *this, sim_card_t *card)
*/
static void add_card(private_sim_manager_t *this, sim_card_t *card)
{ {
this->lock->write_lock(this->lock); this->lock->write_lock(this->lock);
this->cards->insert_last(this->cards, card); this->cards->insert_last(this->cards, card);
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, remove_card, void,
* Implementation of sim_manager_t.remove_card private_sim_manager_t *this, sim_card_t *card)
*/
static void remove_card(private_sim_manager_t *this, sim_card_t *card)
{ {
this->lock->write_lock(this->lock); this->lock->write_lock(this->lock);
this->cards->remove(this->cards, card, NULL); this->cards->remove(this->cards, card, NULL);
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, card_get_triplet, bool,
* Implementation of sim_manager_t.card_get_triplet private_sim_manager_t *this, identification_t *id,
*/ char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN])
static bool card_get_triplet(private_sim_manager_t *this, identification_t *id,
char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN],
char kc[SIM_KC_LEN])
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
@@ -102,14 +95,10 @@ static bool card_get_triplet(private_sim_manager_t *this, identification_t *id,
return FALSE; return FALSE;
} }
/** METHOD(sim_manager_t, card_get_quintuplet, status_t,
* Implementation of sim_manager_t.card_get_quintuplet private_sim_manager_t *this, identification_t *id, char rand[AKA_RAND_LEN],
*/ char autn[AKA_AUTN_LEN], char ck[AKA_CK_LEN], char ik[AKA_IK_LEN],
static status_t card_get_quintuplet(private_sim_manager_t *this, char res[AKA_RES_MAX], int *res_len)
identification_t *id, char rand[AKA_RAND_LEN],
char autn[AKA_AUTN_LEN], char ck[AKA_CK_LEN],
char ik[AKA_IK_LEN], char res[AKA_RES_MAX],
int *res_len)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
@@ -142,11 +131,9 @@ static status_t card_get_quintuplet(private_sim_manager_t *this,
return status; return status;
} }
/** METHOD(sim_manager_t, card_resync, bool,
* Implementation of sim_manager_t.card_resync private_sim_manager_t *this, identification_t *id,
*/ char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN])
static bool card_resync(private_sim_manager_t *this, identification_t *id,
char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN])
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
@@ -167,11 +154,9 @@ static bool card_resync(private_sim_manager_t *this, identification_t *id,
return FALSE; return FALSE;
} }
/** METHOD(sim_manager_t, card_set_pseudonym, void,
* Implementation of sim_manager_t.card_set_pseudonym private_sim_manager_t *this, identification_t *id,
*/ identification_t *pseudonym)
static void card_set_pseudonym(private_sim_manager_t *this,
identification_t *id, identification_t *pseudonym)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
@@ -188,11 +173,8 @@ static void card_set_pseudonym(private_sim_manager_t *this,
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, card_get_pseudonym, identification_t*,
* Implementation of sim_manager_t.card_get_pseudonym private_sim_manager_t *this, identification_t *id)
*/
static identification_t* card_get_pseudonym(private_sim_manager_t *this,
identification_t *id)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
@@ -215,12 +197,9 @@ static identification_t* card_get_pseudonym(private_sim_manager_t *this,
return pseudonym; return pseudonym;
} }
/** METHOD(sim_manager_t, card_set_reauth, void,
* Implementation of sim_manager_t.card_set_reauth private_sim_manager_t *this, identification_t *id, identification_t *next,
*/ char mk[HASH_SIZE_SHA1], u_int16_t counter)
static void card_set_reauth(private_sim_manager_t *this, identification_t *id,
identification_t *next, char mk[HASH_SIZE_SHA1],
u_int16_t counter)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
@@ -238,12 +217,9 @@ static void card_set_reauth(private_sim_manager_t *this, identification_t *id,
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, card_get_reauth, identification_t*,
* Implementation of sim_manager_t.card_get_reauth private_sim_manager_t *this, identification_t *id, char mk[HASH_SIZE_SHA1],
*/ u_int16_t *counter)
static identification_t* card_get_reauth(private_sim_manager_t *this,
identification_t *id, char mk[HASH_SIZE_SHA1],
u_int16_t *counter)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
@@ -266,33 +242,25 @@ static identification_t* card_get_reauth(private_sim_manager_t *this,
return reauth; return reauth;
} }
/** METHOD(sim_manager_t, add_provider, void,
* Implementation of sim_manager_t.add_provider private_sim_manager_t *this, sim_provider_t *provider)
*/
static void add_provider(private_sim_manager_t *this, sim_provider_t *provider)
{ {
this->lock->write_lock(this->lock); this->lock->write_lock(this->lock);
this->providers->insert_last(this->providers, provider); this->providers->insert_last(this->providers, provider);
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, remove_provider, void,
* Implementation of sim_manager_t.remove_provider private_sim_manager_t *this, sim_provider_t *provider)
*/
static void remove_provider(private_sim_manager_t *this,
sim_provider_t *provider)
{ {
this->lock->write_lock(this->lock); this->lock->write_lock(this->lock);
this->providers->remove(this->providers, provider, NULL); this->providers->remove(this->providers, provider, NULL);
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, provider_get_triplet, bool,
* Implementation of sim_manager_t.provider_get_triplet private_sim_manager_t *this, identification_t *id, char rand[SIM_RAND_LEN],
*/ char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN])
static bool provider_get_triplet(private_sim_manager_t *this,
identification_t *id, char rand[SIM_RAND_LEN],
char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN])
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_provider_t *provider; sim_provider_t *provider;
@@ -317,14 +285,10 @@ static bool provider_get_triplet(private_sim_manager_t *this,
return FALSE; return FALSE;
} }
/** METHOD(sim_manager_t, provider_get_quintuplet, bool,
* Implementation of sim_manager_t.provider_get_quintuplet private_sim_manager_t *this, identification_t *id, char rand[AKA_RAND_LEN],
*/ char xres[AKA_RES_MAX], int *xres_len, char ck[AKA_CK_LEN],
static bool provider_get_quintuplet(private_sim_manager_t *this, char ik[AKA_IK_LEN], char autn[AKA_AUTN_LEN])
identification_t *id, char rand[AKA_RAND_LEN],
char xres[AKA_RES_MAX], int *xres_len,
char ck[AKA_CK_LEN], char ik[AKA_IK_LEN],
char autn[AKA_AUTN_LEN])
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_provider_t *provider; sim_provider_t *provider;
@@ -349,11 +313,9 @@ static bool provider_get_quintuplet(private_sim_manager_t *this,
return FALSE; return FALSE;
} }
/** METHOD(sim_manager_t, provider_resync, bool,
* Implementation of sim_manager_t.provider_resync private_sim_manager_t *this, identification_t *id,
*/ char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN])
static bool provider_resync(private_sim_manager_t *this, identification_t *id,
char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN])
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_provider_t *provider; sim_provider_t *provider;
@@ -374,11 +336,8 @@ static bool provider_resync(private_sim_manager_t *this, identification_t *id,
return FALSE; return FALSE;
} }
/** METHOD(sim_manager_t, provider_is_pseudonym, identification_t*,
* Implementation of sim_manager_t.provider_is_pseudonym private_sim_manager_t *this, identification_t *id)
*/
static identification_t* provider_is_pseudonym(private_sim_manager_t *this,
identification_t *id)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_provider_t *provider; sim_provider_t *provider;
@@ -401,11 +360,8 @@ static identification_t* provider_is_pseudonym(private_sim_manager_t *this,
return permanent; return permanent;
} }
/** METHOD(sim_manager_t, provider_gen_pseudonym, identification_t*,
* Implementation of sim_manager_t.provider_gen_pseudonym private_sim_manager_t *this, identification_t *id)
*/
static identification_t* provider_gen_pseudonym(private_sim_manager_t *this,
identification_t *id)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_provider_t *provider; sim_provider_t *provider;
@@ -427,12 +383,9 @@ static identification_t* provider_gen_pseudonym(private_sim_manager_t *this,
return pseudonym; return pseudonym;
} }
/** METHOD(sim_manager_t, provider_is_reauth, identification_t*,
* Implementation of sim_manager_t.provider_is_reauth private_sim_manager_t *this, identification_t *id, char mk[HASH_SIZE_SHA1],
*/ u_int16_t *counter)
static identification_t* provider_is_reauth(private_sim_manager_t *this,
identification_t *id, char mk[HASH_SIZE_SHA1],
u_int16_t *counter)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_provider_t *provider; sim_provider_t *provider;
@@ -455,11 +408,8 @@ static identification_t* provider_is_reauth(private_sim_manager_t *this,
return permanent; return permanent;
} }
/** METHOD(sim_manager_t, provider_gen_reauth, identification_t*,
* Implementation of sim_manager_t.provider_gen_reauth private_sim_manager_t *this, identification_t *id, char mk[HASH_SIZE_SHA1])
*/
static identification_t* provider_gen_reauth(private_sim_manager_t *this,
identification_t *id, char mk[HASH_SIZE_SHA1])
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_provider_t *provider; sim_provider_t *provider;
@@ -481,31 +431,25 @@ static identification_t* provider_gen_reauth(private_sim_manager_t *this,
return reauth; return reauth;
} }
/** METHOD(sim_manager_t, add_hooks, void,
* Implementation of sim_manager_t.add_hooks private_sim_manager_t *this, sim_hooks_t *hooks)
*/
static void add_hooks(private_sim_manager_t *this, sim_hooks_t *hooks)
{ {
this->lock->write_lock(this->lock); this->lock->write_lock(this->lock);
this->hooks->insert_last(this->hooks, hooks); this->hooks->insert_last(this->hooks, hooks);
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, remove_hooks, void,
* Implementation of sim_manager_t.remove_hooks private_sim_manager_t *this, sim_hooks_t *hooks)
*/
static void remove_hooks(private_sim_manager_t *this, sim_hooks_t *hooks)
{ {
this->lock->write_lock(this->lock); this->lock->write_lock(this->lock);
this->hooks->remove(this->hooks, hooks, NULL); this->hooks->remove(this->hooks, hooks, NULL);
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, message_hook, void,
* Implementation of sim_manager_t.message_hook private_sim_manager_t *this, simaka_message_t *message,
*/ bool inbound, bool decrypted)
static void message_hook(private_sim_manager_t *this,
simaka_message_t *message, bool inbound, bool decrypted)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_hooks_t *hooks; sim_hooks_t *hooks;
@@ -520,11 +464,8 @@ static void message_hook(private_sim_manager_t *this,
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, key_hook, void,
* Implementation of sim_manager_t.key_hook private_sim_manager_t *this, chunk_t k_encr, chunk_t k_auth)
*/
static void key_hook(private_sim_manager_t *this,
chunk_t k_encr, chunk_t k_auth)
{ {
enumerator_t *enumerator; enumerator_t *enumerator;
sim_hooks_t *hooks; sim_hooks_t *hooks;
@@ -539,10 +480,8 @@ static void key_hook(private_sim_manager_t *this,
this->lock->unlock(this->lock); this->lock->unlock(this->lock);
} }
/** METHOD(sim_manager_t, destroy, void,
* Implementation of sim_manager_t.destroy. private_sim_manager_t *this)
*/
static void destroy(private_sim_manager_t *this)
{ {
this->cards->destroy(this->cards); this->cards->destroy(this->cards);
this->providers->destroy(this->providers); this->providers->destroy(this->providers);
@@ -556,36 +495,39 @@ static void destroy(private_sim_manager_t *this)
*/ */
sim_manager_t *sim_manager_create() sim_manager_t *sim_manager_create()
{ {
private_sim_manager_t *this = malloc_thing(private_sim_manager_t); private_sim_manager_t *this;
this->public.add_card = (void(*)(sim_manager_t*, sim_card_t *card))add_card; INIT(this,
this->public.remove_card = (void(*)(sim_manager_t*, sim_card_t *card))remove_card; .public = {
this->public.card_get_triplet = (bool(*)(sim_manager_t*, identification_t *id, char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN]))card_get_triplet; .add_card = _add_card,
this->public.card_get_quintuplet = (status_t(*)(sim_manager_t*, identification_t *id, char rand[AKA_RAND_LEN], char autn[AKA_AUTN_LEN], char ck[AKA_CK_LEN], char ik[AKA_IK_LEN], char res[AKA_RES_MAX], int *res_len))card_get_quintuplet; .remove_card = _remove_card,
this->public.card_resync = (bool(*)(sim_manager_t*, identification_t *id, char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN]))card_resync; .card_get_triplet = _card_get_triplet,
this->public.card_set_pseudonym = (void(*)(sim_manager_t*, identification_t *id, identification_t *pseudonym))card_set_pseudonym; .card_get_quintuplet = _card_get_quintuplet,
this->public.card_get_pseudonym = (identification_t*(*)(sim_manager_t*, identification_t *id))card_get_pseudonym; .card_resync = _card_resync,
this->public.card_set_reauth = (void(*)(sim_manager_t*, identification_t *id, identification_t *next, char mk[HASH_SIZE_SHA1], u_int16_t counter))card_set_reauth; .card_set_pseudonym = _card_set_pseudonym,
this->public.card_get_reauth = (identification_t*(*)(sim_manager_t*, identification_t *id, char mk[HASH_SIZE_SHA1], u_int16_t *counter))card_get_reauth; .card_get_pseudonym = _card_get_pseudonym,
this->public.add_provider = (void(*)(sim_manager_t*, sim_provider_t *provider))add_provider; .card_set_reauth = _card_set_reauth,
this->public.remove_provider = (void(*)(sim_manager_t*, sim_provider_t *provider))remove_provider; .card_get_reauth = _card_get_reauth,
this->public.provider_get_triplet = (bool(*)(sim_manager_t*, identification_t *id, char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN]))provider_get_triplet; .add_provider = _add_provider,
this->public.provider_get_quintuplet = (bool(*)(sim_manager_t*, identification_t *id, char rand[AKA_RAND_LEN], char xres[AKA_RES_MAX], int *xres_len, char ck[AKA_CK_LEN], char ik[AKA_IK_LEN], char autn[AKA_AUTN_LEN]))provider_get_quintuplet; .remove_provider = _remove_provider,
this->public.provider_resync = (bool(*)(sim_manager_t*, identification_t *id, char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN]))provider_resync; .provider_get_triplet = _provider_get_triplet,
this->public.provider_is_pseudonym = (identification_t*(*)(sim_manager_t*, identification_t *id))provider_is_pseudonym; .provider_get_quintuplet = _provider_get_quintuplet,
this->public.provider_gen_pseudonym = (identification_t*(*)(sim_manager_t*, identification_t *id))provider_gen_pseudonym; .provider_resync = _provider_resync,
this->public.provider_is_reauth = (identification_t*(*)(sim_manager_t*, identification_t *id, char mk[HASH_SIZE_SHA1], u_int16_t *counter))provider_is_reauth; .provider_is_pseudonym = _provider_is_pseudonym,
this->public.provider_gen_reauth = (identification_t*(*)(sim_manager_t*, identification_t *id, char mk[HASH_SIZE_SHA1]))provider_gen_reauth; .provider_gen_pseudonym = _provider_gen_pseudonym,
this->public.add_hooks = (void(*)(sim_manager_t*, sim_hooks_t *hooks))add_hooks; .provider_is_reauth = _provider_is_reauth,
this->public.remove_hooks = (void(*)(sim_manager_t*, sim_hooks_t *hooks))remove_hooks; .provider_gen_reauth = _provider_gen_reauth,
this->public.message_hook = (void(*)(sim_manager_t*, simaka_message_t *message, bool inbound, bool decrypted))message_hook; .add_hooks = _add_hooks,
this->public.key_hook = (void(*)(sim_manager_t*, chunk_t k_encr, chunk_t k_auth))key_hook; .remove_hooks = _remove_hooks,
this->public.destroy = (void(*)(sim_manager_t*))destroy; .message_hook = _message_hook,
.key_hook = _key_hook,
this->cards = linked_list_create(); .destroy = _destroy,
this->providers = linked_list_create(); },
this->hooks = linked_list_create(); .cards = linked_list_create(),
this->lock = rwlock_create(RWLOCK_TYPE_DEFAULT); .providers = linked_list_create(),
.hooks = linked_list_create(),
.lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
);
return &this->public; return &this->public;
} }