cmds.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2011 Vojtech Horky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00036 #ifndef USB_USBMAST_CMDS_H_
00037 #define USB_USBMAST_CMDS_H_
00038 
00039 #include <sys/types.h>
00040 #include <usb/usb.h>
00041 
00042 typedef struct {
00043         uint32_t dCBWSignature;
00044         uint32_t dCBWTag;
00045         uint32_t dCBWDataTransferLength;
00046         uint8_t bmCBWFlags;
00047         uint8_t bCBWLUN;
00048         uint8_t bCBWBLength;
00049         uint8_t CBWCB[16];
00050 } __attribute__((packed)) usb_massstor_cbw_t;
00051 
00052 typedef struct {
00053         uint32_t dCSWSignature;
00054         uint32_t dCSWTag;
00055         uint32_t dCSWDataResidue;
00056         uint8_t dCSWStatus;
00057 } __attribute__((packed)) usb_massstor_csw_t;
00058 
00059 static inline void usb_massstor_cbw_prepare(usb_massstor_cbw_t *cbw,
00060     uint32_t tag, uint32_t transfer_length, usb_direction_t dir,
00061     uint8_t lun, uint8_t cmd_len, uint8_t *cmd)
00062 {
00063         cbw->dCBWSignature = uint32_host2usb(0x43425355);
00064         cbw->dCBWTag = tag;
00065         cbw->dCBWDataTransferLength = transfer_length;
00066 
00067         cbw->bmCBWFlags = 0;
00068         if (dir == USB_DIRECTION_IN) {
00069                 cbw->bmCBWFlags |= (1 << 7);
00070         }
00071 
00072         /* Only lowest 4 bits. */
00073         cbw->bCBWLUN = lun & 0x0F;
00074 
00075         /* Only lowest 5 bits. */
00076         cbw->bCBWBLength = cmd_len & 0x1F;
00077 
00078         memcpy(cbw->CBWCB, cmd, cbw->bCBWBLength);
00079 }
00080 
00081 #endif
00082 

Generated on Thu Jun 2 07:45:40 2011 for HelenOS/USB by  doxygen 1.4.7