static const char* asimcard_io_get_response( ASimCard sim, int id, int p1, int p2, int p3 ) { int count; char* out = sim->out_buff; SimFile ef = asimcard_ef_find(sim, id); if (ef == NULL) { return SIM_RESPONSE_FILE_NOT_FOUND; } if (p1 != 0 || p2 != 0 || p3 != 15) { return SIM_RESPONSE_INCORRECT_PARAMETERS; } sprintf(out, "%s,", SIM_RESPONSE_NORMAL_ENDING); out += strlen(out); count = sim_file_to_hex(ef, out); if (count < 0) { return SIM_RESPONSE_EXECUTION_ERROR; } out[count] = 0; return sim->out_buff; }
static const char* asimcard_io_update_record( ASimCard sim, int id, int p1, int p2, int p3, char* data ) { char* out = sim->out_buff; SimFile ef = asimcard_ef_find(sim, id); if (ef == NULL) { return SIM_RESPONSE_FILE_NOT_FOUND; } // We only support ABSOLUTE_MODE if (p2 != SIM_FILE_RECORD_ABSOLUTE_MODE || p1 <= 0) { return SIM_RESPONSE_INCORRECT_PARAMETERS; } if (ef->any.flags & SIM_FILE_READ_ONLY) { return SIM_RESPONSE_CONDITION_NOT_SATISFIED; } if (ef->linear.rec_len < p3) { return SIM_RESPONSE_WRONG_LENGTH; } if (ef->linear.rec_count < p1) { return SIM_RESPONSE_RECORD_NOT_FOUND; } if (asimcard_ef_update_linear(ef, p1, data) < 0) { return SIM_RESPONSE_EXECUTION_ERROR; } return SIM_RESPONSE_NORMAL_ENDING; }
static const char* asimcard_io_read_binary( ASimCard sim, int id, int p1, int p2, int p3 ) { char* out = sim->out_buff; SimFile ef = asimcard_ef_find(sim, id); if (ef == NULL) { return SIM_RESPONSE_FILE_NOT_FOUND; } if (p1 != 0 || p2 != 0) { return SIM_RESPONSE_INCORRECT_PARAMETERS; } if (ef->any.type != SIM_FILE_EF_DEDICATED) { return SIM_RESPONSE_FUNCTION_NOT_SUPPORT; } if (ef->dedicated.length < p3) { return SIM_RESPONSE_WRONG_LENGTH; } sprintf(out, "%s,", SIM_RESPONSE_NORMAL_ENDING); out += strlen(out); if (asimcard_ef_read_dedicated(ef, out) < 0) { return SIM_RESPONSE_EXECUTION_ERROR; } return sim->out_buff; }
static const char* asimcard_io_read_record( ASimCard sim, int id, int p1, int p2, int p3 ) { char* out = sim->out_buff; SimFile ef = asimcard_ef_find(sim, id); if (ef == NULL) { return SIM_RESPONSE_FILE_NOT_FOUND; } // We only support ABSOLUTE_MODE if (p2 != SIM_FILE_RECORD_ABSOLUTE_MODE || p1 <= 0) { return SIM_RESPONSE_INCORRECT_PARAMETERS; } if (ef->any.type != SIM_FILE_EF_LINEAR) { return SIM_RESPONSE_FUNCTION_NOT_SUPPORT; } if (ef->linear.rec_count < p1) { return SIM_RESPONSE_RECORD_NOT_FOUND; } if (ef->linear.rec_len < p3) { return SIM_RESPONSE_WRONG_LENGTH; } sprintf(out, "%s,", SIM_RESPONSE_NORMAL_ENDING); out += strlen(out); if (asimcard_ef_read_linear(ef, p1, out) < 0) { return SIM_RESPONSE_EXECUTION_ERROR; } return sim->out_buff; }
const char* asimcard_io( ASimCard sim, const char* cmd ) { int command, id, p1, p2, p3; char data[128] = {'\0'}; SimFile ef; assert( memcmp( cmd, "+CRSM=", 6 ) == 0 ); if ( sscanf(cmd, "+CRSM=%d,%d,%d,%d,%d,%s", &command, &id, &p1, &p2, &p3, data) >= 5 ) { switch (command) { case A_SIM_CMD_GET_RESPONSE: return asimcard_io_get_response(sim, id, p1, p2, p3); case A_SIM_CMD_READ_BINARY: return asimcard_io_read_binary(sim, id, p1, p2, p3); case A_SIM_CMD_READ_RECORD: return asimcard_io_read_record(sim, id, p1, p2, p3); case A_SIM_CMD_UPDATE_RECORD: return asimcard_io_update_record(sim, id, p1, p2, p3, data); case A_SIM_CMD_UPDATE_BINARY: ef = asimcard_ef_find(sim, id); return asimcard_ef_update_dedicated(ef, data); default: return SIM_RESPONSE_FUNCTION_NOT_SUPPORT; } } return SIM_RESPONSE_INCORRECT_PARAMETERS; }