Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1 | /* GPRS Networks Service (NS) messages on the Gb interface |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 2 | * 3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05) */ |
| 3 | |
Harald Welte | 605ac5d | 2012-06-16 16:09:52 +0800 | [diff] [blame] | 4 | /* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 16 | * GNU General Public License for more details. |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 17 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License |
Harald Welte | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 20 | * |
| 21 | */ |
| 22 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 23 | /*! \addtogroup libgb |
| 24 | * @{ |
| 25 | */ |
| 26 | |
| 27 | /*! \file gprs_ns.c */ |
| 28 | |
| 29 | /*! |
| 30 | * GPRS Networks Service (NS) messages on the Gb interface |
| 31 | * 3GPP TS 08.16 version 8.0.1 Release 1999 / ETSI TS 101 299 V8.0.1 (2002-05) |
| 32 | * |
| 33 | * Some introduction into NS: NS is used typically on top of frame relay, |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 34 | * but in the ip.access world it is encapsulated in UDP packets. It serves |
| 35 | * as an intermediate shim betwen BSSGP and the underlying medium. It doesn't |
| 36 | * do much, apart from providing congestion notification and status indication. |
| 37 | * |
| 38 | * Terms: |
| 39 | * NS Network Service |
| 40 | * NSVC NS Virtual Connection |
| 41 | * NSEI NS Entity Identifier |
| 42 | * NSVL NS Virtual Link |
| 43 | * NSVLI NS Virtual Link Identifier |
| 44 | * BVC BSSGP Virtual Connection |
| 45 | * BVCI BSSGP Virtual Connection Identifier |
| 46 | * NSVCG NS Virtual Connection Goup |
| 47 | * Blocked NS-VC cannot be used for user traffic |
| 48 | * Alive Ability of a NS-VC to provide communication |
| 49 | * |
| 50 | * There can be multiple BSSGP virtual connections over one (group of) NSVC's. BSSGP will |
| 51 | * therefore identify the BSSGP virtual connection by a BVCI passed down to NS. |
| 52 | * NS then has to firgure out which NSVC's are responsible for this BVCI. |
| 53 | * Those mappings are administratively configured. |
| 54 | */ |
| 55 | |
Harald Welte | dd1c83c | 2010-05-13 13:58:08 +0200 | [diff] [blame] | 56 | /* This implementation has the following limitations: |
| 57 | * o Only one NS-VC for each NSE: No load-sharing function |
| 58 | * o NSVCI 65535 and 65534 are reserved for internal use |
| 59 | * o Only UDP is supported as of now, no frame relay support |
| 60 | * o The IP Sub-Network-Service (SNS) as specified in 48.016 is not implemented |
| 61 | * o There are no BLOCK and UNBLOCK timers (yet?) |
| 62 | */ |
| 63 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 64 | #include <stdlib.h> |
| 65 | #include <unistd.h> |
| 66 | #include <errno.h> |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 67 | #include <stdint.h> |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 68 | |
Holger Hans Peter Freyther | 3c16de2 | 2012-07-12 14:13:41 +0200 | [diff] [blame] | 69 | #include <sys/types.h> |
| 70 | #include <sys/socket.h> |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 71 | #include <arpa/inet.h> |
| 72 | |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 73 | #include <osmocom/core/msgb.h> |
| 74 | #include <osmocom/gsm/tlv.h> |
| 75 | #include <osmocom/core/talloc.h> |
| 76 | #include <osmocom/core/select.h> |
| 77 | #include <osmocom/core/rate_ctr.h> |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 78 | #include <osmocom/core/stat_item.h> |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 79 | #include <osmocom/core/stats.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 80 | #include <osmocom/core/socket.h> |
Harald Welte | 4fcdd76 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 81 | #include <osmocom/core/signal.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 82 | #include <osmocom/gprs/gprs_ns.h> |
| 83 | #include <osmocom/gprs/gprs_bssgp.h> |
| 84 | #include <osmocom/gprs/gprs_ns_frgre.h> |
| 85 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 86 | #include "common_vty.h" |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 87 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 88 | static const struct tlv_definition ns_att_tlvdef = { |
| 89 | .def = { |
| 90 | [NS_IE_CAUSE] = { TLV_TYPE_TvLV, 0 }, |
| 91 | [NS_IE_VCI] = { TLV_TYPE_TvLV, 0 }, |
| 92 | [NS_IE_PDU] = { TLV_TYPE_TvLV, 0 }, |
| 93 | [NS_IE_BVCI] = { TLV_TYPE_TvLV, 0 }, |
| 94 | [NS_IE_NSEI] = { TLV_TYPE_TvLV, 0 }, |
| 95 | }, |
| 96 | }; |
| 97 | |
Harald Welte | c51c23c | 2010-05-13 12:55:20 +0200 | [diff] [blame] | 98 | enum ns_ctr { |
| 99 | NS_CTR_PKTS_IN, |
| 100 | NS_CTR_PKTS_OUT, |
| 101 | NS_CTR_BYTES_IN, |
| 102 | NS_CTR_BYTES_OUT, |
| 103 | NS_CTR_BLOCKED, |
| 104 | NS_CTR_DEAD, |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 105 | NS_CTR_REPLACED, |
| 106 | NS_CTR_NSEI_CHG, |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 107 | NS_CTR_INV_VCI, |
| 108 | NS_CTR_INV_NSEI, |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 109 | NS_CTR_LOST_ALIVE, |
| 110 | NS_CTR_LOST_RESET, |
Harald Welte | c51c23c | 2010-05-13 12:55:20 +0200 | [diff] [blame] | 111 | }; |
| 112 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 113 | static const struct rate_ctr_desc nsvc_ctr_description[] = { |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 114 | { "packets.in", "Packets at NS Level ( In)" }, |
| 115 | { "packets.out","Packets at NS Level (Out)" }, |
| 116 | { "bytes.in", "Bytes at NS Level ( In)" }, |
| 117 | { "bytes.out", "Bytes at NS Level (Out)" }, |
| 118 | { "blocked", "NS-VC Block count " }, |
| 119 | { "dead", "NS-VC gone dead count " }, |
| 120 | { "replaced", "NS-VC replaced other count" }, |
Jacob Erlbeck | ab852ee | 2013-10-24 01:33:24 +0200 | [diff] [blame] | 121 | { "nsei-chg", "NS-VC changed NSEI count " }, |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 122 | { "inv-nsvci", "NS-VCI was invalid count " }, |
| 123 | { "inv-nsei", "NSEI was invalid count " }, |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 124 | { "lost.alive", "ALIVE ACK missing count " }, |
| 125 | { "lost.reset", "RESET ACK missing count " }, |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | static const struct rate_ctr_group_desc nsvc_ctrg_desc = { |
Harald Welte | c51c23c | 2010-05-13 12:55:20 +0200 | [diff] [blame] | 129 | .group_name_prefix = "ns.nsvc", |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 130 | .group_description = "NSVC Peer Statistics", |
| 131 | .num_ctr = ARRAY_SIZE(nsvc_ctr_description), |
| 132 | .ctr_desc = nsvc_ctr_description, |
Jacob Erlbeck | fed2a48 | 2015-11-03 16:18:56 +0100 | [diff] [blame] | 133 | .class_id = OSMO_STATS_CLASS_PEER, |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 134 | }; |
| 135 | |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 136 | enum ns_stat { |
| 137 | NS_STAT_ALIVE_DELAY, |
| 138 | }; |
| 139 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 140 | static const struct osmo_stat_item_desc nsvc_stat_description[] = { |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 141 | { "alive.delay", "ALIVE reponse time ", "ms", 16, 0 }, |
| 142 | }; |
| 143 | |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 144 | static const struct osmo_stat_item_group_desc nsvc_statg_desc = { |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 145 | .group_name_prefix = "ns.nsvc", |
| 146 | .group_description = "NSVC Peer Statistics", |
| 147 | .num_items = ARRAY_SIZE(nsvc_stat_description), |
| 148 | .item_desc = nsvc_stat_description, |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 149 | .class_id = OSMO_STATS_CLASS_PEER, |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 150 | }; |
| 151 | |
Holger Hans Peter Freyther | 9e1cd5a | 2013-10-25 11:09:26 +0200 | [diff] [blame] | 152 | #define CHECK_TX_RC(rc, nsvc) \ |
| 153 | if (rc < 0) \ |
| 154 | LOGP(DNS, LOGL_ERROR, "TX failed (%d) to peer %s\n", \ |
| 155 | rc, gprs_ns_ll_str(nsvc)); |
| 156 | |
Jacob Erlbeck | 8d192d7 | 2015-04-07 17:52:45 +0200 | [diff] [blame] | 157 | struct msgb *gprs_ns_msgb_alloc(void) |
| 158 | { |
| 159 | struct msgb *msg = msgb_alloc_headroom(NS_ALLOC_SIZE, NS_ALLOC_HEADROOM, |
| 160 | "GPRS/NS"); |
| 161 | if (!msg) { |
| 162 | LOGP(DNS, LOGL_ERROR, "Failed to allocate NS message of size %d\n", |
| 163 | NS_ALLOC_SIZE); |
| 164 | } |
| 165 | return msg; |
| 166 | } |
| 167 | |
Holger Hans Peter Freyther | 9e1cd5a | 2013-10-25 11:09:26 +0200 | [diff] [blame] | 168 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 169 | /*! \brief Lookup struct gprs_nsvc based on NSVCI |
| 170 | * \param[in] nsi NS instance in which to search |
| 171 | * \param[in] nsvci NSVCI to be searched |
| 172 | * \returns gprs_nsvc of respective NSVCI |
| 173 | */ |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 174 | struct gprs_nsvc *gprs_nsvc_by_nsvci(struct gprs_ns_inst *nsi, uint16_t nsvci) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 175 | { |
| 176 | struct gprs_nsvc *nsvc; |
| 177 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
| 178 | if (nsvc->nsvci == nsvci) |
| 179 | return nsvc; |
| 180 | } |
| 181 | return NULL; |
| 182 | } |
| 183 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 184 | /*! \brief Lookup struct gprs_nsvc based on NSEI |
| 185 | * \param[in] nsi NS instance in which to search |
| 186 | * \param[in] nsei NSEI to be searched |
Jacob Erlbeck | 6901715 | 2013-10-14 12:03:54 +0200 | [diff] [blame] | 187 | * \returns first gprs_nsvc of respective NSEI |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 188 | */ |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 189 | struct gprs_nsvc *gprs_nsvc_by_nsei(struct gprs_ns_inst *nsi, uint16_t nsei) |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 190 | { |
| 191 | struct gprs_nsvc *nsvc; |
| 192 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
| 193 | if (nsvc->nsei == nsei) |
| 194 | return nsvc; |
| 195 | } |
| 196 | return NULL; |
| 197 | } |
| 198 | |
Jacob Erlbeck | 6901715 | 2013-10-14 12:03:54 +0200 | [diff] [blame] | 199 | static struct gprs_nsvc *gprs_active_nsvc_by_nsei(struct gprs_ns_inst *nsi, |
| 200 | uint16_t nsei) |
| 201 | { |
| 202 | struct gprs_nsvc *nsvc; |
| 203 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
| 204 | if (nsvc->nsei == nsei) { |
Jacob Erlbeck | bf02196 | 2013-10-17 13:58:35 +0200 | [diff] [blame] | 205 | if (!(nsvc->state & NSE_S_BLOCKED) && |
| 206 | nsvc->state & NSE_S_ALIVE) |
Jacob Erlbeck | 6901715 | 2013-10-14 12:03:54 +0200 | [diff] [blame] | 207 | return nsvc; |
| 208 | } |
| 209 | } |
| 210 | return NULL; |
| 211 | } |
| 212 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 213 | /* Lookup struct gprs_nsvc based on remote peer socket addr */ |
| 214 | static struct gprs_nsvc *nsvc_by_rem_addr(struct gprs_ns_inst *nsi, |
| 215 | struct sockaddr_in *sin) |
| 216 | { |
| 217 | struct gprs_nsvc *nsvc; |
| 218 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
Harald Welte | 38407ef | 2010-05-12 11:56:39 +0000 | [diff] [blame] | 219 | if (nsvc->ip.bts_addr.sin_addr.s_addr == |
| 220 | sin->sin_addr.s_addr && |
| 221 | nsvc->ip.bts_addr.sin_port == sin->sin_port) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 222 | return nsvc; |
| 223 | } |
| 224 | return NULL; |
| 225 | } |
| 226 | |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 227 | static void gprs_ns_timer_cb(void *data); |
| 228 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 229 | struct gprs_nsvc *gprs_nsvc_create(struct gprs_ns_inst *nsi, uint16_t nsvci) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 230 | { |
| 231 | struct gprs_nsvc *nsvc; |
| 232 | |
Harald Welte | b1020d5 | 2010-05-25 22:17:30 +0200 | [diff] [blame] | 233 | LOGP(DNS, LOGL_INFO, "NSVCI=%u Creating NS-VC\n", nsvci); |
| 234 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 235 | nsvc = talloc_zero(nsi, struct gprs_nsvc); |
| 236 | nsvc->nsvci = nsvci; |
Jacob Erlbeck | 9b591b7 | 2013-11-11 09:43:05 +0100 | [diff] [blame] | 237 | nsvc->nsvci_is_valid = 1; |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 238 | /* before RESET procedure: BLOCKED and DEAD */ |
| 239 | nsvc->state = NSE_S_BLOCKED; |
| 240 | nsvc->nsi = nsi; |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 241 | nsvc->timer.cb = gprs_ns_timer_cb; |
| 242 | nsvc->timer.data = nsvc; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 243 | nsvc->ctrg = rate_ctr_group_alloc(nsvc, &nsvc_ctrg_desc, nsvci); |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 244 | nsvc->statg = osmo_stat_item_group_alloc(nsvc, &nsvc_statg_desc, nsvci); |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 245 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 246 | llist_add(&nsvc->list, &nsi->gprs_nsvcs); |
| 247 | |
| 248 | return nsvc; |
| 249 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 250 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 251 | /*! \brief Delete given NS-VC |
| 252 | * \param[in] nsvc gprs_nsvc to be deleted |
| 253 | */ |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 254 | void gprs_nsvc_delete(struct gprs_nsvc *nsvc) |
Harald Welte | 2bffac5 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 255 | { |
Pablo Neira Ayuso | 2b15952 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 256 | if (osmo_timer_pending(&nsvc->timer)) |
| 257 | osmo_timer_del(&nsvc->timer); |
Harald Welte | 2bffac5 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 258 | llist_del(&nsvc->list); |
Jacob Erlbeck | a52ba01 | 2013-10-24 01:33:21 +0200 | [diff] [blame] | 259 | rate_ctr_group_free(nsvc->ctrg); |
Jacob Erlbeck | 0975a7f | 2015-12-17 09:51:53 +0100 | [diff] [blame] | 260 | osmo_stat_item_group_free(nsvc->statg); |
Harald Welte | 2bffac5 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 261 | talloc_free(nsvc); |
| 262 | } |
| 263 | |
Pablo Neira Ayuso | 2b88a2a | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 264 | static void ns_osmo_signal_dispatch(struct gprs_nsvc *nsvc, unsigned int signal, |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 265 | uint8_t cause) |
| 266 | { |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 267 | struct ns_signal_data nssd = {0}; |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 268 | |
| 269 | nssd.nsvc = nsvc; |
| 270 | nssd.cause = cause; |
| 271 | |
Harald Welte | 4fcdd76 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 272 | osmo_signal_dispatch(SS_L_NS, signal, &nssd); |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 273 | } |
| 274 | |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 275 | static void ns_osmo_signal_dispatch_mismatch(struct gprs_nsvc *nsvc, |
| 276 | struct msgb *msg, |
| 277 | uint8_t pdu_type, uint8_t ie_type) |
| 278 | { |
| 279 | struct ns_signal_data nssd = {0}; |
| 280 | |
| 281 | nssd.nsvc = nsvc; |
| 282 | nssd.pdu_type = pdu_type; |
| 283 | nssd.ie_type = ie_type; |
| 284 | nssd.msg = msg; |
| 285 | |
| 286 | osmo_signal_dispatch(SS_L_NS, S_NS_MISMATCH, &nssd); |
| 287 | } |
| 288 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 289 | static void ns_osmo_signal_dispatch_replaced(struct gprs_nsvc *nsvc, struct gprs_nsvc *old_nsvc) |
| 290 | { |
| 291 | struct ns_signal_data nssd = {0}; |
| 292 | |
| 293 | nssd.nsvc = nsvc; |
| 294 | nssd.old_nsvc = old_nsvc; |
| 295 | |
| 296 | osmo_signal_dispatch(SS_L_NS, S_NS_REPLACED, &nssd); |
| 297 | } |
| 298 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 299 | /* Section 10.3.2, Table 13 */ |
Harald Welte | 2577d41 | 2010-05-02 09:37:45 +0200 | [diff] [blame] | 300 | static const struct value_string ns_cause_str[] = { |
| 301 | { NS_CAUSE_TRANSIT_FAIL, "Transit network failure" }, |
| 302 | { NS_CAUSE_OM_INTERVENTION, "O&M intervention" }, |
| 303 | { NS_CAUSE_EQUIP_FAIL, "Equipment failure" }, |
| 304 | { NS_CAUSE_NSVC_BLOCKED, "NS-VC blocked" }, |
| 305 | { NS_CAUSE_NSVC_UNKNOWN, "NS-VC unknown" }, |
| 306 | { NS_CAUSE_BVCI_UNKNOWN, "BVCI unknown" }, |
| 307 | { NS_CAUSE_SEM_INCORR_PDU, "Semantically incorrect PDU" }, |
| 308 | { NS_CAUSE_PDU_INCOMP_PSTATE, "PDU not compatible with protocol state" }, |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 309 | { NS_CAUSE_PROTO_ERR_UNSPEC, "Protocol error, unspecified" }, |
Harald Welte | 2577d41 | 2010-05-02 09:37:45 +0200 | [diff] [blame] | 310 | { NS_CAUSE_INVAL_ESSENT_IE, "Invalid essential IE" }, |
| 311 | { NS_CAUSE_MISSING_ESSENT_IE, "Missing essential IE" }, |
| 312 | { 0, NULL } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 313 | }; |
| 314 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 315 | /*! \brief Obtain a human-readable string for NS cause value */ |
Harald Welte | 2577d41 | 2010-05-02 09:37:45 +0200 | [diff] [blame] | 316 | const char *gprs_ns_cause_str(enum ns_cause cause) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 317 | { |
Harald Welte | 2577d41 | 2010-05-02 09:37:45 +0200 | [diff] [blame] | 318 | return get_value_string(ns_cause_str, cause); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 319 | } |
| 320 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 321 | static int nsip_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 322 | extern int grps_ns_frgre_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 323 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 324 | static int gprs_ns_tx(struct gprs_nsvc *nsvc, struct msgb *msg) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 325 | { |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 326 | int ret; |
| 327 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 328 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 329 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 330 | /* Increment number of Uplink bytes */ |
Harald Welte | c51c23c | 2010-05-13 12:55:20 +0200 | [diff] [blame] | 331 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_PKTS_OUT]); |
| 332 | rate_ctr_add(&nsvc->ctrg->ctr[NS_CTR_BYTES_OUT], msgb_l2len(msg)); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 333 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 334 | switch (nsvc->ll) { |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 335 | case GPRS_NS_LL_UDP: |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 336 | ret = nsip_sendmsg(nsvc, msg); |
Jacob Erlbeck | 8d192d7 | 2015-04-07 17:52:45 +0200 | [diff] [blame] | 337 | if (ret < 0) |
| 338 | LOGP(DNS, LOGL_INFO, |
| 339 | "failed to send NS message via UDP: %s\n", |
| 340 | strerror(-ret)); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 341 | break; |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 342 | case GPRS_NS_LL_FR_GRE: |
| 343 | ret = gprs_ns_frgre_sendmsg(nsvc, msg); |
Jacob Erlbeck | 8d192d7 | 2015-04-07 17:52:45 +0200 | [diff] [blame] | 344 | if (ret < 0) |
| 345 | LOGP(DNS, LOGL_INFO, |
| 346 | "failed to send NS message via FR/GRE: %s\n", |
| 347 | strerror(-ret)); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 348 | break; |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 349 | default: |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 350 | LOGP(DNS, LOGL_ERROR, "unsupported NS linklayer %u\n", nsvc->ll); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 351 | msgb_free(msg); |
| 352 | ret = -EIO; |
| 353 | break; |
| 354 | } |
| 355 | return ret; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 356 | } |
| 357 | |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 358 | static int gprs_ns_tx_simple(struct gprs_nsvc *nsvc, uint8_t pdu_type) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 359 | { |
Harald Welte | ba4c666 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 360 | struct msgb *msg = gprs_ns_msgb_alloc(); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 361 | struct gprs_ns_hdr *nsh; |
| 362 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 363 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 364 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 365 | if (!msg) |
| 366 | return -ENOMEM; |
| 367 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 368 | msg->l2h = msgb_put(msg, sizeof(*nsh)); |
| 369 | nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 370 | |
| 371 | nsh->pdu_type = pdu_type; |
| 372 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 373 | return gprs_ns_tx(nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 374 | } |
| 375 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 376 | /*! \brief Transmit a NS-RESET on a given NSVC |
| 377 | * \param[in] nsvc NS-VC used for transmission |
| 378 | * \paam[in] cause Numeric NS cause value |
| 379 | */ |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 380 | int gprs_ns_tx_reset(struct gprs_nsvc *nsvc, uint8_t cause) |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 381 | { |
Harald Welte | ba4c666 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 382 | struct msgb *msg = gprs_ns_msgb_alloc(); |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 383 | struct gprs_ns_hdr *nsh; |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 384 | uint16_t nsvci = htons(nsvc->nsvci); |
| 385 | uint16_t nsei = htons(nsvc->nsei); |
| 386 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 387 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 388 | |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 389 | if (!msg) |
| 390 | return -ENOMEM; |
| 391 | |
Harald Welte | 6ecaa3d | 2010-05-12 12:01:33 +0000 | [diff] [blame] | 392 | LOGP(DNS, LOGL_INFO, "NSEI=%u Tx NS RESET (NSVCI=%u, cause=%s)\n", |
| 393 | nsvc->nsei, nsvc->nsvci, gprs_ns_cause_str(cause)); |
| 394 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 395 | msg->l2h = msgb_put(msg, sizeof(*nsh)); |
| 396 | nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 397 | nsh->pdu_type = NS_PDUT_RESET; |
| 398 | |
| 399 | msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause); |
| 400 | msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *) &nsvci); |
| 401 | msgb_tvlv_put(msg, NS_IE_NSEI, 2, (uint8_t *) &nsei); |
| 402 | |
| 403 | return gprs_ns_tx(nsvc, msg); |
| 404 | |
| 405 | } |
| 406 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 407 | /*! \brief Transmit a NS-STATUS on a given NSVC |
| 408 | * \param[in] nsvc NS-VC to be used for transmission |
| 409 | * \param[in] cause Numeric NS cause value |
| 410 | * \param[in] bvci BVCI to be reset within NSVC |
| 411 | * \param[in] orig_msg message causing the STATUS */ |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 412 | int gprs_ns_tx_status(struct gprs_nsvc *nsvc, uint8_t cause, |
| 413 | uint16_t bvci, struct msgb *orig_msg) |
| 414 | { |
Harald Welte | ba4c666 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 415 | struct msgb *msg = gprs_ns_msgb_alloc(); |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 416 | struct gprs_ns_hdr *nsh; |
| 417 | uint16_t nsvci = htons(nsvc->nsvci); |
| 418 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 419 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 420 | |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 421 | bvci = htons(bvci); |
| 422 | |
| 423 | if (!msg) |
| 424 | return -ENOMEM; |
| 425 | |
Harald Welte | 90af194 | 2010-05-15 23:02:24 +0200 | [diff] [blame] | 426 | LOGP(DNS, LOGL_NOTICE, "NSEI=%u Tx NS STATUS (NSVCI=%u, cause=%s)\n", |
Harald Welte | 6ecaa3d | 2010-05-12 12:01:33 +0000 | [diff] [blame] | 427 | nsvc->nsei, nsvc->nsvci, gprs_ns_cause_str(cause)); |
| 428 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 429 | msg->l2h = msgb_put(msg, sizeof(*nsh)); |
| 430 | nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 431 | nsh->pdu_type = NS_PDUT_STATUS; |
| 432 | |
| 433 | msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause); |
| 434 | |
| 435 | /* Section 9.2.7.1: Static conditions for NS-VCI */ |
| 436 | if (cause == NS_CAUSE_NSVC_BLOCKED || |
| 437 | cause == NS_CAUSE_NSVC_UNKNOWN) |
| 438 | msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *)&nsvci); |
| 439 | |
| 440 | /* Section 9.2.7.2: Static conditions for NS PDU */ |
| 441 | switch (cause) { |
| 442 | case NS_CAUSE_SEM_INCORR_PDU: |
| 443 | case NS_CAUSE_PDU_INCOMP_PSTATE: |
| 444 | case NS_CAUSE_PROTO_ERR_UNSPEC: |
| 445 | case NS_CAUSE_INVAL_ESSENT_IE: |
| 446 | case NS_CAUSE_MISSING_ESSENT_IE: |
| 447 | msgb_tvlv_put(msg, NS_IE_PDU, msgb_l2len(orig_msg), |
| 448 | orig_msg->l2h); |
| 449 | break; |
| 450 | default: |
| 451 | break; |
| 452 | } |
| 453 | |
| 454 | /* Section 9.2.7.3: Static conditions for BVCI */ |
| 455 | if (cause == NS_CAUSE_BVCI_UNKNOWN) |
| 456 | msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *)&bvci); |
| 457 | |
| 458 | return gprs_ns_tx(nsvc, msg); |
| 459 | } |
| 460 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 461 | /*! \brief Transmit a NS-BLOCK on a tiven NS-VC |
| 462 | * \param[in] nsvc NS-VC on which the NS-BLOCK is to be transmitted |
| 463 | * \param[in] cause Numeric NS Cause value |
| 464 | * \returns 0 in case of success |
| 465 | */ |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 466 | int gprs_ns_tx_block(struct gprs_nsvc *nsvc, uint8_t cause) |
| 467 | { |
Harald Welte | ba4c666 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 468 | struct msgb *msg = gprs_ns_msgb_alloc(); |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 469 | struct gprs_ns_hdr *nsh; |
| 470 | uint16_t nsvci = htons(nsvc->nsvci); |
| 471 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 472 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 473 | |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 474 | if (!msg) |
| 475 | return -ENOMEM; |
| 476 | |
Harald Welte | 6ecaa3d | 2010-05-12 12:01:33 +0000 | [diff] [blame] | 477 | LOGP(DNS, LOGL_INFO, "NSEI=%u Tx NS BLOCK (NSVCI=%u, cause=%s)\n", |
| 478 | nsvc->nsei, nsvc->nsvci, gprs_ns_cause_str(cause)); |
| 479 | |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 480 | /* be conservative and mark it as blocked even now! */ |
| 481 | nsvc->state |= NSE_S_BLOCKED; |
Harald Welte | c51c23c | 2010-05-13 12:55:20 +0200 | [diff] [blame] | 482 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_BLOCKED]); |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 483 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 484 | msg->l2h = msgb_put(msg, sizeof(*nsh)); |
| 485 | nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 486 | nsh->pdu_type = NS_PDUT_BLOCK; |
| 487 | |
| 488 | msgb_tvlv_put(msg, NS_IE_CAUSE, 1, &cause); |
| 489 | msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *) &nsvci); |
| 490 | |
| 491 | return gprs_ns_tx(nsvc, msg); |
| 492 | } |
| 493 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 494 | /*! \brief Transmit a NS-UNBLOCK on a given NS-VC |
| 495 | * \param[in] nsvc NS-VC on which the NS-UNBLOCK is to be transmitted |
| 496 | * \returns 0 in case of success |
| 497 | */ |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 498 | int gprs_ns_tx_unblock(struct gprs_nsvc *nsvc) |
| 499 | { |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 500 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 6ecaa3d | 2010-05-12 12:01:33 +0000 | [diff] [blame] | 501 | LOGP(DNS, LOGL_INFO, "NSEI=%u Tx NS UNBLOCK (NSVCI=%u)\n", |
| 502 | nsvc->nsei, nsvc->nsvci); |
| 503 | |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 504 | return gprs_ns_tx_simple(nsvc, NS_PDUT_UNBLOCK); |
| 505 | } |
| 506 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 507 | /*! \brief Transmit a NS-ALIVE on a given NS-VC |
| 508 | * \param[in] nsvc NS-VC on which the NS-ALIVE is to be transmitted |
| 509 | * \returns 0 in case of success |
| 510 | */ |
Harald Welte | b983c31 | 2010-05-12 12:11:45 +0000 | [diff] [blame] | 511 | int gprs_ns_tx_alive(struct gprs_nsvc *nsvc) |
| 512 | { |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 513 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | b983c31 | 2010-05-12 12:11:45 +0000 | [diff] [blame] | 514 | LOGP(DNS, LOGL_DEBUG, "NSEI=%u Tx NS ALIVE (NSVCI=%u)\n", |
| 515 | nsvc->nsei, nsvc->nsvci); |
| 516 | |
| 517 | return gprs_ns_tx_simple(nsvc, NS_PDUT_ALIVE); |
| 518 | } |
| 519 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 520 | /*! \brief Transmit a NS-ALIVE-ACK on a given NS-VC |
| 521 | * \param[in] nsvc NS-VC on which the NS-ALIVE-ACK is to be transmitted |
| 522 | * \returns 0 in case of success |
| 523 | */ |
Harald Welte | b983c31 | 2010-05-12 12:11:45 +0000 | [diff] [blame] | 524 | int gprs_ns_tx_alive_ack(struct gprs_nsvc *nsvc) |
| 525 | { |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 526 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | b983c31 | 2010-05-12 12:11:45 +0000 | [diff] [blame] | 527 | LOGP(DNS, LOGL_DEBUG, "NSEI=%u Tx NS ALIVE_ACK (NSVCI=%u)\n", |
| 528 | nsvc->nsei, nsvc->nsvci); |
| 529 | |
| 530 | return gprs_ns_tx_simple(nsvc, NS_PDUT_ALIVE_ACK); |
| 531 | } |
| 532 | |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 533 | static const enum ns_timeout timer_mode_tout[_NSVC_TIMER_NR] = { |
| 534 | [NSVC_TIMER_TNS_RESET] = NS_TOUT_TNS_RESET, |
| 535 | [NSVC_TIMER_TNS_ALIVE] = NS_TOUT_TNS_ALIVE, |
| 536 | [NSVC_TIMER_TNS_TEST] = NS_TOUT_TNS_TEST, |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 537 | }; |
| 538 | |
Harald Welte | 7c24b9e | 2010-05-12 12:21:52 +0000 | [diff] [blame] | 539 | static const struct value_string timer_mode_strs[] = { |
| 540 | { NSVC_TIMER_TNS_RESET, "tns-reset" }, |
| 541 | { NSVC_TIMER_TNS_ALIVE, "tns-alive" }, |
| 542 | { NSVC_TIMER_TNS_TEST, "tns-test" }, |
| 543 | { 0, NULL } |
| 544 | }; |
| 545 | |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 546 | static void nsvc_start_timer(struct gprs_nsvc *nsvc, enum nsvc_timer_mode mode) |
| 547 | { |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 548 | enum ns_timeout tout = timer_mode_tout[mode]; |
| 549 | unsigned int seconds = nsvc->nsi->timeout[tout]; |
| 550 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 551 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 4e187c6 | 2010-05-12 13:55:36 +0000 | [diff] [blame] | 552 | DEBUGP(DNS, "NSEI=%u Starting timer in mode %s (%u seconds)\n", |
| 553 | nsvc->nsei, get_value_string(timer_mode_strs, mode), |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 554 | seconds); |
Harald Welte | 7c24b9e | 2010-05-12 12:21:52 +0000 | [diff] [blame] | 555 | |
Pablo Neira Ayuso | 2b15952 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 556 | if (osmo_timer_pending(&nsvc->timer)) |
| 557 | osmo_timer_del(&nsvc->timer); |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 558 | |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 559 | gettimeofday(&nsvc->timer_started, NULL); |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 560 | nsvc->timer_mode = mode; |
Pablo Neira Ayuso | 2b15952 | 2011-05-06 12:11:06 +0200 | [diff] [blame] | 561 | osmo_timer_schedule(&nsvc->timer, seconds, 0); |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 562 | } |
| 563 | |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 564 | static int nsvc_timer_elapsed_ms(struct gprs_nsvc *nsvc) |
| 565 | { |
| 566 | struct timeval now, elapsed; |
| 567 | gettimeofday(&now, NULL); |
| 568 | timersub(&now, &nsvc->timer_started, &elapsed); |
| 569 | |
| 570 | return 1000 * elapsed.tv_sec + elapsed.tv_usec / 1000; |
| 571 | } |
| 572 | |
Harald Welte | 8040545 | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 573 | static void gprs_ns_timer_cb(void *data) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 574 | { |
| 575 | struct gprs_nsvc *nsvc = data; |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 576 | enum ns_timeout tout = timer_mode_tout[nsvc->timer_mode]; |
| 577 | unsigned int seconds = nsvc->nsi->timeout[tout]; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 578 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 579 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 4e187c6 | 2010-05-12 13:55:36 +0000 | [diff] [blame] | 580 | DEBUGP(DNS, "NSEI=%u Timer expired in mode %s (%u seconds)\n", |
| 581 | nsvc->nsei, get_value_string(timer_mode_strs, nsvc->timer_mode), |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 582 | seconds); |
Harald Welte | 7c24b9e | 2010-05-12 12:21:52 +0000 | [diff] [blame] | 583 | |
Harald Welte | 8040545 | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 584 | switch (nsvc->timer_mode) { |
| 585 | case NSVC_TIMER_TNS_ALIVE: |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 586 | /* Tns-alive case: we expired without response ! */ |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 587 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_LOST_ALIVE]); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 588 | nsvc->alive_retries++; |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 589 | if (nsvc->alive_retries > |
| 590 | nsvc->nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]) { |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 591 | /* mark as dead and blocked */ |
| 592 | nsvc->state = NSE_S_BLOCKED; |
Harald Welte | c51c23c | 2010-05-13 12:55:20 +0200 | [diff] [blame] | 593 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_BLOCKED]); |
| 594 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_DEAD]); |
Harald Welte | e4ecc8c | 2010-05-12 00:16:57 +0200 | [diff] [blame] | 595 | LOGP(DNS, LOGL_NOTICE, |
| 596 | "NSEI=%u Tns-alive expired more then " |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 597 | "%u times, blocking NS-VC\n", nsvc->nsei, |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 598 | nsvc->nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES]); |
Pablo Neira Ayuso | 2b88a2a | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 599 | ns_osmo_signal_dispatch(nsvc, S_NS_ALIVE_EXP, 0); |
| 600 | ns_osmo_signal_dispatch(nsvc, S_NS_BLOCK, NS_CAUSE_NSVC_BLOCKED); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 601 | return; |
| 602 | } |
Harald Welte | b983c31 | 2010-05-12 12:11:45 +0000 | [diff] [blame] | 603 | /* Tns-test case: send NS-ALIVE PDU */ |
| 604 | gprs_ns_tx_alive(nsvc); |
| 605 | /* start Tns-alive timer */ |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 606 | nsvc_start_timer(nsvc, NSVC_TIMER_TNS_ALIVE); |
Harald Welte | 8040545 | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 607 | break; |
| 608 | case NSVC_TIMER_TNS_TEST: |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 609 | /* Tns-test case: send NS-ALIVE PDU */ |
Harald Welte | b983c31 | 2010-05-12 12:11:45 +0000 | [diff] [blame] | 610 | gprs_ns_tx_alive(nsvc); |
| 611 | /* start Tns-alive timer (transition into faster |
| 612 | * alive retransmissions) */ |
Harald Welte | 7c24b9e | 2010-05-12 12:21:52 +0000 | [diff] [blame] | 613 | nsvc->alive_retries = 0; |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 614 | nsvc_start_timer(nsvc, NSVC_TIMER_TNS_ALIVE); |
| 615 | break; |
| 616 | case NSVC_TIMER_TNS_RESET: |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 617 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_LOST_RESET]); |
Jacob Erlbeck | cc6ac4c | 2015-12-17 13:22:36 +0100 | [diff] [blame] | 618 | if (!(nsvc->state & NSE_S_RESET)) |
| 619 | LOGP(DNS, LOGL_NOTICE, |
| 620 | "NSEI=%u Reset timed out but RESET flag is not set\n", |
| 621 | nsvc->nsei); |
| 622 | /* Mark NS-VC locally as blocked and dead */ |
| 623 | nsvc->state = NSE_S_BLOCKED | NSE_S_RESET; |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 624 | /* Chapter 7.3: Re-send the RESET */ |
Harald Welte | 570fb83 | 2010-05-03 21:05:24 +0200 | [diff] [blame] | 625 | gprs_ns_tx_reset(nsvc, NS_CAUSE_OM_INTERVENTION); |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 626 | /* Re-start Tns-reset timer */ |
Harald Welte | 69a4cf2 | 2010-05-03 20:55:10 +0200 | [diff] [blame] | 627 | nsvc_start_timer(nsvc, NSVC_TIMER_TNS_RESET); |
Harald Welte | 8040545 | 2010-05-03 20:16:13 +0200 | [diff] [blame] | 628 | break; |
Harald Welte | 2fc725d | 2010-05-11 10:15:26 +0200 | [diff] [blame] | 629 | case _NSVC_TIMER_NR: |
| 630 | break; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 631 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /* Section 9.2.6 */ |
Harald Welte | c547848 | 2010-03-18 00:01:43 +0800 | [diff] [blame] | 635 | static int gprs_ns_tx_reset_ack(struct gprs_nsvc *nsvc) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 636 | { |
Harald Welte | ba4c666 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 637 | struct msgb *msg = gprs_ns_msgb_alloc(); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 638 | struct gprs_ns_hdr *nsh; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 639 | uint16_t nsvci, nsei; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 640 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 641 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 642 | if (!msg) |
| 643 | return -ENOMEM; |
| 644 | |
Harald Welte | c547848 | 2010-03-18 00:01:43 +0800 | [diff] [blame] | 645 | nsvci = htons(nsvc->nsvci); |
| 646 | nsei = htons(nsvc->nsei); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 647 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 648 | msg->l2h = msgb_put(msg, sizeof(*nsh)); |
| 649 | nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 650 | |
| 651 | nsh->pdu_type = NS_PDUT_RESET_ACK; |
| 652 | |
Harald Welte | e4ecc8c | 2010-05-12 00:16:57 +0200 | [diff] [blame] | 653 | LOGP(DNS, LOGL_INFO, "NSEI=%u Tx NS RESET ACK (NSVCI=%u)\n", |
Harald Welte | bbc9fac | 2010-05-03 18:54:12 +0200 | [diff] [blame] | 654 | nsvc->nsei, nsvc->nsvci); |
Harald Welte | c547848 | 2010-03-18 00:01:43 +0800 | [diff] [blame] | 655 | |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 656 | msgb_tvlv_put(msg, NS_IE_VCI, 2, (uint8_t *)&nsvci); |
| 657 | msgb_tvlv_put(msg, NS_IE_NSEI, 2, (uint8_t *)&nsei); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 658 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 659 | return gprs_ns_tx(nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 660 | } |
| 661 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 662 | /*! \brief High-level function for transmitting a NS-UNITDATA messsage |
| 663 | * \param[in] nsi NS-instance on which we shall transmit |
| 664 | * \param[in] msg struct msgb to be trasnmitted |
| 665 | * |
| 666 | * This function obtains the NS-VC by the msgb_nsei(msg) and then checks |
| 667 | * if the NS-VC is ALIVEV and not BLOCKED. After that, it adds a NS |
| 668 | * header for the NS-UNITDATA message type and sends it off. |
| 669 | * |
| 670 | * Section 9.2.10: transmit side / NS-UNITDATA-REQUEST primitive |
| 671 | */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 672 | int gprs_ns_sendmsg(struct gprs_ns_inst *nsi, struct msgb *msg) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 673 | { |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 674 | struct gprs_nsvc *nsvc; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 675 | struct gprs_ns_hdr *nsh; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 676 | uint16_t bvci = msgb_bvci(msg); |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 677 | |
Jacob Erlbeck | 6901715 | 2013-10-14 12:03:54 +0200 | [diff] [blame] | 678 | nsvc = gprs_active_nsvc_by_nsei(nsi, msgb_nsei(msg)); |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 679 | if (!nsvc) { |
Jacob Erlbeck | 6901715 | 2013-10-14 12:03:54 +0200 | [diff] [blame] | 680 | int rc; |
| 681 | if (gprs_nsvc_by_nsei(nsi, msgb_nsei(msg))) { |
| 682 | LOGP(DNS, LOGL_ERROR, |
| 683 | "All NS-VCs for NSEI %u are either dead or blocked!\n", |
| 684 | msgb_nsei(msg)); |
| 685 | rc = -EBUSY; |
| 686 | } else { |
| 687 | LOGP(DNS, LOGL_ERROR, "Unable to resolve NSEI %u " |
| 688 | "to NS-VC!\n", msgb_nsei(msg)); |
| 689 | rc = -EINVAL; |
| 690 | } |
| 691 | |
Harald Welte | f47df64 | 2010-08-09 21:15:40 +0800 | [diff] [blame] | 692 | msgb_free(msg); |
Jacob Erlbeck | 6901715 | 2013-10-14 12:03:54 +0200 | [diff] [blame] | 693 | return rc; |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 694 | } |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 695 | log_set_context(GPRS_CTX_NSVC, nsvc); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 696 | |
Harald Welte | ec20ba4 | 2010-05-13 12:18:49 +0200 | [diff] [blame] | 697 | msg->l2h = msgb_push(msg, sizeof(*nsh) + 3); |
| 698 | nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 699 | if (!nsh) { |
Harald Welte | b8a6a83 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 700 | LOGP(DNS, LOGL_ERROR, "Not enough headroom for NS header\n"); |
Harald Welte | f47df64 | 2010-08-09 21:15:40 +0800 | [diff] [blame] | 701 | msgb_free(msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 702 | return -EIO; |
| 703 | } |
| 704 | |
| 705 | nsh->pdu_type = NS_PDUT_UNITDATA; |
| 706 | /* spare octet in data[0] */ |
| 707 | nsh->data[1] = bvci >> 8; |
| 708 | nsh->data[2] = bvci & 0xff; |
| 709 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 710 | return gprs_ns_tx(nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | /* Section 9.2.10: receive side */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 714 | static int gprs_ns_rx_unitdata(struct gprs_nsvc *nsvc, struct msgb *msg) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 715 | { |
| 716 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *)msg->l2h; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 717 | uint16_t bvci; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 718 | |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 719 | if (nsvc->state & NSE_S_BLOCKED) |
| 720 | return gprs_ns_tx_status(nsvc, NS_CAUSE_NSVC_BLOCKED, |
| 721 | 0, msg); |
| 722 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 723 | /* spare octet in data[0] */ |
| 724 | bvci = nsh->data[1] << 8 | nsh->data[2]; |
Harald Welte | ec19c10 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 725 | msgb_bssgph(msg) = &nsh->data[3]; |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 726 | msgb_bvci(msg) = bvci; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 727 | |
| 728 | /* call upper layer (BSSGP) */ |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 729 | return nsvc->nsi->cb(GPRS_NS_EVT_UNIT_DATA, nsvc, msg, bvci); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* Section 9.2.7 */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 733 | static int gprs_ns_rx_status(struct gprs_nsvc *nsvc, struct msgb *msg) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 734 | { |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 735 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 736 | struct tlv_parsed tp; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 737 | uint8_t cause; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 738 | int rc; |
| 739 | |
Harald Welte | 4133783 | 2010-05-16 00:24:26 +0200 | [diff] [blame] | 740 | LOGP(DNS, LOGL_NOTICE, "NSEI=%u Rx NS STATUS ", nsvc->nsei); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 741 | |
Harald Welte | bd33f3d | 2010-05-30 17:19:38 +0200 | [diff] [blame] | 742 | rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, |
| 743 | msgb_l2len(msg) - sizeof(*nsh), 0, 0); |
Harald Welte | 3625038 | 2010-05-28 10:08:14 +0200 | [diff] [blame] | 744 | if (rc < 0) { |
| 745 | LOGPC(DNS, LOGL_NOTICE, "Error during TLV Parse\n"); |
| 746 | LOGP(DNS, LOGL_ERROR, "NSEI=%u Rx NS STATUS: " |
| 747 | "Error during TLV Parse\n", nsvc->nsei); |
| 748 | return rc; |
| 749 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 750 | |
| 751 | if (!TLVP_PRESENT(&tp, NS_IE_CAUSE)) { |
Harald Welte | e4ecc8c | 2010-05-12 00:16:57 +0200 | [diff] [blame] | 752 | LOGPC(DNS, LOGL_INFO, "missing cause IE\n"); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 753 | return -EINVAL; |
| 754 | } |
| 755 | |
| 756 | cause = *TLVP_VAL(&tp, NS_IE_CAUSE); |
Harald Welte | 4133783 | 2010-05-16 00:24:26 +0200 | [diff] [blame] | 757 | LOGPC(DNS, LOGL_NOTICE, "cause=%s\n", gprs_ns_cause_str(cause)); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 758 | |
| 759 | return 0; |
| 760 | } |
| 761 | |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 762 | /* Replace a nsvc object with another based on NSVCI. |
| 763 | * This function replaces looks for a NSVC with the given NSVCI and replaces it |
| 764 | * if possible and necessary. If replaced, the former value of *nsvc is |
| 765 | * returned in *old_nsvc. |
| 766 | * \return != 0 if *nsvc points to a matching NSVC. |
| 767 | */ |
| 768 | static int gprs_nsvc_replace_if_found(uint16_t nsvci, |
| 769 | struct gprs_nsvc **nsvc, |
| 770 | struct gprs_nsvc **old_nsvc) |
| 771 | { |
| 772 | struct gprs_nsvc *matching_nsvc; |
| 773 | |
| 774 | if ((*nsvc)->nsvci == nsvci) { |
| 775 | *old_nsvc = NULL; |
| 776 | return 1; |
| 777 | } |
| 778 | |
| 779 | matching_nsvc = gprs_nsvc_by_nsvci((*nsvc)->nsi, nsvci); |
| 780 | |
| 781 | if (!matching_nsvc) |
| 782 | return 0; |
| 783 | |
| 784 | /* The NS-VCI is already used by this NS-VC */ |
| 785 | |
| 786 | char *old_peer; |
| 787 | |
| 788 | /* Exchange the NS-VC objects */ |
| 789 | *old_nsvc = *nsvc; |
| 790 | *nsvc = matching_nsvc; |
| 791 | |
| 792 | /* Do logging */ |
| 793 | old_peer = talloc_strdup(*old_nsvc, gprs_ns_ll_str(*old_nsvc)); |
| 794 | LOGP(DNS, LOGL_INFO, "NS-VC changed link (NSVCI=%u) from %s to %s\n", |
| 795 | nsvci, old_peer, gprs_ns_ll_str(*nsvc)); |
| 796 | |
| 797 | talloc_free(old_peer); |
| 798 | |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 799 | return 1; |
| 800 | } |
| 801 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 802 | /* Section 7.3 */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 803 | static int gprs_ns_rx_reset(struct gprs_nsvc **nsvc, struct msgb *msg) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 804 | { |
| 805 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 806 | struct tlv_parsed tp; |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 807 | uint8_t cause; |
| 808 | uint16_t nsvci, nsei; |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 809 | struct gprs_nsvc *orig_nsvc = NULL; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 810 | int rc; |
| 811 | |
Harald Welte | bd33f3d | 2010-05-30 17:19:38 +0200 | [diff] [blame] | 812 | rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, |
| 813 | msgb_l2len(msg) - sizeof(*nsh), 0, 0); |
Harald Welte | 3625038 | 2010-05-28 10:08:14 +0200 | [diff] [blame] | 814 | if (rc < 0) { |
| 815 | LOGP(DNS, LOGL_ERROR, "NSEI=%u Rx NS RESET " |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 816 | "Error during TLV Parse\n", (*nsvc)->nsei); |
Harald Welte | 3625038 | 2010-05-28 10:08:14 +0200 | [diff] [blame] | 817 | return rc; |
| 818 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 819 | |
| 820 | if (!TLVP_PRESENT(&tp, NS_IE_CAUSE) || |
| 821 | !TLVP_PRESENT(&tp, NS_IE_VCI) || |
| 822 | !TLVP_PRESENT(&tp, NS_IE_NSEI)) { |
Harald Welte | b8a6a83 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 823 | LOGP(DNS, LOGL_ERROR, "NS RESET Missing mandatory IE\n"); |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 824 | gprs_ns_tx_status(*nsvc, NS_CAUSE_MISSING_ESSENT_IE, 0, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 825 | return -EINVAL; |
| 826 | } |
| 827 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 828 | cause = *(uint8_t *) TLVP_VAL(&tp, NS_IE_CAUSE); |
| 829 | nsvci = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_VCI)); |
| 830 | nsei = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_NSEI)); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 831 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 832 | LOGP(DNS, LOGL_INFO, "NSVCI=%u%s Rx NS RESET (NSEI=%u, NSVCI=%u, cause=%s)\n", |
| 833 | (*nsvc)->nsvci, (*nsvc)->nsvci_is_valid ? "" : "(invalid)", |
| 834 | nsei, nsvci, gprs_ns_cause_str(cause)); |
| 835 | |
Jacob Erlbeck | ab852ee | 2013-10-24 01:33:24 +0200 | [diff] [blame] | 836 | if ((*nsvc)->nsvci_is_valid && (*nsvc)->nsvci != nsvci) { |
| 837 | if ((*nsvc)->persistent || (*nsvc)->remote_end_is_sgsn) { |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 838 | /* The incoming RESET doesn't match the NSVCI. Send an |
| 839 | * appropriate RESET_ACK and ignore the RESET. |
| 840 | * See 3GPP TS 08.16, 7.3.1, 2nd paragraph. |
| 841 | */ |
| 842 | ns_osmo_signal_dispatch_mismatch(*nsvc, msg, |
| 843 | NS_PDUT_RESET, |
| 844 | NS_IE_VCI); |
| 845 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_INV_VCI]); |
| 846 | gprs_ns_tx_reset_ack(*nsvc); |
| 847 | return 0; |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 848 | } |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 849 | |
| 850 | /* NS-VCI has changed */ |
Jacob Erlbeck | 54b8b2d | 2013-10-24 01:33:25 +0200 | [diff] [blame] | 851 | if (!gprs_nsvc_replace_if_found(nsvci, nsvc, &orig_nsvc)) { |
| 852 | LOGP(DNS, LOGL_INFO, "Creating NS-VC %d replacing %d " |
| 853 | "at %s\n", |
| 854 | nsvci, (*nsvc)->nsvci, |
| 855 | gprs_ns_ll_str(*nsvc)); |
| 856 | orig_nsvc = *nsvc; |
| 857 | *nsvc = gprs_nsvc_create((*nsvc)->nsi, nsvci); |
Jacob Erlbeck | 54b8b2d | 2013-10-24 01:33:25 +0200 | [diff] [blame] | 858 | (*nsvc)->nsei = nsei; |
| 859 | } |
Jacob Erlbeck | ab852ee | 2013-10-24 01:33:24 +0200 | [diff] [blame] | 860 | } |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 861 | |
Jacob Erlbeck | ab852ee | 2013-10-24 01:33:24 +0200 | [diff] [blame] | 862 | if ((*nsvc)->nsvci_is_valid && (*nsvc)->nsei != nsei) { |
| 863 | if ((*nsvc)->persistent || (*nsvc)->remote_end_is_sgsn) { |
| 864 | /* The incoming RESET doesn't match the NSEI. Send an |
| 865 | * appropriate RESET_ACK and ignore the RESET. |
| 866 | * See 3GPP TS 08.16, 7.3.1, 3rd paragraph. |
| 867 | */ |
| 868 | ns_osmo_signal_dispatch_mismatch(*nsvc, msg, |
| 869 | NS_PDUT_RESET, |
| 870 | NS_IE_NSEI); |
| 871 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_INV_NSEI]); |
Holger Hans Peter Freyther | 726e272 | 2013-10-25 11:05:10 +0200 | [diff] [blame] | 872 | rc = gprs_ns_tx_reset_ack(*nsvc); |
Holger Hans Peter Freyther | 9e1cd5a | 2013-10-25 11:09:26 +0200 | [diff] [blame] | 873 | CHECK_TX_RC(rc, *nsvc); |
Jacob Erlbeck | ab852ee | 2013-10-24 01:33:24 +0200 | [diff] [blame] | 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | /* NSEI has changed */ |
| 878 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_NSEI_CHG]); |
| 879 | (*nsvc)->nsei = nsei; |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 880 | } |
Harald Welte | bbc9fac | 2010-05-03 18:54:12 +0200 | [diff] [blame] | 881 | |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 882 | /* Mark NS-VC as blocked and alive */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 883 | (*nsvc)->state = NSE_S_BLOCKED | NSE_S_ALIVE; |
Harald Welte | e8b9ca2 | 2010-05-11 18:18:31 +0200 | [diff] [blame] | 884 | |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 885 | if (orig_nsvc) { |
Jacob Erlbeck | 54b8b2d | 2013-10-24 01:33:25 +0200 | [diff] [blame] | 886 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_REPLACED]); |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 887 | ns_osmo_signal_dispatch_replaced(*nsvc, orig_nsvc); |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 888 | |
| 889 | /* Update the ll info fields */ |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 890 | gprs_ns_ll_copy(*nsvc, orig_nsvc); |
| 891 | gprs_ns_ll_clear(orig_nsvc); |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 892 | } else { |
| 893 | (*nsvc)->nsei = nsei; |
| 894 | (*nsvc)->nsvci = nsvci; |
| 895 | (*nsvc)->nsvci_is_valid = 1; |
Holger Hans Peter Freyther | 495b0db | 2015-11-04 14:39:37 +0100 | [diff] [blame] | 896 | rate_ctr_group_upd_idx((*nsvc)->ctrg, nsvci); |
| 897 | osmo_stat_item_group_udp_idx((*nsvc)->statg, nsvci); |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 898 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 899 | |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 900 | /* inform interested parties about the fact that this NSVC |
| 901 | * has received RESET */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 902 | ns_osmo_signal_dispatch(*nsvc, S_NS_RESET, cause); |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 903 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 904 | rc = gprs_ns_tx_reset_ack(*nsvc); |
Jacob Erlbeck | 05395a6 | 2013-10-08 12:04:45 +0200 | [diff] [blame] | 905 | |
| 906 | /* start the test procedure */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 907 | gprs_ns_tx_simple((*nsvc), NS_PDUT_ALIVE); |
| 908 | nsvc_start_timer((*nsvc), NSVC_TIMER_TNS_TEST); |
Jacob Erlbeck | 05395a6 | 2013-10-08 12:04:45 +0200 | [diff] [blame] | 909 | |
| 910 | return rc; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 911 | } |
| 912 | |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 913 | static int gprs_ns_rx_reset_ack(struct gprs_nsvc **nsvc, struct msgb *msg) |
| 914 | { |
| 915 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 916 | struct tlv_parsed tp; |
| 917 | uint16_t nsvci, nsei; |
| 918 | struct gprs_nsvc *orig_nsvc = NULL; |
| 919 | int rc; |
| 920 | |
| 921 | rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, |
| 922 | msgb_l2len(msg) - sizeof(*nsh), 0, 0); |
| 923 | if (rc < 0) { |
| 924 | LOGP(DNS, LOGL_ERROR, "NSEI=%u Rx NS RESET ACK " |
| 925 | "Error during TLV Parse\n", (*nsvc)->nsei); |
| 926 | return rc; |
| 927 | } |
| 928 | |
| 929 | if (!TLVP_PRESENT(&tp, NS_IE_VCI) || |
| 930 | !TLVP_PRESENT(&tp, NS_IE_NSEI)) { |
| 931 | LOGP(DNS, LOGL_ERROR, "NS RESET ACK Missing mandatory IE\n"); |
Holger Hans Peter Freyther | 7c91bfd | 2013-10-25 11:02:05 +0200 | [diff] [blame] | 932 | rc = gprs_ns_tx_status(*nsvc, NS_CAUSE_MISSING_ESSENT_IE, 0, msg); |
Holger Hans Peter Freyther | 9e1cd5a | 2013-10-25 11:09:26 +0200 | [diff] [blame] | 933 | CHECK_TX_RC(rc, *nsvc); |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 934 | return -EINVAL; |
| 935 | } |
| 936 | |
Max | 27e8036 | 2016-04-23 19:37:58 +0200 | [diff] [blame] | 937 | nsvci = ntohs(tlvp_val16_unal(&tp, NS_IE_VCI)); |
| 938 | nsei = ntohs(tlvp_val16_unal(&tp, NS_IE_NSEI)); |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 939 | |
| 940 | LOGP(DNS, LOGL_INFO, "NSVCI=%u%s Rx NS RESET ACK (NSEI=%u, NSVCI=%u)\n", |
| 941 | (*nsvc)->nsvci, (*nsvc)->nsvci_is_valid ? "" : "(invalid)", |
| 942 | nsei, nsvci); |
| 943 | |
| 944 | if (!((*nsvc)->state & NSE_S_RESET)) { |
| 945 | /* Not waiting for a RESET_ACK on this NS-VC, ignore it. |
| 946 | * See 3GPP TS 08.16, 7.3.1, 5th paragraph. |
| 947 | */ |
| 948 | LOGP(DNS, LOGL_ERROR, |
| 949 | "NS RESET ACK Discarding unexpected message for " |
| 950 | "NS-VCI %d from SGSN NSEI=%d\n", |
| 951 | nsvci, nsei); |
| 952 | return 0; |
| 953 | } |
| 954 | |
| 955 | if (!(*nsvc)->nsvci_is_valid) { |
| 956 | LOGP(DNS, LOGL_NOTICE, |
| 957 | "NS RESET ACK Uninitialised NS-VC (%u) for " |
| 958 | "NS-VCI %d, NSEI=%d from %s\n", |
| 959 | (*nsvc)->nsvci, nsvci, nsei, gprs_ns_ll_str(*nsvc)); |
| 960 | return -EINVAL; |
| 961 | } |
| 962 | |
| 963 | if ((*nsvc)->nsvci != nsvci) { |
| 964 | /* NS-VCI has changed */ |
| 965 | |
| 966 | /* if !0, use another NSVC object that matches the NSVCI */ |
| 967 | int use_other_nsvc; |
| 968 | |
| 969 | /* Only do this with BSS peers */ |
Jacob Erlbeck | ab852ee | 2013-10-24 01:33:24 +0200 | [diff] [blame] | 970 | use_other_nsvc = !(*nsvc)->remote_end_is_sgsn && |
| 971 | !(*nsvc)->persistent; |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 972 | |
| 973 | if (use_other_nsvc) |
| 974 | /* Update *nsvc to point to the right NSVC object */ |
| 975 | use_other_nsvc = gprs_nsvc_replace_if_found(nsvci, nsvc, |
| 976 | &orig_nsvc); |
| 977 | |
| 978 | if (!use_other_nsvc) { |
| 979 | /* The incoming RESET_ACK doesn't match the NSVCI. |
| 980 | * See 3GPP TS 08.16, 7.3.1, 4th paragraph. |
| 981 | */ |
| 982 | ns_osmo_signal_dispatch_mismatch(*nsvc, msg, |
| 983 | NS_PDUT_RESET_ACK, |
| 984 | NS_IE_VCI); |
| 985 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_INV_VCI]); |
| 986 | LOGP(DNS, LOGL_ERROR, |
| 987 | "NS RESET ACK Unknown NS-VCI %d (%s NSEI=%d) " |
| 988 | "from %s\n", |
| 989 | nsvci, |
| 990 | (*nsvc)->remote_end_is_sgsn ? "SGSN" : "BSS", |
| 991 | nsei, gprs_ns_ll_str(*nsvc)); |
| 992 | return -EINVAL; |
| 993 | } |
| 994 | |
| 995 | /* Notify others */ |
Jacob Erlbeck | 54b8b2d | 2013-10-24 01:33:25 +0200 | [diff] [blame] | 996 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_REPLACED]); |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 997 | ns_osmo_signal_dispatch_replaced(*nsvc, orig_nsvc); |
| 998 | |
| 999 | /* Update the ll info fields */ |
| 1000 | gprs_ns_ll_copy(*nsvc, orig_nsvc); |
| 1001 | gprs_ns_ll_clear(orig_nsvc); |
| 1002 | } else if ((*nsvc)->nsei != nsei) { |
Jacob Erlbeck | ab852ee | 2013-10-24 01:33:24 +0200 | [diff] [blame] | 1003 | if ((*nsvc)->persistent || (*nsvc)->remote_end_is_sgsn) { |
| 1004 | /* The incoming RESET_ACK doesn't match the NSEI. |
| 1005 | * See 3GPP TS 08.16, 7.3.1, 4th paragraph. |
| 1006 | */ |
| 1007 | ns_osmo_signal_dispatch_mismatch(*nsvc, msg, |
| 1008 | NS_PDUT_RESET_ACK, |
| 1009 | NS_IE_NSEI); |
| 1010 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_INV_NSEI]); |
| 1011 | LOGP(DNS, LOGL_ERROR, |
| 1012 | "NS RESET ACK Unknown NSEI %d (NS-VCI=%u) from %s\n", |
| 1013 | nsei, nsvci, gprs_ns_ll_str(*nsvc)); |
| 1014 | return -EINVAL; |
| 1015 | } |
| 1016 | |
| 1017 | /* NSEI has changed */ |
| 1018 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_NSEI_CHG]); |
| 1019 | (*nsvc)->nsei = nsei; |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | /* Mark NS-VC as blocked and alive */ |
| 1023 | (*nsvc)->state = NSE_S_BLOCKED | NSE_S_ALIVE; |
| 1024 | (*nsvc)->remote_state = NSE_S_BLOCKED | NSE_S_ALIVE; |
| 1025 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_BLOCKED]); |
| 1026 | if ((*nsvc)->persistent || (*nsvc)->remote_end_is_sgsn) { |
| 1027 | /* stop RESET timer */ |
| 1028 | osmo_timer_del(&(*nsvc)->timer); |
| 1029 | } |
| 1030 | /* Initiate TEST proc.: Send ALIVE and start timer */ |
| 1031 | rc = gprs_ns_tx_simple(*nsvc, NS_PDUT_ALIVE); |
| 1032 | nsvc_start_timer(*nsvc, NSVC_TIMER_TNS_TEST); |
| 1033 | |
| 1034 | return rc; |
| 1035 | } |
| 1036 | |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 1037 | static int gprs_ns_rx_block(struct gprs_nsvc *nsvc, struct msgb *msg) |
| 1038 | { |
| 1039 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 1040 | struct tlv_parsed tp; |
| 1041 | uint8_t *cause; |
| 1042 | int rc; |
| 1043 | |
Harald Welte | e4ecc8c | 2010-05-12 00:16:57 +0200 | [diff] [blame] | 1044 | LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS BLOCK\n", nsvc->nsei); |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 1045 | |
| 1046 | nsvc->state |= NSE_S_BLOCKED; |
| 1047 | |
Harald Welte | bd33f3d | 2010-05-30 17:19:38 +0200 | [diff] [blame] | 1048 | rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, |
| 1049 | msgb_l2len(msg) - sizeof(*nsh), 0, 0); |
Harald Welte | 3625038 | 2010-05-28 10:08:14 +0200 | [diff] [blame] | 1050 | if (rc < 0) { |
| 1051 | LOGP(DNS, LOGL_ERROR, "NSEI=%u Rx NS BLOCK " |
| 1052 | "Error during TLV Parse\n", nsvc->nsei); |
| 1053 | return rc; |
| 1054 | } |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 1055 | |
| 1056 | if (!TLVP_PRESENT(&tp, NS_IE_CAUSE) || |
| 1057 | !TLVP_PRESENT(&tp, NS_IE_VCI)) { |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 1058 | LOGP(DNS, LOGL_ERROR, "NS RESET Missing mandatory IE\n"); |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 1059 | gprs_ns_tx_status(nsvc, NS_CAUSE_MISSING_ESSENT_IE, 0, msg); |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 1060 | return -EINVAL; |
| 1061 | } |
| 1062 | |
| 1063 | cause = (uint8_t *) TLVP_VAL(&tp, NS_IE_CAUSE); |
| 1064 | //nsvci = (uint16_t *) TLVP_VAL(&tp, NS_IE_VCI); |
| 1065 | |
Pablo Neira Ayuso | 2b88a2a | 2011-05-06 12:12:31 +0200 | [diff] [blame] | 1066 | ns_osmo_signal_dispatch(nsvc, S_NS_BLOCK, *cause); |
Harald Welte | c51c23c | 2010-05-13 12:55:20 +0200 | [diff] [blame] | 1067 | rate_ctr_inc(&nsvc->ctrg->ctr[NS_CTR_BLOCKED]); |
Harald Welte | 834f26d | 2010-05-11 06:20:54 +0200 | [diff] [blame] | 1068 | |
| 1069 | return gprs_ns_tx_simple(nsvc, NS_PDUT_BLOCK_ACK); |
| 1070 | } |
| 1071 | |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1072 | int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg, |
| 1073 | struct gprs_nsvc *fallback_nsvc, |
| 1074 | struct gprs_nsvc **new_nsvc); |
| 1075 | |
| 1076 | int gprs_ns_process_msg(struct gprs_ns_inst *nsi, struct msgb *msg, |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1077 | struct gprs_nsvc **nsvc); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1078 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1079 | /*! \brief Receive incoming NS message from underlying transport layer |
| 1080 | * \param nsi NS instance to which the data belongs |
| 1081 | * \param[in] msg message buffer containing newly-received data |
| 1082 | * \param[in] saddr socketaddr from which data was received |
| 1083 | * \param[in] ll link-layer type in which data was received |
| 1084 | * \returns 0 in case of success, < 0 in case of error |
| 1085 | * |
| 1086 | * This is the main entry point int othe NS imlementation where frames |
| 1087 | * from the underlying transport (normally UDP) enter. |
| 1088 | */ |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1089 | int gprs_ns_rcvmsg(struct gprs_ns_inst *nsi, struct msgb *msg, |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 1090 | struct sockaddr_in *saddr, enum gprs_ns_ll ll) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1091 | { |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1092 | struct gprs_nsvc *nsvc; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1093 | int rc = 0; |
| 1094 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1095 | /* look up the NSVC based on source address */ |
| 1096 | nsvc = nsvc_by_rem_addr(nsi, saddr); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1097 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1098 | if (!nsvc) { |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1099 | struct gprs_nsvc *fallback_nsvc; |
| 1100 | |
| 1101 | fallback_nsvc = nsi->unknown_nsvc; |
| 1102 | log_set_context(GPRS_CTX_NSVC, fallback_nsvc); |
| 1103 | fallback_nsvc->ip.bts_addr = *saddr; |
| 1104 | fallback_nsvc->ll = ll; |
| 1105 | |
| 1106 | rc = gprs_ns_vc_create(nsi, msg, fallback_nsvc, &nsvc); |
| 1107 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1108 | if (rc < 0) |
Harald Welte | 3625038 | 2010-05-28 10:08:14 +0200 | [diff] [blame] | 1109 | return rc; |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1110 | |
| 1111 | rc = 0; |
| 1112 | } |
| 1113 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1114 | if (nsvc) |
| 1115 | rc = gprs_ns_process_msg(nsi, msg, &nsvc); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1116 | |
| 1117 | return rc; |
| 1118 | } |
| 1119 | |
Jacob Erlbeck | 96550e0 | 2013-10-14 22:06:47 +0200 | [diff] [blame] | 1120 | const char *gprs_ns_ll_str(struct gprs_nsvc *nsvc) |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1121 | { |
| 1122 | static char buf[80]; |
| 1123 | snprintf(buf, sizeof(buf), "%s:%u", |
| 1124 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
| 1125 | ntohs(nsvc->ip.bts_addr.sin_port)); |
Holger Hans Peter Freyther | 0cccf40 | 2013-10-25 11:00:23 +0200 | [diff] [blame] | 1126 | buf[sizeof(buf) - 1] = '\0'; |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1127 | |
| 1128 | return buf; |
| 1129 | } |
| 1130 | |
Jacob Erlbeck | 96550e0 | 2013-10-14 22:06:47 +0200 | [diff] [blame] | 1131 | void gprs_ns_ll_copy(struct gprs_nsvc *nsvc, struct gprs_nsvc *other) |
| 1132 | { |
| 1133 | nsvc->ll = other->ll; |
| 1134 | |
| 1135 | switch (nsvc->ll) { |
| 1136 | case GPRS_NS_LL_UDP: |
| 1137 | nsvc->ip = other->ip; |
| 1138 | break; |
| 1139 | case GPRS_NS_LL_FR_GRE: |
| 1140 | nsvc->frgre = other->frgre; |
| 1141 | break; |
| 1142 | default: |
| 1143 | break; |
| 1144 | } |
| 1145 | } |
| 1146 | |
| 1147 | void gprs_ns_ll_clear(struct gprs_nsvc *nsvc) |
| 1148 | { |
| 1149 | switch (nsvc->ll) { |
| 1150 | case GPRS_NS_LL_UDP: |
| 1151 | nsvc->ip.bts_addr.sin_addr.s_addr = INADDR_ANY; |
| 1152 | nsvc->ip.bts_addr.sin_port = 0; |
| 1153 | break; |
| 1154 | case GPRS_NS_LL_FR_GRE: |
| 1155 | nsvc->frgre.bts_addr.sin_addr.s_addr = INADDR_ANY; |
| 1156 | nsvc->frgre.bts_addr.sin_port = 0; |
| 1157 | break; |
| 1158 | default: |
| 1159 | break; |
| 1160 | } |
| 1161 | } |
| 1162 | |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1163 | /*! \brief Create/get NS-VC independently from underlying transport layer |
| 1164 | * \param nsi NS instance to which the data belongs |
| 1165 | * \param[in] msg message buffer containing newly-received data |
| 1166 | * \param[in] fallback_nsvc is used to send error messages back to the peer |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1167 | * and to initialise the ll info of a created NS-VC object |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1168 | * \param[out] new_nsvc contains a pointer to a NS-VC object if one has |
| 1169 | * been created or found |
| 1170 | * \returns < 0 in case of error, GPRS_NS_CS_SKIPPED if a message has been |
| 1171 | * skipped, GPRS_NS_CS_REJECTED if a message has been rejected and |
| 1172 | * answered accordingly, GPRS_NS_CS_CREATED if a new NS-VC object |
| 1173 | * has been created and registered, and GPRS_NS_CS_FOUND if an |
| 1174 | * existing NS-VC object has been found with the same NSEI. |
| 1175 | * |
| 1176 | * This contains the initial NS automaton state (NS-VC not yet attached). |
| 1177 | */ |
| 1178 | int gprs_ns_vc_create(struct gprs_ns_inst *nsi, struct msgb *msg, |
| 1179 | struct gprs_nsvc *fallback_nsvc, |
| 1180 | struct gprs_nsvc **new_nsvc) |
| 1181 | { |
| 1182 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *)msg->l2h; |
| 1183 | struct gprs_nsvc *existing_nsvc; |
| 1184 | |
| 1185 | struct tlv_parsed tp; |
Jacob Erlbeck | b6390f9 | 2013-10-08 12:04:46 +0200 | [diff] [blame] | 1186 | uint16_t nsvci; |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1187 | uint16_t nsei; |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1188 | |
| 1189 | int rc; |
| 1190 | |
| 1191 | if (nsh->pdu_type == NS_PDUT_STATUS) { |
Jacob Erlbeck | 3d557b1 | 2013-10-28 13:29:11 +0100 | [diff] [blame] | 1192 | /* Do not respond, see 3GPP TS 08.16, 7.5.1 */ |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1193 | LOGP(DNS, LOGL_INFO, "Ignoring NS STATUS from %s " |
| 1194 | "for non-existing NS-VC\n", |
Jacob Erlbeck | 96550e0 | 2013-10-14 22:06:47 +0200 | [diff] [blame] | 1195 | gprs_ns_ll_str(fallback_nsvc)); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1196 | return GPRS_NS_CS_SKIPPED; |
| 1197 | } |
| 1198 | |
Jacob Erlbeck | 3d557b1 | 2013-10-28 13:29:11 +0100 | [diff] [blame] | 1199 | if (nsh->pdu_type == NS_PDUT_ALIVE_ACK) { |
| 1200 | /* Ignore this, see 3GPP TS 08.16, 7.4.1 */ |
| 1201 | LOGP(DNS, LOGL_INFO, "Ignoring NS ALIVE ACK from %s " |
| 1202 | "for non-existing NS-VC\n", |
| 1203 | gprs_ns_ll_str(fallback_nsvc)); |
| 1204 | return GPRS_NS_CS_SKIPPED; |
| 1205 | } |
| 1206 | |
| 1207 | if (nsh->pdu_type == NS_PDUT_RESET_ACK) { |
| 1208 | /* Ignore this, see 3GPP TS 08.16, 7.3.1 */ |
| 1209 | LOGP(DNS, LOGL_INFO, "Ignoring NS RESET ACK from %s " |
| 1210 | "for non-existing NS-VC\n", |
| 1211 | gprs_ns_ll_str(fallback_nsvc)); |
| 1212 | return GPRS_NS_CS_SKIPPED; |
| 1213 | } |
| 1214 | |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1215 | /* Only the RESET procedure creates a new NSVC */ |
| 1216 | if (nsh->pdu_type != NS_PDUT_RESET) { |
| 1217 | /* Since we have no NSVC, we have to use a fake */ |
| 1218 | log_set_context(GPRS_CTX_NSVC, fallback_nsvc); |
| 1219 | LOGP(DNS, LOGL_INFO, "Rejecting NS PDU type 0x%0x " |
| 1220 | "from %s for non-existing NS-VC\n", |
Jacob Erlbeck | 96550e0 | 2013-10-14 22:06:47 +0200 | [diff] [blame] | 1221 | nsh->pdu_type, gprs_ns_ll_str(fallback_nsvc)); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1222 | fallback_nsvc->nsvci = fallback_nsvc->nsei = 0xfffe; |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 1223 | fallback_nsvc->nsvci_is_valid = 0; |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1224 | fallback_nsvc->state = NSE_S_ALIVE; |
| 1225 | |
| 1226 | rc = gprs_ns_tx_status(fallback_nsvc, |
| 1227 | NS_CAUSE_PDU_INCOMP_PSTATE, 0, msg); |
| 1228 | if (rc < 0) { |
| 1229 | LOGP(DNS, LOGL_ERROR, "TX failed (%d) to peer %s\n", |
Jacob Erlbeck | 96550e0 | 2013-10-14 22:06:47 +0200 | [diff] [blame] | 1230 | rc, gprs_ns_ll_str(fallback_nsvc)); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1231 | return rc; |
| 1232 | } |
| 1233 | return GPRS_NS_CS_REJECTED; |
| 1234 | } |
| 1235 | |
| 1236 | rc = tlv_parse(&tp, &ns_att_tlvdef, nsh->data, |
| 1237 | msgb_l2len(msg) - sizeof(*nsh), 0, 0); |
| 1238 | if (rc < 0) { |
| 1239 | LOGP(DNS, LOGL_ERROR, "Rx NS RESET Error %d during " |
| 1240 | "TLV Parse\n", rc); |
| 1241 | return rc; |
| 1242 | } |
| 1243 | if (!TLVP_PRESENT(&tp, NS_IE_CAUSE) || |
| 1244 | !TLVP_PRESENT(&tp, NS_IE_VCI) || !TLVP_PRESENT(&tp, NS_IE_NSEI)) { |
| 1245 | LOGP(DNS, LOGL_ERROR, "NS RESET Missing mandatory IE\n"); |
Holger Hans Peter Freyther | 9e1cd5a | 2013-10-25 11:09:26 +0200 | [diff] [blame] | 1246 | rc = gprs_ns_tx_status(fallback_nsvc, NS_CAUSE_MISSING_ESSENT_IE, 0, |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1247 | msg); |
Holger Hans Peter Freyther | 9e1cd5a | 2013-10-25 11:09:26 +0200 | [diff] [blame] | 1248 | CHECK_TX_RC(rc, fallback_nsvc); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1249 | return -EINVAL; |
| 1250 | } |
Jacob Erlbeck | b6390f9 | 2013-10-08 12:04:46 +0200 | [diff] [blame] | 1251 | nsvci = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_VCI)); |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1252 | nsei = ntohs(*(uint16_t *) TLVP_VAL(&tp, NS_IE_NSEI)); |
Jacob Erlbeck | b6390f9 | 2013-10-08 12:04:46 +0200 | [diff] [blame] | 1253 | /* Check if we already know this NSVCI, the remote end might |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1254 | * simply have changed addresses, or it is a SGSN */ |
Jacob Erlbeck | b6390f9 | 2013-10-08 12:04:46 +0200 | [diff] [blame] | 1255 | existing_nsvc = gprs_nsvc_by_nsvci(nsi, nsvci); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1256 | if (!existing_nsvc) { |
| 1257 | *new_nsvc = gprs_nsvc_create(nsi, 0xffff); |
Jacob Erlbeck | 9b591b7 | 2013-11-11 09:43:05 +0100 | [diff] [blame] | 1258 | (*new_nsvc)->nsvci_is_valid = 0; |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1259 | log_set_context(GPRS_CTX_NSVC, *new_nsvc); |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1260 | gprs_ns_ll_copy(*new_nsvc, fallback_nsvc); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1261 | LOGP(DNS, LOGL_INFO, "Creating NS-VC for BSS at %s\n", |
Jacob Erlbeck | 96550e0 | 2013-10-14 22:06:47 +0200 | [diff] [blame] | 1262 | gprs_ns_ll_str(fallback_nsvc)); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1263 | |
| 1264 | return GPRS_NS_CS_CREATED; |
| 1265 | } |
| 1266 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1267 | /* Check NSEI */ |
| 1268 | if (existing_nsvc->nsei != nsei) { |
| 1269 | LOGP(DNS, LOGL_NOTICE, |
| 1270 | "NS-VC changed NSEI (NSVCI=%u) from %u to %u\n", |
| 1271 | nsvci, existing_nsvc->nsei, nsei); |
| 1272 | |
| 1273 | /* Override old NSEI */ |
| 1274 | existing_nsvc->nsei = nsei; |
| 1275 | |
| 1276 | /* Do statistics */ |
| 1277 | rate_ctr_inc(&existing_nsvc->ctrg->ctr[NS_CTR_NSEI_CHG]); |
| 1278 | } |
| 1279 | |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1280 | *new_nsvc = existing_nsvc; |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1281 | gprs_ns_ll_copy(*new_nsvc, fallback_nsvc); |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1282 | return GPRS_NS_CS_FOUND; |
| 1283 | } |
| 1284 | |
| 1285 | /*! \brief Process NS message independently from underlying transport layer |
| 1286 | * \param nsi NS instance to which the data belongs |
| 1287 | * \param[in] msg message buffer containing newly-received data |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1288 | * \param[inout] nsvc refers to the virtual connection, may be modified when |
| 1289 | * processing a NS_RESET |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1290 | * \returns 0 in case of success, < 0 in case of error |
| 1291 | * |
| 1292 | * This contains the main NS automaton. |
| 1293 | */ |
| 1294 | int gprs_ns_process_msg(struct gprs_ns_inst *nsi, struct msgb *msg, |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1295 | struct gprs_nsvc **nsvc) |
Jacob Erlbeck | 84cdc70 | 2013-10-08 12:04:44 +0200 | [diff] [blame] | 1296 | { |
| 1297 | struct gprs_ns_hdr *nsh = (struct gprs_ns_hdr *) msg->l2h; |
| 1298 | int rc = 0; |
| 1299 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1300 | msgb_nsei(msg) = (*nsvc)->nsei; |
Harald Welte | c547848 | 2010-03-18 00:01:43 +0800 | [diff] [blame] | 1301 | |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1302 | log_set_context(GPRS_CTX_NSVC, *nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 1303 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 1304 | /* Increment number of Incoming bytes */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1305 | rate_ctr_inc(&(*nsvc)->ctrg->ctr[NS_CTR_PKTS_IN]); |
| 1306 | rate_ctr_add(&(*nsvc)->ctrg->ctr[NS_CTR_BYTES_IN], msgb_l2len(msg)); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 1307 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1308 | switch (nsh->pdu_type) { |
| 1309 | case NS_PDUT_ALIVE: |
Harald Welte | 2bffac5 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 1310 | /* If we're dead and blocked and suddenly receive a |
| 1311 | * NS-ALIVE out of the blue, we might have been re-started |
| 1312 | * and should send a NS-RESET to make sure everything recovers |
| 1313 | * fine. */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1314 | if ((*nsvc)->state == NSE_S_BLOCKED) |
Jacob Erlbeck | 6ac70a4 | 2014-10-07 14:12:30 +0200 | [diff] [blame] | 1315 | rc = gprs_nsvc_reset((*nsvc), NS_CAUSE_PDU_INCOMP_PSTATE); |
| 1316 | else if (!((*nsvc)->state & NSE_S_RESET)) |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1317 | rc = gprs_ns_tx_alive_ack(*nsvc); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1318 | break; |
| 1319 | case NS_PDUT_ALIVE_ACK: |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 1320 | if ((*nsvc)->timer_mode == NSVC_TIMER_TNS_ALIVE) |
Jacob Erlbeck | fc9533d | 2015-10-29 00:55:58 +0100 | [diff] [blame] | 1321 | osmo_stat_item_set((*nsvc)->statg->items[NS_STAT_ALIVE_DELAY], |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 1322 | nsvc_timer_elapsed_ms(*nsvc)); |
Harald Welte | 90af194 | 2010-05-15 23:02:24 +0200 | [diff] [blame] | 1323 | /* stop Tns-alive and start Tns-test */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1324 | nsvc_start_timer(*nsvc, NSVC_TIMER_TNS_TEST); |
| 1325 | if ((*nsvc)->remote_end_is_sgsn) { |
Harald Welte | 7fb7e61 | 2010-05-03 21:11:22 +0200 | [diff] [blame] | 1326 | /* FIXME: this should be one level higher */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1327 | if ((*nsvc)->state & NSE_S_BLOCKED) |
| 1328 | rc = gprs_ns_tx_unblock(*nsvc); |
Harald Welte | 7fb7e61 | 2010-05-03 21:11:22 +0200 | [diff] [blame] | 1329 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1330 | break; |
| 1331 | case NS_PDUT_UNITDATA: |
| 1332 | /* actual user data */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1333 | rc = gprs_ns_rx_unitdata(*nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1334 | break; |
| 1335 | case NS_PDUT_STATUS: |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1336 | rc = gprs_ns_rx_status(*nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1337 | break; |
| 1338 | case NS_PDUT_RESET: |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 1339 | rc = gprs_ns_rx_reset(nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1340 | break; |
| 1341 | case NS_PDUT_RESET_ACK: |
Jacob Erlbeck | 5405a10 | 2013-10-24 01:33:23 +0200 | [diff] [blame] | 1342 | rc = gprs_ns_rx_reset_ack(nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1343 | break; |
| 1344 | case NS_PDUT_UNBLOCK: |
| 1345 | /* Section 7.2: unblocking procedure */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1346 | LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS UNBLOCK\n", (*nsvc)->nsei); |
| 1347 | (*nsvc)->state &= ~NSE_S_BLOCKED; |
| 1348 | ns_osmo_signal_dispatch(*nsvc, S_NS_UNBLOCK, 0); |
| 1349 | rc = gprs_ns_tx_simple(*nsvc, NS_PDUT_UNBLOCK_ACK); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1350 | break; |
| 1351 | case NS_PDUT_UNBLOCK_ACK: |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1352 | LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS UNBLOCK ACK\n", (*nsvc)->nsei); |
Harald Welte | c1402a6 | 2010-05-12 11:48:44 +0200 | [diff] [blame] | 1353 | /* mark NS-VC as unblocked + active */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1354 | (*nsvc)->state = NSE_S_ALIVE; |
| 1355 | (*nsvc)->remote_state = NSE_S_ALIVE; |
| 1356 | ns_osmo_signal_dispatch(*nsvc, S_NS_UNBLOCK, 0); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1357 | break; |
| 1358 | case NS_PDUT_BLOCK: |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1359 | rc = gprs_ns_rx_block(*nsvc, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1360 | break; |
| 1361 | case NS_PDUT_BLOCK_ACK: |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1362 | LOGP(DNS, LOGL_INFO, "NSEI=%u Rx NS BLOCK ACK\n", (*nsvc)->nsei); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1363 | /* mark remote NS-VC as blocked + active */ |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1364 | (*nsvc)->remote_state = NSE_S_BLOCKED | NSE_S_ALIVE; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1365 | break; |
| 1366 | default: |
Harald Welte | e4ecc8c | 2010-05-12 00:16:57 +0200 | [diff] [blame] | 1367 | LOGP(DNS, LOGL_NOTICE, "NSEI=%u Rx Unknown NS PDU type 0x%02x\n", |
Jacob Erlbeck | 5e6d679 | 2013-10-14 22:06:48 +0200 | [diff] [blame] | 1368 | (*nsvc)->nsei, nsh->pdu_type); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1369 | rc = -EINVAL; |
| 1370 | break; |
| 1371 | } |
| 1372 | return rc; |
| 1373 | } |
| 1374 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1375 | /*! \brief Create a new GPRS NS instance |
| 1376 | * \param[in] cb Call-back function for incoming BSSGP data |
| 1377 | * \returns dynamically allocated gprs_ns_inst |
| 1378 | */ |
Harald Welte | 4fcdd76 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 1379 | struct gprs_ns_inst *gprs_ns_instantiate(gprs_ns_cb_t *cb, void *ctx) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1380 | { |
Harald Welte | 4fcdd76 | 2012-06-16 16:40:42 +0800 | [diff] [blame] | 1381 | struct gprs_ns_inst *nsi = talloc_zero(ctx, struct gprs_ns_inst); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1382 | |
| 1383 | nsi->cb = cb; |
| 1384 | INIT_LLIST_HEAD(&nsi->gprs_nsvcs); |
Harald Welte | fe4ab90 | 2010-05-12 17:19:53 +0000 | [diff] [blame] | 1385 | nsi->timeout[NS_TOUT_TNS_BLOCK] = 3; |
| 1386 | nsi->timeout[NS_TOUT_TNS_BLOCK_RETRIES] = 3; |
| 1387 | nsi->timeout[NS_TOUT_TNS_RESET] = 3; |
| 1388 | nsi->timeout[NS_TOUT_TNS_RESET_RETRIES] = 3; |
| 1389 | nsi->timeout[NS_TOUT_TNS_TEST] = 30; |
| 1390 | nsi->timeout[NS_TOUT_TNS_ALIVE] = 3; |
| 1391 | nsi->timeout[NS_TOUT_TNS_ALIVE_RETRIES] = 10; |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1392 | |
Harald Welte | 60cc6ac | 2010-05-13 14:20:56 +0200 | [diff] [blame] | 1393 | /* Create the dummy NSVC that we use for sending |
| 1394 | * messages to non-existant/unknown NS-VC's */ |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 1395 | nsi->unknown_nsvc = gprs_nsvc_create(nsi, 0xfffe); |
Jacob Erlbeck | 9b591b7 | 2013-11-11 09:43:05 +0100 | [diff] [blame] | 1396 | nsi->unknown_nsvc->nsvci_is_valid = 0; |
Harald Welte | 60cc6ac | 2010-05-13 14:20:56 +0200 | [diff] [blame] | 1397 | llist_del(&nsi->unknown_nsvc->list); |
Holger Hans Peter Freyther | 777b056 | 2014-07-07 20:00:35 +0200 | [diff] [blame] | 1398 | INIT_LLIST_HEAD(&nsi->unknown_nsvc->list); |
Harald Welte | dd1c83c | 2010-05-13 13:58:08 +0200 | [diff] [blame] | 1399 | |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1400 | return nsi; |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1401 | } |
| 1402 | |
Holger Hans Peter Freyther | c62a1bf | 2013-07-02 09:10:11 +0200 | [diff] [blame] | 1403 | void gprs_ns_close(struct gprs_ns_inst *nsi) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1404 | { |
Andreas Eversberg | aaccdac | 2012-09-28 10:11:25 +0200 | [diff] [blame] | 1405 | struct gprs_nsvc *nsvc, *nsvc2; |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1406 | |
Holger Hans Peter Freyther | 777b056 | 2014-07-07 20:00:35 +0200 | [diff] [blame] | 1407 | gprs_nsvc_delete(nsi->unknown_nsvc); |
| 1408 | |
Andreas Eversberg | aaccdac | 2012-09-28 10:11:25 +0200 | [diff] [blame] | 1409 | /* delete all NSVCs and clear their timers */ |
| 1410 | llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) |
| 1411 | gprs_nsvc_delete(nsvc); |
| 1412 | |
| 1413 | /* close socket and unregister */ |
| 1414 | if (nsi->nsip.fd.data) { |
| 1415 | close(nsi->nsip.fd.fd); |
| 1416 | osmo_fd_unregister(&nsi->nsip.fd); |
Holger Hans Peter Freyther | c62a1bf | 2013-07-02 09:10:11 +0200 | [diff] [blame] | 1417 | nsi->nsip.fd.data = NULL; |
Andreas Eversberg | aaccdac | 2012-09-28 10:11:25 +0200 | [diff] [blame] | 1418 | } |
Holger Hans Peter Freyther | c62a1bf | 2013-07-02 09:10:11 +0200 | [diff] [blame] | 1419 | } |
Andreas Eversberg | aaccdac | 2012-09-28 10:11:25 +0200 | [diff] [blame] | 1420 | |
Holger Hans Peter Freyther | c62a1bf | 2013-07-02 09:10:11 +0200 | [diff] [blame] | 1421 | /*! \brief Destroy an entire NS instance |
| 1422 | * \param nsi gprs_ns_inst that is to be destroyed |
| 1423 | * |
| 1424 | * This function releases all resources associated with the |
| 1425 | * NS-instance. |
| 1426 | */ |
| 1427 | void gprs_ns_destroy(struct gprs_ns_inst *nsi) |
| 1428 | { |
| 1429 | gprs_ns_close(nsi); |
Andreas Eversberg | aaccdac | 2012-09-28 10:11:25 +0200 | [diff] [blame] | 1430 | /* free the NSI */ |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1431 | talloc_free(nsi); |
| 1432 | } |
| 1433 | |
| 1434 | |
| 1435 | /* NS-over-IP code, according to 3GPP TS 48.016 Chapter 6.2 |
| 1436 | * We don't support Size Procedure, Configuration Procedure, ChangeWeight Procedure */ |
| 1437 | |
| 1438 | /* Read a single NS-over-IP message */ |
Pablo Neira Ayuso | bfadfb7 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 1439 | static struct msgb *read_nsip_msg(struct osmo_fd *bfd, int *error, |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1440 | struct sockaddr_in *saddr) |
| 1441 | { |
Harald Welte | ba4c666 | 2010-05-19 15:38:10 +0200 | [diff] [blame] | 1442 | struct msgb *msg = gprs_ns_msgb_alloc(); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1443 | int ret = 0; |
| 1444 | socklen_t saddr_len = sizeof(*saddr); |
| 1445 | |
| 1446 | if (!msg) { |
| 1447 | *error = -ENOMEM; |
| 1448 | return NULL; |
| 1449 | } |
| 1450 | |
Holger Hans Peter Freyther | 26c3251 | 2010-05-28 03:25:36 +0800 | [diff] [blame] | 1451 | ret = recvfrom(bfd->fd, msg->data, NS_ALLOC_SIZE - NS_ALLOC_HEADROOM, 0, |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1452 | (struct sockaddr *)saddr, &saddr_len); |
| 1453 | if (ret < 0) { |
Harald Welte | b8a6a83 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 1454 | LOGP(DNS, LOGL_ERROR, "recv error %s during NSIP recv\n", |
Harald Welte | bbc9fac | 2010-05-03 18:54:12 +0200 | [diff] [blame] | 1455 | strerror(errno)); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1456 | msgb_free(msg); |
| 1457 | *error = ret; |
| 1458 | return NULL; |
| 1459 | } else if (ret == 0) { |
| 1460 | msgb_free(msg); |
| 1461 | *error = ret; |
| 1462 | return NULL; |
| 1463 | } |
| 1464 | |
| 1465 | msg->l2h = msg->data; |
| 1466 | msgb_put(msg, ret); |
| 1467 | |
| 1468 | return msg; |
| 1469 | } |
| 1470 | |
Pablo Neira Ayuso | bfadfb7 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 1471 | static int handle_nsip_read(struct osmo_fd *bfd) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1472 | { |
| 1473 | int error; |
| 1474 | struct sockaddr_in saddr; |
| 1475 | struct gprs_ns_inst *nsi = bfd->data; |
| 1476 | struct msgb *msg = read_nsip_msg(bfd, &error, &saddr); |
| 1477 | |
| 1478 | if (!msg) |
| 1479 | return error; |
| 1480 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 1481 | error = gprs_ns_rcvmsg(nsi, msg, &saddr, GPRS_NS_LL_UDP); |
Harald Welte | 91813cf | 2010-05-12 18:38:45 +0000 | [diff] [blame] | 1482 | |
| 1483 | msgb_free(msg); |
| 1484 | |
| 1485 | return error; |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1486 | } |
| 1487 | |
Pablo Neira Ayuso | bfadfb7 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 1488 | static int handle_nsip_write(struct osmo_fd *bfd) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1489 | { |
| 1490 | /* FIXME: actually send the data here instead of nsip_sendmsg() */ |
| 1491 | return -EIO; |
| 1492 | } |
| 1493 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 1494 | static int nsip_sendmsg(struct gprs_nsvc *nsvc, struct msgb *msg) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1495 | { |
| 1496 | int rc; |
| 1497 | struct gprs_ns_inst *nsi = nsvc->nsi; |
| 1498 | struct sockaddr_in *daddr = &nsvc->ip.bts_addr; |
| 1499 | |
| 1500 | rc = sendto(nsi->nsip.fd.fd, msg->data, msg->len, 0, |
| 1501 | (struct sockaddr *)daddr, sizeof(*daddr)); |
| 1502 | |
Holger Hans Peter Freyther | 5274646 | 2012-03-01 20:30:32 +0100 | [diff] [blame] | 1503 | msgb_free(msg); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1504 | |
| 1505 | return rc; |
| 1506 | } |
| 1507 | |
| 1508 | /* UDP Port 23000 carries the LLC-in-BSSGP-in-NS protocol stack */ |
Pablo Neira Ayuso | bfadfb7 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 1509 | static int nsip_fd_cb(struct osmo_fd *bfd, unsigned int what) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1510 | { |
| 1511 | int rc = 0; |
| 1512 | |
| 1513 | if (what & BSC_FD_READ) |
| 1514 | rc = handle_nsip_read(bfd); |
| 1515 | if (what & BSC_FD_WRITE) |
| 1516 | rc = handle_nsip_write(bfd); |
| 1517 | |
| 1518 | return rc; |
| 1519 | } |
| 1520 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1521 | /*! \brief Create a listening socket for GPRS NS/UDP/IP |
| 1522 | * \param[in] nsi NS protocol instance to listen |
| 1523 | * \returns >=0 (fd) in case of success, negative in case of error |
| 1524 | * |
| 1525 | * A call to this function will create a UDP socket bound to the port |
| 1526 | * number and IP address specified in the NS protocol instance. The |
| 1527 | * file descriptor of the socket will be stored in nsi->nsip.fd. |
| 1528 | */ |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 1529 | int gprs_ns_nsip_listen(struct gprs_ns_inst *nsi) |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1530 | { |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 1531 | struct in_addr in; |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1532 | int ret; |
| 1533 | |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 1534 | in.s_addr = htonl(nsi->nsip.local_ip); |
| 1535 | |
| 1536 | nsi->nsip.fd.cb = nsip_fd_cb; |
| 1537 | nsi->nsip.fd.data = nsi; |
| 1538 | ret = osmo_sock_init_ofd(&nsi->nsip.fd, AF_INET, SOCK_DGRAM, |
| 1539 | IPPROTO_UDP, inet_ntoa(in), |
| 1540 | nsi->nsip.local_port, OSMO_SOCK_F_BIND); |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1541 | if (ret < 0) |
| 1542 | return ret; |
| 1543 | |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 1544 | ret = setsockopt(nsi->nsip.fd.fd, IPPROTO_IP, IP_TOS, |
| 1545 | &nsi->nsip.dscp, sizeof(nsi->nsip.dscp)); |
| 1546 | if (ret < 0) |
| 1547 | LOGP(DNS, LOGL_ERROR, |
| 1548 | "Failed to set the DSCP to %d with ret(%d) errno(%d)\n", |
| 1549 | nsi->nsip.dscp, ret, errno); |
| 1550 | |
Harald Welte | f030b21 | 2010-04-26 19:18:54 +0200 | [diff] [blame] | 1551 | |
| 1552 | return ret; |
| 1553 | } |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1554 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1555 | /*! \brief Initiate a RESET procedure |
| 1556 | * \param[in] nsvc NS-VC in which to start the procedure |
| 1557 | * \param[in] cause Numeric NS cause value |
| 1558 | * |
| 1559 | * This is a high-level function initiating a NS-RESET procedure. It |
| 1560 | * will not only send a NS-RESET, but also set the state to BLOCKED and |
| 1561 | * start the Tns-reset timer. |
| 1562 | */ |
Jacob Erlbeck | 0540d83 | 2014-10-08 11:47:36 +0200 | [diff] [blame] | 1563 | int gprs_nsvc_reset(struct gprs_nsvc *nsvc, uint8_t cause) |
Harald Welte | 731d1fc | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 1564 | { |
Jacob Erlbeck | 0540d83 | 2014-10-08 11:47:36 +0200 | [diff] [blame] | 1565 | int rc; |
| 1566 | |
Harald Welte | b1020d5 | 2010-05-25 22:17:30 +0200 | [diff] [blame] | 1567 | LOGP(DNS, LOGL_INFO, "NSEI=%u RESET procedure based on API request\n", |
| 1568 | nsvc->nsei); |
| 1569 | |
Harald Welte | 731d1fc | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 1570 | /* Mark NS-VC locally as blocked and dead */ |
Jacob Erlbeck | 6ac70a4 | 2014-10-07 14:12:30 +0200 | [diff] [blame] | 1571 | nsvc->state = NSE_S_BLOCKED | NSE_S_RESET; |
| 1572 | |
Harald Welte | 731d1fc | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 1573 | /* Send NS-RESET PDU */ |
Jacob Erlbeck | 0540d83 | 2014-10-08 11:47:36 +0200 | [diff] [blame] | 1574 | rc = gprs_ns_tx_reset(nsvc, cause); |
| 1575 | if (rc < 0) { |
Harald Welte | 731d1fc | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 1576 | LOGP(DNS, LOGL_ERROR, "NSEI=%u, error resetting NS-VC\n", |
| 1577 | nsvc->nsei); |
| 1578 | } |
| 1579 | /* Start Tns-reset */ |
| 1580 | nsvc_start_timer(nsvc, NSVC_TIMER_TNS_RESET); |
Jacob Erlbeck | 0540d83 | 2014-10-08 11:47:36 +0200 | [diff] [blame] | 1581 | |
| 1582 | return rc; |
Harald Welte | 731d1fc | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 1583 | } |
| 1584 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1585 | /*! \brief Establish a NS connection (from the BSS) to the SGSN |
| 1586 | * \param nsi NS-instance |
| 1587 | * \param[in] dest Destination IP/Port |
| 1588 | * \param[in] nsei NSEI of the to-be-established NS-VC |
| 1589 | * \param[in] nsvci NSVCI of the to-be-established NS-VC |
| 1590 | * \returns struct gprs_nsvc representing the new NS-VC |
| 1591 | * |
| 1592 | * This function will establish a single NS/UDP/IP connection in uplink |
| 1593 | * (BSS to SGSN) direction. |
| 1594 | */ |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 1595 | struct gprs_nsvc *gprs_ns_nsip_connect(struct gprs_ns_inst *nsi, |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 1596 | struct sockaddr_in *dest, uint16_t nsei, |
| 1597 | uint16_t nsvci) |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1598 | { |
| 1599 | struct gprs_nsvc *nsvc; |
| 1600 | |
| 1601 | nsvc = nsvc_by_rem_addr(nsi, dest); |
Harald Welte | 38407ef | 2010-05-12 11:56:39 +0000 | [diff] [blame] | 1602 | if (!nsvc) |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 1603 | nsvc = gprs_nsvc_create(nsi, nsvci); |
Harald Welte | 38407ef | 2010-05-12 11:56:39 +0000 | [diff] [blame] | 1604 | nsvc->ip.bts_addr = *dest; |
Harald Welte | 1203de3 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 1605 | nsvc->nsei = nsei; |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1606 | nsvc->remote_end_is_sgsn = 1; |
| 1607 | |
Holger Hans Peter Freyther | 5617d99 | 2010-05-23 21:18:01 +0800 | [diff] [blame] | 1608 | gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 1609 | return nsvc; |
Harald Welte | 3771d09 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1610 | } |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1611 | |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 1612 | void gprs_ns_set_log_ss(int ss) |
| 1613 | { |
| 1614 | DNS = ss; |
| 1615 | } |
| 1616 | |
Harald Welte | a9f23c8 | 2011-11-23 15:01:31 +0100 | [diff] [blame] | 1617 | /*! }@ */ |