阅读:2029回复:0
1394ddk程序分析疑难点
DDK中的IsochAttachBuffers(
HWND hWnd, PSTR szDeviceName, PISOCH_ATTACH_BUFFERS isochAttachBuffers, BOOL bAutoAlloc, BOOL bAutoFill ) { HANDLE hDevice; PISOCH_ATTACH_BUFFERS pIsochAttachBuffers; PRING3_ISOCH_DESCRIPTOR pR3TempDescriptor; RING3_ISOCH_DESCRIPTOR R3_IsochDescriptor; OVERLAPPED overLapped; ULONG ulBufferSize; DWORD dwBytesRet; DWORD dwRet; ULONG i, n; hDevice = OpenDevice(hWnd, szDeviceName, TRUE); if (hDevice != INVALID_HANDLE_VALUE) { R3_IsochDescriptor = isochAttachBuffers->R3_IsochDescriptor[0]; // they are always required to give me at least one filled in ring3 isoch descriptor. // this way if they set the bAutoAlloc flag, i have a template on what to set up. // basically, i\'ll auto allocate however many descriptors they want, base on the first one. // if they want something more, then they are required to allocate all of the descriptors themselves // // if the bAutoAlloc flag is set, that means that we allocate according to // the first descriptor. we assume there\'s only one configured descriptor // if (bAutoAlloc) { // lets calculate the buffer size ulBufferSize = sizeof(ISOCH_ATTACH_BUFFERS) + (isochAttachBuffers->R3_IsochDescriptor[0].ulLength*isochAttachBuffers->nNumberOfDescriptors) + (sizeof(RING3_ISOCH_DESCRIPTOR)*(isochAttachBuffers->nNumberOfDescriptors-1)); TRACE(TL_TRACE, (hWnd, \"size of ISOCH_ATTACH_BUFFERS = %d\\r\\n\", sizeof(ISOCH_ATTACH_BUFFERS))); TRACE(TL_TRACE, (hWnd, \"size of CYCLE_TIME = %d\\r\\n\", sizeof(CYCLE_TIME))); TRACE(TL_TRACE, (hWnd, \"size of HANDLE = %d\\r\\n\", sizeof( HANDLE))); TRACE(TL_TRACE, (hWnd, \"size of ulBufferSize = %d\\r\\n\", ulBufferSize)); pIsochAttachBuffers = (PISOCH_ATTACH_BUFFERS)LocalAlloc(LPTR, ulBufferSize); if (!pIsochAttachBuffers) { dwRet = GetLastError(); TRACE(TL_ERROR, (hWnd, \"Could not allocate pIsochAttachBuffers\\r\\n\")); goto Exit_IsochAttachBuffers; } ZeroMemory(pIsochAttachBuffers, ulBufferSize); *pIsochAttachBuffers = *isochAttachBuffers; // // now we need to setup each descriptor // pR3TempDescriptor = &pIsochAttachBuffers->R3_IsochDescriptor[0]; for (i=0; i < isochAttachBuffers->nNumberOfDescriptors; i++) { *pR3TempDescriptor = R3_IsochDescriptor; TRACE(TL_TRACE, (hWnd, \"(ULONG_PTR)pR3TempDescriptor = %d\\r\\n\", (ULONG_PTR)pR3TempDescriptor)); TRACE(TL_TRACE, (hWnd, \"pR3TempDescriptor->ulLength= %d\\r\\n\", pR3TempDescriptor->ulLength)); pR3TempDescriptor = (PRING3_ISOCH_DESCRIPTOR)((ULONG_PTR)pR3TempDescriptor + pR3TempDescriptor->ulLength + sizeof(RING3_ISOCH_DESCRIPTOR)); TRACE(TL_TRACE, (hWnd, \"pR3TempDescriptor = %d\\r\\n\", pR3TempDescriptor)); TRACE(TL_TRACE, (hWnd, \"sizeof(RING3_ISOCH_DESCRIPTOR= %d\\r\\n\", sizeof(RING3_ISOCH_DESCRIPTOR))); } } else { // we have already received an allocated buffer, let\'s just map it into // our attach struct and pass it down. pIsochAttachBuffers = isochAttachBuffers; ulBufferSize = pIsochAttachBuffers->ulBufferSize; } TRACE(TL_TRACE, (hWnd, \"pIsochAttachBuffers = %d\\r\\n\", pIsochAttachBuffers)); if (pIsochAttachBuffers) { overLapped.hEvent = CreateEvent( NULL, TRUE, FALSE, NULL ); // reset our event, in case we\'ll be doing another attach ResetEvent(overLapped.hEvent); if (bAutoFill) { // get the point to the first descriptor pR3TempDescriptor = &pIsochAttachBuffers->R3_IsochDescriptor[0]; for (i=0; i < pIsochAttachBuffers->nNumberOfDescriptors; i++) { // if we\'re listening, fill it with 0\'s // if we\'re talking, fill it incrementally TRACE(TL_TRACE, (hWnd, \"size of isochAttachBuffers->R3_IsochDescriptor.fulFlags= %d\\r\\n\", isochAttachBuffers->R3_IsochDescriptor[0].fulFlags)); if (isochAttachBuffers->R3_IsochDescriptor.fulFlags & RESOURCE_USED_IN_LISTENING) { FillMemory(&pR3TempDescriptor->Data, pR3TempDescriptor->ulLength, 0); TRACE(TL_TRACE, (hWnd, \"pR3TempDescriptor->Data = %d\\r\\n\", *pR3TempDescriptor->Data)); } else { if (pR3TempDescriptor->fulFlags == DESCRIPTOR_HEADER_SCATTER_GATHER) { } else { for (n=0; n < (pR3TempDescriptor->ulLength/sizeof(ULONG)); n++) { CopyMemory((ULONG *)&pR3TempDescriptor->Data+n, (ULONG *)&n, sizeof(ULONG)); //TRACE(TL_TRACE, (hWnd, \"(ULONG )&pR3TempDescriptor->Data = %d\\r\\n\", *pR3TempDescriptor->Data+n)); } } } pR3TempDescriptor = (PRING3_ISOCH_DESCRIPTOR)((ULONG_PTR)pR3TempDescriptor + pR3TempDescriptor->ulLength + sizeof(RING3_ISOCH_DESCRIPTOR)); } } } TRACE(TL_TRACE, (hWnd, \"pIsochAttachBuffers = %d\\r\\n\", pIsochAttachBuffers->R3_IsochDescriptor[0].ulLength)); //&pIsochAttachBuffers->R3_IsochDescriptor[0]=pR3TempDescriptor; DeviceIoControl( hDevice, IOCTL_ISOCH_ATTACH_BUFFERS, pIsochAttachBuffers, ulBufferSize, pIsochAttachBuffers, ulBufferSize, &dwBytesRet, &overLapped); dwRet = GetLastError(); if ((dwRet != ERROR_SUCCESS) && (dwRet != ERROR_IO_PENDING)) { TRACE(TL_ERROR, (hWnd, \"IsochAttachBuffers Failed = %d\\r\\n\", dwRet)); } else { // we got a pending, so we need to wait... if (dwRet == ERROR_IO_PENDING) { if (!GetOverlappedResult(hDevice, &overLapped, &dwBytesRet, TRUE)) { // getoverlappedresult failed, lets find out why... dwRet = GetLastError(); TRACE(TL_ERROR, (hWnd, \"IsochAttachBuffers1: GetOverlappedResult Failed! dwRet = %d\\r\\n\", dwRet)); } } } // free up resources CloseHandle(hDevice); } else { dwRet = GetLastError(); TRACE(TL_ERROR, (hWnd, \"Error = 0x%x\\r\\n\", dwRet)); } Exit_IsochAttachBuffers: TRACE(TL_TRACE, (hWnd, \"pIsochDescriptor = 0x%x\\r\\n\", pIsochAttachBuffers->pIsochDescriptor)); TRACE(TL_TRACE, (hWnd, \"Exit IsochAttachBuffers\\r\\n\")); return(dwRet); } // IsochAttachBuffers 这个函数中的pR3TempDescriptor跟pIsochAttachBuffers好像没有关系,有谁研究过? |
|