OSDN Git Service

DO NOT MERGE
[android-x86/hardware-ril.git] / reference-ril / atchannel.c
index 5e7a1c1..2ef3a4c 100644 (file)
 #define LOG_TAG "AT"
 #include <utils/Log.h>
 
-#ifdef HAVE_ANDROID_OS
-/* for IOCTL's */
-#include <linux/omap_csmi.h>
-#endif /*HAVE_ANDROID_OS*/
-
 #include "misc.h"
 
-#ifdef HAVE_ANDROID_OS
-#define USE_NP 1
-#endif /* HAVE_ANDROID_OS */
-
 
 #define NUM_ELEMS(x) (sizeof(x)/sizeof(x[0]))
 
@@ -60,16 +51,12 @@ static ATUnsolHandler s_unsolHandler;
 static char s_ATBuffer[MAX_AT_RESPONSE+1];
 static char *s_ATBufferCur = s_ATBuffer;
 
-static int s_ackPowerIoctl; /* true if TTY has android byte-count
-                                handshake for low power*/
-static int s_readCount = 0;
-
 #if AT_DEBUG
 void  AT_DUMP(const char*  prefix, const char*  buff, int  len)
 {
     if (len < 0)
         len = strlen(buff);
-    ALOGD("%.*s", len, buff);
+    RLOGD("%.*s", len, buff);
 }
 #endif
 
@@ -94,20 +81,21 @@ static void onReaderClosed();
 static int writeCtrlZ (const char *s);
 static int writeline (const char *s);
 
-#ifndef USE_NP
+#define NS_PER_S 1000000000
 static void setTimespecRelative(struct timespec *p_ts, long long msec)
 {
     struct timeval tv;
 
     gettimeofday(&tv, (struct timezone *) NULL);
 
-    /* what's really funny about this is that I know
-       pthread_cond_timedwait just turns around and makes this
-       a relative time again */
     p_ts->tv_sec = tv.tv_sec + (msec / 1000);
     p_ts->tv_nsec = (tv.tv_usec + (msec % 1000) * 1000L ) * 1000L;
+    /* assuming tv.tv_usec < 10^6 */
+    if (p_ts->tv_nsec >= NS_PER_S) {
+        p_ts->tv_sec++;
+        p_ts->tv_nsec -= NS_PER_S;
+    }
 }
-#endif /*USE_NP*/
 
 static void sleepMsec(long long msec)
 {
@@ -290,7 +278,7 @@ static void processLine(const char *line)
         break;
 
         default: /* this should never be reached */
-            ALOGE("Unsupported AT command type %d\n", s_type);
+            RLOGE("Unsupported AT command type %d\n", s_type);
             handleUnsolicited(line);
         break;
     }
@@ -371,7 +359,7 @@ static const char *readline()
 
     while (p_eol == NULL) {
         if (0 == MAX_AT_RESPONSE - (p_read - s_ATBuffer)) {
-            ALOGE("ERROR: Input line exceeded buffer\n");
+            RLOGE("ERROR: Input line exceeded buffer\n");
             /* ditch buffer and start over again */
             s_ATBufferCur = s_ATBuffer;
             *s_ATBufferCur = '\0';
@@ -385,7 +373,6 @@ static const char *readline()
 
         if (count > 0) {
             AT_DUMP( "<< ", p_read, count );
-            s_readCount += count;
 
             p_read[count] = '\0';
 
@@ -398,9 +385,9 @@ static const char *readline()
         } else if (count <= 0) {
             /* read error encountered or EOF reached */
             if(count == 0) {
-                ALOGD("atchannel: EOF reached");
+                RLOGD("atchannel: EOF reached");
             } else {
-                ALOGD("atchannel: read error %s", strerror(errno));
+                RLOGD("atchannel: read error %s", strerror(errno));
             }
             return NULL;
         }
@@ -413,7 +400,7 @@ static const char *readline()
     s_ATBufferCur = p_eol + 1; /* this will always be <= p_read,    */
                               /* and there will be a \0 at *p_read */
 
-    ALOGD("AT< %s\n", ret);
+    RLOGD("AT< %s\n", ret);
     return ret;
 }
 
@@ -435,7 +422,7 @@ static void onReaderClosed()
 }
 
 
-static void *readerLoop(void *arg)
+static void *readerLoop(void *arg __unused)
 {
     for (;;) {
         const char * line;
@@ -457,6 +444,7 @@ static void *readerLoop(void *arg)
             line2 = readline();
 
             if (line2 == NULL) {
+                free(line1);
                 break;
             }
 
@@ -467,14 +455,6 @@ static void *readerLoop(void *arg)
         } else {
             processLine(line);
         }
-
-#ifdef HAVE_ANDROID_OS
-        if (s_ackPowerIoctl > 0) {
-            /* acknowledge that bytes have been read and processed */
-            ioctl(s_fd, OMAP_CSMI_TTY_ACK, &s_readCount);
-            s_readCount = 0;
-        }
-#endif /*HAVE_ANDROID_OS*/
     }
 
     onReaderClosed();
@@ -499,7 +479,7 @@ static int writeline (const char *s)
         return AT_ERROR_CHANNEL_CLOSED;
     }
 
-    ALOGD("AT> %s\n", s);
+    RLOGD("AT> %s\n", s);
 
     AT_DUMP( ">> ", s, strlen(s) );
 
@@ -538,7 +518,7 @@ static int writeCtrlZ (const char *s)
         return AT_ERROR_CHANNEL_CLOSED;
     }
 
-    ALOGD("AT> %s^Z\n", s);
+    RLOGD("AT> %s^Z\n", s);
 
     AT_DUMP( ">* ", s, strlen(s) );
 
@@ -598,40 +578,6 @@ int at_open(int fd, ATUnsolHandler h)
     s_smsPDU = NULL;
     sp_response = NULL;
 
-    /* Android power control ioctl */
-#ifdef HAVE_ANDROID_OS
-#ifdef OMAP_CSMI_POWER_CONTROL
-    ret = ioctl(fd, OMAP_CSMI_TTY_ENABLE_ACK);
-    if(ret == 0) {
-        int ack_count;
-               int read_count;
-        int old_flags;
-        char sync_buf[256];
-        old_flags = fcntl(fd, F_GETFL, 0);
-        fcntl(fd, F_SETFL, old_flags | O_NONBLOCK);
-        do {
-            ioctl(fd, OMAP_CSMI_TTY_READ_UNACKED, &ack_count);
-                       read_count = 0;
-            do {
-                ret = read(fd, sync_buf, sizeof(sync_buf));
-                               if(ret > 0)
-                                       read_count += ret;
-            } while(ret > 0 || (ret < 0 && errno == EINTR));
-            ioctl(fd, OMAP_CSMI_TTY_ACK, &ack_count);
-         } while(ack_count > 0 || read_count > 0);
-        fcntl(fd, F_SETFL, old_flags);
-        s_readCount = 0;
-        s_ackPowerIoctl = 1;
-    }
-    else
-        s_ackPowerIoctl = 0;
-
-#else // OMAP_CSMI_POWER_CONTROL
-    s_ackPowerIoctl = 0;
-
-#endif // OMAP_CSMI_POWER_CONTROL
-#endif /*HAVE_ANDROID_OS*/
-
     pthread_attr_init (&attr);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
 
@@ -723,9 +669,7 @@ static int at_send_command_full_nolock (const char *command, ATCommandType type,
                     long long timeoutMsec, ATResponse **pp_outResponse)
 {
     int err = 0;
-#ifndef USE_NP
     struct timespec ts;
-#endif /*USE_NP*/
 
     if(sp_response != NULL) {
         err = AT_ERROR_COMMAND_PENDING;
@@ -743,19 +687,13 @@ static int at_send_command_full_nolock (const char *command, ATCommandType type,
     s_smsPDU = smspdu;
     sp_response = at_response_new();
 
-#ifndef USE_NP
     if (timeoutMsec != 0) {
         setTimespecRelative(&ts, timeoutMsec);
     }
-#endif /*USE_NP*/
 
     while (sp_response->finalResponse == NULL && s_readerClosed == 0) {
         if (timeoutMsec != 0) {
-#ifdef USE_NP
-            err = pthread_cond_timeout_np(&s_commandcond, &s_commandmutex, timeoutMsec);
-#else
             err = pthread_cond_timedwait(&s_commandcond, &s_commandmutex, &ts);
-#endif /*USE_NP*/
         } else {
             err = pthread_cond_wait(&s_commandcond, &s_commandmutex);
         }