From de460b91facdc8f4f468440440c0234f7cc0132b Mon Sep 17 00:00:00 2001 From: Abhijit R D Date: Mon, 26 Aug 2013 11:53:01 +0530 Subject: [PATCH] BSS Handover implementation Added implmentation of Static Handover over WIFI Change-Id: I441578438b5c8482a42b7b767ea086c5b508deac --- packaging/nfc-manager.spec | 1 + src/commonlib/net_nfc_util_handover.c | 8 +- src/manager/CMakeLists.txt | 2 +- src/manager/include/net_nfc_server_handover_bss.h | 47 ++ .../include/net_nfc_server_process_handover.h | 14 + src/manager/net_nfc_server_handover_bss.c | 575 +++++++++++++++++++++ src/manager/net_nfc_server_process_handover.c | 17 +- src/manager/net_nfc_server_tag.c | 66 ++- 8 files changed, 702 insertions(+), 28 deletions(-) create mode 100644 src/manager/include/net_nfc_server_handover_bss.h create mode 100644 src/manager/net_nfc_server_handover_bss.c diff --git a/packaging/nfc-manager.spec b/packaging/nfc-manager.spec index 321243b..d66805e 100644 --- a/packaging/nfc-manager.spec +++ b/packaging/nfc-manager.spec @@ -17,6 +17,7 @@ BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(bluetooth-api) +BuildRequires: pkgconfig(capi-network-wifi) BuildRequires: pkgconfig(mm-sound) BuildRequires: pkgconfig(appsvc) BuildRequires: pkgconfig(svi) diff --git a/src/commonlib/net_nfc_util_handover.c b/src/commonlib/net_nfc_util_handover.c index 3497b0c..de399ab 100644 --- a/src/commonlib/net_nfc_util_handover.c +++ b/src/commonlib/net_nfc_util_handover.c @@ -607,23 +607,23 @@ net_nfc_error_e net_nfc_util_create_ndef_record_with_carrier_config(ndef_record_ static net_nfc_error_e __net_nfc_get_list_from_serial_for_wifi(GList **list, uint8_t *data, uint32_t length) { - net_nfc_carrier_property_s *elem = NULL; uint8_t *current = data; uint8_t *last = current + length; while (current < last) { + net_nfc_carrier_property_s *elem = NULL; _net_nfc_util_alloc_mem(elem, sizeof(net_nfc_carrier_property_s)); if (elem == NULL) { return NET_NFC_ALLOC_FAIL; } - elem->attribute = *((uint16_t *)current); - elem->length = *((uint16_t *)(current + 2)); + elem->attribute = current[0]<<8|current[1]; + elem->length = current[2]<<8|current[3]; if (elem->attribute == NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL) { - __net_nfc_get_list_from_serial_for_wifi((GList **)&(elem->data), (current + 4), elem->length); + __net_nfc_get_list_from_serial_for_wifi(list, (current + 4), elem->length); elem->is_group = true; } else diff --git a/src/manager/CMakeLists.txt b/src/manager/CMakeLists.txt index 2499651..af454bf 100644 --- a/src/manager/CMakeLists.txt +++ b/src/manager/CMakeLists.txt @@ -15,7 +15,7 @@ IF("${CMAKE_BUILD_TYPE}" STREQUAL "") ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") INCLUDE(FindPkgConfig) -pkg_check_modules(manager_pkges REQUIRED aul glib-2.0 gio-unix-2.0 security-server vconf dlog tapi appsvc libcurl bluetooth-api libssl svi capi-media-wav-player pkgmgr pkgmgr-info ecore-x pmapi) +pkg_check_modules(manager_pkges REQUIRED aul glib-2.0 gio-unix-2.0 security-server vconf dlog tapi appsvc libcurl bluetooth-api libssl svi capi-media-wav-player pkgmgr pkgmgr-info capi-network-wifi ecore-x pmapi) FOREACH(flag ${manager_pkges_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) diff --git a/src/manager/include/net_nfc_server_handover_bss.h b/src/manager/include/net_nfc_server_handover_bss.h new file mode 100644 index 0000000..947a8bd --- /dev/null +++ b/src/manager/include/net_nfc_server_handover_bss.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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. + */ + + +#ifndef __NET_NFC_SERVER_HANDOVER_BSS_H__ +#define __NET_NFC_SERVER_HANDOVER_BSS_H__ +#include +#include +#include "net_nfc_debug_internal.h" +#include "net_nfc_util_internal.h" +#include "net_nfc_util_ndef_message.h" +#include "net_nfc_util_ndef_record.h" +#include "net_nfc_util_handover.h" +#include "net_nfc_server_handover_internal.h" +#include "net_nfc_server_llcp.h" + +typedef struct _net_nfc_handover_bss_process_context_t +{ + int step; + net_nfc_error_e result; + net_nfc_server_handover_process_carrier_record_cb cb; + ndef_record_s *carrier; + data_s data; + void *user_param; + wifi_ap_h ap_handle; + net_nfc_carrier_config_s *config; +} +net_nfc_handover_bss_process_context_t; + +net_nfc_error_e net_nfc_server_handover_bss_process_carrier_record( + ndef_record_s *record, + net_nfc_server_handover_process_carrier_record_cb cb, + void *user_param); +#endif //__NET_NFC_SERVER_HANDOVER_BSS_H__ diff --git a/src/manager/include/net_nfc_server_process_handover.h b/src/manager/include/net_nfc_server_process_handover.h index 3eb59e3..e21fa55 100644 --- a/src/manager/include/net_nfc_server_process_handover.h +++ b/src/manager/include/net_nfc_server_process_handover.h @@ -29,4 +29,18 @@ net_nfc_error_e net_nfc_server_handover_default_server_register(); net_nfc_error_e net_nfc_server_handover_default_server_unregister(); +net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata( + ndef_message_s **selector, + data_s *data); + +net_nfc_error_e +_net_nfc_server_handover_get_carrier_record_by_priority_order( + ndef_message_s *request, + ndef_record_s **record); + +net_nfc_error_e _net_nfc_server_handover_process_carrier_record( + ndef_record_s *carrier, + void *cb, + void *user_param); + #endif //__NET_NFC_SERVER_PROCESS_HANDOVER_H__ diff --git a/src/manager/net_nfc_server_handover_bss.c b/src/manager/net_nfc_server_handover_bss.c new file mode 100644 index 0000000..835bda1 --- /dev/null +++ b/src/manager/net_nfc_server_handover_bss.c @@ -0,0 +1,575 @@ +/* + * Copyright (c) 2013 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * 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 "net_nfc_util_handover.h" +#include "net_nfc_server_handover_bss.h" + +static int _net_nfc_handover_bss_process_carrier_record( + net_nfc_handover_bss_process_context_t *context); + +int _net_nfc_handover_bss_convert_security_type(int value) +{ + int retval = 0; + switch (value) + { + case 0x0001: /* Open */ + retval = WIFI_SECURITY_TYPE_NONE; + break; + case 0x0002: /* WPA - Personal */ + retval = WIFI_SECURITY_TYPE_WPA_PSK; + break; + case 0x0004: /* WPA - Shared */ + retval = WIFI_SECURITY_TYPE_WEP; + break; + case 0x0008: /* WPA - Enterprise */ + case 0x0010: /* WPA2 - Enterprise */ + retval = WIFI_SECURITY_TYPE_EAP; + break; + case 0x0020: /* WPA2 - Personal */ + retval = WIFI_SECURITY_TYPE_WPA_PSK; + break; + default: + DEBUG_ERR_MSG("Invalid security Type"); + retval = 0; + } + return retval; +} + +int _net_nfc_handover_bss_convert_encryption_type (int enc_type) +{ + int retval = 0; + switch (enc_type) + { + case 0x0001: /* None */ + retval = WIFI_ENCRYPTION_TYPE_NONE; + break; + case 0x0002: /* WEP */ + retval = WIFI_ENCRYPTION_TYPE_WEP; + break; + case 0x0004: /* TKIP */ + retval = WIFI_ENCRYPTION_TYPE_TKIP; + break; + case 0x0008: /* AES */ + retval = WIFI_ENCRYPTION_TYPE_AES; + break; + case 0x000C: /* TKIP + AES */ + retval = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED; + break; + default: + DEBUG_ERR_MSG("Invalid Encryption type"); + retval = 0; + } + return retval; +} + +wifi_ap_h +_net_nfc_handover_bss_create_ap(net_nfc_carrier_config_s *config) +{ + wifi_ap_h ap_handle = NULL; + data_s temp = { NULL, 0 }; + int err = WIFI_ERROR_NONE; + + // Sets SSID + err = net_nfc_util_get_carrier_config_property(config, + NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp.length, &temp.buffer); + DEBUG_SERVER_MSG("SSID = [%s] err %d",temp.buffer, err); + err = wifi_ap_create((char*)temp.buffer, &ap_handle); + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("Failed to create AP information %d",err); + goto error; + } + + // Sets Authentication Type + net_nfc_util_get_carrier_config_property(config, + NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE,(uint16_t *)&temp.length, &temp.buffer); + if(temp.length == 2) + { + uint16_t securitytype = temp.buffer[0] <<8 | temp.buffer[1]; + DEBUG_MSG("wifi_ap_set_security_type %x", securitytype); + err = wifi_ap_set_security_type(ap_handle, + _net_nfc_handover_bss_convert_security_type(securitytype)); + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("set security type failed"); + goto error; + } + } + else + { + DEBUG_ERR_MSG("Invalid authentication length"); + goto error; + } + net_nfc_util_get_carrier_config_property(config, + NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length, &temp.buffer); + + // Sets Network Key + err = wifi_ap_set_passphrase(ap_handle,(char*)temp.buffer); + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("Failed to set passphrase"); + goto error; + } + // Sets encryption Type + net_nfc_util_get_carrier_config_property(config, + NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE,(uint16_t *)&temp.length, &temp.buffer); + if(temp.length == 2) + { + uint16_t enc_type = temp.buffer[0] <<8 | temp.buffer[1]; + DEBUG_MSG("wifi_ap_set_encryption_type %x", enc_type); + err = wifi_ap_set_encryption_type(ap_handle, + _net_nfc_handover_bss_convert_encryption_type(enc_type)); + } + else + { + DEBUG_ERR_MSG("Invalid Encryption length"); + goto error; + } + return ap_handle; +error: + if(ap_handle != NULL) + { + wifi_ap_destroy(ap_handle); + } + return NULL; +} + +void +_net_nfc_handover_bss_on_wifi_activated(wifi_error_e errorCode, void* user_data) +{ + net_nfc_handover_bss_process_context_t *context = user_data; + if(context == NULL) + { + DEBUG_ERR_MSG("Invalid context"); + context->result = NET_NFC_OPERATION_FAIL; + } + if (errorCode == WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("WIFI activated succesfully"); + context->result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("Failed to activate WIFI"); + context->result = NET_NFC_OPERATION_FAIL; + } +} + +bool +_net_nfc_handover_bss_wifi_for_each_access_point_found( + wifi_ap_h ap_handle, void *user_data) +{ + data_s temp_ssid = { NULL, 0 }; + int err = WIFI_ERROR_NONE; + char* essid = NULL; + net_nfc_handover_bss_process_context_t *context = user_data; + + if(context == NULL) + { + DEBUG_ERR_MSG("Invalid context"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + return false; + } + + wifi_ap_clone(&context->ap_handle, ap_handle); + err = net_nfc_util_get_carrier_config_property(context->config, + NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp_ssid.length, + &temp_ssid.buffer); + + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("Wifi get carrier config failed"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + return false; + } + + wifi_ap_get_essid(ap_handle, &essid); + DEBUG_MSG("Scan Result Ap essid [%s]",essid); + if(memcmp(temp_ssid.buffer, essid,temp_ssid.length) == 0) + { + return false; + } + else + { + wifi_ap_destroy(context->ap_handle); + context->ap_handle = NULL; + } + return true; +} + +void +_net_nfc_handover_bss_on_wifi_bgscan_completed(wifi_error_e errorCode, + void* user_data) +{ + int err = WIFI_ERROR_NONE; + net_nfc_handover_bss_process_context_t *context = user_data; + + if(context == NULL) + { + DEBUG_ERR_MSG("Invalid context"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + return false; + } + + if(errorCode != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("Wifi scan failed"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + else + { + net_nfc_util_create_carrier_config_from_config_record( + &context->config, context->carrier); + context->ap_handle = NULL; + err = wifi_foreach_found_aps( + _net_nfc_handover_bss_wifi_for_each_access_point_found, + context); + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("wifi_foreach_found_aps failed Err[%x]",err); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + if(context->ap_handle == NULL) + { + wifi_encryption_type_e enc_type; + wifi_security_type_e sec_type; + DEBUG_MSG("It's Hidden AP"); + context->ap_handle = _net_nfc_handover_bss_create_ap( + context->config); + wifi_ap_get_encryption_type(context->ap_handle, &enc_type); + DEBUG_MSG("Encryption type %x",enc_type); + wifi_ap_get_security_type(context->ap_handle, &sec_type); + DEBUG_MSG("Authentication type %x", sec_type); + } + else + { + data_s temp = { NULL, 0 }; + wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_TYPE_NONE; + wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE; + //set passkey + net_nfc_util_get_carrier_config_property(context->config, + NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length, + &temp.buffer); + + DEBUG_ERR_MSG("Network Key %s",temp.buffer); + // Sets Network Key + err = wifi_ap_set_passphrase(context->ap_handle, + (char*)temp.buffer); + + wifi_ap_get_encryption_type(context->ap_handle, &enc_type); + DEBUG_MSG("Encryption type %x",enc_type); + wifi_ap_get_security_type(context->ap_handle, &sec_type); + DEBUG_MSG("Authentication type %x", sec_type); + } + context->step = NET_NFC_LLCP_STEP_03; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + + } +} + +void +_net_nfc_handover_bss_on_wifi_scan_completed(wifi_error_e errorCode, + void* user_data) +{ + int err = WIFI_ERROR_NONE; + net_nfc_handover_bss_process_context_t *context = user_data; + + if(context == NULL) + { + DEBUG_ERR_MSG("Invalid context"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + return false; + } + + if(errorCode != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("Wifi scan failed"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + else + { + net_nfc_util_create_carrier_config_from_config_record( + &context->config, context->carrier); + context->ap_handle = NULL; + err = wifi_foreach_found_aps( + _net_nfc_handover_bss_wifi_for_each_access_point_found, + context); + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("wifi_foreach_found_aps failed Err[%x]",err); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + + } + if(context->ap_handle == NULL) + { + wifi_encryption_type_e enc_type; + wifi_security_type_e sec_type; + DEBUG_MSG("It's Hidden AP"); + context->ap_handle = _net_nfc_handover_bss_create_ap( + context->config); + wifi_ap_get_encryption_type(context->ap_handle, &enc_type); + DEBUG_MSG("Encryption type %x",enc_type); + wifi_ap_get_security_type(context->ap_handle, &sec_type); + DEBUG_MSG("Authentication type %x", sec_type); + } + else + { + data_s temp = { NULL, 0 }; + wifi_encryption_type_e enc_type = WIFI_ENCRYPTION_TYPE_NONE; + wifi_security_type_e sec_type = WIFI_SECURITY_TYPE_NONE; + //set passkey + net_nfc_util_get_carrier_config_property(context->config, + NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length, + &temp.buffer); + + DEBUG_ERR_MSG("Network Key %s",temp.buffer); + // Sets Network Key + err = wifi_ap_set_passphrase(context->ap_handle,(char*)temp.buffer); + + wifi_ap_get_encryption_type(context->ap_handle, &enc_type); + DEBUG_MSG("Encryption type %x",enc_type); + wifi_ap_get_security_type(context->ap_handle, &sec_type); + DEBUG_MSG("Authentication type %x", sec_type); + } + context->step = NET_NFC_LLCP_STEP_03; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + + } + +} + +void +_net_nfc_handover_bss_on_wifi_connected(wifi_error_e errorCode, void* user_data) +{ + net_nfc_handover_bss_process_context_t *context = user_data; + + if(context == NULL) + { + DEBUG_ERR_MSG("Invalid context"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + return false; + } + + if(errorCode == WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("WIFI Connected succesfully"); + context->result = NET_NFC_OK; + } + else + { + DEBUG_ERR_MSG("Failed to connect WIFI"); + context->result = NET_NFC_OPERATION_FAIL; + } + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); +} + +static int _net_nfc_handover_bss_process_carrier_record( + net_nfc_handover_bss_process_context_t *context) +{ + LOGD("[%s:%d] START", __func__, __LINE__); + + if(context == NULL) + { + DEBUG_ERR_MSG("Invalid context"); + DEBUG_ERR_MSG("Handover Failed"); + return -1; + } + + if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY) + { + DEBUG_ERR_MSG("context->result is error" + " [%d]", context->result); + context->step = NET_NFC_LLCP_STEP_RETURN; + } + + switch (context->step) + { + case NET_NFC_LLCP_STEP_01 : + { + int err = WIFI_ERROR_NONE; + DEBUG_MSG("STEP [1]"); + err = wifi_initialize(); + /* WIFI returns WIFI_ERROR_INVALID_OPERATION in case already + * initialized*/ + if (err == WIFI_ERROR_NONE || err == WIFI_ERROR_INVALID_OPERATION) + { + bool val = false; + + err = wifi_is_activated(&val); + /* next step */ + + if (val == false) + { + context->result = NET_NFC_OK; + wifi_set_background_scan_cb( + _net_nfc_handover_bss_on_wifi_bgscan_completed, context); + wifi_activate( + _net_nfc_handover_bss_on_wifi_activated, context); + } + else + { + /* do next step */ + DEBUG_MSG("Wifi is enabled already, go next step"); + context->result = NET_NFC_OK; + context->step = NET_NFC_LLCP_STEP_02; + g_idle_add((GSourceFunc) + _net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + } + else + { + DEBUG_ERR_MSG("Wifi init failed"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + } + break; + + case NET_NFC_LLCP_STEP_02 : + { + + int err = WIFI_ERROR_NONE; + DEBUG_MSG("STEP [2]"); + err = wifi_scan(_net_nfc_handover_bss_on_wifi_scan_completed, + context); + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("Wifi scan failed"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + } + + break; + case NET_NFC_LLCP_STEP_03 : + { + DEBUG_MSG("Connect with WIFI"); + int err = wifi_connect(context->ap_handle, + _net_nfc_handover_bss_on_wifi_connected, context); + DEBUG_MSG("Connect with WIFI err [%x]",err); + if(err != WIFI_ERROR_NONE) + { + DEBUG_ERR_MSG("Wifi Connect failed"); + context->result = NET_NFC_OPERATION_FAIL; + context->step = NET_NFC_LLCP_STEP_RETURN; + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + } + break; + case NET_NFC_LLCP_STEP_RETURN : + { + DEBUG_MSG("STEP return"); + if(context->result == NET_NFC_OK) + { + DEBUG_MSG("Handover completed succesfully"); + } + else + { + DEBUG_ERR_MSG("Handover Failed"); + } + wifi_deinitialize(); + } + break; + + default : + break; + } + + LOGD("[%s:%d] END", __func__, __LINE__); + + return 0; +} + +net_nfc_error_e net_nfc_server_handover_bss_process_carrier_record( + ndef_record_s *record, + net_nfc_server_handover_process_carrier_record_cb cb, + void *user_param) +{ + net_nfc_error_e result = NET_NFC_OK; + net_nfc_handover_bss_process_context_t *context = NULL; + + _net_nfc_util_alloc_mem(context, sizeof(*context)); + if (context != NULL) + { + context->cb = cb; + context->user_param = user_param; + context->step = NET_NFC_LLCP_STEP_01; + net_nfc_util_create_record(record->TNF, &record->type_s, + &record->id_s, &record->payload_s, &context->carrier); + + g_idle_add( + (GSourceFunc)_net_nfc_handover_bss_process_carrier_record, + (gpointer)context); + } + else + { + result = NET_NFC_ALLOC_FAIL; + } + + return result; +} diff --git a/src/manager/net_nfc_server_process_handover.c b/src/manager/net_nfc_server_process_handover.c index bb9fd6c..9a23850 100644 --- a/src/manager/net_nfc_server_process_handover.c +++ b/src/manager/net_nfc_server_process_handover.c @@ -27,7 +27,7 @@ #include "net_nfc_server_handover_internal.h" #include "net_nfc_server_process_snep.h" #include "net_nfc_util_gdbus_internal.h" - +#include "net_nfc_server_handover_bss.h" typedef void (*_net_nfc_server_handover_create_carrier_msg_cb)( net_nfc_error_e result, @@ -101,11 +101,6 @@ static void _net_nfc_server_handover_client_connected_cb( static void _net_nfc_server_handover_get_response_process( net_nfc_handover_context_t *context); -static net_nfc_error_e _net_nfc_server_handover_process_carrier_record( - ndef_record_s *carrier, - void *cb, - void *user_param); - static int _net_nfc_server_handover_append_wifi_carrier_config( net_nfc_server_handover_create_config_context_t *context); @@ -294,7 +289,7 @@ static void _net_nfc_server_handover_bt_process_carrier_record_cb( } -static net_nfc_error_e +net_nfc_error_e _net_nfc_server_handover_get_carrier_record_by_priority_order( ndef_message_s *request, ndef_record_s **record) @@ -399,7 +394,7 @@ static net_nfc_error_e _net_nfc_server_handover_create_requester_from_rawdata( return result; } -static net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata( +net_nfc_error_e _net_nfc_server_handover_create_selector_from_rawdata( ndef_message_s **selector, data_s *data) { @@ -875,7 +870,7 @@ _net_nfc_server_handover_create_low_power_selector_message( return result; } -static net_nfc_error_e _net_nfc_server_handover_process_carrier_record( +net_nfc_error_e _net_nfc_server_handover_process_carrier_record( ndef_record_s *carrier, void *cb, void *user_param) @@ -912,6 +907,10 @@ static net_nfc_error_e _net_nfc_server_handover_process_carrier_record( case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS : DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]"); + net_nfc_server_handover_bss_process_carrier_record( + carrier, + NULL, + NULL); _net_nfc_util_free_mem(context); break; diff --git a/src/manager/net_nfc_server_tag.c b/src/manager/net_nfc_server_tag.c index bb8c9fe..c099b6e 100644 --- a/src/manager/net_nfc_server_tag.c +++ b/src/manager/net_nfc_server_tag.c @@ -24,7 +24,8 @@ #include "net_nfc_server_context_internal.h" #include "net_nfc_server_tag.h" #include "net_nfc_server_p2p.h" - +#include "net_nfc_server_process_handover.h" +#include "net_nfc_util_ndef_record.h" typedef struct _CurrentTagInfoData CurrentTagInfoData; @@ -360,6 +361,7 @@ static void tag_slave_target_detected_thread_func(gpointer user_data) GVariant *raw_data = NULL; WatchDogData *watch_dog = NULL; + bool isHandoverMessage = false; target = net_nfc_server_get_target_info(); @@ -414,8 +416,41 @@ static void tag_slave_target_detected_thread_func(gpointer user_data) target->devType, &recv_data) == TRUE) { - net_nfc_app_util_process_ndef(recv_data); - raw_data = net_nfc_util_gdbus_data_to_variant(recv_data); + ndef_message_s *selector; + ndef_record_s *record; + ndef_record_s *recordasperpriority; + result = _net_nfc_server_handover_create_selector_from_rawdata( + &selector, + recv_data); + + if (result == NET_NFC_OK) + { + result = + _net_nfc_server_handover_get_carrier_record_by_priority_order( + selector, + &record); + isHandoverMessage = true; + if (result == NET_NFC_OK) + { + net_nfc_util_create_record( + record->TNF, + &record->type_s, &record->id_s, + &record->payload_s, + &recordasperpriority); + + _net_nfc_server_handover_process_carrier_record(recordasperpriority, NULL, NULL); + } + else + { + DEBUG_ERR_MSG("_get_carrier_record_by_priority_order" + " failed, [%d]",result); + } + } + else + { + net_nfc_app_util_process_ndef(recv_data); + raw_data = net_nfc_util_gdbus_data_to_variant(recv_data); + } } else { @@ -435,17 +470,20 @@ static void tag_slave_target_detected_thread_func(gpointer user_data) raw_data = net_nfc_util_gdbus_data_to_variant(&empty_data); } - /* send TagDiscoverd signal */ - net_nfc_gdbus_tag_emit_tag_discovered(tag_skeleton, - GPOINTER_TO_UINT(target->handle), - target->devType, - is_ndef_supported, - ndef_card_state, - max_data_size, - actual_data_size, - target->number_of_keys, - target_info_values, - raw_data); + if(isHandoverMessage == false) + { + /* send TagDiscoverd signal */ + net_nfc_gdbus_tag_emit_tag_discovered(tag_skeleton, + GPOINTER_TO_UINT(target->handle), + target->devType, + is_ndef_supported, + ndef_card_state, + max_data_size, + actual_data_size, + target->number_of_keys, + target_info_values, + raw_data); + } /* turn on watch dog */ DEBUG_SERVER_MSG("turn on watch dog"); -- 2.7.4