revise initial functions and error checkings
authorYoungjae Shin <yj99.shin@samsung.com>
Wed, 2 Oct 2013 09:13:22 +0000 (18:13 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Wed, 2 Oct 2013 09:16:27 +0000 (18:16 +0900)
Change-Id: I55ea5f6d2694c22192458a224ce797d7a4e557d1

CMakeLists.txt
packaging/capi-network-nfc [deleted file]
packaging/capi-network-nfc.spec
src/nfc.c

index e2f34f781c731c23d9f4ef01d854cc37368683be..ae7c6123cfb96a32c7e67ff0742a630c024023ed 100644 (file)
@@ -23,7 +23,7 @@ SET(service "network")
 SET(submodule "nfc")
 
 # for package file
-SET(dependents "dlog glib-2.0 nfc-common-lib nfc capi-base-common vconf ecore-x capi-appfw-app-manager")
+SET(dependents "dlog glib-2.0 nfc-common-lib nfc capi-base-common vconf ecore-x")
 SET(pc_dependents "capi-base-common")
 
 SET(fw_name "${project_prefix}-${service}-${submodule}")
diff --git a/packaging/capi-network-nfc b/packaging/capi-network-nfc
deleted file mode 100644 (file)
index ec68963..0000000
+++ /dev/null
@@ -1,206 +0,0 @@
-Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.\r
-\r
-                                 Apache License\r
-                           Version 2.0, January 2004\r
-                        http://www.apache.org/licenses/\r
-\r
-   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\r
-\r
-   1. Definitions.\r
-\r
-      "License" shall mean the terms and conditions for use, reproduction,\r
-      and distribution as defined by Sections 1 through 9 of this document.\r
-\r
-      "Licensor" shall mean the copyright owner or entity authorized by\r
-      the copyright owner that is granting the License.\r
-\r
-      "Legal Entity" shall mean the union of the acting entity and all\r
-      other entities that control, are controlled by, or are under common\r
-      control with that entity. For the purposes of this definition,\r
-      "control" means (i) the power, direct or indirect, to cause the\r
-      direction or management of such entity, whether by contract or\r
-      otherwise, or (ii) ownership of fifty percent (50%) or more of the\r
-      outstanding shares, or (iii) beneficial ownership of such entity.\r
-\r
-      "You" (or "Your") shall mean an individual or Legal Entity\r
-      exercising permissions granted by this License.\r
-\r
-      "Source" form shall mean the preferred form for making modifications,\r
-      including but not limited to software source code, documentation\r
-      source, and configuration files.\r
-\r
-      "Object" form shall mean any form resulting from mechanical\r
-      transformation or translation of a Source form, including but\r
-      not limited to compiled object code, generated documentation,\r
-      and conversions to other media types.\r
-\r
-      "Work" shall mean the work of authorship, whether in Source or\r
-      Object form, made available under the License, as indicated by a\r
-      copyright notice that is included in or attached to the work\r
-      (an example is provided in the Appendix below).\r
-\r
-      "Derivative Works" shall mean any work, whether in Source or Object\r
-      form, that is based on (or derived from) the Work and for which the\r
-      editorial revisions, annotations, elaborations, or other modifications\r
-      represent, as a whole, an original work of authorship. For the purposes\r
-      of this License, Derivative Works shall not include works that remain\r
-      separable from, or merely link (or bind by name) to the interfaces of,\r
-      the Work and Derivative Works thereof.\r
-\r
-      "Contribution" shall mean any work of authorship, including\r
-      the original version of the Work and any modifications or additions\r
-      to that Work or Derivative Works thereof, that is intentionally\r
-      submitted to Licensor for inclusion in the Work by the copyright owner\r
-      or by an individual or Legal Entity authorized to submit on behalf of\r
-      the copyright owner. For the purposes of this definition, "submitted"\r
-      means any form of electronic, verbal, or written communication sent\r
-      to the Licensor or its representatives, including but not limited to\r
-      communication on electronic mailing lists, source code control systems,\r
-      and issue tracking systems that are managed by, or on behalf of, the\r
-      Licensor for the purpose of discussing and improving the Work, but\r
-      excluding communication that is conspicuously marked or otherwise\r
-      designated in writing by the copyright owner as "Not a Contribution."\r
-\r
-      "Contributor" shall mean Licensor and any individual or Legal Entity\r
-      on behalf of whom a Contribution has been received by Licensor and\r
-      subsequently incorporated within the Work.\r
-\r
-   2. Grant of Copyright License. Subject to the terms and conditions of\r
-      this License, each Contributor hereby grants to You a perpetual,\r
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
-      copyright license to reproduce, prepare Derivative Works of,\r
-      publicly display, publicly perform, sublicense, and distribute the\r
-      Work and such Derivative Works in Source or Object form.\r
-\r
-   3. Grant of Patent License. Subject to the terms and conditions of\r
-      this License, each Contributor hereby grants to You a perpetual,\r
-      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\r
-      (except as stated in this section) patent license to make, have made,\r
-      use, offer to sell, sell, import, and otherwise transfer the Work,\r
-      where such license applies only to those patent claims licensable\r
-      by such Contributor that are necessarily infringed by their\r
-      Contribution(s) alone or by combination of their Contribution(s)\r
-      with the Work to which such Contribution(s) was submitted. If You\r
-      institute patent litigation against any entity (including a\r
-      cross-claim or counterclaim in a lawsuit) alleging that the Work\r
-      or a Contribution incorporated within the Work constitutes direct\r
-      or contributory patent infringement, then any patent licenses\r
-      granted to You under this License for that Work shall terminate\r
-      as of the date such litigation is filed.\r
-\r
-   4. Redistribution. You may reproduce and distribute copies of the\r
-      Work or Derivative Works thereof in any medium, with or without\r
-      modifications, and in Source or Object form, provided that You\r
-      meet the following conditions:\r
-\r
-      (a) You must give any other recipients of the Work or\r
-          Derivative Works a copy of this License; and\r
-\r
-      (b) You must cause any modified files to carry prominent notices\r
-          stating that You changed the files; and\r
-\r
-      (c) You must retain, in the Source form of any Derivative Works\r
-          that You distribute, all copyright, patent, trademark, and\r
-          attribution notices from the Source form of the Work,\r
-          excluding those notices that do not pertain to any part of\r
-          the Derivative Works; and\r
-\r
-      (d) If the Work includes a "NOTICE" text file as part of its\r
-          distribution, then any Derivative Works that You distribute must\r
-          include a readable copy of the attribution notices contained\r
-          within such NOTICE file, excluding those notices that do not\r
-          pertain to any part of the Derivative Works, in at least one\r
-          of the following places: within a NOTICE text file distributed\r
-          as part of the Derivative Works; within the Source form or\r
-          documentation, if provided along with the Derivative Works; or,\r
-          within a display generated by the Derivative Works, if and\r
-          wherever such third-party notices normally appear. The contents\r
-          of the NOTICE file are for informational purposes only and\r
-          do not modify the License. You may add Your own attribution\r
-          notices within Derivative Works that You distribute, alongside\r
-          or as an addendum to the NOTICE text from the Work, provided\r
-          that such additional attribution notices cannot be construed\r
-          as modifying the License.\r
-\r
-      You may add Your own copyright statement to Your modifications and\r
-      may provide additional or different license terms and conditions\r
-      for use, reproduction, or distribution of Your modifications, or\r
-      for any such Derivative Works as a whole, provided Your use,\r
-      reproduction, and distribution of the Work otherwise complies with\r
-      the conditions stated in this License.\r
-\r
-   5. Submission of Contributions. Unless You explicitly state otherwise,\r
-      any Contribution intentionally submitted for inclusion in the Work\r
-      by You to the Licensor shall be under the terms and conditions of\r
-      this License, without any additional terms or conditions.\r
-      Notwithstanding the above, nothing herein shall supersede or modify\r
-      the terms of any separate license agreement you may have executed\r
-      with Licensor regarding such Contributions.\r
-\r
-   6. Trademarks. This License does not grant permission to use the trade\r
-      names, trademarks, service marks, or product names of the Licensor,\r
-      except as required for reasonable and customary use in describing the\r
-      origin of the Work and reproducing the content of the NOTICE file.\r
-\r
-   7. Disclaimer of Warranty. Unless required by applicable law or\r
-      agreed to in writing, Licensor provides the Work (and each\r
-      Contributor provides its Contributions) on an "AS IS" BASIS,\r
-      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\r
-      implied, including, without limitation, any warranties or conditions\r
-      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\r
-      PARTICULAR PURPOSE. You are solely responsible for determining the\r
-      appropriateness of using or redistributing the Work and assume any\r
-      risks associated with Your exercise of permissions under this License.\r
-\r
-   8. Limitation of Liability. In no event and under no legal theory,\r
-      whether in tort (including negligence), contract, or otherwise,\r
-      unless required by applicable law (such as deliberate and grossly\r
-      negligent acts) or agreed to in writing, shall any Contributor be\r
-      liable to You for damages, including any direct, indirect, special,\r
-      incidental, or consequential damages of any character arising as a\r
-      result of this License or out of the use or inability to use the\r
-      Work (including but not limited to damages for loss of goodwill,\r
-      work stoppage, computer failure or malfunction, or any and all\r
-      other commercial damages or losses), even if such Contributor\r
-      has been advised of the possibility of such damages.\r
-\r
-   9. Accepting Warranty or Additional Liability. While redistributing\r
-      the Work or Derivative Works thereof, You may choose to offer,\r
-      and charge a fee for, acceptance of support, warranty, indemnity,\r
-      or other liability obligations and/or rights consistent with this\r
-      License. However, in accepting such obligations, You may act only\r
-      on Your own behalf and on Your sole responsibility, not on behalf\r
-      of any other Contributor, and only if You agree to indemnify,\r
-      defend, and hold each Contributor harmless for any liability\r
-      incurred by, or claims asserted against, such Contributor by reason\r
-      of your accepting any such warranty or additional liability.\r
-\r
-   END OF TERMS AND CONDITIONS\r
-\r
-   APPENDIX: How to apply the Apache License to your work.\r
-\r
-      To apply the Apache License to your work, attach the following\r
-      boilerplate notice, with the fields enclosed by brackets "[]"\r
-      replaced with your own identifying information. (Don't include\r
-      the brackets!)  The text should be enclosed in the appropriate\r
-      comment syntax for the file format. We also recommend that a\r
-      file or class name and description of purpose be included on the\r
-      same "printed page" as the copyright notice for easier\r
-      identification within third-party archives.\r
-\r
-   Copyright [yyyy] [name of copyright owner]\r
-\r
-   Licensed under the Apache License, Version 2.0 (the "License");\r
-   you may not use this file except in compliance with the License.\r
-   You may obtain a copy of the License at\r
-\r
-       http://www.apache.org/licenses/LICENSE-2.0\r
-\r
-   Unless required by applicable law or agreed to in writing, software\r
-   distributed under the License is distributed on an "AS IS" BASIS,\r
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-   See the License for the specific language governing permissions and\r
-   limitations under the License.\r
-\r
-\r
-\r
index abee292974845498494ca91b8da67b4a7f65b3a2..041b0a9ff4c11b761e3997dc22cc16a9ff5b8112 100644 (file)
@@ -1,7 +1,7 @@
 #sbs-git:slp/api/nfc capi-network-nfc 0.0.1 14f15050f8f6ff8217421da04fa5d66e834e2016
 Name:       capi-network-nfc
 Summary:    A NFC library in SLP C API
-Version:    0.0.9
+Version:    0.0.10
 Release:    0
 Group:      API/C API
 License:    Apache-2.0
@@ -14,7 +14,6 @@ BuildRequires:  pkgconfig(nfc-common-lib)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(vconf)
 BuildRequires:  pkgconfig(ecore-x)
-BuildRequires:  pkgconfig(capi-appfw-app-manager)
 
 %description
 A NFC library in SLP C API.
@@ -44,7 +43,7 @@ make %{?jobs:-j%jobs}
 %install
 rm -rf %{buildroot}
 mkdir -p %{buildroot}/usr/share/license
-cp -af %{_builddir}/%{name}-%{version}/packaging/capi-network-nfc %{buildroot}/usr/share/license/
+cp -af LICENSE.APLv2 %{buildroot}/usr/share/license/%{name}
 
 %make_install
 
index 412b1b1bb4a95af0f44eea3169b682c9054766b3..991d45157756d017c76c96fca81b8ec952feeb3f 100755 (executable)
--- a/src/nfc.c
+++ b/src/nfc.c
@@ -1,18 +1,18 @@
 /*
-* Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+ * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
 
 #include <unistd.h>
 
@@ -24,7 +24,7 @@
 #include <net_nfc_exchanger.h>
 #include <vconf.h>
 #include <Ecore_X.h>
-#include <app_manager.h>
+#include <glib.h>
 
 /**
  * @brief The default factory key.
@@ -85,12 +85,32 @@ const unsigned char NFC_RECORD_HANDOVER_REQUEST_TYPE[2] = { 'H','r' };
  */
 const unsigned char NFC_RECORD_HANDOVER_SELECT_TYPE[2] = { 'H','s' };
 
+typedef struct _init_context_t
+{
+       nfc_initialize_completed_cb cb;
+       int ret;
+       void* user_data;
+}init_context_t;
 
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
 #define LOG_TAG "CAPI_NETWORK_NFC"
 
+static int _init_callback(init_context_t *context)
+{
+       if (context == NULL) {
+               return 0;
+       }
+
+       if(context->cb != NULL)
+               context->cb(context->ret, context->user_data);
+
+       free(context);
+
+       return 0;
+}
+
 static pid_t _get_focus_app_pid()
 {
        Ecore_X_Window focus;
@@ -105,37 +125,20 @@ static pid_t _get_focus_app_pid()
        return -1;
 }
 
-static pid_t _get_current_app_pid()
-{
-       char *app_id = NULL;
-       app_context_h context = NULL;
-       pid_t pid, pgid;
-
-       pid = getpid();
-       app_manager_get_app_id(pid, &app_id);
-       app_manager_get_app_context(app_id, &context);
-
-       app_context_get_pid(context, &pgid);
-
-       free(app_id);
-       app_context_destroy(context);
-
-       return pgid;
-}
-
 static bool _check_app_permission()
 {
        pid_t focus_app_pid, current_app_pid;
 
        focus_app_pid = _get_focus_app_pid();
-       current_app_pid = _get_current_app_pid();
+       current_app_pid = getpgid(getpid());
 
        LOGE( "[check app permission] focus_app_pid [%d],  current_app_pid [%d]", focus_app_pid, current_app_pid);
 
        return (focus_app_pid == current_app_pid) ? true : false;
 }
 
-static int _return_invalid_param(const char *func){
+static int _return_invalid_param(const char *func)
+{
        LOGE( "INVALID_PARAMETER (0x%08x)", NFC_ERROR_INVALID_PARAMETER);
        return NFC_ERROR_INVALID_PARAMETER;
 }
@@ -145,81 +148,81 @@ static int _convert_error_code(const char *func, int native_error_code)
        int error_code = NFC_ERROR_NONE;
        char * errorstr = NULL;
        switch(native_error_code){
-               case 0 :
-                       error_code = NFC_ERROR_NONE;
-                       errorstr  = "ERROR_NONE";
-                       break;
+       case 0 :
+               error_code = NFC_ERROR_NONE;
+               errorstr  = "ERROR_NONE";
+               break;
 
-               case NET_NFC_ALLOC_FAIL:
-                       error_code = NFC_ERROR_OUT_OF_MEMORY;
-                       errorstr  = "OUT_OF_MEMORY";
-                       break;
+       case NET_NFC_ALLOC_FAIL:
+               error_code = NFC_ERROR_OUT_OF_MEMORY;
+               errorstr  = "OUT_OF_MEMORY";
+               break;
 
-               case NET_NFC_UNKNOWN_ERROR:
-               case NET_NFC_THREAD_CREATE_FAIL:
-               case NET_NFC_INVALID_STATE:
-               case NET_NFC_IPC_FAIL:
-               case NET_NFC_BUFFER_TOO_SMALL:
-               case NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED:
-               case NET_NFC_RF_ERROR:
-               case NET_NFC_NOT_SUPPORTED:
-               case NET_NFC_TAG_READ_FAILED:
-               case NET_NFC_TAG_WRITE_FAILED:
-               case NET_NFC_OPERATION_FAIL:
-               case NET_NFC_SECURITY_FAIL:
-               case NET_NFC_INSUFFICIENT_STORAGE:
-               case NET_NFC_NOT_CONNECTED:
-               case NET_NFC_NOT_INITIALIZED:
-               case NET_NFC_NOT_REGISTERED:
-                       error_code = NFC_ERROR_OPERATION_FAILED;
-                       errorstr  = "OPERATION_FAILED";
-                       break;
+       case NET_NFC_UNKNOWN_ERROR:
+       case NET_NFC_THREAD_CREATE_FAIL:
+       case NET_NFC_INVALID_STATE:
+       case NET_NFC_IPC_FAIL:
+       case NET_NFC_BUFFER_TOO_SMALL:
+       case NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED:
+       case NET_NFC_RF_ERROR:
+       case NET_NFC_NOT_SUPPORTED:
+       case NET_NFC_TAG_READ_FAILED:
+       case NET_NFC_TAG_WRITE_FAILED:
+       case NET_NFC_OPERATION_FAIL:
+       case NET_NFC_SECURITY_FAIL:
+       case NET_NFC_INSUFFICIENT_STORAGE:
+       case NET_NFC_NOT_CONNECTED:
+       case NET_NFC_NOT_INITIALIZED:
+       case NET_NFC_NOT_REGISTERED:
+               error_code = NFC_ERROR_OPERATION_FAILED;
+               errorstr  = "OPERATION_FAILED";
+               break;
 
-               case NET_NFC_OUT_OF_BOUND:
-               case NET_NFC_NULL_PARAMETER:
-               case NET_NFC_NOT_ALLOWED_OPERATION:
-               case NET_NFC_LLCP_INVALID_SOCKET:
-               case NET_NFC_NO_DATA_FOUND:
-                       error_code = NFC_ERROR_INVALID_PARAMETER;
-                       errorstr  = "INVALID_PARAMETER";
-                       break;
-               case NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE:
-                       error_code = NFC_ERROR_INVALID_RECORD_TYPE;
-                       errorstr  = "INVALID_RECORD_TYPE";
-                       break;
+       case NET_NFC_OUT_OF_BOUND:
+       case NET_NFC_NULL_PARAMETER:
+       case NET_NFC_NOT_ALLOWED_OPERATION:
+       case NET_NFC_LLCP_INVALID_SOCKET:
+       case NET_NFC_NO_DATA_FOUND:
+               error_code = NFC_ERROR_INVALID_PARAMETER;
+               errorstr  = "INVALID_PARAMETER";
+               break;
+       case NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE:
+               error_code = NFC_ERROR_INVALID_RECORD_TYPE;
+               errorstr  = "INVALID_RECORD_TYPE";
+               break;
 
-               case NET_NFC_ALREADY_INITIALIZED:
-               case NET_NFC_ALREADY_REGISTERED:
-                       error_code = NFC_ERROR_NONE;
-                       errorstr  = "ERROR_NONE";
-                       break;
+       case NET_NFC_ALREADY_INITIALIZED:
+       case NET_NFC_ALREADY_REGISTERED:
+               error_code = NFC_ERROR_NONE;
+               errorstr  = "ERROR_NONE";
+               break;
 
-               case NET_NFC_RF_TIMEOUT:
-                       error_code = NFC_ERROR_TIMED_OUT;
-                       errorstr  = "TIMED_OUT";
-                       break;
-               case NET_NFC_INVALID_FORMAT:
-               case NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK:
-               case NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK:
-               case NET_NFC_NDEF_BUF_END_WITHOUT_ME:
-                       error_code = NFC_ERROR_INVALID_NDEF_MESSAGE;
-                       errorstr  = "INVALID_NDEF_MESSAGE";
-                       break;
-               case NET_NFC_NO_NDEF_MESSAGE:
-                       error_code = NFC_ERROR_NO_NDEF_MESSAGE;
-                       errorstr  = "NO_NDEF_MESSAGE";
-                       break;
-               case NET_NFC_BUSY :
-                       error_code = NFC_ERROR_DEVICE_BUSY;
-                       errorstr  = "DEVICE_BUSY";
-                       break;
-               case NET_NFC_NO_NDEF_SUPPORT:
-                       error_code = NFC_ERROR_NOT_NDEF_FORMAT;
-                       errorstr  = "NOT_SUPPORTED";
-                       break;
-               default :
-                       error_code = NFC_ERROR_OPERATION_FAILED;
-                       errorstr  = "OPERATION_FAILED";
+       case NET_NFC_RF_TIMEOUT:
+               error_code = NFC_ERROR_TIMED_OUT;
+               errorstr  = "TIMED_OUT";
+               break;
+       case NET_NFC_INVALID_FORMAT:
+       case NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK:
+       case NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK:
+       case NET_NFC_NDEF_BUF_END_WITHOUT_ME:
+               error_code = NFC_ERROR_INVALID_NDEF_MESSAGE;
+               errorstr  = "INVALID_NDEF_MESSAGE";
+               break;
+       case NET_NFC_NO_NDEF_MESSAGE:
+               error_code = NFC_ERROR_NO_NDEF_MESSAGE;
+               errorstr  = "NO_NDEF_MESSAGE";
+               break;
+       case NET_NFC_BUSY :
+               error_code = NFC_ERROR_DEVICE_BUSY;
+               errorstr  = "DEVICE_BUSY";
+               break;
+       case NET_NFC_NO_NDEF_SUPPORT:
+               error_code = NFC_ERROR_NOT_NDEF_FORMAT;
+               errorstr  = "NOT_SUPPORTED";
+               break;
+       default :
+               error_code = NFC_ERROR_OPERATION_FAILED;
+               errorstr  = "OPERATION_FAILED";
        }
 
        LOGE( "NFC %s(0x%08x)", errorstr, error_code);
@@ -228,8 +231,17 @@ static int _convert_error_code(const char *func, int native_error_code)
 
 }
 
-_nfc_context_s g_nfc_context;
+static _nfc_context_s g_nfc_context;
+
+static void _clear_context()
+{
+       if (g_nfc_context.current_tag != NULL)
+       {
+               net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
+       }
 
+       memset(&g_nfc_context, 0, sizeof(g_nfc_context));
+}
 
 static void nfc_manager_set_activation_completed_cb(nfc_activation_completed_cb callback , void *user_data)
 {
@@ -258,7 +270,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
        int capi_result = _convert_error_code("EVENT", result);
 
        switch ( message ){
-               case NET_NFC_MESSAGE_TRANSCEIVE:
+       case NET_NFC_MESSAGE_TRANSCEIVE:
                {
                        if( trans_data != NULL ){
                                _async_callback_data *user_cb = (_async_callback_data*)trans_data;
@@ -283,7 +295,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        }
                        break;
                }
-               case NET_NFC_MESSAGE_READ_NDEF:
+       case NET_NFC_MESSAGE_READ_NDEF:
                {
                        if( trans_data != NULL ) {
                                ndef_message_h ndef_message = (ndef_message_h)data;
@@ -293,7 +305,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        }
                        break;
                }
-               case NET_NFC_MESSAGE_WRITE_NDEF:
+       case NET_NFC_MESSAGE_WRITE_NDEF:
                {
                        if( trans_data != NULL ){
                                _async_callback_data *user_cb = (_async_callback_data*)trans_data;
@@ -302,7 +314,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        }
                        break;
                }
-               case NET_NFC_MESSAGE_TAG_DISCOVERED:
+       case NET_NFC_MESSAGE_TAG_DISCOVERED:
                {
                        net_nfc_target_info_s *target_info = (net_nfc_target_info_s *)data;
 
@@ -329,11 +341,11 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        }
                        break;
                }
-               case NET_NFC_MESSAGE_NOTIFY:
+       case NET_NFC_MESSAGE_NOTIFY:
                {
                        break;
                }
-               case NET_NFC_MESSAGE_TAG_DETACHED:
+       case NET_NFC_MESSAGE_TAG_DETACHED:
                {
                        if( g_nfc_context.on_tag_discovered_cb ){
                                g_nfc_context.on_tag_discovered_cb( NFC_DISCOVERED_TYPE_DETACHED,  (nfc_tag_h)g_nfc_context.current_tag , g_nfc_context.on_tag_discovered_user_data );
@@ -346,7 +358,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        }
                        break;
                }
-               case NET_NFC_MESSAGE_P2P_DISCOVERED:
+       case NET_NFC_MESSAGE_P2P_DISCOVERED:
                {
                        g_nfc_context.current_target = (net_nfc_target_handle_h)data;
                        g_nfc_context.on_p2p_recv_cb = NULL;
@@ -360,7 +372,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
 
                        break;
                }
-               case NET_NFC_MESSAGE_P2P_DETACHED:
+       case NET_NFC_MESSAGE_P2P_DETACHED:
                {
                        if( g_nfc_context.on_p2p_discovered_cb ){
                                g_nfc_context.on_p2p_discovered_cb( NFC_DISCOVERED_TYPE_DETACHED,  (nfc_p2p_target_h)(g_nfc_context.current_target) , g_nfc_context.on_p2p_discovered_user_data );
@@ -373,7 +385,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
 
                        break;
                }
-               case NET_NFC_MESSAGE_P2P_SEND :
+       case NET_NFC_MESSAGE_P2P_SEND :
                {
                        if( g_nfc_context.on_p2p_send_completed_cb != NULL ){
 
@@ -385,7 +397,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        }
                        break;
                }
-               case NET_NFC_MESSAGE_P2P_RECEIVE :
+       case NET_NFC_MESSAGE_P2P_RECEIVE :
                {
                        if( g_nfc_context.on_p2p_recv_cb != NULL ){
                                ndef_message_h ndef_message ;
@@ -396,7 +408,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
 
                        break;
                }
-               case NET_NFC_MESSAGE_FORMAT_NDEF:
+       case NET_NFC_MESSAGE_FORMAT_NDEF:
                {
                        if( trans_data != NULL) {
                                _async_callback_data *user_cb = (_async_callback_data*)trans_data;
@@ -406,7 +418,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        break;
                }
 
-               case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
+       case NET_NFC_MESSAGE_CONNECTION_HANDOVER :
                {
                        if( g_nfc_context.on_p2p_connection_handover_completed_cb != NULL ){
 
@@ -431,8 +443,8 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
 
                                                        snprintf(buffer, 50, "%02x:%02x:%02x:%02x:%02x:%02x",temp[0], temp[1], temp[2], temp[3], temp[4], temp[5]);
 
-                                                        ac_data = (strdup(buffer));
-                                                        ac_data_size = strlen(ac_data ) +1;
+                                                       ac_data = (strdup(buffer));
+                                                       ac_data_size = strlen(ac_data ) +1;
                                                }
                                                net_nfc_free_data(ac_info);
                                        }
@@ -451,7 +463,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                }
 
 
-               case NET_NFC_MESSAGE_IS_TAG_CONNECTED :
+       case NET_NFC_MESSAGE_IS_TAG_CONNECTED :
                {
                        net_nfc_target_type_e  devType = *(net_nfc_target_type_e *)data;
 
@@ -479,7 +491,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        break;
                }
 
-               case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO :
+       case NET_NFC_MESSAGE_GET_CURRENT_TAG_INFO :
                {
                        net_nfc_target_info_s *target_info = (net_nfc_target_info_s *)data;
 
@@ -503,7 +515,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        break;
                }
 
-               case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE :
+       case NET_NFC_MESSAGE_GET_CURRENT_TARGET_HANDLE :
                {
                        g_nfc_context.current_target = (net_nfc_target_handle_h)data;
 
@@ -516,8 +528,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        break;
                }
 
-
-               case NET_NFC_MESSAGE_INIT :
+       case NET_NFC_MESSAGE_INIT :
                {
                        bool activated = true;
 
@@ -540,14 +551,12 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                                        g_nfc_context.on_activation_doing = false;
                                        LOGE( "g_nfc_context.on_activation_doing\n");
                                }
-
-
                        }
 
                        break;
                }
 
-               case NET_NFC_MESSAGE_DEINIT :
+       case NET_NFC_MESSAGE_DEINIT :
                {
                        bool activated = false;
 
@@ -573,7 +582,7 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        break;
                }
 
-               case NET_NFC_MESSAGE_SET_SE :
+       case NET_NFC_MESSAGE_SET_SE :
                {
                        if( trans_data != NULL ){
                                _async_callback_data *user_cb = (_async_callback_data*)trans_data;
@@ -583,39 +592,39 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        break;
                }
 
-               case NET_NFC_MESSAGE_SE_START_TRANSACTION :
-               case NET_NFC_MESSAGE_SE_END_TRANSACTION :
-               case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION:
-               case NET_NFC_MESSAGE_SE_CONNECTIVITY :
-               case NET_NFC_MESSAGE_SE_FIELD_ON :
-               case NET_NFC_MESSAGE_SE_FIELD_OFF :
-               case NET_NFC_MESSAGE_SE_TYPE_CHANGED :
+       case NET_NFC_MESSAGE_SE_START_TRANSACTION :
+       case NET_NFC_MESSAGE_SE_END_TRANSACTION :
+       case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION:
+       case NET_NFC_MESSAGE_SE_CONNECTIVITY :
+       case NET_NFC_MESSAGE_SE_FIELD_ON :
+       case NET_NFC_MESSAGE_SE_FIELD_OFF :
+       case NET_NFC_MESSAGE_SE_TYPE_CHANGED :
                {
                        nfc_se_event_e event = NFC_SE_EVENT_START_TRANSACTION;
                        switch( message ){
-                               case NET_NFC_MESSAGE_SE_START_TRANSACTION:
-                                       event = NFC_SE_EVENT_START_TRANSACTION;
-                                       break;
-                               case NET_NFC_MESSAGE_SE_END_TRANSACTION:
-                                       event = NFC_SE_EVENT_END_TRANSACTION;
-                                       break;
-                               case NET_NFC_MESSAGE_SE_CONNECTIVITY:
-                                       event = NFC_SE_EVENT_CONNECTIVITY;
-                                       break;
-                               case NET_NFC_MESSAGE_SE_FIELD_ON :
-                                       event = NFC_SE_EVENT_FIELD_ON;
-                                       break;
-                               case NET_NFC_MESSAGE_SE_FIELD_OFF :
-                                       event = NFC_SE_EVENT_FIELD_OFF;
-                                       break;
-                               case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION:
-                                       event = NFC_SE_EVENT_TRANSACTION;
-                                       break;
-                               case NET_NFC_MESSAGE_SE_TYPE_CHANGED:
-                                       event = NFC_SE_EVENT_SE_TYPE_CHANGED;
-                                       break;
-                               default:
-                                       break;
+                       case NET_NFC_MESSAGE_SE_START_TRANSACTION:
+                               event = NFC_SE_EVENT_START_TRANSACTION;
+                               break;
+                       case NET_NFC_MESSAGE_SE_END_TRANSACTION:
+                               event = NFC_SE_EVENT_END_TRANSACTION;
+                               break;
+                       case NET_NFC_MESSAGE_SE_CONNECTIVITY:
+                               event = NFC_SE_EVENT_CONNECTIVITY;
+                               break;
+                       case NET_NFC_MESSAGE_SE_FIELD_ON :
+                               event = NFC_SE_EVENT_FIELD_ON;
+                               break;
+                       case NET_NFC_MESSAGE_SE_FIELD_OFF :
+                               event = NFC_SE_EVENT_FIELD_OFF;
+                               break;
+                       case NET_NFC_MESSAGE_SE_TYPE_TRANSACTION:
+                               event = NFC_SE_EVENT_TRANSACTION;
+                               break;
+                       case NET_NFC_MESSAGE_SE_TYPE_CHANGED:
+                               event = NFC_SE_EVENT_SE_TYPE_CHANGED;
+                               break;
+                       default:
+                               break;
                        }
 
                        if( g_nfc_context.on_se_event_cb ){
@@ -629,8 +638,8 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
                        }
                }
 
-               default :
-                       break;
+       default :
+               break;
        }
 
 }
@@ -638,13 +647,11 @@ void _nfc_response_handler(net_nfc_message_e message, net_nfc_error_e result, vo
 
 bool nfc_manager_is_supported(void)
 {
-
        int nfc_supported = 0;
 
        net_nfc_is_supported(&nfc_supported);
 
        return nfc_supported;
-
 }
 
 
@@ -658,7 +665,7 @@ int nfc_manager_set_activation(bool activation, nfc_activation_completed_cb call
 
        if (nfc_check_activation == true)
        {
-               LOGE( "nfc_manager_check_activation BUSY!!!!!\n");
+               LOGE( "nfc_manager_check_activation BUSY!!!!!");
                return NFC_ERROR_DEVICE_BUSY;
        }
 
@@ -708,6 +715,7 @@ int nfc_manager_set_activation_changed_cb(nfc_activation_changed_cb callback , v
 {
        if( callback == NULL)
                return _return_invalid_param(__func__);
+
        g_nfc_context.on_activation_changed_cb = callback;
        g_nfc_context.on_activation_changed_user_data = user_data;
        return 0;
@@ -719,9 +727,6 @@ void nfc_manager_unset_activation_changed_cb(void)
        g_nfc_context.on_activation_changed_user_data = NULL;
 }
 
-
-
-
 bool nfc_manager_is_activated(void)
 {
        int activated = 0;
@@ -736,7 +741,6 @@ bool nfc_manager_is_activated(void)
        {
                return false;
        }
-
 }
 
 static bool _is_initialized()
@@ -748,6 +752,7 @@ int nfc_manager_initialize (nfc_initialize_completed_cb callback, void *user_dat
 {
        int ret;
        int nfc_supported = 0;
+       init_context_t*  context;
 
        net_nfc_is_supported(&nfc_supported);
 
@@ -759,18 +764,44 @@ int nfc_manager_initialize (nfc_initialize_completed_cb callback, void *user_dat
 
        if (!_is_initialized())
        {
+               int type;
+
                ret = net_nfc_initialize();
                if( ret != NET_NFC_OK )
                        return _convert_error_code(__func__, ret);
 
-               memset( &g_nfc_context , 0 , sizeof( g_nfc_context));
+               _clear_context();
                net_nfc_set_response_callback( _nfc_response_handler , &g_nfc_context);
+
+               if (net_nfc_is_tag_connected_sync(&type) == NET_NFC_OK)
+               {
+                       if (type == NET_NFC_NFCIP1_INITIATOR ||
+                                       type == NET_NFC_NFCIP1_TARGET)
+                       {
+                               net_nfc_get_current_target_handle_sync(&g_nfc_context.current_target);
+                       }
+                       else
+                       {
+                               net_nfc_get_current_tag_info_sync((net_nfc_target_info_h *)&g_nfc_context.current_tag);
+                       }
+               }
+
                g_nfc_context.initialized = true;
-               net_nfc_state_activate();
-               g_nfc_context.on_initialize_completed_cb = callback;
-               ret = net_nfc_is_tag_connected(user_data);
-               if( ret != NET_NFC_OK )
-                       return _convert_error_code(__func__, ret);
+
+               if (callback != NULL)
+               {
+                       context = (init_context_t*)malloc( sizeof(init_context_t));
+
+                       if(context == NULL )
+                               return NFC_ERROR_OUT_OF_MEMORY;
+
+                       memset(context , 0 , sizeof(init_context_t));
+                       context->cb = callback;
+                       context->ret = ret;
+                       context->user_data = user_data;
+                       g_idle_add((GSourceFunc)_init_callback, (gpointer)context);
+               }
+
        }
 
        return NFC_ERROR_NONE;
@@ -790,45 +821,29 @@ int nfc_manager_initialize_sync()
 
        if (!_is_initialized())
        {
-               int devType;
+               int type;
 
                ret = net_nfc_initialize();
                if (ret != NET_NFC_OK)
                        return _convert_error_code(__func__, ret);
 
-               memset(&g_nfc_context, 0, sizeof(g_nfc_context));
+               _clear_context();
                net_nfc_set_response_callback(_nfc_response_handler, &g_nfc_context);
-               g_nfc_context.initialized = true;
-               net_nfc_state_activate();
-
-               ret = net_nfc_is_tag_connected_sync(&devType);
-               if (ret == NET_NFC_OK)
+               if (net_nfc_is_tag_connected_sync(&type) == NET_NFC_OK)
                {
-                       if ((devType == NET_NFC_NFCIP1_TARGET) || (devType == NET_NFC_NFCIP1_INITIATOR))
+                       if (type == NET_NFC_NFCIP1_INITIATOR ||
+                                       type == NET_NFC_NFCIP1_TARGET)
                        {
-                               net_nfc_get_current_target_handle_sync((net_nfc_target_handle_h *)&g_nfc_context.current_target);
+                               net_nfc_get_current_target_handle_sync(&g_nfc_context.current_target);
                        }
-                       else if ((devType > NET_NFC_UNKNOWN_TARGET) && (devType < NET_NFC_NFCIP1_TARGET))
+                       else
                        {
-                               if (g_nfc_context.current_tag != NULL)
-                               {
-                                       net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
-                                       g_nfc_context.current_tag = NULL;
-                               }
-
                                net_nfc_get_current_tag_info_sync((net_nfc_target_info_h *)&g_nfc_context.current_tag);
                        }
                }
-               else
-               {
-                       if (ret == NET_NFC_NOT_CONNECTED)
-                       {
-                               ret = NFC_ERROR_NONE;
-                       }
-               }
 
-               if (ret != NET_NFC_OK)
-                       return _convert_error_code(__func__, ret);
+               g_nfc_context.initialized = true;
+
        }
 
        return NFC_ERROR_NONE;
@@ -840,14 +855,16 @@ int nfc_manager_deinitialize (void)
 
        if (_is_initialized())
        {
+#if 0
                net_nfc_state_deactivate();
-
-               ret = net_nfc_deinitialize();
-
+#endif
                if (ret == 0)
                        net_nfc_unset_response_callback();
 
-               g_nfc_context.initialized = false;
+               ret = net_nfc_deinitialize();
+
+               net_nfc_release_tag_info((net_nfc_target_info_h)g_nfc_context.current_tag);
+               memset(&g_nfc_context, 0, sizeof(g_nfc_context));
        }
 
        return _convert_error_code(__func__, ret);
@@ -857,6 +874,7 @@ int nfc_manager_set_tag_discovered_cb( nfc_tag_discovered_cb callback , void * u
 {
        if( callback == NULL)
                return _return_invalid_param(__func__);
+
        g_nfc_context.on_tag_discovered_cb = callback;
        g_nfc_context.on_tag_discovered_user_data = user_data;
        return 0;
@@ -871,6 +889,7 @@ int nfc_manager_set_ndef_discovered_cb( nfc_ndef_discovered_cb callback , void *
 {
        if( callback == NULL)
                return _return_invalid_param(__func__);
+
        g_nfc_context.on_ndef_discovered_cb= callback;
        g_nfc_context.on_ndef_discovered_user_data= user_data;
        return 0;
@@ -878,7 +897,6 @@ int nfc_manager_set_ndef_discovered_cb( nfc_ndef_discovered_cb callback , void *
 
 void nfc_manager_unset_ndef_discovered_cb( void )
 {
-
        g_nfc_context.on_ndef_discovered_cb = NULL;
        g_nfc_context.on_ndef_discovered_user_data = NULL;
 }
@@ -890,7 +908,6 @@ void nfc_manager_set_tag_filter(int filter )
 
 int nfc_manager_get_tag_filter(void)
 {
-
        return net_nfc_get_tag_filter();
 }
 
@@ -920,6 +937,7 @@ int nfc_manager_get_connected_tag(nfc_tag_h * tag)
 int nfc_manager_get_connected_target(nfc_p2p_target_h *target)
 {
        int ret;
+
        if( target == NULL )
                return _return_invalid_param(__func__);
 
@@ -975,7 +993,7 @@ int nfc_manager_set_card_emulation_se_type(nfc_se_type_e type, nfc_set_card_emul
 
        if( callback != NULL )
        {
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -995,7 +1013,7 @@ int nfc_manager_set_card_emulation_se_type(nfc_se_type_e type, nfc_set_card_emul
                se_type = NET_NFC_SE_TYPE_UICC;
                break;
        default:
-       break;
+               break;
        }
 
        ret = net_nfc_set_secure_element_type(se_type, (void *)trans_data);
@@ -1008,6 +1026,9 @@ int nfc_manager_get_card_emulation_se_type(nfc_se_type_e* type)
        int ret = NFC_ERROR_NONE;
        int se_type;
 
+       if (type == NULL)
+               return _return_invalid_param(__func__);
+
        if ((ret = vconf_get_int(VCONFKEY_NFC_SE_TYPE, &se_type)) != 0)
        {
                ret = NFC_ERROR_OPERATION_FAILED;
@@ -1027,8 +1048,10 @@ int nfc_manager_get_card_emulation_se_type(nfc_se_type_e* type)
 int nfc_manager_get_cached_message(nfc_ndef_message_h *ndef_message)
 {
        int ret;
+
        if( ndef_message == NULL )
                return _return_invalid_param(__func__);
+
        ret = net_nfc_retrieve_current_ndef_message(ndef_message);
        return _convert_error_code(__func__, ret);
 }
@@ -1049,20 +1072,22 @@ int nfc_ndef_record_create(nfc_ndef_record_h* record, nfc_record_tnf_e tnf, cons
 
 int nfc_ndef_record_create_text(nfc_ndef_record_h* record, const char * text, const char * lang_code, nfc_encode_type_e encode )
 {
+       int ret;
 
        if(record == NULL ||  text == NULL || lang_code == NULL )
                return _return_invalid_param(__func__);
-       int ret;
+
        ret = net_nfc_create_text_type_record((ndef_record_h*)record, text, lang_code, encode);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_record_create_uri(nfc_ndef_record_h* record, const char* uri)
 {
+       int ret;
 
        if(record == NULL ||  uri == NULL)
                return _return_invalid_param(__func__);
-       int ret;
+
        ret = net_nfc_create_uri_type_record((ndef_record_h*)record , uri , NET_NFC_SCHEMA_FULL_URI);
        return _convert_error_code(__func__, ret);
 }
@@ -1071,6 +1096,7 @@ int nfc_ndef_record_create_mime(nfc_ndef_record_h* record, const char * mime_typ
 {
        if(record == NULL ||  mime_type == NULL || data == NULL)
                return _return_invalid_param(__func__);
+
        return nfc_ndef_record_create(record , NFC_RECORD_TNF_MIME_MEDIA , (unsigned char *) mime_type, strlen(mime_type), NULL, 0, data, data_size );
 }
 
@@ -1082,6 +1108,7 @@ int nfc_ndef_record_get_mime_type(nfc_ndef_record_h record , char **mime_type){
 
        if(record == NULL ||  mime_type == NULL)
                return _return_invalid_param(__func__);
+
        nfc_record_tnf_e tnf;
        if( nfc_ndef_record_get_tnf(record, &tnf ) != 0 || tnf != NFC_RECORD_TNF_MIME_MEDIA ){
                return NFC_ERROR_INVALID_RECORD_TYPE;
@@ -1104,20 +1131,22 @@ int nfc_ndef_record_get_mime_type(nfc_ndef_record_h record , char **mime_type){
 
 int nfc_ndef_record_destroy(nfc_ndef_record_h record)
 {
+       int ret;
 
        if(record == NULL  )
                return _return_invalid_param(__func__);
-       int ret;
+
        ret = net_nfc_free_record(record);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_record_set_id (nfc_ndef_record_h record, unsigned char *id , int id_size)
 {
+       int ret;
 
-       if(record == NULL ||  id == NULL )
+       if (record == NULL || id == NULL || id_size <= 0)
                return _return_invalid_param(__func__);
-       int ret;
+
        data_s id_data = {id, id_size};
        ret = net_nfc_set_record_id(record, (data_h)&id_data);
        return _convert_error_code(__func__, ret);
@@ -1125,10 +1154,11 @@ int nfc_ndef_record_set_id (nfc_ndef_record_h record, unsigned char *id , int id
 
 int nfc_ndef_record_get_payload (nfc_ndef_record_h record, unsigned char ** payload, int *size)
 {
+       int ret ;
 
        if(record == NULL ||  payload == NULL || size == NULL )
                return _return_invalid_param(__func__);
-       int ret ;
+
        data_s *payload_data;
        ret = net_nfc_get_record_payload(record, (data_h*)&payload_data);
        if( ret == 0){
@@ -1140,9 +1170,12 @@ int nfc_ndef_record_get_payload (nfc_ndef_record_h record, unsigned char ** payl
 
 int nfc_ndef_record_get_type (nfc_ndef_record_h record, unsigned char ** type, int *size)
 {
-
        int ret ;
        data_s *type_data;
+
+       if (record == NULL || type == NULL || size == NULL)
+               return _return_invalid_param(__func__);
+
        ret = net_nfc_get_record_type(record, (data_h*)&type_data);
        if( ret == 0){
                *type = type_data->buffer;
@@ -1153,12 +1186,12 @@ int nfc_ndef_record_get_type (nfc_ndef_record_h record, unsigned char ** type, i
 
 int nfc_ndef_record_get_id (nfc_ndef_record_h record, unsigned char **id , int *size)
 {
+       int ret ;
+       data_s *id_data;
 
        if(record == NULL ||  id == NULL || size == NULL )
                return _return_invalid_param(__func__);
 
-       int ret ;
-       data_s *id_data;
        ret = net_nfc_get_record_id(record, (data_h*)&id_data);
        if( ret == 0){
                *id = id_data->buffer;
@@ -1169,92 +1202,105 @@ int nfc_ndef_record_get_id (nfc_ndef_record_h record, unsigned char **id , int *
 
 int nfc_ndef_record_get_tnf(nfc_ndef_record_h record, nfc_record_tnf_e * tnf)
 {
+       int ret;
 
        if(record == NULL ||  tnf == NULL )
                return _return_invalid_param(__func__);
-       int ret;
+
        ret = net_nfc_get_record_tnf(record, (net_nfc_record_tnf_e*)tnf);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_record_get_text(nfc_ndef_record_h record, char** buffer)
 {
+       int ret;
 
        if(record == NULL ||  buffer == NULL)
                return _return_invalid_param(__func__);
-       int ret;
+
        ret = net_nfc_create_text_string_from_text_record(record, buffer);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_record_get_langcode(nfc_ndef_record_h record, char **lang_code)
 {
+       int ret;
 
        if(record == NULL ||  lang_code == NULL)
                return _return_invalid_param(__func__);
-       int ret;
+
        ret = net_nfc_get_languange_code_string_from_text_record(record, lang_code);
        return _convert_error_code(__func__, ret);
 }
 int nfc_ndef_record_get_encode_type(nfc_ndef_record_h record, nfc_encode_type_e *encode)
 {
+       int ret=0;
 
        if(record == NULL ||  encode == NULL  )
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_get_encoding_type_from_text_record(record, (net_nfc_encode_type_e*)encode);
-//     if( ret == NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE)
-//             LOGE("%s reord type is not text type");
+       //      if( ret == NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE)
+       //              LOGE("%s reord type is not text type");
        return _convert_error_code(__func__, ret);
 }
 int nfc_ndef_record_get_uri(nfc_ndef_record_h record , char **uri)
 {
+       int ret=0;
 
        if(record == NULL ||  uri == NULL  )
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_create_uri_string_from_uri_record(record, uri);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_create(nfc_ndef_message_h* ndef_message)
 {
+       int ret = 0;
 
        if( ndef_message == NULL )
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_create_ndef_message(ndef_message);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_create_from_rawdata(nfc_ndef_message_h* ndef_message, const unsigned char* rawdata, int rawdata_size)
 {
+       int ret = 0;
 
-       if( ndef_message == NULL || rawdata == NULL)
+       if (ndef_message == NULL || rawdata == NULL || rawdata_size <= 0)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        data_s rawdata_data = {(unsigned char *)rawdata, rawdata_size};
+
        ret = net_nfc_create_ndef_message_from_rawdata((ndef_message_h*)ndef_message , (data_h)&rawdata_data);
+
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_destroy(nfc_ndef_message_h ndef_message)
 {
+       int ret = 0;
 
        if( ndef_message == NULL )
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_free_ndef_message(ndef_message);
+
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_get_record_count(nfc_ndef_message_h ndef_message , int *count)
 {
+       int ret = 0;
 
        if( ndef_message == NULL || count == NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_get_ndef_message_record_count(ndef_message , count);
+
        return _convert_error_code(__func__, ret);
 }
 
@@ -1270,11 +1316,14 @@ int nfc_ndef_message_get_rawdata(nfc_ndef_message_h ndef_message , unsigned char
        *rawdata_size = 0;
 
        ret = net_nfc_create_rawdata_from_ndef_message(ndef_message, (data_h *)&rawdata_data);
-       if (rawdata_data)
-       {
+       if (ret == NET_NFC_OK) {
                *rawdata = calloc(1, rawdata_data->length);
-               memcpy(*rawdata, rawdata_data->buffer, rawdata_data->length);
-               *rawdata_size = rawdata_data->length;
+               if (*rawdata != NULL) {
+                       memcpy(*rawdata, rawdata_data->buffer, rawdata_data->length);
+                       *rawdata_size = rawdata_data->length;
+               } else {
+                       ret = NET_NFC_ALLOC_FAIL;
+               }
                net_nfc_free_data((data_h)rawdata_data);
        }
 
@@ -1283,90 +1332,100 @@ int nfc_ndef_message_get_rawdata(nfc_ndef_message_h ndef_message , unsigned char
 
 int nfc_ndef_message_get_rawdata_size(nfc_ndef_message_h ndef_message , int *byte_size)
 {
+       int ret = 0;
 
        if( ndef_message == NULL || byte_size == NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
-       ret = net_nfc_get_ndef_message_byte_length(ndef_message , byte_size);
+
+       ret = net_nfc_get_ndef_message_byte_length(ndef_message, byte_size);
+
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_append_record(nfc_ndef_message_h ndef_message , nfc_ndef_record_h record)
 {
+       int ret=0;
 
        if( ndef_message == NULL || record == NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_append_record_to_ndef_message(ndef_message , record );
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_insert_record(nfc_ndef_message_h ndef_message , int index, nfc_ndef_record_h record)
 {
+       int ret=0;
 
        if( ndef_message == NULL || record == NULL )
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_append_record_by_index(ndef_message , index , record);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_remove_record(nfc_ndef_message_h ndef_message , int index)
 {
+       int ret=0;
 
        if( ndef_message == NULL )
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_remove_record_by_index(ndef_message , index);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_ndef_message_get_record(nfc_ndef_message_h ndef_message , int index , nfc_ndef_record_h *record)
 {
+       int ret=0;
 
        if( ndef_message == NULL || record == NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_get_record_by_index(ndef_message , index , (ndef_record_h*)record);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_tag_get_type( nfc_tag_h tag , nfc_tag_type_e *type)
 {
+       int ret=0;
 
        if( tag == NULL || type == NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_get_tag_type( tag, (net_nfc_target_type_e*) type);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_tag_is_support_ndef(nfc_tag_h tag, bool * is_support)
 {
+       int ret=0;
 
        if( tag == NULL || is_support== NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_get_tag_ndef_support(tag , is_support);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_tag_get_maximum_ndef_size(nfc_tag_h tag , unsigned int * max_size)
 {
+       int ret=0;
 
        if( tag == NULL || max_size == NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_get_tag_max_data_size(tag , max_size);
        return _convert_error_code(__func__, ret);
 }
 
 int nfc_tag_get_ndef_size(nfc_tag_h tag, unsigned int * actual_data_size)
 {
+       int ret=0;
 
        if( tag == NULL || actual_data_size == NULL)
                return _return_invalid_param(__func__);
-       int ret=0;
+
        ret = net_nfc_get_tag_actual_data_size(tag , actual_data_size);
        return _convert_error_code(__func__, ret);
 }
@@ -1374,7 +1433,6 @@ int nfc_tag_get_ndef_size(nfc_tag_h tag, unsigned int * actual_data_size)
 int nfc_tag_foreach_information(nfc_tag_h tag , nfc_tag_information_cb callback , void * user_data )
 {
        int i;
-
        net_nfc_tag_info_s *taglist = g_nfc_context.current_tag->tag_info_list;
 
        if( tag == NULL || callback == NULL )
@@ -1392,8 +1450,7 @@ int nfc_tag_foreach_information(nfc_tag_h tag , nfc_tag_information_cb callback
 
 int nfc_tag_transceive( nfc_tag_h tag, unsigned char * buffer, int buffer_size,  nfc_tag_transceive_completed_cb callback , void * user_data )
 {
-
-       if( tag == NULL )
+       if (tag == NULL || buffer == NULL || buffer_size <= 0)
                return _return_invalid_param(__func__);
 
        if(!nfc_manager_is_activated())
@@ -1414,7 +1471,7 @@ int nfc_tag_transceive( nfc_tag_h tag, unsigned char * buffer, int buffer_size,
 
        _async_callback_data * trans_data = NULL;
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1430,7 +1487,6 @@ int nfc_tag_transceive( nfc_tag_h tag, unsigned char * buffer, int buffer_size,
 
 int nfc_tag_read_ndef( nfc_tag_h tag, nfc_tag_read_completed_cb callback , void * user_data)
 {
-
        if( tag == NULL )
                return _return_invalid_param(__func__);
 
@@ -1445,7 +1501,7 @@ int nfc_tag_read_ndef( nfc_tag_h tag, nfc_tag_read_completed_cb callback , void
 
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1458,8 +1514,7 @@ int nfc_tag_read_ndef( nfc_tag_h tag, nfc_tag_read_completed_cb callback , void
 
 int nfc_tag_write_ndef(nfc_tag_h tag, nfc_ndef_message_h msg , nfc_tag_write_completed_cb callback ,  void *user_data)
 {
-
-       if( tag == NULL )
+       if (tag == NULL || msg == NULL)
                return _return_invalid_param(__func__);
 
        if(!nfc_manager_is_activated())
@@ -1483,7 +1538,7 @@ int nfc_tag_write_ndef(nfc_tag_h tag, nfc_ndef_message_h msg , nfc_tag_write_com
 
        }
 
-        int byte_size = 0;
+       int byte_size = 0;
        nfc_ndef_message_get_rawdata_size(msg , &byte_size);
 
        if(tag_info->maxDataSize < byte_size)
@@ -1494,7 +1549,7 @@ int nfc_tag_write_ndef(nfc_tag_h tag, nfc_ndef_message_h msg , nfc_tag_write_com
 
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1507,8 +1562,7 @@ int nfc_tag_write_ndef(nfc_tag_h tag, nfc_ndef_message_h msg , nfc_tag_write_com
 
 int nfc_tag_format_ndef(nfc_tag_h tag , unsigned char * key, int key_size , nfc_tag_format_completed_cb callback, void * user_data )
 {
-
-       if( tag == NULL )
+       if (tag == NULL || key == NULL || key_size <= 0)
                return _return_invalid_param(__func__);
 
        if(!nfc_manager_is_activated())
@@ -1528,7 +1582,7 @@ int nfc_tag_format_ndef(nfc_tag_h tag , unsigned char * key, int key_size , nfc_
 
        _async_callback_data * trans_data = NULL;
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1542,8 +1596,7 @@ int nfc_tag_format_ndef(nfc_tag_h tag , unsigned char * key, int key_size , nfc_
 
 int nfc_mifare_authenticate_with_keyA(nfc_tag_h tag,  int sector_index, unsigned char * auth_key, nfc_mifare_authenticate_with_keyA_completed_cb callback, void *user_data)
 {
-
-       if( tag == NULL )
+       if (tag == NULL || auth_key == NULL)
                return _return_invalid_param(__func__);
 
        if(!nfc_manager_is_activated())
@@ -1557,7 +1610,7 @@ int nfc_mifare_authenticate_with_keyA(nfc_tag_h tag,  int sector_index, unsigned
 
        _async_callback_data * trans_data = NULL;
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1572,8 +1625,7 @@ int nfc_mifare_authenticate_with_keyA(nfc_tag_h tag,  int sector_index, unsigned
 
 int nfc_mifare_authenticate_with_keyB(nfc_tag_h tag,  int sector_index, unsigned char * auth_key, nfc_mifare_authenticate_with_keyB_completed_cb callback, void *user_data)
 {
-
-       if( tag == NULL )
+       if (tag == NULL || auth_key == NULL)
                return _return_invalid_param(__func__);
 
        if(!nfc_manager_is_activated())
@@ -1587,7 +1639,7 @@ int nfc_mifare_authenticate_with_keyB(nfc_tag_h tag,  int sector_index, unsigned
        net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1602,7 +1654,6 @@ int nfc_mifare_authenticate_with_keyB(nfc_tag_h tag,  int sector_index, unsigned
 
 int nfc_mifare_read_block(nfc_tag_h tag, int block_index, nfc_mifare_read_block_completed_cb callback, void *user_data)
 {
-
        if( tag == NULL )
                return _return_invalid_param(__func__);
 
@@ -1616,7 +1667,7 @@ int nfc_mifare_read_block(nfc_tag_h tag, int block_index, nfc_mifare_read_block_
        net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1631,6 +1682,9 @@ int nfc_mifare_read_block(nfc_tag_h tag, int block_index, nfc_mifare_read_block_
 
 int nfc_mifare_read_page(nfc_tag_h tag, int page_index, nfc_mifare_read_block_completed_cb callback, void *user_data)
 {
+       if (tag == NULL)
+               return _return_invalid_param(__func__);
+
        if(!nfc_manager_is_activated())
        {
                return NFC_ERROR_NOT_ACTIVATED;
@@ -1641,8 +1695,7 @@ int nfc_mifare_read_page(nfc_tag_h tag, int page_index, nfc_mifare_read_block_co
 
 int nfc_mifare_write_block (nfc_tag_h tag, int block_index, unsigned char* buffer, int buffer_size, nfc_mifare_write_block_completed_cb callback, void* user_data)
 {
-
-       if( tag == NULL )
+       if (tag == NULL || buffer == NULL || buffer_size <= 0)
                return _return_invalid_param(__func__);
 
        if(!nfc_manager_is_activated())
@@ -1656,7 +1709,7 @@ int nfc_mifare_write_block (nfc_tag_h tag, int block_index, unsigned char* buffe
        net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1671,8 +1724,7 @@ int nfc_mifare_write_block (nfc_tag_h tag, int block_index, unsigned char* buffe
 
 int nfc_mifare_write_page(nfc_tag_h tag, int page_index, unsigned char* buffer, int buffer_size, nfc_mifare_write_block_completed_cb callback, void* user_data)
 {
-
-       if( tag == NULL )
+       if (tag == NULL || buffer == NULL || buffer_size <= 0)
                return _return_invalid_param(__func__);
 
        if(!nfc_manager_is_activated())
@@ -1688,7 +1740,7 @@ int nfc_mifare_write_page(nfc_tag_h tag, int page_index, unsigned char* buffer,
 
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1703,7 +1755,6 @@ int nfc_mifare_write_page(nfc_tag_h tag, int page_index, unsigned char* buffer,
 
 int nfc_mifare_increment(nfc_tag_h tag, int block_index, int value, nfc_mifare_increment_completed_cb callback, void *user_data)
 {
-
        if( tag == NULL )
                return _return_invalid_param(__func__);
 
@@ -1717,7 +1768,7 @@ int nfc_mifare_increment(nfc_tag_h tag, int block_index, int value, nfc_mifare_i
        net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1733,7 +1784,6 @@ int nfc_mifare_increment(nfc_tag_h tag, int block_index, int value, nfc_mifare_i
 
 int nfc_mifare_decrement(nfc_tag_h tag, int block_index, int value, nfc_mifare_decrement_completed_cb callback, void *user_data)
 {
-
        if( tag == NULL )
                return _return_invalid_param(__func__);
 
@@ -1748,7 +1798,7 @@ int nfc_mifare_decrement(nfc_tag_h tag, int block_index, int value, nfc_mifare_d
 
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1763,7 +1813,6 @@ int nfc_mifare_decrement(nfc_tag_h tag, int block_index, int value, nfc_mifare_d
 
 int nfc_mifare_transfer(nfc_tag_h tag, int block_index, nfc_mifare_transfer_completed_cb callback, void *user_data)
 {
-
        if( tag == NULL )
                return _return_invalid_param(__func__);
 
@@ -1778,7 +1827,7 @@ int nfc_mifare_transfer(nfc_tag_h tag, int block_index, nfc_mifare_transfer_comp
 
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1793,7 +1842,6 @@ int nfc_mifare_transfer(nfc_tag_h tag, int block_index, nfc_mifare_transfer_comp
 
 int nfc_mifare_restore(nfc_tag_h tag, int block_index, nfc_mifare_restore_completed_cb callback, void *user_data)
 {
-
        if( tag == NULL )
                return _return_invalid_param(__func__);
 
@@ -1808,7 +1856,7 @@ int nfc_mifare_restore(nfc_tag_h tag, int block_index, nfc_mifare_restore_comple
        net_nfc_target_info_s *tag_info = (net_nfc_target_info_s*)tag;
 
        if( callback != NULL ){
-               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
+               trans_data = (_async_callback_data*)malloc( sizeof(_async_callback_data));
                if(trans_data == NULL )
                        return NFC_ERROR_OUT_OF_MEMORY;
                memset(trans_data , 0 , sizeof(_async_callback_data));
@@ -1821,7 +1869,8 @@ int nfc_mifare_restore(nfc_tag_h tag, int block_index, nfc_mifare_restore_comple
        return _convert_error_code(__func__, ret);
 }
 
-int nfc_p2p_send(nfc_p2p_target_h target , nfc_ndef_message_h message , nfc_p2p_send_completed_cb callback, void *user_data){
+int nfc_p2p_send(nfc_p2p_target_h target , nfc_ndef_message_h message , nfc_p2p_send_completed_cb callback, void *user_data)
+{
        int ret;
 
        if( target == NULL || message == NULL  )
@@ -1867,7 +1916,8 @@ int nfc_p2p_send(nfc_p2p_target_h target , nfc_ndef_message_h message , nfc_p2p_
        return 0;
 }
 
-int nfc_p2p_send_no_permission(nfc_p2p_target_h target , nfc_ndef_message_h message , nfc_p2p_send_completed_cb callback, void *user_data){
+int nfc_p2p_send_no_permission(nfc_p2p_target_h target , nfc_ndef_message_h message , nfc_p2p_send_completed_cb callback, void *user_data)
+{
        int ret;
 
        if( target == NULL || message == NULL  )
@@ -1910,6 +1960,7 @@ int nfc_p2p_send_no_permission(nfc_p2p_target_h target , nfc_ndef_message_h mess
 int nfc_p2p_connection_handover(nfc_p2p_target_h target , nfc_ac_type_e type, nfc_p2p_connection_handover_completed_cb callback, void *user_data){
        int ret;
        net_nfc_conn_handover_carrier_type_e net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+
        if( target == NULL  )
                return _return_invalid_param(__func__);
 
@@ -1922,22 +1973,22 @@ int nfc_p2p_connection_handover(nfc_p2p_target_h target , nfc_ac_type_e type, nf
        }
 
        switch( type ){
-               case NFC_AC_TYPE_BT:
-                       net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
-                       break;
-               case NFC_AC_TYPE_WIFI:
-                       net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;
-                       break;
-               case NFC_AC_TYPE_WIFI_DIRECT:
-                       net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;
-                       break;
-               case NFC_AC_TYPE_UNKNOWN :
-                       net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-                       break;
+       case NFC_AC_TYPE_BT:
+               net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+               break;
+       case NFC_AC_TYPE_WIFI:
+               net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS;
+               break;
+       case NFC_AC_TYPE_WIFI_DIRECT:
+               net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS;
+               break;
+       case NFC_AC_TYPE_UNKNOWN :
+               net_ac_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
+               break;
 
-               default:
-                       break;
-               }
+       default:
+               break;
+       }
        ret = net_nfc_exchanger_request_connection_handover((net_nfc_target_handle_h)target, net_ac_type);
 
        if( ret != 0 ){
@@ -1950,12 +2001,11 @@ int nfc_p2p_connection_handover(nfc_p2p_target_h target , nfc_ac_type_e type, nf
        return 0;
 }
 
-bool nfc_p2p_is_supported_ac_type( nfc_ac_type_e carrior){
-
+bool nfc_p2p_is_supported_ac_type( nfc_ac_type_e carrior)
+{
        if( carrior > NFC_AC_TYPE_UNKNOWN  )
                return false;
 
-
        if( carrior == NFC_AC_TYPE_BT){
                return true;
        }
@@ -1964,11 +2014,12 @@ bool nfc_p2p_is_supported_ac_type( nfc_ac_type_e carrior){
        }
 }
 
-int nfc_p2p_set_data_received_cb(nfc_p2p_target_h target, nfc_p2p_data_recived_cb callback, void *user_data){
+int nfc_p2p_set_data_received_cb(nfc_p2p_target_h target, nfc_p2p_data_recived_cb callback, void *user_data)
+{
        if( target == NULL || callback == NULL )
                return _return_invalid_param(__func__);
 
-//     if( g_nfc_context.current_target.connection_id != ((net_nfc_target_handle_s*)target)->connection_id )
+       //      if( g_nfc_context.current_target.connection_id != ((net_nfc_target_handle_s*)target)->connection_id )
        if(g_nfc_context.current_target != target )
                return _return_invalid_param(__func__);
 
@@ -1977,11 +2028,12 @@ int nfc_p2p_set_data_received_cb(nfc_p2p_target_h target, nfc_p2p_data_recived_c
        return 0;
 }
 
-int nfc_p2p_unset_data_received_cb(nfc_p2p_target_h target){
+int nfc_p2p_unset_data_received_cb(nfc_p2p_target_h target)
+{
        if( target == NULL )
                return _return_invalid_param(__func__);
 
-//     if( g_nfc_context.current_target.connection_id != ((net_nfc_target_handle_s*)target)->connection_id )
+       //      if( g_nfc_context.current_target.connection_id != ((net_nfc_target_handle_s*)target)->connection_id )
        if(g_nfc_context.current_target != target )
                return _return_invalid_param(__func__);
 
@@ -1990,9 +2042,11 @@ int nfc_p2p_unset_data_received_cb(nfc_p2p_target_h target){
        return 0;
 }
 
-int nfc_manager_set_p2p_target_discovered_cb( nfc_p2p_target_discovered_cb callback , void *user_data){
+int nfc_manager_set_p2p_target_discovered_cb( nfc_p2p_target_discovered_cb callback , void *user_data)
+{
        if( callback == NULL )
                return _return_invalid_param(__func__);
+
        g_nfc_context.on_p2p_discovered_cb = callback;
        g_nfc_context.on_p2p_discovered_user_data = user_data;
        return 0;
@@ -2003,28 +2057,34 @@ void nfc_manager_unset_p2p_target_discovered_cb( void ){
        g_nfc_context.on_p2p_discovered_user_data = NULL;
 }
 
-int nfc_manager_set_se_event_cb(nfc_se_event_cb callback, void *user_data){
+int nfc_manager_set_se_event_cb(nfc_se_event_cb callback, void *user_data)
+{
        if( callback == NULL )
                return _return_invalid_param(__func__);
+
        g_nfc_context.on_se_event_cb = callback;
        g_nfc_context.on_se_event_user_data = user_data;
        return 0;
 }
 
-void nfc_manager_unset_se_event_cb(void){
+void nfc_manager_unset_se_event_cb(void)
+{
        g_nfc_context.on_se_event_cb = NULL;
        g_nfc_context.on_se_event_user_data = NULL;
 }
 
-int nfc_manager_set_se_transaction_event_cb(nfc_se_transaction_event_cb callback, void *user_data){
+int nfc_manager_set_se_transaction_event_cb(nfc_se_transaction_event_cb callback, void *user_data)
+{
        if( callback == NULL )
                return _return_invalid_param(__func__);
+
        g_nfc_context.on_se_transaction_event_cb = callback;
        g_nfc_context.on_se_transaction_event_user_data = user_data;
        return 0;
 }
 
-void nfc_manager_unset_se_transaction_event_cb(void){
+void nfc_manager_unset_se_transaction_event_cb(void)
+{
        g_nfc_context.on_se_transaction_event_cb = NULL;
        g_nfc_context.on_se_transaction_event_user_data = NULL;
 }