Commit e88fe80f authored by Guido Casati's avatar Guido Casati

Use 5G-S-TMSI in RRC connection setup procedures

* Use 5G-S-TMSI part 1 in RRCSetupRequest according to TS 38.331 clause 5.3.3.3
* Send indication of 5GMM info from NAS to RRC: transfer the 5G-S-TMSI to RRC to be used as UE identity
* Set the ng-5G-S-TMSI-Value in RRCSetupComplete to ng-5G-S-TMSI-Part2 according to 5.3.3.4 of 3GPP TS 38.331
* current and only scenario: RRCSetup is received in response to an RRCSetupRequest
parent 576f185a
......@@ -771,7 +771,7 @@ int do_RRCReconfiguration(const gNB_RRC_UE_t *UE,
return((enc_rval.encoded+7)/8);
}
int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv)
int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv, uint64_t fiveG_S_TMSI)
{
NR_UL_CCCH_Message_t ul_ccch_msg = {0};
ul_ccch_msg.message.present = NR_UL_CCCH_MessageType_PR_c1;
......@@ -779,7 +779,8 @@ int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv)
c1->present = NR_UL_CCCH_MessageType__c1_PR_rrcSetupRequest;
asn1cCalloc(c1->choice.rrcSetupRequest, rrcSetupRequest);
if (1) {
if (fiveG_S_TMSI == UINT64_MAX) {
/* set the ue-Identity to a random value */
rrcSetupRequest->rrcSetupRequest.ue_Identity.present = NR_InitialUE_Identity_PR_randomValue;
BIT_STRING_t *str = &rrcSetupRequest->rrcSetupRequest.ue_Identity.choice.randomValue;
str->size = 5;
......@@ -791,12 +792,24 @@ int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv)
str->buf[3] = rv[3];
str->buf[4] = rv[4] & 0xfe;
} else {
uint64_t fiveG_S_TMSI_part1 = fiveG_S_TMSI & ((1ULL << 39) - 1);
/** set the ue-Identity to ng-5G-S-TMSI-Part1
* ng-5G-S-TMSI-Part1: the rightmost 39 bits of 5G-S-TMSI
* BIT STRING (SIZE (39)) - 3GPP TS 38.331 */
LOG_D(NR_RRC, "5G-S-TMSI: %lu, set the ue-Identity to ng-5G-S-TMSI-Part1 %lu\n", fiveG_S_TMSI, fiveG_S_TMSI_part1);
rrcSetupRequest->rrcSetupRequest.ue_Identity.present = NR_InitialUE_Identity_PR_ng_5G_S_TMSI_Part1;
BIT_STRING_t *str = &rrcSetupRequest->rrcSetupRequest.ue_Identity.choice.ng_5G_S_TMSI_Part1;
str->size = 1;
str->bits_unused = 0;
str->size = 5;
str->bits_unused = 1;
str->buf = CALLOC(1, str->size);
str->buf[0] = 0x12;
/* shift, mask and fill the buffer */
int i;
uint8_t mask = 0xFF;
for (i = 0; i < str->size - 1; i++) {
int shift = ((str->size - i - 1) * 8) - str->bits_unused;
str->buf[i] = (fiveG_S_TMSI_part1 >> shift) & mask;
}
str->buf[i] = (fiveG_S_TMSI_part1 << str->bits_unused) & mask;
}
rrcSetupRequest->rrcSetupRequest.establishmentCause = NR_EstablishmentCause_mo_Signalling; //EstablishmentCause_mo_Data;
......@@ -877,6 +890,8 @@ int do_RRCSetupComplete(uint8_t *buffer,
size_t buffer_size,
const uint8_t Transaction_id,
uint8_t sel_plmn_id,
bool is_rrc_connection_setup,
uint64_t fiveG_s_tmsi,
const int dedicatedInfoNASLength,
const char *dedicatedInfoNAS)
{
......@@ -892,7 +907,21 @@ int do_RRCSetupComplete(uint8_t *buffer,
NR_RRCSetupComplete_IEs_t *ies = RrcSetupComplete->criticalExtensions.choice.rrcSetupComplete;
ies->selectedPLMN_Identity = sel_plmn_id;
ies->registeredAMF = NULL;
/* RRCSetup is received in response to an RRCSetupRequest
* set the ng-5G-S-TMSI-Value to ng-5G-S-TMSI-Part2 (5.3.3.4 of 3GPP TS 38.331) */
if (fiveG_s_tmsi != UINT64_MAX) {
if (is_rrc_connection_setup) {
ies->ng_5G_S_TMSI_Value = CALLOC(1, sizeof(struct NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value));
ies->ng_5G_S_TMSI_Value->present = NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value_PR_ng_5G_S_TMSI_Part2;
INT16_TO_BIT_STRING((uint16_t)fiveG_s_tmsi, &ies->ng_5G_S_TMSI_Value->choice.ng_5G_S_TMSI_Part2);
} else {
ies->ng_5G_S_TMSI_Value = CALLOC(1, sizeof(struct NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value));
ies->ng_5G_S_TMSI_Value->present = NR_RRCSetupComplete_IEs__ng_5G_S_TMSI_Value_PR_ng_5G_S_TMSI;
FIVEG_S_TMSI_TO_BIT_STRING(fiveG_s_tmsi, &ies->ng_5G_S_TMSI_Value->choice.ng_5G_S_TMSI);
}
} else {
ies->ng_5G_S_TMSI_Value = NULL;
}
memset(&ies->dedicatedNAS_Message,0,sizeof(OCTET_STRING_t));
OCTET_STRING_fromBuf(&ies->dedicatedNAS_Message, dedicatedInfoNAS, dedicatedInfoNASLength);
......
......@@ -110,10 +110,12 @@ int do_RRCSetupComplete(uint8_t *buffer,
size_t buffer_size,
const uint8_t Transaction_id,
uint8_t sel_plmn_id,
bool is_rrc_connection_setup,
uint64_t fiveG_S_TMSI,
const int dedicatedInfoNASLength,
const char *dedicatedInfoNAS);
int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv);
int do_RRCSetupRequest(uint8_t *buffer, size_t buffer_size, uint8_t *rv, uint64_t fiveG_S_TMSI_part1);
int do_NR_RRCReconfigurationComplete_for_nsa(uint8_t *buffer, size_t buffer_size, NR_RRC_TransactionIdentifier_t Transaction_id);
......
......@@ -682,10 +682,8 @@ static void nr_rrc_ue_prepare_RRCSetupRequest(NR_UE_RRC_INST_t *rrc)
rv[i] = taus() & 0xff;
#endif
}
uint8_t buf[1024];
int len = do_RRCSetupRequest(buf, sizeof(buf), rv);
int len = do_RRCSetupRequest(buf, sizeof(buf), rv, rrc->fiveG_S_TMSI);
nr_rlc_srb_recv_sdu(rrc->ue_id, 0, buf, len);
}
......@@ -909,7 +907,21 @@ static void rrc_ue_generate_RRCSetupComplete(const NR_UE_RRC_INST_t *rrc, const
nas_msg_length = sizeof(nr_nas_attach_req_imsi_dummy_NSA_case);
}
int size = do_RRCSetupComplete(buffer, sizeof(buffer), Transaction_id, rrc->selected_plmn_identity, nas_msg_length, nas_msg);
/* ng-5G-S-TMSI-Part2: The leftmost 9 bits of 5G-S-TMSI. */
if (rrc->fiveG_S_TMSI == UINT64_MAX)
LOG_D(NR_RRC, "5G-S-TMSI is not available!\n");
uint64_t fiveG_S_TMSI =
rrc->fiveG_S_TMSI != UINT64_MAX
? rrc->ra_trigger == RRC_CONNECTION_SETUP ? (rrc->fiveG_S_TMSI >> 39) & ((1ULL << 9) - 1) : rrc->fiveG_S_TMSI
: UINT64_MAX;
int size = do_RRCSetupComplete(buffer,
sizeof(buffer),
Transaction_id,
rrc->selected_plmn_identity,
rrc->ra_trigger == RRC_CONNECTION_SETUP,
fiveG_S_TMSI,
nas_msg_length,
nas_msg);
LOG_I(NR_RRC, "[UE %ld][RAPROC] Logical Channel UL-DCCH (SRB1), Generating RRCSetupComplete (bytes%d)\n", rrc->ue_id, size);
int srb_id = 1; // RRC setup complete on SRB1
LOG_D(NR_RRC, "[RRC_UE %ld] PDCP_DATA_REQ/%d Bytes RRCSetupComplete ---> %d\n", rrc->ue_id, size, srb_id);
......
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