This chapter:
An AG ISDN Messaging API application typically performs the following tasks:

Figure 9: AG ISDN Messaging API Application Flowchart
You must initialize and load DSP files, Trunk Control Programs (TCPs) and protocol stack runfiles to your AG board(s) before you can run an AG ISDN application. The items to load to the boards are specified in an AG configuration file (ag.cfg). To load the components to your AG boards, run agmon, the AG board initialization and monitoring utility. agmon reads the AG configuration file and sets up your boards as described in the file. To learn how to create an AG configuration file for your setup, see the AG ISDN Installation Manual, the installation manual for your AG board, and the AG Runtime Configuration and Developer's Manual.
Keep agmon running on the system to monitor your AG boards and report errors.
To initialize, an AG ISDN Messaging API application does the following:
A trunk is referred to by its network access identifier (NAI). When you initialize an ISDN protocol stack instance for a CTA context (using isdnStartProtocol), you specify the NAI of the trunk to associate with the CTA context. From then on, the application can communicate with the D channel on that trunk via the CTA context handle. For example, when an event is received, the CTA context handle indicates the trunk on which the event occurred.
Different board types support differing numbers of D channels, with different NAI numbers.
The table below shows what each AG board type supports:
|
Board Type |
Number of D Channels |
NAIs |
|
Up to 4 |
0 through 3 | |
|
Up to 4 |
0 through 3 | |
|
Up to 2 |
0 through 1 | |
|
1 |
0 |
For more information, see Section 4.4, Accessing D Channels.
The connection id is a handle to a call on a B channel. It is used to identify the call in all communications between the ACU and the application. The id is a number between 0 and 39.
When an incoming call arrives, the protocol stack assigns it a connection id. The connection id assigned is the highest unused value starting with 39. For example, if connection ids 39 and 38 are already allocated to calls, the protocol stack assigns id 37 to the next call.
When the application places a call, it assigns a connection id to the call. To avoid any chance of collision, the application should use connection ids beginning with 0. The application must keep track of which connection ids are in use and which are available. (The demonstration program documented in Chapter 9 illustrates this.)
When a call is disconnected, the connection id is freed. The id can then be assigned to a new call by the protocol stack or the application.
A different set of connection ids (numbered 0 through 39) is available for each D channel. Thus a call is identified both by its D channel context and by its connection id.
To send a message to the ACU, the application does the following:
Figure 10 illustrates the content and meaning of each of the arguments sent in an isdnSendMessage function call:

Figure 10: isdnSendMessage Data Structures
All messages and events are presented to the application through the standard CT Access/AG Access event handling mechanism. The events returned can be standard CT access or AG Access events, events sent by an ISDN protocol stack instance, or events specific to any AG Access or CT Access extensions. They arrive in the form of the standard CTA (or ADI) event data structure:
typedef struct CTA_EVENT
{
DWORD id; /* event id (LIBEVN_xxx in `libdef.h') */
CTAHD ctahd; /* CTA context handle */
DWORD timestamp;/* timestamp */
DWORD userid; /* user-supplied ID */
DWORD size; /* size of buffer if buffer is not NULL */
void *buffer; /* buffer pointer */
DWORD value; /* Event status or reason or other data */
DWORD reserved; /* must be 0 */
} CTA_EVENT;
The CTA_EVENT or ADI_EVENT structure informs the application which event occurred on which CTA context, and provides additional information specific to the event. The event's prefix relates the event to a specific Natural MicroSystems library of functions, as shown in the following table:
|
This prefix... |
Indicates... |
|
CTAEVN |
A CT Access event. |
|
ADIEVN |
An AG Access or ADI service event. |
|
ISDNEVN |
An AG ISDN event. |
The CTA_EVENT or ADI_EVENT structure contains the following fields:
CT Access and AG Access applications receive these events in different ways, as follows:
When an ISDN ACU message is received, an ISDNEVN_RCV_MESSAGE event occurs.
buffer in the CT Access or AG Access structure is a pointer to an ISDN_PACKET structure. This structure contains:
Figure 11 illustrates the structure of this message packet:

Figure 11: Receiving ACU Messages
After receiving and processing the data within the CTA_EVENT event buffer, the application must use isdnReleaseBuffer to free the buffer as quickly as possible. Otherwise, the ISDN interface will time out and stop passing events to the application. For more information about isdnReleaseBuffer, see Chapter 7.
The following code fragment illustrates how the application should process an incoming ISDN ACU event from the on-board protocol stack via the CT Access event mechanism:
cta_ret = ctaWaitEvent(ctaqueuehd, &cta_event, CTA_WAIT_FOREVER);
if (cta_ret != SUCCESS)
{
printf("isdnproc: ctaWaitEvent failure %d %x\n",
cta_ret, cta_ret);
continue;
}
/* we have an event -- switch on the type */
switch (cta_event.id)
{
.
.
.
case ISDNEVN_RCV_MESSAGE:
/* pick up the ISDN_PACKET structure */
isdnpkt = (ISDN_PACKET *)adi_event.buffer;
isdnmsg = (ISDN_MESSAGE *)&isdnpkt->message;
/* extract information from the ISDN incoming packet */
message = isdnmsg->code;
sender = isdnmsg->from_ent;
recipient = isdnmsg->to_ent;
CRN = isdnmsg->add.conn_id;
To stop an ISDN protocol stack instance, call isdnStopProtocol from within the application. This shuts down the ISDN protocol stack instance, and releases all on-board resources and buffers formerly used by the protocol stack instance.
The ISDNEVN_STOP_PROTOCOL event contains the completion status of the stop request. If the stack instance stopped successfully, the value field in this event contains SUCCESS. Otherwise, another reason code appears here.
For more information about isdnStopProtocol, see Chapter 7.
Natural MicroSystems, Inc.
100 Crossing Boulevard
Framingham, MA 01702