Package ieee80211_channels :: Module channels
[frames] | no frames]

Source Code for Module ieee80211_channels.channels

  1  #! /usr/bin/env python 
  2   
  3  freq_to_chan_map = { 
  4      2412000000L : 1,  
  5      2417000000L : 2,  
  6      2422000000L : 3,  
  7      2427000000L : 4,  
  8      2432000000L : 5,  
  9      2437000000L : 6,  
 10      2442000000L : 7,  
 11      2447000000L : 8,  
 12      2452000000L : 9,  
 13      2457000000L : 10,  
 14      2462000000L : 11,  
 15      2467000000L : 12,  
 16      2472000000L : 13,  
 17      2484000000L : 14,  
 18      3657500000L : 131,  
 19      3662500000L : 132,  
 20      3660000000L : 132,  
 21      3667500000L : 133,  
 22      3665000000L : 133,  
 23      3672500000L : 134,  
 24      3670000000L : 134,  
 25      3677500000L : 135,  
 26      3682500000L : 136,  
 27      3680000000L : 136,  
 28      3687500000L : 137,  
 29      3685000000L : 137,  
 30      3689500000L : 138,  
 31      3690000000L : 138,  
 32      4915000000L : 183,  
 33      4920000000L : 184,  
 34      4925000000L : 185,  
 35      4935000000L : 187,  
 36      4940000000L : 188,  
 37      4945000000L : 189,  
 38      4960000000L : 192,  
 39      4980000000L : 196,  
 40      5035000000L : 7,  
 41      5040000000L : 8,  
 42      5045000000L : 9,  
 43      5055000000L : 11,  
 44      5060000000L : 12,  
 45      5080000000L : 16,  
 46      5170000000L : 34,  
 47      5180000000L : 36,  
 48      5190000000L : 38,  
 49      5200000000L : 40,  
 50      5210000000L : 42,  
 51      5220000000L : 44,  
 52      5230000000L : 46,  
 53      5240000000L : 48,  
 54      5260000000L : 52,  
 55      5280000000L : 56,  
 56      5300000000L : 60,  
 57      5320000000L : 64,  
 58      5500000000L : 100,  
 59      5520000000L : 104,  
 60      5540000000L : 108,  
 61      5560000000L : 112,  
 62      5580000000L : 116,  
 63      5600000000L : 120,  
 64      5620000000L : 124,  
 65      5640000000L : 128,  
 66      5660000000L : 132,  
 67      5680000000L : 136,  
 68      5700000000L : 140,  
 69      5745000000L : 149,  
 70      5765000000L : 153,  
 71      5785000000L : 157,  
 72      5805000000L : 161,  
 73      5825000000L : 165,  
 74  } 
75 76 -class IEEE80211_Channels:
77 """ 78 This class implements IEEE802.11 frequency <---> (channel, band) mapping. 79 """ 80 BAND_2400_MHz = "2400MHz band" #: 2.4GHz band 81 BAND_3600_MHz = "3600MHz band" #: 3.6GHz band 82 BAND_5000_MHz = "5000MHz band" #: 5GHz band 83 BAND_UNKNOWN = "Unknown band" #: unknown band 84 85 @staticmethod
86 - def get_band_from_freq(freq):
87 """ 88 Retrieves the band a frequency belongs to. 89 90 @type freq: long 91 @param freq: the frequency in Hz 92 93 @rtype: string 94 @return: the frequency band (see the class constants) 95 """ 96 if freq >= 2412000000L and freq <= 2484000000L: 97 return IEEE80211_Channels.BAND_2400_MHz 98 elif freq >= 3657500000L and freq <= 3690000000L: 99 return IEEE80211_Channels.BAND_3600_MHz 100 elif freq >= 4915000000L and freq <= 5825000000L: 101 return IEEE80211_Channels.BAND_5000_MHz 102 else: 103 return IEEE80211_Channels.BAND_UNKNOWN
104 105 @staticmethod
106 - def get_channel(freq):
107 """ 108 Returns the channel number corresponding to a frequency. 109 110 @type freq: long 111 @param freq: the frequency in Hz 112 113 @rtype: int 114 @return: channel number or -1 if the frequency is not a valid IEEE802.11 channel 115 """ 116 try: 117 return freq_to_chan_map[freq] 118 except: 119 return -1
120 121 @staticmethod
122 - def get_freq(channel, band):
123 """ 124 Returns the frequency corresponding to a given channel and band. 125 126 @type channel: int 127 @param channel: the channel number 128 @type band: string 129 @param band: the frequency band (one of the class defined constants should be given) 130 131 @rtype: long 132 @return: frequency in Hz or -1 if the (channel, band) combination is not valid 133 """ 134 for freq, ch in freq_to_chan_map.iteritems(): 135 if ch == channel and IEEE80211_Channels.get_band_from_freq(freq) == band: 136 return freq 137 return -1
138