def lookup_name(self,address, device=-1, timeout=10):
      """
      Linux only

      Tries to determine the friendly name (human readable) of the device with
      the specified bluetooth address.  Returns the name on success, and None
      on failure.

      timeout=10   how many seconds to search before giving up.
      """
      logger.debug("Device: %s " % (device))
      if sys.platform == "linux2":
        # NOTE: I had to rewrite this for the latest bluez, 
        # the reason this is complicated is because I need to select the device,
        # before making the call.
        # http://code.google.com/p/pybluez/source/detail?spec=svn27&r=22
        if not bluetooth.is_valid_address(address): 
            raise ValueError("%s is not a valid Bluetooth address" % address)
        
        try:
            sock = _bt.hci_open_dev (device)
        except:
            raise ValueError("error accessing bluetooth device")

        timeoutms = int (timeout * 1000)
        try: 
            name = _bt.hci_read_remote_name (sock, address, timeoutms)
        except _bt.error, e:
            # name lookup failed.  either a timeout, or I/O error
            name = None
            sock.close()
        return name          
        def lookup_name(self, address, device=-1, timeout=10):
            """
      Linux only

      Tries to determine the friendly name (human readable) of the device with
      the specified bluetooth address.  Returns the name on success, and None
      on failure.

      timeout=10   how many seconds to search before giving up.
      """
            logger.debug("Device: %s " % (device))
            if sys.platform == "linux2":
                # NOTE: I had to rewrite this for the latest bluez,
                # the reason this is complicated is because I need to select the device,
                # before making the call.
                # http://code.google.com/p/pybluez/source/detail?spec=svn27&r=22
                if not bluetooth.is_valid_address(address):
                    raise ValueError("%s is not a valid Bluetooth address" %
                                     address)

                try:
                    sock = _bt.hci_open_dev(device)
                except:
                    raise ValueError("error accessing bluetooth device")

                timeoutms = int(timeout * 1000)
                try:
                    name = _bt.hci_read_remote_name(sock, address, timeoutms)
                except _bt.error, e:
                    # name lookup failed.  either a timeout, or I/O error
                    name = None
                    sock.close()
                return name
Esempio n. 3
0
def discover_devices (duration=8, flush_cache=True, lookup_names=False,
                      lookup_class=False, device_id=-1, iac=IAC_GIAC):
    if device_id == -1:
        device_id = _bt.hci_get_route()

    sock = _gethcisock (device_id)
    try:
        results = _bt.hci_inquiry (sock, duration=duration, flush_cache=True,
                                   lookup_class=lookup_class, device_id=device_id,
                                   iac=iac)
    except _bt.error as e:
        sock.close ()
        raise BluetoothError (e.args[0], "Error communicating with local "
        "bluetooth adapter: " + e.args[1])

    if lookup_names:
        pairs = []
        for item in results:
            if lookup_class:
                addr, dev_class = item
            else:
                addr = item
            timeoutms = int (10 * 1000)
            try:
                name = _bt.hci_read_remote_name (sock, addr, timeoutms)
            except _bt.error:
                # name lookup failed.  either a timeout, or I/O error
                continue
            pairs.append ((addr, name, dev_class) if lookup_class else (addr, name))
        sock.close ()
        return pairs
    else:
        sock.close ()
        return results
Esempio n. 4
0
def lookup_name (address, timeout=10):
    if not is_valid_address (address):
        raise BluetoothError (EINVAL, "%s is not a valid Bluetooth address" % address)

    sock = _gethcisock ()
    timeoutms = int (timeout * 1000)
    try:
        name = _bt.hci_read_remote_name (sock, address, timeoutms)
    except _bt.error:
        # name lookup failed.  either a timeout, or I/O error
        name = None
    sock.close ()
    return name
Esempio n. 5
0
                    if match == False:
                        # Add this entry to the list
                        nowstr = str(datetime.datetime.now())
                        details = [["First seen: " + nowstr]]
                        details[0].append("Last Seen: " + nowstr)
                        details[0].append("OUI Vendor: " +
                                          bthandler.bt_print_device_manuf(
                                              addr[0:8].replace(":", "")))

                        # retrieve friendly name
                        timeout = 5000  # ms

                        try:
                            if self.ui.scanmode == 0:
                                name = bluez.hci_read_remote_name(
                                    self.sock, addr, timeout)
                            else:
                                name = "<Not Enumerated>"

                        except bluez.error, e:
                            # Name lookup failed, timeout or I/O error
                            name = "<Unknown>"

                        devclass_raw = struct.unpack(
                            "BBB",
                            pkt[1 + 8 * nrsp + 3 * i:1 + 8 * nrsp + 3 * i + 3])
                        devclass_str = bthandler.bt_devclass(
                            (int(devclass_raw[1] & 0x1f)),
                            int(devclass_raw[0] >> 2))

                        idev = [addr, name, devclass_str]