Files
Rakesh BB 25f3d632f4 [NGAP] Fix incorrect AMF Set ID type (uint8 → uint16) causing AMF lookup failure
- Corrected AMF Set ID data type in ngap_gNB_nnsf_select_amf_by_amf_setid() from uint8_t to uint16_t.

- AMF Set ID is a 10-bit field as per 3GPP TS 38.413 §9.3.3.12.

- The incorrect data type caused truncation for AMF Set IDs >255, leading to lookup failures during RRC reestablishment.

- Verified successful reestablishment with large AMF Set IDs after the fix.

Reason for fix: AMF lookup using AMF Set ID was failing because the 10-bit AMF Set ID was truncated to 8 bits.

Closes #1012
2025-10-28 12:23:14 +05:30

410 lines
15 KiB
C

/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file ngap_gNB_nnsf.c
* \brief ngap NAS node selection functions
* \author Yoshio INOUE, Masayuki HARADA
* \date 2020
* \version 0.1
* \email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com (yoshio.inoue%40fujitsu.com%2cmasayuki.harada%40fujitsu.com)
*/
#include "ngap_gNB_nnsf.h"
#include <stdio.h>
#include "ngap_gNB_defs.h"
#include "ngap_common.h"
#include "queue.h"
#include "tree.h"
ngap_gNB_amf_data_t *ngap_gNB_nnsf_select_amf(ngap_gNB_instance_t *instance_p, const ngap_rrc_establishment_cause_t cause)
{
struct ngap_gNB_amf_data_s *amf_data_p = NULL;
struct ngap_gNB_amf_data_s *amf_highest_capacity_p = NULL;
uint8_t current_capacity = 0;
RB_FOREACH(amf_data_p, ngap_amf_map, &instance_p->ngap_amf_head) {
if (amf_data_p->state != NGAP_GNB_STATE_CONNECTED) {
/* The association between AMF and gNB is not ready for the moment,
* go to the next known AMF.
*/
if (amf_data_p->state == NGAP_GNB_OVERLOAD) {
/* AMF is overloaded. We have to check the RRC establishment
* cause and take decision to the select this AMF depending on
* the overload state.
*/
if ((cause == NGAP_RRC_CAUSE_MO_DATA)
&& (amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_MO_DATA)) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_ALL_SIGNALLING)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA))) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA)
|| (cause == NGAP_RRC_CAUSE_HIGH_PRIO_ACCESS))) {
continue;
}
/* At this point, the RRC establishment can be handled by the AMF
* even if it is in overload state.
*/
} else {
/* The AMF is not overloaded, association is simply not ready. */
continue;
}
}
if (current_capacity < amf_data_p->relative_amf_capacity) {
/* We find a better AMF, keep a reference to it */
current_capacity = amf_data_p->relative_amf_capacity;
amf_highest_capacity_p = amf_data_p;
}
}
return amf_highest_capacity_p;
}
ngap_gNB_amf_data_t *ngap_gNB_nnsf_select_amf_by_plmn_id(ngap_gNB_instance_t *instance_p,
const ngap_rrc_establishment_cause_t cause,
const plmn_id_t selected_plmn_identity)
{
struct ngap_gNB_amf_data_s *amf_data_p = NULL;
struct ngap_gNB_amf_data_s *amf_highest_capacity_p = NULL;
uint8_t current_capacity = 0;
RB_FOREACH(amf_data_p, ngap_amf_map, &instance_p->ngap_amf_head) {
struct served_guami_s *guami_p = NULL;
struct plmn_identity_s *served_plmn_p = NULL;
if (amf_data_p->state != NGAP_GNB_STATE_CONNECTED) {
/* The association between AMF and gNB is not ready for the moment,
* go to the next known AMF.
*/
if (amf_data_p->state == NGAP_GNB_OVERLOAD) {
/* AMF is overloaded. We have to check the RRC establishment
* cause and take decision to the select this AMF depending on
* the overload state.
*/
if ((cause == NGAP_RRC_CAUSE_MO_DATA)
&& (amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_MO_DATA)) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_ALL_SIGNALLING)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA))) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA)
|| (cause == NGAP_RRC_CAUSE_HIGH_PRIO_ACCESS))) {
continue;
}
/* At this point, the RRC establishment can be handled by the AMF
* even if it is in overload state.
*/
} else {
/* The AMF is not overloaded, association is simply not ready. */
continue;
}
}
/* Looking for served GUAMI PLMN Identity selected matching the one provided by the UE */
STAILQ_FOREACH(guami_p, &amf_data_p->served_guami, next) {
STAILQ_FOREACH(served_plmn_p, &guami_p->served_plmns, next) {
if ((served_plmn_p->mcc == selected_plmn_identity.mcc) && (served_plmn_p->mnc == selected_plmn_identity.mnc)) {
break;
}
}
/* if found, we can stop the outer loop, too */
if (served_plmn_p) break;
}
/* if we didn't find such a served PLMN, go on with the next AMF */
if (!served_plmn_p) continue;
if (current_capacity < amf_data_p->relative_amf_capacity) {
/* We find a better AMF, keep a reference to it */
current_capacity = amf_data_p->relative_amf_capacity;
amf_highest_capacity_p = amf_data_p;
}
}
return amf_highest_capacity_p;
}
ngap_gNB_amf_data_t *ngap_gNB_nnsf_select_amf_by_amf_setid(ngap_gNB_instance_t *instance_p,
const ngap_rrc_establishment_cause_t cause,
const plmn_id_t selected_plmn_identity,
uint16_t amf_setid)
{
struct ngap_gNB_amf_data_s *amf_data_p = NULL;
RB_FOREACH(amf_data_p, ngap_amf_map, &instance_p->ngap_amf_head) {
struct served_guami_s *guami_p = NULL;
if (amf_data_p->state != NGAP_GNB_STATE_CONNECTED) {
/* The association between AMF and gNB is not ready for the moment,
* go to the next known AMF.
*/
if (amf_data_p->state == NGAP_GNB_OVERLOAD) {
/* AMF is overloaded. We have to check the RRC establishment
* cause and take decision to the select this AMF depending on
* the overload state.
*/
if ((cause == NGAP_RRC_CAUSE_MO_DATA)
&& (amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_MO_DATA)) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_ALL_SIGNALLING)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA))) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA)
|| (cause == NGAP_RRC_CAUSE_HIGH_PRIO_ACCESS))) {
continue;
}
/* At this point, the RRC establishment can be handled by the AMF
* even if it is in overload state.
*/
} else {
/* The AMF is not overloaded, association is simply not ready. */
continue;
}
}
/* Looking for AMF code matching the one provided by NAS */
STAILQ_FOREACH(guami_p, &amf_data_p->served_guami, next) {
struct amf_set_id_s *amf_setid_p = NULL;
struct plmn_identity_s *served_plmn_p = NULL;
STAILQ_FOREACH(served_plmn_p, &guami_p->served_plmns, next) {
if ((served_plmn_p->mcc == selected_plmn_identity.mcc) && (served_plmn_p->mnc == selected_plmn_identity.mnc)) {
break;
}
}
STAILQ_FOREACH(amf_setid_p, &guami_p->amf_set_ids, next) {
if (amf_setid_p->amf_set_id == amf_setid) {
break;
}
}
/* The AMF matches the parameters provided by the NAS layer ->
* the AMF is knwown and the association is ready.
* Return the reference to the AMF to use it for this UE.
*/
if (amf_setid_p && served_plmn_p) {
return amf_data_p;
}
}
}
NGAP_WARN("No matching AMF found for PLMN (MCC=%03d MNC=%0*d) and AMF SetID=%u\n",
selected_plmn_identity.mcc,
selected_plmn_identity.mnc_digit_length,
selected_plmn_identity.mnc,
amf_setid);
/* At this point no AMF matches the selected PLMN and AMF code. In this case,
* return NULL. That way the RRC layer should know about it and reject RRC
* connectivity. */
return NULL;
}
ngap_gNB_amf_data_t *ngap_gNB_nnsf_select_amf_by_guami(ngap_gNB_instance_t *instance_p,
const ngap_rrc_establishment_cause_t cause,
const nr_guami_t guami)
{
struct ngap_gNB_amf_data_s *amf_data_p = NULL;
RB_FOREACH(amf_data_p, ngap_amf_map, &instance_p->ngap_amf_head) {
struct served_guami_s *guami_p = NULL;
if (amf_data_p->state != NGAP_GNB_STATE_CONNECTED) {
/* The association between AMF and gNB is not ready for the moment,
* go to the next known AMF.
*/
if (amf_data_p->state == NGAP_GNB_OVERLOAD) {
/* AMF is overloaded. We have to check the RRC establishment
* cause and take decision to the select this AMF depending on
* the overload state.
*/
if ((cause == NGAP_RRC_CAUSE_MO_DATA)
&& (amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_MO_DATA)) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_REJECT_ALL_SIGNALLING)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA))) {
continue;
}
if ((amf_data_p->overload_state == NGAP_OVERLOAD_ONLY_EMERGENCY_AND_MT)
&& ((cause == NGAP_RRC_CAUSE_MO_SIGNALLING) || (cause == NGAP_RRC_CAUSE_MO_DATA)
|| (cause == NGAP_RRC_CAUSE_HIGH_PRIO_ACCESS))) {
continue;
}
/* At this point, the RRC establishment can be handled by the AMF
* even if it is in overload state.
*/
} else {
/* The AMF is not overloaded, association is simply not ready. */
continue;
}
}
/* Looking for AMF guami matching the one provided by NAS */
STAILQ_FOREACH(guami_p, &amf_data_p->served_guami, next) {
struct served_region_id_s *region_id_p = NULL;
struct amf_set_id_s *amf_set_id_p = NULL;
struct amf_pointer_s *pointer_p = NULL;
struct plmn_identity_s *served_plmn_p = NULL;
STAILQ_FOREACH(served_plmn_p, &guami_p->served_plmns, next) {
if ((served_plmn_p->mcc == guami.plmn.mcc) && (served_plmn_p->mnc == guami.plmn.mnc)) {
break;
}
}
STAILQ_FOREACH(region_id_p, &guami_p->served_region_ids, next) {
if (region_id_p->amf_region_id == guami.amf_region_id) {
break;
}
}
STAILQ_FOREACH(amf_set_id_p, &guami_p->amf_set_ids, next) {
if (amf_set_id_p->amf_set_id == guami.amf_set_id) {
break;
}
}
STAILQ_FOREACH(pointer_p, &guami_p->amf_pointers, next) {
if (pointer_p->amf_pointer == guami.amf_pointer) {
break;
}
}
/* The AMF matches the parameters provided by the NAS layer ->
* the AMF is knwown and the association is ready.
* Return the reference to the AMF to use it for this UE.
*/
if ((region_id_p != NULL) &&
(amf_set_id_p != NULL) &&
(pointer_p != NULL) &&
(served_plmn_p != NULL)) {
return amf_data_p;
}
}
}
NGAP_WARN("No matching AMF found for GUAMI (MCC=%03d MNC=%0*d RegionID=%d SetID=%d Pointer=%d)\n",
guami.plmn.mcc,
guami.plmn.mnc_digit_length,
guami.plmn.mnc,
guami.amf_region_id,
guami.amf_set_id,
guami.amf_pointer);
/* At this point no AMF matches the provided GUAMI. In this case, return
* NULL. That way the RRC layer should know about it and reject RRC
* connectivity. */
return NULL;
}
ngap_gNB_amf_data_t *ngap_gNB_nnsf_select_amf_by_guami_no_cause(ngap_gNB_instance_t *instance_p, const nr_guami_t guami)
{
struct ngap_gNB_amf_data_s *amf_data_p = NULL;
struct ngap_gNB_amf_data_s *amf_highest_capacity_p = NULL;
uint8_t current_capacity = 0;
RB_FOREACH(amf_data_p, ngap_amf_map, &instance_p->ngap_amf_head) {
struct served_guami_s *guami_p = NULL;
if (amf_data_p->state != NGAP_GNB_STATE_CONNECTED) {
/* The association between AMF and gNB is not ready for the moment,
* go to the next known AMF.
*/
if (amf_data_p->state == NGAP_GNB_OVERLOAD) {
/* AMF is overloaded. We have to check the RRC establishment
* cause and take decision to the select this AMF depending on
* the overload state.
*/
} else {
/* The AMF is not overloaded, association is simply not ready. */
continue;
}
}
if (current_capacity < amf_data_p->relative_amf_capacity) {
/* We find a better AMF, keep a reference to it */
current_capacity = amf_data_p->relative_amf_capacity;
amf_highest_capacity_p = amf_data_p;
}
/* Looking for AMF guami matching the one provided by NAS */
STAILQ_FOREACH(guami_p, &amf_data_p->served_guami, next) {
struct served_region_id_s *region_id_p = NULL;
struct amf_set_id_s *amf_set_id_p = NULL;
struct plmn_identity_s *served_plmn_p = NULL;
STAILQ_FOREACH(served_plmn_p, &guami_p->served_plmns, next) {
if ((served_plmn_p->mcc == guami.plmn.mcc) && (served_plmn_p->mnc == guami.plmn.mnc)) {
break;
}
}
STAILQ_FOREACH(amf_set_id_p, &guami_p->amf_set_ids, next) {
if (amf_set_id_p->amf_set_id == guami.amf_set_id) {
break;
}
}
STAILQ_FOREACH(region_id_p, &guami_p->served_region_ids, next) {
if (region_id_p->amf_region_id == guami.amf_region_id) {
break;
}
}
/* The AMF matches the parameters provided by the NAS layer ->
* the AMF is knwown and the association is ready.
* Return the reference to the AMF to use it for this UE.
*/
if ((region_id_p != NULL) &&
(amf_set_id_p != NULL) &&
(served_plmn_p != NULL)) {
return amf_data_p;
}
}
}
/* At this point no AMF matches the provided GUAMI. Select the one with the
* highest relative capacity.
* In case the list of known AMF is empty, simply return NULL, that way the RRC
* layer should know about it and reject RRC connectivity.
*/
return amf_highest_capacity_p;
}