cpu_ldst.h: Allow NB_MMU_MODES to be 7
[qemu/ar7.git] / libcacard / vcardt.c
blob9ce4648f8caf0fceb5399cd6004b58437fd0b8e4
1 #include <stdlib.h>
2 #include <string.h>
3 #include <glib.h>
5 #include "libcacard/vcardt.h"
7 #include "libcacard/vcardt_internal.h"
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
16 unsigned char *vcard_alloc_atr(const char *postfix, int *atr_len)
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;
25 if (postfix == NULL) {
26 postfix = default_postfix;
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;
39 return atr;