home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
ctcoll95.zip
/
BASTELST
/
PAPI020.ZIP
/
API.C
next >
Wrap
C/C++ Source or Header
|
1993-10-06
|
7KB
|
423 lines
/* Common ISDN API C-Library Functions
Author: Dietmar Friede
Copyright (c) 1992 D.Friede
#include "copy"
#include "copying.doc"
*/
#define VERSION "0.18 21.09.1993"
#include "stdio.h"
#include <dos.h>
#include <ctype.h>
#include <mem.h>
#include "types.h"
#include "api.h"
#include "head.h"
word check_listen(void);
extern unsigned application;
static word messagenr= 0;
struct msg_head *getmsg(void);
word dirps(void);
void restore(word);
extern dword InfoMask;
static struct msg_head *
setmsghdnr(word msg_nr, word l, byte c, byte sc)
{
struct msg_head *m;
m=getmsg();
if(m)
{
m->length=l;
m->appl_id= application;
m->command= c;
m->subcommand= sc;
m->msg_nr=msg_nr;
}
return m;
}
static struct msg_head *
setmsghd(word l, byte c, byte sc)
{
messagenr++;
return(setmsghdnr(messagenr&0x7fff,l,c,sc));
}
static int
sendsimplenr(word msg_nr, byte c, byte sc, word w)
{
word *s;
struct msg_head *m;
if((m=getmsg())==null) return 1;
m->length= 10;
m->appl_id= application;
m->command= c;
m->subcommand= sc;
m->msg_nr=msg_nr;
s= (word *) m->data;
*s= w;
return api_put_message((byte far *)m);
}
static int
sendsimple(byte c, byte sc, word w)
{
messagenr++;
return(sendsimplenr(messagenr&0x7fff,c,sc,w));
}
int
con_req(byte contr, byte b_channel, dword inf_mask,
byte out_serv, byte out_serv_add, byte src_eaz,
byte * dest_addr)
{
dword *l;
struct msg_head *m;
if((m=setmsghd(18+dest_addr[0],2,0)) == null) return 1;
m->data[0]= contr;
m->data[1]= b_channel;
l= (dword *) &m->data[2];
*l= inf_mask;
m->data[6]= out_serv;
m->data[7]= out_serv_add;
m->data[8]= src_eaz;
memcpy(&m->data[9],dest_addr,dest_addr[0]+1);
return api_put_message((byte far *)m);
}
int
con_resp(word msg_nr,word plci, byte reject)
{
word *s;
struct msg_head *m;
if((m=setmsghdnr(msg_nr,11,2,3)) == null ) return 1;
s= (word *) m->data;
*s= plci;
m->data[2]= reject;
return api_put_message((byte far *)m);
}
int
con_act_resp(word msg_nr,word plci)
{
return(sendsimplenr(msg_nr,3,3,plci));
}
int
discon_req(word plci, byte cause)
{
word *s;
struct msg_head *m;
if((m=setmsghd(11,4,0)) == null) return 1;
s= (word *) m->data;
*s= plci;
m->data[2]= cause;
return api_put_message((byte far *)m);
}
int
discon_resp(word msg_nr,word plci)
{
return(sendsimplenr(msg_nr,4,3,plci));
}
word
listen_req(byte contr, dword inf_mask, word eaz_mask, word si_mask)
{
dword *l;
word *s;
struct msg_head *m;
if((m=setmsghd(17,5,0)) == null) return 1;
m->data[0]= contr;
l= (dword *) &m->data[1];
*l= inf_mask;
s= (word *) &m->data[5];
*s= eaz_mask;
s++;
*s= si_mask;
return api_put_message((byte far *)m);
}
int
inf_req(word plci, dword inf_mask)
{
word *s;
dword *l;
struct msg_head *m;
if((m=setmsghd(14,7,0))==null) return 1;
messagenr&=0x7fff;
s= (word *) m->data;
*s= plci;
l= (dword *) &m->data[2];
*l= inf_mask;
return api_put_message((byte far *)m);
}
int
inf_resp(word msg_nr,word plci)
{
return(sendsimplenr(msg_nr,7,3,plci));
}
int
con_inf_req(word plci,byte * dest_addr)
{
word *s;
struct msg_head *m;
if((m=setmsghd(11+dest_addr[0],9,0)) == null) return 1;
s= (word *) m->data;
*s= plci;
memcpy(&m->data[2],dest_addr,dest_addr[0]+1);
return api_put_message((byte far *)m);
}
int
sel_b2_prot_req(word plci, byte prot, byte * dlpd)
{
word *s;
struct msg_head *m;
if((m=setmsghd(12+dlpd[0],0x40,0)) == null) return 1;
s= (word *) m->data;
*s= plci;
m->data[2]= prot;
memcpy(&m->data[3],dlpd,8);
return api_put_message((byte far *)m);
}
int
sel_b3_prot_req(word plci, byte prot, byte * ncpd)
{
word *s;
struct msg_head *m;
if((m=setmsghd(12+ncpd[0],0x80,0)) == null) return 1;
s= (word *) m->data;
*s= plci;
m->data[2]= prot;
memcpy(&m->data[3],ncpd,ncpd[0]+1);
return api_put_message((byte far *)m);
}
int
listen_b3_req(word plci)
{
return(sendsimple(0x81,0,plci));
}
int
con_b3_req(word plci, byte *ncpi)
{
word *s;
struct msg_head *m;
if((m=setmsghd(11+ncpi[0],0x82,0)) == null ) return 1;
s= (word *) m->data;
*s= plci;
memcpy(&m->data[2],ncpi,ncpi[0]+1);
return api_put_message((byte far *)m);
}
int
con_b3_resp(word msg_nr,word ncci, byte reject, byte *ncpi)
{
word *s;
struct msg_head *m;
if((m= setmsghdnr(msg_nr,12+ncpi[0],0x82,3)) == null) return 1;
s= (word *) m->data;
*s= ncci;
m->data[2]= reject;
memcpy(&m->data[3],ncpi,ncpi[0]+1);
return api_put_message((byte far *)m);
}
int
con_b3_act_resp(word msg_nr,word ncci)
{
return(sendsimplenr(msg_nr,0x83,3,ncci));
}
int
discon_b3_req(word ncci, byte * ncpi)
{
word *s;
struct msg_head *m;
if((m=setmsghd(11+ncpi[0],0x84,0)) == null) return 1;
s= (word *) m->data;
*s= ncci;
memcpy(&m->data[2],ncpi,ncpi[0]+1);
return api_put_message((byte far *)m);
}
int
discon_b3_resp(word msg_nr,word ncci)
{
return(sendsimplenr(msg_nr,0x84,3,ncci));
}
int
get_b3_par_req(word ncci)
{
return(sendsimple(0x85,0,ncci));
}
int
dat_b3_req(word ncci, word dat_length, dword data, byte number, word flags)
{
dword *l;
word *s;
struct msg_head *m;
if((m=setmsghd(19,0x86,0)) == null) return 1;
s= (word *) &m->data[0];
*s= ncci;
s++;
*s= dat_length;
l= (dword *) &m->data[4];
*l= data;
m->data[8]=number;
s= (word *) &m->data[9];
*s= flags;
return api_put_message((byte far *)m);
}
int
dat_b3_resp(word msg_nr,word ncci, byte number)
{
word *s;
struct msg_head *m;
if((m=setmsghdnr(msg_nr,11,0x86,3)) == null) return 1;
s= (word *) m->data;
*s= ncci;
m->data[2]= number;
return api_put_message((byte far *)m);
}
static byte far text[64];
static byte far messages[0x4000];
extern InterruptPtr SaveTimerInt;
extern byte own_eaz;
void interrupt timevec(void);
int
api_init (word bsize, word verbose)
{
word err;
word maxblock, nmesg;
dword msize;
if(api_check()) return 1;
if(verbose)
{
printf("ISDN Card:\n");
api_get_manufacturer(text);
printf("Manufacturer: %s\n",text);
api_get_version(text);
printf("%s\n",text);
api_get_serial(text);
if( text[0] )
printf("Serial: %s\n",text);
}
msize= sizeof(messages)-(2*180);
maxblock= (word) (msize/bsize);
if(maxblock < 2)
{
printf("Message Memory too small to register\n");
return 1;
}
msize= maxblock*bsize;
nmesg= (word) ((sizeof(messages)-msize)/180);
if(verbose)
{
printf("register no mesg %d 1 conn. no buffs %d buffsize %d\n",
nmesg,maxblock,bsize);
}
if(api_register(messages,nmesg,1,maxblock,bsize) == 0)
{
printf("cannot register\n");
return 1;
}
err= api_set_signal(apivec);
if(err)
{
printf("cannot set signal\n");
return 1;
}
err= listen_req((byte)0,InfoMask,(word)(1 << own_eaz),(word)0x80);
if(err)
{
printf("Cannot listen %x\n",err);
api_set_signal((long)0);
return 1;
}
err= dirps();
SaveTimerInt = getvect(8);
setvect(8,timevec);
restore(err);
if(check_listen())
{
printf("Cannot Listen\n");
api_set_signal((long)0);
setvect(8,SaveTimerInt);
return 1;
}
return 0;
}
void
api_stop(void)
{
word err;
setvect(8,SaveTimerInt);
if(api_set_signal((long) 0)) printf("cannot reset signal\n");
err= api_release();
if(err) printf("release err %x\n",err);
}