blob: f5ff524da24b2110d1a7f683581bc6ee40c041d6 [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
Pau Espin Pedrola299d652019-08-14 19:11:10 +020089 /* Timer defintions */
90 struct osmo_tdef *T_defs;
Harald Welte94508822015-08-15 19:08:21 +020091
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080092 int dynamic_lookup;
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +020093
Harald Welte0b588be2018-07-30 18:25:31 +020094 struct osmo_oap_client_config oap;
Philippf1f34362016-08-26 17:00:21 +020095
96 /* RFC1144 TCP/IP header compression */
97 struct {
98 int active;
99 int passive;
100 int s01;
101 } pcomp_rfc1144;
Philipp73f83d52016-09-02 13:38:01 +0200102
103 /* V.42vis data compression */
104 struct {
105 int active;
106 int passive;
107 int p0;
108 int p1;
109 int p2;
110 } dcomp_v42bis;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200111
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100112#if BUILD_IU
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200113 struct {
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100114 enum ranap_nsap_addr_enc rab_assign_addr_enc;
Pau Espin Pedrol2c908992019-08-19 19:06:06 +0200115 uint32_t cs7_instance;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200116 } iu;
Neels Hofmeyr69e356b2018-03-15 13:00:35 +0100117#endif
Stefan Sperling88220092018-12-11 14:42:00 +0100118
119 /* This is transmitted as IPA Serial Number tag, which is used for GSUP routing (e.g. in OsmoHLR).
120 * This name must be set in a multi-SGSN network, and it must be unique to each SGSN.
121 * If no name is set, the IPA Serial Number will be the same as the Unit Name,
122 * and will be of the form 'SGSN-00-00-00-00-00-00' */
123 char *sgsn_ipa_name;
Harald Welte288be162010-05-01 16:48:27 +0200124};
125
Harald Welte2720e732010-05-17 00:44:57 +0200126struct sgsn_instance {
127 char *config_file;
128 struct sgsn_config cfg;
129 /* File descriptor wrappers for LibGTP */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200130 struct osmo_fd gtp_fd0;
131 struct osmo_fd gtp_fd1c;
132 struct osmo_fd gtp_fd1u;
Harald Welte2720e732010-05-17 00:44:57 +0200133 /* GSN instance for libgtp */
134 struct gsn_t *gsn;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100135 /* Subscriber */
Harald Weltef4b2c4c2018-09-16 07:53:41 +0200136 struct osmo_gsup_client *gsup_client;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100137 /* LLME inactivity timer */
138 struct osmo_timer_list llme_timer;
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800139
140 /* c-ares event loop integration */
141 struct osmo_timer_list ares_timer;
142 struct llist_head ares_fds;
143 ares_channel ares_channel;
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800144 struct ares_addr_node *ares_servers;
Alexander Couzens14314bd2016-07-05 09:52:52 +0200145
146 struct rate_ctr_group *rate_ctrs;
Harald Welte2720e732010-05-17 00:44:57 +0200147};
148
Harald Welte8fc1a462010-05-17 00:53:10 +0200149extern struct sgsn_instance *sgsn;
Harald Welte288be162010-05-01 16:48:27 +0200150
151/* sgsn_vty.c */
152
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +0200153int sgsn_vty_init(struct sgsn_config *cfg);
154int sgsn_parse_config(const char *config_file);
Maxc005db72017-10-27 18:43:29 +0200155char *sgsn_gtp_ntoa(struct ul16_t *ul);
Harald Welte288be162010-05-01 16:48:27 +0200156
157/* sgsn.c */
158
159/* Main input function for Gb proxy */
160int sgsn_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci);
161
Pau Espin Pedrol6dfb5fe2019-08-29 17:21:00 +0200162/* sgsn_libgtp.c */
Harald Welte77289c22010-05-18 14:32:29 +0200163struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
Harald Welte6abf94e2010-05-18 10:35:06 +0200164 struct sgsn_mm_ctx *mmctx,
165 uint16_t nsapi,
166 struct tlv_parsed *tp);
Harald Welte77289c22010-05-18 14:32:29 +0200167int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
Daniel Willmann21b269f2016-05-11 12:43:47 +0200168void sgsn_pdp_upd_gtp_u(struct sgsn_pdp_ctx *pdp, void *addr, size_t alen);
Pau Espin Pedrolfa120102018-07-09 20:37:47 +0200169void sgsn_ggsn_echo_req(struct sgsn_ggsn_ctx *ggc);
Pau Espin Pedrol6dfb5fe2019-08-29 17:21:00 +0200170int send_act_pdp_cont_acc(struct sgsn_pdp_ctx *pctx);
Harald Welte77289c22010-05-18 14:32:29 +0200171
Harald Welteebabdea2010-06-01 18:28:10 +0200172/* gprs_sndcp.c */
173
174/* Entry point for the SNSM-ACTIVATE.indication */
175int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Weltece22f922010-06-03 21:21:21 +0200176/* Entry point for the SNSM-DEACTIVATE.indication */
177int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Welteebabdea2010-06-01 18:28:10 +0200178/* Called by SNDCP when it has received/re-assembled a N-PDU */
Harald Welte8911cef2010-07-01 19:56:19 +0200179int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
180 struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
Harald Weltebb1c8052010-06-03 06:38:38 +0200181int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi,
182 void *mmcontext);
Holger Hans Peter Freyther3dccda52011-10-14 23:42:13 +0200183int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
184 uint8_t *hdr, uint16_t len);
Harald Welteebabdea2010-06-01 18:28:10 +0200185
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200186
187/*
188 * CDR related functionality
189 */
190int sgsn_cdr_init(struct sgsn_instance *sgsn);
191
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800192
193/*
194 * C-ARES related functionality
195 */
196int sgsn_ares_init(struct sgsn_instance *sgsn);
197int sgsn_ares_query(struct sgsn_instance *sgsm, const char *name, ares_host_callback cb, void *data);
198
Harald Welte288be162010-05-01 16:48:27 +0200199#endif