From 15a37ef9dfc724787932a0ce5805526d1a93c872 Mon Sep 17 00:00:00 2001 From: Jakub Kramarz Date: Tue, 7 Jan 2025 00:30:49 +0100 Subject: [PATCH] seos_sam: ran make style --- armsrc/sam_common.c | 92 ++++++++++----------- armsrc/sam_common.h | 6 +- armsrc/sam_picopass.c | 32 ++++---- armsrc/sam_seos.c | 154 +++++++++++++++++------------------ client/src/cmdhficlass.c | 6 +- client/src/cmdhfseos.c | 48 +++++------ client/src/cmdhfseos.h | 4 +- client/src/wiegand_formats.c | 6 +- client/src/wiegand_formats.h | 2 +- common_arm/ticks.c | 2 +- 10 files changed, 176 insertions(+), 176 deletions(-) diff --git a/armsrc/sam_common.c b/armsrc/sam_common.c index 835428074..76ca269e1 100644 --- a/armsrc/sam_common.c +++ b/armsrc/sam_common.c @@ -96,12 +96,12 @@ int sam_rxtx(const uint8_t *data, uint16_t n, uint8_t *resp, uint16_t *resplen) *resplen += more_len; - out: +out: return res; } -static inline void swap_clock_counters(volatile unsigned int * a, unsigned int * b){ +static inline void swap_clock_counters(volatile unsigned int *a, unsigned int *b) { unsigned int c = *a; *a = *b; *b = c; @@ -113,9 +113,9 @@ static inline void swap_clock_counters(volatile unsigned int * a, unsigned int * * AT91SAM7S512 has a single Timer-Counter, that is reused in clocks Ticks * and CountSspClk. This function stops the current clock and restores previous * values. It is used to switch between different clock sources. - * It probably makes communication timing off, but at least makes it work. + * It probably makes communication timing off, but at least makes it work. */ -static void swap_clocks(void){ +static void swap_clocks(void) { static unsigned int tc0, tc1, tc2 = 0; StopTicks(); swap_clock_counters(&(AT91C_BASE_TC0->TC_CV), &tc0); @@ -123,12 +123,12 @@ static void swap_clocks(void){ swap_clock_counters(&(AT91C_BASE_TC2->TC_CV), &tc2); } -void switch_clock_to_ticks(void){ +void switch_clock_to_ticks(void) { swap_clocks(); StartTicks(); } -void switch_clock_to_countsspclk(void){ +void switch_clock_to_countsspclk(void) { swap_clocks(); StartCountSspClk(); } @@ -155,21 +155,21 @@ int sam_send_payload( const uint8_t addr_dest, const uint8_t addr_reply, - const uint8_t * const payload, + const uint8_t *const payload, const uint16_t *payload_len, uint8_t *response, uint16_t *response_len -){ +) { int res = PM3_SUCCESS; - uint8_t * buf = response; + uint8_t *buf = response; buf[0] = 0xA0; // CLA buf[1] = 0xDA; // INS (PUT DATA) buf[2] = 0x02; // P1 (TLV format?) buf[3] = 0x63; // P2 - buf[4] = SAM_TX_ASN1_PREFIX_LENGTH + (uint8_t) *payload_len; // LEN + buf[4] = SAM_TX_ASN1_PREFIX_LENGTH + (uint8_t) * payload_len; // LEN buf[5] = addr_src; buf[6] = addr_dest; @@ -185,10 +185,10 @@ int sam_send_payload( *payload_len ); - uint16_t length = SAM_TX_ASN1_PREFIX_LENGTH + SAM_TX_APDU_PREFIX_LENGTH + (uint8_t) *payload_len; + uint16_t length = SAM_TX_ASN1_PREFIX_LENGTH + SAM_TX_APDU_PREFIX_LENGTH + (uint8_t) * payload_len; LogTrace(buf, length, 0, 0, NULL, true); - if (g_dbglevel >= DBG_INFO){ + if (g_dbglevel >= DBG_INFO) { DbpString("SAM REQUEST APDU: "); Dbhexdump(length, buf, false); } @@ -201,12 +201,12 @@ int sam_send_payload( } LogTrace(response, *response_len, 0, 0, NULL, false); - if (g_dbglevel >= DBG_INFO){ + if (g_dbglevel >= DBG_INFO) { DbpString("SAM RESPONSE APDU: "); Dbhexdump(*response_len, response, false); } - out: +out: return res; } @@ -218,18 +218,18 @@ int sam_send_payload( * * @return Status code indicating success or failure of the operation. */ -int sam_get_version(void){ +int sam_get_version(void) { int res = PM3_SUCCESS; if (g_dbglevel >= DBG_DEBUG) DbpString("start sam_get_version"); - uint8_t * response = BigBuf_malloc(ISO7816_MAX_FRAME); + uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME); uint16_t response_len = ISO7816_MAX_FRAME; uint8_t payload[] = { 0xa0, 0x02, // <- SAM command - 0x82, 0x00 // <- get version + 0x82, 0x00 // <- get version }; uint16_t payload_len = sizeof(payload); @@ -255,46 +255,46 @@ int sam_get_version(void){ if (g_dbglevel >= DBG_DEBUG) DbpString("end sam_get_version"); - if(response[5] != 0xbd){ + if (response[5] != 0xbd) { Dbprintf("Invalid SAM response"); goto error; - }else{ - uint8_t * sam_response_an = sam_find_asn1_node(response + 5, 0x8a); - if(sam_response_an == NULL){ + } else { + uint8_t *sam_response_an = sam_find_asn1_node(response + 5, 0x8a); + if (sam_response_an == NULL) { if (g_dbglevel >= DBG_ERROR) DbpString("SAM get response failed"); goto error; } - uint8_t * sam_version_an = sam_find_asn1_node(sam_response_an, 0x80); - if(sam_version_an == NULL){ + uint8_t *sam_version_an = sam_find_asn1_node(sam_response_an, 0x80); + if (sam_version_an == NULL) { if (g_dbglevel >= DBG_ERROR) DbpString("SAM get version failed"); goto error; } - uint8_t * sam_build_an = sam_find_asn1_node(sam_response_an, 0x81); - if(sam_build_an == NULL){ + uint8_t *sam_build_an = sam_find_asn1_node(sam_response_an, 0x81); + if (sam_build_an == NULL) { if (g_dbglevel >= DBG_ERROR) DbpString("SAM get firmware ID failed"); goto error; } - if (g_dbglevel >= DBG_INFO){ + if (g_dbglevel >= DBG_INFO) { DbpString("SAM get version successful"); Dbprintf("Firmware version: %X.%X", sam_version_an[2], sam_version_an[3]); Dbprintf("Firmware ID: "); - Dbhexdump(sam_build_an[1], sam_build_an+2, false); + Dbhexdump(sam_build_an[1], sam_build_an + 2, false); } goto out; } - error: +error: res = PM3_ESOFT; - out: +out: BigBuf_free(); if (g_dbglevel >= DBG_DEBUG) DbpString("end sam_get_version"); - + return res; } @@ -310,14 +310,14 @@ int sam_get_version(void){ * @param type The type of the ASN.1 node to find. * @return Pointer to the ASN.1 node of the specified type if found, otherwise NULL. */ -uint8_t * sam_find_asn1_node(const uint8_t * root, const uint8_t type){ - const uint8_t * end = (uint8_t *) root + *(root+1); - uint8_t * current = (uint8_t *) root + 2; - while(current < end){ - if(*current == type){ +uint8_t *sam_find_asn1_node(const uint8_t *root, const uint8_t type) { + const uint8_t *end = (uint8_t *) root + *(root + 1); + uint8_t *current = (uint8_t *) root + 2; + while (current < end) { + if (*current == type) { return current; - }else{ - current += 2 + *(current+1); + } else { + current += 2 + *(current + 1); } } return NULL; @@ -328,7 +328,7 @@ uint8_t * sam_find_asn1_node(const uint8_t * root, const uint8_t type){ * * This function appends an ASN.1 node of a specified type and length to the end of * the ASN.1 structure at specified node level. - * + * * It is the most naive solution that does not handle the case where the node to append is * not the last node at the same level. It also does not also care about proper * order of the nodes. @@ -339,21 +339,21 @@ uint8_t * sam_find_asn1_node(const uint8_t * root, const uint8_t type){ * @param data Pointer to the data to be appended. * @param len The length of the data to be appended. */ -void sam_append_asn1_node(const uint8_t * root, const uint8_t * node, uint8_t type, const uint8_t * const data, uint8_t len){ - uint8_t * end = (uint8_t *) root + *(root+1) + 2; +void sam_append_asn1_node(const uint8_t *root, const uint8_t *node, uint8_t type, const uint8_t *const data, uint8_t len) { + uint8_t *end = (uint8_t *) root + *(root + 1) + 2; *(end) = type; - *(end+1) = len; - memcpy(end+2, data, len); + *(end + 1) = len; + memcpy(end + 2, data, len); - for(uint8_t * current = (uint8_t *) root; current <= node; current += 2){ - *(current+1) += 2 + len; + for (uint8_t *current = (uint8_t *) root; current <= node; current += 2) { + *(current + 1) += 2 + len; }; return; } -void sam_send_ack(void){ - uint8_t * response = BigBuf_malloc(ISO7816_MAX_FRAME); +void sam_send_ack(void) { + uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME); uint16_t response_len = ISO7816_MAX_FRAME; uint8_t payload[] = { diff --git a/armsrc/sam_common.h b/armsrc/sam_common.h index 5e243346c..645957a3c 100644 --- a/armsrc/sam_common.h +++ b/armsrc/sam_common.h @@ -32,7 +32,7 @@ int sam_send_payload( const uint8_t addr_dest, const uint8_t addr_reply, - const uint8_t * const payload, + const uint8_t *const payload, const uint16_t *payload_len, uint8_t *response, @@ -41,8 +41,8 @@ int sam_send_payload( int sam_get_version(void); -uint8_t * sam_find_asn1_node(const uint8_t * root, const uint8_t type); -void sam_append_asn1_node(const uint8_t * root, const uint8_t * node, uint8_t type, const uint8_t * const data, uint8_t len); +uint8_t *sam_find_asn1_node(const uint8_t *root, const uint8_t type); +void sam_append_asn1_node(const uint8_t *root, const uint8_t *node, uint8_t type, const uint8_t *const data, uint8_t len); void sam_send_ack(void); diff --git a/armsrc/sam_picopass.c b/armsrc/sam_picopass.c index 055423f41..d396a31c5 100644 --- a/armsrc/sam_picopass.c +++ b/armsrc/sam_picopass.c @@ -41,12 +41,12 @@ * @param card_select Pointer to the descriptor of the detected card. * @return Status code indicating success or failure of the operation. */ -static int sam_set_card_detected(picopass_hdr_t * card_select){ +static int sam_set_card_detected(picopass_hdr_t *card_select) { int res = PM3_SUCCESS; if (g_dbglevel >= DBG_DEBUG) DbpString("start sam_set_card_detected"); - uint8_t * response = BigBuf_malloc(ISO7816_MAX_FRAME); + uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME); uint16_t response_len = ISO7816_MAX_FRAME; // a0 12 @@ -59,13 +59,13 @@ static int sam_set_card_detected(picopass_hdr_t * card_select){ uint8_t payload[] = { 0xa0, 18, // <- SAM command - 0xad, 16, // <- set detected card - 0xa0, 4+10, - 0x80, 2, // <- protocol - 0x00, 0x04, // <- Picopass - 0x81, 8, // <- CSN - card_select->csn[0], card_select->csn[1], card_select->csn[2], card_select->csn[3], - card_select->csn[4], card_select->csn[5], card_select->csn[6], card_select->csn[7] + 0xad, 16, // <- set detected card + 0xa0, 4 + 10, + 0x80, 2, // <- protocol + 0x00, 0x04, // <- Picopass + 0x81, 8, // <- CSN + card_select->csn[0], card_select->csn[1], card_select->csn[2], card_select->csn[3], + card_select->csn[4], card_select->csn[5], card_select->csn[6], card_select->csn[7] }; uint16_t payload_len = sizeof(payload); @@ -82,12 +82,12 @@ static int sam_set_card_detected(picopass_hdr_t * card_select){ // bd 02 <- response // 8a 00 <- empty response (accepted) // 90 00 - - if(response[5] != 0xbd){ + + if (response[5] != 0xbd) { if (g_dbglevel >= DBG_ERROR) Dbprintf("Invalid SAM response"); goto error; - }else{ + } else { // uint8_t * sam_response_an = sam_find_asn1_node(response + 5, 0x8a); // if(sam_response_an == NULL){ // if (g_dbglevel >= DBG_ERROR) @@ -96,10 +96,10 @@ static int sam_set_card_detected(picopass_hdr_t * card_select){ // } goto out; } - error: +error: res = PM3_ESOFT; - out: +out: BigBuf_free(); if (g_dbglevel >= DBG_DEBUG) @@ -240,11 +240,11 @@ int sam_picopass_get_pacs(void) { // second - get PACS (0xA1) // a0 05 - // a1 03 + // a1 03 // 80 01 // 04 hexstr_to_byte_array("a005a103800104", sam_apdu, &sam_len); - if(sam_send_payload(0x44, 0x0a, 0x44, sam_apdu, (uint16_t *) &sam_len, resp, &resp_len) != PM3_SUCCESS) { + if (sam_send_payload(0x44, 0x0a, 0x44, sam_apdu, (uint16_t *) &sam_len, resp, &resp_len) != PM3_SUCCESS) { res = PM3_ECARDEXCHANGE; goto out; } diff --git a/armsrc/sam_seos.c b/armsrc/sam_seos.c index 37a2da259..2e5c09349 100644 --- a/armsrc/sam_seos.c +++ b/armsrc/sam_seos.c @@ -49,29 +49,29 @@ * @param card_select Pointer to the descriptor of the detected card. * @return Status code indicating success or failure of the operation. */ -static int sam_set_card_detected(iso14a_card_select_t * card_select){ +static int sam_set_card_detected(iso14a_card_select_t *card_select) { int res = PM3_SUCCESS; if (g_dbglevel >= DBG_DEBUG) DbpString("start sam_set_card_detected"); - uint8_t * request = BigBuf_malloc(ISO7816_MAX_FRAME); + uint8_t *request = BigBuf_malloc(ISO7816_MAX_FRAME); uint16_t request_len = ISO7816_MAX_FRAME; - uint8_t * response = BigBuf_malloc(ISO7816_MAX_FRAME); + uint8_t *response = BigBuf_malloc(ISO7816_MAX_FRAME); uint16_t response_len = ISO7816_MAX_FRAME; const uint8_t payload[] = { 0xa0, 8, // <- SAM command - 0xad, 6, // <- set detected card - 0xa0, 4, // <- detected card details - 0x80, 2, // <- protocol - 0x00, 0x02 // <- ISO14443A + 0xad, 6, // <- set detected card + 0xa0, 4, // <- detected card details + 0x80, 2, // <- protocol + 0x00, 0x02 // <- ISO14443A }; memcpy(request, payload, sizeof(payload)); - sam_append_asn1_node(request, request+4, 0x81, card_select->uid, card_select->uidlen); - sam_append_asn1_node(request, request+4, 0x82, card_select->atqa, 2); - sam_append_asn1_node(request, request+4, 0x83, &card_select->sak, 1); + sam_append_asn1_node(request, request + 4, 0x81, card_select->uid, card_select->uidlen); + sam_append_asn1_node(request, request + 4, 0x82, card_select->atqa, 2); + sam_append_asn1_node(request, request + 4, 0x83, &card_select->sak, 1); request_len = request[1] + 2; sam_send_payload( @@ -87,12 +87,12 @@ static int sam_set_card_detected(iso14a_card_select_t * card_select){ // bd 02 <- response // 8a 00 <- empty response (accepted) // 90 00 - - if(response[5] != 0xbd){ + + if (response[5] != 0xbd) { if (g_dbglevel >= DBG_ERROR) Dbprintf("Invalid SAM response"); goto error; - }else{ + } else { // uint8_t * sam_response_an = sam_find_asn1_node(response + 5, 0x8a); // if(sam_response_an == NULL){ // if (g_dbglevel >= DBG_ERROR) @@ -101,10 +101,10 @@ static int sam_set_card_detected(iso14a_card_select_t * card_select){ // } goto out; } - error: +error: res = PM3_ESOFT; - out: +out: BigBuf_free(); if (g_dbglevel >= DBG_DEBUG) @@ -123,7 +123,7 @@ static int sam_set_card_detected(iso14a_card_select_t * card_select){ * * @return Length of SAM APDU to be sent. */ -inline static uint16_t sam_seos_copy_payload_nfc2sam(uint8_t *sam_tx, uint8_t * nfc_rx, uint8_t nfc_len){ +inline static uint16_t sam_seos_copy_payload_nfc2sam(uint8_t *sam_tx, uint8_t *nfc_rx, uint8_t nfc_len) { // NFC resp: // 6f 0c 84 0a a0 00 00 04 40 00 01 01 00 01 90 00 fb e3 @@ -138,18 +138,18 @@ inline static uint16_t sam_seos_copy_payload_nfc2sam(uint8_t *sam_tx, uint8_t * const uint8_t payload[] = { 0xbd, 4, - 0xa0, 2, - 0xa0, 0 + 0xa0, 2, + 0xa0, 0 }; const uint8_t tag81[] = { - 0x00, 0x00 + 0x00, 0x00 }; memcpy(sam_tx, payload, sizeof(payload)); - - sam_append_asn1_node(sam_tx, sam_tx+4, 0x80, nfc_rx, nfc_len); - sam_append_asn1_node(sam_tx, sam_tx+4, 0x81, tag81, sizeof(tag81)); + + sam_append_asn1_node(sam_tx, sam_tx + 4, 0x80, nfc_rx, nfc_len); + sam_append_asn1_node(sam_tx, sam_tx + 4, 0x81, tag81, sizeof(tag81)); return sam_tx[1] + 2; // length of the ASN1 tree } @@ -163,7 +163,7 @@ inline static uint16_t sam_seos_copy_payload_nfc2sam(uint8_t *sam_tx, uint8_t * * @param sam_rx_buf Pointer to the buffer containing the data received from the SAM. * @return Length of NFC APDU to be sent. */ -inline static uint16_t sam_seos_copy_payload_sam2nfc(uint8_t * nfc_tx_buf, uint8_t * sam_rx_buf){ +inline static uint16_t sam_seos_copy_payload_sam2nfc(uint8_t *nfc_tx_buf, uint8_t *sam_rx_buf) { // SAM resp: // c1 61 c1 00 00 // a1 21 <- nfc command @@ -182,8 +182,8 @@ inline static uint16_t sam_seos_copy_payload_sam2nfc(uint8_t * nfc_tx_buf, uint8 // 00 a4 04 00 0a a0 00 00 04 40 00 01 01 00 01 00 // copy data out of c1->a1>->a1->80 node - uint16_t nfc_tx_len = (uint8_t) *(sam_rx_buf + 10); - memcpy(nfc_tx_buf, sam_rx_buf+11, nfc_tx_len); + uint16_t nfc_tx_len = (uint8_t) * (sam_rx_buf + 10); + memcpy(nfc_tx_buf, sam_rx_buf + 11, nfc_tx_len); return nfc_tx_len; } @@ -193,13 +193,13 @@ inline static uint16_t sam_seos_copy_payload_sam2nfc(uint8_t * nfc_tx_buf, uint8 * Unpacks request to the SAM and relays ISO14A traffic to the card. * If no request data provided, sends a request to get PACS data. * - * @param request Pointer to the buffer containing the request to be sent to the SAM. + * @param request Pointer to the buffer containing the request to be sent to the SAM. * @param request_len Length of the request to be sent to the SAM. * @param response Pointer to the buffer where the retreived data will be stored. * @param response_len Pointer to the variable where the length of the retreived data will be stored. * @return Status code indicating success or failure of the operation. */ -static int sam_send_request_iso14a(const uint8_t * const request, const uint8_t request_len, uint8_t * response, uint8_t * response_len){ +static int sam_send_request_iso14a(const uint8_t *const request, const uint8_t request_len, uint8_t *response, uint8_t *response_len) { int res = PM3_SUCCESS; if (g_dbglevel >= DBG_DEBUG) DbpString("start sam_send_request_iso14a"); @@ -207,22 +207,22 @@ static int sam_send_request_iso14a(const uint8_t * const request, const uint8_t uint8_t buf1[ISO7816_MAX_FRAME] = {0}; uint8_t buf2[ISO7816_MAX_FRAME] = {0}; - uint8_t * sam_tx_buf = buf1; + uint8_t *sam_tx_buf = buf1; uint16_t sam_tx_len; - uint8_t * sam_rx_buf = buf2; + uint8_t *sam_rx_buf = buf2; uint16_t sam_rx_len; - uint8_t * nfc_tx_buf = buf1; + uint8_t *nfc_tx_buf = buf1; uint16_t nfc_tx_len; - uint8_t * nfc_rx_buf = buf2; + uint8_t *nfc_rx_buf = buf2; uint16_t nfc_rx_len; - if(request_len > 0){ + if (request_len > 0) { sam_tx_len = request_len; memcpy(sam_tx_buf, request, sam_tx_len); - }else{ + } else { // send get pacs static const uint8_t payload[] = { 0xa0, 19, // <- SAM command @@ -243,23 +243,23 @@ static int sam_send_request_iso14a(const uint8_t * const request, const uint8_t sam_rx_buf, &sam_rx_len ); - if(sam_rx_buf[1] == 0x61){ // commands to be relayed to card starts with 0x61 + if (sam_rx_buf[1] == 0x61) { // commands to be relayed to card starts with 0x61 // tag <-> SAM exchange starts here - while(sam_rx_buf[1] == 0x61){ + while (sam_rx_buf[1] == 0x61) { switch_clock_to_countsspclk(); nfc_tx_len = sam_seos_copy_payload_sam2nfc(nfc_tx_buf, sam_rx_buf); nfc_rx_len = iso14_apdu( - nfc_tx_buf, - nfc_tx_len, - false, - nfc_rx_buf, - ISO7816_MAX_FRAME, - NULL - ); + nfc_tx_buf, + nfc_tx_len, + false, + nfc_rx_buf, + ISO7816_MAX_FRAME, + NULL + ); switch_clock_to_ticks(); - sam_tx_len = sam_seos_copy_payload_nfc2sam(sam_tx_buf, nfc_rx_buf, nfc_rx_len-2); + sam_tx_len = sam_seos_copy_payload_nfc2sam(sam_tx_buf, nfc_rx_buf, nfc_rx_len - 2); sam_send_payload( 0x14, 0x0a, 0x14, @@ -267,13 +267,13 @@ static int sam_send_request_iso14a(const uint8_t * const request, const uint8_t sam_rx_buf, &sam_rx_len ); - // last SAM->TAG + // last SAM->TAG // c1 61 c1 00 00 a1 02 >>82<< 00 90 00 - if(sam_rx_buf[7] == 0x82){ + if (sam_rx_buf[7] == 0x82) { // tag <-> SAM exchange ends here break; } - + } static const uint8_t hfack[] = { @@ -310,25 +310,25 @@ static int sam_send_request_iso14a(const uint8_t * const request, const uint8_t // 82 01 // 07 // 90 00 - if(request_len == 0){ - if( - !(sam_rx_buf[5] == 0xbd && sam_rx_buf[5+2] == 0x8a && sam_rx_buf[5+4] == 0x03) + if (request_len == 0) { + if ( + !(sam_rx_buf[5] == 0xbd && sam_rx_buf[5 + 2] == 0x8a && sam_rx_buf[5 + 4] == 0x03) && - !(sam_rx_buf[5] == 0xbd && sam_rx_buf[5+2] == 0xb3 && sam_rx_buf[5+4] == 0xa0) - ){ + !(sam_rx_buf[5] == 0xbd && sam_rx_buf[5 + 2] == 0xb3 && sam_rx_buf[5 + 4] == 0xa0) + ) { if (g_dbglevel >= DBG_ERROR) Dbprintf("No PACS data in SAM response"); - res=PM3_ESOFT; + res = PM3_ESOFT; } } - *response_len = sam_rx_buf[5+1] +2; - memcpy(response, sam_rx_buf+5, *response_len); + *response_len = sam_rx_buf[5 + 1] + 2; + memcpy(response, sam_rx_buf + 5, *response_len); goto out; - out: - return res; +out: + return res; } /** @@ -337,7 +337,7 @@ static int sam_send_request_iso14a(const uint8_t * const request, const uint8_t * This function is called by appmain.c * It sends a request to the SAM to get the PACS data from the SEOS card. * The PACS data is then returned to the PM3 client. - * + * * @return Status code indicating success or failure of the operation. */ int sam_seos_get_pacs(PacketCommandNG *c) { @@ -346,7 +346,7 @@ int sam_seos_get_pacs(PacketCommandNG *c) { uint8_t *cmd = c->data.asBytes; uint16_t cmd_len = (uint16_t) c->oldarg[2]; - + int res = PM3_EFAILED; clear_trace(); @@ -358,13 +358,13 @@ int sam_seos_get_pacs(PacketCommandNG *c) { // step 1: ping SAM sam_get_version(); - if(!skipDetect){ + if (!skipDetect) { // step 2: get card information iso14a_card_select_t card_a_info; // implicit StartSspClk() happens here iso14443a_setup(FPGA_HF_ISO14443A_READER_MOD); - if (!iso14443a_select_card(NULL, &card_a_info, NULL, true, 0, false)){ + if (!iso14443a_select_card(NULL, &card_a_info, NULL, true, 0, false)) { goto err; } @@ -378,7 +378,7 @@ int sam_seos_get_pacs(PacketCommandNG *c) { uint8_t sam_response[ISO7816_MAX_FRAME] = { 0x00 }; uint8_t sam_response_len = 0; res = sam_send_request_iso14a(cmd, cmd_len, sam_response, &sam_response_len); - if(res != PM3_SUCCESS){ + if (res != PM3_SUCCESS) { goto err; } if (g_dbglevel >= DBG_INFO) @@ -387,19 +387,19 @@ int sam_seos_get_pacs(PacketCommandNG *c) { goto out; goto off; - err: - res = PM3_ENOPACS; - reply_ng(CMD_HF_SAM_SEOS, res, NULL, 0); - goto off; - out: - reply_ng(CMD_HF_SAM_SEOS, PM3_SUCCESS, sam_response, sam_response_len); - goto off; - off: - if(disconnectAfter){ - switch_off(); - } - set_tracing(false); - StopTicks(); - BigBuf_free(); - return res; -} \ No newline at end of file +err: + res = PM3_ENOPACS; + reply_ng(CMD_HF_SAM_SEOS, res, NULL, 0); + goto off; +out: + reply_ng(CMD_HF_SAM_SEOS, PM3_SUCCESS, sam_response, sam_response_len); + goto off; +off: + if (disconnectAfter) { + switch_off(); + } + set_tracing(false); + StopTicks(); + BigBuf_free(); + return res; +} diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index ea53ebb83..60c24fb49 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -5434,15 +5434,15 @@ static int CmdHFiClassSAM(const char *Cmd) { // CSN, config, epurse, NR/MAC, AIA // PACS - // 03 05 + // 03 05 // 06 85 80 6d c0 // first byte skip // second byte length // third padded // fourth .. uint8_t *d = resp.data.asBytes; - HIDDumpPACSBits(d+2, d[1], verbose); - + HIDDumpPACSBits(d + 2, d[1], verbose); + return PM3_SUCCESS; } diff --git a/client/src/cmdhfseos.c b/client/src/cmdhfseos.c index c0a2891de..54e0ce550 100644 --- a/client/src/cmdhfseos.c +++ b/client/src/cmdhfseos.c @@ -1688,15 +1688,15 @@ static int CmdHfSeosSAM(const char *Cmd) { verbose = true; } bool disconnectAfter = true; - if(arg_get_lit(ctx, 2)){ + if (arg_get_lit(ctx, 2)) { disconnectAfter = false; } bool skipDetect = false; - if(arg_get_lit(ctx, 3)){ + if (arg_get_lit(ctx, 3)) { skipDetect = true; } bool decodeTLV = false; - if(arg_get_lit(ctx, 4)){ + if (arg_get_lit(ctx, 4)) { decodeTLV = true; } @@ -1728,45 +1728,45 @@ static int CmdHfSeosSAM(const char *Cmd) { PrintAndLogEx(WARNING, "SAM select failed"); return resp.status; } - + uint8_t *d = resp.data.asBytes; // check for standard SamCommandGetContentElement response // bd 09 // 8a 07 // 03 05 <- tag + length // 06 85 80 6d c0 <- decoded PACS data - if(d[0] == 0xbd && d[2] == 0x8a && d[4] == 0x03){ + if (d[0] == 0xbd && d[2] == 0x8a && d[4] == 0x03) { uint8_t pacs_length = d[5]; - uint8_t * pacs_data = d + 6; + uint8_t *pacs_data = d + 6; int res = HIDDumpPACSBits(pacs_data, pacs_length, verbose); - if(res != PM3_SUCCESS){ + if (res != PM3_SUCCESS) { return res; } - // check for standard samCommandGetContentElement2: - // bd 1e - // b3 1c - // a0 1a - // 80 05 - // 06 85 80 6d c0 - // 81 0e - // 2b 06 01 04 01 81 e4 38 01 01 02 04 3c ff - // 82 01 - // 07 - } else if(d[0]==0xbd && d[2]==0xb3 && d[4]==0xa0){ - const uint8_t * pacs = d + 6; + // check for standard samCommandGetContentElement2: + // bd 1e + // b3 1c + // a0 1a + // 80 05 + // 06 85 80 6d c0 + // 81 0e + // 2b 06 01 04 01 81 e4 38 01 01 02 04 3c ff + // 82 01 + // 07 + } else if (d[0] == 0xbd && d[2] == 0xb3 && d[4] == 0xa0) { + const uint8_t *pacs = d + 6; const uint8_t pacs_length = pacs[1]; - const uint8_t * pacs_data = pacs + 2; + const uint8_t *pacs_data = pacs + 2; int res = HIDDumpPACSBits(pacs_data, pacs_length, verbose); - if(res != PM3_SUCCESS){ + if (res != PM3_SUCCESS) { return res; } - const uint8_t * oid = pacs + 2 + pacs_length; + const uint8_t *oid = pacs + 2 + pacs_length; const uint8_t oid_length = oid[1]; - const uint8_t * oid_data = oid + 2; + const uint8_t *oid_data = oid + 2; PrintAndLogEx(SUCCESS, "SIO OID.......: " _GREEN_("%s"), sprint_hex_inrow(oid_data, oid_length)); - const uint8_t * mediaType = oid + 2 + oid_length; + const uint8_t *mediaType = oid + 2 + oid_length; const uint8_t mediaType_data = mediaType[2]; PrintAndLogEx(SUCCESS, "SIO Media Type: " _GREEN_("%s"), getSioMediaTypeInfo(mediaType_data)); diff --git a/client/src/cmdhfseos.h b/client/src/cmdhfseos.h index 950346c04..f75e070d5 100644 --- a/client/src/cmdhfseos.h +++ b/client/src/cmdhfseos.h @@ -29,6 +29,6 @@ typedef struct { int infoSeos(bool verbose); int CmdHFSeos(const char *Cmd); -int seos_kdf(bool encryption, uint8_t* masterKey, uint8_t keyslot, - uint8_t* adfOid, size_t adfoid_len, uint8_t* diversifier, uint8_t diversifier_len, uint8_t* out, int encryption_algorithm, int hash_algorithm); +int seos_kdf(bool encryption, uint8_t *masterKey, uint8_t keyslot, + uint8_t *adfOid, size_t adfoid_len, uint8_t *diversifier, uint8_t diversifier_len, uint8_t *out, int encryption_algorithm, int hash_algorithm); #endif diff --git a/client/src/wiegand_formats.c b/client/src/wiegand_formats.c index ecbf47000..e3e146153 100644 --- a/client/src/wiegand_formats.c +++ b/client/src/wiegand_formats.c @@ -1664,7 +1664,7 @@ void HIDUnpack(int idx, wiegand_message_t *packed) { } } -int HIDDumpPACSBits(const uint8_t * const data, const uint8_t length, bool verbose){ +int HIDDumpPACSBits(const uint8_t *const data, const uint8_t length, bool verbose) { uint8_t n = length - 1; uint8_t pad = data[0]; char *binstr = (char *)calloc((length * 8) + 1, sizeof(uint8_t)); @@ -1733,5 +1733,5 @@ int HIDDumpPACSBits(const uint8_t * const data, const uint8_t length, bool verbo PrintAndLogEx(NORMAL, ""); } free(binstr); - return PM3_SUCCESS; -} \ No newline at end of file + return PM3_SUCCESS; +} diff --git a/client/src/wiegand_formats.h b/client/src/wiegand_formats.h index 763edaba8..630d9cbb4 100644 --- a/client/src/wiegand_formats.h +++ b/client/src/wiegand_formats.h @@ -54,7 +54,7 @@ bool HIDPack(int format_idx, wiegand_card_t *card, wiegand_message_t *packed, bo bool HIDTryUnpack(wiegand_message_t *packed); void HIDPackTryAll(wiegand_card_t *card, bool preamble); void HIDUnpack(int idx, wiegand_message_t *packed); -int HIDDumpPACSBits(const uint8_t * const data, const uint8_t length, bool verbose); +int HIDDumpPACSBits(const uint8_t *const data, const uint8_t length, bool verbose); void print_wiegand_code(wiegand_message_t *packed); void print_desc_wiegand(cardformat_t *fmt, wiegand_message_t *packed); #endif diff --git a/common_arm/ticks.c b/common_arm/ticks.c index c078407ea..4abda2689 100644 --- a/common_arm/ticks.c +++ b/common_arm/ticks.c @@ -305,7 +305,7 @@ uint32_t GetTicks(void) { do { hi = AT91C_BASE_TC1->TC_CV; lo = AT91C_BASE_TC0->TC_CV; - } while (hi != AT91C_BASE_TC1->TC_CV); + } while (hi != AT91C_BASE_TC1->TC_CV); return (hi << 16) | lo; }