blob: de8d41f21b0f77c198a9748e4be158d928e9624c [file] [log] [blame]
Harald Welte1fa60c82009-02-09 18:13:26 +00001/* OpenBSC Abis input driver for mISDNuser */
2
3/* (C) 2008-2009 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
5 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24#include <stdio.h>
25#include <unistd.h>
26#include <stdlib.h>
27#include <errno.h>
28#include <string.h>
29#include <time.h>
30#include <sys/fcntl.h>
31#include <sys/types.h>
32#include <sys/socket.h>
33#include <sys/ioctl.h>
34#include <arpa/inet.h>
35#include <mISDNif.h>
36
37//#define AF_COMPATIBILITY_FUNC
38//#include <compat_af_isdn.h>
39#define AF_ISDN 34
40#define PF_ISDN AF_ISDN
41
42#include <openbsc/select.h>
43#include <openbsc/msgb.h>
44#include <openbsc/debug.h>
45#include <openbsc/gsm_data.h>
46#include <openbsc/abis_nm.h>
47#include <openbsc/abis_rsl.h>
48#include <openbsc/subchan_demux.h>
49#include <openbsc/e1_input.h>
50
51/* data structure for one E1 interface with A-bis */
52struct mi_e1_handle {
53 /* The mISDN card number of the card we use */
54 int cardnr;
55};
56
57#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[] = {
Holger Freythercbc7b062009-02-09 23:10:48 +000065 { PH_CONTROL_IND, "PH_CONTROL_IND" },
66 { PH_DATA_IND, "PH_DATA_IND" },
67 { PH_DATA_CNF, "PH_DATA_CNF" },
Holger Freyther5d7e5572009-02-10 18:40:45 +000068 { PH_ACTIVATE_IND, "PH_ACTIVATE_IND" },
Harald Welte1fa60c82009-02-09 18:13:26 +000069 { 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;
98 struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE);
99 struct sockaddr_mISDN l2addr;
100 struct mISDNhead *hh;
101 socklen_t alen;
102 int ret;
103
104 if (!msg)
105 return -ENOMEM;
106
107 hh = (struct mISDNhead *) msg->data;
108
109 alen = sizeof(l2addr);
110 ret = recvfrom(bfd->fd, msg->data, 300, 0,
111 (struct sockaddr *) &l2addr, &alen);
112 if (ret < 0) {
113 fprintf(stderr, "recvfrom error %s\n", strerror(errno));
114 return ret;
115 }
116
Holger Freytheracb688b2009-05-01 04:59:55 +0000117 if (alen != sizeof(l2addr)) {
118 fprintf(stderr, "%s error len\n", __func__);
Harald Welte1fa60c82009-02-09 18:13:26 +0000119 return -EINVAL;
Holger Freytheracb688b2009-05-01 04:59:55 +0000120 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000121
122 msgb_put(msg, ret);
123
124 DEBUGP(DMI, "alen =%d, dev(%d) channel(%d) sapi(%d) tei(%d)\n",
125 alen, l2addr.dev, l2addr.channel, l2addr.sapi, l2addr.tei);
126
Holger Freyther57dd7bf2009-02-10 01:04:22 +0000127 DEBUGP(DMI, "<= len = %d, prim(0x%x) id(0x%x): %s\n",
128 ret, hh->prim, hh->id, get_prim_name(hh->prim));
Harald Welte1fa60c82009-02-09 18:13:26 +0000129
130 switch (hh->prim) {
131 case DL_INFORMATION_IND:
132 /* mISDN tells us which channel number is allocated for this
133 * tuple of (SAPI, TEI). */
Holger Freytheracb688b2009-05-01 04:59:55 +0000134 DEBUGP(DMI, "DL_INFORMATION_IND: use channel(%d) sapi(%d) tei(%d) for now\n",
Harald Welte1fa60c82009-02-09 18:13:26 +0000135 l2addr.channel, l2addr.sapi, l2addr.tei);
136 link = e1inp_lookup_sign_link(e1i_ts, l2addr.tei, l2addr.sapi);
137 if (!link) {
138 DEBUGPC(DMI, "mISDN message for unknown sign_link\n");
139 free(msg);
140 return -EINVAL;
141 }
142 /* save the channel number in the driver private struct */
143 link->driver.misdn.channel = l2addr.channel;
144 break;
Harald Welte7d144762009-05-23 05:40:49 +0000145 case DL_ESTABLISH_IND:
146 DEBUGP(DMI, "DL_ESTABLISH_IND: channel(%d) sapi(%d) tei(%d)\n",
147 l2addr.channel, l2addr.sapi, l2addr.tei);
Harald Welte1fa60c82009-02-09 18:13:26 +0000148 ret = e1inp_event(e1i_ts, EVT_E1_TEI_UP, l2addr.tei, l2addr.sapi);
149 break;
Harald Welte7d144762009-05-23 05:40:49 +0000150 case DL_RELEASE_IND:
151 DEBUGP(DMI, "DL_RELEASE_IND: channel(%d) sapi(%d) tei(%d)\n",
152 l2addr.channel, l2addr.sapi, l2addr.tei);
Harald Welte1fa60c82009-02-09 18:13:26 +0000153 ret = e1inp_event(e1i_ts, EVT_E1_TEI_DN, l2addr.tei, l2addr.sapi);
154 break;
155 case DL_DATA_IND:
Harald Welte1fa60c82009-02-09 18:13:26 +0000156 msg->l2h = msg->data + MISDN_HEADER_LEN;
Harald Welte3cc4bf52009-02-28 13:08:01 +0000157 DEBUGP(DMI, "RX: %s\n", hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000158 ret = e1inp_rx_ts(e1i_ts, msg, l2addr.tei, l2addr.sapi);
159 break;
Harald Welte7d144762009-05-23 05:40:49 +0000160 case PH_ACTIVATE_IND:
161 DEBUGP(DMI, "PH_ACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
162 l2addr.channel, l2addr.sapi, l2addr.tei);
163 break;
164 case PH_DEACTIVATE_IND:
165 DEBUGP(DMI, "PH_DEACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
166 l2addr.channel, l2addr.sapi, l2addr.tei);
167 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000168 default:
169 break;
170 }
171 return ret;
172}
173
Harald Weltef55b49f2009-05-23 06:20:41 +0000174static int ts_want_write(struct e1inp_ts *e1i_ts)
175{
176 /* We never include the mISDN B-Channel FD into the
177 * writeset, since it doesn't support poll() based
178 * write flow control */
179 if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
180 return 0;
181
182 e1i_ts->driver.misdn.fd.when |= BSC_FD_WRITE;
183
184 return 0;
185}
186
187static void timeout_ts1_write(void *data)
188{
189 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
190
191 /* trigger write of ts1, due to tx delay timer */
192 ts_want_write(e1i_ts);
193}
194
Harald Welte1fa60c82009-02-09 18:13:26 +0000195static int handle_ts1_write(struct bsc_fd *bfd)
196{
197 struct e1inp_line *line = bfd->data;
198 unsigned int ts_nr = bfd->priv_nr;
199 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
200 struct e1inp_sign_link *sign_link;
201 struct sockaddr_mISDN sa;
202 struct msgb *msg;
203 struct mISDNhead *hh;
204 u_int8_t *l2_data;
205 int ret;
206
Harald Weltef55b49f2009-05-23 06:20:41 +0000207 bfd->when &= ~BSC_FD_WRITE;
208
Harald Welte1fa60c82009-02-09 18:13:26 +0000209 /* get the next msg for this timeslot */
210 msg = e1inp_tx_ts(e1i_ts, &sign_link);
211 if (!msg) {
Harald Weltef55b49f2009-05-23 06:20:41 +0000212 /* no message after tx delay timer */
Harald Welte1fa60c82009-02-09 18:13:26 +0000213 return 0;
214 }
215
216 l2_data = msg->data;
217
218 /* prepend the mISDNhead */
219 hh = (struct mISDNhead *) msgb_push(msg, sizeof(*hh));
220 hh->prim = DL_DATA_REQ;
221
Holger Freytheracb688b2009-05-01 04:59:55 +0000222 DEBUGP(DMI, "TX TEI(%d) SAPI(%d): %s\n", sign_link->tei,
223 sign_link->sapi, hexdump(l2_data, msg->len - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000224
225 /* construct the sockaddr */
226 sa.family = AF_ISDN;
227 sa.sapi = sign_link->sapi;
228 sa.dev = sign_link->tei;
229 sa.channel = sign_link->driver.misdn.channel;
230
231 ret = sendto(bfd->fd, msg->data, msg->len, 0,
232 (struct sockaddr *)&sa, sizeof(sa));
Holger Freytheracb688b2009-05-01 04:59:55 +0000233 if (ret < 0)
234 fprintf(stderr, "%s sendto failed %d\n", __func__, ret);
Harald Welte1fa60c82009-02-09 18:13:26 +0000235 msgb_free(msg);
236
Harald Weltef55b49f2009-05-23 06:20:41 +0000237 /* set tx delay timer for next event */
238 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
239 e1i_ts->sign.tx_timer.data = e1i_ts;
240 bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 50000);
Harald Welte1fa60c82009-02-09 18:13:26 +0000241
242 return ret;
243}
244
Harald Weltef9227c72009-02-18 03:39:00 +0000245#define BCHAN_TX_GRAN 160
Harald Welte8ffcfed2009-02-10 18:18:50 +0000246/* write to a B channel TS */
247static int handle_tsX_write(struct bsc_fd *bfd)
248{
249 struct e1inp_line *line = bfd->data;
250 unsigned int ts_nr = bfd->priv_nr;
251 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
252 struct mISDNhead *hh;
253 u_int8_t tx_buf[BCHAN_TX_GRAN + sizeof(*hh)];
254 struct subch_mux *mx = &e1i_ts->trau.mux;
255 int ret;
Harald Welte1fa60c82009-02-09 18:13:26 +0000256
Harald Welte8ffcfed2009-02-10 18:18:50 +0000257 hh = (struct mISDNhead *) tx_buf;
258 hh->prim = PH_DATA_REQ;
259
260 subchan_mux_out(mx, tx_buf+sizeof(*hh), BCHAN_TX_GRAN);
261
Harald Welte3cc4bf52009-02-28 13:08:01 +0000262 DEBUGP(DMIB, "BCHAN TX: %s\n",
263 hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN));
Harald Welte8ffcfed2009-02-10 18:18:50 +0000264
265 ret = send(bfd->fd, tx_buf, sizeof(*hh) + BCHAN_TX_GRAN, 0);
266 if (ret < sizeof(*hh) + BCHAN_TX_GRAN)
267 DEBUGP(DMIB, "send returns %d instead of %u\n", ret,
268 sizeof(*hh) + BCHAN_TX_GRAN);
269
270 return ret;
271}
272
273#define TSX_ALLOC_SIZE 4096
Harald Welte1fa60c82009-02-09 18:13:26 +0000274/* FIXME: read from a B channel TS */
275static int handle_tsX_read(struct bsc_fd *bfd)
276{
277 struct e1inp_line *line = bfd->data;
278 unsigned int ts_nr = bfd->priv_nr;
279 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
280 struct msgb *msg = msgb_alloc(TSX_ALLOC_SIZE);
281 struct mISDNhead *hh;
282 int ret;
283
284 if (!msg)
285 return -ENOMEM;
286
287 hh = (struct mISDNhead *) msg->data;
288
289 ret = recv(bfd->fd, msg->data, TSX_ALLOC_SIZE, 0);
290 if (ret < 0) {
291 fprintf(stderr, "recvfrom error %s\n", strerror(errno));
292 return ret;
293 }
294
295 msgb_put(msg, ret);
296
Holger Freytheracb688b2009-05-01 04:59:55 +0000297 if (hh->prim != PH_CONTROL_IND)
298 DEBUGP(DMIB, "<= BCHAN len = %d, prim(0x%x) id(0x%x): %s\n",
299 ret, hh->prim, hh->id, get_prim_name(hh->prim));
Harald Welte1fa60c82009-02-09 18:13:26 +0000300
301 switch (hh->prim) {
302 case PH_DATA_IND:
303 msg->l2h = msg->data + MISDN_HEADER_LEN;
Harald Welte3cc4bf52009-02-28 13:08:01 +0000304 DEBUGP(DMIB, "BCHAN RX: %s\n",
305 hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000306 ret = e1inp_rx_ts(e1i_ts, msg, 0, 0);
307 break;
Holger Freyther5d7e5572009-02-10 18:40:45 +0000308 case PH_ACTIVATE_IND:
Harald Welte8ffcfed2009-02-10 18:18:50 +0000309 case PH_DATA_CNF:
310 /* physical layer indicates that data has been sent,
311 * we thus can send some more data */
312 ret = handle_tsX_write(bfd);
Harald Welte1fa60c82009-02-09 18:13:26 +0000313 default:
314 break;
315 }
316 /* FIXME: why do we free signalling msgs in the caller, and trau not? */
317 msgb_free(msg);
318
319 return ret;
320}
321
Harald Welte1fa60c82009-02-09 18:13:26 +0000322/* callback from select.c in case one of the fd's can be read/written */
323static int misdn_fd_cb(struct bsc_fd *bfd, unsigned int what)
324{
325 struct e1inp_line *line = bfd->data;
326 unsigned int ts_nr = bfd->priv_nr;
327 unsigned int idx = ts_nr-1;
328 struct e1inp_ts *e1i_ts = &line->ts[idx];
329 int rc = 0;
330
331 switch (e1i_ts->type) {
332 case E1INP_TS_TYPE_SIGN:
333 if (what & BSC_FD_READ)
334 rc = handle_ts1_read(bfd);
335 if (what & BSC_FD_WRITE)
336 rc = handle_ts1_write(bfd);
337 break;
338 case E1INP_TS_TYPE_TRAU:
339 if (what & BSC_FD_READ)
340 rc = handle_tsX_read(bfd);
Harald Welte8ffcfed2009-02-10 18:18:50 +0000341 /* We never include the mISDN B-Channel FD into the
342 * writeset, since it doesn't support poll() based
343 * write flow control */
Harald Welte1fa60c82009-02-09 18:13:26 +0000344 break;
345 default:
346 fprintf(stderr, "unknown E1 TS type %u\n", e1i_ts->type);
347 break;
348 }
349
350 return rc;
351}
352
353static int activate_bchan(struct e1inp_line *line, int ts, int act)
354{
355 struct mISDNhead hh;
356 int ret;
357 unsigned int idx = ts-1;
358 struct e1inp_ts *e1i_ts = &line->ts[idx];
359 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
360
361 fprintf(stdout, "activate bchan\n");
362 if (act)
363 hh.prim = PH_ACTIVATE_REQ;
364 else
365 hh.prim = PH_DEACTIVATE_REQ;
366
367 hh.id = MISDN_ID_ANY;
368 ret = sendto(bfd->fd, &hh, sizeof(hh), 0, NULL, 0);
369 if (ret < 0) {
370 fprintf(stdout, "could not send ACTIVATE_RQ %s\n",
371 strerror(errno));
372 }
373
374 return ret;
375}
376
Harald Welte1fa60c82009-02-09 18:13:26 +0000377struct e1inp_driver misdn_driver = {
378 .name = "mISDNuser",
379 .want_write = ts_want_write,
380};
381
Holger Freytherb5c00f52009-04-22 22:08:07 +0000382static int mi_e1_setup(struct e1inp_line *line, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000383{
384 struct mi_e1_handle *e1h = line->driver_data;
385 int ts, ret;
386
387 /* TS0 is CRC4, don't need any fd for it */
388 for (ts = 1; ts < NUM_E1_TS; ts++) {
389 unsigned int idx = ts-1;
390 struct e1inp_ts *e1i_ts = &line->ts[idx];
391 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
392 struct sockaddr_mISDN addr;
393
394 bfd->data = line;
395 bfd->priv_nr = ts;
396 bfd->cb = misdn_fd_cb;
397
398 switch (e1i_ts->type) {
399 case E1INP_TS_TYPE_NONE:
400 continue;
401 break;
402 case E1INP_TS_TYPE_SIGN:
403 bfd->fd = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_LAPD_NT);
404 bfd->when = BSC_FD_READ;
405 break;
406 case E1INP_TS_TYPE_TRAU:
407 bfd->fd = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_RAW);
Harald Welte8ffcfed2009-02-10 18:18:50 +0000408 /* We never include the mISDN B-Channel FD into the
409 * writeset, since it doesn't support poll() based
410 * write flow control */
411 bfd->when = BSC_FD_READ;
Harald Welte1fa60c82009-02-09 18:13:26 +0000412 break;
413 }
414
415 if (bfd->fd < 0) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000416 fprintf(stderr, "%s could not open socket %s\n",
417 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000418 return bfd->fd;
419 }
420
421 memset(&addr, 0, sizeof(addr));
422 addr.family = AF_ISDN;
423 addr.dev = e1h->cardnr;
424 switch (e1i_ts->type) {
425 case E1INP_TS_TYPE_SIGN:
426 addr.channel = 0;
427 /* SAPI not supported yet in kernel */
428 //addr.sapi = e1inp_ts->sign.sapi;
429 addr.sapi = 0;
430 addr.tei = GROUP_TEI;
431 break;
432 case E1INP_TS_TYPE_TRAU:
433 addr.channel = ts;
434 break;
435 default:
436 DEBUGP(DMI, "unsupported E1 TS type: %u\n",
437 e1i_ts->type);
438 break;
439 }
440
441 ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
442 if (ret < 0) {
443 fprintf(stderr, "could not bind l2 socket %s\n",
444 strerror(errno));
445 return -EIO;
446 }
447
Holger Freyther8521e5f2009-06-02 03:25:24 +0000448 if (e1i_ts->type == E1INP_TS_TYPE_SIGN) {
449 ret = ioctl(bfd->fd, IMCLEAR_L2, &release_l2);
Holger Freytherb5c00f52009-04-22 22:08:07 +0000450 if (ret < 0) {
451 fprintf(stderr, "could not send IOCTL IMCLEAN_L2 %s\n", strerror(errno));
452 return -EIO;
453 }
454 }
455
Harald Welte1fa60c82009-02-09 18:13:26 +0000456 /* FIXME: only activate B-Channels once we start to
457 * use them to conserve CPU power */
458 if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
459 activate_bchan(line, ts, 1);
460
461 ret = bsc_register_fd(bfd);
462 if (ret < 0) {
463 fprintf(stderr, "could not register FD: %s\n",
464 strerror(ret));
465 return ret;
466 }
467 }
468
469 return 0;
470}
471
Holger Freytherb5c00f52009-04-22 22:08:07 +0000472int mi_setup(int cardnr, struct e1inp_line *line, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000473{
474 struct mi_e1_handle *e1h;
475 int sk, ret, cnt;
476 struct mISDN_devinfo devinfo;
477
478 /* register the driver with the core */
479 /* FIXME: do this in the plugin initializer function */
480 ret = e1inp_driver_register(&misdn_driver);
481 if (ret)
482 return ret;
483
484 /* create the actual line instance */
485 /* FIXME: do this independent of driver registration */
486 e1h = malloc(sizeof(*e1h));
487 memset(e1h, 0, sizeof(*e1h));
488
489 e1h->cardnr = cardnr;
490
491 line->driver = &misdn_driver;
492 line->driver_data = e1h;
493
494 /* open the ISDN card device */
495 sk = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
496 if (sk < 0) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000497 fprintf(stderr, "%s could not open socket %s\n",
498 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000499 return sk;
500 }
501
502 ret = ioctl(sk, IMGETCOUNT, &cnt);
503 if (ret) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000504 fprintf(stderr, "%s error getting interf count: %s\n",
505 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000506 close(sk);
507 return -ENODEV;
508 }
509 //DEBUGP(DMI,"%d device%s found\n", cnt, (cnt==1)?"":"s");
510 printf("%d device%s found\n", cnt, (cnt==1)?"":"s");
511#if 1
512 devinfo.id = e1h->cardnr;
513 ret = ioctl(sk, IMGETDEVINFO, &devinfo);
514 if (ret < 0) {
515 fprintf(stdout, "error getting info for device %d: %s\n",
516 e1h->cardnr, strerror(errno));
517 return -ENODEV;
518 }
519 fprintf(stdout, " id: %d\n", devinfo.id);
520 fprintf(stdout, " Dprotocols: %08x\n", devinfo.Dprotocols);
521 fprintf(stdout, " Bprotocols: %08x\n", devinfo.Bprotocols);
522 fprintf(stdout, " protocol: %d\n", devinfo.protocol);
523 fprintf(stdout, " nrbchan: %d\n", devinfo.nrbchan);
524 fprintf(stdout, " name: %s\n", devinfo.name);
525#endif
526
Holger Freytheracb688b2009-05-01 04:59:55 +0000527 if (!(devinfo.Dprotocols & (1 << ISDN_P_NT_E1))) {
528 fprintf(stderr, "error: card is not of type E1 (NT-mode)\n");
529 return -EINVAL;
530 }
531
532 if (devinfo.nrbchan != 30) {
533 fprintf(stderr, "error: E1 card has no 30 B-channels\n");
534 return -EINVAL;
535 }
536
Holger Freytherb5c00f52009-04-22 22:08:07 +0000537 ret = mi_e1_setup(line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +0000538 if (ret)
539 return ret;
540
541 return e1inp_line_register(line);
542}