aboutsummaryrefslogtreecommitdiffstats
path: root/channels/misdn/isdn_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'channels/misdn/isdn_lib.c')
-rw-r--r--channels/misdn/isdn_lib.c82
1 files changed, 53 insertions, 29 deletions
diff --git a/channels/misdn/isdn_lib.c b/channels/misdn/isdn_lib.c
index 13e6a8207..3f33176a3 100644
--- a/channels/misdn/isdn_lib.c
+++ b/channels/misdn/isdn_lib.c
@@ -431,7 +431,7 @@ static void dump_chan_list(struct misdn_stack *stack)
-static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel)
+static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchannel *bc, int channel, int dec)
{
int i;
@@ -443,14 +443,25 @@ static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchan
}
channel--;
-
- for (i = 0; i < stack->b_num; i++) {
- if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
- if (!stack->channels[i]) {
- cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
- bc->channel=i+1;
- cb_event(EVENT_NEW_CHANNEL, bc, NULL);
- return i+1;
+
+ if (dec) {
+ for (i = stack->b_num-1; i >=0; i--) {
+ if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
+ if (!stack->channels[i]) {
+ cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
+ bc->channel=i+1;
+ return i+1;
+ }
+ }
+ }
+ } else {
+ for (i = 0; i < stack->b_num; i++) {
+ if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
+ if (!stack->channels[i]) {
+ cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
+ bc->channel=i+1;
+ return i+1;
+ }
}
}
}
@@ -541,6 +552,7 @@ static void empty_bc(struct misdn_bchannel *bc)
bc->in_use= 0;
bc->cw= 0;
+ bc->dec=0;
bc->channel = 0;
bc->sending_complete = 0;
@@ -689,7 +701,7 @@ static int set_chan_in_stack(struct misdn_stack *stack, int channel)
if (!stack->channels[channel-1])
stack->channels[channel-1] = 1;
else {
- cb_log(0,stack->port,"channel already in use:%d\n", channel );
+ cb_log(4,stack->port,"channel already in use:%d\n", channel );
return -1;
}
} else {
@@ -837,7 +849,7 @@ static int create_process (int midev, struct misdn_bchannel *bc) {
struct misdn_stack *stack=get_stack_by_bc(bc);
if (stack->nt) {
- if (!find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0))
+ if (!find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, 0))
return -1;
/*bc->channel=free_chan;*/
@@ -869,10 +881,11 @@ static int create_process (int midev, struct misdn_bchannel *bc) {
} else {
if (stack->ptp || bc->te_choose_channel) {
/* we know exactly which channels are in use */
- if (!find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0))
+ if (!find_free_chan_in_stack(stack, bc, bc->channel_preselected ? bc->channel : 0, 0))
return -1;
/*bc->channel=free_chan;*/
cb_log(2,stack->port, " --> found channel: %d\n", bc->channel);
+
if (set_chan_in_stack(stack ,bc->channel)<0) return -1;
} else {
/* other phones could have made a call also on this port (ptmp) */
@@ -1508,7 +1521,7 @@ static int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_
case EVENT_SETUP:
{
if (bc->channel == 0xff) {
- if (!find_free_chan_in_stack(stack, bc, 0)) {
+ if (!find_free_chan_in_stack(stack, bc, 0, 0)) {
cb_log(0, stack->port, "Any Channel Requested, but we have no more!!\n");
bc->out_cause=34;
misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
@@ -1557,7 +1570,7 @@ static int handle_cr ( struct misdn_stack *stack, iframe_t *frm)
case CC_NEW_CR|INDICATION:
cb_log(7, stack->port, " --> lib: NEW_CR Ind with l3id:%x on this port.\n",frm->dinfo);
- struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1);
+ struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0);
if (!bc) {
cb_log(0, stack->port, " --> !! lib: No free channel!\n");
return -1;
@@ -1795,7 +1808,7 @@ handle_event_nt(void *dat, void *arg)
case CC_SETUP|INDICATION:
{
- struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1);
+ struct misdn_bchannel* bc=misdn_lib_get_free_bc(stack->port, 0, 1, 0);
if (!bc)
ERR_NO_CHANNEL:
{
@@ -2039,8 +2052,7 @@ handle_event_nt(void *dat, void *arg)
switch (event) {
case EVENT_SETUP:
if (bc->channel<=0 || bc->channel==0xff) {
- bc->channel=find_free_chan_in_stack(stack,bc, 0);
-
+ bc->channel=find_free_chan_in_stack(stack,bc, 0,0);
if (bc->channel<=0)
goto ERR_NO_CHANNEL;
} else if (!stack->ptp)
@@ -3057,7 +3069,7 @@ static void prepare_bc(struct misdn_bchannel*bc, int channel)
#endif
}
-struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout)
+struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout, int dec)
{
struct misdn_stack *stack;
int i;
@@ -3090,17 +3102,29 @@ struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout)
}
int maxnum=inout&&!stack->pri&&!stack->ptp?stack->b_num+1:stack->b_num;
- //int maxnum=stack->b_num+1;
- cb_log(0,0,"maxnum:%d",maxnum);
- for (i = 0; i <maxnum; i++) {
- if (!stack->bc[i].in_use) {
- /* 3. channel on bri means CW*/
- if (!stack->pri && i==stack->b_num)
- stack->bc[i].cw=1;
-
- prepare_bc(&stack->bc[i], channel);
- return &stack->bc[i];
+ if (dec) {
+ for (i = maxnum-1; i>=0; i--) {
+ if (!stack->bc[i].in_use) {
+ /* 3. channel on bri means CW*/
+ if (!stack->pri && i==stack->b_num)
+ stack->bc[i].cw=1;
+
+ prepare_bc(&stack->bc[i], channel);
+ stack->bc[i].dec=1;
+ return &stack->bc[i];
+ }
+ }
+ } else {
+ for (i = 0; i <maxnum; i++) {
+ if (!stack->bc[i].in_use) {
+ /* 3. channel on bri means CW*/
+ if (!stack->pri && i==stack->b_num)
+ stack->bc[i].cw=1;
+
+ prepare_bc(&stack->bc[i], channel);
+ return &stack->bc[i];
+ }
}
}
@@ -3222,7 +3246,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
if (stack->nt) {
if (bc->channel <=0 ) { /* else we have the channel already */
- if (!find_free_chan_in_stack(stack, bc, 0)) {
+ if (!find_free_chan_in_stack(stack, bc, 0,0)) {
cb_log(0, stack->port, " No free channel at the moment\n");
/*FIXME: add disconnect*/
err=-ENOCHAN;