I think there is more to it than that. There is an init_enet.c file with Atheros 4.0.2 patch that somehow needs to be integrated into the existing init_enet.c in bsd for K70 along with user_config.h adjustments. I have not been able to successfully compile. Please help if you can. My last two errors are :
Description Resource Path Location Type
undefined reference to `ENET_initialize_wifi' rtcs_init.c /K70MQXTEST/Sources line 240 C/C++ Problem
undefined reference to `ipcfg_init_device_wifi' rtcs_init.c /K70MQXTEST/Sources line 234 C/C++ Problem
Relevant Files
init_enet.c
/**HEADER********************************************************************
*
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
***************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED 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 FREESCALE OR ITS 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.
*
*END************************************************************************/
#include "main.h"
#include <ipcfg.h>
#include "iwcfg.h"
#if RTCS_PPP
#include <ppp.h>
#if ! RTCSCFG_ENABLE_VIRTUAL_ROUTES
#error This application requires RTCSCFG_ENABLE_VIRTUAL_ROUTES defined non-zero in user_config.h. Please recompile libraries (BSP, RTCS) with this option.
#endif
#if ! RTCSCFG_ENABLE_GATEWAYS
#error This application requires RTCSCFG_ENABLE_GATEWAYS defined non-zero in user_config.h. Please recompile libraries (BSP, RTCS) with this option.
#endif
#warning This application requires PPP device to be defined manually and being different from the default IO channel (BSP_DEFAULT_IO_CHANNEL). See PPP_DEVICE in config.h.
LWSEM_STRUCT ppp_sem;
static void PPP_linkup (pointer lwsem) {_lwsem_post(lwsem);}
extern void PPP_start(void);
char localname[] = "psti";
char localsecret[] = "secret";
char remotename[] = "guest";
char remotesecret[] = "anonymous";
PPP_SECRET lsecret =
{sizeof(localname)-1, sizeof(localsecret)-1, localname, localsecret};
PPP_SECRET lsecrets[] = {
{sizeof(remotename)-1, sizeof(localsecret)-1, remotename, localsecret},
{0, 0, NULL, NULL}};
PPP_SECRET rsecrets[] = {
{sizeof(remotename)-1, sizeof(remotesecret)-1, remotename, remotesecret},
{0, 0, NULL, NULL}};
extern PPP_SECRET_PTR _PPP_PAP_LSECRET;
extern PPP_SECRET_PTR _PPP_PAP_RSECRETS;
extern char_ptr _PPP_CHAP_LNAME;
extern PPP_SECRET_PTR _PPP_CHAP_LSECRETS;
extern PPP_SECRET_PTR _PPP_CHAP_RSECRETS;
/*FUNCTION*------------------------------------------------
*
* Function Name: PPP_start
* Comments :
*
*
*END*-----------------------------------------------------*/
void PPP_start(void)
{
uint_32 error;
_rtcs_if_handle ihandle;
MQX_FILE_PTR pfile;
_iopcb_handle pio;
_ppp_handle phandle;
IPCP_DATA_STRUCT ipcp_data;
_PPP_PAP_RSECRETS = rsecrets; /* Require authentication, allow PAP */
_PPP_PAP_LSECRET = &lsecret; /* Allow peer to request PAP */
_PPP_CHAP_LNAME = localname; /* Needed by CHAP */
_PPP_CHAP_RSECRETS = rsecrets; /* Require authentication, allow CHAP */
_PPP_CHAP_LSECRETS = lsecrets; /* Allow peer to request CHAP */
/* Install a route for a default gateway */
RTCS_gate_add(GATE_ADDR, INADDR_ANY, INADDR_ANY);
pfile = fopen(PPP_DEVICE, NULL);
#ifdef PPP_DEVICE_DUN
_io_dun_install("dun:");
pfile = fopen("dun:", (char_ptr)pfile);
#endif
pio = _iopcb_ppphdlc_init(pfile);
_PPP_ACCM = 0;
error = PPP_initialize(pio, &phandle);
if (error) {
printf("\nPPP initialize: %lx", error);
_task_block();
} /* Endif */
_iopcb_open(pio, PPP_lowerup, PPP_lowerdown, phandle);
error = RTCS_if_add(phandle, RTCS_IF_PPP, &ihandle);
if (error) {
printf("\nIF add failed, error = %lx", error);
_task_block();
} /* Endif */
_lwsem_create(&ppp_sem, 0);
_mem_zero(&ipcp_data, sizeof(ipcp_data));
ipcp_data.IP_UP = PPP_linkup;
ipcp_data.IP_DOWN = NULL;
ipcp_data.IP_PARAM = &ppp_sem;
ipcp_data.ACCEPT_LOCAL_ADDR = FALSE;
ipcp_data.ACCEPT_REMOTE_ADDR = FALSE;
ipcp_data.LOCAL_ADDR = PPP_LOCADDR;
ipcp_data.REMOTE_ADDR = PPP_PEERADDR;
ipcp_data.DEFAULT_NETMASK = TRUE;
ipcp_data.DEFAULT_ROUTE = TRUE;
error = RTCS_if_bind_IPCP(ihandle, &ipcp_data);
if (error) {
printf("\nIF bind failed, error = %lx", error);
_task_block();
} /* Endif */
printf("\nPlease initiate PPP connection. Waiting...");
_lwsem_wait(&ppp_sem);
printf("\nPPP device %s bound to %d.%d.%d.%d", PPP_DEVICE, IPBYTES(ipcp_data.LOCAL_ADDR));
}
#endif /* RTCS_PPP */
static int_32 gWifiConnected = 0;
static _enet_handle handle[BSP_ENET_DEVICE_COUNT];
/*FUNCTION*-------------------------------------------------------------
*
* Function Name : WifiConnected()
* Returned Value : NA
* Comments : Sets an LED to indicate that the wifi is connected
* to the network.
*
*END*-----------------------------------------------------------------*/
static void WifiConnected(int value)
{
gWifiConnected = 1;
printf("Wifi connected!\n");
return;
}
/*FUNCTION*-------------------------------------------------------------
*
* Function Name : SetCallback()
* Returned Value : SHELL_EXIT_SUCCESS if mode set successfully else ERROR CODE
* Comments : Sets the Atheros wifi driver callback function which
* the driver will call when the state of the wifi
* connection changes.
*
*END*-----------------------------------------------------------------*/
static int_32 SetCallback()
{
ATH_IOCTL_PARAM_STRUCT inout_param;
uint_32 error,dev_status;
inout_param.cmd_id = ATH_SET_CONNECT_STATE_CALLBACK;
inout_param.data = (void *)WifiConnected;
inout_param.length = 4;
error = ENET_mediactl(handle[ATHEROS_WIFI_DEFAULT_ENET_DEVICE],ENET_MEDIACTL_IS_INITIALIZED,&dev_status);
if (SHELL_EXIT_SUCCESS != error)
{
return error;
}
if (dev_status == FALSE)
{
return ENET_ERROR;
}
error = ENET_mediactl(handle[ATHEROS_WIFI_DEFAULT_ENET_DEVICE],ENET_MEDIACTL_VENDOR_SPECIFIC,&inout_param);
if (SHELL_EXIT_SUCCESS != error)
{
return error;
}
return SHELL_EXIT_SUCCESS;
}
extern uint_32 ipcfg_init_device_wifi(uint_32, _enet_address);
extern _mqx_uint ENET_initialize_wifi(_mqx_uint, _enet_address, _mqx_uint, _enet_handle _PTR_);
/*FUNCTION*-----------------------------------------------------
*
* Function Name : rtcs_init
* Comments :
* This function installs and initializes RTCS
*
*END*-----------------------------------------------------*/
void rtcs_init()
{
IPCFG_IP_ADDRESS_DATA ip_data;
_enet_address enet_address;
uint_32 error = RTCS_create();
if (error != RTCS_OK)
{
printf("\nRTCS failed to initialize, error = %X", error);
_task_block();
}
_IP_forward = TRUE;
#ifdef BSP_ENET_DEVICE_COUNT
#if (BSP_ENET_DEVICE_COUNT > 0)
/*Following section is relevant only in case there as some enet driver available in BSP (FEC, MACNET, WIFI or other enet driver)*/
/* calcualte unique mac address from IP ADDRES */
ENET_get_mac_address (ENET_DEVICE, ENET_IPADDR, enet_address);
error = ipcfg_init_device (ENET_DEVICE, enet_address);
if (error != RTCS_OK)
{
printf("\nFailed to initialize ethernet device, error = %X", error);
_task_block();
}
if (!HTTP_USE_ONE_SERVER){
ip_data.ip = WIFI_IPADDR;
ip_data.mask = WIFI_IPMASK;
ip_data.gateway = WIFI_GATEWAY;
/* calcualte unique mac address from IP ADDRES */
ENET_get_mac_address(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, WIFI_IPADDR, enet_address);
error = ipcfg_init_device_wifi(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, enet_address);
if (error != RTCS_OK)
{
printf("\nFailed to initialize wifi device, error = %X", error);
_task_block();
}
if((error = ENET_initialize_wifi(1, enet_address, 1, &handle[1])) != ENETERR_INITIALIZED_DEVICE)
{
printf("Error during ENET_initialize device n.%d 0x%08x\n", 1, error);
while(1){}
}
SetCallback();
/* hardcoded values for SSID and security params are used to try to connect. This
* is fine for a demo but not very practicle for a "real world" product. Instead
* one option is to use WPS as shown above. */
iwcfg_set_essid (1,WIFI_SSID);
iwcfg_set_sec_type (1,WIFI_SECURITY);
iwcfg_set_mode (1,WIFI_NW_MODE);
iwcfg_commit(1);
}
#if RTCSCFG_ENABLE_LWDNS
LWDNS_server_ipaddr = ENET_DNS;
ipcfg_add_dns_ip(ENET_DEVICE,LWDNS_server_ipaddr);
#endif /* RTCSCFG_ENABLE_LWDNS */
printf("\nWaiting for ethernet cable plug in ... ");
while(!ipcfg_get_link_active(ENET_DEVICE)) {};
printf("Cable connected\n");
#if RTCS_DHCP
printf("Contacting DHCP server ... ");
error = ipcfg_bind_dhcp_wait(ENET_DEVICE, FALSE, &ip_data);
#else
ip_data.ip = ENET_IPADDR;
ip_data.mask = ENET_IPMASK;
ip_data.gateway = ENET_GATEWAY;
printf("Setting static IP address ... ");
error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);
#endif /* RTCS_DHCP */
if (error != IPCFG_ERROR_OK)
{
printf("\nRTCS failed to bind Ethernet interface with IPv4, error = %X", error);
_task_block();
}
else
{
printf("OK\n");
}
ipcfg_get_ip(ENET_DEVICE, &ip_data);
printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0)));
if (!HTTP_USE_ONE_SERVER){
#if RTCS_DHCP
printf("Contacting DHCP server ... ");
error = ipcfg_bind_dhcp_wait(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, FALSE, &ip_data);
#else
ip_data.ip = WIFI_IPADDR;
ip_data.mask = WIFI_IPMASK;
ip_data.gateway = WIFI_GATEWAY;
printf("Setting static IP address ... ");
error = ipcfg_bind_staticip (ATHEROS_WIFI_DEFAULT_ENET_DEVICE, &ip_data);
#endif /* RTCS_DHCP */
if (error != IPCFG_ERROR_OK)
{
printf("\nRTCS failed to bind Wifi interface with IPv4, error = %X", error);
_task_block();
}
else
{
printf("OK\n");
}
ipcfg_get_ip(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, &ip_data);
printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ATHEROS_WIFI_DEFAULT_ENET_DEVICE,0)));
}
main. h
#ifndef __main_h_
#define __main_h_
#include <mqx.h>
#include <bsp.h>
#include <mfs.h>
#include <shell.h>
#define APPLICATION_HAS_SHELL
#include <rtcs.h>
#ifdef APPLICATION_HAS_SHELL
#include <sh_rtcs.h>
#endif
#include <ipcfg.h>
#include "tfs.h"
#include "enet.h"
#include "enet_wifi.h"
#include "iwcfg.h"
#include "string.h"
#include "atheros_wifi_api.h"
#include "atheros_wifi.h"
//#include "atheros_phy.h"
#define MAIN_TASK 1
#define RAM_DISK_SIZE 0x2000
/* Uncomment following code to use whole external MRAM for ramdisk, if available.
Not applicable when using MRAM target! */
/*
#define RAM_DISK_BASE BSP_EXTERNAL_MRAM_BASE
#define RAM_DISK_SIZE BSP_EXTERNAL_MRAM_SIZE
*/
#define ENET_DEVICE 0
#define ATHEROS_WIFI_DEFAULT_ENET_DEVICE 1
#define RTCS_DHCP 0
#define ENET_IPADDR IPADDR(192,168,1,99)
#define ENET_IPMASK IPADDR(255,255,0,0)
#define ENET_GATEWAY IPADDR(192,168,0,1)
#define ENET_DNS IPADDR(192,168,0,2)
#define WIFI_IPADDR IPADDR(192,168,1,98)
#define WIFI_IPMASK IPADDR(255,255,0,0)
#define WIFI_GATEWAY IPADDR(192,168,0,1)
#define WIFI_SSID "Wireless3"
//Possible Values managed or adhoc
#define WIFI_NW_MODE "managed"
//Possible vales
// 1. "wep"
// 2. "wpa"
// 3. "wpa2"
// 4. "none"
#define WIFI_SECURITY "wpa"
#define WIFI_PASSPHRASE "M3tr01nd2010"
#define RTCS_PPP 0
/* Use this define to tell example if only one server should be used for all interfaces */
#define HTTP_USE_ONE_SERVER 0
#if RTCSCFG_ENABLE_IP6
#if RTCSCFG_ENABLE_IP4
/*
** HTTP_INET_AF is AF_INET+AF_INET for http support IPv4+IPv6.
** HTTP_INET_AF is AF_INET for http support IPv4 only.
** HTTP_INET_AF is AF_INET6 for http support IPv6 only.
*/
#define HTTP_INET_AF (AF_INET | AF_INET6)
#else
#define HTTP_INET_AF AF_INET6
#endif
#else
#define HTTP_INET_AF AF_INET
#endif
//#define HTTP_INET_AF AF_INET
#define HTTP_SCOPE_ID 0 /* For any IF. */
extern void Main_task (uint_32);
void Ram_disk_start(void);
void rtcs_init(void);
/* PPP device must be set manually and
** must be different from the default IO channel (BSP_DEFAULT_IO_CHANNEL)
*/
#define PPP_DEVICE "ittyb:"
/*
** Define PPP_DEVICE_DUN only when using PPP to communicate
** to Win9x Dial-Up Networking over a null-modem
** This is ignored if PPP_DEVICE is not #define'd
*/
#define PPP_DEVICE_DUN 1
/*
** Define the local and remote IP addresses for the PPP link
** These are ignored if PPP_DEVICE is not #define'd
*/
#define PPP_LOCADDR IPADDR(192,168,0,216)
#define PPP_PEERADDR IPADDR(192,168,0,217)
#define GATE_ADDR IPADDR(192,168,0,1)
#endif /* __main_h_ */
main. c
/**HEADER*******************************************************************
*
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
****************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED 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 FREESCALE OR ITS 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.
*
****************************************************************************
*
* Comments:
*
* This file contains main initialization for your application
* and infinite loop
*
*END************************************************************************/
#include "main.h"
#if !defined(RAM_DISK_SIZE)
#error Please specify RAM_DISK_SIZE
#endif
#if defined(APPLICATION_HAS_SHELL) && (!SHELLCFG_USES_RTCS)
#error This application requires SHELLCFG_USES_RTCS defined non-zero in user_config.h. Please recompile libraries with this option if any Ethernet interface is available.
#endif
#if ! SHELLCFG_USES_MFS
#error This application requires SHELLCFG_USES_MFS defined non-zero in user_config.h. Please recompile libraries with this option.
#endif
#define CONTROL_TASK 2
#define SHELL_TASK 3
uint_32 counter = 0;
uint_32 counter2 = 0;
uint_32 counter3 = 0;
uint_32 real_desPSI = 0;
uint_32 real_startPSI = 0;
char boostMode = 0;
const SHELL_COMMAND_STRUCT Shell_commands[] = {
/* MFS commands */
{ "cd", Shell_cd },
{ "copy", Shell_copy },
{ "create", Shell_create },
{ "del", Shell_del },
{ "disect", Shell_disect},
{ "dir", Shell_dir },
{ "format", Shell_format },
{ "mkdir", Shell_mkdir },
{ "pwd", Shell_pwd },
{ "read", Shell_read },
{ "ren", Shell_rename },
{ "rmdir", Shell_rmdir },
{ "type", Shell_type },
{ "write", Shell_write },
/* RTCS commands */
{ "arpadd", Shell_arpadd },
{ "arpdel", Shell_arpdel },
{ "arpdisp", Shell_arpdisp },
{ "gate", Shell_gate },
{ "gethbn", Shell_get_host_by_name },
{ "getrt", Shell_getroute },
{ "ipconfig", Shell_ipconfig },
{ "netstat", Shell_netstat },
#if RTCSCFG_ENABLE_ICMP
{ "ping", Shell_ping },
#endif
{ "telnet", Shell_Telnet_client },
{ "telnetd", Shell_Telnetd },
{ "walkrt", Shell_walkroute },
/* Add your custom shell commands here */
/* { "command_name", Your_function }, */
{ "sh", Shell_sh },
{ "help", Shell_help },
{ "?", Shell_command_list },
{ "exit", Shell_exit },
{ NULL, NULL },
};
const SHELL_COMMAND_STRUCT Telnetd_shell_commands[] = {
/* RTCS commands */
{ "exit", Shell_exit },
{ "gethbn", Shell_get_host_by_name },
{ "getrt", Shell_getroute },
{ "help", Shell_help },
{ "ipconfig", Shell_ipconfig },
{ "netstat", Shell_netstat },
{ "pause", Shell_pause },
#if RTCSCFG_ENABLE_ICMP
{ "ping", Shell_ping },
#endif
{ "telnet", Shell_Telnet_client },
{ "walkrt", Shell_walkroute },
{ "?", Shell_command_list },
{ NULL, NULL }
};
HTTPSRV_AUTH_USER_STRUCT users[] = {
{"developer", "freescale"},
{ NULL, NULL} /* Array terminator */
};
HTTPSRV_AUTH_REALM_STRUCT auth_realms[] = {
{ "Freescale webpage", "rtc.html", HTTPSRV_AUTH_BASIC, users},
{ NULL, NULL, HTTPSRV_AUTH_INVALID, NULL} /* Array terminator */
};
void shell_task(uint_32 data);
void control_task(uint_32 data);
TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task number, Entry point, Stack, Pri, String, Auto? */
{MAIN_TASK, Main_task, 2000, 8, "main", MQX_AUTO_START_TASK},
{CONTROL_TASK, control_task, 2000, 9, "Control_task", 0, 0, 0},
{SHELL_TASK, shell_task, 2000, 9, "Shell_task", 0, 0, 0},
{ 0 }
};
void control_task(uint_32 data){
for (;;){
//counter++;
counter = real_desPSI;
counter2 = real_startPSI;
counter3 = boostMode;
}
}
void shell_task(uint_32 data){
for (;;){
/* Run the shell */
Shell(Shell_commands, NULL);
printf("Shell exited, restarting...\n");
}
}
void Main_task(uint_32 initial_data)
{
int_32 error;
uint_32 server[BSP_ENET_DEVICE_COUNT];
extern const HTTPSRV_CGI_LINK_STRUCT cgi_lnk_tbl[];
extern const TFS_DIR_ENTRY tfs_data[];
HTTPSRV_PARAM_STRUCT params[BSP_ENET_DEVICE_COUNT];
uint_32 ip_addr[BSP_ENET_DEVICE_COUNT];
uint_32 i = 0;
char* indexes[BSP_ENET_DEVICE_COUNT];
uint_8 n_devices = BSP_ENET_DEVICE_COUNT;
#if !HTTP_USE_ONE_SERVER
uint_8 n_servers = BSP_ENET_DEVICE_COUNT;
#else
uint_8 n_servers = 1;
#endif
_int_install_unexpected_isr();
/* Install ramdisk - MFS init */
Ram_disk_start();
/* RTCS init */
rtcs_init();
ip_addr[0] = ENET_IPADDR;
ip_addr[1] = WIFI_IPADDR;
/* Start HTTP server on each interface */
for (i = 0; (i < n_devices) && (n_devices != 0); i++)
{
indexes[i] = (char*) _mem_alloc_zero(sizeof("\\index_x.html"));
if (indexes[i] == NULL)
{
printf("\n Failed to allocate memory.");
_task_block();
}
}
/* Install trivial file system. HTTP server pages are stored there. */
error = _io_tfs_install("tfs:", tfs_data);
/* Start HTTP server on each interface */
for (i = 0; i < n_servers; i++)
{
_mem_zero(¶ms[i], sizeof(HTTPSRV_PARAM_STRUCT));
params[i].af = HTTP_INET_AF; //IPv4, IPv6 or from config.h
#if RTCSCFG_ENABLE_IP6
/* Set interface number here. Zero is any. */
params[i].ipv6_scope_id = HTTP_SCOPE_ID;
#endif
sprintf(indexes[i], "\\index.html", i);
params[i].root_dir = "tfs:";
params[i].index_page = indexes[i];
params[i].auth_table = auth_realms;
printf("Starting http server No.%d on IP", i);
/*
** If there is only one server listen on any IP address
** so address can change in runtime (DHCP etc.).
** Otherwise we will use static IP for server.
*/
if (HTTP_INET_AF & AF_INET)
{
#if RTCSCFG_ENABLE_IP4
if ((i == 0) && (n_servers == 1))
{
params[i].ipv4_address.s_addr = INADDR_ANY;
}
else
{
params[i].ipv4_address.s_addr = ip_addr[i];
}
/* Print active IPv4 address */
printf(" %d.%d.%d.%d", IPBYTES(ip_addr[i]));
#endif
}
if (HTTP_INET_AF & AF_INET6)
{
#if RTCSCFG_ENABLE_IP6
IPCFG6_GET_ADDR_DATA data;
char prn_addr6[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
ipcfg6_get_addr_info_n(0, 0, &data);
if(inet_ntop(AF_INET6, &(data.ip_addr), prn_addr6, sizeof(prn_addr6)))
{
/* Print active IPv6 address */
printf("%s %s", (HTTP_INET_AF & AF_INET) ? " and" : "", prn_addr6);
}
#endif
}
/*
** Maximum default number of available sockets in RTCS is six.
** Maximum of two are used for HTTP server as listening sockets (one for IPv4 and one for IPv6).
** So we take two of sockets and use them for sessions.
*/
params[i].max_ses = 2;
params[i].cgi_lnk_tbl = (HTTPSRV_CGI_LINK_STRUCT*) cgi_lnk_tbl;
/* There are a lot of static data in CGIs so we have to set large enough stack for script handler */
params[i].script_stack = 1700;
server[i] = HTTPSRV_init(¶ms[i]);
printf("...");
if (server[i] == RTCS_ERROR)
{
printf("[FAIL]\n");
}
else
{
printf("[OK]\n");
}
}
/*
indexes[0] = (char*) _mem_alloc_zero(sizeof("\\index_x.html"));
if (indexes[0] == NULL)
{
printf("\n Failed to allocate memory.");
_task_block();
}
*/
/*
_mem_zero(¶ms[0], sizeof(HTTPSRV_PARAM_STRUCT));
params[0].af = HTTP_INET_AF; //IPv4, IPv6 or from config.h
#if RTCSCFG_ENABLE_IP6
// Set interface number here. Zero is any.
params[0].ipv6_scope_id = HTTP_SCOPE_ID;
#endif
sprintf(indexes[0], "\\index.html", 0);
params[0].root_dir = "tfs:";
params[0].index_page = indexes[0];
params[0].auth_table = auth_realms;
printf("Starting http server No.%d on IP", 0);
//
// If there is only one server listen on any IP address
// so address can change in runtime (DHCP etc.).
// Otherwise we will use static IP for server.
if (HTTP_INET_AF & AF_INET)
{
#if RTCSCFG_ENABLE_IP4
if ((i == 0) && (n_servers == 1))
{
params[0].ipv4_address.s_addr = INADDR_ANY;
}
else
{
params[0].ipv4_address.s_addr = ip_addr[0];
}
// Print active IPv4 address
printf(" %d.%d.%d.%d", IPBYTES(ip_addr[0]));
#endif
}
if (HTTP_INET_AF & AF_INET6)
{
#if RTCSCFG_ENABLE_IP6
IPCFG6_GET_ADDR_DATA data;
char prn_addr6[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
ipcfg6_get_addr_info_n(0, 0, &data);
if(inet_ntop(AF_INET6, &(data.ip_addr), prn_addr6, sizeof(prn_addr6)))
{
// Print active IPv6 address
printf("%s %s", (HTTP_INET_AF & AF_INET) ? " and" : "", prn_addr6);
}
#endif
}
//
// Maximum default number of available sockets in RTCS is six.
// Maximum of two are used for HTTP server as listening sockets (one for IPv4 and one for IPv6).
// So we take two of sockets and use them for sessions.
params[0].max_ses = 2;
params[0].cgi_lnk_tbl = (HTTPSRV_CGI_LINK_STRUCT*) cgi_lnk_tbl;
// There are a lot of static data in CGIs so we have to set large enough stack for script handler
params[0].script_stack = 2000;
server[0] = HTTPSRV_init(¶ms[0]);
printf("...");
if (server[0] == RTCS_ERROR)
{
printf("[FAIL]\n");
}
else
{
printf("[OK]\n");
}
*/
/*******************************
*
* START YOUR CODING HERE
*
********************************/
_task_create(0, CONTROL_TASK, 0);
_task_block();
/*
for(;;){
}
*/
}
/* EOF */
rtcs_init.c
/**HEADER********************************************************************
*
* Copyright (c) 2008 Freescale Semiconductor;
* All Rights Reserved
*
* Copyright (c) 1989-2008 ARC International;
* All Rights Reserved
*
***************************************************************************
*
* THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED 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 FREESCALE OR ITS 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.
*
*END************************************************************************/
#include "main.h"
#include <ipcfg.h>
#include "iwcfg.h"
#if RTCS_PPP
#include <ppp.h>
#if ! RTCSCFG_ENABLE_VIRTUAL_ROUTES
#error This application requires RTCSCFG_ENABLE_VIRTUAL_ROUTES defined non-zero in user_config.h. Please recompile libraries (BSP, RTCS) with this option.
#endif
#if ! RTCSCFG_ENABLE_GATEWAYS
#error This application requires RTCSCFG_ENABLE_GATEWAYS defined non-zero in user_config.h. Please recompile libraries (BSP, RTCS) with this option.
#endif
#warning This application requires PPP device to be defined manually and being different from the default IO channel (BSP_DEFAULT_IO_CHANNEL). See PPP_DEVICE in config.h.
LWSEM_STRUCT ppp_sem;
static void PPP_linkup (pointer lwsem) {_lwsem_post(lwsem);}
extern void PPP_start(void);
char localname[] = "psti";
char localsecret[] = "secret";
char remotename[] = "guest";
char remotesecret[] = "anonymous";
PPP_SECRET lsecret =
{sizeof(localname)-1, sizeof(localsecret)-1, localname, localsecret};
PPP_SECRET lsecrets[] = {
{sizeof(remotename)-1, sizeof(localsecret)-1, remotename, localsecret},
{0, 0, NULL, NULL}};
PPP_SECRET rsecrets[] = {
{sizeof(remotename)-1, sizeof(remotesecret)-1, remotename, remotesecret},
{0, 0, NULL, NULL}};
extern PPP_SECRET_PTR _PPP_PAP_LSECRET;
extern PPP_SECRET_PTR _PPP_PAP_RSECRETS;
extern char_ptr _PPP_CHAP_LNAME;
extern PPP_SECRET_PTR _PPP_CHAP_LSECRETS;
extern PPP_SECRET_PTR _PPP_CHAP_RSECRETS;
/*FUNCTION*------------------------------------------------
*
* Function Name: PPP_start
* Comments :
*
*
*END*-----------------------------------------------------*/
void PPP_start(void)
{
uint_32 error;
_rtcs_if_handle ihandle;
MQX_FILE_PTR pfile;
_iopcb_handle pio;
_ppp_handle phandle;
IPCP_DATA_STRUCT ipcp_data;
_PPP_PAP_RSECRETS = rsecrets; /* Require authentication, allow PAP */
_PPP_PAP_LSECRET = &lsecret; /* Allow peer to request PAP */
_PPP_CHAP_LNAME = localname; /* Needed by CHAP */
_PPP_CHAP_RSECRETS = rsecrets; /* Require authentication, allow CHAP */
_PPP_CHAP_LSECRETS = lsecrets; /* Allow peer to request CHAP */
/* Install a route for a default gateway */
RTCS_gate_add(GATE_ADDR, INADDR_ANY, INADDR_ANY);
pfile = fopen(PPP_DEVICE, NULL);
#ifdef PPP_DEVICE_DUN
_io_dun_install("dun:");
pfile = fopen("dun:", (char_ptr)pfile);
#endif
pio = _iopcb_ppphdlc_init(pfile);
_PPP_ACCM = 0;
error = PPP_initialize(pio, &phandle);
if (error) {
printf("\nPPP initialize: %lx", error);
_task_block();
} /* Endif */
_iopcb_open(pio, PPP_lowerup, PPP_lowerdown, phandle);
error = RTCS_if_add(phandle, RTCS_IF_PPP, &ihandle);
if (error) {
printf("\nIF add failed, error = %lx", error);
_task_block();
} /* Endif */
_lwsem_create(&ppp_sem, 0);
_mem_zero(&ipcp_data, sizeof(ipcp_data));
ipcp_data.IP_UP = PPP_linkup;
ipcp_data.IP_DOWN = NULL;
ipcp_data.IP_PARAM = &ppp_sem;
ipcp_data.ACCEPT_LOCAL_ADDR = FALSE;
ipcp_data.ACCEPT_REMOTE_ADDR = FALSE;
ipcp_data.LOCAL_ADDR = PPP_LOCADDR;
ipcp_data.REMOTE_ADDR = PPP_PEERADDR;
ipcp_data.DEFAULT_NETMASK = TRUE;
ipcp_data.DEFAULT_ROUTE = TRUE;
error = RTCS_if_bind_IPCP(ihandle, &ipcp_data);
if (error) {
printf("\nIF bind failed, error = %lx", error);
_task_block();
} /* Endif */
printf("\nPlease initiate PPP connection. Waiting...");
_lwsem_wait(&ppp_sem);
printf("\nPPP device %s bound to %d.%d.%d.%d", PPP_DEVICE, IPBYTES(ipcp_data.LOCAL_ADDR));
}
#endif /* RTCS_PPP */
static int_32 gWifiConnected = 0;
static _enet_handle handle[BSP_ENET_DEVICE_COUNT];
/*FUNCTION*-------------------------------------------------------------
*
* Function Name : WifiConnected()
* Returned Value : NA
* Comments : Sets an LED to indicate that the wifi is connected
* to the network.
*
*END*-----------------------------------------------------------------*/
static void WifiConnected(int value)
{
gWifiConnected = 1;
printf("Wifi connected!\n");
return;
}
/*FUNCTION*-------------------------------------------------------------
*
* Function Name : SetCallback()
* Returned Value : SHELL_EXIT_SUCCESS if mode set successfully else ERROR CODE
* Comments : Sets the Atheros wifi driver callback function which
* the driver will call when the state of the wifi
* connection changes.
*
*END*-----------------------------------------------------------------*/
static int_32 SetCallback()
{
ATH_IOCTL_PARAM_STRUCT inout_param;
uint_32 error,dev_status;
inout_param.cmd_id = ATH_SET_CONNECT_STATE_CALLBACK;
inout_param.data = (void *)WifiConnected;
inout_param.length = 4;
error = ENET_mediactl(handle[ATHEROS_WIFI_DEFAULT_ENET_DEVICE],ENET_MEDIACTL_IS_INITIALIZED,&dev_status);
if (SHELL_EXIT_SUCCESS != error)
{
return error;
}
if (dev_status == FALSE)
{
return ENET_ERROR;
}
error = ENET_mediactl(handle[ATHEROS_WIFI_DEFAULT_ENET_DEVICE],ENET_MEDIACTL_VENDOR_SPECIFIC,&inout_param);
if (SHELL_EXIT_SUCCESS != error)
{
return error;
}
return SHELL_EXIT_SUCCESS;
}
extern uint_32 ipcfg_init_device_wifi(uint_32, _enet_address);
extern _mqx_uint ENET_initialize_wifi(_mqx_uint, _enet_address, _mqx_uint, _enet_handle _PTR_);
/*FUNCTION*-----------------------------------------------------
*
* Function Name : rtcs_init
* Comments :
* This function installs and initializes RTCS
*
*END*-----------------------------------------------------*/
void rtcs_init()
{
IPCFG_IP_ADDRESS_DATA ip_data;
_enet_address enet_address;
uint_32 error = RTCS_create();
if (error != RTCS_OK)
{
printf("\nRTCS failed to initialize, error = %X", error);
_task_block();
}
_IP_forward = TRUE;
#ifdef BSP_ENET_DEVICE_COUNT
#if (BSP_ENET_DEVICE_COUNT > 0)
/*Following section is relevant only in case there as some enet driver available in BSP (FEC, MACNET, WIFI or other enet driver)*/
/* calcualte unique mac address from IP ADDRES */
ENET_get_mac_address (ENET_DEVICE, ENET_IPADDR, enet_address);
error = ipcfg_init_device (ENET_DEVICE, enet_address);
if (error != RTCS_OK)
{
printf("\nFailed to initialize ethernet device, error = %X", error);
_task_block();
}
if (!HTTP_USE_ONE_SERVER){
ip_data.ip = WIFI_IPADDR;
ip_data.mask = WIFI_IPMASK;
ip_data.gateway = WIFI_GATEWAY;
/* calcualte unique mac address from IP ADDRES */
ENET_get_mac_address(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, WIFI_IPADDR, enet_address);
error = ipcfg_init_device_wifi(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, enet_address);
if (error != RTCS_OK)
{
printf("\nFailed to initialize wifi device, error = %X", error);
_task_block();
}
if((error = ENET_initialize_wifi(1, enet_address, 1, &handle[1])) != ENETERR_INITIALIZED_DEVICE)
{
printf("Error during ENET_initialize device n.%d 0x%08x\n", 1, error);
while(1){}
}
SetCallback();
/* hardcoded values for SSID and security params are used to try to connect. This
* is fine for a demo but not very practicle for a "real world" product. Instead
* one option is to use WPS as shown above. */
iwcfg_set_essid (1,WIFI_SSID);
iwcfg_set_sec_type (1,WIFI_SECURITY);
iwcfg_set_mode (1,WIFI_NW_MODE);
iwcfg_commit(1);
}
#if RTCSCFG_ENABLE_LWDNS
LWDNS_server_ipaddr = ENET_DNS;
ipcfg_add_dns_ip(ENET_DEVICE,LWDNS_server_ipaddr);
#endif /* RTCSCFG_ENABLE_LWDNS */
printf("\nWaiting for ethernet cable plug in ... ");
while(!ipcfg_get_link_active(ENET_DEVICE)) {};
printf("Cable connected\n");
#if RTCS_DHCP
printf("Contacting DHCP server ... ");
error = ipcfg_bind_dhcp_wait(ENET_DEVICE, FALSE, &ip_data);
#else
ip_data.ip = ENET_IPADDR;
ip_data.mask = ENET_IPMASK;
ip_data.gateway = ENET_GATEWAY;
printf("Setting static IP address ... ");
error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data);
#endif /* RTCS_DHCP */
if (error != IPCFG_ERROR_OK)
{
printf("\nRTCS failed to bind Ethernet interface with IPv4, error = %X", error);
_task_block();
}
else
{
printf("OK\n");
}
ipcfg_get_ip(ENET_DEVICE, &ip_data);
printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0)));
if (!HTTP_USE_ONE_SERVER){
#if RTCS_DHCP
printf("Contacting DHCP server ... ");
error = ipcfg_bind_dhcp_wait(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, FALSE, &ip_data);
#else
ip_data.ip = WIFI_IPADDR;
ip_data.mask = WIFI_IPMASK;
ip_data.gateway = WIFI_GATEWAY;
printf("Setting static IP address ... ");
error = ipcfg_bind_staticip (ATHEROS_WIFI_DEFAULT_ENET_DEVICE, &ip_data);
#endif /* RTCS_DHCP */
if (error != IPCFG_ERROR_OK)
{
printf("\nRTCS failed to bind Wifi interface with IPv4, error = %X", error);
_task_block();
}
else
{
printf("OK\n");
}
ipcfg_get_ip(ATHEROS_WIFI_DEFAULT_ENET_DEVICE, &ip_data);
printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip));
printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask));
printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway));
printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ATHEROS_WIFI_DEFAULT_ENET_DEVICE,0)));
}
#endif /* BSP_ENET_DEVICE_COUNT > 0 */
#endif /* BSP_ENET_DEVICE_COUNT */
#if RTCS_PPP
PPP_start();
#endif /* RTCS_PPP */
/* TODO: start server(s) in separate tasks */
}
#endif /* BSP_ENET_DEVICE_COUNT > 0 */
#endif /* BSP_ENET_DEVICE_COUNT */
#if RTCS_PPP
PPP_start();
#endif /* RTCS_PPP */
/* TODO: start server(s) in separate tasks */
}