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