Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1 | /* NS-over-IP proxy */ |
| 2 | |
| 3 | /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 85531cc | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 4 | * (C) 2010 by On-Waves |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 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 | 9f75c35 | 2010-04-30 20:26:32 +0200 | [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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 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 | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <unistd.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <getopt.h> |
| 27 | #include <errno.h> |
| 28 | #include <sys/fcntl.h> |
| 29 | #include <sys/stat.h> |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 30 | #include <arpa/inet.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 31 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 32 | #include <osmocom/core/talloc.h> |
| 33 | #include <osmocom/core/select.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 34 | |
| 35 | #include <openbsc/signal.h> |
| 36 | #include <openbsc/debug.h> |
| 37 | #include <openbsc/gprs_ns.h> |
| 38 | #include <openbsc/gprs_bssgp.h> |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 39 | #include <openbsc/gb_proxy.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 40 | |
| 41 | struct gbprox_peer { |
| 42 | struct llist_head list; |
| 43 | |
| 44 | /* NS-VC over which we send/receive data to this BVC */ |
| 45 | struct gprs_nsvc *nsvc; |
| 46 | |
| 47 | /* BVCI used for Point-to-Point to this peer */ |
| 48 | uint16_t bvci; |
Harald Welte | 36f98d9 | 2011-02-06 13:09:29 +0100 | [diff] [blame] | 49 | int blocked; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 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 | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 58 | /* Find the gbprox_peer by its BVCI */ |
| 59 | static struct gbprox_peer *peer_by_bvci(uint16_t bvci) |
| 60 | { |
| 61 | struct gbprox_peer *peer; |
| 62 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 63 | if (peer->bvci == bvci) |
| 64 | return peer; |
| 65 | } |
| 66 | return NULL; |
| 67 | } |
| 68 | |
| 69 | static struct gbprox_peer *peer_by_nsvc(struct gprs_nsvc *nsvc) |
| 70 | { |
| 71 | struct gbprox_peer *peer; |
| 72 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 73 | if (peer->nsvc == nsvc) |
| 74 | return peer; |
| 75 | } |
| 76 | return NULL; |
| 77 | } |
| 78 | |
| 79 | /* look-up a peer by its Routeing Area Code (RAC) */ |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 80 | static struct gbprox_peer *peer_by_rac(const uint8_t *ra) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 81 | { |
| 82 | struct gbprox_peer *peer; |
| 83 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 84 | if (!memcmp(peer->ra, ra, 6)) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 85 | return peer; |
| 86 | } |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | /* look-up a peer by its Location Area Code (LAC) */ |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 91 | static struct gbprox_peer *peer_by_lac(const uint8_t *la) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 92 | { |
| 93 | struct gbprox_peer *peer; |
| 94 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 95 | if (!memcmp(peer->ra, la, 5)) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 96 | return peer; |
| 97 | } |
| 98 | return NULL; |
| 99 | } |
| 100 | |
| 101 | static struct gbprox_peer *peer_alloc(uint16_t bvci) |
| 102 | { |
| 103 | struct gbprox_peer *peer; |
| 104 | |
| 105 | peer = talloc_zero(tall_bsc_ctx, struct gbprox_peer); |
| 106 | if (!peer) |
| 107 | return NULL; |
| 108 | |
| 109 | peer->bvci = bvci; |
| 110 | llist_add(&peer->list, &gbprox_bts_peers); |
| 111 | |
| 112 | return peer; |
| 113 | } |
| 114 | |
| 115 | static void peer_free(struct gbprox_peer *peer) |
| 116 | { |
| 117 | llist_del(&peer->list); |
| 118 | talloc_free(peer); |
| 119 | } |
| 120 | |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 121 | /* FIXME: this needs to go to libosmocore/msgb.c */ |
| 122 | static struct msgb *msgb_copy(const struct msgb *msg, const char *name) |
| 123 | { |
Holger Hans Peter Freyther | 62d9798 | 2010-06-08 18:14:37 +0800 | [diff] [blame] | 124 | struct openbsc_msgb_cb *old_cb, *new_cb; |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 125 | struct msgb *new_msg; |
| 126 | |
Holger Hans Peter Freyther | 62d9798 | 2010-06-08 18:14:37 +0800 | [diff] [blame] | 127 | new_msg = msgb_alloc(msg->data_len, name); |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 128 | if (!new_msg) |
| 129 | return NULL; |
| 130 | |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 131 | /* copy data */ |
Holger Hans Peter Freyther | 62d9798 | 2010-06-08 18:14:37 +0800 | [diff] [blame] | 132 | memcpy(new_msg->_data, msg->_data, new_msg->data_len); |
| 133 | |
| 134 | /* copy header */ |
| 135 | new_msg->len = msg->len; |
| 136 | new_msg->data += msg->data - msg->_data; |
| 137 | new_msg->head += msg->head - msg->_data; |
| 138 | new_msg->tail += msg->tail - msg->_data; |
| 139 | |
| 140 | new_msg->l1h = new_msg->_data + (msg->l1h - msg->_data); |
| 141 | new_msg->l2h = new_msg->_data + (msg->l2h - msg->_data); |
| 142 | new_msg->l3h = new_msg->_data + (msg->l3h - msg->_data); |
| 143 | new_msg->l4h = new_msg->_data + (msg->l4h - msg->_data); |
| 144 | |
| 145 | /* copy GB specific data */ |
| 146 | old_cb = OBSC_MSGB_CB(msg); |
| 147 | new_cb = OBSC_MSGB_CB(new_msg); |
| 148 | |
| 149 | new_cb->bssgph = new_msg->_data + (old_cb->bssgph - msg->_data); |
| 150 | new_cb->llch = new_msg->_data + (old_cb->llch - msg->_data); |
| 151 | |
Harald Welte | fb9e06f | 2011-02-06 17:17:05 +0100 | [diff] [blame] | 152 | /* bssgp_cell_id is a pointer into the old msgb, so we need to make |
| 153 | * it a pointer into the new msgb */ |
| 154 | new_cb->bssgp_cell_id = new_msg->_data + (old_cb->bssgp_cell_id - msg->_data); |
Holger Hans Peter Freyther | 62d9798 | 2010-06-08 18:14:37 +0800 | [diff] [blame] | 155 | new_cb->nsei = old_cb->nsei; |
| 156 | new_cb->bvci = old_cb->bvci; |
| 157 | new_cb->tlli = old_cb->tlli; |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 158 | |
| 159 | return new_msg; |
| 160 | } |
| 161 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 162 | /* strip off the NS header */ |
| 163 | static void strip_ns_hdr(struct msgb *msg) |
| 164 | { |
| 165 | int strip_len = msgb_bssgph(msg) - msg->data; |
| 166 | msgb_pull(msg, strip_len); |
| 167 | } |
| 168 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 169 | /* feed a message down the NS-VC associated with the specified peer */ |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 170 | static int gbprox_relay2sgsn(struct msgb *old_msg, uint16_t ns_bvci) |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 171 | { |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 172 | /* create a copy of the message so the old one can |
| 173 | * be free()d safely when we return from gbprox_rcvmsg() */ |
| 174 | struct msgb *msg = msgb_copy(old_msg, "msgb_relay2sgsn"); |
| 175 | |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 176 | DEBUGP(DGPRS, "NSEI=%u proxying BTS->SGSN (NS_BVCI=%u, NSEI=%u)\n", |
Harald Welte | 96f71f2 | 2010-05-03 19:28:05 +0200 | [diff] [blame] | 177 | msgb_nsei(msg), ns_bvci, gbcfg.nsip_sgsn_nsei); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 178 | |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 179 | msgb_bvci(msg) = ns_bvci; |
| 180 | msgb_nsei(msg) = gbcfg.nsip_sgsn_nsei; |
| 181 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 182 | strip_ns_hdr(msg); |
| 183 | |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 184 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 187 | /* feed a message down the NS-VC associated with the specified peer */ |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 188 | static int gbprox_relay2peer(struct msgb *old_msg, struct gbprox_peer *peer, |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 189 | uint16_t ns_bvci) |
| 190 | { |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 191 | /* create a copy of the message so the old one can |
| 192 | * be free()d safely when we return from gbprox_rcvmsg() */ |
| 193 | struct msgb *msg = msgb_copy(old_msg, "msgb_relay2peer"); |
| 194 | |
Harald Welte | 0ab535b | 2010-05-13 10:34:56 +0200 | [diff] [blame] | 195 | DEBUGP(DGPRS, "NSEI=%u proxying SGSN->BSS (NS_BVCI=%u, NSEI=%u)\n", |
Harald Welte | 96f71f2 | 2010-05-03 19:28:05 +0200 | [diff] [blame] | 196 | msgb_nsei(msg), ns_bvci, peer->nsvc->nsei); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 197 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 198 | msgb_bvci(msg) = ns_bvci; |
| 199 | msgb_nsei(msg) = peer->nsvc->nsei; |
| 200 | |
Harald Welte | 0ab535b | 2010-05-13 10:34:56 +0200 | [diff] [blame] | 201 | /* Strip the old NS header, it will be replaced with a new one */ |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 202 | strip_ns_hdr(msg); |
| 203 | |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 204 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Harald Welte | 36f98d9 | 2011-02-06 13:09:29 +0100 | [diff] [blame] | 207 | static int block_unblock_peer(uint16_t ptp_bvci, uint8_t pdu_type) |
| 208 | { |
| 209 | struct gbprox_peer *peer; |
| 210 | |
| 211 | peer = peer_by_bvci(ptp_bvci); |
| 212 | if (!peer) { |
| 213 | LOGP(DGPRS, LOGL_ERROR, "BVCI=%u: Cannot find BSS\n", |
| 214 | ptp_bvci); |
| 215 | return -ENOENT; |
| 216 | } |
| 217 | |
| 218 | switch (pdu_type) { |
| 219 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 220 | peer->blocked = 1; |
| 221 | break; |
| 222 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 223 | peer->blocked = 0; |
| 224 | break; |
| 225 | default: |
| 226 | break; |
| 227 | } |
| 228 | return 0; |
| 229 | } |
| 230 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 231 | /* Send a message to a peer identified by ptp_bvci but using ns_bvci |
| 232 | * in the NS hdr */ |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 233 | static int gbprox_relay2bvci(struct msgb *msg, uint16_t ptp_bvci, |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 234 | uint16_t ns_bvci) |
| 235 | { |
| 236 | struct gbprox_peer *peer; |
| 237 | |
| 238 | peer = peer_by_bvci(ptp_bvci); |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 239 | if (!peer) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 240 | LOGP(DGPRS, LOGL_ERROR, "BVCI=%u: Cannot find BSS\n", |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 241 | ptp_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 242 | return -ENOENT; |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 243 | } |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 244 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 245 | return gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /* Receive an incoming signalling message from a BSS-side NS-VC */ |
| 249 | static int gbprox_rx_sig_from_bss(struct msgb *msg, struct gprs_nsvc *nsvc, |
| 250 | uint16_t ns_bvci) |
| 251 | { |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 252 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 253 | struct tlv_parsed tp; |
| 254 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 255 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 256 | struct gbprox_peer *from_peer; |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 257 | struct gprs_ra_id raid; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 258 | |
Harald Welte | c471d3d | 2011-02-06 17:13:12 +0100 | [diff] [blame] | 259 | if (ns_bvci != 0 && ns_bvci != 1) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 260 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u BVCI=%u is not signalling\n", |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 261 | nsvc->nsei, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 262 | return -EINVAL; |
| 263 | } |
| 264 | |
| 265 | /* we actually should never see those two for BVCI == 0, but double-check |
| 266 | * just to make sure */ |
| 267 | if (pdu_type == BSSGP_PDUT_UL_UNITDATA || |
| 268 | pdu_type == BSSGP_PDUT_DL_UNITDATA) { |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 269 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u UNITDATA not allowed in " |
| 270 | "signalling\n", nsvc->nsei); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 271 | return -EINVAL; |
| 272 | } |
| 273 | |
| 274 | bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 275 | |
| 276 | switch (pdu_type) { |
| 277 | case BSSGP_PDUT_SUSPEND: |
| 278 | case BSSGP_PDUT_RESUME: |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 279 | /* We implement RAC snooping during SUSPEND/RESUME, since |
| 280 | * it establishes a relationsip between BVCI/peer and the |
| 281 | * routeing area code. The snooped information is then |
| 282 | * used for routing the {SUSPEND,RESUME}_[N]ACK back to |
| 283 | * the correct BSSGP */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 284 | if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) |
| 285 | goto err_mand_ie; |
| 286 | from_peer = peer_by_nsvc(nsvc); |
| 287 | if (!from_peer) |
| 288 | goto err_no_peer; |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 289 | memcpy(from_peer->ra, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA), |
| 290 | sizeof(from_peer->ra)); |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 291 | gsm48_parse_ra(&raid, from_peer->ra); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 292 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u BSSGP SUSPEND/RESUME " |
| 293 | "RAC snooping: RAC %u-%u-%u-%u behind BVCI=%u, " |
| 294 | "NSVCI=%u\n",nsvc->nsei, raid.mcc, raid.mnc, raid.lac, |
| 295 | raid.rac , from_peer->bvci, nsvc->nsvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 296 | /* FIXME: This only supports one BSS per RA */ |
| 297 | break; |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 298 | case BSSGP_PDUT_BVC_RESET: |
| 299 | /* If we receive a BVC reset on the signalling endpoint, we |
| 300 | * don't want the SGSN to reset, as the signalling endpoint |
| 301 | * is common for all point-to-point BVCs (and thus all BTS) */ |
| 302 | if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { |
| 303 | uint16_t bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 72953b8 | 2010-05-12 00:20:41 +0200 | [diff] [blame] | 304 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u Rx BVC RESET (BVCI=%u)\n", |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 305 | nsvc->nsei, bvci); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 306 | if (bvci == 0) { |
| 307 | /* FIXME: only do this if SGSN is alive! */ |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 308 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u Tx fake " |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 309 | "BVC RESET ACK of BVCI=0\n", nsvc->nsei); |
| 310 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
| 311 | nsvc->nsei, 0, ns_bvci); |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 312 | } |
| 313 | from_peer = peer_by_bvci(bvci); |
| 314 | if (!from_peer) { |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 315 | /* if a PTP-BVC is reset, and we don't know that |
| 316 | * PTP-BVCI yet, we should allocate a new peer */ |
| 317 | LOGP(DGPRS, LOGL_INFO, "Allocationg new peer for " |
| 318 | "BVCI=%u via NSVCI=%u/NSEI=%u\n", bvci, |
| 319 | nsvc->nsvci, nsvc->nsei); |
| 320 | from_peer = peer_alloc(bvci); |
| 321 | from_peer->nsvc = nsvc; |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 322 | } |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 323 | if (TLVP_PRESENT(&tp, BSSGP_IE_CELL_ID)) { |
| 324 | struct gprs_ra_id raid; |
| 325 | /* We have a Cell Identifier present in this |
| 326 | * PDU, this means we can extend our local |
| 327 | * state information about this particular cell |
| 328 | * */ |
| 329 | memcpy(from_peer->ra, |
| 330 | TLVP_VAL(&tp, BSSGP_IE_CELL_ID), |
| 331 | sizeof(from_peer->ra)); |
| 332 | gsm48_parse_ra(&raid, from_peer->ra); |
| 333 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u/BVCI=%u " |
Harald Welte | 72953b8 | 2010-05-12 00:20:41 +0200 | [diff] [blame] | 334 | "Cell ID %u-%u-%u-%u\n", nsvc->nsei, |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 335 | bvci, raid.mcc, raid.mnc, raid.lac, |
| 336 | raid.rac); |
| 337 | } |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 338 | } |
| 339 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 340 | } |
| 341 | |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 342 | /* Normally, we can simply pass on all signalling messages from BSS to |
| 343 | * SGSN */ |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 344 | return gbprox_relay2sgsn(msg, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 345 | err_no_peer: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 346 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(BSS) cannot find peer based on RAC\n", |
| 347 | nsvc->nsei); |
| 348 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 349 | err_mand_ie: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 350 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(BSS) missing mandatory RA IE\n", |
| 351 | nsvc->nsei); |
| 352 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | /* Receive paging request from SGSN, we need to relay to proper BSS */ |
| 356 | static int gbprox_rx_paging(struct msgb *msg, struct tlv_parsed *tp, |
| 357 | struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 358 | { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 359 | struct gbprox_peer *peer = NULL; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 360 | |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 361 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u(SGSN) BSSGP PAGING ", |
| 362 | nsvc->nsei); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 363 | if (TLVP_PRESENT(tp, BSSGP_IE_BVCI)) { |
| 364 | uint16_t bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 365 | LOGPC(DGPRS, LOGL_INFO, "routing by BVCI to peer BVCI=%u\n", |
| 366 | bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 367 | } else if (TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) { |
| 368 | peer = peer_by_rac(TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 369 | LOGPC(DGPRS, LOGL_INFO, "routing by RAC to peer BVCI=%u\n", |
Holger Hans Peter Freyther | 62eaf54 | 2010-06-08 16:30:24 +0800 | [diff] [blame] | 370 | peer ? peer->bvci : -1); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 371 | } else if (TLVP_PRESENT(tp, BSSGP_IE_LOCATION_AREA)) { |
| 372 | peer = peer_by_lac(TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA)); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 373 | LOGPC(DGPRS, LOGL_INFO, "routing by LAC to peer BVCI=%u\n", |
Holger Hans Peter Freyther | 62eaf54 | 2010-06-08 16:30:24 +0800 | [diff] [blame] | 374 | peer ? peer->bvci : -1); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 375 | } else |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 376 | LOGPC(DGPRS, LOGL_INFO, "\n"); |
| 377 | |
| 378 | if (!peer) { |
| 379 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) BSSGP PAGING: " |
| 380 | "unable to route, missing IE\n", nsvc->nsei); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 381 | return -EINVAL; |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 382 | } |
| 383 | return gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 384 | } |
| 385 | |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 386 | /* Receive an incoming BVC-RESET message from the SGSN */ |
| 387 | static int rx_reset_from_sgsn(struct msgb *msg, struct tlv_parsed *tp, |
| 388 | struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 389 | { |
| 390 | struct gbprox_peer *peer; |
| 391 | uint16_t ptp_bvci; |
| 392 | |
| 393 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI)) { |
| 394 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, |
| 395 | NULL, msg); |
| 396 | } |
| 397 | ptp_bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
| 398 | |
| 399 | if (ptp_bvci >= 2) { |
| 400 | /* A reset for a PTP BVC was received, forward it to its |
| 401 | * respective peer */ |
| 402 | peer = peer_by_bvci(ptp_bvci); |
| 403 | if (!peer) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 404 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u BVCI=%u: Cannot find BSS\n", |
| 405 | nsvc->nsei, ptp_bvci); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 406 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, |
| 407 | NULL, msg); |
| 408 | } |
| 409 | return gbprox_relay2peer(msg, peer, ns_bvci); |
| 410 | } |
| 411 | |
| 412 | /* A reset for the Signalling entity has been received |
| 413 | * from the SGSN. As the signalling BVCI is shared |
| 414 | * among all the BSS's that we multiplex, it needs to |
| 415 | * be relayed */ |
| 416 | llist_for_each_entry(peer, &gbprox_bts_peers, list) |
| 417 | gbprox_relay2peer(msg, peer, ns_bvci); |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 422 | /* Receive an incoming signalling message from the SGSN-side NS-VC */ |
| 423 | static int gbprox_rx_sig_from_sgsn(struct msgb *msg, struct gprs_nsvc *nsvc, |
| 424 | uint16_t ns_bvci) |
| 425 | { |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 426 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 427 | struct tlv_parsed tp; |
| 428 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 429 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 430 | struct gbprox_peer *peer; |
| 431 | uint16_t bvci; |
| 432 | int rc = 0; |
| 433 | |
Harald Welte | c471d3d | 2011-02-06 17:13:12 +0100 | [diff] [blame] | 434 | if (ns_bvci != 0 && ns_bvci != 1) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 435 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) BVCI=%u is not " |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 436 | "signalling\n", nsvc->nsei, ns_bvci); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 437 | /* FIXME: Send proper error message */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 438 | return -EINVAL; |
| 439 | } |
| 440 | |
| 441 | /* we actually should never see those two for BVCI == 0, but double-check |
| 442 | * just to make sure */ |
| 443 | if (pdu_type == BSSGP_PDUT_UL_UNITDATA || |
| 444 | pdu_type == BSSGP_PDUT_DL_UNITDATA) { |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 445 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) UNITDATA not allowed in " |
| 446 | "signalling\n", nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 447 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 451 | |
| 452 | switch (pdu_type) { |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 453 | case BSSGP_PDUT_BVC_RESET: |
| 454 | rc = rx_reset_from_sgsn(msg, &tp, nsvc, ns_bvci); |
| 455 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 456 | case BSSGP_PDUT_FLUSH_LL: |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 457 | case BSSGP_PDUT_BVC_RESET_ACK: |
| 458 | /* simple case: BVCI IE is mandatory */ |
| 459 | if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) |
| 460 | goto err_mand_ie; |
| 461 | bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 462 | rc = gbprox_relay2bvci(msg, bvci, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 463 | break; |
| 464 | case BSSGP_PDUT_PAGING_PS: |
| 465 | case BSSGP_PDUT_PAGING_CS: |
| 466 | /* process the paging request (LAC/RAC lookup) */ |
| 467 | rc = gbprox_rx_paging(msg, &tp, nsvc, ns_bvci); |
| 468 | break; |
| 469 | case BSSGP_PDUT_STATUS: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 470 | /* Some exception has occurred */ |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 471 | LOGP(DGPRS, LOGL_NOTICE, |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 472 | "NSEI=%u(SGSN) BSSGP STATUS ", nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 473 | if (!TLVP_PRESENT(&tp, BSSGP_IE_CAUSE)) { |
| 474 | LOGPC(DGPRS, LOGL_NOTICE, "\n"); |
| 475 | goto err_mand_ie; |
| 476 | } |
| 477 | LOGPC(DGPRS, LOGL_NOTICE, |
| 478 | "cause=0x%02x(%s) ", *TLVP_VAL(&tp, BSSGP_IE_CAUSE), |
| 479 | bssgp_cause_str(*TLVP_VAL(&tp, BSSGP_IE_CAUSE))); |
| 480 | if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 481 | uint16_t *bvci = (uint16_t *) |
| 482 | TLVP_VAL(&tp, BSSGP_IE_BVCI); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 483 | LOGPC(DGPRS, LOGL_NOTICE, |
| 484 | "BVCI=%u\n", ntohs(*bvci)); |
| 485 | } else |
| 486 | LOGPC(DGPRS, LOGL_NOTICE, "\n"); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 487 | break; |
| 488 | /* those only exist in the SGSN -> BSS direction */ |
| 489 | case BSSGP_PDUT_SUSPEND_ACK: |
| 490 | case BSSGP_PDUT_SUSPEND_NACK: |
| 491 | case BSSGP_PDUT_RESUME_ACK: |
| 492 | case BSSGP_PDUT_RESUME_NACK: |
| 493 | /* RAC IE is mandatory */ |
| 494 | if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) |
| 495 | goto err_mand_ie; |
| 496 | peer = peer_by_rac(TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA)); |
| 497 | if (!peer) |
| 498 | goto err_no_peer; |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 499 | rc = gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 500 | break; |
Harald Welte | 36f98d9 | 2011-02-06 13:09:29 +0100 | [diff] [blame] | 501 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 502 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
| 503 | if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) |
| 504 | goto err_mand_ie; |
| 505 | bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
| 506 | if (bvci == 0) { |
| 507 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) BSSGP " |
| 508 | "%sBLOCK_ACK for signalling BVCI ?!?\n", nsvc->nsei, |
| 509 | pdu_type == BSSGP_PDUT_BVC_UNBLOCK_ACK ? "UN":""); |
| 510 | /* should we send STATUS ? */ |
| 511 | } else { |
| 512 | /* Mark BVC as (un)blocked */ |
| 513 | block_unblock_peer(bvci, pdu_type); |
| 514 | } |
| 515 | rc = gbprox_relay2bvci(msg, bvci, ns_bvci); |
| 516 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 517 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 518 | LOGP(DGPRS, LOGL_ERROR, |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 519 | "NSEI=%u(SGSN) BSSGP INVOKE TRACE not supported\n",nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 520 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 521 | break; |
| 522 | default: |
Harald Welte | 72953b8 | 2010-05-12 00:20:41 +0200 | [diff] [blame] | 523 | LOGP(DGPRS, LOGL_NOTICE, "BSSGP PDU type 0x%02x unknown\n", |
| 524 | pdu_type); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 525 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 526 | break; |
| 527 | } |
| 528 | |
| 529 | return rc; |
| 530 | err_mand_ie: |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 531 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) missing mandatory IE\n", |
| 532 | nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 533 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 534 | err_no_peer: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 535 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) cannot find peer based on RAC\n", |
| 536 | nsvc->nsei); |
| 537 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | /* Main input function for Gb proxy */ |
| 541 | int gbprox_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 542 | { |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 543 | int rc; |
Harald Welte | 36f98d9 | 2011-02-06 13:09:29 +0100 | [diff] [blame] | 544 | struct gbprox_peer *peer; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 545 | |
| 546 | /* Only BVCI=0 messages need special treatment */ |
| 547 | if (ns_bvci == 0 || ns_bvci == 1) { |
| 548 | if (nsvc->remote_end_is_sgsn) |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 549 | rc = gbprox_rx_sig_from_sgsn(msg, nsvc, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 550 | else |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 551 | rc = gbprox_rx_sig_from_bss(msg, nsvc, ns_bvci); |
| 552 | } else { |
| 553 | /* All other BVCI are PTP and thus can be simply forwarded */ |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 554 | if (!nsvc->remote_end_is_sgsn) { |
Harald Welte | 36f98d9 | 2011-02-06 13:09:29 +0100 | [diff] [blame] | 555 | return gbprox_relay2sgsn(msg, ns_bvci); |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 556 | } |
Harald Welte | 36f98d9 | 2011-02-06 13:09:29 +0100 | [diff] [blame] | 557 | /* else: SGSN -> BSS direction */ |
| 558 | peer = peer_by_bvci(ns_bvci); |
| 559 | if (!peer) { |
| 560 | LOGP(DGPRS, LOGL_INFO, "Allocationg new peer for " |
| 561 | "BVCI=%u via NSVC=%u/NSEI=%u\n", ns_bvci, |
| 562 | nsvc->nsvci, nsvc->nsei); |
| 563 | peer = peer_alloc(ns_bvci); |
| 564 | peer->nsvc = nsvc; |
| 565 | } |
| 566 | if (peer->blocked) { |
| 567 | LOGP(DGPRS, LOGL_NOTICE, "Dropping PDU for " |
| 568 | "blocked BVCI=%u via NSVC=%u/NSEI=%u\n", |
| 569 | ns_bvci, nsvc->nsvci, nsvc->nsei); |
| 570 | return bssgp_tx_status(BSSGP_CAUSE_BVCI_BLOCKED, NULL, msg); |
| 571 | } |
| 572 | rc = gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 573 | } |
| 574 | |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 575 | return rc; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 576 | } |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 577 | |
Harald Welte | 1ccbf44 | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 578 | int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi) |
| 579 | { |
| 580 | struct gprs_nsvc *nsvc; |
| 581 | |
| 582 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
| 583 | if (!nsvc->persistent) |
| 584 | continue; |
| 585 | gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 586 | } |
| 587 | return 0; |
| 588 | } |
| 589 | |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 590 | /* Signal handler for signals from NS layer */ |
| 591 | int gbprox_signal(unsigned int subsys, unsigned int signal, |
| 592 | void *handler_data, void *signal_data) |
| 593 | { |
| 594 | struct ns_signal_data *nssd = signal_data; |
| 595 | struct gprs_nsvc *nsvc = nssd->nsvc; |
| 596 | struct gbprox_peer *peer; |
| 597 | |
| 598 | if (subsys != SS_NS) |
| 599 | return 0; |
| 600 | |
Harald Welte | f69c059 | 2010-05-11 18:29:44 +0200 | [diff] [blame] | 601 | if (signal == S_NS_RESET && nsvc->nsei == gbcfg.nsip_sgsn_nsei) { |
| 602 | /* We have received a NS-RESET from the NSEI and NSVC |
| 603 | * of the SGSN. This might happen with SGSN that start |
| 604 | * their own NS-RESET procedure without waiting for our |
| 605 | * NS-RESET */ |
| 606 | nsvc->remote_end_is_sgsn = 1; |
| 607 | } |
| 608 | |
Harald Welte | b778d2c | 2010-05-12 13:28:25 +0000 | [diff] [blame] | 609 | if (signal == S_NS_ALIVE_EXP && nsvc->remote_end_is_sgsn) { |
| 610 | LOGP(DGPRS, LOGL_NOTICE, "Tns alive expired too often, " |
| 611 | "re-starting RESET procedure\n"); |
| 612 | nsip_connect(nsvc->nsi, &nsvc->ip.bts_addr, nsvc->nsei, |
| 613 | nsvc->nsvci); |
| 614 | } |
| 615 | |
Harald Welte | 5e106d7 | 2011-02-06 16:33:29 +0100 | [diff] [blame] | 616 | if (!nsvc->remote_end_is_sgsn) { |
| 617 | /* from BSS to SGSN */ |
| 618 | peer = peer_by_nsvc(nsvc); |
| 619 | if (!peer) { |
| 620 | LOGP(DGPRS, LOGL_NOTICE, "signal %u for unknown peer " |
| 621 | "NSEI=%u/NSVCI=%u\n", signal, nsvc->nsei, |
| 622 | nsvc->nsvci); |
| 623 | return 0; |
| 624 | } |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 625 | switch (signal) { |
| 626 | case S_NS_RESET: |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 627 | case S_NS_BLOCK: |
Harald Welte | 5e106d7 | 2011-02-06 16:33:29 +0100 | [diff] [blame] | 628 | if (!peer->blocked) |
| 629 | break; |
| 630 | LOGP(DGPRS, LOGL_NOTICE, "Converting NS_RESET from " |
| 631 | "NSEI=%u/NSVCI=%u into BSSGP_BVC_BLOCK to SGSN\n", |
| 632 | nsvc->nsei, nsvc->nsvci); |
| 633 | bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_BLOCK, nsvc->nsei, |
| 634 | peer->bvci, 0); |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 635 | break; |
Harald Welte | 5e106d7 | 2011-02-06 16:33:29 +0100 | [diff] [blame] | 636 | } |
| 637 | } else { |
| 638 | /* iterate over all BTS peers and send the respective PDU */ |
| 639 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 640 | switch (signal) { |
| 641 | case S_NS_RESET: |
| 642 | gprs_ns_tx_reset(peer->nsvc, nssd->cause); |
| 643 | break; |
| 644 | case S_NS_BLOCK: |
| 645 | gprs_ns_tx_block(peer->nsvc, nssd->cause); |
| 646 | break; |
| 647 | case S_NS_UNBLOCK: |
| 648 | gprs_ns_tx_unblock(peer->nsvc); |
| 649 | break; |
| 650 | } |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 656 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 657 | #include <osmocom/vty/command.h> |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 658 | |
| 659 | gDEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy", |
| 660 | SHOW_STR "Display information about the Gb proxy") |
| 661 | { |
| 662 | struct gbprox_peer *peer; |
| 663 | |
| 664 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 665 | struct gprs_nsvc *nsvc = peer->nsvc; |
| 666 | struct gprs_ra_id raid; |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 667 | gsm48_parse_ra(&raid, peer->ra); |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 668 | |
Harald Welte | 268bed0 | 2010-05-19 17:42:20 +0200 | [diff] [blame] | 669 | vty_out(vty, "NSEI %5u, NS-VC %5u, PTP-BVCI %5u, " |
Harald Welte | 7570c21 | 2010-05-19 17:06:16 +0200 | [diff] [blame] | 670 | "RAC %u-%u-%u-%u", |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 671 | nsvc->nsei, nsvc->nsvci, peer->bvci, |
Harald Welte | 7570c21 | 2010-05-19 17:06:16 +0200 | [diff] [blame] | 672 | raid.mcc, raid.mnc, raid.lac, raid.rac); |
| 673 | if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE) |
Harald Welte | f3956cb | 2011-02-06 17:44:14 +0100 | [diff] [blame] | 674 | vty_out(vty, " %s:%u", |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 675 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
Harald Welte | f3956cb | 2011-02-06 17:44:14 +0100 | [diff] [blame] | 676 | ntohs(nsvc->ip.bts_addr.sin_port)); |
| 677 | if (peer->blocked) |
| 678 | vty_out(vty, " [BVC-BLOCKED]"); |
| 679 | |
| 680 | vty_out(vty, "%s", VTY_NEWLINE); |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 681 | } |
| 682 | return CMD_SUCCESS; |
| 683 | } |