blob: 2b1b97caad378d5e65fe6db25dff9c8a4b6be3a6 [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>
Harald Welte288be162010-05-01 16:48:27 +02006
Harald Welteea34a4e2012-06-16 14:59:56 +08007#include <osmocom/gprs/gprs_ns.h>
Harald Welte6abf94e2010-05-18 10:35:06 +02008#include <openbsc/gprs_sgsn.h>
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +02009#include <openbsc/oap.h>
Harald Welte288be162010-05-01 16:48:27 +020010
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080011#include <ares.h>
12
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010013struct gprs_gsup_client;
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080014struct hostent;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010015
Jacob Erlbeck106f5472014-11-04 10:08:37 +010016enum sgsn_auth_policy {
17 SGSN_AUTH_POLICY_OPEN,
18 SGSN_AUTH_POLICY_CLOSED,
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010019 SGSN_AUTH_POLICY_ACL_ONLY,
20 SGSN_AUTH_POLICY_REMOTE
Jacob Erlbeck106f5472014-11-04 10:08:37 +010021};
22
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020023struct sgsn_cdr {
24 char *filename;
25 int interval;
26};
27
Harald Welte288be162010-05-01 16:48:27 +020028struct sgsn_config {
29 /* parsed from config file */
Harald Welte288be162010-05-01 16:48:27 +020030
Harald Welte2720e732010-05-17 00:44:57 +020031 char *gtp_statedir;
32 struct sockaddr_in gtp_listenaddr;
33
Harald Welte288be162010-05-01 16:48:27 +020034 /* misc */
35 struct gprs_ns_inst *nsi;
Harald Welte7f6da482013-03-19 11:00:13 +010036
Jacob Erlbeck106f5472014-11-04 10:08:37 +010037 enum sgsn_auth_policy auth_policy;
Harald Welte7f6da482013-03-19 11:00:13 +010038 struct llist_head imsi_acl;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010039
40 struct sockaddr_in gsup_server_addr;
41 int gsup_server_port;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +010042
43 int require_authentication;
Jacob Erlbeck771573c2014-12-19 18:08:48 +010044 int require_update_location;
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +020045
46 /* CDR configuration */
47 struct sgsn_cdr cdr;
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080048
Harald Welte94508822015-08-15 19:08:21 +020049 struct {
50 int T3312;
51 int T3322;
52 int T3350;
53 int T3360;
54 int T3370;
55 int T3313;
56 int T3314;
57 int T3316;
58 int T3385;
59 int T3386;
60 int T3395;
61 int T3397;
62 } timers;
63
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +080064 int dynamic_lookup;
Neels Hofmeyr9c534fd2015-10-12 11:57:37 +020065
66 struct oap_config oap;
Harald Welte288be162010-05-01 16:48:27 +020067};
68
Harald Welte2720e732010-05-17 00:44:57 +020069struct sgsn_instance {
70 char *config_file;
71 struct sgsn_config cfg;
72 /* File descriptor wrappers for LibGTP */
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +020073 struct osmo_fd gtp_fd0;
74 struct osmo_fd gtp_fd1c;
75 struct osmo_fd gtp_fd1u;
Harald Welte2720e732010-05-17 00:44:57 +020076 /* Timer for libGTP */
Pablo Neira Ayusobf540cb2011-05-06 12:11:06 +020077 struct osmo_timer_list gtp_timer;
Harald Welte2720e732010-05-17 00:44:57 +020078 /* GSN instance for libgtp */
79 struct gsn_t *gsn;
Jacob Erlbeck39f040d2014-12-18 12:46:47 +010080 /* Subscriber */
81 struct gprs_gsup_client *gsup_client;
Jacob Erlbeck81ffb742015-01-23 11:33:51 +010082 /* LLME inactivity timer */
83 struct osmo_timer_list llme_timer;
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +080084
85 /* c-ares event loop integration */
86 struct osmo_timer_list ares_timer;
87 struct llist_head ares_fds;
88 ares_channel ares_channel;
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +080089 struct ares_addr_node *ares_servers;
Harald Welte2720e732010-05-17 00:44:57 +020090};
91
Harald Welte8fc1a462010-05-17 00:53:10 +020092extern struct sgsn_instance *sgsn;
Harald Welte288be162010-05-01 16:48:27 +020093
94/* sgsn_vty.c */
95
96int sgsn_vty_init(void);
97int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg);
98
99/* sgsn.c */
100
101/* Main input function for Gb proxy */
102int sgsn_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci);
103
Harald Welte6abf94e2010-05-18 10:35:06 +0200104
Harald Welte77289c22010-05-18 14:32:29 +0200105struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn,
Harald Welte6abf94e2010-05-18 10:35:06 +0200106 struct sgsn_mm_ctx *mmctx,
107 uint16_t nsapi,
108 struct tlv_parsed *tp);
Harald Welte77289c22010-05-18 14:32:29 +0200109int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx);
110
Harald Welteebabdea2010-06-01 18:28:10 +0200111/* gprs_sndcp.c */
112
113/* Entry point for the SNSM-ACTIVATE.indication */
114int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Weltece22f922010-06-03 21:21:21 +0200115/* Entry point for the SNSM-DEACTIVATE.indication */
116int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi);
Harald Welteebabdea2010-06-01 18:28:10 +0200117/* Called by SNDCP when it has received/re-assembled a N-PDU */
Harald Welte8911cef2010-07-01 19:56:19 +0200118int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
119 struct msgb *msg, uint32_t npdu_len, uint8_t *npdu);
Harald Weltebb1c8052010-06-03 06:38:38 +0200120int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi,
121 void *mmcontext);
Holger Hans Peter Freyther3dccda52011-10-14 23:42:13 +0200122int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle,
123 uint8_t *hdr, uint16_t len);
Harald Welteebabdea2010-06-01 18:28:10 +0200124
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200125
126/*
127 * CDR related functionality
128 */
129int sgsn_cdr_init(struct sgsn_instance *sgsn);
130
Holger Hans Peter Freyther66e71062015-05-25 01:21:50 +0800131
132/*
133 * C-ARES related functionality
134 */
135int sgsn_ares_init(struct sgsn_instance *sgsn);
136int sgsn_ares_query(struct sgsn_instance *sgsm, const char *name, ares_host_callback cb, void *data);
137
Harald Welte288be162010-05-01 16:48:27 +0200138#endif