blob: df3841e6b60c252b6963f04bb46566c2e8c79c84 [file] [log] [blame]
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +08001/*
Holger Hans Peter Freythere1880102011-04-23 23:31:31 +02002 * (C) 2010-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
3 * (C) 2010-2011 by On-Waves
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +08004 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +08009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +080015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +080018 *
19 */
20
21#ifndef BSC_NAT_H
22#define BSC_NAT_H
23
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +080024#include "mgcp.h"
25
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +010026
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010027#include <osmocom/core/select.h>
28#include <osmocom/core/msgb.h>
29#include <osmocom/core/msgfile.h>
30#include <osmocom/core/timer.h>
31#include <osmocom/core/write_queue.h>
32#include <osmocom/core/rate_ctr.h>
33#include <osmocom/core/statistics.h>
34#include <osmocom/gsm/protocol/gsm_04_08.h>
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +080035
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +020036#include <regex.h>
37
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +010038#define DIR_BSC 1
39#define DIR_MSC 2
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080040
Holger Hans Peter Freyther474698a2011-05-02 16:50:36 +020041#define PAGIN_GROUP_UNASSIGNED -1
42
Holger Hans Peter Freyther3d387422010-10-16 16:35:00 +020043struct sccp_source_reference;
Holger Hans Peter Freytherc2b31ed2010-07-31 05:17:17 +080044struct sccp_connections;
45struct bsc_nat_parsed;
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +080046struct bsc_nat;
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +020047struct bsc_nat_ussd_con;
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +080048
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +080049enum {
50 NAT_CON_TYPE_NONE,
51 NAT_CON_TYPE_LU,
52 NAT_CON_TYPE_CM_SERV_REQ,
53 NAT_CON_TYPE_PAG_RESP,
Holger Hans Peter Freyther74dc3032010-09-29 02:47:29 +080054 NAT_CON_TYPE_SSA,
Holger Hans Peter Freytherb71c23b2010-05-16 20:43:52 +080055 NAT_CON_TYPE_LOCAL_REJECT,
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +080056 NAT_CON_TYPE_OTHER,
57};
58
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +080059/*
Holger Hans Peter Freythere5d32492011-04-16 16:02:59 +020060 * Is this terminated to the MSC, to the local machine (release
61 * handling for IMSI filtering) or to a USSD provider?
62 */
63enum {
64 NAT_CON_END_MSC,
65 NAT_CON_END_LOCAL,
66 NAT_CON_END_USSD,
67};
68
69/*
Daniel Willmanna86bc392011-02-18 14:32:56 +010070 * Pending command entry
71 */
72struct bsc_cmd_list {
73 struct llist_head list_entry;
74
75 struct osmo_timer_list timeout;
76
77 /* The NATed ID used on the bsc_con*/
78 int nat_id;
79
80 /* The control connection from which the command originated */
81 struct ctrl_connection *ccon;
82
83 /* The command from the control connection */
84 struct ctrl_cmd *cmd;
85};
86
87/*
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +010088 * Per BSC data structure
89 */
90struct bsc_connection {
91 struct llist_head list_entry;
92
93 /* do we know anything about this BSC? */
94 int authenticated;
95
96 /* the fd we use to communicate */
Pablo Neira Ayusoe1273b12011-05-06 12:09:47 +020097 struct osmo_wqueue write_queue;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080098
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +020099 /* the BSS associated */
100 struct bsc_config *cfg;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800101
102 /* a timeout node */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200103 struct osmo_timer_list id_timeout;
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800104
Holger Hans Peter Freyther906c15e2010-05-02 19:28:59 +0800105 /* pong timeout */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200106 struct osmo_timer_list ping_timeout;
107 struct osmo_timer_list pong_timeout;
Holger Hans Peter Freyther906c15e2010-05-02 19:28:59 +0800108
Holger Hans Peter Freyther45fd07d2010-08-28 18:22:14 +0800109 /* mgcp related code */
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100110 char *_endpoint_status;
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100111 int number_multiplexes;
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100112 int max_endpoints;
Holger Hans Peter Freyther45fd07d2010-08-28 18:22:14 +0800113 int last_endpoint;
114
Daniel Willmanna86bc392011-02-18 14:32:56 +0100115 /* track the pending commands for this BSC */
116 struct llist_head cmd_pending;
117 int last_id;
118
Holger Hans Peter Freytheraa698242010-06-15 18:46:19 +0800119 /* a back pointer */
120 struct bsc_nat *nat;
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +0100121};
122
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800123/**
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200124 * Stats per BSC
125 */
126struct bsc_config_stats {
Holger Hans Peter Freytherb2c38eb2010-06-17 18:16:00 +0800127 struct rate_ctr_group *ctrg;
128};
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200129
Holger Hans Peter Freytherb2c38eb2010-06-17 18:16:00 +0800130enum bsc_cfg_ctr {
131 BCFG_CTR_SCCP_CONN,
132 BCFG_CTR_SCCP_CALLS,
133 BCFG_CTR_NET_RECONN,
Holger Hans Peter Freyther8330c1c2010-06-17 18:29:42 +0800134 BCFG_CTR_DROPPED_SCCP,
135 BCFG_CTR_DROPPED_CALLS,
Holger Hans Peter Freytheree884962010-09-25 17:58:22 +0800136 BCFG_CTR_REJECTED_CR,
137 BCFG_CTR_REJECTED_MSG,
138 BCFG_CTR_ILL_PACKET,
Holger Hans Peter Freyther463dc622010-10-03 19:41:42 +0800139 BCFG_CTR_CON_TYPE_LU,
140 BCFG_CTR_CON_CMSERV_RQ,
141 BCFG_CTR_CON_PAG_RESP,
Holger Hans Peter Freyther74dc3032010-09-29 02:47:29 +0800142 BCFG_CTR_CON_SSA,
Holger Hans Peter Freyther463dc622010-10-03 19:41:42 +0800143 BCFG_CTR_CON_OTHER,
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200144};
145
146/**
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800147 * One BSC entry in the config
148 */
149struct bsc_config {
150 struct llist_head entry;
151
152 char *token;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800153 int nr;
154
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800155 char *description;
156
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200157 /* imsi white and blacklist */
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800158 char *acc_lst_name;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200159
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800160 int forbid_paging;
Holger Hans Peter Freyther474698a2011-05-02 16:50:36 +0200161 int paging_group;
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800162
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100163 /* audio handling */
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100164 int max_endpoints;
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100165
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200166 /* backpointer */
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800167 struct bsc_nat *nat;
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200168
169 struct bsc_config_stats stats;
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800170
171 struct llist_head lac_list;
172};
173
174struct bsc_lac_entry {
175 struct llist_head entry;
176 uint16_t lac;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800177};
178
Holger Hans Peter Freyther474698a2011-05-02 16:50:36 +0200179struct bsc_nat_paging_group {
180 struct llist_head entry;
181
182 /* list of lac entries */
183 struct llist_head lists;
184 int nr;
185};
186
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800187/**
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200188 * BSCs point of view of endpoints
189 */
190struct bsc_endpoint {
Holger Hans Peter Freyther5b2726e2010-08-06 09:05:05 +0800191 /* the operation that is carried out */
192 int transaction_state;
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200193 /* the pending transaction id */
194 char *transaction_id;
195 /* the bsc we are talking to */
196 struct bsc_connection *bsc;
197};
198
199/**
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200200 * Statistic for the nat.
201 */
202struct bsc_nat_statistics {
203 struct {
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200204 struct osmo_counter *conn;
205 struct osmo_counter *calls;
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200206 } sccp;
207
208 struct {
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200209 struct osmo_counter *reconn;
210 struct osmo_counter *auth_fail;
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200211 } bsc;
212
213 struct {
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200214 struct osmo_counter *reconn;
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200215 } msc;
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200216
217 struct {
Pablo Neira Ayusodfb342c2011-05-06 12:13:10 +0200218 struct osmo_counter *reconn;
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200219 } ussd;
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200220};
221
Holger Hans Peter Freyther2f1a9842010-09-25 06:14:52 +0800222enum bsc_nat_acc_ctr {
223 ACC_LIST_BSC_FILTER,
224 ACC_LIST_NAT_FILTER,
225};
226
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800227struct bsc_nat_acc_lst {
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800228 struct llist_head list;
229
Holger Hans Peter Freyther2f1a9842010-09-25 06:14:52 +0800230 /* counter */
231 struct rate_ctr_group *stats;
232
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800233 /* the name of the list */
234 const char *name;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800235 struct llist_head fltr_list;
236};
237
238struct bsc_nat_acc_lst_entry {
239 struct llist_head list;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800240
241 /* the filter */
242 char *imsi_allow;
243 regex_t imsi_allow_re;
244 char *imsi_deny;
245 regex_t imsi_deny_re;
246};
247
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200248/**
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800249 * the structure of the "nat" network
250 */
251struct bsc_nat {
252 /* active SCCP connections that need patching */
253 struct llist_head sccp_connections;
254
255 /* active BSC connections that need patching */
256 struct llist_head bsc_connections;
257
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800258 /* access lists */
259 struct llist_head access_lists;
260
Holger Hans Peter Freyther474698a2011-05-02 16:50:36 +0200261 /* paging groups */
262 struct llist_head paging_groups;
263
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800264 /* known BSC's */
265 struct llist_head bsc_configs;
266 int num_bsc;
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800267 int bsc_ip_dscp;
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800268
269 /* MGCP config */
270 struct mgcp_config *mgcp_cfg;
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800271 uint8_t mgcp_msg[4096];
Holger Hans Peter Freyther8d200652010-04-04 18:09:10 +0200272 int mgcp_length;
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200273
Holger Hans Peter Freytherb7527612010-04-07 11:20:36 +0200274 /* msc things */
Holger Hans Peter Freythere1880102011-04-23 23:31:31 +0200275 struct llist_head dests;
276 struct bsc_msc_dest *main_dest;
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800277 struct bsc_msc_connection *msc_con;
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800278 char *token;
Holger Hans Peter Freytherb7527612010-04-07 11:20:36 +0200279
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800280 /* timeouts */
281 int auth_timeout;
282 int ping_timeout;
283 int pong_timeout;
284
Holger Hans Peter Freythera0df82d2010-04-01 08:21:33 +0200285 struct bsc_endpoint *bsc_endpoints;
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200286
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200287 /* filter */
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800288 char *acc_lst_name;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200289
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200290 /* number rewriting */
291 char *num_rewr_name;
Holger Hans Peter Freytherad75eab2011-05-27 12:38:58 +0200292 struct llist_head num_rewr;
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200293
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200294 char *smsc_rewr_name;
295 struct llist_head smsc_rewr;
Holger Hans Peter Freytheracc40312011-05-27 19:21:24 +0200296 char *tpdest_match_name;
297 struct llist_head tpdest_match;
Holger Hans Peter Freyther68368dd2012-01-10 22:39:07 +0100298 char *sms_clear_tp_srr_name;
299 struct llist_head sms_clear_tp_srr;
Holger Hans Peter Freyther8e60f622012-01-18 20:00:28 +0100300 char *sms_num_rewr_name;
301 struct llist_head sms_num_rewr;
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200302
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200303 /* USSD messages we want to match */
304 char *ussd_lst_name;
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200305 char *ussd_query;
Holger Hans Peter Freythera18b1162011-04-01 17:32:21 +0200306 regex_t ussd_query_re;
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200307 char *ussd_token;
308 char *ussd_local;
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200309 struct osmo_fd ussd_listen;
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200310 struct bsc_nat_ussd_con *ussd_con;
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200311
Holger Hans Peter Freytherde2b8602011-04-23 23:55:14 +0200312 /* for maintainenance */
313 int blocked;
314
Holger Hans Peter Freytherd4702862010-04-12 12:17:09 +0200315 /* statistics */
316 struct bsc_nat_statistics stats;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800317};
318
Holger Hans Peter Freyther91b9a452011-04-16 17:01:47 +0200319struct bsc_nat_ussd_con {
Pablo Neira Ayusoe1273b12011-05-06 12:09:47 +0200320 struct osmo_wqueue queue;
Holger Hans Peter Freyther91b9a452011-04-16 17:01:47 +0200321 struct bsc_nat *nat;
322 int authorized;
323
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200324 struct osmo_timer_list auth_timeout;
Holger Hans Peter Freyther91b9a452011-04-16 17:01:47 +0200325};
326
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800327/* create and init the structures */
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800328struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800329struct bsc_config *bsc_config_num(struct bsc_nat *nat, int num);
Holger Hans Peter Freyther9212d9d2011-02-27 11:18:41 +0100330void bsc_config_free(struct bsc_config *);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800331void bsc_config_add_lac(struct bsc_config *cfg, int lac);
332void bsc_config_del_lac(struct bsc_config *cfg, int lac);
333int bsc_config_handles_lac(struct bsc_config *cfg, int lac);
334
Holger Hans Peter Freytherdcf8a7d2010-06-15 18:48:01 +0800335struct bsc_nat *bsc_nat_alloc(void);
336struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800337void bsc_nat_set_msc_ip(struct bsc_nat *bsc, const char *ip);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800338
Holger Hans Peter Freyther23fe7be2010-03-30 10:45:48 +0200339void sccp_connection_destroy(struct sccp_connections *);
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800340void bsc_close_connection(struct bsc_connection *);
Holger Hans Peter Freyther9f8f3d02010-02-07 13:08:09 +0100341
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800342const char *bsc_con_type_to_string(int type);
343
Holger Hans Peter Freyther0b8f69d2010-06-15 18:45:38 +0800344/**
345 * parse the given message into the above structure
346 */
347struct bsc_nat_parsed *bsc_nat_parse(struct msgb *msg);
348
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800349/**
350 * filter based on IP Access header in both directions
351 */
Holger Hans Peter Freyther1d6fb182010-01-30 11:53:30 +0100352int bsc_nat_filter_ipa(int direction, struct msgb *msg, struct bsc_nat_parsed *parsed);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800353int bsc_nat_vty_init(struct bsc_nat *nat);
Holger Hans Peter Freyther1ffe98c2011-05-02 16:20:32 +0200354int bsc_nat_find_paging(struct msgb *msg, const uint8_t **,int *len);
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800355
Holger Hans Peter Freyther0ab6bab2010-06-15 18:47:49 +0800356/**
Holger Hans Peter Freytherb4af5c92010-05-14 03:39:56 +0800357 * Content filtering.
358 */
Holger Hans Peter Freyther19c0a842010-05-16 02:00:40 +0800359int bsc_nat_filter_sccp_cr(struct bsc_connection *bsc, struct msgb *msg,
Holger Hans Peter Freyther749497e2010-09-29 01:19:42 +0800360 struct bsc_nat_parsed *, int *con_type, char **imsi);
Holger Hans Peter Freyther74e0a1b2010-09-15 01:11:08 +0800361int bsc_nat_filter_dt(struct bsc_connection *bsc, struct msgb *msg,
362 struct sccp_connections *con, struct bsc_nat_parsed *parsed);
Holger Hans Peter Freytherb4af5c92010-05-14 03:39:56 +0800363
364/**
Holger Hans Peter Freyther0ab6bab2010-06-15 18:47:49 +0800365 * SCCP patching and handling
366 */
Holger Hans Peter Freytherfa20c942010-05-16 16:51:31 +0800367struct sccp_connections *create_sccp_src_ref(struct bsc_connection *bsc, struct bsc_nat_parsed *parsed);
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800368int update_sccp_src_ref(struct sccp_connections *sccp, struct bsc_nat_parsed *parsed);
Holger Hans Peter Freyther0ab6bab2010-06-15 18:47:49 +0800369void remove_sccp_src_ref(struct bsc_connection *bsc, struct msgb *msg, struct bsc_nat_parsed *parsed);
Holger Hans Peter Freyther49c7fb52010-06-15 18:48:55 +0800370struct sccp_connections *patch_sccp_src_ref_to_bsc(struct msgb *, struct bsc_nat_parsed *, struct bsc_nat *);
Holger Hans Peter Freytherb5513ca2010-04-21 18:56:12 +0800371struct sccp_connections *patch_sccp_src_ref_to_msc(struct msgb *, struct bsc_nat_parsed *, struct bsc_connection *);
Holger Hans Peter Freyther3d387422010-10-16 16:35:00 +0200372struct sccp_connections *bsc_nat_find_con_by_bsc(struct bsc_nat *, struct sccp_source_reference *);
Holger Hans Peter Freyther0ab6bab2010-06-15 18:47:49 +0800373
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800374/**
375 * MGCP/Audio handling
376 */
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100377int bsc_mgcp_nr_multiplexes(int max_endpoints);
Holger Hans Peter Freytherdbd16fe2010-07-23 19:08:55 +0800378int bsc_write_mgcp(struct bsc_connection *bsc, const uint8_t *data, unsigned int length);
Holger Hans Peter Freyther45fd07d2010-08-28 18:22:14 +0800379int bsc_mgcp_assign_patch(struct sccp_connections *, struct msgb *msg);
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800380void bsc_mgcp_init(struct sccp_connections *);
381void bsc_mgcp_dlcx(struct sccp_connections *);
Holger Hans Peter Freyther241e1302010-03-31 09:16:56 +0200382void bsc_mgcp_free_endpoints(struct bsc_nat *nat);
Holger Hans Peter Freyther7b7eef62010-04-22 12:08:17 +0800383int bsc_mgcp_nat_init(struct bsc_nat *nat);
Holger Hans Peter Freyther465313e2010-06-15 18:49:53 +0800384
Holger Hans Peter Freyther08a1b162010-04-18 02:26:16 +0800385struct sccp_connections *bsc_mgcp_find_con(struct bsc_nat *, int endpoint_number);
Holger Hans Peter Freytherf7c86c52010-08-30 13:44:32 +0800386struct msgb *bsc_mgcp_rewrite(char *input, int length, int endp, const char *ip, int port);
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200387void bsc_mgcp_forward(struct bsc_connection *bsc, struct msgb *msg);
388
Holger Hans Peter Freyther26a43892010-04-05 23:09:27 +0200389void bsc_mgcp_clear_endpoints_for(struct bsc_connection *bsc);
Holger Hans Peter Freyther3c3bce12010-04-01 10:16:28 +0200390int bsc_mgcp_parse_response(const char *str, int *code, char transaction[60]);
Holger Hans Peter Freyther46340132010-08-06 08:26:54 +0800391uint32_t bsc_mgcp_extract_ci(const char *resp);
Holger Hans Peter Freytherfc9bd232010-04-01 03:55:27 +0200392
Holger Hans Peter Freyther2896df72010-04-08 10:24:57 +0200393
394int bsc_write(struct bsc_connection *bsc, struct msgb *msg, int id);
Pablo Neira Ayusoe1273b12011-05-06 12:09:47 +0200395int bsc_do_write(struct osmo_wqueue *queue, struct msgb *msg, int id);
396int bsc_write_msg(struct osmo_wqueue *queue, struct msgb *msg);
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200397int bsc_write_cb(struct osmo_fd *bfd, struct msgb *msg);
Holger Hans Peter Freyther2896df72010-04-08 10:24:57 +0200398
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800399/* IMSI allow/deny handling */
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800400struct bsc_nat_acc_lst *bsc_nat_acc_lst_find(struct bsc_nat *nat, const char *name);
401struct bsc_nat_acc_lst *bsc_nat_acc_lst_get(struct bsc_nat *nat, const char *name);
402void bsc_nat_acc_lst_delete(struct bsc_nat_acc_lst *lst);
Holger Hans Peter Freyther12dc89a2010-05-14 18:38:29 +0800403
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800404struct bsc_nat_acc_lst_entry *bsc_nat_acc_lst_entry_create(struct bsc_nat_acc_lst *);
Holger Hans Peter Freytherc1cac1e2010-10-11 09:50:31 +0200405int bsc_nat_lst_check_allow(struct bsc_nat_acc_lst *lst, const char *imsi);
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800406
Holger Hans Peter Freyther20ee3122010-07-05 14:39:44 +0800407int bsc_nat_msc_is_connected(struct bsc_nat *nat);
408
Holger Hans Peter Freyther463dc622010-10-03 19:41:42 +0800409int bsc_conn_type_to_ctr(struct sccp_connections *conn);
410
Holger Hans Peter Freythera3967572010-09-29 02:30:50 +0800411struct gsm48_hdr *bsc_unpack_dtap(struct bsc_nat_parsed *parsed, struct msgb *msg, uint32_t *len);
412
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +0800413/** USSD filtering */
Holger Hans Peter Freytherc16c2dc2010-10-13 20:22:36 +0200414int bsc_ussd_init(struct bsc_nat *nat);
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +0800415int bsc_check_ussd(struct sccp_connections *con, struct bsc_nat_parsed *parsed, struct msgb *msg);
Holger Hans Peter Freyther54f53522010-10-27 11:01:55 +0200416int bsc_close_ussd_connections(struct bsc_nat *nat);
Holger Hans Peter Freyther17870cf2010-09-29 19:32:55 +0800417
Holger Hans Peter Freytherdf8e6e92011-05-27 14:09:55 +0200418struct msgb *bsc_nat_rewrite_msg(struct bsc_nat *nat, struct msgb *msg, struct bsc_nat_parsed *, const char *imsi);
Holger Hans Peter Freythera914daf2010-10-21 12:12:57 +0200419
Holger Hans Peter Freyther6860c442011-05-02 19:16:13 +0200420/** paging group handling */
421struct bsc_nat_paging_group *bsc_nat_paging_group_num(struct bsc_nat *nat, int group);
422struct bsc_nat_paging_group *bsc_nat_paging_group_create(struct bsc_nat *nat, int group);
423void bsc_nat_paging_group_delete(struct bsc_nat_paging_group *);
424void bsc_nat_paging_group_add_lac(struct bsc_nat_paging_group *grp, int lac);
425void bsc_nat_paging_group_del_lac(struct bsc_nat_paging_group *grp, int lac);
426
Holger Hans Peter Freytherad75eab2011-05-27 12:38:58 +0200427/**
428 * Number rewriting support below
429 */
430struct bsc_nat_num_rewr_entry {
431 struct llist_head list;
432
433 regex_t msisdn_reg;
434 regex_t num_reg;
435
436 char *replace;
437};
438
Holger Hans Peter Freyther9c205712011-05-27 17:14:15 +0200439void bsc_nat_num_rewr_entry_adapt(void *ctx, struct llist_head *head, const struct osmo_config_list *);
Holger Hans Peter Freytherad75eab2011-05-27 12:38:58 +0200440
Holger Hans Peter Freyther6a97b8d2010-06-15 18:45:26 +0800441#endif