blob: 0341138f11f3cc1232ae0b8c2d7c2372e4f923f2 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
Harald Weltef142c972011-05-24 13:25:38 +02004#include <stdint.h>
Maxddee01f2016-05-24 14:23:27 +02005#include <regex.h>
6#include <sys/types.h>
Maxe6052c42016-06-30 10:25:49 +02007#include <stdbool.h>
Harald Weltef142c972011-05-24 13:25:38 +02008
9#include <osmocom/core/timer.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020010#include <osmocom/core/rate_ctr.h>
Harald Welte6be350c2011-05-25 13:10:08 +020011#include <osmocom/core/select.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020012#include <osmocom/core/stats.h>
13
Harald Welte121e9a42016-04-20 13:13:19 +020014#include <osmocom/crypt/auth.h>
Philipp Maier39f62bb2017-04-09 12:32:51 +020015#include <osmocom/sigtran/sccp_sap.h>
Harald Weltef142c972011-05-24 13:25:38 +020016
Neels Hofmeyrc0164792017-09-04 15:15:32 +020017#include <osmocom/bsc/common.h>
18#include <osmocom/bsc/rest_octets.h>
19#include <osmocom/bsc/common_cs.h>
Harald Welteb96be392011-05-25 12:33:33 +020020
Philipp Maier39f62bb2017-04-09 12:32:51 +020021
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020022/** annotations for msgb ownership */
23#define __uses
24
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010025#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
26
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020027struct mncc_sock_state;
Jacob Erlbeck1e30a282014-12-03 09:28:24 +010028struct gsm_subscriber_group;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010029struct bsc_subscr;
Harald Weltea43e0b42016-06-19 18:06:02 +020030struct vlr_instance;
31struct vlr_subscr;
Neels Hofmeyr7b656882017-07-09 22:09:18 +020032struct gprs_ra_id;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020033
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080034#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
35
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010036#define tmsi_from_string(str) strtoul(str, NULL, 10)
37
Max70fdd242017-06-15 15:10:53 +020038/* 3-bit long values */
39#define EARFCN_PRIO_INVALID 8
40#define EARFCN_MEAS_BW_INVALID 8
41/* 5-bit long values */
42#define EARFCN_QRXLV_INVALID 32
43#define EARFCN_THRESH_LOW_INVALID 32
44
Sylvain Munaut30a15382009-12-24 00:27:26 +010045enum gsm_security_event {
46 GSM_SECURITY_NOAVAIL,
47 GSM_SECURITY_AUTH_FAILED,
48 GSM_SECURITY_SUCCEEDED,
Andreas Eversberg641475c2013-07-10 08:58:03 +020049 GSM_SECURITY_ALREADY,
Sylvain Munaut30a15382009-12-24 00:27:26 +010050};
51
Harald Welte8e1e3ee2009-02-01 13:32:45 +000052struct msgb;
53typedef int gsm_cbfn(unsigned int hooknum,
54 unsigned int event,
55 struct msgb *msg,
56 void *data, void *param);
57
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080058/*
59 * A dummy to keep a connection up for at least
60 * a couple of seconds to work around MSC issues.
61 */
62struct gsm_anchor_operation {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020063 struct osmo_timer_list timeout;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080064};
65
Harald Weltef7c28b02009-12-21 13:30:17 +010066/* Maximum number of neighbor cells whose average we track */
67#define MAX_NEIGH_MEAS 10
68/* Maximum size of the averaging window for neighbor cells */
69#define MAX_WIN_NEIGH_AVG 10
70
71/* processed neighbor measurements for one cell */
72struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020073 uint16_t arfcn;
74 uint8_t bsic;
75 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +010076 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020077 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +010078};
79
Neels Hofmeyrd3270a92017-02-02 01:07:28 +010080enum ran_type {
81 RAN_UNKNOWN,
82 RAN_GERAN_A, /* 2G / A-interface */
83 RAN_UTRAN_IU, /* 3G / Iu-interface (IuCS or IuPS) */
84};
85
Neels Hofmeyrc29505e2016-05-20 21:59:55 +020086extern const struct value_string ran_type_names[];
87static inline const char *ran_type_name(enum ran_type val)
88{ return get_value_string(ran_type_names, val); }
89
Harald Weltea43e0b42016-06-19 18:06:02 +020090struct gsm_classmark {
91 bool classmark1_set;
92 struct gsm48_classmark1 classmark1;
93 uint8_t classmark2_len;
94 uint8_t classmark2[3];
95 uint8_t classmark3_len;
96 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
97};
98
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +020099enum integrity_protection_state {
100 INTEGRITY_PROTECTION_NONE = 0,
101 INTEGRITY_PROTECTION_IK = 1,
102 INTEGRITY_PROTECTION_IK_CK = 2,
103};
104
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200105/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100106struct gsm_subscriber_connection {
Harald Weltea43e0b42016-06-19 18:06:02 +0200107 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800108 struct llist_head entry;
109
Harald Weltea43e0b42016-06-19 18:06:02 +0200110 /* usage count. If this drops to zero, we start the release
111 * towards A/Iu */
112 uint32_t use_count;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100113
Harald Weltea43e0b42016-06-19 18:06:02 +0200114 /* The MS has opened the conn with a CM Service Request, and we shall
115 * keep it open for an actual request (or until timeout). */
116 bool received_cm_service_request;
117
118 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100119 struct bsc_subscr *bsub;
120
Harald Weltea43e0b42016-06-19 18:06:02 +0200121 /* libmsc/libvlr subscriber information (if available) */
122 struct vlr_subscr *vsub;
123
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200124 /* LU expiration handling */
125 uint8_t expire_timer_stopped;
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100126 /* SMS helpers for libmsc */
127 uint8_t next_rp_ref;
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200128
Harald Weltea43e0b42016-06-19 18:06:02 +0200129 struct osmo_fsm_inst *conn_fsm;
130
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100131 /* Are we part of a special "silent" call */
132 int silent_call;
133
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200134 /* MNCC rtp bridge markers */
135 int mncc_rtp_bridge;
136 int mncc_rtp_create_pending;
Holger Hans Peter Freytherc21dcb22015-08-04 14:41:21 +0200137 int mncc_rtp_connect_pending;
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200138
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800139 /* bsc structures */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200140 struct osmo_bsc_sccp_con *sccp_con; /* BSC */
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800141
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100142 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200143 struct gsm_network *network;
144
Harald Weltea43e0b42016-06-19 18:06:02 +0200145 bool in_release;
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200146 struct gsm_lchan *lchan; /* BSC */
147 struct gsm_lchan *ho_lchan; /* BSC */
148 struct gsm_bts *bts; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100149
150 /* for assignment handling */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200151 struct osmo_timer_list T10; /* BSC */
152 struct gsm_lchan *secondary_lchan; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100153
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100154 /* connected via 2G or 3G? */
155 enum ran_type via_ran;
Harald Weltea43e0b42016-06-19 18:06:02 +0200156
157 struct gsm_classmark classmark;
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200158
159 uint16_t lac;
160 struct gsm_encr encr;
161
Philipp Maier39f62bb2017-04-09 12:32:51 +0200162 struct {
163 unsigned int mgcp_rtp_endpoint;
164 uint16_t port_subscr;
165 uint16_t port_cn;
166 } rtp;
167
Philipp Maier39f62bb2017-04-09 12:32:51 +0200168 struct {
169 /* A pointer to the SCCP user that handles
170 * the SCCP connections for this subscriber
171 * connection */
172 struct osmo_sccp_user *scu;
173
174 /* The address of the BSC that is associated
175 * with this subscriber connection */
176 struct osmo_sccp_addr bsc_addr;
177
178 /* The connection identifier that is used
179 * to reference the SCCP connection that is
180 * associated with this subscriber connection */
181 int conn_id;
182 } a;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100183};
184
Harald Weltef142c972011-05-24 13:25:38 +0200185
Harald Welte6be350c2011-05-25 13:10:08 +0200186#include "gsm_data_shared.h"
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100187
Harald Welted82101e2017-12-09 23:07:38 +0100188enum {
189 BTS_CTR_CHREQ_TOTAL,
190 BTS_CTR_CHREQ_NO_CHANNEL,
191 BTS_CTR_CHAN_RF_FAIL,
192 BTS_CTR_CHAN_RLL_ERR,
193 BTS_CTR_BTS_OML_FAIL,
194 BTS_CTR_BTS_RSL_FAIL,
195 BTS_CTR_CODEC_AMR_F,
196 BTS_CTR_CODEC_AMR_H,
197 BTS_CTR_CODEC_EFR,
198 BTS_CTR_CODEC_V1_FR,
199 BTS_CTR_CODEC_V1_HR,
Harald Weltecf9d4312017-12-13 23:17:16 +0100200 BTS_CTR_PAGING_ATTEMPTED,
201 BTS_CTR_PAGING_ALREADY,
202 BTS_CTR_PAGING_RESPONDED,
203 BTS_CTR_PAGING_EXPIRED,
Harald Welte4f598922017-12-14 13:47:02 +0100204 BTS_CTR_CHAN_ACT_TOTAL,
205 BTS_CTR_CHAN_ACT_NACK,
Harald Welte62d9cb02017-12-14 14:00:26 +0100206 BTS_CTR_RSL_UNKNOWN,
Harald Welted82101e2017-12-09 23:07:38 +0100207};
208
209static const struct rate_ctr_desc bts_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +0100210 [BTS_CTR_CHREQ_TOTAL] = {"chreq:total", "Received channel requests."},
211 [BTS_CTR_CHREQ_NO_CHANNEL] = {"chreq:no_channel", "Sent to MS no channel available."},
212 [BTS_CTR_CHAN_RF_FAIL] = {"chan:rf_fail", "Received a RF failure indication from BTS."},
213 [BTS_CTR_CHAN_RLL_ERR] = {"chan:rll_err", "Received a RLL failure with T200 cause from BTS."},
Harald Welted82101e2017-12-09 23:07:38 +0100214 [BTS_CTR_BTS_OML_FAIL] = {"oml_fail", "Received a TEI down on a OML link."},
215 [BTS_CTR_BTS_RSL_FAIL] = {"rsl_fail", "Received a TEI down on a OML link."},
Harald Welte1ef46d92017-12-09 23:10:46 +0100216 [BTS_CTR_CODEC_AMR_F] = {"codec:amr_f", "Count the usage of AMR/F codec by channel mode requested."},
217 [BTS_CTR_CODEC_AMR_H] = {"codec:amr_h", "Count the usage of AMR/H codec by channel mode requested."},
218 [BTS_CTR_CODEC_EFR] = {"codec:efr", "Count the usage of EFR codec by channel mode requested."},
219 [BTS_CTR_CODEC_V1_FR] = {"codec:fr", "Count the usage of FR codec by channel mode requested."},
220 [BTS_CTR_CODEC_V1_HR] = {"codec:hr", "Count the usage of HR codec by channel mode requested."},
Harald Weltecf9d4312017-12-13 23:17:16 +0100221
222 [BTS_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
223 [BTS_CTR_PAGING_ALREADY] = {"paging:already", "Paging attempts ignored as subsciber was already being paged."},
224 [BTS_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful paging response."},
225 [BTS_CTR_PAGING_EXPIRED] = {"paging:expired", "Paging Request expired because of timeout T3113."},
Harald Welte4f598922017-12-14 13:47:02 +0100226 [BTS_CTR_CHAN_ACT_TOTAL] = {"chan_act:total", "Total number of Channel Activations."},
227 [BTS_CTR_CHAN_ACT_NACK] = {"chan_act:nack", "Number of Channel Activations that the BTS NACKed"},
Harald Welte62d9cb02017-12-14 14:00:26 +0100228 [BTS_CTR_RSL_UNKNOWN] = {"rsl:unknown", "Number of unknown/unsupported RSL messages received from BTS"},
Harald Welted82101e2017-12-09 23:07:38 +0100229};
230
231static const struct rate_ctr_group_desc bts_ctrg_desc = {
232 "bts",
233 "base transceiver station",
234 OSMO_STATS_CLASS_GLOBAL,
235 ARRAY_SIZE(bts_ctr_description),
236 bts_ctr_description,
237};
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100238
Alexander Couzens20423ea2016-07-12 15:42:02 +0200239enum {
Alexander Couzensb847a212016-08-02 11:34:11 +0200240 BSC_CTR_HANDOVER_ATTEMPTED,
241 BSC_CTR_HANDOVER_NO_CHANNEL,
242 BSC_CTR_HANDOVER_TIMEOUT,
243 BSC_CTR_HANDOVER_COMPLETED,
244 BSC_CTR_HANDOVER_FAILED,
245 BSC_CTR_PAGING_ATTEMPTED,
246 BSC_CTR_PAGING_DETACHED,
Harald Weltecf9d4312017-12-13 23:17:16 +0100247 BSC_CTR_PAGING_RESPONDED,
Alexander Couzensb847a212016-08-02 11:34:11 +0200248};
249
250static const struct rate_ctr_desc bsc_ctr_description[] = {
Harald Welte1ef46d92017-12-09 23:10:46 +0100251 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover:attempted", "Received handover attempts."},
252 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover:no_channel", "Sent no channel available responses."},
253 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover:timeout", "Count the amount of timeouts of timer T3103."},
254 [BSC_CTR_HANDOVER_COMPLETED] = {"handover:completed", "Received handover completed."},
255 [BSC_CTR_HANDOVER_FAILED] = {"handover:failed", "Receive HO FAIL messages."},
Harald Weltecf9d4312017-12-13 23:17:16 +0100256
257 [BSC_CTR_PAGING_ATTEMPTED] = {"paging:attempted", "Paging attempts for a subscriber."},
Harald Welte1ef46d92017-12-09 23:10:46 +0100258 [BSC_CTR_PAGING_DETACHED] = {"paging:detached", "Counts the amount of paging attempts which couldn't sent out any paging request because no responsible bts found."},
Harald Weltecf9d4312017-12-13 23:17:16 +0100259 [BSC_CTR_PAGING_RESPONDED] = {"paging:responded", "Paging attempts with successful response."},
Alexander Couzensb847a212016-08-02 11:34:11 +0200260};
261
Alexander Couzensb847a212016-08-02 11:34:11 +0200262
263
264static const struct rate_ctr_group_desc bsc_ctrg_desc = {
265 "bsc",
266 "base station controller",
267 OSMO_STATS_CLASS_GLOBAL,
268 ARRAY_SIZE(bsc_ctr_description),
269 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200270};
271
Harald Welte (local)69de3972009-08-12 14:42:23 +0200272enum gsm_auth_policy {
273 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
274 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
275 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
Maxddee01f2016-05-24 14:23:27 +0200276 GSM_AUTH_POLICY_REGEXP, /* accept IMSIs matching given regexp */
Harald Welte (local)69de3972009-08-12 14:42:23 +0200277};
278
Harald Weltedea252d2017-12-10 19:55:18 +0100279#define GSM_T3101_DEFAULT 3 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +0200280#define GSM_T3103_DEFAULT 5 /* s */
281#define GSM_T3105_DEFAULT 100 /* ms */
282#define GSM_T3107_DEFAULT 5 /* s */
283#define GSM_T3109_DEFAULT 19 /* s, must be 2s + radio_link_timeout*0.48 */
284#define GSM_T3111_DEFAULT 2 /* s */
Harald Welte6e59ced2017-12-14 12:49:43 +0100285#define GSM_T3113_DEFAULT 10 /* s */
Harald Weltea0d324b2017-07-20 01:47:39 +0200286#define GSM_T3115_DEFAULT 10
287#define GSM_T3117_DEFAULT 10
288#define GSM_T3119_DEFAULT 10
Andreas Eversberg75e13a42013-02-07 11:51:16 +0100289#define GSM_T3122_DEFAULT 10
Harald Weltea0d324b2017-07-20 01:47:39 +0200290#define GSM_T3141_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530291
Neels Hofmeyr73983952016-05-10 13:29:33 +0200292struct gsm_tz {
293 int override; /* if 0, use system's time zone instead. */
294 int hr; /* hour */
295 int mn; /* minute */
296 int dst; /* daylight savings */
297};
298
Harald Welte52b1f982008-12-23 20:25:15 +0000299struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200300 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
301 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
302 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
303 * these have in common, like country and network code, put in yet
304 * separate structs and placed as members in osmo_bsc and osmo_msc. */
305
Harald Welte52b1f982008-12-23 20:25:15 +0000306 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200307 uint16_t country_code;
308 uint16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000309 char *name_long;
310 char *name_short;
Harald Welte1085c092009-11-18 20:33:19 +0100311 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900312 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100313 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100314 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100315 struct {
316 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100317 /* Window RXLEV averaging */
318 unsigned int win_rxlev_avg; /* number of SACCH frames */
319 /* Window RXQUAL averaging */
320 unsigned int win_rxqual_avg; /* number of SACCH frames */
321 /* Window RXLEV neighbouring cells averaging */
322 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
323
324 /* how often should we check for power budget HO */
325 unsigned int pwr_interval; /* SACCH frames */
326 /* how much better does a neighbor cell have to be ? */
327 unsigned int pwr_hysteresis; /* dBm */
328 /* maximum distacne before we try a handover */
329 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100330 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000331
Alexander Couzensb847a212016-08-02 11:34:11 +0200332 struct rate_ctr_group *bsc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200333 struct osmo_counter *active_calls;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100334
Harald Welte4bfdfe72009-06-10 23:11:52 +0800335 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200336 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200337 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800338 struct llist_head upqueue;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +0200339 /*
340 * TODO: Move the trans_list into the subscriber connection and
341 * create a pending list for MT transactions. These exist before
342 * we have a subscriber connection.
343 */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800344 struct llist_head trans_list;
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +0800345 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800346
Harald Welte52b1f982008-12-23 20:25:15 +0000347 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200348 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100349
350 /* timer values */
351 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100352 int T3103;
353 int T3105;
354 int T3107;
355 int T3109;
356 int T3111;
357 int T3113;
358 int T3115;
359 int T3117;
360 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +0100361 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100362 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100363
Jan Luebbebfbdeec2012-12-27 00:27:16 +0100364 /* timer to expire old location updates */
365 struct osmo_timer_list subscr_expire_timer;
366
Harald Welteeab84a12009-12-13 10:53:12 +0100367 /* Radio Resource Location Protocol (TS 04.31) */
368 struct {
369 enum rrlp_mode mode;
370 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800371
Alexander Couzens547c2072017-11-21 12:03:04 +0100372 enum gsm_chan_t ctype_by_chreq[_NUM_CHREQ_T];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800373
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +0800374 /* Use a TCH for handling requests of type paging any */
375 int pag_any_tch;
376
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800377 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200378 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +0100379
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100380 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200381
382 /* control interface */
383 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200384
385 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
386 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +0200387
388 /* all active subscriber connections. */
389 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200390
391 /* if override is nonzero, this timezone data is used for all MM
392 * contexts. */
393 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
394 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100395 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200396 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100397
398 /* List of all struct bsc_subscr used in libbsc. This llist_head is
399 * allocated so that the llist_head pointer itself can serve as a
400 * talloc context (useful to not have to pass the entire gsm_network
401 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
402 * not require gsm_data.h). In an MSC-without-BSC environment, this
403 * pointer is NULL to indicate absence of a bsc_subscribers list. */
404 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +0200405
406 /* MSC: GSUP server address of the HLR */
407 const char *gsup_server_addr_str;
408 uint16_t gsup_server_port;
409
410 struct vlr_instance *vlr;
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200411
412 /* Periodic location update default value */
413 uint8_t t3212;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +0200414
415 struct {
Philipp Maier39c609b2017-09-27 15:51:34 +0200416 struct mgcp_client_conf *conf;
417 struct mgcp_client *client;
418 } mgw;
419
420 struct {
Philipp Maier39f62bb2017-04-09 12:32:51 +0200421 /* CS7 instance id number (set via VTY) */
422 uint32_t cs7_instance;
Philipp Maier39f62bb2017-04-09 12:32:51 +0200423 /* A list with the context information about
424 * all BSCs we have connections with */
425 struct llist_head bscs;
426 struct osmo_sccp_instance *sccp;
427 } a;
Harald Welte52b1f982008-12-23 20:25:15 +0000428};
429
Harald Welted4bdee72012-11-08 19:44:08 +0100430struct osmo_esme;
431
432enum gsm_sms_source_id {
433 SMS_SOURCE_UNKNOWN = 0,
434 SMS_SOURCE_MS, /* received from MS */
435 SMS_SOURCE_VTY, /* received from VTY */
436 SMS_SOURCE_SMPP, /* received via SMPP */
437};
438
Harald Welte7e310b12009-03-30 20:56:32 +0000439#define SMS_HDR_SIZE 128
440#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100441
442struct gsm_sms_addr {
443 uint8_t ton;
444 uint8_t npi;
445 char addr[21+1];
446};
447
Harald Welte7e310b12009-03-30 20:56:32 +0000448struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900449 unsigned long long id;
Harald Weltea43e0b42016-06-19 18:06:02 +0200450 struct vlr_subscr *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100451 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100452 enum gsm_sms_source_id source;
453
454 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200455 uint8_t transaction_id;
456 uint32_t msg_ref;
457 } gsm411;
458
459 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100460 struct osmo_esme *esme;
461 uint32_t sequence_nr;
462 int transaction_mode;
463 char msg_id[16];
464 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000465
Harald Welteb9c758b2009-07-05 14:02:46 +0200466 unsigned long validity_minutes;
Keith5f9d0bd2017-08-16 22:45:07 +0200467 time_t created;
Pablo Neira Ayusoe1cdc322017-08-07 14:01:30 +0100468 bool is_report;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200469 uint8_t reply_path_req;
470 uint8_t status_rep_req;
471 uint8_t ud_hdr_ind;
472 uint8_t protocol_id;
473 uint8_t data_coding_scheme;
474 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200475 uint8_t user_data_len;
476 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200477
Harald Welte7e310b12009-03-30 20:56:32 +0000478 char text[SMS_TEXT_SIZE];
479};
480
Neels Hofmeyrc13e6872016-05-11 13:53:47 +0200481extern void talloc_ctx_init(void *ctx_root);
482
Harald Welte39315c42010-01-10 18:01:52 +0100483int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200484
Harald Welte1d014a52009-08-08 15:38:29 +0200485enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200486const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000487struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
488 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000489
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200490extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100491extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200492
Harald Weltef383aa12012-07-02 19:51:55 +0200493/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +0000494static inline int is_ipaccess_bts(struct gsm_bts *bts)
495{
496 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100497 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +0100498 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000499 return 1;
500 default:
501 break;
502 }
503 return 0;
504}
505
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200506static inline int is_sysmobts_v2(struct gsm_bts *bts)
507{
508 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +0100509 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200510 return 1;
511 default:
512 break;
513 }
514 return 0;
515}
516
Harald Welte5b570672009-08-10 10:08:01 +0200517static inline int is_siemens_bts(struct gsm_bts *bts)
518{
519 switch (bts->type) {
520 case GSM_BTS_TYPE_BS11:
521 return 1;
522 default:
523 break;
524 }
525
526 return 0;
527}
528
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100529static inline int is_nokia_bts(struct gsm_bts *bts)
530{
531 switch (bts->type) {
532 case GSM_BTS_TYPE_NOKIA_SITE:
533 return 1;
534 default:
535 break;
536 }
537
538 return 0;
539}
540
Andreas Eversbergdcf38e12013-12-05 14:37:11 +0100541static inline int is_e1_bts(struct gsm_bts *bts)
542{
543 switch (bts->type) {
544 case GSM_BTS_TYPE_BS11:
545 case GSM_BTS_TYPE_RBS2000:
546 case GSM_BTS_TYPE_NOKIA_SITE:
547 return 1;
548 default:
549 break;
550 }
551
552 return 0;
553}
554
Harald Welte (local)69de3972009-08-12 14:42:23 +0200555enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
556const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
557
Harald Welteeab84a12009-12-13 10:53:12 +0100558enum rrlp_mode rrlp_mode_parse(const char *arg);
559const char *rrlp_mode_name(enum rrlp_mode mode);
560
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100561enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +0200562const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100563int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +0200564
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200565int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +0800566void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +0100567
Harald Weltef3d8e922010-06-14 22:44:42 +0200568int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Weltefbda4e12010-03-04 11:04:52 +0100569int gsm_bts_model_register(struct gsm_bts_model *model);
570
Neels Hofmeyr42eb0142016-05-20 17:15:44 +0200571struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
572void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
573
574struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
575void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +0800576
Harald Welte3300c012011-06-05 13:31:33 +0200577struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
578 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100579 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +0100580
Harald Welte3300c012011-06-05 13:31:33 +0200581void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
582 uint8_t e1_ts, uint8_t e1_ts_ss);
583
Maxbe356ed2017-09-07 19:10:09 +0200584void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Max71d082b2017-05-30 15:03:38 +0200585bool gsm_btsmodel_has_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Welte3300c012011-06-05 13:31:33 +0200586struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +0100587int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -0400588int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +0200589
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200590/* generic E1 line operations for all ISDN-based BTS. */
591extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
592
Harald Weltee555c2b2012-08-17 13:02:12 +0200593extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
594extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
595
Max3d049d22017-10-09 17:12:53 +0200596char *get_model_oml_status(const struct gsm_bts *bts);
597
Max25cc4072017-10-10 14:50:35 +0200598unsigned long long bts_uptime(const struct gsm_bts *bts);
599
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100600/* control interface handling */
601int bsc_base_ctrl_cmds_install(void);
602
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100603/* dependency handling */
604void bts_depend_mark(struct gsm_bts *bts, int dep);
605void bts_depend_clear(struct gsm_bts *bts, int dep);
606int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +0100607int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100608
Harald Welte2f8b9d22017-06-18 11:12:13 +0300609int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
610void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
611
Harald Weltea43e0b42016-06-19 18:06:02 +0200612bool classmark_is_r99(struct gsm_classmark *cm);
613
Harald Welte6be350c2011-05-25 13:10:08 +0200614#endif /* _GSM_DATA_H */