mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-09 17:56:53 +08:00
added new tlv function
This commit is contained in:
parent
a5f8454168
commit
723298d00c
2 changed files with 41 additions and 0 deletions
|
@ -25,6 +25,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define TLV_TAG_CLASS_MASK 0xc0
|
||||
#define TLV_TAG_COMPLEX 0x20
|
||||
|
@ -534,3 +535,40 @@ struct tlvdb *tlvdb_elm_get_parent(struct tlvdb *tlvdb)
|
|||
{
|
||||
return tlvdb->parent;
|
||||
}
|
||||
|
||||
bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value)
|
||||
{
|
||||
*value = 0;
|
||||
if (etlv)
|
||||
{
|
||||
if (etlv->len == 0)
|
||||
return true;
|
||||
|
||||
if (etlv->len == 1)
|
||||
{
|
||||
*value = etlv->value[0];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool tlv_get_int(const struct tlv *etlv, int *value)
|
||||
{
|
||||
*value = 0;
|
||||
if (etlv)
|
||||
{
|
||||
if (etlv->len == 0)
|
||||
return true;
|
||||
|
||||
if (etlv->len <= 4)
|
||||
{
|
||||
for (int i = 0; i < etlv->len; i++)
|
||||
{
|
||||
*value += etlv->value[i] * pow(0x100, i);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -61,4 +61,7 @@ unsigned char *tlv_encode(const struct tlv *tlv, size_t *len);
|
|||
bool tlv_is_constructed(const struct tlv *tlv);
|
||||
bool tlv_equal(const struct tlv *a, const struct tlv *b);
|
||||
|
||||
bool tlv_get_uint8(const struct tlv *etlv, uint8_t *value);
|
||||
bool tlv_get_int(const struct tlv *etlv, int *value);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue