/*******************************************************************************
	wpingme.c	3/15/04
   - This sample program is for use with the CompactFlash WiFi Application Kit.
     The program will initialize the TCP/IP stack.  It also sets the wifi card
     in Infrastructure mode.  Then it will set the Network parameters according
     to tcp_conif.lib.  You will then be albe to ping the board from a WLAN.

*******************************************************************************/
// setup default network parameters
#define TCPCONFIG 3

// replace these with your own 128bit network key
const char key0[13] = { 0xCC,0xA1,0xF2,0x70,0x7A,0xB9,0xDE,0xD1,0xE6,0x92,0xD3,0xEE,0x09 };
const char key1[13] = { 0xCC,0xA1,0xF2,0x70,0x7A,0xB9,0xDE,0xD1,0xE6,0x92,0xD3,0xEE,0x09 };
const char key2[13] = { 0xCC,0xA1,0xF2,0x70,0x7A,0xB9,0xDE,0xD1,0xE6,0x92,0xD3,0xEE,0x09 };
const char key3[13] = { 0xCC,0xA1,0xF2,0x70,0x7A,0xB9,0xDE,0xD1,0xE6,0x92,0xD3,0xEE,0x09 };

// change the ssid to your particular wifi network ssid
#define WIFI_INIT \
 	pd_ioctl(0,WIFI_MODE,"BSS",0);\
 	pd_ioctl(0,WIFI_SSID,"TECH_WIFI",0); \
   pd_ioctl(0,WIFI_WEP_FLAG,"1",0);\
   pd_ioctl(0,WIFI_WEP_USEKEY,"0",0);\
   pd_ioctl(0,WIFI_WEP_KEY0,key0,sizeof(key0));\
   pd_ioctl(0,WIFI_WEP_KEY1,key1,sizeof(key1));\
   pd_ioctl(0,WIFI_WEP_KEY2,key2,sizeof(key2));\
   pd_ioctl(0,WIFI_WEP_KEY3,key3,sizeof(key3));\
   pd_ioctl(0,WIFI_WEP_AUTH,"1",0);



#define DCRTCP_VERBOSE	// uncomment for additional tcp stack debugging info
//#define CF_VERBOSE		// uncomment for additional CF Wifi debugging info
//#define CF_DEBUG

#memmap xmem
#define PKTDRV "cfprism.lib"			// bring in just wifi support
//#define ETH_DRIVER cfprism.lib  	// bring in wi-fi drivers & use PPP (will cause warining)
#use dcrtcp.lib            // bring in tcp stack

void main()
{
	struct wifi_status wstatus;

	sock_init();
   while(ifpending(IF_ETH0)%2)
		tcp_tick(NULL);
   ip_print_ifs();	// show ip address in the stdio window

   while(1)
   {
      tcp_tick(NULL);

      costate
      {
      	waitfor(DelayMs(1000));
         pd_ioctl( 0,WIFI_STATUS,(char *)&wstatus,sizeof(wstatus) );
         printf("status %x quality %d signal %d noise %d rate %d ssid %s\n",
          		  wstatus.status,wstatus.quality,wstatus.signal,
                 wstatus.noise,wstatus.rate,wstatus.ssid);
      }
	}
}