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