2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
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.
17 #include "nfc_common.h"
19 _nfc_context_s gdbus_nfc_context;
22 pid_t nfc_common_get_focus_app_pid()
27 ret = aul_window_get_focused_pid(&pid);
29 if (ret == AUL_R_OK) {
32 LOGD("aul_window_get_focused_pid is failed");
37 char * nfc_common_get_bt_address_string(data_h data)
45 buffer = net_nfc_get_data_buffer(data);
46 length = net_nfc_get_data_length(data);
48 if (buffer == NULL || length < 6)
51 return g_strdup_printf("%02X:%02X:%02X:%02X:%02X:%02X",
60 bool nfc_common_check_app_permission()
62 pid_t focus_app_pid, current_app_pid;
64 focus_app_pid = nfc_common_get_focus_app_pid();
65 current_app_pid = getpgid(getpid());
67 LOGD("[check app permission] focus_app_pid [%d], current_app_pid [%d]", focus_app_pid,
70 return (focus_app_pid == current_app_pid) ? true : false;
73 int nfc_common_convert_error_code(const char *func, int native_error_code)
75 int error_code = NFC_ERROR_NONE;
76 char *errorstr = NULL;
78 switch (native_error_code) {
80 error_code = NFC_ERROR_NONE;
81 errorstr = "ERROR_NONE";
84 case NET_NFC_ALLOC_FAIL:
85 error_code = NFC_ERROR_OUT_OF_MEMORY;
86 errorstr = "OUT_OF_MEMORY";
89 case NET_NFC_NOT_CONNECTED:
90 error_code = NFC_ERROR_NO_DEVICE;
91 errorstr = "NO_DEVICE";
94 case NET_NFC_UNKNOWN_ERROR:
95 case NET_NFC_THREAD_CREATE_FAIL:
96 case NET_NFC_IPC_FAIL:
97 case NET_NFC_BUFFER_TOO_SMALL:
98 case NET_NFC_COMMUNICATE_WITH_CONTROLLER_FAILED:
99 case NET_NFC_RF_ERROR:
100 case NET_NFC_NOT_SUPPORTED:
101 case NET_NFC_TAG_READ_FAILED:
102 case NET_NFC_TAG_WRITE_FAILED:
103 case NET_NFC_OPERATION_FAIL:
104 case NET_NFC_INSUFFICIENT_STORAGE:
105 case NET_NFC_NOT_INITIALIZED:
106 case NET_NFC_NOT_REGISTERED:
107 case NET_NFC_NO_DATA_FOUND:
108 case NET_NFC_NOT_ALLOWED_OPERATION:
109 error_code = NFC_ERROR_OPERATION_FAILED;
110 errorstr = "OPERATION_FAILED";
113 case NET_NFC_SECURITY_FAIL:
114 error_code = NFC_ERROR_SECURITY_RESTRICTED;
115 errorstr = "SECURITY_RESTRICTED";
118 case NET_NFC_INVALID_STATE:
119 error_code = NFC_ERROR_ILLEGAL_STATE;
120 errorstr = "ILLEGAL_STATE";
123 case NET_NFC_OUT_OF_BOUND:
124 case NET_NFC_NULL_PARAMETER:
125 case NET_NFC_LLCP_INVALID_SOCKET:
126 error_code = NFC_ERROR_INVALID_PARAMETER;
127 errorstr = "INVALID_PARAMETER";
129 case NET_NFC_NDEF_RECORD_IS_NOT_EXPECTED_TYPE:
130 error_code = NFC_ERROR_INVALID_RECORD_TYPE;
131 errorstr = "INVALID_RECORD_TYPE";
134 case NET_NFC_ALREADY_INITIALIZED:
135 case NET_NFC_ALREADY_REGISTERED:
136 error_code = NFC_ERROR_NONE;
137 errorstr = "ERROR_NONE";
140 case NET_NFC_RF_TIMEOUT:
141 error_code = NFC_ERROR_TIMED_OUT;
142 errorstr = "TIMED_OUT";
144 case NET_NFC_INVALID_FORMAT:
145 case NET_NFC_NDEF_TYPE_LENGTH_IS_NOT_OK:
146 case NET_NFC_NDEF_ID_LENGTH_IS_NOT_OK:
147 case NET_NFC_NDEF_BUF_END_WITHOUT_ME:
148 error_code = NFC_ERROR_INVALID_NDEF_MESSAGE;
149 errorstr = "INVALID_NDEF_MESSAGE";
151 case NET_NFC_NO_NDEF_MESSAGE:
152 error_code = NFC_ERROR_NO_NDEF_MESSAGE;
153 errorstr = "NO_NDEF_MESSAGE";
156 error_code = NFC_ERROR_DEVICE_BUSY;
157 errorstr = "DEVICE_BUSY";
159 case NET_NFC_NO_NDEF_SUPPORT:
160 error_code = NFC_ERROR_NOT_NDEF_FORMAT;
161 errorstr = "NOT_SUPPORTED";
163 case NET_NFC_PERMISSION_DENIED:
164 error_code = NFC_ERROR_PERMISSION_DENIED;
165 errorstr = "PERMISSION_DENIED";
167 case NET_NFC_NOT_ACTIVATED:
168 error_code = NFC_ERROR_NOT_ACTIVATED;
169 errorstr = "NOT_ACTIVATED";
171 case NET_NFC_DATA_CONFLICTED:
172 error_code = NFC_ERROR_DATA_CONFLICTED;
173 errorstr = "DATA_CONFLICTED";
176 error_code = NFC_ERROR_OPERATION_FAILED;
177 errorstr = "OPERATION_FAILED";
180 if (error_code != NFC_ERROR_NONE)
181 LOGE("NFC func : %s, %s(0x%08x)", func, errorstr, error_code);
186 bool nfc_common_is_initialized()
188 return gdbus_nfc_context.initialized;
191 bool nfc_common_is_supported(char *str)
196 ret = system_info_get_platform_bool(str, &is_supported);
204 int nfc_common_get_rawdata_size(nfc_ndef_message_h ndef_message,
205 unsigned int *byte_size)
211 CHECK_SUPPORTED(NFC_FEATURE);
213 CHECK_INVALID(ndef_message == NULL);
214 CHECK_INVALID(byte_size == NULL);
216 ret = net_nfc_get_ndef_message_byte_length(ndef_message,
217 (unsigned int *)byte_size);
219 return nfc_common_convert_error_code(__func__, ret);