임베디드 프로그래밍  

         
전체 기타 | WinCE | Delphi | VisualC | ARM | Media | SE | 마리오네트 | Java | wdm | JTAG | 영상처리 | 인증 | 질문/답변 | H/W | 알고리즘 | Platform | .net | VB | PPC | Network | android | QT | WWW | Linux |
2005/02/15 WDM USB 교육 요약
하창호02-17 13:59 | HIT : 4,225
<WDM USB 강의 요약>
1. UNICODE String
- Leghth(2byte)
- Max Leghth(2byte)
- Pointer(4byte)

2. Debug 문
- KdPrint((" DGCrtClsOpen was Called.... \n")); // 괄호 2개
- 디버거로만 확인 됨

3. 간단한 드라이버 예제
#include <NTDDK.h>

#define NT_DEVICE_NAME  L"\\Device\\DGCRTCLS"
#define DOS_DEVICE_NAME L"\\DosDevices\\DOSDGCRTCLS" // 어플리케이션에서 CreateFile 할 때 넣는 부분  

void
DGCrtClsUnload(
        IN PDRIVER_OBJECT pDriverObject
        );

NTSTATUS
DGCrtClsOpen(
        IN PDEVICE_OBJECT pDeviceObject,
        IN PIRP pIrp
        );

NTSTATUS
DGCrtClsClose(
        IN PDEVICE_OBJECT pDeviceObject,
        IN PIRP pIrp
        );

NTSTATUS
DriverEntry(
        IN PDRIVER_OBJECT pDriverObject,
        IN PUNICODE_STRING regPath
        )
{
        PDEVICE_OBJECT pDeviceObject = NULL;
        NTSTATUS ntStatus;
        UNICODE_STRING uniNtNameString, uniWin32NameString;


        RtlInitUnicodeString( &uniNtNameString, NT_DEVICE_NAME );
        ntStatus = IoCreateDevice (
                                        pDriverObject,
                    0,                                                        // DeviceExtensionSize
                    &uniNtNameString,
                    FILE_DEVICE_UNKNOWN,                //
                    0,                                                        // No standard device characteristics
                    FALSE,                                                // not exclusive device
                    &pDeviceObject
                    );
        if( !NT_SUCCESS(ntStatus) ) {
                return ntStatus;
        }

        // create dispatch points for create/open, close, unload
        pDriverObject->MajorFunction[IRP_MJ_CREATE] = DGCrtClsOpen;
        pDriverObject->MajorFunction[IRP_MJ_CLOSE] = DGCrtClsClose;
        pDriverObject->DriverUnload = DGCrtClsUnload;
        
        pDeviceObject->Flags |= DO_BUFFERED_IO;

        RtlInitUnicodeString( &uniWin32NameString, DOS_DEVICE_NAME );
        ntStatus = IoCreateSymbolicLink( &uniWin32NameString, &uniNtNameString );
        if (!NT_SUCCESS(ntStatus)){
                IoDeleteDevice( pDriverObject->DeviceObject );
        }

        return ntStatus;
}

void
DGCrtClsUnload(
        IN PDRIVER_OBJECT pDriverObject
        )
{
        PDEVICE_OBJECT pDeviceObject;
        UNICODE_STRING uniWin32NameString;


        pDeviceObject = pDriverObject->DeviceObject;

        RtlInitUnicodeString( &uniWin32NameString, DOS_DEVICE_NAME );
        IoDeleteSymbolicLink( &uniWin32NameString );
        IoDeleteDevice( pDriverObject->DeviceObject );
}

NTSTATUS
DGCrtClsOpen(
        IN PDEVICE_OBJECT pDeviceObject,
        IN PIRP pIrp
        )
{
        KdPrint((" DGCrtClsOpen was Called.... \n")); // 디버그 메세지 디버그에서만 뜸
        pIrp->IoStatus.Status = STATUS_SUCCESS; // device 쪽에 처리하라고 세팅함
        pIrp->IoStatus.Information = 0;
        IoCompleteRequest( pIrp, IO_NO_INCREMENT ); // pIrp 다 사용했으니까 메모리 해제해도 된다는 의미
        return STATUS_SUCCESS; // STATUS_SUCCESS 를 넘기면 App 쪽에서 정상적인 핸들을 얻는다
}

NTSTATUS
DGCrtClsClose(
        IN PDEVICE_OBJECT pDeviceObject,
        IN PIRP pIrp
        )
{
        KdPrint((" DGCrtClsClose was Called.... \n"));
        pIrp->IoStatus.Status = STATUS_SUCCESS;
        pIrp->IoStatus.Information = 0;
        IoCompleteRequest( pIrp, IO_NO_INCREMENT );
        return STATUS_SUCCESS;
}

4. 간단한 드라이버 사용하는 어플리케이션 예제
#include <afxwin.h>

int main()
{
        HANDLE hDevice;

        hDevice = CreateFile("\\\\.\\DOSDGCRTCLS", // SYS 소스에서 썼던 DOS_DEVICE_NAME 에서 DosDevices 대신 \\. 씀
                                                        GENERIC_READ | GENERIC_WRITE,
                                                        0,
                                                        NULL,
                                                        OPEN_EXISTING,
                                                        FILE_ATTRIBUTE_NORMAL,
                                                        NULL
                                                        );

        if( hDevice == (HANDLE) -1 )
        {
                return 0;
        }
                                
        // do something....
        // 뭔짓을 하겠지만 아직 IO 내용 없음
        
        MessageBox(NULL, "Create Success", "testApp", MB_OK);
        
        CloseHandle( hDevice );
        return 0;
}

5. Makefile 내용
!INCLUDE $(NTMAKEENV)\makefile.def

6. Sources 내용
TARGETNAME=DGCrtCls
TARGETPATH=obj
TARGETTYPE=DRIVER
SOURCES=DGCrtCls.c

7. 레지스트리 등록 내용
\registry\machine\system\currentcontrolset\services\DGCrtCls
- Type = REG_DWORD 0x00000001
- Start = REG_DWORD 0x00000003
- Group = Extended base
- ErrorControl = REG_DWORD 0x00000001



9  wdm :: Windows NT DDK에 포함된 BulkUsb sample ...  …1  하창호 2005·02·18 5048
8  wdm :: 2005/02/18 WDM USB 교육 요약    하창호 2005·02·18 3992
7  wdm :: DevGURU.com 배포용 U1000 USB 드라이브 및 A...    하창호 2005·02·18 3859
6  wdm :: Windows NT DDK에 포함된 Usbview sample    하창호 2005·02·17 6261
5  wdm :: 2005/02/16 WDM USB 교육 요약    하창호 2005·02·17 4478
 wdm :: 2005/02/15 WDM USB 교육 요약    하창호 2005·02·17 4225
3  wdm :: Device 정보와 Data 후킹하는 프로그램 크랙버젼    하창호 2005·02·16 7
2  wdm :: WDM USB 교육 샘플 예제  …3  하창호 2005·02·15 4544
1  wdm :: 2005/02/14 WDM USB 교육 요약    하창호 2005·02·14 4974
1
   
Copyright 1999-2018 Zeroboard / skin by GGAMBO
....