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> |
| 29 | } |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 30 | |
Jacob Erlbeck | fea17f8 | 2015-08-16 21:36:32 +0200 | [diff] [blame] | 31 | #define GPRS_UNDEFINED_IMSI "000" |
| 32 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 33 | GprsMsStorage::GprsMsStorage(BTS *bts) : |
| 34 | m_bts(bts) |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 35 | { |
| 36 | } |
| 37 | |
| 38 | GprsMsStorage::~GprsMsStorage() |
| 39 | { |
Jacob Erlbeck | c362df2 | 2016-01-20 22:02:19 +0100 | [diff] [blame] | 40 | cleanup(); |
| 41 | } |
| 42 | |
| 43 | void GprsMsStorage::cleanup() |
| 44 | { |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 45 | 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 | |
| 54 | void GprsMsStorage::ms_idle(class GprsMs *ms) |
| 55 | { |
| 56 | llist_del(&ms->list()); |
Jacob Erlbeck | f5898a0 | 2015-11-27 19:05:13 +0100 | [diff] [blame] | 57 | if (m_bts) |
Pau Espin Pedrol | 97e88fd | 2020-05-12 22:45:04 +0200 | [diff] [blame] | 58 | m_bts->stat_item_add(STAT_MS_PRESENT, -1); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 59 | if (ms->is_idle()) |
| 60 | delete ms; |
| 61 | } |
| 62 | |
| 63 | void GprsMsStorage::ms_active(class GprsMs *ms) |
| 64 | { |
| 65 | /* Nothing to do */ |
| 66 | } |
| 67 | |
| 68 | GprsMs *GprsMsStorage::get_ms(uint32_t tlli, uint32_t old_tlli, const char *imsi) const |
| 69 | { |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 70 | GprsMs *ms; |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 71 | LListHead<GprsMs> *pos; |
| 72 | |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 73 | 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 Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 83 | /* not found by TLLI */ |
| 84 | |
Jacob Erlbeck | fea17f8 | 2015-08-16 21:36:32 +0200 | [diff] [blame] | 85 | if (imsi && imsi[0] && strcmp(imsi, GPRS_UNDEFINED_IMSI) != 0) { |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 86 | 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 Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 96 | GprsMs *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 Erlbeck | f5898a0 | 2015-11-27 19:05:13 +0100 | [diff] [blame] | 104 | if (m_bts) |
Pau Espin Pedrol | 97e88fd | 2020-05-12 22:45:04 +0200 | [diff] [blame] | 105 | m_bts->stat_item_add(STAT_MS_PRESENT, 1); |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 106 | |
| 107 | return ms; |
| 108 | } |