blob: 710f850a5e5675b6ef1c93a6c4a78eecc185e9ca [file] [log] [blame]
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +08001/* routines to track connections */
2/*
Holger Hans Peter Freyther84ec8712011-02-15 20:01:47 +01003 * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010-2011 by On-Waves
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +08005 * 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>
Holger Hans Peter Freythera7bc3aa2011-02-16 16:12:07 +010026#include <ss7_application.h>
27#include <ss7_application.h>
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080028
Harald Welteff397ed2011-05-08 10:29:23 +020029#include <osmocom/core/talloc.h>
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080030
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080031#include <string.h>
32
Holger Hans Peter Freythera7bc3aa2011-02-16 16:12:07 +010033struct active_sccp_con *find_con_by_dest_ref(struct ss7_application *fw, struct sccp_source_reference *ref)
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080034{
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 Freythere86c02e2011-02-10 15:32:14 +010042 llist_for_each_entry(con, &fw->sccp_connections, entry) {
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +080043 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 Freythera7bc3aa2011-02-16 16:12:07 +010052struct active_sccp_con *find_con_by_src_ref(struct ss7_application *fw, struct sccp_source_reference *src_ref)
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080053{
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 Freythere86c02e2011-02-10 15:32:14 +010060 llist_for_each_entry(con, &fw->sccp_connections, entry) {
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080061 if (memcmp(&con->src_ref, src_ref, sizeof(*src_ref)) == 0)
62 return con;
63 }
64
65 return NULL;
66}
67
Holger Hans Peter Freythera7bc3aa2011-02-16 16:12:07 +010068struct active_sccp_con *find_con_by_src_dest_ref(struct ss7_application *fw,
Holger Hans Peter Freythere86c02e2011-02-10 15:32:14 +010069 struct sccp_source_reference *src_ref,
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080070 struct sccp_source_reference *dst_ref)
71{
72 struct active_sccp_con *con;
73
Holger Hans Peter Freythere86c02e2011-02-10 15:32:14 +010074 llist_for_each_entry(con, &fw->sccp_connections, entry) {
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080075 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 Freythera7bc3aa2011-02-16 16:12:07 +010084unsigned int sls_for_src_ref(struct ss7_application *fw, struct sccp_source_reference *ref)
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080085{
86 struct active_sccp_con *con;
87
Holger Hans Peter Freythere86c02e2011-02-10 15:32:14 +010088 con = find_con_by_src_ref(fw, ref);
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080089 if (!con)
Holger Hans Peter Freyther346e1c42011-01-02 18:11:37 +010090 return -1;
Holger Hans Peter Freyther1cb634a2010-09-30 16:10:17 +080091 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);
Harald Welteff397ed2011-05-08 10:29:23 +0200100 osmo_timer_del(&con->rlc_timeout);
Holger Hans Peter Freyther35948552010-09-30 17:30:50 +0800101 talloc_free(con);
102}
103