Skip to content

Commit 6c961d3

Browse files
committed
Initial commit.
0 parents commit 6c961d3

File tree

18 files changed

+1767
-0
lines changed

18 files changed

+1767
-0
lines changed

inc/byteorder.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#ifndef __BYTEORDER__H__
2+
#define __BYTEORDER__H__
3+
4+
#include "tlv_types.h"
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
#define BIG_ENDIAN_PLATFORM 1
11+
#define LITTLE_ENDIAN_PLATFORM 0
12+
13+
#define TAG_LENGTH_ENDIAN BIG_ENDIAN_PLATFORM
14+
15+
#define BSWAP_32(x) \
16+
(tlv_uint32_t)((((tlv_uint32_t)(x) & 0xff000000) >> 24) | \
17+
(((tlv_uint32_t)(x) & 0x00ff0000) >> 8) | \
18+
(((tlv_uint32_t)(x) & 0x0000ff00) << 8) | \
19+
(((tlv_uint32_t)(x) & 0x000000ff) << 24) \
20+
)
21+
22+
#define BSWAP_16(x) (tlv_uint16_t)((((tlv_uint16_t)(x) & 0xff00) >> 8) | (((tlv_uint16_t)(x) & 0x00ff) << 8))
23+
24+
25+
#ifdef __cplusplus
26+
}
27+
#endif
28+
29+
#endif

inc/key_list.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 __KEY_LIST_H__
14+
#define __KEY_LIST_H__
15+
16+
17+
#include "tlv_types.h"
18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
22+
typedef struct _value {
23+
void *value;
24+
} value_t;
25+
26+
typedef void (*value_releaser)(value_t value);
27+
28+
#define key_compare(a, b) ((a==b)?1:0)
29+
30+
typedef struct key_list_node {
31+
tlv_int32_t key;
32+
value_t value;
33+
struct key_list_node *prev;
34+
struct key_list_node *next;
35+
} key_list_node_t;
36+
37+
typedef struct key_list {
38+
tlv_uint32_t count;
39+
key_list_node_t *header;
40+
value_releaser releaser;
41+
} key_list_t;
42+
43+
key_list_t *key_list_create(value_releaser releaser);
44+
tlv_bool_t key_list_destroy(key_list_t *list);
45+
46+
tlv_uint32_t key_list_count(key_list_t *list);
47+
tlv_int32_t key_list_keyset(key_list_t *list, tlv_int32_t* array, tlv_uint32_t array_size);
48+
tlv_bool_t key_list_find_key(key_list_t *list, tlv_int32_t key);
49+
50+
tlv_bool_t key_list_add(key_list_t *list, tlv_int32_t key, value_t value);
51+
tlv_bool_t key_list_get(key_list_t *list, tlv_int32_t key, value_t *value);
52+
tlv_bool_t key_list_edit(key_list_t *list, tlv_int32_t key, value_t value);
53+
tlv_bool_t key_list_delete(key_list_t *list, tlv_int32_t key);
54+
55+
56+
#ifdef __cplusplus
57+
}
58+
#endif
59+
60+
#endif

inc/tlv.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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

inc/tlv_iostream.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef __TLV_IOSTREAM_H__
2+
#define __TLV_IOSTREAM_H__
3+
4+
#include "tlv_types.h"
5+
#include "tlv.h"
6+
#include "serial.h"
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
typedef struct _send_data
13+
{
14+
tlv_uint8_t *pdata;
15+
tlv_uint32_t data_len;
16+
tlv_uint16_t tage;
17+
}send_data_type;
18+
19+
tlv_uint32_t tlv_init(uart_port_e port, uart_cfg_t *config, tlv_parse_callback parse_cb, tlv_uint16_t * tags_buff, tlv_uint16_t tags_num);
20+
tlv_base_t *tlv_get_value(tlv_uint32_t tlv);
21+
void tlv_dest_value(tlv_uint32_t tlv);
22+
tlv_error_t tlv_send(tlv_uint32_t tlv, send_data_type *send_data_array, tlv_uint16_t array_len);
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif
27+
28+
#endif

port/JL/memory.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) Quectel Wireless Solution, Co., Ltd.All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
/*
19+
@file :memory.c
20+
@author :Chavis Chen (chavis.chen@quectel.com)
21+
@brief :This file shows the platform memory interface
22+
@version :0.1
23+
@date :2023-12-14 13:14:44
24+
@copyright :Copyright (c) 2022
25+
*/
26+
27+
#include <stdlib.h>
28+
#include <string.h>
29+
#include "tlv_types.h"
30+
31+
void *platform_memory_alloc(tlv_uint32_t size)
32+
{
33+
void *ptr = malloc(size);
34+
35+
if (ptr)
36+
{
37+
memset(ptr, 0, size);
38+
return ptr;
39+
}
40+
else
41+
{
42+
return NULL;
43+
}
44+
}
45+
46+
void *platform_memory_calloc(tlv_uint32_t num, tlv_uint32_t size)
47+
{
48+
void *ptr = malloc(num * size);
49+
50+
if (ptr)
51+
{
52+
memset(ptr, 0, size);
53+
return ptr;
54+
}
55+
else
56+
{
57+
return NULL;
58+
}
59+
}
60+
61+
void platform_memory_free(void *ptr)
62+
{
63+
free(ptr);
64+
}

0 commit comments

Comments
 (0)