VOID XenUsb_EvtChildListScanForChildren(WDFCHILDLIST child_list) { NTSTATUS status; PXENUSB_DEVICE_DATA xudd = GetXudd(WdfChildListGetDevice(child_list)); XENUSB_PDO_IDENTIFICATION_DESCRIPTION child_description; CHAR path[128]; PCHAR value; ULONG i; FUNCTION_ENTER(); WdfChildListBeginScan(child_list); // hold the queue on each device and set each device to a pending state // read backend/num_ports //RtlStringCbPrintfA(path, ARRAY_SIZE(path), "%s/num-ports", xudd->vectors.backend_path); status = XnReadString(xudd->handle, XBT_NIL, path, &value); if (status != STATUS_SUCCESS) { WdfChildListEndScan(child_list); FUNCTION_MSG("Failed to read num-ports\n"); return; } xudd->num_ports = (ULONG)parse_numeric_string(value); XnFreeMem(xudd->handle, value); FUNCTION_MSG("num-ports = %d\n", xudd->num_ports); for (i = 0; i < 8; i++) { xudd->ports[i].port_number = i + 1; xudd->ports[i].port_type = USB_PORT_TYPE_NOT_CONNECTED; xudd->ports[i].port_status = 0; //1 << PORT_ENABLE; xudd->ports[i].port_change = 0x0000; } /* only a single root hub is enumerated */ WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(&child_description.header, sizeof(child_description)); child_description.device_number = 0; //TODO: get the proper index from parent status = WdfChildListAddOrUpdateChildDescriptionAsPresent(child_list, &child_description.header, NULL); if (!NT_SUCCESS(status)) { FUNCTION_MSG("WdfChildListAddOrUpdateChildDescriptionAsPresent failed with status 0x%08x\n", status); } WdfChildListEndScan(child_list); FUNCTION_EXIT(); }
VOID VIOSerialAddPort( IN WDFDEVICE Device, IN ULONG id ) { VIOSERIAL_PORT port; PPORTS_DEVICE pContext = GetPortsDevice(Device); NTSTATUS status = STATUS_SUCCESS; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,"%s DeviceId = %d :: PortId = %d\n", __FUNCTION__, pContext->DeviceId, id); WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT( &port.Header, sizeof(port) ); port.PortId = id; port.DeviceId = pContext->DeviceId; port.NameString.Buffer = NULL; port.NameString.Length = 0; port.NameString.MaximumLength = 0; port.InBuf = NULL; port.HostConnected = port.GuestConnected = FALSE; port.OutVqFull = FALSE; port.Removed = FALSE; port.BusDevice = Device; status = WdfChildListAddOrUpdateChildDescriptionAsPresent( WdfFdoGetDefaultChildList(Device), &port.Header, NULL ); if (status == STATUS_OBJECT_NAME_EXISTS) { TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "The description is already present in the list, the serial number is not unique.\n"); return; } TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "WdfChildListAddOrUpdateChildDescriptionAsPresent = 0x%x.\n", status); }
NTSTATUS Bus_PlugInDevice( _In_ WDFDEVICE Device, _In_ PWCHAR HardwareIds, _In_ size_t CchHardwareIds, _In_ ULONG SerialNo ) /*++ Routine Description: The user application has told us that a new device on the bus has arrived. We therefore create a description structure in stack, fill in information about the child device and call WdfChildListAddOrUpdateChildDescriptionAsPresent to add the device. --*/ { PDO_IDENTIFICATION_DESCRIPTION description; NTSTATUS status; PAGED_CODE (); // // Initialize the description with the information about the newly // plugged in device. // WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT( &description.Header, sizeof(description) ); description.SerialNo = SerialNo; description.CchHardwareIds = CchHardwareIds; description.HardwareIds = HardwareIds; // // Call the framework to add this child to the childlist. This call // will internaly call our DescriptionCompare callback to check // whether this device is a new device or existing device. If // it's a new device, the framework will call DescriptionDuplicate to create // a copy of this description in nonpaged pool. // The actual creation of the child device will happen when the framework // receives QUERY_DEVICE_RELATION request from the PNP manager in // response to InvalidateDeviceRelations call made as part of adding // a new child. // status = WdfChildListAddOrUpdateChildDescriptionAsPresent( WdfFdoGetDefaultChildList(Device), &description.Header, NULL); // AddressDescription if (status == STATUS_OBJECT_NAME_EXISTS) { // // The description is already present in the list, the serial number is // not unique, return error. // status = STATUS_INVALID_PARAMETER; } return status; }
VOID OsrFxEnumerateChildren( _In_ WDFDEVICE Device ) /*++ Routine Description: This routine configures a continuous reader on the interrupt endpoint. Arguments: Return Value: NT status value --*/ { WDFCHILDLIST list; UCHAR i; NTSTATUS status; PDEVICE_CONTEXT pDeviceContext; pDeviceContext = GetDeviceContext(Device); list = WdfFdoGetDefaultChildList(Device); WdfChildListBeginScan(list); // // A call to WdfChildListBeginScan indicates to the framework that the // driver is about to scan for dynamic children. If the driver doesn't // call either WdfChildListUpdateChildDescriptionAsPresent or // WdfChildListMarkAllChildDescriptionsPresent before WdfChildListEndScan is, // called, all the previously reported children will be reported as missing // to the PnP subsystem. // for(i=0; i< RTL_BITS_OF(UCHAR); i++) { // // Report every set bit in the switchstate as a child device. // if(pDeviceContext->CurrentSwitchState & (1<<i)) { PDO_IDENTIFICATION_DESCRIPTION description; // // Initialize the description with the information about the newly // plugged in device. // WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT( &description.Header, sizeof(description) ); // // Since switches are marked in the wrong order on the board, // we will fix it here so that the DM display matches with the // board. // description.SwitchNumber = RTL_BITS_OF(UCHAR)-i; TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "Switch %d is ON\n", description.SwitchNumber); // // Call the framework to add this child to the devicelist. This call // will internaly call our DescriptionCompare callback to check // whether this device is a new device or existing device. If // it's a new device, the framework will call DescriptionDuplicate to create // a copy of this description in nonpaged pool. // The actual creation of the child device will happen when the framework // receives QUERY_DEVICE_RELATION request from the PNP manager in // response to InvalidateDevice relation call made as part of adding // a new child. // status = WdfChildListAddOrUpdateChildDescriptionAsPresent( list, &description.Header, NULL); // AddressDescription if (status == STATUS_OBJECT_NAME_EXISTS) { } } } WdfChildListEndScan(list); return; }