Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 1 | /* routines to track connections */ |
| 2 | /* |
| 3 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * (C) 2010 by On-Waves |
| 5 | * All Rights Reserved |
| 6 | * |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 7 | * This program is free software: you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation, either version 3 of the License, or |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 16 | * |
Holger Hans Peter Freyther | de56c22 | 2011-01-16 17:45:14 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "bsc_sccp.h" |
| 23 | #include "bsc_data.h" |
| 24 | |
Holger Hans Peter Freyther | 3594855 | 2010-09-30 17:30:50 +0800 | [diff] [blame] | 25 | #include <cellmgr_debug.h> |
| 26 | |
| 27 | #include <osmocore/talloc.h> |
| 28 | |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 29 | #include <string.h> |
| 30 | |
| 31 | extern struct bsc_data bsc; |
| 32 | |
Holger Hans Peter Freyther | 3594855 | 2010-09-30 17:30:50 +0800 | [diff] [blame] | 33 | struct active_sccp_con *find_con_by_dest_ref(struct sccp_source_reference *ref) |
| 34 | { |
| 35 | struct active_sccp_con *con; |
| 36 | |
| 37 | if (!ref) { |
| 38 | LOGP(DINP, LOGL_ERROR, "Dest Reference is NULL. No connection found.\n"); |
| 39 | return NULL; |
| 40 | } |
| 41 | |
| 42 | llist_for_each_entry(con, &bsc.sccp_connections, entry) { |
| 43 | if (memcmp(&con->dst_ref, ref, sizeof(*ref)) == 0) |
| 44 | return con; |
| 45 | } |
| 46 | |
| 47 | LOGP(DINP, LOGL_ERROR, "No connection fond with: 0x%x as dest\n", sccp_src_ref_to_int(ref)); |
| 48 | return NULL; |
| 49 | } |
| 50 | |
| 51 | |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 52 | struct active_sccp_con *find_con_by_src_ref(struct sccp_source_reference *src_ref) |
| 53 | { |
| 54 | struct active_sccp_con *con; |
| 55 | |
| 56 | /* it is quite normal to not find this one */ |
| 57 | if (!src_ref) |
| 58 | return NULL; |
| 59 | |
| 60 | llist_for_each_entry(con, &bsc.sccp_connections, entry) { |
| 61 | if (memcmp(&con->src_ref, src_ref, sizeof(*src_ref)) == 0) |
| 62 | return con; |
| 63 | } |
| 64 | |
| 65 | return NULL; |
| 66 | } |
| 67 | |
| 68 | struct active_sccp_con *find_con_by_src_dest_ref(struct sccp_source_reference *src_ref, |
| 69 | struct sccp_source_reference *dst_ref) |
| 70 | { |
| 71 | struct active_sccp_con *con; |
| 72 | |
| 73 | llist_for_each_entry(con, &bsc.sccp_connections, entry) { |
| 74 | if (memcmp(src_ref, &con->src_ref, sizeof(*src_ref)) == 0 && |
| 75 | memcmp(dst_ref, &con->dst_ref, sizeof(*dst_ref)) == 0) { |
| 76 | return con; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | return NULL; |
| 81 | } |
| 82 | |
| 83 | unsigned int sls_for_src_ref(struct sccp_source_reference *ref) |
| 84 | { |
| 85 | struct active_sccp_con *con; |
| 86 | |
| 87 | con = find_con_by_src_ref(ref); |
| 88 | if (!con) |
Holger Hans Peter Freyther | 346e1c4 | 2011-01-02 18:11:37 +0100 | [diff] [blame^] | 89 | return -1; |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 90 | return con->sls; |
| 91 | } |
| 92 | |
Holger Hans Peter Freyther | 3594855 | 2010-09-30 17:30:50 +0800 | [diff] [blame] | 93 | /* |
| 94 | * remove data |
| 95 | */ |
| 96 | void free_con(struct active_sccp_con *con) |
| 97 | { |
| 98 | llist_del(&con->entry); |
| 99 | bsc_del_timer(&con->rlc_timeout); |
| 100 | talloc_free(con); |
| 101 | } |
| 102 | |