-/* process bchannel export/import message from join */
-void message_bchannel_from_join(class JoinRemote *joinremote, int type, unsigned long handle)
-{
- class Endpoint *epoint;
- class Port *port;
- class PmISDN *isdnport;
- struct mISDNport *mISDNport;
- int i, ii;
-
- switch(type)
- {
- case BCHANNEL_REQUEST:
- /* find the port object for the join object ref */
- if (!(epoint = find_epoint_id(joinremote->j_epoint_id)))
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no endpoint (anymore)\n", joinremote->j_serial);
- return;
- }
- if (!epoint->ep_portlist)
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no port (anymore in portlist)\n", joinremote->j_serial);
- return;
- }
- if (epoint->ep_portlist->next)
- {
- PERROR("join %d has enpoint %d with more than one port. this shall not happen to remote joins.\n", joinremote->j_serial, epoint->ep_serial);
- }
- if (!(port = find_port_id(epoint->ep_portlist->port_id)))
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no port (anymore as object)\n", joinremote->j_serial);
- return;
- }
- if ((port->p_type&PORT_CLASS_MASK) != PORT_CLASS_mISDN)
- {
- PERROR("join %d has port %d not of mISDN type. This shall not happen.\n", joinremote->j_serial, port->p_serial);
- }
- isdnport = (class PmISDN *)port;
-
- /* assign */
- if (isdnport->p_m_remote_id)
- {
- PERROR("join %d recevied bchannel request from remote, but channel is already assinged.\n", joinremote->j_serial);
- break;
- }
- mISDNport = isdnport->p_m_mISDNport;
- i = isdnport->p_m_b_index;
- chan_trace_header(mISDNport, isdnport, "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
- add_trace("type", NULL, "export request");
- end_trace();
- isdnport->p_m_remote_ref = joinremote->j_serial;
- isdnport->p_m_remote_id = joinremote->j_remote_id;
- if (mISDNport && i>=0)
- {
- bchannel_event(mISDNport, i, B_EVENT_EXPORTREQUEST);
- }
- break;
-
- case BCHANNEL_RELEASE:
- /* find the port object for the join object ref */
- if (!(epoint = find_epoint_id(joinremote->j_epoint_id)))
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no endpoint (anymore)\n", joinremote->j_serial);
- return;
- }
- if (!epoint->ep_portlist)
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no port (anymore in portlist)\n", joinremote->j_serial);
- return;
- }
- if (epoint->ep_portlist->next)
- {
- PERROR("join %d has enpoint %d with more than one port. this shall not happen to remote joins.\n", joinremote->j_serial, epoint->ep_serial);
- }
- if (!(port = find_port_id(epoint->ep_portlist->port_id)))
- {
- PDEBUG(DEBUG_BCHANNEL, "join %d has no port (anymore as object)\n", joinremote->j_serial);
- return;
- }
- if ((port->p_type&PORT_CLASS_MASK) != PORT_CLASS_mISDN)
- {
- PERROR("join %d has port %d not of mISDN type. This shall not happen.\n", joinremote->j_serial, port->p_serial);
- }
- isdnport = (class PmISDN *)port;
-
- /* release */
- if (!isdnport->p_m_remote_id)
- {
- PERROR("join %d recevied bchannel release from remote, but channel is already released.\n", joinremote->j_serial);
- break;
- }
- mISDNport = isdnport->p_m_mISDNport;
- i = isdnport->p_m_b_index;
- chan_trace_header(mISDNport, isdnport, "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
- add_trace("type", NULL, "export request");
- end_trace();
- isdnport->p_m_remote_ref = 0;
- isdnport->p_m_remote_id = 0;
- if (mISDNport && i>=0)
- {
- bchannel_event(mISDNport, i, B_EVENT_IMPORTREQUEST);
- }
- break;
-
- case BCHANNEL_ASSIGN_ACK:
- case BCHANNEL_REMOVE_ACK:
- /* find mISDNport for stack ID */
- mISDNport = mISDNport_first;
- while(mISDNport)
- {
- i = 0;
- ii = mISDNport->b_num;
- while(i < ii)
- {
- if ((unsigned long)(mISDNport->portnum<<8)+i+1+(i>=15) == handle)
- break;
- i++;
- }
- if (i != ii)
- break;
- mISDNport = mISDNport->next;
- }
- if (!mISDNport)
- {
- PERROR("received assign/remove ack for bchannel's handle=%x, but handle does not exist in any mISDNport structure.\n", handle);
- break;
- }
- /* mISDNport may now be set or NULL */
-
- /* set */
- chan_trace_header(mISDNport, mISDNport->b_port[i], "MESSAGE_BCHANNEL (from remote application)", DIRECTION_NONE);
- add_trace("type", NULL, (type==BCHANNEL_ASSIGN_ACK)?"assign_ack":"remove_ack");
- end_trace();
- if (mISDNport && i>=0)
- bchannel_event(mISDNport, i, (type==BCHANNEL_ASSIGN_ACK)?B_EVENT_EXPORTED:B_EVENT_IMPORTED);
- break;
- default:
- PERROR("received wrong bchannel message type %d from remote\n", type);
- }
-}
-