2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <Commons/Exception.h>
22 #include <dpl/log/log.h>
30 using namespace Api::NFC;
32 std::vector<unsigned char> NFCUtil::toVector(const unsigned char *ch, const int size) {
33 std::vector<unsigned char> vec;
34 if (ch && (size > 0)) {
37 for (i = 0; i < size; i++)
40 LogDebug("result:" << byteToString(ch, size));
44 unsigned char *NFCUtil::toCharPtr(std::vector<unsigned char> vec) {
46 unsigned char * chr = (unsigned char *) malloc(vec.size() * sizeof(unsigned char));
47 for (int i = 0; i < static_cast<int>(vec.size()); i++)
56 char *NFCUtil::byteToString(std::vector<unsigned char> buffer){
57 static char localbuffer[255];
58 memset(localbuffer, 0, 255);
59 memcpy(localbuffer, toCharPtr(buffer), buffer.size());
63 char *NFCUtil::byteToString(const unsigned char* buffer, const int size){
64 static char localbuffer[255];
65 memset(localbuffer, 0, 255);
66 memcpy(localbuffer, buffer, size);
70 nfcTagType NFCUtil::convertTonfcTagType(const unsigned short type) {
71 switch (static_cast<nfc_tag_type_e>(type)) {
72 case NFC_GENERIC_PICC:
73 return NFC_TAGTYPE_GENERIC_PICC;
74 case NFC_ISO14443_A_PICC:
75 return NFC_TAGTYPE_ISO14443_A_PICC;
76 case NFC_ISO14443_4A_PICC:
77 return NFC_TAGTYPE_ISO14443_4A_PICC;
78 case NFC_ISO14443_3A_PICC:
79 return NFC_TAGTYPE_ISO14443_3A_PICC;
80 case NFC_MIFARE_MINI_PICC:
81 return NFC_TAGTYPE_MIFARE_MINI_PICC;
82 case NFC_MIFARE_1K_PICC:
83 return NFC_TAGTYPE_MIFARE_1K_PICC;
84 case NFC_MIFARE_4K_PICC:
85 return NFC_TAGTYPE_MIFARE_4K_PICC;
86 case NFC_MIFARE_ULTRA_PICC:
87 return NFC_TAGTYPE_MIFARE_ULTRA_PICC;
88 case NFC_MIFARE_DESFIRE_PICC:
89 return NFC_TAGTYPE_MIFARE_DESFIRE_PICC;
90 case NFC_ISO14443_B_PICC:
91 return NFC_TAGTYPE_ISO14443_B_PICC;
92 case NFC_ISO14443_4B_PICC:
93 return NFC_TAGTYPE_ISO14443_4B_PICC;
94 case NFC_ISO14443_BPRIME_PICC:
95 return NFC_TAGTYPE_ISO14443_BPRIME_PICC;
97 return NFC_TAGTYPE_FELICA_PICC;
99 return NFC_TAGTYPE_JEWEL_PICC;
100 case NFC_ISO15693_PICC:
101 return NFC_TAGTYPE_ISO15693_PICC;
102 case NFC_UNKNOWN_TARGET:
104 return NFC_TAGTYPE_UNKNOWN_TARGET;
108 unsigned short NFCUtil::convertToTNF(nfcTNF tnf) {
110 case NFC_TNF_WELL_KNOWN:
111 return static_cast<unsigned short>(NFC_RECORD_TNF_WELL_KNOWN);
112 case NFC_TNF_MIME_MEDIA:
113 return static_cast<unsigned short>(NFC_RECORD_TNF_MIME_MEDIA);
115 return static_cast<unsigned short>(NFC_RECORD_TNF_URI);
116 case NFC_TNF_EXTERNAL_RTD:
117 return static_cast<unsigned short>(NFC_RECORD_TNF_EXTERNAL_RTD);
118 case NFC_TNF_UNKNOWN:
119 return static_cast<unsigned short>(NFC_RECORD_TNF_UNKNOWN);
120 case NFC_TNF_UNCHAGNED:
121 return static_cast<unsigned short>(NFC_RECORD_TNF_UNCHAGNED);
124 return static_cast<unsigned short>(NFC_RECORD_TNF_EMPTY);
128 nfcTNF NFCUtil::convertTonfcTNF(unsigned short tnf) {
129 switch (static_cast<nfc_record_tnf_e>(tnf)) {
130 case NFC_RECORD_TNF_WELL_KNOWN:
131 return NFC_TNF_WELL_KNOWN;
132 case NFC_RECORD_TNF_MIME_MEDIA:
133 return NFC_TNF_MIME_MEDIA;
134 case NFC_RECORD_TNF_URI:
136 case NFC_RECORD_TNF_EXTERNAL_RTD:
137 return NFC_TNF_EXTERNAL_RTD;
138 case NFC_RECORD_TNF_UNKNOWN:
139 return NFC_TNF_UNKNOWN;
140 case NFC_RECORD_TNF_UNCHAGNED:
141 return NFC_TNF_UNCHAGNED;
142 case NFC_RECORD_TNF_EMPTY:
144 return NFC_TNF_EMPTY;