blob: 7e0b5d477b0d60ad3b5d28d2884819c7f65fbb49 [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>
9#include <osmocom/sgsn/oap_client.h>
10#include <osmocom/sgsn/common.h>
Harald Welte288be162010-05-01 16:48:27 +020011
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080012#include <ares.h>
Maxc005db72017-10-27 18:43:29 +020013#include <gtp.h>
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080014
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010015struct gprs_gsup_client;
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080016struct hostent;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010017
Jacob Erlbeck106f5472014-11-04 10:08:37 +010018enum sgsn_auth_policy {
19 SGSN_AUTH_POLICY_OPEN,
20 SGSN_AUTH_POLICY_CLOSED,
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010021 SGSN_AUTH_POLICY_ACL_ONLY,
22 SGSN_AUTH_POLICY_REMOTE
Jacob Erlbeck106f5472014-11-04 10:08:37 +010023};
24
Alexander Couzens14314bd2016-07-05 09:52:52 +020025
26enum sgsn_rate_ctr_keys {
Alexander Couzens4e699a92016-07-05 11:04:27 +020027 CTR_LLC_DL_BYTES,
28 CTR_LLC_UL_BYTES,
29 CTR_LLC_DL_PACKETS,
30 CTR_LLC_UL_PACKETS,
Alexander Couzens14314bd2016-07-05 09:52:52 +020031 CTR_GPRS_ATTACH_REQUEST,
32 CTR_GPRS_ATTACH_ACKED,
33 CTR_GPRS_ATTACH_REJECTED,
34 CTR_GPRS_DETACH_REQUEST,
35 CTR_GPRS_DETACH_ACKED,
36 CTR_GPRS_ROUTING_AREA_REQUEST,
37 CTR_GPRS_ROUTING_AREA_ACKED,
38 CTR_GPRS_ROUTING_AREA_REJECT,
39 /* PDP single packet counter / GSM 04.08 9.5.1 - 9.5.9 */
40 CTR_PDP_ACTIVATE_REQUEST,
41 CTR_PDP_ACTIVATE_REJECT,
42 CTR_PDP_ACTIVATE_ACCEPT,
43 CTR_PDP_REQUEST_ACTIVATE, /* unused */
44 CTR_PDP_REQUEST_ACTIVATE_REJ, /* unused */
45 CTR_PDP_MODIFY_REQUEST, /* unsued */
46 CTR_PDP_MODIFY_ACCEPT, /* unused */
47 CTR_PDP_DL_DEACTIVATE_REQUEST,
48 CTR_PDP_DL_DEACTIVATE_ACCEPT,
49 CTR_PDP_UL_DEACTIVATE_REQUEST,
50 CTR_PDP_UL_DEACTIVATE_ACCEPT,
51};
52
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020053struct sgsn_cdr {
54 char *filename;
Pau Espin Pedrol2e9ea502017-11-29 14:01:35 +010055 bool trap;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020056 int interval;
57};
58
Harald Welte288be162010-05-01 16:48:27 +020059struct sgsn_config {
60 /* parsed from config file */
Harald Welte288be162010-05-01 16:48:27 +020061
Harald Welte2720e732010-05-17 00:44:57 +020062 char *gtp_statedir;
63 struct sockaddr_in gtp_listenaddr;
64
Harald Welte288be162010-05-01 16:48:27 +020065 /* misc */
66 struct gprs_ns_inst *nsi;
Harald Welte7f6da482013-03-19 11:00:13 +010067
Jacob Erlbeck106f5472014-11-04 10:08:37 +010068 enum sgsn_auth_policy auth_policy;
Max93408ae2016-06-28 14:10:16 +020069 enum gprs_ciph_algo cipher;
Harald Welte7f6da482013-03-19 11:00:13 +010070 struct llist_head imsi_acl;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010071
72 struct sockaddr_in gsup_server_addr;
73 int gsup_server_port;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010074
75 int require_authentication;
Jacob Erlbeck771573c2014-12-19 18:08:48 +010076 int require_update_location;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020077
78 /* CDR configuration */
79 struct sgsn_cdr cdr;
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080080
Harald Welte94508822015-08-15 19:08:21 +020081 struct {
82 int T3312;
83 int T3322;
84 int T3350;
85 int T3360;
86 int T3370;
87 int T3313;
88 int T3314;
89 int T3316;
90 int T3385;
91 int T3386;
92 int T3395;
93 int T3397;
94 } timers;
95
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080096 int dynamic_lookup;
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +020097
Neels Hofmeyr49012f12016-12-08 21:30:34 +010098 struct oap_client_config oap;
Philippf1f34362016-08-26 17:00:21 +020099
100 /* RFC1144 TCP/IP header compression */
101 struct {
102 int active;
103 int passive;
104 int s01;
105 } pcomp_rfc1144;
Philipp73f83d52016-09-02 13:38:01 +0200106
107 /* V.42vis data compression */
108 struct {
109 int active;
110 int passive;
111 int p0;
112 int p1;
113 int p2;
114 } dcomp_v42bis;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200115
116 struct {
Neels Hofmeyra7a39472017-07-05 15:19:52 +0200117 int rab_assign_addr_enc;
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200118 } iu;
Harald Welte288be162010-05-01 16:48:27 +0200119};
120
Harald Welte2720e732010-05-17 00:44:57 +0200121struct sgsn_instance {
122 char *config_file;
123 struct sgsn_config cfg;
124 /* File descriptor wrappers for LibGTP */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200125 struct osmo_fd gtp_fd0;
126 struct osmo_fd gtp_fd1c;
127 struct osmo_fd gtp_fd1u;
Harald Welte2720e732010-05-17 00:44:57 +0200128 /* Timer for libGTP */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +0200129 struct osmo_timer_list gtp_timer;
Harald Welte2720e732010-05-17 00:44:57 +0200130 /* GSN instance for libgtp */
131 struct gsn_t *gsn;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100132 /* Subscriber */
Neels Hofmeyr814fef02016-12-08 21:19:57 +0100133 struct gsup_client *gsup_client;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100134 /* LLME inactivity timer */
135 struct osmo_timer_list llme_timer;
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800136
137 /* c-ares event loop integration */
138 struct osmo_timer_list ares_timer;
139 struct llist_head ares_fds;
140 ares_channel ares_channel;
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800141 struct ares_addr_node *ares_servers;
Alexander Couzens14314bd2016-07-05 09:52:52 +0200142
143 struct rate_ctr_group *rate_ctrs;
Harald Welte2720e732010-05-17 00:44:57 +0200144};
145
Harald Welte8fc1a462010-05-17 00:53:10 +0200146extern struct sgsn_instance *sgsn;
Harald Welte288be162010-05-01 16:48:27 +0200147
148/* sgsn_vty.c */
149
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +0200150int sgsn_vty_init(struct sgsn_config *cfg);
151int sgsn_parse_config(const char *config_file);
Maxc005db72017-10-27 18:43:29 +0200152char *sgsn_gtp_ntoa(struct ul16_t *ul);
Harald Welte288be162010-05-01 16:48:27 +0200153
154/* sgsn.c */
155
156/* Main input function for Gb proxy */
157int sgsn_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci);
158
Harald Welte6abf94e2010-05-18 10:35:06 +0200159
Harald Welte77289c22010-05-18 14:32:29 +0200160struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
Harald Welte6abf94e2010-05-18 10:35:06 +0200161 struct sgsn_mm_ctx *mmctx,
162 uint16_t nsapi,
163 struct tlv_parsed *tp);
Harald Welte77289c22010-05-18 14:32:29 +0200164int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
Daniel Willmann21b269f2016-05-11 12:43:47 +0200165void sgsn_pdp_upd_gtp_u(struct sgsn_pdp_ctx *pdp, void *addr, size_t alen);
Harald Welte77289c22010-05-18 14:32:29 +0200166
Harald Welteebabdea2010-06-01 18:28:10 +0200167/* gprs_sndcp.c */
168
169/* Entry point for the SNSM-ACTIVATE.indication */
170int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Weltece22f922010-06-03 21:21:21 +0200171/* Entry point for the SNSM-DEACTIVATE.indication */
172int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Welteebabdea2010-06-01 18:28:10 +0200173/* Called by SNDCP when it has received/re-assembled a N-PDU */
Harald Welte8911cef2010-07-01 19:56:19 +0200174int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
175 struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
Harald Weltebb1c8052010-06-03 06:38:38 +0200176int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi,
177 void *mmcontext);
Holger Hans Peter Freyther3dccda52011-10-14 23:42:13 +0200178int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
179 uint8_t *hdr, uint16_t len);
Harald Welteebabdea2010-06-01 18:28:10 +0200180
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200181
182/*
183 * CDR related functionality
184 */
185int sgsn_cdr_init(struct sgsn_instance *sgsn);
186
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800187
188/*
189 * C-ARES related functionality
190 */
191int sgsn_ares_init(struct sgsn_instance *sgsn);
192int sgsn_ares_query(struct sgsn_instance *sgsm, const char *name, ares_host_callback cb, void *data);
193
Harald Welte288be162010-05-01 16:48:27 +0200194#endif