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.

sl_NetCfgGet() garbage value for SL_MAC_ADDRESS_GET

Other Parts Discussed in Thread: CC3200

Hello,

I am using cc3200 launchpad and SDK version 0.5.2. Before few days I was able to retrieve MAC address of CC3200 by doing..

unsigned char macAddressVal[SL_MAC_ADDR_LEN];
unsigned cahr macAddressLen = SL_MAC_ADDR_LEN;

memset(macAddressVal, '\0', sizeof(macAddressVal));
lReport = sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(unsigned char *)macAddressVal);

But now value of MAC address is certain garbage. I can not figure out reason behind this. It would be appreciable if any one can point me towards troubleshooting of this problem. 

  • [ Update ]

    My chip version is xCC3200HZ. Radio tool can read the mac address so I guess MAC is not get erased from chip.

  • I am still facing this issue..expecting some inputs from TI employees..

  • Niral,

    I'm not seeing this issue on my setup - I consistently get the correct MAC address of the device.

    Are you seeing this only w/ this perticular board?

    -Praneet

  • I do not have any other board so I can not answer your question. When I used same board with radio tool, it displayed the MAC address. I tried same code provided with radio tool source but did not get MAC address..

    Can you post source code of above result you have got???

  • 8182.main.c
    //*****************************************************************************
    //
    //  Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
    //
    //
    //  Redistribution and use in source and binary forms, with or without
    //  modification, are permitted provided that the following conditions
    //  are met:
    //
    //  Redistributions of source code must retain the above copyright
    //  notice, this list of conditions and the following disclaimer.
    //
    //  Redistributions in binary form must reproduce the above copyright
    //  notice, this list of conditions and the following disclaimer in the
    //  documentation and/or other materials provided with the
    //  distribution.
    //
    //  Neither the name of Texas Instruments Incorporated nor the names of
    //  its contributors may be used to endorse or promote products derived
    //  from this software without specific prior written permission.
    //
    //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    //  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    //  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    //  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    //  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    //  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    //  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    //  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    //  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    //
    //*****************************************************************************
    
    
    //*****************************************************************************
    //
    // Application Name     -   Getting started with Wi-Fi STATION mode
    // Application Overview -   This is a sample application demonstrating how to
    //                          start CC3200 in WLAN-Station mode and connect to a
    //                          Wi-Fi access-point. The application connects to an
    //                          access-point and ping the gateway. It also checks
    //                          for an internet connectivity by pinging "www.ti.com"
    // Application Details  -
    // http://processors.wiki.ti.com/index.php/CC32xx_Getting_Started_with_WLAN_Station
    // or
    // doc\examples\CC32xx_Getting_Started_with_WLAN_Station.pdf
    //
    //*****************************************************************************
    
    
    //****************************************************************************
    //
    //! \addtogroup getting_started_sta
    //! @{
    //
    //****************************************************************************
    
    #include <stdlib.h>
    #include <string.h>
    
    // Simplelink includes
    #include "simplelink.h"
    
    //Driverlib includes
    #include "hw_types.h"
    #include "hw_ints.h"
    #include "rom.h"
    #include "rom_map.h"
    #include "interrupt.h"
    #include "prcm.h"
    #include "utils.h"
    
    //Free_rtos/ti-rtos includes
    #include "osi.h"
    #ifdef USE_FREERTOS
    #include "FreeRTOS.h"
    #include "task.h"
    #endif
    
    //Common interface includes
    #include "gpio_if.h"
    #ifndef NOTERM
    #include "uart_if.h"
    #endif
    #include "pinmux.h"
    
    
    #ifdef NOTERM
    #define UART_PRINT(x, ...)
    #else
    #define UART_PRINT Report
    #endif
    
    #define APPLICATION_NAME        "WLAN STATION"
    #define APPLICATION_VERSION     "1.0.0"
    #define SUCCESS                 0
    
    //
    // Values for below macros shall be modified as per access-point(AP) properties
    // SimpleLink device will connect to following AP when application is executed
    //
    #define SSID_NAME           "cc3200demo"    /* AP SSID */
    #define SECURITY_TYPE       SL_SEC_TYPE_OPEN/* Security type (OPEN or WEP or WPA) */
    #define SECURITY_KEY        ""              /* Password of the secured AP */
    #define SSID_LEN_MAX        (32)
    #define BSSID_LEN_MAX       (6)
    #define HOST_NAME           "www.ti.com"
    
    //
    // Values for below macros shall be modified for setting the 'Ping' properties
    //
    #define PING_INTERVAL       1000    /* In msecs */
    #define PING_TIMEOUT        3000    /* In msecs */
    #define PING_PKT_SIZE       20      /* In bytes */
    #define NO_OF_ATTEMPTS      3
    
    #define SL_STOP_TIMEOUT     30
    #define UNUSED(x)           x = x
    #define SPAWN_TASK_PRIORITY 9
    #define OSI_STACK_SIZE      2048
    
    // Loop forever, user can change it as per application's requirement
    #define LOOP_FOREVER(line_number) \
                {\
                    while(1); \
                }
    
    // check the error code and handle it
    #define ASSERT_ON_ERROR(line_number, error_code) \
                {\
                    if (error_code < 0) return error_code;\
                }
    
    //Status bits - These are used to set/reset the corresponding bits in
    // given variable
    typedef enum{
        STATUS_BIT_CONNECTION =  0, // If this bit is Set SimpleLink device is
                                    // connected to the AP
    
        STATUS_BIT_IP_AQUIRED,       // If this bit is Set SimpleLink device has
                                     // acquired IP
    
        STATUS_BIT_PING_DONE        // If this bit is Set SimpleLink device has
                                    // successfully completed Ping operation
    }e_StatusBits;
    
    // Application specific status/error codes
    typedef enum{
        // Choosing -0x7D0 to avoid overlap w/ host-driver's error codes
        LAN_CONNECTION_FAILED = -0x7D0,
        INTERNET_CONNECTION_FAILED = LAN_CONNECTION_FAILED - 1,
        DEVICE_NOT_IN_STATION_MODE = INTERNET_CONNECTION_FAILED - 1,
    
        STATUS_CODE_MAX = -0xBB8
    }e_AppStatusCodes;
    
    #define SET_STATUS_BIT(status_variable, bit)  status_variable |= (1<<(bit))
    #define CLR_STATUS_BIT(status_variable, bit)  status_variable &= ~(1<<(bit))
    #define CLR_STATUS_BIT_ALL(status_variable)   (status_variable = 0)
    #define GET_STATUS_BIT(status_variable, bit)  (0 != (status_variable & \
                                                                    (1<<(bit))))
    
    #define IS_CONNECTED(status_variable)         GET_STATUS_BIT(status_variable, \
                                                           STATUS_BIT_CONNECTION)
    #define IS_IP_ACQUIRED(status_variable)       GET_STATUS_BIT(status_variable, \
                                                           STATUS_BIT_IP_AQUIRED)
    #define IS_PING_DONE(status_variable)         GET_STATUS_BIT(status_variable, \
                                                           STATUS_BIT_PING_DONE)
    
    
    //
    // GLOBAL VARIABLES -- Start
    //
    unsigned long  g_ulStatus = 0;//SimpleLink Status
    unsigned long  g_ulPingPacketsRecv = 0; //Number of Ping Packets received
    unsigned long  g_ulGatewayIP = 0; //Network Gateway IP address
    unsigned char  g_ucConnectionSSID[SSID_LEN_MAX+1]; //Connection SSID
    unsigned char  g_ucConnectionBSSID[BSSID_LEN_MAX]; //Connection BSSID
    
    #if defined(gcc)
    extern void (* const g_pfnVectors[])(void);
    #endif
    #if defined(ewarm)
    extern uVectorEntry __vector_table;
    #endif
    //
    // GLOBAL VARIABLES -- End
    //
    
    
    //****************************************************************************
    //                      LOCAL FUNCTION PROTOTYPES
    //****************************************************************************
    static long WlanConnect();
    void WlanStationMode( void *pvParameters );
    static long CheckLanConnection();
    static long CheckInternetConnection();
    static void InitializeAppVariables();
    static long ConfigureSimpleLinkToDefaultState();
    
    
    #ifdef USE_FREERTOS
    //*****************************************************************************
    // FreeRTOS User Hook Functions enabled in FreeRTOSConfig.h
    //*****************************************************************************
    
    //*****************************************************************************
    //
    //! \brief Application defined hook (or callback) function - assert
    //!
    //! \param[in]  pcFile - Pointer to the File Name
    //! \param[in]  ulLine - Line Number
    //!
    //! \return none
    //!
    //*****************************************************************************
    void
    vAssertCalled( const char *pcFile, unsigned long ulLine )
    {
        //Handle Assert here
        while(1)
        {
        }
    }
    
    //*****************************************************************************
    //
    //! \brief Application defined idle task hook
    //!
    //! \param  none
    //!
    //! \return none
    //!
    //*****************************************************************************
    void
    vApplicationIdleHook( void)
    {
        //Handle Idle Hook for Profiling, Power Management etc
    }
    
    //*****************************************************************************
    //
    //! \brief Application defined malloc failed hook
    //!
    //! \param  none
    //!
    //! \return none
    //!
    //*****************************************************************************
    void vApplicationMallocFailedHook()
    {
        //Handle Memory Allocation Errors
        while(1)
        {
        }
    }
    
    //*****************************************************************************
    //
    //! \brief Application defined stack overflow hook
    //!
    //! \param  none
    //!
    //! \return none
    //!
    //*****************************************************************************
    void vApplicationStackOverflowHook( xTaskHandle *pxTask,
                                       signed portCHAR *pcTaskName)
    {
        //Handle FreeRTOS Stack Overflow
        while(1)
        {
        }
    }
    #endif //USE_FREERTOS
    
    
    //*****************************************************************************
    // SimpleLink Asynchronous Event Handlers -- Start
    //*****************************************************************************
    
    
    //*****************************************************************************
    //
    //! \brief The Function Handles WLAN Events
    //!
    //! \param[in]  pWlanEvent - Pointer to WLAN Event Info
    //!
    //! \return None
    //!
    //*****************************************************************************
    void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
    {
        switch(pWlanEvent->Event)
        {
            case SL_WLAN_CONNECT_EVENT:
            {
                SET_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
    
                //
                // Information about the connected AP (like name, MAC etc) will be
                // available in 'sl_protocol_wlanConnectAsyncResponse_t'-Applications
                // can use it if required
                //
                //  sl_protocol_wlanConnectAsyncResponse_t *pEventData = NULL;
                // pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
                //
    
                // Copy new connection SSID and BSSID to global parameters
                memcpy(g_ucConnectionSSID,pWlanEvent->EventData.
                       STAandP2PModeWlanConnected.ssid_name,
                       pWlanEvent->EventData.STAandP2PModeWlanConnected.ssid_len);
                memcpy(g_ucConnectionBSSID,
                       pWlanEvent->EventData.STAandP2PModeWlanConnected.bssid,
                       SL_BSSID_LENGTH);
    
                UART_PRINT("[WLAN EVENT] STA Connected to the AP: %s ,"
                            "BSSID: %x:%x:%x:%x:%x:%x\n\r",
                          g_ucConnectionSSID,g_ucConnectionBSSID[0],
                          g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
                          g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
                          g_ucConnectionBSSID[5]);
            }
            break;
    
            case SL_WLAN_DISCONNECT_EVENT:
            {
                sl_protocol_wlanConnectAsyncResponse_t*  pEventData = NULL;
    
                CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
                CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
    
                pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;
    
                // If the user has initiated 'Disconnect' request,
                //'reason_code' is SL_USER_INITIATED_DISCONNECTION
                if(SL_USER_INITIATED_DISCONNECTION == pEventData->reason_code)
                {
                    UART_PRINT("[WLAN EVENT]Device disconnected from the AP: %s,"
                    "BSSID: %x:%x:%x:%x:%x:%x on application's request \n\r",
                               g_ucConnectionSSID,g_ucConnectionBSSID[0],
                               g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
                               g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
                               g_ucConnectionBSSID[5]);
                }
                else
                {
                    UART_PRINT("[WLAN ERROR]Device disconnected from the AP AP: %s,"
                    "BSSID: %x:%x:%x:%x:%x:%x on an ERROR..!! \n\r",
                               g_ucConnectionSSID,g_ucConnectionBSSID[0],
                               g_ucConnectionBSSID[1],g_ucConnectionBSSID[2],
                               g_ucConnectionBSSID[3],g_ucConnectionBSSID[4],
                               g_ucConnectionBSSID[5]);
                }
                memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID));
                memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID));
            }
            break;
    
            default:
            {
                UART_PRINT("[WLAN EVENT] Unexpected event [0x%x]\n\r",
                           pWlanEvent->Event);
            }
            break;
        }
    }
    
    //*****************************************************************************
    //
    //! \brief This function handles network events such as IP acquisition, IP
    //!           leased, IP released etc.
    //!
    //! \param[in]  pNetAppEvent - Pointer to NetApp Event Info
    //!
    //! \return None
    //!
    //*****************************************************************************
    void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
    {
        switch(pNetAppEvent->Event)
        {
            case SL_NETAPP_IPV4_ACQUIRED:
            {
                SlIpV4AcquiredAsync_t *pEventData = NULL;
    
                SET_STATUS_BIT(g_ulStatus, STATUS_BIT_IP_AQUIRED);
    
                //Ip Acquired Event Data
                pEventData = &pNetAppEvent->EventData.ipAcquiredV4;
    
                //Gateway IP address
                g_ulGatewayIP = pEventData->gateway;
    
                UART_PRINT("[NETAPP EVENT] IP Acquired: IP=%d.%d.%d.%d , "
                "Gateway=%d.%d.%d.%d\n\r",
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,3),
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,2),
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,1),
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.ip,0),
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,3),
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,2),
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,1),
                SL_IPV4_BYTE(pNetAppEvent->EventData.ipAcquiredV4.gateway,0));
            }
            break;
    
            default:
            {
                UART_PRINT("[NETAPP EVENT] Unexpected event [0x%x] \n\r",
                           pNetAppEvent->Event);
            }
            break;
        }
    }
    
    
    //*****************************************************************************
    //
    //! \brief This function handles HTTP server events
    //!
    //! \param[in]  pServerEvent - Contains the relevant event information
    //! \param[in]    pServerResponse - Should be filled by the user with the
    //!                                      relevant response information
    //!
    //! \return None
    //!
    //****************************************************************************
    void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent,
                                      SlHttpServerResponse_t *pHttpResponse)
    {
        // Unused in this application
    }
    
    //*****************************************************************************
    //
    //! \brief This function handles General Events
    //!
    //! \param[in]     pDevEvent - Pointer to General Event Info
    //!
    //! \return None
    //!
    //*****************************************************************************
    void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
    {
        //
        // Most of the general errors are not FATAL are are to be handled
        // appropriately by the application
        //
        UART_PRINT("[GENERAL EVENT] - ID=[%d] Sender=[%d]\n\n",
                   pDevEvent->EventData.deviceEvent.status,
                   pDevEvent->EventData.deviceEvent.sender);
    }
    
    
    //*****************************************************************************
    //
    //! This function handles socket events indication
    //!
    //! \param[in]      pSock - Pointer to Socket Event Info
    //!
    //! \return None
    //!
    //*****************************************************************************
    void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
    {
        //
        // This application doesn't work w/ socket - Events are not expected
        //
        switch( pSock->Event )
        {
            case SL_NETAPP_SOCKET_TX_FAILED:
                switch( pSock->EventData.status )
                {
                    case SL_ECLOSE:
                        UART_PRINT("[SOCK ERROR] - close socket (%d) operation "
                        "failed to transmit all queued packets\n\n",
                               pSock->EventData.sd);
                        break;
                    default:
                        UART_PRINT("[SOCK ERROR] - TX FAILED : socket %d , reason"
                            "(%d) \n\n",
                               pSock->EventData.sd, pSock->EventData.status);
                }
                break;
    
            default:
                UART_PRINT("[SOCK EVENT] - Unexpected Event [%x0x]\n\n",pSock->Event);
        }
    }
    
    
    //*****************************************************************************
    //
    //! \brief This function handles ping report events
    //!
    //! \param[in]     pPingReport - Ping report statistics
    //!
    //! \return None
    //!
    //*****************************************************************************
    static void SimpleLinkPingReport(SlPingReport_t *pPingReport)
    {
        SET_STATUS_BIT(g_ulStatus, STATUS_BIT_PING_DONE);
        g_ulPingPacketsRecv = pPingReport->PacketsReceived;
    }
    
    //*****************************************************************************
    // SimpleLink Asynchronous Event Handlers -- End
    //*****************************************************************************
    
    
    
    //*****************************************************************************
    //
    //! \brief This function initializes the application variables
    //!
    //! \param    None
    //!
    //! \return None
    //!
    //*****************************************************************************
    static void InitializeAppVariables()
    {
        g_ulStatus = 0;
        g_ulPingPacketsRecv = 0;
        g_ulGatewayIP = 0;
        memset(g_ucConnectionSSID,0,sizeof(g_ucConnectionSSID));
        memset(g_ucConnectionBSSID,0,sizeof(g_ucConnectionBSSID));
    }
    
    
    //*****************************************************************************
    //! \brief This function puts the device in its default state. It:
    //!           - Set the mode to STATION
    //!           - Configures connection policy to Auto and AutoSmartConfig
    //!           - Deletes all the stored profiles
    //!           - Enables DHCP
    //!           - Disables Scan policy
    //!           - Sets Tx power to maximum
    //!           - Sets power policy to normal
    //!           - TBD - Unregister mDNS services
    //!
    //! \param   none
    //! \return  On success, zero is returned. On error, negative is returned
    //*****************************************************************************
    
    static long ConfigureSimpleLinkToDefaultState()
    {
        SlVersionFull   ver = {0};
    
        unsigned char ucVal = 1;
        unsigned char ucConfigOpt = 0;
        unsigned char ucConfigLen = 0;
        unsigned char ucPower = 0;
    
        long lRetVal = -1;
        long lMode = -1;
    
        lMode = sl_Start(0, 0, 0);
        ASSERT_ON_ERROR(__LINE__, lMode);
    
        // Get the device's version-information
        ucConfigOpt = SL_DEVICE_GENERAL_VERSION;
        ucConfigLen = sizeof(ver);
        lRetVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &ucConfigOpt,
                                    &ucConfigLen, (unsigned char *)(&ver));
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        UART_PRINT("Host Driver Version: %s\n\r",SL_DRIVER_VERSION);
        UART_PRINT("Build Version %d.%d.%d.%d.31.%d.%d.%d.%d.%d.%d.%d.%d\n\r",
        ver.NwpVersion[0],ver.NwpVersion[1],ver.NwpVersion[2],ver.NwpVersion[3],
        ver.ChipFwAndPhyVersion.FwVersion[0],ver.ChipFwAndPhyVersion.FwVersion[1],
        ver.ChipFwAndPhyVersion.FwVersion[2],ver.ChipFwAndPhyVersion.FwVersion[3],
        ver.ChipFwAndPhyVersion.PhyVersion[0],ver.ChipFwAndPhyVersion.PhyVersion[1],
        ver.ChipFwAndPhyVersion.PhyVersion[2],ver.ChipFwAndPhyVersion.PhyVersion[3]);
    
        // Set connection policy to Auto + SmartConfig
        //      (Device's default connection policy)
        lRetVal = sl_WlanPolicySet(SL_POLICY_CONNECTION,
                                    SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Remove all profiles
        lRetVal = sl_WlanProfileDel(0xFF);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // If the device is not in station-mode, try putting it in staion-mode
        if (ROLE_STA != lMode)
        {
            if (ROLE_AP == lMode)
            {
                // If the device is in AP mode, we need to wait for this event
                // before doing anything
                while(!IS_IP_ACQUIRED(g_ulStatus))
                {
    #ifndef SL_PLATFORM_MULTI_THREADED
                  _SlNonOsMainLoopTask();
    #endif
                }
            }
    
            // Switch to STA role and restart
            lRetVal = sl_WlanSetMode(ROLE_STA);
            ASSERT_ON_ERROR(__LINE__, lRetVal);
    
            lRetVal = sl_Stop(SL_STOP_TIMEOUT);
            ASSERT_ON_ERROR(__LINE__, lRetVal);
    
            // reset status bits
            CLR_STATUS_BIT_ALL(g_ulStatus);
    
            lRetVal = sl_Start(0, 0, 0);
            ASSERT_ON_ERROR(__LINE__, lRetVal);
    
            // Check if the device is in station again
            if (ROLE_STA != lRetVal)
            {
                // We don't want to proceed if the device is not up in STA-mode
                return DEVICE_NOT_IN_STATION_MODE;
            }
        }
    
        //
        // Device in station-mode. Disconnect previous connection if any
        // The function returns 0 if 'Disconnected done', negative number if already
        // disconnected Wait for 'disconnection' event if 0 is returned, Ignore
        // other return-codes
        //
        lRetVal = sl_WlanDisconnect();
        if(0 == lRetVal)
        {
            // Wait
            while(IS_CONNECTED(g_ulStatus))
            {
    #ifndef SL_PLATFORM_MULTI_THREADED
                  _SlNonOsMainLoopTask();
    #endif
            }
        }
    
        // Enable DHCP client
        lRetVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&ucVal);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Disable scan
        ucConfigOpt = SL_SCAN_POLICY(0);
        lRetVal = sl_WlanPolicySet(SL_POLICY_SCAN , ucConfigOpt, NULL, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Set Tx power level for station mode
        // Number between 0-15, as dB offset from max power - 0 will set max power
        ucPower = 0;
        lRetVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID,
                WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (unsigned char *)&ucPower);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Set PM policy to normal
        lRetVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Unregister mDNS services
        lRetVal = sl_NetAppMDNSUnRegisterService(0, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        lRetVal = sl_Stop(SL_STOP_TIMEOUT);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        InitializeAppVariables();
    
        return lRetVal; // Success
    }
    
    //*****************************************************************************
    //! \brief This function checks the LAN connection by pinging the AP's gateway
    //!
    //! \param  None
    //!
    //! \return 0 on success, negative error-code on error
    //!
    //*****************************************************************************
    static long CheckLanConnection()
    {
        SlPingStartCommand_t pingParams = {0};
        SlPingReport_t pingReport = {0};
    
        long lRetVal = -1;
    
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_PING_DONE);
        g_ulPingPacketsRecv = 0;
    
        // Set the ping parameters
        pingParams.PingIntervalTime = PING_INTERVAL;
        pingParams.PingSize = PING_PKT_SIZE;
        pingParams.PingRequestTimeout = PING_TIMEOUT;
        pingParams.TotalNumberOfAttempts = NO_OF_ATTEMPTS;
        pingParams.Flags = 0;
        pingParams.Ip = g_ulGatewayIP;
    
        // Check for LAN connection
        lRetVal = sl_NetAppPingStart((SlPingStartCommand_t*)&pingParams, SL_AF_INET,
                                (SlPingReport_t*)&pingReport, SimpleLinkPingReport);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Wait for NetApp Event
        while(!IS_PING_DONE(g_ulStatus))
        {
    #ifndef SL_PLATFORM_MULTI_THREADED
            _SlNonOsMainLoopTask();
    #endif
        }
    
        if(0 == g_ulPingPacketsRecv)
        {
            //Problem with LAN connection
            return LAN_CONNECTION_FAILED;
        }
    
        // LAN connection is successful
        return SUCCESS;
    }
    
    
    //*****************************************************************************
    //! \brief This function checks the internet connection by pinging
    //!     the external-host (HOST_NAME)
    //!
    //! \param  None
    //!
    //! \return  0 on success, negative error-code on error
    //!
    //*****************************************************************************
    static long CheckInternetConnection()
    {
        SlPingStartCommand_t pingParams = {0};
        SlPingReport_t pingReport = {0};
    
        unsigned long ulIpAddr = 0;
        long lRetVal = -1;
    
        CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_PING_DONE);
        g_ulPingPacketsRecv = 0;
    
        // Set the ping parameters
        pingParams.PingIntervalTime = PING_INTERVAL;
        pingParams.PingSize = PING_PKT_SIZE;
        pingParams.PingRequestTimeout = PING_TIMEOUT;
        pingParams.TotalNumberOfAttempts = NO_OF_ATTEMPTS;
        pingParams.Flags = 0;
        pingParams.Ip = g_ulGatewayIP;
    
        // Check for Internet connection
        lRetVal = sl_NetAppDnsGetHostByName(HOST_NAME, sizeof(HOST_NAME),
                                                    &ulIpAddr, SL_AF_INET);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Replace the ping address to match HOST_NAME's IP address
        pingParams.Ip = ulIpAddr;
    
        // Try to ping HOST_NAME
        lRetVal = sl_NetAppPingStart((SlPingStartCommand_t*)&pingParams, SL_AF_INET,
                                (SlPingReport_t*)&pingReport, SimpleLinkPingReport);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Wait
        while(!IS_PING_DONE(g_ulStatus))
        {
          // Wait for Ping Event
    #ifndef SL_PLATFORM_MULTI_THREADED
            _SlNonOsMainLoopTask();
    #endif
        }
    
        if (0 == g_ulPingPacketsRecv)
        {
            // Problem with internet connection
            return INTERNET_CONNECTION_FAILED;
        }
    
        // Internet connection is successful
        return SUCCESS;
    }
    
    
    //****************************************************************************
    //
    //! \brief Connecting to a WLAN Accesspoint
    //!
    //!  This function connects to the required AP (SSID_NAME) with Security
    //!  parameters specified in te form of macros at the top of this file
    //!
    //! \param  None
    //!
    //! \return  None
    //!
    //! \warning    If the WLAN connection fails or we don't aquire an IP
    //!            address, It will be stuck in this function forever.
    //
    //****************************************************************************
    static long WlanConnect()
    {
        SlSecParams_t secParams = {0};
        long lRetVal = 0;
    
        secParams.Key = SECURITY_KEY;
        secParams.KeyLen = strlen(SECURITY_KEY);
        secParams.Type = SECURITY_TYPE;
    
        lRetVal = sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0);
        ASSERT_ON_ERROR(__LINE__, lRetVal);
    
        // Wait for WLAN Event
        while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus)))
        {
            // Toggle LEDs to Indicate Connection Progress
            GPIO_IF_LedOff(MCU_IP_ALLOC_IND);
            MAP_UtilsDelay(800000);
            GPIO_IF_LedOn(MCU_IP_ALLOC_IND);
            MAP_UtilsDelay(800000);
        }
    
        return SUCCESS;
    
    }
    
    //****************************************************************************
    //
    //! \brief Start simplelink, connect to the ap and run the ping test
    //!
    //! This function starts the simplelink, connect to the ap and start the ping
    //! test on the default gateway for the ap
    //!
    //! \param[in]  pvParameters - Pointer to the list of parameters that
    //!             can bepassed to the task while creating it
    //!
    //! \return  None
    //
    //****************************************************************************
    void WlanStationMode( void *pvParameters )
    {
        unsigned char macAddressVal[SL_MAC_ADDR_LEN] = {'\0'};
        unsigned char macAddressLen = SL_MAC_ADDR_LEN;
    
        long lRetVal = -1;
        InitializeAppVariables();
    
        //
        // Following function configure the device to default state by cleaning
        // the persistent settings stored in NVMEM (viz. connection profiles &
        // policies, power policy etc)
        //
        // Applications may choose to skip this step if the developer is sure
        // that the device is in its default state at start of applicaton
        //
        // Note that all profiles and persistent settings that were done on the
        // device will be lost
        //
        lRetVal = ConfigureSimpleLinkToDefaultState();
        if(lRetVal < 0)
        {
            if (DEVICE_NOT_IN_STATION_MODE == lRetVal)
            {
                UART_PRINT("Failed to configure the device in its default state\n\r");
            }
    
            LOOP_FOREVER(__LINE__);
        }
    
        UART_PRINT("Device is configured in default state \n\r");
    
        //
        // Assumption is that the device is configured in station mode already
        // and it is in its default state
        //
        lRetVal = sl_Start(0, 0, 0);
        if (lRetVal < 0 || ROLE_STA != lRetVal)
        {
            UART_PRINT("Failed to start the device \n\r");
            LOOP_FOREVER(__LINE__);
        }
    
        UART_PRINT("Device started as STATION \n\r");
    
        sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(unsigned char *)macAddressVal);
        UART_PRINT("Device MAC Address is [%x:%x:%x:%x:%x:%x] \n\r", macAddressVal[0], macAddressVal[1], macAddressVal[2],
                                                                     macAddressVal[3], macAddressVal[4], macAddressVal[5]);
    
        //
        //Connecting to WLAN AP
        //
        lRetVal = WlanConnect();
        if(lRetVal < 0)
        {
            UART_PRINT("Failed to establish connection w/ an AP \n\r");
            LOOP_FOREVER(__LINE__);
        }
    
        UART_PRINT("Connection established w/ AP and IP is aquired \n\r");
        UART_PRINT("Pinging...! \n\r");
    
        //
        // Checking the Lan connection by pinging to AP gateway
        //
        lRetVal = CheckLanConnection();
        if(lRetVal < 0)
        {
            UART_PRINT("Device couldn't ping the gateway \n\r");
            LOOP_FOREVER(__LINE__);
        }
    
        // Turn on GREEN LED when device gets PING response from AP
        GPIO_IF_LedOn(MCU_EXECUTE_SUCCESS_IND);
    
        //
        // Checking the internet connection by pinging to external host
        //
        lRetVal = CheckInternetConnection();
        if(lRetVal < 0)
        {
            UART_PRINT("Device couldn't ping the external host \n\r");
            LOOP_FOREVER(__LINE__);
        }
    
        // Turn on ORAGE LED when device gets PING response from AP
        GPIO_IF_LedOn(MCU_ORANGE_LED_GPIO);
    
        UART_PRINT("Device pinged both the gateway and the external host \n\r");
    
        UART_PRINT("WLAN STATION example executed successfully \n\r");
    
        //
        // power off the network processor
        //
        lRetVal = sl_Stop(SL_STOP_TIMEOUT);
        if(lRetVal < 0)
        {
            UART_PRINT("Device couldn't be stopped \n\r");
            LOOP_FOREVER(__LINE__);
        }
    
        LOOP_FOREVER(__LINE__);
    
    }
    //*****************************************************************************
    //
    //! Application startup display on UART
    //!
    //! \param  none
    //!
    //! \return none
    //!
    //*****************************************************************************
    static void
    DisplayBanner(char * AppName)
    {
    
        UART_PRINT("\n\n\n\r");
        UART_PRINT("\t\t *************************************************\n\r");
        UART_PRINT("\t\t           CC3200 %s Application       \n\r", AppName);
        UART_PRINT("\t\t *************************************************\n\r");
        UART_PRINT("\n\n\n\r");
    }
    //*****************************************************************************
    //
    //! \brief  Board Initialization & Configuration
    //!
    //! \param  None
    //!
    //! \return None
    //
    //*****************************************************************************
    static void
    BoardInit(void)
    {
    // In case of TI-RTOS vector table is initialize by OS itself
    #ifndef USE_TIRTOS
        //
        // Set vector table base
        //
    #if defined(ccs) || defined(gcc)
        MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]);
    #endif
    #if defined(ewarm)
        MAP_IntVTableBaseSet((unsigned long)&__vector_table);
    #endif
    #endif //USE_TIRTOS
    
        //
        // Enable Processor
        //
        MAP_IntMasterEnable();
        MAP_IntEnable(FAULT_SYSTICK);
    
        PRCMCC3200MCUInit();
    }
    
    
    //*****************************************************************************
    //                            MAIN FUNCTION
    //*****************************************************************************
    void main()
    {
        //
        // Board Initialization
        //
        BoardInit();
    
        //
        // configure the GPIO pins for LEDs,UART
        //
        PinMuxConfig();
    
        //
        // Configure the UART
        //
    #ifndef NOTERM
        InitTerm();
    #endif  //NOTERM
    
        //
        // Display Application Banner
        //
        DisplayBanner(APPLICATION_NAME);
    
        //
        // Configure all 3 LEDs
        //
        GPIO_IF_LedConfigure(LED1|LED2|LED3);
    
        // switch off all LEDs
        GPIO_IF_LedOff(MCU_ALL_LED_IND);
    
        //
        // Start the SimpleLink Host
        //
        VStartSimpleLinkSpawnTask(SPAWN_TASK_PRIORITY);
    
        //
        // Start the WlanStationMode task
        //
        osi_TaskCreate( WlanStationMode, (const signed char*)"Wlan Station Task",
                                    OSI_STACK_SIZE, NULL, 1, NULL );
        //
        // Start the task scheduler
        //
        osi_start();
      }
    
    //*****************************************************************************
    //
    // Close the Doxygen group.
    //! @}
    //
    //*****************************************************************************
    

    Attached 'main.c' of 'getting_started_with_wlan_station' example - Please look for 'sl_NetCfgGet'.

    -Praneet

  • Thanks @Praneet

    Your code is giving me MAC address. However I want MAC address in string format..

    I'm not using %x in my code..  How can I do it..?? Can I use any function from string.h??

  • Hi Niral,

    These are the steps I recommend....also you should be able to find a lot of information on how to work with strings in c by performing an Internet search....c is not great for working with strings, but there is a lot of information out there to help you.

    Step 1: Extract each byte from the 6 byte MAC address that is stored in macAddressVal and turn the value into the char representation by using sprintf

    // do this for all 6 values
    char macAddressChar1[2];
    sprintf(macAddressChar1, "%02X", macAddressVal[0]);   

    Step 2: Create a string by joining the values together using strcat

    char macAddress[18];
    // do this for 6 chars you created in step 1 strcat(macAddress, (char *)macAddressChar1); strcat(macAddress, ":"); strcat(macAddress, (char *)macAddressChar2); strcat(macAddress, ":");

    Glenn.

  • @Glenn

    The approach you suggested results into more number of lines. I have shorten it using strdup()..

    for (i = 0 ; i < 6 ; ++i)
    {
        snprintf(stringBuffer, 20, "%02x", macAddressVal[i]);
        strcat(tag, strdup(stringBuffer));
    }

    @Glenn and @Praneet Thanks for your inputs :) :)

  • Hi Niral,

    Thanks for the verification of my answer.

    Not sure you need the snprintf or strdup. The following function works, it includes the : in between the values and saves some memory usage also.

    //*****************************************************************************
    //! getMacAddress
    //!
    //! Returns the MAC Address as a string
    //!
    //****************************************************************************
    char * getMacAddress()
    {
    	int i;
    
    	unsigned char macAddressVal[SL_MAC_ADDR_LEN];
    	unsigned char macAddressLen = SL_MAC_ADDR_LEN;
    
    	sl_NetCfgGet(SL_MAC_ADDRESS_GET,NULL,&macAddressLen,(unsigned char *)macAddressVal);
    
    	char macAddressPart[2];
    	static char macAddressFull[18];
    
    	for (i = 0 ; i < 6 ; i++)
    	{
    		sprintf(macAddressPart, "%02X", macAddressVal[i]);
    		strcat(macAddressFull, (char *)macAddressPart);
    		strcat(macAddressFull, ":");
    	}
    
    	macAddressFull[17] = '\0'; // Replace the the last : with a zero termination
    
    	return macAddressFull;
    }
    
    char * macAddress = getMacAddress(); 

    Glenn.

  • @Glenn

    Thanks for sharing.. It does save memory usage..

  • Niral,

    It is best to avoid using strdup(). You will need to free the memory explicitly after you use this, otherwise your stack will likely overflow after a few calls to this function. If you really need to use something like it, then try out strdupa(). this will automatically free memory once you exit the function....but it is recommend to only use with "short" strings.

    Glenn.