CAPI 2.0 for passive telephony devices

Hans Petter Selasky hselasky at c2i.net
Thu Jul 7 12:18:58 GMT 2005


On Wednesday 06 July 2005 19:27, Steven Looman wrote:
> On Tue, Jul 05, 2005 at 10:10:32PM +0200, Hans Petter Selasky wrote:
> > Hi,
>
> Hi,
>
> > I'm almost finished integrating CAPI2.0 into I4B. The CAPI interface will
> > have some limitations like that it only supports HDLC and transparent
> > mode. No X.75 and no FAX/Modem yet.
>
> Great!
>
> > I have put CAPI2.0 support into /sys/dev/i4b/layer4/i4b_capidrv.c
> > And it's only 3000 lines long.
> >
> > All CAPI structures will now be defined using a new macro
> > "CAPI_MAKE_STRUCT()". Here is an example showing how to use it:
> >
> > #define CH(m)\
> >     m(WORD, wLength,)\
> >     m(WORD, wApp,)\
> >     m(WORD, wCmd,)\
> >     m(WORD, wNum,)\
> >     m(DWORD, dwCid,)\
> >     m(QWORD, qwTest,)\
> >     m(STRUCT, sTest,)\
> >     m(BYTE_ARRAY, sArray, [20])\
> >
> > CAPI_MAKE_STRUCT(CH);
> >
> > If one tries to use CAPI_INIT() on the wrong structure it will cause a
> > compilation error!
>
> Eh.. sure, what does it do exactly and why do we need this? I don't think
> the error checking isn't that usefull either.

We need this to be able to parse CAPI packets. The problem is that not all 
elements have a constant size. Else one could just have defined a simple 
"struct { } __packed XXX;" for each packet type. For example "STRUCT" can 
have a size from 0 to 65535 bytes.

So if a packet looks like this:

#define XXX(m) \
m(STRUCT, s0) \
m(STRUCT, s1) \
m(WORD, wFlag)

and you want to access "wFlag" one cannot do this by a simple offset into the 
packet, but first have to decode the length of struct "s0" then "s1" and then 
one is able to read "wFlag". And then the packet can be too short, and in 
that case "wFlag" should have a value of zero.

So to make decoding easy for the applications, they are supposed to use some 
predefined *DECODED structures, but can also make its own using 
CAPI_MAKE_STRUCT(), combined with CAPI_INIT() and either capi_encode() or 
capi_decode() to translate a packet forth or back.

Else one ends up with people writing applications that make assumptions about 
packets, and when those assumptions are not met, the decoding/encoding will 
fail, even though the packet is CAPI 2.0 compliant. So I've tried to make the 
packet translation process as simple and safe as possible.

By using these macros it is easy to update the system later. Simply by adding 
a line to a macro, all generated structures and tables related to 
encoding/decoding of CAPI packets are updated.

> Can you show any sources? Just showing this isn't that clear to me.

Ok, I just took my working copy (the header file is not finished) an put it 
at:

http://home.c2i.net/hselasky/isdn4bsd/capi/capi20.h.bz2
http://home.c2i.net/hselasky/isdn4bsd/capi/i4b_capidrv.c.bz2

--HPS


More information about the freebsd-isdn mailing list