Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1 | /* OpenBSC Abis input driver for ip.access */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2010 by Holger Hans Peter Freyther |
| 5 | * (C) 2010 by On-Waves |
| 6 | * |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Affero General Public License as published by |
| 11 | * the Free Software Foundation; either version 3 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Affero General Public License |
| 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include "internal.h" |
| 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <unistd.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <errno.h> |
| 30 | #include <string.h> |
| 31 | #include <time.h> |
| 32 | #include <sys/fcntl.h> |
| 33 | #include <sys/socket.h> |
| 34 | #include <sys/ioctl.h> |
| 35 | #include <arpa/inet.h> |
| 36 | |
| 37 | #include <osmocom/core/select.h> |
| 38 | #include <osmocom/gsm/tlv.h> |
| 39 | #include <osmocom/core/msgb.h> |
| 40 | #include <osmocom/core/logging.h> |
| 41 | #include <talloc.h> |
Pablo Neira Ayuso | 177094b | 2011-06-07 12:21:51 +0200 | [diff] [blame] | 42 | #include <osmocom/abis/e1_input.h> |
| 43 | #include <osmocom/abis/ipaccess.h> |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 44 | #include <osmocom/core/socket.h> |
Pablo Neira Ayuso | 0b099b2 | 2011-06-09 13:14:11 +0200 | [diff] [blame] | 45 | #include <osmocom/abis/logging.h> |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 46 | #include <osmocom/abis/ipa.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 47 | |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 48 | static void *tall_ipa_ctx; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 49 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 50 | #define TS1_ALLOC_SIZE 900 |
| 51 | |
| 52 | /* |
| 53 | * Common propietary IPA messages: |
| 54 | * - PONG: in reply to PING. |
| 55 | * - ID_REQUEST: first messages once OML has been established. |
| 56 | * - ID_ACK: in reply to ID_ACK. |
| 57 | */ |
| 58 | const uint8_t ipa_pong_msg[] = { |
| 59 | 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG |
| 60 | }; |
| 61 | |
| 62 | const uint8_t ipa_id_ack_msg[] = { |
| 63 | 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK |
| 64 | }; |
| 65 | |
| 66 | const uint8_t ipa_id_req_msg[] = { |
| 67 | 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET, |
| 68 | 0x01, IPAC_IDTAG_UNIT, |
| 69 | 0x01, IPAC_IDTAG_MACADDR, |
| 70 | 0x01, IPAC_IDTAG_LOCATION1, |
| 71 | 0x01, IPAC_IDTAG_LOCATION2, |
| 72 | 0x01, IPAC_IDTAG_EQUIPVERS, |
| 73 | 0x01, IPAC_IDTAG_SWVERSION, |
| 74 | 0x01, IPAC_IDTAG_UNITNAME, |
| 75 | 0x01, IPAC_IDTAG_SERNR, |
| 76 | }; |
| 77 | |
| 78 | static int ipaccess_send(int fd, const void *msg, size_t msglen) |
| 79 | { |
| 80 | int ret; |
| 81 | |
| 82 | ret = write(fd, msg, msglen); |
| 83 | if (ret < 0) |
| 84 | return ret; |
| 85 | if (ret < msglen) { |
| 86 | LOGP(DINP, LOGL_ERROR, "ipaccess_send: short write\n"); |
| 87 | return -EIO; |
| 88 | } |
| 89 | return ret; |
| 90 | } |
| 91 | |
| 92 | int ipaccess_send_pong(int fd) |
| 93 | { |
| 94 | return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg)); |
| 95 | } |
| 96 | |
| 97 | int ipaccess_send_id_ack(int fd) |
| 98 | { |
| 99 | return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg)); |
| 100 | } |
| 101 | |
| 102 | int ipaccess_send_id_req(int fd) |
| 103 | { |
| 104 | return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg)); |
| 105 | } |
| 106 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 107 | /* base handling of the ip.access protocol */ |
| 108 | int ipaccess_rcvmsg_base(struct msgb *msg, |
| 109 | struct osmo_fd *bfd) |
| 110 | { |
| 111 | uint8_t msg_type = *(msg->l2h); |
| 112 | int ret = 0; |
| 113 | |
| 114 | switch (msg_type) { |
| 115 | case IPAC_MSGT_PING: |
| 116 | ret = ipaccess_send_pong(bfd->fd); |
| 117 | break; |
| 118 | case IPAC_MSGT_PONG: |
| 119 | DEBUGP(DMI, "PONG!\n"); |
| 120 | break; |
| 121 | case IPAC_MSGT_ID_ACK: |
| 122 | DEBUGP(DMI, "ID_ACK? -> ACK!\n"); |
| 123 | ret = ipaccess_send_id_ack(bfd->fd); |
| 124 | break; |
| 125 | } |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, |
| 130 | struct osmo_fd *bfd) |
| 131 | { |
| 132 | uint8_t msg_type = *(msg->l2h); |
| 133 | |
| 134 | /* handle base messages */ |
| 135 | ipaccess_rcvmsg_base(msg, bfd); |
| 136 | |
| 137 | switch (msg_type) { |
| 138 | case IPAC_MSGT_ID_RESP: |
| 139 | DEBUGP(DMI, "ID_RESP\n"); |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 140 | if (!line->ops->sign_link_up) { |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 141 | LOGP(DINP, LOGL_ERROR, "Fix your application, " |
| 142 | "no action set if the signalling link " |
| 143 | "becomes ready\n"); |
| 144 | return -EINVAL; |
| 145 | } |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 146 | line->ops->sign_link_up(msg, line, bfd->priv_nr); |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 147 | break; |
| 148 | } |
| 149 | return 0; |
| 150 | } |
| 151 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 152 | static int handle_ts1_read(struct osmo_fd *bfd) |
| 153 | { |
| 154 | struct e1inp_line *line = bfd->data; |
| 155 | unsigned int ts_nr = bfd->priv_nr; |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 156 | struct e1inp_ts *e1i_ts = NULL; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 157 | struct e1inp_sign_link *link; |
| 158 | struct ipaccess_head *hh; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 159 | struct msgb *msg; |
| 160 | int ret = 0, error; |
| 161 | |
Pablo Neira Ayuso | 7a24940 | 2011-06-21 14:15:46 +0200 | [diff] [blame] | 162 | error = ipa_msg_recv(bfd->fd, &msg); |
| 163 | if (error <= 0) { |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 164 | /* skip if RSL line is not set yet. */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 165 | if (e1i_ts && e1i_ts->line->ops->error) |
| 166 | e1i_ts->line->ops->error(NULL, line, ts_nr, error); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 167 | if (error == 0) { |
| 168 | osmo_fd_unregister(bfd); |
| 169 | close(bfd->fd); |
| 170 | bfd->fd = -1; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 171 | talloc_free(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 172 | } |
| 173 | return error; |
| 174 | } |
| 175 | DEBUGP(DMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); |
| 176 | |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 177 | /* Now that we're sure that we've got a line for socket. */ |
| 178 | e1i_ts = &line->ts[ts_nr-1]; |
| 179 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 180 | hh = (struct ipaccess_head *) msg->data; |
| 181 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 182 | ipaccess_rcvmsg(line, msg, bfd); |
| 183 | msgb_free(msg); |
| 184 | return ret; |
| 185 | } |
| 186 | /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg() |
| 187 | * might have free'd it !!! */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 188 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 189 | link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 190 | if (!link) { |
| 191 | LOGP(DINP, LOGL_ERROR, "no matching signalling link for " |
| 192 | "hh->proto=0x%02x\n", hh->proto); |
| 193 | msgb_free(msg); |
| 194 | return -EIO; |
| 195 | } |
| 196 | msg->dst = link; |
Pablo Neira Ayuso | ff66363 | 2011-06-26 19:10:56 +0200 | [diff] [blame] | 197 | msg->trx = link->trx; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 198 | |
| 199 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 200 | if (!e1i_ts->line->ops->sign_link) { |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 201 | LOGP(DINP, LOGL_ERROR, "Fix your application, " |
| 202 | "no action set for signalling messages.\n"); |
| 203 | return -ENOENT; |
| 204 | } |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 205 | e1i_ts->line->ops->sign_link(msg, line, link); |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 206 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 207 | return ret; |
| 208 | } |
| 209 | |
| 210 | void ipaccess_prepend_header_ext(struct msgb *msg, int proto) |
| 211 | { |
| 212 | struct ipaccess_head_ext *hh_ext; |
| 213 | |
| 214 | /* prepend the osmo ip.access header extension */ |
| 215 | hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext)); |
| 216 | hh_ext->proto = proto; |
| 217 | } |
| 218 | |
| 219 | void ipaccess_prepend_header(struct msgb *msg, int proto) |
| 220 | { |
| 221 | struct ipaccess_head *hh; |
| 222 | |
| 223 | /* prepend the ip.access header */ |
| 224 | hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh)); |
| 225 | hh->len = htons(msg->len - sizeof(*hh)); |
| 226 | hh->proto = proto; |
| 227 | } |
| 228 | |
| 229 | static int ts_want_write(struct e1inp_ts *e1i_ts) |
| 230 | { |
| 231 | e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE; |
| 232 | |
| 233 | return 0; |
| 234 | } |
| 235 | |
| 236 | static void timeout_ts1_write(void *data) |
| 237 | { |
| 238 | struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data; |
| 239 | |
| 240 | /* trigger write of ts1, due to tx delay timer */ |
| 241 | ts_want_write(e1i_ts); |
| 242 | } |
| 243 | |
| 244 | static int handle_ts1_write(struct osmo_fd *bfd) |
| 245 | { |
| 246 | struct e1inp_line *line = bfd->data; |
| 247 | unsigned int ts_nr = bfd->priv_nr; |
| 248 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 249 | struct e1inp_sign_link *sign_link; |
| 250 | struct msgb *msg; |
| 251 | uint8_t proto; |
| 252 | int ret; |
| 253 | |
| 254 | bfd->when &= ~BSC_FD_WRITE; |
| 255 | |
| 256 | /* get the next msg for this timeslot */ |
| 257 | msg = e1inp_tx_ts(e1i_ts, &sign_link); |
| 258 | if (!msg) { |
| 259 | /* no message after tx delay timer */ |
| 260 | return 0; |
| 261 | } |
| 262 | |
| 263 | switch (sign_link->type) { |
| 264 | case E1INP_SIGN_OML: |
| 265 | proto = IPAC_PROTO_OML; |
| 266 | break; |
| 267 | case E1INP_SIGN_RSL: |
| 268 | proto = IPAC_PROTO_RSL; |
| 269 | break; |
| 270 | default: |
| 271 | msgb_free(msg); |
| 272 | bfd->when |= BSC_FD_WRITE; /* come back for more msg */ |
| 273 | return -EINVAL; |
| 274 | } |
| 275 | |
| 276 | msg->l2h = msg->data; |
| 277 | ipaccess_prepend_header(msg, sign_link->tei); |
| 278 | |
| 279 | DEBUGP(DMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); |
| 280 | |
| 281 | ret = send(bfd->fd, msg->data, msg->len, 0); |
| 282 | msgb_free(msg); |
| 283 | |
| 284 | /* set tx delay timer for next event */ |
| 285 | e1i_ts->sign.tx_timer.cb = timeout_ts1_write; |
| 286 | e1i_ts->sign.tx_timer.data = e1i_ts; |
| 287 | |
| 288 | /* Reducing this might break the nanoBTS 900 init. */ |
| 289 | osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); |
| 290 | |
| 291 | return ret; |
| 292 | } |
| 293 | |
| 294 | /* callback from select.c in case one of the fd's can be read/written */ |
| 295 | static int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what) |
| 296 | { |
| 297 | struct e1inp_line *line = bfd->data; |
| 298 | unsigned int ts_nr = bfd->priv_nr; |
| 299 | unsigned int idx = ts_nr-1; |
| 300 | struct e1inp_ts *e1i_ts; |
| 301 | int rc = 0; |
| 302 | |
| 303 | /* In case of early RSL we might not yet have a line */ |
| 304 | |
| 305 | if (line) |
| 306 | e1i_ts = &line->ts[idx]; |
| 307 | |
| 308 | if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) { |
| 309 | if (what & BSC_FD_READ) |
| 310 | rc = handle_ts1_read(bfd); |
| 311 | if (what & BSC_FD_WRITE) |
| 312 | rc = handle_ts1_write(bfd); |
| 313 | } else |
| 314 | LOGP(DINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type); |
| 315 | |
| 316 | return rc; |
| 317 | } |
| 318 | |
Pablo Neira Ayuso | c00ee73 | 2011-06-21 12:22:49 +0200 | [diff] [blame] | 319 | static int ipaccess_line_update(struct e1inp_line *line, |
| 320 | enum e1inp_line_role role, const char *addr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 321 | |
| 322 | struct e1inp_driver ipaccess_driver = { |
| 323 | .name = "ipa", |
| 324 | .want_write = ts_want_write, |
| 325 | .line_update = ipaccess_line_update, |
| 326 | .default_delay = 0, |
| 327 | }; |
| 328 | |
| 329 | /* callback of the OML listening filedescriptor */ |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 330 | static int ipaccess_bsc_oml_cb(struct ipa_server_link *link, int fd) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 331 | { |
| 332 | int ret; |
| 333 | int idx = 0; |
| 334 | int i; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 335 | struct e1inp_line *line = link->line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 336 | struct e1inp_ts *e1i_ts; |
| 337 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 338 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 339 | /* create virrtual E1 timeslots for signalling */ |
| 340 | e1inp_ts_config_sign(&line->ts[1-1], line); |
| 341 | |
| 342 | /* initialize the fds */ |
| 343 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 344 | line->ts[i].driver.ipaccess.fd.fd = -1; |
| 345 | |
| 346 | e1i_ts = &line->ts[idx]; |
| 347 | |
Pablo Neira Ayuso | 93c6201 | 2011-06-26 19:12:47 +0200 | [diff] [blame^] | 348 | bfd = &e1i_ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 349 | bfd->fd = fd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 350 | bfd->data = line; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 351 | bfd->priv_nr = E1INP_SIGN_OML; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 352 | bfd->cb = ipaccess_fd_cb; |
| 353 | bfd->when = BSC_FD_READ; |
| 354 | ret = osmo_fd_register(bfd); |
| 355 | if (ret < 0) { |
| 356 | LOGP(DINP, LOGL_ERROR, "could not register FD\n"); |
| 357 | close(bfd->fd); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 362 | ret = ipaccess_send_id_req(bfd->fd); |
| 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 367 | static int ipaccess_bsc_rsl_cb(struct ipa_server_link *link, int fd) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 368 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 369 | struct osmo_fd *bfd; |
| 370 | int ret; |
| 371 | |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 372 | bfd = talloc_zero(tall_ipa_ctx, struct osmo_fd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 373 | if (!bfd) |
| 374 | return -ENOMEM; |
| 375 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 376 | bfd->fd = fd; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 377 | bfd->priv_nr = E1INP_SIGN_RSL; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 378 | bfd->cb = ipaccess_fd_cb; |
| 379 | bfd->when = BSC_FD_READ; |
| 380 | ret = osmo_fd_register(bfd); |
| 381 | if (ret < 0) { |
| 382 | LOGP(DINP, LOGL_ERROR, "could not register FD\n"); |
| 383 | close(bfd->fd); |
| 384 | talloc_free(bfd); |
| 385 | return ret; |
| 386 | } |
| 387 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 388 | ret = ipaccess_send_id_req(bfd->fd); |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 393 | static int ipaccess_bts_cb(struct ipa_client_link *link, struct msgb *msg) |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 394 | { |
| 395 | struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; |
| 396 | struct e1inp_ts *e1i_ts = NULL; |
| 397 | struct e1inp_sign_link *sign_link; |
| 398 | |
| 399 | /* special handling for IPA CCM. */ |
| 400 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 401 | uint8_t msg_type = *(msg->l2h); |
| 402 | |
| 403 | /* ping, pong and acknowledgment cases. */ |
| 404 | ipaccess_rcvmsg_base(msg, &link->ofd); |
| 405 | |
| 406 | /* this is a request for identification from the BSC. */ |
| 407 | if (msg_type == IPAC_MSGT_ID_GET) { |
| 408 | LOGP(DINP, LOGL_NOTICE, "received ID get\n"); |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 409 | if (!link->line->ops->sign_link_up) { |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 410 | LOGP(DINP, LOGL_ERROR, "Fix your application, " |
| 411 | "no action set if the signalling link " |
| 412 | "becomes ready\n"); |
| 413 | return -EINVAL; |
| 414 | } |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 415 | link->line->ops->sign_link_up(msg, link->line, |
| 416 | link->port == IPA_TCP_PORT_OML ? |
| 417 | E1INP_SIGN_OML : E1INP_SIGN_RSL); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 418 | } |
| 419 | return 0; |
| 420 | } else if (link->port == IPA_TCP_PORT_OML) |
| 421 | e1i_ts = &link->line->ts[0]; |
| 422 | else if (link->port == IPA_TCP_PORT_RSL) |
| 423 | e1i_ts = &link->line->ts[1]; |
| 424 | |
| 425 | /* look up for some existing signaling link. */ |
| 426 | sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 427 | if (sign_link == NULL) { |
| 428 | LOGP(DINP, LOGL_ERROR, "no matching signalling link for " |
| 429 | "hh->proto=0x%02x\n", hh->proto); |
| 430 | msgb_free(msg); |
| 431 | return -EIO; |
| 432 | } |
| 433 | msg->dst = sign_link; |
Pablo Neira Ayuso | ff66363 | 2011-06-26 19:10:56 +0200 | [diff] [blame] | 434 | msg->trx = sign_link->trx; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 435 | |
| 436 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 437 | if (!link->line->ops->sign_link) { |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 438 | LOGP(DINP, LOGL_ERROR, "Fix your application, " |
| 439 | "no action set for signalling messages.\n"); |
| 440 | return -ENOENT; |
| 441 | } |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 442 | link->line->ops->sign_link(msg, link->line, sign_link); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 443 | return 0; |
| 444 | } |
| 445 | |
Pablo Neira Ayuso | c00ee73 | 2011-06-21 12:22:49 +0200 | [diff] [blame] | 446 | static int ipaccess_line_update(struct e1inp_line *line, |
| 447 | enum e1inp_line_role role, const char *addr) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 448 | { |
| 449 | int ret = -ENOENT; |
| 450 | |
| 451 | switch(role) { |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 452 | case E1INP_LINE_R_BSC: { |
| 453 | struct ipa_server_link *oml_link, *rsl_link; |
| 454 | |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 455 | LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n"); |
| 456 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 457 | oml_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 458 | "0.0.0.0", IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 459 | ipaccess_bsc_oml_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 460 | if (oml_link == NULL) { |
| 461 | LOGP(DINP, LOGL_ERROR, "cannot create OML " |
| 462 | "BSC link: %s\n", strerror(errno)); |
| 463 | return -ENOMEM; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 464 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 465 | if (ipa_server_link_open(oml_link) < 0) { |
| 466 | LOGP(DINP, LOGL_ERROR, "cannot open OML BSC link: %s\n", |
| 467 | strerror(errno)); |
| 468 | ipa_server_link_close(oml_link); |
| 469 | ipa_server_link_destroy(oml_link); |
| 470 | return -EIO; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 471 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 472 | rsl_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 473 | "0.0.0.0", IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 474 | ipaccess_bsc_rsl_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 475 | if (rsl_link == NULL) { |
| 476 | LOGP(DINP, LOGL_ERROR, "cannot create RSL " |
| 477 | "BSC link: %s\n", strerror(errno)); |
| 478 | return -ENOMEM; |
| 479 | } |
| 480 | if (ipa_server_link_open(rsl_link) < 0) { |
| 481 | LOGP(DINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n", |
| 482 | strerror(errno)); |
| 483 | ipa_server_link_close(rsl_link); |
| 484 | ipa_server_link_destroy(rsl_link); |
| 485 | return -EIO; |
| 486 | } |
| 487 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 488 | break; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 489 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 490 | case E1INP_LINE_R_BTS: { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 491 | struct ipa_client_link *link, *rsl_link; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 492 | |
| 493 | LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n"); |
| 494 | |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 495 | link = ipa_client_link_create(tall_ipa_ctx, line, |
| 496 | addr, IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 497 | ipaccess_bts_cb, NULL); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 498 | if (link == NULL) { |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 499 | LOGP(DINP, LOGL_ERROR, "cannot create OML " |
| 500 | "BTS link: %s\n", strerror(errno)); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 501 | return -ENOMEM; |
| 502 | } |
| 503 | if (ipa_client_link_open(link) < 0) { |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 504 | LOGP(DINP, LOGL_ERROR, "cannot open OML BTS link: %s\n", |
| 505 | strerror(errno)); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 506 | ipa_client_link_close(link); |
| 507 | ipa_client_link_destroy(link); |
| 508 | return -EIO; |
| 509 | } |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 510 | rsl_link = ipa_client_link_create(tall_ipa_ctx, line, |
| 511 | addr, IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 512 | ipaccess_bts_cb, NULL); |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 513 | if (rsl_link == NULL) { |
| 514 | LOGP(DINP, LOGL_ERROR, "cannot create RSL " |
| 515 | "BTS link: %s\n", strerror(errno)); |
| 516 | return -ENOMEM; |
| 517 | } |
| 518 | if (ipa_client_link_open(rsl_link) < 0) { |
| 519 | LOGP(DINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n", |
| 520 | strerror(errno)); |
| 521 | ipa_client_link_close(rsl_link); |
| 522 | ipa_client_link_destroy(rsl_link); |
| 523 | return -EIO; |
| 524 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 525 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 526 | break; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 527 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 528 | default: |
| 529 | break; |
| 530 | } |
| 531 | return ret; |
| 532 | } |
| 533 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 534 | void e1inp_ipaccess_init(void) |
| 535 | { |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 536 | tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 537 | e1inp_driver_register(&ipaccess_driver); |
| 538 | } |