f1ap_du_rrc_message_transfer.c 13.2 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_du_rrc_message_transfer.c
 * \brief f1ap rrc message transfer for DU
 * \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_decoder.h"
36
#include "f1ap_itti_messaging.h"
37

38
#include "f1ap_du_rrc_message_transfer.h"
39

40 41 42 43
#include "NR_DL-CCCH-Message.h"
#include "NR_UL-CCCH-Message.h"
#include "NR_DL-DCCH-Message.h"
#include "NR_UL-DCCH-Message.h"
44 45 46 47
// for SRB1_logicalChannelConfig_defaultValue
#include "rrc_extern.h"
#include "common/ran_context.h"

48
#include "openair2/RRC/NR/rrc_gNB_UE_context.h"
49
#include "asn1_msg.h"
50
#include "intertask_interface.h"
51
#include "LAYER2/NR_MAC_gNB/mac_proto.h"
52

53
#include "openair2/LAYER2/NR_MAC_gNB/mac_rrc_dl_handler.h"
54

55
/*  DL RRC Message Transfer */
56 57 58 59
int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                      uint32_t         assoc_id,
                                      uint32_t         stream,
                                      F1AP_F1AP_PDU_t *pdu) {
60 61 62 63 64
  F1AP_DLRRCMessageTransfer_t    *container;
  F1AP_DLRRCMessageTransferIEs_t *ie;
  uint64_t        cu_ue_f1ap_id;
  uint64_t        du_ue_f1ap_id;
  int             executeDuplication;
65 66
  //uint64_t        subscriberProfileIDforRFP;
  //uint64_t        rAT_FrequencySelectionPriority;
67 68 69 70 71 72
  DevAssert(pdu != NULL);
  container = &pdu->choice.initiatingMessage->value.choice.DLRRCMessageTransfer;
  /* GNB_CU_UE_F1AP_ID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_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;
73
  LOG_D(F1AP, "cu_ue_f1ap_id %lu \n", cu_ue_f1ap_id);
74 75 76 77
  /* GNB_DU_UE_F1AP_ID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_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;
78 79
  LOG_D(F1AP, "du_ue_f1ap_id %lu associated with UE RNTI %x \n",
        du_ue_f1ap_id,
Robert Schmidt's avatar
Robert Schmidt committed
80
        f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id)); // this should be the one transmitted via initial ul rrc message transfer
81

Laurent THOMAS's avatar
Laurent THOMAS committed
82
  if (f1ap_du_add_cu_ue_id(instance,du_ue_f1ap_id, cu_ue_f1ap_id) < 0 ) {
83
    LOG_E(F1AP, "Failed to find the F1AP UID \n");
84 85
    //return -1;
  }
86

87 88 89 90
  /* optional */
  /* oldgNB_DU_UE_F1AP_ID */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
91
                               F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID, true);
92 93 94 95 96 97
  }

  /* mandatory */
  /* SRBID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_SRBID, true);
98
  uint64_t  srb_id = ie->value.choice.SRBID;
99
  LOG_D(F1AP, "srb_id %lu \n", srb_id);
100 101 102 103 104

  /* optional */
  /* ExecuteDuplication */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
105
                               F1AP_ProtocolIE_ID_id_ExecuteDuplication, true);
106
    executeDuplication = ie->value.choice.ExecuteDuplication;
107
    LOG_D(F1AP, "ExecuteDuplication %d \n", executeDuplication);
108 109 110 111 112 113 114 115 116 117 118
  }

  // issue in here
  /* mandatory */
  /* RRC Container */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_RRCContainer, true);
  /* optional */
  /* RAT_FrequencyPriorityInformation */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
119
                               F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation, true);
120 121

    switch(ie->value.choice.RAT_FrequencyPriorityInformation.present) {
Xue Song's avatar
Xue Song committed
122
      case F1AP_RAT_FrequencyPriorityInformation_PR_eNDC:
123
        //subscriberProfileIDforRFP = ie->value.choice.RAT_FrequencyPriorityInformation.choice.subscriberProfileIDforRFP;
124
        break;
125

Xue Song's avatar
Xue Song committed
126
      case F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN:
127
        //rAT_FrequencySelectionPriority = ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority;
128
        break;
129

130
      default:
131
        LOG_W(F1AP, "unhandled IE RAT_FrequencyPriorityInformation.present\n");
132
        break;
133 134 135
    }
  }

Robert Schmidt's avatar
Robert Schmidt committed
136 137 138 139 140 141 142 143 144 145
  f1ap_dl_rrc_message_t dl_rrc = {
    .rrc_container_length = ie->value.choice.RRCContainer.size,
    .rrc_container = ie->value.choice.RRCContainer.buf,
    .rnti = f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id),
    .srb_id = srb_id
  };
  int rc = dl_rrc_message(instance, &dl_rrc);
  if (rc == 0)
    return 0; /* has been handled, otherwise continue below */

146 147
  // decode RRC Container and act on the message type
  AssertFatal(srb_id<3,"illegal srb_id\n");
Robert Schmidt's avatar
Robert Schmidt committed
148 149 150 151 152 153 154
  MessageDef *msg = itti_alloc_new_message(TASK_DU_F1, 0, NR_DU_RRC_DL_INDICATION);
  NRDuDlReq_t *req=&NRDuDlReq(msg);
  req->rnti=f1ap_get_rnti_by_du_id(DUtype, instance, du_ue_f1ap_id);
  req->srb_id=srb_id;
  req->buf= get_free_mem_block( ie->value.choice.RRCContainer.size, __func__);
  memcpy(req->buf->data, ie->value.choice.RRCContainer.buf, ie->value.choice.RRCContainer.size);
  itti_send_msg_to_task(TASK_RRC_GNB, instance, msg);
155
  return 0;
156 157 158
}

/*  UL RRC Message Transfer */
159
int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t     instanceP,
160 161 162 163 164
    int             CC_idP,
    int             UE_id,
    rnti_t          rntiP,
    const uint8_t   *sduP,
    sdu_size_t      sdu_lenP,
165
    const uint8_t   *sdu2P,
166 167
    sdu_size_t      sdu2_lenP) {
  F1AP_F1AP_PDU_t                       pdu= {0};
168
  F1AP_InitialULRRCMessageTransfer_t    *out;
169 170
  uint8_t  *buffer=NULL;
  uint32_t  len=0;
Laurent THOMAS's avatar
Laurent THOMAS committed
171
  int f1ap_uid = f1ap_add_ue (DUtype, instanceP, rntiP);
172 173

  if (f1ap_uid  < 0 ) {
174
    LOG_E(F1AP, "Failed to add UE \n");
175 176
    return -1;
  }
Laurent Thomas's avatar
Laurent Thomas committed
177

178 179 180
  /* Create */
  /* 0. Message Type */
  pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
Laurent THOMAS's avatar
Laurent THOMAS committed
181
  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
182 183 184 185
  tmp->procedureCode = F1AP_ProcedureCode_id_InitialULRRCMessageTransfer;
  tmp->criticality   = F1AP_Criticality_ignore;
  tmp->value.present = F1AP_InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
  out = &tmp->value.choice.InitialULRRCMessageTransfer;
186 187
  /* mandatory */
  /* c1. GNB_DU_UE_F1AP_ID */
188 189 190 191
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie1);
  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
  ie1->criticality                    = F1AP_Criticality_reject;
  ie1->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
Laurent THOMAS's avatar
Laurent THOMAS committed
192
  ie1->value.choice.GNB_DU_UE_F1AP_ID = getCxt(DUtype, instanceP)->f1ap_ue[f1ap_uid].du_ue_f1ap_id;
193 194
  /* mandatory */
  /* c2. NRCGI */
195 196 197 198
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie2);
  ie2->id                             = F1AP_ProtocolIE_ID_id_NRCGI;
  ie2->criticality                    = F1AP_Criticality_reject;
  ie2->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_NRCGI;
199
  //Fixme: takes always the first cell
Laurent THOMAS's avatar
Laurent THOMAS committed
200
  addnRCGI(ie2->value.choice.NRCGI, getCxt(DUtype, instanceP)->setupReq.cell);
201 202
  /* mandatory */
  /* c3. C_RNTI */  // 16
203 204 205 206 207
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie3);
  ie3->id                             = F1AP_ProtocolIE_ID_id_C_RNTI;
  ie3->criticality                    = F1AP_Criticality_reject;
  ie3->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_C_RNTI;
  ie3->value.choice.C_RNTI=rntiP;
208 209
  /* mandatory */
  /* c4. RRCContainer */
210 211 212 213 214
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie4);
  ie4->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
  ie4->criticality                   = F1AP_Criticality_reject;
  ie4->value.present                 = F1AP_InitialULRRCMessageTransferIEs__value_PR_RRCContainer;
  OCTET_STRING_fromBuf(&ie4->value.choice.RRCContainer, (const char *)sduP, sdu_lenP);
215 216 217

  /* optional */
  /* c5. DUtoCURRCContainer */
218
  if (sdu2P) {
219 220 221 222 223
    asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie5);
    ie5->id                             = F1AP_ProtocolIE_ID_id_DUtoCURRCContainer;
    ie5->criticality                    = F1AP_Criticality_reject;
    ie5->value.present                  = F1AP_InitialULRRCMessageTransferIEs__value_PR_DUtoCURRCContainer;
    OCTET_STRING_fromBuf(&ie5->value.choice.DUtoCURRCContainer,
224
                         (const char *)sdu2P,
225 226
                         sdu2_lenP);
  }
227 228 229 230 231
  /* mandatory */
  /* c6. Transaction ID (integer value) */
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_InitialULRRCMessageTransferIEs_t, ie6);
  ie6->id                        = F1AP_ProtocolIE_ID_id_TransactionID;
  ie6->criticality               = F1AP_Criticality_ignore;
232
  ie6->value.present             = F1AP_InitialULRRCMessageTransferIEs__value_PR_TransactionID;
233
  ie6->value.choice.TransactionID = F1AP_get_next_transaction_identifier(f1ap_req(false, instanceP)->gNB_DU_id, f1ap_req(false, instanceP)->gNB_DU_id);
234 235

  /* encode */
236
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
Xue Song's avatar
Xue Song committed
237
    LOG_E(F1AP, "Failed to encode F1 INITIAL UL RRC MESSAGE TRANSFER\n");
238
    return -1;
239 240
  }

Laurent THOMAS's avatar
Laurent THOMAS committed
241
  f1ap_itti_send_sctp_data_req(false, instanceP, buffer, len, getCxt(DUtype, instanceP)->default_sctp_stream_id);
242
  return 0;
243
}
244 245


246 247
int DU_send_UL_NR_RRC_MESSAGE_TRANSFER(instance_t instance,
                                       const f1ap_ul_rrc_message_t *msg) {
248
  const rnti_t rnti = msg->rnti;
249
  F1AP_F1AP_PDU_t                pdu= {0};
250 251 252
  F1AP_ULRRCMessageTransfer_t    *out;
  uint8_t *buffer = NULL;
  uint32_t len;
253
  LOG_D(F1AP, "[DU %ld] %s: size %d UE RNTI %x in SRB %d\n",
254 255 256 257 258 259 260
        instance, __func__, msg->rrc_container_length, rnti, msg->srb_id);
  //for (int i = 0;i < msg->rrc_container_length; i++)
  //  printf("%02x ", msg->rrc_container[i]);
  //printf("\n");
  /* Create */
  /* 0. Message Type */
  pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
Laurent THOMAS's avatar
Laurent THOMAS committed
261
  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
262 263 264 265
  tmp->procedureCode = F1AP_ProcedureCode_id_ULRRCMessageTransfer;
  tmp->criticality   = F1AP_Criticality_ignore;
  tmp->value.present = F1AP_InitiatingMessage__value_PR_ULRRCMessageTransfer;
  out = &tmp->value.choice.ULRRCMessageTransfer;
266 267
  /* mandatory */
  /* c1. GNB_CU_UE_F1AP_ID */
268 269 270 271
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie1);
  ie1->id                             = F1AP_ProtocolIE_ID_id_gNB_CU_UE_F1AP_ID;
  ie1->criticality                    = F1AP_Criticality_reject;
  ie1->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_CU_UE_F1AP_ID;
Laurent THOMAS's avatar
Laurent THOMAS committed
272
  ie1->value.choice.GNB_CU_UE_F1AP_ID = f1ap_get_cu_ue_f1ap_id(DUtype, instance, rnti);
273 274
  /* mandatory */
  /* c2. GNB_DU_UE_F1AP_ID */
275 276 277 278
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie2);
  ie2->id                             = F1AP_ProtocolIE_ID_id_gNB_DU_UE_F1AP_ID;
  ie2->criticality                    = F1AP_Criticality_reject;
  ie2->value.present                  = F1AP_ULRRCMessageTransferIEs__value_PR_GNB_DU_UE_F1AP_ID;
Laurent THOMAS's avatar
Laurent THOMAS committed
279
  ie2->value.choice.GNB_DU_UE_F1AP_ID = f1ap_get_du_ue_f1ap_id(DUtype, instance, rnti);
280 281
  /* mandatory */
  /* c3. SRBID */
282 283 284 285 286
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie3);
  ie3->id                            = F1AP_ProtocolIE_ID_id_SRBID;
  ie3->criticality                   = F1AP_Criticality_reject;
  ie3->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_SRBID;
  ie3->value.choice.SRBID            = msg->srb_id;
287 288 289
  // issue in here
  /* mandatory */
  /* c4. RRCContainer */
290 291 292 293 294
  asn1cSequenceAdd(out->protocolIEs.list, F1AP_ULRRCMessageTransferIEs_t, ie4);
  ie4->id                            = F1AP_ProtocolIE_ID_id_RRCContainer;
  ie4->criticality                   = F1AP_Criticality_reject;
  ie4->value.present                 = F1AP_ULRRCMessageTransferIEs__value_PR_RRCContainer;
  OCTET_STRING_fromBuf(&ie4->value.choice.RRCContainer,
295 296 297
                       (const char *) msg->rrc_container,
                       msg->rrc_container_length);

298
  /* encode */
299 300 301 302 303
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
    LOG_E(F1AP, "Failed to encode F1 UL RRC MESSAGE TRANSFER \n");
    return -1;
  }

Laurent THOMAS's avatar
Laurent THOMAS committed
304
  f1ap_itti_send_sctp_data_req(false, instance, buffer, len, getCxt(DUtype, instance)->default_sctp_stream_id);
305 306
  return 0;
}