blob: 1b34c2a5d0bb87b1abdc2038059461e23a30f2fe [file] [log] [blame]
Harald Welte288be162010-05-01 16:48:27 +02001#ifndef _SGSN_H
2#define _SGSN_H
3
Harald Welte288be162010-05-01 16:48:27 +02004
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +01005#include <osmocom/core/msgb.h>
Alexander Couzensf23e2db2020-07-27 22:39:58 +02006#include <osmocom/core/select.h>
Max93408ae2016-06-28 14:10:16 +02007#include <osmocom/crypt/gprs_cipher.h>
Alexander Couzensf23e2db2020-07-27 22:39:58 +02008#include <osmocom/gprs/gprs_ns2.h>
Pau Espin Pedrole5c89982021-05-03 18:16:42 +02009#include <osmocom/gprs/gprs_bssgp.h>
10
Neels Hofmeyr396f2e62017-09-04 15:13:25 +020011#include <osmocom/sgsn/gprs_sgsn.h>
Pau Espin Pedrole5c89982021-05-03 18:16:42 +020012#include <osmocom/sgsn/gtp_mme.h>
Harald Welte0b588be2018-07-30 18:25:31 +020013#include <osmocom/gsm/oap_client.h>
Harald Weltef4b2c4c2018-09-16 07:53:41 +020014#include <osmocom/gsupclient/gsup_client.h>
Neels Hofmeyr396f2e62017-09-04 15:13:25 +020015#include <osmocom/sgsn/common.h>
Harald Welte288be162010-05-01 16:48:27 +020016
Neels Hofmeyr69e356b2018-03-15 13:00:35 +010017#include "../../bscconfig.h"
18
19#if BUILD_IU
20#include <osmocom/ranap/iu_client.h>
21#endif
22
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080023#include <ares.h>
Maxc005db72017-10-27 18:43:29 +020024#include <gtp.h>
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080025
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080026struct hostent;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010027
Jacob Erlbeck106f5472014-11-04 10:08:37 +010028enum sgsn_auth_policy {
29 SGSN_AUTH_POLICY_OPEN,
30 SGSN_AUTH_POLICY_CLOSED,
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010031 SGSN_AUTH_POLICY_ACL_ONLY,
32 SGSN_AUTH_POLICY_REMOTE
Jacob Erlbeck106f5472014-11-04 10:08:37 +010033};
34
Alexander Couzens14314bd2016-07-05 09:52:52 +020035
36enum sgsn_rate_ctr_keys {
Alexander Couzens4e699a92016-07-05 11:04:27 +020037 CTR_LLC_DL_BYTES,
38 CTR_LLC_UL_BYTES,
39 CTR_LLC_DL_PACKETS,
40 CTR_LLC_UL_PACKETS,
Alexander Couzens14314bd2016-07-05 09:52:52 +020041 CTR_GPRS_ATTACH_REQUEST,
42 CTR_GPRS_ATTACH_ACKED,
43 CTR_GPRS_ATTACH_REJECTED,
44 CTR_GPRS_DETACH_REQUEST,
45 CTR_GPRS_DETACH_ACKED,
46 CTR_GPRS_ROUTING_AREA_REQUEST,
47 CTR_GPRS_ROUTING_AREA_ACKED,
48 CTR_GPRS_ROUTING_AREA_REJECT,
49 /* PDP single packet counter / GSM 04.08 9.5.1 - 9.5.9 */
50 CTR_PDP_ACTIVATE_REQUEST,
51 CTR_PDP_ACTIVATE_REJECT,
52 CTR_PDP_ACTIVATE_ACCEPT,
53 CTR_PDP_REQUEST_ACTIVATE, /* unused */
54 CTR_PDP_REQUEST_ACTIVATE_REJ, /* unused */
55 CTR_PDP_MODIFY_REQUEST, /* unsued */
56 CTR_PDP_MODIFY_ACCEPT, /* unused */
57 CTR_PDP_DL_DEACTIVATE_REQUEST,
58 CTR_PDP_DL_DEACTIVATE_ACCEPT,
59 CTR_PDP_UL_DEACTIVATE_REQUEST,
60 CTR_PDP_UL_DEACTIVATE_ACCEPT,
61};
62
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020063struct sgsn_cdr {
64 char *filename;
Pau Espin Pedrol2e9ea502017-11-29 14:01:35 +010065 bool trap;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020066 int interval;
67};
68
Harald Welte288be162010-05-01 16:48:27 +020069struct sgsn_config {
70 /* parsed from config file */
Harald Welte288be162010-05-01 16:48:27 +020071
Harald Welte2720e732010-05-17 00:44:57 +020072 char *gtp_statedir;
73 struct sockaddr_in gtp_listenaddr;
74
Harald Welte288be162010-05-01 16:48:27 +020075 /* misc */
Alexander Couzensf23e2db2020-07-27 22:39:58 +020076 struct gprs_ns2_inst *nsi;
Harald Welte7f6da482013-03-19 11:00:13 +010077
Jacob Erlbeck106f5472014-11-04 10:08:37 +010078 enum sgsn_auth_policy auth_policy;
Neels Hofmeyr340a7e92022-03-07 15:37:24 +010079 uint8_t gea_encryption_mask;
Neels Hofmeyr3c7656a2022-03-07 15:38:59 +010080 uint8_t uea_encryption_mask;
Harald Welte7f6da482013-03-19 11:00:13 +010081 struct llist_head imsi_acl;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010082
83 struct sockaddr_in gsup_server_addr;
84 int gsup_server_port;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010085
Pau Espin Pedrold1463bc2019-06-13 19:03:25 +020086 /* Only meaningful if auth_policy is SGSN_AUTH_POLICY_REMOTE */
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010087 int require_authentication;
Pau Espin Pedrold1463bc2019-06-13 19:03:25 +020088
Jacob Erlbeck771573c2014-12-19 18:08:48 +010089 int require_update_location;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020090
91 /* CDR configuration */
92 struct sgsn_cdr cdr;
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080093
Pau Espin Pedrola299d652019-08-14 19:11:10 +020094 /* Timer defintions */
95 struct osmo_tdef *T_defs;
Harald Welte94508822015-08-15 19:08:21 +020096
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080097 int dynamic_lookup;
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +020098
Harald Welte0b588be2018-07-30 18:25:31 +020099 struct osmo_oap_client_config oap;
Philippf1f34362016-08-26 17:00:21 +0200100
101 /* RFC1144 TCP/IP header compression */
102 struct {
103 int active;
104 int passive;
105 int s01;
106 } pcomp_rfc1144;
Philipp73f83d52016-09-02 13:38:01 +0200107
108 /* V.42vis data compression */
109 struct {
110 int active;
111 int passive;
112 int p0;
113 int p1;
114 int p2;
115 } dcomp_v42bis;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200116
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100117#if BUILD_IU
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200118 struct {
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100119 enum ranap_nsap_addr_enc rab_assign_addr_enc;
Pau Espin Pedrol2c908992019-08-19 19:06:06 +0200120 uint32_t cs7_instance;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200121 } iu;
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100122#endif
Stefan Sperling88220092018-12-11 14:42:00 +0100123
124 /* This is transmitted as IPA Serial Number tag, which is used for GSUP routing (e.g. in OsmoHLR).
125 * This name must be set in a multi-SGSN network, and it must be unique to each SGSN.
126 * If no name is set, the IPA Serial Number will be the same as the Unit Name,
127 * and will be of the form 'SGSN-00-00-00-00-00-00' */
128 char *sgsn_ipa_name;
Harald Welte288be162010-05-01 16:48:27 +0200129};
130
Harald Welte2720e732010-05-17 00:44:57 +0200131struct sgsn_instance {
132 char *config_file;
133 struct sgsn_config cfg;
134 /* File descriptor wrappers for LibGTP */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200135 struct osmo_fd gtp_fd0;
136 struct osmo_fd gtp_fd1c;
137 struct osmo_fd gtp_fd1u;
Harald Welte2720e732010-05-17 00:44:57 +0200138 /* GSN instance for libgtp */
139 struct gsn_t *gsn;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100140 /* Subscriber */
Harald Weltef4b2c4c2018-09-16 07:53:41 +0200141 struct osmo_gsup_client *gsup_client;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100142 /* LLME inactivity timer */
143 struct osmo_timer_list llme_timer;
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800144
145 /* c-ares event loop integration */
146 struct osmo_timer_list ares_timer;
147 struct llist_head ares_fds;
148 ares_channel ares_channel;
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800149 struct ares_addr_node *ares_servers;
Alexander Couzens14314bd2016-07-05 09:52:52 +0200150
151 struct rate_ctr_group *rate_ctrs;
Pau Espin Pedrole5c89982021-05-03 18:16:42 +0200152
153 struct llist_head mme_list; /* list of struct sgsn_mme_ctx */
Harald Welte2720e732010-05-17 00:44:57 +0200154};
155
Harald Welte8fc1a462010-05-17 00:53:10 +0200156extern struct sgsn_instance *sgsn;
Harald Welte288be162010-05-01 16:48:27 +0200157
158/* sgsn_vty.c */
159
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +0200160int sgsn_vty_init(struct sgsn_config *cfg);
161int sgsn_parse_config(const char *config_file);
Maxc005db72017-10-27 18:43:29 +0200162char *sgsn_gtp_ntoa(struct ul16_t *ul);
Harald Welte288be162010-05-01 16:48:27 +0200163
164/* sgsn.c */
165
166/* Main input function for Gb proxy */
Alexander Couzensf23e2db2020-07-27 22:39:58 +0200167int sgsn_rcvmsg(struct msgb *msg, struct gprs_ns2_vc *nsvc, uint16_t ns_bvci);
Harald Welte288be162010-05-01 16:48:27 +0200168
Pau Espin Pedrol6dfb5fe2019-08-29 17:21:00 +0200169/* sgsn_libgtp.c */
Harald Welte77289c22010-05-18 14:32:29 +0200170struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
Harald Welte6abf94e2010-05-18 10:35:06 +0200171 struct sgsn_mm_ctx *mmctx,
172 uint16_t nsapi,
173 struct tlv_parsed *tp);
Harald Welte77289c22010-05-18 14:32:29 +0200174int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
Daniel Willmann21b269f2016-05-11 12:43:47 +0200175void sgsn_pdp_upd_gtp_u(struct sgsn_pdp_ctx *pdp, void *addr, size_t alen);
Pau Espin Pedrolfa120102018-07-09 20:37:47 +0200176void sgsn_ggsn_echo_req(struct sgsn_ggsn_ctx *ggc);
Pau Espin Pedrol6dfb5fe2019-08-29 17:21:00 +0200177int send_act_pdp_cont_acc(struct sgsn_pdp_ctx *pctx);
Pau Espin Pedrole5c89982021-05-03 18:16:42 +0200178int sgsn_mme_ran_info_req(struct sgsn_mme_ctx *mme, const struct bssgp_ran_information_pdu *pdu);
Harald Welte77289c22010-05-18 14:32:29 +0200179
Harald Welteebabdea2010-06-01 18:28:10 +0200180/* gprs_sndcp.c */
181
182/* Entry point for the SNSM-ACTIVATE.indication */
183int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Weltece22f922010-06-03 21:21:21 +0200184/* Entry point for the SNSM-DEACTIVATE.indication */
185int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Welteebabdea2010-06-01 18:28:10 +0200186/* Called by SNDCP when it has received/re-assembled a N-PDU */
Harald Welte8911cef2010-07-01 19:56:19 +0200187int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
188 struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
Harald Weltebb1c8052010-06-03 06:38:38 +0200189int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi,
190 void *mmcontext);
Holger Hans Peter Freyther3dccda52011-10-14 23:42:13 +0200191int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
192 uint8_t *hdr, uint16_t len);
Harald Welteebabdea2010-06-01 18:28:10 +0200193
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200194
195/*
196 * CDR related functionality
197 */
198int sgsn_cdr_init(struct sgsn_instance *sgsn);
199
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800200
201/*
202 * C-ARES related functionality
203 */
204int sgsn_ares_init(struct sgsn_instance *sgsn);
205int sgsn_ares_query(struct sgsn_instance *sgsm, const char *name, ares_host_callback cb, void *data);
206
Harald Welte288be162010-05-01 16:48:27 +0200207#endif