rlc_mac.c 25.8 KB
Newer Older
gauthier's avatar
Licence    
gauthier 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
/*******************************************************************************
Eurecom OpenAirInterface 2
Copyright(c) 1999 - 2014 Eurecom

This program is free software; you can redistribute it and/or modify it
under the terms and conditions of the GNU General Public License,
version 2, as published by the Free Software Foundation.

This program is distributed in the hope it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.

The full GNU General Public License is included in this distribution in
the file called "COPYING".

Contact Information
Openair Admin: openair_admin@eurecom.fr
Openair Tech : openair_tech@eurecom.fr
Forums       : http://forums.eurecom.fsr/openairinterface
Address      : EURECOM,
               Campus SophiaTech,
               450 Route des Chappes,
               CS 50193
               06904 Biot Sophia Antipolis cedex,
               FRANCE
*******************************************************************************/
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
                                rlc_mac.c
                             -------------------
  AUTHOR  : Lionel GAUTHIER
  COMPANY : EURECOM
  EMAIL   : Lionel.Gauthier@eurecom.fr
*/

//-----------------------------------------------------------------------------
#define RLC_MAC_C
#include "rlc.h"
#include "LAYER2/MAC/extern.h"
#include "UTIL/LOG/log.h"
gauthier's avatar
gauthier committed
45
46
#include "UTIL/OCG/OCG_vars.h"
#include "assertions.h"
47

gauthier's avatar
gauthier committed
48
#define DEBUG_MAC_INTERFACE 1
49
50

//-----------------------------------------------------------------------------
51
52
53
54
55
struct mac_data_ind mac_rlc_deserialize_tb (
    char     *buffer_pP,
    tb_size_t tb_sizeP,
    num_tb_t  num_tbP,
    crc_t    *crcs_pP) {
56
57
//-----------------------------------------------------------------------------
  struct mac_data_ind  data_ind;
gauthier's avatar
gauthier committed
58
  mem_block_t*         tb_p;
59
  num_tb_t             nb_tb_read;
60
  tbs_size_t           tbs_size;
61
62
63
64
65
66

  nb_tb_read = 0;
  tbs_size   = 0;
  list_init(&data_ind.data, NULL);

  while (num_tbP > 0) {
gauthier's avatar
gauthier committed
67
68
69
        tb_p = get_free_mem_block(sizeof (mac_rlc_max_rx_header_size_t) + tb_sizeP);
        if (tb_p != NULL) {
            ((struct mac_tb_ind *) (tb_p->data))->first_bit = 0;
gauthier's avatar
gauthier committed
70
            ((struct mac_tb_ind *) (tb_p->data))->data_ptr = (uint8_t*)&tb_p->data[sizeof (mac_rlc_max_rx_header_size_t)];
gauthier's avatar
gauthier committed
71
72
73
            ((struct mac_tb_ind *) (tb_p->data))->size = tb_sizeP;
            if (crcs_pP)
                ((struct mac_tb_ind *) (tb_p->data))->error_indication = crcs_pP[nb_tb_read];
74
            else
gauthier's avatar
gauthier committed
75
                ((struct mac_tb_ind *) (tb_p->data))->error_indication = 0;
76

gauthier's avatar
gauthier committed
77
            memcpy(((struct mac_tb_ind *) (tb_p->data))->data_ptr, &buffer_pP[tbs_size], tb_sizeP);
78
79
80

#ifdef DEBUG_MAC_INTERFACE
            LOG_T(RLC, "[MAC-RLC] DUMP RX PDU(%d bytes):\n", tb_sizeP);
gauthier's avatar
gauthier committed
81
            rlc_util_print_hex_octets(RLC, ((struct mac_tb_ind *) (tb_p->data))->data_ptr, tb_sizeP);
82
83
84
#endif
            nb_tb_read = nb_tb_read + 1;
            tbs_size   = tbs_size   + tb_sizeP;
gauthier's avatar
gauthier committed
85
            list_add_tail_eurecom(tb_p, &data_ind.data);
86
87
88
89
90
91
92
93
94
        }
        num_tbP = num_tbP - 1;
  }
  data_ind.no_tb            = nb_tb_read;
  data_ind.tb_size          = tb_sizeP << 3;

  return data_ind;
}
//-----------------------------------------------------------------------------
gauthier's avatar
gauthier committed
95
tbs_size_t mac_rlc_serialize_tb (char* buffer_pP, list_t transport_blocksP) {
96
//-----------------------------------------------------------------------------
97
  mem_block_t *tb_p;
98
99
100
101
102
  tbs_size_t   tbs_size;
  tbs_size_t   tb_size;

  tbs_size = 0;
  while (transport_blocksP.nb_elements > 0) {
gauthier's avatar
gauthier committed
103
104
105
    tb_p = list_remove_head (&transport_blocksP);
    if (tb_p != NULL) {
       tb_size = ((struct mac_tb_req *) (tb_p->data))->tb_size;
106
107
#ifdef DEBUG_MAC_INTERFACE
        LOG_T(RLC, "[MAC-RLC] DUMP TX PDU(%d bytes):\n", tb_size);
gauthier's avatar
gauthier committed
108
        rlc_util_print_hex_octets(RLC, ((struct mac_tb_req *) (tb_p->data))->data_ptr, tb_size);
109
#endif
gauthier's avatar
gauthier committed
110
       memcpy(&buffer_pP[tbs_size], &((struct mac_tb_req *) (tb_p->data))->data_ptr[0], tb_size);
111
       tbs_size = tbs_size + tb_size;
gauthier's avatar
gauthier committed
112
       free_mem_block(tb_p);
113
114
115
116
117
    }
  }
  return tbs_size;
}
//-----------------------------------------------------------------------------
118
119
120
121
122
123
124
125
tbs_size_t mac_rlc_data_req(
    module_id_t       enb_mod_idP,
    module_id_t       ue_mod_idP,
    frame_t           frameP,
    eNB_flag_t        enb_flagP,
    MBMS_flag_t       MBMS_flagP,
    logical_chan_id_t channel_idP,
    char             *buffer_pP) {
126
127
//-----------------------------------------------------------------------------
    struct mac_data_req    data_request;
128
129
130
131
    rb_id_t                rb_id           = 0;
    rlc_mode_t             rlc_mode        = RLC_MODE_NONE;
    void                  *rlc_p           = NULL;
    rlc_mbms_id_t         *mbms_id_p       = NULL;
gauthier's avatar
gauthier committed
132

133
#ifdef DEBUG_MAC_INTERFACE
gauthier's avatar
gauthier committed
134
    LOG_D(RLC, "\n[RLC] Inst %s enb id %d ue id %d: MAC_RLC_DATA_REQ channel %d (%d) MAX RB %d, Num_tb %d\n",
gauthier's avatar
gauthier committed
135
               (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP, channel_idP, RLC_MAX_LC, NB_RB_MAX);
gauthier's avatar
gauthier committed
136

137
#endif // DEBUG_MAC_INTERFACE
gauthier's avatar
gauthier committed
138
    if (MBMS_flagP)
139
        AssertFatal (channel_idP < RLC_MAX_MBMS_LC,        "channel id is too high (%u/%d)!\n",     channel_idP, RLC_MAX_MBMS_LC);
gauthier's avatar
gauthier committed
140
141
    else
        AssertFatal (channel_idP < NB_RB_MAX,        "channel id is too high (%u/%d)!\n",     channel_idP, NB_RB_MAX);
142
#if defined(USER_MODE) && defined(OAI_EMU)
gauthier's avatar
gauthier committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    if (enb_flagP) {
        AssertFatal ((enb_mod_idP >= oai_emulation.info.first_enb_local) && (oai_emulation.info.nb_enb_local > 0),
            "eNB module id is too low (%u/%d)!\n",
            enb_mod_idP,
            oai_emulation.info.first_enb_local);
        AssertFatal ((enb_mod_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local)) && (oai_emulation.info.nb_enb_local > 0),
            "eNB module id is too high (%u/%d)!\n",
            enb_mod_idP,
            oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local);
        AssertFatal (ue_mod_idP  < NB_UE_INST,
            "UE module id is too high (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
    } else {
157
158
        AssertFatal (MBMS_flagP == MBMS_FLAG_NO ," MBMS FLAG SHOULD NOT BE SET IN mac_rlc_data_req in UE\n");

gauthier's avatar
gauthier committed
159
160
161
162
163
164
165
166
167
        AssertFatal (ue_mod_idP  < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local),
            "UE module id is too high (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
        AssertFatal (ue_mod_idP  >= oai_emulation.info.first_ue_local,
            "UE module id is too low (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local);
    }
168
#endif 
gauthier's avatar
gauthier committed
169
170

    if (enb_flagP) {
171
172
        if (MBMS_flagP) {
            mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[enb_mod_idP][channel_idP];
173
174
175
            rb_id     = rlc_mbms_array_eNB[enb_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].rb_id;
            rlc_p     = (void*)&rlc_mbms_array_eNB[enb_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um;
            rlc_mode  = RLC_MODE_UM;
176
177
178
179
180
181
182
            AssertFatal (rlc_mbms_array_eNB[enb_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um.allocation == TRUE ,
                "enB MBMS RLC UM not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
        } else {
            rb_id = lcid2rbid_eNB[enb_mod_idP][ue_mod_idP][channel_idP];
            rlc_mode = rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].mode;
            switch (rlc_mode) {
                case RLC_MODE_NONE:
183
184
		  //AssertFatal (0 , "enB RLC not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
		  AssertError (0 , 0, "enB RLC not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
185
186
187
188
189
190
191
192
193
194
195
196
197
198
                    return (tbs_size_t)0;
                    break;
                case RLC_MODE_AM:
                    rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.am;
                    break;
                case RLC_MODE_UM:
                    rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.um;
                    break;
                case RLC_MODE_TM:
                    rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.tm;
                    break;
                default:
                    AssertFatal (0 , "enB RLC internal memory error rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
            }
gauthier's avatar
gauthier committed
199
200
201
202
203
        }
    } else {
        rb_id = lcid2rbid_ue[ue_mod_idP][channel_idP];
        rlc_mode = rlc_array_ue[ue_mod_idP][rb_id].mode;
        switch (rlc_mode) {
gauthier's avatar
gauthier committed
204
          case RLC_MODE_NONE:
gauthier's avatar
gauthier committed
205
206
207
              AssertFatal (0 , "UE RLC not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, ue_mod_idP);
              return (tbs_size_t)0;
              break;
gauthier's avatar
gauthier committed
208
          case RLC_MODE_AM:
gauthier's avatar
gauthier committed
209
210
              rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.am;
              break;
gauthier's avatar
gauthier committed
211
          case RLC_MODE_UM:
gauthier's avatar
gauthier committed
212
213
              rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.um;
              break;
gauthier's avatar
gauthier committed
214
          case RLC_MODE_TM:
gauthier's avatar
gauthier committed
215
216
217
218
219
220
221
222
              rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.tm;
              break;
          default:
              AssertFatal (0 , "UE RLC internal memory error rb id %u lcid %u module %u!\n", rb_id, channel_idP, ue_mod_idP);
        }
    }

    switch (rlc_mode) {
gauthier's avatar
gauthier committed
223
        case RLC_MODE_NONE:
gauthier's avatar
gauthier committed
224
225
        break;

gauthier's avatar
gauthier committed
226
        case RLC_MODE_AM:
gauthier's avatar
gauthier committed
227
228
229
230
            data_request = rlc_am_mac_data_request((rlc_am_entity_t*)rlc_p, frameP);
            return mac_rlc_serialize_tb(buffer_pP, data_request.data);
            break;

gauthier's avatar
gauthier committed
231
        case RLC_MODE_UM:
gauthier's avatar
gauthier committed
232
233
234
235
            data_request = rlc_um_mac_data_request((rlc_um_entity_t*)rlc_p, frameP);
            return mac_rlc_serialize_tb(buffer_pP, data_request.data);
            break;

gauthier's avatar
gauthier committed
236
        case RLC_MODE_TM:
gauthier's avatar
gauthier committed
237
238
239
240
241
242
243
            data_request = rlc_tm_mac_data_request((rlc_tm_entity_t*)rlc_p, frameP);
            return mac_rlc_serialize_tb(buffer_pP, data_request.data);
            break;

        default:;
    }
    return (tbs_size_t)0;
244
245
}
//-----------------------------------------------------------------------------
246
247
248
249
250
251
252
253
254
255
256
void mac_rlc_data_ind     (
    module_id_t         enb_mod_idP,
    module_id_t         ue_mod_idP,
    frame_t             frameP,
    eNB_flag_t          enb_flagP,
    MBMS_flag_t         MBMS_flagP,
    logical_chan_id_t   channel_idP,
    char               *buffer_pP,
    tb_size_t           tb_sizeP,
    num_tb_t            num_tbP,
    crc_t              *crcs_pP) {
257
//-----------------------------------------------------------------------------
258
259
    rb_id_t                rb_id      = 0;
    rlc_mode_t             rlc_mode   = RLC_MODE_NONE;
gauthier's avatar
gauthier committed
260
    void                  *rlc_p      = NULL;
261
    rlc_mbms_id_t         *mbms_id_p  = NULL;
262
263
#ifdef DEBUG_MAC_INTERFACE
    if (num_tbP) {
gauthier's avatar
gauthier committed
264
265
      LOG_D(RLC, "[Frame %5u][%s][RLC][MOD %u/%u] MAC_RLC_DATA_IND on channel %d (%d), rb max %d, Num_tb %d\n",
              frameP,
gauthier's avatar
gauthier committed
266
              (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
267
268
269
270
271
272
              enb_mod_idP,
              ue_mod_idP,
              channel_idP,
              RLC_MAX_LC,
              NB_RB_MAX,
              num_tbP);
273
274
    }
#endif // DEBUG_MAC_INTERFACE
gauthier's avatar
gauthier committed
275
#ifdef OAI_EMU
gauthier's avatar
gauthier committed
276
    if (MBMS_flagP)
277
278
        AssertFatal (channel_idP < RLC_MAX_MBMS_LC,  "channel id is too high (%u/%d)!\n",
                     channel_idP, RLC_MAX_MBMS_LC);
gauthier's avatar
gauthier committed
279
    else
280
281
        AssertFatal (channel_idP < NB_RB_MAX,        "channel id is too high (%u/%d)!\n",
                     channel_idP, NB_RB_MAX);
282

gauthier's avatar
gauthier committed
283
284
285
286
287
288
289
290
291
292
293
294
295
    if (enb_flagP) {
        AssertFatal ((enb_mod_idP >= oai_emulation.info.first_enb_local) && (oai_emulation.info.nb_enb_local > 0),
            "eNB module id is too low (%u/%d)!\n",
            enb_mod_idP,
            oai_emulation.info.first_enb_local);
        AssertFatal ((enb_mod_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local)) && (oai_emulation.info.nb_enb_local > 0),
            "eNB module id is too high (%u/%d)!\n",
            enb_mod_idP,
            oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local);
        AssertFatal (ue_mod_idP  < NB_UE_INST,
            "UE module id is too high (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
296
        AssertFatal (MBMS_flagP == MBMS_FLAG_NO ," MBMS FLAG SHOULD NOT BE SET IN mac_rlc_data_ind in eNB\n");
gauthier's avatar
gauthier committed
297
298
299
300
301
302
303
304
305
306
307
308
    } else {
        AssertFatal (ue_mod_idP  < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local),
            "UE module id is too high (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
        AssertFatal (ue_mod_idP  >= oai_emulation.info.first_ue_local,
            "UE module id is too low (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local);
    }
#endif
    if (enb_flagP) {
gauthier's avatar
gauthier committed
309
310
311
312
        rb_id = lcid2rbid_eNB[enb_mod_idP][ue_mod_idP][channel_idP];
        AssertFatal (rb_id < NB_RB_MAX, "enB RB id is too high (%u/%d) lcid %u enb module %u ue module id %u!\n", rb_id, NB_RB_MAX, channel_idP, enb_mod_idP, ue_mod_idP);
        rlc_mode = rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].mode;
        switch (rlc_mode) {
gauthier's avatar
gauthier committed
313
          case RLC_MODE_NONE:
314
315
	    //AssertFatal (0 , "enB RLC not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
	    AssertError (0 , 0, "enB RLC not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
gauthier's avatar
gauthier committed
316
              break;
gauthier's avatar
gauthier committed
317
          case RLC_MODE_AM:
gauthier's avatar
gauthier committed
318
319
              rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.am;
              break;
gauthier's avatar
gauthier committed
320
          case RLC_MODE_UM:
gauthier's avatar
gauthier committed
321
322
              rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.um;
              break;
gauthier's avatar
gauthier committed
323
          case RLC_MODE_TM:
gauthier's avatar
gauthier committed
324
325
326
327
328
329
              rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.tm;
              break;
          default:
              AssertFatal (0 , "enB RLC internal memory error rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
        }
    } else {
330
331
        if (MBMS_flagP) {
            mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ue_mod_idP][channel_idP];
332
333
334
            rb_id     = rlc_mbms_array_ue[ue_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].rb_id;
            rlc_p     = (void*)&rlc_mbms_array_ue[ue_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um;
            rlc_mode  = RLC_MODE_UM;
335
            AssertFatal (rlc_mbms_array_ue[ue_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um.allocation == TRUE ,
336
337
                "UE MBMS RLC UM not configured rb id %u lcid %u service_id %u session_id %u module %u!\n",
                rb_id, channel_idP,mbms_id_p->service_id, mbms_id_p->session_id, ue_mod_idP);
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
        } else {
            rb_id = lcid2rbid_ue[ue_mod_idP][channel_idP];
            AssertFatal (rb_id < NB_RB_MAX, "UE RB id is too high (%u/%d) lcid %u enb module %u ue module id %u!\n", rb_id, NB_RB_MAX, channel_idP, enb_mod_idP, ue_mod_idP);
            rlc_mode = rlc_array_ue[ue_mod_idP][rb_id].mode;
            switch (rlc_mode) {
              case RLC_MODE_NONE:
                  AssertFatal (0 , "UE RLC not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, ue_mod_idP);
                  break;
              case RLC_MODE_AM:
                  rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.am;
                  break;
              case RLC_MODE_UM:
                  rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.um;
                  break;
              case RLC_MODE_TM:
                  rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.tm;
                  break;
              default:
                AssertFatal (0 , "UE RLC internal memory error rb id %u lcid %u module %u!\n", rb_id, channel_idP, ue_mod_idP);
            }
gauthier's avatar
gauthier committed
358
359
360
361
        }
    }
    struct mac_data_ind data_ind = mac_rlc_deserialize_tb(buffer_pP, tb_sizeP, num_tbP, crcs_pP);
    switch (rlc_mode) {
gauthier's avatar
gauthier committed
362
        case RLC_MODE_NONE:
gauthier's avatar
gauthier committed
363
364
        //handle_event(WARNING,"FILE %s FONCTION mac_rlc_data_ind() LINE %s : no radio bearer configured :%d\n", __FILE__, __LINE__, channel_idP);
        break;
365

gauthier's avatar
gauthier committed
366
        case RLC_MODE_AM:
367
#ifdef DEBUG_MAC_INTERFACE
gauthier's avatar
gauthier committed
368
            LOG_D(RLC, "MAC DATA IND TO RLC_AM MOD_ID %s enb id %u ue id %u \n", (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP);
369
#endif
gauthier's avatar
gauthier committed
370
            rlc_am_mac_data_indication((rlc_am_entity_t*)rlc_p, frameP, enb_flagP, data_ind);
gauthier's avatar
gauthier committed
371
            break;
372

gauthier's avatar
gauthier committed
373
        case RLC_MODE_UM:
374
#ifdef DEBUG_MAC_INTERFACE
gauthier's avatar
gauthier committed
375
            LOG_D(RLC, "MAC DATA IND TO RLC_UM MOD_ID %s enb id %u ue id %u \n", (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP);
376
#endif
gauthier's avatar
gauthier committed
377
            rlc_um_mac_data_indication((rlc_um_entity_t*)rlc_p, frameP, enb_flagP, data_ind);
gauthier's avatar
gauthier committed
378
            break;
379

gauthier's avatar
gauthier committed
380
        case RLC_MODE_TM:
381
#ifdef DEBUG_MAC_INTERFACE
gauthier's avatar
gauthier committed
382
            LOG_D(RLC, "MAC DATA IND TO RLC_TM MOD_ID %s enb id %u ue id %u \n", (enb_flagP) ? "eNB" : "UE", enb_mod_idP, ue_mod_idP);
383
#endif
gauthier's avatar
gauthier committed
384
            rlc_tm_mac_data_indication((rlc_tm_entity_t*)rlc_p, frameP, enb_flagP, data_ind);
gauthier's avatar
gauthier committed
385
            break;
386
387
388
    }
}
//-----------------------------------------------------------------------------
389
390
391
392
393
394
395
396
mac_rlc_status_resp_t mac_rlc_status_ind(
    module_id_t       enb_mod_idP,
    module_id_t       ue_mod_idP,
    frame_t           frameP,
    eNB_flag_t        enb_flagP,
    MBMS_flag_t       MBMS_flagP,
    logical_chan_id_t channel_idP,
    tb_size_t         tb_sizeP) {
397
398
//-----------------------------------------------------------------------------
  mac_rlc_status_resp_t  mac_rlc_status_resp;
gauthier's avatar
gauthier committed
399
400
  struct mac_status_ind  tx_status;
  struct mac_status_resp status_resp;
401
402
  rb_id_t                rb_id      = 0;
  rlc_mode_t             rlc_mode   = RLC_MODE_NONE;
gauthier's avatar
gauthier committed
403
  void                  *rlc_p      = NULL;
404
  rlc_mbms_id_t         *mbms_id_p  = NULL;
gauthier's avatar
gauthier committed
405
406
407
408

  memset (&mac_rlc_status_resp, 0, sizeof(mac_rlc_status_resp_t));
  memset (&tx_status          , 0, sizeof(struct mac_status_ind));

gauthier's avatar
gauthier committed
409
#ifdef OAI_EMU
gauthier's avatar
gauthier committed
410
  if (MBMS_flagP)
411
412
413
414
415
416
417
      AssertFatal (channel_idP < RLC_MAX_MBMS_LC,
                   "%s channel id is too high (%u/%d) enb module id %u ue module id %u!\n",
                   (enb_flagP) ? "eNB" : "UE",
                   channel_idP,
                   RLC_MAX_MBMS_LC,
                   enb_mod_idP,
                   ue_mod_idP);
gauthier's avatar
gauthier committed
418
  else
419
420
421
422
423
424
425
      AssertFatal (channel_idP < NB_RB_MAX,
                   "%s channel id is too high (%u/%d) enb module id %u ue module id %u!\n",
                   (enb_flagP) ? "eNB" : "UE",
                   channel_idP,
                   NB_RB_MAX,
                   enb_mod_idP,
                   ue_mod_idP);
gauthier's avatar
gauthier committed
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453

    if (enb_flagP) {
        AssertFatal ((enb_mod_idP >= oai_emulation.info.first_enb_local) && (oai_emulation.info.nb_enb_local > 0),
            "eNB module id is too low (%u/%d)!\n",
            enb_mod_idP,
            oai_emulation.info.first_enb_local);
        AssertFatal ((enb_mod_idP < (oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local)) && (oai_emulation.info.nb_enb_local > 0),
            "eNB module id is too high (%u/%d)!\n",
            enb_mod_idP,
            oai_emulation.info.first_enb_local + oai_emulation.info.nb_enb_local);
        AssertFatal (ue_mod_idP  < NB_UE_INST,
            "UE module id is too high (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
    } else {
        AssertFatal (ue_mod_idP  < (oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local),
            "UE module id is too high (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local + oai_emulation.info.nb_ue_local);
        AssertFatal (ue_mod_idP  >= oai_emulation.info.first_ue_local,
            "UE module id is too low (%u/%d)!\n",
            ue_mod_idP,
            oai_emulation.info.first_ue_local);
    }
#endif


  if (enb_flagP) {
454
455
      if (MBMS_flagP) {
          mbms_id_p = &rlc_mbms_lcid2service_session_id_eNB[enb_mod_idP][channel_idP];
456
457
458
459
460
461
462
463
          rb_id     = rlc_mbms_array_eNB[enb_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].rb_id;
          rlc_p     = (void*)&rlc_mbms_array_eNB[enb_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um;
          rlc_mode  = RLC_MODE_UM;
          if (rlc_mbms_array_eNB[enb_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um.allocation == FALSE) {
              return mac_rlc_status_resp;
          }
          //AssertFatal (rlc_mbms_array_eNB[enb_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um.allocation == TRUE ,
          //    "enB MBMS RLC UM not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, enb_mod_idP);
464
465
466
467
      } else {
          rb_id = lcid2rbid_eNB[enb_mod_idP][ue_mod_idP][channel_idP];
          if (rb_id >= NB_RB_MAX) {
              /*LOG_D(RLC, "[FRAME %05d][%s][RLC][MOD %u/%u] MAC STATUS IND TO NOT CONFIGURED BEARER lc id %u \n",
gauthier's avatar
gauthier committed
468
              frameP,
gauthier's avatar
gauthier committed
469
              (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
470
471
472
              enb_mod_idP,
              ue_mod_idP,
              channel_idP);*/
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
              return mac_rlc_status_resp;
          }
          rlc_mode = rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].mode;
          switch (rlc_mode) {
              case RLC_MODE_NONE:
                  //LOG_E (RLC, "enB RLC not configured rb id %u lcid %u enb id  %u ue id %u!\n", rb_id, channel_idP, enb_mod_idP, ue_mod_idP);
                  return mac_rlc_status_resp;
                  break;
              case RLC_MODE_AM:
                  rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.am;
                  break;
              case RLC_MODE_UM:
                  rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.um;
                  break;
              case RLC_MODE_TM:
                  rlc_p = (void*)&rlc_array_eNB[enb_mod_idP][ue_mod_idP][rb_id].rlc.tm;
                  break;
              default:
                  AssertFatal (0 , "enB RLC internal memory error rb id %u lcid %u enb id  %u ue id %u!\n", rb_id, channel_idP, enb_mod_idP, ue_mod_idP);
          }
493
494
      }
  } else {
495
496
      if (MBMS_flagP) {
          mbms_id_p = &rlc_mbms_lcid2service_session_id_ue[ue_mod_idP][channel_idP];
497
498
499
          rb_id     = rlc_mbms_array_ue[ue_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].rb_id;
          rlc_p     = (void*)&rlc_mbms_array_ue[ue_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um;
          rlc_mode  = RLC_MODE_UM;
500
501
502
503
504
505
          AssertFatal (rlc_mbms_array_ue[ue_mod_idP][mbms_id_p->service_id][mbms_id_p->session_id].um.allocation == TRUE ,
              "UE MBMS RLC UM not configured rb id %u lcid %u module %u!\n", rb_id, channel_idP, ue_mod_idP);
      } else {
          rb_id = lcid2rbid_ue[ue_mod_idP][channel_idP];
          if (rb_id >= NB_RB_MAX) {
              /*LOG_D(RLC, "[FRAME %05d][%s][RLC][MOD %u/%u] MAC STATUS IND TO NOT CONFIGURED BEARER lc id %u \n",
gauthier's avatar
gauthier committed
506
              frameP,
gauthier's avatar
gauthier committed
507
              (enb_flagP) ? "eNB" : "UE",
gauthier's avatar
gauthier committed
508
509
510
              enb_mod_idP,
              ue_mod_idP,
              channel_idP);*/
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
              return mac_rlc_status_resp;
          }
          rlc_mode = rlc_array_ue[ue_mod_idP][rb_id].mode;
          switch (rlc_mode) {
            case RLC_MODE_NONE:
                AssertFatal (0 , "UE RLC not configured rb id %u lcid %u enb id  %u ue id %u!\n", rb_id, channel_idP, enb_mod_idP, ue_mod_idP);
                return mac_rlc_status_resp;
                break;
            case RLC_MODE_AM:
                rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.am;
                break;
            case RLC_MODE_UM:
                rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.um;
                break;
            case RLC_MODE_TM:
                rlc_p = (void*)&rlc_array_ue[ue_mod_idP][rb_id].rlc.tm;
                break;
            default:
              AssertFatal (0 , "UE RLC internal memory error rb id %u lcid %u enb id  %u ue id %u!\n", rb_id, channel_idP, enb_mod_idP, ue_mod_idP);
          }
gauthier's avatar
gauthier committed
531
532
533
534
      }
  }

  switch (rlc_mode) {
gauthier's avatar
gauthier committed
535
      case RLC_MODE_NONE:
gauthier's avatar
gauthier committed
536
537
538
      //handle_event(WARNING,"FILE %s FONCTION mac_rlc_data_ind() LINE %s : no radio bearer configured :%d\n", __FILE__, __LINE__, channel_idP);
      break;

gauthier's avatar
gauthier committed
539
      case RLC_MODE_AM:
gauthier's avatar
gauthier committed
540
541
542
543
544
545
546
547
          status_resp = rlc_am_mac_status_indication((rlc_am_entity_t*)rlc_p, frameP, tb_sizeP, tx_status);
          mac_rlc_status_resp.bytes_in_buffer                 = status_resp.buffer_occupancy_in_bytes;
          mac_rlc_status_resp.head_sdu_creation_time          = status_resp.head_sdu_creation_time;
          mac_rlc_status_resp.head_sdu_remaining_size_to_send = status_resp.head_sdu_remaining_size_to_send;
          mac_rlc_status_resp.head_sdu_is_segmented           = status_resp.head_sdu_is_segmented;
          return mac_rlc_status_resp;
          break;

gauthier's avatar
gauthier committed
548
      case RLC_MODE_UM:
gauthier's avatar
gauthier committed
549
          status_resp = rlc_um_mac_status_indication((rlc_um_entity_t*)rlc_p, frameP, enb_flagP, tb_sizeP, tx_status);
gauthier's avatar
gauthier committed
550
551
552
553
554
555
556
557
          mac_rlc_status_resp.bytes_in_buffer                 = status_resp.buffer_occupancy_in_bytes;
          mac_rlc_status_resp.pdus_in_buffer                  = status_resp.buffer_occupancy_in_pdus;
          mac_rlc_status_resp.head_sdu_creation_time          = status_resp.head_sdu_creation_time;
          mac_rlc_status_resp.head_sdu_remaining_size_to_send = status_resp.head_sdu_remaining_size_to_send;
          mac_rlc_status_resp.head_sdu_is_segmented           = status_resp.head_sdu_is_segmented;
          return mac_rlc_status_resp;
          break;

gauthier's avatar
gauthier committed
558
      case RLC_MODE_TM:
gauthier's avatar
gauthier committed
559
560
561
562
563
564
565
          status_resp = rlc_tm_mac_status_indication((rlc_tm_entity_t*)rlc_p, frameP, tb_sizeP, tx_status);
          mac_rlc_status_resp.bytes_in_buffer = status_resp.buffer_occupancy_in_bytes;
          mac_rlc_status_resp.pdus_in_buffer  = status_resp.buffer_occupancy_in_pdus;
          return mac_rlc_status_resp;
          break;

      default:;
566
567
568
569
  }
  return mac_rlc_status_resp;
}