f1ap_du_rrc_message_transfer.c 11.7 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
#include "f1ap_encoder.h"
35
#include "f1ap_itti_messaging.h"
36

37
#include "f1ap_du_rrc_message_transfer.h"
38

39 40
#include "uper_decoder.h"

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

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

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

56
/*  DL RRC Message Transfer */
57 58 59 60
int DU_handle_DL_RRC_MESSAGE_TRANSFER(instance_t       instance,
                                      uint32_t         assoc_id,
                                      uint32_t         stream,
                                      F1AP_F1AP_PDU_t *pdu) {
61 62 63
  F1AP_DLRRCMessageTransfer_t    *container;
  F1AP_DLRRCMessageTransferIEs_t *ie;
  int             executeDuplication;
64 65
  //uint64_t        subscriberProfileIDforRFP;
  //uint64_t        rAT_FrequencySelectionPriority;
66 67 68 69 70
  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);
71
  uint32_t cu_ue_f1ap_id = ie->value.choice.GNB_CU_UE_F1AP_ID;
72 73 74
  /* 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);
75
  uint32_t du_ue_f1ap_id = ie->value.choice.GNB_DU_UE_F1AP_ID;
76 77 78 79 80

  /* optional */
  /* oldgNB_DU_UE_F1AP_ID */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
81
                               F1AP_ProtocolIE_ID_id_oldgNB_DU_UE_F1AP_ID, true);
82 83 84 85 86 87
  }

  /* mandatory */
  /* SRBID */
  F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
                             F1AP_ProtocolIE_ID_id_SRBID, true);
88
  uint64_t  srb_id = ie->value.choice.SRBID;
89
  LOG_D(F1AP, "srb_id %lu \n", srb_id);
90 91 92 93 94

  /* optional */
  /* ExecuteDuplication */
  if (0) {
    F1AP_FIND_PROTOCOLIE_BY_ID(F1AP_DLRRCMessageTransferIEs_t, ie, container,
95
                               F1AP_ProtocolIE_ID_id_ExecuteDuplication, true);
96
    executeDuplication = ie->value.choice.ExecuteDuplication;
97
    LOG_D(F1AP, "ExecuteDuplication %d \n", executeDuplication);
98 99 100 101 102 103 104 105 106 107 108
  }

  // 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,
109
                               F1AP_ProtocolIE_ID_id_RAT_FrequencyPriorityInformation, true);
110 111

    switch(ie->value.choice.RAT_FrequencyPriorityInformation.present) {
Xue Song's avatar
Xue Song committed
112
      case F1AP_RAT_FrequencyPriorityInformation_PR_eNDC:
113
        //subscriberProfileIDforRFP = ie->value.choice.RAT_FrequencyPriorityInformation.choice.subscriberProfileIDforRFP;
114
        break;
115

Xue Song's avatar
Xue Song committed
116
      case F1AP_RAT_FrequencyPriorityInformation_PR_nGRAN:
117
        //rAT_FrequencySelectionPriority = ie->value.choice.RAT_FrequencyPriorityInformation.choice.rAT_FrequencySelectionPriority;
118
        break;
119

120
      default:
121
        LOG_W(F1AP, "unhandled IE RAT_FrequencyPriorityInformation.present\n");
122
        break;
123 124 125
    }
  }

Robert Schmidt's avatar
Robert Schmidt committed
126
  f1ap_dl_rrc_message_t dl_rrc = {
127 128
    .gNB_CU_ue_id = cu_ue_f1ap_id,
    .gNB_DU_ue_id = du_ue_f1ap_id,
Robert Schmidt's avatar
Robert Schmidt committed
129 130 131 132
    .rrc_container_length = ie->value.choice.RRCContainer.size,
    .rrc_container = ie->value.choice.RRCContainer.buf,
    .srb_id = srb_id
  };
133
  dl_rrc_message_transfer(&dl_rrc);
134
  return 0;
135 136 137
}

/*  UL RRC Message Transfer */
138 139
int DU_send_INITIAL_UL_RRC_MESSAGE_TRANSFER(instance_t instanceP, const f1ap_initial_ul_rrc_message_t *msg)
{
140
  F1AP_F1AP_PDU_t                       pdu= {0};
141
  F1AP_InitialULRRCMessageTransfer_t    *out;
142 143
  uint8_t  *buffer=NULL;
  uint32_t  len=0;
Laurent Thomas's avatar
Laurent Thomas committed
144

145 146 147
  /* Create */
  /* 0. Message Type */
  pdu.present = F1AP_F1AP_PDU_PR_initiatingMessage;
Laurent THOMAS's avatar
Laurent THOMAS committed
148
  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
149 150 151 152
  tmp->procedureCode = F1AP_ProcedureCode_id_InitialULRRCMessageTransfer;
  tmp->criticality   = F1AP_Criticality_ignore;
  tmp->value.present = F1AP_InitiatingMessage__value_PR_InitialULRRCMessageTransfer;
  out = &tmp->value.choice.InitialULRRCMessageTransfer;
153 154
  /* mandatory */
  /* c1. GNB_DU_UE_F1AP_ID */
155 156 157 158
  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;
159
  ie1->value.choice.GNB_DU_UE_F1AP_ID = msg->gNB_DU_ue_id;
160 161
  /* mandatory */
  /* c2. NRCGI */
162 163 164 165
  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;
166
  //Fixme: takes always the first cell
Laurent THOMAS's avatar
Laurent THOMAS committed
167
  addnRCGI(ie2->value.choice.NRCGI, getCxt(DUtype, instanceP)->setupReq.cell);
168 169
  /* mandatory */
  /* c3. C_RNTI */  // 16
170 171 172 173
  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;
174
  ie3->value.choice.C_RNTI = msg->crnti;
175 176
  /* mandatory */
  /* c4. RRCContainer */
177 178 179 180
  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;
181
  OCTET_STRING_fromBuf(&ie4->value.choice.RRCContainer, (const char *)msg->rrc_container, msg->rrc_container_length);
182 183 184

  /* optional */
  /* c5. DUtoCURRCContainer */
185
  if (msg->du2cu_rrc_container != NULL) {
186 187 188 189 190
    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,
191 192
                         (const char *)msg->du2cu_rrc_container,
                         msg->du2cu_rrc_container_length);
193
  }
194 195 196 197 198
  /* 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;
199
  ie6->value.present             = F1AP_InitialULRRCMessageTransferIEs__value_PR_TransactionID;
200
  ie6->value.choice.TransactionID = F1AP_get_next_transaction_identifier(0, 0);
201 202

  /* encode */
203
  if (f1ap_encode_pdu(&pdu, &buffer, &len) < 0) {
Xue Song's avatar
Xue Song committed
204
    LOG_E(F1AP, "Failed to encode F1 INITIAL UL RRC MESSAGE TRANSFER\n");
205
    return -1;
206 207
  }

Laurent THOMAS's avatar
Laurent THOMAS committed
208
  f1ap_itti_send_sctp_data_req(false, instanceP, buffer, len, getCxt(DUtype, instanceP)->default_sctp_stream_id);
209
  return 0;
210
}
211

212 213
int DU_send_UL_NR_RRC_MESSAGE_TRANSFER(instance_t instance, const f1ap_ul_rrc_message_t *msg)
{
214
  F1AP_F1AP_PDU_t                pdu= {0};
215 216 217
  F1AP_ULRRCMessageTransfer_t    *out;
  uint8_t *buffer = NULL;
  uint32_t len;
218 219 220 221 222 223 224
  LOG_D(F1AP,
        "[DU %ld] %s: size %d UE RNTI %x in SRB %d\n",
        instance,
        __func__,
        msg->rrc_container_length,
        msg->gNB_DU_ue_id,
        msg->srb_id);
225 226 227 228 229 230
  //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
231
  asn1cCalloc(pdu.choice.initiatingMessage, tmp);
232 233 234 235
  tmp->procedureCode = F1AP_ProcedureCode_id_ULRRCMessageTransfer;
  tmp->criticality   = F1AP_Criticality_ignore;
  tmp->value.present = F1AP_InitiatingMessage__value_PR_ULRRCMessageTransfer;
  out = &tmp->value.choice.ULRRCMessageTransfer;
236 237
  /* mandatory */
  /* c1. GNB_CU_UE_F1AP_ID */
238 239 240 241
  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;
242
  ie1->value.choice.GNB_CU_UE_F1AP_ID = msg->gNB_CU_ue_id;
243 244
  /* mandatory */
  /* c2. GNB_DU_UE_F1AP_ID */
245 246 247 248
  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;
249
  ie2->value.choice.GNB_DU_UE_F1AP_ID = msg->gNB_DU_ue_id;
250 251
  /* mandatory */
  /* c3. SRBID */
252 253 254 255 256
  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;
257 258 259
  // issue in here
  /* mandatory */
  /* c4. RRCContainer */
260 261 262 263 264
  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,
265 266 267
                       (const char *) msg->rrc_container,
                       msg->rrc_container_length);

268
  /* encode */
269 270 271 272 273
  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
274
  f1ap_itti_send_sctp_data_req(false, instance, buffer, len, getCxt(DUtype, instance)->default_sctp_stream_id);
275 276
  return 0;
}