blob: 4305d137d258c952fc471af4d9b6b9c550defbe9 [file] [log] [blame]
Harald Welte323e4f62010-05-01 11:28:43 +02001#ifndef _GB_PROXY_H
2#define _GB_PROXY_H
3
Harald Welte323e4f62010-05-01 11:28:43 +02004
Pablo Neira Ayusodd5fff42011-03-22 16:47:59 +01005#include <osmocom/core/msgb.h>
Harald Welte323e4f62010-05-01 11:28:43 +02006
Harald Weltecfb6b282012-06-16 14:59:56 +08007#include <osmocom/gprs/gprs_ns.h>
Harald Weltebd9591f2010-05-19 19:45:32 +02008#include <osmocom/vty/command.h>
Harald Welte323e4f62010-05-01 11:28:43 +02009
Holger Hans Peter Freyther5eaf1a22014-08-04 11:10:09 +020010struct rate_ctr_group;
11
Jacob Erlbeck0727f9a2014-05-28 10:59:10 +020012enum gbproxy_patch_mode {
13 GBPROX_PATCH_DEFAULT,
14 GBPROX_PATCH_BSSGP, /*!< BSGGP messages only */
15 GBPROX_PATCH_LLC_ATTACH_REQ, /*!< BSSGP and Attach Request */
16 GBPROX_PATCH_LLC_ATTACH, /*!< BSSGP and Attach Request/Response */
17 GBPROX_PATCH_LLC_GMM, /*!< BSSGP and all GMM msgs */
Jacob Erlbeck5620c6d2014-05-23 20:48:07 +020018 GBPROX_PATCH_LLC_GSM, /*!< BSSGP and all GMM and GSM msgs */
Jacob Erlbeck0727f9a2014-05-28 10:59:10 +020019 GBPROX_PATCH_LLC, /*!< BSSGP and all supported LLC msgs */
20};
21
Harald Welte323e4f62010-05-01 11:28:43 +020022struct gbproxy_config {
23 /* parsed from config file */
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +020024 uint16_t nsip_sgsn_nsei;
Harald Welte323e4f62010-05-01 11:28:43 +020025
26 /* misc */
27 struct gprs_ns_inst *nsi;
Jacob Erlbeck2504bc42014-05-19 10:14:58 +020028
Holger Hans Peter Freyther5eaf1a22014-08-04 11:10:09 +020029 /* Linked list of all Gb peers (except SGSN) */
30 struct llist_head bts_peers;
31
Jacob Erlbeck2504bc42014-05-19 10:14:58 +020032 /* force mcc/mnc */
33 int core_mnc;
34 int core_mcc;
Jacob Erlbeck5620c6d2014-05-23 20:48:07 +020035 uint8_t* core_apn;
36 size_t core_apn_size;
Jacob Erlbeck43037632014-06-06 18:49:23 +020037 char * match_re;
Jacob Erlbeck0727f9a2014-05-28 10:59:10 +020038 enum gbproxy_patch_mode patch_mode;
Jacob Erlbeck43037632014-06-06 18:49:23 +020039 int tlli_max_age;
40 int tlli_max_len;
Harald Welte323e4f62010-05-01 11:28:43 +020041};
42
Holger Hans Peter Freyther5eaf1a22014-08-04 11:10:09 +020043struct gbprox_patch_state {
44 int local_mnc;
45 int local_mcc;
46
47 /* List of TLLIs for which patching is enabled */
48 struct llist_head enabled_tllis;
49 int enabled_tllis_count;
50};
51
52struct gbprox_peer {
53 struct llist_head list;
54
55 /* NSEI of the peer entity */
56 uint16_t nsei;
57
58 /* BVCI used for Point-to-Point to this peer */
59 uint16_t bvci;
60 int blocked;
61
62 /* Routeing Area that this peer is part of (raw 04.08 encoding) */
63 uint8_t ra[6];
64
65 /* Counter */
66 struct rate_ctr_group *ctrg;
67
68 struct gbprox_patch_state patch_state;
69};
70
71struct gbprox_tlli_info {
72 struct llist_head list;
73
74 uint32_t tlli;
75 time_t timestamp;
76 uint8_t *mi_data;
77 size_t mi_data_len;
78};
79
80
Harald Weltef01709d2010-05-03 18:54:58 +020081extern struct gbproxy_config gbcfg;
Harald Welte323e4f62010-05-01 11:28:43 +020082
83/* gb_proxy_vty .c */
84
85int gbproxy_vty_init(void);
86int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg);
87
88
89/* gb_proxy.c */
Holger Hans Peter Freyther5eaf1a22014-08-04 11:10:09 +020090int gbproxy_init_config(struct gbproxy_config *cfg);
Harald Welte323e4f62010-05-01 11:28:43 +020091
92/* Main input function for Gb proxy */
Jacob Erlbecke48c3472013-10-15 12:00:27 +020093int gbprox_rcvmsg(struct msgb *msg, uint16_t nsei, uint16_t ns_bvci, uint16_t nsvci);
Harald Welte323e4f62010-05-01 11:28:43 +020094
Harald Welte5bb0d362010-05-11 06:34:24 +020095int gbprox_signal(unsigned int subsys, unsigned int signal,
96 void *handler_data, void *signal_data);
Harald Welte9ee404a2010-05-14 11:53:08 +000097
98/* Reset all persistent NS-VC's */
99int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi);
100
Jacob Erlbeckeed33ef2014-07-07 10:45:59 +0200101int gbprox_dump_global(FILE *stream, int indent);
102int gbprox_dump_peers(FILE *stream, int indent);
Jacob Erlbeck67f03bd2013-10-24 12:48:55 +0200103void gbprox_reset();
Jacob Erlbeck5620c6d2014-05-23 20:48:07 +0200104
105char *gbprox_apn_to_str(char *str, const uint8_t *apn_enc, size_t max_chars);
106int gbprox_str_to_apn(uint8_t *apn_enc, const char *str, size_t max_chars);
Jacob Erlbeck43037632014-06-06 18:49:23 +0200107
108int gbprox_set_patch_filter(const char *filter, const char **err_msg);
Holger Hans Peter Freyther5eaf1a22014-08-04 11:10:09 +0200109
110void gbprox_delete_tlli(struct gbprox_peer *peer,
111 struct gbprox_tlli_info *tlli_info);
112int gbprox_remove_stale_ttlis(struct gbprox_peer *peer, time_t now);
113int gbprox_cleanup_peers(uint16_t nsei, uint16_t bvci);
114
115/* tmp */
116struct rate_ctr_group *get_global_ctrg(void);
117struct gbprox_peer *peer_by_nsei(uint16_t nsei);
Harald Welte323e4f62010-05-01 11:28:43 +0200118#endif