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