Commit d67a3c52 authored by aligungr's avatar aligungr

L3 RRC/NAS developments

parent dc8bebb8
......@@ -48,19 +48,20 @@ bool NasMm::isInNonAllowedArea()
if (!m_usim->isValid())
return false;
auto plmn = m_base->shCtx.getCurrentPlmn();
if (!plmn.hasValue())
auto currentCell = m_base->shCtx.currentCell.get();
if (!currentCell.hasValue())
return false;
auto plmn = currentCell.plmn;
if (nas::utils::ServiceAreaListForbidsPlmn(m_storage->serviceAreaList->get(), nas::utils::PlmnFrom(plmn)))
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(),
nas::VTrackingAreaIdentity{nas::utils::PlmnFrom(plmn), octet3{tac}}))
{
return true;
}
return false;
}
......
......@@ -34,6 +34,10 @@ void NasMm::receiveAuthenticationRequest(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) {
// Clear RAND and RES* stored in volatile memory
m_usim->m_rand = {};
......@@ -111,7 +115,7 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms
return;
}
auto snn = keys::ConstructServingNetworkName(m_base->shCtx.getCurrentPlmn());
auto snn = keys::ConstructServingNetworkName(currentPlmn);
if (receivedEap.attributes.getKdfInput() != OctetString::FromAscii(snn))
{
......@@ -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.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
m_nwConsecutiveAuthFailure = 0;
......@@ -257,6 +261,10 @@ void NasMm::receiveAuthenticationRequestEap(const nas::AuthenticationRequest &ms
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) {
if (cause != nas::EMmCause::SYNCH_FAILURE)
m_logger->err("Sending Authentication Failure with cause [%s]", nas::utils::EnumToString(cause));
......@@ -346,7 +354,7 @@ void NasMm::receiveAuthenticationRequest5gAka(const nas::AuthenticationRequest &
auto milenage = calculateMilenage(m_usim->m_sqnMng->getSqn(), rand, false);
auto ckIk = OctetString::Concat(milenage.ck, milenage.ik);
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
m_usim->m_rand = rand.copy();
......@@ -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.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
m_nwConsecutiveAuthFailure = 0;
......
......@@ -241,7 +241,9 @@ void NasMm::receiveDeregistrationRequest(const nas::DeRegistrationRequestUeTermi
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)
......
......@@ -11,7 +11,6 @@
#include <algorithm>
#include <lib/nas/utils.hpp>
#include <ue/nas/task.hpp>
#include <utils/common.hpp>
namespace nr::ue
{
......@@ -231,6 +230,12 @@ void NasMm::receiveRegistrationAccept(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
if (msg.taiList.has_value() && nas::utils::TaiListSize(*msg.taiList) == 0)
{
......@@ -239,7 +244,6 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg)
return;
}
m_storage->taiList->set(msg.taiList.value_or(nas::IE5gsTrackingAreaIdentityList{}));
Tai currentTai = m_base->shCtx.getCurrentTai();
if (currentTai.hasValue() &&
nas::utils::TaiListContains(m_storage->taiList->get(), nas::VTrackingAreaIdentity{currentTai}))
m_storage->lastVisitedRegisteredTai->set(currentTai);
......@@ -262,7 +266,7 @@ void NasMm::receiveInitialRegistrationAccept(const nas::RegistrationAccept &msg)
[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
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
// 5GMM-REGISTERED and set the 5GS update status to 5U1 UPDATED.
......@@ -352,6 +356,12 @@ void NasMm::receiveInitialRegistrationAccept(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
// list. If there is no TAI list received, the UE shall consider the old TAI list as valid."
if (msg.taiList.has_value())
......@@ -364,9 +374,7 @@ void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg
}
m_storage->taiList->set(*msg.taiList);
Tai currentTai = m_base->shCtx.getCurrentTai();
if (currentTai.hasValue() && nas::utils::TaiListContains(*msg.taiList, nas::VTrackingAreaIdentity{currentTai}))
if (nas::utils::TaiListContains(*msg.taiList, nas::VTrackingAreaIdentity{currentTai}))
m_storage->lastVisitedRegisteredTai->set(currentTai);
}
......@@ -383,7 +391,7 @@ void NasMm::receiveMobilityRegistrationAccept(const nas::RegistrationAccept &msg
[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
m_storage->equivalentPlmnList->add(m_base->shCtx.getCurrentPlmn());
m_storage->equivalentPlmnList->add(currentPlmn);
// Store the service area list
m_storage->serviceAreaList->set(msg.serviceAreaList.value_or(nas::IEServiceAreaList{}));
......@@ -603,7 +611,9 @@ void NasMm::receiveInitialRegistrationReject(const nas::RegistrationReject &msg)
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(m_base->shCtx.getCurrentPlmn());
}
if (cause == nas::EMmCause::CONGESTION)
......@@ -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)
{
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)
......@@ -865,7 +877,7 @@ void NasMm::handleAbnormalMobilityRegFailure(nas::ERegistrationType regType)
{
auto tai = m_base->shCtx.getCurrentTai();
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
// to 5U1 UPDATED"
......
......@@ -34,8 +34,13 @@ void NasMm::sendServiceRequest(EServiceReqCause reqCause)
m_logger->err("Service Request canceled, UE not in 5U1 UPDATED state");
return;
}
if (!nas::utils::TaiListContains(m_storage->taiList->get(),
nas::VTrackingAreaIdentity{m_base->shCtx.getCurrentTai()}))
Tai currentTai = 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");
return;
......@@ -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)
{
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)
......
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