2012-01-04 21:58:18 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS HID Parser Library
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: lib/drivers/hidparser/parser.c
|
|
|
|
* PURPOSE: HID Parser
|
|
|
|
* PROGRAMMERS:
|
|
|
|
* Michael Martin (michael.martin@reactos.org)
|
|
|
|
* Johannes Anderwald (johannes.anderwald@reactos.org)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "parser.h"
|
|
|
|
|
2014-01-03 10:28:56 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-01-04 21:58:18 +00:00
|
|
|
static UCHAR ItemSize[4] = { 0, 1, 2, 4 };
|
|
|
|
|
|
|
|
VOID
|
|
|
|
HidParser_DeleteReport(
|
|
|
|
IN PHID_REPORT Report)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// not implemented
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
HidParser_FreeCollection(
|
|
|
|
IN PHID_COLLECTION Collection)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// not implemented
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_AllocateCollection(
|
|
|
|
IN PHID_COLLECTION ParentCollection,
|
|
|
|
IN UCHAR Type,
|
|
|
|
IN PLOCAL_ITEM_STATE LocalItemState,
|
|
|
|
OUT PHID_COLLECTION * OutCollection)
|
|
|
|
{
|
|
|
|
PHID_COLLECTION Collection;
|
|
|
|
USAGE_VALUE UsageValue;
|
|
|
|
|
|
|
|
//
|
|
|
|
// first allocate the collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Collection = (PHID_COLLECTION)AllocFunction(sizeof(HID_COLLECTION));
|
2012-01-04 21:58:18 +00:00
|
|
|
if (!Collection)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// init collection
|
|
|
|
//
|
|
|
|
Collection->Root = ParentCollection;
|
|
|
|
Collection->Type = Type;
|
|
|
|
Collection->StringID = LocalItemState->StringIndex;
|
|
|
|
Collection->PhysicalID = LocalItemState->DesignatorIndex;
|
|
|
|
|
|
|
|
//
|
|
|
|
// set Usage
|
|
|
|
//
|
|
|
|
ASSERT(LocalItemState);
|
|
|
|
ASSERT(LocalItemState->UsageStack);
|
|
|
|
|
|
|
|
if (LocalItemState->UsageStackUsed > 0)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// usage value from first local stack item
|
|
|
|
//
|
|
|
|
UsageValue.u.Extended = LocalItemState->UsageStack[0].u.Extended;
|
|
|
|
}
|
|
|
|
else if (LocalItemState->UsageMinimumSet)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// use value from minimum
|
|
|
|
//
|
|
|
|
UsageValue.u.Extended = LocalItemState->UsageMinimum.u.Extended;
|
|
|
|
}
|
|
|
|
else if (LocalItemState->UsageMaximumSet)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// use value from maximum
|
|
|
|
//
|
|
|
|
UsageValue.u.Extended = LocalItemState->UsageMaximum.u.Extended;
|
|
|
|
}
|
|
|
|
else if (Type == COLLECTION_LOGICAL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// root collection
|
|
|
|
//
|
|
|
|
UsageValue.u.Extended = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no usage set
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("HIDPARSE] No usage set\n");
|
2012-01-04 21:58:18 +00:00
|
|
|
UsageValue.u.Extended = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// store usage
|
|
|
|
//
|
|
|
|
Collection->Usage = UsageValue.u.Extended;
|
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
|
|
|
*OutCollection = Collection;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_AddCollection(
|
|
|
|
IN PHID_COLLECTION CurrentCollection,
|
|
|
|
IN PHID_COLLECTION NewCollection)
|
|
|
|
{
|
|
|
|
PHID_COLLECTION * NewAllocCollection;
|
|
|
|
ULONG CollectionCount;
|
|
|
|
|
|
|
|
//
|
|
|
|
// increment collection array
|
|
|
|
//
|
|
|
|
CollectionCount = CurrentCollection->NodeCount + 1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate new collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
NewAllocCollection = (PHID_COLLECTION*)AllocFunction(sizeof(PHID_COLLECTION) * CollectionCount);
|
2012-01-04 21:58:18 +00:00
|
|
|
if (!NewAllocCollection)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrentCollection->NodeCount)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// copy old array
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
CopyFunction(NewAllocCollection, CurrentCollection->Nodes, CurrentCollection->NodeCount * sizeof(PHID_COLLECTION));
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// delete old array
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(CurrentCollection->Nodes);
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// insert new item
|
|
|
|
//
|
|
|
|
NewAllocCollection[CurrentCollection->NodeCount] = (struct __HID_COLLECTION__*)NewCollection;
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// store new array
|
|
|
|
//
|
|
|
|
CurrentCollection->Nodes = NewAllocCollection;
|
|
|
|
CurrentCollection->NodeCount++;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-30 19:29:26 +00:00
|
|
|
HidParser_FindReportInCollection(
|
|
|
|
IN PHID_COLLECTION Collection,
|
2012-01-04 21:58:18 +00:00
|
|
|
IN UCHAR ReportType,
|
|
|
|
IN UCHAR ReportID,
|
|
|
|
OUT PHID_REPORT *OutReport)
|
|
|
|
{
|
|
|
|
ULONG Index;
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS Status;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
2012-01-30 19:29:26 +00:00
|
|
|
// search in local list
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-30 19:29:26 +00:00
|
|
|
for(Index = 0; Index < Collection->ReportCount; Index++)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
2012-01-30 19:29:26 +00:00
|
|
|
if (Collection->Reports[Index]->Type == ReportType && Collection->Reports[Index]->ReportID == ReportID)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// found report
|
|
|
|
//
|
2012-01-30 19:29:26 +00:00
|
|
|
*OutReport = Collection->Reports[Index];
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-30 19:29:26 +00:00
|
|
|
//
|
|
|
|
// search in sub collections
|
|
|
|
//
|
|
|
|
for(Index = 0; Index < Collection->NodeCount; Index++)
|
|
|
|
{
|
|
|
|
Status = HidParser_FindReportInCollection(Collection->Nodes[Index], ReportType, ReportID, OutReport);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status == HIDP_STATUS_SUCCESS)
|
2012-01-30 19:29:26 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
|
|
|
// no such report found
|
|
|
|
//
|
|
|
|
*OutReport = NULL;
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_REPORT_DOES_NOT_EXIST;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 19:29:26 +00:00
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-30 19:29:26 +00:00
|
|
|
HidParser_FindReport(
|
2012-01-31 16:19:33 +00:00
|
|
|
IN PHID_PARSER_CONTEXT ParserContext,
|
2012-01-30 19:29:26 +00:00
|
|
|
IN UCHAR ReportType,
|
|
|
|
IN UCHAR ReportID,
|
|
|
|
OUT PHID_REPORT *OutReport)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// search in current top level collection
|
|
|
|
//
|
|
|
|
return HidParser_FindReportInCollection(ParserContext->RootCollection->Nodes[ParserContext->RootCollection->NodeCount-1], ReportType, ReportID, OutReport);
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_AllocateReport(
|
|
|
|
IN UCHAR ReportType,
|
|
|
|
IN UCHAR ReportID,
|
|
|
|
OUT PHID_REPORT *OutReport)
|
|
|
|
{
|
|
|
|
PHID_REPORT Report;
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate report
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Report = (PHID_REPORT)AllocFunction(sizeof(HID_REPORT));
|
2012-01-04 21:58:18 +00:00
|
|
|
if (!Report)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// init report
|
|
|
|
//
|
|
|
|
Report->ReportID = ReportID;
|
|
|
|
Report->Type = ReportType;
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
*OutReport = Report;
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-30 19:29:26 +00:00
|
|
|
HidParser_AddReportToCollection(
|
2012-01-31 16:19:33 +00:00
|
|
|
IN PHID_PARSER_CONTEXT ParserContext,
|
2012-01-30 19:29:26 +00:00
|
|
|
IN PHID_COLLECTION CurrentCollection,
|
2012-01-04 21:58:18 +00:00
|
|
|
IN PHID_REPORT NewReport)
|
|
|
|
{
|
|
|
|
PHID_REPORT * NewReportArray;
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate new report array
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
NewReportArray = (PHID_REPORT*)AllocFunction(sizeof(PHID_REPORT) * (CurrentCollection->ReportCount + 1));
|
2012-01-04 21:58:18 +00:00
|
|
|
if (!NewReportArray)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-30 19:29:26 +00:00
|
|
|
if (CurrentCollection->ReportCount)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// copy old array contents
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
CopyFunction(NewReportArray, CurrentCollection->Reports, sizeof(PHID_REPORT) * CurrentCollection->ReportCount);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// free old array
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(CurrentCollection->Reports);
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
2012-01-30 19:29:26 +00:00
|
|
|
NewReportArray[CurrentCollection->ReportCount] = NewReport;
|
|
|
|
CurrentCollection->Reports = NewReportArray;
|
|
|
|
CurrentCollection->ReportCount++;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// completed successfully
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_GetReport(
|
2012-01-31 16:19:33 +00:00
|
|
|
IN PHID_PARSER_CONTEXT ParserContext,
|
2012-01-30 19:29:26 +00:00
|
|
|
IN PHID_COLLECTION Collection,
|
2012-01-04 21:58:18 +00:00
|
|
|
IN UCHAR ReportType,
|
|
|
|
IN UCHAR ReportID,
|
|
|
|
IN UCHAR CreateIfNotExists,
|
|
|
|
OUT PHID_REPORT *OutReport)
|
|
|
|
{
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS Status;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// try finding existing report
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_FindReport(ParserContext, ReportType, ReportID, OutReport);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status == HIDP_STATUS_SUCCESS || CreateIfNotExists == FALSE)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// founed report
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate new report
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_AllocateReport(ReportType, ReportID, OutReport);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status != HIDP_STATUS_SUCCESS)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to allocate report
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// add report
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_AddReportToCollection(ParserContext, Collection, *OutReport);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status != HIDP_STATUS_SUCCESS)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to allocate report
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(*OutReport);
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_ReserveReportItems(
|
|
|
|
IN PHID_REPORT Report,
|
2012-01-31 16:19:33 +00:00
|
|
|
IN ULONG ReportCount,
|
|
|
|
OUT PHID_REPORT *OutReport)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
2012-01-31 16:19:33 +00:00
|
|
|
PHID_REPORT NewReport;
|
|
|
|
ULONG OldSize, Size;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
if (Report->ItemCount + ReportCount <= Report->ItemAllocated)
|
|
|
|
{
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// space is already allocated
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
*OutReport = Report;
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
//calculate new size
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
OldSize = sizeof(HID_REPORT) + (Report->ItemCount) * sizeof(HID_REPORT_ITEM);
|
|
|
|
Size = ReportCount * sizeof(HID_REPORT_ITEM);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// allocate memory
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
NewReport = (PHID_REPORT)AllocFunction(Size + OldSize);
|
2012-01-31 16:19:33 +00:00
|
|
|
if (!NewReport)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// copy old report
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
CopyFunction(NewReport, Report, OldSize);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// increase array size
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
NewReport->ItemAllocated += ReportCount;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// store result
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
*OutReport = NewReport;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// completed sucessfully
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
HidParser_SignRange(
|
|
|
|
IN ULONG Minimum,
|
|
|
|
IN ULONG Maximum,
|
|
|
|
OUT PULONG NewMinimum,
|
|
|
|
OUT PULONG NewMaximum)
|
|
|
|
{
|
|
|
|
ULONG Mask = 0x80000000;
|
|
|
|
ULONG Index;
|
|
|
|
|
|
|
|
for (Index = 0; Index < 4; Index++)
|
|
|
|
{
|
|
|
|
if (Minimum & Mask)
|
|
|
|
{
|
|
|
|
Minimum |= Mask;
|
|
|
|
if (Maximum & Mask)
|
|
|
|
Maximum |= Mask;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mask >>= 8;
|
|
|
|
Mask |= 0xff000000;
|
|
|
|
}
|
|
|
|
|
|
|
|
*NewMinimum = Minimum;
|
|
|
|
*NewMaximum = Maximum;
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_InitReportItem(
|
|
|
|
IN PHID_REPORT Report,
|
|
|
|
IN PHID_REPORT_ITEM ReportItem,
|
|
|
|
IN PGLOBAL_ITEM_STATE GlobalItemState,
|
|
|
|
IN PLOCAL_ITEM_STATE LocalItemState,
|
|
|
|
IN PMAIN_ITEM_DATA ItemData,
|
|
|
|
IN ULONG ReportItemIndex)
|
|
|
|
{
|
|
|
|
ULONG LogicalMinimum;
|
|
|
|
ULONG LogicalMaximum;
|
|
|
|
ULONG PhysicalMinimum;
|
|
|
|
ULONG PhysicalMaximum;
|
|
|
|
ULONG UsageMinimum;
|
|
|
|
ULONG UsageMaximum;
|
|
|
|
USAGE_VALUE UsageValue;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get logical bounds
|
|
|
|
//
|
|
|
|
LogicalMinimum = GlobalItemState->LogicalMinimum;
|
|
|
|
LogicalMaximum = GlobalItemState->LogicialMaximum;
|
|
|
|
if (LogicalMinimum > LogicalMaximum)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// make them signed
|
|
|
|
//
|
|
|
|
HidParser_SignRange(LogicalMinimum, LogicalMaximum, &LogicalMinimum, &LogicalMaximum);
|
|
|
|
}
|
|
|
|
//ASSERT(LogicalMinimum <= LogicalMaximum);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get physical bounds
|
|
|
|
//
|
|
|
|
PhysicalMinimum = GlobalItemState->PhysicalMinimum;
|
|
|
|
PhysicalMaximum = GlobalItemState->PhysicalMaximum;
|
|
|
|
if (PhysicalMinimum > PhysicalMaximum)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// make them signed
|
|
|
|
//
|
|
|
|
HidParser_SignRange(PhysicalMinimum, PhysicalMaximum, &PhysicalMinimum, &PhysicalMaximum);
|
|
|
|
}
|
|
|
|
//ASSERT(PhysicalMinimum <= PhysicalMaximum);
|
|
|
|
|
|
|
|
//
|
|
|
|
// get usage bounds
|
|
|
|
//
|
|
|
|
UsageMinimum = 0;
|
|
|
|
UsageMaximum = 0;
|
|
|
|
if (ItemData->ArrayVariable == FALSE)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get usage bounds
|
|
|
|
//
|
|
|
|
UsageMinimum = LocalItemState->UsageMinimum.u.Extended;
|
|
|
|
UsageMaximum = LocalItemState->UsageMaximum.u.Extended;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get usage value from stack
|
|
|
|
//
|
|
|
|
if (ReportItemIndex < LocalItemState->UsageStackUsed)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// use stack item
|
|
|
|
//
|
|
|
|
UsageValue = LocalItemState->UsageStack[ReportItemIndex];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get usage minimum from local state
|
|
|
|
//
|
|
|
|
UsageValue = LocalItemState->UsageMinimum;
|
|
|
|
|
|
|
|
//
|
|
|
|
// append item index
|
|
|
|
//
|
|
|
|
UsageValue.u.Extended += ReportItemIndex;
|
|
|
|
|
2012-01-31 19:00:45 +00:00
|
|
|
if (LocalItemState->UsageMaximumSet)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
2012-01-31 19:00:45 +00:00
|
|
|
if (UsageValue.u.Extended > LocalItemState->UsageMaximum.u.Extended)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// maximum reached
|
|
|
|
//
|
|
|
|
UsageValue.u.Extended = LocalItemState->UsageMaximum.u.Extended;
|
|
|
|
}
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// usage usage bounds
|
|
|
|
//
|
|
|
|
UsageMinimum = UsageMaximum = UsageValue.u.Extended;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// now store all values
|
|
|
|
//
|
|
|
|
ReportItem->ByteOffset = (Report->ReportSize / 8);
|
|
|
|
ReportItem->Shift = (Report->ReportSize % 8);
|
|
|
|
ReportItem->Mask = ~(0xFFFFFFFF << GlobalItemState->ReportSize);
|
|
|
|
ReportItem->BitCount = GlobalItemState->ReportSize;
|
|
|
|
ReportItem->HasData = (ItemData->DataConstant == FALSE);
|
|
|
|
ReportItem->Array = (ItemData->ArrayVariable == 0);
|
2014-11-16 14:07:37 +00:00
|
|
|
ReportItem->Relative = (ItemData->Relative != FALSE);
|
2012-01-04 21:58:18 +00:00
|
|
|
ReportItem->Minimum = LogicalMinimum;
|
|
|
|
ReportItem->Maximum = LogicalMaximum;
|
|
|
|
ReportItem->UsageMinimum = UsageMinimum;
|
|
|
|
ReportItem->UsageMaximum = UsageMaximum;
|
|
|
|
|
|
|
|
//
|
|
|
|
// increment report size
|
|
|
|
//
|
|
|
|
Report->ReportSize += GlobalItemState->ReportSize;
|
|
|
|
|
|
|
|
//
|
|
|
|
// completed successfully
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 16:19:33 +00:00
|
|
|
BOOLEAN
|
|
|
|
HidParser_UpdateCurrentCollectionReport(
|
|
|
|
IN PHID_COLLECTION Collection,
|
|
|
|
IN PHID_REPORT Report,
|
|
|
|
IN PHID_REPORT NewReport)
|
|
|
|
{
|
|
|
|
ULONG Index;
|
|
|
|
BOOLEAN Found = FALSE, TempFound;
|
|
|
|
|
|
|
|
//
|
|
|
|
// search in local list
|
|
|
|
//
|
|
|
|
for(Index = 0; Index < Collection->ReportCount; Index++)
|
|
|
|
{
|
|
|
|
if (Collection->Reports[Index] == Report)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// update report
|
|
|
|
//
|
|
|
|
Collection->Reports[Index] = NewReport;
|
|
|
|
Found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// search in sub collections
|
|
|
|
//
|
|
|
|
for(Index = 0; Index < Collection->NodeCount; Index++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// was it found
|
|
|
|
//
|
|
|
|
TempFound = HidParser_UpdateCurrentCollectionReport(Collection->Nodes[Index], Report, NewReport);
|
|
|
|
if (TempFound)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// the same report should not be found in different collections
|
|
|
|
//
|
|
|
|
ASSERT(Found == FALSE);
|
|
|
|
Found = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return Found;
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
HidParser_UpdateCollectionReport(
|
|
|
|
IN PHID_PARSER_CONTEXT ParserContext,
|
|
|
|
IN PHID_REPORT Report,
|
|
|
|
IN PHID_REPORT NewReport)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// update in current collection
|
|
|
|
//
|
|
|
|
return HidParser_UpdateCurrentCollectionReport(ParserContext->RootCollection->Nodes[ParserContext->RootCollection->NodeCount-1], Report, NewReport);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_AddMainItem(
|
2012-01-31 16:19:33 +00:00
|
|
|
IN PHID_PARSER_CONTEXT ParserContext,
|
2012-01-04 21:58:18 +00:00
|
|
|
IN PHID_REPORT Report,
|
|
|
|
IN PGLOBAL_ITEM_STATE GlobalItemState,
|
|
|
|
IN PLOCAL_ITEM_STATE LocalItemState,
|
|
|
|
IN PMAIN_ITEM_DATA ItemData,
|
|
|
|
IN PHID_COLLECTION Collection)
|
|
|
|
{
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS Status;
|
2012-01-04 21:58:18 +00:00
|
|
|
ULONG Index;
|
2012-01-31 16:19:33 +00:00
|
|
|
PHID_REPORT NewReport;
|
|
|
|
BOOLEAN Found;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// first grow report item array
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_ReserveReportItems(Report, GlobalItemState->ReportCount, &NewReport);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status != HIDP_STATUS_SUCCESS)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to allocate memory
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2012-01-31 16:19:33 +00:00
|
|
|
if (NewReport != Report)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// update current top level collection
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
Found = HidParser_UpdateCollectionReport(ParserContext, Report, NewReport);
|
|
|
|
ASSERT(Found);
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2012-01-31 16:19:33 +00:00
|
|
|
//
|
|
|
|
// sanity check
|
|
|
|
//
|
|
|
|
ASSERT(NewReport->ItemCount + GlobalItemState->ReportCount <= NewReport->ItemAllocated);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
for(Index = 0; Index < GlobalItemState->ReportCount; Index++)
|
|
|
|
{
|
2012-01-31 16:19:33 +00:00
|
|
|
Status = HidParser_InitReportItem(NewReport, &NewReport->Items[NewReport->ItemCount], GlobalItemState, LocalItemState, ItemData, Index);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status != HIDP_STATUS_SUCCESS)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// failed to init report item
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// increment report item count
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
NewReport->ItemCount++;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-04 21:58:18 +00:00
|
|
|
HidParser_ParseReportDescriptor(
|
|
|
|
IN PUCHAR ReportDescriptor,
|
2012-01-31 16:19:33 +00:00
|
|
|
IN ULONG ReportLength,
|
|
|
|
OUT PVOID *OutParser)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
PGLOBAL_ITEM_STATE LinkedGlobalItemState, NextLinkedGlobalItemState;
|
|
|
|
ULONG Index;
|
|
|
|
PUSAGE_VALUE NewUsageStack, UsageValue;
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS Status;
|
2012-01-04 21:58:18 +00:00
|
|
|
PHID_COLLECTION CurrentCollection, NewCollection;
|
|
|
|
PUCHAR CurrentOffset, ReportEnd;
|
|
|
|
PITEM_PREFIX CurrentItem;
|
|
|
|
ULONG CurrentItemSize;
|
|
|
|
PLONG_ITEM CurrentLongItem;
|
|
|
|
PSHORT_ITEM CurrentShortItem;
|
|
|
|
ULONG Data;
|
|
|
|
UCHAR ReportType;
|
|
|
|
PHID_REPORT Report;
|
|
|
|
PMAIN_ITEM_DATA MainItemData;
|
|
|
|
PHID_PARSER_CONTEXT ParserContext;
|
|
|
|
|
2017-01-27 11:09:36 +00:00
|
|
|
CurrentOffset = ReportDescriptor;
|
|
|
|
ReportEnd = ReportDescriptor + ReportLength;
|
|
|
|
|
|
|
|
if (ReportDescriptor >= ReportEnd)
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_USAGE_NOT_FOUND;
|
2017-01-27 11:09:36 +00:00
|
|
|
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2012-01-31 16:19:33 +00:00
|
|
|
// allocate parser
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
ParserContext = AllocFunction(sizeof(HID_PARSER_CONTEXT));
|
2017-01-27 11:09:36 +00:00
|
|
|
if (!ParserContext)
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate usage stack
|
|
|
|
//
|
|
|
|
ParserContext->LocalItemState.UsageStackAllocated = 10;
|
2019-05-03 11:24:05 +00:00
|
|
|
ParserContext->LocalItemState.UsageStack = (PUSAGE_VALUE)AllocFunction(ParserContext->LocalItemState.UsageStackAllocated * sizeof(USAGE_VALUE));
|
2012-01-04 21:58:18 +00:00
|
|
|
if (!ParserContext->LocalItemState.UsageStack)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(ParserContext);
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// now allocate root collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_AllocateCollection(NULL, COLLECTION_LOGICAL, &ParserContext->LocalItemState, &ParserContext->RootCollection);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status != HIDP_STATUS_SUCCESS)
|
2012-01-04 21:58:18 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(ParserContext->LocalItemState.UsageStack);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.UsageStack = NULL;
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(ParserContext);
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// start parsing
|
|
|
|
//
|
|
|
|
CurrentCollection = ParserContext->RootCollection;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get current item
|
|
|
|
//
|
|
|
|
CurrentItem = (PITEM_PREFIX)CurrentOffset;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get item size
|
|
|
|
//
|
|
|
|
CurrentItemSize = ItemSize[CurrentItem->Size];
|
|
|
|
Data = 0;
|
|
|
|
|
|
|
|
if (CurrentItem->Type == ITEM_TYPE_LONG)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// increment item size with size of data item
|
|
|
|
//
|
|
|
|
CurrentLongItem = (PLONG_ITEM)CurrentItem;
|
|
|
|
CurrentItemSize += CurrentLongItem->DataSize;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// get short item
|
|
|
|
//
|
|
|
|
CurrentShortItem = (PSHORT_ITEM)CurrentItem;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get associated data
|
|
|
|
//
|
|
|
|
//ASSERT(CurrentItemSize == 1 || CurrentItemSize == 2 || CurrentItemSize == 4);
|
|
|
|
if (CurrentItemSize == 1)
|
|
|
|
Data = CurrentShortItem->Data.UData8[0];
|
|
|
|
else if (CurrentItemSize == 2)
|
|
|
|
Data = CurrentShortItem->Data.UData16[0];
|
|
|
|
else if (CurrentItemSize == 4)
|
|
|
|
Data = CurrentShortItem->Data.UData32;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// invalid item size
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
//DebugFunction("CurrentItem invalid item size %lu\n", CurrentItemSize);
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("Tag %x Type %x Size %x Offset %lu Length %lu\n", CurrentItem->Tag, CurrentItem->Type, CurrentItem->Size, ((ULONG_PTR)CurrentItem - (ULONG_PTR)ReportDescriptor), ReportLength);
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
|
|
|
// handle items
|
|
|
|
//
|
|
|
|
ASSERT(CurrentItem->Type >= ITEM_TYPE_MAIN && CurrentItem->Type <= ITEM_TYPE_LONG);
|
|
|
|
switch(CurrentItem->Type)
|
|
|
|
{
|
|
|
|
case ITEM_TYPE_MAIN:
|
|
|
|
{
|
|
|
|
// preprocess the local state if relevant (usages for
|
|
|
|
// collections and report items)
|
|
|
|
if (CurrentItem->Tag != ITEM_TAG_MAIN_END_COLLECTION)
|
|
|
|
{
|
|
|
|
// make all usages extended for easier later processing
|
|
|
|
for (Index = 0; Index < ParserContext->LocalItemState.UsageStackUsed; Index++)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// is it already extended
|
|
|
|
//
|
|
|
|
if (ParserContext->LocalItemState.UsageStack[Index].IsExtended)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//
|
|
|
|
// extend usage item
|
|
|
|
//
|
|
|
|
ParserContext->LocalItemState.UsageStack[Index].u.s.UsagePage = ParserContext->GlobalItemState.UsagePage;
|
|
|
|
ParserContext->LocalItemState.UsageStack[Index].IsExtended = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ParserContext->LocalItemState.UsageMinimum.IsExtended) {
|
|
|
|
// the specs say if one of them is extended they must
|
|
|
|
// both be extended, so if the minimum isn't, the
|
|
|
|
// maximum mustn't either.
|
|
|
|
ParserContext->LocalItemState.UsageMinimum.u.s.UsagePage
|
|
|
|
= ParserContext->LocalItemState.UsageMaximum.u.s.UsagePage
|
|
|
|
= ParserContext->GlobalItemState.UsagePage;
|
|
|
|
ParserContext->LocalItemState.UsageMinimum.IsExtended
|
|
|
|
= ParserContext->LocalItemState.UsageMaximum.IsExtended = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//LocalItemState.usage_stack = usageStack;
|
|
|
|
//ParserContext->LocalItemState.UsageStackUsed = UsageStackUsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (CurrentItem->Tag == ITEM_TAG_MAIN_COLLECTION) {
|
|
|
|
|
|
|
|
//
|
|
|
|
// allocate new collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_AllocateCollection(CurrentCollection, (UCHAR)Data, &ParserContext->LocalItemState, &NewCollection);
|
2020-04-17 21:54:14 +00:00
|
|
|
ASSERT(Status == HIDP_STATUS_SUCCESS);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// add new collection to current collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_AddCollection(CurrentCollection, NewCollection);
|
2020-04-17 21:54:14 +00:00
|
|
|
ASSERT(Status == HIDP_STATUS_SUCCESS);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// make new collection current
|
|
|
|
//
|
|
|
|
CurrentCollection = NewCollection;
|
|
|
|
}
|
|
|
|
else if (CurrentItem->Tag == ITEM_TAG_MAIN_END_COLLECTION)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// assert on ending the root collection
|
|
|
|
//
|
|
|
|
ASSERT(CurrentCollection != ParserContext->RootCollection);
|
|
|
|
|
|
|
|
//
|
|
|
|
// use parent of current collection
|
|
|
|
//
|
|
|
|
CurrentCollection = CurrentCollection->Root;
|
|
|
|
ASSERT(CurrentCollection);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ReportType = HID_REPORT_TYPE_ANY;
|
|
|
|
|
|
|
|
switch (CurrentItem->Tag) {
|
|
|
|
case ITEM_TAG_MAIN_INPUT:
|
|
|
|
ReportType = HID_REPORT_TYPE_INPUT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_MAIN_OUTPUT:
|
|
|
|
ReportType = HID_REPORT_TYPE_OUTPUT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_MAIN_FEATURE:
|
|
|
|
ReportType = HID_REPORT_TYPE_FEATURE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] Unknown ReportType Tag %x Type %x Size %x CurrentItemSize %x\n", CurrentItem->Tag, CurrentItem->Type, CurrentItem->Size, CurrentItemSize);
|
2012-01-04 21:58:18 +00:00
|
|
|
ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ReportType == HID_REPORT_TYPE_ANY)
|
|
|
|
break;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get report
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_GetReport(ParserContext, CurrentCollection, ReportType, ParserContext->GlobalItemState.ReportId, TRUE, &Report);
|
2020-04-17 21:54:14 +00:00
|
|
|
ASSERT(Status == HIDP_STATUS_SUCCESS);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
// fill in a sensible default if the index isn't set
|
|
|
|
if (!ParserContext->LocalItemState.DesignatorIndexSet) {
|
|
|
|
ParserContext->LocalItemState.DesignatorIndex
|
|
|
|
= ParserContext->LocalItemState.DesignatorMinimum;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ParserContext->LocalItemState.StringIndexSet)
|
|
|
|
ParserContext->LocalItemState.StringIndex = ParserContext->LocalItemState.StringMinimum;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get main item data
|
|
|
|
//
|
|
|
|
MainItemData = (PMAIN_ITEM_DATA)&Data;
|
|
|
|
|
|
|
|
//
|
|
|
|
// add states & data to the report
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_AddMainItem(ParserContext, Report, &ParserContext->GlobalItemState, &ParserContext->LocalItemState, MainItemData, CurrentCollection);
|
2020-04-17 21:54:14 +00:00
|
|
|
ASSERT(Status == HIDP_STATUS_SUCCESS);
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// backup stack
|
|
|
|
//
|
|
|
|
Index = ParserContext->LocalItemState.UsageStackAllocated;
|
|
|
|
NewUsageStack = ParserContext->LocalItemState.UsageStack;
|
|
|
|
|
|
|
|
//
|
|
|
|
// reset the local item state and clear the usage stack
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
ZeroFunction(&ParserContext->LocalItemState, sizeof(LOCAL_ITEM_STATE));
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// restore stack
|
|
|
|
//
|
|
|
|
ParserContext->LocalItemState.UsageStack = NewUsageStack;
|
|
|
|
ParserContext->LocalItemState.UsageStackAllocated = Index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ITEM_TYPE_GLOBAL:
|
|
|
|
{
|
|
|
|
switch (CurrentItem->Tag) {
|
|
|
|
case ITEM_TAG_GLOBAL_USAGE_PAGE:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_USAGE_PAGE %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.UsagePage = Data;
|
|
|
|
break;
|
|
|
|
case ITEM_TAG_GLOBAL_LOGICAL_MINIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_LOGICAL_MINIMUM %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.LogicalMinimum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_LOGICAL_MAXIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_LOCAL_MAXIMUM %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.LogicialMaximum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_PHYSICAL_MINIMUM %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.PhysicalMinimum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_PHYSICAL_MAXIMUM %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.PhysicalMaximum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_UNIT_EXPONENT:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_UNIT_EXPONENT %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.UnitExponent = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_UNIT:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_UNIT %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.Unit = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_REPORT_SIZE:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_SIZE %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.ReportSize = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_REPORT_ID:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_ID %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.ReportId = Data;
|
|
|
|
ParserContext->UseReportIDs = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_REPORT_COUNT:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_REPORT_COUNT %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->GlobalItemState.ReportCount = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_GLOBAL_PUSH:
|
|
|
|
{
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_PUSH\n");
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
|
|
|
// allocate global item state
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
LinkedGlobalItemState = (PGLOBAL_ITEM_STATE)AllocFunction(sizeof(GLOBAL_ITEM_STATE));
|
2012-01-04 21:58:18 +00:00
|
|
|
ASSERT(LinkedGlobalItemState);
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy global item state
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
CopyFunction(LinkedGlobalItemState, &ParserContext->GlobalItemState, sizeof(GLOBAL_ITEM_STATE));
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// store pushed item in link member
|
|
|
|
//
|
|
|
|
ParserContext->GlobalItemState.Next = (struct __GLOBAL_ITEM_STATE__*)LinkedGlobalItemState;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ITEM_TAG_GLOBAL_POP:
|
|
|
|
{
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_GLOBAL_POP\n");
|
2012-01-04 21:58:18 +00:00
|
|
|
if (ParserContext->GlobalItemState.Next == NULL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// pop without push
|
|
|
|
//
|
|
|
|
ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get link
|
|
|
|
//
|
|
|
|
LinkedGlobalItemState = (PGLOBAL_ITEM_STATE)ParserContext->GlobalItemState.Next;
|
|
|
|
|
|
|
|
//
|
|
|
|
// replace current item with linked one
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
CopyFunction(&ParserContext->GlobalItemState, LinkedGlobalItemState, sizeof(GLOBAL_ITEM_STATE));
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// free item
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(LinkedGlobalItemState);
|
2012-01-04 21:58:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
//
|
|
|
|
// unknown / unsupported tag
|
|
|
|
//
|
|
|
|
ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ITEM_TYPE_LOCAL:
|
|
|
|
{
|
|
|
|
switch (CurrentItem->Tag)
|
|
|
|
{
|
|
|
|
case ITEM_TAG_LOCAL_USAGE:
|
|
|
|
{
|
|
|
|
if (ParserContext->LocalItemState.UsageStackUsed >= ParserContext->LocalItemState.UsageStackAllocated)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// increment stack size
|
|
|
|
//
|
|
|
|
ParserContext->LocalItemState.UsageStackAllocated += 10;
|
|
|
|
|
|
|
|
//
|
|
|
|
// build new usage stack
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
NewUsageStack = (PUSAGE_VALUE)AllocFunction(sizeof(USAGE_VALUE) * ParserContext->LocalItemState.UsageStackAllocated);
|
2012-01-04 21:58:18 +00:00
|
|
|
ASSERT(NewUsageStack);
|
|
|
|
|
|
|
|
//
|
|
|
|
// copy old usage stack
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
CopyFunction(NewUsageStack, ParserContext->LocalItemState.UsageStack, sizeof(USAGE_VALUE) * (ParserContext->LocalItemState.UsageStackAllocated - 10));
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// free old usage stack
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(ParserContext->LocalItemState.UsageStack);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// replace with new usage stack
|
|
|
|
//
|
|
|
|
ParserContext->LocalItemState.UsageStack = NewUsageStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// get fresh usage value
|
|
|
|
//
|
|
|
|
UsageValue = &ParserContext->LocalItemState.UsageStack[ParserContext->LocalItemState.UsageStackUsed];
|
|
|
|
|
|
|
|
//
|
|
|
|
// init usage stack
|
|
|
|
//
|
|
|
|
UsageValue->IsExtended = CurrentItemSize == sizeof(ULONG);
|
|
|
|
UsageValue->u.Extended = Data;
|
|
|
|
|
|
|
|
//
|
|
|
|
// increment usage stack usage count
|
|
|
|
//
|
|
|
|
ParserContext->LocalItemState.UsageStackUsed++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_USAGE_MINIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_USAGE_MINIMUM Data %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.UsageMinimum.u.Extended = Data;
|
|
|
|
ParserContext->LocalItemState.UsageMinimum.IsExtended
|
|
|
|
= CurrentItemSize == sizeof(ULONG);
|
|
|
|
ParserContext->LocalItemState.UsageMinimumSet = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_USAGE_MAXIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_USAGE_MAXIMUM Data %x ItemSize %x %x\n", Data, CurrentItemSize, CurrentItem->Size);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.UsageMaximum.u.Extended = Data;
|
|
|
|
ParserContext->LocalItemState.UsageMaximum.IsExtended
|
|
|
|
= CurrentItemSize == sizeof(ULONG);
|
|
|
|
ParserContext->LocalItemState.UsageMaximumSet = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_DESIGNATOR_INDEX:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_DESIGNATOR_INDEX Data %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.DesignatorIndex = Data;
|
|
|
|
ParserContext->LocalItemState.DesignatorIndexSet = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_DESIGNATOR_MINIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_DESIGNATOR_MINIMUM Data %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.DesignatorMinimum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_DESIGNATOR_MAXIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_DESIGNATOR_MAXIMUM Data %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.DesignatorMaximum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_STRING_INDEX:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_STRING_INDEX Data %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.StringIndex = Data;
|
|
|
|
ParserContext->LocalItemState.StringIndexSet = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_STRING_MINIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_STRING_MINIMUM Data %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.StringMinimum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ITEM_TAG_LOCAL_STRING_MAXIMUM:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] ITEM_TAG_LOCAL_STRING_MAXIMUM Data %x\n", Data);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.StringMaximum = Data;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("Unknown Local Item Tag %x\n", CurrentItem->Tag);
|
2012-01-04 21:58:18 +00:00
|
|
|
ASSERT(FALSE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ITEM_TYPE_LONG:
|
|
|
|
{
|
|
|
|
CurrentLongItem = (PLONG_ITEM)CurrentItem;
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("Unsupported ITEM_TYPE_LONG Tag %x\n", CurrentLongItem->LongItemTag);
|
2012-01-04 21:58:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// move to next item
|
|
|
|
//
|
|
|
|
CurrentOffset += CurrentItemSize + sizeof(ITEM_PREFIX);
|
|
|
|
|
2017-01-27 11:09:36 +00:00
|
|
|
}while (CurrentOffset < ReportEnd);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// cleanup global stack
|
|
|
|
//
|
|
|
|
LinkedGlobalItemState = (PGLOBAL_ITEM_STATE)ParserContext->GlobalItemState.Next;
|
|
|
|
while(LinkedGlobalItemState != NULL)
|
|
|
|
{
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("[HIDPARSE] Freeing GlobalState %p\n", LinkedGlobalItemState);
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
|
|
|
// free global item state
|
|
|
|
//
|
|
|
|
NextLinkedGlobalItemState = (PGLOBAL_ITEM_STATE)LinkedGlobalItemState->Next;
|
|
|
|
|
|
|
|
//
|
|
|
|
// free state
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(LinkedGlobalItemState);
|
2012-01-04 21:58:18 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// move to next global state
|
|
|
|
//
|
|
|
|
LinkedGlobalItemState = NextLinkedGlobalItemState;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// free usage stack
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
FreeFunction(ParserContext->LocalItemState.UsageStack);
|
2012-01-04 21:58:18 +00:00
|
|
|
ParserContext->LocalItemState.UsageStack = NULL;
|
|
|
|
|
2012-01-31 16:19:33 +00:00
|
|
|
//
|
|
|
|
// store result
|
|
|
|
//
|
|
|
|
*OutParser = ParserContext;
|
|
|
|
|
2012-01-04 21:58:18 +00:00
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_SUCCESS;
|
2012-01-04 21:58:18 +00:00
|
|
|
}
|
2012-01-31 16:19:33 +00:00
|
|
|
|
|
|
|
PHID_COLLECTION
|
|
|
|
HidParser_GetCollection(
|
|
|
|
PHID_PARSER_CONTEXT ParserContext,
|
|
|
|
IN ULONG CollectionNumber)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// sanity checks
|
|
|
|
//
|
|
|
|
ASSERT(ParserContext);
|
|
|
|
ASSERT(ParserContext->RootCollection);
|
|
|
|
ASSERT(ParserContext->RootCollection->NodeCount);
|
|
|
|
|
|
|
|
//
|
|
|
|
// is collection index out of bounds
|
|
|
|
//
|
|
|
|
if (CollectionNumber < ParserContext->RootCollection->NodeCount)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// valid collection
|
|
|
|
//
|
|
|
|
return ParserContext->RootCollection->Nodes[CollectionNumber];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// no such collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
DebugFunction("HIDPARSE] No such collection %lu\n", CollectionNumber);
|
2012-01-31 16:19:33 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
HidParser_NumberOfTopCollections(
|
|
|
|
IN PVOID ParserCtx)
|
|
|
|
{
|
|
|
|
PHID_PARSER_CONTEXT ParserContext;
|
|
|
|
|
|
|
|
//
|
|
|
|
// get parser context
|
|
|
|
//
|
|
|
|
ParserContext = (PHID_PARSER_CONTEXT)ParserCtx;
|
|
|
|
|
|
|
|
//
|
|
|
|
// sanity checks
|
|
|
|
//
|
|
|
|
ASSERT(ParserContext);
|
|
|
|
ASSERT(ParserContext->RootCollection);
|
|
|
|
ASSERT(ParserContext->RootCollection->NodeCount);
|
|
|
|
|
|
|
|
//
|
|
|
|
// number of top collections
|
|
|
|
//
|
|
|
|
return ParserContext->RootCollection->NodeCount;
|
|
|
|
}
|
|
|
|
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS
|
2012-01-31 16:19:33 +00:00
|
|
|
HidParser_BuildContext(
|
|
|
|
IN PVOID ParserContext,
|
|
|
|
IN ULONG CollectionIndex,
|
|
|
|
IN ULONG ContextSize,
|
|
|
|
OUT PVOID *CollectionContext)
|
|
|
|
{
|
|
|
|
PHID_COLLECTION Collection;
|
|
|
|
PVOID Context;
|
2020-04-17 21:54:14 +00:00
|
|
|
NTSTATUS Status;
|
2012-01-31 16:19:33 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// lets get the collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Collection = HidParser_GetCollection((PHID_PARSER_CONTEXT)ParserContext, CollectionIndex);
|
2012-01-31 16:19:33 +00:00
|
|
|
ASSERT(Collection);
|
|
|
|
|
|
|
|
//
|
|
|
|
// lets allocate the context
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Context = AllocFunction(ContextSize);
|
2012-01-31 16:19:33 +00:00
|
|
|
if (Context == NULL)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// no memory
|
|
|
|
//
|
2020-04-17 21:54:14 +00:00
|
|
|
return HIDP_STATUS_INTERNAL_ERROR;
|
2012-01-31 16:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// lets build the context
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Status = HidParser_BuildCollectionContext(Collection, Context, ContextSize);
|
2020-04-17 21:54:14 +00:00
|
|
|
if (Status == HIDP_STATUS_SUCCESS)
|
2012-01-31 16:19:33 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// store context
|
|
|
|
//
|
|
|
|
*CollectionContext = Context;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// done
|
|
|
|
//
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
HidParser_GetContextSize(
|
|
|
|
IN PVOID ParserContext,
|
|
|
|
IN ULONG CollectionIndex)
|
|
|
|
{
|
|
|
|
PHID_COLLECTION Collection;
|
|
|
|
ULONG Size;
|
|
|
|
|
|
|
|
//
|
|
|
|
// lets get the collection
|
|
|
|
//
|
2019-05-03 11:24:05 +00:00
|
|
|
Collection = HidParser_GetCollection((PHID_PARSER_CONTEXT)ParserContext, CollectionIndex);
|
2012-01-31 16:19:33 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// calculate size
|
|
|
|
//
|
|
|
|
Size = HidParser_CalculateContextSize(Collection);
|
|
|
|
return Size;
|
|
|
|
}
|
|
|
|
|