示例#1
0
extern void
WFDisplayScanMgr()
{
    tWFScanResult   bssDesc;
    char ssid[32];

    if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
       return;

    if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))
       return;

    if (!IS_SCAN_STATE_VALID(SCANCXT.scanState))
       return;

    WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc);

    /* Display SSID */
    sprintf(ssid, "%s\r\n", bssDesc.ssid);
    putsUART(ssid);

    if (++SCANCXT.displayIdx == SCANCXT.numScanResults)  {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
#if defined(WF_CONSOLE)
        WFConsoleReleaseConsoleMsg();
#endif
    }

    return;
}
示例#2
0
 void WFDisplayScanMgr(void)
{
    DRV_WIFI_SCAN_RESULT   bssDesc;
    char ssid[32+1];
    char buf[10];
    int i;
    char rssiChan[48];

    if ((SCANCXT.numScanResults == 0)               ||
        (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) ||
        (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))    ||
        (!IS_SCAN_STATE_VALID(SCANCXT.scanState)))
    {
       SCAN_CLEAR_DISPLAY(SCANCXT.scanState); 
       return;
    }

    WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc);

    /* Display SSID */
    for(i=0;i<32;i++) ssid[i] = bssDesc.ssid[i];
    ssid[32] = 0;
    if(bssDesc.ssidLen<32) ssid[bssDesc.ssidLen] = 0;

    sprintf(buf,"%d  ",SCANCXT.displayIdx+1);
    SYS_CONSOLE_MESSAGE(buf);
    SYS_CONSOLE_MESSAGE("SSID:");
    SYS_CONSOLE_MESSAGE(ssid);
    SYS_CONSOLE_MESSAGE("\r\n");

    /* Display SSID  & Channel */
    /* RSSI_MAX : 200, RSSI_MIN : 106 */
    sprintf(rssiChan, "  => RSSI: %u, Channel: %u\r\n", bssDesc.rssi, bssDesc.channel);
    SYS_CONSOLE_MESSAGE(rssiChan);

    #if (WF_DEFAULT_NETWORK_TYPE == DRV_WIFI_NETWORK_TYPE_SOFT_AP) || (DRV_WIFI_DEFAULT_ADHOC_PRESCAN == DRV_WIFI_ENABLED)
        preScanResult[SCANCXT.displayIdx]= bssDesc;    // WF_PRESCAN
        if (SCANCXT.displayIdx == sizeof(preScanResult) / sizeof(preScanResult[0]) - 1) {
            SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
            SCANCXT.displayIdx = 0;
            #if defined(CMD_PARSER)
            WFConsoleReleaseConsoleMsg();
            #endif
        }
    #endif

    if (++SCANCXT.displayIdx == SCANCXT.numScanResults)  
    {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
        #if defined(CMD_PARSER)
        WFConsoleReleaseConsoleMsg();
        #endif
    }
}
示例#3
0
extern void
WFDisplayScanMgr()
{
    tWFScanResult   bssDesc;
    char ssid[32];
	char rssiChan[48];

    if (SCANCXT.numScanResults == 0)
       return;
    if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
       return;

    if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))
       return;

    if (!IS_SCAN_STATE_VALID(SCANCXT.scanState))
       return;

    WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc);

    /* Display SSID */
    sprintf(ssid, "%s\r\n", bssDesc.ssid);
    putsUART(ssid);

	/* Display SSID  & Channel */
    /* RSSI_MAX : 200, RSSI_MIN : 106 */
    sprintf(rssiChan, "  => RSSI: %u, Channel: %u\r\n", bssDesc.rssi, bssDesc.channel);
    putsUART(rssiChan);

    if (++SCANCXT.displayIdx == SCANCXT.numScanResults)  {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
#if defined(WF_CONSOLE)
        WFConsoleReleaseConsoleMsg();
#endif
    }

    return;
}
示例#4
0
int main(void)
#endif
{
    BYTE i;
    static DWORD t = 0;
    static DWORD dwLastIP = 0;
    static UINT8 updateDisplay = 0;

#if defined (EZ_CONFIG_STORE)
    static DWORD ButtonPushStart = 0;
#endif

#if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)
    UINT8 channelList[] = MY_DEFAULT_CHANNEL_LIST_PRESCAN; // WF_PRESCAN
    tWFScanResult bssDesc;
#endif

    // Initialize application specific hardware
    InitializeBoard();

    // Initiates board setup process if button is depressed
    // on startup
    if (BUTTON1_IO == 0u) {
        while (BUTTON1_IO == 0);
        SelfTestMode();
    }

    //#if defined(USE_LCD)



    /*******************************************************************/
    // Initialize the LCD
    /*******************************************************************/

    ConfigureLCD_SPI();

    LCDInit();

    /*******************************************************************/
    // Display Start-up Splash Screen
    /*******************************************************************/
    LCDBacklightON();
    LEDS_ON();
    LCDErase();
    sprintf((char *) LCDText, (char*) "  MiWi - WiFi  ");
    sprintf((char *) &(LCDText[16]), (char*) " Gateway  Demo");
    LCDUpdate();





    /*******************************************************************/
    // Initialize the MiWi Protocol Stack. The only input parameter indicates
    // if previous network configuration should be restored.
    /*******************************************************************/
    MiApp_ProtocolInit(FALSE);

    /*******************************************************************/
    // Set Device Communication Channel
    /*******************************************************************/
    if (MiApp_SetChannel(myChannel) == FALSE) {
        LCDDisplay((char *) "ERROR: Unable to Set Channel..", 0, TRUE);
        while (1);
    }

    /*******************************************************************/
    //  Set the connection mode. The possible connection modes are:
    //      ENABLE_ALL_CONN:    Enable all kinds of connection
    //      ENABLE_PREV_CONN:   Only allow connection already exists in
    //                          connection table
    //      ENABL_ACTIVE_SCAN_RSP:  Allow response to Active scan
    //      DISABLE_ALL_CONN:   Disable all connections.
    /*******************************************************************/
    MiApp_ConnectionMode(ENABLE_ALL_CONN);

    /*******************************************************************/
    // Function MiApp_EstablishConnection try to establish a new
    // connection with peer device.
    // The first parameter is the index to the active scan result,
    //      which is acquired by discovery process (active scan). If
    //      the value of the index is 0xFF, try to establish a
    //      connection with any peer.
    // The second parameter is the mode to establish connection,
    //      either direct or indirect. Direct mode means connection
    //      within the radio range; indirect mode means connection
    //      may or may not in the radio range.
    /*******************************************************************/
    i = MiApp_EstablishConnection(0xFF, CONN_MODE_DIRECT);

    /*******************************************************************/
    // Display current opertion on LCD of demo board, if applicable
    /*******************************************************************/
    if (i != 0xFF) {
        ; // Connected Peer on Channel
    } else {
        /*******************************************************************/
        // If no network can be found and join, we need to start a new
        // network by calling function MiApp_StartConnection
        //
        // The first parameter is the mode of start connection. There are
        // two valid connection modes:
        //   - START_CONN_DIRECT        start the connection on current
        //                              channel
        //   - START_CONN_ENERGY_SCN    perform an energy scan first,
        //                              before starting the connection on
        //                              the channel with least noise
        //   - START_CONN_CS_SCN        perform a carrier sense scan
        //                              first, before starting the
        //                              connection on the channel with
        //                              least carrier sense noise. Not
        //                              supported for current radios
        //
        // The second parameter is the scan duration, which has the same
        //     definition in Energy Scan. 10 is roughly 1 second. 9 is a
        //     half second and 11 is 2 seconds. Maximum scan duration is
        //     14, or roughly 16 seconds.
        //
        // The third parameter is the channel map. Bit 0 of the
        //     double word parameter represents channel 0. For the 2.4GHz
        //     frequency band, all possible channels are channel 11 to
        //     channel 26. As the result, the bit map is 0x07FFF800. Stack
        //     will filter out all invalid channels, so the application
        //     only needs to pay attention to the channels that are not
        //     preferred.
        /*******************************************************************/
        MiApp_StartConnection(START_CONN_DIRECT, 10, 0);
    }

    // Turn OFF LCD after setting up MiWi Connection
    LCDBacklightOFF();

    // Initialize stack-related hardware components that may be
    // required by the UART configuration routines
    TickInit();
#if defined(STACK_USE_MPFS2)
    MPFSInit();
#endif

    // Initialize Stack and application related NV variables into AppConfig.
    InitAppConfig();
    dwLastIP = AppConfig.MyIPAddr.Val;
    // Initialize core stack layers (MAC, ARP, TCP, UDP) and
    // application modules (HTTP, SNMP, etc.)
    StackInit();

#if defined ( EZ_CONFIG_SCAN )
    WFInitScan();
#endif

#if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)
    // WF_PRESCAN: Pre-scan before starting up as SoftAP mode  
    WF_CASetScanType(MY_DEFAULT_SCAN_TYPE);
    WF_CASetChannelList(channelList, sizeof (channelList));

    if (WFStartScan() == WF_SUCCESS) {
        SCAN_SET_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
        //putsUART("main: Prescan WFStartScan() success ................. \r\n");
    }

    // Needed to trigger g_scan_done		
    WFRetrieveScanResult(0, &bssDesc);
#else

#if defined(WF_CS_TRIS)
    WF_Connect();
#endif // defined(WF_CS_TRIS)

#endif // (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)

    // Initialize any application-specific modules or functions/
    // For this demo application, this only includes the
    // UART 2 TCP Bridge
#if defined(STACK_USE_UART2TCP_BRIDGE)
    UART2TCPBridgeInit();
#endif

#if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
    ZeroconfLLInitialize();
#endif

#if defined(STACK_USE_ZEROCONF_MDNS_SD)
    mDNSInitialize(MY_DEFAULT_HOST_NAME);
    mDNSServiceRegister(
            (const char *) AppConfig.NetBIOSName, // base name of the service
            "_http._tcp.local", // type of the service
            80, // TCP or UDP port, at which this service is available
            ((const BYTE *) "path=/index.htm"), // TXT info
            1, // auto rename the service when if needed
            NULL, // no callback function
            NULL // no application context
            );

    mDNSMulticastFilterRegister();
#endif

#if defined(WF_CONSOLE)
    WFConsoleInit();
#endif

    // Now that all items are initialized, begin the co-operative
    // multitasking loop.  This infinite loop will continuously
    // execute all stack-related tasks, as well as your own
    // application's functions.  Custom functions should be added
    // at the end of this loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must be broken
    // down into smaller pieces so that other tasks can have CPU time.

    LEDS_OFF();

    while (1) {

        /*******************************************************************/
        // Check Button Events
        /*******************************************************************/
        if (BUTTON1_IO == 0u) {
            while (BUTTON1_IO == 0);
            LCDErase();
            sprintf((char *) LCDText, (char*) "Erase Room Info?");
            sprintf((char *) &(LCDText[16]), (char*) "SW0:Yes  SW2:No");
            LCDUpdate();

            while (1) {
                if (BUTTON1_IO == 0u) {
                    while (BUTTON1_IO == 0);
                    LCDDisplay((char *) "STATUS: Erasing...", 0, TRUE);
                    EraseRoomInfo();
                    DisplaySSID();
                    break;
                } else if (BUTTON2_IO == 0u) {
                    while (BUTTON2_IO == 0);
                    DisplaySSID();
                    break;
                }


            }
        }

        // Blink LED0 twice per sec when unconfigured, once per sec after config
        if ((TickGet() - t >= TICK_SECOND / (4ul - (CFGCXT.isWifiDoneConfigure * 2ul)))) {
            t = TickGet();
            LED0_INV();
        }

        if(CFGCXT.isWifiNeedToConfigure) updateDisplay = 1;
        

        #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)
                if (g_scan_done) {
                    if (g_prescan_waiting) {
                        SCANCXT.displayIdx = 0;
                        while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) {
                            WFDisplayScanMgr();
                        }


        #if defined(WF_CS_TRIS)
                        WF_Connect();
        #endif
                        DisplaySSID();
                        g_scan_done = 0;
                        g_prescan_waiting = 0;
                    }
                }
        #endif // (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)


        // This task performs normal stack task including checking
        // for incoming packet, type of packet and calling
        // appropriate stack entity to process it.
        StackTask();

        WiFiTask();
        // This tasks invokes each of the core stack application tasks
        StackApplications();

        #if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
                ZeroconfLLProcess();
        #endif

        #if defined(STACK_USE_ZEROCONF_MDNS_SD)
                mDNSProcess();
                // Use this function to exercise service update function
                // HTTPUpdateRecord();
        #endif

        // Process application specific tasks here.
        // For this demo app, this will include the Generic TCP
        // client and servers, and the SNMP, Ping, and SNMP Trap
        // demos.  Following that, we will process any IO from
        // the inputs on the board itself.
        // Any custom modules or processing you need to do should
        // go here.

        #if defined(WF_CONSOLE)
                //WFConsoleProcess();
                //    #if !defined(STACK_USE_EZ_CONFIG)
                //	IperfAppCall();
                //      #endif
                //WFConsoleProcessEpilogue();
        wait_console_input:
        #endif

        #if defined(STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE)
                GenericTCPClient();
        #endif

        #if defined(STACK_USE_GENERIC_TCP_SERVER_EXAMPLE)
                GenericTCPServer();
        #endif

        #if defined(STACK_USE_SMTP_CLIENT)
                SMTPDemo();
        #endif

        #if defined(STACK_USE_ICMP_CLIENT)
                PingDemo();
                //PingConsole();
        #endif

        #if defined(STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED)
                //User should use one of the following SNMP demo
                // This routine demonstrates V1 or V2 trap formats with one variable binding.
                SNMPTrapDemo();

        #if defined(SNMP_STACK_USE_V2_TRAP) || defined(SNMP_V1_V2_TRAP_WITH_SNMPV3)
                //This routine provides V2 format notifications with multiple (3) variable bindings
                //User should modify this routine to send v2 trap format notifications with the required varbinds.
                //SNMPV2TrapDemo();
        #endif
                if (gSendTrapFlag)
                    SNMPSendTrap();
        #endif

        #if defined ( WF_CONSOLE ) && defined ( EZ_CONFIG_SCAN )
                WFDisplayScanMgr();
        #endif

        #if defined(STACK_USE_BERKELEY_API)
                BerkeleyTCPClientDemo();
                BerkeleyTCPServerDemo();
                BerkeleyUDPClientDemo();
        #endif

        if((updateDisplay && CFGCXT.isWifiDoneConfigure) || (dwLastIP != AppConfig.MyIPAddr.Val))
        {
            if(dwLastIP != AppConfig.MyIPAddr.Val)
                dwLastIP = AppConfig.MyIPAddr.Val;
            if(updateDisplay && CFGCXT.isWifiDoneConfigure)
                updateDisplay = 0;
            
            #if defined(STACK_USE_ANNOUNCE)
                AnnounceIP();
            #endif
            #if defined(STACK_USE_ZEROCONF_MDNS_SD)
                mDNSFillHostRecord();
            #endif
            DisplaySSID();


        }

    }
}
示例#5
0
void WFDisplayScanMgr()
{
    tWFScanResult   bssDesc;
    char ssid[WF_MAX_SSID_LENGTH+1];
    char rssiChan[48];
    int    i;
    char    st[80];

    if (SCANCXT.numScanResults == 0) {
       SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
       return;
    }
    if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
       return;

    if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))
       return;

    if (!IS_SCAN_STATE_VALID(SCANCXT.scanState))
       return;

    WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc);
    sprintf(st,"%3d ",SCANCXT.displayIdx);
    putrsUART(st);

    if (bssDesc.bssType == 1)
        sprintf(st,"NetType: Infra.");
    else if (bssDesc.bssType == 2)
        sprintf(st,"NetType: Ad-hoc");
    putrsUART(st);

    sprintf(st,", ESSID:");
    putrsUART(st);

    /* Display SSID */
    for(i=0;i<bssDesc.ssidLen;i++) ssid[i] = bssDesc.ssid[i];
    ssid[bssDesc.ssidLen] = 0;
    putsUART(ssid);
    putrsUART("\r\n");

    /* Display SSID  & Channel */
#ifdef STACK_USE_CERTIFICATE_DEBUG
    sprintf(rssiChan, "\tRSSI: %3u, Channel: %2u", bssDesc.rssi, bssDesc.channel);
        putsUART(rssiChan);
    /* Display BSSID */
    sprintf(rssiChan, ", BSSID: %02x:%02x:%02x:%02x:%02x:%02x",
                 bssDesc.bssid[0],bssDesc.bssid[1],bssDesc.bssid[2],
                 bssDesc.bssid[3],bssDesc.bssid[4],bssDesc.bssid[5]);
    putsUART(rssiChan);
    /* Display Security Mode */
    if((bssDesc.apConfig & 0x10) == 0)    // bit4==0:   open (no security)
    {
        sprintf(rssiChan, ", SecMode: %s\r\n", "Open");
    }
    else    // bit4== 1:    security
    {
        if ((bssDesc.apConfig & 0xc0) == 0xc0) // bit7 ==  1: WPA2, bit6 == 1: WPA
        {
            sprintf(rssiChan, ", SecMode: %s\r\n", "WPA/WPA2");
        }
        else if ((bssDesc.apConfig & 0x80) == 0x80) // bit7 ==  1: WPA2
        {
            sprintf(rssiChan, ", SecMode: %s\r\n", "WPA2");
        }
        else if((bssDesc.apConfig & 0x40) == 0x40)//bit6==1: WPA
        {
            sprintf(rssiChan, ", SecMode: %s\r\n", "WPA");
        }
        else    // bit7==0, bit6==0, WEP
        {
            sprintf(rssiChan, ", SecMode: %s\r\n", "WEP");
        }
    }
    putsUART(rssiChan);
#else
    sprintf(rssiChan, ", RSSI: %u, Channel: %u\r\n", bssDesc.rssi, bssDesc.channel);
        putsUART(rssiChan);
#endif

#if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)
    preScanResult[SCANCXT.displayIdx]= bssDesc;    // WF_PRESCAN
    if (SCANCXT.displayIdx == sizeof(preScanResult) / sizeof(preScanResult[0]) - 1) {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
        #if defined(WF_CONSOLE) & defined(STACK_USE_UART)
        WFConsoleReleaseConsoleMsg();
        #endif
    }
#endif

    if (++SCANCXT.displayIdx == SCANCXT.numScanResults)  {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
#if defined(WF_CONSOLE) & defined(STACK_USE_UART)
        WFConsoleReleaseConsoleMsg();
#endif
    }

    return;
}
示例#6
0
/*******************************************************************************
  Function:
    void do_iwconfig_cmd(void)

  Summary:
    Responds to the user invoking iwconfig command

  Description:
    Responds to the user invoking iwconfig command

  Precondition:
    MACInit must be called first.

  Parameters:
    None.

  Returns:
    None.

  Remarks:
    None.
 *****************************************************************************/
void do_iwconfig_cmd(void)
{
    if (!WF_hibernate.state && !iwconfigSetCb() )
        return;

    // if user only typed in iwconfig with no other parameters
    if (ARGC == 1u)
    {
        if (!WF_hibernate.state)
            iwconfigDisplayStatus();
        else
#if defined(STACK_USE_UART)
            WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode - command failed.", TRUE);
#endif
        return;
    }

    if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "wakeup") == 0) )
    {
        if (!WF_hibernate.wakeup_notice)
        {
            WF_hibernate.wakeup_notice = TRUE;
        }

#if defined(STACK_USE_UART)
        WFConsolePrintRomStr("The Wi-Fi module is awake.", TRUE);
#endif

        return;
    }

    if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "hibernate") == 0) )
    {
        if (!WF_hibernate.state)
        {
            WF_hibernate.state = WF_HB_ENTER_SLEEP;
            WF_hibernate.wakeup_notice = FALSE;
            WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode.", TRUE);
        }
        else
            WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode.", TRUE);
        return;
    }

    if (WF_hibernate.state)
    {
        WFConsolePrintRomStr("The Wi-Fi module is in hibernate mode - command failed.", TRUE);
        return;
    }

    if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "ssid") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetSsid())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "mode") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetMode())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "channel") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetChannel())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "power") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetPower())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "domain") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetDomain())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "rts") == 0) )
    {
        if (!WF_hibernate.state && !iwconfigSetRTS())
            return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "txrate") == 0) )
    {
        // txrate is NOT available. Will always return FALSE
        if (!WF_hibernate.state && !iwconfigSetTxRate())
            return;
    }

#if defined ( EZ_CONFIG_SCAN ) && !defined(__18CXX)
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "scan") == 0))
    {
        if (!WF_hibernate.state)
        {
            // WFInitScan();
            WFConsolePrintRomStr("Scanning...", TRUE);
            if (WFStartScan() == WF_SUCCESS)
            {
                WFConsolePrintRomStr("Scan completed.", TRUE);
            }
            else
            {
                WFConsolePrintRomStr("Scan failed. Already in progress or not allowed", TRUE);
            }
        }
        else
        {
            WFConsolePrintRomStr("In hibernate mode - scan is not allowed.", TRUE);
        }
        return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "scanresults") == 0) )
    {
        if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))
            WFConsolePrintRomStr("Scann in process...please wait or try again later", TRUE);
        else if (SCANCXT.numScanResults > 0)
        {
            SCAN_SET_DISPLAY(SCANCXT.scanState);
            SCANCXT.displayIdx = 0;
            while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
            {
                WFDisplayScanMgr();
            }
        }
        else
            WFConsolePrintRomStr("No scan results to display.", TRUE);

        return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "starttest") == 0))
    {
        test_flag = TRUE;
        test_count = 0;
        return;
    }
    else if ( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "stoptest") == 0))
    {
        test_flag = FALSE;
        return;
    }

#endif /* EZ_CONFIG_SCAN */

    else if( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "connect") == 0))
    {
        iwconfigSetConnect();
        return;
    }
#ifdef	STACK_USE_CERTIFICATE_DEBUG
    else if( (2u <= ARGC) && (strcmppgm2ram((char*)ARGV[1], "macstats") == 0))
    {
        iwconfigGetMacStats();
        return;
    }
#endif
    else
    {
        WFConsolePrintRomStr("Unknown parameter", TRUE);
        return;
    }
}
示例#7
0
//
// Main application entry point.
//
int main(void)
{

#if defined(HOST_CM_TEST)
    DWORD t1 = 0;
    char st[80];
    BOOL host_scan = FALSE;
    UINT16 scan_count = 0;
#endif

    static IPV4_ADDR dwLastIP[sizeof (TCPIP_HOSTS_CONFIGURATION) / sizeof (*TCPIP_HOSTS_CONFIGURATION)];
    int i, nNets;

#if defined(SYS_USERIO_ENABLE)    
    static SYS_TICK startTick = 0;
    int32_t LEDstate=SYS_USERIO_LED_DEASSERTED;
#endif  // defined(SYS_USERIO_ENABLE)

    TCPIP_NET_HANDLE netH;
    const char  *netName=0;
    const char  *netBiosName;

#if defined (TCPIP_STACK_USE_ZEROCONF_MDNS_SD)
    char mDNSServiceName[] = "MyWebServiceNameX ";     // base name of the service Must not exceed 16 bytes long
                                                       // the last digit will be incremented by interface
#endif  // defined (TCPIP_STACK_USE_ZEROCONF_MDNS_SD)

    // perform system initialization
    if(!SYS_Initialize())
    {
        return 0;
    }


    SYS_CONSOLE_MESSAGE("\r\n\n\n ---  TCPIP Demo Starts!  --- \r\n");
    SYS_OUT_MESSAGE("TCPIPStack " TCPIP_STACK_VERSION "  ""                ");

    // Initialize the TCPIP stack
    if (!TCPIP_STACK_Init(TCPIP_HOSTS_CONFIGURATION, sizeof (TCPIP_HOSTS_CONFIGURATION) / sizeof (*TCPIP_HOSTS_CONFIGURATION),
            TCPIP_STACK_MODULE_CONFIG_TBL, sizeof (TCPIP_STACK_MODULE_CONFIG_TBL) / sizeof (*TCPIP_STACK_MODULE_CONFIG_TBL)))
    {
        return 0;
    }

    // Display the names associated with each interface
    // Perform mDNS registration if mDNS is enabled
    nNets = TCPIP_STACK_NetworksNo();
    for(i = 0; i < nNets; i++)
    {
        netH = TCPIP_STACK_IxToNet(i);
        netName = TCPIP_STACK_NetName(netH);
        netBiosName = TCPIP_STACK_NetBIOSName(netH);

#if defined(TCPIP_STACK_USE_NBNS)
        SYS_CONSOLE_PRINT("    Interface %s on host %s - NBNS enabled\r\n", netName, netBiosName);
#else
        SYS_CONSOLE_PRINT("    Interface %s on host %s - NBNS disabled\r\n", netName, netBiosName);
#endif  // defined(TCPIP_STACK_USE_NBNS)

#if defined (TCPIP_STACK_USE_ZEROCONF_MDNS_SD)
        mDNSServiceName[sizeof(mDNSServiceName) - 2] = '1' + i;
        mDNSServiceRegister( netH
            , mDNSServiceName                   // name of the service
            ,"_http._tcp.local"                 // type of the service
            ,80                                 // TCP or UDP port, at which this service is available
            ,((const BYTE *)"path=/index.htm")  // TXT info
            ,1                                  // auto rename the service when if needed
            ,NULL                               // no callback function
            ,NULL);                             // no application context
#endif //TCPIP_STACK_USE_ZEROCONF_MDNS_SD
    }

#if defined (TCPIP_STACK_USE_IPV6)
    TCPIP_ICMPV6_RegisterCallback(ICMPv6Callback);
#endif

#if defined(TCPIP_STACK_USE_ICMP_CLIENT)
    ICMPRegisterCallback(PingProcessIPv4);
#endif


#if defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)
    TCPIP_NET_HANDLE hWiFi = TCPIP_STACK_NetHandle("MRF24W");
    if (hWiFi)
    {
       TCPIP_STACK_RegisterHandler(hWiFi, TCPIP_EV_RX_ALL | TCPIP_EV_TX_ALL | TCPIP_EV_RXTX_ERRORS, StackNotification, 0);
    }
#endif  // defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)

#if defined(WF_UPDATE_FIRMWARE_UART_24G)
    extern bool    WF_FirmwareUpdate_Uart_24G(void);
    WF_FirmwareUpdate_Uart_24G();
#endif

  

    // Now that all items are initialized, begin the co-operative
    // multitasking loop.  This infinite loop will continuously
    // execute all stack-related tasks, as well as your own
    // application's functions.  Custom functions should be added
    // at the end of this loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must be broken
    // down into smaller pieces so that other tasks can have CPU time.
    while (1)
    {
        SYS_Tasks();

       
#if defined(SYS_USERIO_ENABLE)    
        // Blink LED0 (right most one) every second.
        if (SYS_TICK_Get() - startTick >= SYS_TICK_TicksPerSecondGet() / 2ul)
        {
            startTick = SYS_TICK_Get();
            LEDstate ^= SYS_USERIO_LED_ASSERTED;
            SYS_USERIO_SetLED(SYS_USERIO_LED_0, LEDstate);
        }
#endif  // defined(SYS_USERIO_ENABLE)   

        // This task performs normal stack task including checking
        // for incoming packet, type of packet and calling
        // appropriate stack entity to process it.
        TCPIP_STACK_Task();

        // Process application specific tasks here.
        // For this demo app, this will include the Generic TCP
        // client and servers, and the SNMP, Ping, and SNMP Trap
        // demos.  Following that, we will process any IO from
        // the inputs on the board itself.
        // Any custom modules or processing you need to do should
        // go here.
#if defined(TCPIP_STACK_USE_TCP) && defined(APP_USE_FTP_CLIENT_DEMO)
        FTPClient();
#endif        
#if defined(TCPIP_STACK_USE_TCP) && defined(APP_USE_GENERIC_TCP_CLIENT_DEMO)
        GenericTCPClient();
#endif

#if defined(TCPIP_STACK_USE_TCP) && defined(APP_USE_GENERIC_TCP_SERVER_DEMO)
        GenericTCPServer();
#endif

#if defined(TCPIP_STACK_USE_SMTP_CLIENT) && defined(APP_USE_SMTP_CLIENT_DEMO)
        SMTPDemo();
#endif

#if (defined(TCPIP_STACK_USE_ICMP_CLIENT) || defined (TCPIP_STACK_USE_IPV6)) && defined(APP_USE_PING_DEMO)
        // use ping on the default interface
        PingDemoTask();
#endif

#if defined(TCPIP_STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED)

        // User should use one of the following SNMP demo
        // This routine demonstrates V1 or V2 trap formats with one variable binding.

        //SNMPTrapDemo(); //This function sends the both SNMP trap version1 and 2 type of notifications

        #if defined(SNMP_STACK_USE_V2_TRAP) || defined(SNMP_V1_V2_TRAP_WITH_SNMPV3)
        //This routine provides V2 format notifications with multiple (3) variable bindings
        //User should modify this routine to send v2 trap format notifications with the required varbinds.
            SNMPV2TrapDemo(); //This function sends the SNMP trap version 2 type of notifications
        #endif

         /*
         SNMPSendTrap() is used to send trap notification to previously configured ip address if trap notification is enabled.
         There are different trap notification code. The current implementation sends trap for authentication failure (4).
           PreCondition: If application defined event occurs to send the trap. Declare a notification flag and update as the event occurs.
           Uncomment the below function if the application requires.

         if(notification flag is updated by the application as a predefined event occured)
        {
            SNMPSendTrap();
        }

        */

#endif 


#if defined(TCPIP_STACK_USE_BERKELEY_API) && defined(APP_USE_BERKELEY_API_DEMO)
        BerkeleyTCPClientDemo();
        BerkeleyTCPServerDemo();
        BerkeleyUDPClientDemo(0);
#endif

        // If the local IP address has changed (ex: due to DHCP lease change)
        // write the new IP address to the console display, UART, and Announce
        // service
        // We use the default interface
        for (i = 0; i < sizeof (TCPIP_HOSTS_CONFIGURATION) / sizeof (*TCPIP_HOSTS_CONFIGURATION); i++)
        {
            netH = TCPIP_STACK_NetHandle(TCPIP_HOSTS_CONFIGURATION[i].interface);
            if ((uint32_t) dwLastIP[i].Val != TCPIP_STACK_NetAddress(netH))
            {
                dwLastIP[i].Val = TCPIP_STACK_NetAddress(netH);

                SYS_CONSOLE_PRINT("Interface Name is: %s\r\n", TCPIP_HOSTS_CONFIGURATION[i].interface);
                SYS_CONSOLE_MESSAGE("New IP Address is: "); DisplayIPValue(dwLastIP[i]);
                SYS_CONSOLE_MESSAGE("\r\n");
            }
        }

#if defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)
        if (stackNotifyCnt)
        {
            stackNotifyCnt = 0;
            ProcessNotification(stackNotifyHandle);
        }
#endif  // defined(TCPIP_STACK_USE_EVENT_NOTIFICATION)

#if defined(WF_UPDATE_FIRMWARE_TCPCLIENT_24G)
    void WF_FirmwareUpdate_TcpClient_24G(void);
    WF_FirmwareUpdate_TcpClient_24G();
#endif //defined(WF_UPDATE_FIRMWARE_TCPCLIENT_24G)

#if defined(HOST_CM_TEST)
       switch (g_event)
        {
            case WF_EVENT_CONNECTION_PERMANENTLY_LOST:
            case WF_EVENT_CONNECTION_FAILED:
                g_event = 0xff;             // clear current event
                // if host scan is active, it can be forced inactive by connection/re-connection process
                // so just reset host scan state to inactive.
                host_scan = FALSE;          // host scan inactive
                SYS_CONSOLE_MESSAGE("Reconnecting....\r\n");
                WF_Connect();
                break;
            case WF_EVENT_CONNECTION_SUCCESSFUL:
                g_event = 0xff;             // clear current event
                // if host scan is active, it can be forced inactive by connection/re-connection process
                // so just reset host scan state to inactive.
                host_scan = FALSE;          // host scan inactive
                break;
            case WF_EVENT_SCAN_RESULTS_READY:
                g_event = 0xff;             // clear current event
                host_scan = FALSE;          // host scan inactive
                // Scan results are valid - OK to retrieve
                if (SCANCXT.numScanResults > 0)
                {
                    SCAN_SET_DISPLAY(SCANCXT.scanState);
                    SCANCXT.displayIdx = 0;
                    while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
                         WFDisplayScanMgr();
                }
                break;
           case WF_EVENT_CONNECTION_TEMPORARILY_LOST:
                // This event can happened when CM in module is enabled.
                g_event = 0xff;         // clear current event
                // if host scan is active, it can be forced inactive by connection/re-connection process
                // so just reset host scan state to inactive.
                host_scan = FALSE;      // host scan inactive
                break;
            default:
                //sprintf(st,"skip event = %d\r\n",g_event);
                //SYS_CONSOLE_MESSAGE(st);
                break;
        }

       if (g_DhcpSuccessful)
       {

       /* Send and Receive UDP packets */
        if(UDPIsOpened(socket1))
        {
            // UDP TX every 10 msec
            if(SYS_TICK_Get() - timeudp >= SYS_TICK_TicksPerSecondGet() / 100)
            {
                timeudp = SYS_TICK_Get();
                tx_number++;
                LED0_IO ^= 1;
                sprintf(str,"rem=%12lu",tx_number);
                for(cntstr=16;cntstr<999;cntstr++)
                    str[cntstr]=cntstr;
                str[999]=0;
                // Send tx_number (formatted in a string)
                if(UDPIsTxPutReady(socket1,1000)!=0)
                {
                    UDPPutString(socket1,(BYTE *)str);
                    UDPFlush(socket1);
                    SYS_CONSOLE_MESSAGE(".");
                }
            }

            // UDP RX tx_number of remote board
            if(UDPIsGetReady(socket1)!=0)
            {
                LED1_IO ^= 1;
                UDPGetArray(socket1,(BYTE *)str,1000);
                str[16]=0;
                //sprintf((char*)LCDText,"%sloc=%12lu",str,tx_number); // Write on EXP16 LCD local and remote TX number
                //strcpypgm2ram(LCDText,str);
                //LCDUpdate();
                SYS_CONSOLE_MESSAGE("Rx");

            }
        }

        // Do host scan
         if((SYS_TICK_Get() - t1) >= SYS_TICK_TicksPerSecondGet() * 20)
        {
            t1 = SYS_TICK_Get();
            if (!host_scan)             // allow host scan if currently inactive
            {
                sprintf(st,"%d Scanning ..... event = %d\r\n",++scan_count, g_event);
                SYS_CONSOLE_MESSAGE(st);
                host_scan = TRUE;       // host scan active
                WF_Scan(0xff);          // scan on all channels
            }
        }
       } // DHCP status
       
#endif  //HOST_CM_TEST


    }
}
void WDRV_ScanResultsDisplayManager(void)
{
    static bool displayHeader = true;
    uint8_t i;
    uint8_t ssid[32 + 1];

    if ((g_scanStatus.numberOfResults == 0) ||
        (!IS_SCAN_STATE_DISPLAY(g_scanStatus.scanState)) ||
        (IS_SCAN_IN_PROGRESS(g_scanStatus.scanState)) ||
        (!IS_SCAN_STATE_VALID(g_scanStatus.scanState)))
    {
       SCAN_CLEAR_DISPLAY(g_scanStatus.scanState);
       return;
    }

    if (displayHeader)
    {
        g_scanStatus.displayIdx = 0;
        SYS_CONSOLE_MESSAGE((const char *)"\nWi-Fi Scan Results:\r\n\n");
        if (g_scanStatus.numberOfResults == 0)
        {
            /* No AP found, re-initialize the scan context state. Scan is not allowed in Soft AP mode.
             * However, g_scanStatus.numberOfResults needs to be preserved for webpage using.
             */
            SYS_CONSOLE_MESSAGE((const char *)"No AP found\r\n ");
            SCAN_CLEAR_DISPLAY(g_scanStatus.scanState);
            if (WDRV_CONFIG_PARAMS(networkType) == WDRV_NETWORK_TYPE_SOFT_AP) {
                SCAN_CLEAR_VALID(g_scanStatus.scanState);
                return;
            } else {
                return;
            }
        }
        else
        {
            SYS_CONSOLE_MESSAGE((const char *)"    SSID                              RSSI  Channel\r\n");
            SYS_CONSOLE_MESSAGE((const char *)"    --------------------------------  ----  -------\r\n");
            displayHeader = false;
        }
    }

    // If the g_scanResults[] buffer is full, don't try to store more scan results to it.
    if (g_scanStatus.displayIdx > sizeof(g_scanResults) / sizeof(g_scanResults[0]) - 1)
    {
        SCAN_CLEAR_DISPLAY(g_scanStatus.scanState);
        g_scanStatus.displayIdx = 0;
        displayHeader = true;
        return;
    }
    WDRV_EXT_ScanResultGet(g_scanStatus.displayIdx, &(g_scanResults[g_scanStatus.displayIdx]));

    /* Display SSID */
    memset(ssid, ' ', sizeof(ssid));
    for (i = 0; i < g_scanResults[g_scanStatus.displayIdx].ssidLen; ++i)
    {
        if (!isprint(g_scanResults[g_scanStatus.displayIdx].ssid[i]))
            ssid[i] = '*';
        else
            ssid[i] = g_scanResults[g_scanStatus.displayIdx].ssid[i];
    }
    ssid[32] = 0;

    /* RSSI_MAX : 128, RSSI_MIN : 43 */
    SYS_CONSOLE_PRINT(" %2d)%s  %2u    %u\r\n",
            g_scanStatus.displayIdx + 1,
            ssid,
            g_scanResults[g_scanStatus.displayIdx].rssi,
            g_scanResults[g_scanStatus.displayIdx].channel);

    // If all the scan results have been displayed and stored, clear status and return.
    if (++g_scanStatus.displayIdx >= g_scanStatus.numberOfResults)
    {
        SCAN_CLEAR_DISPLAY(g_scanStatus.scanState);
        g_scanStatus.displayIdx = 0;
        displayHeader = true;
    }
}
示例#9
0
int main(void)
#endif
{
    static DWORD t = 0;
    static DWORD dwLastIP = 0;

    #if defined (EZ_CONFIG_STORE)
    static DWORD ButtonPushStart = 0;
    #endif

    #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)
    UINT8            channelList[] = MY_DEFAULT_CHANNEL_LIST_PRESCAN;  // WF_PRESCAN
    tWFScanResult     bssDesc;
    #endif

    // Initialize application specific hardware
    InitializeBoard();

    #if defined(USE_LCD)
    // Initialize and display the stack version on the LCD
    LCDInit();
    DelayMs(100);
    strcpypgm2ram((char*)LCDText, "TCPStack " TCPIP_STACK_VERSION "  "
        "                ");
    LCDUpdate();
    #endif

    // Initialize stack-related hardware components that may be
    // required by the UART configuration routines
    TickInit();
    #if defined(STACK_USE_MPFS2)
    MPFSInit();
    #endif

    // Initialize Stack and application related NV variables into AppConfig.
    InitAppConfig();

    // Initiates board setup process if button is depressed 
    // on startup
    if(BUTTON0_IO == 0u)
    {
        #if defined(EEPROM_CS_TRIS) || defined(SPIFLASH_CS_TRIS)
        // Invalidate the EEPROM contents if BUTTON0 is held down for more than 4 seconds
        DWORD StartTime = TickGet();
        LED_PUT(0x00);

        while(BUTTON0_IO == 0u)
        {
            if(TickGet() - StartTime > 4*TICK_SECOND)
            {
                #if defined(EEPROM_CS_TRIS)
                XEEBeginWrite(0x0000);
                XEEWrite(0xFF);
                XEEWrite(0xFF);
                XEEEndWrite();
                #elif defined(SPIFLASH_CS_TRIS)
                SPIFlashBeginWrite(0x0000);
                SPIFlashWrite(0xFF);
                SPIFlashWrite(0xFF);
                #endif

                #if defined(STACK_USE_UART)
                putrsUART("\r\n\r\nBUTTON0 held for more than 4 seconds.  Default settings restored.\r\n\r\n");
                #endif

                LED_PUT(0x0F);
                while((LONG)(TickGet() - StartTime) <= (LONG)(9*TICK_SECOND/2));
                LED_PUT(0x00);
                while(BUTTON0_IO == 0u);
                Reset();
                break;
            }
        }
        #endif

        #if defined(STACK_USE_UART)
        DoUARTConfig();
        #endif
    }

    // Initialize core stack layers (MAC, ARP, TCP, UDP) and
    // application modules (HTTP, SNMP, etc.)
    StackInit();

    #if defined ( EZ_CONFIG_SCAN )
    WFInitScan();
    #endif

    #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)
    // WF_PRESCAN: Pre-scan before starting up as SoftAP mode  
    WF_CASetScanType(MY_DEFAULT_SCAN_TYPE);
    WF_CASetChannelList(channelList, sizeof(channelList));

    if (WFStartScan() == WF_SUCCESS)
    {
        SCAN_SET_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
        //putsUART("main: Prescan WFStartScan() success ................. \r\n");
    }

    // Needed to trigger g_scan_done
    WFRetrieveScanResult(0, &bssDesc);
    #else

    #if defined(WF_CS_TRIS)
    WF_Connect();
    #endif // defined(WF_CS_TRIS)

    #endif // (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)

    // Initialize any application-specific modules or functions/
    // For this demo application, this only includes the
    // UART 2 TCP Bridge
    #if defined(STACK_USE_UART2TCP_BRIDGE)
    UART2TCPBridgeInit();
    #endif

    #if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
    ZeroconfLLInitialize();
    #endif

    #if defined(STACK_USE_ZEROCONF_MDNS_SD)
    mDNSInitialize(MY_DEFAULT_HOST_NAME);
	#if defined(STACK_USE_TCP_MOBILE_APP_SERVER)
		mDNSServiceRegister(
        	(const char *) "HomeControlServer",    // base name of the service
        	"_home-control._tcp.local",                // type of the service
        	27561,                                // TCP or UDP port, at which this service is available
        	((const BYTE *)"control home devices"),    // TXT info
        	1,                                    // auto rename the service when if needed
        	NULL,                                // no callback function
        	NULL                                // no application context
        	);
	#else	/* !defined(STACK_USE_TCP_MOBILE_APP_SERVER) */
    	mDNSServiceRegister(
        	(const char *) "DemoWebServer",    // base name of the service
        	"_http._tcp.local",                // type of the service
        	80,                                // TCP or UDP port, at which this service is available
        	((const BYTE *)"path=/index.htm"),    // TXT info
        	1,                                    // auto rename the service when if needed
        	NULL,                                // no callback function
        	NULL                                // no application context
        	);
	#endif	/* defined(STACK_USE_TCP_MOBILE_APP_SERVER) */
    mDNSMulticastFilterRegister();
    #endif

    #if defined(WF_CONSOLE)
    WFConsoleInit();
    #endif

    // Now that all items are initialized, begin the co-operative
    // multitasking loop.  This infinite loop will continuously
    // execute all stack-related tasks, as well as your own
    // application's functions.  Custom functions should be added
    // at the end of this loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must be broken
    // down into smaller pieces so that other tasks can have CPU time.
    while(1)
    {
        #if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)    
        if (g_scan_done) {
           if (g_prescan_waiting) {
               putrsUART((ROM char*)"\n SoftAP prescan results ........ \r\n\n");
               SCANCXT.displayIdx = 0;
               while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) {
                   WFDisplayScanMgr();
               }
               putrsUART((ROM char*)"\r\n ");

               #if defined(WF_CS_TRIS)
               WF_Connect();
               #endif
               g_scan_done = 0;
               g_prescan_waiting = 0;
           }
        }
        #endif // (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP)   

        #if defined(WF_PRE_SCAN_IN_ADHOC)
        if(g_prescan_adhoc_done)
        {
            WFGetScanResults();
            g_prescan_adhoc_done = 0;
        }
        #endif

        #if defined (EZ_CONFIG_STORE)
        // Hold button3 for 4 seconds to reset to defaults.
        if (BUTTON3_IO == 0u) {  // Button is pressed
            if (ButtonPushStart == 0)  //Just pressed
                ButtonPushStart = TickGet();
            else
                if(TickGet() - ButtonPushStart > 4*TICK_SECOND)
                    RestoreWifiConfig();
        } 
        else 
        {
            ButtonPushStart = 0; //Button release reset the clock
        } 

        if (AppConfig.saveSecurityInfo)
        {
            // set true by WF_ProcessEvent after connecting to a new network
            // get the security info, and if required, push the PSK to EEPROM
            if ((AppConfig.SecurityMode == WF_SECURITY_WPA_WITH_PASS_PHRASE) ||
                (AppConfig.SecurityMode == WF_SECURITY_WPA2_WITH_PASS_PHRASE) ||
                (AppConfig.SecurityMode == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE))
            {
                // only need to save when doing passphrase
                tWFCPElements profile;
                UINT8 connState;
                UINT8 connID;
                WF_CMGetConnectionState(&connState, &connID);
                WF_CPGetElements(connID, &profile);
                
                memcpy((char*)AppConfig.SecurityKey, (char*)profile.securityKey, 32);
                AppConfig.SecurityMode--; // the calc psk is exactly one below for each passphrase option
                AppConfig.SecurityKeyLength = 32;                

                SaveAppConfig(&AppConfig);
            }
            
            AppConfig.saveSecurityInfo = FALSE;
        }
        #endif // EZ_CONFIG_STORE

        #if defined (STACK_USE_EZ_CONFIG)
        // Blink LED0 twice per sec when unconfigured, once per sec after config
        if((TickGet() - t >= TICK_SECOND/(4ul - (CFGCXT.isWifiDoneConfigure*2ul))))
        #else
        // Blink LED0 (right most one) every second.
        if(TickGet() - t >= TICK_SECOND/2ul)
        #endif // STACK_USE_EZ_CONFIG
        {
            t = TickGet();
            LED0_IO ^= 1;
        }

        // This task performs normal stack task including checking
        // for incoming packet, type of packet and calling
        // appropriate stack entity to process it.
        StackTask();

        // This tasks invokes each of the core stack application tasks
        StackApplications();

        #if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
        ZeroconfLLProcess();
        #endif

        #if defined(STACK_USE_ZEROCONF_MDNS_SD)
        mDNSProcess();
        // Use this function to exercise service update function
        // HTTPUpdateRecord();
        #endif

        // Process application specific tasks here.
        // For this demo app, this will include the Generic TCP
        // client and servers, and the SNMP, Ping, and SNMP Trap
        // demos.  Following that, we will process any IO from
        // the inputs on the board itself.
        // Any custom modules or processing you need to do should
        // go here.

        #if defined(WF_CONSOLE)
        WFConsoleProcess();
        WFConsoleProcessEpilogue();
        #endif

        #if defined(STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE)
        GenericTCPClient();
        #endif

        #if defined(STACK_USE_GENERIC_TCP_SERVER_EXAMPLE)
        GenericTCPServer();
        #endif

		#if defined(STACK_USE_TCP_MOBILE_APP_SERVER)
		MobileTCPServer();
		#endif
		
        #if defined(STACK_USE_SMTP_CLIENT)
        SMTPDemo();
        #endif

        #if defined(STACK_USE_ICMP_CLIENT)
        PingDemo();
        PingConsole();
        #endif

        #if defined(STACK_USE_SNMP_SERVER) && !defined(SNMP_TRAP_DISABLED)
        //User should use one of the following SNMP demo
        // This routine demonstrates V1 or V2 trap formats with one variable binding.
        SNMPTrapDemo();

        #if defined(SNMP_STACK_USE_V2_TRAP) || defined(SNMP_V1_V2_TRAP_WITH_SNMPV3)
        //This routine provides V2 format notifications with multiple (3) variable bindings
        //User should modify this routine to send v2 trap format notifications with the required varbinds.
        //SNMPV2TrapDemo();
        #endif
        if(gSendTrapFlag)
            SNMPSendTrap();
        #endif

        #if defined(STACK_USE_BERKELEY_API)
        BerkeleyTCPClientDemo();
        BerkeleyTCPServerDemo();
        BerkeleyUDPClientDemo();
        #endif


        // If the local IP address has changed (ex: due to DHCP lease change)
        // write the new IP address to the LCD display, UART, and Announce 
        // service
        if(dwLastIP != AppConfig.MyIPAddr.Val)
        {
            dwLastIP = AppConfig.MyIPAddr.Val;

            #if defined(STACK_USE_UART)
                putrsUART((ROM char*)"\r\nNew IP Address: ");
            #endif

            DisplayIPValue(AppConfig.MyIPAddr);

            #if defined(STACK_USE_UART)
                putrsUART((ROM char*)"\r\n");
            #endif


            #if defined(STACK_USE_ANNOUNCE)
                AnnounceIP();
            #endif

            #if defined(STACK_USE_ZEROCONF_MDNS_SD)
                mDNSFillHostRecord();
            #endif
        }
    }
}
示例#10
0
// ************************************************************
// Main application entry point.
// ************************************************************
int main(void)
{
    static DWORD t = 0;	
    static DWORD dwLastIP = 0;
#if defined (EZ_CONFIG_STORE)
    static DWORD ButtonPushStart = 0;
#endif
    UINT8         channelList[] = MY_DEFAULT_CHANNEL_LIST_PRESCAN;  // WF_PRESCAN
    tWFScanResult bssDesc;
#if 0	
    INT8 TxPower;   // Needed to change MRF24WG transmit power. 
#endif

    // Initialize application specific hardware
    InitializeBoard();

    // Initialize TCP/IP stack timer
    TickInit();                        //  Timer 3 interrupt for refreshing motor status inside here
    demo_TickInit();

    #if defined(STACK_USE_MPFS2)
    // Initialize the MPFS File System
	// Generate a WifiGDemoMPFSImg.c file using the MPFS utility (refer to Convert WebPages to MPFS.bat)
	// that gets compiled into source code and programmed into the flash of the uP.
    MPFSInit();
    #endif
	
    // Initialize Stack and application related NV variables into AppConfig.
    InitAppConfig();

    // Initialize core stack layers (MAC, ARP, TCP, UDP) and
    // application modules (HTTP, SNMP, etc.)
    StackInit();

    Exosite_Init("microchip","dv102412",IF_WIFI, 0);

#if 0	
    // Below is used to change MRF24WG transmit power. 
    // This has been verified to be functional (Jan 2013) 
    if (AppConfig.networkType == WF_SOFT_AP)
    {
        WF_TxPowerGetMax(&TxPower);                       
        WF_TxPowerSetMax(TxPower);       
    }
#endif

    // Run Self Test if SW0 pressed on startup
    if(SW0_IO == 1)
        SelfTest();

    #ifdef STACK_USE_TELNET_SERVER
        // Initialize Telnet and
        // Put Remote client in Remote Character Echo Mode
        TelnetInit();
        putc(0xff, stdout);     // IAC = Interpret as Command
        putc(0xfe, stdout);     // Type of Operation = DONT
        putc(0x22, stdout);     // Option = linemode
        putc(0xff, stdout);     // IAC = Interpret as Command
        putc(0xfb, stdout);     // Type of Operation = DO
        putc(0x01, stdout);     // Option = echo
    #endif


    #if defined ( EZ_CONFIG_SCAN )
    // Initialize WiFi Scan State Machine NV variables
    WFInitScan();
    #endif
	
    // WF_PRESCAN: Pre-scan before starting up as SoftAP mode  
    WF_CASetScanType(MY_DEFAULT_SCAN_TYPE);
    WF_CASetChannelList(channelList, sizeof(channelList));
		
    if (WFStartScan() == WF_SUCCESS) {
       SCAN_SET_DISPLAY(SCANCXT.scanState);
       SCANCXT.displayIdx = 0;
    }
	
    // Needed to trigger g_scan_done		
    WFRetrieveScanResult(0, &bssDesc);		
  	
    #if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
    // Initialize Zeroconf Link-Local state-machine, regardless of network type.
    ZeroconfLLInitialize();
    #endif
	
    #if defined(STACK_USE_ZEROCONF_MDNS_SD)
    // Initialize DNS Host-Name from TCPIPConfig.h, regardless of network type.
    mDNSInitialize(MY_DEFAULT_HOST_NAME);
    mDNSServiceRegister(
            // (const char *) AppConfig.NetBIOSName,        // base name of the service. Ensure uniformity with CheckHibernate().
            (const char *) "DemoWebServer",          // base name of the service. Ensure uniformity with CheckHibernate().
            "_http._tcp.local",                      // type of the service
            80,	                                     // TCP or UDP port, at which this service is available
            ((const BYTE *)"path=/index.htm"),       // TXT info
            1,                                       // auto rename the service when if needed
            NULL,                                    // no callback function
            NULL                                     // no application context
            );
    mDNSMulticastFilterRegister();
    #endif
	
    #if defined(WF_CONSOLE)
    // Initialize the WiFi Console App
    WFConsoleInit();
    #endif

    // Now that all items are initialized, begin the co-operative
    // multitasking loop.  This infinite loop will continuously
    // execute all stack-related tasks, as well as your own
    // application's functions.  Custom functions should be added
    // at the end of this loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must be broken
    // down into smaller pieces so that other tasks can have CPU time.
   #ifndef PERIOD
#define PERIOD  3120        //  set 3120 for get to timer interrupt every 20ms, 40MHz PBUS, div by 256
#endif
    OpenTimer3(T3_ON | T3_SOURCE_INT | T3_PS_1_256, PERIOD);
    while(1)
    {
         if (AppConfig.networkType == WF_SOFT_AP) {
            if (g_scan_done) {
                if (g_prescan_waiting) {
                     SCANCXT.displayIdx = 0;
                     while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) {
                         WFDisplayScanMgr();
                     }
				
                     #if defined(WF_CS_TRIS)
                     WF_Connect();
                     #endif
                     g_scan_done = 0;
                     g_prescan_waiting = 0;
                }
            }
         }

        #if defined (EZ_CONFIG_STORE)
        // Hold SW0 for 4 seconds to reset to defaults.
        if (SW0_IO == 1u) {  // Button is pressed
            button_state = 1;
            if (ButtonPushStart == 0)  //Just pressed
                ButtonPushStart = TickGet();
            else
                if(TickGet() - ButtonPushStart > 4*TICK_SECOND)
                    RestoreWifiConfig();
        } 
        else 
        {
            ButtonPushStart = 0; //Button release reset the clock
        }
		
        if (AppConfig.saveSecurityInfo)
        {
            // set true by WF_ProcessEvent after connecting to a new network
            // get the security info, and if required, push the PSK to EEPROM
            if ((AppConfig.SecurityMode == WF_SECURITY_WPA_WITH_PASS_PHRASE) ||
                (AppConfig.SecurityMode == WF_SECURITY_WPA2_WITH_PASS_PHRASE) ||
                (AppConfig.SecurityMode == WF_SECURITY_WPA_AUTO_WITH_PASS_PHRASE))
            {
                // only need to save when doing passphrase
                tWFCPElements profile;
                UINT8 connState;
                UINT8 connID;
                WF_CMGetConnectionState(&connState, &connID);
                WF_CPGetElements(connID, &profile);
                
                memcpy((char*)AppConfig.SecurityKey, (char*)profile.securityKey, 32);
                AppConfig.SecurityMode--; // the calc psk is exactly one below for each passphrase option
                AppConfig.SecurityKeyLength = 32;                

                SaveAppConfig(&AppConfig);
            }
            
            AppConfig.saveSecurityInfo = FALSE;
        }
        #endif // EZ_CONFIG_STORE
		
        // Blink LED0 twice per sec when unconfigured, once per sec after config
        if((TickGet() - t >= TICK_SECOND/(4ul - (CFGCXT.isWifiDoneConfigure*3ul))))
        {
            t = TickGet();
            LED0_INV();
        }

        // This task performs normal stack task including checking
        // for incoming packet, type of packet and calling
        // appropriate stack entity to process it.
        StackTask();

        // This task invokes each of the core stack application tasks
        if (cloud_mode == 0)
          StackApplications();

        // Enable WF_USE_POWER_SAVE_FUNCTIONS 
        WiFiTask();

        #if defined(STACK_USE_ZEROCONF_LINK_LOCAL)
        ZeroconfLLProcess();
        #endif

        #if defined(STACK_USE_ZEROCONF_MDNS_SD)
        mDNSProcess();
        #endif

        Exosite_Demo();
        // Process application specific tasks here.
        // Any custom modules or processing you need to do should
        // go here.
        #if defined(WF_CONSOLE)
		WFConsoleProcess();
		WFConsoleProcessEpilogue();
		#endif

		// If the local IP address has changed (ex: due to DHCP lease change)
		// write the new IP address to the LCD display, UART, and Announce 
		// service
		if(dwLastIP != AppConfig.MyIPAddr.Val) 
		{
			dwLastIP = AppConfig.MyIPAddr.Val;	
			DisplayIPValue(AppConfig.MyIPAddr);			
		
			#if defined(STACK_USE_ANNOUNCE)
			AnnounceIP();
	 		#endif
		
			#if defined(STACK_USE_ZEROCONF_MDNS_SD)
			mDNSFillHostRecord();
	 		#endif
		}

    }
}
void WFDisplayScanMgr(void)
{
    DRV_WIFI_SCAN_RESULT bssDesc;
    char ssid[32 + 1];
    int i;

    if ((SCANCXT.numScanResults == 0)               ||
            (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) ||
            (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))    ||
            (!IS_SCAN_STATE_VALID(SCANCXT.scanState)))
    {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        return;
    }

    WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc);

    memset(ssid, ' ', sizeof(ssid));

    /* Display SSID */
    for (i = 0; i < bssDesc.ssidLen; i++)
    {
        if (!isprint(bssDesc.ssid[i]))
        {
            ssid[i] = '*';
        }
        else
        {
            ssid[i] = bssDesc.ssid[i];
        }
    }

    ssid[32] = 0;

    /* Display Index & SSID */
    //SYS_CONSOLE_PRINT("%2d)  ",SCANCXT.displayIdx + 1);
    //SYS_CONSOLE_PRINT("%s", ssid);

    /* Display RSSI & Channel */
    /* RSSI_MAX : 128, RSSI_MIN : 43 */
    //SYS_CONSOLE_PRINT(" %2u    %u\r\n", bssDesc.rssi, bssDesc.channel);

    SYS_CONSOLE_PRINT(" %2d) %s %2u    %u\r\n", SCANCXT.displayIdx + 1, ssid, bssDesc.rssi, bssDesc.channel);

    if (p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
    {
        preScanResult[SCANCXT.displayIdx] = bssDesc; // WF_PRESCAN
        if (SCANCXT.displayIdx == sizeof(preScanResult) / sizeof(preScanResult[0]) - 1)
        {
            /* Prescan is finished, re-initialize the scan context state. Scan is not allowed in Soft AP mode.
             * However, SCANCXT.numScanResults needs to be preserved for webpage using.
             */
            SCAN_CLEAR_VALID(SCANCXT.scanState);
            SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
            SCANCXT.displayIdx = 0;
        }
    }
    else
    {
#if (DRV_WIFI_DEFAULT_ADHOC_PRESCAN == DRV_WIFI_ENABLED)
        preScanResult[SCANCXT.displayIdx] = bssDesc; // WF_PRESCAN
        if (SCANCXT.displayIdx == sizeof(preScanResult) / sizeof(preScanResult[0]) - 1)
        {
            SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
            SCANCXT.displayIdx = 0;
        }
#endif
    }

    if (++SCANCXT.displayIdx == SCANCXT.numScanResults)
    {
        if (p_wifi_ConfigData->networkType == DRV_WIFI_NETWORK_TYPE_SOFT_AP)
        {
            /* Prescan is finished, re-initialize the scan context state. Scan is not allowed in Soft AP mode.
             * However, SCANCXT.numScanResults needs to be preserved for webpage using.
             */
            SCAN_CLEAR_VALID(SCANCXT.scanState);
            SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
            SCANCXT.displayIdx = 0;
        }
        else
        {
            SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
            SCANCXT.displayIdx = 0;
        }
    }
}
示例#12
0
//
// Main application entry point.
//
int main(void)
{
    static SYS_TICK startTick = 0;
    static IPV4_ADDR dwLastIP[2] = { {-1}, {-1} };
    IPV4_ADDR           ipAddr;

    SYS_USERIO_LED_STATE LEDstate = SYS_USERIO_LED_DEASSERTED;
    int                 i, nNets;
    TCPIP_NET_HANDLE    netH;
    const char          *netName, *netBiosName;

#if defined (TCPIP_STACK_USE_ZEROCONF_MDNS_SD)
    char mDNSServiceName[] = "MyWebServiceNameX ";     // base name of the service Must not exceed 16 bytes long
                                                       // the last digit will be incremented by interface
#endif  // defined (TCPIP_STACK_USE_ZEROCONF_MDNS_SD)


    // perform system initialization
    SYS_Initialize(0);

    SYS_CONSOLE_MESSAGE("\r\n\n\n ---  TCPIP Demo Starts!  --- \r\n");
    SYS_OUT_MESSAGE("TCPIPStack " TCPIP_STACK_VERSION "  ""                ");

        // Display the names associated with each interface
    nNets = TCPIP_STACK_NumberOfNetworksGet();
    for(i = 0; i < nNets; i++)
    {

        netH = TCPIP_STACK_IndexToNet(i);
        netName = TCPIP_STACK_NetNameGet(netH);
        netBiosName = TCPIP_STACK_NetBIOSName(netH);

#if defined(TCPIP_STACK_USE_NBNS)
        SYS_CONSOLE_PRINT("    Interface %s on host %s - NBNS enabled\r\n", netName, netBiosName);
#else
        SYS_CONSOLE_PRINT("    Interface %s on host %s - NBNS disabled\r\n", netName, netBiosName);
#endif  // defined(TCPIP_STACK_USE_NBNS)

#if defined (TCPIP_STACK_USE_ZEROCONF_MDNS_SD)
        mDNSServiceName[sizeof(mDNSServiceName) - 2] = '1' + i;
        TCPIP_MDNS_ServiceRegister( netH
                , mDNSServiceName                   // name of the service
                ,"_http._tcp.local"                 // type of the service
                ,80                                 // TCP or UDP port, at which this service is available
                ,((const uint8_t *)"path=/index.htm")  // TXT info
                ,1                                  // auto rename the service when if needed
                ,NULL                               // no callback function
                ,NULL);                             // no application context
#endif //TCPIP_STACK_USE_ZEROCONF_MDNS_SD
    }

#if defined(WF_UPDATE_FIRMWARE_UART_24G)
    extern bool    WF_FirmwareUpdate_Uart_24G(void);
    WF_FirmwareUpdate_Uart_24G();
#endif

    // Now that all items are initialized, begin the co-operative
    // multitasking loop.  This infinite loop will continuously
    // execute all stack-related tasks, as well as your own
    // application's functions.  Custom functions should be added
    // at the end of this loop.
    // Note that this is a "co-operative mult-tasking" mechanism
    // where every task performs its tasks (whether all in one shot
    // or part of it) and returns so that other tasks can do their
    // job.
    // If a task needs very long time to do its job, it must be broken
    // down into smaller pieces so that other tasks can have CPU time.
    while (1)
    {
        SYS_Tasks();

        // Blink LED0 every second.
        if (SYS_TICK_Get() - startTick >= SYS_TICK_TicksPerSecondGet() / 2ul)
        {
            startTick = SYS_TICK_Get();
            LEDstate ^= SYS_USERIO_LED_ASSERTED;
            SYS_USERIO_SetLED(SYS_USERIO_LED_0, LEDstate);
        }

        // if the IP address of an interface has changed
        // display the new value on the system console
        nNets = TCPIP_STACK_NumberOfNetworksGet();
        for (i = 0; i < nNets; i++)
        {
            netH = TCPIP_STACK_IndexToNet(i);
            ipAddr.Val = TCPIP_STACK_NetAddress(netH);
            if(dwLastIP[i].Val != ipAddr.Val)
            {
                dwLastIP[i].Val = ipAddr.Val;

                SYS_CONSOLE_MESSAGE(TCPIP_STACK_NetNameGet(netH));
                SYS_CONSOLE_MESSAGE(" IP Address: ");
                SYS_CONSOLE_PRINT("%d.%d.%d.%d \r\n", ipAddr.v[0], ipAddr.v[1], ipAddr.v[2], ipAddr.v[3]);
            }
        }

#if (WF_DEFAULT_NETWORK_TYPE == WF_NETWORK_TYPE_SOFT_AP)

        if (g_scan_done) {
           if (g_prescan_waiting) {
               SYS_CONSOLE_MESSAGE((const char*)"\n SoftAP prescan results ........ \r\n\n");
               SCANCXT.displayIdx = 0;
               extern void WFDisplayScanMgr(void);
               while (IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) {
                   WFDisplayScanMgr();
               }
               SYS_CONSOLE_MESSAGE((const char*)"\r\n ");

       #if defined(WF_CS_TRIS)
                Demo_Wifi_Connect();
       #endif
               g_scan_done = 0;
               g_prescan_waiting = 0;
           }
        }
#endif // (WF_DEFAULT_NETWORK_TYPE == WF_NETWORK_TYPE_SOFT_AP)

#if defined(WF_UPDATE_FIRMWARE_UART_24G)
    WF_FirmwareUpdate_Uart_24G();
#endif

#if defined(WF_UPDATE_FIRMWARE_TCPCLIENT_24G)
    WF_FirmwareUpdate_TcpClient_24G();
#endif

    }
}
void WFDisplayScanMgr()
{
    tWFScanResult   bssDesc;
    char ssid[80];
    char rssiChan[48];
    int    count;

    if (SCANCXT.numScanResults == 0)
       return;
    if (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
       return;

    if (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))
       return;

    if (!IS_SCAN_STATE_VALID(SCANCXT.scanState))
       return;

    WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc);

    /* Display SSID */
    count = SCANCXT.displayIdx + 1;
    sprintf(ssid, "%d SSID: %s\r\n", count, bssDesc.ssid);
    putsUART(ssid);

    /* Display SSID  & Channel */
    /* RSSI_MAX : 200, RSSI_MIN : 106 */
#ifdef STACK_USE_CERTIFATE_DEBUG	
	sprintf(rssiChan, "  => RSSI: %u, Channel: %u", bssDesc.rssi, bssDesc.channel);
    putsUART(rssiChan);
	/* Display BSSID */
	sprintf(rssiChan, " , BSSID: %02x:%02x:%02x:%02x:%02x:%02x ,", 
				 bssDesc.bssid[0],bssDesc.bssid[1],bssDesc.bssid[2],
				 bssDesc.bssid[3],bssDesc.bssid[4],bssDesc.bssid[5]);
	putsUART(rssiChan);
	/* Display Security Mode */
	if((bssDesc.apConfig & 0x10) == 0)	  // bit4==0:	open (no security)
	{
		sprintf(rssiChan, "Security mode: %s\r\n", "Open");
	}
	else								 // bit4== 1:	security
	{			 
		if ((bssDesc.apConfig & 0x80) == 0x80) // bit7 ==  1: WPA2
		{
			sprintf(rssiChan, "Security mode: %s\r\n", "WPA2");
		}
		else if((bssDesc.apConfig & 0x40) == 0x40)//bit6==1: WPA
		{
			sprintf(rssiChan, "Security mode: %s\r\n", "WPA");
		}
		else									  // bit7==0, bit6 ==0, WEP
		{
			sprintf(rssiChan, "Security mode: %s\r\n", "WEP");
		}
	}
	putsUART(rssiChan);
#else
	sprintf(rssiChan, "  => RSSI: %u, Channel: %u\r\n", bssDesc.rssi, bssDesc.channel);
    putsUART(rssiChan);
#endif

#if (MY_DEFAULT_NETWORK_TYPE == WF_SOFT_AP) 		
	preScanResult[SCANCXT.displayIdx]= bssDesc;    // WF_PRESCAN
#endif

    if (++SCANCXT.displayIdx == SCANCXT.numScanResults)  {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
#if defined(WF_CONSOLE) & defined(STACK_USE_UART)
        WFConsoleReleaseConsoleMsg();
#endif
    }

    return;
}
示例#14
0
/*****************************************************************************
  Function:
	HTTP_IO_RESULT HTTPExecuteGet(void)
	
  Internal:
  	See documentation in the TCP/IP Stack API or HTTP2.h for details.
  ***************************************************************************/
HTTP_IO_RESULT HTTPExecuteGet(void)
{
	BYTE *ptr;
	BYTE filename[20];
	
	// Load the file name
	// Make sure BYTE filename[] above is large enough for your longest name
	MPFSGetFilename(curHTTP.file, filename, 20);

    /******************************************/
	// If it's the leds.cgi LED update file
    /******************************************/
	if(!memcmppgm2ram(filename, "leds.cgi", 8))
	{
		// Determine which LED to toggle
		ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"led");
		
		// Toggle the specified LED
		switch(*ptr)
        {
			case '1':
				LED1_INV();
				break;
			case '2':
				LED2_INV();
				break;
            default:
                break;
		}
		
	}
    /******************************************/
    // If it's the wifi.xml scan file
    /******************************************/
    if(!memcmppgm2ram(filename, "wifi.xml", 8))
	{
		ptr = HTTPGetROMArg(curHTTP.data, (ROM BYTE *)"scan");

		if (ptr != NULL)
		{
            if(IS_SCAN_IN_PROGRESS(SCANCXT.scanState))
                return HTTP_IO_WAITING;

            if(IS_SCAN_STATE_DISPLAY(SCANCXT.scanState))
                return HTTP_IO_DONE;

			// Start Scan Request
        	if (WFStartScan() == WF_SUCCESS)
	    	{
            	SCAN_SET_DISPLAY(SCANCXT.scanState);
            	SCANCXT.displayIdx = 0;
                return HTTP_IO_WAITING;
        	}
		}
	}
	else
	{
        ;
	}		
	
	return HTTP_IO_DONE;
}
示例#15
0
 void WFDisplayScanMgr(void)
{
    t_wfScanResult   bssDesc;
    char st[80];
    int i;
	
    if ((SCANCXT.numScanResults == 0)               ||
        (!IS_SCAN_STATE_DISPLAY(SCANCXT.scanState)) ||
        (IS_SCAN_IN_PROGRESS(SCANCXT.scanState))    ||
        (!IS_SCAN_STATE_VALID(SCANCXT.scanState)))
    {
       return;
    }

    WFRetrieveScanResult(SCANCXT.displayIdx, &bssDesc);

    /* Display SSID */
    sprintf(st,"%2d ",SCANCXT.displayIdx);
    SYS_CONSOLE_MESSAGE(st);
    SYS_CONSOLE_MESSAGE("SSID: ");
    for(i = 0; i < bssDesc.ssidLen; i++) st[i] = bssDesc.ssid[i];
    st[bssDesc.ssidLen]=0;
    SYS_CONSOLE_MESSAGE(st);
    SYS_CONSOLE_MESSAGE("\r\n");


    /* Display BSSID */
    SYS_CONSOLE_MESSAGE("   BSSID: ");
    for(i = 0; i < WF_BSSID_LENGTH; i++)
    {
        if (i < 5)
        {
            sprintf(st, "%02X:", bssDesc.bssid[i]);
            SYS_CONSOLE_MESSAGE(st);
        }
        else
        {
            sprintf(st, "%02X, ", bssDesc.bssid[i]);
            SYS_CONSOLE_MESSAGE(st);
        }
    }
    /* Display network mode*/
    if (bssDesc.bssType == WF_NETWORK_TYPE_INFRASTRUCTURE)
        SYS_CONSOLE_MESSAGE("Network Mode: Infra, ");
    else if (bssDesc.bssType == WF_NETWORK_TYPE_ADHOC)
        SYS_CONSOLE_MESSAGE("Network Mode: Adhoc, ");

    /* Display RSSI  & Channel */
    sprintf(st, "RSSI: %3u, Channel: %2u\r\n", bssDesc.rssi, bssDesc.channel);
    SYS_CONSOLE_MESSAGE(st);

    #if (WF_DEFAULT_NETWORK_TYPE == WF_NETWORK_TYPE_SOFT_AP)
        preScanResult[SCANCXT.displayIdx]= bssDesc;    // WF_PRESCAN
    #endif

    if (++SCANCXT.displayIdx == SCANCXT.numScanResults)  
    {
        SCAN_CLEAR_DISPLAY(SCANCXT.scanState);
        SCANCXT.displayIdx = 0;
        #if defined(CMD_PARSER)
            WFConsoleReleaseConsoleMsg();
        #endif
    }
}