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.test_utils.wifi.aware import aware_const as aconsts 21from acts.test_utils.wifi.aware import aware_test_utils as autils 22from acts.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 __init__(self, controllers): 33 AwareBaseTest.__init__(self, controllers) 34 35 def start_discovery_session(self, dut, session_id, is_publish, dtype, 36 service_name): 37 """Start a discovery session 38 39 Args: 40 dut: Device under test 41 session_id: ID of the Aware session in which to start discovery 42 is_publish: True for a publish session, False for subscribe session 43 dtype: Type of the discovery session 44 service_name: Service name to use for the discovery session 45 46 Returns: 47 Discovery session ID. 48 """ 49 config = {} 50 config[aconsts.DISCOVERY_KEY_DISCOVERY_TYPE] = dtype 51 config[aconsts.DISCOVERY_KEY_SERVICE_NAME] = service_name 52 53 if is_publish: 54 disc_id = dut.droid.wifiAwarePublish(session_id, config) 55 event_name = aconsts.SESSION_CB_ON_PUBLISH_STARTED 56 else: 57 disc_id = dut.droid.wifiAwareSubscribe(session_id, config) 58 event_name = aconsts.SESSION_CB_ON_SUBSCRIBE_STARTED 59 60 autils.wait_for_event(dut, event_name) 61 return disc_id 62 63 #################################################################### 64 65 def test_service_ids_in_beacon(self): 66 """Verify that beacons include service IDs for both publish and subscribe 67 sessions of all types: solicited/unsolicited/active/passive.""" 68 dut = self.android_devices[0] 69 70 self.log.info("Reminder: start a sniffer before running test") 71 72 # attach 73 session_id = dut.droid.wifiAwareAttach(True) 74 autils.wait_for_event(dut, aconsts.EVENT_CB_ON_ATTACHED) 75 ident_event = autils.wait_for_event(dut, 76 aconsts.EVENT_CB_ON_IDENTITY_CHANGED) 77 mac = ident_event["data"]["mac"] 78 self.log.info("Source MAC Address of 'interesting' packets = %s", mac) 79 self.log.info("Wireshark filter = 'wlan.ta == %s:%s:%s:%s:%s:%s'", mac[0:2], 80 mac[2:4], mac[4:6], mac[6:8], mac[8:10], mac[10:12]) 81 82 time.sleep(5) # get some samples pre-discovery 83 84 # start 4 discovery session (one of each type) 85 self.start_discovery_session(dut, session_id, True, 86 aconsts.PUBLISH_TYPE_UNSOLICITED, 87 "GoogleTestService-Pub-Unsolicited") 88 self.start_discovery_session(dut, session_id, True, 89 aconsts.PUBLISH_TYPE_SOLICITED, 90 "GoogleTestService-Pub-Solicited") 91 self.start_discovery_session(dut, session_id, False, 92 aconsts.SUBSCRIBE_TYPE_ACTIVE, 93 "GoogleTestService-Sub-Active") 94 self.start_discovery_session(dut, session_id, False, 95 aconsts.SUBSCRIBE_TYPE_PASSIVE, 96 "GoogleTestService-Sub-Passive") 97 98 time.sleep(15) # get some samples while discovery is alive 99 100 self.log.info("Reminder: stop sniffer") 101