public int getProtocol() {

    return WifiUtil.getConfirmType(mResult);
  }
  /**
   * Enable the scan access point which has security. This may result in the asynchronous delivery
   * of state change events. Applications should register the 'SUPPLICANT_STATE_CHANGED_ACTION' and
   * 'NETWORK_STATE_CHANGED_ACTION' receiver to receive the state change events.
   *
   * @param One of the access point which want to link.
   * @return Return true if the operation succeed, false otherwise.
   */
  public boolean enableNetworkLink(ScanResult result, String sectretKey) {
    if (WifiConst.DummyMode) {
      return false;
    }

    int networkId = -1;
    int keyLength = sectretKey.length();
    WifiConfiguration config = new WifiConfiguration();
    if (localLOGV)
      NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: Enable Access Point with Password.");
    if (result == null || sectretKey == null) {
      return false;
    }

    WifiUtil.clearConfiguration(config);
    config.status = WifiConfiguration.Status.ENABLED;

    config.SSID = WifiUtil.convertToQuotedString(result.SSID);

    int encrypt = WifiUtil.getEncrypt(result);

    if (encrypt == WifiConst.W_ENCRYPT_WEP) {
      if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: WEP encrypt.");
      if ((keyLength == 5 || keyLength == 10 || keyLength == 13 || keyLength == 26)
          && sectretKey.matches("[0-9A-Fa-f]*")) {
        config.wepKeys[0] = sectretKey;
      } else {
        config.wepKeys[0] = '"' + sectretKey + '"';
      }
    } else {
      if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: other encrypt.");
      if (sectretKey.matches("[0-9A-Fa-f]{64}")) {
        config.preSharedKey = sectretKey;
      } else {
        config.preSharedKey = "\"" + sectretKey + "\"";
      }
    }

    int ConfirmType = WifiUtil.getConfirmType(result);
    switch (ConfirmType) {
      case WifiConst.W_CONFIRM_OPEN:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_OPEN");
        config.allowedKeyManagement.set(KeyMgmt.NONE);
        config.allowedAuthAlgorithms.clear();
        config.allowedPairwiseCiphers.set(PairwiseCipher.NONE);
        config.allowedGroupCiphers.clear();
        config.allowedProtocols.clear();
        break;

      case WifiConst.W_CONFIRM_WEP:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_WEP");
        config.allowedKeyManagement.set(KeyMgmt.NONE);
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
        config.allowedPairwiseCiphers.set(PairwiseCipher.NONE);

        if (keyLength == 5 || keyLength == 10) {
          config.allowedGroupCiphers.set(GroupCipher.WEP40);
        } else {
          config.allowedGroupCiphers.set(GroupCipher.WEP104);
        }

        config.allowedProtocols.clear();
        break;

      case WifiConst.W_CONFIRM_WPA_PSK:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_WPA_PSK");
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.allowedProtocols.set(Protocol.WPA);
        config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
        break;

      case WifiConst.W_CONFIRM_WPA2_PSK:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_WPA2_PSK");
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.allowedProtocols.set(Protocol.RSN);
        config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
        break;

      case WifiConst.W_CONFIRM_PSK_AUTO:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_PSK_AUTO");
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.allowedProtocols.set(Protocol.RSN);
        config.allowedProtocols.set(Protocol.WPA);
        config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
        break;

      case WifiConst.W_CONFIRM_WPA_EAP:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_WPA_EAP");
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.allowedProtocols.set(Protocol.WPA);
        config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
        break;

      case WifiConst.W_CONFIRM_WPA2_EAP:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_WPA2_EAP");
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.allowedProtocols.set(Protocol.RSN);
        config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
        break;

      case WifiConst.W_CONFIRM_EAP_AUTO:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_CONFIRM_EAP_AUTO");
        config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
        config.allowedProtocols.set(Protocol.RSN);
        config.allowedProtocols.set(Protocol.WPA);
        config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
        break;

      default:
        break;
    }

    switch (encrypt) {
      case WifiConst.W_ENCRYPT_WEP:
        break;

      case WifiConst.W_ENCRYPT_TKIP:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_ENCRYPT_TKIP");
        config.allowedGroupCiphers.set(GroupCipher.TKIP);
        config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
        break;

      case WifiConst.W_ENCRYPT_AES:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_ENCRYPT_AES");
        config.allowedGroupCiphers.set(GroupCipher.CCMP);
        config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
        break;

      case WifiConst.W_ENCRYPT_TKIP_AES:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_ENCRYPT_TKIP_AES");
        config.allowedGroupCiphers.set(GroupCipher.TKIP);
        config.allowedGroupCiphers.set(GroupCipher.CCMP);
        config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
        config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
        break;

      default:
        if (localLOGV) NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: W_ENCRYPT default.");
        break;
    }

    networkId = mWifiManager.addNetwork(config);
    if (localLOGV)
      NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: 398  networkId -> " + networkId);
    mWifiManager.updateNetwork(config);

    if (networkId == -1) {
      return false;
    }

    if (mWifiManager.enableNetwork(networkId, true)) {
      if (localLOGV)
        NetLog.d(TAG, "[WifiAvailableAp][EnableNetworkLink]: Enable network link SUCCESS.");

      mWifiManager.reconnect();

      return true;
    }

    return false;
  }