Beispiel #1
0
int openDataChannel(char* deviceNote, int isBlocking, RILChannelCtx* p_channel, int channelId)
{
    RLOGI("openDataChannel");
    if (p_channel->fd > 0)
        closeDataChannel(p_channel);

    memset(p_channel, 0, sizeof(RILChannelCtx));
    p_channel->fd = -1;    /* fd of the AT channel */

    int retryCounter = 0;
    int err = 0;
    while (p_channel->fd < 0 && retryCounter < 5) {
        do {
            RLOGI("set property for usb permission");
            p_channel->fd = open(deviceNote, isBlocking? O_RDWR : (O_RDWR | O_NONBLOCK));
        } while (p_channel->fd < 0 && errno == EINTR);

        if (p_channel->fd < 0) {
            perror ("opening AT interface. retrying...");
            RLOGE("could not connect to %s: %s", "/dev/ttyUSB0", strerror(errno));
            /* reduce polling time for usb connected */
            sleep(1);
            /* never returns */
        } else {
            struct termios ios;
            tcgetattr(p_channel->fd, &ios );
            ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
            ios.c_iflag = 0;
            tcsetattr(p_channel->fd, TCSANOW, &ios );
        }
        ++retryCounter;
    }

    if (p_channel->fd < 0) {
        RLOGE("%s open failed", deviceNote);
        return -1;
    } else {
        RLOGI("%s open success", deviceNote);
        p_channel->ATBufferCur = p_channel->ATBuffer;
        p_channel->myName = deviceNote;
        p_channel->id = ++channelId;
        p_channel->unsolHandler = 0;
        p_channel->readerClosed = 0;
        p_channel->responsePrefix = NULL;
        p_channel->smsPDU = NULL;
        p_channel->p_response = NULL;
    }
    return 0;
}
void requestDialUpCsd(void* data, size_t datalen, RIL_Token t)
{
    const char *dialUpNumber, *slotId;
    int request_parm_num = (datalen/sizeof(char*));
    char* command;
    int err = 0;

    RIL_Data_Call_Response_v6* response = alloca(sizeof(RIL_Data_Call_Response_v6));
    initialDataCallResponse(response, 1);

    LOGD("requestCsdDialUp() with datalen=%d,parm_num=%d",datalen,request_parm_num);
    dialUpNumber = ((const char**)data)[0];
    slotId = ((const char **)data)[1];

    err = openDataChannel("/dev/pttycsd", 1, &g_CsdDataChannel, g_CsdDataChannel.id);
    if (err < 0) {
        LOGE("requestCsdDialUp(): fail to open channel.");
        goto error;
    }

    // Select CSD dial up SIM.
    switch (slotId[0]) {
        case '0':
            command = "AT+ESUO=4";
            break;
        case '1':
            command = "AT=ESUO=5";
            break;
        default:
            command = "AT+ESUO=4";
            break;
    }
    err = at_send_command_to_data_channel(command, NULL, &g_CsdDataChannel);
    if (err < 0) {
        LOGE("requestCsdDialUp(): fail to select dial up SIM.");
        goto error;
    }

    // CSD dial up.
    asprintf(&command, "ATD%s", dialUpNumber);
    err = at_send_command_to_data_channel(command, NULL, &g_CsdDataChannel);
    free(command);
    if (err < 0) {
        LOGE("requestCsdDialUp(): fail to dial up.");
        goto error;
    }
    closeDataChannel(&g_CsdDataChannel);

    // Start pppd
    property_set("net.gprs.ppp-exit", "");
    property_set("ctl.start", "pppd_csd");

    int count = 0;
    while (count < 10) {
        if (isPPPRunning()) {
            LOGD("pppd started [%d]", count);
            break;
        } else {
            LOGD("Wait pppd started [%d]", count);
            sleep(1);
        }
        ++count;
    }

    int isPolling = 1;
    char* exitCode = malloc(PROPERTY_VALUE_MAX);
    char* runningCode = malloc(PROPERTY_VALUE_MAX);
    count = 0;
    int isPPPSucceed = 0;
    while (isPolling && count < 300) {
        memset(exitCode, 0, PROPERTY_VALUE_MAX);
        memset(runningCode, 0, PROPERTY_VALUE_MAX);
        property_get("net.gprs.ppp-running", runningCode, "");
        property_get("net.gprs.ppp-exit", exitCode, "");

        if (strcmp(exitCode, "") != 0) {
            LOGD("pppd exited [%s] during starting", exitCode);
            isPolling = 0;
        } else if (strcmp(runningCode, "yes") == 0) {
            //PPP Parameter
            char local[PROPERTY_VALUE_MAX] = {0};
            char remote[PROPERTY_VALUE_MAX] = {0};
            char dns1[PROPERTY_VALUE_MAX] = {0};
            char dns2[PROPERTY_VALUE_MAX] = {0};

            LOGD("polling pppd done");

            property_get("net.ppp0.local-ip", local, "0.0.0.0");
            property_get("net.ppp0.remote-ip", remote, "0.0.0.0");
            property_get("net.ppp0.dns1", dns1, "0.0.0.0");
            property_get("net.ppp0.dns2", dns2, "0.0.0.0");

            response->status = PDP_FAIL_NONE;
            response->suggestedRetryTime = 0;
            response->cid = 0;
            response->active = 2;
            asprintf(&response->type, "%s", "PPP");
            asprintf(&response->ifname, "%s", "ppp0");
            //address, local-ip
            asprintf(&response->addresses, "%s", local);
            //gateway, remote-ip
            asprintf(&response->gateways, "%s", remote);
            //dns
            asprintf(&response->dnses, "%s %s", dns1, dns2);

            LOGD("PPP Data call response: status=%d, suggestedRetryTime=%d, cid=%d, active=%d, \
                type=%s, ifname=%s, addresses=%s, dnses=%s, gateways=%s",
                response->status, response->suggestedRetryTime,
                response->cid, response->active, response->type,
                response->ifname, response->addresses,
                response->dnses, response->gateways);  
            
            isPPPSucceed = 1;
            isPolling = 0;
        } else {