libcdio
0.83
|
00001 /* 00002 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 00003 Rocky Bernstein <rocky@gnu.org> 00004 00005 This program is free software: you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation, either version 3 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00036 #ifndef __CDIO_MMC_H__ 00037 #define __CDIO_MMC_H__ 00038 00039 #include <cdio/cdio.h> 00040 #include <cdio/types.h> 00041 #include <cdio/dvd.h> 00042 #include <cdio/audio.h> 00043 #include <cdio/mmc_util.h> 00044 00045 #ifdef __cplusplus 00046 extern "C" { 00047 #endif /* __cplusplus */ 00048 00049 /* On GNU/Linux see <linux/byteorder/big_endian.h> and 00050 <linux/byteorder/little_endian.h> 00051 */ 00052 #ifdef WORDS_BIGENDIAN 00053 # if !defined(__LITTLE_ENDIAN_BITFIELD) && !defined(__BIG_ENDIAN_BITFIELD) 00054 # define __MMC_BIG_ENDIAN_BITFIELD 00055 # endif 00056 #else 00057 # if !defined(__LITTLE_ENDIAN_BITFIELD) && !defined(__BIG_ENDIAN_BITFIELD) 00058 # define __MMC_LITTLE_ENDIAN_BITFIELD 00059 # endif 00060 #endif 00061 00069 typedef struct cdio_mmc_request_sense { 00070 #if defined(__MMC_BIG_ENDIAN_BITFIELD) 00071 uint8_t valid : 1; 00072 uint8_t error_code : 7; 00073 #else 00074 uint8_t error_code : 7; 00075 uint8_t valid : 1; 00076 #endif 00077 uint8_t segment_number; 00078 #if defined(__MMC_BIG_ENDIAN_BITFIELD) 00079 uint8_t filemark : 1; 00081 uint8_t eom : 1; 00084 uint8_t ili : 1; 00085 uint8_t reserved1 : 1; 00086 uint8_t sense_key : 4; 00087 #else 00088 uint8_t sense_key : 4; 00089 uint8_t reserved1 : 1; 00090 uint8_t ili : 1; 00091 uint8_t eom : 1; 00094 uint8_t filemark : 1; 00096 #endif 00097 uint8_t information[4]; 00098 uint8_t additional_sense_len; 00099 uint8_t command_info[4]; 00100 uint8_t asc; 00101 uint8_t ascq; 00102 uint8_t fruc; 00103 uint8_t sks[3]; 00104 uint8_t asb[46]; 00105 } cdio_mmc_request_sense_t; 00106 00107 00111 typedef enum { 00112 CDIO_MMC_SENSE_KEY_NO_SENSE = 0, 00113 CDIO_MMC_SENSE_KEY_RECOVERED_ERROR = 1, 00114 CDIO_MMC_SENSE_KEY_NOT_READY = 2, 00115 CDIO_MMC_SENSE_KEY_MEDIUM_ERROR = 3, 00116 CDIO_MMC_SENSE_KEY_HARDWARE_ERROR = 4, 00117 CDIO_MMC_SENSE_KEY_ILLEGAL_REQUEST = 5, 00118 CDIO_MMC_SENSE_KEY_UNIT_ATTENTION = 6, 00119 CDIO_MMC_SENSE_KEY_DATA_PROTECT = 7, 00120 CDIO_MMC_SENSE_KEY_BLANK_CHECK = 8, 00121 CDIO_MMC_SENSE_KEY_VENDOR_SPECIFIC = 9, 00122 CDIO_MMC_SENSE_KEY_COPY_ABORTED = 10, 00123 CDIO_MMC_SENSE_KEY_ABORTED_COMMAND = 11, 00124 CDIO_MMC_SENSE_KEY_OBSOLETE = 12, 00125 } cdio_mmc_sense_key_t; 00126 00138 typedef enum { 00139 CDIO_MMC_GPCMD_TEST_UNIT_READY = 0x00, 00140 CDIO_MMC_GPCMD_INQUIRY = 0x12, 00142 CDIO_MMC_GPCMD_MODE_SELECT_6 = 0x15, 00144 CDIO_MMC_GPCMD_MODE_SENSE_6 = 0x1a, 00149 CDIO_MMC_GPCMD_START_STOP_UNIT = 0x1b, 00151 CDIO_MMC_GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL 00152 = 0x1e, 00158 CDIO_MMC_GPCMD_READ_10 = 0x28, 00160 CDIO_MMC_GPCMD_READ_SUBCHANNEL = 0x42, 00162 CDIO_MMC_GPCMD_READ_TOC = 0x43, 00164 CDIO_MMC_GPCMD_READ_HEADER = 0x44, 00165 CDIO_MMC_GPCMD_PLAY_AUDIO_10 = 0x45, 00168 CDIO_MMC_GPCMD_GET_CONFIGURATION = 0x46, 00170 CDIO_MMC_GPCMD_PLAY_AUDIO_MSF = 0x47, 00173 CDIO_MMC_GPCMD_PLAY_AUDIO_TI = 0x48, 00174 CDIO_MMC_GPCMD_PLAY_TRACK_REL_10 = 0x49, 00181 CDIO_MMC_GPCMD_GET_EVENT_STATUS = 0x4a, 00183 CDIO_MMC_GPCMD_PAUSE_RESUME = 0x4b, 00187 CDIO_MMC_GPCMD_READ_DISC_INFO = 0x51, 00189 CDIO_MMC_GPCMD_READ_TRACK_INFORMATION = 0x52, 00191 CDIO_MMC_GPCMD_MODE_SELECT_10 = 0x55, 00193 CDIO_MMC_GPCMD_MODE_SENSE_10 = 0x5a, 00202 CDIO_MMC_GPCMD_PLAY_AUDIO_12 = 0xa5, 00205 CDIO_MMC_GPCMD_LOAD_UNLOAD = 0xa6, 00207 CDIO_MMC_GPCMD_READ_12 = 0xa8, 00209 CDIO_MMC_GPCMD_PLAY_TRACK_REL_12 = 0xa9, 00215 CDIO_MMC_GPCMD_READ_DVD_STRUCTURE = 0xad, 00217 CDIO_MMC_GPCMD_READ_MSF = 0xb9, 00220 CDIO_MMC_GPCMD_SET_SPEED = 0xbb, 00230 CDIO_MMC_GPCMD_READ_CD = 0xbe, 00236 CDIO_MMC_GPCMD_CD_PLAYBACK_STATUS = 0xc4 , 00237 CDIO_MMC_GPCMD_PLAYBACK_CONTROL = 0xc9 , 00238 CDIO_MMC_GPCMD_READ_CDDA = 0xd8 , 00239 CDIO_MMC_GPCMD_READ_CDXA = 0xdb , 00240 CDIO_MMC_GPCMD_READ_ALL_SUBCODES = 0xdf 00241 } cdio_mmc_gpcmd_t; 00242 00243 00247 typedef enum { 00248 CDIO_MMC_READ_SUB_ST_INVALID = 0x00, 00249 CDIO_MMC_READ_SUB_ST_PLAY = 0x11, 00251 CDIO_MMC_READ_SUB_ST_PAUSED = 0x12, 00252 CDIO_MMC_READ_SUB_ST_COMPLETED = 0x13, 00254 CDIO_MMC_READ_SUB_ST_ERROR = 0x14, 00256 CDIO_MMC_READ_SUB_ST_NO_STATUS = 0x15, 00258 } cdio_mmc_read_sub_state_t; 00259 00261 typedef enum { 00262 CDIO_MMC_READ_TYPE_ANY = 0, 00263 CDIO_MMC_READ_TYPE_CDDA = 1, 00264 CDIO_MMC_READ_TYPE_MODE1 = 2, 00265 CDIO_MMC_READ_TYPE_MODE2 = 3, 00266 CDIO_MMC_READ_TYPE_M2F1 = 4, 00267 CDIO_MMC_READ_TYPE_M2F2 = 5 00268 } cdio_mmc_read_cd_type_t; 00269 00273 typedef enum { 00274 CDIO_MMC_READTOC_FMT_TOC = 0, 00275 CDIO_MMC_READTOC_FMT_SESSION = 1, 00276 CDIO_MMC_READTOC_FMT_FULTOC = 2, 00277 CDIO_MMC_READTOC_FMT_PMA = 3, 00278 CDIO_MMC_READTOC_FMT_ATIP = 4, 00279 CDIO_MMC_READTOC_FMT_CDTEXT = 5 00280 } cdio_mmc_readtoc_t; 00281 00285 typedef enum { 00286 CDIO_MMC_R_W_ERROR_PAGE = 0x01, 00287 CDIO_MMC_WRITE_PARMS_PAGE = 0x05, 00288 CDIO_MMC_CDR_PARMS_PAGE = 0x0d, 00289 CDIO_MMC_AUDIO_CTL_PAGE = 0x0e, 00290 CDIO_MMC_POWER_PAGE = 0x1a, 00291 CDIO_MMC_FAULT_FAIL_PAGE = 0x1c, 00292 CDIO_MMC_TO_PROTECT_PAGE = 0x1d, 00293 CDIO_MMC_CAPABILITIES_PAGE = 0x2a, 00294 CDIO_MMC_ALL_PAGES = 0x3f, 00295 } cdio_mmc_mode_page_t; 00296 00300 typedef enum { 00301 CDIO_MMC_READ_DISC_INFO_STANDARD = 0x0, 00302 CDIO_MMC_READ_DISC_INFO_TRACK = 0x1, 00303 CDIO_MMC_READ_DISC_INFO_POW = 0x2, 00304 } cdio_mmc_read_disc_info_datatype_t; 00305 00306 00307 PRAGMA_BEGIN_PACKED 00308 struct mmc_audio_volume_entry_s 00309 { 00310 uint8_t selection; /* Only the lower 4 bits are used. */ 00311 uint8_t volume; 00312 } GNUC_PACKED; 00313 00314 typedef struct mmc_audio_volume_entry_s mmc_audio_volume_entry_t; 00315 00319 struct mmc_audio_volume_s 00320 { 00321 mmc_audio_volume_entry_t port[4]; 00322 } GNUC_PACKED; 00323 00324 typedef struct mmc_audio_volume_s mmc_audio_volume_t; 00325 00326 PRAGMA_END_PACKED 00327 00328 00332 typedef enum { 00333 CDIO_MMC_GET_CONF_ALL_FEATURES = 0, 00335 CDIO_MMC_GET_CONF_CURRENT_FEATURES = 1, 00338 CDIO_MMC_GET_CONF_NAMED_FEATURE = 2 00340 } cdio_mmc_get_conf_t; 00341 00342 00347 typedef enum { 00348 CDIO_MMC_FEATURE_PROFILE_LIST = 0x000, 00349 CDIO_MMC_FEATURE_CORE = 0x001, 00350 CDIO_MMC_FEATURE_MORPHING = 0x002, 00352 CDIO_MMC_FEATURE_REMOVABLE_MEDIUM = 0x003, 00353 CDIO_MMC_FEATURE_WRITE_PROTECT = 0x004, 00354 CDIO_MMC_FEATURE_RANDOM_READABLE = 0x010, 00355 CDIO_MMC_FEATURE_MULTI_READ = 0x01D, 00356 CDIO_MMC_FEATURE_CD_READ = 0x01E, 00357 CDIO_MMC_FEATURE_DVD_READ = 0x01F, 00358 CDIO_MMC_FEATURE_RANDOM_WRITABLE = 0x020, 00359 CDIO_MMC_FEATURE_INCR_WRITE = 0x021, 00361 CDIO_MMC_FEATURE_SECTOR_ERASE = 0x022, 00362 CDIO_MMC_FEATURE_FORMATABLE = 0x023, 00363 CDIO_MMC_FEATURE_DEFECT_MGMT = 0x024, 00367 CDIO_MMC_FEATURE_WRITE_ONCE = 0x025, 00369 CDIO_MMC_FEATURE_RESTRICT_OVERW = 0x026, 00371 CDIO_MMC_FEATURE_CD_RW_CAV = 0x027, 00372 CDIO_MMC_FEATURE_MRW = 0x028, 00373 CDIO_MMC_FEATURE_ENHANCED_DEFECT = 0x029, 00374 CDIO_MMC_FEATURE_DVD_PRW = 0x02A, 00375 CDIO_MMC_FEATURE_DVD_PR = 0x02B, 00376 CDIO_MMC_FEATURE_RIGID_RES_OVERW = 0x02C, 00377 CDIO_MMC_FEATURE_CD_TAO = 0x02D, 00378 CDIO_MMC_FEATURE_CD_SAO = 0x02E, 00380 CDIO_MMC_FEATURE_DVD_R_RW_WRITE = 0x02F, 00381 CDIO_MMC_FEATURE_CD_RW_MEDIA_WRITE= 0x037, 00382 CDIO_MMC_FEATURE_DVD_PR_2_LAYER = 0x03B, 00383 CDIO_MMC_FEATURE_POWER_MGMT = 0x100, 00385 CDIO_MMC_FEATURE_CDDA_EXT_PLAY = 0x103, 00388 CDIO_MMC_FEATURE_MCODE_UPGRADE = 0x104, /* Ability for the device to 00389 accept new microcode via 00390 the interface */ 00391 CDIO_MMC_FEATURE_TIME_OUT = 0x105, 00394 CDIO_MMC_FEATURE_DVD_CSS = 0x106, 00397 CDIO_MMC_FEATURE_RT_STREAMING = 0x107, 00400 CDIO_MMC_FEATURE_LU_SN = 0x108, 00402 CDIO_MMC_FEATURE_FIRMWARE_DATE = 0x1FF, 00404 } cdio_mmc_feature_t; 00405 00406 typedef enum { 00407 CDIO_MMC_FEATURE_INTERFACE_UNSPECIFIED = 0, 00408 CDIO_MMC_FEATURE_INTERFACE_SCSI = 1, 00409 CDIO_MMC_FEATURE_INTERFACE_ATAPI = 2, 00410 CDIO_MMC_FEATURE_INTERFACE_IEEE_1394 = 3, 00411 CDIO_MMC_FEATURE_INTERFACE_IEEE_1394A = 4, 00412 CDIO_MMC_FEATURE_INTERFACE_FIBRE_CH = 5 00413 } cdio_mmc_feature_interface_t; 00414 00415 00420 #define MAX_CDB_LEN 12 00421 00426 typedef struct mmc_cdb_s { 00427 uint8_t field[MAX_CDB_LEN]; 00428 } mmc_cdb_t; 00429 00434 typedef struct mmc_feature_list_header_s { 00435 unsigned char length_msb; 00436 unsigned char length_1sb; 00437 unsigned char length_2sb; 00438 unsigned char length_lsb; 00439 unsigned char reserved1; 00440 unsigned char reserved2; 00441 unsigned char profile_msb; 00442 unsigned char profile_lsb; 00443 } cdio_mmc_feature_list_header_t; 00444 00449 typedef enum mmc_direction_s { 00450 SCSI_MMC_DATA_READ, 00451 SCSI_MMC_DATA_WRITE, 00452 SCSI_MMC_DATA_NONE 00453 } cdio_mmc_direction_t; 00460 #define SCSI_MMC_HAS_DIR_NONE 1 00461 00462 typedef struct mmc_subchannel_s 00463 { 00464 uint8_t reserved; 00465 uint8_t audio_status; 00466 uint16_t data_length; 00467 uint8_t format; 00468 uint8_t address: 4; 00469 uint8_t control: 4; 00470 uint8_t track; 00471 uint8_t index; 00472 uint8_t abs_addr[4]; 00473 uint8_t rel_addr[4]; 00474 } cdio_mmc_subchannel_t; 00475 00476 #define CDIO_MMC_SET_COMMAND(cdb, command) \ 00477 cdb[0] = command 00478 00479 #define CDIO_MMC_SET_READ_TYPE(cdb, sector_type) \ 00480 cdb[1] = (sector_type << 2) 00481 00482 #define CDIO_MMC_GETPOS_LEN16(p, pos) \ 00483 (p[pos]<<8) + p[pos+1] 00484 00485 #define CDIO_MMC_GET_LEN16(p) \ 00486 (p[0]<<8) + p[1] 00487 00488 #define CDIO_MMC_GET_LEN32(p) \ 00489 (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3]; 00490 00491 #define CDIO_MMC_SET_LEN16(cdb, pos, len) \ 00492 cdb[pos ] = (len >> 8) & 0xff; \ 00493 cdb[pos+1] = (len ) & 0xff 00494 00495 #define CDIO_MMC_SET_READ_LBA(cdb, lba) \ 00496 cdb[2] = (lba >> 24) & 0xff; \ 00497 cdb[3] = (lba >> 16) & 0xff; \ 00498 cdb[4] = (lba >> 8) & 0xff; \ 00499 cdb[5] = (lba ) & 0xff 00500 00501 #define CDIO_MMC_SET_START_TRACK(cdb, command) \ 00502 cdb[6] = command 00503 00504 #define CDIO_MMC_SET_READ_LENGTH24(cdb, len) \ 00505 cdb[6] = (len >> 16) & 0xff; \ 00506 cdb[7] = (len >> 8) & 0xff; \ 00507 cdb[8] = (len ) & 0xff 00508 00509 #define CDIO_MMC_SET_READ_LENGTH16(cdb, len) \ 00510 CDIO_MMC_SET_LEN16(cdb, 7, len) 00511 00512 #define CDIO_MMC_SET_READ_LENGTH8(cdb, len) \ 00513 cdb[8] = (len ) & 0xff 00514 00515 #define CDIO_MMC_MCSB_ALL_HEADERS 0xf 00516 00517 #define CDIO_MMC_SET_MAIN_CHANNEL_SELECTION_BITS(cdb, val) \ 00518 cdb[9] = val << 3; 00519 00528 driver_return_code_t mmc_audio_get_volume (CdIo_t *p_cdio, /*out*/ 00529 mmc_audio_volume_t *p_volume); 00530 00537 driver_return_code_t 00538 mmc_audio_read_subchannel (CdIo_t *p_cdio, 00539 /*out*/ cdio_subchannel_t *p_subchannel); 00540 00550 driver_return_code_t 00551 mmc_isrc_track_read_subchannel (CdIo_t *p_cdio, /*in*/ const track_t track, 00552 /*out*/ char *p_isrc); 00553 00558 const char *mmc_audio_state2str( uint8_t i_audio_state ); 00559 00566 int mmc_get_blocksize ( CdIo_t *p_cdio ); 00567 00573 uint8_t mmc_get_cmd_len(uint8_t mmc_cmd); 00574 00581 lsn_t mmc_get_disc_last_lsn( const CdIo_t *p_cdio ); 00582 00592 discmode_t mmc_get_discmode( const CdIo_t *p_cdio ); 00593 00594 00595 typedef enum { 00596 CDIO_MMC_LEVEL_WEIRD, 00597 CDIO_MMC_LEVEL_1, 00598 CDIO_MMC_LEVEL_2, 00599 CDIO_MMC_LEVEL_3, 00600 CDIO_MMC_LEVEL_NONE 00601 } cdio_mmc_level_t; 00602 00608 cdio_mmc_level_t mmc_get_drive_mmc_cap(CdIo_t *p_cdio); 00609 00610 00618 discmode_t mmc_get_dvd_struct_physical ( const CdIo_t *p_cdio, 00619 cdio_dvd_struct_t *s); 00620 00627 int mmc_get_tray_status ( const CdIo_t *p_cdio ); 00628 00637 bool mmc_get_hwinfo ( const CdIo_t *p_cdio, 00638 /* out*/ cdio_hwinfo_t *p_hw_info ); 00639 00640 00647 int mmc_get_media_changed(const CdIo_t *p_cdio); 00648 00660 char * mmc_get_mcn(const CdIo_t *p_cdio); 00661 00670 bool_3way_t mmc_have_interface(CdIo_t *p_cdio, 00671 cdio_mmc_feature_interface_t e_interface ); 00672 00673 00692 driver_return_code_t mmc_read_data_sectors ( CdIo_t *p_cdio, void *p_buf, 00693 lsn_t i_lsn, 00694 uint16_t i_blocksize, 00695 uint32_t i_blocks ); 00696 00701 driver_return_code_t mmc_read_sectors ( const CdIo_t *p_cdio, void *p_buf, 00702 lsn_t i_lsn, int read_sector_type, 00703 uint32_t i_blocks); 00704 00720 driver_return_code_t 00721 mmc_run_cmd( const CdIo_t *p_cdio, unsigned int i_timeout_ms, 00722 const mmc_cdb_t *p_cdb, 00723 cdio_mmc_direction_t e_direction, unsigned int i_buf, 00724 /*in/out*/ void *p_buf ); 00725 00745 driver_return_code_t 00746 mmc_run_cmd_len( const CdIo_t *p_cdio, unsigned int i_timeout_ms, 00747 const mmc_cdb_t *p_cdb, unsigned int i_cdb, 00748 cdio_mmc_direction_t e_direction, unsigned int i_buf, 00749 /*in/out*/ void *p_buf ); 00750 00768 int mmc_last_cmd_sense ( const CdIo_t *p_cdio, 00769 cdio_mmc_request_sense_t **pp_sense); 00770 00774 driver_return_code_t mmc_set_blocksize ( const CdIo_t *p_cdio, 00775 uint16_t i_blocksize); 00776 00777 #ifdef __cplusplus 00778 } 00779 #endif /* __cplusplus */ 00780 00787 extern cdio_mmc_feature_t debug_cdio_mmc_feature; 00788 extern cdio_mmc_feature_interface_t debug_cdio_mmc_feature_interface; 00789 extern cdio_mmc_feature_profile_t debug_cdio_mmc_feature_profile; 00790 extern cdio_mmc_get_conf_t debug_cdio_mmc_get_conf; 00791 extern cdio_mmc_gpcmd_t debug_cdio_mmc_gpcmd; 00792 extern cdio_mmc_read_sub_state_t debug_cdio_mmc_read_sub_state; 00793 extern cdio_mmc_read_cd_type_t debug_cdio_mmc_read_cd_type; 00794 extern cdio_mmc_readtoc_t debug_cdio_mmc_readtoc; 00795 extern cdio_mmc_mode_page_t debug_cdio_mmc_mode_page; 00796 00797 #ifndef DO_NOT_WANT_OLD_MMC_COMPATIBILITY 00798 #define CDIO_MMC_GPCMD_START_STOP CDIO_MMC_GPCMD_START_STOP_UNIT 00799 #define CDIO_MMC_GPCMD_ALLOW_MEDIUM_REMOVAL \ 00800 CDIO_MMC_GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL 00801 #endif /*DO_NOT_WANT_PARANOIA_COMPATIBILITY*/ 00802 00803 #endif /* __MMC_H__ */ 00804 00805 /* 00806 * Local variables: 00807 * c-file-style: "ruby" 00808 * tab-width: 8 00809 * indent-tabs-mode: nil 00810 * End: 00811 */