2 * Copyright (C) 2010 NXP Semiconductors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <sys/types.h>
30 #include "net_nfc_oem_controller.h"
31 #include "net_nfc_typedef.h"
32 #include "nfc_debug_private.h"
34 #include "phDal4Nfc_message_glib.h"
35 #include "phNfcHalTypes.h"
36 #include "phNfcIoctlCode.h"
37 #include "net_nfc_util_private.h"
39 ////////////// DEFINE START /////////////////
41 #ifndef NET_NFC_EXPORT_API
42 #define NET_NFC_EXPORT_API __attribute__((visibility("default")))
45 //#define EEDATA_SETTINGS_NUMBER 24
46 #define EEDATA_SETTINGS_NUMBER 29 // from ginger bread 2.3.4
47 #define NET_NFC_EEPROM_WRITEN "memory/private/nfc-plugin-nxp/eeprom"
48 #define NET_NFC_OEM_CONTROLLER_LOCK \
50 pthread_mutex_lock(&g_controller_lock);\
53 #define NET_NFC_OEM_CONTROLLER_UNLOCK \
55 pthread_mutex_unlock(&g_controller_lock);\
58 #define NET_NFC_OEM_CONTROLLER_SIGNAL(cond) \
60 pthread_mutex_lock(&g_controller_lock);\
61 pthread_cond_signal(cond);\
62 pthread_mutex_unlock(&g_controller_lock);\
65 #define NET_NFC_OEM_CONTROLLER_WAIT(cond) \
69 gettimeofday(&now, NULL);\
70 ts.tv_sec = now.tv_sec + 2;\
71 ts.tv_nsec = now.tv_usec * 1000;\
72 pthread_cond_timedwait(cond, &g_controller_lock, &ts);\
75 typedef struct _socket_info_s
77 net_nfc_llcp_socket_t socket_handle;
79 unsigned int my_index;
82 // net_nfc_llcp_socket_t socket_handle_incomming;
88 typedef struct _ndef_info_s
90 uint8_t ndef_card_state;
95 typedef struct _controller_context_s
97 pthread_cond_t *controller_cond;
100 } controller_context_s;
102 typedef struct _accept_context_s
104 net_nfc_target_handle_s *handle;
105 net_nfc_llcp_socket_t server_scket;
106 net_nfc_llcp_socket_t incomming;
110 typedef struct _transfer_context_s
112 net_nfc_llcp_socket_t oal_socket;
115 } transfer_context_s;
117 ////////////// DEFINE END /////////////////
119 ////////////// STATIC FIELD START ///////////////
121 /* static variable */
123 #define KEYS_ISO14443A_MAX 6
124 #define KEYS_ISO14443B_MAX 7
125 #define KEYS_JEWEL_MAX 3
126 #define KEYS_FELICA_MAX 3
127 #define KEYS_ISO15693_MAX 4
128 #define KEYS_NFCIP_MAX 5
130 #define keys_ISO14443A "UID:APP_DATA:SAK:ATQA:MAX_DATA_RATE:FWI_SFGT:"
131 #define keys_ISO14443B "UID:APP_DATA:PROTOCOL_INFO:ATQ_RESPONSE:HI_LAYER_RESPONSE:AFI:MAX_DATA_RATE:"
132 #define keys_JEWEL "UID:HEADER_ROM0:HEADER_ROM1:"
133 #define keys_FELICA "IDm:PMm:SYSTEM_CODE:"
134 #define keys_ISO15693 "UID:DSF_ID:FLAGS:AFI:"
135 #define keys_NFCIP "UID:ATR_INFORMATION:SAK:ATQA:MAX_DATA_RATE:"
137 #define BUFFER_LENGTH_MAX 1024
139 #define READ_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX
140 #define WRITE_BUFFER_LENGTH_MAX BUFFER_LENGTH_MAX
141 #define NET_NFC_MAX_LLCP_SOCKET_BUFFER BUFFER_LENGTH_MAX
143 #define NET_NFC_MAX_TRANCIEVE_BUFFER 256
145 static phHal_sHwReference_t psHwRef = { 0 };
146 //static phLibNfc_sADD_Cfg_t sADDConfig ;
147 static bool g_stack_init_successful;
148 static pthread_mutex_t g_controller_lock = PTHREAD_MUTEX_INITIALIZER;
149 static bool is_EEPROM_writen = false;
150 extern const uint8_t nxp_nfc_fw[];
152 static net_nfc_target_handle_s *current_working_handle = NULL;
155 static target_detection_listener_cb g_nxp_controller_target_cb;
156 static se_transaction_listener_cb g_nxp_controller_se_cb;
157 static llcp_event_listener_cb g_nxp_controller_llcp_cb;
159 static phLibNfc_SE_List_t g_se_list[PHLIBNFC_MAXNO_OF_SE] = { { 0 } };
160 static uint8_t g_se_no = 0;
163 socket_info_s socket_info_array[PHFRINFC_LLCP_NB_SOCKET_MAX] = { { 0, } };
165 static phNfc_sData_t gInputParam;
166 static phNfc_sData_t gOutputParam;
167 ////////////// STATIC FIELD END ///////////////
169 ////////////// STATIC FUNCTION DECLARE START //////////
171 static bool net_nfc_nxp_controller_init(net_nfc_error_e *result);
172 static bool net_nfc_nxp_controller_deinit(void);
173 static bool net_nfc_nxp_controller_register_listener(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result);
174 static bool net_nfc_nxp_controller_unregister_listener();
175 static bool net_nfc_nxp_controller_get_firmware_version(data_s **data, net_nfc_error_e *result);
176 static bool net_nfc_nxp_controller_check_firmware_version(net_nfc_error_e *result);
177 static bool net_nfc_nxp_controller_update_firmware(net_nfc_error_e *result);
178 static bool net_nfc_nxp_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result);
179 static bool net_nfc_nxp_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result);
180 static bool net_nfc_nxp_controller_get_secure_element_list(net_nfc_secure_element_info_s *list, int *count, net_nfc_error_e *result);
181 static bool net_nfc_nxp_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result);
182 static bool net_nfc_nxp_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
183 static bool net_nfc_nxp_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
184 static bool net_nfc_nxp_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result);
185 static bool net_nfc_nxp_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
186 static bool net_nfc_nxp_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result);
187 static bool net_nfc_nxp_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result);
188 static bool net_nfc_nxp_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
189 static bool net_nfc_nxp_controller_transceive(net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result);
190 static bool net_nfc_nxp_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result);
191 static bool net_nfc_nxp_controller_exception_handler(void);
192 static bool net_nfc_nxp_controller_is_ready(net_nfc_error_e *error);
194 static bool net_nfc_nxp_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e * result);
195 static bool net_nfc_nxp_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
196 static bool net_nfc_nxp_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result);
197 static bool net_nfc_nxp_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, void *user_param);
198 static bool net_nfc_nxp_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result);
199 static bool net_nfc_nxp_controller_llcp_listen(net_nfc_target_handle_s *handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
200 static bool net_nfc_nxp_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
201 static bool net_nfc_nxp_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, void *user_param);
202 static bool net_nfc_nxp_controller_llcp_connect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, void *user_param);
203 static bool net_nfc_nxp_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
204 static bool net_nfc_nxp_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param);
205 static bool net_nfc_nxp_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e *result);
206 static bool net_nfc_nxp_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
207 static bool net_nfc_nxp_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
208 static bool net_nfc_nxp_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param);
209 static bool net_nfc_nxp_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, void *user_param);
210 static bool net_nfc_nxp_controller_llcp_get_remote_config(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result);
211 static bool net_nfc_nxp_controller_llcp_get_remote_socket_info(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result);
213 //static void net_nfc_nxp_controller_print_tag_info(phNfc_uRemoteDevInfo_t *devInfo, phNfc_eRemDevType_t RemDevType);
214 static int net_nfc_nxp_controller_tag_device_info(phNfc_uRemoteDevInfo_t *devInfo, phNfc_eRemDevType_t RemDevType, uint8_t **buffer, uint32_t *buffer_length);
215 static void net_nfc_nxp_controller_device_info_ISO14443A(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length);
216 static void net_nfc_nxp_controller_device_info_ISO14443B(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length);
217 static void net_nfc_nxp_controller_device_info_Jewel(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length);
218 static void net_nfc_nxp_controller_device_info_Felica(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length);
219 static void net_nfc_nxp_controller_device_info_ISO15693(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length);
220 static void net_nfc_nxp_controller_device_info_NFCIP(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length);
222 static bool net_nfc_nxp_controller_sim_test(net_nfc_error_e *result);
223 static bool net_nfc_nxp_controller_prbs_test(net_nfc_error_e *result , uint32_t tech , uint32_t rate);
225 static bool net_nfc_nxp_controller_test_mode_on(net_nfc_error_e *result);
226 static bool net_nfc_nxp_controller_test_mode_off(net_nfc_error_e *result);
228 static bool net_nfc_nxp_controller_support_nfc(net_nfc_error_e *result);
230 /* callback function */
231 static void _net_nfc_init_cb(void *pContext, NFCSTATUS status);
232 static void _net_nfc_deinit_cb(void *pContext, NFCSTATUS status);
234 static void _net_nfc_se_notification_cb(void *pContext, phLibNfc_eSE_EvtType_t EventType, phLibNfc_Handle hSecureElement, phLibNfc_uSeEvtInfo_t *pSeEvtInfo, NFCSTATUS status);
235 static void _net_nfc_remotedev_notification_cb(void *pContext, phLibNfc_RemoteDevList_t *psRemoteDevList, uint8_t uNofRemoteDev, NFCSTATUS status);
236 static void _net_nfc_configure_discovery_cb(void *pContext, NFCSTATUS status);
237 static void _net_nfc_connect_cb(void *pContext, phLibNfc_Handle hRemoteDev, phLibNfc_sRemoteDevInformation_t *psRemoteDevInfo, NFCSTATUS status);
238 static void _net_nfc_disconnect_cb(void *pContext, phLibNfc_Handle hRemoteDev, NFCSTATUS status);
239 static void _net_nfc_transceive_cb(void *pContext, phLibNfc_Handle hRemoteDev, phNfc_sData_t *pResBuffer, NFCSTATUS status);
240 static void _net_nfc_ndef_read_cb(void *pContext, NFCSTATUS tatus);
241 static void _net_nfc_ndef_write_cb(void *pContext, NFCSTATUS status);
242 static void _net_nfc_make_read_only_cb(void *pContext, NFCSTATUS status);
243 static void _net_nfc_format_remote_dev_ndef_cb(void *pContext, NFCSTATUS status);
244 static void _net_nfc_target_check_presence_cb(void *pContext, NFCSTATUS status);
245 static void _net_nfc_target_check_ndef_cb(void *pContext, phLibNfc_ChkNdef_Info_t Ndef_Info, NFCSTATUS status);
246 static void _net_nfc_firmware_cb(void *pContext, phNfc_sData_t *Outparam_Cb, NFCSTATUS status);
248 static void _net_nfc_llcp_recv_from_cb(void *pContext, uint8_t service_access_point, NFCSTATUS status);
249 static void _net_nfc_llcp_recv_cb(void *pContext, NFCSTATUS status);
250 static void _net_nfc_llcp_sendTo_cb(void *pContext, NFCSTATUS status);
251 static void _net_nfc_llcp_send_cb(void *pContext, NFCSTATUS status);
252 static void _net_nfc_llcp_connect_cb(void *pContext, uint8_t nErrCode, NFCSTATUS status);
253 static void _net_nfc_llcp_connect_sap_cb(void *pContext, uint8_t nErrCode, NFCSTATUS status);
254 static void _net_nfc_llcp_accept_cb(void *pContext, NFCSTATUS status);
255 static void _net_nfc_llcp_accepted_socket_err_cb(void *pContext, uint8_t nErrCode);
256 static void _net_nfc_llcp_listen_cb(void *pContext, net_nfc_llcp_socket_t IncomingSocket);
257 static void _net_nfc_llcp_socket_err_cb(void *pContext, uint8_t nErrCode);
258 static void _net_nfc_llcp_link_status_cb(void *pContext, phLibNfc_Llcp_eLinkStatus_t eLinkStatus);
259 static void _net_nfc_llcp_check_llcp_cb(void *pContext, NFCSTATUS status);
260 static void _net_nfc_llcp_disconnect_cb(void *pContext, NFCSTATUS status);
262 static void _net_nfc_test_mode_off_cb(void *pContext, NFCSTATUS status);
263 static void _net_nfc_test_mode_on_cb(void *pContext, NFCSTATUS status);
264 static void _net_nfc_swp_test_cb(void *pContext, phNfc_sData_t *Outparam_Cb, NFCSTATUS status);
266 /* etc static function */
267 static net_nfc_error_e _net_nfc_nxp_error_converter(uint16_t result);
268 static int net_nfc_nxp_controller_convert_target_type(int type, phLibNfc_RemoteDevList_t *TagInfo);
271 static void _net_nfc_nxp_set_mode_default();
272 static void _net_nfc_nxp_set_mode_off();
273 static void _net_nfc_nxp_set_mode_reader();
274 static void _net_nfc_nxp_set_mode_p2p();
275 static void _net_nfc_nxp_set_mode_paymentonly();
277 static bool _net_nfc_nxp_check_pprom_is_completed();
278 static void _net_nfc_nxp_set_pprom_is_completed();
279 static void _net_nfc_nxp_disable_irq_timeout();
280 static void _net_nfc_nxp_controller_lock_init();
282 static socket_info_s *_net_nfc_get_available_socket_slot();
283 static void _net_nfc_remove_socket_slot(net_nfc_llcp_socket_t socket);
284 static void _net_nfc_reset_socket_array();
286 static bool __net_nfc_is_valid_target_handle(net_nfc_target_handle_s *handle);
287 static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s **handle);
288 static void __net_nfc_make_invalid_target_handle();
290 static bool net_nfc_nxp_controller_configure_discovery_stop();
293 ////////////// STATIC FUNCTION DECLARE END //////////
295 static net_nfc_error_e _net_nfc_nxp_error_converter(uint16_t result)
297 net_nfc_error_e retVal = NET_NFC_OK;
298 result = result & 0xFF;
301 case NFCSTATUS_SUCCESS :
304 case NFCSTATUS_INVALID_PARAMETER :
305 DEBUG_MSG("error : NFCSTATUS_INVALID_PARAMETER ");
306 retVal = NET_NFC_NULL_PARAMETER;
308 case NFCSTATUS_BUFFER_TOO_SMALL :
309 DEBUG_MSG("error : NFCSTATUS_BUFFER_TOO_SMALL ");
310 retVal = NET_NFC_BUFFER_TOO_SMALL;
312 case NFCSTATUS_INVALID_DEVICE :
313 DEBUG_MSG("error : NFCSTATUS_INVALID_DEVICE ");
314 retVal = NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED;
316 case NFCSTATUS_RF_TIMEOUT :
317 DEBUG_MSG("error : NFCSTATUS_RF_TIMEOUT ");
318 retVal = NET_NFC_RF_TIMEOUT;
320 case NFCSTATUS_RF_ERROR :
321 DEBUG_MSG("error : NFCSTATUS_RF_ERROR ");
322 retVal = NET_NFC_RF_ERROR;
324 case NFCSTATUS_INSUFFICIENT_RESOURCES :
325 DEBUG_MSG("error : NFCSTATUS_INSUFFICIENT_RESOURCES ");
326 retVal = NET_NFC_ALLOC_FAIL;
328 case NFCSTATUS_BOARD_COMMUNICATION_ERROR :
329 DEBUG_MSG("error : NFCSTATUS_BOARD_COMMUNICATION_ERROR ");
330 retVal = NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED;
332 case NFCSTATUS_INVALID_STATE :
333 DEBUG_MSG("error : NFCSTATUS_INVALID_STATE ");
334 retVal = NET_NFC_INVALID_STATE;
336 case NFCSTATUS_NOT_INITIALISED :
337 DEBUG_MSG("error : NFCSTATUS_NOT_INITIALISED ");
338 retVal = NET_NFC_NOT_INITIALIZED;
340 case NFCSTATUS_ALREADY_INITIALISED :
341 DEBUG_MSG("error : NFCSTATUS_ALREADY_INITIALISED ");
342 retVal = NET_NFC_ALREADY_INITIALIZED;
344 case NFCSTATUS_FEATURE_NOT_SUPPORTED :
345 DEBUG_MSG("error : NFCSTATUS_FEATURE_NOT_SUPPORTED ");
346 retVal = NET_NFC_NOT_SUPPORTED;
348 case NFCSTATUS_NOT_REGISTERED :
349 DEBUG_MSG("error : NFCSTATUS_NOT_REGISTERED ");
350 retVal = NET_NFC_NOT_REGISTERED;
352 case NFCSTATUS_ALREADY_REGISTERED :
353 DEBUG_MSG("error : NFCSTATUS_ALREADY_REGISTERED ");
354 retVal = NET_NFC_ALREADY_REGISTERED;
356 case NFCSTATUS_NOT_ALLOWED :
357 DEBUG_MSG("error : NFCSTATUS_NOT_ALLOWED ");
358 retVal = NET_NFC_NOT_ALLOWED_OPERATION;
360 case NFCSTATUS_BUSY :
361 DEBUG_MSG("error : NFCSTATUS_BUSY ");
362 retVal = NET_NFC_BUSY;
364 case NFCSTATUS_INVALID_REMOTE_DEVICE :
365 DEBUG_MSG("error : NFCSTATUS_INVALID_REMOTE_DEVICE ");
366 retVal = NET_NFC_INVALID_HANDLE;
368 case NFCSTATUS_SMART_TAG_FUNC_NOT_SUPPORTED :
369 DEBUG_MSG("error : NFCSTATUS_SMART_TAG_FUNC_NOT_SUPPORTED ");
370 retVal = NET_NFC_NOT_SUPPORTED;
372 case NFCSTATUS_READ_FAILED :
373 DEBUG_MSG("error : NFCSTATUS_READ_FAILED ");
374 retVal = NET_NFC_TAG_READ_FAILED;
376 case NFCSTATUS_WRITE_FAILED :
377 DEBUG_MSG("error : NFCSTATUS_WRITE_FAILED ");
378 retVal = NET_NFC_TAG_WRITE_FAILED;
380 case NFCSTATUS_NO_NDEF_SUPPORT :
381 DEBUG_MSG("error : NFCSTATUS_NO_NDEF_SUPPORT ");
382 retVal = NET_NFC_NO_NDEF_SUPPORT;
384 case NFCSTATUS_EOF_NDEF_CONTAINER_REACHED :
385 DEBUG_MSG("error : NFCSTATUS_EOF_NDEF_CONTAINER_REACHED ");
386 retVal = NET_NFC_INSUFFICIENT_STORAGE;
388 case NFCSTATUS_INVALID_RECEIVE_LENGTH :
389 DEBUG_MSG("error : NFCSTATUS_INVALID_RECEIVE_LENGTH ");
390 retVal = NET_NFC_OPERATION_FAIL;
392 case NFCSTATUS_INVALID_FORMAT :
393 DEBUG_MSG("error : NFCSTATUS_INVALID_FORMAT ");
394 retVal = NET_NFC_INVALID_FORMAT;
396 case NFCSTATUS_INSUFFICIENT_STORAGE :
397 DEBUG_MSG("error : NFCSTATUS_INSUFFICIENT_STORAGE ");
398 retVal = NET_NFC_INSUFFICIENT_STORAGE;
400 case NFCSTATUS_FORMAT_ERROR :
401 DEBUG_MSG("error : NFCSTATUS_FORMAT_ERROR ");
402 retVal = NET_NFC_INVALID_FORMAT;
404 case NFCSTATUS_TARGET_LOST :
405 DEBUG_MSG("error : TARGET IS MOVED AWAY");
406 retVal = NET_NFC_TARGET_IS_MOVED_AWAY;
408 case NFCSTATUS_FAILED :
409 DEBUG_MSG("error : FATAL ERROR");
410 retVal = NET_NFC_OPERATION_FAIL;
412 case NFCSTATUS_TARGET_NOT_CONNECTED :
413 DEBUG_MSG("error : NFCSTATUS_TARGET_NOT_CONNECTED");
414 retVal = NET_NFC_NOT_CONNECTED;
416 case NFCSTATUS_PENDING :
417 retVal = NET_NFC_BUSY;
419 // Not understanded Error codes
420 case NFCSTATUS_MORE_INFORMATION :
421 case NFCSTATUS_MULTIPLE_PROTOCOLS : // this is not error
422 case NFCSTATUS_MULTIPLE_TAGS :
423 case NFCSTATUS_DESELECTED : // This is event
424 case NFCSTATUS_RELEASED :
426 // Below error codes should not be returned to Client APP
428 DEBUG_MSG("Unkown Error codes is found, %d", result);
429 retVal = NET_NFC_UNKNOWN_ERROR;
436 static int net_nfc_nxp_controller_convert_llcp_error_codes(uint16_t type)
438 net_nfc_error_e retVal;
441 case PHFRINFC_LLCP_ERR_DISCONNECTED :
442 DEBUG_MSG("llcp error code converter : PHFRINET_NFC_LLCP_ERR_DISCONNECTED");
443 retVal = NET_NFC_LLCP_SOCKET_DISCONNECTED;
445 case PHFRINFC_LLCP_ERR_FRAME_REJECTED :
446 DEBUG_MSG("llcp error code converter : PHFRINET_NFC_LLCP_ERR_FRAME_REJECTED");
447 retVal = NET_NFC_LLCP_SOCKET_FRAME_REJECTED;
449 case PHFRINFC_LLCP_ERR_BUSY_CONDITION :
450 case PHFRINFC_LLCP_ERR_NOT_BUSY_CONDITION :
451 DEBUG_MSG("llcp error code converter : BUSY CONDITION");
453 DEBUG_MSG("Unkown Error codes is found, %d", type);
454 retVal = NET_NFC_UNKNOWN_ERROR;
460 static int net_nfc_nxp_controller_convert_target_type(int type, phLibNfc_RemoteDevList_t *TagInfo)
470 case 0x88: // Infineon 1K
473 case 0x28: // 1K emulation
474 case 0x38: // 4K emulation
480 DEBUG_MSG("before convert = [%d]", type);
484 case phNfc_ePICC_DevType :
485 convert = NET_NFC_GENERIC_PICC;
487 case phNfc_eISO14443_A_PICC :
489 if (TagInfo->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak == 0x20)
491 convert = NET_NFC_MIFARE_DESFIRE_PICC;
495 convert = NET_NFC_ISO14443_A_PICC;
500 case phNfc_eISO14443_4A_PICC :
501 convert = NET_NFC_ISO14443_4A_PICC;
503 case phNfc_eISO14443_3A_PICC :
504 convert = NET_NFC_ISO14443_3A_PICC;
506 case phNfc_eMifare_PICC :
508 if (TagInfo->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak == 0x09)
510 convert = NET_NFC_MIFARE_MINI_PICC;
512 else if (TagInfo->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak == 0x08)
514 convert = NET_NFC_MIFARE_1K_PICC;
516 else if (TagInfo->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak == 0x18)
518 convert = NET_NFC_MIFARE_4K_PICC;
520 else if (TagInfo->psRemoteDevInfo->RemoteDevInfo.Iso14443A_Info.Sak == 0x00)
522 convert = NET_NFC_MIFARE_ULTRA_PICC;
527 case phNfc_eISO14443_B_PICC :
528 convert = NET_NFC_ISO14443_B_PICC;
530 case phNfc_eISO14443_4B_PICC :
531 convert = NET_NFC_ISO14443_4B_PICC;
533 case phNfc_eISO14443_BPrime_PICC :
534 convert = NET_NFC_ISO14443_BPRIME_PICC;
536 case phNfc_eFelica_PICC :
537 convert = NET_NFC_FELICA_PICC;
539 case phNfc_eJewel_PICC :
540 convert = NET_NFC_JEWEL_PICC;
542 case phNfc_eISO15693_PICC :
543 convert = NET_NFC_ISO15693_PICC;
545 case phNfc_eNfcIP1_Target :
546 convert = NET_NFC_NFCIP1_TARGET;
548 case phNfc_eNfcIP1_Initiator :
549 convert = NET_NFC_NFCIP1_INITIATOR;
551 case phNfc_eUnknown_DevType :
552 case phNfc_eISO14443_A_PCD :
553 case phNfc_eISO14443_B_PCD :
554 case phNfc_eISO14443_BPrime_PCD :
555 case phNfc_eFelica_PCD :
556 case phNfc_eJewel_PCD :
557 case phNfc_eISO15693_PCD :
558 case phNfc_ePCD_DevType :
559 case phNfc_eInvalid_DevType :
561 convert = NET_NFC_UNKNOWN_TARGET;
565 DEBUG_MSG("after convert = [%d]", convert);
570 static socket_info_s *_net_nfc_get_available_socket_slot()
573 for (; idx < PHFRINFC_LLCP_NB_SOCKET_MAX; idx++)
575 if (socket_info_array[idx].isValid == false)
577 memset(&(socket_info_array[idx]), 0x00, sizeof(socket_info_s));
578 socket_info_array[idx].my_index = idx;
579 socket_info_array[idx].isValid = true;
580 _net_nfc_util_alloc_mem(socket_info_array[idx].data.buffer, NET_NFC_MAX_LLCP_SOCKET_BUFFER);
581 socket_info_array[idx].data.length = NET_NFC_MAX_LLCP_SOCKET_BUFFER;
582 return &(socket_info_array[idx]);
589 static void _net_nfc_remove_socket_slot(net_nfc_llcp_socket_t socket)
593 for (; idx < PHFRINFC_LLCP_NB_SOCKET_MAX; idx++)
595 if (socket_info_array[idx].isValid == true &&
596 socket_info_array[idx].socket_handle == socket)
598 if (socket_info_array[idx].data.buffer != NULL)
600 free(socket_info_array[idx].data.buffer);
601 socket_info_array[idx].data.buffer = NULL;
603 if (socket_info_array[idx].context != NULL)
605 free(socket_info_array[idx].context);
606 socket_info_array[idx].context = NULL;
609 socket_info_array[idx].isValid = false;
610 socket_info_array[idx].socket_handle = 0;
615 static socket_info_s *_net_nfc_find_server_socket(net_nfc_llcp_socket_t socket)
618 for (; idx < PHFRINFC_LLCP_NB_SOCKET_MAX; idx++)
620 if (socket_info_array[idx].socket_handle == socket && socket_info_array[idx].isValid == true)
622 return &(socket_info_array[idx]);
629 static void _net_nfc_reset_socket_array()
633 memset(socket_info_array, 0x00, sizeof(socket_info_array));
635 for (; idx < PHFRINFC_LLCP_NB_SOCKET_MAX; idx++)
637 socket_info_array[idx].isValid = false;
641 void _net_nfc_phLibNfc_Mgt_IoCtl_cb(void *pContext, phNfc_sData_t *pOutParam, NFCSTATUS Status)
643 controller_context_s *context = NULL;
645 if (pContext != NULL)
647 context = (controller_context_s *)pContext;
648 context->result = (int)Status;
651 if (Status != NFCSTATUS_SUCCESS)
653 DEBUG_MSG("IOCTL Error: [0x%x] \n", Status);
658 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
662 ///////////////////////////////////////////////// callback function ////////////////////////////////////////////////////////
664 static void _net_nfc_format_remote_dev_ndef_cb(void *pContext, NFCSTATUS status)
666 controller_context_s *context = NULL;
668 if (pContext != NULL)
670 context = (controller_context_s *)pContext;
671 context->result = (int)status;
674 if (status == NFCSTATUS_SUCCESS)
676 DEBUG_MSG("format is successful");
680 DEBUG_MSG("format is failed = [0x%x]", status);
685 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
689 static void _net_nfc_init_cb(void *pContext, NFCSTATUS status)
691 controller_context_s *context = NULL;
693 if (pContext != NULL)
695 context = (controller_context_s *)pContext;
696 context->result = (int)status;
699 if (status == NFCSTATUS_SUCCESS)
701 DEBUG_MSG("stack initialization is successful");
705 DEBUG_MSG("stack initialization is failed = [0x%x]", status);
710 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
714 static void _net_nfc_deinit_cb(void *pContext, NFCSTATUS status)
716 controller_context_s *context = NULL;
718 if (pContext != NULL)
720 context = (controller_context_s *)pContext;
721 context->result = (int)status;
724 if (status == NFCSTATUS_SUCCESS)
726 DEBUG_MSG("stack deinitialization is successful");
730 DEBUG_MSG("stack deinitialization is failed = [0x%x]", status);
735 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
740 static void _net_nfc_firmware_cb(void *pContext, phNfc_sData_t *Outparam_Cb, NFCSTATUS status)
742 controller_context_s *context = NULL;
744 DEBUG_MSG("_net_nfc_firmware_cb call");
746 if (pContext != NULL)
748 context = (controller_context_s *)pContext;
749 *((int*)context->user_context) = status;
752 if (status == NFCSTATUS_SUCCESS)
754 DEBUG_MSG("FIRMWARE DOWNLOAD SUCCESS");
759 DEBUG_MSG("FIRMWARE DOWNLOAD FAIL [0x%x]\n", status);
764 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
768 static void _net_nfc_configure_discovery_cb(void *pContext, NFCSTATUS status)
770 controller_context_s *context = NULL;
772 if (pContext != NULL)
774 context = (controller_context_s *)pContext;
775 context->result = (int)status;
778 if (status == NFCSTATUS_SUCCESS)
780 DEBUG_MSG("configure discovery is successful");
784 DEBUG_ERR_MSG("configure discovery is fail");
789 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
793 static void _net_nfc_remotedev_notification_cb(void *pContext, phLibNfc_RemoteDevList_t *psRemoteDevList, uint8_t uNofRemoteDev, NFCSTATUS status)
795 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_MULTIPLE_PROTOCOLS)
797 if (status == NFCSTATUS_DESELECTED)
799 DEBUG_MSG("Deselected by Remote Device = [0x%x] ", status);
805 DEBUG_MSG(" Tag dectection error = [0x%x] ", status);
807 if (g_nxp_controller_target_cb != NULL)
809 // Do we need to call check presency ?
810 net_nfc_request_msg_t *req_msg = NULL;
812 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_msg_t));
817 req_msg->length = sizeof(net_nfc_request_msg_t);
818 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_RESTART_POLLING_LOOP;
820 g_nxp_controller_target_cb(req_msg, NULL);
827 switch (psRemoteDevList->psRemoteDevInfo->RemDevType)
829 case phNfc_eInvalid_DevType :
831 DEBUG_MSG(" remote read or invalid type or unknown type ");
839 if (g_nxp_controller_target_cb != NULL)
841 net_nfc_target_handle_s *handle = NULL;
842 uint8_t *buffer = NULL;
843 uint32_t buffer_length = 0, num_of_keys, length, devType;
844 net_nfc_request_target_detected_t *target_detected = NULL;
847 DEBUG_MSG("device is detected count = [0x%x]", uNofRemoteDev);
849 __net_nfc_make_valid_target_handle(&handle);
855 if (status == NFCSTATUS_MULTIPLE_PROTOCOLS)
860 devType = net_nfc_nxp_controller_convert_target_type(psRemoteDevList[index].psRemoteDevInfo->RemDevType, &(psRemoteDevList[index]));
862 num_of_keys = net_nfc_nxp_controller_tag_device_info(&(psRemoteDevList[index].psRemoteDevInfo->RemoteDevInfo), psRemoteDevList[index].psRemoteDevInfo->RemDevType, &buffer, &buffer_length);
864 length = sizeof(net_nfc_request_target_detected_t) + buffer_length;
866 _net_nfc_util_alloc_mem(target_detected, length);
867 if (target_detected == NULL)
871 target_detected->length = length;
872 target_detected->request_type = NET_NFC_MESSAGE_SERVICE_STANDALONE_TARGET_DETECTED;
874 target_detected->handle = handle;
875 handle->connection_id = psRemoteDevList[index].hTargetDev;
877 target_detected->devType = devType;
878 if (target_detected->devType == NET_NFC_NFCIP1_TARGET)
880 DEBUG_MSG("set llcp connection type. remote device is target");
881 handle->connection_type = NET_NFC_P2P_CONNECTION_TARGET;
883 else if (target_detected->devType == NET_NFC_NFCIP1_INITIATOR)
885 DEBUG_MSG("set llcp connection type. remote device is initiator");
886 handle->connection_type = NET_NFC_P2P_CONNECTION_INITIATOR;
890 DEBUG_MSG("set tag connection");
891 handle->connection_type = NET_NFC_TAG_CONNECTION;
894 target_detected->number_of_keys = num_of_keys;
897 target_detected->target_info_values.length = buffer_length;
898 memcpy(&target_detected->target_info_values.buffer, buffer, target_detected->target_info_values.length);
901 DEBUG_MSG("target info = [%d]", psRemoteDevList[index].psRemoteDevInfo->RemDevType);
903 DEBUG_MSG("target info values length = [%d]", target_detected->target_info_values.length);
905 DEBUG_MSG("connection type is = [%d]", handle->connection_type);
907 g_nxp_controller_target_cb(target_detected, NULL);
909 DEBUG_MSG("target detected is end. go to process command");
913 static void _net_nfc_se_mode_cb(void *pContext, phLibNfc_Handle hSecureElement, NFCSTATUS status)
915 controller_context_s *context = NULL;
917 if (pContext != NULL)
919 context = (controller_context_s *)pContext;
920 context->result = (int)status;
923 if (status == NFCSTATUS_SUCCESS)
925 DEBUG_MSG("set SE mode is successful");
929 DEBUG_MSG("set SE mode is fail");
934 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
938 static void _net_nfc_se_notification_cb(void *pContext, phLibNfc_eSE_EvtType_t EventType, phLibNfc_Handle hSecureElement, phLibNfc_uSeEvtInfo_t *pSeEvtInfo, NFCSTATUS status)
940 DEBUG_MSG(" transaction in SE type = [%d] secure handle element = [%d] status = [0x%x]", EventType, hSecureElement, status);
942 if (pSeEvtInfo != NULL)
948 for (; i < pSeEvtInfo->UiccEvtInfo.aid.length; i++)
950 DEBUG_MSG("[0x%x]", pSeEvtInfo->UiccEvtInfo.aid.buffer[i]);
954 if (g_nxp_controller_se_cb != NULL)
956 net_nfc_request_se_event_t *se_event = NULL;
958 _net_nfc_util_alloc_mem(se_event, sizeof(net_nfc_request_se_event_t));
959 if (se_event == NULL)
964 se_event->length = sizeof(net_nfc_request_se_event_t);
966 se_event->aid.length = pSeEvtInfo->UiccEvtInfo.aid.length;
967 if(se_event->aid.length > 0)
969 _net_nfc_util_alloc_mem(se_event->aid.buffer, se_event->aid.length);
970 memcpy(se_event->aid.buffer, pSeEvtInfo->UiccEvtInfo.aid.buffer, se_event->aid.length);
973 se_event->param.length = pSeEvtInfo->UiccEvtInfo.param.length;
974 if(se_event->param.length > 0)
976 _net_nfc_util_alloc_mem(se_event->param.buffer, se_event->param.length);
977 memcpy(se_event->param.buffer, pSeEvtInfo->UiccEvtInfo.param.buffer, se_event->param.length);
982 case phLibNfc_eSE_EvtStartTransaction :
983 se_event->request_type = NET_NFC_MESSAGE_SE_START_TRANSACTION;
986 case phLibNfc_eSE_EvtEndTransaction :
987 se_event->request_type = NET_NFC_MESSAGE_SE_END_TRANSACTION;
990 case phLibNfc_eSE_EvtTypeTransaction :
991 se_event->request_type = NET_NFC_MESSAGE_SE_TYPE_TRANSACTION;
994 case phLibNfc_eSE_EvtConnectivity :
995 se_event->request_type = NET_NFC_MESSAGE_SE_CONNECTIVITY;
998 case phLibNfc_eSE_EvtFieldOn :
999 se_event->request_type = NET_NFC_MESSAGE_SE_FIELD_ON;
1002 case phLibNfc_eSE_EvtFieldOff :
1003 se_event->request_type = NET_NFC_MESSAGE_SE_FIELD_OFF;
1007 se_event->request_type = NET_NFC_MESSAGE_SE_TYPE_TRANSACTION;
1011 g_nxp_controller_se_cb((void *)se_event, NULL);
1016 static void _net_nfc_connect_cb(void *pContext, phLibNfc_Handle hRemoteDev, phLibNfc_sRemoteDevInformation_t *psRemoteDevInfo, NFCSTATUS status)
1018 controller_context_s *context = NULL;
1020 if (pContext != NULL)
1022 context = (controller_context_s *)pContext;
1023 context->result = (int)status;
1026 if (status == NFCSTATUS_SUCCESS)
1028 DEBUG_MSG("connection is successful = [0x%x]", hRemoteDev);
1032 DEBUG_MSG("connection is fail");
1035 if (context != NULL)
1037 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1041 static void _net_nfc_disconnect_cb(void *pContext, phLibNfc_Handle hRemoteDev, NFCSTATUS status)
1043 controller_context_s *context = NULL;
1045 if (pContext != NULL)
1047 context = (controller_context_s *)pContext;
1048 context->result = (int)status;
1051 if (status == NFCSTATUS_SUCCESS)
1053 DEBUG_MSG("disconnection is successful");
1057 DEBUG_MSG("disconnection is fail");
1060 if (context != NULL)
1062 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1066 static void _net_nfc_transceive_cb(void *pContext, phLibNfc_Handle hRemoteDev, phNfc_sData_t *pResBuffer, NFCSTATUS status)
1068 controller_context_s *context = NULL;
1070 context = (controller_context_s *)pContext;
1072 if (pResBuffer != NULL && pResBuffer->length > 0 && pResBuffer->buffer != NULL)
1074 DEBUG_MSG("the received byte length = [%d]", pResBuffer->length);
1076 if (pContext != NULL)
1078 data_s *data = (data_s *)context->user_context;
1082 context->result = (int)status;
1084 _net_nfc_util_alloc_mem(data->buffer, pResBuffer->length);
1085 if ((data)->buffer != NULL)
1087 data->length = pResBuffer->length;
1088 memcpy((data)->buffer, pResBuffer->buffer, pResBuffer->length);
1090 DEBUG_MSG("mem copy");
1094 DEBUG_MSG("_net_nfc_util_alloc_mem fail");
1101 if (pContext != NULL)
1103 context->result = (int)status;
1105 if (status != NFCSTATUS_SUCCESS)
1107 DEBUG_MSG("transceive is failed = [0x%x]", status);
1111 DEBUG_MSG("transceive is success = [0x%x]", status);
1115 if (context != NULL)
1117 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1121 static void _net_nfc_ndef_read_cb(void *pContext, NFCSTATUS status)
1123 controller_context_s *context = NULL;
1125 if (pContext != NULL)
1127 context = (controller_context_s *)pContext;
1128 context->result = (int)status;
1131 if (status == NFCSTATUS_SUCCESS)
1133 DEBUG_MSG("ndef read is successful");
1137 DEBUG_MSG("ndef read is failed = [0x%x]", status);
1140 if (context != NULL)
1142 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1146 static void _net_nfc_ndef_write_cb(void *pContext, NFCSTATUS status)
1148 controller_context_s *context = NULL;
1150 if (pContext != NULL)
1152 context = (controller_context_s *)pContext;
1153 context->result = (int)status;
1156 if (status == NFCSTATUS_SUCCESS)
1158 DEBUG_MSG("write ndef is successful");
1162 DEBUG_MSG("write ndef is failed = [0x%x]", status);
1165 if (context != NULL)
1167 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1171 static void _net_nfc_make_read_only_cb(void *pContext, NFCSTATUS status)
1173 controller_context_s *context = NULL;
1175 if (pContext != NULL)
1177 context = (controller_context_s *)pContext;
1178 context->result = (int)status;
1181 if (status == NFCSTATUS_SUCCESS)
1183 DEBUG_MSG("make read only is successful");
1187 DEBUG_MSG("make read only is failed = [0x%x]", status);
1190 if (context != NULL)
1192 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1196 static void _net_nfc_target_check_presence_cb(void *pContext, NFCSTATUS status)
1198 controller_context_s *context = NULL;
1200 if (pContext != NULL)
1202 context = (controller_context_s *)pContext;
1203 context->result = (int)status;
1206 if (status == NFCSTATUS_SUCCESS)
1208 //DEBUG_MSG("target is present");
1212 DEBUG_MSG("target is moved away = [0x%x]", status);
1215 if (context != NULL)
1217 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1221 static void _net_nfc_target_check_ndef_cb(void *pContext, phLibNfc_ChkNdef_Info_t Ndef_Info, NFCSTATUS status)
1223 controller_context_s *context = (controller_context_s *)pContext;
1225 if (context != NULL)
1227 ndef_info_s *ndef_info = (ndef_info_s *)context->user_context;
1228 context->result = (int)status;
1230 if (status == NFCSTATUS_SUCCESS)
1232 ndef_info->ndef_card_state = Ndef_Info.NdefCardState;
1233 ndef_info->max_data_size = Ndef_Info.MaxNdefMsgLength;
1234 ndef_info->real_data_size = Ndef_Info.ActualNdefMsgLength;
1236 DEBUG_MSG("target has ndef message : Real data [%d]", Ndef_Info.ActualNdefMsgLength);
1240 ndef_info->ndef_card_state = 0;
1241 ndef_info->max_data_size = -1;
1242 ndef_info->real_data_size = -1;
1244 DEBUG_MSG("target does not has ndef message = [0x%x]", status);
1248 if (context != NULL)
1250 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
1254 ////////////////////////////////////////////////////////////////////
1257 static void _net_nfc_nxp_set_mode_default()
1259 DEBUG_MSG("Set Config Default");
1261 // NFCIP will be detected by exernal reader
1262 // we will be able to detect and read TAG
1264 sADDConfig.PollDevInfo.PollEnabled = TRUE;
1266 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443A = TRUE;
1267 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443B = TRUE;
1268 sADDConfig.PollDevInfo.PollCfgInfo.EnableFelica212 = TRUE;
1269 sADDConfig.PollDevInfo.PollCfgInfo.EnableNfcActive = TRUE;
1270 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso15693 = TRUE;
1272 sADDConfig.PollDevInfo.PollCfgInfo.DisableCardEmulation = FALSE;
1274 sADDConfig.NfcIP_Mode = phNfc_eP2P_ALL;
1275 sADDConfig.NfcIP_Tgt_Disable = FALSE;
1277 sADDConfig.Duration = 0xF4240 / 2; // Card Emulation 1
1280 static void _net_nfc_nxp_set_mode_off()
1282 DEBUG_MSG("Set Config OFF");
1283 sADDConfig.PollDevInfo.PollEnabled = FALSE;
1285 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443A = FALSE;
1286 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443B = FALSE;
1287 sADDConfig.PollDevInfo.PollCfgInfo.EnableFelica212 = FALSE;
1288 sADDConfig.PollDevInfo.PollCfgInfo.EnableNfcActive = FALSE;
1289 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso15693 = FALSE;
1290 sADDConfig.PollDevInfo.PollCfgInfo.DisableCardEmulation = TRUE;
1292 sADDConfig.NfcIP_Mode = phNfc_eDefaultP2PMode;
1293 sADDConfig.NfcIP_Tgt_Disable = TRUE;
1294 sADDConfig.Duration = 0xF4240 / 2; // Card Emulation 1
1298 static void _net_nfc_nxp_set_mode_reader()
1300 DEBUG_MSG("Set Config Reader");
1301 sADDConfig.PollDevInfo.PollEnabled = FALSE;
1303 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443A = TRUE;
1304 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443B = TRUE;
1305 sADDConfig.PollDevInfo.PollCfgInfo.EnableFelica212 = TRUE;
1306 sADDConfig.PollDevInfo.PollCfgInfo.EnableNfcActive = FALSE;
1307 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso15693 = TRUE;
1309 sADDConfig.PollDevInfo.PollCfgInfo.DisableCardEmulation = TRUE;
1311 sADDConfig.NfcIP_Mode = phNfc_eDefaultP2PMode;
1312 sADDConfig.NfcIP_Tgt_Disable = FALSE;
1313 sADDConfig.Duration = 0xF4240 / 2; // Card Emulation 1
1317 static void _net_nfc_nxp_set_mode_p2p()
1319 DEBUG_MSG("Set Config P2P");
1321 sADDConfig.PollDevInfo.PollEnabled = TRUE;
1323 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443A = FALSE;
1324 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443B = FALSE;
1325 sADDConfig.PollDevInfo.PollCfgInfo.EnableFelica212 = FALSE;
1326 sADDConfig.PollDevInfo.PollCfgInfo.EnableNfcActive = TRUE;
1327 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso15693 = FALSE;
1329 // is it right to change card emulation to TRUE ??? // check it
1330 sADDConfig.PollDevInfo.PollCfgInfo.DisableCardEmulation = FALSE;
1332 sADDConfig.NfcIP_Mode = phNfc_eP2P_ALL;
1333 sADDConfig.NfcIP_Tgt_Disable = FALSE;
1335 sADDConfig.Duration = 0xF4240 / 2; // Card Emulation 1
1339 static void _net_nfc_nxp_set_mode_paymentonly()
1341 DEBUG_MSG("Set Config card emulation");
1343 sADDConfig.PollDevInfo.PollEnabled = FALSE;
1345 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443A = FALSE;
1346 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso14443B = FALSE;
1347 sADDConfig.PollDevInfo.PollCfgInfo.EnableFelica212 = FALSE;
1348 sADDConfig.PollDevInfo.PollCfgInfo.EnableNfcActive = TRUE;
1349 sADDConfig.PollDevInfo.PollCfgInfo.EnableIso15693 = FALSE;
1350 sADDConfig.PollDevInfo.PollCfgInfo.DisableCardEmulation = FALSE;
1352 sADDConfig.NfcIP_Mode = phNfc_eDefaultP2PMode;
1353 sADDConfig.NfcIP_Tgt_Disable = TRUE;
1354 sADDConfig.Duration = 0xF4240 / 2; // Card Emulation 1
1359 static bool _net_nfc_nxp_check_pprom_is_completed()
1361 int vconf_val = false;
1363 if (is_EEPROM_writen)
1366 if (vconf_get_bool(NET_NFC_EEPROM_WRITEN, &vconf_val) != 0)
1371 if (vconf_val == true)
1377 static void _net_nfc_nxp_set_pprom_is_completed()
1379 vconf_set_bool(NET_NFC_EEPROM_WRITEN, true);
1380 is_EEPROM_writen = true;
1383 static bool _net_nfc_dal_config()
1385 phLibNfc_sConfig_t Config;
1388 NET_NFC_OEM_CONTROLLER_LOCK;
1390 if ((nClientID = InitMessageQueue()) == 0)
1392 NET_NFC_OEM_CONTROLLER_UNLOCK;
1393 DEBUG_MSG("failed to init message Q");
1394 return NFCSTATUS_INSUFFICIENT_RESOURCES;
1397 Config.nClientId = nClientID;
1399 if (phLibNfc_Mgt_ConfigureDriver(&Config, &psHwRef.p_board_driver) == NFCSTATUS_SUCCESS)
1401 NET_NFC_OEM_CONTROLLER_UNLOCK;
1402 DEBUG_MSG("_net_nfc_dal_config success");
1407 NET_NFC_OEM_CONTROLLER_UNLOCK;
1408 DEBUG_MSG("failed to configure driver");
1413 static void _net_nfc_nxp_disable_irq_timeout()
1417 phNfc_sData_t outData;
1418 phNfc_sData_t inData;
1420 uint8_t outBuffer[16];
1421 uint8_t inBuffer[4];
1424 inData.buffer = inBuffer;
1427 outData.buffer = outBuffer;
1428 outData.length = 16;
1430 if (_net_nfc_nxp_check_pprom_is_completed())
1432 DEBUG_MSG("eeprom is already writed");
1437 uint8_t EEDATA_Settings[EEDATA_SETTINGS_NUMBER][4] = {
1439 {0x00,0x9B,0xD1,0x0D} // Tx consumption higher than 0x0D (average 50mA)
1440 ,{0x00,0x9B,0xD2,0x24} // GSP setting for this threshold
1441 ,{0x00,0x9B,0xD3,0x0A} // Tx consumption higher than 0x0A (average 40mA)
1442 ,{0x00,0x9B,0xD4,0x22} // GSP setting for this threshold
1443 ,{0x00,0x9B,0xD5,0x08} // Tx consumption higher than 0x08 (average 30mA)
1444 ,{0x00,0x9B,0xD6,0x1E} // GSP setting for this threshold
1445 ,{0x00,0x9B,0xDD,0x1C} // GSP setting for this threshold
1446 ,{0x00,0x9B,0x84,0x13} // ANACM2 setting
1447 ,{0x00,0x99,0x81,0x7F} // ANAVMID setting PCD
1448 ,{0x00,0x99,0x31,0x70} // ANAVMID setting PICC
1451 ,{0x00,0x98,0x00,0x3F} // SECURE_ELEMENT_CONFIGURATION -Enable SE
1452 ,{0x00,0x9F,0x09,0x00} // SWP_PBTF_RFU
1453 ,{0x00,0x9F,0x0A,0x05} // SWP_PBTF_RFLD --> RFLEVEL Detector for PBTF
1454 ,{0x00,0x9E,0xD1,0xA1} //
1456 // Change RF Level Detector ANARFLDWU
1457 ,{0x00,0x99,0x23,0x00} // Default Value is 0x01
1459 // Polling Loop Optimisation Detection - 0x86 to enable - 0x00 to disable
1460 ,{0x00,0x9E,0x74,0x00} // Default Value is 0x00, bits 0->2: sensitivity (0==maximal, 6==minimal), bits 3->6: RFU, bit 7: (0 -> disabled, 1 -> enabled)
1462 // Polling Loop - Card Emulation Timeout
1463 ,{0x00,0x9F,0x35,0x14} // Time for which PN544 stays in Card Emulation mode after leaving RF field
1464 ,{0x00,0x9F,0x36,0x60} // Default value 0x0411 = 50 ms ---> New Value : 0x1460 = 250 ms
1467 ,{0x00,0x9C,0x31,0x00} //
1468 ,{0x00,0x9C,0x32,0x00} //
1469 ,{0x00,0x9C,0x0C,0x00} //
1470 ,{0x00,0x9C,0x0D,0x00} //
1471 ,{0x00,0x9C,0x12,0x00} //
1472 ,{0x00,0x9C,0x13,0x00} //
1476 // from ginger bread 2.3.4
1477 uint8_t EEDATA_Settings[EEDATA_SETTINGS_NUMBER][4] = {
1478 // DIFFERENTIAL_ANTENNA
1481 {0x00,0x9B,0xD1,0x0D} // Tx consumption higher than 0x0D (average 50mA)
1482 ,{0x00,0x9B,0xD2,0x24} // GSP setting for this threshold
1483 ,{0x00,0x9B,0xD3,0x0A} // Tx consumption higher than 0x0A (average 40mA)
1484 ,{0x00,0x9B,0xD4,0x22} // GSP setting for this threshold
1485 ,{0x00,0x9B,0xD5,0x08} // Tx consumption higher than 0x08 (average 30mA)
1486 ,{0x00,0x9B,0xD6,0x1E} // GSP setting for this threshold
1487 ,{0x00,0x9B,0xDD,0x1C} // GSP setting for this threshold
1488 ,{0x00,0x9B,0x84,0x13} // ANACM2 setting
1489 ,{0x00,0x99,0x81,0x7F} // ANAVMID setting PCD
1490 ,{0x00,0x99,0x31,0x70} // ANAVMID setting PICC
1493 ,{0x00,0x98,0x00,0x3F} // SECURE_ELEMENT_CONFIGURATION - No Secure Element
1494 ,{0x00,0x9F,0x09,0x00} // SWP_PBTF_RFU
1495 ,{0x00,0x9F,0x0A,0x05} // SWP_PBTF_RFLD --> RFLEVEL Detector for PBTF
1496 ,{0x00,0x9E,0xD1,0xA1} //
1498 // Change RF Level Detector ANARFLDWU
1499 ,{0x00,0x99,0x23,0x00} // Default Value is 0x01
1501 // Polling Loop Optimisation Detection - 0x86 to enable - 0x00 to disable
1503 ,{0x00,0x9E,0x74,0x00} // Default Value is 0x00, bits 0->2: sensitivity (0==maximal, 6==minimal), bits 3->6: RFU, bit 7: (0 -> disabled, 1 -> enabled)
1505 // Polling Loop - Card Emulation Timeout
1506 ,{0x00,0x9F,0x35,0x14} // Time for which PN544 stays in Card Emulation mode after leaving RF field
1507 ,{0x00,0x9F,0x36,0x60} // Default value 0x0411 = 50 ms ---> New Value : 0x1460 = 250 ms
1510 ,{0x00,0x9C,0x31,0x00} //
1511 ,{0x00,0x9C,0x32,0x00} //
1512 ,{0x00,0x9C,0x0C,0x00} //
1513 ,{0x00,0x9C,0x0D,0x00} //
1514 ,{0x00,0x9C,0x12,0x00} //
1515 ,{0x00,0x9C,0x13,0x00} //
1517 //WTX for LLCP communication
1518 ,{0x00,0x98,0xA2,0x09} // Max value: 14 (default value: 09)
1520 //Murata Resonator setting
1521 ,{0x00,0x9C,0x5C,0x06} // default 0x0140 = 1ms
1522 ,{0x00,0x9C,0x5D,0x81} // 0x0681(= 5ms) is recommended value by Murata
1523 ,{0x00,0x9F,0x19,0x60} // nxp test 3sec
1524 ,{0x00,0x9F,0x1A,0x00} // nxp test 3sec
1525 //,{0x00,0x9F,0x19,0x82} // nxp test 1.6sec
1526 //,{0x00,0x9F,0x1A,0x35} // nxp test 1.6sec
1529 DEBUG_MSG("writing eeprom");
1531 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
1532 controller_context_s context = { &controller_cond, NULL, 0 };
1534 DEBUG_MSG("writing eeprom");
1536 for (idx = 0; idx < EEDATA_SETTINGS_NUMBER; idx++)
1538 memcpy(inData.buffer, EEDATA_Settings[idx], inData.length);
1540 NET_NFC_OEM_CONTROLLER_LOCK;
1541 ret = phLibNfc_Mgt_IoCtl(psHwRef.p_board_driver, NFC_MEM_WRITE, &inData, &outData, _net_nfc_phLibNfc_Mgt_IoCtl_cb, (void *)&context);
1542 if (ret != NFCSTATUS_PENDING)
1544 NET_NFC_OEM_CONTROLLER_UNLOCK;
1545 DEBUG_MSG("phLibNfc_Mgt_IoCtl returned [%d] _net_nfc_disable_irq_timeout is failed\n", ret);
1548 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
1549 NET_NFC_OEM_CONTROLLER_UNLOCK;
1552 DEBUG_MSG("_net_nfc_disable_irq_timeout is completed\n");
1553 _net_nfc_nxp_set_pprom_is_completed();
1556 static void _net_nfc_nxp_controller_lock_init()
1558 pthread_mutexattr_t attr;
1560 pthread_mutexattr_init(&attr);
1561 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
1562 pthread_mutex_init(&g_controller_lock, &attr);
1565 NET_NFC_EXPORT_API bool onload(net_nfc_oem_interface_s *nxp_interfaces)
1567 nxp_interfaces->init = net_nfc_nxp_controller_init;
1568 nxp_interfaces->deinit = net_nfc_nxp_controller_deinit;
1569 nxp_interfaces->register_listener = net_nfc_nxp_controller_register_listener;
1570 nxp_interfaces->unregister_listener = net_nfc_nxp_controller_unregister_listener;
1571 nxp_interfaces->get_firmware_version = net_nfc_nxp_controller_get_firmware_version;
1572 nxp_interfaces->check_firmware_version = net_nfc_nxp_controller_check_firmware_version;
1573 nxp_interfaces->update_firmeware = net_nfc_nxp_controller_update_firmware;
1574 nxp_interfaces->get_stack_information = net_nfc_nxp_controller_get_stack_information;
1575 nxp_interfaces->configure_discovery = net_nfc_nxp_controller_configure_discovery;
1576 nxp_interfaces->get_secure_element_list = net_nfc_nxp_controller_get_secure_element_list;
1577 nxp_interfaces->set_secure_element_mode = net_nfc_nxp_controller_set_secure_element_mode;
1578 nxp_interfaces->connect = net_nfc_nxp_controller_connect;
1579 nxp_interfaces->disconnect = net_nfc_nxp_controller_disconnect;
1580 nxp_interfaces->check_ndef = net_nfc_nxp_controller_check_ndef;
1581 nxp_interfaces->check_presence = net_nfc_nxp_controller_check_target_presence;
1582 nxp_interfaces->read_ndef = net_nfc_nxp_controller_read_ndef;
1583 nxp_interfaces->write_ndef = net_nfc_nxp_controller_write_ndef;
1584 nxp_interfaces->make_read_only_ndef = net_nfc_nxp_controller_make_read_only_ndef;
1585 nxp_interfaces->transceive = net_nfc_nxp_controller_transceive;
1586 nxp_interfaces->format_ndef = net_nfc_nxp_controller_format_ndef;
1587 nxp_interfaces->exception_handler = net_nfc_nxp_controller_exception_handler;
1588 nxp_interfaces->is_ready = net_nfc_nxp_controller_is_ready;
1590 nxp_interfaces->config_llcp = net_nfc_nxp_controller_llcp_config;
1591 nxp_interfaces->check_llcp_status = net_nfc_nxp_controller_llcp_check_llcp;
1592 nxp_interfaces->activate_llcp = net_nfc_nxp_controller_llcp_activate_llcp;
1593 nxp_interfaces->create_llcp_socket = net_nfc_nxp_controller_llcp_create_socket;
1594 nxp_interfaces->bind_llcp_socket = net_nfc_nxp_controller_llcp_bind;
1595 nxp_interfaces->listen_llcp_socket = net_nfc_nxp_controller_llcp_listen;
1596 nxp_interfaces->accept_llcp_socket = net_nfc_nxp_controller_llcp_accept;
1597 nxp_interfaces->connect_llcp_by_url = net_nfc_nxp_controller_llcp_connect_by_url;
1598 nxp_interfaces->connect_llcp = net_nfc_nxp_controller_llcp_connect;
1599 nxp_interfaces->disconnect_llcp = net_nfc_nxp_controller_llcp_disconnect;
1600 nxp_interfaces->close_llcp_socket = net_nfc_nxp_controller_llcp_socket_close;
1601 nxp_interfaces->recv_llcp = net_nfc_nxp_controller_llcp_recv;
1602 nxp_interfaces->send_llcp = net_nfc_nxp_controller_llcp_send;
1603 nxp_interfaces->recv_from_llcp = net_nfc_nxp_controller_llcp_recv_from;
1604 nxp_interfaces->send_to_llcp = net_nfc_nxp_controller_llcp_send_to;
1605 nxp_interfaces->reject_llcp = net_nfc_nxp_controller_llcp_reject;
1606 nxp_interfaces->get_remote_config = net_nfc_nxp_controller_llcp_get_remote_config;
1607 nxp_interfaces->get_remote_socket_info = net_nfc_nxp_controller_llcp_get_remote_socket_info;
1609 nxp_interfaces->sim_test = net_nfc_nxp_controller_sim_test;
1610 nxp_interfaces->prbs_test = net_nfc_nxp_controller_prbs_test;
1612 nxp_interfaces->test_mode_on = net_nfc_nxp_controller_test_mode_on;
1613 nxp_interfaces->test_mode_off = net_nfc_nxp_controller_test_mode_off;
1615 nxp_interfaces->support_nfc = net_nfc_nxp_controller_support_nfc;
1620 static bool net_nfc_nxp_controller_init(net_nfc_error_e *result)
1622 NFCSTATUS status = NFCSTATUS_SUCCESS;
1623 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
1624 controller_context_s context = { &controller_cond, NULL, 0 };
1631 *result = NET_NFC_OK;
1633 _net_nfc_nxp_controller_lock_init();
1635 DEBUG_MSG("Dal config \n");
1636 if (_net_nfc_dal_config() != true)
1638 DEBUG_MSG("Port config is failed");
1642 DEBUG_MSG("start stack init \n");
1644 NET_NFC_OEM_CONTROLLER_LOCK;
1645 if ((status = phLibNfc_Mgt_Initialize(psHwRef.p_board_driver, _net_nfc_init_cb, (void *)&context)) != NFCSTATUS_PENDING)
1647 NET_NFC_OEM_CONTROLLER_UNLOCK;
1648 DEBUG_MSG("stack init is failed = [0x%x] \n", status);
1650 g_stack_init_successful = false;
1656 pthread_cond_wait(&controller_cond, &g_controller_lock);
1657 //NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
1658 NET_NFC_OEM_CONTROLLER_UNLOCK;
1660 DEBUG_MSG("stack initialization is in progress");
1662 if (context.result != NFCSTATUS_SUCCESS)
1664 DEBUG_MSG("stack init is failed = [0x%x] \n", context.result);
1666 if (net_nfc_nxp_controller_update_firmware(result) == false)
1668 DEBUG_MSG("UPDATE FAIL");
1673 DEBUG_MSG("UPDATE SUCCESS");
1674 net_nfc_nxp_controller_init(result);
1675 g_stack_init_successful = true;
1679 g_stack_init_successful = false;
1684 DEBUG_MSG("Success Stack init & Check the Firmware Version!!");
1686 if(net_nfc_nxp_controller_check_firmware_version(result) == TRUE)
1688 DEBUG_MSG("Need to update the firmware");
1690 if(net_nfc_nxp_controller_update_firmware(result) != TRUE)
1692 DEBUG_MSG("Fail to download firmware!!");
1695 else/*Firmware Update Success & Retry init*/
1697 DEBUG_MSG("Firmware UPDATE SUCCESS & Retry init!!");
1699 if (_net_nfc_dal_config() != true)
1701 DEBUG_MSG("Port config is failed");
1705 NET_NFC_OEM_CONTROLLER_LOCK;
1706 if ((status = phLibNfc_Mgt_Initialize(psHwRef.p_board_driver, _net_nfc_init_cb, (void *)&context)) != NFCSTATUS_PENDING)
1708 NET_NFC_OEM_CONTROLLER_UNLOCK;
1709 DEBUG_MSG("stack init is failed = [0x%x] \n", status);
1711 g_stack_init_successful = false;
1717 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
1718 NET_NFC_OEM_CONTROLLER_UNLOCK;
1720 DEBUG_MSG("New stack initialization is success!!");
1722 if (context.result != NFCSTATUS_SUCCESS)
1724 DEBUG_MSG("stack init is failed = [0x%x] \n", context.result);
1726 g_stack_init_successful = false;
1734 g_stack_init_successful = true;
1736 DEBUG_MSG("Stack init finished!!");
1740 static bool net_nfc_nxp_controller_deinit(void)
1742 NFCSTATUS status = NFCSTATUS_SUCCESS;
1743 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
1744 controller_context_s context = { &controller_cond, NULL, 0 };
1746 _net_nfc_nxp_controller_lock_init();
1748 NET_NFC_OEM_CONTROLLER_LOCK;
1749 if ((status = phLibNfc_Mgt_DeInitialize(psHwRef.p_board_driver, _net_nfc_deinit_cb, /*NULL*/(void *)&context)) != NFCSTATUS_PENDING)
1751 NET_NFC_OEM_CONTROLLER_UNLOCK;
1752 DEBUG_MSG("deinit is failed");
1757 pthread_cond_wait(&controller_cond, &g_controller_lock);
1758 NET_NFC_OEM_CONTROLLER_UNLOCK;
1759 DEBUG_MSG("deinit is success");
1762 phLibNfc_Mgt_UnConfigureDriver(psHwRef.p_board_driver);
1763 DEBUG_MSG("unregister driver");
1768 static bool net_nfc_nxp_controller_register_listener(target_detection_listener_cb target_detection_listener, se_transaction_listener_cb se_transaction_listener, llcp_event_listener_cb llcp_event_listener, net_nfc_error_e *result)
1770 phLibNfc_Registry_Info_t reginfo = { 0, };
1771 int user_context = 0;
1772 NFCSTATUS status = NFCSTATUS_SUCCESS;
1779 *result = NET_NFC_OK;
1781 // READER option : the protocol which will be detected by READER.
1783 reginfo.MifareUL = TRUE;
1784 reginfo.MifareStd = TRUE;
1785 reginfo.ISO14443_4A = TRUE;
1786 reginfo.ISO14443_4B = TRUE;
1787 reginfo.Jewel = TRUE;
1789 reginfo.Felica = TRUE;
1790 reginfo.ISO15693 = TRUE;
1792 NET_NFC_OEM_CONTROLLER_LOCK;
1794 if ((status = phLibNfc_RemoteDev_NtfRegister(®info, _net_nfc_remotedev_notification_cb, &user_context)) == NFCSTATUS_SUCCESS)
1796 DEBUG_MSG("register Remote device callback is successful");
1800 DEBUG_MSG("register Remote device callback is failed = [0x%x]", status);
1803 if ((status = phLibNfc_SE_NtfRegister(_net_nfc_se_notification_cb, &user_context)) == NFCSTATUS_SUCCESS)
1805 DEBUG_MSG("register SE callback is successful");
1809 DEBUG_MSG("register SE callback is failed = [0x%x]", status);
1812 g_nxp_controller_target_cb = target_detection_listener;
1813 g_nxp_controller_se_cb = se_transaction_listener;
1814 g_nxp_controller_llcp_cb = llcp_event_listener;
1816 NET_NFC_OEM_CONTROLLER_UNLOCK;
1821 static bool net_nfc_nxp_controller_unregister_listener()
1823 NET_NFC_OEM_CONTROLLER_LOCK;
1825 g_nxp_controller_target_cb = NULL;
1826 g_nxp_controller_se_cb = NULL;
1827 g_nxp_controller_llcp_cb = NULL;
1829 NET_NFC_OEM_CONTROLLER_UNLOCK;
1834 static bool net_nfc_nxp_controller_get_firmware_version(data_s **data, net_nfc_error_e *result)
1836 NFCSTATUS status = NFCSTATUS_SUCCESS;
1837 uint8_t version_info[11];
1843 *result = NET_NFC_OK;
1845 // if ((status = net_nfc_nxp_controller_get_stack_information((net_nfc_stack_information_s *)version_info, result)) == true)
1847 // DEBUG_MSG("version [%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X]", version_info[0], version_info[1], version_info[2], version_info[3], version_info[4], version_info[5], version_info[6], version_info[7], version_info[8], version_info[9], version_info[10]);
1849 _net_nfc_util_alloc_mem(*data, sizeof(data_s));
1851 (*data)->length = 5;
1852 _net_nfc_util_alloc_mem((*data)->buffer, (*data)->length);
1854 snprintf((char *)(*data)->buffer, (*data)->length, "%d.%d", 1, 17);
1860 // DEBUG_ERR_MSG("get_stack_capability failed \n");
1866 static bool net_nfc_nxp_controller_check_firmware_version(net_nfc_error_e *result)
1868 NFCSTATUS status = NFCSTATUS_SUCCESS;
1870 uint8_t version_info[11];/*Already Installed*/
1878 if(nxp_nfc_full_version == NULL)
1880 DEBUG_MSG("=== There are no firmware file");
1884 *result = NET_NFC_OK;
1886 DEBUG_MSG("get stack capability");
1888 if ((status = net_nfc_nxp_controller_get_stack_information((net_nfc_stack_information_s *)version_info, result)) != true)
1890 DEBUG_MSG("get_stack_capability failed \n");
1894 for (i = 0; i < 11; i++)
1896 if (version_info[i] != nxp_nfc_full_version[i])
1898 DEBUG_MSG("version_info[%d] = [%x]\n", i, version_info[i]);
1899 DEBUG_MSG("nxp_nfc_full_version[%d] = [%x]\n", i, nxp_nfc_full_version[i]);
1900 /*Plug-In's firmware version*/
1901 DEBUG_MSG("Need Update");
1904 DEBUG_MSG("[%d]'s hexa is same", i)
1907 DEBUG_MSG("Don't Need Update");
1911 static bool net_nfc_nxp_controller_update_firmware(net_nfc_error_e *result)
1913 phNfc_sData_t InParam;
1914 phNfc_sData_t OutParam;
1915 int user_context = 0xff;
1916 NFCSTATUS status = NFCSTATUS_SUCCESS;
1917 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
1918 controller_context_s context = { &controller_cond, &user_context };
1925 *result = NET_NFC_OK;
1927 net_nfc_nxp_controller_deinit();
1929 if (_net_nfc_dal_config() != true)
1931 DEBUG_MSG("Port config is failed");
1935 _net_nfc_util_alloc_mem(InParam.buffer, 1);
1937 _net_nfc_util_alloc_mem(OutParam.buffer, 1);
1938 OutParam.length = 1;
1940 NET_NFC_OEM_CONTROLLER_LOCK;
1941 phLibNfc_Download_Mode();
1942 NET_NFC_OEM_CONTROLLER_UNLOCK;
1944 NET_NFC_OEM_CONTROLLER_LOCK;
1945 if ((status = phLibNfc_Mgt_IoCtl(psHwRef.p_board_driver, NFC_FW_DOWNLOAD, &InParam, &OutParam, _net_nfc_firmware_cb, (void *)&context)) != NFCSTATUS_PENDING)
1947 DEBUG_MSG("Firmware update ERROR1");
1948 NET_NFC_OEM_CONTROLLER_UNLOCK;
1949 free(InParam.buffer);
1950 free(OutParam.buffer);
1955 DEBUG_MSG("phLibNfc_Mgt_IoCtl NFC_FW_DOWNLOAD status[%d]", status);
1957 pthread_cond_wait(&controller_cond, &g_controller_lock);
1958 //NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
1960 DEBUG_MSG("user_context status[%d]", user_context);
1961 NET_NFC_OEM_CONTROLLER_UNLOCK;
1963 if (user_context != NFCSTATUS_SUCCESS)
1965 DEBUG_MSG("Firmware update ERROR2");
1966 free(InParam.buffer);
1967 free(OutParam.buffer);
1971 DEBUG_MSG("Firmware update SUCCESS");
1973 free(InParam.buffer);
1974 free(OutParam.buffer);
1979 /*static net_nfc_stack_information_s *_net_nfc_nxp_convert_stack_information(phLibNfc_StackCapabilities_t *stack_capa)
1981 net_nfc_stack_information_s *stack_info;
1982 memcpy(stack_info.net_nfc_fw_version , stack_capa.psDevCapabilities.fw_version , sizeof(uint32_t));
1987 static bool net_nfc_nxp_controller_get_stack_information(net_nfc_stack_information_s *stack_info, net_nfc_error_e *result)
1994 DEBUG_MSG("net_nfc_nxp_controller_get_stack_information");
1996 *result = NET_NFC_OK;
1998 int user_context = 0;
1999 NFCSTATUS friReturn;
2001 phLibNfc_StackCapabilities_t stack_capa;
2003 NET_NFC_OEM_CONTROLLER_LOCK;
2004 if((friReturn = phLibNfc_Mgt_GetstackCapabilities (&stack_capa , (void *)&user_context)) != NFCSTATUS_SUCCESS)
2006 NET_NFC_OEM_CONTROLLER_UNLOCK;
2007 DEBUG_MSG("net_nfc_nxp_controller_get_stack_information false");
2010 NET_NFC_OEM_CONTROLLER_UNLOCK;
2012 DEBUG_MSG("net_nfc_nxp_controller_get_stack_information Version = [%x]" , stack_capa.psDevCapabilities.full_version);
2015 // convert stack capa to stack info
2016 //stack_info = _net_nfc_nxp_convert_stack_information(&stack_capa);
2017 memcpy(stack_info ,&stack_capa.psDevCapabilities.full_version , 11*sizeof(uint8_t));
2018 DEBUG_MSG("net_nfc_nxp_controller_get_stack_information true");
2022 static void _net_nfc_nxp_set_add_config(net_nfc_event_filter_e config, phLibNfc_sADD_Cfg_t *ADD_config)
2024 DEBUG_MSG("set polling loop configure = [0x%x]", config);
2026 if (ADD_config == NULL)
2029 if (config & NET_NFC_ISO14443A_ENABLE)
2031 DEBUG_MSG("turn on ISO14443A");
2032 ADD_config->PollDevInfo.PollCfgInfo.EnableIso14443A = TRUE;
2036 DEBUG_MSG("turn off ISO14443A");
2037 ADD_config->PollDevInfo.PollCfgInfo.EnableIso14443A = FALSE;
2040 if (config & NET_NFC_ISO14443B_ENABLE)
2042 DEBUG_MSG("turn on ISO14443B");
2043 ADD_config->PollDevInfo.PollCfgInfo.EnableIso14443B = TRUE;
2047 DEBUG_MSG("turn off ISO14443B");
2048 ADD_config->PollDevInfo.PollCfgInfo.EnableIso14443B = FALSE;
2051 if (config & NET_NFC_FELICA_ENABLE)
2053 DEBUG_MSG("turn on Felica");
2054 ADD_config->PollDevInfo.PollCfgInfo.EnableFelica212 = TRUE;
2055 ADD_config->PollDevInfo.PollCfgInfo.EnableFelica424 = TRUE;
2059 DEBUG_MSG("turn off Felica");
2060 ADD_config->PollDevInfo.PollCfgInfo.EnableFelica212 = FALSE;
2061 ADD_config->PollDevInfo.PollCfgInfo.EnableFelica424 = FALSE;
2064 if (config & NET_NFC_ISO15693_ENABLE)
2066 DEBUG_MSG("turn on ISO15693");
2067 ADD_config->PollDevInfo.PollCfgInfo.EnableIso15693 = TRUE;
2071 DEBUG_MSG("turn off ISO15693");
2072 ADD_config->PollDevInfo.PollCfgInfo.EnableIso15693 = FALSE;
2075 if (config & NET_NFC_IP_ENABLE)
2077 DEBUG_MSG("turn on NFCIP");
2078 ADD_config->PollDevInfo.PollCfgInfo.EnableNfcActive = TRUE;
2079 ADD_config->PollDevInfo.PollCfgInfo.DisableCardEmulation = FALSE;
2080 ADD_config->NfcIP_Mode = phNfc_eP2P_ALL;
2081 ADD_config->NfcIP_Tgt_Disable = FALSE;
2085 DEBUG_MSG("turn off NFCIP");
2086 ADD_config->PollDevInfo.PollCfgInfo.EnableNfcActive = FALSE;
2087 ADD_config->PollDevInfo.PollCfgInfo.DisableCardEmulation = FALSE;
2088 ADD_config->NfcIP_Mode = 0;
2089 ADD_config->NfcIP_Tgt_Disable = TRUE;
2092 ADD_config->Duration = 0xF4240; // Card Emulation 1
2095 static bool net_nfc_nxp_controller_configure_discovery(net_nfc_discovery_mode_e mode, net_nfc_event_filter_e config, net_nfc_error_e *result)
2097 NFCSTATUS friReturn = NFCSTATUS_SUCCESS;
2098 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2099 controller_context_s context = { &controller_cond, NULL, 0 };
2100 phLibNfc_sADD_Cfg_t AddConfig;
2107 *result = NET_NFC_OK;
2109 if (mode == NET_NFC_DISCOVERY_MODE_START || mode == NET_NFC_DISCOVERY_MODE_STOP)
2111 DEBUG_MSG("stop and start is not supported in NXP solution");
2112 *result = NET_NFC_OUT_OF_BOUND;
2116 DEBUG_MSG("run poll loop");
2118 _net_nfc_nxp_set_add_config(config, &AddConfig);
2120 NET_NFC_OEM_CONTROLLER_LOCK;
2122 __net_nfc_make_invalid_target_handle();
2123 friReturn = phLibNfc_Mgt_ConfigureDiscovery(mode, AddConfig, _net_nfc_configure_discovery_cb, (void *)&context);
2124 if (friReturn != NFCSTATUS_PENDING)
2126 NET_NFC_OEM_CONTROLLER_UNLOCK;
2128 DEBUG_MSG("discovering config is error");
2129 *result = _net_nfc_nxp_error_converter(friReturn);
2134 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2135 NET_NFC_OEM_CONTROLLER_UNLOCK;
2137 DEBUG_MSG("discovering config is end");
2139 if (context.result != NFCSTATUS_SUCCESS)
2141 *result = _net_nfc_nxp_error_converter(context.result);
2151 static bool net_nfc_nxp_controller_get_secure_element_list(net_nfc_secure_element_info_s *list, int *count, net_nfc_error_e *result)
2158 *result = NET_NFC_OK;
2160 if (list == NULL || count == NULL)
2162 *result = NET_NFC_NULL_PARAMETER;
2172 for (; i < g_se_no; i++)
2174 _net_nfc_util_alloc_mem(list[i].handle, sizeof(net_nfc_target_handle_s));
2175 if (list[i].handle != NULL)
2177 list[i].handle->connection_id = g_se_list[i].hSecureElement;
2178 list[i].handle->connection_type = NET_NFC_SE_CONNECTION;
2181 list[i].secure_element_type = g_se_list[i].eSE_Type;
2182 list[i].secure_element_state = g_se_list[i].eSE_CurrentState;
2184 if (list[i].secure_element_type == SECURE_ELEMENT_TYPE_ESE)
2186 DEBUG_MSG("ESE is found");
2188 else if (list[i].secure_element_type == SECURE_ELEMENT_TYPE_UICC)
2190 DEBUG_MSG("UICC is found");
2194 DEBUG_MSG("unknown type is found = [%d]", list[i].secure_element_type);
2202 NFCSTATUS status = NFCSTATUS_SUCCESS;
2204 NET_NFC_OEM_CONTROLLER_LOCK;
2206 if ((status = phLibNfc_SE_GetSecureElementList(g_se_list, &g_se_no)) == NFCSTATUS_SUCCESS)
2210 NET_NFC_OEM_CONTROLLER_UNLOCK;
2212 DEBUG_MSG("get secure item info is ok. item counts = [%d]", g_se_no);
2216 for (; i < g_se_no; i++)
2218 _net_nfc_util_alloc_mem(list[i].handle, sizeof(net_nfc_target_handle_s));
2219 if (list[i].handle != NULL)
2221 list[i].handle->connection_id = g_se_list[i].hSecureElement;
2222 list[i].handle->connection_type = NET_NFC_SE_CONNECTION;
2225 if (g_se_list[i].eSE_Type == phLibNfc_SE_Type_SmartMX)
2227 DEBUG_MSG("ESE is found");
2229 else if (g_se_list[i].eSE_Type == phLibNfc_SE_Type_UICC)
2231 DEBUG_MSG("UICC is found");
2235 DEBUG_MSG("unknown type is found = [%d]", g_se_list[i].eSE_Type);
2238 list[i].secure_element_type = g_se_list[i].eSE_Type;
2239 list[i].secure_element_state = g_se_list[i].eSE_CurrentState;
2246 NET_NFC_OEM_CONTROLLER_UNLOCK;
2248 *result = NET_NFC_NO_DATA_FOUND;
2250 DEBUG_MSG("there is no secure item error = [0x%x]", status);
2257 static bool net_nfc_nxp_controller_set_secure_element_mode(net_nfc_secure_element_type_e element_type, net_nfc_secure_element_mode_e mode, net_nfc_error_e *result)
2259 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2260 controller_context_s context = { &controller_cond, NULL, 0 };
2261 NFCSTATUS status = NFCSTATUS_SUCCESS;
2262 phLibNfc_eSE_ActivationMode act_mode = phLibNfc_SE_ActModeOff;
2263 net_nfc_secure_element_info_s info[PHLIBNFC_MAXNO_OF_SE] = { { 0 } };
2265 phLibNfc_Handle secure_element_handle = 0;
2272 *result = NET_NFC_OK;
2274 if (net_nfc_nxp_controller_get_secure_element_list(info, &se_count, result) != true)
2276 DEBUG_MSG("get secure element info is failed");
2282 for (; i < se_count; i++)
2284 if (info[i].secure_element_type == element_type)
2286 if (info[i].handle != NULL)
2288 secure_element_handle = (phLibNfc_Handle)info[i].handle->connection_id;
2289 DEBUG_MSG("SE type is mached, handle = [0x%x]", secure_element_handle);
2294 DEBUG_MSG("handle is not vaild");
2295 *result = NET_NFC_INVALID_HANDLE;
2304 DEBUG_MSG("no matching SE type");
2305 *result = NET_NFC_NO_DATA_FOUND;
2313 case SECURE_ELEMENT_WIRED_MODE :
2314 act_mode = phLibNfc_SE_ActModeWired;
2316 case SECURE_ELEMENT_VIRTUAL_MODE :
2317 act_mode = phLibNfc_SE_ActModeVirtual;
2319 case SECURE_ELEMENT_OFF_MODE :
2320 act_mode = phLibNfc_SE_ActModeOff;
2323 act_mode = phLibNfc_SE_ActModeVirtual;
2327 NET_NFC_OEM_CONTROLLER_LOCK;
2329 status = phLibNfc_SE_SetMode(secure_element_handle, act_mode, _net_nfc_se_mode_cb, (void *)&context);
2331 if (status == NFCSTATUS_PENDING)
2333 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2334 NET_NFC_OEM_CONTROLLER_UNLOCK;
2336 if (context.result != NFCSTATUS_SUCCESS)
2338 DEBUG_MSG("set secure element mode is failed = [0x%x]", context.result);
2342 else if (status == NFCSTATUS_SUCCESS)
2344 NET_NFC_OEM_CONTROLLER_UNLOCK;
2346 if (context.result != NFCSTATUS_SUCCESS)
2348 DEBUG_MSG("set secure element mode is failed = [0x%x]", context.result);
2354 NET_NFC_OEM_CONTROLLER_UNLOCK;
2355 DEBUG_MSG("set SE is failed = [0x%x]", status);
2360 DEBUG_MSG("set secure element mode is good");
2364 static bool net_nfc_nxp_controller_check_target_presence(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
2366 phLibNfc_Handle hTargetDev;
2367 NFCSTATUS friReturn = NFCSTATUS_SUCCESS;
2368 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2369 controller_context_s context = { &controller_cond, NULL, 0 };
2376 *result = NET_NFC_OK;
2380 *result = NET_NFC_NULL_PARAMETER;
2384 hTargetDev = (phLibNfc_Handle)handle->connection_id;
2386 NET_NFC_OEM_CONTROLLER_LOCK;
2387 friReturn = phLibNfc_RemoteDev_CheckPresence(hTargetDev, _net_nfc_target_check_presence_cb, (void *)&context);
2388 if (friReturn == NFCSTATUS_PENDING)
2390 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2391 NET_NFC_OEM_CONTROLLER_UNLOCK;
2393 if (context.result == NFCSTATUS_SUCCESS)
2399 *result = _net_nfc_nxp_error_converter(context.result);
2404 NET_NFC_OEM_CONTROLLER_UNLOCK;
2405 DEBUG_MSG("check presence operation is failed = [0x%x]", friReturn);
2406 *result = _net_nfc_nxp_error_converter(friReturn);
2412 static bool net_nfc_nxp_controller_connect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
2414 phLibNfc_Handle hTargetDev;
2415 NFCSTATUS friReturn;
2416 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2417 controller_context_s context = { &controller_cond, NULL, 0 };
2424 *result = NET_NFC_OK;
2428 *result = NET_NFC_NULL_PARAMETER;
2432 if (!__net_nfc_is_valid_target_handle(handle))
2434 *result = NET_NFC_INVALID_HANDLE;
2438 hTargetDev = (phLibNfc_Handle)handle->connection_id;
2440 NET_NFC_OEM_CONTROLLER_LOCK;
2441 friReturn = phLibNfc_RemoteDev_Connect(hTargetDev, _net_nfc_connect_cb, (void *)&context);
2442 if (friReturn == NFCSTATUS_PENDING)
2444 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2445 NET_NFC_OEM_CONTROLLER_UNLOCK;
2446 if (context.result != NFCSTATUS_SUCCESS)
2448 *result = _net_nfc_nxp_error_converter(context.result);
2455 NET_NFC_OEM_CONTROLLER_UNLOCK;
2456 DEBUG_MSG("connecting to target is failed = [0x%x]", friReturn);
2457 *result = _net_nfc_nxp_error_converter(friReturn);
2464 static bool net_nfc_nxp_controller_disconnect(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
2471 *result = NET_NFC_OK;
2475 *result = NET_NFC_NULL_PARAMETER;
2479 if (!__net_nfc_is_valid_target_handle(handle))
2481 *result = NET_NFC_INVALID_HANDLE;
2485 if (handle->connection_type == NET_NFC_P2P_CONNECTION_INITIATOR || handle->connection_type == NET_NFC_P2P_CONNECTION_TARGET)
2488 for (; idx < PHFRINFC_LLCP_NB_SOCKET_MAX; idx++)
2490 if (socket_info_array[idx].isValid == true && socket_info_array[idx].socket_handle != 0)
2492 net_nfc_error_e error = NET_NFC_OK;
2493 net_nfc_nxp_controller_llcp_socket_close(socket_info_array[idx].socket_handle, &error);
2498 if (handle->connection_type == NET_NFC_P2P_CONNECTION_INITIATOR)
2501 DEBUG_MSG("I am Target. The remote device is initiator. refuse to call disconnect ");
2502 __net_nfc_make_invalid_target_handle();
2507 phLibNfc_Handle hTargetDev = (phLibNfc_Handle)handle->connection_id;
2509 *result = NET_NFC_OK;
2510 NFCSTATUS friReturn;
2512 phLibNfc_eReleaseType_t releaseType = NFC_INVALID_RELEASE_TYPE;
2514 switch (handle->connection_type)
2516 case NET_NFC_TAG_CONNECTION :
2517 releaseType = NFC_DISCOVERY_CONTINUE;
2519 case NET_NFC_P2P_CONNECTION_INITIATOR :
2520 case NET_NFC_P2P_CONNECTION_TARGET :
2521 releaseType = NFC_DISCOVERY_RESTART;
2523 case NET_NFC_SE_CONNECTION :
2524 releaseType = NFC_SMARTMX_RELEASE;
2527 releaseType = NFC_DISCOVERY_CONTINUE;
2532 // This handle is not useful anymore
2533 __net_nfc_make_invalid_target_handle();
2535 DEBUG_MSG("releaseType = [%d]", releaseType);
2537 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2538 controller_context_s context = { &controller_cond, NULL, 0 };
2540 NET_NFC_OEM_CONTROLLER_LOCK;
2542 DEBUG_MSG("call disconnect");
2544 friReturn = phLibNfc_RemoteDev_Disconnect(hTargetDev, releaseType, _net_nfc_disconnect_cb, (void *)&context);
2545 if (friReturn == NFCSTATUS_PENDING)
2547 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2548 NET_NFC_OEM_CONTROLLER_UNLOCK;
2550 if (context.result != NFCSTATUS_SUCCESS)
2552 DEBUG_ERR_MSG("disconnect is failed = [0x%x]", context.result);
2553 *result = _net_nfc_nxp_error_converter(context.result);
2559 NET_NFC_OEM_CONTROLLER_UNLOCK;
2560 DEBUG_MSG("disconnect is failed = [0x%x]", friReturn);
2561 *result = _net_nfc_nxp_error_converter(friReturn);
2568 static bool net_nfc_nxp_controller_check_ndef(net_nfc_target_handle_s *handle, uint8_t *ndef_card_state, int *max_data_size, int *real_data_size, net_nfc_error_e *result)
2570 phLibNfc_Handle hTargetDev;
2571 ndef_info_s ndef_info;
2572 NFCSTATUS friReturn = NFCSTATUS_SUCCESS;
2573 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2574 controller_context_s context = { &controller_cond, &ndef_info, 0 };
2582 *result = NET_NFC_OK;
2584 if (handle == NULL || ndef_card_state == NULL || max_data_size == NULL || real_data_size == NULL || result == NULL)
2586 *result = NET_NFC_NULL_PARAMETER;
2590 hTargetDev = (phLibNfc_Handle)handle->connection_id;
2592 ndef_info.ndef_card_state = 0;
2593 ndef_info.max_data_size = -1;
2594 ndef_info.real_data_size = -1;
2596 if (!__net_nfc_is_valid_target_handle(handle))
2598 *result = NET_NFC_INVALID_HANDLE;
2602 NET_NFC_OEM_CONTROLLER_LOCK;
2603 friReturn = phLibNfc_Ndef_CheckNdef(hTargetDev, _net_nfc_target_check_ndef_cb, (void *)&context);
2604 if (friReturn == NFCSTATUS_PENDING)
2606 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2607 NET_NFC_OEM_CONTROLLER_UNLOCK;
2609 if (context.result != NFCSTATUS_SUCCESS)
2611 *result = _net_nfc_nxp_error_converter(context.result);
2616 *ndef_card_state = ndef_info.ndef_card_state;
2617 *max_data_size = ndef_info.max_data_size;
2618 *real_data_size = ndef_info.real_data_size;
2620 DEBUG_MSG("Card State : [%d] MAX data size :[%d] actual data size = [%d]", ndef_info.ndef_card_state, ndef_info.max_data_size, ndef_info.real_data_size);
2627 NET_NFC_OEM_CONTROLLER_UNLOCK;
2628 DEBUG_MSG("operation is failed = [0x%x]", friReturn);
2629 *result = _net_nfc_nxp_error_converter(friReturn);
2636 static bool net_nfc_nxp_controller_make_read_only_ndef(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
2638 phLibNfc_Handle hTargetDev;
2639 NFCSTATUS ret = NFCSTATUS_SUCCESS;
2640 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2641 controller_context_s context = { &controller_cond, NULL, 0 };
2648 *result = NET_NFC_OK;
2650 if (handle == NULL || result == NULL)
2652 *result = NET_NFC_NULL_PARAMETER;
2656 if (!__net_nfc_is_valid_target_handle(handle))
2658 *result = NET_NFC_INVALID_HANDLE;
2662 hTargetDev = (phLibNfc_Handle)handle->connection_id;
2664 DEBUG_MSG("make read only ndef tag");
2666 NET_NFC_OEM_CONTROLLER_LOCK;
2668 if ((ret = phLibNfc_ConvertToReadOnlyNdef(hTargetDev, _net_nfc_make_read_only_cb, (void *)&context)) == NFCSTATUS_PENDING)
2670 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2671 NET_NFC_OEM_CONTROLLER_UNLOCK;
2673 if (context.result != NFCSTATUS_SUCCESS)
2675 *result = _net_nfc_nxp_error_converter(context.result);
2681 NET_NFC_OEM_CONTROLLER_UNLOCK;
2682 *result = _net_nfc_nxp_error_converter(ret);
2690 static bool net_nfc_nxp_controller_read_ndef(net_nfc_target_handle_s *handle, data_s **data, net_nfc_error_e *result)
2692 phLibNfc_Handle hTargetDev;
2693 NFCSTATUS ret = NFCSTATUS_SUCCESS;
2700 *result = NET_NFC_OK;
2702 if (handle == NULL || data == NULL || result == NULL)
2704 *result = NET_NFC_NULL_PARAMETER;
2708 if (!__net_nfc_is_valid_target_handle(handle))
2710 *result = NET_NFC_INVALID_HANDLE;
2714 hTargetDev = (phLibNfc_Handle)handle->connection_id;
2716 DEBUG_MSG("read msg from TAG");
2718 uint8_t ndef_card_state = 0;
2719 int real_data_size = 0;
2720 int max_data_size = 0;
2722 if (net_nfc_nxp_controller_check_ndef(handle, &ndef_card_state, &max_data_size, &real_data_size, result) != true)
2724 *result = NET_NFC_NO_NDEF_SUPPORT;
2729 if (real_data_size == 0)
2731 *result = NET_NFC_NO_NDEF_MESSAGE;
2735 _net_nfc_util_alloc_mem(*data, sizeof(data_s));
2738 *result = NET_NFC_ALLOC_FAIL;
2742 (*data)->length = real_data_size;
2743 _net_nfc_util_alloc_mem((*data)->buffer, real_data_size);
2744 if ((*data)->buffer == NULL)
2746 _net_nfc_util_free_mem(*data);
2747 *result = NET_NFC_ALLOC_FAIL;
2751 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2752 controller_context_s context = { &controller_cond, NULL, 0 };
2754 NET_NFC_OEM_CONTROLLER_LOCK;
2755 if ((ret = phLibNfc_Ndef_Read(hTargetDev, (phNfc_sData_t *)*data, phLibNfc_Ndef_EBegin, _net_nfc_ndef_read_cb, (void *)&context)) == NFCSTATUS_PENDING)
2757 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2758 NET_NFC_OEM_CONTROLLER_UNLOCK;
2760 if (context.result != NFCSTATUS_SUCCESS)
2762 _net_nfc_util_free_mem((*data)->buffer);
2763 _net_nfc_util_free_mem(*data);
2765 *result = _net_nfc_nxp_error_converter(context.result);
2771 NET_NFC_OEM_CONTROLLER_UNLOCK;
2773 _net_nfc_util_free_mem((*data)->buffer);
2774 _net_nfc_util_free_mem(*data);
2776 *result = _net_nfc_nxp_error_converter(ret);
2784 static bool net_nfc_nxp_controller_write_ndef(net_nfc_target_handle_s *handle, data_s *data, net_nfc_error_e *result)
2786 phLibNfc_Handle hTargetDev;
2787 NFCSTATUS ret = NFCSTATUS_SUCCESS;
2788 bool is_ndef_support = false;
2790 uint8_t ndef_card_state = 0;
2791 int max_data_size = 0;
2792 int real_data_size = 0;
2799 *result = NET_NFC_OK;
2801 if (handle == NULL || data == NULL || result == NULL)
2803 *result = NET_NFC_NULL_PARAMETER;
2806 if (!__net_nfc_is_valid_target_handle(handle))
2808 *result = NET_NFC_INVALID_HANDLE;
2812 hTargetDev = (phLibNfc_Handle)handle->connection_id;
2814 is_ndef_support = net_nfc_nxp_controller_check_ndef(handle, &ndef_card_state, &max_data_size, &real_data_size, result);
2815 if (is_ndef_support == true)
2817 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2818 controller_context_s context = { &controller_cond, NULL, 0 };
2820 if (ndef_card_state == NET_NFC_NDEF_CARD_READ_ONLY)
2822 DEBUG_MSG("It is read only tag", ndef_card_state);
2823 *result = NET_NFC_NOT_ALLOWED_OPERATION;
2828 if (data->length > max_data_size)
2830 DEBUG_MSG("the MAX available size in this tag is = [%d] bytes. but you try to write [%d] bytes", max_data_size, data->length);
2831 *result = NET_NFC_INSUFFICIENT_STORAGE;
2836 NET_NFC_OEM_CONTROLLER_LOCK;
2838 if ((ret = phLibNfc_Ndef_Write(hTargetDev, (phNfc_sData_t *)(data), _net_nfc_ndef_write_cb, (void *)&context)) == NFCSTATUS_PENDING)
2840 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2841 NET_NFC_OEM_CONTROLLER_UNLOCK;
2843 if (context.result != NFCSTATUS_SUCCESS)
2845 *result = _net_nfc_nxp_error_converter(context.result);
2851 NET_NFC_OEM_CONTROLLER_UNLOCK;
2853 DEBUG_MSG("operation is failed = [0x%x]", ret);
2854 *result = _net_nfc_nxp_error_converter(ret);
2860 *result = NET_NFC_NO_NDEF_SUPPORT;
2867 static bool net_nfc_nxp_controller_transceive(net_nfc_target_handle_s *handle, net_nfc_transceive_info_s *info, data_s **data, net_nfc_error_e *result)
2869 phLibNfc_Handle hTargetDev;
2870 NFCSTATUS friReturn = NFCSTATUS_SUCCESS;
2871 uint8_t trbuffer[NET_NFC_MAX_TRANCIEVE_BUFFER] = { 0, };
2872 phLibNfc_sTransceiveInfo_t trans_info;
2879 *result = NET_NFC_OK;
2881 if (handle == NULL || info == NULL || data == NULL || result == NULL)
2883 *result = NET_NFC_NULL_PARAMETER;
2887 if (!__net_nfc_is_valid_target_handle(handle))
2889 *result = NET_NFC_INVALID_HANDLE;
2893 if (info->trans_data.buffer == NULL || info->trans_data.length == 0)
2895 *result = NET_NFC_NULL_PARAMETER;
2899 hTargetDev = (phLibNfc_Handle)handle->connection_id;
2901 *result = NET_NFC_OK;
2903 _net_nfc_util_alloc_mem(*data, sizeof (data_s));
2905 (*data)->buffer = NULL;
2906 (*data)->length = 0;
2908 memset(&trans_info, 0x00, sizeof(phLibNfc_sTransceiveInfo_t));
2910 trans_info.sRecvData.length = NET_NFC_MAX_TRANCIEVE_BUFFER;
2911 trans_info.sRecvData.buffer = trbuffer;
2913 DEBUG_MSG_PRINT_BUFFER(info->trans_data.buffer, info->trans_data.length);
2915 switch (info->dev_type)
2917 case NET_NFC_MIFARE_MINI_PICC :
2918 case NET_NFC_MIFARE_1K_PICC :
2919 case NET_NFC_MIFARE_4K_PICC :
2920 case NET_NFC_MIFARE_ULTRA_PICC :
2922 trans_info.cmd.MfCmd = info->trans_data.buffer[0];
2923 trans_info.addr = info->trans_data.buffer[1];
2925 trans_info.sSendData.buffer = info->trans_data.buffer + 2; // only parametor should be passed to FRI stack with MIFARE cmd
2926 trans_info.sSendData.length = info->trans_data.length - 4; // remove CMD (1byte) + ADDR (1byte) + CRC_A (2byte)
2930 case NET_NFC_FELICA_PICC :
2932 trans_info.cmd.FelCmd = phNfc_eFelica_Raw;
2933 trans_info.addr = 0x00;
2934 trans_info.sSendData.buffer = info->trans_data.buffer;
2935 trans_info.sSendData.length = info->trans_data.length;
2939 case NET_NFC_ISO15693_PICC :
2941 trans_info.cmd.Iso15693Cmd = phNfc_eIso15693_Cmd;
2942 trans_info.addr = 0x00;
2943 trans_info.sSendData.buffer = info->trans_data.buffer;
2944 trans_info.sSendData.length = info->trans_data.length;
2950 trans_info.sSendData.buffer = info->trans_data.buffer;
2951 trans_info.sSendData.length = info->trans_data.length;
2956 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
2957 controller_context_s context = { &controller_cond, *data, 0 };
2959 NET_NFC_OEM_CONTROLLER_LOCK;
2960 friReturn = phLibNfc_RemoteDev_Transceive(hTargetDev, &trans_info, _net_nfc_transceive_cb, (void *)&context);
2961 if (friReturn == NFCSTATUS_PENDING)
2963 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
2964 NET_NFC_OEM_CONTROLLER_UNLOCK;
2966 if (context.result == NFCSTATUS_SUCCESS)
2972 *result = _net_nfc_nxp_error_converter(context.result);
2974 /* TODO : release data??? */
2980 NET_NFC_OEM_CONTROLLER_UNLOCK;
2981 DEBUG_MSG("transceiving with remote device is failed %d", friReturn);
2982 *result = _net_nfc_nxp_error_converter(friReturn);
2984 /* TODO : release data??? */
2989 static bool net_nfc_nxp_controller_exception_handler(void)
2991 NFCSTATUS status = NFCSTATUS_SUCCESS;
2992 net_nfc_error_e error;
2994 if ((status = phLibNfc_Mgt_DeInitialize(psHwRef.p_board_driver, NULL, NULL)) != NFCSTATUS_SUCCESS)
2996 DEBUG_MSG("deinit is failed");
3000 DEBUG_MSG("deinit is success");
3003 if (phLibNfc_Mgt_UnConfigureDriver(psHwRef.p_board_driver) == NFCSTATUS_SUCCESS)
3005 DEBUG_MSG("unregister driver is success");
3009 DEBUG_MSG("unregister driver is failed");
3012 if (net_nfc_nxp_controller_init(&error) == false)
3018 net_nfc_llcp_config_info_s config = { 128, 1, 100, 0 };
3020 if (net_nfc_nxp_controller_llcp_config(&config, &error) == true)
3022 DEBUG_MSG("set llcp config is success");
3026 DEBUG_MSG("set llcp config is failed");
3029 if (net_nfc_nxp_controller_register_listener(g_nxp_controller_target_cb, g_nxp_controller_se_cb, g_nxp_controller_llcp_cb, &error) == true)
3031 DEBUG_MSG("register event cb is success");
3035 DEBUG_MSG("register event cb is failed");
3038 if (net_nfc_nxp_controller_configure_discovery(NET_NFC_DISCOVERY_MODE_CONFIG, NET_NFC_ALL_ENABLE, &error) == true)
3040 DEBUG_MSG("configure discovery loop is success");
3044 DEBUG_MSG("configure discovery loop is failed");
3051 static bool net_nfc_nxp_controller_is_ready(net_nfc_error_e *result)
3058 return g_stack_init_successful;
3061 static bool net_nfc_nxp_controller_format_ndef(net_nfc_target_handle_s *handle, data_s *secure_key, net_nfc_error_e *result)
3063 phLibNfc_Handle hTargetDev;
3064 NFCSTATUS status = NFCSTATUS_SUCCESS;
3065 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
3066 controller_context_s context = { &controller_cond, NULL, 0 };
3067 uint8_t ndef_card_state = 0;
3068 int max_data_size = 0;
3069 int real_data_size = 0;
3076 *result = NET_NFC_OK;
3080 *result = NET_NFC_NULL_PARAMETER;
3084 if (!__net_nfc_is_valid_target_handle(handle))
3086 *result = NET_NFC_INVALID_HANDLE;
3090 hTargetDev = (phLibNfc_Handle)handle->connection_id;
3092 if (net_nfc_nxp_controller_check_ndef(handle, &ndef_card_state, &max_data_size, &real_data_size, result) == true)
3094 DEBUG_MSG("ndef format : NET_NFC_TAG_IS_ALREADY_FORMATTED");
3095 *result = NET_NFC_TAG_IS_ALREADY_FORMATTED;
3099 NET_NFC_OEM_CONTROLLER_LOCK;
3101 if ((status = phLibNfc_RemoteDev_FormatNdef(hTargetDev, (phNfc_sData_t *)secure_key, _net_nfc_format_remote_dev_ndef_cb, &context)) == NFCSTATUS_PENDING)
3103 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
3104 NET_NFC_OEM_CONTROLLER_UNLOCK;
3106 if (context.result == NFCSTATUS_SUCCESS)
3108 DEBUG_MSG("net_nfc_nxp_controller_format_ndef success");
3109 *result = NET_NFC_OK;
3114 DEBUG_MSG("ndef format : error is returned from stack #1= [0x%x]", context.result);
3120 DEBUG_MSG("ndef format : error is returned from stack #2 = [0x%x]", status);
3122 NET_NFC_OEM_CONTROLLER_UNLOCK;
3123 *result = _net_nfc_nxp_error_converter(status);
3129 /*******************
3131 ********************/
3133 void _net_nfc_llcp_config_cb(void *pContext, NFCSTATUS status)
3135 controller_context_s *context = NULL;
3137 if (pContext != NULL)
3139 context = (controller_context_s *)pContext;
3140 context->result = (int)status;
3143 if (status == NFCSTATUS_SUCCESS)
3145 DEBUG_MSG("set llcp config is success");
3149 DEBUG_MSG("set llcp config is failed = [0x%x]", status);
3152 if (context != NULL)
3154 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
3158 void _net_nfc_llcp_check_llcp_cb(void *pContext, NFCSTATUS status)
3160 if (pContext != NULL)
3162 controller_context_s *context = (controller_context_s *)pContext;
3163 context->result = status;
3166 if (status == NFCSTATUS_SUCCESS)
3168 DEBUG_MSG("llcp status is success");
3172 DEBUG_MSG("llcp status is not good = [0x%x]", status);
3176 void _net_nfc_llcp_link_status_cb(void *pContext, phLibNfc_Llcp_eLinkStatus_t eLinkStatus)
3178 if (eLinkStatus == phFriNfc_LlcpMac_eLinkActivated)
3180 DEBUG_MSG("llcp link status is activated");
3184 DEBUG_MSG("llcp link status is deactivated = [0x%x]", eLinkStatus);
3186 if (pContext != NULL)
3188 controller_context_s *context = (controller_context_s *)pContext;
3189 net_nfc_request_llcp_msg_t *req_msg = NULL;
3191 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3192 if (req_msg != NULL)
3194 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3195 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_DEACTIVATED;
3196 g_nxp_controller_llcp_cb(req_msg, context->user_context);
3199 _net_nfc_util_free_mem(context);
3204 void _net_nfc_llcp_socket_err_cb(void *pContext, uint8_t nErrCode)
3206 socket_info_s *socket_info = (socket_info_s *)pContext;
3208 // CB MUST return ASAP
3209 if (nErrCode == PHFRINFC_LLCP_ERR_FRAME_REJECTED)
3211 DEBUG_MSG("> ERROR: FRAME REJECTED - DISCONNECTED \n");
3213 else if (nErrCode == PHFRINFC_LLCP_ERR_DISCONNECTED)
3215 DEBUG_MSG("> Socket error and DISCONNECTED \n");
3219 DEBUG_MSG("> Error code: %d \n", nErrCode);
3222 if (socket_info != NULL)
3224 if (_net_nfc_find_server_socket(socket_info->socket_handle) == NULL)
3226 DEBUG_MSG("> socket is already closed \n");
3229 if (socket_info->socket_handle != (net_nfc_llcp_socket_t) NULL && socket_info->isValid == true)
3231 net_nfc_request_llcp_msg_t *req_msg = NULL;
3233 DEBUG_MSG("close err socket = [0x%x]", socket_info->socket_handle);
3235 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3236 if (req_msg != NULL)
3238 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3239 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ERROR;
3240 req_msg->result = net_nfc_nxp_controller_convert_llcp_error_codes(nErrCode);
3242 g_nxp_controller_llcp_cb(req_msg, socket_info->user_context);
3248 void __net_nfc_llcp_accept_cb_from_listen(void *pContext, NFCSTATUS status)
3250 accept_context_s *context = NULL;
3251 net_nfc_request_accept_socket_t *detail = NULL;
3253 DEBUG_MSG("accept cb is called");
3255 _net_nfc_util_alloc_mem(detail, sizeof(net_nfc_request_accept_socket_t));
3258 context = (accept_context_s *)pContext;
3260 detail->length = sizeof(net_nfc_request_accept_socket_t);
3261 detail->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT;
3262 detail->handle = context->handle;
3263 detail->incomming_socket = context->incomming;
3264 detail->trans_param = context->user_param;
3265 detail->result = _net_nfc_nxp_error_converter(status);
3267 DEBUG_MSG("callback is called, incomming is %X", detail->incomming_socket);
3269 g_nxp_controller_llcp_cb(detail, context->user_param);
3273 void __net_nfc_llcp_accepted_socket_err_cb_from_listen(void *pContext, uint8_t nErrCode)
3275 accept_context_s *context = NULL;
3277 if (nErrCode == PHFRINFC_LLCP_ERR_FRAME_REJECTED)
3279 DEBUG_MSG("> ERROR: FRAME REJECTED - DISCONNECTED \n");
3281 else if (nErrCode == PHFRINFC_LLCP_ERR_DISCONNECTED)
3283 DEBUG_MSG("> DISCONNECTED \n");
3287 DEBUG_MSG("> Error code: %d \n", nErrCode);
3290 if (pContext != NULL)
3292 context = (accept_context_s *)pContext;
3294 if (_net_nfc_find_server_socket(context->incomming) == NULL)
3296 DEBUG_MSG("> socket is already closed \n");
3300 net_nfc_request_llcp_msg_t *req_msg = NULL;
3302 _net_nfc_util_alloc_mem(req_msg, sizeof (net_nfc_request_llcp_msg_t));
3304 if (req_msg != NULL)
3306 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3307 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR;
3308 req_msg->result = net_nfc_nxp_controller_convert_llcp_error_codes(nErrCode);
3310 g_nxp_controller_llcp_cb(req_msg, context->user_param);
3316 void _net_nfc_llcp_listen_cb(void *pContext, net_nfc_llcp_socket_t IncomingSocket)
3318 DEBUG_MSG("listen cb is called. Incomming Socket is = [0x%x]", IncomingSocket);
3320 /* net_nfc_request_msg_t *req_msg = (net_nfc_request_msg_t*)calloc(1, sizeof(net_nfc_request_msg_t));
3321 net_nfc_request_accept_socket_t *detail = (net_nfc_request_accept_socket_t *)calloc(1, sizeof(net_nfc_request_accept_socket_t));
3322 accept_context_s *context = NULL;
3323 socket_info_s *psocket_info = NULL;
3325 if(req_msg != NULL && detail != NULL)
3327 context = (accept_context_s *) pContext;
3328 detail->incomming_socket = context->server_scket;
3329 detail->handle = context->handle;
3331 psocket_info = _net_nfc_find_server_socket(context->server_scket);
3332 psocket_info->socket_handle_incomming = IncomingSocket;
3334 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_ACCEPT;
3335 req_msg->detail_message = detail;
3337 g_nxp_controller_llcp_cb(req_msg, NULL);
3339 if (context != NULL) {
3340 _net_nfc_util_free_mem (context);
3344 if (pContext != NULL)
3346 accept_context_s *context = (accept_context_s *)pContext;
3347 socket_info_s *psocket_info = NULL;
3348 data_s *socket_buffer;
3349 phLibNfc_Llcp_sSocketOptions_t sOptions;
3350 accept_context_s *accept_socket_context = NULL;
3353 psocket_info = _net_nfc_find_server_socket(context->server_scket);
3354 // psocket_info->socket_handle_incomming = IncomingSocket;
3355 context->incomming = IncomingSocket;
3357 sOptions.miu = psocket_info->miu;
3358 sOptions.rw = psocket_info->rw;
3360 psocket_info = _net_nfc_get_available_socket_slot();
3361 if (psocket_info == NULL)
3363 DEBUG_ERR_MSG("> ERROR: failed to accept incomming socket caused by no available slot \n");
3366 psocket_info->socket_handle = IncomingSocket;
3367 //psocket_info->miu = psocket_info->miu;
3368 //psocket_info->rw = psocket_info->rw;
3369 socket_buffer = &(psocket_info->data);
3371 /*_net_nfc_util_alloc_mem (context->data.buffer, BUFFER_LENGTH_MAX);
3372 context->data.length = BUFFER_LENGTH_MAX;
3373 if (context->data.buffer == NULL) {
3374 DEBUG_MSG("> ERROR: socket buffer allocation is failed \n");
3376 socket_buffer = &(context->data);
3379 // NET_NFC_OEM_CONTROLLER_LOCK;
3380 _net_nfc_util_alloc_mem(accept_socket_context, sizeof(accept_context_s));
3381 memcpy(accept_socket_context, context, sizeof(accept_context_s));
3383 psocket_info->context = accept_socket_context;
3385 status = phLibNfc_Llcp_Accept(IncomingSocket,
3387 (phNfc_sData_t *)socket_buffer,
3388 __net_nfc_llcp_accepted_socket_err_cb_from_listen,
3389 __net_nfc_llcp_accept_cb_from_listen,
3390 accept_socket_context);
3391 DEBUG_MSG("Accept in listen callback is called: return [%d]", status);
3392 // NET_NFC_OEM_CONTROLLER_UNLOCK
3395 DEBUG_MSG("listen cb is end");
3398 void _net_nfc_llcp_accepted_socket_err_cb(void *pContext, uint8_t nErrCode)
3400 controller_context_s *context = NULL;
3402 if (nErrCode == PHFRINFC_LLCP_ERR_FRAME_REJECTED)
3404 DEBUG_MSG("> ERROR: FRAME REJECTED - DISCONNECTED \n");
3406 else if (nErrCode == PHFRINFC_LLCP_ERR_DISCONNECTED)
3408 DEBUG_MSG("> DISCONNECTED \n");
3412 DEBUG_MSG("> Error code: %d \n", nErrCode);
3415 if (pContext != NULL)
3417 net_nfc_request_llcp_msg_t *req_msg = NULL;
3418 socket_info_s *socket_info = (socket_info_s *)context->user_context;
3420 context = (controller_context_s *)pContext;
3422 _net_nfc_util_alloc_mem(req_msg, sizeof (net_nfc_request_llcp_msg_t));
3423 if (req_msg != NULL)
3425 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3426 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_SOCKET_ACCEPTED_ERROR;
3427 req_msg->result = net_nfc_nxp_controller_convert_llcp_error_codes(nErrCode);
3429 g_nxp_controller_llcp_cb(req_msg, context->user_context);
3432 if (socket_info != NULL)
3434 if (socket_info->data.buffer != NULL)
3436 _net_nfc_util_free_mem(socket_info->data.buffer);
3437 socket_info->data.buffer = NULL;
3440 _net_nfc_util_free_mem(socket_info);
3443 _net_nfc_util_free_mem(context);
3447 void _net_nfc_llcp_accept_cb(void *pContext, NFCSTATUS status)
3449 controller_context_s *context = NULL;
3451 if (pContext != NULL)
3453 context = (controller_context_s *)pContext;
3454 socket_info_s *socket_info = (socket_info_s *)context->user_context;
3456 if (socket_info != NULL)
3458 context->result = (int)status;
3461 // TODO : free socket_info
3463 // free should be done in socket error
3464 //free(socket_info);
3467 if (status == NFCSTATUS_SUCCESS)
3469 DEBUG_MSG(">>>>> client is accepted \n");
3473 DEBUG_MSG(">>>>> client is not accpeted = [0x%x]\n", status);
3476 if (context != NULL)
3478 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
3482 void _net_nfc_llcp_connect_sap_cb(void *pContext, uint8_t nErrCode, NFCSTATUS status)
3484 if (pContext != NULL)
3486 net_nfc_request_llcp_msg_t *req_msg = NULL;
3488 if (status == NFCSTATUS_SUCCESS)
3490 DEBUG_MSG(">>>>> SOCKET is CONNECTED \n");
3494 DEBUG_MSG(">>>>> SOCKET is not CONNECTED status = [0x%x] errCode = [0x%x]\n", status, nErrCode);
3497 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3498 if (req_msg == NULL)
3500 DEBUG_MSG("Allocation is failed\n");
3504 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3505 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT_SAP;
3506 req_msg->result = _net_nfc_nxp_error_converter(status);
3508 g_nxp_controller_llcp_cb(req_msg, pContext);
3512 void _net_nfc_llcp_connect_cb(void *pContext, uint8_t nErrCode, NFCSTATUS status)
3514 if (pContext != NULL)
3516 net_nfc_request_llcp_msg_t *req_msg = NULL;
3518 if (status == NFCSTATUS_SUCCESS)
3520 DEBUG_MSG(">>>>> SOCKET is CONNECTED \n");
3524 DEBUG_MSG(">>>>> SOCKET is not CONNECTED status = [0x%x] errCode = [0x%x]\n", status, nErrCode);
3527 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3528 if (req_msg == NULL)
3530 DEBUG_MSG("Allocation is failed\n");
3534 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3535 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_CONNECT;
3536 req_msg->result = _net_nfc_nxp_error_converter(status);
3538 g_nxp_controller_llcp_cb(req_msg, pContext);
3542 void _net_nfc_llcp_send_cb(void *pContext, NFCSTATUS status)
3544 net_nfc_request_llcp_msg_t *req_msg = NULL;
3545 transfer_context_s *tcontext = (transfer_context_s *)pContext;
3547 if (pContext == NULL)
3550 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3551 if (req_msg != NULL)
3553 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3554 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_SEND;
3555 req_msg->result = _net_nfc_nxp_error_converter(status);
3557 g_nxp_controller_llcp_cb(req_msg, tcontext->user_param);
3560 /* below memory must be freed */
3561 _net_nfc_util_free_mem(tcontext->data.buffer);
3562 _net_nfc_util_free_mem(tcontext);
3565 void _net_nfc_llcp_sendTo_cb(void *pContext, NFCSTATUS status)
3567 net_nfc_request_llcp_msg_t *req_msg = NULL;
3568 transfer_context_s *tcontext = (transfer_context_s *)pContext;
3570 if (pContext == NULL)
3573 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3574 if (req_msg != NULL)
3576 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3577 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_SEND_TO;
3578 req_msg->result = _net_nfc_nxp_error_converter(status);
3580 g_nxp_controller_llcp_cb(req_msg, tcontext->user_param);
3583 /* below memory must be freed */
3584 _net_nfc_util_free_mem(tcontext->data.buffer);
3585 _net_nfc_util_free_mem(tcontext);
3588 void _net_nfc_llcp_recv_cb(void *pContext, NFCSTATUS status)
3590 net_nfc_request_llcp_msg_t *req_msg = NULL;
3592 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3593 if (req_msg != NULL)
3595 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3596 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE;
3597 req_msg->result = _net_nfc_nxp_error_converter(status);
3599 g_nxp_controller_llcp_cb(req_msg, pContext);
3603 void _net_nfc_llcp_recv_from_cb(void *pContext, uint8_t service_access_point, NFCSTATUS status)
3605 net_nfc_request_llcp_msg_t *req_msg = NULL;
3607 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3608 if (req_msg != NULL)
3610 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3611 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_RECEIVE_FROM;
3612 req_msg->result = _net_nfc_nxp_error_converter(status);
3614 g_nxp_controller_llcp_cb(req_msg, pContext);
3618 void _net_nfc_llcp_disconnect_cb(void *pContext, NFCSTATUS status)
3620 net_nfc_request_llcp_msg_t *req_msg = NULL;
3622 _net_nfc_util_alloc_mem(req_msg, sizeof(net_nfc_request_llcp_msg_t));
3623 if (req_msg != NULL)
3625 req_msg->length = sizeof(net_nfc_request_llcp_msg_t);
3626 req_msg->request_type = NET_NFC_MESSAGE_SERVICE_LLCP_DISCONNECT;
3627 req_msg->result = _net_nfc_nxp_error_converter(status);
3629 g_nxp_controller_llcp_cb(req_msg, pContext);
3633 void _net_nfc_llcp_reject_cb(void *pContext, NFCSTATUS status)
3635 controller_context_s *context = NULL;
3637 if (status == NFCSTATUS_SUCCESS)
3639 DEBUG_MSG("llcp reject [0x%x] is success", status);
3643 DEBUG_MSG("llcp reject [0x%x] is failed", status);
3646 DEBUG_MSG("pContext = [0x%x]", pContext);
3648 if (pContext != NULL)
3650 context = (controller_context_s *)pContext;
3651 context->result = status;
3653 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
3657 static bool net_nfc_nxp_controller_llcp_config(net_nfc_llcp_config_info_s *config, net_nfc_error_e * result)
3659 NFCSTATUS status = NFCSTATUS_SUCCESS;
3660 phLibNfc_Llcp_sLinkParameters_t LLCP_Config_Info;
3661 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
3662 controller_context_s context = { &controller_cond, NULL, 0 };
3669 *result = NET_NFC_OK;
3671 _net_nfc_reset_socket_array();
3673 memset(&LLCP_Config_Info, 0x00, sizeof(phLibNfc_Llcp_sLinkParameters_t));
3675 LLCP_Config_Info.miu = config->miu;
3676 LLCP_Config_Info.lto = config->lto;
3677 LLCP_Config_Info.wks = config->wks;
3678 LLCP_Config_Info.option = config->option;
3680 DEBUG_MSG("> Set LLCP config params (LTO=%d, MIU=%d, OPTION=0x%02x, WKS=0x%02x): ", LLCP_Config_Info.lto,
3681 LLCP_Config_Info.miu,
3682 LLCP_Config_Info.option,
3683 LLCP_Config_Info.wks);
3685 NET_NFC_OEM_CONTROLLER_LOCK;
3686 if ((status = phLibNfc_Mgt_SetLlcp_ConfigParams(&LLCP_Config_Info,
3687 _net_nfc_llcp_config_cb,
3688 &context)) == NFCSTATUS_PENDING)
3690 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
3691 NET_NFC_OEM_CONTROLLER_UNLOCK;
3694 else if (status == NFCSTATUS_SUCCESS)
3696 NET_NFC_OEM_CONTROLLER_UNLOCK;
3701 NET_NFC_OEM_CONTROLLER_UNLOCK;
3702 DEBUG_MSG("set llcp config operation is failed = [0x%x]", status);
3703 *result = _net_nfc_nxp_error_converter(status);
3707 if (context.result != NFCSTATUS_SUCCESS)
3709 DEBUG_MSG("set llcp config param is failed");
3710 *result = _net_nfc_nxp_error_converter(context.result);
3717 static bool net_nfc_nxp_controller_llcp_check_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
3719 controller_context_s *context = NULL;
3720 phLibNfc_Handle hRemoteDevice;
3721 NFCSTATUS status = NFCSTATUS_SUCCESS;
3728 *result = NET_NFC_OK;
3732 *result = NET_NFC_NULL_PARAMETER;
3736 if (!__net_nfc_is_valid_target_handle(handle))
3738 *result = NET_NFC_INVALID_HANDLE;
3742 _net_nfc_util_alloc_mem(context, sizeof(controller_context_s));
3743 if (context == NULL)
3745 *result = NET_NFC_ALLOC_FAIL;
3749 context->controller_cond = NULL;
3750 context->user_context = handle;
3751 context->result = 0;
3753 hRemoteDevice = handle->connection_id;
3755 // pass the connection handle value to disconnect
3757 NET_NFC_OEM_CONTROLLER_LOCK;
3758 status = phLibNfc_Llcp_CheckLlcp(hRemoteDevice, _net_nfc_llcp_check_llcp_cb, _net_nfc_llcp_link_status_cb, context);
3760 DEBUG_MSG("llcp check_llcp operation result = [0x%x]", status);
3762 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
3764 NET_NFC_OEM_CONTROLLER_UNLOCK;
3766 DEBUG_MSG("check result");
3768 if (context->result != NFCSTATUS_SUCCESS)
3770 DEBUG_MSG("Llcp of remote target is not available");
3771 *result = _net_nfc_nxp_error_converter(context->result);
3776 DEBUG_MSG("Llcp of remote target is activated");
3782 NET_NFC_OEM_CONTROLLER_UNLOCK;
3783 DEBUG_MSG("check_llcp operation is failed: %d\n", status);
3784 *result = _net_nfc_nxp_error_converter(status);
3789 static bool net_nfc_nxp_controller_llcp_activate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
3791 phLibNfc_Handle hRemoteDevice;
3792 NFCSTATUS status = NFCSTATUS_SUCCESS;
3799 *result = NET_NFC_OK;
3803 *result = NET_NFC_NULL_PARAMETER;
3807 if (!__net_nfc_is_valid_target_handle(handle))
3809 *result = NET_NFC_INVALID_HANDLE;
3813 hRemoteDevice = handle->connection_id;
3815 NET_NFC_OEM_CONTROLLER_LOCK;
3816 status = phLibNfc_Llcp_Activate(hRemoteDevice);
3817 NET_NFC_OEM_CONTROLLER_UNLOCK;
3819 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
3821 DEBUG_MSG("llcp layer is activated = [0x%x]", status);
3826 DEBUG_MSG("activating llcp layer is failed = [0x%x]", status);
3827 *result = _net_nfc_nxp_error_converter(status);
3833 static bool net_nfc_nxp_controller_llcp_deactivate_llcp(net_nfc_target_handle_s *handle, net_nfc_error_e *result)
3840 *result = NET_NFC_OK;
3844 *result = NET_NFC_NULL_PARAMETER;
3848 if (!__net_nfc_is_valide_target_handle (handle)){
3849 *result = NET_NFC_INVALID_HANDLE;
3853 NFCSTATUS status = NFCSTATUS_SUCCESS;
3854 phLibNfc_Handle hRemoteDevice = handle->connection_id;
3856 NET_NFC_OEM_CONTROLLER_LOCK;
3857 status = phLibNfc_Llcp_Deactivate( hRemoteDevice );
3858 NET_NFC_OEM_CONTROLLER_UNLOCK;
3860 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
3862 DEBUG_MSG("llcp layer is deactivated = [0x%x]", status);
3867 DEBUG_MSG("Deactivating llcp layer is failed = [0x%x]", status);
3868 *result = _net_nfc_nxp_error_converter (status);
3874 static bool net_nfc_nxp_controller_llcp_create_socket(net_nfc_llcp_socket_t *socket, net_nfc_socket_type_e socketType, uint16_t miu, uint8_t rw, net_nfc_error_e *result, void *user_param)
3876 NFCSTATUS status = NFCSTATUS_SUCCESS;
3877 phLibNfc_Llcp_sSocketOptions_t sOptions;
3878 socket_info_s *socket_info = NULL;
3885 *result = NET_NFC_OK;
3889 *result = NET_NFC_NULL_PARAMETER;
3893 if (socketType < NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED || socketType > NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONLESS)
3895 *result = NET_NFC_NULL_PARAMETER;
3900 // Where is better to place this available socket slot fucntionality ? nfc-service ? oem_controller ?
3901 socket_info = _net_nfc_get_available_socket_slot();
3902 if (socket_info == NULL)
3904 DEBUG_MSG("mem alloc is failed");
3908 socket_info->user_context = user_param;
3909 socket_info->miu = miu;
3910 socket_info->rw = rw;
3912 memset(&sOptions, 0x00, sizeof(phLibNfc_Llcp_sSocketOptions_t));
3914 NET_NFC_OEM_CONTROLLER_LOCK;
3916 if (socketType == NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED)
3920 DEBUG_MSG("> LLCP Create Socket Connection Oriented: MIU:%d RW:%d", miu, rw);
3921 status = phLibNfc_Llcp_Socket(
3922 phFriNfc_LlcpTransport_eConnectionOriented,
3924 (phNfc_sData_t*)&(socket_info->data),
3926 _net_nfc_llcp_socket_err_cb,
3931 DEBUG_MSG("> LLCP Create Socket ConnectionLess: ");
3932 status = phLibNfc_Llcp_Socket(
3933 phFriNfc_LlcpTransport_eConnectionLess,
3937 _net_nfc_llcp_socket_err_cb,
3942 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
3944 NET_NFC_OEM_CONTROLLER_UNLOCK;
3945 DEBUG_MSG("socket is created = [0x%x], result = [0x%x]", *socket, status);
3946 socket_info->socket_handle = *socket;
3952 NET_NFC_OEM_CONTROLLER_UNLOCK;
3953 DEBUG_MSG("operation socket creation is failed = [0x%x]", status);
3954 *result = _net_nfc_nxp_error_converter(status);
3959 static bool net_nfc_nxp_controller_llcp_bind(net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result)
3961 NFCSTATUS status = NFCSTATUS_SUCCESS;
3968 *result = NET_NFC_OK;
3970 NET_NFC_OEM_CONTROLLER_LOCK;
3971 status = phLibNfc_Llcp_Bind(socket, service_access_point);
3972 NET_NFC_OEM_CONTROLLER_UNLOCK;
3974 DEBUG_MSG("llcp bind operation result = [0x%x]", status);
3976 *result = _net_nfc_nxp_error_converter(status);
3978 if (status != NFCSTATUS_SUCCESS)
3980 DEBUG_MSG("phLibNfc_Llcp_Bind is failed = [0x%x]", status);
3987 static bool net_nfc_nxp_controller_llcp_listen(net_nfc_target_handle_s *handle, uint8_t *service_access_name, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param)
3989 NFCSTATUS status = NFCSTATUS_SUCCESS;
3990 accept_context_s *accept_context = NULL;
3997 if (service_access_name == NULL)
3999 *result = NET_NFC_NULL_PARAMETER;
4003 if (!__net_nfc_is_valid_target_handle(handle))
4005 *result = NET_NFC_INVALID_HANDLE;
4009 *result = NET_NFC_OK;
4011 _net_nfc_util_alloc_mem(accept_context, sizeof(accept_context_s));
4012 if (accept_context == NULL)
4014 *result = NET_NFC_ALLOC_FAIL;
4018 accept_context->handle = handle;
4019 accept_context->server_scket = socket;
4020 accept_context->user_param = user_param;
4022 phNfc_sData_t service_name = { service_access_name, strlen((char *)service_access_name) };
4024 socket_info_s *psocket_info = _net_nfc_find_server_socket(socket);
4025 if (psocket_info != NULL)
4027 psocket_info->context = accept_context; // let it free when the socket is closed
4030 NET_NFC_OEM_CONTROLLER_LOCK;
4031 status = phLibNfc_Llcp_Listen(socket, (phNfc_sData_t *)&service_name, _net_nfc_llcp_listen_cb, (void *)accept_context);
4032 NET_NFC_OEM_CONTROLLER_UNLOCK;
4034 DEBUG_MSG("llcp listen operation result = [0x%x]", status);
4036 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
4038 DEBUG_MSG("socket listening is good");
4043 DEBUG_MSG("operation socket listening is failed = [0x%x]", status);
4044 *result = _net_nfc_nxp_error_converter(status);
4049 /* below accept function does not used. */
4050 static bool net_nfc_nxp_controller_llcp_accept(net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
4052 NFCSTATUS status = NFCSTATUS_SUCCESS;
4053 phLibNfc_Llcp_sSocketOptions_t sOptions;
4054 socket_info_s *socket_info = NULL;
4055 controller_context_s *context = NULL;
4057 sOptions.miu = PHFRINFC_LLCP_MIU_DEFAULT;
4058 sOptions.rw = PHFRINFC_LLCP_RW_DEFAULT * 2;
4060 DEBUG_MSG("> LLCP Accept Socket: ");
4062 _net_nfc_util_alloc_mem(context, sizeof(controller_context_s));
4063 if (context == NULL)
4065 DEBUG_MSG("mem alloc is failed");
4069 _net_nfc_util_alloc_mem(socket_info, sizeof(socket_info_s));
4070 if (socket_info == NULL)
4072 DEBUG_MSG("mem alloc is failed");
4073 _net_nfc_util_free_mem(context);
4078 _net_nfc_util_alloc_mem(socket_info->data.buffer, 1024);
4079 if (socket_info->data.buffer == NULL)
4081 DEBUG_MSG("mem alloc is failed");
4082 _net_nfc_util_free_mem(socket_info);
4083 _net_nfc_util_free_mem(context);
4088 /*psocket_info = _net_nfc_find_server_socket(socket);
4089 if (psocket_info == NULL) {
4090 *result = NET_NFC_LLCP_INVALID_SOCKET;
4095 socket_info->data.length = BUFFER_LENGTH_MAX;
4096 socket_info->socket_handle = socket;
4098 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
4100 // TODO :: when context is freed ?
4102 context->controller_cond = &controller_cond;
4103 context->user_context = socket_info;
4104 context->result = 0;
4106 NET_NFC_OEM_CONTROLLER_LOCK;
4107 status = phLibNfc_Llcp_Accept(socket,
4109 (phNfc_sData_t *)&(socket_info->data),
4110 _net_nfc_llcp_accepted_socket_err_cb,
4111 _net_nfc_llcp_accept_cb,
4114 DEBUG_MSG("llcp accept operation result = [0x%x]", status);
4116 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
4118 if (status == NFCSTATUS_PENDING)
4120 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
4123 NET_NFC_OEM_CONTROLLER_UNLOCK;
4125 if (context->result != NFCSTATUS_SUCCESS)
4127 DEBUG_MSG("accept socket is failed = [0x%x]", context->result);
4128 *result = _net_nfc_nxp_error_converter(context->result);
4134 NET_NFC_OEM_CONTROLLER_UNLOCK;
4135 DEBUG_MSG("operation socket accepting is failed = [0x%x]", status);
4136 *result = _net_nfc_nxp_error_converter(status);
4143 static bool net_nfc_nxp_controller_llcp_connect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t service_access_point, net_nfc_error_e *result, void *user_param)
4145 phLibNfc_Handle hRemoteDevice;
4146 NFCSTATUS status = NFCSTATUS_SUCCESS;
4155 *result = NET_NFC_NULL_PARAMETER;
4159 if (!__net_nfc_is_valid_target_handle(handle))
4161 *result = NET_NFC_INVALID_HANDLE;
4165 hRemoteDevice = handle->connection_id;
4167 NET_NFC_OEM_CONTROLLER_LOCK;
4168 status = phLibNfc_Llcp_Connect(hRemoteDevice,
4170 service_access_point,
4171 _net_nfc_llcp_connect_sap_cb,
4174 DEBUG_MSG("llcp connect operation results = [0x%x]", status);
4176 NET_NFC_OEM_CONTROLLER_UNLOCK;
4178 *result = _net_nfc_nxp_error_converter(status);
4180 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
4182 DEBUG_MSG("operation socket connecting is failed = [0x%x]", status);
4190 static bool net_nfc_nxp_controller_llcp_connect_by_url(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, uint8_t *service_access_name, net_nfc_error_e *result, void *user_param)
4192 phLibNfc_Handle hRemoteDevice;
4193 NFCSTATUS status = NFCSTATUS_SUCCESS;
4202 *result = NET_NFC_NULL_PARAMETER;
4206 if (!__net_nfc_is_valid_target_handle(handle))
4208 *result = NET_NFC_INVALID_HANDLE;
4212 hRemoteDevice = handle->connection_id;
4214 if (service_access_name == NULL)
4219 phNfc_sData_t service_name = { service_access_name, strlen((char *)service_access_name) };
4221 NET_NFC_OEM_CONTROLLER_LOCK;
4223 DEBUG_MSG("socket = [0x%x] and service name [%s]", socket, service_access_name);
4225 status = phLibNfc_Llcp_ConnectByUri(hRemoteDevice,
4227 (phNfc_sData_t *)&service_name,
4228 _net_nfc_llcp_connect_cb,
4231 DEBUG_MSG("llcp connect by url operation result = [0x%x]", status);
4233 NET_NFC_OEM_CONTROLLER_UNLOCK;
4235 *result = _net_nfc_nxp_error_converter(status);
4237 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
4239 DEBUG_MSG("operation socket connecting is failed = [0x%x]", status);
4246 static bool net_nfc_nxp_controller_llcp_send(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param)
4248 transfer_context_s *trans_context = NULL;
4249 phLibNfc_Handle hRemoteDevice;
4250 NFCSTATUS status = NFCSTATUS_SUCCESS;
4259 *result = NET_NFC_NULL_PARAMETER;
4263 //socket_info_s *psocket_info = _net_nfc_find_server_socket(socket);
4264 //net_nfc_llcp_socket_t real_socket;
4266 /*if (psocket_info == NULL ) {
4267 *result = NET_NFC_LLCP_INVALID_SOCKET;
4271 /*if (psocket_info->socket_handle_incomming == 0){
4272 real_socket = socket;
4275 real_socket = psocket_info->socket_handle_incomming;
4278 /* this context and data copy is requried because the data comes from parameter will be freed after this functions */
4279 _net_nfc_util_alloc_mem(trans_context, sizeof(transfer_context_s));
4280 if (trans_context == NULL)
4282 *result = NET_NFC_ALLOC_FAIL;
4286 _net_nfc_util_alloc_mem(trans_context->data.buffer, data->length);
4287 if (trans_context->data.buffer == NULL)
4289 _net_nfc_util_free_mem(trans_context);
4290 *result = NET_NFC_ALLOC_FAIL;
4294 memcpy(trans_context->data.buffer, data->buffer, data->length);
4295 trans_context->data.length = data->length;
4297 trans_context->user_param = user_param;
4298 trans_context->oal_socket = socket;
4299 /* -- data copy is finished -- */
4301 hRemoteDevice = handle->connection_id;
4303 NET_NFC_OEM_CONTROLLER_LOCK;
4305 status = phLibNfc_Llcp_Send(hRemoteDevice, socket, (phNfc_sData_t *)&(trans_context->data), _net_nfc_llcp_send_cb, trans_context);
4307 DEBUG_MSG("llcp send operation result = [0x%x]", status);
4309 NET_NFC_OEM_CONTROLLER_UNLOCK;
4311 *result = _net_nfc_nxp_error_converter(status);
4312 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
4314 DEBUG_MSG("operation phLibNfc_Llcp_Send is failed = [0x%x]", status);
4321 static bool net_nfc_nxp_controller_llcp_send_to(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, uint8_t service_access_point, net_nfc_error_e *result, void *user_param)
4323 transfer_context_s *trans_context = NULL;
4324 phLibNfc_Handle hRemoteDevice;
4325 NFCSTATUS status = NFCSTATUS_SUCCESS;
4334 *result = NET_NFC_NULL_PARAMETER;
4338 if (!__net_nfc_is_valid_target_handle(handle))
4340 *result = NET_NFC_INVALID_HANDLE;
4344 /* this context and data copy is requried because the data comes from parameter will be freed after this functions */
4345 _net_nfc_util_alloc_mem(trans_context, sizeof(transfer_context_s));
4346 if (trans_context == NULL)
4348 *result = NET_NFC_ALLOC_FAIL;
4352 _net_nfc_util_alloc_mem(trans_context->data.buffer, data->length);
4353 if (trans_context->data.buffer == NULL)
4355 _net_nfc_util_free_mem(trans_context);
4356 *result = NET_NFC_ALLOC_FAIL;
4359 memcpy(trans_context->data.buffer, data->buffer, data->length);
4360 trans_context->data.length = data->length;
4362 trans_context->user_param = user_param;
4363 trans_context->oal_socket = socket;
4364 /* -- data copy is finished -- */
4366 hRemoteDevice = handle->connection_id;
4368 NET_NFC_OEM_CONTROLLER_LOCK;
4370 status = phLibNfc_Llcp_SendTo(hRemoteDevice, socket, service_access_point, (phNfc_sData_t *)&(trans_context->data), _net_nfc_llcp_sendTo_cb, trans_context);
4372 DEBUG_MSG("llcp send to operation result = [0x%x]", status);
4374 NET_NFC_OEM_CONTROLLER_UNLOCK;
4376 *result = _net_nfc_nxp_error_converter(status);
4378 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
4380 DEBUG_MSG("operation phLibNfc_Llcp_SendTo is failed = [0x%x]", status);
4387 static bool net_nfc_nxp_controller_llcp_recv(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param)
4389 phLibNfc_Handle hRemoteDevice;
4390 NFCSTATUS status = NFCSTATUS_SUCCESS;
4397 if (handle == NULL || data == NULL)
4399 *result = NET_NFC_NULL_PARAMETER;
4403 if (!__net_nfc_is_valid_target_handle(handle))
4405 *result = NET_NFC_INVALID_HANDLE;
4409 *result = NET_NFC_OK;
4411 hRemoteDevice = handle->connection_id;
4413 /*socket_info_s *psocket_info = _net_nfc_find_server_socket(socket);
4414 //net_nfc_llcp_socket_t real_socket;
4416 if (psocket_info == NULL) {
4417 *result = NET_NFC_LLCP_INVALID_SOCKET;
4421 /*if (psocket_info->socket_handle_incomming == 0){
4422 real_socket = socket;
4425 real_socket = psocket_info->socket_handle_incomming;
4428 NET_NFC_OEM_CONTROLLER_LOCK;
4430 status = phLibNfc_Llcp_Recv(hRemoteDevice,
4432 (phNfc_sData_t *)data,
4433 _net_nfc_llcp_recv_cb,
4436 DEBUG_MSG("llcp recv operation result = [0x%x]", status);
4438 NET_NFC_OEM_CONTROLLER_UNLOCK;
4440 *result = _net_nfc_nxp_error_converter(status);
4442 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
4444 DEBUG_MSG("operation phLibNfc_Llcp_Recv is failed = [0x%x]", status);
4451 static bool net_nfc_nxp_controller_llcp_recv_from(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, data_s *data, net_nfc_error_e *result, void *user_param)
4453 NFCSTATUS status = NFCSTATUS_SUCCESS;
4460 if (handle == NULL || data == NULL)
4462 *result = NET_NFC_NULL_PARAMETER;
4465 if (!__net_nfc_is_valid_target_handle(handle))
4467 *result = NET_NFC_INVALID_HANDLE;
4471 *result = NET_NFC_OK;
4473 NET_NFC_OEM_CONTROLLER_LOCK;
4475 status = phLibNfc_Llcp_RecvFrom(handle->connection_id, socket,
4476 (phNfc_sData_t *)data,
4477 _net_nfc_llcp_recv_from_cb,
4480 DEBUG_MSG("llcp recv from operation result = [0x%x]", status);
4482 NET_NFC_OEM_CONTROLLER_UNLOCK;
4484 *result = _net_nfc_nxp_error_converter(status);
4486 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
4488 DEBUG_MSG("operation phLibNfc_Llcp_Recv is failed = [0x%x]", status);
4495 static bool net_nfc_nxp_controller_llcp_disconnect(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result, void *user_param)
4497 phLibNfc_Handle hRemoteDevice;
4498 NFCSTATUS status = NFCSTATUS_SUCCESS;
4507 *result = NET_NFC_NULL_PARAMETER;
4511 if (!__net_nfc_is_valid_target_handle(handle))
4513 *result = NET_NFC_INVALID_HANDLE;
4517 /*socket_info_s *psocket_info = _net_nfc_find_server_socket(socket);
4518 //net_nfc_llcp_socket_t real_socket;
4520 if (psocket_info == NULL) {
4521 *result = NET_NFC_LLCP_INVALID_SOCKET;
4525 /*if (psocket_info->socket_handle_incomming == 0){
4526 real_socket = socket;
4529 real_socket = psocket_info->socket_handle_incomming;
4532 *result = NET_NFC_OK;
4534 hRemoteDevice = handle->connection_id;
4536 NET_NFC_OEM_CONTROLLER_LOCK;
4538 DEBUG_MSG("disconnect socket = [0x%x]", socket);
4540 status = phLibNfc_Llcp_Disconnect(hRemoteDevice, socket,
4541 _net_nfc_llcp_disconnect_cb,
4544 DEBUG_MSG("llcp disconnect operation result = [0x%x]", status);
4546 NET_NFC_OEM_CONTROLLER_UNLOCK;
4548 *result = _net_nfc_nxp_error_converter(status);
4550 if (status != NFCSTATUS_SUCCESS && status != NFCSTATUS_PENDING)
4552 DEBUG_MSG("operation net_nfc_nxp_controller_llcp_disconnect is failed = [0x%x]", status);
4559 static bool net_nfc_nxp_controller_llcp_socket_close(net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
4561 NFCSTATUS status = NFCSTATUS_SUCCESS;
4562 // net_nfc_llcp_socket_t incomming_socket ;
4564 DEBUG_MSG("try to close socket = [0x%x]", socket);
4566 /*socket_info_s *psocket_info = _net_nfc_find_server_socket(socket);
4568 if (psocket_info == NULL) {
4569 *result = NET_NFC_LLCP_INVALID_SOCKET;
4573 //incomming_socket = psocket_info->socket_handle_incomming;
4574 _net_nfc_remove_socket_slot(socket);
4576 /*if (incomming_socket != 0){
4577 NET_NFC_OEM_CONTROLLER_LOCK;
4578 status = phLibNfc_Llcp_Close(incomming_socket);
4579 NET_NFC_OEM_CONTROLLER_UNLOCK;
4582 NET_NFC_OEM_CONTROLLER_LOCK;
4583 status = phLibNfc_Llcp_Close(socket);
4584 NET_NFC_OEM_CONTROLLER_UNLOCK;
4586 *result = _net_nfc_nxp_error_converter(status);
4588 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
4590 DEBUG_MSG("closing socket is good");
4595 DEBUG_MSG("closing socket is failed = [0x%x]", status);
4600 static bool net_nfc_nxp_controller_llcp_reject(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_error_e *result)
4602 phLibNfc_Handle hRemoteDevice;
4603 NFCSTATUS status = NFCSTATUS_SUCCESS;
4605 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
4606 controller_context_s context = { &controller_cond, NULL, 0 };
4615 *result = NET_NFC_NULL_PARAMETER;
4619 if (!__net_nfc_is_valid_target_handle(handle))
4621 *result = NET_NFC_INVALID_HANDLE;
4625 *result = NET_NFC_OK;
4627 /*socket_info_s *psocket_info = _net_nfc_find_server_socket(socket);
4628 if (psocket_info == NULL) {
4629 *result = NET_NFC_LLCP_INVALID_SOCKET;
4633 hRemoteDevice = handle->connection_id;
4635 NET_NFC_OEM_CONTROLLER_LOCK;
4637 DEBUG_MSG("reject socket = [0x%x]", socket);
4639 status = phLibNfc_Llcp_Reject(hRemoteDevice, socket,
4640 _net_nfc_llcp_reject_cb,
4643 DEBUG_MSG("llcp disconnect operation result = [0x%x]", status);
4645 if (status == NFCSTATUS_SUCCESS || status == NFCSTATUS_PENDING)
4648 if (status == NFCSTATUS_PENDING)
4650 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
4653 NET_NFC_OEM_CONTROLLER_UNLOCK;
4655 if (context.result != NFCSTATUS_SUCCESS)
4657 DEBUG_MSG("llcp socket reject is failed = [0x%x]", context.result);
4658 *result = _net_nfc_nxp_error_converter(context.result);
4664 DEBUG_MSG("operation socket reject by llcp is failed = [0x%x]", status);
4666 NET_NFC_OEM_CONTROLLER_UNLOCK;
4668 *result = _net_nfc_nxp_error_converter(status);
4675 static bool net_nfc_nxp_controller_llcp_get_remote_config(net_nfc_target_handle_s *handle, net_nfc_llcp_config_info_s *config, net_nfc_error_e *result)
4677 phLibNfc_Handle hRemoteDevice;
4678 phLibNfc_Llcp_sLinkParameters_t info;
4680 NFCSTATUS status = NFCSTATUS_SUCCESS;
4687 if (handle == NULL || config == NULL)
4689 *result = NET_NFC_NULL_PARAMETER;
4693 if (!__net_nfc_is_valid_target_handle(handle))
4695 *result = NET_NFC_INVALID_HANDLE;
4699 *result = NET_NFC_OK;
4701 hRemoteDevice = handle->connection_id;
4703 NET_NFC_OEM_CONTROLLER_LOCK;
4705 DEBUG_MSG("get remote info..");
4707 status = phLibNfc_Llcp_GetRemoteInfo(hRemoteDevice, &info);
4709 DEBUG_MSG("llcp get remote info operation result = [0x%x]", status);
4711 NET_NFC_OEM_CONTROLLER_UNLOCK;
4713 if (status != NFCSTATUS_SUCCESS)
4715 DEBUG_MSG("operation getinfo by llcp is failed = [0x%x]", status);
4716 *result = _net_nfc_nxp_error_converter(status);
4720 config->lto = info.lto;
4721 config->miu = info.miu;
4722 config->option = info.option;
4723 config->wks = info.wks;
4729 static bool net_nfc_nxp_controller_llcp_get_remote_socket_info(net_nfc_target_handle_s *handle, net_nfc_llcp_socket_t socket, net_nfc_llcp_socket_option_s *option, net_nfc_error_e *result)
4731 NFCSTATUS status = NFCSTATUS_SUCCESS;
4732 phLibNfc_Llcp_sSocketOptions_t psRemoteOptions;
4739 if (handle == NULL || option == NULL)
4741 *result = NET_NFC_NULL_PARAMETER;
4745 if (!__net_nfc_is_valid_target_handle(handle))
4747 *result = NET_NFC_INVALID_HANDLE;
4751 //socket_info_s *psocket_info = _net_nfc_find_server_socket(socket);
4752 //net_nfc_llcp_socket_t real_socket;
4754 /*if (psocket_info == NULL ) {
4755 *result = NET_NFC_LLCP_INVALID_SOCKET;
4759 if (psocket_info->socket_handle_incomming == 0){
4760 real_socket = socket;
4763 real_socket = psocket_info->socket_handle_incomming;
4766 NET_NFC_OEM_CONTROLLER_LOCK;
4767 status = phLibNfc_Llcp_SocketGetRemoteOptions(handle->connection_id, socket, &psRemoteOptions);
4768 NET_NFC_OEM_CONTROLLER_UNLOCK;
4770 if (status != NFCSTATUS_SUCCESS)
4772 DEBUG_MSG("operation getting socket info is failed = [0x%x]", status);
4773 *result = _net_nfc_nxp_error_converter(status);
4777 option->miu = psRemoteOptions.miu;
4778 option->rw = psRemoteOptions.rw;
4779 option->type = NET_NFC_LLCP_SOCKET_TYPE_CONNECTIONORIENTED;
4785 static void net_nfc_nxp_controller_print_tag_info(phNfc_uRemoteDevInfo_t *devInfo, phNfc_eRemDevType_t RemDevType)
4789 case phNfc_eISO14443_A_PICC :
4790 case phNfc_eISO14443_4A_PICC :
4791 case phNfc_eISO14443_3A_PICC :
4792 case phNfc_eMifare_PICC :
4794 phNfc_sIso14443AInfo_t* info = (phNfc_sIso14443AInfo_t *)(devInfo);
4796 DEBUG_MSG("ISO14443 UID : ");
4797 DEBUG_MSG("\tUID : ");
4798 DEBUG_MSG_PRINT_BUFFER(info->Uid, info->UidLength);
4800 DEBUG_MSG("\tAppData");
4801 DEBUG_MSG_PRINT_BUFFER(info->AppData, info->AppDataLength);
4803 DEBUG_MSG("\tSak = [0x%x]", info->Sak);
4805 DEBUG_MSG("\tAtqA");
4806 DEBUG_MSG_PRINT_BUFFER(info->AtqA, PHHAL_ATQA_LENGTH);
4808 DEBUG_MSG("\tMaxDataRate = [0x%x]", info->MaxDataRate);
4810 DEBUG_MSG("\tFwi_Sfgt = [0x%x]", info->Fwi_Sfgt);
4815 case phNfc_eISO14443_B_PICC :
4816 case phNfc_eISO14443_4B_PICC :
4817 case phNfc_eISO14443_BPrime_PICC :
4822 case phNfc_eFelica_PICC :
4826 case phNfc_eJewel_PICC :
4830 case phNfc_eISO15693_PICC :
4835 case phNfc_eNfcIP1_Target :
4836 case phNfc_eNfcIP1_Initiator :
4847 static int net_nfc_nxp_controller_tag_device_info(phNfc_uRemoteDevInfo_t *devInfo, phNfc_eRemDevType_t RemDevType, uint8_t **buffer, uint32_t *buffer_length)
4849 int number_of_keys = 0;
4853 case phNfc_eISO14443_A_PICC :
4854 case phNfc_eISO14443_4A_PICC :
4855 case phNfc_eISO14443_3A_PICC :
4856 case phNfc_eMifare_PICC :
4858 net_nfc_nxp_controller_device_info_ISO14443A(devInfo, buffer, buffer_length);
4859 number_of_keys = KEYS_ISO14443A_MAX;
4863 case phNfc_eISO14443_B_PICC :
4864 case phNfc_eISO14443_4B_PICC :
4865 case phNfc_eISO14443_BPrime_PICC :
4867 net_nfc_nxp_controller_device_info_ISO14443B(devInfo, buffer, buffer_length);
4868 number_of_keys = KEYS_ISO14443B_MAX;
4872 case phNfc_eFelica_PICC :
4874 net_nfc_nxp_controller_device_info_Felica(devInfo, buffer, buffer_length);
4875 number_of_keys = KEYS_FELICA_MAX;
4878 case phNfc_eJewel_PICC :
4880 net_nfc_nxp_controller_device_info_Jewel(devInfo, buffer, buffer_length);
4881 number_of_keys = KEYS_JEWEL_MAX;
4884 case phNfc_eISO15693_PICC :
4886 net_nfc_nxp_controller_device_info_ISO15693(devInfo, buffer, buffer_length);
4887 number_of_keys = KEYS_ISO15693_MAX;
4891 case phNfc_eNfcIP1_Target :
4892 case phNfc_eNfcIP1_Initiator :
4894 net_nfc_nxp_controller_device_info_NFCIP(devInfo, buffer, buffer_length);
4895 number_of_keys = KEYS_NFCIP_MAX;
4903 return number_of_keys;
4906 static void net_nfc_nxp_controller_device_info_ISO14443A(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length)
4908 phNfc_sIso14443AInfo_t *info = (phNfc_sIso14443AInfo_t *)(devInfo);
4910 /* key_name: UID APP_DATA SAK ATQA MAX_DATA_RATE FWI_SFGT*/
4911 // *buffer_length = strlen(keys_ISO14443A) + info->UidLength + info->AppDataLength + sizeof(uint8_t) + PHHAL_ATQA_LENGTH + sizeof(uint8_t) + sizeof(uint8_t) ;
4912 *buffer_length = strlen(keys_ISO14443A) + KEYS_ISO14443A_MAX + info->UidLength + info->AppDataLength + sizeof(uint8_t) + PHHAL_ATQA_LENGTH + sizeof(uint8_t) + sizeof(uint8_t);
4914 _net_nfc_util_alloc_mem(*buffer, *buffer_length);
4915 if (*buffer != NULL)
4917 uint8_t *pBuffer = *buffer;
4923 key_length = strlen("UID");
4924 *pBuffer = (uint8_t)key_length;
4925 pBuffer = pBuffer + 1;
4928 memcpy(pBuffer, "UID", key_length);
4929 pBuffer = pBuffer + key_length;
4932 *pBuffer = (uint8_t)info->UidLength;
4933 pBuffer = pBuffer + 1;
4936 if (info->UidLength > 0)
4938 memcpy(pBuffer, info->Uid, info->UidLength);
4939 pBuffer = pBuffer + info->UidLength;
4944 key_length = strlen("APP_DATA");
4945 *pBuffer = (uint8_t)key_length;
4946 pBuffer = pBuffer + 1;
4949 memcpy(pBuffer, "APP_DATA", key_length);
4950 pBuffer = pBuffer + key_length;
4953 *pBuffer = (uint8_t)info->AppDataLength;
4954 pBuffer = pBuffer + 1;
4956 if (info->AppDataLength != 0)
4958 memcpy(pBuffer, info->AppData, info->AppDataLength);
4959 pBuffer = pBuffer + info->AppDataLength;
4964 key_length = strlen("SAK");
4965 *pBuffer = (uint8_t)key_length;
4966 pBuffer = pBuffer + 1;
4968 memcpy(pBuffer, "SAK", key_length);
4969 pBuffer = pBuffer + key_length;
4972 *pBuffer = (uint8_t)sizeof(uint8_t);
4973 pBuffer = pBuffer + 1;
4976 *pBuffer = info->Sak;
4977 pBuffer = pBuffer + sizeof(uint8_t);
4979 DEBUG_MSG("MIFARE SAK = [0x%x]", info->Sak);
4983 key_length = strlen("ATQA");
4984 *pBuffer = (uint8_t)key_length;
4985 pBuffer = pBuffer + 1;
4988 memcpy(pBuffer, "ATQA", key_length);
4989 pBuffer = pBuffer + key_length;
4992 *pBuffer = (uint8_t)PHHAL_ATQA_LENGTH;
4993 pBuffer = pBuffer + 1;
4996 memcpy(pBuffer, info->AtqA, PHHAL_ATQA_LENGTH);
4997 pBuffer = pBuffer + PHHAL_ATQA_LENGTH;
5001 key_length = strlen("MAX_DATA_RATE");
5002 *pBuffer = (uint8_t)key_length;
5003 pBuffer = pBuffer + 1;
5006 memcpy(pBuffer, "MAX_DATA_RATE", key_length);
5007 pBuffer = pBuffer + key_length;
5010 *pBuffer = (uint8_t)sizeof(uint8_t);
5011 pBuffer = pBuffer + 1;
5014 *pBuffer = info->MaxDataRate;
5015 pBuffer = pBuffer + sizeof(uint8_t);
5019 key_length = strlen("FWI_SFGT");
5020 *pBuffer = (uint8_t)key_length;
5021 pBuffer = pBuffer + 1;
5024 memcpy(pBuffer, "FWI_SFGT", key_length);
5025 pBuffer = pBuffer + key_length;
5028 *pBuffer = (uint8_t)sizeof(uint8_t);
5029 pBuffer = pBuffer + 1;
5032 *pBuffer = info->Fwi_Sfgt;
5036 static void net_nfc_nxp_controller_device_info_ISO14443B(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length)
5038 phNfc_sIso14443BInfo_t *info = (phNfc_sIso14443BInfo_t *)(devInfo);
5040 /* key length key_name value length (1byte) UID APP_DATA PROTOCOL_INFO HI_LAYER_RESPONSE AFI MAX_DATA_RATE*/
5041 *buffer_length = strlen(keys_ISO14443B) + KEYS_ISO14443B_MAX + NET_NFC_PUPI_LENGTH + NET_NFC_APP_DATA_B_LENGTH + NET_NFC_PROT_INFO_B_LENGTH + info->HiLayerRespLength + sizeof(uint8_t) + sizeof(uint8_t);
5043 _net_nfc_util_alloc_mem(*buffer, *buffer_length);
5044 if (*buffer != NULL)
5046 uint8_t *pBuffer = *buffer;
5052 key_length = strlen("UID");
5053 *pBuffer = (uint8_t)key_length;
5054 pBuffer = pBuffer + 1;
5057 memcpy(pBuffer, "UID", key_length);
5058 pBuffer = pBuffer + key_length;
5061 *pBuffer = NET_NFC_PUPI_LENGTH;
5062 pBuffer = pBuffer + 1;
5065 memcpy(pBuffer, info->AtqB.AtqResInfo.Pupi, NET_NFC_PUPI_LENGTH);
5066 pBuffer = pBuffer + NET_NFC_PUPI_LENGTH;
5071 key_length = strlen("APP_DATA");
5072 *pBuffer = (uint8_t)key_length;
5073 pBuffer = pBuffer + 1;
5076 memcpy(pBuffer, "APP_DATA", key_length);
5077 pBuffer = pBuffer + key_length;
5080 *pBuffer = NET_NFC_APP_DATA_B_LENGTH;
5081 pBuffer = pBuffer + 1;
5084 memcpy(pBuffer, info->AtqB.AtqResInfo.AppData, NET_NFC_APP_DATA_B_LENGTH);
5085 pBuffer = pBuffer + NET_NFC_APP_DATA_B_LENGTH;
5090 key_length = strlen("PROTOCOL_INFO");
5091 *pBuffer = (uint8_t)key_length;
5092 pBuffer = pBuffer + 1;
5095 memcpy(pBuffer, "PROTOCOL_INFO", key_length);
5096 pBuffer = pBuffer + key_length;
5099 *pBuffer = NET_NFC_PROT_INFO_B_LENGTH;
5100 pBuffer = pBuffer + 1;
5103 memcpy(pBuffer, info->AtqB.AtqResInfo.ProtInfo, NET_NFC_PROT_INFO_B_LENGTH);
5104 pBuffer = pBuffer + NET_NFC_PROT_INFO_B_LENGTH;
5106 // HI_LAYER_RESPONSE
5109 key_length = strlen("HI_LAYER_RESPONSE");
5110 *pBuffer = (uint8_t)key_length;
5111 pBuffer = pBuffer + 1;
5114 memcpy(pBuffer, "HI_LAYER_RESPONSE", key_length);
5115 pBuffer = pBuffer + key_length;
5118 *pBuffer = info->HiLayerRespLength;
5119 pBuffer = pBuffer + 1;
5122 if (info->HiLayerRespLength > 0)
5124 memcpy(pBuffer, info->HiLayerResp, info->HiLayerRespLength);
5125 pBuffer = pBuffer + info->HiLayerRespLength;
5131 key_length = strlen("AFI");
5132 *pBuffer = (uint8_t)key_length;
5133 pBuffer = pBuffer + 1;
5136 memcpy(pBuffer, "AFI", key_length);
5137 pBuffer = pBuffer + key_length;
5140 *pBuffer = sizeof(uint8_t);
5141 pBuffer = pBuffer + 1;
5144 *pBuffer = info->Afi;
5145 pBuffer = pBuffer + sizeof(uint8_t);
5150 key_length = strlen("MAX_DATA_RATE");
5151 *pBuffer = (uint8_t)key_length;
5152 pBuffer = pBuffer + 1;
5155 memcpy(pBuffer, "MAX_DATA_RATE", key_length);
5156 pBuffer = pBuffer + key_length;
5159 *pBuffer = sizeof(uint8_t);
5160 pBuffer = pBuffer + 1;
5163 *pBuffer = info->MaxDataRate;
5167 static void net_nfc_nxp_controller_device_info_Jewel(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length)
5169 phNfc_sJewelInfo_t *info = (phNfc_sJewelInfo_t *)(devInfo);
5171 /* key_length key_name length (1byte) UID HEADER_ROM0 HEADER_ROM1 */
5172 *buffer_length = strlen(keys_JEWEL) + KEYS_JEWEL_MAX + info->UidLength + sizeof(uint8_t) + sizeof(uint8_t);
5174 _net_nfc_util_alloc_mem(*buffer, *buffer_length);
5175 if (*buffer != NULL)
5177 uint8_t *pBuffer = *buffer;
5183 key_length = strlen("UID");
5184 *pBuffer = (uint8_t)key_length;
5185 pBuffer = pBuffer + 1;
5188 memcpy(pBuffer, "UID", key_length);
5189 pBuffer = pBuffer + key_length;
5192 *pBuffer = info->UidLength;
5193 pBuffer = pBuffer + 1;
5196 if (info->UidLength > 0)
5198 memcpy(pBuffer, info->Uid, info->UidLength);
5199 pBuffer = pBuffer + info->UidLength;
5205 key_length = strlen("HEADER_ROM0");
5206 *pBuffer = (uint8_t)key_length;
5207 pBuffer = pBuffer + 1;
5210 memcpy(pBuffer, "HEADER_ROM0", key_length);
5211 pBuffer = pBuffer + key_length;
5214 *pBuffer = sizeof(uint8_t);
5215 pBuffer = pBuffer + 1;
5218 *pBuffer = info->HeaderRom0;
5219 pBuffer = pBuffer + sizeof(uint8_t);
5224 key_length = strlen("HEADER_ROM1");
5225 *pBuffer = (uint8_t)key_length;
5226 pBuffer = pBuffer + 1;
5229 memcpy(pBuffer, "HEADER_ROM1", key_length);
5230 pBuffer = pBuffer + key_length;
5233 *pBuffer = sizeof(uint8_t);
5234 pBuffer = pBuffer + 1;
5237 *pBuffer = info->HeaderRom1;
5239 DEBUG_MSG("header rom 0 = [0x%X] header rom 1 = [0x%X]", info->HeaderRom0, info->HeaderRom1);
5243 static void net_nfc_nxp_controller_device_info_Felica(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length)
5245 phNfc_sFelicaInfo_t *info = (phNfc_sFelicaInfo_t *)(devInfo);
5247 /* key length key name length (1byte) UID PM SYSTEM_CODE */
5248 *buffer_length = strlen(keys_FELICA) + KEYS_FELICA_MAX + info->IDmLength + NET_NFC_FEL_PM_LEN + NET_NFC_FEL_SYS_CODE_LEN;
5250 _net_nfc_util_alloc_mem(*buffer, *buffer_length);
5251 if (*buffer != NULL)
5253 uint8_t *pBuffer = *buffer;
5259 key_length = strlen("IDm");
5260 *pBuffer = (uint8_t)key_length;
5261 pBuffer = pBuffer + 1;
5264 memcpy(pBuffer, "IDm", key_length);
5265 pBuffer = pBuffer + key_length;
5268 *pBuffer = info->IDmLength;
5269 pBuffer = pBuffer + 1;
5272 if (info->IDmLength > 0)
5274 memcpy(pBuffer, info->IDm, info->IDmLength);
5275 pBuffer = pBuffer + info->IDmLength;
5281 key_length = strlen("PMm");
5282 *pBuffer = (uint8_t)key_length;
5283 pBuffer = pBuffer + 1;
5286 memcpy(pBuffer, "PMm", key_length);
5287 pBuffer = pBuffer + key_length;
5290 *pBuffer = NET_NFC_FEL_PM_LEN;
5291 pBuffer = pBuffer + 1;
5294 memcpy(pBuffer, info->PMm, NET_NFC_FEL_PM_LEN);
5295 pBuffer = pBuffer + NET_NFC_FEL_PM_LEN;
5300 key_length = strlen("SYSTEM_CODE");
5301 *pBuffer = (uint8_t)key_length;
5302 pBuffer = pBuffer + 1;
5305 memcpy(pBuffer, "SYSTEM_CODE", key_length);
5306 pBuffer = pBuffer + key_length;
5309 *pBuffer = NET_NFC_FEL_SYS_CODE_LEN;
5310 pBuffer = pBuffer + 1;
5313 memcpy(pBuffer, info->SystemCode, NET_NFC_FEL_SYS_CODE_LEN);
5317 static void net_nfc_nxp_controller_device_info_ISO15693(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length)
5319 phNfc_sIso15693Info_t *info = (phNfc_sIso15693Info_t *)(devInfo);
5321 /* key length key_name length (1byte) UID DSF_ID FLAGS AFI */
5322 *buffer_length = strlen(keys_ISO15693) + KEYS_ISO15693_MAX + info->UidLength + sizeof(uint8_t) + sizeof(uint8_t) + sizeof(uint8_t);
5324 _net_nfc_util_alloc_mem(*buffer, *buffer_length);
5325 if (*buffer != NULL)
5327 uint8_t *pBuffer = *buffer;
5333 key_length = strlen("UID");
5334 *pBuffer = (uint8_t)key_length;
5335 pBuffer = pBuffer + 1;
5338 memcpy(pBuffer, "UID", key_length);
5339 pBuffer = pBuffer + key_length;
5342 *pBuffer = info->UidLength;
5343 pBuffer = pBuffer + 1;
5346 if (info->UidLength > 0)
5348 memcpy(pBuffer, info->Uid, info->UidLength);
5349 pBuffer = pBuffer + info->UidLength;
5355 key_length = strlen("DSF_ID");
5356 *pBuffer = (uint8_t)key_length;
5357 pBuffer = pBuffer + 1;
5360 memcpy(pBuffer, "DSF_ID", key_length);
5361 pBuffer = pBuffer + key_length;
5364 *pBuffer = sizeof(uint8_t);
5365 pBuffer = pBuffer + 1;
5368 *pBuffer = info->Dsfid;
5369 pBuffer = pBuffer + sizeof(uint8_t);
5374 key_length = strlen("FLAGS");
5375 *pBuffer = (uint8_t)key_length;
5376 pBuffer = pBuffer + 1;
5379 memcpy(pBuffer, "FLAGS", key_length);
5380 pBuffer = pBuffer + key_length;
5383 *pBuffer = sizeof(uint8_t);
5384 pBuffer = pBuffer + 1;
5388 *pBuffer = info->Flags;
5389 pBuffer = pBuffer + sizeof(uint8_t);
5394 key_length = strlen("AFI");
5395 *pBuffer = (uint8_t)key_length;
5396 pBuffer = pBuffer + 1;
5399 memcpy(pBuffer, "AFI", key_length);
5400 pBuffer = pBuffer + key_length;
5403 *pBuffer = sizeof(uint8_t);
5404 pBuffer = pBuffer + 1;
5407 *pBuffer = info->Afi;
5411 static void net_nfc_nxp_controller_device_info_NFCIP(phNfc_uRemoteDevInfo_t *devInfo, uint8_t **buffer, uint32_t *buffer_length)
5413 phNfc_sNfcIPInfo_t *info = (phNfc_sNfcIPInfo_t *)(devInfo);
5415 /* key length key_name length (1byte) UID ATR_INFORMATION SAK ATQA MAX_DATA_RATE */
5416 *buffer_length = strlen(keys_NFCIP) + KEYS_NFCIP_MAX + info->NFCID_Length + info->ATRInfo_Length + sizeof(uint8_t) + NET_NFC_ATQA_LENGTH + sizeof(uint16_t);
5418 _net_nfc_util_alloc_mem(*buffer, *buffer_length);
5419 if (*buffer != NULL)
5421 uint8_t *pBuffer = *buffer;
5427 key_length = strlen("UID");
5428 *pBuffer = (uint8_t)key_length;
5429 pBuffer = pBuffer + 1;
5432 memcpy(pBuffer, "UID", key_length);
5433 pBuffer = pBuffer + key_length;
5436 *pBuffer = info->NFCID_Length;
5437 pBuffer = pBuffer + 1;
5440 if (info->NFCID_Length > 0)
5442 memcpy(pBuffer, info->NFCID, info->NFCID_Length);
5443 pBuffer = pBuffer + info->NFCID_Length;
5449 key_length = strlen("ATR_INFORMATION");
5450 *pBuffer = (uint8_t)key_length;
5451 pBuffer = pBuffer + 1;
5454 memcpy(pBuffer, "ATR_INFORMATION", key_length);
5455 pBuffer = pBuffer + key_length;
5458 *pBuffer = info->ATRInfo_Length;
5459 pBuffer = pBuffer + 1;
5462 if (info->ATRInfo_Length > 0)
5464 memcpy(pBuffer, info->ATRInfo, info->ATRInfo_Length);
5465 pBuffer = pBuffer + info->ATRInfo_Length;
5471 key_length = strlen("SAK");
5472 *pBuffer = (uint8_t)key_length;
5473 pBuffer = pBuffer + 1;
5476 memcpy(pBuffer, "SAK", key_length);
5477 pBuffer = pBuffer + key_length;
5480 *pBuffer = sizeof(uint8_t);
5481 pBuffer = pBuffer + 1;
5484 *pBuffer = info->SelRes;
5485 pBuffer = pBuffer + sizeof(uint8_t);
5490 key_length = strlen("ATQA");
5491 *pBuffer = (uint8_t)key_length;
5492 pBuffer = pBuffer + 1;
5495 memcpy(pBuffer, "ATQA", key_length);
5496 pBuffer = pBuffer + key_length;
5499 *pBuffer = NET_NFC_ATQA_LENGTH;
5500 pBuffer = pBuffer + 1;
5503 memcpy(pBuffer, info->SenseRes, NET_NFC_ATQA_LENGTH);
5504 pBuffer = pBuffer + NET_NFC_ATQA_LENGTH;
5509 key_length = strlen("MAX_DATA_RATE");
5510 *pBuffer = (uint8_t)key_length;
5511 pBuffer = pBuffer + 1;
5514 memcpy(pBuffer, "MAX_DATA_RATE", key_length);
5515 pBuffer = pBuffer + key_length;
5518 *pBuffer = sizeof(uint16_t);
5519 pBuffer = pBuffer + 1;
5522 if (info->Nfcip_Datarate == phNfc_eDataRate_106)
5525 pBuffer = pBuffer + 1;
5529 else if (info->Nfcip_Datarate == phNfc_eDataRate_212)
5532 pBuffer = pBuffer + 1;
5536 else if (info->Nfcip_Datarate == phNfc_eDataRate_424)
5538 *pBuffer = (424 & 0xff00) >> 8;
5539 pBuffer = pBuffer + 1;
5541 *pBuffer = (424 & 0x00ff);
5546 pBuffer = pBuffer + 1;
5553 static bool net_nfc_nxp_controller_test_mode_on(net_nfc_error_e *result)
5556 NFCSTATUS status = NFCSTATUS_SUCCESS;
5557 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
5558 controller_context_s context = { &controller_cond, NULL, 0 };
5565 *result = NET_NFC_OK;
5567 //_net_nfc_nxp_controller_lock_init();
5569 DEBUG_MSG("net_nfc_nxp_controller_test_mode_on \n");
5571 phLibNfc_Mgt_UnConfigureDriver(psHwRef.p_board_driver);
5573 DEBUG_MSG("Dal config \n");
5575 if (_net_nfc_dal_config() != true)
5577 DEBUG_MSG("Port config is failed");
5581 NET_NFC_OEM_CONTROLLER_LOCK;
5582 if ((status = phLibNfc_Mgt_ConfigureTestMode(psHwRef.p_board_driver, _net_nfc_test_mode_on_cb, phLibNfc_TstMode_On, (void *)&context)) != NFCSTATUS_PENDING)
5584 NET_NFC_OEM_CONTROLLER_UNLOCK;
5585 DEBUG_MSG("net_nfc_nxp_controller_test_mode_on is failed = [0x%x] \n", status);
5591 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
5592 NET_NFC_OEM_CONTROLLER_UNLOCK;
5594 DEBUG_MSG("net_nfc_nxp_controller_test_mode_on is in progress");
5596 if (context.result != NFCSTATUS_SUCCESS)
5598 DEBUG_MSG("net_nfc_nxp_controller_test_mode_onis failed = [0x%x] \n", context.result);
5604 DEBUG_MSG("net_nfc_nxp_controller_test_mode_on finished");
5609 static bool net_nfc_nxp_controller_test_mode_off(net_nfc_error_e *result)
5612 NFCSTATUS status = NFCSTATUS_SUCCESS;
5613 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
5614 controller_context_s context = { &controller_cond, NULL, 0 };
5621 *result = NET_NFC_OK;
5623 DEBUG_MSG("net_nfc_nxp_controller_test_mode_off \n");
5625 NET_NFC_OEM_CONTROLLER_LOCK;
5626 if ((status = phLibNfc_Mgt_ConfigureTestMode(psHwRef.p_board_driver, _net_nfc_test_mode_off_cb, phLibNfc_TstMode_Off, (void *)&context)) != NFCSTATUS_PENDING)
5628 NET_NFC_OEM_CONTROLLER_UNLOCK;
5629 DEBUG_MSG("phLibNfc_Mgt_ConfigureTestMode off is failed = [0x%x] \n", status);
5635 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
5636 NET_NFC_OEM_CONTROLLER_UNLOCK;
5638 DEBUG_MSG("phLibNfc_Mgt_ConfigureTestMode off is in progress");
5640 if (context.result != NFCSTATUS_SUCCESS)
5642 DEBUG_MSG("phLibNfc_Mgt_ConfigureTestMode off is failed = [0x%x] \n", context.result);
5648 DEBUG_MSG("phLibNfc_Mgt_ConfigureTestMode off finished");
5653 static void _net_nfc_test_mode_off_cb(void *pContext, NFCSTATUS status)
5655 controller_context_s *context = NULL;
5657 if (pContext != NULL)
5659 context = (controller_context_s *)pContext;
5660 context->result = (int)status;
5663 if (status == NFCSTATUS_SUCCESS)
5665 DEBUG_MSG("test_mode_off is successful");
5669 DEBUG_MSG("test_mode_off is failed = [0x%x]", status);
5672 if (context != NULL)
5674 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
5678 static void _net_nfc_test_mode_on_cb(void *pContext, NFCSTATUS status)
5680 controller_context_s *context = NULL;
5682 if (pContext != NULL)
5684 context = (controller_context_s *)pContext;
5685 context->result = (int)status;
5688 if (status == NFCSTATUS_SUCCESS)
5690 DEBUG_MSG("test_mode_on is successful");
5694 DEBUG_MSG("test_mode_on is failed = [0x%x]", status);
5697 if (context != NULL)
5699 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
5703 static bool net_nfc_nxp_controller_sim_test(net_nfc_error_e *result)
5705 phNfc_sData_t InParam;
5706 phNfc_sData_t OutParam;
5708 int user_context = 0;
5709 NFCSTATUS status = NFCSTATUS_SUCCESS;
5710 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
5711 controller_context_s context = { &controller_cond, &user_context };
5712 int ret = NFCSTATUS_SUCCESS;
5714 net_nfc_nxp_controller_configure_discovery_stop();
5715 DEBUG_MSG("net_nfc_nxp_controller_configure_discovery_stop out");
5721 DEBUG_MSG("net_nfc_nxp_controller_sim_test Enter");
5723 *result = NET_NFC_OK;
5725 gInputParam.buffer = NULL;
5726 gInputParam.length = 0x00;
5727 gOutputParam.buffer = resp;
5728 gOutputParam.length = 0x02;
5730 NET_NFC_OEM_CONTROLLER_LOCK;
5731 if ((status = phLibNfc_Mgt_IoCtl(psHwRef.p_board_driver, DEVMGMT_SWP_TEST/*PHLIBNFC_SWP_TEST*/, &gInputParam, &gOutputParam, _net_nfc_swp_test_cb, (void *)&context)) != NFCSTATUS_PENDING)
5733 NET_NFC_OEM_CONTROLLER_UNLOCK;
5734 DEBUG_MSG("DEVMGMT_SWP_TEST OEM FAIL [%d]\n" , status);
5739 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
5740 NET_NFC_OEM_CONTROLLER_UNLOCK;
5741 DEBUG_MSG("DEVMGMT_SWP_TEST 1 PASS gOutputParam.buffer[0] = [%d]" , gOutputParam.buffer[0]);
5742 //ret = (gOutputParam.buffer[0] == 0) ? TRUE : FALSE;
5745 DEBUG_MSG("DEVMGMT_SWP_TEST END");
5749 static bool net_nfc_nxp_controller_prbs_test(net_nfc_error_e *result , uint32_t tech , uint32_t rate)
5751 phNfc_sData_t InParam;
5752 phNfc_sData_t OutParam;
5754 uint8_t PRBS_setting[2] = {0x01,0x01}; // PRBS setting
5755 int user_context = 0;
5756 NFCSTATUS status = NFCSTATUS_SUCCESS;
5757 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
5758 controller_context_s context = { &controller_cond, &user_context };
5765 DEBUG_MSG("net_nfc_nxp_controller_prbs_test Enter");
5767 *result = NET_NFC_OK;
5769 PRBS_setting[0] = tech;
5770 PRBS_setting[1] = rate;
5772 gInputParam.buffer = PRBS_setting;
5773 gInputParam.length = 0x02;
5774 gOutputParam.buffer = resp;
5776 DEBUG_MSG("PRBS_setting[0] = [%d]\n" , PRBS_setting[0]);
5777 DEBUG_MSG("PRBS_setting[1] = [%d]\n" , PRBS_setting[1]);
5779 NET_NFC_OEM_CONTROLLER_LOCK;
5780 if ((status = phLibNfc_Mgt_IoCtl(psHwRef.p_board_driver, DEVMGMT_PRBS_TEST/*PHLIBNFC_SWP_TEST*/, &gInputParam, &gOutputParam, _net_nfc_swp_test_cb, (void *)&context)) != NFCSTATUS_PENDING)
5782 NET_NFC_OEM_CONTROLLER_UNLOCK;
5787 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
5788 NET_NFC_OEM_CONTROLLER_UNLOCK;
5789 DEBUG_MSG("DEVMGMT_PRBS_TEST 1 PASS gOutputParam.buffer[0] = [%d]" , gOutputParam.buffer[0]);
5791 if (user_context != NFCSTATUS_SUCCESS)
5793 DEBUG_MSG("DEVMGMT_PRBS_TEST ERROR");
5797 DEBUG_MSG("DEVMGMT_PRBS_TEST End");
5802 static void _net_nfc_swp_test_cb(void *pContext, phNfc_sData_t *Outparam_Cb, NFCSTATUS status)
5804 controller_context_s *context = NULL;
5806 if (pContext != NULL)
5808 context = (controller_context_s *)pContext;
5809 *((int *)context->user_context) = status;
5812 if (status == NFCSTATUS_SUCCESS)
5814 DEBUG_MSG("Callback TEST SUCCESS");
5819 DEBUG_MSG("Callback TEST FAIL [0x%x]\n", status);
5822 if (context != NULL)
5824 NET_NFC_OEM_CONTROLLER_SIGNAL(context->controller_cond);
5828 static bool net_nfc_nxp_controller_configure_discovery_stop()
5830 NFCSTATUS friReturn = NFCSTATUS_SUCCESS;
5831 pthread_cond_t controller_cond = PTHREAD_COND_INITIALIZER;
5832 controller_context_s context = { &controller_cond, NULL, 0 };
5833 phLibNfc_sADD_Cfg_t AddConfig;
5836 AddConfig.PollDevInfo.PollEnabled = 0;
5837 AddConfig.Duration = 300000; /* in ms */
5838 AddConfig.NfcIP_Mode = phNfc_eDefaultP2PMode;
5839 AddConfig.NfcIP_Tgt_Disable = TRUE;
5842 DEBUG_MSG("stop poll loop");
5844 NET_NFC_OEM_CONTROLLER_LOCK;
5846 //__net_nfc_make_invalid_target_handle();
5847 friReturn = phLibNfc_Mgt_ConfigureDiscovery(NFC_DISCOVERY_CONFIG, AddConfig, _net_nfc_configure_discovery_cb, (void *)&context);
5848 if (friReturn != NFCSTATUS_PENDING)
5850 NET_NFC_OEM_CONTROLLER_UNLOCK;
5852 DEBUG_MSG("discovering config is error");
5857 NET_NFC_OEM_CONTROLLER_WAIT(&controller_cond);
5858 NET_NFC_OEM_CONTROLLER_UNLOCK;
5860 DEBUG_MSG("discovering config is end");
5862 if (context.result != NFCSTATUS_SUCCESS)
5874 static bool net_nfc_nxp_controller_support_nfc(net_nfc_error_e *result)
5877 struct stat st = { 0, };
5884 if (stat("/dev/pn544", &st) == 0)
5886 *result = NET_NFC_OK;
5891 *result = NET_NFC_NOT_SUPPORTED;
5897 pthread_mutex_t *_nfc_get_fri_lock()
5899 return &g_controller_lock;
5902 static bool __net_nfc_is_valid_target_handle(net_nfc_target_handle_s *handle)
5904 bool result = (current_working_handle == handle);
5907 DEBUG_MSG("[WARNING]: INVALID HANDLE IS DETECTED!");
5912 static void __net_nfc_make_valid_target_handle(net_nfc_target_handle_s **handle)
5914 if (current_working_handle != NULL)
5916 DEBUG_MSG("[WARNING]: HANDLE WAS ALLOCATED ALREADY!");
5918 _net_nfc_util_alloc_mem(*handle, sizeof(net_nfc_target_handle_s));
5919 if (*handle != NULL)
5921 current_working_handle = *handle;
5925 static void __net_nfc_make_invalid_target_handle()
5927 if (current_working_handle != NULL)
5929 _net_nfc_util_free_mem(current_working_handle);
5930 current_working_handle = NULL;