# lapddemo structure and coding features

The main function (in lapddemo.c) accepts and parses the command line options, reads the configuration file, and establishes the data link. At this point, the program can either send a SETUP message to the trunk (if you type S) or wait for messages from the line.

Note: The SETUP message sent by lapddemo contains the following information elements only: bearer capability, channel ID, calling number, and called number. Some switch variants may require additional information elements.

If a Q.931 message is received, the program decodes information from the message, such as the protocol discriminator (for example, Q.931 CC), the call reference value, and the message type (for example, SETUP). It responds with an appropriate message, specified in the configuration file. For example, after receiving a SETUP message, it sends an ALERTING message.

The state machine takes into consideration only the state of the data link. There are only two states: idle and data link established. The program has no knowledge of the state of a call, so it can be configured to break Q.931 message protocol rules (for example, by sending a SETUP message after receiving a SETUP message). It is the user's responsibility to configure the program properly.

Q.931 messages are built using functions from isdnlib.c, for example, BuildSetup and BuildAlerting. lapdlib.h contains the prototypes for these functions and the definitions of the structures used by the functions. decisdn.h contains the defines used to build Q.931 information elements and messages.