Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
    assert(argc-1 == 1);
    const char *devpath = argv[1];

    printf("allocating channel...\n");
    struct at *at = at_alloc_unix(devpath, B115200);

    printf("opening port...\n");
    assert(at_open(at) == 0);

    printf("attaching callbacks\n");
    at_set_callbacks(at, &generic_modem_callbacks, NULL);

    const char *commands[] = {
        "AT",
        "ATE0",
        "AT+CGMR",
        "AT+CGSN",
        "AT+CCID",
        "AT+CMEE=0",
        "AT+BLAH",
        "AT+CMEE=2",
        "AT+BLAH",
        NULL
    };

    printf("sending commands...\n");
    at_set_timeout(at, 10);
    for (const char **command=commands; *command; command++) {
        const char *result = at_command(at, *command);
        printf("%s => %s\n", *command, result ? result : strerror(errno));
    }

    printf("freeing resources...\n");
    at_free(at);

    return 0;
}
Ejemplo n.º 2
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");
    }
}
Ejemplo n.º 3
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");
		}
   	 }
	
}