blob: 7910f4a7f6450fc47d4db0a86136a9e823285973 [file] [log] [blame]
Hung-ying Tyan2b04d292009-06-27 15:59:44 +08001/*
2 * Copyright (C) 2009, 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
17package com.android.server.vpn;
18
19import android.net.vpn.L2tpIpsecPskProfile;
20
21import java.io.IOException;
22
23/**
24 * The service that manages the preshared key based L2TP-over-IPSec VPN
25 * connection.
26 */
27class L2tpIpsecPskService extends VpnService<L2tpIpsecPskProfile> {
Hung-ying Tyan21bd4af2009-07-23 07:37:27 +080028 private static final String IPSEC = "racoon";
Hung-ying Tyan2b04d292009-06-27 15:59:44 +080029
30 @Override
31 protected void connect(String serverIp, String username, String password)
32 throws IOException {
Hung-ying Tyan2b04d292009-06-27 15:59:44 +080033 L2tpIpsecPskProfile p = getProfile();
34
35 // IPSEC
Hung-ying Tyan21bd4af2009-07-23 07:37:27 +080036 DaemonProxy ipsec = startDaemon(IPSEC);
37 ipsec.sendCommand(serverIp, L2tpService.L2TP_PORT, p.getPresharedKey());
38 ipsec.closeControlSocket();
Hung-ying Tyan2b04d292009-06-27 15:59:44 +080039
40 sleep(2000); // 2 seconds
41
42 // L2TP
43 MtpdHelper.sendCommand(this, L2tpService.L2TP_DAEMON, serverIp,
44 L2tpService.L2TP_PORT,
45 (p.isSecretEnabled() ? p.getSecretString() : null),
46 username, password);
47 }
Hung-ying Tyanfe8e48cd2009-07-30 14:02:48 +080048
49 @Override
50 protected void stopPreviouslyRunDaemons() {
51 stopDaemon(IPSEC);
52 stopDaemon(MtpdHelper.MTPD);
53 }
Hung-ying Tyan2b04d292009-06-27 15:59:44 +080054}