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.
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"
28 static void run_next_callback(gpointer user_data);
30 static void p2p_connection_handover_cb(net_nfc_error_e result,
31 net_nfc_conn_handover_carrier_type_e type,
35 static net_nfc_connection_handover_info_s *global_info = NULL;
38 static void run_next_callback(gpointer user_data)
43 callback = (GCallback)(user_data);
48 static void p2p_connection_handover_cb(net_nfc_error_e result,
49 net_nfc_conn_handover_carrier_type_e type,
53 g_print("Connection handover completed\n");
55 print_received_data(data);
57 global_info->type = type;
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);
67 run_next_callback(user_data);
70 static void _p2p_connection_handover(
71 net_nfc_conn_handover_carrier_type_e type, gpointer user_data)
73 net_nfc_error_e result = NET_NFC_OK;
74 net_nfc_target_handle_s *handle = NULL;
76 handle = net_nfc_test_device_get_target_handle();
78 g_print("handle for handover : %p \n", handle);
80 result = net_nfc_client_p2p_connection_handover(
83 p2p_connection_handover_cb,
85 g_print("net_nfc_client_p2p_connection_handover() : %d\n", result);
88 static void _p2p_connection_handover_sync(
89 net_nfc_conn_handover_carrier_type_e type, gpointer user_data)
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;
96 handle = net_nfc_test_device_get_target_handle();
98 result = net_nfc_client_p2p_connection_handover_sync(
103 g_print("net_nfc_client_p2p_connection_handover_sync() : %d\n", result);
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);
110 void net_nfc_test_p2p_connection_handover_with_BT(gpointer data,
113 _p2p_connection_handover(NET_NFC_CONN_HANDOVER_CARRIER_BT, user_data);
116 void net_nfc_test_p2p_connection_handover_with_WIFI(gpointer data,
119 _p2p_connection_handover(NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, user_data);
122 void net_nfc_test_p2p_connection_handover_with_BT_sync(gpointer data,
125 _p2p_connection_handover_sync(NET_NFC_CONN_HANDOVER_CARRIER_BT, user_data);
128 void net_nfc_test_p2p_connection_handover_with_WIFI_sync(gpointer data,
131 _p2p_connection_handover_sync(NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS, user_data);
134 void net_nfc_test_handover_get_alternative_carrier_type(gpointer data,
137 net_nfc_error_e result = NET_NFC_OK;
138 net_nfc_conn_handover_carrier_type_e type;
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);
145 void net_nfc_test_handover_handle_alternative_carrier_data(gpointer data,
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;
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);
156 hand_info = global_info;
158 result = net_nfc_client_handover_free_alternative_carrier_data(hand_info);
159 g_print("Free alternative carrier data %d", result);