/*---------------------------------------------------------------------------* Project: WD demo File: scan.c Copyright 2006 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Log: scan.c,v $ Revision 1.12 2007/08/01 09:36:29 kitase_hirotake TAB -> SPACE Revision 1.11 2006/11/14 00:08:22 terui Made revision so that the buffer storing the scan result will be in MEM2. Revision 1.10 2006/09/27 09:46:44 terui Changed the scan type to PASSIVE. Made adjustment to the look of debug output. Modified so that the signal strength of the discovered AP will be displayed. Modified so that MP communication parent can be identified. Revision 1.9 2006/09/11 08:23:37 okajima_manabu Corrected the reversed display of WPA2 AES and WPA AES. Miscellaneous minor adjustment to display related items. Revision 1.8 09/06/2006 02:31:12 yoshioka_yasuhiro Added support for WD library. Added support for encryption format scan. Revision 1.7 2006/08/29 09:57:34 terui Changed the scan method and scan time specification. Revision 1.6 08/15/2006 03:51:15 yasu Support for PADDING warnings. Revision 1.5 2006/08/09 00:36:19 yasu NCDSleep->OSSleepTicks Revision 1.4 2006/08/08 01:19:10 yasu Moved the wd related header under private. Revision 1.3 2006/07/18 09:25:25 terui Fix appearance Revision 1.2 2006/07/13 12:39:07 terui Fix appearance Revision 1.1 2006/07/13 12:16:23 terui Initial upload $NoKeywords: $ *---------------------------------------------------------------------------*/ #include #include #include #include "sample.h" #include /* For memset(), memcpy() */ /*---------------------------------------------------------------------------* Constant Definitions *---------------------------------------------------------------------------*/ #define SCAN_BUF_SIZE ( 2048 * 2 ) /*---------------------------------------------------------------------------* Internal variable definitions *---------------------------------------------------------------------------*/ static u16 scanEnableChannel; static WDScanParam scanParam; //static u16 scanResult[ SCAN_BUF_SIZE / sizeof( u16 ) ] ATTRIBUTE_ALIGN( 32 ); static u16* scanResult; static const char* privacyMode[] = { "NONE ", "WEP40 ", "WEP104 ", " ", "WPA TKIP ", "WPA2 AES ", "WPA AES ", "WPA TKIP ", "WEP " }; /*---------------------------------------------------------------------------* Internal function prototype *---------------------------------------------------------------------------*/ static void ReportUsage( void ); static void SetDefaultScanParam( WDScanParam* param ); static void AnalyzeScanResult( u16* buf, u16 bufSize ); /*---------------------------------------------------------------------------* Name: main Description: Entry point at time of program start. Arguments: None Returns: int - Returns the result of the process. *---------------------------------------------------------------------------*/ int main( void ) { WDError err; KPADStatus input; SampleInit(); { void* arenaLo = OSGetMEM2ArenaLo(); scanResult = (u16*)OSRoundUp32B( (u32)arenaLo ); arenaLo = (void*)OSRoundUp32B( OSRoundUp32B( (u32)arenaLo ) + SCAN_BUF_SIZE ); OSSetMEM2ArenaLo( arenaLo ); } SetDefaultScanParam( &scanParam ); /* Scan scannable channels */ scanEnableChannel = 0x0000; err = WDCheckEnableChannel( &scanParam.channelBitmap ); if( err != WD_SUCCESS ) SampleReport( "ERROR(%d): StartupScanParam\n", err ); ReportUsage(); while( TRUE ) { input.trig = 0; (void)KPADRead( WPAD_CHAN0, &input, 1 ); /* (A) button */ if( input.trig & KPAD_BUTTON_A ) { /* Execute scan */ err = WDScanOnce( scanResult, SCAN_BUF_SIZE, &scanParam ); if( err != WD_SUCCESS ) { OSReport( "ERROR(%d): UpdateScanInfo\n", err ); if( err != WD_ERR_INSUFFICIENT_BUF ) return err; } AnalyzeScanResult( scanResult, SCAN_BUF_SIZE ); } /* Draw and wait for V-Blank */ SampleWaitRetrace(); } OSHalt( "End of demo" ); return 0; } /*---------------------------------------------------------------------------* Name: ReportUsage Description: Outputs how to operate the demo program. Arguments: None Returns: None *---------------------------------------------------------------------------*/ static void ReportUsage( void ) { SampleReport( "*******************************************************\n" ); SampleReport( " WD scan demo\n" ); SampleReport( " ---- Usage ----\n" ); SampleReport( " (A) : Do scan\n" ); SampleReport( "*******************************************************\n" ); } /*---------------------------------------------------------------------------* Name: SetDefaultScanParam Description: Edits parameters used for scanning. Arguments: param - Pointer to structure to be edited. Returns: None. *---------------------------------------------------------------------------*/ static void SetDefaultScanParam( WDScanParam* param ) { /* Specify the channel to be scanned using bit field format */ param->channelBitmap = scanEnableChannel; /* Specify the time to scan in units of ms */ param->maxChannelTime = 100; /* Specify the BSSIDs for which scan results are to be filtered (all 0xff means no filter) */ (void)memset( param->bssid, 0xff, WD_SIZE_BSSID ); /* Specify scan type */ param->scanType = WD_SCANTYPE_PASSIVE; // param->scanType = WD_SCANTYPE_ACTIVE; /* Specify SSID for which scan results are to be filtered */ param->ssidLength = 0; (void)memset( param->ssid, 0x00, WD_SIZE_SSID ); (void)memset( param->ssidMatchMask, 0xff, WD_SIZE_SSID ); } /*---------------------------------------------------------------------------* Name: AnalyzeScanResult Description: Analyzes the scan result. Arguments: buf - Buffer storing the scan result. bufSize - Maximum size of the buffer. Returns: None. *---------------------------------------------------------------------------*/ static void AnalyzeScanResult( u16* buf, u16 bufSize ) { s32 i; WDBssDesc* p; s32 size; if( buf[ 0 ] > 0 ) { SampleReport( "-------------------------------------------------------------------------------\n" ); SampleReport( "ch lv ss security capa rateset bssid ssid\n" ); SampleReport( "-------------------------------------------------------------------------------\n" ); size = sizeof( u16 ); p = (WDBssDesc*)( (u32)buf + size ); for( i = 0; i < buf[ 0 ]; i ++ ) { size += ( p->length * 2 ); if( size > bufSize ) { break; } else { s8 ssid[ WD_SIZE_SSID + 1 ]; (void)memcpy( ssid, p->ssid, WD_SIZE_SSID ); ssid[ WD_SIZE_SSID ] = 0x00; SampleReport( "%2d %2u %s %s %s %04x/%04x %02x:%02x:%02x:%02x:%02x:%02x %s\n", p->channel, WDGetRadioLevel( (const WDBssDesc*)p ), ( WDFindGameInfo( NULL, NULL, (const WDBssDesc*)p ) ? "MP " : ( ( p->capaInfo & 0x0003 ) == 0x0001 ? "ESS " : ( ( p->capaInfo & 0x0003 ) == 0x0002 ? "IBSS" : " " ) ) ), privacyMode[ WDGetPrivacyMode( (const WDBssDesc*)p ) ], ( ( p->capaInfo % 0x0020 ) == 0x0020 ? "S " : "L " ), p->rateSet.basic, p->rateSet.support, p->bssid[ 0 ], p->bssid[ 1 ], p->bssid[ 2 ], p->bssid[ 3 ], p->bssid[ 4 ], p->bssid[ 5 ], ssid ); } p = (WDBssDesc*)( (u32)buf + size ); } } else { SampleReport( "Could not discover AP\n" ); } } /*---------------------------------------------------------------------------* End of file *---------------------------------------------------------------------------*/