//*****************************************************************************
//
// 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 - TCP Socket
// Application Overview - This particular application illustrates how this
// device can be used as a client or server for TCP
// communication.
// Application Details -
// http://processors.wiki.ti.com/index.php/CC32xx_TCP_Socket_Application
// or
// docs\examples\CC32xx_TCP_Socket_Application.pdf
//
//*****************************************************************************
//****************************************************************************
//
//! \addtogroup tcp_socket
//! @{
//
//****************************************************************************
// Standard includes
#include <stdlib.h>
#include <string.h>
// simplelink includes
#include "simplelink.h"
#include "wlan.h"
// driverlib includes
#include "hw_ints.h"
#include "hw_types.h"
#include "hw_memmap.h"
#include "hw_common_reg.h"
#include "rom.h"
#include "rom_map.h"
#include "interrupt.h"
#include "prcm.h"
#include "uart.h"
#include "utils.h"
// common interface includes
#include "udma_if.h"
#include "common.h"
#ifndef NOTERM
#include "uart_if.h"
#endif
#include "pinmux.h"
#define APPLICATION_NAME "TCP Socket"
#define APPLICATION_VERSION "1.1.1"
#define IP_ADDR 0x0a0a64fe /* 10.10.100.254 */
#define PORT_NUM 8899
#define BUF_SIZE 262
#define TCP_PACKET_COUNT 1000
//Manual Static IP Configuration
#define Net_ipv4 SL_IPV4_VAL(10,10,100,195)
#define Net_ipv4Mask SL_IPV4_VAL(255,255,255,0)
#define Net_ipv4Gateway SL_IPV4_VAL(10,10,100,254)
#define Net_ipv4DnsServer SL_IPV4_VAL(10,10,100,254)
// Application specific status/error codes
typedef enum{
// Choosing -0x7D0 to avoid overlap w/ host-driver's error codes
SOCKET_CREATE_ERROR = -0x7D0,
BIND_ERROR = SOCKET_CREATE_ERROR - 1,
LISTEN_ERROR = BIND_ERROR -1,
SOCKET_OPT_ERROR = LISTEN_ERROR -1,
CONNECT_ERROR = SOCKET_OPT_ERROR -1,
ACCEPT_ERROR = CONNECT_ERROR - 1,
SEND_ERROR = ACCEPT_ERROR -1,
RECV_ERROR = SEND_ERROR -1,
SOCKET_CLOSE_ERROR = RECV_ERROR -1,
DEVICE_NOT_IN_STATION_MODE = SOCKET_CLOSE_ERROR - 1,
STATUS_CODE_MAX = -0xBB8
}e_AppStatusCodes;
//****************************************************************************
// LOCAL FUNCTION PROTOTYPES
//****************************************************************************
int BsdTcpClient(unsigned short usPort);
int BsdTcpServer(unsigned short usPort);
static long WlanConnect();
static void DisplayBanner();
static void BoardInit();
static void InitializeAppVariables();
//*****************************************************************************
// GLOBAL VARIABLES -- Start
//*****************************************************************************
volatile unsigned long g_ulStatus = 0;//SimpleLink Status
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
unsigned long g_ulDestinationIp = IP_ADDR;
unsigned int g_uiPortNum = PORT_NUM;
volatile unsigned long g_ulPacketCount = TCP_PACKET_COUNT;
unsigned char g_ucConnectionStatus = 0;
unsigned char g_ucSimplelinkstarted = 0;
unsigned long g_ulIpAddr = 0;
char g_cBsdBuf[BUF_SIZE];
#if defined(ccs) || defined (gcc)
extern void (* const g_pfnVectors[])(void);
#endif
#if defined(ewarm)
extern uVectorEntry __vector_table;
#endif
//*****************************************************************************
// GLOBAL VARIABLES -- End
//*****************************************************************************
//*****************************************************************************
// 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)
{
if(!pWlanEvent)
{
return;
}
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 'slWlanConnectAsyncResponse_t'-Applications
// can use it if required
//
// slWlanConnectAsyncResponse_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:
{
slWlanConnectAsyncResponse_t* pEventData = NULL;
CLR_STATUS_BIT(g_ulStatus, STATUS_BIT_CONNECTION);
CL