Fix issue reading MNC length in USIM.

master
Pedro Alvarez 4 years ago
parent c46402c836
commit 3eb525563a

@ -56,6 +56,9 @@ public:
int* res_len,
uint8_t* k_asme);
// Helpers
virtual std::string get_mnc_str(const uint8_t* imsi_vec, std::string mcc_str) final;
private:
// Smartcard sub-class which is a port of the PC/SC smartcard implementation
// of WPA Supplicant written by Jouni Malinen <j@w1.fi> and licensed under BSD

@ -62,7 +62,10 @@ private:
uint8_t* res,
int* res_len,
uint8_t* k_asme);
void str_to_hex(std::string str, uint8_t* hex);
// Helpers
virtual std::string get_mnc_str(const uint8_t* imsi_vec, std::string mcc_str) final;
void str_to_hex(std::string str, uint8_t* hex);
// User data
auth_algo_t auth_algo = auth_algo_milenage;

@ -101,6 +101,10 @@ public:
void store_keys_before_ho(const srslte::as_security_config_t& as_ctx) final;
void restore_keys_from_failed_ho(srslte::as_security_config_t* as_ctx) final;
// Helpers
std::string get_mcc_str(const uint8_t* imsi_vec);
virtual std::string get_mnc_str(const uint8_t* imsi_vec, std::string mcc_str) = 0;
protected:
bool initiated = false;
@ -113,7 +117,6 @@ protected:
uint64_t imei = 0;
std::string imsi_str;
std::string imei_str;
uint32_t mnc_length = 0;
// Security variables
uint8_t ck[CK_LEN] = {};

@ -91,10 +91,6 @@ int pcsc_usim::init(usim_args_t* args)
return ret;
}
// Get MNC length
mnc_length = sc.get_mnc_len();
log->debug("MNC length %d\n", mnc_length);
initiated = true;
ret = SRSLTE_SUCCESS;
@ -163,6 +159,19 @@ auth_result_t pcsc_usim::generate_authentication_response(uint8_t* rand,
return ret;
}
std::string pcsc_usim::get_mnc_str(const uint8_t* imsi_vec, std::string mcc_str)
{
uint32_t mcc_len = 3;
uint32_t mnc_len = sc.get_mnc_len();
std::ostringstream mnc_oss;
for (uint32_t i = mcc_len; i < mcc_len + mnc_len; i++) {
mnc_oss << (int)imsi_vec[i];
}
return mnc_oss.str();
}
/*********************************
* PC/SC class
********************************/

@ -248,6 +248,25 @@ auth_result_t usim::gen_auth_res_xor(uint8_t* rand,
return result;
}
std::string usim::get_mnc_str(const uint8_t* imsi_vec, std::string mcc_str)
{
uint32_t mcc_len = 3;
uint32_t mnc_len = 2;
std::ostringstream mnc_oss;
// US MCC uses 3 MNC digits
if (!mcc_str.compare("310") || !mcc_str.compare("311") || !mcc_str.compare("312") || !mcc_str.compare("313") ||
!mcc_str.compare("316")) {
mnc_len = 3;
}
for (uint32_t i = mcc_len; i < mcc_len + mnc_len; i++) {
mnc_oss << (int)imsi_vec[i];
}
return mnc_oss.str();
}
void usim::str_to_hex(std::string str, uint8_t* hex)
{
uint32_t i;

@ -96,6 +96,16 @@ bool usim_base::get_imei_vec(uint8_t* imei_, uint32_t n)
return true;
}
std::string usim_base::get_mcc_str(const uint8_t* imsi_vec)
{
std::ostringstream mcc_oss;
uint32_t mcc_len = 3;
for (uint32_t i = 0; i < mcc_len; i++) {
mcc_oss << (int)imsi_vec[i];
}
return mcc_oss.str();
}
bool usim_base::get_home_plmn_id(srslte::plmn_id_t* home_plmn_id)
{
if (!initiated) {
@ -106,18 +116,11 @@ bool usim_base::get_home_plmn_id(srslte::plmn_id_t* home_plmn_id)
uint8_t imsi_vec[15];
get_imsi_vec(imsi_vec, 15);
std::ostringstream plmn_str;
uint mcc_len = 3;
for (uint i = 0; i < mcc_len; i++) {
plmn_str << (int)imsi_vec[i];
}
for (uint i = mcc_len; i < mcc_len + mnc_length; i++) {
plmn_str << (int)imsi_vec[i];
}
std::string mcc_str = get_mcc_str(imsi_vec);
std::string mnc_str = get_mnc_str(imsi_vec, mcc_str);
if (home_plmn_id->from_string(plmn_str.str())) {
std::string plmn_str = mcc_str + mnc_str;
if (home_plmn_id->from_string(plmn_str)) {
log->error("Error reading home PLMN from SIM.\n");
return false;
}

Loading…
Cancel
Save