2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
20 #include "net_nfc_client_tag_jewel.h"
21 #include "net_nfc_client_tag_internal.h"
23 #include "net_nfc_typedef_internal.h"
24 #include "net_nfc_debug_internal.h"
25 #include "net_nfc_util_internal.h"
26 #include "net_nfc_target_info.h"
29 #define JEWEL_CMD_REQA 0x26
30 #define JEWEL_CMD_WUPA 0x52
31 #define JEWEL_CMD_RID 0x78
32 #define JEWEL_CMD_RALL 0x00
33 #define JEWEL_CMD_READ 0x01
34 #define JEWEL_CMD_WRITE_E 0x53
35 #define JEWEL_CMD_WRITE_NE 0x1A
36 #define JEWEL_TAG_KEY "UID"
38 API net_nfc_error_e net_nfc_client_jewel_read_id(net_nfc_target_handle_h handle,
39 nfc_transceive_data_callback callback, void *user_data)
41 net_nfc_target_info_s *target_info = NULL;
45 uint8_t send_buffer[9] = {0x00, };
48 return NET_NFC_NULL_PARAMETER;
50 if(net_nfc_client_tag_is_connected() == FALSE)
51 return NET_NFC_OPERATION_FAIL;
53 target_info = net_nfc_client_tag_get_client_target_info();
54 if (target_info == NULL)
55 return NET_NFC_NO_DATA_FOUND;
57 if(target_info->devType != NET_NFC_JEWEL_PICC)
59 NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType);
60 return NET_NFC_NOT_ALLOWED_OPERATION;
63 send_buffer[0] = JEWEL_CMD_RID;
65 net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
67 DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
69 rawdata.buffer = send_buffer;
72 return net_nfc_client_transceive_data(handle,
78 API net_nfc_error_e net_nfc_client_jewel_read_byte(net_nfc_target_handle_h handle,
79 uint8_t block, uint8_t byte, nfc_transceive_data_callback callback, void *user_data)
81 net_nfc_target_info_s *target_info = NULL;
87 uint8_t send_buffer[9] = {0x00, };
90 return NET_NFC_NULL_PARAMETER;
92 if(block > 0xE || byte > 0x7 )
93 return NET_NFC_OUT_OF_BOUND;
95 if(net_nfc_client_tag_is_connected() == FALSE)
96 return NET_NFC_OPERATION_FAIL;
98 target_info = net_nfc_client_tag_get_client_target_info();
99 if (target_info == NULL)
100 return NET_NFC_NO_DATA_FOUND;
102 if(target_info->devType != NET_NFC_JEWEL_PICC)
104 NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType);
105 return NET_NFC_NOT_ALLOWED_OPERATION;
108 if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
112 return NET_NFC_NO_DATA_FOUND;
116 if(((data_s*)UID)->length != 4)
117 return NET_NFC_OUT_OF_BOUND;
120 send_buffer[0] = JEWEL_CMD_READ;
123 send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
126 send_buffer[2] = 0x00;
129 memcpy(&(send_buffer[3]),
130 ((data_s*)UID)->buffer,
131 ((data_s*)UID)->length);
133 net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
135 DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
137 rawdata.buffer = send_buffer;
140 return net_nfc_client_transceive_data(handle,
146 API net_nfc_error_e net_nfc_client_jewel_read_all(net_nfc_target_handle_h handle,
147 nfc_transceive_data_callback callback, void *user_data)
149 net_nfc_target_info_s *target_info = NULL;
155 uint8_t send_buffer[9] = {0x00, };
158 return NET_NFC_NULL_PARAMETER;
160 if(net_nfc_client_tag_is_connected() == FALSE)
161 return NET_NFC_OPERATION_FAIL;
163 target_info = net_nfc_client_tag_get_client_target_info();
164 if (target_info == NULL)
165 return NET_NFC_NO_DATA_FOUND;
167 if(target_info->devType != NET_NFC_JEWEL_PICC)
169 NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType);
170 return NET_NFC_NOT_ALLOWED_OPERATION;
173 if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
177 return NET_NFC_NO_DATA_FOUND;
180 if(((data_s*)UID)->length != 4)
181 return NET_NFC_OUT_OF_BOUND;
184 send_buffer[0] = JEWEL_CMD_RALL;
187 send_buffer[1] = 0x00;
190 send_buffer[2] = 0x00;
193 memcpy(&(send_buffer[3]),
194 ((data_s*)UID)->buffer,
195 ((data_s*)UID)->length);
197 net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
199 DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
201 rawdata.buffer = send_buffer;
204 return net_nfc_client_transceive_data(handle,
210 API net_nfc_error_e net_nfc_client_jewel_write_with_erase(
211 net_nfc_target_handle_h handle,
215 nfc_transceive_callback callback,
218 net_nfc_target_info_s *target_info = NULL;
221 uint8_t send_buffer[9] = {0x00, };
224 return NET_NFC_NULL_PARAMETER;
226 if(block > 0xE || byte > 0x7 )
227 return NET_NFC_OUT_OF_BOUND;
229 if(net_nfc_client_tag_is_connected() == FALSE)
230 return NET_NFC_OPERATION_FAIL;
233 target_info = net_nfc_client_tag_get_client_target_info();
234 if (target_info == NULL)
235 return NET_NFC_NO_DATA_FOUND;
237 if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
241 return NET_NFC_NO_DATA_FOUND;
244 if(((data_s*)UID)->length != 4)
245 return NET_NFC_OUT_OF_BOUND;
248 send_buffer[0] = JEWEL_CMD_WRITE_E;
251 send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
254 send_buffer[2] = data;
257 memcpy(&(send_buffer[3]),
258 ((data_s*)UID)->buffer,
259 ((data_s*)UID)->length);
261 net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
263 DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
265 rawdata.buffer = send_buffer;
268 return net_nfc_client_transceive(handle,
275 API net_nfc_error_e net_nfc_client_jewel_write_with_no_erase(
276 net_nfc_target_handle_h handle,
280 nfc_transceive_callback callback,
283 net_nfc_target_info_s *target_info = NULL;
289 uint8_t send_buffer[9] = {0x00, };
292 return NET_NFC_NULL_PARAMETER;
294 if(block > 0xE || byte > 0x7 )
295 return NET_NFC_OUT_OF_BOUND;
297 if(net_nfc_client_tag_is_connected() == FALSE)
298 return NET_NFC_OPERATION_FAIL;
300 target_info = net_nfc_client_tag_get_client_target_info();
301 if (target_info == NULL)
302 return NET_NFC_NO_DATA_FOUND;
304 if(target_info->devType != NET_NFC_JEWEL_PICC)
306 NFC_ERR("only Jewel tag is available(TAG=%d)", target_info->devType);
307 return NET_NFC_NOT_ALLOWED_OPERATION;
310 if(net_nfc_get_tag_info_value((net_nfc_target_info_h)target_info,
314 return NET_NFC_NO_DATA_FOUND;
317 if(((data_s*)UID)->length != 4)
318 return NET_NFC_OUT_OF_BOUND;
321 send_buffer[0] = JEWEL_CMD_WRITE_NE;
324 send_buffer[1] = (((block << 3) & 0x78) | (byte & 0x7));
327 send_buffer[2] = data;
330 memcpy(&(send_buffer[3]),
331 ((data_s*)UID)->buffer,
332 ((data_s*)UID)->length);
334 net_nfc_util_compute_CRC(CRC_B, send_buffer, 9);
336 DEBUG_MSG_PRINT_BUFFER(send_buffer, 9);
338 rawdata.buffer = send_buffer;
341 return net_nfc_client_transceive(handle,