Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345/* * PROJECT: ReactOS HID Parser Library * LICENSE: GPL - See COPYING in the top level directory * FILE: lib/drivers/hidparser/context.c * PURPOSE: HID Parser * PROGRAMMERS: * Michael Martin (michael.martin@reactos.org) * Johannes Anderwald (johannes.anderwald@reactos.org) */
#include "parser.h"
#define NDEBUG#include <debug.h>
typedef struct{ ULONG Size; union { UCHAR RawData[1]; };}HID_COLLECTION_CONTEXT, *PHID_COLLECTION_CONTEXT;
ULONGHidParser_CalculateCollectionSize( IN PHID_COLLECTION Collection){ ULONG Size = 0, Index;
Size = sizeof(HID_COLLECTION);
// // add size required for the number of report items // for(Index = 0; Index < Collection->ReportCount; Index++) { // // get report size // ASSERT(Collection->Reports[Index]->ItemCount); Size += sizeof(HID_REPORT) + Collection->Reports[Index]->ItemCount * sizeof(HID_REPORT_ITEM); }
// // calculate size for sub collections // for(Index = 0; Index < Collection->NodeCount; Index++) { Size += HidParser_CalculateCollectionSize(Collection->Nodes[Index]); }
// // append size for the offset // Size += (Collection->ReportCount + Collection->NodeCount) * sizeof(ULONG);
// // done // return Size;}
ULONGHidParser_CalculateContextSize( IN PHID_COLLECTION Collection){ ULONG Size;
// // minimum size is the size of the collection // Size = HidParser_CalculateCollectionSize(Collection);
// // append collection context size // Size += sizeof(HID_COLLECTION_CONTEXT); return Size;}
ULONGHidParser_StoreCollection( IN PHID_COLLECTION Collection, IN PHID_COLLECTION_CONTEXT CollectionContext, IN ULONG CurrentOffset){ ULONG Index; ULONG ReportSize; ULONG InitialOffset; ULONG CollectionSize; PHID_COLLECTION TargetCollection;
// // backup initial offset // InitialOffset = CurrentOffset;
// // get target collection // TargetCollection = (PHID_COLLECTION)(&CollectionContext->RawData[CurrentOffset]);
// // first copy the collection details // CopyFunction(TargetCollection, Collection, sizeof(HID_COLLECTION));
// // calulcate collection size // CollectionSize = sizeof(HID_COLLECTION) + sizeof(ULONG) * (Collection->ReportCount + Collection->NodeCount);
// // increase offset // CurrentOffset += CollectionSize;
// // sanity check // ASSERT(CurrentOffset < CollectionContext->Size);
// // first store the report items // for(Index = 0; Index < Collection->ReportCount; Index++) { // // calculate report size // ReportSize = sizeof(HID_REPORT) + Collection->Reports[Index]->ItemCount * sizeof(HID_REPORT_ITEM);
// // sanity check // ASSERT(CurrentOffset + ReportSize < CollectionContext->Size);
// // copy report item // CopyFunction(&CollectionContext->RawData[CurrentOffset], Collection->Reports[Index], ReportSize);
// // store offset to report item // TargetCollection->Offsets[Index] = CurrentOffset;
// // move to next offset // CurrentOffset += ReportSize; }
ASSERT(CurrentOffset <= CollectionContext->Size);
// // now store the sub collections // for(Index = 0; Index < Collection->NodeCount; Index++) { // // store offset // TargetCollection->Offsets[Collection->ReportCount + Index] = CurrentOffset;
// // store sub collections // CurrentOffset += HidParser_StoreCollection(Collection->Nodes[Index], CollectionContext, CurrentOffset);
// // sanity check // ASSERT(CurrentOffset < CollectionContext->Size); }
// // return size of collection // return CurrentOffset - InitialOffset;}
NTSTATUSHidParser_BuildCollectionContext( IN PHID_COLLECTION RootCollection, IN PVOID Context, IN ULONG ContextSize){ PHID_COLLECTION_CONTEXT CollectionContext; ULONG CollectionSize;
// // init context // CollectionContext = (PHID_COLLECTION_CONTEXT)Context; CollectionContext->Size = ContextSize;
// // store collections // CollectionSize = HidParser_StoreCollection(RootCollection, CollectionContext, 0);
// // sanity check // ASSERT(CollectionSize + sizeof(HID_COLLECTION_CONTEXT) == ContextSize);
DPRINT("CollectionContext %p\n", CollectionContext); DPRINT("CollectionContext RawData %p\n", CollectionContext->RawData); DPRINT("CollectionContext Size %lu\n", CollectionContext->Size);
// // done // return HIDP_STATUS_SUCCESS;}
PHID_REPORTHidParser_SearchReportInCollection( IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection, IN UCHAR ReportType){ ULONG Index; PHID_REPORT Report; PHID_COLLECTION SubCollection;
// // search first in local array // for(Index = 0; Index < Collection->ReportCount; Index++) { // // get report // Report = (PHID_REPORT)(CollectionContext->RawData + Collection->Offsets[Index]); if (Report->Type == ReportType) { // // found report // return Report; } }
// // now search in sub collections // for(Index = 0; Index < Collection->NodeCount; Index++) { // // get collection // SubCollection = (PHID_COLLECTION)(CollectionContext->RawData + Collection->Offsets[Collection->ReportCount + Index]);
// // recursively search collection // Report = HidParser_SearchReportInCollection(CollectionContext, SubCollection, ReportType); if (Report) { // // found report // return Report; } }
// // not found // return NULL;}
PHID_REPORTHidParser_GetReportInCollection( IN PVOID Context, IN UCHAR ReportType){ PHID_COLLECTION_CONTEXT CollectionContext = (PHID_COLLECTION_CONTEXT)Context;
// // done // return HidParser_SearchReportInCollection(CollectionContext, (PHID_COLLECTION)&CollectionContext->RawData, ReportType);}
PHID_COLLECTIONHidParser_GetCollectionFromContext( IN PVOID Context){ PHID_COLLECTION_CONTEXT CollectionContext = (PHID_COLLECTION_CONTEXT)Context;
// // return root collection // return (PHID_COLLECTION)CollectionContext->RawData;}
ULONGHidParser_GetCollectionCount( IN PHID_COLLECTION_CONTEXT CollectionContext, IN PHID_COLLECTION Collection){ ULONG Index; ULONG Count = Collection->NodeCount; PHID_COLLECTION SubCollection;
for(Index = 0; Index < Collection->NodeCount; Index++) { // // get offset to sub collection // SubCollection = (PHID_COLLECTION)(CollectionContext->RawData + Collection->Offsets[Collection->ReportCount + Index]);
// // count collection for sub nodes // Count += HidParser_GetCollectionCount(CollectionContext, SubCollection); }
// // done // return Count;}
ULONGHidParser_GetTotalCollectionCount( IN PVOID Context){ PHID_COLLECTION_CONTEXT CollectionContext;
// // get parser context // CollectionContext = (PHID_COLLECTION_CONTEXT)Context;
// // count collections // return HidParser_GetCollectionCount(CollectionContext, (PHID_COLLECTION)CollectionContext->RawData);}