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