Re: Write/Read Bulk communication process in KEXT. How?
Re: Write/Read Bulk communication process in KEXT. How?
- Subject: Re: Write/Read Bulk communication process in KEXT. How?
- From: Chinki <email@hidden>
- Date: Thu, 25 May 2006 14:45:18 +0530
Hi Micheal,
Thanks a lot for your suggestion!! I really appreciate the time you took to look into my code and sent your suggestions. Below is the updated code which communicates well with the USB bulk device (it might be useful to other users too!).
Again, please correct me for my mistakes in the code if any,
/////////////////////////////
bulkDeviceCommuncation()
{
IOReturn status = kIOReturnNoDevice;
UInt32 size = 0;
IOMemoryDescriptor *memDescOut = NULL;
IOMemoryDescriptor *memDescIn = NULL;
// Allocate the memory descriptor needed
memDescOut = IOMemoryDescriptor::withAddress(
(void *)&Command,
sizeof(COMMAND),
kIODirectionOut);
if ( memDescOut == NULL )
{
return kIOReturnNoResources;
}
if(!myDataStructure->fOutPipe)
{
DBLog(("\nOutpipe not valid\n"));
return kIOReturnNoDevice;
}
// Prepare the memory for I/O Transfer
status = memDescOut->prepare(memDescOut->getDirection());
if(status != kIOReturnSuccess){
return status;
}
status = (myDataStructure->fOutPipe)->Write( memDescOut,
(UInt32)1000, // Use the client's timeout for both
(UInt32)2000,
sizof(COMMAND),
(IOUSBCompletion*)NULL );
if(status == kIOReturnSuccess) {
// Complete process of memory after i/o transaction finsishes
status = memDescOut->complete(memDescOut->getDirection());
if(status != kIOReturnSuccess){
return status;
}
memDescIn = IOMemoryDescriptor::withAddress( (void*)&Response,
sizof(RESPONSE),
kIODirectionIn);
if ( memDescIn == NULL )
{
return kIOReturnNoResources;
}
// Prepare the memory for I/O Transfer
status = memDescIn->prepare(memDescIn->getDirection());
if(status != kIOReturnSuccess){
return status;
}
status = (myDataStructure->fInPipe)->Read(memDescIn,
(UInt32)1000,
(UInt32)2000,
size,
(IOUSBCompletion*)NULL,
&size);
} else {
return status;
}
if(status != kIOReturnSuccess){
return status;
}
// Complete process of memory after i/o transaction finsishes
status = memDescIn->complete(memDescIn->getDirection());
if(status != kIOReturnSuccess){
return status;
}
//free
memDescIn = NULL;
memDescOut = NULL;
return status;
}
//////////////////////////////
All suggestions /comments are most welcome ! Your comments/suggestions are most valuable !!
Faithfully yours,
Chinki
On 5/25/06, Michael Smith <email@hidden> wrote:
On May 24, 2006, at 9:02 PM, Chinki wrote:
> Step4. Communicating with the KEY [ MAIN PART OF OUR DISCUSSION]
>
> a) I get the structure (got from user level) and Allocate the
> memory using IOMemoryDescriptor in my communication module (kext)
> i.e,
> // assign for OUT pipe
> IOMemoryDescriptor *memDescOut = NULL;
>
> // assign for IN pipe
> IOMemoryDescriptor *memDescIN = NULL;
>
> // Now create and initialize an IOMemoryDescriptor for memory FOR
> WRITE
> memDescOut = IOMemoryDescriptor::withAddress( (void*)
> &myOutStructure, sizeof(MY_OUTSTRUCTURE), kDirectionOUT)
I assume you mean kIODirectionOut?
>
> // check for validation of memDescOut
> // Fill myOutStructure
>
> // Do write operation with the allocated outpipe
> status = (pdx->fOUTPipe)->Write( memDescOut, (UInt32)1000, (UInt32)
> 2000, size, NULL);
You are missing the ->prepare() and ->complete() calls.
> // Similarly for IN structure
>
> // Now create and initialize an IOMemoryDescriptor for memory FOR READ
> memDescIN = IOMemoryDescriptor::withAddress( (void*)&myINStructure,
> sizeof(MY_OUTSTRUCTURE), kDirectionOUT)
I assume you mean kIODirectionIn?
> // check for validation of memDescIn
> // Fill myOutStructure
>
> // Do write operation with the allocated outpipe
> status = (pdx->fINPipe)->Read( memDescIN , (UInt32)1000, (UInt32)
> 2000, size, NULL, &gotsize);
You are missing the ->prepare() and ->complete() calls.
I also note that you're not checking the result of the
IOMemoryDescriptor::withAddress() calls. It's imperative that you do
this, and handle the case where they return NULL in a sensible fashion.
= Mike
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden