Remove unnecessary setting
[platform/core/connectivity/nfc-manager-neard.git] / tests / net_nfc_test_handover.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 "net_nfc_client_handover.h"
19 #include "net_nfc_test_handover.h"
20 #include "net_nfc_test_util.h"
21 #include "net_nfc_target_info.h"
22 #include "net_nfc_typedef_internal.h"
23 #include "net_nfc_typedef.h"
24 #include "net_nfc_test_p2p.h"
25 #include "net_nfc_util_internal.h"
26
27
28 static void run_next_callback(gpointer user_data);
29
30 static void p2p_connection_handover_cb(net_nfc_error_e result,
31                 net_nfc_conn_handover_carrier_type_e type,
32                 data_s *data,
33                 void *user_data);
34
35 static net_nfc_connection_handover_info_s *global_info = NULL;
36
37
38 static void run_next_callback(gpointer user_data)
39 {
40         if (user_data)
41         {
42                 GCallback callback;
43                 callback = (GCallback)(user_data);
44                 callback();
45         }
46 }
47
48 static void p2p_connection_handover_cb(net_nfc_error_e result,
49                 net_nfc_conn_handover_carrier_type_e type,
50                 data_s *data,
51                 void *user_data)
52 {
53         g_print("Connection handover completed\n");
54
55         print_received_data(data);
56
57         global_info->type = type;
58
59         if(data->length > 0)
60         {
61                 g_print("Callback has valid data \n");
62                 global_info->data.buffer = data->buffer;
63                 global_info->data.length = data->length;
64                 print_received_data(&global_info->data);
65         }
66
67         run_next_callback(user_data);
68 }
69
70 static void _p2p_connection_handover(
71                 net_nfc_conn_handover_carrier_type_e type, gpointer user_data)
72 {
73         net_nfc_error_e result = NET_NFC_OK;
74         net_nfc_target_handle_s *handle = NULL;
75
76         handle = net_nfc_test_device_get_target_handle();
77
78         g_print("handle for handover : %p \n", handle);
79
80         result = net_nfc_client_p2p_connection_handover(
81                         handle,
82                         type,
83                         p2p_connection_handover_cb,
84                         user_data);
85         g_print("net_nfc_client_p2p_connection_handover() : %d\n", result);
86 }
87
88 static void _p2p_connection_handover_sync(
89                 net_nfc_conn_handover_carrier_type_e type, gpointer user_data)
90 {
91         net_nfc_error_e result = NET_NFC_OK;
92         net_nfc_conn_handover_carrier_type_e out_carrier;
93         data_s *out_data = NULL;
94         net_nfc_target_handle_s *handle = NULL;
95
96         handle = net_nfc_test_device_get_target_handle();
97
98         result = net_nfc_client_p2p_connection_handover_sync(
99                         handle,
100                         type,
101                         &out_carrier,
102                         &out_data);
103         g_print("net_nfc_client_p2p_connection_handover_sync() : %d\n", result);
104
105         g_print("Received out carrier type & carrier type  %d, %d\n", out_carrier, type);
106         print_received_data(out_data);
107         run_next_callback(user_data);
108 }
109
110 void net_nfc_test_p2p_connection_handover_with_BT(gpointer data,
111                 gpointer user_data)
112 {
113         _p2p_connection_handover(NET_NFC_CONN_HANDOVER_CARRIER_BT, user_data);
114 }
115
116 void net_nfc_test_p2p_connection_handover_with_WIFI(gpointer data,
117                 gpointer user_data)
118 {
119         _p2p_connection_handover(NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, user_data);
120 }
121
122 void net_nfc_test_p2p_connection_handover_with_BT_sync(gpointer data,
123                 gpointer user_data)
124 {
125         _p2p_connection_handover_sync(NET_NFC_CONN_HANDOVER_CARRIER_BT, user_data);
126 }
127
128 void net_nfc_test_p2p_connection_handover_with_WIFI_sync(gpointer data,
129                 gpointer user_data)
130 {
131         _p2p_connection_handover_sync(NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, user_data);
132 }
133
134 void net_nfc_test_handover_get_alternative_carrier_type(gpointer data,
135                 gpointer user_data)
136 {
137         net_nfc_error_e result = NET_NFC_OK;
138         net_nfc_conn_handover_carrier_type_e type;
139
140         result = net_nfc_client_handover_get_alternative_carrier_type(global_info, &type);
141         g_print("net_nfc_client_handover_get_alternative_carrier_type() : %d\n", result);
142         g_print("Handover alternative carrier type -> %d", type);
143 }
144
145 void net_nfc_test_handover_handle_alternative_carrier_data(gpointer data,
146                 gpointer user_data)
147 {
148         net_nfc_error_e result = NET_NFC_OK;
149         data_s *out_data = NULL;
150         net_nfc_connection_handover_info_s *hand_info = NULL;
151
152         result = net_nfc_client_handover_get_alternative_carrier_data(global_info, &out_data);
153         g_print(" Get alternative carrier data  %d", result);
154         print_received_data(out_data);
155
156         hand_info = global_info;
157
158         result = net_nfc_client_handover_free_alternative_carrier_data(hand_info);
159         g_print("Free alternative carrier data  %d", result);
160 }