aboutsummaryrefslogtreecommitdiffstats
path: root/channels/misdn
diff options
context:
space:
mode:
Diffstat (limited to 'channels/misdn')
-rw-r--r--channels/misdn/isdn_lib.c200
-rw-r--r--channels/misdn/isdn_lib.h296
-rw-r--r--channels/misdn/isdn_lib_intern.h76
3 files changed, 409 insertions, 163 deletions
diff --git a/channels/misdn/isdn_lib.c b/channels/misdn/isdn_lib.c
index 54d90ea18..eddde67e4 100644
--- a/channels/misdn/isdn_lib.c
+++ b/channels/misdn/isdn_lib.c
@@ -25,6 +25,14 @@
#include "isdn_lib_intern.h"
#include "isdn_lib.h"
+/*
+ * Define ARRAY_LEN() because I cannot
+ * #include "asterisk/utils.h"
+ */
+#define ARRAY_LEN(a) (sizeof(a) / sizeof(a[0]))
+
+#include "asterisk/causes.h"
+
void misdn_join_conf(struct misdn_bchannel *bc, int conf_id);
void misdn_split_conf(struct misdn_bchannel *bc, int conf_id);
@@ -137,17 +145,16 @@ int misdn_lib_get_maxchans(int port)
}
-struct misdn_stack* get_stack_by_bc(struct misdn_bchannel *bc)
+struct misdn_stack *get_stack_by_bc(struct misdn_bchannel *bc)
{
- struct misdn_stack *stack=get_misdn_stack();
+ struct misdn_stack *stack = get_misdn_stack();
- if (!bc) return NULL;
+ if (!bc)
+ return NULL;
- for ( ; stack; stack=stack->next) {
- int i;
- for (i=0; i <=stack->b_num; i++) {
- if ( bc->port == stack->port) return stack;
- }
+ for ( ; stack; stack = stack->next) {
+ if (bc->port == stack->port)
+ return stack;
}
return NULL;
@@ -163,12 +170,13 @@ void get_show_stack_details(int port, char *buf)
}
if (stack) {
- sprintf(buf, "* Port %d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d", stack->port, stack->nt?"NT":"TE", stack->ptp?"PTP":"PMP", stack->l2link?"UP":"DOWN", stack->l1link?"UP":"DOWN",stack->blocked);
-
+ sprintf(buf, "* Port %d Type %s Prot. %s L2Link %s L1Link:%s Blocked:%d",
+ stack->port, stack->nt ? "NT" : "TE", stack->ptp ? "PTP" : "PMP",
+ stack->l2link ? "UP" : "DOWN", stack->l1link ? "UP" : "DOWN",
+ stack->blocked);
} else {
buf[0]=0;
}
-
}
@@ -193,8 +201,9 @@ static enum global_states global_state=MISDN_INITIALIZING;
struct misdn_lib {
+ /*! \brief mISDN device handle returned by mISDN_open() */
int midev;
- int midev_nt;
+ int midev_nt; /* Not used */
pthread_t event_thread;
pthread_t event_handler_thread;
@@ -262,9 +271,6 @@ void stack_holder_remove(struct misdn_stack *stack, struct misdn_bchannel *holde
struct misdn_bchannel *stack_holder_find(struct misdn_stack *stack, unsigned long l3id);
/* from isdn_lib.h */
-int init_bc(struct misdn_stack * stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime);
-struct misdn_stack* stack_init(int midev, int port, int ptp);
-void stack_destroy(struct misdn_stack* stack);
/* user iface */
int te_lib_init( void ) ; /* returns midev */
void te_lib_destroy(int midev) ;
@@ -439,8 +445,10 @@ int misdn_cap_is_speech(int cap)
int misdn_inband_avail(struct misdn_bchannel *bc)
{
- /*if ! early_bconnect we have never inband available*/
- if ( ! bc->early_bconnect ) return 0;
+ if (!bc->early_bconnect) {
+ /* We have opted to never receive any available inband recorded messages */
+ return 0;
+ }
switch (bc->progress_indicator) {
case INFO_PI_INBAND_AVAILABLE:
@@ -517,7 +525,7 @@ static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchan
if (dec) {
for (i = bnums; i >=0; i--) {
- if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
+ if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 D channel ;) and work with chan preselection */
if (!stack->channels[i]) {
cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
chan=i+1;
@@ -527,7 +535,7 @@ static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchan
}
} else {
for (i = 0; i <= bnums; i++) {
- if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 Dchannel ;) and work with chan preselection */
+ if (i != 15 && (channel < 0 || i == channel)) { /* skip E1 D channel ;) and work with chan preselection */
if (!stack->channels[i]) {
cb_log (3, stack->port, " --> found chan%s: %d\n", channel>=0?" (preselected)":"", i+1);
chan=i+1;
@@ -540,13 +548,13 @@ static int find_free_chan_in_stack(struct misdn_stack *stack, struct misdn_bchan
if (!chan) {
cb_log (1, stack->port, " !! NO FREE CHAN IN STACK\n");
dump_chan_list(stack);
- bc->out_cause=34;
+ bc->out_cause = AST_CAUSE_NORMAL_CIRCUIT_CONGESTION;
return -1;
}
if (set_chan_in_stack(stack, chan)<0) {
cb_log (0, stack->port, "Channel Already in use:%d\n", chan);
- bc->out_cause=44;
+ bc->out_cause = AST_CAUSE_REQUESTED_CHAN_UNAVAIL;
return -1;
}
@@ -683,9 +691,9 @@ static void empty_bc(struct misdn_bchannel *bc)
bc->orig=0;
- bc->cause=16;
- bc->out_cause=16;
- bc->pres=0 ; /* screened */
+ bc->cause = AST_CAUSE_NORMAL_CLEARING;
+ bc->out_cause = AST_CAUSE_NORMAL_CLEARING;
+ bc->pres = 0; /* allowed */
bc->evq=EVENT_NOTHING;
@@ -909,7 +917,7 @@ static int create_process (int midev, struct misdn_bchannel *bc) {
if (stack->procids[i]==0) break;
if (i== MAXPROCS) {
- cb_log(0, stack->port, "Couldnt Create New ProcId.\n");
+ cb_log(0, stack->port, "Couldn't Create New ProcId.\n");
return -1;
}
stack->procids[i]=1;
@@ -990,13 +998,13 @@ int setup_bc(struct misdn_bchannel *bc)
case BCHAN_CLEANED:
break;
default:
- cb_log(4, stack->port, "$$$ bc already upsetted stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) );
+ cb_log(4, stack->port, "$$$ bc already setup stid :%x (state:%s)\n", b_stid, bc_state2str(bc->bc_state) );
return -1;
}
cb_log(5, stack->port, "$$$ Setting up bc with stid :%x\n", b_stid);
- /*check if the b_stid is alread initialized*/
+ /*check if the b_stid is already initialized*/
for (i=0; i <= stack->b_num; i++) {
if (stack->bc[i].b_stid == b_stid) {
cb_log(0, bc->port, "setup_bc: b_stid:%x already in use !!!\n", b_stid);
@@ -1046,10 +1054,9 @@ int setup_bc(struct misdn_bchannel *bc)
li.name[l-1] = 0;
}
li.pid.layermask = ISDN_LAYER((4));
- li.pid.protocol[4] = ISDN_PID_L4_B_USER
-;
+ li.pid.protocol[4] = ISDN_PID_L4_B_USER;
+
bc->layer=4;
-
}
ret = mISDN_new_layer(midev, &li);
@@ -1138,7 +1145,7 @@ int setup_bc(struct misdn_bchannel *bc)
/** IFACE **/
-int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime)
+static int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, int port, int bidx, char *msn, int firsttime)
{
unsigned char buff[1025] = "";
iframe_t *frm = (iframe_t *)buff;
@@ -1151,7 +1158,9 @@ int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, in
memset(bc, 0,sizeof(struct misdn_bchannel));
bc->send_lock=malloc(sizeof(struct send_lock));
-
+ if (!bc->send_lock) {
+ return -1;
+ }
pthread_mutex_init(&bc->send_lock->lock, NULL);
if (msn) {
@@ -1176,6 +1185,9 @@ int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, in
clear_ibuffer( ibuf);
ibuf->rsem=malloc(sizeof(sem_t));
+ if (!ibuf->rsem) {
+ return -1;
+ }
bc->astbuf=ibuf;
@@ -1202,7 +1214,7 @@ int init_bc(struct misdn_stack *stack, struct misdn_bchannel *bc, int midev, in
-struct misdn_stack* stack_init( int midev, int port, int ptp )
+static struct misdn_stack *stack_init(int midev, int port, int ptp)
{
int ret;
unsigned char buff[1025];
@@ -1387,7 +1399,7 @@ struct misdn_stack* stack_init( int midev, int port, int ptp )
}
-void stack_destroy(struct misdn_stack* stack)
+static void stack_destroy(struct misdn_stack *stack)
{
char buf[1024];
if (!stack) return;
@@ -1646,7 +1658,7 @@ static int handle_cr ( struct misdn_stack *stack, iframe_t *frm)
struct misdn_bchannel dummybc;
if (!bc) {
- cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
+ cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
misdn_make_dummy(&dummybc, stack->port, frm->dinfo, stack->nt, 0);
bc=&dummybc;
@@ -1673,7 +1685,7 @@ static int handle_cr ( struct misdn_stack *stack, iframe_t *frm)
dump_chan_list(stack);
if (bc->stack_holder) {
- cb_log(4,stack->port, "REMOVEING Holder\n");
+ cb_log(4,stack->port, "REMOVING Holder\n");
stack_holder_remove( stack, bc);
free(bc);
}
@@ -1692,7 +1704,7 @@ static int handle_cr ( struct misdn_stack *stack, iframe_t *frm)
}
-/*Emptys bc if it's reserved (no SETUP out yet)*/
+/* Empties bc if it's reserved (no SETUP out yet) */
void misdn_lib_release(struct misdn_bchannel *bc)
{
struct misdn_stack *stack=get_stack_by_bc(bc);
@@ -1801,10 +1813,10 @@ int release_cr(struct misdn_stack *stack, mISDNuser_head_t *hh)
frm.addr=stack->upper_id | FLG_MSG_DOWN;
frm.prim = CC_RELEASE_CR|INDICATION;
- cb_log(4, stack->port, " --> CC_RELEASE_CR: Faking Realease_cr for %x l3id:%x\n",frm.addr, frm.dinfo);
+ cb_log(4, stack->port, " --> CC_RELEASE_CR: Faking Release_cr for %x l3id:%x\n",frm.addr, frm.dinfo);
/** removing procid **/
if (!bc) {
- cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x) on this port.\n", hh->dinfo);
+ cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", hh->dinfo);
misdn_make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0);
bc=&dummybc;
}
@@ -1815,7 +1827,7 @@ int release_cr(struct misdn_stack *stack, mISDNuser_head_t *hh)
stack->procids[bc->l3_id&0xff] = 0 ;
}
}
- else cb_log(0, stack->port, "Couldnt find BC so I couldnt remove the Process!!!! this is a bad port.\n");
+ else cb_log(0, stack->port, "Couldn't find BC so I couldn't remove the Process!!!! this is a bad port.\n");
if (handle_cr(stack, &frm)<0) {
}
@@ -1868,7 +1880,7 @@ handle_event_nt(void *dat, void *arg)
cb_log(4, stack->port, "bc_l3id:%x holded_bc_l3id:%x\n",bc->l3_id, hold_bc->l3_id);
if (hold_bc) {
- cb_log(4, stack->port, "REMOVEING Holder\n");
+ cb_log(4, stack->port, "REMOVING Holder\n");
/*swap the backup to our new channel back*/
stack_holder_remove(stack, hold_bc);
@@ -2045,7 +2057,7 @@ handle_event_nt(void *dat, void *arg)
cb_log(3 , stack->port, "%% GOT L2 DeActivate Info.\n");
if (stack->l2upcnt>3) {
- cb_log(0 , stack->port, "!!! Could not Get the L2 up after 3 Attemps!!!\n");
+ 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);
@@ -2077,7 +2089,7 @@ handle_event_nt(void *dat, void *arg)
bc=find_bc_by_l3id(stack, hh->dinfo);
if (!bc) {
- cb_log(4, stack->port, " --> Didn't found BC so temporarly creating dummy BC (l3id:%x).\n", hh->dinfo);
+ cb_log(4, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x).\n", hh->dinfo);
misdn_make_dummy(&dummybc, stack->port, hh->dinfo, stack->nt, 0);
bc=&dummybc;
}
@@ -2116,7 +2128,7 @@ handle_event_nt(void *dat, void *arg)
} else {
if (reject) {
switch(bc->cause){
- case 17:
+ case AST_CAUSE_USER_BUSY:
cb_log(1, stack->port, "Siemens Busy reject..\n");
break;
@@ -2678,12 +2690,12 @@ handle_frm_bc:
switch (response) {
case RESPONSE_IGNORE_SETUP_WITHOUT_CLOSE:
- cb_log(0, stack->port, "TOTALY IGNORING SETUP \n");
+ cb_log(0, stack->port, "TOTALLY IGNORING SETUP\n");
break;
case RESPONSE_IGNORE_SETUP:
/* I think we should send CC_RELEASE_CR, but am not sure*/
- bc->out_cause=16;
+ bc->out_cause = AST_CAUSE_NORMAL_CLEARING;
case RESPONSE_RELEASE_SETUP:
misdn_lib_send_event(bc,EVENT_RELEASE_COMPLETE);
@@ -2706,7 +2718,7 @@ handle_frm_bc:
}
if (event == EVENT_RELEASE_COMPLETE) {
- /* release bchannel only after we've anounced the RELEASE_COMPLETE */
+ /* release bchannel only after we've announced the RELEASE_COMPLETE */
int channel=bc->channel;
int tmpcause=bc->cause;
int tmp_out_cause=bc->out_cause;
@@ -2715,8 +2727,8 @@ handle_frm_bc:
bc->out_cause=tmp_out_cause;
clean_up_bc(bc);
- if (tmpcause == 44) {
- cb_log(0,stack->port,"**** Received CAUSE:44, so not cleaning up channel %d\n", channel);
+ if (tmpcause == AST_CAUSE_REQUESTED_CHAN_UNAVAIL) {
+ cb_log(0,stack->port,"**** Received CAUSE:%d, so not cleaning up channel %d\n", AST_CAUSE_REQUESTED_CHAN_UNAVAIL, channel);
cb_log(0,stack->port,"**** This channel is now no longer available,\nplease try to restart it with 'misdn send restart <port> <channel>'\n");
set_chan_in_stack(stack, channel);
bc->channel=channel;
@@ -2743,9 +2755,9 @@ handle_frm_bc:
} else {
struct misdn_bchannel dummybc;
if (frm->prim!=(CC_FACILITY|INDICATION))
- cb_log(0, stack->port, " --> Didn't find BC so temporarly creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
+ cb_log(0, stack->port, " --> Didn't find BC so temporarily creating dummy BC (l3id:%x) on this port.\n", frm->dinfo);
else
- cb_log(5, stack->port, " --> Using Dummy BC for FACILITy\n");
+ cb_log(5, stack->port, " --> Using Dummy BC for FACILITY\n");
memset (&dummybc,0,sizeof(dummybc));
dummybc.port=stack->port;
@@ -2787,7 +2799,7 @@ static int handle_l1(msg_t *msg)
for (i=0;i<=stack->b_num; i++) {
if (stack->bc[i].evq != EVENT_NOTHING) {
- cb_log(4, stack->port, "Fireing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0));
+ cb_log(4, stack->port, "Firing Queued Event %s because L1 got up\n", isdn_get_info(msgs_g, stack->bc[i].evq, 0));
misdn_lib_send_event(&stack->bc[i],stack->bc[i].evq);
stack->bc[i].evq=EVENT_NOTHING;
}
@@ -2973,7 +2985,7 @@ static msg_t *fetch_msg(int midev)
msg->len=r;
if (r==0) {
- free_msg(msg); /* danger, cauz usualy freeing in main_loop */
+ free_msg(msg); /* danger, cause usually freeing in main_loop */
cb_log(6,0,"Got empty Msg..\n");
return NULL;
}
@@ -3014,6 +3026,7 @@ void misdn_lib_isdn_l1watcher(int port)
}
}
+/* This is a thread */
static void misdn_lib_isdn_event_catcher(void *arg)
{
struct misdn_lib *mgr = arg;
@@ -3030,7 +3043,7 @@ static void misdn_lib_isdn_event_catcher(void *arg)
frm = (iframe_t*) msg->data;
- /** When we make a call from NT2Ast we get this frames **/
+ /** When we make a call from NT2Ast we get these frames **/
if (frm->len == 0 && frm->addr == 0 && frm->dinfo == 0 && frm->prim == 0 ) {
zero_frm++;
free_msg(msg);
@@ -3094,7 +3107,7 @@ void te_lib_destroy(int midev)
char buf[1024];
mISDN_write_frame(midev, buf, 0, MGR_DELENTITY | REQUEST, entity, 0, NULL, TIMEOUT_1SEC);
- cb_log(4, 0, "Entetity deleted\n");
+ cb_log(4, 0, "Entity deleted\n");
mISDN_close(midev);
cb_log(4, 0, "midev closed\n");
}
@@ -3157,7 +3170,7 @@ static void prepare_bc(struct misdn_bchannel*bc, int channel)
bc->need_disconnect=1;
bc->need_release=1;
bc->need_release_complete=1;
- bc->cause=16;
+ bc->cause = AST_CAUSE_NORMAL_CLEARING;
if (++mypid>5000) mypid=1;
bc->pid=mypid;
@@ -3248,23 +3261,47 @@ struct misdn_bchannel* misdn_lib_get_free_bc(int port, int channel, int inout, i
}
-static char *fac2str (enum FacFunction func)
+
+
+/* ******************************************************************* */
+/*!
+ * \internal
+ * \brief Convert the facility function enum value into a string.
+ *
+ * \return String version of the enum value
+ */
+static const char *fac2str(enum FacFunction facility)
{
- struct arr_el {
- enum FacFunction p;
- char *s ;
+ static const struct {
+ enum FacFunction facility;
+ char *name;
} arr[] = {
+/* *INDENT-OFF* */
{ Fac_None, "Fac_None" },
- { Fac_CD, "Fac_CD"},
+ { Fac_GetSupportedServices, "Fac_GetSupportedServices" },
+ { Fac_Listen, "Fac_Listen" },
+ { Fac_Suspend, "Fac_Suspend" },
+ { Fac_Resume, "Fac_Resume" },
+ { Fac_CFActivate, "Fac_CFActivate" },
+ { Fac_CFDeactivate, "Fac_CFDeactivate" },
+ { Fac_CFInterrogateParameters, "Fac_CFInterrogateParameters" },
+ { Fac_CFInterrogateNumbers, "Fac_CFInterrogateNumbers" },
+ { Fac_CD, "Fac_CD" },
+ { Fac_AOCDCurrency, "Fac_AOCDCurrency" },
+ { Fac_AOCDChargingUnit, "Fac_AOCDChargingUnit" },
+/* *INDENT-ON* */
};
- int i;
-
- for (i=0; i < sizeof(arr)/sizeof( struct arr_el) ; i ++)
- if ( arr[i].p==func) return arr[i].s;
+ unsigned index;
+ for (index = 0; index < ARRAY_LEN(arr); ++index) {
+ if (arr[index].facility == facility) {
+ return arr[index].name;
+ }
+ } /* end for */
+
return "unknown";
-}
+} /* end fac2str() */
void misdn_lib_log_ies(struct misdn_bchannel *bc)
{
@@ -3300,19 +3337,17 @@ void misdn_lib_log_ies(struct misdn_bchannel *bc)
cb_log(5, stack->port, " --> bc:%p h:%d sh:%d\n", bc, bc->holded, bc->stack_holder);
}
-void misdn_send_lock(struct misdn_bchannel *bc);
-void misdn_send_unlock(struct misdn_bchannel *bc);
#define RETURN(a,b) {retval=a; goto b;}
-void misdn_send_lock(struct misdn_bchannel *bc)
+static void misdn_send_lock(struct misdn_bchannel *bc)
{
//cb_log(0,bc->port,"Locking bc->pid:%d\n", bc->pid);
if (bc->send_lock)
pthread_mutex_lock(&bc->send_lock->lock);
}
-void misdn_send_unlock(struct misdn_bchannel *bc)
+static void misdn_send_unlock(struct misdn_bchannel *bc)
{
//cb_log(0,bc->port,"UnLocking bc->pid:%d\n", bc->pid);
if (bc->send_lock)
@@ -3337,7 +3372,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
misdn_send_lock(bc);
- cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->uperid:%x\n",stack->nt, stack->upper_id);
+ cb_log(6,stack->port,"SENDEVENT: stack->nt:%d stack->upperid:%x\n",stack->nt, stack->upper_id);
if ( stack->nt && !stack->l1link) {
/** Queue Event **/
@@ -3480,7 +3515,7 @@ int misdn_lib_send_event(struct misdn_bchannel *bc, enum event_e event )
bc->need_release_complete=0;
if (!stack->nt) {
- /*create clenaup in TE*/
+ /*create cleanup in TE*/
int channel=bc->channel;
int tmpcause=bc->cause;
@@ -3710,7 +3745,7 @@ int misdn_lib_get_port_info(int port)
iframe_t *frm;
struct misdn_stack *stack=find_stack_by_port(port);
if (!msg) {
- cb_log(0, port, "misgn_lib_get_port: alloc_msg failed!\n");
+ cb_log(0, port, "misdn_lib_get_port_info: alloc_msg failed!\n");
return -1;
}
frm=(iframe_t*)msg->data;
@@ -3739,7 +3774,7 @@ 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, "misgn_lib_get_port: alloc_msg failed!\n");
+ cb_log(0, bc->port, "queue_cleanup_bc: alloc_msg failed!\n");
return -1;
}
frm=(iframe_t*)msg->data;
@@ -3769,7 +3804,7 @@ int misdn_lib_pid_restart(int pid)
return 0;
}
-/*Sends Restart message for every bchnanel*/
+/*Sends Restart message for every bchannel*/
int misdn_lib_send_restart(int port, int channel)
{
struct misdn_stack *stack=find_stack_by_port(port);
@@ -3851,6 +3886,7 @@ int misdn_lib_port_restart(int port)
sem_t handler_started;
+/* This is a thread */
static void manager_event_handler(void *arg)
{
sem_post(&handler_started);
@@ -3893,6 +3929,7 @@ static void manager_event_handler(void *arg)
free_msg(msg);
break;
case MGR_SETSTACK | REQUEST :
+ /* Warning: memory leak here if we get this message */
break;
default:
mISDN_write(glob_mgr->midev, frm, mISDN_HEADER_LEN+frm->len, TIMEOUT_1SEC);
@@ -3947,8 +3984,10 @@ static void manager_event_handler(void *arg)
}
-int misdn_lib_maxports_get() { /** BE AWARE WE HAVE NO CB_LOG HERE! **/
-
+int misdn_lib_maxports_get(void)
+{
+ /* BE AWARE WE HAVE NO cb_log() HERE! */
+
int i = mISDN_open();
int max=0;
@@ -4056,7 +4095,7 @@ int misdn_lib_init(char *portlist, struct misdn_lib_iface *iface, void *user_dat
stack=stack_init(midev, port, ptp);
if (!stack) {
- perror("init_stack");
+ perror("stack_init");
exit(1);
}
@@ -4103,7 +4142,7 @@ int misdn_lib_init(char *portlist, struct misdn_lib_iface *iface, void *user_dat
return (mgr == NULL);
}
-void misdn_lib_destroy()
+void misdn_lib_destroy(void)
{
struct misdn_stack *help;
int i;
@@ -4327,9 +4366,6 @@ void stack_holder_add(struct misdn_stack *stack, struct misdn_bchannel *holder)
cb_log(4,stack->port, "*HOLDER: add %x\n",holder->l3_id);
holder->stack_holder=1;
-
- if (!stack ) return ;
-
holder->next=NULL;
if (!stack->holding) {
diff --git a/channels/misdn/isdn_lib.h b/channels/misdn/isdn_lib.h
index 3ea5385d0..15e43b0aa 100644
--- a/channels/misdn/isdn_lib.h
+++ b/channels/misdn/isdn_lib.h
@@ -11,7 +11,7 @@
* the GNU General Public License
*/
-/*! \file
+/*! \file
* \brief Interface to mISDN
*
* \author Christian Richter <crich@beronet.com>
@@ -27,9 +27,9 @@
/** end of init usage **/
-/*
+/*
* uncomment the following to make chan_misdn create
- * record files in /tmp/misdn-{rx|tx}-PortChannel format
+ * record files in /tmp/misdn-{rx|tx}-PortChannel format
* */
/*#define MISDN_SAVE_DATA*/
@@ -50,9 +50,9 @@ beroec_t *beroec_new(int tail, enum beroec_type type, int anti_howl,
int tonedisable, int zerocoeff, int adapt, int nlp);
void beroec_destroy(beroec_t *ec);
-int beroec_cancel_alaw_chunk(beroec_t *ec,
- char *send,
- char *receive ,
+int beroec_cancel_alaw_chunk(beroec_t *ec,
+ char *send,
+ char *receive,
int len);
int beroec_version(void);
@@ -103,7 +103,7 @@ enum mISDN_NUMBER_PLAN {
NUMPLAN_NATIONAL=0x2,
NUMPLAN_SUBSCRIBER=0x4,
NUMPLAN_UNKNOWN=0x0
-};
+};
enum event_response_e {
@@ -158,7 +158,7 @@ enum event_e {
EVENT_PORT_ALARM,
EVENT_NEW_CHANNEL,
EVENT_UNKNOWN
-};
+};
enum ie_name_e {
@@ -192,7 +192,7 @@ enum { /* progress indicators */
enum { /*CODECS*/
INFO_CODEC_ULAW=2,
INFO_CODEC_ALAW=3
-};
+};
enum layer_e {
@@ -200,85 +200,173 @@ enum layer_e {
L2,
L1,
UNKNOWN
-};
+};
struct misdn_bchannel {
+ /*! \brief B channel send locking structure */
struct send_lock *send_lock;
+ /*! \brief TRUE if this is a dummy BC record */
int dummy;
+ /*! \brief TRUE if NT side of protocol (TE otherwise) */
int nt;
+
+ /*! \brief TRUE if ISDN-PRI (ISDN-BRI otherwise) */
int pri;
+ /*! \brief Logical Layer 1 port associated with this B channel */
int port;
+
/** init stuff **/
+ /*! \brief B Channel mISDN driver stack ID */
int b_stid;
+
/* int b_addr; */
+
+ /*! \brief B Channel mISDN driver layer ID from mISDN_new_layer() */
int layer_id;
+ /*! \brief B channel layer; set to 3 or 4 */
int layer;
-
- /*state stuff*/
+
+ /* state stuff */
+ /*! \brief TRUE if DISCONNECT needs to be sent to clear a call */
int need_disconnect;
+
+ /*! \brief TRUE if RELEASE needs to be sent to clear a call */
int need_release;
+
+ /*! \brief TRUE if RELEASE_COMPLETE needs to be sent to clear a call */
int need_release_complete;
+ /*! \brief TRUE if allocate higher B channels first */
int dec;
- /** var stuff**/
+
+ /* var stuff */
+ /*! \brief Layer 3 process ID */
int l3_id;
+
+ /*! \brief B channel process ID (1-5000) */
int pid;
+
+ /*! \brief Not used. Saved mISDN stack CONNECT_t ces value */
int ces;
+ /*! \brief B channel to restart if received a RESTART message */
int restart_channel;
+
+ /*! \brief Assigned B channel number B1, B2... 0 if not assigned */
int channel;
+
+ /*! \brief TRUE if the B channel number is preselected */
int channel_preselected;
-
+
+ /*! \brief TRUE if B channel record is in use */
int in_use;
+
+ /*! \brief Time when empty_bc() last called on this record */
struct timeval last_used;
+
+ /*! \brief TRUE if call waiting */
int cw;
+
+ /*! \brief B Channel mISDN driver layer ID from mISDN_get_layerid() */
int addr;
- char * bframe;
+ /*! \brief B channel speech sample data buffer */
+ char *bframe;
+
+ /*! \brief B channel speech sample data buffer size */
int bframe_len;
- int time_usec;
-
-
+ int time_usec; /* Not used */
+
+ /*! \brief Not used. Contents are setup but not used. */
void *astbuf;
- void *misdnbuf;
+ void *misdnbuf; /* Not used */
+ /*! \brief TRUE if the TE side should choose the B channel to use
+ * \note This value is user configurable in /etc/asterisk/misdn.conf
+ */
int te_choose_channel;
+
+ /*! \brief TRUE if the call progress indicators can indicate an inband audio message for the user to listen to
+ * \note This value is user configurable in /etc/asterisk/misdn.conf
+ */
int early_bconnect;
-
- /* dtmf digit */
+
+ /*! \brief Last decoded DTMF digit from mISDN driver */
int dtmf;
+
+ /*! \brief TRUE if we should produce DTMF tones ourselves
+ * \note This value is user configurable in /etc/asterisk/misdn.conf
+ */
int send_dtmf;
- /* get setup ack */
+ /*! \brief TRUE if we send SETUP_ACKNOWLEDGE on incoming calls anyway (instead of PROCEEDING).
+ *
+ * This requests additional INFORMATION messages, so we can
+ * wait for digits without issues.
+ * \note This value is user configurable in /etc/asterisk/misdn.conf
+ */
int need_more_infos;
- /* may there be more infos ?*/
+ /*! \brief TRUE if all digits necessary to complete the call are available.
+ * No more INFORMATION messages are needed.
+ */
int sending_complete;
- /* wether we should use jollys dsp or not */
+ /*! \brief TRUE if we will not use jollys dsp */
int nodsp;
-
- /* wether we should use our jitter buf system or not */
+
+ /*! \brief TRUE if we will not use the jitter buffer system */
int nojitter;
-
+
+ /*! \brief Type-of-number in ISDN terms for the dialed/called number
+ * \note This value is set to "dialplan" in /etc/asterisk/misdn.conf for outgoing calls
+ */
enum mISDN_NUMBER_PLAN dnumplan;
+
+ /*! \brief Type-of-number in ISDN terms for the redirecting number which a call diversion or transfer was invoked.
+ * \note Collected from the incoming SETUP message but not used.
+ */
enum mISDN_NUMBER_PLAN rnumplan;
+
+ /*! \brief Type-of-number in ISDN terms for the originating/calling number (Caller-ID)
+ * \note This value is set to "localdialplan" in /etc/asterisk/misdn.conf for outgoing calls
+ */
enum mISDN_NUMBER_PLAN onumplan;
+
+ /*! \brief Type-of-number in ISDN terms for the connected party number
+ * \note This value is set to "cpndialplan" in /etc/asterisk/misdn.conf for outgoing calls
+ */
enum mISDN_NUMBER_PLAN cpnnumplan;
+ /*! \brief Progress Indicator IE coding standard field.
+ * \note Collected from the incoming messages but not used.
+ */
int progress_coding;
+
+ /*! \brief Progress Indicator IE location field.
+ * \note Collected from the incoming messages but not used.
+ */
int progress_location;
+
+ /*! \brief Progress Indicator IE progress description field.
+ * Used to determine if there is an inband audio message present.
+ */
int progress_indicator;
+ /*! \brief Inbound FACILITY message function type and contents */
struct FacParm fac_in;
+
+ /*! \brief Outbound FACILITY message function type and contents.
+ * \note Filled in by misdn facility commands before FACILITY message sent.
+ */
struct FacParm fac_out;
/* storing the current AOCD info here */
@@ -287,92 +375,194 @@ struct misdn_bchannel {
struct FacAOCDCurrency currency;
struct FacAOCDChargingUnit chargingUnit;
} AOCD;
+ /*! \brief TRUE if AOCDtype and AOCD data are ready to export to Asterisk */
int AOCD_need_export;
-
+
+ /*! \brief Event waiting for Layer 1 to come up */
enum event_e evq;
-
+
/*** CRYPTING STUFF ***/
-
- int crypt;
- int curprx;
- int curptx;
+ int crypt; /* Initialized, Not used */
+ int curprx; /* Initialized, Not used */
+ int curptx; /* Initialized, Not used */
+
+ /*! \brief Blowfish encryption key string (secret) */
char crypt_key[255];
-
- int crypt_state;
-
- /*char ast_dtmf_buf[255];
- char misdn_dtmf_buf[255]; */
-
+
+ int crypt_state; /* Not used */
/*** CRYPTING STUFF END***/
-
+
+ /*! \brief Seems to have been intended for something to do with the jitter buffer.
+ * \note Used as a boolean. Only initialized to 0 and referenced in a couple places
+ */
int active;
- int upset;
+ int upset; /* Not used */
+ /*! \brief TRUE if tone generator allowed to start */
int generate_tone;
+
+ /*! \brief Number of tone samples to generate */
int tone_cnt;
-
+
+ /*! \brief Current B Channel state */
enum bchannel_state bc_state;
+
+ /*! \brief This is used as a pending bridge join request for when bc_state becomes BCHAN_ACTIVATED */
enum bchannel_state next_bc_state;
+ /*! \brief Bridgign conference ID */
int conf_id;
-
+
+ /*! \brief TRUE if this channel is on hold */
int holded;
+
+ /*! \brief TRUE if this channel is on the misdn_stack->holding list
+ * \note If TRUE this implies that the structure is also malloced.
+ */
int stack_holder;
+ /*! \brief Caller ID presentation restriction code
+ * 0=Allowed, 1=Restricted, 2=Unavailable
+ * \note It is settable by the misdn_set_opt() application.
+ */
int pres;
+
+ /*! \brief Caller ID screening code
+ * 0=Unscreened, 1=Passed Screen, 2=Failed Screen, 3=Network Number
+ */
int screen;
-
+
+ /*! \brief SETUP message bearer capability field code value */
int capability;
+
+ /*! \brief Companding ALaw/uLaw encoding (INFO_CODEC_ALAW / INFO_CODEC_ULAW) */
int law;
- /** V110 Stuff **/
+
+ /* V110 Stuff */
+ /*! \brief Q.931 Bearer Capability IE Information Transfer Rate field. Initialized to 0x10 (64kbit). Altered by incoming SETUP messages. */
int rate;
+
+ /*! \brief Q.931 Bearer Capability IE Transfer Mode field. Initialized to 0 (Circuit). Altered by incoming SETUP messages. */
int mode;
+ /*! \brief Q.931 Bearer Capability IE User Information Layer 1 Protocol field code.
+ * \note Collected from the incoming SETUP message but not used.
+ */
int user1;
+
+ /*! \brief Q.931 Bearer Capability IE Layer 1 User Rate field.
+ * \note Collected from the incoming SETUP message and exported to Asterisk variable MISDN_URATE.
+ */
int urate;
+
+ /*! \brief TRUE if call made in digital HDLC mode
+ * \note This value is user configurable in /etc/asterisk/misdn.conf.
+ * It is also settable by the misdn_set_opt() application.
+ */
int hdlc;
/* V110 */
-
+
+ /*! \brief Display message that can be displayed by the user phone.
+ * \note Maximum displayable length is 34 or 82 octets.
+ * It is also settable by the misdn_set_opt() application.
+ */
char display[84];
+
+ /*! \brief Not used. Contents are setup but not used. */
char msn[32];
+
+ /*! \brief Originating/Calling Phone Number (Address)
+ * \note This value can be set to "callerid" in /etc/asterisk/misdn.conf for outgoing calls
+ */
char oad[32];
+
+ /*! \brief Redirecting Phone Number (Address) where a call diversion or transfer was invoked */
char rad[32];
+
+ /*! \brief Dialed/Called Phone Number (Address) */
char dad[32];
+
+ /*! \brief Connected Party/Line Phone Number (Address) */
char cad[32];
+
+ /*! \brief Original Dialed/Called Phone Number (Address) before national/international dialing prefix added.
+ * \note Not used. Contents are setup but not used.
+ */
char orig_dad[32];
+
+ /*! \brief Q.931 Keypad Facility IE contents
+ * \note Contents exported and imported to Asterisk variable MISDN_KEYPAD
+ */
char keypad[32];
+ /*! \brief Current overlap dialing digits to/from INFORMATION messages */
char info_dad[64];
+
+ /*! \brief Collected digits to go into info_dad[] while waiting for a SETUP_ACKNOWLEDGE to come in. */
char infos_pending[64];
/* unsigned char info_keypad[32]; */
/* unsigned char clisub[24]; */
/* unsigned char cldsub[24]; */
+ /*! \brief User-User information string.
+ * \note Contents exported and imported to Asterisk variable MISDN_USERUSER
+ * \note We only support ASCII strings (IA5 characters).
+ */
char uu[256];
+
+ /*! \brief User-User information string length in uu[] */
int uulen;
-
+
+ /*! \brief Q.931 Cause for disconnection code (received)
+ * \note Need to use the AST_CAUSE_xxx code definitions in causes.h
+ */
int cause;
+
+ /*! \brief Q.931 Cause for disconnection code (sent)
+ * \note Need to use the AST_CAUSE_xxx code definitions in causes.h
+ * \note -1 is used to suppress including the cause code in the RELEASE message.
+ */
int out_cause;
-
+
/* struct misdn_bchannel hold_bc; */
-
+
/** list stuf **/
#ifdef MISDN_1_2
+ /*! \brief The configuration string for the mISDN dsp pipeline in /etc/asterisk/misdn.conf. */
char pipeline[128];
#else
+ /*! \brief TRUE if the echo cancellor is enabled */
int ec_enable;
+
+ /*! \brief Number of taps in the echo cancellor when enabled.
+ * \note This value is user configurable in /etc/asterisk/misdn.conf (echocancel)
+ */
int ec_deftaps;
#endif
-
+
+ /*! \brief TRUE if the channel was allocated from the available B channels */
int channel_found;
-
+
+ /*! \brief Who originated the call (ORG_AST, ORG_MISDN)
+ * \note Set but not used when the misdn_set_opt() application enables echo cancellation.
+ */
int orig;
+ /*! \brief Tx gain setting (range -8 to 8)
+ * \note This value is user configurable in /etc/asterisk/misdn.conf.
+ * It is also settable by the misdn_set_opt() application.
+ */
int txgain;
+
+ /*! \brief Rx gain setting (range -8 to 8)
+ * \note This value is user configurable in /etc/asterisk/misdn.conf.
+ * It is also settable by the misdn_set_opt() application.
+ */
int rxgain;
-
+
+ /*! \brief Next node in the misdn_stack.holding list */
struct misdn_bchannel *next;
};
@@ -439,7 +629,7 @@ int misdn_lib_port_up(int port, int notcheck);
int misdn_lib_get_port_down(int port);
int misdn_lib_get_port_up (int port) ;
-
+
int misdn_lib_maxports_get(void) ;
void misdn_lib_release(struct misdn_bchannel *bc);
diff --git a/channels/misdn/isdn_lib_intern.h b/channels/misdn/isdn_lib_intern.h
index 725ef963f..498c73935 100644
--- a/channels/misdn/isdn_lib_intern.h
+++ b/channels/misdn/isdn_lib_intern.h
@@ -28,8 +28,8 @@
#endif
-ibuffer_t *astbuf;
-ibuffer_t *misdnbuf;
+ibuffer_t *astbuf; /* Not used */
+ibuffer_t *misdnbuf; /* Not used */
struct send_lock {
pthread_mutex_t lock;
@@ -38,15 +38,14 @@ struct send_lock {
struct isdn_msg {
unsigned long misdn_msg;
-
+
enum layer_e layer;
enum event_e event;
-
+
void (*msg_parser)(struct isdn_msg *msgs, msg_t *msg, struct misdn_bchannel *bc, int nt);
msg_t *(*msg_builder)(struct isdn_msg *msgs, struct misdn_bchannel *bc, int nt);
char *info;
-
-} ;
+} ;
/* for isdn_msg_parser.c */
msg_t *create_l3msg(int prim, int mt, int dinfo , int size, int nt);
@@ -57,57 +56,78 @@ struct misdn_stack {
/** is first element because &nst equals &mISDNlist **/
net_stack_t nst;
manager_t mgr;
-
+
+ /*! \brief D Channel mISDN driver stack ID (Parent stack ID) */
int d_stid;
-
+
+ /*! /brief Number of B channels supported by this port */
int b_num;
-
+
+ /*! \brief B Channel mISDN driver stack IDs (Child stack IDs) */
int b_stids[MAX_BCHANS + 1];
-
+
+ /*! \brief TRUE if Point-To-Point(PTP) (Point-To-Multipoint(PTMP) otherwise) */
int ptp;
+ /*! \brief Number of consecutive times PTP Layer 2 declared down */
int l2upcnt;
- int l2_id;
+ int l2_id; /* Not used */
+
+ /*! \brief Lower layer mISDN ID (addr) (Layer 1/3) */
int lower_id;
+
+ /*! \brief Upper layer mISDN ID (addr) (Layer 2/4) */
int upper_id;
-
+ /*! \brief TRUE if port is blocked */
int blocked;
+ /*! \brief TRUE if Layer 2 is UP */
int l2link;
-
- time_t l2establish;
-
+
+ time_t l2establish; /* Not used */
+
+ /*! \brief TRUE if Layer 1 is UP */
int l1link;
+ /*! \brief TRUE if restart has been sent to the other side after stack startup */
int restart_sent;
+ /*! \brief mISDN device handle returned by mISDN_open() */
int midev;
-
+
+ /*! \brief TRUE if NT side of protocol (TE otherwise) */
int nt;
-
+
+ /*! \brief TRUE if ISDN-PRI (ISDN-BRI otherwise) */
int pri;
-
+ /*! \brief CR Process ID allocation table. TRUE if ID allocated */
int procids[0x100+1];
+ /*! \brief Queue of Event messages to send to mISDN */
msg_queue_t downqueue;
- msg_queue_t upqueue;
- int busy;
-
+ msg_queue_t upqueue; /* No code puts anything on this queue */
+ int busy; /* Not used */
+
+ /*! \brief Logical Layer 1 port associated with this stack */
int port;
+
+ /*! \brief B Channel record pool array */
struct misdn_bchannel bc[MAX_BCHANS + 1];
-
- struct misdn_bchannel* bc_list;
-
+
+ struct misdn_bchannel* bc_list; /* Not used */
+
+ /*! \brief Array of B channels in use (a[0] = B1). TRUE if B channel in use */
int channels[MAX_BCHANS + 1];
-
- struct misdn_bchannel *holding; /* Queue which holds holded channels :) */
-
+ /*! \brief List of holded channels */
+ struct misdn_bchannel *holding;
+
+ /*! \brief Next stack in the list of stacks */
struct misdn_stack *next;
-};
+};
struct misdn_stack* get_stack_by_bc(struct misdn_bchannel *bc);