Add qemu 2.4.0
[kvmfornfv.git] / qemu / libcacard / vcardt.c
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 unsigned char *vcard_alloc_atr(const char *postfix, int *atr_len)
17 {
18     int postfix_len;
19     const char prefix[] = "VCARD_";
20     const char default_postfix[] = "DEFAULT";
21     const int prefix_len = sizeof(prefix) - 1;
22     int total_len;
23     unsigned char *atr;
24
25     if (postfix == NULL) {
26         postfix = default_postfix;
27     }
28     postfix_len = strlen(postfix);
29     total_len = 3 + prefix_len + postfix_len;
30     atr = g_malloc(total_len);
31     atr[0] = ATR_TS_DIRECT_CONVENTION;
32     atr[1] = ATR_TD_PRESENT + prefix_len + postfix_len;
33     atr[2] = 0x00;
34     memcpy(&atr[3], prefix, prefix_len);
35     memcpy(&atr[3 + prefix_len], postfix, postfix_len);
36     if (atr_len) {
37         *atr_len = total_len;
38     }
39     return atr;
40 }