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

Add all the LTO commands in header file #4

Merged
merged 3 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add Select in header
  • Loading branch information
Kevin-Nakamoto committed Feb 22, 2021
commit 59cf09a8f0d03a8b821977440df5c14dbde6dc62
26 changes: 20 additions & 6 deletions nfc-ltocm.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ bool ltocm_req_serial(uint8_t *serialNum, int *serialNumLen)

}

bool ltocm_select(uint8_t *serialNum, uint8_t *retSelect, int *retLenSelect)
{
uint8_t selectCmd[sizeof(LTOCM_SELECT)];
memcpy(selectCmd, LTOCM_SELECT, sizeof(LTOCM_SELECT));
memcpy(&selectCmd[2], &serialNum[0], 5);
iso14443a_crc_append(selectCmd, 7);

if (!transmit_bytes(selectCmd, sizeof(LTOCM_SELECT)))
return false;

*retSelect = abtRx[0];
*retLenSelect = szRxBytes;
return true;

}

int main(int argc, char **argv)
{
int returncode = EXIT_SUCCESS;
Expand Down Expand Up @@ -277,18 +293,16 @@ int main(int argc, char **argv)

// Send LTO-CM SELECT to Select the chip we just found
// (LTO-CM state PRESELECT -> COMMAND)
uint8_t selectCmd[sizeof(LTOCM_SELECT)];
memcpy(selectCmd, LTOCM_SELECT, sizeof(LTOCM_SELECT));
memcpy(&selectCmd[2], abtRx, 5);
iso14443a_crc_append(selectCmd, 7);
if (!transmit_bytes(selectCmd, sizeof(LTOCM_SELECT))) {
uint8_t retSelect;
int retLenSelect;
if (!ltocm_select(&serialNum[0], &retSelect, &retLenSelect)) {
printf("Error: error with SELECT command\n");
returncode = EXIT_FAILURE;
goto err_exit;
}

// Check that the LTO-CM chip sent us an acknowledgement
if ((szRxBytes != 1) || (abtRx[0] != 0x0A)) {
if ((retLenSelect != 1) || (retSelect != 0x0A)) {
printf("Error: Failed to SELECT the LTO-CM chip\n");
returncode = EXIT_FAILURE;
goto err_exit;
Expand Down
2 changes: 1 addition & 1 deletion nfc-ltocm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

bool ltocm_req_std(uint8_t *ltoStandard);
bool ltocm_req_serial(uint8_t *serialNum, int *serialNumLen);

bool ltocm_select(uint8_t *serialNum, uint8_t *retSelect, int *retLenSelect);

#endif