Neels Hofmeyr | 17518fe | 2017-06-20 04:35:06 +0200 | [diff] [blame] | 1 | /*! \file gprs_bssgp_bss.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 | 85fc314 | 2011-11-25 08:58:40 +0100 | [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 | 85fc314 | 2011-11-25 08:58:40 +0100 | [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 | 85fc314 | 2011-11-25 08:58:40 +0100 | [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 | 85fc314 | 2011-11-25 08:58:40 +0100 | [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 | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <errno.h> |
| 26 | #include <stdint.h> |
| 27 | |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 28 | #include <osmocom/core/msgb.h> |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 29 | #include <osmocom/core/byteswap.h> |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 30 | #include <osmocom/core/rate_ctr.h> |
| 31 | #include <osmocom/gsm/tlv.h> |
| 32 | #include <osmocom/core/talloc.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 33 | #include <osmocom/gprs/gprs_bssgp.h> |
Harald Welte | 30fabdf | 2012-09-10 08:54:35 +0200 | [diff] [blame] | 34 | #include <osmocom/gprs/gprs_bssgp_bss.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 35 | #include <osmocom/gprs/gprs_ns.h> |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 36 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 37 | #include "gprs_bssgp_internal.h" |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 38 | #include "common_vty.h" |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 39 | |
Jacob Erlbeck | c1cb75e | 2015-06-18 13:21:30 +0200 | [diff] [blame] | 40 | #define GSM_IMSI_LENGTH 17 |
| 41 | |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 42 | uint8_t *bssgp_msgb_tlli_put(struct msgb *msg, uint32_t tlli) |
| 43 | { |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 44 | uint32_t _tlli = osmo_htonl(tlli); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 45 | return msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 46 | } |
| 47 | |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 48 | uint8_t *bssgp_msgb_ra_put(struct msgb *msg, const struct gprs_ra_id *ra_id) |
| 49 | { |
| 50 | struct gsm48_ra_id ra; |
| 51 | |
| 52 | gsm48_encode_ra(&ra, ra_id); |
| 53 | return msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, sizeof(ra), (const uint8_t *)&ra); |
| 54 | } |
| 55 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 56 | /*! GMM-SUSPEND.req (Chapter 10.3.6) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 57 | int bssgp_tx_suspend(uint16_t nsei, uint32_t tlli, |
| 58 | const struct gprs_ra_id *ra_id) |
| 59 | { |
| 60 | struct msgb *msg = bssgp_msgb_alloc(); |
| 61 | struct bssgp_normal_hdr *bgph = |
| 62 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 63 | |
| 64 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=0) Tx SUSPEND (TLLI=0x%04x)\n", |
| 65 | tlli); |
| 66 | msgb_nsei(msg) = nsei; |
| 67 | msgb_bvci(msg) = 0; /* Signalling */ |
| 68 | bgph->pdu_type = BSSGP_PDUT_SUSPEND; |
| 69 | |
| 70 | bssgp_msgb_tlli_put(msg, tlli); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 71 | bssgp_msgb_ra_put(msg, ra_id); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 72 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 73 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 76 | /*! GMM-RESUME.req (Chapter 10.3.9) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 77 | int bssgp_tx_resume(uint16_t nsei, uint32_t tlli, |
| 78 | const struct gprs_ra_id *ra_id, uint8_t suspend_ref) |
| 79 | { |
| 80 | struct msgb *msg = bssgp_msgb_alloc(); |
| 81 | struct bssgp_normal_hdr *bgph = |
| 82 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 83 | |
| 84 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=0) Tx RESUME (TLLI=0x%04x)\n", |
| 85 | tlli); |
| 86 | msgb_nsei(msg) = nsei; |
| 87 | msgb_bvci(msg) = 0; /* Signalling */ |
| 88 | bgph->pdu_type = BSSGP_PDUT_RESUME; |
| 89 | |
| 90 | bssgp_msgb_tlli_put(msg, tlli); |
Max | f1ad60e | 2018-01-05 14:19:33 +0100 | [diff] [blame] | 91 | bssgp_msgb_ra_put(msg, ra_id); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 92 | |
| 93 | msgb_tvlv_put(msg, BSSGP_IE_SUSPEND_REF_NR, 1, &suspend_ref); |
| 94 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 95 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 96 | } |
| 97 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 98 | /*! Transmit RA-CAPABILITY-UPDATE (10.3.3) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 99 | int bssgp_tx_ra_capa_upd(struct bssgp_bvc_ctx *bctx, uint32_t tlli, uint8_t tag) |
| 100 | { |
| 101 | struct msgb *msg = bssgp_msgb_alloc(); |
| 102 | struct bssgp_normal_hdr *bgph = |
| 103 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 104 | |
| 105 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx RA-CAPA-UPD (TLLI=0x%04x)\n", |
| 106 | bctx->bvci, tlli); |
| 107 | |
| 108 | /* set NSEI and BVCI in msgb cb */ |
| 109 | msgb_nsei(msg) = bctx->nsei; |
| 110 | msgb_bvci(msg) = bctx->bvci; |
| 111 | |
| 112 | bgph->pdu_type = BSSGP_PDUT_RA_CAPA_UDPATE; |
| 113 | bssgp_msgb_tlli_put(msg, tlli); |
| 114 | |
| 115 | msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag); |
| 116 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 117 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* first common part of RADIO-STATUS */ |
| 121 | static struct msgb *common_tx_radio_status(struct bssgp_bvc_ctx *bctx) |
| 122 | { |
| 123 | struct msgb *msg = bssgp_msgb_alloc(); |
| 124 | struct bssgp_normal_hdr *bgph = |
| 125 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 126 | |
| 127 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx RADIO-STATUS ", |
| 128 | bctx->bvci); |
| 129 | |
| 130 | /* set NSEI and BVCI in msgb cb */ |
| 131 | msgb_nsei(msg) = bctx->nsei; |
| 132 | msgb_bvci(msg) = bctx->bvci; |
| 133 | |
| 134 | bgph->pdu_type = BSSGP_PDUT_RADIO_STATUS; |
| 135 | |
| 136 | return msg; |
| 137 | } |
| 138 | |
| 139 | /* second common part of RADIO-STATUS */ |
| 140 | static int common_tx_radio_status2(struct msgb *msg, uint8_t cause) |
| 141 | { |
| 142 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause); |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 143 | LOGPC(DBSSGP, LOGL_NOTICE, "CAUSE=%s\n", bssgp_cause_str(cause)); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 144 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 145 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 148 | /*! Transmit RADIO-STATUS for TLLI (10.3.5) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 149 | int bssgp_tx_radio_status_tlli(struct bssgp_bvc_ctx *bctx, uint8_t cause, |
| 150 | uint32_t tlli) |
| 151 | { |
| 152 | struct msgb *msg = common_tx_radio_status(bctx); |
| 153 | |
| 154 | if (!msg) |
| 155 | return -ENOMEM; |
| 156 | bssgp_msgb_tlli_put(msg, tlli); |
| 157 | LOGPC(DBSSGP, LOGL_NOTICE, "TLLI=0x%08x ", tlli); |
| 158 | |
| 159 | return common_tx_radio_status2(msg, cause); |
| 160 | } |
| 161 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 162 | /*! Transmit RADIO-STATUS for TMSI (10.3.5) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 163 | int bssgp_tx_radio_status_tmsi(struct bssgp_bvc_ctx *bctx, uint8_t cause, |
| 164 | uint32_t tmsi) |
| 165 | { |
| 166 | struct msgb *msg = common_tx_radio_status(bctx); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 167 | uint32_t _tmsi = osmo_htonl(tmsi); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 168 | |
| 169 | if (!msg) |
| 170 | return -ENOMEM; |
| 171 | msgb_tvlv_put(msg, BSSGP_IE_TMSI, 4, (uint8_t *)&_tmsi); |
| 172 | LOGPC(DBSSGP, LOGL_NOTICE, "TMSI=0x%08x ", tmsi); |
| 173 | |
| 174 | return common_tx_radio_status2(msg, cause); |
| 175 | } |
| 176 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 177 | /*! Transmit RADIO-STATUS for IMSI (10.3.5) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 178 | int bssgp_tx_radio_status_imsi(struct bssgp_bvc_ctx *bctx, uint8_t cause, |
| 179 | const char *imsi) |
| 180 | { |
| 181 | struct msgb *msg = common_tx_radio_status(bctx); |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 182 | uint8_t mi[GSM48_MID_MAX_SIZE]; |
| 183 | int imsi_len = gsm48_generate_mid_from_imsi(mi, imsi); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 184 | |
| 185 | if (!msg) |
| 186 | return -ENOMEM; |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 187 | /* gsm48_generate_mid_from_imsi() is guaranteed to never return more than 11, |
| 188 | * but somehow gcc (8.2) is not smart enough to figure this out and claims that |
| 189 | * the memcpy in msgb_tvlv_put() below will cause and out-of-bounds access up to |
| 190 | * mi[131], which is wrong */ |
| 191 | #pragma GCC diagnostic push |
| 192 | #pragma GCC diagnostic ignored "-Warray-bounds" |
| 193 | OSMO_ASSERT(imsi_len <= GSM48_MID_MAX_SIZE); |
| 194 | /* strip the MI type and length values (2 bytes) */ |
| 195 | if (imsi_len > 2) |
| 196 | msgb_tvlv_put(msg, BSSGP_IE_IMSI, imsi_len-2, mi+2); |
| 197 | #pragma GCC diagnostic pop |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 198 | LOGPC(DBSSGP, LOGL_NOTICE, "IMSI=%s ", imsi); |
| 199 | |
| 200 | return common_tx_radio_status2(msg, cause); |
| 201 | } |
| 202 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 203 | /*! Transmit FLUSH-LL-ACK (Chapter 10.4.2) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 204 | int bssgp_tx_flush_ll_ack(struct bssgp_bvc_ctx *bctx, uint32_t tlli, |
| 205 | uint8_t action, uint16_t bvci_new, |
| 206 | uint32_t num_octets) |
| 207 | { |
| 208 | struct msgb *msg = bssgp_msgb_alloc(); |
| 209 | struct bssgp_normal_hdr *bgph = |
| 210 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 211 | uint16_t _bvci_new = osmo_htons(bvci_new); |
| 212 | uint32_t _oct_aff = osmo_htonl(num_octets & 0xFFFFFF); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 213 | |
| 214 | msgb_nsei(msg) = bctx->nsei; |
| 215 | msgb_bvci(msg) = 0; /* Signalling */ |
| 216 | bgph->pdu_type = BSSGP_PDUT_FLUSH_LL_ACK; |
| 217 | |
| 218 | bssgp_msgb_tlli_put(msg, tlli); |
| 219 | msgb_tvlv_put(msg, BSSGP_IE_FLUSH_ACTION, 1, &action); |
| 220 | if (action == 1) /* transferred */ |
| 221 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci_new); |
| 222 | msgb_tvlv_put(msg, BSSGP_IE_NUM_OCT_AFF, 3, (uint8_t *) &_oct_aff); |
| 223 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 224 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 227 | /*! Transmit LLC-DISCARDED (Chapter 10.4.3) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 228 | int bssgp_tx_llc_discarded(struct bssgp_bvc_ctx *bctx, uint32_t tlli, |
| 229 | uint8_t num_frames, uint32_t num_octets) |
| 230 | { |
| 231 | struct msgb *msg = bssgp_msgb_alloc(); |
| 232 | struct bssgp_normal_hdr *bgph = |
| 233 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 234 | uint16_t _bvci = osmo_htons(bctx->bvci); |
| 235 | uint32_t _oct_aff = osmo_htonl(num_octets & 0xFFFFFF); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 236 | |
| 237 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx LLC-DISCARDED " |
| 238 | "TLLI=0x%04x, FRAMES=%u, OCTETS=%u\n", bctx->bvci, tlli, |
| 239 | num_frames, num_octets); |
| 240 | msgb_nsei(msg) = bctx->nsei; |
| 241 | msgb_bvci(msg) = 0; /* Signalling */ |
| 242 | bgph->pdu_type = BSSGP_PDUT_LLC_DISCARD; |
| 243 | |
| 244 | bssgp_msgb_tlli_put(msg, tlli); |
| 245 | |
| 246 | msgb_tvlv_put(msg, BSSGP_IE_LLC_FRAMES_DISCARDED, 1, &num_frames); |
| 247 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
Andreas Eversberg | aa5d0e8 | 2012-07-21 13:33:39 +0200 | [diff] [blame] | 248 | msgb_tvlv_put(msg, BSSGP_IE_NUM_OCT_AFF, 3, ((uint8_t *) &_oct_aff) + 1); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 249 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 250 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 251 | } |
| 252 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 253 | /*! Transmit a BVC-BLOCK message (Chapter 10.4.8) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 254 | int bssgp_tx_bvc_block(struct bssgp_bvc_ctx *bctx, uint8_t cause) |
| 255 | { |
| 256 | struct msgb *msg = bssgp_msgb_alloc(); |
| 257 | struct bssgp_normal_hdr *bgph = |
| 258 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 259 | uint16_t _bvci = osmo_htons(bctx->bvci); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 260 | |
| 261 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-BLOCK " |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 262 | "CAUSE=%s\n", bctx->bvci, bssgp_cause_str(cause)); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 263 | |
| 264 | msgb_nsei(msg) = bctx->nsei; |
| 265 | msgb_bvci(msg) = 0; /* Signalling */ |
| 266 | bgph->pdu_type = BSSGP_PDUT_BVC_BLOCK; |
| 267 | |
| 268 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
| 269 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause); |
| 270 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 271 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 274 | /*! Transmit a BVC-UNBLOCK message (Chapter 10.4.10) */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 275 | int bssgp_tx_bvc_unblock(struct bssgp_bvc_ctx *bctx) |
| 276 | { |
| 277 | struct msgb *msg = bssgp_msgb_alloc(); |
| 278 | struct bssgp_normal_hdr *bgph = |
| 279 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 280 | uint16_t _bvci = osmo_htons(bctx->bvci); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 281 | |
Harald Welte | 6a469e1 | 2019-02-19 11:07:50 +0100 | [diff] [blame] | 282 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-UNBLOCK\n", bctx->bvci); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 283 | |
| 284 | msgb_nsei(msg) = bctx->nsei; |
| 285 | msgb_bvci(msg) = 0; /* Signalling */ |
| 286 | bgph->pdu_type = BSSGP_PDUT_BVC_UNBLOCK; |
| 287 | |
| 288 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
| 289 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 290 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 293 | /*! Transmit a BVC-RESET message (Chapter 10.4.12) */ |
Harald Welte | 2d3465f | 2020-06-26 15:13:19 +0200 | [diff] [blame] | 294 | int bssgp_tx_bvc_reset2(struct bssgp_bvc_ctx *bctx, uint16_t bvci, uint8_t cause, bool add_cell_id) |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 295 | { |
| 296 | struct msgb *msg = bssgp_msgb_alloc(); |
| 297 | struct bssgp_normal_hdr *bgph = |
| 298 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 299 | uint16_t _bvci = osmo_htons(bvci); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 300 | |
| 301 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP (BVCI=%u) Tx BVC-RESET " |
Max | 2c34ab4 | 2016-03-17 15:42:26 +0100 | [diff] [blame] | 302 | "CAUSE=%s\n", bvci, bssgp_cause_str(cause)); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 303 | |
| 304 | msgb_nsei(msg) = bctx->nsei; |
| 305 | msgb_bvci(msg) = 0; /* Signalling */ |
| 306 | bgph->pdu_type = BSSGP_PDUT_BVC_RESET; |
| 307 | |
| 308 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
| 309 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, &cause); |
Harald Welte | 2d3465f | 2020-06-26 15:13:19 +0200 | [diff] [blame] | 310 | if (add_cell_id) { |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 311 | uint8_t bssgp_cid[8]; |
| 312 | bssgp_create_cell_id(bssgp_cid, &bctx->ra_id, bctx->cell_id); |
| 313 | msgb_tvlv_put(msg, BSSGP_IE_CELL_ID, sizeof(bssgp_cid), bssgp_cid); |
| 314 | } |
| 315 | /* Optional: Feature Bitmap */ |
| 316 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 317 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 318 | } |
Harald Welte | 2d3465f | 2020-06-26 15:13:19 +0200 | [diff] [blame] | 319 | int bssgp_tx_bvc_reset(struct bssgp_bvc_ctx *bctx, uint16_t bvci, uint8_t cause) |
| 320 | { |
Harald Welte | bd771a9 | 2020-10-04 21:42:38 +0200 | [diff] [blame] | 321 | /* The Cell Identifier IE is mandatory in the BVC-RESET PDU sent from BSS to SGSN in order to reset a |
| 322 | * BVC corresponding to a PTP functional entity. The Cell Identifier IE shall not be used in any other |
| 323 | * BVC-RESET PDU. */ |
| 324 | switch (bvci) { |
| 325 | case BVCI_SIGNALLING: |
| 326 | case BVCI_PTM: |
| 327 | return bssgp_tx_bvc_reset2(bctx, bvci, cause, false); |
| 328 | default: |
| 329 | return bssgp_tx_bvc_reset2(bctx, bvci, cause, true); |
| 330 | } |
Harald Welte | 2d3465f | 2020-06-26 15:13:19 +0200 | [diff] [blame] | 331 | } |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 332 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 333 | /*! Transmit a FLOW_CONTROL-BVC (Chapter 10.4.4) |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 334 | * \param[in] bctx BVC Context |
Andreas Eversberg | b8d18f3 | 2012-09-30 16:59:33 +0200 | [diff] [blame] | 335 | * \param[in] tag Additional tag to identify acknowledge |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 336 | * \param[in] bucket_size Maximum bucket size in octets |
| 337 | * \param[in] bucket_leak_rate Bucket leak rate in octets/sec |
| 338 | * \param[in] bmax_default_ms Maximum bucket size default for MS |
| 339 | * \param[in] r_default_ms Bucket leak rate default for MS in octets/sec |
| 340 | * \param[in] bucket_full_ratio Ratio (in percent) of queue filling |
| 341 | * \param[in] queue_delay_ms Average queuing delay in milliseconds |
| 342 | */ |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 343 | int bssgp_tx_fc_bvc(struct bssgp_bvc_ctx *bctx, uint8_t tag, |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 344 | uint32_t bucket_size, uint32_t bucket_leak_rate, |
Jacob Erlbeck | 9385d1e | 2015-05-06 09:29:32 +0200 | [diff] [blame] | 345 | uint32_t bmax_default_ms, uint32_t r_default_ms, |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 346 | uint8_t *bucket_full_ratio, uint32_t *queue_delay_ms) |
| 347 | { |
| 348 | struct msgb *msg; |
| 349 | struct bssgp_normal_hdr *bgph; |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 350 | uint16_t e_bucket_size, e_leak_rate, e_bmax_default_ms, e_r_default_ms; |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 351 | uint16_t e_queue_delay = 0; /* to make gcc happy */ |
| 352 | |
| 353 | if ((bucket_size / 100) > 0xffff) |
| 354 | return -EINVAL; |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 355 | e_bucket_size = osmo_htons(bucket_size / 100); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 356 | |
| 357 | if ((bucket_leak_rate * 8 / 100) > 0xffff) |
| 358 | return -EINVAL; |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 359 | e_leak_rate = osmo_htons((bucket_leak_rate * 8) / 100); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 360 | |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 361 | if ((bmax_default_ms / 100) > 0xffff) |
| 362 | return -EINVAL; |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 363 | e_bmax_default_ms = osmo_htons(bmax_default_ms / 100); |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 364 | |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 365 | if ((r_default_ms * 8 / 100) > 0xffff) |
| 366 | return -EINVAL; |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 367 | e_r_default_ms = osmo_htons((r_default_ms * 8) / 100); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 368 | |
| 369 | if (queue_delay_ms) { |
| 370 | if ((*queue_delay_ms / 10) > 60000) |
| 371 | return -EINVAL; |
| 372 | else if (*queue_delay_ms == 0xFFFFFFFF) |
| 373 | e_queue_delay = 0xFFFF; |
| 374 | else |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 375 | e_queue_delay = osmo_htons(*queue_delay_ms / 10); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | msg = bssgp_msgb_alloc(); |
| 379 | bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 380 | msgb_nsei(msg) = bctx->nsei; |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 381 | msgb_bvci(msg) = bctx->bvci; |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 382 | bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_BVC; |
| 383 | |
| 384 | msgb_tvlv_put(msg, BSSGP_IE_TAG, sizeof(tag), (uint8_t *)&tag); |
| 385 | msgb_tvlv_put(msg, BSSGP_IE_BVC_BUCKET_SIZE, |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 386 | sizeof(e_bucket_size), (uint8_t *) &e_bucket_size); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 387 | msgb_tvlv_put(msg, BSSGP_IE_BUCKET_LEAK_RATE, |
| 388 | sizeof(e_leak_rate), (uint8_t *) &e_leak_rate); |
| 389 | msgb_tvlv_put(msg, BSSGP_IE_BMAX_DEFAULT_MS, |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 390 | sizeof(e_bmax_default_ms), |
| 391 | (uint8_t *) &e_bmax_default_ms); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 392 | msgb_tvlv_put(msg, BSSGP_IE_R_DEFAULT_MS, |
| 393 | sizeof(e_r_default_ms), (uint8_t *) &e_r_default_ms); |
| 394 | if (bucket_full_ratio) |
| 395 | msgb_tvlv_put(msg, BSSGP_IE_BUCKET_FULL_RATIO, |
| 396 | 1, bucket_full_ratio); |
| 397 | if (queue_delay_ms) |
| 398 | msgb_tvlv_put(msg, BSSGP_IE_BVC_MEASUREMENT, |
| 399 | sizeof(e_queue_delay), |
| 400 | (uint8_t *) &e_queue_delay); |
| 401 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 402 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 403 | } |
| 404 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 405 | /*! Transmit a FLOW_CONTROL-MS (Chapter 10.4.6) |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 406 | * \param[in] bctx BVC Context |
Andreas Eversberg | b8d18f3 | 2012-09-30 16:59:33 +0200 | [diff] [blame] | 407 | * \param[in] tlli TLLI to identify MS |
| 408 | * \param[in] tag Additional tag to identify acknowledge |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 409 | * \param[in] ms_bucket_size Maximum bucket size in octets |
| 410 | * \param[in] bucket_leak_rate Bucket leak rate in octets/sec |
| 411 | * \param[in] bucket_full_ratio Ratio (in percent) of queue filling |
| 412 | */ |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 413 | int bssgp_tx_fc_ms(struct bssgp_bvc_ctx *bctx, uint32_t tlli, uint8_t tag, |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 414 | uint32_t ms_bucket_size, uint32_t bucket_leak_rate, |
| 415 | uint8_t *bucket_full_ratio) |
| 416 | { |
| 417 | struct msgb *msg; |
| 418 | struct bssgp_normal_hdr *bgph; |
| 419 | uint16_t e_bucket_size, e_leak_rate; |
| 420 | |
| 421 | if ((ms_bucket_size / 100) > 0xffff) |
| 422 | return -EINVAL; |
| 423 | e_bucket_size = ms_bucket_size / 100; |
| 424 | |
| 425 | if ((bucket_leak_rate * 8 / 100) > 0xffff) |
| 426 | return -EINVAL; |
| 427 | e_leak_rate = (bucket_leak_rate * 8) / 100; |
| 428 | |
| 429 | msg = bssgp_msgb_alloc(); |
| 430 | bgph = (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 431 | msgb_nsei(msg) = bctx->nsei; |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 432 | msgb_bvci(msg) = bctx->bvci; |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 433 | bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_MS; |
| 434 | |
Max | e29ec85 | 2018-01-05 14:30:22 +0100 | [diff] [blame] | 435 | bssgp_msgb_tlli_put(msg, tlli); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 436 | msgb_tvlv_put(msg, BSSGP_IE_TAG, sizeof(tag), (uint8_t *)&tag); |
| 437 | msgb_tvlv_put(msg, BSSGP_IE_MS_BUCKET_SIZE, |
| 438 | sizeof(e_bucket_size), (uint8_t *) &e_bucket_size); |
| 439 | msgb_tvlv_put(msg, BSSGP_IE_BUCKET_LEAK_RATE, |
| 440 | sizeof(e_leak_rate), (uint8_t *) &e_leak_rate); |
| 441 | if (bucket_full_ratio) |
| 442 | msgb_tvlv_put(msg, BSSGP_IE_BUCKET_FULL_RATIO, |
| 443 | 1, bucket_full_ratio); |
| 444 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 445 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | e92866b | 2012-09-10 08:56:04 +0200 | [diff] [blame] | 446 | } |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 447 | |
Neels Hofmeyr | 87e4550 | 2017-06-20 00:17:59 +0200 | [diff] [blame] | 448 | /*! RL-UL-UNITDATA.req (Chapter 10.2.2) |
Andreas Eversberg | b8d18f3 | 2012-09-30 16:59:33 +0200 | [diff] [blame] | 449 | * \param[in] bctx BVC Context |
| 450 | * \param[in] tlli TLLI to identify MS |
| 451 | * \param[in] qos_profile Pointer to three octests of QoS profile |
| 452 | * \param[in] llc_pdu msgb pointer containing UL Unitdata IE payload |
| 453 | */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 454 | int bssgp_tx_ul_ud(struct bssgp_bvc_ctx *bctx, uint32_t tlli, |
| 455 | const uint8_t *qos_profile, struct msgb *llc_pdu) |
| 456 | { |
| 457 | struct msgb *msg = llc_pdu; |
| 458 | uint8_t bssgp_cid[8]; |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 459 | uint8_t bssgp_align[3] = {0, 0, 0}; |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 460 | struct bssgp_ud_hdr *budh; |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 461 | int align = sizeof(*budh); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 462 | |
| 463 | /* FIXME: Optional LSA Identifier List, PFI */ |
| 464 | |
| 465 | /* Cell Identifier */ |
| 466 | bssgp_create_cell_id(bssgp_cid, &bctx->ra_id, bctx->cell_id); |
Andreas Eversberg | f44ed8c | 2012-09-23 06:05:20 +0200 | [diff] [blame] | 467 | align += 2; /* add T+L */ |
| 468 | align += sizeof(bssgp_cid); |
| 469 | |
| 470 | /* First push alignment IE */ |
| 471 | align += 2; /* add T+L */ |
| 472 | align = (4 - align) & 3; /* how many octest are required to align? */ |
| 473 | msgb_tvlv_push(msg, BSSGP_IE_ALIGNMENT, align, bssgp_align); |
| 474 | |
| 475 | /* Push other IEs */ |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 476 | msgb_tvlv_push(msg, BSSGP_IE_CELL_ID, sizeof(bssgp_cid), bssgp_cid); |
| 477 | |
| 478 | /* User Data Header */ |
| 479 | budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 480 | budh->tlli = osmo_htonl(tlli); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 481 | memcpy(budh->qos_profile, qos_profile, 3); |
| 482 | budh->pdu_type = BSSGP_PDUT_UL_UNITDATA; |
| 483 | |
| 484 | /* set NSEI and BVCI in msgb cb */ |
| 485 | msgb_nsei(msg) = bctx->nsei; |
| 486 | msgb_bvci(msg) = bctx->bvci; |
| 487 | |
| 488 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]); |
| 489 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_OUT], msg->len); |
| 490 | |
Alexander Couzens | 85a8fd3 | 2020-07-18 15:57:07 +0200 | [diff] [blame] | 491 | return bssgp_ns_send(bssgp_ns_send_data, msg); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* Parse a single GMM-PAGING.req to a given NSEI/NS-BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 495 | int bssgp_rx_paging(struct bssgp_paging_info *pinfo, |
| 496 | struct msgb *msg) |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 497 | { |
| 498 | struct bssgp_normal_hdr *bgph = |
| 499 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 500 | struct tlv_parsed tp; |
| 501 | uint8_t ra[6]; |
| 502 | int rc, data_len; |
| 503 | |
| 504 | memset(ra, 0, sizeof(ra)); |
| 505 | |
| 506 | data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
| 507 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 508 | if (rc < 0) |
| 509 | goto err_mand_ie; |
| 510 | |
| 511 | switch (bgph->pdu_type) { |
| 512 | case BSSGP_PDUT_PAGING_PS: |
| 513 | pinfo->mode = BSSGP_PAGING_PS; |
| 514 | break; |
| 515 | case BSSGP_PDUT_PAGING_CS: |
| 516 | pinfo->mode = BSSGP_PAGING_CS; |
| 517 | break; |
| 518 | default: |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | |
| 522 | /* IMSI */ |
| 523 | if (!TLVP_PRESENT(&tp, BSSGP_IE_IMSI)) |
| 524 | goto err_mand_ie; |
| 525 | if (!pinfo->imsi) |
Jacob Erlbeck | c1cb75e | 2015-06-18 13:21:30 +0200 | [diff] [blame] | 526 | pinfo->imsi = talloc_zero_size(pinfo, GSM_IMSI_LENGTH); |
Harald Welte | a13fb75 | 2020-06-16 08:44:42 +0200 | [diff] [blame] | 527 | gsm48_mi_to_string(pinfo->imsi, GSM_IMSI_LENGTH, |
| 528 | TLVP_VAL(&tp, BSSGP_IE_IMSI), |
| 529 | TLVP_LEN(&tp, BSSGP_IE_IMSI)); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 530 | |
| 531 | /* DRX Parameters */ |
| 532 | if (!TLVP_PRESENT(&tp, BSSGP_IE_DRX_PARAMS)) |
| 533 | goto err_mand_ie; |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 534 | pinfo->drx_params = tlvp_val16be(&tp, BSSGP_IE_DRX_PARAMS); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 535 | |
| 536 | /* Scope */ |
| 537 | if (TLVP_PRESENT(&tp, BSSGP_IE_BSS_AREA_ID)) { |
| 538 | pinfo->scope = BSSGP_PAGING_BSS_AREA; |
| 539 | } else if (TLVP_PRESENT(&tp, BSSGP_IE_LOCATION_AREA)) { |
| 540 | pinfo->scope = BSSGP_PAGING_LOCATION_AREA; |
| 541 | memcpy(ra, TLVP_VAL(&tp, BSSGP_IE_LOCATION_AREA), |
| 542 | TLVP_LEN(&tp, BSSGP_IE_LOCATION_AREA)); |
| 543 | gsm48_parse_ra(&pinfo->raid, ra); |
| 544 | } else if (TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) { |
| 545 | pinfo->scope = BSSGP_PAGING_ROUTEING_AREA; |
| 546 | memcpy(ra, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA), |
| 547 | TLVP_LEN(&tp, BSSGP_IE_ROUTEING_AREA)); |
| 548 | gsm48_parse_ra(&pinfo->raid, ra); |
| 549 | } else if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { |
| 550 | pinfo->scope = BSSGP_PAGING_BVCI; |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 551 | pinfo->bvci = tlvp_val16be(&tp, BSSGP_IE_BVCI); |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 552 | } else |
| 553 | return -EINVAL; |
| 554 | |
| 555 | /* QoS profile mandatory for PS */ |
| 556 | if (pinfo->mode == BSSGP_PAGING_PS) { |
| 557 | if (!TLVP_PRESENT(&tp, BSSGP_IE_QOS_PROFILE)) |
| 558 | goto err_cond_ie; |
| 559 | if (TLVP_LEN(&tp, BSSGP_IE_QOS_PROFILE) < 3) |
| 560 | goto err; |
| 561 | |
| 562 | memcpy(&pinfo->qos, TLVP_VAL(&tp, BSSGP_IE_QOS_PROFILE), |
| 563 | 3); |
| 564 | } |
| 565 | |
| 566 | /* Optional (P-)TMSI */ |
| 567 | if (TLVP_PRESENT(&tp, BSSGP_IE_TMSI) && |
Harald Welte | 6176b6e | 2016-11-11 15:10:33 +0100 | [diff] [blame] | 568 | TLVP_LEN(&tp, BSSGP_IE_TMSI) >= 4) { |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 569 | if (!pinfo->ptmsi) |
| 570 | pinfo->ptmsi = talloc_zero_size(pinfo, sizeof(uint32_t)); |
Harald Welte | bfe62e5 | 2017-05-15 12:48:30 +0200 | [diff] [blame] | 571 | *(pinfo->ptmsi) = osmo_load32be(TLVP_VAL(&tp, BSSGP_IE_TMSI)); |
Harald Welte | 6176b6e | 2016-11-11 15:10:33 +0100 | [diff] [blame] | 572 | } |
Harald Welte | 85fc314 | 2011-11-25 08:58:40 +0100 | [diff] [blame] | 573 | |
| 574 | return 0; |
| 575 | |
| 576 | err_mand_ie: |
| 577 | err_cond_ie: |
| 578 | err: |
| 579 | /* FIXME */ |
| 580 | return 0; |
| 581 | } |