| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
from __future__ import absolute_import, print_function, unicode_literals |
| 5 |
|
| 6 |
from optparse import OptionParser, make_option |
| 7 |
import sys |
| 8 |
import time |
| 9 |
import dbus |
| 10 |
import bluezutils |
| 11 |
import dbus.mainloop.glib |
| 12 |
try: |
| 13 |
from gi.repository import GObject |
| 14 |
except ImportError: |
| 15 |
import gobject as GObject |
| 16 |
|
| 17 |
bus = dbus.SystemBus() |
| 18 |
|
| 19 |
option_list = [ |
| 20 |
make_option("-i", "--device", action="store", |
| 21 |
type="string", dest="dev_id"), |
| 22 |
] |
| 23 |
parser = OptionParser(option_list=option_list) |
| 24 |
|
| 25 |
(options, args) = parser.parse_args() |
| 26 |
|
| 27 |
adapter_path = bluezutils.find_adapter(options.dev_id).object_path |
| 28 |
server = dbus.Interface(bus.get_object("org.bluez", adapter_path), |
| 29 |
"org.bluez.NetworkServer1") |
| 30 |
|
| 31 |
service = "nap" |
| 32 |
|
| 33 |
if (len(args) < 1): |
| 34 |
bridge = "tether" |
| 35 |
else: |
| 36 |
bridge = args[0] |
| 37 |
|
| 38 |
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) |
| 39 |
|
| 40 |
mainloop = GObject.MainLoop() |
| 41 |
|
| 42 |
server.Register(service, bridge) |
| 43 |
|
| 44 |
print("Server for %s registered for %s" % (service, bridge)) |
| 45 |
|
| 46 |
print("Press CTRL-C to disconnect") |
| 47 |
|
| 48 |
mainloop.run() |