- p_capainfo.exthlc = INFO_HLC_NONE;
- break;
- default:
- p_capainfo.exthlc = exthlc + 0x80;
- break;
- }
-
- /* channel_id */
- dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)((unsigned long)data+headerlen), &exclusive, &channel);
- if (exclusive<0)
- exclusive = 0;
- if (channel==CHANNEL_NO && p_type==PORT_TYPE_DSS1_TE_IN)
- PDEBUG(DEBUG_BCHANNEL, "- no channel is given by the network, causing to fail, since CW is not possible for external lines\n");
- if (channel <= 0) /* not given, no channel, whatever.. */
- channel = CHANNEL_ANY; /* any channel */
- if (p_m_mISDNport->b_reserved >= p_m_mISDNport->b_num) // of out chan..
- {
- printlog("--- port#%d all channels are used/reserved.\n", ifport->portnum);
- ret = -34; // no channel
- goto no_channel;
- }
- if (channel == CHANNE_ANY)
- {
- PDEBUG(DEBUG_BCHANNEL, "- any channel is assumed from the %s, so we need to return the a channel from our list\n", (p_m_d_ntmode)?"user":"network");
- /* check for any channel form selection list */
- channel = 0;
- selchannel = ifport->channel_in;
- while(selchannel)
- {
- switch(selchannel->channel)
- {
- case CHANNEL_FREE: /* free channel */
- if (mISDNport->b_inuse >= mISDNport->b_num)
- break; /* all channel in use or reserverd */
- /* find channel */
- i = 0;
- while(i < mISDNport->b_num)
- {
- if (mISDNport->b_port[i] == NULL)
- {
- channel = i+1+(i>=15);
- printlog("--- port#%d no channel given, so selecting free channel %d\n", ifport->portnum, channel);
- break;
- }
- i++;
- }
- break;
-
- default:
- if (selchannel->channel<1 || selchannel->channel==16)
- break; /* invalid channels */
- i = selchannel->channel-1-(selchannel->channel>=17);
- if (i >= mISDNport->b_num)
- break; /* channel not in port */
- if (mISDNport->b_port[i] == NULL)
- {
- channel = selchannel->channel;
- printlog("--- port#%d no channel given, so selecting channel %d from list\n", ifport->portnum, channel);
- break;
- }
- break;
- }
- if (channel)
- break; /* found channel */
- selchannel = selchannel->next;
- }
- if (!channel)
- {
- printlog("--- port#%d no channel found.\n", ifport->portnum);
- ret = -34; // no channel
- goto no_channel;
- }
- goto use_channel;
- }
- if (channel > 0)
- {
- /* check for given channel in selection list */
- selchannel = ifport->channel_in;
- while(selchannel)
- {
- if (selchannel->channel == channel || selchannel->channel == CHANNEL_FREE)
- break;
- selchannel = selchannel->next;
- }
- if (!selchannel)
- channel = 0;
-
- /* exclusive channel requests must be in the list */
- if (exclusive)
- {
- if (!channel)
- {
- PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, but not in list of incomming channel.\n", channel);
- printlog("--- port#%d channel %d given exclusively, it is accepted.\n", ifport->portnum, channel);
- ret = 6; // unacceptable
- goto no_channel;
- }
- PDEBUG(DEBUG_BCHANNEL, "- exclusive channel %d is selected, as in list of incomming channels.\n", channel);
- i = selchannel->channel-1-(selchannel->channel>=17);
- if (mISDNport->b_port[i] == NULL)
- {
- printlog("--- port#%d channel %d given exclusively, it is accepted and free.\n", ifport->portnum, channel);
- goto use_channel;
- }
- printlog("--- port#%d channel %d given exclusively, it is accepted, but busy.\n", ifport->portnum, channel);
- ret = 6; // unacceptable
- goto no_channel;
- }
-
- /* requested channels in list will be used */
- if (channel)
- {
- PDEBUG(DEBUG_BCHANNEL, "- channel %d given, found in list.\n", channel);
- i = selchannel->channel-1-(selchannel->channel>=17);
- if (mISDNport->b_port[i] == NULL)
- {
- printlog("--- port#%d channel %d given, it is accepted and free.\n", ifport->portnum, channel);
- goto use_channel;
- }
- }
-
- /* if channel is not available or not in list, it must be searched */
- PDEBUG(DEBUG_BCHANNEL, "- channel %d given, but not in list of incomming channels.\n", channel);
-
- /* check for first free channel in list */
- channel = 0;
- selchannel = ifport->channel_in;
- while(selchannel)
- {
- switch(selchannel->channel)
- {
- case CHANNEL_FREE: /* free channel */
- if (mISDNport->b_inuse >= mISDNport->b_num)
- break; /* all channel in use or reserverd */
- /* find channel */
- i = 0;
- while(i < mISDNport->b_num)
- {
- if (mISDNport->b_port[i] == NULL)
- {
- channel = i+1+(i>=15);
- printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
- break;
- }
- i++;
- }
- break;
-
- default:
- if (selchannel->channel<1 || selchannel->channel==16)
- break; /* invalid channels */
- i = selchannel->channel-1-(selchannel->channel>=17);
- if (i >= mISDNport->b_num)
- break; /* channel not in port */
- if (mISDNport->b_port[i] == NULL)
- {
- channel = selchannel->channel;
- printlog("--- port#%d requested channel was not in list, so using free channel %d from list.\n", ifport->portnum, channel);
- break;
- }
- break;
- }
- if (channel)
- break; /* found channel */
- selchannel = selchannel->next;
- }
- if (!channel)
- {
- printlog("--- port#%d no channel found.\n", ifport->portnum);
- ret = 6; // unacceptable
- goto no_channel;
- }