]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - rfkill/rfkill.py
5 # Copyright (c) 2015 Intel Corporation
7 # Author: Johannes Berg <johannes.berg@intel.com>
9 # This software may be distributed under the terms of the MIT license.
10 # See COPYING for more details.
29 _OP_CHANGE_ALL
) = range(4)
33 TYPE_WLAN
: "Wireless LAN",
34 TYPE_BLUETOOTH
: "Bluetooth",
35 TYPE_UWB
: "Ultra-Wideband",
37 TYPE_WWAN
: "Wireless WAN",
43 # idx, type, op, soft, hard
44 _event_struct
= '@IBBBB'
45 _event_sz
= struct
.calcsize(_event_struct
)
47 class RFKillException(Exception):
51 def __init__(self
, idx
):
61 return open('/sys/class/rfkill/rfkill%d/name' % self
._idx
, 'r').read().rstrip()
66 for r
, s
, h
in RFKill
.list():
74 return _type_names
.get(self
._type
, "unknown")
82 raise RFKillException("RFKill instance no longer exists")
85 def soft_blocked(self
):
86 return self
.blocked
[0]
89 def soft_blocked(self
, block
):
96 def hard_blocked(self
):
97 return self
.blocked
[1]
100 rfk
= open('/dev/rfkill', 'w')
101 s
= struct
.pack(_event_struct
, self
.idx
, TYPE_ALL
, _OP_CHANGE
, 1, 0)
106 rfk
= open('/dev/rfkill', 'w')
107 s
= struct
.pack(_event_struct
, self
.idx
, TYPE_ALL
, _OP_CHANGE
, 0, 0)
112 def block_all(cls
, t
=TYPE_ALL
):
113 rfk
= open('/dev/rfkill', 'w')
115 s
= struct
.pack(_event_struct
, 0, t
, _OP_CHANGE_ALL
, 1, 0)
120 def unblock_all(cls
, t
=TYPE_ALL
):
121 rfk
= open('/dev/rfkill', 'w')
122 s
= struct
.pack(_event_struct
, 0, t
, _OP_CHANGE_ALL
, 0, 0)
129 rfk
= open('/dev/rfkill', 'r')
131 flgs
= fcntl
.fcntl(fd
, fcntl
.F_GETFL
)
132 fcntl
.fcntl(fd
, fcntl
.F_SETFL
, flgs | os
.O_NONBLOCK
)
135 d
= rfk
.read(_event_sz
)
136 _idx
, _t
, _op
, _s
, _h
= struct
.unpack(_event_struct
, d
)
141 res
.append((r
, _s
, _h
))
146 if __name__
== "__main__":
147 for r
, s
, h
in RFKill
.list():
148 print "%d: %s: %s" % (r
.idx
, r
.name
, r
.type_name
)
149 print "\tSoft blocked: %s" % ("yes" if s
else "no")
150 print "\tHard blocked: %s" % ("yes" if h
else "no")