blob: 0a6ea29ea57de014c8337e4be41034781d4e2d07 [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>
Max93408ae2016-06-28 14:10:16 +02006#include <osmocom/crypt/gprs_cipher.h>
Harald Welteea34a4e2012-06-16 14:59:56 +08007#include <osmocom/gprs/gprs_ns.h>
Neels Hofmeyr396f2e62017-09-04 15:13:25 +02008#include <osmocom/sgsn/gprs_sgsn.h>
Harald Welte0b588be2018-07-30 18:25:31 +02009#include <osmocom/gsm/oap_client.h>
Harald Weltef4b2c4c2018-09-16 07:53:41 +020010#include <osmocom/gsupclient/gsup_client.h>
Neels Hofmeyr396f2e62017-09-04 15:13:25 +020011#include <osmocom/sgsn/common.h>
Harald Welte288be162010-05-01 16:48:27 +020012
Neels Hofmeyr69e356b2018-03-15 13:00:35 +010013#include "../../bscconfig.h"
14
15#if BUILD_IU
16#include <osmocom/ranap/iu_client.h>
17#endif
18
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080019#include <ares.h>
Maxc005db72017-10-27 18:43:29 +020020#include <gtp.h>
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080021
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080022struct hostent;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010023
Jacob Erlbeck106f5472014-11-04 10:08:37 +010024enum sgsn_auth_policy {
25 SGSN_AUTH_POLICY_OPEN,
26 SGSN_AUTH_POLICY_CLOSED,
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010027 SGSN_AUTH_POLICY_ACL_ONLY,
28 SGSN_AUTH_POLICY_REMOTE
Jacob Erlbeck106f5472014-11-04 10:08:37 +010029};
30
Alexander Couzens14314bd2016-07-05 09:52:52 +020031
32enum sgsn_rate_ctr_keys {
Alexander Couzens4e699a92016-07-05 11:04:27 +020033 CTR_LLC_DL_BYTES,
34 CTR_LLC_UL_BYTES,
35 CTR_LLC_DL_PACKETS,
36 CTR_LLC_UL_PACKETS,
Alexander Couzens14314bd2016-07-05 09:52:52 +020037 CTR_GPRS_ATTACH_REQUEST,
38 CTR_GPRS_ATTACH_ACKED,
39 CTR_GPRS_ATTACH_REJECTED,
40 CTR_GPRS_DETACH_REQUEST,
41 CTR_GPRS_DETACH_ACKED,
42 CTR_GPRS_ROUTING_AREA_REQUEST,
43 CTR_GPRS_ROUTING_AREA_ACKED,
44 CTR_GPRS_ROUTING_AREA_REJECT,
45 /* PDP single packet counter / GSM 04.08 9.5.1 - 9.5.9 */
46 CTR_PDP_ACTIVATE_REQUEST,
47 CTR_PDP_ACTIVATE_REJECT,
48 CTR_PDP_ACTIVATE_ACCEPT,
49 CTR_PDP_REQUEST_ACTIVATE, /* unused */
50 CTR_PDP_REQUEST_ACTIVATE_REJ, /* unused */
51 CTR_PDP_MODIFY_REQUEST, /* unsued */
52 CTR_PDP_MODIFY_ACCEPT, /* unused */
53 CTR_PDP_DL_DEACTIVATE_REQUEST,
54 CTR_PDP_DL_DEACTIVATE_ACCEPT,
55 CTR_PDP_UL_DEACTIVATE_REQUEST,
56 CTR_PDP_UL_DEACTIVATE_ACCEPT,
57};
58
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020059struct sgsn_cdr {
60 char *filename;
Pau Espin Pedrol2e9ea502017-11-29 14:01:35 +010061 bool trap;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020062 int interval;
63};
64
Harald Welte288be162010-05-01 16:48:27 +020065struct sgsn_config {
66 /* parsed from config file */
Harald Welte288be162010-05-01 16:48:27 +020067
Harald Welte2720e732010-05-17 00:44:57 +020068 char *gtp_statedir;
69 struct sockaddr_in gtp_listenaddr;
70
Harald Welte288be162010-05-01 16:48:27 +020071 /* misc */
72 struct gprs_ns_inst *nsi;
Harald Welte7f6da482013-03-19 11:00:13 +010073
Jacob Erlbeck106f5472014-11-04 10:08:37 +010074 enum sgsn_auth_policy auth_policy;
Max93408ae2016-06-28 14:10:16 +020075 enum gprs_ciph_algo cipher;
Harald Welte7f6da482013-03-19 11:00:13 +010076 struct llist_head imsi_acl;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010077
78 struct sockaddr_in gsup_server_addr;
79 int gsup_server_port;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010080
Pau Espin Pedrold1463bc2019-06-13 19:03:25 +020081 /* Only meaningful if auth_policy is SGSN_AUTH_POLICY_REMOTE */
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010082 int require_authentication;
Pau Espin Pedrold1463bc2019-06-13 19:03:25 +020083
Jacob Erlbeck771573c2014-12-19 18:08:48 +010084 int require_update_location;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020085
86 /* CDR configuration */
87 struct sgsn_cdr cdr;
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080088
Harald Welte94508822015-08-15 19:08:21 +020089 struct {
90 int T3312;
91 int T3322;
92 int T3350;
93 int T3360;
94 int T3370;
95 int T3313;
96 int T3314;
97 int T3316;
98 int T3385;
99 int T3386;
100 int T3395;
101 int T3397;
102 } timers;
103
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800104 int dynamic_lookup;
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +0200105
Harald Welte0b588be2018-07-30 18:25:31 +0200106 struct osmo_oap_client_config oap;
Philippf1f34362016-08-26 17:00:21 +0200107
108 /* RFC1144 TCP/IP header compression */
109 struct {
110 int active;
111 int passive;
112 int s01;
113 } pcomp_rfc1144;
Philipp73f83d52016-09-02 13:38:01 +0200114
115 /* V.42vis data compression */
116 struct {
117 int active;
118 int passive;
119 int p0;
120 int p1;
121 int p2;
122 } dcomp_v42bis;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200123
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100124#if BUILD_IU
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200125 struct {
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100126 enum ranap_nsap_addr_enc rab_assign_addr_enc;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200127 } iu;
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100128#endif
Stefan Sperling88220092018-12-11 14:42:00 +0100129
130 /* This is transmitted as IPA Serial Number tag, which is used for GSUP routing (e.g. in OsmoHLR).
131 * This name must be set in a multi-SGSN network, and it must be unique to each SGSN.
132 * If no name is set, the IPA Serial Number will be the same as the Unit Name,
133 * and will be of the form 'SGSN-00-00-00-00-00-00' */
134 char *sgsn_ipa_name;
Harald Welte288be162010-05-01 16:48:27 +0200135};
136
Harald Welte2720e732010-05-17 00:44:57 +0200137struct sgsn_instance {
138 char *config_file;
139 struct sgsn_config cfg;
140 /* File descriptor wrappers for LibGTP */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200141 struct osmo_fd gtp_fd0;
142 struct osmo_fd gtp_fd1c;
143 struct osmo_fd gtp_fd1u;
Harald Welte2720e732010-05-17 00:44:57 +0200144 /* Timer for libGTP */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200145 struct osmo_timer_list gtp_timer;
Harald Welte2720e732010-05-17 00:44:57 +0200146 /* GSN instance for libgtp */
147 struct gsn_t *gsn;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100148 /* Subscriber */
Harald Weltef4b2c4c2018-09-16 07:53:41 +0200149 struct osmo_gsup_client *gsup_client;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100150 /* LLME inactivity timer */
151 struct osmo_timer_list llme_timer;
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800152
153 /* c-ares event loop integration */
154 struct osmo_timer_list ares_timer;
155 struct llist_head ares_fds;
156 ares_channel ares_channel;
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800157 struct ares_addr_node *ares_servers;
Alexander Couzens14314bd2016-07-05 09:52:52 +0200158
159 struct rate_ctr_group *rate_ctrs;
Harald Welte2720e732010-05-17 00:44:57 +0200160};
161
Harald Welte8fc1a462010-05-17 00:53:10 +0200162extern struct sgsn_instance *sgsn;
Harald Welte288be162010-05-01 16:48:27 +0200163
164/* sgsn_vty.c */
165
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +0200166int sgsn_vty_init(struct sgsn_config *cfg);
167int sgsn_parse_config(const char *config_file);
Maxc005db72017-10-27 18:43:29 +0200168char *sgsn_gtp_ntoa(struct ul16_t *ul);
Harald Welte288be162010-05-01 16:48:27 +0200169
170/* sgsn.c */
171
172/* Main input function for Gb proxy */
173int sgsn_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci);
174
Harald Welte6abf94e2010-05-18 10:35:06 +0200175
Harald Welte77289c22010-05-18 14:32:29 +0200176struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
Harald Welte6abf94e2010-05-18 10:35:06 +0200177 struct sgsn_mm_ctx *mmctx,
178 uint16_t nsapi,
179 struct tlv_parsed *tp);
Harald Welte77289c22010-05-18 14:32:29 +0200180int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
Daniel Willmann21b269f2016-05-11 12:43:47 +0200181void sgsn_pdp_upd_gtp_u(struct sgsn_pdp_ctx *pdp, void *addr, size_t alen);
Pau Espin Pedrolfa120102018-07-09 20:37:47 +0200182void sgsn_ggsn_echo_req(struct sgsn_ggsn_ctx *ggc);
Harald Welte77289c22010-05-18 14:32:29 +0200183
Harald Welteebabdea2010-06-01 18:28:10 +0200184/* gprs_sndcp.c */
185
186/* Entry point for the SNSM-ACTIVATE.indication */
187int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Weltece22f922010-06-03 21:21:21 +0200188/* Entry point for the SNSM-DEACTIVATE.indication */
189int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Welteebabdea2010-06-01 18:28:10 +0200190/* Called by SNDCP when it has received/re-assembled a N-PDU */
Harald Welte8911cef2010-07-01 19:56:19 +0200191int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
192 struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
Harald Weltebb1c8052010-06-03 06:38:38 +0200193int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi,
194 void *mmcontext);
Holger Hans Peter Freyther3dccda52011-10-14 23:42:13 +0200195int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
196 uint8_t *hdr, uint16_t len);
Harald Welteebabdea2010-06-01 18:28:10 +0200197
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200198
199/*
200 * CDR related functionality
201 */
202int sgsn_cdr_init(struct sgsn_instance *sgsn);
203
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800204
205/*
206 * C-ARES related functionality
207 */
208int sgsn_ares_init(struct sgsn_instance *sgsn);
209int sgsn_ares_query(struct sgsn_instance *sgsm, const char *name, ares_host_callback cb, void *data);
210
Harald Welte288be162010-05-01 16:48:27 +0200211#endif