コード例 #1
0
 def reconnectWhileBonded():
     isTestSuccessFull = bleAdapter.connect(runTest.testDevice)
     #since there is a bond with DUT, pairing is automatic
     if (isTestSuccessFull == True):
         isTestSuccessfull = bleAdapter.writeCharacteristic(
             runTest.DUT_ENCRYPT_CHAR_UUID, runTest.DUT_ENCRYPT_CHAR_UUID)
     runTest.submitTestResult(isTestSuccessFull,
                              runTest.reconnectWhileBonded)
コード例 #2
0
    def reconnectWhileNotBonded():
        isTestSuccessFull = bleAdapter.connect(runTest.testDevice)
        if isTestSuccessFull == False:
            print("reconnectWhileNotBonded test: Could not connect")
            sys.stdout.flush()
            runTest.submitTestResult(False, runTest.reconnectWhileNotBonded)
            return

        #Since secure connection only are accepted, pairing in "just works" shoud get rejected
        if bleAdapter.pair() == True:
            print("reconnectWhileNotBonded test: Able to pair in just Works mode")
            sys.stdout.flush()
            runTest.submitTestResult(False, runTest.reconnectWhileNotBonded)
            return

        runTest.submitTestResult(True, runTest.reconnectWhileNotBonded)
コード例 #3
0
    def Advertise_Interval_Consistent_After_BT_Reset(scan_filter,
                                                     bleAdapter):
        isTestSuccessFull = True
        runTest._advertisement_start(
            scan_filter=scan_filter,
            UUID=runTest.DUT_UUID_128,
            discoveryEvent_Cb=runTest.discoveryEventCb,
            bleAdapter=bleAdapter)
        secondKPI = runTest._scan_discovery_with_timer(bleAdapter)

        runTest._simple_connect()

        isTestSuccessFull = runTest.discoverPrimaryServices()
        bleAdapter.gatt.updateLocalAttributeTable( False )

        time.sleep(2)  # wait for connection parameters update
        # Second time disconnect
        isTestSuccessFull &= bleAdapter.disconnect()

        # Third time connection
        # wait for DUT to start advertising
        thirdKPI = runTest._scan_discovery_with_timer(bleAdapter)
        isTestSuccessFull &= bleAdapter.connect(runTest.testDevice)

        if thirdKPI > secondKPI * 10:
            isTestSuccessFull &= False

        # write result back to server
        isTestSuccessFull = runTest.discoverPrimaryServices()
        bleAdapter.gatt.updateLocalAttributeTable( False )

        isTestSuccessFull &= runTest.writeResultWithoutResponse(
            chr(isTestSuccessFull + 48))

        runTest.stopAdvertisement(scan_filter)
        isTestSuccessFull &= bleAdapter.disconnect()
        testutils.removeBondedDevices()

        return isTestSuccessFull
コード例 #4
0
 def _simple_connect():
     # Simple Connection test
     testDevice = runTest.getTestDevice()
     isTestSuccessFull = bleAdapter.connect(testDevice)
     time.sleep(2)  # wait for connection parameters update
コード例 #5
0
def main():
    scan_filter = dict()

    bleAdapter.init()
    agent = securityAgent.createSecurityAgent()

    scan_filter.update({"UUIDs": [runTest.DUT_UUID_128]})
    bleAdapter.setDiscoveryFilter(scan_filter)
    # Discovery test
    bleAdapter.startDiscovery(runTest.discoveryEventCb)
    runTest.mainloop.run()
    isTestSuccessFull = True
    runTest.submitTestResult(isTestSuccessFull, runTest.advertisement)
    bleAdapter.stopDiscovery()

    # Simple Connection test
    testDevice = runTest.getTestDevice()
    isTestSuccessFull = bleAdapter.connect(testDevice)
    runTest.submitTestResult(isTestSuccessFull, runTest.simpleConnection)
    time.sleep(2)  # wait for connection parameters update

    # Discover all primary services
    isTestSuccessFull = runTest.discoverPrimaryServices()
    runTest.submitTestResult(isTestSuccessFull,
                             runTest.discoverPrimaryServices)

    bleAdapter.gatt.updateLocalAttributeTable()

    # Check device not present. After discovery of services, advertisement
    # should have stopped.
    runTest.stopAdvertisement(scan_filter)

    # Change MTU size
    # bleAdapter.readLocalMTU()

    # Check attribute table UUIDs
    bleAdapter.gatt.updateLocalAttributeTable()
    isTestSuccessFull = runTest.checkUUIDs(bleAdapter.gatt)
    runTest.submitTestResult(isTestSuccessFull, runTest.checkUUIDs)

    # Check attribute table properties
    isTestSuccessFull = runTest.checkProperties(bleAdapter.gatt)
    runTest.submitTestResult(isTestSuccessFull, runTest.checkProperties)

    # CHeck long write
    isTestSuccessFull = runTest.writeLongCharacteristic()
    runTest.submitTestResult(isTestSuccessFull,
                             runTest.writeLongCharacteristic)

    # Check read/write, simple connection
    isTestSuccessFull = runTest.readWriteSimpleConnection()
    runTest.submitTestResult(isTestSuccessFull,
                             runTest.readWriteSimpleConnection)

    # check write without response
    isTestSuccessFull = runTest.writeWithoutResponse()
    runTest.submitTestResult(isTestSuccessFull, runTest.writeWithoutResponse)

    # Enable and receive notification and indication then disable.
    bleAdapter.setNotificationCallBack(runTest.notificationCb)
    bleAdapter.subscribeForNotification(
        runTest.DUT_NOTIFY_CHAR_UUID)  # subscribe for next test
    bleAdapter.subscribeForNotification(
        runTest.DUT_INDICATE_CHAR_UUID)  # subscribe for next test
    isTestSuccessFull = True
    runTest.mainloop.run()
    runTest.submitTestResult(isTestSuccessFull, runTest.notification)

    bleAdapter.setNotificationCallBack(runTest.indicationCb)
    isTestSuccessFull = True
    runTest.mainloop.run()
    runTest.submitTestResult(isTestSuccessFull, runTest.indication)

    isTestSuccessFull = bleAdapter.subscribeForNotification(
        runTest.DUT_NOTIFY_CHAR_UUID, subscribe=False)  # unsubscribe
    isTestSuccessFull = True
    runTest.submitTestResult(isTestSuccessFull, runTest.removeNotification)

    isTestSuccessFull = bleAdapter.subscribeForNotification(
        runTest.DUT_INDICATE_CHAR_UUID, subscribe=False)  # unsubscribe
    isTestSuccessFull = True
    runTest.submitTestResult(isTestSuccessFull, runTest.removeIndication)

    # Check writing to protected characteristic triggers pairing
    isTestSuccessFull = runTest.pairing()
    runTest.submitTestResult(isTestSuccessFull, runTest.pairing)
    bleAdapter.bondToRemoteDevice()

    # Check writing to protected characteristic after successfull pairing
    # succeed
    time.sleep(2)  # wait before starting next test
    isTestSuccessFull = runTest.readWriteProtectedAttributesWhilePaired()
    runTest.submitTestResult(isTestSuccessFull,
                             runTest.readWriteProtectedAttributesWhilePaired)

    # disconnect, Note it is not a test happening on bluez, the DUT is waiting
    # for a disconnect Cb
    runTest.disconnect()

    # reconnect! Since devices bonded, it should not ask for pairing again.
    # Security agent can be destroyed
    # remove security agent so as not to trigger auto pairing.
    securityAgent.removeSecurityAgent()
    bleAdapter.setDiscoveryFilter(scan_filter)
    # wait for DUT to start advertising
    bleAdapter.startDiscovery(runTest.discoveryStartedCb)
    runTest.mainloop.run()
    bleAdapter.stopDiscovery()
    runTest.reconnectWhileBonded()

    # reconnect while not bonded. Pairing should fail since Just works is not
    # accepted
    bleAdapter.disconnect()
    bleAdapter.removeBondedDevices()
    time.sleep(2)  # wait for bonded devices to be deleted
    bleAdapter.setDiscoveryFilter(scan_filter)
    bleAdapter.startDiscovery(runTest.discoveryEventCb)
    runTest.mainloop.run()
    bleAdapter.stopDiscovery()

    agent = securityAgent.createSecurityAgent("NoInputNoOutput", agent)
    runTest.reconnectWhileNotBonded()

    time.sleep(2)
    runTest.printTestsSummary()