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