blob: fa2fed778aeee4e96290ad32a158c4a188d25078 [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
Harald Welteb96be392011-05-25 12:33:33 +020016#include <openbsc/rest_octets.h>
Neels Hofmeyr402006d2016-05-11 14:28:25 +020017#include <openbsc/common_cs.h>
Harald Welteb96be392011-05-25 12:33:33 +020018
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020019/** annotations for msgb ownership */
20#define __uses
21
Holger Hans Peter Freyther6f615552010-11-15 20:50:42 +010022#define OBSC_NM_W_ACK_CB(__msgb) (__msgb)->cb[3]
23
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020024struct mncc_sock_state;
Jacob Erlbeck1e30a282014-12-03 09:28:24 +010025struct gsm_subscriber_group;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +010026struct bsc_subscr;
Harald Welte7b423ed2016-06-19 18:06:02 +020027struct vlr_instance;
28struct vlr_subscr;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020029
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080030#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
31
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010032#define tmsi_from_string(str) strtoul(str, NULL, 10)
33
Max70fdd242017-06-15 15:10:53 +020034/* 3-bit long values */
35#define EARFCN_PRIO_INVALID 8
36#define EARFCN_MEAS_BW_INVALID 8
37/* 5-bit long values */
38#define EARFCN_QRXLV_INVALID 32
39#define EARFCN_THRESH_LOW_INVALID 32
40
Sylvain Munaut30a15382009-12-24 00:27:26 +010041enum gsm_security_event {
42 GSM_SECURITY_NOAVAIL,
43 GSM_SECURITY_AUTH_FAILED,
44 GSM_SECURITY_SUCCEEDED,
Andreas Eversberg641475c2013-07-10 08:58:03 +020045 GSM_SECURITY_ALREADY,
Sylvain Munaut30a15382009-12-24 00:27:26 +010046};
47
Harald Welte8e1e3ee2009-02-01 13:32:45 +000048struct msgb;
49typedef int gsm_cbfn(unsigned int hooknum,
50 unsigned int event,
51 struct msgb *msg,
52 void *data, void *param);
53
Sylvain Munaut47193072009-12-27 21:56:14 +010054/* Real authentication information containing Ki */
55enum gsm_auth_algo {
56 AUTH_ALGO_NONE,
57 AUTH_ALGO_XOR,
58 AUTH_ALGO_COMP128v1,
59};
60
61struct gsm_auth_info {
62 enum gsm_auth_algo auth_algo;
63 unsigned int a3a8_ki_len;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020064 uint8_t a3a8_ki[16];
Sylvain Munaut47193072009-12-27 21:56:14 +010065};
66
67struct gsm_auth_tuple {
68 int use_count;
69 int key_seq;
Harald Welte121e9a42016-04-20 13:13:19 +020070 struct osmo_auth_vector vec;
Sylvain Munaut47193072009-12-27 21:56:14 +010071};
Sylvain Munautb48216f2010-06-09 12:45:37 +020072#define GSM_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
Sylvain Munaut47193072009-12-27 21:56:14 +010073
Holger Freyther73487a22008-12-31 18:53:57 +000074/*
Sylvain Munaut30a15382009-12-24 00:27:26 +010075 * AUTHENTICATION/CIPHERING state
76 */
77struct gsm_security_operation {
78 struct gsm_auth_tuple atuple;
79 gsm_cbfn *cb;
80 void *cb_data;
81};
82
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080083/*
84 * A dummy to keep a connection up for at least
85 * a couple of seconds to work around MSC issues.
86 */
87struct gsm_anchor_operation {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020088 struct osmo_timer_list timeout;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080089};
90
Harald Weltef7c28b02009-12-21 13:30:17 +010091/* Maximum number of neighbor cells whose average we track */
92#define MAX_NEIGH_MEAS 10
93/* Maximum size of the averaging window for neighbor cells */
94#define MAX_WIN_NEIGH_AVG 10
95
96/* processed neighbor measurements for one cell */
97struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020098 uint16_t arfcn;
99 uint8_t bsic;
100 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +0100101 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200102 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +0100103};
104
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100105enum ran_type {
106 RAN_UNKNOWN,
107 RAN_GERAN_A, /* 2G / A-interface */
108 RAN_UTRAN_IU, /* 3G / Iu-interface (IuCS or IuPS) */
109};
110
Harald Welte7b423ed2016-06-19 18:06:02 +0200111struct gsm_classmark {
112 bool classmark1_set;
113 struct gsm48_classmark1 classmark1;
114 uint8_t classmark2_len;
115 uint8_t classmark2[3];
116 uint8_t classmark3_len;
117 uint8_t classmark3[14]; /* if cm3 gets extended by spec, it will be truncated */
118};
119
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200120/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100121struct gsm_subscriber_connection {
Harald Welte7b423ed2016-06-19 18:06:02 +0200122 /* global linked list of subscriber_connections */
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800123 struct llist_head entry;
124
Harald Welte7b423ed2016-06-19 18:06:02 +0200125 /* usage count. If this drops to zero, we start the release
126 * towards A/Iu */
127 uint32_t use_count;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100128
Harald Welte7b423ed2016-06-19 18:06:02 +0200129 /* The MS has opened the conn with a CM Service Request, and we shall
130 * keep it open for an actual request (or until timeout). */
131 bool received_cm_service_request;
132
133 /* libbsc subscriber information (if available) */
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100134 struct bsc_subscr *bsub;
135
Harald Welte7b423ed2016-06-19 18:06:02 +0200136 /* libmsc/libvlr subscriber information (if available) */
137 struct vlr_subscr *vsub;
138
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200139 /* LU expiration handling */
140 uint8_t expire_timer_stopped;
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100141 /* SMS helpers for libmsc */
142 uint8_t next_rp_ref;
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200143
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100144 /*
145 * Operations that have a state and might be pending
146 */
Sylvain Munaut30a15382009-12-24 00:27:26 +0100147 struct gsm_security_operation *sec_operation;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800148 struct gsm_anchor_operation *anch_operation;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100149
Harald Welte7b423ed2016-06-19 18:06:02 +0200150 struct osmo_fsm_inst *conn_fsm;
151
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100152 /* Are we part of a special "silent" call */
153 int silent_call;
154
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200155 /* MNCC rtp bridge markers */
156 int mncc_rtp_bridge;
157 int mncc_rtp_create_pending;
Holger Hans Peter Freytherc21dcb22015-08-04 14:41:21 +0200158 int mncc_rtp_connect_pending;
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200159
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800160 /* bsc structures */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200161 struct osmo_bsc_sccp_con *sccp_con; /* BSC */
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800162
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100163 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200164 struct gsm_network *network;
165
Harald Welte7b423ed2016-06-19 18:06:02 +0200166 bool in_release;
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200167 struct gsm_lchan *lchan; /* BSC */
168 struct gsm_lchan *ho_lchan; /* BSC */
169 struct gsm_bts *bts; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100170
171 /* for assignment handling */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200172 struct osmo_timer_list T10; /* BSC */
173 struct gsm_lchan *secondary_lchan; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100174
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100175 /* connected via 2G or 3G? */
176 enum ran_type via_ran;
Harald Welte7b423ed2016-06-19 18:06:02 +0200177
178 struct gsm_classmark classmark;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100179};
180
Harald Weltef142c972011-05-24 13:25:38 +0200181
Harald Welte6be350c2011-05-25 13:10:08 +0200182#define ROLE_BSC
183#include "gsm_data_shared.h"
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100184
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100185
Alexander Couzens20423ea2016-07-12 15:42:02 +0200186enum {
Alexander Couzensb847a212016-08-02 11:34:11 +0200187 BSC_CTR_CHREQ_TOTAL,
188 BSC_CTR_CHREQ_NO_CHANNEL,
189 BSC_CTR_HANDOVER_ATTEMPTED,
190 BSC_CTR_HANDOVER_NO_CHANNEL,
191 BSC_CTR_HANDOVER_TIMEOUT,
192 BSC_CTR_HANDOVER_COMPLETED,
193 BSC_CTR_HANDOVER_FAILED,
194 BSC_CTR_PAGING_ATTEMPTED,
195 BSC_CTR_PAGING_DETACHED,
196 BSC_CTR_PAGING_COMPLETED,
197 BSC_CTR_PAGING_EXPIRED,
198 BSC_CTR_CHAN_RF_FAIL,
199 BSC_CTR_CHAN_RLL_ERR,
200 BSC_CTR_BTS_OML_FAIL,
201 BSC_CTR_BTS_RSL_FAIL,
Alexander Couzens8c53c592016-08-23 06:27:19 +0200202 BSC_CTR_CODEC_AMR_F,
203 BSC_CTR_CODEC_AMR_H,
204 BSC_CTR_CODEC_EFR,
205 BSC_CTR_CODEC_V1_FR,
206 BSC_CTR_CODEC_V1_HR,
Alexander Couzensb847a212016-08-02 11:34:11 +0200207};
208
209static const struct rate_ctr_desc bsc_ctr_description[] = {
210 [BSC_CTR_CHREQ_TOTAL] = {"chreq.total", "Received channel requests."},
211 [BSC_CTR_CHREQ_NO_CHANNEL] = {"chreq.no_channel", "Sent to MS no channel available."},
212 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover.attempted", "Received handover attempts."},
213 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover.no_channel", "Sent no channel available responses."},
214 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover.timeout", "Count the amount of timeouts of timer T3103."},
215 [BSC_CTR_HANDOVER_COMPLETED] = {"handover.completed", "Received handover completed."},
216 [BSC_CTR_HANDOVER_FAILED] = {"handover.failed", "Receive HO FAIL messages."},
217 [BSC_CTR_PAGING_ATTEMPTED] = {"paging.attempted", "Paging attempts for a MS."},
218 [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."},
219 [BSC_CTR_PAGING_COMPLETED] = {"paging.completed", "Paging successful completed."},
220 [BSC_CTR_PAGING_EXPIRED] = {"paging.expired", "Paging Request expired because of timeout T3113."},
221 [BSC_CTR_CHAN_RF_FAIL] = {"chan.rf_fail", "Received a RF failure indication from BTS."},
222 [BSC_CTR_CHAN_RLL_ERR] = {"chan.rll_err", "Received a RLL failure with T200 cause from BTS."},
223 [BSC_CTR_BTS_OML_FAIL] = {"bts.oml_fail", "Received a TEI down on a OML link."},
224 [BSC_CTR_BTS_RSL_FAIL] = {"bts.rsl_fail", "Received a TEI down on a OML link."},
Alexander Couzens8c53c592016-08-23 06:27:19 +0200225 [BSC_CTR_CODEC_AMR_F] = {"bts.codec_amr_f", "Count the usage of AMR/F codec by channel mode requested."},
226 [BSC_CTR_CODEC_AMR_H] = {"bts.codec_amr_h", "Count the usage of AMR/H codec by channel mode requested."},
227 [BSC_CTR_CODEC_EFR] = {"bts.codec_efr", "Count the usage of EFR codec by channel mode requested."},
228 [BSC_CTR_CODEC_V1_FR] = {"bts.codec_fr", "Count the usage of FR codec by channel mode requested."},
229 [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 +0200230};
231
232enum {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200233 MSC_CTR_LOC_UPDATE_TYPE_ATTACH,
234 MSC_CTR_LOC_UPDATE_TYPE_NORMAL,
235 MSC_CTR_LOC_UPDATE_TYPE_PERIODIC,
236 MSC_CTR_LOC_UPDATE_TYPE_DETACH,
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200237 MSC_CTR_LOC_UPDATE_FAILED,
238 MSC_CTR_LOC_UPDATE_COMPLETED,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200239 MSC_CTR_SMS_SUBMITTED,
240 MSC_CTR_SMS_NO_RECEIVER,
241 MSC_CTR_SMS_DELIVERED,
242 MSC_CTR_SMS_RP_ERR_MEM,
243 MSC_CTR_SMS_RP_ERR_OTHER,
Alexander Couzensaa386d22016-08-21 20:16:33 +0200244 MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200245 MSC_CTR_CALL_MO_SETUP,
246 MSC_CTR_CALL_MO_CONNECT_ACK,
247 MSC_CTR_CALL_MT_SETUP,
248 MSC_CTR_CALL_MT_CONNECT,
Alexander Couzens92f552f2016-08-23 07:32:27 +0200249 MSC_CTR_CALL_ACTIVE,
250 MSC_CTR_CALL_COMPLETE,
251 MSC_CTR_CALL_INCOMPLETE,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200252};
253
254static const struct rate_ctr_desc msc_ctr_description[] = {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200255 [MSC_CTR_LOC_UPDATE_TYPE_ATTACH] = {"loc_update_type.attach", "Received location update imsi attach requests."},
256 [MSC_CTR_LOC_UPDATE_TYPE_NORMAL] = {"loc_update_type.normal", "Received location update normal requests."},
257 [MSC_CTR_LOC_UPDATE_TYPE_PERIODIC] = {"loc_update_type.periodic", "Received location update periodic requests."},
258 [MSC_CTR_LOC_UPDATE_TYPE_DETACH] = {"loc_update_type.detach", "Received location update detach indication."},
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200259 [MSC_CTR_LOC_UPDATE_FAILED] = {"loc_update_resp.failed", "Rejected location updates."},
260 [MSC_CTR_LOC_UPDATE_COMPLETED] = {"loc_update_resp.completed", "Successful location updates."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200261 [MSC_CTR_SMS_SUBMITTED] = {"sms.submitted", "Received a RPDU from a MS (MO)."},
262 [MSC_CTR_SMS_NO_RECEIVER] = {"sms.no_receiver", "Counts SMS which couldn't routed because no receiver found."},
263 [MSC_CTR_SMS_DELIVERED] = {"sms.delivered", "Global SMS Deliver attempts."},
264 [MSC_CTR_SMS_RP_ERR_MEM] = {"sms.rp_err_mem", "CAUSE_MT_MEM_EXCEEDED errors of MS responses on a sms deliver attempt."},
265 [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 +0200266 [MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR] = {"sms.deliver_unknown_error", "Unknown error occured during sms delivery."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200267 /* FIXME: count also sms delivered */
268 [MSC_CTR_CALL_MO_SETUP] = {"call.mo_setup", "Received setup requests from a MS to init a MO call."},
269 [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."},
270 [MSC_CTR_CALL_MT_SETUP] = {"call.mt_setup", "Sent setup requests to the MS (MT)."},
271 [MSC_CTR_CALL_MT_CONNECT] = {"call.mt_connect", "Sent a connect to the MS (MT)."},
Alexander Couzens92f552f2016-08-23 07:32:27 +0200272 [MSC_CTR_CALL_ACTIVE] = {"call.active", "Count total amount of calls that ever reached active state."},
273 [MSC_CTR_CALL_COMPLETE] = {"call.complete", "Count total amount of calls which got terminated by disconnect req or ind after reaching active state."},
274 [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 +0200275};
276
277
278static const struct rate_ctr_group_desc bsc_ctrg_desc = {
279 "bsc",
280 "base station controller",
281 OSMO_STATS_CLASS_GLOBAL,
282 ARRAY_SIZE(bsc_ctr_description),
283 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200284};
285
286static const struct rate_ctr_group_desc msc_ctrg_desc = {
287 "msc",
288 "mobile switching center",
289 OSMO_STATS_CLASS_GLOBAL,
290 ARRAY_SIZE(msc_ctr_description),
291 msc_ctr_description,
Harald Welte24ff6ee2009-12-22 00:41:05 +0100292};
293
Harald Welte (local)69de3972009-08-12 14:42:23 +0200294enum gsm_auth_policy {
295 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
296 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
297 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
Maxddee01f2016-05-24 14:23:27 +0200298 GSM_AUTH_POLICY_REGEXP, /* accept IMSIs matching given regexp */
Harald Welte (local)69de3972009-08-12 14:42:23 +0200299};
300
Harald Welteb84ddfc2009-12-01 17:36:54 +0530301#define GSM_T3101_DEFAULT 10
Harald Welte67161f22012-06-03 13:01:47 +0200302#define GSM_T3105_DEFAULT 40
Harald Welteb84ddfc2009-12-01 17:36:54 +0530303#define GSM_T3113_DEFAULT 60
Andreas Eversberg75e13a42013-02-07 11:51:16 +0100304#define GSM_T3122_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530305
Neels Hofmeyr73983952016-05-10 13:29:33 +0200306struct gsm_tz {
307 int override; /* if 0, use system's time zone instead. */
308 int hr; /* hour */
309 int mn; /* minute */
310 int dst; /* daylight savings */
311};
312
Harald Welte52b1f982008-12-23 20:25:15 +0000313struct gsm_network {
314 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200315 uint16_t country_code;
316 uint16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000317 char *name_long;
318 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200319 enum gsm_auth_policy auth_policy;
Maxddee01f2016-05-24 14:23:27 +0200320 regex_t authorized_regexp;
321 char *authorized_reg_str;
Harald Welte1085c092009-11-18 20:33:19 +0100322 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900323 int a5_encryption;
Harald Welte7b423ed2016-06-19 18:06:02 +0200324 bool authentication_required;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100325 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100326 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100327 struct {
328 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100329 /* Window RXLEV averaging */
330 unsigned int win_rxlev_avg; /* number of SACCH frames */
331 /* Window RXQUAL averaging */
332 unsigned int win_rxqual_avg; /* number of SACCH frames */
333 /* Window RXLEV neighbouring cells averaging */
334 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
335
336 /* how often should we check for power budget HO */
337 unsigned int pwr_interval; /* SACCH frames */
338 /* how much better does a neighbor cell have to be ? */
339 unsigned int pwr_hysteresis; /* dBm */
340 /* maximum distacne before we try a handover */
341 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100342 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000343
Alexander Couzensb847a212016-08-02 11:34:11 +0200344 struct rate_ctr_group *bsc_ctrs;
345 struct rate_ctr_group *msc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200346 struct osmo_counter *active_calls;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100347
Harald Welte4bfdfe72009-06-10 23:11:52 +0800348 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200349 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200350 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800351 struct llist_head upqueue;
352 struct llist_head trans_list;
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +0800353 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800354
Harald Welte52b1f982008-12-23 20:25:15 +0000355 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200356 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100357
358 /* timer values */
359 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100360 int T3103;
361 int T3105;
362 int T3107;
363 int T3109;
364 int T3111;
365 int T3113;
366 int T3115;
367 int T3117;
368 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +0100369 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100370 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100371
Jan Luebbebfbdeec2012-12-27 00:27:16 +0100372 /* timer to expire old location updates */
373 struct osmo_timer_list subscr_expire_timer;
374
Harald Welteeab84a12009-12-13 10:53:12 +0100375 /* Radio Resource Location Protocol (TS 04.31) */
376 struct {
377 enum rrlp_mode mode;
378 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800379
Alexander Couzens11368112016-11-28 23:26:50 +0100380 enum gsm_chan_t ctype_by_chreq[18];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800381
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +0800382 /* Use a TCH for handling requests of type paging any */
383 int pag_any_tch;
384
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800385 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200386 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +0100387
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100388 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200389
390 /* control interface */
391 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200392
393 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
394 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +0200395
396 /* all active subscriber connections. */
397 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200398
399 /* if override is nonzero, this timezone data is used for all MM
400 * contexts. */
401 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
402 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100403 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200404 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100405
406 /* List of all struct bsc_subscr used in libbsc. This llist_head is
407 * allocated so that the llist_head pointer itself can serve as a
408 * talloc context (useful to not have to pass the entire gsm_network
409 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
410 * not require gsm_data.h). In an MSC-without-BSC environment, this
411 * pointer is NULL to indicate absence of a bsc_subscribers list. */
412 struct llist_head *bsc_subscribers;
Harald Welte7b423ed2016-06-19 18:06:02 +0200413
414 /* MSC: GSUP server address of the HLR */
415 const char *gsup_server_addr_str;
416 uint16_t gsup_server_port;
417
418 struct vlr_instance *vlr;
Harald Welte52b1f982008-12-23 20:25:15 +0000419};
420
Harald Welted4bdee72012-11-08 19:44:08 +0100421struct osmo_esme;
422
423enum gsm_sms_source_id {
424 SMS_SOURCE_UNKNOWN = 0,
425 SMS_SOURCE_MS, /* received from MS */
426 SMS_SOURCE_VTY, /* received from VTY */
427 SMS_SOURCE_SMPP, /* received via SMPP */
428};
429
Harald Welte7e310b12009-03-30 20:56:32 +0000430#define SMS_HDR_SIZE 128
431#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100432
433struct gsm_sms_addr {
434 uint8_t ton;
435 uint8_t npi;
436 char addr[21+1];
437};
438
Harald Welte7e310b12009-03-30 20:56:32 +0000439struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900440 unsigned long long id;
Harald Welte7b423ed2016-06-19 18:06:02 +0200441 struct vlr_subscr *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100442 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100443 enum gsm_sms_source_id source;
444
445 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200446 uint8_t transaction_id;
447 uint32_t msg_ref;
448 } gsm411;
449
450 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100451 struct osmo_esme *esme;
452 uint32_t sequence_nr;
453 int transaction_mode;
454 char msg_id[16];
455 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000456
Harald Welteb9c758b2009-07-05 14:02:46 +0200457 unsigned long validity_minutes;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200458 uint8_t reply_path_req;
459 uint8_t status_rep_req;
460 uint8_t ud_hdr_ind;
461 uint8_t protocol_id;
462 uint8_t data_coding_scheme;
463 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200464 uint8_t user_data_len;
465 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200466
Harald Welte7e310b12009-03-30 20:56:32 +0000467 char text[SMS_TEXT_SIZE];
468};
469
Neels Hofmeyrc13e6872016-05-11 13:53:47 +0200470extern void talloc_ctx_init(void *ctx_root);
471
Harald Welte39315c42010-01-10 18:01:52 +0100472int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200473
Harald Welte84874c92009-12-14 22:33:02 +0100474/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100475struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200476 uint16_t arfcn, uint8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100477
Harald Welte1d014a52009-08-08 15:38:29 +0200478enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200479const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000480struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
481 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000482
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200483extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100484extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200485
Harald Weltef383aa12012-07-02 19:51:55 +0200486/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +0000487static inline int is_ipaccess_bts(struct gsm_bts *bts)
488{
489 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100490 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +0100491 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000492 return 1;
493 default:
494 break;
495 }
496 return 0;
497}
498
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200499static inline int is_sysmobts_v2(struct gsm_bts *bts)
500{
501 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +0100502 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200503 return 1;
504 default:
505 break;
506 }
507 return 0;
508}
509
Harald Welte5b570672009-08-10 10:08:01 +0200510static inline int is_siemens_bts(struct gsm_bts *bts)
511{
512 switch (bts->type) {
513 case GSM_BTS_TYPE_BS11:
514 return 1;
515 default:
516 break;
517 }
518
519 return 0;
520}
521
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100522static inline int is_nokia_bts(struct gsm_bts *bts)
523{
524 switch (bts->type) {
525 case GSM_BTS_TYPE_NOKIA_SITE:
526 return 1;
527 default:
528 break;
529 }
530
531 return 0;
532}
533
Andreas Eversbergdcf38e12013-12-05 14:37:11 +0100534static inline int is_e1_bts(struct gsm_bts *bts)
535{
536 switch (bts->type) {
537 case GSM_BTS_TYPE_BS11:
538 case GSM_BTS_TYPE_RBS2000:
539 case GSM_BTS_TYPE_NOKIA_SITE:
540 return 1;
541 default:
542 break;
543 }
544
545 return 0;
546}
547
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);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100556int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +0200557
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200558int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +0800559void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +0100560struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
561
Harald Weltef3d8e922010-06-14 22:44:42 +0200562int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Weltefbda4e12010-03-04 11:04:52 +0100563int gsm_bts_model_register(struct gsm_bts_model *model);
564
Neels Hofmeyr42eb0142016-05-20 17:15:44 +0200565struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
566void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
567
568struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
569void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +0800570
Harald Welte3300c012011-06-05 13:31:33 +0200571struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
572 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100573 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +0100574
Harald Welte3300c012011-06-05 13:31:33 +0200575void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
576 uint8_t e1_ts, uint8_t e1_ts_ss);
577
578void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
Max71d082b2017-05-30 15:03:38 +0200579bool gsm_btsmodel_has_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Welte3300c012011-06-05 13:31:33 +0200580struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +0100581int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -0400582int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +0200583
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200584/* generic E1 line operations for all ISDN-based BTS. */
585extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
586
Harald Weltee555c2b2012-08-17 13:02:12 +0200587extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
588extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
589
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100590/* control interface handling */
591int bsc_base_ctrl_cmds_install(void);
Harald Welte7b423ed2016-06-19 18:06:02 +0200592int msc_ctrl_cmds_install(struct gsm_network *net);
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100593
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100594/* dependency handling */
595void bts_depend_mark(struct gsm_bts *bts, int dep);
596void bts_depend_clear(struct gsm_bts *bts, int dep);
597int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +0100598int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100599
Harald Welte2f8b9d22017-06-18 11:12:13 +0300600int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
601void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
602
Harald Welte7b423ed2016-06-19 18:06:02 +0200603bool classmark_is_r99(struct gsm_classmark *cm);
604
Harald Welte6be350c2011-05-25 13:10:08 +0200605#endif /* _GSM_DATA_H */