1 /*
2  * Copyright (C) 2018 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.soap;
18 
19 import android.util.SparseArray;
20 
21 import java.util.Arrays;
22 import java.util.HashMap;
23 import java.util.List;
24 import java.util.Locale;
25 import java.util.Map;
26 
27 /**
28  * Constant definitions for SPP (Subscription Provisioning Protocol).
29  */
30 public class SppConstants {
31     // Supported SPP Version.
32     public static final String SUPPORTED_SPP_VERSION = "1.0";
33 
34     // Supported Management Objects as required by SPP Version 1.0.
35     public static final List<String> SUPPORTED_MO_LIST = Arrays.asList(
36             "urn:wfa:mo:hotspot2dot0-perprovidersubscription:1.0",    // Hotspot 2.0 PPS MO tree
37             "urn:wfa:mo-ext:hotspot2dot0-devdetail-ext:1.0",    // Hotspot 2.0 DevDetail extension
38             "urn:oma:mo:oma-dm-devinfo:1.0",    // OMA-DM DevInfo
39             "urn:oma:mo:oma-dm-devdetail:1.0");    // OMA-DM DevDetail
40 
41     // Method names.
42     public static final String METHOD_POST_DEV_DATA = "sppPostDevData";
43     public static final String METHOD_UPDATE_RESPONSE = "sppUpdateResponse";
44 
45     // SOAP properties.
46     public static final String PROPERTY_SUPPORTED_SPP_VERSIONS = "supportedSPPVersions";
47     public static final String PROPERTY_SUPPORTED_MO_LIST = "supportedMOList";
48     public static final String PROPERTY_MO_CONTAINER = "moContainer";
49     public static final String PROPERTY_SPP_ERROR = "sppError";
50 
51     // SOAP attributes.
52     public static final String ATTRIBUTE_SPP_VERSION = "sppVersion";
53     public static final String ATTRIBUTE_SPP_STATUS = "sppStatus";
54 
55     public static final String ATTRIBUTE_REQUEST_REASON = "requestReason";
56     public static final String ATTRIBUTE_SESSION_ID = "sessionID";
57     public static final String ATTRIBUTE_REDIRECT_URI = "redirectURI";
58     public static final String ATTRIBUTE_MO_URN = "moURN";
59     public static final String ATTRIBUTE_ERROR_CODE = "errorCode";
60 
61     public static final int INVALID_SPP_CONSTANT = -1;
62 
63     private static final SparseArray<String> sStatusStrings = new SparseArray<>();
64     private static final Map<String, Integer> sStatusEnums = new HashMap<>();
65     static {
sStatusStrings.put(SppStatus.OK, "OK")66         sStatusStrings.put(SppStatus.OK, "OK");
sStatusStrings.put(SppStatus.PROV_COMPLETE, "Provisioning complete, request sppUpdateResponse")67         sStatusStrings.put(SppStatus.PROV_COMPLETE,
68                 "Provisioning complete, request sppUpdateResponse");
sStatusStrings.put(SppStatus.REMEDIATION_COMPLETE, "Remediation complete, request sppUpdateResponse")69         sStatusStrings.put(SppStatus.REMEDIATION_COMPLETE,
70                 "Remediation complete, request sppUpdateResponse");
sStatusStrings.put(SppStatus.UPDATE_COMPLETE, "Update complete, request sppUpdateResponse")71         sStatusStrings.put(SppStatus.UPDATE_COMPLETE, "Update complete, request sppUpdateResponse");
sStatusStrings.put(SppStatus.EXCHANGE_COMPLETE, "Exchange complete, release TLS connection")72         sStatusStrings.put(SppStatus.EXCHANGE_COMPLETE,
73                 "Exchange complete, release TLS connection");
sStatusStrings.put(SppStatus.UNKOWN, "No update available at this time")74         sStatusStrings.put(SppStatus.UNKOWN, "No update available at this time");
sStatusStrings.put(SppStatus.ERROR, "Error occurred")75         sStatusStrings.put(SppStatus.ERROR, "Error occurred");
76 
77         for (int i = 0; i < sStatusStrings.size(); i++) {
sStatusStrings.keyAt(i)78             sStatusEnums.put(sStatusStrings.valueAt(i).toLowerCase(), sStatusStrings.keyAt(i));
79         }
80     }
81 
82     private static final SparseArray<String> sErrorStrings = new SparseArray<>();
83     private static final Map<String, Integer> sErrorEnums = new HashMap<>();
84     static {
sErrorStrings.put(SppError.VERSION_NOT_SUPPORTED, "SPP version not supported")85         sErrorStrings.put(SppError.VERSION_NOT_SUPPORTED, "SPP version not supported");
sErrorStrings.put(SppError.MOS_NOT_SUPPORTED, "One or more mandatory MOs not supported")86         sErrorStrings.put(SppError.MOS_NOT_SUPPORTED, "One or more mandatory MOs not supported");
sErrorStrings.put(SppError.CREDENTIALS_FAILURE, "Credentials cannot be provisioned at this time")87         sErrorStrings.put(SppError.CREDENTIALS_FAILURE,
88                 "Credentials cannot be provisioned at this time");
sErrorStrings.put(SppError.REMEDIATION_FAILURE, "Remediation cannot be completed at this time")89         sErrorStrings.put(SppError.REMEDIATION_FAILURE,
90                 "Remediation cannot be completed at this time");
sErrorStrings.put(SppError.PROVISIONING_FAILED, "Provisioning cannot be completed at this time")91         sErrorStrings.put(SppError.PROVISIONING_FAILED,
92                 "Provisioning cannot be completed at this time");
sErrorStrings.put(SppError.EXISITING_CERTIFICATE, "Continue to use existing certificate")93         sErrorStrings.put(SppError.EXISITING_CERTIFICATE, "Continue to use existing certificate");
sErrorStrings.put(SppError.COOKIE_INVALID, "Cookie invalid")94         sErrorStrings.put(SppError.COOKIE_INVALID, "Cookie invalid");
sErrorStrings.put(SppError.WEB_SESSION_ID, "No corresponding web-browser-connection Session ID")95         sErrorStrings.put(SppError.WEB_SESSION_ID,
96                 "No corresponding web-browser-connection Session ID");
sErrorStrings.put(SppError.PERMISSION_DENITED, "Permission denied")97         sErrorStrings.put(SppError.PERMISSION_DENITED, "Permission denied");
sErrorStrings.put(SppError.COMMAND_FAILED, "Command failed")98         sErrorStrings.put(SppError.COMMAND_FAILED, "Command failed");
sErrorStrings.put(SppError.MO_ADD_OR_UPDATE_FAILED, "MO addition or update failed")99         sErrorStrings.put(SppError.MO_ADD_OR_UPDATE_FAILED, "MO addition or update failed");
sErrorStrings.put(SppError.DEVICE_FULL, "Device full")100         sErrorStrings.put(SppError.DEVICE_FULL, "Device full");
sErrorStrings.put(SppError.BAD_TREE_URI, "Bad management tree URI")101         sErrorStrings.put(SppError.BAD_TREE_URI, "Bad management tree URI");
sErrorStrings.put(SppError.TOO_LARGE, "Requested entity too large")102         sErrorStrings.put(SppError.TOO_LARGE, "Requested entity too large");
sErrorStrings.put(SppError.COMMAND_NOT_ALLOWED, "Command not allowed")103         sErrorStrings.put(SppError.COMMAND_NOT_ALLOWED, "Command not allowed");
sErrorStrings.put(SppError.USER_ABORTED, "Command not executed due to user")104         sErrorStrings.put(SppError.USER_ABORTED, "Command not executed due to user");
sErrorStrings.put(SppError.NOT_FOUND, "Not found")105         sErrorStrings.put(SppError.NOT_FOUND, "Not found");
sErrorStrings.put(SppError.OTHER, "Other")106         sErrorStrings.put(SppError.OTHER, "Other");
107 
108         for (int i = 0; i < sErrorStrings.size(); i++) {
sErrorStrings.keyAt(i)109             sErrorEnums.put(sErrorStrings.valueAt(i).toLowerCase(), sErrorStrings.keyAt(i));
110         }
111     }
112 
113     /**
114      * Convert the {@link SppStatus} to <code>String</code>
115      *
116      * @param status value of {@link SppStatus}
117      * @return string of the status
118      */
mapStatusIntToString(int status)119     public static String mapStatusIntToString(int status) {
120         return sStatusStrings.get(status);
121     }
122 
123     /**
124      * Convert the status string to {@link SppStatus}
125      *
126      * @param status string of the status
127      * @return <code>int</code> value of {@link SppStatus} if found; {@link #INVALID_SPP_CONSTANT}
128      * otherwise.
129      */
mapStatusStringToInt(String status)130     public static int mapStatusStringToInt(String status) {
131         Integer value = sStatusEnums.get(status.toLowerCase(Locale.US));
132         return (value == null) ? INVALID_SPP_CONSTANT : value;
133     }
134 
135     /**
136      * Convert the {@link SppError} to <code>String</code>
137      *
138      * @param error value of {@link SppError}
139      * @return string of error
140      */
mapErrorIntToString(int error)141     public static String mapErrorIntToString(int error) {
142         return sErrorStrings.get(error);
143     }
144 
145     /**
146      * Convert the error string to {@link SppError}
147      *
148      * @param error string of the error
149      * @return <code>int</code> value of {@link SppError} if found; {@link #INVALID_SPP_CONSTANT}
150      * otherwise.
151      */
mapErrorStringToInt(String error)152     public static int mapErrorStringToInt(String error) {
153         Integer value = sErrorEnums.get(error.toLowerCase());
154         return (value == null) ? INVALID_SPP_CONSTANT : value;
155     }
156 
157     // Request reasons for sppPostDevData requests.
158     // Refer to Table 13(sppPostDevData Elements and Attributes Descriptions)
159     // in Hotspot2.0 R2 Technical specification.
160     public class SppReason {
161         public static final String SUBSCRIPTION_REGISTRATION =
162                 "Subscription registration";
163         public static final String SUBSCRIPTION_PROVISIONING =
164                 "Subscription provisioning";
165         public static final String SUBSCRIPTION_REMEDIATION =
166                 "Subscription remediation";
167         public static final String USER_INPUT_COMPLETED = "User input completed";
168         public static final String NO_ACCEPTABLE_CLIENT_CERTIFICATE =
169                 "No acceptable client certificate";
170         public static final String CERTIFICATE_ENROLLMENT_COMPLETED =
171                 "Certificate enrollment completed";
172         public static final String CERTIFICATE_ENROLLMENT_FAILED =
173                 "Certificate enrollment failed";
174         public static final String SUBSCRIPTION_METADATA_UPDATE =
175                 "Subscription metadata update";
176         public static final String POLICY_UPDATE = "Policy update";
177         public static final String MO_UPLOAD = "MO upload";
178         public static final String RETRIEVE_NEXT_COMMAND = "Retrieve next command";
179         public static final String UNSPECIFIED = "Unspecified";
180     }
181 
182     /**
183      * enumeration values for the status defined by SPP (Subscription Provisioning Protocol).
184      *
185      * @see <a href=https://www.wi-fi.org/specifications/hotspot2dot0/v1.0/spp/spp-v1.0.xsd>SPP
186      * protocol 1.0</a>
187      */
188     public class SppStatus {
189         public static final int OK = 0;
190         public static final int PROV_COMPLETE = 1;
191         public static final int REMEDIATION_COMPLETE = 2;
192         public static final int UPDATE_COMPLETE = 3;
193         public static final int EXCHANGE_COMPLETE = 4;
194         public static final int UNKOWN = 5;
195         public static final int ERROR = 6;
196     }
197 
198     /**
199      * Enumeration values for the errors defined by SPP (Subscription Provisioning Protocol).
200      *
201      * @see <a href=https://www.wi-fi.org/specifications/hotspot2dot0/v1.0/spp/spp-v1.0.xsd>SPP
202      * protocol 1.0</a>
203      */
204     public class SppError {
205         public static final int VERSION_NOT_SUPPORTED = 0;
206         public static final int MOS_NOT_SUPPORTED = 1;
207         public static final int CREDENTIALS_FAILURE = 2;
208         public static final int REMEDIATION_FAILURE = 3;
209         public static final int PROVISIONING_FAILED = 4;
210         public static final int EXISITING_CERTIFICATE = 5;
211         public static final int COOKIE_INVALID = 6;
212         public static final int WEB_SESSION_ID = 7;
213         public static final int PERMISSION_DENITED = 8;
214         public static final int COMMAND_FAILED = 9;
215         public static final int MO_ADD_OR_UPDATE_FAILED = 10;
216         public static final int DEVICE_FULL = 11;
217         public static final int BAD_TREE_URI = 12;
218         public static final int TOO_LARGE = 13;
219         public static final int COMMAND_NOT_ALLOWED = 14;
220         public static final int USER_ABORTED = 15;
221         public static final int NOT_FOUND = 16;
222         public static final int OTHER = 17;
223     }
224 }