blob: 8e47ce35cc6434c4cb81c9b6b8b89768b88e1d1f [file] [log] [blame]
Pau Espin Pedrol724ecc62022-11-02 14:57:24 +01001/*
2 * OsmoGGSN - Gateway GPRS Support Node
3 * Copyright (C) 2002, 2003, 2004 Mondru AB.
4 *
5 * The contents of this file may be used under the terms of the GNU
6 * General Public License Version 2, provided that the above copyright
7 * notice and this permission notice is included in all copies or
8 * substantial portions of the software.
9 *
10 */
11
12#ifndef _GSN_H
13#define _GSN_H
14
15#include <osmocom/core/utils.h>
16#include <osmocom/core/defs.h>
17#include <osmocom/core/timer.h>
Pau Espin Pedrol9f1f7472022-11-02 19:52:19 +010018#include <osmocom/core/tdef.h>
Pau Espin Pedrolb9036af2022-11-02 18:17:56 +010019#include <osmocom/core/rate_ctr.h>
Pau Espin Pedrol724ecc62022-11-02 14:57:24 +010020
21#include "pdp.h"
22
23#define GTP_MODE_GGSN 1
24#define GTP_MODE_SGSN 2
25
26#define RESTART_FILE "gsn_restart"
27
Pau Espin Pedrol9f1f7472022-11-02 19:52:19 +010028extern struct osmo_tdef gtp_T_defs[];
29
Pau Espin Pedrol724ecc62022-11-02 14:57:24 +010030/* ***********************************************************
31 * Information storage for each gsn instance
32 *
33 * Normally each instance of the application corresponds to
34 * one instance of a gsn.
35 *
36 * In order to avoid global variables in the application, and
37 * also in order to allow several instances of a gsn in the same
38 * application this struct is provided in order to store all
39 * relevant information related to the gsn.
40 *
41 * Note that this does not include information storage for '
42 * each pdp context. This is stored in another struct.
43 *************************************************************/
44
Pau Espin Pedrolb9036af2022-11-02 18:17:56 +010045enum gsn_rate_ctr_keys {
46 GSN_CTR_ERR_SOCKET,
47 GSN_CTR_ERR_READFROM, /* Number of readfrom errors */
48 GSN_CTR_ERR_SENDTO, /* Number of sendto errors */
49 GSN_CTR_ERR_QUEUEFULL, /* Number of times queue was full */
50 GSN_CTR_ERR_SEQ, /* Number of seq out of range */
51 GSN_CTR_ERR_ADDRESS, /* GSN address conversion failed */
52 GSN_CTR_ERR_UNKNOWN_PDP, /* GSN address conversion failed */
53 GSN_CTR_ERR_UNEXPECTED_CAUSE, /* Unexpected cause value received */
54 GSN_CTR_ERR_OUT_OF_PDP, /* Out of storage for PDP contexts */
55 GSN_CTR_PKT_EMPTY, /* Number of empty packets */
56 GSN_CTR_PKT_UNSUP, /* Number of unsupported version 29.60 11.1.1 */
57 GSN_CTR_PKT_TOOSHORT, /* Number of too short headers 29.60 11.1.2 */
58 GSN_CTR_PKT_UNKNOWN, /* Number of unknown messages 29.60 11.1.3 */
59 GSN_CTR_PKT_UNEXPECT, /* Number of unexpected messages 29.60 11.1.4 */
60 GSN_CTR_PKT_DUPLICATE, /* Number of duplicate or unsolicited replies */
61 GSN_CTR_PKT_MISSING, /* Number of missing information field messages */
62 GSN_CTR_PKT_INCORRECT, /* Number of incorrect information field messages */
63 GSN_CTR_PKT_INVALID, /* Number of invalid message format messages */
64};
65
Pau Espin Pedrol9f1f7472022-11-02 19:52:19 +010066/* 3GPP TS 29.006 14.1, 14,2 */
67enum gtp_gsn_timers {
68 GTP_GSN_TIMER_T3_RESPONSE = 3,
69 GTP_GSN_TIMER_N3_REQUESTS = 1003,
Pau Espin Pedrol3a55b892022-11-04 11:21:23 +010070 GTP_GSN_TIMER_T3_HOLD_RESPONSE = -3,
Pau Espin Pedrol9f1f7472022-11-02 19:52:19 +010071};
72
Pau Espin Pedrol724ecc62022-11-02 14:57:24 +010073struct gsn_t {
74 /* Parameters related to the network interface */
75
76 int fd0; /* GTP0 file descriptor */
77 int fd1c; /* GTP1 control plane file descriptor */
78 int fd1u; /* GTP0 user plane file descriptor */
79 int mode; /* Mode of operation: GGSN or SGSN */
Oliver Smith9bd27112024-02-22 16:02:37 +010080 struct in_addr gsnc; /* IP address of this gsn for signalling */
81 struct in_addr gsnu; /* IP address of this gsn for user traffic */
Pau Espin Pedrol724ecc62022-11-02 14:57:24 +010082
83 /* Parameters related to signalling messages */
84 uint16_t seq_next; /* Next sequence number to use */
85 int seq_first; /* First packet in queue (oldest timeout) */
86 int seq_last; /* Last packet in queue (youngest timeout) */
87
88 unsigned char restart_counter; /* Increment on restart. Stored on disk */
89 char *statedir; /* Disk location for permanent storage */
90 void *priv; /* used by libgtp users to attach their own state) */
91 struct queue_t *queue_req; /* Request queue */
92 struct queue_t *queue_resp; /* Response queue */
93
94 struct pdp_t pdpa[PDP_MAX]; /* PDP storage */
95 struct pdp_t *hashtid[PDP_MAX]; /* Hash table for IMSI + NSAPI */
96
97 struct osmo_timer_list queue_timer; /* internal queue_{req,resp} timer */
98
99 /* Call back functions */
100 int (*cb_delete_context) (struct pdp_t *);
101 int (*cb_create_context_ind) (struct pdp_t *);
102 int (*cb_unsup_ind) (struct sockaddr_in * peer);
103 int (*cb_extheader_ind) (struct sockaddr_in * peer);
104 int (*cb_ran_info_relay_ind) (struct sockaddr_in *peer, union gtpie_member **ie);
105 int (*cb_conf) (int type, int cause, struct pdp_t * pdp, void *cbp);
106 int (*cb_data_ind) (struct pdp_t * pdp, void *pack, unsigned len);
107 int (*cb_recovery) (struct sockaddr_in * peer, uint8_t recovery);
108 int (*cb_recovery2) (struct sockaddr_in * peer, struct pdp_t * pdp, uint8_t recovery);
109 int (*cb_recovery3) (struct gsn_t *gsn, struct sockaddr_in *peer, struct pdp_t *pdp, uint8_t recovery);
110
111 /* Counters */
Pau Espin Pedrolb9036af2022-11-02 18:17:56 +0100112 struct rate_ctr_group *ctrg;
Pau Espin Pedrol9f1f7472022-11-02 19:52:19 +0100113
114 /* Timers: */
115 struct osmo_tdef *tdef;
Pau Espin Pedrol724ecc62022-11-02 14:57:24 +0100116};
117
118/* External API functions */
119
Oliver Smith9bd27112024-02-22 16:02:37 +0100120extern int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen,
121 int mode);
Pau Espin Pedrol724ecc62022-11-02 14:57:24 +0100122
123extern int gtp_free(struct gsn_t *gsn);
124
125extern int gtp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp,
126 uint64_t imsi, uint8_t nsapi) OSMO_DEPRECATED("Use gtp_pdp_newpdp() instead");
127extern int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp);
128extern int gtp_freepdp_teardown(struct gsn_t *gsn, struct pdp_t *pdp);
129
130extern int gtp_create_context_req(struct gsn_t *gsn, struct pdp_t *pdp,
131 void *cbp);
132
133extern int gtp_set_cb_create_context_ind(struct gsn_t *gsn,
134 int (*cb_create_context_ind) (struct
135 pdp_t *
136 pdp));
137extern int gtp_set_cb_data_ind(struct gsn_t *gsn,
138 int (*cb_data_ind) (struct pdp_t * pdp,
139 void *pack, unsigned len));
140extern int gtp_set_cb_delete_context(struct gsn_t *gsn,
141 int (*cb_delete_context) (struct pdp_t *
142 pdp));
143/*extern int gtp_set_cb_create_context(struct gsn_t *gsn,
144 int (*cb_create_context) (struct pdp_t* pdp)); */
145
146extern int gtp_set_cb_unsup_ind(struct gsn_t *gsn,
147 int (*cb) (struct sockaddr_in * peer));
148
149extern int gtp_set_cb_extheader_ind(struct gsn_t *gsn,
150 int (*cb) (struct sockaddr_in * peer));
151
152extern int gtp_set_cb_ran_info_relay_ind(struct gsn_t *gsn,
153 int (*cb) (struct sockaddr_in * peer, union gtpie_member **ie));
154
155extern int gtp_set_cb_conf(struct gsn_t *gsn,
156 int (*cb) (int type, int cause, struct pdp_t * pdp,
157 void *cbp));
158
159int gtp_set_cb_recovery(struct gsn_t *gsn,
160 int (*cb) (struct sockaddr_in * peer,
161 uint8_t recovery))
162 OSMO_DEPRECATED("Use gtp_set_cb_recovery2() instead, to obtain pdp ctx originating the recovery");
163int gtp_set_cb_recovery2(struct gsn_t *gsn,
164 int (*cb) (struct sockaddr_in * peer,
165 struct pdp_t * pdp,
166 uint8_t recovery))
167 OSMO_DEPRECATED("Use gtp_set_cb_recovery3() instead, to obtain gsn handling the recovery");
168int gtp_set_cb_recovery3(struct gsn_t *gsn,
169 int (*cb) (struct gsn_t * gsn, struct sockaddr_in * peer,
170 struct pdp_t * pdp,
171 uint8_t recovery));
172void gtp_clear_queues(struct gsn_t *gsn);
173extern int gtp_fd(struct gsn_t *gsn);
174
175extern int gtp_retrans(struct gsn_t *gsn) OSMO_DEPRECATED("This API is a no-op, libgtp already does the job internally");
176extern int gtp_retranstimeout(struct gsn_t *gsn, struct timeval *timeout) OSMO_DEPRECATED("This API is a no-op and will return a 1 day timeout");
177
178/* Internal APIs: */
179void gtp_queue_timer_start(struct gsn_t *gsn);
180
181#endif /* !_GSN_H */