void onStkEventDownloadCall(char* urc, RILChannelCtx* p_channel) { RIL_SOCKET_ID rid = getRILIdByChannelCtx(p_channel); int err, i = 0; char *p_cur = (char *)urc; int response[NUM_EVDL_CALL]={0}; //RIL_EVDLCall response = NULL; /* * +EVDLCALL: <status>,<ti>,<is_mt_call>,<is_far_end>,<cause_len>,<cause> */ for(i = 0; i < NUM_EVDL_CALL-1; i++) { response[i] = 0xff; } err = at_tok_start(&p_cur); if (err < 0) goto error; for(i = 0; i < NUM_EVDL_CALL-1; i++) { err = at_tok_nextint(&p_cur, &(response[i])); if(err < 0) { response[i] = 0xFF; LOGE("There is something wrong with item [%d]",i);}//goto error; } err = at_tok_nexthexint(&p_cur, &(response[i])); if(err < 0) { LOGE("There is something wrong with item [%d]",i);//goto error; } RIL_onUnsolicitedResponse( RIL_UNSOL_STK_EVDL_CALL, response, NUM_EVDL_CALL * sizeof(int), rid); return; error: LOGE("There is something wrong with the +EVDLCALL"); }
/** * RIL_REQUEST_VOICE_REGISTRATION_STATE * * Request current registration state. */ void requestRegistrationState(int request, void *data, size_t datalen, RIL_Token t) { (void) data; (void) datalen, (void)request; int err = 0; const char resp_size = 15; int response[resp_size]; char *responseStr[resp_size]; ATResponse *cgreg_resp = NULL, *e2reg_resp = NULL; char *line; int commas = 0; int skip, cs_status = 0; int i; /* IMPORTANT: Will take screen state lock here. Make sure to always call releaseScreenStateLock BEFORE returning! */ getScreenStateLock(); if (!getScreenState()) { (void)at_send_command("AT+CREG=2"); /* Ignore the response, not VITAL. */ } /* Setting default values in case values are not returned by AT command */ for (i = 0; i < resp_size; i++) responseStr[i] = NULL; memset(response, 0, sizeof(response)); err = at_send_command_singleline("AT+CREG?", "+CREG:", &cgreg_resp); if (err != AT_NOERROR) goto error; line = cgreg_resp->p_intermediates->line; err = at_tok_start(&line); if (err < 0) goto error; /* * The solicited version of the CREG response is * +CREG: n, stat, [lac, cid] * and the unsolicited version is * +CREG: stat, [lac, cid] * The <n> parameter is basically "is unsolicited creg on?" * which it should always be. * * Now we should normally get the solicited version here, * but the unsolicited version could have snuck in * so we have to handle both. * * Also since the LAC and CID are only reported when registered, * we can have 1, 2, 3, or 4 arguments here. * * finally, a +CGREG: answer may have a fifth value that corresponds * to the network type, as in; * * +CGREG: n, stat [,lac, cid [,networkType]] */ /* Count number of commas */ err = at_tok_charcounter(line, ',', &commas); if (err < 0) goto error; switch (commas) { case 0: /* +CREG: <stat> */ err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; response[1] = -1; response[2] = -1; break; case 1: /* +CREG: <n>, <stat> */ err = at_tok_nextint(&line, &skip); if (err < 0) goto error; err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; response[1] = -1; response[2] = -1; if (err < 0) goto error; break; case 2: /* +CREG: <stat>, <lac>, <cid> */ err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); if (err < 0) goto error; break; case 3: /* +CREG: <n>, <stat>, <lac>, <cid> */ case 4: /* +CREG: <n>, <stat>, <lac>, <cid>, <?> */ err = at_tok_nextint(&line, &skip); if (err < 0) goto error; err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); if (err < 0) goto error; break; default: goto error; } s_registrationDeniedReason = DEFAULT_VALUE; if (response[0] == CGREG_STAT_REG_DENIED) { err = at_send_command_singleline("AT*E2REG?", "*E2REG:", &e2reg_resp); if (err != AT_NOERROR) goto error; line = e2reg_resp->p_intermediates->line; err = at_tok_start(&line); if (err < 0) goto error; err = at_tok_nextint(&line, &skip); if (err < 0) goto error; err = at_tok_nextint(&line, &cs_status); if (err < 0) goto error; response[13] = convertRegistrationDeniedReason(cs_status); s_registrationDeniedReason = response[13]; err = asprintf(&responseStr[13], "%08x", response[13]); if (err < 0) goto error; } err = asprintf(&responseStr[0], "%d", response[0]); if (err < 0) goto error; if (response[1] > 0) err = asprintf(&responseStr[1], "%04x", response[1]); if (err < 0) goto error; if (response[2] > 0) err = asprintf(&responseStr[2], "%08x", response[2]); if (err < 0) goto error; if (response[0] == CGREG_STAT_REG_HOME_NET || response[0] == CGREG_STAT_ROAMING) responseStr[3] = getNetworkType(0); RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, resp_size * sizeof(char *)); finally: if (!getScreenState()) (void)at_send_command("AT+CREG=0"); releaseScreenStateLock(); /* Important! */ for (i = 0; i < resp_size; i++) free(responseStr[i]); at_response_free(cgreg_resp); at_response_free(e2reg_resp); return; error: LOGE("%s() Must never return an error when radio is on", __func__); RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); goto finally; }
/** * RIL_REQUEST_DATA_REGISTRATION_STATE * * Request current GPRS registration state. */ void requestGprsRegistrationState(int request, void *data, size_t datalen, RIL_Token t) { (void)request, (void)data, (void)datalen; int err = 0; const char resp_size = 6; int response[resp_size]; char *responseStr[resp_size]; ATResponse *atresponse = NULL; char *line, *p; int commas = 0; int skip, tmp; int count = 3; getScreenStateLock(); if (!getScreenState()) (void)at_send_command("AT+CGREG=2"); /* Response not vital */ memset(responseStr, 0, sizeof(responseStr)); memset(response, 0, sizeof(response)); response[1] = -1; response[2] = -1; err = at_send_command_singleline("AT+CGREG?", "+CGREG: ", &atresponse); if (err != AT_NOERROR) goto error; line = atresponse->p_intermediates->line; err = at_tok_start(&line); if (err < 0) goto error; /* * The solicited version of the +CGREG response is * +CGREG: n, stat, [lac, cid [,<AcT>]] * and the unsolicited version is * +CGREG: stat, [lac, cid [,<AcT>]] * The <n> parameter is basically "is unsolicited creg on?" * which it should always be. * * Now we should normally get the solicited version here, * but the unsolicited version could have snuck in * so we have to handle both. * * Also since the LAC, CID and AcT are only reported when registered, * we can have 1, 2, 3, 4 or 5 arguments here. */ /* Count number of commas */ p = line; err = at_tok_charcounter(line, ',', &commas); if (err < 0) { LOGE("%s() at_tok_charcounter failed", __func__); goto error; } switch (commas) { case 0: /* +CGREG: <stat> */ err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; break; case 1: /* +CGREG: <n>, <stat> */ err = at_tok_nextint(&line, &skip); if (err < 0) goto error; err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; break; case 2: /* +CGREG: <stat>, <lac>, <cid> */ err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); if (err < 0) goto error; break; case 3: /* +CGREG: <n>, <stat>, <lac>, <cid> */ /* +CGREG: <stat>, <lac>, <cid>, <AcT> */ err = at_tok_nextint(&line, &tmp); if (err < 0) goto error; /* We need to check if the second parameter is <lac> */ if (*(line) == '"') { response[0] = tmp; /* <stat> */ err = at_tok_nexthexint(&line, &response[1]); /* <lac> */ if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); /* <cid> */ if (err < 0) goto error; err = at_tok_nextint(&line, &response[3]); /* <AcT> */ if (err < 0) goto error; count = 4; } else { err = at_tok_nextint(&line, &response[0]); /* <stat> */ if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); /* <lac> */ if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); /* <cid> */ if (err < 0) goto error; } break; case 4: /* +CGREG: <n>, <stat>, <lac>, <cid>, <AcT> */ err = at_tok_nextint(&line, &skip); /* <n> */ if (err < 0) goto error; err = at_tok_nextint(&line, &response[0]); /* <stat> */ if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); /* <lac> */ if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); /* <cid> */ if (err < 0) goto error; err = at_tok_nextint(&line, &response[3]); /* <AcT> */ if (err < 0) goto error; count = 4; break; default: LOGE("%s() Invalid input", __func__); goto error; } if (response[0] == CGREG_STAT_REG_HOME_NET || response[0] == CGREG_STAT_ROAMING) responseStr[3] = getNetworkType(response[3]); /* Converting to stringlist for Android */ asprintf(&responseStr[0], "%d", response[0]); /* state */ if (response[1] >= 0) asprintf(&responseStr[1], "%04x", response[1]); /* LAC */ else responseStr[1] = NULL; if (response[2] >= 0) asprintf(&responseStr[2], "%08x", response[2]); /* CID */ else responseStr[2] = NULL; responseStr[5] = "1"; RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, resp_size * sizeof(char *)); finally: if (!getScreenState()) (void)at_send_command("AT+CGREG=0"); releaseScreenStateLock(); /* Important! */ if (responseStr[0]) free(responseStr[0]); if (responseStr[1]) free(responseStr[1]); if (responseStr[2]) free(responseStr[2]); if (responseStr[3]) free(responseStr[3]); at_response_free(atresponse); return; error: LOGE("%s Must never return an error when radio is on", __func__); RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); goto finally; }
static int _requestRegistrationStateWCDMASub(void *data,int request, size_t datalen, RIL_Token t) { int err; int response[4]={0,}; char * responseStr[4]={NULL,}; ATResponse *p_response = NULL; const char *cmd; const char *prefix; char *line, *p; int commas; int skip; int count = 3; int i = 0; if (request == RIL_REQUEST_VOICE_REGISTRATION_STATE) { cmd = "AT+CREG?"; prefix = "+CREG:"; } else if (request == RIL_REQUEST_DATA_REGISTRATION_STATE) { cmd = "AT+CGREG?"; prefix = "+CGREG:"; } else { assert(0); goto error; } err = at_send_command_singleline(cmd, prefix, &p_response); if (err != 0 ||p_response->success == 0 ) goto error; line = p_response->p_intermediates->line; err = at_tok_start(&line); if (err < 0) goto error; /* Ok you have to be careful here * The solicited version of the CREG response is * +CREG: n, stat, [lac, cid] * and the unsolicited version is * +CREG: stat, [lac, cid] * The <n> parameter is basically "is unsolicited creg on?" * which it should always be * * Now we should normally get the solicited version here, * but the unsolicited version could have snuck in * so we have to handle both * * Also since the LAC and CID are only reported when registered, * we can have 1, 2, 3, or 4 arguments here * * finally, a +CGREG: answer may have a fifth value that corresponds * to the network type, as in; * * +CGREG: n, stat [,lac, cid [,networkType]] */ /* count number of commas */ commas = 0; for (p = line ; *p != '\0' ;p++) { if (*p == ',') commas++; } switch (commas) { case 0: /* +CREG: <stat> */ err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; break; case 1: /* +CREG: <n>, <stat> */ err = at_tok_nextint(&line, &skip); if (err < 0) goto error; err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; break; case 2: /* +CREG: <stat>, <lac>, <cid> */ err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); if (err < 0) goto error; break; case 3: /* +CREG: <n>, <stat>, <lac>, <cid> */ err = at_tok_nextint(&line, &skip); if (err < 0) goto error; err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); if (err < 0) goto error; break; /* special case for CGREG, there is a fourth parameter * that is the network type (unknown/gprs/edge/umts) */ case 4: /* +CGREG: <n>, <stat>, <lac>, <cid>, <networkType> */ err = at_tok_nextint(&line, &skip); if (err < 0) goto error; err = at_tok_nextint(&line, &response[0]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[1]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[2]); if (err < 0) goto error; err = at_tok_nexthexint(&line, &response[3]); if (err < 0) goto error; count = 4; break; default: goto error; } if(response[0] != 1 && response[0] != 5 && response[0] != 3) goto error; //if(response[0] == 5) response[0] = 1; int type = getNetworkType(); asprintf(&responseStr[0], "%d", response[0]); asprintf(&responseStr[1], "%x", response[1]); asprintf(&responseStr[2], "%x", response[2]); asprintf(&responseStr[3], "%d", type); creg_value=response[0]; RIL_onRequestComplete(t, RIL_E_SUCCESS, responseStr, 4*sizeof(char*)); at_response_free(p_response); for(i=0;i<4;i++){ if(responseStr[i]) free(responseStr[i]); } return 0; error: LOGE("requestRegistrationState must never return an error when radio is on"); RIL_onRequestComplete(t, RIL_E_GENERIC_FAILURE, NULL, 0); at_response_free(p_response); for(i=0;i<4;i++){ if(responseStr[i]) free(responseStr[i]); } return -1; }