blob: 6a7f3360cd388215efa0b9674657559451d19d17 [file] [log] [blame]
Jacob Erlbeck53670862015-05-12 17:54:33 +02001/* gprs_ms_storage.cpp
2 *
3 * Copyright (C) 2015 by Sysmocom s.f.m.c. GmbH
4 * Author: Jacob Erlbeck <jerlbeck@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21
22#include "gprs_ms_storage.h"
23
24#include "tbf.h"
Jacob Erlbeckf5898a02015-11-27 19:05:13 +010025#include "bts.h"
Jacob Erlbeck53670862015-05-12 17:54:33 +020026#include "gprs_debug.h"
27
Jacob Erlbeckfea17f82015-08-16 21:36:32 +020028#define GPRS_UNDEFINED_IMSI "000"
29
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020030GprsMsStorage::GprsMsStorage(BTS *bts) :
31 m_bts(bts)
Jacob Erlbeck53670862015-05-12 17:54:33 +020032{
33}
34
35GprsMsStorage::~GprsMsStorage()
36{
Jacob Erlbeckc362df22016-01-20 22:02:19 +010037 cleanup();
38}
39
40void GprsMsStorage::cleanup()
41{
Jacob Erlbeck53670862015-05-12 17:54:33 +020042 LListHead<GprsMs> *pos, *tmp;
43
44 llist_for_each_safe(pos, tmp, &m_list) {
45 GprsMs *ms = pos->entry();
46 ms->set_callback(NULL);
47 ms_idle(ms);
48 }
49}
50
51void GprsMsStorage::ms_idle(class GprsMs *ms)
52{
53 llist_del(&ms->list());
Jacob Erlbeckf5898a02015-11-27 19:05:13 +010054 if (m_bts)
55 m_bts->ms_present(m_bts->ms_present_get() - 1);
Jacob Erlbeck53670862015-05-12 17:54:33 +020056 if (ms->is_idle())
57 delete ms;
58}
59
60void GprsMsStorage::ms_active(class GprsMs *ms)
61{
62 /* Nothing to do */
63}
64
65GprsMs *GprsMsStorage::get_ms(uint32_t tlli, uint32_t old_tlli, const char *imsi) const
66{
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020067 GprsMs *ms;
Jacob Erlbeck53670862015-05-12 17:54:33 +020068 LListHead<GprsMs> *pos;
69
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020070 if (tlli || old_tlli) {
71 llist_for_each(pos, &m_list) {
72 ms = pos->entry();
73 if (ms->check_tlli(tlli))
74 return ms;
75 if (ms->check_tlli(old_tlli))
76 return ms;
77 }
Jacob Erlbeck53670862015-05-12 17:54:33 +020078 }
79
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020080 /* not found by TLLI */
81
Jacob Erlbeckfea17f82015-08-16 21:36:32 +020082 if (imsi && imsi[0] && strcmp(imsi, GPRS_UNDEFINED_IMSI) != 0) {
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020083 llist_for_each(pos, &m_list) {
84 ms = pos->entry();
85 if (strcmp(imsi, ms->imsi()) == 0)
86 return ms;
87 }
88 }
89
90 return NULL;
Jacob Erlbeck53670862015-05-12 17:54:33 +020091}
92
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +020093GprsMs *GprsMsStorage::create_ms()
94{
95 GprsMs *ms;
96
97 ms = new GprsMs(m_bts, 0);
98
99 ms->set_callback(this);
100 llist_add(&ms->list(), &m_list);
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100101 if (m_bts)
102 m_bts->ms_present(m_bts->ms_present_get() + 1);
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +0200103
104 return ms;
105}
106
Jacob Erlbeck0e50ce62015-05-21 16:58:22 +0200107GprsMs *GprsMsStorage::create_ms(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir)
Jacob Erlbeck53670862015-05-12 17:54:33 +0200108{
Jacob Erlbeck0e50ce62015-05-21 16:58:22 +0200109 GprsMs *ms = get_ms(tlli);
Jacob Erlbeck53670862015-05-12 17:54:33 +0200110
111 if (ms)
112 return ms;
113
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +0200114 ms = create_ms();
Jacob Erlbeck0e50ce62015-05-21 16:58:22 +0200115
116 if (dir == GPRS_RLCMAC_UL_TBF)
117 ms->set_tlli(tlli);
118 else
119 ms->confirm_tlli(tlli);
120
Jacob Erlbeck53670862015-05-12 17:54:33 +0200121 return ms;
122}