blob: 2cddd2548fc9f6afe405c13bc751a32ca16dcccf [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
Harald Welted35038d2018-01-25 00:07:33 +010021#include "gsm_data_shared.h"
22
23
Philipp Maierfbf66102017-04-09 12:32:51 +020024
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020025/** annotations for msgb ownership */
26#define __uses
27
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010028#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
29
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020030struct mncc_sock_state;
Jacob Erlbeck1e30a282014-12-03 09:28:24 +010031struct gsm_subscriber_group;
Harald Welte2483f1b2016-06-19 18:06:02 +020032struct vlr_instance;
33struct vlr_subscr;
Neels Hofmeyr00e82d62017-07-05 15:19:52 +020034struct ranap_ue_conn_ctx;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020035
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080036#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
37
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010038#define tmsi_from_string(str) strtoul(str, NULL, 10)
39
Max70fdd242017-06-15 15:10:53 +020040/* 3-bit long values */
41#define EARFCN_PRIO_INVALID 8
42#define EARFCN_MEAS_BW_INVALID 8
43/* 5-bit long values */
44#define EARFCN_QRXLV_INVALID 32
45#define EARFCN_THRESH_LOW_INVALID 32
46
Sylvain Munaut30a15382009-12-24 00:27:26 +010047enum gsm_security_event {
48 GSM_SECURITY_NOAVAIL,
49 GSM_SECURITY_AUTH_FAILED,
50 GSM_SECURITY_SUCCEEDED,
Andreas Eversberg641475c2013-07-10 08:58:03 +020051 GSM_SECURITY_ALREADY,
Sylvain Munaut30a15382009-12-24 00:27:26 +010052};
53
Harald Welte8e1e3ee2009-02-01 13:32:45 +000054struct msgb;
55typedef int gsm_cbfn(unsigned int hooknum,
56 unsigned int event,
57 struct msgb *msg,
58 void *data, void *param);
59
Sylvain Munaut47193072009-12-27 21:56:14 +010060/* Real authentication information containing Ki */
61enum gsm_auth_algo {
62 AUTH_ALGO_NONE,
63 AUTH_ALGO_XOR,
64 AUTH_ALGO_COMP128v1,
65};
66
67struct gsm_auth_info {
68 enum gsm_auth_algo auth_algo;
69 unsigned int a3a8_ki_len;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020070 uint8_t a3a8_ki[16];
Sylvain Munaut47193072009-12-27 21:56:14 +010071};
72
73struct gsm_auth_tuple {
74 int use_count;
75 int key_seq;
Harald Welte121e9a42016-04-20 13:13:19 +020076 struct osmo_auth_vector vec;
Sylvain Munaut47193072009-12-27 21:56:14 +010077};
Sylvain Munautb48216f2010-06-09 12:45:37 +020078#define GSM_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
Sylvain Munaut47193072009-12-27 21:56:14 +010079
Holger Freyther73487a22008-12-31 18:53:57 +000080/*
Sylvain Munaut30a15382009-12-24 00:27:26 +010081 * AUTHENTICATION/CIPHERING state
82 */
83struct gsm_security_operation {
84 struct gsm_auth_tuple atuple;
85 gsm_cbfn *cb;
86 void *cb_data;
87};
88
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080089/*
90 * A dummy to keep a connection up for at least
91 * a couple of seconds to work around MSC issues.
92 */
93struct gsm_anchor_operation {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020094 struct osmo_timer_list timeout;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080095};
96
Harald Weltef7c28b02009-12-21 13:30:17 +010097/* Maximum number of neighbor cells whose average we track */
98#define MAX_NEIGH_MEAS 10
99/* Maximum size of the averaging window for neighbor cells */
100#define MAX_WIN_NEIGH_AVG 10
101
102/* processed neighbor measurements for one cell */
103struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200104 uint16_t arfcn;
105 uint8_t bsic;
106 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +0100107 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200108 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +0100109};
110
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100111enum ran_type {
112 RAN_UNKNOWN,
113 RAN_GERAN_A, /* 2G / A-interface */
114 RAN_UTRAN_IU, /* 3G / Iu-interface (IuCS or IuPS) */
115};
116
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200117extern const struct value_string ran_type_names[];
118static inline const char *ran_type_name(enum ran_type val)
119{ return get_value_string(ran_type_names, val); }
120
Harald Welte2483f1b2016-06-19 18:06:02 +0200121struct gsm_classmark {
122 bool classmark1_set;
123 struct gsm48_classmark1 classmark1;
124 uint8_t classmark2_len;
125 uint8_t classmark2[3];
126 uint8_t classmark3_len;
127 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
128};
129
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200130enum integrity_protection_state {
131 INTEGRITY_PROTECTION_NONE = 0,
132 INTEGRITY_PROTECTION_IK = 1,
133 INTEGRITY_PROTECTION_IK_CK = 2,
134};
135
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200136/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100137struct gsm_subscriber_connection {
Harald Welte2483f1b2016-06-19 18:06:02 +0200138 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800139 struct llist_head entry;
140
Harald Welte2483f1b2016-06-19 18:06:02 +0200141 /* usage count. If this drops to zero, we start the release
142 * towards A/Iu */
143 uint32_t use_count;
Neels Hofmeyr6166f292017-11-22 14:33:12 +0100144 uint32_t use_tokens;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100145
Harald Welte2483f1b2016-06-19 18:06:02 +0200146 /* The MS has opened the conn with a CM Service Request, and we shall
147 * keep it open for an actual request (or until timeout). */
148 bool received_cm_service_request;
149
Harald Welte2483f1b2016-06-19 18:06:02 +0200150 /* libmsc/libvlr subscriber information (if available) */
151 struct vlr_subscr *vsub;
152
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200153 /* LU expiration handling */
154 uint8_t expire_timer_stopped;
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100155 /* SMS helpers for libmsc */
156 uint8_t next_rp_ref;
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200157
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100158 /*
159 * Operations that have a state and might be pending
160 */
Sylvain Munaut30a15382009-12-24 00:27:26 +0100161 struct gsm_security_operation *sec_operation;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800162 struct gsm_anchor_operation *anch_operation;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100163
Harald Welte2483f1b2016-06-19 18:06:02 +0200164 struct osmo_fsm_inst *conn_fsm;
165
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100166 /* Are we part of a special "silent" call */
167 int silent_call;
168
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200169 /* MNCC rtp bridge markers */
170 int mncc_rtp_bridge;
171 int mncc_rtp_create_pending;
Holger Hans Peter Freytherc21dcb22015-08-04 14:41:21 +0200172 int mncc_rtp_connect_pending;
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200173
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100174 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200175 struct gsm_network *network;
176
Harald Welte2483f1b2016-06-19 18:06:02 +0200177 bool in_release;
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100178
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100179 /* connected via 2G or 3G? */
180 enum ran_type via_ran;
Harald Welte2483f1b2016-06-19 18:06:02 +0200181
182 struct gsm_classmark classmark;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200183
184 uint16_t lac;
185 struct gsm_encr encr;
186
Harald Weltec2007852018-02-03 21:08:26 +0100187 /* N(SD) expected in the received frame, per flow (TS 24.007 11.2.3.2.3.2.2) */
188 uint8_t n_sd_next[4];
189
Philipp Maierfbf66102017-04-09 12:32:51 +0200190 struct {
191 unsigned int mgcp_rtp_endpoint;
192 uint16_t port_subscr;
193 uint16_t port_cn;
194 } rtp;
195
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200196 /* which Iu-CS connection, if any. */
197 struct {
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200198 struct ranap_ue_conn_ctx *ue_ctx;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200199 uint8_t rab_id;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200200 } iu;
Philipp Maierfbf66102017-04-09 12:32:51 +0200201
202 struct {
203 /* A pointer to the SCCP user that handles
204 * the SCCP connections for this subscriber
205 * connection */
206 struct osmo_sccp_user *scu;
207
208 /* The address of the BSC that is associated
209 * with this subscriber connection */
210 struct osmo_sccp_addr bsc_addr;
211
212 /* The connection identifier that is used
213 * to reference the SCCP connection that is
214 * associated with this subscriber connection */
Philipp Maier64dbc542018-01-30 11:38:59 +0100215 uint32_t conn_id;
Philipp Maierfbf66102017-04-09 12:32:51 +0200216 } a;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100217};
218
Harald Weltef142c972011-05-24 13:25:38 +0200219
Alexander Couzensb847a212016-08-02 11:34:11 +0200220enum {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200221 MSC_CTR_LOC_UPDATE_TYPE_ATTACH,
222 MSC_CTR_LOC_UPDATE_TYPE_NORMAL,
223 MSC_CTR_LOC_UPDATE_TYPE_PERIODIC,
224 MSC_CTR_LOC_UPDATE_TYPE_DETACH,
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200225 MSC_CTR_LOC_UPDATE_FAILED,
226 MSC_CTR_LOC_UPDATE_COMPLETED,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200227 MSC_CTR_SMS_SUBMITTED,
228 MSC_CTR_SMS_NO_RECEIVER,
229 MSC_CTR_SMS_DELIVERED,
230 MSC_CTR_SMS_RP_ERR_MEM,
231 MSC_CTR_SMS_RP_ERR_OTHER,
Alexander Couzensaa386d22016-08-21 20:16:33 +0200232 MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200233 MSC_CTR_CALL_MO_SETUP,
234 MSC_CTR_CALL_MO_CONNECT_ACK,
235 MSC_CTR_CALL_MT_SETUP,
236 MSC_CTR_CALL_MT_CONNECT,
Alexander Couzens92f552f2016-08-23 07:32:27 +0200237 MSC_CTR_CALL_ACTIVE,
238 MSC_CTR_CALL_COMPLETE,
239 MSC_CTR_CALL_INCOMPLETE,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200240};
241
242static const struct rate_ctr_desc msc_ctr_description[] = {
Neels Hofmeyrc6bf2742017-11-18 23:22:17 +0100243 [MSC_CTR_LOC_UPDATE_TYPE_ATTACH] = {"loc_update_type:attach", "Received location update imsi attach requests."},
244 [MSC_CTR_LOC_UPDATE_TYPE_NORMAL] = {"loc_update_type:normal", "Received location update normal requests."},
245 [MSC_CTR_LOC_UPDATE_TYPE_PERIODIC] = {"loc_update_type:periodic", "Received location update periodic requests."},
246 [MSC_CTR_LOC_UPDATE_TYPE_DETACH] = {"loc_update_type:detach", "Received location update detach indication."},
247 [MSC_CTR_LOC_UPDATE_FAILED] = {"loc_update_resp:failed", "Rejected location updates."},
248 [MSC_CTR_LOC_UPDATE_COMPLETED] = {"loc_update_resp:completed", "Successful location updates."},
249 [MSC_CTR_SMS_SUBMITTED] = {"sms:submitted", "Received a RPDU from a MS (MO)."},
250 [MSC_CTR_SMS_NO_RECEIVER] = {"sms:no_receiver", "Counts SMS which couldn't routed because no receiver found."},
251 [MSC_CTR_SMS_DELIVERED] = {"sms:delivered", "Global SMS Deliver attempts."},
252 [MSC_CTR_SMS_RP_ERR_MEM] = {"sms:rp_err_mem", "CAUSE_MT_MEM_EXCEEDED errors of MS responses on a sms deliver attempt."},
253 [MSC_CTR_SMS_RP_ERR_OTHER] = {"sms:rp_err_other", "Other error of MS responses on a sms delive attempt."},
254 [MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR] = {"sms:deliver_unknown_error", "Unknown error occured during sms delivery."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200255 /* FIXME: count also sms delivered */
Neels Hofmeyrc6bf2742017-11-18 23:22:17 +0100256 [MSC_CTR_CALL_MO_SETUP] = {"call:mo_setup", "Received setup requests from a MS to init a MO call."},
257 [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."},
258 [MSC_CTR_CALL_MT_SETUP] = {"call:mt_setup", "Sent setup requests to the MS (MT)."},
259 [MSC_CTR_CALL_MT_CONNECT] = {"call:mt_connect", "Sent a connect to the MS (MT)."},
260 [MSC_CTR_CALL_ACTIVE] = {"call:active", "Count total amount of calls that ever reached active state."},
261 [MSC_CTR_CALL_COMPLETE] = {"call:complete", "Count total amount of calls which got terminated by disconnect req or ind after reaching active state."},
262 [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 +0200263};
264
Alexander Couzens20423ea2016-07-12 15:42:02 +0200265static const struct rate_ctr_group_desc msc_ctrg_desc = {
266 "msc",
267 "mobile switching center",
268 OSMO_STATS_CLASS_GLOBAL,
269 ARRAY_SIZE(msc_ctr_description),
270 msc_ctr_description,
Harald Welte24ff6ee2009-12-22 00:41:05 +0100271};
272
Harald Welte (local)69de3972009-08-12 14:42:23 +0200273enum gsm_auth_policy {
274 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
275 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
276 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
Maxddee01f2016-05-24 14:23:27 +0200277 GSM_AUTH_POLICY_REGEXP, /* accept IMSIs matching given regexp */
Harald Welte (local)69de3972009-08-12 14:42:23 +0200278};
279
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100280#define MSC_PAGING_RESPONSE_TIMER_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530281
Neels Hofmeyr73983952016-05-10 13:29:33 +0200282struct gsm_tz {
283 int override; /* if 0, use system's time zone instead. */
284 int hr; /* hour */
285 int mn; /* minute */
286 int dst; /* daylight savings */
287};
288
Harald Welte52b1f982008-12-23 20:25:15 +0000289struct gsm_network {
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200290 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
291 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
292 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
293 * these have in common, like country and network code, put in yet
294 * separate structs and placed as members in osmo_bsc and osmo_msc. */
295
Harald Welte52b1f982008-12-23 20:25:15 +0000296 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200297 uint16_t country_code;
298 uint16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000299 char *name_long;
300 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200301 enum gsm_auth_policy auth_policy;
Maxddee01f2016-05-24 14:23:27 +0200302 regex_t authorized_regexp;
303 char *authorized_reg_str;
Harald Welte1085c092009-11-18 20:33:19 +0100304 enum gsm48_reject_value reject_cause;
Harald Welte7b222aa2017-12-23 19:30:32 +0100305 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
306 uint8_t a5_encryption_mask;
Harald Welte2483f1b2016-06-19 18:06:02 +0200307 bool authentication_required;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100308 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100309 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100310 struct {
311 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100312 /* Window RXLEV averaging */
313 unsigned int win_rxlev_avg; /* number of SACCH frames */
314 /* Window RXQUAL averaging */
315 unsigned int win_rxqual_avg; /* number of SACCH frames */
316 /* Window RXLEV neighbouring cells averaging */
317 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
318
319 /* how often should we check for power budget HO */
320 unsigned int pwr_interval; /* SACCH frames */
321 /* how much better does a neighbor cell have to be ? */
322 unsigned int pwr_hysteresis; /* dBm */
323 /* maximum distacne before we try a handover */
324 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100325 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000326
Alexander Couzensb847a212016-08-02 11:34:11 +0200327 struct rate_ctr_group *bsc_ctrs;
328 struct rate_ctr_group *msc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200329 struct osmo_counter *active_calls;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100330
Harald Welte4bfdfe72009-06-10 23:11:52 +0800331 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200332 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200333 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800334 struct llist_head upqueue;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200335 /*
336 * TODO: Move the trans_list into the subscriber connection and
337 * create a pending list for MT transactions. These exist before
338 * we have a subscriber connection.
339 */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800340 struct llist_head trans_list;
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +0800341 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800342
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100343 unsigned int paging_response_timer;
Harald Welteeab84a12009-12-13 10:53:12 +0100344
Jan Luebbebfbdeec2012-12-27 00:27:16 +0100345 /* timer to expire old location updates */
346 struct osmo_timer_list subscr_expire_timer;
347
Harald Welteeab84a12009-12-13 10:53:12 +0100348 /* Radio Resource Location Protocol (TS 04.31) */
349 struct {
350 enum rrlp_mode mode;
351 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800352
Alexander Couzens11368112016-11-28 23:26:50 +0100353 enum gsm_chan_t ctype_by_chreq[18];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800354
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +0800355 /* Use a TCH for handling requests of type paging any */
356 int pag_any_tch;
357
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800358 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200359 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +0100360
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100361 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200362
363 /* control interface */
364 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200365
366 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
367 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +0200368
369 /* all active subscriber connections. */
370 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200371
372 /* if override is nonzero, this timezone data is used for all MM
373 * contexts. */
374 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
375 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100376 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200377 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100378
Harald Welte2483f1b2016-06-19 18:06:02 +0200379 /* MSC: GSUP server address of the HLR */
380 const char *gsup_server_addr_str;
381 uint16_t gsup_server_port;
382
383 struct vlr_instance *vlr;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200384
385 /* Periodic location update default value */
386 uint8_t t3212;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200387
388 struct {
Neels Hofmeyr6c8afe12017-09-04 01:03:58 +0200389 struct mgcp_client_conf conf;
390 struct mgcp_client *client;
391 } mgw;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200392
393 struct {
Philipp Maierfbf66102017-04-09 12:32:51 +0200394 /* CS7 instance id number (set via VTY) */
395 uint32_t cs7_instance;
Neels Hofmeyr00e82d62017-07-05 15:19:52 +0200396 int rab_assign_addr_enc;
Philipp Maierfbf66102017-04-09 12:32:51 +0200397 struct osmo_sccp_instance *sccp;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200398 } iu;
Philipp Maierfbf66102017-04-09 12:32:51 +0200399
400 struct {
401 /* CS7 instance id number (set via VTY) */
402 uint32_t cs7_instance;
403 /* A list with the context information about
404 * all BSCs we have connections with */
405 struct llist_head bscs;
406 struct osmo_sccp_instance *sccp;
407 } a;
Harald Welte52b1f982008-12-23 20:25:15 +0000408};
409
Harald Welted4bdee72012-11-08 19:44:08 +0100410struct osmo_esme;
411
412enum gsm_sms_source_id {
413 SMS_SOURCE_UNKNOWN = 0,
414 SMS_SOURCE_MS, /* received from MS */
415 SMS_SOURCE_VTY, /* received from VTY */
416 SMS_SOURCE_SMPP, /* received via SMPP */
417};
418
Harald Welte7e310b12009-03-30 20:56:32 +0000419#define SMS_HDR_SIZE 128
420#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100421
422struct gsm_sms_addr {
423 uint8_t ton;
424 uint8_t npi;
425 char addr[21+1];
426};
427
Harald Welte7e310b12009-03-30 20:56:32 +0000428struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900429 unsigned long long id;
Harald Welte2483f1b2016-06-19 18:06:02 +0200430 struct vlr_subscr *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100431 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100432 enum gsm_sms_source_id source;
433
434 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200435 uint8_t transaction_id;
436 uint32_t msg_ref;
437 } gsm411;
438
439 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100440 struct osmo_esme *esme;
441 uint32_t sequence_nr;
442 int transaction_mode;
443 char msg_id[16];
444 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000445
Harald Welteb9c758b2009-07-05 14:02:46 +0200446 unsigned long validity_minutes;
Keithc601adc2017-08-16 22:45:07 +0200447 time_t created;
Pablo Neira Ayusoadae8592017-08-07 14:01:30 +0100448 bool is_report;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200449 uint8_t reply_path_req;
450 uint8_t status_rep_req;
451 uint8_t ud_hdr_ind;
452 uint8_t protocol_id;
453 uint8_t data_coding_scheme;
454 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200455 uint8_t user_data_len;
456 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200457
Harald Welte7e310b12009-03-30 20:56:32 +0000458 char text[SMS_TEXT_SIZE];
459};
460
Neels Hofmeyrc13e6872016-05-11 13:53:47 +0200461extern void talloc_ctx_init(void *ctx_root);
462
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200463extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100464extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200465
Harald Welte (local)69de3972009-08-12 14:42:23 +0200466enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
467const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
468
Harald Welteeab84a12009-12-13 10:53:12 +0100469enum rrlp_mode rrlp_mode_parse(const char *arg);
470const char *rrlp_mode_name(enum rrlp_mode mode);
471
Neels Hofmeyr42eb0142016-05-20 17:15:44 +0200472struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
473void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +0800474
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100475/* control interface handling */
476int bsc_base_ctrl_cmds_install(void);
Harald Welte2483f1b2016-06-19 18:06:02 +0200477int msc_ctrl_cmds_install(struct gsm_network *net);
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100478
Harald Welte2483f1b2016-06-19 18:06:02 +0200479bool classmark_is_r99(struct gsm_classmark *cm);
480
Harald Welte6be350c2011-05-25 13:10:08 +0200481#endif /* _GSM_DATA_H */