Remove unnecessary setting
[platform/core/connectivity/nfc-manager-neard.git] / tests / net_nfc_test_tag.c
1 /*
2  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  *                               http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17
18 #include <glib-object.h>
19
20 #include "net_nfc_typedef_internal.h"
21 #include "net_nfc_client_tag.h"
22 #include "net_nfc_test_tag.h"
23
24 static net_nfc_target_info_s *global_info = NULL;
25
26 static void run_next_callback(gpointer user_data)
27 {
28         if (user_data)
29         {
30                 GCallback callback;
31
32                 callback = (GCallback)(user_data);
33
34                 callback();
35         }
36 }
37 #if 0
38 static gchar *tag_type_to_string(net_nfc_target_type_e dev_type)
39 {
40         switch(dev_type)
41         {
42         case NET_NFC_UNKNOWN_TARGET:
43                 return "Unknown Target";
44         case NET_NFC_GENERIC_PICC:
45                 return "Generic PICC";
46         case NET_NFC_ISO14443_A_PICC:
47                 return "ISO14443 PICC";
48         case NET_NFC_ISO14443_4A_PICC:
49                 return "ISO14443 4A PICC";
50         case NET_NFC_ISO14443_3A_PICC:
51                 return "ISO14443 3A PICC";
52         case NET_NFC_MIFARE_MINI_PICC:
53                 return "Mifare mini PICC";
54         case NET_NFC_MIFARE_1K_PICC:
55                 return "Mifare 1K PICC";
56         case NET_NFC_MIFARE_4K_PICC:
57                 return "Mifare 4K PICC";
58         case NET_NFC_MIFARE_ULTRA_PICC:
59                 return "Mifare Ultra PICC";
60         case NET_NFC_MIFARE_DESFIRE_PICC:
61                 return "Mifare Desfire PICC";
62         case NET_NFC_ISO14443_B_PICC:
63                 return "ISO14443 B PICC";
64         case NET_NFC_ISO14443_4B_PICC:
65                 return "ISO14443 4B PICC";
66         case NET_NFC_ISO14443_BPRIME_PICC:
67                 return "ISO14443 BPRIME PICC";
68         case NET_NFC_FELICA_PICC:
69                 return "Felica PICC";
70         case NET_NFC_JEWEL_PICC:
71                 return "Jewel PICC";
72         case NET_NFC_ISO15693_PICC:
73                 return "ISO15693 PICC";
74         case NET_NFC_NFCIP1_TARGET:
75                 return "NFCIP1 Target";
76         case NET_NFC_NFCIP1_INITIATOR:
77                 return "NFCIP1 Initiator";
78         default:
79                 break;
80         }
81         return "Invalid Target";
82 }
83 #endif
84 static void print_is_tag_connected(net_nfc_target_type_e dev_type)
85 {
86         if (global_info)
87         {
88                 net_nfc_target_type_e type;
89
90                 net_nfc_get_tag_type(global_info, &type);
91
92                 if(dev_type == type)
93                         g_print("DevType is same as Discovered tag\n");
94         }
95 }
96
97 static void print_get_current_target_handle(net_nfc_target_handle_s *handle)
98 {
99         net_nfc_target_handle_s *global_handle;
100         guint global_handle_id;
101         guint handle_id;
102
103         net_nfc_get_tag_handle(global_info, &global_handle);
104
105         global_handle_id = GPOINTER_TO_UINT(global_handle);
106         handle_id = GPOINTER_TO_UINT(handle);
107
108         g_print("Tag handle %x, Current Tag handle %x\n",
109                         global_handle_id,
110                         handle_id);
111         if (global_handle_id == handle_id)
112                 g_print("Current Tag is matched discovered Tag\n");
113 }
114
115 static void print_get_current_tag_info(net_nfc_target_info_s *info)
116 {
117         net_nfc_target_handle_s *handle;
118
119         if (global_info == NULL)
120         {
121                 g_print("Discovered tag info does not exist\n");
122                 return;
123         }
124
125         if (info == NULL)
126         {
127                 g_print("Current tag info does not exist\n");
128                 return;
129         }
130
131         net_nfc_get_tag_handle(info, &handle);
132         print_get_current_target_handle(handle);
133
134         return;
135 }
136
137 static void tag_detached(void *user_data)
138 {
139         g_print("TagDetached\n");
140 }
141 #if 0
142 static void is_tag_connected_completed(net_nfc_error_e result,
143                 net_nfc_target_type_e dev_type,
144                 void *user_data)
145 {
146         g_print("IsTagConnected Completed %d\n", result);
147         g_print("--- dev type : %s (%d)\n", tag_type_to_string(dev_type),
148                         dev_type);
149
150         if (result == NET_NFC_OK)
151                 print_is_tag_connected(dev_type);
152         else if (result == NET_NFC_NOT_CONNECTED)
153                 g_print("NET_NFC_NOT_CONNECTED\n");
154
155         run_next_callback(user_data);
156 }
157
158 static void get_current_tag_info_completed(net_nfc_error_e result,
159                 net_nfc_target_info_s *info, void *user_data)
160 {
161         g_print("GetCurrentTagInfo Completed %d\n", result);
162
163         if (result == NET_NFC_OK)
164                 print_get_current_tag_info(info);
165
166         run_next_callback(user_data);
167 }
168
169 static void get_current_target_handle_completed(net_nfc_error_e result,
170                 net_nfc_target_handle_s *handle, void *user_data)
171 {
172         g_print("GetCurrentTargetHandle Completed %d\n", result);
173
174         if (result == NET_NFC_OK)
175                 print_get_current_target_handle(handle);
176
177         run_next_callback(user_data);
178 }
179 #endif
180
181
182 static void tag_discovered(net_nfc_target_info_s *info, void *user_data)
183 {
184         g_print("TagDiscovered\n");
185
186         net_nfc_duplicate_target_info(info, &global_info);
187
188         run_next_callback(user_data);
189 }
190
191
192 #if 0
193 void net_nfc_test_tag_is_tag_connected(gpointer data, gpointer user_data)
194 {
195         net_nfc_client_tag_is_tag_connected(is_tag_connected_completed,
196                         user_data);
197 }
198
199 void net_nfc_test_tag_get_current_tag_info(gpointer data, gpointer user_data)
200 {
201         net_nfc_client_tag_get_current_tag_info(get_current_tag_info_completed,
202                         user_data);
203 }
204
205 void net_nfc_test_tag_get_current_target_handle(gpointer data,
206                 gpointer user_data)
207 {
208         net_nfc_client_tag_get_current_target_handle(
209                         get_current_target_handle_completed,
210                         user_data);
211 }
212 #endif
213 void net_nfc_test_tag_is_tag_connected_sync(gpointer data, gpointer user_data)
214 {
215         net_nfc_error_e result;
216         net_nfc_target_type_e dev_type;
217
218         result = net_nfc_client_tag_is_tag_connected_sync(&dev_type);
219
220         if (result == NET_NFC_OK)
221                 print_is_tag_connected(dev_type);
222         else if (result == NET_NFC_NOT_CONNECTED)
223                 g_print("NET_NFC_NOT_CONNECTED\n");
224
225         run_next_callback(user_data);
226 }
227
228 void net_nfc_test_tag_get_current_tag_info_sync(gpointer data,
229                 gpointer user_data)
230 {
231         net_nfc_error_e result;
232         net_nfc_target_info_s *info;
233
234         result = net_nfc_client_tag_get_current_tag_info_sync(&info);
235
236         if (result == NET_NFC_OK)
237                 print_get_current_tag_info(info);
238
239         run_next_callback(user_data);
240 }
241
242 void net_nfc_test_tag_get_current_target_handle_sync(gpointer data,
243                 gpointer user_data)
244 {
245         net_nfc_error_e result;
246         net_nfc_target_handle_s *handle;
247
248         result = net_nfc_client_tag_get_current_target_handle_sync(&handle);
249
250         if (result == NET_NFC_OK)
251                 print_get_current_target_handle(handle);
252
253         run_next_callback(user_data);
254 }
255
256 void net_nfc_test_tag_set_tag_discovered(gpointer data, gpointer user_data)
257 {
258         g_print("Waiting for TagDiscovered Signal\n");
259
260         net_nfc_client_tag_unset_tag_detached();
261
262         net_nfc_client_tag_set_tag_detached(tag_detached, NULL);
263
264         net_nfc_client_tag_unset_tag_discovered();
265
266         net_nfc_client_tag_set_tag_discovered(tag_discovered, user_data);
267 }
268
269 net_nfc_target_info_s* net_nfc_test_tag_get_target_info(void)
270 {
271         return global_info;
272 }
273
274 void net_nfc_test_tag_set_tag_detached(gpointer data, gpointer user_data)
275 {
276         g_print("Waiting for TagDetached Singal\n");
277
278         net_nfc_client_tag_set_tag_detached(tag_detached, NULL);
279 }
280
281 void net_nfc_test_tag_set_filter(gpointer data, gpointer user_data)
282 {
283         net_nfc_event_filter_e filter = NET_NFC_ALL_ENABLE;
284
285         net_nfc_client_tag_set_filter(filter);
286 }
287
288 void net_nfc_test_tag_get_filter(gpointer data, gpointer user_data)
289 {
290         net_nfc_event_filter_e filter = NET_NFC_ALL_DISABLE;
291
292         filter = net_nfc_client_tag_get_filter();
293
294         g_print(" NFC tag filter = %d", filter);
295 }