Skip to content

Commit

Permalink
Add MBM u300-ril 4.0.0.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
Borkata authored and EnJens committed Jan 19, 2012
1 parent 2bb3f38 commit 72953f1
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 306 deletions.
1 change: 0 additions & 1 deletion mbm-ril/at_tok.c
Expand Up @@ -130,7 +130,6 @@ static char *nextTok(char **p_cur)
return ret;
}


/**
* Parses the next integer in the AT response line and places it in *p_out.
* Returns 0 on success and -1 on fail.
Expand Down
79 changes: 41 additions & 38 deletions mbm-ril/atchannel.c
Expand Up @@ -53,7 +53,7 @@
#define HANDSHAKE_RETRY_COUNT 8
#define HANDSHAKE_TIMEOUT_MSEC 250
#define DEFAULT_AT_TIMEOUT_MSEC (3 * 60 * 1000)
#define BUFFSIZE 256
#define BUFFSIZE 512

struct atcontext {
pthread_t tid_reader;
Expand Down Expand Up @@ -99,9 +99,9 @@ static pthread_once_t key_once = PTHREAD_ONCE_INIT;

static int writeCtrlZ (const char *s);
static int writeline (const char *s);
static void onReaderClosed();
static void onReaderClosed(void);

static void make_key()
static void make_key(void)
{
(void) pthread_key_create(&key, NULL);
}
Expand Down Expand Up @@ -132,7 +132,7 @@ static void ac_free(void)
}
}

static int initializeAtContext()
static int initializeAtContext(void)
{
struct atcontext *ac = NULL;

Expand All @@ -158,8 +158,7 @@ static int initializeAtContext()
ac->ATBufferCur = ac->ATBuffer;

if (pipe(ac->readerCmdFds)) {
LOGE("%s() Failed to create pipe: %s", __func__,
strerror(errno));
LOGE("%s() Failed to create pipe: %s", __func__, strerror(errno));
goto error;
}

Expand All @@ -186,7 +185,7 @@ static int initializeAtContext()
return -1;
}

static struct atcontext *getAtContext()
static struct atcontext *getAtContext(void)
{
struct atcontext *ac = NULL;

Expand Down Expand Up @@ -390,8 +389,7 @@ static void processLine(const char *line)
break;
case NUMERIC:
if (ac->response->p_intermediates == NULL
&& isdigit(line[0])
) {
&& isdigit(line[0])) {
addIntermediate(line);
} else {
/* Either we already have an intermediate response or
Expand All @@ -401,8 +399,7 @@ static void processLine(const char *line)
break;
case SINGLELINE:
if (ac->response->p_intermediates == NULL
&& strStartsWith (line, ac->responsePrefix)
) {
&& strStartsWith (line, ac->responsePrefix)) {
addIntermediate(line);
} else {
/* We already have an intermediate response. */
Expand Down Expand Up @@ -440,7 +437,7 @@ static char * findNextEOL(char *cur)
return cur+2;
}

// Find next newline
/* Find next newline */
while (*cur != '\0' && *cur != '\r' && *cur != '\n') cur++;

return *cur == '\0' ? NULL : cur;
Expand All @@ -457,7 +454,7 @@ static char * findNextEOL(char *cur)
* have buffered stdio.
*/

static const char *readline()
static const char *readline(void)
{
ssize_t count;

Expand Down Expand Up @@ -504,7 +501,10 @@ static const char *readline()
int err;
struct pollfd pfds[2];

if (0 >= MAX_AT_RESPONSE - (p_read - ac->ATBuffer)) {
/* This condition should be synchronized with the read function call
* size argument below.
*/
if (0 >= MAX_AT_RESPONSE - (p_read - ac->ATBuffer) - 2) {
LOGE("%s() ERROR: Input line exceeded buffer", __func__);
/* Ditch buffer and start over again. */
ac->ATBufferCur = ac->ATBuffer;
Expand Down Expand Up @@ -546,16 +546,24 @@ static const char *readline()
continue;

do
/* The size argument should be synchronized to the ditch buffer
* condition above.
*/
count = read(ac->fd, p_read,
MAX_AT_RESPONSE - (p_read - ac->ATBuffer));
MAX_AT_RESPONSE - (p_read - ac->ATBuffer) - 2);

while (count < 0 && errno == EINTR);

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

/* Implementation requires extra EOS or EOL to get it right if
* there are no trailing newlines in the read buffer. Adding extra
* EOS does not harm even if there actually were trailing EOLs.
*/
p_read[count] = '\0';
p_read[count+1] = '\0';

/* Skip over leading newlines. */
while (*ac->ATBufferCur == '\r' || *ac->ATBufferCur == '\n')
Expand All @@ -578,15 +586,18 @@ static const char *readline()

ret = ac->ATBufferCur;
*p_eol = '\0';

/* The extra EOS added after read takes care of the case when there is no
* valid data after p_eol.
*/
ac->ATBufferCur = p_eol + 1; /* This will always be <= p_read,
and there will be a \0 at *p_read. */

LOGI("AT(%d)< %s", ac->fd, ret);
return ret;
}


static void onReaderClosed()
static void onReaderClosed(void)
{
struct atcontext *ac = getAtContext();
if (ac->onReaderClosed != NULL && ac->readerClosed == 0) {
Expand All @@ -603,7 +614,6 @@ static void onReaderClosed()
}
}


static void *readerLoop(void *arg)
{
struct atcontext *ac = NULL;
Expand Down Expand Up @@ -698,7 +708,6 @@ static int writeline (const char *s)
return 0;
}


static int writeCtrlZ (const char *s)
{
size_t cur = 0;
Expand All @@ -707,9 +716,8 @@ static int writeCtrlZ (const char *s)

struct atcontext *ac = getAtContext();

if (ac->fd < 0 || ac->readerClosed > 0) {
if (ac->fd < 0 || ac->readerClosed > 0)
return AT_ERROR_CHANNEL_CLOSED;
}

LOGD("AT> %s^Z\n", s);

Expand All @@ -721,9 +729,8 @@ static int writeCtrlZ (const char *s)
written = write (ac->fd, s + cur, len - cur);
} while (written < 0 && errno == EINTR);

if (written < 0) {
if (written < 0)
return AT_ERROR_GENERIC;
}

cur += written;
}
Expand All @@ -733,20 +740,18 @@ static int writeCtrlZ (const char *s)
written = write (ac->fd, "\032" , 1);
} while ((written < 0 && errno == EINTR) || (written == 0));

if (written < 0) {
if (written < 0)
return AT_ERROR_GENERIC;
}

return 0;
}

static void clearPendingCommand()
static void clearPendingCommand(void)
{
struct atcontext *ac = getAtContext();

if (ac->response != NULL) {
if (ac->response != NULL)
at_response_free(ac->response);
}

ac->response = NULL;
ac->responsePrefix = NULL;
Expand Down Expand Up @@ -778,9 +783,8 @@ static AT_Error at_get_error(const ATResponse *p_response)
if (p_response == NULL)
return merror(GENERIC_ERROR, GENERIC_ERROR_UNSPECIFIED);

if (p_response->success > 0) {
if (p_response->success > 0)
return AT_NOERROR;
}

if (p_response->finalResponse == NULL)
return AT_ERROR_INVALID_RESPONSE;
Expand Down Expand Up @@ -859,7 +863,7 @@ int at_open(int fd, ATUnsolHandler h)
}

/* FIXME is it ok to call this from the reader and the command thread? */
void at_close()
void at_close(void)
{
struct atcontext *ac = getAtContext();

Expand All @@ -881,7 +885,7 @@ void at_close()
write(ac->readerCmdFds[1], "x", 1);
}

static ATResponse * at_response_new()
static ATResponse *at_response_new(void)
{
return (ATResponse *) calloc(1, sizeof(ATResponse));
}
Expand Down Expand Up @@ -970,9 +974,9 @@ static int at_send_command_full_nolock (const char *command, ATCommandType type,
goto finally;

while (ac->response->finalResponse == NULL && ac->readerClosed == 0) {
if (timeoutMsec != 0) {
if (timeoutMsec != 0)
err = pthread_cond_timeout_np(&ac->commandcond, &ac->commandmutex, timeoutMsec);
} else
else
err = pthread_cond_wait(&ac->commandcond, &ac->commandmutex);

if (err == ETIMEDOUT) {
Expand Down Expand Up @@ -1035,9 +1039,8 @@ static int at_send_command_full (const char *command, ATCommandType type,
return AT_ERROR_STRING_CREATION;
}
ptr = strbuf;
} else {
} else
ptr = command;
}

err = at_send_command_full_nolock(ptr, type,
responsePrefix, smspdu,
Expand Down Expand Up @@ -1146,7 +1149,7 @@ int at_send_command_numeric (const char *command,
struct atcontext *ac = getAtContext();

err = at_send_command_full (command, NUMERIC, NULL,
NULL, ac->timeoutMsec, pp_outResponse, 0, empty);
NULL, ac->timeoutMsec, pp_outResponse, 0, empty);

if (err == AT_NOERROR && pp_outResponse != NULL
&& (*pp_outResponse) != NULL
Expand Down Expand Up @@ -1271,7 +1274,7 @@ void at_set_on_reader_closed(void (*onClose)(void))
* 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(void)
{
int i;
int err = 0;
Expand Down
4 changes: 2 additions & 2 deletions mbm-ril/atchannel.h
Expand Up @@ -84,7 +84,7 @@ typedef struct {
typedef void (*ATUnsolHandler)(const char *s, const char *sms_pdu);

int at_open(int fd, ATUnsolHandler h);
void at_close();
void at_close(void);

/*
* Set default timeout for at commands. Let it be reasonable high
Expand Down Expand Up @@ -122,7 +122,7 @@ int at_send_command_multiline (const char *command,
...);


int at_handshake();
int at_handshake(void);

int at_send_command (const char *command, ...);

Expand Down
3 changes: 1 addition & 2 deletions mbm-ril/net-utils.c
Expand Up @@ -49,9 +49,8 @@ int ifc_init(void)
{
if (ifc_ctl_sock == -1) {
ifc_ctl_sock = socket(AF_INET, SOCK_DGRAM, 0);
if (ifc_ctl_sock < 0) {
if (ifc_ctl_sock < 0)
LOGE("%s() socket() failed: %s", __func__, strerror(errno));
}
}
return ifc_ctl_sock < 0 ? -1 : 0;
}
Expand Down

0 comments on commit 72953f1

Please sign in to comment.