blob: 21ee8357dfd6883c9888202acdaf45b8eac71138 [file] [log] [blame]
Matthew Fredricksond105e202010-02-16 22:07:04 +01001/* OpenBSC Abis input driver for DAHDI */
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +01002
3/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
Matthew Fredricksond105e202010-02-16 22:07:04 +01005 * (C) 2010 by Digium and Matthew Fredrickson <creslin@digium.com>
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +01006 *
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
25#include <stdio.h>
26#include <unistd.h>
27#include <stdlib.h>
28#include <errno.h>
29#include <string.h>
30#include <time.h>
31#include <sys/fcntl.h>
32#include <sys/types.h>
33#include <sys/socket.h>
34#include <sys/ioctl.h>
35#include <arpa/inet.h>
36#include <mISDNif.h>
37
38//#define AF_COMPATIBILITY_FUNC
39//#include <compat_af_isdn.h>
40#ifndef AF_ISDN
41#define AF_ISDN 34
42#define PF_ISDN AF_ISDN
43#endif
44
45#include <openbsc/select.h>
46#include <openbsc/msgb.h>
47#include <openbsc/debug.h>
48#include <openbsc/gsm_data.h>
49#include <openbsc/abis_nm.h>
50#include <openbsc/abis_rsl.h>
51#include <openbsc/subchan_demux.h>
52#include <openbsc/e1_input.h>
53#include <openbsc/talloc.h>
54
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +010055#include "lapd.h"
56
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +010057#define TS1_ALLOC_SIZE 300
58
59struct prim_name {
60 unsigned int prim;
61 const char *name;
62};
63
64const struct prim_name prim_names[] = {
65 { PH_CONTROL_IND, "PH_CONTROL_IND" },
66 { PH_DATA_IND, "PH_DATA_IND" },
67 { PH_DATA_CNF, "PH_DATA_CNF" },
68 { PH_ACTIVATE_IND, "PH_ACTIVATE_IND" },
69 { DL_ESTABLISH_IND, "DL_ESTABLISH_IND" },
70 { DL_ESTABLISH_CNF, "DL_ESTABLISH_CNF" },
71 { DL_RELEASE_IND, "DL_RELEASE_IND" },
72 { DL_RELEASE_CNF, "DL_RELEASE_CNF" },
73 { DL_DATA_IND, "DL_DATA_IND" },
74 { DL_UNITDATA_IND, "DL_UNITDATA_IND" },
75 { DL_INFORMATION_IND, "DL_INFORMATION_IND" },
76 { MPH_ACTIVATE_IND, "MPH_ACTIVATE_IND" },
77 { MPH_DEACTIVATE_IND, "MPH_DEACTIVATE_IND" },
78};
79
80const char *get_prim_name(unsigned int prim)
81{
82 int i;
83
84 for (i = 0; i < ARRAY_SIZE(prim_names); i++) {
85 if (prim_names[i].prim == prim)
86 return prim_names[i].name;
87 }
88
89 return "UNKNOWN";
90}
91
92static int handle_ts1_read(struct bsc_fd *bfd)
93{
94 struct e1inp_line *line = bfd->data;
95 unsigned int ts_nr = bfd->priv_nr;
96 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
97 struct e1inp_sign_link *link;
Matthew Fredricksonbc6649e2010-02-16 22:01:36 +010098 struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "DAHDI TS1");
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +010099 struct sockaddr_mISDN l2addr;
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100100 struct mISDNhead ah;
101 struct mISDNhead *hh = &ah;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100102 int ret;
103
104 if (!msg)
105 return -ENOMEM;
106
107 hh = (struct mISDNhead *) msg->data;
108
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100109 ret = read(bfd->fd, &msg->data, TS1_ALLOC_SIZE - 16);
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100110 if (ret < 0) {
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100111 perror("read ");
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100112 }
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100113 msgb_put(msg, ret);
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100114 if (ret <= 3) {
115 perror("read ");
116 }
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100117
118 DEBUGP(DMI, "<= len = %d, prim(0x%x) id(0x%x): %s\n",
119 ret, hh->prim, hh->id, get_prim_name(hh->prim));
120
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100121 int ilen;
122 lapd_mph_type prim;
123 uint8_t *idata = lapd_receive(msg->data, msg->len, &ilen, &prim, bfd);
124
125 switch (prim) {
126 case 0: break;
127 case LAPD_MPH_ACTIVATE_IND: hh->prim = MPH_ACTIVATE_IND; break;
128 case LAPD_MPH_DEACTIVATE_IND: hh->prim = MPH_DEACTIVATE_IND; break;
129 case LAPD_DL_DATA_IND: hh->prim = DL_DATA_IND; break;
130 default: printf("ERROR: unknown prim\n");
131 };
132
133 int pass_on = (prim != 0);
134
135 if (!pass_on) {
136 return 0;
137 };
138
139 l2addr.sapi = msg->data[0] >> 2;
140 l2addr.tei = msg->data[1] >> 1;
141 msgb_pull(msg, 2);
142
143#if 0
144 switch (hh->prim) {
145 case DL_INFORMATION_IND:
146 DEBUGP(DMI, "got DL_INFORMATION_IND\n");
147 struct sockaddr_mISDN *sa = NULL;
148 char *lstr = "UNKN";
149
150 switch (l2addr.tei) {
151 case TEI_OML:
152 sa = &e1h->omladdr;
153 lstr = "OML";
154 break;
155 case TEI_RSL:
156 sa = &e1h->l2addr;
157 lstr = "RSL";
158 break;
159 default:
160 break;
161 }
162 if (sa) {
163 DEBUGP(DMI, "%s use channel(%d) sapi(%d) tei(%d) for now\n",
164 lstr, l2addr.channel, l2addr.sapi, l2addr.tei);
165 memcpy(sa, &l2addr, sizeof(l2addr));
166 }
167 break;
168 case DL_ESTABLISH_IND:
169 DEBUGP(DMI, "got DL_ESTABLISH_IND\n");
170 break;
171 case DL_ESTABLISH_CNF:
172 DEBUGP(DMI, "got DL_ESTABLISH_CNF\n");
173 break;
174 case DL_RELEASE_IND:
175 DEBUGP(DMI, "got DL_RELEASE_IND: E1 Layer 1 disappeared?\n");
176 break;
177#if 0
178 case MPH_ACTIVATE_IND:
179 DEBUGP(DMI, "got MPH_ACTIVATE_IND\n");
180 printf("tei %d, sapi %d\n", l2addr.tei, l2addr.sapi);
181 if (l2addr.tei == TEI_OML && l2addr.sapi == SAPI_OML)
182 e1h->cb(EVT_E1_OML_UP, e1h->bts);
183 else if (l2addr.tei == TEI_RSL && l2addr.sapi == SAPI_RSL)
184 e1h->cb(EVT_E1_RSL_UP, e1h->bts);
185 break;
186 case MPH_DEACTIVATE_IND:
187 DEBUGP(DMI, "got MPH_DEACTIVATE_IND: TEI link closed?\n");
188 if (l2addr.tei == TEI_OML && l2addr.sapi == SAPI_OML)
189 e1h->cb(EVT_E1_OML_DN, e1h->bts);
190 else if (l2addr.tei == TEI_RSL && l2addr.sapi == SAPI_RSL)
191 e1h->cb(EVT_E1_RSL_DN, e1h->bts);
192 break;
193#endif
194 case DL_DATA_IND:
195 DEBUGP(DMI, "got DL_DATA_IND\n");
196
197 ret = msg->len;
198 msg->l2h = msg->data + 2;// + MISDN_HEADER_LEN;
199
200#if 0
201 if (debug_mask & DMI) {
202 fprintf(stdout, "RX: ");
203 hexdump(msgb_l2(msg), ret - (msg->l2h - msg->data));// - MISDN_HEADER_LEN);
204 }
205#endif
206 switch (l2addr.tei) {
207 case TEI_OML:
208 ret = abis_nm_rcvmsg(msg);
209 break;
210 case TEI_RSL:
211 ret = abis_rsl_rcvmsg(msg);
212 break;
213 default:
214 fprintf(stderr, "DATA_IND for unknown TEI\n");
215 break;
216 }
217 break;
218 default:
219 DEBUGP(DMI, "got unexpected 0x%x prim\n", hh->prim);
220 break;
221 }
222#endif
223
224
225
226#if 1
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100227 switch (hh->prim) {
228 case DL_INFORMATION_IND:
229 /* mISDN tells us which channel number is allocated for this
230 * tuple of (SAPI, TEI). */
231 DEBUGP(DMI, "DL_INFORMATION_IND: use channel(%d) sapi(%d) tei(%d) for now\n",
232 l2addr.channel, l2addr.sapi, l2addr.tei);
233 link = e1inp_lookup_sign_link(e1i_ts, l2addr.tei, l2addr.sapi);
234 if (!link) {
235 DEBUGPC(DMI, "mISDN message for unknown sign_link\n");
236 msgb_free(msg);
237 return -EINVAL;
238 }
239 /* save the channel number in the driver private struct */
240 link->driver.misdn.channel = l2addr.channel;
241 break;
242 case DL_ESTABLISH_IND:
243 DEBUGP(DMI, "DL_ESTABLISH_IND: channel(%d) sapi(%d) tei(%d)\n",
244 l2addr.channel, l2addr.sapi, l2addr.tei);
245 ret = e1inp_event(e1i_ts, EVT_E1_TEI_UP, l2addr.tei, l2addr.sapi);
246 break;
247 case DL_RELEASE_IND:
248 DEBUGP(DMI, "DL_RELEASE_IND: channel(%d) sapi(%d) tei(%d)\n",
249 l2addr.channel, l2addr.sapi, l2addr.tei);
250 ret = e1inp_event(e1i_ts, EVT_E1_TEI_DN, l2addr.tei, l2addr.sapi);
251 break;
252 case DL_DATA_IND:
253 case DL_UNITDATA_IND:
254 msg->l2h = msg->data + MISDN_HEADER_LEN;
255 DEBUGP(DMI, "RX: %s\n", hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
256 ret = e1inp_rx_ts(e1i_ts, msg, l2addr.tei, l2addr.sapi);
257 break;
258 case PH_ACTIVATE_IND:
259 DEBUGP(DMI, "PH_ACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
260 l2addr.channel, l2addr.sapi, l2addr.tei);
261 break;
262 case PH_DEACTIVATE_IND:
263 DEBUGP(DMI, "PH_DEACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
264 l2addr.channel, l2addr.sapi, l2addr.tei);
265 break;
266 default:
267 break;
268 }
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100269#endif
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100270 return ret;
271}
272
273static int ts_want_write(struct e1inp_ts *e1i_ts)
274{
275 /* We never include the mISDN B-Channel FD into the
276 * writeset, since it doesn't support poll() based
277 * write flow control */
278 if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
279 return 0;
280
281 e1i_ts->driver.misdn.fd.when |= BSC_FD_WRITE;
282
283 return 0;
284}
285
286static void timeout_ts1_write(void *data)
287{
288 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
289
290 /* trigger write of ts1, due to tx delay timer */
291 ts_want_write(e1i_ts);
292}
293
294static int handle_ts1_write(struct bsc_fd *bfd)
295{
296 struct e1inp_line *line = bfd->data;
297 unsigned int ts_nr = bfd->priv_nr;
298 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
299 struct e1inp_sign_link *sign_link;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100300 struct msgb *msg;
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100301 //u_int8_t *l2_data;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100302 int ret;
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100303 //int no_oml = 0;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100304
305 bfd->when &= ~BSC_FD_WRITE;
306
307 /* get the next msg for this timeslot */
308 msg = e1inp_tx_ts(e1i_ts, &sign_link);
309 if (!msg) {
310 /* no message after tx delay timer */
311 return 0;
312 }
313
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100314#if 0
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100315 DEBUGP(DMI, "TX TEI(%d) SAPI(%d): %s\n", sign_link->tei,
316 sign_link->sapi, hexdump(l2_data, msg->len - MISDN_HEADER_LEN));
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100317#endif
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100318
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100319 lapd_transmit(sign_link->tei, msg->data, msg->len, bfd);
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100320
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100321 ret = write(bfd->fd, msg->data, msg->len + 2);
322
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100323 if (ret < 0)
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100324 fprintf(stderr, "%s write failed %d\n", __func__, ret);
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100325 msgb_free(msg);
326
327 /* set tx delay timer for next event */
328 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
329 e1i_ts->sign.tx_timer.data = e1i_ts;
330 bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 50000);
331
332 return ret;
333}
334
335#define BCHAN_TX_GRAN 160
336/* write to a B channel TS */
337static int handle_tsX_write(struct bsc_fd *bfd)
338{
339 struct e1inp_line *line = bfd->data;
340 unsigned int ts_nr = bfd->priv_nr;
341 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
342 struct mISDNhead *hh;
343 u_int8_t tx_buf[BCHAN_TX_GRAN + sizeof(*hh)];
344 struct subch_mux *mx = &e1i_ts->trau.mux;
345 int ret;
346
347 hh = (struct mISDNhead *) tx_buf;
348 hh->prim = PH_DATA_REQ;
349
350 subchan_mux_out(mx, tx_buf+sizeof(*hh), BCHAN_TX_GRAN);
351
352 DEBUGP(DMIB, "BCHAN TX: %s\n",
353 hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN));
354
355 ret = send(bfd->fd, tx_buf, sizeof(*hh) + BCHAN_TX_GRAN, 0);
356 if (ret < sizeof(*hh) + BCHAN_TX_GRAN)
357 DEBUGP(DMIB, "send returns %d instead of %lu\n", ret,
358 sizeof(*hh) + BCHAN_TX_GRAN);
359
360 return ret;
361}
362
363#define TSX_ALLOC_SIZE 4096
364/* FIXME: read from a B channel TS */
365static int handle_tsX_read(struct bsc_fd *bfd)
366{
367 struct e1inp_line *line = bfd->data;
368 unsigned int ts_nr = bfd->priv_nr;
369 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
370 struct msgb *msg = msgb_alloc(TSX_ALLOC_SIZE, "DAHDI TSx");
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100371 struct mISDNhead ah;
372 struct mISDNhead *hh = &ah;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100373 int ret;
374
375 if (!msg)
376 return -ENOMEM;
377
378 hh = (struct mISDNhead *) msg->data;
379
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100380 ret = read(bfd->fd, msg->data, TSX_ALLOC_SIZE);
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100381 if (ret < 0) {
382 fprintf(stderr, "read error %s\n", strerror(errno));
383 return ret;
384 }
385
386 msgb_put(msg, ret - 2);
387
388 if (hh->prim != PH_CONTROL_IND)
389 DEBUGP(DMIB, "<= BCHAN len = %d, prim(0x%x) id(0x%x): %s\n",
390 ret, hh->prim, hh->id, get_prim_name(hh->prim));
391
392 switch (hh->prim) {
393 case PH_DATA_IND:
394 msg->l2h = msg->data + MISDN_HEADER_LEN;
395 DEBUGP(DMIB, "BCHAN RX: %s\n",
396 hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
397 ret = e1inp_rx_ts(e1i_ts, msg, 0, 0);
398 break;
399 case PH_ACTIVATE_IND:
400 case PH_DATA_CNF:
401 /* physical layer indicates that data has been sent,
402 * we thus can send some more data */
403 ret = handle_tsX_write(bfd);
404 default:
405 break;
406 }
407 /* FIXME: why do we free signalling msgs in the caller, and trau not? */
408 msgb_free(msg);
409
410 return ret;
411}
412
413/* callback from select.c in case one of the fd's can be read/written */
414static int dahdi_fd_cb(struct bsc_fd *bfd, unsigned int what)
415{
416 struct e1inp_line *line = bfd->data;
417 unsigned int ts_nr = bfd->priv_nr;
418 unsigned int idx = ts_nr-1;
419 struct e1inp_ts *e1i_ts = &line->ts[idx];
420 int rc = 0;
421
422 switch (e1i_ts->type) {
423 case E1INP_TS_TYPE_SIGN:
424 if (what & BSC_FD_READ)
425 rc = handle_ts1_read(bfd);
426 if (what & BSC_FD_WRITE)
427 rc = handle_ts1_write(bfd);
428 break;
429 case E1INP_TS_TYPE_TRAU:
430 if (what & BSC_FD_READ)
431 rc = handle_tsX_read(bfd);
432 /* We never include the mISDN B-Channel FD into the
433 * writeset, since it doesn't support poll() based
434 * write flow control */
435 break;
436 default:
437 fprintf(stderr, "unknown E1 TS type %u\n", e1i_ts->type);
438 break;
439 }
440
441 return rc;
442}
443
444#if 0
445static int activate_bchan(struct e1inp_line *line, int ts, int act)
446{
447 struct mISDNhead hh;
448 int ret;
449 unsigned int idx = ts-1;
450 struct e1inp_ts *e1i_ts = &line->ts[idx];
451 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
452
453 fprintf(stdout, "activate bchan\n");
454 if (act)
455 hh.prim = PH_ACTIVATE_REQ;
456 else
457 hh.prim = PH_DEACTIVATE_REQ;
458
459 hh.id = MISDN_ID_ANY;
460 ret = sendto(bfd->fd, &hh, sizeof(hh), 0, NULL, 0);
461 if (ret < 0) {
462 fprintf(stdout, "could not send ACTIVATE_RQ %s\n",
463 strerror(errno));
464 }
465
466 return ret;
467}
468#endif
469
470struct e1inp_driver dahdi_driver = {
471 .name = "DAHDI",
472 .want_write = ts_want_write,
473};
474
475static int mi_e1_setup(struct e1inp_line *line, int release_l2)
476{
477 int ts, ret;
478
479 /* TS0 is CRC4, don't need any fd for it */
480 for (ts = 1; ts < NUM_E1_TS; ts++) {
481 unsigned int idx = ts-1;
482 char openstr[128];
483 struct e1inp_ts *e1i_ts = &line->ts[idx];
484 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100485
486 bfd->data = line;
487 bfd->priv_nr = ts;
488 bfd->cb = dahdi_fd_cb;
489 snprintf(openstr, sizeof(openstr), "/dev/dahdi/%d", ts);
490
491 switch (e1i_ts->type) {
492 case E1INP_TS_TYPE_NONE:
493 continue;
494 break;
495 case E1INP_TS_TYPE_SIGN:
496 bfd->fd = open(openstr, O_RDWR);
497 bfd->when = BSC_FD_READ;
498 break;
499 case E1INP_TS_TYPE_TRAU:
500 bfd->fd = open(openstr, O_RDWR);
501 /* We never include the mISDN B-Channel FD into the
502 * writeset, since it doesn't support poll() based
503 * write flow control */
504 bfd->when = BSC_FD_READ;
505 break;
506 }
507
508 if (bfd->fd < 0) {
509 fprintf(stderr, "%s could not open %s %s\n",
510 __func__, openstr, strerror(errno));
511 return bfd->fd;
512 }
513
514 ret = bsc_register_fd(bfd);
515 if (ret < 0) {
516 fprintf(stderr, "could not register FD: %s\n",
517 strerror(ret));
518 return ret;
519 }
520 }
521
522 return 0;
523}
524
525int mi_e1_line_update(struct e1inp_line *line)
526{
527 struct mISDN_devinfo devinfo;
Matthew Fredricksonb1cb8eb2010-02-17 19:25:39 +0100528 //int sk, ret, cnt;
529 int ret;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100530
531 if (!line->driver) {
532 /* this must be the first update */
Matthew Fredricksonbc6649e2010-02-16 22:01:36 +0100533 line->driver = &dahdi_driver;
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100534 } else {
535 /* this is a subsequent update */
536 /* FIXME: first close all sockets */
537 fprintf(stderr, "incremental line updates not supported yet\n");
538 return 0;
539 }
540
Matthew Fredricksonbc6649e2010-02-16 22:01:36 +0100541 if (line->driver != &dahdi_driver)
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100542 return -EINVAL;
543
Matthew Fredricksonbc6649e2010-02-16 22:01:36 +0100544#if 0
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100545 /* open the ISDN card device */
546 sk = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
547 if (sk < 0) {
548 fprintf(stderr, "%s could not open socket %s\n",
549 __func__, strerror(errno));
550 return sk;
551 }
552
553 ret = ioctl(sk, IMGETCOUNT, &cnt);
554 if (ret) {
555 fprintf(stderr, "%s error getting interf count: %s\n",
556 __func__, strerror(errno));
557 close(sk);
558 return -ENODEV;
559 }
560 //DEBUGP(DMI,"%d device%s found\n", cnt, (cnt==1)?"":"s");
561 printf("%d device%s found\n", cnt, (cnt==1)?"":"s");
562#if 1
563 devinfo.id = line->num;
564 ret = ioctl(sk, IMGETDEVINFO, &devinfo);
565 if (ret < 0) {
566 fprintf(stdout, "error getting info for device %d: %s\n",
567 line->num, strerror(errno));
568 return -ENODEV;
569 }
570 fprintf(stdout, " id: %d\n", devinfo.id);
571 fprintf(stdout, " Dprotocols: %08x\n", devinfo.Dprotocols);
572 fprintf(stdout, " Bprotocols: %08x\n", devinfo.Bprotocols);
573 fprintf(stdout, " protocol: %d\n", devinfo.protocol);
574 fprintf(stdout, " nrbchan: %d\n", devinfo.nrbchan);
575 fprintf(stdout, " name: %s\n", devinfo.name);
576#endif
577
578 if (!(devinfo.Dprotocols & (1 << ISDN_P_NT_E1))) {
579 fprintf(stderr, "error: card is not of type E1 (NT-mode)\n");
580 return -EINVAL;
581 }
Matthew Fredricksonbc6649e2010-02-16 22:01:36 +0100582#endif
Matthew Fredricksonb5ddc182010-02-16 21:55:50 +0100583
584 ret = mi_e1_setup(line, 1);
585 if (ret)
586 return ret;
587
588 return 0;
589}
590
591static __attribute__((constructor)) void on_dso_load_sms(void)
592{
593 /* register the driver with the core */
594 e1inp_driver_register(&dahdi_driver);
595}