#include #include #include #include #include #include #include #include #include #include "lgsm_internals.h" #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_send(struct lgsm_handle *lh, const char *tx) { struct gsmd_msg_hdr *gmh = (struct gsmd_msg_hdr *)passthrough_buf; char *tx_buf = (char *)gmh + sizeof(*gmh); int len = strlen(tx); if (len > PT_BUF_SIZE) return -EINVAL; gmh->version = GSMD_PROTO_VERSION; gmh->msg_type = GSMD_MSG_PASSTHROUGH; gmh->msg_subtype = GSMD_PASSTHROUGH_REQ; gmh->len = len+1; strcpy(tx_buf, tx); 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, rc, passthrough_rbuf, sizeof(passthrough_rbuf)); if (rc <= 0) return rc; if (rc < sizeof(*rgmh)) return -EINVAL; if (rc < sizeof(*rgmh) + rgmh->len) return -EINVAL; /* FIXME: make sure rx_buf is zero-terminated */ strcpy(rx, rx_buf); *rx_len = rgmh->len; return rx_len; }