blob: 18a6d5803074f2f9d58588daca91835154332e0b [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>
18
19#include "pdp.h"
20
21#define GTP_MODE_GGSN 1
22#define GTP_MODE_SGSN 2
23
24#define RESTART_FILE "gsn_restart"
25
26/* ***********************************************************
27 * Information storage for each gsn instance
28 *
29 * Normally each instance of the application corresponds to
30 * one instance of a gsn.
31 *
32 * In order to avoid global variables in the application, and
33 * also in order to allow several instances of a gsn in the same
34 * application this struct is provided in order to store all
35 * relevant information related to the gsn.
36 *
37 * Note that this does not include information storage for '
38 * each pdp context. This is stored in another struct.
39 *************************************************************/
40
41struct gsn_t {
42 /* Parameters related to the network interface */
43
44 int fd0; /* GTP0 file descriptor */
45 int fd1c; /* GTP1 control plane file descriptor */
46 int fd1u; /* GTP0 user plane file descriptor */
47 int mode; /* Mode of operation: GGSN or SGSN */
48 struct in_addr gsnc; /* IP address of this gsn for signalling */
49 struct in_addr gsnu; /* IP address of this gsn for user traffic */
50
51 /* Parameters related to signalling messages */
52 uint16_t seq_next; /* Next sequence number to use */
53 int seq_first; /* First packet in queue (oldest timeout) */
54 int seq_last; /* Last packet in queue (youngest timeout) */
55
56 unsigned char restart_counter; /* Increment on restart. Stored on disk */
57 char *statedir; /* Disk location for permanent storage */
58 void *priv; /* used by libgtp users to attach their own state) */
59 struct queue_t *queue_req; /* Request queue */
60 struct queue_t *queue_resp; /* Response queue */
61
62 struct pdp_t pdpa[PDP_MAX]; /* PDP storage */
63 struct pdp_t *hashtid[PDP_MAX]; /* Hash table for IMSI + NSAPI */
64
65 struct osmo_timer_list queue_timer; /* internal queue_{req,resp} timer */
66
67 /* Call back functions */
68 int (*cb_delete_context) (struct pdp_t *);
69 int (*cb_create_context_ind) (struct pdp_t *);
70 int (*cb_unsup_ind) (struct sockaddr_in * peer);
71 int (*cb_extheader_ind) (struct sockaddr_in * peer);
72 int (*cb_ran_info_relay_ind) (struct sockaddr_in *peer, union gtpie_member **ie);
73 int (*cb_conf) (int type, int cause, struct pdp_t * pdp, void *cbp);
74 int (*cb_data_ind) (struct pdp_t * pdp, void *pack, unsigned len);
75 int (*cb_recovery) (struct sockaddr_in * peer, uint8_t recovery);
76 int (*cb_recovery2) (struct sockaddr_in * peer, struct pdp_t * pdp, uint8_t recovery);
77 int (*cb_recovery3) (struct gsn_t *gsn, struct sockaddr_in *peer, struct pdp_t *pdp, uint8_t recovery);
78
79 /* Counters */
80
81 uint64_t err_socket; /* Number of socket errors */
82 uint64_t err_readfrom; /* Number of readfrom errors */
83 uint64_t err_sendto; /* Number of sendto errors */
84 uint64_t err_memcpy; /* Number of memcpy */
85 uint64_t err_queuefull; /* Number of times queue was full */
86 uint64_t err_seq; /* Number of seq out of range */
87 uint64_t err_address; /* GSN address conversion failed */
88 uint64_t err_unknownpdp; /* GSN address conversion failed */
89 uint64_t err_unknowntid; /* Application supplied unknown imsi+nsapi */
90 uint64_t err_cause; /* Unexpected cause value received */
91 uint64_t err_outofpdp; /* Out of storage for PDP contexts */
92
93 uint64_t empty; /* Number of empty packets */
94 uint64_t unsup; /* Number of unsupported version 29.60 11.1.1 */
95 uint64_t tooshort; /* Number of too short headers 29.60 11.1.2 */
96 uint64_t unknown; /* Number of unknown messages 29.60 11.1.3 */
97 uint64_t unexpect; /* Number of unexpected messages 29.60 11.1.4 */
98 uint64_t duplicate; /* Number of duplicate or unsolicited replies */
99 uint64_t missing; /* Number of missing information field messages */
100 uint64_t incorrect; /* Number of incorrect information field messages */
101 uint64_t invalid; /* Number of invalid message format messages */
102};
103
104/* External API functions */
105
106extern int gtp_new(struct gsn_t **gsn, char *statedir, struct in_addr *listen,
107 int mode);
108
109extern int gtp_free(struct gsn_t *gsn);
110
111extern int gtp_newpdp(struct gsn_t *gsn, struct pdp_t **pdp,
112 uint64_t imsi, uint8_t nsapi) OSMO_DEPRECATED("Use gtp_pdp_newpdp() instead");
113extern int gtp_freepdp(struct gsn_t *gsn, struct pdp_t *pdp);
114extern int gtp_freepdp_teardown(struct gsn_t *gsn, struct pdp_t *pdp);
115
116extern int gtp_create_context_req(struct gsn_t *gsn, struct pdp_t *pdp,
117 void *cbp);
118
119extern int gtp_set_cb_create_context_ind(struct gsn_t *gsn,
120 int (*cb_create_context_ind) (struct
121 pdp_t *
122 pdp));
123extern int gtp_set_cb_data_ind(struct gsn_t *gsn,
124 int (*cb_data_ind) (struct pdp_t * pdp,
125 void *pack, unsigned len));
126extern int gtp_set_cb_delete_context(struct gsn_t *gsn,
127 int (*cb_delete_context) (struct pdp_t *
128 pdp));
129/*extern int gtp_set_cb_create_context(struct gsn_t *gsn,
130 int (*cb_create_context) (struct pdp_t* pdp)); */
131
132extern int gtp_set_cb_unsup_ind(struct gsn_t *gsn,
133 int (*cb) (struct sockaddr_in * peer));
134
135extern int gtp_set_cb_extheader_ind(struct gsn_t *gsn,
136 int (*cb) (struct sockaddr_in * peer));
137
138extern int gtp_set_cb_ran_info_relay_ind(struct gsn_t *gsn,
139 int (*cb) (struct sockaddr_in * peer, union gtpie_member **ie));
140
141extern int gtp_set_cb_conf(struct gsn_t *gsn,
142 int (*cb) (int type, int cause, struct pdp_t * pdp,
143 void *cbp));
144
145int gtp_set_cb_recovery(struct gsn_t *gsn,
146 int (*cb) (struct sockaddr_in * peer,
147 uint8_t recovery))
148 OSMO_DEPRECATED("Use gtp_set_cb_recovery2() instead, to obtain pdp ctx originating the recovery");
149int gtp_set_cb_recovery2(struct gsn_t *gsn,
150 int (*cb) (struct sockaddr_in * peer,
151 struct pdp_t * pdp,
152 uint8_t recovery))
153 OSMO_DEPRECATED("Use gtp_set_cb_recovery3() instead, to obtain gsn handling the recovery");
154int gtp_set_cb_recovery3(struct gsn_t *gsn,
155 int (*cb) (struct gsn_t * gsn, struct sockaddr_in * peer,
156 struct pdp_t * pdp,
157 uint8_t recovery));
158void gtp_clear_queues(struct gsn_t *gsn);
159extern int gtp_fd(struct gsn_t *gsn);
160
161extern int gtp_retrans(struct gsn_t *gsn) OSMO_DEPRECATED("This API is a no-op, libgtp already does the job internally");
162extern 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");
163
164/* Internal APIs: */
165void gtp_queue_timer_start(struct gsn_t *gsn);
166
167#endif /* !_GSN_H */