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) {
111 return static_cast<unsigned short>(NFC_RECORD_TNF_EMPTY);
112 case NFC_TNF_WELL_KNOWN:
113 return static_cast<unsigned short>(NFC_RECORD_TNF_WELL_KNOWN);
114 case NFC_TNF_MIME_MEDIA:
115 return static_cast<unsigned short>(NFC_RECORD_TNF_MIME_MEDIA);
117 return static_cast<unsigned short>(NFC_RECORD_TNF_URI);
118 case NFC_TNF_EXTERNAL_RTD:
119 return static_cast<unsigned short>(NFC_RECORD_TNF_EXTERNAL_RTD);
120 case NFC_TNF_UNKNOWN:
121 return static_cast<unsigned short>(NFC_RECORD_TNF_UNKNOWN);
122 case NFC_TNF_UNCHAGNED:
123 return static_cast<unsigned short>(NFC_RECORD_TNF_UNCHAGNED);
127 nfcTNF NFCUtil::convertTonfcTNF(unsigned short tnf) {
128 switch (static_cast<nfc_record_tnf_e>(tnf)) {
129 case NFC_RECORD_TNF_EMPTY:
130 return NFC_TNF_EMPTY;
131 case NFC_RECORD_TNF_WELL_KNOWN:
132 return NFC_TNF_WELL_KNOWN;
133 case NFC_RECORD_TNF_MIME_MEDIA:
134 return NFC_TNF_MIME_MEDIA;
135 case NFC_RECORD_TNF_URI:
137 case NFC_RECORD_TNF_EXTERNAL_RTD:
138 return NFC_TNF_EXTERNAL_RTD;
139 case NFC_RECORD_TNF_UNKNOWN:
140 return NFC_TNF_UNKNOWN;
141 case NFC_RECORD_TNF_UNCHAGNED:
142 return NFC_TNF_UNCHAGNED;