Branch data Line data Source code
1 : : #include <stdlib.h>
2 : : #include <string.h>
3 : : #include <glib.h>
4 : :
5 : : #include "vcardt.h"
6 : :
7 : : #include "vcardt_internal.h"
8 : :
9 : : /* create an ATR with appropriate historical bytes */
10 : : #define ATR_TS_DIRECT_CONVENTION 0x3b
11 : : #define ATR_TA_PRESENT 0x10
12 : : #define ATR_TB_PRESENT 0x20
13 : : #define ATR_TC_PRESENT 0x40
14 : : #define ATR_TD_PRESENT 0x80
15 : :
16 : 1 : unsigned char *vcard_alloc_atr(const char *postfix, int *atr_len)
17 : : {
18 : : int postfix_len;
19 : 1 : const char prefix[] = "VCARD_";
20 : 1 : const char default_postfix[] = "DEFAULT";
21 : : const int prefix_len = sizeof(prefix) - 1;
22 : : int total_len;
23 : : unsigned char *atr;
24 : :
25 [ - + ]: 1 : if (postfix == NULL) {
26 : : postfix = default_postfix;
27 : : }
28 : 1 : postfix_len = strlen(postfix);
29 : 1 : total_len = 3 + prefix_len + postfix_len;
30 : 1 : atr = g_malloc(total_len);
31 : 1 : atr[0] = ATR_TS_DIRECT_CONVENTION;
32 : 1 : atr[1] = ATR_TD_PRESENT + prefix_len + postfix_len;
33 : 1 : atr[2] = 0x00;
34 : 1 : memcpy(&atr[3], prefix, prefix_len);
35 : 1 : memcpy(&atr[3 + prefix_len], postfix, postfix_len);
36 [ + - ]: 1 : if (atr_len) {
37 : 1 : *atr_len = total_len;
38 : : }
39 : 1 : return atr;
40 : : }
|