From d0cec1a401b3b8dbd5a35921b44597f03f46f262 Mon Sep 17 00:00:00 2001 From: Johannes Anderwald Date: Tue, 31 Jan 2012 19:00:45 +0000 Subject: [PATCH] [HIDPARSE] - Implement HidP_GetUsagesEx - HidP_GetUsagesEx uses HidP_GetUsages with undefined usage page - Required for hid usb support - Check if there is a maximum set. In that case verify if a usage maximum has been set and apply it to the currnt usage. Fixes asserts while usb composite device installation (keyboard) svn path=/branches/usb-bringup-trunk/; revision=55357 --- lib/drivers/hidparser/api.c | 65 ++++++++++++++++++++++++++-------- lib/drivers/hidparser/parser.c | 15 ++++---- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/lib/drivers/hidparser/api.c b/lib/drivers/hidparser/api.c index a3abc9ff698..25083955b86 100644 --- a/lib/drivers/hidparser/api.c +++ b/lib/drivers/hidparser/api.c @@ -345,6 +345,7 @@ HidParser_GetUsagesWithReport( PHID_REPORT_ITEM ReportItem; UCHAR Activated; ULONG Data; + PUSAGE_AND_PAGE UsageAndPage = NULL; // // get report @@ -366,6 +367,17 @@ HidParser_GetUsagesWithReport( return HIDPARSER_STATUS_INVALID_REPORT_LENGTH; } + // + // cast to usage and page + // + if (UsagePage == HID_USAGE_PAGE_UNDEFINED) + { + // + // the caller requested any set usages + // + UsageAndPage = (PUSAGE_AND_PAGE)UsageList; + } + for(Index = 0; Index < Report->ItemCount; Index++) { // @@ -384,17 +396,20 @@ HidParser_GetUsagesWithReport( // CurrentUsagePage = (ReportItem->UsageMinimum >> 16); - // - // does usage match - // - if (UsagePage != CurrentUsagePage) - continue; + if (UsagePage != HID_USAGE_PAGE_UNDEFINED) + { + // + // does usage match + // + if (UsagePage != CurrentUsagePage) + continue; + } // // check if the specified usage is activated // ASSERT(ReportItem->ByteOffset < ReportDescriptorLength); - ASSERT(ReportItem->BitCount < 8); + ASSERT(ReportItem->BitCount <= 8); // // one extra shift for skipping the prepended report id @@ -428,10 +443,21 @@ HidParser_GetUsagesWithReport( continue; } - // - // store item - // - UsageList[ItemCount] = (ReportItem->UsageMinimum & 0xFFFF); + if (UsagePage != HID_USAGE_PAGE_UNDEFINED) + { + // + // store item + // + UsageList[ItemCount] = (ReportItem->UsageMinimum & 0xFFFF); + } + else + { + // + // store usage and page + // + UsageAndPage[ItemCount].Usage = (ReportItem->UsageMinimum & 0xFFFF); + UsageAndPage[ItemCount].UsagePage = CurrentUsagePage; + } ItemCount++; } @@ -443,10 +469,21 @@ HidParser_GetUsagesWithReport( return HIDPARSER_STATUS_BUFFER_TOO_SMALL; } - // - // success, clear rest of array - // - Parser->Zero(&UsageList[ItemCount], (*UsageLength - ItemCount) * sizeof(USAGE)); + if (UsagePage == HID_USAGE_PAGE_UNDEFINED) + { + // + // success, clear rest of array + // + Parser->Zero(&UsageAndPage[ItemCount], (*UsageLength - ItemCount) * sizeof(USAGE_AND_PAGE)); + } + else + { + // + // success, clear rest of array + // + Parser->Zero(&UsageList[ItemCount], (*UsageLength - ItemCount) * sizeof(USAGE)); + } + // // store result size diff --git a/lib/drivers/hidparser/parser.c b/lib/drivers/hidparser/parser.c index 998bce4802e..0705788aa99 100644 --- a/lib/drivers/hidparser/parser.c +++ b/lib/drivers/hidparser/parser.c @@ -535,20 +535,21 @@ HidParser_InitReportItem( // get usage minimum from local state // UsageValue = LocalItemState->UsageMinimum; - ASSERT(LocalItemState->UsageMinimumSet); - ASSERT(LocalItemState->UsageMaximumSet); // // append item index // UsageValue.u.Extended += ReportItemIndex; - if (UsageValue.u.Extended > LocalItemState->UsageMaximum.u.Extended) + if (LocalItemState->UsageMaximumSet) { - // - // maximum reached - // - UsageValue.u.Extended = LocalItemState->UsageMaximum.u.Extended; + if (UsageValue.u.Extended > LocalItemState->UsageMaximum.u.Extended) + { + // + // maximum reached + // + UsageValue.u.Extended = LocalItemState->UsageMaximum.u.Extended; + } } }