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