blob: a97405105f139b7a9172054c64226884084afa66 [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;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020027
Holger Hans Peter Freyther9c595b72010-06-15 11:20:52 +080028#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
29
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010030#define tmsi_from_string(str) strtoul(str, NULL, 10)
31
Max70fdd242017-06-15 15:10:53 +020032/* 3-bit long values */
33#define EARFCN_PRIO_INVALID 8
34#define EARFCN_MEAS_BW_INVALID 8
35/* 5-bit long values */
36#define EARFCN_QRXLV_INVALID 32
37#define EARFCN_THRESH_LOW_INVALID 32
38
Sylvain Munaut30a15382009-12-24 00:27:26 +010039enum gsm_security_event {
40 GSM_SECURITY_NOAVAIL,
41 GSM_SECURITY_AUTH_FAILED,
42 GSM_SECURITY_SUCCEEDED,
Andreas Eversberg641475c2013-07-10 08:58:03 +020043 GSM_SECURITY_ALREADY,
Sylvain Munaut30a15382009-12-24 00:27:26 +010044};
45
Harald Welte8e1e3ee2009-02-01 13:32:45 +000046struct msgb;
47typedef int gsm_cbfn(unsigned int hooknum,
48 unsigned int event,
49 struct msgb *msg,
50 void *data, void *param);
51
Sylvain Munaut47193072009-12-27 21:56:14 +010052/* Real authentication information containing Ki */
53enum gsm_auth_algo {
54 AUTH_ALGO_NONE,
55 AUTH_ALGO_XOR,
56 AUTH_ALGO_COMP128v1,
57};
58
59struct gsm_auth_info {
60 enum gsm_auth_algo auth_algo;
61 unsigned int a3a8_ki_len;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020062 uint8_t a3a8_ki[16];
Sylvain Munaut47193072009-12-27 21:56:14 +010063};
64
65struct gsm_auth_tuple {
66 int use_count;
67 int key_seq;
Harald Welte121e9a42016-04-20 13:13:19 +020068 struct osmo_auth_vector vec;
Sylvain Munaut47193072009-12-27 21:56:14 +010069};
Sylvain Munautb48216f2010-06-09 12:45:37 +020070#define GSM_KEY_SEQ_INVAL 7 /* GSM 04.08 - 10.5.1.2 */
Sylvain Munaut47193072009-12-27 21:56:14 +010071
Holger Freyther73487a22008-12-31 18:53:57 +000072/*
73 * LOCATION UPDATING REQUEST state
74 *
75 * Our current operation is:
76 * - Get imei/tmsi
77 * - Accept/Reject according to global policy
78 */
79struct gsm_loc_updating_operation {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020080 struct osmo_timer_list updating_timer;
Holger Hans Peter Freyther251aa912009-10-27 10:42:28 +010081 unsigned int waiting_for_imsi : 1;
82 unsigned int waiting_for_imei : 1;
Sylvain Munaut2030a2a2010-06-10 13:36:59 +020083 unsigned int key_seq : 4;
Holger Freyther73487a22008-12-31 18:53:57 +000084};
85
Sylvain Munaut30a15382009-12-24 00:27:26 +010086/*
87 * AUTHENTICATION/CIPHERING state
88 */
89struct gsm_security_operation {
90 struct gsm_auth_tuple atuple;
91 gsm_cbfn *cb;
92 void *cb_data;
93};
94
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +080095/*
96 * A dummy to keep a connection up for at least
97 * a couple of seconds to work around MSC issues.
98 */
99struct gsm_anchor_operation {
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200100 struct osmo_timer_list timeout;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800101};
102
Harald Weltef7c28b02009-12-21 13:30:17 +0100103/* Maximum number of neighbor cells whose average we track */
104#define MAX_NEIGH_MEAS 10
105/* Maximum size of the averaging window for neighbor cells */
106#define MAX_WIN_NEIGH_AVG 10
107
108/* processed neighbor measurements for one cell */
109struct neigh_meas_proc {
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200110 uint16_t arfcn;
111 uint8_t bsic;
112 uint8_t rxlev[MAX_WIN_NEIGH_AVG];
Harald Weltef7c28b02009-12-21 13:30:17 +0100113 unsigned int rxlev_cnt;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200114 uint8_t last_seen_nr;
Harald Weltef7c28b02009-12-21 13:30:17 +0100115};
116
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100117enum ran_type {
118 RAN_UNKNOWN,
119 RAN_GERAN_A, /* 2G / A-interface */
120 RAN_UTRAN_IU, /* 3G / Iu-interface (IuCS or IuPS) */
121};
122
Neels Hofmeyr378a4922016-05-09 21:07:43 +0200123/* active radio connection of a mobile subscriber */
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100124struct gsm_subscriber_connection {
Holger Hans Peter Freyther79f763f2010-09-16 00:53:37 +0800125 struct llist_head entry;
126
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100127 /* To whom we are allocated at the moment */
128 struct gsm_subscriber *subscr;
129
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100130 /* libbsc subscriber information */
131 struct bsc_subscr *bsub;
132
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200133 /* LU expiration handling */
134 uint8_t expire_timer_stopped;
Holger Hans Peter Freytherca114432014-02-08 15:20:48 +0100135 /* SMS helpers for libmsc */
136 uint8_t next_rp_ref;
Holger Hans Peter Freythere7bd8632013-06-30 15:30:47 +0200137
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100138 /*
139 * Operations that have a state and might be pending
140 */
141 struct gsm_loc_updating_operation *loc_operation;
Sylvain Munaut30a15382009-12-24 00:27:26 +0100142 struct gsm_security_operation *sec_operation;
Holger Hans Peter Freyther02d39b22010-07-05 15:34:16 +0800143 struct gsm_anchor_operation *anch_operation;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100144
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100145 /* Are we part of a special "silent" call */
146 int silent_call;
147
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200148 /* MNCC rtp bridge markers */
149 int mncc_rtp_bridge;
150 int mncc_rtp_create_pending;
Holger Hans Peter Freytherc21dcb22015-08-04 14:41:21 +0200151 int mncc_rtp_connect_pending;
Holger Hans Peter Freytherc8a6c132015-08-04 13:32:09 +0200152
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800153 /* bsc structures */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200154 struct osmo_bsc_sccp_con *sccp_con; /* BSC */
Holger Hans Peter Freyther2f9d1ef2010-09-16 20:14:01 +0800155
Holger Hans Peter Freyther18b63f42010-03-23 07:52:17 +0100156 /* back pointers */
Neels Hofmeyr5e0b0a62016-05-09 22:33:01 +0200157 struct gsm_network *network;
158
Holger Hans Peter Freyther40494552010-06-28 17:09:29 +0800159 int in_release;
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200160 struct gsm_lchan *lchan; /* BSC */
161 struct gsm_lchan *ho_lchan; /* BSC */
162 struct gsm_bts *bts; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100163
164 /* for assignment handling */
Neels Hofmeyrce090f82016-05-30 15:00:23 +0200165 struct osmo_timer_list T10; /* BSC */
166 struct gsm_lchan *secondary_lchan; /* BSC */
Holger Hans Peter Freyther77cd95d2010-11-14 16:19:48 +0100167
Neels Hofmeyrd3270a92017-02-02 01:07:28 +0100168 /* connected via 2G or 3G? */
169 enum ran_type via_ran;
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100170};
171
Harald Weltef142c972011-05-24 13:25:38 +0200172
Harald Welte6be350c2011-05-25 13:10:08 +0200173#define ROLE_BSC
174#include "gsm_data_shared.h"
Holger Hans Peter Freyther68884aa2010-03-23 06:41:45 +0100175
Holger Hans Peter Freyther5ba6f482009-10-28 14:23:39 +0100176
Alexander Couzens20423ea2016-07-12 15:42:02 +0200177enum {
Alexander Couzensb847a212016-08-02 11:34:11 +0200178 BSC_CTR_CHREQ_TOTAL,
179 BSC_CTR_CHREQ_NO_CHANNEL,
180 BSC_CTR_HANDOVER_ATTEMPTED,
181 BSC_CTR_HANDOVER_NO_CHANNEL,
182 BSC_CTR_HANDOVER_TIMEOUT,
183 BSC_CTR_HANDOVER_COMPLETED,
184 BSC_CTR_HANDOVER_FAILED,
185 BSC_CTR_PAGING_ATTEMPTED,
186 BSC_CTR_PAGING_DETACHED,
187 BSC_CTR_PAGING_COMPLETED,
188 BSC_CTR_PAGING_EXPIRED,
189 BSC_CTR_CHAN_RF_FAIL,
190 BSC_CTR_CHAN_RLL_ERR,
191 BSC_CTR_BTS_OML_FAIL,
192 BSC_CTR_BTS_RSL_FAIL,
Alexander Couzens8c53c592016-08-23 06:27:19 +0200193 BSC_CTR_CODEC_AMR_F,
194 BSC_CTR_CODEC_AMR_H,
195 BSC_CTR_CODEC_EFR,
196 BSC_CTR_CODEC_V1_FR,
197 BSC_CTR_CODEC_V1_HR,
Alexander Couzensb847a212016-08-02 11:34:11 +0200198};
199
200static const struct rate_ctr_desc bsc_ctr_description[] = {
201 [BSC_CTR_CHREQ_TOTAL] = {"chreq.total", "Received channel requests."},
202 [BSC_CTR_CHREQ_NO_CHANNEL] = {"chreq.no_channel", "Sent to MS no channel available."},
203 [BSC_CTR_HANDOVER_ATTEMPTED] = {"handover.attempted", "Received handover attempts."},
204 [BSC_CTR_HANDOVER_NO_CHANNEL] = {"handover.no_channel", "Sent no channel available responses."},
205 [BSC_CTR_HANDOVER_TIMEOUT] = {"handover.timeout", "Count the amount of timeouts of timer T3103."},
206 [BSC_CTR_HANDOVER_COMPLETED] = {"handover.completed", "Received handover completed."},
207 [BSC_CTR_HANDOVER_FAILED] = {"handover.failed", "Receive HO FAIL messages."},
208 [BSC_CTR_PAGING_ATTEMPTED] = {"paging.attempted", "Paging attempts for a MS."},
209 [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."},
210 [BSC_CTR_PAGING_COMPLETED] = {"paging.completed", "Paging successful completed."},
211 [BSC_CTR_PAGING_EXPIRED] = {"paging.expired", "Paging Request expired because of timeout T3113."},
212 [BSC_CTR_CHAN_RF_FAIL] = {"chan.rf_fail", "Received a RF failure indication from BTS."},
213 [BSC_CTR_CHAN_RLL_ERR] = {"chan.rll_err", "Received a RLL failure with T200 cause from BTS."},
214 [BSC_CTR_BTS_OML_FAIL] = {"bts.oml_fail", "Received a TEI down on a OML link."},
215 [BSC_CTR_BTS_RSL_FAIL] = {"bts.rsl_fail", "Received a TEI down on a OML link."},
Alexander Couzens8c53c592016-08-23 06:27:19 +0200216 [BSC_CTR_CODEC_AMR_F] = {"bts.codec_amr_f", "Count the usage of AMR/F codec by channel mode requested."},
217 [BSC_CTR_CODEC_AMR_H] = {"bts.codec_amr_h", "Count the usage of AMR/H codec by channel mode requested."},
218 [BSC_CTR_CODEC_EFR] = {"bts.codec_efr", "Count the usage of EFR codec by channel mode requested."},
219 [BSC_CTR_CODEC_V1_FR] = {"bts.codec_fr", "Count the usage of FR codec by channel mode requested."},
220 [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 +0200221};
222
223enum {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200224 MSC_CTR_LOC_UPDATE_TYPE_ATTACH,
225 MSC_CTR_LOC_UPDATE_TYPE_NORMAL,
226 MSC_CTR_LOC_UPDATE_TYPE_PERIODIC,
227 MSC_CTR_LOC_UPDATE_TYPE_DETACH,
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200228 MSC_CTR_LOC_UPDATE_FAILED,
229 MSC_CTR_LOC_UPDATE_COMPLETED,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200230 MSC_CTR_SMS_SUBMITTED,
231 MSC_CTR_SMS_NO_RECEIVER,
232 MSC_CTR_SMS_DELIVERED,
233 MSC_CTR_SMS_RP_ERR_MEM,
234 MSC_CTR_SMS_RP_ERR_OTHER,
Alexander Couzensaa386d22016-08-21 20:16:33 +0200235 MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200236 MSC_CTR_CALL_MO_SETUP,
237 MSC_CTR_CALL_MO_CONNECT_ACK,
238 MSC_CTR_CALL_MT_SETUP,
239 MSC_CTR_CALL_MT_CONNECT,
Alexander Couzens92f552f2016-08-23 07:32:27 +0200240 MSC_CTR_CALL_ACTIVE,
241 MSC_CTR_CALL_COMPLETE,
242 MSC_CTR_CALL_INCOMPLETE,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200243};
244
245static const struct rate_ctr_desc msc_ctr_description[] = {
Alexander Couzens20423ea2016-07-12 15:42:02 +0200246 [MSC_CTR_LOC_UPDATE_TYPE_ATTACH] = {"loc_update_type.attach", "Received location update imsi attach requests."},
247 [MSC_CTR_LOC_UPDATE_TYPE_NORMAL] = {"loc_update_type.normal", "Received location update normal requests."},
248 [MSC_CTR_LOC_UPDATE_TYPE_PERIODIC] = {"loc_update_type.periodic", "Received location update periodic requests."},
249 [MSC_CTR_LOC_UPDATE_TYPE_DETACH] = {"loc_update_type.detach", "Received location update detach indication."},
Neels Hofmeyr36891a72016-05-09 13:18:03 +0200250 [MSC_CTR_LOC_UPDATE_FAILED] = {"loc_update_resp.failed", "Rejected location updates."},
251 [MSC_CTR_LOC_UPDATE_COMPLETED] = {"loc_update_resp.completed", "Successful location updates."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200252 [MSC_CTR_SMS_SUBMITTED] = {"sms.submitted", "Received a RPDU from a MS (MO)."},
253 [MSC_CTR_SMS_NO_RECEIVER] = {"sms.no_receiver", "Counts SMS which couldn't routed because no receiver found."},
254 [MSC_CTR_SMS_DELIVERED] = {"sms.delivered", "Global SMS Deliver attempts."},
255 [MSC_CTR_SMS_RP_ERR_MEM] = {"sms.rp_err_mem", "CAUSE_MT_MEM_EXCEEDED errors of MS responses on a sms deliver attempt."},
256 [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 +0200257 [MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR] = {"sms.deliver_unknown_error", "Unknown error occured during sms delivery."},
Alexander Couzens20423ea2016-07-12 15:42:02 +0200258 /* FIXME: count also sms delivered */
259 [MSC_CTR_CALL_MO_SETUP] = {"call.mo_setup", "Received setup requests from a MS to init a MO call."},
260 [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."},
261 [MSC_CTR_CALL_MT_SETUP] = {"call.mt_setup", "Sent setup requests to the MS (MT)."},
262 [MSC_CTR_CALL_MT_CONNECT] = {"call.mt_connect", "Sent a connect to the MS (MT)."},
Alexander Couzens92f552f2016-08-23 07:32:27 +0200263 [MSC_CTR_CALL_ACTIVE] = {"call.active", "Count total amount of calls that ever reached active state."},
264 [MSC_CTR_CALL_COMPLETE] = {"call.complete", "Count total amount of calls which got terminated by disconnect req or ind after reaching active state."},
265 [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 +0200266};
267
268
269static const struct rate_ctr_group_desc bsc_ctrg_desc = {
270 "bsc",
271 "base station controller",
272 OSMO_STATS_CLASS_GLOBAL,
273 ARRAY_SIZE(bsc_ctr_description),
274 bsc_ctr_description,
Alexander Couzens20423ea2016-07-12 15:42:02 +0200275};
276
277static const struct rate_ctr_group_desc msc_ctrg_desc = {
278 "msc",
279 "mobile switching center",
280 OSMO_STATS_CLASS_GLOBAL,
281 ARRAY_SIZE(msc_ctr_description),
282 msc_ctr_description,
Harald Welte24ff6ee2009-12-22 00:41:05 +0100283};
284
Harald Welte (local)69de3972009-08-12 14:42:23 +0200285enum gsm_auth_policy {
286 GSM_AUTH_POLICY_CLOSED, /* only subscribers authorized in DB */
287 GSM_AUTH_POLICY_ACCEPT_ALL, /* accept everyone, even if not authorized in DB */
288 GSM_AUTH_POLICY_TOKEN, /* accept first, send token per sms, then revoke authorization */
Maxddee01f2016-05-24 14:23:27 +0200289 GSM_AUTH_POLICY_REGEXP, /* accept IMSIs matching given regexp */
Harald Welte (local)69de3972009-08-12 14:42:23 +0200290};
291
Harald Welteb84ddfc2009-12-01 17:36:54 +0530292#define GSM_T3101_DEFAULT 10
Harald Welte67161f22012-06-03 13:01:47 +0200293#define GSM_T3105_DEFAULT 40
Harald Welteb84ddfc2009-12-01 17:36:54 +0530294#define GSM_T3113_DEFAULT 60
Andreas Eversberg75e13a42013-02-07 11:51:16 +0100295#define GSM_T3122_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530296
Neels Hofmeyr73983952016-05-10 13:29:33 +0200297struct gsm_tz {
298 int override; /* if 0, use system's time zone instead. */
299 int hr; /* hour */
300 int mn; /* minute */
301 int dst; /* daylight savings */
302};
303
Harald Welte52b1f982008-12-23 20:25:15 +0000304struct gsm_network {
305 /* global parameters */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200306 uint16_t country_code;
307 uint16_t network_code;
Harald Weltec6ba9c22008-12-30 18:01:02 +0000308 char *name_long;
309 char *name_short;
Harald Welte (local)69de3972009-08-12 14:42:23 +0200310 enum gsm_auth_policy auth_policy;
Maxddee01f2016-05-24 14:23:27 +0200311 regex_t authorized_regexp;
312 char *authorized_reg_str;
Harald Welte1085c092009-11-18 20:33:19 +0100313 enum gsm48_reject_value reject_cause;
Harald Welte4381cfe2009-08-30 15:47:06 +0900314 int a5_encryption;
Holger Hans Peter Freytherf7d752f2009-11-16 17:12:38 +0100315 int neci;
Harald Welte648b6ce2009-12-14 09:00:24 +0100316 int send_mm_info;
Harald Weltebc814502009-12-19 21:41:52 +0100317 struct {
318 int active;
Harald Weltef7c28b02009-12-21 13:30:17 +0100319 /* Window RXLEV averaging */
320 unsigned int win_rxlev_avg; /* number of SACCH frames */
321 /* Window RXQUAL averaging */
322 unsigned int win_rxqual_avg; /* number of SACCH frames */
323 /* Window RXLEV neighbouring cells averaging */
324 unsigned int win_rxlev_avg_neigh; /* number of SACCH frames */
325
326 /* how often should we check for power budget HO */
327 unsigned int pwr_interval; /* SACCH frames */
328 /* how much better does a neighbor cell have to be ? */
329 unsigned int pwr_hysteresis; /* dBm */
330 /* maximum distacne before we try a handover */
331 unsigned int max_distance; /* TA values */
Harald Weltebc814502009-12-19 21:41:52 +0100332 } handover;
Harald Welte52b1f982008-12-23 20:25:15 +0000333
Alexander Couzensb847a212016-08-02 11:34:11 +0200334 struct rate_ctr_group *bsc_ctrs;
335 struct rate_ctr_group *msc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200336 struct osmo_counter *active_calls;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100337
Harald Welte4bfdfe72009-06-10 23:11:52 +0800338 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200339 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200340 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800341 struct llist_head upqueue;
342 struct llist_head trans_list;
Holger Hans Peter Freytherabcddf12010-06-14 18:20:15 +0800343 struct bsc_api *bsc_api;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800344
Harald Welte52b1f982008-12-23 20:25:15 +0000345 unsigned int num_bts;
Harald Weltee441d9c2009-06-21 16:17:15 +0200346 struct llist_head bts_list;
Holger Hans Peter Freytherc4d88ad2009-11-21 21:18:38 +0100347
348 /* timer values */
349 int T3101;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100350 int T3103;
351 int T3105;
352 int T3107;
353 int T3109;
354 int T3111;
355 int T3113;
356 int T3115;
357 int T3117;
358 int T3119;
Harald Welte2862dca2010-12-23 14:39:29 +0100359 int T3122;
Holger Hans Peter Freyther23975e72009-11-21 21:42:26 +0100360 int T3141;
Harald Welteeab84a12009-12-13 10:53:12 +0100361
Jan Luebbebfbdeec2012-12-27 00:27:16 +0100362 /* timer to expire old location updates */
363 struct osmo_timer_list subscr_expire_timer;
364
Harald Welteeab84a12009-12-13 10:53:12 +0100365 /* Radio Resource Location Protocol (TS 04.31) */
366 struct {
367 enum rrlp_mode mode;
368 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800369
Alexander Couzens11368112016-11-28 23:26:50 +0100370 enum gsm_chan_t ctype_by_chreq[18];
Holger Hans Peter Freyther78891072010-09-06 09:36:02 +0800371
Holger Hans Peter Freyther76fc4a32010-09-06 09:41:50 +0800372 /* Use a TCH for handling requests of type paging any */
373 int pag_any_tch;
374
Holger Hans Peter Freyther3e8e0462010-09-15 22:29:25 +0800375 /* MSC data in case we are a true BSC */
Holger Hans Peter Freyther8ec49522011-08-15 15:53:00 +0200376 struct osmo_bsc_data *bsc_data;
Holger Hans Peter Freytherdaee5ca2010-12-22 12:34:39 +0100377
378 /* subscriber related features */
Maxe6052c42016-06-30 10:25:49 +0200379 bool auto_create_subscr;
380 bool auto_assign_exten;
Max0fcd2e22016-06-07 15:32:16 +0200381 uint64_t ext_min;
382 uint64_t ext_max;
Jacob Erlbeck1e30a282014-12-03 09:28:24 +0100383 struct gsm_subscriber_group *subscr_group;
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100384 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200385
Holger Hans Peter Freyther666e36a2015-07-13 20:33:08 +0200386 /* nitb related control */
387 int avoid_tmsi;
388
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200389 /* control interface */
390 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200391
392 /* Allow or disallow TCH/F on dynamic TCH/F_TCH/H_PDCH; OS#1778 */
393 bool dyn_ts_allow_tch_f;
Neels Hofmeyrd90fa422016-05-09 21:03:12 +0200394
395 /* all active subscriber connections. */
396 struct llist_head subscr_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200397
398 /* if override is nonzero, this timezone data is used for all MM
399 * contexts. */
400 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
401 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100402 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200403 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100404
405 /* List of all struct bsc_subscr used in libbsc. This llist_head is
406 * allocated so that the llist_head pointer itself can serve as a
407 * talloc context (useful to not have to pass the entire gsm_network
408 * struct to the bsc_subscr_* API, and for bsc_susbscr unit tests to
409 * not require gsm_data.h). In an MSC-without-BSC environment, this
410 * pointer is NULL to indicate absence of a bsc_subscribers list. */
411 struct llist_head *bsc_subscribers;
Harald Welte52b1f982008-12-23 20:25:15 +0000412};
413
Harald Welted4bdee72012-11-08 19:44:08 +0100414struct osmo_esme;
415
416enum gsm_sms_source_id {
417 SMS_SOURCE_UNKNOWN = 0,
418 SMS_SOURCE_MS, /* received from MS */
419 SMS_SOURCE_VTY, /* received from VTY */
420 SMS_SOURCE_SMPP, /* received via SMPP */
421};
422
Harald Welte7e310b12009-03-30 20:56:32 +0000423#define SMS_HDR_SIZE 128
424#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100425
426struct gsm_sms_addr {
427 uint8_t ton;
428 uint8_t npi;
429 char addr[21+1];
430};
431
Harald Welte7e310b12009-03-30 20:56:32 +0000432struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900433 unsigned long long id;
Harald Welte7e310b12009-03-30 20:56:32 +0000434 struct gsm_subscriber *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100435 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100436 enum gsm_sms_source_id source;
437
438 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200439 uint8_t transaction_id;
440 uint32_t msg_ref;
441 } gsm411;
442
443 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100444 struct osmo_esme *esme;
445 uint32_t sequence_nr;
446 int transaction_mode;
447 char msg_id[16];
448 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000449
Harald Welteb9c758b2009-07-05 14:02:46 +0200450 unsigned long validity_minutes;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200451 uint8_t reply_path_req;
452 uint8_t status_rep_req;
453 uint8_t ud_hdr_ind;
454 uint8_t protocol_id;
455 uint8_t data_coding_scheme;
456 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200457 uint8_t user_data_len;
458 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200459
Harald Welte7e310b12009-03-30 20:56:32 +0000460 char text[SMS_TEXT_SIZE];
461};
462
Neels Hofmeyrc13e6872016-05-11 13:53:47 +0200463extern void talloc_ctx_init(void *ctx_root);
464
Harald Welte39315c42010-01-10 18:01:52 +0100465int gsm_set_bts_type(struct gsm_bts *bts, enum gsm_bts_type type);
Harald Weltee441d9c2009-06-21 16:17:15 +0200466
Harald Welte84874c92009-12-14 22:33:02 +0100467/* Get reference to a neighbor cell on a given BCCH ARFCN */
Harald Welte0b121032009-12-15 00:21:31 +0100468struct gsm_bts *gsm_bts_neighbor(const struct gsm_bts *bts,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200469 uint16_t arfcn, uint8_t bsic);
Harald Welte84874c92009-12-14 22:33:02 +0100470
Harald Welte1d014a52009-08-08 15:38:29 +0200471enum gsm_bts_type parse_btstype(const char *arg);
Holger Hans Peter Freyther2dceae62009-06-12 17:39:38 +0200472const char *btstype2str(enum gsm_bts_type type);
Harald Weltebe991492009-05-23 13:56:40 +0000473struct gsm_bts *gsm_bts_by_lac(struct gsm_network *net, unsigned int lac,
474 struct gsm_bts *start_bts);
Harald Welte32201c12009-03-10 12:15:10 +0000475
Andreas Eversberg8226fa72009-06-29 15:19:38 +0200476extern void *tall_bsc_ctx;
Harald Weltef88c8a02009-12-20 13:48:15 +0100477extern int ipacc_rtp_direct;
Harald Welte2cf161b2009-06-20 22:36:41 +0200478
Harald Weltef383aa12012-07-02 19:51:55 +0200479/* this actaully refers to the IPA transport, not the BTS model */
Harald Welte32201c12009-03-10 12:15:10 +0000480static inline int is_ipaccess_bts(struct gsm_bts *bts)
481{
482 switch (bts->type) {
Mike Habene2d82272009-10-02 12:19:34 +0100483 case GSM_BTS_TYPE_NANOBTS:
Maxf9685c12017-03-23 12:01:07 +0100484 case GSM_BTS_TYPE_OSMOBTS:
Harald Welte32201c12009-03-10 12:15:10 +0000485 return 1;
486 default:
487 break;
488 }
489 return 0;
490}
491
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200492static inline int is_sysmobts_v2(struct gsm_bts *bts)
493{
494 switch (bts->type) {
Maxf9685c12017-03-23 12:01:07 +0100495 case GSM_BTS_TYPE_OSMOBTS:
Holger Hans Peter Freyther6f6cbf72015-04-04 19:35:22 +0200496 return 1;
497 default:
498 break;
499 }
500 return 0;
501}
502
Harald Welte5b570672009-08-10 10:08:01 +0200503static inline int is_siemens_bts(struct gsm_bts *bts)
504{
505 switch (bts->type) {
506 case GSM_BTS_TYPE_BS11:
507 return 1;
508 default:
509 break;
510 }
511
512 return 0;
513}
514
Andreas Eversberg7d8fa342013-12-05 13:25:06 +0100515static inline int is_nokia_bts(struct gsm_bts *bts)
516{
517 switch (bts->type) {
518 case GSM_BTS_TYPE_NOKIA_SITE:
519 return 1;
520 default:
521 break;
522 }
523
524 return 0;
525}
526
Andreas Eversbergdcf38e12013-12-05 14:37:11 +0100527static inline int is_e1_bts(struct gsm_bts *bts)
528{
529 switch (bts->type) {
530 case GSM_BTS_TYPE_BS11:
531 case GSM_BTS_TYPE_RBS2000:
532 case GSM_BTS_TYPE_NOKIA_SITE:
533 return 1;
534 default:
535 break;
536 }
537
538 return 0;
539}
540
Harald Welte (local)69de3972009-08-12 14:42:23 +0200541enum gsm_auth_policy gsm_auth_policy_parse(const char *arg);
542const char *gsm_auth_policy_name(enum gsm_auth_policy policy);
543
Harald Welteeab84a12009-12-13 10:53:12 +0100544enum rrlp_mode rrlp_mode_parse(const char *arg);
545const char *rrlp_mode_name(enum rrlp_mode mode);
546
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100547enum bts_gprs_mode bts_gprs_mode_parse(const char *arg, int *valid);
Harald Welte4511d892010-04-18 15:51:20 +0200548const char *bts_gprs_mode_name(enum bts_gprs_mode mode);
Holger Hans Peter Freyther4e13a8f2015-01-31 22:16:00 +0100549int bts_gprs_mode_is_compat(struct gsm_bts *bts, enum bts_gprs_mode mode);
Harald Welte4511d892010-04-18 15:51:20 +0200550
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200551int gsm48_ra_id_by_bts(uint8_t *buf, struct gsm_bts *bts);
Harald Welte97a282b2010-03-14 15:37:43 +0800552void gprs_ra_id_by_bts(struct gprs_ra_id *raid, struct gsm_bts *bts);
Harald Welted12b0fd2009-12-15 21:36:05 +0100553struct gsm_meas_rep *lchan_next_meas_rep(struct gsm_lchan *lchan);
554
Harald Weltef3d8e922010-06-14 22:44:42 +0200555int gsm_btsmodel_set_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Weltefbda4e12010-03-04 11:04:52 +0100556int gsm_bts_model_register(struct gsm_bts_model *model);
557
Neels Hofmeyr42eb0142016-05-20 17:15:44 +0200558struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_lchan *lchan);
559void bsc_subscr_con_free(struct gsm_subscriber_connection *conn);
560
561struct gsm_subscriber_connection *msc_subscr_con_allocate(struct gsm_network *network);
562void msc_subscr_con_free(struct gsm_subscriber_connection *conn);
Holger Hans Peter Freyther2412a072010-06-28 15:47:12 +0800563
Harald Welte3300c012011-06-05 13:31:33 +0200564struct gsm_bts *gsm_bts_alloc_register(struct gsm_network *net,
565 enum gsm_bts_type type,
Harald Weltea2bbc5e2015-11-20 10:43:31 +0100566 uint8_t bsic);
Harald Welte142d12d2014-12-29 17:47:08 +0100567
Harald Welte3300c012011-06-05 13:31:33 +0200568void set_ts_e1link(struct gsm_bts_trx_ts *ts, uint8_t e1_nr,
569 uint8_t e1_ts, uint8_t e1_ts_ss);
570
571void gsm_trx_lock_rf(struct gsm_bts_trx *trx, int locked);
Max71d082b2017-05-30 15:03:38 +0200572bool gsm_btsmodel_has_feature(struct gsm_bts_model *model, enum gsm_bts_features feat);
Harald Welte3300c012011-06-05 13:31:33 +0200573struct gsm_bts_trx *gsm_bts_trx_by_nr(struct gsm_bts *bts, int nr);
Holger Hans Peter Freythera49b2c02014-11-21 11:18:45 +0100574int gsm_bts_trx_set_system_infos(struct gsm_bts_trx *trx);
Alexander Chemerisc36a13b2015-05-30 14:40:54 -0400575int gsm_bts_set_system_infos(struct gsm_bts *bts);
Harald Welte3300c012011-06-05 13:31:33 +0200576
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200577/* generic E1 line operations for all ISDN-based BTS. */
578extern struct e1inp_line_ops bts_isdn_e1inp_line_ops;
579
Harald Weltee555c2b2012-08-17 13:02:12 +0200580extern const struct value_string bts_type_names[_NUM_GSM_BTS_TYPE+1];
581extern const struct value_string bts_type_descs[_NUM_GSM_BTS_TYPE+1];
582
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100583/* control interface handling */
584int bsc_base_ctrl_cmds_install(void);
Holger Hans Peter Freyther9dbc3f82014-03-23 12:06:36 +0100585int msc_ctrl_cmds_install(void);
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100586
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100587/* dependency handling */
588void bts_depend_mark(struct gsm_bts *bts, int dep);
589void bts_depend_clear(struct gsm_bts *bts, int dep);
590int bts_depend_check(struct gsm_bts *bts);
Holger Hans Peter Freytherf7e23c52014-12-17 15:44:32 +0100591int bts_depend_is_depedency(struct gsm_bts *base, struct gsm_bts *other);
Holger Hans Peter Freytherc22930e2014-12-17 14:46:17 +0100592
Harald Welte2f8b9d22017-06-18 11:12:13 +0300593int gsm_bts_get_radio_link_timeout(const struct gsm_bts *bts);
594void gsm_bts_set_radio_link_timeout(struct gsm_bts *bts, int value);
595
Harald Welte6be350c2011-05-25 13:10:08 +0200596#endif /* _GSM_DATA_H */