Add Multiple AT channels supported for ril api v2
Change-Id: I53f574c85d07bd7b8e0dd15d2e596d23c8772907
diff --git a/mbtk/mbtk_rild_v2/src/atchannel.c b/mbtk/mbtk_rild_v2/src/atchannel.c
index fe96df1..8a19159 100755
--- a/mbtk/mbtk_rild_v2/src/atchannel.c
+++ b/mbtk/mbtk_rild_v2/src/atchannel.c
@@ -38,20 +38,20 @@
#define HANDSHAKE_TIMEOUT_MSEC 500
#define AT_BUFF_MAX 1024
-static pthread_t s_tid_reader;
-static int s_at_fd = -1; /* fd of the AT channel */
+static pthread_t s_tid_reader[ATPORTTYPE_NUM];
+static int s_at_fd[ATPORTTYPE_NUM] = {-1}; /* fd of the AT channel */
static int s_uart_fd = -1; /* fd of the UART channel */
static ATUnsolHandler s_unsolHandler;
/* for input buffering */
-static char s_ATBuffer[MAX_AT_RESPONSE+1];
-static char *s_ATBufferCur = s_ATBuffer;
+static char s_ATBuffer[ATPORTTYPE_NUM][MAX_AT_RESPONSE+1];
+static char *s_ATBufferCur[ATPORTTYPE_NUM] = {s_ATBuffer[ATPORTTYPE_0], s_ATBuffer[ATPORTTYPE_1], s_ATBuffer[ATPORTTYPE_2]};
static char s_UartBuffer[MAX_AT_RESPONSE+1];
static char *s_UartBufferCur = s_UartBuffer;
-static mbtk_ril_at_state_enum at_state = RIL_AT_STATE_CLOSED;
+static mbtk_ril_at_state_enum at_state[ATPORTTYPE_NUM] = {RIL_AT_STATE_CLOSED};
#if AT_DEBUG
void AT_DUMP(const char* prefix, const char* buff, int len)
@@ -72,22 +72,22 @@
*/
// "Wait" when AT process...
-static pthread_mutex_t s_commandmutex = PTHREAD_MUTEX_INITIALIZER;
-static pthread_cond_t s_commandcond = PTHREAD_COND_INITIALIZER;
+static pthread_mutex_t s_commandmutex[ATPORTTYPE_NUM] = {PTHREAD_MUTEX_INITIALIZER};
+static pthread_cond_t s_commandcond[ATPORTTYPE_NUM] = {PTHREAD_COND_INITIALIZER};
-static ATCommandType s_type;
-static const char *s_responsePrefix = NULL;
-static const char *s_smsPDU = NULL;
-static ATResponse *sp_response = NULL;
-static char s_curr_at[AT_BUFF_MAX];
+static ATCommandType s_type[ATPORTTYPE_NUM];
+static const char *s_responsePrefix[ATPORTTYPE_NUM] = {NULL};
+static const char *s_smsPDU[ATPORTTYPE_NUM] = {NULL};
+static ATResponse *sp_response[ATPORTTYPE_NUM] = {NULL};
+static char s_curr_at[ATPORTTYPE_NUM][AT_BUFF_MAX];
static void (*s_onTimeout)(void) = NULL;
static void (*s_onReaderClosed)(void) = NULL;
static int s_readerClosed;
-static void onReaderClosed();
-static int writeCtrlZ (const char *s);
-static int writeline (const char *s);
+static void onReaderClosed(ATPortType_enum port);
+static int writeCtrlZ (ATPortType_enum port, const char *s);
+static int writeline (ATPortType_enum port, const char *s);
typedef struct
{
@@ -137,7 +137,7 @@
/** add an intermediate response to sp_response*/
-static void addIntermediate(const char *line)
+static void addIntermediate(ATPortType_enum port, const char *line)
{
ATLine *p_new;
@@ -151,8 +151,8 @@
/* note: this adds to the head of the list, so the list
will be in reverse order of lines received. the order is flipped
again before passing on to the command issuer */
- p_new->p_next = sp_response->p_intermediates;
- sp_response->p_intermediates = p_new;
+ p_new->p_next = sp_response[port]->p_intermediates;
+ sp_response[port]->p_intermediates = p_new;
}
@@ -170,7 +170,7 @@
"NO ANSWER",
"NO DIALTONE",
};
-static int isFinalResponseError(const char *line)
+static int isFinalResponseError(ATPortType_enum port, const char *line)
{
size_t i;
@@ -182,7 +182,7 @@
}
}
- if(!strncasecmp(s_curr_at, "ATD", 3) && strStartsWith(line, "NO CARRIER"))
+ if(!strncasecmp(s_curr_at[port], "ATD", 3) && strStartsWith(line, "NO CARRIER"))
{
return 1;
}
@@ -220,9 +220,9 @@
* See 27.007 annex B
* WARNING: NO CARRIER and others are sometimes unsolicited
*/
-static int isFinalResponse(const char *line)
+static int isFinalResponse(ATPortType_enum port, const char *line)
{
- return isFinalResponseSuccess(line) || isFinalResponseError(line);
+ return isFinalResponseSuccess(line) || isFinalResponseError(port, line);
}
/**
@@ -252,12 +252,12 @@
/** assumes s_commandmutex is held */
-static void handleFinalResponse(const char *line)
+static void handleFinalResponse(ATPortType_enum port, const char *line)
{
- sp_response->finalResponse = strdup(line);
+ sp_response[port]->finalResponse = strdup(line);
//LOGD("AT complete (pthread_cond_signal): %s",line);
- pthread_cond_signal(&s_commandcond);
+ pthread_cond_signal(&s_commandcond[port]);
}
static void handleUnsolicited(const char *line)
@@ -268,43 +268,43 @@
}
}
-static void processLine(const char *line)
+static void processLine(ATPortType_enum port, const char *line)
{
- pthread_mutex_lock(&s_commandmutex);
+ pthread_mutex_lock(&s_commandmutex[port]);
// LOGD("LINE : %s", line);
- if (sp_response == NULL)
+ if (sp_response[port] == NULL)
{
/* no command pending */
handleUnsolicited(line);
}
else if (isFinalResponseSuccess(line))
{
- sp_response->success = 1;
- handleFinalResponse(line);
+ sp_response[port]->success = 1;
+ handleFinalResponse(port, line);
}
- else if (isFinalResponseError(line))
+ else if (isFinalResponseError(port, line))
{
- sp_response->success = 0;
- handleFinalResponse(line);
+ sp_response[port]->success = 0;
+ handleFinalResponse(port, line);
}
- else if (s_smsPDU != NULL && 0 == strcmp(line, "> "))
+ else if (s_smsPDU[port] != NULL && 0 == strcmp(line, "> "))
{
// See eg. TS 27.005 4.3
// Commands like AT+CMGS have a "> " prompt
- writeCtrlZ(s_smsPDU);
- s_smsPDU = NULL;
+ writeCtrlZ(port, s_smsPDU[port]);
+ s_smsPDU[port] = NULL;
}
- else switch (s_type)
+ else switch (s_type[port])
{
case NO_RESULT:
handleUnsolicited(line);
break;
case NUMERIC:
- if (sp_response->p_intermediates == NULL
+ if (sp_response[port]->p_intermediates == NULL
&& isdigit(line[0])
)
{
- addIntermediate(line);
+ addIntermediate(port, line);
}
else
{
@@ -314,8 +314,8 @@
}
break;
case SINGLELINE:
- if (sp_response->p_intermediates == NULL
- && strStartsWith (line, s_responsePrefix)
+ if (sp_response[port]->p_intermediates == NULL
+ && strStartsWith (line, s_responsePrefix[port])
)
{
if(*line == '"')
@@ -331,12 +331,12 @@
ptr--;
}
}
- addIntermediate(line_temp);
+ addIntermediate(port, line_temp);
free(line_temp);
}
else
{
- addIntermediate(line);
+ addIntermediate(port, line);
}
}
else
@@ -346,9 +346,9 @@
}
break;
case MULTILINE:
- if (strStartsWith (line, s_responsePrefix))
+ if (strStartsWith (line, s_responsePrefix[port]))
{
- addIntermediate(line);
+ addIntermediate(port, line);
}
else
{
@@ -357,12 +357,12 @@
break;
default: /* this should never be reached */
- LOGE("Unsupported AT command type %d\n", s_type);
+ LOGE("Unsupported AT command type %d\n", s_type[port]);
handleUnsolicited(line);
break;
}
- pthread_mutex_unlock(&s_commandmutex);
+ pthread_mutex_unlock(&s_commandmutex[port]);
}
@@ -397,7 +397,7 @@
* have buffered stdio.
*/
-static const char *readline()
+static const char *readline(ATPortType_enum port)
{
ssize_t count;
@@ -409,33 +409,33 @@
* mean "buffer consumed completely". If it points to a character, than
* the buffer continues until a \0
*/
- if (*s_ATBufferCur == '\0')
+ if (*s_ATBufferCur[port] == '\0')
{
/* empty buffer */
- s_ATBufferCur = s_ATBuffer;
- *s_ATBufferCur = '\0';
- p_read = s_ATBuffer;
+ s_ATBufferCur[port] = s_ATBuffer[port];
+ *s_ATBufferCur[port] = '\0';
+ p_read = s_ATBuffer[port];
}
else /* *s_ATBufferCur != '\0' */
{
/* there's data in the buffer from the last read */
// skip over leading newlines
- while (*s_ATBufferCur == '\r' || *s_ATBufferCur == '\n')
- s_ATBufferCur++;
+ while (*s_ATBufferCur[port] == '\r' || *s_ATBufferCur[port] == '\n')
+ s_ATBufferCur[port]++;
- p_eol = findNextEOL(s_ATBufferCur);
+ p_eol = findNextEOL(s_ATBufferCur[port]);
if (p_eol == NULL)
{
/* a partial line. move it up and prepare to read more */
size_t len;
- len = strlen(s_ATBufferCur);
+ len = strlen(s_ATBufferCur[port]);
- memmove(s_ATBuffer, s_ATBufferCur, len + 1);
- p_read = s_ATBuffer + len;
- s_ATBufferCur = s_ATBuffer;
+ memmove(s_ATBuffer[port], s_ATBufferCur[port], len + 1);
+ p_read = s_ATBuffer[port] + len;
+ s_ATBufferCur[port] = s_ATBuffer[port];
}
/* Otherwise, (p_eol !- NULL) there is a complete line */
/* that will be returned the while () loop below */
@@ -443,19 +443,19 @@
while (p_eol == NULL)
{
- if (0 == MAX_AT_RESPONSE - (p_read - s_ATBuffer))
+ if (0 == MAX_AT_RESPONSE - (p_read - s_ATBuffer[port]))
{
LOGE("ERROR: Input line exceeded buffer\n");
/* ditch buffer and start over again */
- s_ATBufferCur = s_ATBuffer;
- *s_ATBufferCur = '\0';
- p_read = s_ATBuffer;
+ s_ATBufferCur[port] = s_ATBuffer[port];
+ *s_ATBufferCur[port] = '\0';
+ p_read = s_ATBuffer[port];
}
do
{
- count = read(s_at_fd, p_read,
- MAX_AT_RESPONSE - (p_read - s_ATBuffer));
+ count = read(s_at_fd[port], p_read,
+ MAX_AT_RESPONSE - (p_read - s_ATBuffer[port]));
usleep(10000);
}
while (count < 0 && errno == EINTR);
@@ -467,10 +467,10 @@
p_read[count] = '\0';
// skip over leading newlines
- while (*s_ATBufferCur == '\r' || *s_ATBufferCur == '\n')
- s_ATBufferCur++;
+ while (*s_ATBufferCur[port] == '\r' || *s_ATBufferCur[port] == '\n')
+ s_ATBufferCur[port]++;
- p_eol = findNextEOL(s_ATBufferCur);
+ p_eol = findNextEOL(s_ATBufferCur[port]);
p_read += count;
}
else if (count <= 0)
@@ -490,9 +490,9 @@
/* a full line in the buffer. Place a \0 over the \r and return */
- ret = s_ATBufferCur;
+ ret = s_ATBufferCur[port];
*p_eol = '\0';
- s_ATBufferCur = p_eol + 1; /* this will always be <= p_read, */
+ s_ATBufferCur[port] = p_eol + 1; /* this will always be <= p_read, */
/* and there will be a \0 at *p_read */
LOGD("AT< %s", ret);
@@ -603,19 +603,19 @@
-static void onReaderClosed()
+static void onReaderClosed(ATPortType_enum port)
{
LOGD("onReaderClosed()");
if (s_onReaderClosed != NULL && s_readerClosed == 0)
{
- pthread_mutex_lock(&s_commandmutex);
+ pthread_mutex_lock(&s_commandmutex[port]);
s_readerClosed = 1;
- pthread_cond_signal(&s_commandcond);
+ pthread_cond_signal(&s_commandcond[port]);
- pthread_mutex_unlock(&s_commandmutex);
+ pthread_mutex_unlock(&s_commandmutex[port]);
s_onReaderClosed();
}
@@ -632,11 +632,12 @@
static void *readerLoop(void *arg)
{
UNUSED(arg);
+ ATPortType_enum *port = (ATPortType_enum*)arg;
for (;;)
{
const char * line;
- line = readline();
+ line = readline(*port);
if (line == NULL)
{
@@ -661,7 +662,7 @@
// till next call to 'readline()' hence making a copy of line
// before calling readline again.
line1 = strdup(line);
- line2 = readline();
+ line2 = readline(*port);
if (line2 == NULL)
{
@@ -677,11 +678,13 @@
}
else
{
- processLine(line);
+ processLine(*port, line);
}
}
- onReaderClosed();
+ onReaderClosed(*port);
+
+ free(port);
return NULL;
}
@@ -689,6 +692,7 @@
static void *readerUrcLoop(void *arg)
{
UNUSED(arg);
+ ATPortType_enum *port = (ATPortType_enum*)arg;
for (;;)
{
const char *line;
@@ -703,7 +707,9 @@
handleUnsolicited(line);
}
- onReaderClosed();
+ onReaderClosed(*port);
+
+ free(port);
return NULL;
}
@@ -716,13 +722,13 @@
* This function exists because as of writing, android libc does not
* have buffered stdio.
*/
-static int writeline (const char *s)
+static int writeline (ATPortType_enum port, const char *s)
{
size_t cur = 0;
size_t len = strlen(s);
ssize_t written;
- if (s_at_fd < 0 || s_readerClosed > 0)
+ if (s_at_fd[port] < 0 || s_readerClosed > 0)
{
return AT_ERROR_CHANNEL_CLOSED;
}
@@ -731,15 +737,15 @@
AT_DUMP( ">> ", s, strlen(s) );
- memset(s_curr_at, 0x0, AT_BUFF_MAX);
- memcpy(s_curr_at, s, strlen(s));
+ memset(s_curr_at[port], 0x0, AT_BUFF_MAX);
+ memcpy(s_curr_at[port], s, strlen(s));
/* the main string */
while (cur < len)
{
do
{
- written = write (s_at_fd, s + cur, len - cur);
+ written = write (s_at_fd[port], s + cur, len - cur);
}
while (written < 0 && errno == EINTR);
@@ -755,7 +761,7 @@
do
{
- written = write (s_at_fd, "\r", 1);
+ written = write (s_at_fd[port], "\r", 1);
}
while ((written < 0 && errno == EINTR) || (written == 0));
@@ -767,13 +773,13 @@
return 0;
}
-static int writeCtrlZ (const char *s)
+static int writeCtrlZ (ATPortType_enum port, const char *s)
{
size_t cur = 0;
size_t len = strlen(s);
ssize_t written;
- if (s_at_fd < 0 || s_readerClosed > 0)
+ if (s_at_fd[port] < 0 || s_readerClosed > 0)
{
return AT_ERROR_CHANNEL_CLOSED;
}
@@ -787,7 +793,7 @@
{
do
{
- written = write (s_at_fd, s + cur, len - cur);
+ written = write (s_at_fd[port], s + cur, len - cur);
}
while (written < 0 && errno == EINTR);
@@ -803,7 +809,7 @@
do
{
- written = write (s_at_fd, "\032", 1);
+ written = write (s_at_fd[port], "\032", 1);
}
while ((written < 0 && errno == EINTR) || (written == 0));
@@ -815,16 +821,16 @@
return 0;
}
-static void clearPendingCommand()
+static void clearPendingCommand(ATPortType_enum port)
{
- if (sp_response != NULL)
+ if (sp_response[port] != NULL)
{
- at_response_free(sp_response);
+ at_response_free(sp_response[port]);
}
- sp_response = NULL;
- s_responsePrefix = NULL;
- s_smsPDU = NULL;
+ sp_response[port] = NULL;
+ s_responsePrefix[port] = NULL;
+ s_smsPDU[port] = NULL;
}
@@ -832,22 +838,27 @@
* Starts AT handler on stream "fd'
* returns 0 on success, -1 on error
*/
-int at_open(int at_fd, int uart_fd, ATUnsolHandler h)
+int at_open(ATPortType_enum port, int at_fd, int uart_fd, ATUnsolHandler h)
{
int ret;
pthread_attr_t attr;
- s_at_fd = at_fd;
+ s_at_fd[port] = at_fd;
s_uart_fd = uart_fd;
s_unsolHandler = h;
s_readerClosed = 0;
- s_responsePrefix = NULL;
- s_smsPDU = NULL;
- sp_response = NULL;
+ s_responsePrefix[port] = NULL;
+ s_smsPDU[port] = NULL;
+ sp_response[port] = NULL;
+
+ ATPortType_enum *at_port_ptr = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
+ ATPortType_enum *urc_port_ptr = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
+ *at_port_ptr = port;
+ *urc_port_ptr = port;
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- ret = pthread_create(&s_tid_reader, &attr, readerLoop, NULL);
+ ret = pthread_create(&s_tid_reader[port], &attr, readerLoop, at_port_ptr);
if (ret < 0)
{
LOGE("AT thread create fail.");
@@ -855,7 +866,7 @@
}
pthread_t uart_tid_reader;
- ret = pthread_create(&uart_tid_reader, &attr, readerUrcLoop, NULL);
+ ret = pthread_create(&uart_tid_reader, &attr, readerUrcLoop, urc_port_ptr);
if (ret < 0)
{
LOGE("Uart thread create fail.");
@@ -866,27 +877,27 @@
}
/* FIXME is it ok to call this from the reader and the command thread? */
-void at_close()
+void at_close(ATPortType_enum port)
{
LOGD("at_close()");
- if (s_at_fd >= 0)
+ if (s_at_fd[port] >= 0)
{
- close(s_at_fd);
+ close(s_at_fd[port]);
}
if (s_uart_fd >= 0)
{
close(s_uart_fd);
}
- s_at_fd = -1;
+ s_at_fd[port] = -1;
s_uart_fd = -1;
- pthread_mutex_lock(&s_commandmutex);
+ pthread_mutex_lock(&s_commandmutex[port]);
s_readerClosed = 1;
- pthread_cond_signal(&s_commandcond);
- pthread_mutex_unlock(&s_commandmutex);
+ pthread_cond_signal(&s_commandcond[port]);
+ pthread_mutex_unlock(&s_commandmutex[port]);
/* the reader thread should eventually die */
- at_state = RIL_AT_STATE_CLOSED;
+ at_state[port] = RIL_AT_STATE_CLOSED;
}
static ATResponse * at_response_new()
@@ -960,33 +971,33 @@
*
* timeoutMsec == 0 means infinite timeout
*/
-static int at_send_command_full_nolock (const char *command, ATCommandType type,
+static int at_send_command_full_nolock (ATPortType_enum port, const char *command, ATCommandType type,
const char *responsePrefix, const char *smspdu,
long long timeoutMsec, ATResponse **pp_outResponse)
{
int err = 0;
bool tiemout_close = true;
struct timespec ts;
- if(at_state == RIL_AT_STATE_READY)
- at_state = RIL_AT_STATE_BUSY;
+ if(at_state[port] == RIL_AT_STATE_READY)
+ at_state[port] = RIL_AT_STATE_BUSY;
- if(sp_response != NULL)
+ if(sp_response[port] != NULL)
{
err = AT_ERROR_COMMAND_PENDING;
goto error;
}
- err = writeline (command);
+ err = writeline (port, command);
if (err < 0)
{
goto error;
}
- s_type = type;
- s_responsePrefix = responsePrefix;
- s_smsPDU = smspdu;
- sp_response = at_response_new();
+ s_type[port] = type;
+ s_responsePrefix[port] = responsePrefix;
+ s_smsPDU[port] = smspdu;
+ sp_response[port] = at_response_new();
if(timeoutMsec == 0)
{
@@ -998,16 +1009,16 @@
setTimespecRelative(&ts, timeoutMsec);
}
- while (sp_response->finalResponse == NULL && s_readerClosed == 0)
+ while (sp_response[port]->finalResponse == NULL && s_readerClosed == 0)
{
//LOGD("AT wait time:%lld",timeoutMsec);
if (timeoutMsec != 0)
{
- err = pthread_cond_timedwait(&s_commandcond, &s_commandmutex, &ts);
+ err = pthread_cond_timedwait(&s_commandcond[port], &s_commandmutex[port], &ts);
}
else
{
- err = pthread_cond_wait(&s_commandcond, &s_commandmutex);
+ err = pthread_cond_wait(&s_commandcond[port], &s_commandmutex[port]);
}
//LOGD("AT continue:err - %d",err);
@@ -1027,16 +1038,16 @@
if (pp_outResponse == NULL)
{
- at_response_free(sp_response);
+ at_response_free(sp_response[port]);
}
else
{
/* line reader stores intermediate responses in reverse order */
- reverseIntermediates(sp_response);
- *pp_outResponse = sp_response;
+ reverseIntermediates(sp_response[port]);
+ *pp_outResponse = sp_response[port];
}
- sp_response = NULL;
+ sp_response[port] = NULL;
if(s_readerClosed > 0)
{
@@ -1046,9 +1057,9 @@
err = 0;
error:
- if(at_state == RIL_AT_STATE_BUSY)
- at_state = RIL_AT_STATE_READY;
- clearPendingCommand();
+ if(at_state[port] == RIL_AT_STATE_BUSY)
+ at_state[port] = RIL_AT_STATE_READY;
+ clearPendingCommand(port);
return err;
}
@@ -1058,13 +1069,13 @@
*
* timeoutMsec == 0 means infinite timeout
*/
-static int at_send_command_full (const char *command, ATCommandType type,
+static int at_send_command_full (ATPortType_enum port, const char *command, ATCommandType type,
const char *responsePrefix, const char *smspdu,
long long timeoutMsec, ATResponse **pp_outResponse)
{
int err;
- if (0 != pthread_equal(s_tid_reader, pthread_self()))
+ if (0 != pthread_equal(s_tid_reader[port], pthread_self()))
{
/* cannot be called from reader thread */
LOGE("cannot be called from reader thread.");
@@ -1072,18 +1083,18 @@
}
// Waitting for previous AT complete.
- while(at_state == RIL_AT_STATE_BUSY)
+ while(at_state[port] == RIL_AT_STATE_BUSY)
{
usleep(10000);
}
- pthread_mutex_lock(&s_commandmutex);
+ pthread_mutex_lock(&s_commandmutex[port]);
- err = at_send_command_full_nolock(command, type,
+ err = at_send_command_full_nolock(port, command, type,
responsePrefix, smspdu,
timeoutMsec, pp_outResponse);
- pthread_mutex_unlock(&s_commandmutex);
+ pthread_mutex_unlock(&s_commandmutex[port]);
if (err == AT_ERROR_TIMEOUT_CLOSE && s_onTimeout != NULL)
{
@@ -1103,20 +1114,20 @@
* if non-NULL, the resulting ATResponse * must be eventually freed with
* at_response_free
*/
-int at_send_command (const char *command, ATResponse **pp_outResponse)
+int at_send_command (ATPortType_enum port, const char *command, ATResponse **pp_outResponse)
{
- return at_send_command_full (command, NO_RESULT, NULL,
+ return at_send_command_full (port, command, NO_RESULT, NULL,
NULL, 0, pp_outResponse);
}
-int at_send_command_singleline (const char *command,
+int at_send_command_singleline (ATPortType_enum port, const char *command,
const char *responsePrefix,
ATResponse **pp_outResponse)
{
int err;
- err = at_send_command_full (command, SINGLELINE, responsePrefix,
+ err = at_send_command_full (port, command, SINGLELINE, responsePrefix,
NULL, 0, pp_outResponse);
if (err == 0 && pp_outResponse != NULL
@@ -1133,13 +1144,13 @@
return err;
}
-int at_send_command_singleline_with_timeout (const char *command,
+int at_send_command_singleline_with_timeout (ATPortType_enum port, const char *command,
const char *responsePrefix,
ATResponse **pp_outResponse,long long timeoutMsec)
{
int err;
- err = at_send_command_full (command, SINGLELINE, responsePrefix,
+ err = at_send_command_full (port, command, SINGLELINE, responsePrefix,
NULL, timeoutMsec, pp_outResponse);
if (err == 0 && pp_outResponse != NULL
@@ -1158,12 +1169,12 @@
-int at_send_command_numeric (const char *command,
+int at_send_command_numeric (ATPortType_enum port, const char *command,
ATResponse **pp_outResponse)
{
int err;
- err = at_send_command_full (command, NUMERIC, NULL,
+ err = at_send_command_full (port, command, NUMERIC, NULL,
NULL, 0, pp_outResponse);
if (err == 0 && pp_outResponse != NULL
@@ -1181,14 +1192,14 @@
}
-int at_send_command_sms (const char *command,
+int at_send_command_sms (ATPortType_enum port, const char *command,
const char *pdu,
const char *responsePrefix,
ATResponse **pp_outResponse)
{
int err;
- err = at_send_command_full (command, SINGLELINE, responsePrefix,
+ err = at_send_command_full (port, command, SINGLELINE, responsePrefix,
pdu, 0, pp_outResponse);
if (err == 0 && pp_outResponse != NULL
@@ -1206,13 +1217,13 @@
}
-int at_send_command_multiline (const char *command,
+int at_send_command_multiline (ATPortType_enum port, const char *command,
const char *responsePrefix,
ATResponse **pp_outResponse)
{
int err;
- err = at_send_command_full (command, MULTILINE, responsePrefix,
+ err = at_send_command_full (port, command, MULTILINE, responsePrefix,
NULL, 0, pp_outResponse);
return err;
@@ -1242,17 +1253,17 @@
* Periodically issue an AT command and wait for a response.
* Used to ensure channel has start up and is active
*/
-int at_handshake()
+int at_handshake(ATPortType_enum port)
{
// int i;
int err = 0;
- if (0 != pthread_equal(s_tid_reader, pthread_self()))
+ if (0 != pthread_equal(s_tid_reader[port], pthread_self()))
{
/* cannot be called from reader thread */
return AT_ERROR_INVALID_THREAD;
}
- pthread_mutex_lock(&s_commandmutex);
+ pthread_mutex_lock(&s_commandmutex[port]);
#if 0
for (i = 0 ; i < HANDSHAKE_RETRY_COUNT ; i++)
@@ -1267,7 +1278,7 @@
}
}
#else
- err = at_send_command_full_nolock("ATE0Q0V1", NO_RESULT,
+ err = at_send_command_full_nolock(port, "ATE0Q0V1", NO_RESULT,
NULL, NULL, 0, NULL);
#endif
@@ -1278,7 +1289,7 @@
sleepMsec(HANDSHAKE_TIMEOUT_MSEC);
}
- pthread_mutex_unlock(&s_commandmutex);
+ pthread_mutex_unlock(&s_commandmutex[port]);
return err;
@@ -1324,14 +1335,14 @@
return ret;
}
-mbtk_ril_at_state_enum at_state_get()
+mbtk_ril_at_state_enum at_state_get(ATPortType_enum port)
{
- return at_state;
+ return at_state[port];
}
-void at_state_set(mbtk_ril_at_state_enum state)
+void at_state_set(ATPortType_enum port, mbtk_ril_at_state_enum state)
{
- at_state = state;
+ at_state[port] = state;
}
bool at_rsp_check(ATResponse *p_response)
@@ -1342,8 +1353,8 @@
return true;
}
-void unused_func()
+void unused_func(ATPortType_enum port)
{
- isFinalResponse(NULL);
+ isFinalResponse(port, NULL);
}