ngap_gNB_ue_context.c 2.89 KB
Newer Older
zhenghuangkun's avatar
zhenghuangkun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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 ngap_gNB_ue_context.c
 * \brief ngap UE context management within gNB
zhenghuangkun's avatar
zhenghuangkun committed
24 25
 * \author Yoshio INOUE, Masayuki HARADA
 * \date 2020
zhenghuangkun's avatar
zhenghuangkun committed
26
 * \version 0.1
zhenghuangkun's avatar
zhenghuangkun committed
27 28
 * \email: yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com (yoshio.inoue%40fujitsu.com%2cmasayuki.harada%40fujitsu.com)
 */ 
zhenghuangkun's avatar
zhenghuangkun committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#include "tree.h"

#include "intertask_interface.h"

#include "ngap_common.h"
#include "ngap_gNB_defs.h"
#include "ngap_gNB_ue_context.h"

int ngap_gNB_compare_gNB_ue_ngap_id(
  struct ngap_gNB_ue_context_s *p1, struct ngap_gNB_ue_context_s *p2)
{
  if (p1->gNB_ue_ngap_id > p2->gNB_ue_ngap_id) {
    return 1;
  }

  if (p1->gNB_ue_ngap_id < p2->gNB_ue_ngap_id) {
    return -1;
  }

  return 0;
}

/* Generate the tree management functions */
RB_GENERATE(ngap_ue_map, ngap_gNB_ue_context_s, entries,
            ngap_gNB_compare_gNB_ue_ngap_id);

struct ngap_gNB_ue_context_s *ngap_gNB_allocate_new_UE_context(void)
{
  struct ngap_gNB_ue_context_s *new_p;

  new_p = malloc(sizeof(struct ngap_gNB_ue_context_s));

  if (new_p == NULL) {
    NGAP_ERROR("Cannot allocate new ue context\n");
    return NULL;
  }

  memset(new_p, 0, sizeof(struct ngap_gNB_ue_context_s));

  return new_p;
}

struct ngap_gNB_ue_context_s *ngap_gNB_get_ue_context(
  ngap_gNB_instance_t *instance_p,
  uint32_t gNB_ue_ngap_id)
{
  ngap_gNB_ue_context_t temp;

  memset(&temp, 0, sizeof(struct ngap_gNB_ue_context_s));

Xue Song's avatar
Xue Song committed
85 86
  /* gNB ue ngap id = 32 bits wide */
  temp.gNB_ue_ngap_id = gNB_ue_ngap_id & 0xFFFFFFFF;
zhenghuangkun's avatar
zhenghuangkun committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

  return RB_FIND(ngap_ue_map, &instance_p->ngap_ue_head, &temp);
}

void ngap_gNB_free_ue_context(struct ngap_gNB_ue_context_s *ue_context_p)
{
  if (ue_context_p == NULL) {
    NGAP_ERROR("Trying to free a NULL context\n");
    return;
  }

  /* TODO: check that context is currently not in the tree of known
   * contexts.
   */

  free(ue_context_p);
}