rlc_tm_init.c 5.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * 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.0  (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
 */
21

22
23
#define RLC_TM_MODULE 1
#define RLC_TM_INIT_C 1
24
25
26
27
//-----------------------------------------------------------------------------
#include "rlc_tm.h"
#include "LAYER2/MAC/extern.h"
//-----------------------------------------------------------------------------
28
void config_req_rlc_tm (
29
30
31
  const protocol_ctxt_t* const  ctxt_pP,
  const srb_flag_t  srb_flagP,
  const rlc_tm_info_t * const config_tmP,
32
33
  const rb_id_t rb_idP,
  const logical_chan_id_t chan_idP
34
)
35
{
36
37
  rlc_union_t     *rlc_union_p  = NULL;
  rlc_tm_entity_t *rlc_p        = NULL;
38
  hash_key_t       key          = RLC_COLL_KEY_VALUE(ctxt_pP->module_id, ctxt_pP->rnti, ctxt_pP->enb_flag, rb_idP, srb_flagP);
39
40
41
42
43
44
  hashtable_rc_t   h_rc;

  h_rc = hashtable_get(rlc_coll_p, key, (void**)&rlc_union_p);

  if (h_rc == HASH_TABLE_OK) {
    rlc_p = &rlc_union_p->rlc.tm;
45
46
    LOG_D(RLC, PROTOCOL_RLC_TM_CTXT_FMT" CONFIG_REQ (is_uplink_downlink=%d) RB %u\n",
          PROTOCOL_RLC_TM_CTXT_ARGS(ctxt_pP, rlc_p),
47
48
49
50
51
          config_tmP->is_uplink_downlink,
          rb_idP);

    rlc_tm_init(ctxt_pP, rlc_p);
    rlc_p->protocol_state = RLC_DATA_TRANSFER_READY_STATE;
52
    rlc_tm_set_debug_infos(ctxt_pP, rlc_p, srb_flagP, rb_idP, chan_idP);
53
54
    rlc_tm_configure(ctxt_pP, rlc_p, config_tmP->is_uplink_downlink);
  } else {
55
56
    LOG_E(RLC, PROTOCOL_RLC_TM_CTXT_FMT" CONFIG_REQ RB %u RLC NOT FOUND\n",
          PROTOCOL_RLC_TM_CTXT_ARGS(ctxt_pP, rlc_p),
57
58
          rb_idP);
  }
59
60
61
}

//-----------------------------------------------------------------------------
62
void rlc_tm_init (
63
64
65
  const protocol_ctxt_t* const  ctxt_pP,
  rlc_tm_entity_t * const rlcP
)
66
{
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  int saved_allocation = rlcP->allocation;
  memset (rlcP, 0, sizeof (struct rlc_tm_entity));
  rlcP->allocation = saved_allocation;
  // TX SIDE
  list_init (&rlcP->pdus_to_mac_layer, NULL);

  rlcP->protocol_state    = RLC_NULL_STATE;
  rlcP->nb_sdu            = 0;
  rlcP->next_sdu_index    = 0;
  rlcP->current_sdu_index = 0;

  rlcP->output_sdu_size_to_write = 0;
  rlcP->buffer_occupancy  = 0;

  // SPARE : not 3GPP
  rlcP->size_input_sdus_buffer = 16;

  if ((rlcP->input_sdus_alloc == NULL) && (rlcP->size_input_sdus_buffer > 0)) {
85
    rlcP->input_sdus_alloc = get_free_mem_block (rlcP->size_input_sdus_buffer * sizeof (void *), __func__);
86
87
88
    rlcP->input_sdus = (mem_block_t **) (rlcP->input_sdus_alloc->data);
    memset (rlcP->input_sdus, 0, rlcP->size_input_sdus_buffer * sizeof (void *));
  }
89
90
91
}

//-----------------------------------------------------------------------------
92
93
void
rlc_tm_reset_state_variables (
94
95
96
  const protocol_ctxt_t* const  ctxt_pP,
  struct rlc_tm_entity * const rlcP
)
97
98
99
100
101
102
103
104
105
{
  rlcP->output_sdu_size_to_write = 0;
  rlcP->buffer_occupancy = 0;
  rlcP->nb_sdu = 0;
  rlcP->next_sdu_index = 0;
  rlcP->current_sdu_index = 0;
}
//-----------------------------------------------------------------------------
void
106
rlc_tm_cleanup (
107
108
  rlc_tm_entity_t * const rlcP
)
109
{
110
111
112
113
114
115
116
  int             index;
  // TX SIDE
  list_free (&rlcP->pdus_to_mac_layer);

  if (rlcP->input_sdus_alloc) {
    for (index = 0; index < rlcP->size_input_sdus_buffer; index++) {
      if (rlcP->input_sdus[index]) {
117
        free_mem_block (rlcP->input_sdus[index], __func__);
118
      }
119
    }
120

121
    free_mem_block (rlcP->input_sdus_alloc, __func__);
122
123
124
125
126
    rlcP->input_sdus_alloc = NULL;
  }

  // RX SIDE
  if ((rlcP->output_sdu_in_construction)) {
127
    free_mem_block (rlcP->output_sdu_in_construction, __func__);
128
129
130
  }

  memset(rlcP, 0, sizeof(rlc_tm_entity_t));
131
132
133
}

//-----------------------------------------------------------------------------
134
void rlc_tm_configure(
135
136
137
  const protocol_ctxt_t* const  ctxt_pP,
  rlc_tm_entity_t * const rlcP,
  const boolean_t is_uplink_downlinkP)
138
{
139
140
  rlcP->is_uplink_downlink = is_uplink_downlinkP;
  rlc_tm_reset_state_variables (ctxt_pP, rlcP);
141
142
143
}

//-----------------------------------------------------------------------------
144
void rlc_tm_set_debug_infos(
145
146
147
  const protocol_ctxt_t* const  ctxt_pP,
  rlc_tm_entity_t * const rlcP,
  const srb_flag_t  srb_flagP,
148
  const rb_id_t     rb_idP,
149
  const logical_chan_id_t chan_idP) 
150
{
151
152
  rlcP->rb_id      = rb_idP;
  rlcP->channel_id = chan_idP;
153
154
155
156
157
158

  if (srb_flagP) {
    rlcP->is_data_plane = 0;
  } else {
    rlcP->is_data_plane = 1;
  }
159
}