1 /* 2 * hostapd / EAP-SIM database/authenticator gateway 3 * Copyright (c) 2005-2008, 2012, Jouni Malinen <j (at) w1.fi> 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #ifndef EAP_SIM_DB_H 10 #define EAP_SIM_DB_H 11 12 #include "eap_common/eap_sim_common.h" 13 14 /* Identity prefixes */ 15 #define EAP_SIM_PERMANENT_PREFIX '1' 16 #define EAP_SIM_PSEUDONYM_PREFIX '3' 17 #define EAP_SIM_REAUTH_ID_PREFIX '5' 18 #define EAP_AKA_PERMANENT_PREFIX '0' 19 #define EAP_AKA_PSEUDONYM_PREFIX '2' 20 #define EAP_AKA_REAUTH_ID_PREFIX '4' 21 #define EAP_AKA_PRIME_PERMANENT_PREFIX '6' 22 #define EAP_AKA_PRIME_PSEUDONYM_PREFIX '7' 23 #define EAP_AKA_PRIME_REAUTH_ID_PREFIX '8' 24 25 enum eap_sim_db_method { 26 EAP_SIM_DB_SIM, 27 EAP_SIM_DB_AKA, 28 EAP_SIM_DB_AKA_PRIME 29 }; 30 31 struct eap_sim_db_data; 32 33 struct eap_sim_db_data * 34 eap_sim_db_init(const char *config, 35 void (*get_complete_cb)(void *ctx, void *session_ctx), 36 void *ctx); 37 38 void eap_sim_db_deinit(void *priv); 39 40 int eap_sim_db_get_gsm_triplets(struct eap_sim_db_data *data, 41 const char *username, int max_chal, 42 u8 *_rand, u8 *kc, u8 *sres, 43 void *cb_session_ctx); 44 45 #define EAP_SIM_DB_FAILURE -1 46 #define EAP_SIM_DB_PENDING -2 47 48 char * eap_sim_db_get_next_pseudonym(struct eap_sim_db_data *data, 49 enum eap_sim_db_method method); 50 51 char * eap_sim_db_get_next_reauth_id(struct eap_sim_db_data *data, 52 enum eap_sim_db_method method); 53 54 int eap_sim_db_add_pseudonym(struct eap_sim_db_data *data, 55 const char *permanent, char *pseudonym); 56 57 int eap_sim_db_add_reauth(struct eap_sim_db_data *data, const char *permanent, 58 char *reauth_id, u16 counter, const u8 *mk); 59 int eap_sim_db_add_reauth_prime(struct eap_sim_db_data *data, 60 const char *permanent, 61 char *reauth_id, u16 counter, const u8 *k_encr, 62 const u8 *k_aut, const u8 *k_re); 63 64 const char * eap_sim_db_get_permanent(struct eap_sim_db_data *data, 65 const char *pseudonym); 66 67 struct eap_sim_reauth { 68 struct eap_sim_reauth *next; 69 char *permanent; /* Permanent username */ 70 char *reauth_id; /* Fast re-authentication username */ 71 u16 counter; 72 u8 mk[EAP_SIM_MK_LEN]; 73 u8 k_encr[EAP_SIM_K_ENCR_LEN]; 74 u8 k_aut[EAP_AKA_PRIME_K_AUT_LEN]; 75 u8 k_re[EAP_AKA_PRIME_K_RE_LEN]; 76 }; 77 78 struct eap_sim_reauth * 79 eap_sim_db_get_reauth_entry(struct eap_sim_db_data *data, 80 const char *reauth_id); 81 82 void eap_sim_db_remove_reauth(struct eap_sim_db_data *data, 83 struct eap_sim_reauth *reauth); 84 85 int eap_sim_db_get_aka_auth(struct eap_sim_db_data *data, const char *username, 86 u8 *_rand, u8 *autn, u8 *ik, u8 *ck, 87 u8 *res, size_t *res_len, void *cb_session_ctx); 88 89 int eap_sim_db_resynchronize(struct eap_sim_db_data *data, 90 const char *username, const u8 *auts, 91 const u8 *_rand); 92 93 char * sim_get_username(const u8 *identity, size_t identity_len); 94 95 #endif /* EAP_SIM_DB_H */ 96