diff --git a/client/src/cmdfpga.c b/client/src/cmdfpga.c index e9b0bde6f..88531f1e0 100644 --- a/client/src/cmdfpga.c +++ b/client/src/cmdfpga.c @@ -90,7 +90,7 @@ static int CmdConfigFpga(const char *Cmd) { // Start to send data in chunks size_t offset = 0; while (offset < datalen) { - size_t chunk_size = (datalen - offset) > pm3_max_cmd_data_size() ? pm3_max_cmd_data_size() : (datalen - offset); + size_t chunk_size = (datalen - offset) > g_conn.max_cmd_data_size ? g_conn.max_cmd_data_size : (datalen - offset); SendCommandNG(CMD_FPGA_BITSTREAM_CONFIG_WRITE, data + offset, chunk_size); // Wait for response before sending next chunk if (WaitForResponseTimeout(CMD_FPGA_BITSTREAM_CONFIG_WRITE, &resp, 5000) == false) { diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index 710515d32..6159e846c 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -301,7 +301,7 @@ int hf14a_getversion_data(iso14a_card_select_t *card, uint64_t select_status, ve void SendIso14aReaderEx(uint32_t flags, const uint8_t *data, uint16_t datalen, uint16_t len, uint16_t lenbits, uint32_t timeout, uint32_t wait_us) { - if (datalen > (pm3_max_cmd_data_size() - sizeof(iso14a_raw_cmd_t))) { + if (datalen > (g_conn.max_cmd_data_size - sizeof(iso14a_raw_cmd_t))) { PrintAndLogEx(WARNING, "Sending " _RED_("%u") " bytes of payload is too much, abort", datalen); return; } @@ -1235,7 +1235,7 @@ int ExchangeRAW14a(uint8_t *datain, int datainlen, bool activateField, bool leav uint8_t data[PM3_CMD_DATA_SIZE] = { 0x0a | gs_frames_num, 0x00 }; gs_frames_num ^= 1; - int min = MIN((int)(pm3_max_cmd_data_size() - 2), (datainlen & 0x1FF)); + int min = MIN((int)(g_conn.max_cmd_data_size - 2), (datainlen & 0x1FF)); memcpy(&data[2], datain, min); SendIso14aReader(ISO14A_RAW | ISO14A_APPEND_CRC | cmdc, data, min + 2); @@ -1541,7 +1541,7 @@ int ExchangeAPDU14a(const uint8_t *datain, int datainlen, bool activateField, bo // 3 byte here - 1b framing header, 2b crc16 if (g_apdu_in_framing_enable && - ((gs_frame_len && (datainlen > gs_frame_len - 3)) || (datainlen > pm3_max_cmd_data_size() - 3))) { + ((gs_frame_len && (datainlen > gs_frame_len - 3)) || (datainlen > g_conn.max_cmd_data_size - 3))) { int clen = 0; diff --git a/client/src/cmdhf14b.c b/client/src/cmdhf14b.c index 189d32083..2f4432e6f 100644 --- a/client/src/cmdhf14b.c +++ b/client/src/cmdhf14b.c @@ -1269,7 +1269,7 @@ static int CmdHF14BRaw(const char *Cmd) { } // Max buffer is PM3_CMD_DATA_SIZE - datalen = (datalen > pm3_max_cmd_data_size()) ? pm3_max_cmd_data_size() : datalen; + datalen = (datalen > g_conn.max_cmd_data_size) ? g_conn.max_cmd_data_size : datalen; iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + datalen); if (packet == NULL) { @@ -2935,7 +2935,7 @@ int exchange_14b_apdu(uint8_t *datain, int datainlen, bool activate_field, // 3 byte here - 1b framing header, 2b crc16 if (apdu_in_framing_enable && - ((apdu_frame_length && (datainlen > apdu_frame_length - 3)) || (datainlen > pm3_max_cmd_data_size() - 3))) { + ((apdu_frame_length && (datainlen > apdu_frame_length - 3)) || (datainlen > g_conn.max_cmd_data_size - 3))) { int clen = 0; bool v_activate_field = activate_field; diff --git a/client/src/cmdhf15.c b/client/src/cmdhf15.c index e7e2f7dde..fa69da62e 100644 --- a/client/src/cmdhf15.c +++ b/client/src/cmdhf15.c @@ -1649,7 +1649,7 @@ static int hf15EmlSetMem(const uint8_t *data, uint16_t count, size_t offset) { uint8_t data[]; } PACKED; - if (count > (pm3_max_cmd_data_size() - sizeof(struct p))) { + if (count > (g_conn.max_cmd_data_size - sizeof(struct p))) { return PM3_ESOFT; } @@ -2575,11 +2575,11 @@ static int CmdHF15Raw(const char *Cmd) { bool wait = arg_get_lit(ctx, 7); CLIParserFree(ctx); - datalen = (datalen >= pm3_max_cmd_data_size()) ? pm3_max_cmd_data_size() : datalen; + datalen = (datalen >= g_conn.max_cmd_data_size) ? g_conn.max_cmd_data_size : datalen; if (crc) { - if ((datalen - 2) < pm3_max_cmd_data_size()) { + if ((datalen - 2) < g_conn.max_cmd_data_size) { AddCrc15(data, datalen); datalen += 2; } else { diff --git a/client/src/cmdhfepa.c b/client/src/cmdhfepa.c index 58dd930fe..2cd8092c2 100644 --- a/client/src/cmdhfepa.c +++ b/client/src/cmdhfepa.c @@ -162,7 +162,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { for (int i = 0; i < ARRAYLEN(apdu_lengths); i++) { // chunk size = what fits one frame to THIS device, minus the reply header - const int chunk = (int)(pm3_max_cmd_data_size() - sizeof(epa_replay_t)); + const int chunk = (int)(g_conn.max_cmd_data_size - sizeof(epa_replay_t)); // transfer the APDU in several parts if necessary for (int j = 0; j * chunk < apdu_lengths[i]; j++) { // amount of data in this packet diff --git a/client/src/cmdhffelica.c b/client/src/cmdhffelica.c index 982b1f8bc..19a4a3397 100644 --- a/client/src/cmdhffelica.c +++ b/client/src/cmdhffelica.c @@ -8252,7 +8252,7 @@ static int felica_sim_model_from_json(json_t *root, felica_sim_model_t *model_ou static int felica_sim_send_control(uint8_t subcommand, uint32_t total_len, uint32_t offset, uint16_t model_crc, const uint8_t *data, uint16_t data_len, uint32_t timeout_ms) { - if (data_len > (pm3_max_cmd_data_size() - sizeof(felica_sim_upload_t))) { + if (data_len > (g_conn.max_cmd_data_size - sizeof(felica_sim_upload_t))) { return PM3_EOVFLOW; } @@ -8287,7 +8287,7 @@ static int felica_sim_upload_model(const felica_sim_model_t *model) { return ret; } - const uint16_t chunk_size = pm3_max_cmd_data_size() - sizeof(felica_sim_upload_t); + const uint16_t chunk_size = g_conn.max_cmd_data_size - sizeof(felica_sim_upload_t); uint32_t offset = 0; PrintAndLogEx(INFO, "Uploading simulator model"); PrintAndLogEx(INFO, "." NOLF); @@ -9438,7 +9438,7 @@ static int CmdHFFelicaCmdRaw(const char *Cmd) { } // Max transport buffer is PM3_CMD_DATA_SIZE - datalen = (datalen > pm3_max_cmd_data_size()) ? pm3_max_cmd_data_size() : datalen; + datalen = (datalen > g_conn.max_cmd_data_size) ? g_conn.max_cmd_data_size : datalen; PrintAndLogEx(SUCCESS, "Data: %s", sprint_hex(data, datalen)); diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 0372722de..2166159f4 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -307,7 +307,7 @@ static void iclass_upload_emul(uint8_t *d, uint16_t n, uint16_t offset, uint16_t PrintAndLogEx(INFO, "." NOLF); while (bytes_remaining > 0) { - uint32_t bytes_in_packet = MIN((uint32_t)(pm3_max_cmd_data_size() - 4), bytes_remaining); + uint32_t bytes_in_packet = MIN((uint32_t)(g_conn.max_cmd_data_size - 4), bytes_remaining); if (bytes_in_packet == bytes_remaining) { // Disable fast mode on last packet g_conn.block_after_ACK = false; @@ -3565,8 +3565,8 @@ static int CmdHFiClassRestore(const char *Cmd) { uint32_t payload_size = sizeof(iclass_restore_req_t) + (sizeof(iclass_restore_item_t) * (endblock - startblock + 1)); - if (payload_size > pm3_max_cmd_data_size()) { - PrintAndLogEx(NORMAL, "Trying to write too many blocks at once. Max: %d", pm3_max_cmd_data_size() / 8); + if (payload_size > g_conn.max_cmd_data_size) { + PrintAndLogEx(NORMAL, "Trying to write too many blocks at once. Max: %d", g_conn.max_cmd_data_size / 8); return PM3_EINVARG; } @@ -6065,8 +6065,8 @@ static int CmdHFiClassCheckKeys(const char *Cmd) { // USB_COMMAND. 512/4 = 103 mac uint32_t max_chunk_size = 0; - if (keycount > ((pm3_max_cmd_data_size() - sizeof(iclass_chk_t)) / 4)) - max_chunk_size = (pm3_max_cmd_data_size() - sizeof(iclass_chk_t)) / 4; + if (keycount > ((g_conn.max_cmd_data_size - sizeof(iclass_chk_t)) / 4)) + max_chunk_size = (g_conn.max_cmd_data_size - sizeof(iclass_chk_t)) / 4; else max_chunk_size = keycount; @@ -8070,7 +8070,7 @@ static int CmdHFiClassSAMExtract(const char *Cmd) { data[0] = flags; int cmdlen = 0; - if (CLIParamHexToBuf(arg_get_str(ctx, 8), data + 1, pm3_max_cmd_data_size() - 1, &cmdlen) != PM3_SUCCESS) { + if (CLIParamHexToBuf(arg_get_str(ctx, 8), data + 1, g_conn.max_cmd_data_size - 1, &cmdlen) != PM3_SUCCESS) { CLIParserFree(ctx); return PM3_ESOFT; } diff --git a/client/src/cmdhfjooki.c b/client/src/cmdhfjooki.c index 142d84a66..1956c606f 100644 --- a/client/src/cmdhfjooki.c +++ b/client/src/cmdhfjooki.c @@ -547,7 +547,7 @@ static int CmdHF14AJookiSim(const char *Cmd) { uint8_t blockno = 0; // 12 is the size of the struct the fct mf_eml_set_mem_xt uses to transfer to device - uint16_t max_avail_blocks = ((pm3_max_cmd_data_size() - 12) / blockwidth); + uint16_t max_avail_blocks = ((g_conn.max_cmd_data_size - 12) / blockwidth); while (datalen) { if (datalen == blockwidth) { diff --git a/client/src/cmdhflegic.c b/client/src/cmdhflegic.c index e64796176..5f1780086 100644 --- a/client/src/cmdhflegic.c +++ b/client/src/cmdhflegic.c @@ -35,7 +35,7 @@ static int CmdHelp(const char *Cmd); #define LEGIC_PRIME_MIM256 256 #define LEGIC_PRIME_MIM1024 1024 #define LEGIC_BLOCK_SIZE 8 -#define LEGIC_PACKET_SIZE (pm3_max_cmd_data_size() - sizeof(legic_packet_t)) +#define LEGIC_PACKET_SIZE (g_conn.max_cmd_data_size - sizeof(legic_packet_t)) static bool legic_xor(uint8_t *data, uint16_t cardsize) { diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index cd6ebccf7..b21277e6f 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -3395,7 +3395,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { res = mf_check_keys_fast(sector_cnt, true, true, 1, key_cnt, keyBlock, e_sector, use_flashmemory, verbose); } else { - uint32_t maxkeys = (pm3_max_cmd_data_size() - sizeof(mf_chkkeys_fast_t)) / 6; + uint32_t maxkeys = (g_conn.max_cmd_data_size - sizeof(mf_chkkeys_fast_t)) / 6; if (maxkeys > 255) { maxkeys = 255; } @@ -4049,7 +4049,7 @@ static int CmdHF14AMfChk_fast(const char *Cmd) { return PM3_EMALLOC; } - uint32_t maxkeys = (pm3_max_cmd_data_size() - sizeof(mf_chkkeys_fast_t)) / 6; + uint32_t maxkeys = (g_conn.max_cmd_data_size - sizeof(mf_chkkeys_fast_t)) / 6; if (maxkeys > 255) { maxkeys = 255; } @@ -5437,7 +5437,7 @@ int CmdHF14AMfELoad(const char *Cmd) { int cnt = 0; // 12 is the size of the struct the fct mf_eml_set_mem_xt uses to transfer to device - uint16_t max_avail_blocks = ((pm3_max_cmd_data_size() - 12) / block_width) * block_width; + uint16_t max_avail_blocks = ((g_conn.max_cmd_data_size - 12) / block_width) * block_width; while (bytes_read && cnt < block_cnt) { if (bytes_read == block_width) { @@ -9412,7 +9412,7 @@ static int CmdHF14AGen4Save(const char *Cmd) { uint16_t bytes_left = bytes ; // 12 is the size of the struct the fct mf_eml_set_mem_xt uses to transfer to device - uint16_t max_avail_blocks = ((pm3_max_cmd_data_size() - 12) / MFBLOCK_SIZE) * MFBLOCK_SIZE; + uint16_t max_avail_blocks = ((g_conn.max_cmd_data_size - 12) / MFBLOCK_SIZE) * MFBLOCK_SIZE; while (bytes_left > 0 && cnt < block_cnt) { if (bytes_left == MFBLOCK_SIZE) { diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 2c8d78213..0ff39cef9 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -4445,7 +4445,7 @@ static int mfu_3pass_check_keys(uint8_t key_index, uint8_t firstChunk, uint8_t l } PACKED; uint8_t keysize = segment != -1 ? MIFAREU3P_KEY_SIZE / 4 : MIFAREU3P_KEY_SIZE; memcpy(payload.ref_key, ref_key, MIFAREU3P_KEY_SIZE); - if (nkeys * keysize > (uint32_t)(pm3_max_cmd_data_size() - MIFAREU3P_CHKKEY_HEADER)) { + if (nkeys * keysize > (uint32_t)(g_conn.max_cmd_data_size - MIFAREU3P_CHKKEY_HEADER)) { PrintAndLogEx(ERR, "Key chunk size exceeds payload size"); return PM3_ESOFT; } @@ -4687,7 +4687,7 @@ static int CmdHF14AMfUCAuth(const char *Cmd) { uint16_t max_retries_per_call = retries; if (collect_nonces) { // Not strictly needed, but to avoid fw warning - max_retries_per_call = ((pm3_max_cmd_data_size() - sizeof(uint32_t) * 2) / sizeof(uint64_t)) - 1; + max_retries_per_call = ((g_conn.max_cmd_data_size - sizeof(uint32_t) * 2) / sizeof(uint64_t)) - 1; } isok = ul3pass_authentication(auth_key_ptr, MIFAREULC_KEY_INDEX, !keep_field_on, MIN(retries - auths, max_retries_per_call), &auths, &ms, false, !skip_auth, check_answer, use_fastread0, collect_nonces, (uint8_t *)(nonces + auths), reset_field, available_pairs, pairs); } while (skip_auth && auths < 1 + retries); @@ -4783,7 +4783,7 @@ static int CmdHF14AMfUCAuthChk(const char *Cmd) { } // cap by what fits in one frame, then by what the nkeys field can announce - uint32_t max_chunk = (pm3_max_cmd_data_size() - MIFAREU3P_CHKKEY_HEADER) / keysize; + uint32_t max_chunk = (g_conn.max_cmd_data_size - MIFAREU3P_CHKKEY_HEADER) / keysize; if (max_chunk > MIFAREU3P_CHKKEY_MAX_KEYS) { max_chunk = MIFAREU3P_CHKKEY_MAX_KEYS; } @@ -5002,7 +5002,7 @@ static int CmdHF14AMfUAESAuthChk(const char *Cmd) { } // cap by what fits in one frame, then by what the nkeys field can announce - uint32_t max_chunk = (pm3_max_cmd_data_size() - MIFAREU3P_CHKKEY_HEADER) / keysize; + uint32_t max_chunk = (g_conn.max_cmd_data_size - MIFAREU3P_CHKKEY_HEADER) / keysize; if (max_chunk > MIFAREU3P_CHKKEY_MAX_KEYS) { max_chunk = MIFAREU3P_CHKKEY_MAX_KEYS; } @@ -8685,9 +8685,9 @@ static int CmdHF14AMfUeSetBlk(const char *Cmd) { // one esetblk is a single CMD_HF_MIFARE_EML_MEMSET; its payload (data + a 4-byte // header) must fit the command buffer. Larger sets should use `hf mfu eload`. - if (datalen > (int)(pm3_max_cmd_data_size() - 4)) { + if (datalen > (int)(g_conn.max_cmd_data_size - 4)) { PrintAndLogEx(WARNING, "too many pages for one command: max %d pages (%d bytes). Use " _YELLOW_("`hf mfu eload`") " for larger sets", - (int)((pm3_max_cmd_data_size() - 4) / MFU_BLOCK_SIZE), (int)(pm3_max_cmd_data_size() - 4)); + (int)((g_conn.max_cmd_data_size - 4) / MFU_BLOCK_SIZE), (int)(g_conn.max_cmd_data_size - 4)); return PM3_EINVARG; } diff --git a/client/src/cmdhfseos.c b/client/src/cmdhfseos.c index 6dac3d527..ef2289514 100644 --- a/client/src/cmdhfseos.c +++ b/client/src/cmdhfseos.c @@ -2321,7 +2321,7 @@ static int CmdHfSeosSAM(const char *Cmd) { data[0] = flags; int cmdlen = 0; - if (CLIParamHexToBuf(arg_get_str(ctx, 5), data + 1, pm3_max_cmd_data_size() - 1, &cmdlen) != PM3_SUCCESS) { + if (CLIParamHexToBuf(arg_get_str(ctx, 5), data + 1, g_conn.max_cmd_data_size - 1, &cmdlen) != PM3_SUCCESS) { CLIParserFree(ctx); return PM3_ESOFT; } diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index a1282d4b3..4c154edea 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -1910,8 +1910,8 @@ static int CmdPing(const char *Cmd) { uint32_t len = arg_get_u32_def(ctx, 1, 32); CLIParserFree(ctx); - if (len > pm3_max_cmd_data_size()) - len = pm3_max_cmd_data_size(); + if (len > g_conn.max_cmd_data_size) + len = g_conn.max_cmd_data_size; if (len) { PrintAndLogEx(INFO, "Ping sent with payload len... " _YELLOW_("%d"), len); diff --git a/client/src/cmdlf.c b/client/src/cmdlf.c index 9603a257a..17b682620 100644 --- a/client/src/cmdlf.c +++ b/client/src/cmdlf.c @@ -359,8 +359,8 @@ int CmdLFCommandRead(const char *Cmd) { memset(payload.symbol_extra, 0, sizeof(payload.symbol_extra)); memset(payload.period_extra, 0, sizeof(payload.period_extra)); - if (cmd_len > (size_t)(pm3_max_cmd_data_size() - PAYLOAD_HEADER_SIZE) - 8 * add_crc_ht - 1) { - PrintAndLogEx(ERR, "cmd too long, max length is %zu", (size_t)(pm3_max_cmd_data_size() - PAYLOAD_HEADER_SIZE) - 8 * add_crc_ht - 1); + if (cmd_len > (size_t)(g_conn.max_cmd_data_size - PAYLOAD_HEADER_SIZE) - 8 * add_crc_ht - 1) { + PrintAndLogEx(ERR, "cmd too long, max length is %zu", (size_t)(g_conn.max_cmd_data_size - PAYLOAD_HEADER_SIZE) - 8 * add_crc_ht - 1); return PM3_EINVARG; } @@ -1072,9 +1072,9 @@ int lfsim_upload_gb(void) { //can send only 512 bits at a time (1 byte sent per bit...) PrintAndLogEx(INFO, "." NOLF); - for (size_t i = 0; i < g_GraphTraceLen; i += pm3_max_cmd_data_size() - 3) { + for (size_t i = 0; i < g_GraphTraceLen; i += g_conn.max_cmd_data_size - 3) { - size_t len = MIN((g_GraphTraceLen - i), (size_t)(pm3_max_cmd_data_size() - 3)); + size_t len = MIN((g_GraphTraceLen - i), (size_t)(g_conn.max_cmd_data_size - 3)); clearCommandBuffer(); payload_up.offset = i; @@ -1239,10 +1239,10 @@ int CmdLFfskSim(const char *Cmd) { } size_t size = g_DemodBufferLen; - if (size > (pm3_max_cmd_data_size() - sizeof(lf_fsksim_t))) { - PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, (size_t)(pm3_max_cmd_data_size() - sizeof(lf_fsksim_t))); + if (size > (g_conn.max_cmd_data_size - sizeof(lf_fsksim_t))) { + PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, (size_t)(g_conn.max_cmd_data_size - sizeof(lf_fsksim_t))); PrintAndLogEx(INFO, "Continuing with trimmed down data"); - size = pm3_max_cmd_data_size() - sizeof(lf_fsksim_t); + size = g_conn.max_cmd_data_size - sizeof(lf_fsksim_t); } lf_fsksim_t *payload = calloc(1, sizeof(lf_fsksim_t) + size); @@ -1356,10 +1356,10 @@ int CmdLFaskSim(const char *Cmd) { } size_t size = g_DemodBufferLen; - if (size > (pm3_max_cmd_data_size() - sizeof(lf_asksim_t))) { - PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, (size_t)(pm3_max_cmd_data_size() - sizeof(lf_asksim_t))); + if (size > (g_conn.max_cmd_data_size - sizeof(lf_asksim_t))) { + PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, (size_t)(g_conn.max_cmd_data_size - sizeof(lf_asksim_t))); PrintAndLogEx(INFO, "Continuing with trimmed down data"); - size = pm3_max_cmd_data_size() - sizeof(lf_asksim_t); + size = g_conn.max_cmd_data_size - sizeof(lf_asksim_t); } lf_asksim_t *payload = calloc(1, sizeof(lf_asksim_t) + size); @@ -1492,10 +1492,10 @@ int CmdLFpskSim(const char *Cmd) { } size_t size = g_DemodBufferLen; - if (size > (pm3_max_cmd_data_size() - sizeof(lf_psksim_t))) { - PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, (size_t)(pm3_max_cmd_data_size() - sizeof(lf_psksim_t))); + if (size > (g_conn.max_cmd_data_size - sizeof(lf_psksim_t))) { + PrintAndLogEx(WARNING, "DemodBuffer too long for current implementation - length: %zu - max: %zu", size, (size_t)(g_conn.max_cmd_data_size - sizeof(lf_psksim_t))); PrintAndLogEx(INFO, "Continuing with trimmed down data"); - size = pm3_max_cmd_data_size() - sizeof(lf_psksim_t); + size = g_conn.max_cmd_data_size - sizeof(lf_psksim_t); } lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + size); diff --git a/client/src/cmdlfem4x50.c b/client/src/cmdlfem4x50.c index 2c1ccc7e4..8fa3a663e 100644 --- a/client/src/cmdlfem4x50.c +++ b/client/src/cmdlfem4x50.c @@ -166,7 +166,7 @@ static int em4x50_load_file(const char *filename, uint8_t *data, size_t data_len static int em4x50_seteml(const uint8_t *src, uint32_t offset, uint32_t numofbytes) { // an EM4x50 is 136 bytes, so the whole tag always fits in a single frame - if ((offset + numofbytes) > (pm3_max_cmd_data_size() - sizeof(em4x50_eset_t))) { + if ((offset + numofbytes) > (g_conn.max_cmd_data_size - sizeof(em4x50_eset_t))) { PrintAndLogEx(FAILED, "%u bytes at offset %u doesn't fit in one frame", numofbytes, offset); return PM3_EOUTOFBOUND; } diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index 94cc4d3f3..3382d08cb 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -1139,7 +1139,7 @@ static int download_trace(void) { gs_traceLen = 0; - gs_trace = calloc(pm3_max_cmd_data_size(), sizeof(uint8_t)); + gs_trace = calloc(g_conn.max_cmd_data_size, sizeof(uint8_t)); if (gs_trace == NULL) { PrintAndLogEx(WARNING, "Failed to allocate memory"); return PM3_EMALLOC; @@ -1149,7 +1149,7 @@ static int download_trace(void) { // Query for the size of the trace, downloading PM3_CMD_DATA_SIZE PacketResponseNG resp; - if (!GetFromDevice(BIG_BUF, gs_trace, pm3_max_cmd_data_size(), 0, NULL, 0, &resp, 4000, true)) { + if (!GetFromDevice(BIG_BUF, gs_trace, g_conn.max_cmd_data_size, 0, NULL, 0, &resp, 4000, true)) { PrintAndLogEx(WARNING, "timeout while waiting for reply"); free(gs_trace); gs_trace = NULL; @@ -1166,7 +1166,7 @@ static int download_trace(void) { gs_traceLen = ((const download_done_t *)resp.data.asBytes)->extra; // if tracelog buffer was larger and we need to download more. - if (gs_traceLen > pm3_max_cmd_data_size()) { + if (gs_traceLen > g_conn.max_cmd_data_size) { free(gs_trace); gs_trace = calloc(gs_traceLen, sizeof(uint8_t)); diff --git a/client/src/cmdusart.c b/client/src/cmdusart.c index 8dcae1ce7..9fc47f382 100644 --- a/client/src/cmdusart.c +++ b/client/src/cmdusart.c @@ -71,7 +71,7 @@ static int usart_txrx(uint8_t *srcdata, size_t srclen, uint8_t *dstdata, size_t payload.header.waittime = waittime; - if (srclen >= (size_t)(pm3_max_cmd_data_size() - sizeof(uint32_t))) { + if (srclen >= (size_t)(g_conn.max_cmd_data_size - sizeof(uint32_t))) { return PM3_EOVFLOW; } @@ -637,7 +637,7 @@ static int CmdUsartTXhex(const char *Cmd) { int dlen = 0; uint8_t data[PM3_CMD_DATA_SIZE] = {0x00}; - int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, (int)pm3_max_cmd_data_size(), &dlen); + int res = CLIParamHexToBuf(arg_get_str(ctx, 1), data, (int)g_conn.max_cmd_data_size, &dlen); CLIParserFree(ctx); if (res) { diff --git a/client/src/comms.c b/client/src/comms.c index 4b385cd46..46af8ee6a 100644 --- a/client/src/comms.c +++ b/client/src/comms.c @@ -40,10 +40,6 @@ static serial_port sp = NULL; communication_arg_t g_conn; capabilities_t g_pm3_capabilities; -uint16_t pm3_max_cmd_data_size(void) { - return g_conn.max_cmd_data_size; -} - static pthread_t communication_thread; static pthread_t reconnect_thread; @@ -182,7 +178,7 @@ void SendCommandNG(uint16_t cmd, uint8_t *data, size_t len) { PrintAndLogEx(INFO, "Sending bytes to proxmark failed - offline"); return; } - uint16_t maxlen = pm3_max_cmd_data_size(); + uint16_t maxlen = g_conn.max_cmd_data_size; if (len > maxlen) { PrintAndLogEx(WARNING, "Sending " _RED_("%zu") " bytes of payload is too much for this device (max " _YELLOW_("%u") "), abort", len, maxlen); return; diff --git a/client/src/comms.h b/client/src/comms.h index cdc6d1f7a..4eba1b0c5 100644 --- a/client/src/comms.h +++ b/client/src/comms.h @@ -107,7 +107,6 @@ size_t GetCommunicationRawReceiveNum(void); bool OpenProxmarkSilent(pm3_device_t **dev, const char *port, uint32_t speed); bool OpenProxmark(pm3_device_t **dev, const char *port, bool wait_for_port, int timeout, bool flash_mode, uint32_t speed); int TestProxmark(pm3_device_t *dev); -uint16_t pm3_max_cmd_data_size(void); void CloseProxmark(pm3_device_t *dev); void StartReconnectProxmark(void); diff --git a/client/src/mifare/mifarehost.c b/client/src/mifare/mifarehost.c index 885997390..d06a666dd 100644 --- a/client/src/mifare/mifarehost.c +++ b/client/src/mifare/mifarehost.c @@ -181,7 +181,7 @@ int mf_dark_side(uint8_t blockno, uint8_t key_type, uint64_t *key) { uint32_t max_keys = KEYS_IN_BLOCK; { // cap per-chunk keys to what fits one CHKKEYS frame to THIS device (5B header, uint8_t count) - uint32_t rt = (pm3_max_cmd_data_size() - 5) / MIFARE_KEY_SIZE; + uint32_t rt = (g_conn.max_cmd_data_size - 5) / MIFARE_KEY_SIZE; if (max_keys > rt) max_keys = rt; } for (uint32_t i = 0; i < keycount; i += max_keys) { @@ -495,7 +495,7 @@ int mf_key_brute(uint8_t blockNo, uint8_t keyType, const uint8_t *key, uint64_t // keys per call is bounded by what THIS device accepts (negotiated at connect) // and by the uint8_t keycnt field. keyBlock stays sized to the compile-time // KEYS_IN_BLOCK, which is always >= this runtime value. - uint32_t per = (pm3_max_cmd_data_size() - 5) / MIFARE_KEY_SIZE; + uint32_t per = (g_conn.max_cmd_data_size - 5) / MIFARE_KEY_SIZE; if (per > 255) { per = 255; } @@ -695,7 +695,7 @@ int mf_nested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBlockNo uint64_t key64 = -1; // The list may still contain several key candidates. Test each of them with mfCheckKeys - uint32_t kib = (pm3_max_cmd_data_size() - 5) / MIFARE_KEY_SIZE; + uint32_t kib = (g_conn.max_cmd_data_size - 5) / MIFARE_KEY_SIZE; if (kib > KEYS_IN_BLOCK) { kib = KEYS_IN_BLOCK; } @@ -894,7 +894,7 @@ int mf_static_nested(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trg if (IfPm3Flash()) { maxkeysinblock = 1000; // uploaded to flash via chunked SPIFFS } else { - maxkeysinblock = (pm3_max_cmd_data_size() - 5) / MIFARE_KEY_SIZE; // one CHKKEYS frame to THIS device + maxkeysinblock = (g_conn.max_cmd_data_size - 5) / MIFARE_KEY_SIZE; // one CHKKEYS frame to THIS device if (maxkeysinblock > 255) { // mf_check_keys keycnt is uint8_t maxkeysinblock = 255; } @@ -1121,7 +1121,7 @@ int mf_eml_get_mem(uint8_t *data, int blockNum, int blocksCount) { int mf_eml_get_mem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) { size_t size = ((size_t) blocksCount) * blockBtWidth; - if (size > pm3_max_cmd_data_size()) { + if (size > g_conn.max_cmd_data_size) { return PM3_ESOFT; } @@ -1165,7 +1165,7 @@ int mf_eml_set_mem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtW } PACKED; size_t size = ((size_t) blocksCount) * blockBtWidth; - if (size > (pm3_max_cmd_data_size() - sizeof(struct p))) { + if (size > (g_conn.max_cmd_data_size - sizeof(struct p))) { return PM3_EINVARG; }