Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1 | /* NS-over-IP proxy */ |
| 2 | |
| 3 | /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2010 by On Waves |
| 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 <unistd.h> |
| 24 | #include <stdio.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
| 27 | #include <getopt.h> |
| 28 | #include <errno.h> |
| 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/stat.h> |
| 31 | #include <sys/types.h> |
| 32 | |
| 33 | #include <osmocore/talloc.h> |
| 34 | #include <osmocore/select.h> |
| 35 | |
| 36 | #include <openbsc/signal.h> |
| 37 | #include <openbsc/debug.h> |
| 38 | #include <openbsc/gprs_ns.h> |
| 39 | #include <openbsc/gprs_bssgp.h> |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 40 | #include <openbsc/gb_proxy.h> |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 41 | |
| 42 | struct gbprox_peer { |
| 43 | struct llist_head list; |
| 44 | |
| 45 | /* NS-VC over which we send/receive data to this BVC */ |
| 46 | struct gprs_nsvc *nsvc; |
| 47 | |
| 48 | /* BVCI used for Point-to-Point to this peer */ |
| 49 | uint16_t bvci; |
| 50 | |
| 51 | /* Routeing Area that this peer is part of (raw 04.08 encoding) */ |
| 52 | uint8_t ra[6]; |
| 53 | }; |
| 54 | |
| 55 | /* Linked list of all Gb peers (except SGSN) */ |
| 56 | static LLIST_HEAD(gbprox_bts_peers); |
| 57 | |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 58 | extern struct gprs_ns_inst *gbprox_nsi; |
| 59 | |
| 60 | /* Find the gbprox_peer by its BVCI */ |
| 61 | static struct gbprox_peer *peer_by_bvci(uint16_t bvci) |
| 62 | { |
| 63 | struct gbprox_peer *peer; |
| 64 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 65 | if (peer->bvci == bvci) |
| 66 | return peer; |
| 67 | } |
| 68 | return NULL; |
| 69 | } |
| 70 | |
| 71 | static struct gbprox_peer *peer_by_nsvc(struct gprs_nsvc *nsvc) |
| 72 | { |
| 73 | struct gbprox_peer *peer; |
| 74 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 75 | if (peer->nsvc == nsvc) |
| 76 | return peer; |
| 77 | } |
| 78 | return NULL; |
| 79 | } |
| 80 | |
| 81 | /* look-up a peer by its Routeing Area Code (RAC) */ |
Harald Welte | e49c829 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 82 | static struct gbprox_peer *peer_by_rac(const uint8_t *ra) |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 83 | { |
| 84 | struct gbprox_peer *peer; |
| 85 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 86 | if (!memcmp(&peer->ra, ra, 6)) |
| 87 | return peer; |
| 88 | } |
| 89 | return NULL; |
| 90 | } |
| 91 | |
| 92 | /* look-up a peer by its Location Area Code (LAC) */ |
Harald Welte | e49c829 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 93 | static struct gbprox_peer *peer_by_lac(const uint8_t *la) |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 94 | { |
| 95 | struct gbprox_peer *peer; |
| 96 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 97 | if (!memcmp(&peer->ra, la, 5)) |
| 98 | return peer; |
| 99 | } |
| 100 | return NULL; |
| 101 | } |
| 102 | |
| 103 | static struct gbprox_peer *peer_alloc(uint16_t bvci) |
| 104 | { |
| 105 | struct gbprox_peer *peer; |
| 106 | |
| 107 | peer = talloc_zero(tall_bsc_ctx, struct gbprox_peer); |
| 108 | if (!peer) |
| 109 | return NULL; |
| 110 | |
| 111 | peer->bvci = bvci; |
| 112 | llist_add(&peer->list, &gbprox_bts_peers); |
| 113 | |
| 114 | return peer; |
| 115 | } |
| 116 | |
| 117 | static void peer_free(struct gbprox_peer *peer) |
| 118 | { |
| 119 | llist_del(&peer->list); |
| 120 | talloc_free(peer); |
| 121 | } |
| 122 | |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 123 | /* strip off the NS header */ |
| 124 | static void strip_ns_hdr(struct msgb *msg) |
| 125 | { |
| 126 | int strip_len = msgb_bssgph(msg) - msg->data; |
| 127 | msgb_pull(msg, strip_len); |
| 128 | } |
| 129 | |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 130 | /* FIXME: this is copy+paste from gprs_bssgp.c */ |
| 131 | static inline struct msgb *bssgp_msgb_alloc(void) |
| 132 | { |
| 133 | return msgb_alloc_headroom(4096, 128, "BSSGP"); |
| 134 | } |
| 135 | static int bssgp_tx_simple_bvci(uint8_t pdu_type, uint16_t nsei, |
| 136 | uint16_t bvci, uint16_t ns_bvci) |
| 137 | { |
| 138 | struct msgb *msg = bssgp_msgb_alloc(); |
| 139 | struct bssgp_normal_hdr *bgph = |
| 140 | (struct bssgp_normal_hdr *) msgb_put(msg, sizeof(*bgph)); |
| 141 | uint16_t _bvci; |
| 142 | |
| 143 | msgb_nsei(msg) = nsei; |
| 144 | msgb_bvci(msg) = ns_bvci; |
| 145 | |
| 146 | bgph->pdu_type = pdu_type; |
| 147 | _bvci = htons(bvci); |
| 148 | msgb_tvlv_put(msg, BSSGP_IE_BVCI, 2, (uint8_t *) &_bvci); |
| 149 | |
| 150 | return gprs_ns_sendmsg(gbprox_nsi, msg); |
| 151 | } |
| 152 | |
| 153 | |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 154 | /* feed a message down the NS-VC associated with the specified peer */ |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 155 | static int gbprox_relay2sgsn(struct msgb *msg, uint16_t ns_bvci) |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 156 | { |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 157 | DEBUGP(DGPRS, "NSEI=%u proxying to SGSN (NS_BVCI=%u, NSEI=%u)\n", |
Harald Welte | e661b27 | 2010-05-03 19:28:05 +0200 | [diff] [blame] | 158 | msgb_nsei(msg), ns_bvci, gbcfg.nsip_sgsn_nsei); |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 159 | |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 160 | msgb_bvci(msg) = ns_bvci; |
| 161 | msgb_nsei(msg) = gbcfg.nsip_sgsn_nsei; |
| 162 | |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 163 | strip_ns_hdr(msg); |
| 164 | |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 165 | return gprs_ns_sendmsg(gbprox_nsi, msg); |
| 166 | } |
| 167 | |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 168 | /* feed a message down the NS-VC associated with the specified peer */ |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 169 | static int gbprox_relay2peer(struct msgb *msg, struct gbprox_peer *peer, |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 170 | uint16_t ns_bvci) |
| 171 | { |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 172 | DEBUGP(DGPRS, "NSEI=%u proxying to BSS (NS_BVCI=%u, NSEI=%u)\n", |
Harald Welte | e661b27 | 2010-05-03 19:28:05 +0200 | [diff] [blame] | 173 | msgb_nsei(msg), ns_bvci, peer->nsvc->nsei); |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 174 | |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 175 | msgb_bvci(msg) = ns_bvci; |
| 176 | msgb_nsei(msg) = peer->nsvc->nsei; |
| 177 | |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 178 | strip_ns_hdr(msg); |
| 179 | |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 180 | return gprs_ns_sendmsg(gbprox_nsi, msg); |
| 181 | } |
| 182 | |
| 183 | /* Send a message to a peer identified by ptp_bvci but using ns_bvci |
| 184 | * in the NS hdr */ |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 185 | static int gbprox_relay2bvci(struct msgb *msg, uint16_t ptp_bvci, |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 186 | uint16_t ns_bvci) |
| 187 | { |
| 188 | struct gbprox_peer *peer; |
| 189 | |
| 190 | peer = peer_by_bvci(ptp_bvci); |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 191 | if (!peer) { |
| 192 | LOGP(DGPRS, LOGL_ERROR, "Cannot find BSS for BVCI %u\n", |
| 193 | ptp_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 194 | return -ENOENT; |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 195 | } |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 196 | |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 197 | return gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /* Receive an incoming signalling message from a BSS-side NS-VC */ |
| 201 | static int gbprox_rx_sig_from_bss(struct msgb *msg, struct gprs_nsvc *nsvc, |
| 202 | uint16_t ns_bvci) |
| 203 | { |
Harald Welte | 2ac2e91 | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 204 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 205 | struct tlv_parsed tp; |
| 206 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 2ac2e91 | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 207 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 208 | struct gbprox_peer *from_peer; |
Harald Welte | e49c829 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 209 | struct gprs_ra_id raid; |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 210 | |
| 211 | if (ns_bvci != 0) { |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 212 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u BVCI %u is not signalling\n", |
| 213 | nsvc->nsei, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 214 | return -EINVAL; |
| 215 | } |
| 216 | |
| 217 | /* we actually should never see those two for BVCI == 0, but double-check |
| 218 | * just to make sure */ |
| 219 | if (pdu_type == BSSGP_PDUT_UL_UNITDATA || |
| 220 | pdu_type == BSSGP_PDUT_DL_UNITDATA) { |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 221 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u UNITDATA not allowed in " |
| 222 | "signalling\n", nsvc->nsei); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 223 | return -EINVAL; |
| 224 | } |
| 225 | |
| 226 | bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 227 | |
| 228 | switch (pdu_type) { |
| 229 | case BSSGP_PDUT_SUSPEND: |
| 230 | case BSSGP_PDUT_RESUME: |
Harald Welte | e49c829 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 231 | /* We implement RAC snooping during SUSPEND/RESUME, since |
| 232 | * it establishes a relationsip between BVCI/peer and the |
| 233 | * routeing area code. The snooped information is then |
| 234 | * used for routing the {SUSPEND,RESUME}_[N]ACK back to |
| 235 | * the correct BSSGP */ |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 236 | if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) |
| 237 | goto err_mand_ie; |
| 238 | from_peer = peer_by_nsvc(nsvc); |
| 239 | if (!from_peer) |
| 240 | goto err_no_peer; |
| 241 | memcpy(&from_peer->ra, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA), |
| 242 | sizeof(&from_peer->ra)); |
Harald Welte | e49c829 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 243 | gsm48_parse_ra(&raid, &from_peer->ra); |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 244 | DEBUGP(DGPRS, "NSEI=%u RAC snooping: RAC %u/%u/%u/%u behind BVCI=%u, " |
| 245 | "NSVCI=%u\n", nsvc->nsei, raid.mcc, raid.mnc, raid.lac, |
| 246 | raid.rac , from_peer->bvci, nsvc->nsvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 247 | /* FIXME: This only supports one BSS per RA */ |
| 248 | break; |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 249 | case BSSGP_PDUT_BVC_RESET: |
| 250 | /* If we receive a BVC reset on the signalling endpoint, we |
| 251 | * don't want the SGSN to reset, as the signalling endpoint |
| 252 | * is common for all point-to-point BVCs (and thus all BTS) */ |
| 253 | if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { |
| 254 | uint16_t bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
| 255 | if (bvci == 0) { |
| 256 | /* FIXME: only do this if SGSN is alive! */ |
| 257 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u Sending fake " |
| 258 | "BVC RESET ACK of BVCI=0\n", nsvc->nsei); |
| 259 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
| 260 | nsvc->nsei, 0, ns_bvci); |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 261 | } else if (!peer_by_bvci(bvci)) { |
| 262 | /* if a PTP-BVC is reset, and we don't know that |
| 263 | * PTP-BVCI yet, we should allocate a new peer */ |
| 264 | LOGP(DGPRS, LOGL_INFO, "Allocationg new peer for " |
| 265 | "BVCI=%u via NSVCI=%u/NSEI=%u\n", bvci, |
| 266 | nsvc->nsvci, nsvc->nsei); |
| 267 | from_peer = peer_alloc(bvci); |
| 268 | from_peer->nsvc = nsvc; |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 269 | } |
| 270 | } |
| 271 | break; |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* Normally, we can simply pass on all signalling messages from BSS to SGSN */ |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 275 | return gbprox_relay2sgsn(msg, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 276 | err_no_peer: |
| 277 | err_mand_ie: |
| 278 | /* FIXME: do something */ |
| 279 | ; |
| 280 | } |
| 281 | |
| 282 | /* Receive paging request from SGSN, we need to relay to proper BSS */ |
| 283 | static int gbprox_rx_paging(struct msgb *msg, struct tlv_parsed *tp, |
| 284 | struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 285 | { |
| 286 | struct gbprox_peer *peer; |
| 287 | |
| 288 | if (TLVP_PRESENT(tp, BSSGP_IE_BVCI)) { |
| 289 | uint16_t bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 290 | return gbprox_relay2bvci(msg, bvci, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 291 | } else if (TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) { |
| 292 | peer = peer_by_rac(TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 293 | return gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 294 | } else if (TLVP_PRESENT(tp, BSSGP_IE_LOCATION_AREA)) { |
| 295 | peer = peer_by_lac(TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA)); |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 296 | return gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 297 | } else |
| 298 | return -EINVAL; |
| 299 | } |
| 300 | |
| 301 | /* Receive an incoming signalling message from the SGSN-side NS-VC */ |
| 302 | static int gbprox_rx_sig_from_sgsn(struct msgb *msg, struct gprs_nsvc *nsvc, |
| 303 | uint16_t ns_bvci) |
| 304 | { |
Harald Welte | 2ac2e91 | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 305 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 306 | struct tlv_parsed tp; |
| 307 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | 2ac2e91 | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 308 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 309 | struct gbprox_peer *peer; |
| 310 | uint16_t bvci; |
| 311 | int rc = 0; |
| 312 | |
| 313 | if (ns_bvci != 0) { |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 314 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) BVCI %u is not " |
| 315 | "signalling\n", nsvc->nsei, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 316 | return -EINVAL; |
| 317 | } |
| 318 | |
| 319 | /* we actually should never see those two for BVCI == 0, but double-check |
| 320 | * just to make sure */ |
| 321 | if (pdu_type == BSSGP_PDUT_UL_UNITDATA || |
| 322 | pdu_type == BSSGP_PDUT_DL_UNITDATA) { |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 323 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) UNITDATA not allowed in " |
| 324 | "signalling\n", nsvc->nsei); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 325 | return -EINVAL; |
| 326 | } |
| 327 | |
| 328 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 329 | |
| 330 | switch (pdu_type) { |
| 331 | case BSSGP_PDUT_FLUSH_LL: |
| 332 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 333 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 334 | case BSSGP_PDUT_BVC_RESET: |
| 335 | case BSSGP_PDUT_BVC_RESET_ACK: |
| 336 | /* simple case: BVCI IE is mandatory */ |
| 337 | if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) |
| 338 | goto err_mand_ie; |
| 339 | bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 340 | rc = gbprox_relay2bvci(msg, bvci, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 341 | break; |
| 342 | case BSSGP_PDUT_PAGING_PS: |
| 343 | case BSSGP_PDUT_PAGING_CS: |
| 344 | /* process the paging request (LAC/RAC lookup) */ |
| 345 | rc = gbprox_rx_paging(msg, &tp, nsvc, ns_bvci); |
| 346 | break; |
| 347 | case BSSGP_PDUT_STATUS: |
| 348 | /* FIXME: Some exception has occurred */ |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 349 | LOGP(DGPRS, LOGL_NOTICE, |
| 350 | "NSEI=%u(SGSN) STATUS not implemented yet\n", nsvc->nsei); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 351 | break; |
| 352 | /* those only exist in the SGSN -> BSS direction */ |
| 353 | case BSSGP_PDUT_SUSPEND_ACK: |
| 354 | case BSSGP_PDUT_SUSPEND_NACK: |
| 355 | case BSSGP_PDUT_RESUME_ACK: |
| 356 | case BSSGP_PDUT_RESUME_NACK: |
| 357 | /* RAC IE is mandatory */ |
| 358 | if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) |
| 359 | goto err_mand_ie; |
| 360 | peer = peer_by_rac(TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA)); |
| 361 | if (!peer) |
| 362 | goto err_no_peer; |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 363 | rc = gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 364 | break; |
| 365 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | 6aa24d1 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 366 | LOGP(DGPRS, LOGL_ERROR, |
| 367 | "NSEI=%u(SGSN) INVOKE TRACE not supported\n", nsvc->nsei); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 368 | break; |
| 369 | default: |
| 370 | DEBUGP(DGPRS, "BSSGP PDU type 0x%02x unknown\n", pdu_type); |
| 371 | break; |
| 372 | } |
| 373 | |
| 374 | return rc; |
| 375 | err_mand_ie: |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 376 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) missing mandatory IE\n", |
| 377 | nsvc->nsei); |
| 378 | /* FIXME: this would pull gprs_bssgp.c in, which in turn has dependencies */ |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 379 | //return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 380 | return; |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 381 | err_no_peer: |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 382 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) cannot find peer based on RAC\n"); |
| 383 | /* FIXME */ |
| 384 | return; |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | /* Main input function for Gb proxy */ |
| 388 | int gbprox_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 389 | { |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 390 | int rc; |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 391 | |
| 392 | /* Only BVCI=0 messages need special treatment */ |
| 393 | if (ns_bvci == 0 || ns_bvci == 1) { |
| 394 | if (nsvc->remote_end_is_sgsn) |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 395 | rc = gbprox_rx_sig_from_sgsn(msg, nsvc, ns_bvci); |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 396 | else |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 397 | rc = gbprox_rx_sig_from_bss(msg, nsvc, ns_bvci); |
| 398 | } else { |
| 399 | /* All other BVCI are PTP and thus can be simply forwarded */ |
Harald Welte | 0358aae | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 400 | if (!nsvc->remote_end_is_sgsn) { |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 401 | rc = gbprox_relay2sgsn(msg, ns_bvci); |
Harald Welte | e49c829 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 402 | } else { |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 403 | struct gbprox_peer *peer = peer_by_bvci(ns_bvci); |
| 404 | if (!peer) { |
| 405 | LOGP(DGPRS, LOGL_NOTICE, "Allocationg new peer for " |
| 406 | "BVCI=%u via NSVC=%u/NSEI=%u\n", ns_bvci, |
| 407 | nsvc->nsvci, nsvc->nsei); |
| 408 | peer = peer_alloc(ns_bvci); |
| 409 | peer->nsvc = nsvc; |
| 410 | } |
Harald Welte | 3ad3243 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 411 | rc = gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | e49c829 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 412 | } |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 413 | } |
| 414 | |
Harald Welte | f01709d | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 415 | return rc; |
Harald Welte | d1991e7 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 416 | } |