1/*
2 * Copyright (C) 2006 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.internal.telephony.cdma;
18
19import android.os.Message;
20import android.util.Log;
21
22import com.android.internal.telephony.DataConnection;
23import com.android.internal.telephony.gsm.ApnSetting;
24import com.android.internal.telephony.Phone;
25import com.android.internal.telephony.RILConstants;
26
27/**
28 * {@hide}
29 */
30public class CdmaDataConnection extends DataConnection {
31
32    private static final String LOG_TAG = "CDMA";
33
34    /** Fail cause of last Data Call activate from RIL_LastDataCallActivateFailCause */
35    private final static int PS_NET_DOWN_REASON_OPERATOR_DETERMINED_BARRING         = 8;
36    private final static int PS_NET_DOWN_REASON_AUTH_FAILED                         = 29;
37    private final static int PS_NET_DOWN_REASON_OPTION_NOT_SUPPORTED                = 32;
38    private final static int PS_NET_DOWN_REASON_OPTION_UNSUBSCRIBED                 = 33;
39
40
41    // ***** Constructor
42    private CdmaDataConnection(CDMAPhone phone, String name) {
43        super(phone, name);
44    }
45
46    /**
47     * Create the connection object
48     *
49     * @param phone
50     * @return CdmaDataConnection that was created.
51     */
52    static CdmaDataConnection makeDataConnection(CDMAPhone phone) {
53        synchronized (mCountLock) {
54            mCount += 1;
55        }
56        CdmaDataConnection cdmaDc = new CdmaDataConnection(phone, "CdmaDataConnection-" + mCount);
57        cdmaDc.start();
58        if (DBG) cdmaDc.log("Made " + cdmaDc.getName());
59        return cdmaDc;
60    }
61
62    /**
63     * Begin setting up a data connection, calls setupDataCall
64     * and the ConnectionParams will be returned with the
65     * EVENT_SETUP_DATA_CONNECTION_DONE AsyncResul.userObj.
66     *
67     * @param cp is the connection parameters
68     */
69    @Override
70    protected void onConnect(ConnectionParams cp) {
71        if (DBG) log("CdmaDataConnection Connecting...");
72
73        createTime = -1;
74        lastFailTime = -1;
75        lastFailCause = FailCause.NONE;
76        int dataProfile;
77        if ((cp.apn != null) && (cp.apn.types.length > 0) && (cp.apn.types[0] != null) &&
78                (cp.apn.types[0].equals(Phone.APN_TYPE_DUN))) {
79            if (DBG) log("CdmaDataConnection using DUN");
80            dataProfile = RILConstants.DATA_PROFILE_TETHERED;
81        } else {
82            dataProfile = RILConstants.DATA_PROFILE_DEFAULT;
83        }
84
85        // msg.obj will be returned in AsyncResult.userObj;
86        Message msg = obtainMessage(EVENT_SETUP_DATA_CONNECTION_DONE, cp);
87        msg.obj = cp;
88        phone.mCM.setupDataCall(
89                Integer.toString(RILConstants.SETUP_DATA_TECH_CDMA),
90                Integer.toString(dataProfile),
91                null, null, null,
92                Integer.toString(RILConstants.SETUP_DATA_AUTH_PAP_CHAP),
93                RILConstants.SETUP_DATA_PROTOCOL_IP, msg);
94    }
95
96    @Override
97    public String toString() {
98        return "State=" + getCurrentState().getName() + " create=" + createTime + " lastFail="
99                + lastFailTime + " lastFasilCause=" + lastFailCause;
100    }
101
102    @Override
103    protected FailCause getFailCauseFromRequest(int rilCause) {
104        FailCause cause;
105
106        switch (rilCause) {
107            case PS_NET_DOWN_REASON_OPERATOR_DETERMINED_BARRING:
108                cause = FailCause.OPERATOR_BARRED;
109                break;
110            case PS_NET_DOWN_REASON_AUTH_FAILED:
111                cause = FailCause.USER_AUTHENTICATION;
112                break;
113            case PS_NET_DOWN_REASON_OPTION_NOT_SUPPORTED:
114                cause = FailCause.SERVICE_OPTION_NOT_SUPPORTED;
115                break;
116            case PS_NET_DOWN_REASON_OPTION_UNSUBSCRIBED:
117                cause = FailCause.SERVICE_OPTION_NOT_SUBSCRIBED;
118                break;
119            default:
120                cause = FailCause.UNKNOWN;
121        }
122        return cause;
123    }
124
125    @Override
126    protected boolean isDnsOk(String[] domainNameServers) {
127        if ((NULL_IP.equals(domainNameServers[0])
128                && NULL_IP.equals(domainNameServers[1])
129                && !((CDMAPhone) phone).isDnsCheckDisabled())) {
130            return false;
131        } else {
132            return true;
133        }
134    }
135
136    @Override
137    protected void log(String s) {
138        Log.d(LOG_TAG, "[" + getName() + "] " + s);
139    }
140}
141