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.
19 #include <net_nfc_typedef.h>
21 #include <net_nfc_exchanger.h>
24 #include "nfc_api_test.h"
28 /* Function definition list*/
29 int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2);
30 int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2);
31 int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2);
32 int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2);
33 int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2);
34 int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2);
35 int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2);
36 int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2);
37 int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2);
38 int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2);
39 int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2);
40 int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2);
41 int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2);
42 int nfcConnHandover(uint8_t testNumber,void* arg_ptr2);
43 int nfcTestAPIException (uint8_t testNumber,void* arg_ptr);
44 int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr);
45 int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr);
46 int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr);
47 int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2);
48 int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2);
49 int nfcTestSnep(uint8_t testNumber,void* arg_ptr);
52 void print_test_result (char * str, net_nfc_test_result_e result);
54 #define NET_NFC_TAG_DISCOVERED 1
55 #define NET_NFC_TAG_CONNECT (1 << 1)
56 #define NET_NFC_TAG_CHECK_NDEF (1 << 2)
57 #define NET_NFC_TAG_NDEF_READ (1 << 3)
58 #define NET_NFC_TAG_NDEF_WRITE (1 << 4)
59 #define NET_NFC_TAG_NDEF_READ_BIG (1 << 5)
60 #define NET_NFC_TAG_NDEF_WRITE_BIG (1 << 6)
61 #define NET_NFC_TAG_DISCONNECT (1 << 7)
62 #define NET_NFC_MAX_TAG_TYPE 20
64 static nfcTestType nfcTestMatrix[] =
66 // {"API STRESS_WRITE_READ TEST", nfcTestReadWriteMode, NET_NFC_TEST_NOT_YET}, // OK
67 // {"Remove tag while writing", nfcTestWriteMode, NET_NFC_TEST_NOT_YET}, //OK
68 // {"Remove tag while reading", nfcTestAPIBasicTest2, NET_NFC_TEST_NOT_YET}, // OK
69 //{"API BASIC TEST3", nfcTestAPIBasicTest3, NET_NFC_TEST_NOT_YET},
70 // {"API MUTIPLE REQUEST", nfcTestAPIMultipleRequest, NET_NFC_TEST_NOT_YET}, // OK
71 // {"API BASIC TEST1", nfcTestAPIBasicTest1, NET_NFC_TEST_NOT_YET}, // OK
72 // {"Check NDEF message", nfcTestNdefParser, NET_NFC_TEST_NOT_YET}, // OK
73 // {"write mode", nfcTestWriteMode, NET_NFC_TEST_NOT_YET},
74 // {"reader mode", nfcTestReaderMode, NET_NFC_TEST_NOT_YET},
75 // {"format ndef", nfcTestFormatNdef, NET_NFC_TEST_NOT_YET},
76 // {"internal_se_test", nfcTestInternalSe, NET_NFC_TEST_NOT_YET},
77 // {"exchange mode", nfcTestExchanger, NET_NFC_TEST_NOT_YET},
78 // {"Transceive Test", nfcTestTransceive, NET_NFC_TEST_NOT_YET},
79 // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
80 // {"connection handover msg test", nfcConnHandover, NET_NFC_TEST_NOT_YET},
81 // {"API Exception Test", nfcTestAPIException, NET_NFC_TEST_NOT_YET},
82 // {"API Exception Test2", nfcTestAPIException_tagAPI, NET_NFC_TEST_NOT_YET},
83 /// {"API Exception Test3", nfcTestAPIException_targetInfo, NET_NFC_TEST_NOT_YET},
84 // {"LLCP Test", nfcTestLLCP, NET_NFC_TEST_NOT_YET},
85 // {"LLCP Test", nfcTestStressLLCP, NET_NFC_TEST_NOT_YET},
86 // {"Handover Message", nfcConnHandoverMessageTest , NET_NFC_TEST_NOT_YET},
87 {"snep test", nfcTestSnep, NET_NFC_TEST_NOT_YET},
88 {NULL, NULL, NET_NFC_TEST_NOT_YET},
91 static uint32_t testDevType = 0;
92 static uint32_t testCardMaxNdefLength = 0;
93 static uint8_t tagTestResult[NET_NFC_MAX_TAG_TYPE];
95 static int read_count = 0;
96 static int write_count = 0;
97 static int detect_count = 0;
99 static net_nfc_target_handle_h tag_handle = NULL;
100 static int test_count = 0;
104 /* Below smart poster data can has problem or parser has some problem.
106 uint8_t nfcTestSpHex[]= {0xD1,0x02,0x37,0x53,0x70,0x91,0x01,0x18,0x54,0x04,
107 0x74,0x65,0x73,0x74,0x53,0x6D,0x61,0x72,0x74,0x70,
108 0x6F,0x73,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,
109 0x70,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00,
110 0x51,0x01,0x10,0x55,0x00,0x77,0x77,0x77,0x2E,0x73,
111 0x61,0x6D,0x73,0x75,0x6E,0x67,0x2E,0x63,0x6F,0x6D};
114 uint8_t nfcTestSp[]={0xD1,0x02,0x24,0x53,0x70,0x91,0x01,0x14,0x54
115 ,0x00,0x53,0x6D,0x61,0x72,0x74,0x70,0x6F,0x73
116 ,0x74,0x65,0x72,0x20,0x45,0x78,0x61,0x6D,0x70
117 ,0x6C,0x65,0x11,0x03,0x01,0x61,0x63,0x74,0x00
118 ,0x51,0x01,0x01,0x55,0x00};
121 // test Text "Samsung Linux Platform NFC TEST"
122 uint8_t nfcTestTextHex[]= {0xD1,0x01,0x20,0x54,0x00,0x53,0x61,0x6D,0x73,0x75
123 ,0x6E,0x67,0x20,0x4C,0x69,0x6E,0x75,0x78,0x20,0x50
124 ,0x6C,0x61,0x74,0x66,0x6F,0x72,0x6D,0x20,0x4E,0x46
125 ,0x43,0x20,0x54,0x45,0x53,0x54};
128 // test URI "http://www.samsunglinuxplatform.nfctest.com"
129 uint8_t nfcTestUriHex[]={0xD1,0x01,0x2C,0x55,0x00,0x68,0x74,0x74,0x70,0x3A
130 ,0x2F,0x2F,0x77,0x77,0x77,0x2E,0x73,0x61,0x6D,0x73
131 ,0x75,0x6E,0x67,0x6C,0x69,0x6E,0x75,0x78,0x70,0x6C
132 ,0x61,0x74,0x66,0x6F,0x72,0x6D,0x2E,0x6E,0x66,0x63
133 ,0x74,0x65,0x73,0x74,0x2E,0x63,0x6F,0x6D};
135 uint8_t nfcTestText[] = "payload http://www.samsunglinuxplatform.nfctest.com";
136 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};
140 static pthread_cond_t pcond = PTHREAD_COND_INITIALIZER;
141 static pthread_mutex_t plock = PTHREAD_MUTEX_INITIALIZER;
143 static gboolean test_process_func(gpointer data)
145 uint8_t i, testNumber;
148 while (nfcTestMatrix[count].testName != NULL){
152 for(i=0; i<count; i++)
154 PRINT_INFO("%d. %s START\n", i, nfcTestMatrix[i].testName);
156 if(nfcTestMatrix[i].testFn !=NULL){
157 nfcTestMatrix[i].testResult = nfcTestMatrix[i].testFn(i, NULL);
158 //print_test_result (nfcTestMatrix[i].testName, nfcTestMatrix[i].testResult);
168 GMainLoop* loop = NULL;
169 loop = g_main_new(TRUE);
171 g_timeout_add_seconds(1, test_process_func, NULL); // 1secs
172 g_main_loop_run(loop);
177 void print_test_result (char * str, net_nfc_test_result_e result)
179 if (result == NET_NFC_TEST_OK){
180 PRINT_RESULT_SUCCESS("TEST [%s] is PASSED",str);
182 else if (result == NET_NFC_TEST_FAIL){
183 PRINT_RESULT_FAIL("TEST [%s] is FAILED",str);
186 PRINT_INFO("TEST is being tested\n");
191 /*=================================================================================*/
193 static net_nfc_test_result_e test_case_result;
195 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 );
196 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);
198 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 )
203 int nfcTestClientInit(uint8_t testNumber,void* arg_ptr2)
205 net_nfc_error_e result;
206 result = net_nfc_initialize();
207 CHECK_RESULT(result);
210 result = net_nfc_set_response_callback (net_nfc_test_client_cb, NULL);
211 CHECK_RESULT(result);
213 result = net_nfc_unset_response_callback ();
214 CHECK_RESULT(result);
216 result = net_nfc_deinitialize ();
217 CHECK_RESULT(result);
219 return NET_NFC_TEST_OK;
223 net_nfc_exchanger_data_h net_nfc_exchanger_callback(net_nfc_exchanger_event_e event, void * user_param)
225 PRINT_INFO(" event = [%d] \n", event);
226 test_case_result = NET_NFC_TEST_OK;
230 case NET_NFC_EXCHANGER_DATA_REQUESTED:
232 PRINT_INFO("exchange is requested");
233 net_nfc_exchanger_data_h ex_data = NULL;
234 net_nfc_error_e error = NET_NFC_OK;
235 data_h payload = NULL;
238 uint8_t buffer[1024] = {0};
245 net_nfc_create_data(&payload, buffer, 1024);
248 if((error = net_nfc_create_exchanger_data(&ex_data, (uint8_t *)"http://www.samsung.com")) == NET_NFC_OK)
249 //if((error = net_nfc_create_exchanger_url_type_data(&ex_data, NET_NFC_SCHEMA_FULL_URI, (uint8_t *)"file://test.txt")) == NET_NFC_OK)
250 //if((error = net_nfc_create_exchanger_raw_type_data(&ex_data, "text/plain", payload)) == NET_NFC_OK)
256 PRINT_INFO("create exchanger data is failed = [%d]", error);
257 //pthread_cond_signal (&pcond);
261 case NET_NFC_EXCHANGER_TRANSFER_FAILED:
262 case NET_NFC_EXCHANGER_TRANSFER_COMPLETED:
265 //pthread_cond_signal (&pcond);
267 if(event == NET_NFC_EXCHANGER_TRANSFER_COMPLETED)
269 PRINT_INFO("transfer exchanger msg is completed");
273 PRINT_INFO("transfer exchanger msg is failed");
282 /*=================================================================================*/
283 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)
287 PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
291 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
292 net_nfc_target_type_e type;
293 net_nfc_target_handle_h id;
295 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
297 net_nfc_get_tag_type (target_info, &type);
298 net_nfc_get_tag_handle(target_info, &id);
299 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
300 PRINT_INFO("target type: %d\n", type);
301 PRINT_INFO("target id: %X\n", id);
302 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
307 net_nfc_get_tag_actual_data_size (target_info ,&actual_size);
308 net_nfc_get_tag_max_data_size (target_info ,&max_size);
309 PRINT_INFO("\tmax data [%d]\tactual data [%d]\n", max_size,actual_size );
310 net_nfc_read_tag (id, (void *)2);
313 PRINT_INSTRUCT("Please use NDEF formated tag!!");
314 test_case_result = NET_NFC_TEST_FAIL;
318 case NET_NFC_MESSAGE_READ_NDEF:{
320 ndef_message_h ndef = (ndef_message_h)(data);
322 net_nfc_create_rawdata_from_ndef_message (ndef ,&rawdata);
323 PRINT_INFO("read ndef message is ok, length is [%d]", net_nfc_get_data_length(rawdata));
324 //_//net_nfc_ndef_print_message (ndef);
327 if (memcmp(net_nfc_get_data_buffer (rawdata),nfcTestSpHex, net_nfc_get_data_length (rawdata)) == 0){
328 test_case_result = NET_NFC_TEST_OK;
332 pthread_mutex_lock (&plock);
333 pthread_cond_signal (&pcond);
334 pthread_mutex_unlock (&plock);
343 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)
347 PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
351 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
353 PRINT_INFO("NET_NFC_MESSAGE_TAG_DISCOVERED");
355 net_nfc_target_type_e type;
356 net_nfc_target_handle_h id;
358 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
360 net_nfc_get_tag_type (target_info, &type);
361 net_nfc_get_tag_handle(target_info, &id);
362 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
363 PRINT_INFO("target type: %d\n", type);
364 PRINT_INFO("target id: %X\n", id);
365 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
367 data_h ndef_key = NULL;
368 net_nfc_mifare_create_net_nfc_forum_key(&ndef_key);
369 net_nfc_format_ndef(id, ndef_key, NULL);
374 case NET_NFC_MESSAGE_FORMAT_NDEF:{
375 PRINT_INFO("NET_NFC_MESSAGE_FORMAT_NDEF");
376 PRINT_INFO("result = [%d]", result);
379 case NET_NFC_MESSAGE_TAG_DETACHED:
381 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED");
389 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)
393 case NET_NFC_MESSAGE_GET_SE :
395 PRINT_INFO("NET_NFC_MESSAGE_GET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
396 //net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_ESE, NULL);
397 net_nfc_set_secure_element_type(NET_NFC_SE_TYPE_UICC, NULL);
400 case NET_NFC_MESSAGE_SET_SE :
402 PRINT_INFO("NET_NFC_MESSAGE_SET_SE result = [%d] se type = [%d]", result, *((uint8_t *)data));
403 net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_ESE, NULL);
404 //net_nfc_open_internal_secure_element(NET_NFC_SE_TYPE_UICC, NULL);
407 case NET_NFC_MESSAGE_OPEN_INTERNAL_SE :
409 PRINT_INFO("NET_NFC_MESSAGE_OPEN_INTERNAL_SE result = [%d] and handle = [0x%x]", result, data);
411 uint8_t apdu_cmd[4] = {0x00, 0xA4, 0x00, 0x0C} ; // CLA 0-> use default channel and no secure message. 0xA4 -> select instruction
412 net_nfc_create_data(&apdu, apdu_cmd, 4);
413 net_nfc_send_apdu((net_nfc_target_handle_h)(data), apdu, data);
417 case NET_NFC_MESSAGE_SEND_APDU_SE:
419 PRINT_INFO("NET_NFC_MESSAGE_SEND_APDU_SE result = [%d]", result);
423 uint8_t * r_buffer = net_nfc_get_data_buffer (data);
424 uint32_t r_buffer_length = net_nfc_get_data_length (data);
426 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (data));
429 for (idx = 0; idx < r_buffer_length; idx++){
430 printf (" %02X", r_buffer[idx]);
434 net_nfc_close_internal_secure_element((net_nfc_target_handle_h)trans_data, NULL);
437 case NET_NFC_MESSAGE_CLOSE_INTERNAL_SE :
440 PRINT_INFO("NET_NFC_MESSAGE_CLOSE_INTERNAL_SE result = [%d]", result);
447 PRINT_INFO("user_param = [%d] trans_param = [%d]", user_param, trans_data);
450 /*=================================================================================*/
451 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)
456 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
457 net_nfc_target_type_e type;
458 net_nfc_target_handle_h id;
460 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
461 net_nfc_carrier_config_h * config;
462 ndef_record_h record;
464 net_nfc_get_tag_type (target_info, &type);
465 net_nfc_get_tag_handle(target_info, &id);
466 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
467 PRINT_INFO("target type: %d\n", type);
468 PRINT_INFO("target id: %X\n", id);
469 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
473 ndef_message_h ndef = NULL;
474 data_h bt_config = NULL;
475 net_nfc_create_data_only(&bt_config);
477 // 2byte :: OOB length, 6byte :: bt addr
478 uint8_t temp[8] = {0x00, 0x08, 0x00, 0x02, 0x78, 0xDD, 0xC4, 0x8A};
479 net_nfc_create_carrier_config (&config,NET_NFC_CONN_HANDOVER_CARRIER_BT );
480 net_nfc_add_carrier_config_property (config ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,8 ,temp);
481 net_nfc_create_ndef_record_with_carrier_config (&record, config);
482 net_nfc_create_handover_select_message (&ndef);
483 net_nfc_append_carrier_config_record (message,record,NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
485 net_nfc_write_ndef(id, ndef, NULL);
489 PRINT_INSTRUCT("Please use NDEF formated tag!!");
490 test_case_result = NET_NFC_TEST_FAIL;
494 case NET_NFC_MESSAGE_WRITE_NDEF:{
496 if(result == NET_NFC_OK){
497 PRINT_INFO("write ndef message is ok");
498 test_case_result = NET_NFC_TEST_OK;
501 pthread_mutex_lock (&plock);
502 pthread_cond_signal (&pcond);
503 pthread_mutex_unlock (&plock);
511 int nfcConnHandover(uint8_t testNumber,void* arg_ptr2)
513 int user_context = 0;
514 net_nfc_error_e result;
516 test_case_result = NET_NFC_TEST_FAIL;
518 result = net_nfc_initialize();
520 net_nfc_state_activate(1);
522 CHECK_RESULT(result);
523 result = net_nfc_set_response_callback (net_nfc_test_static_handover_cb, NULL);
524 CHECK_RESULT(result);
526 PRINT_INSTRUCT("Please close a tag to device!!");
528 //pthread_cond_wait (&pcond,&plock );
530 PRINT_INFO("operation is end");
532 result = net_nfc_unset_response_callback ();
534 CHECK_RESULT(result);
535 result = net_nfc_deinitialize ();
536 CHECK_RESULT(result);
541 ndef_message_h ndef = NULL;
543 if(net_nfc_retrieve_current_ndef_message(&ndef) == NET_NFC_OK){
544 PRINT_INFO("retrieve is ok");
547 PRINT_INFO("retrieve is failed");
548 return NET_NFC_TEST_FAIL;
551 ndef_message_h ndef = NULL;
552 data_h bt_config = NULL;
553 net_nfc_create_data_only(&bt_config);
555 // 2byte :: OOB length, 6byte :: bt addr
556 uint8_t temp[8] = {0x00, 0x08, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
558 net_nfc_set_data(bt_config, temp, 8);
559 net_nfc_create_static_connection_handover_select_message(&ndef, bt_config, NULL);
561 net_nfc_conn_handover_info_h handover_info = NULL;
563 if(net_nfc_parse_connection_handover_ndef_message(ndef, &handover_info) == NET_NFC_OK){
564 PRINT_INFO("parsing is ok");
568 if((result = net_nfc_get_connection_handover_version(handover_info, &version)) == NET_NFC_OK){
569 PRINT_INFO("version = [%d]", version);
572 PRINT_INFO("get version is failed = [%d]", result);
576 unsigned short random_number = 0;
577 if((result = net_nfc_get_connection_handover_random_number(handover_info, &random_number)) == NET_NFC_OK)
579 PRINT_INFO("random_number = [%d]", random_number);
583 PRINT_INFO("get random_number is failed = [%d]", result);
586 data_h record_type = NULL;
587 net_nfc_get_connection_handover_record_type(handover_info, &record_type);
588 PRINT_INFO("record type = [%c] [%c]", (net_nfc_get_data_buffer(record_type))[0], (net_nfc_get_data_buffer(record_type))[1]);
590 uint8_t carrier_count = 0;
591 net_nfc_get_connection_handover_alternative_carrier_count(handover_info, &carrier_count);
594 for(; i < carrier_count; i++)
596 net_nfc_conn_handover_carrier_info_h carrier_info = NULL;
597 net_nfc_get_connection_handover_carrier_handle_by_index(handover_info, i, &carrier_info);
599 if(carrier_info != NULL){
600 net_nfc_conn_handover_carrier_type_e carrier_type = 0;
601 net_nfc_get_carrier_type(carrier_info, &carrier_type);
603 if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_BT)
605 PRINT_INFO("carrier is BT");
607 else if(carrier_type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI)
609 PRINT_INFO("carrier is WIFI");
613 PRINT_INFO("carrier is unknown");
617 net_nfc_get_carrier_id(carrier_info, &id);
619 PRINT_INFO("id = [0x%x]", (net_nfc_get_data_buffer(id))[0]);
621 net_nfc_conn_handover_carrier_state_e carrier_state = 0;
622 net_nfc_get_carrier_power_state(carrier_info, &carrier_state);
624 PRINT_INFO("cps is = [0x%x]", carrier_state);
626 data_h config = NULL;
627 if((result = net_nfc_get_carrier_configuration(carrier_info, &config)) == NET_NFC_OK)
629 PRINT_INFO("good to get config");
633 PRINT_INFO("failed to get config = [%d]", result);
636 uint8_t* buffer = NULL;
637 if((buffer = net_nfc_get_data_buffer(config)) != NULL)
639 unsigned short size = ( buffer[0] << 8 ) |buffer[1];
640 PRINT_INFO("size is = [%d]", size);
644 PRINT_INFO("carrier addr is [0x%x]", buffer[2]);
645 PRINT_INFO("carrier addr is [0x%x]", buffer[3]);
646 PRINT_INFO("carrier addr is [0x%x]", buffer[4]);
647 PRINT_INFO("carrier addr is [0x%x]", buffer[5]);
648 PRINT_INFO("carrier addr is [0x%x]", buffer[6]);
649 PRINT_INFO("carrier addr is [0x%x]", buffer[7]);
653 PRINT_INFO("more data -_-;; ");
658 PRINT_INFO("failed to buffer");
666 PRINT_INFO("parsing is failed");
668 return NET_NFC_TEST_FAIL;
672 if(handover_info != NULL){
673 if((net_nfc_free_connection_handover_info(handover_info)) == NET_NFC_OK){
674 PRINT_INFO("free is good");
677 PRINT_INFO("free is failed");
682 return test_case_result;
685 int nfcTestFormatNdef(uint8_t testNumber,void* arg_ptr2)
687 PRINT_INFO("%s is start", __func__);
689 int user_context = 0;
690 net_nfc_error_e result;
691 test_case_result = NET_NFC_TEST_FAIL;
693 result = net_nfc_initialize();
695 net_nfc_state_activate(1);
697 CHECK_RESULT(result);
698 result = net_nfc_set_response_callback (net_nfc_test_format_cb, (void *)1);
699 CHECK_RESULT(result);
701 PRINT_INSTRUCT("Please close a tag to device!!");
703 //pthread_cond_wait (&pcond,&plock );
706 PRINT_INFO("operation is end");
708 result = net_nfc_unset_response_callback ();
710 CHECK_RESULT(result);
711 result = net_nfc_deinitialize ();
712 CHECK_RESULT(result);
716 return test_case_result;
719 int nfcTestInternalSe(uint8_t testNumber,void* arg_ptr2)
721 PRINT_INFO("%s is start", __func__);
723 int user_context = 0;
724 net_nfc_error_e result;
725 test_case_result = NET_NFC_TEST_FAIL;
727 result = net_nfc_initialize();
729 net_nfc_state_activate(1);
731 CHECK_RESULT(result);
732 result = net_nfc_set_response_callback (net_nfc_test_se_cb, (void *)1);
733 CHECK_RESULT(result);
735 net_nfc_get_secure_element_type(NULL);
737 PRINT_INSTRUCT("Please close a tag to device!!");
739 return test_case_result;
744 int nfcTestReaderMode(uint8_t testNumber,void* arg_ptr2)
746 PRINT_INFO("%s is start", __func__);
748 int user_context = 0;
749 net_nfc_error_e result;
750 test_case_result = NET_NFC_TEST_FAIL;
752 result = net_nfc_initialize();
754 net_nfc_state_activate(1);
756 CHECK_RESULT(result);
757 result = net_nfc_set_response_callback (net_nfc_test_reader_cb, (void *)1);
758 CHECK_RESULT(result);
760 PRINT_INSTRUCT("Please close a tag to device!!");
762 //pthread_cond_wait (&pcond,&plock );
765 PRINT_INFO("operation is end");
767 result = net_nfc_unset_response_callback ();
769 CHECK_RESULT(result);
770 result = net_nfc_deinitialize ();
771 CHECK_RESULT(result);
775 return test_case_result;
778 int nfcTestExchanger(uint8_t testNumber,void* arg_ptr2)
780 PRINT_INFO("%s is start", __func__);
781 int user_context = 0;
782 net_nfc_error_e result;
783 test_case_result = NET_NFC_TEST_FAIL;
785 if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_OK){
786 test_case_result = NET_NFC_TEST_FAIL;
787 PRINT_INFO("failed to set exchanger_cb = [%d]", result);
788 return test_case_result;
791 PRINT_INFO("setting exchange callback is ok = [%d]", result);
795 if((result = net_nfc_initialize()) != NET_NFC_NOT_ALLOWED_OPERATION){
796 test_case_result = NET_NFC_TEST_FAIL;
797 PRINT_INFO("NET_NFC_NOT_ALLOWED_OPERATION 1 is not returned = [%d]", result);
798 return test_case_result;
800 PRINT_INFO("net_nfc_init is failed = [%d]", result);
803 if((result = net_nfc_unset_exchanger_cb()) != NET_NFC_OK){
804 test_case_result = NET_NFC_TEST_FAIL;
805 PRINT_INFO("unset exchanger cb is failed = [%d]", result);
806 return test_case_result;
808 PRINT_INFO("unset ex cb is ok = [%d]", result);
811 if((result = net_nfc_initialize()) != NET_NFC_OK){
812 test_case_result = NET_NFC_TEST_FAIL;
813 PRINT_INFO("net_nfc_init is failed = [%d]", result);
814 return test_case_result;
816 PRINT_INFO("net_nfc_init is ok = [%d]", result);
819 if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_NOT_ALLOWED_OPERATION){
820 test_case_result = NET_NFC_TEST_FAIL;
821 PRINT_INFO("NET_NFC_NOT_ALLOWED_OPERATION 2 is not returned = [%d]", result);
822 return test_case_result;
824 PRINT_INFO("set ex cb is failed = [%d]", result);
827 if((result = net_nfc_deinitialize()) != NET_NFC_OK){
828 test_case_result = NET_NFC_TEST_FAIL;
829 PRINT_INFO("nfc deinit is failed = [%d]", result);
830 return test_case_result;
832 PRINT_INFO("net_nfc_deinit is ok = [%d]", result);
835 if((result = net_nfc_set_exchanger_cb(net_nfc_exchanger_callback, NULL)) != NET_NFC_OK){
836 PRINT_INFO("set exchanger cb is failed = [%d]", result);
837 test_case_result = NET_NFC_TEST_FAIL;
838 return test_case_result;
840 PRINT_INFO("settting ex cb is ok = [%d]", result);
844 //pthread_cond_wait (&pcond,&plock );
846 //PRINT_INFO("operation is end");
847 //result = net_nfc_unset_exchanger_cb();
848 //CHECK_RESULT(result);
850 test_case_result = NET_NFC_TEST_OK;
852 return test_case_result;
855 /*=================================================================================*/
857 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)
863 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
864 net_nfc_target_type_e type;
865 net_nfc_target_handle_h handle;
867 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
869 net_nfc_get_tag_type (target_info, &type);
870 net_nfc_get_tag_handle (target_info, &handle);
871 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
872 PRINT_INFO("target type: %d\n", type);
873 PRINT_INFO("target id: %X\n", handle);
874 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
880 net_nfc_error_e error = NET_NFC_OK;
881 ndef_message_h msg = NULL;
882 ndef_record_h record = NULL;
884 if( (error = net_nfc_create_uri_type_record(&record, "http://www.naver.com", NET_NFC_SCHEMA_FULL_URI)) == NET_NFC_OK)
886 if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
888 if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
890 ////net_nfc_ndef_print_message(msg);
891 net_nfc_write_ndef(tag_handle, msg, &user_context);
892 net_nfc_free_ndef_message(msg);
896 PRINT_INFO("failed to append ndef message = [%d]", error);
897 net_nfc_free_record(record);
898 net_nfc_free_ndef_message(msg);
900 pthread_mutex_lock (&plock);
901 pthread_cond_signal (&pcond);
902 pthread_mutex_unlock (&plock);
907 PRINT_INFO("failed to create ndef msg");
908 net_nfc_free_record(record);
910 pthread_mutex_lock (&plock);
911 pthread_cond_signal (&pcond);
912 pthread_mutex_unlock (&plock);
917 PRINT_INFO("failed to create text type record");
919 pthread_mutex_lock (&plock);
920 pthread_cond_signal (&pcond);
921 pthread_mutex_unlock (&plock);
925 PRINT_INSTRUCT("Please use NDEF formated tag!!");
931 case NET_NFC_MESSAGE_TAG_DETACHED:
933 if (write_count++ >= 20) {
934 test_case_result = NET_NFC_TEST_OK;
935 pthread_mutex_lock (&plock);
936 pthread_cond_signal (&pcond);
937 pthread_mutex_unlock (&plock);
940 PRINT_INSTRUCT("Please close a tag to device again!!");
945 case NET_NFC_MESSAGE_WRITE_NDEF:
947 /*if (result == NET_NFC_OK) {
948 test_case_result = NET_NFC_TEST_OK;
951 PRINT_INFO("received error: %d\n", result);
952 test_case_result = NET_NFC_TEST_FAIL;
956 /* pthread_mutex_lock (&plock);
957 pthread_cond_signal (&pcond);
958 pthread_mutex_unlock (&plock);
961 if(write_count++ == 20)
964 PRINT_INSTRUCT("completed, please remove tag");
969 net_nfc_error_e error = NET_NFC_OK;
970 ndef_message_h msg = NULL;
971 ndef_record_h record = NULL;
973 if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
975 if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
977 if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
979 ////net_nfc_ndef_print_message(msg);
980 net_nfc_write_ndef(tag_handle, msg, &user_context);
981 net_nfc_free_ndef_message(msg);
985 PRINT_INFO("failed to append ndef message = [%d]", error);
986 net_nfc_free_record(record);
987 net_nfc_free_ndef_message(msg);
988 test_case_result = NET_NFC_TEST_FAIL;
990 pthread_mutex_lock (&plock);
991 pthread_cond_signal (&pcond);
992 pthread_mutex_unlock (&plock);
997 PRINT_INFO("failed to create ndef msg");
998 net_nfc_free_record(record);
999 test_case_result = NET_NFC_TEST_FAIL;
1001 pthread_mutex_lock (&plock);
1002 pthread_cond_signal (&pcond);
1003 pthread_mutex_unlock (&plock);
1008 PRINT_INFO("failed to create text type record");
1009 test_case_result = NET_NFC_TEST_FAIL;
1011 pthread_mutex_lock (&plock);
1012 pthread_cond_signal (&pcond);
1013 pthread_mutex_unlock (&plock);
1026 int nfcTestWriteMode(uint8_t testNumber,void* arg_ptr2)
1028 int user_context = 0;
1029 net_nfc_error_e result;
1030 test_case_result = NET_NFC_TEST_FAIL;
1032 result = net_nfc_initialize();
1033 CHECK_RESULT(result);
1035 net_nfc_state_activate(1);
1037 result = net_nfc_set_response_callback (net_nfc_test_write_cb, NULL);
1038 CHECK_RESULT(result);
1041 PRINT_INSTRUCT("TEST: remove tag while write");
1042 PRINT_INSTRUCT("Please close a tag to device!!");
1044 //pthread_cond_wait (&pcond,&plock );
1047 result = net_nfc_unset_response_callback ();
1048 CHECK_RESULT(result);
1049 result = net_nfc_deinitialize ();
1050 CHECK_RESULT(result);
1052 return test_case_result;
1057 int nfcTestReadWriteMode(uint8_t testNumber,void* arg_ptr2)
1059 int user_context = 0;
1060 net_nfc_error_e result;
1061 test_case_result = NET_NFC_TEST_FAIL;
1066 result = net_nfc_initialize();
1067 CHECK_RESULT(result);
1069 net_nfc_state_activate(1);
1071 result = net_nfc_set_response_callback (net_nfc_test_read_write_cb, NULL);
1072 CHECK_RESULT(result);
1074 PRINT_INSTRUCT("Testing (50 each) read and write test");
1075 PRINT_INSTRUCT("Please close a tag to device!!");
1077 //pthread_cond_wait (&pcond,&plock );
1079 result = net_nfc_unset_response_callback ();
1080 CHECK_RESULT(result);
1081 result = net_nfc_deinitialize ();
1082 CHECK_RESULT(result);
1086 return test_case_result;
1090 /*=================================================================================*/
1092 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)
1096 printf ("callback is called with message %d\n", message);
1099 case NET_NFC_MESSAGE_TAG_DISCOVERED:{
1100 net_nfc_target_type_e type;
1101 net_nfc_target_handle_h id;
1103 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1104 net_nfc_error_e result = NET_NFC_OK;
1106 net_nfc_get_tag_type (target_info, &type);
1107 net_nfc_get_tag_handle (target_info, &id);
1108 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1109 PRINT_INFO("target type: %d\n", type);
1110 PRINT_INFO("target id: %X\n", id);
1111 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1115 if(type == NET_NFC_MIFARE_ULTRA_PICC){
1117 if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
1118 PRINT_INFO("failed to read = [%d]", result);
1122 else if(type >= NET_NFC_MIFARE_MINI_PICC && type <= NET_NFC_MIFARE_4K_PICC){
1124 data_h mad_key = NULL;
1125 data_h net_nfc_forum_key = NULL;
1126 data_h default_key = NULL;
1128 net_nfc_mifare_create_application_directory_key(&mad_key);
1129 net_nfc_mifare_create_net_nfc_forum_key(&net_nfc_forum_key);
1130 net_nfc_mifare_create_default_key(&default_key);
1142 // key = net_nfc_forum_key;
1145 // if(net_nfc_mifare_authenticate_with_keyB(id, sector, key, NULL) != NET_NFC_OK){
1146 if(net_nfc_mifare_authenticate_with_keyA(id, sector, default_key, NULL) != NET_NFC_OK){
1147 PRINT_INFO("failed to authenticate sector");
1154 if(type == NET_NFC_MIFARE_4K_PICC && sector > 31){
1166 for(; j < nBlocks; j++){
1167 if((result = net_nfc_mifare_read(tag_handle, sector * 4 + j, NULL)) != NET_NFC_OK){
1168 PRINT_INFO("failed to read = [%d]", result);
1170 PRINT_INFO("block [%d] is read", sector * 4 + j);
1175 data_h write_block = NULL;
1176 uint8_t buffer[16] = {0x00,};
1177 uint8_t* temp = buffer;
1180 int value_comp = 1 + ~value;
1182 uint8_t addr_comp = 1 + ~addr;
1185 // read block 5 and write block 5 and read again
1186 if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
1187 PRINT_INFO("failed to read = [%d]", result);
1189 PRINT_INFO("block 5 is read");
1192 // read block 5 and write block 5 and read again
1194 memcpy(temp, &value, sizeof(int));
1195 temp = temp + sizeof(int);
1197 memcpy(temp, &value_comp, sizeof(int));
1198 temp = temp + sizeof(int);
1200 memcpy(temp, &value, sizeof(int));
1201 temp = temp + sizeof(int);
1214 net_nfc_create_data(&write_block, buffer, 16);
1216 if((result = net_nfc_mifare_write_block(tag_handle, addr, write_block,NULL)) != NET_NFC_OK){
1217 PRINT_INFO("failed to write = [%d]", result);
1219 PRINT_INFO("block 5 is written");
1222 if((result = net_nfc_mifare_read(tag_handle, addr, NULL)) != NET_NFC_OK){
1223 PRINT_INFO("failed to read = [%d]", result);
1225 PRINT_INFO("block 5 is read");
1229 // read block 6 and decrease 6 and read again
1232 if((result = net_nfc_mifare_read(tag_handle, 7, NULL)) != NET_NFC_OK){
1233 PRINT_INFO("failed to read = [%d]", result);
1235 PRINT_INFO("read sector trailor of sector 1. it will be a block 7 th");
1240 data_h write_block = NULL;
1241 uint8_t buffer[16] = {0x00, 0x00, 0x03, 0xE8, 0xFF, 0xFF, 0xFC, 0x18, 0x00, 0x00, 0x03, 0xE8, 0x05, 0xFB, 0x05, 0xFB};
1243 net_nfc_create_data(&write_block, buffer, 16);
1245 if((result = net_nfc_mifare_write_block(tag_handle, 5, write_block, NULL)) != NET_NFC_OK){
1246 PRINT_INFO("failed to write = [%d]", result);
1248 PRINT_INFO("block 5 is written");
1252 if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
1253 PRINT_INFO("failed to read = [%d]", result);
1255 PRINT_INFO("block 5 is read");
1260 if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
1261 PRINT_INFO("failed to read = [%d]", result);
1265 int decrease_amount = 10; // 10 won
1267 if((result = net_nfc_mifare_decrement(tag_handle, 5, decrease_amount, NULL)) != NET_NFC_OK){
1268 PRINT_INFO("failed to decrease = [%d]", result);
1270 PRINT_INFO("block 5 is decreased");
1273 if((result = net_nfc_mifare_transfer(tag_handle, 5, NULL)) != NET_NFC_OK){
1274 PRINT_INFO("failed to transfer = [%d]", result);
1276 PRINT_INFO("internal register is transfered to block 5");
1280 if((result = net_nfc_mifare_read(tag_handle, 5, NULL)) != NET_NFC_OK){
1281 PRINT_INFO("failed to read = [%d]", result);
1285 net_nfc_free_data(mad_key);
1286 net_nfc_free_data(default_key);
1287 net_nfc_free_data(net_nfc_forum_key);
1293 else if(type == NET_NFC_JEWEL_PICC){
1295 if(net_nfc_jewel_read_id(id, NULL) != NET_NFC_OK){
1296 PRINT_INFO("failed to read ID");
1301 }else if(type == NET_NFC_FELICA_PICC){
1304 net_nfc_error_e result = NET_NFC_OK;
1307 if((result = net_nfc_felica_poll(id, NET_NFC_FELICA_POLL_COMM_SPEED_REQUEST, 0x0, NULL)) != NET_NFC_OK){
1308 PRINT_INFO("can not execute cmd felica poll");
1311 PRINT_INFO("send poll req cmd is success");
1314 if((result = net_nfc_felica_request_system_code(id, NULL)) != NET_NFC_OK){
1315 PRINT_INFO("can not execute cmd felica request system code");
1318 PRINT_INFO("send request system req cmd is success");
1321 if((result = net_nfc_felica_request_response(id, NULL)) != NET_NFC_OK){
1322 PRINT_INFO("can not execute cmd felica request response");
1325 PRINT_INFO("send request response cmd is success");
1328 uint16_t service_code = 0xffff;
1329 if((result = net_nfc_felica_request_service(id, 1, &service_code, 1, NULL)) != NET_NFC_OK){
1330 PRINT_INFO("can not execute cmd felica request response");
1333 PRINT_INFO("send request response cmd is success");
1337 uint16_t service_code = 0xffff;
1338 uint8_t blocks = 0x2;
1340 if((result = net_nfc_felica_read_without_encryption(id, 1, &service_code, 1, &blocks, NULL)) != NET_NFC_OK){
1341 PRINT_INFO("can not execute cmd felica request response");
1344 PRINT_INFO("send request response cmd is success");
1350 case NET_NFC_MESSAGE_TRANSCEIVE:{
1351 if (result == NET_NFC_OK) {
1353 if(test_count == 0){
1355 data_h r_data = (data_h) data;
1357 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1358 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1360 PRINT_INFO ("read uid is ok. format is = > [HeadRom0][HeadRom1][UID0][UID1][UID2][UID3]");
1361 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1363 for (idx = 0; idx < r_buffer_length; idx++){
1364 printf (" %02X", r_buffer[idx]);
1367 PRINT_INFO("READ ALL DATA");
1368 if((result = net_nfc_jewel_read_all(tag_handle, NULL)) != NET_NFC_OK){
1369 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1374 else if(test_count == 1){
1376 data_h r_data = (data_h) data;
1378 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1379 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1381 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1383 for (idx = 0; idx < r_buffer_length; idx++){
1384 printf (" %02X", r_buffer[idx]);
1387 test_case_result = NET_NFC_TEST_OK;
1391 PRINT_INFO("READ one byte. addr is the first byte of block 0");
1392 if((result = net_nfc_jewel_read_byte(tag_handle, 0, 0, NULL)) != NET_NFC_OK){
1393 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1399 else if(test_count == 2){
1401 data_h r_data = (data_h) data;
1403 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1404 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1406 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1408 for (idx = 0; idx < r_buffer_length; idx++){
1409 printf (" %02X", r_buffer[idx]);
1412 test_case_result = NET_NFC_TEST_OK;
1415 PRINT_INFO("erase and write data 0xff . addr is the first byte of block 1");
1416 if((result = net_nfc_jewel_write_with_erase(tag_handle, 1, 0, 0xff, NULL)) != NET_NFC_OK){
1417 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1422 else if(test_count == 3){
1424 data_h r_data = (data_h) data;
1426 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1427 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1429 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1431 for (idx = 0; idx < r_buffer_length; idx++){
1432 printf (" %02X", r_buffer[idx]);
1435 test_case_result = NET_NFC_TEST_OK;
1438 PRINT_INFO("read one byte . addr is the first byte of block 1");
1439 if((result = net_nfc_jewel_read_byte(tag_handle, 1, 0, NULL)) != NET_NFC_OK){
1440 PRINT_INFO("failed to read all jewel tag = [%d]", result);
1445 else if(test_count == 4){
1448 data_h r_data = (data_h) data;
1450 uint8_t * r_buffer = net_nfc_get_data_buffer (r_data);
1451 uint32_t r_buffer_length = net_nfc_get_data_length (r_data);
1453 PRINT_INFO ("Received data [size:%d] \n", net_nfc_get_data_length (r_data));
1455 for (idx = 0; idx < r_buffer_length; idx++){
1456 printf (" %02X", r_buffer[idx]);
1459 else if(test_count == 5){
1460 PRINT_INFO("auth key A is success = [%d]", result);
1461 test_case_result = NET_NFC_TEST_OK;
1462 net_nfc_error_e result = NET_NFC_OK;
1464 if((result = net_nfc_mifare_read(tag_handle, 0, NULL)) != NET_NFC_OK){
1466 PRINT_INFO("failed to read = [%d]", result);
1468 PRINT_INFO("calling read is ok");
1477 PRINT_INFO("trancecive is failed with %d\n", result);
1478 test_case_result = NET_NFC_TEST_FAIL;
1480 //pthread_mutex_lock (&plock);
1481 //pthread_cond_signal (&pcond);
1482 //pthread_mutex_unlock (&plock);
1492 #define NUM_OF_THREAD 10
1493 #define REQUEST_PER_THREAD 5
1495 static number_of_read_completed = 0;
1497 static void* net_nfc_read_ndef_test(void* handle)
1499 net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
1502 for (count = 0; count < REQUEST_PER_THREAD ; count ++)
1504 if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
1506 PRINT_INFO("send request is success");
1510 PRINT_INFO("send request is failed");
1514 return (void *)NULL;
1516 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)
1520 printf ("callback is called with message %d\n", message);
1524 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1526 net_nfc_target_type_e type;
1527 net_nfc_target_handle_h handle;
1529 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1531 net_nfc_get_tag_type (target_info, &type);
1532 net_nfc_get_tag_handle (target_info, &handle);
1533 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1534 PRINT_INFO("target type: %d\n", type);
1535 PRINT_INFO("target handle: %X\n", handle);
1536 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1538 test_case_result = NET_NFC_TEST_OK;
1539 number_of_read_completed = 0;
1541 pthread_t read_thread[NUM_OF_THREAD];
1542 pthread_attr_t attr;
1543 pthread_attr_init(&attr);
1544 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1547 for(; i < NUM_OF_THREAD; i++)
1549 pthread_create(&read_thread[i], &attr, net_nfc_read_ndef_test, handle);
1555 case NET_NFC_MESSAGE_READ_NDEF:
1557 PRINT_INFO("NET_NFC_MESSAGE_READ_NDEF result = [%d]\n", result);
1561 PRINT_INFO("read ndef msg");
1562 number_of_read_completed ++;
1564 ndef_message_h ndef = (ndef_message_h)(data);
1566 ////net_nfc_ndef_print_message(ndef);
1568 if (number_of_read_completed == NUM_OF_THREAD * REQUEST_PER_THREAD)
1570 test_case_result = NET_NFC_TEST_OK;
1571 PRINT_INSTRUCT("Test is completed. please remove the tag !!");
1577 case NET_NFC_MESSAGE_TAG_DETACHED:
1579 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
1581 pthread_mutex_lock (&plock);
1582 pthread_cond_signal (&pcond);
1583 pthread_mutex_unlock (&plock);
1587 case NET_NFC_MESSAGE_NOTIFY:
1589 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1598 #define NUM_OF_DETECT_TRY 10
1600 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)
1604 printf ("callback is called with message %d\n", message);
1608 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1610 net_nfc_target_type_e type;
1611 net_nfc_target_handle_h id;
1613 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1615 net_nfc_get_tag_type (target_info, &type);
1616 net_nfc_get_tag_handle (target_info, &id);
1617 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1619 PRINT_INFO("target type: %d\n", type);
1620 PRINT_INFO("target handle: %X\n", id);
1621 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1624 int nok = 0; // number of keys
1625 net_nfc_error_e error = NET_NFC_OK;
1627 if((error = net_nfc_get_tag_info_keys(target_info, &keys, &nok)) == NET_NFC_OK)
1632 PRINT_INFO("key [%s]", keys[i]);
1634 data_h value = NULL;
1635 if((error = net_nfc_get_tag_info_value(target_info, keys[i], &value)) == NET_NFC_OK)
1638 uint32_t data_length = net_nfc_get_data_length(value);
1639 uint8_t* data_buffer = net_nfc_get_data_buffer(value);
1641 PRINT_INFO("\n key >> ", keys[i]);
1644 for(; index < data_length; index++)
1646 printf(" [0x%x] ", data_buffer[index]);
1651 printf(" [0x%x] ", *data_buffer);
1655 PRINT_INFO("<< \n");
1659 PRINT_INFO("get value is failed = [0x%x]", error);
1665 PRINT_INFO("failed to get keys = [%d]", error);
1673 PRINT_INFO("TAG is detected = [%d]", detect_count);
1674 PRINT_INSTRUCT("please remove the tag !! Test left [%d] times", NUM_OF_DETECT_TRY - detect_count);
1679 case NET_NFC_MESSAGE_TAG_DETACHED:
1681 PRINT_INSTRUCT("please close the tag again!!");
1683 //pthread_mutex_lock (&plock);
1684 //pthread_cond_signal (&pcond);
1685 //pthread_mutex_unlock (&plock);
1687 if(detect_count >= NUM_OF_DETECT_TRY)
1689 test_case_result = NET_NFC_TEST_OK;
1690 pthread_mutex_lock (&plock);
1691 pthread_cond_signal (&pcond);
1692 pthread_mutex_unlock (&plock);
1697 case NET_NFC_MESSAGE_NOTIFY:
1699 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1709 static void* net_nfc_read_stress_ndef_test(void* handle)
1711 net_nfc_target_handle_h target_handle = (net_nfc_target_handle_h)handle;
1714 for (count = 0; count < 200 ; count ++)
1716 if(net_nfc_read_tag(target_handle, NULL) == NET_NFC_OK)
1721 PRINT_INFO("send request is failed");
1725 PRINT_INFO("send request is completed");
1727 return (void *)NULL;
1730 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)
1736 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1738 net_nfc_target_type_e type;
1739 net_nfc_target_handle_h handle;
1741 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1743 net_nfc_get_tag_type (target_info, &type);
1744 net_nfc_get_tag_handle (target_info, &handle);
1745 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1746 PRINT_INFO("target type: %d\n", type);
1747 PRINT_INFO("target handle: %X\n", handle);
1748 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1752 pthread_t read_thread;
1753 pthread_attr_t attr;
1754 pthread_attr_init(&attr);
1755 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1757 pthread_create(&read_thread, &attr, net_nfc_read_stress_ndef_test, handle);
1761 PRINT_INFO("non ndef tag.");
1763 test_case_result = NET_NFC_TEST_FAIL;
1765 pthread_mutex_lock (&plock);
1766 pthread_cond_signal (&pcond);
1767 pthread_mutex_unlock (&plock);
1773 case NET_NFC_MESSAGE_READ_NDEF:
1777 ndef_message_h ndef = (ndef_message_h)(data);
1779 ////net_nfc_ndef_print_message(ndef);
1781 test_case_result = NET_NFC_TEST_OK;
1786 if(read_count == 20)
1788 PRINT_INSTRUCT("please remove the tag !!");
1795 case NET_NFC_MESSAGE_TAG_DETACHED:
1797 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
1799 if (read_count >= 20 && read_count < 200){
1800 test_case_result = NET_NFC_TEST_OK;
1801 pthread_mutex_lock (&plock);
1802 pthread_cond_signal (&pcond);
1803 pthread_mutex_unlock (&plock);
1806 PRINT_INSTRUCT("please close the tag again !!");
1813 case NET_NFC_MESSAGE_NOTIFY:
1815 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1825 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)
1829 printf ("callback is called with message %d\n", message);
1833 case NET_NFC_MESSAGE_TAG_DISCOVERED:
1835 net_nfc_target_type_e type;
1836 net_nfc_target_handle_h handle;
1838 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
1840 net_nfc_get_tag_type (target_info, &type);
1841 net_nfc_get_tag_handle (target_info, &handle);
1842 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
1843 PRINT_INFO("target type: %d\n", type);
1844 PRINT_INFO("target handle: %X\n", handle);
1845 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
1849 tag_handle = handle;
1850 if(net_nfc_read_tag(handle, user_param) == NET_NFC_OK)
1852 PRINT_INFO("try to read ndef");
1857 PRINT_INFO("non ndef tag.");
1859 test_case_result = NET_NFC_TEST_FAIL;
1861 pthread_mutex_lock (&plock);
1862 pthread_cond_signal (&pcond);
1863 pthread_mutex_unlock (&plock);
1869 case NET_NFC_MESSAGE_READ_NDEF:
1871 if (write_count >= 50){
1872 PRINT_INSTRUCT("Test is finished. Please remove the tag from device!!");
1873 test_case_result = NET_NFC_TEST_OK;
1878 ndef_message_h ndef = (ndef_message_h)(data);
1880 ////net_nfc_ndef_print_message(ndef);
1882 test_case_result = NET_NFC_TEST_OK;
1884 net_nfc_error_e error = NET_NFC_OK;
1885 ndef_message_h msg = NULL;
1886 ndef_record_h record = NULL;
1888 if( (error = net_nfc_create_text_type_record(&record, "This is real NFC", "en-US", NET_NFC_ENCODE_UTF_8)) == NET_NFC_OK)
1890 if( (error = net_nfc_create_ndef_message(&msg)) == NET_NFC_OK)
1892 if( (error = net_nfc_append_record_to_ndef_message(msg, record)) == NET_NFC_OK)
1894 ////net_nfc_ndef_print_message(msg);
1896 if(net_nfc_write_ndef(tag_handle, msg, &user_context) == NET_NFC_OK)
1898 PRINT_INFO("write count = [%d] \n", write_count++);
1899 PRINT_INFO("write ndef msg");
1901 net_nfc_free_ndef_message(msg);
1905 PRINT_INFO("failed to append ndef message = [%d]", error);
1906 net_nfc_free_record(record);
1907 net_nfc_free_ndef_message(msg);
1909 pthread_mutex_lock (&plock);
1910 pthread_cond_signal (&pcond);
1911 pthread_mutex_unlock (&plock);
1916 PRINT_INFO("failed to create ndef msg");
1917 net_nfc_free_record(record);
1919 pthread_mutex_lock (&plock);
1920 pthread_cond_signal (&pcond);
1921 pthread_mutex_unlock (&plock);
1926 PRINT_INFO("failed to create text type record");
1928 pthread_mutex_lock (&plock);
1929 pthread_cond_signal (&pcond);
1930 pthread_mutex_unlock (&plock);
1937 test_case_result = NET_NFC_TEST_FAIL;
1939 pthread_mutex_lock (&plock);
1940 pthread_cond_signal (&pcond);
1941 pthread_mutex_unlock (&plock);
1946 //net_nfc_read_ndef(tag_handle, user_param);
1952 case NET_NFC_MESSAGE_WRITE_NDEF:
1954 if (result == NET_NFC_OK) {
1956 test_case_result = NET_NFC_TEST_OK;
1958 if(net_nfc_read_tag(tag_handle, user_param) == NET_NFC_OK)
1960 PRINT_INFO("read count = [%d] \n", read_count++);
1961 PRINT_INFO("try to read ndef");
1965 PRINT_INFO("received error: %d\n", result);
1966 test_case_result = NET_NFC_TEST_FAIL;
1968 pthread_mutex_lock (&plock);
1969 pthread_cond_signal (&pcond);
1970 pthread_mutex_unlock (&plock);
1975 case NET_NFC_MESSAGE_TAG_DETACHED:
1977 PRINT_INFO("NET_NFC_MESSAGE_TAG_DETACHED \n");
1979 pthread_mutex_lock (&plock);
1980 pthread_cond_signal (&pcond);
1981 pthread_mutex_unlock (&plock);
1985 case NET_NFC_MESSAGE_NOTIFY:
1987 PRINT_INFO("NET_NFC_MESSAGE_NOTIFY \n");
1997 int nfcTestAPIMultipleRequest(uint8_t testNumber,void* arg_ptr2)
1999 int user_context = 0;
2000 net_nfc_error_e result;
2001 test_case_result = NET_NFC_TEST_FAIL;
2003 result = net_nfc_initialize();
2004 CHECK_RESULT(result);
2006 net_nfc_state_activate(1);
2008 result = net_nfc_set_response_callback (net_nfc_test_multiple_request_cb, NULL);
2009 CHECK_RESULT(result);
2011 PRINT_INSTRUCT("Please close a tag to device for a while!!");
2013 //pthread_cond_wait (&pcond,&plock );
2015 result = net_nfc_unset_response_callback ();
2016 CHECK_RESULT(result);
2018 result = net_nfc_deinitialize ();
2019 CHECK_RESULT(result);
2021 return test_case_result;
2025 int nfcTestAPIBasicTest1(uint8_t testNumber,void* arg_ptr2)
2027 int user_context = 0;
2028 net_nfc_error_e result;
2029 test_case_result = NET_NFC_TEST_FAIL;
2038 for(i; i < NET_NFC_NFCIP1_INITIATOR; i++)
2040 if(net_nfc_get_tag_info_keys(i, &keys, &length) == NET_NFC_OK)
2044 PRINT_INFO("############################\n") ;
2045 for(; index < length; index++)
2047 PRINT_INFO("supported key = [%s] \n", keys[index]);
2049 PRINT_INFO("############################\n") ;
2051 test_case_result = NET_NFC_TEST_OK;
2056 result = net_nfc_initialize();
2057 CHECK_RESULT(result);
2059 net_nfc_state_activate(1);
2061 result = net_nfc_set_response_callback (net_nfc_test_detected_cb, NULL);
2063 // net_nfc_set_tag_filter(NET_NFC_ALL_DISABLE);
2064 // net_nfc_set_tag_filter(NET_NFC_ISO14443A_ENABLE);
2065 // net_nfc_set_tag_filter(NET_NFC_ISO14443B_ENABLE);
2066 // net_nfc_set_tag_filter(NET_NFC_ISO15693_ENABLE );
2067 // net_nfc_set_tag_filter(NET_NFC_FELICA_ENABLE );
2068 // net_nfc_set_tag_filter(NET_NFC_JEWEL_ENABLE );
2069 // net_nfc_set_tag_filter(NET_NFC_ALL_ENABLE );
2072 CHECK_RESULT(result);
2074 //PRINT_INSTRUCT("Please close a tag to device!!");
2076 //pthread_cond_wait (&pcond,&plock );
2079 result = net_nfc_unset_response_callback ();
2080 CHECK_RESULT(result);
2082 result = net_nfc_deinitialize ();
2086 CHECK_RESULT(result);
2089 return test_case_result;
2092 int nfcTestAPIBasicTest2(uint8_t testNumber,void* arg_ptr2)
2094 int user_context = 0;
2095 net_nfc_error_e result;
2096 test_case_result = NET_NFC_TEST_FAIL;
2098 result = net_nfc_initialize();
2099 CHECK_RESULT(result);
2101 net_nfc_state_activate(1);
2105 result = net_nfc_set_response_callback (net_nfc_test_read_cb, NULL);
2106 CHECK_RESULT(result);
2108 PRINT_INSTRUCT("remove tag while reading operation !!");
2109 PRINT_INSTRUCT("Please close a tag to device!!");
2112 pthread_cond_wait (&pcond,&plock );
2114 result = net_nfc_unset_response_callback ();
2115 CHECK_RESULT(result);
2117 result = net_nfc_deinitialize ();
2118 CHECK_RESULT(result);
2120 return test_case_result;
2123 int nfcTestAPIBasicTest3(uint8_t testNumber,void* arg_ptr2)
2125 int user_context = 0;
2126 net_nfc_error_e result;
2127 test_case_result = NET_NFC_TEST_FAIL;
2129 ndef_message_h ndef_message = NULL;
2131 if(net_nfc_retrieve_current_ndef_message(&ndef_message) == NET_NFC_OK)
2134 if(net_nfc_get_ndef_message_record_count(ndef_message, &count) == NET_NFC_OK)
2137 for(; i < count; i++)
2139 ndef_record_h record = NULL;
2140 if(net_nfc_get_record_by_index(ndef_message, i, &record) == NET_NFC_OK)
2142 net_nfc_record_tnf_e tnf;
2143 if(net_nfc_get_record_tnf(record, &tnf) == NET_NFC_OK)
2147 case NET_NFC_RECORD_WELL_KNOWN_TYPE:
2150 data_h payload = NULL;
2152 if(net_nfc_get_record_type(record, &type) == NET_NFC_OK && net_nfc_get_record_payload(record, &payload) == NET_NFC_OK)
2154 if(strcmp(net_nfc_get_data_buffer(type), "Sp") == 0)
2158 else if(strcmp(net_nfc_get_data_buffer(type), "T") == 0)
2161 net_nfc_encode_type_e utf;
2162 uint32_t utf_length = 0;
2163 uint32_t lang_length = 0;
2165 uint32_t text_length = 0;
2166 char* language_code_str = NULL;
2168 if(net_nfc_get_encoding_type_from_text_record(record, &utf) == NET_NFC_OK)
2170 PRINT_INFO("utf = [%s]", utf);
2174 PRINT_INFO("failed to get utf");
2177 if(net_nfc_get_languange_code_string_from_text_record(record, &language_code_str) == NET_NFC_OK)
2179 PRINT_INFO("language_code = [%s]", language_code_str);
2183 PRINT_INFO("failed to get language code");
2186 if(net_nfc_create_text_string_from_text_record(record, &text) == NET_NFC_OK)
2188 PRINT_INFO("text = [%s]", text);
2192 PRINT_INFO("failed to get text");
2198 uint8_t* utf = NULL;
2199 uint8_t* language_code = NULL;
2200 uint8_t* text = NULL;
2203 uint8_t* buffer = net_nfc_get_data_buffer(payload);
2204 uint32_t buffer_length = net_nfc_get_data_length(payload);
2206 PRINT_INFO("\n from file >>>");
2208 for(; index < buffer_length; index++)
2210 printf(" [%d] ", buffer[index]);
2213 PRINT_INFO("\n from file <<<");
2217 int controllbyte = buffer[0];
2219 if((controllbyte & 0x80)== 1)
2221 PRINT_INFO("UTF-16");
2222 utf = (uint8_t*)"UTF-16";
2226 PRINT_INFO("UTF-8");
2227 utf = (uint8_t*)"UTF-8";
2230 int lang_code_length = controllbyte & 0x3F;
2234 language_code = (uint8_t *)malloc(lang_code_length + 1);
2236 memset(language_code, 0x00, lang_code_length + 1);
2237 memcpy(language_code, &(buffer[index]), lang_code_length);
2239 PRINT_INFO("lang_code = [%s]", language_code);
2241 index = lang_code_length + 1;
2243 int text_length = buffer_length - (lang_code_length + 1); // payload length - (lang code length + control byte)
2245 PRINT_INFO("buffer length = [%d]", buffer_length);
2246 PRINT_INFO("lang_code_length = [%d]", lang_code_length);
2247 PRINT_INFO("text_length = [%d]", text_length);
2249 text = (uint8_t *)malloc(text_length + 1);
2251 memset(text, 0x00, text_length + 1);
2252 memcpy(text, &(buffer[index]), text_length);
2254 PRINT_INFO("encoding type = [%s]", utf);
2255 PRINT_INFO("lang_code = [%s]", language_code);
2256 PRINT_INFO("text = [%s]", text);
2257 test_case_result = NET_NFC_TEST_OK;
2260 else if(strcmp(net_nfc_get_data_buffer(type), "U") == 0)
2274 PRINT_INFO("unknow type");
2284 CHECK_RESULT(result);
2286 return test_case_result;
2289 int nfcTestTransceive(uint8_t testNumber,void* arg_ptr2)
2291 int user_context = 0;
2292 net_nfc_error_e result;
2293 test_case_result = NET_NFC_TEST_FAIL;
2295 result = net_nfc_initialize();
2296 CHECK_RESULT(result);
2298 net_nfc_state_activate(1);
2300 result = net_nfc_set_response_callback (net_nfc_test_transceive_cb, NULL);
2301 CHECK_RESULT(result);
2303 PRINT_INSTRUCT("Please close a tag to device!!");
2305 //pthread_cond_wait (&pcond,&plock );
2307 result = net_nfc_unset_response_callback ();
2308 CHECK_RESULT(result);
2309 result = net_nfc_deinitialize ();
2310 CHECK_RESULT(result);
2313 return test_case_result;
2316 /*=================================================================================*/
2319 int nfcTestNdefParser(uint8_t testNumber,void* arg_ptr2)
2321 net_nfc_error_e result;
2323 ndef_message_h uriMsg = NULL;
2324 ndef_message_h spMsg = NULL;
2325 ndef_record_h uriRecord = NULL;
2326 ndef_record_h spRecord = NULL;
2327 data_h type_data = NULL;
2328 data_h raw_data = NULL;
2329 char smart_poster_type[] = "Sp";
2330 ndef_record_h record = NULL;
2331 test_case_result = NET_NFC_TEST_OK;
2333 result = net_nfc_create_ndef_message (&uriMsg);
2334 CHECK_RESULT(result);
2336 result = net_nfc_create_uri_type_record (&record ,"http://www.naver.com", NET_NFC_SCHEMA_FULL_URI);
2337 CHECK_RESULT(result);
2339 result = net_nfc_append_record_to_ndef_message (uriMsg, record);
2340 CHECK_RESULT(result);
2344 result = net_nfc_create_text_type_record (&record ,"This is the URI Test" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2345 CHECK_RESULT(result);
2347 result = net_nfc_append_record_to_ndef_message (uriMsg, record);
2348 CHECK_RESULT(result);
2350 result = net_nfc_create_text_type_record (&record ,"Hello World" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2351 CHECK_RESULT(result);
2353 result = net_nfc_append_record_by_index (uriMsg,0 ,record);
2354 CHECK_RESULT(result);
2356 result = net_nfc_create_text_type_record (&record ,"TEST1" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2357 CHECK_RESULT(result);
2359 result = net_nfc_append_record_by_index (uriMsg,1 ,record);
2360 CHECK_RESULT(result);
2362 result = net_nfc_create_text_type_record (&record ,"TEST2" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2363 CHECK_RESULT(result);
2365 result = net_nfc_append_record_by_index (uriMsg,2 ,record);
2366 CHECK_RESULT(result);
2368 result = net_nfc_create_text_type_record (&record ,"TEST3" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
2369 CHECK_RESULT(result);
2372 result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
2373 CHECK_RESULT(result);
2375 result = net_nfc_append_record_by_index (uriMsg, position ,record);
2376 CHECK_RESULT(result);
2378 //_//net_nfc_ndef_print_message (uriMsg);
2380 result = net_nfc_create_data (&type_data ,"U", 1);
2381 CHECK_RESULT(result);
2383 result = net_nfc_search_record_by_type (uriMsg ,NET_NFC_RECORD_WELL_KNOWN_TYPE ,type_data ,&record);
2384 CHECK_RESULT(result);
2385 if (record != uriRecord){
2386 PRINT_RESULT_FAIL("Record search result does not matched");
2387 return NET_NFC_TEST_FAIL;
2390 result = net_nfc_remove_record_by_index (uriMsg ,1);
2391 CHECK_RESULT(result);
2393 result = net_nfc_remove_record_by_index (uriMsg ,0);
2394 CHECK_RESULT(result);
2396 result = net_nfc_get_ndef_message_record_count (uriMsg,&position);
2397 CHECK_RESULT(result);
2399 result = net_nfc_remove_record_by_index (uriMsg, position - 1);
2400 CHECK_RESULT(result);
2402 result = net_nfc_remove_record_by_index (uriMsg ,2);
2403 CHECK_RESULT(result);
2405 //_//net_nfc_ndef_print_message (uriMsg);
2407 result = net_nfc_create_rawdata_from_ndef_message (uriMsg, &raw_data);
2408 CHECK_RESULT(result);
2410 result = net_nfc_create_data (&type_data, smart_poster_type, strlen (smart_poster_type));
2411 CHECK_RESULT(result);
2413 result = net_nfc_create_record (&spRecord, NET_NFC_RECORD_WELL_KNOWN_TYPE,type_data , NULL, raw_data);
2414 CHECK_RESULT(result);
2416 result = net_nfc_create_ndef_message (&spMsg);
2417 CHECK_RESULT(result);
2419 result = net_nfc_append_record_to_ndef_message (spMsg, spRecord);
2420 CHECK_RESULT(result);
2422 net_nfc_free_data (type_data);
2423 net_nfc_free_data (raw_data);
2425 return test_case_result;
2428 /*=================================================================================*/
2430 net_nfc_llcp_socket_t server_socket;
2431 net_nfc_llcp_socket_t accepted_socket;
2432 net_nfc_llcp_socket_t client_socket;
2434 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)
2436 PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
2440 case NET_NFC_MESSAGE_LLCP_LISTEN:
2442 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2444 case NET_NFC_MESSAGE_LLCP_CONNECT:
2446 PRINT_INFO ("LLCP connect is completed with error code %d", result);
2448 char * str = "Client message: Hello, server!";
2449 net_nfc_create_data (&data, str ,strlen (str) + 1);
2450 net_nfc_send_llcp (client_socket, data, NULL);
2453 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2455 case NET_NFC_MESSAGE_LLCP_SEND:
2457 PRINT_INFO ("LLCP send is completed with error code %d", result);
2458 net_nfc_receive_llcp (client_socket, 512 ,NULL);
2462 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2463 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2464 data_h received_data = (data_h) data;
2465 PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
2467 net_nfc_disconnect_llcp (client_socket ,NULL);
2469 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2471 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2472 net_nfc_close_llcp_socket (client_socket, NULL);
2475 case NET_NFC_MESSAGE_LLCP_ERROR:
2476 PRINT_INFO ("LLCP socket error is completed with error code %d", result);
2477 net_nfc_close_llcp_socket (client_socket, NULL);
2486 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)
2488 PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
2491 case NET_NFC_MESSAGE_LLCP_LISTEN:
2493 PRINT_INFO ("LLCP Listen is completed with error code %d", result);
2497 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2499 PRINT_INFO ("LLCP accept is completed with error code %d", result);
2500 accepted_socket = *(net_nfc_llcp_socket_t *)(data);
2501 net_nfc_set_llcp_socket_callback (accepted_socket, net_nfc_server_socket_cb, NULL);
2502 net_nfc_receive_llcp (accepted_socket, 512 ,NULL);
2505 case NET_NFC_MESSAGE_LLCP_CONNECT:
2507 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2509 case NET_NFC_MESSAGE_LLCP_SEND:
2511 PRINT_INFO ("LLCP send is completed with error code %d", result);
2512 net_nfc_disconnect_llcp (accepted_socket ,NULL);
2516 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2518 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2519 data_h received_data = (data_h) data;
2520 PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
2523 char * str = "Server message: Welcome NFC llcp world!";
2524 net_nfc_create_data (&data, str ,strlen (str) + 1);
2525 net_nfc_send_llcp (accepted_socket, data, NULL);
2529 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2531 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2532 net_nfc_close_llcp_socket (accepted_socket, NULL);
2535 case NET_NFC_MESSAGE_LLCP_ERROR:
2537 PRINT_INFO ("LLCP socket error is received with code %d", result);
2538 net_nfc_close_llcp_socket (accepted_socket, NULL);
2539 net_nfc_close_llcp_socket (server_socket, NULL);
2547 net_nfc_target_handle_h snep_handle;
2548 net_nfc_exchanger_data_h snep_ex_data = NULL;
2551 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)
2553 PRINT_INFO ("client message received [%d]", message);
2557 case NET_NFC_MESSAGE_P2P_DISCOVERED:
2559 snep_handle = (net_nfc_target_handle_h) data;
2560 //= (net_nfc_target_handle_h) target_info->handle;
2561 /* Fill the data to send. */
2563 if(NET_NFC_OK == net_nfc_create_exchanger_data(&snep_ex_data, nfcTestUri))
2565 if(net_nfc_send_exchanger_data(snep_ex_data, snep_handle) == NET_NFC_OK)
2567 PRINT_INFO ("exchanger data send success");
2571 PRINT_INFO ("exchanger data send fail");
2576 PRINT_INFO ("create exchanger data fail");
2582 case NET_NFC_MESSAGE_P2P_SEND:
2584 PRINT_INFO ("NET_NFC_MESSAGE_P2P_SEND result [%d]", result);
2589 case NET_NFC_MESSAGE_P2P_DETACHED:
2591 PRINT_INFO ("Target disconnected.");
2596 case NET_NFC_MESSAGE_P2P_RECEIVE:
2599 // data_h received_data = (data_h)data;
2601 // PRINT_INFO ("NET_NFC_MESSAGE_P2P_RECEIVE [%s]", net_nfc_get_data_buffer(received_data));
2602 // PRINT_INFO (" length [%d]", net_nfc_get_data_length(received_data));
2611 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)
2615 case NET_NFC_MESSAGE_LLCP_DISCOVERED:
2617 net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
2618 uint8_t lto, option;
2620 net_nfc_get_llcp_configure_lto (config , <o);
2621 net_nfc_get_llcp_configure_wks (config , &wks);
2622 net_nfc_get_llcp_configure_miu (config , &miu);
2623 net_nfc_get_llcp_configure_option (config , &option);
2625 PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
2627 net_nfc_create_llcp_socket (&server_socket, NULL);
2628 net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_socket_cb, NULL);
2629 net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
2631 net_nfc_create_llcp_socket (&client_socket, NULL);
2632 net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_socket_cb, NULL);
2633 net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
2637 case NET_NFC_MESSAGE_LLCP_CONFIG:
2639 PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
2643 case NET_NFC_MESSAGE_P2P_DETACHED:
2645 PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
2654 int nfcTestSnep(uint8_t testNumber,void* arg_ptr)
2656 net_nfc_error_e result;
2658 result = net_nfc_initialize();
2659 CHECK_RESULT(result);
2660 net_nfc_state_activate (1);
2661 result = net_nfc_set_response_callback (net_nfc_test_snep_cb, NULL);
2663 PRINT_INSTRUCT("START SNEP test !!");
2664 return NET_NFC_TEST_OK;
2667 int nfcTestLLCP(uint8_t testNumber,void* arg_ptr2)
2669 net_nfc_error_e result;
2670 net_nfc_llcp_config_info_h config;
2671 result = net_nfc_initialize();
2672 CHECK_RESULT(result);
2673 net_nfc_state_activate (1);
2674 result = net_nfc_set_response_callback (net_nfc_test_llcp_cb, NULL);
2675 CHECK_RESULT(result);
2676 result = net_nfc_create_llcp_configure_default (&config);
2677 CHECK_RESULT(result);
2678 result = net_nfc_set_llcp_local_configure (config ,NULL);
2680 PRINT_INSTRUCT("Please start P2P communicate!!");
2683 pthread_cond_wait (&pcond,&plock );
2685 result = net_nfc_unset_response_callback ();
2686 CHECK_RESULT(result);
2687 result = net_nfc_deinitialize ();
2688 CHECK_RESULT(result);
2691 return NET_NFC_TEST_OK;
2694 /*=================================================================================*/
2696 /* LLCP Stress Test */
2698 net_nfc_llcp_socket_t server_socket;
2699 net_nfc_llcp_socket_t client_socket;
2701 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)
2703 PRINT_INFO ("\nCLIENT callback is called MESSAGE[%d]", message);
2707 case NET_NFC_MESSAGE_LLCP_LISTEN:
2709 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2711 case NET_NFC_MESSAGE_LLCP_CONNECT:
2713 PRINT_INFO ("LLCP connect is completed with error code %d", result);
2715 char * str = "Client message: Hello, server!";
2716 net_nfc_create_data (&data, str ,strlen (str) + 1);
2717 net_nfc_send_llcp (client_socket, data, NULL);
2720 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2722 case NET_NFC_MESSAGE_LLCP_SEND:
2724 PRINT_INFO ("LLCP send is completed with error code %d", result);
2725 net_nfc_receive_llcp (client_socket, 512 ,NULL);
2729 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2730 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2731 data_h received_data = (data_h) data;
2732 PRINT_INFO ("Server --> Client : %s" , net_nfc_get_data_buffer (received_data));
2734 net_nfc_disconnect_llcp (client_socket ,NULL);
2736 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2738 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2739 net_nfc_close_llcp_socket (client_socket, NULL);
2742 case NET_NFC_MESSAGE_LLCP_ERROR:
2743 PRINT_INFO ("LLCP socket error is completed with error code %d", result);
2744 net_nfc_close_llcp_socket (client_socket, NULL);
2753 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)
2755 PRINT_INFO ("\nSERVER callback is called MESSAGE[%d]", message);
2758 case NET_NFC_MESSAGE_LLCP_LISTEN:
2760 PRINT_INFO ("LLCP Listen is completed with error code %d", result);
2764 case NET_NFC_MESSAGE_LLCP_ACCEPTED:
2766 PRINT_INFO ("LLCP accept is completed with error code %d", result);
2767 net_nfc_receive_llcp (server_socket, 512 ,NULL);
2770 case NET_NFC_MESSAGE_LLCP_CONNECT:
2772 case NET_NFC_MESSAGE_LLCP_CONNECT_SAP:
2774 case NET_NFC_MESSAGE_LLCP_SEND:
2776 PRINT_INFO ("LLCP send is completed with error code %d", result);
2777 net_nfc_disconnect_llcp (server_socket ,NULL);
2781 case NET_NFC_MESSAGE_LLCP_RECEIVE:
2783 PRINT_INFO ("LLCP receive is completed with error code %d", result);
2784 data_h received_data = (data_h) data;
2785 PRINT_INFO ("Server <-- Client : %s" , net_nfc_get_data_buffer (received_data));
2788 char * str = "Server message: Welcome NFC llcp world!";
2789 net_nfc_create_data (&data, str ,strlen (str) + 1);
2790 net_nfc_send_llcp (server_socket, data, NULL);
2794 case NET_NFC_MESSAGE_LLCP_DISCONNECT:
2796 PRINT_INFO ("LLCP disconnect is completed with error code %d", result);
2797 net_nfc_close_llcp_socket (server_socket, NULL);
2801 case NET_NFC_MESSAGE_LLCP_ERROR:
2803 PRINT_INFO ("LLCP socket error is received with code %d", result);
2804 net_nfc_close_llcp_socket (server_socket, NULL);
2812 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)
2816 case NET_NFC_MESSAGE_LLCP_DISCOVERED:
2818 net_nfc_llcp_config_info_h config = (net_nfc_llcp_config_info_h) data;
2819 uint8_t lto, option;
2821 net_nfc_get_llcp_configure_lto (config , <o);
2822 net_nfc_get_llcp_configure_wks (config , &wks);
2823 net_nfc_get_llcp_configure_miu (config , &miu);
2824 net_nfc_get_llcp_configure_option (config , &option);
2826 PRINT_INFO ("Remote Device llcp info:\n \tlto: %d, \twks: %d, \tmiu: %d, \toption: %d", lto, wks, miu, option);
2828 net_nfc_create_llcp_socket (&server_socket, NULL);
2829 net_nfc_set_llcp_socket_callback (server_socket, net_nfc_server_stress_socket_cb, NULL);
2830 net_nfc_listen_llcp (server_socket, "urn:nfc:xsn:samsung.com:testllcp" ,16 ,NULL);
2832 net_nfc_create_llcp_socket (&client_socket, NULL);
2833 net_nfc_set_llcp_socket_callback (client_socket, net_nfc_client_stress_socket_cb, NULL);
2834 net_nfc_connect_llcp (client_socket,"urn:nfc:xsn:samsung.com:testllcp",NULL);
2838 case NET_NFC_MESSAGE_LLCP_CONFIG:
2840 PRINT_INFO ("LLCP llcp local config is completed with error code %d", result);
2844 case NET_NFC_MESSAGE_P2P_DETACHED:
2846 PRINT_INFO ("LLCP NET_NFC_MESSAGE_P2P_DETACHED %d", result);
2855 int nfcTestStressLLCP(uint8_t testNumber,void* arg_ptr2)
2857 net_nfc_error_e result;
2858 net_nfc_llcp_config_info_h config;
2859 result = net_nfc_initialize();
2860 CHECK_RESULT(result);
2861 net_nfc_state_activate (1);
2862 result = net_nfc_set_response_callback (net_nfc_test_llcp_stress_cb, NULL);
2863 CHECK_RESULT(result);
2864 result = net_nfc_create_llcp_configure_default (&config);
2865 CHECK_RESULT(result);
2866 result = net_nfc_set_llcp_local_configure (config ,NULL);
2868 PRINT_INSTRUCT("Please start P2P communicate!!");
2870 pthread_cond_wait (&pcond,&plock );
2872 result = net_nfc_unset_response_callback ();
2873 CHECK_RESULT(result);
2874 result = net_nfc_deinitialize ();
2875 CHECK_RESULT(result);
2878 return NET_NFC_TEST_OK;
2881 /*=================================================================================*/
2884 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)
2886 PRINT_INFO ("Message is received 1 %d", result);
2887 test_case_result = NET_NFC_TEST_FAIL;
2888 pthread_mutex_lock (&plock);
2889 pthread_cond_signal (&pcond);
2890 pthread_mutex_unlock (&plock);
2893 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)
2895 PRINT_INFO ("Message is received 2 %d", result);
2896 test_case_result = NET_NFC_TEST_FAIL;
2897 pthread_mutex_lock (&plock);
2898 pthread_cond_signal (&pcond);
2899 pthread_mutex_unlock (&plock);
2902 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)
2904 PRINT_INFO ("Message is received 3 %d", result);
2905 test_case_result = NET_NFC_TEST_OK;
2906 pthread_mutex_lock (&plock);
2907 pthread_cond_signal (&pcond);
2908 pthread_mutex_unlock (&plock);
2914 int nfcTestAPIException (uint8_t testNumber,void* arg_ptr)
2916 net_nfc_error_e result;
2917 test_case_result = NET_NFC_TEST_FAIL;
2919 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
2920 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_ALREADY_INITIALIZED);
2921 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
2924 for (count_try = 0; count_try < 20; count_try ++)
2926 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
2927 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
2930 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
2931 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_NOT_INITIALIZED);
2934 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
2936 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb1, NULL));
2937 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
2938 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
2939 net_nfc_state_activate (1);
2941 PRINT_INSTRUCT("Please close a tag to device!!");
2943 pthread_cond_wait (&pcond,&plock );
2944 if (!test_case_result) return test_case_result;
2946 PRINT_INSTRUCT("Please remove the tag from device!!");
2947 pthread_cond_wait (&pcond,&plock );
2949 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
2950 CHECK_ASSULT (NET_NFC_OK != net_nfc_set_response_callback (NULL, NULL));
2952 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb2, NULL));
2953 CHECK_ASSULT (NET_NFC_OK == net_nfc_unset_response_callback ());
2955 PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
2958 for (idx = 10 ;idx > 0 ; idx --)
2960 PRINT_INSTRUCT("count down [%d]", idx);
2963 if (!test_case_result) return test_case_result;
2965 PRINT_INSTRUCT("Please remove the tag from device!!");
2968 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
2969 net_nfc_state_activate (1);
2970 net_nfc_state_activate (1);
2971 net_nfc_state_activate (1);
2973 PRINT_INSTRUCT("Please close a tag to device!!");
2975 pthread_cond_wait (&pcond,&plock );
2976 if (!test_case_result) return test_case_result;
2977 PRINT_INSTRUCT("Please remove the tag from device!!");
2978 pthread_cond_wait (&pcond,&plock );
2980 net_nfc_state_deactivate ();
2981 PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
2983 for (idx = 10 ;idx > 0 ; idx --)
2985 PRINT_INSTRUCT("count down [%d]", idx);
2988 if (!test_case_result) return test_case_result;
2989 PRINT_INSTRUCT("Please remove the tag from device!!");
2992 net_nfc_state_activate (1);
2993 CHECK_ASSULT(net_nfc_deinitialize () == NET_NFC_OK);
2995 PRINT_INSTRUCT("Please close a tag to device!! in 10 sec");
2998 for (idx = 10 ;idx > 0 ; idx --)
3000 PRINT_INSTRUCT("count down [%d]", idx);
3003 if (!test_case_result) return test_case_result;
3005 PRINT_INSTRUCT("Please remove the tag from device!!");
3008 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
3009 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_cb3, NULL));
3010 net_nfc_state_activate (1);
3012 PRINT_INSTRUCT("Please close a tag to device!!");
3014 pthread_cond_wait (&pcond,&plock );
3015 if (!test_case_result) return test_case_result;
3017 return NET_NFC_TEST_OK;
3020 /*=================================================================================*/
3023 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)
3025 PRINT_INFO ("Message is received 3 %d", result);
3026 test_case_result = NET_NFC_TEST_OK;
3030 case NET_NFC_MESSAGE_TAG_DISCOVERED:
3032 switch (*(int*) user_param)
3034 case 0: // transceive
3036 net_nfc_target_type_e type;
3037 net_nfc_target_handle_h id;
3039 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3040 net_nfc_error_e e_ret ;
3042 net_nfc_get_tag_type (target_info, &type);
3043 net_nfc_get_tag_handle (target_info, &id);
3044 net_nfc_get_tag_ndef_support (target_info, &is_ndef);
3045 PRINT_INFO("target type: %d\n", type);
3046 PRINT_INFO("target id: %X\n", id);
3047 PRINT_INFO("Is NDEF supoort: %d\n", is_ndef);
3049 net_nfc_deinitialize (); // Before calling transceive
3055 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3056 net_nfc_target_handle_h id;
3057 net_nfc_get_tag_handle (target_info, &id);
3058 net_nfc_deinitialize();
3059 if (NET_NFC_OK == net_nfc_read_tag (id ,NULL)){
3060 test_case_result = NET_NFC_TEST_FAIL;
3066 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3067 net_nfc_target_handle_h id;
3068 ndef_message_h message = NULL;
3069 ndef_record_h record = NULL;
3071 net_nfc_get_tag_handle (target_info, &id);
3072 net_nfc_deinitialize();
3074 net_nfc_create_ndef_message (&message);
3075 net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
3076 net_nfc_append_record_to_ndef_message (message ,record);
3077 if (NET_NFC_OK == net_nfc_write_ndef (id ,message ,NULL)){
3078 test_case_result = NET_NFC_TEST_FAIL;
3085 net_nfc_target_info_h target_info = (net_nfc_target_info_h)data;
3086 net_nfc_target_handle_h id;
3088 char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
3089 net_nfc_create_data (&key, data, 6);
3090 net_nfc_get_tag_handle (target_info, &id);
3091 net_nfc_deinitialize();
3092 if (NET_NFC_OK == net_nfc_format_ndef(id, key, NULL)){
3093 test_case_result = NET_NFC_TEST_FAIL;
3099 pthread_mutex_lock (&plock);
3100 pthread_cond_signal (&pcond);
3101 pthread_mutex_unlock (&plock);
3108 int nfcTestAPIException_tagAPI (uint8_t testNumber,void* arg_ptr)
3112 /* Call API before initailize */
3115 char data [] = {0xff,0xff,0xff,0xff,0xff,0xff};
3116 net_nfc_create_data (&key, data, 6);
3117 CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, key, NULL));
3118 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_format_ndef(NULL, key, NULL));
3119 CHECK_ASSULT (NET_NFC_OK != net_nfc_format_ndef((net_nfc_target_handle_h) 0x302023, NULL, NULL));
3121 CHECK_ASSULT (NET_NFC_OK != net_nfc_read_tag ((net_nfc_target_handle_h) 0x302023 ,NULL));
3122 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_read_tag (NULL ,NULL));
3124 ndef_message_h message = NULL;
3125 ndef_record_h record = NULL;
3126 net_nfc_create_ndef_message (&message);
3127 net_nfc_create_text_type_record (&record, "abc" ,"en-US" ,NET_NFC_ENCODE_UTF_8);
3128 net_nfc_append_record_to_ndef_message (message ,record);
3129 CHECK_ASSULT (NET_NFC_OK != net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,message,NULL));
3130 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef (NULL ,message,NULL));
3131 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_write_ndef ((net_nfc_target_handle_h)0x302023 ,NULL,NULL));
3132 net_nfc_free_ndef_message (message);
3135 for (test_case = 0 ; test_case < 4; test_case++){
3136 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
3137 net_nfc_state_activate (1);
3138 PRINT_INSTRUCT("Please close a tag to device!!");
3139 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_tagAPI, &test_case));
3140 pthread_cond_wait (&pcond,&plock );
3141 if (test_case_result == NET_NFC_TEST_FAIL) return test_case_result;
3142 PRINT_INSTRUCT("Please remoe the tag from device!!");
3146 CHECK_ASSULT(net_nfc_deinitialize () != NET_NFC_OK);
3148 return NET_NFC_TEST_OK;
3150 /*=================================================================================*/
3153 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)
3155 PRINT_INFO ("Message is received 3 %d", result);
3156 test_case_result = NET_NFC_TEST_OK;
3164 case NET_NFC_MESSAGE_TAG_DISCOVERED:
3167 if (NET_NFC_OK != net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
3168 test_case_result = NET_NFC_TEST_FAIL;
3172 if (NET_NFC_OK == net_nfc_get_tag_info_value ((net_nfc_target_info_h)data, "abc", &value)){
3173 test_case_result = NET_NFC_TEST_FAIL;
3176 PRINT_INSTRUCT("Please remove the tag from device!!");
3180 case NET_NFC_MESSAGE_TAG_DETACHED:
3182 if (NET_NFC_OK == net_nfc_get_tag_info_keys((net_nfc_target_info_h)data, &keys, &length)){
3183 test_case_result = NET_NFC_TEST_FAIL;
3187 pthread_mutex_lock (&plock);
3188 pthread_cond_signal (&pcond);
3189 pthread_mutex_unlock (&plock);
3196 int nfcTestAPIException_targetInfo (uint8_t testNumber,void* arg_ptr)
3198 net_nfc_target_type_e target_type;
3199 net_nfc_target_handle_h target_id;
3202 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type ((net_nfc_target_info_h)0x302023, NULL));
3203 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_type (NULL, &target_type));
3205 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle((net_nfc_target_info_h)0x302023, NULL));
3206 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_handle(NULL, &target_id));
3208 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support ((net_nfc_target_info_h)0x302023, NULL));
3209 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_ndef_support (NULL, &is_support));
3211 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size ((net_nfc_target_info_h)0x302023, NULL));
3212 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_max_data_size (NULL, &size));
3214 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size ((net_nfc_target_info_h)0x302023, NULL));
3215 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_actual_data_size (NULL, &size));
3219 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, NULL, &length));
3220 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys((net_nfc_target_info_h)0x302023, &keys, NULL));
3221 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_keys(NULL, &keys, &length));
3223 const char* key = "hello";
3226 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, key , NULL));
3227 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value((net_nfc_target_info_h)0x302023, NULL, &value));
3228 CHECK_ASSULT (NET_NFC_NULL_PARAMETER == net_nfc_get_tag_info_value(NULL, key, &value));
3230 CHECK_ASSULT(net_nfc_initialize() == NET_NFC_OK);
3231 net_nfc_state_activate (1);
3232 CHECK_ASSULT (NET_NFC_OK == net_nfc_set_response_callback (net_nfc_test_API_exception_targetInfo, NULL));
3233 PRINT_INSTRUCT("Please close a tag to device!!");
3235 pthread_cond_wait (&pcond,&plock );
3237 CHECK_ASSULT(net_nfc_deinitialize() == NET_NFC_OK);
3238 return NET_NFC_TEST_OK;
3241 /*=================================================================================*/
3244 int nfcConnHandoverMessageTest (uint8_t testNumber,void* arg_ptr)
3246 net_nfc_carrier_config_h carrier;
3247 net_nfc_property_group_h group;
3248 ndef_record_h carrier_record;
3249 ndef_message_h message;
3250 uint8_t buffer[256] = {0,};
3253 net_nfc_error_e result;
3254 char SSID[] = "HomeWLAN";
3255 char dev_name[] = "DeviceName";
3256 uint8_t btdev_addr[] = {0x01, 0x07, 0x80, 0x80, 0xBF, 0xA1};
3258 result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS);
3259 CHECK_RESULT(result);
3262 result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION, 1, buffer);
3263 CHECK_RESULT(result);
3264 result = net_nfc_create_carrier_config_group (&group, NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL);
3265 CHECK_RESULT(result);
3268 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_INDEX, 1, buffer);
3269 CHECK_RESULT(result);
3271 length = sprintf (buffer, "%s", SSID);
3272 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_SSID, length, buffer);
3273 CHECK_RESULT(result);
3275 *((uint16_t*) buffer ) = 0x20;
3276 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE, 2, buffer);
3277 CHECK_RESULT(result);
3279 *((uint16_t*) buffer ) = 0x0008;
3280 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE, 2, buffer);
3281 CHECK_RESULT(result);
3283 length = sprintf (buffer, "MyPreSharedKey");
3284 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_NET_KEY, length, buffer);
3285 CHECK_RESULT(result);
3293 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR, 6, buffer);
3294 CHECK_RESULT(result);
3297 *((uint16_t*) buffer ) = 0x0001;
3298 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_CHANNEL, 2, buffer);
3299 CHECK_RESULT(result);
3304 result = net_nfc_add_carrier_config_group_property (group, NET_NFC_WIFI_ATTRIBUTE_VEN_EXT, 3, buffer);
3305 CHECK_RESULT(result);
3307 result = net_nfc_append_carrier_config_group (carrier, group);
3308 CHECK_RESULT(result);
3311 result = net_nfc_add_carrier_config_property (carrier, NET_NFC_WIFI_ATTRIBUTE_VERSION2, 1, buffer);
3312 CHECK_RESULT(result);
3314 result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
3315 CHECK_RESULT(result);
3317 result = net_nfc_free_carrier_config (carrier); /* this free all data include group */
3318 CHECK_RESULT(result);
3320 result = net_nfc_create_handover_request_message (&message);
3321 CHECK_RESULT(result);
3323 //net_nfc_ndef_print_message (message);
3325 result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE);
3326 CHECK_RESULT(result);
3328 //net_nfc_ndef_print_message (message);
3332 result = net_nfc_create_carrier_config (&carrier ,NET_NFC_CONN_HANDOVER_CARRIER_BT);
3333 CHECK_RESULT(result);
3335 buffer[0] = btdev_addr[0];
3336 buffer[1] = btdev_addr[1];
3337 buffer[2] = btdev_addr[2];
3338 buffer[3] = btdev_addr[3];
3339 buffer[4] = btdev_addr[4];
3340 buffer[5] = btdev_addr[5];
3341 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS ,6 ,buffer);
3342 CHECK_RESULT(result);
3347 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_COD ,3 ,buffer);
3348 CHECK_RESULT(result);
3351 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_C ,16 ,buffer);
3352 CHECK_RESULT(result);
3354 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_OOB_HASH_R ,16 ,buffer);
3355 CHECK_RESULT(result);
3361 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_UUID16 ,4 ,buffer);
3362 CHECK_RESULT(result);
3364 length = sprintf (buffer, "%s", dev_name);
3365 result = net_nfc_add_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME ,length ,buffer);
3366 CHECK_RESULT(result);
3368 result = net_nfc_create_ndef_record_with_carrier_config (&carrier_record ,carrier);
3369 CHECK_RESULT(result);
3371 result = net_nfc_append_carrier_config_record (message, carrier_record, NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATING);
3372 CHECK_RESULT(result);
3374 //net_nfc_ndef_print_message (message);
3376 result = net_nfc_free_carrier_config (carrier);
3377 CHECK_RESULT(result);
3379 result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
3380 CHECK_RESULT(result);
3382 result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
3383 CHECK_RESULT(result);
3385 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_WIFI_ATTRIBUTE_VERSION , &length, &pdata);
3386 CHECK_RESULT(result);
3387 if (pdata[0] != 0x10){
3388 PRINT_RESULT_FAIL("FILE:%s, LINE:%d, value %d",__FILE__,__LINE__, pdata[0]);
3389 return NET_NFC_TEST_FAIL;
3392 result = net_nfc_get_carrier_config_group (carrier ,0 , &group);
3393 CHECK_RESULT(result);
3395 result = net_nfc_get_carrier_config_group_property (group ,NET_NFC_WIFI_ATTRIBUTE_SSID, &length, &pdata);
3396 CHECK_RESULT(result);
3397 if (memcmp (pdata, SSID, length) != 0){
3398 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3399 return NET_NFC_TEST_FAIL;
3402 result = net_nfc_remove_carrier_config_group_property (group,NET_NFC_WIFI_ATTRIBUTE_VEN_EXT);
3403 CHECK_RESULT(result);
3405 result = net_nfc_get_carrier_config_record (message,1 ,&carrier_record);
3406 CHECK_RESULT(result);
3408 result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
3409 CHECK_RESULT(result);
3411 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata);
3412 CHECK_RESULT(result);
3413 if (memcmp (pdata, btdev_addr, length) != 0) {
3414 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3415 return NET_NFC_TEST_FAIL;
3418 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata);
3419 CHECK_RESULT(result);
3420 if (memcmp (pdata, dev_name, length) != 0){
3421 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3422 return NET_NFC_TEST_FAIL;
3425 result = net_nfc_get_alternative_carrier_record_count (message, &length);
3426 CHECK_RESULT(result);
3429 PRINT_RESULT_FAIL("FILE:%s, LINE:%d, count = %d",__FILE__,__LINE__, length);
3430 return NET_NFC_TEST_FAIL;
3433 net_nfc_conn_handover_carrier_state_e power_state;
3434 result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
3435 CHECK_RESULT(result);
3437 if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE){
3438 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3439 return NET_NFC_TEST_FAIL;
3441 result = net_nfc_set_alternative_carrier_power_status (message,1 ,NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE);
3442 CHECK_RESULT(result);
3444 result = net_nfc_get_alternative_carrier_power_status (message,1 ,&power_state);
3445 CHECK_RESULT(result);
3447 if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
3448 PRINT_RESULT_FAIL("FILE:%s, LINE:%d, status = %d",__FILE__,__LINE__, power_state);
3449 return NET_NFC_TEST_FAIL;
3452 net_nfc_conn_handover_carrier_type_e ctype;
3453 result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
3455 if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS){
3456 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3457 return NET_NFC_TEST_FAIL;
3460 unsigned short r_num;
3461 result = net_nfc_get_handover_random_number (message, &r_num);
3463 result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
3464 CHECK_RESULT(result);
3466 result = net_nfc_remove_carrier_config_record (message, carrier_record);
3467 CHECK_RESULT(result);
3469 result = net_nfc_get_carrier_config_record (message,0 ,&carrier_record);
3470 CHECK_RESULT(result);
3472 result = net_nfc_create_carrier_config_from_config_record (&carrier ,carrier_record);
3473 CHECK_RESULT(result);
3475 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_ADDRESS , &length, &pdata);
3476 CHECK_RESULT(result);
3477 if (memcmp (pdata, btdev_addr, length) != 0) {
3478 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3479 return NET_NFC_TEST_FAIL;
3482 result = net_nfc_get_carrier_config_property (carrier ,NET_NFC_BT_ATTRIBUTE_NAME , &length, &pdata);
3483 CHECK_RESULT(result);
3484 if (memcmp (pdata, dev_name, length) != 0){
3485 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3486 return NET_NFC_TEST_FAIL;
3489 result = net_nfc_get_alternative_carrier_record_count (message, &length);
3490 CHECK_RESULT(result);
3493 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3494 return NET_NFC_TEST_FAIL;
3497 result = net_nfc_get_alternative_carrier_power_status (message,0 ,&power_state);
3498 CHECK_RESULT(result);
3500 if (power_state != NET_NFC_CONN_HANDOVER_CARRIER_INACTIVATE){
3501 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3502 return NET_NFC_TEST_FAIL;
3505 result = net_nfc_get_alternative_carrier_type (message, 0 , &ctype);
3507 if (ctype != NET_NFC_CONN_HANDOVER_CARRIER_BT){
3508 PRINT_RESULT_FAIL("FILE:%s, LINE:%d,",__FILE__,__LINE__);
3509 return NET_NFC_TEST_FAIL;
3512 //net_nfc_ndef_print_message (message);
3514 return NET_NFC_TEST_OK;
3518 /*=================================================================================*/