1+ #!/usr/bin/env python
2+ """ device.py
3+
4+ Example for displaying device details
5+ """
6+
7+ import argparse as ap
8+ import pyric # pyric error (and ecode EUNDEF)
9+ from pyric import pyw # for iw functionality
10+ from pyric import device # for chipset/driver
11+ from pyric .channels import rf2ch # rf to channel conversion
12+
13+ def execute (dev ):
14+ # ensure dev is a wireless interfaces
15+ wifaces = pyw .winterfaces ()
16+ if dev not in wifaces :
17+ print "Device {0} is not wireless, use one of {1}" .format (dev ,wifaces )
18+
19+ dinfo = pyw .devinfo (dev )
20+ card = dinfo ['card' ]
21+ pinfo = pyw .phyinfo (card )
22+ driver = device .ifdriver (card .dev )
23+ chipset = device .ifchipset (driver )
24+
25+ msg = "Device {0}\n " .format (dev )
26+ msg += "\t Driver: {0} Chipset: {1}\n " .format (driver ,chipset )
27+ msg += "\t ifindex: {0}\n " .format (card .idx )
28+ msg += "\t wdev: {0}\n " .format (dinfo ['wdev' ])
29+ msg += "\t addr: {0}\n " .format (dinfo ['mac' ])
30+ msg += "\t mode: {0}\n " .format (dinfo ['mode' ])
31+ msg += "\t wiphy: {0}\n " .format (card .phy )
32+ if dinfo ['mode' ] == 'managed' :
33+ msg += "\t channel: {0} (1 MHz), width: {2}, CF: {3}\n " .format (rf2ch (dinfo ['RF' ]),
34+ dinfo ['RF' ],
35+ dinfo ['CHW' ],
36+ dinfo ['CF' ])
37+ else :
38+ msg += "\t Device not associated\n "
39+ print msg
40+
41+ msg = "Wiphy phy{0}\n " .format (card .phy )
42+ msg += "\t Generation: {0}m Coverage Class: {1}\n " .format (pinfo ['generation' ],
43+ pinfo ['cov_class' ])
44+ msg += "\t Max # scan SSIDs: {0}\n " .format (pinfo ['scan_ssids' ])
45+ msg += "\t Retry Short: {0}, Long: {1}\n " .format (pinfo ['retry_short' ],
46+ pinfo ['retry_long' ])
47+ msg += "\t Threshold Frag: {0}, RTS: {1}\n " .format (pinfo ['frag_thresh' ],
48+ pinfo ['rts_thresh' ])
49+ msg += "\t Supported Modes:\n "
50+ for mode in pinfo ['modes' ]:
51+ msg += "\t * {0}\n " .format (mode )
52+ msg += "\t Supported Commands:\n "
53+ for cmd in pinfo ['commands' ]:
54+ msg += "\t * {0}\n " .format (cmd )
55+ msg += "\t Supported Frequencies:\n "
56+ for freq in pinfo ['freqs' ]:
57+ msg += "\t * {0}\n " .format (freq )
58+
59+ print msg
60+
61+ if __name__ == '__main__' :
62+ # create arg parser and parse command line args
63+ print "Wireless Device Info Display using PyRIC v{0}" .format (pyric .__version__ )
64+ argp = ap .ArgumentParser (description = "Wireless Device Data" )
65+ argp .add_argument ('-d' ,'--dev' ,help = "Wireless Device" )
66+ args = argp .parse_args ()
67+ try :
68+ dev = args .dev
69+ if dev is None :
70+ print "usage: python device.py -d <dev>"
71+ else :
72+ execute (dev )
73+ except pyric .error as e :
74+ print e
0 commit comments