blob: 429526dece5045a3241ac4bbcba887b764312a82 [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
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 Hofmeyrc29505e2016-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 Weltea43e0b42016-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 Hofmeyrce4d88b2017-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 Weltea43e0b42016-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 Weltea43e0b42016-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;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100142
Harald Weltea43e0b42016-06-19 18:06:02 +0200143 /* The MS has opened the conn with a CM Service Request, and we shall
144 * keep it open for an actual request (or until timeout). */
145 bool received_cm_service_request;
146
147 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100148 struct bsc_subscr *bsub;
149
Harald Weltea43e0b42016-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 Weltea43e0b42016-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 Freyther2f9d1ef2010-09-16 20:14:01 +0800174 /* bsc structures */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200175 struct osmo_bsc_sccp_con *sccp_con; /* BSC */
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800176
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100177 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200178 struct gsm_network *network;
179
Harald Weltea43e0b42016-06-19 18:06:02 +0200180 bool in_release;
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200181 struct gsm_lchan *lchan; /* BSC */
182 struct gsm_lchan *ho_lchan; /* BSC */
183 struct gsm_bts *bts; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100184
185 /* for assignment handling */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200186 struct osmo_timer_list T10; /* BSC */
187 struct gsm_lchan *secondary_lchan; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100188
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100189 /* connected via 2G or 3G? */
190 enum ran_type via_ran;
Harald Weltea43e0b42016-06-19 18:06:02 +0200191
192 struct gsm_classmark classmark;
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200193
194 uint16_t lac;
195 struct gsm_encr encr;
196
Philipp Maier39f62bb2017-04-09 12:32:51 +0200197 struct {
198 unsigned int mgcp_rtp_endpoint;
199 uint16_t port_subscr;
200 uint16_t port_cn;
201 } rtp;
202
Philipp Maier39f62bb2017-04-09 12:32:51 +0200203 struct {
204 /* A pointer to the SCCP user that handles
205 * the SCCP connections for this subscriber
206 * connection */
207 struct osmo_sccp_user *scu;
208
209 /* The address of the BSC that is associated
210 * with this subscriber connection */
211 struct osmo_sccp_addr bsc_addr;
212
213 /* The connection identifier that is used
214 * to reference the SCCP connection that is
215 * associated with this subscriber connection */
216 int conn_id;
217 } a;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100218};
219
Harald Weltef142c972011-05-24 13:25:38 +0200220
Harald Welte6be350c2011-05-25 13:10:08 +0200221#define ROLE_BSC
222#include "gsm_data_shared.h"
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100223
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100224
Alexander Couzens20423ea2016-07-12 15:42:02 +0200225enum {
Alexander Couzensb847a212016-08-02 11:34:11 +0200226 BSC_CTR_CHREQ_TOTAL,
227 BSC_CTR_CHREQ_NO_CHANNEL,
228 BSC_CTR_HANDOVER_ATTEMPTED,
229 BSC_CTR_HANDOVER_NO_CHANNEL,
230 BSC_CTR_HANDOVER_TIMEOUT,
231 BSC_CTR_HANDOVER_COMPLETED,
232 BSC_CTR_HANDOVER_FAILED,
233 BSC_CTR_PAGING_ATTEMPTED,
234 BSC_CTR_PAGING_DETACHED,
235 BSC_CTR_PAGING_COMPLETED,
236 BSC_CTR_PAGING_EXPIRED,
237 BSC_CTR_CHAN_RF_FAIL,
238 BSC_CTR_CHAN_RLL_ERR,
239 BSC_CTR_BTS_OML_FAIL,
240 BSC_CTR_BTS_RSL_FAIL,
Alexander Couzens8c53c592016-08-23 06:27:19 +0200241 BSC_CTR_CODEC_AMR_F,
242 BSC_CTR_CODEC_AMR_H,
243 BSC_CTR_CODEC_EFR,
244 BSC_CTR_CODEC_V1_FR,
245 BSC_CTR_CODEC_V1_HR,
Alexander Couzensb847a212016-08-02 11:34:11 +0200246};
247
248static const struct rate_ctr_desc bsc_ctr_description[] = {
249 [BSC_CTR_CHREQ_TOTAL] = {"chreq.total", "Received channel requests."},
250 [BSC_CTR_CHREQ_NO_CHANNEL] = {"chreq.no_channel", "Sent to MS no channel available."},
251 [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."},
256 [BSC_CTR_PAGING_ATTEMPTED] = {"paging.attempted", "Paging attempts for a MS."},
257 [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."},
258 [BSC_CTR_PAGING_COMPLETED] = {"paging.completed", "Paging successful completed."},
259 [BSC_CTR_PAGING_EXPIRED] = {"paging.expired", "Paging Request expired because of timeout T3113."},
260 [BSC_CTR_CHAN_RF_FAIL] = {"chan.rf_fail", "Received a RF failure indication from BTS."},
261 [BSC_CTR_CHAN_RLL_ERR] = {"chan.rll_err", "Received a RLL failure with T200 cause from BTS."},
262 [BSC_CTR_BTS_OML_FAIL] = {"bts.oml_fail", "Received a TEI down on a OML link."},
263 [BSC_CTR_BTS_RSL_FAIL] = {"bts.rsl_fail", "Received a TEI down on a OML link."},
Alexander Couzens8c53c592016-08-23 06:27:19 +0200264 [BSC_CTR_CODEC_AMR_F] = {"bts.codec_amr_f", "Count the usage of AMR/F codec by channel mode requested."},
265 [BSC_CTR_CODEC_AMR_H] = {"bts.codec_amr_h", "Count the usage of AMR/H codec by channel mode requested."},
266 [BSC_CTR_CODEC_EFR] = {"bts.codec_efr", "Count the usage of EFR codec by channel mode requested."},
267 [BSC_CTR_CODEC_V1_FR] = {"bts.codec_fr", "Count the usage of FR codec by channel mode requested."},
268 [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 +0200269};
270
271enum {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200272 MSC_CTR_LOC_UPDATE_TYPE_ATTACH,
273 MSC_CTR_LOC_UPDATE_TYPE_NORMAL,
274 MSC_CTR_LOC_UPDATE_TYPE_PERIODIC,
275 MSC_CTR_LOC_UPDATE_TYPE_DETACH,
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200276 MSC_CTR_LOC_UPDATE_FAILED,
277 MSC_CTR_LOC_UPDATE_COMPLETED,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200278 MSC_CTR_SMS_SUBMITTED,
279 MSC_CTR_SMS_NO_RECEIVER,
280 MSC_CTR_SMS_DELIVERED,
281 MSC_CTR_SMS_RP_ERR_MEM,
282 MSC_CTR_SMS_RP_ERR_OTHER,
Alexander Couzensaa386d22016-08-21 20:16:33 +0200283 MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200284 MSC_CTR_CALL_MO_SETUP,
285 MSC_CTR_CALL_MO_CONNECT_ACK,
286 MSC_CTR_CALL_MT_SETUP,
287 MSC_CTR_CALL_MT_CONNECT,
Alexander Couzens92f552f2016-08-23 07:32:27 +0200288 MSC_CTR_CALL_ACTIVE,
289 MSC_CTR_CALL_COMPLETE,
290 MSC_CTR_CALL_INCOMPLETE,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200291};
292
293static const struct rate_ctr_desc msc_ctr_description[] = {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200294 [MSC_CTR_LOC_UPDATE_TYPE_ATTACH] = {"loc_update_type.attach", "Received location update imsi attach requests."},
295 [MSC_CTR_LOC_UPDATE_TYPE_NORMAL] = {"loc_update_type.normal", "Received location update normal requests."},
296 [MSC_CTR_LOC_UPDATE_TYPE_PERIODIC] = {"loc_update_type.periodic", "Received location update periodic requests."},
297 [MSC_CTR_LOC_UPDATE_TYPE_DETACH] = {"loc_update_type.detach", "Received location update detach indication."},
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200298 [MSC_CTR_LOC_UPDATE_FAILED] = {"loc_update_resp.failed", "Rejected location updates."},
299 [MSC_CTR_LOC_UPDATE_COMPLETED] = {"loc_update_resp.completed", "Successful location updates."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200300 [MSC_CTR_SMS_SUBMITTED] = {"sms.submitted", "Received a RPDU from a MS (MO)."},
301 [MSC_CTR_SMS_NO_RECEIVER] = {"sms.no_receiver", "Counts SMS which couldn't routed because no receiver found."},
302 [MSC_CTR_SMS_DELIVERED] = {"sms.delivered", "Global SMS Deliver attempts."},
303 [MSC_CTR_SMS_RP_ERR_MEM] = {"sms.rp_err_mem", "CAUSE_MT_MEM_EXCEEDED errors of MS responses on a sms deliver attempt."},
304 [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 +0200305 [MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR] = {"sms.deliver_unknown_error", "Unknown error occured during sms delivery."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200306 /* FIXME: count also sms delivered */
307 [MSC_CTR_CALL_MO_SETUP] = {"call.mo_setup", "Received setup requests from a MS to init a MO call."},
308 [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."},
309 [MSC_CTR_CALL_MT_SETUP] = {"call.mt_setup", "Sent setup requests to the MS (MT)."},
310 [MSC_CTR_CALL_MT_CONNECT] = {"call.mt_connect", "Sent a connect to the MS (MT)."},
Alexander Couzens92f552f2016-08-23 07:32:27 +0200311 [MSC_CTR_CALL_ACTIVE] = {"call.active", "Count total amount of calls that ever reached active state."},
312 [MSC_CTR_CALL_COMPLETE] = {"call.complete", "Count total amount of calls which got terminated by disconnect req or ind after reaching active state."},
313 [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 +0200314};
315
316
317static const struct rate_ctr_group_desc bsc_ctrg_desc = {
318 "bsc",
319 "base station controller",
320 OSMO_STATS_CLASS_GLOBAL,
321 ARRAY_SIZE(bsc_ctr_description),
322 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200323};
324
325static const struct rate_ctr_group_desc msc_ctrg_desc = {
326 "msc",
327 "mobile switching center",
328 OSMO_STATS_CLASS_GLOBAL,
329 ARRAY_SIZE(msc_ctr_description),
330 msc_ctr_description,
Harald Welte24ff6ee2009-12-22 00:41:05 +0100331};
332
Harald Welte (local)69de3972009-08-12 14:42:23 +0200333enum gsm_auth_policy {
334 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
335 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
336 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
Maxddee01f2016-05-24 14:23:27 +0200337 GSM_AUTH_POLICY_REGEXP, /* accept IMSIs matching given regexp */
Harald Welte (local)69de3972009-08-12 14:42:23 +0200338};
339
Harald Weltea0d324b2017-07-20 01:47:39 +0200340#define GSM_T3101_DEFAULT 10 /* s */
341#define GSM_T3103_DEFAULT 5 /* s */
342#define GSM_T3105_DEFAULT 100 /* ms */
343#define GSM_T3107_DEFAULT 5 /* s */
344#define GSM_T3109_DEFAULT 19 /* s, must be 2s + radio_link_timeout*0.48 */
345#define GSM_T3111_DEFAULT 2 /* s */
Harald Welteb84ddfc2009-12-01 17:36:54 +0530346#define GSM_T3113_DEFAULT 60
Harald Weltea0d324b2017-07-20 01:47:39 +0200347#define GSM_T3115_DEFAULT 10
348#define GSM_T3117_DEFAULT 10
349#define GSM_T3119_DEFAULT 10
Andreas Eversberg75e13a42013-02-07 11:51:16 +0100350#define GSM_T3122_DEFAULT 10
Harald Weltea0d324b2017-07-20 01:47:39 +0200351#define GSM_T3141_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530352
Neels Hofmeyr73983952016-05-10 13:29:33 +0200353struct gsm_tz {
354 int override; /* if 0, use system's time zone instead. */
355 int hr; /* hour */
356 int mn; /* minute */
357 int dst; /* daylight savings */
358};
359
Harald Welte52b1f982008-12-23 20:25:15 +0000360struct gsm_network {
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200361 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
362 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
363 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
364 * these have in common, like country and network code, put in yet
365 * separate structs and placed as members in osmo_bsc and osmo_msc. */
366
Harald Welte52b1f982008-12-23 20:25:15 +0000367 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200368 uint16_t country_code;
369 uint16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000370 char *name_long;
371 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200372 enum gsm_auth_policy auth_policy;
Maxddee01f2016-05-24 14:23:27 +0200373 regex_t authorized_regexp;
374 char *authorized_reg_str;
Harald Welte1085c092009-11-18 20:33:19 +0100375 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900376 int a5_encryption;
Harald Weltea43e0b42016-06-19 18:06:02 +0200377 bool authentication_required;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100378 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100379 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100380 struct {
381 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100382 /* Window RXLEV averaging */
383 unsigned int win_rxlev_avg; /* number of SACCH frames */
384 /* Window RXQUAL averaging */
385 unsigned int win_rxqual_avg; /* number of SACCH frames */
386 /* Window RXLEV neighbouring cells averaging */
387 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
388
389 /* how often should we check for power budget HO */
390 unsigned int pwr_interval; /* SACCH frames */
391 /* how much better does a neighbor cell have to be ? */
392 unsigned int pwr_hysteresis; /* dBm */
393 /* maximum distacne before we try a handover */
394 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100395 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000396
Alexander Couzensb847a212016-08-02 11:34:11 +0200397 struct rate_ctr_group *bsc_ctrs;
398 struct rate_ctr_group *msc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200399 struct osmo_counter *active_calls;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100400
Harald Welte4bfdfe72009-06-10 23:11:52 +0800401 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200402 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200403 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800404 struct llist_head upqueue;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +0200405 /*
406 * TODO: Move the trans_list into the subscriber connection and
407 * create a pending list for MT transactions. These exist before
408 * we have a subscriber connection.
409 */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800410 struct llist_head trans_list;
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +0800411 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800412
Harald Welte52b1f982008-12-23 20:25:15 +0000413 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200414 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100415
416 /* timer values */
417 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100418 int T3103;
419 int T3105;
420 int T3107;
421 int T3109;
422 int T3111;
423 int T3113;
424 int T3115;
425 int T3117;
426 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +0100427 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100428 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100429
Jan Luebbebfbdeec2012-12-27 00:27:16 +0100430 /* timer to expire old location updates */
431 struct osmo_timer_list subscr_expire_timer;
432
Harald Welteeab84a12009-12-13 10:53:12 +0100433 /* Radio Resource Location Protocol (TS 04.31) */
434 struct {
435 enum rrlp_mode mode;
436 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800437
Alexander Couzens11368112016-11-28 23:26:50 +0100438 enum gsm_chan_t ctype_by_chreq[18];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800439
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +0800440 /* Use a TCH for handling requests of type paging any */
441 int pag_any_tch;
442
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800443 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200444 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +0100445
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100446 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200447
448 /* control interface */
449 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200450
451 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
452 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +0200453
454 /* all active subscriber connections. */
455 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200456
457 /* if override is nonzero, this timezone data is used for all MM
458 * contexts. */
459 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
460 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100461 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200462 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100463
464 /* List of all struct bsc_subscr used in libbsc. This llist_head is
465 * allocated so that the llist_head pointer itself can serve as a
466 * talloc context (useful to not have to pass the entire gsm_network
467 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
468 * not require gsm_data.h). In an MSC-without-BSC environment, this
469 * pointer is NULL to indicate absence of a bsc_subscribers list. */
470 struct llist_head *bsc_subscribers;
Harald Weltea43e0b42016-06-19 18:06:02 +0200471
472 /* MSC: GSUP server address of the HLR */
473 const char *gsup_server_addr_str;
474 uint16_t gsup_server_port;
475
476 struct vlr_instance *vlr;
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200477
478 /* Periodic location update default value */
479 uint8_t t3212;
Neels Hofmeyrc29505e2016-05-20 21:59:55 +0200480
481 struct {
Philipp Maier39f62bb2017-04-09 12:32:51 +0200482 /* CS7 instance id number (set via VTY) */
483 uint32_t cs7_instance;
Philipp Maier39f62bb2017-04-09 12:32:51 +0200484 /* A list with the context information about
485 * all BSCs we have connections with */
486 struct llist_head bscs;
487 struct osmo_sccp_instance *sccp;
488 } a;
Harald Welte52b1f982008-12-23 20:25:15 +0000489};
490
Harald Welted4bdee72012-11-08 19:44:08 +0100491struct osmo_esme;
492
493enum gsm_sms_source_id {
494 SMS_SOURCE_UNKNOWN = 0,
495 SMS_SOURCE_MS, /* received from MS */
496 SMS_SOURCE_VTY, /* received from VTY */
497 SMS_SOURCE_SMPP, /* received via SMPP */
498};
499
Harald Welte7e310b12009-03-30 20:56:32 +0000500#define SMS_HDR_SIZE 128
501#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100502
503struct gsm_sms_addr {
504 uint8_t ton;
505 uint8_t npi;
506 char addr[21+1];
507};
508
Harald Welte7e310b12009-03-30 20:56:32 +0000509struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900510 unsigned long long id;
Harald Weltea43e0b42016-06-19 18:06:02 +0200511 struct vlr_subscr *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100512 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100513 enum gsm_sms_source_id source;
514
515 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200516 uint8_t transaction_id;
517 uint32_t msg_ref;
518 } gsm411;
519
520 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100521 struct osmo_esme *esme;
522 uint32_t sequence_nr;
523 int transaction_mode;
524 char msg_id[16];
525 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000526
Harald Welteb9c758b2009-07-05 14:02:46 +0200527 unsigned long validity_minutes;
Keith5f9d0bd2017-08-16 22:45:07 +0200528 time_t created;
Pablo Neira Ayusoe1cdc322017-08-07 14:01:30 +0100529 bool is_report;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200530 uint8_t reply_path_req;
531 uint8_t status_rep_req;
532 uint8_t ud_hdr_ind;
533 uint8_t protocol_id;
534 uint8_t data_coding_scheme;
535 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200536 uint8_t user_data_len;
537 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200538
Harald Welte7e310b12009-03-30 20:56:32 +0000539 char text[SMS_TEXT_SIZE];
540};
541
Neels Hofmeyrc13e6872016-05-11 13:53:47 +0200542extern void talloc_ctx_init(void *ctx_root);
543
Harald Welte39315c42010-01-10 18:01:52 +0100544int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200545
Harald Welte1d014a52009-08-08 15:38:29 +0200546enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200547const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000548struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
549 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000550
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200551extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100552extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200553
Harald Weltef383aa12012-07-02 19:51:55 +0200554/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +0000555static inline int is_ipaccess_bts(struct gsm_bts *bts)
556{
557 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100558 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +0100559 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000560 return 1;
561 default:
562 break;
563 }
564 return 0;
565}
566
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200567static inline int is_sysmobts_v2(struct gsm_bts *bts)
568{
569 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +0100570 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200571 return 1;
572 default:
573 break;
574 }
575 return 0;
576}
577
Harald Welte5b570672009-08-10 10:08:01 +0200578static inline int is_siemens_bts(struct gsm_bts *bts)
579{
580 switch (bts->type) {
581 case GSM_BTS_TYPE_BS11:
582 return 1;
583 default:
584 break;
585 }
586
587 return 0;
588}
589
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100590static inline int is_nokia_bts(struct gsm_bts *bts)
591{
592 switch (bts->type) {
593 case GSM_BTS_TYPE_NOKIA_SITE:
594 return 1;
595 default:
596 break;
597 }
598
599 return 0;
600}
601
Andreas Eversbergdcf38e12013-12-05 14:37:11 +0100602static inline int is_e1_bts(struct gsm_bts *bts)
603{
604 switch (bts->type) {
605 case GSM_BTS_TYPE_BS11:
606 case GSM_BTS_TYPE_RBS2000:
607 case GSM_BTS_TYPE_NOKIA_SITE:
608 return 1;
609 default:
610 break;
611 }
612
613 return 0;
614}
615
Harald Welte (local)69de3972009-08-12 14:42:23 +0200616enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
617const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
618
Harald Welteeab84a12009-12-13 10:53:12 +0100619enum rrlp_mode rrlp_mode_parse(const char *arg);
620const char *rrlp_mode_name(enum rrlp_mode mode);
621
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100622enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +0200623const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100624int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +0200625
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200626int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +0800627void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +0100628
Harald Weltef3d8e922010-06-14 22:44:42 +0200629int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Weltefbda4e12010-03-04 11:04:52 +0100630int gsm_bts_model_register(struct gsm_bts_model *model);
631
Neels Hofmeyr42eb0142016-05-20 17:15:44 +0200632struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
633void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
634
635struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
636void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +0800637
Harald Welte3300c012011-06-05 13:31:33 +0200638struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
639 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100640 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +0100641
Harald Welte3300c012011-06-05 13:31:33 +0200642void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
643 uint8_t e1_ts, uint8_t e1_ts_ss);
644
Maxbe356ed2017-09-07 19:10:09 +0200645void gsm_trx_lock_rf(struct gsm_bts_trx *trx, bool locked, const char *reason);
Max71d082b2017-05-30 15:03:38 +0200646bool gsm_btsmodel_has_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Welte3300c012011-06-05 13:31:33 +0200647struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +0100648int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -0400649int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +0200650
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200651/* generic E1 line operations for all ISDN-based BTS. */
652extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
653
Harald Weltee555c2b2012-08-17 13:02:12 +0200654extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
655extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
656
Max3d049d22017-10-09 17:12:53 +0200657char *get_oml_status(const struct gsm_bts *bts);
658char *get_model_oml_status(const struct gsm_bts *bts);
659
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100660/* control interface handling */
661int bsc_base_ctrl_cmds_install(void);
662
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100663/* dependency handling */
664void bts_depend_mark(struct gsm_bts *bts, int dep);
665void bts_depend_clear(struct gsm_bts *bts, int dep);
666int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +0100667int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100668
Harald Welte2f8b9d22017-06-18 11:12:13 +0300669int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
670void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
671
Harald Weltea43e0b42016-06-19 18:06:02 +0200672bool classmark_is_r99(struct gsm_classmark *cm);
673
Harald Welte6be350c2011-05-25 13:10:08 +0200674#endif /* _GSM_DATA_H */