Commit 3a5ace00 authored by Guido Casati's avatar Guido Casati

Use F1AP lib for F1 Setup Response in stack

parent df2c92e6
......@@ -102,142 +102,26 @@ int CU_handle_F1_SETUP_REQUEST(instance_t instance, sctp_assoc_t assoc_id, uint3
return 0;
}
/**
* @brief F1AP Setup Response encoding (9.2.1.5 of 3GPP TS 38.473) and message transfer
*/
int CU_send_F1_SETUP_RESPONSE(sctp_assoc_t assoc_id, f1ap_setup_resp_t *f1ap_setup_resp)
{
F1AP_F1AP_PDU_t pdu= {0};
uint8_t *buffer=NULL;
uint32_t len=0;
/* Create */
/* 0. Message Type */
pdu.present = F1AP_F1AP_PDU_PR_successfulOutcome;
asn1cCalloc(pdu.choice.successfulOutcome, tmp);
tmp->procedureCode = F1AP_ProcedureCode_id_F1Setup;
tmp->criticality = F1AP_Criticality_reject;
tmp->value.present = F1AP_SuccessfulOutcome__value_PR_F1SetupResponse;
F1AP_F1SetupResponse_t *out = &pdu.choice.successfulOutcome->value.choice.F1SetupResponse;
/* mandatory */
/* c1. Transaction ID (integer value)*/
asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupResponseIEs_t, ie1);
ie1->id = F1AP_ProtocolIE_ID_id_TransactionID;
ie1->criticality = F1AP_Criticality_reject;
ie1->value.present = F1AP_F1SetupResponseIEs__value_PR_TransactionID;
ie1->value.choice.TransactionID = f1ap_setup_resp->transaction_id;
uint32_t len = 0;
/* optional */
/* c2. GNB_CU_Name */
if (f1ap_setup_resp->gNB_CU_name != NULL) {
asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupResponseIEs_t, ie2);
ie2->id = F1AP_ProtocolIE_ID_id_gNB_CU_Name;
ie2->criticality = F1AP_Criticality_ignore;
ie2->value.present = F1AP_F1SetupResponseIEs__value_PR_GNB_CU_Name;
OCTET_STRING_fromBuf(&ie2->value.choice.GNB_CU_Name, f1ap_setup_resp->gNB_CU_name,
strlen(f1ap_setup_resp->gNB_CU_name));
}
/* mandatory */
/* c3. cells to be Activated list */
int num_cells_to_activate = f1ap_setup_resp->num_cells_to_activate;
LOG_D(F1AP, "num_cells_to_activate = %d \n", num_cells_to_activate);
if (num_cells_to_activate >0) {
asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupResponseIEs_t, ie3);
ie3->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List;
ie3->criticality = F1AP_Criticality_reject;
ie3->value.present = F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List;
for (int i=0; i<num_cells_to_activate; i++) {
asn1cSequenceAdd(ie3->value.choice.Cells_to_be_Activated_List.list,
F1AP_Cells_to_be_Activated_List_ItemIEs_t, cells_to_be_activated_ies);
cells_to_be_activated_ies->id = F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item;
cells_to_be_activated_ies->criticality = F1AP_Criticality_reject;
cells_to_be_activated_ies->value.present = F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item;
/* 3.1 cells to be Activated list item */
F1AP_Cells_to_be_Activated_List_Item_t *cells_to_be_activated_item=
&cells_to_be_activated_ies->value.choice.Cells_to_be_Activated_List_Item;
/* - nRCGI */
addnRCGI(cells_to_be_activated_item->nRCGI, f1ap_setup_resp->cells_to_activate+i);
/* optional */
/* - nRPCI */
if (1) {
cells_to_be_activated_item->nRPCI = (F1AP_NRPCI_t *)calloc(1, sizeof(F1AP_NRPCI_t));
*cells_to_be_activated_item->nRPCI = f1ap_setup_resp->cells_to_activate[i].nrpci; // int 0..1007
}
/* optional */
/* - gNB-CU System Information */
if (f1ap_setup_resp->cells_to_activate[i].num_SI > 0) {
/* 3.1.2 gNB-CUSystem Information */
F1AP_ProtocolExtensionContainer_10696P112_t *p = calloc(1, sizeof(* p));
cells_to_be_activated_item->iE_Extensions = (struct F1AP_ProtocolExtensionContainer *) p;
asn1cSequenceAdd(p->list, F1AP_Cells_to_be_Activated_List_ItemExtIEs_t, cells_to_be_activated_itemExtIEs);
cells_to_be_activated_itemExtIEs->id = F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation;
cells_to_be_activated_itemExtIEs->criticality = F1AP_Criticality_reject;
cells_to_be_activated_itemExtIEs->extensionValue.present = F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation;
F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation =
&cells_to_be_activated_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
// for (int sIBtype=2;sIBtype<33;sIBtype++) { //21 ? 33 ?
for (int sIBtype=2; sIBtype<21; sIBtype++) {
for (int n = 0; n < f1ap_setup_resp->cells_to_activate[i].num_SI; n++) {
if (f1ap_setup_resp->cells_to_activate[i].SI_msg[n].SI_container != NULL) {
if (f1ap_setup_resp->cells_to_activate[i].SI_msg[n].SI_type > 6
&& f1ap_setup_resp->cells_to_activate[i].SI_msg[n].SI_type != 9) {
asn1cSequenceAdd(gNB_CUSystemInformation->sibtypetobeupdatedlist.list, F1AP_SibtypetobeupdatedListItem_t, sib_item);
sib_item->sIBtype = f1ap_setup_resp->cells_to_activate[i].SI_msg[n].SI_type;
OCTET_STRING_fromBuf(&sib_item->sIBmessage,
(const char *)f1ap_setup_resp->cells_to_activate[i].SI_msg[n].SI_container,
f1ap_setup_resp->cells_to_activate[i].SI_msg[n].SI_container_length);
LOG_D(F1AP,
"f1ap_setup_resp->cells_to_activate[%d].SI_msg[%d].SI_container_length = %d \n",
i,
n,
f1ap_setup_resp->cells_to_activate[i].SI_msg[n].SI_container_length);
}
}
}
}
}
}
}
/* c5. RRC VERSION */
asn1cSequenceAdd(out->protocolIEs.list, F1AP_F1SetupResponseIEs_t, ie4);
ie4->id = F1AP_ProtocolIE_ID_id_GNB_CU_RRC_Version;
ie4->criticality = F1AP_Criticality_reject;
ie4->value.present = F1AP_F1SetupResponseIEs__value_PR_RRC_Version;
// RRC Version: "This IE is not used in this release."
// we put one bit for each byte in rrc_ver that is != 0
uint8_t bits = 0;
for (int i = 0; i < 3; ++i)
bits |= (f1ap_setup_resp->rrc_ver[i] != 0) << i;
BIT_STRING_t *bs = &ie4->value.choice.RRC_Version.latest_RRC_Version;
bs->buf = calloc(1, sizeof(char));
AssertFatal(bs->buf != NULL, "out of memory\n");
bs->buf[0] = bits;
bs->size = 1;
bs->bits_unused = 5;
F1AP_ProtocolExtensionContainer_10696P228_t *p = (F1AP_ProtocolExtensionContainer_10696P228_t*)calloc(1, sizeof(F1AP_ProtocolExtensionContainer_10696P228_t));
asn1cSequenceAdd(p->list, F1AP_RRC_Version_ExtIEs_t, rrcv_ext);
rrcv_ext->id = F1AP_ProtocolIE_ID_id_latest_RRC_Version_Enhanced;
rrcv_ext->criticality = F1AP_Criticality_ignore;
rrcv_ext->extensionValue.present = F1AP_RRC_Version_ExtIEs__extensionValue_PR_OCTET_STRING_SIZE_3_;
OCTET_STRING_t *os = &rrcv_ext->extensionValue.choice.OCTET_STRING_SIZE_3_;
os->size = 3;
os->buf = malloc(3 * sizeof(*os->buf));
AssertFatal(os->buf != NULL, "out of memory\n");
for (int i = 0; i < 3; ++i)
os->buf[i] = f1ap_setup_resp->rrc_ver[i];
ie4->value.choice.RRC_Version.iE_Extensions = (struct F1AP_ProtocolExtensionContainer *)p;
/* Encode F1 Setup Response */
F1AP_F1AP_PDU_t *pdu = encode_f1ap_setup_response(f1ap_setup_resp);
/* Free after encode */
free_f1ap_setup_response(f1ap_setup_resp);
/* encode */
if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
if (f1ap_encode_pdu(pdu, &buffer, &len) < 0) {
LOG_E(F1AP, "Failed to encode F1 setup response\n");
ASN_STRUCT_FREE(asn_DEF_F1AP_F1AP_PDU, pdu);
return -1;
}
ASN_STRUCT_RESET(asn_DEF_F1AP_F1AP_PDU, &pdu);
ASN_STRUCT_FREE(asn_DEF_F1AP_F1AP_PDU, pdu);
f1ap_itti_send_sctp_data_req(assoc_id, buffer, len);
return 0;
}
......
......@@ -325,177 +325,13 @@ int DU_send_F1_SETUP_REQUEST(sctp_assoc_t assoc_id, const f1ap_setup_req_t *setu
int DU_handle_F1_SETUP_RESPONSE(instance_t instance, sctp_assoc_t assoc_id, uint32_t stream, F1AP_F1AP_PDU_t *pdu)
{
LOG_D(F1AP, "DU_handle_F1_SETUP_RESPONSE\n");
AssertFatal(pdu->present == F1AP_F1AP_PDU_PR_successfulOutcome,
"pdu->present != F1AP_F1AP_PDU_PR_successfulOutcome\n");
AssertFatal(pdu->choice.successfulOutcome->procedureCode == F1AP_ProcedureCode_id_F1Setup,
"pdu->choice.successfulOutcome->procedureCode != F1AP_ProcedureCode_id_F1Setup\n");
AssertFatal(pdu->choice.successfulOutcome->criticality == F1AP_Criticality_reject,
"pdu->choice.successfulOutcome->criticality != F1AP_Criticality_reject\n");
AssertFatal(pdu->choice.successfulOutcome->value.present == F1AP_SuccessfulOutcome__value_PR_F1SetupResponse,
"pdu->choice.successfulOutcome->value.present != F1AP_SuccessfulOutcome__value_PR_F1SetupResponse\n");
F1AP_F1SetupResponse_t *in = &pdu->choice.successfulOutcome->value.choice.F1SetupResponse;
F1AP_F1SetupResponseIEs_t *ie;
int TransactionId = -1;
int num_cells_to_activate = 0;
/* Decode */
f1ap_setup_resp_t resp = {0};
for (int i=0; i < in->protocolIEs.list.count; i++) {
ie = in->protocolIEs.list.array[i];
switch (ie->id) {
case F1AP_ProtocolIE_ID_id_TransactionID:
AssertFatal(ie->criticality == F1AP_Criticality_reject,
"ie->criticality != F1AP_Criticality_reject\n");
AssertFatal(ie->value.present == F1AP_F1SetupResponseIEs__value_PR_TransactionID,
"ie->value.present != F1AP_F1SetupResponseIEs__value_PR_TransactionID\n");
TransactionId=ie->value.choice.TransactionID;
LOG_D(F1AP, "F1AP: F1Setup-Resp: TransactionId %d\n",
TransactionId);
break;
case F1AP_ProtocolIE_ID_id_gNB_CU_Name:
AssertFatal(ie->criticality == F1AP_Criticality_ignore,
"ie->criticality != F1AP_Criticality_ignore\n");
AssertFatal(ie->value.present == F1AP_F1SetupResponseIEs__value_PR_GNB_CU_Name,
"ie->value.present != F1AP_F1SetupResponseIEs__value_PR_GNB_CU_Name\n");
resp.gNB_CU_name = malloc(ie->value.choice.GNB_CU_Name.size+1);
memcpy(resp.gNB_CU_name, ie->value.choice.GNB_CU_Name.buf, ie->value.choice.GNB_CU_Name.size);
resp.gNB_CU_name[ie->value.choice.GNB_CU_Name.size] = '\0';
LOG_D(F1AP, "F1AP: F1Setup-Resp: gNB_CU_name %s\n", resp.gNB_CU_name);
break;
case F1AP_ProtocolIE_ID_id_GNB_CU_RRC_Version:
AssertFatal(ie->criticality == F1AP_Criticality_reject,
"ie->criticality != F1AP_Criticality_reject\n");
AssertFatal(ie->value.present == F1AP_F1SetupResponseIEs__value_PR_RRC_Version,
"ie->value.present != F1AP_F1SetupResponseIEs__value_PR_RRC_Version\n");
// RRC Version: "This IE is not used in this release."
if(ie->value.choice.RRC_Version.iE_Extensions) {
F1AP_ProtocolExtensionContainer_10696P228_t *ext =
(F1AP_ProtocolExtensionContainer_10696P228_t *)ie->value.choice.RRC_Version.iE_Extensions;
if(ext->list.count > 0){
F1AP_RRC_Version_ExtIEs_t *rrcext = ext->list.array[0];
OCTET_STRING_t *os = &rrcext->extensionValue.choice.OCTET_STRING_SIZE_3_;
for (int i = 0; i < 3; i++)
resp.rrc_ver[i] = os->buf[i];
}
}
break;
case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List: {
AssertFatal(ie->criticality == F1AP_Criticality_reject,
"ie->criticality != F1AP_Criticality_reject\n");
AssertFatal(ie->value.present == F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List,
"ie->value.present != F1AP_F1SetupResponseIEs__value_PR_Cells_to_be_Activated_List\n");
num_cells_to_activate = ie->value.choice.Cells_to_be_Activated_List.list.count;
LOG_D(F1AP, "F1AP: Activating %d cells\n",num_cells_to_activate);
for (int i=0; i<num_cells_to_activate; i++) {
F1AP_Cells_to_be_Activated_List_ItemIEs_t *cells_to_be_activated_list_item_ies = (F1AP_Cells_to_be_Activated_List_ItemIEs_t *) ie->value.choice.Cells_to_be_Activated_List.list.array[i];
AssertFatal(cells_to_be_activated_list_item_ies->id == F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item,
"cells_to_be_activated_list_item_ies->id != F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List_Item");
AssertFatal(cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject,
"cells_to_be_activated_list_item_ies->criticality == F1AP_Criticality_reject");
AssertFatal(cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item,
"cells_to_be_activated_list_item_ies->value.present == F1AP_Cells_to_be_Activated_List_ItemIEs__value_PR_Cells_to_be_Activated_List_Item");
F1AP_Cells_to_be_Activated_List_Item_t *cell =
&cells_to_be_activated_list_item_ies->value.choice.Cells_to_be_Activated_List_Item;
TBCD_TO_MCC_MNC(&cell->nRCGI.pLMN_Identity,
resp.cells_to_activate[i].plmn.mcc,
resp.cells_to_activate[i].plmn.mnc,
resp.cells_to_activate[i].plmn.mnc_digit_length);
LOG_D(F1AP, "nr_cellId : %x %x %x %x %x\n",
cell->nRCGI.nRCellIdentity.buf[0],
cell->nRCGI.nRCellIdentity.buf[1],
cell->nRCGI.nRCellIdentity.buf[2],
cell->nRCGI.nRCellIdentity.buf[3],
cell->nRCGI.nRCellIdentity.buf[4]);
BIT_STRING_TO_NR_CELL_IDENTITY(&cell->nRCGI.nRCellIdentity, resp.cells_to_activate[i].nr_cellid);
if (cell->nRPCI != NULL)
resp.cells_to_activate[i].nrpci = *cell->nRPCI;
F1AP_ProtocolExtensionContainer_10696P112_t *ext = (F1AP_ProtocolExtensionContainer_10696P112_t *)cell->iE_Extensions;
if (ext==NULL)
continue;
for (int cnt=0; cnt<ext->list.count; cnt++) {
F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *cells_to_be_activated_list_itemExtIEs=(F1AP_Cells_to_be_Activated_List_ItemExtIEs_t *)ext->list.array[cnt];
switch (cells_to_be_activated_list_itemExtIEs->id) {
/*
case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_NOTHING:
case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_GNB_CUSystemInformation,
case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailablePLMNList,
case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_ExtendedAvailablePLMN_List,
case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_IAB_Info_IAB_donor_CU,
case F1AP_Cells_to_be_Activated_List_ItemExtIEs__extensionValue_PR_AvailableSNPN_ID_List
*/
case F1AP_ProtocolIE_ID_id_gNB_CUSystemInformation: {
resp.cells_to_activate[i].nrpci = (cell->nRPCI != NULL) ? *cell->nRPCI : 0;
F1AP_GNB_CUSystemInformation_t *gNB_CUSystemInformation = (F1AP_GNB_CUSystemInformation_t *)&cells_to_be_activated_list_itemExtIEs->extensionValue.choice.GNB_CUSystemInformation;
resp.cells_to_activate[i].num_SI = gNB_CUSystemInformation->sibtypetobeupdatedlist.list.count;
AssertFatal(ext->list.count==1,"At least one SI message should be there, and only 1 for now!\n");
LOG_D(F1AP,
"F1AP: Cell %d MCC %d MNC %d NRCellid %lx num_si %d\n",
i,
resp.cells_to_activate[i].plmn.mcc,
resp.cells_to_activate[i].plmn.mnc,
resp.cells_to_activate[i].nr_cellid,
resp.cells_to_activate[i].num_SI);
for (int s = 0; s < resp.cells_to_activate[i].num_SI; s++) {
F1AP_SibtypetobeupdatedListItem_t *sib_item = gNB_CUSystemInformation->sibtypetobeupdatedlist.list.array[s];
f1ap_sib_msg_t *SI_msg = &resp.cells_to_activate[i].SI_msg[s];
SI_msg->SI_container = calloc(sib_item->sIBmessage.size, sizeof(uint8_t));
AssertFatal(SI_msg->SI_container != NULL, "out of memory\n");
memcpy(SI_msg->SI_container, sib_item->sIBmessage.buf, sib_item->sIBmessage.size);
SI_msg->SI_container_length = sib_item->sIBmessage.size;
SI_msg->SI_type = sib_item->sIBtype;
LOG_D(F1AP, "F1AP: SI_container_length[%d][%ld] %ld bytes\n", i, sib_item->sIBtype, sib_item->sIBmessage.size);
}
break;
}
case F1AP_ProtocolIE_ID_id_AvailablePLMNList:
AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
break;
case F1AP_ProtocolIE_ID_id_ExtendedAvailablePLMN_List:
AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
break;
case F1AP_ProtocolIE_ID_id_IAB_Info_IAB_donor_CU:
AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
break;
case F1AP_ProtocolIE_ID_id_AvailableSNPN_ID_List:
AssertFatal(1==0,"F1AP_ProtocolIE_ID_id_AvailablePLMNList not supported yet\n");
break;
default:
AssertFatal(1==0,"F1AP_ProtocolIE_ID_id %d unknown\n",(int)cells_to_be_activated_list_itemExtIEs->id);
break;
}
} // for (cnt=...
} // for (cells_to_activate...
break;
} // case F1AP_ProtocolIE_ID_id_Cells_to_be_Activated_List
default:
AssertFatal(1==0,"F1AP_ProtocolIE_ID_id %d unknown\n", (int)ie->id);
break;
} // switch ie
} // for IE
AssertFatal(TransactionId!=-1,"TransactionId was not sent\n");
LOG_D(F1AP,"F1AP: num_cells_to_activate %d\n",num_cells_to_activate);
resp.num_cells_to_activate = num_cells_to_activate;
// tmp
for (int i=0; i<num_cells_to_activate; i++)
AssertFatal(resp.cells_to_activate[i].num_SI == 0, "System Information handling not implemented");
if (!decode_f1ap_setup_response(pdu, &resp)) {
LOG_E(F1AP, "cannot decode F1AP Setup Response\n");
free_f1ap_setup_response(&resp);
return -1;
}
LOG_D(F1AP, "Sending F1AP_SETUP_RESP ITTI message\n");
f1_setup_response(&resp);
return 0;
......
......@@ -28,6 +28,7 @@
#include "F1AP_CauseRadioNetwork.h"
#include "openair3/ocp-gtpu/gtp_itf.h"
#include "openair2/LAYER2/nr_pdcp/nr_pdcp_oai_api.h"
#include "lib/f1ap_interface_management.h"
#include "executables/softmodem-common.h"
......@@ -169,10 +170,10 @@ void f1_setup_response(const f1ap_setup_resp_t *resp)
mac->f1_config.setup_resp = malloc(sizeof(*mac->f1_config.setup_resp));
AssertFatal(mac->f1_config.setup_resp != NULL, "out of memory\n");
*mac->f1_config.setup_resp = *resp;
if (resp->gNB_CU_name)
mac->f1_config.setup_resp->gNB_CU_name = strdup(resp->gNB_CU_name);
// Copy F1AP message
*mac->f1_config.setup_resp = cp_f1ap_setup_response(resp);
// free F1AP message after copy
free_f1ap_setup_response(resp);
NR_SCHED_UNLOCK(&mac->sched_lock);
// NOTE: Before accepting any UEs, we should initialize the UE states.
......
......@@ -24,6 +24,7 @@
#include "mac_rrc_dl.h"
#include "nr_rrc_defs.h"
#include "openair2/F1AP/lib/f1ap_rrc_message_transfer.h"
#include "openair2/F1AP/lib/f1ap_interface_management.h"
static void f1_reset_cu_initiated_f1ap(sctp_assoc_t assoc_id, const f1ap_reset_t *reset)
{
......@@ -45,6 +46,7 @@ static void f1_setup_response_f1ap(sctp_assoc_t assoc_id, const f1ap_setup_resp_
*f1ap_msg = *resp;
if (resp->gNB_CU_name != NULL)
f1ap_msg->gNB_CU_name = strdup(resp->gNB_CU_name);
free_f1ap_setup_response(resp);
itti_send_msg_to_task(TASK_CU_F1, 0, msg);
}
......
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