📄 app_sdp.c
字号:
/****************************************************************************
Copyright (C) Cambridge Silicon Radio Ltd. 2005-2006
Part of BlueLab 3.6.2-release
FILE NAME
app_sdp.c
DESCRIPTION
This file contains code to parse SDP records.
Values can be searched for by type and then set or read out.
*/
/****************************************************************************
Header files
*/
#include <stdlib.h>
#include "app_private.h"
#include "app_sdp.h"
#ifdef APP_DEBUG
#include <stdio.h>
#define MAIN_PRINT(x) printf x
#else
#define MAIN_PRINT(x)
#endif
/* Attribute numbers */
#define HID_DEVICE_RELEASE_NUMBER (0x200)
#define HID_PARSER_VERSION (0x201)
#define HID_VIRTUAL_CABLE (0x204)
#define HID_RECONNECT_INITIATE (0x205)
#define HID_NORMALLY_CONNECTABLE (0x20d)
#define HID_BOOT_DEVICE (0x20e)
#if 0 /* 惑侩窍瘤 臼澜 */
/*************************************************************************
NAME
appSdpAssemble
DESCRIPTION
Make a uint32 from 1,2,or 4 MSB bytes pointed to by data.
RETURNS
uint32 - Value pointer to by data.
*/
static uint32 appSdpAssemble(uint8 *data, uint8 size)
{
uint16 hi = 0, lo = data[0] & 0xff;
if (size >= 2)
{
lo = (lo << 8) + (data[1] & 0xff);
}
if (size >= 4)
{
hi = lo;
lo = ((data[2] & 0xff) <<8) + (data[3] & 0xFF);
}
return (((uint32)hi) << 16) + lo;
}
/*************************************************************************
NAME
appSdpGetDataInfo
DESCRIPTION
Return a pointer to the data section of this element, and fill in
the supplied dataSize parameter so that the data can be properly
read later on. Only used internally.
RETURNS
uint8 * Pointer to the data section of this element.
*/
static uint8 *appSdpGetDataInfo(uint8 *record, uint32 *data_size)
{
uint8 size = (*record) & 7;
uint8 descriptor = ((*record) >> 3) & 0x1f;
record++;
switch (size)
{
/* Simple size types... */
default:
case 0:
if (descriptor)
*data_size = 1;
else
*data_size = 0;
break;
case 1:
*data_size = 2;
break;
case 2:
*data_size = 4;
break;
case 3:
*data_size = 8;
break;
case 4:
*data_size = 16;
break;
/* Indirected size types */
case 5:
*data_size = appSdpAssemble(record, 1);
record += 1;
break;
case 6:
*data_size = appSdpAssemble(record, 2);
record += 2;
break;
case 7:
*data_size = appSdpAssemble(record, 4);
record += 4;
break;
}
/* Return pointer to start of data */
return record;
}
/*************************************************************************
NAME
appSdpGetData
DESCRIPTION
Returns the data contained in this element, given a pointer to the
start of the element.
RETURNS
uint32 - Value of data element.
*/
uint32 appSdpGetData(uint8 *record)
{
uint8 *data_ptr;
uint32 data_size;
if (record == NULL)
return 0;
data_ptr = appSdpGetDataInfo(record, &data_size);
return appSdpAssemble(data_ptr, (uint8)data_size);
}
/*************************************************************************
NAME
appSdpSkipElement
DESCRIPTION
Skip over this element entirely and return a pointer to the next
one.
RETURNS
uint8 * - Pointer to the next element.
*/
uint8 *appSdpSkipElement(uint8 *record)
{
uint32 data_size;
uint8 *data_ptr;
if (record == NULL)
return 0;
/* Get a pointer to the data, as well as the size of the data section. */
data_ptr = appSdpGetDataInfo(record, &data_size);
/* The next element comes after this elements data section.... */
return data_ptr + data_size ;
}
/*************************************************************************
NAME
appSdpFindElement
DESCRIPTION
Allows a search of an SDP record by element type. returns NULL if
the specified element type can't be found or a pointer to it.
RETURNS
uint8 * - Pointer to the found element.
*/
uint8 *appSdpFindElement(appSdpType desc, uint8 *record, uint8 *end_ptr)
{
uint32 dummy;
while (record < end_ptr)
{
uint8 descriptor = ((*record) >> 3) & 0x1f;
/* If this is the type we're looking for, return it now, otherwise
skip ahead to the next element */
if ((uint8)desc == descriptor)
return record;
/* Composite types (data elements) are just headers that group a
series of following elements. We need to ignore them. */
switch (descriptor)
{
/* Compostite types - ignore header */
case 6:
case 7:
record = appSdpGetDataInfo(record, &dummy);
break;
case 0:
++record;
break; /* do nothing */
/* Primitive types - skip over data section */
default:
record = appSdpSkipElement(record);
break;
}
}
/* Element not found */
return NULL;
}
/*************************************************************************
NAME
DESCRIPTION
RETURNS
BT DEV狼 SDP 漂己蔼 技泼窃
*/
appSdpResult appSdpHandleMandatory(appDeviceTaskData *theDevice, uint8 *ptr, uint8 *end_ptr)
{
uint8 attribute_count = 0;
do
{
uint32 attribute, result;
attribute = appSdpGetData(ptr);
ptr = appSdpSkipElement(ptr);
result = appSdpGetData(ptr);
ptr = appSdpSkipElement(ptr);
MAIN_PRINT(("Found attribute %lx, result %ld\n", attribute, result));
switch (attribute)
{
case HID_VIRTUAL_CABLE:
{
attribute_count |= (1 << 0);
theDevice->dev_info.hid_virtual_cable = result;
}
break;
case HID_RECONNECT_INITIATE:
{
attribute_count |= (1 << 1);
theDevice->dev_info.hid_reconnect_initiate = result;
}
break;
case HID_PARSER_VERSION:
{
attribute_count |= (1 << 2);
if ((result & 0xff00) != 0x100)
return appSdpWrongHidVersion;
}
break;
case HID_BOOT_DEVICE:
{
attribute_count |= (1 << 3);
if (result != 1)
return appSdpNotBootDevice;
}
break;
default:
break;
}
} while (ptr < end_ptr);
return (attribute_count == 0x0F) ? appSdpOk : appSdpMissingAttribute;
}
/*************************************************************************
NAME
DESCRIPTION
RETURNS
BT DEV狼 SDP 漂己蔼 技泼窃
*/
appSdpResult appSdpHandleOptional(appDeviceTaskData *theDevice, uint8 *ptr, uint8 *end_ptr)
{
do
{
uint32 attribute, result;
attribute = appSdpGetData(ptr);
ptr = appSdpSkipElement(ptr);
result = appSdpGetData(ptr);
ptr = appSdpSkipElement(ptr);
MAIN_PRINT(("Found attribute %lx, result %ld\n", attribute, result));
switch (attribute)
{
case HID_NORMALLY_CONNECTABLE:
{
theDevice->dev_info.hid_normally_connectable = result;
}
break;
default:
break;
}
} while (ptr < end_ptr);
return appSdpOk;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -