Beispiel #1
0
 def apInRange(self, sta, ap, wlan, dist):
     """
     When ap is in range
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     :param dist: distance between source and destination  
     """
     if self.rec_rssi:
         os.system('hwsim_mgmt -k %s %s >/dev/null 2>&1' %
                   (sta.phyID[wlan], abs(int(sta.params['rssi'][wlan]))))
     if ap not in sta.params['apsInRange']:
         sta.params['apsInRange'].append(ap)
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     else:
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     if ap == sta.params['associatedTo'][wlan]:
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         sta.params['rssi'][wlan] = rssi_
         snr_ = setChannelParams.setSNR(sta, wlan)
         sta.params['snr'][wlan] = snr_
         if sta not in ap.params['associatedStations']:
             ap.params['associatedStations'].append(sta)
         if not WmediumdServerConn.connected and dist >= 0.01:
             setChannelParams(sta, ap, wlan, dist)
         if WmediumdServerConn.connected and dist >= 0.01:
             WmediumdServerConn.send_snr_update(
                 WmediumdSNRLink(sta.wmediumdIface, ap.wmediumdIface,
                                 sta.params['snr'][wlan]))
     setChannelParams.recordParams(sta, ap)
Beispiel #2
0
 def apOutOfRange(self, sta, ap, wlan, dist):
     """
     When ap is out of range
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     :param dist: distance between source and destination  
     """
     if ap == sta.params['associatedTo'][wlan]:
         debug('iw dev %s disconnect\n' % sta.params['wlan'][wlan])
         if 'encrypt' in ap.params:
             if ap.params['encrypt'][0] == 'wpa' or ap.params['encrypt'][
                     0] == 'wpa2':
                 os.system('rm %s.staconf' % sta)
                 pidfile = "mn%d_%s_%s_wpa.pid" % (os.getpid(), sta.name,
                                                   wlan)
                 os.system(
                     'pkill -f \'wpa_supplicant -B -Dnl80211 -P %s -i %s\''
                     % (pidfile, sta.params['wlan'][wlan]))
                 os.system('rm /var/run/wpa_supplicant/%s' %
                           sta.params['wlan'][wlan])
         sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
         sta.params['associatedTo'][wlan] = ''
         sta.params['rssi'][wlan] = 0
         sta.params['snr'][wlan] = 0
         sta.params['channel'][wlan] = 0
         # sta.params['frequency'][wlan] = 0
     if sta in ap.params['associatedStations']:
         ap.params['associatedStations'].remove(sta)
     if ap in sta.params['apsInRange']:
         sta.params['apsInRange'].remove(ap)
         ap.params['stationsInRange'].pop(sta, None)
     setChannelParams.recordParams(sta, ap)
Beispiel #3
0
    def configureAP(self, ap, wlanID=0, aplist=None):
        """Configure AP
        
        :param ap: ap node
        :param wlanID: wlan ID
        """
        if 'phywlan' in ap.params:
            wlanID = 1
        for wlan in range(len(ap.params['wlan']) + wlanID):
            if wlanID == 1:
                wlan = 0
            if 'encrypt' in ap.params and 'config' not in ap.params:
                if ap.params['encrypt'][wlan] == 'wpa':
                    ap.auth_algs = 1
                    ap.wpa = 1
                    if 'ieee80211r' in ap.params and ap.params[
                            'ieee80211r'] == 'yes':
                        ap.wpa_key_mgmt = 'FT-EAP'
                    else:
                        ap.wpa_key_mgmt = 'WPA-EAP'
                    ap.rsn_pairwise = 'TKIP CCMP'
                    ap.wpa_passphrase = ap.params['passwd'][0]
                elif ap.params['encrypt'][wlan] == 'wpa2':
                    ap.auth_algs = 1
                    ap.wpa = 2
                    if 'ieee80211r' in ap.params and ap.params[
                            'ieee80211r'] == 'yes':
                        ap.wpa_key_mgmt = 'FT-PSK'
                    else:
                        ap.wpa_key_mgmt = 'WPA-PSK'
                    ap.rsn_pairwise = 'CCMP'
                    ap.wpa_passphrase = ap.params['passwd'][0]
                elif ap.params['encrypt'][wlan] == 'wep':
                    ap.auth_algs = 2
                    ap.wep_key0 = ap.params['passwd'][0]

            cls = AccessPoint
            cls(ap, wlan=wlan, aplist=aplist)

            if 'phywlan' not in ap.params:
                iface = ap.params['wlan'][wlan]
            else:
                iface = ap.params['phywlan']
            if not self.useWmediumd:
                self.setBw(ap, wlan, iface)

            if ap.func[0] != 'ap':
                ap.params['frequency'][wlan] = setChannelParams.frequency(
                    ap, 0)
                wlanID = 0
            setChannelParams.recordParams(None, ap)

            if len(ap.params['ssid']) > 1 and wlan == 0:
                break
Beispiel #4
0
 def updateAssociation(self, sta, ap, wlan):
     """ 
     Updates attributes regarding the association
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     """
     if sta.params['associatedTo'][wlan] != '' and sta in sta.params['associatedTo'][wlan].params['associatedStations']:
         sta.params['associatedTo'][wlan].params['associatedStations'].remove(sta)
         setChannelParams.recordParams(sta, sta.params['associatedTo'][wlan])
     cls = Association
     cls.updateParams(sta, ap, wlan)
     sta.params['associatedTo'][wlan] = ap
Beispiel #5
0
 def apOutOfRange(self, sta, ap, wlan, dist):
     """
     When ap is out of range
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     :param dist: distance between source and destination  
     """
     if ap == sta.params['associatedTo'][wlan]:
         debug('iw dev %s disconnect\n' % sta.params['wlan'][wlan])
         if 'encrypt' in ap.params:
             if ap.params['encrypt'][0] == 'wpa' or ap.params['encrypt'][
                     0] == 'wpa2':
                 os.system('rm %s.staconf' % sta)
                 pidfile = "mn%d_%s_%s_wpa.pid" % (os.getpid(), sta.name,
                                                   wlan)
                 os.system(
                     'pkill -f \'wpa_supplicant -B -Dnl80211 -P %s -i %s\''
                     % (pidfile, sta.params['wlan'][wlan]))
                 os.system('rm /var/run/wpa_supplicant/%s' %
                           sta.params['wlan'][wlan])
         sta.pexec('iw dev %s disconnect' % sta.params['wlan'][wlan])
         sta.params['associatedTo'][wlan] = ''
         sta.params['rssi'][wlan] = 0
         sta.params['snr'][wlan] = 0
         sta.params['channel'][wlan] = 0
         # sta.params['frequency'][wlan] = 0
     if sta in ap.params['associatedStations']:
         ap.params['associatedStations'].remove(sta)
     #~ if ap in sta.params['apsInRange']:
     if ap in sta.params['apsInRange']:
         #
         #Out of Range Event
         #
         if ap.params['r1_r2_sentevent'] == [True, False]:
             ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                         (sta.params['mac'][0], "-100.0", "OUT", 1,
                          ap.params['controller_IP']))
             ap.params['r1_r2_sentevent'] = [False, False]
         elif ap.params['r1_r2_sentevent'] == [
                 True, True
         ] or ap.params['r1_r2_sentevent'] == [False, True]:
             ap.params['r1_r2_sentevent'] = [False, False]
         #
         #
         #
         sta.params['apsInRange'].remove(ap)
         ap.params['stationsInRange'].pop(sta, None)
     setChannelParams.recordParams(sta, ap)
Beispiel #6
0
 def apInRange(self, sta, ap, wlan, dist):
     """
     When ap is in range
     
     :param sta: station
     :param ap: access point
     :param wlan: wlan ID
     :param dist: distance between source and destination  
     """
     if self.rec_rssi:
         os.system('hwsim_mgmt -k %s %s >/dev/null 2>&1' %
                   (sta.phyID[wlan], abs(int(sta.params['rssi'][wlan]))))
     if ap not in sta.params['apsInRange']:
         sta.params['apsInRange'].append(ap)
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     else:
         rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
         ap.params['stationsInRange'][sta] = rssi_
     if ap == sta.params['associatedTo'][wlan]:
         if not WmediumdServerConn.interference_enabled:
             rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
             sta.params['rssi'][wlan] = rssi_
             snr_ = setChannelParams.setSNR(sta, wlan)
             sta.params['snr'][wlan] = snr_
         if sta not in ap.params['associatedStations']:
             ap.params['associatedStations'].append(sta)
         if dist >= 0.01:
             if WmediumdServerConn.connected:
                 if WmediumdServerConn.interference_enabled:
                     if sta.lastpos != sta.params['position']:
                         time.sleep(0.0001)
                         cls = Association
                         cls.setPositionWmediumd(sta)
                         sta.lastpos = sta.params['position']
                 else:
                     if sta.lastpos != sta.params['position']:
                         cls = Association
                         cls.setSNRWmediumd(sta,
                                            ap,
                                            snr=sta.params['snr'][wlan])
             else:
                 setChannelParams(sta, ap, wlan, dist)
     setChannelParams.recordParams(sta, ap)
Beispiel #7
0
    def apInRange(self, sta, ap, wlan, dist):
        """
        When ap is in range
        
        :param sta: station
        :param ap: access point
        :param wlan: wlan ID
        :param dist: distance between source and destination  
        """

        outevent = False
        if self.rec_rssi:
            os.system('hwsim_mgmt -k %s %s >/dev/null 2>&1' %
                      (sta.phyID[wlan], abs(int(sta.params['rssi'][wlan]))))
        if ap not in sta.params['apsInRange']:
            sta.params['apsInRange'].append(ap)
            rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
            ap.params['stationsInRange'][sta] = rssi_
        else:
            rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
            ap.params['stationsInRange'][sta] = rssi_
            if sta in ap.params['associatedStations'] and ap.params[
                    'stationsInRange'][sta] > -43 and ap.func[0] == 'ap':
                sta.params['minswch'] = False
            if sta in ap.params['associatedStations'] and ap.params[
                    'stationsInRange'][sta] > -45.95 and ap.func[0] == 'ap':
                sta.params['maxswch'] = False
            outevent = True
        if ap == sta.params['associatedTo'][wlan]:
            rssi_ = setChannelParams.setRSSI(sta, ap, wlan, dist)
            sta.params['rssi'][wlan] = rssi_
            snr_ = setChannelParams.setSNR(sta, wlan)
            sta.params['snr'][wlan] = snr_
            if sta not in ap.params['associatedStations']:
                ap.params['associatedStations'].append(sta)
            if not WmediumdServerConn.connected and dist >= 0.01:
                setChannelParams(sta, ap, wlan, dist)
            if ap.func[0] == 'ap':
                #~ ap.params['out']=False
                if ap.params['stationsInRange'][sta] <= -44 and sta.params[
                        'minswch'] == False:
                    #~ ap.cmd('echo "%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],ap.params['controller_IP']))
                    #~ print(sta.params['mac'], ap.params['stationsInRange'][sta],ap.params['controller_IP'],ap.name)

                    #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['ASSO'],ap.params['controller_IP']))
                    #~ print 'STA ' + str(sta.params['mac']) + 'is ASSOCIATED to '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
                    ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                                (sta.params['mac'][0],
                                 ap.params['stationsInRange'][sta], "ASSO", 1,
                                 ap.params['controller_IP']))
                    sta.params['minswch'] = True
                    sta.params['x'] = len(sta.params['apsInRange']) - 1
                    ap.params['AssoMacRSSI1'][sta.params['mac'][
                        0]] = ap.params['stationsInRange'][sta]
                elif ap.params['stationsInRange'][sta] <= -46 and sta.params[
                        'maxswch'] == False:
                    #~ print 'STA ' + str(sta.params['mac']) + 'is ASSOCIATED to '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
                    ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                                (sta.params['mac'][0],
                                 ap.params['stationsInRange'][sta], "ASSO", 2,
                                 ap.params['controller_IP']))
                    #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['ASSO'],ap.params['controller_IP']))
                    sta.params['maxswch'] = True
                    sta.params['y'] = len(sta.params['apsInRange']) - 1
                    ap.params['AssoMacRSSI2'][sta.params['mac'][
                        0]] = ap.params['stationsInRange'][sta]
                    #~ if (ap.params['AssoMacRSSI1'] != {}) and (ap.params['AssoMacRSSI2'] != {}):
                    #~ if (ap.params['AssoMacRSSI1'][sta.params['mac'][0]] != None) and (ap.params['AssoMacRSSI2'][sta.params['mac'][0]] != None):
                    #~ print (ap.name, 'ASSO', sta.params['mac'], ap.params['AssoMacRSSI2'][sta.params['mac'][0]] - ap.params['AssoMacRSSI1'][sta.params['mac'][0]])
                    #~ ap.cmd('echo "%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],ap.params['controller_IP']))

                    #~ Uncomment this one for exact getrssi
                    #~ ap.cmd('echo "%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['AssoMacRSSI2'][sta.params['mac'][0]] - ap.params['AssoMacRSSI1'][sta.params['mac'][0]],'ASSO',ap.params['controller_IP']))
                    #~ print 'STA ' + str(sta.params['mac']) + 'is ASSOCIATED to '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
            if WmediumdServerConn.connected and dist >= 0.01:
                WmediumdServerConn.send_snr_update(
                    WmediumdSNRLink(sta.wmediumdIface, ap.wmediumdIface,
                                    sta.params['snr'][wlan]))
        elif ap != sta.params['associatedTo'][wlan] and sta.params[
                'x'] > 0 and ap.func[0] == 'ap':
            #~ ap.params['out'][sta.params['mac'][0]]=True
            #~ print 'STA ' + str(sta.params['mac']) + 'is in RANGE of '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
            ap.cmdPrint(
                'echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                (sta.params['mac'][0], ap.params['stationsInRange'][sta],
                 "RANGE", 1, ap.params['controller_IP']))
            #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['RANGE'],ap.params['controller_IP']))
            sta.params['x'] = sta.params['x'] - 1
            ap.params['InRgMacRSSI1'][sta.params['mac']
                                      [0]] = ap.params['stationsInRange'][sta]
            ap.params['r1_r2_sentevent'][0] = True
        elif ap != sta.params['associatedTo'][wlan] and sta.params[
                'y'] > 0 and ap.func[0] == 'ap':
            #~ ap.params['out'][sta.params['mac'][0]]=False
            #~ print 'STA ' + str(sta.params['mac']) + 'is in RANGE of '+ ap.name + ' With RSSI ' + str(ap.params['stationsInRange'][sta])
            ap.cmdPrint(
                'echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %
                (sta.params['mac'][0], ap.params['stationsInRange'][sta],
                 "RANGE", 2, ap.params['controller_IP']))
            #~ ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta], "DONE", 2, ap.params['controller_IP']))
            #~ ap.cmd('echo "%s,%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta],['RANGE'],ap.params['controller_IP']))
            sta.params['y'] = sta.params['y'] - 1
            ap.params['InRgMacRSSI2'][sta.params['mac']
                                      [0]] = ap.params['stationsInRange'][sta]
            ap.params['r1_r2_sentevent'][1] = True
            if ap.params['r1_r2_sentevent'] == [
                    True, True
            ] or ap.params['r1_r2_sentevent'] == [False, True]:
                ap.params['r1_r2_sentevent'] = [False, False]
            #~ if (ap.params['InRgMacRSSI1'] != {}) and (ap.params['InRgMacRSSI2'] != {}):
            #~ if (ap.params['InRgMacRSSI1'][sta.params['mac'][0]] != None) and (ap.params['InRgMacRSSI2'][sta.params['mac'][0]] != None):
            #~ print (ap.name, 'InRg', sta.params['mac'], ap.params['InRgMacRSSI2'][sta.params['mac'][0]] - ap.params['InRgMacRSSI1'][sta.params['mac'][0]])
            #~ ap.cmd('echo "%s,%s,%s" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['InRgMacRSSI2'][sta.params['mac'][0]] - ap.params['InRgMacRSSI1'][sta.params['mac'][0]],'RANGE',ap.params['controller_IP']))
            #~ elif  ap.func[0]=='ap' and ap != sta.params['associatedTo'][wlan] and float(setChannelParams.getDistance(ap, sta))>=((float(ap.params['range']))-1) and outevent==True:
            #~ if sta not in ap.params['associatedStations'] and ap.params['r1_r2_sentevent']==[True,False]:
            #~ ap.cmdPrint('echo "%s,%s,%s,%d" > /dev/udp/%s/5005' %(sta.params['mac'][0], ap.params['stationsInRange'][sta], "OUT", 1, ap.params['controller_IP']))

        setChannelParams.recordParams(sta, ap)