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