WifiP2pConfig.java revision 9cc2718abc0152d79e3e8bf23be94ddd3cc9db87
155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync/* 255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Copyright (C) 2011 The Android Open Source Project 355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Licensed under the Apache License, Version 2.0 (the "License"); 555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * you may not use this file except in compliance with the License. 655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * You may obtain a copy of the License at 755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * http://www.apache.org/licenses/LICENSE-2.0 955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * 1055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Unless required by applicable law or agreed to in writing, software 1155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * distributed under the License is distributed on an "AS IS" BASIS, 1255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * See the License for the specific language governing permissions and 1455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * limitations under the License. 1555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 1655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 1755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncpackage android.net.wifi.p2p; 1855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 1955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.net.wifi.WpsConfiguration; 2055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.net.wifi.WpsConfiguration.Setup; 2155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.Parcelable; 2255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncimport android.os.Parcel; 2355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 2455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync/** 2555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * A class representing a Wi-Fi P2p configuration 2655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * @hide 2755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 2855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo syncpublic class WifiP2pConfig implements Parcelable { 2955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 3055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 3155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * Device address 3255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 3355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String deviceAddress; 3455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 3555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 3655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * WPS configuration 3755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 3855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WpsConfiguration wpsConfig; 3955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 4055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 4155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * This is an integer value between 0 and 15 where 0 indicates the least 4255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * inclination to be a group owner and 15 indicates the highest inclination 4355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync * to be a group owner. 442b8edd0c485f74067605c19983e3e7f44b20ec50repo sync * 452b8edd0c485f74067605c19983e3e7f44b20ec50repo sync * A value of -1 indicates the system can choose an appropriate value. 4655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 472b8edd0c485f74067605c19983e3e7f44b20ec50repo sync public int groupOwnerIntent = -1; 4855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 4955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** 50ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff * Indicates whether the configuration is saved 519cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff * @hide 5255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync */ 53ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public enum Persist { 54ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff SYSTEM_DEFAULT, 55ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff YES, 56ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff NO 57ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff } 58ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff 599cc2718abc0152d79e3e8bf23be94ddd3cc9db87Irfan Sheriff /** @hide */ 60ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff public Persist persist = Persist.SYSTEM_DEFAULT; 6155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 6255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pConfig() { 6355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync //set defaults 6455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig = new WpsConfiguration(); 6555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig.setup = Setup.PBC; 6655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 6755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 6855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /* P2P-GO-NEG-REQUEST 42:fc:89:a8:96:09 dev_passwd_id=4 */ 6955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pConfig(String supplicantEvent) throws IllegalArgumentException { 7055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync String[] tokens = supplicantEvent.split(" "); 7155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 7255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (tokens.length < 2 || !tokens[0].equals("P2P-GO-NEG-REQUEST")) { 7355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync throw new IllegalArgumentException("Malformed supplicant event"); 7455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 7555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 7655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync deviceAddress = tokens[1]; 7755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig = new WpsConfiguration(); 7855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 7955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (tokens.length > 2) { 8055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync String[] nameVal = tokens[2].split("="); 8155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync int devPasswdId; 8255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync try { 8355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync devPasswdId = Integer.parseInt(nameVal[1]); 8455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } catch (NumberFormatException e) { 8555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync devPasswdId = 0; 8655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 8755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync //As defined in wps/wps_defs.h 8855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync switch (devPasswdId) { 8955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync case 0x00: 9055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig.setup = Setup.LABEL; 9155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync break; 9255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync case 0x01: 9355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig.setup = Setup.KEYPAD; 9455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync break; 9555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync case 0x04: 9655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig.setup = Setup.PBC; 9755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync break; 9855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync case 0x05: 9955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig.setup = Setup.DISPLAY; 10055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync break; 10155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync default: 10255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync wpsConfig.setup = Setup.PBC; 10355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync break; 10455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 10555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 10655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 10755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 10855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public String toString() { 10955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync StringBuffer sbuf = new StringBuffer(); 11055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n address: ").append(deviceAddress); 11155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n wps: ").append(wpsConfig); 11255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync sbuf.append("\n groupOwnerIntent: ").append(groupOwnerIntent); 113ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff sbuf.append("\n persist: ").append(persist.toString()); 11455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return sbuf.toString(); 11555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 11655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 11755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** Implement the Parcelable interface {@hide} */ 11855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public int describeContents() { 11955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return 0; 12055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 12155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 12255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** copy constructor {@hide} */ 12355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pConfig(WifiP2pConfig source) { 12455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync if (source != null) { 12555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync //TODO: implement 12655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 12755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 12855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 12955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** Implement the Parcelable interface {@hide} */ 13055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public void writeToParcel(Parcel dest, int flags) { 13155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeString(deviceAddress); 13255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeParcelable(wpsConfig, flags); 13355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync dest.writeInt(groupOwnerIntent); 134ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff dest.writeString(persist.name()); 13555bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 13655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 13755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync /** Implement the Parcelable interface {@hide} */ 13855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public static final Creator<WifiP2pConfig> CREATOR = 13955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync new Creator<WifiP2pConfig>() { 14055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pConfig createFromParcel(Parcel in) { 14155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync WifiP2pConfig config = new WifiP2pConfig(); 14255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync config.deviceAddress = in.readString(); 14355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync config.wpsConfig = (WpsConfiguration) in.readParcelable(null); 14455bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync config.groupOwnerIntent = in.readInt(); 145ea5b16ac5751022de73e8f1225407eb01e7f1824Irfan Sheriff config.persist = Persist.valueOf(in.readString()); 14655bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return config; 14755bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 14855bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync 14955bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync public WifiP2pConfig[] newArray(int size) { 15055bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync return new WifiP2pConfig[size]; 15155bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync } 15255bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync }; 15355bc5f3e0408bcb5a39a6732de0b2d1aa99a55berepo sync} 154