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