#include "net_nfc_util_ndef_record.h"
#include "net_nfc_server_llcp.h"
#include "net_nfc_server_handover_bss.h"
+#include <execinfo.h>
+
+static gboolean _net_nfc_handover_bss_process_carrier_record(
+ gpointer user_data);
+
+static void _net_nfc_handover_bss_get_carrier_record(
+ net_nfc_handover_bss_create_context_t *context);
+
+static net_nfc_error_e _net_nfc_handover_bss_create_carrier_record(
+ ndef_record_s **record);
+
+#ifdef TARGET
+static net_nfc_error_e _net_nfc_handover_bss_create_config_record(
+ ndef_record_s **record);
+
+static int _net_nfc_handover_process_wifi_direct_setup(
+ net_nfc_handover_bss_get_context_t *context);
+
+static gboolean _net_nfc_handover_bss_wfd_get_carrier_record(
+ net_nfc_handover_bss_get_context_t *context);
+
+static void _net_nfc_wifi_process_error(int error);
+
+static int _net_nfc_handover_process_wifi_group_setup(
+ net_nfc_handover_bss_get_context_t *context);
+
+static int _net_nfc_handover_getpassword(uint8_t** password );
+#endif
-static gboolean _net_nfc_handover_bss_process_carrier_record(gpointer user_data);
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;
+ 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 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;
+ 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;
}
// Sets SSID
err = net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_SSID,(uint16_t *)&temp.length, &temp.buffer);
+ 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)
// Sets Authentication Type
net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE,(uint16_t *)&temp.length, &temp.buffer);
+ 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));
+ _net_nfc_handover_bss_convert_security_type(securitytype));
if(err != WIFI_ERROR_NONE)
{
DEBUG_ERR_MSG("set security type failed");
goto error;
}
net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length, &temp.buffer);
+ 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);
}
// Sets encryption Type
net_nfc_util_get_carrier_config_property(config,
- NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE,(uint16_t *)&temp.length, &temp.buffer);
+ 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));
+ _net_nfc_handover_bss_convert_encryption_type(enc_type));
}
else
{
if(context == NULL)
{
DEBUG_ERR_MSG("Invalid context");
- context->result = NET_NFC_OPERATION_FAIL;
+ return;
}
if (errorCode == WIFI_ERROR_NONE)
{
if(context == NULL)
{
DEBUG_ERR_MSG("Invalid context");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(_net_nfc_handover_bss_process_carrier_record, context);
return false;
}
DEBUG_ERR_MSG("Wifi get carrier config failed");
context->result = NET_NFC_OPERATION_FAIL;
context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(_net_nfc_handover_bss_process_carrier_record, context);
+ g_idle_add(_net_nfc_handover_bss_process_carrier_record,
+ context);
return false;
}
return true;
}
-void _net_nfc_handover_bss_on_wifi_bgscan_completed(
- wifi_error_e errorCode, void* user_data)
+void
+_net_nfc_handover_bss_on_wifi_bgscan_completed(wifi_error_e error_code,
+ 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(_net_nfc_handover_bss_process_carrier_record, context);
return;
}
-
- if(errorCode != WIFI_ERROR_NONE)
+ if(error_code != 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(_net_nfc_handover_bss_process_carrier_record,context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ 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(_net_nfc_handover_bss_process_carrier_record, 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(_net_nfc_handover_bss_process_carrier_record, context);
+ context->result = NET_NFC_OK;
+ context->step = NET_NFC_LLCP_STEP_02;
}
}
-void _net_nfc_handover_bss_on_wifi_scan_completed(wifi_error_e errorCode,
+void
+_net_nfc_handover_bss_on_wifi_scan_completed(wifi_error_e error_code,
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(_net_nfc_handover_bss_process_carrier_record, context);
- return;
- }
-
- if(errorCode != WIFI_ERROR_NONE)
+ if(error_code != 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(_net_nfc_handover_bss_process_carrier_record, context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ context);
}
else
{
&context->config, context->carrier);
context->ap_handle = NULL;
err = wifi_foreach_found_aps(
- _net_nfc_handover_bss_wifi_for_each_access_point_found,
- context);
+ _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(_net_nfc_handover_bss_process_carrier_record, context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ 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);
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);
+ NET_NFC_WIFI_ATTRIBUTE_NET_KEY,(uint16_t *)&temp.length,
+ &temp.buffer);
DEBUG_ERR_MSG("Network Key %s",temp.buffer);
// Sets Network Key
DEBUG_MSG("Authentication type %x", sec_type);
}
context->step = NET_NFC_LLCP_STEP_03;
- g_idle_add(_net_nfc_handover_bss_process_carrier_record, context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ context);
}
}
void
-_net_nfc_handover_bss_on_wifi_connected(wifi_error_e errorCode, void* user_data)
+_net_nfc_handover_bss_on_wifi_connected(wifi_error_e error_code, 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(_net_nfc_handover_bss_process_carrier_record, context);
return;
}
- if(errorCode == WIFI_ERROR_NONE)
+ if(error_code == WIFI_ERROR_NONE)
{
DEBUG_ERR_MSG("WIFI Connected succesfully");
context->result = NET_NFC_OK;
context->result = NET_NFC_OPERATION_FAIL;
}
context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(_net_nfc_handover_bss_process_carrier_record,context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ context);
}
-static gboolean _net_nfc_handover_bss_process_carrier_record(gpointer user_data)
+static gboolean _net_nfc_handover_bss_process_carrier_record(
+ gpointer user_data)
{
- net_nfc_handover_bss_process_context_t *context = user_data;
-
LOGD("[%s:%d] START", __func__, __LINE__);
+ net_nfc_handover_bss_process_context_t *context = user_data;
+
if(context == NULL)
{
DEBUG_ERR_MSG("Invalid context");
DEBUG_ERR_MSG("Handover Failed");
- return -1;
+ return 0;
}
if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
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;
+ 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 */
+ 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);
+ 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(_net_nfc_handover_bss_process_carrier_record,
+ 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(_net_nfc_handover_bss_process_carrier_record, context);
+ DEBUG_ERR_MSG("Wifi init failed");
+ context->result = NET_NFC_OPERATION_FAIL;
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ context);
}
}
- else
- {
- DEBUG_ERR_MSG("Wifi init failed");
- context->result = NET_NFC_OPERATION_FAIL;
- context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(_net_nfc_handover_bss_process_carrier_record, context);
- }
- }
- break;
+ break;
case NET_NFC_LLCP_STEP_02:
{
DEBUG_ERR_MSG("Wifi scan failed");
context->result = NET_NFC_OPERATION_FAIL;
context->step = NET_NFC_LLCP_STEP_RETURN;
- g_idle_add(_net_nfc_handover_bss_process_carrier_record, context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ context);
}
}
{
DEBUG_MSG("Connect with WIFI");
int err = wifi_connect(context->ap_handle,
- _net_nfc_handover_bss_on_wifi_connected, context);
+ _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(_net_nfc_handover_bss_process_carrier_record, context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ context);
}
}
break;
DEBUG_ERR_MSG("Handover Failed");
}
wifi_deinitialize();
+ context->cb(context->result,
+ NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS,
+ NULL,
+ context->user_param);
}
break;
}
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)
+ 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;
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);
+ &record->id_s, &record->payload_s, &context->carrier);
- g_idle_add(_net_nfc_handover_bss_process_carrier_record, context);
+ g_idle_add(
+ _net_nfc_handover_bss_process_carrier_record,
+ context);
}
else
{
result = NET_NFC_ALLOC_FAIL;
}
+ return result;
+}
+
+#ifdef TARGET
+void
+_net_nfc_wifi_direct_power_changed(int err, wifi_direct_device_state_e device_state, void* user_data)
+{
+
+ if(device_state == WIFI_DIRECT_DEVICE_STATE_ACTIVATED && err == WIFI_DIRECT_ERROR_NONE)
+ {
+ int err = wifi_direct_start_discovery(true, 0);
+ DEBUG_MSG("wifi direct is enabled %d",err);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("wifi direct power state error");
+ net_nfc_handover_bss_create_context_t* context =
+ (net_nfc_handover_bss_create_context_t*)user_data;
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+ }
+}
+
+void
+_net_nfc_wifi_scan_completed_cb(int err, wifi_direct_discovery_state_e discovery_state, void* user_data)
+{
+
+ net_nfc_handover_bss_create_context_t* context =
+ (net_nfc_handover_bss_create_context_t*) user_data;
+
+ if(discovery_state == WIFI_DIRECT_ONLY_LISTEN_STARTED && err == WIFI_DIRECT_ERROR_NONE)
+ {
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("wifi scan error");
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+ }
+
+}
+
+void
+_net_nfc_wifi_direct_connection_changed(wifi_direct_error_e error_code,
+ wifi_direct_connection_state_e connection_state,
+ const char* mac_address,
+ void *user_data)
+{
+
+ net_nfc_handover_bss_create_context_t* context =
+ (net_nfc_handover_bss_create_context_t*) user_data;
+
+ if(connection_state == WIFI_DIRECT_GROUP_CREATED
+ && error_code == WIFI_DIRECT_ERROR_NONE)
+ {
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("_net_nfc_wifi_direct_connection_changed failed"
+ "[%d] [%d]",error_code,connection_state);
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+ }
+}
+
+#endif
+
+static net_nfc_error_e _net_nfc_handover_bss_create_carrier_record(
+ ndef_record_s **record)
+{
+ net_nfc_error_e result;
+
+ if ((result = net_nfc_util_create_handover_carrier_record(
+ record)) == NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_record"
+ "_with_carrier_config [%d]",result);
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_carrier_config failed "
+ "[%d]", result);
+ }
return result;
}
+
+
+#ifdef TARGET
+static int _net_nfc_handover_getpassword(uint8_t** password )
+{
+
+ char data[256];
+ int ret_val;
+
+ ret_val = system("wpa_cli -g /var/run/wpa_supplicant/p2p-wlan0-0 p2p_get_passphrase "
+ "> /tmp/nfc_p2p_passphrase.txt");
+
+ DEBUG_MSG("system command returned with [%d]",ret_val);
+
+ FILE *f = fopen("/tmp/nfc_p2p_passphrase.txt","r");
+ if(f != NULL)
+ {
+ int readlength;
+ int cnt;
+ readlength = fread(data, 1 , 255, f);
+ for(cnt = 0; cnt < readlength; cnt++)
+ {
+ if(data[cnt] == '\n')
+ {
+ break;
+ }
+ }
+ _net_nfc_util_alloc_mem(*password,(readlength - cnt)+1);
+ memcpy(*password, &data[cnt+1], (readlength - cnt));
+ fclose(f);
+ return (readlength-cnt);
+ }
+ else
+ return 0;
+}
+
+
+static net_nfc_error_e _net_nfc_handover_bss_create_config_record(
+ ndef_record_s **record)
+{
+ char* mac_address = NULL;
+ char* ssid = NULL;
+ net_nfc_carrier_config_s *config = NULL;
+ net_nfc_carrier_property_s *cred_config = NULL;
+ net_nfc_error_e result;
+ uint8_t *password = NULL;
+ int pw_length = 0;
+
+ data_s version_data = {NULL,0};
+ data_s net_index_data = {NULL,0};
+ data_s ssid_data = {NULL,0};
+ data_s auth_data = {NULL,0};
+ data_s enc_type = {NULL,0};
+ data_s mac_data = {NULL,0};
+
+ _net_nfc_util_alloc_mem(version_data.buffer,1);
+ if(version_data.buffer)
+ {
+ version_data.length = 1;
+ *version_data.buffer = 0x01;
+
+ if ((result = net_nfc_util_create_carrier_config(
+ &config,
+ NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)) == NET_NFC_OK)
+ {
+ if ((result = net_nfc_util_add_carrier_config_property(
+ config,
+ NET_NFC_WIFI_ATTRIBUTE_VERSION,
+ version_data.length, version_data.buffer)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier_config_property failed"
+ "[%d]", result);
+ }
+ }
+
+ _net_nfc_util_free_mem(version_data.buffer);
+ }
+
+ if ((result = net_nfc_util_create_carrier_config_group(
+ &cred_config,
+ NET_NFC_WIFI_ATTRIBUTE_CREDENTIAL)) == NET_NFC_OK)
+ {
+
+ _net_nfc_util_alloc_mem(net_index_data.buffer,1);
+ if(net_index_data.buffer)
+ {
+ net_index_data.length = 1;
+ *net_index_data.buffer = 1;
+
+
+ net_nfc_util_add_carrier_config_group_property(
+ cred_config,
+ NET_NFC_WIFI_ATTRIBUTE_NET_INDEX,
+ net_index_data.length, net_index_data.buffer);
+
+ _net_nfc_util_free_mem(net_index_data.buffer);
+ }
+
+ wifi_direct_get_ssid(&ssid);
+
+ _net_nfc_util_alloc_mem(ssid_data.buffer,strlen(ssid)+2);
+ if(ssid_data.buffer)
+ {
+ ssid_data.length = strlen(ssid);
+ memcpy(ssid_data.buffer,ssid, strlen(ssid));
+
+ net_nfc_util_add_carrier_config_group_property(
+ cred_config,
+ NET_NFC_WIFI_ATTRIBUTE_SSID,
+ ssid_data.length, ssid_data.buffer);
+
+ _net_nfc_util_free_mem(version_data.buffer);
+ }
+
+ _net_nfc_util_alloc_mem(auth_data.buffer,2);
+ if(auth_data.buffer)
+ {
+ auth_data.length = 1;
+ *auth_data.buffer = 20;
+
+ net_nfc_util_add_carrier_config_group_property(
+ cred_config,
+ NET_NFC_WIFI_ATTRIBUTE_AUTH_TYPE,
+ auth_data.length, auth_data.buffer);
+
+ _net_nfc_util_free_mem(auth_data.buffer);
+ }
+
+ _net_nfc_util_alloc_mem(enc_type.buffer,2);
+ if(enc_type.buffer)
+ {
+ enc_type.length = 1;
+ *enc_type.buffer = 8;
+
+ net_nfc_util_add_carrier_config_group_property(
+ cred_config,
+ NET_NFC_WIFI_ATTRIBUTE_ENC_TYPE,
+ enc_type.length, enc_type.buffer);
+
+ _net_nfc_util_free_mem(enc_type.buffer);
+ }
+
+ pw_length = _net_nfc_handover_getpassword(&password);
+
+ DEBUG_ERR_MSG("_net_nfc_handover_getpassword[%s]", password);
+
+ net_nfc_util_add_carrier_config_group_property(
+ cred_config,
+ NET_NFC_WIFI_ATTRIBUTE_NET_KEY,
+ pw_length, password);
+
+ _net_nfc_util_free_mem(password);
+
+ wifi_direct_get_mac_address(&mac_address);
+
+ _net_nfc_util_alloc_mem(mac_data.buffer,strlen(mac_address)+2);
+ if(mac_data.buffer)
+ {
+ mac_data.length = strlen(mac_address);
+ memcpy(mac_data.buffer,mac_address,strlen(mac_address));
+
+ if ((result = net_nfc_util_add_carrier_config_group_property(
+ cred_config,
+ NET_NFC_WIFI_ATTRIBUTE_MAC_ADDR,
+ mac_data.length, mac_data.buffer)) != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_add_carrier"
+ "_config_property failed"
+ "[%d]", result);
+ }
+ }
+
+ _net_nfc_util_free_mem(mac_data.buffer);
+
+ }
+ net_nfc_util_append_carrier_config_group(config, cred_config);
+
+ result = net_nfc_util_create_ndef_record_with_carrier_config(
+ record,
+ config);
+
+ if (result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("net_nfc_util_create_ndef_record"
+ "_with_carrier_config failed"
+ "[%d]",result);
+ }
+
+ return result;
+}
+#endif
+
+
+static void _net_nfc_handover_bss_get_carrier_record(
+ net_nfc_handover_bss_create_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+
+ if(context != NULL)
+ {
+
+ if (context->result != NET_NFC_OK && context->result != NET_NFC_BUSY)
+ {
+ DEBUG_ERR_MSG("context->result is error [%d]", context->result);
+ }
+
+ context->result = NET_NFC_OK;
+
+ context->cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+
+ /* Create carrier record */
+ context->result =_net_nfc_handover_bss_create_carrier_record(
+ &context->carrier);
+ if (context->result!= NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("create_bss_config_record failed"
+ " [%d]", context->result);
+ }
+
+ /* complete and return to upper step */
+ context->cb(context->result,
+ context->cps,
+ context->carrier,
+ 0,
+ NULL,
+ context->user_param);
+ }
+}
+
+#ifdef TARGET
+static void _net_nfc_wifi_process_error(int error)
+{
+ DEBUG_ERR_MSG("_net_nfc_wifi_process_error - [%d]",error);
+
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+ context->result = NET_NFC_OPERATION_FAIL;
+
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+
+ return;
+}
+
+static int _net_nfc_handover_process_wifi_direct_setup(
+ net_nfc_handover_bss_get_context_t *context)
+{
+ int err = WIFI_DIRECT_ERROR_NONE;
+ err = wifi_direct_initialize();
+ if(err != WIFI_DIRECT_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("wifi_direct_initialize err value %d",err);
+ return err;
+ }
+
+ err = wifi_direct_set_device_state_changed_cb(
+ _net_nfc_wifi_direct_power_changed,
+ context);
+
+ if(err != WIFI_DIRECT_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("wifi_direct_set_device_state_changed_cb err value %d",err);
+ return err;
+ }
+
+ err = wifi_direct_set_discovery_state_changed_cb(
+ _net_nfc_wifi_scan_completed_cb,
+ context);
+
+ if(err != WIFI_DIRECT_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("wifi_direct_set_discovery_state_changed_cb err value %d",err);
+ return err;
+ }
+
+ err = wifi_direct_set_connection_state_changed_cb(
+ _net_nfc_wifi_direct_connection_changed,
+ context);
+
+ if (err != WIFI_DIRECT_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("wifi_direct_set_connection_state_changed_cb err value %d",err);
+ return err;
+ }
+ else
+ {
+ context->step = NET_NFC_LLCP_STEP_02;
+ context->result = NET_NFC_OK;
+
+ wifi_direct_state_e status = WIFI_DIRECT_STATE_DEACTIVATED;
+
+ err = wifi_direct_get_state(&status);
+ DEBUG_ERR_MSG("status value %d",status);
+
+ if (status != WIFI_DIRECT_STATE_ACTIVATED)
+ {
+ wifi_direct_activate();
+ }
+ else
+ {
+ DEBUG_MSG("wifi direct is enabled already");
+
+ /* do next step */
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+ }
+ return WIFI_DIRECT_ERROR_NONE;
+
+ }
+}
+
+static int _net_nfc_handover_process_wifi_group_setup(
+ net_nfc_handover_bss_get_context_t *context)
+{
+ int err = WIFI_DIRECT_ERROR_NONE;
+ bool group_owner = false;
+
+ err = wifi_direct_is_group_owner(&group_owner);
+ DEBUG_ERR_MSG("error value %d",err);
+
+ context->step = NET_NFC_LLCP_STEP_03;
+ context->result = NET_NFC_OK;
+
+ if(err == WIFI_DIRECT_ERROR_NONE)
+ {
+ if(group_owner == true)
+ {
+ DEBUG_MSG("Already group owner, continue next step");
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+ }
+ else
+ {
+ err = wifi_direct_create_group();
+ if (err != WIFI_DIRECT_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("wifi_direct_create_group failed [%d]",err);
+ return err;
+ }
+ }
+ }
+ else
+ {
+ DEBUG_ERR_MSG("wifi_direct_is_group_owner failed [%d]",err);
+ return err;
+ }
+
+}
+
+static gboolean _net_nfc_handover_bss_wfd_get_carrier_record(
+ net_nfc_handover_bss_get_context_t *context)
+{
+ LOGD("[%s:%d] START", __func__, __LINE__);
+ if(context == NULL)
+ {
+ DEBUG_ERR_MSG("Invalid context");
+ return FALSE;
+ }
+
+ if(context != NULL)
+ {
+ int err = WIFI_DIRECT_ERROR_NONE;
+
+ 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 :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_01");
+ err = _net_nfc_handover_process_wifi_direct_setup(context);
+ if(err != WIFI_DIRECT_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("_net_nfc_handover_process_wifi_direct_setup failed");
+ _net_nfc_wifi_process_error(err);
+ }
+ break;
+ case NET_NFC_LLCP_STEP_02:
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_02");
+ err = _net_nfc_handover_process_wifi_group_setup(context);
+ if(err != WIFI_DIRECT_ERROR_NONE)
+ {
+ DEBUG_ERR_MSG("_net_nfc_handover_process_wifi_group_setup failed");
+ _net_nfc_wifi_process_error(err);
+ }
+ break;
+ case NET_NFC_LLCP_STEP_03 :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_03");
+ context->step = NET_NFC_LLCP_STEP_RETURN;
+
+ /* append config to ndef message */
+ context->result =_net_nfc_handover_bss_create_config_record(
+ &context->carrier);
+ if (context->result != NET_NFC_OK)
+ {
+ DEBUG_ERR_MSG("_net_nfc_handover_bss_create_config_record failed"
+ "[%d]", context->result);
+ }
+
+ g_idle_add((GSourceFunc)
+ _net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+
+ break;
+ case NET_NFC_LLCP_STEP_RETURN :
+ DEBUG_ERR_MSG("NET_NFC_LLCP_STEP_RETURN");
+ /* unregister current callback */
+ wifi_direct_unset_connection_state_changed_cb();
+ wifi_direct_unset_device_state_changed_cb();
+ wifi_direct_unset_discovery_state_changed_cb();
+ wifi_direct_deinitialize();
+
+ /* complete and return to upper step */
+ context->cb(context->result,
+ context->cps,
+ context->carrier,
+ context->aux_data_count,
+ context->aux_data,
+ context->user_param);
+ break;
+
+ default :
+ break;
+ }
+ }
+ LOGD("[%s:%d] END", __func__, __LINE__);
+
+ return TRUE;
+}
+#endif
+
+net_nfc_error_e net_nfc_server_handover_bss_get_carrier_record(
+ net_nfc_server_handover_get_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_error_e result = NET_NFC_OK;
+ net_nfc_handover_bss_create_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_handover_bss_get_carrier_record(context);
+
+ }
+ else
+ {
+ result = NET_NFC_ALLOC_FAIL;
+ }
+
+ return result;
+}
+
+#ifdef TARGET
+net_nfc_error_e net_nfc_server_handover_bss_wfd_get_carrier_record(
+ net_nfc_server_handover_get_carrier_record_cb cb,
+ void *user_param)
+{
+ net_nfc_handover_bss_get_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;
+ context->cps = NET_NFC_CONN_HANDOVER_CARRIER_ACTIVATE;
+
+ g_idle_add((GSourceFunc)_net_nfc_handover_bss_wfd_get_carrier_record,
+ (gpointer)context);
+
+ return NET_NFC_OK:
+ }
+ else
+ {
+ return NET_NFC_ALLOC_FAIL;
+ }
+
+}
+#endif
-static void _net_nfc_server_handover_send_response(net_nfc_error_e result,
+static void _net_nfc_server_handover_send_response(
+ net_nfc_error_e result,
net_nfc_conn_handover_carrier_type_e carrier,
data_s *ac_data,
void *user_param);
data_s *data,
void *user_param);
+static void _net_nfc_server_handover_bss_get_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_state_e cps,
+ ndef_record_s *carrier,
+ uint32_t aux_data_count,
+ ndef_record_s *aux_data,
+ void *user_param);
+
+static void _net_nfc_server_handover_bss_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param);
static void _net_nfc_server_handover_get_response_process(
net_nfc_handover_context_t *context);
/* don't free context */
}
+static void _net_nfc_server_handover_bss_get_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_state_e cps,
+ ndef_record_s *carrier,
+ uint32_t aux_data_count,
+ ndef_record_s *aux_data,
+ void *user_param)
+{
+ net_nfc_server_handover_create_config_context_t *context =
+ (net_nfc_server_handover_create_config_context_t *)user_param;
+
+ /* append record to ndef message */
+ if (result == NET_NFC_OK)
+ {
+ ndef_record_s *record;
+
+ net_nfc_util_create_record(carrier->TNF,
+ &carrier->type_s,
+ &carrier->id_s,
+ &carrier->payload_s,
+ &record);
+
+ if ((result = net_nfc_util_append_carrier_config_record(
+ context->ndef_message,
+ record,
+ cps)) == NET_NFC_OK)
+ {
+ DEBUG_SERVER_MSG("net_nfc_util_append_carrier"
+ "_config_record success");
+ }
+ else
+ {
+ DEBUG_ERR_MSG("net_nfc_util_append_carrier"
+ "_config_record failed [%d]",
+ result);
+ net_nfc_util_free_record(record);
+ }
+
+ g_idle_add(
+ (GSourceFunc)_net_nfc_server_handover_iterate_carrier_configs_to_next,
+ (gpointer)context);
+ }
+ /* don't free context */
+}
static void _net_nfc_server_handover_bt_process_carrier_record_cb(
net_nfc_error_e result,
net_nfc_conn_handover_carrier_type_e type,
_net_nfc_util_free_mem(context);
}
+static void _net_nfc_server_handover_bss_process_carrier_record_cb(
+ net_nfc_error_e result,
+ net_nfc_conn_handover_carrier_type_e type,
+ data_s *data,
+ void *user_param)
+{
+
+ net_nfc_server_handover_process_config_context_t *context =
+ (net_nfc_server_handover_process_config_context_t *)user_param;
+
+ if(context)
+ {
+ if (context->cb != NULL)
+ {
+ context->cb(result, type, data, context->user_param);
+ }
+ else
+ DEBUG_ERR_MSG("Invalid Callback");
-net_nfc_error_e net_nfc_server_handover_get_carrier_record_by_priority_order(
- ndef_message_s *request, ndef_record_s **record)
+ _net_nfc_util_free_mem(context);
+ }
+}
+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 result;
unsigned int carrier_count = 0;
net_nfc_server_handover_create_config_context_t *context)
{
LOGD("[%s:%d] START", __func__, __LINE__);
+ net_nfc_error_e result = NET_NFC_OK;
switch (context->current_type)
{
context);
break;
- // case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
- // DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
- // g_idle_add(
- // (GSourceFunc)net_nfc_service_llcp_handover_append_wifi_carrier_config,
- // context);
- // break;
+ case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS :
+ DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
+
+#ifdef TARGET
+ if(memcmp(context->ndef_message->records->type_s.buffer ,CH_SEL_RECORD_TYPE,
+ context->ndef_message->records->type_s.length)==0)
+ {
+ result = net_nfc_server_handover_bss_wfd_get_carrier_record(
+ _net_nfc_server_handover_bss_get_carrier_record_cb,
+ context);
+ }
+ else
+#endif
+ {
+ result = net_nfc_server_handover_bss_get_carrier_record(
+ _net_nfc_server_handover_bss_get_carrier_record_cb,
+ context);
+ }
+ DEBUG_MSG("[%d]",result);
+ break;
// case NET_NFC_CONN_HANDOVER_CARRIER_WIFI_IBSS :
// DEBUG_MSG("[NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS]");
return 0;
}
-static net_nfc_error_e _net_nfc_server_handover_create_requester_carrier_configs(
+static net_nfc_error_e
+_net_nfc_server_handover_create_requester_carrier_configs(
net_nfc_conn_handover_carrier_type_e type,
void *cb,
void *user_param)
return result;
}
-static net_nfc_error_e _net_nfc_server_handover_create_selector_carrier_configs(
+static net_nfc_error_e
+_net_nfc_server_handover_create_selector_carrier_configs(
net_nfc_conn_handover_carrier_type_e type,
void *cb,
void *user_param)
LOGD("[%s:%d] START", __func__, __LINE__);
- _net_nfc_util_alloc_mem(context, sizeof(*context));
+ _net_nfc_util_alloc_mem(context, sizeof(net_nfc_server_handover_create_config_context_t));
if (context != NULL)
{
context->type = type;
if (type == NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN)
+ {
context->current_type = NET_NFC_CONN_HANDOVER_CARRIER_BT;
+ }
else
context->current_type = context->type;
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);
+ _net_nfc_server_handover_bss_process_carrier_record_cb,
+ context);
break;
case NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN :
return result;
}
-#if 0
-static net_nfc_error_e _net_nfc_server_handover_snep_client_cb(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- _net_nfc_server_handover_client_context_t *context =
- (_net_nfc_server_handover_client_context_t *)user_param;
-
- DEBUG_SERVER_MSG("type [%d], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- switch (type) {
- case SNEP_RESP_SUCCESS :
- {
- ndef_message_s *selector;
-
- result = net_nfc_server_handover_create_selector_from_rawdata(
- &selector,
- data);
- if (result == NET_NFC_OK) {
- if (false /* is low power ??? */) {
- result =
- _net_nfc_server_handover_process_selector_msg(
- selector,
- user_param);
- } else {
- result =
- _net_nfc_server_handover_process_selector_msg(
- selector,
- user_param);
- }
-
- if (result != NET_NFC_OK) {
- DEBUG_ERR_MSG("_net_nfc_server_handover_process"
- "_selector_msg failed [%d]",result);
- if (context->cb != NULL) {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
-
- net_nfc_util_free_ndef_message(selector);
- } else {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create"
- "_selector_from_rawdata failed [%d]",result);
- if (context->cb != NULL) {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
- }
- break;
-
- case SNEP_RESP_BAD_REQ :
- case SNEP_RESP_EXCESS_DATA :
- case SNEP_RESP_NOT_FOUND :
- case SNEP_RESP_NOT_IMPLEMENT :
- case SNEP_RESP_REJECT :
- case SNEP_RESP_UNSUPPORTED_VER :
- default :
- {
- DEBUG_ERR_MSG("error response [0x%02x]", type);
- if (context->cb != NULL) {
- context->cb(result, context->type, NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
- break;
- }
-
- return result;
-}
-
-
-static void _net_nfc_server_handover_create_requester_carrier_configs_cb(
- net_nfc_error_e result,
- ndef_message_s *msg,
- void *user_param)
-{
- _net_nfc_server_handover_client_context_t *context =
- (_net_nfc_server_handover_client_context_t *)user_param;
- data_s data;
-
- if (context == NULL)
- {
- return;
- }
-
- if (msg != NULL) {
- /* convert ndef message */
- if ((result = _net_nfc_server_handover_convert_ndef_message_to_data(msg,
- &data)) == NET_NFC_OK) {
- net_nfc_service_snep_client(context->handle,
- SNEP_SAN,
- 0,
- SNEP_REQ_GET,
- &data,
- _net_nfc_server_handover_snep_client_cb,
- context);
-
- net_nfc_util_free_data(&data);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_convert"
- "_ndef_message_to_datafailed [%d]",result);
- if (context->cb != NULL)
- {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
- }
- else
- {
- DEBUG_ERR_MSG("null param, [%d]", result);
- if (context->cb != NULL)
- {
- context->cb(result,
- context->type,
- NULL,
- context->user_param);
- }
- _net_nfc_util_free_mem(context);
- }
-}
-#endif
-
-
-#if 0
-
-static void _net_nfc_server_handover_server_create_carrier_configs_cb(
- net_nfc_error_e result,
- ndef_message_s *selector,
- void *user_param)
-{
- _net_nfc_server_handover_create_config_context_t *context =
- (_net_nfc_server_handover_create_config_context_t *)user_param;
- data_s data;
-
- if (context == NULL)
- {
- return;
- }
-
- if (result == NET_NFC_OK)
- {
- result = _net_nfc_server_handover_convert_ndef_message_to_data(
- selector,
- &data);
-
- if (result == NET_NFC_OK)
- {
- /* process message */
- net_nfc_server_handover_process_carrier_record(
- context->record,
- NULL,
- NULL);
-
- result = net_nfc_service_snep_server_send_get_response(
- context->user_param,
- &data);
- if (result != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("net_nfc_service_snep_server"
- "_send_get_response failed [%d]",result);
- }
- net_nfc_util_free_data(&data);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_convert_ndef_message_to_data"
- "failed [%d]",result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create_selector_msg"
- "failed [%d]",result);
- }
-
- _net_nfc_util_free_mem(context);
-}
-
-static net_nfc_error_e _net_nfc_server_handover_create_selector_msg(
- net_nfc_snep_handle_h handle,
- ndef_message_s *request,
- void *user_param)
-{
- net_nfc_error_e result;
- uint32_t count;
-
- net_nfc_manager_util_play_sound(NET_NFC_TASK_END);
-
- /* get requester message */
- if ((result = net_nfc_util_get_alternative_carrier_record_count(
- request,
- &count)) == NET_NFC_OK)
- {
- if (1/* power state */ || count == 1)
- {
- ndef_record_s *record = NULL;
-
- /* fill alternative carrier information */
- if ((result =
- net_nfc_server_handover_get_carrier_record_by_priority_order(
- request,
- &record)) == NET_NFC_OK)
- {
- net_nfc_conn_handover_carrier_type_e type =
- NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
-
- if ((result = net_nfc_util_get_alternative_carrier_type_from_record(
- record,
- &type)) == NET_NFC_OK)
- {
- _net_nfc_server_handover_create_config_context_t *context = NULL;
-
- _net_nfc_util_alloc_mem(context, sizeof(*context));
-
- context->user_param = handle;
-
- net_nfc_util_create_record(record->TNF,
- &record->type_s, &record->id_s,
- &record->payload_s,
- &context->record);
-
- if ((result = _net_nfc_server_handover_create_selector_carrier_configs(
- type,
- _net_nfc_server_handover_server_create_carrier_configs_cb,
- context)) != NET_NFC_OK)
- {
- DEBUG_ERR_MSG("_create_selector_carrier_configs "
- "failed [%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("get_alternative_carrier_type_from_record "
- "failed [%d]", result);
- }
- }
- else
- {
- DEBUG_ERR_MSG("r_get_carrier_record_by_priority_order"
- " failed [%d]", result);
- }
- }
- else /* low power && count > 1 */
- {
- ndef_message_s selector;
-
- if ((result = _net_nfc_server_handover_create_low_power_selector_message(
- request,
- &selector)) == NET_NFC_OK)
- {
- _net_nfc_server_handover_server_create_carrier_configs_cb(
- NET_NFC_OK,
- &selector,
- user_param);
-
- net_nfc_util_free_ndef_message(&selector);
- }
- else
- {
- DEBUG_ERR_MSG("_create_low_power_selector_message"
- "failed [%d]", result);
- }
- }
- }
- else
- {
- DEBUG_ERR_MSG("net_nfc_util_get_alternative_carrier_record_count"
- "failed [%d]", result);
- }
-
- return result;
-}
-
-
-static net_nfc_error_e _net_nfc_server_handover_create_server_cb(
- net_nfc_snep_handle_h handle,
- net_nfc_error_e result,
- uint32_t type,
- data_s *data,
- void *user_param)
-{
- DEBUG_SERVER_MSG("type [0x%02x], result [%d], data [%p], user_param [%p]",
- type, result, data, user_param);
-
- if (result != NET_NFC_OK || data == NULL || data->buffer == NULL)
- {
- /* restart */
- return NET_NFC_NULL_PARAMETER;
- }
-
- switch (type)
- {
- case SNEP_REQ_GET :
- {
- ndef_message_s *request;
-
- /* TODO : send select response to requester */
- result =
- _net_nfc_server_handover_create_requester_from_rawdata(
- &request,
- data);
- if (result == NET_NFC_OK) {
- if (1/* TODO : check version */)
- {
- _net_nfc_server_handover_create_selector_msg(
- handle,
- request,
- user_param);
- }
- else
- {
- DEBUG_ERR_MSG("not supported version [0x%x]",
- result);
-
- result = NET_NFC_NOT_SUPPORTED;
- }
-
- net_nfc_util_free_ndef_message(request);
- }
- else
- {
- DEBUG_ERR_MSG("_net_nfc_server_handover_create"
- "_requester_from_rawdata failed [%d]",result);
- }
- }
- break;
-
- case SNEP_REQ_PUT :
- DEBUG_ERR_MSG("PUT request doesn't supported");
- result = NET_NFC_NOT_SUPPORTED;
- break;
-
- default :
- DEBUG_ERR_MSG("error [%d]", result);
- break;
- }
-
- return result;
-}
-#else
-
-
-
static net_nfc_error_e _net_nfc_server_handover_select_carrier_record(
ndef_message_s *request,
net_nfc_conn_handover_carrier_type_e *type,
return result;
}
-#endif
-
static void _net_nfc_server_handover_create_carrier_configs_2_cb(
net_nfc_error_e result,
ndef_message_s *selector,
"_carrier_record_cb result [%d]",result);
context->result = result;
+
if (result == NET_NFC_OK)
- {
context->state = NET_NFC_LLCP_STEP_04;
- }
else
- {
context->state = NET_NFC_MESSAGE_LLCP_ERROR;
- }
_net_nfc_server_handover_server_process(context);
}
context->result = result;
+ net_nfc_conn_handover_carrier_type_e type;
+
+ net_nfc_util_get_alternative_carrier_type_from_record(
+ context->record,
+ &type);
if (result == NET_NFC_OK)
{
result = _net_nfc_server_handover_convert_ndef_message_to_data(
&context->data);
DEBUG_SERVER_MSG("selector message created, length [%d]",
context->data.length);
- context->state = NET_NFC_LLCP_STEP_03;
+ if(type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)
+ context->state = NET_NFC_LLCP_STEP_04;
+ else
+ context->state = NET_NFC_LLCP_STEP_03;
}
else
{
}
static void _handover_default_activate_cb(int event,
- net_nfc_target_handle_s *handle, uint32_t sap, const char *san, void *user_param)
+ net_nfc_target_handle_s *handle,uint32_t sap, const char *san, void *user_param)
{
net_nfc_error_e result;
if (result == NET_NFC_OK)
{
- net_nfc_util_alloc_data(&context->data, data->length);
- memcpy(context->data.buffer, data->buffer, data->length);
+ if(context->type == NET_NFC_CONN_HANDOVER_CARRIER_WIFI_BSS)
+ context->state = NET_NFC_LLCP_STEP_RETURN;
+ else
+ {
+ net_nfc_util_alloc_data(&context->data, data->length);
+ memcpy(context->data.buffer, data->buffer, data->length);
- context->state = NET_NFC_LLCP_STEP_05;
+ context->state = NET_NFC_LLCP_STEP_05;
+ }
}
else
{
_net_nfc_server_handover_client_process(context);
}
-static void _net_nfc_server_handover_client_recv_cb(net_nfc_error_e result,
+static void _net_nfc_server_handover_client_recv_cb(
+ net_nfc_error_e result,
net_nfc_target_handle_s *handle,
net_nfc_llcp_socket_t socket,
data_s *data,
_net_nfc_server_handover_client_process(context);
}
-static void _net_nfc_server_handover_client_send_cb(net_nfc_error_e result,
+static void _net_nfc_server_handover_client_send_cb(
+ net_nfc_error_e result,
net_nfc_target_handle_s *handle,
net_nfc_llcp_socket_t socket,
data_s *data,
if (result != NET_NFC_OK)
{
- DEBUG_ERR_MSG("net_nfc_server_handover_process_carrier_record failed [%d]",result);
+ DEBUG_ERR_MSG("net_nfc_server_handover_process_carrier_record"
+ "failed [%d]",result);
}
break;
DEBUG_SERVER_MSG("result [%d], socket [%x], user_param [%p]",
result, socket, user_param);
+ HandoverRequestData *handover_data = NULL;
+ handover_data = (HandoverRequestData *)user_param;
if (result == NET_NFC_OK)
{
net_nfc_handover_context_t *context = NULL;
context->handle = handle;
context->socket = socket;
context->state = NET_NFC_LLCP_STEP_01;
+ context->type = handover_data->type;
context->user_param = user_param;
_net_nfc_server_handover_client_process(context);
}
}
}
-static void _net_nfc_server_handover_client_error_cb(net_nfc_error_e result,
+static void _net_nfc_server_handover_client_error_cb(
+ net_nfc_error_e result,
net_nfc_target_handle_s *handle,
net_nfc_llcp_socket_t socket,
data_s *data,