blob: c307fee6ba581e2c15e73409f20d02b69e3cbecd [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>
Harald Weltef142c972011-05-24 13:25:38 +020015
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020016#include <openbsc/common.h>
Harald Welteb96be392011-05-25 12:33:33 +020017#include <openbsc/rest_octets.h>
Neels Hofmeyr402006d2016-05-11 14:28:25 +020018#include <openbsc/common_cs.h>
Neels Hofmeyr84da6b12016-05-20 21:59:55 +020019#include <openbsc/mgcpgw_client.h>
Harald Welteb96be392011-05-25 12:33:33 +020020
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020021/** annotations for msgb ownership */
22#define __uses
23
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010024#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
25
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020026struct mncc_sock_state;
Jacob Erlbeck1e30a282014-12-03 09:28:24 +010027struct gsm_subscriber_group;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010028struct bsc_subscr;
Harald Welte2483f1b2016-06-19 18:06:02 +020029struct vlr_instance;
30struct vlr_subscr;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +020031struct ue_conn_ctx;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020032
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080033#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
34
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010035#define tmsi_from_string(str) strtoul(str, NULL, 10)
36
Max70fdd242017-06-15 15:10:53 +020037/* 3-bit long values */
38#define EARFCN_PRIO_INVALID 8
39#define EARFCN_MEAS_BW_INVALID 8
40/* 5-bit long values */
41#define EARFCN_QRXLV_INVALID 32
42#define EARFCN_THRESH_LOW_INVALID 32
43
Sylvain Munaut30a15382009-12-24 00:27:26 +010044enum gsm_security_event {
45 GSM_SECURITY_NOAVAIL,
46 GSM_SECURITY_AUTH_FAILED,
47 GSM_SECURITY_SUCCEEDED,
Andreas Eversberg641475c2013-07-10 08:58:03 +020048 GSM_SECURITY_ALREADY,
Sylvain Munaut30a15382009-12-24 00:27:26 +010049};
50
Harald Welte8e1e3ee2009-02-01 13:32:45 +000051struct msgb;
52typedef int gsm_cbfn(unsigned int hooknum,
53 unsigned int event,
54 struct msgb *msg,
55 void *data, void *param);
56
Sylvain Munaut47193072009-12-27 21:56:14 +010057/* Real authentication information containing Ki */
58enum gsm_auth_algo {
59 AUTH_ALGO_NONE,
60 AUTH_ALGO_XOR,
61 AUTH_ALGO_COMP128v1,
62};
63
64struct gsm_auth_info {
65 enum gsm_auth_algo auth_algo;
66 unsigned int a3a8_ki_len;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020067 uint8_t a3a8_ki[16];
Sylvain Munaut47193072009-12-27 21:56:14 +010068};
69
70struct gsm_auth_tuple {
71 int use_count;
72 int key_seq;
Harald Welte121e9a42016-04-20 13:13:19 +020073 struct osmo_auth_vector vec;
Sylvain Munaut47193072009-12-27 21:56:14 +010074};
Sylvain Munautb48216f2010-06-09 12:45:37 +020075#define GSM_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
Sylvain Munaut47193072009-12-27 21:56:14 +010076
Holger Freyther73487a22008-12-31 18:53:57 +000077/*
Sylvain Munaut30a15382009-12-24 00:27:26 +010078 * AUTHENTICATION/CIPHERING state
79 */
80struct gsm_security_operation {
81 struct gsm_auth_tuple atuple;
82 gsm_cbfn *cb;
83 void *cb_data;
84};
85
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080086/*
87 * A dummy to keep a connection up for at least
88 * a couple of seconds to work around MSC issues.
89 */
90struct gsm_anchor_operation {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020091 struct osmo_timer_list timeout;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080092};
93
Harald Weltef7c28b02009-12-21 13:30:17 +010094/* Maximum number of neighbor cells whose average we track */
95#define MAX_NEIGH_MEAS 10
96/* Maximum size of the averaging window for neighbor cells */
97#define MAX_WIN_NEIGH_AVG 10
98
99/* processed neighbor measurements for one cell */
100struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200101 uint16_t arfcn;
102 uint8_t bsic;
103 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +0100104 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200105 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +0100106};
107
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100108enum ran_type {
109 RAN_UNKNOWN,
110 RAN_GERAN_A, /* 2G / A-interface */
111 RAN_UTRAN_IU, /* 3G / Iu-interface (IuCS or IuPS) */
112};
113
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200114extern const struct value_string ran_type_names[];
115static inline const char *ran_type_name(enum ran_type val)
116{ return get_value_string(ran_type_names, val); }
117
Harald Welte2483f1b2016-06-19 18:06:02 +0200118struct gsm_classmark {
119 bool classmark1_set;
120 struct gsm48_classmark1 classmark1;
121 uint8_t classmark2_len;
122 uint8_t classmark2[3];
123 uint8_t classmark3_len;
124 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
125};
126
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200127enum integrity_protection_state {
128 INTEGRITY_PROTECTION_NONE = 0,
129 INTEGRITY_PROTECTION_IK = 1,
130 INTEGRITY_PROTECTION_IK_CK = 2,
131};
132
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200133/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100134struct gsm_subscriber_connection {
Harald Welte2483f1b2016-06-19 18:06:02 +0200135 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800136 struct llist_head entry;
137
Harald Welte2483f1b2016-06-19 18:06:02 +0200138 /* usage count. If this drops to zero, we start the release
139 * towards A/Iu */
140 uint32_t use_count;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100141
Harald Welte2483f1b2016-06-19 18:06:02 +0200142 /* The MS has opened the conn with a CM Service Request, and we shall
143 * keep it open for an actual request (or until timeout). */
144 bool received_cm_service_request;
145
146 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100147 struct bsc_subscr *bsub;
148
Harald Welte2483f1b2016-06-19 18:06:02 +0200149 /* libmsc/libvlr subscriber information (if available) */
150 struct vlr_subscr *vsub;
151
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200152 /* LU expiration handling */
153 uint8_t expire_timer_stopped;
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100154 /* SMS helpers for libmsc */
155 uint8_t next_rp_ref;
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200156
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100157 /*
158 * Operations that have a state and might be pending
159 */
Sylvain Munaut30a15382009-12-24 00:27:26 +0100160 struct gsm_security_operation *sec_operation;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800161 struct gsm_anchor_operation *anch_operation;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100162
Harald Welte2483f1b2016-06-19 18:06:02 +0200163 struct osmo_fsm_inst *conn_fsm;
164
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100165 /* Are we part of a special "silent" call */
166 int silent_call;
167
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200168 /* MNCC rtp bridge markers */
169 int mncc_rtp_bridge;
170 int mncc_rtp_create_pending;
Holger Hans Peter Freytherc21dcb22015-08-04 14:41:21 +0200171 int mncc_rtp_connect_pending;
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200172
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800173 /* bsc structures */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200174 struct osmo_bsc_sccp_con *sccp_con; /* BSC */
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800175
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100176 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200177 struct gsm_network *network;
178
Harald Welte2483f1b2016-06-19 18:06:02 +0200179 bool in_release;
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200180 struct gsm_lchan *lchan; /* BSC */
181 struct gsm_lchan *ho_lchan; /* BSC */
182 struct gsm_bts *bts; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100183
184 /* for assignment handling */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200185 struct osmo_timer_list T10; /* BSC */
186 struct gsm_lchan *secondary_lchan; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100187
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100188 /* connected via 2G or 3G? */
189 enum ran_type via_ran;
Harald Welte2483f1b2016-06-19 18:06:02 +0200190
191 struct gsm_classmark classmark;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200192
193 uint16_t lac;
194 struct gsm_encr encr;
195
196 /* which Iu-CS connection, if any. */
197 struct {
198 struct ue_conn_ctx *ue_ctx;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200199 unsigned int mgcp_rtp_endpoint;
200 uint16_t mgcp_rtp_port_ue;
201 uint16_t mgcp_rtp_port_cn;
202 uint8_t rab_id;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200203 } iu;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100204};
205
Harald Weltef142c972011-05-24 13:25:38 +0200206
Harald Welte6be350c2011-05-25 13:10:08 +0200207#define ROLE_BSC
208#include "gsm_data_shared.h"
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100209
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100210
Alexander Couzens20423ea2016-07-12 15:42:02 +0200211enum {
Alexander Couzensb847a212016-08-02 11:34:11 +0200212 BSC_CTR_CHREQ_TOTAL,
213 BSC_CTR_CHREQ_NO_CHANNEL,
214 BSC_CTR_HANDOVER_ATTEMPTED,
215 BSC_CTR_HANDOVER_NO_CHANNEL,
216 BSC_CTR_HANDOVER_TIMEOUT,
217 BSC_CTR_HANDOVER_COMPLETED,
218 BSC_CTR_HANDOVER_FAILED,
219 BSC_CTR_PAGING_ATTEMPTED,
220 BSC_CTR_PAGING_DETACHED,
221 BSC_CTR_PAGING_COMPLETED,
222 BSC_CTR_PAGING_EXPIRED,
223 BSC_CTR_CHAN_RF_FAIL,
224 BSC_CTR_CHAN_RLL_ERR,
225 BSC_CTR_BTS_OML_FAIL,
226 BSC_CTR_BTS_RSL_FAIL,
Alexander Couzens8c53c592016-08-23 06:27:19 +0200227 BSC_CTR_CODEC_AMR_F,
228 BSC_CTR_CODEC_AMR_H,
229 BSC_CTR_CODEC_EFR,
230 BSC_CTR_CODEC_V1_FR,
231 BSC_CTR_CODEC_V1_HR,
Alexander Couzensb847a212016-08-02 11:34:11 +0200232};
233
234static const struct rate_ctr_desc bsc_ctr_description[] = {
235 [BSC_CTR_CHREQ_TOTAL] = {"chreq.total", "Received channel requests."},
236 [BSC_CTR_CHREQ_NO_CHANNEL] = {"chreq.no_channel", "Sent to MS no channel available."},
237 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover.attempted", "Received handover attempts."},
238 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover.no_channel", "Sent no channel available responses."},
239 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover.timeout", "Count the amount of timeouts of timer T3103."},
240 [BSC_CTR_HANDOVER_COMPLETED] = {"handover.completed", "Received handover completed."},
241 [BSC_CTR_HANDOVER_FAILED] = {"handover.failed", "Receive HO FAIL messages."},
242 [BSC_CTR_PAGING_ATTEMPTED] = {"paging.attempted", "Paging attempts for a MS."},
243 [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."},
244 [BSC_CTR_PAGING_COMPLETED] = {"paging.completed", "Paging successful completed."},
245 [BSC_CTR_PAGING_EXPIRED] = {"paging.expired", "Paging Request expired because of timeout T3113."},
246 [BSC_CTR_CHAN_RF_FAIL] = {"chan.rf_fail", "Received a RF failure indication from BTS."},
247 [BSC_CTR_CHAN_RLL_ERR] = {"chan.rll_err", "Received a RLL failure with T200 cause from BTS."},
248 [BSC_CTR_BTS_OML_FAIL] = {"bts.oml_fail", "Received a TEI down on a OML link."},
249 [BSC_CTR_BTS_RSL_FAIL] = {"bts.rsl_fail", "Received a TEI down on a OML link."},
Alexander Couzens8c53c592016-08-23 06:27:19 +0200250 [BSC_CTR_CODEC_AMR_F] = {"bts.codec_amr_f", "Count the usage of AMR/F codec by channel mode requested."},
251 [BSC_CTR_CODEC_AMR_H] = {"bts.codec_amr_h", "Count the usage of AMR/H codec by channel mode requested."},
252 [BSC_CTR_CODEC_EFR] = {"bts.codec_efr", "Count the usage of EFR codec by channel mode requested."},
253 [BSC_CTR_CODEC_V1_FR] = {"bts.codec_fr", "Count the usage of FR codec by channel mode requested."},
254 [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 +0200255};
256
257enum {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200258 MSC_CTR_LOC_UPDATE_TYPE_ATTACH,
259 MSC_CTR_LOC_UPDATE_TYPE_NORMAL,
260 MSC_CTR_LOC_UPDATE_TYPE_PERIODIC,
261 MSC_CTR_LOC_UPDATE_TYPE_DETACH,
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200262 MSC_CTR_LOC_UPDATE_FAILED,
263 MSC_CTR_LOC_UPDATE_COMPLETED,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200264 MSC_CTR_SMS_SUBMITTED,
265 MSC_CTR_SMS_NO_RECEIVER,
266 MSC_CTR_SMS_DELIVERED,
267 MSC_CTR_SMS_RP_ERR_MEM,
268 MSC_CTR_SMS_RP_ERR_OTHER,
Alexander Couzensaa386d22016-08-21 20:16:33 +0200269 MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200270 MSC_CTR_CALL_MO_SETUP,
271 MSC_CTR_CALL_MO_CONNECT_ACK,
272 MSC_CTR_CALL_MT_SETUP,
273 MSC_CTR_CALL_MT_CONNECT,
Alexander Couzens92f552f2016-08-23 07:32:27 +0200274 MSC_CTR_CALL_ACTIVE,
275 MSC_CTR_CALL_COMPLETE,
276 MSC_CTR_CALL_INCOMPLETE,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200277};
278
279static const struct rate_ctr_desc msc_ctr_description[] = {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200280 [MSC_CTR_LOC_UPDATE_TYPE_ATTACH] = {"loc_update_type.attach", "Received location update imsi attach requests."},
281 [MSC_CTR_LOC_UPDATE_TYPE_NORMAL] = {"loc_update_type.normal", "Received location update normal requests."},
282 [MSC_CTR_LOC_UPDATE_TYPE_PERIODIC] = {"loc_update_type.periodic", "Received location update periodic requests."},
283 [MSC_CTR_LOC_UPDATE_TYPE_DETACH] = {"loc_update_type.detach", "Received location update detach indication."},
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200284 [MSC_CTR_LOC_UPDATE_FAILED] = {"loc_update_resp.failed", "Rejected location updates."},
285 [MSC_CTR_LOC_UPDATE_COMPLETED] = {"loc_update_resp.completed", "Successful location updates."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200286 [MSC_CTR_SMS_SUBMITTED] = {"sms.submitted", "Received a RPDU from a MS (MO)."},
287 [MSC_CTR_SMS_NO_RECEIVER] = {"sms.no_receiver", "Counts SMS which couldn't routed because no receiver found."},
288 [MSC_CTR_SMS_DELIVERED] = {"sms.delivered", "Global SMS Deliver attempts."},
289 [MSC_CTR_SMS_RP_ERR_MEM] = {"sms.rp_err_mem", "CAUSE_MT_MEM_EXCEEDED errors of MS responses on a sms deliver attempt."},
290 [MSC_CTR_SMS_RP_ERR_OTHER] = {"sms.rp_err_other", "Other error of MS responses on a sms delive attempt."},
Alexander Couzensaa386d22016-08-21 20:16:33 +0200291 [MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR] = {"sms.deliver_unknown_error", "Unknown error occured during sms delivery."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200292 /* FIXME: count also sms delivered */
293 [MSC_CTR_CALL_MO_SETUP] = {"call.mo_setup", "Received setup requests from a MS to init a MO call."},
294 [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."},
295 [MSC_CTR_CALL_MT_SETUP] = {"call.mt_setup", "Sent setup requests to the MS (MT)."},
296 [MSC_CTR_CALL_MT_CONNECT] = {"call.mt_connect", "Sent a connect to the MS (MT)."},
Alexander Couzens92f552f2016-08-23 07:32:27 +0200297 [MSC_CTR_CALL_ACTIVE] = {"call.active", "Count total amount of calls that ever reached active state."},
298 [MSC_CTR_CALL_COMPLETE] = {"call.complete", "Count total amount of calls which got terminated by disconnect req or ind after reaching active state."},
299 [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 +0200300};
301
302
303static const struct rate_ctr_group_desc bsc_ctrg_desc = {
304 "bsc",
305 "base station controller",
306 OSMO_STATS_CLASS_GLOBAL,
307 ARRAY_SIZE(bsc_ctr_description),
308 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200309};
310
311static const struct rate_ctr_group_desc msc_ctrg_desc = {
312 "msc",
313 "mobile switching center",
314 OSMO_STATS_CLASS_GLOBAL,
315 ARRAY_SIZE(msc_ctr_description),
316 msc_ctr_description,
Harald Welte24ff6ee2009-12-22 00:41:05 +0100317};
318
Harald Welte (local)69de3972009-08-12 14:42:23 +0200319enum gsm_auth_policy {
320 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
321 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
322 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
Maxddee01f2016-05-24 14:23:27 +0200323 GSM_AUTH_POLICY_REGEXP, /* accept IMSIs matching given regexp */
Harald Welte (local)69de3972009-08-12 14:42:23 +0200324};
325
Harald Welteb84ddfc2009-12-01 17:36:54 +0530326#define GSM_T3101_DEFAULT 10
Harald Welte67161f22012-06-03 13:01:47 +0200327#define GSM_T3105_DEFAULT 40
Harald Welteb84ddfc2009-12-01 17:36:54 +0530328#define GSM_T3113_DEFAULT 60
Andreas Eversberg75e13a42013-02-07 11:51:16 +0100329#define GSM_T3122_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530330
Neels Hofmeyr73983952016-05-10 13:29:33 +0200331struct gsm_tz {
332 int override; /* if 0, use system's time zone instead. */
333 int hr; /* hour */
334 int mn; /* minute */
335 int dst; /* daylight savings */
336};
337
Harald Welte52b1f982008-12-23 20:25:15 +0000338struct gsm_network {
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200339 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
340 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
341 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
342 * these have in common, like country and network code, put in yet
343 * separate structs and placed as members in osmo_bsc and osmo_msc. */
344
Harald Welte52b1f982008-12-23 20:25:15 +0000345 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200346 uint16_t country_code;
347 uint16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000348 char *name_long;
349 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200350 enum gsm_auth_policy auth_policy;
Maxddee01f2016-05-24 14:23:27 +0200351 regex_t authorized_regexp;
352 char *authorized_reg_str;
Harald Welte1085c092009-11-18 20:33:19 +0100353 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900354 int a5_encryption;
Harald Welte2483f1b2016-06-19 18:06:02 +0200355 bool authentication_required;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100356 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100357 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100358 struct {
359 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100360 /* Window RXLEV averaging */
361 unsigned int win_rxlev_avg; /* number of SACCH frames */
362 /* Window RXQUAL averaging */
363 unsigned int win_rxqual_avg; /* number of SACCH frames */
364 /* Window RXLEV neighbouring cells averaging */
365 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
366
367 /* how often should we check for power budget HO */
368 unsigned int pwr_interval; /* SACCH frames */
369 /* how much better does a neighbor cell have to be ? */
370 unsigned int pwr_hysteresis; /* dBm */
371 /* maximum distacne before we try a handover */
372 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100373 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000374
Alexander Couzensb847a212016-08-02 11:34:11 +0200375 struct rate_ctr_group *bsc_ctrs;
376 struct rate_ctr_group *msc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200377 struct osmo_counter *active_calls;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100378
Harald Welte4bfdfe72009-06-10 23:11:52 +0800379 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200380 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200381 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800382 struct llist_head upqueue;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200383 /*
384 * TODO: Move the trans_list into the subscriber connection and
385 * create a pending list for MT transactions. These exist before
386 * we have a subscriber connection.
387 */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800388 struct llist_head trans_list;
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +0800389 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800390
Harald Welte52b1f982008-12-23 20:25:15 +0000391 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200392 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100393
394 /* timer values */
395 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100396 int T3103;
397 int T3105;
398 int T3107;
399 int T3109;
400 int T3111;
401 int T3113;
402 int T3115;
403 int T3117;
404 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +0100405 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100406 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100407
Jan Luebbebfbdeec2012-12-27 00:27:16 +0100408 /* timer to expire old location updates */
409 struct osmo_timer_list subscr_expire_timer;
410
Harald Welteeab84a12009-12-13 10:53:12 +0100411 /* Radio Resource Location Protocol (TS 04.31) */
412 struct {
413 enum rrlp_mode mode;
414 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800415
Alexander Couzens11368112016-11-28 23:26:50 +0100416 enum gsm_chan_t ctype_by_chreq[18];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800417
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +0800418 /* Use a TCH for handling requests of type paging any */
419 int pag_any_tch;
420
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800421 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200422 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +0100423
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100424 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200425
426 /* control interface */
427 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200428
429 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
430 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +0200431
432 /* all active subscriber connections. */
433 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200434
435 /* if override is nonzero, this timezone data is used for all MM
436 * contexts. */
437 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
438 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100439 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200440 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100441
442 /* List of all struct bsc_subscr used in libbsc. This llist_head is
443 * allocated so that the llist_head pointer itself can serve as a
444 * talloc context (useful to not have to pass the entire gsm_network
445 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
446 * not require gsm_data.h). In an MSC-without-BSC environment, this
447 * pointer is NULL to indicate absence of a bsc_subscribers list. */
448 struct llist_head *bsc_subscribers;
Harald Welte2483f1b2016-06-19 18:06:02 +0200449
450 /* MSC: GSUP server address of the HLR */
451 const char *gsup_server_addr_str;
452 uint16_t gsup_server_port;
453
454 struct vlr_instance *vlr;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200455
456 /* Periodic location update default value */
457 uint8_t t3212;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200458
459 struct {
460 struct mgcpgw_client_conf conf;
461 struct mgcpgw_client *client;
462 } mgcpgw;
463
464 struct {
465 enum nsap_addr_enc rab_assign_addr_enc;
466 } iu;
Harald Welte52b1f982008-12-23 20:25:15 +0000467};
468
Harald Welted4bdee72012-11-08 19:44:08 +0100469struct osmo_esme;
470
471enum gsm_sms_source_id {
472 SMS_SOURCE_UNKNOWN = 0,
473 SMS_SOURCE_MS, /* received from MS */
474 SMS_SOURCE_VTY, /* received from VTY */
475 SMS_SOURCE_SMPP, /* received via SMPP */
476};
477
Harald Welte7e310b12009-03-30 20:56:32 +0000478#define SMS_HDR_SIZE 128
479#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100480
481struct gsm_sms_addr {
482 uint8_t ton;
483 uint8_t npi;
484 char addr[21+1];
485};
486
Harald Welte7e310b12009-03-30 20:56:32 +0000487struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900488 unsigned long long id;
Harald Welte2483f1b2016-06-19 18:06:02 +0200489 struct vlr_subscr *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100490 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100491 enum gsm_sms_source_id source;
492
493 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200494 uint8_t transaction_id;
495 uint32_t msg_ref;
496 } gsm411;
497
498 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100499 struct osmo_esme *esme;
500 uint32_t sequence_nr;
501 int transaction_mode;
502 char msg_id[16];
503 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000504
Harald Welteb9c758b2009-07-05 14:02:46 +0200505 unsigned long validity_minutes;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200506 uint8_t reply_path_req;
507 uint8_t status_rep_req;
508 uint8_t ud_hdr_ind;
509 uint8_t protocol_id;
510 uint8_t data_coding_scheme;
511 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200512 uint8_t user_data_len;
513 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200514
Harald Welte7e310b12009-03-30 20:56:32 +0000515 char text[SMS_TEXT_SIZE];
516};
517
Neels Hofmeyrc13e6872016-05-11 13:53:47 +0200518extern void talloc_ctx_init(void *ctx_root);
519
Harald Welte39315c42010-01-10 18:01:52 +0100520int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200521
Harald Welte1d014a52009-08-08 15:38:29 +0200522enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200523const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000524struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
525 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000526
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200527extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100528extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200529
Harald Weltef383aa12012-07-02 19:51:55 +0200530/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +0000531static inline int is_ipaccess_bts(struct gsm_bts *bts)
532{
533 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100534 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +0100535 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000536 return 1;
537 default:
538 break;
539 }
540 return 0;
541}
542
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200543static inline int is_sysmobts_v2(struct gsm_bts *bts)
544{
545 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +0100546 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200547 return 1;
548 default:
549 break;
550 }
551 return 0;
552}
553
Harald Welte5b570672009-08-10 10:08:01 +0200554static inline int is_siemens_bts(struct gsm_bts *bts)
555{
556 switch (bts->type) {
557 case GSM_BTS_TYPE_BS11:
558 return 1;
559 default:
560 break;
561 }
562
563 return 0;
564}
565
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100566static inline int is_nokia_bts(struct gsm_bts *bts)
567{
568 switch (bts->type) {
569 case GSM_BTS_TYPE_NOKIA_SITE:
570 return 1;
571 default:
572 break;
573 }
574
575 return 0;
576}
577
Andreas Eversbergdcf38e12013-12-05 14:37:11 +0100578static inline int is_e1_bts(struct gsm_bts *bts)
579{
580 switch (bts->type) {
581 case GSM_BTS_TYPE_BS11:
582 case GSM_BTS_TYPE_RBS2000:
583 case GSM_BTS_TYPE_NOKIA_SITE:
584 return 1;
585 default:
586 break;
587 }
588
589 return 0;
590}
591
Harald Welte (local)69de3972009-08-12 14:42:23 +0200592enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
593const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
594
Harald Welteeab84a12009-12-13 10:53:12 +0100595enum rrlp_mode rrlp_mode_parse(const char *arg);
596const char *rrlp_mode_name(enum rrlp_mode mode);
597
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100598enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +0200599const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100600int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +0200601
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200602int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +0800603void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +0100604
Harald Weltef3d8e922010-06-14 22:44:42 +0200605int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Weltefbda4e12010-03-04 11:04:52 +0100606int gsm_bts_model_register(struct gsm_bts_model *model);
607
Neels Hofmeyr42eb0142016-05-20 17:15:44 +0200608struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
609void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
610
611struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
612void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +0800613
Harald Welte3300c012011-06-05 13:31:33 +0200614struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
615 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100616 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +0100617
Harald Welte3300c012011-06-05 13:31:33 +0200618void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
619 uint8_t e1_ts, uint8_t e1_ts_ss);
620
621void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
Max71d082b2017-05-30 15:03:38 +0200622bool gsm_btsmodel_has_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Welte3300c012011-06-05 13:31:33 +0200623struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +0100624int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -0400625int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +0200626
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200627/* generic E1 line operations for all ISDN-based BTS. */
628extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
629
Harald Weltee555c2b2012-08-17 13:02:12 +0200630extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
631extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
632
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100633/* control interface handling */
634int bsc_base_ctrl_cmds_install(void);
Harald Welte2483f1b2016-06-19 18:06:02 +0200635int msc_ctrl_cmds_install(struct gsm_network *net);
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100636
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100637/* dependency handling */
638void bts_depend_mark(struct gsm_bts *bts, int dep);
639void bts_depend_clear(struct gsm_bts *bts, int dep);
640int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +0100641int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100642
Harald Welte2f8b9d22017-06-18 11:12:13 +0300643int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
644void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
645
Harald Welte2483f1b2016-06-19 18:06:02 +0200646bool classmark_is_r99(struct gsm_classmark *cm);
647
Harald Welte6be350c2011-05-25 13:10:08 +0200648#endif /* _GSM_DATA_H */