From 8c02b36fe168ebceb75bd666774d303a701e5ba9 Mon Sep 17 00:00:00 2001 From: cdfrey Date: Sat, 18 Aug 2007 05:11:00 +0000 Subject: [PATCH] - added code in probe.cc to fetch the device's description. The description is now part of the probe results along with the PIN. Updates to protocol.h, adding a new attribute definition. Thanks to Rick Scott for pointing out the code in XmBlackberry where he implemented this first. --- src/probe.cc | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- src/probe.h | 5 ++++- src/protocol.h | 1 + 3 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/probe.cc b/src/probe.cc index 35b1961f..5f52176e 100644 --- a/src/probe.cc +++ b/src/probe.cc @@ -29,6 +29,8 @@ #include "packet.h" #include "socket.h" #include "protocol.h" +#include "record-internal.h" +#include "strnlen.h" #include using namespace Usb; @@ -68,14 +70,13 @@ namespace { } // anonymous namespace -bool Probe::Parse(const Data &data, ProbeResult &result) +bool Probe::CheckSize(const Data &data, unsigned int required) { - // validate response data const unsigned char *pd = data.GetData(); if( GetSize(pd) != (unsigned int) data.GetSize() || - data.GetSize() < 0x14 || - pd[4] != 0x06 ) + data.GetSize() < required || + pd[4] != SB_COMMAND_FETCHED_ATTRIBUTE ) { dout("Probe: Parse data failure: GetSize(pd): " << GetSize(pd) << ", data.GetSize(): " << data.GetSize() @@ -83,12 +84,36 @@ bool Probe::Parse(const Data &data, ProbeResult &result) return false; } + return true; +} + +bool Probe::ParsePIN(const Data &data, ProbeResult &result) +{ + // validate response data + const unsigned char *pd = data.GetData(); + + if( !CheckSize(data, 0x14) ) + return false; + // capture the PIN result.m_pin = btohl(*((uint32_t *) &pd[16])); return true; } +bool Probe::ParseDesc(const Data &data, ProbeResult &result) +{ + if( !CheckSize(data, 29) ) + return false; + + // capture the description + const char *desc = (const char*) &data.GetData()[28]; + int maxlen = data.GetSize() - 28; + result.m_description.assign(desc, strnlen(desc, maxlen)); + + return true; +} + Probe::Probe() { Usb::DeviceIDType devid; @@ -192,12 +217,26 @@ void Probe::ProbeDevice(Usb::DeviceIDType devid) socket.Send(packet); if( packet.ObjectID() != SB_OBJECT_PROFILE || packet.AttributeID() != SB_ATTR_PROFILE_PIN || - !Parse(receive, result) ) + !ParsePIN(receive, result) ) { dout("Probe: unable to fetch PIN"); continue; } + // fetch Description + packet.GetAttribute(SB_OBJECT_PROFILE, SB_ATTR_PROFILE_DESC); + socket.Send(packet); + // response ObjectID does not match request... :-/ + if( // packet.ObjectID() != SB_OBJECT_PROFILE || + packet.AttributeID() != SB_ATTR_PROFILE_DESC || + !ParseDesc(receive, result) ) + { + dout("Probe: unable to fetch description"); + // this is a relatively new feature, so don't + // fail here... just blank the description + result.m_description.clear(); + } + // more unknowns: for( uint16_t attr = 5; attr < 9; attr++ ) { packet.GetAttribute(SB_OBJECT_SOCKET_UNKNOWN, attr); @@ -242,8 +281,9 @@ int Probe::FindActive(uint32_t pin) const std::ostream& operator<< (std::ostream &os, const ProbeResult &pr) { - os << "Device ID: " << pr.m_dev << std::setbase(16) << ". PIN: " - << pr.m_pin; + os << "Device ID: " << pr.m_dev + << std::hex << ". PIN: " << pr.m_pin + << ", Description: " << pr.m_description; return os; } diff --git a/src/probe.h b/src/probe.h index 07ea29a0..922438d5 100644 --- a/src/probe.h +++ b/src/probe.h @@ -36,6 +36,7 @@ struct ProbeResult uint32_t m_pin; Usb::EndpointPair m_ep; uint8_t m_zeroSocketSequence; + std::string m_description; }; std::ostream& operator<< (std::ostream &os, const ProbeResult &pr); @@ -45,7 +46,9 @@ class Probe { std::vector m_results; - bool Parse(const Data &data, ProbeResult &result); + bool CheckSize(const Data &data, unsigned int required); + bool ParsePIN(const Data &data, ProbeResult &result); + bool ParseDesc(const Data &data, ProbeResult &result); protected: void ProbeDevice(Usb::DeviceIDType devid); diff --git a/src/protocol.h b/src/protocol.h index 163bb9e9..ec66e7fe 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -49,6 +49,7 @@ #define SB_OBJECT_INITIAL_UNKNOWN 0x14 #define SB_ATTR_INITIAL_UNKNOWN 0x01 #define SB_OBJECT_PROFILE 0x08 +#define SB_ATTR_PROFILE_DESC 0x02 #define SB_ATTR_PROFILE_PIN 0x04 #define SB_OBJECT_SOCKET_UNKNOWN 0x04 -- 2.11.4.GIT