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