1 /* 2 * Copyright (C) 2011 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 android.net.wifi.p2p; 18 19 import android.os.Parcelable; 20 import android.os.Parcel; 21 import android.util.Log; 22 23 /** 24 * A class representing a Wi-Fi p2p provisional discovery request/response 25 * See {@link #WifiP2pProvDiscEvent} for supported types 26 * 27 * @hide 28 */ 29 public class WifiP2pProvDiscEvent { 30 31 private static final String TAG = "WifiP2pProvDiscEvent"; 32 33 public static final int PBC_REQ = 1; 34 public static final int PBC_RSP = 2; 35 public static final int ENTER_PIN = 3; 36 public static final int SHOW_PIN = 4; 37 38 /* One of PBC_REQ, PBC_RSP, ENTER_PIN or SHOW_PIN */ 39 public int event; 40 41 public WifiP2pDevice device; 42 43 /* Valid when event = SHOW_PIN */ 44 public String pin; 45 46 public WifiP2pProvDiscEvent() { 47 device = new WifiP2pDevice(); 48 } 49 50 /** 51 * @param string formats supported include 52 * 53 * P2P-PROV-DISC-PBC-REQ 42:fc:89:e1:e2:27 54 * P2P-PROV-DISC-PBC-RESP 02:12:47:f2:5a:36 55 * P2P-PROV-DISC-ENTER-PIN 42:fc:89:e1:e2:27 56 * P2P-PROV-DISC-SHOW-PIN 42:fc:89:e1:e2:27 44490607 57 * 58 * Note: The events formats can be looked up in the wpa_supplicant code 59 * @hide 60 */ 61 public WifiP2pProvDiscEvent(String string) throws IllegalArgumentException { 62 String[] tokens = string.split(" "); 63 64 if (tokens.length < 2) { 65 throw new IllegalArgumentException("Malformed event " + string); 66 } 67 68 if (tokens[0].endsWith("PBC-REQ")) event = PBC_REQ; 69 else if (tokens[0].endsWith("PBC-RESP")) event = PBC_RSP; 70 else if (tokens[0].endsWith("ENTER-PIN")) event = ENTER_PIN; 71 else if (tokens[0].endsWith("SHOW-PIN")) event = SHOW_PIN; 72 else throw new IllegalArgumentException("Malformed event " + string); 73 74 75 device = new WifiP2pDevice(); 76 device.deviceAddress = tokens[1]; 77 78 if (event == SHOW_PIN) { 79 pin = tokens[2]; 80 } 81 } 82 83 public String toString() { 84 StringBuffer sbuf = new StringBuffer(); 85 sbuf.append(device); 86 sbuf.append("\n event: ").append(event); 87 sbuf.append("\n pin: ").append(pin); 88 return sbuf.toString(); 89 } 90 } 91