f1ap_cu_rrc_message_transfer.c 13 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/*
 * 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 f1ap_cu_rrc_message_transfer.c
 * \brief f1ap rrc message transfer for CU
 * \author EURECOM/NTUST
 * \date 2018
 * \version 0.1
 * \company Eurecom
 * \email: navid.nikaein@eurecom.fr, bing-kai.hong@eurecom.fr
 * \note
 * \warning
 */

#include "f1ap_common.h"
34 35
#include "f1ap_encoder.h"
#include "f1ap_itti_messaging.h"
36
#include "f1ap_cu_rrc_message_transfer.h"
37 38
#include "common/ran_context.h"
#include "openair3/UTILS/conversions.h"
39
#include "LAYER2/nr_pdcp/nr_pdcp_oai_api.h"
40

41 42 43 44
/*
    Initial UL RRC Message Transfer
*/

45
int CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t             instance,
46 47 48
    uint32_t               assoc_id,
    uint32_t               stream,
    F1AP_F1AP_PDU_t       *pdu) {
49
  LOG_D(F1AP, "CU_handle_INITIAL_UL_RRC_MESSAGE_TRANSFER\n");
50
  // decode the F1 message
51
  // get the rrc message from the contauiner
52
  // call func rrc_eNB_decode_ccch: <-- needs some update here
53 54 55 56
  MessageDef                            *message_p;
  F1AP_InitialULRRCMessageTransfer_t    *container;
  F1AP_InitialULRRCMessageTransferIEs_t *ie;
  DevAssert(pdu != NULL);
57

58
  if (stream != 0) {
59 60
    LOG_E(F1AP, "[SCTP %d] Received F1 on stream != 0 (%d)\n",
          assoc_id, stream);
61 62
    return -1;
  }
63

64 65 66 67
  container = &pdu->choice.initiatingMessage->value.choice.InitialULRRCMessageTransfer;
  /* GNB_DU_UE_F1AP_ID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
68 69
  uint32_t du_ue_id = ie->value.choice.GNB_DU_UE_F1AP_ID;

70
  /* NRCGI
71
  * Fixme: process NRCGI
72
  */
73 74
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_NRCGI, true);
75 76
  uint64_t nr_cellid;
  BIT_STRING_TO_NR_CELL_IDENTITY(&ie->value.choice.NRCGI.nRCellIdentity,nr_cellid);
77 78 79
  /* RNTI */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_C_RNTI, true);
80
  rnti_t rnti = ie->value.choice.C_RNTI;
81 82
  F1AP_InitialULRRCMessageTransferIEs_t *rrccont;
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, rrccont, container,
83
                             F1AP_ProtocolIE_ID_id_RRCContainer, true);
84
  AssertFatal(rrccont!=NULL,"RRCContainer is missing\n");
85

86 87
  F1AP_InitialULRRCMessageTransferIEs_t *du2cu;
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_InitialULRRCMessageTransferIEs_t, du2cu, container,
Laurent THOMAS's avatar
Laurent THOMAS committed
88
                             F1AP_ProtocolIE_ID_id_DUtoCURRCContainer, false);
89

Laurent THOMAS's avatar
Laurent THOMAS committed
90
  int f1ap_uid = f1ap_add_ue(CUtype, instance, rnti);
91

92
  if (f1ap_uid  < 0 ) {
93
    LOG_E(F1AP, "Failed to add UE \n");
94 95
    return -1;
  }
96

97
  // create an ITTI message and copy SDU
98 99 100 101 102 103 104 105 106 107 108 109 110 111
  AssertFatal(f1ap_req(true, instance)->cell_type == CELL_MACRO_GNB, "illegal cell type %d\n", f1ap_req(true, instance)->cell_type);
  message_p = itti_alloc_new_message(TASK_CU_F1, 0, F1AP_INITIAL_UL_RRC_MESSAGE);
  f1ap_initial_ul_rrc_message_t *ul_rrc = &F1AP_INITIAL_UL_RRC_MESSAGE(message_p);
  ul_rrc->gNB_DU_ue_id = du_ue_id;
  ul_rrc->nr_cellid = nr_cellid; // CU instance
  ul_rrc->crnti = rnti;
  ul_rrc->rrc_container_length = rrccont->value.choice.RRCContainer.size;
  ul_rrc->rrc_container = malloc(ul_rrc->rrc_container_length);
  memcpy(ul_rrc->rrc_container, rrccont->value.choice.RRCContainer.buf, ul_rrc->rrc_container_length);
  AssertFatal(du2cu != NULL, "no masterCellGroup in initial UL RRC message\n");
  ul_rrc->du2cu_rrc_container_length = du2cu->value.choice.DUtoCURRCContainer.size;
  ul_rrc->du2cu_rrc_container = malloc(ul_rrc->du2cu_rrc_container_length);
  memcpy(ul_rrc->du2cu_rrc_container, du2cu->value.choice.DUtoCURRCContainer.buf, ul_rrc->du2cu_rrc_container_length);
  itti_send_msg_to_task(TASK_RRC_GNB, instance, message_p);
112

113
  return 0;
114 115 116 117 118 119
}

/*
    DL RRC Message Transfer.
*/
//void CU_send_DL_RRC_MESSAGE_TRANSFER(F1AP_DLRRCMessageTransfer_t *DLRRCMessageTransfer) {
120
int CU_send_DL_RRC_MESSAGE_TRANSFER(instance_t                instance,
121
                                    f1ap_dl_rrc_message_t    *f1ap_dl_rrc) {
Xue Song's avatar
Xue Song committed
122
  LOG_D(F1AP, "CU send DL_RRC_MESSAGE_TRANSFER \n");
123
  F1AP_F1AP_PDU_t                 pdu= {0};
124
  F1AP_DLRRCMessageTransfer_t    *out;
125 126
  uint8_t  *buffer=NULL;
  uint32_t  len=0;
127
  /* Create */
128
  /* 0. Message Type */
129
  pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
Laurent THOMAS's avatar
Laurent THOMAS committed
130
  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
131 132 133 134
  tmp->procedureCode = F1AP_ProcedureCode_id_DLRRCMessageTransfer;
  tmp->criticality   = F1AP_Criticality_ignore;
  tmp->value.present = F1AP_InitiatingMessage__value_PR_DLRRCMessageTransfer;
  out = &tmp->value.choice.DLRRCMessageTransfer;
135 136
  /* mandatory */
  /* c1. GNB_CU_UE_F1AP_ID */
137 138 139 140
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie1);
  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
  ie1->criticality                    = F1AP_Criticality_reject;
  ie1->value.present                  = F1AP_DLRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
Laurent THOMAS's avatar
Laurent THOMAS committed
141
  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(CUtype, instance, f1ap_dl_rrc->rnti);
142
  LOG_D(F1AP, "Setting GNB_CU_UE_F1AP_ID %llu associated with UE RNTI %x (instance %ld)\n",
143
        (unsigned long long int)ie1->value.choice.GNB_CU_UE_F1AP_ID, f1ap_dl_rrc->rnti, instance);
144 145
  /* mandatory */
  /* c2. GNB_DU_UE_F1AP_ID */
146 147 148 149
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie2);
  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
  ie2->criticality                    = F1AP_Criticality_reject;
  ie2->value.present                  = F1AP_DLRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
Laurent THOMAS's avatar
Laurent THOMAS committed
150
  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(CUtype, instance, f1ap_dl_rrc->rnti);
151
  LOG_D(F1AP, "GNB_DU_UE_F1AP_ID %llu associated with UE RNTI %x \n", (unsigned long long int)ie2->value.choice.GNB_DU_UE_F1AP_ID, f1ap_dl_rrc->rnti);
152 153
  /* optional */
  /* c3. oldgNB_DU_UE_F1AP_ID */
154 155 156 157 158 159 160
  /* if (f1ap_dl_rrc->old_gNB_DU_ue_id != 0xFFFFFFFF) {
     asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie3);
     ie3->id                                = F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID;
     ie3->criticality                       = F1AP_Criticality_reject;
     ie3->value.present                     = F1AP_DLRRCMessageTransferIEs__value_PR_NOTHING;
     ie3->value.choice.oldgNB_DU_UE_F1AP_ID = f1ap_dl_rrc->old_gNB_DU_ue_id;
   }*/
161 162
  /* mandatory */
  /* c4. SRBID */
163 164 165 166 167
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie4);
  ie4->id                            = F1AP_ProtocolIE_ID_id_SRBID;
  ie4->criticality                   = F1AP_Criticality_reject;
  ie4->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_SRBID;
  ie4->value.choice.SRBID            = f1ap_dl_rrc->srb_id;
168 169 170

  /* optional */
  /* c5. ExecuteDuplication */
171
  if (f1ap_dl_rrc->execute_duplication) {
172 173 174 175 176
    asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie5);
    ie5->id                            = F1AP_ProtocolIE_ID_id_ExecuteDuplication;
    ie5->criticality                   = F1AP_Criticality_ignore;
    ie5->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_ExecuteDuplication;
    ie5->value.choice.ExecuteDuplication = F1AP_ExecuteDuplication_true;
177 178 179 180 181
  }

  // issue in here
  /* mandatory */
  /* c6. RRCContainer */
182 183 184 185 186
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie6);
  ie6->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
  ie6->criticality                   = F1AP_Criticality_reject;
  ie6->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_RRCContainer;
  OCTET_STRING_fromBuf(&ie6->value.choice.RRCContainer,
187
                       (const char *)f1ap_dl_rrc->rrc_container, f1ap_dl_rrc->rrc_container_length);
188

189 190
  /* optional */
  /* c7. RAT_FrequencyPriorityInformation */
191
  /* TODO */
192
  if (0) {
Xue Song's avatar
Xue Song committed
193
    int endc=1;
194 195 196 197 198
    asn1cSequenceAdd(out->protocolIEs.list, F1AP_DLRRCMessageTransferIEs_t, ie7);
    ie7->id                            = F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation;
    ie7->criticality                   = F1AP_Criticality_reject;
    ie7->value.present                 = F1AP_DLRRCMessageTransferIEs__value_PR_RAT_FrequencyPriorityInformation;

Xue Song's avatar
Xue Song committed
199
    if (endc==1) {
200 201 202 203 204
      ie7->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_eNDC;
      ie7->value.choice.RAT_FrequencyPriorityInformation.choice.eNDC = 123L;
    } else {
      ie7->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN;
      ie7->value.choice.RAT_FrequencyPriorityInformation.choice.nGRAN = 11L;
Xue Song's avatar
Xue Song committed
205
    }
206 207 208

    //ie->value.choice.RAT_FrequencyPriorityInformation.present = F1AP_RAT_FrequencyPriorityInformation_PR_rAT_FrequencySelectionPriority;
    //ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority = 123L;
209
  }
Xue Song's avatar
Xue Song committed
210

211 212
  /* encode */
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
Xue Song's avatar
Xue Song committed
213
    LOG_E(F1AP, "Failed to encode F1 DL RRC MESSAGE TRANSFER \n");
214
    return -1;
215 216
  }

217
  f1ap_itti_send_sctp_data_req(true, instance, buffer, len, 0 /* BK: fix me*/);
218
  return 0;
219 220 221 222 223
}

/*
    UL RRC Message Transfer
*/
224 225 226 227
int CU_handle_UL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                      uint32_t         assoc_id,
                                      uint32_t         stream,
                                      F1AP_F1AP_PDU_t *pdu) {
228
  LOG_D(F1AP, "CU_handle_UL_RRC_MESSAGE_TRANSFER \n");
229 230 231 232 233 234
  F1AP_ULRRCMessageTransfer_t    *container;
  F1AP_ULRRCMessageTransferIEs_t *ie;
  uint64_t        cu_ue_f1ap_id;
  uint64_t        du_ue_f1ap_id;
  uint64_t        srb_id;
  DevAssert(pdu != NULL);
235

236 237
  if (stream != 0) {
    LOG_E(F1AP, "[SCTP %d] Received F1 on stream != 0 (%d)\n",
238
          assoc_id, stream);
239 240 241 242 243 244 245 246
    return -1;
  }

  container = &pdu->choice.initiatingMessage->value.choice.ULRRCMessageTransfer;
  /* GNB_CU_UE_F1AP_ID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID, true);
  cu_ue_f1ap_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
247
  LOG_D(F1AP, "cu_ue_f1ap_id %lu associated with RNTI %x\n",
Laurent THOMAS's avatar
Laurent THOMAS committed
248
        cu_ue_f1ap_id, f1ap_get_rnti_by_cu_id(CUtype, instance, cu_ue_f1ap_id));
249 250 251 252
  /* GNB_DU_UE_F1AP_ID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID, true);
  du_ue_f1ap_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
253
  LOG_D(F1AP, "du_ue_f1ap_id %lu associated with RNTI %x\n",
Laurent THOMAS's avatar
Laurent THOMAS committed
254
        du_ue_f1ap_id, f1ap_get_rnti_by_cu_id(CUtype, instance, du_ue_f1ap_id));
255 256 257 258 259
  /* mandatory */
  /* SRBID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_SRBID, true);
  srb_id = ie->value.choice.SRBID;
260 261

  if (srb_id < 1 )
262
    LOG_E(F1AP, "Unexpected UL RRC MESSAGE for srb_id %lu \n", srb_id);
263
  else
264
    LOG_D(F1AP, "UL RRC MESSAGE for srb_id %lu in DCCH \n", srb_id);
265 266 267 268 269 270

  // issue in here
  /* mandatory */
  /* RRC Container */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_ULRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_RRCContainer, true);
271
  protocol_ctxt_t ctxt={0};
272
  ctxt.instance = instance;
273
  ctxt.module_id = instance;
274
  ctxt.rntiMaybeUEid = f1ap_get_rnti_by_cu_id(CUtype, instance, cu_ue_f1ap_id);
275
  ctxt.enb_flag = 1;
Xue Song's avatar
Xue Song committed
276
  ctxt.eNB_index = 0;
277
  mem_block_t *mb = get_free_mem_block(ie->value.choice.RRCContainer.size,__func__);
278
  memcpy((void *)mb->data,(void *)ie->value.choice.RRCContainer.buf,ie->value.choice.RRCContainer.size);
279
  LOG_D(F1AP, "Calling pdcp_data_ind for UE RNTI %lx srb_id %lu with size %ld (DCCH) \n", ctxt.rntiMaybeUEid, srb_id, ie->value.choice.RRCContainer.size);
280 281 282
  //for (int i = 0; i < ie->value.choice.RRCContainer.size; i++)
  //  printf("%02x ", mb->data[i]);
  //printf("\n");
283
  pdcp_data_ind (&ctxt,
284 285 286 287
                 1, // srb_flag
                 0, // embms_flag
                 srb_id,
                 ie->value.choice.RRCContainer.size,
288
                 mb, NULL, NULL);
289
  return 0;
290
}