User's Manual

Enhanced Class 1 Bluetooth v2.1 Module
User’s Guide
Americas: +1-800-492-2320 Option 2
Europe: +44-1628-858-940
Hong Kong: +852-2923-0610
www.lairdtech.com/wireless
132
CONN-GUIDE-BT740_v0.2
12.2.5 Sample code to interpret a ScanReport logical packet
The following code shows how a logical ‘Scan Report’ packet could be separated into its constituent parts:
void PrintScanReport(unsigned char *pRxPkt, unsigned nRxPktLen)
{
char baMsg[512];
uint16 nHandle;
uint16 nPersonId;
uint16 nObject;
uint16 nAttrId;
uint16 nAttrLen;
uint8 *pSrc;
char *pMsg;
nHandle = (pRxPkt[3]<<8)+pRxPkt[4];
nPersonId = (pRxPkt[5]<<8)+pRxPkt[6];
printf(baMsg,"SCAN REPORT handle=%d personId=%d, reports=%d",
nHandle, nPersonId, pRxPkt[7]);
pSrc = &pRxPkt[8];
while(pSrc < &pRxPkt[nRxPktLen])
{
switch(*pSrc)
{
case HDP_SCANREPORT_INFOTYPE_OBJECT: /* 0x00 */
pSrc++;
if( pSrc >= &pRxPkt[nRxPktLen] )
{
printf("INSUFFICIENT LENGTH -- ABORT display of msg");
break;
}
nObject = (pSrc[0]<<8)+pSrc[1];
printf(" O:%d (%04X)",nObject,nObject);
pSrc+=2;
break;
case HDP_SCANREPORT_INFOTYPE_ATTRIBUTE: /* 0x01 */
pMsg = baMsg;
pSrc++;
nAttrId = (pSrc[0]<<8)+pSrc[1];
pSrc+=2;
nAttrLen = (pSrc[0]<<8)+pSrc[1];
pSrc+=2;
if( &pSrc[nAttrLen] > &pRxPkt[nRxPktLen] )