2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.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_typedef.h>
22 #include <net_nfc_exchanger.h>
25 #include "nfc_api_test.h"
29 /* Function definition list*/
30 int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2);
31 int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2);
32 int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2);
33 int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2);
34 int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2);
35 int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2);
36 int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2);
37 int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2);
38 int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2);
39 int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2);
40 int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2);
41 int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2);
42 int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2);
43 int nfcConnHandover(uint8_t testNumber,void* arg_ptr2);
44 int nfcTestAPIException (uint8_t testNumber,void* arg_ptr);
45 int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr);
46 int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr);
47 int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr);
48 int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2);
49 int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2);
50 int nfcTestSnep(uint8_t testNumber,void* arg_ptr);
53 void print_test_result (char * str, net_nfc_test_result_e result);
55 #define NET_NFC_TAG_DISCOVERED 1
56 #define NET_NFC_TAG_CONNECT (1 << 1)
57 #define NET_NFC_TAG_CHECK_NDEF (1 << 2)
58 #define NET_NFC_TAG_NDEF_READ (1 << 3)
59 #define NET_NFC_TAG_NDEF_WRITE (1 << 4)
60 #define NET_NFC_TAG_NDEF_READ_BIG (1 << 5)
61 #define NET_NFC_TAG_NDEF_WRITE_BIG (1 << 6)
62 #define NET_NFC_TAG_DISCONNECT (1 << 7)
63 #define NET_NFC_MAX_TAG_TYPE 20
65 static nfcTestType nfcTestMatrix[] =
67 // {"API STRESS_WRITE_READ TEST", nfcTestReadWriteMode, NET_NFC_TEST_NOT_YET}, // OK
68 // {"Remove tag while writing", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, //OK
69 // {"Remove tag while reading", nfcTestAPIBasicTest2, NET_NFC_TEST_NOT_YET}, // OK
70 //{"API BASIC TEST3", nfcTestAPIBasicTest3, NET_NFC_TEST_NOT_YET},
71 // {"API MUTIPLE REQUEST", nfcTestAPIMultipleRequest, NET_NFC_TEST_NOT_YET}, // OK
72 // {"API BASIC TEST1", nfcTestAPIBasicTest1, NET_NFC_TEST_NOT_YET}, // OK
73 // {"Check NDEF message", nfcTestNdefParser, NET_NFC_TEST_NOT_YET}, // OK
74 // {"write mode", nfcTestWriteMode, NET_NFC_TEST_NOT_YET},
75 // {"reader mode", nfcTestReaderMode, NET_NFC_TEST_NOT_YET},
76 // {"format ndef", nfcTestFormatNdef, NET_NFC_TEST_NOT_YET},
77 // {"internal_se_test", nfcTestInternalSe, NET_NFC_TEST_NOT_YET},
78 // {"exchange mode", nfcTestExchanger, NET_NFC_TEST_NOT_YET},
79 // {"Transceive Test", nfcTestTransceive, NET_NFC_TEST_NOT_YET},
80 // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
81 // {"connection handover msg test", nfcConnHandover, NET_NFC_TEST_NOT_YET},
82 // {"API Exception Test", nfcTestAPIException, NET_NFC_TEST_NOT_YET},
83 // {"API Exception Test2", nfcTestAPIException_tagAPI, NET_NFC_TEST_NOT_YET},
84 /// {"API Exception Test3", nfcTestAPIException_targetInfo, NET_NFC_TEST_NOT_YET},
85 // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
86 // {"LLCP Test", nfcTestStressLLCP, NET_NFC_TEST_NOT_YET},
87 // {"Handover Message", nfcConnHandoverMessageTest , NET_NFC_TEST_NOT_YET},
88 {"snep test", nfcTestSnep, NET_NFC_TEST_NOT_YET},
89 {NULL, NULL, NET_NFC_TEST_NOT_YET},
92 static uint32_t testDevType = 0;
93 static uint32_t testCardMaxNdefLength = 0;
94 static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE];
96 static int read_count = 0;
97 static int write_count = 0;
98 static int detect_count = 0;
100 static net_nfc_target_handle_h tag_handle = NULL;
101 static int test_count = 0;
105 /* Below smart poster data can has problem or parser has some problem.
107 uint8_t nfcTestSpHex[]= {0xD1,0x02,0x37,0x53,0x70,0x91,0x01,0x18,0x54,0x04,
108 0x74,0x65,0x73,0x74,0x53,0x6D,0x61,0x72,0x74,0x70,
109 0x6F,0x73,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,
110 0x70,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00,
111 0x51,0x01,0x10,0x55,0x00,0x77,0x77,0x77,0x2E,0x73,
112 0x61,0x6D,0x73,0x75,0x6E,0x67,0x2E,0x63,0x6F,0x6D};
115 uint8_t nfcTestSp[]={0xD1,0x02,0x24,0x53,0x70,0x91,0x01,0x14,0x54
116 ,0x00,0x53,0x6D,0x61,0x72,0x74,0x70,0x6F,0x73
117 ,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,0x70
118 ,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00
119 ,0x51,0x01,0x01,0x55,0x00};
122 // test Text "Samsung Linux Platform NFC TEST"
123 uint8_t nfcTestTextHex[]= {0xD1,0x01,0x20,0x54,0x00,0x53,0x61,0x6D,0x73,0x75
124 ,0x6E,0x67,0x20,0x4C,0x69,0x6E,0x75,0x78,0x20,0x50
125 ,0x6C,0x61,0x74,0x66,0x6F,0x72,0x6D,0x20,0x4E,0x46
126 ,0x43,0x20,0x54,0x45,0x53,0x54};
129 // test URI "http://www.samsunglinuxplatform.nfctest.com"
130 uint8_t nfcTestUriHex[]={0xD1,0x01,0x2C,0x55,0x00,0x68,0x74,0x74,0x70,0x3A
131 ,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x73,0x61,0x6D,0x73
132 ,0x75,0x6E,0x67,0x6C,0x69,0x6E,0x75,0x78,0x70,0x6C
133 ,0x61,0x74,0x66,0x6F,0x72,0x6D,0x2E,0x6E,0x66,0x63
134 ,0x74,0x65,0x73,0x74,0x2E,0x63,0x6F,0x6D};
136 uint8_t nfcTestText[] = "payload http://www.samsunglinuxplatform.nfctest.com";
137 uint8_t nfcTestUri[] = {0xD1,0x01,0x13,0x55,0x1,0x73,0x61,0x6D,0x73,0x75,0x6E,0x67,0x6D,0x6F,0x62,0x69,0x6C,0x65,0x2E,0x63,0x6F,0x6D,0x2F};
141 static pthread_cond_t pcond = PTHREAD_COND_INITIALIZER;
142 static pthread_mutex_t plock = PTHREAD_MUTEX_INITIALIZER;
144 static gboolean test_process_func(gpointer data)
146 uint8_t i, testNumber;
149 while (nfcTestMatrix[count].testName != NULL){
153 for(i=0; i<count; i++)
155 PRINT_INFO("%d. %s START\n", i, nfcTestMatrix[i].testName);
157 if(nfcTestMatrix[i].testFn !=NULL){
158 nfcTestMatrix[i].testResult = nfcTestMatrix[i].testFn(i, NULL);
159 //print_test_result (nfcTestMatrix[i].testName, nfcTestMatrix[i].testResult);
169 GMainLoop* loop = NULL;
170 loop = g_main_new(TRUE);
172 g_timeout_add_seconds(1, test_process_func, NULL); // 1secs
173 g_main_loop_run(loop);
178 void print_test_result (char * str, net_nfc_test_result_e result)
180 if (result == NET_NFC_TEST_OK){
181 PRINT_RESULT_SUCCESS("TEST [%s] is PASSED",str);
183 else if (result == NET_NFC_TEST_FAIL){
184 PRINT_RESULT_FAIL("TEST [%s] is FAILED",str);
187 PRINT_INFO("TEST is being tested\n");
192 /*=================================================================================*/
194 static net_nfc_test_result_e test_case_result;
196 static void net_nfc_test_read_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data );
197 static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data);
199 static void net_nfc_test_client_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data )
204 int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2)
206 net_nfc_error_e result;
207 result = net_nfc_initialize();
208 CHECK_RESULT(result);
211 result = net_nfc_set_response_callback (net_nfc_test_client_cb, NULL);
212 CHECK_RESULT(result);
214 result = net_nfc_unset_response_callback ();
215 CHECK_RESULT(result);
217 result = net_nfc_deinitialize ();
218 CHECK_RESULT(result);
220 return NET_NFC_TEST_OK;
224 net_nfc_exchanger_data_h net_nfc_exchanger_callback(net_nfc_exchanger_event_e event, void * user_param)
226 PRINT_INFO(" event = [%d] \n", event);
227 test_case_result = NET_NFC_TEST_OK;
231 case NET_NFC_EXCHANGER_DATA_REQUESTED:
233 PRINT_INFO("exchange is requested");
234 net_nfc_exchanger_data_h ex_data = NULL;
235 net_nfc_error_e error = NET_NFC_OK;
236 data_h payload = NULL;
239 uint8_t buffer[1024] = {0};
246 net_nfc_create_data(&payload, buffer, 1024);
249 if((error = net_nfc_create_exchanger_data(&ex_data, (uint8_t *)"http://www.samsung.com")) == NET_NFC_OK)
250 //if((error = net_nfc_create_exchanger_url_type_data(&ex_data, NET_NFC_SCHEMA_FULL_URI, (uint8_t *)"file://test.txt")) == NET_NFC_OK)
251 //if((error = net_nfc_create_exchanger_raw_type_data(&ex_data, "text/plain", payload)) == NET_NFC_OK)
257 PRINT_INFO("create exchanger data is failed = [%d]", error);
258 //pthread_cond_signal (&pcond);
262 case NET_NFC_EXCHANGER_TRANSFER_FAILED:
263 case NET_NFC_EXCHANGER_TRANSFER_COMPLETED:
266 //pthread_cond_signal (&pcond);
268 if(event == NET_NFC_EXCHANGER_TRANSFER_COMPLETED)
270 PRINT_INFO("transfer exchanger msg is completed");
274 PRINT_INFO("transfer exchanger msg is failed");
283 /*=================================================================================*/
284 static void net_nfc_test_reader_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
288 PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
292 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
293 net_nfc_target_type_e type;
294 net_nfc_target_handle_h id;
296 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
298 net_nfc_get_tag_type (target_info, &type);
299 net_nfc_get_tag_handle(target_info, &id);
300 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
301 PRINT_INFO("target type: %d\n", type);
302 PRINT_INFO("target id: %X\n", id);
303 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
308 net_nfc_get_tag_actual_data_size (target_info ,&actual_size);
309 net_nfc_get_tag_max_data_size (target_info ,&max_size);
310 PRINT_INFO("\tmax data [%d]\tactual data [%d]\n", max_size,actual_size );
311 net_nfc_read_tag (id, (void *)2);
314 PRINT_INSTRUCT("Please use NDEF formated tag!!");
315 test_case_result = NET_NFC_TEST_FAIL;
319 case NET_NFC_MESSAGE_READ_NDEF:{
321 ndef_message_h ndef = (ndef_message_h)(data);
323 net_nfc_create_rawdata_from_ndef_message (ndef ,&rawdata);
324 PRINT_INFO("read ndef message is ok, length is [%d]", net_nfc_get_data_length(rawdata));
325 //_//net_nfc_ndef_print_message (ndef);
328 if (memcmp(net_nfc_get_data_buffer (rawdata),nfcTestSpHex, net_nfc_get_data_length (rawdata)) == 0){
329 test_case_result = NET_NFC_TEST_OK;
333 pthread_mutex_lock (&plock);
334 pthread_cond_signal (&pcond);
335 pthread_mutex_unlock (&plock);
344 static void net_nfc_test_format_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
348 PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
352 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
354 PRINT_INFO("NET_NFC_MESSAGE_TAG_DISCOVERED");
356 net_nfc_target_type_e type;
357 net_nfc_target_handle_h id;
359 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
361 net_nfc_get_tag_type (target_info, &type);
362 net_nfc_get_tag_handle(target_info, &id);
363 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
364 PRINT_INFO("target type: %d\n", type);
365 PRINT_INFO("target id: %X\n", id);
366 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
368 data_h ndef_key = NULL;
369 net_nfc_mifare_create_net_nfc_forum_key(&ndef_key);
370 net_nfc_format_ndef(id, ndef_key, NULL);
375 case NET_NFC_MESSAGE_FORMAT_NDEF:{
376 PRINT_INFO("NET_NFC_MESSAGE_FORMAT_NDEF");
377 PRINT_INFO("result = [%d]", result);
380 case NET_NFC_MESSAGE_TAG_DETACHED:
382 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED");
390 static void net_nfc_test_se_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
394 case NET_NFC_MESSAGE_GET_SE :
396 PRINT_INFO("NET_NFC_MESSAGE_GET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
397 //net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
398 net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
401 case NET_NFC_MESSAGE_SET_SE :
403 PRINT_INFO("NET_NFC_MESSAGE_SET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
404 net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL);
405 //net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_UICC, NULL);
408 case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
410 PRINT_INFO("NET_NFC_MESSAGE_OPEN_INTERNAL_SE result = [%d] and handle = [0x%x]", result, data);
412 uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C} ; // CLA 0-> use default channel and no secure message. 0xA4 -> select instruction
413 net_nfc_create_data(&apdu, apdu_cmd, 4);
414 net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data);
418 case NET_NFC_MESSAGE_SEND_APDU_SE:
420 PRINT_INFO("NET_NFC_MESSAGE_SEND_APDU_SE result = [%d]", result);
424 uint8_t * r_buffer = net_nfc_get_data_buffer (data);
425 uint32_t r_buffer_length = net_nfc_get_data_length (data);
427 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (data));
430 for (idx = 0; idx < r_buffer_length; idx++){
431 printf (" %02X", r_buffer[idx]);
435 net_nfc_close_internal_secure_element((net_nfc_target_handle_h)trans_data, NULL);
438 case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
441 PRINT_INFO("NET_NFC_MESSAGE_CLOSE_INTERNAL_SE result = [%d]", result);
448 PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
451 /*=================================================================================*/
452 static void net_nfc_test_static_handover_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
457 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
458 net_nfc_target_type_e type;
459 net_nfc_target_handle_h id;
461 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
462 net_nfc_carrier_config_h * config;
463 ndef_record_h record;
465 net_nfc_get_tag_type (target_info, &type);
466 net_nfc_get_tag_handle(target_info, &id);
467 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
468 PRINT_INFO("target type: %d\n", type);
469 PRINT_INFO("target id: %X\n", id);
470 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
474 ndef_message_h ndef = NULL;
475 data_h bt_config = NULL;
476 net_nfc_create_data_only(&bt_config);
478 // 2byte :: OOB length, 6byte :: bt addr
479 uint8_t temp[8] = {0x00, 0x08, 0x00, 0x02, 0x78, 0xDD, 0xC4, 0x8A};
480 net_nfc_create_carrier_config (&config,NET_NFC_CONN_HANDOVER_CARRIER_BT );
481 net_nfc_add_carrier_config_property (config ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,8 ,temp);
482 net_nfc_create_ndef_record_with_carrier_config (&record, config);
483 net_nfc_create_handover_select_message (&ndef);
484 net_nfc_append_carrier_config_record (message,record,NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
486 net_nfc_write_ndef(id, ndef, NULL);
490 PRINT_INSTRUCT("Please use NDEF formated tag!!");
491 test_case_result = NET_NFC_TEST_FAIL;
495 case NET_NFC_MESSAGE_WRITE_NDEF:{
497 if(result == NET_NFC_OK){
498 PRINT_INFO("write ndef message is ok");
499 test_case_result = NET_NFC_TEST_OK;
502 pthread_mutex_lock (&plock);
503 pthread_cond_signal (&pcond);
504 pthread_mutex_unlock (&plock);
512 int nfcConnHandover(uint8_t testNumber,void* arg_ptr2)
514 int user_context = 0;
515 net_nfc_error_e result;
517 test_case_result = NET_NFC_TEST_FAIL;
519 result = net_nfc_initialize();
521 net_nfc_state_activate(1);
523 CHECK_RESULT(result);
524 result = net_nfc_set_response_callback (net_nfc_test_static_handover_cb, NULL);
525 CHECK_RESULT(result);
527 PRINT_INSTRUCT("Please close a tag to device!!");
529 //pthread_cond_wait (&pcond,&plock );
531 PRINT_INFO("operation is end");
533 result = net_nfc_unset_response_callback ();
535 CHECK_RESULT(result);
536 result = net_nfc_deinitialize ();
537 CHECK_RESULT(result);
542 ndef_message_h ndef = NULL;
544 if(net_nfc_retrieve_current_ndef_message(&ndef) == NET_NFC_OK){
545 PRINT_INFO("retrieve is ok");
548 PRINT_INFO("retrieve is failed");
549 return NET_NFC_TEST_FAIL;
552 ndef_message_h ndef = NULL;
553 data_h bt_config = NULL;
554 net_nfc_create_data_only(&bt_config);
556 // 2byte :: OOB length, 6byte :: bt addr
557 uint8_t temp[8] = {0x00, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
559 net_nfc_set_data(bt_config, temp, 8);
560 net_nfc_create_static_connection_handover_select_message(&ndef, bt_config, NULL);
562 net_nfc_conn_handover_info_h handover_info = NULL;
564 if(net_nfc_parse_connection_handover_ndef_message(ndef, &handover_info) == NET_NFC_OK){
565 PRINT_INFO("parsing is ok");
569 if((result = net_nfc_get_connection_handover_version(handover_info, &version)) == NET_NFC_OK){
570 PRINT_INFO("version = [%d]", version);
573 PRINT_INFO("get version is failed = [%d]", result);
577 unsigned short random_number = 0;
578 if((result = net_nfc_get_connection_handover_random_number(handover_info, &random_number)) == NET_NFC_OK)
580 PRINT_INFO("random_number = [%d]", random_number);
584 PRINT_INFO("get random_number is failed = [%d]", result);
587 data_h record_type = NULL;
588 net_nfc_get_connection_handover_record_type(handover_info, &record_type);
589 PRINT_INFO("record type = [%c] [%c]", (net_nfc_get_data_buffer(record_type))[0], (net_nfc_get_data_buffer(record_type))[1]);
591 uint8_t carrier_count = 0;
592 net_nfc_get_connection_handover_alternative_carrier_count(handover_info, &carrier_count);
595 for(; i < carrier_count; i++)
597 net_nfc_conn_handover_carrier_info_h carrier_info = NULL;
598 net_nfc_get_connection_handover_carrier_handle_by_index(handover_info, i, &carrier_info);
600 if(carrier_info != NULL){
601 net_nfc_conn_handover_carrier_type_e carrier_type = 0;
602 net_nfc_get_carrier_type(carrier_info, &carrier_type);
604 if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
606 PRINT_INFO("carrier is BT");
608 else if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI)
610 PRINT_INFO("carrier is WIFI");
614 PRINT_INFO("carrier is unknown");
618 net_nfc_get_carrier_id(carrier_info, &id);
620 PRINT_INFO("id = [0x%x]", (net_nfc_get_data_buffer(id))[0]);
622 net_nfc_conn_handover_carrier_state_e carrier_state = 0;
623 net_nfc_get_carrier_power_state(carrier_info, &carrier_state);
625 PRINT_INFO("cps is = [0x%x]", carrier_state);
627 data_h config = NULL;
628 if((result = net_nfc_get_carrier_configuration(carrier_info, &config)) == NET_NFC_OK)
630 PRINT_INFO("good to get config");
634 PRINT_INFO("failed to get config = [%d]", result);
637 uint8_t* buffer = NULL;
638 if((buffer = net_nfc_get_data_buffer(config)) != NULL)
640 unsigned short size = ( buffer[0] << 8 ) |buffer[1];
641 PRINT_INFO("size is = [%d]", size);
645 PRINT_INFO("carrier addr is [0x%x]", buffer[2]);
646 PRINT_INFO("carrier addr is [0x%x]", buffer[3]);
647 PRINT_INFO("carrier addr is [0x%x]", buffer[4]);
648 PRINT_INFO("carrier addr is [0x%x]", buffer[5]);
649 PRINT_INFO("carrier addr is [0x%x]", buffer[6]);
650 PRINT_INFO("carrier addr is [0x%x]", buffer[7]);
654 PRINT_INFO("more data -_-;; ");
659 PRINT_INFO("failed to buffer");
667 PRINT_INFO("parsing is failed");
669 return NET_NFC_TEST_FAIL;
673 if(handover_info != NULL){
674 if((net_nfc_free_connection_handover_info(handover_info)) == NET_NFC_OK){
675 PRINT_INFO("free is good");
678 PRINT_INFO("free is failed");
683 return test_case_result;
686 int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2)
688 PRINT_INFO("%s is start", __func__);
690 int user_context = 0;
691 net_nfc_error_e result;
692 test_case_result = NET_NFC_TEST_FAIL;
694 result = net_nfc_initialize();
696 net_nfc_state_activate(1);
698 CHECK_RESULT(result);
699 result = net_nfc_set_response_callback (net_nfc_test_format_cb, (void *)1);
700 CHECK_RESULT(result);
702 PRINT_INSTRUCT("Please close a tag to device!!");
704 //pthread_cond_wait (&pcond,&plock );
707 PRINT_INFO("operation is end");
709 result = net_nfc_unset_response_callback ();
711 CHECK_RESULT(result);
712 result = net_nfc_deinitialize ();
713 CHECK_RESULT(result);
717 return test_case_result;
720 int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2)
722 PRINT_INFO("%s is start", __func__);
724 int user_context = 0;
725 net_nfc_error_e result;
726 test_case_result = NET_NFC_TEST_FAIL;
728 result = net_nfc_initialize();
730 net_nfc_state_activate(1);
732 CHECK_RESULT(result);
733 result = net_nfc_set_response_callback (net_nfc_test_se_cb, (void *)1);
734 CHECK_RESULT(result);
736 net_nfc_get_secure_element_type(NULL);
738 PRINT_INSTRUCT("Please close a tag to device!!");
740 return test_case_result;
745 int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2)
747 PRINT_INFO("%s is start", __func__);
749 int user_context = 0;
750 net_nfc_error_e result;
751 test_case_result = NET_NFC_TEST_FAIL;
753 result = net_nfc_initialize();
755 net_nfc_state_activate(1);
757 CHECK_RESULT(result);
758 result = net_nfc_set_response_callback (net_nfc_test_reader_cb, (void *)1);
759 CHECK_RESULT(result);
761 PRINT_INSTRUCT("Please close a tag to device!!");
763 //pthread_cond_wait (&pcond,&plock );
766 PRINT_INFO("operation is end");
768 result = net_nfc_unset_response_callback ();
770 CHECK_RESULT(result);
771 result = net_nfc_deinitialize ();
772 CHECK_RESULT(result);
776 return test_case_result;
779 int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2)
781 PRINT_INFO("%s is start", __func__);
782 int user_context = 0;
783 net_nfc_error_e result;
784 test_case_result = NET_NFC_TEST_FAIL;
786 if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_OK){
787 test_case_result = NET_NFC_TEST_FAIL;
788 PRINT_INFO("failed to set exchanger_cb = [%d]", result);
789 return test_case_result;
792 PRINT_INFO("setting exchange callback is ok = [%d]", result);
796 if((result = net_nfc_initialize()) != NET_NFC_NOT_ALLOWED_OPERATION){
797 test_case_result = NET_NFC_TEST_FAIL;
798 PRINT_INFO("NET_NFC_NOT_ALLOWED_OPERATION 1 is not returned = [%d]", result);
799 return test_case_result;
801 PRINT_INFO("net_nfc_init is failed = [%d]", result);
804 if((result = net_nfc_unset_exchanger_cb()) != NET_NFC_OK){
805 test_case_result = NET_NFC_TEST_FAIL;
806 PRINT_INFO("unset exchanger cb is failed = [%d]", result);
807 return test_case_result;
809 PRINT_INFO("unset ex cb is ok = [%d]", result);
812 if((result = net_nfc_initialize()) != NET_NFC_OK){
813 test_case_result = NET_NFC_TEST_FAIL;
814 PRINT_INFO("net_nfc_init is failed = [%d]", result);
815 return test_case_result;
817 PRINT_INFO("net_nfc_init is ok = [%d]", result);
820 if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_NOT_ALLOWED_OPERATION){
821 test_case_result = NET_NFC_TEST_FAIL;
822 PRINT_INFO("NET_NFC_NOT_ALLOWED_OPERATION 2 is not returned = [%d]", result);
823 return test_case_result;
825 PRINT_INFO("set ex cb is failed = [%d]", result);
828 if((result = net_nfc_deinitialize()) != NET_NFC_OK){
829 test_case_result = NET_NFC_TEST_FAIL;
830 PRINT_INFO("nfc deinit is failed = [%d]", result);
831 return test_case_result;
833 PRINT_INFO("net_nfc_deinit is ok = [%d]", result);
836 if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_OK){
837 PRINT_INFO("set exchanger cb is failed = [%d]", result);
838 test_case_result = NET_NFC_TEST_FAIL;
839 return test_case_result;
841 PRINT_INFO("settting ex cb is ok = [%d]", result);
845 //pthread_cond_wait (&pcond,&plock );
847 //PRINT_INFO("operation is end");
848 //result = net_nfc_unset_exchanger_cb();
849 //CHECK_RESULT(result);
851 test_case_result = NET_NFC_TEST_OK;
853 return test_case_result;
856 /*=================================================================================*/
858 static void net_nfc_test_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
864 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
865 net_nfc_target_type_e type;
866 net_nfc_target_handle_h handle;
868 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
870 net_nfc_get_tag_type (target_info, &type);
871 net_nfc_get_tag_handle (target_info, &handle);
872 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
873 PRINT_INFO("target type: %d\n", type);
874 PRINT_INFO("target id: %X\n", handle);
875 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
881 net_nfc_error_e error = NET_NFC_OK;
882 ndef_message_h msg = NULL;
883 ndef_record_h record = NULL;
885 if( (error = net_nfc_create_uri_type_record(&record, "http://www.naver.com", NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
887 if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
889 if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
891 ////net_nfc_ndef_print_message(msg);
892 net_nfc_write_ndef(tag_handle, msg, &user_context);
893 net_nfc_free_ndef_message(msg);
897 PRINT_INFO("failed to append ndef message = [%d]", error);
898 net_nfc_free_record(record);
899 net_nfc_free_ndef_message(msg);
901 pthread_mutex_lock (&plock);
902 pthread_cond_signal (&pcond);
903 pthread_mutex_unlock (&plock);
908 PRINT_INFO("failed to create ndef msg");
909 net_nfc_free_record(record);
911 pthread_mutex_lock (&plock);
912 pthread_cond_signal (&pcond);
913 pthread_mutex_unlock (&plock);
918 PRINT_INFO("failed to create text type record");
920 pthread_mutex_lock (&plock);
921 pthread_cond_signal (&pcond);
922 pthread_mutex_unlock (&plock);
926 PRINT_INSTRUCT("Please use NDEF formated tag!!");
932 case NET_NFC_MESSAGE_TAG_DETACHED:
934 if (write_count++ >= 20) {
935 test_case_result = NET_NFC_TEST_OK;
936 pthread_mutex_lock (&plock);
937 pthread_cond_signal (&pcond);
938 pthread_mutex_unlock (&plock);
941 PRINT_INSTRUCT("Please close a tag to device again!!");
946 case NET_NFC_MESSAGE_WRITE_NDEF:
948 /*if (result == NET_NFC_OK) {
949 test_case_result = NET_NFC_TEST_OK;
952 PRINT_INFO("received error: %d\n", result);
953 test_case_result = NET_NFC_TEST_FAIL;
957 /* pthread_mutex_lock (&plock);
958 pthread_cond_signal (&pcond);
959 pthread_mutex_unlock (&plock);
962 if(write_count++ == 20)
965 PRINT_INSTRUCT("completed, please remove tag");
970 net_nfc_error_e error = NET_NFC_OK;
971 ndef_message_h msg = NULL;
972 ndef_record_h record = NULL;
974 if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
976 if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
978 if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
980 ////net_nfc_ndef_print_message(msg);
981 net_nfc_write_ndef(tag_handle, msg, &user_context);
982 net_nfc_free_ndef_message(msg);
986 PRINT_INFO("failed to append ndef message = [%d]", error);
987 net_nfc_free_record(record);
988 net_nfc_free_ndef_message(msg);
989 test_case_result = NET_NFC_TEST_FAIL;
991 pthread_mutex_lock (&plock);
992 pthread_cond_signal (&pcond);
993 pthread_mutex_unlock (&plock);
998 PRINT_INFO("failed to create ndef msg");
999 net_nfc_free_record(record);
1000 test_case_result = NET_NFC_TEST_FAIL;
1002 pthread_mutex_lock (&plock);
1003 pthread_cond_signal (&pcond);
1004 pthread_mutex_unlock (&plock);
1009 PRINT_INFO("failed to create text type record");
1010 test_case_result = NET_NFC_TEST_FAIL;
1012 pthread_mutex_lock (&plock);
1013 pthread_cond_signal (&pcond);
1014 pthread_mutex_unlock (&plock);
1027 int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2)
1029 int user_context = 0;
1030 net_nfc_error_e result;
1031 test_case_result = NET_NFC_TEST_FAIL;
1033 result = net_nfc_initialize();
1034 CHECK_RESULT(result);
1036 net_nfc_state_activate(1);
1038 result = net_nfc_set_response_callback (net_nfc_test_write_cb, NULL);
1039 CHECK_RESULT(result);
1042 PRINT_INSTRUCT("TEST: remove tag while write");
1043 PRINT_INSTRUCT("Please close a tag to device!!");
1045 //pthread_cond_wait (&pcond,&plock );
1048 result = net_nfc_unset_response_callback ();
1049 CHECK_RESULT(result);
1050 result = net_nfc_deinitialize ();
1051 CHECK_RESULT(result);
1053 return test_case_result;
1058 int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2)
1060 int user_context = 0;
1061 net_nfc_error_e result;
1062 test_case_result = NET_NFC_TEST_FAIL;
1067 result = net_nfc_initialize();
1068 CHECK_RESULT(result);
1070 net_nfc_state_activate(1);
1072 result = net_nfc_set_response_callback (net_nfc_test_read_write_cb, NULL);
1073 CHECK_RESULT(result);
1075 PRINT_INSTRUCT("Testing (50 each) read and write test");
1076 PRINT_INSTRUCT("Please close a tag to device!!");
1078 //pthread_cond_wait (&pcond,&plock );
1080 result = net_nfc_unset_response_callback ();
1081 CHECK_RESULT(result);
1082 result = net_nfc_deinitialize ();
1083 CHECK_RESULT(result);
1087 return test_case_result;
1091 /*=================================================================================*/
1093 static void net_nfc_test_transceive_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
1097 printf ("callback is called with message %d\n", message);
1100 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
1101 net_nfc_target_type_e type;
1102 net_nfc_target_handle_h id;
1104 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1105 net_nfc_error_e result = NET_NFC_OK;
1107 net_nfc_get_tag_type (target_info, &type);
1108 net_nfc_get_tag_handle (target_info, &id);
1109 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1110 PRINT_INFO("target type: %d\n", type);
1111 PRINT_INFO("target id: %X\n", id);
1112 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1116 if(type == NET_NFC_MIFARE_ULTRA_PICC){
1118 if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
1119 PRINT_INFO("failed to read = [%d]", result);
1123 else if(type >= NET_NFC_MIFARE_MINI_PICC && type <= NET_NFC_MIFARE_4K_PICC){
1125 data_h mad_key = NULL;
1126 data_h net_nfc_forum_key = NULL;
1127 data_h default_key = NULL;
1129 net_nfc_mifare_create_application_directory_key(&mad_key);
1130 net_nfc_mifare_create_net_nfc_forum_key(&net_nfc_forum_key);
1131 net_nfc_mifare_create_default_key(&default_key);
1143 // key = net_nfc_forum_key;
1146 // if(net_nfc_mifare_authenticate_with_keyB(id, sector, key, NULL) != NET_NFC_OK){
1147 if(net_nfc_mifare_authenticate_with_keyA(id, sector, default_key, NULL) != NET_NFC_OK){
1148 PRINT_INFO("failed to authenticate sector");
1155 if(type == NET_NFC_MIFARE_4K_PICC && sector > 31){
1167 for(; j < nBlocks; j++){
1168 if((result = net_nfc_mifare_read(tag_handle, sector * 4 + j, NULL)) != NET_NFC_OK){
1169 PRINT_INFO("failed to read = [%d]", result);
1171 PRINT_INFO("block [%d] is read", sector * 4 + j);
1176 data_h write_block = NULL;
1177 uint8_t buffer[16] = {0x00,};
1178 uint8_t* temp = buffer;
1181 int value_comp = 1 + ~value;
1183 uint8_t addr_comp = 1 + ~addr;
1186 // read block 5 and write block 5 and read again
1187 if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
1188 PRINT_INFO("failed to read = [%d]", result);
1190 PRINT_INFO("block 5 is read");
1193 // read block 5 and write block 5 and read again
1195 memcpy(temp, &value, sizeof(int));
1196 temp = temp + sizeof(int);
1198 memcpy(temp, &value_comp, sizeof(int));
1199 temp = temp + sizeof(int);
1201 memcpy(temp, &value, sizeof(int));
1202 temp = temp + sizeof(int);
1215 net_nfc_create_data(&write_block, buffer, 16);
1217 if((result = net_nfc_mifare_write_block(tag_handle, addr, write_block,NULL)) != NET_NFC_OK){
1218 PRINT_INFO("failed to write = [%d]", result);
1220 PRINT_INFO("block 5 is written");
1223 if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
1224 PRINT_INFO("failed to read = [%d]", result);
1226 PRINT_INFO("block 5 is read");
1230 // read block 6 and decrease 6 and read again
1233 if((result = net_nfc_mifare_read(tag_handle, 7, NULL)) != NET_NFC_OK){
1234 PRINT_INFO("failed to read = [%d]", result);
1236 PRINT_INFO("read sector trailor of sector 1. it will be a block 7 th");
1241 data_h write_block = NULL;
1242 uint8_t buffer[16] = {0x00, 0x00, 0x03, 0xE8, 0xFF, 0xFF, 0xFC, 0x18, 0x00, 0x00, 0x03, 0xE8, 0x05, 0xFB, 0x05, 0xFB};
1244 net_nfc_create_data(&write_block, buffer, 16);
1246 if((result = net_nfc_mifare_write_block(tag_handle, 5, write_block, NULL)) != NET_NFC_OK){
1247 PRINT_INFO("failed to write = [%d]", result);
1249 PRINT_INFO("block 5 is written");
1253 if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
1254 PRINT_INFO("failed to read = [%d]", result);
1256 PRINT_INFO("block 5 is read");
1261 if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
1262 PRINT_INFO("failed to read = [%d]", result);
1266 int decrease_amount = 10; // 10 won
1268 if((result = net_nfc_mifare_decrement(tag_handle, 5, decrease_amount, NULL)) != NET_NFC_OK){
1269 PRINT_INFO("failed to decrease = [%d]", result);
1271 PRINT_INFO("block 5 is decreased");
1274 if((result = net_nfc_mifare_transfer(tag_handle, 5, NULL)) != NET_NFC_OK){
1275 PRINT_INFO("failed to transfer = [%d]", result);
1277 PRINT_INFO("internal register is transfered to block 5");
1281 if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
1282 PRINT_INFO("failed to read = [%d]", result);
1286 net_nfc_free_data(mad_key);
1287 net_nfc_free_data(default_key);
1288 net_nfc_free_data(net_nfc_forum_key);
1294 else if(type == NET_NFC_JEWEL_PICC){
1296 if(net_nfc_jewel_read_id(id, NULL) != NET_NFC_OK){
1297 PRINT_INFO("failed to read ID");
1302 }else if(type == NET_NFC_FELICA_PICC){
1305 net_nfc_error_e result = NET_NFC_OK;
1308 if((result = net_nfc_felica_poll(id, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST, 0x0, NULL)) != NET_NFC_OK){
1309 PRINT_INFO("can not execute cmd felica poll");
1312 PRINT_INFO("send poll req cmd is success");
1315 if((result = net_nfc_felica_request_system_code(id, NULL)) != NET_NFC_OK){
1316 PRINT_INFO("can not execute cmd felica request system code");
1319 PRINT_INFO("send request system req cmd is success");
1322 if((result = net_nfc_felica_request_response(id, NULL)) != NET_NFC_OK){
1323 PRINT_INFO("can not execute cmd felica request response");
1326 PRINT_INFO("send request response cmd is success");
1329 uint16_t service_code = 0xffff;
1330 if((result = net_nfc_felica_request_service(id, 1, &service_code, 1, NULL)) != NET_NFC_OK){
1331 PRINT_INFO("can not execute cmd felica request response");
1334 PRINT_INFO("send request response cmd is success");
1338 uint16_t service_code = 0xffff;
1339 uint8_t blocks = 0x2;
1341 if((result = net_nfc_felica_read_without_encryption(id, 1, &service_code, 1, &blocks, NULL)) != NET_NFC_OK){
1342 PRINT_INFO("can not execute cmd felica request response");
1345 PRINT_INFO("send request response cmd is success");
1351 case NET_NFC_MESSAGE_TRANSCEIVE:{
1352 if (result == NET_NFC_OK) {
1354 if(test_count == 0){
1356 data_h r_data = (data_h) data;
1358 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1359 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1361 PRINT_INFO ("read uid is ok. format is = > [HeadRom0][HeadRom1][UID0][UID1][UID2][UID3]");
1362 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1364 for (idx = 0; idx < r_buffer_length; idx++){
1365 printf (" %02X", r_buffer[idx]);
1368 PRINT_INFO("READ ALL DATA");
1369 if((result = net_nfc_jewel_read_all(tag_handle, NULL)) != NET_NFC_OK){
1370 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1375 else if(test_count == 1){
1377 data_h r_data = (data_h) data;
1379 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1380 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1382 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1384 for (idx = 0; idx < r_buffer_length; idx++){
1385 printf (" %02X", r_buffer[idx]);
1388 test_case_result = NET_NFC_TEST_OK;
1392 PRINT_INFO("READ one byte. addr is the first byte of block 0");
1393 if((result = net_nfc_jewel_read_byte(tag_handle, 0, 0, NULL)) != NET_NFC_OK){
1394 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1400 else if(test_count == 2){
1402 data_h r_data = (data_h) data;
1404 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1405 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1407 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1409 for (idx = 0; idx < r_buffer_length; idx++){
1410 printf (" %02X", r_buffer[idx]);
1413 test_case_result = NET_NFC_TEST_OK;
1416 PRINT_INFO("erase and write data 0xff . addr is the first byte of block 1");
1417 if((result = net_nfc_jewel_write_with_erase(tag_handle, 1, 0, 0xff, NULL)) != NET_NFC_OK){
1418 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1423 else if(test_count == 3){
1425 data_h r_data = (data_h) data;
1427 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1428 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1430 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1432 for (idx = 0; idx < r_buffer_length; idx++){
1433 printf (" %02X", r_buffer[idx]);
1436 test_case_result = NET_NFC_TEST_OK;
1439 PRINT_INFO("read one byte . addr is the first byte of block 1");
1440 if((result = net_nfc_jewel_read_byte(tag_handle, 1, 0, NULL)) != NET_NFC_OK){
1441 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1446 else if(test_count == 4){
1449 data_h r_data = (data_h) data;
1451 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1452 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1454 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1456 for (idx = 0; idx < r_buffer_length; idx++){
1457 printf (" %02X", r_buffer[idx]);
1460 else if(test_count == 5){
1461 PRINT_INFO("auth key A is success = [%d]", result);
1462 test_case_result = NET_NFC_TEST_OK;
1463 net_nfc_error_e result = NET_NFC_OK;
1465 if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
1467 PRINT_INFO("failed to read = [%d]", result);
1469 PRINT_INFO("calling read is ok");
1478 PRINT_INFO("trancecive is failed with %d\n", result);
1479 test_case_result = NET_NFC_TEST_FAIL;
1481 //pthread_mutex_lock (&plock);
1482 //pthread_cond_signal (&pcond);
1483 //pthread_mutex_unlock (&plock);
1493 #define NUM_OF_THREAD 10
1494 #define REQUEST_PER_THREAD 5
1496 static number_of_read_completed = 0;
1498 static void* net_nfc_read_ndef_test(void* handle)
1500 net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
1503 for (count = 0; count < REQUEST_PER_THREAD ; count ++)
1505 if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
1507 PRINT_INFO("send request is success");
1511 PRINT_INFO("send request is failed");
1515 return (void *)NULL;
1517 static void net_nfc_test_multiple_request_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
1521 printf ("callback is called with message %d\n", message);
1525 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1527 net_nfc_target_type_e type;
1528 net_nfc_target_handle_h handle;
1530 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1532 net_nfc_get_tag_type (target_info, &type);
1533 net_nfc_get_tag_handle (target_info, &handle);
1534 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1535 PRINT_INFO("target type: %d\n", type);
1536 PRINT_INFO("target handle: %X\n", handle);
1537 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1539 test_case_result = NET_NFC_TEST_OK;
1540 number_of_read_completed = 0;
1542 pthread_t read_thread[NUM_OF_THREAD];
1543 pthread_attr_t attr;
1544 pthread_attr_init(&attr);
1545 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1548 for(; i < NUM_OF_THREAD; i++)
1550 pthread_create(&read_thread[i], &attr, net_nfc_read_ndef_test, handle);
1556 case NET_NFC_MESSAGE_READ_NDEF:
1558 PRINT_INFO("NET_NFC_MESSAGE_READ_NDEF result = [%d]\n", result);
1562 PRINT_INFO("read ndef msg");
1563 number_of_read_completed ++;
1565 ndef_message_h ndef = (ndef_message_h)(data);
1567 ////net_nfc_ndef_print_message(ndef);
1569 if (number_of_read_completed == NUM_OF_THREAD * REQUEST_PER_THREAD)
1571 test_case_result = NET_NFC_TEST_OK;
1572 PRINT_INSTRUCT("Test is completed. please remove the tag !!");
1578 case NET_NFC_MESSAGE_TAG_DETACHED:
1580 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
1582 pthread_mutex_lock (&plock);
1583 pthread_cond_signal (&pcond);
1584 pthread_mutex_unlock (&plock);
1588 case NET_NFC_MESSAGE_NOTIFY:
1590 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1599 #define NUM_OF_DETECT_TRY 10
1601 static void net_nfc_test_detected_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
1605 printf ("callback is called with message %d\n", message);
1609 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1611 net_nfc_target_type_e type;
1612 net_nfc_target_handle_h id;
1614 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1616 net_nfc_get_tag_type (target_info, &type);
1617 net_nfc_get_tag_handle (target_info, &id);
1618 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1620 PRINT_INFO("target type: %d\n", type);
1621 PRINT_INFO("target handle: %X\n", id);
1622 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1625 int nok = 0; // number of keys
1626 net_nfc_error_e error = NET_NFC_OK;
1628 if((error = net_nfc_get_tag_info_keys(target_info, &keys, &nok)) == NET_NFC_OK)
1633 PRINT_INFO("key [%s]", keys[i]);
1635 data_h value = NULL;
1636 if((error = net_nfc_get_tag_info_value(target_info, keys[i], &value)) == NET_NFC_OK)
1639 uint32_t data_length = net_nfc_get_data_length(value);
1640 uint8_t* data_buffer = net_nfc_get_data_buffer(value);
1642 PRINT_INFO("\n key >> ", keys[i]);
1645 for(; index < data_length; index++)
1647 printf(" [0x%x] ", data_buffer[index]);
1652 printf(" [0x%x] ", *data_buffer);
1656 PRINT_INFO("<< \n");
1660 PRINT_INFO("get value is failed = [0x%x]", error);
1666 PRINT_INFO("failed to get keys = [%d]", error);
1674 PRINT_INFO("TAG is detected = [%d]", detect_count);
1675 PRINT_INSTRUCT("please remove the tag !! Test left [%d] times", NUM_OF_DETECT_TRY - detect_count);
1680 case NET_NFC_MESSAGE_TAG_DETACHED:
1682 PRINT_INSTRUCT("please close the tag again!!");
1684 //pthread_mutex_lock (&plock);
1685 //pthread_cond_signal (&pcond);
1686 //pthread_mutex_unlock (&plock);
1688 if(detect_count >= NUM_OF_DETECT_TRY)
1690 test_case_result = NET_NFC_TEST_OK;
1691 pthread_mutex_lock (&plock);
1692 pthread_cond_signal (&pcond);
1693 pthread_mutex_unlock (&plock);
1698 case NET_NFC_MESSAGE_NOTIFY:
1700 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1710 static void* net_nfc_read_stress_ndef_test(void* handle)
1712 net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
1715 for (count = 0; count < 200 ; count ++)
1717 if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
1722 PRINT_INFO("send request is failed");
1726 PRINT_INFO("send request is completed");
1728 return (void *)NULL;
1731 static void net_nfc_test_read_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
1737 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1739 net_nfc_target_type_e type;
1740 net_nfc_target_handle_h handle;
1742 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1744 net_nfc_get_tag_type (target_info, &type);
1745 net_nfc_get_tag_handle (target_info, &handle);
1746 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1747 PRINT_INFO("target type: %d\n", type);
1748 PRINT_INFO("target handle: %X\n", handle);
1749 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1753 pthread_t read_thread;
1754 pthread_attr_t attr;
1755 pthread_attr_init(&attr);
1756 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1758 pthread_create(&read_thread, &attr, net_nfc_read_stress_ndef_test, handle);
1762 PRINT_INFO("non ndef tag.");
1764 test_case_result = NET_NFC_TEST_FAIL;
1766 pthread_mutex_lock (&plock);
1767 pthread_cond_signal (&pcond);
1768 pthread_mutex_unlock (&plock);
1774 case NET_NFC_MESSAGE_READ_NDEF:
1778 ndef_message_h ndef = (ndef_message_h)(data);
1780 ////net_nfc_ndef_print_message(ndef);
1782 test_case_result = NET_NFC_TEST_OK;
1787 if(read_count == 20)
1789 PRINT_INSTRUCT("please remove the tag !!");
1796 case NET_NFC_MESSAGE_TAG_DETACHED:
1798 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
1800 if (read_count >= 20 && read_count < 200){
1801 test_case_result = NET_NFC_TEST_OK;
1802 pthread_mutex_lock (&plock);
1803 pthread_cond_signal (&pcond);
1804 pthread_mutex_unlock (&plock);
1807 PRINT_INSTRUCT("please close the tag again !!");
1814 case NET_NFC_MESSAGE_NOTIFY:
1816 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1826 static void net_nfc_test_read_write_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
1830 printf ("callback is called with message %d\n", message);
1834 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1836 net_nfc_target_type_e type;
1837 net_nfc_target_handle_h handle;
1839 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1841 net_nfc_get_tag_type (target_info, &type);
1842 net_nfc_get_tag_handle (target_info, &handle);
1843 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1844 PRINT_INFO("target type: %d\n", type);
1845 PRINT_INFO("target handle: %X\n", handle);
1846 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1850 tag_handle = handle;
1851 if(net_nfc_read_tag(handle, user_param) == NET_NFC_OK)
1853 PRINT_INFO("try to read ndef");
1858 PRINT_INFO("non ndef tag.");
1860 test_case_result = NET_NFC_TEST_FAIL;
1862 pthread_mutex_lock (&plock);
1863 pthread_cond_signal (&pcond);
1864 pthread_mutex_unlock (&plock);
1870 case NET_NFC_MESSAGE_READ_NDEF:
1872 if (write_count >= 50){
1873 PRINT_INSTRUCT("Test is finished. Please remove the tag from device!!");
1874 test_case_result = NET_NFC_TEST_OK;
1879 ndef_message_h ndef = (ndef_message_h)(data);
1881 ////net_nfc_ndef_print_message(ndef);
1883 test_case_result = NET_NFC_TEST_OK;
1885 net_nfc_error_e error = NET_NFC_OK;
1886 ndef_message_h msg = NULL;
1887 ndef_record_h record = NULL;
1889 if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
1891 if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
1893 if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
1895 ////net_nfc_ndef_print_message(msg);
1897 if(net_nfc_write_ndef(tag_handle, msg, &user_context) == NET_NFC_OK)
1899 PRINT_INFO("write count = [%d] \n", write_count++);
1900 PRINT_INFO("write ndef msg");
1902 net_nfc_free_ndef_message(msg);
1906 PRINT_INFO("failed to append ndef message = [%d]", error);
1907 net_nfc_free_record(record);
1908 net_nfc_free_ndef_message(msg);
1910 pthread_mutex_lock (&plock);
1911 pthread_cond_signal (&pcond);
1912 pthread_mutex_unlock (&plock);
1917 PRINT_INFO("failed to create ndef msg");
1918 net_nfc_free_record(record);
1920 pthread_mutex_lock (&plock);
1921 pthread_cond_signal (&pcond);
1922 pthread_mutex_unlock (&plock);
1927 PRINT_INFO("failed to create text type record");
1929 pthread_mutex_lock (&plock);
1930 pthread_cond_signal (&pcond);
1931 pthread_mutex_unlock (&plock);
1938 test_case_result = NET_NFC_TEST_FAIL;
1940 pthread_mutex_lock (&plock);
1941 pthread_cond_signal (&pcond);
1942 pthread_mutex_unlock (&plock);
1947 //net_nfc_read_ndef(tag_handle, user_param);
1953 case NET_NFC_MESSAGE_WRITE_NDEF:
1955 if (result == NET_NFC_OK) {
1957 test_case_result = NET_NFC_TEST_OK;
1959 if(net_nfc_read_tag(tag_handle, user_param) == NET_NFC_OK)
1961 PRINT_INFO("read count = [%d] \n", read_count++);
1962 PRINT_INFO("try to read ndef");
1966 PRINT_INFO("received error: %d\n", result);
1967 test_case_result = NET_NFC_TEST_FAIL;
1969 pthread_mutex_lock (&plock);
1970 pthread_cond_signal (&pcond);
1971 pthread_mutex_unlock (&plock);
1976 case NET_NFC_MESSAGE_TAG_DETACHED:
1978 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
1980 pthread_mutex_lock (&plock);
1981 pthread_cond_signal (&pcond);
1982 pthread_mutex_unlock (&plock);
1986 case NET_NFC_MESSAGE_NOTIFY:
1988 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1998 int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2)
2000 int user_context = 0;
2001 net_nfc_error_e result;
2002 test_case_result = NET_NFC_TEST_FAIL;
2004 result = net_nfc_initialize();
2005 CHECK_RESULT(result);
2007 net_nfc_state_activate(1);
2009 result = net_nfc_set_response_callback (net_nfc_test_multiple_request_cb, NULL);
2010 CHECK_RESULT(result);
2012 PRINT_INSTRUCT("Please close a tag to device for a while!!");
2014 //pthread_cond_wait (&pcond,&plock );
2016 result = net_nfc_unset_response_callback ();
2017 CHECK_RESULT(result);
2019 result = net_nfc_deinitialize ();
2020 CHECK_RESULT(result);
2022 return test_case_result;
2026 int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2)
2028 int user_context = 0;
2029 net_nfc_error_e result;
2030 test_case_result = NET_NFC_TEST_FAIL;
2039 for(i; i < NET_NFC_NFCIP1_INITIATOR; i++)
2041 if(net_nfc_get_tag_info_keys(i, &keys, &length) == NET_NFC_OK)
2045 PRINT_INFO("############################\n") ;
2046 for(; index < length; index++)
2048 PRINT_INFO("supported key = [%s] \n", keys[index]);
2050 PRINT_INFO("############################\n") ;
2052 test_case_result = NET_NFC_TEST_OK;
2057 result = net_nfc_initialize();
2058 CHECK_RESULT(result);
2060 net_nfc_state_activate(1);
2062 result = net_nfc_set_response_callback (net_nfc_test_detected_cb, NULL);
2064 // net_nfc_set_tag_filter(NET_NFC_ALL_DISABLE);
2065 // net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE);
2066 // net_nfc_set_tag_filter(NET_NFC_ISO14443B_ENABLE);
2067 // net_nfc_set_tag_filter(NET_NFC_ISO15693_ENABLE );
2068 // net_nfc_set_tag_filter(NET_NFC_FELICA_ENABLE );
2069 // net_nfc_set_tag_filter(NET_NFC_JEWEL_ENABLE );
2070 // net_nfc_set_tag_filter(NET_NFC_ALL_ENABLE );
2073 CHECK_RESULT(result);
2075 //PRINT_INSTRUCT("Please close a tag to device!!");
2077 //pthread_cond_wait (&pcond,&plock );
2080 result = net_nfc_unset_response_callback ();
2081 CHECK_RESULT(result);
2083 result = net_nfc_deinitialize ();
2087 CHECK_RESULT(result);
2090 return test_case_result;
2093 int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2)
2095 int user_context = 0;
2096 net_nfc_error_e result;
2097 test_case_result = NET_NFC_TEST_FAIL;
2099 result = net_nfc_initialize();
2100 CHECK_RESULT(result);
2102 net_nfc_state_activate(1);
2106 result = net_nfc_set_response_callback (net_nfc_test_read_cb, NULL);
2107 CHECK_RESULT(result);
2109 PRINT_INSTRUCT("remove tag while reading operation !!");
2110 PRINT_INSTRUCT("Please close a tag to device!!");
2113 pthread_cond_wait (&pcond,&plock );
2115 result = net_nfc_unset_response_callback ();
2116 CHECK_RESULT(result);
2118 result = net_nfc_deinitialize ();
2119 CHECK_RESULT(result);
2121 return test_case_result;
2124 int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2)
2126 int user_context = 0;
2127 net_nfc_error_e result;
2128 test_case_result = NET_NFC_TEST_FAIL;
2130 ndef_message_h ndef_message = NULL;
2132 if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK)
2135 if(net_nfc_get_ndef_message_record_count(ndef_message, &count) == NET_NFC_OK)
2138 for(; i < count; i++)
2140 ndef_record_h record = NULL;
2141 if(net_nfc_get_record_by_index(ndef_message, i, &record) == NET_NFC_OK)
2143 net_nfc_record_tnf_e tnf;
2144 if(net_nfc_get_record_tnf(record, &tnf) == NET_NFC_OK)
2148 case NET_NFC_RECORD_WELL_KNOWN_TYPE:
2151 data_h payload = NULL;
2153 if(net_nfc_get_record_type(record, &type) == NET_NFC_OK && net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
2155 if(strcmp(net_nfc_get_data_buffer(type), "Sp") == 0)
2159 else if(strcmp(net_nfc_get_data_buffer(type), "T") == 0)
2162 net_nfc_encode_type_e utf;
2163 uint32_t utf_length = 0;
2164 uint32_t lang_length = 0;
2166 uint32_t text_length = 0;
2167 char* language_code_str = NULL;
2169 if(net_nfc_get_encoding_type_from_text_record(record, &utf) == NET_NFC_OK)
2171 PRINT_INFO("utf = [%s]", utf);
2175 PRINT_INFO("failed to get utf");
2178 if(net_nfc_get_languange_code_string_from_text_record(record, &language_code_str) == NET_NFC_OK)
2180 PRINT_INFO("language_code = [%s]", language_code_str);
2184 PRINT_INFO("failed to get language code");
2187 if(net_nfc_create_text_string_from_text_record(record, &text) == NET_NFC_OK)
2189 PRINT_INFO("text = [%s]", text);
2193 PRINT_INFO("failed to get text");
2199 uint8_t* utf = NULL;
2200 uint8_t* language_code = NULL;
2201 uint8_t* text = NULL;
2204 uint8_t* buffer = net_nfc_get_data_buffer(payload);
2205 uint32_t buffer_length = net_nfc_get_data_length(payload);
2207 PRINT_INFO("\n from file >>>");
2209 for(; index < buffer_length; index++)
2211 printf(" [%d] ", buffer[index]);
2214 PRINT_INFO("\n from file <<<");
2218 int controllbyte = buffer[0];
2220 if((controllbyte & 0x80)== 1)
2222 PRINT_INFO("UTF-16");
2223 utf = (uint8_t*)"UTF-16";
2227 PRINT_INFO("UTF-8");
2228 utf = (uint8_t*)"UTF-8";
2231 int lang_code_length = controllbyte & 0x3F;
2235 language_code = (uint8_t *)malloc(lang_code_length + 1);
2237 memset(language_code, 0x00, lang_code_length + 1);
2238 memcpy(language_code, &(buffer[index]), lang_code_length);
2240 PRINT_INFO("lang_code = [%s]", language_code);
2242 index = lang_code_length + 1;
2244 int text_length = buffer_length - (lang_code_length + 1); // payload length - (lang code length + control byte)
2246 PRINT_INFO("buffer length = [%d]", buffer_length);
2247 PRINT_INFO("lang_code_length = [%d]", lang_code_length);
2248 PRINT_INFO("text_length = [%d]", text_length);
2250 text = (uint8_t *)malloc(text_length + 1);
2252 memset(text, 0x00, text_length + 1);
2253 memcpy(text, &(buffer[index]), text_length);
2255 PRINT_INFO("encoding type = [%s]", utf);
2256 PRINT_INFO("lang_code = [%s]", language_code);
2257 PRINT_INFO("text = [%s]", text);
2258 test_case_result = NET_NFC_TEST_OK;
2261 else if(strcmp(net_nfc_get_data_buffer(type), "U") == 0)
2275 PRINT_INFO("unknow type");
2285 CHECK_RESULT(result);
2287 return test_case_result;
2290 int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2)
2292 int user_context = 0;
2293 net_nfc_error_e result;
2294 test_case_result = NET_NFC_TEST_FAIL;
2296 result = net_nfc_initialize();
2297 CHECK_RESULT(result);
2299 net_nfc_state_activate(1);
2301 result = net_nfc_set_response_callback (net_nfc_test_transceive_cb, NULL);
2302 CHECK_RESULT(result);
2304 PRINT_INSTRUCT("Please close a tag to device!!");
2306 //pthread_cond_wait (&pcond,&plock );
2308 result = net_nfc_unset_response_callback ();
2309 CHECK_RESULT(result);
2310 result = net_nfc_deinitialize ();
2311 CHECK_RESULT(result);
2314 return test_case_result;
2317 /*=================================================================================*/
2320 int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2)
2322 net_nfc_error_e result;
2324 ndef_message_h uriMsg = NULL;
2325 ndef_message_h spMsg = NULL;
2326 ndef_record_h uriRecord = NULL;
2327 ndef_record_h spRecord = NULL;
2328 data_h type_data = NULL;
2329 data_h raw_data = NULL;
2330 char smart_poster_type[] = "Sp";
2331 ndef_record_h record = NULL;
2332 test_case_result = NET_NFC_TEST_OK;
2334 result = net_nfc_create_ndef_message (&uriMsg);
2335 CHECK_RESULT(result);
2337 result = net_nfc_create_uri_type_record (&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
2338 CHECK_RESULT(result);
2340 result = net_nfc_append_record_to_ndef_message (uriMsg, record);
2341 CHECK_RESULT(result);
2345 result = net_nfc_create_text_type_record (&record ,"This is the URI Test" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2346 CHECK_RESULT(result);
2348 result = net_nfc_append_record_to_ndef_message (uriMsg, record);
2349 CHECK_RESULT(result);
2351 result = net_nfc_create_text_type_record (&record ,"Hello World" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2352 CHECK_RESULT(result);
2354 result = net_nfc_append_record_by_index (uriMsg,0 ,record);
2355 CHECK_RESULT(result);
2357 result = net_nfc_create_text_type_record (&record ,"TEST1" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2358 CHECK_RESULT(result);
2360 result = net_nfc_append_record_by_index (uriMsg,1 ,record);
2361 CHECK_RESULT(result);
2363 result = net_nfc_create_text_type_record (&record ,"TEST2" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2364 CHECK_RESULT(result);
2366 result = net_nfc_append_record_by_index (uriMsg,2 ,record);
2367 CHECK_RESULT(result);
2369 result = net_nfc_create_text_type_record (&record ,"TEST3" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2370 CHECK_RESULT(result);
2373 result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
2374 CHECK_RESULT(result);
2376 result = net_nfc_append_record_by_index (uriMsg, position ,record);
2377 CHECK_RESULT(result);
2379 //_//net_nfc_ndef_print_message (uriMsg);
2381 result = net_nfc_create_data (&type_data ,"U", 1);
2382 CHECK_RESULT(result);
2384 result = net_nfc_search_record_by_type (uriMsg ,NET_NFC_RECORD_WELL_KNOWN_TYPE ,type_data ,&record);
2385 CHECK_RESULT(result);
2386 if (record != uriRecord){
2387 PRINT_RESULT_FAIL("Record search result does not matched");
2388 return NET_NFC_TEST_FAIL;
2391 result = net_nfc_remove_record_by_index (uriMsg ,1);
2392 CHECK_RESULT(result);
2394 result = net_nfc_remove_record_by_index (uriMsg ,0);
2395 CHECK_RESULT(result);
2397 result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
2398 CHECK_RESULT(result);
2400 result = net_nfc_remove_record_by_index (uriMsg, position - 1);
2401 CHECK_RESULT(result);
2403 result = net_nfc_remove_record_by_index (uriMsg ,2);
2404 CHECK_RESULT(result);
2406 //_//net_nfc_ndef_print_message (uriMsg);
2408 result = net_nfc_create_rawdata_from_ndef_message (uriMsg, &raw_data);
2409 CHECK_RESULT(result);
2411 result = net_nfc_create_data (&type_data, smart_poster_type, strlen (smart_poster_type));
2412 CHECK_RESULT(result);
2414 result = net_nfc_create_record (&spRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE,type_data , NULL, raw_data);
2415 CHECK_RESULT(result);
2417 result = net_nfc_create_ndef_message (&spMsg);
2418 CHECK_RESULT(result);
2420 result = net_nfc_append_record_to_ndef_message (spMsg, spRecord);
2421 CHECK_RESULT(result);
2423 net_nfc_free_data (type_data);
2424 net_nfc_free_data (raw_data);
2426 return test_case_result;
2429 /*=================================================================================*/
2431 net_nfc_llcp_socket_t server_socket;
2432 net_nfc_llcp_socket_t accepted_socket;
2433 net_nfc_llcp_socket_t client_socket;
2435 static void net_nfc_client_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
2437 PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
2441 case NET_NFC_MESSAGE_LLCP_LISTEN:
2443 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2445 case NET_NFC_MESSAGE_LLCP_CONNECT:
2447 PRINT_INFO ("LLCP connect is completed with error code %d", result);
2449 char * str = "Client message: Hello, server!";
2450 net_nfc_create_data (&data, str ,strlen (str) + 1);
2451 net_nfc_send_llcp (client_socket, data, NULL);
2454 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2456 case NET_NFC_MESSAGE_LLCP_SEND:
2458 PRINT_INFO ("LLCP send is completed with error code %d", result);
2459 net_nfc_receive_llcp (client_socket, 512 ,NULL);
2463 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2464 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2465 data_h received_data = (data_h) data;
2466 PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
2468 net_nfc_disconnect_llcp (client_socket ,NULL);
2470 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2472 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2473 net_nfc_close_llcp_socket (client_socket, NULL);
2476 case NET_NFC_MESSAGE_LLCP_ERROR:
2477 PRINT_INFO ("LLCP socket error is completed with error code %d", result);
2478 net_nfc_close_llcp_socket (client_socket, NULL);
2487 static void net_nfc_server_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
2489 PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
2492 case NET_NFC_MESSAGE_LLCP_LISTEN:
2494 PRINT_INFO ("LLCP Listen is completed with error code %d", result);
2498 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2500 PRINT_INFO ("LLCP accept is completed with error code %d", result);
2501 accepted_socket = *(net_nfc_llcp_socket_t *)(data);
2502 net_nfc_set_llcp_socket_callback (accepted_socket, net_nfc_server_socket_cb, NULL);
2503 net_nfc_receive_llcp (accepted_socket, 512 ,NULL);
2506 case NET_NFC_MESSAGE_LLCP_CONNECT:
2508 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2510 case NET_NFC_MESSAGE_LLCP_SEND:
2512 PRINT_INFO ("LLCP send is completed with error code %d", result);
2513 net_nfc_disconnect_llcp (accepted_socket ,NULL);
2517 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2519 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2520 data_h received_data = (data_h) data;
2521 PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
2524 char * str = "Server message: Welcome NFC llcp world!";
2525 net_nfc_create_data (&data, str ,strlen (str) + 1);
2526 net_nfc_send_llcp (accepted_socket, data, NULL);
2530 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2532 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2533 net_nfc_close_llcp_socket (accepted_socket, NULL);
2536 case NET_NFC_MESSAGE_LLCP_ERROR:
2538 PRINT_INFO ("LLCP socket error is received with code %d", result);
2539 net_nfc_close_llcp_socket (accepted_socket, NULL);
2540 net_nfc_close_llcp_socket (server_socket, NULL);
2548 net_nfc_target_handle_h snep_handle;
2549 net_nfc_exchanger_data_h snep_ex_data = NULL;
2552 static void net_nfc_test_snep_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
2554 PRINT_INFO ("client message received [%d]", message);
2558 case NET_NFC_MESSAGE_P2P_DISCOVERED:
2560 snep_handle = (net_nfc_target_handle_h) data;
2561 //= (net_nfc_target_handle_h) target_info->handle;
2562 /* Fill the data to send. */
2564 if(NET_NFC_OK == net_nfc_create_exchanger_data(&snep_ex_data, nfcTestUri))
2566 if(net_nfc_send_exchanger_data(snep_ex_data, snep_handle) == NET_NFC_OK)
2568 PRINT_INFO ("exchanger data send success");
2572 PRINT_INFO ("exchanger data send fail");
2577 PRINT_INFO ("create exchanger data fail");
2583 case NET_NFC_MESSAGE_P2P_SEND:
2585 PRINT_INFO ("NET_NFC_MESSAGE_P2P_SEND result [%d]", result);
2590 case NET_NFC_MESSAGE_P2P_DETACHED:
2592 PRINT_INFO ("Target disconnected.");
2597 case NET_NFC_MESSAGE_P2P_RECEIVE:
2600 // data_h received_data = (data_h)data;
2602 // PRINT_INFO ("NET_NFC_MESSAGE_P2P_RECEIVE [%s]", net_nfc_get_data_buffer(received_data));
2603 // PRINT_INFO (" length [%d]", net_nfc_get_data_length(received_data));
2612 static void net_nfc_test_llcp_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
2616 case NET_NFC_MESSAGE_LLCP_DISCOVERED:
2618 net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
2619 uint8_t lto, option;
2621 net_nfc_get_llcp_configure_lto (config , <o);
2622 net_nfc_get_llcp_configure_wks (config , &wks);
2623 net_nfc_get_llcp_configure_miu (config , &miu);
2624 net_nfc_get_llcp_configure_option (config , &option);
2626 PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
2628 net_nfc_create_llcp_socket (&server_socket, NULL);
2629 net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_socket_cb, NULL);
2630 net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
2632 net_nfc_create_llcp_socket (&client_socket, NULL);
2633 net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_socket_cb, NULL);
2634 net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
2638 case NET_NFC_MESSAGE_LLCP_CONFIG:
2640 PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
2644 case NET_NFC_MESSAGE_P2P_DETACHED:
2646 PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
2655 int nfcTestSnep(uint8_t testNumber,void* arg_ptr)
2657 net_nfc_error_e result;
2659 result = net_nfc_initialize();
2660 CHECK_RESULT(result);
2661 net_nfc_state_activate (1);
2662 result = net_nfc_set_response_callback (net_nfc_test_snep_cb, NULL);
2664 PRINT_INSTRUCT("START SNEP test !!");
2665 return NET_NFC_TEST_OK;
2668 int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2)
2670 net_nfc_error_e result;
2671 net_nfc_llcp_config_info_h config;
2672 result = net_nfc_initialize();
2673 CHECK_RESULT(result);
2674 net_nfc_state_activate (1);
2675 result = net_nfc_set_response_callback (net_nfc_test_llcp_cb, NULL);
2676 CHECK_RESULT(result);
2677 result = net_nfc_create_llcp_configure_default (&config);
2678 CHECK_RESULT(result);
2679 result = net_nfc_set_llcp_local_configure (config ,NULL);
2681 PRINT_INSTRUCT("Please start P2P communicate!!");
2684 pthread_cond_wait (&pcond,&plock );
2686 result = net_nfc_unset_response_callback ();
2687 CHECK_RESULT(result);
2688 result = net_nfc_deinitialize ();
2689 CHECK_RESULT(result);
2692 return NET_NFC_TEST_OK;
2695 /*=================================================================================*/
2697 /* LLCP Stress Test */
2699 net_nfc_llcp_socket_t server_socket;
2700 net_nfc_llcp_socket_t client_socket;
2702 static void net_nfc_client_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
2704 PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
2708 case NET_NFC_MESSAGE_LLCP_LISTEN:
2710 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2712 case NET_NFC_MESSAGE_LLCP_CONNECT:
2714 PRINT_INFO ("LLCP connect is completed with error code %d", result);
2716 char * str = "Client message: Hello, server!";
2717 net_nfc_create_data (&data, str ,strlen (str) + 1);
2718 net_nfc_send_llcp (client_socket, data, NULL);
2721 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2723 case NET_NFC_MESSAGE_LLCP_SEND:
2725 PRINT_INFO ("LLCP send is completed with error code %d", result);
2726 net_nfc_receive_llcp (client_socket, 512 ,NULL);
2730 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2731 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2732 data_h received_data = (data_h) data;
2733 PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
2735 net_nfc_disconnect_llcp (client_socket ,NULL);
2737 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2739 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2740 net_nfc_close_llcp_socket (client_socket, NULL);
2743 case NET_NFC_MESSAGE_LLCP_ERROR:
2744 PRINT_INFO ("LLCP socket error is completed with error code %d", result);
2745 net_nfc_close_llcp_socket (client_socket, NULL);
2754 static void net_nfc_server_stress_socket_cb (net_nfc_llcp_message_e message, net_nfc_error_e result, void * data, void * user_data, void * trans_data)
2756 PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
2759 case NET_NFC_MESSAGE_LLCP_LISTEN:
2761 PRINT_INFO ("LLCP Listen is completed with error code %d", result);
2765 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2767 PRINT_INFO ("LLCP accept is completed with error code %d", result);
2768 net_nfc_receive_llcp (server_socket, 512 ,NULL);
2771 case NET_NFC_MESSAGE_LLCP_CONNECT:
2773 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2775 case NET_NFC_MESSAGE_LLCP_SEND:
2777 PRINT_INFO ("LLCP send is completed with error code %d", result);
2778 net_nfc_disconnect_llcp (server_socket ,NULL);
2782 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2784 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2785 data_h received_data = (data_h) data;
2786 PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
2789 char * str = "Server message: Welcome NFC llcp world!";
2790 net_nfc_create_data (&data, str ,strlen (str) + 1);
2791 net_nfc_send_llcp (server_socket, data, NULL);
2795 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2797 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2798 net_nfc_close_llcp_socket (server_socket, NULL);
2802 case NET_NFC_MESSAGE_LLCP_ERROR:
2804 PRINT_INFO ("LLCP socket error is received with code %d", result);
2805 net_nfc_close_llcp_socket (server_socket, NULL);
2813 static void net_nfc_test_llcp_stress_cb(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
2817 case NET_NFC_MESSAGE_LLCP_DISCOVERED:
2819 net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
2820 uint8_t lto, option;
2822 net_nfc_get_llcp_configure_lto (config , <o);
2823 net_nfc_get_llcp_configure_wks (config , &wks);
2824 net_nfc_get_llcp_configure_miu (config , &miu);
2825 net_nfc_get_llcp_configure_option (config , &option);
2827 PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
2829 net_nfc_create_llcp_socket (&server_socket, NULL);
2830 net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_stress_socket_cb, NULL);
2831 net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
2833 net_nfc_create_llcp_socket (&client_socket, NULL);
2834 net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_stress_socket_cb, NULL);
2835 net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
2839 case NET_NFC_MESSAGE_LLCP_CONFIG:
2841 PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
2845 case NET_NFC_MESSAGE_P2P_DETACHED:
2847 PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
2856 int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2)
2858 net_nfc_error_e result;
2859 net_nfc_llcp_config_info_h config;
2860 result = net_nfc_initialize();
2861 CHECK_RESULT(result);
2862 net_nfc_state_activate (1);
2863 result = net_nfc_set_response_callback (net_nfc_test_llcp_stress_cb, NULL);
2864 CHECK_RESULT(result);
2865 result = net_nfc_create_llcp_configure_default (&config);
2866 CHECK_RESULT(result);
2867 result = net_nfc_set_llcp_local_configure (config ,NULL);
2869 PRINT_INSTRUCT("Please start P2P communicate!!");
2871 pthread_cond_wait (&pcond,&plock );
2873 result = net_nfc_unset_response_callback ();
2874 CHECK_RESULT(result);
2875 result = net_nfc_deinitialize ();
2876 CHECK_RESULT(result);
2879 return NET_NFC_TEST_OK;
2882 /*=================================================================================*/
2885 static void net_nfc_test_API_exception_cb1(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
2887 PRINT_INFO ("Message is received 1 %d", result);
2888 test_case_result = NET_NFC_TEST_FAIL;
2889 pthread_mutex_lock (&plock);
2890 pthread_cond_signal (&pcond);
2891 pthread_mutex_unlock (&plock);
2894 static void net_nfc_test_API_exception_cb2(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
2896 PRINT_INFO ("Message is received 2 %d", result);
2897 test_case_result = NET_NFC_TEST_FAIL;
2898 pthread_mutex_lock (&plock);
2899 pthread_cond_signal (&pcond);
2900 pthread_mutex_unlock (&plock);
2903 static void net_nfc_test_API_exception_cb3(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
2905 PRINT_INFO ("Message is received 3 %d", result);
2906 test_case_result = NET_NFC_TEST_OK;
2907 pthread_mutex_lock (&plock);
2908 pthread_cond_signal (&pcond);
2909 pthread_mutex_unlock (&plock);
2915 int nfcTestAPIException (uint8_t testNumber,void* arg_ptr)
2917 net_nfc_error_e result;
2918 test_case_result = NET_NFC_TEST_FAIL;
2920 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
2921 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_ALREADY_INITIALIZED);
2922 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
2925 for (count_try = 0; count_try < 20; count_try ++)
2927 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
2928 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
2931 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
2932 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
2935 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
2937 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb1, NULL));
2938 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
2939 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
2940 net_nfc_state_activate (1);
2942 PRINT_INSTRUCT("Please close a tag to device!!");
2944 pthread_cond_wait (&pcond,&plock );
2945 if (!test_case_result) return test_case_result;
2947 PRINT_INSTRUCT("Please remove the tag from device!!");
2948 pthread_cond_wait (&pcond,&plock );
2950 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
2951 CHECK_ASSULT (NET_NFC_OK != net_nfc_set_response_callback (NULL, NULL));
2953 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
2954 CHECK_ASSULT (NET_NFC_OK == net_nfc_unset_response_callback ());
2956 PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
2959 for (idx = 10 ;idx > 0 ; idx --)
2961 PRINT_INSTRUCT("count down [%d]", idx);
2964 if (!test_case_result) return test_case_result;
2966 PRINT_INSTRUCT("Please remove the tag from device!!");
2969 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
2970 net_nfc_state_activate (1);
2971 net_nfc_state_activate (1);
2972 net_nfc_state_activate (1);
2974 PRINT_INSTRUCT("Please close a tag to device!!");
2976 pthread_cond_wait (&pcond,&plock );
2977 if (!test_case_result) return test_case_result;
2978 PRINT_INSTRUCT("Please remove the tag from device!!");
2979 pthread_cond_wait (&pcond,&plock );
2981 net_nfc_state_deactivate ();
2982 PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
2984 for (idx = 10 ;idx > 0 ; idx --)
2986 PRINT_INSTRUCT("count down [%d]", idx);
2989 if (!test_case_result) return test_case_result;
2990 PRINT_INSTRUCT("Please remove the tag from device!!");
2993 net_nfc_state_activate (1);
2994 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
2996 PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
2999 for (idx = 10 ;idx > 0 ; idx --)
3001 PRINT_INSTRUCT("count down [%d]", idx);
3004 if (!test_case_result) return test_case_result;
3006 PRINT_INSTRUCT("Please remove the tag from device!!");
3009 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
3010 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
3011 net_nfc_state_activate (1);
3013 PRINT_INSTRUCT("Please close a tag to device!!");
3015 pthread_cond_wait (&pcond,&plock );
3016 if (!test_case_result) return test_case_result;
3018 return NET_NFC_TEST_OK;
3021 /*=================================================================================*/
3024 static void net_nfc_test_API_exception_tagAPI(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
3026 PRINT_INFO ("Message is received 3 %d", result);
3027 test_case_result = NET_NFC_TEST_OK;
3031 case NET_NFC_MESSAGE_TAG_DISCOVERED:
3033 switch (*(int*) user_param)
3035 case 0: // transceive
3037 net_nfc_target_type_e type;
3038 net_nfc_target_handle_h id;
3040 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3041 net_nfc_error_e e_ret ;
3043 net_nfc_get_tag_type (target_info, &type);
3044 net_nfc_get_tag_handle (target_info, &id);
3045 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
3046 PRINT_INFO("target type: %d\n", type);
3047 PRINT_INFO("target id: %X\n", id);
3048 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
3050 net_nfc_deinitialize (); // Before calling transceive
3056 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3057 net_nfc_target_handle_h id;
3058 net_nfc_get_tag_handle (target_info, &id);
3059 net_nfc_deinitialize();
3060 if (NET_NFC_OK == net_nfc_read_tag (id ,NULL)){
3061 test_case_result = NET_NFC_TEST_FAIL;
3067 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3068 net_nfc_target_handle_h id;
3069 ndef_message_h message = NULL;
3070 ndef_record_h record = NULL;
3072 net_nfc_get_tag_handle (target_info, &id);
3073 net_nfc_deinitialize();
3075 net_nfc_create_ndef_message (&message);
3076 net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
3077 net_nfc_append_record_to_ndef_message (message ,record);
3078 if (NET_NFC_OK == net_nfc_write_ndef (id ,message ,NULL)){
3079 test_case_result = NET_NFC_TEST_FAIL;
3086 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3087 net_nfc_target_handle_h id;
3089 char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
3090 net_nfc_create_data (&key, data, 6);
3091 net_nfc_get_tag_handle (target_info, &id);
3092 net_nfc_deinitialize();
3093 if (NET_NFC_OK == net_nfc_format_ndef(id, key, NULL)){
3094 test_case_result = NET_NFC_TEST_FAIL;
3100 pthread_mutex_lock (&plock);
3101 pthread_cond_signal (&pcond);
3102 pthread_mutex_unlock (&plock);
3109 int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr)
3113 /* Call API before initailize */
3116 char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
3117 net_nfc_create_data (&key, data, 6);
3118 CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL));
3119 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_format_ndef(NULL, key, NULL));
3120 CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL));
3122 CHECK_ASSULT (NET_NFC_OK != net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL));
3123 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_read_tag (NULL ,NULL));
3125 ndef_message_h message = NULL;
3126 ndef_record_h record = NULL;
3127 net_nfc_create_ndef_message (&message);
3128 net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
3129 net_nfc_append_record_to_ndef_message (message ,record);
3130 CHECK_ASSULT (NET_NFC_OK != net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message,NULL));
3131 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef (NULL ,message,NULL));
3132 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL));
3133 net_nfc_free_ndef_message (message);
3136 for (test_case = 0 ; test_case < 4; test_case++){
3137 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
3138 net_nfc_state_activate (1);
3139 PRINT_INSTRUCT("Please close a tag to device!!");
3140 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_tagAPI, &test_case));
3141 pthread_cond_wait (&pcond,&plock );
3142 if (test_case_result == NET_NFC_TEST_FAIL) return test_case_result;
3143 PRINT_INSTRUCT("Please remoe the tag from device!!");
3147 CHECK_ASSULT(net_nfc_deinitialize () != NET_NFC_OK);
3149 return NET_NFC_TEST_OK;
3151 /*=================================================================================*/
3154 static void net_nfc_test_API_exception_targetInfo(net_nfc_message_e message, net_nfc_error_e result, void* data, void* user_param, void * trans_data)
3156 PRINT_INFO ("Message is received 3 %d", result);
3157 test_case_result = NET_NFC_TEST_OK;
3165 case NET_NFC_MESSAGE_TAG_DISCOVERED:
3168 if (NET_NFC_OK != net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
3169 test_case_result = NET_NFC_TEST_FAIL;
3173 if (NET_NFC_OK == net_nfc_get_tag_info_value ((net_nfc_target_info_h)data, "abc", &value)){
3174 test_case_result = NET_NFC_TEST_FAIL;
3177 PRINT_INSTRUCT("Please remove the tag from device!!");
3181 case NET_NFC_MESSAGE_TAG_DETACHED:
3183 if (NET_NFC_OK == net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
3184 test_case_result = NET_NFC_TEST_FAIL;
3188 pthread_mutex_lock (&plock);
3189 pthread_cond_signal (&pcond);
3190 pthread_mutex_unlock (&plock);
3197 int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr)
3199 net_nfc_target_type_e target_type;
3200 net_nfc_target_handle_h target_id;
3203 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type ((net_nfc_target_info_h)0x302023, NULL));
3204 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type (NULL, &target_type));
3206 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle((net_nfc_target_info_h)0x302023, NULL));
3207 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle(NULL, &target_id));
3209 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support ((net_nfc_target_info_h)0x302023, NULL));
3210 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support (NULL, &is_support));
3212 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size ((net_nfc_target_info_h)0x302023, NULL));
3213 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size (NULL, &size));
3215 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size ((net_nfc_target_info_h)0x302023, NULL));
3216 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size (NULL, &size));
3220 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, NULL, &length));
3221 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, &keys, NULL));
3222 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys(NULL, &keys, &length));
3224 const char* key = "hello";
3227 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, key , NULL));
3228 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, NULL, &value));
3229 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value));
3231 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
3232 net_nfc_state_activate (1);
3233 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_targetInfo, NULL));
3234 PRINT_INSTRUCT("Please close a tag to device!!");
3236 pthread_cond_wait (&pcond,&plock );
3238 CHECK_ASSULT(net_nfc_deinitialize() == NET_NFC_OK);
3239 return NET_NFC_TEST_OK;
3242 /*=================================================================================*/
3245 int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr)
3247 net_nfc_carrier_config_h carrier;
3248 net_nfc_property_group_h group;
3249 ndef_record_h carrier_record;
3250 ndef_message_h message;
3251 uint8_t buffer[256] = {0,};
3254 net_nfc_error_e result;
3255 char SSID[] = "HomeWLAN";
3256 char dev_name[] = "DeviceName";
3257 uint8_t btdev_addr[] = {0x01, 0x07, 0x80, 0x80, 0xBF, 0xA1};
3259 result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS);
3260 CHECK_RESULT(result);
3263 result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION, 1, buffer);
3264 CHECK_RESULT(result);
3265 result = net_nfc_create_carrier_config_group (&group, NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL);
3266 CHECK_RESULT(result);
3269 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_INDEX, 1, buffer);
3270 CHECK_RESULT(result);
3272 length = sprintf (buffer, "%s", SSID);
3273 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_SSID, length, buffer);
3274 CHECK_RESULT(result);
3276 *((uint16_t*) buffer ) = 0x20;
3277 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE, 2, buffer);
3278 CHECK_RESULT(result);
3280 *((uint16_t*) buffer ) = 0x0008;
3281 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE, 2, buffer);
3282 CHECK_RESULT(result);
3284 length = sprintf (buffer, "MyPreSharedKey");
3285 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_KEY, length, buffer);
3286 CHECK_RESULT(result);
3294 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR, 6, buffer);
3295 CHECK_RESULT(result);
3298 *((uint16_t*) buffer ) = 0x0001;
3299 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_CHANNEL, 2, buffer);
3300 CHECK_RESULT(result);
3305 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_VEN_EXT, 3, buffer);
3306 CHECK_RESULT(result);
3308 result = net_nfc_append_carrier_config_group (carrier, group);
3309 CHECK_RESULT(result);
3312 result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION2, 1, buffer);
3313 CHECK_RESULT(result);
3315 result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
3316 CHECK_RESULT(result);
3318 result = net_nfc_free_carrier_config (carrier); /* this free all data include group */
3319 CHECK_RESULT(result);
3321 result = net_nfc_create_handover_request_message (&message);
3322 CHECK_RESULT(result);
3324 //net_nfc_ndef_print_message (message);
3326 result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
3327 CHECK_RESULT(result);
3329 //net_nfc_ndef_print_message (message);
3333 result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_BT);
3334 CHECK_RESULT(result);
3336 buffer[0] = btdev_addr[0];
3337 buffer[1] = btdev_addr[1];
3338 buffer[2] = btdev_addr[2];
3339 buffer[3] = btdev_addr[3];
3340 buffer[4] = btdev_addr[4];
3341 buffer[5] = btdev_addr[5];
3342 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,6 ,buffer);
3343 CHECK_RESULT(result);
3348 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_COD ,3 ,buffer);
3349 CHECK_RESULT(result);
3352 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_C ,16 ,buffer);
3353 CHECK_RESULT(result);
3355 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_R ,16 ,buffer);
3356 CHECK_RESULT(result);
3362 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_UUID16 ,4 ,buffer);
3363 CHECK_RESULT(result);
3365 length = sprintf (buffer, "%s", dev_name);
3366 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME ,length ,buffer);
3367 CHECK_RESULT(result);
3369 result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
3370 CHECK_RESULT(result);
3372 result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING);
3373 CHECK_RESULT(result);
3375 //net_nfc_ndef_print_message (message);
3377 result = net_nfc_free_carrier_config (carrier);
3378 CHECK_RESULT(result);
3380 result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
3381 CHECK_RESULT(result);
3383 result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
3384 CHECK_RESULT(result);
3386 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_WIFI_ATTRIBUTE_VERSION , &length, &pdata);
3387 CHECK_RESULT(result);
3388 if (pdata[0] != 0x10){
3389 PRINT_RESULT_FAIL("FILE:%s, LINE:%d, value %d",__FILE__,__LINE__, pdata[0]);
3390 return NET_NFC_TEST_FAIL;
3393 result = net_nfc_get_carrier_config_group (carrier ,0 , &group);
3394 CHECK_RESULT(result);
3396 result = net_nfc_get_carrier_config_group_property (group ,NET_NFC_WIFI_ATTRIBUTE_SSID, &length, &pdata);
3397 CHECK_RESULT(result);
3398 if (memcmp (pdata, SSID, length) != 0){
3399 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3400 return NET_NFC_TEST_FAIL;
3403 result = net_nfc_remove_carrier_config_group_property (group,NET_NFC_WIFI_ATTRIBUTE_VEN_EXT);
3404 CHECK_RESULT(result);
3406 result = net_nfc_get_carrier_config_record (message,1 ,&carrier_record);
3407 CHECK_RESULT(result);
3409 result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
3410 CHECK_RESULT(result);
3412 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata);
3413 CHECK_RESULT(result);
3414 if (memcmp (pdata, btdev_addr, length) != 0) {
3415 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3416 return NET_NFC_TEST_FAIL;
3419 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata);
3420 CHECK_RESULT(result);
3421 if (memcmp (pdata, dev_name, length) != 0){
3422 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3423 return NET_NFC_TEST_FAIL;
3426 result = net_nfc_get_alternative_carrier_record_count (message, &length);
3427 CHECK_RESULT(result);
3430 PRINT_RESULT_FAIL("FILE:%s, LINE:%d, count = %d",__FILE__,__LINE__, length);
3431 return NET_NFC_TEST_FAIL;
3434 net_nfc_conn_handover_carrier_state_e power_state;
3435 result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
3436 CHECK_RESULT(result);
3438 if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE){
3439 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3440 return NET_NFC_TEST_FAIL;
3442 result = net_nfc_set_alternative_carrier_power_status (message,1 ,NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE);
3443 CHECK_RESULT(result);
3445 result = net_nfc_get_alternative_carrier_power_status (message,1 ,&power_state);
3446 CHECK_RESULT(result);
3448 if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
3449 PRINT_RESULT_FAIL("FILE:%s, LINE:%d, status = %d",__FILE__,__LINE__, power_state);
3450 return NET_NFC_TEST_FAIL;
3453 net_nfc_conn_handover_carrier_type_e ctype;
3454 result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
3456 if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS){
3457 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3458 return NET_NFC_TEST_FAIL;
3461 unsigned short r_num;
3462 result = net_nfc_get_handover_random_number (message, &r_num);
3464 result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
3465 CHECK_RESULT(result);
3467 result = net_nfc_remove_carrier_config_record (message, carrier_record);
3468 CHECK_RESULT(result);
3470 result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
3471 CHECK_RESULT(result);
3473 result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
3474 CHECK_RESULT(result);
3476 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata);
3477 CHECK_RESULT(result);
3478 if (memcmp (pdata, btdev_addr, length) != 0) {
3479 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3480 return NET_NFC_TEST_FAIL;
3483 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata);
3484 CHECK_RESULT(result);
3485 if (memcmp (pdata, dev_name, length) != 0){
3486 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3487 return NET_NFC_TEST_FAIL;
3490 result = net_nfc_get_alternative_carrier_record_count (message, &length);
3491 CHECK_RESULT(result);
3494 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3495 return NET_NFC_TEST_FAIL;
3498 result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
3499 CHECK_RESULT(result);
3501 if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
3502 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3503 return NET_NFC_TEST_FAIL;
3506 result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
3508 if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_BT){
3509 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3510 return NET_NFC_TEST_FAIL;
3513 //net_nfc_ndef_print_message (message);
3515 return NET_NFC_TEST_OK;
3519 /*=================================================================================*/