Author: wirtz Date: Fri Oct 16 15:25:29 2009 New Revision: 1219 Log: added command line arg. to switch from AP selection by signal strength to quality call with "-q" to use Modified: trunk/tools/iwlist_parser.c Modified: trunk/tools/iwlist_parser.c ============================================================================== --- trunk/tools/iwlist_parser.c Fri Oct 16 14:48:46 2009 (r1218) +++ trunk/tools/iwlist_parser.c Fri Oct 16 15:25:29 2009 (r1219) @@ -29,6 +29,7 @@ bool essidflag; //Look for one SSID only bool fileflag; //Use a file rather than stdin? +bool selectByQualityFlag; char strEssid[MAX_CELLS][ESSID_LENGTH]; char strMAC[MAX_CELLS][MAC_LENGTH]; @@ -51,6 +52,7 @@ { essidflag = false; fileflag = false; + selectByQualityFlag = false; step = 1; int c = 0; @@ -68,12 +70,15 @@ memset(pESSID, 0, ESSID_LENGTH); memset(strSelectedESSID, 0, ESSID_LENGTH); - while ((c = getopt(argc, argv, "s:f:h")) != -1) { + while ((c = getopt(argc, argv, "s:f:h:q")) != -1) { switch (c) { case 's': essidflag = true; strcpy(strSelectedESSID, optarg); break; + case 'q': + selectByQualityFlag = true; + break; case 'f': fileflag = true; strcpy(strFilename, optarg); @@ -86,6 +91,7 @@ fprintf(stderr, "-h\t\tShows this text.\n"); fprintf(stderr, "-s <ESSID>\tShows only results for this essid\n"); fprintf(stderr, "-f <FILE>\tParses from FILE\n"); + fprintf(stderr, "-q = best AP selected by quality (otherwise by signal strength)\n"); exit(0); case '?': fprintf(stderr, "Unrecognized option: -%c \n", optopt); @@ -93,6 +99,8 @@ } } + printf("Selecting best AP by %s\n", (selectByQualityFlag ? "Quality" : "Signal Strength")); + parseFromFile(strFilename); printBestAP(); @@ -285,7 +293,7 @@ { //Select best SignalStrength for given AP (or all AP's) int iIndexCell = 0; - int iBestStrength = 0; + int iBestStrength = -500; int iBestQuality = 0; int i; int foundBest = false; @@ -297,16 +305,26 @@ //debug //printf("MAC: %s\nESSID: %s\nQuality: %d\nSignalStrength: %d\n", strMAC[i], strEssid[i], iQuality[i], iSignalStrength[i]); + if ( selectByQualityFlag ) { + if ( iQuality[i] > iBestQuality) { + iBestQuality = iQuality[i]; + iIndexCell = i; + #ifdef DEBUG + printf("Set index for best Cell to: %i\n", i); + #endif + foundBest = true; + } + } else { - //if (iSignalStrength[i] > iBestStrength) { - //i BestStrength = iSignalStrength[i]; - if ( iQuality[i] > iBestQuality) { - iBestQuality = iQuality[i]; - iIndexCell = i; -#ifdef DEBUG - printf("Set index for best Cell to: %i\n", i); -#endif - foundBest = true; + if ( iSignalStrength[i] != 0 && (int)iSignalStrength[i] > iBestStrength) { + iBestStrength = iSignalStrength[i]; + iIndexCell = i; + #ifdef DEBUG + printf("Set index for best Cell to: %i\n", i); + #endif + foundBest = true; + } + } } }