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> |
| 30 | #include <sys/types.h> |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 31 | #include <arpa/inet.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 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 | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 40 | #include <openbsc/gb_proxy.h> |
Harald Welte | 9f75c35 | 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 | 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 | |
| 152 | new_cb->bssgp_cell_id = old_cb->bssgp_cell_id; |
| 153 | new_cb->nsei = old_cb->nsei; |
| 154 | new_cb->bvci = old_cb->bvci; |
| 155 | new_cb->tlli = old_cb->tlli; |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 156 | |
| 157 | return new_msg; |
| 158 | } |
| 159 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 160 | /* strip off the NS header */ |
| 161 | static void strip_ns_hdr(struct msgb *msg) |
| 162 | { |
| 163 | int strip_len = msgb_bssgph(msg) - msg->data; |
| 164 | msgb_pull(msg, strip_len); |
| 165 | } |
| 166 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 167 | /* feed a message down the NS-VC associated with the specified peer */ |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 168 | static int gbprox_relay2sgsn(struct msgb *old_msg, uint16_t ns_bvci) |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 169 | { |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 170 | /* create a copy of the message so the old one can |
| 171 | * be free()d safely when we return from gbprox_rcvmsg() */ |
| 172 | struct msgb *msg = msgb_copy(old_msg, "msgb_relay2sgsn"); |
| 173 | |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 174 | 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] | 175 | msgb_nsei(msg), ns_bvci, gbcfg.nsip_sgsn_nsei); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 176 | |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 177 | msgb_bvci(msg) = ns_bvci; |
| 178 | msgb_nsei(msg) = gbcfg.nsip_sgsn_nsei; |
| 179 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 180 | strip_ns_hdr(msg); |
| 181 | |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 182 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 185 | /* feed a message down the NS-VC associated with the specified peer */ |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 186 | static int gbprox_relay2peer(struct msgb *old_msg, struct gbprox_peer *peer, |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 187 | uint16_t ns_bvci) |
| 188 | { |
Harald Welte | 39d0bb5 | 2010-05-12 18:10:25 +0000 | [diff] [blame] | 189 | /* create a copy of the message so the old one can |
| 190 | * be free()d safely when we return from gbprox_rcvmsg() */ |
| 191 | struct msgb *msg = msgb_copy(old_msg, "msgb_relay2peer"); |
| 192 | |
Harald Welte | 0ab535b | 2010-05-13 10:34:56 +0200 | [diff] [blame] | 193 | 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] | 194 | msgb_nsei(msg), ns_bvci, peer->nsvc->nsei); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 195 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 196 | msgb_bvci(msg) = ns_bvci; |
| 197 | msgb_nsei(msg) = peer->nsvc->nsei; |
| 198 | |
Harald Welte | 0ab535b | 2010-05-13 10:34:56 +0200 | [diff] [blame] | 199 | /* 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] | 200 | strip_ns_hdr(msg); |
| 201 | |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 202 | return gprs_ns_sendmsg(bssgp_nsi, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /* Send a message to a peer identified by ptp_bvci but using ns_bvci |
| 206 | * in the NS hdr */ |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 207 | static int gbprox_relay2bvci(struct msgb *msg, uint16_t ptp_bvci, |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 208 | uint16_t ns_bvci) |
| 209 | { |
| 210 | struct gbprox_peer *peer; |
| 211 | |
| 212 | peer = peer_by_bvci(ptp_bvci); |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 213 | if (!peer) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 214 | LOGP(DGPRS, LOGL_ERROR, "BVCI=%u: Cannot find BSS\n", |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 215 | ptp_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 216 | return -ENOENT; |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 217 | } |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 218 | |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 219 | return gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* Receive an incoming signalling message from a BSS-side NS-VC */ |
| 223 | static int gbprox_rx_sig_from_bss(struct msgb *msg, struct gprs_nsvc *nsvc, |
| 224 | uint16_t ns_bvci) |
| 225 | { |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 226 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 227 | struct tlv_parsed tp; |
| 228 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 229 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 230 | struct gbprox_peer *from_peer; |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 231 | struct gprs_ra_id raid; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 232 | |
| 233 | if (ns_bvci != 0) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 234 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u BVCI=%u is not signalling\n", |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 235 | nsvc->nsei, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 236 | return -EINVAL; |
| 237 | } |
| 238 | |
| 239 | /* we actually should never see those two for BVCI == 0, but double-check |
| 240 | * just to make sure */ |
| 241 | if (pdu_type == BSSGP_PDUT_UL_UNITDATA || |
| 242 | pdu_type == BSSGP_PDUT_DL_UNITDATA) { |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 243 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u UNITDATA not allowed in " |
| 244 | "signalling\n", nsvc->nsei); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 245 | return -EINVAL; |
| 246 | } |
| 247 | |
| 248 | bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 249 | |
| 250 | switch (pdu_type) { |
| 251 | case BSSGP_PDUT_SUSPEND: |
| 252 | case BSSGP_PDUT_RESUME: |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 253 | /* We implement RAC snooping during SUSPEND/RESUME, since |
| 254 | * it establishes a relationsip between BVCI/peer and the |
| 255 | * routeing area code. The snooped information is then |
| 256 | * used for routing the {SUSPEND,RESUME}_[N]ACK back to |
| 257 | * the correct BSSGP */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 258 | if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) |
| 259 | goto err_mand_ie; |
| 260 | from_peer = peer_by_nsvc(nsvc); |
| 261 | if (!from_peer) |
| 262 | goto err_no_peer; |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 263 | memcpy(from_peer->ra, TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA), |
| 264 | sizeof(from_peer->ra)); |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 265 | gsm48_parse_ra(&raid, from_peer->ra); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 266 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u BSSGP SUSPEND/RESUME " |
| 267 | "RAC snooping: RAC %u-%u-%u-%u behind BVCI=%u, " |
| 268 | "NSVCI=%u\n",nsvc->nsei, raid.mcc, raid.mnc, raid.lac, |
| 269 | raid.rac , from_peer->bvci, nsvc->nsvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 270 | /* FIXME: This only supports one BSS per RA */ |
| 271 | break; |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 272 | case BSSGP_PDUT_BVC_RESET: |
| 273 | /* If we receive a BVC reset on the signalling endpoint, we |
| 274 | * don't want the SGSN to reset, as the signalling endpoint |
| 275 | * is common for all point-to-point BVCs (and thus all BTS) */ |
| 276 | if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { |
| 277 | uint16_t bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 72953b8 | 2010-05-12 00:20:41 +0200 | [diff] [blame] | 278 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u Rx BVC RESET (BVCI=%u)\n", |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 279 | nsvc->nsei, bvci); |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 280 | if (bvci == 0) { |
| 281 | /* FIXME: only do this if SGSN is alive! */ |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 282 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u Tx fake " |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 283 | "BVC RESET ACK of BVCI=0\n", nsvc->nsei); |
| 284 | return bssgp_tx_simple_bvci(BSSGP_PDUT_BVC_RESET_ACK, |
| 285 | nsvc->nsei, 0, ns_bvci); |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 286 | } |
| 287 | from_peer = peer_by_bvci(bvci); |
| 288 | if (!from_peer) { |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 289 | /* if a PTP-BVC is reset, and we don't know that |
| 290 | * PTP-BVCI yet, we should allocate a new peer */ |
| 291 | LOGP(DGPRS, LOGL_INFO, "Allocationg new peer for " |
| 292 | "BVCI=%u via NSVCI=%u/NSEI=%u\n", bvci, |
| 293 | nsvc->nsvci, nsvc->nsei); |
| 294 | from_peer = peer_alloc(bvci); |
| 295 | from_peer->nsvc = nsvc; |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 296 | } |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 297 | if (TLVP_PRESENT(&tp, BSSGP_IE_CELL_ID)) { |
| 298 | struct gprs_ra_id raid; |
| 299 | /* We have a Cell Identifier present in this |
| 300 | * PDU, this means we can extend our local |
| 301 | * state information about this particular cell |
| 302 | * */ |
| 303 | memcpy(from_peer->ra, |
| 304 | TLVP_VAL(&tp, BSSGP_IE_CELL_ID), |
| 305 | sizeof(from_peer->ra)); |
| 306 | gsm48_parse_ra(&raid, from_peer->ra); |
| 307 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u/BVCI=%u " |
Harald Welte | 72953b8 | 2010-05-12 00:20:41 +0200 | [diff] [blame] | 308 | "Cell ID %u-%u-%u-%u\n", nsvc->nsei, |
Harald Welte | 1174c08 | 2010-05-12 00:07:29 +0200 | [diff] [blame] | 309 | bvci, raid.mcc, raid.mnc, raid.lac, |
| 310 | raid.rac); |
| 311 | } |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 312 | } |
| 313 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 314 | } |
| 315 | |
Harald Welte | e9ea269 | 2010-05-11 20:20:13 +0200 | [diff] [blame] | 316 | /* Normally, we can simply pass on all signalling messages from BSS to |
| 317 | * SGSN */ |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 318 | return gbprox_relay2sgsn(msg, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 319 | err_no_peer: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 320 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(BSS) cannot find peer based on RAC\n", |
| 321 | nsvc->nsei); |
| 322 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 323 | err_mand_ie: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 324 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(BSS) missing mandatory RA IE\n", |
| 325 | nsvc->nsei); |
| 326 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* Receive paging request from SGSN, we need to relay to proper BSS */ |
| 330 | static int gbprox_rx_paging(struct msgb *msg, struct tlv_parsed *tp, |
| 331 | struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 332 | { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 333 | struct gbprox_peer *peer = NULL; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 334 | |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 335 | LOGP(DGPRS, LOGL_INFO, "NSEI=%u(SGSN) BSSGP PAGING ", |
| 336 | nsvc->nsei); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 337 | if (TLVP_PRESENT(tp, BSSGP_IE_BVCI)) { |
| 338 | uint16_t bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 339 | LOGPC(DGPRS, LOGL_INFO, "routing by BVCI to peer BVCI=%u\n", |
| 340 | bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 341 | } else if (TLVP_PRESENT(tp, BSSGP_IE_ROUTEING_AREA)) { |
| 342 | peer = peer_by_rac(TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA)); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 343 | 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] | 344 | peer ? peer->bvci : -1); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 345 | } else if (TLVP_PRESENT(tp, BSSGP_IE_LOCATION_AREA)) { |
| 346 | peer = peer_by_lac(TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA)); |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 347 | 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] | 348 | peer ? peer->bvci : -1); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 349 | } else |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 350 | LOGPC(DGPRS, LOGL_INFO, "\n"); |
| 351 | |
| 352 | if (!peer) { |
| 353 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) BSSGP PAGING: " |
| 354 | "unable to route, missing IE\n", nsvc->nsei); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 355 | return -EINVAL; |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 356 | } |
| 357 | return gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 360 | /* Receive an incoming BVC-RESET message from the SGSN */ |
| 361 | static int rx_reset_from_sgsn(struct msgb *msg, struct tlv_parsed *tp, |
| 362 | struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 363 | { |
| 364 | struct gbprox_peer *peer; |
| 365 | uint16_t ptp_bvci; |
| 366 | |
| 367 | if (!TLVP_PRESENT(tp, BSSGP_IE_BVCI)) { |
| 368 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, |
| 369 | NULL, msg); |
| 370 | } |
| 371 | ptp_bvci = ntohs(*(uint16_t *)TLVP_VAL(tp, BSSGP_IE_BVCI)); |
| 372 | |
| 373 | if (ptp_bvci >= 2) { |
| 374 | /* A reset for a PTP BVC was received, forward it to its |
| 375 | * respective peer */ |
| 376 | peer = peer_by_bvci(ptp_bvci); |
| 377 | if (!peer) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 378 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u BVCI=%u: Cannot find BSS\n", |
| 379 | nsvc->nsei, ptp_bvci); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 380 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, |
| 381 | NULL, msg); |
| 382 | } |
| 383 | return gbprox_relay2peer(msg, peer, ns_bvci); |
| 384 | } |
| 385 | |
| 386 | /* A reset for the Signalling entity has been received |
| 387 | * from the SGSN. As the signalling BVCI is shared |
| 388 | * among all the BSS's that we multiplex, it needs to |
| 389 | * be relayed */ |
| 390 | llist_for_each_entry(peer, &gbprox_bts_peers, list) |
| 391 | gbprox_relay2peer(msg, peer, ns_bvci); |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 396 | /* Receive an incoming signalling message from the SGSN-side NS-VC */ |
| 397 | static int gbprox_rx_sig_from_sgsn(struct msgb *msg, struct gprs_nsvc *nsvc, |
| 398 | uint16_t ns_bvci) |
| 399 | { |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 400 | struct bssgp_normal_hdr *bgph = (struct bssgp_normal_hdr *) msgb_bssgph(msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 401 | struct tlv_parsed tp; |
| 402 | uint8_t pdu_type = bgph->pdu_type; |
Harald Welte | ca3620a | 2010-05-03 16:30:59 +0200 | [diff] [blame] | 403 | int data_len = msgb_bssgp_len(msg) - sizeof(*bgph); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 404 | struct gbprox_peer *peer; |
| 405 | uint16_t bvci; |
| 406 | int rc = 0; |
| 407 | |
| 408 | if (ns_bvci != 0) { |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 409 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) BVCI=%u is not " |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 410 | "signalling\n", nsvc->nsei, ns_bvci); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 411 | /* FIXME: Send proper error message */ |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 412 | return -EINVAL; |
| 413 | } |
| 414 | |
| 415 | /* we actually should never see those two for BVCI == 0, but double-check |
| 416 | * just to make sure */ |
| 417 | if (pdu_type == BSSGP_PDUT_UL_UNITDATA || |
| 418 | pdu_type == BSSGP_PDUT_DL_UNITDATA) { |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 419 | LOGP(DGPRS, LOGL_NOTICE, "NSEI=%u(SGSN) UNITDATA not allowed in " |
| 420 | "signalling\n", nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 421 | return bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | rc = bssgp_tlv_parse(&tp, bgph->data, data_len); |
| 425 | |
| 426 | switch (pdu_type) { |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 427 | case BSSGP_PDUT_BVC_RESET: |
| 428 | rc = rx_reset_from_sgsn(msg, &tp, nsvc, ns_bvci); |
| 429 | break; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 430 | case BSSGP_PDUT_FLUSH_LL: |
| 431 | case BSSGP_PDUT_BVC_BLOCK_ACK: |
| 432 | case BSSGP_PDUT_BVC_UNBLOCK_ACK: |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 433 | case BSSGP_PDUT_BVC_RESET_ACK: |
| 434 | /* simple case: BVCI IE is mandatory */ |
| 435 | if (!TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) |
| 436 | goto err_mand_ie; |
| 437 | bvci = ntohs(*(uint16_t *)TLVP_VAL(&tp, BSSGP_IE_BVCI)); |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 438 | rc = gbprox_relay2bvci(msg, bvci, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 439 | break; |
| 440 | case BSSGP_PDUT_PAGING_PS: |
| 441 | case BSSGP_PDUT_PAGING_CS: |
| 442 | /* process the paging request (LAC/RAC lookup) */ |
| 443 | rc = gbprox_rx_paging(msg, &tp, nsvc, ns_bvci); |
| 444 | break; |
| 445 | case BSSGP_PDUT_STATUS: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 446 | /* Some exception has occurred */ |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 447 | LOGP(DGPRS, LOGL_NOTICE, |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 448 | "NSEI=%u(SGSN) BSSGP STATUS ", nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 449 | if (!TLVP_PRESENT(&tp, BSSGP_IE_CAUSE)) { |
| 450 | LOGPC(DGPRS, LOGL_NOTICE, "\n"); |
| 451 | goto err_mand_ie; |
| 452 | } |
| 453 | LOGPC(DGPRS, LOGL_NOTICE, |
| 454 | "cause=0x%02x(%s) ", *TLVP_VAL(&tp, BSSGP_IE_CAUSE), |
| 455 | bssgp_cause_str(*TLVP_VAL(&tp, BSSGP_IE_CAUSE))); |
| 456 | if (TLVP_PRESENT(&tp, BSSGP_IE_BVCI)) { |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 457 | uint16_t *bvci = (uint16_t *) |
| 458 | TLVP_VAL(&tp, BSSGP_IE_BVCI); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 459 | LOGPC(DGPRS, LOGL_NOTICE, |
| 460 | "BVCI=%u\n", ntohs(*bvci)); |
| 461 | } else |
| 462 | LOGPC(DGPRS, LOGL_NOTICE, "\n"); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 463 | break; |
| 464 | /* those only exist in the SGSN -> BSS direction */ |
| 465 | case BSSGP_PDUT_SUSPEND_ACK: |
| 466 | case BSSGP_PDUT_SUSPEND_NACK: |
| 467 | case BSSGP_PDUT_RESUME_ACK: |
| 468 | case BSSGP_PDUT_RESUME_NACK: |
| 469 | /* RAC IE is mandatory */ |
| 470 | if (!TLVP_PRESENT(&tp, BSSGP_IE_ROUTEING_AREA)) |
| 471 | goto err_mand_ie; |
| 472 | peer = peer_by_rac(TLVP_VAL(&tp, BSSGP_IE_ROUTEING_AREA)); |
| 473 | if (!peer) |
| 474 | goto err_no_peer; |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 475 | rc = gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 476 | break; |
| 477 | case BSSGP_PDUT_SGSN_INVOKE_TRACE: |
Harald Welte | 44c4830 | 2010-05-03 19:22:32 +0200 | [diff] [blame] | 478 | LOGP(DGPRS, LOGL_ERROR, |
Harald Welte | 4cf12e9 | 2010-05-13 14:14:56 +0200 | [diff] [blame] | 479 | "NSEI=%u(SGSN) BSSGP INVOKE TRACE not supported\n",nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 480 | rc = bssgp_tx_status(BSSGP_CAUSE_PDU_INCOMP_FEAT, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 481 | break; |
| 482 | default: |
Harald Welte | 72953b8 | 2010-05-12 00:20:41 +0200 | [diff] [blame] | 483 | LOGP(DGPRS, LOGL_NOTICE, "BSSGP PDU type 0x%02x unknown\n", |
| 484 | pdu_type); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 485 | rc = bssgp_tx_status(BSSGP_CAUSE_PROTO_ERR_UNSPEC, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 486 | break; |
| 487 | } |
| 488 | |
| 489 | return rc; |
| 490 | err_mand_ie: |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 491 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) missing mandatory IE\n", |
| 492 | nsvc->nsei); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 493 | return bssgp_tx_status(BSSGP_CAUSE_MISSING_MAND_IE, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 494 | err_no_peer: |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 495 | LOGP(DGPRS, LOGL_ERROR, "NSEI=%u(SGSN) cannot find peer based on RAC\n", |
| 496 | nsvc->nsei); |
| 497 | return bssgp_tx_status(BSSGP_CAUSE_UNKNOWN_BVCI, NULL, msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | /* Main input function for Gb proxy */ |
| 501 | int gbprox_rcvmsg(struct msgb *msg, struct gprs_nsvc *nsvc, uint16_t ns_bvci) |
| 502 | { |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 503 | int rc; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 504 | |
| 505 | /* Only BVCI=0 messages need special treatment */ |
| 506 | if (ns_bvci == 0 || ns_bvci == 1) { |
| 507 | if (nsvc->remote_end_is_sgsn) |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 508 | rc = gbprox_rx_sig_from_sgsn(msg, nsvc, ns_bvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 509 | else |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 510 | rc = gbprox_rx_sig_from_bss(msg, nsvc, ns_bvci); |
| 511 | } else { |
| 512 | /* All other BVCI are PTP and thus can be simply forwarded */ |
Harald Welte | 1c77c6e | 2010-05-03 21:37:11 +0200 | [diff] [blame] | 513 | if (!nsvc->remote_end_is_sgsn) { |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 514 | rc = gbprox_relay2sgsn(msg, ns_bvci); |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 515 | } else { |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 516 | struct gbprox_peer *peer = peer_by_bvci(ns_bvci); |
| 517 | if (!peer) { |
Harald Welte | 72953b8 | 2010-05-12 00:20:41 +0200 | [diff] [blame] | 518 | LOGP(DGPRS, LOGL_INFO, "Allocationg new peer for " |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 519 | "BVCI=%u via NSVC=%u/NSEI=%u\n", ns_bvci, |
| 520 | nsvc->nsvci, nsvc->nsei); |
| 521 | peer = peer_alloc(ns_bvci); |
| 522 | peer->nsvc = nsvc; |
| 523 | } |
Harald Welte | 69619e3 | 2010-05-03 19:05:10 +0200 | [diff] [blame] | 524 | rc = gbprox_relay2peer(msg, peer, ns_bvci); |
Harald Welte | 70f38d2 | 2010-05-01 12:10:57 +0200 | [diff] [blame] | 525 | } |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Harald Welte | 672f5c4 | 2010-05-03 18:54:58 +0200 | [diff] [blame] | 528 | return rc; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 529 | } |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 530 | |
Harald Welte | 1ccbf44 | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 531 | int gbprox_reset_persistent_nsvcs(struct gprs_ns_inst *nsi) |
| 532 | { |
| 533 | struct gprs_nsvc *nsvc; |
| 534 | |
| 535 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
| 536 | if (!nsvc->persistent) |
| 537 | continue; |
| 538 | gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 539 | } |
| 540 | return 0; |
| 541 | } |
| 542 | |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 543 | /* Signal handler for signals from NS layer */ |
| 544 | int gbprox_signal(unsigned int subsys, unsigned int signal, |
| 545 | void *handler_data, void *signal_data) |
| 546 | { |
| 547 | struct ns_signal_data *nssd = signal_data; |
| 548 | struct gprs_nsvc *nsvc = nssd->nsvc; |
| 549 | struct gbprox_peer *peer; |
| 550 | |
| 551 | if (subsys != SS_NS) |
| 552 | return 0; |
| 553 | |
Harald Welte | f69c059 | 2010-05-11 18:29:44 +0200 | [diff] [blame] | 554 | if (signal == S_NS_RESET && nsvc->nsei == gbcfg.nsip_sgsn_nsei) { |
| 555 | /* We have received a NS-RESET from the NSEI and NSVC |
| 556 | * of the SGSN. This might happen with SGSN that start |
| 557 | * their own NS-RESET procedure without waiting for our |
| 558 | * NS-RESET */ |
| 559 | nsvc->remote_end_is_sgsn = 1; |
| 560 | } |
| 561 | |
Harald Welte | b778d2c | 2010-05-12 13:28:25 +0000 | [diff] [blame] | 562 | if (signal == S_NS_ALIVE_EXP && nsvc->remote_end_is_sgsn) { |
| 563 | LOGP(DGPRS, LOGL_NOTICE, "Tns alive expired too often, " |
| 564 | "re-starting RESET procedure\n"); |
| 565 | nsip_connect(nsvc->nsi, &nsvc->ip.bts_addr, nsvc->nsei, |
| 566 | nsvc->nsvci); |
| 567 | } |
| 568 | |
Harald Welte | c1c1dd2 | 2010-05-11 06:34:24 +0200 | [diff] [blame] | 569 | /* We currently only care about signals from the SGSN */ |
| 570 | if (!nsvc->remote_end_is_sgsn) |
| 571 | return 0; |
| 572 | |
| 573 | /* iterate over all BTS peers and send the respective PDU */ |
| 574 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 575 | switch (signal) { |
| 576 | case S_NS_RESET: |
| 577 | gprs_ns_tx_reset(peer->nsvc, nssd->cause); |
| 578 | break; |
| 579 | case S_NS_BLOCK: |
| 580 | gprs_ns_tx_block(peer->nsvc, nssd->cause); |
| 581 | break; |
| 582 | case S_NS_UNBLOCK: |
| 583 | gprs_ns_tx_unblock(peer->nsvc); |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | return 0; |
| 588 | } |
| 589 | |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 590 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 591 | #include <osmocom/vty/command.h> |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 592 | |
| 593 | gDEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy", |
| 594 | SHOW_STR "Display information about the Gb proxy") |
| 595 | { |
| 596 | struct gbprox_peer *peer; |
| 597 | |
| 598 | llist_for_each_entry(peer, &gbprox_bts_peers, list) { |
| 599 | struct gprs_nsvc *nsvc = peer->nsvc; |
| 600 | struct gprs_ra_id raid; |
Harald Welte | 7fc9822 | 2010-05-11 10:15:42 +0200 | [diff] [blame] | 601 | gsm48_parse_ra(&raid, peer->ra); |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 602 | |
Harald Welte | 268bed0 | 2010-05-19 17:42:20 +0200 | [diff] [blame] | 603 | vty_out(vty, "NSEI %5u, NS-VC %5u, PTP-BVCI %5u, " |
Harald Welte | 7570c21 | 2010-05-19 17:06:16 +0200 | [diff] [blame] | 604 | "RAC %u-%u-%u-%u", |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 605 | nsvc->nsei, nsvc->nsvci, peer->bvci, |
Harald Welte | 7570c21 | 2010-05-19 17:06:16 +0200 | [diff] [blame] | 606 | raid.mcc, raid.mnc, raid.lac, raid.rac); |
| 607 | if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE) |
| 608 | vty_out(vty, " %s:%u%s", |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 609 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
| 610 | ntohs(nsvc->ip.bts_addr.sin_port), VTY_NEWLINE); |
Harald Welte | 7570c21 | 2010-05-19 17:06:16 +0200 | [diff] [blame] | 611 | else |
| 612 | vty_out(vty, "%s", VTY_NEWLINE); |
Harald Welte | 85801d0 | 2010-05-11 05:49:43 +0200 | [diff] [blame] | 613 | } |
| 614 | return CMD_SUCCESS; |
| 615 | } |