VOID VIOSerialRemovePort( IN WDFDEVICE Device, IN PVIOSERIAL_PORT Port ) { WDFCHILDLIST PortList; NTSTATUS status; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s DeviceId: %d PortId: %d\n", __FUNCTION__, Port->DeviceId, Port->PortId); Port->Removed = TRUE; PortList = WdfFdoGetDefaultChildList(Device); status = WdfChildListUpdateChildDescriptionAsMissing(PortList, &Port->Header); if (status == STATUS_NO_SUCH_DEVICE) { TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "A device which does not exist was specified.\n", status); } TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- %s\n", __FUNCTION__); }
NTSTATUS Bus_UnPlugDevice( WDFDEVICE Device, ULONG SerialNo ) /*++ Routine Description: The application has told us a device has departed from the bus. We therefore need to flag the PDO as no longer present. Arguments: Returns: STATUS_SUCCESS upon successful removal from the list STATUS_INVALID_PARAMETER if the removal was unsuccessful --*/ { NTSTATUS status; WDFCHILDLIST list; PAGED_CODE (); list = WdfFdoGetDefaultChildList(Device); if (0 == SerialNo) { // // Unplug everybody. We do this by starting a scan and then not reporting // any children upon its completion // status = STATUS_SUCCESS; WdfChildListBeginScan(list); // // A call to WdfChildListBeginScan indicates to the framework that the // driver is about to scan for dynamic children. After this call has // returned, all previously reported children associated with this will be // marked as potentially missing. A call to either // WdfChildListUpdateChildDescriptionAsPresent or // WdfChildListMarkAllChildDescriptionsPresent will mark all previuosly // reported missing children as present. If any children currently // present are not reported present by calling // WdfChildListUpdateChildDescriptionAsPresent at the time of // WdfChildListEndScan, they will be reported as missing to the PnP subsystem // After WdfChildListEndScan call has returned, the framework will // invalidate the device relations for the FDO associated with the list // and report the changes // WdfChildListEndScan(list); } else { PDO_IDENTIFICATION_DESCRIPTION description; WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT( &description.Header, sizeof(description) ); description.SerialNo = SerialNo; // // WdfFdoUpdateChildDescriptionAsMissing indicates to the framework that a // child device that was previuosly detected is no longe present on the bus. // This API can be called by itself or after a call to WdfChildListBeginScan. // After this call has returned, the framework will invalidate the device // relations for the FDO associated with the list and report the changes. // status = WdfChildListUpdateChildDescriptionAsMissing(list, &description.Header); if (status == STATUS_NO_SUCH_DEVICE) { // // serial number didn't exist. Remap it to a status that user // application can understand when it gets translated to win32 // error code. // status = STATUS_INVALID_PARAMETER; } } return status; }