NTSTATUS OnD0Entry( _In_ WDFDEVICE FxDevice, _In_ WDF_POWER_DEVICE_STATE FxPreviousState ) /*++ Routine Description: This routine allocates objects needed by the driver. Arguments: FxDevice - a handle to the framework device object FxPreviousState - previous power state Return Value: Status --*/ { FuncEntry(TRACE_FLAG_WDFLOADING); UNREFERENCED_PARAMETER(FxPreviousState); PDEVICE_CONTEXT pDevice = GetDeviceContext(FxDevice); NTSTATUS status = STATUS_SUCCESS; WdfTimerStart(pDevice->Timer, WDF_REL_TIMEOUT_IN_MS(10)); BOOTTRACKPAD(pDevice); pDevice->RegsSet = false; pDevice->ConnectInterrupt = true; FuncExit(TRACE_FLAG_WDFLOADING); return status; }
VOID OnIoDeviceControl( _In_ WDFQUEUE FxQueue, _In_ WDFREQUEST FxRequest, _In_ size_t OutputBufferLength, _In_ size_t InputBufferLength, _In_ ULONG IoControlCode ) /*++ Routine Description: This event is called when the framework receives IRP_MJ_DEVICE_CONTROL requests from the system. Arguments: FxQueue - Handle to the framework queue object that is associated with the I/O request. FxRequest - Handle to a framework request object. OutputBufferLength - length of the request's output buffer, if an output buffer is available. InputBufferLength - length of the request's input buffer, if an input buffer is available. IoControlCode - the driver-defined or system-defined I/O control code (IOCTL) that is associated with the request. Return Value: VOID --*/ { FuncEntry(TRACE_FLAG_SPBAPI); WDFDEVICE device; PDEVICE_CONTEXT pDevice; BOOLEAN fSync = FALSE; NTSTATUS status = STATUS_SUCCESS; UNREFERENCED_PARAMETER(OutputBufferLength); UNREFERENCED_PARAMETER(InputBufferLength); device = WdfIoQueueGetDevice(FxQueue); pDevice = GetDeviceContext(device); CyapaPrint( DEBUG_LEVEL_INFO, DBG_IOCTL, "DeviceIoControl request %p received with IOCTL=%lu", FxRequest, IoControlCode); CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "%s, Queue:0x%p, Request:0x%p\n", DbgHidInternalIoctlString(IoControlCode), FxQueue, FxRequest ); // // Translate the test IOCTL into the appropriate // SPB API method. Open and close are completed // synchronously. // switch (IoControlCode) { case IOCTL_HID_GET_DEVICE_DESCRIPTOR: // // Retrieves the device's HID descriptor. // status = CyapaGetHidDescriptor(device, FxRequest); fSync = TRUE; break; case IOCTL_HID_GET_DEVICE_ATTRIBUTES: // //Retrieves a device's attributes in a HID_DEVICE_ATTRIBUTES structure. // status = CyapaGetDeviceAttributes(FxRequest); fSync = TRUE; break; case IOCTL_HID_GET_REPORT_DESCRIPTOR: // //Obtains the report descriptor for the HID device. // status = CyapaGetReportDescriptor(device, FxRequest); fSync = TRUE; break; case IOCTL_HID_GET_STRING: // // Requests that the HID minidriver retrieve a human-readable string // for either the manufacturer ID, the product ID, or the serial number // from the string descriptor of the device. The minidriver must send // a Get String Descriptor request to the device, in order to retrieve // the string descriptor, then it must extract the string at the // appropriate index from the string descriptor and return it in the // output buffer indicated by the IRP. Before sending the Get String // Descriptor request, the minidriver must retrieve the appropriate // index for the manufacturer ID, the product ID or the serial number // from the device extension of a top level collection associated with // the device. // status = CyapaGetString(FxRequest); fSync = TRUE; break; case IOCTL_HID_WRITE_REPORT: case IOCTL_HID_SET_OUTPUT_REPORT: // //Transmits a class driver-supplied report to the device. // status = BOOTTRACKPAD(pDevice); if (!NT_SUCCESS(status)){ CyapaPrint(DBG_IOCTL, DEBUG_LEVEL_ERROR, "Error booting Cyapa device!\n"); } fSync = TRUE; break; case IOCTL_HID_READ_REPORT: case IOCTL_HID_GET_INPUT_REPORT: // // Returns a report from the device into a class driver-supplied buffer. // status = CyapaReadReport(pDevice, FxRequest, &fSync); break; case IOCTL_HID_GET_FEATURE: // // returns a feature report associated with a top-level collection // status = CyapaGetFeature(pDevice, FxRequest, &fSync); break; case IOCTL_HID_ACTIVATE_DEVICE: // // Makes the device ready for I/O operations. // case IOCTL_HID_DEACTIVATE_DEVICE: // // Causes the device to cease operations and terminate all outstanding // I/O requests. // default: fSync = TRUE; status = STATUS_NOT_SUPPORTED; CyapaPrint( DEBUG_LEVEL_INFO, DBG_IOCTL, "Request %p received with unexpected IOCTL=%lu", FxRequest, IoControlCode); } // // Complete the request if necessary. // if (fSync) { CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "%s completed, Queue:0x%p, Request:0x%p\n", DbgHidInternalIoctlString(IoControlCode), FxQueue, FxRequest ); WdfRequestComplete(FxRequest, status); } else { CyapaPrint(DEBUG_LEVEL_INFO, DBG_IOCTL, "%s deferred, Queue:0x%p, Request:0x%p\n", DbgHidInternalIoctlString(IoControlCode), FxQueue, FxRequest ); } FuncExit(TRACE_FLAG_SPBAPI); }