blob: a04c2abd799739e8ff6400447eba3e193f128f6b [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;
Harald Welte966636f2009-06-26 19:39:35 +020099 struct msgb *msg = msgb_alloc(TS1_ALLOC_SIZE, "mISDN TS1");
Harald Welte1fa60c82009-02-09 18:13:26 +0000100 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 Weltedd2b4342009-07-04 09:28:00 +0200157 case DL_UNITDATA_IND:
Harald Welte1fa60c82009-02-09 18:13:26 +0000158 msg->l2h = msg->data + MISDN_HEADER_LEN;
Harald Welte3cc4bf52009-02-28 13:08:01 +0000159 DEBUGP(DMI, "RX: %s\n", hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000160 ret = e1inp_rx_ts(e1i_ts, msg, l2addr.tei, l2addr.sapi);
161 break;
Harald Welte7d144762009-05-23 05:40:49 +0000162 case PH_ACTIVATE_IND:
163 DEBUGP(DMI, "PH_ACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
164 l2addr.channel, l2addr.sapi, l2addr.tei);
165 break;
166 case PH_DEACTIVATE_IND:
167 DEBUGP(DMI, "PH_DEACTIVATE_IND: channel(%d) sapi(%d) tei(%d)\n",
168 l2addr.channel, l2addr.sapi, l2addr.tei);
169 break;
Harald Welte1fa60c82009-02-09 18:13:26 +0000170 default:
171 break;
172 }
173 return ret;
174}
175
Harald Weltef55b49f2009-05-23 06:20:41 +0000176static int ts_want_write(struct e1inp_ts *e1i_ts)
177{
178 /* We never include the mISDN B-Channel FD into the
179 * writeset, since it doesn't support poll() based
180 * write flow control */
181 if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
182 return 0;
183
184 e1i_ts->driver.misdn.fd.when |= BSC_FD_WRITE;
185
186 return 0;
187}
188
189static void timeout_ts1_write(void *data)
190{
191 struct e1inp_ts *e1i_ts = (struct e1inp_ts *)data;
192
193 /* trigger write of ts1, due to tx delay timer */
194 ts_want_write(e1i_ts);
195}
196
Harald Welte1fa60c82009-02-09 18:13:26 +0000197static int handle_ts1_write(struct bsc_fd *bfd)
198{
199 struct e1inp_line *line = bfd->data;
200 unsigned int ts_nr = bfd->priv_nr;
201 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
202 struct e1inp_sign_link *sign_link;
203 struct sockaddr_mISDN sa;
204 struct msgb *msg;
205 struct mISDNhead *hh;
206 u_int8_t *l2_data;
207 int ret;
208
Harald Weltef55b49f2009-05-23 06:20:41 +0000209 bfd->when &= ~BSC_FD_WRITE;
210
Harald Welte1fa60c82009-02-09 18:13:26 +0000211 /* get the next msg for this timeslot */
212 msg = e1inp_tx_ts(e1i_ts, &sign_link);
213 if (!msg) {
Harald Weltef55b49f2009-05-23 06:20:41 +0000214 /* no message after tx delay timer */
Harald Welte1fa60c82009-02-09 18:13:26 +0000215 return 0;
216 }
217
218 l2_data = msg->data;
219
220 /* prepend the mISDNhead */
221 hh = (struct mISDNhead *) msgb_push(msg, sizeof(*hh));
222 hh->prim = DL_DATA_REQ;
223
Holger Freytheracb688b2009-05-01 04:59:55 +0000224 DEBUGP(DMI, "TX TEI(%d) SAPI(%d): %s\n", sign_link->tei,
225 sign_link->sapi, hexdump(l2_data, msg->len - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000226
227 /* construct the sockaddr */
228 sa.family = AF_ISDN;
229 sa.sapi = sign_link->sapi;
230 sa.dev = sign_link->tei;
231 sa.channel = sign_link->driver.misdn.channel;
232
233 ret = sendto(bfd->fd, msg->data, msg->len, 0,
234 (struct sockaddr *)&sa, sizeof(sa));
Holger Freytheracb688b2009-05-01 04:59:55 +0000235 if (ret < 0)
236 fprintf(stderr, "%s sendto failed %d\n", __func__, ret);
Harald Welte1fa60c82009-02-09 18:13:26 +0000237 msgb_free(msg);
238
Harald Weltef55b49f2009-05-23 06:20:41 +0000239 /* set tx delay timer for next event */
240 e1i_ts->sign.tx_timer.cb = timeout_ts1_write;
241 e1i_ts->sign.tx_timer.data = e1i_ts;
242 bsc_schedule_timer(&e1i_ts->sign.tx_timer, 0, 50000);
Harald Welte1fa60c82009-02-09 18:13:26 +0000243
244 return ret;
245}
246
Harald Weltef9227c72009-02-18 03:39:00 +0000247#define BCHAN_TX_GRAN 160
Harald Welte8ffcfed2009-02-10 18:18:50 +0000248/* write to a B channel TS */
249static int handle_tsX_write(struct bsc_fd *bfd)
250{
251 struct e1inp_line *line = bfd->data;
252 unsigned int ts_nr = bfd->priv_nr;
253 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
254 struct mISDNhead *hh;
255 u_int8_t tx_buf[BCHAN_TX_GRAN + sizeof(*hh)];
256 struct subch_mux *mx = &e1i_ts->trau.mux;
257 int ret;
Harald Welte1fa60c82009-02-09 18:13:26 +0000258
Harald Welte8ffcfed2009-02-10 18:18:50 +0000259 hh = (struct mISDNhead *) tx_buf;
260 hh->prim = PH_DATA_REQ;
261
262 subchan_mux_out(mx, tx_buf+sizeof(*hh), BCHAN_TX_GRAN);
263
Harald Welte3cc4bf52009-02-28 13:08:01 +0000264 DEBUGP(DMIB, "BCHAN TX: %s\n",
265 hexdump(tx_buf+sizeof(*hh), BCHAN_TX_GRAN));
Harald Welte8ffcfed2009-02-10 18:18:50 +0000266
267 ret = send(bfd->fd, tx_buf, sizeof(*hh) + BCHAN_TX_GRAN, 0);
268 if (ret < sizeof(*hh) + BCHAN_TX_GRAN)
269 DEBUGP(DMIB, "send returns %d instead of %u\n", ret,
270 sizeof(*hh) + BCHAN_TX_GRAN);
271
272 return ret;
273}
274
275#define TSX_ALLOC_SIZE 4096
Harald Welte1fa60c82009-02-09 18:13:26 +0000276/* FIXME: read from a B channel TS */
277static int handle_tsX_read(struct bsc_fd *bfd)
278{
279 struct e1inp_line *line = bfd->data;
280 unsigned int ts_nr = bfd->priv_nr;
281 struct e1inp_ts *e1i_ts = &line->ts[ts_nr-1];
Harald Welte966636f2009-06-26 19:39:35 +0200282 struct msgb *msg = msgb_alloc(TSX_ALLOC_SIZE, "mISDN TSx");
Harald Welte1fa60c82009-02-09 18:13:26 +0000283 struct mISDNhead *hh;
284 int ret;
285
286 if (!msg)
287 return -ENOMEM;
288
289 hh = (struct mISDNhead *) msg->data;
290
291 ret = recv(bfd->fd, msg->data, TSX_ALLOC_SIZE, 0);
292 if (ret < 0) {
293 fprintf(stderr, "recvfrom error %s\n", strerror(errno));
294 return ret;
295 }
296
297 msgb_put(msg, ret);
298
Holger Freytheracb688b2009-05-01 04:59:55 +0000299 if (hh->prim != PH_CONTROL_IND)
300 DEBUGP(DMIB, "<= BCHAN len = %d, prim(0x%x) id(0x%x): %s\n",
301 ret, hh->prim, hh->id, get_prim_name(hh->prim));
Harald Welte1fa60c82009-02-09 18:13:26 +0000302
303 switch (hh->prim) {
304 case PH_DATA_IND:
305 msg->l2h = msg->data + MISDN_HEADER_LEN;
Harald Welte3cc4bf52009-02-28 13:08:01 +0000306 DEBUGP(DMIB, "BCHAN RX: %s\n",
307 hexdump(msgb_l2(msg), ret - MISDN_HEADER_LEN));
Harald Welte1fa60c82009-02-09 18:13:26 +0000308 ret = e1inp_rx_ts(e1i_ts, msg, 0, 0);
309 break;
Holger Freyther5d7e5572009-02-10 18:40:45 +0000310 case PH_ACTIVATE_IND:
Harald Welte8ffcfed2009-02-10 18:18:50 +0000311 case PH_DATA_CNF:
312 /* physical layer indicates that data has been sent,
313 * we thus can send some more data */
314 ret = handle_tsX_write(bfd);
Harald Welte1fa60c82009-02-09 18:13:26 +0000315 default:
316 break;
317 }
318 /* FIXME: why do we free signalling msgs in the caller, and trau not? */
319 msgb_free(msg);
320
321 return ret;
322}
323
Harald Welte1fa60c82009-02-09 18:13:26 +0000324/* callback from select.c in case one of the fd's can be read/written */
325static int misdn_fd_cb(struct bsc_fd *bfd, unsigned int what)
326{
327 struct e1inp_line *line = bfd->data;
328 unsigned int ts_nr = bfd->priv_nr;
329 unsigned int idx = ts_nr-1;
330 struct e1inp_ts *e1i_ts = &line->ts[idx];
331 int rc = 0;
332
333 switch (e1i_ts->type) {
334 case E1INP_TS_TYPE_SIGN:
335 if (what & BSC_FD_READ)
336 rc = handle_ts1_read(bfd);
337 if (what & BSC_FD_WRITE)
338 rc = handle_ts1_write(bfd);
339 break;
340 case E1INP_TS_TYPE_TRAU:
341 if (what & BSC_FD_READ)
342 rc = handle_tsX_read(bfd);
Harald Welte8ffcfed2009-02-10 18:18:50 +0000343 /* We never include the mISDN B-Channel FD into the
344 * writeset, since it doesn't support poll() based
345 * write flow control */
Harald Welte1fa60c82009-02-09 18:13:26 +0000346 break;
347 default:
348 fprintf(stderr, "unknown E1 TS type %u\n", e1i_ts->type);
349 break;
350 }
351
352 return rc;
353}
354
355static int activate_bchan(struct e1inp_line *line, int ts, int act)
356{
357 struct mISDNhead hh;
358 int ret;
359 unsigned int idx = ts-1;
360 struct e1inp_ts *e1i_ts = &line->ts[idx];
361 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
362
363 fprintf(stdout, "activate bchan\n");
364 if (act)
365 hh.prim = PH_ACTIVATE_REQ;
366 else
367 hh.prim = PH_DEACTIVATE_REQ;
368
369 hh.id = MISDN_ID_ANY;
370 ret = sendto(bfd->fd, &hh, sizeof(hh), 0, NULL, 0);
371 if (ret < 0) {
372 fprintf(stdout, "could not send ACTIVATE_RQ %s\n",
373 strerror(errno));
374 }
375
376 return ret;
377}
378
Harald Welte1fa60c82009-02-09 18:13:26 +0000379struct e1inp_driver misdn_driver = {
380 .name = "mISDNuser",
381 .want_write = ts_want_write,
382};
383
Holger Freytherb5c00f52009-04-22 22:08:07 +0000384static int mi_e1_setup(struct e1inp_line *line, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000385{
386 struct mi_e1_handle *e1h = line->driver_data;
387 int ts, ret;
388
389 /* TS0 is CRC4, don't need any fd for it */
390 for (ts = 1; ts < NUM_E1_TS; ts++) {
391 unsigned int idx = ts-1;
392 struct e1inp_ts *e1i_ts = &line->ts[idx];
393 struct bsc_fd *bfd = &e1i_ts->driver.misdn.fd;
394 struct sockaddr_mISDN addr;
395
396 bfd->data = line;
397 bfd->priv_nr = ts;
398 bfd->cb = misdn_fd_cb;
399
400 switch (e1i_ts->type) {
401 case E1INP_TS_TYPE_NONE:
402 continue;
403 break;
404 case E1INP_TS_TYPE_SIGN:
405 bfd->fd = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_LAPD_NT);
406 bfd->when = BSC_FD_READ;
407 break;
408 case E1INP_TS_TYPE_TRAU:
409 bfd->fd = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_RAW);
Harald Welte8ffcfed2009-02-10 18:18:50 +0000410 /* We never include the mISDN B-Channel FD into the
411 * writeset, since it doesn't support poll() based
412 * write flow control */
413 bfd->when = BSC_FD_READ;
Harald Welte1fa60c82009-02-09 18:13:26 +0000414 break;
415 }
416
417 if (bfd->fd < 0) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000418 fprintf(stderr, "%s could not open socket %s\n",
419 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000420 return bfd->fd;
421 }
422
423 memset(&addr, 0, sizeof(addr));
424 addr.family = AF_ISDN;
425 addr.dev = e1h->cardnr;
426 switch (e1i_ts->type) {
427 case E1INP_TS_TYPE_SIGN:
428 addr.channel = 0;
429 /* SAPI not supported yet in kernel */
430 //addr.sapi = e1inp_ts->sign.sapi;
431 addr.sapi = 0;
432 addr.tei = GROUP_TEI;
433 break;
434 case E1INP_TS_TYPE_TRAU:
435 addr.channel = ts;
436 break;
437 default:
438 DEBUGP(DMI, "unsupported E1 TS type: %u\n",
439 e1i_ts->type);
440 break;
441 }
442
443 ret = bind(bfd->fd, (struct sockaddr *) &addr, sizeof(addr));
444 if (ret < 0) {
445 fprintf(stderr, "could not bind l2 socket %s\n",
446 strerror(errno));
447 return -EIO;
448 }
449
Holger Freyther8521e5f2009-06-02 03:25:24 +0000450 if (e1i_ts->type == E1INP_TS_TYPE_SIGN) {
451 ret = ioctl(bfd->fd, IMCLEAR_L2, &release_l2);
Holger Freytherb5c00f52009-04-22 22:08:07 +0000452 if (ret < 0) {
453 fprintf(stderr, "could not send IOCTL IMCLEAN_L2 %s\n", strerror(errno));
454 return -EIO;
455 }
456 }
457
Harald Welte1fa60c82009-02-09 18:13:26 +0000458 /* FIXME: only activate B-Channels once we start to
459 * use them to conserve CPU power */
460 if (e1i_ts->type == E1INP_TS_TYPE_TRAU)
461 activate_bchan(line, ts, 1);
462
463 ret = bsc_register_fd(bfd);
464 if (ret < 0) {
465 fprintf(stderr, "could not register FD: %s\n",
466 strerror(ret));
467 return ret;
468 }
469 }
470
471 return 0;
472}
473
Holger Freytherb5c00f52009-04-22 22:08:07 +0000474int mi_setup(int cardnr, struct e1inp_line *line, int release_l2)
Harald Welte1fa60c82009-02-09 18:13:26 +0000475{
476 struct mi_e1_handle *e1h;
477 int sk, ret, cnt;
478 struct mISDN_devinfo devinfo;
479
480 /* register the driver with the core */
481 /* FIXME: do this in the plugin initializer function */
482 ret = e1inp_driver_register(&misdn_driver);
483 if (ret)
484 return ret;
485
486 /* create the actual line instance */
487 /* FIXME: do this independent of driver registration */
Harald Welte2cf161b2009-06-20 22:36:41 +0200488 e1h = talloc(tall_bsc_ctx, struct mi_e1_handle);
Harald Welte1fa60c82009-02-09 18:13:26 +0000489 memset(e1h, 0, sizeof(*e1h));
490
491 e1h->cardnr = cardnr;
492
493 line->driver = &misdn_driver;
494 line->driver_data = e1h;
495
496 /* open the ISDN card device */
497 sk = socket(PF_ISDN, SOCK_RAW, ISDN_P_BASE);
498 if (sk < 0) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000499 fprintf(stderr, "%s could not open socket %s\n",
500 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000501 return sk;
502 }
503
504 ret = ioctl(sk, IMGETCOUNT, &cnt);
505 if (ret) {
Holger Freytheracb688b2009-05-01 04:59:55 +0000506 fprintf(stderr, "%s error getting interf count: %s\n",
507 __func__, strerror(errno));
Harald Welte1fa60c82009-02-09 18:13:26 +0000508 close(sk);
509 return -ENODEV;
510 }
511 //DEBUGP(DMI,"%d device%s found\n", cnt, (cnt==1)?"":"s");
512 printf("%d device%s found\n", cnt, (cnt==1)?"":"s");
513#if 1
514 devinfo.id = e1h->cardnr;
515 ret = ioctl(sk, IMGETDEVINFO, &devinfo);
516 if (ret < 0) {
517 fprintf(stdout, "error getting info for device %d: %s\n",
518 e1h->cardnr, strerror(errno));
519 return -ENODEV;
520 }
521 fprintf(stdout, " id: %d\n", devinfo.id);
522 fprintf(stdout, " Dprotocols: %08x\n", devinfo.Dprotocols);
523 fprintf(stdout, " Bprotocols: %08x\n", devinfo.Bprotocols);
524 fprintf(stdout, " protocol: %d\n", devinfo.protocol);
525 fprintf(stdout, " nrbchan: %d\n", devinfo.nrbchan);
526 fprintf(stdout, " name: %s\n", devinfo.name);
527#endif
528
Holger Freytheracb688b2009-05-01 04:59:55 +0000529 if (!(devinfo.Dprotocols & (1 << ISDN_P_NT_E1))) {
530 fprintf(stderr, "error: card is not of type E1 (NT-mode)\n");
531 return -EINVAL;
532 }
533
534 if (devinfo.nrbchan != 30) {
535 fprintf(stderr, "error: E1 card has no 30 B-channels\n");
536 return -EINVAL;
537 }
538
Holger Freytherb5c00f52009-04-22 22:08:07 +0000539 ret = mi_e1_setup(line, release_l2);
Harald Welte1fa60c82009-02-09 18:13:26 +0000540 if (ret)
541 return ret;
542
543 return e1inp_line_register(line);
544}