-/*
- * bchannel handling
- */
-
-/* select free bchannel from loopback interface */
-int Psip::hunt_bchannel(void)
-{
- return loop_hunt_bchannel(this, p_m_mISDNport);
-}
-
-/* close SIP side bchannel */
-void Psip::bchannel_close(void)
-{
- if (p_m_s_b_sock > -1) {
- unregister_fd(&p_m_s_b_fd);
- close(p_m_s_b_sock);
- }
- p_m_s_b_sock = -1;
- p_m_s_b_index = -1;
- p_m_s_b_active = 0;
-}
-
-static int b_handler(struct lcr_fd *fd, unsigned int what, void *instance, int index);
-
-/* open external side bchannel */
-int Psip::bchannel_open(int index)
-{
- int ret;
- struct sockaddr_mISDN addr;
- struct mISDNhead act;
-
- if (p_m_s_b_sock > -1) {
- PERROR("Socket already created for index %d\n", index);
- return(-EIO);
- }
-
- /* open socket */
- ret = p_m_s_b_sock = socket(PF_ISDN, SOCK_DGRAM, ISDN_P_B_RAW);
- if (ret < 0) {
- PERROR("Failed to open bchannel-socket for index %d\n", index);
- bchannel_close();
- return(ret);
- }
- memset(&p_m_s_b_fd, 0, sizeof(p_m_s_b_fd));
- p_m_s_b_fd.fd = p_m_s_b_sock;
- register_fd(&p_m_s_b_fd, LCR_FD_READ, b_handler, this, 0);
-
-
- /* bind socket to bchannel */
- addr.family = AF_ISDN;
- addr.dev = mISDNloop.port;
- addr.channel = index+1+(index>15);
- ret = bind(p_m_s_b_sock, (struct sockaddr *)&addr, sizeof(addr));
- if (ret < 0) {
- PERROR("Failed to bind bchannel-socket for index %d\n", index);
- bchannel_close();
- return(ret);
- }
- /* activate bchannel */
- PDEBUG(DEBUG_SIP, "Activating SIP side channel index %i.\n", index);
- act.prim = PH_ACTIVATE_REQ;
- act.id = 0;
- ret = sendto(p_m_s_b_sock, &act, MISDN_HEADER_LEN, 0, NULL, 0);
- if (ret < 0) {
- PERROR("Failed to activate index %d\n", index);
- bchannel_close();
- return(ret);
- }
-
- p_m_s_b_index = index;
-
- return(0);
-}
-
-/* receive from bchannel */
-void Psip::bchannel_receive(struct mISDNhead *hh, unsigned char *data, int len)