Commit d67a3c52 authored by aligungr's avatar aligungr

L3 RRC/NAS developments

parent dc8bebb8
...@@ -48,19 +48,20 @@ bool NasMm::isInNonAllowedArea() ...@@ -48,19 +48,20 @@ bool NasMm::isInNonAllowedArea()
if (!m_usim->isValid()) if (!m_usim->isValid())
return false; return false;
auto plmn = m_base->shCtx.getCurrentPlmn(); auto currentCell = m_base->shCtx.currentCell.get();
if (!plmn.hasValue()) if (!currentCell.hasValue())
return false; return false;
auto plmn = currentCell.plmn;
if (nas::utils::ServiceAreaListForbidsPlmn(m_storage->serviceAreaList->get(), nas::utils::PlmnFrom(plmn))) if (nas::utils::ServiceAreaListForbidsPlmn(m_storage->serviceAreaList->get(), nas::utils::PlmnFrom(plmn)))
return true; return true;
int tac = m_base->shCtx.currentCell.get<int>([](auto &value) { return value.tac; }); int tac = currentCell.tac;
if (nas::utils::ServiceAreaListForbidsTai(m_storage->serviceAreaList->get(), if (nas::utils::ServiceAreaListForbidsTai(m_storage->serviceAreaList->get(),
nas::VTrackingAreaIdentity{nas::utils::PlmnFrom(plmn), octet3{tac}})) nas::VTrackingAreaIdentity{nas::utils::PlmnFrom(plmn), octet3{tac}}))
{
return true; return true;
}
return false; return false;
} }
......
...@@ -34,6 +34,10 @@ void NasMm::receiveAuthenticationRequest(const nas::AuthenticationRequest &msg) ...@@ -34,6 +34,10 @@ void NasMm::receiveAuthenticationRequest(const nas::AuthenticationRequest &msg)
void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &msg) void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &msg)
{ {
Plmn currentPlmn = m_base->shCtx.getCurrentPlmn();
if (!currentPlmn.hasValue())
return;
auto sendEapFailure = [this](std::unique_ptr<eap::Eap> &&eap) { auto sendEapFailure = [this](std::unique_ptr<eap::Eap> &&eap) {
// Clear RAND and RES* stored in volatile memory // Clear RAND and RES* stored in volatile memory
m_usim->m_rand = {}; m_usim->m_rand = {};
...@@ -111,7 +115,7 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms ...@@ -111,7 +115,7 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms
return; return;
} }
auto snn = keys::ConstructServingNetworkName(m_base->shCtx.getCurrentPlmn()); auto snn = keys::ConstructServingNetworkName(currentPlmn);
if (receivedEap.attributes.getKdfInput() != OctetString::FromAscii(snn)) if (receivedEap.attributes.getKdfInput() != OctetString::FromAscii(snn))
{ {
...@@ -196,7 +200,7 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms ...@@ -196,7 +200,7 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms
m_usim->m_nonCurrentNsCtx->keys.kAusf = keys::CalculateKAusfFor5gAka(milenage.ck, milenage.ik, snn, sqnXorAk); m_usim->m_nonCurrentNsCtx->keys.kAusf = keys::CalculateKAusfFor5gAka(milenage.ck, milenage.ik, snn, sqnXorAk);
m_usim->m_nonCurrentNsCtx->keys.abba = msg.abba.rawData.copy(); m_usim->m_nonCurrentNsCtx->keys.abba = msg.abba.rawData.copy();
keys::DeriveKeysSeafAmf(*m_base->config, m_base->shCtx.getCurrentPlmn(), *m_usim->m_nonCurrentNsCtx); keys::DeriveKeysSeafAmf(*m_base->config, currentPlmn, *m_usim->m_nonCurrentNsCtx);
// Send response // Send response
m_nwConsecutiveAuthFailure = 0; m_nwConsecutiveAuthFailure = 0;
...@@ -257,6 +261,10 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms ...@@ -257,6 +261,10 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms
void NasMm::receiveAuthenticationRequest5gAka(const nas::AuthenticationRequest &msg) void NasMm::receiveAuthenticationRequest5gAka(const nas::AuthenticationRequest &msg)
{ {
Plmn currentPLmn = m_base->shCtx.getCurrentPlmn();
if (!currentPLmn.hasValue())
return;
auto sendFailure = [this](nas::EMmCause cause, std::optional<OctetString> &&auts = std::nullopt) { auto sendFailure = [this](nas::EMmCause cause, std::optional<OctetString> &&auts = std::nullopt) {
if (cause != nas::EMmCause::SYNCH_FAILURE) if (cause != nas::EMmCause::SYNCH_FAILURE)
m_logger->err("Sending Authentication Failure with cause [%s]", nas::utils::EnumToString(cause)); m_logger->err("Sending Authentication Failure with cause [%s]", nas::utils::EnumToString(cause));
...@@ -346,7 +354,7 @@ void NasMm::receiveAuthenticationRequest5gAka(const nas::AuthenticationRequest & ...@@ -346,7 +354,7 @@ void NasMm::receiveAuthenticationRequest5gAka(const nas::AuthenticationRequest &
auto milenage = calculateMilenage(m_usim->m_sqnMng->getSqn(), rand, false); auto milenage = calculateMilenage(m_usim->m_sqnMng->getSqn(), rand, false);
auto ckIk = OctetString::Concat(milenage.ck, milenage.ik); auto ckIk = OctetString::Concat(milenage.ck, milenage.ik);
auto sqnXorAk = OctetString::Xor(m_usim->m_sqnMng->getSqn(), milenage.ak); auto sqnXorAk = OctetString::Xor(m_usim->m_sqnMng->getSqn(), milenage.ak);
auto snn = keys::ConstructServingNetworkName(m_base->shCtx.getCurrentPlmn()); auto snn = keys::ConstructServingNetworkName(currentPLmn);
// Store the relevant parameters // Store the relevant parameters
m_usim->m_rand = rand.copy(); m_usim->m_rand = rand.copy();
...@@ -359,7 +367,7 @@ void NasMm::receiveAuthenticationRequest5gAka(const nas::AuthenticationRequest & ...@@ -359,7 +367,7 @@ void NasMm::receiveAuthenticationRequest5gAka(const nas::AuthenticationRequest &
m_usim->m_nonCurrentNsCtx->keys.kAusf = keys::CalculateKAusfFor5gAka(milenage.ck, milenage.ik, snn, sqnXorAk); m_usim->m_nonCurrentNsCtx->keys.kAusf = keys::CalculateKAusfFor5gAka(milenage.ck, milenage.ik, snn, sqnXorAk);
m_usim->m_nonCurrentNsCtx->keys.abba = msg.abba.rawData.copy(); m_usim->m_nonCurrentNsCtx->keys.abba = msg.abba.rawData.copy();
keys::DeriveKeysSeafAmf(*m_base->config, m_base->shCtx.getCurrentPlmn(), *m_usim->m_nonCurrentNsCtx); keys::DeriveKeysSeafAmf(*m_base->config, currentPLmn, *m_usim->m_nonCurrentNsCtx);
// Send response // Send response
m_nwConsecutiveAuthFailure = 0; m_nwConsecutiveAuthFailure = 0;
......
...@@ -241,7 +241,9 @@ void NasMm::receiveDeregistrationRequest(const nas::DeRegistrationRequestUeTermi ...@@ -241,7 +241,9 @@ void NasMm::receiveDeregistrationRequest(const nas::DeRegistrationRequestUeTermi
if (cause == nas::EMmCause::PLMN_NOT_ALLOWED) if (cause == nas::EMmCause::PLMN_NOT_ALLOWED)
{ {
m_storage->forbiddenPlmnList->add(m_base->shCtx.getCurrentPlmn()); Plmn plmn = m_base->shCtx.getCurrentPlmn();
if (plmn.hasValue())
m_storage->forbiddenPlmnList->add(plmn);
} }
if (cause == nas::EMmCause::TA_NOT_ALLOWED) if (cause == nas::EMmCause::TA_NOT_ALLOWED)
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <algorithm> #include <algorithm>
#include <lib/nas/utils.hpp> #include <lib/nas/utils.hpp>
#include <ue/nas/task.hpp> #include <ue/nas/task.hpp>
#include <utils/common.hpp>
namespace nr::ue namespace nr::ue
{ {
...@@ -231,6 +230,12 @@ void NasMm::receiveRegistrationAccept(const nas::RegistrationAccept &msg) ...@@ -231,6 +230,12 @@ void NasMm::receiveRegistrationAccept(const nas::RegistrationAccept &msg)
void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg) void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg)
{ {
Tai currentTai = m_base->shCtx.getCurrentTai();
Plmn currentPlmn = currentTai.plmn;
if (!currentTai.hasValue())
return;
// Store the TAI list as a registration area // Store the TAI list as a registration area
if (msg.taiList.has_value() && nas::utils::TaiListSize(*msg.taiList) == 0) if (msg.taiList.has_value() && nas::utils::TaiListSize(*msg.taiList) == 0)
{ {
...@@ -239,7 +244,6 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg) ...@@ -239,7 +244,6 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg)
return; return;
} }
m_storage->taiList->set(msg.taiList.value_or(nas::IE5gsTrackingAreaIdentityList{})); m_storage->taiList->set(msg.taiList.value_or(nas::IE5gsTrackingAreaIdentityList{}));
Tai currentTai = m_base->shCtx.getCurrentTai();
if (currentTai.hasValue() && if (currentTai.hasValue() &&
nas::utils::TaiListContains(m_storage->taiList->get(), nas::VTrackingAreaIdentity{currentTai})) nas::utils::TaiListContains(m_storage->taiList->get(), nas::VTrackingAreaIdentity{currentTai}))
m_storage->lastVisitedRegisteredTai->set(currentTai); m_storage->lastVisitedRegisteredTai->set(currentTai);
...@@ -262,7 +266,7 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg) ...@@ -262,7 +266,7 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg)
[this](auto &forbiddenPlmn) { m_storage->equivalentPlmnList->remove(forbiddenPlmn); }); [this](auto &forbiddenPlmn) { m_storage->equivalentPlmnList->remove(forbiddenPlmn); });
} }
// .. in addition, the UE shall add to the stored list the PLMN code of the registered PLMN that sent the list // .. in addition, the UE shall add to the stored list the PLMN code of the registered PLMN that sent the list
m_storage->equivalentPlmnList->add(m_base->shCtx.getCurrentPlmn()); m_storage->equivalentPlmnList->add(currentPlmn);
// Upon receipt of the REGISTRATION ACCEPT message, the UE shall reset the registration attempt counter, enter state // Upon receipt of the REGISTRATION ACCEPT message, the UE shall reset the registration attempt counter, enter state
// 5GMM-REGISTERED and set the 5GS update status to 5U1 UPDATED. // 5GMM-REGISTERED and set the 5GS update status to 5U1 UPDATED.
...@@ -352,6 +356,12 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg) ...@@ -352,6 +356,12 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg)
void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg) void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg)
{ {
Tai currentTai = m_base->shCtx.getCurrentTai();
Plmn currentPlmn = currentTai.plmn;
if (!currentTai.hasValue())
return;
// "The UE, upon receiving a REGISTRATION ACCEPT message, shall delete its old TAI list and store the received TAI // "The UE, upon receiving a REGISTRATION ACCEPT message, shall delete its old TAI list and store the received TAI
// list. If there is no TAI list received, the UE shall consider the old TAI list as valid." // list. If there is no TAI list received, the UE shall consider the old TAI list as valid."
if (msg.taiList.has_value()) if (msg.taiList.has_value())
...@@ -364,9 +374,7 @@ void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg ...@@ -364,9 +374,7 @@ void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg
} }
m_storage->taiList->set(*msg.taiList); m_storage->taiList->set(*msg.taiList);
if (nas::utils::TaiListContains(*msg.taiList, nas::VTrackingAreaIdentity{currentTai}))
Tai currentTai = m_base->shCtx.getCurrentTai();
if (currentTai.hasValue() && nas::utils::TaiListContains(*msg.taiList, nas::VTrackingAreaIdentity{currentTai}))
m_storage->lastVisitedRegisteredTai->set(currentTai); m_storage->lastVisitedRegisteredTai->set(currentTai);
} }
...@@ -383,7 +391,7 @@ void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg ...@@ -383,7 +391,7 @@ void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg
[this](auto &forbiddenPlmn) { m_storage->equivalentPlmnList->remove(forbiddenPlmn); }); [this](auto &forbiddenPlmn) { m_storage->equivalentPlmnList->remove(forbiddenPlmn); });
} }
// .. in addition, the UE shall add to the stored list the PLMN code of the registered PLMN that sent the list // .. in addition, the UE shall add to the stored list the PLMN code of the registered PLMN that sent the list
m_storage->equivalentPlmnList->add(m_base->shCtx.getCurrentPlmn()); m_storage->equivalentPlmnList->add(currentPlmn);
// Store the service area list // Store the service area list
m_storage->serviceAreaList->set(msg.serviceAreaList.value_or(nas::IEServiceAreaList{})); m_storage->serviceAreaList->set(msg.serviceAreaList.value_or(nas::IEServiceAreaList{}));
...@@ -603,6 +611,8 @@ void NasMm::receiveInitialRegistrationReject(const nas::RegistrationReject &msg) ...@@ -603,6 +611,8 @@ void NasMm::receiveInitialRegistrationReject(const nas::RegistrationReject &msg)
if (cause == nas::EMmCause::PLMN_NOT_ALLOWED || cause == nas::EMmCause::SERVING_NETWORK_NOT_AUTHORIZED) if (cause == nas::EMmCause::PLMN_NOT_ALLOWED || cause == nas::EMmCause::SERVING_NETWORK_NOT_AUTHORIZED)
{ {
Plmn plmn = m_base->shCtx.getCurrentPlmn();
if (plmn.hasValue())
m_storage->forbiddenPlmnList->add(m_base->shCtx.getCurrentPlmn()); m_storage->forbiddenPlmnList->add(m_base->shCtx.getCurrentPlmn());
} }
...@@ -763,7 +773,9 @@ void NasMm::receiveMobilityRegistrationReject(const nas::RegistrationReject &msg ...@@ -763,7 +773,9 @@ void NasMm::receiveMobilityRegistrationReject(const nas::RegistrationReject &msg
if (cause == nas::EMmCause::PLMN_NOT_ALLOWED || cause == nas::EMmCause::SERVING_NETWORK_NOT_AUTHORIZED) if (cause == nas::EMmCause::PLMN_NOT_ALLOWED || cause == nas::EMmCause::SERVING_NETWORK_NOT_AUTHORIZED)
{ {
m_storage->forbiddenPlmnList->add(m_base->shCtx.getCurrentPlmn()); Plmn plmn = m_base->shCtx.getCurrentPlmn();
if (plmn.hasValue())
m_storage->forbiddenPlmnList->add(plmn);
} }
if (cause == nas::EMmCause::CONGESTION) if (cause == nas::EMmCause::CONGESTION)
...@@ -865,7 +877,7 @@ void NasMm::handleAbnormalMobilityRegFailure(nas::ERegistrationType regType) ...@@ -865,7 +877,7 @@ void NasMm::handleAbnormalMobilityRegFailure(nas::ERegistrationType regType)
{ {
auto tai = m_base->shCtx.getCurrentTai(); auto tai = m_base->shCtx.getCurrentTai();
bool includedInTaiList = bool includedInTaiList =
nas::utils::TaiListContains(m_storage->taiList->get(), nas::VTrackingAreaIdentity{tai}); tai.hasValue() && nas::utils::TaiListContains(m_storage->taiList->get(), nas::VTrackingAreaIdentity{tai});
// "If the TAI of the current serving cell is not included in the TAI list or the 5GS update status is different // "If the TAI of the current serving cell is not included in the TAI list or the 5GS update status is different
// to 5U1 UPDATED" // to 5U1 UPDATED"
......
...@@ -34,8 +34,13 @@ void NasMm::sendServiceRequest(EServiceReqCause reqCause) ...@@ -34,8 +34,13 @@ void NasMm::sendServiceRequest(EServiceReqCause reqCause)
m_logger->err("Service Request canceled, UE not in 5U1 UPDATED state"); m_logger->err("Service Request canceled, UE not in 5U1 UPDATED state");
return; return;
} }
if (!nas::utils::TaiListContains(m_storage->taiList->get(), Tai currentTai = m_base->shCtx.getCurrentTai();
nas::VTrackingAreaIdentity{m_base->shCtx.getCurrentTai()})) if (!currentTai.hasValue())
{
m_logger->err("Service Request canceled, no active cell exists");
return;
}
if (!nas::utils::TaiListContains(m_storage->taiList->get(), nas::VTrackingAreaIdentity{currentTai}))
{ {
m_logger->err("Service Request canceled, current TAI is not in the TAI list"); m_logger->err("Service Request canceled, current TAI is not in the TAI list");
return; return;
...@@ -306,7 +311,9 @@ void NasMm::receiveServiceReject(const nas::ServiceReject &msg) ...@@ -306,7 +311,9 @@ void NasMm::receiveServiceReject(const nas::ServiceReject &msg)
if (cause == nas::EMmCause::PLMN_NOT_ALLOWED || cause == nas::EMmCause::SERVING_NETWORK_NOT_AUTHORIZED) if (cause == nas::EMmCause::PLMN_NOT_ALLOWED || cause == nas::EMmCause::SERVING_NETWORK_NOT_AUTHORIZED)
{ {
m_storage->forbiddenPlmnList->add(m_base->shCtx.getCurrentPlmn()); Plmn plmn = m_base->shCtx.getCurrentPlmn();
if (plmn.hasValue())
m_storage->forbiddenPlmnList->add(plmn);
} }
if (cause == nas::EMmCause::TA_NOT_ALLOWED) if (cause == nas::EMmCause::TA_NOT_ALLOWED)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment