static NTSTATUS XenM2BPdoQueryDeviceRelations(PXENM2B_PDO_EXTENSION pPdoExt, PIRP pIrp) { PIO_STACK_LOCATION pIrpStack; PDEVICE_RELATIONS pRelations; DEVICE_RELATION_TYPE Type; pIrpStack = IoGetCurrentIrpStackLocation(pIrp); Type = pIrpStack->Parameters.QueryDeviceRelations.Type; if (Type != TargetDeviceRelation) { TraceDebug(("%s: Relations Type: %d\n", __FUNCTION__, Type)); return STATUS_SUCCESS; } if (XenM2BGetPnPState(&pPdoExt->DevicePnPState) == PnPStateDeleted) { TraceDebug(("%s: Target deleted\n", __FUNCTION__)); return STATUS_NO_SUCH_DEVICE; } pRelations = ExAllocatePoolWithTag(PagedPool, sizeof(DEVICE_RELATIONS), XENM2B_POOL_TAG); if (pRelations == NULL) { TraceDebug(("%s: Relations alloc failed\n", __FUNCTION__)); return STATUS_INSUFFICIENT_RESOURCES; } pRelations->Count = 1; pRelations->Objects[0] = pPdoExt->pDevice; ObReferenceObject(pPdoExt->pDevice); pIrp->IoStatus.Information = (ULONG_PTR)pRelations; return STATUS_SUCCESS; }
static NTSTATUS XenM2BPdoQueryDeviceText(PXENM2B_PDO_EXTENSION pPdoExt, PIRP pIrp) { PIO_STACK_LOCATION pIrpStack; PVOID pBuffer; UNICODE_STRING Text; NTSTATUS Status; pIrpStack = IoGetCurrentIrpStackLocation(pIrp); switch (pIrpStack->Parameters.QueryDeviceText.DeviceTextType) { case DeviceTextDescription: TraceDebug(("%s: DeviceTextDescription\n", __FUNCTION__)); break; case DeviceTextLocationInformation: TraceDebug(("%s: DeviceTextLocationInformation\n", __FUNCTION__)); break; default: pIrp->IoStatus.Information = 0; return STATUS_NOT_SUPPORTED; } pBuffer = ExAllocatePoolWithTag(PagedPool, XENM2B_MAX_TEXT_LENGTH, XENM2B_POOL_TAG); if (pBuffer == NULL) return STATUS_INSUFFICIENT_RESOURCES; RtlZeroMemory(pBuffer, XENM2B_MAX_TEXT_LENGTH); Text.Buffer = pBuffer; Text.MaximumLength = XENM2B_MAX_TEXT_LENGTH; Text.Length = 0; switch (pIrpStack->Parameters.QueryDeviceText.DeviceTextType) { case DeviceTextDescription: RtlAppendUnicodeStringToString(&Text, &pPdoExt->DeviceName); break; case DeviceTextLocationInformation: RtlAppendUnicodeToString(&Text, L"Xen PV HID Device on XenM2B Bus"); break; default: ASSERT(FALSE); break; } TraceDebug(("%s: %wZ\n", __FUNCTION__, &Text)); pIrp->IoStatus.Information = (ULONG_PTR)pBuffer; return STATUS_SUCCESS; }
NTSTATUS XenM2BPdoPower(PDEVICE_OBJECT pDeviceObject, PIRP pIrp) { PXENM2B_PDO_EXTENSION pPdoExt = (PXENM2B_PDO_EXTENSION)pDeviceObject->DeviceExtension; PIO_STACK_LOCATION pIrpStack; POWER_STATE PowerState; POWER_STATE_TYPE PowerType; NTSTATUS Status = STATUS_SUCCESS; pIrpStack = IoGetCurrentIrpStackLocation(pIrp); PowerType = pIrpStack->Parameters.Power.Type; PowerState = pIrpStack->Parameters.Power.State; switch (pIrpStack->MinorFunction) { case IRP_MN_SET_POWER: TraceDebug(("%s: IRP_MN_SET_POWER\n", __FUNCTION__)); if (PowerType == DevicePowerState) { TraceDebug(("%s: IRP_MN_SET_POWER DevicePowerState:%x\n", __FUNCTION__, PowerState.DeviceState)); PoSetPowerState(pPdoExt->pDevice, DevicePowerState, PowerState); pPdoExt->DevicePowerState = PowerState.DeviceState; } else if (PowerType == SystemPowerState) { TraceDebug(("%s: IRP_MN_SET_POWER SystemPowerState:%x\n", __FUNCTION__, PowerState.SystemState)); pPdoExt->SystemPowerState = PowerState.SystemState; } PoStartNextPowerIrp(pIrp); pIrp->IoStatus.Status = Status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); break; case IRP_MN_QUERY_POWER: TraceDebug(("%s: IRP_MN_QUERY_POWER\n", __FUNCTION__)); PoStartNextPowerIrp(pIrp); pIrp->IoStatus.Status = Status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); break; case IRP_MN_WAIT_WAKE: case IRP_MN_POWER_SEQUENCE: default: PoStartNextPowerIrp(pIrp); Status = pIrp->IoStatus.Status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); break; } return Status; }
VOID XenM2BPdoDeleteDevice(PDEVICE_OBJECT pDeviceObject) { PXENM2B_PDO_EXTENSION pPdoExt = (PXENM2B_PDO_EXTENSION)pDeviceObject->DeviceExtension; TraceDebug(("%s: Entry Device:%wZ\n", __FUNCTION__, &pPdoExt->DeviceName)); XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStateDeleted); XenM2BReleaseHidContext(pPdoExt->pHidCtx); IoDeleteDevice(pDeviceObject); TraceDebug(("%s: Exit\n", __FUNCTION__)); }
const Item* EntityController::GetScrollListItem(const Entity & entity, const uint & itemID) const { auto i = _scrollLists.find(entity); if (i != _scrollLists.end()) if (itemID < i->second->items.size()) { return &i->second->items[itemID]; } else { TraceDebug("itemID %d out of range.", itemID); return nullptr; } TraceDebug("Tried to get value of slider that was not a slider"); return nullptr; }
const float EntityController::GetSliderValue(const Entity & entity) const { auto i = _sliders.find(entity); if (i != _sliders.end()) return i->second->curr; TraceDebug("Tried to get value of slider that was not a slider"); return 0.0f; }
const unsigned int EntityController::GetListSelectionValue(const Entity & entity) const { auto i = _listSelections.find(entity); if (i != _listSelections.end()) return i->second->value; TraceDebug("Tried to get value of selectionlist that was not a selectionlist"); return 0; }
const void EntityController::ShowPopupBox(const Entity & entity) { auto i = _popUps.find(entity); if (i != _popUps.end()) { _popInfo.e = entity; _popInfo.poping = true; } TraceDebug("Tried to pop an entity that was not an popupbox."); }
const float EntityController::GetProgressBarValue(const Entity & entity) const { auto i = _progressBars.find(entity); if (i != _progressBars.end()) return i->second->value; TraceDebug("Tried to get value of progressbar that was not a progressbar"); return 0.0f; }
const void EntityController::SetProgressBarMaxValue(const Entity & entity, const float value) { auto i = _progressBars.find(entity); if (i != _progressBars.end()) { auto& b = i->second; b->maxV = value; } TraceDebug("Tried to set max value of progressbar that was not a progressbar"); return void(); }
const void EntityController::SetProgressBarWidth(const Entity & entity, const float width) { auto i = _progressBars.find(entity); if (i != _progressBars.end()) { auto& b = i->second; b->width = width; } TraceDebug("Tried to set width of progressbar that was not a progressbar"); return void(); }
void ReceiverCleanup(PRECEIVER Receiver) { ReceiverCommonCleanup(&Receiver->Common); ReceiverCommonCleanupBuffers(&Receiver->Common); if (Receiver->RecvPacketPool != NULL) { TraceDebug (("Freeing packet pool.\n")); NdisFreePacketPool(Receiver->RecvPacketPool); Receiver->RecvPacketPool = NULL; } }
void XmKillThread(struct xm_thread *t) { if (!t) return; TraceDebug (("Killing thread %p.\n", t)); XM_ASSERT(KeGetCurrentThread() != t->thread); t->exit = TRUE; KeSetEvent(&t->event, IO_NO_INCREMENT, FALSE); KeWaitForSingleObject(t->thread, Executive, KernelMode, FALSE, NULL); ObDereferenceObject(t->thread); XmFreeMemory(t); }
const void EntityController::SetProgressBarValue(const Entity & entity, const float value) { auto i = _progressBars.find(entity); if (i != _progressBars.end()) { auto& b = i->second; float pl = b->width*((b->value - b->minV) / (b->maxV - b->minV)); b->value = fmin(fmax(value, b->minV), b->maxV); float l = b->width*((b->value - b->minV) / (b->maxV - b->minV)); _animation->PlayAnimation(entity, "scale", l - pl, pl); } TraceDebug("Tried to set value of progressbar that was not a progressbar"); return void(); }
const Entity EntityBuilder::CreateListSelection(const XMFLOAT3 & position, std::string& name, float fontSize, const std::vector<std::string>& values, const unsigned int startValue, float size1, float size2, std::function<void()> updatefunc, const XMFLOAT4& textColor) { ListSelection* l = nullptr; Entity e = _entity.Create(); try { if (values.size() == 0) { TraceDebug("Tried to create listselection with no values"); std::vector<std::string> v; v.push_back("NaN"); l = new ListSelection(v, 0, updatefunc); } else l = new ListSelection(values, startValue, updatefunc); } catch (std::exception& e) { e; throw ErrorMsg(1500002, L"Could not create listselection"); } _controller->AddListSelection(e, l); Entity text = _entity.Create(); Entity bl; Entity br; //Entity ename = _entity.Create(); //_transform->CreateTransform(ename); _transform->CreateTransform(e); _transform->CreateTransform(text); _text->BindText(e, name, "Assets/Fonts/cooper", fontSize, textColor); if (l->value >= l->values.size()) { l->value = 0; TraceDebug("Tried to set default value out of range."); } _text->BindText(text, l->values[l->value], "Assets/Fonts/cooper", fontSize, textColor); bl = CreateButton( XMFLOAT3(size1, 5.0f, 0.0f), "<-", fontSize, textColor, 50.0f, 50.0f, "", [this, text, l, e]() { l->value = (l->value > 0) ? l->value - 1 : 0; this->_text->ChangeText(text, l->values[l->value]); // this->_text->ChangeText(e, l->values[l->value]); l->update(); }); _overlay->SetExtents(bl, _text->GetLength(bl), (uint)fontSize); br = CreateButton( XMFLOAT3(size1 + size2, 5.0f, 0.0f), "->", fontSize, textColor, 50.0f, 50.0f, "", [this, text, l, e]() { l->value = static_cast<unsigned int>((l->value < l->values.size() - 1) ? l->value + 1 : l->values.size() - 1); this->_text->ChangeText(text, l->values[l->value]); //this->_text->ChangeText(e, l->values[l->value]); l->update(); }); _overlay->SetExtents(br, _text->GetLength(br), (uint)fontSize); _transform->SetPosition(text, XMFLOAT3(size1 + 50.0f, 5.0f, 0.0f)); _transform->BindChild(e, text); _transform->BindChild(e, bl); _transform->BindChild(e, br); // _transform->BindChild(e, ename); _transform->SetPosition(e, position); return e; }
void AnimMesh::load(char *fn) { s_corefile f; Face *facelist; TVertex *tvertex1; int id, flags, animflags; int numtfaces; int vdatasize = 0; int i, j; numvertices = 0; numfacegroups = 0; numuvchannels = 0; // empty out numfaces[] for (i = 0; i < MAXFACEGROUPS; i++) numfaces[i] = 0; corefile_open(fn, &f, FILE_READ); // === Read ID === corefile_read(&id, 4, 1, &f); corefile_read(&numvertices, 2, 1, &f); corefile_read(&numfacegroups, 2, 1, &f); corefile_read(&numuvchannels, 2, 1, &f); corefile_read(&flags, 2, 1, &f); // === Read vertices === vertex = (Vertex*)wrap_malloc(numvertices * sizeof(Vertex)); for (i = 0; i < numvertices; i++) { corefile_read(&vertex[i].x, 4, 1, &f); corefile_read(&vertex[i].y, 4, 1, &f); corefile_read(&vertex[i].z, 4, 1, &f); } // === read faces === for (j = 0; j < numfacegroups; j++) { corefile_read(&numfaces[j], 2, 1, &f); corefile_read(&matid[j], 2, 1, &f); //TraceDebug( "numfaces: %i", numfaces[j]); face[j] = (Face*)wrap_malloc(numfaces[j] * sizeof(Face)); facelist = (Face*)face[j]; for (i = 0; i < numfaces[j]; i++) { corefile_read(&facelist[i].a, 2, 1, &f); corefile_read(&facelist[i].b, 2, 1, &f); corefile_read(&facelist[i].c, 2, 1, &f); corefile_read(&facelist[i].flags, 2, 1, &f); } } // empty out numtvertices[] for (int x = 0; x < MAXUVCHANNELS; x++) numtvertices[x] = 0; // === read UV's === for (j = 0; j < numuvchannels; j++) { corefile_read(&numtvertices[j], 2, 1, &f); corefile_read(&numtfaces, 2, 1, &f); tvertex[j] = (TVertex*)wrap_malloc(numtvertices[j] * sizeof(TVertex)); tvertex1 = (TVertex*)tvertex[j]; for (i = 0; i < numtvertices[j]; i++) { corefile_read(&tvertex1[i].u, 4, 1, &f); corefile_read(&tvertex1[i].v, 4, 1, &f); } facelist = (Face*)face[0]; for (i = 0; i < numfaces[0]; i++) { // was: numtfaces if (j == 0) { corefile_read(&facelist[i].ta, 2, 1, &f); corefile_read(&facelist[i].tb, 2, 1, &f); corefile_read(&facelist[i].tc, 2, 1, &f); } else { corefile_read(&facelist[i].ta2, 2, 1, &f); corefile_read(&facelist[i].tb2, 2, 1, &f); corefile_read(&facelist[i].tc2, 2, 1, &f); } } } // === Read animation data === if (flags & 4) { // numanimations = 0; corefile_read(&numanimations, 2, 1, &f); corefile_read(&animtype, 2, 1, &f); corefile_read(&animflags, 2, 1, &f); TraceDebug("animation found! %i animations", numanimations);; for (j = 0; j < numanimations; j++) { anim[j].numframes = 0; anim[j].speed = 0; anim[j].loop = 0; } for (j = 0; j < numanimations; j++) { //corefile_read(anim[j].name,16,1,&f); corefile_read(&anim[j].numframes, 2, 1, &f); corefile_read(&anim[j].speed, 2, 1, &f); corefile_read(&anim[j].loop, 2, 1, &f); //anim[j].speed*=4; anim[j].numframes++; TraceDebug("anim: %i", j, "numframes: %i", anim[j].numframes, " ,speed: %i", anim[j].speed, " , loop: %i", anim[j].loop);; vdatasize = anim[j].numframes * numvertices * sizeof(Vertex); anim[j].vdata = (Vertex*)(wrap_malloc(vdatasize)); corefile_read(anim[j].vdata, vdatasize, 1, &f); } } // animation corefile_close(&f); lastvdata = vertex; TraceDebug("- animmesh loaded"); //getchar(); }
NTSTATUS XenM2BPdoPnP(PDEVICE_OBJECT pDeviceObject, PIRP pIrp) { PXENM2B_PDO_EXTENSION pPdoExt = (PXENM2B_PDO_EXTENSION)pDeviceObject->DeviceExtension; PIO_STACK_LOCATION pIrpStack; NTSTATUS Status = STATUS_SUCCESS; pIrpStack = IoGetCurrentIrpStackLocation(pIrp); switch (pIrpStack->MinorFunction) { case IRP_MN_START_DEVICE: TraceDebug(("%s: IRP_MN_START_DEVICE\n", __FUNCTION__)); pPdoExt->DevicePowerState = PowerDeviceD0; XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStateStarted); break; case IRP_MN_STOP_DEVICE: TraceDebug(("%s: IRP_MN_STOP_DEVICE\n", __FUNCTION__)); XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStateStopped); break; case IRP_MN_SURPRISE_REMOVAL: TraceDebug(("%s: IRP_MN_SURPRISE_REMOVAL\n", __FUNCTION__)); XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStateSurpriseRemoval); // TODO test removal vs. surprise removal break; case IRP_MN_REMOVE_DEVICE: TraceDebug(("%s: IRP_MN_REMOVE_DEVICE\n", __FUNCTION__)); // Already gone. if (XenM2BGetPnPState(&pPdoExt->DevicePnPState) == PnPStateDeleted) { TraceDebug(("%s: Device deleted\n", __FUNCTION__)); break; } if (pPdoExt->Missing) { // DEV_RESET will set the Missing flag before causing a re-enumeration in the FDO. // The FDO will report this PDO as not present in the relations query and it will // be removed here. TraceDebug(("%s: Delete:%wZ\n", __FUNCTION__, &pPdoExt->DeviceName)); XenM2BPdoUnlink(pPdoExt, FALSE); XenM2BPdoDeleteDevice(pPdoExt->pDevice); } else { TraceDebug(("%s: Enumerated:%wZ\n", __FUNCTION__, &pPdoExt->DeviceName)); XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStateEnumerated); } break; case IRP_MN_EJECT: TraceDebug(("%s: IRP_MN_EJECT\n", __FUNCTION__)); // Already gone. if (XenM2BGetPnPState(&pPdoExt->DevicePnPState) == PnPStateDeleted) { TraceDebug(("%s: Device deleted\n", __FUNCTION__)); break; } XenM2BPdoUnlink(pPdoExt, FALSE); XenM2BPdoDeleteDevice(pPdoExt->pDevice); break; case IRP_MN_QUERY_REMOVE_DEVICE: TraceDebug(("%s: IRP_MN_QUERY_REMOVE_DEVICE\n", __FUNCTION__)); XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStateRemovePending); break; case IRP_MN_QUERY_STOP_DEVICE: TraceDebug(("%s: IRP_MN_QUERY_STOP_DEVICE\n", __FUNCTION__)); XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStateStopPending); break; case IRP_MN_CANCEL_REMOVE_DEVICE: TraceDebug(("%s: IRP_MN_CANCEL_REMOVE_DEVICE\n", __FUNCTION__)); (VOID)XenM2BRestorePnPState(&pPdoExt->DevicePnPState, PnPStateRemovePending); break; case IRP_MN_CANCEL_STOP_DEVICE: TraceDebug(("%s: IRP_MN_CANCEL_STOP_DEVICE\n", __FUNCTION__)); (VOID)XenM2BRestorePnPState(&pPdoExt->DevicePnPState, PnPStateStopPending); break; case IRP_MN_QUERY_DEVICE_RELATIONS: TraceDebug(("%s: IRP_MN_QUERY_DEVICE_RELATIONS\n", __FUNCTION__)); Status = XenM2BPdoQueryDeviceRelations(pPdoExt, pIrp); break; case IRP_MN_QUERY_INTERFACE: Status = XenM2BPdoQueryInterface(pPdoExt, pIrp); break; case IRP_MN_QUERY_CAPABILITIES: Status = XenM2BPdoQueryCapabilities(pPdoExt, pIrp); break; case IRP_MN_QUERY_DEVICE_TEXT: Status = XenM2BPdoQueryDeviceText(pPdoExt, pIrp); break; case IRP_MN_QUERY_ID: Status = XenM2BPdoQueryId(pPdoExt, pIrp); break; case IRP_MN_QUERY_BUS_INFORMATION: Status = XenM2BPdoQueryBusInformation(pPdoExt, pIrp); break; case IRP_MN_DEVICE_USAGE_NOTIFICATION: Status = XenM2BPdoDeviceUsageNotification(pPdoExt, pIrp); if (Status == STATUS_PENDING) return Status; break; case IRP_MN_READ_CONFIG: case IRP_MN_WRITE_CONFIG: Status = STATUS_NOT_SUPPORTED; break; case IRP_MN_FILTER_RESOURCE_REQUIREMENTS: case IRP_MN_QUERY_RESOURCES: case IRP_MN_QUERY_RESOURCE_REQUIREMENTS: case IRP_MN_QUERY_PNP_DEVICE_STATE: case IRP_MN_SET_LOCK: default: Status = pIrp->IoStatus.Status; break; } pIrp->IoStatus.Status = Status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); return Status; }
static NTSTATUS XenM2BPdoQueryId(PXENM2B_PDO_EXTENSION pPdoExt, PIRP pIrp) { PIO_STACK_LOCATION pIrpStack; PWCHAR pBuffer; UNICODE_STRING Id; ULONG Type; size_t Length; NTSTATUS Status; pIrpStack = IoGetCurrentIrpStackLocation(pIrp); switch (pIrpStack->Parameters.QueryId.IdType) { case BusQueryInstanceID: TraceDebug(("%s: BusQueryInstanceID\n", __FUNCTION__)); break; case BusQueryDeviceID: TraceDebug(("%s: BusQueryDeviceID\n", __FUNCTION__)); break; case BusQueryHardwareIDs: TraceDebug(("%s: BusQueryHardwareIDs\n", __FUNCTION__)); break; default: pIrp->IoStatus.Information = 0; return STATUS_NOT_SUPPORTED; } pBuffer = ExAllocatePoolWithTag(PagedPool, XENM2B_MAX_DEVID_LENGTH, XENM2B_POOL_TAG); if (pBuffer == NULL) return STATUS_INSUFFICIENT_RESOURCES; RtlZeroMemory(pBuffer, XENM2B_MAX_DEVID_LENGTH); Id.Buffer = pBuffer; Id.MaximumLength = XENM2B_MAX_DEVID_LENGTH; Id.Length = 0; switch (pIrpStack->Parameters.QueryId.IdType) { case BusQueryInstanceID: Type = REG_SZ; RtlAppendUnicodeStringToString(&Id, &pPdoExt->InstanceID); break; case BusQueryDeviceID: Type = REG_SZ; RtlAppendUnicodeToString(&Id, L"XENM2B\\DEVICE"); break; case BusQueryHardwareIDs: Type = REG_MULTI_SZ; RtlAppendUnicodeToString(&Id, L"XENM2B\\DEVICE"); Id.Buffer += Id.Length/2; Id.Buffer++; // past terminator Id.MaximumLength = Id.MaximumLength - Id.Length; Id.MaximumLength -= sizeof(WCHAR); Id.Length = 0; RtlAppendUnicodeToString(&Id, L"XENDEVICE"); break; default: Type = REG_NONE; ASSERT(FALSE); break; } Id.Buffer = pBuffer; Id.MaximumLength = XENM2B_MAX_DEVID_LENGTH; Id.Length = 0; switch (Type) { case REG_SZ: TraceDebug(("%s: %ws\n", __FUNCTION__, Id.Buffer)); break; case REG_MULTI_SZ: do { TraceDebug(("%s: - %ws\n", __FUNCTION__, Id.Buffer)); Id.Buffer += wcslen(Id.Buffer); Id.Buffer++; } while (*Id.Buffer != L'\0'); break; default: ASSERT(FALSE); break; } pIrp->IoStatus.Information = (ULONG_PTR)pBuffer; return STATUS_SUCCESS; }
static NTSTATUS XenM2BPdoQueryInterface(PXENM2B_PDO_EXTENSION pPdoExt, PIRP pIrp) { PIO_STACK_LOCATION pIrpStack; PXENM2B_CLIENT_INTERFACE pInterface; const GUID *pInterfaceType; USHORT Size; USHORT Version; NTSTATUS Status; TraceDebug(("%s(%wZ): ====>\n", __FUNCTION__, &pPdoExt->DeviceName)); pIrpStack = IoGetCurrentIrpStackLocation(pIrp); pInterfaceType = pIrpStack->Parameters.QueryInterface.InterfaceType; Size = pIrpStack->Parameters.QueryInterface.Size; Version = pIrpStack->Parameters.QueryInterface.Version; TraceDebug(("%s: %08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n", __FUNCTION__, pInterfaceType->Data1, pInterfaceType->Data2, pInterfaceType->Data3, pInterfaceType->Data4[0], pInterfaceType->Data4[1], pInterfaceType->Data4[2], pInterfaceType->Data4[3], pInterfaceType->Data4[4], pInterfaceType->Data4[5], pInterfaceType->Data4[6], pInterfaceType->Data4[7])); if (!RtlEqualMemory(pInterfaceType, &XENM2B_CLIENT_INTERFACE_GUID, sizeof(GUID))) return STATUS_SUCCESS; if (Version != XENM2B_CLIENT_INTERFACE_VERSION) return STATUS_SUCCESS; if (Size < sizeof(XENM2B_CLIENT_INTERFACE)) return STATUS_BUFFER_TOO_SMALL; // Get the input client interface - PXENHID_OPERATIONS pInterface = (PXENM2B_CLIENT_INTERFACE)pIrpStack->Parameters.QueryInterface.Interface; ASSERT(pInterface->Header.Size == sizeof(XENM2B_CLIENT_INTERFACE)); ASSERT(pInterface->Header.Version == XENM2B_CLIENT_INTERFACE_VERSION); TraceDebug(("%s: CLIENT Version: %04x\n", __FUNCTION__, pInterface->Header.Version)); pPdoExt->Interface.pXenHidContext = pInterface->Header.Context; pPdoExt->Interface.pXenHidOperations = pInterface->Operations.pXenHid; // Set the output server interface - PXENM2B_OPERATIONS pInterface->Header.Version = XENM2B_SERVER_INTERFACE_VERSION; TraceDebug(("%s: SERVER Version: %04x\n", __FUNCTION__, pInterface->Header.Version)); pInterface->Operations.pXenM2B = XenM2BGetInterfaceOperations(); pInterface->Header.Context = &pPdoExt->Interface; // Interface block is used as the context. pInterface->Header.InterfaceReference = XenM2BInterfaceReference; pInterface->Header.InterfaceDereference = XenM2BInterfaceDereference; // Finally call this once to set the state to referenced and initialize the spin lock. XenM2BInterfaceReference(&pPdoExt->Interface); pIrp->IoStatus.Information = 0; TraceDebug(("%s: <====\n", __FUNCTION__)); return STATUS_SUCCESS; }
PDEVICE_OBJECT XenM2BPdoCreate(PXENM2B_FDO_EXTENSION pFdoExt, PCHAR pDeviceName, UCHAR SlotID) { PDEVICE_OBJECT pDevice; PXENM2B_PDO_EXTENSION pPdoExt; NTSTATUS Status; size_t NameLength; ANSI_STRING AnsiName; ULONG Hash; Status = RtlStringCchLengthA(pDeviceName, XENM2B_PDO_NAME_LENGTH, &NameLength); if ((!NT_SUCCESS(Status))||(NameLength >= XENM2B_PDO_NAME_LENGTH)) { TraceError(("%s: Invalid device name, error: 0x%x length: 0x%x\n", __FUNCTION__, Status, NameLength)); return NULL; } if (NameLength == 0) { TraceError(("%s: Invalid empty device name\n", __FUNCTION__)); return NULL; } Status = IoCreateDevice(pFdoExt->pDriver, sizeof(XENM2B_PDO_EXTENSION), NULL, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN | FILE_AUTOGENERATED_DEVICE_NAME, FALSE, &pDevice); if (!NT_SUCCESS(Status)) { TraceError(("%s: Failed to create new PDO, error: 0x%x\n", __FUNCTION__, Status)); return NULL; } pPdoExt = (PXENM2B_PDO_EXTENSION)pDevice->DeviceExtension; RtlZeroMemory(pPdoExt, sizeof(XENM2B_PDO_EXTENSION)); pPdoExt->Type = XenM2BPdo; pPdoExt->pDevice = pDevice; // Convert the name to UNICODE and store as the device TEXT. AnsiName.Length = (USHORT)NameLength; AnsiName.MaximumLength = NameLength + sizeof(CHAR); AnsiName.Buffer = pDeviceName; pPdoExt->DeviceName.Length = 0; pPdoExt->DeviceName.MaximumLength = XENM2B_PDO_NAME_LENGTH * sizeof(WCHAR); pPdoExt->DeviceName.Buffer = pPdoExt->pDeviceNameW; Status = RtlAnsiStringToUnicodeString(&pPdoExt->DeviceName, &AnsiName, FALSE); if (!NT_SUCCESS(Status)) { TraceError(("%s: Failed to convert ANSI device name %s to UNICODE, error: 0x%x\n", __FUNCTION__, pDeviceName, Status)); IoDeleteDevice(pDevice); return NULL; } // Create a unique instance ID for this device RtlHashUnicodeString(&pPdoExt->DeviceName, FALSE, HASH_STRING_ALGORITHM_DEFAULT, &Hash); Status = RtlStringCchPrintfW(&pPdoExt->pInstanceIDW[0], (XENM2B_PDO_NAME_LENGTH - 1), L"XH%8.8XS%2.2X", Hash, SlotID); if (!NT_SUCCESS(Status)) { TraceError(("%s: Failed to create Instance ID for device %s, error: 0x%x\n", __FUNCTION__, pDeviceName, Status)); IoDeleteDevice(pDevice); return NULL; } RtlInitUnicodeString(&pPdoExt->InstanceID, pPdoExt->pInstanceIDW); TraceDebug(("%s: %p -> Device: %wZ Instance: %wZ\n", __FUNCTION__, pDevice, &pPdoExt->DeviceName, &pPdoExt->InstanceID)); ExInitializeFastMutex(&pPdoExt->DevicePnPState.PnPStateMutex); XenM2BSetPnPState(&pPdoExt->DevicePnPState, PnPStatePresent); pPdoExt->SystemPowerState = PowerSystemWorking; pPdoExt->DevicePowerState = PowerDeviceD3; pDevice->Flags &= ~DO_DEVICE_INITIALIZING; return pDevice; }