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