Read Home PLMN from IMSI

master
Ismael Gomez 7 years ago
parent a5b384da4a
commit c7d5231251

@ -54,6 +54,7 @@ class usim_interface_nas
public:
virtual void get_imsi_vec(uint8_t* imsi_, uint32_t n) = 0;
virtual void get_imei_vec(uint8_t* imei_, uint32_t n) = 0;
virtual int get_home_plmn_id(LIBLTE_RRC_PLMN_IDENTITY_STRUCT *home_plmn_id) = 0;
virtual void generate_authentication_response(uint8_t *rand,
uint8_t *autn_enb,
uint16_t mcc,

@ -95,7 +95,6 @@ public:
// UE interface
void attach_request();
void deattach_request();
private:

@ -61,6 +61,7 @@ public:
// NAS interface
void get_imsi_vec(uint8_t* imsi_, uint32_t n);
void get_imei_vec(uint8_t* imei_, uint32_t n);
int get_home_plmn_id(LIBLTE_RRC_PLMN_IDENTITY_STRUCT *home_plmn_id);
void generate_authentication_response(uint8_t *rand,
uint8_t *autn_enb,
@ -119,6 +120,8 @@ private:
uint8_t k_asme[32];
uint8_t k_enb[32];
bool initiated;
};
} // namespace srsue

@ -181,11 +181,10 @@ bool ue::init(all_args_t *args_)
rlc.init(&pdcp, &rrc, this, &rlc_log, &mac, 0 /* RB_ID_SRB0 */);
pdcp.init(&rlc, &rrc, &gw, &pdcp_log, 0 /* RB_ID_SRB0 */, SECURITY_DIRECTION_UPLINK);
usim.init(&args->usim, &usim_log);
nas.init(&usim, &rrc, &gw, &nas_log, 1 /* RB_ID_SRB1 */);
gw.init(&pdcp, &nas, &gw_log, 3 /* RB_ID_DRB1 */);
usim.init(&args->usim, &usim_log);
rrc.init(&phy, &mac, &rlc, &pdcp, &nas, &usim, &mac, &rrc_log);
rrc.set_ue_category(atoi(args->expert.ue_cateogry.c_str()));

@ -50,8 +50,12 @@ void nas::init(usim_interface_nas *usim_,
nas_log = nas_log_;
state = EMM_STATE_DEREGISTERED;
plmn_selection = PLMN_NOT_SELECTED;
home_plmn.mcc = 61441; // This is 001
home_plmn.mnc = 65281; // This is 01
if (usim->get_home_plmn_id(&home_plmn)) {
nas_log->error("Getting Home PLMN Id from USIM. Defaulting to 001-01\n");
home_plmn.mcc = 61441; // This is 001
home_plmn.mnc = 65281; // This is 01
}
cfg = cfg_;
}
@ -64,6 +68,7 @@ emm_state_t nas::get_state() {
/*******************************************************************************
UE interface
*******************************************************************************/
void nas::attach_request() {
nas_log->info("Attach Request\n");
if (state == EMM_STATE_DEREGISTERED) {
@ -137,7 +142,7 @@ void nas::plmn_search_end() {
rrc->plmn_select(known_plmns[0]);
} else {
nas_log->info("Finished searching PLMN in current EARFCN set but no networks were found.\n");
nas_log->debug("Finished searching PLMN in current EARFCN set but no networks were found.\n");
}
}

@ -458,7 +458,7 @@ void rrc::cell_found(uint32_t earfcn, srslte_cell_t phy_cell, float rsrp) {
// PHY indicates that has gone through all known EARFCN
void rrc::earfcn_end() {
rrc_log->info("Finished searching cells in EARFCN set while in state %s\n", rrc_state_text[state]);
rrc_log->debug("Finished searching cells in EARFCN set while in state %s\n", rrc_state_text[state]);
// If searching for PLMN, indicate NAS we scanned all frequencies
if (state == RRC_STATE_PLMN_SELECTION) {

@ -25,13 +25,15 @@
*/
#include <sstream>
#include "upper/usim.h"
#include "srslte/common/bcd_helpers.h"
using namespace srslte;
namespace srsue{
usim::usim()
usim::usim() : initiated(false)
{}
void usim::init(usim_args_t *args, srslte::log *usim_log_)
@ -91,6 +93,7 @@ void usim::init(usim_args_t *args, srslte::log *usim_log_)
if("xor" == args->algo) {
auth_algo = auth_algo_xor;
}
initiated = true;
}
void usim::stop()
@ -102,6 +105,11 @@ void usim::stop()
void usim::get_imsi_vec(uint8_t* imsi_, uint32_t n)
{
if (!initiated)
{
usim_log->error("Getting IMSI: USIM not initiated\n");
return;
}
if(NULL == imsi_ || n < 15)
{
usim_log->error("Invalid parameters to get_imsi_vec");
@ -111,13 +119,18 @@ void usim::get_imsi_vec(uint8_t* imsi_, uint32_t n)
uint64_t temp = imsi;
for(int i=14;i>=0;i--)
{
imsi_[i] = temp % 10;
temp /= 10;
imsi_[i] = temp % 10;
temp /= 10;
}
}
void usim::get_imei_vec(uint8_t* imei_, uint32_t n)
{
if (!initiated)
{
usim_log->error("Getting IMEI: USIM not initiated\n");
return;
}
if(NULL == imei_ || n < 15)
{
usim_log->error("Invalid parameters to get_imei_vec");
@ -127,9 +140,46 @@ void usim::get_imei_vec(uint8_t* imei_, uint32_t n)
uint64 temp = imei;
for(int i=14;i>=0;i--)
{
imei_[i] = temp % 10;
temp /= 10;
imei_[i] = temp % 10;
temp /= 10;
}
}
int usim::get_home_plmn_id(LIBLTE_RRC_PLMN_IDENTITY_STRUCT *home_plmn_id)
{
if (!initiated)
{
usim_log->error("Getting Home PLMN Id: USIM not initiated\n");
return -1;
}
uint32_t mcc_len = 3;
uint32_t mnc_len = 2;
uint8_t imsi_vec[15];
get_imsi_vec(imsi_vec, 15);
std::ostringstream mcc_str, mnc_str;
for (int i=0;i<mcc_len;i++) {
mcc_str << (int) imsi_vec[i];
}
// US MCC uses 3 MNC digits
if (!mcc_str.str().compare("310")) {
mnc_len = 3;
}
for (int i=mcc_len;i<mcc_len+mnc_len;i++) {
mnc_str << (int) imsi_vec[i];
}
string_to_mcc(mcc_str.str(), &home_plmn_id->mcc);
string_to_mnc(mnc_str.str(), &home_plmn_id->mnc);
usim_log->info("Read Home PLMN Id=%s\n",
plmn_id_to_string(*home_plmn_id).c_str());
return 0;
}
void usim::generate_authentication_response(uint8_t *rand,

Loading…
Cancel
Save