|
| 1 | +/* |
| 2 | + * COPYRIGHT NOTICE |
| 3 | + * Copyright (C) 2015, Jhuster, All Rights Reserved |
| 4 | + * Author: Jhuster(lujun.hust@gmail.com) |
| 5 | + * |
| 6 | + * https://github.com/Jhuster/TLV |
| 7 | + * |
| 8 | + * This library is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU Lesser General Public License as published |
| 10 | + * by the Free Software Foundation; either version 2.1 of the License, |
| 11 | + * or (at your option) any later version. |
| 12 | + */ |
| 13 | +#ifndef __TLV_BOX_H__ |
| 14 | +#define __TLV_BOX_H__ |
| 15 | + |
| 16 | +#include "key_list.h" |
| 17 | +#include "tlv_types.h" |
| 18 | + |
| 19 | +#ifdef __cplusplus |
| 20 | +extern "C" { |
| 21 | +#endif |
| 22 | + |
| 23 | +#define EMV_TAGS_LENTH 146 |
| 24 | + |
| 25 | +typedef struct _tlv_base |
| 26 | +{ |
| 27 | + tlv_uint16_t tag; |
| 28 | + tlv_uint16_t length; |
| 29 | + tlv_uint8_t *value; |
| 30 | +} tlv_base_t; |
| 31 | + |
| 32 | +typedef enum _tlv_error |
| 33 | +{ |
| 34 | + NO_ERROR = 0, |
| 35 | + NOT_INITIALIZED = -1, |
| 36 | + TAG_BAD_VAL = -2, |
| 37 | + TAG_IS_INSUFF = -3, |
| 38 | + LEN_IS_INSUFF = -4, |
| 39 | + VAL_IS_INSUFF = -5, |
| 40 | + VAL_IS_OVERFLOW = -6, |
| 41 | + BUF_IS_NULL = -7, |
| 42 | +ALLOC_MEMORY_ERROR = -8, |
| 43 | + LIST_OPERATION_ERR = -9, |
| 44 | + SER_BUFF_NOT_NULL = -10, |
| 45 | + CROSS_REF_DATA = -11, |
| 46 | + PARAMS_ERROR = -12, |
| 47 | +} tlv_error_t; |
| 48 | + |
| 49 | +typedef void (* tlv_parse_callback)(tlv_uint32_t tlv, |
| 50 | + tlv_error_t error_num, |
| 51 | +tlv_uint8_t *original_data, |
| 52 | +tlv_uint32_t original_data_len, |
| 53 | +tlv_uint32_t parse_positon); |
| 54 | + |
| 55 | +typedef struct _tlv_box |
| 56 | +{ |
| 57 | + key_list_t *m_list; |
| 58 | + tlv_uint8_t *m_serialized_buffer; |
| 59 | + tlv_uint32_t m_serialized_bytes; |
| 60 | + tlv_uint16_t *m_tags_buffer; |
| 61 | + tlv_uint16_t m_tags_number; |
| 62 | + tlv_uint32_t m_parse_positon; |
| 63 | +tlv_parse_callback m_parse_cb; |
| 64 | +} tlv_box_t; |
| 65 | + |
| 66 | +extern tlv_uint16_t emv_tags[EMV_TAGS_LENTH]; |
| 67 | + |
| 68 | +tlv_box_t *tlv_box_create(void); |
| 69 | +tlv_error_t tlv_parse(tlv_box_t *box, tlv_uint8_t *buffer, tlv_uint32_t buffersize, tlv_uint8_t byteorder); |
| 70 | +tlv_error_t tlv_box_destroy(tlv_box_t *box); |
| 71 | +tlv_uint8_t *tlv_box_get_buffer(tlv_box_t *box); |
| 72 | +tlv_int32_t tlv_box_get_size(tlv_box_t *box); |
| 73 | +tlv_error_t tlv_set_tags(tlv_box_t *box, tlv_uint16_t * tags_buff, tlv_uint16_t tags_num); |
| 74 | +tlv_base_t *tlv_box_get_value(tlv_box_t *box); |
| 75 | +void tlv_box_dest_value(tlv_box_t *box); |
| 76 | +tlv_int16_t tlv_box_get_lenth(tlv_box_t *box, tlv_uint16_t tag); |
| 77 | +tlv_error_t tlv_set_value(tlv_box_t *box, tlv_uint16_t tag, void *value, tlv_uint16_t length); |
| 78 | +tlv_error_t tlv_box_serialize(tlv_box_t *box, tlv_uint8_t byteorder); |
| 79 | + |
| 80 | +#ifdef __cplusplus |
| 81 | +} |
| 82 | +#endif |
| 83 | + |
| 84 | +#endif |
0 commit comments