Skip to content

Commit

Permalink
armsrc/sam_common.c: type cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jkramarz committed Jan 5, 2025
1 parent 016dd60 commit 0d78218
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
28 changes: 12 additions & 16 deletions armsrc/sam_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@


#include <string.h>
// #include "sam_picopass.h"
#include "sam_common.h"
#include "iclass.h"
// #include "crc16.h"
#include "proxmark3_arm.h"
#include "BigBuf.h"
// #include "cmd.h"
#include "commonutil.h"
#include "ticks.h"
#include "dbprint.h"
#include "i2c.h"
#include "iso15693.h"
#include "protocols.h"
// #include "optimized_cipher.h"
// #include "fpgaloader.h"


/**
* @brief Transmits data to and receives data from a HID®'s iCLASS® SE™ Processor.
Expand Down Expand Up @@ -155,12 +151,12 @@ void switch_clock_to_countsspclk(void){
* @return Status code indicating success or failure of the operation.
*/
int sam_send_payload(
uint8_t addr_src,
uint8_t addr_dest,
uint8_t addr_reply,
const uint8_t addr_src,
const uint8_t addr_dest,
const uint8_t addr_reply,

uint8_t *payload,
uint16_t *payload_len,
const uint8_t * const payload,
const uint16_t *payload_len,

uint8_t *response,
uint16_t *response_len
Expand Down Expand Up @@ -314,9 +310,9 @@ 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(uint8_t * root, const uint8_t type){
const uint8_t * end = root + *(root+1);
uint8_t * current = root + 2;
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;
Expand All @@ -343,14 +339,14 @@ uint8_t * sam_find_asn1_node(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(uint8_t * root, uint8_t * node, uint8_t type, uint8_t * data, uint8_t len){
uint8_t * end = 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);

for(uint8_t * current = root; current <= node; current += 2){
for(uint8_t * current = (uint8_t *) root; current <= node; current += 2){
*(current+1) += 2 + len;
};
return;
Expand Down
14 changes: 7 additions & 7 deletions armsrc/sam_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ void switch_clock_to_ticks(void);
void switch_clock_to_countsspclk(void);

int sam_send_payload(
uint8_t addr_src,
uint8_t addr_dest,
uint8_t addr_reply,
const uint8_t addr_src,
const uint8_t addr_dest,
const uint8_t addr_reply,

uint8_t *payload,
uint16_t *payload_len,
const uint8_t * const payload,
const uint16_t *payload_len,

uint8_t *response,
uint16_t *response_len
);

int sam_get_version(void);

uint8_t * sam_find_asn1_node(uint8_t * root, const uint8_t type);
void sam_append_asn1_node(uint8_t * root, uint8_t * node, uint8_t type, uint8_t * 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);

Expand Down
2 changes: 1 addition & 1 deletion armsrc/sam_picopass.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int sam_picopass_get_pacs(void) {
// 80 01
// 04
hexstr_to_byte_array("a005a103800104", sam_apdu, &sam_len);
if(sam_send_payload(0x44, 0x0a, 0x44, sam_apdu, &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;
}
Expand Down
2 changes: 1 addition & 1 deletion armsrc/sam_seos.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static int sam_set_card_detected(iso14a_card_select_t * card_select){
uint8_t * response = BigBuf_malloc(ISO7816_MAX_FRAME);
uint16_t response_len = ISO7816_MAX_FRAME;

uint8_t payload[] = {
const uint8_t payload[] = {
0xa0, 8, // <- SAM command
0xad, 6, // <- set detected card
0xa0, 4, // <- detected card details
Expand Down

0 comments on commit 0d78218

Please sign in to comment.