blob: 73570b3a7ad3f1d5d2cbf3f89789d6d87be5137d [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>
Vadim Yanitskiycb988942020-11-08 13:27:35 +070029 #include <osmocom/gsm/gsm48.h>
Max1187a772018-01-26 13:31:42 +010030}
Jacob Erlbeck53670862015-05-12 17:54:33 +020031
Jacob Erlbeckfea17f82015-08-16 21:36:32 +020032#define GPRS_UNDEFINED_IMSI "000"
33
Jacob Erlbeck17214bb2015-06-02 14:06:12 +020034GprsMsStorage::GprsMsStorage(BTS *bts) :
35 m_bts(bts)
Jacob Erlbeck53670862015-05-12 17:54:33 +020036{
37}
38
39GprsMsStorage::~GprsMsStorage()
40{
Jacob Erlbeckc362df22016-01-20 22:02:19 +010041 cleanup();
42}
43
44void GprsMsStorage::cleanup()
45{
Jacob Erlbeck53670862015-05-12 17:54:33 +020046 LListHead<GprsMs> *pos, *tmp;
47
48 llist_for_each_safe(pos, tmp, &m_list) {
49 GprsMs *ms = pos->entry();
50 ms->set_callback(NULL);
51 ms_idle(ms);
52 }
53}
54
55void GprsMsStorage::ms_idle(class GprsMs *ms)
56{
57 llist_del(&ms->list());
Jacob Erlbeckf5898a02015-11-27 19:05:13 +010058 if (m_bts)
Pau Espin Pedrol97e88fd2020-05-12 22:45:04 +020059 m_bts->stat_item_add(STAT_MS_PRESENT, -1);
Jacob Erlbeck53670862015-05-12 17:54:33 +020060 if (ms->is_idle())
61 delete ms;
62}
63
64void GprsMsStorage::ms_active(class GprsMs *ms)
65{
66 /* Nothing to do */
67}
68
69GprsMs *GprsMsStorage::get_ms(uint32_t tlli, uint32_t old_tlli, const char *imsi) const
70{
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020071 GprsMs *ms;
Jacob Erlbeck53670862015-05-12 17:54:33 +020072 LListHead<GprsMs> *pos;
73
Vadim Yanitskiycb988942020-11-08 13:27:35 +070074 if (tlli != GSM_RESERVED_TMSI || old_tlli != GSM_RESERVED_TMSI) {
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020075 llist_for_each(pos, &m_list) {
76 ms = pos->entry();
77 if (ms->check_tlli(tlli))
78 return ms;
79 if (ms->check_tlli(old_tlli))
80 return ms;
81 }
Jacob Erlbeck53670862015-05-12 17:54:33 +020082 }
83
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020084 /* not found by TLLI */
85
Jacob Erlbeckfea17f82015-08-16 21:36:32 +020086 if (imsi && imsi[0] && strcmp(imsi, GPRS_UNDEFINED_IMSI) != 0) {
Jacob Erlbeck7b9f8252015-05-21 11:07:53 +020087 llist_for_each(pos, &m_list) {
88 ms = pos->entry();
89 if (strcmp(imsi, ms->imsi()) == 0)
90 return ms;
91 }
92 }
93
94 return NULL;
Jacob Erlbeck53670862015-05-12 17:54:33 +020095}
96
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +020097GprsMs *GprsMsStorage::create_ms()
98{
99 GprsMs *ms;
100
Vadim Yanitskiycb988942020-11-08 13:27:35 +0700101 ms = new GprsMs(m_bts, GSM_RESERVED_TMSI);
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +0200102
103 ms->set_callback(this);
104 llist_add(&ms->list(), &m_list);
Jacob Erlbeckf5898a02015-11-27 19:05:13 +0100105 if (m_bts)
Pau Espin Pedrol97e88fd2020-05-12 22:45:04 +0200106 m_bts->stat_item_add(STAT_MS_PRESENT, 1);
Jacob Erlbeckcb1b4942015-06-19 10:59:58 +0200107
108 return ms;
109}