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