Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gprs_bssgp.c |
| 2 | * GPRS BSSGP protocol implementation as per 3GPP TS 08.18. */ |
| 3 | /* |
| 4 | * (C) 2009-2017 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 5 | * |
| 6 | * All Rights Reserved |
| 7 | * |
Harald Welte | e08da97 | 2017-11-13 01:00:26 +0900 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | * |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 10 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 18 | * GNU General Public License for more details. |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 19 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 20 | * You should have received a copy of the GNU General Public License |
Harald Welte | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 22 | * |
Harald Welte | 4e5721d | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 23 | * TODO: |
| 24 | * o properly count incoming BVC-RESET packets in counter group |
| 25 | * o set log context as early as possible for outgoing packets |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <errno.h> |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 29 | #include <stdint.h> |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 30 | |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 31 | #include <osmocom/core/msgb.h> |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 32 | #include <osmocom/core/byteswap.h> |
| 33 | #include <osmocom/core/bit16gen.h> |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 34 | #include <osmocom/gsm/tlv.h> |
| 35 | #include <osmocom/core/talloc.h> |
| 36 | #include <osmocom/core/rate_ctr.h> |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 37 | #include <osmocom/core/stats.h> |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 38 | |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 39 | #include <osmocom/gprs/gprs_bssgp.h> |
Max | 8b8938f | 2017-06-29 19:48:29 +0200 | [diff] [blame] | 40 | #include <osmocom/gprs/gprs_bssgp_bss.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 41 | #include <osmocom/gprs/gprs_ns.h> |
| 42 | |
Daniel Willmann | 2d42b90 | 2020-09-26 09:11:05 +0200 | [diff] [blame] | 43 | #include "osmocom/gsm/gsm48.h" |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 44 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 45 | void *bssgp_tall_ctx = NULL; |
| 46 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 47 | static int _gprs_ns_sendmsg(void *ctx, struct msgb *msg); |
| 48 | |
| 49 | bssgp_bvc_send bssgp_ns_send = _gprs_ns_sendmsg; |
| 50 | void *bssgp_ns_send_data = NULL; |
| 51 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 52 | static const struct rate_ctr_desc bssgp_ctr_description[] = { |
Harald Welte | a7a5065 | 2017-10-03 17:49:21 +0800 | [diff] [blame] | 53 | { "packets:in", "Packets at BSSGP Level ( In)" }, |
| 54 | { "packets:out","Packets at BSSGP Level (Out)" }, |
| 55 | { "bytes:in", "Bytes at BSSGP Level ( In)" }, |
| 56 | { "bytes:out", "Bytes at BSSGP Level (Out)" }, |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 57 | { "blocked", "BVC Blocking count" }, |
| 58 | { "discarded", "BVC LLC Discarded count" }, |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 59 | { "status", "BVC Status count" }, |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | static const struct rate_ctr_group_desc bssgp_ctrg_desc = { |
Harald Welte | a7a5065 | 2017-10-03 17:49:21 +0800 | [diff] [blame] | 63 | .group_name_prefix = "bssgp:bss_ctx", |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 64 | .group_description = "BSSGP Peer Statistics", |
| 65 | .num_ctr = ARRAY_SIZE(bssgp_ctr_description), |
| 66 | .ctr_desc = bssgp_ctr_description, |
Jacob Erlbeck | bc9d9ac | 2015-11-02 14:49:35 +0100 | [diff] [blame] | 67 | .class_id = OSMO_STATS_CLASS_PEER, |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 70 | LLIST_HEAD(bssgp_bvc_ctxts); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 71 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 72 | static int _bssgp_tx_dl_ud(struct bssgp_flow_control *fc, struct msgb *msg, |
| 73 | uint32_t llc_pdu_len, void *priv); |
| 74 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 75 | |
Alexander Couzens | 83fb686 | 2020-09-03 19:30:08 +0200 | [diff] [blame] | 76 | /* callback to be backward compatible with old users which do not set the bssgp_ns_send function */ |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 77 | static int _gprs_ns_sendmsg(void *ctx, struct msgb *msg) |
| 78 | { |
| 79 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 80 | } |
| 81 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 82 | /* Find a BTS Context based on parsed RA ID and Cell ID */ |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 83 | struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid) |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 84 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 85 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 86 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 87 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 88 | if (!memcmp(&bctx->ra_id, raid, sizeof(bctx->ra_id)) && |
| 89 | bctx->cell_id == cid) |
| 90 | return bctx; |
| 91 | } |
| 92 | return NULL; |
| 93 | } |
| 94 | |
Daniel Willmann | 2d42b90 | 2020-09-26 09:11:05 +0200 | [diff] [blame] | 95 | /*! Transmit a BVC-RESET message with a given nsei and bvci (Chapter 10.4.12) |
| 96 | * \param[in] nsei The NSEI to transmit over |
| 97 | * \param[in] bvci BVCI of the BVC to reset |
| 98 | * \param[in] cause The cause of the reset |
| 99 | * \param[in] ra_id Pointer to the ra_id to include. If NULL no cell information will be included |
| 100 | * \param[in] cell_id The cell_id to include (if ra_id is not NULL) |
| 101 | */ |
| 102 | int bssgp_tx_bvc_reset_nsei_bvci(uint16_t nsei, uint16_t bvci, enum gprs_bssgp_cause cause, const struct gprs_ra_id *ra_id, uint16_t cell_id) |
| 103 | { |
| 104 | struct msgb *msg = bssgp_msgb_alloc(); |
| 105 | struct bssgp_normal_hdr *bgph = |
| 106 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 107 | uint16_t _bvci = osmo_htons(bvci); |
| 108 | |
| 109 | msgb_nsei(msg) = nsei; |
| 110 | msgb_bvci(msg) = 0; /* Signalling */ |
| 111 | bgph->pdu_type = BSSGP_PDUT_BVC_RESET; |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 112 | LOGP(DLBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-RESET " |
Daniel Willmann | 2d42b90 | 2020-09-26 09:11:05 +0200 | [diff] [blame] | 113 | "CAUSE=%s\n", bvci, bssgp_cause_str(cause)); |
| 114 | |
| 115 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
| 116 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, (uint8_t *) &cause); |
| 117 | if (ra_id) { |
| 118 | uint8_t bssgp_cid[8]; |
| 119 | bssgp_create_cell_id(bssgp_cid, ra_id, cell_id); |
| 120 | msgb_tvlv_put(msg, BSSGP_IE_CELL_ID, sizeof(bssgp_cid), bssgp_cid); |
| 121 | } |
| 122 | |
| 123 | /* Optional: Feature Bitmap */ |
| 124 | |
| 125 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
| 126 | } |
| 127 | |
Max | 8b8938f | 2017-06-29 19:48:29 +0200 | [diff] [blame] | 128 | /*! Initiate reset procedure for all PTP BVC on a given NSEI. |
| 129 | * |
| 130 | * This function initiates reset procedure for all PTP BVC with a given cause. |
| 131 | * \param[in] nsei NSEI to which PTP BVC should belong to |
| 132 | * \param[in] cause Cause of BVC RESET |
| 133 | * \returns 0 on success, negative error code otherwise |
| 134 | */ |
| 135 | int bssgp_tx_bvc_ptp_reset(uint16_t nsei, enum gprs_bssgp_cause cause) |
| 136 | { |
| 137 | int rc; |
| 138 | struct bssgp_bvc_ctx *bctx; |
| 139 | |
| 140 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
| 141 | if (bctx->nsei == nsei && bctx->bvci != BVCI_SIGNALLING) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 142 | LOGP(DLBSSGP, LOGL_DEBUG, "NSEI=%u/BVCI=%u RESET due to %s\n", |
Max | 8b8938f | 2017-06-29 19:48:29 +0200 | [diff] [blame] | 143 | nsei, bctx->bvci, bssgp_cause_str(cause)); |
| 144 | rc = bssgp_tx_bvc_reset(bctx, bctx->bvci, cause); |
| 145 | if (rc < 0) |
| 146 | return rc; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | return 0; |
| 151 | } |
| 152 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 153 | /* Find a BTS context based on BVCI+NSEI tuple */ |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 154 | struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei) |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 155 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 156 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 157 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 158 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 159 | if (bctx->nsei == nsei && bctx->bvci == bvci) |
| 160 | return bctx; |
| 161 | } |
| 162 | return NULL; |
| 163 | } |
| 164 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 165 | void bssgp_set_bssgp_callback(bssgp_bvc_send ns_send, void *data) |
| 166 | { |
| 167 | bssgp_ns_send = ns_send; |
| 168 | bssgp_ns_send_data = data; |
| 169 | } |
| 170 | |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 171 | struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei) |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 172 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 173 | struct bssgp_bvc_ctx *ctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 174 | |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 175 | ctx = talloc_zero(bssgp_tall_ctx, struct bssgp_bvc_ctx); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 176 | if (!ctx) |
| 177 | return NULL; |
| 178 | ctx->bvci = bvci; |
| 179 | ctx->nsei = nsei; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 180 | /* FIXME: BVCI is not unique, only BVCI+NSEI ?!? */ |
| 181 | ctx->ctrg = rate_ctr_group_alloc(ctx, &bssgp_ctrg_desc, bvci); |
Alexander Couzens | 6a2c074 | 2020-09-16 23:09:24 +0200 | [diff] [blame] | 182 | if (!ctx->ctrg) |
| 183 | goto err_ctrg; |
| 184 | |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 185 | ctx->fc = talloc_zero(ctx, struct bssgp_flow_control); |
Alexander Couzens | 6a2c074 | 2020-09-16 23:09:24 +0200 | [diff] [blame] | 186 | if (!ctx->fc) |
| 187 | goto err_fc; |
| 188 | |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 189 | /* cofigure for 2Mbit, 30 packets in queue */ |
| 190 | bssgp_fc_init(ctx->fc, 100000, 2*1024*1024/8, 30, &_bssgp_tx_dl_ud); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 191 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 192 | llist_add(&ctx->list, &bssgp_bvc_ctxts); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 193 | |
| 194 | return ctx; |
Alexander Couzens | 6a2c074 | 2020-09-16 23:09:24 +0200 | [diff] [blame] | 195 | |
| 196 | err_fc: |
| 197 | rate_ctr_group_free(ctx->ctrg); |
| 198 | err_ctrg: |
| 199 | talloc_free(ctx); |
| 200 | return NULL; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Vadim Yanitskiy | 8eae2fc | 2019-11-09 01:45:11 +0700 | [diff] [blame] | 203 | void bssgp_bvc_ctx_free(struct bssgp_bvc_ctx *ctx) |
| 204 | { |
| 205 | if (!ctx) |
| 206 | return; |
Alexander Couzens | 495b4a7 | 2020-09-16 23:10:03 +0200 | [diff] [blame] | 207 | |
| 208 | osmo_timer_del(&ctx->fc->timer); |
Vadim Yanitskiy | 8eae2fc | 2019-11-09 01:45:11 +0700 | [diff] [blame] | 209 | rate_ctr_group_free(ctx->ctrg); |
| 210 | llist_del(&ctx->list); |
| 211 | talloc_free(ctx); |
| 212 | } |
| 213 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 214 | /* Chapter 10.4.5: Flow Control BVC ACK */ |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 215 | static int bssgp_tx_fc_bvc_ack(uint16_t nsei, uint8_t tag, uint16_t ns_bvci) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 216 | { |
| 217 | struct msgb *msg = bssgp_msgb_alloc(); |
| 218 | struct bssgp_normal_hdr *bgph = |
| 219 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 220 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 221 | msgb_nsei(msg) = nsei; |
| 222 | msgb_bvci(msg) = ns_bvci; |
| 223 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 224 | bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_BVC_ACK; |
| 225 | msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag); |
| 226 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 227 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 230 | /* 10.3.7 SUSPEND-ACK PDU */ |
| 231 | int bssgp_tx_suspend_ack(uint16_t nsei, uint32_t tlli, |
| 232 | const struct gprs_ra_id *ra_id, uint8_t suspend_ref) |
| 233 | { |
| 234 | struct msgb *msg = bssgp_msgb_alloc(); |
| 235 | struct bssgp_normal_hdr *bgph = |
| 236 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 237 | |
| 238 | msgb_nsei(msg) = nsei; |
| 239 | msgb_bvci(msg) = 0; /* Signalling */ |
| 240 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_ACK; |
| 241 | |
Max | e29ec85 | 2018-01-05 14:30:22 +0100 | [diff] [blame] | 242 | bssgp_msgb_tlli_put(msg, tlli); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 243 | bssgp_msgb_ra_put(msg, ra_id); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 244 | msgb_tvlv_put(msg, BSSGP_IE_SUSPEND_REF_NR, 1, &suspend_ref); |
| 245 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 246 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | /* 10.3.8 SUSPEND-NACK PDU */ |
| 250 | int bssgp_tx_suspend_nack(uint16_t nsei, uint32_t tlli, |
Dieter Spaar | d2b13fc | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 251 | const struct gprs_ra_id *ra_id, |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 252 | uint8_t *cause) |
| 253 | { |
| 254 | struct msgb *msg = bssgp_msgb_alloc(); |
| 255 | struct bssgp_normal_hdr *bgph = |
| 256 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 257 | |
| 258 | msgb_nsei(msg) = nsei; |
| 259 | msgb_bvci(msg) = 0; /* Signalling */ |
| 260 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 261 | |
Max | e29ec85 | 2018-01-05 14:30:22 +0100 | [diff] [blame] | 262 | bssgp_msgb_tlli_put(msg, tlli); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 263 | bssgp_msgb_ra_put(msg, ra_id); |
| 264 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 265 | if (cause) |
| 266 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 267 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 268 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* 10.3.10 RESUME-ACK PDU */ |
| 272 | int bssgp_tx_resume_ack(uint16_t nsei, uint32_t tlli, |
| 273 | const struct gprs_ra_id *ra_id) |
| 274 | { |
| 275 | struct msgb *msg = bssgp_msgb_alloc(); |
| 276 | struct bssgp_normal_hdr *bgph = |
| 277 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 278 | |
| 279 | msgb_nsei(msg) = nsei; |
| 280 | msgb_bvci(msg) = 0; /* Signalling */ |
| 281 | bgph->pdu_type = BSSGP_PDUT_RESUME_ACK; |
| 282 | |
Max | e29ec85 | 2018-01-05 14:30:22 +0100 | [diff] [blame] | 283 | bssgp_msgb_tlli_put(msg, tlli); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 284 | bssgp_msgb_ra_put(msg, ra_id); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 285 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 286 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* 10.3.11 RESUME-NACK PDU */ |
| 290 | int bssgp_tx_resume_nack(uint16_t nsei, uint32_t tlli, |
| 291 | const struct gprs_ra_id *ra_id, uint8_t *cause) |
| 292 | { |
| 293 | struct msgb *msg = bssgp_msgb_alloc(); |
| 294 | struct bssgp_normal_hdr *bgph = |
| 295 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 296 | |
| 297 | msgb_nsei(msg) = nsei; |
| 298 | msgb_bvci(msg) = 0; /* Signalling */ |
| 299 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 300 | |
Max | e29ec85 | 2018-01-05 14:30:22 +0100 | [diff] [blame] | 301 | bssgp_msgb_tlli_put(msg, tlli); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 302 | bssgp_msgb_ra_put(msg, ra_id); |
| 303 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 304 | if (cause) |
| 305 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 306 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 307 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 308 | } |
| 309 | |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 310 | uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf) |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 311 | { |
| 312 | /* 6 octets RAC */ |
| 313 | gsm48_parse_ra(raid, buf); |
| 314 | /* 2 octets CID */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 315 | return osmo_load16be(buf+6); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 316 | } |
| 317 | |
Harald Welte | 2861007 | 2011-11-24 21:32:07 +0100 | [diff] [blame] | 318 | int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, |
| 319 | uint16_t cid) |
| 320 | { |
Harald Welte | 2861007 | 2011-11-24 21:32:07 +0100 | [diff] [blame] | 321 | /* 6 octets RAC */ |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 322 | gsm48_encode_ra((struct gsm48_ra_id *)buf, raid); |
Harald Welte | 2861007 | 2011-11-24 21:32:07 +0100 | [diff] [blame] | 323 | /* 2 octets CID */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 324 | osmo_store16be(cid, buf+6); |
Harald Welte | 2861007 | 2011-11-24 21:32:07 +0100 | [diff] [blame] | 325 | |
| 326 | return 8; |
| 327 | } |
| 328 | |
Philipp Maier | bd10c21 | 2020-12-14 22:28:19 +0100 | [diff] [blame] | 329 | /*! Parse a RIM Routing information IE (3GPP TS 48.018, chapter 11.3.70). |
| 330 | * \param[out] ri user provided memory to store the parsed results. |
| 331 | * \param[in] buf input buffer of the value part of the IE. |
| 332 | * \returns length of parsed octets, -EINVAL on error. */ |
| 333 | int bssgp_parse_rim_ri(struct bssgp_rim_routing_info *ri, const uint8_t *buf, |
| 334 | unsigned int len) |
| 335 | { |
| 336 | struct gprs_ra_id raid_temp; |
| 337 | |
| 338 | memset(ri, 0, sizeof(*ri)); |
| 339 | if (len < 2) |
| 340 | return -EINVAL; |
| 341 | |
| 342 | ri->discr = buf[0] & 0x0f; |
| 343 | |
| 344 | switch (ri->discr) { |
| 345 | case BSSGP_RIM_ROUTING_INFO_GERAN: |
| 346 | if (len < 9) |
| 347 | return -EINVAL; |
| 348 | ri->geran.cid = bssgp_parse_cell_id(&ri->geran.raid, buf + 1); |
| 349 | return 9; |
| 350 | case BSSGP_RIM_ROUTING_INFO_UTRAN: |
| 351 | if (len < 9) |
| 352 | return -EINVAL; |
| 353 | gsm48_parse_ra(&ri->utran.raid, buf + 1); |
| 354 | ri->utran.rncid = osmo_load16be(buf + 7); |
| 355 | return 9; |
| 356 | case BSSGP_RIM_ROUTING_INFO_EUTRAN: |
| 357 | if (len < 7 || len > 14) |
| 358 | return -EINVAL; |
| 359 | /* Note: 3GPP TS 24.301 Figure 9.9.3.32.1 and 3GPP TS 24.008 |
| 360 | * Figure 10.5.130 specify MCC/MNC encoding in the same way, |
| 361 | * so we can re-use gsm48_parse_ra() for that. */ |
| 362 | gsm48_parse_ra(&raid_temp, buf + 1); |
| 363 | ri->eutran.tai.mcc = raid_temp.mcc; |
| 364 | ri->eutran.tai.mnc = raid_temp.mnc; |
| 365 | ri->eutran.tai.mnc_3_digits = raid_temp.mnc_3_digits; |
| 366 | ri->eutran.tai.tac = osmo_load16be(buf + 4); |
| 367 | memcpy(ri->eutran.global_enb_id, buf + 6, len - 6); |
| 368 | ri->eutran.global_enb_id_len = len - 6; |
| 369 | return len; |
| 370 | default: |
| 371 | return -EINVAL; |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | /*! Encode a RIM Routing information IE (3GPP TS 48.018, chapter 11.3.70). |
| 376 | * \param[out] buf user provided memory (at least 14 byte) for the generated value part of the IE. |
| 377 | * \param[in] ri user provided input data struct. |
| 378 | * \returns length of encoded octets, -EINVAL on error. */ |
| 379 | int bssgp_create_rim_ri(uint8_t *buf, const struct bssgp_rim_routing_info *ri) |
| 380 | { |
| 381 | int rc; |
| 382 | struct gprs_ra_id raid_temp; |
| 383 | |
| 384 | buf[0] = ri->discr & 0x0f; |
| 385 | buf++; |
| 386 | |
| 387 | switch (ri->discr) { |
| 388 | case BSSGP_RIM_ROUTING_INFO_GERAN: |
| 389 | rc = bssgp_create_cell_id(buf, &ri->geran.raid, ri->geran.cid); |
| 390 | if (rc < 0) |
| 391 | return -EINVAL; |
| 392 | return rc + 1; |
| 393 | case BSSGP_RIM_ROUTING_INFO_UTRAN: |
| 394 | gsm48_encode_ra((struct gsm48_ra_id *)buf, &ri->utran.raid); |
| 395 | osmo_store16be(ri->utran.rncid, buf + 6); |
| 396 | return 9; |
| 397 | case BSSGP_RIM_ROUTING_INFO_EUTRAN: |
| 398 | /* Note: 3GPP TS 24.301 Figure 9.9.3.32.1 and 3GPP TS 24.008 |
| 399 | * Figure 10.5.130 specify MCC/MNC encoding in the same way, |
| 400 | * so we can re-use gsm48_encode_ra() for that. */ |
Vadim Yanitskiy | c9f4c49 | 2021-01-05 14:53:25 +0100 | [diff] [blame] | 401 | raid_temp = (struct gprs_ra_id) { |
| 402 | .mcc = ri->eutran.tai.mcc, |
| 403 | .mnc = ri->eutran.tai.mnc, |
| 404 | .mnc_3_digits = ri->eutran.tai.mnc_3_digits, |
Vadim Yanitskiy | e2ad6eb | 2021-01-05 14:55:38 +0100 | [diff] [blame] | 405 | /* TAC is encoded in the same way as LAC */ |
| 406 | .lac = ri->eutran.tai.tac, |
Vadim Yanitskiy | c9f4c49 | 2021-01-05 14:53:25 +0100 | [diff] [blame] | 407 | }; |
| 408 | |
Philipp Maier | bd10c21 | 2020-12-14 22:28:19 +0100 | [diff] [blame] | 409 | gsm48_encode_ra((struct gsm48_ra_id *)buf, &raid_temp); |
Philipp Maier | bd10c21 | 2020-12-14 22:28:19 +0100 | [diff] [blame] | 410 | OSMO_ASSERT(ri->eutran.global_enb_id_len <= |
| 411 | sizeof(ri->eutran.global_enb_id)); |
| 412 | memcpy(buf + 5, ri->eutran.global_enb_id, |
| 413 | ri->eutran.global_enb_id_len); |
| 414 | return ri->eutran.global_enb_id_len + 6; |
| 415 | default: |
| 416 | return -EINVAL; |
| 417 | } |
| 418 | } |
| 419 | |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 420 | /* Chapter 8.4 BVC-Reset Procedure */ |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 421 | static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 422 | uint16_t ns_bvci) |
| 423 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 424 | struct osmo_bssgp_prim nmp; |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 425 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 426 | uint16_t nsei = msgb_nsei(msg); |
| 427 | uint16_t bvci; |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 428 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 429 | bvci = tlvp_val16be(tp, BSSGP_IE_BVCI); |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 430 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx RESET cause=%s\n", bvci, |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 431 | bssgp_cause_str(*TLVP_VAL(tp, BSSGP_IE_CAUSE))); |
| 432 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 433 | /* look-up or create the BTS context for this BVC */ |
| 434 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 435 | if (!bctx) |
| 436 | bctx = btsctx_alloc(bvci, nsei); |
| 437 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 438 | /* As opposed to NS-VCs, BVCs are NOT blocked after RESET */ |
| 439 | bctx->state &= ~BVC_S_BLOCKED; |
| 440 | |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 441 | /* When we receive a BVC-RESET PDU (at least of a PTP BVCI), the BSS |
| 442 | * informs us about its RAC + Cell ID, so we can create a mapping */ |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 443 | if (bvci != 0 && bvci != 1) { |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 444 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_CELL_ID, 8)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 445 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx RESET " |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 446 | "missing mandatory IE\n", bvci); |
| 447 | return -EINVAL; |
| 448 | } |
| 449 | /* actually extract RAC / CID */ |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 450 | bctx->cell_id = bssgp_parse_cell_id(&bctx->ra_id, |
| 451 | TLVP_VAL(tp, BSSGP_IE_CELL_ID)); |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 452 | LOGP(DLBSSGP, LOGL_NOTICE, "Cell %s CI %u on BVCI %u\n", |
Neels Hofmeyr | c4fce14 | 2018-02-20 13:47:08 +0100 | [diff] [blame] | 453 | osmo_rai_name(&bctx->ra_id), bctx->cell_id, bvci); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 454 | } |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 455 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 456 | /* Send NM_BVC_RESET.ind to NM */ |
| 457 | memset(&nmp, 0, sizeof(nmp)); |
| 458 | nmp.nsei = nsei; |
| 459 | nmp.bvci = bvci; |
| 460 | nmp.tp = tp; |
| 461 | nmp.ra_id = &bctx->ra_id; |
| 462 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_RESET, |
| 463 | PRIM_OP_INDICATION, msg); |
| 464 | bssgp_prim_cb(&nmp.oph, NULL); |
| 465 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 466 | /* Acknowledge the RESET to the BTS */ |
Harald Welte | 5b3bffb | 2012-09-07 12:03:40 +0200 | [diff] [blame] | 467 | bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
| 468 | nsei, bvci, ns_bvci); |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 469 | return 0; |
| 470 | } |
| 471 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 472 | static int bssgp_rx_bvc_block(struct msgb *msg, struct tlv_parsed *tp) |
| 473 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 474 | struct osmo_bssgp_prim nmp; |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 475 | uint16_t bvci, nsei = msgb_nsei(msg); |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 476 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 477 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 478 | bvci = tlvp_val16be(tp, BSSGP_IE_BVCI); |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 479 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 480 | /* 8.3.2: Signalling BVC shall never be blocked */ |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 481 | LOGP(DLBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 482 | "received block for signalling BVC!?!\n", |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 483 | nsei, msgb_bvci(msg)); |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 484 | return 0; |
| 485 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 486 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 487 | LOGP(DLBSSGP, LOGL_INFO, "BSSGP Rx BVCI=%u BVC-BLOCK\n", bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 488 | |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 489 | ptp_ctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 490 | if (!ptp_ctx) |
| 491 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 492 | |
| 493 | ptp_ctx->state |= BVC_S_BLOCKED; |
| 494 | rate_ctr_inc(&ptp_ctx->ctrg->ctr[BSSGP_CTR_BLOCKED]); |
| 495 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 496 | /* Send NM_BVC_BLOCK.ind to NM */ |
| 497 | memset(&nmp, 0, sizeof(nmp)); |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 498 | nmp.nsei = nsei; |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 499 | nmp.bvci = bvci; |
| 500 | nmp.tp = tp; |
| 501 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_BLOCK, |
| 502 | PRIM_OP_INDICATION, msg); |
| 503 | bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 504 | |
| 505 | /* We always acknowledge the BLOCKing */ |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 506 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, nsei, |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 507 | bvci, msgb_bvci(msg)); |
| 508 | }; |
| 509 | |
| 510 | static int bssgp_rx_bvc_unblock(struct msgb *msg, struct tlv_parsed *tp) |
| 511 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 512 | struct osmo_bssgp_prim nmp; |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 513 | uint16_t bvci, nsei = msgb_nsei(msg); |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 514 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 515 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 516 | bvci = tlvp_val16be(tp, BSSGP_IE_BVCI); |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 517 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 518 | /* 8.3.2: Signalling BVC shall never be blocked */ |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 519 | LOGP(DLBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 520 | "received unblock for signalling BVC!?!\n", |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 521 | nsei, msgb_bvci(msg)); |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 522 | return 0; |
| 523 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 524 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 525 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx BVC-UNBLOCK\n", bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 526 | |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 527 | ptp_ctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 528 | if (!ptp_ctx) |
| 529 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 530 | |
| 531 | ptp_ctx->state &= ~BVC_S_BLOCKED; |
| 532 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 533 | /* Send NM_BVC_UNBLOCK.ind to NM */ |
| 534 | memset(&nmp, 0, sizeof(nmp)); |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 535 | nmp.nsei = nsei; |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 536 | nmp.bvci = bvci; |
| 537 | nmp.tp = tp; |
| 538 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_UNBLOCK, |
| 539 | PRIM_OP_INDICATION, msg); |
| 540 | bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 541 | |
| 542 | /* We always acknowledge the unBLOCKing */ |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 543 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, nsei, |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 544 | bvci, msgb_bvci(msg)); |
| 545 | }; |
| 546 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 547 | /* Uplink unit-data */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 548 | static int bssgp_rx_ul_ud(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 549 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 550 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 551 | struct osmo_bssgp_prim gbp; |
Harald Welte | ec19c10 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 552 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 553 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 554 | /* extract TLLI and parse TLV IEs */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 555 | msgb_tlli(msg) = osmo_ntohl(budh->tlli); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 556 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 557 | DEBUGP(DLBSSGP, "BSSGP TLLI=0x%08x Rx UPLINK-UNITDATA\n", msgb_tlli(msg)); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 558 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 559 | /* Cell ID and LLC_PDU are the only mandatory IE */ |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 560 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_CELL_ID, 8) || |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 561 | !TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 562 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP TLLI=0x%08x Rx UL-UD " |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 563 | "missing mandatory IE\n", msgb_tlli(msg)); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 564 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 565 | } |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 566 | |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 567 | /* store pointer to LLC header and CELL ID in msgb->cb */ |
Holger Hans Peter Freyther | b6eded8 | 2010-05-23 21:11:19 +0800 | [diff] [blame] | 568 | msgb_llch(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_LLC_PDU); |
| 569 | msgb_bcid(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_CELL_ID); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 570 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 571 | /* Send BSSGP_UL_UD.ind to NM */ |
| 572 | memset(&gbp, 0, sizeof(gbp)); |
| 573 | gbp.nsei = ctx->nsei; |
| 574 | gbp.bvci = ctx->bvci; |
| 575 | gbp.tlli = msgb_tlli(msg); |
| 576 | gbp.tp = tp; |
| 577 | osmo_prim_init(&gbp.oph, SAP_BSSGP_LL, PRIM_BSSGP_UL_UD, |
| 578 | PRIM_OP_INDICATION, msg); |
| 579 | return bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 580 | } |
| 581 | |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 582 | static int bssgp_rx_suspend(struct msgb *msg, struct tlv_parsed *tp) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 583 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 584 | struct osmo_bssgp_prim gbp; |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 585 | struct gprs_ra_id raid; |
| 586 | uint32_t tlli; |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 587 | uint16_t ns_bvci = msgb_bvci(msg), nsei = msgb_nsei(msg); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 588 | int rc; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 589 | |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 590 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_TLLI, 4) || |
| 591 | !TLVP_PRES_LEN(tp, BSSGP_IE_ROUTEING_AREA, 6)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 592 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx SUSPEND " |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 593 | "missing mandatory IE\n", ns_bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 594 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 595 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 596 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 597 | tlli = tlvp_val32be(tp, BSSGP_IE_TLLI); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 598 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 599 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u TLLI=0x%08x Rx SUSPEND\n", |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 600 | ns_bvci, tlli); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 601 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 602 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 603 | |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 604 | /* Inform GMM about the SUSPEND request */ |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 605 | memset(&gbp, 0, sizeof(gbp)); |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 606 | gbp.nsei = nsei; |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 607 | gbp.bvci = ns_bvci; |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 608 | gbp.tlli = tlli; |
| 609 | gbp.ra_id = &raid; |
| 610 | osmo_prim_init(&gbp.oph, SAP_BSSGP_GMM, PRIM_BSSGP_GMM_SUSPEND, |
| 611 | PRIM_OP_REQUEST, msg); |
| 612 | |
| 613 | rc = bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 614 | if (rc < 0) |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 615 | return bssgp_tx_suspend_nack(nsei, tlli, &raid, NULL); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 616 | |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 617 | bssgp_tx_suspend_ack(nsei, tlli, &raid, 0); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 618 | |
Holger Hans Peter Freyther | d30cefa | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 619 | return 0; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 620 | } |
| 621 | |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 622 | static int bssgp_rx_resume(struct msgb *msg, struct tlv_parsed *tp) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 623 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 624 | struct osmo_bssgp_prim gbp; |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 625 | struct gprs_ra_id raid; |
| 626 | uint32_t tlli; |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 627 | uint8_t suspend_ref; |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 628 | uint16_t ns_bvci = msgb_bvci(msg), nsei = msgb_nsei(msg); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 629 | int rc; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 630 | |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 631 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_TLLI, 4 ) || |
| 632 | !TLVP_PRES_LEN(tp, BSSGP_IE_ROUTEING_AREA, 6) || |
| 633 | !TLVP_PRES_LEN(tp, BSSGP_IE_SUSPEND_REF_NR, 1)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 634 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx RESUME " |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 635 | "missing mandatory IE\n", ns_bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 636 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 637 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 638 | |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 639 | tlli = tlvp_val32be(tp, BSSGP_IE_TLLI); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 640 | suspend_ref = *TLVP_VAL(tp, BSSGP_IE_SUSPEND_REF_NR); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 641 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 642 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u TLLI=0x%08x Rx RESUME\n", ns_bvci, tlli); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 643 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 644 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 645 | |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 646 | /* Inform GMM about the RESUME request */ |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 647 | memset(&gbp, 0, sizeof(gbp)); |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 648 | gbp.nsei = nsei; |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 649 | gbp.bvci = ns_bvci; |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 650 | gbp.tlli = tlli; |
| 651 | gbp.ra_id = &raid; |
| 652 | gbp.u.resume.suspend_ref = suspend_ref; |
| 653 | osmo_prim_init(&gbp.oph, SAP_BSSGP_GMM, PRIM_BSSGP_GMM_RESUME, |
| 654 | PRIM_OP_REQUEST, msg); |
| 655 | |
| 656 | rc = bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 657 | if (rc < 0) |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 658 | return bssgp_tx_resume_nack(nsei, tlli, &raid, |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 659 | NULL); |
| 660 | |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 661 | bssgp_tx_resume_ack(nsei, tlli, &raid); |
Holger Hans Peter Freyther | d30cefa | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 662 | return 0; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 663 | } |
| 664 | |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 665 | |
| 666 | static int bssgp_rx_llc_disc(struct msgb *msg, struct tlv_parsed *tp, |
| 667 | struct bssgp_bvc_ctx *ctx) |
| 668 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 669 | struct osmo_bssgp_prim nmp; |
Harald Welte | b736314 | 2010-07-23 21:59:29 +0200 | [diff] [blame] | 670 | uint32_t tlli = 0; |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 671 | uint16_t nsei = msgb_nsei(msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 672 | |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 673 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_TLLI, 4) || |
| 674 | !TLVP_PRES_LEN(tp, BSSGP_IE_LLC_FRAMES_DISCARDED, 1) || |
| 675 | !TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2) || |
| 676 | !TLVP_PRES_LEN(tp, BSSGP_IE_NUM_OCT_AFF, 3)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 677 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx LLC DISCARDED " |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 678 | "missing mandatory IE\n", ctx->bvci); |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 679 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 680 | } |
| 681 | |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 682 | tlli = tlvp_val32be(tp, BSSGP_IE_TLLI); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 683 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 684 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u TLLI=%08x Rx LLC DISCARDED\n", |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 685 | ctx->bvci, tlli); |
| 686 | |
| 687 | rate_ctr_inc(&ctx->ctrg->ctr[BSSGP_CTR_DISCARDED]); |
| 688 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 689 | /* send NM_LLC_DISCARDED to NM */ |
| 690 | memset(&nmp, 0, sizeof(nmp)); |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 691 | nmp.nsei = nsei; |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 692 | nmp.bvci = ctx->bvci; |
| 693 | nmp.tlli = tlli; |
| 694 | nmp.tp = tp; |
| 695 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_LLC_DISCARDED, |
| 696 | PRIM_OP_INDICATION, msg); |
| 697 | |
| 698 | return bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 699 | } |
| 700 | |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 701 | int bssgp_rx_status(struct msgb *msg, struct tlv_parsed *tp, |
| 702 | uint16_t bvci, struct bssgp_bvc_ctx *bctx) |
| 703 | { |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 704 | uint16_t nsei = msgb_nsei(msg); |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 705 | struct osmo_bssgp_prim nmp; |
| 706 | enum gprs_bssgp_cause cause; |
| 707 | |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 708 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_CAUSE, 1)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 709 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx STATUS " |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 710 | "missing mandatory IE\n", bvci); |
| 711 | cause = BSSGP_CAUSE_PROTO_ERR_UNSPEC; |
| 712 | } else { |
| 713 | cause = *TLVP_VAL(tp, BSSGP_IE_CAUSE); |
| 714 | } |
| 715 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 716 | LOGP(DLBSSGP, LOGL_NOTICE, "BSSGP BVCI=%u Rx BVC STATUS, cause=%s\n", |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 717 | bvci, bssgp_cause_str(cause)); |
| 718 | |
| 719 | if (cause == BSSGP_CAUSE_BVCI_BLOCKED || cause == BSSGP_CAUSE_UNKNOWN_BVCI) { |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 720 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2)) |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 721 | LOGP(DLBSSGP, LOGL_ERROR, |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 722 | "BSSGP BVCI=%u Rx STATUS cause=%s " |
| 723 | "missing conditional BVCI IE\n", |
| 724 | bvci, bssgp_cause_str(cause)); |
| 725 | } |
| 726 | |
| 727 | if (bctx) |
| 728 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_STATUS]); |
| 729 | |
| 730 | /* send NM_STATUS to NM */ |
| 731 | memset(&nmp, 0, sizeof(nmp)); |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 732 | nmp.nsei = nsei; |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 733 | nmp.bvci = bvci; |
| 734 | nmp.tp = tp; |
| 735 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_STATUS, |
| 736 | PRIM_OP_INDICATION, msg); |
| 737 | |
| 738 | return bssgp_prim_cb(&nmp.oph, NULL); |
| 739 | } |
| 740 | |
Philipp Maier | 1eaa7bc | 2020-12-16 21:07:04 +0100 | [diff] [blame] | 741 | static int bssgp_rx_rim(struct msgb *msg, struct tlv_parsed *tp, uint16_t bvci) |
| 742 | { |
| 743 | struct osmo_bssgp_prim nmp; |
| 744 | uint16_t nsei = msgb_nsei(msg); |
| 745 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *)msgb_bssgph(msg); |
| 746 | enum bssgp_prim prim; |
| 747 | |
| 748 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx RIM-PDU:%s\n", bvci, bssgp_pdu_str(bgph->pdu_type)); |
| 749 | |
| 750 | /* Specify PRIM type based on the RIM PDU */ |
| 751 | switch (bgph->pdu_type) { |
| 752 | case BSSGP_PDUT_RAN_INFO: |
| 753 | case BSSGP_PDUT_RAN_INFO_REQ: |
| 754 | case BSSGP_PDUT_RAN_INFO_ACK: |
| 755 | case BSSGP_PDUT_RAN_INFO_ERROR: |
| 756 | case BSSGP_PDUT_RAN_INFO_APP_ERROR: |
| 757 | prim = PRIM_BSSGP_RIM_PDU_TRANSFER; |
| 758 | break; |
| 759 | default: |
| 760 | /* Caller already makes sure that this can't happen. */ |
| 761 | OSMO_ASSERT(false); |
| 762 | } |
| 763 | |
| 764 | /* Send BSSGP RIM indication to NM */ |
| 765 | memset(&nmp, 0, sizeof(nmp)); |
| 766 | nmp.nsei = nsei; |
| 767 | nmp.bvci = bvci; |
| 768 | nmp.tp = tp; |
| 769 | osmo_prim_init(&nmp.oph, SAP_BSSGP_RIM, prim, PRIM_OP_INDICATION, msg); |
| 770 | bssgp_prim_cb(&nmp.oph, NULL); |
| 771 | |
| 772 | return 0; |
| 773 | } |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 774 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 775 | /* One element (msgb) in a BSSGP Flow Control queue */ |
| 776 | struct bssgp_fc_queue_element { |
| 777 | /* linked list of queue elements */ |
| 778 | struct llist_head list; |
| 779 | /* The message that we have enqueued */ |
| 780 | struct msgb *msg; |
| 781 | /* Length of the LLC PDU part of the contained message */ |
| 782 | uint32_t llc_pdu_len; |
| 783 | /* private pointer passed to the flow control out_cb function */ |
| 784 | void *priv; |
| 785 | }; |
| 786 | |
| 787 | static int fc_queue_timer_cfg(struct bssgp_flow_control *fc); |
| 788 | static int bssgp_fc_needs_queueing(struct bssgp_flow_control *fc, uint32_t pdu_len); |
| 789 | |
| 790 | static void fc_timer_cb(void *data) |
| 791 | { |
| 792 | struct bssgp_flow_control *fc = data; |
| 793 | struct bssgp_fc_queue_element *fcqe; |
| 794 | struct timeval time_now; |
| 795 | |
| 796 | /* if the queue is empty, we return without sending something |
| 797 | * and without re-starting the timer */ |
| 798 | if (llist_empty(&fc->queue)) |
| 799 | return; |
| 800 | |
| 801 | /* get the first entry from the queue */ |
| 802 | fcqe = llist_entry(fc->queue.next, struct bssgp_fc_queue_element, |
| 803 | list); |
| 804 | |
| 805 | if (bssgp_fc_needs_queueing(fc, fcqe->llc_pdu_len)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 806 | LOGP(DLBSSGP, LOGL_NOTICE, "BSSGP-FC: fc_timer_cb() but still " |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 807 | "not able to send PDU of %u bytes\n", fcqe->llc_pdu_len); |
| 808 | /* make sure we re-start the timer */ |
| 809 | fc_queue_timer_cfg(fc); |
| 810 | return; |
| 811 | } |
| 812 | |
| 813 | /* remove from the queue */ |
| 814 | llist_del(&fcqe->list); |
| 815 | |
| 816 | fc->queue_depth--; |
| 817 | |
| 818 | /* record the time we transmitted this PDU */ |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 819 | osmo_gettimeofday(&time_now, NULL); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 820 | fc->time_last_pdu = time_now; |
| 821 | |
| 822 | /* call the output callback for this FC instance */ |
| 823 | fc->out_cb(fcqe->priv, fcqe->msg, fcqe->llc_pdu_len, NULL); |
| 824 | |
| 825 | /* we expect that out_cb will in the end free the msgb once |
| 826 | * it is no longer needed */ |
| 827 | |
| 828 | /* but we have to free the queue element ourselves */ |
| 829 | talloc_free(fcqe); |
| 830 | |
| 831 | /* re-configure the timer for the next PDU */ |
| 832 | fc_queue_timer_cfg(fc); |
| 833 | } |
| 834 | |
| 835 | /* configure/schedule the flow control timer to expire once the bucket |
| 836 | * will have leaked a sufficient number of bytes to transmit the next |
| 837 | * PDU in the queue */ |
| 838 | static int fc_queue_timer_cfg(struct bssgp_flow_control *fc) |
| 839 | { |
| 840 | struct bssgp_fc_queue_element *fcqe; |
| 841 | uint32_t msecs; |
| 842 | |
| 843 | if (llist_empty(&fc->queue)) |
| 844 | return 0; |
| 845 | |
Jacob Erlbeck | 9731935 | 2015-04-30 19:28:03 +0200 | [diff] [blame] | 846 | fcqe = llist_entry(fc->queue.next, struct bssgp_fc_queue_element, |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 847 | list); |
| 848 | |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 849 | if (fc->bucket_leak_rate != 0) { |
| 850 | /* Calculate the point in time at which we will have leaked |
| 851 | * a sufficient number of bytes from the bucket to transmit |
| 852 | * the first PDU in the queue */ |
| 853 | msecs = (fcqe->llc_pdu_len * 1000) / fc->bucket_leak_rate; |
| 854 | /* FIXME: add that time to fc->time_last_pdu and subtract it from |
| 855 | * current time */ |
Pablo Neira Ayuso | 44f423f | 2017-05-08 18:00:28 +0200 | [diff] [blame] | 856 | osmo_timer_setup(&fc->timer, fc_timer_cb, fc); |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 857 | osmo_timer_schedule(&fc->timer, msecs / 1000, (msecs % 1000) * 1000); |
| 858 | } else { |
| 859 | /* If the PCU is telling us to not send any more data at all, |
| 860 | * there's no point starting a timer. */ |
| 861 | } |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | /* Enqueue a PDU in the flow control queue for delayed transmission */ |
| 867 | static int fc_enqueue(struct bssgp_flow_control *fc, struct msgb *msg, |
| 868 | uint32_t llc_pdu_len, void *priv) |
| 869 | { |
| 870 | struct bssgp_fc_queue_element *fcqe; |
| 871 | |
| 872 | if (fc->queue_depth >= fc->max_queue_depth) |
| 873 | return -ENOSPC; |
| 874 | |
| 875 | fcqe = talloc_zero(fc, struct bssgp_fc_queue_element); |
| 876 | if (!fcqe) |
| 877 | return -ENOMEM; |
| 878 | fcqe->msg = msg; |
| 879 | fcqe->llc_pdu_len = llc_pdu_len; |
| 880 | fcqe->priv = priv; |
| 881 | |
| 882 | llist_add_tail(&fcqe->list, &fc->queue); |
| 883 | |
| 884 | fc->queue_depth++; |
| 885 | |
| 886 | /* re-configure the timer for dequeueing the pdu */ |
| 887 | fc_queue_timer_cfg(fc); |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | /* According to Section 8.2 */ |
| 893 | static int bssgp_fc_needs_queueing(struct bssgp_flow_control *fc, uint32_t pdu_len) |
| 894 | { |
| 895 | struct timeval time_now, time_diff; |
| 896 | int64_t bucket_predicted; |
| 897 | uint32_t csecs_elapsed, leaked; |
| 898 | |
| 899 | /* B' = B + L(p) - (Tc - Tp)*R */ |
| 900 | |
| 901 | /* compute number of centi-seconds that have elapsed since transmitting |
| 902 | * the last PDU (Tc - Tp) */ |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 903 | osmo_gettimeofday(&time_now, NULL); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 904 | timersub(&time_now, &fc->time_last_pdu, &time_diff); |
| 905 | csecs_elapsed = time_diff.tv_sec*100 + time_diff.tv_usec/10000; |
| 906 | |
| 907 | /* compute number of bytes that have leaked in the elapsed number |
| 908 | * of centi-seconds */ |
| 909 | leaked = csecs_elapsed * (fc->bucket_leak_rate / 100); |
| 910 | /* add the current PDU length to the last bucket level */ |
| 911 | bucket_predicted = fc->bucket_counter + pdu_len; |
| 912 | /* ... and subtract the number of leaked bytes */ |
| 913 | bucket_predicted -= leaked; |
| 914 | |
Vadim Yanitskiy | f178695 | 2017-06-12 03:41:35 +0700 | [diff] [blame] | 915 | if (bucket_predicted < pdu_len) |
| 916 | return 0; |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 917 | |
| 918 | if (bucket_predicted <= fc->bucket_size_max) { |
| 919 | /* the bucket is not full yet, we can pass the packet */ |
| 920 | fc->bucket_counter = bucket_predicted; |
Vadim Yanitskiy | f178695 | 2017-06-12 03:41:35 +0700 | [diff] [blame] | 921 | return 0; |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | /* bucket is full, PDU needs to be delayed */ |
| 925 | return 1; |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /* output callback for BVC flow control */ |
| 929 | static int _bssgp_tx_dl_ud(struct bssgp_flow_control *fc, struct msgb *msg, |
| 930 | uint32_t llc_pdu_len, void *priv) |
| 931 | { |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 932 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | /* input function of the flow control implementation, called first |
| 936 | * for the MM flow control, and then as the MM flow control output |
| 937 | * callback in order to perform BVC flow control */ |
| 938 | int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, |
| 939 | uint32_t llc_pdu_len, void *priv) |
| 940 | { |
| 941 | struct timeval time_now; |
| 942 | |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 943 | if (llc_pdu_len > fc->bucket_size_max) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 944 | LOGP(DLBSSGP, LOGL_NOTICE, "Single PDU (size=%u) is larger " |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 945 | "than maximum bucket size (%u)!\n", llc_pdu_len, |
| 946 | fc->bucket_size_max); |
Holger Hans Peter Freyther | 10dd73c | 2014-10-10 17:24:34 +0200 | [diff] [blame] | 947 | msgb_free(msg); |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 948 | return -EIO; |
| 949 | } |
| 950 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 951 | if (bssgp_fc_needs_queueing(fc, llc_pdu_len)) { |
Neels Hofmeyr | cd325ef | 2017-11-16 22:32:36 +0100 | [diff] [blame] | 952 | int rc; |
| 953 | rc = fc_enqueue(fc, msg, llc_pdu_len, priv); |
| 954 | if (rc) |
| 955 | msgb_free(msg); |
| 956 | return rc; |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 957 | } else { |
| 958 | /* record the time we transmitted this PDU */ |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 959 | osmo_gettimeofday(&time_now, NULL); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 960 | fc->time_last_pdu = time_now; |
| 961 | return fc->out_cb(priv, msg, llc_pdu_len, NULL); |
| 962 | } |
| 963 | } |
| 964 | |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 965 | |
| 966 | /* Initialize the Flow Control structure */ |
| 967 | void bssgp_fc_init(struct bssgp_flow_control *fc, |
| 968 | uint32_t bucket_size_max, uint32_t bucket_leak_rate, |
| 969 | uint32_t max_queue_depth, |
| 970 | int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, |
| 971 | uint32_t llc_pdu_len, void *priv)) |
| 972 | { |
| 973 | fc->out_cb = out_cb; |
| 974 | fc->bucket_size_max = bucket_size_max; |
| 975 | fc->bucket_leak_rate = bucket_leak_rate; |
| 976 | fc->max_queue_depth = max_queue_depth; |
| 977 | INIT_LLIST_HEAD(&fc->queue); |
Neels Hofmeyr | 8e2f7e8 | 2016-09-22 03:58:13 +0200 | [diff] [blame] | 978 | osmo_gettimeofday(&fc->time_last_pdu, NULL); |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 979 | } |
| 980 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 981 | /* Initialize the Flow Control parameters for a new MS according to |
| 982 | * default values for the BVC specified by BVCI and NSEI */ |
| 983 | int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci, |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 984 | uint16_t nsei, uint32_t max_queue_depth) |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 985 | { |
| 986 | struct bssgp_bvc_ctx *ctx; |
| 987 | |
| 988 | ctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 989 | if (!ctx) |
| 990 | return -ENODEV; |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 991 | |
| 992 | /* output call-back of per-MS FC is per-CTX FC */ |
| 993 | bssgp_fc_init(fc_ms, ctx->bmax_default_ms, ctx->r_default_ms, |
| 994 | max_queue_depth, bssgp_fc_in); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 995 | |
| 996 | return 0; |
| 997 | } |
| 998 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 999 | static int bssgp_rx_fc_bvc(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 1000 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1001 | { |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 1002 | uint32_t old_leak_rate = bctx->fc->bucket_leak_rate; |
| 1003 | uint32_t old_r_def_ms = bctx->r_default_ms; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1004 | |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1005 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx Flow Control BVC\n", |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1006 | bctx->bvci); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1007 | |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 1008 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_TAG, 1) || |
| 1009 | !TLVP_PRES_LEN(tp, BSSGP_IE_BVC_BUCKET_SIZE, 2) || |
| 1010 | !TLVP_PRES_LEN(tp, BSSGP_IE_BUCKET_LEAK_RATE, 2) || |
| 1011 | !TLVP_PRES_LEN(tp, BSSGP_IE_BMAX_DEFAULT_MS, 2) || |
| 1012 | !TLVP_PRES_LEN(tp, BSSGP_IE_R_DEFAULT_MS,2)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1013 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx FC BVC " |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1014 | "missing mandatory IE\n", bctx->bvci); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1015 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1016 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1017 | |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 1018 | /* 11.3.5 Bucket Size in 100 octets unit */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1019 | bctx->fc->bucket_size_max = 100 * tlvp_val16be(tp, BSSGP_IE_BVC_BUCKET_SIZE); |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 1020 | /* 11.3.4 Bucket Leak Rate in 100 bits/sec unit */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1021 | bctx->fc->bucket_leak_rate = 100 * tlvp_val16be(tp, BSSGP_IE_BUCKET_LEAK_RATE) / 8; |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 1022 | /* 11.3.2 in octets */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1023 | bctx->bmax_default_ms = tlvp_val16be(tp, BSSGP_IE_BMAX_DEFAULT_MS); |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 1024 | /* 11.3.32 Bucket Leak rate in 100bits/sec unit */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1025 | bctx->r_default_ms = 100 * tlvp_val16be(tp, BSSGP_IE_R_DEFAULT_MS) / 8; |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1026 | |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 1027 | if (old_leak_rate != 0 && bctx->fc->bucket_leak_rate == 0) |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1028 | LOGP(DLBSSGP, LOGL_NOTICE, "BSS instructs us to bucket leak " |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 1029 | "rate of 0, stopping all DL GPRS!\n"); |
| 1030 | else if (old_leak_rate == 0 && bctx->fc->bucket_leak_rate != 0) |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1031 | LOGP(DLBSSGP, LOGL_NOTICE, "BSS instructs us to bucket leak " |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 1032 | "rate of != 0, restarting all DL GPRS!\n"); |
| 1033 | |
| 1034 | if (old_r_def_ms != 0 && bctx->r_default_ms == 0) |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1035 | LOGP(DLBSSGP, LOGL_NOTICE, "BSS instructs us to MS default " |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 1036 | "bucket leak rate of 0, stopping DL GPRS!\n"); |
| 1037 | else if (old_r_def_ms == 0 && bctx->r_default_ms != 0) |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1038 | LOGP(DLBSSGP, LOGL_NOTICE, "BSS instructs us to MS default " |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 1039 | "bucket leak rate != 0, restarting DL GPRS!\n"); |
| 1040 | |
| 1041 | /* reconfigure the timer for flow control based on new values */ |
| 1042 | fc_queue_timer_cfg(bctx->fc); |
| 1043 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1044 | /* Send FLOW_CONTROL_BVC_ACK */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 1045 | return bssgp_tx_fc_bvc_ack(msgb_nsei(msg), *TLVP_VAL(tp, BSSGP_IE_TAG), |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1046 | msgb_bvci(msg)); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1047 | } |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 1048 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1049 | /* Receive a BSSGP PDU from a BSS on a PTP BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1050 | static int bssgp_rx_ptp(struct msgb *msg, struct tlv_parsed *tp, |
| 1051 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1052 | { |
Harald Welte | ec19c10 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 1053 | struct bssgp_normal_hdr *bgph = |
| 1054 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1055 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1056 | int rc = 0; |
| 1057 | |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 1058 | OSMO_ASSERT(pdu_type != BSSGP_PDUT_STATUS); |
| 1059 | |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 1060 | /* If traffic is received on a BVC that is marked as blocked, the |
| 1061 | * received PDU shall not be accepted and a STATUS PDU (Cause value: |
| 1062 | * BVC Blocked) shall be sent to the peer entity on the signalling BVC */ |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 1063 | if (bctx->state & BVC_S_BLOCKED) { |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 1064 | uint16_t bvci = msgb_bvci(msg); |
| 1065 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &bvci, msg); |
| 1066 | } |
| 1067 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1068 | switch (pdu_type) { |
| 1069 | case BSSGP_PDUT_UL_UNITDATA: |
| 1070 | /* some LLC data from the MS */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1071 | rc = bssgp_rx_ul_ud(msg, tp, bctx); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1072 | break; |
| 1073 | case BSSGP_PDUT_RA_CAPABILITY: |
| 1074 | /* BSS requests RA capability or IMSI */ |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1075 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx RA CAPABILITY UPDATE\n", |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1076 | bctx->bvci); |
Harald Welte | 6b7cf25 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 1077 | /* FIXME: send GMM_RA_CAPABILITY_UPDATE.ind to GMM */ |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1078 | /* FIXME: send RA_CAPA_UPDATE_ACK */ |
| 1079 | break; |
| 1080 | case BSSGP_PDUT_RADIO_STATUS: |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1081 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx RADIO STATUS\n", bctx->bvci); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1082 | /* BSS informs us of some exception */ |
Harald Welte | 6b7cf25 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 1083 | /* FIXME: send GMM_RADIO_STATUS.ind to GMM */ |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1084 | break; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1085 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 1086 | /* BSS informs us of available bandwidth in Gb interface */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1087 | rc = bssgp_rx_fc_bvc(msg, tp, bctx); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1088 | break; |
| 1089 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 1090 | /* BSS informs us of available bandwidth to one MS */ |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1091 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx Flow Control MS\n", |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1092 | bctx->bvci); |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1093 | /* FIXME: actually implement flow control */ |
| 1094 | /* FIXME: Send FLOW_CONTROL_MS_ACK */ |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1095 | break; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1096 | case BSSGP_PDUT_STATUS: |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 1097 | /* This is already handled in bssgp_rcvmsg() */ |
Jacob Erlbeck | 49ed9be | 2015-03-17 10:21:16 +0100 | [diff] [blame] | 1098 | break; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1099 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 1100 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 1101 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 1102 | case BSSGP_PDUT_MODIFY_BSS_PFC: |
| 1103 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1104 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx PDU type %s not [yet] " |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 1105 | "implemented\n", bctx->bvci, bssgp_pdu_str(pdu_type)); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1106 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1107 | break; |
| 1108 | /* those only exist in the SGSN -> BSS direction */ |
| 1109 | case BSSGP_PDUT_DL_UNITDATA: |
| 1110 | case BSSGP_PDUT_PAGING_PS: |
| 1111 | case BSSGP_PDUT_PAGING_CS: |
| 1112 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1113 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
| 1114 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1115 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u PDU type %s only exists in DL\n", |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 1116 | bctx->bvci, bssgp_pdu_str(pdu_type)); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1117 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 1118 | rc = -EINVAL; |
| 1119 | break; |
| 1120 | default: |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1121 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u PDU type %s unknown\n", |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 1122 | bctx->bvci, bssgp_pdu_str(pdu_type)); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1123 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 1124 | break; |
| 1125 | } |
| 1126 | |
Holger Hans Peter Freyther | d30cefa | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 1127 | return rc; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /* Receive a BSSGP PDU from a BSS on a SIGNALLING BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1131 | static int bssgp_rx_sign(struct msgb *msg, struct tlv_parsed *tp, |
| 1132 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1133 | { |
| 1134 | struct bssgp_normal_hdr *bgph = |
| 1135 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 1136 | uint8_t pdu_type = bgph->pdu_type; |
| 1137 | int rc = 0; |
| 1138 | uint16_t ns_bvci = msgb_bvci(msg); |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 1139 | uint16_t bvci = bctx ? bctx->bvci : ns_bvci; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1140 | |
| 1141 | switch (bgph->pdu_type) { |
| 1142 | case BSSGP_PDUT_SUSPEND: |
| 1143 | /* MS wants to suspend */ |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 1144 | rc = bssgp_rx_suspend(msg, tp); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1145 | break; |
| 1146 | case BSSGP_PDUT_RESUME: |
| 1147 | /* MS wants to resume */ |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 1148 | rc = bssgp_rx_resume(msg, tp); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1149 | break; |
| 1150 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 1151 | /* BSS informs us it has performed LL FLUSH */ |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1152 | DEBUGP(DLBSSGP, "BSSGP Rx BVCI=%u FLUSH LL ACK\n", bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1153 | /* FIXME: send NM_FLUSH_LL.res to NM */ |
| 1154 | break; |
| 1155 | case BSSGP_PDUT_LLC_DISCARD: |
| 1156 | /* BSS informs that some LLC PDU's have been discarded */ |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 1157 | if (!bctx) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1158 | LOGP(DLBSSGP, LOGL_ERROR, |
Jacob Erlbeck | b43baf2 | 2014-09-10 12:43:28 +0200 | [diff] [blame] | 1159 | "BSSGP Rx LLC-DISCARD missing mandatory BVCI\n"); |
| 1160 | goto err_mand_ie; |
| 1161 | } |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1162 | rc = bssgp_rx_llc_disc(msg, tp, bctx); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1163 | break; |
| 1164 | case BSSGP_PDUT_BVC_BLOCK: |
| 1165 | /* BSS tells us that BVC shall be blocked */ |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 1166 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2) || |
| 1167 | !TLVP_PRES_LEN(tp, BSSGP_IE_CAUSE, 1)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1168 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP Rx BVC-BLOCK " |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1169 | "missing mandatory IE\n"); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1170 | goto err_mand_ie; |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1171 | } |
Harald Welte | 2677ea5 | 2010-05-31 17:16:36 +0200 | [diff] [blame] | 1172 | rc = bssgp_rx_bvc_block(msg, tp); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1173 | break; |
| 1174 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 1175 | /* BSS tells us that BVC shall be unblocked */ |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 1176 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1177 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP Rx BVC-UNBLOCK " |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1178 | "missing mandatory IE\n"); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1179 | goto err_mand_ie; |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1180 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1181 | rc = bssgp_rx_bvc_unblock(msg, tp); |
| 1182 | break; |
Max | 590c402 | 2017-06-28 14:29:24 +0200 | [diff] [blame] | 1183 | case BSSGP_PDUT_BVC_RESET_ACK: |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1184 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx BVC-RESET-ACK\n", bvci); |
Max | 590c402 | 2017-06-28 14:29:24 +0200 | [diff] [blame] | 1185 | break; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1186 | case BSSGP_PDUT_BVC_RESET: |
| 1187 | /* BSS tells us that BVC init is required */ |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 1188 | if (!TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2) || |
| 1189 | !TLVP_PRES_LEN(tp, BSSGP_IE_CAUSE, 1)) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1190 | LOGP(DLBSSGP, LOGL_ERROR, "BSSGP Rx BVC-RESET " |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1191 | "missing mandatory IE\n"); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1192 | goto err_mand_ie; |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 1193 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1194 | rc = bssgp_rx_bvc_reset(msg, tp, ns_bvci); |
| 1195 | break; |
| 1196 | case BSSGP_PDUT_STATUS: |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 1197 | /* This is already handled in bssgp_rcvmsg() */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1198 | break; |
Philipp Maier | 1eaa7bc | 2020-12-16 21:07:04 +0100 | [diff] [blame] | 1199 | |
| 1200 | case BSSGP_PDUT_RAN_INFO: |
| 1201 | case BSSGP_PDUT_RAN_INFO_REQ: |
| 1202 | case BSSGP_PDUT_RAN_INFO_ACK: |
| 1203 | case BSSGP_PDUT_RAN_INFO_ERROR: |
| 1204 | case BSSGP_PDUT_RAN_INFO_APP_ERROR: |
| 1205 | bssgp_rx_rim(msg, tp, bvci); |
| 1206 | break; |
| 1207 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1208 | /* those only exist in the SGSN -> BSS direction */ |
| 1209 | case BSSGP_PDUT_PAGING_PS: |
| 1210 | case BSSGP_PDUT_PAGING_CS: |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1211 | case BSSGP_PDUT_SUSPEND_ACK: |
| 1212 | case BSSGP_PDUT_SUSPEND_NACK: |
| 1213 | case BSSGP_PDUT_RESUME_ACK: |
| 1214 | case BSSGP_PDUT_RESUME_NACK: |
Harald Welte | 6b7cf25 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 1215 | case BSSGP_PDUT_FLUSH_LL: |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1216 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 1217 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 1218 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1219 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx PDU type %s only exists in DL\n", |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 1220 | bvci, bssgp_pdu_str(pdu_type)); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1221 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1222 | rc = -EINVAL; |
| 1223 | break; |
| 1224 | default: |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1225 | DEBUGP(DLBSSGP, "BSSGP BVCI=%u Rx PDU type %s unknown\n", |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 1226 | bvci, bssgp_pdu_str(pdu_type)); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1227 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1228 | break; |
| 1229 | } |
| 1230 | |
| 1231 | return rc; |
| 1232 | err_mand_ie: |
| 1233 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 1234 | } |
| 1235 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1236 | /* We expect msgb_bssgph() to point to the BSSGP header */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1237 | int bssgp_rcvmsg(struct msgb *msg) |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1238 | { |
| 1239 | struct bssgp_normal_hdr *bgph = |
| 1240 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 1241 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
| 1242 | struct tlv_parsed tp; |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 1243 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1244 | uint8_t pdu_type = bgph->pdu_type; |
| 1245 | uint16_t ns_bvci = msgb_bvci(msg); |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 1246 | uint16_t nsei = msgb_nsei(msg); |
Jacob Erlbeck | b83b838 | 2014-09-23 13:28:22 +0200 | [diff] [blame] | 1247 | uint16_t bvci = ns_bvci; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1248 | int data_len; |
| 1249 | int rc = 0; |
| 1250 | |
| 1251 | /* Identifiers from DOWN: NSEI, BVCI (both in msg->cb) */ |
| 1252 | |
| 1253 | /* UNITDATA BSSGP headers have TLLI in front */ |
| 1254 | if (pdu_type != BSSGP_PDUT_UL_UNITDATA && |
| 1255 | pdu_type != BSSGP_PDUT_DL_UNITDATA) { |
| 1256 | data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
| 1257 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 1258 | } else { |
| 1259 | data_len = msgb_bssgp_len(msg) - sizeof(*budh); |
| 1260 | rc = bssgp_tlv_parse(&tp, budh->data, data_len); |
| 1261 | } |
Stefan Sperling | 2b544b2 | 2018-06-25 12:20:43 +0200 | [diff] [blame] | 1262 | if (rc < 0) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1263 | LOGP(DLBSSGP, LOGL_ERROR, "Failed to parse BSSGP %s message. Invalid message was: %s\n", |
Stefan Sperling | 2b544b2 | 2018-06-25 12:20:43 +0200 | [diff] [blame] | 1264 | bssgp_pdu_str(pdu_type), msgb_hexdump(msg)); |
Stefan Sperling | f1e13d6 | 2018-06-25 12:20:43 +0200 | [diff] [blame] | 1265 | if (pdu_type != BSSGP_PDUT_STATUS) |
| 1266 | return bssgp_tx_status(BSSGP_CAUSE_INV_MAND_INF, NULL, msg); |
Stefan Sperling | 2b544b2 | 2018-06-25 12:20:43 +0200 | [diff] [blame] | 1267 | return rc; |
| 1268 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1269 | |
Harald Welte | 2d9ce71 | 2020-12-03 15:53:59 +0100 | [diff] [blame] | 1270 | if (bvci == BVCI_SIGNALLING && TLVP_PRES_LEN(&tp, BSSGP_IE_BVCI, 2)) |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1271 | bvci = tlvp_val16be(&tp, BSSGP_IE_BVCI); |
Jacob Erlbeck | b83b838 | 2014-09-23 13:28:22 +0200 | [diff] [blame] | 1272 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1273 | /* look-up or create the BTS context for this BVC */ |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 1274 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1275 | |
Harald Welte | 16c8dbb | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 1276 | if (bctx) { |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 1277 | log_set_context(LOG_CTX_GB_BVC, bctx); |
Harald Welte | 16c8dbb | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 1278 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_IN]); |
| 1279 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_IN], |
| 1280 | msgb_bssgp_len(msg)); |
| 1281 | } |
| 1282 | |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 1283 | /* Always handle STATUS PDUs, even if they contain an invalid BVCI or |
| 1284 | * are otherwise unexpected */ |
| 1285 | if (pdu_type == BSSGP_PDUT_STATUS) |
| 1286 | /* Some exception has occurred */ |
| 1287 | return bssgp_rx_status(msg, &tp, bvci, bctx); |
| 1288 | |
| 1289 | /* Only a RESET PDU can create a new BVC context, otherwise it must be |
| 1290 | * registered if a BVCI is given. */ |
| 1291 | if (!bctx && bvci != BVCI_SIGNALLING && |
| 1292 | pdu_type != BSSGP_PDUT_BVC_RESET) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1293 | LOGP(DLBSSGP, LOGL_NOTICE, "NSEI=%u/BVCI=%u Rejecting PDU type %s for unknown BVCI\n", nsei, bvci, |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 1294 | bssgp_pdu_str(pdu_type)); |
Jacob Erlbeck | 36153dc | 2015-03-17 10:21:17 +0100 | [diff] [blame] | 1295 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 1296 | } |
| 1297 | |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 1298 | if (ns_bvci == BVCI_SIGNALLING) |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1299 | rc = bssgp_rx_sign(msg, &tp, bctx); |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 1300 | else if (ns_bvci == BVCI_PTM) |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1301 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Jacob Erlbeck | b535e39 | 2015-04-07 17:52:44 +0200 | [diff] [blame] | 1302 | else if (bctx) |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1303 | rc = bssgp_rx_ptp(msg, &tp, bctx); |
Jacob Erlbeck | b535e39 | 2015-04-07 17:52:44 +0200 | [diff] [blame] | 1304 | else |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1305 | LOGP(DLBSSGP, LOGL_NOTICE, |
Max | 548caef | 2019-03-07 13:49:34 +0100 | [diff] [blame] | 1306 | "NSEI=%u/BVCI=%u Cannot handle PDU type %s for unknown BVCI, NS BVCI %u\n", nsei, bvci, |
| 1307 | bssgp_pdu_str(pdu_type), ns_bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1308 | |
| 1309 | return rc; |
| 1310 | } |
| 1311 | |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1312 | int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, |
| 1313 | struct bssgp_dl_ud_par *dup) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1314 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 1315 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1316 | struct bssgp_ud_hdr *budh; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 1317 | uint8_t llc_pdu_tlv_hdr_len = 2; |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1318 | uint8_t *llc_pdu_tlv; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 1319 | uint16_t msg_len = msg->len; |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1320 | uint16_t bvci = msgb_bvci(msg); |
| 1321 | uint16_t nsei = msgb_nsei(msg); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1322 | uint16_t _pdu_lifetime = osmo_htons(pdu_lifetime); /* centi-seconds */ |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1323 | uint16_t drx_params; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1324 | |
Jacob Erlbeck | c641591 | 2015-04-07 17:52:43 +0200 | [diff] [blame] | 1325 | OSMO_ASSERT(dup != NULL); |
| 1326 | |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1327 | /* Identifiers from UP: TLLI, BVCI, NSEI (all in msgb->cb) */ |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 1328 | if (bvci <= BVCI_PTM ) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1329 | LOGP(DLBSSGP, LOGL_ERROR, "Cannot send DL-UD to BVCI %u\n", |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1330 | bvci); |
Holger Hans Peter Freyther | 10dd73c | 2014-10-10 17:24:34 +0200 | [diff] [blame] | 1331 | msgb_free(msg); |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1332 | return -EINVAL; |
| 1333 | } |
| 1334 | |
| 1335 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1336 | if (!bctx) { |
Harald Welte | fde19ed | 2020-12-07 21:43:51 +0100 | [diff] [blame] | 1337 | LOGP(DLBSSGP, LOGL_ERROR, "Cannot send DL-UD to unknown BVCI %u\n", |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 1338 | bvci); |
Holger Hans Peter Freyther | 10dd73c | 2014-10-10 17:24:34 +0200 | [diff] [blame] | 1339 | msgb_free(msg); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 1340 | return -ENODEV; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1341 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1342 | |
| 1343 | if (msg->len > TVLV_MAX_ONEBYTE) |
| 1344 | llc_pdu_tlv_hdr_len += 1; |
| 1345 | |
| 1346 | /* prepend the tag and length of the LLC-PDU TLV */ |
| 1347 | llc_pdu_tlv = msgb_push(msg, llc_pdu_tlv_hdr_len); |
| 1348 | llc_pdu_tlv[0] = BSSGP_IE_LLC_PDU; |
| 1349 | if (llc_pdu_tlv_hdr_len > 2) { |
| 1350 | llc_pdu_tlv[1] = msg_len >> 8; |
| 1351 | llc_pdu_tlv[2] = msg_len & 0xff; |
| 1352 | } else { |
Sylvain Munaut | b00d1ad | 2010-06-09 21:13:13 +0200 | [diff] [blame] | 1353 | llc_pdu_tlv[1] = msg_len & 0x7f; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1354 | llc_pdu_tlv[1] |= 0x80; |
| 1355 | } |
| 1356 | |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1357 | /* FIXME: optional elements: Alignment, UTRAN CCO, LSA, PFI */ |
| 1358 | |
Jacob Erlbeck | c641591 | 2015-04-07 17:52:43 +0200 | [diff] [blame] | 1359 | /* Old TLLI to help BSS map from old->new */ |
| 1360 | if (dup->tlli) { |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1361 | uint32_t tlli = osmo_htonl(*dup->tlli); |
Jacob Erlbeck | c641591 | 2015-04-07 17:52:43 +0200 | [diff] [blame] | 1362 | msgb_tvlv_push(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &tlli); |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1363 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1364 | |
Jacob Erlbeck | c641591 | 2015-04-07 17:52:43 +0200 | [diff] [blame] | 1365 | /* IMSI */ |
| 1366 | if (dup->imsi && strlen(dup->imsi)) { |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 1367 | uint8_t mi[GSM48_MID_MAX_SIZE]; |
| 1368 | /* gsm48_generate_mid_from_imsi() is guaranteed to never return more than 11, |
| 1369 | * but somehow gcc (8.2) is not smart enough to figure this out and claims that |
| 1370 | * the memcpy in msgb_tvlv_put() below will cause and out-of-bounds access up to |
| 1371 | * mi[131], which is wrong */ |
| 1372 | #pragma GCC diagnostic push |
| 1373 | #pragma GCC diagnostic ignored "-Warray-bounds" |
| 1374 | int imsi_len = gsm48_generate_mid_from_imsi(mi, dup->imsi); |
| 1375 | OSMO_ASSERT(imsi_len <= GSM48_MID_MAX_SIZE); |
| 1376 | if (imsi_len > 2) |
| 1377 | msgb_tvlv_push(msg, BSSGP_IE_IMSI, |
| 1378 | imsi_len-2, mi+2); |
| 1379 | #pragma GCC diagnostic pop |
Jacob Erlbeck | c641591 | 2015-04-07 17:52:43 +0200 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | /* DRX parameters */ |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1383 | drx_params = osmo_htons(dup->drx_parms); |
Jacob Erlbeck | c641591 | 2015-04-07 17:52:43 +0200 | [diff] [blame] | 1384 | msgb_tvlv_push(msg, BSSGP_IE_DRX_PARAMS, 2, |
| 1385 | (uint8_t *) &drx_params); |
| 1386 | |
| 1387 | /* FIXME: Priority */ |
| 1388 | |
| 1389 | /* MS Radio Access Capability */ |
| 1390 | if (dup->ms_ra_cap.len) |
| 1391 | msgb_tvlv_push(msg, BSSGP_IE_MS_RADIO_ACCESS_CAP, |
| 1392 | dup->ms_ra_cap.len, dup->ms_ra_cap.v); |
| 1393 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1394 | /* prepend the pdu lifetime */ |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1395 | msgb_tvlv_push(msg, BSSGP_IE_PDU_LIFETIME, 2, (uint8_t *)&_pdu_lifetime); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1396 | |
| 1397 | /* prepend the QoS profile, TLLI and pdu type */ |
| 1398 | budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1399 | memcpy(budh->qos_profile, dup->qos_profile, sizeof(budh->qos_profile)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1400 | budh->tlli = osmo_htonl(msgb_tlli(msg)); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1401 | budh->pdu_type = BSSGP_PDUT_DL_UNITDATA; |
| 1402 | |
Harald Welte | 16c8dbb | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 1403 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]); |
| 1404 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_OUT], msg->len); |
| 1405 | |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1406 | /* Identifiers down: BVCI, NSEI (in msgb->cb) */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 1407 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 1408 | /* check if we have to go through per-ms flow control or can go |
| 1409 | * directly to the per-BSS flow control */ |
| 1410 | if (dup->fc) |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 1411 | return bssgp_fc_in(dup->fc, msg, msg_len, bctx->fc); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 1412 | else |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 1413 | return bssgp_fc_in(bctx->fc, msg, msg_len, NULL); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1414 | } |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1415 | |
| 1416 | /* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1417 | int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, |
| 1418 | struct bssgp_paging_info *pinfo) |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1419 | { |
| 1420 | struct msgb *msg = bssgp_msgb_alloc(); |
| 1421 | struct bssgp_normal_hdr *bgph = |
| 1422 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1423 | uint16_t drx_params = osmo_htons(pinfo->drx_params); |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 1424 | uint8_t mi[GSM48_MID_MAX_SIZE]; |
| 1425 | int imsi_len = gsm48_generate_mid_from_imsi(mi, pinfo->imsi); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 1426 | struct gsm48_ra_id ra; |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 1427 | |
| 1428 | if (imsi_len < 2) |
| 1429 | return -EINVAL; |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1430 | |
| 1431 | msgb_nsei(msg) = nsei; |
| 1432 | msgb_bvci(msg) = ns_bvci; |
| 1433 | |
| 1434 | if (pinfo->mode == BSSGP_PAGING_PS) |
| 1435 | bgph->pdu_type = BSSGP_PDUT_PAGING_PS; |
| 1436 | else |
| 1437 | bgph->pdu_type = BSSGP_PDUT_PAGING_CS; |
| 1438 | /* IMSI */ |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 1439 | /* gsm48_generate_mid_from_imsi() is guaranteed to never return more than 11, |
| 1440 | * but somehow gcc (8.2) is not smart enough to figure this out and claims that |
| 1441 | * the memcpy in msgb_tvlv_put() below will cause and out-of-bounds access up to |
| 1442 | * mi[131], which is wrong */ |
| 1443 | #pragma GCC diagnostic push |
| 1444 | #pragma GCC diagnostic ignored "-Warray-bounds" |
| 1445 | OSMO_ASSERT(imsi_len <= GSM48_MID_MAX_SIZE); |
| 1446 | msgb_tvlv_put(msg, BSSGP_IE_IMSI, imsi_len-2, mi+2); |
| 1447 | #pragma GCC diagnostic pop |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1448 | /* DRX Parameters */ |
| 1449 | msgb_tvlv_put(msg, BSSGP_IE_DRX_PARAMS, 2, |
| 1450 | (uint8_t *) &drx_params); |
| 1451 | /* Scope */ |
| 1452 | switch (pinfo->scope) { |
| 1453 | case BSSGP_PAGING_BSS_AREA: |
| 1454 | { |
| 1455 | uint8_t null = 0; |
| 1456 | msgb_tvlv_put(msg, BSSGP_IE_BSS_AREA_ID, 1, &null); |
| 1457 | } |
| 1458 | break; |
| 1459 | case BSSGP_PAGING_LOCATION_AREA: |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 1460 | gsm48_encode_ra(&ra, &pinfo->raid); |
| 1461 | msgb_tvlv_put(msg, BSSGP_IE_LOCATION_AREA, 4, (const uint8_t *)&ra); |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1462 | break; |
| 1463 | case BSSGP_PAGING_ROUTEING_AREA: |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 1464 | bssgp_msgb_ra_put(msg, &pinfo->raid); |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1465 | break; |
| 1466 | case BSSGP_PAGING_BVCI: |
| 1467 | { |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1468 | uint16_t bvci = osmo_htons(pinfo->bvci); |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1469 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *)&bvci); |
| 1470 | } |
| 1471 | break; |
| 1472 | } |
| 1473 | /* QoS profile mandatory for PS */ |
| 1474 | if (pinfo->mode == BSSGP_PAGING_PS) |
| 1475 | msgb_tvlv_put(msg, BSSGP_IE_QOS_PROFILE, 3, pinfo->qos); |
| 1476 | |
| 1477 | /* Optional (P-)TMSI */ |
| 1478 | if (pinfo->ptmsi) { |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 1479 | uint32_t ptmsi = osmo_htonl(*pinfo->ptmsi); |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1480 | msgb_tvlv_put(msg, BSSGP_IE_TMSI, 4, (uint8_t *) &ptmsi); |
| 1481 | } |
| 1482 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 1483 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1484 | } |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 1485 | |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1486 | void bssgp_set_log_ss(int ss) |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 1487 | { |
Pau Espin Pedrol | 0e61716 | 2020-12-10 13:38:42 +0100 | [diff] [blame] | 1488 | /* BSSGP has moved from DGPRS to DLGPRS, please update your code if it's |
| 1489 | * still calling this function |
| 1490 | */ |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 1491 | } |
Alexander Couzens | acc0a07 | 2018-08-07 11:22:28 +0200 | [diff] [blame] | 1492 | |
| 1493 | /*! |
| 1494 | * \brief Flush the queue of the bssgp_flow_control |
| 1495 | * \param[in] The flow control object which holds the queue. |
| 1496 | */ |
| 1497 | void bssgp_fc_flush_queue(struct bssgp_flow_control *fc) |
| 1498 | { |
| 1499 | struct bssgp_fc_queue_element *element, *tmp; |
| 1500 | |
| 1501 | llist_for_each_entry_safe(element, tmp, &fc->queue, list) { |
| 1502 | msgb_free(element->msg); |
| 1503 | llist_del(&element->list); |
| 1504 | talloc_free(element); |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | /*! |
| 1509 | * \brief Flush the queues of all BSSGP contexts. |
| 1510 | */ |
| 1511 | void bssgp_flush_all_queues() |
| 1512 | { |
| 1513 | struct bssgp_bvc_ctx *bctx; |
| 1514 | |
| 1515 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
| 1516 | if (bctx->fc) |
| 1517 | bssgp_fc_flush_queue(bctx->fc); |
| 1518 | } |
| 1519 | } |