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