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.

CCS/CC3220SF-LAUNCHXL: Gateway/SubnetMask when using "sl_WlanConnect()"

Part Number: CC3220SF-LAUNCHXL


Tool/software: Code Composer Studio

Hi,

When we are connecting to the WiFi network using a static IP, we provide the gateway and the subnet mask parameters. However, It appears that the SimpleLink SW is not using either of these parameters. I've come to this conclusion based on two observations. 1) Setting the -gw to all zeros has no affect, 2) the subnet mask is not passed into the sl_WlanConnect() function. Can you provide an explanation as to how the gateway parameter is used when connecting to the WiFi network with a static IP?

Thanks!  Glenn.

  • hi Glenn,

    sl_WlanConnect only handles the L2 connection (802.11) to the access point.

    The IP Addresses will be acquired by default using DHCP following a successful connection.

    If you want to change this default and use static IP, you can call the following command (before calling the sl_WlanConnect):

    sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_STATIC,....)

    see for example:

    SlNetCfgIpV4Args_t ipV4;
    ipV4.Ip = (_u32)SL_IPV4_VAL(10,1,1,201); // _u32 IP address 
    ipV4.IpMask = (_u32)SL_IPV4_VAL(255,255,255,0); // _u32 Subnet mask for this STA/P2P
    ipV4.IpGateway = (_u32)SL_IPV4_VAL(10,1,1,1); // _u32 Default gateway address
    ipV4.IpDnsServer = (_u32)SL_IPV4_VAL(8,16,32,64); // _u32 DNS server address
    
    sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE,SL_NETCFG_ADDR_STATIC,sizeof(SlNetCfgIpV4Args_t),(_u8 *)&ipV4); 
    sl_Stop(0);
    sl_Start(NULL,NULL,NULL);
    
    

    Br,

    Kobi

  • Hi Glenn,

    If you want to use static network parameters for a STA mode (IP, GW, DNS, subnet mask) you need to use sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_STATIC,..) before calling sl_WlanConnect(). You should to realize that connecting into WLAN and obtaining netwrok parameters are a different layers of ISO/OSI model. From this reason are used different APIs for such purpose.

    Jan

  • Hi Kobi,

    In the network terminal example, if an IP is specified in the connect message,the function cmdWlanConnectCallback() calls

          setStaticIPConfig((uint8_t*)(ConnectParams.ip), (uint8_t*)(ConnectParams.gw), (uint8_t*)(ConnectParams.dns));

    This set function which is located in wlan_cmd.c ultimately calls the function you mentioned:

         sl_NetCfgSet(SL_NETCFG_IPV4_STA_ADDR_MODE, SL_NETCFG_ADDR_STATIC, sizeof(SlNetCfgIpV4Args_t), (uint8_t *)&ipV4);

    However, it calls it with the subnet mask hard coded on line 2530 to:  

    LINE 2530:    ipV4.IpMask = (unsigned long)(SL_IPV4_VAL(255,255,255,0));    Was that intentional or just an oversight?

    Also, on LINE 2519, as long as pGw in not NULL, the gateway should be set to whatever is in the connect message.

    So if I specify the GW as (0,0,0,0) I should fail to connect, but the device still connects. Shouldn't it fail?

    LINE 2519: 

    if (pGw != NULL)
    {
    ret = ipv4AddressParse((char*)pGw, (uint32_t*)&ipV4.IpGateway);
    ASSERT_ON_ERROR(ret, CMD_ERROR);
    }
    else
    {
    /* Use the first address in subnet mask 24, as default GW */
    ipV4.IpGateway = ((ipV4.Ip & 0xFFFFFF00)|0x00000001);
    }

    Thanks, Glenn.

  • Regarding the IP mask - you are right. This is a bug in the example.

    Regarding  the GW - I'm not sure if we are looking for error values (such as addresses outside the local network). The connection to the AP however is not related and it can be setup successfully. You will not be able to reach the GW of course.

    Br,

    Kobi