blob: 27b47cf8e9147123d778469d418aa63235d32114 [file] [log] [blame]
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +02001#ifndef _GB_PROXY_H
2#define _GB_PROXY_H
3
4
5#include <osmocom/core/msgb.h>
Alexander Couzens951e1332020-09-22 13:21:46 +02006#include <osmocom/core/timer.h>
Neels Hofmeyr6179f0c2018-02-21 00:39:36 +01007#include <osmocom/gsm/gsm23003.h>
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +02008
Alexander Couzens951e1332020-09-22 13:21:46 +02009#include <osmocom/gprs/gprs_ns2.h>
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020010#include <osmocom/vty/command.h>
11
12#include <sys/types.h>
13#include <regex.h>
Harald Weltebec70412019-03-22 09:44:42 +010014#include <stdbool.h>
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020015
16#define GBPROXY_INIT_VU_GEN_TX 256
17
Daniel Willmann8f407b12020-12-02 19:33:50 +010018/* BVCI uses 16 bits */
19#define BVC_LOG_CTX_FLAG (1<<17)
20
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020021struct rate_ctr_group;
22struct gprs_gb_parse_context;
23struct tlv_parsed;
24
25enum gbproxy_global_ctr {
26 GBPROX_GLOB_CTR_INV_BVCI,
27 GBPROX_GLOB_CTR_INV_LAI,
28 GBPROX_GLOB_CTR_INV_RAI,
29 GBPROX_GLOB_CTR_INV_NSEI,
30 GBPROX_GLOB_CTR_PROTO_ERR_BSS,
31 GBPROX_GLOB_CTR_PROTO_ERR_SGSN,
32 GBPROX_GLOB_CTR_NOT_SUPPORTED_BSS,
33 GBPROX_GLOB_CTR_NOT_SUPPORTED_SGSN,
34 GBPROX_GLOB_CTR_RESTART_RESET_SGSN,
35 GBPROX_GLOB_CTR_TX_ERR_SGSN,
36 GBPROX_GLOB_CTR_OTHER_ERR,
37 GBPROX_GLOB_CTR_PATCH_PEER_ERR,
38};
39
Harald Welte560bdb32020-12-04 22:24:47 +010040enum gbproxy_bvc_ctr {
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020041 GBPROX_PEER_CTR_BLOCKED,
42 GBPROX_PEER_CTR_UNBLOCKED,
43 GBPROX_PEER_CTR_DROPPED,
44 GBPROX_PEER_CTR_INV_NSEI,
45 GBPROX_PEER_CTR_TX_ERR,
46 GBPROX_PEER_CTR_RAID_PATCHED_BSS,
47 GBPROX_PEER_CTR_RAID_PATCHED_SGSN,
48 GBPROX_PEER_CTR_APN_PATCHED,
49 GBPROX_PEER_CTR_TLLI_PATCHED_BSS,
50 GBPROX_PEER_CTR_TLLI_PATCHED_SGSN,
51 GBPROX_PEER_CTR_PTMSI_PATCHED_BSS,
52 GBPROX_PEER_CTR_PTMSI_PATCHED_SGSN,
53 GBPROX_PEER_CTR_PATCH_CRYPT_ERR,
54 GBPROX_PEER_CTR_PATCH_ERR,
55 GBPROX_PEER_CTR_ATTACH_REQS,
56 GBPROX_PEER_CTR_ATTACH_REJS,
57 GBPROX_PEER_CTR_ATTACH_ACKS,
58 GBPROX_PEER_CTR_ATTACH_COMPLS,
59 GBPROX_PEER_CTR_RA_UPD_REQS,
60 GBPROX_PEER_CTR_RA_UPD_REJS,
61 GBPROX_PEER_CTR_RA_UPD_ACKS,
62 GBPROX_PEER_CTR_RA_UPD_COMPLS,
63 GBPROX_PEER_CTR_GMM_STATUS_BSS,
64 GBPROX_PEER_CTR_GMM_STATUS_SGSN,
65 GBPROX_PEER_CTR_DETACH_REQS,
66 GBPROX_PEER_CTR_DETACH_ACKS,
67 GBPROX_PEER_CTR_PDP_ACT_REQS,
68 GBPROX_PEER_CTR_PDP_ACT_REJS,
69 GBPROX_PEER_CTR_PDP_ACT_ACKS,
70 GBPROX_PEER_CTR_PDP_DEACT_REQS,
71 GBPROX_PEER_CTR_PDP_DEACT_ACKS,
72 GBPROX_PEER_CTR_TLLI_UNKNOWN,
73 GBPROX_PEER_CTR_TLLI_CACHE_SIZE,
74 GBPROX_PEER_CTR_LAST,
75};
76
77enum gbproxy_keep_mode {
Harald Welte4a8769a2019-03-22 08:26:45 +010078 GBPROX_KEEP_NEVER, /* don't ever keep TLLI/IMSI state of de-registered subscribers */
79 GBPROX_KEEP_REATTACH, /* keep if re-attach has been requested by SGSN */
80 GBPROX_KEEP_IDENTIFIED, /* keep if we had resolved an IMSI */
81 GBPROX_KEEP_ALWAYS, /* always keep */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020082};
83
84enum gbproxy_match_id {
Harald Welte4a8769a2019-03-22 08:26:45 +010085 GBPROX_MATCH_PATCHING, /* match rule on whether or not we should patch */
86 GBPROX_MATCH_ROUTING, /* match rule on whether or not we should route (2-SGSN) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020087 GBPROX_MATCH_LAST
88};
89
90struct gbproxy_match {
Harald Weltebec70412019-03-22 09:44:42 +010091 bool enable; /* is this match enabled? */
Harald Welte4a8769a2019-03-22 08:26:45 +010092 char *re_str; /* regular expression (for IMSI) in string format */
93 regex_t re_comp; /* compiled regular expression (for IMSI) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020094};
95
Harald Welte4a8769a2019-03-22 08:26:45 +010096/* global gb-proxy configuration */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020097struct gbproxy_config {
98 /* parsed from config file */
99 uint16_t nsip_sgsn_nsei;
100
Harald Welte4a8769a2019-03-22 08:26:45 +0100101 /* NS instance of libosmogb */
Alexander Couzens951e1332020-09-22 13:21:46 +0200102 struct gprs_ns2_inst *nsi;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200103
Harald Welte2b7b1bb2020-12-04 23:58:20 +0100104 /* Linked list of all BSS side Gb peers */
105 struct llist_head bss_nses;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200106
107 /* Counter */
108 struct rate_ctr_group *ctrg;
109
Harald Welte4a8769a2019-03-22 08:26:45 +0100110 /* MCC/MNC to be patched into RA-ID on the way from BSS to SGSN? */
Neels Hofmeyr6179f0c2018-02-21 00:39:36 +0100111 struct osmo_plmn_id core_plmn;
Harald Welte4a8769a2019-03-22 08:26:45 +0100112
113 /* APN to be patched into PDP CTX ACT REQ on the way from BSS to SGSN */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200114 uint8_t* core_apn;
115 size_t core_apn_size;
Harald Welte4a8769a2019-03-22 08:26:45 +0100116
Pau Espin Pedrole0d647f2018-08-17 13:13:27 +0200117 /* Frequency (sec) at which timer to clean stale links is fired (0 disabled) */
118 unsigned int clean_stale_timer_freq;
Pau Espin Pedrol02485242018-08-16 12:11:46 +0200119 /* If !0, Max age to consider a struct gbproxy_link_info as stale */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200120 int tlli_max_age;
Harald Welte560bdb32020-12-04 22:24:47 +0100121 /* If !0, Max len of gbproxy_bvc->list (list of struct gbproxy_link_info) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200122 int tlli_max_len;
Pau Espin Pedrol02485242018-08-16 12:11:46 +0200123 /* If !0, Max len of gbproxy_link_info->stored_msgs (list of msgb) */
124 uint32_t stored_msgs_max_len;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200125
Harald Welte4a8769a2019-03-22 08:26:45 +0100126 /* Should the P-TMSI be patched on the fly (required for 2-SGSN config) */
Harald Weltebec70412019-03-22 09:44:42 +0100127 bool patch_ptmsi;
Harald Welte4a8769a2019-03-22 08:26:45 +0100128 /* Should the IMSI be acquired by the proxy (required for 2-SGSN config) */
Harald Weltebec70412019-03-22 09:44:42 +0100129 bool acquire_imsi;
Harald Welte4a8769a2019-03-22 08:26:45 +0100130 /* Should we route subscribers to two different SGSNs? */
Harald Weltebec70412019-03-22 09:44:42 +0100131 bool route_to_sgsn2;
Harald Welte4a8769a2019-03-22 08:26:45 +0100132 /* NSEI of the second SGSN */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200133 uint16_t nsip_sgsn2_nsei;
Harald Welte4a8769a2019-03-22 08:26:45 +0100134 /* should we keep a cache of per-subscriber state even after de-registration? */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200135 enum gbproxy_keep_mode keep_link_infos;
136
Harald Welte4a8769a2019-03-22 08:26:45 +0100137 /* IMSI checking/matching for 2-SGSN routing and patching */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200138 struct gbproxy_match matches[GBPROX_MATCH_LAST];
139};
140
141struct gbproxy_patch_state {
Neels Hofmeyr6179f0c2018-02-21 00:39:36 +0100142 struct osmo_plmn_id local_plmn;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200143
144 /* List of TLLIs for which patching is enabled */
145 struct llist_head logical_links;
146 int logical_link_count;
147};
148
Daniel Willmanne50550e2020-11-26 18:19:21 +0100149/* One BVC inside an NSE */
Harald Welte560bdb32020-12-04 22:24:47 +0100150struct gbproxy_bvc {
151 /* linked to gbproxy_nse.bvcs */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200152 struct llist_head list;
153
Harald Welte560bdb32020-12-04 22:24:47 +0100154 /* The NSE this BVC belongs to */
Daniel Willmanne50550e2020-11-26 18:19:21 +0100155 struct gbproxy_nse *nse;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200156
Harald Welte560bdb32020-12-04 22:24:47 +0100157 /* PTP BVCI of this BVC */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200158 uint16_t bvci;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200159
Harald Welte560bdb32020-12-04 22:24:47 +0100160 /* Routing Area that this BVC is part of (raw 04.08 encoding) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200161 uint8_t ra[6];
162
Daniel Willmanne50550e2020-11-26 18:19:21 +0100163 /* true if this BVC is blocked */
164 bool blocked;
165
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200166 /* Counter */
167 struct rate_ctr_group *ctrg;
168
Harald Welte4a8769a2019-03-22 08:26:45 +0100169 /* State related to on-the-fly patching of certain messages */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200170 struct gbproxy_patch_state patch_state;
Pau Espin Pedrole0d647f2018-08-17 13:13:27 +0200171
172 /* Fired periodically to clean up stale links from list */
173 struct osmo_timer_list clean_stale_timer;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200174};
175
Harald Welte560bdb32020-12-04 22:24:47 +0100176/* one NS Entity that we interact with (BSS/PCU) */
Daniel Willmanne50550e2020-11-26 18:19:21 +0100177struct gbproxy_nse {
Harald Welte2b7b1bb2020-12-04 23:58:20 +0100178 /* linked to gbproxy_config.bss_nses */
Daniel Willmanne50550e2020-11-26 18:19:21 +0100179 struct llist_head list;
180
181 /* point back to the config */
182 struct gbproxy_config *cfg;
183
Harald Welte560bdb32020-12-04 22:24:47 +0100184 /* NSEI of the NSE */
Daniel Willmanne50550e2020-11-26 18:19:21 +0100185 uint16_t nsei;
186
187 /* List of all BVCs in this NSE */
Harald Welte560bdb32020-12-04 22:24:47 +0100188 struct llist_head bvcs;
Daniel Willmanne50550e2020-11-26 18:19:21 +0100189};
190
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200191struct gbproxy_tlli_state {
Harald Welte4a8769a2019-03-22 08:26:45 +0100192 /* currently active TLLI */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200193 uint32_t current;
Harald Welte4a8769a2019-03-22 08:26:45 +0100194 /* newly-assigned TLLI (e.g. during P-TMSI allocation procedure) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200195 uint32_t assigned;
Harald Welte4a8769a2019-03-22 08:26:45 +0100196 /* has the BSS side validated (confirmed) the new TLLI? */
Harald Weltebec70412019-03-22 09:44:42 +0100197 bool bss_validated;
Harald Welte4a8769a2019-03-22 08:26:45 +0100198 /* has the SGSN side validated (confirmed) the new TLLI? */
Harald Weltebec70412019-03-22 09:44:42 +0100199 bool net_validated;
Harald Welte4a8769a2019-03-22 08:26:45 +0100200 /* NOTE: once both are validated, we set current = assigned and assigned = 0 */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200201
Harald Welte4a8769a2019-03-22 08:26:45 +0100202 /* The P-TMSI for this subscriber */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200203 uint32_t ptmsi;
204};
205
Harald Welte4a8769a2019-03-22 08:26:45 +0100206/* One TLLI (= UE, = Subscriber) served via this proxy */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200207struct gbproxy_link_info {
Harald Welte560bdb32020-12-04 22:24:47 +0100208 /* link to gbproxy_bvc.patch_state.logical_links */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200209 struct llist_head list;
210
Harald Welte4a8769a2019-03-22 08:26:45 +0100211 /* TLLI on the BSS/PCU side */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200212 struct gbproxy_tlli_state tlli;
Harald Welte4a8769a2019-03-22 08:26:45 +0100213 /* TLLI on the SGSN side (can be different in case of P-TMSI patching) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200214 struct gbproxy_tlli_state sgsn_tlli;
Harald Welte4a8769a2019-03-22 08:26:45 +0100215 /* NSEI of the SGSN serving this link */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200216 uint32_t sgsn_nsei;
217
Harald Welte4a8769a2019-03-22 08:26:45 +0100218 /* timestamp when we last had any contact with this UE */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200219 time_t timestamp;
Harald Welte4a8769a2019-03-22 08:26:45 +0100220
221 /* IMSI of the subscriber (if/once known) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200222 uint8_t *imsi;
223 size_t imsi_len;
224
Harald Welte4a8769a2019-03-22 08:26:45 +0100225 /* is the IMSI acquisition still pending? */
Harald Weltebec70412019-03-22 09:44:42 +0100226 bool imsi_acq_pending;
Harald Welte4a8769a2019-03-22 08:26:45 +0100227
228 /* queue of stored UL messages (until IMSI acquisition completes and we can
229 * determine which of the SGSNs we should route this to */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200230 struct llist_head stored_msgs;
Pau Espin Pedrol02485242018-08-16 12:11:46 +0200231 uint32_t stored_msgs_len;
Harald Welte4a8769a2019-03-22 08:26:45 +0100232
233 /* generated N(U) we use (required due to IMSI acquisition */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200234 unsigned vu_gen_tx_bss;
235
Harald Welte4a8769a2019-03-22 08:26:45 +0100236 /* is this subscriber deregistered (TLLI invalidated)? */
Harald Weltebec70412019-03-22 09:44:42 +0100237 bool is_deregistered;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200238
Harald Welte4a8769a2019-03-22 08:26:45 +0100239 /* does this link match either the (2-SGSN) routing or the patching rule? */
Harald Weltebec70412019-03-22 09:44:42 +0100240 bool is_matching[GBPROX_MATCH_LAST];
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200241};
242
Daniel Willmann066c4cb2020-12-01 16:36:29 +0100243/* Convenience logging macros for NSE/BVC */
244#define LOGPNSE_CAT(NSE, SUBSYS, LEVEL, FMT, ARGS...) \
245 LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS) " FMT, (NSE)->nsei, ## ARGS)
246#define LOGPNSE(NSE, LEVEL, FMT, ARGS...) \
247 LOGPNSE_CAT(NSE, DGPRS, LEVEL, FMT, ## ARGS)
248
249#define LOGPBVC_CAT(BVC, SUBSYS, LEVEL, FMT, ARGS...) \
250 LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS)-BVC(%05u/%s) " FMT, (BVC)->nse->nsei, (BVC)->bvci, \
251 (BVC)->blocked ? "BLOCKED" : "UNBLOCKED", ## ARGS)
252#define LOGPBVC(BVC, LEVEL, FMT, ARGS...) \
253 LOGPBVC_CAT(BVC, DGPRS, LEVEL, FMT, ## ARGS)
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200254
255/* gb_proxy_vty .c */
256
257int gbproxy_vty_init(void);
258int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg);
259
Daniel Willmann13404b72018-06-01 07:21:20 +0200260/* gb_proxy_ctrl.c */
261int gb_ctrl_cmds_install(void);
262
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200263
264/* gb_proxy.c */
265int gbproxy_init_config(struct gbproxy_config *cfg);
266
267/* Main input function for Gb proxy */
Alexander Couzens951e1332020-09-22 13:21:46 +0200268int gbprox_rcvmsg(void *ctx, struct msgb *msg);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200269
270int gbprox_signal(unsigned int subsys, unsigned int signal,
271 void *handler_data, void *signal_data);
272
Alexander Couzens951e1332020-09-22 13:21:46 +0200273
274int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200275
276void gbprox_reset(struct gbproxy_config *cfg);
277
278/* TLLI info handling */
Harald Welte560bdb32020-12-04 22:24:47 +0100279void gbproxy_delete_link_infos(struct gbproxy_bvc *bvc);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200280struct gbproxy_link_info *gbproxy_update_link_state_ul(
Harald Welte560bdb32020-12-04 22:24:47 +0100281 struct gbproxy_bvc *bvc, time_t now,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200282 struct gprs_gb_parse_context *parse_ctx);
283struct gbproxy_link_info *gbproxy_update_link_state_dl(
Harald Welte560bdb32020-12-04 22:24:47 +0100284 struct gbproxy_bvc *bvc, time_t now,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200285 struct gprs_gb_parse_context *parse_ctx);
286int gbproxy_update_link_state_after(
Harald Welte560bdb32020-12-04 22:24:47 +0100287 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200288 time_t now, struct gprs_gb_parse_context *parse_ctx);
Harald Welte560bdb32020-12-04 22:24:47 +0100289int gbproxy_remove_stale_link_infos(struct gbproxy_bvc *bvc, time_t now);
290void gbproxy_delete_link_info(struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200291 struct gbproxy_link_info *link_info);
292void gbproxy_link_info_discard_messages(struct gbproxy_link_info *link_info);
293
Harald Welte560bdb32020-12-04 22:24:47 +0100294void gbproxy_attach_link_info(struct gbproxy_bvc *bvc, time_t now,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200295 struct gbproxy_link_info *link_info);
296void gbproxy_update_link_info(struct gbproxy_link_info *link_info,
297 const uint8_t *imsi, size_t imsi_len);
Harald Welte560bdb32020-12-04 22:24:47 +0100298void gbproxy_detach_link_info(struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200299 struct gbproxy_link_info *link_info);
Harald Welte560bdb32020-12-04 22:24:47 +0100300struct gbproxy_link_info *gbproxy_link_info_alloc( struct gbproxy_bvc *bvc);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200301
302struct gbproxy_link_info *gbproxy_link_info_by_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100303 struct gbproxy_bvc *bvc, uint32_t tlli);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200304struct gbproxy_link_info *gbproxy_link_info_by_imsi(
Harald Welte560bdb32020-12-04 22:24:47 +0100305 struct gbproxy_bvc *bvc, const uint8_t *imsi, size_t imsi_len);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200306struct gbproxy_link_info *gbproxy_link_info_by_any_sgsn_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100307 struct gbproxy_bvc *bvc, uint32_t tlli);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200308struct gbproxy_link_info *gbproxy_link_info_by_sgsn_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100309 struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200310 uint32_t tlli, uint32_t sgsn_nsei);
311struct gbproxy_link_info *gbproxy_link_info_by_ptmsi(
Harald Welte560bdb32020-12-04 22:24:47 +0100312 struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200313 uint32_t ptmsi);
314
315int gbproxy_imsi_matches(
316 struct gbproxy_config *cfg,
317 enum gbproxy_match_id match_id,
318 struct gbproxy_link_info *link_info);
319uint32_t gbproxy_map_tlli(
320 uint32_t other_tlli, struct gbproxy_link_info *link_info, int to_bss);
321
322/* needed by gb_proxy_tlli.h */
Harald Welte560bdb32020-12-04 22:24:47 +0100323uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_bvc *bvc, uint32_t sgsn_ptmsi);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200324uint32_t gbproxy_make_sgsn_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100325 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200326 uint32_t bss_tlli);
327void gbproxy_reset_link(struct gbproxy_link_info *link_info);
328int gbproxy_check_imsi(
329 struct gbproxy_match *match, const uint8_t *imsi, size_t imsi_len);
330
331/* Message patching */
332void gbproxy_patch_bssgp(
333 struct msgb *msg, uint8_t *bssgp, size_t bssgp_len,
Harald Welte560bdb32020-12-04 22:24:47 +0100334 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200335 int *len_change, struct gprs_gb_parse_context *parse_ctx);
336
337int gbproxy_patch_llc(
338 struct msgb *msg, uint8_t *llc, size_t llc_len,
Harald Welte560bdb32020-12-04 22:24:47 +0100339 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200340 int *len_change, struct gprs_gb_parse_context *parse_ctx);
341
342int gbproxy_set_patch_filter(
343 struct gbproxy_match *match, const char *filter, const char **err_msg);
344void gbproxy_clear_patch_filter(struct gbproxy_match *match);
345
346/* Peer handling */
Harald Welte560bdb32020-12-04 22:24:47 +0100347struct gbproxy_bvc *gbproxy_bvc_by_bvci(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200348 struct gbproxy_config *cfg, uint16_t bvci);
Harald Welte560bdb32020-12-04 22:24:47 +0100349struct gbproxy_bvc *gbproxy_bvc_by_nsei(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200350 struct gbproxy_config *cfg, uint16_t nsei);
Harald Welte560bdb32020-12-04 22:24:47 +0100351struct gbproxy_bvc *gbproxy_bvc_by_rai(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200352 struct gbproxy_config *cfg, const uint8_t *ra);
Harald Welte560bdb32020-12-04 22:24:47 +0100353struct gbproxy_bvc *gbproxy_bvc_by_lai(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200354 struct gbproxy_config *cfg, const uint8_t *la);
Harald Welte560bdb32020-12-04 22:24:47 +0100355struct gbproxy_bvc *gbproxy_bvc_by_lac(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200356 struct gbproxy_config *cfg, const uint8_t *la);
Harald Welte560bdb32020-12-04 22:24:47 +0100357struct gbproxy_bvc *gbproxy_bvc_by_bssgp_tlv(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200358 struct gbproxy_config *cfg, struct tlv_parsed *tp);
Harald Welte560bdb32020-12-04 22:24:47 +0100359struct gbproxy_bvc *gbproxy_bvc_alloc(struct gbproxy_nse *nse, uint16_t bvci);
360void gbproxy_bvc_free(struct gbproxy_bvc *bvc);
361void gbproxy_bvc_move(struct gbproxy_bvc *bvc, struct gbproxy_nse *nse);
362int gbproxy_cleanup_bvcs(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200363
Daniel Willmanne50550e2020-11-26 18:19:21 +0100364/* NSE handling */
365struct gbproxy_nse *gbproxy_nse_alloc(struct gbproxy_config *cfg, uint16_t nsei);
366void gbproxy_nse_free(struct gbproxy_nse *nse);
367struct gbproxy_nse *gbproxy_nse_by_nsei(struct gbproxy_config *cfg, uint16_t nsei);
368struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei);
369
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200370#endif