blob: 04518c59ea88204510080819286e0113392e298b [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"
Max1187a772018-01-26 13:31:42 +010026
27extern "C" {
28 #include <osmocom/core/linuxlist.h>
29}
Jacob Erlbeck53670862015-05-12 17:54:33 +020030
Jacob Erlbeckfea17f82015-08-16 21:36:32 +020031#define GPRS_UNDEFINED_IMSI "000"
32
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020033GprsMsStorage::GprsMsStorage(BTS *bts) :
34 m_bts(bts)
Jacob Erlbeck53670862015-05-12 17:54:33 +020035{
36}
37
38GprsMsStorage::~GprsMsStorage()
39{
Jacob Erlbeckc362df22016-01-20 22:02:19 +010040 cleanup();
41}
42
43void GprsMsStorage::cleanup()
44{
Jacob Erlbeck53670862015-05-12 17:54:33 +020045 LListHead<GprsMs> *pos, *tmp;
46
47 llist_for_each_safe(pos, tmp, &m_list) {
48 GprsMs *ms = pos->entry();
49 ms->set_callback(NULL);
50 ms_idle(ms);
51 }
52}
53
54void GprsMsStorage::ms_idle(class GprsMs *ms)
55{
56 llist_del(&ms->list());
Jacob Erlbeckf5898a02015-11-27 19:05:13 +010057 if (m_bts)
58 m_bts->ms_present(m_bts->ms_present_get() - 1);
Jacob Erlbeck53670862015-05-12 17:54:33 +020059 if (ms->is_idle())
60 delete ms;
61}
62
63void GprsMsStorage::ms_active(class GprsMs *ms)
64{
65 /* Nothing to do */
66}
67
68GprsMs *GprsMsStorage::get_ms(uint32_t tlli, uint32_t old_tlli, const char *imsi) const
69{
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020070 GprsMs *ms;
Jacob Erlbeck53670862015-05-12 17:54:33 +020071 LListHead<GprsMs> *pos;
72
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020073 if (tlli || old_tlli) {
74 llist_for_each(pos, &m_list) {
75 ms = pos->entry();
76 if (ms->check_tlli(tlli))
77 return ms;
78 if (ms->check_tlli(old_tlli))
79 return ms;
80 }
Jacob Erlbeck53670862015-05-12 17:54:33 +020081 }
82
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020083 /* not found by TLLI */
84
Jacob Erlbeckfea17f82015-08-16 21:36:32 +020085 if (imsi && imsi[0] && strcmp(imsi, GPRS_UNDEFINED_IMSI) != 0) {
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020086 llist_for_each(pos, &m_list) {
87 ms = pos->entry();
88 if (strcmp(imsi, ms->imsi()) == 0)
89 return ms;
90 }
91 }
92
93 return NULL;
Jacob Erlbeck53670862015-05-12 17:54:33 +020094}
95
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +020096GprsMs *GprsMsStorage::create_ms()
97{
98 GprsMs *ms;
99
100 ms = new GprsMs(m_bts, 0);
101
102 ms->set_callback(this);
103 llist_add(&ms->list(), &m_list);
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100104 if (m_bts)
105 m_bts->ms_present(m_bts->ms_present_get() + 1);
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +0200106
107 return ms;
108}