Skip to content

Commit

Permalink
more use of malloc
Browse files Browse the repository at this point in the history
  • Loading branch information
bettse committed Jul 27, 2024
1 parent 0d677d5 commit b5c45a9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 30 deletions.
32 changes: 4 additions & 28 deletions ccid.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,12 @@ void seader_ccid_XfrBlockToSlot(
seader_uart->tx_len = header_len + len;
seader_uart->tx_len = seader_add_lrc(seader_uart->tx_buf, seader_uart->tx_len);

char display[SEADER_UART_RX_BUF_SIZE * 2 + 1] = {0};
char* display = malloc(seader_uart->tx_len * 2 + 1);
for(uint8_t i = 0; i < seader_uart->tx_len; i++) {
snprintf(display + (i * 2), sizeof(display), "%02x", seader_uart->tx_buf[i]);
}
FURI_LOG_D(TAG, "seader_ccid_XfrBlockToSlot(%d) %d: %s", slot, seader_uart->tx_len, display);
free(display);

furi_thread_flags_set(furi_thread_get_id(seader_uart->tx_thread), WorkerEvtSamRx);
}
Expand All @@ -162,11 +163,12 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
CCID_Message message;
message.consumed = 0;

char display[SEADER_UART_RX_BUF_SIZE * 2 + 1] = {0};
char* display = malloc(cmd_len * 2 + 1);
for(uint8_t i = 0; i < cmd_len; i++) {
snprintf(display + (i * 2), sizeof(display), "%02x", cmd[i]);
}
FURI_LOG_D(TAG, "seader_ccid_process %d: %s", cmd_len, display);
free(display);

if(cmd_len == 2) {
if(cmd[0] == CCID_MESSAGE_TYPE_RDR_to_PC_NotifySlotChange) {
Expand Down Expand Up @@ -253,11 +255,6 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
message.bError = ccid[8];
message.payload = ccid + 10;

memset(display, 0, sizeof(display));
for(uint8_t i = 0; i < message.dwLength; i++) {
snprintf(display + (i * 2), sizeof(display), "%02x", message.payload[i]);
}

if(cmd_len < 2 + 10 + message.dwLength + 1) {
// Incomplete
return message.consumed;
Expand All @@ -274,27 +271,6 @@ size_t seader_ccid_process(Seader* seader, uint8_t* cmd, size_t cmd_len) {
return message.consumed;
}

/*
if(message.dwLength == 0) {
FURI_LOG_D(
TAG,
"CCID [%d|%d] type: %02x, status: %02x, error: %02x",
message.bSlot,
message.bSeq,
message.bMessageType,
message.bStatus,
message.bError);
} else {
FURI_LOG_D(
TAG,
"CCID [%d|%d] %ld: %s",
message.bSlot,
message.bSeq,
message.dwLength,
display);
}
*/

//0306 81 00000000 0000 0200 01 87
//0306 81 00000000 0000 0100 01 84
if(message.bMessageType == CCID_MESSAGE_TYPE_RDR_to_PC_SlotStatus) {
Expand Down
2 changes: 1 addition & 1 deletion sam_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ bool seader_send_apdu(
}

uint8_t length = APDU_HEADER_LEN + payloadLen;
uint8_t *apdu = malloc(length);
uint8_t* apdu = malloc(length);
if(!apdu) {
FURI_LOG_E(TAG, "Failed to allocate memory for apdu in seader_send_apdu");
return false;
Expand Down
2 changes: 1 addition & 1 deletion uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int32_t seader_uart_worker(void* context) {
seader_uart->tx_sem = furi_semaphore_alloc(1, 1);

seader_uart->tx_thread =
furi_thread_alloc_ex("SeaderUartTxWorker", 3 * 1024, seader_uart_tx_thread, seader);
furi_thread_alloc_ex("SeaderUartTxWorker", 2 * 1024, seader_uart_tx_thread, seader);

seader_uart_serial_init(seader_uart, seader_uart->cfg.uart_ch);
seader_uart_set_baudrate(seader_uart, seader_uart->cfg.baudrate);
Expand Down

0 comments on commit b5c45a9

Please sign in to comment.