Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1 | /*! \file gprs_ns2.h */ |
| 2 | |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include <stdint.h> |
| 7 | #include <netinet/in.h> |
| 8 | |
| 9 | #include <osmocom/core/prim.h> |
Alexander Couzens | b3b837c | 2020-10-27 15:12:25 +0100 | [diff] [blame] | 10 | #include <osmocom/gprs/protocol/gsm_08_16.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 11 | |
| 12 | struct osmo_sockaddr; |
Alexander Couzens | 1fac6f7 | 2020-10-01 19:08:38 +0200 | [diff] [blame] | 13 | struct osmo_sockaddr_str; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 14 | |
| 15 | struct gprs_ns2_inst; |
| 16 | struct gprs_ns2_nse; |
| 17 | struct gprs_ns2_vc; |
| 18 | struct gprs_ns2_vc_bind; |
| 19 | struct gprs_ns2_vc_driver; |
| 20 | struct gprs_ns_ie_ip4_elem; |
| 21 | struct gprs_ns_ie_ip6_elem; |
| 22 | |
| 23 | enum gprs_ns2_vc_mode { |
Harald Welte | fa2d66c | 2020-10-17 13:09:34 +0200 | [diff] [blame] | 24 | /*! The VC will use RESET/BLOCK/UNBLOCK to start the connection and do ALIVE/ACK. |
| 25 | * This is what is needed for Frame Relay transport, and if you use a R97/R99 Gb |
| 26 | * interface over an IP transport (never standardized by 3GPP) */ |
| 27 | NS2_VC_MODE_BLOCKRESET, |
| 28 | /*! The VC will only use ALIVE/ACK (no RESET/BLOCK/UNBLOCK), which is for Gb-IP |
| 29 | * interface compliant to 3GPP Rel=4 or later. */ |
| 30 | NS2_VC_MODE_ALIVE, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
| 33 | /*! Osmocom NS primitives according to 48.016 5.2 Service primitves */ |
| 34 | enum gprs_ns2_prim { |
| 35 | PRIM_NS_UNIT_DATA, |
| 36 | PRIM_NS_CONGESTION, |
| 37 | PRIM_NS_STATUS, |
| 38 | }; |
| 39 | |
Alexander Couzens | 0ab028c | 2020-11-04 02:41:44 +0100 | [diff] [blame] | 40 | extern const struct value_string gprs_ns2_prim_strs[]; |
Alexander Couzens | 2498f1d | 2020-10-27 01:09:01 +0100 | [diff] [blame] | 41 | |
| 42 | /*! Obtain a human-readable string for NS primitives */ |
| 43 | static inline const char *gprs_ns2_prim_str(enum gprs_ns2_prim val) |
Alexander Couzens | 0ab028c | 2020-11-04 02:41:44 +0100 | [diff] [blame] | 44 | { return get_value_string(gprs_ns2_prim_strs, val); } |
Alexander Couzens | 2498f1d | 2020-10-27 01:09:01 +0100 | [diff] [blame] | 45 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 46 | /*! Osmocom NS primitives according to 48.016 5.2.2.4 Service primitves */ |
| 47 | enum gprs_ns2_congestion_cause { |
| 48 | NS_CONG_CAUSE_BACKWARD_BEGIN, |
| 49 | NS_CONG_CAUSE_BACKWARD_END, |
| 50 | NS_CONG_CAUSE_FORWARD_BEGIN, |
| 51 | NS_CONG_CAUSE_FORWARD_END, |
| 52 | }; |
| 53 | |
| 54 | /*! Osmocom NS primitives according to 48.016 5.2.2.6 Service primitves */ |
| 55 | enum gprs_ns2_affecting_cause { |
| 56 | NS_AFF_CAUSE_VC_FAILURE, |
| 57 | NS_AFF_CAUSE_VC_RECOVERY, |
| 58 | NS_AFF_CAUSE_FAILURE, |
| 59 | NS_AFF_CAUSE_RECOVERY, |
| 60 | /* osmocom own causes */ |
| 61 | NS_AFF_CAUSE_SNS_CONFIGURED, |
| 62 | NS_AFF_CAUSE_SNS_FAILURE, |
| 63 | }; |
| 64 | |
Alexander Couzens | 2498f1d | 2020-10-27 01:09:01 +0100 | [diff] [blame] | 65 | extern const struct value_string gprs_ns2_aff_cause_prim_strs[]; |
| 66 | |
| 67 | /*! Obtain a human-readable string for NS affective cause in primitives */ |
| 68 | static inline const char *gprs_ns2_aff_cause_prim_str(enum gprs_ns2_affecting_cause val) |
| 69 | { return get_value_string(gprs_ns2_aff_cause_prim_strs, val); } |
| 70 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 71 | /*! Osmocom NS primitives according to 48.016 5.2.2.7 Service primitves */ |
| 72 | enum gprs_ns2_change_ip_endpoint { |
| 73 | NS_ENDPOINT_NO_CHANGE, |
| 74 | NS_ENDPOINT_REQUEST_CHANGE, |
| 75 | NS_ENDPOINT_CONFIRM_CHANGE, |
| 76 | }; |
| 77 | |
Alexander Couzens | b3b837c | 2020-10-27 15:12:25 +0100 | [diff] [blame] | 78 | extern const struct value_string gprs_ns2_cause_strs[]; |
| 79 | |
| 80 | /*! Obtain a human-readable string for NS primitives */ |
| 81 | static inline const char *gprs_ns2_cause_str(enum ns_cause val) |
| 82 | { return get_value_string(gprs_ns2_cause_strs, val); } |
| 83 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 84 | struct osmo_gprs_ns2_prim { |
| 85 | struct osmo_prim_hdr oph; |
| 86 | |
| 87 | uint16_t nsei; |
| 88 | uint16_t bvci; |
| 89 | |
| 90 | union { |
| 91 | struct { |
| 92 | enum gprs_ns2_change_ip_endpoint change; |
| 93 | /* TODO: implement resource distribution |
| 94 | * add place holder for the link selector */ |
| 95 | long long _resource_distribution_placeholder1; |
| 96 | long long _resource_distribution_placeholder2; |
| 97 | long long _resource_distribution_placeholder3; |
| 98 | } unitdata; |
| 99 | struct { |
| 100 | enum gprs_ns2_congestion_cause cause; |
| 101 | } congestion; |
| 102 | struct { |
| 103 | enum gprs_ns2_affecting_cause cause; |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 104 | char *nsvc; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 105 | /* 48.016 5.2.2.6 transfer capability */ |
| 106 | int transfer; |
Alexander Couzens | da0a285 | 2020-10-01 23:24:07 +0200 | [diff] [blame] | 107 | /* osmocom specific */ |
| 108 | /* Persistent NSE/NSVC are configured by vty */ |
| 109 | bool persistent; |
| 110 | /* Only true on the first time it's available. |
| 111 | * Allow the BSSGP layer to reset persistent NSE */ |
| 112 | bool first; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 113 | } status; |
| 114 | } u; |
| 115 | }; |
| 116 | |
| 117 | /* instance */ |
| 118 | struct gprs_ns2_inst *gprs_ns2_instantiate(void *ctx, osmo_prim_cb cb, void *cb_data); |
| 119 | void gprs_ns2_free(struct gprs_ns2_inst *inst); |
| 120 | int gprs_ns2_dynamic_create_nse(struct gprs_ns2_inst *nsi, bool create_nse); |
| 121 | |
| 122 | /* Entrypoint for primitives from the NS USER */ |
| 123 | int gprs_ns2_recv_prim(struct gprs_ns2_inst *nsi, struct osmo_prim_hdr *oph); |
| 124 | |
Alexander Couzens | 6cb5d5f | 2020-10-11 23:23:31 +0200 | [diff] [blame] | 125 | /*! a callback to iterate over all NSVC */ |
| 126 | typedef int (*gprs_ns2_foreach_nsvc_cb)(struct gprs_ns2_vc *nsvc, void *ctx); |
| 127 | |
| 128 | int gprs_ns2_nse_foreach_nsvc(struct gprs_ns2_nse *nse, |
| 129 | gprs_ns2_foreach_nsvc_cb cb, void *cb_data); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 130 | struct gprs_ns2_nse *gprs_ns2_nse_by_nsei(struct gprs_ns2_inst *nsi, uint16_t nsei); |
| 131 | struct gprs_ns2_nse *gprs_ns2_create_nse(struct gprs_ns2_inst *nsi, uint16_t nsei); |
Alexander Couzens | 05e7f7d | 2020-10-11 19:51:46 +0200 | [diff] [blame] | 132 | uint16_t gprs_ns2_nse_nsei(struct gprs_ns2_nse *nse); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 133 | void gprs_ns2_free_nse(struct gprs_ns2_nse *nse); |
Alexander Couzens | 4b6c8af | 2020-10-11 20:15:25 +0200 | [diff] [blame] | 134 | void gprs_ns2_free_nses(struct gprs_ns2_inst *nsi); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 135 | |
| 136 | /* create vc */ |
| 137 | void gprs_ns2_free_nsvc(struct gprs_ns2_vc *nsvc); |
| 138 | struct gprs_ns2_vc *gprs_ns2_nsvc_by_nsvci(struct gprs_ns2_inst *nsi, uint16_t nsvci); |
| 139 | |
| 140 | /* IP VL driver */ |
| 141 | int gprs_ns2_ip_bind(struct gprs_ns2_inst *nsi, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 142 | const struct osmo_sockaddr *local, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 143 | int dscp, |
| 144 | struct gprs_ns2_vc_bind **result); |
Alexander Couzens | 4f60845 | 2020-10-11 18:41:24 +0200 | [diff] [blame] | 145 | struct gprs_ns2_vc_bind *gprs_ns2_ip_bind_by_sockaddr(struct gprs_ns2_inst *nsi, |
| 146 | const struct osmo_sockaddr *sockaddr); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 147 | void gprs_ns2_bind_set_mode(struct gprs_ns2_vc_bind *bind, enum gprs_ns2_vc_mode mode); |
| 148 | |
| 149 | /* create a VC connection */ |
| 150 | struct gprs_ns2_vc *gprs_ns2_ip_connect(struct gprs_ns2_vc_bind *bind, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 151 | const struct osmo_sockaddr *remote, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 152 | struct gprs_ns2_nse *nse, |
| 153 | uint16_t nsvci); |
| 154 | |
| 155 | struct gprs_ns2_vc *gprs_ns2_ip_connect2(struct gprs_ns2_vc_bind *bind, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 156 | const struct osmo_sockaddr *remote, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 157 | uint16_t nsei, |
| 158 | uint16_t nsvci); |
| 159 | struct gprs_ns2_vc *gprs_ns2_ip_connect_inactive(struct gprs_ns2_vc_bind *bind, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 160 | const struct osmo_sockaddr *remote, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 161 | struct gprs_ns2_nse *nse, |
| 162 | uint16_t nsvci); |
| 163 | |
| 164 | void gprs_ns2_free_bind(struct gprs_ns2_vc_bind *bind); |
Alexander Couzens | 896fcd5 | 2020-10-11 19:52:36 +0200 | [diff] [blame] | 165 | void gprs_ns2_free_binds(struct gprs_ns2_inst *nsi); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 166 | |
| 167 | /* create a VC SNS connection */ |
| 168 | int gprs_ns2_ip_connect_sns(struct gprs_ns2_vc_bind *bind, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 169 | const struct osmo_sockaddr *remote, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 170 | uint16_t nsei); |
Alexander Couzens | 125298f | 2020-10-11 21:22:42 +0200 | [diff] [blame] | 171 | const struct osmo_sockaddr *gprs_ns2_nse_sns_remote(struct gprs_ns2_nse *nse); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 172 | |
Alexander Couzens | d33512b | 2020-10-11 21:42:11 +0200 | [diff] [blame] | 173 | const struct osmo_sockaddr *gprs_ns2_ip_vc_remote(const struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 979f5f5 | 2020-10-11 21:01:48 +0200 | [diff] [blame] | 174 | const struct osmo_sockaddr *gprs_ns2_ip_vc_local(const struct gprs_ns2_vc *nsvc); |
Alexander Couzens | d420ea9 | 2020-10-12 01:11:05 +0200 | [diff] [blame] | 175 | bool gprs_ns2_ip_vc_equal(const struct gprs_ns2_vc *nsvc, |
| 176 | const struct osmo_sockaddr *local, |
| 177 | const struct osmo_sockaddr *remote, |
| 178 | uint16_t nsvci); |
Alexander Couzens | 9a4cf27 | 2020-10-11 20:48:04 +0200 | [diff] [blame] | 179 | const struct osmo_sockaddr *gprs_ns2_ip_bind_sockaddr(struct gprs_ns2_vc_bind *bind); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 180 | int gprs_ns2_is_ip_bind(struct gprs_ns2_vc_bind *bind); |
| 181 | int gprs_ns2_ip_bind_set_dscp(struct gprs_ns2_vc_bind *bind, int dscp); |
Alexander Couzens | 38b19e8 | 2020-09-23 23:56:37 +0200 | [diff] [blame] | 182 | struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_bind( |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 183 | struct gprs_ns2_vc_bind *bind, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 184 | const struct osmo_sockaddr *saddr); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 185 | |
| 186 | int gprs_ns2_frgre_bind(struct gprs_ns2_inst *nsi, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 187 | const struct osmo_sockaddr *local, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 188 | int dscp, |
| 189 | struct gprs_ns2_vc_bind **result); |
| 190 | int gprs_ns2_is_frgre_bind(struct gprs_ns2_vc_bind *bind); |
| 191 | |
Alexander Couzens | 38b19e8 | 2020-09-23 23:56:37 +0200 | [diff] [blame] | 192 | struct gprs_ns2_vc *gprs_ns2_nsvc_by_sockaddr_nse( |
| 193 | struct gprs_ns2_nse *nse, |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 194 | const struct osmo_sockaddr *sockaddr); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 195 | void gprs_ns2_start_alive_all_nsvcs(struct gprs_ns2_nse *nse); |
Daniel Willmann | f128654 | 2020-11-03 23:03:33 +0100 | [diff] [blame] | 196 | |
| 197 | /* VC information */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 198 | const char *gprs_ns2_ll_str(struct gprs_ns2_vc *nsvc); |
| 199 | char *gprs_ns2_ll_str_buf(char *buf, size_t buf_len, struct gprs_ns2_vc *nsvc); |
| 200 | char *gprs_ns2_ll_str_c(const void *ctx, struct gprs_ns2_vc *nsvc); |
Daniel Willmann | f128654 | 2020-11-03 23:03:33 +0100 | [diff] [blame] | 201 | const char *gprs_ns2_nsvc_state_name(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 202 | |
| 203 | /* vty */ |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 204 | int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi, |
| 205 | const struct osmo_sockaddr_str *default_bind); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 206 | int gprs_ns2_vty_create(); |
Daniel Willmann | 4fb27a8 | 2020-09-25 15:39:46 +0200 | [diff] [blame] | 207 | void gprs_ns2_vty_force_vc_mode(bool force, enum gprs_ns2_vc_mode mode, const char *reason); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 208 | |
| 209 | |
| 210 | /*! @} */ |