Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 1 | /* GPRS BSSGP protocol implementation as per 3GPP TS 08.18 */ |
| 2 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <errno.h> |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 24 | #include <stdint.h> |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 25 | |
| 26 | #include <netinet/in.h> |
| 27 | |
| 28 | #include <osmocore/msgb.h> |
| 29 | #include <osmocore/tlv.h> |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 30 | #include <osmocore/talloc.h> |
| 31 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 32 | #include <openbsc/debug.h> |
| 33 | #include <openbsc/gsm_data.h> |
| 34 | #include <openbsc/gsm_04_08_gprs.h> |
| 35 | #include <openbsc/gprs_bssgp.h> |
| 36 | #include <openbsc/gprs_llc.h> |
| 37 | #include <openbsc/gprs_ns.h> |
| 38 | |
| 39 | /* global pointer to the gsm network data structure */ |
| 40 | /* FIXME: this must go! */ |
| 41 | extern struct gsm_network *bsc_gsmnet; |
| 42 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 43 | void *bssgp_tall_ctx = NULL; |
| 44 | |
Harald Welte | dbab1c7 | 2010-05-02 09:34:20 +0200 | [diff] [blame] | 45 | |
| 46 | /* Our actual implementation */ |
| 47 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 48 | #define BVC_F_BLOCKED 0x0001 |
| 49 | |
| 50 | /* The per-BTS context that we keep on the SGSN side of the BSSGP link */ |
| 51 | struct bssgp_bts_ctx { |
| 52 | struct llist_head list; |
| 53 | |
| 54 | /* parsed RA ID and Cell ID of the remote BTS */ |
| 55 | struct gprs_ra_id ra_id; |
| 56 | uint16_t cell_id; |
| 57 | |
| 58 | /* NSEI and BVCI of underlying Gb link. Together they |
| 59 | * uniquely identify a link to a BTS (5.4.4) */ |
| 60 | uint16_t bvci; |
| 61 | uint16_t nsei; |
| 62 | |
| 63 | uint32_t bvc_state; |
| 64 | |
| 65 | /* we might want to add this as a shortcut later, avoiding the NSVC |
| 66 | * lookup for every packet, similar to a routing cache */ |
| 67 | //struct gprs_nsvc *nsvc; |
| 68 | }; |
| 69 | LLIST_HEAD(bts_ctxts); |
| 70 | |
| 71 | /* Find a BTS Context based on parsed RA ID and Cell ID */ |
| 72 | struct bssgp_bts_ctx *btsctx_by_raid_cid(const struct gprs_ra_id *raid, uint16_t cid) |
| 73 | { |
| 74 | struct bssgp_bts_ctx *bctx; |
| 75 | |
| 76 | llist_for_each_entry(bctx, &bts_ctxts, list) { |
| 77 | if (!memcmp(&bctx->ra_id, raid, sizeof(bctx->ra_id)) && |
| 78 | bctx->cell_id == cid) |
| 79 | return bctx; |
| 80 | } |
| 81 | return NULL; |
| 82 | } |
| 83 | |
| 84 | /* Find a BTS context based on BVCI+NSEI tuple */ |
| 85 | struct bssgp_bts_ctx *btsctx_by_bvci_nsei(uint16_t bvci, uint16_t nsei) |
| 86 | { |
| 87 | struct bssgp_bts_ctx *bctx; |
| 88 | |
| 89 | llist_for_each_entry(bctx, &bts_ctxts, list) { |
| 90 | if (bctx->nsei == nsei && bctx->bvci == bvci) |
| 91 | return bctx; |
| 92 | } |
| 93 | return NULL; |
| 94 | } |
| 95 | |
| 96 | struct bssgp_btx_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei) |
| 97 | { |
| 98 | struct bssgp_bts_ctx *ctx; |
| 99 | |
| 100 | ctx = talloc_zero(bssgp_tall_ctx, struct bssgp_bts_ctx); |
| 101 | if (!ctx) |
| 102 | return NULL; |
| 103 | ctx->bvci = bvci; |
| 104 | ctx->nsei = nsei; |
| 105 | llist_add(&ctx->list, &bts_ctxts); |
| 106 | |
| 107 | return ctx; |
| 108 | } |
| 109 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 110 | /* Chapter 10.4.5: Flow Control BVC ACK */ |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 111 | static int bssgp_tx_fc_bvc_ack(uint16_t nsei, uint8_t tag, uint16_t ns_bvci) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 112 | { |
| 113 | struct msgb *msg = bssgp_msgb_alloc(); |
| 114 | struct bssgp_normal_hdr *bgph = |
| 115 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 116 | |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 117 | msgb_nsei(msg) = nsei; |
| 118 | msgb_bvci(msg) = ns_bvci; |
| 119 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 120 | bgph->pdu_type = BSSGP_PDUT_FLOW_CONTROL_BVC_ACK; |
| 121 | msgb_tvlv_put(msg, BSSGP_IE_TAG, 1, &tag); |
| 122 | |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 123 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 124 | } |
| 125 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 126 | uint16_t bssgp_parse_cell_id(struct gprs_ra_id *raid, const uint8_t *buf) |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 127 | { |
| 128 | /* 6 octets RAC */ |
| 129 | gsm48_parse_ra(raid, buf); |
| 130 | /* 2 octets CID */ |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 131 | return ntohs(*(uint16_t *) (buf+6)); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 134 | /* Chapter 8.4 BVC-Reset Procedure */ |
| 135 | static int bssgp_rx_bvc_reset(struct msgb *msg, struct tlv_parsed *tp, |
| 136 | uint16_t ns_bvci) |
| 137 | { |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 138 | struct bssgp_bts_ctx *bctx; |
| 139 | uint16_t nsei = msgb_nsei(msg); |
| 140 | uint16_t bvci; |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 141 | int rc; |
| 142 | |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 143 | bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 144 | DEBUGPC(DBSSGP, "BVCI=%u, cause=%s\n", bvci, |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 145 | bssgp_cause_str(*TLVP_VAL(tp, BSSGP_IE_CAUSE))); |
| 146 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 147 | /* look-up or create the BTS context for this BVC */ |
| 148 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 149 | if (!bctx) |
| 150 | bctx = btsctx_alloc(bvci, nsei); |
| 151 | |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 152 | /* When we receive a BVC-RESET PDU (at least of a PTP BVCI), the BSS |
| 153 | * informs us about its RAC + Cell ID, so we can create a mapping */ |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 154 | if (bvci != 0 && bvci != 1) { |
| 155 | if (!TLVP_PRESENT(tp, BSSGP_IE_CELL_ID)) { |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 156 | LOGP(DBSSGP, LOGL_ERROR, "BSSGP RESET BVCI=%u " |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 157 | "missing mandatory IE\n", bvci); |
| 158 | return -EINVAL; |
| 159 | } |
| 160 | /* actually extract RAC / CID */ |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 161 | bctx->cell_id = bssgp_parse_cell_id(&bctx->ra_id, |
| 162 | TLVP_VAL(tp, BSSGP_IE_CELL_ID)); |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 163 | LOGP(DBSSGP, LOGL_NOTICE, "Cell %u-%u-%u-%u CI %u on BVCI %u\n", |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 164 | bctx->ra_id.mcc, bctx->ra_id.mnc, bctx->ra_id.lac, |
| 165 | bctx->ra_id.rac, bctx->cell_id, bvci); |
| 166 | } |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 167 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 168 | /* Acknowledge the RESET to the BTS */ |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 169 | rc = bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 170 | nsei, bvci, ns_bvci); |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 174 | /* Uplink unit-data */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 175 | static int bssgp_rx_ul_ud(struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 176 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 177 | struct bssgp_ud_hdr *budh = (struct bssgp_ud_hdr *) msgb_bssgph(msg); |
Harald Welte | 721961c | 2010-05-02 21:29:36 +0200 | [diff] [blame] | 178 | int data_len = msgb_bssgp_len(msg) - sizeof(*budh); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 179 | struct tlv_parsed tp; |
| 180 | int rc; |
| 181 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 182 | DEBUGP(DBSSGP, "BSSGP UL-UD\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 183 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 184 | /* extract TLLI and parse TLV IEs */ |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 185 | msgb_tlli(msg) = ntohl(budh->tlli); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 186 | rc = bssgp_tlv_parse(&tp, budh->data, data_len); |
| 187 | |
| 188 | /* Cell ID and LLC_PDU are the only mandatory IE */ |
| 189 | if (!TLVP_PRESENT(&tp, BSSGP_IE_CELL_ID) || |
| 190 | !TLVP_PRESENT(&tp, BSSGP_IE_LLC_PDU)) |
| 191 | return -EIO; |
| 192 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 193 | /* FIXME: lookup bssgp_bts_ctx based on BVCI + NSEI */ |
| 194 | |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 195 | /* store pointer to LLC header and CELL ID in msgb->cb */ |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 196 | msgb_llch(msg) = TLVP_VAL(&tp, BSSGP_IE_LLC_PDU); |
Harald Welte | 11d7c10 | 2010-05-02 11:54:55 +0200 | [diff] [blame] | 197 | msgb_bcid(msg) = TLVP_VAL(&tp, BSSGP_IE_CELL_ID); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 198 | |
| 199 | return gprs_llc_rcvmsg(msg, &tp); |
| 200 | } |
| 201 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 202 | static int bssgp_rx_suspend(struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 203 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 204 | struct bssgp_normal_hdr *bgph = |
| 205 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 721961c | 2010-05-02 21:29:36 +0200 | [diff] [blame] | 206 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 207 | struct tlv_parsed tp; |
| 208 | int rc; |
| 209 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 210 | DEBUGP(DBSSGP, "BSSGP SUSPEND\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 211 | |
| 212 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 213 | if (rc < 0) |
| 214 | return rc; |
| 215 | |
| 216 | if (!TLVP_PRESENT(&tp, BSSGP_IE_TLLI) || |
| 217 | !TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) |
| 218 | return -EIO; |
| 219 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 220 | /* FIXME: pass the SUSPEND request to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 221 | /* SEND SUSPEND_ACK or SUSPEND_NACK */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 222 | } |
| 223 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 224 | static int bssgp_rx_resume(struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 225 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 226 | struct bssgp_normal_hdr *bgph = |
| 227 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 721961c | 2010-05-02 21:29:36 +0200 | [diff] [blame] | 228 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 229 | struct tlv_parsed tp; |
| 230 | int rc; |
| 231 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 232 | DEBUGP(DBSSGP, "BSSGP RESUME\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 233 | |
| 234 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 235 | if (rc < 0) |
| 236 | return rc; |
| 237 | |
| 238 | if (!TLVP_PRESENT(&tp, BSSGP_IE_TLLI) || |
| 239 | !TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA) || |
| 240 | !TLVP_PRESENT(&tp, BSSGP_IE_SUSPEND_REF_NR)) |
| 241 | return -EIO; |
| 242 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 243 | /* FIXME: pass the RESUME request to GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 244 | /* SEND RESUME_ACK or RESUME_NACK */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 245 | } |
| 246 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 247 | static int bssgp_rx_fc_bvc(struct msgb *msg, struct tlv_parsed *tp) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 248 | { |
| 249 | |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 250 | DEBUGP(DBSSGP, "BSSGP FC BVC\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 251 | |
| 252 | if (!TLVP_PRESENT(tp, BSSGP_IE_TAG) || |
| 253 | !TLVP_PRESENT(tp, BSSGP_IE_BVC_BUCKET_SIZE) || |
| 254 | !TLVP_PRESENT(tp, BSSGP_IE_BUCKET_LEAK_RATE) || |
| 255 | !TLVP_PRESENT(tp, BSSGP_IE_BMAX_DEFAULT_MS) || |
| 256 | !TLVP_PRESENT(tp, BSSGP_IE_R_DEFAULT_MS)) |
| 257 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 258 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 259 | /* FIXME: actually implement flow control */ |
| 260 | |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 261 | /* Send FLOW_CONTROL_BVC_ACK */ |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 262 | return bssgp_tx_fc_bvc_ack(msgb_nsei(msg), *TLVP_VAL(tp, BSSGP_IE_TAG), |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 263 | msgb_bvci(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 264 | } |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 265 | |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 266 | /* We expect msgb_bssgph() to point to the BSSGP header */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 267 | int gprs_bssgp_rcvmsg(struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 268 | { |
Harald Welte | fd3fa1d | 2010-05-02 09:50:42 +0200 | [diff] [blame] | 269 | struct bssgp_normal_hdr *bgph = |
| 270 | (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 271 | struct tlv_parsed tp; |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 272 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 721961c | 2010-05-02 21:29:36 +0200 | [diff] [blame] | 273 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 274 | uint16_t bvci; /* PTP BVCI */ |
| 275 | uint16_t ns_bvci = msgb_bvci(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 276 | int rc = 0; |
| 277 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 278 | /* Identifiers from DOWN: NSEI, BVCI (both in msg->cb) */ |
| 279 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 280 | /* UNITDATA BSSGP headers have TLLI in front */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 281 | if (pdu_type != BSSGP_PDUT_UL_UNITDATA && |
| 282 | pdu_type != BSSGP_PDUT_DL_UNITDATA) |
| 283 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 284 | |
| 285 | switch (pdu_type) { |
| 286 | case BSSGP_PDUT_UL_UNITDATA: |
| 287 | /* some LLC data from the MS */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 288 | rc = bssgp_rx_ul_ud(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 289 | break; |
| 290 | case BSSGP_PDUT_RA_CAPABILITY: |
| 291 | /* BSS requests RA capability or IMSI */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 292 | DEBUGP(DBSSGP, "BSSGP RA CAPABILITY UPDATE\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 293 | /* FIXME: send RA_CAPA_UPDATE_ACK */ |
| 294 | break; |
| 295 | case BSSGP_PDUT_RADIO_STATUS: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 296 | DEBUGP(DBSSGP, "BSSGP RADIO STATUS\n"); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 297 | /* BSS informs us of some exception */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 298 | /* FIXME: notify GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 299 | break; |
| 300 | case BSSGP_PDUT_SUSPEND: |
| 301 | /* MS wants to suspend */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 302 | rc = bssgp_rx_suspend(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 303 | break; |
| 304 | case BSSGP_PDUT_RESUME: |
| 305 | /* MS wants to resume */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 306 | rc = bssgp_rx_resume(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 307 | break; |
| 308 | case BSSGP_PDUT_FLUSH_LL: |
| 309 | /* BSS informs MS has moved to one cell to other cell */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 310 | DEBUGP(DBSSGP, "BSSGP FLUSH LL\n"); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 311 | /* FIXME: notify GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 312 | /* Send FLUSH_LL_ACK */ |
| 313 | break; |
| 314 | case BSSGP_PDUT_LLC_DISCARD: |
| 315 | /* BSS informs that some LLC PDU's have been discarded */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 316 | DEBUGP(DBSSGP, "BSSGP LLC DISCARDED\n"); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 317 | /* FIXME: notify GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 318 | break; |
| 319 | case BSSGP_PDUT_FLOW_CONTROL_BVC: |
| 320 | /* BSS informs us of available bandwidth in Gb interface */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 321 | rc = bssgp_rx_fc_bvc(msg, &tp); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 322 | break; |
| 323 | case BSSGP_PDUT_FLOW_CONTROL_MS: |
| 324 | /* BSS informs us of available bandwidth to one MS */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 325 | DEBUGP(DBSSGP, "BSSGP FC MS\n"); |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 326 | /* FIXME: actually implement flow control */ |
| 327 | /* FIXME: Send FLOW_CONTROL_MS_ACK */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 328 | break; |
| 329 | case BSSGP_PDUT_BVC_BLOCK: |
| 330 | /* BSS tells us that BVC shall be blocked */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 331 | DEBUGP(DBSSGP, "BSSGP BVC BLOCK "); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 332 | if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI) || |
| 333 | !TLVP_PRESENT(&tp, BSSGP_IE_CAUSE)) |
| 334 | goto err_mand_ie; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 335 | bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 336 | DEBUGPC(DBSSGP, "BVCI=%u, cause=%s\n", bvci, |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 337 | bssgp_cause_str(*TLVP_VAL(&tp, BSSGP_IE_CAUSE))); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 338 | /* We always acknowledge the BLOCKing */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 339 | rc = bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK_ACK, |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 340 | msgb_nsei(msg), bvci, ns_bvci); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 341 | break; |
| 342 | case BSSGP_PDUT_BVC_UNBLOCK: |
| 343 | /* BSS tells us that BVC shall be unblocked */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 344 | DEBUGP(DBSSGP, "BSSGP BVC UNBLOCK "); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 345 | if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) |
| 346 | goto err_mand_ie; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 347 | bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 348 | DEBUGPC(DBSSGP, "BVCI=%u\n", bvci); |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 349 | /* We always acknowledge the unBLOCKing */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 350 | rc = bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_UNBLOCK_ACK, |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 351 | msgb_nsei(msg), bvci, ns_bvci); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 352 | break; |
| 353 | case BSSGP_PDUT_BVC_RESET: |
| 354 | /* BSS tells us that BVC init is required */ |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 355 | DEBUGP(DBSSGP, "BSSGP BVC RESET "); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 356 | if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI) || |
| 357 | !TLVP_PRESENT(&tp, BSSGP_IE_CAUSE)) |
| 358 | goto err_mand_ie; |
Harald Welte | 288be16 | 2010-05-01 16:48:27 +0200 | [diff] [blame] | 359 | rc = bssgp_rx_bvc_reset(msg, &tp, ns_bvci); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 360 | break; |
| 361 | case BSSGP_PDUT_STATUS: |
| 362 | /* Some exception has occurred */ |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 363 | /* FIXME: notify GMM */ |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 364 | case BSSGP_PDUT_DOWNLOAD_BSS_PFC: |
| 365 | case BSSGP_PDUT_CREATE_BSS_PFC_ACK: |
| 366 | case BSSGP_PDUT_CREATE_BSS_PFC_NACK: |
| 367 | case BSSGP_PDUT_MODIFY_BSS_PFC: |
| 368 | case BSSGP_PDUT_DELETE_BSS_PFC_ACK: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 369 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x not [yet] implemented\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 370 | pdu_type); |
| 371 | break; |
| 372 | /* those only exist in the SGSN -> BSS direction */ |
| 373 | case BSSGP_PDUT_DL_UNITDATA: |
| 374 | case BSSGP_PDUT_PAGING_PS: |
| 375 | case BSSGP_PDUT_PAGING_CS: |
| 376 | case BSSGP_PDUT_RA_CAPA_UPDATE_ACK: |
| 377 | case BSSGP_PDUT_SUSPEND_ACK: |
| 378 | case BSSGP_PDUT_SUSPEND_NACK: |
| 379 | case BSSGP_PDUT_RESUME_ACK: |
| 380 | case BSSGP_PDUT_RESUME_NACK: |
| 381 | case BSSGP_PDUT_FLUSH_LL_ACK: |
| 382 | case BSSGP_PDUT_FLOW_CONTROL_BVC_ACK: |
| 383 | case BSSGP_PDUT_FLOW_CONTROL_MS_ACK: |
| 384 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 385 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 386 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 387 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x only exists in DL\n", |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 388 | pdu_type); |
| 389 | rc = -EINVAL; |
| 390 | break; |
| 391 | default: |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 392 | DEBUGP(DBSSGP, "BSSGP PDU type 0x%02x unknown\n", pdu_type); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 393 | break; |
| 394 | } |
| 395 | |
| 396 | return rc; |
| 397 | err_mand_ie: |
| 398 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
| 399 | } |
| 400 | |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 401 | /* Entry function from upper level (LLC), asking us to transmit a BSSGP PDU |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 402 | * to a remote MS (identified by TLLI) at a BTS identified by its BVCI and NSEI */ |
| 403 | int gprs_bssgp_tx_dl_ud(struct msgb *msg) |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 404 | { |
Harald Welte | 6557cd0 | 2010-05-02 09:23:16 +0200 | [diff] [blame] | 405 | struct bssgp_bts_ctx *bctx; |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 406 | struct bssgp_ud_hdr *budh; |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 407 | uint8_t llc_pdu_tlv_hdr_len = 2; |
| 408 | uint8_t *llc_pdu_tlv, *qos_profile; |
| 409 | uint16_t pdu_lifetime = 1000; /* centi-seconds */ |
| 410 | uint8_t qos_profile_default[3] = { 0x00, 0x00, 0x21 }; |
| 411 | uint16_t msg_len = msg->len; |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 412 | uint16_t bvci = msgb_bvci(msg); |
| 413 | uint16_t nsei = msgb_nsei(msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 414 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 415 | /* Identifiers from UP: TLLI, BVCI, NSEI (all in msgb->cb) */ |
| 416 | if (bvci < 2) { |
Harald Welte | 6b72cdf | 2010-05-11 05:54:22 +0200 | [diff] [blame] | 417 | LOGP(DBSSGP, LOGL_ERROR, "Cannot send DL-UD to BVCI %u\n", |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 418 | bvci); |
| 419 | return -EINVAL; |
| 420 | } |
| 421 | |
| 422 | bctx = btsctx_by_bvci_nsei(bvci, nsei); |
| 423 | if (!bctx) |
| 424 | bctx = btsctx_alloc(bvci, nsei); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 425 | |
| 426 | if (msg->len > TVLV_MAX_ONEBYTE) |
| 427 | llc_pdu_tlv_hdr_len += 1; |
| 428 | |
| 429 | /* prepend the tag and length of the LLC-PDU TLV */ |
| 430 | llc_pdu_tlv = msgb_push(msg, llc_pdu_tlv_hdr_len); |
| 431 | llc_pdu_tlv[0] = BSSGP_IE_LLC_PDU; |
| 432 | if (llc_pdu_tlv_hdr_len > 2) { |
| 433 | llc_pdu_tlv[1] = msg_len >> 8; |
| 434 | llc_pdu_tlv[2] = msg_len & 0xff; |
| 435 | } else { |
| 436 | llc_pdu_tlv[1] = msg_len & 0x3f; |
| 437 | llc_pdu_tlv[1] |= 0x80; |
| 438 | } |
| 439 | |
| 440 | /* FIXME: optional elements */ |
| 441 | |
| 442 | /* prepend the pdu lifetime */ |
| 443 | pdu_lifetime = htons(pdu_lifetime); |
Harald Welte | eaa614c | 2010-05-02 11:26:34 +0200 | [diff] [blame] | 444 | msgb_tvlv_push(msg, BSSGP_IE_PDU_LIFETIME, 2, (uint8_t *)&pdu_lifetime); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 445 | |
| 446 | /* prepend the QoS profile, TLLI and pdu type */ |
| 447 | budh = (struct bssgp_ud_hdr *) msgb_push(msg, sizeof(*budh)); |
| 448 | memcpy(budh->qos_profile, qos_profile_default, sizeof(qos_profile_default)); |
Harald Welte | 943c5bc | 2010-04-30 16:33:12 +0200 | [diff] [blame] | 449 | budh->tlli = htonl(msgb_tlli(msg)); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 450 | budh->pdu_type = BSSGP_PDUT_DL_UNITDATA; |
| 451 | |
Harald Welte | e6afd60 | 2010-05-02 11:19:37 +0200 | [diff] [blame] | 452 | /* Identifiers down: BVCI, NSEI (in msgb->cb) */ |
Harald Welte | 44f1c27 | 2010-04-30 19:54:29 +0200 | [diff] [blame] | 453 | |
| 454 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9b455bf | 2010-03-14 15:45:01 +0800 | [diff] [blame] | 455 | } |