Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 1 | /* routines to track connections */ |
| 2 | /* |
Holger Hans Peter Freyther | 84ec871 | 2011-02-15 20:01:47 +0100 | [diff] [blame] | 3 | * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 4 | * (C) 2010-2011 by On-Waves |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 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> |
Holger Hans Peter Freyther | a7bc3aa | 2011-02-16 16:12:07 +0100 | [diff] [blame] | 26 | #include <ss7_application.h> |
| 27 | #include <ss7_application.h> |
Holger Hans Peter Freyther | 3594855 | 2010-09-30 17:30:50 +0800 | [diff] [blame] | 28 | |
| 29 | #include <osmocore/talloc.h> |
| 30 | |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 31 | #include <string.h> |
| 32 | |
Holger Hans Peter Freyther | a7bc3aa | 2011-02-16 16:12:07 +0100 | [diff] [blame] | 33 | struct active_sccp_con *find_con_by_dest_ref(struct ss7_application *fw, struct sccp_source_reference *ref) |
Holger Hans Peter Freyther | 3594855 | 2010-09-30 17:30:50 +0800 | [diff] [blame] | 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 | |
Holger Hans Peter Freyther | e86c02e | 2011-02-10 15:32:14 +0100 | [diff] [blame] | 42 | llist_for_each_entry(con, &fw->sccp_connections, entry) { |
Holger Hans Peter Freyther | 3594855 | 2010-09-30 17:30:50 +0800 | [diff] [blame] | 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 | a7bc3aa | 2011-02-16 16:12:07 +0100 | [diff] [blame] | 52 | struct active_sccp_con *find_con_by_src_ref(struct ss7_application *fw, struct sccp_source_reference *src_ref) |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 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 | |
Holger Hans Peter Freyther | e86c02e | 2011-02-10 15:32:14 +0100 | [diff] [blame] | 60 | llist_for_each_entry(con, &fw->sccp_connections, entry) { |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 61 | if (memcmp(&con->src_ref, src_ref, sizeof(*src_ref)) == 0) |
| 62 | return con; |
| 63 | } |
| 64 | |
| 65 | return NULL; |
| 66 | } |
| 67 | |
Holger Hans Peter Freyther | a7bc3aa | 2011-02-16 16:12:07 +0100 | [diff] [blame] | 68 | struct active_sccp_con *find_con_by_src_dest_ref(struct ss7_application *fw, |
Holger Hans Peter Freyther | e86c02e | 2011-02-10 15:32:14 +0100 | [diff] [blame] | 69 | struct sccp_source_reference *src_ref, |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 70 | struct sccp_source_reference *dst_ref) |
| 71 | { |
| 72 | struct active_sccp_con *con; |
| 73 | |
Holger Hans Peter Freyther | e86c02e | 2011-02-10 15:32:14 +0100 | [diff] [blame] | 74 | llist_for_each_entry(con, &fw->sccp_connections, entry) { |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 75 | if (memcmp(src_ref, &con->src_ref, sizeof(*src_ref)) == 0 && |
| 76 | memcmp(dst_ref, &con->dst_ref, sizeof(*dst_ref)) == 0) { |
| 77 | return con; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return NULL; |
| 82 | } |
| 83 | |
Holger Hans Peter Freyther | a7bc3aa | 2011-02-16 16:12:07 +0100 | [diff] [blame] | 84 | unsigned int sls_for_src_ref(struct ss7_application *fw, struct sccp_source_reference *ref) |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 85 | { |
| 86 | struct active_sccp_con *con; |
| 87 | |
Holger Hans Peter Freyther | e86c02e | 2011-02-10 15:32:14 +0100 | [diff] [blame] | 88 | con = find_con_by_src_ref(fw, ref); |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 89 | if (!con) |
Holger Hans Peter Freyther | 346e1c4 | 2011-01-02 18:11:37 +0100 | [diff] [blame] | 90 | return -1; |
Holger Hans Peter Freyther | 1cb634a | 2010-09-30 16:10:17 +0800 | [diff] [blame] | 91 | return con->sls; |
| 92 | } |
| 93 | |
Holger Hans Peter Freyther | 3594855 | 2010-09-30 17:30:50 +0800 | [diff] [blame] | 94 | /* |
| 95 | * remove data |
| 96 | */ |
| 97 | void free_con(struct active_sccp_con *con) |
| 98 | { |
| 99 | llist_del(&con->entry); |
| 100 | bsc_del_timer(&con->rlc_timeout); |
| 101 | talloc_free(con); |
| 102 | } |
| 103 | |