在做一个蓝牙HID设备的时候,从机使用的SensorTile,主机使用的Android 5.0平板(内核3.4),在内核中的HID驱动和HID设备是通过VID PID匹配的,而这个SensorTile的VID PID一直是0x00, 0x00。为了快速验证,我把generic-usb
或者hid-multitouch
的hid_device_id
表中添加了如下代码以兜底这个VID PID均为0x00的蓝牙HID设备,经测试是可以顺利驱动的。
// for generic-usb
{ HID_BLUETOOTH_DEVICE(HID_ANY_ID, HID_ANY_ID) },
// for hid-multitouch
{ .driver_data = MT_CLS_DEFAULT, HID_BLUETOOTH_DEVICE(HID_ANY_ID,HID_ANY_ID) },
必经上面这种改法只是为了验证,最终这样改不合适,那么蓝牙设备的VID PID是在哪里设置的呢?我作了进一步追踪。
内核的上一级是uhid
,通过查看在external/bluetooth/bluedroid/btif/co/bta_hh_co.c
的bta_hh_co_send_hid_info
这里进入到uhid
的。
/*******************************************************************************
**
** Function bta_hh_co_send_hid_info
**
** Description This function is called in btif_hh.c to process DSCP received.
**
** Parameters dev_handle - device handle
** dscp_len - report descriptor length
** *p_dscp - report descriptor
**
** Returns void
*******************************************************************************/
void bta_hh_co_send_hid_info(btif_hh_device_t *p_dev, char *dev_name, UINT16 vendor_id,
UINT16 product_id, UINT16 version, UINT8 ctry_code,
int dscp_len, UINT8 *p_dscp)
{
...
APPL_TRACE_WARNING("%s: vendor_id = 0x%04x, product_id = 0x%04x, version= 0x%04x,"
"ctry_code=0x%02x",__FUNCTION__,
vendor_id, product_id,
version, ctry_code);
...
}
向上再追踪到了:
/*******************************************************************************
**
** Function SDP_GetDiRecord
**
** Description This function retrieves a remote device's DI record from
** the specified database.
**
** Returns SDP_SUCCESS if record retrieved, else error
**
*******************************************************************************/
UINT16 SDP_GetDiRecord( UINT8 get_record_index, tSDP_DI_GET_RECORD *p_device_info,
tSDP_DISCOVERY_DB *p_db )
{
...
p_curr_attr = SDP_FindAttributeInRec( p_curr_record, ATTR_ID_VENDOR_ID );
if ( p_curr_attr )
p_device_info->rec.vendor = p_curr_attr->attr_value.v.u16;
else
result = SDP_ERR_ATTR_NOT_PRESENT;
...
}
通过查看得知该函数是通过SDP
协议获取VENDOR_ID
的,在蓝牙协议官网上一查,还真就查到了:
SDP协议中的VendorId
来源:https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
那么现在就清楚了,蓝牙中也是有VID 和 PID,方便区别不同的厂商,这样主机系统驱动中就可以加以区分。需要具体到从机的SDP协议中查看一下。下回分解。
《完》