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.aware;
18 
19 import android.net.wifi.aware.Characteristics;
20 import android.os.Bundle;
21 
22 import com.android.server.wifi.DeviceConfigFacade;
23 
24 import org.json.JSONException;
25 import org.json.JSONObject;
26 
27 /**
28  * A container class for Aware (vendor) implementation capabilities (or
29  * limitations). Filled-in by the firmware.
30  */
31 public class Capabilities {
32     public int maxConcurrentAwareClusters;
33     public int maxPublishes;
34     public int maxSubscribes;
35     public int maxServiceNameLen;
36     public int maxMatchFilterLen;
37     public int maxTotalMatchFilterLen;
38     public int maxServiceSpecificInfoLen;
39     public int maxExtendedServiceSpecificInfoLen;
40     public int maxNdiInterfaces;
41     public int maxNdpSessions;
42     public int maxAppInfoLen;
43     public int maxQueuedTransmitMessages;
44     public int maxSubscribeInterfaceAddresses;
45     public int supportedDataPathCipherSuites;
46     public int supportedPairingCipherSuites;
47     public boolean isInstantCommunicationModeSupported;
48     public boolean isNanPairingSupported;
49     public boolean isSetClusterIdSupported;
50     public boolean isSuspensionSupported;
51     public boolean is6gSupported;
52     public boolean isHeSupported;
53 
54     /**
55      * Converts the internal capabilities to a parcelable & potentially app-facing
56      * characteristics bundle. Only some of the information is exposed.
57      */
toPublicCharacteristics(DeviceConfigFacade deviceConfigFacade)58     public Characteristics toPublicCharacteristics(DeviceConfigFacade deviceConfigFacade) {
59         Bundle bundle = new Bundle();
60         bundle.putInt(Characteristics.KEY_MAX_SERVICE_NAME_LENGTH, maxServiceNameLen);
61         bundle.putInt(
62                 Characteristics.KEY_MAX_SERVICE_SPECIFIC_INFO_LENGTH,
63                 Math.max(maxExtendedServiceSpecificInfoLen, maxServiceSpecificInfoLen));
64         bundle.putInt(Characteristics.KEY_MAX_MATCH_FILTER_LENGTH, maxMatchFilterLen);
65         bundle.putInt(Characteristics.KEY_SUPPORTED_DATA_PATH_CIPHER_SUITES,
66                 supportedDataPathCipherSuites);
67         bundle.putInt(Characteristics.KEY_SUPPORTED_PAIRING_CIPHER_SUITES,
68                 supportedPairingCipherSuites);
69         bundle.putBoolean(Characteristics.KEY_IS_INSTANT_COMMUNICATION_MODE_SUPPORTED,
70                 isInstantCommunicationModeSupported);
71         bundle.putInt(Characteristics.KEY_MAX_NDP_NUMBER, maxNdpSessions);
72         bundle.putInt(Characteristics.KEY_MAX_NDI_NUMBER, maxNdiInterfaces);
73         bundle.putInt(Characteristics.KEY_MAX_PUBLISH_NUMBER, maxPublishes);
74         bundle.putInt(Characteristics.KEY_MAX_SUBSCRIBE_NUMBER, maxSubscribes);
75         bundle.putBoolean(Characteristics.KEY_SUPPORT_NAN_PAIRING, isNanPairingSupported);
76         bundle.putBoolean(Characteristics.KEY_SUPPORT_SUSPENSION,
77                 deviceConfigFacade.isAwareSuspensionEnabled() && isSuspensionSupported);
78         return new Characteristics(bundle);
79     }
80 
toJSON()81     JSONObject toJSON() throws JSONException {
82         JSONObject j = new JSONObject();
83         j.put("maxConcurrentAwareClusters", maxConcurrentAwareClusters);
84         j.put("maxPublishes", maxPublishes);
85         j.put("maxSubscribes", maxSubscribes);
86         j.put("maxServiceNameLen", maxServiceNameLen);
87         j.put("maxMatchFilterLen", maxMatchFilterLen);
88         j.put("maxServiceSpecificInfoLen", maxServiceSpecificInfoLen);
89         j.put("maxExtendedServiceSpecificInfoLen", maxExtendedServiceSpecificInfoLen);
90         j.put("maxNdiInterfaces", maxNdiInterfaces);
91         j.put("maxNdpSessions", maxNdpSessions);
92         j.put("maxAppInfoLen", maxAppInfoLen);
93         j.put("maxQueuedTransmitMessages", maxQueuedTransmitMessages);
94         j.put("maxSubscribeInterfaceAddresses", maxSubscribeInterfaceAddresses);
95         j.put("supportedCipherSuites", supportedDataPathCipherSuites);
96         j.put("isInstantCommunicationModeSupported", isInstantCommunicationModeSupported);
97         j.put("isSetClusterIdSupported", isSetClusterIdSupported);
98         j.put("isNanPairingSupported", isNanPairingSupported);
99         j.put("isSuspensionSupported", isSuspensionSupported);
100         return j;
101     }
102 
103     @Override
toString()104     public String toString() {
105         return "Capabilities [maxConcurrentAwareClusters="
106                 + maxConcurrentAwareClusters
107                 + ", maxPublishes="
108                 + maxPublishes
109                 + ", maxSubscribes="
110                 + maxSubscribes
111                 + ", maxServiceNameLen="
112                 + maxServiceNameLen
113                 + ", maxMatchFilterLen="
114                 + maxMatchFilterLen
115                 + ", maxTotalMatchFilterLen="
116                 + maxTotalMatchFilterLen
117                 + ", maxServiceSpecificInfoLen="
118                 + maxServiceSpecificInfoLen
119                 + ", maxExtendedServiceSpecificInfoLen="
120                 + maxExtendedServiceSpecificInfoLen
121                 + ", maxNdiInterfaces="
122                 + maxNdiInterfaces
123                 + ", maxNdpSessions="
124                 + maxNdpSessions
125                 + ", maxAppInfoLen="
126                 + maxAppInfoLen
127                 + ", maxQueuedTransmitMessages="
128                 + maxQueuedTransmitMessages
129                 + ", maxSubscribeInterfaceAddresses="
130                 + maxSubscribeInterfaceAddresses
131                 + ", supportedCipherSuites="
132                 + supportedDataPathCipherSuites
133                 + ", isInstantCommunicationModeSupport="
134                 + isInstantCommunicationModeSupported
135                 + ", isNanPairingSupported="
136                 + isNanPairingSupported
137                 + ", isSetClusterIdSupported="
138                 + isSetClusterIdSupported
139                 + ", isSuspensionSupported="
140                 + isSuspensionSupported
141                 + ", is6gSupported="
142                 + is6gSupported
143                 + ", isHeSupported="
144                 + isHeSupported
145                 + "]";
146     }
147 }
148