ReactOS 0.4.16-dev-1163-gec5b142
pdo.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Universal Serial Bus Bulk Enhanced Host Controller Interface
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: drivers/usb/usbccgp/pdo.c
5 * PURPOSE: USB device driver.
6 * PROGRAMMERS:
7 * Michael Martin (michael.martin@reactos.org)
8 * Johannes Anderwald (johannes.anderwald@reactos.org)
9 * Cameron Gutman
10 */
11
12#include "usbccgp.h"
13
14#include <ntddk.h>
15
16#define NDEBUG
17#include <debug.h>
18
22 IN OUT PIRP Irp)
23{
24 PIO_STACK_LOCATION IoStack;
26 PPDO_DEVICE_EXTENSION PDODeviceExtension;
27 LPWSTR GenericString = L"Composite USB Device";
28
29 //
30 // get current irp stack location
31 //
33
34 //
35 // get device extension
36 //
37 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
38
39 //
40 // check if type is description
41 //
42 if (IoStack->Parameters.QueryDeviceText.DeviceTextType != DeviceTextDescription)
43 {
44 //
45 // we only handle description
46 //
47 return Irp->IoStatus.Status;
48 }
49
50 //
51 // is there a device description
52 //
53 if (PDODeviceExtension->FunctionDescriptor->FunctionDescription.Length)
54 {
55 //
56 // allocate buffer
57 //
58 Buffer = AllocateItem(NonPagedPool, PDODeviceExtension->FunctionDescriptor->FunctionDescription.Length + sizeof(WCHAR));
59 if (!Buffer)
60 {
61 //
62 // no memory
63 //
65 }
66
67 //
68 // copy buffer
69 //
70 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
71 RtlCopyMemory(Buffer, PDODeviceExtension->FunctionDescriptor->FunctionDescription.Buffer, PDODeviceExtension->FunctionDescriptor->FunctionDescription.Length);
72 return STATUS_SUCCESS;
73 }
74
75 //
76 // FIXME use GenericCompositeUSBDeviceString
77 //
79 Buffer = AllocateItem(PagedPool, (wcslen(GenericString) + 1) * sizeof(WCHAR));
80 if (!Buffer)
81 {
82 //
83 // no memory
84 //
86 }
87 RtlCopyMemory(Buffer, GenericString, (wcslen(GenericString) + 1) * sizeof(WCHAR));
88 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
89
90 return STATUS_SUCCESS;
91}
92
96 IN OUT PIRP Irp)
97{
98 PDEVICE_RELATIONS DeviceRelations;
99 PIO_STACK_LOCATION IoStack;
100
101 DPRINT("USBCCGP_PdoHandleDeviceRelations\n");
102
103 //
104 // get current irp stack location
105 //
107
108 //
109 // check if relation type is BusRelations
110 //
112 {
113 //
114 // PDO handles only target device relation
115 //
116 return Irp->IoStatus.Status;
117 }
118
119 //
120 // allocate device relations
121 //
122 DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS));
123 if (!DeviceRelations)
124 {
125 //
126 // no memory
127 //
129 }
130
131 //
132 // initialize device relations
133 //
134 DeviceRelations->Count = 1;
135 DeviceRelations->Objects[0] = DeviceObject;
137
138 //
139 // store result
140 //
141 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
142
143 //
144 // completed successfully
145 //
146 return STATUS_SUCCESS;
147}
148
151 IN LPWSTR DeviceId,
153 OUT LPWSTR *OutString)
154{
155 ULONG Length = 0, StringLength;
157
158 //
159 // count length of string
160 //
161 String = DeviceId;
162 while (*String)
163 {
164 StringLength = wcslen(String) + 1;
165 Length += StringLength;
166 Length += 6; //&MI_XX
167 String += StringLength;
168 }
169
170 //
171 // now allocate the buffer
172 //
173 String = AllocateItem(NonPagedPool, (Length + 2) * sizeof(WCHAR));
174 if (!String)
175 {
176 //
177 // no memory
178 //
180 }
181
182 //
183 // store result
184 //
185 *OutString = String;
186
187 while (*DeviceId)
188 {
189 StringLength = swprintf(String, L"%s&MI_%02x", DeviceId, InterfaceNumber) + 1;
190 Length = wcslen(DeviceId) + 1;
191 DPRINT("String %p\n", String);
192
193 //
194 // next string
195 //
196 String += StringLength;
197 DeviceId += Length;
198 }
199
200 //
201 // success
202 //
203 return STATUS_SUCCESS;
204}
205
206
210 PIRP Irp)
211{
212 PIO_STACK_LOCATION IoStack;
213 PUNICODE_STRING DeviceString = NULL;
214 PPDO_DEVICE_EXTENSION PDODeviceExtension;
217
218 //
219 // get current irp stack location
220 //
222
223 //
224 // get device extension
225 //
226 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
227
228
229 if (IoStack->Parameters.QueryId.IdType == BusQueryDeviceID)
230 {
231 //
232 // handle query device id
233 //
234 if (IoForwardIrpSynchronously(PDODeviceExtension->NextDeviceObject, Irp))
235 {
236 Status = Irp->IoStatus.Status;
237 }
238 else
239 {
241 }
242
243 if (NT_SUCCESS(Status))
244 {
245 //
246 // allocate buffer
247 //
248 Buffer = AllocateItem(NonPagedPool, (wcslen((LPWSTR)Irp->IoStatus.Information) + 7) * sizeof(WCHAR));
249 if (Buffer)
250 {
251 //
252 // append interface number
253 //
254 ASSERT(Irp->IoStatus.Information);
255 swprintf(Buffer, L"%s&MI_%02x", (LPWSTR)Irp->IoStatus.Information, PDODeviceExtension->FunctionDescriptor->FunctionNumber);
256 DPRINT("BusQueryDeviceID %S\n", Buffer);
257
258 ExFreePool((PVOID)Irp->IoStatus.Information);
259 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
260 }
261 else
262 {
263 //
264 // no memory
265 //
267 }
268 }
269 return Status;
270 }
271 else if (IoStack->Parameters.QueryId.IdType == BusQueryHardwareIDs)
272 {
273 //
274 // handle instance id
275 //
276 DeviceString = &PDODeviceExtension->FunctionDescriptor->HardwareId;
277 }
278 else if (IoStack->Parameters.QueryId.IdType == BusQueryInstanceID)
279 {
280 //
281 // handle instance id
282 //
283 Buffer = AllocateItem(NonPagedPool, 5 * sizeof(WCHAR));
284 if (!Buffer)
285 {
286 //
287 // no memory
288 //
290 }
291
292 //
293 // use function number
294 //
295 swprintf(Buffer, L"%04x", PDODeviceExtension->FunctionDescriptor->FunctionNumber);
296 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
297 return STATUS_SUCCESS;
298 }
299 else if (IoStack->Parameters.QueryId.IdType == BusQueryCompatibleIDs)
300 {
301 //
302 // handle instance id
303 //
304 DeviceString = &PDODeviceExtension->FunctionDescriptor->CompatibleId;
305 }
306 else
307 {
308 //
309 // unsupported query
310 //
311 return Irp->IoStatus.Status;
312 }
313
314 //
315 // sanity check
316 //
317 ASSERT(DeviceString != NULL);
318
319 //
320 // allocate buffer
321 //
322 Buffer = AllocateItem(NonPagedPool, DeviceString->Length + sizeof(WCHAR));
323 if (!Buffer)
324 {
325 //
326 // no memory
327 //
329 }
330
331 //
332 // copy buffer
333 //
334 RtlCopyMemory(Buffer, DeviceString->Buffer, DeviceString->Length);
335 Buffer[DeviceString->Length / sizeof(WCHAR)] = UNICODE_NULL;
336 Irp->IoStatus.Information = (ULONG_PTR)Buffer;
337
338 return STATUS_SUCCESS;
339}
340
344 PIRP Irp)
345{
346 PIO_STACK_LOCATION IoStack;
347 PPDO_DEVICE_EXTENSION PDODeviceExtension;
349 ULONG Index, bFound;
350
351 //
352 // get current stack location
353 //
355
356 //
357 // get device extension
358 //
359 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
360
361 //
362 // sanity check
363 //
364 ASSERT(PDODeviceExtension->Common.IsFDO == FALSE);
365
366 switch(IoStack->MinorFunction)
367 {
369 {
370 //
371 // handle device relations
372 //
374 break;
375 }
377 {
378 //
379 // handle query device text
380 //
382 break;
383 }
384 case IRP_MN_QUERY_ID:
385 {
386 //
387 // handle request
388 //
390 break;
391 }
393 {
394 //
395 // remove us from the fdo's pdo list
396 //
397 bFound = FALSE;
398 for(Index = 0; Index < PDODeviceExtension->FDODeviceExtension->FunctionDescriptorCount; Index++)
399 {
400 if (PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] == DeviceObject)
401 {
402 //
403 // remove us
404 //
405 PDODeviceExtension->FDODeviceExtension->ChildPDO[Index] = NULL;
406 bFound = TRUE;
407 break;
408 }
409 }
410
411 //
412 // Complete the IRP
413 //
414 Irp->IoStatus.Status = STATUS_SUCCESS;
416
417 if (bFound)
418 {
419 //
420 // Delete the device object
421 //
423 }
424 return STATUS_SUCCESS;
425 }
427 {
428 //
429 // copy device capabilities
430 //
431 RtlCopyMemory(IoStack->Parameters.DeviceCapabilities.Capabilities, &PDODeviceExtension->Capabilities, sizeof(DEVICE_CAPABILITIES));
432
433 /* Complete the IRP */
434 Irp->IoStatus.Status = STATUS_SUCCESS;
436 return STATUS_SUCCESS;
437 }
440 {
441 //
442 // sure
443 //
445 break;
446 }
448 {
449 //
450 // no-op for PDO
451 //
452 DPRINT("[USBCCGP] PDO IRP_MN_START\n");
454 break;
455 }
457 {
458 //
459 // forward to lower device object
460 //
462 return IoCallDriver(PDODeviceExtension->NextDeviceObject, Irp);
463 }
464 default:
465 {
466 //
467 // do nothing
468 //
469 Status = Irp->IoStatus.Status;
470 break;
471 }
472 }
473
474 //
475 // complete request
476 //
477 if (Status != STATUS_PENDING)
478 {
479 //
480 // store result
481 //
482 Irp->IoStatus.Status = Status;
483
484 //
485 // complete request
486 //
488 }
489
490 //
491 // done processing
492 //
493 return Status;
494
495}
496
500 PIRP Irp)
501{
502 PIO_STACK_LOCATION IoStack;
503 PPDO_DEVICE_EXTENSION PDODeviceExtension;
504 PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor;
506 ULONG TotalSize, Index;
507 ULONG Size;
508 PURB Urb;
510 PUCHAR BufferPtr;
512
513 //
514 // get current stack location
515 //
517
518 DPRINT("USBCCGP_BuildConfigurationDescriptor\n");
519
520 //
521 // get device extension
522 //
523 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
524
525 //
526 // get configuration descriptor
527 //
528 ConfigurationDescriptor = PDODeviceExtension->ConfigurationDescriptor;
529
530 //
531 // calculate size of configuration descriptor
532 //
533 TotalSize = sizeof(USB_CONFIGURATION_DESCRIPTOR);
534
535 for (Index = 0; Index < PDODeviceExtension->FunctionDescriptor->NumberOfInterfaces; Index++)
536 {
537 //
538 // get current interface descriptor
539 //
540 InterfaceDescriptor = PDODeviceExtension->FunctionDescriptor->InterfaceDescriptorList[Index];
541 InterfaceNumber = InterfaceDescriptor->bInterfaceNumber;
542
543 //
544 // add to size and move to next descriptor
545 //
546 TotalSize += InterfaceDescriptor->bLength;
548
549 do
550 {
551 if ((ULONG_PTR)InterfaceDescriptor >= ((ULONG_PTR)ConfigurationDescriptor + ConfigurationDescriptor->wTotalLength))
552 {
553 //
554 // reached end of configuration descriptor
555 //
556 break;
557 }
558
559 //
560 // association descriptors are removed
561 //
563 {
565 {
566 if (InterfaceNumber != InterfaceDescriptor->bInterfaceNumber)
567 {
568 //
569 // reached next descriptor
570 //
571 break;
572 }
573
574 //
575 // include alternate descriptor
576 //
577 }
578
579 //
580 // append size
581 //
582 TotalSize += InterfaceDescriptor->bLength;
583 }
584
585 //
586 // move to next descriptor
587 //
589 } while(TRUE);
590 }
591
592 //
593 // now allocate temporary buffer for the configuration descriptor
594 //
595 Buffer = AllocateItem(NonPagedPool, TotalSize);
596 if (!Buffer)
597 {
598 //
599 // failed to allocate buffer
600 //
601 DPRINT1("[USBCCGP] Failed to allocate %lu Bytes\n", TotalSize);
603 }
604
605 //
606 // first copy the configuration descriptor
607 //
608 RtlCopyMemory(Buffer, ConfigurationDescriptor, sizeof(USB_CONFIGURATION_DESCRIPTOR));
609 BufferPtr = (PUCHAR)((ULONG_PTR)Buffer + ConfigurationDescriptor->bLength);
610
611 for (Index = 0; Index < PDODeviceExtension->FunctionDescriptor->NumberOfInterfaces; Index++)
612 {
613 //
614 // get current interface descriptor
615 //
616 InterfaceDescriptor = PDODeviceExtension->FunctionDescriptor->InterfaceDescriptorList[Index];
617 InterfaceNumber = InterfaceDescriptor->bInterfaceNumber;
618
619 //
620 // copy descriptor and move to next descriptor
621 //
623 BufferPtr += InterfaceDescriptor->bLength;
625
626 do
627 {
628 if ((ULONG_PTR)InterfaceDescriptor >= ((ULONG_PTR)ConfigurationDescriptor + ConfigurationDescriptor->wTotalLength))
629 {
630 //
631 // reached end of configuration descriptor
632 //
633 break;
634 }
635
636 //
637 // association descriptors are removed
638 //
640 {
642 {
643 if (InterfaceNumber != InterfaceDescriptor->bInterfaceNumber)
644 {
645 //
646 // reached next descriptor
647 //
648 break;
649 }
650
651 //
652 // include alternate descriptor
653 //
654 DPRINT("InterfaceDescriptor %p Alternate %x InterfaceNumber %x\n", InterfaceDescriptor, InterfaceDescriptor->bAlternateSetting, InterfaceDescriptor->bInterfaceNumber);
655 }
656
657 //
658 // copy descriptor
659 //
661 BufferPtr += InterfaceDescriptor->bLength;
662 }
663
664 //
665 // move to next descriptor
666 //
668 } while(TRUE);
669 }
670
671 //
672 // modify configuration descriptor
673 //
674 ConfigurationDescriptor = Buffer;
675 ConfigurationDescriptor->wTotalLength = (USHORT)TotalSize;
676 ConfigurationDescriptor->bNumInterfaces = PDODeviceExtension->FunctionDescriptor->NumberOfInterfaces;
677
678 //
679 // get urb
680 //
681 Urb = (PURB)IoStack->Parameters.Others.Argument1;
682 ASSERT(Urb);
683
684 //
685 // copy descriptor
686 //
687 Size = min(TotalSize, Urb->UrbControlDescriptorRequest.TransferBufferLength);
689
690 //
691 // store final size
692 //
693 Urb->UrbControlDescriptorRequest.TransferBufferLength = Size;
694
695 //
696 // free buffer
697 //
699
700 //
701 // done
702 //
703 return STATUS_SUCCESS;
704}
705
709 PIRP Irp)
710{
711 PIO_STACK_LOCATION IoStack;
712 PPDO_DEVICE_EXTENSION PDODeviceExtension;
713 PURB Urb, NewUrb;
714 PUSBD_INTERFACE_INFORMATION InterfaceInformation;
717 ULONG NeedSelect, FoundInterface;
719
720 //
721 // get current stack location
722 //
724
725 //
726 // get device extension
727 //
728 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
729
730 //
731 // get urb
732 //
733 Urb = (PURB)IoStack->Parameters.Others.Argument1;
734 ASSERT(Urb);
735
736 //
737 // is there already an configuration handle
738 //
739 if (Urb->UrbSelectConfiguration.ConfigurationHandle)
740 {
741 //
742 // nothing to do
743 //
744 return STATUS_SUCCESS;
745 }
746
747 //
748 // if there is no configuration descriptor, unconfigure the device
749 //
750 if (Urb->UrbSelectConfiguration.ConfigurationDescriptor == NULL)
751 {
752 return STATUS_SUCCESS;
753 }
754
755 // sanity checks
756 //C_ASSERT(sizeof(struct _URB_HEADER) == 16);
757 //C_ASSERT(FIELD_OFFSET(struct _URB_SELECT_CONFIGURATION, Interface.Length) == 24);
758 //C_ASSERT(sizeof(USBD_INTERFACE_INFORMATION) == 36);
759 //C_ASSERT(sizeof(struct _URB_SELECT_CONFIGURATION) == 0x3C);
760
761 // available buffer length
763
764 //
765 // check all interfaces
766 //
767 InterfaceInformation = &Urb->UrbSelectConfiguration.Interface;
768
769 Entry = NULL;
770 do
771 {
772 DPRINT1("[USBCCGP] SelectConfiguration Function %x InterfaceNumber %x Alternative %x Length %lu InterfaceInformation->Length %lu\n",
773 PDODeviceExtension->FunctionDescriptor->FunctionNumber, InterfaceInformation->InterfaceNumber, InterfaceInformation->AlternateSetting, Length, InterfaceInformation->Length);
774 ASSERT(InterfaceInformation->Length);
775 //
776 // search for the interface in the local interface list
777 //
778 FoundInterface = FALSE;
779 for (InterfaceIndex = 0; InterfaceIndex < PDODeviceExtension->FunctionDescriptor->NumberOfInterfaces; InterfaceIndex++)
780 {
781 if (PDODeviceExtension->FunctionDescriptor->InterfaceDescriptorList[InterfaceIndex]->bInterfaceNumber == InterfaceInformation->InterfaceNumber)
782 {
783 // found interface entry
784 FoundInterface = TRUE;
785 break;
786 }
787 }
788
789 if (!FoundInterface)
790 {
791 //
792 // invalid parameter
793 //
794 DPRINT1("InterfaceInformation InterfaceNumber %x Alternative %x NumberOfPipes %x not found\n", InterfaceInformation->InterfaceNumber, InterfaceInformation->AlternateSetting, InterfaceInformation->NumberOfPipes);
796 }
797
798 //
799 // now query the total interface list
800 //
801 Entry = NULL;
802 for (InterfaceIndex = 0; InterfaceIndex < PDODeviceExtension->InterfaceListCount; InterfaceIndex++)
803 {
804 if (PDODeviceExtension->InterfaceList[InterfaceIndex].Interface->InterfaceNumber == InterfaceInformation->InterfaceNumber)
805 {
806 //
807 // found entry
808 //
809 Entry = &PDODeviceExtension->InterfaceList[InterfaceIndex];
810 }
811 }
812
813 //
814 // sanity check
815 //
816 ASSERT(Entry);
817 if (!Entry)
818 {
819 //
820 // corruption detected
821 //
822 KeBugCheck(0);
823 }
824
825 NeedSelect = FALSE;
826 if (Entry->InterfaceDescriptor->bAlternateSetting == InterfaceInformation->AlternateSetting)
827 {
828 for(InterfaceIndex = 0; InterfaceIndex < InterfaceInformation->NumberOfPipes; InterfaceIndex++)
829 {
830 if (InterfaceInformation->Pipes[InterfaceIndex].MaximumTransferSize != Entry->Interface->Pipes[InterfaceIndex].MaximumTransferSize)
831 {
832 //
833 // changed interface
834 //
835 NeedSelect = TRUE;
836 }
837 }
838 }
839 else
840 {
841 //
842 // need select as the interface number differ
843 //
844 NeedSelect = TRUE;
845 }
846
847 if (!NeedSelect)
848 {
849 //
850 // interface is already selected
851 //
852 ASSERT(Length >= Entry->Interface->Length);
853 RtlCopyMemory(InterfaceInformation, Entry->Interface, Entry->Interface->Length);
854
855 //
856 // adjust remaining buffer size
857 //
858 ASSERT(Entry->Interface->Length);
859 Length -= Entry->Interface->Length;
860
861 //
862 // move to next output interface information
863 //
864 InterfaceInformation = (PUSBD_INTERFACE_INFORMATION)((ULONG_PTR)InterfaceInformation + Entry->Interface->Length);
865 }
866 else
867 {
868 //
869 // select interface
870 //
871 DPRINT1("Selecting InterfaceIndex %lu AlternateSetting %lu NumberOfPipes %lu\n", InterfaceInformation->InterfaceNumber, InterfaceInformation->AlternateSetting, InterfaceInformation->NumberOfPipes);
872 ASSERT(InterfaceInformation->Length == Entry->Interface->Length);
873
874 //
875 // build urb
876 //
878 if (!NewUrb)
879 {
880 //
881 // no memory
882 //
884 }
885
886 //
887 // now prepare interface urb
888 //
889 UsbBuildSelectInterfaceRequest(NewUrb, (USHORT)GET_SELECT_INTERFACE_REQUEST_SIZE(InterfaceInformation->NumberOfPipes), PDODeviceExtension->ConfigurationHandle, InterfaceInformation->InterfaceNumber, InterfaceInformation->AlternateSetting);
890
891 //
892 // now select the interface
893 //
894 Status = USBCCGP_SyncUrbRequest(PDODeviceExtension->NextDeviceObject, NewUrb);
895 DPRINT1("SelectInterface Status %x\n", Status);
896
897 if (!NT_SUCCESS(Status))
898 {
899 //
900 // failed
901 //
902 break;
903 }
904
905 //
906 // update configuration info
907 //
908 ASSERT(Entry->Interface->Length >= NewUrb->UrbSelectInterface.Interface.Length);
909 ASSERT(Length >= NewUrb->UrbSelectInterface.Interface.Length);
910 RtlCopyMemory(Entry->Interface, &NewUrb->UrbSelectInterface.Interface, NewUrb->UrbSelectInterface.Interface.Length);
911
912 //
913 // update provided interface information
914 //
915 ASSERT(Length >= Entry->Interface->Length);
916 RtlCopyMemory(InterfaceInformation, Entry->Interface, Entry->Interface->Length);
917
918 //
919 // decrement remaining buffer size
920 //
921 ASSERT(Entry->Interface->Length);
922 Length -= Entry->Interface->Length;
923
924 //
925 // adjust output buffer offset
926 //
927 InterfaceInformation = (PUSBD_INTERFACE_INFORMATION)((ULONG_PTR)InterfaceInformation + Entry->Interface->Length);
928
929 //
930 // free urb
931 //
932 FreeItem(NewUrb);
933 }
934
935 } while(Length);
936
937 //
938 // store configuration handle
939 //
940 Urb->UrbSelectConfiguration.ConfigurationHandle = PDODeviceExtension->ConfigurationHandle;
941
942 DPRINT1("[USBCCGP] SelectConfiguration Function %x Completed\n", PDODeviceExtension->FunctionDescriptor->FunctionNumber);
943
944 //
945 // done
946 //
947 return STATUS_SUCCESS;
948}
949
953 PIRP Irp)
954{
955 PIO_STACK_LOCATION IoStack;
956 PPDO_DEVICE_EXTENSION PDODeviceExtension;
958 PURB Urb;
959
960 //
961 // get current stack location
962 //
964
965 //
966 // get device extension
967 //
968 PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
969
971 {
972 //
973 // get urb
974 //
975 Urb = (PURB)IoStack->Parameters.Others.Argument1;
976 ASSERT(Urb);
977 DPRINT("IOCTL_INTERNAL_USB_SUBMIT_URB Function %x\n", Urb->UrbHeader.Function);
978
979 if (Urb->UrbHeader.Function == URB_FUNCTION_SELECT_CONFIGURATION)
980 {
981 //
982 // select configuration
983 //
985 Irp->IoStatus.Status = Status;
987 return Status;
988 }
989 else if (Urb->UrbHeader.Function == URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE)
990 {
992 {
993 //
994 // is the buffer big enough
995 //
996 if (Urb->UrbControlDescriptorRequest.TransferBufferLength < sizeof(USB_DEVICE_DESCRIPTOR))
997 {
998 //
999 // invalid buffer size
1000 //
1001 DPRINT1("[USBCCGP] invalid device descriptor size %lu\n", Urb->UrbControlDescriptorRequest.TransferBufferLength);
1002 Urb->UrbControlDescriptorRequest.TransferBufferLength = sizeof(USB_DEVICE_DESCRIPTOR);
1003 Irp->IoStatus.Status = STATUS_INVALID_BUFFER_SIZE;
1006 }
1007
1008 //
1009 // copy device descriptor
1010 //
1011 ASSERT(Urb->UrbControlDescriptorRequest.TransferBuffer);
1012 RtlCopyMemory(Urb->UrbControlDescriptorRequest.TransferBuffer, &PDODeviceExtension->DeviceDescriptor, sizeof(USB_DEVICE_DESCRIPTOR));
1013 Irp->IoStatus.Status = STATUS_SUCCESS;
1015 return STATUS_SUCCESS;
1016 }
1017 else if (Urb->UrbControlDescriptorRequest.DescriptorType == USB_CONFIGURATION_DESCRIPTOR_TYPE)
1018 {
1019 //
1020 // build configuration descriptor
1021 //
1023 Irp->IoStatus.Status = Status;
1025 return Status;
1026 }
1027 else if (Urb->UrbControlDescriptorRequest.DescriptorType == USB_STRING_DESCRIPTOR_TYPE)
1028 {
1029 PUSB_STRING_DESCRIPTOR StringDescriptor;
1030
1031 //
1032 // get the requested string descriptor
1033 //
1034 ASSERT(Urb->UrbControlDescriptorRequest.TransferBuffer);
1035 Status = USBCCGP_GetDescriptor(PDODeviceExtension->FDODeviceExtension->NextDeviceObject,
1037 Urb->UrbControlDescriptorRequest.TransferBufferLength,
1038 Urb->UrbControlDescriptorRequest.Index,
1039 Urb->UrbControlDescriptorRequest.LanguageId,
1040 (PVOID*)&StringDescriptor);
1041 if (NT_SUCCESS(Status))
1042 {
1043 if (StringDescriptor->bLength == 2)
1044 {
1045 FreeItem(StringDescriptor);
1047 }
1048 else
1049 {
1050 RtlCopyMemory(Urb->UrbControlDescriptorRequest.TransferBuffer,
1051 StringDescriptor->bString,
1052 StringDescriptor->bLength + sizeof(WCHAR));
1053 FreeItem(StringDescriptor);
1055 }
1056 }
1057 Irp->IoStatus.Status = Status;
1059 return Status;
1060 }
1061 }
1062 else
1063 {
1065 Status = IoCallDriver(PDODeviceExtension->NextDeviceObject, Irp);
1066 return Status;
1067 }
1068 }
1069 else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_GET_PORT_STATUS)
1070 {
1072 Status = IoCallDriver(PDODeviceExtension->NextDeviceObject, Irp);
1073 return Status;
1074 }
1075 else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT)
1076 {
1078 Status = IoCallDriver(PDODeviceExtension->NextDeviceObject, Irp);
1079 return Status;
1080 }
1081 else if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_CYCLE_PORT)
1082 {
1084 Status = IoCallDriver(PDODeviceExtension->NextDeviceObject, Irp);
1085 return Status;
1086 }
1087
1088 DPRINT1("IOCTL %x\n", IoStack->Parameters.DeviceIoControl.IoControlCode);
1089 DPRINT1("InputBufferLength %lu\n", IoStack->Parameters.DeviceIoControl.InputBufferLength);
1090 DPRINT1("OutputBufferLength %lu\n", IoStack->Parameters.DeviceIoControl.OutputBufferLength);
1091 DPRINT1("Type3InputBuffer %p\n", IoStack->Parameters.DeviceIoControl.Type3InputBuffer);
1092
1093 ASSERT(FALSE);
1094
1095 Irp->IoStatus.Status = STATUS_NOT_IMPLEMENTED;
1098}
1099
1103 PIRP Irp)
1104{
1106 PIO_STACK_LOCATION IoStack;
1107
1109
1110 switch (IoStack->MinorFunction)
1111 {
1112 case IRP_MN_SET_POWER:
1113 case IRP_MN_QUERY_POWER:
1114 Irp->IoStatus.Status = STATUS_SUCCESS;
1115 break;
1116 }
1117
1118 Status = Irp->IoStatus.Status;
1121 return Status;
1122}
1123
1124
1128 PIRP Irp)
1129{
1130 PIO_STACK_LOCATION IoStack;
1132
1133 /* get stack location */
1135
1136 switch(IoStack->MajorFunction)
1137 {
1138 case IRP_MJ_PNP:
1142 case IRP_MJ_POWER:
1144 default:
1145 DPRINT1("PDO_Dispatch Function %x not implemented\n", IoStack->MajorFunction);
1146 Status = Irp->IoStatus.Status;
1148 return Status;
1149 }
1150}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
DECLSPEC_NORETURN VOID NTAPI KeBugCheck(ULONG BugCheckCode)
Definition: bug.c:1434
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_PENDING
Definition: d3dkmdt.h:43
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define swprintf
Definition: precomp.h:40
struct _PDO_DEVICE_EXTENSION * PPDO_DEVICE_EXTENSION
#define ULONG_PTR
Definition: config.h:101
NTSTATUS NTAPI USBCCGP_GetDescriptor(IN PDEVICE_OBJECT DeviceObject, IN UCHAR DescriptorType, IN ULONG DescriptorLength, IN UCHAR DescriptorIndex, IN LANGID LanguageId, OUT PVOID *OutDescriptor)
Definition: descriptor.c:19
NTSTATUS USBCCGP_SyncUrbRequest(IN PDEVICE_OBJECT DeviceObject, OUT PURB UrbRequest)
Definition: misc.c:35
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
PVOID AllocateItem(IN POOL_TYPE PoolType, IN SIZE_T NumberOfBytes)
Definition: misc.c:29
VOID FreeItem(IN PVOID Item)
Definition: misc.c:37
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
#define min(a, b)
Definition: monoChain.cc:55
#define UNICODE_NULL
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1251
#define IoCompleteRequest
Definition: irp.c:1240
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
#define IoCallDriver
Definition: irp.c:1225
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
#define STATUS_INVALID_BUFFER_SIZE
Definition: ntstatus.h:650
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
base of all file and directory entries
Definition: entries.h:83
PDEVICE_OBJECT Objects[1]
Definition: iotypes.h:2163
union _IO_STACK_LOCATION::@1620 Parameters
struct _IO_STACK_LOCATION::@4107::@4132 QueryDeviceRelations
struct _IO_STACK_LOCATION::@4107::@4146 Others
struct _IO_STACK_LOCATION::@4107::@4139 QueryDeviceText
struct _IO_STACK_LOCATION::@4107::@4134 DeviceCapabilities
struct _IO_STACK_LOCATION::@4107::@4138 QueryId
struct _IO_STACK_LOCATION::@1620::@1621 DeviceIoControl
COMMON_DEVICE_EXTENSION Common
Definition: pci.h:59
Definition: usb.h:529
struct _URB_SELECT_CONFIGURATION UrbSelectConfiguration
Definition: usb.h:533
struct _URB_CONTROL_DESCRIPTOR_REQUEST UrbControlDescriptorRequest
Definition: usb.h:545
struct _URB_SELECT_INTERFACE UrbSelectInterface
Definition: usb.h:532
struct _URB_HEADER UrbHeader
Definition: usb.h:531
USBD_PIPE_INFORMATION Pipes[1]
Definition: usb.h:286
Definition: usbdlib.h:7
ULONG MaximumTransferSize
Definition: usb.h:265
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define STATUS_DEVICE_DATA_ERROR
Definition: udferr_usr.h:159
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define USB_CONFIGURATION_DESCRIPTOR_TYPE
Definition: usb100.h:50
struct _USB_INTERFACE_DESCRIPTOR * PUSB_INTERFACE_DESCRIPTOR
#define USB_DEVICE_DESCRIPTOR_TYPE
Definition: usb100.h:49
struct _USB_DEVICE_DESCRIPTOR USB_DEVICE_DESCRIPTOR
#define USB_STRING_DESCRIPTOR_TYPE
Definition: usb100.h:51
#define USB_INTERFACE_DESCRIPTOR_TYPE
Definition: usb100.h:52
#define USB_INTERFACE_ASSOCIATION_DESCRIPTOR_TYPE
Definition: usb200.h:117
NTSTATUS PDO_HandleInternalDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:951
NTSTATUS USBCCGP_PdoHandleQueryId(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:208
NTSTATUS PDO_HandlePower(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:1101
NTSTATUS PDO_HandlePnp(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:342
NTSTATUS USBCCGP_PdoHandleQueryDeviceText(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:20
NTSTATUS PDO_Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:1126
NTSTATUS USBCCGP_PdoAppendInterfaceNumber(IN LPWSTR DeviceId, IN ULONG InterfaceNumber, OUT LPWSTR *OutString)
Definition: pdo.c:150
NTSTATUS USBCCGP_PdoHandleDeviceRelations(IN PDEVICE_OBJECT DeviceObject, IN OUT PIRP Irp)
Definition: pdo.c:94
NTSTATUS USBCCGP_PDOSelectConfiguration(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:707
NTSTATUS USBCCGP_BuildConfigurationDescriptor(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pdo.c:498
struct _USBD_INTERFACE_INFORMATION * PUSBD_INTERFACE_INFORMATION
struct _URB * PURB
#define URB_FUNCTION_SELECT_CONFIGURATION
Definition: usb.h:86
#define URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE
Definition: usb.h:97
#define UsbBuildSelectInterfaceRequest(urb, length, configurationHandle, interfaceNumber, alternateSetting)
Definition: usbdlib.h:59
#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes)
Definition: usbdlib.h:117
_In_ PVOID _In_ LONG InterfaceNumber
Definition: usbdlib.h:169
#define IOCTL_INTERNAL_USB_SUBMIT_URB
Definition: usbioctl.h:32
#define IOCTL_INTERNAL_USB_RESET_PORT
Definition: usbioctl.h:35
#define IOCTL_INTERNAL_USB_CYCLE_PORT
Definition: usbioctl.h:53
#define IOCTL_INTERNAL_USB_GET_PORT_STATUS
Definition: usbioctl.h:44
_In_ WDFCOLLECTION _In_ ULONG Index
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_In_ WDFUSBINTERFACE _In_ UCHAR _Out_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor
Definition: wdfusb.h:2334
_In_ WDFUSBDEVICE _In_ UCHAR InterfaceIndex
Definition: wdfusb.h:2462
DEVICE_CAPABILITIES
Definition: iotypes.h:965
@ TargetDeviceRelation
Definition: iotypes.h:2156
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define IRP_MN_QUERY_INTERFACE
#define IRP_MN_START_DEVICE
#define IRP_MN_QUERY_ID
#define IRP_MN_REMOVE_DEVICE
struct _DEVICE_RELATIONS * PDEVICE_RELATIONS
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_QUERY_DEVICE_TEXT
#define IRP_MN_QUERY_CAPABILITIES
#define IRP_MN_SET_POWER
#define IRP_MJ_INTERNAL_DEVICE_CONTROL
@ DeviceTextDescription
Definition: iotypes.h:2945
#define IRP_MJ_POWER
@ BusQueryCompatibleIDs
Definition: iotypes.h:2938
@ BusQueryInstanceID
Definition: iotypes.h:2939
@ BusQueryDeviceID
Definition: iotypes.h:2936
@ BusQueryHardwareIDs
Definition: iotypes.h:2937
#define IRP_MN_QUERY_POWER
#define IRP_MN_QUERY_REMOVE_DEVICE
#define ObReferenceObject
Definition: obfuncs.h:204
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184