blob: 3ed823deb6a0e2e890248eefe651a9bdbdc15c16 [file] [log] [blame]
#!/usr/bin/python
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# Set the APN to be used when making connections on a cellular
# service.
import sys
import dbus, flimflam
from optparse import OptionParser
usage = '''
%prog [options] apn service-name
or
%prog --clear service-name'''
parser = OptionParser(usage=usage)
parser.add_option('-n', '--network_id', type='string',
dest='network_id',
default=None,
help='user name to be used with the APN')
parser.add_option('-u', '--username', type='string',
dest='username',
default=None,
help='user name to be used with the APN')
parser.add_option('-p', '--password', type='string',
dest='password',
default=None,
help='password to be used with the APN')
parser.add_option('-c', '--clear',
action='store_true', dest='clear_apn',
default=False,
help='Clear any APN associated with the named service')
(options, args) = parser.parse_args()
props = dbus.Dictionary(signature="ss")
if not options.clear_apn:
if len(args) < 1:
parser.error("The APN and service name must be specified")
elif len(args) < 2:
parser.error("The service name must be specified")
elif len(args) > 2:
parser.error("Too many arguments")
apn = args[0]
servicename = args[1]
props['apn'] = apn
if options.network_id:
props['network_id'] = options.network_id
if options.username:
props['username'] = options.username
if options.password:
props['password'] = options.password
else:
if len(args) < 1:
parser.error("The service name must be specified")
servicename = args[0]
flim = flimflam.FlimFlam(dbus.SystemBus())
service = flim.FindElementByNameSubstring('Service', servicename)
if not service:
print "Unknown service %s" % servicename
sys.exit(2)
if not options.clear_apn:
service.SetProperty("Cellular.APN", props)
else:
service.ClearProperty("Cellular.APN")