blob: ea13c43bf33dc8f1ef7afbde2c8448eb5ae6d217 [file] [log] [blame]
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +08001/* 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 Freytherde56c222011-01-16 17:45:14 +01007 * 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 Freyther1cb634a2010-09-30 16:10:17 +080010 * (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 Freytherde56c222011-01-16 17:45:14 +010015 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080016 *
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +010017 * 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 Freyther1cb634a2010-09-30 16:10:17 +080019 *
20 */
21
22#include "bsc_sccp.h"
23#include "bsc_data.h"
24
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080025#include <cellmgr_debug.h>
26
27#include <osmocore/talloc.h>
28
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080029#include <string.h>
30
31extern struct bsc_data bsc;
32
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080033struct 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 Freyther1cb634a2010-09-30 16:10:17 +080052struct 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
68struct 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
83unsigned 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 Freyther346e1c42011-01-02 18:11:37 +010089 return -1;
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080090 return con->sls;
91}
92
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080093/*
94 * remove data
95 */
96void 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