Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | /* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */ |
| 2 | |
Harald Welte | 8645e10 | 2012-06-16 16:09:52 +0800 | [diff] [blame] | 3 | /* (C) 2009-2012 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 19 | * |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 20 | * TODO: |
| 21 | * o properly count incoming BVC-RESET packets in counter group |
| 22 | * o set log context as early as possible for outgoing packets |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #include <errno.h> |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 26 | #include <stdint.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 27 | |
| 28 | #include <netinet/in.h> |
| 29 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 30 | #include <osmocom/core/msgb.h> |
| 31 | #include <osmocom/gsm/tlv.h> |
| 32 | #include <osmocom/core/talloc.h> |
| 33 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 34 | |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 35 | #include <osmocom/gprs/gprs_bssgp.h> |
| 36 | #include <osmocom/gprs/gprs_ns.h> |
| 37 | |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 38 | #include "common_vty.h" |
| 39 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 40 | void *bssgp_tall_ctx = NULL; |
| 41 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 42 | static const struct rate_ctr_desc bssgp_ctr_description[] = { |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 43 | { "packets.in", "Packets at BSSGP Level ( In)" }, |
| 44 | { "packets.out","Packets at BSSGP Level (Out)" }, |
| 45 | { "bytes.in", "Bytes at BSSGP Level ( In)" }, |
| 46 | { "bytes.out", "Bytes at BSSGP Level (Out)" }, |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 47 | { "blocked", "BVC Blocking count" }, |
| 48 | { "discarded", "BVC LLC Discarded count" }, |
| 49 | }; |
| 50 | |
| 51 | static const struct rate_ctr_group_desc bssgp_ctrg_desc = { |
| 52 | .group_name_prefix = "bssgp.bss_ctx", |
| 53 | .group_description = "BSSGP Peer Statistics", |
| 54 | .num_ctr = ARRAY_SIZE(bssgp_ctr_description), |
| 55 | .ctr_desc = bssgp_ctr_description, |
| 56 | }; |
| 57 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 58 | LLIST_HEAD(bssgp_bvc_ctxts); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 59 | |
| 60 | /* Find a BTS Context based on parsed RA ID and Cell ID */ |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 61 | struct bssgp_bvc_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid) |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 62 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 63 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 64 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 65 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 66 | if (!memcmp(&bctx->ra_id, raid, sizeof(bctx->ra_id)) && |
| 67 | bctx->cell_id == cid) |
| 68 | return bctx; |
| 69 | } |
| 70 | return NULL; |
| 71 | } |
| 72 | |
| 73 | /* Find a BTS context based on BVCI+NSEI tuple */ |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 74 | struct bssgp_bvc_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei) |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 75 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 76 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 77 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 78 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 79 | if (bctx->nsei == nsei && bctx->bvci == bvci) |
| 80 | return bctx; |
| 81 | } |
| 82 | return NULL; |
| 83 | } |
| 84 | |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 85 | struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei) |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 86 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 87 | struct bssgp_bvc_ctx *ctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 88 | |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 89 | ctx = talloc_zero(bssgp_tall_ctx, struct bssgp_bvc_ctx); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 90 | if (!ctx) |
| 91 | return NULL; |
| 92 | ctx->bvci = bvci; |
| 93 | ctx->nsei = nsei; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 94 | /* FIXME: BVCI is not unique, only BVCI+NSEI ?!? */ |
| 95 | ctx->ctrg = rate_ctr_group_alloc(ctx, &bssgp_ctrg_desc, bvci); |
| 96 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 97 | llist_add(&ctx->list, &bssgp_bvc_ctxts); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 98 | |
| 99 | return ctx; |
| 100 | } |
| 101 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 102 | /* Chapter 10.4.5: Flow Control BVC ACK */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 103 | static int bssgp_tx_fc_bvc_ack(uint16_t nsei, uint8_t tag, uint16_t ns_bvci) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 104 | { |
| 105 | struct msgb *msg = bssgp_msgb_alloc(); |
| 106 | struct bssgp_normal_hdr *bgph = |
| 107 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 108 | |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 109 | msgb_nsei(msg) = nsei; |
| 110 | msgb_bvci(msg) = ns_bvci; |
| 111 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 112 | bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_BVC_ACK; |
| 113 | msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag); |
| 114 | |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 115 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 116 | } |
| 117 | |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 118 | /* 10.3.7 SUSPEND-ACK PDU */ |
| 119 | int bssgp_tx_suspend_ack(uint16_t nsei, uint32_t tlli, |
| 120 | const struct gprs_ra_id *ra_id, uint8_t suspend_ref) |
| 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 | uint32_t _tlli; |
| 126 | uint8_t ra[6]; |
| 127 | |
| 128 | msgb_nsei(msg) = nsei; |
| 129 | msgb_bvci(msg) = 0; /* Signalling */ |
| 130 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_ACK; |
| 131 | |
| 132 | _tlli = htonl(tlli); |
| 133 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 134 | gsm48_construct_ra(ra, ra_id); |
| 135 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 136 | msgb_tvlv_put(msg, BSSGP_IE_SUSPEND_REF_NR, 1, &suspend_ref); |
| 137 | |
| 138 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 139 | } |
| 140 | |
| 141 | /* 10.3.8 SUSPEND-NACK PDU */ |
| 142 | int bssgp_tx_suspend_nack(uint16_t nsei, uint32_t tlli, |
Dieter Spaar | df30d40 | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 143 | const struct gprs_ra_id *ra_id, |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 144 | uint8_t *cause) |
| 145 | { |
| 146 | struct msgb *msg = bssgp_msgb_alloc(); |
| 147 | struct bssgp_normal_hdr *bgph = |
| 148 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 149 | uint32_t _tlli; |
Dieter Spaar | df30d40 | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 150 | uint8_t ra[6]; |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 151 | |
| 152 | msgb_nsei(msg) = nsei; |
| 153 | msgb_bvci(msg) = 0; /* Signalling */ |
| 154 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 155 | |
| 156 | _tlli = htonl(tlli); |
| 157 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
Dieter Spaar | df30d40 | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 158 | gsm48_construct_ra(ra, ra_id); |
| 159 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 160 | if (cause) |
| 161 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 162 | |
| 163 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 164 | } |
| 165 | |
| 166 | /* 10.3.10 RESUME-ACK PDU */ |
| 167 | int bssgp_tx_resume_ack(uint16_t nsei, uint32_t tlli, |
| 168 | const struct gprs_ra_id *ra_id) |
| 169 | { |
| 170 | struct msgb *msg = bssgp_msgb_alloc(); |
| 171 | struct bssgp_normal_hdr *bgph = |
| 172 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 173 | uint32_t _tlli; |
| 174 | uint8_t ra[6]; |
| 175 | |
| 176 | msgb_nsei(msg) = nsei; |
| 177 | msgb_bvci(msg) = 0; /* Signalling */ |
| 178 | bgph->pdu_type = BSSGP_PDUT_RESUME_ACK; |
| 179 | |
| 180 | _tlli = htonl(tlli); |
| 181 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 182 | gsm48_construct_ra(ra, ra_id); |
| 183 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 184 | |
| 185 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 186 | } |
| 187 | |
| 188 | /* 10.3.11 RESUME-NACK PDU */ |
| 189 | int bssgp_tx_resume_nack(uint16_t nsei, uint32_t tlli, |
| 190 | const struct gprs_ra_id *ra_id, uint8_t *cause) |
| 191 | { |
| 192 | struct msgb *msg = bssgp_msgb_alloc(); |
| 193 | struct bssgp_normal_hdr *bgph = |
| 194 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 195 | uint32_t _tlli; |
| 196 | uint8_t ra[6]; |
| 197 | |
| 198 | msgb_nsei(msg) = nsei; |
| 199 | msgb_bvci(msg) = 0; /* Signalling */ |
| 200 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 201 | |
| 202 | _tlli = htonl(tlli); |
| 203 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 204 | gsm48_construct_ra(ra, ra_id); |
| 205 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 206 | if (cause) |
| 207 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 208 | |
| 209 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 210 | } |
| 211 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 212 | uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf) |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 213 | { |
| 214 | /* 6 octets RAC */ |
| 215 | gsm48_parse_ra(raid, buf); |
| 216 | /* 2 octets CID */ |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 217 | return ntohs(*(uint16_t *) (buf+6)); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Harald Welte | 8cbc4a4 | 2011-11-24 21:32:07 +0100 | [diff] [blame] | 220 | int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, |
| 221 | uint16_t cid) |
| 222 | { |
| 223 | uint16_t *out_cid = (uint16_t *) (buf + 6); |
| 224 | /* 6 octets RAC */ |
| 225 | gsm48_construct_ra(buf, raid); |
| 226 | /* 2 octets CID */ |
| 227 | *out_cid = htons(cid); |
| 228 | |
| 229 | return 8; |
| 230 | } |
| 231 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 232 | /* Chapter 8.4 BVC-Reset Procedure */ |
| 233 | static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, |
| 234 | uint16_t ns_bvci) |
| 235 | { |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 236 | struct osmo_bssgp_prim nmp; |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 237 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 238 | uint16_t nsei = msgb_nsei(msg); |
| 239 | uint16_t bvci; |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 240 | int rc; |
| 241 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 242 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 243 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx RESET cause=%s\n", bvci, |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 244 | bssgp_cause_str(*TLVP_VAL(tp, BSSGP_IE_CAUSE))); |
| 245 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 246 | /* look-up or create the BTS context for this BVC */ |
| 247 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 248 | if (!bctx) |
| 249 | bctx = btsctx_alloc(bvci, nsei); |
| 250 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 251 | /* As opposed to NS-VCs, BVCs are NOT blocked after RESET */ |
| 252 | bctx->state &= ~BVC_S_BLOCKED; |
| 253 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 254 | /* When we receive a BVC-RESET PDU (at least of a PTP BVCI), the BSS |
| 255 | * informs us about its RAC + Cell ID, so we can create a mapping */ |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 256 | if (bvci != 0 && bvci != 1) { |
| 257 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID)) { |
Harald Welte | c45a804 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 258 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx RESET " |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 259 | "missing mandatory IE\n", bvci); |
| 260 | return -EINVAL; |
| 261 | } |
| 262 | /* actually extract RAC / CID */ |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 263 | bctx->cell_id = bssgp_parse_cell_id(&bctx->ra_id, |
| 264 | TLVP_VAL(tp, BSSGP_IE_CELL_ID)); |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 265 | LOGP(DBSSGP, LOGL_NOTICE, "Cell %u-%u-%u-%u CI %u on BVCI %u\n", |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 266 | bctx->ra_id.mcc, bctx->ra_id.mnc, bctx->ra_id.lac, |
| 267 | bctx->ra_id.rac, bctx->cell_id, bvci); |
| 268 | } |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 269 | |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 270 | /* Send NM_BVC_RESET.ind to NM */ |
| 271 | memset(&nmp, 0, sizeof(nmp)); |
| 272 | nmp.nsei = nsei; |
| 273 | nmp.bvci = bvci; |
| 274 | nmp.tp = tp; |
| 275 | nmp.ra_id = &bctx->ra_id; |
| 276 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_RESET, |
| 277 | PRIM_OP_INDICATION, msg); |
| 278 | bssgp_prim_cb(&nmp.oph, NULL); |
| 279 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 280 | /* Acknowledge the RESET to the BTS */ |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 281 | rc = bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 282 | nsei, bvci, ns_bvci); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 283 | return 0; |
| 284 | } |
| 285 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 286 | static int bssgp_rx_bvc_block(struct msgb *msg, struct tlv_parsed *tp) |
| 287 | { |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 288 | struct osmo_bssgp_prim nmp; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 289 | uint16_t bvci; |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 290 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 291 | |
| 292 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 293 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 2b36ae1 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 294 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 295 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 296 | "received block for signalling BVC!?!\n", |
| 297 | msgb_nsei(msg), msgb_bvci(msg)); |
| 298 | return 0; |
| 299 | } |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 300 | |
Harald Welte | c45a804 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 301 | LOGP(DBSSGP, LOGL_INFO, "BSSGP Rx BVCI=%u BVC-BLOCK\n", bvci); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 302 | |
| 303 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 304 | if (!ptp_ctx) |
| 305 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 306 | |
| 307 | ptp_ctx->state |= BVC_S_BLOCKED; |
| 308 | rate_ctr_inc(&ptp_ctx->ctrg->ctr[BSSGP_CTR_BLOCKED]); |
| 309 | |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 310 | /* Send NM_BVC_BLOCK.ind to NM */ |
| 311 | memset(&nmp, 0, sizeof(nmp)); |
| 312 | nmp.nsei = msgb_nsei(msg); |
| 313 | nmp.bvci = bvci; |
| 314 | nmp.tp = tp; |
| 315 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_BLOCK, |
| 316 | PRIM_OP_INDICATION, msg); |
| 317 | bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 318 | |
| 319 | /* We always acknowledge the BLOCKing */ |
| 320 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, msgb_nsei(msg), |
| 321 | bvci, msgb_bvci(msg)); |
| 322 | }; |
| 323 | |
| 324 | static int bssgp_rx_bvc_unblock(struct msgb *msg, struct tlv_parsed *tp) |
| 325 | { |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 326 | struct osmo_bssgp_prim nmp; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 327 | uint16_t bvci; |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 328 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 329 | |
| 330 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 331 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 2b36ae1 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 332 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 333 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 334 | "received unblock for signalling BVC!?!\n", |
| 335 | msgb_nsei(msg), msgb_bvci(msg)); |
| 336 | return 0; |
| 337 | } |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 338 | |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 339 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx BVC-UNBLOCK\n", bvci); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 340 | |
| 341 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 342 | if (!ptp_ctx) |
| 343 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 344 | |
| 345 | ptp_ctx->state &= ~BVC_S_BLOCKED; |
| 346 | |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 347 | /* Send NM_BVC_UNBLOCK.ind to NM */ |
| 348 | memset(&nmp, 0, sizeof(nmp)); |
| 349 | nmp.nsei = msgb_nsei(msg); |
| 350 | nmp.bvci = bvci; |
| 351 | nmp.tp = tp; |
| 352 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_UNBLOCK, |
| 353 | PRIM_OP_INDICATION, msg); |
| 354 | bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 355 | |
| 356 | /* We always acknowledge the unBLOCKing */ |
| 357 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, msgb_nsei(msg), |
| 358 | bvci, msgb_bvci(msg)); |
| 359 | }; |
| 360 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 361 | /* Uplink unit-data */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 362 | static int bssgp_rx_ul_ud(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 363 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 364 | { |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 365 | struct osmo_bssgp_prim gbp; |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 366 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 367 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 368 | /* extract TLLI and parse TLV IEs */ |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 369 | msgb_tlli(msg) = ntohl(budh->tlli); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 370 | |
Harald Welte | c45a804 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 371 | DEBUGP(DBSSGP, "BSSGP TLLI=0x%08x Rx UPLINK-UNITDATA\n", msgb_tlli(msg)); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 372 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 373 | /* Cell ID and LLC_PDU are the only mandatory IE */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 374 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID) || |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 375 | !TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU)) { |
| 376 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP TLLI=0x%08x Rx UL-UD " |
| 377 | "missing mandatory IE\n", msgb_tlli(msg)); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 378 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 379 | } |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 380 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 381 | /* store pointer to LLC header and CELL ID in msgb->cb */ |
Holger Hans Peter Freyther | 2e22a5d | 2010-05-23 21:11:19 +0800 | [diff] [blame] | 382 | msgb_llch(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_LLC_PDU); |
| 383 | msgb_bcid(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_CELL_ID); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 384 | |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 385 | /* Send BSSGP_UL_UD.ind to NM */ |
| 386 | memset(&gbp, 0, sizeof(gbp)); |
| 387 | gbp.nsei = ctx->nsei; |
| 388 | gbp.bvci = ctx->bvci; |
| 389 | gbp.tlli = msgb_tlli(msg); |
| 390 | gbp.tp = tp; |
| 391 | osmo_prim_init(&gbp.oph, SAP_BSSGP_LL, PRIM_BSSGP_UL_UD, |
| 392 | PRIM_OP_INDICATION, msg); |
| 393 | return bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 394 | } |
| 395 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 396 | static int bssgp_rx_suspend(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 397 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 398 | { |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 399 | struct osmo_bssgp_prim gbp; |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 400 | struct bssgp_normal_hdr *bgph = |
| 401 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 402 | struct gprs_ra_id raid; |
| 403 | uint32_t tlli; |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 404 | int rc; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 405 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 406 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 407 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) { |
| 408 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx SUSPEND " |
| 409 | "missing mandatory IE\n", ctx->bvci); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 410 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 411 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 412 | |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 413 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 414 | |
Harald Welte | 3d379ba | 2010-05-31 20:18:35 +0200 | [diff] [blame] | 415 | DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=0x%08x Rx SUSPEND\n", |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 416 | ctx->bvci, tlli); |
| 417 | |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 418 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 419 | |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 420 | /* Inform GMM about the SUSPEND request */ |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 421 | memset(&gbp, 0, sizeof(gbp)); |
| 422 | gbp.nsei = msgb_nsei(msg); |
| 423 | gbp.bvci = ctx->bvci; |
| 424 | gbp.tlli = tlli; |
| 425 | gbp.ra_id = &raid; |
| 426 | osmo_prim_init(&gbp.oph, SAP_BSSGP_GMM, PRIM_BSSGP_GMM_SUSPEND, |
| 427 | PRIM_OP_REQUEST, msg); |
| 428 | |
| 429 | rc = bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 430 | if (rc < 0) |
Dieter Spaar | df30d40 | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 431 | return bssgp_tx_suspend_nack(msgb_nsei(msg), tlli, &raid, NULL); |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 432 | |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 433 | bssgp_tx_suspend_ack(msgb_nsei(msg), tlli, &raid, 0); |
| 434 | |
Holger Hans Peter Freyther | 9e28ecc | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 435 | return 0; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 436 | } |
| 437 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 438 | static int bssgp_rx_resume(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 439 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 440 | { |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 441 | struct osmo_bssgp_prim gbp; |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 442 | struct bssgp_normal_hdr *bgph = |
| 443 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 444 | struct gprs_ra_id raid; |
| 445 | uint32_t tlli; |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 446 | uint8_t suspend_ref; |
| 447 | int rc; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 448 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 449 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 450 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA) || |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 451 | !TLVP_PRESENT(tp, BSSGP_IE_SUSPEND_REF_NR)) { |
| 452 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx RESUME " |
| 453 | "missing mandatory IE\n", ctx->bvci); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 454 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 455 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 456 | |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 457 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 458 | suspend_ref = *TLVP_VAL(tp, BSSGP_IE_SUSPEND_REF_NR); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 459 | |
Harald Welte | c45a804 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 460 | DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=0x%08x Rx RESUME\n", ctx->bvci, tlli); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 461 | |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 462 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 463 | |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 464 | /* Inform GMM about the RESUME request */ |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 465 | memset(&gbp, 0, sizeof(gbp)); |
| 466 | gbp.nsei = msgb_nsei(msg); |
| 467 | gbp.bvci = ctx->bvci; |
| 468 | gbp.tlli = tlli; |
| 469 | gbp.ra_id = &raid; |
| 470 | gbp.u.resume.suspend_ref = suspend_ref; |
| 471 | osmo_prim_init(&gbp.oph, SAP_BSSGP_GMM, PRIM_BSSGP_GMM_RESUME, |
| 472 | PRIM_OP_REQUEST, msg); |
| 473 | |
| 474 | rc = bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 5bfe499 | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 475 | if (rc < 0) |
| 476 | return bssgp_tx_resume_nack(msgb_nsei(msg), tlli, &raid, |
| 477 | NULL); |
| 478 | |
Harald Welte | 02ea86f | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 479 | bssgp_tx_resume_ack(msgb_nsei(msg), tlli, &raid); |
Holger Hans Peter Freyther | 9e28ecc | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 480 | return 0; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 481 | } |
| 482 | |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 483 | |
| 484 | static int bssgp_rx_llc_disc(struct msgb *msg, struct tlv_parsed *tp, |
| 485 | struct bssgp_bvc_ctx *ctx) |
| 486 | { |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 487 | struct osmo_bssgp_prim nmp; |
Harald Welte | d30e087 | 2010-07-23 21:59:29 +0200 | [diff] [blame] | 488 | uint32_t tlli = 0; |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 489 | |
| 490 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 491 | !TLVP_PRESENT(tp, BSSGP_IE_LLC_FRAMES_DISCARDED) || |
| 492 | !TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
| 493 | !TLVP_PRESENT(tp, BSSGP_IE_NUM_OCT_AFF)) { |
| 494 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx LLC DISCARDED " |
| 495 | "missing mandatory IE\n", ctx->bvci); |
| 496 | } |
| 497 | |
Harald Welte | d30e087 | 2010-07-23 21:59:29 +0200 | [diff] [blame] | 498 | if (TLVP_PRESENT(tp, BSSGP_IE_TLLI)) |
| 499 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 500 | |
Harald Welte | c45a804 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 501 | DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=%08x Rx LLC DISCARDED\n", |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 502 | ctx->bvci, tlli); |
| 503 | |
| 504 | rate_ctr_inc(&ctx->ctrg->ctr[BSSGP_CTR_DISCARDED]); |
| 505 | |
Harald Welte | b1fd902 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 506 | /* send NM_LLC_DISCARDED to NM */ |
| 507 | memset(&nmp, 0, sizeof(nmp)); |
| 508 | nmp.nsei = msgb_nsei(msg); |
| 509 | nmp.bvci = ctx->bvci; |
| 510 | nmp.tlli = tlli; |
| 511 | nmp.tp = tp; |
| 512 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_LLC_DISCARDED, |
| 513 | PRIM_OP_INDICATION, msg); |
| 514 | |
| 515 | return bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 516 | } |
| 517 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 518 | static int bssgp_rx_fc_bvc(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 519 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 520 | { |
| 521 | |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 522 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx Flow Control BVC\n", |
| 523 | bctx->bvci); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 524 | |
| 525 | if (!TLVP_PRESENT(tp, BSSGP_IE_TAG) || |
| 526 | !TLVP_PRESENT(tp, BSSGP_IE_BVC_BUCKET_SIZE) || |
| 527 | !TLVP_PRESENT(tp, BSSGP_IE_BUCKET_LEAK_RATE) || |
| 528 | !TLVP_PRESENT(tp, BSSGP_IE_BMAX_DEFAULT_MS) || |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 529 | !TLVP_PRESENT(tp, BSSGP_IE_R_DEFAULT_MS)) { |
| 530 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx FC BVC " |
| 531 | "missing mandatory IE\n", bctx->bvci); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 532 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 533 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 534 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 535 | /* FIXME: actually implement flow control */ |
| 536 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 537 | /* Send FLOW_CONTROL_BVC_ACK */ |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 538 | return bssgp_tx_fc_bvc_ack(msgb_nsei(msg), *TLVP_VAL(tp, BSSGP_IE_TAG), |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 539 | msgb_bvci(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 540 | } |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 541 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 542 | /* Receive a BSSGP PDU from a BSS on a PTP BVCI */ |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 543 | static int bssgp_rx_ptp(struct msgb *msg, struct tlv_parsed *tp, |
| 544 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 545 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 546 | struct bssgp_normal_hdr *bgph = |
| 547 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 548 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 549 | int rc = 0; |
| 550 | |
Harald Welte | 2b36ae1 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 551 | /* If traffic is received on a BVC that is marked as blocked, the |
| 552 | * received PDU shall not be accepted and a STATUS PDU (Cause value: |
| 553 | * BVC Blocked) shall be sent to the peer entity on the signalling BVC */ |
| 554 | if (bctx->state & BVC_S_BLOCKED && pdu_type != BSSGP_PDUT_STATUS) { |
| 555 | uint16_t bvci = msgb_bvci(msg); |
| 556 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &bvci, msg); |
| 557 | } |
| 558 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 559 | switch (pdu_type) { |
| 560 | case BSSGP_PDUT_UL_UNITDATA: |
| 561 | /* some LLC data from the MS */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 562 | rc = bssgp_rx_ul_ud(msg, tp, bctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 563 | break; |
| 564 | case BSSGP_PDUT_RA_CAPABILITY: |
| 565 | /* BSS requests RA capability or IMSI */ |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 566 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx RA CAPABILITY UPDATE\n", |
| 567 | bctx->bvci); |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 568 | /* FIXME: send GMM_RA_CAPABILITY_UPDATE.ind to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 569 | /* FIXME: send RA_CAPA_UPDATE_ACK */ |
| 570 | break; |
| 571 | case BSSGP_PDUT_RADIO_STATUS: |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 572 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx RADIO STATUS\n", bctx->bvci); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 573 | /* BSS informs us of some exception */ |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 574 | /* FIXME: send GMM_RADIO_STATUS.ind to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 575 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 576 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 577 | /* BSS informs us of available bandwidth in Gb interface */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 578 | rc = bssgp_rx_fc_bvc(msg, tp, bctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 579 | break; |
| 580 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 581 | /* BSS informs us of available bandwidth to one MS */ |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 582 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx Flow Control MS\n", |
| 583 | bctx->bvci); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 584 | /* FIXME: actually implement flow control */ |
| 585 | /* FIXME: Send FLOW_CONTROL_MS_ACK */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 586 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 587 | case BSSGP_PDUT_STATUS: |
| 588 | /* Some exception has occurred */ |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 589 | /* FIXME: send NM_STATUS.ind to NM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 590 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 591 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 592 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 593 | case BSSGP_PDUT_MODIFY_BSS_PFC: |
| 594 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 595 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx PDU type 0x%02x not [yet] " |
| 596 | "implemented\n", bctx->bvci, pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 597 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 598 | break; |
| 599 | /* those only exist in the SGSN -> BSS direction */ |
| 600 | case BSSGP_PDUT_DL_UNITDATA: |
| 601 | case BSSGP_PDUT_PAGING_PS: |
| 602 | case BSSGP_PDUT_PAGING_CS: |
| 603 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 604 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
| 605 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 606 | DEBUGP(DBSSGP, "BSSGP BVCI=%u PDU type 0x%02x only exists " |
| 607 | "in DL\n", bctx->bvci, pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 608 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 609 | rc = -EINVAL; |
| 610 | break; |
| 611 | default: |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 612 | DEBUGP(DBSSGP, "BSSGP BVCI=%u PDU type 0x%02x unknown\n", |
| 613 | bctx->bvci, pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 614 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 615 | break; |
| 616 | } |
| 617 | |
Holger Hans Peter Freyther | 9e28ecc | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 618 | return rc; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | /* Receive a BSSGP PDU from a BSS on a SIGNALLING BVCI */ |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 622 | static int bssgp_rx_sign(struct msgb *msg, struct tlv_parsed *tp, |
| 623 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 624 | { |
| 625 | struct bssgp_normal_hdr *bgph = |
| 626 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 627 | uint8_t pdu_type = bgph->pdu_type; |
| 628 | int rc = 0; |
| 629 | uint16_t ns_bvci = msgb_bvci(msg); |
| 630 | uint16_t bvci; |
| 631 | |
| 632 | switch (bgph->pdu_type) { |
| 633 | case BSSGP_PDUT_SUSPEND: |
| 634 | /* MS wants to suspend */ |
| 635 | rc = bssgp_rx_suspend(msg, tp, bctx); |
| 636 | break; |
| 637 | case BSSGP_PDUT_RESUME: |
| 638 | /* MS wants to resume */ |
| 639 | rc = bssgp_rx_resume(msg, tp, bctx); |
| 640 | break; |
| 641 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 642 | /* BSS informs us it has performed LL FLUSH */ |
Harald Welte | c45a804 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 643 | DEBUGP(DBSSGP, "BSSGP Rx BVCI=%u FLUSH LL ACK\n", bctx->bvci); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 644 | /* FIXME: send NM_FLUSH_LL.res to NM */ |
| 645 | break; |
| 646 | case BSSGP_PDUT_LLC_DISCARD: |
| 647 | /* BSS informs that some LLC PDU's have been discarded */ |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 648 | rc = bssgp_rx_llc_disc(msg, tp, bctx); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 649 | break; |
| 650 | case BSSGP_PDUT_BVC_BLOCK: |
| 651 | /* BSS tells us that BVC shall be blocked */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 652 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 653 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) { |
| 654 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Rx BVC-BLOCK " |
| 655 | "missing mandatory IE\n"); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 656 | goto err_mand_ie; |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 657 | } |
Harald Welte | 72b4b20 | 2010-05-31 17:16:36 +0200 | [diff] [blame] | 658 | rc = bssgp_rx_bvc_block(msg, tp); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 659 | break; |
| 660 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 661 | /* BSS tells us that BVC shall be unblocked */ |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 662 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI)) { |
| 663 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Rx BVC-UNBLOCK " |
| 664 | "missing mandatory IE\n"); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 665 | goto err_mand_ie; |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 666 | } |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 667 | rc = bssgp_rx_bvc_unblock(msg, tp); |
| 668 | break; |
| 669 | case BSSGP_PDUT_BVC_RESET: |
| 670 | /* BSS tells us that BVC init is required */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 671 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 672 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) { |
| 673 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Rx BVC-RESET " |
| 674 | "missing mandatory IE\n"); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 675 | goto err_mand_ie; |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 676 | } |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 677 | rc = bssgp_rx_bvc_reset(msg, tp, ns_bvci); |
| 678 | break; |
| 679 | case BSSGP_PDUT_STATUS: |
| 680 | /* Some exception has occurred */ |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 681 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx BVC STATUS\n", bctx->bvci); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 682 | /* FIXME: send NM_STATUS.ind to NM */ |
| 683 | break; |
| 684 | /* those only exist in the SGSN -> BSS direction */ |
| 685 | case BSSGP_PDUT_PAGING_PS: |
| 686 | case BSSGP_PDUT_PAGING_CS: |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 687 | case BSSGP_PDUT_SUSPEND_ACK: |
| 688 | case BSSGP_PDUT_SUSPEND_NACK: |
| 689 | case BSSGP_PDUT_RESUME_ACK: |
| 690 | case BSSGP_PDUT_RESUME_NACK: |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 691 | case BSSGP_PDUT_FLUSH_LL: |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 692 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 693 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 694 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 695 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx PDU type 0x%02x only exists " |
| 696 | "in DL\n", bctx->bvci, pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 697 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 698 | rc = -EINVAL; |
| 699 | break; |
| 700 | default: |
Harald Welte | c91ce1a | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 701 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx PDU type 0x%02x unknown\n", |
| 702 | bctx->bvci, pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 703 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 704 | break; |
| 705 | } |
| 706 | |
| 707 | return rc; |
| 708 | err_mand_ie: |
| 709 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 710 | } |
| 711 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 712 | /* We expect msgb_bssgph() to point to the BSSGP header */ |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 713 | int bssgp_rcvmsg(struct msgb *msg) |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 714 | { |
| 715 | struct bssgp_normal_hdr *bgph = |
| 716 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 717 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
| 718 | struct tlv_parsed tp; |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 719 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 720 | uint8_t pdu_type = bgph->pdu_type; |
| 721 | uint16_t ns_bvci = msgb_bvci(msg); |
| 722 | int data_len; |
| 723 | int rc = 0; |
| 724 | |
| 725 | /* Identifiers from DOWN: NSEI, BVCI (both in msg->cb) */ |
| 726 | |
| 727 | /* UNITDATA BSSGP headers have TLLI in front */ |
| 728 | if (pdu_type != BSSGP_PDUT_UL_UNITDATA && |
| 729 | pdu_type != BSSGP_PDUT_DL_UNITDATA) { |
| 730 | data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
| 731 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 732 | } else { |
| 733 | data_len = msgb_bssgp_len(msg) - sizeof(*budh); |
| 734 | rc = bssgp_tlv_parse(&tp, budh->data, data_len); |
| 735 | } |
| 736 | |
| 737 | /* look-up or create the BTS context for this BVC */ |
| 738 | bctx = btsctx_by_bvci_nsei(ns_bvci, msgb_nsei(msg)); |
| 739 | /* Only a RESET PDU can create a new BVC context */ |
| 740 | if (!bctx && pdu_type != BSSGP_PDUT_BVC_RESET) { |
| 741 | LOGP(DBSSGP, LOGL_NOTICE, "NSEI=%u/BVCI=%u Rejecting PDU " |
| 742 | "type %u for unknown BVCI\n", msgb_nsei(msg), ns_bvci, |
| 743 | pdu_type); |
| 744 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
| 745 | } |
| 746 | |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 747 | if (bctx) { |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 748 | log_set_context(GPRS_CTX_BVC, bctx); |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 749 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_IN]); |
| 750 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_IN], |
| 751 | msgb_bssgp_len(msg)); |
| 752 | } |
| 753 | |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 754 | if (ns_bvci == BVCI_SIGNALLING) |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 755 | rc = bssgp_rx_sign(msg, &tp, bctx); |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 756 | else if (ns_bvci == BVCI_PTM) |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 757 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
| 758 | else |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 759 | rc = bssgp_rx_ptp(msg, &tp, bctx); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 760 | |
| 761 | return rc; |
| 762 | } |
| 763 | |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 764 | int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, |
| 765 | struct bssgp_dl_ud_par *dup) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 766 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 767 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 768 | struct bssgp_ud_hdr *budh; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 769 | uint8_t llc_pdu_tlv_hdr_len = 2; |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 770 | uint8_t *llc_pdu_tlv; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 771 | uint16_t msg_len = msg->len; |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 772 | uint16_t bvci = msgb_bvci(msg); |
| 773 | uint16_t nsei = msgb_nsei(msg); |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 774 | uint16_t _pdu_lifetime = htons(pdu_lifetime); /* centi-seconds */ |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 775 | uint16_t drx_params; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 776 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 777 | /* Identifiers from UP: TLLI, BVCI, NSEI (all in msgb->cb) */ |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 778 | if (bvci <= BVCI_PTM ) { |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 779 | LOGP(DBSSGP, LOGL_ERROR, "Cannot send DL-UD to BVCI %u\n", |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 780 | bvci); |
| 781 | return -EINVAL; |
| 782 | } |
| 783 | |
| 784 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 785 | if (!bctx) { |
| 786 | /* FIXME: don't simply create missing context, but reject message */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 787 | bctx = btsctx_alloc(bvci, nsei); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 788 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 789 | |
| 790 | if (msg->len > TVLV_MAX_ONEBYTE) |
| 791 | llc_pdu_tlv_hdr_len += 1; |
| 792 | |
| 793 | /* prepend the tag and length of the LLC-PDU TLV */ |
| 794 | llc_pdu_tlv = msgb_push(msg, llc_pdu_tlv_hdr_len); |
| 795 | llc_pdu_tlv[0] = BSSGP_IE_LLC_PDU; |
| 796 | if (llc_pdu_tlv_hdr_len > 2) { |
| 797 | llc_pdu_tlv[1] = msg_len >> 8; |
| 798 | llc_pdu_tlv[2] = msg_len & 0xff; |
| 799 | } else { |
Sylvain Munaut | 644a0ca | 2010-06-09 21:13:13 +0200 | [diff] [blame] | 800 | llc_pdu_tlv[1] = msg_len & 0x7f; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 801 | llc_pdu_tlv[1] |= 0x80; |
| 802 | } |
| 803 | |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 804 | /* FIXME: optional elements: Alignment, UTRAN CCO, LSA, PFI */ |
| 805 | |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 806 | if (dup) { |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 807 | /* Old TLLI to help BSS map from old->new */ |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 808 | if (dup->tlli) { |
| 809 | uint32_t tlli = htonl(*dup->tlli); |
| 810 | msgb_tvlv_push(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &tlli); |
| 811 | } |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 812 | |
| 813 | /* IMSI */ |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 814 | if (strlen(dup->imsi)) { |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 815 | uint8_t mi[10]; |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 816 | int imsi_len = gsm48_generate_mid_from_imsi(mi, dup->imsi); |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 817 | if (imsi_len > 2) |
| 818 | msgb_tvlv_push(msg, BSSGP_IE_IMSI, |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 819 | imsi_len-2, mi+2); |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 820 | } |
| 821 | |
| 822 | /* DRX parameters */ |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 823 | drx_params = htons(dup->drx_parms); |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 824 | msgb_tvlv_push(msg, BSSGP_IE_DRX_PARAMS, 2, |
| 825 | (uint8_t *) &drx_params); |
| 826 | |
| 827 | /* FIXME: Priority */ |
| 828 | |
| 829 | /* MS Radio Access Capability */ |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 830 | if (dup->ms_ra_cap.len) |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 831 | msgb_tvlv_push(msg, BSSGP_IE_MS_RADIO_ACCESS_CAP, |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 832 | dup->ms_ra_cap.len, dup->ms_ra_cap.v); |
| 833 | |
Harald Welte | 56a0145 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 834 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 835 | |
| 836 | /* prepend the pdu lifetime */ |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 837 | msgb_tvlv_push(msg, BSSGP_IE_PDU_LIFETIME, 2, (uint8_t *)&_pdu_lifetime); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 838 | |
| 839 | /* prepend the QoS profile, TLLI and pdu type */ |
| 840 | budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); |
Harald Welte | faa70ff | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 841 | memcpy(budh->qos_profile, dup->qos_profile, sizeof(budh->qos_profile)); |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 842 | budh->tlli = htonl(msgb_tlli(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 843 | budh->pdu_type = BSSGP_PDUT_DL_UNITDATA; |
| 844 | |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 845 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]); |
| 846 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_OUT], msg->len); |
| 847 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 848 | /* Identifiers down: BVCI, NSEI (in msgb->cb) */ |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 849 | |
| 850 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 851 | } |
Harald Welte | bb35c45 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 852 | |
| 853 | /* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */ |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 854 | int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, |
| 855 | struct bssgp_paging_info *pinfo) |
Harald Welte | bb35c45 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 856 | { |
| 857 | struct msgb *msg = bssgp_msgb_alloc(); |
| 858 | struct bssgp_normal_hdr *bgph = |
| 859 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 860 | uint16_t drx_params = htons(pinfo->drx_params); |
| 861 | uint8_t mi[10]; |
| 862 | int imsi_len = gsm48_generate_mid_from_imsi(mi, pinfo->imsi); |
| 863 | uint8_t ra[6]; |
| 864 | |
| 865 | if (imsi_len < 2) |
| 866 | return -EINVAL; |
| 867 | |
| 868 | msgb_nsei(msg) = nsei; |
| 869 | msgb_bvci(msg) = ns_bvci; |
| 870 | |
| 871 | if (pinfo->mode == BSSGP_PAGING_PS) |
| 872 | bgph->pdu_type = BSSGP_PDUT_PAGING_PS; |
| 873 | else |
| 874 | bgph->pdu_type = BSSGP_PDUT_PAGING_CS; |
| 875 | /* IMSI */ |
| 876 | msgb_tvlv_put(msg, BSSGP_IE_IMSI, imsi_len-2, mi+2); |
| 877 | /* DRX Parameters */ |
| 878 | msgb_tvlv_put(msg, BSSGP_IE_DRX_PARAMS, 2, |
| 879 | (uint8_t *) &drx_params); |
| 880 | /* Scope */ |
| 881 | switch (pinfo->scope) { |
| 882 | case BSSGP_PAGING_BSS_AREA: |
| 883 | { |
| 884 | uint8_t null = 0; |
| 885 | msgb_tvlv_put(msg, BSSGP_IE_BSS_AREA_ID, 1, &null); |
| 886 | } |
| 887 | break; |
| 888 | case BSSGP_PAGING_LOCATION_AREA: |
| 889 | gsm48_construct_ra(ra, &pinfo->raid); |
| 890 | msgb_tvlv_put(msg, BSSGP_IE_LOCATION_AREA, 4, ra); |
| 891 | break; |
| 892 | case BSSGP_PAGING_ROUTEING_AREA: |
| 893 | gsm48_construct_ra(ra, &pinfo->raid); |
| 894 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 895 | break; |
| 896 | case BSSGP_PAGING_BVCI: |
| 897 | { |
| 898 | uint16_t bvci = htons(pinfo->bvci); |
| 899 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *)&bvci); |
| 900 | } |
| 901 | break; |
| 902 | } |
| 903 | /* QoS profile mandatory for PS */ |
| 904 | if (pinfo->mode == BSSGP_PAGING_PS) |
| 905 | msgb_tvlv_put(msg, BSSGP_IE_QOS_PROFILE, 3, pinfo->qos); |
| 906 | |
| 907 | /* Optional (P-)TMSI */ |
| 908 | if (pinfo->ptmsi) { |
| 909 | uint32_t ptmsi = htonl(*pinfo->ptmsi); |
| 910 | msgb_tvlv_put(msg, BSSGP_IE_TMSI, 4, (uint8_t *) &ptmsi); |
| 911 | } |
| 912 | |
| 913 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 914 | } |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 915 | |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 916 | void bssgp_set_log_ss(int ss) |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 917 | { |
| 918 | DBSSGP = ss; |
| 919 | } |