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 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 78 | static const char *idtag_names[] = { |
| 79 | [IPAC_IDTAG_SERNR] = "Serial_Number", |
| 80 | [IPAC_IDTAG_UNITNAME] = "Unit_Name", |
| 81 | [IPAC_IDTAG_LOCATION1] = "Location_1", |
| 82 | [IPAC_IDTAG_LOCATION2] = "Location_2", |
| 83 | [IPAC_IDTAG_EQUIPVERS] = "Equipment_Version", |
| 84 | [IPAC_IDTAG_SWVERSION] = "Software_Version", |
| 85 | [IPAC_IDTAG_IPADDR] = "IP_Address", |
| 86 | [IPAC_IDTAG_MACADDR] = "MAC_Address", |
| 87 | [IPAC_IDTAG_UNIT] = "Unit_ID", |
| 88 | }; |
| 89 | |
| 90 | const char *ipaccess_idtag_name(uint8_t tag) |
| 91 | { |
| 92 | if (tag >= ARRAY_SIZE(idtag_names)) |
| 93 | return "unknown"; |
| 94 | |
| 95 | return idtag_names[tag]; |
| 96 | } |
| 97 | |
| 98 | int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len) |
| 99 | { |
| 100 | uint8_t t_len; |
| 101 | uint8_t t_tag; |
| 102 | uint8_t *cur = buf; |
| 103 | |
| 104 | memset(dec, 0, sizeof(*dec)); |
| 105 | |
| 106 | while (len >= 2) { |
| 107 | len -= 2; |
| 108 | t_len = *cur++; |
| 109 | t_tag = *cur++; |
| 110 | |
| 111 | if (t_len > len + 1) { |
| 112 | LOGP(DMI, LOGL_ERROR, "The tag does not fit: %d\n", t_len); |
| 113 | return -EINVAL; |
| 114 | } |
| 115 | |
| 116 | DEBUGPC(DMI, "%s='%s' ", ipaccess_idtag_name(t_tag), cur); |
| 117 | |
| 118 | dec->lv[t_tag].len = t_len; |
| 119 | dec->lv[t_tag].val = cur; |
| 120 | |
| 121 | cur += t_len; |
| 122 | len -= t_len; |
| 123 | } |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | int ipaccess_parse_unitid(const char *str, struct ipaccess_unit *unit_data) |
| 128 | { |
| 129 | unsigned long ul; |
| 130 | char *endptr; |
| 131 | const char *nptr; |
| 132 | |
| 133 | nptr = str; |
| 134 | ul = strtoul(nptr, &endptr, 10); |
| 135 | if (endptr <= nptr) |
| 136 | return -EINVAL; |
| 137 | if (unit_data->site_id) |
| 138 | unit_data->site_id = ul & 0xffff; |
| 139 | |
| 140 | if (*endptr++ != '/') |
| 141 | return -EINVAL; |
| 142 | |
| 143 | nptr = endptr; |
| 144 | ul = strtoul(nptr, &endptr, 10); |
| 145 | if (endptr <= nptr) |
| 146 | return -EINVAL; |
| 147 | if (unit_data->bts_id) |
| 148 | unit_data->bts_id = ul & 0xffff; |
| 149 | |
| 150 | if (*endptr++ != '/') |
| 151 | return -EINVAL; |
| 152 | |
| 153 | nptr = endptr; |
| 154 | ul = strtoul(nptr, &endptr, 10); |
| 155 | if (endptr <= nptr) |
| 156 | return -EINVAL; |
| 157 | if (unit_data->trx_id) |
| 158 | unit_data->trx_id = ul & 0xffff; |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 163 | static int ipaccess_send(int fd, const void *msg, size_t msglen) |
| 164 | { |
| 165 | int ret; |
| 166 | |
| 167 | ret = write(fd, msg, msglen); |
| 168 | if (ret < 0) |
| 169 | return ret; |
| 170 | if (ret < msglen) { |
| 171 | LOGP(DINP, LOGL_ERROR, "ipaccess_send: short write\n"); |
| 172 | return -EIO; |
| 173 | } |
| 174 | return ret; |
| 175 | } |
| 176 | |
| 177 | int ipaccess_send_pong(int fd) |
| 178 | { |
| 179 | return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg)); |
| 180 | } |
| 181 | |
| 182 | int ipaccess_send_id_ack(int fd) |
| 183 | { |
| 184 | return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg)); |
| 185 | } |
| 186 | |
| 187 | int ipaccess_send_id_req(int fd) |
| 188 | { |
| 189 | return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg)); |
| 190 | } |
| 191 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 192 | /* base handling of the ip.access protocol */ |
| 193 | int ipaccess_rcvmsg_base(struct msgb *msg, |
| 194 | struct osmo_fd *bfd) |
| 195 | { |
| 196 | uint8_t msg_type = *(msg->l2h); |
| 197 | int ret = 0; |
| 198 | |
| 199 | switch (msg_type) { |
| 200 | case IPAC_MSGT_PING: |
| 201 | ret = ipaccess_send_pong(bfd->fd); |
| 202 | break; |
| 203 | case IPAC_MSGT_PONG: |
| 204 | DEBUGP(DMI, "PONG!\n"); |
| 205 | break; |
| 206 | case IPAC_MSGT_ID_ACK: |
| 207 | DEBUGP(DMI, "ID_ACK? -> ACK!\n"); |
| 208 | ret = ipaccess_send_id_ack(bfd->fd); |
| 209 | break; |
| 210 | } |
| 211 | return 0; |
| 212 | } |
| 213 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 214 | /* base handling of the ip.access protocol */ |
| 215 | int ipaccess_rcvmsg_bts_base(struct msgb *msg, |
| 216 | struct osmo_fd *bfd) |
| 217 | { |
| 218 | uint8_t msg_type = *(msg->l2h); |
| 219 | int ret = 0; |
| 220 | |
| 221 | switch (msg_type) { |
| 222 | case IPAC_MSGT_PING: |
| 223 | ret = ipaccess_send_pong(bfd->fd); |
| 224 | break; |
| 225 | case IPAC_MSGT_PONG: |
| 226 | DEBUGP(DMI, "PONG!\n"); |
| 227 | break; |
| 228 | case IPAC_MSGT_ID_ACK: |
| 229 | DEBUGP(DMI, "ID_ACK\n"); |
| 230 | break; |
| 231 | } |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static void ipaccess_drop(struct osmo_fd *bfd) |
| 236 | { |
| 237 | struct e1inp_line *line = bfd->data; |
| 238 | |
| 239 | /* e1inp_sign_link_destroy releases the socket descriptors for us. */ |
| 240 | line->ops->sign_link_down(line); |
| 241 | |
| 242 | /* RSL connection without ID_RESP, release temporary socket. */ |
| 243 | if (line->ts[E1INP_SIGN_OML-1].type == E1INP_SIGN_NONE) |
| 244 | talloc_free(bfd); |
| 245 | } |
| 246 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 247 | static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, |
| 248 | struct osmo_fd *bfd) |
| 249 | { |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 250 | struct tlv_parsed tlvp; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 251 | uint8_t msg_type = *(msg->l2h); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 252 | struct ipaccess_unit unit_data = {}; |
| 253 | struct e1inp_sign_link *sign_link; |
| 254 | char *unitid; |
| 255 | int len, ret; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 256 | |
| 257 | /* handle base messages */ |
| 258 | ipaccess_rcvmsg_base(msg, bfd); |
| 259 | |
| 260 | switch (msg_type) { |
| 261 | case IPAC_MSGT_ID_RESP: |
| 262 | DEBUGP(DMI, "ID_RESP\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 263 | /* parse tags, search for Unit ID */ |
| 264 | ret = ipaccess_idtag_parse(&tlvp, (uint8_t *)msg->l2h + 2, |
| 265 | msgb_l2len(msg)-2); |
| 266 | DEBUGP(DMI, "\n"); |
| 267 | if (ret < 0) { |
| 268 | LOGP(DINP, LOGL_ERROR, "ignoring IPA response message " |
| 269 | "with malformed TLVs\n"); |
| 270 | return ret; |
| 271 | } |
| 272 | if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT)) |
| 273 | break; |
| 274 | |
| 275 | len = TLVP_LEN(&tlvp, IPAC_IDTAG_UNIT); |
| 276 | if (len < 1) |
| 277 | break; |
| 278 | |
| 279 | unitid = (char *) TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT); |
| 280 | unitid[len - 1] = '\0'; |
| 281 | ipaccess_parse_unitid(unitid, &unit_data); |
| 282 | |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 283 | if (!line->ops->sign_link_up) { |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 284 | LOGP(DINP, LOGL_ERROR, |
| 285 | "Unable to set signal link, closing socket.\n"); |
| 286 | osmo_fd_unregister(bfd); |
| 287 | close(bfd->fd); |
| 288 | bfd->fd = -1; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 289 | return -EINVAL; |
| 290 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 291 | /* the BSC creates the new sign links at this stage. */ |
| 292 | if (bfd->priv_nr == E1INP_SIGN_OML) { |
| 293 | sign_link = |
| 294 | line->ops->sign_link_up(&unit_data, line, |
| 295 | E1INP_SIGN_OML); |
| 296 | if (sign_link == NULL) { |
| 297 | LOGP(DINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 298 | "Unable to set signal link, " |
| 299 | "closing socket.\n"); |
| 300 | osmo_fd_unregister(bfd); |
| 301 | close(bfd->fd); |
| 302 | bfd->fd = -1; |
| 303 | return -EINVAL; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 304 | } |
| 305 | } else if (bfd->priv_nr == E1INP_SIGN_RSL) { |
| 306 | struct e1inp_ts *e1i_ts; |
| 307 | struct osmo_fd *newbfd; |
| 308 | |
| 309 | sign_link = |
| 310 | line->ops->sign_link_up(&unit_data, line, |
| 311 | E1INP_SIGN_RSL); |
| 312 | if (sign_link == NULL) { |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 313 | LOGP(DINP, LOGL_ERROR, |
| 314 | "Unable to set signal link, " |
| 315 | "closing socket.\n"); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 316 | osmo_fd_unregister(bfd); |
| 317 | close(bfd->fd); |
| 318 | bfd->fd = -1; |
| 319 | talloc_free(bfd); |
| 320 | return 0; |
| 321 | } |
| 322 | /* Finally, we know which OML link is associated with |
| 323 | * this RSL link, attach it to this socket. */ |
| 324 | bfd->data = line = sign_link->ts->line; |
| 325 | e1i_ts = &line->ts[E1INP_SIGN_RSL+unit_data.trx_id-1]; |
| 326 | newbfd = &e1i_ts->driver.ipaccess.fd; |
| 327 | |
| 328 | /* get rid of our old temporary bfd */ |
| 329 | memcpy(newbfd, bfd, sizeof(*newbfd)); |
| 330 | newbfd->priv_nr = E1INP_SIGN_RSL + unit_data.trx_id; |
| 331 | osmo_fd_unregister(bfd); |
| 332 | bfd->fd = -1; |
| 333 | talloc_free(bfd); |
| 334 | osmo_fd_register(newbfd); |
| 335 | } |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 336 | break; |
| 337 | } |
| 338 | return 0; |
| 339 | } |
| 340 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 341 | static int handle_ts1_read(struct osmo_fd *bfd) |
| 342 | { |
| 343 | struct e1inp_line *line = bfd->data; |
| 344 | unsigned int ts_nr = bfd->priv_nr; |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 345 | struct e1inp_ts *e1i_ts = NULL; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 346 | struct e1inp_sign_link *link; |
| 347 | struct ipaccess_head *hh; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 348 | struct msgb *msg; |
| 349 | int ret = 0, error; |
| 350 | |
Pablo Neira Ayuso | 7a24940 | 2011-06-21 14:15:46 +0200 | [diff] [blame] | 351 | error = ipa_msg_recv(bfd->fd, &msg); |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 352 | if (error < 0) |
| 353 | return error; |
| 354 | else if (error == 0) { |
| 355 | ipaccess_drop(bfd); |
| 356 | LOGP(DINP, LOGL_NOTICE, "Sign link vanished, dead socket\n"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 357 | return error; |
| 358 | } |
| 359 | DEBUGP(DMI, "RX %u: %s\n", ts_nr, osmo_hexdump(msgb_l2(msg), msgb_l2len(msg))); |
| 360 | |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 361 | /* Now that we're sure that we've got a line for socket. */ |
| 362 | e1i_ts = &line->ts[ts_nr-1]; |
| 363 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 364 | hh = (struct ipaccess_head *) msg->data; |
| 365 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 366 | ipaccess_rcvmsg(line, msg, bfd); |
| 367 | msgb_free(msg); |
| 368 | return ret; |
| 369 | } |
| 370 | /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg() |
| 371 | * might have free'd it !!! */ |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 372 | |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 373 | link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 374 | if (!link) { |
| 375 | LOGP(DINP, LOGL_ERROR, "no matching signalling link for " |
| 376 | "hh->proto=0x%02x\n", hh->proto); |
| 377 | msgb_free(msg); |
| 378 | return -EIO; |
| 379 | } |
| 380 | msg->dst = link; |
Pablo Neira Ayuso | ff66363 | 2011-06-26 19:10:56 +0200 | [diff] [blame] | 381 | msg->trx = link->trx; |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 382 | |
| 383 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 384 | if (!e1i_ts->line->ops->sign_link) { |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 385 | LOGP(DINP, LOGL_ERROR, "Fix your application, " |
| 386 | "no action set for signalling messages.\n"); |
| 387 | return -ENOENT; |
| 388 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 389 | e1i_ts->line->ops->sign_link(msg, link); |
Pablo Neira Ayuso | 5a4b7c5 | 2011-06-07 14:07:48 +0200 | [diff] [blame] | 390 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 391 | return ret; |
| 392 | } |
| 393 | |
| 394 | void ipaccess_prepend_header_ext(struct msgb *msg, int proto) |
| 395 | { |
| 396 | struct ipaccess_head_ext *hh_ext; |
| 397 | |
| 398 | /* prepend the osmo ip.access header extension */ |
| 399 | hh_ext = (struct ipaccess_head_ext *) msgb_push(msg, sizeof(*hh_ext)); |
| 400 | hh_ext->proto = proto; |
| 401 | } |
| 402 | |
| 403 | void ipaccess_prepend_header(struct msgb *msg, int proto) |
| 404 | { |
| 405 | struct ipaccess_head *hh; |
| 406 | |
| 407 | /* prepend the ip.access header */ |
| 408 | hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh)); |
| 409 | hh->len = htons(msg->len - sizeof(*hh)); |
| 410 | hh->proto = proto; |
| 411 | } |
| 412 | |
| 413 | static int ts_want_write(struct e1inp_ts *e1i_ts) |
| 414 | { |
| 415 | e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE; |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 420 | static void ipaccess_close(struct e1inp_ts *e1i_ts) |
| 421 | { |
| 422 | struct osmo_fd *bfd = &e1i_ts->driver.ipaccess.fd; |
| 423 | osmo_fd_unregister(bfd); |
| 424 | close(bfd->fd); |
| 425 | bfd->fd = -1; |
| 426 | } |
| 427 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 428 | static void timeout_ts1_write(void *data) |
| 429 | { |
| 430 | struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data; |
| 431 | |
| 432 | /* trigger write of ts1, due to tx delay timer */ |
| 433 | ts_want_write(e1i_ts); |
| 434 | } |
| 435 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 436 | static int __handle_ts1_write(struct osmo_fd *bfd, struct e1inp_line *line) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 437 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 438 | unsigned int ts_nr = bfd->priv_nr; |
| 439 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 440 | struct e1inp_sign_link *sign_link; |
| 441 | struct msgb *msg; |
| 442 | uint8_t proto; |
| 443 | int ret; |
| 444 | |
| 445 | bfd->when &= ~BSC_FD_WRITE; |
| 446 | |
| 447 | /* get the next msg for this timeslot */ |
| 448 | msg = e1inp_tx_ts(e1i_ts, &sign_link); |
| 449 | if (!msg) { |
| 450 | /* no message after tx delay timer */ |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | switch (sign_link->type) { |
| 455 | case E1INP_SIGN_OML: |
| 456 | proto = IPAC_PROTO_OML; |
| 457 | break; |
| 458 | case E1INP_SIGN_RSL: |
| 459 | proto = IPAC_PROTO_RSL; |
| 460 | break; |
| 461 | default: |
| 462 | msgb_free(msg); |
| 463 | bfd->when |= BSC_FD_WRITE; /* come back for more msg */ |
| 464 | return -EINVAL; |
| 465 | } |
| 466 | |
| 467 | msg->l2h = msg->data; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 468 | /* This is an IPA CCM, it already contains the header, skip. */ |
| 469 | if (msgb_tailroom(msg) < sizeof(struct ipaccess_head)) |
| 470 | ipaccess_prepend_header(msg, sign_link->tei); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 471 | |
| 472 | DEBUGP(DMI, "TX %u: %s\n", ts_nr, osmo_hexdump(msg->l2h, msgb_l2len(msg))); |
| 473 | |
| 474 | ret = send(bfd->fd, msg->data, msg->len, 0); |
| 475 | msgb_free(msg); |
| 476 | |
| 477 | /* set tx delay timer for next event */ |
| 478 | e1i_ts->sign.tx_timer.cb = timeout_ts1_write; |
| 479 | e1i_ts->sign.tx_timer.data = e1i_ts; |
| 480 | |
| 481 | /* Reducing this might break the nanoBTS 900 init. */ |
| 482 | osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, e1i_ts->sign.delay); |
| 483 | |
| 484 | return ret; |
| 485 | } |
| 486 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 487 | int handle_ts1_write(struct osmo_fd *bfd) |
| 488 | { |
| 489 | struct e1inp_line *line = bfd->data; |
| 490 | |
| 491 | return __handle_ts1_write(bfd, line); |
| 492 | } |
| 493 | |
| 494 | int ipaccess_bts_write_cb(struct ipa_client_link *link) |
| 495 | { |
| 496 | struct e1inp_line *line = link->line; |
| 497 | |
| 498 | return __handle_ts1_write(link->ofd, line); |
| 499 | } |
| 500 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 501 | /* callback from select.c in case one of the fd's can be read/written */ |
| 502 | static int ipaccess_fd_cb(struct osmo_fd *bfd, unsigned int what) |
| 503 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 504 | int rc = 0; |
| 505 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 506 | if (what & BSC_FD_READ) |
| 507 | rc = handle_ts1_read(bfd); |
| 508 | if (what & BSC_FD_WRITE) |
| 509 | rc = handle_ts1_write(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 510 | |
| 511 | return rc; |
| 512 | } |
| 513 | |
Pablo Neira Ayuso | c00ee73 | 2011-06-21 12:22:49 +0200 | [diff] [blame] | 514 | static int ipaccess_line_update(struct e1inp_line *line, |
| 515 | enum e1inp_line_role role, const char *addr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 516 | |
| 517 | struct e1inp_driver ipaccess_driver = { |
| 518 | .name = "ipa", |
| 519 | .want_write = ts_want_write, |
| 520 | .line_update = ipaccess_line_update, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 521 | .close = ipaccess_close, |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 522 | .default_delay = 0, |
| 523 | }; |
| 524 | |
| 525 | /* callback of the OML listening filedescriptor */ |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 526 | 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] | 527 | { |
| 528 | int ret; |
| 529 | int idx = 0; |
| 530 | int i; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 531 | struct e1inp_line *line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 532 | struct e1inp_ts *e1i_ts; |
| 533 | struct osmo_fd *bfd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 534 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 535 | /* clone virtual E1 line for this new OML link. */ |
| 536 | line = talloc_zero(tall_ipa_ctx, struct e1inp_line); |
| 537 | if (line == NULL) { |
| 538 | LOGP(DINP, LOGL_ERROR, "could not clone E1 line\n"); |
| 539 | return -1; |
| 540 | } |
| 541 | memcpy(line, link->line, sizeof(struct e1inp_line)); |
| 542 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 543 | /* create virrtual E1 timeslots for signalling */ |
Pablo Neira Ayuso | 5930185 | 2011-06-27 15:44:23 +0200 | [diff] [blame] | 544 | e1inp_ts_config_sign(&line->ts[E1INP_SIGN_OML-1], line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 545 | |
| 546 | /* initialize the fds */ |
| 547 | for (i = 0; i < ARRAY_SIZE(line->ts); ++i) |
| 548 | line->ts[i].driver.ipaccess.fd.fd = -1; |
| 549 | |
| 550 | e1i_ts = &line->ts[idx]; |
| 551 | |
Pablo Neira Ayuso | 93c6201 | 2011-06-26 19:12:47 +0200 | [diff] [blame] | 552 | bfd = &e1i_ts->driver.ipaccess.fd; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 553 | bfd->fd = fd; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 554 | bfd->data = line; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 555 | bfd->priv_nr = E1INP_SIGN_OML; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 556 | bfd->cb = ipaccess_fd_cb; |
| 557 | bfd->when = BSC_FD_READ; |
| 558 | ret = osmo_fd_register(bfd); |
| 559 | if (ret < 0) { |
| 560 | LOGP(DINP, LOGL_ERROR, "could not register FD\n"); |
| 561 | close(bfd->fd); |
| 562 | return ret; |
| 563 | } |
| 564 | |
| 565 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 566 | ret = ipaccess_send_id_req(bfd->fd); |
| 567 | |
| 568 | return ret; |
| 569 | } |
| 570 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 571 | 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] | 572 | { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 573 | struct osmo_fd *bfd; |
| 574 | int ret; |
| 575 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 576 | /* We don't know yet which OML link to associate it with. Thus, we |
| 577 | * allocate a temporary bfd until we have received ID. */ |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 578 | bfd = talloc_zero(tall_ipa_ctx, struct osmo_fd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 579 | if (!bfd) |
| 580 | return -ENOMEM; |
| 581 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 582 | bfd->fd = fd; |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 583 | /* This dummy line is replaced once we can attach it to the OML link */ |
| 584 | bfd->data = link->line; |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 585 | bfd->priv_nr = E1INP_SIGN_RSL; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 586 | bfd->cb = ipaccess_fd_cb; |
| 587 | bfd->when = BSC_FD_READ; |
| 588 | ret = osmo_fd_register(bfd); |
| 589 | if (ret < 0) { |
| 590 | LOGP(DINP, LOGL_ERROR, "could not register FD\n"); |
| 591 | close(bfd->fd); |
| 592 | talloc_free(bfd); |
| 593 | return ret; |
| 594 | } |
| 595 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 596 | ret = ipaccess_send_id_req(bfd->fd); |
| 597 | |
| 598 | return 0; |
| 599 | } |
| 600 | |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 601 | static struct msgb *abis_msgb_alloc(int headroom) |
| 602 | { |
| 603 | struct msgb *nmsg; |
| 604 | |
| 605 | headroom += sizeof(struct ipaccess_head); |
| 606 | |
| 607 | nmsg = msgb_alloc_headroom(1200 + headroom, headroom, "dummy BTS"); |
| 608 | if (!nmsg) |
| 609 | return NULL; |
| 610 | return nmsg; |
| 611 | } |
| 612 | |
| 613 | static void abis_push_ipa(struct msgb *msg, uint8_t proto) |
| 614 | { |
| 615 | struct ipaccess_head *nhh; |
| 616 | |
| 617 | msg->l2h = msg->data; |
| 618 | nhh = (struct ipaccess_head *) msgb_push(msg, sizeof(*nhh)); |
| 619 | nhh->proto = proto; |
| 620 | nhh->len = htons(msgb_l2len(msg)); |
| 621 | } |
| 622 | |
| 623 | static struct msgb * |
| 624 | ipa_bts_id_resp(struct ipaccess_unit *dev, uint8_t *data, int len) |
| 625 | { |
| 626 | struct msgb *nmsg; |
| 627 | char str[64]; |
| 628 | uint8_t *tag; |
| 629 | |
| 630 | nmsg = abis_msgb_alloc(0); |
| 631 | if (!nmsg) |
| 632 | return NULL; |
| 633 | |
| 634 | *msgb_put(nmsg, 1) = IPAC_MSGT_ID_RESP; |
| 635 | while (len) { |
| 636 | if (len < 2) { |
| 637 | LOGP(DINP, LOGL_NOTICE, |
| 638 | "Short read of ipaccess tag\n"); |
| 639 | msgb_free(nmsg); |
| 640 | return NULL; |
| 641 | } |
| 642 | switch (data[1]) { |
| 643 | case IPAC_IDTAG_UNIT: |
| 644 | sprintf(str, "%u/%u/%u", |
| 645 | dev->site_id, dev->bts_id, dev->trx_id); |
| 646 | break; |
| 647 | case IPAC_IDTAG_MACADDR: |
| 648 | sprintf(str, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 649 | dev->mac_addr[0], dev->mac_addr[1], |
| 650 | dev->mac_addr[2], dev->mac_addr[3], |
| 651 | dev->mac_addr[4], dev->mac_addr[5]); |
| 652 | break; |
| 653 | case IPAC_IDTAG_LOCATION1: |
| 654 | strcpy(str, dev->location1); |
| 655 | break; |
| 656 | case IPAC_IDTAG_LOCATION2: |
| 657 | strcpy(str, dev->location2); |
| 658 | break; |
| 659 | case IPAC_IDTAG_EQUIPVERS: |
| 660 | strcpy(str, dev->equipvers); |
| 661 | break; |
| 662 | case IPAC_IDTAG_SWVERSION: |
| 663 | strcpy(str, dev->swversion); |
| 664 | break; |
| 665 | case IPAC_IDTAG_UNITNAME: |
| 666 | sprintf(str, "%s-%02x-%02x-%02x-%02x-%02x-%02x", |
| 667 | dev->unit_name, |
| 668 | dev->mac_addr[0], dev->mac_addr[1], |
| 669 | dev->mac_addr[2], dev->mac_addr[3], |
| 670 | dev->mac_addr[4], dev->mac_addr[5]); |
| 671 | break; |
| 672 | case IPAC_IDTAG_SERNR: |
| 673 | strcpy(str, dev->serno); |
| 674 | break; |
| 675 | default: |
| 676 | LOGP(DINP, LOGL_NOTICE, |
| 677 | "Unknown ipaccess tag 0x%02x\n", *data); |
| 678 | msgb_free(nmsg); |
| 679 | return NULL; |
| 680 | } |
| 681 | LOGP(DINP, LOGL_INFO, " tag %d: %s\n", data[1], str); |
| 682 | tag = msgb_put(nmsg, 3 + strlen(str) + 1); |
| 683 | tag[0] = 0x00; |
| 684 | tag[1] = 1 + strlen(str) + 1; |
| 685 | tag[2] = data[1]; |
| 686 | memcpy(tag + 3, str, strlen(str) + 1); |
| 687 | data += 2; |
| 688 | len -= 2; |
| 689 | } |
| 690 | abis_push_ipa(nmsg, IPAC_PROTO_IPACCESS); |
| 691 | return nmsg; |
| 692 | } |
| 693 | |
| 694 | static struct msgb *ipa_bts_id_ack(void) |
| 695 | { |
| 696 | struct msgb *nmsg2; |
| 697 | |
| 698 | nmsg2 = abis_msgb_alloc(0); |
| 699 | if (!nmsg2) |
| 700 | return NULL; |
| 701 | |
| 702 | *msgb_put(nmsg2, 1) = IPAC_MSGT_ID_ACK; |
| 703 | abis_push_ipa(nmsg2, IPAC_PROTO_IPACCESS); |
| 704 | |
| 705 | return nmsg2; |
| 706 | } |
| 707 | |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 708 | 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] | 709 | { |
| 710 | struct ipaccess_head *hh = (struct ipaccess_head *) msg->data; |
| 711 | struct e1inp_ts *e1i_ts = NULL; |
| 712 | struct e1inp_sign_link *sign_link; |
| 713 | |
| 714 | /* special handling for IPA CCM. */ |
| 715 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 716 | uint8_t msg_type = *(msg->l2h); |
| 717 | |
| 718 | /* ping, pong and acknowledgment cases. */ |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 719 | ipaccess_rcvmsg_bts_base(msg, link->ofd); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 720 | |
| 721 | /* this is a request for identification from the BSC. */ |
| 722 | if (msg_type == IPAC_MSGT_ID_GET) { |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 723 | struct e1inp_sign_link *sign_link; |
| 724 | struct msgb *rmsg; |
| 725 | uint8_t *data = msgb_l2(msg); |
| 726 | int len = msgb_l2len(msg); |
| 727 | |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 728 | LOGP(DINP, LOGL_NOTICE, "received ID get\n"); |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 729 | if (!link->line->ops->sign_link_up) { |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 730 | LOGP(DINP, LOGL_ERROR, |
| 731 | "Unable to set signal link, " |
| 732 | "closing socket.\n"); |
| 733 | osmo_fd_unregister(link->ofd); |
| 734 | close(link->ofd->fd); |
| 735 | link->ofd->fd = -1; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 736 | return -EINVAL; |
| 737 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 738 | sign_link = link->line->ops->sign_link_up(msg, |
| 739 | link->line, |
| 740 | link->ofd->priv_nr); |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 741 | if (sign_link == NULL) { |
| 742 | LOGP(DINP, LOGL_ERROR, |
Pablo Neira Ayuso | cd8d2e5 | 2011-07-02 17:05:21 +0200 | [diff] [blame] | 743 | "Unable to set signal link, " |
| 744 | "closing socket.\n"); |
| 745 | osmo_fd_unregister(link->ofd); |
| 746 | close(link->ofd->fd); |
| 747 | link->ofd->fd = -1; |
Pablo Neira Ayuso | dfafe68 | 2011-07-02 14:32:32 +0200 | [diff] [blame] | 748 | return -EINVAL; |
| 749 | } |
| 750 | rmsg = ipa_bts_id_resp(link->line->ops->data, |
| 751 | data + 1, len - 1); |
| 752 | ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); |
| 753 | msgb_free(rmsg); |
| 754 | |
| 755 | /* send ID_ACK. */ |
| 756 | rmsg = ipa_bts_id_ack(); |
| 757 | ipaccess_send(link->ofd->fd, rmsg->data, rmsg->len); |
| 758 | msgb_free(rmsg); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 759 | } |
| 760 | return 0; |
| 761 | } else if (link->port == IPA_TCP_PORT_OML) |
| 762 | e1i_ts = &link->line->ts[0]; |
| 763 | else if (link->port == IPA_TCP_PORT_RSL) |
| 764 | e1i_ts = &link->line->ts[1]; |
| 765 | |
| 766 | /* look up for some existing signaling link. */ |
| 767 | sign_link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
| 768 | if (sign_link == NULL) { |
| 769 | LOGP(DINP, LOGL_ERROR, "no matching signalling link for " |
| 770 | "hh->proto=0x%02x\n", hh->proto); |
| 771 | msgb_free(msg); |
| 772 | return -EIO; |
| 773 | } |
| 774 | msg->dst = sign_link; |
Pablo Neira Ayuso | ff66363 | 2011-06-26 19:10:56 +0200 | [diff] [blame] | 775 | msg->trx = sign_link->trx; |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 776 | |
| 777 | /* XXX better use e1inp_ts_rx? */ |
Pablo Neira Ayuso | f163d23 | 2011-06-25 18:42:55 +0200 | [diff] [blame] | 778 | if (!link->line->ops->sign_link) { |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 779 | LOGP(DINP, LOGL_ERROR, "Fix your application, " |
| 780 | "no action set for signalling messages.\n"); |
| 781 | return -ENOENT; |
| 782 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 783 | link->line->ops->sign_link(msg, sign_link); |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 784 | return 0; |
| 785 | } |
| 786 | |
Pablo Neira Ayuso | c00ee73 | 2011-06-21 12:22:49 +0200 | [diff] [blame] | 787 | static int ipaccess_line_update(struct e1inp_line *line, |
| 788 | enum e1inp_line_role role, const char *addr) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 789 | { |
| 790 | int ret = -ENOENT; |
| 791 | |
| 792 | switch(role) { |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 793 | case E1INP_LINE_R_BSC: { |
| 794 | struct ipa_server_link *oml_link, *rsl_link; |
| 795 | |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 796 | LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BSC mode\n"); |
| 797 | |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 798 | oml_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 799 | "0.0.0.0", IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 800 | ipaccess_bsc_oml_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 801 | if (oml_link == NULL) { |
| 802 | LOGP(DINP, LOGL_ERROR, "cannot create OML " |
| 803 | "BSC link: %s\n", strerror(errno)); |
| 804 | return -ENOMEM; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 805 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 806 | if (ipa_server_link_open(oml_link) < 0) { |
| 807 | LOGP(DINP, LOGL_ERROR, "cannot open OML BSC link: %s\n", |
| 808 | strerror(errno)); |
| 809 | ipa_server_link_close(oml_link); |
| 810 | ipa_server_link_destroy(oml_link); |
| 811 | return -EIO; |
Pablo Neira Ayuso | f67471f | 2011-06-07 11:25:49 +0200 | [diff] [blame] | 812 | } |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 813 | rsl_link = ipa_server_link_create(tall_ipa_ctx, line, |
| 814 | "0.0.0.0", IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | e009f4a | 2011-06-23 13:36:34 +0200 | [diff] [blame] | 815 | ipaccess_bsc_rsl_cb, NULL); |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 816 | if (rsl_link == NULL) { |
| 817 | LOGP(DINP, LOGL_ERROR, "cannot create RSL " |
| 818 | "BSC link: %s\n", strerror(errno)); |
| 819 | return -ENOMEM; |
| 820 | } |
| 821 | if (ipa_server_link_open(rsl_link) < 0) { |
| 822 | LOGP(DINP, LOGL_ERROR, "cannot open RSL BSC link: %s\n", |
| 823 | strerror(errno)); |
| 824 | ipa_server_link_close(rsl_link); |
| 825 | ipa_server_link_destroy(rsl_link); |
| 826 | return -EIO; |
| 827 | } |
| 828 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 829 | break; |
Pablo Neira Ayuso | 986191f | 2011-06-21 19:56:26 +0200 | [diff] [blame] | 830 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 831 | case E1INP_LINE_R_BTS: { |
Pablo Neira Ayuso | c07a8e7 | 2011-06-21 19:50:04 +0200 | [diff] [blame] | 832 | struct ipa_client_link *link, *rsl_link; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 833 | |
| 834 | LOGP(DINP, LOGL_NOTICE, "enabling ipaccess BTS mode\n"); |
| 835 | |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 836 | link = ipa_client_link_create(tall_ipa_ctx, |
| 837 | &line->ts[E1INP_SIGN_OML-1], |
| 838 | "ipa", E1INP_SIGN_OML, |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 839 | addr, IPA_TCP_PORT_OML, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 840 | ipaccess_bts_cb, |
| 841 | ipaccess_bts_write_cb, |
| 842 | NULL); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 843 | if (link == NULL) { |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 844 | LOGP(DINP, LOGL_ERROR, "cannot create OML " |
| 845 | "BTS link: %s\n", strerror(errno)); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 846 | return -ENOMEM; |
| 847 | } |
| 848 | if (ipa_client_link_open(link) < 0) { |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 849 | LOGP(DINP, LOGL_ERROR, "cannot open OML BTS link: %s\n", |
| 850 | strerror(errno)); |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 851 | ipa_client_link_close(link); |
| 852 | ipa_client_link_destroy(link); |
| 853 | return -EIO; |
| 854 | } |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 855 | rsl_link = ipa_client_link_create(tall_ipa_ctx, |
| 856 | &line->ts[E1INP_SIGN_RSL-1], |
| 857 | "ipa", E1INP_SIGN_RSL, |
Pablo Neira Ayuso | 591ddad | 2011-06-21 18:16:42 +0200 | [diff] [blame] | 858 | addr, IPA_TCP_PORT_RSL, |
Pablo Neira Ayuso | c9c4fd3 | 2011-06-30 12:19:42 +0200 | [diff] [blame] | 859 | ipaccess_bts_cb, |
| 860 | ipaccess_bts_write_cb, |
| 861 | NULL); |
Pablo Neira Ayuso | 29465d3 | 2011-06-21 14:21:33 +0200 | [diff] [blame] | 862 | if (rsl_link == NULL) { |
| 863 | LOGP(DINP, LOGL_ERROR, "cannot create RSL " |
| 864 | "BTS link: %s\n", strerror(errno)); |
| 865 | return -ENOMEM; |
| 866 | } |
| 867 | if (ipa_client_link_open(rsl_link) < 0) { |
| 868 | LOGP(DINP, LOGL_ERROR, "cannot open RSL BTS link: %s\n", |
| 869 | strerror(errno)); |
| 870 | ipa_client_link_close(rsl_link); |
| 871 | ipa_client_link_destroy(rsl_link); |
| 872 | return -EIO; |
| 873 | } |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 874 | ret = 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 875 | break; |
Pablo Neira Ayuso | 96e8128 | 2011-06-09 15:06:11 +0200 | [diff] [blame] | 876 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 877 | default: |
| 878 | break; |
| 879 | } |
| 880 | return ret; |
| 881 | } |
| 882 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 883 | void e1inp_ipaccess_init(void) |
| 884 | { |
Pablo Neira Ayuso | 54b4979 | 2011-06-07 12:15:26 +0200 | [diff] [blame] | 885 | tall_ipa_ctx = talloc_named_const(libosmo_abis_ctx, 1, "ipa"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 886 | e1inp_driver_register(&ipaccess_driver); |
| 887 | } |