Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 1 | /* OpenBSC Abis input driver for DAHDI */ |
| 2 | |
| 3 | /* (C) 2008-2011 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 5 | * (C) 2010 by Digium and Matthew Fredrickson <creslin@digium.com> |
| 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 General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 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 General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
Holger Hans Peter Freyther | d9d1b5c | 2014-09-25 18:47:12 +0200 | [diff] [blame] | 25 | #include "config.h" |
Harald Welte | 3bc7885 | 2011-08-24 08:32:38 +0200 | [diff] [blame] | 26 | |
| 27 | #ifdef HAVE_DAHDI_USER_H |
| 28 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <unistd.h> |
| 31 | #include <stdlib.h> |
| 32 | #include <errno.h> |
| 33 | #include <string.h> |
| 34 | #include <time.h> |
| 35 | #include <sys/fcntl.h> |
| 36 | #include <sys/socket.h> |
| 37 | #include <sys/ioctl.h> |
| 38 | #include <arpa/inet.h> |
| 39 | #include <dahdi/user.h> |
| 40 | |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 41 | #include <osmocom/core/talloc.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 42 | #include <osmocom/core/select.h> |
| 43 | #include <osmocom/core/msgb.h> |
Pablo Neira Ayuso | 0b9ed9a | 2011-07-02 17:25:19 +0200 | [diff] [blame] | 44 | #include <osmocom/core/logging.h> |
Pablo Neira Ayuso | a20762a | 2011-07-02 19:01:58 +0200 | [diff] [blame] | 45 | #include <osmocom/core/signal.h> |
Harald Welte | 95e5dec | 2011-08-16 14:41:32 +0200 | [diff] [blame] | 46 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 47 | |
| 48 | #include <osmocom/vty/vty.h> |
| 49 | |
Pablo Neira Ayuso | 0b9ed9a | 2011-07-02 17:25:19 +0200 | [diff] [blame] | 50 | #include <osmocom/abis/subchan_demux.h> |
| 51 | #include <osmocom/abis/e1_input.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 52 | |
Pablo Neira Ayuso | 355ce69 | 2011-07-05 14:53:37 +0200 | [diff] [blame] | 53 | #include <osmocom/abis/lapd.h> |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 54 | |
| 55 | #define TS1_ALLOC_SIZE 300 |
| 56 | |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 57 | struct span_cfg { |
| 58 | struct llist_head list; |
| 59 | |
| 60 | unsigned int span_nr; |
| 61 | unsigned int chan_base; |
| 62 | unsigned int chan_num; |
| 63 | }; |
| 64 | |
| 65 | static struct span_cfg *span_cfgs[DAHDI_MAX_SPANS]; |
| 66 | |
| 67 | static int reread_span_cfgs(void) |
| 68 | { |
| 69 | struct dahdi_spaninfo si; |
| 70 | unsigned int basechan = 1; |
Harald Welte | 494f290 | 2011-09-26 23:06:49 +0200 | [diff] [blame] | 71 | int span_nr; |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 72 | int fd; |
| 73 | |
| 74 | if ((fd = open("/dev/dahdi/ctl", O_RDWR)) < 0) { |
| 75 | LOGP(DLMI, LOGL_ERROR, "Unable to open DAHDI ctl: %s\n", |
| 76 | strerror(errno)); |
| 77 | return -EIO; |
| 78 | } |
| 79 | |
Harald Welte | e2bd685 | 2011-09-26 23:03:12 +0200 | [diff] [blame] | 80 | for (span_nr = 1; span_nr < DAHDI_MAX_SPANS; span_nr++) { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 81 | struct span_cfg *scfg; |
Harald Welte | e2bd685 | 2011-09-26 23:03:12 +0200 | [diff] [blame] | 82 | /* our array index starts at 0, but DAHDI span at 1 */ |
| 83 | int i = span_nr - 1; |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 84 | |
| 85 | /* clear any old cached information */ |
| 86 | if (span_cfgs[i]) { |
| 87 | talloc_free(span_cfgs[i]); |
| 88 | span_cfgs[i] = NULL; |
| 89 | } |
| 90 | |
| 91 | memset(&si, 0, sizeof(si)); |
Harald Welte | e2bd685 | 2011-09-26 23:03:12 +0200 | [diff] [blame] | 92 | si.spanno = span_nr; |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 93 | if (ioctl(fd, DAHDI_SPANSTAT, &si)) |
| 94 | continue; |
| 95 | |
| 96 | /* create and link new span_cfg */ |
| 97 | scfg = talloc_zero(NULL, struct span_cfg); |
| 98 | if (!scfg) { |
| 99 | close(fd); |
| 100 | return -ENOMEM; |
| 101 | } |
Harald Welte | e2bd685 | 2011-09-26 23:03:12 +0200 | [diff] [blame] | 102 | scfg->span_nr = span_nr; |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 103 | scfg->chan_num = si.totalchans; |
| 104 | scfg->chan_base = basechan; |
| 105 | span_cfgs[i] = scfg; |
| 106 | |
| 107 | basechan += si.totalchans; |
| 108 | } |
| 109 | |
| 110 | close(fd); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 115 | /* Corresponds to dahdi/user.h, only PRI related events */ |
| 116 | static const struct value_string dahdi_evt_names[] = { |
| 117 | { DAHDI_EVENT_NONE, "NONE" }, |
| 118 | { DAHDI_EVENT_ALARM, "ALARM" }, |
| 119 | { DAHDI_EVENT_NOALARM, "NOALARM" }, |
| 120 | { DAHDI_EVENT_ABORT, "HDLC ABORT" }, |
| 121 | { DAHDI_EVENT_OVERRUN, "HDLC OVERRUN" }, |
| 122 | { DAHDI_EVENT_BADFCS, "HDLC BAD FCS" }, |
| 123 | { DAHDI_EVENT_REMOVED, "REMOVED" }, |
| 124 | { 0, NULL } |
| 125 | }; |
| 126 | |
| 127 | static void handle_dahdi_exception(struct e1inp_ts *ts) |
| 128 | { |
| 129 | int rc, evt; |
Harald Welte | 95e5dec | 2011-08-16 14:41:32 +0200 | [diff] [blame] | 130 | struct e1inp_line *line = ts->line; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 131 | struct input_signal_data isd; |
| 132 | |
| 133 | rc = ioctl(ts->driver.dahdi.fd.fd, DAHDI_GETEVENT, &evt); |
| 134 | if (rc < 0) |
| 135 | return; |
| 136 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 137 | LOGP(DLMI, LOGL_NOTICE, "Line %u(%s) / TS %u DAHDI EVENT %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 138 | ts->line->num, ts->line->name, ts->num, |
| 139 | get_value_string(dahdi_evt_names, evt)); |
| 140 | |
| 141 | isd.line = ts->line; |
Harald Welte | f35d889 | 2016-10-16 15:33:52 +0200 | [diff] [blame] | 142 | isd.ts_nr = ts->num; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 143 | |
| 144 | switch (evt) { |
| 145 | case DAHDI_EVENT_ALARM: |
| 146 | /* we should notify the code that the line is gone */ |
Pablo Neira Ayuso | de66891 | 2011-08-16 17:26:23 +0200 | [diff] [blame] | 147 | osmo_signal_dispatch(SS_L_INPUT, S_L_INP_LINE_ALARM, &isd); |
Harald Welte | 95e5dec | 2011-08-16 14:41:32 +0200 | [diff] [blame] | 148 | rate_ctr_inc(&line->rate_ctr->ctr[E1I_CTR_ALARM]); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 149 | break; |
| 150 | case DAHDI_EVENT_NOALARM: |
| 151 | /* alarm has gone, we should re-start the SABM requests */ |
Pablo Neira Ayuso | de66891 | 2011-08-16 17:26:23 +0200 | [diff] [blame] | 152 | osmo_signal_dispatch(SS_L_INPUT, S_L_INP_LINE_NOALARM, &isd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 153 | break; |
Harald Welte | 95e5dec | 2011-08-16 14:41:32 +0200 | [diff] [blame] | 154 | case DAHDI_EVENT_ABORT: |
| 155 | rate_ctr_inc(&line->rate_ctr->ctr[E1I_CTR_HDLC_ABORT]); |
| 156 | break; |
| 157 | case DAHDI_EVENT_OVERRUN: |
| 158 | rate_ctr_inc(&line->rate_ctr->ctr[E1I_CTR_HDLC_OVERR]); |
| 159 | break; |
| 160 | case DAHDI_EVENT_BADFCS: |
| 161 | rate_ctr_inc(&line->rate_ctr->ctr[E1I_CTR_HDLC_BADFCS]); |
| 162 | break; |
| 163 | case DAHDI_EVENT_REMOVED: |
| 164 | rate_ctr_inc(&line->rate_ctr->ctr[E1I_CTR_REMOVED]); |
| 165 | break; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
| 169 | static int handle_ts1_read(struct osmo_fd *bfd) |
| 170 | { |
| 171 | struct e1inp_line *line = bfd->data; |
| 172 | unsigned int ts_nr = bfd->priv_nr; |
| 173 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 174 | struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "DAHDI TS1"); |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 175 | int ret; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 176 | |
| 177 | if (!msg) |
| 178 | return -ENOMEM; |
| 179 | |
| 180 | ret = read(bfd->fd, msg->data, TS1_ALLOC_SIZE - 16); |
| 181 | if (ret == -1) |
| 182 | handle_dahdi_exception(e1i_ts); |
| 183 | else if (ret < 0) { |
| 184 | perror("read "); |
| 185 | } |
| 186 | msgb_put(msg, ret - 2); |
| 187 | if (ret <= 3) { |
| 188 | perror("read "); |
| 189 | } |
| 190 | |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 191 | return e1inp_rx_ts_lapd(e1i_ts, msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | static int ts_want_write(struct e1inp_ts *e1i_ts) |
| 195 | { |
| 196 | /* We never include the DAHDI B-Channel FD into the |
| 197 | * writeset, since it doesn't support poll() based |
| 198 | * write flow control */ |
| 199 | if (e1i_ts->type == E1INP_TS_TYPE_TRAU) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 200 | LOGP(DLINP, LOGL_DEBUG, "Trying to write TRAU ts\n"); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 201 | return 0; |
| 202 | } |
| 203 | |
| 204 | e1i_ts->driver.dahdi.fd.when |= BSC_FD_WRITE; |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | static void timeout_ts1_write(void *data) |
| 210 | { |
| 211 | struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data; |
| 212 | |
| 213 | /* trigger write of ts1, due to tx delay timer */ |
| 214 | ts_want_write(e1i_ts); |
| 215 | } |
| 216 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 217 | static void dahdi_write_msg(struct msgb *msg, void *cbdata) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 218 | { |
| 219 | struct osmo_fd *bfd = cbdata; |
| 220 | struct e1inp_line *line = bfd->data; |
| 221 | unsigned int ts_nr = bfd->priv_nr; |
| 222 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 223 | int ret; |
| 224 | |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 225 | ret = write(bfd->fd, msg->data, msg->len + 2); |
| 226 | msgb_free(msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 227 | if (ret == -1) |
| 228 | handle_dahdi_exception(e1i_ts); |
| 229 | else if (ret < 0) |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 230 | LOGP(DLMI, LOGL_NOTICE, "%s write failed %d\n", __func__, ret); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | static int handle_ts1_write(struct osmo_fd *bfd) |
| 234 | { |
| 235 | struct e1inp_line *line = bfd->data; |
| 236 | unsigned int ts_nr = bfd->priv_nr; |
| 237 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 238 | struct e1inp_sign_link *sign_link; |
| 239 | struct msgb *msg; |
| 240 | |
| 241 | bfd->when &= ~BSC_FD_WRITE; |
| 242 | |
| 243 | /* get the next msg for this timeslot */ |
| 244 | msg = e1inp_tx_ts(e1i_ts, &sign_link); |
| 245 | if (!msg) { |
| 246 | /* no message after tx delay timer */ |
| 247 | return 0; |
| 248 | } |
| 249 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 250 | DEBUGP(DLMI, "TX: %s\n", osmo_hexdump(msg->data, msg->len)); |
Harald Welte | fd44a5f | 2011-08-21 00:48:54 +0200 | [diff] [blame] | 251 | lapd_transmit(e1i_ts->lapd, sign_link->tei, |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 252 | sign_link->sapi, msg); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 253 | |
| 254 | /* set tx delay timer for next event */ |
| 255 | e1i_ts->sign.tx_timer.cb = timeout_ts1_write; |
| 256 | e1i_ts->sign.tx_timer.data = e1i_ts; |
| 257 | osmo_timer_schedule(&e1i_ts->sign.tx_timer, 0, 50000); |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Harald Welte | 7a228eb | 2016-07-28 11:09:31 +0200 | [diff] [blame] | 262 | static void handle_hdlc_write(struct osmo_fd *bfd) |
| 263 | { |
| 264 | struct e1inp_line *line = bfd->data; |
| 265 | unsigned int ts_nr = bfd->priv_nr; |
| 266 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 267 | struct msgb *msg; |
| 268 | int ret; |
| 269 | |
| 270 | /* get the next msg for this timeslot */ |
| 271 | msg = e1inp_tx_ts(e1i_ts, NULL); |
| 272 | if (!msg) |
| 273 | return; |
| 274 | |
| 275 | ret = write(bfd->fd, msg->data, msg->len + 2); |
| 276 | msgb_free(msg); |
| 277 | if (ret == -1) |
| 278 | handle_dahdi_exception(e1i_ts); |
| 279 | else if (ret < 0) |
| 280 | LOGP(DLMI, LOGL_NOTICE, "%s write failed %d\n", __func__, ret); |
| 281 | } |
| 282 | |
| 283 | static int handle_hdlc_read(struct osmo_fd *bfd) |
| 284 | { |
| 285 | struct e1inp_line *line = bfd->data; |
| 286 | unsigned int ts_nr = bfd->priv_nr; |
| 287 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 288 | struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "DAHDI HDLC Rx"); |
| 289 | int ret; |
| 290 | |
| 291 | if (!msg) |
| 292 | return -ENOMEM; |
| 293 | |
| 294 | ret = read(bfd->fd, msg->data, TS1_ALLOC_SIZE - 16); |
| 295 | if (ret == -1) |
| 296 | handle_dahdi_exception(e1i_ts); |
| 297 | else if (ret < 0) { |
| 298 | perror("read "); |
| 299 | } |
| 300 | msgb_put(msg, ret - 2); |
| 301 | if (ret <= 3) { |
| 302 | perror("read "); |
| 303 | } |
| 304 | |
| 305 | return e1inp_rx_ts(e1i_ts, msg, 0, 0); |
| 306 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 307 | |
| 308 | static int invertbits = 1; |
| 309 | |
| 310 | static uint8_t flip_table[256]; |
| 311 | |
| 312 | static void init_flip_bits(void) |
| 313 | { |
| 314 | int i,k; |
| 315 | |
| 316 | for (i = 0 ; i < 256 ; i++) { |
| 317 | uint8_t sample = 0 ; |
| 318 | for (k = 0; k<8; k++) { |
| 319 | if ( i & 1 << k ) sample |= 0x80 >> k; |
| 320 | } |
| 321 | flip_table[i] = sample; |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | static uint8_t * flip_buf_bits ( uint8_t * buf , int len) |
| 326 | { |
| 327 | int i; |
| 328 | uint8_t * start = buf; |
| 329 | |
| 330 | for (i = 0 ; i < len; i++) { |
| 331 | buf[i] = flip_table[(uint8_t)buf[i]]; |
| 332 | } |
| 333 | |
| 334 | return start; |
| 335 | } |
| 336 | |
| 337 | #define D_BCHAN_TX_GRAN 160 |
| 338 | /* write to a B channel TS */ |
| 339 | static int handle_tsX_write(struct osmo_fd *bfd) |
| 340 | { |
| 341 | struct e1inp_line *line = bfd->data; |
| 342 | unsigned int ts_nr = bfd->priv_nr; |
| 343 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 344 | uint8_t tx_buf[D_BCHAN_TX_GRAN]; |
| 345 | struct subch_mux *mx = &e1i_ts->trau.mux; |
| 346 | int ret; |
| 347 | |
| 348 | ret = subchan_mux_out(mx, tx_buf, D_BCHAN_TX_GRAN); |
| 349 | |
| 350 | if (ret != D_BCHAN_TX_GRAN) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 351 | LOGP(DLINP, LOGL_DEBUG, "Huh, got ret of %d\n", ret); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 352 | if (ret < 0) |
| 353 | return ret; |
| 354 | } |
| 355 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 356 | DEBUGP(DLMIB, "BCHAN TX: %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 357 | osmo_hexdump(tx_buf, D_BCHAN_TX_GRAN)); |
| 358 | |
| 359 | if (invertbits) { |
| 360 | flip_buf_bits(tx_buf, ret); |
| 361 | } |
| 362 | |
| 363 | ret = write(bfd->fd, tx_buf, ret); |
| 364 | if (ret < D_BCHAN_TX_GRAN) |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 365 | LOGP(DLINP, LOGL_DEBUG, "send returns %d instead of %d\n", |
| 366 | ret, D_BCHAN_TX_GRAN); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 367 | |
| 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | #define D_TSX_ALLOC_SIZE (D_BCHAN_TX_GRAN) |
| 372 | /* FIXME: read from a B channel TS */ |
| 373 | static int handle_tsX_read(struct osmo_fd *bfd) |
| 374 | { |
| 375 | struct e1inp_line *line = bfd->data; |
| 376 | unsigned int ts_nr = bfd->priv_nr; |
| 377 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 378 | struct msgb *msg = msgb_alloc(D_TSX_ALLOC_SIZE, "DAHDI TSx"); |
| 379 | int ret; |
| 380 | |
| 381 | if (!msg) |
| 382 | return -ENOMEM; |
| 383 | |
| 384 | ret = read(bfd->fd, msg->data, D_TSX_ALLOC_SIZE); |
| 385 | if (ret < 0 || ret != D_TSX_ALLOC_SIZE) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 386 | LOGP(DLINP, LOGL_DEBUG, "read error %d %s\n", |
| 387 | ret, strerror(errno)); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 388 | return ret; |
| 389 | } |
| 390 | |
| 391 | if (invertbits) { |
| 392 | flip_buf_bits(msg->data, ret); |
| 393 | } |
| 394 | |
| 395 | msgb_put(msg, ret); |
| 396 | |
| 397 | msg->l2h = msg->data; |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 398 | DEBUGP(DLMIB, "BCHAN RX: %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 399 | osmo_hexdump(msgb_l2(msg), ret)); |
| 400 | ret = e1inp_rx_ts(e1i_ts, msg, 0, 0); |
| 401 | /* physical layer indicates that data has been sent, |
| 402 | * we thus can send some more data */ |
| 403 | ret = handle_tsX_write(bfd); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 404 | |
| 405 | return ret; |
| 406 | } |
| 407 | |
Harald Welte | a0108e7 | 2016-07-27 21:44:50 +0200 | [diff] [blame] | 408 | /* write to a raw channel TS */ |
| 409 | static int handle_ts_raw_write(struct osmo_fd *bfd) |
| 410 | { |
| 411 | struct e1inp_line *line = bfd->data; |
| 412 | unsigned int ts_nr = bfd->priv_nr; |
| 413 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 414 | struct msgb *msg; |
| 415 | int ret; |
| 416 | |
| 417 | /* get the next msg for this timeslot */ |
| 418 | msg = e1inp_tx_ts(e1i_ts, NULL); |
| 419 | if (!msg) |
| 420 | return 0; |
| 421 | |
| 422 | if (msg->len != D_BCHAN_TX_GRAN) { |
| 423 | /* This might lead to a transmit underrun, as we call tx |
| 424 | * from the rx path, as there's no select/poll on dahdi |
| 425 | * */ |
| 426 | LOGP(DLINP, LOGL_NOTICE, "unexpected msg->len = %u, " |
| 427 | "expected %u\n", msg->len, D_BCHAN_TX_GRAN); |
| 428 | } |
| 429 | |
| 430 | DEBUGP(DLMIB, "RAW CHAN TX: %s\n", |
| 431 | osmo_hexdump(msg->data, msg->len)); |
| 432 | |
| 433 | if (0/*invertbits*/) { |
| 434 | flip_buf_bits(msg->data, msg->len); |
| 435 | } |
| 436 | |
| 437 | ret = write(bfd->fd, msg->data, msg->len); |
| 438 | if (ret < msg->len) |
| 439 | LOGP(DLINP, LOGL_DEBUG, "send returns %d instead of %d\n", |
| 440 | ret, msg->len); |
| 441 | msgb_free(msg); |
| 442 | |
| 443 | return ret; |
| 444 | } |
| 445 | |
| 446 | static int handle_ts_raw_read(struct osmo_fd *bfd) |
| 447 | { |
| 448 | struct e1inp_line *line = bfd->data; |
| 449 | unsigned int ts_nr = bfd->priv_nr; |
| 450 | struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1]; |
| 451 | struct msgb *msg = msgb_alloc(D_TSX_ALLOC_SIZE, "DAHDI Raw TS"); |
| 452 | int ret; |
| 453 | |
| 454 | if (!msg) |
| 455 | return -ENOMEM; |
| 456 | |
| 457 | ret = read(bfd->fd, msg->data, D_TSX_ALLOC_SIZE); |
| 458 | if (ret < 0 || ret != D_TSX_ALLOC_SIZE) { |
| 459 | LOGP(DLINP, LOGL_DEBUG, "read error %d %s\n", |
| 460 | ret, strerror(errno)); |
| 461 | return ret; |
| 462 | } |
| 463 | |
| 464 | if (0/*invertbits*/) { |
| 465 | flip_buf_bits(msg->data, ret); |
| 466 | } |
| 467 | |
| 468 | msgb_put(msg, ret); |
| 469 | |
| 470 | msg->l2h = msg->data; |
| 471 | DEBUGP(DLMIB, "RAW CHAN RX: %s\n", |
| 472 | osmo_hexdump(msgb_l2(msg), ret)); |
| 473 | ret = e1inp_rx_ts(e1i_ts, msg, 0, 0); |
| 474 | /* physical layer indicates that data has been sent, |
| 475 | * we thus can send some more data */ |
| 476 | ret = handle_ts_raw_write(bfd); |
| 477 | |
| 478 | return ret; |
| 479 | } |
| 480 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 481 | /* callback from select.c in case one of the fd's can be read/written */ |
| 482 | static int dahdi_fd_cb(struct osmo_fd *bfd, unsigned int what) |
| 483 | { |
| 484 | struct e1inp_line *line = bfd->data; |
| 485 | unsigned int ts_nr = bfd->priv_nr; |
| 486 | unsigned int idx = ts_nr-1; |
| 487 | struct e1inp_ts *e1i_ts = &line->ts[idx]; |
| 488 | int rc = 0; |
| 489 | |
| 490 | switch (e1i_ts->type) { |
| 491 | case E1INP_TS_TYPE_SIGN: |
| 492 | if (what & BSC_FD_EXCEPT) |
| 493 | handle_dahdi_exception(e1i_ts); |
| 494 | if (what & BSC_FD_READ) |
| 495 | rc = handle_ts1_read(bfd); |
| 496 | if (what & BSC_FD_WRITE) |
| 497 | rc = handle_ts1_write(bfd); |
| 498 | break; |
Harald Welte | 7a228eb | 2016-07-28 11:09:31 +0200 | [diff] [blame] | 499 | case E1INP_TS_TYPE_HDLC: |
| 500 | if (what & BSC_FD_EXCEPT) |
| 501 | handle_dahdi_exception(e1i_ts); |
| 502 | if (what & BSC_FD_READ) |
| 503 | rc = handle_hdlc_read(bfd); |
| 504 | if (what & BSC_FD_WRITE) |
| 505 | handle_hdlc_write(bfd); |
| 506 | break; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 507 | case E1INP_TS_TYPE_TRAU: |
| 508 | if (what & BSC_FD_EXCEPT) |
| 509 | handle_dahdi_exception(e1i_ts); |
| 510 | if (what & BSC_FD_READ) |
| 511 | rc = handle_tsX_read(bfd); |
| 512 | if (what & BSC_FD_WRITE) |
| 513 | rc = handle_tsX_write(bfd); |
| 514 | /* We never include the DAHDI B-Channel FD into the |
| 515 | * writeset, since it doesn't support poll() based |
| 516 | * write flow control */ |
| 517 | break; |
Harald Welte | a0108e7 | 2016-07-27 21:44:50 +0200 | [diff] [blame] | 518 | case E1INP_TS_TYPE_RAW: |
| 519 | if (what & BSC_FD_EXCEPT) |
| 520 | handle_dahdi_exception(e1i_ts); |
| 521 | if (what & BSC_FD_READ) |
| 522 | rc = handle_ts_raw_read(bfd); |
| 523 | if (what & BSC_FD_WRITE) |
| 524 | rc = handle_ts_raw_write(bfd); |
| 525 | /* We never include the DAHDI B-Channel FD into the |
| 526 | * writeset, since it doesn't support poll() based |
| 527 | * write flow control */ |
| 528 | break; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 529 | default: |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 530 | LOGP(DLINP, LOGL_NOTICE, |
| 531 | "unknown E1 TS type %u\n", e1i_ts->type); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 532 | break; |
| 533 | } |
| 534 | |
| 535 | return rc; |
| 536 | } |
| 537 | |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 538 | static void dahdi_vty_show(struct vty *vty, struct e1inp_line *line) |
| 539 | { |
| 540 | struct span_cfg *scfg; |
| 541 | |
Holger Hans Peter Freyther | f69b812 | 2013-07-06 18:54:58 +0200 | [diff] [blame] | 542 | if (line->port_nr >= ARRAY_SIZE(span_cfgs)) |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 543 | return; |
| 544 | |
| 545 | scfg = span_cfgs[line->port_nr]; |
| 546 | if (!scfg) { |
| 547 | vty_out(vty, "DAHDI Span %u non-existant%s", |
| 548 | line->port_nr+1, VTY_NEWLINE); |
| 549 | return; |
| 550 | } |
| 551 | |
| 552 | vty_out(vty, "DAHDI Span #%u, Base Nr %u, Timeslots: %u%s", |
| 553 | line->port_nr+1, scfg->chan_base, scfg->chan_num, |
| 554 | VTY_NEWLINE); |
| 555 | } |
| 556 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 557 | static int dahdi_e1_line_update(struct e1inp_line *line); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 558 | |
| 559 | struct e1inp_driver dahdi_driver = { |
| 560 | .name = "dahdi", |
| 561 | .want_write = ts_want_write, |
| 562 | .line_update = &dahdi_e1_line_update, |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 563 | .vty_show = &dahdi_vty_show, |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 564 | }; |
| 565 | |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 566 | int dahdi_set_bufinfo(int fd, int as_sigchan) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 567 | { |
| 568 | struct dahdi_bufferinfo bi; |
| 569 | int x = 0; |
| 570 | |
| 571 | if (ioctl(fd, DAHDI_GET_BUFINFO, &bi)) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 572 | LOGP(DLINP, LOGL_ERROR, "Error getting bufinfo\n"); |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 573 | return -EIO; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | if (as_sigchan) { |
| 577 | bi.numbufs = 4; |
| 578 | bi.bufsize = 512; |
| 579 | } else { |
| 580 | bi.numbufs = 8; |
| 581 | bi.bufsize = D_BCHAN_TX_GRAN; |
| 582 | bi.txbufpolicy = DAHDI_POLICY_WHEN_FULL; |
| 583 | } |
| 584 | |
| 585 | if (ioctl(fd, DAHDI_SET_BUFINFO, &bi)) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 586 | LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 587 | return -EIO; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | if (!as_sigchan) { |
| 591 | if (ioctl(fd, DAHDI_AUDIOMODE, &x)) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 592 | LOGP(DLINP, LOGL_ERROR, "Error setting bufinfo\n"); |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 593 | return -EIO; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 594 | } |
| 595 | } else { |
| 596 | int one = 1; |
| 597 | ioctl(fd, DAHDI_HDLCFCSMODE, &one); |
| 598 | /* we cannot reliably check for the ioctl return value here |
| 599 | * as this command will fail if the slot _already_ was a |
| 600 | * signalling slot before :( */ |
| 601 | } |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 602 | return 0; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | static int dahdi_e1_setup(struct e1inp_line *line) |
| 606 | { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 607 | struct span_cfg *scfg; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 608 | int ts, ret; |
| 609 | |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 610 | reread_span_cfgs(); |
| 611 | |
| 612 | scfg = span_cfgs[line->port_nr]; |
Harald Welte | 0cf5514 | 2011-09-26 23:06:18 +0200 | [diff] [blame] | 613 | if (!scfg) { |
| 614 | LOGP(DLMI, LOGL_ERROR, "Line %u(%s): DAHDI Port %u (Span %u) " |
| 615 | "doesn't exist\n", line->num, line->name, line->port_nr, |
| 616 | line->port_nr+1); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 617 | return -EIO; |
Harald Welte | 0cf5514 | 2011-09-26 23:06:18 +0200 | [diff] [blame] | 618 | } |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 619 | |
| 620 | line->num_ts = scfg->chan_num; |
| 621 | |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 622 | /* TS0 is CRC4, don't need any fd for it */ |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 623 | for (ts = 1; ts <= scfg->chan_num; ts++) { |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 624 | unsigned int idx = ts-1; |
| 625 | char openstr[128]; |
| 626 | struct e1inp_ts *e1i_ts = &line->ts[idx]; |
| 627 | struct osmo_fd *bfd = &e1i_ts->driver.dahdi.fd; |
Harald Welte | f3ca61c | 2011-08-09 11:21:23 +0200 | [diff] [blame] | 628 | int dev_nr; |
| 629 | |
Harald Welte | cfc9f1f | 2011-08-24 09:45:36 +0200 | [diff] [blame] | 630 | /* unregister FD if it was already registered */ |
| 631 | if (bfd->list.next && bfd->list.next != LLIST_POISON1) |
| 632 | osmo_fd_unregister(bfd); |
| 633 | |
Harald Welte | f3ca61c | 2011-08-09 11:21:23 +0200 | [diff] [blame] | 634 | /* DAHDI device names/numbers just keep incrementing |
| 635 | * even over multiple boards. So TS1 of the second |
| 636 | * board will be 32 */ |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 637 | dev_nr = scfg->chan_base + idx; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 638 | |
| 639 | bfd->data = line; |
| 640 | bfd->priv_nr = ts; |
| 641 | bfd->cb = dahdi_fd_cb; |
Harald Welte | f3ca61c | 2011-08-09 11:21:23 +0200 | [diff] [blame] | 642 | snprintf(openstr, sizeof(openstr), "/dev/dahdi/%d", dev_nr); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 643 | |
| 644 | switch (e1i_ts->type) { |
| 645 | case E1INP_TS_TYPE_NONE: |
Harald Welte | cfc9f1f | 2011-08-24 09:45:36 +0200 | [diff] [blame] | 646 | /* close/release LAPD instance, if any */ |
| 647 | if (e1i_ts->lapd) { |
| 648 | lapd_instance_free(e1i_ts->lapd); |
| 649 | e1i_ts->lapd = NULL; |
| 650 | } |
| 651 | if (bfd->fd) { |
| 652 | close(bfd->fd); |
| 653 | bfd->fd = 0; |
| 654 | } |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 655 | continue; |
| 656 | break; |
| 657 | case E1INP_TS_TYPE_SIGN: |
Harald Welte | cfc9f1f | 2011-08-24 09:45:36 +0200 | [diff] [blame] | 658 | if (!bfd->fd) |
| 659 | bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 660 | if (bfd->fd == -1) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 661 | LOGP(DLINP, LOGL_ERROR, |
| 662 | "%s could not open %s %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 663 | __func__, openstr, strerror(errno)); |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 664 | return -EIO; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 665 | } |
| 666 | bfd->when = BSC_FD_READ | BSC_FD_EXCEPT; |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 667 | ret = dahdi_set_bufinfo(bfd->fd, 1); |
| 668 | if (ret < 0) |
| 669 | return ret; |
| 670 | |
Harald Welte | cfc9f1f | 2011-08-24 09:45:36 +0200 | [diff] [blame] | 671 | if (!e1i_ts->lapd) |
Andreas Eversberg | a7ff001 | 2011-09-26 11:29:30 +0200 | [diff] [blame] | 672 | e1i_ts->lapd = lapd_instance_alloc(1, |
| 673 | dahdi_write_msg, bfd, e1inp_dlsap_up, |
Andreas Eversberg | 3744b87 | 2011-09-27 12:12:36 +0200 | [diff] [blame] | 674 | e1i_ts, &lapd_profile_abis); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 675 | break; |
Harald Welte | 7a228eb | 2016-07-28 11:09:31 +0200 | [diff] [blame] | 676 | case E1INP_TS_TYPE_HDLC: |
| 677 | if (!bfd->fd) |
| 678 | bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); |
| 679 | if (bfd->fd == -1) { |
| 680 | LOGP(DLINP, LOGL_ERROR, |
| 681 | "%s could not open %s %s\n", |
| 682 | __func__, openstr, strerror(errno)); |
| 683 | return -EIO; |
| 684 | } |
| 685 | bfd->when = BSC_FD_READ | BSC_FD_EXCEPT; |
| 686 | ret = dahdi_set_bufinfo(bfd->fd, 1); |
| 687 | if (ret < 0) |
| 688 | return ret; |
| 689 | break; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 690 | case E1INP_TS_TYPE_TRAU: |
Harald Welte | a0108e7 | 2016-07-27 21:44:50 +0200 | [diff] [blame] | 691 | case E1INP_TS_TYPE_RAW: |
Harald Welte | cfc9f1f | 2011-08-24 09:45:36 +0200 | [diff] [blame] | 692 | /* close/release LAPD instance, if any */ |
| 693 | if (e1i_ts->lapd) { |
| 694 | lapd_instance_free(e1i_ts->lapd); |
| 695 | e1i_ts->lapd = NULL; |
| 696 | } |
| 697 | if (!bfd->fd) |
| 698 | bfd->fd = open(openstr, O_RDWR | O_NONBLOCK); |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 699 | if (bfd->fd == -1) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 700 | LOGP(DLINP, LOGL_ERROR, |
| 701 | "%s could not open %s %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 702 | __func__, openstr, strerror(errno)); |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 703 | return -EIO; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 704 | } |
Pablo Neira Ayuso | 7ed9258 | 2012-03-12 18:38:45 +0100 | [diff] [blame] | 705 | ret = dahdi_set_bufinfo(bfd->fd, 0); |
| 706 | if (ret < 0) |
| 707 | return -EIO; |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 708 | /* We never include the DAHDI B-Channel FD into the |
| 709 | * writeset, since it doesn't support poll() based |
| 710 | * write flow control */ |
| 711 | bfd->when = BSC_FD_READ | BSC_FD_EXCEPT;// | BSC_FD_WRITE; |
| 712 | break; |
| 713 | } |
| 714 | |
| 715 | if (bfd->fd < 0) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 716 | LOGP(DLINP, LOGL_ERROR, |
| 717 | "%s could not open %s %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 718 | __func__, openstr, strerror(errno)); |
| 719 | return bfd->fd; |
| 720 | } |
| 721 | |
| 722 | ret = osmo_fd_register(bfd); |
| 723 | if (ret < 0) { |
Pablo Neira Ayuso | 5c67fb5 | 2012-03-12 18:34:12 +0100 | [diff] [blame] | 724 | LOGP(DLINP, LOGL_ERROR, |
| 725 | "could not register FD: %s\n", |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 726 | strerror(ret)); |
| 727 | return ret; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
Pablo Neira Ayuso | 4e862cb | 2011-08-19 18:43:38 +0200 | [diff] [blame] | 734 | static int dahdi_e1_line_update(struct e1inp_line *line) |
Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 735 | { |
| 736 | if (line->driver != &dahdi_driver) |
| 737 | return -EINVAL; |
| 738 | |
| 739 | return dahdi_e1_setup(line); |
| 740 | } |
| 741 | |
| 742 | int e1inp_dahdi_init(void) |
| 743 | { |
| 744 | init_flip_bits(); |
| 745 | |
| 746 | /* register the driver with the core */ |
| 747 | return e1inp_driver_register(&dahdi_driver); |
| 748 | } |
Harald Welte | 3bc7885 | 2011-08-24 08:32:38 +0200 | [diff] [blame] | 749 | |
| 750 | #endif /* HAVE_DAHDI_USER_H */ |