1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2008-2013 Team XBMC
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 from bluetooth import *
20 import bluetooth._bluetooth as _bt
24 def __init__(self, bdaddress=None):
25 self.cport = 0x11 # HID's control PSM
26 self.iport = 0x13 # HID' interrupt PSM
31 self.address = bdaddress
33 # create the HID control socket
34 self.csock = BluetoothSocket( L2CAP )
35 self.csock.bind((self.address, self.cport))
36 set_l2cap_mtu(self.csock, 64)
37 self.csock.settimeout(2)
38 self.csock.listen(self.backlog)
40 # create the HID interrupt socket
41 self.isock = BluetoothSocket( L2CAP )
42 self.isock.bind((self.address, self.iport))
43 set_l2cap_mtu(self.isock, 64)
44 self.isock.settimeout(2)
45 self.isock.listen(self.backlog)
47 self.connected = False
52 (self.client_csock, self.caddress) = self.csock.accept()
53 print "Accepted Control connection from %s" % self.caddress[0]
54 (self.client_isock, self.iaddress) = self.isock.accept()
55 print "Accepted Interrupt connection from %s" % self.iaddress[0]
59 self.connected = False
62 def get_local_address(self):
63 hci = BluetoothSocket( HCI )
65 buf = array.array('B', [0] * 96)
66 fcntl.ioctl(fd, _bt.HCIGETDEVINFO, buf, 1)
67 data = struct.unpack_from("H8s6B", buf.tostring())
68 return data[2:8][::-1]
70 def get_control_socket(self):
72 return (self.client_csock, self.caddress)
77 def get_interrupt_socket(self):
79 return (self.client_isock, self.iaddress)