00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #ifndef __CDIO_MMC_H__
00029 #define __CDIO_MMC_H__
00030
00031 #include <cdio/cdio.h>
00032 #include <cdio/types.h>
00033 #include <cdio/dvd.h>
00034 #include <cdio/audio.h>
00035
00036 #ifdef __cplusplus
00037 extern "C" {
00038 #endif
00039
00042 extern uint32_t mmc_timeout_ms;
00043
00045 #define MMC_TIMEOUT_DEFAULT 6000
00046
00049 extern uint32_t mmc_read_timeout_ms;
00050
00052 #define MMC_READ_TIMEOUT_DEFAULT 3*60*1000
00053
00054
00065 typedef enum {
00066 CDIO_MMC_GPCMD_INQUIRY = 0x12,
00068 CDIO_MMC_GPCMD_MODE_SELECT_6 = 0x15,
00070 CDIO_MMC_GPCMD_MODE_SENSE_6 = 0x1a,
00075 CDIO_MMC_GPCMD_START_STOP = 0x1b,
00077 CDIO_MMC_GPCMD_ALLOW_MEDIUM_REMOVAL = 0x1e,
00082 CDIO_MMC_GPCMD_READ_10 = 0x28,
00084 CDIO_MMC_GPCMD_READ_SUBCHANNEL = 0x42,
00086 CDIO_MMC_GPCMD_READ_TOC = 0x43,
00088 CDIO_MMC_GPCMD_READ_HEADER = 0x44,
00089 CDIO_MMC_GPCMD_PLAY_AUDIO_10 = 0x45,
00092 CDIO_MMC_GPCMD_GET_CONFIGURATION = 0x46,
00094 CDIO_MMC_GPCMD_PLAY_AUDIO_MSF = 0x47,
00097 CDIO_MMC_GPCMD_PLAY_AUDIO_TI = 0x48,
00098 CDIO_MMC_GPCMD_PLAY_TRACK_REL_10 = 0x49,
00105 CDIO_MMC_GPCMD_GET_EVENT_STATUS = 0x4a,
00107 CDIO_MMC_GPCMD_PAUSE_RESUME = 0x4b,
00111 CDIO_MMC_GPCMD_READ_DISC_INFO = 0x51,
00113 CDIO_MMC_GPCMD_MODE_SELECT_10 = 0x55,
00115 CDIO_MMC_GPCMD_MODE_SENSE_10 = 0x5a,
00123 CDIO_MMC_GPCMD_PLAY_AUDIO_12 = 0xa5,
00126 CDIO_MMC_GPCMD_LOAD_UNLOAD = 0xa6,
00128 CDIO_MMC_GPCMD_READ_12 = 0xa8,
00130 CDIO_MMC_GPCMD_PLAY_TRACK_REL_12 = 0xa9,
00136 CDIO_MMC_GPCMD_READ_DVD_STRUCTURE = 0xad,
00138 CDIO_MMC_GPCMD_READ_MSF = 0xb9,
00141 CDIO_MMC_GPCMD_SET_SPEED = 0xbb,
00151 CDIO_MMC_GPCMD_READ_CD = 0xbe,
00156 CDIO_MMC_GPCMD_CD_PLAYBACK_STATUS = 0xc4 ,
00157 CDIO_MMC_GPCMD_PLAYBACK_CONTROL = 0xc9 ,
00158 CDIO_MMC_GPCMD_READ_CDDA = 0xd8 ,
00159 CDIO_MMC_GPCMD_READ_CDXA = 0xdb ,
00160 CDIO_MMC_GPCMD_READ_ALL_SUBCODES = 0xdf
00161 } cdio_mmc_gpcmd_t;
00162
00163
00165 typedef enum {
00166 CDIO_MMC_READ_SUB_ST_INVALID = 0x00,
00167 CDIO_MMC_READ_SUB_ST_PLAY = 0x11,
00169 CDIO_MMC_READ_SUB_ST_PAUSED = 0x12,
00170 CDIO_MMC_READ_SUB_ST_COMPLETED = 0x13,
00172 CDIO_MMC_READ_SUB_ST_ERROR = 0x14,
00174 CDIO_MMC_READ_SUB_ST_NO_STATUS = 0x15,
00176 } cdio_mmc_read_sub_state_t;
00177
00179 typedef enum {
00180 CDIO_MMC_READ_TYPE_ANY = 0,
00181 CDIO_MMC_READ_TYPE_CDDA = 1,
00182 CDIO_MMC_READ_TYPE_MODE1 = 2,
00183 CDIO_MMC_READ_TYPE_MODE2 = 3,
00184 CDIO_MMC_READ_TYPE_M2F1 = 4,
00185 CDIO_MMC_READ_TYPE_M2F2 = 5
00186 } cdio_mmc_read_cd_type_t;
00187
00189 typedef enum {
00190 CDIO_MMC_READTOC_FMT_TOC = 0,
00191 CDIO_MMC_READTOC_FMT_SESSION = 1,
00192 CDIO_MMC_READTOC_FMT_FULTOC = 2,
00193 CDIO_MMC_READTOC_FMT_PMA = 3,
00194 CDIO_MMC_READTOC_FMT_ATIP = 4,
00195 CDIO_MMC_READTOC_FMT_CDTEXT = 5
00196 } cdio_mmc_readtoc_t;
00197
00199 typedef enum {
00200 CDIO_MMC_R_W_ERROR_PAGE = 0x01,
00201 CDIO_MMC_WRITE_PARMS_PAGE = 0x05,
00202 CDIO_MMC_CDR_PARMS_PAGE = 0x0d,
00203 CDIO_MMC_AUDIO_CTL_PAGE = 0x0e,
00204 CDIO_MMC_POWER_PAGE = 0x1a,
00205 CDIO_MMC_FAULT_FAIL_PAGE = 0x1c,
00206 CDIO_MMC_TO_PROTECT_PAGE = 0x1d,
00207 CDIO_MMC_CAPABILITIES_PAGE = 0x2a,
00208 CDIO_MMC_ALL_PAGES = 0x3f,
00209 } cdio_mmc_mode_page_t;
00210
00211
00212 PRAGMA_BEGIN_PACKED
00213 struct mmc_audio_volume_entry_s
00214 {
00215 uint8_t selection;
00216 uint8_t volume;
00217 } GNUC_PACKED;
00218
00219 typedef struct mmc_audio_volume_entry_s mmc_audio_volume_entry_t;
00220
00222 struct mmc_audio_volume_s
00223 {
00224 mmc_audio_volume_entry_t port[4];
00225 } GNUC_PACKED;
00226
00227 typedef struct mmc_audio_volume_s mmc_audio_volume_t;
00228
00229 PRAGMA_END_PACKED
00230
00231
00233 typedef enum {
00234 CDIO_MMC_GET_CONF_ALL_FEATURES = 0,
00236 CDIO_MMC_GET_CONF_CURRENT_FEATURES = 1,
00239 CDIO_MMC_GET_CONF_NAMED_FEATURE = 2
00241 } cdio_mmc_get_conf_t;
00242
00243
00246 typedef enum {
00247 CDIO_MMC_FEATURE_PROFILE_LIST = 0x000,
00248 CDIO_MMC_FEATURE_CORE = 0x001,
00249 CDIO_MMC_FEATURE_MORPHING = 0x002,
00251 CDIO_MMC_FEATURE_REMOVABLE_MEDIUM = 0x003,
00252 CDIO_MMC_FEATURE_WRITE_PROTECT = 0x004,
00253 CDIO_MMC_FEATURE_RANDOM_READABLE = 0x010,
00254 CDIO_MMC_FEATURE_MULTI_READ = 0x01D,
00255 CDIO_MMC_FEATURE_CD_READ = 0x01E,
00256 CDIO_MMC_FEATURE_DVD_READ = 0x01F,
00257 CDIO_MMC_FEATURE_RANDOM_WRITABLE = 0x020,
00258 CDIO_MMC_FEATURE_INCR_WRITE = 0x021,
00260 CDIO_MMC_FEATURE_SECTOR_ERASE = 0x022,
00261 CDIO_MMC_FEATURE_FORMATABLE = 0x023,
00262 CDIO_MMC_FEATURE_DEFECT_MGMT = 0x024,
00266 CDIO_MMC_FEATURE_WRITE_ONCE = 0x025,
00268 CDIO_MMC_FEATURE_RESTRICT_OVERW = 0x026,
00270 CDIO_MMC_FEATURE_CD_RW_CAV = 0x027,
00271 CDIO_MMC_FEATURE_MRW = 0x028,
00272 CDIO_MMC_FEATURE_ENHANCED_DEFECT = 0x029,
00273 CDIO_MMC_FEATURE_DVD_PRW = 0x02A,
00274 CDIO_MMC_FEATURE_DVD_PR = 0x02B,
00275 CDIO_MMC_FEATURE_RIGID_RES_OVERW = 0x02C,
00276 CDIO_MMC_FEATURE_CD_TAO = 0x02D,
00277 CDIO_MMC_FEATURE_CD_SAO = 0x02E,
00279 CDIO_MMC_FEATURE_DVD_R_RW_WRITE = 0x02F,
00280 CDIO_MMC_FEATURE_CD_RW_MEDIA_WRITE= 0x037,
00281 CDIO_MMC_FEATURE_DVD_PR_2_LAYER = 0x03B,
00282 CDIO_MMC_FEATURE_POWER_MGMT = 0x100,
00284 CDIO_MMC_FEATURE_CDDA_EXT_PLAY = 0x103,
00287 CDIO_MMC_FEATURE_MCODE_UPGRADE = 0x104,
00288
00289
00290 CDIO_MMC_FEATURE_TIME_OUT = 0x105,
00293 CDIO_MMC_FEATURE_DVD_CSS = 0x106,
00296 CDIO_MMC_FEATURE_RT_STREAMING = 0x107,
00299 CDIO_MMC_FEATURE_LU_SN = 0x108,
00301 CDIO_MMC_FEATURE_FIRMWARE_DATE = 0x1FF,
00303 } cdio_mmc_feature_t;
00304
00306 typedef enum {
00307 CDIO_MMC_FEATURE_PROF_NON_REMOVABLE = 0x0001,
00309 CDIO_MMC_FEATURE_PROF_REMOVABLE = 0x0002,
00311 CDIO_MMC_FEATURE_PROF_MO_ERASABLE = 0x0003,
00314 CDIO_MMC_FEATURE_PROF_MO_WRITE_ONCE = 0x0004,
00316 CDIO_MMC_FEATURE_PROF_AS_MO = 0x0005,
00318 CDIO_MMC_FEATURE_PROF_CD_ROM = 0x0008,
00320 CDIO_MMC_FEATURE_PROF_CD_R = 0x0009,
00322 CDIO_MMC_FEATURE_PROF_CD_RW = 0x000A,
00324 CDIO_MMC_FEATURE_PROF_DVD_ROM = 0x0010,
00325 CDIO_MMC_FEATURE_PROF_DVD_R_SEQ = 0x0011,
00327 CDIO_MMC_FEATURE_PROF_DVD_RAM = 0x0012,
00328 CDIO_MMC_FEATURE_PROF_DVD_RW_RO = 0x0013,
00330 CDIO_MMC_FEATURE_PROF_DVD_RW_SEQ = 0x0014,
00332 CDIO_MMC_FEATURE_PROF_DVD_PRW = 0x001A,
00333 CDIO_MMC_FEATURE_PROF_DVD_PR = 0x001B,
00334 CDIO_MMC_FEATURE_PROF_DDCD_ROM = 0x0020,
00335 CDIO_MMC_FEATURE_PROF_DDCD_R = 0x0021,
00336 CDIO_MMC_FEATURE_PROF_DDCD_RW = 0x0022,
00337 CDIO_MMC_FEATURE_PROF_DVD_PR2 = 0x002B,
00339 CDIO_MMC_FEATURE_PROF_NON_CONFORM = 0xFFFF,
00341 } cdio_mmc_feature_profile_t;
00342
00343 typedef enum {
00344 CDIO_MMC_FEATURE_INTERFACE_UNSPECIFIED = 0,
00345 CDIO_MMC_FEATURE_INTERFACE_SCSI = 1,
00346 CDIO_MMC_FEATURE_INTERFACE_ATAPI = 2,
00347 CDIO_MMC_FEATURE_INTERFACE_IEEE_1394 = 3,
00348 CDIO_MMC_FEATURE_INTERFACE_IEEE_1394A = 4,
00349 CDIO_MMC_FEATURE_INTERFACE_FIBRE_CH = 5
00350 } cdio_mmc_feature_interface_t;
00351
00352
00356 #define MAX_CDB_LEN 12
00357
00361 typedef struct mmc_cdb_s {
00362 uint8_t field[MAX_CDB_LEN];
00363 } mmc_cdb_t;
00364
00368 typedef struct mmc_feature_list_header_s {
00369 unsigned char length_msb;
00370 unsigned char length_1sb;
00371 unsigned char length_2sb;
00372 unsigned char length_lsb;
00373 unsigned char reserved1;
00374 unsigned char reserved2;
00375 unsigned char profile_msb;
00376 unsigned char profile_lsb;
00377 } cdio_mmc_feature_list_header_t;
00378
00382 typedef enum mmc_direction_s {
00383 SCSI_MMC_DATA_READ,
00384 SCSI_MMC_DATA_WRITE
00385 } cdio_mmc_direction_t;
00386
00387 typedef struct mmc_subchannel_s
00388 {
00389 uint8_t reserved;
00390 uint8_t audio_status;
00391 uint16_t data_length;
00392 uint8_t format;
00393 uint8_t address: 4;
00394 uint8_t control: 4;
00395 uint8_t track;
00396 uint8_t index;
00397 uint8_t abs_addr[4];
00398 uint8_t rel_addr[4];
00399 } cdio_mmc_subchannel_t;
00400
00401 #define CDIO_MMC_SET_COMMAND(cdb, command) \
00402 cdb[0] = command
00403
00404 #define CDIO_MMC_SET_READ_TYPE(cdb, sector_type) \
00405 cdb[1] = (sector_type << 2)
00406
00407 #define CDIO_MMC_GETPOS_LEN16(p, pos) \
00408 (p[pos]<<8) + p[pos+1]
00409
00410 #define CDIO_MMC_GET_LEN16(p) \
00411 (p[0]<<8) + p[1]
00412
00413 #define CDIO_MMC_GET_LEN32(p) \
00414 (p[0] << 24) + (p[1] << 16) + (p[2] << 8) + p[3];
00415
00416 #define CDIO_MMC_SET_LEN16(cdb, pos, len) \
00417 cdb[pos ] = (len >> 8) & 0xff; \
00418 cdb[pos+1] = (len ) & 0xff
00419
00420 #define CDIO_MMC_SET_READ_LBA(cdb, lba) \
00421 cdb[2] = (lba >> 24) & 0xff; \
00422 cdb[3] = (lba >> 16) & 0xff; \
00423 cdb[4] = (lba >> 8) & 0xff; \
00424 cdb[5] = (lba ) & 0xff
00425
00426 #define CDIO_MMC_SET_START_TRACK(cdb, command) \
00427 cdb[6] = command
00428
00429 #define CDIO_MMC_SET_READ_LENGTH24(cdb, len) \
00430 cdb[6] = (len >> 16) & 0xff; \
00431 cdb[7] = (len >> 8) & 0xff; \
00432 cdb[8] = (len ) & 0xff
00433
00434 #define CDIO_MMC_SET_READ_LENGTH16(cdb, len) \
00435 CDIO_MMC_SET_LEN16(cdb, 7, len)
00436
00437 #define CDIO_MMC_SET_READ_LENGTH8(cdb, len) \
00438 cdb[8] = (len ) & 0xff
00439
00440 #define CDIO_MMC_MCSB_ALL_HEADERS 0xf
00441
00442 #define CDIO_MMC_SET_MAIN_CHANNEL_SELECTION_BITS(cdb, val) \
00443 cdb[9] = val << 3;
00444
00451 driver_return_code_t
00452 mmc_audio_read_subchannel (CdIo_t *p_cdio,
00453 cdio_subchannel_t *p_subchannel);
00454
00459 const char *mmc_audio_state2str( uint8_t i_audio_state );
00460
00466 driver_return_code_t mmc_eject_media( const CdIo_t *p_cdio );
00467
00471 const char *mmc_feature2str( int i_feature );
00472
00476 const char *mmc_feature_profile2str( int i_feature_profile );
00477
00483 uint8_t mmc_get_cmd_len(uint8_t mmc_cmd);
00484
00489 int mmc_get_blocksize ( CdIo_t *p_cdio );
00490
00494 driver_return_code_t mmc_close_tray( CdIo_t *p_cdio );
00495
00501 lsn_t mmc_get_disc_last_lsn( const CdIo_t *p_cdio );
00502
00512 discmode_t mmc_get_discmode( const CdIo_t *p_cdio );
00513
00514
00519 void mmc_get_drive_cap ( CdIo_t *p_cdio,
00520 cdio_drive_read_cap_t *p_read_cap,
00521 cdio_drive_write_cap_t *p_write_cap,
00522 cdio_drive_misc_cap_t *p_misc_cap);
00523
00524 typedef enum {
00525 CDIO_MMC_LEVEL_WEIRD,
00526 CDIO_MMC_LEVEL_1,
00527 CDIO_MMC_LEVEL_2,
00528 CDIO_MMC_LEVEL_3,
00529 CDIO_MMC_LEVEL_NONE
00530 } cdio_mmc_level_t;
00531
00535 cdio_mmc_level_t mmc_get_drive_mmc_cap(CdIo_t *p_cdio);
00536
00537
00543 discmode_t mmc_get_dvd_struct_physical ( const CdIo_t *p_cdio,
00544 cdio_dvd_struct_t *s);
00545
00553 int mmc_get_event_status(const CdIo_t *p_cdio, uint8_t out_buf[2]);
00554
00561 int mmc_get_tray_status ( const CdIo_t *p_cdio );
00562
00569 bool mmc_get_hwinfo ( const CdIo_t *p_cdio,
00570 cdio_hwinfo_t *p_hw_info );
00571
00572
00579 int mmc_get_media_changed(const CdIo_t *p_cdio);
00580
00591 char * mmc_get_mcn ( const CdIo_t *p_cdio );
00592
00597 driver_return_code_t mmc_audio_get_volume (CdIo_t *p_cdio,
00598 mmc_audio_volume_t *p_volume);
00599
00606 bool_3way_t mmc_have_interface( CdIo_t *p_cdio,
00607 cdio_mmc_feature_interface_t e_interface );
00608
00613 int mmc_mode_sense( CdIo_t *p_cdio, void *p_buf, int i_size,
00614 int page);
00615
00616
00621 int mmc_mode_sense_10( CdIo_t *p_cdio, void *p_buf, int i_size,
00622 int page);
00623
00628 int mmc_mode_sense_6( CdIo_t *p_cdio, void *p_buf, int i_size,
00629 int page);
00630
00731 driver_return_code_t
00732 mmc_read_cd ( const CdIo_t *p_cdio, void *p_buf, lsn_t i_lsn,
00733 int expected_sector_type, bool b_digital_audio_play,
00734 bool b_sync, uint8_t header_codes, bool b_user_data,
00735 bool b_edc_ecc, uint8_t c2_error_information,
00736 uint8_t subchannel_selection, uint16_t i_blocksize,
00737 uint32_t i_blocks );
00738
00757 driver_return_code_t mmc_read_data_sectors ( CdIo_t *p_cdio, void *p_buf,
00758 lsn_t i_lsn,
00759 uint16_t i_blocksize,
00760 uint32_t i_blocks );
00761
00765 driver_return_code_t mmc_read_sectors ( const CdIo_t *p_cdio, void *p_buf,
00766 lsn_t i_lsn, int read_sector_type,
00767 uint32_t i_blocks);
00768
00784 int mmc_run_cmd( const CdIo_t *p_cdio, unsigned int i_timeout_ms,
00785 const mmc_cdb_t *p_cdb,
00786 cdio_mmc_direction_t e_direction, unsigned int i_buf,
00787 void *p_buf );
00791 driver_return_code_t mmc_set_blocksize ( const CdIo_t *p_cdio,
00792 uint16_t i_blocksize);
00793
00811 driver_return_code_t mmc_set_drive_speed( const CdIo_t *p_cdio,
00812 int i_drive_speed );
00813
00835 driver_return_code_t mmc_set_speed( const CdIo_t *p_cdio,
00836 int i_Kbs_speed );
00837
00849 driver_return_code_t
00850 mmc_start_stop_media(const CdIo_t *p_cdio, bool b_eject, bool b_immediate,
00851 uint8_t power_condition);
00852
00853 #ifdef __cplusplus
00854 }
00855 #endif
00856
00862 extern cdio_mmc_feature_t debug_cdio_mmc_feature;
00863 extern cdio_mmc_feature_interface_t debug_cdio_mmc_feature_interface;
00864 extern cdio_mmc_feature_profile_t debug_cdio_mmc_feature_profile;
00865 extern cdio_mmc_get_conf_t debug_cdio_mmc_get_conf;
00866 extern cdio_mmc_gpcmd_t debug_cdio_mmc_gpcmd;
00867 extern cdio_mmc_read_sub_state_t debug_cdio_mmc_read_sub_state;
00868 extern cdio_mmc_read_cd_type_t debug_cdio_mmc_read_cd_type;
00869 extern cdio_mmc_readtoc_t debug_cdio_mmc_readtoc;
00870 extern cdio_mmc_mode_page_t debug_cdio_mmc_mode_page;
00871
00872 #endif
00873
00874
00875
00876
00877
00878
00879
00880