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