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" |
| 25 | #include "gprs_debug.h" |
| 26 | |
Jacob Erlbeck | fea17f8 | 2015-08-16 21:36:32 +0200 | [diff] [blame] | 27 | #define GPRS_UNDEFINED_IMSI "000" |
| 28 | |
Jacob Erlbeck | 17214bb | 2015-06-02 14:06:12 +0200 | [diff] [blame] | 29 | GprsMsStorage::GprsMsStorage(BTS *bts) : |
| 30 | m_bts(bts) |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 31 | { |
| 32 | } |
| 33 | |
| 34 | GprsMsStorage::~GprsMsStorage() |
| 35 | { |
| 36 | LListHead<GprsMs> *pos, *tmp; |
| 37 | |
| 38 | llist_for_each_safe(pos, tmp, &m_list) { |
| 39 | GprsMs *ms = pos->entry(); |
| 40 | ms->set_callback(NULL); |
| 41 | ms_idle(ms); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | void GprsMsStorage::ms_idle(class GprsMs *ms) |
| 46 | { |
| 47 | llist_del(&ms->list()); |
| 48 | if (ms->is_idle()) |
| 49 | delete ms; |
| 50 | } |
| 51 | |
| 52 | void GprsMsStorage::ms_active(class GprsMs *ms) |
| 53 | { |
| 54 | /* Nothing to do */ |
| 55 | } |
| 56 | |
| 57 | GprsMs *GprsMsStorage::get_ms(uint32_t tlli, uint32_t old_tlli, const char *imsi) const |
| 58 | { |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 59 | GprsMs *ms; |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 60 | LListHead<GprsMs> *pos; |
| 61 | |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 62 | if (tlli || old_tlli) { |
| 63 | llist_for_each(pos, &m_list) { |
| 64 | ms = pos->entry(); |
| 65 | if (ms->check_tlli(tlli)) |
| 66 | return ms; |
| 67 | if (ms->check_tlli(old_tlli)) |
| 68 | return ms; |
| 69 | } |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 70 | } |
| 71 | |
Jacob Erlbeck | 7b9f825 | 2015-05-21 11:07:53 +0200 | [diff] [blame] | 72 | /* not found by TLLI */ |
| 73 | |
Jacob Erlbeck | fea17f8 | 2015-08-16 21:36:32 +0200 | [diff] [blame] | 74 | if (imsi && imsi[0] && strcmp(imsi, GPRS_UNDEFINED_IMSI) != 0) { |
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 (strcmp(imsi, ms->imsi()) == 0) |
| 78 | return ms; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | return NULL; |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 83 | } |
| 84 | |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 85 | GprsMs *GprsMsStorage::create_ms() |
| 86 | { |
| 87 | GprsMs *ms; |
| 88 | |
| 89 | ms = new GprsMs(m_bts, 0); |
| 90 | |
| 91 | ms->set_callback(this); |
| 92 | llist_add(&ms->list(), &m_list); |
| 93 | |
| 94 | return ms; |
| 95 | } |
| 96 | |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 97 | GprsMs *GprsMsStorage::create_ms(uint32_t tlli, enum gprs_rlcmac_tbf_direction dir) |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 98 | { |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 99 | GprsMs *ms = get_ms(tlli); |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 100 | |
| 101 | if (ms) |
| 102 | return ms; |
| 103 | |
Jacob Erlbeck | cb1b494 | 2015-06-19 10:59:58 +0200 | [diff] [blame] | 104 | ms = create_ms(); |
Jacob Erlbeck | 0e50ce6 | 2015-05-21 16:58:22 +0200 | [diff] [blame] | 105 | |
| 106 | if (dir == GPRS_RLCMAC_UL_TBF) |
| 107 | ms->set_tlli(tlli); |
| 108 | else |
| 109 | ms->confirm_tlli(tlli); |
| 110 | |
Jacob Erlbeck | 5367086 | 2015-05-12 17:54:33 +0200 | [diff] [blame] | 111 | return ms; |
| 112 | } |