rrc_gNB_internode.c 5.94 KB
Newer Older
Raymond Knopp's avatar
Raymond Knopp committed
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 34 35 36 37
/*
 * 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 rrc_gNB_internode.c
 * \brief rrc internode procedures for gNB
 * \author Raymond Knopp
 * \date 2019
 * \version 1.0
 * \company Eurecom
 * \email: raymond.knopp@eurecom.fr
 */
#ifndef RRC_GNB_INTERNODE_C
#define RRC_GNB_INTERNODE_C

#include "nr_rrc_defs.h"
#include "NR_RRCReconfiguration.h"
#include "NR_UE-NR-Capability.h"
#include "NR_CG-ConfigInfo.h"
#include "NR_UE-CapabilityRAT-ContainerList.h"
38
#include "LTE_UE-CapabilityRAT-ContainerList.h"
Raymond Knopp's avatar
Raymond Knopp committed
39 40
#include "NR_CG-Config.h"

41
int parse_CG_ConfigInfo(gNB_RRC_INST *rrc, NR_CG_ConfigInfo_t *CG_ConfigInfo, x2ap_ENDC_sgnb_addition_req_t *m) {
Raymond Knopp's avatar
Raymond Knopp committed
42 43 44
  if (CG_ConfigInfo->criticalExtensions.present == NR_CG_ConfigInfo__criticalExtensions_PR_c1) {
    if (CG_ConfigInfo->criticalExtensions.choice.c1) {
      if (CG_ConfigInfo->criticalExtensions.choice.c1->present == NR_CG_ConfigInfo__criticalExtensions__c1_PR_cg_ConfigInfo) {
45 46 47 48
        NR_CG_ConfigInfo_IEs_t *cg_ConfigInfo = CG_ConfigInfo->criticalExtensions.choice.c1->choice.cg_ConfigInfo;

        if (cg_ConfigInfo->ue_CapabilityInfo) {
          // Decode UE-CapabilityRAT-ContainerList
49
          LTE_UE_CapabilityRAT_ContainerList_t *UE_CapabilityRAT_ContainerList=NULL;
50 51 52 53 54 55 56
          UE_CapabilityRAT_ContainerList = calloc(1,sizeof(LTE_UE_CapabilityRAT_ContainerList_t));
          asn_dec_rval_t dec_rval = uper_decode(NULL,
                                                &asn_DEF_LTE_UE_CapabilityRAT_ContainerList,
                                                (void **)&UE_CapabilityRAT_ContainerList,
                                                cg_ConfigInfo->ue_CapabilityInfo->buf,
                                                cg_ConfigInfo->ue_CapabilityInfo->size, 0, 0);

Raymond Knopp's avatar
Raymond Knopp committed
57
          if ((dec_rval.code != RC_OK) && (dec_rval.consumed == 0)) {
58 59 60 61 62 63 64 65 66 67
            AssertFatal(1==0,"[InterNode] Failed to decode NR_UE_CapabilityRAT_ContainerList (%zu bits), size of OCTET_STRING %lu\n",
                        dec_rval.consumed, cg_ConfigInfo->ue_CapabilityInfo->size);
          }

          rrc_parse_ue_capabilities(rrc,UE_CapabilityRAT_ContainerList, m,cg_ConfigInfo);
        }

        if (cg_ConfigInfo->candidateCellInfoListMN) AssertFatal(1==0,"Can't handle candidateCellInfoListMN yet\n");
      } else AssertFatal(1==0,"c1 extension is not cg_ConfigInfo, returning\n");
    } else {
Raymond Knopp's avatar
Raymond Knopp committed
68
      LOG_E(RRC,"c1 extension not found, returning\n");
69
      return(-1);
Raymond Knopp's avatar
Raymond Knopp committed
70 71 72 73 74 75
    }
  } else {
    LOG_E(RRC,"Ignoring unknown CG_ConfigInfo extensions\n");
    return(-1);
  }

76 77
  return(0);
}
Raymond Knopp's avatar
Raymond Knopp committed
78 79


80 81 82 83
int generate_CG_Config(gNB_RRC_INST *rrc,
                       NR_CG_Config_t *cg_Config,
                       NR_RRCReconfiguration_t *reconfig,
                       NR_RadioBearerConfig_t *rbconfig) {
Raymond Knopp's avatar
Raymond Knopp committed
84 85 86 87 88
  cg_Config->criticalExtensions.present = NR_CG_Config__criticalExtensions_PR_c1;
  cg_Config->criticalExtensions.choice.c1 = calloc(1,sizeof(*cg_Config->criticalExtensions.choice.c1));
  cg_Config->criticalExtensions.choice.c1->present = NR_CG_Config__criticalExtensions__c1_PR_cg_Config;
  cg_Config->criticalExtensions.choice.c1->choice.cg_Config = calloc(1,sizeof(NR_CG_Config_IEs_t));
  char buffer[1024];
89
  int total_size;
Raymond Knopp's avatar
Raymond Knopp committed
90 91 92 93 94
  asn_enc_rval_t enc_rval = uper_encode_to_buffer(&asn_DEF_NR_RRCReconfiguration, NULL, (void *)reconfig, buffer, 1024);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);
  cg_Config->criticalExtensions.choice.c1->choice.cg_Config->scg_CellGroupConfig = calloc(1,sizeof(OCTET_STRING_t));
  OCTET_STRING_fromBuf(cg_Config->criticalExtensions.choice.c1->choice.cg_Config->scg_CellGroupConfig,
95 96
                       (const char *)buffer,
                       (enc_rval.encoded+7)>>3);
97
  total_size = (enc_rval.encoded+7)>>3;
98
  LOG_I(RRC,"Dumping NR_RRCReconfiguration message (%jd bytes)\n",(enc_rval.encoded+7)>>3);
99 100

  for (int i=0; i<(enc_rval.encoded+7)>>3; i++) {
101
    printf("%02x",((uint8_t *)buffer)[i]);
Raymond Knopp's avatar
Raymond Knopp committed
102
  }
103

Raymond Knopp's avatar
Raymond Knopp committed
104
  printf("\n");
105
  FILE *fd = fopen("reconfig.raw","w");
106
  fwrite((void *)buffer,1,(size_t)((enc_rval.encoded+7)>>3),fd);
107
  fclose(fd);
Raymond Knopp's avatar
Raymond Knopp committed
108 109 110 111 112
  enc_rval = uper_encode_to_buffer(&asn_DEF_NR_RadioBearerConfig, NULL, (void *)rbconfig, buffer, 1024);
  AssertFatal (enc_rval.encoded > 0, "ASN1 message encoding failed (%s, %jd)!\n",
               enc_rval.failed_type->name, enc_rval.encoded);
  cg_Config->criticalExtensions.choice.c1->choice.cg_Config->scg_RB_Config = calloc(1,sizeof(OCTET_STRING_t));
  OCTET_STRING_fromBuf(cg_Config->criticalExtensions.choice.c1->choice.cg_Config->scg_RB_Config,
113 114
                       (const char *)buffer,
                       (enc_rval.encoded+7)>>3);
115
  LOG_I(RRC,"Dumping scg_RB_Config message (%jd bytes)\n",(enc_rval.encoded+7)>>3);
116 117 118

  for (int i=0; i<(enc_rval.encoded+7)>>3; i++) {
    printf("%02x",((uint8_t *)buffer)[i]);
Raymond Knopp's avatar
Raymond Knopp committed
119
  }
120

Raymond Knopp's avatar
Raymond Knopp committed
121
  printf("\n");
122
  fd = fopen("rbconfig.raw","w");
123
  fwrite((void *)buffer,1,(size_t)((enc_rval.encoded+7)>>3),fd);
124
  fclose(fd);
125 126
  total_size = total_size + ((enc_rval.encoded+7)>>3);
  return(total_size);
Raymond Knopp's avatar
Raymond Knopp committed
127 128 129
}

#endif