# Sending queries to MSPP filters

The MSPP service provides query commands to solicit configuration and operation data from MSPP filters. Queries (and commands) to endpoint and channel filters return filter status information in a buffer. The buffer must be released using mspReleaseBuffer. Applications can query endpoint filters at any time, but can only query channel filters when the channel is enabled.

To send a query to an endpoint or channel filter within a channel, the application can invoke mspSendQuery and specify:

- MSPP ephd or chnhd.

- Filter query produced by ORing a filter ID with a filter query ID.

To build a valid filter query, use the mspBuildQuery macro (defined in mspquery.h) to concatenate the filter ID with a filter query ID. mspBuildQuery is defined as follows:

/* Macro used to concatenate queries with filter definitions */
#define mspBuildQuery(filterid,queryid) ((filterid << 8) | query)

The MSPP service returns a filter-specific structure that provides information about the filter's configuration and status.

Note: In operating systems that use big endian byte order (for example, SPARC Solaris), the parameter structures must be converted from big endian to little endian (the byte order format used by the CG board) or vice versa. For information about macros provided to convert from big endian formatted structures to little endian format (and the reverse), refer to Converting command and query structure byte order.

## Example: Using mspSendQuery

The following code sample shows how to use mspSendQuery to query information about a jitter filter within a voice channel:

ret = mspSendQuery(chnhd,
mspBuildQuery( MSP_FILTER_JITTER, MSP_QRY_JITTER_GET_STATE ),
/* Call a routine to wait for this specific event */
WaitForSpecificEvent( hMsppVoiceChanCtaHd, ( MSPEVN_QUERY_DONE |
MSP_QRY_JITTER_GET_STATE ), &event );
if ( event.value != CTA_REASON_FINISHED )
{
printf("MSPP Send Command failed \n");
if ( event.value == CTAERR_OUT_OF_RESOURCES)
printf("Ran out of buffers probably forgot to release buffers back
to the service \n");
}
else
{
if ( event.size != 0 && event.buffer!= 0 )
/* Since = CTA_REASON_FINISHED should have a buffer, this code is */
/* just double checking that a buffer was returned. */
{/* Print out the parts of the structure that we are interested in */
pJitterStateBuf = (msp_FILTER_JITTER_STATE *)event.buffer;
printf("rx = %d\n",pJitterStateBuf->rx);
printf("rx_accept = %d\n",pJitterStateBuf->rx_accept);
printf("tx_valid = %d\n",pJitterStateBuf->tx_valid);
printf("Query Successful\n");
/* Now that we have data, free buffer back to the service */
ret = mspReleaseBuffer( hMsppVoiceChanCtaHd, event.buffer);
if ( ret != SUCCESS)
printf("Mspp release buffer failed...probably CTAERR_NOT_FOUND the
wrong address sent or it was released already \n");
}
}

The application frees the event buffer by calling mspReleaseBuffer and specifying the buffer address.

When applications invoke mspSendQuery, the MSPP service returns MSPEVN_QUERY_DONE. The lower byte of event.ID indicates the query ID, and the event.objHD indicates the endpoint or channel filter handle of the MSPP filter that performed the command. For example, if the application uses mspSendCommand to set jitter depth, then the MSPEVN_QUERY_DONE ID is 0x001B2201 (the event ID for MSPEVN_QUERY_DONE is 0x001B22 xx and the command ID for MSP_CMD_JITTER_CHG_DEPTH is 01).