blob: 30a3c795bf34247574160698517dda1bed2b8d03 [file] [log] [blame]
Harald Welte52b1f982008-12-23 20:25:15 +00001#ifndef _GSM_DATA_H
2#define _GSM_DATA_H
3
Harald Weltef142c972011-05-24 13:25:38 +02004#include <stdint.h>
Maxddee01f2016-05-24 14:23:27 +02005#include <regex.h>
6#include <sys/types.h>
Maxe6052c42016-06-30 10:25:49 +02007#include <stdbool.h>
Harald Weltef142c972011-05-24 13:25:38 +02008
9#include <osmocom/core/timer.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020010#include <osmocom/core/rate_ctr.h>
Harald Welte6be350c2011-05-25 13:10:08 +020011#include <osmocom/core/select.h>
Alexander Couzens20423ea2016-07-12 15:42:02 +020012#include <osmocom/core/stats.h>
Max43b01b02017-09-15 11:22:30 +020013#include <osmocom/gsm/gsm48.h>
Harald Welte121e9a42016-04-20 13:13:19 +020014#include <osmocom/crypt/auth.h>
Harald Weltef142c972011-05-24 13:25:38 +020015
Neels Hofmeyr6c8afe12017-09-04 01:03:58 +020016#include <osmocom/mgcp_client/mgcp_client.h>
Harald Welteb96be392011-05-25 12:33:33 +020017
Neels Hofmeyr79921222018-11-30 01:46:51 +010018#include <osmocom/msc/msc_common.h>
19
Harald Welted35038d2018-01-25 00:07:33 +010020#include "gsm_data_shared.h"
21
Harald Welte0e2fa5d2018-04-09 16:35:01 +020022/* TS 48.008 DLCI containing DCCH/ACCH + SAPI */
23#define OMSC_LINKID_CB(__msgb) (__msgb)->cb[3]
Philipp Maierfbf66102017-04-09 12:32:51 +020024
Neels Hofmeyr21adb2b2018-03-15 12:55:46 +010025#include "../../bscconfig.h"
26#if BUILD_IU
27#include <osmocom/ranap/iu_client.h>
28#endif
29
Holger Hans Peter Freytherd7b22c62013-04-29 09:11:02 +020030/** annotations for msgb ownership */
31#define __uses
32
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020033struct mncc_sock_state;
Harald Welte2483f1b2016-06-19 18:06:02 +020034struct vlr_instance;
35struct vlr_subscr;
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +020036
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +010037#define tmsi_from_string(str) strtoul(str, NULL, 10)
38
Harald Welte8e1e3ee2009-02-01 13:32:45 +000039struct msgb;
40typedef int gsm_cbfn(unsigned int hooknum,
41 unsigned int event,
42 struct msgb *msg,
43 void *data, void *param);
44
Alexander Couzensb847a212016-08-02 11:34:11 +020045enum {
Alexander Couzens20423ea2016-07-12 15:42:02 +020046 MSC_CTR_LOC_UPDATE_TYPE_ATTACH,
47 MSC_CTR_LOC_UPDATE_TYPE_NORMAL,
48 MSC_CTR_LOC_UPDATE_TYPE_PERIODIC,
49 MSC_CTR_LOC_UPDATE_TYPE_DETACH,
Neels Hofmeyr36891a72016-05-09 13:18:03 +020050 MSC_CTR_LOC_UPDATE_FAILED,
51 MSC_CTR_LOC_UPDATE_COMPLETED,
Neels Hofmeyre3d3dc62018-03-31 00:02:14 +020052 MSC_CTR_CM_SERVICE_REQUEST_REJECTED,
53 MSC_CTR_CM_SERVICE_REQUEST_ACCEPTED,
54 MSC_CTR_PAGING_RESP_REJECTED,
55 MSC_CTR_PAGING_RESP_ACCEPTED,
Alexander Couzens20423ea2016-07-12 15:42:02 +020056 MSC_CTR_SMS_SUBMITTED,
57 MSC_CTR_SMS_NO_RECEIVER,
58 MSC_CTR_SMS_DELIVERED,
59 MSC_CTR_SMS_RP_ERR_MEM,
60 MSC_CTR_SMS_RP_ERR_OTHER,
Alexander Couzensaa386d22016-08-21 20:16:33 +020061 MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR,
Alexander Couzens20423ea2016-07-12 15:42:02 +020062 MSC_CTR_CALL_MO_SETUP,
63 MSC_CTR_CALL_MO_CONNECT_ACK,
64 MSC_CTR_CALL_MT_SETUP,
65 MSC_CTR_CALL_MT_CONNECT,
Alexander Couzens92f552f2016-08-23 07:32:27 +020066 MSC_CTR_CALL_ACTIVE,
67 MSC_CTR_CALL_COMPLETE,
68 MSC_CTR_CALL_INCOMPLETE,
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +070069 MSC_CTR_NC_SS_MO_REQUESTS,
70 MSC_CTR_NC_SS_MO_ESTABLISHED,
71 MSC_CTR_NC_SS_MT_REQUESTS,
72 MSC_CTR_NC_SS_MT_ESTABLISHED,
Max366390d2018-11-02 16:01:03 +010073 MSC_CTR_BSSMAP_CIPHER_MODE_REJECT,
74 MSC_CTR_BSSMAP_CIPHER_MODE_COMPLETE,
Alexander Couzens20423ea2016-07-12 15:42:02 +020075};
76
77static const struct rate_ctr_desc msc_ctr_description[] = {
Neels Hofmeyrc6bf2742017-11-18 23:22:17 +010078 [MSC_CTR_LOC_UPDATE_TYPE_ATTACH] = {"loc_update_type:attach", "Received location update imsi attach requests."},
79 [MSC_CTR_LOC_UPDATE_TYPE_NORMAL] = {"loc_update_type:normal", "Received location update normal requests."},
80 [MSC_CTR_LOC_UPDATE_TYPE_PERIODIC] = {"loc_update_type:periodic", "Received location update periodic requests."},
81 [MSC_CTR_LOC_UPDATE_TYPE_DETACH] = {"loc_update_type:detach", "Received location update detach indication."},
82 [MSC_CTR_LOC_UPDATE_FAILED] = {"loc_update_resp:failed", "Rejected location updates."},
83 [MSC_CTR_LOC_UPDATE_COMPLETED] = {"loc_update_resp:completed", "Successful location updates."},
Neels Hofmeyre3d3dc62018-03-31 00:02:14 +020084 [MSC_CTR_CM_SERVICE_REQUEST_REJECTED] = {"cm_service_request:rejected", "Rejected CM Service Request."},
85 [MSC_CTR_CM_SERVICE_REQUEST_ACCEPTED] = {"cm_service_request:accepted", "Accepted CM Service Request."},
86 [MSC_CTR_PAGING_RESP_REJECTED] = {"paging_resp:rejected", "Rejected Paging Response."},
87 [MSC_CTR_PAGING_RESP_ACCEPTED] = {"paging_resp:accepted", "Accepted Paging Response."},
Neels Hofmeyrc6bf2742017-11-18 23:22:17 +010088 [MSC_CTR_SMS_SUBMITTED] = {"sms:submitted", "Received a RPDU from a MS (MO)."},
89 [MSC_CTR_SMS_NO_RECEIVER] = {"sms:no_receiver", "Counts SMS which couldn't routed because no receiver found."},
90 [MSC_CTR_SMS_DELIVERED] = {"sms:delivered", "Global SMS Deliver attempts."},
91 [MSC_CTR_SMS_RP_ERR_MEM] = {"sms:rp_err_mem", "CAUSE_MT_MEM_EXCEEDED errors of MS responses on a sms deliver attempt."},
92 [MSC_CTR_SMS_RP_ERR_OTHER] = {"sms:rp_err_other", "Other error of MS responses on a sms delive attempt."},
93 [MSC_CTR_SMS_DELIVER_UNKNOWN_ERROR] = {"sms:deliver_unknown_error", "Unknown error occured during sms delivery."},
Alexander Couzens20423ea2016-07-12 15:42:02 +020094 /* FIXME: count also sms delivered */
Neels Hofmeyrc6bf2742017-11-18 23:22:17 +010095 [MSC_CTR_CALL_MO_SETUP] = {"call:mo_setup", "Received setup requests from a MS to init a MO call."},
96 [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."},
97 [MSC_CTR_CALL_MT_SETUP] = {"call:mt_setup", "Sent setup requests to the MS (MT)."},
98 [MSC_CTR_CALL_MT_CONNECT] = {"call:mt_connect", "Sent a connect to the MS (MT)."},
99 [MSC_CTR_CALL_ACTIVE] = {"call:active", "Count total amount of calls that ever reached active state."},
100 [MSC_CTR_CALL_COMPLETE] = {"call:complete", "Count total amount of calls which got terminated by disconnect req or ind after reaching active state."},
101 [MSC_CTR_CALL_INCOMPLETE] = {"call:incomplete", "Count total amount of call which got terminated by any other reason after reaching active state."},
Vadim Yanitskiy8e25cc52018-06-23 03:32:20 +0700102 [MSC_CTR_NC_SS_MO_REQUESTS] = {"nc_ss:mo_requests", "Received MS-initiated call independent SS/USSD requests."},
103 [MSC_CTR_NC_SS_MO_ESTABLISHED] = {"nc_ss:mo_established", "Established MS-initiated call independent SS/USSD sessions."},
104 [MSC_CTR_NC_SS_MT_REQUESTS] = {"nc_ss:mt_requests", "Received network-initiated call independent SS/USSD requests."},
105 [MSC_CTR_NC_SS_MT_ESTABLISHED] = {"nc_ss:mt_established", "Established network-initiated call independent SS/USSD sessions."},
Max366390d2018-11-02 16:01:03 +0100106 [MSC_CTR_BSSMAP_CIPHER_MODE_REJECT] = {"bssmap:cipher_mode_reject", "Number of CIPHER MODE REJECT messages processed by BSSMAP layer"},
107 [MSC_CTR_BSSMAP_CIPHER_MODE_COMPLETE] = {"bssmap:cipher_mode_complete", "Number of CIPHER MODE COMPLETE messages processed by BSSMAP layer"},
Alexander Couzensb847a212016-08-02 11:34:11 +0200108};
109
Alexander Couzens20423ea2016-07-12 15:42:02 +0200110static const struct rate_ctr_group_desc msc_ctrg_desc = {
111 "msc",
112 "mobile switching center",
113 OSMO_STATS_CLASS_GLOBAL,
114 ARRAY_SIZE(msc_ctr_description),
115 msc_ctr_description,
Harald Welte24ff6ee2009-12-22 00:41:05 +0100116};
117
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100118#define MSC_PAGING_RESPONSE_TIMER_DEFAULT 10
Harald Welteb84ddfc2009-12-01 17:36:54 +0530119
Neels Hofmeyr73983952016-05-10 13:29:33 +0200120struct gsm_tz {
121 int override; /* if 0, use system's time zone instead. */
122 int hr; /* hour */
123 int mn; /* minute */
124 int dst; /* daylight savings */
125};
126
Harald Welte52b1f982008-12-23 20:25:15 +0000127struct gsm_network {
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200128 /* TODO MSCSPLIT the gsm_network struct is basically a kitchen sink for
129 * global settings and variables, "madly" mixing BSC and MSC stuff. Split
130 * this in e.g. struct osmo_bsc and struct osmo_msc, with the things
131 * these have in common, like country and network code, put in yet
132 * separate structs and placed as members in osmo_bsc and osmo_msc. */
133
Neels Hofmeyr379d5792018-02-22 04:04:54 +0100134 struct osmo_plmn_id plmn;
135
Harald Weltec6ba9c22008-12-30 18:01:02 +0000136 char *name_long;
137 char *name_short;
Neels Hofmeyr379d5792018-02-22 04:04:54 +0100138
Harald Welte7b222aa2017-12-23 19:30:32 +0100139 /* bit-mask of permitted encryption algorithms. LSB=A5/0, MSB=A5/7 */
140 uint8_t a5_encryption_mask;
Harald Welte2483f1b2016-06-19 18:06:02 +0200141 bool authentication_required;
Harald Welte648b6ce2009-12-14 09:00:24 +0100142 int send_mm_info;
Harald Welte52b1f982008-12-23 20:25:15 +0000143
Alexander Couzensb847a212016-08-02 11:34:11 +0200144 struct rate_ctr_group *msc_ctrs;
Alexander Couzens92f552f2016-08-23 07:32:27 +0200145 struct osmo_counter *active_calls;
Vadim Yanitskiyad64e2a2018-06-26 18:27:25 +0700146 struct osmo_counter *active_nc_ss;
Harald Welte24ff6ee2009-12-22 00:41:05 +0100147
Harald Welte4bfdfe72009-06-10 23:11:52 +0800148 /* layer 4 */
Holger Hans Peter Freyther694c82d2011-10-26 18:37:09 +0200149 struct mncc_sock_state *mncc_state;
Neels Hofmeyr402006d2016-05-11 14:28:25 +0200150 mncc_recv_cb_t mncc_recv;
Harald Welte4bfdfe72009-06-10 23:11:52 +0800151 struct llist_head upqueue;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200152 /*
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100153 * TODO: Move the trans_list into the RAN connection and
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200154 * create a pending list for MT transactions. These exist before
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100155 * we have a RAN connection.
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200156 */
Harald Welte4bfdfe72009-06-10 23:11:52 +0800157 struct llist_head trans_list;
158
Neels Hofmeyr2ff5bcd2017-12-15 03:02:27 +0100159 unsigned int paging_response_timer;
Harald Welteeab84a12009-12-13 10:53:12 +0100160
161 /* Radio Resource Location Protocol (TS 04.31) */
162 struct {
163 enum rrlp_mode mode;
164 } rrlp;
Holger Hans Peter Freyther5a3a61d2010-09-06 09:25:48 +0800165
Holger Hans Peter Freyther11b28f92010-12-24 13:48:27 +0100166 struct gsm_sms_queue *sms_queue;
Daniel Willmann6fc4a982011-07-22 17:55:42 +0200167
168 /* control interface */
169 struct ctrl_handle *ctrl;
Neels Hofmeyr5f0c71b2016-07-23 20:15:28 +0200170
Neels Hofmeyrc036b792018-11-29 22:37:51 +0100171 /* all active RAN connections. */
172 struct llist_head ran_conns;
Neels Hofmeyr73983952016-05-10 13:29:33 +0200173
174 /* if override is nonzero, this timezone data is used for all MM
175 * contexts. */
176 /* TODO: in OsmoNITB, tz-override used to be BTS-specific. To enable
177 * BTS|RNC specific timezone overrides for multi-tz networks in
Neels Hofmeyrfe291de2017-02-23 21:06:12 +0100178 * OsmoMSC, this should be tied to the location area code (LAC). */
Neels Hofmeyr73983952016-05-10 13:29:33 +0200179 struct gsm_tz tz;
Neels Hofmeyr6d804b12017-02-18 22:20:46 +0100180
Harald Welte2483f1b2016-06-19 18:06:02 +0200181 /* MSC: GSUP server address of the HLR */
182 const char *gsup_server_addr_str;
183 uint16_t gsup_server_port;
184
185 struct vlr_instance *vlr;
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200186
187 /* Periodic location update default value */
188 uint8_t t3212;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200189
Philipp Maier9ca7b312018-10-10 17:00:49 +0200190 /* Global MNCC guard timer value */
191 int mncc_guard_timeout;
192
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200193 struct {
Neels Hofmeyr6c8afe12017-09-04 01:03:58 +0200194 struct mgcp_client_conf conf;
195 struct mgcp_client *client;
196 } mgw;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200197
Neels Hofmeyr21adb2b2018-03-15 12:55:46 +0100198#if BUILD_IU
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200199 struct {
Philipp Maierfbf66102017-04-09 12:32:51 +0200200 /* CS7 instance id number (set via VTY) */
201 uint32_t cs7_instance;
Neels Hofmeyr21adb2b2018-03-15 12:55:46 +0100202 enum ranap_nsap_addr_enc rab_assign_addr_enc;
Philipp Maierfbf66102017-04-09 12:32:51 +0200203 struct osmo_sccp_instance *sccp;
Neels Hofmeyr84da6b12016-05-20 21:59:55 +0200204 } iu;
Neels Hofmeyr21adb2b2018-03-15 12:55:46 +0100205#endif
Philipp Maierfbf66102017-04-09 12:32:51 +0200206
207 struct {
208 /* CS7 instance id number (set via VTY) */
209 uint32_t cs7_instance;
210 /* A list with the context information about
211 * all BSCs we have connections with */
212 struct llist_head bscs;
213 struct osmo_sccp_instance *sccp;
214 } a;
Harald Welte69c54a82018-02-09 20:41:14 +0100215
216 struct {
217 /* MSISDN to which to route MO emergency calls */
218 char *route_to_msisdn;
219 } emergency;
Harald Welte52b1f982008-12-23 20:25:15 +0000220};
221
Harald Welted4bdee72012-11-08 19:44:08 +0100222struct osmo_esme;
223
224enum gsm_sms_source_id {
225 SMS_SOURCE_UNKNOWN = 0,
226 SMS_SOURCE_MS, /* received from MS */
227 SMS_SOURCE_VTY, /* received from VTY */
228 SMS_SOURCE_SMPP, /* received via SMPP */
229};
230
Harald Welte7e310b12009-03-30 20:56:32 +0000231#define SMS_HDR_SIZE 128
232#define SMS_TEXT_SIZE 256
Harald Weltee07b6a72012-11-23 19:02:37 +0100233
234struct gsm_sms_addr {
235 uint8_t ton;
236 uint8_t npi;
237 char addr[21+1];
238};
239
Harald Welte7e310b12009-03-30 20:56:32 +0000240struct gsm_sms {
Harald Welted409be72009-11-07 00:06:19 +0900241 unsigned long long id;
Harald Welte2483f1b2016-06-19 18:06:02 +0200242 struct vlr_subscr *receiver;
Harald Weltec0de14d2012-11-23 23:35:01 +0100243 struct gsm_sms_addr src, dst;
Harald Welted4bdee72012-11-08 19:44:08 +0100244 enum gsm_sms_source_id source;
245
246 struct {
Pablo Neira Ayuso93ffbd02017-05-04 18:44:22 +0200247 uint8_t transaction_id;
248 uint32_t msg_ref;
249 } gsm411;
250
251 struct {
Harald Welted4bdee72012-11-08 19:44:08 +0100252 struct osmo_esme *esme;
253 uint32_t sequence_nr;
254 int transaction_mode;
255 char msg_id[16];
256 } smpp;
Harald Welte7e310b12009-03-30 20:56:32 +0000257
Harald Welteb9c758b2009-07-05 14:02:46 +0200258 unsigned long validity_minutes;
Keithc601adc2017-08-16 22:45:07 +0200259 time_t created;
Pablo Neira Ayusoadae8592017-08-07 14:01:30 +0100260 bool is_report;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200261 uint8_t reply_path_req;
262 uint8_t status_rep_req;
263 uint8_t ud_hdr_ind;
264 uint8_t protocol_id;
265 uint8_t data_coding_scheme;
266 uint8_t msg_ref;
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +0200267 uint8_t user_data_len;
268 uint8_t user_data[SMS_TEXT_SIZE];
Harald Weltef3efc592009-07-27 20:11:35 +0200269
Harald Welte7e310b12009-03-30 20:56:32 +0000270 char text[SMS_TEXT_SIZE];
271};
272
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100273/* control interface handling */
274int bsc_base_ctrl_cmds_install(void);
Harald Welte2483f1b2016-06-19 18:06:02 +0200275int msc_ctrl_cmds_install(struct gsm_network *net);
Holger Hans Peter Freytherf8c42192013-01-09 17:03:27 +0100276
Harald Welte6be350c2011-05-25 13:10:08 +0200277#endif /* _GSM_DATA_H */