1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wifi.hotspot2; 18 19 import android.annotation.IntDef; 20 21 import java.lang.annotation.Retention; 22 import java.lang.annotation.RetentionPolicy; 23 24 /** 25 * This class carries the payload of a Hotspot 2.0 Wireless Network Management (WNM) frame, 26 * described in the Hotspot 2.0 spec, section 3.2. 27 */ 28 public class WnmData { 29 public static final int ESS = 1; // HS2.0 spec section 3.2.1.2, table 4 30 @Retention(RetentionPolicy.SOURCE) 31 @IntDef(value = { 32 HS20_REMEDIATION_EVENT, 33 HS20_DEAUTH_IMMINENT_EVENT, 34 HS20_TERMS_AND_CONDITIONS_ACCEPTANCE_REQUIRED_EVENT}) 35 public @interface WmnEventType {} 36 public static final int HS20_REMEDIATION_EVENT = 0; 37 public static final int HS20_DEAUTH_IMMINENT_EVENT = 1; 38 public static final int HS20_TERMS_AND_CONDITIONS_ACCEPTANCE_REQUIRED_EVENT = 2; 39 public static final int UNDEFINED = -1; 40 41 @Retention(RetentionPolicy.SOURCE) 42 @IntDef(value = { 43 OMA_DM, 44 SOAP_XML_SPP}) 45 public @interface OsuMethod {} 46 public static final int OMA_DM = 0; 47 public static final int SOAP_XML_SPP = 1; 48 49 private final long mBssid; 50 private final String mUrl; 51 private final @WmnEventType int mEventType; 52 private final int mMethod; 53 private final boolean mEss; 54 private final int mDelay; 55 WnmData(@mnEventType int eventType, long bssid, String url, @OsuMethod int method, boolean ess, int delay)56 private WnmData(@WmnEventType int eventType, long bssid, String url, @OsuMethod int method, 57 boolean ess, int delay) { 58 mBssid = bssid; 59 mUrl = url; 60 mMethod = method; 61 mEss = ess; 62 mDelay = delay; 63 mEventType = eventType; 64 } 65 66 /** 67 * Create a Passpoint Remediation WNM-Notification 68 * 69 * @param bssid BSSID of the source AP 70 * @param url URL of the remediation server 71 * @param method OSU method. Refer to section 4.8.1.3 of the Passpoint spec 72 * 73 * @return a WnmData object 74 */ createRemediationEvent(long bssid, String url, @OsuMethod int method)75 public static WnmData createRemediationEvent(long bssid, String url, @OsuMethod int method) { 76 return new WnmData(HS20_REMEDIATION_EVENT, bssid, url, method, false, UNDEFINED); 77 } 78 79 /** 80 * Create a Passpoint Deauth-Imminent WNM-Notification 81 * 82 * @param bssid BSSID of the source AP 83 * @param url URL of the remediation server 84 * @param ess A flag to indicate if the event applies to the ESS or only to the BSS 85 * 86 * @return a WnmData object 87 */ createDeauthImminentEvent(long bssid, String url, boolean ess, int delay)88 public static WnmData createDeauthImminentEvent(long bssid, String url, boolean ess, 89 int delay) { 90 return new WnmData(HS20_DEAUTH_IMMINENT_EVENT, bssid, url, UNDEFINED, ess, delay); 91 } 92 93 /** 94 * Create a Passpoint Terms & Conditions acceptance required WNM-Notification 95 * 96 * @param bssid BSSID of the source AP 97 * @param url URL of the remediation server 98 * 99 * @return a WnmData object 100 */ createTermsAndConditionsAccetanceRequiredEvent(long bssid, String url)101 public static WnmData createTermsAndConditionsAccetanceRequiredEvent(long bssid, String url) { 102 return new WnmData(HS20_TERMS_AND_CONDITIONS_ACCEPTANCE_REQUIRED_EVENT, bssid, url, 103 UNDEFINED, false, UNDEFINED); 104 } 105 106 /** 107 * Get the BSSID of the source AP 108 * 109 * @return The BSSID of the source AP 110 */ getBssid()111 public long getBssid() { 112 return mBssid; 113 } 114 115 /** 116 * Get the URL associated to the WNM-Notification 117 * 118 * @return The URL associated to the WNM-Notification 119 */ getUrl()120 public String getUrl() { 121 return mUrl; 122 } 123 124 /** 125 * Get event type 126 * 127 * @return The WNM-Notification event type 128 */ 129 @WmnEventType getEventType()130 public int getEventType() { 131 return mEventType; 132 } 133 134 /** 135 * Get the OSU method associated to the Remediation WNM-Notification 136 * 137 * @return The OSU method supported by the server 138 */ 139 @OsuMethod getMethod()140 public int getMethod() { 141 return mMethod; 142 } 143 144 /** 145 * Get the ESS flag associated to the Deauth-Imminent WNM-Notification 146 * 147 * @return true if notification is for the entire ESS, false for the BSS only 148 */ isEss()149 public boolean isEss() { 150 return mEss; 151 } 152 153 /** 154 * Get the delay in seconds associated to the Deauth-Imminent WNM-Notification 155 * 156 * @return The delay in seconds that a mobile device shall wait before attempting reassociation 157 */ getDelay()158 public int getDelay() { 159 return mDelay; 160 } 161 } 162