Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 1 | /* 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 Erlbeck | f5898a0 | 2015-11-27 19:05:13 +0100 | [diff] [blame] | 25 | #include "bts.h" |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 26 | |
| 27 | extern "C" { |
| 28 | #include <osmocom/core/linuxlist.h> |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame^] | 29 | #include <osmocom/gsm/gsm48.h> |
Max | 1187a77 | 2018-01-26 13:31:42 +0100 | [diff] [blame] | 30 | } |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 31 | |
Jacob Erlbeck | fea17f8 | 2015-08-16 21:36:32 +0200 | [diff] [blame] | 32 | #define GPRS_UNDEFINED_IMSI "000" |
| 33 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 34 | GprsMsStorage::GprsMsStorage(BTS *bts) : |
| 35 | m_bts(bts) |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 36 | { |
| 37 | } |
| 38 | |
| 39 | GprsMsStorage::~GprsMsStorage() |
| 40 | { |
Jacob Erlbeck | c362df2 | 2016-01-20 22:02:19 +0100 | [diff] [blame] | 41 | cleanup(); |
| 42 | } |
| 43 | |
| 44 | void GprsMsStorage::cleanup() |
| 45 | { |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 46 | 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 | |
| 55 | void GprsMsStorage::ms_idle(class GprsMs *ms) |
| 56 | { |
| 57 | llist_del(&ms->list()); |
Jacob Erlbeck | f5898a0 | 2015-11-27 19:05:13 +0100 | [diff] [blame] | 58 | if (m_bts) |
Pau Espin Pedrol | 97e88fd | 2020-05-12 22:45:04 +0200 | [diff] [blame] | 59 | m_bts->stat_item_add(STAT_MS_PRESENT, -1); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 60 | if (ms->is_idle()) |
| 61 | delete ms; |
| 62 | } |
| 63 | |
| 64 | void GprsMsStorage::ms_active(class GprsMs *ms) |
| 65 | { |
| 66 | /* Nothing to do */ |
| 67 | } |
| 68 | |
| 69 | GprsMs *GprsMsStorage::get_ms(uint32_t tlli, uint32_t old_tlli, const char *imsi) const |
| 70 | { |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 71 | GprsMs *ms; |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 72 | LListHead<GprsMs> *pos; |
| 73 | |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame^] | 74 | if (tlli != GSM_RESERVED_TMSI || old_tlli != GSM_RESERVED_TMSI) { |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 75 | 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 Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 84 | /* not found by TLLI */ |
| 85 | |
Jacob Erlbeck | fea17f8 | 2015-08-16 21:36:32 +0200 | [diff] [blame] | 86 | if (imsi && imsi[0] && strcmp(imsi, GPRS_UNDEFINED_IMSI) != 0) { |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 87 | 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 Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 95 | } |
| 96 | |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 97 | GprsMs *GprsMsStorage::create_ms() |
| 98 | { |
| 99 | GprsMs *ms; |
| 100 | |
Vadim Yanitskiy | cb98894 | 2020-11-08 13:27:35 +0700 | [diff] [blame^] | 101 | ms = new GprsMs(m_bts, GSM_RESERVED_TMSI); |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 102 | |
| 103 | ms->set_callback(this); |
| 104 | llist_add(&ms->list(), &m_list); |
Jacob Erlbeck | f5898a0 | 2015-11-27 19:05:13 +0100 | [diff] [blame] | 105 | if (m_bts) |
Pau Espin Pedrol | 97e88fd | 2020-05-12 22:45:04 +0200 | [diff] [blame] | 106 | m_bts->stat_item_add(STAT_MS_PRESENT, 1); |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 107 | |
| 108 | return ms; |
| 109 | } |