blob: d9ef938f52db6166c733b8b3bbbf6f96a214412b [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>
Neels Hofmeyr396f2e62017-09-04 15:13:25 +02009#include <osmocom/sgsn/gprs_sgsn.h>
Harald Welte0b588be2018-07-30 18:25:31 +020010#include <osmocom/gsm/oap_client.h>
Harald Weltef4b2c4c2018-09-16 07:53:41 +020011#include <osmocom/gsupclient/gsup_client.h>
Neels Hofmeyr396f2e62017-09-04 15:13:25 +020012#include <osmocom/sgsn/common.h>
Harald Welte288be162010-05-01 16:48:27 +020013
Neels Hofmeyr69e356b2018-03-15 13:00:35 +010014#include "../../bscconfig.h"
15
16#if BUILD_IU
17#include <osmocom/ranap/iu_client.h>
18#endif
19
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080020#include <ares.h>
Maxc005db72017-10-27 18:43:29 +020021#include <gtp.h>
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080022
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080023struct hostent;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010024
Jacob Erlbeck106f5472014-11-04 10:08:37 +010025enum sgsn_auth_policy {
26 SGSN_AUTH_POLICY_OPEN,
27 SGSN_AUTH_POLICY_CLOSED,
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010028 SGSN_AUTH_POLICY_ACL_ONLY,
29 SGSN_AUTH_POLICY_REMOTE
Jacob Erlbeck106f5472014-11-04 10:08:37 +010030};
31
Alexander Couzens14314bd2016-07-05 09:52:52 +020032
33enum sgsn_rate_ctr_keys {
Alexander Couzens4e699a92016-07-05 11:04:27 +020034 CTR_LLC_DL_BYTES,
35 CTR_LLC_UL_BYTES,
36 CTR_LLC_DL_PACKETS,
37 CTR_LLC_UL_PACKETS,
Alexander Couzens14314bd2016-07-05 09:52:52 +020038 CTR_GPRS_ATTACH_REQUEST,
39 CTR_GPRS_ATTACH_ACKED,
40 CTR_GPRS_ATTACH_REJECTED,
41 CTR_GPRS_DETACH_REQUEST,
42 CTR_GPRS_DETACH_ACKED,
43 CTR_GPRS_ROUTING_AREA_REQUEST,
44 CTR_GPRS_ROUTING_AREA_ACKED,
45 CTR_GPRS_ROUTING_AREA_REJECT,
46 /* PDP single packet counter / GSM 04.08 9.5.1 - 9.5.9 */
47 CTR_PDP_ACTIVATE_REQUEST,
48 CTR_PDP_ACTIVATE_REJECT,
49 CTR_PDP_ACTIVATE_ACCEPT,
50 CTR_PDP_REQUEST_ACTIVATE, /* unused */
51 CTR_PDP_REQUEST_ACTIVATE_REJ, /* unused */
52 CTR_PDP_MODIFY_REQUEST, /* unsued */
53 CTR_PDP_MODIFY_ACCEPT, /* unused */
54 CTR_PDP_DL_DEACTIVATE_REQUEST,
55 CTR_PDP_DL_DEACTIVATE_ACCEPT,
56 CTR_PDP_UL_DEACTIVATE_REQUEST,
57 CTR_PDP_UL_DEACTIVATE_ACCEPT,
58};
59
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020060struct sgsn_cdr {
61 char *filename;
Pau Espin Pedrol2e9ea502017-11-29 14:01:35 +010062 bool trap;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020063 int interval;
64};
65
Harald Welte288be162010-05-01 16:48:27 +020066struct sgsn_config {
67 /* parsed from config file */
Harald Welte288be162010-05-01 16:48:27 +020068
Harald Welte2720e732010-05-17 00:44:57 +020069 char *gtp_statedir;
70 struct sockaddr_in gtp_listenaddr;
71
Harald Welte288be162010-05-01 16:48:27 +020072 /* misc */
Alexander Couzensf23e2db2020-07-27 22:39:58 +020073 struct gprs_ns2_inst *nsi;
Harald Welte7f6da482013-03-19 11:00:13 +010074
Jacob Erlbeck106f5472014-11-04 10:08:37 +010075 enum sgsn_auth_policy auth_policy;
Max93408ae2016-06-28 14:10:16 +020076 enum gprs_ciph_algo cipher;
Harald Welte7f6da482013-03-19 11:00:13 +010077 struct llist_head imsi_acl;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010078
79 struct sockaddr_in gsup_server_addr;
80 int gsup_server_port;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010081
Pau Espin Pedrold1463bc2019-06-13 19:03:25 +020082 /* Only meaningful if auth_policy is SGSN_AUTH_POLICY_REMOTE */
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010083 int require_authentication;
Pau Espin Pedrold1463bc2019-06-13 19:03:25 +020084
Jacob Erlbeck771573c2014-12-19 18:08:48 +010085 int require_update_location;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020086
87 /* CDR configuration */
88 struct sgsn_cdr cdr;
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080089
Pau Espin Pedrola299d652019-08-14 19:11:10 +020090 /* Timer defintions */
91 struct osmo_tdef *T_defs;
Harald Welte94508822015-08-15 19:08:21 +020092
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080093 int dynamic_lookup;
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +020094
Harald Welte0b588be2018-07-30 18:25:31 +020095 struct osmo_oap_client_config oap;
Philippf1f34362016-08-26 17:00:21 +020096
97 /* RFC1144 TCP/IP header compression */
98 struct {
99 int active;
100 int passive;
101 int s01;
102 } pcomp_rfc1144;
Philipp73f83d52016-09-02 13:38:01 +0200103
104 /* V.42vis data compression */
105 struct {
106 int active;
107 int passive;
108 int p0;
109 int p1;
110 int p2;
111 } dcomp_v42bis;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200112
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100113#if BUILD_IU
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200114 struct {
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100115 enum ranap_nsap_addr_enc rab_assign_addr_enc;
Pau Espin Pedrol2c908992019-08-19 19:06:06 +0200116 uint32_t cs7_instance;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200117 } iu;
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100118#endif
Stefan Sperling88220092018-12-11 14:42:00 +0100119
120 /* This is transmitted as IPA Serial Number tag, which is used for GSUP routing (e.g. in OsmoHLR).
121 * This name must be set in a multi-SGSN network, and it must be unique to each SGSN.
122 * If no name is set, the IPA Serial Number will be the same as the Unit Name,
123 * and will be of the form 'SGSN-00-00-00-00-00-00' */
124 char *sgsn_ipa_name;
Harald Welte288be162010-05-01 16:48:27 +0200125};
126
Harald Welte2720e732010-05-17 00:44:57 +0200127struct sgsn_instance {
128 char *config_file;
129 struct sgsn_config cfg;
130 /* File descriptor wrappers for LibGTP */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200131 struct osmo_fd gtp_fd0;
132 struct osmo_fd gtp_fd1c;
133 struct osmo_fd gtp_fd1u;
Harald Welte2720e732010-05-17 00:44:57 +0200134 /* GSN instance for libgtp */
135 struct gsn_t *gsn;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100136 /* Subscriber */
Harald Weltef4b2c4c2018-09-16 07:53:41 +0200137 struct osmo_gsup_client *gsup_client;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100138 /* LLME inactivity timer */
139 struct osmo_timer_list llme_timer;
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800140
141 /* c-ares event loop integration */
142 struct osmo_timer_list ares_timer;
143 struct llist_head ares_fds;
144 ares_channel ares_channel;
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800145 struct ares_addr_node *ares_servers;
Alexander Couzens14314bd2016-07-05 09:52:52 +0200146
147 struct rate_ctr_group *rate_ctrs;
Harald Welte2720e732010-05-17 00:44:57 +0200148};
149
Harald Welte8fc1a462010-05-17 00:53:10 +0200150extern struct sgsn_instance *sgsn;
Harald Welte288be162010-05-01 16:48:27 +0200151
152/* sgsn_vty.c */
153
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +0200154int sgsn_vty_init(struct sgsn_config *cfg);
155int sgsn_parse_config(const char *config_file);
Maxc005db72017-10-27 18:43:29 +0200156char *sgsn_gtp_ntoa(struct ul16_t *ul);
Harald Welte288be162010-05-01 16:48:27 +0200157
158/* sgsn.c */
159
160/* Main input function for Gb proxy */
Alexander Couzensf23e2db2020-07-27 22:39:58 +0200161int sgsn_rcvmsg(struct msgb *msg, struct gprs_ns2_vc *nsvc, uint16_t ns_bvci);
Harald Welte288be162010-05-01 16:48:27 +0200162
Pau Espin Pedrol6dfb5fe2019-08-29 17:21:00 +0200163/* sgsn_libgtp.c */
Harald Welte77289c22010-05-18 14:32:29 +0200164struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
Harald Welte6abf94e2010-05-18 10:35:06 +0200165 struct sgsn_mm_ctx *mmctx,
166 uint16_t nsapi,
167 struct tlv_parsed *tp);
Harald Welte77289c22010-05-18 14:32:29 +0200168int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
Daniel Willmann21b269f2016-05-11 12:43:47 +0200169void sgsn_pdp_upd_gtp_u(struct sgsn_pdp_ctx *pdp, void *addr, size_t alen);
Pau Espin Pedrolfa120102018-07-09 20:37:47 +0200170void sgsn_ggsn_echo_req(struct sgsn_ggsn_ctx *ggc);
Pau Espin Pedrol6dfb5fe2019-08-29 17:21:00 +0200171int send_act_pdp_cont_acc(struct sgsn_pdp_ctx *pctx);
Harald Welte77289c22010-05-18 14:32:29 +0200172
Harald Welteebabdea2010-06-01 18:28:10 +0200173/* gprs_sndcp.c */
174
175/* Entry point for the SNSM-ACTIVATE.indication */
176int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Weltece22f922010-06-03 21:21:21 +0200177/* Entry point for the SNSM-DEACTIVATE.indication */
178int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Welteebabdea2010-06-01 18:28:10 +0200179/* Called by SNDCP when it has received/re-assembled a N-PDU */
Harald Welte8911cef2010-07-01 19:56:19 +0200180int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
181 struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
Harald Weltebb1c8052010-06-03 06:38:38 +0200182int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi,
183 void *mmcontext);
Holger Hans Peter Freyther3dccda52011-10-14 23:42:13 +0200184int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
185 uint8_t *hdr, uint16_t len);
Harald Welteebabdea2010-06-01 18:28:10 +0200186
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200187
188/*
189 * CDR related functionality
190 */
191int sgsn_cdr_init(struct sgsn_instance *sgsn);
192
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800193
194/*
195 * C-ARES related functionality
196 */
197int sgsn_ares_init(struct sgsn_instance *sgsn);
198int sgsn_ares_query(struct sgsn_instance *sgsm, const char *name, ares_host_callback cb, void *data);
199
Harald Welte288be162010-05-01 16:48:27 +0200200#endif