2019-10-19 17:18:58 +01:00
|
|
|
/*
|
|
|
|
|
* This file is part of the DiscImageChef Remote Server.
|
|
|
|
|
* Copyright (c) 2019 Natalia Portillo.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-10-26 16:11:19 +01:00
|
|
|
#include "linux.h"
|
|
|
|
|
#include "mmc/ioctl.h"
|
2019-10-20 17:11:12 +01:00
|
|
|
|
2019-10-19 17:18:58 +01:00
|
|
|
#include <errno.h>
|
2019-10-26 16:11:19 +01:00
|
|
|
#include <stdint.h>
|
2019-10-19 17:18:58 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
2019-10-26 16:11:19 +01:00
|
|
|
int32_t LinuxSendSdhciCommand(void* device_ctx,
|
2019-10-19 18:30:45 +01:00
|
|
|
uint8_t command,
|
|
|
|
|
uint8_t write,
|
|
|
|
|
uint8_t application,
|
|
|
|
|
uint32_t flags,
|
|
|
|
|
uint32_t argument,
|
|
|
|
|
uint32_t block_size,
|
|
|
|
|
uint32_t blocks,
|
|
|
|
|
char* buffer,
|
|
|
|
|
uint32_t timeout,
|
|
|
|
|
uint32_t* response,
|
|
|
|
|
uint32_t* duration,
|
|
|
|
|
uint32_t* sense)
|
2019-10-19 17:18:58 +01:00
|
|
|
{
|
2019-10-26 16:11:19 +01:00
|
|
|
LinuxDeviceContext* ctx = device_ctx;
|
|
|
|
|
struct mmc_ioc_cmd mmc_ioc_cmd;
|
|
|
|
|
int32_t error;
|
2019-10-19 17:18:58 +01:00
|
|
|
*duration = 0;
|
|
|
|
|
*sense = 0;
|
|
|
|
|
|
2019-10-26 16:11:19 +01:00
|
|
|
if(!ctx) return -1;
|
|
|
|
|
|
2019-10-19 17:18:58 +01:00
|
|
|
memset(response, 0, sizeof(uint32_t) * 4);
|
|
|
|
|
memset(&mmc_ioc_cmd, 0, sizeof(struct mmc_ioc_cmd));
|
|
|
|
|
|
|
|
|
|
mmc_ioc_cmd.write_flag = write;
|
|
|
|
|
mmc_ioc_cmd.is_acmd = application;
|
|
|
|
|
mmc_ioc_cmd.opcode = command;
|
|
|
|
|
mmc_ioc_cmd.arg = argument;
|
|
|
|
|
mmc_ioc_cmd.flags = flags;
|
|
|
|
|
mmc_ioc_cmd.blksz = block_size;
|
|
|
|
|
mmc_ioc_cmd.blocks = blocks;
|
|
|
|
|
if(timeout > 0)
|
|
|
|
|
{
|
|
|
|
|
mmc_ioc_cmd.data_timeout_ns = timeout * 1000000000;
|
|
|
|
|
mmc_ioc_cmd.cmd_timeout_ms = timeout * 1000;
|
|
|
|
|
}
|
|
|
|
|
mmc_ioc_cmd.data_ptr = (uint64_t)buffer;
|
|
|
|
|
|
|
|
|
|
// TODO: Timing
|
2019-10-26 16:11:19 +01:00
|
|
|
error = ioctl(ctx->fd, MMC_IOC_CMD, &mmc_ioc_cmd);
|
2019-10-19 17:18:58 +01:00
|
|
|
|
|
|
|
|
if(error < 0) error = errno;
|
|
|
|
|
|
|
|
|
|
*sense = error < 0;
|
|
|
|
|
|
|
|
|
|
memcpy((char*)response, (char*)&mmc_ioc_cmd.response, sizeof(uint32_t) * 4);
|
|
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
}
|