/usr/bin/cmcc is in indicator-network 0.3.8-0ubuntu6.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 | #!/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
WPAS_DBUS_SERVICE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_INTERFACE = "fi.w1.wpa_supplicant1"
WPAS_DBUS_PATH = "/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"
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("net.connman", "/"),
"net.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 " wpas list"
print " wpas networks"
print " wpas bss"
print " technologies"
print ""
print "Properties:"
print " apn <name>"
print " passphrase <passphrase>"
print " autoconnect <true|false>"
print " ipv4 <dhcp|manual address netmask gateway>"
print " ipv6 <auto | off | manual address netmask gateway>"
print " nameservers auto | <nameserver> [nameserver] [nameserver]"
print " domains [domain] [domain] ..."
return
def is_connected(state):
connected = [ "ready", "offline", "online"]
if state in connected:
return True
else:
return False
def is_associating(state):
return state == "association"
def is_configuration(state):
return state == "configuration"
def is_failed(state):
return state == "failure"
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("net.connman",
path),
"net.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("net.connman",
path),
"net.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("net.connman",
path),
"net.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, convert_dbus_value(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 cmd_state():
manager = get_manager()
properties = manager.GetProperties()
order = ["State", "OfflineMode", "DefaultTechnology",
"ConnectedTechnologies", "EnabledTechnologies",
"AvailableTechnologies", "ActiveProfile", "Profiles",
"Providers", "EnabledDebugs", "AvailableDebugs",
"Technologies", "Services"]
print "[ / ]"
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("net.connman",
path),
"net.connman.Service")
properties = service.GetProperties()
identifier = path[path.rfind("/") + 1:]
state = properties["State"]
if is_connected(state):
connected = "*"
elif is_configuration(state):
connected = "+"
elif is_associating(state):
connected = "-"
elif is_failed(state):
connected = "f"
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_ipv6(service, argv):
if len(argv) < 1:
raise ArgumentException("ipv6 method missing")
method = argv.pop(0)
if method == "auto":
value = { "Method": "auto" }
elif method == "off":
value = { "Method": "off" }
elif method == "manual":
if len(argv) < 3:
raise ArgumentException("invalid syntax for ipv6 "
"manual configuration")
address = argv.pop(0)
prefix = argv.pop(0)
gateway = argv.pop(0)
value = { "Method": "manual",
"Address": address,
"PrefixLength": prefix,
"Gateway": gateway }
else:
raise ArgumentException("Unknown ipv6 method: " + method)
service.SetProperty("IPv6.Configuration", value);
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 }
else:
raise ArgumentException("Unknown ipv4 method: " + method)
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 ["ipv6"]:
cmd_edit_ipv6(service, argv)
elif prop in ["nameservers"]:
cmd_edit_nameservers(service, argv)
elif prop in ["domains"]:
cmd_edit_domains(service, argv)
else:
raise ArgumentException("unknown property: %s" % prop)
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)
# there's no way to know when scan has ended, so just wait and
# hope for best
time.sleep(10)
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",
"IPv6", "IPv6.Configuration",
"Ethernet",
"Nameservers", "Nameservers.Configuration",
"Domains", "Domains.Configuration",
"Proxy",
"PassphraseRequired", "Passphrase",
"SetupRequired", "Roaming",
"Immutable", "Favorite", "AutoConnect" ]
keys = properties.keys()
print "[ %s ]" % service.object_path
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 == "net.connman.Service":
val = convert_dbus_value(value)
print "%s[%s] %s: %s" % (timestamp, get_service_name(path),
name, val)
elif interface == "net.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="net.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, properties):
print " [ %s ]" % path
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.ConnectionManager"
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)
contexts = manager.GetContexts()
for path, properties in contexts:
print_context(path, properties)
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, properties):
print "[ %s ]" % path
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.ConnectionManager":
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")
try:
modems = manager.GetModems()
except dbus.exceptions.DBusException as e:
raise ArgumentException("Failed to contact ofonod:", e)
if len(modems) == 0:
print "No modems found"
return
for path, properties in modems:
print_modem(path, properties)
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")
modems = manager.GetModems()
if len(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 (%s)" % (pin_type,
modem,
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 print_wpas_network_properties(properties):
print " Properties = {"
for p in properties:
print " %s = %s" % (p, convert_dbus_value(properties[p]))
print " }"
def print_wpas_network(props):
for prop in props:
if prop == "Properties":
print_wpas_network_properties(props["Properties"])
else:
print " %s = %s" % (prop,
convert_dbus_value(props[prop]))
def print_wpas_networks(networks):
bus = get_bus()
for path in networks:
print
network = bus.get_object("fi.w1.wpa_supplicant1", path)
props = network.GetAll("fi.w1.wpa_supplicant1.Network",
dbus_interface=dbus.PROPERTIES_IFACE)
print "[ %s ]" % path
print_wpas_network(props)
def print_wpas_bss(props):
for prop in props:
if prop in ["RSN", "IEs", "Rates"]:
pass
elif prop in ["SSID", "BSSID"]:
print " %s =" % prop,
for b in props[prop]:
print "%x" % b,
print
else:
print " %s = %s" % (prop,
convert_dbus_value(props[prop]))
def print_wpas_bsss(bsss):
bus = get_bus()
for path in bsss:
print
bss = bus.get_object("fi.w1.wpa_supplicant1", path)
props = bss.GetAll("fi.w1.wpa_supplicant1.BSS",
dbus_interface=dbus.PROPERTIES_IFACE)
print "[ %s ]" % path
print_wpas_bss(props)
def print_wpas_interface(props):
for prop in props:
if prop == "Capabilities":
pass
else:
print " %s = %s" % (prop, convert_dbus_value(props[prop]))
def print_wpas(props):
print "[ %s ]" % WPAS_DBUS_PATH
for prop in props:
print " %s = %s " % (prop, convert_dbus_value(props[prop]))
def cmd_wpas_list(argv, show_bss=False, show_networks=False):
bus = get_bus()
wpas = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_PATH)
try:
props = wpas.GetAll("fi.w1.wpa_supplicant1",
dbus_interface=dbus.PROPERTIES_IFACE)
except dbus.exceptions.DBusException as e:
raise ArgumentException("Failed to contact wpasupplicant: %s"
"\nAre you root?" % e)
print_wpas(props)
if "Interfaces" not in props:
raise ArgumentException("No Interfaces in properties")
bsss = []
networks = []
for path in props["Interfaces"]:
print
print "[ %s ]" % path
interface = bus.get_object("fi.w1.wpa_supplicant1", path)
props = interface.GetAll("fi.w1.wpa_supplicant1.Interface",
dbus_interface=dbus.PROPERTIES_IFACE)
print_wpas_interface(props)
bsss = bsss + props["BSSs"]
networks = networks + props["Networks"]
if show_bss:
print_wpas_bsss(bsss)
if show_networks:
print_wpas_networks(networks)
def cmd_wpas(argv):
if len(argv) < 1:
raise ArgumentException("wpas command missing")
cmd = argv.pop(0)
if cmd == "list":
cmd_wpas_list(argv)
elif cmd == "networks":
cmd_wpas_list(argv, show_networks=True)
elif cmd == "bss":
cmd_wpas_list(argv, show_bss=True, show_networks=True)
else:
raise ArgumentException("unknown wpas 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 cmd_technologies(argv):
bus = get_bus()
manager = get_manager()
result = []
properties = manager.GetProperties()
for path in properties["Technologies"]:
technology = dbus.Interface(bus.get_object("net.connman",
path),
"net.connman.Technology")
props = technology.GetProperties()
print "[ %s ]" % path
for key in props.keys():
value = convert_dbus_value(props[key])
print " %s = %s" % (key, value)
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 == "wpas":
cmd_wpas(argv)
elif cmd == "connect-hidden":
cmd_connect_hidden(argv)
elif cmd in ["technologies", "tech"]:
cmd_technologies(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()
|