site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; b=CY4KTN3MSFbLBpqKUIbiYi3dTk4qwdZzeCCNN+ZtLeCxVdYnCpA00o/7SdQFeWCRT9N9Nq+9C0RKjA20N88Ey9DIbBdEe6xSFIvEMKno1p2wRYTOZfQubvcM6PpiMWmpaNcp04An1Gjdhoc4ANGsYn/2yEGJHLZUExu9xKn5K04= Hi, Thanks for your reply. With help of the experts, I have finally able to do cross boundary communication successfully. Below is the code snippet for your review. As per Terrys and Michael comments, I have allocated the Command packet memory dynamically and the response packet is kept statically allocated. Shared Structure: ================= typedef struct { unsigned long CmdSize; // Size of command parameters unsigned char InstCode; // Opcode part of CmdCode (set by driver) } CMD_HEAD, *PCMD_HEAD; typedef struct { unsigned long RspSize; // Size of data returned unsigned char ErrorInfo; // Error information } RSP_HEAD, *PRSP_HEAD; typedef union _IOCTL_COMMAND { PCMD_HEAD pApiCmd;// Pointer to Command head RSP_HEAD ApiRsp; // Response head buffer } IOCTL_COMMAND , *PIOCTL_COMMAND; typedef struct { unsigned long pIndex; //the index required by GetDeviceInfo unsigned long iBufferSz; //The command Sz unsigned long oBufferSz; //the expected output Buffer size IOCTL_COMMAND IOCmd; } COMMAND_EXCHANGE, *PCOMMAND_EXCHANGE; At Application Layer: ===================== // assign the input buffer to structIn structIn.IOCmd.pApiCmd = iBuffer; // iBuffer is the void* buffer // Struct Input and Structure output kernReturn = IOConnectMethodStructureIStructureO(*dataPort, myDriverAPICommand, inBuffSize, &outBuffSize, &structIn, &structOut); // copy the output data in oBuffer memcpy(oBuffer, &(structOut.IOCmd.ApiRsp) , oBufferSize); At KEXT Layer: ============= In IOUserClient class: IOReturn myDriverUserClient::CommonAPICmd( COMMAND_EXCHANGE* inpkt, COMMAND_EXCHANGE* outpkt){ PCMD_HEAD pCmd = NULL; PRSP_HEAD pRsp = NULL; pCmd = (PCMD_HEAD)IOMalloc(inputSize); pRsp = (PRSP_HEAD)&(inpkt->IOCmd.ApiRsp); if( (pCmd == NULL) || (pRsp == NULL)) { DBLog(("\nMemory could not be allocated\n")); return kIOReturnNoResources; } status = copyin( (user_addr_t) inpkt->IOCmd.pApiCmd, pCmd, inputSize); .. .. } Bulk communication Module: ========================= In IOService: And then pass the command info to the BULK Communication module: bulkDeviceCommuncation() { IOReturn status; UInt32 size; IOMemoryDescriptor *memDescOut = NULL; IOMemoryDescriptor *memDescIn = NULL; // Validate and allocate if (myDataStructure->fOutPipe == NULL) { status = kIOReturnNoDevice; goto out; } if ((memDescOut = IOMemoryDescriptor::withAddress(&Command, sizeof(COMMAND), kIODirectionOut) == NULL) { status = kIOReturnNoMemory; goto out; } if ((memDescIn = IOMemoryDescriptor::withAddress(&Response, sizeof(RESPONSE), kIODirectinIn) == NULL) { status = kIOReturnNoMemory; goto out; } // do outbound command if ((status = memDescOut->prepare()) != kIOReturnSuccess) goto out; status = myDataStructure->fOutPipe->Write(memDescOut, 1000, 2000, sizeof(COMMAND), NULL); memDescOut->complete(); if (status != kIOReturnSuccess) goto out; // do inbound response if ((status = memDescIn->prepare()) != kIOReturnSuccess) goto out; status = myDataStructure->fInPipe->Read(memDescIn, 1000, 2000, size, NULL, &size); memDescIn->complete(); out: if (memDescOut) memDescOut->release(); if (memDescIn) memDescIn->release(); return(status); } Please send your comments for the same. Thanks and Regards, Rohit Dhamija _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com