This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

P2P client code for CC3100?

Other Parts Discussed in Thread: CC3100, CC3100BOOST

I'm trying to get two MSP430 LaunchPads with CC3100BOOST boards to talk to each other via Wifi Direct.  I saw that the CC3100 SDK has a sample P2P server application, and it works great.  I'm having some trouble creating a complementary client application that would talk to this server, though.

Is there any sample P2P client code available?  One that would connect to this server?  Alternatively, can anyone coach us on the steps needed to modify the existing P2P code?

  • Hi,

    The sample P2P application's default mode is defined as below:


    /* Set the negotiation role (SL_P2P_ROLE_NEGOTIATE).
    * CC3100 will negotiate with remote device GO/client mode.
    * Other valid options are:
    * - SL_P2P_ROLE_GROUP_OWNER
    * - SL_P2P_ROLE_CLIENT */
    retVal = sl_WlanPolicySet(SL_POLICY_P2P, SL_P2P_POLICY(SL_P2P_ROLE_NEGOTIATE,
    SL_P2P_NEG_INITIATOR_ACTIVE),NULL,0);


    You can use SL_P2P_ROLE_CLIENT option to force the device to work as client.

    Regards,
    Gigi Joseph.
  • Thank you, but that doesn't really answer my question. I was asking about the sequence of operations that the client application should use in connecting to the server.

    For example, I know that we need to discover the P2P peers. I found that I can detect the LaunchPad that's running the server appication (the p2p app in the SDK) by executing sl_WlanGetNetworkList().  I'm having trouble after that, though.

    A couple of notes, here:

    (1) The p2p sample application contains the following instructions within establishConnectionWithP2Pdevice(); however, it seems to me that the wouldn't apply to the client app.  Is this correct, and do we need to use some variation of these?

              /* wlan connect call with dummy SSID to start the connection process */
              retVal = sl_WlanConnect(P2P_REMOTE_DEVICE, pal_Strlen(P2P_REMOTE_DEVICE), 0, &secParams, 0);
              ASSERT_ON_ERROR(retVal);

              while(!IS_P2P_NEG_REQ_RECEIVED(g_Status))
              {
                  _SlNonOsMainLoopTask();
              }

    (2)  I tried using sl_WlanConnect() after that, and it returned 0, but the sever didn't seem to detect any connection.  Do I need to use another API function, and are there some intermediate steps that I need to use instead?

    (3)  At the end of establishConnectionWithP2Pdevice(); we have the following sequence of operations. Again, I'm not certain if these would apply to the server app.  Do we need to replace these lines of code or perhaps eliminate them altogether?

              while ((!IS_IP_LEASED(g_Status) && !IS_IP_ACQUIRED(g_Status)) ||
                         (!IS_CONNECTED(g_Status) && !IS_STA_CONNECTED(g_Status)))
              {
                  _SlNonOsMainLoopTask();

                   if (IS_CONNECTION_FAILED(g_Status))
                   {
                        /* Error, connection is failed */
                        CLI_Write((_u8 *)" Connection Failed\r\n");
                        ASSERT_ON_ERROR(P2P_CONNECTION_FAILED);
                   }
              }

  • Hi Dean,

    The sequence of operation for the connection either in P2P client mode GO should be similar.

    You can easily modify the existing P2P example to connect 2 CC3100 device.

    For first device change the following macros

    #define P2P_REMOTE_DEVICE  "cc3100-p2p-device2"
    #define P2P_DEVICE_NAME    "cc3100-p2p-device1"

    For second device change the following macro

    #define P2P_REMOTE_DEVICE  "cc3100-p2p-device1"
    #define P2P_DEVICE_NAME    "cc3100-p2p-device2"

    For both the device modify the 'establishConnectionWithP2Pdevice' function.

    static _i32 establishConnectionWithP2Pdevice()
    {
        SlSecParams_t secParams = {0};
        _i32 retVal = 0;
    
        secParams.Key = KEY;
        secParams.KeyLen = pal_Strlen(KEY);
        secParams.Type = SECURITY_TYPE;
    
        /* wlan connect call with dummy SSID to start the connection process */
        retVal = sl_WlanConnect(P2P_REMOTE_DEVICE, pal_Strlen(P2P_REMOTE_DEVICE), 0, &secParams, 0);
        ASSERT_ON_ERROR(retVal);
    #if 0
        while(!IS_P2P_NEG_REQ_RECEIVED(g_Status))
        {
            _SlNonOsMainLoopTask();
        }
    
        /* Connect with the device requesting the connection */
        retVal = sl_WlanConnect(g_p2p_dev, pal_Strlen(g_p2p_dev), 0, &secParams, 0);
        ASSERT_ON_ERROR(retVal);
    #endif
        while ((!IS_IP_LEASED(g_Status) && !IS_IP_ACQUIRED(g_Status)) ||
                (!IS_CONNECTED(g_Status) && !IS_STA_CONNECTED(g_Status)))
        {
            _SlNonOsMainLoopTask();
    
            if(IS_CONNECTION_FAILED(g_Status))
            {
                /* Error, connection is failed */
                CLI_Write((_u8 *)" Connection Failed\r\n");
                ASSERT_ON_ERROR(P2P_CONNECTION_FAILED);
            }
        }
    
        return SUCCESS;
    }

    Both the device will negotiate with each other for GO and client role. You will also have to change one of the device to use TCP client to connect the TCP server of remote device.

    'sl_WlanConnect' needs to be called with the remote device name to establish a connection.

    Regards,

    Ankur

  • I tried this approach but encountered some problems connecting.

    As a test, I tried connnecting to one of the devices using my cell phone. It did not work until I removed the "#if 0" directive.  That is, it looks as though the following code segment:

        while(!IS_P2P_NEG_REQ_RECEIVED(g_Status))
        {
            _SlNonOsMainLoopTask();
        }
    
        /* Connect with the device requesting the connection */
        retVal = sl_WlanConnect(g_p2p_dev, pal_Strlen(g_p2p_dev), 0, &secParams, 0);
        ASSERT_ON_ERROR(retVal);

    is necessary for the firmware to detect that my cell phone is attempting a connection. Once this happens, the STATUS_BIT_IP_ACQUIRED and STATUS_BIT_P2P_NEG_REQ_RECEIVED bits in g_Status are set.

    Am I missing something?  Also, should we have any corresponding changes on the client side?

  • Hi Dean,

    For simplelink device to connect with another Wi-Fi direct device function 'sl_WlanConnect()' with remote device name as argument should be called.

    In the example provided in the SDK two 'sl_WlanConnect()' are called. First 'sl_WlanConnect()' is called with a dummy device name to enable the scan on the cc3100. Once the remote device initiate a connection with CC3100, cc3100 will receive the remote device information and will call another 'sl_WlanConnect()' with correct parameters for successful connection.

    If the remote device name is know user needs to call 'sl_WlanConnect()' only once with correct device name (modifications shared in my previous post).

    Please let us know if this answers you query.

    Regards,
    Ankur
  • Thank you for the response, Ankur1.  What you said about the example in the SDK is certainly true.

    I am a bit confused, however, since this doesn't seem to match the example given earlier.  In the example given earlier in this discussion, only one call to sl_WlanConnect() is used within establishConnectionWithP2Pdevice().  (The second call is eliminated by the '#if 0' directive.)  Was this an error?

  • Sorry; I see how you said that it only needs to be called once if the device name is known. My error.
  • Hi Dean,

    I am closing this thread, if you have follow up queries please open a new thread and add a link to this one for reference.

    Regards,
    Ankur