blob: 09ac83657bde9c863b8bbd1bb234d9adbbe8d281 [file] [log] [blame]
Harald Welteb77c6972010-05-01 11:28:43 +02001#ifndef _GB_PROXY_H
2#define _GB_PROXY_H
3
Harald Welteb77c6972010-05-01 11:28:43 +02004
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +01005#include <osmocom/core/msgb.h>
Harald Welteb77c6972010-05-01 11:28:43 +02006
Harald Welteea34a4e2012-06-16 14:59:56 +08007#include <osmocom/gprs/gprs_ns.h>
Harald Welte4b037e42010-05-19 19:45:32 +02008#include <osmocom/vty/command.h>
Harald Welteb77c6972010-05-01 11:28:43 +02009
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020010struct rate_ctr_group;
11
Jacob Erlbeck91fb6802014-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 Erlbeck73685282014-05-23 20:48:07 +020018 GBPROX_PATCH_LLC_GSM, /*!< BSSGP and all GMM and GSM msgs */
Jacob Erlbeck91fb6802014-05-28 10:59:10 +020019 GBPROX_PATCH_LLC, /*!< BSSGP and all supported LLC msgs */
20};
21
Harald Welteb77c6972010-05-01 11:28:43 +020022struct gbproxy_config {
23 /* parsed from config file */
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020024 uint16_t nsip_sgsn_nsei;
Harald Welteb77c6972010-05-01 11:28:43 +020025
26 /* misc */
27 struct gprs_ns_inst *nsi;
Jacob Erlbeck67a44452014-05-19 10:14:58 +020028
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020029 /* Linked list of all Gb peers (except SGSN) */
30 struct llist_head bts_peers;
31
Holger Hans Peter Freythera7027a02014-08-04 11:19:56 +020032 /* Counter */
33 struct rate_ctr_group *ctrg;
34
Jacob Erlbeck67a44452014-05-19 10:14:58 +020035 /* force mcc/mnc */
36 int core_mnc;
37 int core_mcc;
Jacob Erlbeck73685282014-05-23 20:48:07 +020038 uint8_t* core_apn;
39 size_t core_apn_size;
Jacob Erlbeck7c101d92014-06-06 18:49:23 +020040 char * match_re;
Jacob Erlbeck91fb6802014-05-28 10:59:10 +020041 enum gbproxy_patch_mode patch_mode;
Jacob Erlbeck7c101d92014-06-06 18:49:23 +020042 int tlli_max_age;
43 int tlli_max_len;
Harald Welteb77c6972010-05-01 11:28:43 +020044};
45
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020046struct gbprox_patch_state {
47 int local_mnc;
48 int local_mcc;
49
50 /* List of TLLIs for which patching is enabled */
51 struct llist_head enabled_tllis;
52 int enabled_tllis_count;
53};
54
55struct gbprox_peer {
56 struct llist_head list;
57
58 /* NSEI of the peer entity */
59 uint16_t nsei;
60
61 /* BVCI used for Point-to-Point to this peer */
62 uint16_t bvci;
63 int blocked;
64
65 /* Routeing Area that this peer is part of (raw 04.08 encoding) */
66 uint8_t ra[6];
67
68 /* Counter */
69 struct rate_ctr_group *ctrg;
70
71 struct gbprox_patch_state patch_state;
72};
73
74struct gbprox_tlli_info {
75 struct llist_head list;
76
77 uint32_t tlli;
78 time_t timestamp;
79 uint8_t *mi_data;
80 size_t mi_data_len;
81};
82
83
Harald Welte672f5c42010-05-03 18:54:58 +020084extern struct gbproxy_config gbcfg;
Harald Welteb77c6972010-05-01 11:28:43 +020085
86/* gb_proxy_vty .c */
87
88int gbproxy_vty_init(void);
89int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg);
90
91
92/* gb_proxy.c */
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020093int gbproxy_init_config(struct gbproxy_config *cfg);
Harald Welteb77c6972010-05-01 11:28:43 +020094
95/* Main input function for Gb proxy */
Jacob Erlbecke75fec62013-10-15 12:00:27 +020096int gbprox_rcvmsg(struct msgb *msg, uint16_t nsei, uint16_t ns_bvci, uint16_t nsvci);
Harald Welteb77c6972010-05-01 11:28:43 +020097
Harald Weltec1c1dd22010-05-11 06:34:24 +020098int gbprox_signal(unsigned int subsys, unsigned int signal,
99 void *handler_data, void *signal_data);
Harald Welte1ccbf442010-05-14 11:53:08 +0000100
101/* Reset all persistent NS-VC's */
102int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi);
103
Jacob Erlbeckb32d3c02014-07-07 10:45:59 +0200104int gbprox_dump_global(FILE *stream, int indent);
105int gbprox_dump_peers(FILE *stream, int indent);
Jacob Erlbeck72b401f2013-10-24 12:48:55 +0200106void gbprox_reset();
Jacob Erlbeck73685282014-05-23 20:48:07 +0200107
108char *gbprox_apn_to_str(char *str, const uint8_t *apn_enc, size_t max_chars);
109int gbprox_str_to_apn(uint8_t *apn_enc, const char *str, size_t max_chars);
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200110
111int gbprox_set_patch_filter(const char *filter, const char **err_msg);
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +0200112
113void gbprox_delete_tlli(struct gbprox_peer *peer,
114 struct gbprox_tlli_info *tlli_info);
Holger Hans Peter Freytherd4d36f22014-08-04 11:14:54 +0200115int gbprox_remove_stale_tllis(struct gbprox_peer *peer, time_t now);
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +0200116int gbprox_cleanup_peers(uint16_t nsei, uint16_t bvci);
117
118/* tmp */
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +0200119struct gbprox_peer *peer_by_nsei(uint16_t nsei);
Harald Welteb77c6972010-05-01 11:28:43 +0200120#endif