Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
B

P¥1呅v”ã@s„dZddlZddlZddlZddlmZddlmZmZddl	m
Z
ddlmZm
Z
Gdd	„d	eƒZGd
d„dƒZGdd
„d
ƒZdS)zB
profiler.interface
~~~~~~~~~~~~~~~~~~

wlan interface data class
éN)Ú
namedtuple)ÚDictÚListé)Ú_20MHZ_FREQUENCY_CHANNEL_MAP)Úflag_last_objectÚrun_commandc@seZdZdZdS)ÚInterfaceErrorzQCustom exception used when there are problems staging the interface for injectionN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__©rrú‘/build/wlanpi-profiler-7IIg1Q/wlanpi-profiler-1.0.11/debian/wlanpi-profiler/opt/wlanpi-profiler/lib/python3.7/site-packages/profiler/interface.pyr	sr	c@seZdZdZdd„ZdS)ÚInterfaceInformationz$Base class for Interface InformationcCs.||_||_||_||_||_||_||_dS)N)ÚphyÚ	interfaceÚmodeÚdriverÚdriver_versionÚfirmware_revÚchipset)ÚselfrrrrrrrrrrÚ__init__"s
zInterfaceInformation.__init__N)r
rrr
rrrrrrsrc@s¨eZdZdZdd„Zdd„Zedd„ƒZdd	œd
d„Zdd	œdd
„Z	dd	œdd„Z
dd	œdd„Zed	œdd„Z
ed	œdd„ZdBeedœdd„Zdd	œdd„Zeed	œdd„ƒZdCdd	œdd„Zeed œd!d"„Zdd	œd#d$„Zed	œd%d&„Zed	œd'd(„Zed	œd)d*„Zed	œd+d,„Zed	œd-d.„Zed	œd/d0„Zed	œd1d2„Zed3d4„ƒZ ed5d6„ƒZ!edDd7d8„ƒZ"dEed	œd:d;„Z#eed	œd<d=„ƒZ$ed	œd>d?„Z%dFed	œd@dA„Z&dS)GÚ	InterfacezWLAN Interface data classcCsBt |jj ¡¡|_d|_d|_d|_d|_	g|_
d|_d|_dS)NÚF)
ÚloggingÚ	getLoggerÚ	__class__r
ÚlowerÚlogÚnameÚchannelÚ	frequencyÚrequires_vifÚphysÚno_interface_prepÚremoved)rrrrr8szInterface.__init__cCsœ|jstdƒ‚| |j¡|_| |j¡}| |¡|_| |¡|_| 	|j¡|_
| |j¡| ¡|_
d|j
›|_d|_|jr´tdd|j›dgƒ}| ||j¡|_| ||j¡|_nbd|jkr|j›d|_|j|jkrü|j d	|j|j|j
¡td
ƒ‚n|j d|j|j
¡d|_|js*td
|jƒ‚|js>td|jƒ‚|j d|j|j¡| ¡|_| ¡|_|jdkr~td|jƒ‚| ¡|_|  ¡| !¡dS)zPerform setup for the interfacezinterface name not setrrÚiwÚdevÚinfoÚ88XXauÚmonzCproposed %s interface matches provided %s and already maps to phy%sz„iwlwifi requires use of a separate monitor interface. did you already handle interface staging and mean to run with --noprep option?znew %s will map to phy%sTzunknown channel setting for %sz unknown frequency setting for %sz/frequency is set to %s which maps to channel %s)ÚmanagedÚmonitorz$%s is mode is not managed or monitorN)"r!r	Ú
get_driverrÚget_ethtool_infoÚget_driver_versionrÚget_firmware_revisionZfirmware_revisionÚget_chipsetrÚcheck_interface_stackÚ
get_phy_idÚphy_idrr,r&rÚ
get_frequencyr#Úget_channelr"r ÚwarningÚdebugr$Úget_macÚmacÚget_moderÚ
get_operstateÚ	operstateÚchecksÚ	log_debug)rÚ
eth_tool_infoÚiw_dev_iface_inforrrÚsetupBsT



zInterface.setupcCsZg}xB|D]:}tt||ƒtƒr0| t||ƒ¡q
| tt||ƒƒ¡q
Wtdd„|DƒƒS)z<Find all matching attributes in a list and return max lengthcss|]}t|ƒVqdS)N)Úlen)Ú.0Úxrrrú	<genexpr>€sz-Interface.get_attr_max_len.<locals>.<genexpr>)Ú
isinstanceÚgetattrÚstrÚappendÚmax)Z
searchListÚattrZ_listÚ_objrrrÚget_attr_max_lenws
zInterface.get_attr_max_lenN)ÚreturncCsÆtddgƒ}t|ƒ| tddgƒ¡|_|j d|j¡g}xˆ|jD]~}xx|jD]n}| |j¡}| 	|j¡}| 
|¡}| |¡}| |j¡}	|j
|jd}
| td|j›|j|
||||	ƒ¡qPWqDW| ¡| dtd	d
ddd
ddƒ¡| dtdddddddƒ¡t |d¡}t |d¡}t |d¡}
t |d¡}t |d¡}t |d¡}t |d¡}tddgƒ}t|ƒd}xF|D]>}|dj|j|j|j|j|j|j|j|||
||||d7}qxWt|ƒdS)zPrint wiphys to the screenÚlsb_releasez-ar(r)zphys: %s)ÚifacerrZPHYrZModeZDriverZ
DriverVersionZFirmwareRevZChipsetrú rrrrrrÚunamerz‡{0:<{phy_len}}  {1:<{interface_len}}  {2:<{mode_len}}  {3:<{driver_len}}  {4:<{driverv_len}}  {5:<{firmwarer_len}}  {6:<{chipset_len}}
)Úphy_lenÚ
interface_lenÚmode_lenÚ
driver_lenÚdriverv_lenÚ
firmwarer_lenÚchipset_lenN)rÚprintÚbuild_iw_phy_listr%r r:Ú
interfacesr0r!r/r1r2r3r=rLrr6ÚreverseÚinsertrrPÚformatrrrrrrr)rrRÚifacesrrSrBrrrrrrVrWrXrYrZr[r\rUÚoutrrrÚprint_interface_information‚sz



z%Interface.print_interface_informationcCsxtdddgƒ}dd„| d¡Dƒ}dd |¡krTd	|jkrt|j d
¡|j d¡n |j dd
 |¡¡|j d¡dS)z*Check and report the set regulatory domainr(ÚregÚgetcSsg|]}d|kr|‘qS)Zcountryr)rFÚlinerrrú
<listcomp>Ïsz.Interface.check_reg_domain.<locals>.<listcomp>Ú
ZUNSETrZiwlwifizBreg domain appears unset. consider setting it with 'iw reg set XX'zZhttps://wireless.wiki.kernel.org/en/users/documentation/iw#updating_your_regulatory_domainzreg domain set to %srTzsee 'iw reg get' for detailsN)rÚsplitÚjoinrr r9r:)rZregdomain_resultZ	regdomainrrrÚcheck_reg_domainÌs
zInterface.check_reg_domaincCs`ddd|j›dgdd|j›dgddd|j›dgg}x(|D] }|j d	d
 |¡¡t|ƒq8WdS)z.Delete monitor interface and restore interfaceÚipÚlinkÚsetÚdownr(r)ÚdelÚupzrun: %srTN)r,r!r r:rlr)rÚcommandsÚcmdrrrÚreset_interfaceÜs
zInterface.reset_interfacecCstddd|j›dgdd|j›dddgddd|j›d	gd|j›d
gg}x,|D]$}|j dd |¡¡t|d
dqHWdS)z4Perform scan in attempt to enable a disabled channelrnrorprqr(r)Útyper-rsÚscanzrun: %srTT)Zsuppress_outputN)r!r r:rlr)rZiwlwifi_scan_commandsrurrrrxçs
zInterface.scanc	CsLddd|j›dgdd|j›dddgddd|j›d	gd|j›dd
|j›dggS)z+Retrieve generic interface staging commandsrnrorprqr(r)rwr.rsr"ÚHT20)r!r")rrrrÚget_generic_staging_commandsósz&Interface.get_generic_staging_commandsc	CsZd|j›dd|j›ddddg	dd	d
|j›dgdd	d
|j›dgd|j›d
d
|j›dgg}|S)z5Retrieve interface staging commands for iwlwifi cardsr(rÚaddrwr.ÚflagsÚnonernrorprsrqÚfreqry)rr,r!r#)rÚcmdsrrrÚget_iwlwifi_staging_commandsüsz&Interface.get_iwlwifi_staging_commandsF)r~rQcCs| |¡}|rŒx|| ¡D]p\}}xf|D]^}t|ƒt|jƒkr&|jsH|jr&|r€|jrf|j d|j|j¡|jr€|j d|j|j¡dSq&WqWdS)zDCheck iw phy channels for disabled or No IR and return True if foundzChannel is disabled for %s (%s)zZNo IR found in iw channel information for %s (%s) which means injection will not function!TF)	Úget_channels_statusÚitemsÚintr~ÚdisabledÚno_irr r9Úch)rr~Úiw_phy_channelsÚverboseZchannels_statusZ_bandÚchannelsr†rrrÚ#check_for_disabled_or_noir_channelss&

z-Interface.check_for_disabled_or_noir_channelscCs tddgƒ}|r.|j d| ¡d dd¡¡tddgƒ}|rP|j d	| ¡¡td
dgƒ}|rr|j d	| ¡¡dd|j›d
g}t|ƒg}d|jkr¢| ¡}nB| 	¡}| 
|jtd
d|j›dgƒ¡rä|j d|j|j¡| 
¡xp|D]h}|j dd |¡¡d|krJt|ƒ ¡}d|krR|j |¡d|krRt|j›dƒ‚qêt|ƒqêW|j|jd|_d|jkrztdƒ‚|j
|jtd
d|j›dgƒdddS)z4Prepare the interface for monitor mode and injectionZwpa_cliz-vzwpa_cli version is %srzwpa_cli rrnz-Vz%sr(z	--versionz-iÚ	terminater+rr‰zBinitiating scan on %s because checks found disabled or No IR on %szrun: %srTr.znon-zeroz
not supportedz( does not appear to support monitor mode)rSz interface is not in monitor modeT)rˆN)rr r:Ú
splitlinesÚreplaceÚstripr!rrzr€rŠr#rrxrlr	r=r,r)rZwpa_cli_versionZ
ip_versionZ
iw_versionZwpa_cli_cmdrruÚstdoutrrrÚstage_interface-sR





zInterface.stage_interfacecCsÈt t ¡dd¡}|r"d|kr0| d¡iSd}d}d}d}d}d}d}i}	g}
tdd	d
ddgƒ}xZt| ¡ƒD]H\}}
| ¡ 	¡}|r®d}| 
d
¡r®| d¡d}qv|rêd}| 
d¡rê| ¡d}| ¡d dd¡ dd¡}qv| 
d¡rød}| 
d¡r^|
 
|||||ƒ¡d}d}d}d}d|kr6d}| ¡d}| ¡d dd¡ dd¡}| 
d
¡r |
 
|||||ƒ¡|
|	|<g}
d}d}| d¡d}|
rv|
 
|||||ƒ¡|
|	|<qvW|	S)z:Run `iw phy phyX channels` and analyze channel informationrézcommand failedz$unable to detect valid channels fromrFTr"r~r†r…r„zband rTrÚ*ú[ú]zno ir)rrÚinspectÚstackr9rrrŒrŽrÚ
startswithrkrrL)r‡r r~r†r…Zbandr„Z
first_bandZfirst_channel_in_bandZbandsr‰r"rhÚ	last_linerrrrnsd




zInterface.get_channels_statuscCsl|js
|r(d|jkr(|j d|j|j¡|js2|r`|j}|jrD|j}d|jkr`|j d||j¡| ¡dS)z*Perform self checks and warn as neccessaryr.z3%s mode is in %s mode when we expected monitor modersz*%s operating state is %s when we expect upN)	r&rr r9r!r$r,r?rm)rZstagedr!rrrr@¨s 



zInterface.checks)rrQcCsŽg}xDt d¡D]6}tj d|¡}tj |¡rdt |¡kr| |¡qW||krx|j d|d |¡¡t|›dƒ‚n|j 	d|¡|SdS)z]Check that the interface we've been asked to run on actually exists and has an mac80211 stackz/sys/class/netZphy80211zW%s interface does not support the mac80211 stack. here are some interfaces which do: %sz, z% is not detected as a valid interfacez%s has a mac80211 stackN)
ÚosÚlistdirÚpathrlÚisdirrLr r9r	r:)rrZdiscovered_interfacesrSZ
iface_pathrrrr4¿szInterface.check_interface_stackcCs$|j d|j|j|j|j|j¡dS)z Send debug information to loggerzAmac: %s, channel: %s, driver: %s, driver-version: %s, chipset: %sN)r r:r<r"rrr)rrrrrAÔszInterface.log_debugcCstdd|›gƒ}| ¡S)z(Gather ethtool information for interfaceÚethtoolz-i)rrŽ)rrSrrrrr0ßszInterface.get_ethtool_infocCs(tddd|›dgƒ}| d¡d ¡S)z'Gather driver information for interfaceÚreadlinkz-fz/sys/class/net/z/device/driverú/éÿÿÿÿ)rrkrŽ)rrSrrrrr/äszInterface.get_drivercCs8d}x.| ¡ ¡D]}| d¡r| dd¡ ¡}qW|S)z#Gather driver version for interfacerzversion:)rrŒr—rrŽ)rrBrdrhrrrr1ës

zInterface.get_driver_versioncCs8d}x.| ¡ ¡D]}| d¡r| dd¡ ¡}qW|S)z,Gather driver firmware version for interfacerzfirmware-version:)rrŒr—rrŽ)rrBrdrhrrrr2ós

zInterface.get_firmware_revisioncCsZddddddddd	d
ddd
ddddg}x |D]}||kr,| |d¡}q,Wd | ¡¡}|S)zRemove extraneous wordszWireless LAN ControllerszNetwork ConnectionzWireless AdapterzWLAN Adapterú(ú)zCorporation.ZCorporationzCorp.ZCorpzInc.ZInczTechnology,Z
Technologyú,ú"z  rT)rrlrk)rrÚwordsÚwordrrrÚcleanup_chipsetûs,
zInterface.cleanup_chipsetcCsZtdd|›dgƒ}| d¡d}d}|dkr„| d¡ddd	… d
d¡}tdd|›gƒ}| d¡d
dd… ¡}| |¡}|S|dkrþtdd|›dgƒ ¡}tdd|›dgƒ ¡}tdd|›d|›dgƒ}| d¡d
 ¡ ¡d}| |¡}|S|dkrRtdd|›dgƒ ¡}tdd|›dgƒ ¡}|›d|›dkrVd}nd}|S)z(Gather chipset information for interfaceÚcatz/sys/class/net/z/device/modaliasú:rrZusbré
ÚpZlsusbz-dééNZpciz/device/vendorz/device/deviceZlspciz-qZsdioz
0x02d0:0xa9a6zBroadcom 43430ÚUnknown)rrkrrŽr§rŒ)rrSZmodaliasZbusrZbusinfoÚvendorZdevicerrrr3s6


zInterface.get_chipsetcCs"tdd|j›dgƒ}| ¡ ¡S)z(Gather MAC address for a given interfacer¨z/sys/class/net/z/address)rr!rŽr)rr<rrrr;9szInterface.get_maccCstj||ddS)z0Determine which frequency the interfac is set toT)r7)rÚparse_iw_dev_iface_info)rCrSrrrr7>szInterface.get_frequencycCstj||ddS)z/Determine which channel the interface is set toT)r8)rr°)rCrSrrrr8EszInterface.get_channelc	CsÎt t ¡dd¡}x²| ¡D]¦}| ¡ ¡}d|kr t| d¡d d¡dƒ}t| d¡d d¡d 	dd	¡ƒ}t
 |d¡}||krš| d
||¡|r°| 
d||¡|S|r | 
d||¡|Sq Wd
S)z;Determine what channel or frequency the interface is set torr‘r"r£rTrr¬r¡rz9iw reported a different channel (%s) than our lookup (%s)z.get_frequency returns %s from `iw dev %s info`z,get_channel returns %s from `iw dev %s info`N)rrr•r–rŒrrŽrƒrkrrrgr9r:)	rCrSr7r8r rhr"r~Úresprrrr°Ls2$z!Interface.parse_iw_dev_iface_inforcCs*|s
|j}tdd|›dgƒ}| ¡ ¡S)a
        Get the current operating state of the interface.

        https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
        What:       /sys/class/net/<iface>/operstate
        Date:       March 2006
        KernelVersion:  2.6.17
        Contact:    netdev@vger.kernel.org
        Description:
            Indicates the interface RFC2863 operational state as a string.
            Possible values are:
            "unknown", "notpresent", "down", "lowerlayerdown", "testing",
            "dormant", "up".
        r¨z/sys/class/net/z
/operstate)r!rrŽr)rrSr?rrrr>nszInterface.get_operstatecCsÖt t ¡dd¡}tdddddgƒ}tdd	d
gƒ}g}g}d}d}d}d}	d}
d}xxt| ¡ƒD]f\}}
| ¡ ¡}|r¦|
rˆgS| 	d
¡r¦d}| 
d¡d}qf| 	d¡rød|ksÀd|krÐ| d||¡qf|rè| |||	|
|ƒ¡| 
d¡d}qf| 	d¡r| 
d¡d}	qf| 	d¡r0| 
d¡d}
qf| 	d¡rL| 
d¡d}qf| 	d
¡r¦| |||	|
|ƒ¡| |||ƒ¡d}d}g}d}	d}
d}| 
d¡d ¡}|
rf| |||	|
|ƒ¡| |||ƒ¡qfW|S)zCreate map of phy to ifacerr‘rSr!ÚifindexÚaddrrwrr6r_Trzphy#Fú#rz
interface Zunnamedz
non-netdevzskipping %s in phy%s detectionrTzifindex zaddr ztype )
rrr•r–rrrŒrŽrr—rkr:rL)Ziw_devsr rSrr%rcZ	first_phyr6Z
iface_namer²r³Ú_typerhZis_last_linerrrr^‚sf

zInterface.build_iw_phy_listcCsb| tddgƒ¡|_d}xD|jD]:}x4|jD]*}|j|jkr,|j d|j|j¡|j}q,Wq W|S)zCCheck and determines the phy# for the interface name of this objectr(r)rzphy%s maps to provided %s)r^rr%r_r!r r:r6)rr6rrSrrrr5ÆszInterface.get_phy_idcCs‚|s
|j}tdd|›dgƒ}d}yt|ƒ}Wntk
rB|SX|dkrRd}n(|dkr`d}n|d	krnd}n|d
krzd}| ¡S)z?Get the current mode of the interface {unknown/managed/monitor}r¨z/sys/class/net/z/typeÚunknownrr-i!r.i"i#)r!rrƒÚ
ValueErrorr)rrSZ_interface_typerrµrrrr=Òs"zInterface.get_mode)F)F)FF)r)r)'r
rrr
rrDÚstaticmethodrPrermrvrxrrzr€rƒÚboolrŠrrrr@rKr4rAr0r/r1r2r§r3r;r7r8r°r>r^r5r=rrrrr5sD
5J	A9# Cr)r
r•rr™ÚcollectionsrÚtypingrrÚ	constantsrZhelpersrrÚ	Exceptionr	rrrrrrÚ<module>
s