224 #define L1OIP_VERSION 0
226 #include <linux/module.h>
232 #include <linux/in.h>
236 #include <linux/slab.h>
241 static const char *l1oip_revision =
"2.00";
243 static int l1oip_cnt;
291 if ((
int)(hc->
keep_tl.expires-jiffies) < 5 *
HZ) {
298 if (
debug & DEBUG_L1OIP_MSG)
303 if (
debug & DEBUG_L1OIP_MSG)
305 "IP is not set.\n", __func__);
311 | (hc->
pri ? 0x20 : 0x00)
312 | (hc->
id ? 0x10 : 0x00)
320 *p++ = (multi == 1) ? 0x80 : 0x00 + channel;
323 *p++ = timebase >> 8;
327 if (localcodec == 1 && ulaw)
329 else if (localcodec == 2 && !ulaw)
331 else if (localcodec == 3)
333 &hc->
chan[channel].codecstate);
350 if (
debug & DEBUG_L1OIP_MSG)
352 "= %d)\n", __func__, len);
367 l1oip_socket_recv(
struct l1oip *hc,
u8 remotecodec,
u8 channel,
u16 timebase,
377 if (
debug & DEBUG_L1OIP_MSG)
379 "ignoring\n", __func__);
383 if (
debug & DEBUG_L1OIP_MSG)
389 "range\n", __func__, channel);
396 "stack\n", __func__, channel);
401 nskb = mI_alloc_skb((remotecodec == 3) ? (len << 1) : len,
GFP_ATOMIC);
406 p =
skb_put(nskb, (remotecodec == 3) ? (len << 1) : len);
408 if (remotecodec == 1 && ulaw)
410 else if (remotecodec == 2 && !ulaw)
412 else if (remotecodec == 3)
418 if (dch && len >= 2) {
425 if (((
s16)(timebase - rx_counter)) >= 0) {
427 if (timebase >= (rx_counter & 0xffff))
429 (rx_counter & 0xffff0000) | timebase;
431 rx_counter = ((rx_counter & 0xffff0000) + 0x10000)
435 if (timebase < (rx_counter & 0xffff))
437 (rx_counter & 0xffff0000) | timebase;
439 rx_counter = ((rx_counter & 0xffff0000) - 0x10000)
445 if (hc->
chan[channel].disorder_flag) {
477 if (
debug & DEBUG_L1OIP_MSG)
482 if (len < 1 + 1 + 2) {
484 "4 bytes\n", __func__, len);
491 __func__, buf[0]>>6);
496 if (((*buf) & 0x20) && !hc->
pri) {
498 "on S0 interface\n", __func__);
501 if (!((*buf) & 0x20) && hc->
pri) {
503 "on E1 interface\n", __func__);
508 packet_id = (*buf >> 4) & 1;
511 remotecodec = (*buf) & 0x0f;
512 if (remotecodec > 3) {
514 "unsupported\n", __func__, remotecodec);
524 "0x%x, but we have not\n", __func__, packet_id);
529 "short for ID value\n", __func__);
532 packet_id = (*buf++) << 24;
533 packet_id += (*buf++) << 16;
534 packet_id += (*buf++) << 8;
535 packet_id += (*buf++);
538 if (packet_id != hc->
id) {
540 "got 0x%x, we 0x%x\n",
541 __func__, packet_id, hc->
id);
547 "ID, but we have\n", __func__);
555 "channel expected at position %d.\n",
556 __func__, len-len_start + 1);
561 channel = *buf & 0x7f;
570 "short, length expected at position %d.\n",
571 __func__, len_start - len - 1);
579 if (len < mlen + 3) {
581 "position %d exceeds total length %d.\n",
582 __func__, mlen, len_start-len - 1, len_start);
585 if (len == mlen + 3) {
587 "position %d will not allow additional "
589 __func__, mlen, len_start-len + 1);
597 "base expected at position %d.\n",
598 __func__, len-len_start + 1);
603 timebase = (*buf++) << 8;
604 timebase |= (*buf++);
611 "received packet\n", __func__);
618 l1oip_socket_recv(hc, remotecodec, channel, timebase, buf, mlen);
640 "0x%08x to 0x%08x (port %d to %d)\n", __func__,
655 l1oip_socket_thread(
void *
data)
661 unsigned char *recvbuf;
662 size_t recvbuf_size = 1500;
664 struct socket *socket =
NULL;
712 msg.msg_name = &sin_rx;
713 msg.msg_namelen =
sizeof(sin_rx);
715 msg.msg_controllen = 0;
721 hc->
sendmsg.msg_controllen = 0;
729 if (
debug & DEBUG_L1OIP_SOCKET)
732 while (!signal_pending(
current)) {
735 .iov_len = recvbuf_size,
740 l1oip_socket_parse(hc, &sin_rx, recvbuf, recvlen);
742 if (
debug & DEBUG_L1OIP_SOCKET)
744 "%s: broken pipe on socket\n", __func__);
759 if (
debug & DEBUG_L1OIP_SOCKET)
775 if (
debug & DEBUG_L1OIP_SOCKET)
782 l1oip_socket_close(
struct l1oip *hc)
788 if (
debug & DEBUG_L1OIP_SOCKET)
790 "killing...\n", __func__);
797 if (
debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
799 "due to timeout\n", __func__);
807 l1oip_socket_open(
struct l1oip *hc)
810 l1oip_socket_close(hc);
825 if (
debug & DEBUG_L1OIP_SOCKET)
837 if (
debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
839 "frame on dchannel\n", __func__);
842 l1oip_socket_send(hc, 0, hc->
d_idx, 0, 0,
NULL, 0);
850 l1oip_keepalive(
void *data)
858 l1oip_timeout(
void *data)
863 if (
debug & DEBUG_L1OIP_MSG)
865 "down.\n", __func__);
871 if (
debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
873 "due to timeout\n", __func__);
881 if (
debug & DEBUG_L1OIP_MSG)
883 "be removed\n", __func__);
893 handle_dmsg(
struct mISDNchannel *ch,
struct sk_buff *
skb)
920 l1oip_socket_send(hc, 0, dch->
slot, 0,
921 hc->
chan[dch->
slot].tx_counter++, p, ll);
929 if (
debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
939 if (
debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
941 "(1..%d)\n", __func__, dch->
slot,
972 if (
debug & DEBUG_L1OIP_SOCKET)
974 "space.\n", __func__);
975 l1oip_socket_open(hc);
978 if (
debug & DEBUG_L1OIP_SOCKET)
982 l1oip_socket_open(hc);
985 if (
debug & DEBUG_L1OIP_SOCKET)
1001 open_dchannel(
struct l1oip *hc,
struct dchannel *dch,
struct channel_req *
rq)
1005 dch->
dev.id, __builtin_return_address(0));
1009 (dch->
dev.D.protocol != rq->protocol)) {
1010 if (
debug & DEBUG_HW_OPEN)
1012 __func__, dch->
dev.D.protocol, rq->protocol);
1014 if (dch->
dev.D.protocol != rq->protocol)
1015 dch->
dev.D.protocol = rq->protocol;
1021 rq->ch = &dch->
dev.D;
1028 open_bchannel(
struct l1oip *hc,
struct dchannel *dch,
struct channel_req *rq)
1033 if (!test_channelmap(rq->adr.channel, dch->
dev.channelmap))
1037 ch = rq->adr.channel;
1046 bch->
ch.protocol = rq->protocol;
1054 l1oip_dctrl(
struct mISDNchannel *ch,
u_int cmd,
void *
arg)
1056 struct mISDNdevice *dev =
container_of(ch,
struct mISDNdevice,
D);
1059 struct channel_req *
rq;
1064 __func__, cmd, arg);
1068 switch (rq->protocol) {
1075 err = open_dchannel(hc, dch, rq);
1083 err = open_dchannel(hc, dch, rq);
1086 err = open_bchannel(hc, dch, rq);
1090 if (
debug & DEBUG_HW_OPEN)
1092 __func__, dch->
dev.id,
1093 __builtin_return_address(0));
1097 err = channel_dctrl(dch, arg);
1109 handle_bmsg(
struct mISDNchannel *ch,
struct sk_buff *skb)
1114 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1120 if (skb->
len <= 0) {
1133 if (
debug & DEBUG_L1OIP_MSG)
1135 "but counting\n", __func__);
1144 if (
debug & DEBUG_L1OIP_MSG)
1146 ", but counting\n", __func__);
1158 l1oip_socket_send(hc, hc->
codec, bch->
slot, 0,
1159 hc->
chan[bch->
slot].tx_counter, p, ll);
1160 hc->
chan[bch->
slot].tx_counter += ll;
1168 if (
debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
1171 hc->
chan[bch->
slot].codecstate = 0;
1177 if (
debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
1179 "(1..%d)\n", __func__, bch->
slot,
1203 if (
debug & DEBUG_L1OIP_MSG)
1220 l1oip_bctrl(
struct mISDNchannel *ch,
u_int cmd,
void *arg)
1227 __func__, cmd, arg);
1238 err = channel_bctrl(bch, arg);
1252 release_card(
struct l1oip *hc)
1256 if (timer_pending(&hc->
keep_tl))
1265 l1oip_socket_close(hc);
1269 for (ch = 0; ch < 128; ch++) {
1270 if (hc->
chan[ch].dch) {
1274 if (hc->
chan[ch].bch) {
1277 #ifdef REORDER_DEBUG
1278 if (hc->
chan[ch].disorder_skb)
1279 dev_kfree_skb(hc->
chan[ch].disorder_skb);
1284 spin_lock(&l1oip_lock);
1286 spin_unlock(&l1oip_lock);
1315 hc->idx = l1oip_cnt;
1317 hc->d_idx = pri ? 16 : 3;
1318 hc->b_num = pri ? 30 : 2;
1319 hc->bundle = bundle;
1321 sprintf(hc->name,
"l1oip-e1.%d", l1oip_cnt + 1);
1323 sprintf(hc->name,
"l1oip-s0.%d", l1oip_cnt + 1);
1325 switch (
codec[l1oip_cnt]) {
1336 hc->codec =
codec[l1oip_cnt];
1339 __func__, hc->codec);
1341 if (
id[l1oip_cnt] == 0) {
1343 "0, this is highly unsecure. Please use 32 "
1344 "bit randmom number 0x...\n");
1346 hc->id =
id[l1oip_cnt];
1347 if (
debug & DEBUG_L1OIP_INIT)
1350 hc->ondemand = ondemand[l1oip_cnt];
1351 if (hc->ondemand && !hc->id) {
1353 "conjunction with non 0 ID\n", __func__);
1357 if (
limit[l1oip_cnt])
1358 hc->b_num =
limit[l1oip_cnt];
1359 if (!pri && hc->b_num > 2) {
1364 if (pri && hc->b_num > 126) {
1369 if (pri && hc->b_num > 30) {
1373 "supported by application.\n", hc->limit);
1376 hc->remoteip =
ip[l1oip_cnt << 2] << 24
1377 |
ip[(l1oip_cnt << 2) + 1] << 16
1378 |
ip[(l1oip_cnt << 2) + 2] << 8
1379 |
ip[(l1oip_cnt << 2) + 3];
1381 if (remoteport[l1oip_cnt])
1382 hc->remoteport = remoteport[l1oip_cnt];
1384 hc->remoteport = hc->localport;
1385 if (
debug & DEBUG_L1OIP_INIT)
1387 "%d.%d.%d.%d port %d ondemand %d\n", __func__,
1388 hc->localport, hc->remoteip >> 24,
1389 (hc->remoteip >> 16) & 0xff,
1390 (hc->remoteip >> 8) & 0xff, hc->remoteip & 0xff,
1391 hc->remoteport, hc->ondemand);
1405 dch->
dev.D.send = handle_dmsg;
1406 dch->
dev.D.ctrl = l1oip_dctrl;
1407 dch->
dev.nrbchan = hc->b_num;
1408 dch->
slot = hc->d_idx;
1409 hc->chan[hc->d_idx].dch = dch;
1411 for (ch = 0; ch < dch->
dev.nrbchan; ch++) {
1425 bch->
ch.send = handle_bmsg;
1426 bch->
ch.ctrl = l1oip_bctrl;
1427 bch->
ch.nr = i +
ch;
1428 list_add(&bch->
ch.list, &dch->
dev.bchannels);
1429 hc->chan[i +
ch].bch = bch;
1430 set_channelmap(bch->
nr, dch->
dev.channelmap);
1438 if (
debug & DEBUG_L1OIP_INIT)
1440 __func__, l1oip_cnt + 1);
1441 ret = l1oip_socket_open(hc);
1445 hc->keep_tl.function = (
void *)l1oip_keepalive;
1446 hc->keep_tl.data = (
ulong)hc;
1451 hc->timeout_tl.function = (
void *)l1oip_timeout;
1452 hc->timeout_tl.data = (
ulong)hc;
1469 INIT_LIST_HEAD(&l1oip_ilist);
1477 switch (
type[l1oip_cnt] & 0xff) {
1496 type[l1oip_cnt] & 0xff);
1501 if (
debug & DEBUG_L1OIP_INIT)
1503 __func__, l1oip_cnt, pri ?
"PRI" :
"BRI",
1504 bundle ?
"bundled IP packet for all B-channels" :
1505 "separate IP packets for every B-channel");
1515 spin_lock(&l1oip_lock);
1517 spin_unlock(&l1oip_lock);
1519 ret = init_card(hc, pri, bundle);