lapbInit()
PROTOTYPE
#include <lapb.h>
int lapbInit(void (*report)(uint chan, ui32 event), void (*parse)(ui8 *data));
DESCRIPTION
lapbInit() initializes TargetLAPB. It must be called before the other LAPB interface routines are used. report points to an optional callback function. If report is not 0, report() is called to report LAPB events to upper layer software. The list of supported events is defined in “lapb.h” and reproduced below:
/*
** Upper Layer Reports
*/
#define LAPB_N2_SABM 1 /* N2 unacknowledged SABMs sent */
#define LAPB_N2_DISC 2 /* N2 unacknowledged DISCs sent */
#define LAPB_N2_RNR 3 /* N2 consecutive RNRs received */
#define LAPB_PHYS_DISC 4 /* physical disconnect occurred */
#define LAPB_LINK_RESET 5 /* LAPB disconnect occurred */
#define LAPB_FRAME_REJ 6 /* entered frame reject state */
#define LAPB_CONNECT 7 /* LAPB connect occurred */
#define LAPB_ALL_ACKED 8 /* all I-frames have been acknowledged */
#define LAPB_DATA_IND 9 /* I-frame data has been received */
LAPB_LINK_RESET is not reported if a physical disconnect occurs. To detect all disconnects, both the LAPB_LINK_RESET and LAPB_PHYS_DISC reports should be monitored.
parse points to a second optional callback function. If LAPB protocol decoding is enabled (see Compile-Time Configuration in Using TargetLAPB), and parse is not 0, parse() is called during I-frame decoding with its parameter pointing to the first byte of I-frame data. This allows the LAPB protocol decoding to include user interpretations of the I-frame data.
If successful, lapbInit() returns 0. Otherwise, it sets errno and returns -1.
ERROR CODES
| Other | If unable to create the necessary semaphores, timer, or LAPB daemon task, the relevant RTOS error code is returned. |
EXAMPLE
/*-------------------------------------------------------------------*/
/* Initialize LAPB protocol stack. */
/*-------------------------------------------------------------------*/
rc = lapbInit(report, 0);
if (rc) error("lapbInit()", rc);
printf("LAPB protocol initialized...\n");