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 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 60 | static int _bssgp_tx_dl_ud(struct bssgp_flow_control *fc, struct msgb *msg, |
| 61 | uint32_t llc_pdu_len, void *priv); |
| 62 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 63 | /* Find a BTS Context based on parsed RA ID and Cell ID */ |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 64 | 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] | 65 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 66 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 67 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 68 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 69 | if (!memcmp(&bctx->ra_id, raid, sizeof(bctx->ra_id)) && |
| 70 | bctx->cell_id == cid) |
| 71 | return bctx; |
| 72 | } |
| 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | /* Find a BTS context based on BVCI+NSEI tuple */ |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 77 | 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] | 78 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 79 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 80 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 81 | llist_for_each_entry(bctx, &bssgp_bvc_ctxts, list) { |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 82 | if (bctx->nsei == nsei && bctx->bvci == bvci) |
| 83 | return bctx; |
| 84 | } |
| 85 | return NULL; |
| 86 | } |
| 87 | |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 88 | struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei) |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 89 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 90 | struct bssgp_bvc_ctx *ctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 91 | |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 92 | ctx = talloc_zero(bssgp_tall_ctx, struct bssgp_bvc_ctx); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 93 | if (!ctx) |
| 94 | return NULL; |
| 95 | ctx->bvci = bvci; |
| 96 | ctx->nsei = nsei; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 97 | /* FIXME: BVCI is not unique, only BVCI+NSEI ?!? */ |
| 98 | ctx->ctrg = rate_ctr_group_alloc(ctx, &bssgp_ctrg_desc, bvci); |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 99 | ctx->fc = talloc_zero(ctx, struct bssgp_flow_control); |
| 100 | /* cofigure for 2Mbit, 30 packets in queue */ |
| 101 | bssgp_fc_init(ctx->fc, 100000, 2*1024*1024/8, 30, &_bssgp_tx_dl_ud); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 102 | |
Harald Welte | a78b9c2 | 2010-05-17 23:02:42 +0200 | [diff] [blame] | 103 | llist_add(&ctx->list, &bssgp_bvc_ctxts); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 104 | |
| 105 | return ctx; |
| 106 | } |
| 107 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 108 | /* Chapter 10.4.5: Flow Control BVC ACK */ |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 109 | 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] | 110 | { |
| 111 | struct msgb *msg = bssgp_msgb_alloc(); |
| 112 | struct bssgp_normal_hdr *bgph = |
| 113 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 114 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 115 | msgb_nsei(msg) = nsei; |
| 116 | msgb_bvci(msg) = ns_bvci; |
| 117 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 118 | bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_BVC_ACK; |
| 119 | msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag); |
| 120 | |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 121 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 122 | } |
| 123 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 124 | /* 10.3.7 SUSPEND-ACK PDU */ |
| 125 | int bssgp_tx_suspend_ack(uint16_t nsei, uint32_t tlli, |
| 126 | const struct gprs_ra_id *ra_id, uint8_t suspend_ref) |
| 127 | { |
| 128 | struct msgb *msg = bssgp_msgb_alloc(); |
| 129 | struct bssgp_normal_hdr *bgph = |
| 130 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 131 | uint32_t _tlli; |
| 132 | uint8_t ra[6]; |
| 133 | |
| 134 | msgb_nsei(msg) = nsei; |
| 135 | msgb_bvci(msg) = 0; /* Signalling */ |
| 136 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_ACK; |
| 137 | |
| 138 | _tlli = htonl(tlli); |
| 139 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 140 | gsm48_construct_ra(ra, ra_id); |
| 141 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 142 | msgb_tvlv_put(msg, BSSGP_IE_SUSPEND_REF_NR, 1, &suspend_ref); |
| 143 | |
| 144 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 145 | } |
| 146 | |
| 147 | /* 10.3.8 SUSPEND-NACK PDU */ |
| 148 | int bssgp_tx_suspend_nack(uint16_t nsei, uint32_t tlli, |
Dieter Spaar | d2b13fc | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 149 | const struct gprs_ra_id *ra_id, |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 150 | uint8_t *cause) |
| 151 | { |
| 152 | struct msgb *msg = bssgp_msgb_alloc(); |
| 153 | struct bssgp_normal_hdr *bgph = |
| 154 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 155 | uint32_t _tlli; |
Dieter Spaar | d2b13fc | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 156 | uint8_t ra[6]; |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 157 | |
| 158 | msgb_nsei(msg) = nsei; |
| 159 | msgb_bvci(msg) = 0; /* Signalling */ |
| 160 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 161 | |
| 162 | _tlli = htonl(tlli); |
| 163 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
Dieter Spaar | d2b13fc | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 164 | gsm48_construct_ra(ra, ra_id); |
| 165 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 166 | if (cause) |
| 167 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 168 | |
| 169 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 170 | } |
| 171 | |
| 172 | /* 10.3.10 RESUME-ACK PDU */ |
| 173 | int bssgp_tx_resume_ack(uint16_t nsei, uint32_t tlli, |
| 174 | const struct gprs_ra_id *ra_id) |
| 175 | { |
| 176 | struct msgb *msg = bssgp_msgb_alloc(); |
| 177 | struct bssgp_normal_hdr *bgph = |
| 178 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 179 | uint32_t _tlli; |
| 180 | uint8_t ra[6]; |
| 181 | |
| 182 | msgb_nsei(msg) = nsei; |
| 183 | msgb_bvci(msg) = 0; /* Signalling */ |
| 184 | bgph->pdu_type = BSSGP_PDUT_RESUME_ACK; |
| 185 | |
| 186 | _tlli = htonl(tlli); |
| 187 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 188 | gsm48_construct_ra(ra, ra_id); |
| 189 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 190 | |
| 191 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 192 | } |
| 193 | |
| 194 | /* 10.3.11 RESUME-NACK PDU */ |
| 195 | int bssgp_tx_resume_nack(uint16_t nsei, uint32_t tlli, |
| 196 | const struct gprs_ra_id *ra_id, uint8_t *cause) |
| 197 | { |
| 198 | struct msgb *msg = bssgp_msgb_alloc(); |
| 199 | struct bssgp_normal_hdr *bgph = |
| 200 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 201 | uint32_t _tlli; |
| 202 | uint8_t ra[6]; |
| 203 | |
| 204 | msgb_nsei(msg) = nsei; |
| 205 | msgb_bvci(msg) = 0; /* Signalling */ |
| 206 | bgph->pdu_type = BSSGP_PDUT_SUSPEND_NACK; |
| 207 | |
| 208 | _tlli = htonl(tlli); |
| 209 | msgb_tvlv_put(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &_tlli); |
| 210 | gsm48_construct_ra(ra, ra_id); |
| 211 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 212 | if (cause) |
| 213 | msgb_tvlv_put(msg, BSSGP_IE_CAUSE, 1, cause); |
| 214 | |
| 215 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 216 | } |
| 217 | |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 218 | 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] | 219 | { |
| 220 | /* 6 octets RAC */ |
| 221 | gsm48_parse_ra(raid, buf); |
| 222 | /* 2 octets CID */ |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 223 | return ntohs(*(uint16_t *) (buf+6)); |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Harald Welte | 2861007 | 2011-11-24 21:32:07 +0100 | [diff] [blame] | 226 | int bssgp_create_cell_id(uint8_t *buf, const struct gprs_ra_id *raid, |
| 227 | uint16_t cid) |
| 228 | { |
| 229 | uint16_t *out_cid = (uint16_t *) (buf + 6); |
| 230 | /* 6 octets RAC */ |
| 231 | gsm48_construct_ra(buf, raid); |
| 232 | /* 2 octets CID */ |
| 233 | *out_cid = htons(cid); |
| 234 | |
| 235 | return 8; |
| 236 | } |
| 237 | |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 238 | /* Chapter 8.4 BVC-Reset Procedure */ |
| 239 | static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, |
| 240 | uint16_t ns_bvci) |
| 241 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 242 | struct osmo_bssgp_prim nmp; |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 243 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 244 | uint16_t nsei = msgb_nsei(msg); |
| 245 | uint16_t bvci; |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 246 | |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 247 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 248 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx RESET cause=%s\n", bvci, |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 249 | bssgp_cause_str(*TLVP_VAL(tp, BSSGP_IE_CAUSE))); |
| 250 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 251 | /* look-up or create the BTS context for this BVC */ |
| 252 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 253 | if (!bctx) |
| 254 | bctx = btsctx_alloc(bvci, nsei); |
| 255 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 256 | /* As opposed to NS-VCs, BVCs are NOT blocked after RESET */ |
| 257 | bctx->state &= ~BVC_S_BLOCKED; |
| 258 | |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 259 | /* When we receive a BVC-RESET PDU (at least of a PTP BVCI), the BSS |
| 260 | * 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] | 261 | if (bvci != 0 && bvci != 1) { |
| 262 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID)) { |
Harald Welte | 086fe32 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 263 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx RESET " |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 264 | "missing mandatory IE\n", bvci); |
| 265 | return -EINVAL; |
| 266 | } |
| 267 | /* actually extract RAC / CID */ |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 268 | bctx->cell_id = bssgp_parse_cell_id(&bctx->ra_id, |
| 269 | TLVP_VAL(tp, BSSGP_IE_CELL_ID)); |
Harald Welte | b8a6a83 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 270 | 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] | 271 | bctx->ra_id.mcc, bctx->ra_id.mnc, bctx->ra_id.lac, |
| 272 | bctx->ra_id.rac, bctx->cell_id, bvci); |
| 273 | } |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 274 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 275 | /* Send NM_BVC_RESET.ind to NM */ |
| 276 | memset(&nmp, 0, sizeof(nmp)); |
| 277 | nmp.nsei = nsei; |
| 278 | nmp.bvci = bvci; |
| 279 | nmp.tp = tp; |
| 280 | nmp.ra_id = &bctx->ra_id; |
| 281 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_RESET, |
| 282 | PRIM_OP_INDICATION, msg); |
| 283 | bssgp_prim_cb(&nmp.oph, NULL); |
| 284 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 285 | /* Acknowledge the RESET to the BTS */ |
Harald Welte | 5b3bffb | 2012-09-07 12:03:40 +0200 | [diff] [blame] | 286 | bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
| 287 | nsei, bvci, ns_bvci); |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 288 | return 0; |
| 289 | } |
| 290 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 291 | static int bssgp_rx_bvc_block(struct msgb *msg, struct tlv_parsed *tp) |
| 292 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 293 | struct osmo_bssgp_prim nmp; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 294 | uint16_t bvci; |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 295 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 296 | |
| 297 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 298 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 299 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 300 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 301 | "received block for signalling BVC!?!\n", |
| 302 | msgb_nsei(msg), msgb_bvci(msg)); |
| 303 | return 0; |
| 304 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 305 | |
Harald Welte | 086fe32 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 306 | LOGP(DBSSGP, LOGL_INFO, "BSSGP Rx BVCI=%u BVC-BLOCK\n", bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 307 | |
| 308 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 309 | if (!ptp_ctx) |
| 310 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 311 | |
| 312 | ptp_ctx->state |= BVC_S_BLOCKED; |
| 313 | rate_ctr_inc(&ptp_ctx->ctrg->ctr[BSSGP_CTR_BLOCKED]); |
| 314 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 315 | /* Send NM_BVC_BLOCK.ind to NM */ |
| 316 | memset(&nmp, 0, sizeof(nmp)); |
| 317 | nmp.nsei = msgb_nsei(msg); |
| 318 | nmp.bvci = bvci; |
| 319 | nmp.tp = tp; |
| 320 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_BLOCK, |
| 321 | PRIM_OP_INDICATION, msg); |
| 322 | bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 323 | |
| 324 | /* We always acknowledge the BLOCKing */ |
| 325 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, msgb_nsei(msg), |
| 326 | bvci, msgb_bvci(msg)); |
| 327 | }; |
| 328 | |
| 329 | static int bssgp_rx_bvc_unblock(struct msgb *msg, struct tlv_parsed *tp) |
| 330 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 331 | struct osmo_bssgp_prim nmp; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 332 | uint16_t bvci; |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 333 | struct bssgp_bvc_ctx *ptp_ctx; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 334 | |
| 335 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 336 | if (bvci == BVCI_SIGNALLING) { |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 337 | /* 8.3.2: Signalling BVC shall never be blocked */ |
| 338 | LOGP(DBSSGP, LOGL_ERROR, "NSEI=%u/BVCI=%u " |
| 339 | "received unblock for signalling BVC!?!\n", |
| 340 | msgb_nsei(msg), msgb_bvci(msg)); |
| 341 | return 0; |
| 342 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 343 | |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 344 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx BVC-UNBLOCK\n", bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 345 | |
| 346 | ptp_ctx = btsctx_by_bvci_nsei(bvci, msgb_nsei(msg)); |
| 347 | if (!ptp_ctx) |
| 348 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, &bvci, msg); |
| 349 | |
| 350 | ptp_ctx->state &= ~BVC_S_BLOCKED; |
| 351 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 352 | /* Send NM_BVC_UNBLOCK.ind to NM */ |
| 353 | memset(&nmp, 0, sizeof(nmp)); |
| 354 | nmp.nsei = msgb_nsei(msg); |
| 355 | nmp.bvci = bvci; |
| 356 | nmp.tp = tp; |
| 357 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_BVC_UNBLOCK, |
| 358 | PRIM_OP_INDICATION, msg); |
| 359 | bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 360 | |
| 361 | /* We always acknowledge the unBLOCKing */ |
| 362 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, msgb_nsei(msg), |
| 363 | bvci, msgb_bvci(msg)); |
| 364 | }; |
| 365 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 366 | /* Uplink unit-data */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 367 | 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] | 368 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 369 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 370 | struct osmo_bssgp_prim gbp; |
Harald Welte | ec19c10 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 371 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 372 | |
Harald Welte | 6752fa4 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 373 | /* extract TLLI and parse TLV IEs */ |
Harald Welte | 510c392 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 374 | msgb_tlli(msg) = ntohl(budh->tlli); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 375 | |
Harald Welte | 086fe32 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 376 | 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] | 377 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 378 | /* Cell ID and LLC_PDU are the only mandatory IE */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 379 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID) || |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 380 | !TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU)) { |
| 381 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP TLLI=0x%08x Rx UL-UD " |
| 382 | "missing mandatory IE\n", msgb_tlli(msg)); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 383 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 384 | } |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 385 | |
Harald Welte | a2ca4ed | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 386 | /* 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] | 387 | msgb_llch(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_LLC_PDU); |
| 388 | msgb_bcid(msg) = (uint8_t *) TLVP_VAL(tp, BSSGP_IE_CELL_ID); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 389 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 390 | /* Send BSSGP_UL_UD.ind to NM */ |
| 391 | memset(&gbp, 0, sizeof(gbp)); |
| 392 | gbp.nsei = ctx->nsei; |
| 393 | gbp.bvci = ctx->bvci; |
| 394 | gbp.tlli = msgb_tlli(msg); |
| 395 | gbp.tp = tp; |
| 396 | osmo_prim_init(&gbp.oph, SAP_BSSGP_LL, PRIM_BSSGP_UL_UD, |
| 397 | PRIM_OP_INDICATION, msg); |
| 398 | return bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 399 | } |
| 400 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 401 | static int bssgp_rx_suspend(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 402 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 403 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 404 | struct osmo_bssgp_prim gbp; |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 405 | struct gprs_ra_id raid; |
| 406 | uint32_t tlli; |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 407 | int rc; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 408 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 409 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 410 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) { |
| 411 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx SUSPEND " |
| 412 | "missing mandatory IE\n", ctx->bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 413 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 414 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 415 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 416 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 417 | |
Harald Welte | 1792532 | 2010-05-31 20:18:35 +0200 | [diff] [blame] | 418 | DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=0x%08x Rx SUSPEND\n", |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 419 | ctx->bvci, tlli); |
| 420 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 421 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 422 | |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 423 | /* Inform GMM about the SUSPEND request */ |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 424 | memset(&gbp, 0, sizeof(gbp)); |
| 425 | gbp.nsei = msgb_nsei(msg); |
| 426 | gbp.bvci = ctx->bvci; |
| 427 | gbp.tlli = tlli; |
| 428 | gbp.ra_id = &raid; |
| 429 | osmo_prim_init(&gbp.oph, SAP_BSSGP_GMM, PRIM_BSSGP_GMM_SUSPEND, |
| 430 | PRIM_OP_REQUEST, msg); |
| 431 | |
| 432 | rc = bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 433 | if (rc < 0) |
Dieter Spaar | d2b13fc | 2010-12-12 12:45:08 +0100 | [diff] [blame] | 434 | return bssgp_tx_suspend_nack(msgb_nsei(msg), tlli, &raid, NULL); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 435 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 436 | bssgp_tx_suspend_ack(msgb_nsei(msg), tlli, &raid, 0); |
| 437 | |
Holger Hans Peter Freyther | d30cefa | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 438 | return 0; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 439 | } |
| 440 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 441 | static int bssgp_rx_resume(struct msgb *msg, struct tlv_parsed *tp, |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 442 | struct bssgp_bvc_ctx *ctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 443 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 444 | struct osmo_bssgp_prim gbp; |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 445 | struct gprs_ra_id raid; |
| 446 | uint32_t tlli; |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 447 | uint8_t suspend_ref; |
| 448 | int rc; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 449 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 450 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 451 | !TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA) || |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 452 | !TLVP_PRESENT(tp, BSSGP_IE_SUSPEND_REF_NR)) { |
| 453 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx RESUME " |
| 454 | "missing mandatory IE\n", ctx->bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 455 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 456 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 457 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 458 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 459 | suspend_ref = *TLVP_VAL(tp, BSSGP_IE_SUSPEND_REF_NR); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 460 | |
Harald Welte | 086fe32 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 461 | 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] | 462 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 463 | gsm48_parse_ra(&raid, TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
| 464 | |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 465 | /* Inform GMM about the RESUME request */ |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 466 | memset(&gbp, 0, sizeof(gbp)); |
| 467 | gbp.nsei = msgb_nsei(msg); |
| 468 | gbp.bvci = ctx->bvci; |
| 469 | gbp.tlli = tlli; |
| 470 | gbp.ra_id = &raid; |
| 471 | gbp.u.resume.suspend_ref = suspend_ref; |
| 472 | osmo_prim_init(&gbp.oph, SAP_BSSGP_GMM, PRIM_BSSGP_GMM_RESUME, |
| 473 | PRIM_OP_REQUEST, msg); |
| 474 | |
| 475 | rc = bssgp_prim_cb(&gbp.oph, NULL); |
Harald Welte | 313cccf | 2010-06-09 11:22:47 +0200 | [diff] [blame] | 476 | if (rc < 0) |
| 477 | return bssgp_tx_resume_nack(msgb_nsei(msg), tlli, &raid, |
| 478 | NULL); |
| 479 | |
Harald Welte | a8aa4df | 2010-05-30 22:00:53 +0200 | [diff] [blame] | 480 | bssgp_tx_resume_ack(msgb_nsei(msg), tlli, &raid); |
Holger Hans Peter Freyther | d30cefa | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 481 | return 0; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 482 | } |
| 483 | |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 484 | |
| 485 | static int bssgp_rx_llc_disc(struct msgb *msg, struct tlv_parsed *tp, |
| 486 | struct bssgp_bvc_ctx *ctx) |
| 487 | { |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 488 | struct osmo_bssgp_prim nmp; |
Harald Welte | b736314 | 2010-07-23 21:59:29 +0200 | [diff] [blame] | 489 | uint32_t tlli = 0; |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 490 | |
| 491 | if (!TLVP_PRESENT(tp, BSSGP_IE_TLLI) || |
| 492 | !TLVP_PRESENT(tp, BSSGP_IE_LLC_FRAMES_DISCARDED) || |
| 493 | !TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
| 494 | !TLVP_PRESENT(tp, BSSGP_IE_NUM_OCT_AFF)) { |
| 495 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx LLC DISCARDED " |
| 496 | "missing mandatory IE\n", ctx->bvci); |
| 497 | } |
| 498 | |
Harald Welte | b736314 | 2010-07-23 21:59:29 +0200 | [diff] [blame] | 499 | if (TLVP_PRESENT(tp, BSSGP_IE_TLLI)) |
| 500 | tlli = ntohl(*(uint32_t *)TLVP_VAL(tp, BSSGP_IE_TLLI)); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 501 | |
Harald Welte | 086fe32 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 502 | DEBUGP(DBSSGP, "BSSGP BVCI=%u TLLI=%08x Rx LLC DISCARDED\n", |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 503 | ctx->bvci, tlli); |
| 504 | |
| 505 | rate_ctr_inc(&ctx->ctrg->ctr[BSSGP_CTR_DISCARDED]); |
| 506 | |
Harald Welte | 15a3643 | 2012-06-17 12:16:31 +0800 | [diff] [blame] | 507 | /* send NM_LLC_DISCARDED to NM */ |
| 508 | memset(&nmp, 0, sizeof(nmp)); |
| 509 | nmp.nsei = msgb_nsei(msg); |
| 510 | nmp.bvci = ctx->bvci; |
| 511 | nmp.tlli = tlli; |
| 512 | nmp.tp = tp; |
| 513 | osmo_prim_init(&nmp.oph, SAP_BSSGP_NM, PRIM_NM_LLC_DISCARDED, |
| 514 | PRIM_OP_INDICATION, msg); |
| 515 | |
| 516 | return bssgp_prim_cb(&nmp.oph, NULL); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 517 | } |
| 518 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 519 | /* One element (msgb) in a BSSGP Flow Control queue */ |
| 520 | struct bssgp_fc_queue_element { |
| 521 | /* linked list of queue elements */ |
| 522 | struct llist_head list; |
| 523 | /* The message that we have enqueued */ |
| 524 | struct msgb *msg; |
| 525 | /* Length of the LLC PDU part of the contained message */ |
| 526 | uint32_t llc_pdu_len; |
| 527 | /* private pointer passed to the flow control out_cb function */ |
| 528 | void *priv; |
| 529 | }; |
| 530 | |
| 531 | static int fc_queue_timer_cfg(struct bssgp_flow_control *fc); |
| 532 | static int bssgp_fc_needs_queueing(struct bssgp_flow_control *fc, uint32_t pdu_len); |
| 533 | |
| 534 | static void fc_timer_cb(void *data) |
| 535 | { |
| 536 | struct bssgp_flow_control *fc = data; |
| 537 | struct bssgp_fc_queue_element *fcqe; |
| 538 | struct timeval time_now; |
| 539 | |
| 540 | /* if the queue is empty, we return without sending something |
| 541 | * and without re-starting the timer */ |
| 542 | if (llist_empty(&fc->queue)) |
| 543 | return; |
| 544 | |
| 545 | /* get the first entry from the queue */ |
| 546 | fcqe = llist_entry(fc->queue.next, struct bssgp_fc_queue_element, |
| 547 | list); |
| 548 | |
| 549 | if (bssgp_fc_needs_queueing(fc, fcqe->llc_pdu_len)) { |
| 550 | LOGP(DBSSGP, LOGL_NOTICE, "BSSGP-FC: fc_timer_cb() but still " |
| 551 | "not able to send PDU of %u bytes\n", fcqe->llc_pdu_len); |
| 552 | /* make sure we re-start the timer */ |
| 553 | fc_queue_timer_cfg(fc); |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | /* remove from the queue */ |
| 558 | llist_del(&fcqe->list); |
| 559 | |
| 560 | fc->queue_depth--; |
| 561 | |
| 562 | /* record the time we transmitted this PDU */ |
| 563 | gettimeofday(&time_now, NULL); |
| 564 | fc->time_last_pdu = time_now; |
| 565 | |
| 566 | /* call the output callback for this FC instance */ |
| 567 | fc->out_cb(fcqe->priv, fcqe->msg, fcqe->llc_pdu_len, NULL); |
| 568 | |
| 569 | /* we expect that out_cb will in the end free the msgb once |
| 570 | * it is no longer needed */ |
| 571 | |
| 572 | /* but we have to free the queue element ourselves */ |
| 573 | talloc_free(fcqe); |
| 574 | |
| 575 | /* re-configure the timer for the next PDU */ |
| 576 | fc_queue_timer_cfg(fc); |
| 577 | } |
| 578 | |
| 579 | /* configure/schedule the flow control timer to expire once the bucket |
| 580 | * will have leaked a sufficient number of bytes to transmit the next |
| 581 | * PDU in the queue */ |
| 582 | static int fc_queue_timer_cfg(struct bssgp_flow_control *fc) |
| 583 | { |
| 584 | struct bssgp_fc_queue_element *fcqe; |
| 585 | uint32_t msecs; |
| 586 | |
| 587 | if (llist_empty(&fc->queue)) |
| 588 | return 0; |
| 589 | |
| 590 | fcqe = llist_entry(&fc->queue.next, struct bssgp_fc_queue_element, |
| 591 | list); |
| 592 | |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 593 | if (fc->bucket_leak_rate != 0) { |
| 594 | /* Calculate the point in time at which we will have leaked |
| 595 | * a sufficient number of bytes from the bucket to transmit |
| 596 | * the first PDU in the queue */ |
| 597 | msecs = (fcqe->llc_pdu_len * 1000) / fc->bucket_leak_rate; |
| 598 | /* FIXME: add that time to fc->time_last_pdu and subtract it from |
| 599 | * current time */ |
| 600 | fc->timer.data = fc; |
| 601 | fc->timer.cb = &fc_timer_cb; |
| 602 | osmo_timer_schedule(&fc->timer, msecs / 1000, (msecs % 1000) * 1000); |
| 603 | } else { |
| 604 | /* If the PCU is telling us to not send any more data at all, |
| 605 | * there's no point starting a timer. */ |
| 606 | } |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 607 | |
| 608 | return 0; |
| 609 | } |
| 610 | |
| 611 | /* Enqueue a PDU in the flow control queue for delayed transmission */ |
| 612 | static int fc_enqueue(struct bssgp_flow_control *fc, struct msgb *msg, |
| 613 | uint32_t llc_pdu_len, void *priv) |
| 614 | { |
| 615 | struct bssgp_fc_queue_element *fcqe; |
| 616 | |
| 617 | if (fc->queue_depth >= fc->max_queue_depth) |
| 618 | return -ENOSPC; |
| 619 | |
| 620 | fcqe = talloc_zero(fc, struct bssgp_fc_queue_element); |
| 621 | if (!fcqe) |
| 622 | return -ENOMEM; |
| 623 | fcqe->msg = msg; |
| 624 | fcqe->llc_pdu_len = llc_pdu_len; |
| 625 | fcqe->priv = priv; |
| 626 | |
| 627 | llist_add_tail(&fcqe->list, &fc->queue); |
| 628 | |
| 629 | fc->queue_depth++; |
| 630 | |
| 631 | /* re-configure the timer for dequeueing the pdu */ |
| 632 | fc_queue_timer_cfg(fc); |
| 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | /* According to Section 8.2 */ |
| 638 | static int bssgp_fc_needs_queueing(struct bssgp_flow_control *fc, uint32_t pdu_len) |
| 639 | { |
| 640 | struct timeval time_now, time_diff; |
| 641 | int64_t bucket_predicted; |
| 642 | uint32_t csecs_elapsed, leaked; |
| 643 | |
| 644 | /* B' = B + L(p) - (Tc - Tp)*R */ |
| 645 | |
| 646 | /* compute number of centi-seconds that have elapsed since transmitting |
| 647 | * the last PDU (Tc - Tp) */ |
| 648 | gettimeofday(&time_now, NULL); |
| 649 | timersub(&time_now, &fc->time_last_pdu, &time_diff); |
| 650 | csecs_elapsed = time_diff.tv_sec*100 + time_diff.tv_usec/10000; |
| 651 | |
| 652 | /* compute number of bytes that have leaked in the elapsed number |
| 653 | * of centi-seconds */ |
| 654 | leaked = csecs_elapsed * (fc->bucket_leak_rate / 100); |
| 655 | /* add the current PDU length to the last bucket level */ |
| 656 | bucket_predicted = fc->bucket_counter + pdu_len; |
| 657 | /* ... and subtract the number of leaked bytes */ |
| 658 | bucket_predicted -= leaked; |
| 659 | |
| 660 | if (bucket_predicted < pdu_len) { |
| 661 | /* this is just to make sure the bucket doesn't underflow */ |
| 662 | bucket_predicted = pdu_len; |
| 663 | goto pass; |
| 664 | } |
| 665 | |
| 666 | if (bucket_predicted <= fc->bucket_size_max) { |
| 667 | /* the bucket is not full yet, we can pass the packet */ |
| 668 | fc->bucket_counter = bucket_predicted; |
| 669 | goto pass; |
| 670 | } |
| 671 | |
| 672 | /* bucket is full, PDU needs to be delayed */ |
| 673 | return 1; |
| 674 | |
| 675 | pass: |
| 676 | /* if we reach here, the PDU can pass */ |
| 677 | return 0; |
| 678 | } |
| 679 | |
| 680 | /* output callback for BVC flow control */ |
| 681 | static int _bssgp_tx_dl_ud(struct bssgp_flow_control *fc, struct msgb *msg, |
| 682 | uint32_t llc_pdu_len, void *priv) |
| 683 | { |
| 684 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 685 | } |
| 686 | |
| 687 | /* input function of the flow control implementation, called first |
| 688 | * for the MM flow control, and then as the MM flow control output |
| 689 | * callback in order to perform BVC flow control */ |
| 690 | int bssgp_fc_in(struct bssgp_flow_control *fc, struct msgb *msg, |
| 691 | uint32_t llc_pdu_len, void *priv) |
| 692 | { |
| 693 | struct timeval time_now; |
| 694 | |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 695 | if (llc_pdu_len > fc->bucket_size_max) { |
| 696 | LOGP(DBSSGP, LOGL_NOTICE, "Single PDU (size=%u) is larger " |
| 697 | "than maximum bucket size (%u)!\n", llc_pdu_len, |
| 698 | fc->bucket_size_max); |
| 699 | return -EIO; |
| 700 | } |
| 701 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 702 | if (bssgp_fc_needs_queueing(fc, llc_pdu_len)) { |
| 703 | return fc_enqueue(fc, msg, llc_pdu_len, priv); |
| 704 | } else { |
| 705 | /* record the time we transmitted this PDU */ |
| 706 | gettimeofday(&time_now, NULL); |
| 707 | fc->time_last_pdu = time_now; |
| 708 | return fc->out_cb(priv, msg, llc_pdu_len, NULL); |
| 709 | } |
| 710 | } |
| 711 | |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 712 | |
| 713 | /* Initialize the Flow Control structure */ |
| 714 | void bssgp_fc_init(struct bssgp_flow_control *fc, |
| 715 | uint32_t bucket_size_max, uint32_t bucket_leak_rate, |
| 716 | uint32_t max_queue_depth, |
| 717 | int (*out_cb)(struct bssgp_flow_control *fc, struct msgb *msg, |
| 718 | uint32_t llc_pdu_len, void *priv)) |
| 719 | { |
| 720 | fc->out_cb = out_cb; |
| 721 | fc->bucket_size_max = bucket_size_max; |
| 722 | fc->bucket_leak_rate = bucket_leak_rate; |
| 723 | fc->max_queue_depth = max_queue_depth; |
| 724 | INIT_LLIST_HEAD(&fc->queue); |
| 725 | gettimeofday(&fc->time_last_pdu, NULL); |
| 726 | } |
| 727 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 728 | /* Initialize the Flow Control parameters for a new MS according to |
| 729 | * default values for the BVC specified by BVCI and NSEI */ |
| 730 | int bssgp_fc_ms_init(struct bssgp_flow_control *fc_ms, uint16_t bvci, |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 731 | uint16_t nsei, uint32_t max_queue_depth) |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 732 | { |
| 733 | struct bssgp_bvc_ctx *ctx; |
| 734 | |
| 735 | ctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 736 | if (!ctx) |
| 737 | return -ENODEV; |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 738 | |
| 739 | /* output call-back of per-MS FC is per-CTX FC */ |
| 740 | bssgp_fc_init(fc_ms, ctx->bmax_default_ms, ctx->r_default_ms, |
| 741 | max_queue_depth, bssgp_fc_in); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 742 | |
| 743 | return 0; |
| 744 | } |
| 745 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 746 | 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] | 747 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 748 | { |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 749 | uint32_t old_leak_rate = bctx->fc->bucket_leak_rate; |
| 750 | uint32_t old_r_def_ms = bctx->r_default_ms; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 751 | |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 752 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx Flow Control BVC\n", |
| 753 | bctx->bvci); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 754 | |
| 755 | if (!TLVP_PRESENT(tp, BSSGP_IE_TAG) || |
| 756 | !TLVP_PRESENT(tp, BSSGP_IE_BVC_BUCKET_SIZE) || |
| 757 | !TLVP_PRESENT(tp, BSSGP_IE_BUCKET_LEAK_RATE) || |
| 758 | !TLVP_PRESENT(tp, BSSGP_IE_BMAX_DEFAULT_MS) || |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 759 | !TLVP_PRESENT(tp, BSSGP_IE_R_DEFAULT_MS)) { |
| 760 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP BVCI=%u Rx FC BVC " |
| 761 | "missing mandatory IE\n", bctx->bvci); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 762 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 763 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 764 | |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 765 | /* 11.3.5 Bucket Size in 100 octets unit */ |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 766 | bctx->fc->bucket_size_max = 100 * |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 767 | ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVC_BUCKET_SIZE)); |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 768 | /* 11.3.4 Bucket Leak Rate in 100 bits/sec unit */ |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 769 | bctx->fc->bucket_leak_rate = 100 * |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 770 | ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BUCKET_LEAK_RATE)) / 8; |
| 771 | /* 11.3.2 in octets */ |
| 772 | bctx->bmax_default_ms = |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 773 | ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BMAX_DEFAULT_MS)); |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 774 | /* 11.3.32 Bucket Leak rate in 100bits/sec unit */ |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 775 | bctx->r_default_ms = 100 * |
Harald Welte | bb82622 | 2012-09-07 10:22:01 +0200 | [diff] [blame] | 776 | ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_R_DEFAULT_MS)) / 8; |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 777 | |
Harald Welte | 27b2bb7 | 2013-06-22 09:44:00 +0200 | [diff] [blame] | 778 | if (old_leak_rate != 0 && bctx->fc->bucket_leak_rate == 0) |
| 779 | LOGP(DBSSGP, LOGL_NOTICE, "BSS instructs us to bucket leak " |
| 780 | "rate of 0, stopping all DL GPRS!\n"); |
| 781 | else if (old_leak_rate == 0 && bctx->fc->bucket_leak_rate != 0) |
| 782 | LOGP(DBSSGP, LOGL_NOTICE, "BSS instructs us to bucket leak " |
| 783 | "rate of != 0, restarting all DL GPRS!\n"); |
| 784 | |
| 785 | if (old_r_def_ms != 0 && bctx->r_default_ms == 0) |
| 786 | LOGP(DBSSGP, LOGL_NOTICE, "BSS instructs us to MS default " |
| 787 | "bucket leak rate of 0, stopping DL GPRS!\n"); |
| 788 | else if (old_r_def_ms == 0 && bctx->r_default_ms != 0) |
| 789 | LOGP(DBSSGP, LOGL_NOTICE, "BSS instructs us to MS default " |
| 790 | "bucket leak rate != 0, restarting DL GPRS!\n"); |
| 791 | |
| 792 | /* reconfigure the timer for flow control based on new values */ |
| 793 | fc_queue_timer_cfg(bctx->fc); |
| 794 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 795 | /* Send FLOW_CONTROL_BVC_ACK */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 796 | 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] | 797 | msgb_bvci(msg)); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 798 | } |
Harald Welte | 3fddf3c | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 799 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 800 | /* Receive a BSSGP PDU from a BSS on a PTP BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 801 | static int bssgp_rx_ptp(struct msgb *msg, struct tlv_parsed *tp, |
| 802 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 803 | { |
Harald Welte | ec19c10 | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 804 | struct bssgp_normal_hdr *bgph = |
| 805 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 806 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 807 | int rc = 0; |
| 808 | |
Harald Welte | 58e65c9 | 2010-05-13 21:45:23 +0200 | [diff] [blame] | 809 | /* If traffic is received on a BVC that is marked as blocked, the |
| 810 | * received PDU shall not be accepted and a STATUS PDU (Cause value: |
| 811 | * BVC Blocked) shall be sent to the peer entity on the signalling BVC */ |
| 812 | if (bctx->state & BVC_S_BLOCKED && pdu_type != BSSGP_PDUT_STATUS) { |
| 813 | uint16_t bvci = msgb_bvci(msg); |
| 814 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, &bvci, msg); |
| 815 | } |
| 816 | |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 817 | switch (pdu_type) { |
| 818 | case BSSGP_PDUT_UL_UNITDATA: |
| 819 | /* some LLC data from the MS */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 820 | rc = bssgp_rx_ul_ud(msg, tp, bctx); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 821 | break; |
| 822 | case BSSGP_PDUT_RA_CAPABILITY: |
| 823 | /* BSS requests RA capability or IMSI */ |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 824 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx RA CAPABILITY UPDATE\n", |
| 825 | bctx->bvci); |
Harald Welte | 6b7cf25 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 826 | /* FIXME: send GMM_RA_CAPABILITY_UPDATE.ind to GMM */ |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 827 | /* FIXME: send RA_CAPA_UPDATE_ACK */ |
| 828 | break; |
| 829 | case BSSGP_PDUT_RADIO_STATUS: |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 830 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx RADIO STATUS\n", bctx->bvci); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 831 | /* BSS informs us of some exception */ |
Harald Welte | 6b7cf25 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 832 | /* FIXME: send GMM_RADIO_STATUS.ind to GMM */ |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 833 | break; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 834 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 835 | /* BSS informs us of available bandwidth in Gb interface */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 836 | rc = bssgp_rx_fc_bvc(msg, tp, bctx); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 837 | break; |
| 838 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 839 | /* BSS informs us of available bandwidth to one MS */ |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 840 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx Flow Control MS\n", |
| 841 | bctx->bvci); |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 842 | /* FIXME: actually implement flow control */ |
| 843 | /* FIXME: Send FLOW_CONTROL_MS_ACK */ |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 844 | break; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 845 | case BSSGP_PDUT_STATUS: |
| 846 | /* Some exception has occurred */ |
Harald Welte | 6b7cf25 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 847 | /* FIXME: send NM_STATUS.ind to NM */ |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 848 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 849 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 850 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 851 | case BSSGP_PDUT_MODIFY_BSS_PFC: |
| 852 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 853 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx PDU type 0x%02x not [yet] " |
| 854 | "implemented\n", bctx->bvci, pdu_type); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 855 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 856 | break; |
| 857 | /* those only exist in the SGSN -> BSS direction */ |
| 858 | case BSSGP_PDUT_DL_UNITDATA: |
| 859 | case BSSGP_PDUT_PAGING_PS: |
| 860 | case BSSGP_PDUT_PAGING_CS: |
| 861 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 862 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
| 863 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 864 | DEBUGP(DBSSGP, "BSSGP BVCI=%u PDU type 0x%02x only exists " |
| 865 | "in DL\n", bctx->bvci, pdu_type); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 866 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 867 | rc = -EINVAL; |
| 868 | break; |
| 869 | default: |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 870 | DEBUGP(DBSSGP, "BSSGP BVCI=%u PDU type 0x%02x unknown\n", |
| 871 | bctx->bvci, pdu_type); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 872 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
| 873 | break; |
| 874 | } |
| 875 | |
Holger Hans Peter Freyther | d30cefa | 2010-05-23 21:12:15 +0800 | [diff] [blame] | 876 | return rc; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | /* Receive a BSSGP PDU from a BSS on a SIGNALLING BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 880 | static int bssgp_rx_sign(struct msgb *msg, struct tlv_parsed *tp, |
| 881 | struct bssgp_bvc_ctx *bctx) |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 882 | { |
| 883 | struct bssgp_normal_hdr *bgph = |
| 884 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 885 | uint8_t pdu_type = bgph->pdu_type; |
| 886 | int rc = 0; |
| 887 | uint16_t ns_bvci = msgb_bvci(msg); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 888 | |
| 889 | switch (bgph->pdu_type) { |
| 890 | case BSSGP_PDUT_SUSPEND: |
| 891 | /* MS wants to suspend */ |
| 892 | rc = bssgp_rx_suspend(msg, tp, bctx); |
| 893 | break; |
| 894 | case BSSGP_PDUT_RESUME: |
| 895 | /* MS wants to resume */ |
| 896 | rc = bssgp_rx_resume(msg, tp, bctx); |
| 897 | break; |
| 898 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 899 | /* BSS informs us it has performed LL FLUSH */ |
Harald Welte | 086fe32 | 2011-08-19 16:45:19 +0200 | [diff] [blame] | 900 | DEBUGP(DBSSGP, "BSSGP Rx BVCI=%u FLUSH LL ACK\n", bctx->bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 901 | /* FIXME: send NM_FLUSH_LL.res to NM */ |
| 902 | break; |
| 903 | case BSSGP_PDUT_LLC_DISCARD: |
| 904 | /* BSS informs that some LLC PDU's have been discarded */ |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 905 | rc = bssgp_rx_llc_disc(msg, tp, bctx); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 906 | break; |
| 907 | case BSSGP_PDUT_BVC_BLOCK: |
| 908 | /* BSS tells us that BVC shall be blocked */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 909 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 910 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) { |
| 911 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Rx BVC-BLOCK " |
| 912 | "missing mandatory IE\n"); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 913 | goto err_mand_ie; |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 914 | } |
Harald Welte | 2677ea5 | 2010-05-31 17:16:36 +0200 | [diff] [blame] | 915 | rc = bssgp_rx_bvc_block(msg, tp); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 916 | break; |
| 917 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 918 | /* BSS tells us that BVC shall be unblocked */ |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 919 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI)) { |
| 920 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Rx BVC-UNBLOCK " |
| 921 | "missing mandatory IE\n"); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 922 | goto err_mand_ie; |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 923 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 924 | rc = bssgp_rx_bvc_unblock(msg, tp); |
| 925 | break; |
| 926 | case BSSGP_PDUT_BVC_RESET: |
| 927 | /* BSS tells us that BVC init is required */ |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 928 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI) || |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 929 | !TLVP_PRESENT(tp, BSSGP_IE_CAUSE)) { |
| 930 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP Rx BVC-RESET " |
| 931 | "missing mandatory IE\n"); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 932 | goto err_mand_ie; |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 933 | } |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 934 | rc = bssgp_rx_bvc_reset(msg, tp, ns_bvci); |
| 935 | break; |
| 936 | case BSSGP_PDUT_STATUS: |
| 937 | /* Some exception has occurred */ |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 938 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx BVC STATUS\n", bctx->bvci); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 939 | /* FIXME: send NM_STATUS.ind to NM */ |
| 940 | break; |
| 941 | /* those only exist in the SGSN -> BSS direction */ |
| 942 | case BSSGP_PDUT_PAGING_PS: |
| 943 | case BSSGP_PDUT_PAGING_CS: |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 944 | case BSSGP_PDUT_SUSPEND_ACK: |
| 945 | case BSSGP_PDUT_SUSPEND_NACK: |
| 946 | case BSSGP_PDUT_RESUME_ACK: |
| 947 | case BSSGP_PDUT_RESUME_NACK: |
Harald Welte | 6b7cf25 | 2010-05-13 19:41:31 +0200 | [diff] [blame] | 948 | case BSSGP_PDUT_FLUSH_LL: |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 949 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 950 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 951 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 952 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx PDU type 0x%02x only exists " |
| 953 | "in DL\n", bctx->bvci, pdu_type); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 954 | bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 955 | rc = -EINVAL; |
| 956 | break; |
| 957 | default: |
Harald Welte | e9686b6 | 2010-05-31 18:07:17 +0200 | [diff] [blame] | 958 | DEBUGP(DBSSGP, "BSSGP BVCI=%u Rx PDU type 0x%02x unknown\n", |
| 959 | bctx->bvci, pdu_type); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 960 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 961 | break; |
| 962 | } |
| 963 | |
| 964 | return rc; |
| 965 | err_mand_ie: |
| 966 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 967 | } |
| 968 | |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 969 | /* We expect msgb_bssgph() to point to the BSSGP header */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 970 | int bssgp_rcvmsg(struct msgb *msg) |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 971 | { |
| 972 | struct bssgp_normal_hdr *bgph = |
| 973 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
| 974 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
| 975 | struct tlv_parsed tp; |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 976 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 977 | uint8_t pdu_type = bgph->pdu_type; |
| 978 | uint16_t ns_bvci = msgb_bvci(msg); |
| 979 | int data_len; |
| 980 | int rc = 0; |
| 981 | |
| 982 | /* Identifiers from DOWN: NSEI, BVCI (both in msg->cb) */ |
| 983 | |
| 984 | /* UNITDATA BSSGP headers have TLLI in front */ |
| 985 | if (pdu_type != BSSGP_PDUT_UL_UNITDATA && |
| 986 | pdu_type != BSSGP_PDUT_DL_UNITDATA) { |
| 987 | data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
| 988 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 989 | } else { |
| 990 | data_len = msgb_bssgp_len(msg) - sizeof(*budh); |
| 991 | rc = bssgp_tlv_parse(&tp, budh->data, data_len); |
| 992 | } |
| 993 | |
| 994 | /* look-up or create the BTS context for this BVC */ |
| 995 | bctx = btsctx_by_bvci_nsei(ns_bvci, msgb_nsei(msg)); |
| 996 | /* Only a RESET PDU can create a new BVC context */ |
| 997 | if (!bctx && pdu_type != BSSGP_PDUT_BVC_RESET) { |
| 998 | LOGP(DBSSGP, LOGL_NOTICE, "NSEI=%u/BVCI=%u Rejecting PDU " |
| 999 | "type %u for unknown BVCI\n", msgb_nsei(msg), ns_bvci, |
| 1000 | pdu_type); |
| 1001 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
| 1002 | } |
| 1003 | |
Harald Welte | 16c8dbb | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 1004 | if (bctx) { |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 1005 | log_set_context(GPRS_CTX_BVC, bctx); |
Harald Welte | 16c8dbb | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 1006 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_IN]); |
| 1007 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_IN], |
| 1008 | msgb_bssgp_len(msg)); |
| 1009 | } |
| 1010 | |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 1011 | if (ns_bvci == BVCI_SIGNALLING) |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1012 | rc = bssgp_rx_sign(msg, &tp, bctx); |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 1013 | else if (ns_bvci == BVCI_PTM) |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1014 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
| 1015 | else |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1016 | rc = bssgp_rx_ptp(msg, &tp, bctx); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1017 | |
| 1018 | return rc; |
| 1019 | } |
| 1020 | |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1021 | int bssgp_tx_dl_ud(struct msgb *msg, uint16_t pdu_lifetime, |
| 1022 | struct bssgp_dl_ud_par *dup) |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1023 | { |
Harald Welte | 8a52113 | 2010-05-17 22:59:29 +0200 | [diff] [blame] | 1024 | struct bssgp_bvc_ctx *bctx; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1025 | struct bssgp_ud_hdr *budh; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 1026 | uint8_t llc_pdu_tlv_hdr_len = 2; |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1027 | uint8_t *llc_pdu_tlv; |
Harald Welte | 8f9a3ee | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 1028 | uint16_t msg_len = msg->len; |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1029 | uint16_t bvci = msgb_bvci(msg); |
| 1030 | uint16_t nsei = msgb_nsei(msg); |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1031 | uint16_t _pdu_lifetime = htons(pdu_lifetime); /* centi-seconds */ |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1032 | uint16_t drx_params; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1033 | |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1034 | /* Identifiers from UP: TLLI, BVCI, NSEI (all in msgb->cb) */ |
Harald Welte | 61c0784 | 2010-05-18 11:57:08 +0200 | [diff] [blame] | 1035 | if (bvci <= BVCI_PTM ) { |
Harald Welte | b8a6a83 | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 1036 | LOGP(DBSSGP, LOGL_ERROR, "Cannot send DL-UD to BVCI %u\n", |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1037 | bvci); |
| 1038 | return -EINVAL; |
| 1039 | } |
| 1040 | |
| 1041 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1042 | if (!bctx) { |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 1043 | LOGP(DBSSGP, LOGL_ERROR, "Cannot send DL-UD to unknown BVCI %u\n", |
| 1044 | bvci); |
| 1045 | return -ENODEV; |
Harald Welte | 25de811 | 2010-05-13 21:26:28 +0200 | [diff] [blame] | 1046 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1047 | |
| 1048 | if (msg->len > TVLV_MAX_ONEBYTE) |
| 1049 | llc_pdu_tlv_hdr_len += 1; |
| 1050 | |
| 1051 | /* prepend the tag and length of the LLC-PDU TLV */ |
| 1052 | llc_pdu_tlv = msgb_push(msg, llc_pdu_tlv_hdr_len); |
| 1053 | llc_pdu_tlv[0] = BSSGP_IE_LLC_PDU; |
| 1054 | if (llc_pdu_tlv_hdr_len > 2) { |
| 1055 | llc_pdu_tlv[1] = msg_len >> 8; |
| 1056 | llc_pdu_tlv[2] = msg_len & 0xff; |
| 1057 | } else { |
Sylvain Munaut | b00d1ad | 2010-06-09 21:13:13 +0200 | [diff] [blame] | 1058 | llc_pdu_tlv[1] = msg_len & 0x7f; |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1059 | llc_pdu_tlv[1] |= 0x80; |
| 1060 | } |
| 1061 | |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1062 | /* FIXME: optional elements: Alignment, UTRAN CCO, LSA, PFI */ |
| 1063 | |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1064 | if (dup) { |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1065 | /* Old TLLI to help BSS map from old->new */ |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1066 | if (dup->tlli) { |
| 1067 | uint32_t tlli = htonl(*dup->tlli); |
| 1068 | msgb_tvlv_push(msg, BSSGP_IE_TLLI, 4, (uint8_t *) &tlli); |
| 1069 | } |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1070 | |
| 1071 | /* IMSI */ |
Harald Welte | 2d956a8 | 2012-07-04 21:55:23 +0200 | [diff] [blame] | 1072 | if (dup->imsi && strlen(dup->imsi)) { |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1073 | uint8_t mi[10]; |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1074 | int imsi_len = gsm48_generate_mid_from_imsi(mi, dup->imsi); |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1075 | if (imsi_len > 2) |
| 1076 | msgb_tvlv_push(msg, BSSGP_IE_IMSI, |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1077 | imsi_len-2, mi+2); |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1078 | } |
| 1079 | |
| 1080 | /* DRX parameters */ |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1081 | drx_params = htons(dup->drx_parms); |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1082 | msgb_tvlv_push(msg, BSSGP_IE_DRX_PARAMS, 2, |
| 1083 | (uint8_t *) &drx_params); |
| 1084 | |
| 1085 | /* FIXME: Priority */ |
| 1086 | |
| 1087 | /* MS Radio Access Capability */ |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1088 | if (dup->ms_ra_cap.len) |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1089 | msgb_tvlv_push(msg, BSSGP_IE_MS_RADIO_ACCESS_CAP, |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1090 | dup->ms_ra_cap.len, dup->ms_ra_cap.v); |
| 1091 | |
Harald Welte | 2f94683 | 2010-05-31 22:12:30 +0200 | [diff] [blame] | 1092 | } |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1093 | |
| 1094 | /* prepend the pdu lifetime */ |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1095 | 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] | 1096 | |
| 1097 | /* prepend the QoS profile, TLLI and pdu type */ |
| 1098 | budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); |
Harald Welte | 8ef54d1 | 2012-06-17 09:31:16 +0800 | [diff] [blame] | 1099 | memcpy(budh->qos_profile, dup->qos_profile, sizeof(budh->qos_profile)); |
Harald Welte | 510c392 | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 1100 | budh->tlli = htonl(msgb_tlli(msg)); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1101 | budh->pdu_type = BSSGP_PDUT_DL_UNITDATA; |
| 1102 | |
Harald Welte | 16c8dbb | 2010-05-17 23:30:01 +0200 | [diff] [blame] | 1103 | rate_ctr_inc(&bctx->ctrg->ctr[BSSGP_CTR_PKTS_OUT]); |
| 1104 | rate_ctr_add(&bctx->ctrg->ctr[BSSGP_CTR_BYTES_OUT], msg->len); |
| 1105 | |
Harald Welte | 30bc19a | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 1106 | /* Identifiers down: BVCI, NSEI (in msgb->cb) */ |
Harald Welte | 24a655f | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 1107 | |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 1108 | /* check if we have to go through per-ms flow control or can go |
| 1109 | * directly to the per-BSS flow control */ |
| 1110 | if (dup->fc) |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 1111 | return bssgp_fc_in(dup->fc, msg, msg_len, bctx->fc); |
Harald Welte | d11c059 | 2012-09-06 21:57:11 +0200 | [diff] [blame] | 1112 | else |
Harald Welte | d8b4769 | 2012-09-07 11:29:32 +0200 | [diff] [blame] | 1113 | return bssgp_fc_in(bctx->fc, msg, msg_len, NULL); |
Harald Welte | 9ba5005 | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1114 | } |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1115 | |
| 1116 | /* Send a single GMM-PAGING.req to a given NSEI/NS-BVCI */ |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1117 | int bssgp_tx_paging(uint16_t nsei, uint16_t ns_bvci, |
| 1118 | struct bssgp_paging_info *pinfo) |
Harald Welte | 68b4f03 | 2010-06-09 16:22:28 +0200 | [diff] [blame] | 1119 | { |
| 1120 | struct msgb *msg = bssgp_msgb_alloc(); |
| 1121 | struct bssgp_normal_hdr *bgph = |
| 1122 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 1123 | uint16_t drx_params = htons(pinfo->drx_params); |
| 1124 | uint8_t mi[10]; |
| 1125 | int imsi_len = gsm48_generate_mid_from_imsi(mi, pinfo->imsi); |
| 1126 | uint8_t ra[6]; |
| 1127 | |
| 1128 | if (imsi_len < 2) |
| 1129 | return -EINVAL; |
| 1130 | |
| 1131 | msgb_nsei(msg) = nsei; |
| 1132 | msgb_bvci(msg) = ns_bvci; |
| 1133 | |
| 1134 | if (pinfo->mode == BSSGP_PAGING_PS) |
| 1135 | bgph->pdu_type = BSSGP_PDUT_PAGING_PS; |
| 1136 | else |
| 1137 | bgph->pdu_type = BSSGP_PDUT_PAGING_CS; |
| 1138 | /* IMSI */ |
| 1139 | msgb_tvlv_put(msg, BSSGP_IE_IMSI, imsi_len-2, mi+2); |
| 1140 | /* DRX Parameters */ |
| 1141 | msgb_tvlv_put(msg, BSSGP_IE_DRX_PARAMS, 2, |
| 1142 | (uint8_t *) &drx_params); |
| 1143 | /* Scope */ |
| 1144 | switch (pinfo->scope) { |
| 1145 | case BSSGP_PAGING_BSS_AREA: |
| 1146 | { |
| 1147 | uint8_t null = 0; |
| 1148 | msgb_tvlv_put(msg, BSSGP_IE_BSS_AREA_ID, 1, &null); |
| 1149 | } |
| 1150 | break; |
| 1151 | case BSSGP_PAGING_LOCATION_AREA: |
| 1152 | gsm48_construct_ra(ra, &pinfo->raid); |
| 1153 | msgb_tvlv_put(msg, BSSGP_IE_LOCATION_AREA, 4, ra); |
| 1154 | break; |
| 1155 | case BSSGP_PAGING_ROUTEING_AREA: |
| 1156 | gsm48_construct_ra(ra, &pinfo->raid); |
| 1157 | msgb_tvlv_put(msg, BSSGP_IE_ROUTEING_AREA, 6, ra); |
| 1158 | break; |
| 1159 | case BSSGP_PAGING_BVCI: |
| 1160 | { |
| 1161 | uint16_t bvci = htons(pinfo->bvci); |
| 1162 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *)&bvci); |
| 1163 | } |
| 1164 | break; |
| 1165 | } |
| 1166 | /* QoS profile mandatory for PS */ |
| 1167 | if (pinfo->mode == BSSGP_PAGING_PS) |
| 1168 | msgb_tvlv_put(msg, BSSGP_IE_QOS_PROFILE, 3, pinfo->qos); |
| 1169 | |
| 1170 | /* Optional (P-)TMSI */ |
| 1171 | if (pinfo->ptmsi) { |
| 1172 | uint32_t ptmsi = htonl(*pinfo->ptmsi); |
| 1173 | msgb_tvlv_put(msg, BSSGP_IE_TMSI, 4, (uint8_t *) &ptmsi); |
| 1174 | } |
| 1175 | |
| 1176 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
| 1177 | } |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 1178 | |
Harald Welte | de4599c | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 1179 | void bssgp_set_log_ss(int ss) |
Harald Welte | cca4963 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 1180 | { |
| 1181 | DBSSGP = ss; |
| 1182 | } |