Other Parts Discussed in Thread: CC3235SF
As advised in the link above, I am trying to scan and connect manually for p2p connection between two CC3235SF LaunchPads.
According to 4.5.4 in the swru445, network processor guide document
To retrieve for peers, activate the WiFi direct scan policy and then there are two ways to search for peers, calling the P2P_DEVFOUND event or sl_WlanGetNetworkList API.
I had try two ways to retrieve peers. I can find nearby peers with the P2P_DEVFOUND event, but couldn't find with sl_WlanGetNetworkList (It is return value is 0)
and It is my code.(I modify the 'network_terminal' example)
(WiFi direct policy set ROLE_NEGOTIATE and NEG_INITIATOR_RAND_BACKOFF)
/* start p2p mode */ int32_t _setP2Pparams(void) { int32_t ret ; int32_t Mode; uint8_t channels[4] = {0}; uint8_t nameLen = 0; /* Sets role negotiations: P2P intent and negotiation initiator */ ret = sl_WlanPolicySet(SL_WLAN_POLICY_P2P, SL_WLAN_P2P_POLICY( SL_WLAN_P2P_ROLE_NEGOTIATE, SL_WLAN_P2P_NEG_INITIATOR_RAND_BACKOFF), NULL, 0); ASSERT_ON_ERROR(ret, WLAN_ERROR); // connection policy for auto connection : auto, fast, anyp2p, auto provisioning(not p2p) // ret = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(1, 0, 1, 0), NULL, 0); // ret = sl_WlanPolicySet(SL_WLAN_POLICY_CONNECTION, SL_WLAN_CONNECTION_POLICY(1, 1, 0, 0), NULL, 0); // if (ret < 0) // { // UART_PRINT( // "Network Terminal - p2p wlanPolicy(connect) set fail \n"); // } /* Set the P2P device type, * which is a part of the discovery process. Default is 1-0050F204-1 */ ret = sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, SL_WLAN_P2P_OPT_DEV_TYPE, strlen(P2P_DEVICE_TYPE), (const uint8_t *)P2P_DEVICE_TYPE); ASSERT_ON_ERROR(ret, WLAN_ERROR); /* Configure device listen and operation channels */ channels[0] = LISTEN_CHANNEL; channels[1] = LISTEN_REGULATORY_CLASS; channels[2] = OPRA_CHANNEL; channels[3] = OPRA_REGULATORY_CLASS; ret = sl_WlanSet(SL_WLAN_CFG_P2P_PARAM_ID, SL_WLAN_P2P_OPT_CHANNEL_N_REGS, sizeof(channels), channels); ASSERT_ON_ERROR(ret, WLAN_ERROR); nameLen = sizeof(app_CB.P2P_CB.p2pDeviceName); /* Print the device's name */ ret = sl_NetAppGet(SL_NETAPP_DEVICE_ID, SL_NETAPP_DEVICE_URN, &nameLen, (uint8_t*)&app_CB.P2P_CB.p2pDeviceName[0]); ASSERT_ON_ERROR(ret, NETAPP_ERROR); UART_PRINT("\n\r[p2pstart] : Starting NWP in P2P role..\n\r"); UART_PRINT("\n\rDevice name: %s\n\r", &app_CB.P2P_CB.p2pDeviceName); /* Set role to P2P and perform NWP reset */ ret = sl_WlanSetMode(ROLE_P2P); ASSERT_ON_ERROR(ret, WLAN_ERROR); ret = sl_Stop(SL_STOP_TIMEOUT); ASSERT_ON_ERROR(ret, DEVICE_ERROR); Mode = sl_Start(0, 0, 0); if(Mode != ROLE_P2P) { UART_PRINT( "\r\n[p2pstart] : Failed to configure device to P2P mode...\r\n"); ASSERT_ON_ERROR(Mode, DEVICE_ERROR); return(-1); } else { app_CB.P2P_CB.P2PsecParams.Key = (signed char *)""; app_CB.P2P_CB.P2PsecParams.KeyLen = strlen( (const char*)app_CB.P2P_CB.P2PsecParams.Key); app_CB.P2P_CB.P2PsecParams.Type = SL_WLAN_SEC_TYPE_P2P_PBC; app_CB.Role = ROLE_P2P; } /* enable scan policy */ _u32 intervalInSeconds = 10; ret = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(1, 1), (_u8*)&intervalInSeconds, sizeof(intervalInSeconds)); if (ret < 0) { UART_PRINT( "Network Terminal - p2p wlanPolicy(scan) set fail \n"); } return(ret); }
/* p2pscan command callback */ int32_t cmdP2PScancallback(void *arg) { int32_t ret = -1; uint8_t triggeredScanTrials = 0; ScanCmd_t ScanParams; _u32 intervalInSeconds = 10, getIntervalTime; _u32 length = sizeof(intervalInSeconds); _u8 policy = 0; /* set Scan policy */ ret = sl_WlanPolicySet(SL_WLAN_POLICY_SCAN, SL_WLAN_SCAN_POLICY(1, 1), (_u8*)&intervalInSeconds, sizeof(intervalInSeconds)); if (ret < 0) { UART_PRINT( "Network Terminal - p2p wlanPolicy(scan) set fail %d\n\r", ret); } ret = sl_WlanPolicyGet(SL_WLAN_POLICY_SCAN, &policy, (_u8*)&getIntervalTime, (_u8*)&length); if (ret < 0) { UART_PRINT( "Network Terminal - p2p wlanPolicy(scan) get fail %d\n\r", ret); } if (policy && SL_WLAN_SCAN_POLICY(0, 0)) { UART_PRINT("scan policy is set to scan disable\n\r"); } else if (policy && SL_WLAN_SCAN_POLICY(0, 1)) { if (policy && SL_WLAN_SCAN_POLICY(1, 1)) { UART_PRINT("scan policy is set to scan all ssid\n\r"); } else { UART_PRINT("scan policy is set to scan hidden ssid\n\r"); } } else if (policy && SL_WLAN_SCAN_POLICY(1, 0)) { UART_PRINT("scan policy is set to scan visible ssid\n\r"); } UART_PRINT("scan interval is %d\n\r", getIntervalTime); memset(&ScanParams, 0x0, sizeof(ScanParams)); ScanParams.numOfentries = MAX_SSID_ENTRIES; /* Clear the results buffer */ memset(&app_CB.gDataBuffer, 0x0, sizeof(app_CB.gDataBuffer)); /* Get scan results from NWP - results would be placed inside the provided buffer */ ret = sl_WlanGetNetworkList(ScanParams.index, ScanParams.numOfentries, &app_CB.gDataBuffer.netEntries[ScanParams.index]); /* If scan policy isn't set, invoking 'sl_WlanGetNetworkList()' * for the first time triggers 'one shot' scan. * The scan parameters would be according to the system persistent * settings on enabled channels. * For more information, see: <simplelink user guide, page: pr.> */ if(SL_ERROR_WLAN_GET_NETWORK_LIST_EAGAIN == ret) { while(triggeredScanTrials < MAX_SCAN_TRAILS) { /* We wait for one second for the NWP to complete the initiated scan and collect results */ sleep(1); /* Collect results form one-shot scans.*/ UART_PRINT("trigger one-shot scan\n\r"); /* Get scan results from NWP - results would be placed inside the provided buffer */ ret = sl_WlanGetNetworkList(ScanParams.index, ScanParams.numOfentries, &app_CB.gDataBuffer.netEntries[ScanParams.index]); if(ret > 0) { break; } else { /* If NWP results aren't ready, try 'MAX_SCAN_TRAILS' attempts to get results */ triggeredScanTrials++ ; } } } if(ret <= 0) { UART_PRINT("\n\r[scan] : Unable to retrieve the network list %d\n\r", ret); return(-1); } /* Print the result table */ printScanResults(ret); return ret; }
/* P2P_DEVFOUND event in slwlanevent handler */ case SL_WLAN_EVENT_P2P_DEVFOUND: { UART_PRINT("\n\r[WLAN EVENT] P2P Remote device found\n\r"); strncpy((char *)app_CB.P2P_CB.p2pPeerDeviceName, (char *)pWlanEvent->Data.P2PDevFound.GoDeviceName, pWlanEvent->Data.P2PDevFound.GoDeviceNameLen); app_CB.P2P_CB.p2pPeerDeviceName[pWlanEvent->Data.P2PDevFound.GoDeviceNameLen] = NULL; UART_PRINT("[WLAN EVENT] \tName: %s\n\r", app_CB.P2P_CB.p2pPeerDeviceName); UART_PRINT("[WLAN EVENT] \tName len: %d\n\r", pWlanEvent->Data.P2PDevFound.GoDeviceNameLen); UART_PRINT("[WLAN EVENT] \tMAC: %x:%x:%x:%x:%x:%x\n\r", pWlanEvent->Data.P2PDevFound.Mac[0], pWlanEvent->Data.P2PDevFound.Mac[1], pWlanEvent->Data.P2PDevFound.Mac[2], pWlanEvent->Data.P2PDevFound.Mac[3], pWlanEvent->Data.P2PDevFound.Mac[4], pWlanEvent->Data.P2PDevFound.Mac[5]); UART_PRINT("[WLAN EVENT] \tWpsMethod: %d\n\r", pWlanEvent->Data.P2PDevFound.WpsMethod); sem_post(&(app_CB.P2P_CB.DeviceFound)); }
And I tried to connect to the found peer(mysimplelink_Bf in above picture) using sl_WlanConnect, but no response.
How can retrieve(using getnetworklist api) and connect to peer? Please give me some advice.
Thanks.