static BDID_DATA *_bdid_parse(BD_FILE_H *fp) { BITSTREAM bs; BDID_DATA *bdid = NULL; uint32_t data_start, extension_data_start; uint8_t tmp[16]; if (bs_init(&bs, fp) < 0) { BD_DEBUG(DBG_NAV, "id.bdmv: read error\n"); return NULL; } if (!_parse_header(&bs, &data_start, &extension_data_start)) { BD_DEBUG(DBG_NAV | DBG_CRIT, "id.bdmv: invalid header\n"); return NULL; } if (bs_seek_byte(&bs, 40) < 0) { BD_DEBUG(DBG_NAV, "id.bdmv: read error\n"); return NULL; } bdid = calloc(1, sizeof(BDID_DATA)); if (!bdid) { BD_DEBUG(DBG_CRIT, "out of memory\n"); return NULL; } bs_read_bytes(&bs, tmp, 4); str_print_hex(bdid->org_id, tmp, 4); bs_read_bytes(&bs, tmp, 16); str_print_hex(bdid->disc_id, tmp, 16); if (extension_data_start) { BD_DEBUG(DBG_NAV | DBG_CRIT, "id.bdmv: ignoring unknown extension data\n"); } return bdid; }
int device_send_cmd(MMCDEV *mmc, const uint8_t *cmd, uint8_t *buf, size_t tx, size_t rx) { SCSITaskInterface **task = NULL; SCSI_Sense_Data sense; SCSITaskStatus status; SCSITaskSGElement iov; UInt8 direction; UInt64 sent; int rc; if (NULL == mmc->taskInterface) { return 0; } do { task = (*mmc->taskInterface)->CreateSCSITask (mmc->taskInterface); if (NULL == task) { BD_DEBUG(DBG_MMC, "Could not create SCSI Task\n"); break; } iov.address = (uintptr_t) buf; iov.length = tx ? tx : rx; if (buf) { direction = tx ? kSCSIDataTransfer_FromInitiatorToTarget : kSCSIDataTransfer_FromTargetToInitiator; } else { direction = kSCSIDataTransfer_NoDataTransfer; } rc = (*task)->SetCommandDescriptorBlock (task, cmd, 16); if (kIOReturnSuccess != rc) { BD_DEBUG(DBG_MMC, "Error setting SCSI command\n"); break; } rc = (*task)->SetScatterGatherEntries (task, &iov, 1, iov.length, direction); if (kIOReturnSuccess != rc) { BD_DEBUG(DBG_MMC, "Error setting SCSI scatter gather entries\n"); break; } rc = (*task)->SetTimeoutDuration (task, 5000000); if (kIOReturnSuccess != rc) { BD_DEBUG(DBG_MMC, "Error setting SCSI command timeout\n"); break; } memset (&sense, 0, sizeof (sense)); rc = (*task)->ExecuteTaskSync (task, &sense, &status, &sent); char str[512]; BD_DEBUG(DBG_MMC, "Send SCSI MMC cmd %s:\n", str_print_hex(str, cmd, 16)); if (tx) { BD_DEBUG(DBG_MMC, " Buffer: %s ->\n", str_print_hex(str, buf, tx>255?255:tx)); } else { BD_DEBUG(DBG_MMC, " Buffer: %s <-\n", str_print_hex(str, buf, rx>255?255:rx)); } if (kIOReturnSuccess != rc || status != 0) { BD_DEBUG(DBG_MMC, " Send failed!\n"); break; } else { BD_DEBUG(DBG_MMC, " Send succeeded! sent = %lld status = %u. response = %x\n", (unsigned long long) sent, status, sense.VALID_RESPONSE_CODE); } (*task)->Release (task); return 1; } while (0); if (task) { (*task)->Release (task); } return 0; }