+}
+
+
+/*
+ * subfunction for bchannel_event
+ * activate / deactivate request
+ */
+static void _bchannel_activate(struct mISDNport *mISDNport, int i, int activate)
+{
+#ifdef SOCKET_MISDN
+ struct mISDNhead act;
+ int ret;
+
+ act.prim = (activate)?DL_ESTABLISH_REQ:DL_RELEASE_REQ;
+ act.id = 0;
+ ret = sendto(mISDNport->b_socket[i], &act, MISDN_HEADER_LEN, 0, NULL, 0);
+ if (!ret)
+ PERROR("Failed to send to socket %d\n", mISDNport->b_socket[i]);
+#else
+ iframe_t act;
+
+ /* activate bchannel */
+ act.prim = (activate?DL_ESTABLISH:DL_RELEASE) | REQUEST;
+ act.addr = mISDNport->b_addr[i] | FLG_MSG_DOWN;
+ act.dinfo = 0;
+ act.len = 0;
+ mISDN_write(mISDNdevice, &act, mISDN_HEADER_LEN+act.len, TIMEOUT_1SEC);
+#endif
+
+ /* trace */
+ chan_trace_header(mISDNport, mISDNport->b_port[i], activate?(char*)"BCHANNEL activate":(char*)"BCHANNEL deactivate", DIRECTION_OUT);
+ add_trace("channel", NULL, "%d", i+1+(i>=15));
+ if (mISDNport->b_timer[i])
+ add_trace("event", NULL, "timeout recovery");
+ end_trace();
+}
+
+
+/*
+ * subfunction for bchannel_event
+ * set features
+ */
+static void _bchannel_configure(struct mISDNport *mISDNport, int i)
+{
+ struct PmISDN *port;
+#ifdef SOCKET_MISDN
+ int handle;
+
+ handle = mISDNport->b_socket[i];
+ port = mISDNport->b_port[i];
+ if (!port)
+ {
+ PERROR("bchannel index i=%d not associated with a port object\n", i);
+ return;
+ }
+
+ /* set dsp features */
+ if (port->p_m_txdata)
+ ph_control(mISDNport, port, handle, (port->p_m_txdata)?DSP_TXDATA_ON:DSP_TXDATA_OFF, 0, "DSP-TXDATA", port->p_m_txdata);
+ if (port->p_m_delay)
+ ph_control(mISDNport, port, handle, DSP_DELAY, port->p_m_delay, "DSP-DELAY", port->p_m_delay);
+ if (port->p_m_tx_gain)
+ ph_control(mISDNport, port, handle, DSP_VOL_CHANGE_TX, port->p_m_tx_gain, "DSP-TX_GAIN", port->p_m_tx_gain);
+ if (port->p_m_rx_gain)
+ ph_control(mISDNport, port, handle, DSP_VOL_CHANGE_RX, port->p_m_rx_gain, "DSP-RX_GAIN", port->p_m_rx_gain);
+ if (port->p_m_pipeline[0])
+ ph_control_block(mISDNport, port, handle, DSP_PIPELINE_CFG, port->p_m_pipeline, strlen(port->p_m_pipeline)+1, "DSP-PIPELINE", 0);
+ if (port->p_m_conf)
+ ph_control(mISDNport, port, handle, DSP_CONF_JOIN, port->p_m_conf, "DSP-CONF", port->p_m_conf);
+ if (port->p_m_echo)
+ ph_control(mISDNport, port, handle, DSP_ECHO_ON, 0, "DSP-ECHO", 1);
+ if (port->p_m_tone)
+ ph_control(mISDNport, port, handle, DSP_TONE_PATT_ON, port->p_m_tone, "DSP-TONE", port->p_m_tone);
+ if (port->p_m_rxoff)
+ ph_control(mISDNport, port, handle, DSP_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
+// if (port->p_m_txmix)
+// ph_control(mISDNport, port, handle, DSP_MIX_ON, 0, "DSP-MIX", 1);
+ if (port->p_m_dtmf)
+ ph_control(mISDNport, port, handle, DTMF_TONE_START, 0, "DSP-DTMF", 1);
+ if (port->p_m_crypt)
+ ph_control_block(mISDNport, port, handle, DSP_BF_ENABLE_KEY, port->p_m_crypt_key, port->p_m_crypt_key_len, "DSP-CRYPT", port->p_m_crypt_key_len);
+#else
+ unsigned long handle;
+
+ handle = mISDNport->b_addr[i];
+ port = mISDNport->b_port[i];
+ if (!port)
+ {
+ PERROR("bchannel index i=%d not associated with a port object\n", i);
+ return;
+ }
+
+ /* set dsp features */
+#ifndef OLD_MISDN
+ if (port->p_m_txdata)
+ ph_control(mISDNport, port, handle, (port->p_m_txdata)?CMX_TXDATA_ON:CMX_TXDATA_OFF, 0, "DSP-TXDATA", port->p_m_txdata);
+ if (port->p_m_delay)
+ ph_control(mISDNport, port, handle, CMX_DELAY, port->p_m_delay, "DSP-DELAY", port->p_m_delay);
+#endif
+ if (port->p_m_tx_gain)
+ ph_control(mISDNport, port, handle, VOL_CHANGE_TX, port->p_m_tx_gain, "DSP-TX_GAIN", port->p_m_tx_gain);
+ if (port->p_m_rx_gain)
+ ph_control(mISDNport, port, handle, VOL_CHANGE_RX, port->p_m_rx_gain, "DSP-RX_GAIN", port->p_m_rx_gain);
+#ifndef OLD_MISDN
+ if (port->p_m_pipeline[0])
+ ph_control_block(mISDNport, port, handle, PIPELINE_CFG, port->p_m_pipeline, strlen(port->p_m_pipeline)+1, "DSP-PIPELINE", 0);
+#endif
+ if (port->p_m_conf)
+ ph_control(mISDNport, port, handle, CMX_CONF_JOIN, port->p_m_conf, "DSP-CONF", port->p_m_conf);
+ if (port->p_m_echo)
+ ph_control(mISDNport, port, handle, CMX_ECHO_ON, 0, "DSP-ECHO", 1);
+ if (port->p_m_tone)
+ ph_control(mISDNport, port, handle, TONE_PATT_ON, port->p_m_tone, "DSP-TONE", port->p_m_tone);
+ if (port->p_m_rxoff)
+ ph_control(mISDNport, port, handle, CMX_RECEIVE_OFF, 0, "DSP-RXOFF", 1);
+// if (port->p_m_txmix)
+// ph_control(mISDNport, port, handle, CMX_MIX_ON, 0, "DSP-MIX", 1);
+ if (port->p_m_dtmf)
+ ph_control(mISDNport, port, handle, DTMF_TONE_START, 0, "DSP-DTMF", 1);
+ if (port->p_m_crypt)
+ ph_control_block(mISDNport, port, handle, BF_ENABLE_KEY, port->p_m_crypt_key, port->p_m_crypt_key_len, "DSP-CRYPT", port->p_m_crypt_key_len);
+#endif
+}
+
+/*
+ * subfunction for bchannel_event
+ * destroy stack
+ */
+static void _bchannel_destroy(struct mISDNport *mISDNport, int i)
+{
+#ifdef SOCKET_MISDN
+ chan_trace_header(mISDNport, mISDNport->b_port[i], "BCHANNEL remove socket", DIRECTION_OUT);
+ add_trace("channel", NULL, "%d", i+1+(i>=15));
+ add_trace("socket", NULL, "%d", mISDNport->b_socket[i]);
+ end_trace();
+ if (mISDNport->b_socket[i] > -1)
+ {
+ close(mISDNport->b_socket[i]);
+ mISDNport->b_socket[i] = -1;
+ }
+#else
+ unsigned char buff[1024];
+
+ chan_trace_header(mISDNport, mISDNport->b_port[i], "BCHANNEL remove stack", DIRECTION_OUT);
+ add_trace("channel", NULL, "%d", i+1+(i>=15));
+ add_trace("stack", "id", "0x%08x", mISDNport->b_stid[i]);
+ add_trace("stack", "address", "0x%08x", mISDNport->b_addr[i]);
+ end_trace();
+ /* remove our stack only if set */
+ if (mISDNport->b_addr[i])
+ {
+ PDEBUG(DEBUG_BCHANNEL, "free stack (b_addr=0x%x)\n", mISDNport->b_addr[i]);
+ mISDN_clear_stack(mISDNdevice, mISDNport->b_stid[i]);
+ mISDN_write_frame(mISDNdevice, buff, mISDNport->b_addr[i] | FLG_MSG_DOWN, MGR_DELLAYER | REQUEST, 0, 0, NULL, TIMEOUT_1SEC);
+ mISDNport->b_addr[i] = 0;