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