Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed use of sizeof (Use it on a pointer is illegal) #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dump_eeprom(st_srx_tag_t *dest, bool verbose) {
fprintf(stderr, "Reading %d blocks\n|", tag_length);
for (uint8_t i = 0; i < tag_length; i++) {
uint8_t *block_dest = dest->raw_bytes + i * 4;
if (st_srx_read_block(pnd, block_dest, i, verbose) <= 0) {
if (st_srx_read_block(pnd, block_dest, sizeof(uint8_t) * 4, i, verbose) <= 0) {
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
nfc_close(pnd);
nfc_exit(context);
Expand All @@ -86,7 +86,7 @@ dump_eeprom(st_srx_tag_t *dest, bool verbose) {

fprintf(stderr, "Reading system area block (0xFF)\n");
uint8_t *block_dest = dest->raw_bytes + 0xff * 4;
if (st_srx_read_block(pnd, block_dest, 0xff, verbose) <= 0) {
if (st_srx_read_block(pnd, block_dest, sizeof(uint8_t) * 4, 0xff, verbose) <= 0) {
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
nfc_close(pnd);
nfc_exit(context);
Expand Down Expand Up @@ -186,15 +186,15 @@ write_eeprom(st_srx_tag_t *src, bool verbose) {
for (uint8_t i = 0; i < tag_length; i++) {
uint8_t *block_src = src->raw_blocks[i];

if (st_srx_read_block(pnd, abtRx, i, verbose) <= 0) {
if (st_srx_read_block(pnd, abtRx, sizeof(abtRx), i, verbose) <= 0) {
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
nfc_close(pnd);
nfc_exit(context);
return EXIT_FAILURE;
}

if (memcmp(block_src, abtRx, 4) != 0) {
if (st_srx_write_block(pnd, abtRx, i, block_src, verbose) <= 0) {
if (st_srx_write_block(pnd, abtRx, sizeof(abtRx), i, block_src, verbose) <= 0) {
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
nfc_close(pnd);
nfc_exit(context);
Expand All @@ -210,14 +210,14 @@ write_eeprom(st_srx_tag_t *src, bool verbose) {

fprintf(stderr, "Writing system area block (0xFF)\n");
uint8_t *block_src = src->srix4k.system_block;
if (st_srx_read_block(pnd, abtRx, 0xFF, verbose) <= 0) {
if (st_srx_read_block(pnd, abtRx, sizeof(abtRx), 0xFF, verbose) <= 0) {
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
nfc_close(pnd);
nfc_exit(context);
return EXIT_FAILURE;
}
if (memcmp(block_src, abtRx, 4) != 0) {
if (st_srx_write_block(pnd, abtRx, 0xFF, block_src, verbose) <= 0) {
if (st_srx_write_block(pnd, abtRx, sizeof(abtRx), 0xFF, block_src, verbose) <= 0) {
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
nfc_close(pnd);
nfc_exit(context);
Expand Down Expand Up @@ -362,7 +362,7 @@ main(int argc, const char *argv[]) {

// Try to retrieve the UID using the SRx protocol to confirm it's working
fprintf(stderr, "Found ISO14443B-2 tag, UID:\n");
size_t received_bytes = st_srx_get_uid(pnd, abtRx, true);
size_t received_bytes = st_srx_get_uid(pnd, abtRx, sizeof(abtRx), true);
if (received_bytes <= 0) {
fclose(dump_fd);
ERR("Failed to retrieve the UID");
Expand Down
4 changes: 2 additions & 2 deletions nfc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ print_nfc_target(const nfc_target *pnt, bool verbose) {
}

size_t
transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, uint8_t *pbtRx, const size_t szTx, bool verbose) {
transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, uint8_t *pbtRx, const size_t szTx, const size_t szRx, bool verbose) {
if (verbose) {
// Show transmitted command
fprintf(stderr, "Sent bits: ");
Expand All @@ -79,7 +79,7 @@ transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, uint8_t *pbtRx, const si
// Transmit the command bytes
size_t res;

if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, pbtRx, sizeof(pbtRx), 0)) < 0)
if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, pbtRx, szRx, 0)) < 0)
return false;

if (verbose) {
Expand Down
2 changes: 1 addition & 1 deletion nfc-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@

void print_hex(const uint8_t *pbtData, size_t szLen);
void print_nfc_target(const nfc_target *pnt, bool verbose);
size_t transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, uint8_t *pbtRx, size_t szTx, bool verbose);
size_t transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, uint8_t *pbtRx, size_t szTx, size_t szRx, bool verbose);

#endif
12 changes: 6 additions & 6 deletions st-srx.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@


size_t
st_srx_get_uid(nfc_device *pnd, uint8_t *uidRx, bool verbose) {
st_srx_get_uid(nfc_device *pnd, uint8_t *uidRx, const size_t szUid, bool verbose) {
uint8_t cmd[] = {0x0b};
return transceive_bytes(pnd, (const uint8_t *) &cmd, uidRx, sizeof(cmd), verbose);
return transceive_bytes(pnd, (const uint8_t *) &cmd, uidRx, sizeof(cmd), szUid, verbose);
}


size_t
st_srx_read_block(nfc_device *pnd, uint8_t *blockRx, uint8_t address, bool verbose) {
st_srx_read_block(nfc_device *pnd, uint8_t *blockRx, const size_t szRead, uint8_t address, bool verbose) {
uint8_t cmd[2] = {0x08};
memcpy(cmd + 1, &address, 1);
return transceive_bytes(pnd, (const uint8_t *) &cmd, blockRx, sizeof(cmd), verbose);
return transceive_bytes(pnd, (const uint8_t *) &cmd, blockRx, sizeof(cmd), szRead, verbose);
}

size_t
st_srx_write_block(nfc_device *pnd, uint8_t *blockRx, uint8_t address, uint8_t *data, bool verbose) {
st_srx_write_block(nfc_device *pnd, uint8_t *blockRx, const size_t szWrite, uint8_t address, uint8_t *data, bool verbose) {
uint8_t cmd[6] = {0x09};
memcpy(cmd + 1, &address, 1);
memcpy(cmd + 2, data, 4);
return transceive_bytes(pnd, (const uint8_t *) &cmd, blockRx, sizeof(cmd), verbose);
return transceive_bytes(pnd, (const uint8_t *) &cmd, blockRx, sizeof(cmd), szWrite, verbose);
}
6 changes: 3 additions & 3 deletions st-srx.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ typedef union {
uint8_t raw_blocks[DUMP_LEN][4];
} st_srx_tag_t;

size_t st_srx_get_uid(nfc_device *pnd, uint8_t *uidRx, bool verbose);
size_t st_srx_read_block(nfc_device *pnd, uint8_t *blockRx, uint8_t address, bool verbose);
size_t st_srx_write_block(nfc_device *pnd, uint8_t *blockRx, uint8_t address, uint8_t *data, bool verbose);
size_t st_srx_get_uid(nfc_device *pnd, uint8_t *uidRx, size_t szUid, bool verbose);
size_t st_srx_read_block(nfc_device *pnd, uint8_t *blockRx, size_t szRead, uint8_t address, bool verbose);
size_t st_srx_write_block(nfc_device *pnd, uint8_t *blockRx, size_t szWrite, uint8_t address, uint8_t *data, bool verbose);

#endif //NFC_ST_SRX_ST_SRX_H