1#!/usr/bin/python3.4 2# 3# Copyright 2017 - The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17import time 18 19from acts import asserts 20from acts_contrib.test_utils.wifi.aware import aware_const as aconsts 21from acts_contrib.test_utils.wifi.aware import aware_test_utils as autils 22from acts_contrib.test_utils.wifi.aware.AwareBaseTest import AwareBaseTest 23 24 25class ServiceIdsTest(AwareBaseTest): 26 """Set of tests for Wi-Fi Aware to verify that beacons include service IDs 27 for discovery. 28 29 Note: this test is an OTA (over-the-air) and requires a Sniffer. 30 """ 31 32 def start_discovery_session(self, dut, session_id, is_publish, dtype, 33 service_name): 34 """Start a discovery session 35 36 Args: 37 dut: Device under test 38 session_id: ID of the Aware session in which to start discovery 39 is_publish: True for a publish session, False for subscribe session 40 dtype: Type of the discovery session 41 service_name: Service name to use for the discovery session 42 43 Returns: 44 Discovery session ID. 45 """ 46 config = {} 47 config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = dtype 48 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = service_name 49 50 if is_publish: 51 disc_id = dut.droid.wifiAwarePublish(session_id, config) 52 event_name = aconsts.SESSION_CB_ON_PUBLISH_STARTED 53 else: 54 disc_id = dut.droid.wifiAwareSubscribe(session_id, config) 55 event_name = aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED 56 57 autils.wait_for_event(dut, event_name) 58 return disc_id 59 60 #################################################################### 61 62 def test_service_ids_in_beacon(self): 63 """Verify that beacons include service IDs for both publish and subscribe 64 sessions of all types: solicited/unsolicited/active/passive.""" 65 dut = self.android_devices[0] 66 67 self.log.info("Reminder: start a sniffer before running test") 68 69 # attach 70 session_id = dut.droid.wifiAwareAttach(True) 71 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) 72 ident_event = autils.wait_for_event( 73 dut, aconsts.EVENT_CB_ON_IDENTITY_CHANGED) 74 mac = ident_event["data"]["mac"] 75 self.log.info("Source MAC Address of 'interesting' packets = %s", mac) 76 self.log.info("Wireshark filter = 'wlan.ta == %s:%s:%s:%s:%s:%s'", 77 mac[0:2], mac[2:4], mac[4:6], mac[6:8], mac[8:10], 78 mac[10:12]) 79 80 time.sleep(5) # get some samples pre-discovery 81 82 # start 4 discovery session (one of each type) 83 self.start_discovery_session(dut, session_id, True, 84 aconsts.PUBLISH_TYPE_UNSOLICITED, 85 "GoogleTestService-Pub-Unsolicited") 86 self.start_discovery_session(dut, session_id, True, 87 aconsts.PUBLISH_TYPE_SOLICITED, 88 "GoogleTestService-Pub-Solicited") 89 self.start_discovery_session(dut, session_id, False, 90 aconsts.SUBSCRIBE_TYPE_ACTIVE, 91 "GoogleTestService-Sub-Active") 92 self.start_discovery_session(dut, session_id, False, 93 aconsts.SUBSCRIBE_TYPE_PASSIVE, 94 "GoogleTestService-Sub-Passive") 95 96 time.sleep(15) # get some samples while discovery is alive 97 98 self.log.info("Reminder: stop sniffer") 99