mirror of
https://github.com/LibreELEC/LibreELEC.tv.git
synced 2025-07-31 22:47:51 +00:00
connman: rework network config and init script again
Signed-off-by: Stephan Raue <stephan@openelec.tv>
This commit is contained in:
parent
a59a17cbc2
commit
3eaa331a4f
@ -1,26 +1,20 @@
|
||||
# Setup Network
|
||||
# Network configuration
|
||||
|
||||
# Hostname
|
||||
HOSTNAME="openelec"
|
||||
|
||||
# Network type ( wired, wlan, 3g )
|
||||
# Note: only "wired" is still supported
|
||||
NETWORK_TYPE="wired"
|
||||
# Network interface name or address (e.g. "eth0" or "00:0d:56:ec:ba:0c")
|
||||
# you can leave blanc to use eth0
|
||||
IFACE=""
|
||||
|
||||
# Connection type ( dhcp, static )
|
||||
CONNECTION="dhcp"
|
||||
# Static IP address in CIDR format (e.g. "192.168.1.1/24")
|
||||
# leave blanc to use DHCP server
|
||||
IPADDRESS=""
|
||||
|
||||
# IP settings (only with static connection type)
|
||||
# IP address
|
||||
IPADDRESS="192.168.0.12"
|
||||
# Network gateway (e.g. "192.168.1.254")
|
||||
# you must setup if you use an static IP address
|
||||
GATEWAY=""
|
||||
|
||||
# Netmask
|
||||
NETMASK="255.255.255.0"
|
||||
|
||||
# Gateway
|
||||
GATEWAY="192.168.0.1"
|
||||
|
||||
# Nameservers ( auto, ip-address )
|
||||
NAMESERVER1="auto"
|
||||
NAMESERVER2=""
|
||||
NAMESERVER3=""
|
||||
# List of DNS servers (e.g. "192.168.1.253;192.168.1.254")
|
||||
# you must setup if you use an static IP address
|
||||
NAMESERVER=""
|
||||
|
@ -26,12 +26,16 @@
|
||||
|
||||
. /etc/profile
|
||||
|
||||
HOSTNAME="openelec" # default hostname
|
||||
NETWORK_TYPE="wired" # default network type
|
||||
CONNECTION="dhcp" # default connection
|
||||
|
||||
[ -f $HOME/.config/network.conf ] && . $HOME/.config/network.conf
|
||||
|
||||
[ -z "$HOSTNAME" ] && HOSTNAME="openelec"
|
||||
[ -z "$IFACE" ] && IFACE=eth0
|
||||
[ -f /sys/class/net/$IFACE/address ] && IFACE=`cat /sys/class/net/$IFACE/address`
|
||||
|
||||
CONNMAN_PROFILE="/var/lib/connman/default.profile"
|
||||
IP=`echo $IPADDRESS | cut -f1 -d/`
|
||||
PREFIX=`echo $IPADDRESS | cut -f2 -d/`
|
||||
|
||||
# bring lo up, whether we have network card or not
|
||||
progress "starting Loopback Network interface"
|
||||
ifconfig lo 127.0.0.1 up
|
||||
@ -44,20 +48,23 @@ CONNECTION="dhcp" # default connection
|
||||
progress "creating /etc/hosts"
|
||||
echo -e "127.0.0.1\tlocalhost $HOSTNAME" > /etc/hosts
|
||||
|
||||
(
|
||||
# starting Connection manager
|
||||
progress "starting Connection manager"
|
||||
|
||||
mkdir -p /var/run
|
||||
touch /var/run/resolv.conf
|
||||
[ -x /usr/sbin/connmand ] && /usr/sbin/connmand || exit 0
|
||||
mkdir -p /var/run/connman
|
||||
mkdir -p /var/lib/connman
|
||||
|
||||
usleep 2000
|
||||
echo "[ethernet_`echo $IFACE | sed 's/://g'`_cable]" > $CONNMAN_PROFILE
|
||||
|
||||
if [ "$CONNECTION" = "dhcp" -a -x /usr/bin/cmcc ]; then
|
||||
/usr/bin/cmcc edit Wired ipv4 dhcp
|
||||
elif [ "$CONNECTION" = "static" -a -n "$IPADDRESS" -a -n "$NETMASK" -a -n "$GATEWAY" -a -x /usr/bin/cmcc ]; then
|
||||
/usr/bin/cmcc edit Wired ipv4 manual "$IPADDRESS" "$NETMASK" "$GATEWAY"
|
||||
/usr/bin/cmcc edit Wired nameservers "$NAMESERVER1" "$NAMESERVER2" "$NAMESERVER3"
|
||||
if [ -z "$IPADDRESS" ]; then
|
||||
echo "IPv4.method=dhcp" >> $CONNMAN_PROFILE
|
||||
else
|
||||
echo "IPv4.method=manual" >> $CONNMAN_PROFILE
|
||||
echo "IPv4.local_address=$IP" >> $CONNMAN_PROFILE
|
||||
[ -n "$PREFIX" ] && echo "IPv4.netmask_prefixlen=$PREFIX" >> $CONNMAN_PROFILE
|
||||
[ -n "$GATEWAY" ] && echo "IPv4.gateway=$GATEWAY" >> $CONNMAN_PROFILE
|
||||
[ -n "$NAMESERVER" ] && echo "Nameservers=$NAMESERVER;" >> $CONNMAN_PROFILE
|
||||
fi
|
||||
)&
|
||||
|
||||
touch /var/run/resolv.conf
|
||||
/usr/sbin/connmand
|
||||
|
@ -14,8 +14,5 @@ mkdir -p $INSTALL/usr/lib/connman/plugins
|
||||
mkdir -p $INSTALL/usr/sbin
|
||||
cp -P $PKG_BUILD/src/connmand $INSTALL/usr/sbin
|
||||
|
||||
mkdir -p $INSTALL/usr/bin
|
||||
cp $PKG_DIR/scripts/cmcc $INSTALL/usr/bin
|
||||
|
||||
mkdir -p $INSTALL/usr/config
|
||||
cp $PKG_DIR/config/network.conf $INSTALL/usr/config
|
||||
|
@ -5,7 +5,7 @@ PKG_ARCH="any"
|
||||
PKG_LICENSE="GPL"
|
||||
PKG_SITE="http://www.connman.net"
|
||||
PKG_URL="http://www.kernel.org/pub/linux/network/connman/$PKG_NAME-$PKG_VERSION.tar.bz2"
|
||||
PKG_DEPENDS="glib dbus udev wpa_supplicant Python pygobject dbus-python"
|
||||
PKG_DEPENDS="glib dbus udev wpa_supplicant"
|
||||
PKG_BUILD_DEPENDS="toolchain glib dbus udev"
|
||||
PKG_PRIORITY="optional"
|
||||
PKG_SECTION="network"
|
||||
|
@ -1,786 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
#
|
||||
# indicator-network - user interface for connman
|
||||
# Copyright 2010 Canonical Ltd.
|
||||
#
|
||||
# Authors:
|
||||
# Kalle Valo <kalle.valo@canonical.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 3, as published
|
||||
# by the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
||||
# PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import dbus
|
||||
import dbus.mainloop.glib
|
||||
import gobject
|
||||
import time
|
||||
|
||||
stamp = False
|
||||
|
||||
class ArgumentException(Exception):
|
||||
def __init__(self, msg):
|
||||
self.msg = msg
|
||||
|
||||
def __str__(self):
|
||||
return self.msg
|
||||
|
||||
def get_bus(async=False):
|
||||
if (async):
|
||||
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
|
||||
|
||||
return dbus.SystemBus()
|
||||
|
||||
def get_manager(bus=None):
|
||||
if bus == None:
|
||||
bus = get_bus()
|
||||
|
||||
return dbus.Interface(bus.get_object("org.moblin.connman", "/"),
|
||||
"org.moblin.connman.Manager")
|
||||
|
||||
def usage(name):
|
||||
print "Usage: %s <command>" % (name)
|
||||
print ""
|
||||
print "Commands:"
|
||||
print " state"
|
||||
print " services"
|
||||
print " connect <service>"
|
||||
print " connect-hidden <name> [passphrase] [type]"
|
||||
print " disconnect <service>"
|
||||
print " show <service>"
|
||||
print " edit <service> [property..]"
|
||||
print " remove <service>"
|
||||
print " scan [technology]"
|
||||
print " enable <technology>"
|
||||
print " disable <technology>"
|
||||
print " offlinemode <on|off>"
|
||||
print " event [-t]"
|
||||
print " modem list"
|
||||
print " modem pin <number>"
|
||||
print " modem puk <number>"
|
||||
print ""
|
||||
print "Properties:"
|
||||
print " apn <name>"
|
||||
print " passphrase <passphrase>"
|
||||
print " autoconnect <true|false>"
|
||||
print " ipv4 <dhcp|manual address netmask gateway>"
|
||||
print " nameservers auto | <nameserver> [nameserver] [nameserver]"
|
||||
print " domains [domain] [domain] ..."
|
||||
|
||||
return
|
||||
|
||||
def is_connected(state):
|
||||
connected = [ "ready", "online"]
|
||||
|
||||
if state in connected:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def find_service(name):
|
||||
bus = get_bus()
|
||||
manager = get_manager(bus)
|
||||
manager_properties = manager.GetProperties()
|
||||
|
||||
path = "/profile/default/" + name
|
||||
|
||||
if path in manager_properties["Services"]:
|
||||
service = dbus.Interface(bus.get_object("org.moblin.connman",
|
||||
path),
|
||||
"org.moblin.connman.Service")
|
||||
return service
|
||||
|
||||
# service not found with the path, let's try find it with name
|
||||
|
||||
found = []
|
||||
|
||||
for path in manager_properties["Services"]:
|
||||
service = dbus.Interface(bus.get_object("org.moblin.connman",
|
||||
path),
|
||||
"org.moblin.connman.Service")
|
||||
|
||||
properties = service.GetProperties()
|
||||
|
||||
if "Name" in properties.keys():
|
||||
if properties["Name"].lower() == name.lower():
|
||||
found.append(service)
|
||||
|
||||
if len(found) > 1:
|
||||
raise ArgumentException("Multiple services with same name, "
|
||||
"use id instead.")
|
||||
elif len(found) == 1:
|
||||
return found.pop()
|
||||
else:
|
||||
raise ArgumentException("Service '%s' not found." % name)
|
||||
|
||||
def get_service_name(path):
|
||||
bus = get_bus()
|
||||
|
||||
try:
|
||||
service = dbus.Interface(bus.get_object("org.moblin.connman",
|
||||
path),
|
||||
"org.moblin.connman.Service")
|
||||
properties = service.GetProperties()
|
||||
name = properties["Name"]
|
||||
if len(name) == 0:
|
||||
name = path[path.rfind("/") + 1:]
|
||||
|
||||
except dbus.DBusException:
|
||||
name = path[path.rfind("/") + 1:]
|
||||
|
||||
return name
|
||||
|
||||
def extract_dict(values):
|
||||
s = ""
|
||||
for k, v in values.items():
|
||||
s += " %s=%s" % (k,v)
|
||||
return "{ %s }" % s
|
||||
|
||||
def extract_list(values):
|
||||
return "[ %s ]" % " ".join(values)
|
||||
|
||||
def convert_dbus_value(value):
|
||||
"""Convert a dbus object to a pretty string"""
|
||||
|
||||
if type(value) is dbus.Dictionary:
|
||||
result = extract_dict(value)
|
||||
elif type(value) is dbus.Array:
|
||||
result = extract_list(value)
|
||||
elif type(value) is dbus.Boolean:
|
||||
if value:
|
||||
result = "true"
|
||||
else:
|
||||
result = "false"
|
||||
elif type(value) is dbus.Byte:
|
||||
result = str(int(value))
|
||||
else:
|
||||
result = str(value)
|
||||
|
||||
return result
|
||||
|
||||
def get_devices():
|
||||
bus = get_bus()
|
||||
manager = get_manager()
|
||||
|
||||
result = []
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for path in properties["Technologies"]:
|
||||
technology = dbus.Interface(bus.get_object("org.moblin.connman",
|
||||
path),
|
||||
"org.moblin.connman.Technology")
|
||||
properties = technology.GetProperties()
|
||||
|
||||
for path in properties["Devices"]:
|
||||
d = dbus.Interface(bus.get_object("org.moblin.connman",
|
||||
path),
|
||||
"org.moblin.connman.Device")
|
||||
result.append(d)
|
||||
|
||||
return result
|
||||
|
||||
def cmd_state():
|
||||
manager = get_manager()
|
||||
properties = manager.GetProperties()
|
||||
order = ["State", "OfflineMode", "DefaultTechnology",
|
||||
"ConnectedTechnologies", "EnabledTechnologies",
|
||||
"AvailableTechnologies", "ActiveProfile", "Profiles",
|
||||
"Providers", "EnabledDebugs", "AvailableDebugs",
|
||||
"Technologies", "Services"]
|
||||
|
||||
keys = properties.keys()
|
||||
|
||||
for key in order:
|
||||
if key in keys:
|
||||
keys.remove(key)
|
||||
value = convert_dbus_value(properties[key])
|
||||
print "%s: %s" % (key, value)
|
||||
|
||||
# print properties missing in the order
|
||||
for key in keys:
|
||||
value = convert_dbus_value(properties[key])
|
||||
print "%s: %s" % (key, value)
|
||||
|
||||
def cmd_services():
|
||||
bus = get_bus()
|
||||
manager = get_manager()
|
||||
manager_properties = manager.GetProperties()
|
||||
|
||||
for path in manager_properties["Services"]:
|
||||
service = dbus.Interface(bus.get_object("org.moblin.connman",
|
||||
path),
|
||||
"org.moblin.connman.Service")
|
||||
|
||||
properties = service.GetProperties()
|
||||
|
||||
identifier = path[path.rfind("/") + 1:]
|
||||
|
||||
if is_connected(properties["State"]):
|
||||
connected = "*"
|
||||
else:
|
||||
connected = " "
|
||||
|
||||
if "Name" in properties.keys():
|
||||
name = properties["Name"]
|
||||
else:
|
||||
name = "{" + properties["Type"] + "}"
|
||||
|
||||
print "%s %-26s { %s }" % (connected, name, identifier)
|
||||
|
||||
def cmd_edit_apn(service, argv):
|
||||
if (len(sys.argv) < 1):
|
||||
raise ArgumentException("apn value missing")
|
||||
|
||||
apn = argv.pop(0)
|
||||
service.SetProperty("APN", apn);
|
||||
|
||||
def cmd_edit_passphrase(service, argv):
|
||||
if (len(sys.argv) < 1):
|
||||
raise ArgumentException("passphrase value missing")
|
||||
|
||||
passphrase = argv.pop(0)
|
||||
service.SetProperty("Passphrase", passphrase);
|
||||
|
||||
def cmd_edit_autoconnect(service, argv):
|
||||
if (len(argv) < 1):
|
||||
raise ArgumentException("autoconnect value missing")
|
||||
|
||||
arg = argv.pop(0)
|
||||
|
||||
if arg == "true":
|
||||
autoconnect = dbus.Boolean(True)
|
||||
elif arg == "false":
|
||||
autoconnect = dbus.Boolean(False)
|
||||
else:
|
||||
raise ArgumentException("Invalid value for autoconnect: %s" %
|
||||
arg)
|
||||
|
||||
print autoconnect
|
||||
service.SetProperty("AutoConnect", autoconnect);
|
||||
|
||||
def cmd_edit_ipv4(service, argv):
|
||||
if len(argv) < 1:
|
||||
raise ArgumentException("ipv4 method missing")
|
||||
|
||||
method = argv.pop(0)
|
||||
|
||||
if method == "dhcp":
|
||||
value = { "Method": "dhcp" }
|
||||
elif method == "manual":
|
||||
if len(argv) < 3:
|
||||
raise ArgumentException("invalid syntax for ipv4 "
|
||||
"manual configuration")
|
||||
|
||||
address = argv.pop(0)
|
||||
netmask = argv.pop(0)
|
||||
gateway = argv.pop(0)
|
||||
|
||||
value = { "Method": "manual",
|
||||
"Address": address,
|
||||
"Netmask": netmask,
|
||||
"Gateway": gateway }
|
||||
|
||||
service.SetProperty("IPv4.Configuration", value);
|
||||
|
||||
def cmd_edit_nameservers(service, argv):
|
||||
items = len(argv)
|
||||
|
||||
if items == 1 and argv[0] == "auto":
|
||||
# disable manual nameservers
|
||||
argv = dbus.Array(signature="s")
|
||||
elif items < 1:
|
||||
raise ArgumentException("nameserver address missing")
|
||||
elif items > 3:
|
||||
raise ArgumentException("maximum of 3 nameserver addresses")
|
||||
|
||||
service.SetProperty("Nameservers.Configuration", argv)
|
||||
|
||||
def cmd_edit_domains(service, argv):
|
||||
l = dbus.Array(argv, signature="s")
|
||||
service.SetProperty("Domains.Configuration", l)
|
||||
|
||||
def cmd_edit(argv):
|
||||
if len(argv) < 1:
|
||||
raise ArgumentException("service name missing")
|
||||
|
||||
name = argv.pop(0)
|
||||
|
||||
service = find_service(name)
|
||||
|
||||
if len(argv) < 1:
|
||||
raise ArgumentException("property name missing")
|
||||
|
||||
while len(argv) > 0:
|
||||
if len(argv) < 1:
|
||||
print "property name missing"
|
||||
prop = argv.pop(0)
|
||||
|
||||
if prop == "apn":
|
||||
cmd_edit_apn(service, argv)
|
||||
elif prop in ["passphrase", "pass"]:
|
||||
cmd_edit_passphrase(service, argv)
|
||||
elif prop in ["autoconnect", "autoconn"]:
|
||||
cmd_edit_autoconnect(service, argv)
|
||||
elif prop in ["ipv4"]:
|
||||
cmd_edit_ipv4(service, argv)
|
||||
elif prop in ["nameservers"]:
|
||||
cmd_edit_nameservers(service, argv)
|
||||
elif prop in ["domains"]:
|
||||
cmd_edit_domains(service, argv)
|
||||
|
||||
def cmd_connect(argv):
|
||||
|
||||
if (len(argv) < 1):
|
||||
raise ArgumentException("Need at least service parameter")
|
||||
|
||||
name = argv.pop(0)
|
||||
service = find_service(name)
|
||||
|
||||
try:
|
||||
service.Connect(timeout=60000)
|
||||
except dbus.DBusException, error:
|
||||
print "%s: %s" % (error._dbus_error_name, error.message)
|
||||
|
||||
def cmd_disconnect(argv):
|
||||
if (len(argv) < 1):
|
||||
raise ArgumentException("Need at least service parameter")
|
||||
|
||||
name = argv.pop(0)
|
||||
service = find_service(name)
|
||||
|
||||
try:
|
||||
service.Disconnect()
|
||||
except dbus.DBusException, error:
|
||||
print "%s: %s" % (error._dbus_error_name, error.message)
|
||||
|
||||
def cmd_remove(argv):
|
||||
if (len(argv) < 1):
|
||||
raise ArgumentException("Need at least service parameter")
|
||||
|
||||
name = argv.pop(0)
|
||||
service = find_service(name)
|
||||
properties = service.GetProperties()
|
||||
|
||||
if properties["Favorite"] == dbus.Boolean(0):
|
||||
raise ArgumentException("Only favorite services can be removed")
|
||||
|
||||
try:
|
||||
service.Remove()
|
||||
except dbus.DBusException, error:
|
||||
print "%s: %s" % (error._dbus_error_name, error.message)
|
||||
|
||||
def cmd_scan(argv):
|
||||
if len(argv) > 0:
|
||||
arg = argv.pop(0)
|
||||
else:
|
||||
arg = ""
|
||||
|
||||
manager = get_manager()
|
||||
manager.RequestScan(arg)
|
||||
|
||||
devices = get_devices()
|
||||
|
||||
if len(devices) == 0:
|
||||
# no devices available so no scan results either
|
||||
return
|
||||
|
||||
# start waiting for scanning to end, but take into account
|
||||
# that not all devices, if any (!), support scanning
|
||||
scanning = False
|
||||
scan_supported = False
|
||||
|
||||
while True:
|
||||
scanning = False
|
||||
for device in devices:
|
||||
properties = device.GetProperties()
|
||||
|
||||
if "Scanning" not in properties:
|
||||
continue
|
||||
|
||||
scan_supported = True
|
||||
|
||||
if properties["Scanning"]:
|
||||
scanning = True
|
||||
|
||||
if not scanning or not scan_supported:
|
||||
break;
|
||||
|
||||
cmd_services()
|
||||
|
||||
def cmd_enable(argv):
|
||||
if len(argv) > 0:
|
||||
technology = argv.pop(0)
|
||||
else:
|
||||
technology = ""
|
||||
|
||||
manager = get_manager()
|
||||
manager.EnableTechnology(technology)
|
||||
|
||||
def cmd_disable(argv):
|
||||
if len(argv) > 0:
|
||||
technology = argv.pop(0)
|
||||
else:
|
||||
technology = ""
|
||||
|
||||
manager = get_manager()
|
||||
manager.DisableTechnology(technology)
|
||||
|
||||
def cmd_offlinemode(argv):
|
||||
if len(argv) > 0:
|
||||
arg = sys.argv.pop(0)
|
||||
if arg == "on":
|
||||
active = dbus.Boolean(1)
|
||||
elif arg == "off":
|
||||
active = dbus.Boolean(0)
|
||||
else:
|
||||
active = dbus.Boolean(arg)
|
||||
|
||||
manager = get_manager()
|
||||
manager.SetProperty("OfflineMode", active)
|
||||
else:
|
||||
properties = manager.GetProperties()
|
||||
print "Offline mode is %s" % (properties["OfflineMode"])
|
||||
|
||||
def cmd_show(argv):
|
||||
if len(argv) < 1:
|
||||
raise ArgumentException("service name missing")
|
||||
|
||||
name = argv.pop(0)
|
||||
service = find_service(name)
|
||||
properties = service.GetProperties()
|
||||
|
||||
order = [ "Name", "Type", "State", "Strength", "Mode", "Security",
|
||||
"IPv4", "IPv4.Configuration",
|
||||
"Ethernet",
|
||||
"Nameservers", "Nameservers.Configuration",
|
||||
"Domains", "Domains.Configuration",
|
||||
"Proxy",
|
||||
"PassphraseRequired", "Passphrase",
|
||||
"SetupRequired", "Roaming",
|
||||
"Immutable", "Favorite", "AutoConnect" ]
|
||||
|
||||
keys = properties.keys()
|
||||
|
||||
for key in order:
|
||||
if key in keys:
|
||||
keys.remove(key)
|
||||
val = convert_dbus_value(properties[key])
|
||||
print "%s: %s" % (key, val)
|
||||
|
||||
# print properties missing in the order
|
||||
for key in keys:
|
||||
val = convert_dbus_value(properties[key])
|
||||
print "%s: %s" % (key, val)
|
||||
|
||||
def connman_property_changed(name, value, path, interface):
|
||||
global stamp
|
||||
|
||||
if stamp:
|
||||
timestamp = "%f " % time.time()
|
||||
else:
|
||||
timestamp = ""
|
||||
|
||||
if interface == "org.moblin.connman.Service":
|
||||
val = convert_dbus_value(value)
|
||||
print "%s[%s] %s: %s" % (timestamp, get_service_name(path),
|
||||
name, val)
|
||||
elif interface == "org.moblin.connman.Manager":
|
||||
val = convert_dbus_value(value)
|
||||
print "%s%s: %s" % (timestamp, name, val)
|
||||
|
||||
def cmd_event(argv):
|
||||
global stamp
|
||||
|
||||
if len(argv) > 0 and argv.pop(0) == "-t":
|
||||
stamp = True
|
||||
|
||||
bus = get_bus(async=True)
|
||||
bus.add_signal_receiver(connman_property_changed,
|
||||
bus_name="org.moblin.connman",
|
||||
signal_name = "PropertyChanged",
|
||||
path_keyword="path",
|
||||
interface_keyword="interface")
|
||||
|
||||
mainloop = gobject.MainLoop()
|
||||
mainloop.run()
|
||||
|
||||
def print_sms_manager(path):
|
||||
bus = get_bus()
|
||||
interface = "org.ofono.SmsManager"
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
interface)
|
||||
|
||||
print " [ %s ]" % interface
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
def print_context(path):
|
||||
bus = get_bus()
|
||||
interface = "org.ofono.PrimaryDataContext"
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
interface)
|
||||
|
||||
print " [ %s ]" % path
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
def print_data_manager(path):
|
||||
bus = get_bus()
|
||||
interface = "org.ofono.DataConnectionManager"
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
interface)
|
||||
|
||||
print " [ %s ]" % interface
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
if "PrimaryContexts" not in properties:
|
||||
return
|
||||
|
||||
for context in properties["PrimaryContexts"]:
|
||||
print_context(context)
|
||||
|
||||
def print_cell_broadcast(path):
|
||||
bus = get_bus()
|
||||
interface = "org.ofono.CellBroadcast"
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
interface)
|
||||
|
||||
print " [ %s ]" % interface
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
def print_network_registration(path):
|
||||
bus = get_bus()
|
||||
interface = "org.ofono.NetworkRegistration"
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
interface)
|
||||
|
||||
print " [ %s ]" % interface
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
def print_supplementary_services(path):
|
||||
bus = get_bus()
|
||||
interface = "org.ofono.SupplementaryServices"
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
interface)
|
||||
|
||||
print " [ %s ]" % interface
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
def print_sim_manager(path):
|
||||
bus = get_bus()
|
||||
interface = "org.ofono.SimManager"
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
interface)
|
||||
|
||||
print " [ %s ]" % interface
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
def print_modem(path):
|
||||
bus = get_bus()
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", path),
|
||||
"org.ofono.Modem")
|
||||
|
||||
print "[ %s ]" % path
|
||||
|
||||
properties = manager.GetProperties()
|
||||
for key in properties.keys():
|
||||
value = convert_dbus_value(properties[key])
|
||||
print " %s = %s" % (key, value)
|
||||
|
||||
if "Interfaces" not in properties:
|
||||
return
|
||||
|
||||
for interface in properties["Interfaces"]:
|
||||
if interface == "org.ofono.SmsManager":
|
||||
print_sms_manager(path)
|
||||
elif interface == "org.ofono.DataConnectionManager":
|
||||
print_data_manager(path)
|
||||
elif interface == "org.ofono.CellBroadcast":
|
||||
print_cell_broadcast(path)
|
||||
elif interface == "org.ofono.NetworkRegistration":
|
||||
print_network_registration(path)
|
||||
elif interface == "org.ofono.SupplementaryServices":
|
||||
print_supplementary_services(path)
|
||||
elif interface == "org.ofono.SimManager":
|
||||
print_sim_manager(path)
|
||||
|
||||
def cmd_modem_list(argv):
|
||||
bus = get_bus()
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", "/"),
|
||||
"org.ofono.Manager")
|
||||
properties = manager.GetProperties()
|
||||
|
||||
if "Modems" not in properties or len(properties["Modems"]) == 0:
|
||||
print "No modems found"
|
||||
return
|
||||
|
||||
modems = properties["Modems"]
|
||||
|
||||
for path in modems:
|
||||
print_modem(path)
|
||||
|
||||
def cmd_modem_pin(pin_type, argv):
|
||||
if len(argv) < 1:
|
||||
raise ArgumentException("%s value missing" % pin_type)
|
||||
|
||||
pin = argv.pop(0)
|
||||
|
||||
bus = get_bus()
|
||||
manager = dbus.Interface(bus.get_object("org.ofono", "/"),
|
||||
"org.ofono.Manager")
|
||||
properties = manager.GetProperties()
|
||||
|
||||
if "Modems" not in properties or len(properties["Modems"]) == 0:
|
||||
print "No modems found"
|
||||
return
|
||||
|
||||
modem = properties["Modems"][0]
|
||||
|
||||
print "Using modem %s" % modem
|
||||
|
||||
sim_manager = dbus.Interface(bus.get_object("org.ofono", modem),
|
||||
"org.ofono.SimManager")
|
||||
|
||||
# check that pin is really needed
|
||||
properties = sim_manager.GetProperties()
|
||||
|
||||
if "PinRequired" not in properties:
|
||||
print "PinRequired not found in properties"
|
||||
return
|
||||
|
||||
if properties["PinRequired"] != pin_type:
|
||||
print "pin type '%s' not required by modem (%s)" % (pin_type,
|
||||
properties["PinRequired"])
|
||||
return
|
||||
try:
|
||||
sim_manager.EnterPin(pin_type, pin)
|
||||
except dbus.exceptions.DBusException as e:
|
||||
print "Failed to enter %s: %s" % (pin_type, str(e))
|
||||
|
||||
def cmd_modem(argv):
|
||||
if len(argv) < 1:
|
||||
raise ArgumentException("modem command missing")
|
||||
|
||||
cmd = argv.pop(0)
|
||||
|
||||
if cmd == "list":
|
||||
cmd_modem_list(argv)
|
||||
elif cmd in ["pin", "puk"]:
|
||||
cmd_modem_pin(cmd, argv)
|
||||
else:
|
||||
raise ArgumentException("unknown modem commmand: %s" % cmd)
|
||||
|
||||
def cmd_connect_hidden(argv):
|
||||
|
||||
if (len(argv) < 1):
|
||||
raise ArgumentException("Network name missing")
|
||||
|
||||
name = argv.pop(0)
|
||||
|
||||
if len(argv) > 0:
|
||||
passphrase = argv.pop(0)
|
||||
else:
|
||||
passphrase = ""
|
||||
|
||||
if len(argv) > 0:
|
||||
security = argv.pop(0)
|
||||
else:
|
||||
if len(passphrase) > 0:
|
||||
security = "rsn"
|
||||
else:
|
||||
security = "none"
|
||||
|
||||
properties = { "Type": "wifi", "Mode": "managed", "SSID": name,
|
||||
"Security": security, "Passphrase": passphrase }
|
||||
|
||||
try:
|
||||
manager = get_manager()
|
||||
manager.ConnectService(properties, timeout=60000)
|
||||
except dbus.DBusException, error:
|
||||
print "%s: %s" % (error._dbus_error_name, error.message)
|
||||
|
||||
def handle_cmd(cmd, argv, name):
|
||||
if cmd == "help":
|
||||
usage(name)
|
||||
elif cmd == "state":
|
||||
cmd_state()
|
||||
elif cmd in ["services", "list"]:
|
||||
cmd_services()
|
||||
elif cmd == "edit":
|
||||
cmd_edit(argv)
|
||||
elif cmd in ["connect", "conn"]:
|
||||
cmd_connect(argv)
|
||||
elif cmd in ["disconnect", "disc"]:
|
||||
cmd_disconnect(argv)
|
||||
elif cmd in ["remove"]:
|
||||
cmd_remove(argv)
|
||||
elif cmd == "scan":
|
||||
cmd_scan(argv)
|
||||
elif cmd == "enable":
|
||||
cmd_enable(argv)
|
||||
elif cmd == "disable":
|
||||
cmd_disable(argv)
|
||||
elif cmd in ["offlinemode", "flightmode"]:
|
||||
cmd_offlinemode(argv)
|
||||
elif cmd == "show":
|
||||
cmd_show(argv)
|
||||
elif cmd == "event":
|
||||
cmd_event(argv)
|
||||
elif cmd == "modem":
|
||||
cmd_modem(argv)
|
||||
elif cmd == "connect-hidden":
|
||||
cmd_connect_hidden(argv)
|
||||
else:
|
||||
print "Unknown command"
|
||||
|
||||
def main():
|
||||
name = sys.argv.pop(0)
|
||||
|
||||
if len(sys.argv) == 0:
|
||||
usage(name)
|
||||
return
|
||||
|
||||
cmd = sys.argv.pop(0)
|
||||
|
||||
try:
|
||||
handle_cmd(cmd, sys.argv, name)
|
||||
except ArgumentException as e:
|
||||
print e
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
@ -1 +0,0 @@
|
||||
https://code.launchpad.net/~indicator-network-developers/indicator-network/indicator-network
|
Loading…
x
Reference in New Issue
Block a user