Skip to content

Commit

Permalink
Read Home PLMN from IMSI
Browse files Browse the repository at this point in the history
  • Loading branch information
ismagom committed Oct 7, 2017
1 parent a5b384d commit c7d5231
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 12 deletions.
1 change: 1 addition & 0 deletions lib/include/srslte/interfaces/ue_interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion srsue/hdr/upper/nas.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ class nas

// UE interface
void attach_request();

void deattach_request();

private:
Expand Down
3 changes: 3 additions & 0 deletions srsue/hdr/upper/usim.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class usim
// 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,
Expand Down Expand Up @@ -119,6 +120,8 @@ class usim
uint8_t k_asme[32];
uint8_t k_enb[32];

bool initiated;

};

} // namespace srsue
Expand Down
3 changes: 1 addition & 2 deletions srsue/src/ue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
11 changes: 8 additions & 3 deletions srsue/src/upper/nas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
}

Expand All @@ -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) {
Expand Down Expand Up @@ -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");
}
}

Expand Down
2 changes: 1 addition & 1 deletion srsue/src/upper/rrc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
60 changes: 55 additions & 5 deletions srsue/src/upper/usim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down Expand Up @@ -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()
Expand All @@ -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");
Expand All @@ -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");
Expand All @@ -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,
Expand Down

0 comments on commit c7d5231

Please sign in to comment.