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 | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 3 | /* (C) 2009-2010 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 |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 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 |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 21 | * TODO: |
| 22 | * o properly count incoming BVC-RESET packets in counter group |
| 23 | * o set log context as early as possible for outgoing packets |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <errno.h> |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 27 | #include <stdint.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 28 | |
| 29 | #include <netinet/in.h> |
| 30 | |
| 31 | #include <osmocore/msgb.h> |
| 32 | #include <osmocore/tlv.h> |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 33 | #include <osmocore/talloc.h> |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 34 | #include <osmocore/rate_ctr.h> |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 35 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 36 | #include <openbsc/debug.h> |
| 37 | #include <openbsc/gsm_data.h> |
| 38 | #include <openbsc/gsm_04_08_gprs.h> |
| 39 | #include <openbsc/gprs_bssgp.h> |
| 40 | #include <openbsc/gprs_llc.h> |
| 41 | #include <openbsc/gprs_ns.h> |
| 42 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 43 | void *bssgp_tall_ctx = NULL; |
| 44 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 45 | #define BVC_F_BLOCKED 0x0001 |
| 46 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 47 | enum bssgp_ctr { |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 48 | BSSGP_CTR_PKTS_IN, |
| 49 | BSSGP_CTR_PKTS_OUT, |
| 50 | BSSGP_CTR_BYTES_IN, |
| 51 | BSSGP_CTR_BYTES_OUT, |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 52 | BSSGP_CTR_BLOCKED, |
| 53 | BSSGP_CTR_DISCARDED, |
| 54 | }; |
| 55 | |
| 56 | static const struct rate_ctr_desc bssgp_ctr_description[] = { |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 57 | { "packets.in", "Packets at BSSGP Level ( In)" }, |
| 58 | { "packets.out","Packets at BSSGP Level (Out)" }, |
| 59 | { "bytes.in", "Bytes at BSSGP Level ( In)" }, |
| 60 | { "bytes.out", "Bytes at BSSGP Level (Out)" }, |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 61 | { "blocked", "BVC Blocking count" }, |
| 62 | { "discarded", "BVC LLC Discarded count" }, |
| 63 | }; |
| 64 | |
| 65 | static const struct rate_ctr_group_desc bssgp_ctrg_desc = { |
| 66 | .group_name_prefix = "bssgp.bss_ctx", |
| 67 | .group_description = "BSSGP Peer Statistics", |
| 68 | .num_ctr = ARRAY_SIZE(bssgp_ctr_description), |
| 69 | .ctr_desc = bssgp_ctr_description, |
| 70 | }; |
| 71 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 72 | LLIST_HEAD(bssgp_bvc_ctxts); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 73 | |
| 74 | /* Find a BTS Context based on parsed RA ID and Cell ID */ |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 75 | 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] | 76 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 77 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 78 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 79 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 80 | if (!memcmp(&bctx->ra_id, raid, sizeof(bctx->ra_id)) && |
| 81 | bctx->cell_id == cid) |
| 82 | return bctx; |
| 83 | } |
| 84 | return NULL; |
| 85 | } |
| 86 | |
| 87 | /* Find a BTS context based on BVCI+NSEI tuple */ |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 88 | 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] | 89 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 90 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 91 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 92 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 93 | if (bctx->nsei == nsei && bctx->bvci == bvci) |
| 94 | return bctx; |
| 95 | } |
| 96 | return NULL; |
| 97 | } |
| 98 | |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 99 | struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei) |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 100 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 101 | struct bssgp_bvc_ctx *ctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 102 | |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 103 | ctx = talloc_zero(bssgp_tall_ctx, struct bssgp_bvc_ctx); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 104 | if (!ctx) |
| 105 | return NULL; |
| 106 | ctx->bvci = bvci; |
| 107 | ctx->nsei = nsei; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 108 | /* FIXME: BVCI is not unique, only BVCI+NSEI ?!? */ |
| 109 | ctx->ctrg = rate_ctr_group_alloc(ctx, &bssgp_ctrg_desc, bvci); |
| 110 | |
Harald Welte | 5c90e5c | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 111 | llist_add(&ctx->list, &bssgp_bvc_ctxts); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 112 | |
| 113 | return ctx; |
| 114 | } |
| 115 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 116 | /* Chapter 10.4.5: Flow Control BVC ACK */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 117 | 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] | 118 | { |
| 119 | struct msgb *msg = bssgp_msgb_alloc(); |
| 120 | struct bssgp_normal_hdr *bgph = |
| 121 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 122 | |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 123 | msgb_nsei(msg) = nsei; |
| 124 | msgb_bvci(msg) = ns_bvci; |
| 125 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 126 | bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_BVC_ACK; |
| 127 | msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag); |
| 128 | |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 129 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 130 | } |
| 131 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 132 | 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] | 133 | { |
| 134 | /* 6 octets RAC */ |
| 135 | gsm48_parse_ra(raid, buf); |
| 136 | /* 2 octets CID */ |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 137 | return ntohs(*(uint16_t *) (buf+6)); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 138 | } |
| 139 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 140 | /* Chapter 8.4 BVC-Reset Procedure */ |
| 141 | static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, |
| 142 | uint16_t ns_bvci) |
| 143 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 144 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 145 | uint16_t nsei = msgb_nsei(msg); |
| 146 | uint16_t bvci; |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 147 | int rc; |
| 148 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 149 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 150 | DEBUGPC(DBSSGP, "BVCI=%u RESET cause=%s\n", bvci, |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 151 | bssgp_cause_str(*TLVP_VAL(tp, BSSGP_IE_CAUSE))); |
| 152 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 153 | /* look-up or create the BTS context for this BVC */ |
| 154 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 155 | if (!bctx) |
| 156 | bctx = btsctx_alloc(bvci, nsei); |
| 157 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 158 | /* As opposed to NS-VCs, BVCs are NOT blocked after RESET */ |
| 159 | bctx->state &= ~BVC_S_BLOCKED; |
| 160 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 161 | /* When we receive a BVC-RESET PDU (at least of a PTP BVCI), the BSS |
| 162 | * 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] | 163 | if (bvci != 0 && bvci != 1) { |
| 164 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID)) { |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 165 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP RESET BVCI=%u " |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 166 | "missing mandatory IE\n", bvci); |
| 167 | return -EINVAL; |
| 168 | } |
| 169 | /* actually extract RAC / CID */ |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 170 | bctx->cell_id = bssgp_parse_cell_id(&bctx->ra_id, |
| 171 | TLVP_VAL(tp, BSSGP_IE_CELL_ID)); |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 172 | 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] | 173 | bctx->ra_id.mcc, bctx->ra_id.mnc, bctx->ra_id.lac, |
| 174 | bctx->ra_id.rac, bctx->cell_id, bvci); |
| 175 | } |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 176 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 177 | /* Acknowledge the RESET to the BTS */ |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 178 | rc = bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 179 | nsei, bvci, ns_bvci); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 180 | return 0; |
| 181 | } |
| 182 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 183 | static int bssgp_rx_bvc_block(struct msgb *msg, struct tlv_parsed *tp) |
| 184 | { |
| 185 | uint16_t bvci; |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 186 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 187 | |
| 188 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 189 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 2b36ae1 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 190 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 191 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 192 | "received block for signalling BVC!?!\n", |
| 193 | msgb_nsei(msg), msgb_bvci(msg)); |
| 194 | return 0; |
| 195 | } |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 196 | |
| 197 | LOGP(DBSSGP, LOGL_INFO, "BVCI=%u BVC-BLOCK\n", bvci); |
| 198 | |
| 199 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 200 | if (!ptp_ctx) |
| 201 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 202 | |
| 203 | ptp_ctx->state |= BVC_S_BLOCKED; |
| 204 | rate_ctr_inc(&ptp_ctx->ctrg->ctr[BSSGP_CTR_BLOCKED]); |
| 205 | |
| 206 | /* FIXME: Send NM_BVC_BLOCK.ind to NM */ |
| 207 | |
| 208 | /* We always acknowledge the BLOCKing */ |
| 209 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, msgb_nsei(msg), |
| 210 | bvci, msgb_bvci(msg)); |
| 211 | }; |
| 212 | |
| 213 | static int bssgp_rx_bvc_unblock(struct msgb *msg, struct tlv_parsed *tp) |
| 214 | { |
| 215 | uint16_t bvci; |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 216 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 217 | |
| 218 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 219 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 2b36ae1 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 220 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 221 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 222 | "received unblock for signalling BVC!?!\n", |
| 223 | msgb_nsei(msg), msgb_bvci(msg)); |
| 224 | return 0; |
| 225 | } |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 226 | |
| 227 | DEBUGP(DBSSGP, "BVCI=%u BVC-UNBLOCK\n", bvci); |
| 228 | |
| 229 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 230 | if (!ptp_ctx) |
| 231 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 232 | |
| 233 | ptp_ctx->state &= ~BVC_S_BLOCKED; |
| 234 | |
| 235 | /* FIXME: Send NM_BVC_UNBLOCK.ind to NM */ |
| 236 | |
| 237 | /* We always acknowledge the unBLOCKing */ |
| 238 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, msgb_nsei(msg), |
| 239 | bvci, msgb_bvci(msg)); |
| 240 | }; |
| 241 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 242 | /* Uplink unit-data */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 243 | 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] | 244 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 245 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 246 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 247 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 248 | DEBUGP(DBSSGP, "BSSGP UL-UD\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 249 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 250 | /* extract TLLI and parse TLV IEs */ |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 251 | msgb_tlli(msg) = ntohl(budh->tlli); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 252 | |
| 253 | /* Cell ID and LLC_PDU are the only mandatory IE */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 254 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID) || |
| 255 | !TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU)) |
| 256 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 257 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 258 | /* store pointer to LLC header and CELL ID in msgb->cb */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 259 | msgb_llch(msg) = TLVP_VAL(tp, BSSGP_IE_LLC_PDU); |
| 260 | msgb_bcid(msg) = TLVP_VAL(tp, BSSGP_IE_CELL_ID); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 261 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 262 | return gprs_llc_rcvmsg(msg, tp); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 263 | } |
| 264 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 265 | static int bssgp_rx_suspend(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 266 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 267 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 268 | struct bssgp_normal_hdr *bgph = |
| 269 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 270 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 271 | DEBUGP(DBSSGP, "BSSGP SUSPEND\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 272 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 273 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 274 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) |
| 275 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 276 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 277 | /* FIXME: pass the SUSPEND request to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 278 | /* SEND SUSPEND_ACK or SUSPEND_NACK */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 279 | } |
| 280 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 281 | static int bssgp_rx_resume(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 282 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 283 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 284 | struct bssgp_normal_hdr *bgph = |
| 285 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 286 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 287 | DEBUGP(DBSSGP, "BSSGP RESUME\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 288 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 289 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 290 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA) || |
| 291 | !TLVP_PRESENT(tp, BSSGP_IE_SUSPEND_REF_NR)) |
| 292 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 293 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 294 | /* FIXME: pass the RESUME request to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 295 | /* SEND RESUME_ACK or RESUME_NACK */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 296 | } |
| 297 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 298 | 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] | 299 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 300 | { |
| 301 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 302 | DEBUGP(DBSSGP, "BSSGP FC BVC\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 303 | |
| 304 | if (!TLVP_PRESENT(tp, BSSGP_IE_TAG) || |
| 305 | !TLVP_PRESENT(tp, BSSGP_IE_BVC_BUCKET_SIZE) || |
| 306 | !TLVP_PRESENT(tp, BSSGP_IE_BUCKET_LEAK_RATE) || |
| 307 | !TLVP_PRESENT(tp, BSSGP_IE_BMAX_DEFAULT_MS) || |
| 308 | !TLVP_PRESENT(tp, BSSGP_IE_R_DEFAULT_MS)) |
| 309 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 310 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 311 | /* FIXME: actually implement flow control */ |
| 312 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 313 | /* Send FLOW_CONTROL_BVC_ACK */ |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 314 | 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] | 315 | msgb_bvci(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 316 | } |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 317 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 318 | /* Receive a BSSGP PDU from a BSS on a PTP BVCI */ |
| 319 | static int gprs_bssgp_rx_ptp(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 320 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 321 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 322 | struct bssgp_normal_hdr *bgph = |
| 323 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 324 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 325 | int rc = 0; |
| 326 | |
Harald Welte | 2b36ae1 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 327 | /* If traffic is received on a BVC that is marked as blocked, the |
| 328 | * received PDU shall not be accepted and a STATUS PDU (Cause value: |
| 329 | * BVC Blocked) shall be sent to the peer entity on the signalling BVC */ |
| 330 | if (bctx->state & BVC_S_BLOCKED && pdu_type != BSSGP_PDUT_STATUS) { |
| 331 | uint16_t bvci = msgb_bvci(msg); |
| 332 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &bvci, msg); |
| 333 | } |
| 334 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 335 | switch (pdu_type) { |
| 336 | case BSSGP_PDUT_UL_UNITDATA: |
| 337 | /* some LLC data from the MS */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 338 | rc = bssgp_rx_ul_ud(msg, tp, bctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 339 | break; |
| 340 | case BSSGP_PDUT_RA_CAPABILITY: |
| 341 | /* BSS requests RA capability or IMSI */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 342 | DEBUGP(DBSSGP, "BSSGP RA CAPABILITY UPDATE\n"); |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 343 | /* FIXME: send GMM_RA_CAPABILITY_UPDATE.ind to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 344 | /* FIXME: send RA_CAPA_UPDATE_ACK */ |
| 345 | break; |
| 346 | case BSSGP_PDUT_RADIO_STATUS: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 347 | DEBUGP(DBSSGP, "BSSGP RADIO STATUS\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 348 | /* BSS informs us of some exception */ |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 349 | /* FIXME: send GMM_RADIO_STATUS.ind to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 350 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 351 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 352 | /* BSS informs us of available bandwidth in Gb interface */ |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 353 | rc = bssgp_rx_fc_bvc(msg, tp, bctx); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 354 | break; |
| 355 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 356 | /* BSS informs us of available bandwidth to one MS */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 357 | DEBUGP(DBSSGP, "BSSGP FC MS\n"); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 358 | /* FIXME: actually implement flow control */ |
| 359 | /* FIXME: Send FLOW_CONTROL_MS_ACK */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 360 | break; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 361 | case BSSGP_PDUT_STATUS: |
| 362 | /* Some exception has occurred */ |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 363 | /* FIXME: send NM_STATUS.ind to NM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 364 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 365 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 366 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 367 | case BSSGP_PDUT_MODIFY_BSS_PFC: |
| 368 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 369 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x not [yet] implemented\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 370 | pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 371 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 372 | break; |
| 373 | /* those only exist in the SGSN -> BSS direction */ |
| 374 | case BSSGP_PDUT_DL_UNITDATA: |
| 375 | case BSSGP_PDUT_PAGING_PS: |
| 376 | case BSSGP_PDUT_PAGING_CS: |
| 377 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 378 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
| 379 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
| 380 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x only exists in DL\n", |
| 381 | pdu_type); |
| 382 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 383 | rc = -EINVAL; |
| 384 | break; |
| 385 | default: |
| 386 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x unknown\n", pdu_type); |
| 387 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 388 | break; |
| 389 | } |
| 390 | |
| 391 | |
| 392 | } |
| 393 | |
| 394 | /* Receive a BSSGP PDU from a BSS on a SIGNALLING BVCI */ |
| 395 | static int gprs_bssgp_rx_sign(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 396 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 397 | { |
| 398 | struct bssgp_normal_hdr *bgph = |
| 399 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 400 | uint8_t pdu_type = bgph->pdu_type; |
| 401 | int rc = 0; |
| 402 | uint16_t ns_bvci = msgb_bvci(msg); |
| 403 | uint16_t bvci; |
| 404 | |
| 405 | switch (bgph->pdu_type) { |
| 406 | case BSSGP_PDUT_SUSPEND: |
| 407 | /* MS wants to suspend */ |
| 408 | rc = bssgp_rx_suspend(msg, tp, bctx); |
| 409 | break; |
| 410 | case BSSGP_PDUT_RESUME: |
| 411 | /* MS wants to resume */ |
| 412 | rc = bssgp_rx_resume(msg, tp, bctx); |
| 413 | break; |
| 414 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 415 | /* BSS informs us it has performed LL FLUSH */ |
| 416 | DEBUGP(DBSSGP, "BSSGP FLUSH LL\n"); |
| 417 | /* FIXME: send NM_FLUSH_LL.res to NM */ |
| 418 | break; |
| 419 | case BSSGP_PDUT_LLC_DISCARD: |
| 420 | /* BSS informs that some LLC PDU's have been discarded */ |
| 421 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_DISCARDED]); |
| 422 | DEBUGP(DBSSGP, "BSSGP LLC DISCARDED\n"); |
| 423 | /* FIXME: send NM_LLC_DISCARDED to NM */ |
| 424 | break; |
| 425 | case BSSGP_PDUT_BVC_BLOCK: |
| 426 | /* BSS tells us that BVC shall be blocked */ |
| 427 | DEBUGP(DBSSGP, "BSSGP BVC BLOCK "); |
| 428 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
| 429 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) |
| 430 | goto err_mand_ie; |
| 431 | rc = bssgp_rx_bvc_unblock(msg, tp); |
| 432 | break; |
| 433 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 434 | /* BSS tells us that BVC shall be unblocked */ |
| 435 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI)) |
| 436 | goto err_mand_ie; |
| 437 | rc = bssgp_rx_bvc_unblock(msg, tp); |
| 438 | break; |
| 439 | case BSSGP_PDUT_BVC_RESET: |
| 440 | /* BSS tells us that BVC init is required */ |
| 441 | DEBUGP(DBSSGP, "BSSGP BVC RESET "); |
| 442 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
| 443 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) |
| 444 | goto err_mand_ie; |
| 445 | rc = bssgp_rx_bvc_reset(msg, tp, ns_bvci); |
| 446 | break; |
| 447 | case BSSGP_PDUT_STATUS: |
| 448 | /* Some exception has occurred */ |
| 449 | /* FIXME: send NM_STATUS.ind to NM */ |
| 450 | break; |
| 451 | /* those only exist in the SGSN -> BSS direction */ |
| 452 | case BSSGP_PDUT_PAGING_PS: |
| 453 | case BSSGP_PDUT_PAGING_CS: |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 454 | case BSSGP_PDUT_SUSPEND_ACK: |
| 455 | case BSSGP_PDUT_SUSPEND_NACK: |
| 456 | case BSSGP_PDUT_RESUME_ACK: |
| 457 | case BSSGP_PDUT_RESUME_NACK: |
Harald Welte | f47dc0b | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 458 | case BSSGP_PDUT_FLUSH_LL: |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 459 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 460 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 461 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 462 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x only exists in DL\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 463 | pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 464 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 465 | rc = -EINVAL; |
| 466 | break; |
| 467 | default: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 468 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x unknown\n", pdu_type); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 469 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 470 | break; |
| 471 | } |
| 472 | |
| 473 | return rc; |
| 474 | err_mand_ie: |
| 475 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 476 | } |
| 477 | |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 478 | /* We expect msgb_bssgph() to point to the BSSGP header */ |
| 479 | int gprs_bssgp_rcvmsg(struct msgb *msg) |
| 480 | { |
| 481 | struct bssgp_normal_hdr *bgph = |
| 482 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 483 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
| 484 | struct tlv_parsed tp; |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 485 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 486 | uint8_t pdu_type = bgph->pdu_type; |
| 487 | uint16_t ns_bvci = msgb_bvci(msg); |
| 488 | int data_len; |
| 489 | int rc = 0; |
| 490 | |
| 491 | /* Identifiers from DOWN: NSEI, BVCI (both in msg->cb) */ |
| 492 | |
| 493 | /* UNITDATA BSSGP headers have TLLI in front */ |
| 494 | if (pdu_type != BSSGP_PDUT_UL_UNITDATA && |
| 495 | pdu_type != BSSGP_PDUT_DL_UNITDATA) { |
| 496 | data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
| 497 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 498 | } else { |
| 499 | data_len = msgb_bssgp_len(msg) - sizeof(*budh); |
| 500 | rc = bssgp_tlv_parse(&tp, budh->data, data_len); |
| 501 | } |
| 502 | |
| 503 | /* look-up or create the BTS context for this BVC */ |
| 504 | bctx = btsctx_by_bvci_nsei(ns_bvci, msgb_nsei(msg)); |
| 505 | /* Only a RESET PDU can create a new BVC context */ |
| 506 | if (!bctx && pdu_type != BSSGP_PDUT_BVC_RESET) { |
| 507 | LOGP(DBSSGP, LOGL_NOTICE, "NSEI=%u/BVCI=%u Rejecting PDU " |
| 508 | "type %u for unknown BVCI\n", msgb_nsei(msg), ns_bvci, |
| 509 | pdu_type); |
| 510 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
| 511 | } |
| 512 | |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 513 | if (bctx) { |
Harald Welte | d9a55f6 | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 514 | log_set_context(BSC_CTX_BVC, bctx); |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 515 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_IN]); |
| 516 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_IN], |
| 517 | msgb_bssgp_len(msg)); |
| 518 | } |
| 519 | |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 520 | if (ns_bvci == BVCI_SIGNALLING) |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 521 | rc = gprs_bssgp_rx_sign(msg, &tp, bctx); |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 522 | else if (ns_bvci == BVCI_PTM) |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 523 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
| 524 | else |
| 525 | rc = gprs_bssgp_rx_ptp(msg, &tp, bctx); |
| 526 | |
| 527 | return rc; |
| 528 | } |
| 529 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 530 | /* Entry function from upper level (LLC), asking us to transmit a BSSGP PDU |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 531 | * to a remote MS (identified by TLLI) at a BTS identified by its BVCI and NSEI */ |
| 532 | int gprs_bssgp_tx_dl_ud(struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 533 | { |
Harald Welte | ada466f | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 534 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 535 | struct bssgp_ud_hdr *budh; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 536 | uint8_t llc_pdu_tlv_hdr_len = 2; |
| 537 | uint8_t *llc_pdu_tlv, *qos_profile; |
| 538 | uint16_t pdu_lifetime = 1000; /* centi-seconds */ |
| 539 | uint8_t qos_profile_default[3] = { 0x00, 0x00, 0x21 }; |
| 540 | uint16_t msg_len = msg->len; |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 541 | uint16_t bvci = msgb_bvci(msg); |
| 542 | uint16_t nsei = msgb_nsei(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 543 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 544 | /* Identifiers from UP: TLLI, BVCI, NSEI (all in msgb->cb) */ |
Harald Welte | b3911a0 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 545 | if (bvci <= BVCI_PTM ) { |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 546 | LOGP(DBSSGP, LOGL_ERROR, "Cannot send DL-UD to BVCI %u\n", |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 547 | bvci); |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | |
| 551 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 552 | if (!bctx) { |
| 553 | /* FIXME: don't simply create missing context, but reject message */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 554 | bctx = btsctx_alloc(bvci, nsei); |
Harald Welte | 3a1bece | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 555 | } |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 556 | |
| 557 | if (msg->len > TVLV_MAX_ONEBYTE) |
| 558 | llc_pdu_tlv_hdr_len += 1; |
| 559 | |
| 560 | /* prepend the tag and length of the LLC-PDU TLV */ |
| 561 | llc_pdu_tlv = msgb_push(msg, llc_pdu_tlv_hdr_len); |
| 562 | llc_pdu_tlv[0] = BSSGP_IE_LLC_PDU; |
| 563 | if (llc_pdu_tlv_hdr_len > 2) { |
| 564 | llc_pdu_tlv[1] = msg_len >> 8; |
| 565 | llc_pdu_tlv[2] = msg_len & 0xff; |
| 566 | } else { |
| 567 | llc_pdu_tlv[1] = msg_len & 0x3f; |
| 568 | llc_pdu_tlv[1] |= 0x80; |
| 569 | } |
| 570 | |
| 571 | /* FIXME: optional elements */ |
| 572 | |
| 573 | /* prepend the pdu lifetime */ |
| 574 | pdu_lifetime = htons(pdu_lifetime); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 575 | 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] | 576 | |
| 577 | /* prepend the QoS profile, TLLI and pdu type */ |
| 578 | budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); |
| 579 | memcpy(budh->qos_profile, qos_profile_default, sizeof(qos_profile_default)); |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 580 | budh->tlli = htonl(msgb_tlli(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 581 | budh->pdu_type = BSSGP_PDUT_DL_UNITDATA; |
| 582 | |
Harald Welte | b1b2908 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 583 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]); |
| 584 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_OUT], msg->len); |
| 585 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 586 | /* Identifiers down: BVCI, NSEI (in msgb->cb) */ |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 587 | |
| 588 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 589 | } |