summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/gsmd/gsmd.h2
-rw-r--r--src/gsmd/atcmd.c22
-rw-r--r--src/gsmd/vendor_bcm.c3
3 files changed, 21 insertions, 6 deletions
diff --git a/include/gsmd/gsmd.h b/include/gsmd/gsmd.h
index 3d92619..f1773c3 100644
--- a/include/gsmd/gsmd.h
+++ b/include/gsmd/gsmd.h
@@ -17,6 +17,7 @@ void *gsmd_tallocs;
/* Refer to 3GPP TS 07.07 v 7.8.0, Chapter 4.1 */
#define LGSM_ATCMD_F_EXTENDED 0x01 /* as opposed to basic */
#define LGSM_ATCMD_F_PARAM 0x02 /* as opposed to action */
+#define LGSM_ATCMD_F_LFCR 0x04 /* accept LFCR as a line terminator */
struct gsmd_atcmd {
struct llist_head list;
@@ -37,6 +38,7 @@ enum llparse_state {
LLPARSE_STATE_IDLE_LF, /* LF before response (V1) */
LLPARSE_STATE_RESULT, /* within result payload */
LLPARSE_STATE_RESULT_CR, /* CR after result */
+ LLPARSE_STATE_RESULT_LF, /* LF after result */
LLPARSE_STATE_PROMPT, /* within a "> " prompt */
LLPARSE_STATE_PROMPT_SPC, /* a complete "> " prompt */
LLPARSE_STATE_ERROR, /* something went wrong */
diff --git a/src/gsmd/atcmd.c b/src/gsmd/atcmd.c
index 514625b..37c8538 100644
--- a/src/gsmd/atcmd.c
+++ b/src/gsmd/atcmd.c
@@ -76,6 +76,14 @@ static inline int llparse_append(struct llparser *llp, char byte)
}
}
+static inline void llparse_endline(struct llparser *llp)
+{
+ /* re-set cursor to start of buffer */
+ llp->cur = llp->buf;
+ llp->state = LLPARSE_STATE_IDLE;
+ memset(llp->buf, 0, LLPARSE_BUF_SIZE);
+}
+
static int llparse_byte(struct llparser *llp, char byte)
{
int ret = 0;
@@ -121,16 +129,18 @@ static int llparse_byte(struct llparser *llp, char byte)
case LLPARSE_STATE_RESULT:
if (byte == '\r')
llp->state = LLPARSE_STATE_RESULT_CR;
+ else if ((llp->flags & LGSM_ATCMD_F_LFCR) && byte == '\n')
+ llp->state = LLPARSE_STATE_RESULT_LF;
else
ret = llparse_append(llp, byte);
break;
case LLPARSE_STATE_RESULT_CR:
- if (byte == '\n') {
- /* re-set cursor to start of buffer */
- llp->cur = llp->buf;
- llp->state = LLPARSE_STATE_IDLE;
- memset(llp->buf, 0, LLPARSE_BUF_SIZE);
- }
+ if (byte == '\n')
+ llparse_endline(llp);
+ break;
+ case LLPARSE_STATE_RESULT_LF:
+ if (byte == '\r')
+ llparse_endline(llp);
break;
case LLPARSE_STATE_PROMPT:
if (byte == ' ')
diff --git a/src/gsmd/vendor_bcm.c b/src/gsmd/vendor_bcm.c
index e8e1584..9bcfa1a 100644
--- a/src/gsmd/vendor_bcm.c
+++ b/src/gsmd/vendor_bcm.c
@@ -98,6 +98,9 @@ static int bcm_initsettings(struct gsmd *g)
int rc;
struct gsmd_atcmd *cmd;
+ /* bcm sometimes sends LFCR instead of CRLF (eg *MTSMENU message) */
+ g->llp.flags |= LGSM_ATCMD_F_LFCR;
+
/* TODO */
return rc;
}
personal git repositories of Harald Welte. Your mileage may vary