s1ap_eNB_ue_context.c 2.78 KB
Newer Older
1 2 3 4 5
/*
 * 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
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 * 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
 */

Cedric Roux's avatar
Cedric Roux committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35
/*! \file s1ap_eNB_ue_context.c
 * \brief s1ap UE context management within eNB
 * \author Sebastien ROUX <sebastien.roux@eurecom.fr>
 * \date 2012
 * \version 0.1
 */

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

#include "tree.h"

36 37
#include "intertask_interface.h"

Cedric Roux's avatar
Cedric Roux committed
38
#include "s1ap_common.h"
39
#include "s1ap_eNB_defs.h"
Cedric Roux's avatar
Cedric Roux committed
40 41
#include "s1ap_eNB_ue_context.h"

42
int s1ap_eNB_compare_eNB_ue_s1ap_id(
43
  struct s1ap_eNB_ue_context_s *p1, struct s1ap_eNB_ue_context_s *p2)
Cedric Roux's avatar
Cedric Roux committed
44
{
45 46 47 48 49 50 51 52 53
  if (p1->eNB_ue_s1ap_id > p2->eNB_ue_s1ap_id) {
    return 1;
  }

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

  return 0;
Cedric Roux's avatar
Cedric Roux committed
54 55 56 57 58 59 60 61
}

/* Generate the tree management functions */
RB_GENERATE(s1ap_ue_map, s1ap_eNB_ue_context_s, entries,
            s1ap_eNB_compare_eNB_ue_s1ap_id);

struct s1ap_eNB_ue_context_s *s1ap_eNB_allocate_new_UE_context(void)
{
62
  struct s1ap_eNB_ue_context_s *new_p;
Cedric Roux's avatar
Cedric Roux committed
63

64
  new_p = malloc(sizeof(struct s1ap_eNB_ue_context_s));
Cedric Roux's avatar
Cedric Roux committed
65

66 67 68 69
  if (new_p == NULL) {
    S1AP_ERROR("Cannot allocate new ue context\n");
    return NULL;
  }
Cedric Roux's avatar
Cedric Roux committed
70

71
  memset(new_p, 0, sizeof(struct s1ap_eNB_ue_context_s));
Cedric Roux's avatar
Cedric Roux committed
72

73
  return new_p;
Cedric Roux's avatar
Cedric Roux committed
74 75 76
}

struct s1ap_eNB_ue_context_s *s1ap_eNB_get_ue_context(
77 78
  s1ap_eNB_instance_t *instance_p,
  uint32_t eNB_ue_s1ap_id)
Cedric Roux's avatar
Cedric Roux committed
79
{
80
  s1ap_eNB_ue_context_t temp;
Cedric Roux's avatar
Cedric Roux committed
81

82
  memset(&temp, 0, sizeof(struct s1ap_eNB_ue_context_s));
Cedric Roux's avatar
Cedric Roux committed
83

84 85
  /* eNB ue s1ap id = 24 bits wide */
  temp.eNB_ue_s1ap_id = eNB_ue_s1ap_id & 0x00FFFFFF;
Cedric Roux's avatar
Cedric Roux committed
86

87
  return RB_FIND(s1ap_ue_map, &instance_p->s1ap_ue_head, &temp);
Cedric Roux's avatar
Cedric Roux committed
88 89 90 91
}

void s1ap_eNB_free_ue_context(struct s1ap_eNB_ue_context_s *ue_context_p)
{
92 93 94 95
  if (ue_context_p == NULL) {
    S1AP_ERROR("Trying to free a NULL context\n");
    return;
  }
Cedric Roux's avatar
Cedric Roux committed
96

97 98 99
  /* TODO: check that context is currently not in the tree of known
   * contexts.
   */
Cedric Roux's avatar
Cedric Roux committed
100

101
  free(ue_context_p);
Cedric Roux's avatar
Cedric Roux committed
102
}