blob: 1b0bff9df3fe386af2a750e36742e180b4d15b3b [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>
Max43b01b02017-09-15 11:22:30 +020013#include <osmocom/gsm/gsm48.h>
Harald Welte121e9a42016-04-20 13:13:19 +020014#include <osmocom/crypt/auth.h>
Philipp Maierfbf66102017-04-09 12:32:51 +020015#include <osmocom/sigtran/sccp_sap.h>
Harald Weltef142c972011-05-24 13:25:38 +020016
Neels Hofmeyr90843962017-09-04 15:04:35 +020017#include <osmocom/msc/common.h>
Neels Hofmeyr90843962017-09-04 15:04:35 +020018#include <osmocom/msc/common_cs.h>
Neels Hofmeyr6c8afe12017-09-04 01:03:58 +020019#include <osmocom/mgcp_client/mgcp_client.h>
Harald Welteb96be392011-05-25 12:33:33 +020020
Philipp Maierfbf66102017-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 Welte2483f1b2016-06-19 18:06:02 +020030struct vlr_instance;
31struct vlr_subscr;
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020032struct ranap_ue_conn_ctx;
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
Sylvain Munaut47193072009-12-27 21:56:14 +010058/* Real authentication information containing Ki */
59enum gsm_auth_algo {
60 AUTH_ALGO_NONE,
61 AUTH_ALGO_XOR,
62 AUTH_ALGO_COMP128v1,
63};
64
65struct gsm_auth_info {
66 enum gsm_auth_algo auth_algo;
67 unsigned int a3a8_ki_len;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020068 uint8_t a3a8_ki[16];
Sylvain Munaut47193072009-12-27 21:56:14 +010069};
70
71struct gsm_auth_tuple {
72 int use_count;
73 int key_seq;
Harald Welte121e9a42016-04-20 13:13:19 +020074 struct osmo_auth_vector vec;
Sylvain Munaut47193072009-12-27 21:56:14 +010075};
Sylvain Munautb48216f2010-06-09 12:45:37 +020076#define GSM_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
Sylvain Munaut47193072009-12-27 21:56:14 +010077
Holger Freyther73487a22008-12-31 18:53:57 +000078/*
Sylvain Munaut30a15382009-12-24 00:27:26 +010079 * AUTHENTICATION/CIPHERING state
80 */
81struct gsm_security_operation {
82 struct gsm_auth_tuple atuple;
83 gsm_cbfn *cb;
84 void *cb_data;
85};
86
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080087/*
88 * A dummy to keep a connection up for at least
89 * a couple of seconds to work around MSC issues.
90 */
91struct gsm_anchor_operation {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020092 struct osmo_timer_list timeout;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080093};
94
Harald Weltef7c28b02009-12-21 13:30:17 +010095/* Maximum number of neighbor cells whose average we track */
96#define MAX_NEIGH_MEAS 10
97/* Maximum size of the averaging window for neighbor cells */
98#define MAX_WIN_NEIGH_AVG 10
99
100/* processed neighbor measurements for one cell */
101struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200102 uint16_t arfcn;
103 uint8_t bsic;
104 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +0100105 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200106 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +0100107};
108
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100109enum ran_type {
110 RAN_UNKNOWN,
111 RAN_GERAN_A, /* 2G / A-interface */
112 RAN_UTRAN_IU, /* 3G / Iu-interface (IuCS or IuPS) */
113};
114
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200115extern const struct value_string ran_type_names[];
116static inline const char *ran_type_name(enum ran_type val)
117{ return get_value_string(ran_type_names, val); }
118
Harald Welte2483f1b2016-06-19 18:06:02 +0200119struct gsm_classmark {
120 bool classmark1_set;
121 struct gsm48_classmark1 classmark1;
122 uint8_t classmark2_len;
123 uint8_t classmark2[3];
124 uint8_t classmark3_len;
125 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
126};
127
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200128enum integrity_protection_state {
129 INTEGRITY_PROTECTION_NONE = 0,
130 INTEGRITY_PROTECTION_IK = 1,
131 INTEGRITY_PROTECTION_IK_CK = 2,
132};
133
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200134/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100135struct gsm_subscriber_connection {
Harald Welte2483f1b2016-06-19 18:06:02 +0200136 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800137 struct llist_head entry;
138
Harald Welte2483f1b2016-06-19 18:06:02 +0200139 /* usage count. If this drops to zero, we start the release
140 * towards A/Iu */
141 uint32_t use_count;
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100142 uint32_t use_tokens;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100143
Harald Welte2483f1b2016-06-19 18:06:02 +0200144 /* The MS has opened the conn with a CM Service Request, and we shall
145 * keep it open for an actual request (or until timeout). */
146 bool received_cm_service_request;
147
148 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100149 struct bsc_subscr *bsub;
150
Harald Welte2483f1b2016-06-19 18:06:02 +0200151 /* libmsc/libvlr subscriber information (if available) */
152 struct vlr_subscr *vsub;
153
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200154 /* LU expiration handling */
155 uint8_t expire_timer_stopped;
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100156 /* SMS helpers for libmsc */
157 uint8_t next_rp_ref;
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200158
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100159 /*
160 * Operations that have a state and might be pending
161 */
Sylvain Munaut30a15382009-12-24 00:27:26 +0100162 struct gsm_security_operation *sec_operation;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800163 struct gsm_anchor_operation *anch_operation;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100164
Harald Welte2483f1b2016-06-19 18:06:02 +0200165 struct osmo_fsm_inst *conn_fsm;
166
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100167 /* Are we part of a special "silent" call */
168 int silent_call;
169
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200170 /* MNCC rtp bridge markers */
171 int mncc_rtp_bridge;
172 int mncc_rtp_create_pending;
Holger Hans Peter Freytherc21dcb22015-08-04 14:41:21 +0200173 int mncc_rtp_connect_pending;
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200174
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800175 /* bsc structures */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200176 struct osmo_bsc_sccp_con *sccp_con; /* BSC */
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800177
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100178 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200179 struct gsm_network *network;
180
Harald Welte2483f1b2016-06-19 18:06:02 +0200181 bool in_release;
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200182 struct gsm_lchan *lchan; /* BSC */
183 struct gsm_lchan *ho_lchan; /* BSC */
184 struct gsm_bts *bts; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100185
186 /* for assignment handling */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200187 struct osmo_timer_list T10; /* BSC */
188 struct gsm_lchan *secondary_lchan; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100189
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100190 /* connected via 2G or 3G? */
191 enum ran_type via_ran;
Harald Welte2483f1b2016-06-19 18:06:02 +0200192
193 struct gsm_classmark classmark;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200194
195 uint16_t lac;
196 struct gsm_encr encr;
197
Philipp Maierfbf66102017-04-09 12:32:51 +0200198 struct {
199 unsigned int mgcp_rtp_endpoint;
200 uint16_t port_subscr;
201 uint16_t port_cn;
202 } rtp;
203
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200204 /* which Iu-CS connection, if any. */
205 struct {
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200206 struct ranap_ue_conn_ctx *ue_ctx;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200207 uint8_t rab_id;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200208 } iu;
Philipp Maierfbf66102017-04-09 12:32:51 +0200209
210 struct {
211 /* A pointer to the SCCP user that handles
212 * the SCCP connections for this subscriber
213 * connection */
214 struct osmo_sccp_user *scu;
215
216 /* The address of the BSC that is associated
217 * with this subscriber connection */
218 struct osmo_sccp_addr bsc_addr;
219
220 /* The connection identifier that is used
221 * to reference the SCCP connection that is
222 * associated with this subscriber connection */
223 int conn_id;
224 } a;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100225};
226
Harald Weltef142c972011-05-24 13:25:38 +0200227
Harald Welte6be350c2011-05-25 13:10:08 +0200228#define ROLE_BSC
229#include "gsm_data_shared.h"
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100230
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100231
Alexander Couzens20423ea2016-07-12 15:42:02 +0200232enum {
Alexander Couzensb847a212016-08-02 11:34:11 +0200233 BSC_CTR_CHREQ_TOTAL,
234 BSC_CTR_CHREQ_NO_CHANNEL,
235 BSC_CTR_HANDOVER_ATTEMPTED,
236 BSC_CTR_HANDOVER_NO_CHANNEL,
237 BSC_CTR_HANDOVER_TIMEOUT,
238 BSC_CTR_HANDOVER_COMPLETED,
239 BSC_CTR_HANDOVER_FAILED,
240 BSC_CTR_PAGING_ATTEMPTED,
241 BSC_CTR_PAGING_DETACHED,
242 BSC_CTR_PAGING_COMPLETED,
243 BSC_CTR_PAGING_EXPIRED,
244 BSC_CTR_CHAN_RF_FAIL,
245 BSC_CTR_CHAN_RLL_ERR,
246 BSC_CTR_BTS_OML_FAIL,
247 BSC_CTR_BTS_RSL_FAIL,
Alexander Couzens8c53c592016-08-23 06:27:19 +0200248 BSC_CTR_CODEC_AMR_F,
249 BSC_CTR_CODEC_AMR_H,
250 BSC_CTR_CODEC_EFR,
251 BSC_CTR_CODEC_V1_FR,
252 BSC_CTR_CODEC_V1_HR,
Alexander Couzensb847a212016-08-02 11:34:11 +0200253};
254
255static const struct rate_ctr_desc bsc_ctr_description[] = {
256 [BSC_CTR_CHREQ_TOTAL] = {"chreq.total", "Received channel requests."},
257 [BSC_CTR_CHREQ_NO_CHANNEL] = {"chreq.no_channel", "Sent to MS no channel available."},
258 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover.attempted", "Received handover attempts."},
259 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover.no_channel", "Sent no channel available responses."},
260 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover.timeout", "Count the amount of timeouts of timer T3103."},
261 [BSC_CTR_HANDOVER_COMPLETED] = {"handover.completed", "Received handover completed."},
262 [BSC_CTR_HANDOVER_FAILED] = {"handover.failed", "Receive HO FAIL messages."},
263 [BSC_CTR_PAGING_ATTEMPTED] = {"paging.attempted", "Paging attempts for a MS."},
264 [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."},
265 [BSC_CTR_PAGING_COMPLETED] = {"paging.completed", "Paging successful completed."},
266 [BSC_CTR_PAGING_EXPIRED] = {"paging.expired", "Paging Request expired because of timeout T3113."},
267 [BSC_CTR_CHAN_RF_FAIL] = {"chan.rf_fail", "Received a RF failure indication from BTS."},
268 [BSC_CTR_CHAN_RLL_ERR] = {"chan.rll_err", "Received a RLL failure with T200 cause from BTS."},
269 [BSC_CTR_BTS_OML_FAIL] = {"bts.oml_fail", "Received a TEI down on a OML link."},
270 [BSC_CTR_BTS_RSL_FAIL] = {"bts.rsl_fail", "Received a TEI down on a OML link."},
Alexander Couzens8c53c592016-08-23 06:27:19 +0200271 [BSC_CTR_CODEC_AMR_F] = {"bts.codec_amr_f", "Count the usage of AMR/F codec by channel mode requested."},
272 [BSC_CTR_CODEC_AMR_H] = {"bts.codec_amr_h", "Count the usage of AMR/H codec by channel mode requested."},
273 [BSC_CTR_CODEC_EFR] = {"bts.codec_efr", "Count the usage of EFR codec by channel mode requested."},
274 [BSC_CTR_CODEC_V1_FR] = {"bts.codec_fr", "Count the usage of FR codec by channel mode requested."},
275 [BSC_CTR_CODEC_V1_HR] = {"bts.codec_hr", "Count the usage of HR codec by channel mode requested."},
Alexander Couzensb847a212016-08-02 11:34:11 +0200276};
277
278enum {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200279 MSC_CTR_LOC_UPDATE_TYPE_ATTACH,
280 MSC_CTR_LOC_UPDATE_TYPE_NORMAL,
281 MSC_CTR_LOC_UPDATE_TYPE_PERIODIC,
282 MSC_CTR_LOC_UPDATE_TYPE_DETACH,
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200283 MSC_CTR_LOC_UPDATE_FAILED,
284 MSC_CTR_LOC_UPDATE_COMPLETED,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200285 MSC_CTR_SMS_SUBMITTED,
286 MSC_CTR_SMS_NO_RECEIVER,
287 MSC_CTR_SMS_DELIVERED,
288 MSC_CTR_SMS_RP_ERR_MEM,
289 MSC_CTR_SMS_RP_ERR_OTHER,
Alexander Couzensaa386d22016-08-21 20:16:33 +0200290 MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200291 MSC_CTR_CALL_MO_SETUP,
292 MSC_CTR_CALL_MO_CONNECT_ACK,
293 MSC_CTR_CALL_MT_SETUP,
294 MSC_CTR_CALL_MT_CONNECT,
Alexander Couzens92f552f2016-08-23 07:32:27 +0200295 MSC_CTR_CALL_ACTIVE,
296 MSC_CTR_CALL_COMPLETE,
297 MSC_CTR_CALL_INCOMPLETE,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200298};
299
300static const struct rate_ctr_desc msc_ctr_description[] = {
Neels Hofmeyrc6bf2742017-11-18 23:22:17 +0100301 [MSC_CTR_LOC_UPDATE_TYPE_ATTACH] = {"loc_update_type:attach", "Received location update imsi attach requests."},
302 [MSC_CTR_LOC_UPDATE_TYPE_NORMAL] = {"loc_update_type:normal", "Received location update normal requests."},
303 [MSC_CTR_LOC_UPDATE_TYPE_PERIODIC] = {"loc_update_type:periodic", "Received location update periodic requests."},
304 [MSC_CTR_LOC_UPDATE_TYPE_DETACH] = {"loc_update_type:detach", "Received location update detach indication."},
305 [MSC_CTR_LOC_UPDATE_FAILED] = {"loc_update_resp:failed", "Rejected location updates."},
306 [MSC_CTR_LOC_UPDATE_COMPLETED] = {"loc_update_resp:completed", "Successful location updates."},
307 [MSC_CTR_SMS_SUBMITTED] = {"sms:submitted", "Received a RPDU from a MS (MO)."},
308 [MSC_CTR_SMS_NO_RECEIVER] = {"sms:no_receiver", "Counts SMS which couldn't routed because no receiver found."},
309 [MSC_CTR_SMS_DELIVERED] = {"sms:delivered", "Global SMS Deliver attempts."},
310 [MSC_CTR_SMS_RP_ERR_MEM] = {"sms:rp_err_mem", "CAUSE_MT_MEM_EXCEEDED errors of MS responses on a sms deliver attempt."},
311 [MSC_CTR_SMS_RP_ERR_OTHER] = {"sms:rp_err_other", "Other error of MS responses on a sms delive attempt."},
312 [MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR] = {"sms:deliver_unknown_error", "Unknown error occured during sms delivery."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200313 /* FIXME: count also sms delivered */
Neels Hofmeyrc6bf2742017-11-18 23:22:17 +0100314 [MSC_CTR_CALL_MO_SETUP] = {"call:mo_setup", "Received setup requests from a MS to init a MO call."},
315 [MSC_CTR_CALL_MO_CONNECT_ACK] = {"call:mo_connect_ack", "Received a connect ack from MS of a MO call. Call is now succesful connected up."},
316 [MSC_CTR_CALL_MT_SETUP] = {"call:mt_setup", "Sent setup requests to the MS (MT)."},
317 [MSC_CTR_CALL_MT_CONNECT] = {"call:mt_connect", "Sent a connect to the MS (MT)."},
318 [MSC_CTR_CALL_ACTIVE] = {"call:active", "Count total amount of calls that ever reached active state."},
319 [MSC_CTR_CALL_COMPLETE] = {"call:complete", "Count total amount of calls which got terminated by disconnect req or ind after reaching active state."},
320 [MSC_CTR_CALL_INCOMPLETE] = {"call:incomplete", "Count total amount of call which got terminated by any other reason after reaching active state."},
Alexander Couzensb847a212016-08-02 11:34:11 +0200321};
322
323
324static const struct rate_ctr_group_desc bsc_ctrg_desc = {
325 "bsc",
326 "base station controller",
327 OSMO_STATS_CLASS_GLOBAL,
328 ARRAY_SIZE(bsc_ctr_description),
329 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200330};
331
332static const struct rate_ctr_group_desc msc_ctrg_desc = {
333 "msc",
334 "mobile switching center",
335 OSMO_STATS_CLASS_GLOBAL,
336 ARRAY_SIZE(msc_ctr_description),
337 msc_ctr_description,
Harald Welte24ff6ee2009-12-22 00:41:05 +0100338};
339
Harald Welte (local)69de3972009-08-12 14:42:23 +0200340enum gsm_auth_policy {
341 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
342 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
343 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
Maxddee01f2016-05-24 14:23:27 +0200344 GSM_AUTH_POLICY_REGEXP, /* accept IMSIs matching given regexp */
Harald Welte (local)69de3972009-08-12 14:42:23 +0200345};
346
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100347#define MSC_PAGING_RESPONSE_TIMER_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530348
Neels Hofmeyr73983952016-05-10 13:29:33 +0200349struct gsm_tz {
350 int override; /* if 0, use system's time zone instead. */
351 int hr; /* hour */
352 int mn; /* minute */
353 int dst; /* daylight savings */
354};
355
Harald Welte52b1f982008-12-23 20:25:15 +0000356struct gsm_network {
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200357 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
358 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
359 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
360 * these have in common, like country and network code, put in yet
361 * separate structs and placed as members in osmo_bsc and osmo_msc. */
362
Harald Welte52b1f982008-12-23 20:25:15 +0000363 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200364 uint16_t country_code;
365 uint16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000366 char *name_long;
367 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200368 enum gsm_auth_policy auth_policy;
Maxddee01f2016-05-24 14:23:27 +0200369 regex_t authorized_regexp;
370 char *authorized_reg_str;
Harald Welte1085c092009-11-18 20:33:19 +0100371 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900372 int a5_encryption;
Harald Welte2483f1b2016-06-19 18:06:02 +0200373 bool authentication_required;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100374 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100375 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100376 struct {
377 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100378 /* Window RXLEV averaging */
379 unsigned int win_rxlev_avg; /* number of SACCH frames */
380 /* Window RXQUAL averaging */
381 unsigned int win_rxqual_avg; /* number of SACCH frames */
382 /* Window RXLEV neighbouring cells averaging */
383 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
384
385 /* how often should we check for power budget HO */
386 unsigned int pwr_interval; /* SACCH frames */
387 /* how much better does a neighbor cell have to be ? */
388 unsigned int pwr_hysteresis; /* dBm */
389 /* maximum distacne before we try a handover */
390 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100391 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000392
Alexander Couzensb847a212016-08-02 11:34:11 +0200393 struct rate_ctr_group *bsc_ctrs;
394 struct rate_ctr_group *msc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200395 struct osmo_counter *active_calls;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100396
Harald Welte4bfdfe72009-06-10 23:11:52 +0800397 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200398 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200399 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800400 struct llist_head upqueue;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200401 /*
402 * TODO: Move the trans_list into the subscriber connection and
403 * create a pending list for MT transactions. These exist before
404 * we have a subscriber connection.
405 */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800406 struct llist_head trans_list;
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +0800407 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800408
Harald Welte52b1f982008-12-23 20:25:15 +0000409 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200410 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100411
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100412 unsigned int paging_response_timer;
Harald Welteeab84a12009-12-13 10:53:12 +0100413
Jan Luebbebfbdeec2012-12-27 00:27:16 +0100414 /* timer to expire old location updates */
415 struct osmo_timer_list subscr_expire_timer;
416
Harald Welteeab84a12009-12-13 10:53:12 +0100417 /* Radio Resource Location Protocol (TS 04.31) */
418 struct {
419 enum rrlp_mode mode;
420 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800421
Alexander Couzens11368112016-11-28 23:26:50 +0100422 enum gsm_chan_t ctype_by_chreq[18];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800423
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +0800424 /* Use a TCH for handling requests of type paging any */
425 int pag_any_tch;
426
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800427 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200428 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +0100429
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100430 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200431
432 /* control interface */
433 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200434
435 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
436 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +0200437
438 /* all active subscriber connections. */
439 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200440
441 /* if override is nonzero, this timezone data is used for all MM
442 * contexts. */
443 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
444 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100445 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200446 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100447
448 /* List of all struct bsc_subscr used in libbsc. This llist_head is
449 * allocated so that the llist_head pointer itself can serve as a
450 * talloc context (useful to not have to pass the entire gsm_network
451 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
452 * not require gsm_data.h). In an MSC-without-BSC environment, this
453 * pointer is NULL to indicate absence of a bsc_subscribers list. */
454 struct llist_head *bsc_subscribers;
Harald Welte2483f1b2016-06-19 18:06:02 +0200455
456 /* MSC: GSUP server address of the HLR */
457 const char *gsup_server_addr_str;
458 uint16_t gsup_server_port;
459
460 struct vlr_instance *vlr;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200461
462 /* Periodic location update default value */
463 uint8_t t3212;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200464
465 struct {
Neels Hofmeyr6c8afe12017-09-04 01:03:58 +0200466 struct mgcp_client_conf conf;
467 struct mgcp_client *client;
468 } mgw;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200469
470 struct {
Philipp Maierfbf66102017-04-09 12:32:51 +0200471 /* CS7 instance id number (set via VTY) */
472 uint32_t cs7_instance;
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200473 int rab_assign_addr_enc;
Philipp Maierfbf66102017-04-09 12:32:51 +0200474 struct osmo_sccp_instance *sccp;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200475 } iu;
Philipp Maierfbf66102017-04-09 12:32:51 +0200476
477 struct {
478 /* CS7 instance id number (set via VTY) */
479 uint32_t cs7_instance;
480 /* A list with the context information about
481 * all BSCs we have connections with */
482 struct llist_head bscs;
483 struct osmo_sccp_instance *sccp;
484 } a;
Harald Welte52b1f982008-12-23 20:25:15 +0000485};
486
Harald Welted4bdee72012-11-08 19:44:08 +0100487struct osmo_esme;
488
489enum gsm_sms_source_id {
490 SMS_SOURCE_UNKNOWN = 0,
491 SMS_SOURCE_MS, /* received from MS */
492 SMS_SOURCE_VTY, /* received from VTY */
493 SMS_SOURCE_SMPP, /* received via SMPP */
494};
495
Harald Welte7e310b12009-03-30 20:56:32 +0000496#define SMS_HDR_SIZE 128
497#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100498
499struct gsm_sms_addr {
500 uint8_t ton;
501 uint8_t npi;
502 char addr[21+1];
503};
504
Harald Welte7e310b12009-03-30 20:56:32 +0000505struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900506 unsigned long long id;
Harald Welte2483f1b2016-06-19 18:06:02 +0200507 struct vlr_subscr *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100508 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100509 enum gsm_sms_source_id source;
510
511 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200512 uint8_t transaction_id;
513 uint32_t msg_ref;
514 } gsm411;
515
516 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100517 struct osmo_esme *esme;
518 uint32_t sequence_nr;
519 int transaction_mode;
520 char msg_id[16];
521 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000522
Harald Welteb9c758b2009-07-05 14:02:46 +0200523 unsigned long validity_minutes;
Keithc601adc2017-08-16 22:45:07 +0200524 time_t created;
Pablo Neira Ayusoadae8592017-08-07 14:01:30 +0100525 bool is_report;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200526 uint8_t reply_path_req;
527 uint8_t status_rep_req;
528 uint8_t ud_hdr_ind;
529 uint8_t protocol_id;
530 uint8_t data_coding_scheme;
531 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200532 uint8_t user_data_len;
533 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200534
Harald Welte7e310b12009-03-30 20:56:32 +0000535 char text[SMS_TEXT_SIZE];
536};
537
Neels Hofmeyrc13e6872016-05-11 13:53:47 +0200538extern void talloc_ctx_init(void *ctx_root);
539
Harald Welte1d014a52009-08-08 15:38:29 +0200540enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200541const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000542struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
543 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000544
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200545extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100546extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200547
Harald Welte (local)69de3972009-08-12 14:42:23 +0200548enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
549const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
550
Harald Welteeab84a12009-12-13 10:53:12 +0100551enum rrlp_mode rrlp_mode_parse(const char *arg);
552const char *rrlp_mode_name(enum rrlp_mode mode);
553
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100554enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +0200555const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
556
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200557int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +0800558void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +0100559
Neels Hofmeyr42eb0142016-05-20 17:15:44 +0200560struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
561void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
562
563struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
564void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +0800565
Harald Welte3300c012011-06-05 13:31:33 +0200566void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
567 uint8_t e1_ts, uint8_t e1_ts_ss);
568
569void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
Maxe591d472017-09-15 13:51:39 +0200570
Harald Welte3300c012011-06-05 13:31:33 +0200571struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +0100572int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -0400573int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +0200574
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200575/* generic E1 line operations for all ISDN-based BTS. */
576extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
577
Harald Weltee555c2b2012-08-17 13:02:12 +0200578extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
579extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
580
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100581/* control interface handling */
582int bsc_base_ctrl_cmds_install(void);
Harald Welte2483f1b2016-06-19 18:06:02 +0200583int msc_ctrl_cmds_install(struct gsm_network *net);
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100584
Harald Welte2483f1b2016-06-19 18:06:02 +0200585bool classmark_is_r99(struct gsm_classmark *cm);
586
Harald Welte6be350c2011-05-25 13:10:08 +0200587#endif /* _GSM_DATA_H */