The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1 | /* //device/system/reference-ril/reference-ril.c |
| 2 | ** |
| 3 | ** Copyright 2006, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 18 | #include <telephony/ril_cdma_sms.h> |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 19 | #include <telephony/librilutils.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 20 | #include <stdio.h> |
| 21 | #include <assert.h> |
| 22 | #include <string.h> |
| 23 | #include <errno.h> |
| 24 | #include <unistd.h> |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 25 | #include <sys/cdefs.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 26 | #include <sys/types.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <fcntl.h> |
| 29 | #include <pthread.h> |
| 30 | #include <alloca.h> |
| 31 | #include "atchannel.h" |
| 32 | #include "at_tok.h" |
| 33 | #include "misc.h" |
| 34 | #include <getopt.h> |
| 35 | #include <sys/socket.h> |
| 36 | #include <cutils/sockets.h> |
| 37 | #include <termios.h> |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 38 | #include <sys/system_properties.h> |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 39 | |
Wink Saville | 9a9fbd2 | 2011-02-15 17:13:10 -0800 | [diff] [blame] | 40 | #include "ril.h" |
Vladimir Chtchetkine | 385a739 | 2011-08-04 14:03:07 -0700 | [diff] [blame] | 41 | #include "hardware/qemu_pipe.h" |
Wink Saville | 9a9fbd2 | 2011-02-15 17:13:10 -0800 | [diff] [blame] | 42 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 43 | #define LOG_TAG "RIL" |
| 44 | #include <utils/Log.h> |
| 45 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 46 | static void *noopRemoveWarning( void *a ) { return a; } |
| 47 | #define RIL_UNUSED_PARM(a) noopRemoveWarning((void *)&(a)); |
| 48 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 49 | #define MAX_AT_RESPONSE 0x1000 |
| 50 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 51 | /* pathname returned from RIL_REQUEST_SETUP_DATA_CALL / RIL_REQUEST_SETUP_DEFAULT_PDP */ |
Robert Greenwalt | f838ede | 2010-07-15 18:54:53 -0700 | [diff] [blame] | 52 | #define PPP_TTY_PATH "eth0" |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 53 | |
| 54 | #ifdef USE_TI_COMMANDS |
| 55 | |
| 56 | // Enable a workaround |
| 57 | // 1) Make incoming call, do not answer |
| 58 | // 2) Hangup remote end |
| 59 | // Expected: call should disappear from CLCC line |
| 60 | // Actual: Call shows as "ACTIVE" before disappearing |
| 61 | #define WORKAROUND_ERRONEOUS_ANSWER 1 |
| 62 | |
| 63 | // Some varients of the TI stack do not support the +CGEV unsolicited |
| 64 | // response. However, they seem to send an unsolicited +CME ERROR: 150 |
| 65 | #define WORKAROUND_FAKE_CGEV 1 |
| 66 | #endif |
| 67 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 68 | /* Modem Technology bits */ |
| 69 | #define MDM_GSM 0x01 |
| 70 | #define MDM_WCDMA 0x02 |
| 71 | #define MDM_CDMA 0x04 |
| 72 | #define MDM_EVDO 0x08 |
| 73 | #define MDM_LTE 0x10 |
| 74 | |
| 75 | typedef struct { |
| 76 | int supportedTechs; // Bitmask of supported Modem Technology bits |
| 77 | int currentTech; // Technology the modem is currently using (in the format used by modem) |
| 78 | int isMultimode; |
| 79 | |
| 80 | // Preferred mode bitmask. This is actually 4 byte-sized bitmasks with different priority values, |
| 81 | // in which the byte number from LSB to MSB give the priority. |
| 82 | // |
| 83 | // |MSB| | |LSB |
| 84 | // value: |00 |00 |00 |00 |
| 85 | // byte #: |3 |2 |1 |0 |
| 86 | // |
| 87 | // Higher byte order give higher priority. Thus, a value of 0x0000000f represents |
| 88 | // a preferred mode of GSM, WCDMA, CDMA, and EvDo in which all are equally preferrable, whereas |
| 89 | // 0x00000201 represents a mode with GSM and WCDMA, in which WCDMA is preferred over GSM |
| 90 | int32_t preferredNetworkMode; |
| 91 | int subscription_source; |
| 92 | |
| 93 | } ModemInfo; |
| 94 | |
| 95 | static ModemInfo *sMdmInfo; |
| 96 | // TECH returns the current technology in the format used by the modem. |
| 97 | // It can be used as an l-value |
| 98 | #define TECH(mdminfo) ((mdminfo)->currentTech) |
| 99 | // TECH_BIT returns the bitmask equivalent of the current tech |
| 100 | #define TECH_BIT(mdminfo) (1 << ((mdminfo)->currentTech)) |
| 101 | #define IS_MULTIMODE(mdminfo) ((mdminfo)->isMultimode) |
| 102 | #define TECH_SUPPORTED(mdminfo, tech) ((mdminfo)->supportedTechs & (tech)) |
| 103 | #define PREFERRED_NETWORK(mdminfo) ((mdminfo)->preferredNetworkMode) |
| 104 | // CDMA Subscription Source |
| 105 | #define SSOURCE(mdminfo) ((mdminfo)->subscription_source) |
| 106 | |
| 107 | static int net2modem[] = { |
| 108 | MDM_GSM | MDM_WCDMA, // 0 - GSM / WCDMA Pref |
| 109 | MDM_GSM, // 1 - GSM only |
| 110 | MDM_WCDMA, // 2 - WCDMA only |
| 111 | MDM_GSM | MDM_WCDMA, // 3 - GSM / WCDMA Auto |
| 112 | MDM_CDMA | MDM_EVDO, // 4 - CDMA / EvDo Auto |
| 113 | MDM_CDMA, // 5 - CDMA only |
| 114 | MDM_EVDO, // 6 - EvDo only |
| 115 | MDM_GSM | MDM_WCDMA | MDM_CDMA | MDM_EVDO, // 7 - GSM/WCDMA, CDMA, EvDo |
| 116 | MDM_LTE | MDM_CDMA | MDM_EVDO, // 8 - LTE, CDMA and EvDo |
| 117 | MDM_LTE | MDM_GSM | MDM_WCDMA, // 9 - LTE, GSM/WCDMA |
| 118 | MDM_LTE | MDM_CDMA | MDM_EVDO | MDM_GSM | MDM_WCDMA, // 10 - LTE, CDMA, EvDo, GSM/WCDMA |
| 119 | MDM_LTE, // 11 - LTE only |
| 120 | }; |
| 121 | |
| 122 | static int32_t net2pmask[] = { |
| 123 | MDM_GSM | (MDM_WCDMA << 8), // 0 - GSM / WCDMA Pref |
| 124 | MDM_GSM, // 1 - GSM only |
| 125 | MDM_WCDMA, // 2 - WCDMA only |
| 126 | MDM_GSM | MDM_WCDMA, // 3 - GSM / WCDMA Auto |
| 127 | MDM_CDMA | MDM_EVDO, // 4 - CDMA / EvDo Auto |
| 128 | MDM_CDMA, // 5 - CDMA only |
| 129 | MDM_EVDO, // 6 - EvDo only |
| 130 | MDM_GSM | MDM_WCDMA | MDM_CDMA | MDM_EVDO, // 7 - GSM/WCDMA, CDMA, EvDo |
| 131 | MDM_LTE | MDM_CDMA | MDM_EVDO, // 8 - LTE, CDMA and EvDo |
| 132 | MDM_LTE | MDM_GSM | MDM_WCDMA, // 9 - LTE, GSM/WCDMA |
| 133 | MDM_LTE | MDM_CDMA | MDM_EVDO | MDM_GSM | MDM_WCDMA, // 10 - LTE, CDMA, EvDo, GSM/WCDMA |
| 134 | MDM_LTE, // 11 - LTE only |
| 135 | }; |
| 136 | |
| 137 | static int is3gpp2(int radioTech) { |
| 138 | switch (radioTech) { |
| 139 | case RADIO_TECH_IS95A: |
| 140 | case RADIO_TECH_IS95B: |
| 141 | case RADIO_TECH_1xRTT: |
| 142 | case RADIO_TECH_EVDO_0: |
| 143 | case RADIO_TECH_EVDO_A: |
| 144 | case RADIO_TECH_EVDO_B: |
| 145 | case RADIO_TECH_EHRPD: |
| 146 | return 1; |
| 147 | default: |
| 148 | return 0; |
| 149 | } |
| 150 | } |
| 151 | |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 152 | typedef enum { |
| 153 | SIM_ABSENT = 0, |
| 154 | SIM_NOT_READY = 1, |
| 155 | SIM_READY = 2, /* SIM_READY means the radio state is RADIO_STATE_SIM_READY */ |
| 156 | SIM_PIN = 3, |
| 157 | SIM_PUK = 4, |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 158 | SIM_NETWORK_PERSONALIZATION = 5, |
| 159 | RUIM_ABSENT = 6, |
| 160 | RUIM_NOT_READY = 7, |
| 161 | RUIM_READY = 8, |
| 162 | RUIM_PIN = 9, |
| 163 | RUIM_PUK = 10, |
| 164 | RUIM_NETWORK_PERSONALIZATION = 11 |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 165 | } SIM_Status; |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 166 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 167 | static void onRequest (int request, void *data, size_t datalen, RIL_Token t); |
| 168 | static RIL_RadioState currentState(); |
| 169 | static int onSupports (int requestCode); |
| 170 | static void onCancel (RIL_Token t); |
| 171 | static const char *getVersion(); |
| 172 | static int isRadioOn(); |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 173 | static SIM_Status getSIMStatus(); |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 174 | static int getCardStatus(RIL_CardStatus_v6 **pp_card_status); |
| 175 | static void freeCardStatus(RIL_CardStatus_v6 *p_card_status); |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 176 | static void onDataCallListChanged(void *param); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 177 | |
| 178 | extern const char * requestToString(int request); |
| 179 | |
| 180 | /*** Static Variables ***/ |
| 181 | static const RIL_RadioFunctions s_callbacks = { |
| 182 | RIL_VERSION, |
| 183 | onRequest, |
| 184 | currentState, |
| 185 | onSupports, |
| 186 | onCancel, |
| 187 | getVersion |
| 188 | }; |
| 189 | |
| 190 | #ifdef RIL_SHLIB |
| 191 | static const struct RIL_Env *s_rilenv; |
| 192 | |
| 193 | #define RIL_onRequestComplete(t, e, response, responselen) s_rilenv->OnRequestComplete(t,e, response, responselen) |
| 194 | #define RIL_onUnsolicitedResponse(a,b,c) s_rilenv->OnUnsolicitedResponse(a,b,c) |
| 195 | #define RIL_requestTimedCallback(a,b,c) s_rilenv->RequestTimedCallback(a,b,c) |
| 196 | #endif |
| 197 | |
| 198 | static RIL_RadioState sState = RADIO_STATE_UNAVAILABLE; |
| 199 | |
| 200 | static pthread_mutex_t s_state_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 201 | static pthread_cond_t s_state_cond = PTHREAD_COND_INITIALIZER; |
| 202 | |
| 203 | static int s_port = -1; |
| 204 | static const char * s_device_path = NULL; |
| 205 | static int s_device_socket = 0; |
| 206 | |
| 207 | /* trigger change to this with s_state_cond */ |
| 208 | static int s_closed = 0; |
| 209 | |
| 210 | static int sFD; /* file desc of AT channel */ |
| 211 | static char sATBuffer[MAX_AT_RESPONSE+1]; |
| 212 | static char *sATBufferCur = NULL; |
| 213 | |
| 214 | static const struct timeval TIMEVAL_SIMPOLL = {1,0}; |
| 215 | static const struct timeval TIMEVAL_CALLSTATEPOLL = {0,500000}; |
| 216 | static const struct timeval TIMEVAL_0 = {0,0}; |
| 217 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 218 | static int s_ims_registered = 0; // 0==unregistered |
| 219 | static int s_ims_services = 1; // & 0x1 == sms over ims supported |
| 220 | static int s_ims_format = 1; // FORMAT_3GPP(1) vs FORMAT_3GPP2(2); |
| 221 | static int s_ims_cause_retry = 0; // 1==causes sms over ims to temp fail |
| 222 | static int s_ims_cause_perm_failure = 0; // 1==causes sms over ims to permanent fail |
| 223 | static int s_ims_gsm_retry = 0; // 1==causes sms over gsm to temp fail |
| 224 | static int s_ims_gsm_fail = 0; // 1==causes sms over gsm to permanent fail |
| 225 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 226 | #ifdef WORKAROUND_ERRONEOUS_ANSWER |
| 227 | // Max number of times we'll try to repoll when we think |
| 228 | // we have a AT+CLCC race condition |
| 229 | #define REPOLL_CALLS_COUNT_MAX 4 |
| 230 | |
| 231 | // Line index that was incoming or waiting at last poll, or -1 for none |
| 232 | static int s_incomingOrWaitingLine = -1; |
| 233 | // Number of times we've asked for a repoll of AT+CLCC |
| 234 | static int s_repollCallsCount = 0; |
| 235 | // Should we expect a call to be answered in the next CLCC? |
| 236 | static int s_expectAnswer = 0; |
| 237 | #endif /* WORKAROUND_ERRONEOUS_ANSWER */ |
| 238 | |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 239 | static int s_cell_info_rate_ms = INT_MAX; |
| 240 | static int s_mcc = 0; |
| 241 | static int s_mnc = 0; |
| 242 | static int s_lac = 0; |
| 243 | static int s_cid = 0; |
| 244 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 245 | static void pollSIMState (void *param); |
| 246 | static void setRadioState(RIL_RadioState newState); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 247 | static void setRadioTechnology(ModemInfo *mdm, int newtech); |
| 248 | static int query_ctec(ModemInfo *mdm, int *current, int32_t *preferred); |
| 249 | static int parse_technology_response(const char *response, int *current, int32_t *preferred); |
| 250 | static int techFromModemType(int mdmtype); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 251 | |
| 252 | static int clccStateToRILState(int state, RIL_CallState *p_state) |
| 253 | |
| 254 | { |
| 255 | switch(state) { |
| 256 | case 0: *p_state = RIL_CALL_ACTIVE; return 0; |
| 257 | case 1: *p_state = RIL_CALL_HOLDING; return 0; |
| 258 | case 2: *p_state = RIL_CALL_DIALING; return 0; |
| 259 | case 3: *p_state = RIL_CALL_ALERTING; return 0; |
| 260 | case 4: *p_state = RIL_CALL_INCOMING; return 0; |
| 261 | case 5: *p_state = RIL_CALL_WAITING; return 0; |
| 262 | default: return -1; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /** |
| 267 | * Note: directly modified line and has *p_call point directly into |
| 268 | * modified line |
| 269 | */ |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 270 | static int callFromCLCCLine(char *line, RIL_Call *p_call) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 271 | { |
| 272 | //+CLCC: 1,0,2,0,0,\"+18005551212\",145 |
| 273 | // index,isMT,state,mode,isMpty(,number,TOA)? |
| 274 | |
| 275 | int err; |
| 276 | int state; |
| 277 | int mode; |
| 278 | |
| 279 | err = at_tok_start(&line); |
| 280 | if (err < 0) goto error; |
| 281 | |
| 282 | err = at_tok_nextint(&line, &(p_call->index)); |
| 283 | if (err < 0) goto error; |
| 284 | |
| 285 | err = at_tok_nextbool(&line, &(p_call->isMT)); |
| 286 | if (err < 0) goto error; |
| 287 | |
| 288 | err = at_tok_nextint(&line, &state); |
| 289 | if (err < 0) goto error; |
| 290 | |
| 291 | err = clccStateToRILState(state, &(p_call->state)); |
| 292 | if (err < 0) goto error; |
| 293 | |
| 294 | err = at_tok_nextint(&line, &mode); |
| 295 | if (err < 0) goto error; |
| 296 | |
| 297 | p_call->isVoice = (mode == 0); |
| 298 | |
| 299 | err = at_tok_nextbool(&line, &(p_call->isMpty)); |
| 300 | if (err < 0) goto error; |
| 301 | |
| 302 | if (at_tok_hasmore(&line)) { |
| 303 | err = at_tok_nextstr(&line, &(p_call->number)); |
| 304 | |
| 305 | /* tolerate null here */ |
| 306 | if (err < 0) return 0; |
| 307 | |
| 308 | // Some lame implementations return strings |
| 309 | // like "NOT AVAILABLE" in the CLCC line |
| 310 | if (p_call->number != NULL |
| 311 | && 0 == strspn(p_call->number, "+0123456789") |
| 312 | ) { |
| 313 | p_call->number = NULL; |
| 314 | } |
| 315 | |
| 316 | err = at_tok_nextint(&line, &p_call->toa); |
| 317 | if (err < 0) goto error; |
| 318 | } |
| 319 | |
Wink Saville | 74fa388 | 2009-12-22 15:35:41 -0800 | [diff] [blame] | 320 | p_call->uusInfo = NULL; |
| 321 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 322 | return 0; |
| 323 | |
| 324 | error: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 325 | RLOGE("invalid CLCC line\n"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 326 | return -1; |
| 327 | } |
| 328 | |
| 329 | |
| 330 | /** do post-AT+CFUN=1 initialization */ |
| 331 | static void onRadioPowerOn() |
| 332 | { |
| 333 | #ifdef USE_TI_COMMANDS |
| 334 | /* Must be after CFUN=1 */ |
| 335 | /* TI specific -- notifications for CPHS things such */ |
| 336 | /* as CPHS message waiting indicator */ |
| 337 | |
| 338 | at_send_command("AT%CPHS=1", NULL); |
| 339 | |
| 340 | /* TI specific -- enable NITZ unsol notifs */ |
| 341 | at_send_command("AT%CTZV=1", NULL); |
| 342 | #endif |
| 343 | |
| 344 | pollSIMState(NULL); |
| 345 | } |
| 346 | |
| 347 | /** do post- SIM ready initialization */ |
| 348 | static void onSIMReady() |
| 349 | { |
| 350 | at_send_command_singleline("AT+CSMS=1", "+CSMS:", NULL); |
| 351 | /* |
| 352 | * Always send SMS messages directly to the TE |
| 353 | * |
| 354 | * mode = 1 // discard when link is reserved (link should never be |
| 355 | * reserved) |
| 356 | * mt = 2 // most messages routed to TE |
| 357 | * bm = 2 // new cell BM's routed to TE |
| 358 | * ds = 1 // Status reports routed to TE |
| 359 | * bfr = 1 // flush buffer |
| 360 | */ |
| 361 | at_send_command("AT+CNMI=1,2,2,1,1", NULL); |
| 362 | } |
| 363 | |
| 364 | static void requestRadioPower(void *data, size_t datalen, RIL_Token t) |
| 365 | { |
| 366 | int onOff; |
| 367 | |
| 368 | int err; |
| 369 | ATResponse *p_response = NULL; |
| 370 | |
| 371 | assert (datalen >= sizeof(int *)); |
| 372 | onOff = ((int *)data)[0]; |
| 373 | |
| 374 | if (onOff == 0 && sState != RADIO_STATE_OFF) { |
| 375 | err = at_send_command("AT+CFUN=0", &p_response); |
| 376 | if (err < 0 || p_response->success == 0) goto error; |
| 377 | setRadioState(RADIO_STATE_OFF); |
| 378 | } else if (onOff > 0 && sState == RADIO_STATE_OFF) { |
| 379 | err = at_send_command("AT+CFUN=1", &p_response); |
| 380 | if (err < 0|| p_response->success == 0) { |
| 381 | // Some stacks return an error when there is no SIM, |
| 382 | // but they really turn the RF portion on |
| 383 | // So, if we get an error, let's check to see if it |
| 384 | // turned on anyway |
| 385 | |
| 386 | if (isRadioOn() != 1) { |
| 387 | goto error; |
| 388 | } |
| 389 | } |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 390 | setRadioState(RADIO_STATE_ON); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | at_response_free(p_response); |
| 394 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 395 | return; |
| 396 | error: |
| 397 | at_response_free(p_response); |
| 398 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 399 | } |
| 400 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 401 | static void requestOrSendDataCallList(RIL_Token *t); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 402 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 403 | static void onDataCallListChanged(void *param __unused) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 404 | { |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 405 | requestOrSendDataCallList(NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 406 | } |
| 407 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 408 | static void requestDataCallList(void *data __unused, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 409 | { |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 410 | requestOrSendDataCallList(&t); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 411 | } |
| 412 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 413 | static void requestOrSendDataCallList(RIL_Token *t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 414 | { |
| 415 | ATResponse *p_response; |
| 416 | ATLine *p_cur; |
| 417 | int err; |
| 418 | int n = 0; |
| 419 | char *out; |
| 420 | |
| 421 | err = at_send_command_multiline ("AT+CGACT?", "+CGACT:", &p_response); |
| 422 | if (err != 0 || p_response->success == 0) { |
| 423 | if (t != NULL) |
| 424 | RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 425 | else |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 426 | RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 427 | NULL, 0); |
| 428 | return; |
| 429 | } |
| 430 | |
| 431 | for (p_cur = p_response->p_intermediates; p_cur != NULL; |
| 432 | p_cur = p_cur->p_next) |
| 433 | n++; |
| 434 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 435 | RIL_Data_Call_Response_v9 *responses = |
| 436 | alloca(n * sizeof(RIL_Data_Call_Response_v9)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 437 | |
| 438 | int i; |
| 439 | for (i = 0; i < n; i++) { |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 440 | responses[i].status = -1; |
Wink Saville | 250eb3c | 2011-06-22 09:11:34 -0700 | [diff] [blame] | 441 | responses[i].suggestedRetryTime = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 442 | responses[i].cid = -1; |
| 443 | responses[i].active = -1; |
| 444 | responses[i].type = ""; |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 445 | responses[i].ifname = ""; |
| 446 | responses[i].addresses = ""; |
| 447 | responses[i].dnses = ""; |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 448 | responses[i].gateways = ""; |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 449 | responses[i].pcscf = ""; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 452 | RIL_Data_Call_Response_v9 *response = responses; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 453 | for (p_cur = p_response->p_intermediates; p_cur != NULL; |
| 454 | p_cur = p_cur->p_next) { |
| 455 | char *line = p_cur->line; |
| 456 | |
| 457 | err = at_tok_start(&line); |
| 458 | if (err < 0) |
| 459 | goto error; |
| 460 | |
| 461 | err = at_tok_nextint(&line, &response->cid); |
| 462 | if (err < 0) |
| 463 | goto error; |
| 464 | |
| 465 | err = at_tok_nextint(&line, &response->active); |
| 466 | if (err < 0) |
| 467 | goto error; |
| 468 | |
| 469 | response++; |
| 470 | } |
| 471 | |
| 472 | at_response_free(p_response); |
| 473 | |
| 474 | err = at_send_command_multiline ("AT+CGDCONT?", "+CGDCONT:", &p_response); |
| 475 | if (err != 0 || p_response->success == 0) { |
| 476 | if (t != NULL) |
| 477 | RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 478 | else |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 479 | RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 480 | NULL, 0); |
| 481 | return; |
| 482 | } |
| 483 | |
| 484 | for (p_cur = p_response->p_intermediates; p_cur != NULL; |
| 485 | p_cur = p_cur->p_next) { |
| 486 | char *line = p_cur->line; |
| 487 | int cid; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 488 | |
| 489 | err = at_tok_start(&line); |
| 490 | if (err < 0) |
| 491 | goto error; |
| 492 | |
| 493 | err = at_tok_nextint(&line, &cid); |
| 494 | if (err < 0) |
| 495 | goto error; |
| 496 | |
| 497 | for (i = 0; i < n; i++) { |
| 498 | if (responses[i].cid == cid) |
| 499 | break; |
| 500 | } |
| 501 | |
| 502 | if (i >= n) { |
| 503 | /* details for a context we didn't hear about in the last request */ |
| 504 | continue; |
| 505 | } |
| 506 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 507 | // Assume no error |
| 508 | responses[i].status = 0; |
| 509 | |
| 510 | // type |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 511 | err = at_tok_nextstr(&line, &out); |
| 512 | if (err < 0) |
| 513 | goto error; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 514 | responses[i].type = alloca(strlen(out) + 1); |
| 515 | strcpy(responses[i].type, out); |
| 516 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 517 | // APN ignored for v5 |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 518 | err = at_tok_nextstr(&line, &out); |
| 519 | if (err < 0) |
| 520 | goto error; |
| 521 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 522 | responses[i].ifname = alloca(strlen(PPP_TTY_PATH) + 1); |
| 523 | strcpy(responses[i].ifname, PPP_TTY_PATH); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 524 | |
| 525 | err = at_tok_nextstr(&line, &out); |
| 526 | if (err < 0) |
| 527 | goto error; |
| 528 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 529 | responses[i].addresses = alloca(strlen(out) + 1); |
| 530 | strcpy(responses[i].addresses, out); |
| 531 | |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 532 | { |
| 533 | char propValue[PROP_VALUE_MAX]; |
| 534 | |
| 535 | if (__system_property_get("ro.kernel.qemu", propValue) != 0) { |
| 536 | /* We are in the emulator - the dns servers are listed |
| 537 | * by the following system properties, setup in |
| 538 | * /system/etc/init.goldfish.sh: |
| 539 | * - net.eth0.dns1 |
| 540 | * - net.eth0.dns2 |
| 541 | * - net.eth0.dns3 |
| 542 | * - net.eth0.dns4 |
| 543 | */ |
| 544 | const int dnslist_sz = 128; |
| 545 | char* dnslist = alloca(dnslist_sz); |
| 546 | const char* separator = ""; |
| 547 | int nn; |
| 548 | |
| 549 | dnslist[0] = 0; |
| 550 | for (nn = 1; nn <= 4; nn++) { |
| 551 | /* Probe net.eth0.dns<n> */ |
| 552 | char propName[PROP_NAME_MAX]; |
| 553 | snprintf(propName, sizeof propName, "net.eth0.dns%d", nn); |
| 554 | |
| 555 | /* Ignore if undefined */ |
| 556 | if (__system_property_get(propName, propValue) == 0) { |
| 557 | continue; |
| 558 | } |
| 559 | |
| 560 | /* Append the DNS IP address */ |
| 561 | strlcat(dnslist, separator, dnslist_sz); |
| 562 | strlcat(dnslist, propValue, dnslist_sz); |
| 563 | separator = " "; |
| 564 | } |
| 565 | responses[i].dnses = dnslist; |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 566 | |
| 567 | /* There is only on gateway in the emulator */ |
| 568 | responses[i].gateways = "10.0.2.2"; |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 569 | } |
| 570 | else { |
| 571 | /* I don't know where we are, so use the public Google DNS |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 572 | * servers by default and no gateway. |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 573 | */ |
| 574 | responses[i].dnses = "8.8.8.8 8.8.4.4"; |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 575 | responses[i].gateways = ""; |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 576 | } |
| 577 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | at_response_free(p_response); |
| 581 | |
| 582 | if (t != NULL) |
| 583 | RIL_onRequestComplete(*t, RIL_E_SUCCESS, responses, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 584 | n * sizeof(RIL_Data_Call_Response_v9)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 585 | else |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 586 | RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 587 | responses, |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 588 | n * sizeof(RIL_Data_Call_Response_v9)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 589 | |
| 590 | return; |
| 591 | |
| 592 | error: |
| 593 | if (t != NULL) |
| 594 | RIL_onRequestComplete(*t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 595 | else |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 596 | RIL_onUnsolicitedResponse(RIL_UNSOL_DATA_CALL_LIST_CHANGED, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 597 | NULL, 0); |
| 598 | |
| 599 | at_response_free(p_response); |
| 600 | } |
| 601 | |
| 602 | static void requestQueryNetworkSelectionMode( |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 603 | void *data __unused, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 604 | { |
| 605 | int err; |
| 606 | ATResponse *p_response = NULL; |
| 607 | int response = 0; |
| 608 | char *line; |
| 609 | |
| 610 | err = at_send_command_singleline("AT+COPS?", "+COPS:", &p_response); |
| 611 | |
| 612 | if (err < 0 || p_response->success == 0) { |
| 613 | goto error; |
| 614 | } |
| 615 | |
| 616 | line = p_response->p_intermediates->line; |
| 617 | |
| 618 | err = at_tok_start(&line); |
| 619 | |
| 620 | if (err < 0) { |
| 621 | goto error; |
| 622 | } |
| 623 | |
| 624 | err = at_tok_nextint(&line, &response); |
| 625 | |
| 626 | if (err < 0) { |
| 627 | goto error; |
| 628 | } |
| 629 | |
| 630 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(int)); |
| 631 | at_response_free(p_response); |
| 632 | return; |
| 633 | error: |
| 634 | at_response_free(p_response); |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 635 | RLOGE("requestQueryNetworkSelectionMode must never return error when radio is on"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 636 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 637 | } |
| 638 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 639 | static void sendCallStateChanged(void *param __unused) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 640 | { |
| 641 | RIL_onUnsolicitedResponse ( |
| 642 | RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, |
| 643 | NULL, 0); |
| 644 | } |
| 645 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 646 | static void requestGetCurrentCalls(void *data __unused, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 647 | { |
| 648 | int err; |
| 649 | ATResponse *p_response; |
| 650 | ATLine *p_cur; |
| 651 | int countCalls; |
| 652 | int countValidCalls; |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 653 | RIL_Call *p_calls; |
| 654 | RIL_Call **pp_calls; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 655 | int i; |
| 656 | int needRepoll = 0; |
| 657 | |
| 658 | #ifdef WORKAROUND_ERRONEOUS_ANSWER |
| 659 | int prevIncomingOrWaitingLine; |
| 660 | |
| 661 | prevIncomingOrWaitingLine = s_incomingOrWaitingLine; |
| 662 | s_incomingOrWaitingLine = -1; |
| 663 | #endif /*WORKAROUND_ERRONEOUS_ANSWER*/ |
| 664 | |
| 665 | err = at_send_command_multiline ("AT+CLCC", "+CLCC:", &p_response); |
| 666 | |
| 667 | if (err != 0 || p_response->success == 0) { |
| 668 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 669 | return; |
| 670 | } |
| 671 | |
| 672 | /* count the calls */ |
| 673 | for (countCalls = 0, p_cur = p_response->p_intermediates |
| 674 | ; p_cur != NULL |
| 675 | ; p_cur = p_cur->p_next |
| 676 | ) { |
| 677 | countCalls++; |
| 678 | } |
| 679 | |
| 680 | /* yes, there's an array of pointers and then an array of structures */ |
| 681 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 682 | pp_calls = (RIL_Call **)alloca(countCalls * sizeof(RIL_Call *)); |
| 683 | p_calls = (RIL_Call *)alloca(countCalls * sizeof(RIL_Call)); |
| 684 | memset (p_calls, 0, countCalls * sizeof(RIL_Call)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 685 | |
| 686 | /* init the pointer array */ |
| 687 | for(i = 0; i < countCalls ; i++) { |
| 688 | pp_calls[i] = &(p_calls[i]); |
| 689 | } |
| 690 | |
| 691 | for (countValidCalls = 0, p_cur = p_response->p_intermediates |
| 692 | ; p_cur != NULL |
| 693 | ; p_cur = p_cur->p_next |
| 694 | ) { |
| 695 | err = callFromCLCCLine(p_cur->line, p_calls + countValidCalls); |
| 696 | |
| 697 | if (err != 0) { |
| 698 | continue; |
| 699 | } |
| 700 | |
| 701 | #ifdef WORKAROUND_ERRONEOUS_ANSWER |
| 702 | if (p_calls[countValidCalls].state == RIL_CALL_INCOMING |
| 703 | || p_calls[countValidCalls].state == RIL_CALL_WAITING |
| 704 | ) { |
| 705 | s_incomingOrWaitingLine = p_calls[countValidCalls].index; |
| 706 | } |
| 707 | #endif /*WORKAROUND_ERRONEOUS_ANSWER*/ |
| 708 | |
| 709 | if (p_calls[countValidCalls].state != RIL_CALL_ACTIVE |
| 710 | && p_calls[countValidCalls].state != RIL_CALL_HOLDING |
| 711 | ) { |
| 712 | needRepoll = 1; |
| 713 | } |
| 714 | |
| 715 | countValidCalls++; |
| 716 | } |
| 717 | |
| 718 | #ifdef WORKAROUND_ERRONEOUS_ANSWER |
| 719 | // Basically: |
| 720 | // A call was incoming or waiting |
| 721 | // Now it's marked as active |
| 722 | // But we never answered it |
| 723 | // |
| 724 | // This is probably a bug, and the call will probably |
| 725 | // disappear from the call list in the next poll |
| 726 | if (prevIncomingOrWaitingLine >= 0 |
| 727 | && s_incomingOrWaitingLine < 0 |
| 728 | && s_expectAnswer == 0 |
| 729 | ) { |
| 730 | for (i = 0; i < countValidCalls ; i++) { |
| 731 | |
| 732 | if (p_calls[i].index == prevIncomingOrWaitingLine |
| 733 | && p_calls[i].state == RIL_CALL_ACTIVE |
| 734 | && s_repollCallsCount < REPOLL_CALLS_COUNT_MAX |
| 735 | ) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 736 | RLOGI( |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 737 | "Hit WORKAROUND_ERRONOUS_ANSWER case." |
| 738 | " Repoll count: %d\n", s_repollCallsCount); |
| 739 | s_repollCallsCount++; |
| 740 | goto error; |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | s_expectAnswer = 0; |
| 746 | s_repollCallsCount = 0; |
| 747 | #endif /*WORKAROUND_ERRONEOUS_ANSWER*/ |
| 748 | |
Wink Saville | 3d54e74 | 2009-05-18 18:00:44 -0700 | [diff] [blame] | 749 | RIL_onRequestComplete(t, RIL_E_SUCCESS, pp_calls, |
| 750 | countValidCalls * sizeof (RIL_Call *)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 751 | |
| 752 | at_response_free(p_response); |
| 753 | |
| 754 | #ifdef POLL_CALL_STATE |
| 755 | if (countValidCalls) { // We don't seem to get a "NO CARRIER" message from |
| 756 | // smd, so we're forced to poll until the call ends. |
| 757 | #else |
| 758 | if (needRepoll) { |
| 759 | #endif |
| 760 | RIL_requestTimedCallback (sendCallStateChanged, NULL, &TIMEVAL_CALLSTATEPOLL); |
| 761 | } |
| 762 | |
| 763 | return; |
| 764 | error: |
| 765 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 766 | at_response_free(p_response); |
| 767 | } |
| 768 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 769 | static void requestDial(void *data, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 770 | { |
| 771 | RIL_Dial *p_dial; |
| 772 | char *cmd; |
| 773 | const char *clir; |
| 774 | int ret; |
| 775 | |
| 776 | p_dial = (RIL_Dial *)data; |
| 777 | |
| 778 | switch (p_dial->clir) { |
| 779 | case 1: clir = "I"; break; /*invocation*/ |
| 780 | case 2: clir = "i"; break; /*suppression*/ |
| 781 | default: |
| 782 | case 0: clir = ""; break; /*subscription default*/ |
| 783 | } |
| 784 | |
| 785 | asprintf(&cmd, "ATD%s%s;", p_dial->address, clir); |
| 786 | |
| 787 | ret = at_send_command(cmd, NULL); |
| 788 | |
| 789 | free(cmd); |
| 790 | |
| 791 | /* success or failure is ignored by the upper layer here. |
| 792 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 793 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 794 | } |
| 795 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 796 | static void requestWriteSmsToSim(void *data, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 797 | { |
| 798 | RIL_SMS_WriteArgs *p_args; |
| 799 | char *cmd; |
| 800 | int length; |
| 801 | int err; |
| 802 | ATResponse *p_response = NULL; |
| 803 | |
| 804 | p_args = (RIL_SMS_WriteArgs *)data; |
| 805 | |
| 806 | length = strlen(p_args->pdu)/2; |
| 807 | asprintf(&cmd, "AT+CMGW=%d,%d", length, p_args->status); |
| 808 | |
| 809 | err = at_send_command_sms(cmd, p_args->pdu, "+CMGW:", &p_response); |
| 810 | |
| 811 | if (err != 0 || p_response->success == 0) goto error; |
| 812 | |
| 813 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 814 | at_response_free(p_response); |
| 815 | |
| 816 | return; |
| 817 | error: |
| 818 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 819 | at_response_free(p_response); |
| 820 | } |
| 821 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 822 | static void requestHangup(void *data, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 823 | { |
| 824 | int *p_line; |
| 825 | |
| 826 | int ret; |
| 827 | char *cmd; |
| 828 | |
| 829 | p_line = (int *)data; |
| 830 | |
| 831 | // 3GPP 22.030 6.5.5 |
| 832 | // "Releases a specific active call X" |
| 833 | asprintf(&cmd, "AT+CHLD=1%d", p_line[0]); |
| 834 | |
| 835 | ret = at_send_command(cmd, NULL); |
| 836 | |
| 837 | free(cmd); |
| 838 | |
| 839 | /* success or failure is ignored by the upper layer here. |
| 840 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 841 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 842 | } |
| 843 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 844 | static void requestSignalStrength(void *data __unused, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 845 | { |
| 846 | ATResponse *p_response = NULL; |
| 847 | int err; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 848 | char *line; |
Uma Maheswari Ramalingam | 9efcac5 | 2012-08-09 11:59:17 -0700 | [diff] [blame] | 849 | int count =0; |
| 850 | int numofElements=sizeof(RIL_SignalStrength_v6)/sizeof(int); |
| 851 | int response[numofElements]; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 852 | |
| 853 | err = at_send_command_singleline("AT+CSQ", "+CSQ:", &p_response); |
| 854 | |
| 855 | if (err < 0 || p_response->success == 0) { |
| 856 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 857 | goto error; |
| 858 | } |
| 859 | |
| 860 | line = p_response->p_intermediates->line; |
| 861 | |
| 862 | err = at_tok_start(&line); |
| 863 | if (err < 0) goto error; |
| 864 | |
Uma Maheswari Ramalingam | 9efcac5 | 2012-08-09 11:59:17 -0700 | [diff] [blame] | 865 | for (count =0; count < numofElements; count ++) { |
| 866 | err = at_tok_nextint(&line, &(response[count])); |
| 867 | if (err < 0) goto error; |
| 868 | } |
Chih-Wei Huang | 2805905 | 2012-04-30 01:13:27 +0800 | [diff] [blame] | 869 | |
Uma Maheswari Ramalingam | 9efcac5 | 2012-08-09 11:59:17 -0700 | [diff] [blame] | 870 | RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 871 | |
| 872 | at_response_free(p_response); |
| 873 | return; |
| 874 | |
| 875 | error: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 876 | RLOGE("requestSignalStrength must never return an error when radio is on"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 877 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 878 | at_response_free(p_response); |
| 879 | } |
| 880 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 881 | /** |
| 882 | * networkModePossible. Decides whether the network mode is appropriate for the |
| 883 | * specified modem |
| 884 | */ |
| 885 | static int networkModePossible(ModemInfo *mdm, int nm) |
| 886 | { |
| 887 | if ((net2modem[nm] & mdm->supportedTechs) == net2modem[nm]) { |
| 888 | return 1; |
| 889 | } |
| 890 | return 0; |
| 891 | } |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 892 | static void requestSetPreferredNetworkType( int request __unused, void *data, |
| 893 | size_t datalen __unused, RIL_Token t ) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 894 | { |
| 895 | ATResponse *p_response = NULL; |
| 896 | char *cmd = NULL; |
| 897 | int value = *(int *)data; |
| 898 | int current, old; |
| 899 | int err; |
| 900 | int32_t preferred = net2pmask[value]; |
| 901 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 902 | RLOGD("requestSetPreferredNetworkType: current: %x. New: %x", PREFERRED_NETWORK(sMdmInfo), preferred); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 903 | if (!networkModePossible(sMdmInfo, value)) { |
| 904 | RIL_onRequestComplete(t, RIL_E_MODE_NOT_SUPPORTED, NULL, 0); |
| 905 | return; |
| 906 | } |
| 907 | if (query_ctec(sMdmInfo, ¤t, NULL) < 0) { |
| 908 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 909 | return; |
| 910 | } |
| 911 | old = PREFERRED_NETWORK(sMdmInfo); |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 912 | RLOGD("old != preferred: %d", old != preferred); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 913 | if (old != preferred) { |
| 914 | asprintf(&cmd, "AT+CTEC=%d,\"%x\"", current, preferred); |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 915 | RLOGD("Sending command: <%s>", cmd); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 916 | err = at_send_command_singleline(cmd, "+CTEC:", &p_response); |
| 917 | free(cmd); |
| 918 | if (err || !p_response->success) { |
| 919 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 920 | return; |
| 921 | } |
| 922 | PREFERRED_NETWORK(sMdmInfo) = value; |
| 923 | if (!strstr( p_response->p_intermediates->line, "DONE") ) { |
| 924 | int current; |
| 925 | int res = parse_technology_response(p_response->p_intermediates->line, ¤t, NULL); |
| 926 | switch (res) { |
| 927 | case -1: // Error or unable to parse |
| 928 | break; |
| 929 | case 1: // Only able to parse current |
| 930 | case 0: // Both current and preferred were parsed |
| 931 | setRadioTechnology(sMdmInfo, current); |
| 932 | break; |
| 933 | } |
| 934 | } |
| 935 | } |
| 936 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 937 | } |
| 938 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 939 | static void requestGetPreferredNetworkType(int request __unused, void *data __unused, |
| 940 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 941 | { |
| 942 | int preferred; |
| 943 | unsigned i; |
| 944 | |
| 945 | switch ( query_ctec(sMdmInfo, NULL, &preferred) ) { |
| 946 | case -1: // Error or unable to parse |
| 947 | case 1: // Only able to parse current |
| 948 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 949 | break; |
| 950 | case 0: // Both current and preferred were parsed |
| 951 | for ( i = 0 ; i < sizeof(net2pmask) / sizeof(int32_t) ; i++ ) { |
| 952 | if (preferred == net2pmask[i]) { |
| 953 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &i, sizeof(int)); |
| 954 | return; |
| 955 | } |
| 956 | } |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 957 | RLOGE("Unknown preferred mode received from modem: %d", preferred); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 958 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 959 | break; |
| 960 | } |
| 961 | |
| 962 | } |
| 963 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 964 | static void requestCdmaPrlVersion(int request __unused, void *data __unused, |
| 965 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 966 | { |
| 967 | int err; |
| 968 | char * responseStr; |
| 969 | ATResponse *p_response = NULL; |
| 970 | const char *cmd; |
| 971 | char *line; |
| 972 | |
| 973 | err = at_send_command_singleline("AT+WPRL?", "+WPRL:", &p_response); |
| 974 | if (err < 0 || !p_response->success) goto error; |
| 975 | line = p_response->p_intermediates->line; |
| 976 | err = at_tok_start(&line); |
| 977 | if (err < 0) goto error; |
| 978 | err = at_tok_nextstr(&line, &responseStr); |
| 979 | if (err < 0 || !responseStr) goto error; |
| 980 | RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, strlen(responseStr)); |
| 981 | at_response_free(p_response); |
| 982 | return; |
| 983 | error: |
| 984 | at_response_free(p_response); |
| 985 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 986 | } |
| 987 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 988 | static void requestCdmaBaseBandVersion(int request __unused, void *data __unused, |
| 989 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 990 | { |
| 991 | int err; |
| 992 | char * responseStr; |
| 993 | ATResponse *p_response = NULL; |
| 994 | const char *cmd; |
| 995 | const char *prefix; |
| 996 | char *line, *p; |
| 997 | int commas; |
| 998 | int skip; |
| 999 | int count = 4; |
| 1000 | |
| 1001 | // Fixed values. TODO: query modem |
| 1002 | responseStr = strdup("1.0.0.0"); |
| 1003 | RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, sizeof(responseStr)); |
| 1004 | free(responseStr); |
| 1005 | } |
| 1006 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1007 | static void requestCdmaDeviceIdentity(int request __unused, void *data __unused, |
| 1008 | size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1009 | { |
| 1010 | int err; |
| 1011 | int response[4]; |
| 1012 | char * responseStr[4]; |
| 1013 | ATResponse *p_response = NULL; |
| 1014 | const char *cmd; |
| 1015 | const char *prefix; |
| 1016 | char *line, *p; |
| 1017 | int commas; |
| 1018 | int skip; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1019 | int count = 4; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1020 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1021 | // Fixed values. TODO: Query modem |
| 1022 | responseStr[0] = "----"; |
| 1023 | responseStr[1] = "----"; |
| 1024 | responseStr[2] = "77777777"; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1025 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1026 | err = at_send_command_numeric("AT+CGSN", &p_response); |
| 1027 | if (err < 0 || p_response->success == 0) { |
| 1028 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1029 | return; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1030 | } else { |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1031 | responseStr[3] = p_response->p_intermediates->line; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1032 | } |
| 1033 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1034 | RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, count*sizeof(char*)); |
| 1035 | at_response_free(p_response); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1036 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1037 | return; |
| 1038 | error: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1039 | RLOGE("requestCdmaDeviceIdentity must never return an error when radio is on"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1040 | at_response_free(p_response); |
| 1041 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1042 | } |
| 1043 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1044 | static void requestCdmaGetSubscriptionSource(int request __unused, void *data, |
| 1045 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1046 | { |
| 1047 | int err; |
| 1048 | int *ss = (int *)data; |
| 1049 | ATResponse *p_response = NULL; |
| 1050 | char *cmd = NULL; |
| 1051 | char *line = NULL; |
| 1052 | int response; |
| 1053 | |
| 1054 | asprintf(&cmd, "AT+CCSS?"); |
| 1055 | if (!cmd) goto error; |
| 1056 | |
| 1057 | err = at_send_command_singleline(cmd, "+CCSS:", &p_response); |
| 1058 | if (err < 0 || !p_response->success) |
| 1059 | goto error; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1060 | |
| 1061 | line = p_response->p_intermediates->line; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1062 | err = at_tok_start(&line); |
| 1063 | if (err < 0) goto error; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1064 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1065 | err = at_tok_nextint(&line, &response); |
| 1066 | free(cmd); |
| 1067 | cmd = NULL; |
| 1068 | |
| 1069 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(response)); |
| 1070 | |
| 1071 | return; |
| 1072 | error: |
| 1073 | free(cmd); |
| 1074 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1075 | } |
| 1076 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1077 | static void requestCdmaSetSubscriptionSource(int request __unused, void *data, |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1078 | size_t datalen, RIL_Token t) |
| 1079 | { |
| 1080 | int err; |
| 1081 | int *ss = (int *)data; |
| 1082 | ATResponse *p_response = NULL; |
| 1083 | char *cmd = NULL; |
| 1084 | |
| 1085 | if (!ss || !datalen) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1086 | RLOGE("RIL_REQUEST_CDMA_SET_SUBSCRIPTION without data!"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1087 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1088 | return; |
| 1089 | } |
| 1090 | asprintf(&cmd, "AT+CCSS=%d", ss[0]); |
| 1091 | if (!cmd) goto error; |
| 1092 | |
| 1093 | err = at_send_command(cmd, &p_response); |
| 1094 | if (err < 0 || !p_response->success) |
| 1095 | goto error; |
| 1096 | free(cmd); |
| 1097 | cmd = NULL; |
| 1098 | |
| 1099 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 1100 | |
| 1101 | RIL_onUnsolicitedResponse(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED, ss, sizeof(ss[0])); |
| 1102 | |
| 1103 | return; |
| 1104 | error: |
| 1105 | free(cmd); |
| 1106 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1107 | } |
| 1108 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1109 | static void requestCdmaSubscription(int request __unused, void *data __unused, |
| 1110 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1111 | { |
| 1112 | int err; |
| 1113 | int response[5]; |
| 1114 | char * responseStr[5]; |
| 1115 | ATResponse *p_response = NULL; |
| 1116 | const char *cmd; |
| 1117 | const char *prefix; |
| 1118 | char *line, *p; |
| 1119 | int commas; |
| 1120 | int skip; |
| 1121 | int count = 5; |
| 1122 | |
| 1123 | // Fixed values. TODO: Query modem |
| 1124 | responseStr[0] = "8587777777"; // MDN |
| 1125 | responseStr[1] = "1"; // SID |
| 1126 | responseStr[2] = "1"; // NID |
| 1127 | responseStr[3] = "8587777777"; // MIN |
| 1128 | responseStr[4] = "1"; // PRL Version |
| 1129 | RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, count*sizeof(char*)); |
| 1130 | |
| 1131 | return; |
| 1132 | error: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1133 | RLOGE("requestRegistrationState must never return an error when radio is on"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1134 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1135 | } |
| 1136 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1137 | static void requestCdmaGetRoamingPreference(int request __unused, void *data __unused, |
| 1138 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1139 | { |
| 1140 | int roaming_pref = -1; |
| 1141 | ATResponse *p_response = NULL; |
| 1142 | char *line; |
| 1143 | int res; |
| 1144 | |
| 1145 | res = at_send_command_singleline("AT+WRMP?", "+WRMP:", &p_response); |
| 1146 | if (res < 0 || !p_response->success) { |
| 1147 | goto error; |
| 1148 | } |
| 1149 | line = p_response->p_intermediates->line; |
| 1150 | |
| 1151 | res = at_tok_start(&line); |
| 1152 | if (res < 0) goto error; |
| 1153 | |
| 1154 | res = at_tok_nextint(&line, &roaming_pref); |
| 1155 | if (res < 0) goto error; |
| 1156 | |
| 1157 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &roaming_pref, sizeof(roaming_pref)); |
| 1158 | return; |
| 1159 | error: |
| 1160 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1161 | } |
| 1162 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1163 | static void requestCdmaSetRoamingPreference(int request __unused, void *data, |
| 1164 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1165 | { |
| 1166 | int *pref = (int *)data; |
| 1167 | ATResponse *p_response = NULL; |
| 1168 | char *line; |
| 1169 | int res; |
| 1170 | char *cmd = NULL; |
| 1171 | |
| 1172 | asprintf(&cmd, "AT+WRMP=%d", *pref); |
| 1173 | if (cmd == NULL) goto error; |
| 1174 | |
| 1175 | res = at_send_command(cmd, &p_response); |
| 1176 | if (res < 0 || !p_response->success) |
| 1177 | goto error; |
| 1178 | |
| 1179 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 1180 | free(cmd); |
| 1181 | return; |
| 1182 | error: |
| 1183 | free(cmd); |
| 1184 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1185 | } |
| 1186 | |
| 1187 | static int parseRegistrationState(char *str, int *type, int *items, int **response) |
| 1188 | { |
| 1189 | int err; |
| 1190 | char *line = str, *p; |
| 1191 | int *resp = NULL; |
| 1192 | int skip; |
| 1193 | int count = 3; |
| 1194 | int commas; |
| 1195 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1196 | RLOGD("parseRegistrationState. Parsing: %s",str); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1197 | err = at_tok_start(&line); |
| 1198 | if (err < 0) goto error; |
| 1199 | |
| 1200 | /* Ok you have to be careful here |
| 1201 | * The solicited version of the CREG response is |
| 1202 | * +CREG: n, stat, [lac, cid] |
| 1203 | * and the unsolicited version is |
| 1204 | * +CREG: stat, [lac, cid] |
| 1205 | * The <n> parameter is basically "is unsolicited creg on?" |
| 1206 | * which it should always be |
| 1207 | * |
| 1208 | * Now we should normally get the solicited version here, |
| 1209 | * but the unsolicited version could have snuck in |
| 1210 | * so we have to handle both |
| 1211 | * |
| 1212 | * Also since the LAC and CID are only reported when registered, |
| 1213 | * we can have 1, 2, 3, or 4 arguments here |
| 1214 | * |
| 1215 | * finally, a +CGREG: answer may have a fifth value that corresponds |
| 1216 | * to the network type, as in; |
| 1217 | * |
| 1218 | * +CGREG: n, stat [,lac, cid [,networkType]] |
| 1219 | */ |
| 1220 | |
| 1221 | /* count number of commas */ |
| 1222 | commas = 0; |
| 1223 | for (p = line ; *p != '\0' ;p++) { |
| 1224 | if (*p == ',') commas++; |
| 1225 | } |
| 1226 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1227 | resp = (int *)calloc(commas + 1, sizeof(int)); |
| 1228 | if (!resp) goto error; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1229 | switch (commas) { |
| 1230 | case 0: /* +CREG: <stat> */ |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1231 | err = at_tok_nextint(&line, &resp[0]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1232 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1233 | resp[1] = -1; |
| 1234 | resp[2] = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1235 | break; |
| 1236 | |
| 1237 | case 1: /* +CREG: <n>, <stat> */ |
| 1238 | err = at_tok_nextint(&line, &skip); |
| 1239 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1240 | err = at_tok_nextint(&line, &resp[0]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1241 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1242 | resp[1] = -1; |
| 1243 | resp[2] = -1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1244 | if (err < 0) goto error; |
| 1245 | break; |
| 1246 | |
| 1247 | case 2: /* +CREG: <stat>, <lac>, <cid> */ |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1248 | err = at_tok_nextint(&line, &resp[0]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1249 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1250 | err = at_tok_nexthexint(&line, &resp[1]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1251 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1252 | err = at_tok_nexthexint(&line, &resp[2]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1253 | if (err < 0) goto error; |
| 1254 | break; |
| 1255 | case 3: /* +CREG: <n>, <stat>, <lac>, <cid> */ |
| 1256 | err = at_tok_nextint(&line, &skip); |
| 1257 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1258 | err = at_tok_nextint(&line, &resp[0]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1259 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1260 | err = at_tok_nexthexint(&line, &resp[1]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1261 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1262 | err = at_tok_nexthexint(&line, &resp[2]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1263 | if (err < 0) goto error; |
| 1264 | break; |
| 1265 | /* special case for CGREG, there is a fourth parameter |
| 1266 | * that is the network type (unknown/gprs/edge/umts) |
| 1267 | */ |
| 1268 | case 4: /* +CGREG: <n>, <stat>, <lac>, <cid>, <networkType> */ |
| 1269 | err = at_tok_nextint(&line, &skip); |
| 1270 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1271 | err = at_tok_nextint(&line, &resp[0]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1272 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1273 | err = at_tok_nexthexint(&line, &resp[1]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1274 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1275 | err = at_tok_nexthexint(&line, &resp[2]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1276 | if (err < 0) goto error; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1277 | err = at_tok_nexthexint(&line, &resp[3]); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1278 | if (err < 0) goto error; |
| 1279 | count = 4; |
| 1280 | break; |
| 1281 | default: |
| 1282 | goto error; |
| 1283 | } |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 1284 | s_lac = resp[1]; |
| 1285 | s_cid = resp[2]; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1286 | if (response) |
| 1287 | *response = resp; |
| 1288 | if (items) |
| 1289 | *items = commas + 1; |
| 1290 | if (type) |
| 1291 | *type = techFromModemType(TECH(sMdmInfo)); |
| 1292 | return 0; |
| 1293 | error: |
| 1294 | free(resp); |
| 1295 | return -1; |
| 1296 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1297 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1298 | #define REG_STATE_LEN 15 |
| 1299 | #define REG_DATA_STATE_LEN 6 |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1300 | static void requestRegistrationState(int request, void *data __unused, |
| 1301 | size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1302 | { |
| 1303 | int err; |
| 1304 | int *registration; |
| 1305 | char **responseStr = NULL; |
| 1306 | ATResponse *p_response = NULL; |
| 1307 | const char *cmd; |
| 1308 | const char *prefix; |
| 1309 | char *line; |
| 1310 | int i = 0, j, numElements = 0; |
| 1311 | int count = 3; |
| 1312 | int type, startfrom; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1313 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1314 | RLOGD("requestRegistrationState"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1315 | if (request == RIL_REQUEST_VOICE_REGISTRATION_STATE) { |
| 1316 | cmd = "AT+CREG?"; |
| 1317 | prefix = "+CREG:"; |
| 1318 | numElements = REG_STATE_LEN; |
| 1319 | } else if (request == RIL_REQUEST_DATA_REGISTRATION_STATE) { |
| 1320 | cmd = "AT+CGREG?"; |
| 1321 | prefix = "+CGREG:"; |
| 1322 | numElements = REG_DATA_STATE_LEN; |
| 1323 | } else { |
| 1324 | assert(0); |
| 1325 | goto error; |
| 1326 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1327 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1328 | err = at_send_command_singleline(cmd, prefix, &p_response); |
| 1329 | |
| 1330 | if (err != 0) goto error; |
| 1331 | |
| 1332 | line = p_response->p_intermediates->line; |
| 1333 | |
| 1334 | if (parseRegistrationState(line, &type, &count, ®istration)) goto error; |
| 1335 | |
| 1336 | responseStr = malloc(numElements * sizeof(char *)); |
| 1337 | if (!responseStr) goto error; |
| 1338 | memset(responseStr, 0, numElements * sizeof(char *)); |
| 1339 | /** |
| 1340 | * The first '4' bytes for both registration states remain the same. |
| 1341 | * But if the request is 'DATA_REGISTRATION_STATE', |
| 1342 | * the 5th and 6th byte(s) are optional. |
| 1343 | */ |
| 1344 | if (is3gpp2(type) == 1) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1345 | RLOGD("registration state type: 3GPP2"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1346 | // TODO: Query modem |
| 1347 | startfrom = 3; |
| 1348 | if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) { |
| 1349 | asprintf(&responseStr[3], "8"); // EvDo revA |
| 1350 | asprintf(&responseStr[4], "1"); // BSID |
| 1351 | asprintf(&responseStr[5], "123"); // Latitude |
| 1352 | asprintf(&responseStr[6], "222"); // Longitude |
| 1353 | asprintf(&responseStr[7], "0"); // CSS Indicator |
| 1354 | asprintf(&responseStr[8], "4"); // SID |
| 1355 | asprintf(&responseStr[9], "65535"); // NID |
| 1356 | asprintf(&responseStr[10], "0"); // Roaming indicator |
| 1357 | asprintf(&responseStr[11], "1"); // System is in PRL |
| 1358 | asprintf(&responseStr[12], "0"); // Default Roaming indicator |
| 1359 | asprintf(&responseStr[13], "0"); // Reason for denial |
| 1360 | asprintf(&responseStr[14], "0"); // Primary Scrambling Code of Current cell |
| 1361 | } else if (request == RIL_REQUEST_DATA_REGISTRATION_STATE) { |
| 1362 | asprintf(&responseStr[3], "8"); // Available data radio technology |
| 1363 | } |
| 1364 | } else { // type == RADIO_TECH_3GPP |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1365 | RLOGD("registration state type: 3GPP"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1366 | startfrom = 0; |
| 1367 | asprintf(&responseStr[1], "%x", registration[1]); |
| 1368 | asprintf(&responseStr[2], "%x", registration[2]); |
| 1369 | if (count > 3) |
| 1370 | asprintf(&responseStr[3], "%d", registration[3]); |
| 1371 | } |
| 1372 | asprintf(&responseStr[0], "%d", registration[0]); |
| 1373 | |
| 1374 | /** |
| 1375 | * Optional bytes for DATA_REGISTRATION_STATE request |
| 1376 | * 4th byte : Registration denial code |
| 1377 | * 5th byte : The max. number of simultaneous Data Calls |
| 1378 | */ |
| 1379 | if(request == RIL_REQUEST_DATA_REGISTRATION_STATE) { |
| 1380 | // asprintf(&responseStr[4], "3"); |
| 1381 | // asprintf(&responseStr[5], "1"); |
| 1382 | } |
| 1383 | |
| 1384 | for (j = startfrom; j < numElements; j++) { |
| 1385 | if (!responseStr[i]) goto error; |
| 1386 | } |
| 1387 | free(registration); |
| 1388 | registration = NULL; |
| 1389 | |
| 1390 | RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, numElements*sizeof(responseStr)); |
| 1391 | for (j = 0; j < numElements; j++ ) { |
| 1392 | free(responseStr[j]); |
| 1393 | responseStr[j] = NULL; |
| 1394 | } |
| 1395 | free(responseStr); |
| 1396 | responseStr = NULL; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1397 | at_response_free(p_response); |
| 1398 | |
| 1399 | return; |
| 1400 | error: |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1401 | if (responseStr) { |
| 1402 | for (j = 0; j < numElements; j++) { |
| 1403 | free(responseStr[j]); |
| 1404 | responseStr[j] = NULL; |
| 1405 | } |
| 1406 | free(responseStr); |
| 1407 | responseStr = NULL; |
| 1408 | } |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1409 | RLOGE("requestRegistrationState must never return an error when radio is on"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1410 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1411 | at_response_free(p_response); |
| 1412 | } |
| 1413 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1414 | static void requestOperator(void *data __unused, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1415 | { |
| 1416 | int err; |
| 1417 | int i; |
| 1418 | int skip; |
| 1419 | ATLine *p_cur; |
| 1420 | char *response[3]; |
| 1421 | |
| 1422 | memset(response, 0, sizeof(response)); |
| 1423 | |
| 1424 | ATResponse *p_response = NULL; |
| 1425 | |
| 1426 | err = at_send_command_multiline( |
| 1427 | "AT+COPS=3,0;+COPS?;+COPS=3,1;+COPS?;+COPS=3,2;+COPS?", |
| 1428 | "+COPS:", &p_response); |
| 1429 | |
| 1430 | /* we expect 3 lines here: |
| 1431 | * +COPS: 0,0,"T - Mobile" |
| 1432 | * +COPS: 0,1,"TMO" |
| 1433 | * +COPS: 0,2,"310170" |
| 1434 | */ |
| 1435 | |
| 1436 | if (err != 0) goto error; |
| 1437 | |
| 1438 | for (i = 0, p_cur = p_response->p_intermediates |
| 1439 | ; p_cur != NULL |
| 1440 | ; p_cur = p_cur->p_next, i++ |
| 1441 | ) { |
| 1442 | char *line = p_cur->line; |
| 1443 | |
| 1444 | err = at_tok_start(&line); |
| 1445 | if (err < 0) goto error; |
| 1446 | |
| 1447 | err = at_tok_nextint(&line, &skip); |
| 1448 | if (err < 0) goto error; |
| 1449 | |
| 1450 | // If we're unregistered, we may just get |
| 1451 | // a "+COPS: 0" response |
| 1452 | if (!at_tok_hasmore(&line)) { |
| 1453 | response[i] = NULL; |
| 1454 | continue; |
| 1455 | } |
| 1456 | |
| 1457 | err = at_tok_nextint(&line, &skip); |
| 1458 | if (err < 0) goto error; |
| 1459 | |
| 1460 | // a "+COPS: 0, n" response is also possible |
| 1461 | if (!at_tok_hasmore(&line)) { |
| 1462 | response[i] = NULL; |
| 1463 | continue; |
| 1464 | } |
| 1465 | |
| 1466 | err = at_tok_nextstr(&line, &(response[i])); |
| 1467 | if (err < 0) goto error; |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 1468 | // Simple assumption that mcc and mnc are 3 digits each |
| 1469 | if (strlen(response[i]) == 6) { |
| 1470 | if (sscanf(response[i], "%3d%3d", &s_mcc, &s_mnc) != 2) { |
| 1471 | RLOGE("requestOperator expected mccmnc to be 6 decimal digits"); |
| 1472 | } |
| 1473 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | if (i != 3) { |
| 1477 | /* expect 3 lines exactly */ |
| 1478 | goto error; |
| 1479 | } |
| 1480 | |
| 1481 | RIL_onRequestComplete(t, RIL_E_SUCCESS, response, sizeof(response)); |
| 1482 | at_response_free(p_response); |
| 1483 | |
| 1484 | return; |
| 1485 | error: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1486 | RLOGE("requestOperator must not return error when radio is on"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1487 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1488 | at_response_free(p_response); |
| 1489 | } |
| 1490 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1491 | static void requestCdmaSendSMS(void *data, size_t datalen, RIL_Token t) |
| 1492 | { |
| 1493 | int err = 1; // Set to go to error: |
| 1494 | RIL_SMS_Response response; |
| 1495 | RIL_CDMA_SMS_Message* rcsm; |
| 1496 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1497 | RLOGD("requestCdmaSendSMS datalen=%zu, sizeof(RIL_CDMA_SMS_Message)=%zu", |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1498 | datalen, sizeof(RIL_CDMA_SMS_Message)); |
| 1499 | |
| 1500 | // verify data content to test marshalling/unmarshalling: |
| 1501 | rcsm = (RIL_CDMA_SMS_Message*)data; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1502 | RLOGD("TeleserviceID=%d, bIsServicePresent=%d, \ |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1503 | uServicecategory=%d, sAddress.digit_mode=%d, \ |
| 1504 | sAddress.Number_mode=%d, sAddress.number_type=%d, ", |
| 1505 | rcsm->uTeleserviceID, rcsm->bIsServicePresent, |
| 1506 | rcsm->uServicecategory,rcsm->sAddress.digit_mode, |
| 1507 | rcsm->sAddress.number_mode,rcsm->sAddress.number_type); |
| 1508 | |
| 1509 | if (err != 0) goto error; |
| 1510 | |
| 1511 | // Cdma Send SMS implementation will go here: |
| 1512 | // But it is not implemented yet. |
| 1513 | |
| 1514 | memset(&response, 0, sizeof(response)); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1515 | response.messageRef = 1; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1516 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(response)); |
| 1517 | return; |
| 1518 | |
| 1519 | error: |
| 1520 | // Cdma Send SMS will always cause send retry error. |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1521 | response.messageRef = -1; |
| 1522 | RIL_onRequestComplete(t, RIL_E_SMS_SEND_FAIL_RETRY, &response, sizeof(response)); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1523 | } |
| 1524 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1525 | static void requestSendSMS(void *data, size_t datalen, RIL_Token t) |
| 1526 | { |
| 1527 | int err; |
| 1528 | const char *smsc; |
| 1529 | const char *pdu; |
| 1530 | int tpLayerLength; |
| 1531 | char *cmd1, *cmd2; |
| 1532 | RIL_SMS_Response response; |
| 1533 | ATResponse *p_response = NULL; |
| 1534 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1535 | memset(&response, 0, sizeof(response)); |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1536 | RLOGD("requestSendSMS datalen =%zu", datalen); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1537 | |
| 1538 | if (s_ims_gsm_fail != 0) goto error; |
| 1539 | if (s_ims_gsm_retry != 0) goto error2; |
| 1540 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1541 | smsc = ((const char **)data)[0]; |
| 1542 | pdu = ((const char **)data)[1]; |
| 1543 | |
| 1544 | tpLayerLength = strlen(pdu)/2; |
| 1545 | |
| 1546 | // "NULL for default SMSC" |
| 1547 | if (smsc == NULL) { |
| 1548 | smsc= "00"; |
| 1549 | } |
| 1550 | |
| 1551 | asprintf(&cmd1, "AT+CMGS=%d", tpLayerLength); |
| 1552 | asprintf(&cmd2, "%s%s", smsc, pdu); |
| 1553 | |
| 1554 | err = at_send_command_sms(cmd1, cmd2, "+CMGS:", &p_response); |
| 1555 | |
| 1556 | if (err != 0 || p_response->success == 0) goto error; |
| 1557 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1558 | /* FIXME fill in messageRef and ackPDU */ |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1559 | response.messageRef = 1; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1560 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &response, sizeof(response)); |
| 1561 | at_response_free(p_response); |
| 1562 | |
| 1563 | return; |
| 1564 | error: |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1565 | response.messageRef = -2; |
| 1566 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, &response, sizeof(response)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1567 | at_response_free(p_response); |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1568 | return; |
| 1569 | error2: |
| 1570 | // send retry error. |
| 1571 | response.messageRef = -1; |
| 1572 | RIL_onRequestComplete(t, RIL_E_SMS_SEND_FAIL_RETRY, &response, sizeof(response)); |
| 1573 | at_response_free(p_response); |
| 1574 | return; |
| 1575 | } |
| 1576 | |
| 1577 | static void requestImsSendSMS(void *data, size_t datalen, RIL_Token t) |
| 1578 | { |
| 1579 | RIL_IMS_SMS_Message *p_args; |
| 1580 | RIL_SMS_Response response; |
| 1581 | |
| 1582 | memset(&response, 0, sizeof(response)); |
| 1583 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1584 | RLOGD("requestImsSendSMS: datalen=%zu, " |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 1585 | "registered=%d, service=%d, format=%d, ims_perm_fail=%d, " |
| 1586 | "ims_retry=%d, gsm_fail=%d, gsm_retry=%d", |
| 1587 | datalen, s_ims_registered, s_ims_services, s_ims_format, |
| 1588 | s_ims_cause_perm_failure, s_ims_cause_retry, s_ims_gsm_fail, |
| 1589 | s_ims_gsm_retry); |
| 1590 | |
| 1591 | // figure out if this is gsm/cdma format |
| 1592 | // then route it to requestSendSMS vs requestCdmaSendSMS respectively |
| 1593 | p_args = (RIL_IMS_SMS_Message *)data; |
| 1594 | |
| 1595 | if (0 != s_ims_cause_perm_failure ) goto error; |
| 1596 | |
| 1597 | // want to fail over ims and this is first request over ims |
| 1598 | if (0 != s_ims_cause_retry && 0 == p_args->retry) goto error2; |
| 1599 | |
| 1600 | if (RADIO_TECH_3GPP == p_args->tech) { |
| 1601 | return requestSendSMS(p_args->message.gsmMessage, |
| 1602 | datalen - sizeof(RIL_RadioTechnologyFamily), |
| 1603 | t); |
| 1604 | } else if (RADIO_TECH_3GPP2 == p_args->tech) { |
| 1605 | return requestCdmaSendSMS(p_args->message.cdmaMessage, |
| 1606 | datalen - sizeof(RIL_RadioTechnologyFamily), |
| 1607 | t); |
| 1608 | } else { |
| 1609 | RLOGE("requestImsSendSMS invalid format value =%d", p_args->tech); |
| 1610 | } |
| 1611 | |
| 1612 | error: |
| 1613 | response.messageRef = -2; |
| 1614 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, &response, sizeof(response)); |
| 1615 | return; |
| 1616 | |
| 1617 | error2: |
| 1618 | response.messageRef = -1; |
| 1619 | RIL_onRequestComplete(t, RIL_E_SMS_SEND_FAIL_RETRY, &response, sizeof(response)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1620 | } |
| 1621 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1622 | static void requestSetupDataCall(void *data, size_t datalen, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1623 | { |
| 1624 | const char *apn; |
| 1625 | char *cmd; |
| 1626 | int err; |
| 1627 | ATResponse *p_response = NULL; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1628 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 1629 | apn = ((const char **)data)[2]; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1630 | |
| 1631 | #ifdef USE_TI_COMMANDS |
| 1632 | // Config for multislot class 10 (probably default anyway eh?) |
| 1633 | err = at_send_command("AT%CPRIM=\"GMM\",\"CONFIG MULTISLOT_CLASS=<10>\"", |
| 1634 | NULL); |
| 1635 | |
| 1636 | err = at_send_command("AT%DATA=2,\"UART\",1,,\"SER\",\"UART\",0", NULL); |
| 1637 | #endif /* USE_TI_COMMANDS */ |
| 1638 | |
| 1639 | int fd, qmistatus; |
| 1640 | size_t cur = 0; |
| 1641 | size_t len; |
| 1642 | ssize_t written, rlen; |
| 1643 | char status[32] = {0}; |
| 1644 | int retry = 10; |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1645 | const char *pdp_type; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1646 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1647 | RLOGD("requesting data connection to APN '%s'", apn); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1648 | |
| 1649 | fd = open ("/dev/qmi", O_RDWR); |
| 1650 | if (fd >= 0) { /* the device doesn't exist on the emulator */ |
| 1651 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1652 | RLOGD("opened the qmi device\n"); |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1653 | asprintf(&cmd, "up:%s", apn); |
| 1654 | len = strlen(cmd); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1655 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1656 | while (cur < len) { |
| 1657 | do { |
| 1658 | written = write (fd, cmd + cur, len - cur); |
| 1659 | } while (written < 0 && errno == EINTR); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1660 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1661 | if (written < 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1662 | RLOGE("### ERROR writing to /dev/qmi"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1663 | close(fd); |
| 1664 | goto error; |
| 1665 | } |
| 1666 | |
| 1667 | cur += written; |
| 1668 | } |
| 1669 | |
| 1670 | // wait for interface to come online |
| 1671 | |
| 1672 | do { |
| 1673 | sleep(1); |
| 1674 | do { |
| 1675 | rlen = read(fd, status, 31); |
| 1676 | } while (rlen < 0 && errno == EINTR); |
| 1677 | |
| 1678 | if (rlen < 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1679 | RLOGE("### ERROR reading from /dev/qmi"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1680 | close(fd); |
| 1681 | goto error; |
| 1682 | } else { |
| 1683 | status[rlen] = '\0'; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1684 | RLOGD("### status: %s", status); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1685 | } |
| 1686 | } while (strncmp(status, "STATE=up", 8) && strcmp(status, "online") && --retry); |
| 1687 | |
| 1688 | close(fd); |
| 1689 | |
| 1690 | if (retry == 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1691 | RLOGE("### Failed to get data connection up\n"); |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1692 | goto error; |
| 1693 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1694 | |
| 1695 | qmistatus = system("netcfg rmnet0 dhcp"); |
| 1696 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1697 | RLOGD("netcfg rmnet0 dhcp: status %d\n", qmistatus); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1698 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1699 | if (qmistatus < 0) goto error; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1700 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1701 | } else { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1702 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1703 | if (datalen > 6 * sizeof(char *)) { |
| 1704 | pdp_type = ((const char **)data)[6]; |
| 1705 | } else { |
| 1706 | pdp_type = "IP"; |
| 1707 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1708 | |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 1709 | asprintf(&cmd, "AT+CGDCONT=1,\"%s\",\"%s\",,0,0", pdp_type, apn); |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1710 | //FIXME check for error here |
| 1711 | err = at_send_command(cmd, NULL); |
| 1712 | free(cmd); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1713 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1714 | // Set required QoS params to default |
| 1715 | err = at_send_command("AT+CGQREQ=1", NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1716 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1717 | // Set minimum QoS params to default |
| 1718 | err = at_send_command("AT+CGQMIN=1", NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1719 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1720 | // packet-domain event reporting |
| 1721 | err = at_send_command("AT+CGEREP=1,0", NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1722 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1723 | // Hangup anything that's happening there now |
| 1724 | err = at_send_command("AT+CGACT=1,0", NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1725 | |
Lorenzo Colitti | 4f81dcf | 2010-09-01 19:38:57 -0700 | [diff] [blame] | 1726 | // Start data on PDP context 1 |
| 1727 | err = at_send_command("ATD*99***1#", &p_response); |
| 1728 | |
| 1729 | if (err < 0 || p_response->success == 0) { |
| 1730 | goto error; |
| 1731 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1732 | } |
| 1733 | |
Wink Saville | 4380897 | 2011-01-13 17:39:51 -0800 | [diff] [blame] | 1734 | requestOrSendDataCallList(&t); |
| 1735 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1736 | at_response_free(p_response); |
| 1737 | |
| 1738 | return; |
| 1739 | error: |
| 1740 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1741 | at_response_free(p_response); |
| 1742 | |
| 1743 | } |
| 1744 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1745 | static void requestSMSAcknowledge(void *data, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1746 | { |
| 1747 | int ackSuccess; |
| 1748 | int err; |
| 1749 | |
| 1750 | ackSuccess = ((int *)data)[0]; |
| 1751 | |
| 1752 | if (ackSuccess == 1) { |
| 1753 | err = at_send_command("AT+CNMA=1", NULL); |
| 1754 | } else if (ackSuccess == 0) { |
| 1755 | err = at_send_command("AT+CNMA=2", NULL); |
| 1756 | } else { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1757 | RLOGE("unsupported arg to RIL_REQUEST_SMS_ACKNOWLEDGE\n"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1758 | goto error; |
| 1759 | } |
| 1760 | |
| 1761 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 1762 | error: |
| 1763 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1764 | |
| 1765 | } |
| 1766 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1767 | static void requestSIM_IO(void *data, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1768 | { |
| 1769 | ATResponse *p_response = NULL; |
| 1770 | RIL_SIM_IO_Response sr; |
| 1771 | int err; |
| 1772 | char *cmd = NULL; |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 1773 | RIL_SIM_IO_v6 *p_args; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1774 | char *line; |
| 1775 | |
| 1776 | memset(&sr, 0, sizeof(sr)); |
| 1777 | |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 1778 | p_args = (RIL_SIM_IO_v6 *)data; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1779 | |
| 1780 | /* FIXME handle pin2 */ |
| 1781 | |
| 1782 | if (p_args->data == NULL) { |
| 1783 | asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d", |
| 1784 | p_args->command, p_args->fileid, |
| 1785 | p_args->p1, p_args->p2, p_args->p3); |
| 1786 | } else { |
| 1787 | asprintf(&cmd, "AT+CRSM=%d,%d,%d,%d,%d,%s", |
| 1788 | p_args->command, p_args->fileid, |
| 1789 | p_args->p1, p_args->p2, p_args->p3, p_args->data); |
| 1790 | } |
| 1791 | |
| 1792 | err = at_send_command_singleline(cmd, "+CRSM:", &p_response); |
| 1793 | |
| 1794 | if (err < 0 || p_response->success == 0) { |
| 1795 | goto error; |
| 1796 | } |
| 1797 | |
| 1798 | line = p_response->p_intermediates->line; |
| 1799 | |
| 1800 | err = at_tok_start(&line); |
| 1801 | if (err < 0) goto error; |
| 1802 | |
| 1803 | err = at_tok_nextint(&line, &(sr.sw1)); |
| 1804 | if (err < 0) goto error; |
| 1805 | |
| 1806 | err = at_tok_nextint(&line, &(sr.sw2)); |
| 1807 | if (err < 0) goto error; |
| 1808 | |
| 1809 | if (at_tok_hasmore(&line)) { |
| 1810 | err = at_tok_nextstr(&line, &(sr.simResponse)); |
| 1811 | if (err < 0) goto error; |
| 1812 | } |
| 1813 | |
| 1814 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &sr, sizeof(sr)); |
| 1815 | at_response_free(p_response); |
| 1816 | free(cmd); |
| 1817 | |
| 1818 | return; |
| 1819 | error: |
| 1820 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1821 | at_response_free(p_response); |
| 1822 | free(cmd); |
| 1823 | |
| 1824 | } |
| 1825 | |
| 1826 | static void requestEnterSimPin(void* data, size_t datalen, RIL_Token t) |
| 1827 | { |
| 1828 | ATResponse *p_response = NULL; |
| 1829 | int err; |
| 1830 | char* cmd = NULL; |
| 1831 | const char** strings = (const char**)data;; |
| 1832 | |
| 1833 | if ( datalen == sizeof(char*) ) { |
| 1834 | asprintf(&cmd, "AT+CPIN=%s", strings[0]); |
| 1835 | } else if ( datalen == 2*sizeof(char*) ) { |
| 1836 | asprintf(&cmd, "AT+CPIN=%s,%s", strings[0], strings[1]); |
| 1837 | } else |
| 1838 | goto error; |
| 1839 | |
| 1840 | err = at_send_command_singleline(cmd, "+CPIN:", &p_response); |
| 1841 | free(cmd); |
| 1842 | |
| 1843 | if (err < 0 || p_response->success == 0) { |
| 1844 | error: |
| 1845 | RIL_onRequestComplete(t, RIL_E_PASSWORD_INCORRECT, NULL, 0); |
| 1846 | } else { |
| 1847 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 1848 | } |
| 1849 | at_response_free(p_response); |
| 1850 | } |
| 1851 | |
| 1852 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1853 | static void requestSendUSSD(void *data, size_t datalen __unused, RIL_Token t) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1854 | { |
| 1855 | const char *ussdRequest; |
| 1856 | |
| 1857 | ussdRequest = (char *)(data); |
| 1858 | |
| 1859 | |
| 1860 | RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0); |
| 1861 | |
| 1862 | // @@@ TODO |
| 1863 | |
| 1864 | } |
| 1865 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1866 | static void requestExitEmergencyMode(void *data __unused, size_t datalen __unused, RIL_Token t) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 1867 | { |
| 1868 | int err; |
| 1869 | ATResponse *p_response = NULL; |
| 1870 | |
| 1871 | err = at_send_command("AT+WSOS=0", &p_response); |
| 1872 | |
| 1873 | if (err < 0 || p_response->success == 0) { |
| 1874 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 1875 | return; |
| 1876 | } |
| 1877 | |
| 1878 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 1879 | } |
| 1880 | |
| 1881 | // TODO: Use all radio types |
| 1882 | static int techFromModemType(int mdmtype) |
| 1883 | { |
| 1884 | int ret = -1; |
| 1885 | switch (1 << mdmtype) { |
| 1886 | case MDM_CDMA: |
| 1887 | ret = RADIO_TECH_1xRTT; |
| 1888 | break; |
| 1889 | case MDM_EVDO: |
| 1890 | ret = RADIO_TECH_EVDO_A; |
| 1891 | break; |
| 1892 | case MDM_GSM: |
| 1893 | ret = RADIO_TECH_GPRS; |
| 1894 | break; |
| 1895 | case MDM_WCDMA: |
| 1896 | ret = RADIO_TECH_HSPA; |
| 1897 | break; |
| 1898 | case MDM_LTE: |
| 1899 | ret = RADIO_TECH_LTE; |
| 1900 | break; |
| 1901 | } |
| 1902 | return ret; |
| 1903 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1904 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 1905 | static void requestGetCellInfoList(void *data __unused, size_t datalen __unused, RIL_Token t) |
Wink Saville | 8a9e021 | 2013-04-09 12:11:38 -0700 | [diff] [blame] | 1906 | { |
| 1907 | uint64_t curTime = ril_nano_time(); |
| 1908 | RIL_CellInfo ci[1] = |
| 1909 | { |
| 1910 | { // ci[0] |
| 1911 | 1, // cellInfoType |
| 1912 | 1, // registered |
| 1913 | curTime - 1000, // Fake some time in the past |
| 1914 | { // union CellInfo |
| 1915 | { // RIL_CellInfoGsm gsm |
| 1916 | { // gsm.cellIdneityGsm |
| 1917 | s_mcc, // mcc |
| 1918 | s_mnc, // mnc |
| 1919 | s_lac, // lac |
| 1920 | s_cid, // cid |
| 1921 | 0 // psc |
| 1922 | }, |
| 1923 | { // gsm.signalStrengthGsm |
| 1924 | 10, // signalStrength |
| 1925 | 0 // bitErrorRate |
| 1926 | } |
| 1927 | } |
| 1928 | } |
| 1929 | } |
| 1930 | }; |
| 1931 | |
| 1932 | RIL_onRequestComplete(t, RIL_E_SUCCESS, ci, sizeof(ci)); |
| 1933 | } |
| 1934 | |
| 1935 | |
| 1936 | static void requestSetCellInfoListRate(void *data, size_t datalen, RIL_Token t) |
| 1937 | { |
| 1938 | // For now we'll save the rate but no RIL_UNSOL_CELL_INFO_LIST messages |
| 1939 | // will be sent. |
| 1940 | assert (datalen == sizeof(int)); |
| 1941 | s_cell_info_rate_ms = ((int *)data)[0]; |
| 1942 | |
| 1943 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 1944 | } |
| 1945 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 1946 | static void requestGetHardwareConfig(void *data, size_t datalen, RIL_Token t) |
| 1947 | { |
| 1948 | // TODO - hook this up with real query/info from radio. |
| 1949 | |
| 1950 | RIL_HardwareConfig hwCfg; |
| 1951 | |
| 1952 | RIL_UNUSED_PARM(data); |
| 1953 | RIL_UNUSED_PARM(datalen); |
| 1954 | |
| 1955 | hwCfg.type = -1; |
| 1956 | |
| 1957 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &hwCfg, sizeof(hwCfg)); |
| 1958 | } |
| 1959 | |
| 1960 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1961 | /*** Callback methods from the RIL library to us ***/ |
| 1962 | |
| 1963 | /** |
| 1964 | * Call from RIL to us to make a RIL_REQUEST |
| 1965 | * |
| 1966 | * Must be completed with a call to RIL_onRequestComplete() |
| 1967 | * |
| 1968 | * RIL_onRequestComplete() may be called from any thread, before or after |
| 1969 | * this function returns. |
| 1970 | * |
| 1971 | * Will always be called from the same thread, so returning here implies |
| 1972 | * that the radio is ready to process another command (whether or not |
| 1973 | * the previous command has completed). |
| 1974 | */ |
| 1975 | static void |
| 1976 | onRequest (int request, void *data, size_t datalen, RIL_Token t) |
| 1977 | { |
| 1978 | ATResponse *p_response; |
| 1979 | int err; |
| 1980 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 1981 | RLOGD("onRequest: %s", requestToString(request)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 1982 | |
| 1983 | /* Ignore all requests except RIL_REQUEST_GET_SIM_STATUS |
| 1984 | * when RADIO_STATE_UNAVAILABLE. |
| 1985 | */ |
| 1986 | if (sState == RADIO_STATE_UNAVAILABLE |
| 1987 | && request != RIL_REQUEST_GET_SIM_STATUS |
| 1988 | ) { |
| 1989 | RIL_onRequestComplete(t, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); |
| 1990 | return; |
| 1991 | } |
| 1992 | |
| 1993 | /* Ignore all non-power requests when RADIO_STATE_OFF |
| 1994 | * (except RIL_REQUEST_GET_SIM_STATUS) |
| 1995 | */ |
| 1996 | if (sState == RADIO_STATE_OFF |
| 1997 | && !(request == RIL_REQUEST_RADIO_POWER |
| 1998 | || request == RIL_REQUEST_GET_SIM_STATUS) |
| 1999 | ) { |
| 2000 | RIL_onRequestComplete(t, RIL_E_RADIO_NOT_AVAILABLE, NULL, 0); |
| 2001 | return; |
| 2002 | } |
| 2003 | |
| 2004 | switch (request) { |
| 2005 | case RIL_REQUEST_GET_SIM_STATUS: { |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 2006 | RIL_CardStatus_v6 *p_card_status; |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2007 | char *p_buffer; |
| 2008 | int buffer_size; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2009 | |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2010 | int result = getCardStatus(&p_card_status); |
| 2011 | if (result == RIL_E_SUCCESS) { |
| 2012 | p_buffer = (char *)p_card_status; |
| 2013 | buffer_size = sizeof(*p_card_status); |
| 2014 | } else { |
| 2015 | p_buffer = NULL; |
| 2016 | buffer_size = 0; |
| 2017 | } |
| 2018 | RIL_onRequestComplete(t, result, p_buffer, buffer_size); |
| 2019 | freeCardStatus(p_card_status); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2020 | break; |
| 2021 | } |
| 2022 | case RIL_REQUEST_GET_CURRENT_CALLS: |
| 2023 | requestGetCurrentCalls(data, datalen, t); |
| 2024 | break; |
| 2025 | case RIL_REQUEST_DIAL: |
| 2026 | requestDial(data, datalen, t); |
| 2027 | break; |
| 2028 | case RIL_REQUEST_HANGUP: |
| 2029 | requestHangup(data, datalen, t); |
| 2030 | break; |
| 2031 | case RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND: |
| 2032 | // 3GPP 22.030 6.5.5 |
| 2033 | // "Releases all held calls or sets User Determined User Busy |
| 2034 | // (UDUB) for a waiting call." |
| 2035 | at_send_command("AT+CHLD=0", NULL); |
| 2036 | |
| 2037 | /* success or failure is ignored by the upper layer here. |
| 2038 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 2039 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2040 | break; |
| 2041 | case RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND: |
| 2042 | // 3GPP 22.030 6.5.5 |
| 2043 | // "Releases all active calls (if any exist) and accepts |
| 2044 | // the other (held or waiting) call." |
| 2045 | at_send_command("AT+CHLD=1", NULL); |
| 2046 | |
| 2047 | /* success or failure is ignored by the upper layer here. |
| 2048 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 2049 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2050 | break; |
| 2051 | case RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE: |
| 2052 | // 3GPP 22.030 6.5.5 |
| 2053 | // "Places all active calls (if any exist) on hold and accepts |
| 2054 | // the other (held or waiting) call." |
| 2055 | at_send_command("AT+CHLD=2", NULL); |
| 2056 | |
| 2057 | #ifdef WORKAROUND_ERRONEOUS_ANSWER |
| 2058 | s_expectAnswer = 1; |
| 2059 | #endif /* WORKAROUND_ERRONEOUS_ANSWER */ |
| 2060 | |
| 2061 | /* success or failure is ignored by the upper layer here. |
| 2062 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 2063 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2064 | break; |
| 2065 | case RIL_REQUEST_ANSWER: |
| 2066 | at_send_command("ATA", NULL); |
| 2067 | |
| 2068 | #ifdef WORKAROUND_ERRONEOUS_ANSWER |
| 2069 | s_expectAnswer = 1; |
| 2070 | #endif /* WORKAROUND_ERRONEOUS_ANSWER */ |
| 2071 | |
| 2072 | /* success or failure is ignored by the upper layer here. |
| 2073 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 2074 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2075 | break; |
| 2076 | case RIL_REQUEST_CONFERENCE: |
| 2077 | // 3GPP 22.030 6.5.5 |
| 2078 | // "Adds a held call to the conversation" |
| 2079 | at_send_command("AT+CHLD=3", NULL); |
| 2080 | |
| 2081 | /* success or failure is ignored by the upper layer here. |
| 2082 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 2083 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2084 | break; |
| 2085 | case RIL_REQUEST_UDUB: |
| 2086 | /* user determined user busy */ |
| 2087 | /* sometimes used: ATH */ |
| 2088 | at_send_command("ATH", NULL); |
| 2089 | |
| 2090 | /* success or failure is ignored by the upper layer here. |
| 2091 | it will call GET_CURRENT_CALLS and determine success that way */ |
| 2092 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2093 | break; |
| 2094 | |
| 2095 | case RIL_REQUEST_SEPARATE_CONNECTION: |
| 2096 | { |
| 2097 | char cmd[12]; |
| 2098 | int party = ((int*)data)[0]; |
| 2099 | |
| 2100 | // Make sure that party is in a valid range. |
| 2101 | // (Note: The Telephony middle layer imposes a range of 1 to 7. |
| 2102 | // It's sufficient for us to just make sure it's single digit.) |
| 2103 | if (party > 0 && party < 10) { |
| 2104 | sprintf(cmd, "AT+CHLD=2%d", party); |
| 2105 | at_send_command(cmd, NULL); |
| 2106 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2107 | } else { |
| 2108 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 2109 | } |
| 2110 | } |
| 2111 | break; |
| 2112 | |
| 2113 | case RIL_REQUEST_SIGNAL_STRENGTH: |
| 2114 | requestSignalStrength(data, datalen, t); |
| 2115 | break; |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 2116 | case RIL_REQUEST_VOICE_REGISTRATION_STATE: |
| 2117 | case RIL_REQUEST_DATA_REGISTRATION_STATE: |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2118 | requestRegistrationState(request, data, datalen, t); |
| 2119 | break; |
| 2120 | case RIL_REQUEST_OPERATOR: |
| 2121 | requestOperator(data, datalen, t); |
| 2122 | break; |
| 2123 | case RIL_REQUEST_RADIO_POWER: |
| 2124 | requestRadioPower(data, datalen, t); |
| 2125 | break; |
| 2126 | case RIL_REQUEST_DTMF: { |
| 2127 | char c = ((char *)data)[0]; |
| 2128 | char *cmd; |
| 2129 | asprintf(&cmd, "AT+VTS=%c", (int)c); |
| 2130 | at_send_command(cmd, NULL); |
| 2131 | free(cmd); |
| 2132 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2133 | break; |
| 2134 | } |
| 2135 | case RIL_REQUEST_SEND_SMS: |
| 2136 | requestSendSMS(data, datalen, t); |
| 2137 | break; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2138 | case RIL_REQUEST_CDMA_SEND_SMS: |
| 2139 | requestCdmaSendSMS(data, datalen, t); |
| 2140 | break; |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 2141 | case RIL_REQUEST_IMS_SEND_SMS: |
| 2142 | requestImsSendSMS(data, datalen, t); |
| 2143 | break; |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2144 | case RIL_REQUEST_SETUP_DATA_CALL: |
| 2145 | requestSetupDataCall(data, datalen, t); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2146 | break; |
| 2147 | case RIL_REQUEST_SMS_ACKNOWLEDGE: |
| 2148 | requestSMSAcknowledge(data, datalen, t); |
| 2149 | break; |
| 2150 | |
| 2151 | case RIL_REQUEST_GET_IMSI: |
| 2152 | p_response = NULL; |
| 2153 | err = at_send_command_numeric("AT+CIMI", &p_response); |
| 2154 | |
| 2155 | if (err < 0 || p_response->success == 0) { |
| 2156 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 2157 | } else { |
| 2158 | RIL_onRequestComplete(t, RIL_E_SUCCESS, |
| 2159 | p_response->p_intermediates->line, sizeof(char *)); |
| 2160 | } |
| 2161 | at_response_free(p_response); |
| 2162 | break; |
| 2163 | |
| 2164 | case RIL_REQUEST_GET_IMEI: |
| 2165 | p_response = NULL; |
| 2166 | err = at_send_command_numeric("AT+CGSN", &p_response); |
| 2167 | |
| 2168 | if (err < 0 || p_response->success == 0) { |
| 2169 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 2170 | } else { |
| 2171 | RIL_onRequestComplete(t, RIL_E_SUCCESS, |
| 2172 | p_response->p_intermediates->line, sizeof(char *)); |
| 2173 | } |
| 2174 | at_response_free(p_response); |
| 2175 | break; |
| 2176 | |
| 2177 | case RIL_REQUEST_SIM_IO: |
| 2178 | requestSIM_IO(data,datalen,t); |
| 2179 | break; |
| 2180 | |
| 2181 | case RIL_REQUEST_SEND_USSD: |
| 2182 | requestSendUSSD(data, datalen, t); |
| 2183 | break; |
| 2184 | |
| 2185 | case RIL_REQUEST_CANCEL_USSD: |
| 2186 | p_response = NULL; |
| 2187 | err = at_send_command_numeric("AT+CUSD=2", &p_response); |
| 2188 | |
| 2189 | if (err < 0 || p_response->success == 0) { |
| 2190 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 2191 | } else { |
| 2192 | RIL_onRequestComplete(t, RIL_E_SUCCESS, |
| 2193 | p_response->p_intermediates->line, sizeof(char *)); |
| 2194 | } |
| 2195 | at_response_free(p_response); |
| 2196 | break; |
| 2197 | |
| 2198 | case RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC: |
| 2199 | at_send_command("AT+COPS=0", NULL); |
| 2200 | break; |
| 2201 | |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 2202 | case RIL_REQUEST_DATA_CALL_LIST: |
| 2203 | requestDataCallList(data, datalen, t); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2204 | break; |
| 2205 | |
| 2206 | case RIL_REQUEST_QUERY_NETWORK_SELECTION_MODE: |
| 2207 | requestQueryNetworkSelectionMode(data, datalen, t); |
| 2208 | break; |
| 2209 | |
| 2210 | case RIL_REQUEST_OEM_HOOK_RAW: |
| 2211 | // echo back data |
| 2212 | RIL_onRequestComplete(t, RIL_E_SUCCESS, data, datalen); |
| 2213 | break; |
| 2214 | |
| 2215 | |
| 2216 | case RIL_REQUEST_OEM_HOOK_STRINGS: { |
| 2217 | int i; |
| 2218 | const char ** cur; |
| 2219 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2220 | RLOGD("got OEM_HOOK_STRINGS: 0x%8p %lu", data, (long)datalen); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2221 | |
| 2222 | |
| 2223 | for (i = (datalen / sizeof (char *)), cur = (const char **)data ; |
| 2224 | i > 0 ; cur++, i --) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2225 | RLOGD("> '%s'", *cur); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | // echo back strings |
| 2229 | RIL_onRequestComplete(t, RIL_E_SUCCESS, data, datalen); |
| 2230 | break; |
| 2231 | } |
| 2232 | |
| 2233 | case RIL_REQUEST_WRITE_SMS_TO_SIM: |
| 2234 | requestWriteSmsToSim(data, datalen, t); |
| 2235 | break; |
| 2236 | |
| 2237 | case RIL_REQUEST_DELETE_SMS_ON_SIM: { |
| 2238 | char * cmd; |
| 2239 | p_response = NULL; |
| 2240 | asprintf(&cmd, "AT+CMGD=%d", ((int *)data)[0]); |
| 2241 | err = at_send_command(cmd, &p_response); |
| 2242 | free(cmd); |
| 2243 | if (err < 0 || p_response->success == 0) { |
| 2244 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 2245 | } else { |
| 2246 | RIL_onRequestComplete(t, RIL_E_SUCCESS, NULL, 0); |
| 2247 | } |
| 2248 | at_response_free(p_response); |
| 2249 | break; |
| 2250 | } |
| 2251 | |
| 2252 | case RIL_REQUEST_ENTER_SIM_PIN: |
| 2253 | case RIL_REQUEST_ENTER_SIM_PUK: |
| 2254 | case RIL_REQUEST_ENTER_SIM_PIN2: |
| 2255 | case RIL_REQUEST_ENTER_SIM_PUK2: |
| 2256 | case RIL_REQUEST_CHANGE_SIM_PIN: |
| 2257 | case RIL_REQUEST_CHANGE_SIM_PIN2: |
| 2258 | requestEnterSimPin(data, datalen, t); |
| 2259 | break; |
| 2260 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 2261 | case RIL_REQUEST_IMS_REGISTRATION_STATE: { |
| 2262 | int reply[2]; |
| 2263 | //0==unregistered, 1==registered |
| 2264 | reply[0] = s_ims_registered; |
| 2265 | |
| 2266 | //to be used when changed to include service supporated info |
| 2267 | //reply[1] = s_ims_services; |
| 2268 | |
| 2269 | // FORMAT_3GPP(1) vs FORMAT_3GPP2(2); |
| 2270 | reply[1] = s_ims_format; |
| 2271 | |
| 2272 | RLOGD("IMS_REGISTRATION=%d, format=%d ", |
| 2273 | reply[0], reply[1]); |
| 2274 | if (reply[1] != -1) { |
| 2275 | RIL_onRequestComplete(t, RIL_E_SUCCESS, reply, sizeof(reply)); |
| 2276 | } else { |
| 2277 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 2278 | } |
| 2279 | break; |
| 2280 | } |
| 2281 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2282 | case RIL_REQUEST_VOICE_RADIO_TECH: |
| 2283 | { |
| 2284 | int tech = techFromModemType(TECH(sMdmInfo)); |
| 2285 | if (tech < 0 ) |
| 2286 | RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); |
| 2287 | else |
| 2288 | RIL_onRequestComplete(t, RIL_E_SUCCESS, &tech, sizeof(tech)); |
| 2289 | } |
| 2290 | break; |
| 2291 | case RIL_REQUEST_SET_PREFERRED_NETWORK_TYPE: |
| 2292 | requestSetPreferredNetworkType(request, data, datalen, t); |
| 2293 | break; |
| 2294 | |
| 2295 | case RIL_REQUEST_GET_PREFERRED_NETWORK_TYPE: |
| 2296 | requestGetPreferredNetworkType(request, data, datalen, t); |
| 2297 | break; |
| 2298 | |
Jun Tian | 5802701 | 2013-07-30 11:07:22 +0800 | [diff] [blame] | 2299 | case RIL_REQUEST_GET_CELL_INFO_LIST: |
| 2300 | requestGetCellInfoList(data, datalen, t); |
| 2301 | break; |
| 2302 | |
| 2303 | case RIL_REQUEST_SET_UNSOL_CELL_INFO_LIST_RATE: |
| 2304 | requestSetCellInfoListRate(data, datalen, t); |
| 2305 | break; |
| 2306 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 2307 | case RIL_REQUEST_GET_HARDWARE_CONFIG: |
| 2308 | requestGetHardwareConfig(data, datalen, t); |
| 2309 | break; |
| 2310 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2311 | /* CDMA Specific Requests */ |
| 2312 | case RIL_REQUEST_BASEBAND_VERSION: |
| 2313 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2314 | requestCdmaBaseBandVersion(request, data, datalen, t); |
| 2315 | break; |
| 2316 | } // Fall-through if tech is not cdma |
| 2317 | |
| 2318 | case RIL_REQUEST_DEVICE_IDENTITY: |
| 2319 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2320 | requestCdmaDeviceIdentity(request, data, datalen, t); |
| 2321 | break; |
| 2322 | } // Fall-through if tech is not cdma |
| 2323 | |
| 2324 | case RIL_REQUEST_CDMA_SUBSCRIPTION: |
| 2325 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2326 | requestCdmaSubscription(request, data, datalen, t); |
| 2327 | break; |
| 2328 | } // Fall-through if tech is not cdma |
| 2329 | |
| 2330 | case RIL_REQUEST_CDMA_SET_SUBSCRIPTION_SOURCE: |
| 2331 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2332 | requestCdmaSetSubscriptionSource(request, data, datalen, t); |
| 2333 | break; |
| 2334 | } // Fall-through if tech is not cdma |
| 2335 | |
| 2336 | case RIL_REQUEST_CDMA_GET_SUBSCRIPTION_SOURCE: |
| 2337 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2338 | requestCdmaGetSubscriptionSource(request, data, datalen, t); |
| 2339 | break; |
| 2340 | } // Fall-through if tech is not cdma |
| 2341 | |
| 2342 | case RIL_REQUEST_CDMA_QUERY_ROAMING_PREFERENCE: |
| 2343 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2344 | requestCdmaGetRoamingPreference(request, data, datalen, t); |
| 2345 | break; |
| 2346 | } // Fall-through if tech is not cdma |
| 2347 | |
| 2348 | case RIL_REQUEST_CDMA_SET_ROAMING_PREFERENCE: |
| 2349 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2350 | requestCdmaSetRoamingPreference(request, data, datalen, t); |
| 2351 | break; |
| 2352 | } // Fall-through if tech is not cdma |
| 2353 | |
| 2354 | case RIL_REQUEST_EXIT_EMERGENCY_CALLBACK_MODE: |
| 2355 | if (TECH_BIT(sMdmInfo) == MDM_CDMA) { |
| 2356 | requestExitEmergencyMode(data, datalen, t); |
| 2357 | break; |
| 2358 | } // Fall-through if tech is not cdma |
| 2359 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2360 | default: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2361 | RLOGD("Request not supported. Tech: %d",TECH(sMdmInfo)); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2362 | RIL_onRequestComplete(t, RIL_E_REQUEST_NOT_SUPPORTED, NULL, 0); |
| 2363 | break; |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | /** |
| 2368 | * Synchronous call from the RIL to us to return current radio state. |
| 2369 | * RADIO_STATE_UNAVAILABLE should be the initial state. |
| 2370 | */ |
| 2371 | static RIL_RadioState |
| 2372 | currentState() |
| 2373 | { |
| 2374 | return sState; |
| 2375 | } |
| 2376 | /** |
| 2377 | * Call from RIL to us to find out whether a specific request code |
| 2378 | * is supported by this implementation. |
| 2379 | * |
| 2380 | * Return 1 for "supported" and 0 for "unsupported" |
| 2381 | */ |
| 2382 | |
| 2383 | static int |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 2384 | onSupports (int requestCode __unused) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2385 | { |
| 2386 | //@@@ todo |
| 2387 | |
| 2388 | return 1; |
| 2389 | } |
| 2390 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 2391 | static void onCancel (RIL_Token t __unused) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2392 | { |
| 2393 | //@@@todo |
| 2394 | |
| 2395 | } |
| 2396 | |
| 2397 | static const char * getVersion(void) |
| 2398 | { |
| 2399 | return "android reference-ril 1.0"; |
| 2400 | } |
| 2401 | |
| 2402 | static void |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2403 | setRadioTechnology(ModemInfo *mdm, int newtech) |
| 2404 | { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2405 | RLOGD("setRadioTechnology(%d)", newtech); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2406 | |
| 2407 | int oldtech = TECH(mdm); |
| 2408 | |
| 2409 | if (newtech != oldtech) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2410 | RLOGD("Tech change (%d => %d)", oldtech, newtech); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2411 | TECH(mdm) = newtech; |
| 2412 | if (techFromModemType(newtech) != techFromModemType(oldtech)) { |
| 2413 | int tech = techFromModemType(TECH(sMdmInfo)); |
| 2414 | if (tech > 0 ) { |
| 2415 | RIL_onUnsolicitedResponse(RIL_UNSOL_VOICE_RADIO_TECH_CHANGED, |
| 2416 | &tech, sizeof(tech)); |
| 2417 | } |
| 2418 | } |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | static void |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2423 | setRadioState(RIL_RadioState newState) |
| 2424 | { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2425 | RLOGD("setRadioState(%d)", newState); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2426 | RIL_RadioState oldState; |
| 2427 | |
| 2428 | pthread_mutex_lock(&s_state_mutex); |
| 2429 | |
| 2430 | oldState = sState; |
| 2431 | |
| 2432 | if (s_closed > 0) { |
| 2433 | // If we're closed, the only reasonable state is |
| 2434 | // RADIO_STATE_UNAVAILABLE |
| 2435 | // This is here because things on the main thread |
| 2436 | // may attempt to change the radio state after the closed |
| 2437 | // event happened in another thread |
| 2438 | newState = RADIO_STATE_UNAVAILABLE; |
| 2439 | } |
| 2440 | |
| 2441 | if (sState != newState || s_closed > 0) { |
| 2442 | sState = newState; |
| 2443 | |
| 2444 | pthread_cond_broadcast (&s_state_cond); |
| 2445 | } |
| 2446 | |
| 2447 | pthread_mutex_unlock(&s_state_mutex); |
| 2448 | |
| 2449 | |
| 2450 | /* do these outside of the mutex */ |
| 2451 | if (sState != oldState) { |
| 2452 | RIL_onUnsolicitedResponse (RIL_UNSOL_RESPONSE_RADIO_STATE_CHANGED, |
| 2453 | NULL, 0); |
Alex Yakavenka | 81d1485 | 2013-12-04 13:54:37 -0800 | [diff] [blame] | 2454 | // Sim state can change as result of radio state change |
| 2455 | RIL_onUnsolicitedResponse (RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, |
| 2456 | NULL, 0); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2457 | |
| 2458 | /* FIXME onSimReady() and onRadioPowerOn() cannot be called |
| 2459 | * from the AT reader thread |
| 2460 | * Currently, this doesn't happen, but if that changes then these |
| 2461 | * will need to be dispatched on the request thread |
| 2462 | */ |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2463 | if (sState == RADIO_STATE_ON) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2464 | onRadioPowerOn(); |
| 2465 | } |
| 2466 | } |
| 2467 | } |
| 2468 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2469 | /** Returns RUIM_NOT_READY on error */ |
| 2470 | static SIM_Status |
| 2471 | getRUIMStatus() |
| 2472 | { |
| 2473 | ATResponse *p_response = NULL; |
| 2474 | int err; |
| 2475 | int ret; |
| 2476 | char *cpinLine; |
| 2477 | char *cpinResult; |
| 2478 | |
| 2479 | if (sState == RADIO_STATE_OFF || sState == RADIO_STATE_UNAVAILABLE) { |
| 2480 | ret = SIM_NOT_READY; |
| 2481 | goto done; |
| 2482 | } |
| 2483 | |
| 2484 | err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &p_response); |
| 2485 | |
| 2486 | if (err != 0) { |
| 2487 | ret = SIM_NOT_READY; |
| 2488 | goto done; |
| 2489 | } |
| 2490 | |
| 2491 | switch (at_get_cme_error(p_response)) { |
| 2492 | case CME_SUCCESS: |
| 2493 | break; |
| 2494 | |
| 2495 | case CME_SIM_NOT_INSERTED: |
| 2496 | ret = SIM_ABSENT; |
| 2497 | goto done; |
| 2498 | |
| 2499 | default: |
| 2500 | ret = SIM_NOT_READY; |
| 2501 | goto done; |
| 2502 | } |
| 2503 | |
| 2504 | /* CPIN? has succeeded, now look at the result */ |
| 2505 | |
| 2506 | cpinLine = p_response->p_intermediates->line; |
| 2507 | err = at_tok_start (&cpinLine); |
| 2508 | |
| 2509 | if (err < 0) { |
| 2510 | ret = SIM_NOT_READY; |
| 2511 | goto done; |
| 2512 | } |
| 2513 | |
| 2514 | err = at_tok_nextstr(&cpinLine, &cpinResult); |
| 2515 | |
| 2516 | if (err < 0) { |
| 2517 | ret = SIM_NOT_READY; |
| 2518 | goto done; |
| 2519 | } |
| 2520 | |
| 2521 | if (0 == strcmp (cpinResult, "SIM PIN")) { |
| 2522 | ret = SIM_PIN; |
| 2523 | goto done; |
| 2524 | } else if (0 == strcmp (cpinResult, "SIM PUK")) { |
| 2525 | ret = SIM_PUK; |
| 2526 | goto done; |
| 2527 | } else if (0 == strcmp (cpinResult, "PH-NET PIN")) { |
| 2528 | return SIM_NETWORK_PERSONALIZATION; |
| 2529 | } else if (0 != strcmp (cpinResult, "READY")) { |
| 2530 | /* we're treating unsupported lock types as "sim absent" */ |
| 2531 | ret = SIM_ABSENT; |
| 2532 | goto done; |
| 2533 | } |
| 2534 | |
| 2535 | at_response_free(p_response); |
| 2536 | p_response = NULL; |
| 2537 | cpinResult = NULL; |
| 2538 | |
| 2539 | ret = SIM_READY; |
| 2540 | |
| 2541 | done: |
| 2542 | at_response_free(p_response); |
| 2543 | return ret; |
| 2544 | } |
| 2545 | |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2546 | /** Returns SIM_NOT_READY on error */ |
David 'Digit' Turner | af1298d | 2011-02-04 13:36:47 +0100 | [diff] [blame] | 2547 | static SIM_Status |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2548 | getSIMStatus() |
| 2549 | { |
| 2550 | ATResponse *p_response = NULL; |
| 2551 | int err; |
| 2552 | int ret; |
| 2553 | char *cpinLine; |
| 2554 | char *cpinResult; |
| 2555 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2556 | RLOGD("getSIMStatus(). sState: %d",sState); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2557 | if (sState == RADIO_STATE_OFF || sState == RADIO_STATE_UNAVAILABLE) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2558 | ret = SIM_NOT_READY; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2559 | goto done; |
| 2560 | } |
| 2561 | |
| 2562 | err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &p_response); |
| 2563 | |
| 2564 | if (err != 0) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2565 | ret = SIM_NOT_READY; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2566 | goto done; |
| 2567 | } |
| 2568 | |
| 2569 | switch (at_get_cme_error(p_response)) { |
| 2570 | case CME_SUCCESS: |
| 2571 | break; |
| 2572 | |
| 2573 | case CME_SIM_NOT_INSERTED: |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2574 | ret = SIM_ABSENT; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2575 | goto done; |
| 2576 | |
| 2577 | default: |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2578 | ret = SIM_NOT_READY; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2579 | goto done; |
| 2580 | } |
| 2581 | |
| 2582 | /* CPIN? has succeeded, now look at the result */ |
| 2583 | |
| 2584 | cpinLine = p_response->p_intermediates->line; |
| 2585 | err = at_tok_start (&cpinLine); |
| 2586 | |
| 2587 | if (err < 0) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2588 | ret = SIM_NOT_READY; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2589 | goto done; |
| 2590 | } |
| 2591 | |
| 2592 | err = at_tok_nextstr(&cpinLine, &cpinResult); |
| 2593 | |
| 2594 | if (err < 0) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2595 | ret = SIM_NOT_READY; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2596 | goto done; |
| 2597 | } |
| 2598 | |
| 2599 | if (0 == strcmp (cpinResult, "SIM PIN")) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2600 | ret = SIM_PIN; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2601 | goto done; |
| 2602 | } else if (0 == strcmp (cpinResult, "SIM PUK")) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2603 | ret = SIM_PUK; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2604 | goto done; |
| 2605 | } else if (0 == strcmp (cpinResult, "PH-NET PIN")) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2606 | return SIM_NETWORK_PERSONALIZATION; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2607 | } else if (0 != strcmp (cpinResult, "READY")) { |
| 2608 | /* we're treating unsupported lock types as "sim absent" */ |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2609 | ret = SIM_ABSENT; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2610 | goto done; |
| 2611 | } |
| 2612 | |
| 2613 | at_response_free(p_response); |
| 2614 | p_response = NULL; |
| 2615 | cpinResult = NULL; |
| 2616 | |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2617 | ret = SIM_READY; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2618 | |
| 2619 | done: |
| 2620 | at_response_free(p_response); |
| 2621 | return ret; |
| 2622 | } |
| 2623 | |
| 2624 | |
| 2625 | /** |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2626 | * Get the current card status. |
| 2627 | * |
| 2628 | * This must be freed using freeCardStatus. |
| 2629 | * @return: On success returns RIL_E_SUCCESS |
| 2630 | */ |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 2631 | static int getCardStatus(RIL_CardStatus_v6 **pp_card_status) { |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2632 | static RIL_AppStatus app_status_array[] = { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2633 | // SIM_ABSENT = 0 |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2634 | { RIL_APPTYPE_UNKNOWN, RIL_APPSTATE_UNKNOWN, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2635 | NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN }, |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2636 | // SIM_NOT_READY = 1 |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2637 | { RIL_APPTYPE_SIM, RIL_APPSTATE_DETECTED, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2638 | NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN }, |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2639 | // SIM_READY = 2 |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2640 | { RIL_APPTYPE_SIM, RIL_APPSTATE_READY, RIL_PERSOSUBSTATE_READY, |
| 2641 | NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN }, |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2642 | // SIM_PIN = 3 |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2643 | { RIL_APPTYPE_SIM, RIL_APPSTATE_PIN, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2644 | NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN }, |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2645 | // SIM_PUK = 4 |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2646 | { RIL_APPTYPE_SIM, RIL_APPSTATE_PUK, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2647 | NULL, NULL, 0, RIL_PINSTATE_ENABLED_BLOCKED, RIL_PINSTATE_UNKNOWN }, |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2648 | // SIM_NETWORK_PERSONALIZATION = 5 |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2649 | { RIL_APPTYPE_SIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_NETWORK, |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2650 | NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN }, |
| 2651 | // RUIM_ABSENT = 6 |
| 2652 | { RIL_APPTYPE_UNKNOWN, RIL_APPSTATE_UNKNOWN, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2653 | NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN }, |
| 2654 | // RUIM_NOT_READY = 7 |
| 2655 | { RIL_APPTYPE_RUIM, RIL_APPSTATE_DETECTED, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2656 | NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN }, |
| 2657 | // RUIM_READY = 8 |
| 2658 | { RIL_APPTYPE_RUIM, RIL_APPSTATE_READY, RIL_PERSOSUBSTATE_READY, |
| 2659 | NULL, NULL, 0, RIL_PINSTATE_UNKNOWN, RIL_PINSTATE_UNKNOWN }, |
| 2660 | // RUIM_PIN = 9 |
| 2661 | { RIL_APPTYPE_RUIM, RIL_APPSTATE_PIN, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2662 | NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN }, |
| 2663 | // RUIM_PUK = 10 |
| 2664 | { RIL_APPTYPE_RUIM, RIL_APPSTATE_PUK, RIL_PERSOSUBSTATE_UNKNOWN, |
| 2665 | NULL, NULL, 0, RIL_PINSTATE_ENABLED_BLOCKED, RIL_PINSTATE_UNKNOWN }, |
| 2666 | // RUIM_NETWORK_PERSONALIZATION = 11 |
| 2667 | { RIL_APPTYPE_RUIM, RIL_APPSTATE_SUBSCRIPTION_PERSO, RIL_PERSOSUBSTATE_SIM_NETWORK, |
| 2668 | NULL, NULL, 0, RIL_PINSTATE_ENABLED_NOT_VERIFIED, RIL_PINSTATE_UNKNOWN } |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2669 | }; |
| 2670 | RIL_CardState card_state; |
| 2671 | int num_apps; |
| 2672 | |
| 2673 | int sim_status = getSIMStatus(); |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2674 | if (sim_status == SIM_ABSENT) { |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2675 | card_state = RIL_CARDSTATE_ABSENT; |
| 2676 | num_apps = 0; |
| 2677 | } else { |
| 2678 | card_state = RIL_CARDSTATE_PRESENT; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2679 | num_apps = 2; |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | // Allocate and initialize base card status. |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 2683 | RIL_CardStatus_v6 *p_card_status = malloc(sizeof(RIL_CardStatus_v6)); |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2684 | p_card_status->card_state = card_state; |
| 2685 | p_card_status->universal_pin_state = RIL_PINSTATE_UNKNOWN; |
| 2686 | p_card_status->gsm_umts_subscription_app_index = RIL_CARD_MAX_APPS; |
| 2687 | p_card_status->cdma_subscription_app_index = RIL_CARD_MAX_APPS; |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 2688 | p_card_status->ims_subscription_app_index = RIL_CARD_MAX_APPS; |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2689 | p_card_status->num_applications = num_apps; |
| 2690 | |
| 2691 | // Initialize application status |
| 2692 | int i; |
| 2693 | for (i = 0; i < RIL_CARD_MAX_APPS; i++) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2694 | p_card_status->applications[i] = app_status_array[SIM_ABSENT]; |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | // Pickup the appropriate application status |
| 2698 | // that reflects sim_status for gsm. |
| 2699 | if (num_apps != 0) { |
| 2700 | // Only support one app, gsm |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2701 | p_card_status->num_applications = 2; |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2702 | p_card_status->gsm_umts_subscription_app_index = 0; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2703 | p_card_status->cdma_subscription_app_index = 1; |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2704 | |
| 2705 | // Get the correct app status |
| 2706 | p_card_status->applications[0] = app_status_array[sim_status]; |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2707 | p_card_status->applications[1] = app_status_array[sim_status + RUIM_ABSENT]; |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | *pp_card_status = p_card_status; |
| 2711 | return RIL_E_SUCCESS; |
| 2712 | } |
| 2713 | |
| 2714 | /** |
| 2715 | * Free the card status returned by getCardStatus |
| 2716 | */ |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 2717 | static void freeCardStatus(RIL_CardStatus_v6 *p_card_status) { |
Wink Saville | f6aa7c1 | 2009-04-30 14:20:52 -0700 | [diff] [blame] | 2718 | free(p_card_status); |
| 2719 | } |
| 2720 | |
| 2721 | /** |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2722 | * SIM ready means any commands that access the SIM will work, including: |
| 2723 | * AT+CPIN, AT+CSMS, AT+CNMI, AT+CRSM |
| 2724 | * (all SMS-related commands) |
| 2725 | */ |
| 2726 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 2727 | static void pollSIMState (void *param __unused) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2728 | { |
| 2729 | ATResponse *p_response; |
| 2730 | int ret; |
| 2731 | |
| 2732 | if (sState != RADIO_STATE_SIM_NOT_READY) { |
| 2733 | // no longer valid to poll |
| 2734 | return; |
| 2735 | } |
| 2736 | |
| 2737 | switch(getSIMStatus()) { |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2738 | case SIM_ABSENT: |
| 2739 | case SIM_PIN: |
| 2740 | case SIM_PUK: |
| 2741 | case SIM_NETWORK_PERSONALIZATION: |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2742 | default: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2743 | RLOGI("SIM ABSENT or LOCKED"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2744 | RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2745 | return; |
| 2746 | |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2747 | case SIM_NOT_READY: |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2748 | RIL_requestTimedCallback (pollSIMState, NULL, &TIMEVAL_SIMPOLL); |
| 2749 | return; |
| 2750 | |
John Wang | 309ac29 | 2009-07-30 14:53:23 -0700 | [diff] [blame] | 2751 | case SIM_READY: |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2752 | RLOGI("SIM_READY"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2753 | onSIMReady(); |
| 2754 | RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_SIM_STATUS_CHANGED, NULL, 0); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2755 | return; |
| 2756 | } |
| 2757 | } |
| 2758 | |
| 2759 | /** returns 1 if on, 0 if off, and -1 on error */ |
| 2760 | static int isRadioOn() |
| 2761 | { |
| 2762 | ATResponse *p_response = NULL; |
| 2763 | int err; |
| 2764 | char *line; |
| 2765 | char ret; |
| 2766 | |
| 2767 | err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &p_response); |
| 2768 | |
| 2769 | if (err < 0 || p_response->success == 0) { |
| 2770 | // assume radio is off |
| 2771 | goto error; |
| 2772 | } |
| 2773 | |
| 2774 | line = p_response->p_intermediates->line; |
| 2775 | |
| 2776 | err = at_tok_start(&line); |
| 2777 | if (err < 0) goto error; |
| 2778 | |
| 2779 | err = at_tok_nextbool(&line, &ret); |
| 2780 | if (err < 0) goto error; |
| 2781 | |
| 2782 | at_response_free(p_response); |
| 2783 | |
| 2784 | return (int)ret; |
| 2785 | |
| 2786 | error: |
| 2787 | |
| 2788 | at_response_free(p_response); |
| 2789 | return -1; |
| 2790 | } |
| 2791 | |
| 2792 | /** |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2793 | * Parse the response generated by a +CTEC AT command |
| 2794 | * The values read from the response are stored in current and preferred. |
| 2795 | * Both current and preferred may be null. The corresponding value is ignored in that case. |
| 2796 | * |
| 2797 | * @return: -1 if some error occurs (or if the modem doesn't understand the +CTEC command) |
| 2798 | * 1 if the response includes the current technology only |
| 2799 | * 0 if the response includes both current technology and preferred mode |
| 2800 | */ |
| 2801 | int parse_technology_response( const char *response, int *current, int32_t *preferred ) |
| 2802 | { |
| 2803 | int err; |
| 2804 | char *line, *p; |
| 2805 | int ct; |
| 2806 | int32_t pt = 0; |
| 2807 | char *str_pt; |
| 2808 | |
| 2809 | line = p = strdup(response); |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2810 | RLOGD("Response: %s", line); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2811 | err = at_tok_start(&p); |
| 2812 | if (err || !at_tok_hasmore(&p)) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2813 | RLOGD("err: %d. p: %s", err, p); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2814 | free(line); |
| 2815 | return -1; |
| 2816 | } |
| 2817 | |
| 2818 | err = at_tok_nextint(&p, &ct); |
| 2819 | if (err) { |
| 2820 | free(line); |
| 2821 | return -1; |
| 2822 | } |
| 2823 | if (current) *current = ct; |
| 2824 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2825 | RLOGD("line remaining after int: %s", p); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2826 | |
| 2827 | err = at_tok_nexthexint(&p, &pt); |
| 2828 | if (err) { |
| 2829 | free(line); |
| 2830 | return 1; |
| 2831 | } |
| 2832 | if (preferred) { |
| 2833 | *preferred = pt; |
| 2834 | } |
| 2835 | free(line); |
| 2836 | |
| 2837 | return 0; |
| 2838 | } |
| 2839 | |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 2840 | int query_supported_techs( ModemInfo *mdm __unused, int *supported ) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2841 | { |
| 2842 | ATResponse *p_response; |
| 2843 | int err, val, techs = 0; |
| 2844 | char *tok; |
| 2845 | char *line; |
| 2846 | |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2847 | RLOGD("query_supported_techs"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2848 | err = at_send_command_singleline("AT+CTEC=?", "+CTEC:", &p_response); |
| 2849 | if (err || !p_response->success) |
| 2850 | goto error; |
| 2851 | line = p_response->p_intermediates->line; |
| 2852 | err = at_tok_start(&line); |
| 2853 | if (err || !at_tok_hasmore(&line)) |
| 2854 | goto error; |
| 2855 | while (!at_tok_nextint(&line, &val)) { |
| 2856 | techs |= ( 1 << val ); |
| 2857 | } |
| 2858 | if (supported) *supported = techs; |
| 2859 | return 0; |
| 2860 | error: |
| 2861 | at_response_free(p_response); |
| 2862 | return -1; |
| 2863 | } |
| 2864 | |
| 2865 | /** |
| 2866 | * query_ctec. Send the +CTEC AT command to the modem to query the current |
| 2867 | * and preferred modes. It leaves values in the addresses pointed to by |
| 2868 | * current and preferred. If any of those pointers are NULL, the corresponding value |
| 2869 | * is ignored, but the return value will still reflect if retreiving and parsing of the |
| 2870 | * values suceeded. |
| 2871 | * |
| 2872 | * @mdm Currently unused |
| 2873 | * @current A pointer to store the current mode returned by the modem. May be null. |
| 2874 | * @preferred A pointer to store the preferred mode returned by the modem. May be null. |
| 2875 | * @return -1 on error (or failure to parse) |
| 2876 | * 1 if only the current mode was returned by modem (or failed to parse preferred) |
| 2877 | * 0 if both current and preferred were returned correctly |
| 2878 | */ |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 2879 | int query_ctec(ModemInfo *mdm __unused, int *current, int32_t *preferred) |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2880 | { |
| 2881 | ATResponse *response = NULL; |
| 2882 | int err; |
| 2883 | int res; |
| 2884 | |
Colin Cross | 5cba488 | 2014-02-05 18:55:42 -0800 | [diff] [blame] | 2885 | RLOGD("query_ctec. current: %p, preferred: %p", current, preferred); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2886 | err = at_send_command_singleline("AT+CTEC?", "+CTEC:", &response); |
| 2887 | if (!err && response->success) { |
| 2888 | res = parse_technology_response(response->p_intermediates->line, current, preferred); |
| 2889 | at_response_free(response); |
| 2890 | return res; |
| 2891 | } |
Colin Cross | 5cba488 | 2014-02-05 18:55:42 -0800 | [diff] [blame] | 2892 | RLOGE("Error executing command: %d. response: %p. status: %d", err, response, response? response->success : -1); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2893 | at_response_free(response); |
| 2894 | return -1; |
| 2895 | } |
| 2896 | |
| 2897 | int is_multimode_modem(ModemInfo *mdm) |
| 2898 | { |
| 2899 | ATResponse *response; |
| 2900 | int err; |
| 2901 | char *line; |
| 2902 | int tech; |
| 2903 | int32_t preferred; |
| 2904 | |
| 2905 | if (query_ctec(mdm, &tech, &preferred) == 0) { |
| 2906 | mdm->currentTech = tech; |
| 2907 | mdm->preferredNetworkMode = preferred; |
| 2908 | if (query_supported_techs(mdm, &mdm->supportedTechs)) { |
| 2909 | return 0; |
| 2910 | } |
| 2911 | return 1; |
| 2912 | } |
| 2913 | return 0; |
| 2914 | } |
| 2915 | |
| 2916 | /** |
| 2917 | * Find out if our modem is GSM, CDMA or both (Multimode) |
| 2918 | */ |
| 2919 | static void probeForModemMode(ModemInfo *info) |
| 2920 | { |
| 2921 | ATResponse *response; |
| 2922 | int err; |
| 2923 | assert (info); |
| 2924 | // Currently, our only known multimode modem is qemu's android modem, |
| 2925 | // which implements the AT+CTEC command to query and set mode. |
| 2926 | // Try that first |
| 2927 | |
| 2928 | if (is_multimode_modem(info)) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2929 | RLOGI("Found Multimode Modem. Supported techs mask: %8.8x. Current tech: %d", |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2930 | info->supportedTechs, info->currentTech); |
| 2931 | return; |
| 2932 | } |
| 2933 | |
| 2934 | /* Being here means that our modem is not multimode */ |
| 2935 | info->isMultimode = 0; |
| 2936 | |
| 2937 | /* CDMA Modems implement the AT+WNAM command */ |
| 2938 | err = at_send_command_singleline("AT+WNAM","+WNAM:", &response); |
| 2939 | if (!err && response->success) { |
| 2940 | at_response_free(response); |
| 2941 | // TODO: find out if we really support EvDo |
| 2942 | info->supportedTechs = MDM_CDMA | MDM_EVDO; |
| 2943 | info->currentTech = MDM_CDMA; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2944 | RLOGI("Found CDMA Modem"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2945 | return; |
| 2946 | } |
| 2947 | if (!err) at_response_free(response); |
| 2948 | // TODO: find out if modem really supports WCDMA/LTE |
| 2949 | info->supportedTechs = MDM_GSM | MDM_WCDMA | MDM_LTE; |
| 2950 | info->currentTech = MDM_GSM; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 2951 | RLOGI("Found GSM Modem"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | /** |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2955 | * Initialize everything that can be configured while we're still in |
| 2956 | * AT+CFUN=0 |
| 2957 | */ |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 2958 | static void initializeCallback(void *param __unused) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2959 | { |
| 2960 | ATResponse *p_response = NULL; |
| 2961 | int err; |
| 2962 | |
| 2963 | setRadioState (RADIO_STATE_OFF); |
| 2964 | |
| 2965 | at_handshake(); |
| 2966 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 2967 | probeForModemMode(sMdmInfo); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 2968 | /* note: we don't check errors here. Everything important will |
| 2969 | be handled in onATTimeout and onATReaderClosed */ |
| 2970 | |
| 2971 | /* atchannel is tolerant of echo but it must */ |
| 2972 | /* have verbose result codes */ |
| 2973 | at_send_command("ATE0Q0V1", NULL); |
| 2974 | |
| 2975 | /* No auto-answer */ |
| 2976 | at_send_command("ATS0=0", NULL); |
| 2977 | |
| 2978 | /* Extended errors */ |
| 2979 | at_send_command("AT+CMEE=1", NULL); |
| 2980 | |
| 2981 | /* Network registration events */ |
| 2982 | err = at_send_command("AT+CREG=2", &p_response); |
| 2983 | |
| 2984 | /* some handsets -- in tethered mode -- don't support CREG=2 */ |
| 2985 | if (err < 0 || p_response->success == 0) { |
| 2986 | at_send_command("AT+CREG=1", NULL); |
| 2987 | } |
| 2988 | |
| 2989 | at_response_free(p_response); |
| 2990 | |
| 2991 | /* GPRS registration events */ |
| 2992 | at_send_command("AT+CGREG=1", NULL); |
| 2993 | |
| 2994 | /* Call Waiting notifications */ |
| 2995 | at_send_command("AT+CCWA=1", NULL); |
| 2996 | |
| 2997 | /* Alternating voice/data off */ |
| 2998 | at_send_command("AT+CMOD=0", NULL); |
| 2999 | |
| 3000 | /* Not muted */ |
| 3001 | at_send_command("AT+CMUT=0", NULL); |
| 3002 | |
| 3003 | /* +CSSU unsolicited supp service notifications */ |
| 3004 | at_send_command("AT+CSSN=0,1", NULL); |
| 3005 | |
| 3006 | /* no connected line identification */ |
| 3007 | at_send_command("AT+COLP=0", NULL); |
| 3008 | |
| 3009 | /* HEX character set */ |
| 3010 | at_send_command("AT+CSCS=\"HEX\"", NULL); |
| 3011 | |
| 3012 | /* USSD unsolicited */ |
| 3013 | at_send_command("AT+CUSD=1", NULL); |
| 3014 | |
| 3015 | /* Enable +CGEV GPRS event notifications, but don't buffer */ |
| 3016 | at_send_command("AT+CGEREP=1,0", NULL); |
| 3017 | |
| 3018 | /* SMS PDU mode */ |
| 3019 | at_send_command("AT+CMGF=0", NULL); |
| 3020 | |
| 3021 | #ifdef USE_TI_COMMANDS |
| 3022 | |
| 3023 | at_send_command("AT%CPI=3", NULL); |
| 3024 | |
| 3025 | /* TI specific -- notifications when SMS is ready (currently ignored) */ |
| 3026 | at_send_command("AT%CSTAT=1", NULL); |
| 3027 | |
| 3028 | #endif /* USE_TI_COMMANDS */ |
| 3029 | |
| 3030 | |
| 3031 | /* assume radio is off on error */ |
| 3032 | if (isRadioOn() > 0) { |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3033 | setRadioState (RADIO_STATE_ON); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | static void waitForClose() |
| 3038 | { |
| 3039 | pthread_mutex_lock(&s_state_mutex); |
| 3040 | |
| 3041 | while (s_closed == 0) { |
| 3042 | pthread_cond_wait(&s_state_cond, &s_state_mutex); |
| 3043 | } |
| 3044 | |
| 3045 | pthread_mutex_unlock(&s_state_mutex); |
| 3046 | } |
| 3047 | |
Sukanya Rajkhowa | a18b9d1 | 2013-09-10 12:30:13 -0700 | [diff] [blame] | 3048 | static void sendUnsolImsNetworkStateChanged() |
| 3049 | { |
| 3050 | #if 0 // to be used when unsol is changed to return data. |
| 3051 | int reply[2]; |
| 3052 | reply[0] = s_ims_registered; |
| 3053 | reply[1] = s_ims_services; |
| 3054 | reply[1] = s_ims_format; |
| 3055 | #endif |
| 3056 | RIL_onUnsolicitedResponse(RIL_UNSOL_RESPONSE_IMS_NETWORK_STATE_CHANGED, |
| 3057 | NULL, 0); |
| 3058 | } |
| 3059 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3060 | /** |
| 3061 | * Called by atchannel when an unsolicited line appears |
| 3062 | * This is called on atchannel's reader thread. AT commands may |
| 3063 | * not be issued here |
| 3064 | */ |
| 3065 | static void onUnsolicited (const char *s, const char *sms_pdu) |
| 3066 | { |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3067 | char *line = NULL, *p; |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3068 | int err; |
| 3069 | |
| 3070 | /* Ignore unsolicited responses until we're initialized. |
| 3071 | * This is OK because the RIL library will poll for initial state |
| 3072 | */ |
| 3073 | if (sState == RADIO_STATE_UNAVAILABLE) { |
| 3074 | return; |
| 3075 | } |
| 3076 | |
| 3077 | if (strStartsWith(s, "%CTZV:")) { |
| 3078 | /* TI specific -- NITZ time */ |
| 3079 | char *response; |
| 3080 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3081 | line = p = strdup(s); |
| 3082 | at_tok_start(&p); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3083 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3084 | err = at_tok_nextstr(&p, &response); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3085 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3086 | free(line); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3087 | if (err != 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3088 | RLOGE("invalid NITZ line %s\n", s); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3089 | } else { |
| 3090 | RIL_onUnsolicitedResponse ( |
| 3091 | RIL_UNSOL_NITZ_TIME_RECEIVED, |
| 3092 | response, strlen(response)); |
| 3093 | } |
| 3094 | } else if (strStartsWith(s,"+CRING:") |
| 3095 | || strStartsWith(s,"RING") |
| 3096 | || strStartsWith(s,"NO CARRIER") |
| 3097 | || strStartsWith(s,"+CCWA") |
| 3098 | ) { |
| 3099 | RIL_onUnsolicitedResponse ( |
| 3100 | RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED, |
| 3101 | NULL, 0); |
| 3102 | #ifdef WORKAROUND_FAKE_CGEV |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3103 | RIL_requestTimedCallback (onDataCallListChanged, NULL, NULL); //TODO use new function |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3104 | #endif /* WORKAROUND_FAKE_CGEV */ |
| 3105 | } else if (strStartsWith(s,"+CREG:") |
| 3106 | || strStartsWith(s,"+CGREG:") |
| 3107 | ) { |
| 3108 | RIL_onUnsolicitedResponse ( |
Wink Saville | 2c1fb3a | 2011-03-19 13:42:45 -0700 | [diff] [blame] | 3109 | RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED, |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3110 | NULL, 0); |
| 3111 | #ifdef WORKAROUND_FAKE_CGEV |
Wink Saville | 7f85680 | 2009-06-09 10:23:37 -0700 | [diff] [blame] | 3112 | RIL_requestTimedCallback (onDataCallListChanged, NULL, NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3113 | #endif /* WORKAROUND_FAKE_CGEV */ |
| 3114 | } else if (strStartsWith(s, "+CMT:")) { |
| 3115 | RIL_onUnsolicitedResponse ( |
| 3116 | RIL_UNSOL_RESPONSE_NEW_SMS, |
| 3117 | sms_pdu, strlen(sms_pdu)); |
| 3118 | } else if (strStartsWith(s, "+CDS:")) { |
| 3119 | RIL_onUnsolicitedResponse ( |
| 3120 | RIL_UNSOL_RESPONSE_NEW_SMS_STATUS_REPORT, |
| 3121 | sms_pdu, strlen(sms_pdu)); |
| 3122 | } else if (strStartsWith(s, "+CGEV:")) { |
| 3123 | /* Really, we can ignore NW CLASS and ME CLASS events here, |
| 3124 | * but right now we don't since extranous |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3125 | * RIL_UNSOL_DATA_CALL_LIST_CHANGED calls are tolerated |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3126 | */ |
| 3127 | /* can't issue AT commands here -- call on main thread */ |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3128 | RIL_requestTimedCallback (onDataCallListChanged, NULL, NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3129 | #ifdef WORKAROUND_FAKE_CGEV |
| 3130 | } else if (strStartsWith(s, "+CME ERROR: 150")) { |
Wink Saville | f4c4d36 | 2009-04-02 01:37:03 -0700 | [diff] [blame] | 3131 | RIL_requestTimedCallback (onDataCallListChanged, NULL, NULL); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3132 | #endif /* WORKAROUND_FAKE_CGEV */ |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3133 | } else if (strStartsWith(s, "+CTEC: ")) { |
| 3134 | int tech, mask; |
| 3135 | switch (parse_technology_response(s, &tech, NULL)) |
| 3136 | { |
| 3137 | case -1: // no argument could be parsed. |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3138 | RLOGE("invalid CTEC line %s\n", s); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3139 | break; |
| 3140 | case 1: // current mode correctly parsed |
| 3141 | case 0: // preferred mode correctly parsed |
| 3142 | mask = 1 << tech; |
| 3143 | if (mask != MDM_GSM && mask != MDM_CDMA && |
| 3144 | mask != MDM_WCDMA && mask != MDM_LTE) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3145 | RLOGE("Unknown technology %d\n", tech); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3146 | } else { |
| 3147 | setRadioTechnology(sMdmInfo, tech); |
| 3148 | } |
| 3149 | break; |
| 3150 | } |
| 3151 | } else if (strStartsWith(s, "+CCSS: ")) { |
| 3152 | int source = 0; |
| 3153 | line = p = strdup(s); |
| 3154 | if (!line) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3155 | RLOGE("+CCSS: Unable to allocate memory"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3156 | return; |
| 3157 | } |
| 3158 | if (at_tok_start(&p) < 0) { |
| 3159 | free(line); |
| 3160 | return; |
| 3161 | } |
| 3162 | if (at_tok_nextint(&p, &source) < 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3163 | RLOGE("invalid +CCSS response: %s", line); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3164 | free(line); |
| 3165 | return; |
| 3166 | } |
| 3167 | SSOURCE(sMdmInfo) = source; |
| 3168 | RIL_onUnsolicitedResponse(RIL_UNSOL_CDMA_SUBSCRIPTION_SOURCE_CHANGED, |
| 3169 | &source, sizeof(source)); |
| 3170 | } else if (strStartsWith(s, "+WSOS: ")) { |
| 3171 | char state = 0; |
| 3172 | int unsol; |
| 3173 | line = p = strdup(s); |
| 3174 | if (!line) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3175 | RLOGE("+WSOS: Unable to allocate memory"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3176 | return; |
| 3177 | } |
| 3178 | if (at_tok_start(&p) < 0) { |
| 3179 | free(line); |
| 3180 | return; |
| 3181 | } |
| 3182 | if (at_tok_nextbool(&p, &state) < 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3183 | RLOGE("invalid +WSOS response: %s", line); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3184 | free(line); |
| 3185 | return; |
| 3186 | } |
| 3187 | free(line); |
| 3188 | |
| 3189 | unsol = state ? |
| 3190 | RIL_UNSOL_ENTER_EMERGENCY_CALLBACK_MODE : RIL_UNSOL_EXIT_EMERGENCY_CALLBACK_MODE; |
| 3191 | |
| 3192 | RIL_onUnsolicitedResponse(unsol, NULL, 0); |
| 3193 | |
| 3194 | } else if (strStartsWith(s, "+WPRL: ")) { |
| 3195 | int version = -1; |
| 3196 | line = p = strdup(s); |
| 3197 | if (!line) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3198 | RLOGE("+WPRL: Unable to allocate memory"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3199 | return; |
| 3200 | } |
| 3201 | if (at_tok_start(&p) < 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3202 | RLOGE("invalid +WPRL response: %s", s); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3203 | free(line); |
| 3204 | return; |
| 3205 | } |
| 3206 | if (at_tok_nextint(&p, &version) < 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3207 | RLOGE("invalid +WPRL response: %s", s); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3208 | free(line); |
| 3209 | return; |
| 3210 | } |
| 3211 | free(line); |
| 3212 | RIL_onUnsolicitedResponse(RIL_UNSOL_CDMA_PRL_CHANGED, &version, sizeof(version)); |
| 3213 | } else if (strStartsWith(s, "+CFUN: 0")) { |
| 3214 | setRadioState(RADIO_STATE_OFF); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3215 | } |
| 3216 | } |
| 3217 | |
| 3218 | /* Called on command or reader thread */ |
| 3219 | static void onATReaderClosed() |
| 3220 | { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3221 | RLOGI("AT channel closed\n"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3222 | at_close(); |
| 3223 | s_closed = 1; |
| 3224 | |
| 3225 | setRadioState (RADIO_STATE_UNAVAILABLE); |
| 3226 | } |
| 3227 | |
| 3228 | /* Called on command thread */ |
| 3229 | static void onATTimeout() |
| 3230 | { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3231 | RLOGI("AT channel timeout; closing\n"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3232 | at_close(); |
| 3233 | |
| 3234 | s_closed = 1; |
| 3235 | |
| 3236 | /* FIXME cause a radio reset here */ |
| 3237 | |
| 3238 | setRadioState (RADIO_STATE_UNAVAILABLE); |
| 3239 | } |
| 3240 | |
Etan Cohen | d365219 | 2014-06-20 08:28:44 -0700 | [diff] [blame] | 3241 | /* Called to pass hardware configuration information to telephony |
| 3242 | * framework. |
| 3243 | */ |
| 3244 | static void setHardwareConfiguration(int num, RIL_HardwareConfig *cfg) |
| 3245 | { |
| 3246 | RIL_onUnsolicitedResponse(RIL_UNSOL_HARDWARE_CONFIG_CHANGED, cfg, num*sizeof(*cfg)); |
| 3247 | } |
| 3248 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3249 | static void usage(char *s) |
| 3250 | { |
| 3251 | #ifdef RIL_SHLIB |
| 3252 | fprintf(stderr, "reference-ril requires: -p <tcp port> or -d /dev/tty_device\n"); |
| 3253 | #else |
| 3254 | fprintf(stderr, "usage: %s [-p <tcp port>] [-d /dev/tty_device]\n", s); |
| 3255 | exit(-1); |
| 3256 | #endif |
| 3257 | } |
| 3258 | |
| 3259 | static void * |
Mark Salyzyn | ba58c20 | 2014-03-12 15:20:22 -0700 | [diff] [blame] | 3260 | mainLoop(void *param __unused) |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3261 | { |
| 3262 | int fd; |
| 3263 | int ret; |
| 3264 | |
| 3265 | AT_DUMP("== ", "entering mainLoop()", -1 ); |
| 3266 | at_set_on_reader_closed(onATReaderClosed); |
| 3267 | at_set_on_timeout(onATTimeout); |
| 3268 | |
| 3269 | for (;;) { |
| 3270 | fd = -1; |
| 3271 | while (fd < 0) { |
| 3272 | if (s_port > 0) { |
| 3273 | fd = socket_loopback_client(s_port, SOCK_STREAM); |
| 3274 | } else if (s_device_socket) { |
The Android Open Source Project | e6e6fb2 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3275 | if (!strcmp(s_device_path, "/dev/socket/qemud")) { |
Vladimir Chtchetkine | 385a739 | 2011-08-04 14:03:07 -0700 | [diff] [blame] | 3276 | /* Before trying to connect to /dev/socket/qemud (which is |
| 3277 | * now another "legacy" way of communicating with the |
| 3278 | * emulator), we will try to connecto to gsm service via |
| 3279 | * qemu pipe. */ |
| 3280 | fd = qemu_pipe_open("qemud:gsm"); |
| 3281 | if (fd < 0) { |
| 3282 | /* Qemu-specific control socket */ |
| 3283 | fd = socket_local_client( "qemud", |
| 3284 | ANDROID_SOCKET_NAMESPACE_RESERVED, |
| 3285 | SOCK_STREAM ); |
| 3286 | if (fd >= 0 ) { |
| 3287 | char answer[2]; |
The Android Open Source Project | e6e6fb2 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3288 | |
Vladimir Chtchetkine | 385a739 | 2011-08-04 14:03:07 -0700 | [diff] [blame] | 3289 | if ( write(fd, "gsm", 3) != 3 || |
| 3290 | read(fd, answer, 2) != 2 || |
| 3291 | memcmp(answer, "OK", 2) != 0) |
| 3292 | { |
| 3293 | close(fd); |
| 3294 | fd = -1; |
| 3295 | } |
| 3296 | } |
| 3297 | } |
The Android Open Source Project | e6e6fb2 | 2009-03-18 17:39:47 -0700 | [diff] [blame] | 3298 | } |
| 3299 | else |
| 3300 | fd = socket_local_client( s_device_path, |
| 3301 | ANDROID_SOCKET_NAMESPACE_FILESYSTEM, |
| 3302 | SOCK_STREAM ); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3303 | } else if (s_device_path != NULL) { |
| 3304 | fd = open (s_device_path, O_RDWR); |
| 3305 | if ( fd >= 0 && !memcmp( s_device_path, "/dev/ttyS", 9 ) ) { |
| 3306 | /* disable echo on serial ports */ |
| 3307 | struct termios ios; |
| 3308 | tcgetattr( fd, &ios ); |
| 3309 | ios.c_lflag = 0; /* disable ECHO, ICANON, etc... */ |
| 3310 | tcsetattr( fd, TCSANOW, &ios ); |
| 3311 | } |
| 3312 | } |
| 3313 | |
| 3314 | if (fd < 0) { |
| 3315 | perror ("opening AT interface. retrying..."); |
| 3316 | sleep(10); |
| 3317 | /* never returns */ |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | s_closed = 0; |
| 3322 | ret = at_open(fd, onUnsolicited); |
| 3323 | |
| 3324 | if (ret < 0) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3325 | RLOGE ("AT error %d on at_open\n", ret); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3326 | return 0; |
| 3327 | } |
| 3328 | |
| 3329 | RIL_requestTimedCallback(initializeCallback, NULL, &TIMEVAL_0); |
| 3330 | |
| 3331 | // Give initializeCallback a chance to dispatched, since |
| 3332 | // we don't presently have a cancellation mechanism |
| 3333 | sleep(1); |
| 3334 | |
| 3335 | waitForClose(); |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3336 | RLOGI("Re-opening after close"); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | #ifdef RIL_SHLIB |
| 3341 | |
| 3342 | pthread_t s_tid_mainloop; |
| 3343 | |
| 3344 | const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv) |
| 3345 | { |
| 3346 | int ret; |
| 3347 | int fd = -1; |
| 3348 | int opt; |
| 3349 | pthread_attr_t attr; |
| 3350 | |
| 3351 | s_rilenv = env; |
| 3352 | |
Sandeep Gutta | 11f2794 | 2014-07-10 05:00:25 +0530 | [diff] [blame^] | 3353 | while ( -1 != (opt = getopt(argc, argv, "p:d:s:c:"))) { |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3354 | switch (opt) { |
| 3355 | case 'p': |
| 3356 | s_port = atoi(optarg); |
| 3357 | if (s_port == 0) { |
| 3358 | usage(argv[0]); |
| 3359 | return NULL; |
| 3360 | } |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3361 | RLOGI("Opening loopback port %d\n", s_port); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3362 | break; |
| 3363 | |
| 3364 | case 'd': |
| 3365 | s_device_path = optarg; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3366 | RLOGI("Opening tty device %s\n", s_device_path); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3367 | break; |
| 3368 | |
| 3369 | case 's': |
| 3370 | s_device_path = optarg; |
| 3371 | s_device_socket = 1; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3372 | RLOGI("Opening socket %s\n", s_device_path); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3373 | break; |
| 3374 | |
Sandeep Gutta | 11f2794 | 2014-07-10 05:00:25 +0530 | [diff] [blame^] | 3375 | case 'c': |
| 3376 | RLOGI("Client id received %s\n", optarg); |
| 3377 | break; |
| 3378 | |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3379 | default: |
| 3380 | usage(argv[0]); |
| 3381 | return NULL; |
| 3382 | } |
| 3383 | } |
| 3384 | |
| 3385 | if (s_port < 0 && s_device_path == NULL) { |
| 3386 | usage(argv[0]); |
| 3387 | return NULL; |
| 3388 | } |
| 3389 | |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3390 | sMdmInfo = calloc(1, sizeof(ModemInfo)); |
| 3391 | if (!sMdmInfo) { |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3392 | RLOGE("Unable to alloc memory for ModemInfo"); |
Jaime A Lopez-Sollano | e964504 | 2012-08-29 07:27:27 -0700 | [diff] [blame] | 3393 | return NULL; |
| 3394 | } |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3395 | pthread_attr_init (&attr); |
| 3396 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 3397 | ret = pthread_create(&s_tid_mainloop, &attr, mainLoop, NULL); |
| 3398 | |
| 3399 | return &s_callbacks; |
| 3400 | } |
| 3401 | #else /* RIL_SHLIB */ |
| 3402 | int main (int argc, char **argv) |
| 3403 | { |
| 3404 | int ret; |
| 3405 | int fd = -1; |
| 3406 | int opt; |
| 3407 | |
| 3408 | while ( -1 != (opt = getopt(argc, argv, "p:d:"))) { |
| 3409 | switch (opt) { |
| 3410 | case 'p': |
| 3411 | s_port = atoi(optarg); |
| 3412 | if (s_port == 0) { |
| 3413 | usage(argv[0]); |
| 3414 | } |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3415 | RLOGI("Opening loopback port %d\n", s_port); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3416 | break; |
| 3417 | |
| 3418 | case 'd': |
| 3419 | s_device_path = optarg; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3420 | RLOGI("Opening tty device %s\n", s_device_path); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3421 | break; |
| 3422 | |
| 3423 | case 's': |
| 3424 | s_device_path = optarg; |
| 3425 | s_device_socket = 1; |
Wink Saville | 4dcab4f | 2012-11-19 16:05:13 -0800 | [diff] [blame] | 3426 | RLOGI("Opening socket %s\n", s_device_path); |
The Android Open Source Project | 00f06fc | 2009-03-03 19:32:15 -0800 | [diff] [blame] | 3427 | break; |
| 3428 | |
| 3429 | default: |
| 3430 | usage(argv[0]); |
| 3431 | } |
| 3432 | } |
| 3433 | |
| 3434 | if (s_port < 0 && s_device_path == NULL) { |
| 3435 | usage(argv[0]); |
| 3436 | } |
| 3437 | |
| 3438 | RIL_register(&s_callbacks); |
| 3439 | |
| 3440 | mainLoop(NULL); |
| 3441 | |
| 3442 | return 0; |
| 3443 | } |
| 3444 | |
| 3445 | #endif /* RIL_SHLIB */ |