blob: 44f09646df70f37d9807676069083de37b2b710f [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>
Harald Welte2cf161b2009-06-20 22:36:41 +020050#include <openbsc/talloc.h>
Harald Welte1fa60c82009-02-09 18:13:26 +000051
52/* data structure for one E1 interface with A-bis */
53struct mi_e1_handle {
54 /* The mISDN card number of the card we use */
55 int cardnr;
56};
57
58#define TS1_ALLOC_SIZE 300
59
60struct prim_name {
61 unsigned int prim;
62 const char *name;
63};
64
65const struct prim_name prim_names[] = {
Holger Freythercbc7b062009-02-09 23:10:48 +000066 { PH_CONTROL_IND, "PH_CONTROL_IND" },
67 { PH_DATA_IND, "PH_DATA_IND" },
68 { PH_DATA_CNF, "PH_DATA_CNF" },
Holger Freyther5d7e5572009-02-10 18:40:45 +000069 { PH_ACTIVATE_IND, "PH_ACTIVATE_IND" },
Harald Welte1fa60c82009-02-09 18:13:26 +000070 { DL_ESTABLISH_IND, "DL_ESTABLISH_IND" },
71 { DL_ESTABLISH_CNF, "DL_ESTABLISH_CNF" },
72 { DL_RELEASE_IND, "DL_RELEASE_IND" },
73 { DL_RELEASE_CNF, "DL_RELEASE_CNF" },
74 { DL_DATA_IND, "DL_DATA_IND" },
75 { DL_UNITDATA_IND, "DL_UNITDATA_IND" },
76 { DL_INFORMATION_IND, "DL_INFORMATION_IND" },
77 { MPH_ACTIVATE_IND, "MPH_ACTIVATE_IND" },
78 { MPH_DEACTIVATE_IND, "MPH_DEACTIVATE_IND" },
79};
80
81const char *get_prim_name(unsigned int prim)
82{
83 int i;
84
85 for (i = 0; i < ARRAY_SIZE(prim_names); i++) {
86 if (prim_names[i].prim == prim)
87 return prim_names[i].name;
88 }
89
90 return "UNKNOWN";
91}
92
93static int handle_ts1_read(struct bsc_fd *bfd)
94{
95 struct e1inp_line *line = bfd->data;
96 unsigned int ts_nr = bfd->priv_nr;
97 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
98 struct e1inp_sign_link *link;
99 struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE);
100 struct sockaddr_mISDN l2addr;
101 struct mISDNhead *hh;
102 socklen_t alen;
103 int ret;
104
105 if (!msg)
106 return -ENOMEM;
107
108 hh = (struct mISDNhead *) msg->data;
109
110 alen = sizeof(l2addr);
111 ret = recvfrom(bfd->fd, msg->data, 300, 0,
112 (struct sockaddr *) &l2addr, &alen);
113 if (ret < 0) {
114 fprintf(stderr, "recvfrom error %s\n", strerror(errno));
115 return ret;
116 }
117
Holger Freytheracb688b2009-05-01 04:59:55 +0000118 if (alen != sizeof(l2addr)) {
119 fprintf(stderr, "%s error len\n", __func__);
Harald Welte1fa60c82009-02-09 18:13:26 +0000120 return -EINVAL;
Holger Freytheracb688b2009-05-01 04:59:55 +0000121 }
Harald Welte1fa60c82009-02-09 18:13:26 +0000122
123 msgb_put(msg, ret);
124
125 DEBUGP(DMI, "alen =%d, dev(%d) channel(%d) sapi(%d) tei(%d)\n",
126 alen, l2addr.dev, l2addr.channel, l2addr.sapi, l2addr.tei);
127
Holger Freyther57dd7bf2009-02-10 01:04:22 +0000128 DEBUGP(DMI, "<= len = %d, prim(0x%x) id(0x%x): %s\n",
129 ret, hh->prim, hh->id, get_prim_name(hh->prim));
Harald Welte1fa60c82009-02-09 18:13:26 +0000130
131 switch (hh->prim) {
132 case DL_INFORMATION_IND:
133 /* mISDN tells us which channel number is allocated for this
134 * tuple of (SAPI, TEI). */
Holger Freytheracb688b2009-05-01 04:59:55 +0000135 DEBUGP(DMI, "DL_INFORMATION_IND: use channel(%d) sapi(%d) tei(%d) for now\n",
Harald Welte1fa60c82009-02-09 18:13:26 +0000136 l2addr.channel, l2addr.sapi, l2addr.tei);
137 link = e1inp_lookup_sign_link(e1i_ts, l2addr.tei, l2addr.sapi);
138 if (!link) {
139 DEBUGPC(DMI, "mISDN message for unknown sign_link\n");
Harald Welte2cf161b2009-06-20 22:36:41 +0200140 msgb_free(msg);
Harald Welte1fa60c82009-02-09 18:13:26 +0000141 return -EINVAL;
142 }
143 /* save the channel number in the driver private struct */
144 link->driver.misdn.channel = l2addr.channel;
145 break;
Harald Welte7d144762009-05-23 05:40:49 +0000146 case DL_ESTABLISH_IND:
147 DEBUGP(DMI, "DL_ESTABLISH_IND: channel(%d) sapi(%d) tei(%d)\n",
148 l2addr.channel, l2addr.sapi, l2addr.tei);
Harald Welte1fa60c82009-02-09 18:13:26 +0000149 ret = e1inp_event(e1i_ts, EVT_E1_TEI_UP, l2addr.tei, l2addr.sapi);
150 break;
Harald Welte7d144762009-05-23 05:40:49 +0000151 case DL_RELEASE_IND:
152 DEBUGP(DMI, "DL_RELEASE_IND: channel(%d) sapi(%d) tei(%d)\n",
153 l2addr.channel, l2addr.sapi, l2addr.tei);
Harald Welte1fa60c82009-02-09 18:13:26 +0000154 ret = e1inp_event(e1i_ts, EVT_E1_TEI_DN, l2addr.tei, l2addr.sapi);
155 break;
156 case DL_DATA_IND:
Harald Welte1fa60c82009-02-09 18:13:26 +0000157 msg->l2h = msg->data + MISDN_HEADER_LEN;
Harald Welte3cc4bf52009-02-28 13:08:01 +0000158 DEBUGP(DMI, "RX: %s\n", hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000159 ret = e1inp_rx_ts(e1i_ts, msg, l2addr.tei, l2addr.sapi);
160 break;
Harald Welte7d144762009-05-23 05:40:49 +0000161 case PH_ACTIVATE_IND:
162 DEBUGP(DMI, "PH_ACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
163 l2addr.channel, l2addr.sapi, l2addr.tei);
164 break;
165 case PH_DEACTIVATE_IND:
166 DEBUGP(DMI, "PH_DEACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
167 l2addr.channel, l2addr.sapi, l2addr.tei);
168 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000169 default:
170 break;
171 }
172 return ret;
173}
174
Harald Weltef55b49f2009-05-23 06:20:41 +0000175static int ts_want_write(struct e1inp_ts *e1i_ts)
176{
177 /* We never include the mISDN B-Channel FD into the
178 * writeset, since it doesn't support poll() based
179 * write flow control */
180 if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
181 return 0;
182
183 e1i_ts->driver.misdn.fd.when |= BSC_FD_WRITE;
184
185 return 0;
186}
187
188static void timeout_ts1_write(void *data)
189{
190 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
191
192 /* trigger write of ts1, due to tx delay timer */
193 ts_want_write(e1i_ts);
194}
195
Harald Welte1fa60c82009-02-09 18:13:26 +0000196static int handle_ts1_write(struct bsc_fd *bfd)
197{
198 struct e1inp_line *line = bfd->data;
199 unsigned int ts_nr = bfd->priv_nr;
200 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
201 struct e1inp_sign_link *sign_link;
202 struct sockaddr_mISDN sa;
203 struct msgb *msg;
204 struct mISDNhead *hh;
205 u_int8_t *l2_data;
206 int ret;
207
Harald Weltef55b49f2009-05-23 06:20:41 +0000208 bfd->when &= ~BSC_FD_WRITE;
209
Harald Welte1fa60c82009-02-09 18:13:26 +0000210 /* get the next msg for this timeslot */
211 msg = e1inp_tx_ts(e1i_ts, &sign_link);
212 if (!msg) {
Harald Weltef55b49f2009-05-23 06:20:41 +0000213 /* no message after tx delay timer */
Harald Welte1fa60c82009-02-09 18:13:26 +0000214 return 0;
215 }
216
217 l2_data = msg->data;
218
219 /* prepend the mISDNhead */
220 hh = (struct mISDNhead *) msgb_push(msg, sizeof(*hh));
221 hh->prim = DL_DATA_REQ;
222
Holger Freytheracb688b2009-05-01 04:59:55 +0000223 DEBUGP(DMI, "TX TEI(%d) SAPI(%d): %s\n", sign_link->tei,
224 sign_link->sapi, hexdump(l2_data, msg->len - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000225
226 /* construct the sockaddr */
227 sa.family = AF_ISDN;
228 sa.sapi = sign_link->sapi;
229 sa.dev = sign_link->tei;
230 sa.channel = sign_link->driver.misdn.channel;
231
232 ret = sendto(bfd->fd, msg->data, msg->len, 0,
233 (struct sockaddr *)&sa, sizeof(sa));
Holger Freytheracb688b2009-05-01 04:59:55 +0000234 if (ret < 0)
235 fprintf(stderr, "%s sendto failed %d\n", __func__, ret);
Harald Welte1fa60c82009-02-09 18:13:26 +0000236 msgb_free(msg);
237
Harald Weltef55b49f2009-05-23 06:20:41 +0000238 /* set tx delay timer for next event */
239 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
240 e1i_ts->sign.tx_timer.data = e1i_ts;
241 bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 50000);
Harald Welte1fa60c82009-02-09 18:13:26 +0000242
243 return ret;
244}
245
Harald Weltef9227c72009-02-18 03:39:00 +0000246#define BCHAN_TX_GRAN 160
Harald Welte8ffcfed2009-02-10 18:18:50 +0000247/* write to a B channel TS */
248static int handle_tsX_write(struct bsc_fd *bfd)
249{
250 struct e1inp_line *line = bfd->data;
251 unsigned int ts_nr = bfd->priv_nr;
252 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
253 struct mISDNhead *hh;
254 u_int8_t tx_buf[BCHAN_TX_GRAN + sizeof(*hh)];
255 struct subch_mux *mx = &e1i_ts->trau.mux;
256 int ret;
Harald Welte1fa60c82009-02-09 18:13:26 +0000257
Harald Welte8ffcfed2009-02-10 18:18:50 +0000258 hh = (struct mISDNhead *) tx_buf;
259 hh->prim = PH_DATA_REQ;
260
261 subchan_mux_out(mx, tx_buf+sizeof(*hh), BCHAN_TX_GRAN);
262
Harald Welte3cc4bf52009-02-28 13:08:01 +0000263 DEBUGP(DMIB, "BCHAN TX: %s\n",
264 hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN));
Harald Welte8ffcfed2009-02-10 18:18:50 +0000265
266 ret = send(bfd->fd, tx_buf, sizeof(*hh) + BCHAN_TX_GRAN, 0);
267 if (ret < sizeof(*hh) + BCHAN_TX_GRAN)
268 DEBUGP(DMIB, "send returns %d instead of %u\n", ret,
269 sizeof(*hh) + BCHAN_TX_GRAN);
270
271 return ret;
272}
273
274#define TSX_ALLOC_SIZE 4096
Harald Welte1fa60c82009-02-09 18:13:26 +0000275/* FIXME: read from a B channel TS */
276static int handle_tsX_read(struct bsc_fd *bfd)
277{
278 struct e1inp_line *line = bfd->data;
279 unsigned int ts_nr = bfd->priv_nr;
280 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
281 struct msgb *msg = msgb_alloc(TSX_ALLOC_SIZE);
282 struct mISDNhead *hh;
283 int ret;
284
285 if (!msg)
286 return -ENOMEM;
287
288 hh = (struct mISDNhead *) msg->data;
289
290 ret = recv(bfd->fd, msg->data, TSX_ALLOC_SIZE, 0);
291 if (ret < 0) {
292 fprintf(stderr, "recvfrom error %s\n", strerror(errno));
293 return ret;
294 }
295
296 msgb_put(msg, ret);
297
Holger Freytheracb688b2009-05-01 04:59:55 +0000298 if (hh->prim != PH_CONTROL_IND)
299 DEBUGP(DMIB, "<= BCHAN len = %d, prim(0x%x) id(0x%x): %s\n",
300 ret, hh->prim, hh->id, get_prim_name(hh->prim));
Harald Welte1fa60c82009-02-09 18:13:26 +0000301
302 switch (hh->prim) {
303 case PH_DATA_IND:
304 msg->l2h = msg->data + MISDN_HEADER_LEN;
Harald Welte3cc4bf52009-02-28 13:08:01 +0000305 DEBUGP(DMIB, "BCHAN RX: %s\n",
306 hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000307 ret = e1inp_rx_ts(e1i_ts, msg, 0, 0);
308 break;
Holger Freyther5d7e5572009-02-10 18:40:45 +0000309 case PH_ACTIVATE_IND:
Harald Welte8ffcfed2009-02-10 18:18:50 +0000310 case PH_DATA_CNF:
311 /* physical layer indicates that data has been sent,
312 * we thus can send some more data */
313 ret = handle_tsX_write(bfd);
Harald Welte1fa60c82009-02-09 18:13:26 +0000314 default:
315 break;
316 }
317 /* FIXME: why do we free signalling msgs in the caller, and trau not? */
318 msgb_free(msg);
319
320 return ret;
321}
322
Harald Welte1fa60c82009-02-09 18:13:26 +0000323/* callback from select.c in case one of the fd's can be read/written */
324static int misdn_fd_cb(struct bsc_fd *bfd, unsigned int what)
325{
326 struct e1inp_line *line = bfd->data;
327 unsigned int ts_nr = bfd->priv_nr;
328 unsigned int idx = ts_nr-1;
329 struct e1inp_ts *e1i_ts = &line->ts[idx];
330 int rc = 0;
331
332 switch (e1i_ts->type) {
333 case E1INP_TS_TYPE_SIGN:
334 if (what & BSC_FD_READ)
335 rc = handle_ts1_read(bfd);
336 if (what & BSC_FD_WRITE)
337 rc = handle_ts1_write(bfd);
338 break;
339 case E1INP_TS_TYPE_TRAU:
340 if (what & BSC_FD_READ)
341 rc = handle_tsX_read(bfd);
Harald Welte8ffcfed2009-02-10 18:18:50 +0000342 /* We never include the mISDN B-Channel FD into the
343 * writeset, since it doesn't support poll() based
344 * write flow control */
Harald Welte1fa60c82009-02-09 18:13:26 +0000345 break;
346 default:
347 fprintf(stderr, "unknown E1 TS type %u\n", e1i_ts->type);
348 break;
349 }
350
351 return rc;
352}
353
354static int activate_bchan(struct e1inp_line *line, int ts, int act)
355{
356 struct mISDNhead hh;
357 int ret;
358 unsigned int idx = ts-1;
359 struct e1inp_ts *e1i_ts = &line->ts[idx];
360 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
361
362 fprintf(stdout, "activate bchan\n");
363 if (act)
364 hh.prim = PH_ACTIVATE_REQ;
365 else
366 hh.prim = PH_DEACTIVATE_REQ;
367
368 hh.id = MISDN_ID_ANY;
369 ret = sendto(bfd->fd, &hh, sizeof(hh), 0, NULL, 0);
370 if (ret < 0) {
371 fprintf(stdout, "could not send ACTIVATE_RQ %s\n",
372 strerror(errno));
373 }
374
375 return ret;
376}
377
Harald Welte1fa60c82009-02-09 18:13:26 +0000378struct e1inp_driver misdn_driver = {
379 .name = "mISDNuser",
380 .want_write = ts_want_write,
381};
382
Holger Freytherb5c00f52009-04-22 22:08:07 +0000383static int mi_e1_setup(struct e1inp_line *line, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000384{
385 struct mi_e1_handle *e1h = line->driver_data;
386 int ts, ret;
387
388 /* TS0 is CRC4, don't need any fd for it */
389 for (ts = 1; ts < NUM_E1_TS; ts++) {
390 unsigned int idx = ts-1;
391 struct e1inp_ts *e1i_ts = &line->ts[idx];
392 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
393 struct sockaddr_mISDN addr;
394
395 bfd->data = line;
396 bfd->priv_nr = ts;
397 bfd->cb = misdn_fd_cb;
398
399 switch (e1i_ts->type) {
400 case E1INP_TS_TYPE_NONE:
401 continue;
402 break;
403 case E1INP_TS_TYPE_SIGN:
404 bfd->fd = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_LAPD_NT);
405 bfd->when = BSC_FD_READ;
406 break;
407 case E1INP_TS_TYPE_TRAU:
408 bfd->fd = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_RAW);
Harald Welte8ffcfed2009-02-10 18:18:50 +0000409 /* We never include the mISDN B-Channel FD into the
410 * writeset, since it doesn't support poll() based
411 * write flow control */
412 bfd->when = BSC_FD_READ;
Harald Welte1fa60c82009-02-09 18:13:26 +0000413 break;
414 }
415
416 if (bfd->fd < 0) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000417 fprintf(stderr, "%s could not open socket %s\n",
418 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000419 return bfd->fd;
420 }
421
422 memset(&addr, 0, sizeof(addr));
423 addr.family = AF_ISDN;
424 addr.dev = e1h->cardnr;
425 switch (e1i_ts->type) {
426 case E1INP_TS_TYPE_SIGN:
427 addr.channel = 0;
428 /* SAPI not supported yet in kernel */
429 //addr.sapi = e1inp_ts->sign.sapi;
430 addr.sapi = 0;
431 addr.tei = GROUP_TEI;
432 break;
433 case E1INP_TS_TYPE_TRAU:
434 addr.channel = ts;
435 break;
436 default:
437 DEBUGP(DMI, "unsupported E1 TS type: %u\n",
438 e1i_ts->type);
439 break;
440 }
441
442 ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
443 if (ret < 0) {
444 fprintf(stderr, "could not bind l2 socket %s\n",
445 strerror(errno));
446 return -EIO;
447 }
448
Holger Freyther8521e5f2009-06-02 03:25:24 +0000449 if (e1i_ts->type == E1INP_TS_TYPE_SIGN) {
450 ret = ioctl(bfd->fd, IMCLEAR_L2, &release_l2);
Holger Freytherb5c00f52009-04-22 22:08:07 +0000451 if (ret < 0) {
452 fprintf(stderr, "could not send IOCTL IMCLEAN_L2 %s\n", strerror(errno));
453 return -EIO;
454 }
455 }
456
Harald Welte1fa60c82009-02-09 18:13:26 +0000457 /* FIXME: only activate B-Channels once we start to
458 * use them to conserve CPU power */
459 if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
460 activate_bchan(line, ts, 1);
461
462 ret = bsc_register_fd(bfd);
463 if (ret < 0) {
464 fprintf(stderr, "could not register FD: %s\n",
465 strerror(ret));
466 return ret;
467 }
468 }
469
470 return 0;
471}
472
Holger Freytherb5c00f52009-04-22 22:08:07 +0000473int mi_setup(int cardnr, struct e1inp_line *line, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000474{
475 struct mi_e1_handle *e1h;
476 int sk, ret, cnt;
477 struct mISDN_devinfo devinfo;
478
479 /* register the driver with the core */
480 /* FIXME: do this in the plugin initializer function */
481 ret = e1inp_driver_register(&misdn_driver);
482 if (ret)
483 return ret;
484
485 /* create the actual line instance */
486 /* FIXME: do this independent of driver registration */
Harald Welte2cf161b2009-06-20 22:36:41 +0200487 e1h = talloc(tall_bsc_ctx, struct mi_e1_handle);
Harald Welte1fa60c82009-02-09 18:13:26 +0000488 memset(e1h, 0, sizeof(*e1h));
489
490 e1h->cardnr = cardnr;
491
492 line->driver = &misdn_driver;
493 line->driver_data = e1h;
494
495 /* open the ISDN card device */
496 sk = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
497 if (sk < 0) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000498 fprintf(stderr, "%s could not open socket %s\n",
499 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000500 return sk;
501 }
502
503 ret = ioctl(sk, IMGETCOUNT, &cnt);
504 if (ret) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000505 fprintf(stderr, "%s error getting interf count: %s\n",
506 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000507 close(sk);
508 return -ENODEV;
509 }
510 //DEBUGP(DMI,"%d device%s found\n", cnt, (cnt==1)?"":"s");
511 printf("%d device%s found\n", cnt, (cnt==1)?"":"s");
512#if 1
513 devinfo.id = e1h->cardnr;
514 ret = ioctl(sk, IMGETDEVINFO, &devinfo);
515 if (ret < 0) {
516 fprintf(stdout, "error getting info for device %d: %s\n",
517 e1h->cardnr, strerror(errno));
518 return -ENODEV;
519 }
520 fprintf(stdout, " id: %d\n", devinfo.id);
521 fprintf(stdout, " Dprotocols: %08x\n", devinfo.Dprotocols);
522 fprintf(stdout, " Bprotocols: %08x\n", devinfo.Bprotocols);
523 fprintf(stdout, " protocol: %d\n", devinfo.protocol);
524 fprintf(stdout, " nrbchan: %d\n", devinfo.nrbchan);
525 fprintf(stdout, " name: %s\n", devinfo.name);
526#endif
527
Holger Freytheracb688b2009-05-01 04:59:55 +0000528 if (!(devinfo.Dprotocols & (1 << ISDN_P_NT_E1))) {
529 fprintf(stderr, "error: card is not of type E1 (NT-mode)\n");
530 return -EINVAL;
531 }
532
533 if (devinfo.nrbchan != 30) {
534 fprintf(stderr, "error: E1 card has no 30 B-channels\n");
535 return -EINVAL;
536 }
537
Holger Freytherb5c00f52009-04-22 22:08:07 +0000538 ret = mi_e1_setup(line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +0000539 if (ret)
540 return ret;
541
542 return e1inp_line_register(line);
543}