Lines Matching refs:hc
278 l1oip_socket_send(struct l1oip *hc, u8 localcodec, u8 channel, u32 chanmask, in l1oip_socket_send() argument
292 if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ)) in l1oip_socket_send()
293 mod_timer(&hc->keep_tl, jiffies + L1OIP_KEEPALIVE * HZ); in l1oip_socket_send()
295 hc->keep_tl.expires = jiffies + L1OIP_KEEPALIVE * HZ; in l1oip_socket_send()
301 if (!hc->sin_remote.sin_addr.s_addr || !hc->sin_remote.sin_port) { in l1oip_socket_send()
310 | (hc->pri ? 0x20 : 0x00) /* type */ in l1oip_socket_send()
311 | (hc->id ? 0x10 : 0x00) /* id */ in l1oip_socket_send()
313 if (hc->id) { in l1oip_socket_send()
314 *p++ = hc->id >> 24; /* id */ in l1oip_socket_send()
315 *p++ = hc->id >> 16; in l1oip_socket_send()
316 *p++ = hc->id >> 8; in l1oip_socket_send()
317 *p++ = hc->id; in l1oip_socket_send()
330 &hc->chan[channel].codecstate); in l1oip_socket_send()
337 spin_lock(&hc->socket_lock); in l1oip_socket_send()
338 if (!hc->socket) { in l1oip_socket_send()
339 spin_unlock(&hc->socket_lock); in l1oip_socket_send()
343 socket = hc->socket; in l1oip_socket_send()
344 hc->socket = NULL; in l1oip_socket_send()
345 spin_unlock(&hc->socket_lock); in l1oip_socket_send()
350 hc->sendiov.iov_base = frame; in l1oip_socket_send()
351 hc->sendiov.iov_len = len; in l1oip_socket_send()
352 len = kernel_sendmsg(socket, &hc->sendmsg, &hc->sendiov, 1, len); in l1oip_socket_send()
354 hc->socket = socket; /* no locking required */ in l1oip_socket_send()
364 l1oip_socket_recv(struct l1oip *hc, u8 remotecodec, u8 channel, u16 timebase, in l1oip_socket_recv() argument
389 dch = hc->chan[channel].dch; in l1oip_socket_recv()
390 bch = hc->chan[channel].bch; in l1oip_socket_recv()
421 rx_counter = hc->chan[channel].rx_counter; in l1oip_socket_recv()
439 hc->chan[channel].rx_counter = rx_counter; in l1oip_socket_recv()
442 if (hc->chan[channel].disorder_flag) { in l1oip_socket_recv()
443 swap(hc->chan[channel].disorder_skb, nskb); in l1oip_socket_recv()
444 swap(hc->chan[channel].disorder_cnt, rx_counter); in l1oip_socket_recv()
446 hc->chan[channel].disorder_flag ^= 1; in l1oip_socket_recv()
458 l1oip_socket_parse(struct l1oip *hc, struct sockaddr_in *sin, u8 *buf, int len) in l1oip_socket_parse() argument
466 struct dchannel *dch = hc->chan[hc->d_idx].dch; in l1oip_socket_parse()
487 if (((*buf) & 0x20) && !hc->pri) { in l1oip_socket_parse()
492 if (!((*buf) & 0x20) && hc->pri) { in l1oip_socket_parse()
513 if (!hc->id) { in l1oip_socket_parse()
529 if (packet_id != hc->id) { in l1oip_socket_parse()
532 __func__, packet_id, hc->id); in l1oip_socket_parse()
536 if (hc->id) { in l1oip_socket_parse()
609 l1oip_socket_recv(hc, remotecodec, channel, timebase, buf, mlen); in l1oip_socket_parse()
618 if (time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) || !hc->timeout_on) { in l1oip_socket_parse()
619 hc->timeout_on = 1; in l1oip_socket_parse()
620 mod_timer(&hc->timeout_tl, jiffies + L1OIP_TIMEOUT * HZ); in l1oip_socket_parse()
622 hc->timeout_tl.expires = jiffies + L1OIP_TIMEOUT * HZ; in l1oip_socket_parse()
625 if ((hc->sin_remote.sin_addr.s_addr != sin->sin_addr.s_addr) in l1oip_socket_parse()
626 || (hc->sin_remote.sin_port != sin->sin_port)) { in l1oip_socket_parse()
630 ntohl(hc->sin_remote.sin_addr.s_addr), in l1oip_socket_parse()
632 ntohs(hc->sin_remote.sin_port), in l1oip_socket_parse()
634 hc->sin_remote.sin_addr.s_addr = sin->sin_addr.s_addr; in l1oip_socket_parse()
635 hc->sin_remote.sin_port = sin->sin_port; in l1oip_socket_parse()
646 struct l1oip *hc = (struct l1oip *)data; in l1oip_socket_thread() local
680 hc->sin_local.sin_family = AF_INET; in l1oip_socket_thread()
681 hc->sin_local.sin_addr.s_addr = INADDR_ANY; in l1oip_socket_thread()
682 hc->sin_local.sin_port = htons((unsigned short)hc->localport); in l1oip_socket_thread()
685 hc->sin_remote.sin_family = AF_INET; in l1oip_socket_thread()
686 hc->sin_remote.sin_addr.s_addr = htonl(hc->remoteip); in l1oip_socket_thread()
687 hc->sin_remote.sin_port = htons((unsigned short)hc->remoteport); in l1oip_socket_thread()
690 if (socket->ops->bind(socket, (struct sockaddr *)&hc->sin_local, in l1oip_socket_thread()
691 sizeof(hc->sin_local))) { in l1oip_socket_thread()
693 __func__, hc->localport); in l1oip_socket_thread()
706 hc->sendmsg.msg_name = &hc->sin_remote; in l1oip_socket_thread()
707 hc->sendmsg.msg_namelen = sizeof(hc->sin_remote); in l1oip_socket_thread()
708 hc->sendmsg.msg_control = NULL; in l1oip_socket_thread()
709 hc->sendmsg.msg_controllen = 0; in l1oip_socket_thread()
712 spin_lock(&hc->socket_lock); in l1oip_socket_thread()
713 hc->socket = socket; in l1oip_socket_thread()
714 spin_unlock(&hc->socket_lock); in l1oip_socket_thread()
725 l1oip_socket_parse(hc, &sin_rx, recvbuf, recvlen); in l1oip_socket_thread()
734 spin_lock(&hc->socket_lock); in l1oip_socket_thread()
736 while (!hc->socket) { in l1oip_socket_thread()
737 spin_unlock(&hc->socket_lock); in l1oip_socket_thread()
739 spin_lock(&hc->socket_lock); in l1oip_socket_thread()
741 hc->socket = NULL; in l1oip_socket_thread()
742 spin_unlock(&hc->socket_lock); in l1oip_socket_thread()
757 complete(&hc->socket_complete); in l1oip_socket_thread()
758 hc->socket_thread = NULL; /* show termination of thread */ in l1oip_socket_thread()
767 l1oip_socket_close(struct l1oip *hc) in l1oip_socket_close() argument
769 struct dchannel *dch = hc->chan[hc->d_idx].dch; in l1oip_socket_close()
772 if (hc->socket_thread) { in l1oip_socket_close()
776 send_sig(SIGTERM, hc->socket_thread, 0); in l1oip_socket_close()
777 wait_for_completion(&hc->socket_complete); in l1oip_socket_close()
792 l1oip_socket_open(struct l1oip *hc) in l1oip_socket_open() argument
795 l1oip_socket_close(hc); in l1oip_socket_open()
797 init_completion(&hc->socket_complete); in l1oip_socket_open()
800 hc->socket_thread = kthread_run(l1oip_socket_thread, hc, "l1oip_%s", in l1oip_socket_open()
801 hc->name); in l1oip_socket_open()
802 if (IS_ERR(hc->socket_thread)) { in l1oip_socket_open()
803 int err = PTR_ERR(hc->socket_thread); in l1oip_socket_open()
806 hc->socket_thread = NULL; in l1oip_socket_open()
807 sock_release(hc->socket); in l1oip_socket_open()
820 struct l1oip *hc = container_of(work, struct l1oip, workq); in l1oip_send_bh() local
827 l1oip_socket_send(hc, 0, hc->d_idx, 0, 0, NULL, 0); in l1oip_send_bh()
837 struct l1oip *hc = from_timer(hc, t, keep_tl); in l1oip_keepalive() local
839 schedule_work(&hc->workq); in l1oip_keepalive()
845 struct l1oip *hc = from_timer(hc, t, in l1oip_timeout() local
847 struct dchannel *dch = hc->chan[hc->d_idx].dch; in l1oip_timeout()
853 hc->timeout_on = 0; /* state that timer must be initialized next time */ in l1oip_timeout()
866 if (hc->ondemand) { in l1oip_timeout()
870 hc->sin_remote.sin_addr.s_addr = 0; in l1oip_timeout()
883 struct l1oip *hc = dch->hw; in handle_dmsg() local
910 l1oip_socket_send(hc, 0, dch->slot, 0, in handle_dmsg()
911 hc->chan[dch->slot].tx_counter++, p, ll); in handle_dmsg()
921 , __func__, dch->slot, hc->b_num + 1); in handle_dmsg()
932 hc->b_num + 1); in handle_dmsg()
949 struct l1oip *hc = dch->hw; in channel_dctrl() local
957 hc->remoteip = (u32)cq->p1; in channel_dctrl()
958 hc->remoteport = cq->p2 & 0xffff; in channel_dctrl()
959 hc->localport = cq->p2 >> 16; in channel_dctrl()
960 if (!hc->remoteport) in channel_dctrl()
961 hc->remoteport = hc->localport; in channel_dctrl()
965 l1oip_socket_open(hc); in channel_dctrl()
971 hc->remoteip = 0; in channel_dctrl()
972 l1oip_socket_open(hc); in channel_dctrl()
978 cq->p1 = hc->remoteip; in channel_dctrl()
979 cq->p2 = hc->remoteport | (hc->localport << 16); in channel_dctrl()
991 open_dchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq) in open_dchannel() argument
1018 open_bchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq) in open_bchannel() argument
1028 bch = hc->chan[ch].bch; in open_bchannel()
1048 struct l1oip *hc = dch->hw; in l1oip_dctrl() local
1061 if (hc->pri) { in l1oip_dctrl()
1065 err = open_dchannel(hc, dch, rq); in l1oip_dctrl()
1069 if (!hc->pri) { in l1oip_dctrl()
1073 err = open_dchannel(hc, dch, rq); in l1oip_dctrl()
1076 err = open_bchannel(hc, dch, rq); in l1oip_dctrl()
1102 struct l1oip *hc = bch->hw; in handle_bmsg() local
1126 hc->chan[bch->slot].tx_counter += l; in handle_bmsg()
1137 hc->chan[bch->slot].tx_counter += l; in handle_bmsg()
1152 l1oip_socket_send(hc, hc->codec, bch->slot, 0, in handle_bmsg()
1153 hc->chan[bch->slot].tx_counter, p, ll); in handle_bmsg()
1154 hc->chan[bch->slot].tx_counter += ll; in handle_bmsg()
1164 , __func__, bch->slot, hc->b_num + 1); in handle_bmsg()
1165 hc->chan[bch->slot].codecstate = 0; in handle_bmsg()
1174 hc->b_num + 1); in handle_bmsg()
1246 release_card(struct l1oip *hc) in release_card() argument
1250 if (timer_pending(&hc->keep_tl)) in release_card()
1251 del_timer(&hc->keep_tl); in release_card()
1253 if (timer_pending(&hc->timeout_tl)) in release_card()
1254 del_timer(&hc->timeout_tl); in release_card()
1256 cancel_work_sync(&hc->workq); in release_card()
1258 if (hc->socket_thread) in release_card()
1259 l1oip_socket_close(hc); in release_card()
1261 if (hc->registered && hc->chan[hc->d_idx].dch) in release_card()
1262 mISDN_unregister_device(&hc->chan[hc->d_idx].dch->dev); in release_card()
1264 if (hc->chan[ch].dch) { in release_card()
1265 mISDN_freedchannel(hc->chan[ch].dch); in release_card()
1266 kfree(hc->chan[ch].dch); in release_card()
1268 if (hc->chan[ch].bch) { in release_card()
1269 mISDN_freebchannel(hc->chan[ch].bch); in release_card()
1270 kfree(hc->chan[ch].bch); in release_card()
1272 if (hc->chan[ch].disorder_skb) in release_card()
1273 dev_kfree_skb(hc->chan[ch].disorder_skb); in release_card()
1279 list_del(&hc->list); in release_card()
1282 kfree(hc); in release_card()
1288 struct l1oip *hc, *next; in l1oip_cleanup() local
1290 list_for_each_entry_safe(hc, next, &l1oip_ilist, list) in l1oip_cleanup()
1291 release_card(hc); in l1oip_cleanup()
1301 init_card(struct l1oip *hc, int pri, int bundle) in init_card() argument
1308 spin_lock_init(&hc->socket_lock); in init_card()
1309 hc->idx = l1oip_cnt; in init_card()
1310 hc->pri = pri; in init_card()
1311 hc->d_idx = pri ? 16 : 3; in init_card()
1312 hc->b_num = pri ? 30 : 2; in init_card()
1313 hc->bundle = bundle; in init_card()
1314 if (hc->pri) in init_card()
1315 sprintf(hc->name, "l1oip-e1.%d", l1oip_cnt + 1); in init_card()
1317 sprintf(hc->name, "l1oip-s0.%d", l1oip_cnt + 1); in init_card()
1330 hc->codec = codec[l1oip_cnt]; in init_card()
1333 __func__, hc->codec); in init_card()
1340 hc->id = id[l1oip_cnt]; in init_card()
1342 printk(KERN_DEBUG "%s: using id 0x%x\n", __func__, hc->id); in init_card()
1344 hc->ondemand = ondemand[l1oip_cnt]; in init_card()
1345 if (hc->ondemand && !hc->id) { in init_card()
1352 hc->b_num = limit[l1oip_cnt]; in init_card()
1353 if (!pri && hc->b_num > 2) { in init_card()
1358 if (pri && hc->b_num > 126) { in init_card()
1363 if (pri && hc->b_num > 30) { in init_card()
1367 "supported by application.\n", hc->limit); in init_card()
1370 hc->remoteip = ip[l1oip_cnt << 2] << 24 in init_card()
1374 hc->localport = port[l1oip_cnt]?:(L1OIP_DEFAULTPORT + l1oip_cnt); in init_card()
1376 hc->remoteport = remoteport[l1oip_cnt]; in init_card()
1378 hc->remoteport = hc->localport; in init_card()
1382 hc->localport, hc->remoteip >> 24, in init_card()
1383 (hc->remoteip >> 16) & 0xff, in init_card()
1384 (hc->remoteip >> 8) & 0xff, hc->remoteip & 0xff, in init_card()
1385 hc->remoteport, hc->ondemand); in init_card()
1392 dch->hw = hc; in init_card()
1401 dch->dev.nrbchan = hc->b_num; in init_card()
1402 dch->slot = hc->d_idx; in init_card()
1403 hc->chan[hc->d_idx].dch = dch; in init_card()
1418 bch->hw = hc; in init_card()
1423 hc->chan[i + ch].bch = bch; in init_card()
1427 ret = mISDN_register_device(&dch->dev, NULL, hc->name); in init_card()
1430 hc->registered = 1; in init_card()
1435 ret = l1oip_socket_open(hc); in init_card()
1439 timer_setup(&hc->keep_tl, l1oip_keepalive, 0); in init_card()
1440 hc->keep_tl.expires = jiffies + 2 * HZ; /* two seconds first time */ in init_card()
1441 add_timer(&hc->keep_tl); in init_card()
1443 timer_setup(&hc->timeout_tl, l1oip_timeout, 0); in init_card()
1444 hc->timeout_on = 0; /* state that we have timer off */ in init_card()
1453 struct l1oip *hc; in l1oip_init() local
1497 hc = kzalloc(sizeof(struct l1oip), GFP_ATOMIC); in l1oip_init()
1498 if (!hc) { in l1oip_init()
1503 INIT_WORK(&hc->workq, (void *)l1oip_send_bh); in l1oip_init()
1506 list_add_tail(&hc->list, &l1oip_ilist); in l1oip_init()
1509 ret = init_card(hc, pri, bundle); in l1oip_init()