blob: c588029b8a4b95941e31e4c6ca8f1606100ed532 [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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
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
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include "bsc_sccp.h"
24#include "bsc_data.h"
25
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080026#include <cellmgr_debug.h>
27
28#include <osmocore/talloc.h>
29
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080030#include <string.h>
31
32extern struct bsc_data bsc;
33
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080034struct active_sccp_con *find_con_by_dest_ref(struct sccp_source_reference *ref)
35{
36 struct active_sccp_con *con;
37
38 if (!ref) {
39 LOGP(DINP, LOGL_ERROR, "Dest Reference is NULL. No connection found.\n");
40 return NULL;
41 }
42
43 llist_for_each_entry(con, &bsc.sccp_connections, entry) {
44 if (memcmp(&con->dst_ref, ref, sizeof(*ref)) == 0)
45 return con;
46 }
47
48 LOGP(DINP, LOGL_ERROR, "No connection fond with: 0x%x as dest\n", sccp_src_ref_to_int(ref));
49 return NULL;
50}
51
52
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080053struct active_sccp_con *find_con_by_src_ref(struct sccp_source_reference *src_ref)
54{
55 struct active_sccp_con *con;
56
57 /* it is quite normal to not find this one */
58 if (!src_ref)
59 return NULL;
60
61 llist_for_each_entry(con, &bsc.sccp_connections, entry) {
62 if (memcmp(&con->src_ref, src_ref, sizeof(*src_ref)) == 0)
63 return con;
64 }
65
66 return NULL;
67}
68
69struct active_sccp_con *find_con_by_src_dest_ref(struct sccp_source_reference *src_ref,
70 struct sccp_source_reference *dst_ref)
71{
72 struct active_sccp_con *con;
73
74 llist_for_each_entry(con, &bsc.sccp_connections, entry) {
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
84unsigned int sls_for_src_ref(struct sccp_source_reference *ref)
85{
86 struct active_sccp_con *con;
87
88 con = find_con_by_src_ref(ref);
89 if (!con)
90 return 13;
91 return con->sls;
92}
93
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080094/*
95 * remove data
96 */
97void 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