From cbffc8d64707828b045b679e8db0269ae362ffcf Mon Sep 17 00:00:00 2001 From: laforge Date: Mon, 23 Oct 2006 20:28:37 +0000 Subject: more gsmd/libgsm implementation git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@114 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/libgsmd/libgsmd_passthrough.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'src/libgsmd/libgsmd_passthrough.c') diff --git a/src/libgsmd/libgsmd_passthrough.c b/src/libgsmd/libgsmd_passthrough.c index 66f4a82..5362e4e 100644 --- a/src/libgsmd/libgsmd_passthrough.c +++ b/src/libgsmd/libgsmd_passthrough.c @@ -12,26 +12,15 @@ #include "lgsm_internals.h" -static u_int16_t next_msg_id; - -static int lgsm_send(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) -{ - gmh->id = next_msg_id++; - return send(lh->fd, (char *) gmh, sizeof(*gmh) + gmh->len, 0); -} - #define PT_BUF_SIZE 1024 static char passthrough_buf[sizeof(struct gsmd_msg_hdr)+PT_BUF_SIZE]; static char passthrough_rbuf[sizeof(struct gsmd_msg_hdr)+PT_BUF_SIZE]; -int lgsm_passthrough(struct lgsm_handle *lh, const char *tx, char *rx, unsigned int *rx_len) +int lgsm_passthrough_send(struct lgsm_handle *lh, const char *tx) { struct gsmd_msg_hdr *gmh = (struct gsmd_msg_hdr *)passthrough_buf; - struct gsmd_msg_hdr *rgmh = (struct gsmd_msg_hdr *)passthrough_rbuf; char *tx_buf = (char *)gmh + sizeof(*gmh); - char *rx_buf = (char *)rgmh + sizeof(*rgmh); int len = strlen(tx); - int rc; if (len > PT_BUF_SIZE) return -EINVAL; @@ -42,13 +31,27 @@ int lgsm_passthrough(struct lgsm_handle *lh, const char *tx, char *rx, unsigned gmh->len = len+1; strcpy(tx_buf, tx); - rc = lgsm_send(lh, gmh); - if (rc < len+sizeof(*gmh)) + if (lgsm_send(lh, gmh) < len+sizeof(*gmh)) + return -EIO; + + return gmh->id; +} + +int lgsm_passthrough(struct lgsm_handle *lh, const char *tx, char *rx, unsigned int *rx_len) +{ + struct gsmd_msg_hdr *rgmh = (struct gsmd_msg_hdr *)passthrough_rbuf; + char *rx_buf = (char *)rgmh + sizeof(*rgmh); + int rc; + + rc = lgsm_passthrough_send(lh, tx); + if (rc < 0) return rc; - /* since we synchronously want to wait for a response, we need to _internally_ loop over - * incoming packets and call the callbacks for intermediate messages (if applicable) */ - rc = lgsm_blocking_wait_packet(lh, gmh->id, passthrough_rbuf, sizeof(passthrough_rbuf)); + /* since we synchronously want to wait for a response, we need to + * _internally_ loop over incoming packets and call the callbacks for + * intermediate messages (if applicable) */ + rc = lgsm_blocking_wait_packet(lh, rc, passthrough_rbuf, + sizeof(passthrough_rbuf)); if (rc <= 0) return rc; -- cgit v1.2.3