Multiple revisions 370563,374536

........
  r370563 | rmudgett | 2012-07-30 11:47:19 -0500 (Mon, 30 Jul 2012) | 2 lines
  
  Release B channel allocation on error path in chan_misdn.
........
  r374536 | rmudgett | 2012-10-05 13:20:01 -0500 (Fri, 05 Oct 2012) | 159 lines
  
  Merged revisions 374515-374535 from
  https://origsvn.digium.com/svn/asterisk/be/branches/C.3-bier
  
  ................
    r374515 | rmudgett | 2012-10-04 17:52:36 -0500 (Thu, 04 Oct 2012) | 10 lines
  
    chan_misdn: Remove some deadcode
  
    * Made setup_bc() static.
  
    Patches:
  	patch1_unused-code.diff (license #6372) patch uploaded by Guenther Kelleter
  	Modified
  
    JIRA ABE-2882
  
  ................
    r374516 | rmudgett | 2012-10-04 18:01:01 -0500 (Thu, 04 Oct 2012) | 7 lines
  
    chan_misdn: Remove unused bchan states
  
    Patches:
  	patch2_unused-states.diff (license #6372) patch uploaded by Guenther Kelleter
  
    JIRA ABE-2882
  
  ................
    r374517 | rmudgett | 2012-10-04 18:17:51 -0500 (Thu, 04 Oct 2012) | 16 lines
  
    chan_misdn: Remove unnecessary null pointer checks and checks for stack->nt
  
    * cleanup_bc() is always called with valid bc (or it would've crashed
    before).
  
    * Value of stack->nt is known in advance at some places.
  
    * Rename handle_event() to handle_event_te(), handle_frm() to
    handle_frm_te().
  
    Patches:
  	patch3_checks.diff (license #6372) patch uploaded by Guenther Kelleter
  	Modified
  
    JIRA ABE-2882
  
  ................
    r374518 | rmudgett | 2012-10-04 18:21:59 -0500 (Thu, 04 Oct 2012) | 7 lines
  
    chan_misdn: Fix spelling in log messages
  
    Patches:
  	patch4_spelling.diff (license #6372) patch uploaded by Guenther Kelleter
  
    JIRA ABE-2882
  
  ................
    r374519 | rmudgett | 2012-10-04 18:31:59 -0500 (Thu, 04 Oct 2012) | 15 lines
  
    chan_misdn: Don't cleanup a bc twice.
  
    In handle_frm_te() after calling misdn_lib_send_event(bc,
    EVENT_RELEASE_COMPLETE) bc is emptied, cleaned and set not in use,
    although misdn_lib_send_event() already did the same.  This is bad.  When
    it's not in use we are not allowed to touch it.
  
    * Moved log message in front of the resulting actions and fixed it to
    match the case.
  
    Patches:
  	patch5_bccleanup.diff (license #6372) patch uploaded by Guenther Kelleter
  
    JIRA ABE-2882
  
  ................
    r374520 | rmudgett | 2012-10-04 18:43:56 -0500 (Thu, 04 Oct 2012) | 12 lines
  
    chan_misdn: Fix memory leaks, bc, chan not cleaned up etc., really bad stuff.
  
    * Fix return codes of cb_events() for EVENT_SETUP to use caller's cleanup
    mechanisms.
  
    * Move cl_queue_chan() call after bearer check.
  
    Patches:
  	patch6_leaks.diff (license #6372) patch uploaded by Guenther Kelleter
  
    JIRA ABE-2882
  
  ................
    r374521 | rmudgett | 2012-10-04 18:48:38 -0500 (Thu, 04 Oct 2012) | 11 lines
  
    chan_misdn: We must initialize cause on sending a DISCONNECT.
  
    We must initialize cause on sending a DISCONNECT, so it is later correctly
    indicated to ast_channel in case the answer (RELEASE/RELEASE_COMPLETE)
    does not include one.
  
    Patches:
  	patch7_hangupcause.diff (license #6372) patch uploaded by Guenther Kelleter
  
    JIRA ABE-2882
  
  ................
    r374522 | rmudgett | 2012-10-04 19:03:56 -0500 (Thu, 04 Oct 2012) | 7 lines
  
    chan_misdn: Remove unused code for upqueue
  
    Patches:
  	patch8_unused-upqueue.diff (license #6372) patch uploaded by Guenther Kelleter
  
    JIRA ABE-2882
  
  ................
    r374523 | rmudgett | 2012-10-04 19:11:50 -0500 (Thu, 04 Oct 2012) | 7 lines
  
    chan_misdn: Improve debugging (port number, messages fixed, dups removed)
  
    Patches:
  	patch9_debug.diff (license #6372) patch uploaded by Guenther Kelleter
  
    JIRA ABE-2882
  
  ................
    r374533 | rmudgett | 2012-10-05 12:17:18 -0500 (Fri, 05 Oct 2012) | 8 lines
  
    chan_misdn: Better debug: we can print_bc_info even if there's no ast leg.
  
    Patches:
  	patch10_debug-bc-2.diff (license #6372) patch uploaded by Guenther Kelleter
  	Modified.
  
    JIRA ABE-2882
  
  ................
    r374534 | rmudgett | 2012-10-05 12:34:10 -0500 (Fri, 05 Oct 2012) | 16 lines
  
    chan_misdn: setup_bc() is called too early for an incoming SETUP on TE.
  
    This prevents the B channel from being setup for HDLC mode when requested
    by the bearer capability and config option hdlc=yes.  It violates
    ETS300102 Ch.5.2.3.2: "The user, in any case, must not connect to the
    channel until a CONNECT ACKNOWLEDGE message has been received."
  
    * Call setup_bc() on receipt of CONNECT_ACKNOWLEGDE for PTMP, and on first
    response to SETUP for PTP.
  
    Patches:
  	abe-2881-2.diff (license #6372) patch uploaded by Guenther Kelleter
  	Modified.
  
    JIRA ABE-2881
  
  ................
    r374535 | rmudgett | 2012-10-05 12:41:05 -0500 (Fri, 05 Oct 2012) | 2 lines
  
    chan_misdn: Remove some more deadcode.
  
  ................
........

Merged revisions 370563,374536 from http://svn.asterisk.org/svn/asterisk/branches/1.8


git-svn-id: https://origsvn.digium.com/svn/asterisk/certified/branches/1.8.11@374540 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Richard Mudgett
2012-10-05 18:56:08 +00:00
parent 8fb6cbc65e
commit 57d21a4dec
4 changed files with 56 additions and 219 deletions

View File

@@ -44,8 +44,6 @@ int (*cb_jb_empty)(struct misdn_bchannel *bc, char *buffer, int len);
void misdn_join_conf(struct misdn_bchannel *bc, int conf_id);
void misdn_split_conf(struct misdn_bchannel *bc, int conf_id);
int queue_cleanup_bc(struct misdn_bchannel *bc) ;
int misdn_lib_get_l2_up(struct misdn_stack *stack);
struct misdn_stack *get_misdn_stack(void);
@@ -212,14 +210,12 @@ static enum global_states global_state=MISDN_INITIALIZING;
struct misdn_lib {
/*! \brief mISDN device handle returned by mISDN_open() */
int midev;
int midev_nt; /* Not used */
pthread_t event_thread;
pthread_t event_handler_thread;
void *user_data;
msg_queue_t upqueue;
msg_queue_t activatequeue;
sem_t new_msg;
@@ -238,8 +234,6 @@ void misdn_tx_jitter(struct misdn_bchannel *bc, int len);
struct misdn_bchannel *find_bc_by_l3id(struct misdn_stack *stack, unsigned long l3id);
int setup_bc(struct misdn_bchannel *bc);
int manager_isdn_handler(iframe_t *frm ,msg_t *msg);
int misdn_lib_port_restart(int port);
@@ -627,16 +621,9 @@ char *bc_state2str(enum bchannel_state state) {
} states[] = {
{"BCHAN_CLEANED", BCHAN_CLEANED },
{"BCHAN_EMPTY", BCHAN_EMPTY},
{"BCHAN_SETUP", BCHAN_SETUP},
{"BCHAN_SETUPED", BCHAN_SETUPED},
{"BCHAN_ACTIVE", BCHAN_ACTIVE},
{"BCHAN_ACTIVATED", BCHAN_ACTIVATED},
{"BCHAN_BRIDGE", BCHAN_BRIDGE},
{"BCHAN_BRIDGED", BCHAN_BRIDGED},
{"BCHAN_RELEASE", BCHAN_RELEASE},
{"BCHAN_RELEASED", BCHAN_RELEASED},
{"BCHAN_CLEAN", BCHAN_CLEAN},
{"BCHAN_CLEAN_REQUEST", BCHAN_CLEAN_REQUEST},
{"BCHAN_ERROR", BCHAN_ERROR}
};
@@ -831,9 +818,8 @@ static int clean_up_bc(struct misdn_bchannel *bc)
unsigned char buff[32];
struct misdn_stack * stack;
cb_log(3, bc?bc->port:0, "$$$ CLEANUP CALLED pid:%d\n", bc?bc->pid:-1);
cb_log(3, bc->port, "$$$ CLEANUP CALLED pid:%d\n", bc->pid);
if (!bc ) return -1;
stack=get_stack_by_bc(bc);
if (!stack) return -1;
@@ -1063,14 +1049,7 @@ static int create_process(int midev, struct misdn_bchannel *bc)
}
void misdn_lib_setup_bc(struct misdn_bchannel *bc)
{
clean_up_bc(bc);
setup_bc(bc);
}
int setup_bc(struct misdn_bchannel *bc)
static int setup_bc(struct misdn_bchannel *bc)
{
unsigned char buff[1025];
int midev;
@@ -1257,9 +1236,9 @@ static int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int mid
pthread_mutex_init(&bc->send_lock->lock, NULL);
empty_bc(bc);
bc_state_change(bc, BCHAN_CLEANED);
bc->port=stack->port;
bc_state_change(bc, BCHAN_CLEANED);
bc->nt=stack->nt?1:0;
bc->pri=stack->pri;
@@ -1331,7 +1310,6 @@ static struct misdn_stack *stack_init(int midev, int port, int ptp)
stack->pri=0;
msg_queue_init(&stack->downqueue);
msg_queue_init(&stack->upqueue);
pthread_mutex_init(&stack->st_lock, NULL);
@@ -1352,11 +1330,11 @@ static struct misdn_stack *stack_init(int midev, int port, int ptp)
switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK) {
case ISDN_PID_L0_TE_S0:
cb_log(8, port, "TE Stack\n");
stack->nt=0;
break;
case ISDN_PID_L0_NT_S0:
cb_log(8, port, "NT Stack\n");
stack->nt=1;
break;
case ISDN_PID_L0_TE_E1:
@@ -1365,10 +1343,9 @@ static struct misdn_stack *stack_init(int midev, int port, int ptp)
stack->pri=1;
break;
case ISDN_PID_L0_NT_E1:
cb_log(8, port, "TE S2M Stack\n");
cb_log(8, port, "NT S2M Stack\n");
stack->nt=1;
stack->pri=1;
break;
default:
cb_log(0, port, "this is a unknown port type 0x%08x\n", stinf->pid.protocol[0]);
@@ -1387,8 +1364,6 @@ static struct misdn_stack *stack_init(int midev, int port, int ptp)
int ret;
int nt=stack->nt;
cb_log(8, port, "Init. Stack.\n");
memset(&li, 0, sizeof(li));
{
int l = sizeof(li.name);
@@ -1429,9 +1404,6 @@ static struct misdn_stack *stack_init(int midev, int port, int ptp)
return(NULL);
}
cb_log(8, port, "NT Stacks upper_id %x\n",stack->upper_id);
/* create nst (nt-mode only) */
if (nt) {
@@ -1481,7 +1453,7 @@ static struct misdn_stack *stack_init(int midev, int port, int ptp)
}
cb_log(8,0,"stack_init: port:%d lowerId:%x upperId:%x\n",stack->port,stack->lower_id, stack->upper_id);
cb_log(8, port, "stack_init: lowerId:%x upperId:%x\n", stack->lower_id, stack->upper_id);
return stack;
}
@@ -1648,14 +1620,11 @@ static struct misdn_bchannel *find_bc_by_channel(int port, int channel)
static int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
static int handle_event_te(struct misdn_bchannel *bc, enum event_e event, iframe_t *frm)
{
struct misdn_stack *stack=get_stack_by_bc(bc);
if (!stack->nt) {
switch (event) {
switch (event) {
case EVENT_CONNECT_ACKNOWLEDGE:
setup_bc(bc);
@@ -1732,7 +1701,9 @@ static int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_
return -1;
}
setup_bc(bc);
if (event != EVENT_SETUP) {
setup_bc(bc);
}
break;
}
@@ -1741,9 +1712,6 @@ static int handle_event ( struct misdn_bchannel *bc, enum event_e event, iframe_
break;
default:
break;
}
} else { /** NT MODE **/
}
return 0;
}
@@ -2192,10 +2160,6 @@ static int handle_event_nt(void *dat, void *arg)
if (stack->l2upcnt>3) {
cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attempts!!!\n");
} else {
#if 0
if (stack->nt)
misdn_lib_reinit_nt_stack(stack->port);
#endif
if (stack->l1link) {
misdn_lib_get_l2_up(stack);
stack->l2upcnt++;
@@ -2489,43 +2453,6 @@ static int handle_bchan(msg_t *msg)
case MGR_SETSTACK| INDICATION:
cb_log(3, stack->port, "BCHAN: MGR_SETSTACK|IND pid:%d\n",bc->pid);
break;
#if 0
AGAIN:
bc->addr = mISDN_get_layerid(stack->midev, bc->b_stid, bc->layer);
if (!bc->addr) {
if (errno == EAGAIN) {
usleep(1000);
goto AGAIN;
}
cb_log(0,stack->port,"$$$ Get Layer (%d) Id Error: %s\n",bc->layer,strerror(errno));
/* we kill the channel later, when we received some
data. */
bc->addr= frm->addr;
} else if ( bc->addr < 0) {
cb_log(0, stack->port,"$$$ bc->addr <0 Error:%s\n",strerror(errno));
bc->addr=0;
}
cb_log(4, stack->port," --> Got Adr %x\n", bc->addr);
free_msg(msg);
switch(bc->bc_state) {
case BCHAN_SETUP:
bc_state_change(bc,BCHAN_SETUPED);
break;
case BCHAN_CLEAN_REQUEST:
default:
cb_log(0, stack->port," --> STATE WASN'T SETUP (but %s) in SETSTACK|IND pid:%d\n",bc_state2str(bc->bc_state), bc->pid);
clean_up_bc(bc);
}
return 1;
#endif
case MGR_DELLAYER| INDICATION:
cb_log(3, stack->port, "BCHAN: MGR_DELLAYER|IND pid:%d\n",bc->pid);
@@ -2765,7 +2692,7 @@ static int handle_frm_nt(msg_t *msg)
}
static int handle_frm(msg_t *msg)
static int handle_frm_te(msg_t *msg)
{
struct misdn_bchannel dummybc;
struct misdn_bchannel *bc;
@@ -2784,11 +2711,11 @@ static int handle_frm(msg_t *msg)
return 0;
}
cb_log(4, stack ? stack->port : 0, "handle_frm: frm->addr:%x frm->prim:%x\n", frm->addr, frm->prim);
cb_log(4, stack->port, "handle_frm_te: frm->addr:%x frm->prim:%x\n", frm->addr, frm->prim);
ret = handle_cr(stack, frm);
if (ret < 0) {
cb_log(3, stack ? stack->port : 0, "handle_frm: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr);
cb_log(3, stack->port, "handle_frm_te: handle_cr <0 prim:%x addr:%x\n", frm->prim, frm->addr);
}
if (ret) {
free_msg(msg);
@@ -2827,7 +2754,7 @@ static int handle_frm(msg_t *msg)
isdn_msg_parse_event(msgs_g, msg, bc, 0);
/* Preprocess some Events */
ret = handle_event(bc, event, frm);
ret = handle_event_te(bc, event, frm);
if (ret < 0) {
cb_log(0, stack->port, "couldn't handle event\n");
free_msg(msg);
@@ -2851,24 +2778,21 @@ static int handle_frm(msg_t *msg)
cb_log(0, stack->port, "TOTALLY IGNORING SETUP\n");
break;
case RESPONSE_IGNORE_SETUP:
cb_log(0, stack->port, "GOT IGNORE SETUP\n");
/* I think we should send CC_RELEASE_CR, but am not sure*/
bc->out_cause = AST_CAUSE_NORMAL_CLEARING;
/* fall through */
case RESPONSE_RELEASE_SETUP:
misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE);
if (bc->channel > 0) {
empty_chan_in_stack(stack, bc->channel);
if (response == RESPONSE_RELEASE_SETUP) {
cb_log(0, stack->port, "GOT RELEASE SETUP\n");
}
empty_bc(bc);
bc_state_change(bc, BCHAN_CLEANED);
bc->in_use = 0;
cb_log(0, stack->port, "GOT IGNORE SETUP\n");
misdn_lib_send_event(bc, EVENT_RELEASE_COMPLETE);
break;
case RESPONSE_OK:
cb_log(4, stack->port, "GOT SETUP OK\n");
break;
default:
cb_log(0, stack->port, "GOT UNKNOWN SETUP RESPONSE\n");
break;
}
break;
@@ -3300,12 +3224,6 @@ static void prepare_bc(struct misdn_bchannel*bc, int channel)
if (++mypid>5000) mypid=1;
bc->pid=mypid;
#if 0
bc->addr=0;
bc->b_stid=0;
bc->layer_id=0;
#endif
bc->in_use = 1;
}
@@ -3690,8 +3608,13 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
case EVENT_PROCEEDING:
case EVENT_SETUP_ACKNOWLEDGE:
case EVENT_CONNECT:
if (!stack->nt)
if (!stack->nt) {
if (stack->ptp) {
setup_bc(bc);
}
break;
}
/* fall through */
case EVENT_RETRIEVE_ACKNOWLEDGE:
if (stack->nt) {
@@ -3787,6 +3710,11 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
cb_log(0, bc->port, " --> we have already sent DISCONNECT\n");
RETURN(-1,OUT);
}
/* IE cause is mandatory for DISCONNECT, but optional for the answers to DISCONNECT.
* We must initialize cause, so it is later correctly indicated to ast_channel
* in case the answer does not include one!
*/
bc->cause = bc->out_cause;
bc->need_disconnect=0;
break;
@@ -3961,24 +3889,6 @@ static int handle_err(msg_t *msg)
return 0;
}
#if 0
static int queue_l2l3(msg_t *msg)
{
iframe_t *frm= (iframe_t*)msg->data;
struct misdn_stack *stack;
stack=find_stack_by_addr( frm->addr );
if (!stack) {
return 0;
}
msg_queue_tail(&stack->upqueue, msg);
sem_post(&glob_mgr->new_msg);
return 1;
}
#endif
int manager_isdn_handler(iframe_t *frm ,msg_t *msg)
{
@@ -4003,7 +3913,7 @@ int manager_isdn_handler(iframe_t *frm ,msg_t *msg)
}
#ifdef RECV_FRM_SYSLOG_DEBUG
syslog(LOG_NOTICE,"mISDN recv: P(%02d): ADDR:%x PRIM:%x DINFO:%x\n",stack->port, frm->addr, frm->prim, frm->dinfo);
syslog(LOG_NOTICE,"mISDN recv: ADDR:%x PRIM:%x DINFO:%x\n", frm->addr, frm->prim, frm->dinfo);
#endif
if (handle_timers(msg))
@@ -4024,7 +3934,7 @@ int manager_isdn_handler(iframe_t *frm ,msg_t *msg)
return 0;
}
if (handle_frm(msg)) {
if (handle_frm_te(msg)) {
return 0;
}
@@ -4071,32 +3981,6 @@ int misdn_lib_get_port_info(int port)
return 0;
}
int queue_cleanup_bc(struct misdn_bchannel *bc)
{
msg_t *msg=alloc_msg(MAX_MSG_SIZE);
iframe_t *frm;
if (!msg) {
cb_log(0, bc->port, "queue_cleanup_bc: alloc_msg failed!\n");
return -1;
}
frm=(iframe_t*)msg->data;
/* activate bchannel */
frm->prim = MGR_CLEARSTACK| REQUEST;
frm->addr = bc->l3_id;
frm->dinfo = bc->port;
frm->len = 0;
msg_queue_tail(&glob_mgr->activatequeue, msg);
sem_post(&glob_mgr->new_msg);
return 0;
}
int misdn_lib_pid_restart(int pid)
{
struct misdn_bchannel *bc=manager_find_bc_by_pid(pid);
@@ -4209,28 +4093,6 @@ static void manager_event_handler(void *arg)
iframe_t *frm = (iframe_t*) msg->data ;
switch ( frm->prim) {
case MGR_CLEARSTACK | REQUEST:
/*a queued bchannel cleanup*/
{
struct misdn_stack *stack=find_stack_by_port(frm->dinfo);
struct misdn_bchannel *bc;
if (!stack) {
cb_log(0,0,"no stack found with port [%d]!! so we cannot cleanup the bc\n",frm->dinfo);
free_msg(msg);
break;
}
bc = find_bc_by_l3id(stack, frm->addr);
if (bc) {
cb_log(1,bc->port,"CLEARSTACK queued, cleaning up\n");
clean_up_bc(bc);
} else {
cb_log(0,stack->port,"bc could not be cleaned correctly !! addr [%x]\n",frm->addr);
}
}
free_msg(msg);
break;
case MGR_SETSTACK | REQUEST :
free_msg(msg);
break;
@@ -4243,18 +4105,6 @@ static void manager_event_handler(void *arg)
for (stack=glob_mgr->stack_list;
stack;
stack=stack->next ) {
while ( (msg=msg_dequeue(&stack->upqueue)) ) {
/** Handle L2/3 Signalling after bchans **/
if (!handle_frm_nt(msg)) {
/* Maybe it's TE */
if (!handle_frm(msg)) {
/* wow none! */
cb_log(0,stack->port,"Wow we've got a strange issue while dequeueing a Frame\n");
}
}
}
/* Here we should check if we really want to
send all the messages we've queued, lets
assume we've queued a Disconnect, but
@@ -4725,9 +4575,7 @@ struct misdn_bchannel *stack_holder_find(struct misdn_stack *stack, unsigned lon
{
struct misdn_bchannel *help;
cb_log(4,stack?stack->port:0, "*HOLDER: find %lx\n",l3id);
if (!stack) return NULL;
cb_log(4, stack->port, "*HOLDER: find %lx\n",l3id);
for (help=stack->holding;
help;