Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 1 | #ifndef _GB_PROXY_H |
| 2 | #define _GB_PROXY_H |
| 3 | |
| 4 | |
| 5 | #include <osmocom/core/msgb.h> |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 6 | #include <osmocom/core/timer.h> |
Neels Hofmeyr | 6179f0c | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 7 | #include <osmocom/gsm/gsm23003.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 8 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 9 | #include <osmocom/gprs/gprs_ns2.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 10 | #include <osmocom/vty/command.h> |
| 11 | |
| 12 | #include <sys/types.h> |
| 13 | #include <regex.h> |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 14 | #include <stdbool.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 15 | |
| 16 | #define GBPROXY_INIT_VU_GEN_TX 256 |
| 17 | |
| 18 | struct rate_ctr_group; |
| 19 | struct gprs_gb_parse_context; |
| 20 | struct tlv_parsed; |
| 21 | |
| 22 | enum gbproxy_global_ctr { |
| 23 | GBPROX_GLOB_CTR_INV_BVCI, |
| 24 | GBPROX_GLOB_CTR_INV_LAI, |
| 25 | GBPROX_GLOB_CTR_INV_RAI, |
| 26 | GBPROX_GLOB_CTR_INV_NSEI, |
| 27 | GBPROX_GLOB_CTR_PROTO_ERR_BSS, |
| 28 | GBPROX_GLOB_CTR_PROTO_ERR_SGSN, |
| 29 | GBPROX_GLOB_CTR_NOT_SUPPORTED_BSS, |
| 30 | GBPROX_GLOB_CTR_NOT_SUPPORTED_SGSN, |
| 31 | GBPROX_GLOB_CTR_RESTART_RESET_SGSN, |
| 32 | GBPROX_GLOB_CTR_TX_ERR_SGSN, |
| 33 | GBPROX_GLOB_CTR_OTHER_ERR, |
| 34 | GBPROX_GLOB_CTR_PATCH_PEER_ERR, |
| 35 | }; |
| 36 | |
| 37 | enum gbproxy_peer_ctr { |
| 38 | GBPROX_PEER_CTR_BLOCKED, |
| 39 | GBPROX_PEER_CTR_UNBLOCKED, |
| 40 | GBPROX_PEER_CTR_DROPPED, |
| 41 | GBPROX_PEER_CTR_INV_NSEI, |
| 42 | GBPROX_PEER_CTR_TX_ERR, |
| 43 | GBPROX_PEER_CTR_RAID_PATCHED_BSS, |
| 44 | GBPROX_PEER_CTR_RAID_PATCHED_SGSN, |
| 45 | GBPROX_PEER_CTR_APN_PATCHED, |
| 46 | GBPROX_PEER_CTR_TLLI_PATCHED_BSS, |
| 47 | GBPROX_PEER_CTR_TLLI_PATCHED_SGSN, |
| 48 | GBPROX_PEER_CTR_PTMSI_PATCHED_BSS, |
| 49 | GBPROX_PEER_CTR_PTMSI_PATCHED_SGSN, |
| 50 | GBPROX_PEER_CTR_PATCH_CRYPT_ERR, |
| 51 | GBPROX_PEER_CTR_PATCH_ERR, |
| 52 | GBPROX_PEER_CTR_ATTACH_REQS, |
| 53 | GBPROX_PEER_CTR_ATTACH_REJS, |
| 54 | GBPROX_PEER_CTR_ATTACH_ACKS, |
| 55 | GBPROX_PEER_CTR_ATTACH_COMPLS, |
| 56 | GBPROX_PEER_CTR_RA_UPD_REQS, |
| 57 | GBPROX_PEER_CTR_RA_UPD_REJS, |
| 58 | GBPROX_PEER_CTR_RA_UPD_ACKS, |
| 59 | GBPROX_PEER_CTR_RA_UPD_COMPLS, |
| 60 | GBPROX_PEER_CTR_GMM_STATUS_BSS, |
| 61 | GBPROX_PEER_CTR_GMM_STATUS_SGSN, |
| 62 | GBPROX_PEER_CTR_DETACH_REQS, |
| 63 | GBPROX_PEER_CTR_DETACH_ACKS, |
| 64 | GBPROX_PEER_CTR_PDP_ACT_REQS, |
| 65 | GBPROX_PEER_CTR_PDP_ACT_REJS, |
| 66 | GBPROX_PEER_CTR_PDP_ACT_ACKS, |
| 67 | GBPROX_PEER_CTR_PDP_DEACT_REQS, |
| 68 | GBPROX_PEER_CTR_PDP_DEACT_ACKS, |
| 69 | GBPROX_PEER_CTR_TLLI_UNKNOWN, |
| 70 | GBPROX_PEER_CTR_TLLI_CACHE_SIZE, |
| 71 | GBPROX_PEER_CTR_LAST, |
| 72 | }; |
| 73 | |
| 74 | enum gbproxy_keep_mode { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 75 | GBPROX_KEEP_NEVER, /* don't ever keep TLLI/IMSI state of de-registered subscribers */ |
| 76 | GBPROX_KEEP_REATTACH, /* keep if re-attach has been requested by SGSN */ |
| 77 | GBPROX_KEEP_IDENTIFIED, /* keep if we had resolved an IMSI */ |
| 78 | GBPROX_KEEP_ALWAYS, /* always keep */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | enum gbproxy_match_id { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 82 | GBPROX_MATCH_PATCHING, /* match rule on whether or not we should patch */ |
| 83 | GBPROX_MATCH_ROUTING, /* match rule on whether or not we should route (2-SGSN) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 84 | GBPROX_MATCH_LAST |
| 85 | }; |
| 86 | |
| 87 | struct gbproxy_match { |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 88 | bool enable; /* is this match enabled? */ |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 89 | char *re_str; /* regular expression (for IMSI) in string format */ |
| 90 | regex_t re_comp; /* compiled regular expression (for IMSI) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 93 | /* global gb-proxy configuration */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 94 | struct gbproxy_config { |
| 95 | /* parsed from config file */ |
| 96 | uint16_t nsip_sgsn_nsei; |
| 97 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 98 | /* NS instance of libosmogb */ |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 99 | struct gprs_ns2_inst *nsi; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 100 | |
| 101 | /* Linked list of all Gb peers (except SGSN) */ |
| 102 | struct llist_head bts_peers; |
| 103 | |
| 104 | /* Counter */ |
| 105 | struct rate_ctr_group *ctrg; |
| 106 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 107 | /* MCC/MNC to be patched into RA-ID on the way from BSS to SGSN? */ |
Neels Hofmeyr | 6179f0c | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 108 | struct osmo_plmn_id core_plmn; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 109 | |
| 110 | /* APN to be patched into PDP CTX ACT REQ on the way from BSS to SGSN */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 111 | uint8_t* core_apn; |
| 112 | size_t core_apn_size; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 113 | |
Pau Espin Pedrol | e0d647f | 2018-08-17 13:13:27 +0200 | [diff] [blame] | 114 | /* Frequency (sec) at which timer to clean stale links is fired (0 disabled) */ |
| 115 | unsigned int clean_stale_timer_freq; |
Pau Espin Pedrol | 0248524 | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 116 | /* If !0, Max age to consider a struct gbproxy_link_info as stale */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 117 | int tlli_max_age; |
Pau Espin Pedrol | 0248524 | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 118 | /* If !0, Max len of gbproxy_peer->list (list of struct gbproxy_link_info) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 119 | int tlli_max_len; |
Pau Espin Pedrol | 0248524 | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 120 | /* If !0, Max len of gbproxy_link_info->stored_msgs (list of msgb) */ |
| 121 | uint32_t stored_msgs_max_len; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 122 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 123 | /* Should the P-TMSI be patched on the fly (required for 2-SGSN config) */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 124 | bool patch_ptmsi; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 125 | /* Should the IMSI be acquired by the proxy (required for 2-SGSN config) */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 126 | bool acquire_imsi; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 127 | /* Should we route subscribers to two different SGSNs? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 128 | bool route_to_sgsn2; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 129 | /* NSEI of the second SGSN */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 130 | uint16_t nsip_sgsn2_nsei; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 131 | /* should we keep a cache of per-subscriber state even after de-registration? */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 132 | enum gbproxy_keep_mode keep_link_infos; |
| 133 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 134 | /* IMSI checking/matching for 2-SGSN routing and patching */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 135 | struct gbproxy_match matches[GBPROX_MATCH_LAST]; |
| 136 | }; |
| 137 | |
| 138 | struct gbproxy_patch_state { |
Neels Hofmeyr | 6179f0c | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 139 | struct osmo_plmn_id local_plmn; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 140 | |
| 141 | /* List of TLLIs for which patching is enabled */ |
| 142 | struct llist_head logical_links; |
| 143 | int logical_link_count; |
| 144 | }; |
| 145 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 146 | /* one peer at NS level that we interact with (BSS/PCU) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 147 | struct gbproxy_peer { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 148 | /* linked to gbproxy_config.bts_peers */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 149 | struct llist_head list; |
| 150 | |
| 151 | /* point back to the config */ |
| 152 | struct gbproxy_config *cfg; |
| 153 | |
| 154 | /* NSEI of the peer entity */ |
| 155 | uint16_t nsei; |
| 156 | |
| 157 | /* BVCI used for Point-to-Point to this peer */ |
| 158 | uint16_t bvci; |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 159 | bool blocked; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 160 | |
| 161 | /* Routeing Area that this peer is part of (raw 04.08 encoding) */ |
| 162 | uint8_t ra[6]; |
| 163 | |
| 164 | /* Counter */ |
| 165 | struct rate_ctr_group *ctrg; |
| 166 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 167 | /* State related to on-the-fly patching of certain messages */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 168 | struct gbproxy_patch_state patch_state; |
Pau Espin Pedrol | e0d647f | 2018-08-17 13:13:27 +0200 | [diff] [blame] | 169 | |
| 170 | /* Fired periodically to clean up stale links from list */ |
| 171 | struct osmo_timer_list clean_stale_timer; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 172 | }; |
| 173 | |
| 174 | struct gbproxy_tlli_state { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 175 | /* currently active TLLI */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 176 | uint32_t current; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 177 | /* newly-assigned TLLI (e.g. during P-TMSI allocation procedure) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 178 | uint32_t assigned; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 179 | /* has the BSS side validated (confirmed) the new TLLI? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 180 | bool bss_validated; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 181 | /* has the SGSN side validated (confirmed) the new TLLI? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 182 | bool net_validated; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 183 | /* NOTE: once both are validated, we set current = assigned and assigned = 0 */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 184 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 185 | /* The P-TMSI for this subscriber */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 186 | uint32_t ptmsi; |
| 187 | }; |
| 188 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 189 | /* One TLLI (= UE, = Subscriber) served via this proxy */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 190 | struct gbproxy_link_info { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 191 | /* link to gbproxy_peer.patch_state.logical_links */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 192 | struct llist_head list; |
| 193 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 194 | /* TLLI on the BSS/PCU side */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 195 | struct gbproxy_tlli_state tlli; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 196 | /* TLLI on the SGSN side (can be different in case of P-TMSI patching) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 197 | struct gbproxy_tlli_state sgsn_tlli; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 198 | /* NSEI of the SGSN serving this link */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 199 | uint32_t sgsn_nsei; |
| 200 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 201 | /* timestamp when we last had any contact with this UE */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 202 | time_t timestamp; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 203 | |
| 204 | /* IMSI of the subscriber (if/once known) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 205 | uint8_t *imsi; |
| 206 | size_t imsi_len; |
| 207 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 208 | /* is the IMSI acquisition still pending? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 209 | bool imsi_acq_pending; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 210 | |
| 211 | /* queue of stored UL messages (until IMSI acquisition completes and we can |
| 212 | * determine which of the SGSNs we should route this to */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 213 | struct llist_head stored_msgs; |
Pau Espin Pedrol | 0248524 | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 214 | uint32_t stored_msgs_len; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 215 | |
| 216 | /* generated N(U) we use (required due to IMSI acquisition */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 217 | unsigned vu_gen_tx_bss; |
| 218 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 219 | /* is this subscriber deregistered (TLLI invalidated)? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 220 | bool is_deregistered; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 221 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 222 | /* does this link match either the (2-SGSN) routing or the patching rule? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 223 | bool is_matching[GBPROX_MATCH_LAST]; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | |
| 227 | /* gb_proxy_vty .c */ |
| 228 | |
| 229 | int gbproxy_vty_init(void); |
| 230 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg); |
| 231 | |
Daniel Willmann | 13404b7 | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 232 | /* gb_proxy_ctrl.c */ |
| 233 | int gb_ctrl_cmds_install(void); |
| 234 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 235 | |
| 236 | /* gb_proxy.c */ |
| 237 | int gbproxy_init_config(struct gbproxy_config *cfg); |
| 238 | |
| 239 | /* Main input function for Gb proxy */ |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 240 | int gbprox_rcvmsg(void *ctx, struct msgb *msg); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 241 | |
| 242 | int gbprox_signal(unsigned int subsys, unsigned int signal, |
| 243 | void *handler_data, void *signal_data); |
| 244 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 245 | |
| 246 | int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 247 | |
| 248 | void gbprox_reset(struct gbproxy_config *cfg); |
| 249 | |
| 250 | /* TLLI info handling */ |
| 251 | void gbproxy_delete_link_infos(struct gbproxy_peer *peer); |
| 252 | struct gbproxy_link_info *gbproxy_update_link_state_ul( |
| 253 | struct gbproxy_peer *peer, time_t now, |
| 254 | struct gprs_gb_parse_context *parse_ctx); |
| 255 | struct gbproxy_link_info *gbproxy_update_link_state_dl( |
| 256 | struct gbproxy_peer *peer, time_t now, |
| 257 | struct gprs_gb_parse_context *parse_ctx); |
| 258 | int gbproxy_update_link_state_after( |
| 259 | struct gbproxy_peer *peer, struct gbproxy_link_info *link_info, |
| 260 | time_t now, struct gprs_gb_parse_context *parse_ctx); |
| 261 | int gbproxy_remove_stale_link_infos(struct gbproxy_peer *peer, time_t now); |
| 262 | void gbproxy_delete_link_info(struct gbproxy_peer *peer, |
| 263 | struct gbproxy_link_info *link_info); |
| 264 | void gbproxy_link_info_discard_messages(struct gbproxy_link_info *link_info); |
| 265 | |
| 266 | void gbproxy_attach_link_info(struct gbproxy_peer *peer, time_t now, |
| 267 | struct gbproxy_link_info *link_info); |
| 268 | void gbproxy_update_link_info(struct gbproxy_link_info *link_info, |
| 269 | const uint8_t *imsi, size_t imsi_len); |
| 270 | void gbproxy_detach_link_info(struct gbproxy_peer *peer, |
| 271 | struct gbproxy_link_info *link_info); |
| 272 | struct gbproxy_link_info *gbproxy_link_info_alloc( struct gbproxy_peer *peer); |
| 273 | |
| 274 | struct gbproxy_link_info *gbproxy_link_info_by_tlli( |
| 275 | struct gbproxy_peer *peer, uint32_t tlli); |
| 276 | struct gbproxy_link_info *gbproxy_link_info_by_imsi( |
| 277 | struct gbproxy_peer *peer, const uint8_t *imsi, size_t imsi_len); |
| 278 | struct gbproxy_link_info *gbproxy_link_info_by_any_sgsn_tlli( |
| 279 | struct gbproxy_peer *peer, uint32_t tlli); |
| 280 | struct gbproxy_link_info *gbproxy_link_info_by_sgsn_tlli( |
| 281 | struct gbproxy_peer *peer, |
| 282 | uint32_t tlli, uint32_t sgsn_nsei); |
| 283 | struct gbproxy_link_info *gbproxy_link_info_by_ptmsi( |
| 284 | struct gbproxy_peer *peer, |
| 285 | uint32_t ptmsi); |
| 286 | |
| 287 | int gbproxy_imsi_matches( |
| 288 | struct gbproxy_config *cfg, |
| 289 | enum gbproxy_match_id match_id, |
| 290 | struct gbproxy_link_info *link_info); |
| 291 | uint32_t gbproxy_map_tlli( |
| 292 | uint32_t other_tlli, struct gbproxy_link_info *link_info, int to_bss); |
| 293 | |
| 294 | /* needed by gb_proxy_tlli.h */ |
| 295 | uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_peer *peer, uint32_t sgsn_ptmsi); |
| 296 | uint32_t gbproxy_make_sgsn_tlli( |
| 297 | struct gbproxy_peer *peer, struct gbproxy_link_info *link_info, |
| 298 | uint32_t bss_tlli); |
| 299 | void gbproxy_reset_link(struct gbproxy_link_info *link_info); |
| 300 | int gbproxy_check_imsi( |
| 301 | struct gbproxy_match *match, const uint8_t *imsi, size_t imsi_len); |
| 302 | |
| 303 | /* Message patching */ |
| 304 | void gbproxy_patch_bssgp( |
| 305 | struct msgb *msg, uint8_t *bssgp, size_t bssgp_len, |
| 306 | struct gbproxy_peer *peer, struct gbproxy_link_info *link_info, |
| 307 | int *len_change, struct gprs_gb_parse_context *parse_ctx); |
| 308 | |
| 309 | int gbproxy_patch_llc( |
| 310 | struct msgb *msg, uint8_t *llc, size_t llc_len, |
| 311 | struct gbproxy_peer *peer, struct gbproxy_link_info *link_info, |
| 312 | int *len_change, struct gprs_gb_parse_context *parse_ctx); |
| 313 | |
| 314 | int gbproxy_set_patch_filter( |
| 315 | struct gbproxy_match *match, const char *filter, const char **err_msg); |
| 316 | void gbproxy_clear_patch_filter(struct gbproxy_match *match); |
| 317 | |
| 318 | /* Peer handling */ |
| 319 | struct gbproxy_peer *gbproxy_peer_by_bvci( |
| 320 | struct gbproxy_config *cfg, uint16_t bvci); |
| 321 | struct gbproxy_peer *gbproxy_peer_by_nsei( |
| 322 | struct gbproxy_config *cfg, uint16_t nsei); |
| 323 | struct gbproxy_peer *gbproxy_peer_by_rai( |
| 324 | struct gbproxy_config *cfg, const uint8_t *ra); |
| 325 | struct gbproxy_peer *gbproxy_peer_by_lai( |
| 326 | struct gbproxy_config *cfg, const uint8_t *la); |
| 327 | struct gbproxy_peer *gbproxy_peer_by_lac( |
| 328 | struct gbproxy_config *cfg, const uint8_t *la); |
| 329 | struct gbproxy_peer *gbproxy_peer_by_bssgp_tlv( |
| 330 | struct gbproxy_config *cfg, struct tlv_parsed *tp); |
| 331 | struct gbproxy_peer *gbproxy_peer_alloc(struct gbproxy_config *cfg, uint16_t bvci); |
| 332 | void gbproxy_peer_free(struct gbproxy_peer *peer); |
| 333 | int gbproxy_cleanup_peers(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci); |
| 334 | |
| 335 | #endif |