def test_attach(self): """Functional test case / Attach test cases / attach Validates that attaching to the Wi-Fi Aware service works (receive the expected callback). """ dut = self.android_devices[0] dut.droid.wifiAwareAttach(False) autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) autils.fail_on_event(dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED)
def verify_discovery_session_term(self, dut, disc_id, config, is_publish, term_ind_on): """Utility to verify that the specified discovery session has terminated (by waiting for the TTL and then attempting to reconfigure). Args: dut: device under test disc_id: discovery id for the existing session config: configuration of the existing session is_publish: True if the configuration was publish, False if subscribe term_ind_on: True if a termination indication is expected, False otherwise """ # Wait for session termination if term_ind_on: autils.wait_for_event( dut, autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED, disc_id)) else: # can't defer wait to end since in any case have to wait for session to # expire autils.fail_on_event( dut, autils.decorate_event(aconsts.SESSION_CB_ON_SESSION_TERMINATED, disc_id)) # Validate that session expired by trying to configure it (expect failure) config[aconsts.DISCOVERY_KEY_SSI] = "something else" if is_publish: dut.droid.wifiAwareUpdatePublish(disc_id, config) else: dut.droid.wifiAwareUpdateSubscribe(disc_id, config) # The response to update discovery session is: # term_ind_on=True: session was cleaned-up so won't get an explicit failure, but won't get a # success either. Can check for no SESSION_CB_ON_SESSION_CONFIG_UPDATED but # will defer to the end of the test (no events on queue). # term_ind_on=False: session was not cleaned-up (yet). So expect # SESSION_CB_ON_SESSION_CONFIG_FAILED. if not term_ind_on: autils.wait_for_event( dut, autils.decorate_event( aconsts.SESSION_CB_ON_SESSION_CONFIG_FAILED, disc_id))
def test_attach_multiple_sessions(self): """Functional test case / Attach test cases / multiple attach sessions Validates that when creating multiple attach sessions each can be configured independently as to whether or not to receive an identity callback. """ dut = self.android_devices[0] # Create 3 attach sessions: 2 without identity callback, 1 with id1 = dut.droid.wifiAwareAttach(False, None, True) time.sleep(10) # to make sure all calls and callbacks are done id2 = dut.droid.wifiAwareAttach(True, None, True) time.sleep(10) # to make sure all calls and callbacks are done id3 = dut.droid.wifiAwareAttach(False, None, True) dut.log.info('id1=%d, id2=%d, id3=%d', id1, id2, id3) # Attach session 1: wait for attach, should not get identity autils.wait_for_event( dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id1)) autils.fail_on_event( dut, autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id1)) # Attach session 2: wait for attach and for identity callback autils.wait_for_event( dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id2)) autils.wait_for_event( dut, autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id2)) # Attach session 3: wait for attach, should not get identity autils.wait_for_event( dut, autils.decorate_event(aconsts.EVENT_CB_ON_ATTACHED, id3)) autils.fail_on_event( dut, autils.decorate_event(aconsts.EVENT_CB_ON_IDENTITY_CHANGED, id3))
def run_mismatched_ib_data_path_test(self, pub_mismatch, sub_mismatch): """Runs the negative in-band data-path tests: mismatched peer ID. Args: pub_mismatch: Mismatch the publisher's ID sub_mismatch: Mismatch the subscriber's ID """ (p_dut, s_dut, p_id, s_id, p_disc_id, s_disc_id, peer_id_on_sub, peer_id_on_pub) = self.set_up_discovery( aconsts.PUBLISH_TYPE_UNSOLICITED, aconsts.SUBSCRIBE_TYPE_PASSIVE, True) if pub_mismatch: peer_id_on_pub = peer_id_on_pub - 1 if sub_mismatch: peer_id_on_sub = peer_id_on_sub - 1 # Publisher: request network p_req_key = self.request_network( p_dut, p_dut.droid.wifiAwareCreateNetworkSpecifier( p_disc_id, peer_id_on_pub, None)) # Subscriber: request network s_req_key = self.request_network( s_dut, s_dut.droid.wifiAwareCreateNetworkSpecifier( s_disc_id, peer_id_on_sub, None)) # Publisher & Subscriber: fail on network formation time.sleep(autils.EVENT_NDP_TIMEOUT) autils.fail_on_event(p_dut, cconsts.EVENT_NETWORK_CALLBACK, timeout=0) autils.fail_on_event(s_dut, cconsts.EVENT_NETWORK_CALLBACK, timeout=0) # clean-up p_dut.droid.connectivityUnregisterNetworkCallback(p_req_key) s_dut.droid.connectivityUnregisterNetworkCallback(s_req_key)
def discovery_mismatch_test_utility(self, is_expected_to_pass, p_type, s_type, p_service_name=None, s_service_name=None, p_mf_1=None, s_mf_1=None): """Utility which runs the negative discovery test for mismatched service configs. Args: is_expected_to_pass: True if positive test, False if negative p_type: Publish discovery type s_type: Subscribe discovery type p_service_name: Publish service name (or None to leave unchanged) s_service_name: Subscribe service name (or None to leave unchanged) p_mf_1: Publish match filter element [1] (or None to leave unchanged) s_mf_1: Subscribe match filter element [1] (or None to leave unchanged) """ p_dut = self.android_devices[0] p_dut.pretty_name = "Publisher" s_dut = self.android_devices[1] s_dut.pretty_name = "Subscriber" # create configurations p_config = self.create_publish_config(p_dut.aware_capabilities, p_type, self.PAYLOAD_SIZE_TYPICAL, ttl=0, term_ind_on=False, null_match=False) if p_service_name is not None: p_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = p_service_name if p_mf_1 is not None: p_config[ aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list([ (10).to_bytes(1, byteorder="big"), p_mf_1, bytes(range(40)) ]) s_config = self.create_publish_config(s_dut.aware_capabilities, s_type, self.PAYLOAD_SIZE_TYPICAL, ttl=0, term_ind_on=False, null_match=False) if s_service_name is not None: s_config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = s_service_name if s_mf_1 is not None: s_config[ aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] = autils.encode_list([ (10).to_bytes(1, byteorder="big"), s_mf_1, bytes(range(40)) ]) p_id = p_dut.droid.wifiAwareAttach(False) autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED) time.sleep(self.device_startup_offset) s_id = s_dut.droid.wifiAwareAttach(False) autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED) # Publisher: start publish and wait for confirmation p_disc_id = p_dut.droid.wifiAwarePublish(p_id, p_config) autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED) # Subscriber: start subscribe and wait for confirmation s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, s_config) autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED) # Subscriber: fail on service discovery if is_expected_to_pass: autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED) else: autils.fail_on_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED) # Publisher+Subscriber: Terminate sessions p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id) s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id) # verify that there were no other events (including terminations) time.sleep(autils.EVENT_TIMEOUT) autils.verify_no_more_events(p_dut, timeout=0) autils.verify_no_more_events(s_dut, timeout=0)
def positive_discovery_test_utility(self, ptype, stype, payload_size): """Utility which runs a positive discovery test: - Discovery (publish/subscribe) with TTL=0 (non-self-terminating) - Exchange messages - Update publish/subscribe - Terminate Args: ptype: Publish discovery type stype: Subscribe discovery type payload_size: One of PAYLOAD_SIZE_* constants - MIN, TYPICAL, MAX """ p_dut = self.android_devices[0] p_dut.pretty_name = "Publisher" s_dut = self.android_devices[1] s_dut.pretty_name = "Subscriber" # Publisher+Subscriber: attach and wait for confirmation p_id = p_dut.droid.wifiAwareAttach(False) autils.wait_for_event(p_dut, aconsts.EVENT_CB_ON_ATTACHED) time.sleep(self.device_startup_offset) s_id = s_dut.droid.wifiAwareAttach(False) autils.wait_for_event(s_dut, aconsts.EVENT_CB_ON_ATTACHED) # Publisher: start publish and wait for confirmation p_config = self.create_publish_config(p_dut.aware_capabilities, ptype, payload_size, ttl=0, term_ind_on=False, null_match=False) p_disc_id = p_dut.droid.wifiAwarePublish(p_id, p_config) autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_PUBLISH_STARTED) # Subscriber: start subscribe and wait for confirmation s_config = self.create_subscribe_config(s_dut.aware_capabilities, stype, payload_size, ttl=0, term_ind_on=False, null_match=True) s_disc_id = s_dut.droid.wifiAwareSubscribe(s_id, s_config) autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED) # Subscriber: wait for service discovery discovery_event = autils.wait_for_event( s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED) peer_id_on_sub = discovery_event["data"][ aconsts.SESSION_CB_KEY_PEER_ID] # Subscriber: validate contents of discovery: # - SSI: publisher's # - Match filter: UNSOLICITED - publisher, SOLICITED - subscriber autils.assert_equal_strings( bytes(discovery_event["data"][ aconsts.SESSION_CB_KEY_SERVICE_SPECIFIC_INFO]).decode("utf-8"), p_config[aconsts.DISCOVERY_KEY_SSI], "Discovery mismatch: service specific info (SSI)") asserts.assert_equal( autils.decode_list(discovery_event["data"][ aconsts.SESSION_CB_KEY_MATCH_FILTER_LIST]), autils.decode_list( p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] if ptype == aconsts.PUBLISH_TYPE_UNSOLICITED else s_config[ aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]), "Discovery mismatch: match filter") # Subscriber: send message to peer (Publisher) s_dut.droid.wifiAwareSendMessage(s_disc_id, peer_id_on_sub, self.get_next_msg_id(), self.query_msg, self.msg_retx_count) autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT) # Publisher: wait for received message pub_rx_msg_event = autils.wait_for_event( p_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED) peer_id_on_pub = pub_rx_msg_event["data"][ aconsts.SESSION_CB_KEY_PEER_ID] # Publisher: validate contents of message asserts.assert_equal( pub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING], self.query_msg, "Subscriber -> Publisher message corrupted") # Publisher: send message to peer (Subscriber) p_dut.droid.wifiAwareSendMessage(p_disc_id, peer_id_on_pub, self.get_next_msg_id(), self.response_msg, self.msg_retx_count) autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_MESSAGE_SENT) # Subscriber: wait for received message sub_rx_msg_event = autils.wait_for_event( s_dut, aconsts.SESSION_CB_ON_MESSAGE_RECEIVED) # Subscriber: validate contents of message asserts.assert_equal( sub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_PEER_ID], peer_id_on_sub, "Subscriber received message from different peer ID then discovery!?" ) autils.assert_equal_strings( sub_rx_msg_event["data"][aconsts.SESSION_CB_KEY_MESSAGE_AS_STRING], self.response_msg, "Publisher -> Subscriber message corrupted") # Subscriber: validate that we're not getting another Service Discovery autils.fail_on_event(s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED) # Publisher: update publish and wait for confirmation p_config[aconsts.DISCOVERY_KEY_SSI] = "something else" p_dut.droid.wifiAwareUpdatePublish(p_disc_id, p_config) autils.wait_for_event(p_dut, aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED) # Subscriber: expect a new service discovery discovery_event = autils.wait_for_event( s_dut, aconsts.SESSION_CB_ON_SERVICE_DISCOVERED) # Subscriber: validate contents of discovery autils.assert_equal_strings( bytes(discovery_event["data"][ aconsts.SESSION_CB_KEY_SERVICE_SPECIFIC_INFO]).decode("utf-8"), p_config[aconsts.DISCOVERY_KEY_SSI], "Discovery mismatch (after pub update): service specific info (SSI)" ) asserts.assert_equal( autils.decode_list(discovery_event["data"][ aconsts.SESSION_CB_KEY_MATCH_FILTER_LIST]), autils.decode_list( p_config[aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST] if ptype == aconsts.PUBLISH_TYPE_UNSOLICITED else s_config[ aconsts.DISCOVERY_KEY_MATCH_FILTER_LIST]), "Discovery mismatch: match filter") # Subscribe: update subscribe and wait for confirmation s_config = self.create_subscribe_config(s_dut.aware_capabilities, stype, payload_size, ttl=0, term_ind_on=False, null_match=False) s_dut.droid.wifiAwareUpdateSubscribe(s_disc_id, s_config) autils.wait_for_event(s_dut, aconsts.SESSION_CB_ON_SESSION_CONFIG_UPDATED) # Publisher+Subscriber: Terminate sessions p_dut.droid.wifiAwareDestroyDiscoverySession(p_disc_id) s_dut.droid.wifiAwareDestroyDiscoverySession(s_disc_id) # sleep for timeout period and then verify all 'fail_on_event' together time.sleep(autils.EVENT_TIMEOUT) # verify that there were no other events autils.verify_no_more_events(p_dut, timeout=0) autils.verify_no_more_events(s_dut, timeout=0) # verify that forbidden callbacks aren't called autils.validate_forbidden_callbacks(p_dut, {aconsts.CB_EV_MATCH: 0})
def run_mismatched_oob_data_path_test(self, init_mismatch_mac=False, resp_mismatch_mac=False, init_encr_type=ENCR_TYPE_OPEN, resp_encr_type=ENCR_TYPE_OPEN): """Runs the negative out-of-band data-path tests: mismatched information between Responder and Initiator. Args: init_mismatch_mac: True to mismatch the Initiator MAC address resp_mismatch_mac: True to mismatch the Responder MAC address init_encr_type: Encryption type of Initiator - ENCR_TYPE_* resp_encr_type: Encryption type of Responder - ENCR_TYPE_* """ init_dut = self.android_devices[0] init_dut.pretty_name = "Initiator" resp_dut = self.android_devices[1] resp_dut.pretty_name = "Responder" # Initiator+Responder: attach and wait for confirmation & identity init_id = init_dut.droid.wifiAwareAttach(True) autils.wait_for_event(init_dut, aconsts.EVENT_CB_ON_ATTACHED) init_ident_event = autils.wait_for_event( init_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED) init_mac = init_ident_event["data"]["mac"] time.sleep(self.device_startup_offset) resp_id = resp_dut.droid.wifiAwareAttach(True) autils.wait_for_event(resp_dut, aconsts.EVENT_CB_ON_ATTACHED) resp_ident_event = autils.wait_for_event( resp_dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED) resp_mac = resp_ident_event["data"]["mac"] if init_mismatch_mac: # assumes legit ones don't start with "00" init_mac = "00" + init_mac[2:] if resp_mismatch_mac: resp_mac = "00" + resp_mac[2:] # wait for for devices to synchronize with each other - there are no other # mechanisms to make sure this happens for OOB discovery (except retrying # to execute the data-path request) time.sleep(self.WAIT_FOR_CLUSTER) # set up separate keys: even if types are the same we want a mismatch init_passphrase = None init_pmk = None if init_encr_type == self.ENCR_TYPE_PASSPHRASE: init_passphrase = self.PASSPHRASE elif init_encr_type == self.ENCR_TYPE_PMK: init_pmk = self.PMK resp_passphrase = None resp_pmk = None if resp_encr_type == self.ENCR_TYPE_PASSPHRASE: resp_passphrase = self.PASSPHRASE2 elif resp_encr_type == self.ENCR_TYPE_PMK: resp_pmk = self.PMK2 # Responder: request network resp_req_key = self.request_network( resp_dut, resp_dut.droid.wifiAwareCreateNetworkSpecifierOob( resp_id, aconsts.DATA_PATH_RESPONDER, init_mac, resp_passphrase, resp_pmk)) # Initiator: request network init_req_key = self.request_network( init_dut, init_dut.droid.wifiAwareCreateNetworkSpecifierOob( init_id, aconsts.DATA_PATH_INITIATOR, resp_mac, init_passphrase, init_pmk)) # Initiator & Responder: fail on network formation time.sleep(autils.EVENT_NDP_TIMEOUT) autils.fail_on_event(init_dut, cconsts.EVENT_NETWORK_CALLBACK, timeout=0) autils.fail_on_event(resp_dut, cconsts.EVENT_NETWORK_CALLBACK, timeout=0) # clean-up resp_dut.droid.connectivityUnregisterNetworkCallback(resp_req_key) init_dut.droid.connectivityUnregisterNetworkCallback(init_req_key)