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