+/*
+ * message received from LCR
+ */
+int receive_message(int message_type, unsigned long ref, union parameter *param)
+{
+ union parameter newparam;
+
+ memset(&newparam, 0, sizeof(union parameter));
+
+ /* handle bchannel message*/
+ if (message_type == MESSAGE_BCHANNEL)
+ {
+ switch(param.bchannel.type)
+ {
+ case BCHANNEL_ASSIGN:
+ if (find_channel_addr(param->bchannel.addr))
+ {
+ fprintf(stderr, "error: bchannel addr %x already assigned.\n", param->bchannel.addr);
+ return(-1);
+ }
+ /* create channel */
+ channel = alloc_channel();
+ channel.addr = param->bchannel.addr;
+ /* in case, ref is not set, this channel instance must
+ * be created until it is removed again by LCR */
+ channel.ref = param->bchannel.ref;
+ /* link to call */
+ if ((call = find_call_ref(param->bchannel.ref)))
+ {
+ call.addr = param->bchannel.addr;
+ }
+
+#warning open stack
+ /* acknowledge */
+ newparam.bchannel.type = BCHANNEL_ASSIGN_ACK;
+ newparam.bchannel.addr = param->bchannel.addr;
+ send_message(MESSAGE_BCHANNEL, 0, &newparam);
+ break;
+
+ case BCHANNEL_REMOVE:
+ if (!(channel = find_channel_addr(param->bchannel.addr)))
+ {
+ fprintf(stderr, "error: bchannel addr %x already assigned.\n", param->bchannel.addr);
+ return(-1);
+ }
+ /* unlink from call */
+ if ((call = find_call_ref(channel->ref)))
+ {
+ call.addr = 0;
+ }
+ /* remove channel */
+ free_channel(channel);
+#warning close stack
+ /* acknowledge */
+ newparam.bchannel.type = BCHANNEL_REMOVE_ACK;
+ newparam.bchannel.addr = param->bchannel.addr;
+ send_message(MESSAGE_BCHANNEL, 0, &newparam);
+
+ break;
+
+ default:
+ fprintf(stderr, "received unknown bchannel message %d\n", param.bchannel.type);
+ }
+ return(0);
+ }
+ switch(message_type)
+ return(0);
+}
+