高分〉〉usb mass storage class driver开发

littlebboy 2005-12-22 08:11:33
那位大虾做过windows下的usb mass storage class driver,也就是u盘的驱动。老板让我开发一个windows2000下的usb mass storage class driver,不能用windows自带的。我看了看usb mass storage class 的协议和WDM驱动程序方面的资料,感觉自己从头写比较困难。谁有usb mass storage class driver的源代码参考一下。
分数不够可以再加,有什么好的建议也可以提。
...全文
332 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxf0204 2006-01-17
  • 打赏
  • 举报
回复
代码好长,帮顶吧!
littlebboy 2006-01-05
  • 打赏
  • 举报
回复
ddk只有实现bulkonly的一些代码,不全。没有实现usb mass storage class
的。
bluedreammer 2005-12-29
  • 打赏
  • 举报
回复
那位大虾做过windows下的usb mass storage class driver,也就是u盘的驱动。老板让我开发一个windows2000下的usb mass storage class driver,不能用windows自带的。
-----------------------------------------------------------------------------------
为什么?ddk里面有的,如果要完全自己写,也要参考的嘛。
yangyzqo 2005-12-23
  • 打赏
  • 举报
回复
platform builder上面的一个头文件,楼主看一下有没有用
CPP文件太长,就不贴了,呵呵
yangyzqo 2005-12-23
  • 打赏
  • 举报
回复

class CUsbPipe
{
public:
USB_PIPE _hPipe;
USB_TRANSFER _hTransfer;
PACKET *_pCurPacket;

PACKET *_pPackets;
PACKET *_pLastPacket;

int iTotalQueue;

public:
CUsbPipe()
{
memset (this, 0, sizeof(*this));
}
};

#if defined (NATIVE_SEQUENCING)
struct CompletedPacket {
CompletedPacket *pNext;
int eType;
int cLength;

unsigned char ucData[1];
};
#endif

class CUsbDevice
{
public:
CUsbDevice();
~CUsbDevice();

BOOL DeviceAttach(USB_HANDLE hDevice, LPCUSB_FUNCS lpUsbFuncs);
BOOL CloseDevice();
BOOL StartHardware();
BOOL StopHardware();

DWORD OpenConnection(void);
void CloseConnection(void);

int WritePacket (unsigned char *pBuffer, int nLen, HCI_TYPE eType);
int ReadPacket (unsigned char *pBuffer, int *pnLen, int *pnType);

DWORD ScoWriteInit();
DWORD ScoWriteDeinit();

BOOL IsScoActive();

protected:

static DWORD WINAPI ReadNotify(LPVOID lpvNotifyParameter);
static DWORD WINAPI WriteNotify(LPVOID lpvNotifyParameter);
static DWORD WINAPI ScoWriteNotify(LPVOID lpvNotifyParameter);

static DWORD WINAPI ReadThreadProcStub(LPVOID lpvNotifyParameter);
DWORD ReadThreadProc(void);

BOOL ParseConfig(LPCUSB_CONFIGURATION lpConfig);
BOOL Initialize(void);
BOOL CheckDevice();
BOOL SubmitReadRequest(int nEvent);

DWORD ScoWriteAlloc();
DWORD ScoWriteFree();
BOOL ScoWritePacket(PUCHAR pBuffer, DWORD dwBufferLen);
BOOL ScoWriteContinueTransfers();
BOOL ScoWriteDoPostProcessing();

int GetBuffer (int nType, int cOffset, int cNeeded, unsigned char *d, int fCleanPackets);
int PacketSize (int nType);
int CompletePacket (int nType);

int RetrievePacket (unsigned char *pBuffer, int *pnLen, int *pnType, DWORD *pdwTimeout);

BOOL CloseConnectionHelper();
void ReleaseSlot (int iSlotIndex);

public:
LPCUSB_FUNCS _lpUsbFuncs;
FixedMemDescr *_pfmdPackets;

protected:
USB_HANDLE _hDevice;

USB_ENDPOINT_DESCRIPTOR _endpEvents;
USB_ENDPOINT_DESCRIPTOR _endpACLIn;
USB_ENDPOINT_DESCRIPTOR _endpACLOut;

USB_ENDPOINT_DESCRIPTOR _endpSCOIn[NUM_SCO_ENDPOINTS];
UCHAR _endpSCOAltSetting[NUM_SCO_ENDPOINTS];
USB_ENDPOINT_DESCRIPTOR _endpSCOOut[NUM_SCO_ENDPOINTS];
int _nSCOInCount, _nSCOOutCount;
int _nScoPipeIdx;
DWORD _dwInTransferLens[MAX_SCO_READ_FRAMES_PER_TRANSFER];
DWORD _dwOutTransferLens[SCO_FRAMES_PER_PACKET];
DWORD _dwSuggestedScoAltSetting;

LPCUSB_INTERFACE _pIntfEvent;

CUsbPipe _usbPipes[NUM_IN_PIPES];

USB_PIPE _hOutPipes[NUM_OUT_PIPES];

BOOL _bClosing;
BOOL _bInitialized;
BOOL _bCloseScoIO;

unsigned int _uiPacketSize;
unsigned int _uiBlockSize;
unsigned int _uiMinPacketSize;
unsigned int _uiSCOReadFrames;
unsigned int _uiSCOMaxWriteTransfers;
unsigned int _uiSCOWritePackets;
unsigned int _bAsyncMode;
unsigned int _bAsyncScoMode;
unsigned int _bAsyncModeError;

#if defined (NATIVE_SEQUENCING)
CompletedPacket *_pPacketList;
CompletedPacket *_pLastPacket;
#endif

#if defined (CONNECTION_TRACKING)
SVSTree *_pHandleTree;
#endif
};




class PACKET
{
public:
int nSize;
int nOffset;
PACKET *pNext;

#if defined (CONNECTION_TRACKING)
DWORD dwWhenReceived;
#endif

unsigned char data[1];

public:
PACKET (void)
{
memset (this, 0, sizeof(*this));
}

void *operator new(size_t nSize)
{
ASSERT(gpUsbDevice->_pfmdPackets);
ASSERT(nSize == sizeof(PACKET));

void *pPacket = svsutil_GetFixed(gpUsbDevice->_pfmdPackets);
ASSERT(pPacket);
return pPacket;
}

void operator delete(void *ptr)
{
ASSERT(ptr);
svsutil_FreeFixed(ptr, gpUsbDevice->_pfmdPackets);
}
};

#if defined (CONNECTION_TRACKING)
#define HCI_Connection_Complete_Event 0x03
#define HCI_Disconnection_Complete_Event 0x05
#define HCI_Command_Complete_Event 0x0e
#define HCI_Reset 0x0c03
#endif

#endif
yangyzqo 2005-12-23
  • 打赏
  • 举报
回复
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/*++
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
PARTICULAR PURPOSE.

Module Name:

usbdev.h

Abstract:

Bluetooth HCI USB interface


Functions:


Notes:

--*/
#ifndef _USBDEV_H_
#define _USBDEB_H_

//
// There are two build flags that define how desynchronization
// of event and data channel is handled.
//
// Problem description:
// There is not synchronization between event and data channels,
// which means that data on connection can preceed connection completion
// event and therefore thrown out. This is solved in USB driver (if
// CONNECTION_TRACKING is defined) by keeping list of existing connections
// and stalling data pipe if data packet came on nonexistent connection.
// The following events are processed to track connection states:
// HCI_Connection_Complete_Event = 0x03,
// HCI_Disconnection_Complete_Event = 0x05,
// HCI_Command_Complete_Event = 0x0e for HCI_Reset command
// Note, that this policy makes reversal of data packet and
// disconnection events even worse, but this is less likely since
// normally there is a lag between last packet and when the connection is
// actually closed. Slight bias in processing events (they are processed
// before data) is given to rectify this situation even further.
//
// If CONNECTION_TRACKING is not defined, NATIVE_SEQUENCING flag can be
// used to forwrd packets up in exactly the sequence in which they arrived
// from the driver. If this flag is not defined, slight bias is given to
// event packets.
//
#define CONNECTION_TRACKING 1

#if defined (CONNECTION_TRACKING) && defined (NATIVE_SEQUENCING)
#error Connection tracking and native sequencing not supported
#endif

#define SCO_FRAMES_PER_PACKET 3

#define SCO_READ_PACKETS_PER_TRANSFER 9
#define MAX_SCO_READ_PACKETS_PER_TRANSFER 15
#define MAX_SCO_READ_FRAMES_PER_TRANSFER (MAX_SCO_READ_PACKETS_PER_TRANSFER * SCO_FRAMES_PER_PACKET)

//
// These constants control the characteristics of the SCO writing system.
//
#define SCO_WRITE_NUMBER_OF_TRANSFER_SLOTS 8 // total number of slots
#define SCO_WRITE_MAX_CONCURRENT_TRANSFERS 6 // num of concurrent transfers that system strives to acheive
#define SCO_WRITE_MAX_PACKETS_PER_TRANSFER 30 // capacity of slots (in number of packets)
#define SCO_WRITE_MIN_PACKETS_FOR_UNFILLED_TRANSFER 10 // don't issue an gUnfilledQ transfer unless it has at least this many packets
#define SCO_WRITE_START_MIN_CONCURRENT_TRANSFERS 5 // when system starting: wait until we have this many issuable slots
#define SCO_WRITE_START_MIN_PACKETS_PER_TRANSFER 10 // when system starting: how many packets to put in slot

#define DEFPACKETSIZE 256
#define DEFBLOCKSIZE 5

#define NUM_SCO_ENDPOINTS 6
#define NUM_IN_PIPES 3
#define NUM_OUT_PIPES 2

#define PACKET_SCO 0
#define PACKET_ACL 1
#define PACKET_COMMAND 2

#define SCO_HEADER_SIZE 3
#define ACL_HEADER_SIZE 4
#define EVENT_HEADER_SIZE 2

#define EVENT_ISOCH 0
#define EVENT_BULK 1
#define EVENT_INTERRUPT 2
#define EVENT_CLOSE 3
#define EVENT_WRITTEN 4
#define EVENT_SCO_WRITTEN 5

#define PACKET_SIZE_R (64 * 1024 + 128)
#define PACKET_SIZE_W (255 + 3)

#if defined (CONNECTION_TRACKING)
#define CONNECTION_TRACKING_TIMEOUT 1000
#endif

class PACKET;
class CUsbPipe;
class CUsbDevice;
class CSynch;

extern CSynch *gpsynchUsbDevice;
extern CUsbDevice *gpUsbDevice;
extern HANDLE gheventRead[NUM_IN_PIPES];
extern HANDLE gheventClose;
extern HANDLE gheventWritten;
extern HANDLE gheventPackets;

extern HCI_TransportCallback gCallback;
extern HINSTANCE ghInst;

extern int giScoWriteMaxPacketSize;
extern int giScoWriteNumPackets;

class CSynch : public SVSSynch
{
};

class CLocalCriticalSection
{
protected:
CSynch *m_pSynch;

public:
CLocalCriticalSection (CSynch *pSynch)
{
m_pSynch = pSynch;
pSynch->Lock();
}

~CLocalCriticalSection (void)
{
m_pSynch->Unlock();
}

inline int IsLocked()
{
return m_pSynch->IsLocked();
}
};

21,597

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 驱动开发/核心开发
社区管理员
  • 驱动开发/核心开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧