diff options
Diffstat (limited to 'src/libgsmd/libgsmd_passthrough.c')
-rw-r--r-- | src/libgsmd/libgsmd_passthrough.c | 37 |
1 files changed, 20 insertions, 17 deletions
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; |