wait for actication request/indication by polling mISDN
This commit is contained in:
parent
9793cb5278
commit
be1d4a8831
|
@ -44,7 +44,7 @@ typedef struct _devinfo {
|
|||
} devinfo_t;
|
||||
|
||||
|
||||
static int VerifyOn=0;
|
||||
static int VerifyOn=1;
|
||||
static devinfo_t mISDN;
|
||||
|
||||
|
||||
|
@ -67,6 +67,15 @@ void set_signals()
|
|||
signal(SIGTERM, sig_handler);
|
||||
}
|
||||
|
||||
#define TICKS_PER_SEC 1000000
|
||||
long get_tick_count(void)
|
||||
{
|
||||
struct timeval tp;
|
||||
|
||||
gettimeofday(&tp, 0);
|
||||
return ((unsigned)tp.tv_sec)*TICKS_PER_SEC+((unsigned)tp.tv_usec);
|
||||
}
|
||||
|
||||
|
||||
/* create userland layer2 */
|
||||
int
|
||||
|
@ -107,11 +116,13 @@ add_dlayer2(devinfo_t *di)
|
|||
return(0);
|
||||
}
|
||||
|
||||
int do_setup(devinfo_t *di) {
|
||||
unsigned char buf[1024];
|
||||
int do_setup(devinfo_t *di)
|
||||
{
|
||||
unsigned char buf[2048];
|
||||
iframe_t *frm = (iframe_t *)buf;
|
||||
int i, ret = 0;
|
||||
stack_info_t *stinf;
|
||||
long t1;
|
||||
|
||||
ret = mISDN_get_stack_count(di->device);
|
||||
if (VerifyOn>1)
|
||||
|
@ -121,7 +132,7 @@ int do_setup(devinfo_t *di) {
|
|||
di->cardnr, ret);
|
||||
return(2);
|
||||
}
|
||||
ret = mISDN_get_stack_info(di->device, di->cardnr, buf, 1024);
|
||||
ret = mISDN_get_stack_info(di->device, di->cardnr, buf, 2048);
|
||||
if (ret<=0) {
|
||||
fprintf(stdout, "cannot get stackinfo err: %d\n", ret);
|
||||
return(3);
|
||||
|
@ -160,25 +171,41 @@ int do_setup(devinfo_t *di) {
|
|||
fprintf(stdout, "created new User-Layer2: 0x%x\n", di->layer2);
|
||||
}
|
||||
|
||||
fprintf(stdout, "sending PH_ACTIVATE | REQUEST to layer1...\n");
|
||||
ret = mISDN_write_frame(di->device, buf, di->layer2 | FLG_MSG_DOWN,
|
||||
PH_ACTIVATE | REQUEST, 0, 0, NULL, 0);
|
||||
|
||||
/* wait for at least timer3 for */
|
||||
ret = mISDN_read(di->device, buf, 128, TIMEOUT_10SEC);
|
||||
// wait for PH_ACTIVATE | INDICATION or CONFIRM
|
||||
t1 = get_tick_count();
|
||||
while (1) {
|
||||
|
||||
ret = mISDN_read(di->device, buf, 2048, 0);
|
||||
|
||||
if (ret > 0) {
|
||||
if ((frm->prim == (PH_ACTIVATE | CONFIRM)) ||
|
||||
(frm->prim == (PH_ACTIVATE | INDICATION))) {
|
||||
fprintf(stdout, "layer1 activated (0x%x)\n", frm->prim);
|
||||
return(0);
|
||||
} else {
|
||||
fprintf(stdout,"unable to activate layer1 (0x%x)\n", frm->prim);
|
||||
}
|
||||
|
||||
/*
|
||||
if (frm->prim == (MGR_SHORTSTATUS | INDICATION)) {
|
||||
fprintf(stdout, "got MGR_SHORTSTATUS | INDICATION\n");
|
||||
}
|
||||
fprintf(stdout, "got (0x%x), still waiting for PH_ACTIVATE | CONFIRM/INDICATION...\n", frm->prim);
|
||||
*/
|
||||
}
|
||||
|
||||
if ((get_tick_count() - t1) > (TICKS_PER_SEC * 5)) {
|
||||
printf(stdout, "unable to activate layer1 (TIMEOUT)\n");
|
||||
return(6);
|
||||
}
|
||||
}
|
||||
|
||||
return(10);
|
||||
return(7);
|
||||
}
|
||||
|
||||
|
||||
int printhexdata(FILE *f, int len, u_char *p)
|
||||
{
|
||||
while(len--) {
|
||||
|
@ -190,23 +217,24 @@ int printhexdata(FILE *f, int len, u_char *p)
|
|||
return(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void main_data_loop(devinfo_t *di)
|
||||
{
|
||||
unsigned char buf[1024];
|
||||
unsigned char tx_buf[1024];
|
||||
struct timeval tp;
|
||||
long a, b;
|
||||
long t1;
|
||||
unsigned char buf[2048];
|
||||
unsigned char tx_buf[2048];
|
||||
|
||||
iframe_t *frm = (iframe_t *)buf;
|
||||
int ret, i;
|
||||
|
||||
gettimeofday(&tp, 0);
|
||||
b = ((unsigned)tp.tv_sec)*1000000+((unsigned)tp.tv_usec);
|
||||
t1 = get_tick_count();
|
||||
|
||||
printf ("waiting for data (use CTRL-C to cancel)...\n");
|
||||
while (1) {
|
||||
/* read data */
|
||||
ret = mISDN_read(di->device, buf, 1024, 0);
|
||||
ret = mISDN_read(di->device, buf, 2048, 0);
|
||||
if (ret >= mISDN_HEADER_LEN) {
|
||||
|
||||
switch(frm->prim) {
|
||||
|
@ -226,11 +254,9 @@ void main_data_loop(devinfo_t *di)
|
|||
}
|
||||
|
||||
/* write data */
|
||||
gettimeofday(&tp, 0);
|
||||
a = ((unsigned)tp.tv_sec)*1000000+((unsigned)tp.tv_usec);
|
||||
|
||||
if ((a-b)>1000000) {
|
||||
if ((get_tick_count()-t1) > TICKS_PER_SEC) {
|
||||
printf(".\n");
|
||||
|
||||
i=0;
|
||||
|
||||
/* send fake d-channel frame, here Tei request */
|
||||
|
@ -251,7 +277,7 @@ void main_data_loop(devinfo_t *di)
|
|||
di->unconfirmed++;
|
||||
}
|
||||
|
||||
b = a;
|
||||
t1 = get_tick_count();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -316,8 +342,10 @@ char *argv[];
|
|||
|
||||
set_signals();
|
||||
err = do_setup(&mISDN);
|
||||
if (err)
|
||||
if (err) {
|
||||
fprintf(stdout, "do_setup error %d\n", err);
|
||||
return(0);
|
||||
}
|
||||
|
||||
main_data_loop(&mISDN);
|
||||
|
||||
|
|
Loading…
Reference in New Issue