blob: b0ab83d7c83deb7b90015574ebec3bdf28580c58 [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>
Harald Welted2fef952020-12-05 00:31:07 +01007#include <osmocom/core/hashtable.h>
Neels Hofmeyr6179f0c2018-02-21 00:39:36 +01008#include <osmocom/gsm/gsm23003.h>
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +02009
Alexander Couzens951e1332020-09-22 13:21:46 +020010#include <osmocom/gprs/gprs_ns2.h>
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020011#include <osmocom/vty/command.h>
12
13#include <sys/types.h>
14#include <regex.h>
Harald Weltebec70412019-03-22 09:44:42 +010015#include <stdbool.h>
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020016
17#define GBPROXY_INIT_VU_GEN_TX 256
18
Daniel Willmann8f407b12020-12-02 19:33:50 +010019/* BVCI uses 16 bits */
20#define BVC_LOG_CTX_FLAG (1<<17)
21
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020022struct rate_ctr_group;
23struct gprs_gb_parse_context;
24struct tlv_parsed;
25
26enum gbproxy_global_ctr {
27 GBPROX_GLOB_CTR_INV_BVCI,
28 GBPROX_GLOB_CTR_INV_LAI,
29 GBPROX_GLOB_CTR_INV_RAI,
30 GBPROX_GLOB_CTR_INV_NSEI,
31 GBPROX_GLOB_CTR_PROTO_ERR_BSS,
32 GBPROX_GLOB_CTR_PROTO_ERR_SGSN,
33 GBPROX_GLOB_CTR_NOT_SUPPORTED_BSS,
34 GBPROX_GLOB_CTR_NOT_SUPPORTED_SGSN,
35 GBPROX_GLOB_CTR_RESTART_RESET_SGSN,
36 GBPROX_GLOB_CTR_TX_ERR_SGSN,
37 GBPROX_GLOB_CTR_OTHER_ERR,
38 GBPROX_GLOB_CTR_PATCH_PEER_ERR,
39};
40
Harald Welte560bdb32020-12-04 22:24:47 +010041enum gbproxy_bvc_ctr {
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020042 GBPROX_PEER_CTR_BLOCKED,
43 GBPROX_PEER_CTR_UNBLOCKED,
44 GBPROX_PEER_CTR_DROPPED,
45 GBPROX_PEER_CTR_INV_NSEI,
46 GBPROX_PEER_CTR_TX_ERR,
47 GBPROX_PEER_CTR_RAID_PATCHED_BSS,
48 GBPROX_PEER_CTR_RAID_PATCHED_SGSN,
49 GBPROX_PEER_CTR_APN_PATCHED,
50 GBPROX_PEER_CTR_TLLI_PATCHED_BSS,
51 GBPROX_PEER_CTR_TLLI_PATCHED_SGSN,
52 GBPROX_PEER_CTR_PTMSI_PATCHED_BSS,
53 GBPROX_PEER_CTR_PTMSI_PATCHED_SGSN,
54 GBPROX_PEER_CTR_PATCH_CRYPT_ERR,
55 GBPROX_PEER_CTR_PATCH_ERR,
56 GBPROX_PEER_CTR_ATTACH_REQS,
57 GBPROX_PEER_CTR_ATTACH_REJS,
58 GBPROX_PEER_CTR_ATTACH_ACKS,
59 GBPROX_PEER_CTR_ATTACH_COMPLS,
60 GBPROX_PEER_CTR_RA_UPD_REQS,
61 GBPROX_PEER_CTR_RA_UPD_REJS,
62 GBPROX_PEER_CTR_RA_UPD_ACKS,
63 GBPROX_PEER_CTR_RA_UPD_COMPLS,
64 GBPROX_PEER_CTR_GMM_STATUS_BSS,
65 GBPROX_PEER_CTR_GMM_STATUS_SGSN,
66 GBPROX_PEER_CTR_DETACH_REQS,
67 GBPROX_PEER_CTR_DETACH_ACKS,
68 GBPROX_PEER_CTR_PDP_ACT_REQS,
69 GBPROX_PEER_CTR_PDP_ACT_REJS,
70 GBPROX_PEER_CTR_PDP_ACT_ACKS,
71 GBPROX_PEER_CTR_PDP_DEACT_REQS,
72 GBPROX_PEER_CTR_PDP_DEACT_ACKS,
73 GBPROX_PEER_CTR_TLLI_UNKNOWN,
74 GBPROX_PEER_CTR_TLLI_CACHE_SIZE,
75 GBPROX_PEER_CTR_LAST,
76};
77
78enum gbproxy_keep_mode {
Harald Welte4a8769a2019-03-22 08:26:45 +010079 GBPROX_KEEP_NEVER, /* don't ever keep TLLI/IMSI state of de-registered subscribers */
80 GBPROX_KEEP_REATTACH, /* keep if re-attach has been requested by SGSN */
81 GBPROX_KEEP_IDENTIFIED, /* keep if we had resolved an IMSI */
82 GBPROX_KEEP_ALWAYS, /* always keep */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020083};
84
85enum gbproxy_match_id {
Harald Welte4a8769a2019-03-22 08:26:45 +010086 GBPROX_MATCH_PATCHING, /* match rule on whether or not we should patch */
87 GBPROX_MATCH_ROUTING, /* match rule on whether or not we should route (2-SGSN) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020088 GBPROX_MATCH_LAST
89};
90
91struct gbproxy_match {
Harald Weltebec70412019-03-22 09:44:42 +010092 bool enable; /* is this match enabled? */
Harald Welte4a8769a2019-03-22 08:26:45 +010093 char *re_str; /* regular expression (for IMSI) in string format */
94 regex_t re_comp; /* compiled regular expression (for IMSI) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020095};
96
Harald Welte4a8769a2019-03-22 08:26:45 +010097/* global gb-proxy configuration */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +020098struct gbproxy_config {
99 /* parsed from config file */
100 uint16_t nsip_sgsn_nsei;
101
Harald Welte4a8769a2019-03-22 08:26:45 +0100102 /* NS instance of libosmogb */
Alexander Couzens951e1332020-09-22 13:21:46 +0200103 struct gprs_ns2_inst *nsi;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200104
Harald Welte2b7b1bb2020-12-04 23:58:20 +0100105 /* Linked list of all BSS side Gb peers */
Harald Welted2fef952020-12-05 00:31:07 +0100106 DECLARE_HASHTABLE(bss_nses, 8);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200107
108 /* Counter */
109 struct rate_ctr_group *ctrg;
110
Harald Welte4a8769a2019-03-22 08:26:45 +0100111 /* MCC/MNC to be patched into RA-ID on the way from BSS to SGSN? */
Neels Hofmeyr6179f0c2018-02-21 00:39:36 +0100112 struct osmo_plmn_id core_plmn;
Harald Welte4a8769a2019-03-22 08:26:45 +0100113
114 /* APN to be patched into PDP CTX ACT REQ on the way from BSS to SGSN */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200115 uint8_t* core_apn;
116 size_t core_apn_size;
Harald Welte4a8769a2019-03-22 08:26:45 +0100117
Pau Espin Pedrole0d647f2018-08-17 13:13:27 +0200118 /* Frequency (sec) at which timer to clean stale links is fired (0 disabled) */
119 unsigned int clean_stale_timer_freq;
Pau Espin Pedrol02485242018-08-16 12:11:46 +0200120 /* If !0, Max age to consider a struct gbproxy_link_info as stale */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200121 int tlli_max_age;
Harald Welte560bdb32020-12-04 22:24:47 +0100122 /* If !0, Max len of gbproxy_bvc->list (list of struct gbproxy_link_info) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200123 int tlli_max_len;
Pau Espin Pedrol02485242018-08-16 12:11:46 +0200124 /* If !0, Max len of gbproxy_link_info->stored_msgs (list of msgb) */
125 uint32_t stored_msgs_max_len;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200126
Harald Welte4a8769a2019-03-22 08:26:45 +0100127 /* Should the P-TMSI be patched on the fly (required for 2-SGSN config) */
Harald Weltebec70412019-03-22 09:44:42 +0100128 bool patch_ptmsi;
Harald Welte4a8769a2019-03-22 08:26:45 +0100129 /* Should the IMSI be acquired by the proxy (required for 2-SGSN config) */
Harald Weltebec70412019-03-22 09:44:42 +0100130 bool acquire_imsi;
Harald Welte4a8769a2019-03-22 08:26:45 +0100131 /* Should we route subscribers to two different SGSNs? */
Harald Weltebec70412019-03-22 09:44:42 +0100132 bool route_to_sgsn2;
Harald Welte4a8769a2019-03-22 08:26:45 +0100133 /* NSEI of the second SGSN */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200134 uint16_t nsip_sgsn2_nsei;
Harald Welte4a8769a2019-03-22 08:26:45 +0100135 /* should we keep a cache of per-subscriber state even after de-registration? */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200136 enum gbproxy_keep_mode keep_link_infos;
137
Harald Welte4a8769a2019-03-22 08:26:45 +0100138 /* IMSI checking/matching for 2-SGSN routing and patching */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200139 struct gbproxy_match matches[GBPROX_MATCH_LAST];
140};
141
142struct gbproxy_patch_state {
Neels Hofmeyr6179f0c2018-02-21 00:39:36 +0100143 struct osmo_plmn_id local_plmn;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200144
145 /* List of TLLIs for which patching is enabled */
146 struct llist_head logical_links;
147 int logical_link_count;
148};
149
Daniel Willmanne50550e2020-11-26 18:19:21 +0100150/* One BVC inside an NSE */
Harald Welte560bdb32020-12-04 22:24:47 +0100151struct gbproxy_bvc {
152 /* linked to gbproxy_nse.bvcs */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200153 struct llist_head list;
154
Harald Welte560bdb32020-12-04 22:24:47 +0100155 /* The NSE this BVC belongs to */
Daniel Willmanne50550e2020-11-26 18:19:21 +0100156 struct gbproxy_nse *nse;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200157
Harald Welte560bdb32020-12-04 22:24:47 +0100158 /* PTP BVCI of this BVC */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200159 uint16_t bvci;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200160
Harald Welte560bdb32020-12-04 22:24:47 +0100161 /* Routing Area that this BVC is part of (raw 04.08 encoding) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200162 uint8_t ra[6];
163
Daniel Willmanne50550e2020-11-26 18:19:21 +0100164 /* true if this BVC is blocked */
165 bool blocked;
166
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200167 /* Counter */
168 struct rate_ctr_group *ctrg;
169
Harald Welte4a8769a2019-03-22 08:26:45 +0100170 /* State related to on-the-fly patching of certain messages */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200171 struct gbproxy_patch_state patch_state;
Pau Espin Pedrole0d647f2018-08-17 13:13:27 +0200172
173 /* Fired periodically to clean up stale links from list */
174 struct osmo_timer_list clean_stale_timer;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200175};
176
Harald Welte560bdb32020-12-04 22:24:47 +0100177/* one NS Entity that we interact with (BSS/PCU) */
Daniel Willmanne50550e2020-11-26 18:19:21 +0100178struct gbproxy_nse {
Harald Welte2b7b1bb2020-12-04 23:58:20 +0100179 /* linked to gbproxy_config.bss_nses */
Harald Welted2fef952020-12-05 00:31:07 +0100180 struct hlist_node list;
Daniel Willmanne50550e2020-11-26 18:19:21 +0100181
182 /* point back to the config */
183 struct gbproxy_config *cfg;
184
Harald Welte560bdb32020-12-04 22:24:47 +0100185 /* NSEI of the NSE */
Daniel Willmanne50550e2020-11-26 18:19:21 +0100186 uint16_t nsei;
187
188 /* List of all BVCs in this NSE */
Harald Welte560bdb32020-12-04 22:24:47 +0100189 struct llist_head bvcs;
Daniel Willmanne50550e2020-11-26 18:19:21 +0100190};
191
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200192struct gbproxy_tlli_state {
Harald Welte4a8769a2019-03-22 08:26:45 +0100193 /* currently active TLLI */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200194 uint32_t current;
Harald Welte4a8769a2019-03-22 08:26:45 +0100195 /* newly-assigned TLLI (e.g. during P-TMSI allocation procedure) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200196 uint32_t assigned;
Harald Welte4a8769a2019-03-22 08:26:45 +0100197 /* has the BSS side validated (confirmed) the new TLLI? */
Harald Weltebec70412019-03-22 09:44:42 +0100198 bool bss_validated;
Harald Welte4a8769a2019-03-22 08:26:45 +0100199 /* has the SGSN side validated (confirmed) the new TLLI? */
Harald Weltebec70412019-03-22 09:44:42 +0100200 bool net_validated;
Harald Welte4a8769a2019-03-22 08:26:45 +0100201 /* NOTE: once both are validated, we set current = assigned and assigned = 0 */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200202
Harald Welte4a8769a2019-03-22 08:26:45 +0100203 /* The P-TMSI for this subscriber */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200204 uint32_t ptmsi;
205};
206
Harald Welte4a8769a2019-03-22 08:26:45 +0100207/* One TLLI (= UE, = Subscriber) served via this proxy */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200208struct gbproxy_link_info {
Harald Welte560bdb32020-12-04 22:24:47 +0100209 /* link to gbproxy_bvc.patch_state.logical_links */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200210 struct llist_head list;
211
Harald Welte4a8769a2019-03-22 08:26:45 +0100212 /* TLLI on the BSS/PCU side */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200213 struct gbproxy_tlli_state tlli;
Harald Welte4a8769a2019-03-22 08:26:45 +0100214 /* TLLI on the SGSN side (can be different in case of P-TMSI patching) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200215 struct gbproxy_tlli_state sgsn_tlli;
Harald Welte4a8769a2019-03-22 08:26:45 +0100216 /* NSEI of the SGSN serving this link */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200217 uint32_t sgsn_nsei;
218
Harald Welte4a8769a2019-03-22 08:26:45 +0100219 /* timestamp when we last had any contact with this UE */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200220 time_t timestamp;
Harald Welte4a8769a2019-03-22 08:26:45 +0100221
222 /* IMSI of the subscriber (if/once known) */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200223 uint8_t *imsi;
224 size_t imsi_len;
225
Harald Welte4a8769a2019-03-22 08:26:45 +0100226 /* is the IMSI acquisition still pending? */
Harald Weltebec70412019-03-22 09:44:42 +0100227 bool imsi_acq_pending;
Harald Welte4a8769a2019-03-22 08:26:45 +0100228
229 /* queue of stored UL messages (until IMSI acquisition completes and we can
230 * determine which of the SGSNs we should route this to */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200231 struct llist_head stored_msgs;
Pau Espin Pedrol02485242018-08-16 12:11:46 +0200232 uint32_t stored_msgs_len;
Harald Welte4a8769a2019-03-22 08:26:45 +0100233
234 /* generated N(U) we use (required due to IMSI acquisition */
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200235 unsigned vu_gen_tx_bss;
236
Harald Welte4a8769a2019-03-22 08:26:45 +0100237 /* is this subscriber deregistered (TLLI invalidated)? */
Harald Weltebec70412019-03-22 09:44:42 +0100238 bool is_deregistered;
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200239
Harald Welte4a8769a2019-03-22 08:26:45 +0100240 /* does this link match either the (2-SGSN) routing or the patching rule? */
Harald Weltebec70412019-03-22 09:44:42 +0100241 bool is_matching[GBPROX_MATCH_LAST];
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200242};
243
Daniel Willmann066c4cb2020-12-01 16:36:29 +0100244/* Convenience logging macros for NSE/BVC */
245#define LOGPNSE_CAT(NSE, SUBSYS, LEVEL, FMT, ARGS...) \
246 LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS) " FMT, (NSE)->nsei, ## ARGS)
247#define LOGPNSE(NSE, LEVEL, FMT, ARGS...) \
248 LOGPNSE_CAT(NSE, DGPRS, LEVEL, FMT, ## ARGS)
249
250#define LOGPBVC_CAT(BVC, SUBSYS, LEVEL, FMT, ARGS...) \
251 LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS)-BVC(%05u/%s) " FMT, (BVC)->nse->nsei, (BVC)->bvci, \
252 (BVC)->blocked ? "BLOCKED" : "UNBLOCKED", ## ARGS)
253#define LOGPBVC(BVC, LEVEL, FMT, ARGS...) \
254 LOGPBVC_CAT(BVC, DGPRS, LEVEL, FMT, ## ARGS)
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200255
256/* gb_proxy_vty .c */
257
258int gbproxy_vty_init(void);
259int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg);
260
Daniel Willmann13404b72018-06-01 07:21:20 +0200261/* gb_proxy_ctrl.c */
262int gb_ctrl_cmds_install(void);
263
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200264
265/* gb_proxy.c */
266int gbproxy_init_config(struct gbproxy_config *cfg);
267
268/* Main input function for Gb proxy */
Alexander Couzens951e1332020-09-22 13:21:46 +0200269int gbprox_rcvmsg(void *ctx, struct msgb *msg);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200270
271int gbprox_signal(unsigned int subsys, unsigned int signal,
272 void *handler_data, void *signal_data);
273
Alexander Couzens951e1332020-09-22 13:21:46 +0200274
275int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200276
277void gbprox_reset(struct gbproxy_config *cfg);
278
279/* TLLI info handling */
Harald Welte560bdb32020-12-04 22:24:47 +0100280void gbproxy_delete_link_infos(struct gbproxy_bvc *bvc);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200281struct gbproxy_link_info *gbproxy_update_link_state_ul(
Harald Welte560bdb32020-12-04 22:24:47 +0100282 struct gbproxy_bvc *bvc, time_t now,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200283 struct gprs_gb_parse_context *parse_ctx);
284struct gbproxy_link_info *gbproxy_update_link_state_dl(
Harald Welte560bdb32020-12-04 22:24:47 +0100285 struct gbproxy_bvc *bvc, time_t now,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200286 struct gprs_gb_parse_context *parse_ctx);
287int gbproxy_update_link_state_after(
Harald Welte560bdb32020-12-04 22:24:47 +0100288 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200289 time_t now, struct gprs_gb_parse_context *parse_ctx);
Harald Welte560bdb32020-12-04 22:24:47 +0100290int gbproxy_remove_stale_link_infos(struct gbproxy_bvc *bvc, time_t now);
291void gbproxy_delete_link_info(struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200292 struct gbproxy_link_info *link_info);
293void gbproxy_link_info_discard_messages(struct gbproxy_link_info *link_info);
294
Harald Welte560bdb32020-12-04 22:24:47 +0100295void gbproxy_attach_link_info(struct gbproxy_bvc *bvc, time_t now,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200296 struct gbproxy_link_info *link_info);
297void gbproxy_update_link_info(struct gbproxy_link_info *link_info,
298 const uint8_t *imsi, size_t imsi_len);
Harald Welte560bdb32020-12-04 22:24:47 +0100299void gbproxy_detach_link_info(struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200300 struct gbproxy_link_info *link_info);
Harald Welte560bdb32020-12-04 22:24:47 +0100301struct gbproxy_link_info *gbproxy_link_info_alloc( struct gbproxy_bvc *bvc);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200302
303struct gbproxy_link_info *gbproxy_link_info_by_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100304 struct gbproxy_bvc *bvc, uint32_t tlli);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200305struct gbproxy_link_info *gbproxy_link_info_by_imsi(
Harald Welte560bdb32020-12-04 22:24:47 +0100306 struct gbproxy_bvc *bvc, const uint8_t *imsi, size_t imsi_len);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200307struct gbproxy_link_info *gbproxy_link_info_by_any_sgsn_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100308 struct gbproxy_bvc *bvc, uint32_t tlli);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200309struct gbproxy_link_info *gbproxy_link_info_by_sgsn_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100310 struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200311 uint32_t tlli, uint32_t sgsn_nsei);
312struct gbproxy_link_info *gbproxy_link_info_by_ptmsi(
Harald Welte560bdb32020-12-04 22:24:47 +0100313 struct gbproxy_bvc *bvc,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200314 uint32_t ptmsi);
315
316int gbproxy_imsi_matches(
317 struct gbproxy_config *cfg,
318 enum gbproxy_match_id match_id,
319 struct gbproxy_link_info *link_info);
320uint32_t gbproxy_map_tlli(
321 uint32_t other_tlli, struct gbproxy_link_info *link_info, int to_bss);
322
323/* needed by gb_proxy_tlli.h */
Harald Welte560bdb32020-12-04 22:24:47 +0100324uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_bvc *bvc, uint32_t sgsn_ptmsi);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200325uint32_t gbproxy_make_sgsn_tlli(
Harald Welte560bdb32020-12-04 22:24:47 +0100326 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200327 uint32_t bss_tlli);
328void gbproxy_reset_link(struct gbproxy_link_info *link_info);
329int gbproxy_check_imsi(
330 struct gbproxy_match *match, const uint8_t *imsi, size_t imsi_len);
331
332/* Message patching */
333void gbproxy_patch_bssgp(
334 struct msgb *msg, uint8_t *bssgp, size_t bssgp_len,
Harald Welte560bdb32020-12-04 22:24:47 +0100335 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200336 int *len_change, struct gprs_gb_parse_context *parse_ctx);
337
338int gbproxy_patch_llc(
339 struct msgb *msg, uint8_t *llc, size_t llc_len,
Harald Welte560bdb32020-12-04 22:24:47 +0100340 struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info,
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200341 int *len_change, struct gprs_gb_parse_context *parse_ctx);
342
343int gbproxy_set_patch_filter(
344 struct gbproxy_match *match, const char *filter, const char **err_msg);
345void gbproxy_clear_patch_filter(struct gbproxy_match *match);
346
347/* Peer handling */
Harald Welte560bdb32020-12-04 22:24:47 +0100348struct gbproxy_bvc *gbproxy_bvc_by_bvci(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200349 struct gbproxy_config *cfg, uint16_t bvci);
Harald Welte560bdb32020-12-04 22:24:47 +0100350struct gbproxy_bvc *gbproxy_bvc_by_nsei(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200351 struct gbproxy_config *cfg, uint16_t nsei);
Harald Welte560bdb32020-12-04 22:24:47 +0100352struct gbproxy_bvc *gbproxy_bvc_by_rai(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200353 struct gbproxy_config *cfg, const uint8_t *ra);
Harald Welte560bdb32020-12-04 22:24:47 +0100354struct gbproxy_bvc *gbproxy_bvc_by_lai(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200355 struct gbproxy_config *cfg, const uint8_t *la);
Harald Welte560bdb32020-12-04 22:24:47 +0100356struct gbproxy_bvc *gbproxy_bvc_by_lac(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200357 struct gbproxy_config *cfg, const uint8_t *la);
Harald Welte560bdb32020-12-04 22:24:47 +0100358struct gbproxy_bvc *gbproxy_bvc_by_bssgp_tlv(
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200359 struct gbproxy_config *cfg, struct tlv_parsed *tp);
Harald Welte560bdb32020-12-04 22:24:47 +0100360struct gbproxy_bvc *gbproxy_bvc_alloc(struct gbproxy_nse *nse, uint16_t bvci);
361void gbproxy_bvc_free(struct gbproxy_bvc *bvc);
362void gbproxy_bvc_move(struct gbproxy_bvc *bvc, struct gbproxy_nse *nse);
363int gbproxy_cleanup_bvcs(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci);
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200364
Daniel Willmanne50550e2020-11-26 18:19:21 +0100365/* NSE handling */
366struct gbproxy_nse *gbproxy_nse_alloc(struct gbproxy_config *cfg, uint16_t nsei);
367void gbproxy_nse_free(struct gbproxy_nse *nse);
368struct gbproxy_nse *gbproxy_nse_by_nsei(struct gbproxy_config *cfg, uint16_t nsei);
369struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei);
370
Neels Hofmeyr4b4c5862017-09-04 15:13:25 +0200371#endif