Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | /* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */ |
| 2 | |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 75bb820 | 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 | 3a3f7cc | 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 | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <errno.h> |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 27 | #include <stdint.h> |
Harald Welte | 75bb820 | 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 | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 33 | #include <osmocore/talloc.h> |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 34 | #include <osmocore/rate_ctr.h> |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 35 | |
Harald Welte | 75bb820 | 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 | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 43 | void *bssgp_tall_ctx = NULL; |
| 44 | |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 45 | #define BVC_F_BLOCKED 0x0001 |
| 46 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 47 | enum bssgp_ctr { |
Harald Welte | 6606517 | 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 | 2cb4335 | 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 | 6606517 | 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 | 2cb4335 | 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 | bcc0369 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 72 | LLIST_HEAD(bssgp_bvc_ctxts); |
Harald Welte | f897265 | 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 | e8dc523 | 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 | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 76 | { |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 77 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 78 | |
Harald Welte | bcc0369 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 79 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | f897265 | 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 | e8dc523 | 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 | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 89 | { |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 90 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 91 | |
Harald Welte | bcc0369 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 92 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | f897265 | 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 | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 99 | struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei) |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 100 | { |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 101 | struct bssgp_bvc_ctx *ctx; |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 102 | |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 103 | ctx = talloc_zero(bssgp_tall_ctx, struct bssgp_bvc_ctx); |
Harald Welte | f897265 | 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 | 2cb4335 | 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 | bcc0369 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 111 | llist_add(&ctx->list, &bssgp_bvc_ctxts); |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 112 | |
| 113 | return ctx; |
| 114 | } |
| 115 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 116 | /* Chapter 10.4.5: Flow Control BVC ACK */ |
Harald Welte | d85d9a9 | 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 | 75bb820 | 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 | cd788ba | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 123 | msgb_nsei(msg) = nsei; |
| 124 | msgb_bvci(msg) = ns_bvci; |
| 125 | |
Harald Welte | 75bb820 | 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 | cd788ba | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 129 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 130 | } |
| 131 | |
Harald Welte | c8a98bc | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 132 | /* 10.3.7 SUSPEND-ACK PDU */ |
| 133 | int bssgp_tx_suspend_ack(uint16_t nsei, uint32_t tlli, |
| 134 | const struct gprs_ra_id *ra_id, uint8_t suspend_ref) |
| 135 | { |
| 136 | struct msgb *msg = bssgp_msgb_alloc(); |
| 137 | struct bssgp_normal_hdr *bgph = |
| 138 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 139 | uint32_t _tlli; |
| 140 | uint8_t ra[6]; |
| 141 | |
| 142 | msgb_nsei(msg) = nsei; |
| 143 | msgb_bvci(msg) = 0; /* Signalling */ |
| 144 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_ACK; |
| 145 | |
| 146 | _tlli = htonl(tlli); |
| 147 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 148 | gsm48_construct_ra(ra, ra_id); |
| 149 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 150 | msgb_tvlv_put(msg, BSSGP_IE_SUSPEND_REF_NR, 1, &suspend_ref); |
| 151 | |
| 152 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 153 | } |
| 154 | |
| 155 | /* 10.3.8 SUSPEND-NACK PDU */ |
| 156 | int bssgp_tx_suspend_nack(uint16_t nsei, uint32_t tlli, |
| 157 | uint8_t *cause) |
| 158 | { |
| 159 | struct msgb *msg = bssgp_msgb_alloc(); |
| 160 | struct bssgp_normal_hdr *bgph = |
| 161 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 162 | uint32_t _tlli; |
| 163 | |
| 164 | msgb_nsei(msg) = nsei; |
| 165 | msgb_bvci(msg) = 0; /* Signalling */ |
| 166 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 167 | |
| 168 | _tlli = htonl(tlli); |
| 169 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 170 | if (cause) |
| 171 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 172 | |
| 173 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 174 | } |
| 175 | |
| 176 | /* 10.3.10 RESUME-ACK PDU */ |
| 177 | int bssgp_tx_resume_ack(uint16_t nsei, uint32_t tlli, |
| 178 | const struct gprs_ra_id *ra_id) |
| 179 | { |
| 180 | struct msgb *msg = bssgp_msgb_alloc(); |
| 181 | struct bssgp_normal_hdr *bgph = |
| 182 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 183 | uint32_t _tlli; |
| 184 | uint8_t ra[6]; |
| 185 | |
| 186 | msgb_nsei(msg) = nsei; |
| 187 | msgb_bvci(msg) = 0; /* Signalling */ |
| 188 | bgph->pdu_type = BSSGP_PDUT_RESUME_ACK; |
| 189 | |
| 190 | _tlli = htonl(tlli); |
| 191 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 192 | gsm48_construct_ra(ra, ra_id); |
| 193 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 194 | |
| 195 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 196 | } |
| 197 | |
| 198 | /* 10.3.11 RESUME-NACK PDU */ |
| 199 | int bssgp_tx_resume_nack(uint16_t nsei, uint32_t tlli, |
| 200 | const struct gprs_ra_id *ra_id, uint8_t *cause) |
| 201 | { |
| 202 | struct msgb *msg = bssgp_msgb_alloc(); |
| 203 | struct bssgp_normal_hdr *bgph = |
| 204 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 205 | uint32_t _tlli; |
| 206 | uint8_t ra[6]; |
| 207 | |
| 208 | msgb_nsei(msg) = nsei; |
| 209 | msgb_bvci(msg) = 0; /* Signalling */ |
| 210 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 211 | |
| 212 | _tlli = htonl(tlli); |
| 213 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 214 | gsm48_construct_ra(ra, ra_id); |
| 215 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 216 | if (cause) |
| 217 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 218 | |
| 219 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 220 | } |
| 221 | |
Harald Welte | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 222 | uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf) |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 223 | { |
| 224 | /* 6 octets RAC */ |
| 225 | gsm48_parse_ra(raid, buf); |
| 226 | /* 2 octets CID */ |
Harald Welte | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 227 | return ntohs(*(uint16_t *) (buf+6)); |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 228 | } |
| 229 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 230 | /* Chapter 8.4 BVC-Reset Procedure */ |
| 231 | static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, |
| 232 | uint16_t ns_bvci) |
| 233 | { |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 234 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 235 | uint16_t nsei = msgb_nsei(msg); |
| 236 | uint16_t bvci; |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 237 | int rc; |
| 238 | |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 239 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 240 | DEBUGPC(DBSSGP, "BVCI=%u RESET cause=%s\n", bvci, |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 241 | bssgp_cause_str(*TLVP_VAL(tp, BSSGP_IE_CAUSE))); |
| 242 | |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 243 | /* look-up or create the BTS context for this BVC */ |
| 244 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 245 | if (!bctx) |
| 246 | bctx = btsctx_alloc(bvci, nsei); |
| 247 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 248 | /* As opposed to NS-VCs, BVCs are NOT blocked after RESET */ |
| 249 | bctx->state &= ~BVC_S_BLOCKED; |
| 250 | |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 251 | /* When we receive a BVC-RESET PDU (at least of a PTP BVCI), the BSS |
| 252 | * informs us about its RAC + Cell ID, so we can create a mapping */ |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 253 | if (bvci != 0 && bvci != 1) { |
| 254 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID)) { |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 255 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP RESET BVCI=%u " |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 256 | "missing mandatory IE\n", bvci); |
| 257 | return -EINVAL; |
| 258 | } |
| 259 | /* actually extract RAC / CID */ |
Harald Welte | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 260 | bctx->cell_id = bssgp_parse_cell_id(&bctx->ra_id, |
| 261 | TLVP_VAL(tp, BSSGP_IE_CELL_ID)); |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 262 | LOGP(DBSSGP, LOGL_NOTICE, "Cell %u-%u-%u-%u CI %u on BVCI %u\n", |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 263 | bctx->ra_id.mcc, bctx->ra_id.mnc, bctx->ra_id.lac, |
| 264 | bctx->ra_id.rac, bctx->cell_id, bvci); |
| 265 | } |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 266 | |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 267 | /* Acknowledge the RESET to the BTS */ |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 268 | rc = bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 269 | nsei, bvci, ns_bvci); |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 273 | static int bssgp_rx_bvc_block(struct msgb *msg, struct tlv_parsed *tp) |
| 274 | { |
| 275 | uint16_t bvci; |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 276 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 277 | |
| 278 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 9c97580 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 279 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 46e3153 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 280 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 281 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 282 | "received block for signalling BVC!?!\n", |
| 283 | msgb_nsei(msg), msgb_bvci(msg)); |
| 284 | return 0; |
| 285 | } |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 286 | |
| 287 | LOGP(DBSSGP, LOGL_INFO, "BVCI=%u BVC-BLOCK\n", bvci); |
| 288 | |
| 289 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 290 | if (!ptp_ctx) |
| 291 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 292 | |
| 293 | ptp_ctx->state |= BVC_S_BLOCKED; |
| 294 | rate_ctr_inc(&ptp_ctx->ctrg->ctr[BSSGP_CTR_BLOCKED]); |
| 295 | |
| 296 | /* FIXME: Send NM_BVC_BLOCK.ind to NM */ |
| 297 | |
| 298 | /* We always acknowledge the BLOCKing */ |
| 299 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, msgb_nsei(msg), |
| 300 | bvci, msgb_bvci(msg)); |
| 301 | }; |
| 302 | |
| 303 | static int bssgp_rx_bvc_unblock(struct msgb *msg, struct tlv_parsed *tp) |
| 304 | { |
| 305 | uint16_t bvci; |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 306 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 307 | |
| 308 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 9c97580 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 309 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 46e3153 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 310 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 311 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 312 | "received unblock for signalling BVC!?!\n", |
| 313 | msgb_nsei(msg), msgb_bvci(msg)); |
| 314 | return 0; |
| 315 | } |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 316 | |
| 317 | DEBUGP(DBSSGP, "BVCI=%u BVC-UNBLOCK\n", bvci); |
| 318 | |
| 319 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 320 | if (!ptp_ctx) |
| 321 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 322 | |
| 323 | ptp_ctx->state &= ~BVC_S_BLOCKED; |
| 324 | |
| 325 | /* FIXME: Send NM_BVC_UNBLOCK.ind to NM */ |
| 326 | |
| 327 | /* We always acknowledge the unBLOCKing */ |
| 328 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, msgb_nsei(msg), |
| 329 | bvci, msgb_bvci(msg)); |
| 330 | }; |
| 331 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 332 | /* Uplink unit-data */ |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 333 | static int bssgp_rx_ul_ud(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 334 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 335 | { |
Harald Welte | 7316440 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 336 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 337 | |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 338 | DEBUGP(DBSSGP, "BSSGP UL-UD\n"); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 339 | |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 340 | /* extract TLLI and parse TLV IEs */ |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 341 | msgb_tlli(msg) = ntohl(budh->tlli); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 342 | |
| 343 | /* Cell ID and LLC_PDU are the only mandatory IE */ |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 344 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID) || |
| 345 | !TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU)) |
| 346 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 347 | |
Harald Welte | 2351f1f | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 348 | /* store pointer to LLC header and CELL ID in msgb->cb */ |
Holger Hans Peter Freyther | 933d238 | 2010-05-23 21:11:19 +0800 | [diff] [blame] | 349 | msgb_llch(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_LLC_PDU); |
| 350 | msgb_bcid(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_CELL_ID); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 351 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 352 | return gprs_llc_rcvmsg(msg, tp); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 353 | } |
| 354 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 355 | static int bssgp_rx_suspend(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 356 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 357 | { |
Harald Welte | 7316440 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 358 | struct bssgp_normal_hdr *bgph = |
| 359 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | c8a98bc | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 360 | struct gprs_ra_id raid; |
| 361 | uint32_t tlli; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 362 | |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 363 | DEBUGP(DBSSGP, "BSSGP SUSPEND\n"); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 364 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 365 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 366 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) |
| 367 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 368 | |
Harald Welte | c8a98bc | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 369 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
| 370 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 371 | |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 372 | /* FIXME: pass the SUSPEND request to GMM */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 373 | /* SEND SUSPEND_ACK or SUSPEND_NACK */ |
Harald Welte | c8a98bc | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 374 | bssgp_tx_suspend_ack(msgb_nsei(msg), tlli, &raid, 0); |
| 375 | |
Holger Hans Peter Freyther | cade846 | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 376 | return 0; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 377 | } |
| 378 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 379 | static int bssgp_rx_resume(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 380 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 381 | { |
Harald Welte | 7316440 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 382 | struct bssgp_normal_hdr *bgph = |
| 383 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | c8a98bc | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 384 | struct gprs_ra_id raid; |
| 385 | uint32_t tlli; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 386 | |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 387 | DEBUGP(DBSSGP, "BSSGP RESUME\n"); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 388 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 389 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 390 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA) || |
| 391 | !TLVP_PRESENT(tp, BSSGP_IE_SUSPEND_REF_NR)) |
| 392 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 393 | |
Harald Welte | c8a98bc | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 394 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
| 395 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 396 | |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 397 | /* FIXME: pass the RESUME request to GMM */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 398 | /* SEND RESUME_ACK or RESUME_NACK */ |
Harald Welte | c8a98bc | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 399 | bssgp_tx_resume_ack(msgb_nsei(msg), tlli, &raid); |
Holger Hans Peter Freyther | cade846 | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 400 | return 0; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 401 | } |
| 402 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 403 | static int bssgp_rx_fc_bvc(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 404 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 405 | { |
| 406 | |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 407 | DEBUGP(DBSSGP, "BSSGP FC BVC\n"); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 408 | |
| 409 | if (!TLVP_PRESENT(tp, BSSGP_IE_TAG) || |
| 410 | !TLVP_PRESENT(tp, BSSGP_IE_BVC_BUCKET_SIZE) || |
| 411 | !TLVP_PRESENT(tp, BSSGP_IE_BUCKET_LEAK_RATE) || |
| 412 | !TLVP_PRESENT(tp, BSSGP_IE_BMAX_DEFAULT_MS) || |
| 413 | !TLVP_PRESENT(tp, BSSGP_IE_R_DEFAULT_MS)) |
| 414 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 415 | |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 416 | /* FIXME: actually implement flow control */ |
| 417 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 418 | /* Send FLOW_CONTROL_BVC_ACK */ |
Harald Welte | cd788ba | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 419 | return bssgp_tx_fc_bvc_ack(msgb_nsei(msg), *TLVP_VAL(tp, BSSGP_IE_TAG), |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 420 | msgb_bvci(msg)); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 421 | } |
Harald Welte | 55fe055 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 422 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 423 | /* Receive a BSSGP PDU from a BSS on a PTP BVCI */ |
| 424 | static int gprs_bssgp_rx_ptp(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 425 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 426 | { |
Harald Welte | 7316440 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 427 | struct bssgp_normal_hdr *bgph = |
| 428 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 429 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 430 | int rc = 0; |
| 431 | |
Harald Welte | 46e3153 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 432 | /* If traffic is received on a BVC that is marked as blocked, the |
| 433 | * received PDU shall not be accepted and a STATUS PDU (Cause value: |
| 434 | * BVC Blocked) shall be sent to the peer entity on the signalling BVC */ |
| 435 | if (bctx->state & BVC_S_BLOCKED && pdu_type != BSSGP_PDUT_STATUS) { |
| 436 | uint16_t bvci = msgb_bvci(msg); |
| 437 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &bvci, msg); |
| 438 | } |
| 439 | |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 440 | switch (pdu_type) { |
| 441 | case BSSGP_PDUT_UL_UNITDATA: |
| 442 | /* some LLC data from the MS */ |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 443 | rc = bssgp_rx_ul_ud(msg, tp, bctx); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 444 | break; |
| 445 | case BSSGP_PDUT_RA_CAPABILITY: |
| 446 | /* BSS requests RA capability or IMSI */ |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 447 | DEBUGP(DBSSGP, "BSSGP RA CAPABILITY UPDATE\n"); |
Harald Welte | e5a45c5 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 448 | /* FIXME: send GMM_RA_CAPABILITY_UPDATE.ind to GMM */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 449 | /* FIXME: send RA_CAPA_UPDATE_ACK */ |
| 450 | break; |
| 451 | case BSSGP_PDUT_RADIO_STATUS: |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 452 | DEBUGP(DBSSGP, "BSSGP RADIO STATUS\n"); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 453 | /* BSS informs us of some exception */ |
Harald Welte | e5a45c5 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 454 | /* FIXME: send GMM_RADIO_STATUS.ind to GMM */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 455 | break; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 456 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 457 | /* BSS informs us of available bandwidth in Gb interface */ |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 458 | rc = bssgp_rx_fc_bvc(msg, tp, bctx); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 459 | break; |
| 460 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 461 | /* BSS informs us of available bandwidth to one MS */ |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 462 | DEBUGP(DBSSGP, "BSSGP FC MS\n"); |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 463 | /* FIXME: actually implement flow control */ |
| 464 | /* FIXME: Send FLOW_CONTROL_MS_ACK */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 465 | break; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 466 | case BSSGP_PDUT_STATUS: |
| 467 | /* Some exception has occurred */ |
Harald Welte | e5a45c5 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 468 | /* FIXME: send NM_STATUS.ind to NM */ |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 469 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 470 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 471 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 472 | case BSSGP_PDUT_MODIFY_BSS_PFC: |
| 473 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 474 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x not [yet] implemented\n", |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 475 | pdu_type); |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 476 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 477 | break; |
| 478 | /* those only exist in the SGSN -> BSS direction */ |
| 479 | case BSSGP_PDUT_DL_UNITDATA: |
| 480 | case BSSGP_PDUT_PAGING_PS: |
| 481 | case BSSGP_PDUT_PAGING_CS: |
| 482 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 483 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
| 484 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
| 485 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x only exists in DL\n", |
| 486 | pdu_type); |
| 487 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 488 | rc = -EINVAL; |
| 489 | break; |
| 490 | default: |
| 491 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x unknown\n", pdu_type); |
| 492 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 493 | break; |
| 494 | } |
| 495 | |
Holger Hans Peter Freyther | cade846 | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 496 | return rc; |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | /* Receive a BSSGP PDU from a BSS on a SIGNALLING BVCI */ |
| 500 | static int gprs_bssgp_rx_sign(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 501 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 502 | { |
| 503 | struct bssgp_normal_hdr *bgph = |
| 504 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 505 | uint8_t pdu_type = bgph->pdu_type; |
| 506 | int rc = 0; |
| 507 | uint16_t ns_bvci = msgb_bvci(msg); |
| 508 | uint16_t bvci; |
| 509 | |
| 510 | switch (bgph->pdu_type) { |
| 511 | case BSSGP_PDUT_SUSPEND: |
| 512 | /* MS wants to suspend */ |
| 513 | rc = bssgp_rx_suspend(msg, tp, bctx); |
| 514 | break; |
| 515 | case BSSGP_PDUT_RESUME: |
| 516 | /* MS wants to resume */ |
| 517 | rc = bssgp_rx_resume(msg, tp, bctx); |
| 518 | break; |
| 519 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 520 | /* BSS informs us it has performed LL FLUSH */ |
| 521 | DEBUGP(DBSSGP, "BSSGP FLUSH LL\n"); |
| 522 | /* FIXME: send NM_FLUSH_LL.res to NM */ |
| 523 | break; |
| 524 | case BSSGP_PDUT_LLC_DISCARD: |
| 525 | /* BSS informs that some LLC PDU's have been discarded */ |
| 526 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_DISCARDED]); |
| 527 | DEBUGP(DBSSGP, "BSSGP LLC DISCARDED\n"); |
| 528 | /* FIXME: send NM_LLC_DISCARDED to NM */ |
| 529 | break; |
| 530 | case BSSGP_PDUT_BVC_BLOCK: |
| 531 | /* BSS tells us that BVC shall be blocked */ |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 532 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
| 533 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) |
| 534 | goto err_mand_ie; |
Harald Welte | 321f8f3 | 2010-05-31 17:16:36 +0200 | [diff] [blame] | 535 | rc = bssgp_rx_bvc_block(msg, tp); |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 536 | break; |
| 537 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 538 | /* BSS tells us that BVC shall be unblocked */ |
| 539 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI)) |
| 540 | goto err_mand_ie; |
| 541 | rc = bssgp_rx_bvc_unblock(msg, tp); |
| 542 | break; |
| 543 | case BSSGP_PDUT_BVC_RESET: |
| 544 | /* BSS tells us that BVC init is required */ |
| 545 | DEBUGP(DBSSGP, "BSSGP BVC RESET "); |
| 546 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
| 547 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) |
| 548 | goto err_mand_ie; |
| 549 | rc = bssgp_rx_bvc_reset(msg, tp, ns_bvci); |
| 550 | break; |
| 551 | case BSSGP_PDUT_STATUS: |
| 552 | /* Some exception has occurred */ |
| 553 | /* FIXME: send NM_STATUS.ind to NM */ |
| 554 | break; |
| 555 | /* those only exist in the SGSN -> BSS direction */ |
| 556 | case BSSGP_PDUT_PAGING_PS: |
| 557 | case BSSGP_PDUT_PAGING_CS: |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 558 | case BSSGP_PDUT_SUSPEND_ACK: |
| 559 | case BSSGP_PDUT_SUSPEND_NACK: |
| 560 | case BSSGP_PDUT_RESUME_ACK: |
| 561 | case BSSGP_PDUT_RESUME_NACK: |
Harald Welte | e5a45c5 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 562 | case BSSGP_PDUT_FLUSH_LL: |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 563 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 564 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 565 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 566 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x only exists in DL\n", |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 567 | pdu_type); |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 568 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 569 | rc = -EINVAL; |
| 570 | break; |
| 571 | default: |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 572 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x unknown\n", pdu_type); |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 573 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 574 | break; |
| 575 | } |
| 576 | |
| 577 | return rc; |
| 578 | err_mand_ie: |
| 579 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 580 | } |
| 581 | |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 582 | /* We expect msgb_bssgph() to point to the BSSGP header */ |
| 583 | int gprs_bssgp_rcvmsg(struct msgb *msg) |
| 584 | { |
| 585 | struct bssgp_normal_hdr *bgph = |
| 586 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 587 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
| 588 | struct tlv_parsed tp; |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 589 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 590 | uint8_t pdu_type = bgph->pdu_type; |
| 591 | uint16_t ns_bvci = msgb_bvci(msg); |
| 592 | int data_len; |
| 593 | int rc = 0; |
| 594 | |
| 595 | /* Identifiers from DOWN: NSEI, BVCI (both in msg->cb) */ |
| 596 | |
| 597 | /* UNITDATA BSSGP headers have TLLI in front */ |
| 598 | if (pdu_type != BSSGP_PDUT_UL_UNITDATA && |
| 599 | pdu_type != BSSGP_PDUT_DL_UNITDATA) { |
| 600 | data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
| 601 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 602 | } else { |
| 603 | data_len = msgb_bssgp_len(msg) - sizeof(*budh); |
| 604 | rc = bssgp_tlv_parse(&tp, budh->data, data_len); |
| 605 | } |
| 606 | |
| 607 | /* look-up or create the BTS context for this BVC */ |
| 608 | bctx = btsctx_by_bvci_nsei(ns_bvci, msgb_nsei(msg)); |
| 609 | /* Only a RESET PDU can create a new BVC context */ |
| 610 | if (!bctx && pdu_type != BSSGP_PDUT_BVC_RESET) { |
| 611 | LOGP(DBSSGP, LOGL_NOTICE, "NSEI=%u/BVCI=%u Rejecting PDU " |
| 612 | "type %u for unknown BVCI\n", msgb_nsei(msg), ns_bvci, |
| 613 | pdu_type); |
| 614 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
| 615 | } |
| 616 | |
Harald Welte | 6606517 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 617 | if (bctx) { |
Harald Welte | 3a3f7cc | 2010-05-17 23:41:43 +0200 | [diff] [blame] | 618 | log_set_context(BSC_CTX_BVC, bctx); |
Harald Welte | 6606517 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 619 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_IN]); |
| 620 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_IN], |
| 621 | msgb_bssgp_len(msg)); |
| 622 | } |
| 623 | |
Harald Welte | 9c97580 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 624 | if (ns_bvci == BVCI_SIGNALLING) |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 625 | rc = gprs_bssgp_rx_sign(msg, &tp, bctx); |
Harald Welte | 9c97580 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 626 | else if (ns_bvci == BVCI_PTM) |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 627 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
| 628 | else |
| 629 | rc = gprs_bssgp_rx_ptp(msg, &tp, bctx); |
| 630 | |
| 631 | return rc; |
| 632 | } |
| 633 | |
Harald Welte | f897265 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 634 | /* Entry function from upper level (LLC), asking us to transmit a BSSGP PDU |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 635 | * to a remote MS (identified by TLLI) at a BTS identified by its BVCI and NSEI */ |
| 636 | int gprs_bssgp_tx_dl_ud(struct msgb *msg) |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 637 | { |
Harald Welte | e8dc523 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 638 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 639 | struct bssgp_ud_hdr *budh; |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 640 | uint8_t llc_pdu_tlv_hdr_len = 2; |
| 641 | uint8_t *llc_pdu_tlv, *qos_profile; |
| 642 | uint16_t pdu_lifetime = 1000; /* centi-seconds */ |
| 643 | uint8_t qos_profile_default[3] = { 0x00, 0x00, 0x21 }; |
| 644 | uint16_t msg_len = msg->len; |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 645 | uint16_t bvci = msgb_bvci(msg); |
| 646 | uint16_t nsei = msgb_nsei(msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 647 | |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 648 | /* Identifiers from UP: TLLI, BVCI, NSEI (all in msgb->cb) */ |
Harald Welte | 9c97580 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 649 | if (bvci <= BVCI_PTM ) { |
Harald Welte | ae14132 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 650 | LOGP(DBSSGP, LOGL_ERROR, "Cannot send DL-UD to BVCI %u\n", |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 651 | bvci); |
| 652 | return -EINVAL; |
| 653 | } |
| 654 | |
| 655 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 656 | if (!bctx) { |
| 657 | /* FIXME: don't simply create missing context, but reject message */ |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 658 | bctx = btsctx_alloc(bvci, nsei); |
Harald Welte | 2cb4335 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 659 | } |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 660 | |
| 661 | if (msg->len > TVLV_MAX_ONEBYTE) |
| 662 | llc_pdu_tlv_hdr_len += 1; |
| 663 | |
| 664 | /* prepend the tag and length of the LLC-PDU TLV */ |
| 665 | llc_pdu_tlv = msgb_push(msg, llc_pdu_tlv_hdr_len); |
| 666 | llc_pdu_tlv[0] = BSSGP_IE_LLC_PDU; |
| 667 | if (llc_pdu_tlv_hdr_len > 2) { |
| 668 | llc_pdu_tlv[1] = msg_len >> 8; |
| 669 | llc_pdu_tlv[2] = msg_len & 0xff; |
| 670 | } else { |
| 671 | llc_pdu_tlv[1] = msg_len & 0x3f; |
| 672 | llc_pdu_tlv[1] |= 0x80; |
| 673 | } |
| 674 | |
| 675 | /* FIXME: optional elements */ |
| 676 | |
| 677 | /* prepend the pdu lifetime */ |
| 678 | pdu_lifetime = htons(pdu_lifetime); |
Harald Welte | d85d9a9 | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 679 | msgb_tvlv_push(msg, BSSGP_IE_PDU_LIFETIME, 2, (uint8_t *)&pdu_lifetime); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 680 | |
| 681 | /* prepend the QoS profile, TLLI and pdu type */ |
| 682 | budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); |
| 683 | memcpy(budh->qos_profile, qos_profile_default, sizeof(qos_profile_default)); |
Harald Welte | cf3c414 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 684 | budh->tlli = htonl(msgb_tlli(msg)); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 685 | budh->pdu_type = BSSGP_PDUT_DL_UNITDATA; |
| 686 | |
Harald Welte | 6606517 | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 687 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]); |
| 688 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_OUT], msg->len); |
| 689 | |
Harald Welte | a6e3270 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 690 | /* Identifiers down: BVCI, NSEI (in msgb->cb) */ |
Harald Welte | cd788ba | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 691 | |
| 692 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 75bb820 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 693 | } |