M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
#!/bin/sh
# /etc/pm/sleep.d/60_wpa_supplicant
# Action script to notify wpa_supplicant of pm-action events.
PATH=/sbin:/usr/sbin:/bin:/usr/bin
WPACLI=wpa_cli
case "$1" in
suspend|hibernate)
$WPACLI suspend
;;
resume|thaw)
$WPACLI resume
;;
esac
exit 0
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/python
import dbus
import sys
import time
import gobject
from dbus.mainloop.glib import DBusGMainLoop
WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
def usage():
print "Usage: %s <ifname>" % sys.argv[0]
print "Press Ctrl-C to stop"
def ProbeRequest(args):
if 'addr' in args:
print '%.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['addr']),
if 'dst' in args:
print '-> %.2x:%.2x:%.2x:%.2x:%.2x:%.2x' % tuple(args['dst']),
if 'bssid' in args:
print '(bssid %.2x:%.2x:%.2x:%.2x:%.2x:%.2x)' % tuple(args['dst']),
if 'signal' in args:
print 'signal:%d' % args['signal'],
if 'ies' in args:
print 'have IEs (%d bytes)' % len(args['ies']),
print ''
if __name__ == "__main__":
global bus
global wpas_obj
global if_obj
global p2p_iface
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
# Print list of i/f if no one is specified
if (len(sys.argv) < 2) :
usage()
sys.exit(0)
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
ifname = sys.argv[1]
path = wpas.GetInterface(ifname)
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
bus.add_signal_receiver(ProbeRequest,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="ProbeRequest")
iface.SubscribeProbeReq()
gobject.MainLoop().run()
+13
View File
@@ -0,0 +1,13 @@
# IEEE 802.1X with dynamic WEP keys using EAP-PEAP/MSCHAPv2
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="example 802.1x network"
key_mgmt=IEEE8021X
eap=PEAP
phase2="auth=MSCHAPV2"
identity="user name"
password="password"
ca_cert="/etc/cert/ca.pem"
}
@@ -0,0 +1,41 @@
# EAP-TLS using private key and certificates via OpenSSL PKCS#11 engine and
# openCryptoki (e.g., with TPM token)
# This example uses following PKCS#11 objects:
# $ pkcs11-tool --module /usr/lib/opencryptoki/libopencryptoki.so -O -l
# Please enter User PIN:
# Private Key Object; RSA
# label: rsakey
# ID: 04
# Usage: decrypt, sign, unwrap
# Certificate Object, type = X.509 cert
# label: ca
# ID: 01
# Certificate Object, type = X.509 cert
# label: cert
# ID: 04
# Configure OpenSSL to load the PKCS#11 engine and openCryptoki module
pkcs11_engine_path=/usr/lib/engines/engine_pkcs11.so
pkcs11_module_path=/usr/lib/opencryptoki/libopencryptoki.so
network={
ssid="test network"
key_mgmt=WPA-EAP
eap=TLS
identity="User"
# use OpenSSL PKCS#11 engine for this network
engine=1
engine_id="pkcs11"
# select the private key and certificates based on ID (see pkcs11-tool
# output above)
key_id="4"
cert_id="4"
ca_cert_id="1"
# set the PIN code; leave this out to configure the PIN to be requested
# interactively when needed (e.g., via wpa_gui or wpa_cli)
pin="123456"
}
+69
View File
@@ -0,0 +1,69 @@
#!/bin/sh
IFNAME=$1
CMD=$2
kill_daemon() {
NAME=$1
PF=$2
if [ ! -r $PF ]; then
return
fi
PID=`cat $PF`
if [ $PID -gt 0 ]; then
if ps $PID | grep -q $NAME; then
kill $PID
fi
fi
rm $PF
}
if [ "$CMD" = "P2P-GROUP-STARTED" ]; then
GIFNAME=$3
if [ "$4" = "GO" ]; then
kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
ifconfig $GIFNAME 192.168.42.1 up
udhcpd /etc/udhcpd-p2p.conf
fi
if [ "$4" = "client" ]; then
kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
kill_daemon udhcpd /var/run/udhcpd-$GIFNAME.pid
udhcpc -i $GIFNAME -p /var/run/udhcpc-$GIFNAME.pid \
-s /etc/udhcpc.script
fi
fi
if [ "$CMD" = "P2P-GROUP-REMOVED" ]; then
GIFNAME=$3
if [ "$4" = "GO" ]; then
kill_daemon udhcpd /var/run/udhcpd-$GIFNAME.pid
ifconfig $GIFNAME 0.0.0.0
fi
if [ "$4" = "client" ]; then
kill_daemon udhcpc /var/run/udhcpc-$GIFNAME.pid
ifconfig $GIFNAME 0.0.0.0
fi
fi
if [ "$CMD" = "P2P-CROSS-CONNECT-ENABLE" ]; then
GIFNAME=$3
UPLINK=$4
# enable NAT/masquarade $GIFNAME -> $UPLINK
iptables -P FORWARD DROP
iptables -t nat -A POSTROUTING -o $UPLINK -j MASQUERADE
iptables -A FORWARD -i $UPLINK -o $GIFNAME -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $GIFNAME -o $UPLINK -j ACCEPT
sysctl net.ipv4.ip_forward=1
fi
if [ "$CMD" = "P2P-CROSS-CONNECT-DISABLE" ]; then
GIFNAME=$3
UPLINK=$4
# disable NAT/masquarade $GIFNAME -> $UPLINK
sysctl net.ipv4.ip_forward=0
iptables -t nat -D POSTROUTING -o $UPLINK -j MASQUERADE
iptables -D FORWARD -i $UPLINK -o $GIFNAME -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -D FORWARD -i $GIFNAME -o $UPLINK -j ACCEPT
fi
+83
View File
@@ -0,0 +1,83 @@
#!/bin/sh
IFNAME=$1
CMD=$2
kill_daemon() {
NAME=$1
PF=$2
if [ ! -r $PF ]; then
return
fi
PID=`cat $PF`
if [ $PID -gt 0 ]; then
if ps $PID | grep -q $NAME; then
kill $PID
fi
fi
rm $PF
}
if [ "$CMD" = "P2P-GROUP-STARTED" ]; then
GIFNAME=$3
if [ "$4" = "GO" ]; then
kill_daemon dhclient /var/run/dhclient-$GIFNAME.pid
rm /var/run/dhclient.leases-$GIFNAME
kill_daemon dnsmasq /var/run/dnsmasq.pid-$GIFNAME
ifconfig $GIFNAME 192.168.42.1 up
if ! dnsmasq -x /var/run/dnsmasq.pid-$GIFNAME \
-i $GIFNAME \
-F192.168.42.11,192.168.42.99; then
# another dnsmasq instance may be running and blocking us; try to
# start with -z to avoid that
dnsmasq -x /var/run/dnsmasq.pid-$GIFNAME \
-i $GIFNAME \
-F192.168.42.11,192.168.42.99 --listen-address 192.168.42.1 -z
fi
fi
if [ "$4" = "client" ]; then
kill_daemon dhclient /var/run/dhclient-$GIFNAME.pid
rm /var/run/dhclient.leases-$GIFNAME
kill_daemon dnsmasq /var/run/dnsmasq.pid-$GIFNAME
dhclient -pf /var/run/dhclient-$GIFNAME.pid \
-lf /var/run/dhclient.leases-$GIFNAME \
-nw \
$GIFNAME
fi
fi
if [ "$CMD" = "P2P-GROUP-REMOVED" ]; then
GIFNAME=$3
if [ "$4" = "GO" ]; then
kill_daemon dnsmasq /var/run/dnsmasq.pid-$GIFNAME
ifconfig $GIFNAME 0.0.0.0
fi
if [ "$4" = "client" ]; then
kill_daemon dhclient /var/run/dhclient-$GIFNAME.pid
rm /var/run/dhclient.leases-$GIFNAME
ifconfig $GIFNAME 0.0.0.0
fi
fi
if [ "$CMD" = "P2P-CROSS-CONNECT-ENABLE" ]; then
GIFNAME=$3
UPLINK=$4
# enable NAT/masquarade $GIFNAME -> $UPLINK
iptables -P FORWARD DROP
iptables -t nat -A POSTROUTING -o $UPLINK -j MASQUERADE
iptables -A FORWARD -i $UPLINK -o $GIFNAME -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i $GIFNAME -o $UPLINK -j ACCEPT
sysctl net.ipv4.ip_forward=1
fi
if [ "$CMD" = "P2P-CROSS-CONNECT-DISABLE" ]; then
GIFNAME=$3
UPLINK=$4
# disable NAT/masquarade $GIFNAME -> $UPLINK
sysctl net.ipv4.ip_forward=0
iptables -t nat -D POSTROUTING -o $UPLINK -j MASQUERADE
iptables -D FORWARD -i $UPLINK -o $GIFNAME -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -D FORWARD -i $GIFNAME -o $UPLINK -j ACCEPT
fi
@@ -0,0 +1,299 @@
#!/usr/bin/python
# Tests p2p_connect
# Will try to connect to another peer
# and form a group
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import getopt
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> -m <wps_method> \ " \
% sys.argv[0]
print " -a <addr> [-p <pin>] [-g <go_intent>] \ "
print " [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -m = wps method"
print " -a = peer address"
print " -p = pin number (8 digits)"
print " -g = group owner intent"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i wlan0 -a 0015008352c0 -m display -p 12345670" % sys.argv[0]
# Required Signals
def GONegotiationSuccess(status):
print "Go Negotiation Success"
def GONegotiationFailure(status):
print 'Go Negotiation Failed. Status:'
print format(status)
os._exit(0)
def GroupStarted(properties):
if properties.has_key("group_object"):
print 'Group Formation Complete %s' \
% properties["group_object"]
os._exit(0)
def WpsFailure(status, etc):
print "WPS Authentication Failure".format(status)
print etc
os._exit(0)
class P2P_Connect():
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global ifname
global wpas
global wpas_dbus_interface
global timeout
global path
global wps_method
global go_intent
global addr
global pin
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Dictionary of Arguements
global p2p_connect_arguements
# Constructor
def __init__(self,ifname,wpas_dbus_interface,addr,
pin,wps_method,go_intent):
# Initializes variables and threads
self.ifname = ifname
self.wpas_dbus_interface = wpas_dbus_interface
self.wps_method = wps_method
self.go_intent = go_intent
self.addr = addr
self.pin = pin
# Generating interface/object paths
self.wpas_dbus_opath = \
"/" + self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = \
self.wpas_dbus_opath + "/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface + ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(
self.wpas_object, self.wpas_dbus_interface)
# See if wpa_supplicant already knows about this interface
self.path = None
try:
self.path = self.wpas.GetInterface(ifname)
except:
if not str(exc).startswith(
self.wpas_dbus_interface + \
".InterfaceUnknown:"):
raise exc
try:
path = self.wpas.CreateInterface(
{'Ifname': ifname, 'Driver': 'test'})
time.sleep(1)
except dbus.DBusException, exc:
if not str(exc).startswith(
self.wpas_dbus_interface + \
".InterfaceExists:"):
raise exc
# Get Interface and objects
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface,self.path)
self.p2p_interface = dbus.Interface(
self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
# Add signals
self.bus.add_signal_receiver(GONegotiationSuccess,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="GONegotiationSuccess")
self.bus.add_signal_receiver(GONegotiationFailure,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="GONegotiationFailure")
self.bus.add_signal_receiver(GroupStarted,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="GroupStarted")
self.bus.add_signal_receiver(WpsFailure,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="WpsFailed")
#Constructing all the arguements needed to connect
def constructArguements(self):
# Adding required arguements
self.p2p_connect_arguements = {'wps_method':self.wps_method,
'peer':dbus.ObjectPath(self.path+'/Peers/'+self.addr)}
# Display requires a pin, and a go intent of 15
if (self.wps_method == 'display'):
if (self.pin != None):
self.p2p_connect_arguements.update({'pin':self.pin})
else:
print "Error:\n Pin required for wps_method=display"
usage()
quit()
if (self.go_intent != None and int(self.go_intent) != 15):
print "go_intent overwritten to 15"
self.go_intent = '15'
# Keypad requires a pin, and a go intent of less than 15
elif (self.wps_method == 'keypad'):
if (self.pin != None):
self.p2p_connect_arguements.update({'pin':self.pin})
else:
print "Error:\n Pin required for wps_method=keypad"
usage()
quit()
if (self.go_intent != None and int(self.go_intent) == 15):
error = "Error :\n Group Owner intent cannot be" + \
" 15 for wps_method=keypad"
print error
usage()
quit()
# Doesn't require pin
# for ./wpa_cli, p2p_connect [mac] [pin#], wps_method=keypad
elif (self.wps_method == 'pin'):
if (self.pin != None):
print "pin ignored"
# No pin is required for pbc so it is ignored
elif (self.wps_method == 'pbc'):
if (self.pin != None):
print "pin ignored"
else:
print "Error:\n wps_method not supported or does not exist"
usage()
quit()
# Go_intent is optional for all arguements
if (self.go_intent != None):
self.p2p_connect_arguements.update(
{'go_intent':dbus.Int32(self.go_intent)})
# Running p2p_connect
def run(self):
try:
result_pin = self.p2p_interface.Connect(
self.p2p_connect_arguements)
except dbus.DBusException, exc:
raise exc
if (self.wps_method == 'pin' and \
not self.p2p_connect_arguements.has_key('pin') ):
print "Connect return with pin value of %d " % int(result_pin)
gobject.MainLoop().run()
if __name__ == "__main__":
# Required
interface_name = None
wps_method = None
addr = None
# Conditionally optional
pin = None
# Optional
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
go_intent = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"hi:m:a:p:g:w:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
# WPS Method
elif (key == "-m"):
wps_method = value
# Address
elif (key == "-a"):
addr = value
# Pin
elif (key == "-p"):
pin = value
# Group Owner Intent
elif (key == "-g"):
go_intent = value
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Required Arguements check
if (interface_name == None or wps_method == None or addr == None):
print "Error:\n Required arguements not specified"
usage()
quit()
# Group Owner Intent Check
if (go_intent != None and (int(go_intent) > 15 or int(go_intent) < 0) ):
print "Error:\n Group Owner Intent must be between 0 and 15 inclusive"
usage()
quit()
# Pin Check
if (pin != None and len(pin) != 8):
print "Error:\n Pin is not 8 digits"
usage()
quit()
try:
p2p_connect_test = P2P_Connect(interface_name,wpas_dbus_interface,
addr,pin,wps_method,go_intent)
except:
print "Error:\n Invalid Arguements"
usage()
quit()
p2p_connect_test.constructArguements()
p2p_connect_test.run()
os._exit(0)
@@ -0,0 +1,169 @@
#!/usr/bin/python
# Tests P2P_Disconnect
# Will perform disconnect on interface_name
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import threading
import getopt
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> \ " \
% sys.argv[0]
print " [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i p2p-wlan0-0" % sys.argv[0]
# Required Signals
def GroupFinished(status, etc):
print "Disconnected"
os._exit(0)
class P2P_Disconnect (threading.Thread):
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global interface_name
global wpas
global wpas_dbus_interface
global path
global timeout
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Constructor
def __init__(self,interface_name,wpas_dbus_interface,timeout):
# Initializes variables and threads
self.interface_name = interface_name
self.wpas_dbus_interface = wpas_dbus_interface
self.timeout = timeout
# Initializes thread and daemon allows for ctrl-c kill
threading.Thread.__init__(self)
self.daemon = True
# Generating interface/object paths
self.wpas_dbus_opath = "/" + \
self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = self.wpas_dbus_opath + \
"/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface \
+ ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(self.wpas_object,
self.wpas_dbus_interface)
# Try to see if supplicant knows about interface
# If not, throw an exception
try:
self.path = self.wpas.GetInterface(
self.interface_name)
except dbus.DBusException, exc:
error = 'Error:\n Interface ' + self.interface_name \
+ ' was not found'
print error
usage()
os._exit(0)
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface, self.path)
self.p2p_interface = dbus.Interface(self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
# Signals
self.bus.add_signal_receiver(GroupFinished,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="GroupFinished")
# Runs p2p_disconnect
def run(self):
# Allows other threads to keep working while MainLoop runs
# Required for timeout implementation
gobject.MainLoop().get_context().iteration(True)
gobject.threads_init()
self.p2p_interface.Disconnect()
gobject.MainLoop().run()
if __name__ == "__main__":
timeout = 5
# Defaults for optional inputs
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
# interface_name is required
interface_name = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"hi:w:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Interface name is required and was not given
if (interface_name == None):
print "Error:\n interface_name is required"
usage()
quit()
# Constructor
try:
p2p_disconnect_test = P2P_Disconnect(interface_name,
wpas_dbus_interface,timeout)
except:
print "Error:\n Invalid wpas_dbus_interface"
usage()
quit()
# Start P2P_Disconnect
p2p_disconnect_test.start()
try:
time.sleep(int(p2p_disconnect_test.timeout))
except:
pass
print "Disconnect timed out"
quit()
+192
View File
@@ -0,0 +1,192 @@
#!/usr/bin/python
# Tests p2p_find
# Will list all devices found/lost within a time frame (timeout)
# Then Program will exit
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import threading
import getopt
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> [-t <timeout>] \ " \
% sys.argv[0]
print " [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -t = timeout = 0s (infinite)"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i wlan0 -t 10" % sys.argv[0]
# Required Signals
def deviceFound(devicepath):
print "Device found: %s" % (devicepath)
def deviceLost(devicepath):
print "Device lost: %s" % (devicepath)
class P2P_Find (threading.Thread):
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global interface_name
global wpas
global wpas_dbus_interface
global timeout
global path
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Constructor
def __init__(self,interface_name,wpas_dbus_interface,timeout):
# Initializes variables and threads
self.timeout = int(timeout)
self.interface_name = interface_name
self.wpas_dbus_interface = wpas_dbus_interface
# Initializes thread and daemon allows for ctrl-c kill
threading.Thread.__init__(self)
self.daemon = True
# Generating interface/object paths
self.wpas_dbus_opath = "/" + \
self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = self.wpas_dbus_opath + \
"/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface \
+ ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(self.wpas_object,
self.wpas_dbus_interface)
# Try to see if supplicant knows about interface
# If not, throw an exception
try:
self.path = self.wpas.GetInterface(
self.interface_name)
except dbus.DBusException, exc:
error = 'Error:\n Interface ' + self.interface_name \
+ ' was not found'
print error
usage()
os._exit(0)
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface, self.path)
self.p2p_interface = dbus.Interface(self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
#Adds listeners for find and lost
self.bus.add_signal_receiver(deviceFound,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="DeviceFound")
self.bus.add_signal_receiver(deviceLost,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="DeviceLost")
# Sets up p2p_find
P2PFindDict = dbus.Dictionary(
{'Timeout':int(self.timeout)})
self.p2p_interface.Find(P2PFindDict)
# Run p2p_find
def run(self):
# Allows other threads to keep working while MainLoop runs
# Required for timeout implementation
gobject.MainLoop().get_context().iteration(True)
gobject.threads_init()
gobject.MainLoop().run()
if __name__ == "__main__":
# Defaults for optional inputs
timeout = 0
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
# interface_name is required
interface_name = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"hi:t:w:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
# Timeout
elif (key == "-t"):
if ( int(value) >= 0):
timeout = value
else:
print "Error:\n Timeout cannot be negative"
usage()
quit()
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Interface name is required and was not given
if (interface_name == None):
print "Error:\n interface_name is required"
usage()
quit()
# Constructor
try:
p2p_find_test = P2P_Find(interface_name, wpas_dbus_interface, timeout)
except:
print "Error:\n Invalid wpas_dbus_interface"
usage()
quit()
# Start P2P_Find
p2p_find_test.start()
try:
# If timeout is 0, then run forever
if (timeout == 0):
while(True):
pass
# Else sleep for (timeout)
else:
time.sleep(p2p_find_test.timeout)
except:
pass
quit()
+168
View File
@@ -0,0 +1,168 @@
#!/usr/bin/python
# Tests P2P_Flush
# Will flush the p2p interface
# Then Program will exit
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import threading
import getopt
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> \ " \
% sys.argv[0]
print " [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i wlan0" % sys.argv[0]
# Required Signals\
def deviceLost(devicepath):
print "Device lost: %s" % (devicepath)
class P2P_Flush (threading.Thread):
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global interface_name
global wpas
global wpas_dbus_interface
global path
global timeout
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Constructor
def __init__(self,interface_name,wpas_dbus_interface,timeout):
# Initializes variables and threads
self.interface_name = interface_name
self.wpas_dbus_interface = wpas_dbus_interface
self.timeout = timeout
# Initializes thread and daemon allows for ctrl-c kill
threading.Thread.__init__(self)
self.daemon = True
# Generating interface/object paths
self.wpas_dbus_opath = "/" + \
self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = self.wpas_dbus_opath + \
"/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface \
+ ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(self.wpas_object,
self.wpas_dbus_interface)
# Try to see if supplicant knows about interface
# If not, throw an exception
try:
self.path = self.wpas.GetInterface(
self.interface_name)
except dbus.DBusException, exc:
error = 'Error:\n Interface ' + self.interface_name \
+ ' was not found'
print error
usage()
os._exit(0)
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface, self.path)
self.p2p_interface = dbus.Interface(self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
# Signals
self.bus.add_signal_receiver(deviceLost,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="DeviceLost")
# Runs p2p_flush
def run(self):
# Allows other threads to keep working while MainLoop runs
# Required for timeout implementation
gobject.MainLoop().get_context().iteration(True)
gobject.threads_init()
self.p2p_interface.Flush()
gobject.MainLoop().run()
if __name__ == "__main__":
# Needed to show which devices were lost
timeout = 5
# Defaults for optional inputs
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
# interface_name is required
interface_name = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"hi:w:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Interface name is required and was not given
if (interface_name == None):
print "Error:\n interface_name is required"
usage()
quit()
# Constructor
try:
p2p_flush_test = P2P_Flush(interface_name, wpas_dbus_interface,timeout)
except:
print "Error:\n Invalid wpas_dbus_interface"
usage()
quit()
# Start P2P_Find
p2p_flush_test.start()
try:
time.sleep(int(p2p_flush_test.timeout))
except:
pass
print "p2p_flush complete"
quit()
@@ -0,0 +1,222 @@
#!/usr/bin/python
# Tests p2p_group_add
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import getopt
import threading
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> [-p <persistent>] \ " \
% sys.argv[0]
print " [-f <frequency>] [-o <group_object_path>] \ "
print " [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -p = persistant group = 0 (0=false, 1=true)"
print " -f = frequency"
print " -o = persistent group object path"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i wlan0" % sys.argv[0]
# Required Signals
def GroupStarted(properties):
if properties.has_key("group_object"):
print 'Group Formation Complete %s' \
% properties["group_object"]
os._exit(0)
def WpsFailure(status, etc):
print "WPS Authentication Failure".format(status)
print etc
os._exit(0)
class P2P_Group_Add (threading.Thread):
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global interface_name
global wpas
global wpas_dbus_interface
global path
global persistent
global frequency
global persistent_group_object
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Arguements
global P2PDictionary
# Constructor
def __init__(self,interface_name,wpas_dbus_interface,persistent,frequency,
persistent_group_object):
# Initializes variables and threads
self.interface_name = interface_name
self.wpas_dbus_interface = wpas_dbus_interface
self.persistent = persistent
self.frequency = frequency
self.persistent_group_object = persistent_group_object
# Initializes thread and daemon allows for ctrl-c kill
threading.Thread.__init__(self)
self.daemon = True
# Generating interface/object paths
self.wpas_dbus_opath = "/" + \
self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = self.wpas_dbus_opath + \
"/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface \
+ ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(self.wpas_object,
self.wpas_dbus_interface)
# Try to see if supplicant knows about interface
# If not, throw an exception
try:
self.path = self.wpas.GetInterface(
self.interface_name)
except dbus.DBusException, exc:
error = 'Error:\n Interface ' + self.interface_name \
+ ' was not found'
print error
usage()
os._exit(0)
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface, self.path)
self.p2p_interface = dbus.Interface(self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
#Adds listeners
self.bus.add_signal_receiver(GroupStarted,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="GroupStarted")
self.bus.add_signal_receiver(WpsFailure,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="WpsFailed")
# Sets up p2p_group_add dictionary
def constructArguements(self):
self.P2PDictionary = {'persistent':self.persistent}
if (self.frequency != None):
if (int(self.frequency) > 0):
self.P2PDictionary.update({'frequency':int(self.frequency)})
else:
print "Error:\n Frequency must be greater than 0"
usage()
os._exit(0)
if (self.persistent_group_object != None):
self.P2PDictionary.update({'persistent_group_object':
self.persistent_group_object})
# Run p2p_group_remove
def run(self):
try:
self.p2p_interface.GroupAdd(self.P2PDictionary)
except:
print "Error:\n Could not preform group add"
usage()
os._exit(0)
# Allows other threads to keep working while MainLoop runs
# Required for timeout implementation
gobject.MainLoop().get_context().iteration(True)
gobject.threads_init()
gobject.MainLoop().run()
if __name__ == "__main__":
# Defaults for optional inputs
# 0 = false, 1 = true
persistent = False
frequency = None
persistent_group_object = None
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
# interface_name is required
interface_name = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"hi:p:f:o:w:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
# Timeout
elif (key == "-p"):
if (value == '0'):
persistent = False
elif (value == '1'):
persistent = True
else:
print "Error:\n Persistent can only be 1 or 0"
usage()
os._exit(0)
# Frequency
elif (key == "-f"):
frequency = value
# Persistent group object path
elif (key == "-o"):
persistent_group_object = value
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Interface name is required and was not given
if (interface_name == None):
print "Error:\n interface_name is required"
usage()
quit()
try:
p2p_group_add_test = P2P_Group_Add(interface_name,wpas_dbus_interface,
persistent,frequency,persistent_group_object)
except:
print "Error:\n Invalid Arguements"
p2p_group_add_test.constructArguements()
p2p_group_add_test.start()
time.sleep(5)
print "Error:\n Group formation timed out"
os._exit(0)
@@ -0,0 +1,201 @@
#!/usr/bin/python
# Tests p2p_invite
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import getopt
import threading
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> -a <addr> \ " \
% sys.argv[0]
print " [-o <persistent_group_object>] [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -a = address of peer"
print " -o = persistent group object path"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i p2p-wlan0-0 -a 00150083523c" % sys.argv[0]
# Required Signals
def InvitationResult(invite_result):
print "Inviation Result signal :"
status = invite_result['status']
print "status = ", status
if invite_result.has_key('BSSID'):
bssid = invite_result['BSSID']
print "BSSID = ", hex(bssid[0]) , ":" , \
hex(bssid[1]) , ":" , hex(bssid[2]) , ":", \
hex(bssid[3]) , ":" , hex(bssid[4]) , ":" , \
hex(bssid[5])
os._exit(0)
class P2P_Invite (threading.Thread):
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global interface_name
global wpas
global wpas_dbus_interface
global path
global addr
global persistent_group_object
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Arguements
global P2PDictionary
# Constructor
def __init__(self,interface_name,wpas_dbus_interface,addr,
persistent_group_object):
# Initializes variables and threads
self.interface_name = interface_name
self.wpas_dbus_interface = wpas_dbus_interface
self.addr = addr
self.persistent_group_object = persistent_group_object
# Initializes thread and daemon allows for ctrl-c kill
threading.Thread.__init__(self)
self.daemon = True
# Generating interface/object paths
self.wpas_dbus_opath = "/" + \
self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = self.wpas_dbus_opath + \
"/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface \
+ ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(self.wpas_object,
self.wpas_dbus_interface)
# Try to see if supplicant knows about interface
# If not, throw an exception
try:
self.path = self.wpas.GetInterface(
self.interface_name)
except dbus.DBusException, exc:
error = 'Error:\n Interface ' + self.interface_name \
+ ' was not found'
print error
usage()
os._exit(0)
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface, self.path)
self.p2p_interface = dbus.Interface(self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
#Adds listeners
self.bus.add_signal_receiver(InvitationResult,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="InvitationResult")
# Sets up p2p_invite dictionary
def constructArguements(self):
self.P2PDictionary = \
{'peer':dbus.ObjectPath(self.path+'/Peers/'+self.addr)}
if (self.persistent_group_object != None):
self.P2PDictionary.update({"persistent_group_object":
self.persistent_group_object})
# Run p2p_invite
def run(self):
try:
self.p2p_interface.Invite(self.P2PDictionary)
except:
print "Error:\n Invalid Arguements"
usage()
os._exit(0)
# Allows other threads to keep working while MainLoop runs
# Required for timeout implementation
gobject.MainLoop().get_context().iteration(True)
gobject.threads_init()
gobject.MainLoop().run()
if __name__ == "__main__":
# Defaults for optional inputs
addr = None
persistent_group_object = None
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
# interface_name is required
interface_name = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"hi:o:w:a:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
elif (key == "-a"):
addr = value
# Persistent group object path
elif (key == "-o"):
persistent_group_object = value
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Interface name is required and was not given
if (interface_name == None):
print "Error:\n interface_name is required"
usage()
quit()
if (addr == None):
print "Error:\n peer address is required"
usage()
quit()
try:
p2p_invite_test = \
P2P_Invite(interface_name,wpas_dbus_interface,
addr,persistent_group_object)
except:
print "Error:\n Invalid Arguements"
usage()
os._exit(1)
p2p_invite_test.constructArguements()
p2p_invite_test.start()
time.sleep(10)
print "Error:\n p2p_invite timed out"
os._exit(0)
@@ -0,0 +1,182 @@
#!/usr/bin/python
# Tests P2P_Find
# Will listen
# Then Program will exit
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import threading
import getopt
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> [-t <timeout>] \ " \
% sys.argv[0]
print " [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -t = timeout = 0s (infinite)"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i wlan0 -t 5" % sys.argv[0]
# Required Signals
def p2pStateChange(status):
print status
class P2P_Listen(threading.Thread):
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global interface_name
global wpas
global wpas_dbus_interface
global path
global timeout
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Constructor
def __init__(self,interface_name,wpas_dbus_interface,timeout):
# Initializes variables and threads
self.timeout = int(timeout)
self.interface_name = interface_name
self.wpas_dbus_interface = wpas_dbus_interface
# Initializes thread and daemon allows for ctrl-c kill
threading.Thread.__init__(self)
self.daemon = True
# Generating interface/object paths
self.wpas_dbus_opath = "/" + \
self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = self.wpas_dbus_opath + \
"/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface \
+ ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(self.wpas_object,
self.wpas_dbus_interface)
# Try to see if supplicant knows about interface
# If not, throw an exception
try:
self.path = self.wpas.GetInterface(
self.interface_name)
except dbus.DBusException, exc:
error = 'Error:\n Interface ' + self.interface_name \
+ ' was not found'
print error
usage()
os._exit(0)
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface, self.path)
self.p2p_interface = dbus.Interface(self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
self.bus.add_signal_receiver(p2pStateChange,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="P2PStateChanged")
# Run p2p_find
def run(self):
# Sets up p2p_listen
self.p2p_interface.Listen(int(self.timeout))
# Allows other threads to keep working while MainLoop runs
# Required for timeout implementation
gobject.MainLoop().get_context().iteration(True)
gobject.threads_init()
gobject.MainLoop().run()
if __name__ == "__main__":
# Defaults for optional inputs
timeout = 0
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
# interface_name is required
interface_name = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"hi:t:w:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
# Timeout
elif (key == "-t"):
if ( int(value) >= 0):
timeout = value
else:
print "Error:\n Timeout cannot be negative"
usage()
quit()
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Interface name is required and was not given
if (interface_name == None):
print "Error:\n interface_name is required"
usage()
quit()
# Constructor
try:
p2p_listen_test = P2P_Listen(interface_name, wpas_dbus_interface, timeout)
except:
print "Error:\n Invalid wpas_dbus_interface"
usage()
quit()
# Start P2P_Find
p2p_listen_test.start()
try:
# If timeout is 0, then run forever
if (int(p2p_listen_test.timeout) == 0):
while(True):
pass
# Else sleep for (timeout)
else:
time.sleep(int(p2p_listen_test.timeout))
except:
pass
quit()
@@ -0,0 +1,174 @@
#!/usr/bin/python
# Tests p2p_stop_find
######### MAY NEED TO RUN AS SUDO #############
import dbus
import sys, os
import time
import gobject
import threading
import getopt
from dbus.mainloop.glib import DBusGMainLoop
def usage():
print "Usage:"
print " %s -i <interface_name> \ " \
% sys.argv[0]
print " [-w <wpas_dbus_interface>]"
print "Options:"
print " -i = interface name"
print " -w = wpas dbus interface = fi.w1.wpa_supplicant1"
print "Example:"
print " %s -i wlan0" % sys.argv[0]
# Required Signals
def deviceLost(devicepath):
print "Device lost: %s" % (devicepath)
def p2pStateChange(status):
print status
os._exit(0)
class P2P_Stop_Find (threading.Thread):
# Needed Variables
global bus
global wpas_object
global interface_object
global p2p_interface
global interface_name
global wpas
global wpas_dbus_interface
global path
global timeout
# Dbus Paths
global wpas_dbus_opath
global wpas_dbus_interfaces_opath
global wpas_dbus_interfaces_interface
global wpas_dbus_interfaces_p2pdevice
# Constructor
def __init__(self,interface_name,wpas_dbus_interface,timeout):
# Initializes variables and threads
self.interface_name = interface_name
self.wpas_dbus_interface = wpas_dbus_interface
self.timeout = timeout
# Initializes thread and daemon allows for ctrl-c kill
threading.Thread.__init__(self)
self.daemon = True
# Generating interface/object paths
self.wpas_dbus_opath = "/" + \
self.wpas_dbus_interface.replace(".","/")
self.wpas_wpas_dbus_interfaces_opath = self.wpas_dbus_opath + \
"/Interfaces"
self.wpas_dbus_interfaces_interface = \
self.wpas_dbus_interface + ".Interface"
self.wpas_dbus_interfaces_p2pdevice = \
self.wpas_dbus_interfaces_interface \
+ ".P2PDevice"
# Getting interfaces and objects
DBusGMainLoop(set_as_default=True)
self.bus = dbus.SystemBus()
self.wpas_object = self.bus.get_object(
self.wpas_dbus_interface,
self.wpas_dbus_opath)
self.wpas = dbus.Interface(self.wpas_object,
self.wpas_dbus_interface)
# Try to see if supplicant knows about interface
# If not, throw an exception
try:
self.path = self.wpas.GetInterface(
self.interface_name)
except dbus.DBusException, exc:
error = 'Error:\n Interface ' + self.interface_name \
+ ' was not found'
print error
usage()
os._exit(0)
self.interface_object = self.bus.get_object(
self.wpas_dbus_interface, self.path)
self.p2p_interface = dbus.Interface(self.interface_object,
self.wpas_dbus_interfaces_p2pdevice)
# Signals
self.bus.add_signal_receiver(deviceLost,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="DeviceLost")
self.bus.add_signal_receiver(p2pStateChange,
dbus_interface=self.wpas_dbus_interfaces_p2pdevice,
signal_name="P2PStateChanged")
# Runs p2p_stop_find
def run(self):
# Allows other threads to keep working while MainLoop runs
# Required for timeout implementation
gobject.MainLoop().get_context().iteration(True)
gobject.threads_init()
self.p2p_interface.StopFind()
gobject.MainLoop().run()
if __name__ == "__main__":
# Needed because P2PStateChanged signal is not caught
timeout = 5
# Defaults for optional inputs
wpas_dbus_interface = 'fi.w1.wpa_supplicant1'
# interface_name is required
interface_name = None
# Using getopts to handle options
try:
options, args = getopt.getopt(sys.argv[1:],"ht:i:w:")
except getopt.GetoptError:
usage()
quit()
# If theres a switch, override default option
for key, value in options:
# Help
if (key == "-h"):
usage()
quit()
# Interface Name
elif (key == "-i"):
interface_name = value
# Dbus interface
elif (key == "-w"):
wpas_dbus_interface = value
else:
assert False, "unhandled option"
# Interface name is required and was not given
if (interface_name == None):
print "Error:\n interface_name is required"
usage()
quit()
# Constructor
try:
p2p_stop_find_test = P2P_Stop_Find(interface_name,
wpas_dbus_interface,timeout)
except:
print "Error:\n Invalid wpas_dbus_interface"
usage()
quit()
# Start P2P_Find
p2p_stop_find_test.start()
try:
time.sleep(int(p2p_stop_find_test.timeout))
except:
pass
print "p2p find stopped"
quit()
@@ -0,0 +1,8 @@
# Plaintext (no encryption) network
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="example open network"
key_mgmt=NONE
}
+120
View File
@@ -0,0 +1,120 @@
# Sample udhcpd configuration file (/etc/udhcpd.conf)
# The start and end of the IP lease block
start 192.168.42.20 #default: 192.168.0.20
end 192.168.42.254 #default: 192.168.0.254
# The interface that udhcpd will use
interface wlan2 #default: eth0
# The maximim number of leases (includes addressesd reserved
# by OFFER's, DECLINE's, and ARP conficts
#max_leases 254 #default: 254
# If remaining is true (default), udhcpd will store the time
# remaining for each lease in the udhcpd leases file. This is
# for embedded systems that cannot keep time between reboots.
# If you set remaining to no, the absolute time that the lease
# expires at will be stored in the dhcpd.leases file.
#remaining yes #default: yes
# The time period at which udhcpd will write out a dhcpd.leases
# file. If this is 0, udhcpd will never automatically write a
# lease file. (specified in seconds)
#auto_time 7200 #default: 7200 (2 hours)
# The amount of time that an IP will be reserved (leased) for if a
# DHCP decline message is received (seconds).
#decline_time 3600 #default: 3600 (1 hour)
# The amount of time that an IP will be reserved (leased) for if an
# ARP conflct occurs. (seconds
#conflict_time 3600 #default: 3600 (1 hour)
# How long an offered address is reserved (leased) in seconds
#offer_time 60 #default: 60 (1 minute)
# If a lease to be given is below this value, the full lease time is
# instead used (seconds).
#min_lease 60 #defult: 60
# The location of the leases file
#lease_file /var/lib/misc/udhcpd.leases #defualt: /var/lib/misc/udhcpd.leases
# The location of the pid file
pidfile /var/run/udhcpd-wlan2.pid #default: /var/run/udhcpd.pid
# Every time udhcpd writes a leases file, the below script will be called.
# Useful for writing the lease file to flash every few hours.
#notify_file #default: (no script)
#notify_file dumpleases # <--- useful for debugging
# The following are bootp specific options, setable by udhcpd.
#siaddr 192.168.0.22 #default: 0.0.0.0
#sname zorak #default: (none)
#boot_file /var/nfs_root #default: (none)
# The remainer of options are DHCP options and can be specifed with the
# keyword 'opt' or 'option'. If an option can take multiple items, such
# as the dns option, they can be listed on the same line, or multiple
# lines. The only option with a default is 'lease'.
#Examles
opt dns 192.168.2.1
option subnet 255.255.255.0
option domain atherosowl.com
option lease 864000 # 10 days of seconds
# Currently supported options, for more info, see options.c
#opt subnet
#opt timezone
#opt router
#opt timesvr
#opt namesvr
#opt dns
#opt logsvr
#opt cookiesvr
#opt lprsvr
#opt bootsize
#opt domain
#opt swapsvr
#opt rootpath
#opt ipttl
#opt mtu
#opt broadcast
#opt wins
#opt lease
#opt ntpsrv
#opt tftp
#opt bootfile
# Static leases map
#static_lease 00:60:08:11:CE:4E 192.168.0.54
#static_lease 00:60:08:11:CE:3E 192.168.0.44
+11
View File
@@ -0,0 +1,11 @@
# Static WEP keys
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="example wep network"
key_mgmt=NONE
wep_key0="abcde"
wep_key1=0102030405
wep_tx_keyidx=0
}
@@ -0,0 +1,12 @@
# WPA-PSK/TKIP
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="example wpa-psk network"
key_mgmt=WPA-PSK
proto=WPA
pairwise=TKIP
group=TKIP
psk="secret passphrase"
}
@@ -0,0 +1,15 @@
# WPA2-EAP/CCMP using EAP-TLS
ctrl_interface=/var/run/wpa_supplicant
network={
ssid="example wpa2-eap network"
key_mgmt=WPA-EAP
proto=WPA2
pairwise=CCMP
group=CCMP
eap=TLS
ca_cert="/etc/cert/ca.pem"
private_key="/etc/cert/user.p12"
private_key_passwd="PKCS#12 passhrase"
}
@@ -0,0 +1,21 @@
# Only WPA-PSK is used. Any valid cipher combination is accepted.
ctrl_interface=/var/run/wpa_supplicant
network={
#Open
# ssid="example open network"
# key_mgmt=NONE
#WPA-PSK
ssid="QSoftAP"
proto=WPA
key_mgmt=WPA-PSK
pairwise=TKIP CCMP
group=TKIP CCMP
psk="1234567890"
#WEP
# ssid="example wep network"
# key_mgmt=NONE
# wep_key0="abcde"
# wep_key1=0102030405
# wep_tx_keyidx=0
}
+59
View File
@@ -0,0 +1,59 @@
#!/usr/bin/python
import dbus
import sys, os
import time
import gobject
def main():
bus = dbus.SystemBus()
wpas_obj = bus.get_object("fi.w1.wpa_supplicant1",
"/fi/w1/wpa_supplicant1")
props = wpas_obj.GetAll("fi.w1.wpa_supplicant1",
dbus_interface=dbus.PROPERTIES_IFACE)
print "GetAll(fi.w1.wpa_supplicant1, /fi/w1/wpa_supplicant1):"
print props
if len(sys.argv) != 2:
os._exit(1)
ifname = sys.argv[1]
wpas = dbus.Interface(wpas_obj, "fi.w1.wpa_supplicant1")
path = wpas.GetInterface(ifname)
if_obj = bus.get_object("fi.w1.wpa_supplicant1", path)
props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface",
dbus_interface=dbus.PROPERTIES_IFACE)
print
print "GetAll(fi.w1.wpa_supplicant1.Interface, %s):" % (path)
print props
props = if_obj.GetAll("fi.w1.wpa_supplicant1.Interface.WPS",
dbus_interface=dbus.PROPERTIES_IFACE)
print
print "GetAll(fi.w1.wpa_supplicant1.Interface.WPS, %s):" % (path)
print props
res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'BSSs',
dbus_interface=dbus.PROPERTIES_IFACE)
if len(res) > 0:
bss_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
props = bss_obj.GetAll("fi.w1.wpa_supplicant1.BSS",
dbus_interface=dbus.PROPERTIES_IFACE)
print
print "GetAll(fi.w1.wpa_supplicant1.BSS, %s):" % (res[0])
print props
res = if_obj.Get("fi.w1.wpa_supplicant1.Interface", 'Networks',
dbus_interface=dbus.PROPERTIES_IFACE)
if len(res) > 0:
net_obj = bus.get_object("fi.w1.wpa_supplicant1", res[0])
props = net_obj.GetAll("fi.w1.wpa_supplicant1.Network",
dbus_interface=dbus.PROPERTIES_IFACE)
print
print "GetAll(fi.w1.wpa_supplicant1.Network, %s):" % (res[0])
print props
if __name__ == "__main__":
main()
+203
View File
@@ -0,0 +1,203 @@
#!/usr/bin/python
import dbus
import sys, os
import time
import gobject
from dbus.mainloop.glib import DBusGMainLoop
WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
WPAS_DBUS_INTERFACES_OPATH = "/fi/w1/wpa_supplicant1/Interfaces"
WPAS_DBUS_BSS_INTERFACE = "fi.w1.wpa_supplicant1.BSS"
WPAS_DBUS_NETWORK_INTERFACE = "fi.w1.wpa_supplicant1.Network"
def byte_array_to_string(s):
import urllib
r = ""
for c in s:
if c >= 32 and c < 127:
r += "%c" % c
else:
r += urllib.quote(chr(c))
return r
def list_interfaces(wpas_obj):
ifaces = wpas_obj.Get(WPAS_DBUS_INTERFACE, 'Interfaces',
dbus_interface=dbus.PROPERTIES_IFACE)
for path in ifaces:
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
ifname = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'Ifname',
dbus_interface=dbus.PROPERTIES_IFACE)
print ifname
def interfaceAdded(interface, properties):
print "InterfaceAdded(%s): Ifname=%s" % (interface, properties['Ifname'])
def interfaceRemoved(interface):
print "InterfaceRemoved(%s)" % (interface)
def propertiesChanged(properties):
for i in properties:
print "PropertiesChanged: %s=%s" % (i, properties[i])
def showBss(bss):
net_obj = bus.get_object(WPAS_DBUS_SERVICE, bss)
net = dbus.Interface(net_obj, WPAS_DBUS_BSS_INTERFACE)
# Convert the byte-array for SSID and BSSID to printable strings
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'BSSID',
dbus_interface=dbus.PROPERTIES_IFACE)
bssid = ""
for item in val:
bssid = bssid + ":%02x" % item
bssid = bssid[1:]
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'SSID',
dbus_interface=dbus.PROPERTIES_IFACE)
ssid = byte_array_to_string(val)
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'WPA',
dbus_interface=dbus.PROPERTIES_IFACE)
wpa = "no"
if val != None:
wpa = "yes"
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'RSN',
dbus_interface=dbus.PROPERTIES_IFACE)
wpa2 = "no"
if val != None:
wpa2 = "yes"
freq = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Frequency',
dbus_interface=dbus.PROPERTIES_IFACE)
signal = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Signal',
dbus_interface=dbus.PROPERTIES_IFACE)
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Rates',
dbus_interface=dbus.PROPERTIES_IFACE)
if len(val) > 0:
maxrate = val[0] / 1000000
else:
maxrate = 0
print " %s :: ssid='%s' wpa=%s wpa2=%s signal=%d rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, signal, maxrate, freq)
def scanDone(success):
gobject.MainLoop().quit()
print "Scan done: success=%s" % success
def scanDone2(success, path=None):
print "Scan done: success=%s [path=%s]" % (success, path)
def bssAdded(bss, properties):
print "BSS added: %s" % (bss)
showBss(bss)
def bssRemoved(bss):
print "BSS removed: %s" % (bss)
def blobAdded(blob):
print "BlobAdded(%s)" % (blob)
def blobRemoved(blob):
print "BlobRemoved(%s)" % (blob)
def networkAdded(network, properties):
print "NetworkAdded(%s)" % (network)
def networkRemoved(network):
print "NetworkRemoved(%s)" % (network)
def networkSelected(network):
print "NetworkSelected(%s)" % (network)
def propertiesChangedInterface(properties):
for i in properties:
print "PropertiesChanged(interface): %s=%s" % (i, properties[i])
def propertiesChangedBss(properties):
for i in properties:
print "PropertiesChanged(BSS): %s=%s" % (i, properties[i])
def propertiesChangedNetwork(properties):
for i in properties:
print "PropertiesChanged(Network): %s=%s" % (i, properties[i])
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
global bus
bus = dbus.SystemBus()
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
if len(sys.argv) != 2:
list_interfaces(wpas_obj)
os._exit(1)
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
bus.add_signal_receiver(interfaceAdded,
dbus_interface=WPAS_DBUS_INTERFACE,
signal_name="InterfaceAdded")
bus.add_signal_receiver(interfaceRemoved,
dbus_interface=WPAS_DBUS_INTERFACE,
signal_name="InterfaceRemoved")
bus.add_signal_receiver(propertiesChanged,
dbus_interface=WPAS_DBUS_INTERFACE,
signal_name="PropertiesChanged")
ifname = sys.argv[1]
path = wpas.GetInterface(ifname)
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
iface.connect_to_signal("ScanDone", scanDone2,
path_keyword='path')
bus.add_signal_receiver(scanDone,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="ScanDone",
path=path)
bus.add_signal_receiver(bssAdded,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BSSAdded",
path=path)
bus.add_signal_receiver(bssRemoved,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BSSRemoved",
path=path)
bus.add_signal_receiver(blobAdded,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BlobAdded",
path=path)
bus.add_signal_receiver(blobRemoved,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BlobRemoved",
path=path)
bus.add_signal_receiver(networkAdded,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="NetworkAdded",
path=path)
bus.add_signal_receiver(networkRemoved,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="NetworkRemoved",
path=path)
bus.add_signal_receiver(networkSelected,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="NetworkSelected",
path=path)
bus.add_signal_receiver(propertiesChangedInterface,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="PropertiesChanged",
path=path)
bus.add_signal_receiver(propertiesChangedBss,
dbus_interface=WPAS_DBUS_BSS_INTERFACE,
signal_name="PropertiesChanged")
bus.add_signal_receiver(propertiesChangedNetwork,
dbus_interface=WPAS_DBUS_NETWORK_INTERFACE,
signal_name="PropertiesChanged")
gobject.MainLoop().run()
if __name__ == "__main__":
main()
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/python
import dbus
import sys, os
import time
import gobject
from dbus.mainloop.glib import DBusGMainLoop
WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
WPAS_DBUS_WPS_INTERFACE = "fi.w1.wpa_supplicant1.Interface.WPS"
def propertiesChanged(properties):
if properties.has_key("State"):
print "PropertiesChanged: State: %s" % (properties["State"])
def scanDone(success):
print "Scan done: success=%s" % success
def bssAdded(bss, properties):
print "BSS added: %s" % (bss)
def bssRemoved(bss):
print "BSS removed: %s" % (bss)
def wpsEvent(name, args):
print "WPS event: %s" % (name)
print args
def credentials(cred):
print "WPS credentials: %s" % (cred)
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
global bus
bus = dbus.SystemBus()
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
if len(sys.argv) != 2:
print "Missing ifname argument"
os._exit(1)
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
bus.add_signal_receiver(scanDone,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="ScanDone")
bus.add_signal_receiver(bssAdded,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BSSAdded")
bus.add_signal_receiver(bssRemoved,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BSSRemoved")
bus.add_signal_receiver(propertiesChanged,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="PropertiesChanged")
bus.add_signal_receiver(wpsEvent,
dbus_interface=WPAS_DBUS_WPS_INTERFACE,
signal_name="Event")
bus.add_signal_receiver(credentials,
dbus_interface=WPAS_DBUS_WPS_INTERFACE,
signal_name="Credentials")
ifname = sys.argv[1]
path = wpas.GetInterface(ifname)
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
if_obj.Set(WPAS_DBUS_WPS_INTERFACE, 'ProcessCredentials',
dbus.Boolean(1),
dbus_interface=dbus.PROPERTIES_IFACE)
wps = dbus.Interface(if_obj, WPAS_DBUS_WPS_INTERFACE)
wps.Start({'Role': 'enrollee', 'Type': 'pbc'})
gobject.MainLoop().run()
if __name__ == "__main__":
main()
+149
View File
@@ -0,0 +1,149 @@
#!/usr/bin/python
import dbus
import sys, os
import time
import gobject
from dbus.mainloop.glib import DBusGMainLoop
WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_OPATH = "/fi/w1/wpa_supplicant1"
WPAS_DBUS_INTERFACES_INTERFACE = "fi.w1.wpa_supplicant1.Interface"
WPAS_DBUS_INTERFACES_OPATH = "/fi/w1/wpa_supplicant1/Interfaces"
WPAS_DBUS_BSS_INTERFACE = "fi.w1.wpa_supplicant1.BSS"
def byte_array_to_string(s):
import urllib
r = ""
for c in s:
if c >= 32 and c < 127:
r += "%c" % c
else:
r += urllib.quote(chr(c))
return r
def list_interfaces(wpas_obj):
ifaces = wpas_obj.Get(WPAS_DBUS_INTERFACE, 'Interfaces',
dbus_interface=dbus.PROPERTIES_IFACE)
for path in ifaces:
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
ifname = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'Ifname',
dbus_interface=dbus.PROPERTIES_IFACE)
print ifname
def propertiesChanged(properties):
if properties.has_key("State"):
print "PropertiesChanged: State: %s" % (properties["State"])
def showBss(bss):
net_obj = bus.get_object(WPAS_DBUS_SERVICE, bss)
net = dbus.Interface(net_obj, WPAS_DBUS_BSS_INTERFACE)
# Convert the byte-array for SSID and BSSID to printable strings
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'BSSID',
dbus_interface=dbus.PROPERTIES_IFACE)
bssid = ""
for item in val:
bssid = bssid + ":%02x" % item
bssid = bssid[1:]
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'SSID',
dbus_interface=dbus.PROPERTIES_IFACE)
ssid = byte_array_to_string(val)
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'WPA',
dbus_interface=dbus.PROPERTIES_IFACE)
wpa = "no"
if len(val["KeyMgmt"]) > 0:
wpa = "yes"
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'RSN',
dbus_interface=dbus.PROPERTIES_IFACE)
wpa2 = "no"
if len(val["KeyMgmt"]) > 0:
wpa2 = "yes"
freq = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Frequency',
dbus_interface=dbus.PROPERTIES_IFACE)
signal = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Signal',
dbus_interface=dbus.PROPERTIES_IFACE)
val = net_obj.Get(WPAS_DBUS_BSS_INTERFACE, 'Rates',
dbus_interface=dbus.PROPERTIES_IFACE)
if len(val) > 0:
maxrate = val[0] / 1000000
else:
maxrate = 0
print " %s :: ssid='%s' wpa=%s wpa2=%s signal=%d rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, signal, maxrate, freq)
def scanDone(success):
print "Scan done: success=%s" % success
res = if_obj.Get(WPAS_DBUS_INTERFACES_INTERFACE, 'BSSs',
dbus_interface=dbus.PROPERTIES_IFACE)
print "Scanned wireless networks:"
for opath in res:
print opath
showBss(opath)
def bssAdded(bss, properties):
print "BSS added: %s" % (bss)
showBss(bss)
def bssRemoved(bss):
print "BSS removed: %s" % (bss)
def main():
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
global bus
bus = dbus.SystemBus()
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
if len(sys.argv) != 2:
list_interfaces(wpas_obj)
os._exit(1)
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
bus.add_signal_receiver(scanDone,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="ScanDone")
bus.add_signal_receiver(bssAdded,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BSSAdded")
bus.add_signal_receiver(bssRemoved,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="BSSRemoved")
bus.add_signal_receiver(propertiesChanged,
dbus_interface=WPAS_DBUS_INTERFACES_INTERFACE,
signal_name="PropertiesChanged")
ifname = sys.argv[1]
# See if wpa_supplicant already knows about this interface
path = None
try:
path = wpas.GetInterface(ifname)
except dbus.DBusException, exc:
if not str(exc).startswith("fi.w1.wpa_supplicant1.InterfaceUnknown:"):
raise exc
try:
path = wpas.CreateInterface({'Ifname': ifname, 'Driver': 'test'})
time.sleep(1)
except dbus.DBusException, exc:
if not str(exc).startswith("fi.w1.wpa_supplicant1.InterfaceExists:"):
raise exc
global if_obj
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
global iface
iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
iface.Scan({'Type': 'active'})
gobject.MainLoop().run()
wpas.RemoveInterface(dbus.ObjectPath(path))
if __name__ == "__main__":
main()
+91
View File
@@ -0,0 +1,91 @@
#!/usr/bin/python
import dbus
import sys, os
import time
WPAS_DBUS_SERVICE = "fi.epitest.hostap.WPASupplicant"
WPAS_DBUS_INTERFACE = "fi.epitest.hostap.WPASupplicant"
WPAS_DBUS_OPATH = "/fi/epitest/hostap/WPASupplicant"
WPAS_DBUS_INTERFACES_INTERFACE = "fi.epitest.hostap.WPASupplicant.Interface"
WPAS_DBUS_INTERFACES_OPATH = "/fi/epitest/hostap/WPASupplicant/Interfaces"
WPAS_DBUS_BSSID_INTERFACE = "fi.epitest.hostap.WPASupplicant.BSSID"
def byte_array_to_string(s):
import urllib
r = ""
for c in s:
if c >= 32 and c < 127:
r += "%c" % c
else:
r += urllib.quote(chr(c))
return r
def main():
if len(sys.argv) != 2:
print "Usage: wpas-test.py <interface>"
os._exit(1)
ifname = sys.argv[1]
bus = dbus.SystemBus()
wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
# See if wpa_supplicant already knows about this interface
path = None
try:
path = wpas.getInterface(ifname)
except dbus.dbus_bindings.DBusException, exc:
if str(exc) != "wpa_supplicant knows nothing about this interface.":
raise exc
try:
path = wpas.addInterface(ifname, {'driver': dbus.Variant('wext')})
except dbus.dbus_bindings.DBusException, exc:
if str(exc) != "wpa_supplicant already controls this interface.":
raise exc
if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
iface.scan()
# Should really wait for the "scanResults" signal instead of sleeping
time.sleep(5)
res = iface.scanResults()
print "Scanned wireless networks:"
for opath in res:
net_obj = bus.get_object(WPAS_DBUS_SERVICE, opath)
net = dbus.Interface(net_obj, WPAS_DBUS_BSSID_INTERFACE)
props = net.properties()
# Convert the byte-array for SSID and BSSID to printable strings
bssid = ""
for item in props["bssid"]:
bssid = bssid + ":%02x" % item
bssid = bssid[1:]
ssid = byte_array_to_string(props["ssid"])
wpa = "no"
if props.has_key("wpaie"):
wpa = "yes"
wpa2 = "no"
if props.has_key("rsnie"):
wpa2 = "yes"
freq = 0
if props.has_key("frequency"):
freq = props["frequency"]
caps = props["capabilities"]
qual = props["quality"]
level = props["level"]
noise = props["noise"]
maxrate = props["maxrate"] / 1000000
print " %s :: ssid='%s' wpa=%s wpa2=%s quality=%d%% rate=%d freq=%d" % (bssid, ssid, wpa, wpa2, qual, maxrate, freq)
wpas.removeInterface(dbus.ObjectPath(path))
# Should fail here with unknown interface error
iface.scan()
if __name__ == "__main__":
main()
+78
View File
@@ -0,0 +1,78 @@
#!/bin/sh
CLI=wpa_cli
pbc()
{
echo "Starting PBC mode"
echo "Push button on the station within two minutes"
if ! $CLI wps_pbc | grep -q OK; then
echo "Failed to enable PBC mode"
fi
}
enter_pin()
{
echo "Enter a PIN from a station to be enrolled to the network."
read -p "Enrollee PIN: " pin
cpin=`$CLI wps_check_pin "$pin" | tail -1`
if [ "$cpin" = "FAIL-CHECKSUM" ]; then
echo "Checksum digit is not valid"
read -p "Do you want to use this PIN (y/n)? " resp
case "$resp" in
y*)
cpin=`echo "$pin" | sed "s/[^1234567890]//g"`
;;
*)
return 1
;;
esac
fi
if [ "$cpin" = "FAIL" ]; then
echo "Invalid PIN: $pin"
return 1
fi
echo "Enabling Enrollee PIN: $cpin"
$CLI wps_pin any "$cpin"
}
show_config()
{
$CLI status wps
}
main_menu()
{
echo "WPS AP"
echo "------"
echo "1: Push button (activate PBC)"
echo "2: Enter Enrollee PIN"
echo "3: Show current configuration"
echo "0: Exit wps-ap-cli"
read -p "Command: " cmd
case "$cmd" in
1)
pbc
;;
2)
enter_pin
;;
3)
show_config
;;
0)
exit 0
;;
*)
echo "Unknown command: $cmd"
;;
esac
echo
main_menu
}
main_menu