HTC Touch Diamond mit Ubuntu nutzen

Mit Hilfe des USB-Kabels lässt sich der interne Speicher des Touch’ nutzen; Internetzugang sollte über Bluetooth mit Hilfe von PAN funktionieren. Ich bin aber noch nicht dazu gekommen, das zu testen.
Die Synchronisation zwischen PDA und Notebook dürfte mit SyncCE funktionieren. Auch dies habe ich noch nicht getestet.

PAN wird übrigens in einer der nächsten Versionen des NetworkManagers integriert werden. Es existiert zwar bereits ein Patch, der libbluez ansteuert. Der Patch ist allerdings gegen die Revision 2574 von NM programmiert worden.
Momentan ist aktuell die Revision 4xxx. Ich hab’ vorgestern versucht, den Patch auf den aktuellen NM-Trunk upzudaten – leider ohne Erfolg und zugegebenermaßen auch mit wenig Lust. War eine stupide Arbeit, beide Forks mit dem Patch abzugleichen.

Die Jungs von Launchpad diskutieren die Integration von PAN in NM hier. Im NetworkManager-Tracker ist der PAN-Request hier zu finden, inkl. des veralteten Patches.

Edith: Ich bin eeeUser-Forum über einen Thread gestolpert, in dem ein kleines Python-PAN-Script vorgestellt wird.

Hier der Code:

#!/usr/bin/env python
# (c) 2008 Kyle Reed
# PAN tethering with WM device w/o using deprecated pand
# I don't claim to know Python, use at your own risk 😉

import pygtk
pygtk.require('2.0')
import gtk
import dbus
import os

### For passing errors to the GUI ###
class BTException:
def __init__(self, msg):
self.error_msg = msg

### BT Helper handles all of the DBUS stuff ###
# usage flow:
# __init__
# getDevicesList
# selectNetworkDevice
# getDeviceProperties
# Connnect|Disconnect
class BTHelper:
# create the helper object and initialize dbus
def __init__(self):
# get the system bus object
self.bus = dbus.SystemBus()

# get the adapter interface to query paired devices
self.adapter = dbus.Interface(self.bus.get_object(
'org.bluez', '/org/bluez/hci0'), 'org.bluez.Adapter')

# get the devices list #
def getDevicesList(self):
try:
self.devices = self.adapter.ListDevices()
return self.devices
except dbus.DBusException:
raise BTException('Could not get adapter interface, is your BT adapter on?')

# get the name of a device from a device string
# doesn't require selectNetworkDevice to be called
def getDeviceName(self, devicePath):
try:
tempDev = dbus.Interface(self.bus.get_object(
'org.bluez', devicePath), 'org.bluez.Device')
tempProps = tempDev.GetProperties()
return tempProps['Alias']
except dbus.DBusException:
return '[Error Fetching Name]'

# select device to query by index #
def selectNetworkDevice(self, index):
try:
self.current_device = dbus.Interface(self.bus.get_object(
'org.bluez', self.devices[index]), 'org.bluez.Network')
except dbus.DBusException:
raise BTException('Could not get network interface for device, is your device active?')

# returns information about the device #
def getDeviceProperties(self):
try:
self.deviceProps = self.current_device.GetProperties()
return self.deviceProps
except dbus.DBusException:
raise BTException('Could not get properties for device, did you select a device?')

# connects and initializes the connection #
def connectDevice(self):
if self.deviceProps['Connected'] == 0:
print 'Connecting...'

try:
# connect and get interface
iface = self.current_device.Connect('NAP')
print 'Using network interface ' + iface

# bring up the interface and start DHCP
os.system('ifconfig up ' + iface)
os.system('dhclient ' + iface)
print 'Connected'
except dbus.DBusException, e:
raise BTException('Connect Failed: %s' % (e))
else:
print 'Already Connected'

def disconnectDevice(self):
if self.deviceProps['Connected']:
print 'Disconnecting...'

try:
# bring down interface
os.system('ifdown ' + self.deviceProps['Device'])

# disconnect
self.current_device.Disconnect()
print 'Disconnected'
except dbus.DBusException, e:
raise BTException('Disconnect Failed: %s' % (e))
else:
print 'Not Connected'
### End BTHelper ###

### Defines the class that draws the GUI ###
class BTHelperGUI:
titleText = 'BlueTooth PAN Helper'

# show an exception message
def showErrorMsg(self, msg):
errorDlg = gtk.MessageDialog(self.window, gtk.DIALOG_MODAL,
gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, msg)
errorDlg.set_title(self.titleText)
errorDlg.run()
errorDlg.destroy()

### Signal Handler Methods
# exit button click
def handleExitClicked(self, widget, data=None):
print('Exiting')
self.exit()

# connect button clicked
def handleConnectClicked(self, widget, data=None):
try:
self.BTHelp.connectDevice()
self.getDeviceInformation()
except BTException, e:
self.showErrorMsg(e.error_msg)

# disconnect button clicked
def handleDisconnectClicked(self, widget, data=None):
try:
self.BTHelp.disconnectDevice()
self.getDeviceInformation()
except BTException, e:
self.showErrorMsg(e.error_msg)

# device selection changed
def handleDeviceSelectionChanged(self, widget, data=None):
selection = self.devicesListView.get_selection()
selectedIter = selection.get_selected()[1]

# nothing selected, return
if(selectedIter is None):
self.setButtonState(-1)
return

selectedIndex = self.devicesListStore.get_value(selectedIter, 2)
print('Selected %s' % (selectedIndex))
try:
self.BTHelp.selectNetworkDevice(selectedIndex)
self.getDeviceInformation()
except BTException, e:
self.showErrorMsg(e.error_msg)

# window manager is closing us (event)
def delete_event(self, widget, event, data=None):
self.exit()
return False
### End handler methods

### support methods ###
# process device names and add to devices list store
def processDevicesList(self):
# list devicees from the BT Adapter
try:
allDevices = self.BTHelp.getDevicesList()
count = 0;
for device in allDevices:
addrOnly = device.split('dev_')[-1]
addrOnly = addrOnly.replace('_', ':')
self.devicesListStore.append([addrOnly,
self.BTHelp.getDeviceName(device), count])
count += 1
except BTException, e:
self.showErrorMsg(e.error_msg)
# hard exit because we haven't stated the main loop
quit()

# get selected device information and set up controls
def getDeviceInformation(self):
try:
properties = self.BTHelp.getDeviceProperties()
self.statsListStore.clear()
self.statsListStore.append(['Connected',str(properties['Connected'])])
self.statsListStore.append(['Device',str(properties['Device'])])

self.setButtonState(int(properties['Connected']))
except BTException, e:
self.showErrorMsg(e.error_msg)

# enable/disable buttons are required
def setButtonState(self, state):
if(state == -1): # none selected
self.connectBtn.set_sensitive(False)
self.disconnectBtn.set_sensitive(False)
elif(state == 0): # disconnected
self.connectBtn.set_sensitive(True)
self.disconnectBtn.set_sensitive(False)
elif(state == 1): # connected
self.connectBtn.set_sensitive(False)
self.disconnectBtn.set_sensitive(True)

# common exit point for program
def exit(self):
gtk.main_quit()
### end support methods ###

def __init__(self):
self.BTHelp = BTHelper()

# create the main window
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title(self.titleText)
self.window.set_default_size(400, 300)
self.window.set_border_width(10)

# set handlers for window events
self.window.connect('delete_event', self.delete_event)

# Devices list view
# set up data backend for devices list
# addr, name, index (hidden)
self.devicesListStore = gtk.ListStore(str, str, int)
self.processDevicesList()

# create devices list columns
devicesListCol = gtk.TreeViewColumn('Device Address')
devicesListCol2 = gtk.TreeViewColumn('Device Name')

# make text renderers and add to columns
addrCell = gtk.CellRendererText()
nameCell = gtk.CellRendererText()
devicesListCol.pack_start(addrCell, True)
devicesListCol2.pack_start(nameCell, True)

# set cell mappings to store data
devicesListCol.add_attribute(addrCell, 'text', 0)
devicesListCol2.add_attribute(nameCell, 'text', 1)

# create devices list and add columns
self.devicesListView = gtk.TreeView(self.devicesListStore)
self.devicesListView.append_column(devicesListCol)
self.devicesListView.append_column(devicesListCol2)

# set signal handlers for devices list
self.devicesListView.connect('cursor-changed', self.handleDeviceSelectionChanged)
# end devices list view

# stats list view
# create stats list data store
self.statsListStore = gtk.ListStore(str, str)
self.statsListStore.append(['Connected', ''])
self.statsListStore.append(['Device', ''])

# create stats columns
statsCol = gtk.TreeViewColumn('Property')
statsCol2 = gtk.TreeViewColumn('Value')

# create text renderers and add to columns
propCell = gtk.CellRendererText()
valueCell = gtk.CellRendererText()
statsCol.pack_start(propCell, True)
statsCol2.pack_start(valueCell, True)

# set data mappings with data store
statsCol.add_attribute(propCell, 'text', 0)
statsCol2.add_attribute(valueCell, 'text', 1)

# create stats list view
self.statsListView = gtk.TreeView(self.statsListStore)
self.statsListView.append_column(statsCol)
self.statsListView.append_column(statsCol2)
# end stats list view

# control buttons
self.connectBtn = gtk.Button('Connect')
self.disconnectBtn = gtk.Button('Disconnect')
self.exitBtn = gtk.Button('Exit')

# set handlers
self.exitBtn.connect('clicked', self.handleExitClicked)
self.connectBtn.connect('clicked', self.handleConnectClicked)
self.disconnectBtn.connect('clicked', self.handleDisconnectClicked)

# pack in a VBox
buttonBox = gtk.VBox(True, 2)
buttonBox.set_border_width(10)
buttonBox.pack_start(self.connectBtn)
buttonBox.pack_start(self.disconnectBtn)
buttonBox.pack_start(self.exitBtn)

# frames for decoration
statsFrame = gtk.Frame(' Status ')
statsFrame.add(self.statsListView)

buttonFrame = gtk.Frame(' Actions ')
buttonFrame.add(buttonBox)
# end control buttons

# add controls to layout
# +-----------------+
# | DEVLIST AREA    |
# +-----+-----------+
# |STATS|BUTTONS    |
# +-----+-----------+

tableLayout = gtk.Table(2, 2, False)
tableLayout.set_row_spacings(10)
tableLayout.set_col_spacings(10)
tableLayout.attach(self.devicesListView, 0, 2, 0, 1)
tableLayout.attach(statsFrame, 0, 1, 1, 2)
tableLayout.attach(buttonFrame, 1, 2, 1, 2)

# add layout to window
self.window.add(tableLayout)
self.window.show_all()

def main(self):
gtk.main()
### End BTHelperGUI ###

### Program Execution here ###
print('BlueTooth PAN Helper GUI')
btgui = BTHelperGUI()
btgui.main()

Good job!

Ich hab es auf meinem Touch ausprobiert und es funktioniert einwandfrei. Wichtig: Das Script als root starten. Auf dem Touch muss unter Programme -> Internet Freigabe bei PC-Verbindung “Bluetooth-PAN” ausgewählt und danach das Handy mit dem Notebook gepairt werden.
Ich bin mal wieder von Linux begeistert. Und von meinem neuen Handy auch 😉

Leave a reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>