Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 1 | #ifndef _GB_PROXY_H |
| 2 | #define _GB_PROXY_H |
| 3 | |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 4 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 5 | #include <osmocom/core/msgb.h> |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 6 | |
Harald Welte | cfb6b28 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 7 | #include <osmocom/gprs/gprs_ns.h> |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 8 | #include <osmocom/vty/command.h> |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 9 | |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame^] | 10 | struct rate_ctr_group; |
| 11 | |
Jacob Erlbeck | 0727f9a | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 12 | enum 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 Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 18 | GBPROX_PATCH_LLC_GSM, /*!< BSSGP and all GMM and GSM msgs */ |
Jacob Erlbeck | 0727f9a | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 19 | GBPROX_PATCH_LLC, /*!< BSSGP and all supported LLC msgs */ |
| 20 | }; |
| 21 | |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 22 | struct gbproxy_config { |
| 23 | /* parsed from config file */ |
Holger Hans Peter Freyther | 7eb8a9a | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 24 | uint16_t nsip_sgsn_nsei; |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 25 | |
| 26 | /* misc */ |
| 27 | struct gprs_ns_inst *nsi; |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 28 | |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame^] | 29 | /* Linked list of all Gb peers (except SGSN) */ |
| 30 | struct llist_head bts_peers; |
| 31 | |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 32 | /* force mcc/mnc */ |
| 33 | int core_mnc; |
| 34 | int core_mcc; |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 35 | uint8_t* core_apn; |
| 36 | size_t core_apn_size; |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 37 | char * match_re; |
Jacob Erlbeck | 0727f9a | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 38 | enum gbproxy_patch_mode patch_mode; |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 39 | int tlli_max_age; |
| 40 | int tlli_max_len; |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 41 | }; |
| 42 | |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame^] | 43 | struct 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 | |
| 52 | struct 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 | |
| 71 | struct 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 Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 81 | extern struct gbproxy_config gbcfg; |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 82 | |
| 83 | /* gb_proxy_vty .c */ |
| 84 | |
| 85 | int gbproxy_vty_init(void); |
| 86 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg); |
| 87 | |
| 88 | |
| 89 | /* gb_proxy.c */ |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame^] | 90 | int gbproxy_init_config(struct gbproxy_config *cfg); |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 91 | |
| 92 | /* Main input function for Gb proxy */ |
Jacob Erlbeck | e48c347 | 2013-10-15 12:00:27 +0200 | [diff] [blame] | 93 | int gbprox_rcvmsg(struct msgb *msg, uint16_t nsei, uint16_t ns_bvci, uint16_t nsvci); |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 94 | |
Harald Welte | 5bb0d36 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 95 | int gbprox_signal(unsigned int subsys, unsigned int signal, |
| 96 | void *handler_data, void *signal_data); |
Harald Welte | 9ee404a | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 97 | |
| 98 | /* Reset all persistent NS-VC's */ |
| 99 | int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi); |
| 100 | |
Jacob Erlbeck | eed33ef | 2014-07-07 10:45:59 +0200 | [diff] [blame] | 101 | int gbprox_dump_global(FILE *stream, int indent); |
| 102 | int gbprox_dump_peers(FILE *stream, int indent); |
Jacob Erlbeck | 67f03bd | 2013-10-24 12:48:55 +0200 | [diff] [blame] | 103 | void gbprox_reset(); |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 104 | |
| 105 | char *gbprox_apn_to_str(char *str, const uint8_t *apn_enc, size_t max_chars); |
| 106 | int gbprox_str_to_apn(uint8_t *apn_enc, const char *str, size_t max_chars); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 107 | |
| 108 | int gbprox_set_patch_filter(const char *filter, const char **err_msg); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame^] | 109 | |
| 110 | void gbprox_delete_tlli(struct gbprox_peer *peer, |
| 111 | struct gbprox_tlli_info *tlli_info); |
| 112 | int gbprox_remove_stale_ttlis(struct gbprox_peer *peer, time_t now); |
| 113 | int gbprox_cleanup_peers(uint16_t nsei, uint16_t bvci); |
| 114 | |
| 115 | /* tmp */ |
| 116 | struct rate_ctr_group *get_global_ctrg(void); |
| 117 | struct gbprox_peer *peer_by_nsei(uint16_t nsei); |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 118 | #endif |