Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 1 | /* OpenBSC Abis input driver for ip.access */ |
| 2 | |
| 3 | /* (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <stdio.h> |
| 24 | #include <unistd.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <errno.h> |
| 27 | #include <string.h> |
| 28 | #include <time.h> |
| 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/types.h> |
| 31 | #include <sys/socket.h> |
| 32 | #include <sys/ioctl.h> |
| 33 | #include <arpa/inet.h> |
| 34 | |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 35 | #include <osmocore/select.h> |
| 36 | #include <osmocore/tlv.h> |
| 37 | #include <osmocore/msgb.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 38 | #include <openbsc/debug.h> |
| 39 | #include <openbsc/gsm_data.h> |
| 40 | #include <openbsc/abis_nm.h> |
| 41 | #include <openbsc/abis_rsl.h> |
| 42 | #include <openbsc/subchan_demux.h> |
| 43 | #include <openbsc/e1_input.h> |
| 44 | #include <openbsc/ipaccess.h> |
Harald Welte | f4625b1 | 2010-02-20 16:24:02 +0100 | [diff] [blame] | 45 | #include <osmocore/talloc.h> |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 46 | |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 47 | #define PRIV_OML 1 |
| 48 | #define PRIV_RSL 2 |
| 49 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 50 | /* data structure for one E1 interface with A-bis */ |
| 51 | struct ia_e1_handle { |
| 52 | struct bsc_fd listen_fd; |
| 53 | struct bsc_fd rsl_listen_fd; |
| 54 | struct gsm_network *gsmnet; |
| 55 | }; |
| 56 | |
| 57 | static struct ia_e1_handle *e1h; |
| 58 | |
| 59 | |
| 60 | #define TS1_ALLOC_SIZE 300 |
| 61 | |
| 62 | static const u_int8_t pong[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG }; |
| 63 | static const u_int8_t id_ack[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK }; |
| 64 | static const u_int8_t id_req[] = { 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET, |
| 65 | 0x01, IPAC_IDTAG_UNIT, |
| 66 | 0x01, IPAC_IDTAG_MACADDR, |
| 67 | 0x01, IPAC_IDTAG_LOCATION1, |
| 68 | 0x01, IPAC_IDTAG_LOCATION2, |
| 69 | 0x01, IPAC_IDTAG_EQUIPVERS, |
| 70 | 0x01, IPAC_IDTAG_SWVERSION, |
| 71 | 0x01, IPAC_IDTAG_UNITNAME, |
| 72 | 0x01, IPAC_IDTAG_SERNR, |
| 73 | }; |
| 74 | |
| 75 | static const char *idtag_names[] = { |
| 76 | [IPAC_IDTAG_SERNR] = "Serial_Number", |
| 77 | [IPAC_IDTAG_UNITNAME] = "Unit_Name", |
| 78 | [IPAC_IDTAG_LOCATION1] = "Location_1", |
| 79 | [IPAC_IDTAG_LOCATION2] = "Location_2", |
| 80 | [IPAC_IDTAG_EQUIPVERS] = "Equipment_Version", |
| 81 | [IPAC_IDTAG_SWVERSION] = "Software_Version", |
| 82 | [IPAC_IDTAG_IPADDR] = "IP_Address", |
| 83 | [IPAC_IDTAG_MACADDR] = "MAC_Address", |
| 84 | [IPAC_IDTAG_UNIT] = "Unit_ID", |
| 85 | }; |
| 86 | |
| 87 | static const char *ipac_idtag_name(int tag) |
| 88 | { |
| 89 | if (tag >= ARRAY_SIZE(idtag_names)) |
| 90 | return "unknown"; |
| 91 | |
| 92 | return idtag_names[tag]; |
| 93 | } |
| 94 | |
Holger Hans Peter Freyther | 5932f64 | 2010-02-09 14:37:23 +0100 | [diff] [blame] | 95 | int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 96 | { |
| 97 | u_int8_t t_len; |
| 98 | u_int8_t t_tag; |
| 99 | u_int8_t *cur = buf; |
| 100 | |
| 101 | while (cur < buf + len) { |
| 102 | t_len = *cur++; |
| 103 | t_tag = *cur++; |
| 104 | |
| 105 | DEBUGPC(DMI, "%s='%s' ", ipac_idtag_name(t_tag), cur); |
| 106 | |
| 107 | dec->lv[t_tag].len = t_len; |
| 108 | dec->lv[t_tag].val = cur; |
| 109 | |
| 110 | cur += t_len; |
| 111 | } |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | struct gsm_bts *find_bts_by_unitid(struct gsm_network *net, |
| 116 | u_int16_t site_id, u_int16_t bts_id) |
| 117 | { |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 118 | struct gsm_bts *bts; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 119 | |
Harald Welte | e712a5f | 2009-06-21 16:17:15 +0200 | [diff] [blame] | 120 | llist_for_each_entry(bts, &net->bts_list, list) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 121 | |
| 122 | if (!is_ipaccess_bts(bts)) |
| 123 | continue; |
| 124 | |
| 125 | if (bts->ip_access.site_id == site_id && |
| 126 | bts->ip_access.bts_id == bts_id) |
| 127 | return bts; |
| 128 | } |
| 129 | |
| 130 | return NULL; |
| 131 | } |
| 132 | |
| 133 | static int parse_unitid(const char *str, u_int16_t *site_id, u_int16_t *bts_id, |
| 134 | u_int16_t *trx_id) |
| 135 | { |
| 136 | unsigned long ul; |
| 137 | char *endptr; |
| 138 | const char *nptr; |
| 139 | |
| 140 | nptr = str; |
| 141 | ul = strtoul(nptr, &endptr, 10); |
| 142 | if (endptr <= nptr) |
| 143 | return -EINVAL; |
| 144 | if (site_id) |
| 145 | *site_id = ul & 0xffff; |
| 146 | |
| 147 | if (*endptr++ != '/') |
| 148 | return -EINVAL; |
| 149 | |
| 150 | nptr = endptr; |
| 151 | ul = strtoul(nptr, &endptr, 10); |
| 152 | if (endptr <= nptr) |
| 153 | return -EINVAL; |
| 154 | if (bts_id) |
| 155 | *bts_id = ul & 0xffff; |
| 156 | |
| 157 | if (*endptr++ != '/') |
| 158 | return -EINVAL; |
| 159 | |
| 160 | nptr = endptr; |
| 161 | ul = strtoul(nptr, &endptr, 10); |
| 162 | if (endptr <= nptr) |
| 163 | return -EINVAL; |
| 164 | if (trx_id) |
| 165 | *trx_id = ul & 0xffff; |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Holger Hans Peter Freyther | bd85b94 | 2010-01-13 09:06:46 +0100 | [diff] [blame] | 170 | /* send the id ack */ |
| 171 | int ipaccess_send_id_ack(int fd) |
| 172 | { |
| 173 | return write(fd, id_ack, sizeof(id_ack)); |
| 174 | } |
| 175 | |
Holger Hans Peter Freyther | aff3f03 | 2010-02-07 12:04:07 +0100 | [diff] [blame] | 176 | int ipaccess_send_id_req(int fd) |
| 177 | { |
| 178 | return write(fd, id_req, sizeof(id_req)); |
| 179 | } |
| 180 | |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 181 | /* base handling of the ip.access protocol */ |
| 182 | int ipaccess_rcvmsg_base(struct msgb *msg, |
| 183 | struct bsc_fd *bfd) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 184 | { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 185 | u_int8_t msg_type = *(msg->l2h); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 186 | int ret = 0; |
| 187 | |
| 188 | switch (msg_type) { |
| 189 | case IPAC_MSGT_PING: |
| 190 | ret = write(bfd->fd, pong, sizeof(pong)); |
| 191 | break; |
| 192 | case IPAC_MSGT_PONG: |
| 193 | DEBUGP(DMI, "PONG!\n"); |
| 194 | break; |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 195 | case IPAC_MSGT_ID_ACK: |
| 196 | DEBUGP(DMI, "ID_ACK? -> ACK!\n"); |
Holger Hans Peter Freyther | bd85b94 | 2010-01-13 09:06:46 +0100 | [diff] [blame] | 197 | ret = ipaccess_send_id_ack(bfd->fd); |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 198 | break; |
| 199 | } |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static int ipaccess_rcvmsg(struct e1inp_line *line, struct msgb *msg, |
| 204 | struct bsc_fd *bfd) |
| 205 | { |
| 206 | struct tlv_parsed tlvp; |
| 207 | u_int8_t msg_type = *(msg->l2h); |
| 208 | u_int16_t site_id = 0, bts_id = 0, trx_id = 0; |
| 209 | struct gsm_bts *bts; |
| 210 | |
| 211 | /* handle base messages */ |
| 212 | ipaccess_rcvmsg_base(msg, bfd); |
| 213 | |
| 214 | switch (msg_type) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 215 | case IPAC_MSGT_ID_RESP: |
| 216 | DEBUGP(DMI, "ID_RESP "); |
| 217 | /* parse tags, search for Unit ID */ |
Holger Hans Peter Freyther | 5932f64 | 2010-02-09 14:37:23 +0100 | [diff] [blame] | 218 | ipaccess_idtag_parse(&tlvp, (u_int8_t *)msg->l2h + 2, |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 219 | msgb_l2len(msg)-2); |
| 220 | DEBUGP(DMI, "\n"); |
| 221 | |
| 222 | if (!TLVP_PRESENT(&tlvp, IPAC_IDTAG_UNIT)) |
| 223 | break; |
| 224 | |
| 225 | /* lookup BTS, create sign_link, ... */ |
| 226 | parse_unitid((char *)TLVP_VAL(&tlvp, IPAC_IDTAG_UNIT), |
| 227 | &site_id, &bts_id, &trx_id); |
| 228 | bts = find_bts_by_unitid(e1h->gsmnet, site_id, bts_id); |
| 229 | if (!bts) { |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 230 | LOGP(DINP, LOGL_ERROR, "Unable to find BTS configuration for " |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 231 | " %u/%u/%u, disconnecting\n", site_id, bts_id, |
| 232 | trx_id); |
| 233 | return -EIO; |
| 234 | } |
| 235 | DEBUGP(DINP, "Identified BTS %u/%u/%u\n", site_id, bts_id, trx_id); |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 236 | if (bfd->priv_nr == PRIV_OML) { |
| 237 | bts->oml_link = e1inp_sign_link_create(&line->ts[PRIV_OML - 1], |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 238 | E1INP_SIGN_OML, bts->c0, |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 239 | bts->oml_tei, 0); |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 240 | } else if (bfd->priv_nr == PRIV_RSL) { |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 241 | struct e1inp_ts *e1i_ts; |
| 242 | struct bsc_fd *newbfd; |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 243 | struct gsm_bts_trx *trx = gsm_bts_trx_num(bts, trx_id); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 244 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 245 | bfd->data = line = bts->oml_link->ts->line; |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 246 | e1i_ts = &line->ts[PRIV_RSL + trx_id - 1]; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 247 | newbfd = &e1i_ts->driver.ipaccess.fd; |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 248 | e1inp_ts_config(e1i_ts, line, E1INP_TS_TYPE_SIGN); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 249 | |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 250 | trx->rsl_link = e1inp_sign_link_create(e1i_ts, |
| 251 | E1INP_SIGN_RSL, trx, |
| 252 | trx->rsl_tei, 0); |
Holger Hans Peter Freyther | 0ce8fc8 | 2010-03-24 04:02:55 +0100 | [diff] [blame] | 253 | |
| 254 | if (newbfd->fd >= 0) { |
| 255 | LOGP(DINP, LOGL_ERROR, "BTS is still registered. Closing old connection.\n"); |
| 256 | bsc_unregister_fd(newbfd); |
| 257 | close(newbfd->fd); |
| 258 | } |
| 259 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 260 | /* get rid of our old temporary bfd */ |
| 261 | memcpy(newbfd, bfd, sizeof(*newbfd)); |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 262 | newbfd->priv_nr = PRIV_RSL + trx_id; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 263 | bsc_unregister_fd(bfd); |
| 264 | bsc_register_fd(newbfd); |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 265 | talloc_free(bfd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 266 | } |
| 267 | break; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 268 | } |
| 269 | return 0; |
| 270 | } |
| 271 | |
Harald Welte | 5a989a9 | 2009-12-16 17:32:37 +0100 | [diff] [blame] | 272 | #define OML_UP 0x0001 |
| 273 | #define RSL_UP 0x0002 |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 274 | |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 275 | /* |
| 276 | * read one ipa message from the socket |
| 277 | * return NULL in case of error |
| 278 | */ |
| 279 | struct msgb *ipaccess_read_msg(struct bsc_fd *bfd, int *error) |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 280 | { |
Harald Welte | 9cfc935 | 2009-06-26 19:39:35 +0200 | [diff] [blame] | 281 | struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "Abis/IP"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 282 | struct ipaccess_head *hh; |
Sylvain Munaut | 9da8a3a | 2009-10-29 16:33:59 +0100 | [diff] [blame] | 283 | int len, ret = 0; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 284 | |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 285 | if (!msg) { |
| 286 | *error = -ENOMEM; |
| 287 | return NULL; |
| 288 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 289 | |
| 290 | /* first read our 3-byte header */ |
| 291 | hh = (struct ipaccess_head *) msg->data; |
| 292 | ret = recv(bfd->fd, msg->data, 3, 0); |
| 293 | if (ret < 0) { |
Harald Welte | a2be686 | 2009-12-24 13:35:18 +0100 | [diff] [blame] | 294 | if (errno != EAGAIN) |
| 295 | LOGP(DINP, LOGL_ERROR, "recv error %d %s\n", ret, strerror(errno)); |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 296 | msgb_free(msg); |
| 297 | *error = ret; |
| 298 | return NULL; |
| 299 | } else if (ret == 0) { |
| 300 | msgb_free(msg); |
| 301 | *error = ret; |
| 302 | return NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 303 | } |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 304 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 305 | msgb_put(msg, ret); |
| 306 | |
| 307 | /* then read te length as specified in header */ |
| 308 | msg->l2h = msg->data + sizeof(*hh); |
Sylvain Munaut | 9da8a3a | 2009-10-29 16:33:59 +0100 | [diff] [blame] | 309 | len = ntohs(hh->len); |
| 310 | ret = recv(bfd->fd, msg->l2h, len, 0); |
| 311 | if (ret < len) { |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 312 | LOGP(DINP, LOGL_ERROR, "short read!\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 313 | msgb_free(msg); |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 314 | *error = -EIO; |
| 315 | return NULL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 316 | } |
| 317 | msgb_put(msg, ret); |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 318 | |
| 319 | return msg; |
| 320 | } |
| 321 | |
| 322 | static int handle_ts1_read(struct bsc_fd *bfd) |
| 323 | { |
| 324 | struct e1inp_line *line = bfd->data; |
| 325 | unsigned int ts_nr = bfd->priv_nr; |
| 326 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 327 | struct e1inp_sign_link *link; |
| 328 | struct msgb *msg; |
| 329 | struct ipaccess_head *hh; |
Holger Hans Peter Freyther | b84a04a | 2009-10-27 10:08:38 +0100 | [diff] [blame] | 330 | int ret = 0, error; |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 331 | |
| 332 | msg = ipaccess_read_msg(bfd, &error); |
| 333 | if (!msg) { |
| 334 | if (error == 0) { |
Harald Welte (local) | 20bf3c6 | 2009-12-28 17:52:11 +0100 | [diff] [blame] | 335 | link = e1inp_lookup_sign_link(e1i_ts, IPAC_PROTO_OML, 0); |
| 336 | if (link) { |
| 337 | link->trx->bts->ip_access.flags = 0; |
| 338 | LOGP(DINP, LOGL_NOTICE, "BTS %u disappeared, dead socket\n", |
| 339 | link->trx->bts->nr); |
| 340 | } else |
| 341 | LOGP(DINP, LOGL_NOTICE, "unknown BTS disappeared, dead socket\n"); |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 342 | e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, IPAC_PROTO_RSL); |
| 343 | e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, IPAC_PROTO_OML); |
| 344 | bsc_unregister_fd(bfd); |
| 345 | close(bfd->fd); |
| 346 | bfd->fd = -1; |
| 347 | } |
| 348 | return error; |
| 349 | } |
| 350 | |
Sylvain Munaut | 71137ac | 2009-09-30 22:35:04 +0200 | [diff] [blame] | 351 | DEBUGP(DMI, "RX %u: %s\n", ts_nr, hexdump(msgb_l2(msg), msgb_l2len(msg))); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 352 | |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 353 | hh = (struct ipaccess_head *) msg->data; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 354 | if (hh->proto == IPAC_PROTO_IPACCESS) { |
| 355 | ret = ipaccess_rcvmsg(line, msg, bfd); |
| 356 | if (ret < 0) { |
| 357 | e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, IPAC_PROTO_RSL); |
| 358 | e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, IPAC_PROTO_OML); |
| 359 | bsc_unregister_fd(bfd); |
| 360 | close(bfd->fd); |
| 361 | bfd->fd = -1; |
| 362 | } |
| 363 | msgb_free(msg); |
| 364 | return ret; |
| 365 | } |
| 366 | /* BIG FAT WARNING: bfd might no longer exist here, since ipaccess_rcvmsg() |
| 367 | * might have free'd it !!! */ |
| 368 | |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 369 | link = e1inp_lookup_sign_link(e1i_ts, hh->proto, 0); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 370 | if (!link) { |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 371 | LOGP(DINP, LOGL_ERROR, "no matching signalling link for " |
| 372 | "hh->proto=0x%02x\n", hh->proto); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 373 | msgb_free(msg); |
| 374 | return -EIO; |
| 375 | } |
| 376 | msg->trx = link->trx; |
| 377 | |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 378 | switch (link->type) { |
| 379 | case E1INP_SIGN_RSL: |
Harald Welte | ca648f9 | 2009-12-21 23:01:33 +0100 | [diff] [blame] | 380 | if (!(msg->trx->bts->ip_access.flags & (RSL_UP << msg->trx->nr))) { |
Harald Welte | 240ce76 | 2009-10-21 21:16:00 +0200 | [diff] [blame] | 381 | e1inp_event(e1i_ts, EVT_E1_TEI_UP, link->tei, link->sapi); |
Harald Welte | ca648f9 | 2009-12-21 23:01:33 +0100 | [diff] [blame] | 382 | msg->trx->bts->ip_access.flags |= (RSL_UP << msg->trx->nr); |
Harald Welte | 240ce76 | 2009-10-21 21:16:00 +0200 | [diff] [blame] | 383 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 384 | ret = abis_rsl_rcvmsg(msg); |
| 385 | break; |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 386 | case E1INP_SIGN_OML: |
Harald Welte | 5a989a9 | 2009-12-16 17:32:37 +0100 | [diff] [blame] | 387 | if (!(msg->trx->bts->ip_access.flags & OML_UP)) { |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 388 | e1inp_event(e1i_ts, EVT_E1_TEI_UP, link->tei, link->sapi); |
Harald Welte | 5a989a9 | 2009-12-16 17:32:37 +0100 | [diff] [blame] | 389 | msg->trx->bts->ip_access.flags |= OML_UP; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 390 | } |
| 391 | ret = abis_nm_rcvmsg(msg); |
| 392 | break; |
| 393 | default: |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 394 | LOGP(DINP, LOGL_NOTICE, "Unknown IP.access protocol proto=0x%02x\n", hh->proto); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 395 | msgb_free(msg); |
| 396 | break; |
| 397 | } |
| 398 | return ret; |
| 399 | } |
| 400 | |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 401 | void ipaccess_prepend_header(struct msgb *msg, int proto) |
| 402 | { |
| 403 | struct ipaccess_head *hh; |
| 404 | |
| 405 | /* prepend the ip.access header */ |
| 406 | hh = (struct ipaccess_head *) msgb_push(msg, sizeof(*hh)); |
Sylvain Munaut | 9da8a3a | 2009-10-29 16:33:59 +0100 | [diff] [blame] | 407 | hh->len = htons(msg->len - sizeof(*hh)); |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 408 | hh->proto = proto; |
| 409 | } |
| 410 | |
Andreas Eversberg | dd36b0b | 2009-10-08 12:53:16 +0200 | [diff] [blame] | 411 | static int ts_want_write(struct e1inp_ts *e1i_ts) |
| 412 | { |
| 413 | e1i_ts->driver.ipaccess.fd.when |= BSC_FD_WRITE; |
| 414 | |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | static void timeout_ts1_write(void *data) |
| 419 | { |
| 420 | struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data; |
| 421 | |
| 422 | /* trigger write of ts1, due to tx delay timer */ |
| 423 | ts_want_write(e1i_ts); |
| 424 | } |
| 425 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 426 | static int handle_ts1_write(struct bsc_fd *bfd) |
| 427 | { |
| 428 | struct e1inp_line *line = bfd->data; |
| 429 | unsigned int ts_nr = bfd->priv_nr; |
| 430 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 431 | struct e1inp_sign_link *sign_link; |
| 432 | struct msgb *msg; |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 433 | u_int8_t proto; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 434 | int ret; |
| 435 | |
Andreas Eversberg | dd36b0b | 2009-10-08 12:53:16 +0200 | [diff] [blame] | 436 | bfd->when &= ~BSC_FD_WRITE; |
| 437 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 438 | /* get the next msg for this timeslot */ |
| 439 | msg = e1inp_tx_ts(e1i_ts, &sign_link); |
| 440 | if (!msg) { |
Andreas Eversberg | dd36b0b | 2009-10-08 12:53:16 +0200 | [diff] [blame] | 441 | /* no message after tx delay timer */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 442 | return 0; |
| 443 | } |
| 444 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 445 | switch (sign_link->type) { |
| 446 | case E1INP_SIGN_OML: |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 447 | proto = IPAC_PROTO_OML; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 448 | break; |
| 449 | case E1INP_SIGN_RSL: |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 450 | proto = IPAC_PROTO_RSL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 451 | break; |
| 452 | default: |
| 453 | msgb_free(msg); |
Andreas Eversberg | dd36b0b | 2009-10-08 12:53:16 +0200 | [diff] [blame] | 454 | bfd->when |= BSC_FD_WRITE; /* come back for more msg */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 455 | return -EINVAL; |
| 456 | } |
| 457 | |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 458 | msg->l2h = msg->data; |
Harald Welte | 2557287 | 2009-10-20 00:22:00 +0200 | [diff] [blame] | 459 | ipaccess_prepend_header(msg, sign_link->tei); |
Holger Hans Peter Freyther | 7d3573e | 2009-08-18 10:05:45 +0200 | [diff] [blame] | 460 | |
| 461 | DEBUGP(DMI, "TX %u: %s\n", ts_nr, hexdump(msg->l2h, msgb_l2len(msg))); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 462 | |
| 463 | ret = send(bfd->fd, msg->data, msg->len, 0); |
| 464 | msgb_free(msg); |
Andreas Eversberg | dd36b0b | 2009-10-08 12:53:16 +0200 | [diff] [blame] | 465 | |
| 466 | /* set tx delay timer for next event */ |
| 467 | e1i_ts->sign.tx_timer.cb = timeout_ts1_write; |
| 468 | e1i_ts->sign.tx_timer.data = e1i_ts; |
| 469 | bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 100000); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 470 | |
| 471 | return ret; |
| 472 | } |
| 473 | |
| 474 | /* callback from select.c in case one of the fd's can be read/written */ |
| 475 | static int ipaccess_fd_cb(struct bsc_fd *bfd, unsigned int what) |
| 476 | { |
| 477 | struct e1inp_line *line = bfd->data; |
| 478 | unsigned int ts_nr = bfd->priv_nr; |
| 479 | unsigned int idx = ts_nr-1; |
| 480 | struct e1inp_ts *e1i_ts; |
| 481 | int rc = 0; |
| 482 | |
| 483 | /* In case of early RSL we might not yet have a line */ |
| 484 | |
| 485 | if (line) |
| 486 | e1i_ts = &line->ts[idx]; |
| 487 | |
| 488 | if (!line || e1i_ts->type == E1INP_TS_TYPE_SIGN) { |
| 489 | if (what & BSC_FD_READ) |
| 490 | rc = handle_ts1_read(bfd); |
| 491 | if (what & BSC_FD_WRITE) |
| 492 | rc = handle_ts1_write(bfd); |
| 493 | } else |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 494 | LOGP(DINP, LOGL_ERROR, "unknown E1 TS type %u\n", e1i_ts->type); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 495 | |
| 496 | return rc; |
| 497 | } |
| 498 | |
| 499 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 500 | struct e1inp_driver ipaccess_driver = { |
| 501 | .name = "ip.access", |
| 502 | .want_write = ts_want_write, |
| 503 | }; |
| 504 | |
| 505 | /* callback of the OML listening filedescriptor */ |
| 506 | static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) |
| 507 | { |
| 508 | int ret; |
| 509 | int idx = 0; |
| 510 | struct e1inp_line *line; |
| 511 | struct e1inp_ts *e1i_ts; |
| 512 | struct bsc_fd *bfd; |
| 513 | struct sockaddr_in sa; |
| 514 | socklen_t sa_len = sizeof(sa); |
| 515 | |
| 516 | if (!(what & BSC_FD_READ)) |
| 517 | return 0; |
| 518 | |
| 519 | ret = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len); |
| 520 | if (ret < 0) { |
| 521 | perror("accept"); |
| 522 | return ret; |
| 523 | } |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 524 | LOGP(DINP, LOGL_NOTICE, "accept()ed new OML link from %s\n", |
| 525 | inet_ntoa(sa.sin_addr)); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 526 | |
Holger Hans Peter Freyther | e453348 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 527 | line = talloc_zero(tall_bsc_ctx, struct e1inp_line); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 528 | if (!line) { |
| 529 | close(ret); |
| 530 | return -ENOMEM; |
| 531 | } |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 532 | line->driver = &ipaccess_driver; |
| 533 | //line->driver_data = e1h; |
| 534 | /* create virrtual E1 timeslots for signalling */ |
| 535 | e1inp_ts_config(&line->ts[1-1], line, E1INP_TS_TYPE_SIGN); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 536 | |
| 537 | e1i_ts = &line->ts[idx]; |
| 538 | |
| 539 | bfd = &e1i_ts->driver.ipaccess.fd; |
| 540 | bfd->fd = ret; |
| 541 | bfd->data = line; |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 542 | bfd->priv_nr = PRIV_OML; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 543 | bfd->cb = ipaccess_fd_cb; |
| 544 | bfd->when = BSC_FD_READ; |
| 545 | ret = bsc_register_fd(bfd); |
| 546 | if (ret < 0) { |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 547 | LOGP(DINP, LOGL_ERROR, "could not register FD\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 548 | close(bfd->fd); |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 549 | talloc_free(line); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 550 | return ret; |
| 551 | } |
| 552 | |
| 553 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
Holger Hans Peter Freyther | aff3f03 | 2010-02-07 12:04:07 +0100 | [diff] [blame] | 554 | ret = ipaccess_send_id_req(bfd->fd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 555 | |
Holger Hans Peter Freyther | 182c745 | 2009-08-10 07:59:27 +0200 | [diff] [blame] | 556 | return ret; |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 557 | //return e1inp_line_register(line); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what) |
| 561 | { |
| 562 | struct sockaddr_in sa; |
| 563 | socklen_t sa_len = sizeof(sa); |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 564 | struct bsc_fd *bfd; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 565 | int ret; |
| 566 | |
| 567 | if (!(what & BSC_FD_READ)) |
| 568 | return 0; |
| 569 | |
Holger Hans Peter Freyther | e453348 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 570 | bfd = talloc_zero(tall_bsc_ctx, struct bsc_fd); |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 571 | if (!bfd) |
| 572 | return -ENOMEM; |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 573 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 574 | /* Some BTS has connected to us, but we don't know yet which line |
| 575 | * (as created by the OML link) to associate it with. Thus, we |
Holger Hans Peter Freyther | 9e30772 | 2009-11-15 13:50:39 +0100 | [diff] [blame] | 576 | * allocate a temporary bfd until we have received ID from BTS */ |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 577 | |
| 578 | bfd->fd = accept(listen_bfd->fd, (struct sockaddr *) &sa, &sa_len); |
| 579 | if (bfd->fd < 0) { |
| 580 | perror("accept"); |
| 581 | return bfd->fd; |
| 582 | } |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 583 | LOGP(DINP, LOGL_NOTICE, "accept()ed new RSL link from %s\n", inet_ntoa(sa.sin_addr)); |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 584 | bfd->priv_nr = PRIV_RSL; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 585 | bfd->cb = ipaccess_fd_cb; |
| 586 | bfd->when = BSC_FD_READ; |
| 587 | ret = bsc_register_fd(bfd); |
| 588 | if (ret < 0) { |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 589 | LOGP(DINP, LOGL_ERROR, "could not register FD\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 590 | close(bfd->fd); |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 591 | talloc_free(bfd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 592 | return ret; |
| 593 | } |
| 594 | /* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */ |
| 595 | ret = write(bfd->fd, id_req, sizeof(id_req)); |
| 596 | |
| 597 | return 0; |
| 598 | } |
| 599 | |
| 600 | static int make_sock(struct bsc_fd *bfd, u_int16_t port, |
| 601 | int (*cb)(struct bsc_fd *fd, unsigned int what)) |
| 602 | { |
| 603 | struct sockaddr_in addr; |
| 604 | int ret, on = 1; |
| 605 | |
| 606 | bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 607 | bfd->cb = cb; |
| 608 | bfd->when = BSC_FD_READ; |
| 609 | //bfd->data = line; |
| 610 | |
Holger Hans Peter Freyther | 2077ac1 | 2010-02-19 13:07:05 +0100 | [diff] [blame] | 611 | if (bfd->fd < 0) { |
| 612 | LOGP(DINP, LOGL_ERROR, "could not create TCP socket.\n"); |
| 613 | return -EIO; |
| 614 | } |
| 615 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 616 | memset(&addr, 0, sizeof(addr)); |
| 617 | addr.sin_family = AF_INET; |
| 618 | addr.sin_port = htons(port); |
| 619 | addr.sin_addr.s_addr = INADDR_ANY; |
| 620 | |
| 621 | setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
| 622 | |
| 623 | ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr)); |
| 624 | if (ret < 0) { |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 625 | LOGP(DINP, LOGL_ERROR, "could not bind l2 socket %s\n", |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 626 | strerror(errno)); |
Holger Hans Peter Freyther | 2077ac1 | 2010-02-19 13:07:05 +0100 | [diff] [blame] | 627 | close(bfd->fd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 628 | return -EIO; |
| 629 | } |
| 630 | |
| 631 | ret = listen(bfd->fd, 1); |
| 632 | if (ret < 0) { |
| 633 | perror("listen"); |
Holger Hans Peter Freyther | 2077ac1 | 2010-02-19 13:07:05 +0100 | [diff] [blame] | 634 | close(bfd->fd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 635 | return ret; |
| 636 | } |
| 637 | |
| 638 | ret = bsc_register_fd(bfd); |
| 639 | if (ret < 0) { |
| 640 | perror("register_listen_fd"); |
Holger Hans Peter Freyther | 2077ac1 | 2010-02-19 13:07:05 +0100 | [diff] [blame] | 641 | close(bfd->fd); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 642 | return ret; |
| 643 | } |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | /* Actively connect to a BTS. Currently used by ipaccess-config.c */ |
| 648 | int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa) |
| 649 | { |
| 650 | struct e1inp_ts *e1i_ts = &line->ts[0]; |
| 651 | struct bsc_fd *bfd = &e1i_ts->driver.ipaccess.fd; |
| 652 | int ret, on = 1; |
| 653 | |
| 654 | bfd->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 655 | bfd->cb = ipaccess_fd_cb; |
| 656 | bfd->when = BSC_FD_READ | BSC_FD_WRITE; |
| 657 | bfd->data = line; |
Holger Hans Peter Freyther | 9d7b638 | 2010-03-24 04:56:13 +0100 | [diff] [blame] | 658 | bfd->priv_nr = PRIV_OML; |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 659 | |
Holger Hans Peter Freyther | 2077ac1 | 2010-02-19 13:07:05 +0100 | [diff] [blame] | 660 | if (bfd->fd < 0) { |
| 661 | LOGP(DINP, LOGL_ERROR, "could not create TCP socket.\n"); |
| 662 | return -EIO; |
| 663 | } |
| 664 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 665 | setsockopt(bfd->fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
| 666 | |
| 667 | ret = connect(bfd->fd, (struct sockaddr *) sa, sizeof(*sa)); |
| 668 | if (ret < 0) { |
Harald Welte | 5a13a45 | 2009-12-23 23:01:04 +0100 | [diff] [blame] | 669 | LOGP(DINP, LOGL_ERROR, "could not connect socket\n"); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 670 | close(bfd->fd); |
| 671 | return ret; |
| 672 | } |
| 673 | |
| 674 | ret = bsc_register_fd(bfd); |
| 675 | if (ret < 0) { |
| 676 | close(bfd->fd); |
| 677 | return ret; |
| 678 | } |
| 679 | |
| 680 | line->driver = &ipaccess_driver; |
| 681 | |
Holger Hans Peter Freyther | 182c745 | 2009-08-10 07:59:27 +0200 | [diff] [blame] | 682 | return ret; |
Harald Welte | 6286888 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 683 | //return e1inp_line_register(line); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | int ipaccess_setup(struct gsm_network *gsmnet) |
| 687 | { |
| 688 | int ret; |
| 689 | |
| 690 | /* register the driver with the core */ |
| 691 | /* FIXME: do this in the plugin initializer function */ |
| 692 | ret = e1inp_driver_register(&ipaccess_driver); |
| 693 | if (ret) |
| 694 | return ret; |
| 695 | |
Holger Hans Peter Freyther | e453348 | 2009-10-29 02:29:45 +0100 | [diff] [blame] | 696 | e1h = talloc_zero(tall_bsc_ctx, struct ia_e1_handle); |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 697 | if (!e1h) |
| 698 | return -ENOMEM; |
Harald Welte | 49a8405 | 2009-06-22 01:36:25 +0200 | [diff] [blame] | 699 | |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 700 | e1h->gsmnet = gsmnet; |
| 701 | |
| 702 | /* Listen for OML connections */ |
Harald Welte | 9994b18 | 2009-12-23 22:47:53 +0100 | [diff] [blame] | 703 | ret = make_sock(&e1h->listen_fd, IPA_TCP_PORT_OML, listen_fd_cb); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 704 | if (ret < 0) |
| 705 | return ret; |
| 706 | |
| 707 | /* Listen for RSL connections */ |
Harald Welte | 9994b18 | 2009-12-23 22:47:53 +0100 | [diff] [blame] | 708 | ret = make_sock(&e1h->rsl_listen_fd, IPA_TCP_PORT_RSL, rsl_listen_fd_cb); |
Harald Welte | 59b0468 | 2009-06-10 05:40:52 +0800 | [diff] [blame] | 709 | |
| 710 | return ret; |
| 711 | } |