Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 1 | #ifndef _SGSN_H |
| 2 | #define _SGSN_H |
| 3 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 4 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 5 | #include <osmocom/core/msgb.h> |
Max | 93408ae | 2016-06-28 14:10:16 +0200 | [diff] [blame] | 6 | #include <osmocom/crypt/gprs_cipher.h> |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 7 | #include <osmocom/gprs/gprs_ns.h> |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 8 | #include <osmocom/sgsn/gprs_sgsn.h> |
| 9 | #include <osmocom/sgsn/oap_client.h> |
| 10 | #include <osmocom/sgsn/common.h> |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 11 | |
Holger Hans Peter Freyther | 66e7106 | 2015-05-25 01:21:50 +0800 | [diff] [blame] | 12 | #include <ares.h> |
Max | c005db7 | 2017-10-27 18:43:29 +0200 | [diff] [blame^] | 13 | #include <gtp.h> |
Holger Hans Peter Freyther | 66e7106 | 2015-05-25 01:21:50 +0800 | [diff] [blame] | 14 | |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 15 | struct gprs_gsup_client; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 16 | struct hostent; |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 17 | |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 18 | enum sgsn_auth_policy { |
| 19 | SGSN_AUTH_POLICY_OPEN, |
| 20 | SGSN_AUTH_POLICY_CLOSED, |
Jacob Erlbeck | be2c8d9 | 2014-11-12 10:18:09 +0100 | [diff] [blame] | 21 | SGSN_AUTH_POLICY_ACL_ONLY, |
| 22 | SGSN_AUTH_POLICY_REMOTE |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
Alexander Couzens | 14314bd | 2016-07-05 09:52:52 +0200 | [diff] [blame] | 25 | |
| 26 | enum sgsn_rate_ctr_keys { |
Alexander Couzens | 4e699a9 | 2016-07-05 11:04:27 +0200 | [diff] [blame] | 27 | CTR_LLC_DL_BYTES, |
| 28 | CTR_LLC_UL_BYTES, |
| 29 | CTR_LLC_DL_PACKETS, |
| 30 | CTR_LLC_UL_PACKETS, |
Alexander Couzens | 14314bd | 2016-07-05 09:52:52 +0200 | [diff] [blame] | 31 | CTR_GPRS_ATTACH_REQUEST, |
| 32 | CTR_GPRS_ATTACH_ACKED, |
| 33 | CTR_GPRS_ATTACH_REJECTED, |
| 34 | CTR_GPRS_DETACH_REQUEST, |
| 35 | CTR_GPRS_DETACH_ACKED, |
| 36 | CTR_GPRS_ROUTING_AREA_REQUEST, |
| 37 | CTR_GPRS_ROUTING_AREA_ACKED, |
| 38 | CTR_GPRS_ROUTING_AREA_REJECT, |
| 39 | /* PDP single packet counter / GSM 04.08 9.5.1 - 9.5.9 */ |
| 40 | CTR_PDP_ACTIVATE_REQUEST, |
| 41 | CTR_PDP_ACTIVATE_REJECT, |
| 42 | CTR_PDP_ACTIVATE_ACCEPT, |
| 43 | CTR_PDP_REQUEST_ACTIVATE, /* unused */ |
| 44 | CTR_PDP_REQUEST_ACTIVATE_REJ, /* unused */ |
| 45 | CTR_PDP_MODIFY_REQUEST, /* unsued */ |
| 46 | CTR_PDP_MODIFY_ACCEPT, /* unused */ |
| 47 | CTR_PDP_DL_DEACTIVATE_REQUEST, |
| 48 | CTR_PDP_DL_DEACTIVATE_ACCEPT, |
| 49 | CTR_PDP_UL_DEACTIVATE_REQUEST, |
| 50 | CTR_PDP_UL_DEACTIVATE_ACCEPT, |
| 51 | }; |
| 52 | |
Holger Hans Peter Freyther | 4f5b823 | 2015-05-05 22:25:48 +0200 | [diff] [blame] | 53 | struct sgsn_cdr { |
| 54 | char *filename; |
| 55 | int interval; |
| 56 | }; |
| 57 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 58 | struct sgsn_config { |
| 59 | /* parsed from config file */ |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 60 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 61 | char *gtp_statedir; |
| 62 | struct sockaddr_in gtp_listenaddr; |
| 63 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 64 | /* misc */ |
| 65 | struct gprs_ns_inst *nsi; |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 66 | |
Jacob Erlbeck | 106f547 | 2014-11-04 10:08:37 +0100 | [diff] [blame] | 67 | enum sgsn_auth_policy auth_policy; |
Max | 93408ae | 2016-06-28 14:10:16 +0200 | [diff] [blame] | 68 | enum gprs_ciph_algo cipher; |
Harald Welte | 7f6da48 | 2013-03-19 11:00:13 +0100 | [diff] [blame] | 69 | struct llist_head imsi_acl; |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 70 | |
| 71 | struct sockaddr_in gsup_server_addr; |
| 72 | int gsup_server_port; |
Jacob Erlbeck | 9d4f46c | 2014-12-17 13:20:08 +0100 | [diff] [blame] | 73 | |
| 74 | int require_authentication; |
Jacob Erlbeck | 771573c | 2014-12-19 18:08:48 +0100 | [diff] [blame] | 75 | int require_update_location; |
Holger Hans Peter Freyther | 4f5b823 | 2015-05-05 22:25:48 +0200 | [diff] [blame] | 76 | |
| 77 | /* CDR configuration */ |
| 78 | struct sgsn_cdr cdr; |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 79 | |
Harald Welte | 9450882 | 2015-08-15 19:08:21 +0200 | [diff] [blame] | 80 | struct { |
| 81 | int T3312; |
| 82 | int T3322; |
| 83 | int T3350; |
| 84 | int T3360; |
| 85 | int T3370; |
| 86 | int T3313; |
| 87 | int T3314; |
| 88 | int T3316; |
| 89 | int T3385; |
| 90 | int T3386; |
| 91 | int T3395; |
| 92 | int T3397; |
| 93 | } timers; |
| 94 | |
Holger Hans Peter Freyther | 39c430e | 2015-05-25 12:26:49 +0800 | [diff] [blame] | 95 | int dynamic_lookup; |
Neels Hofmeyr | 9c534fd | 2015-10-12 11:57:37 +0200 | [diff] [blame] | 96 | |
Neels Hofmeyr | 49012f1 | 2016-12-08 21:30:34 +0100 | [diff] [blame] | 97 | struct oap_client_config oap; |
Philipp | f1f3436 | 2016-08-26 17:00:21 +0200 | [diff] [blame] | 98 | |
| 99 | /* RFC1144 TCP/IP header compression */ |
| 100 | struct { |
| 101 | int active; |
| 102 | int passive; |
| 103 | int s01; |
| 104 | } pcomp_rfc1144; |
Philipp | 73f83d5 | 2016-09-02 13:38:01 +0200 | [diff] [blame] | 105 | |
| 106 | /* V.42vis data compression */ |
| 107 | struct { |
| 108 | int active; |
| 109 | int passive; |
| 110 | int p0; |
| 111 | int p1; |
| 112 | int p2; |
| 113 | } dcomp_v42bis; |
Neels Hofmeyr | 2188a77 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 114 | |
| 115 | struct { |
Neels Hofmeyr | a7a3947 | 2017-07-05 15:19:52 +0200 | [diff] [blame] | 116 | int rab_assign_addr_enc; |
Neels Hofmeyr | 2188a77 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 117 | } iu; |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 120 | struct sgsn_instance { |
| 121 | char *config_file; |
| 122 | struct sgsn_config cfg; |
| 123 | /* File descriptor wrappers for LibGTP */ |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 124 | struct osmo_fd gtp_fd0; |
| 125 | struct osmo_fd gtp_fd1c; |
| 126 | struct osmo_fd gtp_fd1u; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 127 | /* Timer for libGTP */ |
Pablo Neira Ayuso | bf540cb | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 128 | struct osmo_timer_list gtp_timer; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 129 | /* GSN instance for libgtp */ |
| 130 | struct gsn_t *gsn; |
Jacob Erlbeck | 39f040d | 2014-12-18 12:46:47 +0100 | [diff] [blame] | 131 | /* Subscriber */ |
Neels Hofmeyr | 814fef0 | 2016-12-08 21:19:57 +0100 | [diff] [blame] | 132 | struct gsup_client *gsup_client; |
Jacob Erlbeck | 81ffb74 | 2015-01-23 11:33:51 +0100 | [diff] [blame] | 133 | /* LLME inactivity timer */ |
| 134 | struct osmo_timer_list llme_timer; |
Holger Hans Peter Freyther | 66e7106 | 2015-05-25 01:21:50 +0800 | [diff] [blame] | 135 | |
| 136 | /* c-ares event loop integration */ |
| 137 | struct osmo_timer_list ares_timer; |
| 138 | struct llist_head ares_fds; |
| 139 | ares_channel ares_channel; |
Holger Hans Peter Freyther | a5a6da4 | 2015-05-25 15:20:27 +0800 | [diff] [blame] | 140 | struct ares_addr_node *ares_servers; |
Alexander Couzens | 14314bd | 2016-07-05 09:52:52 +0200 | [diff] [blame] | 141 | |
| 142 | struct rate_ctr_group *rate_ctrs; |
Harald Welte | 2720e73 | 2010-05-17 00:44:57 +0200 | [diff] [blame] | 143 | }; |
| 144 | |
Harald Welte | 8fc1a46 | 2010-05-17 00:53:10 +0200 | [diff] [blame] | 145 | extern struct sgsn_instance *sgsn; |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 146 | |
| 147 | /* sgsn_vty.c */ |
| 148 | |
Neels Hofmeyr | c9a352f | 2017-07-20 14:41:20 +0200 | [diff] [blame] | 149 | int sgsn_vty_init(struct sgsn_config *cfg); |
| 150 | int sgsn_parse_config(const char *config_file); |
Max | c005db7 | 2017-10-27 18:43:29 +0200 | [diff] [blame^] | 151 | char *sgsn_gtp_ntoa(struct ul16_t *ul); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 152 | |
| 153 | /* sgsn.c */ |
| 154 | |
| 155 | /* Main input function for Gb proxy */ |
| 156 | int sgsn_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci); |
| 157 | |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 158 | |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 159 | struct sgsn_pdp_ctx *sgsn_create_pdp_ctx(struct sgsn_ggsn_ctx *ggsn, |
Harald Welte | 6abf94e | 2010-05-18 10:35:06 +0200 | [diff] [blame] | 160 | struct sgsn_mm_ctx *mmctx, |
| 161 | uint16_t nsapi, |
| 162 | struct tlv_parsed *tp); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 163 | int sgsn_delete_pdp_ctx(struct sgsn_pdp_ctx *pctx); |
Daniel Willmann | 21b269f | 2016-05-11 12:43:47 +0200 | [diff] [blame] | 164 | void sgsn_pdp_upd_gtp_u(struct sgsn_pdp_ctx *pdp, void *addr, size_t alen); |
Harald Welte | 77289c2 | 2010-05-18 14:32:29 +0200 | [diff] [blame] | 165 | |
Harald Welte | ebabdea | 2010-06-01 18:28:10 +0200 | [diff] [blame] | 166 | /* gprs_sndcp.c */ |
| 167 | |
| 168 | /* Entry point for the SNSM-ACTIVATE.indication */ |
| 169 | int sndcp_sm_activate_ind(struct gprs_llc_lle *lle, uint8_t nsapi); |
Harald Welte | ce22f92 | 2010-06-03 21:21:21 +0200 | [diff] [blame] | 170 | /* Entry point for the SNSM-DEACTIVATE.indication */ |
| 171 | int sndcp_sm_deactivate_ind(struct gprs_llc_lle *lle, uint8_t nsapi); |
Harald Welte | ebabdea | 2010-06-01 18:28:10 +0200 | [diff] [blame] | 172 | /* Called by SNDCP when it has received/re-assembled a N-PDU */ |
Harald Welte | 8911cef | 2010-07-01 19:56:19 +0200 | [diff] [blame] | 173 | int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi, |
| 174 | struct msgb *msg, uint32_t npdu_len, uint8_t *npdu); |
Harald Welte | bb1c805 | 2010-06-03 06:38:38 +0200 | [diff] [blame] | 175 | int sndcp_unitdata_req(struct msgb *msg, struct gprs_llc_lle *lle, uint8_t nsapi, |
| 176 | void *mmcontext); |
Holger Hans Peter Freyther | 3dccda5 | 2011-10-14 23:42:13 +0200 | [diff] [blame] | 177 | int sndcp_llunitdata_ind(struct msgb *msg, struct gprs_llc_lle *lle, |
| 178 | uint8_t *hdr, uint16_t len); |
Harald Welte | ebabdea | 2010-06-01 18:28:10 +0200 | [diff] [blame] | 179 | |
Holger Hans Peter Freyther | 4f5b823 | 2015-05-05 22:25:48 +0200 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | * CDR related functionality |
| 183 | */ |
| 184 | int sgsn_cdr_init(struct sgsn_instance *sgsn); |
| 185 | |
Holger Hans Peter Freyther | 66e7106 | 2015-05-25 01:21:50 +0800 | [diff] [blame] | 186 | |
| 187 | /* |
| 188 | * C-ARES related functionality |
| 189 | */ |
| 190 | int sgsn_ares_init(struct sgsn_instance *sgsn); |
| 191 | int sgsn_ares_query(struct sgsn_instance *sgsm, const char *name, ares_host_callback cb, void *data); |
| 192 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 193 | #endif |