示例#1
0
int at_send_command_to_data_channel(const char *command, ATResponse **pp_outResponse, RILChannelCtx *p_channel) {
    const char* line = NULL;
    int ret = writeline(command, p_channel);
    if (ret == 0) {
        p_channel->p_response = at_response_new();
        do {
            line = readline(p_channel);
            if (line != NULL)
                RLOGI("readline: %s", line);
            else
                RLOGI("readline: EMPTY");
        } while (line != NULL && !(strcmp(line, "OK") == 0 || strcmp(line, "NO CARRIER") == 0 || strStartsWith(line, "CONNECT") == 1 || strstr(line, "ERROR")));

        if (line != NULL) {
            RLOGI("process line: %s", line);
            processLine(line, p_channel);
            if (pp_outResponse == NULL) {
                at_response_free(p_channel->p_response);
            } else {
                reverseIntermediates(p_channel->p_response);
                *pp_outResponse = p_channel->p_response;
            }
            return 0;
        }
    }
    return AT_ERROR_GENERIC;
}
示例#2
0
RILChannelCtx *openPPPDataChannel(int isBlocking)
{
    RLOGI("openDataChannel");
    RILChannelCtx* p_channel = &g_pppDataChannel;
    if (p_channel->fd > 0)
        closePPPDataChannel();

    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");
            /* set this property than the permission of /dev/ttyACM0 will be set to 777 */
            property_set("gsm.usb.ttyusb", "1");
            if (isBlocking)
                p_channel->fd = open("/dev/ttyUSB0", O_RDWR);
            else
                p_channel->fd = open("/dev/ttyUSB0", 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("/dev/ttyUSB0 open failed");
        return NULL;
    } else {
        RLOGI("/dev/ttyUSB0 open success");
        p_channel->ATBufferCur = p_channel->ATBuffer;
        p_channel->myName = "PPP_CHANNEL";
        p_channel->id = ++g_channelIndex;
        p_channel->unsolHandler = 0;
        p_channel->readerClosed = 0;
        p_channel->responsePrefix = NULL;
        p_channel->smsPDU = NULL;
        p_channel->p_response = NULL;
    }
    return &g_pppDataChannel;
}
示例#3
0
void purge_data_channel(RILChannelCtx *p_channel) {
    if (p_channel > 0 && p_channel->fd > 0) {
        const char* line = NULL;
        char buffer[64] = {0};
        int count = 0;
        int readbyte = 0;
        while ((readbyte = read(p_channel->fd, buffer, 64)) > 0) {
            count += readbyte;
        }
        RLOGI("Total %d byte purged", count);
    } else {
        RLOGI("Channel not opened, not to purge");
    }
}
示例#4
0
static void waitForClose()
{
RLOGI("[Emu]waitForClose in");
    pthread_mutex_lock(&s_state_mutex);

    while (s_closed == 0) {
		RLOGI("[Emu]waitForClose while in");
        pthread_cond_wait(&s_state_cond, &s_state_mutex);
		RLOGI("[Emu]waitForClose while out");
    }

    pthread_mutex_unlock(&s_state_mutex);
	RLOGI("[Emu]waitForClose out");
}
示例#5
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 asyncOperation(void* ptr,
					asyncHandler handler,
					asyncDestructor dtor,
					const char* operationID) //operationID for debug
{
	//Run it right away to see if it finished instantly.
	auto res = handler(ptr);
	switch(res)
	{
		case ASYNC_OPERATION_COMPLETE:
			RLOGI("Async operation %s completed", operationID);
			break;
		case ASYNC_OPERATION_RUNNING:
			while(length == BUFFER_SIZE)
			{
				RLOGW("To many async operations in flight! %d", length);
				asyncOperationsProcess();
			}

			asyncBuffer[length++] = (AsyncItem){ptr, handler, dtor, operationID};
			break;
		case ASYNC_OPERATION_FAILURE:
			RLOGE("Async operation %s failed", operationID);
			break;
		default:
			RLOGE("Async operation %s returned invalid result %d", operationID, res);
			break;
	}
}
void asyncOperationsProcess()
{
	for(int i = 0; i < length; i++)
	{
		auto item = asyncBuffer[i];
		auto res  = item.handler(item.payload);
		switch(res)
		{
			case ASYNC_OPERATION_COMPLETE:
				asyncBuffer[i--] = asyncBuffer[--length];
				item.dtor(item.payload);

				RLOGI("Async operation %s completed", item.operationID);
				break;
			case ASYNC_OPERATION_RUNNING:
				//Do nothing
				break;
			case ASYNC_OPERATION_FAILURE:
				RLOGE("Async operation %s failed", item.operationID);
				asyncBuffer[i--] = asyncBuffer[--length];
				item.dtor(item.payload);
				break;
			default:
				RLOGE("Async operation %s returned invalid result %d", item.operationID, res);
				asyncBuffer[i--] = asyncBuffer[--length];
				item.dtor(item.payload);
				break;
		}
	}
}
示例#8
0
void waitForTargetPPPStopped(RILChannelCtx *p_channel) {
    const char* line = NULL;
    int count = 0;
    p_channel->p_response = at_response_new();
    while (count < 60) {
        line = readline(p_channel);
        if (line != NULL && strcmp(line, "NO CARRIER") == 0) {
            RLOGI("readline: %s [%d]", line, count);
            break;
        } else {
            RLOGI("Still wait for NO CARRIER [%d]", count);
            ++count;
            sleep(1);
        }
    }
    at_response_free(p_channel->p_response);
}
示例#9
0
/* Called on command or reader thread */
static void onATReaderClosed()
{
    RLOGI("AT channel closed\n");
    at_close();
    s_closed = 1;

    setRadioState (RADIO_STATE_UNAVAILABLE);
}
示例#10
0
void closePPPDataChannel()
{
    RILChannelCtx* p_channel = &g_pppDataChannel;
    RLOGI("closeDataChannel [%d, %d]", g_channelIndex, p_channel->fd);
    if (p_channel->fd >= 0) {
        close(p_channel->fd);
    }
    p_channel->fd = -1;
}
示例#11
0
/* Called on command or reader thread */
static void onATReaderClosed(RILChannelCtx *p_channel)
{
    RLOGI("AT channel closed\n");
    at_close(p_channel);
    assert(0);
    s_closed = 1;

    setRadioState (RADIO_STATE_UNAVAILABLE, getRILIdByChannelCtx(p_channel));
}
示例#12
0
                    /*if(chmod(path, 0666) < 0 )
                    {
                        RLOGD("chomod: system-error: '%s' (code: %d)", strerror(errno), errno);
                        return NULL;
                    }*/
                    if(symlink(path, s_mux_path[i]) < 0)
                    {
                        RLOGD("symlink: system-error: '%s' (code: %d)", strerror(errno), errno);
                        return NULL;
                    }
                    ttys_index++;
                    i++;
                }
                break;
            #endif

            default:
                usage(argv[0]);
                return NULL;
        }
		
    }
	RLOGI("while out %s\n", s_device_path);
    if (s_port < 0 && s_device_path == NULL && 
        (s_device_range_begin < 0 || s_device_range_end < 0) ) {
        usage(argv[0]);
        return NULL;
    }

    pthread_attr_init (&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
//	if (is_gemini_emulator){
	//	  ret = pthread_create(&s_tid_mainloop, &attr, mainLoop_emulator, NULL);
		//}else{
 		ret = pthread_create(&s_tid_mainloop, &attr, mainLoop, NULL);
//	}
  

    return &s_callbacks;
}
#else /* RIL_SHLIB */
int main (int argc, char **argv)
{
    int ret;
    int fd = -1;
    int opt;

    while ( -1 != (opt = getopt(argc, argv, "p:d:"))) {
	
        switch (opt) {
            case 'p':
                s_port = atoi(optarg);
                if (s_port == 0) {
                    usage(argv[0]);
                }
                RLOGI("Opening loopback port %d\n", s_port);
            break;

            case 'd':
                s_device_path = optarg;
                RLOGI("Opening tty device %s\n", s_device_path);
            break;

            case 's':
                s_device_path   = optarg;
                s_device_socket = 1;
                RLOGI("Opening socket %s\n", s_device_path);
            break;

            default:
                usage(argv[0]);
        }
    }

    if (s_port < 0 && s_device_path == NULL) {
        usage(argv[0]);
    }

    RIL_register(&s_callbacks);

    mainLoop(NULL);

    return 0;
}
示例#13
0
/* Called on command thread */
static void onATTimeout()
{
    RLOGI("AT channel timeout; closing\n");
    at_close();

    s_closed = 1;

    /* FIXME cause a radio reset here */

    setRadioState (RADIO_STATE_UNAVAILABLE);
}
Resource platformLoadResource(const char* path)
{
	RLOGI("Opening resource %s", path);
	auto externalPath = path::buildPath(gApp->activity->externalDataPath, path);
	auto file = fopen(externalPath.c_str(), "r+");
	if(file == 0)
	{
		RLOGI("File is not external %s", path);
		return platformLoadInternalResource(path);
	}

	fseek( file, 0L, SEEK_END);
	auto length = ftell(file);
	rewind(file);
	auto buffer = new uint8_t[length];
	fread(buffer, length, 1, file);
	fclose(file);

	return (Resource) { buffer, (uint32_t)length };
}
示例#15
0
/* Called on command thread */
static void onATTimeout(RILChannelCtx *p_channel)
{
    RLOGI("AT channel timeout; closing\n");
    at_close(p_channel);
    assert(0);
    s_closed = 1;

    /* FIXME cause a radio reset here */

    setRadioState (RADIO_STATE_UNAVAILABLE, getRILIdByChannelCtx(p_channel));
}
示例#16
0
void closeDataChannel(RILChannelCtx* p_channel)
{
    if (p_channel == NULL) {
        RLOGE("closeDataChannel invalid input argument");
        return;
    }

    RLOGI("closeDataChannel [%d, %d]", p_channel->id, p_channel->fd);
    if (p_channel->fd >= 0) {
        close(p_channel->fd);
    }
    p_channel->fd = -1;
}
Resource platformLoadAbsolutePath(const char* resourcePath)
{
    auto file = fopen(resourcePath, "r+");
    ASSERTF(file != 0, "Couldn't open file. %s", resourcePath);
    fseek( file, 0L, SEEK_END);
    auto length = ftell(file);
    rewind(file);
    auto buffer = new uint8_t[length];
    fread(buffer, length, 1, file);
    fclose(file);
    RLOGI("%s", "Successfully loaded!");
    return (Resource){ buffer, (uint32_t)length };
}
示例#18
0
static void *readerLoop(void *arg)
{
	RILChannelCtx *p_channel = (RILChannelCtx *)arg;
	const char *readerName = p_channel->myName;

	RLOGI("%s is up", readerName);


	for (;; ) {
		const char *line;

		line = readline(p_channel);

		RLOGD("%s:%s", readerName, line);

		if (line == NULL)
			break;

		if (isSMSUnsolicited(line)) {
			char *line1;
			const char *line2;
			RLOGD("SMS Urc Received!");
			// The scope of string returned by 'readline()' is valid only
			// till next call to 'readline()' hence making a copy of line
			// before calling readline again.
			line1 = strdup(line);
			line2 = readline(p_channel);

			if (line2 == NULL) {
				RLOGE("NULL line found in %s", readerName);
				break;
			}

			if (p_channel->unsolHandler != NULL) {
				RLOGD("%s: line1:%s,line2:%s", readerName, line1, line2);
				p_channel->unsolHandler(line1, line2, p_channel);
			}
			free(line1);
		} else {
			pthread_mutex_lock(&p_channel->commandmutex);
			RLOGD("%s Enter processLine", readerName);
			processLine(line, p_channel);
			pthread_mutex_unlock(&p_channel->commandmutex);
		}
	}
	RLOGE("%s Closed", readerName);
	onReaderClosed(p_channel);

	return NULL;
}
示例#19
0
/**
 * Called by atchannel when an unsolicited line appears
 * This is called on atchannel's reader thread. AT commands may
 * not be issued here
 */
static void onUnsolicited (const char *s, const char *sms_pdu, void * pChannel)
{
RLOGI("[Emu]get in onUnsolicited");
RLOGI("[Emu]command %s",s);
    char *line = NULL;
    int err;
    RIL_RadioState radioState = sState;
    RILChannelCtx * p_channel = (RILChannelCtx *) pChannel;

#ifdef MTK_GEMINI
    if (MTK_RIL_SOCKET_2 == getRILIdByChannelCtx(p_channel)) {
        radioState = sState2;
		RLOGI("[Emu]state2");
    }
#endif 

    /* Ignore unsolicited responses until we're initialized.
     * This is OK because the RIL library will poll for initial state
     */
    if (radioState == RADIO_STATE_UNAVAILABLE) {
        return;
    }

    if (!(rilNwUnsolicited(s,sms_pdu,p_channel) ||
          rilCcUnsolicited(s,sms_pdu, p_channel) ||
          rilSsUnsolicited(s,sms_pdu, p_channel) ||
          rilSmsUnsolicited(s,sms_pdu, p_channel) ||
          rilStkUnsolicited(s,sms_pdu, p_channel) ||
          rilOemUnsolicited(s,sms_pdu, p_channel) ||
          rilDataUnsolicited(s,sms_pdu, p_channel)||
          rilSimUnsolicited(s,sms_pdu, p_channel))
    ) {

        RLOGE("Unhandled unsolicited result code: %s\n", s);

    }
}
Resource platformLoadInternalResource(const char* path)
{
    RLOGI("Trying to internal load file %s", path);
	auto mgr  = gApp->activity->assetManager;
	auto asset = AAssetManager_open(mgr, path, AASSET_MODE_RANDOM);
	ASSERTF(asset != 0, "The asset %s does not exist", path);

	auto length = AAsset_getLength(asset);
	auto buffer = new uint8_t[length];
	auto err = AAsset_read(asset, buffer, length);

	ASSERTF(err >= 0, "Failed to load internal resource %s. Error was: %d", path, err);
	AAsset_close(asset);

	return (Resource){ buffer, (uint32_t)length };
}
示例#21
0
/**
 * Sends string s to the radio with a \r appended.
 * Returns AT_ERROR_* on error, 0 on success
 *
 * This function exists because as of writing, android libc does not
 * have buffered stdio.
 */
static int writeline(const char *s, RILChannelCtx *p_channel)
{
	size_t cur = 0;
	size_t len = strlen(s);
	ssize_t written;

	if (p_channel->fd < 0 || p_channel->readerClosed > 0)
		return AT_ERROR_CHANNEL_CLOSED;

	RLOGD("AT> %s\n", s);

	AT_DUMP(">> ", s, strlen(s));

	/* the main string */
	while (cur < len) {
		do{
            RLOGI("AT write start\n");
			written = write(p_channel->fd, s + cur, len - cur);
		}while (written < 0 && errno == EINTR);

		if (written < 0)
			return AT_ERROR_GENERIC;

		cur += written;
	}

	/* the \r  */
	do {
		written = write(p_channel->fd, "\r", 1);
	} while ((written < 0 && errno == EINTR) || (written == 0));

	if (written < 0)
		return AT_ERROR_GENERIC;

	return 0;
}
示例#22
0
void gameInitialize(uint32_t screenWidth, uint32_t screenHeight) {
	if (gGame)
		return;
	Profile profile("Game initialize");

	remoteDebugStart(platformDeviceName());

	gGame = new Game();
	gGame->clock = new Clock();
	clockStart(gGame->clock);
	gGame->sensor = new SensorState();
	gGame->screen = new Screen();
	gGame->screen->width = screenWidth;
	gGame->screen->height = screenHeight;
	gGame->fps = 60;

	RLOGI("%s", "Initializing Game!");
	gGame->L = luaCoreCreate();
	if(hasStarted)
		gameRestart();
	else
		gameStart();

}
示例#23
0
static void *
mainLoop(void *param)
{
    int fd;
    int ret;
    char path[50];
    int ttys_index;

    AT_DUMP("== ", "entering mainLoop()", -1 );
    at_set_on_reader_closed(onATReaderClosed);
    at_set_on_timeout(onATTimeout);

    for (;;) {
        fd = -1;
        while  (fd < 0) {
            if (s_port > 0) {
                fd = socket_loopback_client(s_port, SOCK_STREAM);
            } else if (s_device_socket) {
                if (!strcmp(s_device_path, "/dev/socket/qemud")) {
                    /* Qemu-specific control socket */
                    fd = socket_local_client( "qemud",
                                              ANDROID_SOCKET_NAMESPACE_RESERVED,
                                              SOCK_STREAM );
                    if (fd >= 0 ) {
                        char  answer[2];

                        if ( write(fd, "gsm", 3) != 3 ||
                             read(fd, answer, 2) != 2 ||
                             memcmp(answer, "OK", 2) != 0)
                        {
                            close(fd);
                            fd = -1;
                        }
                   }
                }
                else
                    fd = socket_local_client( s_device_path,
                                            ANDROID_SOCKET_NAMESPACE_FILESYSTEM,
                                            SOCK_STREAM );
            } else if (s_device_path != NULL) {
                fd = open (s_device_path, O_RDWR);
                if ( fd >= 0 && !memcmp( s_device_path, "/dev/ttyS", 9 ) ) {
                    /* disable echo on serial ports */
                    struct termios  ios;
                    tcgetattr( fd, &ios );
                    ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
                    ios.c_iflag = 0;
                    tcsetattr( fd, TCSANOW, &ios );
                }
            }
   

            if (fd < 0) {
                perror ("opening AT interface. retrying...");
                sleep(10);
                /* never returns */
            }
        }

        RLOGD("FD: %d", fd);

        s_closed = 0;
        ret = at_open(fd, onUnsolicited);

        if (ret < 0) {
            RLOGE ("AT error %d on at_open\n", ret);
            return 0;
        }

        RIL_requestTimedCallback(initializeCallback, NULL, &TIMEVAL_0);

        // Give initializeCallback a chance to dispatched, since
        // we don't presently have a cancellation mechanism
        sleep(1);

        waitForClose();
        RLOGI("Re-opening after close");
    }
}
示例#24
0
static void gameStart() {
	RLOGI("%s", "Starting game!");
	hasStarted = true;
	luaStartCall(gGame->L);
	nice(1000000);
}
示例#25
0
static void gameRestart() {
	RLOGI("%s", "Restarting game!");
	luaRestartCall(gGame->L);
}
示例#26
0
static void emulator_gemini_opensocket()
{
	int fd;
    		int ret;
		for (;;) {
       		 fd = -1;
			RLOGI("[Emu]emulator_gemini_opensocket_in\n");
			
			RLOGI("[Emu]s_device_socket %d\n",s_device_socket);
			RLOGI("[Emu]s_port %d\n",s_port);
			 while  (fd < 0) {
           			 if (s_port > 0) {
            			    fd = socket_loopback_client(s_port, SOCK_STREAM);
							RLOGI("[Emu]fd1 %d\n",fd);
          			  } else if (s_device_socket) {
            				    if (!strcmp(s_device_path, "/dev/socket/qemud")) {
	                			    /* Qemu-specific control socket */
	             			           fd = socket_local_client( "qemud",
	                                              ANDROID_SOCKET_NAMESPACE_RESERVED,
	                                              SOCK_STREAM );
								RLOGI("[Emu]fd2 %d\n",fd);	
	                 			   if (fd >= 0 ) {
	                 		         	   char  answer[2];

				                        if ( write(fd, "gsm", 3) != 3 ||
				                             read(fd, answer, 2) != 2 ||
				                             memcmp(answer, "OK", 2) != 0)
				                        {
				                            close(fd);
				                            fd = -1;
				                        }
                  		 	 	 }
		            	 	   }
		                	   else {
						  fd = socket_local_client( s_device_path,
                                            ANDROID_SOCKET_NAMESPACE_FILESYSTEM,
                                            SOCK_STREAM );
						}
							   RLOGI("[Emu]fd3 %d\n",fd);
                   			
            				} else if (s_device_path != NULL) {
                				fd = open (s_device_path, O_RDWR);
               				 if ( fd >= 0 && !memcmp( s_device_path, "/dev/ttyS", 9 ) ) {
				                 	/* disable echo on serial ports */
				                    struct termios  ios;
				                    tcgetattr( fd, &ios );
				                    ios.c_lflag = 0;  /* disable ECHO, ICANON, etc... */
							  ios.c_iflag = 0;		
				                    tcsetattr( fd, TCSANOW, &ios );
				                }
							 RLOGI("[Emu]fd4 %d\n",fd);
			            }

			            if (fd < 0) {
							 RLOGI("[Emu]fd<0");
			                perror ("opening AT interface. retrying...");
			                sleep(10);
			                /* never returns */
			            }
       		 }

		        s_closed = 0;
		        ret = at_open_emulator(fd, onUnsolicited,is_gemini_emulator);

		        if (ret < 0) {
		            RLOGE ("AT error %d on at_open\n", ret);
		            return 0;
		        }
			RLOGI("[Emu]RIL_requestTimedCallback");
			RIL_requestTimedCallback(initializeCallback, &s_pollSimId, &TIMEVAL_0);
#ifdef MTK_GEMINI
			RIL_requestTimedCallback(initializeCallback, &s_pollSimId2, &TIMEVAL_0);
#endif 
				RLOGI("[Emu]RIL_requestTimedCallback out");
			// Give initializeCallback a chance to dispatched, since
			// we don't presently have a cancellation mechanism
			sleep(1);
			
			waitForClose();
			RLOGI("Re-opening after close");

		}
}
示例#27
0
static void initializeCallback(void *param)
{
	RLOGE ("[Emu]get in initializeCallback");
    ATResponse *p_response = NULL;
    int err;
    RILId rid = *((RILId *)param);

	char property_value[5] = { 0 };
    int current_share_modem = 0;

    current_share_modem = MTK_SHARE_MODEM_CURRENT;

    setRadioState (RADIO_STATE_OFF,rid);

    err = at_handshake(getDefaultChannelCtx(rid));

    RLOGI("AT handshake: %d",err);

    /* note: we don't check errors here. Everything important will
       be handled in onATTimeout and onATReaderClosed */

    /*  atchannel is tolerant of echo but it must */
    /*  have verbose result codes */
    at_send_command("ATE0Q0V1", NULL, getDefaultChannelCtx(rid));

    /*  No auto-answer */
    at_send_command("ATS0=0", NULL,getDefaultChannelCtx(rid));

    /*  Extended errors */
    at_send_command("AT+CMEE=1", NULL, getDefaultChannelCtx(rid));

    /*  Network registration events */
    err = at_send_command("AT+CREG=2", &p_response, getDefaultChannelCtx(rid));

    /* some handsets -- in tethered mode -- don't support CREG=2 */
    if (err < 0 || p_response->success == 0) {
        at_send_command("AT+CREG=1", NULL, getDefaultChannelCtx(rid));
    }

    at_response_free(p_response);

    /*  GPRS registration events */
    at_send_command("AT+CGREG=1", NULL, getDefaultChannelCtx(rid));

    /*  Call Waiting notifications */
    at_send_command("AT+CCWA=1", NULL, getDefaultChannelCtx(rid));
//[Emu]TODO diff
    /*  mtk00924: enable Call Progress notifications */
    at_send_command("AT+ECPI=4294967295", NULL, getDefaultChannelCtx(rid));

    /*  Alternating voice/data off */
    /*
    at_send_command("AT+CMOD=0", NULL, getDefaultChannelCtx(rid));
    */

    /*  Not muted */
    /*
    at_send_command("AT+CMUT=0", NULL, getDefaultChannelCtx(rid));
    */
    
//[Emu]TODO diff
    /*  +CSSU unsolicited supp service notifications */
    at_send_command("AT+CSSN=1,1", NULL, getDefaultChannelCtx(rid));
//[Emu]TODO diff
    /*  connected line identification on */
    at_send_command("AT+COLP=1", NULL, getDefaultChannelCtx(rid));
//[Emu]TODO diff
    /*  HEX character set */
    at_send_command("AT+CSCS=\"UCS2\"", NULL, getDefaultChannelCtx(rid));

    /*  USSD unsolicited */
    at_send_command("AT+CUSD=1", NULL, getDefaultChannelCtx(rid));

    /*  Enable +CGEV GPRS event notifications, but don't buffer */
    at_send_command("AT+CGEREP=1,0", NULL, getDefaultChannelCtx(rid));

    /*  SMS PDU mode */
    at_send_command("AT+CMGF=0", NULL, getDefaultChannelCtx(rid));

    /* Initial CID table */
    initialCidTable();

//[Emu]TODO diff
    /* Enable getting NITZ, include TZ and Operator Name*/
    /* To Receive +CIEV: 9 and +CIEV: 10*/
//[Emu]TODO_1_ changed
  //  at_send_command("AT+CTZR=1", NULL, getDefaultChannelCtx(rid));
//[Emu]TODO diff
    /*  Enable getting CFU info +ECFU and speech info +ESPEECH*/
//    at_send_command("AT+EINFO=114", NULL, getDefaultChannelCtx(rid));
//[Emu]TODO diff
    /*  Enable get ECSQ URC */
    //at_send_command("AT+ECSQ=2", NULL, getDefaultChannelCtx(rid));
//[Emu]TODO diff
    /*  Enable get +CIEV:7 URC to receive SMS SIM Storage Status*/
   // at_send_command("AT+CMER=1,0,0,2,0", NULL, getDefaultChannelCtx(rid));
//[Emu]TODO diff
#ifdef MTK_VT3G324M_SUPPORT
    at_send_command("AT+CRC=1", NULL, getDefaultChannelCtx(rid));
#endif
#ifdef MTK_GEMINI
    requestSimReset(rid);

	RLOGD("start rild bootup flow [%d, %d, %d, %d]", isDualTalkMode(), rid, RIL_is3GSwitched(), current_share_modem);
	if (isDualTalkMode()) {
		if (rid == MTK_RIL_SOCKET_1) {
			flightModeBoot();
			bootupGetIccid(rid); //query ICCID after AT+ESIMS
			bootupGetImei(rid);
			bootupGetImeisv(rid);
			bootupGetBasebandVersion(rid);
            bootupGetCalData(rid);			
			RLOGD("get SIM inserted status (DT) [%d]", sim_inserted_status);
			RIL_onUnsolicitedResponse(RIL_UNSOL_SIM_INSERTED_STATUS, &sim_inserted_status, sizeof(int), rid);
		}
	} else {
		if (current_share_modem == 1) {
			if (rid == MTK_RIL_SOCKET_1) {
				flightModeBoot();
				bootupGetIccid(rid); //query ICCID after AT+ESIMS
				bootupGetImei(rid);
				bootupGetImeisv(rid);
				bootupGetBasebandVersion(rid);
                bootupGetCalData(rid);											
				RLOGD("get SIM inserted status (Single) [%d]", sim_inserted_status);
				RIL_onUnsolicitedResponse(RIL_UNSOL_SIM_INSERTED_STATUS, &sim_inserted_status, sizeof(int), rid);
			}
		} else if (rid == MTK_RIL_SOCKET_2) {
			flightModeBoot();
			bootupGetIccid(MTK_RIL_SOCKET_1);
			bootupGetIccid(MTK_RIL_SOCKET_2);
			bootupGetImei(MTK_RIL_SOCKET_1);
			bootupGetImei(MTK_RIL_SOCKET_2);
			bootupGetImeisv(MTK_RIL_SOCKET_1);
			bootupGetImeisv(MTK_RIL_SOCKET_2);
			bootupGetBasebandVersion(MTK_RIL_SOCKET_1);
			bootupGetBasebandVersion(MTK_RIL_SOCKET_2);
            bootupGetCalData(MTK_RIL_SOCKET_1);						
			RLOGD("get SIM inserted status [%d]", sim_inserted_status);
			RIL_onUnsolicitedResponse(RIL_UNSOL_SIM_INSERTED_STATUS, &sim_inserted_status, sizeof(int), rid);
		}
	}
#else
	flightModeBoot();
	bootupGetIccid(rid);
	bootupGetImei(rid);
	bootupGetImeisv(rid);
	bootupGetBasebandVersion(rid);
        bootupGetCalData(rid);	
#endif  /* MTK_GEMINI */

//[Emu]TODO diff
    /* assume radio is off on error */
    if (isRadioOn(rid) > 0) {
        setRadioState (RADIO_STATE_SIM_NOT_READY,rid);
    }
}
Resource platformLoadExternalResource(const char* path)
{
    RLOGI("Trying to external load file %s", path);
	auto resourcePath = path::buildPath(gApp->activity->externalDataPath, path);
	return platformLoadAbsolutePath(resourcePath.c_str());
}
示例#29
0
/**
 * Reads a line from the AT channel, returns NULL on timeout.
 * Assumes it has exclusive read access to the FD
 *
 * This line is valid only until the next call to readline
 *
 * This function exists because as of writing, android libc does not
 * have buffered stdio.
 */
static const char *readline(RILChannelCtx *p_channel)
{
	ssize_t count;

	char *p_read = NULL;
	char *p_eol = NULL;
	char *ret;

	/* this is a little odd. I use *s_ATBufferCur == 0 to
	 * mean "buffer consumed completely". If it points to a character, than
	 * the buffer continues until a \0
	 */
	if (*p_channel->ATBufferCur == '\0') {
		/* empty buffer */
		p_channel->ATBufferCur = p_channel->ATBuffer;
		*p_channel->ATBufferCur = '\0';
		p_read = p_channel->ATBuffer;
	} else { /* *s_ATBufferCur != '\0' */
		/* there's data in the buffer from the last read */

		// skip over leading newlines
		while (*p_channel->ATBufferCur == '\r' || *p_channel->ATBufferCur == '\n')
			p_channel->ATBufferCur++;

		p_eol = findNextEOL(p_channel->ATBufferCur);

		if (p_eol == NULL) {
			/* a partial line. move it up and prepare to read more */
			size_t len;

			len = strlen(p_channel->ATBufferCur);

			memmove(p_channel->ATBuffer, p_channel->ATBufferCur, len + 1);
			p_read = p_channel->ATBuffer + len;
			p_channel->ATBufferCur = p_channel->ATBuffer;
		}
		/* Otherwise, (p_eol !- NULL) there is a complete line  */
		/* that will be returned the while () loop below        */
	}

	while (p_eol == NULL) {
		if (0 == MAX_AT_RESPONSE - (p_read - p_channel->ATBuffer)) {
			RLOGE("ERROR: Input line exceeded buffer\n");
			/* ditch buffer and start over again */
			p_channel->ATBufferCur = p_channel->ATBuffer;
			*p_channel->ATBufferCur = '\0';
			p_read = p_channel->ATBuffer;
		}

    do{
        RLOGI("AT read start\n");
		count = read(p_channel->fd, p_read, MAX_AT_RESPONSE - (p_read - p_channel->ATBuffer));
        RLOGI("AT read end: %d:%s\n", count, strerror(errno));
    }while (count < 0 && errno == EINTR);

		if (count > 0) {
			AT_DUMP("<< ", p_read, count);
			p_channel->readCount += count;

			p_read[count] = '\0';


			// skip over leading newlines
			while (*p_channel->ATBufferCur == '\r' || *p_channel->ATBufferCur == '\n')
				p_channel->ATBufferCur++;

			p_eol = findNextEOL(p_channel->ATBufferCur);
			p_read += count;
		} else if (count <= 0) {
			/* read error encountered or EOF reached */
			if (count == 0)
				RLOGD("atchannel: EOF reached");
			else
				RLOGD("atchannel: read error %s", strerror(errno));
			return NULL;
		}
	}

	/* a full line in the buffer. Place a \0 over the \r and return */

	ret = p_channel->ATBufferCur;
	*p_eol = '\0';
    if (p_channel->ATBufferCur[0] == '>' && p_channel->ATBufferCur[1] == ' ' && p_channel->ATBufferCur[2] == '\0') {
        RLOGD("atchannel: This is sms prompt!");
        p_channel->ATBufferCur = p_eol + 1; /* this will always be <= p_read,    */
        p_channel->ATBufferCur[0] = '\0';
    } else {
        p_channel->ATBufferCur = p_eol + 1; /* this will always be <= p_read,    */
    }
    /* and there will be a \0 at *p_read */

	RLOGD("AT< %s\n", ret);
	return ret;
}
示例#30
0
static void *
mainLoop(void *param)
{
    AT_DUMP("== ", "entering mainLoop()", -1 );
    at_set_on_reader_closed(onATReaderClosed);
    at_set_on_timeout(onATTimeout);
    initRILChannels();
	RLOGI("[Emu]mainloop_in");
	RLOGI("[Emu]mainloop_in %d\n",s_device_socket);
	if(s_device_socket)
		{
		emulator_gemini_opensocket();
		return NULL;
	}
	else
		{
		int ret;
	       int i;
	    	RILChannelCtx * p_channel;
	
	    	for (;;) {

		        for (i=0; i < RIL_SUPPORT_CHANNELS; i ++)
		        {
		            p_channel = getChannelCtxbyId(i);

		            while (p_channel->fd < 0)
		            {
		                do {
		                    p_channel->fd = open(s_mux_path[i], O_RDWR);
		                } while (p_channel->fd < 0 && errno == EINTR);
		                
		                if (p_channel->fd < 0) 
		                {
		                    perror ("opening AT interface. retrying...");
		                    RLOGE("could not connect to %s: %s",  s_mux_path[i], strerror(errno));
		                    sleep(10);
		                    /* 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 );
		                }
		            }
		            
		            
		            s_closed = 0;
		            ret = at_open(p_channel->fd,onUnsolicited, p_channel);
		            
		            
		            if (ret < 0) {
		                RLOGE ("AT error %d on at_open\n", ret);
		                return 0;
		            }
	      		  }

		        RIL_requestTimedCallback(initializeCallback, &s_pollSimId, &TIMEVAL_0);
#ifdef MTK_GEMINI
		        RIL_requestTimedCallback(initializeCallback, &s_pollSimId2, &TIMEVAL_0);
#endif 

		        // Give initializeCallback a chance to dispatched, since
		        // we don't presently have a cancellation mechanism
		        sleep(1);

		        waitForClose();
		        RLOGI("Re-opening after close");
		}
   	 }
	
}