'디바이스 드라이버'에 해당되는 글 7건

  1. 2009.06.09 어플리케이션과 드라이버간의 통신 방법 - DeviceIoControl()
  2. 2009.02.17 시스템 장치별 CLASS GUID
  3. 2008.11.04 DDK 다운로드, Windbg 사용... 2
  4. 2008.09.04 DriverEntry()
  5. 2008.09.04 DEVICE_OBJECT
  6. 2008.09.04 DRIVER_OBJECT 1
  7. 2008.07.31 Windows Device Driver 관련 용어들..
2009. 6. 9. 16:12

어플리케이션과 드라이버간의 통신 방법 - DeviceIoControl()



DeviceIoControl() 함수는 2개의 버퍼를 제공하여 디바이스 드라이버와 양방향으로 통신을 하는 함수이다.
이 함수는 일반적인 I/O가 아닌 디바이스 드라이버의 기능을 제어하는 용도로 주로 사용된다. 예를 들어 키보드의 caps lock키를 누를 때 디바이스 드라이버는 키보드 관련 app를 통해 caps lock LED를 On 하도록 한다. 이처럼 디바이스 설정과 같은 부분을 변경하고자 할 때 대부분 이 함수를 사용하여 구현을 하게 된다.

DeviceIoControl() 함수를 보면 아래와 같다.
BOOL DeviceIoControl ( HANDLE FileHandle,
                                      DWORD dwIoControlCode,
                                      LPVOID lpInBuffer,
                                      DWORD nInBufferSize,
                                      LPVOID lpOutBuffer,
                                      DWORD nOutBufferSize,
                                      LPDWORD lpBytesReturned,
                                      LPOVERLAPPED lpOverLapped
                                    );

FileHandle - Handle to device of interest
dwIoControlCode - Control code of operation to perform
lpInBuffer - Pointer to buffer to supply input data(App -> Device Driver)
nInBufferSize - Size of input buffer
lpOutBuffer - Pointer to buffer to receive output data(Device Driver -> App)
nOutBufferSize - Size of output buffer
lpBytesReturned - Pointer to variable to receive byte count
lpOverLapped - pointer to overlapped structure

또한 IoControlCode 라는 것을 사용한다는 특징을 가지고 있다. 이 코드를 가지고 응용 프로그램과 디바이스 드라이버가 통신을 하게 된다. 이는 "CTL_CODE"라는 매크로를 사용하게 되는데 DDK의 "devioctl.h"파일이나 SDK의 "winioctl.h"파일을 참고하면 된다.

DDK에서 정의하는 CTL_CODE 매크로는 아래와 같다.
#define CTL_CODE ( DeviceType, Function, Method, Access ) (       \
                              ((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
DeviceType - IoControlCode 가 사용되는 디바이스 장치의 유형을 정의
Access - 해당하는 IoControlCode 와 같이 사용되는 버퍼의 방향을 명시
Function - 구체적인 수행 코드를 구분
                  MS에서 0~2047까지의 수를 예약해서 사용하므로 드라이버 개발자는 2048~4095까지의 수만
                  사용할 수 있다.
Method - 사용되는 버퍼의 사용 전략을 명시

사용 예
#define IOCTL_INDEX   0x800
#define IOCTL_MY_CODE   CTLCODE(FILE_DEVICE_UNKNOWN,  \
                                                          IOCTL_INDEX,  \
                                                          MEHTOD_BUFFERED,  \
                                                          FILE_ANY_ACCESS)
...
DeviceIoControl(Device, IOCTL_MY_CODE, ...);


'Windows > Device Driver' 카테고리의 다른 글

키보드 스캔코드  (0) 2009.05.21
시스템 장치별 CLASS GUID  (0) 2009.02.17
DDK 다운로드, Windbg 사용...  (2) 2008.11.04
DriverEntry()  (0) 2008.09.04
DEVICE_OBJECT  (0) 2008.09.04
2009. 2. 17. 14:18

시스템 장치별 CLASS GUID



GUID가 가끔 필요할 때가 있는 듯 하다. 정리해 두고 필요할 때 찾아보면 좋을 듯.. ^^;

구글링하다가 발견한 사이트인데.. 정리가 잘 되어있는 듯 해서 가져옴..


[출처] http://cpueblo.com/programming/devicedriver/contents/187.html



System-Supplied Device Setup Classes
[This is preliminary documentation and subject to change.]

This section lists the system-supplied device setup classes. In the definition for each class, the Class and ClassGuid entries correspond to the values that must be specified in the INF Version section of a device's INF file. The GUIDs for system-supplied device setup classes are defined in devguid.h.

Supplying the appropriate class GUID value in the INF for a device, rather than or in addition to the Class=class-name entry, significantly improves the performance of system INF searching. In fact, system INFs that do not require either entry, such as those that neither install a new device class installer nor a device driver, sometimes supply ClassGuid={00000000-0000-0000-0000-000000000000} in their Version sections to cut down on the system's INF searching time.

Following are two lists of system-defined device setup classes:
System-Defined Device Setup Classes Available to Vendors
System-Defined Device Setup Classes Reserved for System Use
System-Defined Device Setup Classes Available to Vendors

 

Battery Devices

Class = Battery
ClassGuid = {72631e54-78a4-11d0-bcf7-00aa00b7b32a}
For Microsoft Windows 2000 and later NT-based operating systems, this class includes battery devices and UPS devices.
For Windows 9x/Me, the System class includes battery devices and UPS devices.

Biometric Device

Class = Biometric
ClassGuid = {53D29EF7-377C-4D14-864B-EB3A85769359}
For Windows Server 2003 and later versions, this class includes all biometric-based personal identification devices.

Bluetooth Devices

Class = Bluetooth
ClassGuid = {e0cbf06c-cd8b-4647-bb8a-263b43f0f974}
For Windows XP SP1 and later, this class includes all Bluetooth devices.

CD-ROM Drives

Class = CDROM
ClassGuid = {4d36e965-e325-11ce-bfc1-08002be10318}
This class includes CD-ROM drives, including SCSI CD-ROM drives. By default, the system's CD-ROM class installer also installs a system-supplied CD audio driver and CD-ROM changer driver as Plug and Play filters.

Disk Drives

Class = DiskDrive
ClassGuid = {4d36e967-e325-11ce-bfc1-08002be10318}
This class includes hard disk drives. See also the HDC and SCSIAdapter classes.

Display Adapters

Class = Display
ClassGuid = {4d36e968-e325-11ce-bfc1-08002be10318}
This class includes video adapters. Drivers for this class include display drivers and video miniport drivers.

Floppy Disk Controllers

Class = FDC
ClassGuid = {4d36e969-e325-11ce-bfc1-08002be10318}
This class includes floppy disk drive controllers.

Floppy Disk Drives

Class= FloppyDisk
ClassGuid= {4d36e980-e325-11ce-bfc1-08002be10318}
This class includes floppy disk drives.

Hard Disk Controllers

Class = HDC
ClassGuid = {4d36e96a-e325-11ce-bfc1-08002be10318}
This class includes hard disk controllers, including ATA/ATAPI controllers but not SCSI and RAID disk controllers.

Human Interface Devices (HID)

Class = HIDClass
ClassGuid = {745a17a0-74d3-11d0-b6fe-00a0c90f57da}
This class includes interactive input devices that are operated by the system-supplied HID class driver, which includes USB devices that comply with the USB HID Standard and non-USB devices that use a HID minidriver. For more information, see HIDClass Device Setup Class.. (See also the Keyboard or Mouse classes later in this list.)

IEEE 1284.4 Devices

Class=Dot4
ClassGuid = {48721b56-6795-11d2-b1a8-0080c72e74a2}
This class includes devices that control the operation of multifunction IEEE 1284.4 peripheral devices.

IEEE 1284.4 Print Functions

Class = Dot4Print
ClassGuid = {49ce6ac8-6f86-11d2-ble5-0080c72e74a2}
This class includes Dot4 print functions. A Dot4 print function is a function on a Dot4 device and has a single child device, which is a member of the Printer device setup class.

IEEE 1394 Devices That Support the 61883 Protocol

Class = 61883
ClassGuid = {7ebefbc0-3200-11d2-b4c2-00a0C9697d07}
This class includes IEEE 1394 devices that support the IEC-61883 protocol device class.

The 61883 component includes the 61883.sys protocol driver that transmits various audio and video data streams over the 1394 bus. These currently include standard/high/low quality DV, MPEG2, DSS, and Audio. These data streams are defined by the IEC-61883 specifications.

IEEE 1394 Devices That Support the AVC Protocol

Class = AVC
ClassGuid = {c06ff265-ae09-48f0-812c16753d7cba83}
This class includes IEEE 1394 devices that support the AVC protocol device class.

IEEE 1394 Devices That Support the SBP2 Protocol

Class = SBP2
ClassGuid = {d48179be-ec20-11d1-b6b8-00c04fa372a7}
This class includes IEEE 1394 devices that support the SBP2 protocol device class.

IEEE 1394 Host Bus Controller

Class = 1394
ClassGuid = {6bdd1fc1-810f-11d0-bec7-08002be2092f}
This class includes 1394 host controllers connected on a PCI bus, but not 1394 peripherals. Drivers for this class are system-supplied.

Imaging Device

Class = Image
ClassGuid = {6bdd1fc6-810f-11d0-bec7-08002be2092f}
This class includes still-image capture devices, digital cameras, and scanners.

IrDA Devices

Class = Infrared
ClassGuid = {6bdd1fc5-810f-11d0-bec7-08002be2092f}
This class includes infrared devices. Drivers for this class include Serial-IR and Fast-IR NDIS miniports, but see also the Network Adapter class for other NDIS NIC miniports.

Keyboard

Class = Keyboard
ClassGuid = {4d36e96b-e325-11ce-bfc1-08002be10318}
This class includes all keyboards. That is, it also must be specified in the (secondary) INF for an enumerated child HID keyboard device.

Media Changers

Class = MediumChanger
ClassGuid = {ce5939ae-ebde-11d0-b181-0000f8753ec4}
This class includes SCSI media changer devices.

Memory Technology Driver

Class = MTD
ClassGuid = {4d36e970-e325-11ce-bfc1-08002be10318}
This class includes memory devices, such as flash memory cards.

Modem

Class = Modem
ClassGuid = {4d36e96d-e325-11ce-bfc1-08002be10318}
This class includes modem devices. An INF file for a device of this class specifies the features and configuration of the device and stores this information in the registry. An INF file for a device of this class can also be used to install device drivers for a controllerless modem or a software modem. These devices split the functionality between the modem device and the device driver. For more information about modem INF files and Microsoft Windows Driver Model (WDM) modem devices, see Overview of Modem INF Files and Adding WDM Modem Support.

Monitor

Class = Monitor
ClassGuid = {4d36e96e-e325-11ce-bfc1-08002be10318}
This class includes display monitors. An INF for a device of this class installs no device driver(s), but rather specifies the features of a particular monitor to be stored in the registry for use by drivers of video adapters. (Monitors are enumerated as the child devices of display adapters.)

Mouse

Class = Mouse
ClassGuid = {4d36e96f-e325-11ce-bfc1-08002be10318}
This class includes all mouse devices and other kinds of pointing devices, such as trackballs. That is, this class also must be specified in the (secondary) INF for an enumerated child HID mouse device.

Multifunction Devices

Class = Multifunction
ClassGuid = {4d36e971-e325-11ce-bfc1-08002be10318}
This class includes combo cards, such as a PCMCIA modem and netcard adapter. The driver for such a Plug and Play multifunction device is installed under this class and enumerates the modem and netcard separately as its child devices.

Multimedia

Class = Media
ClassGuid = {4d36e96c-e325-11ce-bfc1-08002be10318}
This class includes Audio and DVD multimedia devices, joystick ports, and full-motion video capture devices.

Multiport Serial Adapters

Class = MultiportSerial
ClassGuid = {50906cb8-ba12-11d1-bf5d-0000f805f530}
This class includes intelligent multiport serial cards, but not peripheral devices that connect to its ports. It does not include unintelligent (16550-type) mutiport serial controllers or single-port serial controllers (see the Ports class).

Network Adapter

Class = Net
ClassGuid = {4d36e972-e325-11ce-bfc1-08002be10318}
This class includes NDIS miniport drivers excluding Fast-IR miniport drivers, NDIS intermediate drivers (of virtual adapters), and CoNDIS MCM miniport drivers.

Network Client

Class = NetClient
ClassGuid = {4d36e973-e325-11ce-bfc1-08002be10318}
This class includes network and/or print providers.

Network Service

Class = NetService
ClassGuid = {4d36e974-e325-11ce-bfc1-08002be10318}
This class includes network services, such as redirectors and servers.

Network Transport

Class = NetTrans
ClassGuid = {4d36e975-e325-11ce-bfc1-08002be10318}
This class includes NDIS protocols, CoNDIS stand-alone call managers, and CoNDIS clients, as well as higher level drivers in transport stacks.

PCI SSL Accelerator

Class = Security Accelerator
ClassGuid = {268c95a1-edfe-11d3-95c3-0010dc4050a5}
This class includes devices that accelerate secure socket layer (SSL) cryptographic processing.

PCMCIA Adapters

Class = PCMCIA
ClassGuid = {4d36e977-e325-11ce-bfc1-08002be10318}
This class includes PCMCIA and CardBus host controllers, but not PCMCIA or CardBus peripherals. Drivers for this class are system-supplied.

Ports (COM & LPT ports)

Class = Ports
ClassGuid = {4d36e978-e325-11ce-bfc1-08002be10318}
This class includes serial and parallel port devices. See also the MultiportSerial class.

Printers

Class = Printer
ClassGuid = {4d36e979-e325-11ce-bfc1-08002be10318}
This class includes printers.

Printers, Bus-specific class drivers

Class = PNPPrinters
ClassGuid = {4658ee7e-f050-11d1-b6bd-00c04fa372a7}
This class includes SCSI/1394-enumerated printers. Drivers for this class provide printer communication for a specific bus.

Processors

Class = Processor
ClassGuid = {50127dc3-0f36-415e-a6cc-4cb3be910b65}
This class includes processor types.

SCSI and RAID Controllers

Class = SCSIAdapter
ClassGuid = {4d36e97b-e325-11ce-bfc1-08002be10318}
This class includes SCSI HBAs (Host Bus Adapters) and disk-array controllers.

Smart Card Readers

Class = SmartCardReader
ClassGuid = {50dd5230-ba8a-11d1-bf5d-0000f805f530}
This class includes smart card readers.

Storage Volumes

Class = Volume
ClassGuid = {71a27cdd-812a-11d0-bec7-08002be2092f}
This class includes storage volumes as defined by the system-supplied logical volume manager and class drivers that create device objects to represent storage volumes, such as the system disk class driver.

System Devices

Class = System
ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318}
This class includes HALs, system buses, system bridges, the system ACPI driver, and the system volume manager driver.
For Windows 9x/Me, this class also includes battery devices and UPS devices.

Tape Drives

Class = TapeDrive
ClassGuid = {6d807884-7d21-11cf-801c-08002be10318}
This class includes tape drives, including all tape miniclass drivers.

USB

Class = USB
ClassGuid = {36fc9e60-c465-11cf-8056-444553540000}
This class includes USB host controllers and USB hubs, but not USB peripherals. Drivers for this class are system-supplied.

Windows CE USB ActiveSync Devices

Class = WCEUSBS
ClassGuid = {25dbce51-6c8f-4a72-8a6d-b54c2b4fc835}
This class includes Windows CE ActiveSync devices.
The WCEUSBS setup class supports communication between a personal computer and a device that is compatible with the Windows CE ActiveSync driver (generally, PocketPC devices) over USB.
System-Defined Device Setup Classes Reserved for System Use
The following classes and GUIDs should not be used to install devices (or drivers) on Windows 2000 or later platforms:

Adapter

Class = Adapter
ClassGuid = {4d36e964-e325-11ce-bfc1-08002be10318}
This class is obsolete.

APM

Class = APMSupport
ClassGuid = {d45b1c18-c8fa-11d1-9f77-0000f805f530}
This class is reserved for system use.

Computer

Class = Computer
ClassGuid = {4d36e966-e325-11ce-bfc1-08002be10318}
This class is reserved for system use.

Decoders

Class = Decoder
ClassGuid = {6bdd1fc2-810f-11d0-bec7-08002be2092f}
This class is reserved for future use.

Global Positioning System

Class = GPS
ClassGuid = {6bdd1fc3-810f-11d0-bec7-08002be2092f}
This class is reserved for future use.

Host-side IEEE 1394 Kernel Debugger Support

Class = 1394Debug
ClassGuid = {66f250d6-7801-4a64-b139-eea80a450b24}
This class is reserved for system use.

IEEE 1394 IP Network Enumerator

Class = Enum1394
ClassGuid = {c459df55-db08-11d1-b009-00a0c9081ff6}
This class is reserved for system use.

No driver

Class = NoDriver
ClassGuid = {4d36e976-e325-11ce-bfc1-08002be10318}
This class is obsolete.

Non-Plug and Play Drivers

Class = LegacyDriver
ClassGuid = {8ecc055d-047f-11d1-a537-0000f8753ed1}
This class is reserved for system use.

Other Devices

Class = Unknown
ClassGuid = {4d36e97e-e325-11ce-bfc1-08002be10318}
This class is reserved for system use. Enumerated devices for which the system cannot determine the type are installed under this class. Do not use this class if you are unsure in which class your device belongs. Either determine the correct device setup class or create a new class.

Printer Upgrade

Class = Printer Upgrade
ClassGuid = {4d36e97a-e325-11ce-bfc1-08002be10318}
This class is reserved for system use.

Sound

Class = Sound
ClassGuid = {4d36e97c-e325-11ce-bfc1-08002be10318}
This class is obsolete.

Storage Volume Snapshots

Class = VolumeSnapshot
ClassGuid = {533c5b84-ec70-11d2-9505-00c04F79deaf}
This class is reserved for system use.



'Windows > Device Driver' 카테고리의 다른 글

어플리케이션과 드라이버간의 통신 방법 - DeviceIoControl()  (0) 2009.06.09
키보드 스캔코드  (0) 2009.05.21
DDK 다운로드, Windbg 사용...  (2) 2008.11.04
DriverEntry()  (0) 2008.09.04
DEVICE_OBJECT  (0) 2008.09.04
2008. 11. 4. 17:48

DDK 다운로드, Windbg 사용...


망할놈의 키보드 때문에 요즘 죽을 맛이다... -_-
이리 저리 웹에서 문서를 찾지만 뭔말인지 도대체 알아먹을 수가 없다. 
한마디로 XX것이다. 궁금한 것에 대해서 검색을 해도 원하는 정보가 없고, 또 여기 저기 관련 사이트에 질문을 해도 답을 해주는 이가 없을 때의 절망감이란...

그러다 우연하게 얻은 답변은 결국 디바이스 드라이버를 만들어야 하는 상황이 되어버린 것이다. 여기 저기 둘러보아도 알수 없는 이상한 나라에 온 기분이다.

일단 DDK라는 녀석을 받아서 설치를 했다. 전에 잠깐 필터 드라이버를 끄적인다고 WDM인가? 하는 녀석을 설치해서 잠깐 한 적이 있는데.. 그녀석의 이전 버전이라던데.. 여튼 그걸 깔았다.


까는 거야 iso 이미지를 데몬에 집어 넣으니깐 간단히 설명서 같은게 떠서 걍 따라했다. 잘 깔린다. 디버거라는 녀석도 깔았다... Windbg라나??

일단 구한 문서에서 Windbg로 뭘 하길래 따라해 볼겸 실행을 시켰다. 근데... 이거 어떻게 동작을 시켜야 하는지...ㅡ.ㅜ
대충 이리 저리 검색하고 하다가 비슷한 모냥새는 만들었다. 간단하게 Windbg 를 사용하는 방법이다.
먼저 Windbg를 실행한다.
시작 -> 모든 프로그램 -> Debugging Tools for Windows -> WinDbg

다음은 File -> Symbol File Path를 선택한 후 아래 그림과 같이 입력을 한다.
'Symbol path : '란에 'SRV*C:\Symbol*Http://msdl.microsoft.com/download/symbols' 라고 입력을 한 후 Reload를 체크한다. OK 버튼을 클릭하여 빠져 나온다.

File -> Kernel Debug를 실행한 후 Local 탭을 선택한다. 확인 버튼을 클릭한다.

다음과 같이 커널 디버거(?)가 실행되는 것을 볼 수 있다.
맨 아래 'lkd>' 라고 되어 있는 부분에 원하는 명령을 쳐 넣을 수도 있다 물론 결과는 흰색 바탕의 콘솔창에 나타나는 것이고... 아... 모르겠다 사실 ㅋㅋ


'Windows > Device Driver' 카테고리의 다른 글

키보드 스캔코드  (0) 2009.05.21
시스템 장치별 CLASS GUID  (0) 2009.02.17
DriverEntry()  (0) 2008.09.04
DEVICE_OBJECT  (0) 2008.09.04
DRIVER_OBJECT  (1) 2008.09.04
2008. 9. 4. 14:40

DriverEntry()



디바이스 드라이버가 최초로 시작되는 DriverEntry()에 대해 간단하게 알아보자!
이름 그대로 Driver Entry.. 드라이버의 엔트리(입장)이다. 일반적인 프로그램.. 예를 들의 C 프로그램에서 main()과 같은 역할을 하는 함수라고 보면 된다.

MSDN의 내용을 참고 하고 싶으면.. 여기클릭해서 보길 바람!!

드라이버는 I/O Manager에 의해 메모리에 로드(load)되어지고, I/O Manager는 DriverObject를 만들어 DriverEntry() 함수를 호출한다.
그리고 이 DriverEntry() 함수에서는 DriverObject를 초기화 해주는 작업을 진행하게 된다.
초기화 해주는 작업이란것은 드라이버의 I/O 요청에 의한 IRP를 처리해주는 핸들러(함수)를 초기화 해주는 것이라고 알면 될듯 하다.

다음은 WDM 드라이버인 kbfiltr(Keyboard Filter Driver)의 DriverEntry()이다.
NTSTATUS DriverEntry ( IN  PDRIVER_OBJECT  DriverObject,
                                   IN  PUNICODE_STRING RegistryPath )
{
    ULONG i;

    UNREFERENCED_PARAMETER (RegistryPath);

    for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) {
        DriverObject->MajorFunction[i] = KbFilter_DispatchPassThrough;
    }

    DriverObject->MajorFunction [IRP_MJ_CREATE] =
    DriverObject->MajorFunction [IRP_MJ_CLOSE] =        KbFilter_CreateClose;
    DriverObject->MajorFunction [IRP_MJ_PNP] =            KbFilter_PnP;
    DriverObject->MajorFunction [IRP_MJ_POWER] =       KbFilter_Power;
    DriverObject->MajorFunction [IRP_MJ_INTERNAL_DEVICE_CONTROL] =
                                                                                 KbFilter_InternIoCtl;
    DriverObject->DriverUnload = KbFilter_Unload;
    DriverObject->DriverExtension->AddDevice = KbFilter_AddDevice;

    return STATUS_SUCCESS;
}


하는 일을 보면, 인자로 넘어오는 DriverObject의 접근 가능한 필드를 채워넣는 작업을 하고 있다는 것을 알 수 있다.
IRP를 처리하기 위한 루틴들을 MajorFunction[]에 넣고 있다.
그리고 DriverExtension->AddDevice를 통해 AddDevice()를 호출한다.

WDM이 아닌 다른 방식의 드라이버의 DriverEntry()함수도 생긴 모습은 거의 동일하다.
다음은 Ctrl2Cap라는 함수의 DriverEntry() 이다.
NTSTATUS DriverEntry(IN PDRIVER_OBJECT  DriverObject, IN PUNICODE_STRING RegistryPath )
{
    ...
      
    ntStatus = IoCreateDevice (DriverObject,
                               0,
                               &deviceNameUnicodeString,
                               FILE_DEVICE_CTRL2CAP,
                               0,
                               TRUE,
                               &deviceObject );

    if (NT_SUCCESS(ntStatus)) {
        ....
        // Create dispatch points for all the IRPs the keyboard class device handles.
        DriverObject->MajorFunction[IRP_MJ_READ]                  = Ctrl2capDispatchRead;
        DriverObject->MajorFunction[IRP_MJ_CREATE]              =
        DriverObject->MajorFunction[IRP_MJ_CLOSE]                =
        DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS]  =
        DriverObject->MajorFunction[IRP_MJ_CLEANUP]             =
        DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Ctrl2capDispatchGeneral;
    }
    ...
    return Ctrl2capInit( DriverObject );
}


대충 차이점을 보자면, WDM의 디바이스 드라이버는 DriverObject의 DeviceObject를 AddDevice에서 생성을하고, Ctrl2Cap와 같은 드라이버는 DriverEntry()에서 DeviceObject를 생성한다는 것... -_-;;

맞나 모르겠음...^^;

여튼 DriverEntry()의 하는 일은 현재 사용하고자 할 드라이버가 메모리에 적재될 때 , 디바이스 드라이버가 가지는 다양한 기능을 처리할 함수 엔트리들의 주소를 등록한다.


'Windows > Device Driver' 카테고리의 다른 글

키보드 스캔코드  (0) 2009.05.21
시스템 장치별 CLASS GUID  (0) 2009.02.17
DDK 다운로드, Windbg 사용...  (2) 2008.11.04
DEVICE_OBJECT  (0) 2008.09.04
DRIVER_OBJECT  (1) 2008.09.04
2008. 9. 4. 13:22

DEVICE_OBJECT



Windows Driver Kit: Kernel-Mode Driver Architecture
DEVICE_OBJECT
[This is preliminary documentation and subject to change.]

The DEVICE_OBJECT structure is used by the operating system to represent a device object. A device object represents a logical, virtual, or physical device for which a driver handles I/O requests.

typedef struct _DEVICE_OBJECT {
  CSHORT  Type;
  USHORT  Size;
  LONG  ReferenceCount;
  PDRIVER_OBJECT  DriverObject;
  PDEVICE_OBJECT  NextDevice;
  PDEVICE_OBJECT  AttachedDevice;
  PIRP  CurrentIrp;
  PIO_TIMER  Timer;
  ULONG  Flags;
  ULONG  Characteristics;
  __volatile PVPB  Vpb;
  PVOID  DeviceExtension;
  DEVICE_TYPE  DeviceType;
  CCHAR  StackSize;
  union {
    LIST_ENTRY  ListEntry;
    WAIT_CONTEXT_BLOCK  Wcb;
  } Queue;
  ULONG  AlignmentRequirement;
  KDEVICE_QUEUE  DeviceQueue;
  KDPC  Dpc;
  ULONG  ActiveThreadCount;
  PSECURITY_DESCRIPTOR  SecurityDescriptor;
  KEVENT  DeviceLock;
  USHORT  SectorSize;
  USHORT  Spare1;
  PDEVOBJ_EXTENSION  DeviceObjectExtension;
  PVOID  Reserved;
} DEVICE_OBJECT, *PDEVICE_OBJECT;

Members

Type
Used by the operating system to indicate that an object is a device object. For device objects, the value of this member is 3. This is a read-only member.

Size
Specifies the size, in bytes, of the device object. This size does not include the device object extension, if present (see DeviceExtension later in this topic). This is a read-only member.

ReferenceCount
Used by the I/O manager to track the number of open handles for the device that are associated with the device object. This allows the I/O manager to avoid unloading a driver when there are outstanding handles for the driver's device(s). This is a read-only member.

DriverObject
A pointer to the driver object (DRIVER_OBJECT), that reprensents the loaded image of the driver that was input to the DriverEntry and AddDevice routines. This member is set by the I/O manager upon a successful call to IoCreateDevice or IoCreateDeviceSecure. This is a read-only member.

NextDevice
A pointer to the next device object, if any, that was created by the same driver. The I/O manager updates this list at each successful call to IoCreateDevice or IoCreateDeviceSecure.

A non- Plug and Play (PnP) driver that is being unloaded must traverse (“walk”) the list of its device objects and delete them. A PnP driver does not have to walk this list of device objects. Instead, PnP drivers perform their cleanup during the device removal PnP operation (IRP_MN_REMOVE_DEVICE).

A driver that recreates its device objects dynamically also uses this member. This is a read/write member.

AttachedDevice
A pointer to the attached device object. If there is no attached device object, this member is NULL. The device object that is pointed to by the AttachedDevice member typically is the device object of a filter driver, which intercepts I/O requests originally targeted to the device represent by the device object. For more information, see the IoAttachDevice and IoAttachDeviceByPointer topics. This is an opaque member.

CurrentIrp
A pointer to the current IRP if the driver has a StartIo routine whose entry point was set in the driver object and if the driver is currently processing IRP(s). Otherwise, this member is NULL. For more information, see the IoStartPacket and IoStartNextPacket topics. This is a read-only member.

Timer
A pointer to a timer object. This allows the I/O manager to call a driver-supplied timer routine every second. For more information, see IoInitializeTimer. This is a read/write member.

Flags
Device drivers perform a bitwise OR operation with this member in their newly created device objects by using one or more of the following system-defined values:
DO_BUFFERED_IO or DO_DIRECT_IO
Specifies the type of buffering that is used by the I/O manager for I/O requests that are sent to the device stack. Higher-level drivers OR this member with the same value as the next-lower driver in the stack, except possibly for highest-level drivers.
DO_BUS_ENUMERATED_DEVICE
The operating system sets this flag in each physical device object (PDO). Drivers must not modify this flag.
DO_DEVICE_INITIALIZING
The I/O manager sets this flag when it creates the device object. A device function driver or filter driver clears the flag in its AddDevice routine, after it does the following:
  • Attaches the device object to the device stack.
  • Establishes the device power state.
  • Performs a bitwise OR operation on the member with one of the power flags (if it is necessary).

it and The Plug and Play (PnP) manager checks that the flag is clear after the AddDevice routine returns.

DO_EXCLUSIVE
Indicates that the driver services an exclusive device, such as a video, serial, parallel, or sound device. WDM drivers must not set this flag. For more information, see the Specifying Exclusive Access to Device Objects topic.
DO_MAP_IO_BUFFER
This flag is no longer used. Drivers should not set this flag.
DO_POWER_INRUSH
Drivers of devices that require inrush current when the device is turned on must set this flag. A driver cannot set both this flag and DO_POWER_PAGABLE.
DO_POWER_PAGABLE
Pageable drivers that are compatible with Microsoft Windows 2000 and later versions of Windows, are not part of the paging path, and do not require inrush current must set this flag. The system calls such drivers at IRQL = PASSIVE_LEVEL. Drivers cannot set both this flag and DO_POWER_INRUSH. All drivers for WDM, Microsoft Windows 98, and Windows Millennium Edition must set DO_POWER_PAGABLE.
DO_SHUTDOWN_REGISTERED
Used by the I/O manager to indicate that a driver has registered the device object for shutdown notifications. This flag should not be used by drivers.
DO_VERIFY_VOLUME
Removable-media drivers set this flag while they process transfer requests. Such drivers should also check for this flag in the target for a transfer request before they transfer any data. For more information, see the Supporting Removable Media topic.

For more information about how to set the Flags member, see Initializing a Device Object.

Characteristics
Specifies one or more system-defined constants, combined with a bitwise OR operation, that provide additional information about the driver's device. These constants include the following:
FILE_AUTOGENERATED_DEVICE_NAME
Directs the I/O manager to generate a name for the device, instead of the caller specifying a DeviceName when it calls this routine. The I/O manager makes sure that the name is unique. This characteristic is typically specified by a PnP bus driver to generate a name for a physical device object (PDO) for a child device on the same bus. This characteristic is new starting with Microsoft Windows 2000 and Microsoft Windows 98.
FILE_CHARACTERISTIC_PNP_DEVICE
Indicates that the device object is part of a Plug and Play (PnP) stack. This characteristic is required if a bus driver (or bus filter driver) registers WMI support for a device object that has not yet received the IRP_MN_START_DEVICE request. FILE_CHARACTERISTIC_PNP_DEVICE is also required if a function or filter driver registers for WMI before attaching to its device stack.
FILE_CHARACTERISTIC_TS_DEVICE
Indicates that the device object is part of a Terminal Services device stack. Drivers should not set this characteristic.
FILE_CHARACTERISTIC_WEBDAV_DEVICE
Indicates that a Web-based Distributed Authoring and Versioning (WebDAV) file system is mounted on the device. Drivers should not set this characteristic.
FILE_DEVICE_IS_MOUNTED
Indicates that a file system is mounted on the device. Drivers should not set this characteristic.
FILE_DEVICE_SECURE_OPEN
(Microsoft Windows NT 4.0 with Service Pack 5 (SP5) and later versions of Windows)

Directs the I/O manager to apply the security descriptor of the device object to relative opens and trailing file name opens for the device. For more information, see the Controlling Device Namespace Access topic.

FILE_FLOPPY_DISKETTE
Indicates that the device is a floppy disk device.
FILE_READ_ONLY_DEVICE
Indicates that the device cannot be written to.
FILE_REMOTE_DEVICE
Indicates that the device is remote.
FILE_REMOVABLE_MEDIA
Indicates that the storage device supports removable media. Notice that this characteristic indicates removable media, not a removable device. For example, drivers for JAZ drive devices should specify this characteristic, but drivers for PCMCIA flash disks should not.
FILE_VIRTUAL_VOLUME
Indicates that the volume is virtual. Drivers should not set this characteristic.
FILE_WRITE_ONCE_MEDIA
Indicates that the device supports write-once media. Drivers do not set this member directly. For more information about how to set device characteristics, see the Specifying Device Characteristics topic.

Vpb
A pointer to the volume parameter block (VPB) that is associated with the device object. For file system drivers, the VPB can provide a connection to any unnamed logical device object that represents an instance of a mounted volume. This is an opaque member.

DeviceExtension
A pointer to the device extension. The structure and contents of the device extension are driver-defined. The size is driver-determined, specified in the driver's call to IoCreateDevice or IoCreateDeviceSecure. For more information about device extensions, see Device Extensions. This is a read-only member. However, the object that the member points to can be modified by the driver.

DeviceType
Set by IoCreateDevice and IoCreateDeviceSecure by using the value that is specified for that routine's DeviceType parameter. For more information, see the Specifying Device Types topic.

StackSize
Specifies the minimum number of stack locations in IRPs to be sent to this driver. IoCreateDevice and IoCreateDeviceSecure set this member to 1 in newly created device objects; lowest-level drivers can therefore ignore this member. The I/O manager automatically sets the StackSize member in a higher-level driver's device object to the appropriate value if the driver calls IoAttachDevice or IoAttachDeviceToDeviceStack. Only a higher-level driver that chains itself over another driver with IoGetDeviceObjectPointer must explicitly set the value of StackSize in its own device object(s) to 1 + the StackSize value of the next-lower driver's device object.

Queue
Used internally by the I/O manager to queue the device object when it is required. This is an opaque member.

AlignmentRequirement
Specifies the device's address alignment requirement for data transfers. The value must be one of the FILE_XXX_ALIGNMENT values that are defined in Wdm.h. For more information, see the Initializing a Device Object, GetDmaAlignment, and ZwQueryInformationFile topics.

DeviceQueue
The device queue object for the device object. The device queue object contains any IRPs that are waiting to be processed by the driver that is associated with the device object. For more information, see the Driver-Managed IRP Queues topic. This is an opaque member.

Dpc
The deferred procedure call (DPC) object for the device object. For more information, see the Introduction to DPC Objects topic. This is an opaque member.

ActiveThreadCount
Reserved for future use. This is an opaque member.

SecurityDescriptor
Specifies a security descriptor (SECURITY_DESCRIPTOR) for the device object when the device object is created. If this member is NULL, the device object receives default security settings. This is a read-only member, although the member can be modified through the ZwSetSecurityObjectfunction.

DeviceLock
A synchronization event object that is allocated by the I/O manager. The I/O manager obtains his event object before it dispatches a mount or mount-verify request to a file-system driver. This is an opaque member.

SectorSize
If the device object does not represent a volume, this member is set to zero. If the device object represents a volume, this member specifies the volume’s sector size, in bytes. The I/O manager uses this member to make sure that all read operations, write operations, and set file position operations that are issued are aligned correctly when intermediate buffering is disabled. A default system bytes-per-sector value is used when the device object is created, however, file system drivers; and more rarely, legacy and minifilter drivers, can update this value that is based on the geometry of the underlying volume hardware when a mount occurs. Other drivers should not modify this member.

Spare1
Reserved for system use. This is an opaque member.

DeviceObjectExtension
A pointer to a device object extension that is used by the I/O manager and PnP manager to store information about the state of the device. This is an opaque member.

Reserved
Reserved for system use. This is an opaque member.

Comments

The operating system represents devices by device objects. For more information, see the Device Objects and Device Stacks topic.

Drivers create device objects by using the IoCreateDevice and IoCreateDeviceSecure routines. For more information about how to create device objects, see Creating a Device Object.

A device object is partially opaque. Drivers do not set members of the device object directly, unless otherwise documented. For more information about the members that drivers can modify directly, see Initializing a Device Object. For information about other device object properties, see Properties of Device Objects.

Opaque members within a device object must be considered inaccessible. Drivers that have dependencies on object member locations or access to opaque members might not remain portable and interoperable with other drivers over time.

The system-supplied video port driver sets up the fields of the device objects that it creates on behalf of video miniport drivers.

The system-supplied SCSI port driver sets up the fields of the device objects that it creates on behalf of SCSI miniport drivers.

The system-supplied NDIS library sets up the fields of the device objects that it creates on behalf of NDIS miniport drivers.

Requirements

Headers: Defined in Wdm.h. Include Wdm.h, Ntddk.h, Ntifs.h, or Fltkernel.h.

See Also

DRIVER_OBJECT, IoAttachDevice, IoAttachDeviceToDeviceStack, IoCreateDevice, IoDeleteDevice, IoGetDeviceObjectPointer

APIScan Requirements

Header: Wdm.h, Ntddk.h, Ntifs.h
Function: DEVICE_OBJECT

출처 : MSDN


'Windows > Device Driver' 카테고리의 다른 글

키보드 스캔코드  (0) 2009.05.21
시스템 장치별 CLASS GUID  (0) 2009.02.17
DDK 다운로드, Windbg 사용...  (2) 2008.11.04
DriverEntry()  (0) 2008.09.04
DRIVER_OBJECT  (1) 2008.09.04
2008. 9. 4. 11:48

DRIVER_OBJECT



디바이스 드라이버라는 것을 다루고 있다.
이쪽에 대해서는 정말이지 무지하다. 그래서 어렵다. 그래서 공부를 하려한다. 아... -_-;
여기저기 자료 찾고 알때까지.. 잘 할 수 있을 때까지 한번 해보려 한다.
일단 개념부터 정리해나가고.. 보자는.. ^^;

다음은 DRIVER_OBJECT에 대한 MSDN의 내용이다.

Windows Driver Kit: Kernel-Mode Driver Architecture
DRIVER_OBJECT

Each driver object represents the image of a loaded kernel-mode driver. A pointer to the driver object is an input parameter to a driver's DriverEntry, AddDevice, and optional Reinitialize routines and to its Unload routine, if any.

A driver object is partially opaque. Driver writers must know about certain members of a driver object to initialize a driver and to unload it if the driver is unloadable. The following members of the driver object are accessible to drivers.


Accessible Members

PDEVICE_OBJECT DeviceObject
Pointer to the device objects created by the driver. This member is automatically updated when the driver calls IoCreateDevice successfully. A driver can use this member and the NextDevice member of DEVICE_OBJECT to step through a list of all the device objects that the driver created.

PDRIVER_EXTENSION DriverExtension
Pointer to the driver extension. The only accessible member of the driver extension is DriverExtension->AddDevice, into which a driver's DriverEntry routine stores the driver's AddDevice routine.

PUNICODE_STRING HardwareDatabase
Pointer to the \Registry\Machine\Hardware path to the hardware configuration information in the registry.

PFAST_IO_DISPATCH FastIoDispatch
Pointer to a structure defining the driver's fast I/O entry points. This member is used only by FSDs and network transport drivers.

PDRIVER_INITIALIZE DriverInit
The entry point for the DriverEntry routine, which is set up by the I/O manager.

PDRIVER_STARTIO DriverStartIo
The entry point for the driver's StartIo routine, if any, which is set by the DriverEntry routine when the driver initializes. If a driver has no StartIo routine, this member is NULL.

PDRIVER_UNLOAD DriverUnload
The entry point for the driver's Unload routine, if any, which is set by the DriverEntry routine when the driver initializes. If a driver has no Unload routine, this member is NULL.

PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION+1]
A dispatch table consisting of an array of entry points for the driver's DispatchXxx routines. The array's index values are the IRP_MJ_Xxx values representing each IRP major function code. Each driver must set entry points in this array for the IRP_MJ_Xxx requests that the driver handles. For more information, see Writing Dispatch Routines. Each DispatchXxx routine is declared as follows:

NTSTATUS
(*PDRIVER_DISPATCH) (
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp
    );

Comments

Each kernel-mode driver's initialization routine should be named DriverEntry so the system will load the driver automatically. If this routine's name is something else, the driver writer must define the name of the initialization routine for the linker; otherwise, the system loader or I/O manager cannot find the driver's transfer address. The names of other standard driver routines can be chosen at the discretion of the driver writer.

A driver must set its DispatchXxx entry points in the driver object that is passed in to the DriverEntry routine when the driver is loaded. A device driver must set one or more DispatchXxx entry points for the IRP_MJ_XXX that any driver of the same type of device is required to handle. A higher-level driver must set one or more DispatchXxx entry points for all the IRP_MJ_XXX that it must pass on to the underlying device driver. Otherwise, a driver is not sent IRPs for any IRP_MJ_XXX for which it does not set up a DispatchXxx routine in the driver object. For more information about the set of IRP_MJ_XXX that drivers for different types of underlying devices are required to handle, see IRP Major Function Codes.

The DriverEntry routine also sets the driver's AddDevice, StartIo and/or Unload entry points, if any, in the driver object.

The HardwareDatabase string can be used by device drivers to get hardware configuration information from the registry when the driver is loaded. A driver is given read-only access to this string.

The RegistryPath input to the DriverEntry routine points to the \Registry\Machine\System\CurrentControlSet\Services\DriverName key, where the value entry of DriverName identifies the driver. As for the HardwareDatabase in the input driver object, a driver is given read-only access to this string.

Undocumented members within a driver object should be considered inaccessible. Drivers with dependencies on object member locations or on access to undocumented members might not remain portable and interoperable with other drivers over time.

Requirements

Headers: Defined in Wdm.h. Include Wdm.h, Ntddk.h, or Ntifs.h.

See Also

DriverEntry, IoCreateDevice, IoDeleteDevice, StartIo, Unload

APIScan Requirements

Header: Wdm.h, Ntddk.h, Ntifs.h
Function: DRIVER_OBJECT

출처 : MSDN

'Windows > Device Driver' 카테고리의 다른 글

키보드 스캔코드  (0) 2009.05.21
시스템 장치별 CLASS GUID  (0) 2009.02.17
DDK 다운로드, Windbg 사용...  (2) 2008.11.04
DriverEntry()  (0) 2008.09.04
DEVICE_OBJECT  (0) 2008.09.04
2008. 7. 31. 10:45

Windows Device Driver 관련 용어들..



갑작스레 디바이스 드라이버를 작성을 해야할 것 같아서.. 현재 열공(?)중이다...

아.. 솔직히 이런 저런일들로.. 아무것도 할 수 없을 것 같은 상태이긴 하지만.. 그래도 한다.. 꾸역꾸역..

아.. Windows Device에서 사요하는 용어는 몇가지가 있다. 그 중에서 기본이 되는 용어들 몇가지를 살펴보고자 한다.

  • DDK (Driver Development Kit)
  • VxD (Virtual Device Driver)
  • WDM (Windows Driver Model)
  • IFS (Installable File System)
  • WDF (Windows Driver Foundation)
  • WDK (Windows Driver Kit)


DDK

  - Windows 상에서 Device Driver를 개발하는 사람들이 꼭 사용해야할 모음(?) 정도로 생각하면 될 듯 하다.
    가장 기초가 되는, 뭐 이거 없으면 개발을 할 수 없는 뭐.. 그런것?? ntddk.h, wdm.h 등이 있다.

VxD
  - 가상 장치 관리자라고 불린다. x는 디바이스에서 키보드, 마우스 등을 나타낸다.
    Windows 95, 98, ME 등에서 사용을 하는 녀석이다.

WDM
  - windows NT 로 넘어오면서 통합된 Driver 의 필요에 의해 생성된 녀석이다. 일종의 Framework라고 생각하면 맞을 듯 하다.

WDF
  - Vista가 출시되면서 나오게 된 모델로, WDM 보다 조금 더 확장 된 개념으로 보면 된다.

IFS
  - 파일시스템 위주의 특화된 Kit 이라고 보면 된다. 파일시스템에는 CDFS, FASTFAT, NTFS 등이 있으며, ntifs.h를 사용해서 생성한다.

WDK
  - Windows 의 모든 드라이버를 말한다.
    기존의 DDK를 사용하였지만, 지금은 이녀석(WDK)를 사용하여 디바이스 드라이버를 작성하게 될것 같다.

아.. 대충 이리 용어라는걸 알아봤는데.. 도데체 디바이스 드라이버는 어찌 만드는 거지?? -_-;;