diff --git a/lib/asn1/NoArguments.c b/lib/asn1/NoArguments.c new file mode 100644 index 0000000..bb72ca0 --- /dev/null +++ b/lib/asn1/NoArguments.c @@ -0,0 +1,31 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "Seader" + * found in "seader.asn1" + * `asn1c -D ./lib/asn1 -no-gen-example -pdu=all` + */ + +#include "NoArguments.h" + +/* + * This type is implemented using NULL, + * so here we adjust the DEF accordingly. + */ +static const ber_tlv_tag_t asn_DEF_NoArguments_tags_1[] = { + (ASN_TAG_CLASS_UNIVERSAL | (5 << 2)) +}; +asn_TYPE_descriptor_t asn_DEF_NoArguments = { + "NoArguments", + "NoArguments", + &asn_OP_NULL, + asn_DEF_NoArguments_tags_1, + sizeof(asn_DEF_NoArguments_tags_1) + /sizeof(asn_DEF_NoArguments_tags_1[0]), /* 1 */ + asn_DEF_NoArguments_tags_1, /* Same as above */ + sizeof(asn_DEF_NoArguments_tags_1) + /sizeof(asn_DEF_NoArguments_tags_1[0]), /* 1 */ + { 0, 0, NULL_constraint }, + 0, 0, /* No members */ + 0 /* No specifics */ +}; + diff --git a/lib/asn1/NoArguments.h b/lib/asn1/NoArguments.h new file mode 100644 index 0000000..153a001 --- /dev/null +++ b/lib/asn1/NoArguments.h @@ -0,0 +1,43 @@ +/* + * Generated by asn1c-0.9.29 (http://lionet.info/asn1c) + * From ASN.1 module "Seader" + * found in "seader.asn1" + * `asn1c -D ./lib/asn1 -no-gen-example -pdu=all` + */ + +#ifndef _NoArguments_H_ +#define _NoArguments_H_ + + +#include + +/* Including external dependencies */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* NoArguments */ +typedef NULL_t NoArguments_t; + +/* Implementation */ +extern asn_TYPE_descriptor_t asn_DEF_NoArguments; +asn_struct_free_f NoArguments_free; +asn_struct_print_f NoArguments_print; +asn_constr_check_f NoArguments_constraint; +ber_type_decoder_f NoArguments_decode_ber; +der_type_encoder_f NoArguments_encode_der; +xer_type_decoder_f NoArguments_decode_xer; +xer_type_encoder_f NoArguments_encode_xer; +oer_type_decoder_f NoArguments_decode_oer; +oer_type_encoder_f NoArguments_encode_oer; +per_type_decoder_f NoArguments_decode_uper; +per_type_encoder_f NoArguments_encode_uper; + +#ifdef __cplusplus +} +#endif + +#endif /* _NoArguments_H_ */ +#include diff --git a/lib/asn1/SamCommand.c b/lib/asn1/SamCommand.c index 6616330..76f03a6 100644 --- a/lib/asn1/SamCommand.c +++ b/lib/asn1/SamCommand.c @@ -11,7 +11,7 @@ static asn_oer_constraints_t asn_OER_type_SamCommand_constr_1 CC_NOTUSED = { { 0, 0 }, -1}; asn_per_constraints_t asn_PER_type_SamCommand_constr_1 CC_NOTUSED = { - { APC_CONSTRAINED, 2, 2, 0, 2 } /* (0..2) */, + { APC_CONSTRAINED, 2, 2, 0, 3 } /* (0..3) */, { APC_UNCONSTRAINED, -1, -1, 0, 0 }, 0, 0 /* No PER value map */ }; @@ -43,11 +43,21 @@ asn_TYPE_member_t asn_MBR_SamCommand_1[] = { 0, 0, /* No default value */ "cardDetected" }, + { ATF_NOFLAGS, 0, offsetof(struct SamCommand, choice.serialNumber), + (ASN_TAG_CLASS_CONTEXT | (22 << 2)), + -1, /* IMPLICIT tag at current level */ + &asn_DEF_NoArguments, + 0, + { 0, 0, 0 }, + 0, 0, /* No default value */ + "serialNumber" + }, }; static const asn_TYPE_tag2member_t asn_MAP_SamCommand_tag2el_1[] = { { (ASN_TAG_CLASS_CONTEXT | (1 << 2)), 0, 0, 0 }, /* requestPacs */ { (ASN_TAG_CLASS_CONTEXT | (2 << 2)), 1, 0, 0 }, /* version */ - { (ASN_TAG_CLASS_CONTEXT | (13 << 2)), 2, 0, 0 } /* cardDetected */ + { (ASN_TAG_CLASS_CONTEXT | (13 << 2)), 2, 0, 0 }, /* cardDetected */ + { (ASN_TAG_CLASS_CONTEXT | (22 << 2)), 3, 0, 0 } /* serialNumber */ }; asn_CHOICE_specifics_t asn_SPC_SamCommand_specs_1 = { sizeof(struct SamCommand), @@ -55,7 +65,7 @@ asn_CHOICE_specifics_t asn_SPC_SamCommand_specs_1 = { offsetof(struct SamCommand, present), sizeof(((struct SamCommand *)0)->present), asn_MAP_SamCommand_tag2el_1, - 3, /* Count of tags in the map */ + 4, /* Count of tags in the map */ 0, 0, -1 /* Extensions start */ }; @@ -69,7 +79,7 @@ asn_TYPE_descriptor_t asn_DEF_SamCommand = { 0, /* No tags (count) */ { &asn_OER_type_SamCommand_constr_1, &asn_PER_type_SamCommand_constr_1, CHOICE_constraint }, asn_MBR_SamCommand_1, - 3, /* Elements count */ + 4, /* Elements count */ &asn_SPC_SamCommand_specs_1 /* Additional specs */ }; diff --git a/lib/asn1/SamCommand.h b/lib/asn1/SamCommand.h index 7d902c7..1b9bd36 100644 --- a/lib/asn1/SamCommand.h +++ b/lib/asn1/SamCommand.h @@ -15,6 +15,7 @@ #include "RequestPacs.h" #include #include "CardDetected.h" +#include "NoArguments.h" #include #ifdef __cplusplus @@ -26,7 +27,8 @@ typedef enum SamCommand_PR { SamCommand_PR_NOTHING, /* No components present */ SamCommand_PR_requestPacs, SamCommand_PR_version, - SamCommand_PR_cardDetected + SamCommand_PR_cardDetected, + SamCommand_PR_serialNumber } SamCommand_PR; /* SamCommand */ @@ -36,6 +38,7 @@ typedef struct SamCommand { RequestPacs_t requestPacs; NULL_t version; CardDetected_t cardDetected; + NoArguments_t serialNumber; } choice; /* Context for parsing across buffer boundaries */ @@ -45,7 +48,7 @@ typedef struct SamCommand { /* Implementation */ extern asn_TYPE_descriptor_t asn_DEF_SamCommand; extern asn_CHOICE_specifics_t asn_SPC_SamCommand_specs_1; -extern asn_TYPE_member_t asn_MBR_SamCommand_1[3]; +extern asn_TYPE_member_t asn_MBR_SamCommand_1[4]; extern asn_per_constraints_t asn_PER_type_SamCommand_constr_1; #ifdef __cplusplus diff --git a/sam_api.c b/sam_api.c index c567a26..f73f93c 100644 --- a/sam_api.c +++ b/sam_api.c @@ -258,6 +258,27 @@ void sendRequestPacs(SeaderUartBridge* seader_uart) { ASN_STRUCT_FREE(asn_DEF_Payload, payload); } +void seader_worker_send_serial_number(SeaderWorker* seader_worker) { + SeaderUartBridge* seader_uart = seader_worker->uart; + SamCommand_t* samCommand = 0; + samCommand = calloc(1, sizeof *samCommand); + assert(samCommand); + + samCommand->present = SamCommand_PR_serialNumber; + + Payload_t* payload = 0; + payload = calloc(1, sizeof *payload); + assert(payload); + + payload->present = Payload_PR_samCommand; + payload->choice.samCommand = *samCommand; + + seader_send_payload(seader_uart, payload, 0x44, 0x0a, 0x44); + + ASN_STRUCT_FREE(asn_DEF_SamCommand, samCommand); + ASN_STRUCT_FREE(asn_DEF_Payload, payload); +} + void seader_worker_send_version(SeaderWorker* seader_worker) { SeaderUartBridge* seader_uart = seader_worker->uart; SamCommand_t* samCommand = 0; @@ -386,7 +407,7 @@ bool seader_parse_version(SeaderWorker* seader_worker, uint8_t* buf, size_t size ->op->print_struct( &asn_DEF_SamVersion, version, 1, seader_print_struct_callback, versionDebug); if(strlen(versionDebug) > 0) { - // FURI_LOG_D(TAG, "Received version: %s", versionDebug); + FURI_LOG_D(TAG, "Received version: %s", versionDebug); } if(version->version.size == 2) { memcpy(seader_worker->sam_version, version->version.buf, version->version.size); @@ -399,6 +420,16 @@ bool seader_parse_version(SeaderWorker* seader_worker, uint8_t* buf, size_t size return rtn; } +bool seader_parse_serial_number(uint8_t* buf, size_t size) { + memset(display, 0, sizeof(display)); + for(uint8_t i = 0; i < size; i++) { + snprintf(display + (i * 2), sizeof(display), "%02x", buf[i]); + } + + FURI_LOG_D(TAG, "Received serial: %s", display); + return (size == 12); +} + bool seader_parse_sam_response(Seader* seader, SamResponse_t* samResponse) { SeaderWorker* seader_worker = seader->worker; SeaderUartBridge* seader_uart = seader_worker->uart; @@ -415,6 +446,8 @@ bool seader_parse_sam_response(Seader* seader, SamResponse_t* samResponse) { seader->view_dispatcher, SeaderCustomEventWorkerExit); } } else if(seader_parse_version(seader_worker, samResponse->buf, samResponse->size)) { + seader_worker_send_serial_number(seader_worker); + } else if(seader_parse_serial_number(samResponse->buf, samResponse->size)) { // no-op } else if(seader_unpack_pacs(seader, samResponse->buf, samResponse->size)) { view_dispatcher_send_custom_event(seader->view_dispatcher, SeaderCustomEventPollerSuccess); diff --git a/seader.asn1 b/seader.asn1 index 2cca596..668aaa4 100644 --- a/seader.asn1 +++ b/seader.asn1 @@ -6,6 +6,7 @@ RfStatus ::= OCTET STRING SamResponse ::= OCTET STRING -- omnikey_5326_dfr_softwaredeveloperguide 4.2 PAC ::= BIT STRING +NoArguments ::= NULL -- omnikey_5326_dfr_softwaredeveloperguide 3.3 Payload ::= CHOICE { @@ -23,7 +24,8 @@ ErrorResponse ::= SEQUENCE { SamCommand ::= CHOICE { requestPacs [1] IMPLICIT RequestPacs, version [2] IMPLICIT NULL, - cardDetected [13] IMPLICIT CardDetected + cardDetected [13] IMPLICIT CardDetected, + serialNumber [22] IMPLICIT NoArguments } CardDetected ::= SEQUENCE {