/* //device/system/reference-ril/reference-ril.c
**
** Copyright 2006, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#include <telephony/ril_cdma_sms.h>
#include <telephony/librilutils.h>
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/cdefs.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
#include <alloca.h>
#include "atchannel.h"
#include "at_tok.h"
#include "misc.h"
#include <getopt.h>
#include <sys/socket.h>
#include <cutils/sockets.h>
#include <termios.h>
#include <sys/system_properties.h>
#include "ril.h"
#include "hardware/qemu_pipe.h"
#define LOG_TAG "RIL"
#include <utils/Log.h>
static void *noopRemoveWarning( void *a ) { return a; }
#define RIL_UNUSED_PARM(a) noopRemoveWarning((void *)&(a));
#define MAX_AT_RESPONSE 0x1000
/* pathname returned from RIL_REQUEST_SETUP_DATA_CALL / RIL_REQUEST_SETUP_DEFAULT_PDP */
#define PPP_TTY_PATH "eth0"
// Default MTU value
#define DEFAULT_MTU 1500
#ifdef USE_TI_COMMANDS
// Enable a workaround
// 1) Make incoming call, do not answer
// 2) Hangup remote end
// Expected: call should disappear from CLCC line
// Actual: Call shows as "ACTIVE" before disappearing
#define WORKAROUND_ERRONEOUS_ANSWER 1
// Some varients of the TI stack do not support the +CGEV unsolicited
// response. However, they seem to send an unsolicited +CME ERROR: 150
#define WORKAROUND_FAKE_CGEV 1
#endif
/* Modem Technology bits */
#define MDM_GSM 0x01
#define MDM_WCDMA 0x02
#define MDM_CDMA 0x04
#define MDM_EVDO 0x08
#define MDM_LTE 0x10
typedef struct {
int supportedTechs; // Bitmask of supported Modem Technology bits
int currentTech; // Technology the modem is currently using (in the format used by modem)
int isMultimode;
// Preferred mode bitmask. This is actually 4 byte-sized bitmasks with different priority values,
// in which the byte number from LSB to MSB give the priority.
//
// |MSB| | |LSB
// value: |00 |00 |00 |00
// byte #: |3 |2 |1 |0
//
// Higher byte order give higher priority. Thus, a value of 0x0000000f represents
// a preferred mode of GSM, WCDMA, CDMA, and EvDo in which all are equally preferrable, whereas
// 0x00000201 represents a mode with GSM and WCDMA, in which WCDMA is preferred over GSM
int32_t preferredNetworkMode;
int subscription_source;
} ModemInfo;
static ModemInfo *sMdmInfo;
// TECH returns the current technology in the format used by the modem.
// It can be used as an l-value
#define TECH(mdminfo) ((mdminfo)->currentTech)
// TECH_BIT returns the bitmask equivalent of the current tech
#define TECH_BIT(mdminfo) (1 << ((mdminfo)->currentTech))
#define IS_MULTIMODE(mdminfo) ((mdminfo)->isMultimode)
#define TECH_SUPPORTED(mdminfo, tech) ((mdminfo)->supportedTechs & (tech))
#define PREFERRED_NETWORK(mdminfo) ((mdminfo)->preferredNetworkMode)
// CDMA Subscription Source
#define SSOURCE(mdminfo) ((mdminfo)->subscription_source)
static int net2modem[] = {
MDM_GSM | MDM_WCDMA, // 0 - GSM / WCDMA Pref
MDM_GSM, // 1 - GSM only
MDM_WCDMA, // 2 - WCDMA only
MDM_GSM | MDM_WCDMA, // 3 - GSM / WCDMA Auto
MDM_CDMA | MDM_EVDO, // 4 - CDMA / EvDo Auto
MDM_CDMA, // 5 - CDMA only
MDM_EVDO, // 6 - EvDo only
MDM_GSM | MDM_WCDMA | MDM_CDMA | MDM_EVDO, // 7 - GSM/WCDMA, CDMA, EvDo
MDM_LTE | MDM_CDMA | MDM_EVDO, // 8 - LTE, CDMA and EvDo
MDM_LTE | MDM_GSM | MDM_WCDMA, // 9 - LTE, GSM/WCDMA
MDM_LTE | MDM_CDMA | MDM_EVDO | MDM_GSM | MDM_WCDMA, // 10 - LTE, CDMA, EvDo, GSM/WCDMA
MDM_LTE, // 11 - LTE only
};
static int32_t net2pmask[] = {
MDM_GSM | (MDM_WCDMA << 8), // 0 - GSM / WCDMA Pref
MDM_GSM, // 1 - GSM only
MDM_WCDMA, // 2 - WCDMA only
MDM_GSM | MDM_WCDMA, // 3 - GSM / WCDMA Auto
MDM_CDMA | MDM_EVDO, // 4 - CDMA / EvDo Auto
MDM_CDMA, // 5 - CDMA only
MDM_EVDO, // 6 - EvDo only
MDM_GSM | MDM_WCDMA | MDM_CDMA | MDM_EVDO, // 7 - GSM/WCDMA, CDMA, EvDo
MDM_LTE | MDM_CDMA | MDM_EVDO, // 8 - LTE, CDMA and EvDo
MDM_LTE | MDM_GSM | MDM_WCDMA, // 9 - LTE, GSM/WCDMA
MDM_LTE | MDM_CDMA | MDM_EVDO | MDM_GSM | MDM_WCDMA, // 10 - LTE, CDMA, EvDo, GSM/WCDMA
MDM_LTE, // 11 - LTE only
};
static int is3gpp2(int radioTech) {
switch (radioTech) {
case RADIO_TECH_IS95A:
case RADIO_TECH_IS95B:
case RADIO_TECH_1xRTT:
case RADIO_TECH_EVDO_0:
case RADIO_TECH_EVDO_A:
case RADIO_TECH_EVDO_B:
case RADIO_TECH_EHRPD:
return 1;
default:
return 0;
}
}
typedef enum {
SIM_ABSENT = 0,
SIM_NOT_READY = 1,
SIM_READY = 2, /* SIM_READY means the radio state is RADIO_STATE_SIM_READY */
SIM_PIN = 3,
SIM_PUK = 4,
SIM_NETWORK_PERSONALIZATION = 5,
RUIM_ABSENT = 6,
RUIM_NOT_READY = 7,
RUIM_READY = 8,
RUIM_PIN = 9,
RUIM_PUK = 10,
RUIM_NETWORK_PERSONALIZATION = 11
} SIM_Status;
static void onRequest (int request, void *data, size_t datalen, RIL_Token t);
static RIL_RadioState currentState();
static int onSupports (int requestCode);
static void onCancel (RIL_Token t);
static const char *getVersion();
static int isRadioOn();
static SIM_Status getSIMStatus();
static int getCardStatus(RIL_CardStatus_v6 **pp_card_status);
static void freeCardStatus(RIL_CardStatus_v6 *p_card_status);
static void onDataCallListChanged(void *param);
extern const char * requestToString(int request);
/*** Static Variables ***/
static const RIL_RadioFunctions s_callbacks = {
RIL_VERSION,
onRequest,
currentState,
onSupports,
onCancel,
getVersion
};
#ifdef RIL_SHLIB
static const struct RIL_Env *s_rilenv;
#define RIL_onRequestComplete(t, e, response, responselen) s_rilenv->OnRequestComplete(t,e, response, responselen)
#define RIL_onUnsolicitedResponse(a,b,c) s_rilenv->OnUnsolicitedResponse(a,b,c)
#define RIL_requestTimedCallback(a,b,c) s_rilenv->RequestTimedCallback(a,b,c)
#endif
static RIL_RadioState sState = RADIO_STATE_UNAVAILABLE;
static pthread_mutex_t s_state_mutex = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t s_state_cond = PTHREAD_COND_INITIALIZER;
static int s_port = -1;
static const char * s_device_path = NULL;
static int s_device_socket = 0;
/* trigger change to this with s_state_cond */
static int s_closed = 0;
static int sFD; /* file desc of AT channel */
static char sATBuffer[MAX_AT_RESPONSE+1];
static char *sATBufferCur = NULL;
static const struct timeval TIMEVAL_SIMPOLL = {1,0};
static const struct timeval TIMEVAL_CALLSTATEPOLL = {0,500000};
static cons
评论0