I now currently working on a project to perform network switching according to the received signal strength. From the manual of iwconfig, the explanation for signal level is

Received signal strength (RSSI - how strong the received signal is). May be arbitrary units or dBm, iwconfig uses driver meta information to interpret the raw value given by /proc/net/wireless and display the proper unit or maximum value (using 8 bit arithmetic). In Ad-Hoc mode, this may be undefined and you should use iwspy.
but how they interpret? For example, when the signal strength value(=a)i get from /proc/net/wireless is 202, the signal level(=b) in iwconfig is -54dbm. When i look into the source code of iwcommon.c, i found out that the logic behind is

Code:
b = a - 0x100 (= a - 16^2)
here is the part of code in iwcommon.c:
PHP Code:
/********************** STATISTICS SUBROUTINES **********************/

/*------------------------------------------------------------------*/
/*
 * Output the link statistics, taking care of formating
 */
void
print_stats
(FILE *    stream,
        
iwqual *    qual,
        
iwrange *    range,
        
int        has_range)
{
  
/* Just do it */
  
if(has_range && (qual->level != 0))
    {
      
/* If the statistics are in dBm */
      
if(qual->level range->max_qual.level)
    {
      
/* Statistics are in dBm (absolute power measurement) */
      
fprintf(stream,
          
"Quality:%d/%d  Signal level:%d dBm  Noise level:%d dBm%s\n",
          
qual->qualrange->max_qual.qual,
          
qual->level 0x100qual->noise 0x100,
          (
qual->updated 0x7) ? " (updated)" "");
    }
      else
    {
      
/* Statistics are relative values (0 -> max) */
      
fprintf(stream,
          
"Quality:%d/%d  Signal level:%d/%d  Noise level:%d/%d%s\n",
          
qual->qualrange->max_qual.qual,
          
qual->levelrange->max_qual.level,
          
qual->noiserange->max_qual.noise,
          (
qual->updated 0x7) ? " (updated)" "");
    }
    }
  else
    {
      
/* We can't read the range, so we don't know... */
      
fprintf(stream"Quality:%d  Signal level:%d  Noise level:%d%s\n",
          
qual->qualqual->levelqual->noise,
          (
qual->updated 0x7) ? " (updated)" "");
    }

can anyone please explain to me the logic behind these code? I cannot figure out how they come out with this conversion. Besides that, where the raw value given in /proc/net/wireless come from?

Thanks a lot!!!