diff options
Diffstat (limited to 'src/input/ipa.c')
-rw-r--r-- | src/input/ipa.c | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/src/input/ipa.c b/src/input/ipa.c index e7ae6fb..e2da6f4 100644 --- a/src/input/ipa.c +++ b/src/input/ipa.c @@ -23,20 +23,6 @@ #include <osmocom/abis/ipa.h> -#define IPA_ALLOC_SIZE 1200 - -struct msgb *ipa_msg_alloc(int headroom) -{ - struct msgb *nmsg; - - headroom += sizeof(struct ipaccess_head); - - nmsg = msgb_alloc_headroom(1200 + headroom, headroom, "Abis/IP"); - if (!nmsg) - return NULL; - return nmsg; -} - void ipa_msg_push_header(struct msgb *msg, uint8_t proto) { struct ipaccess_head *hh; @@ -47,135 +33,6 @@ void ipa_msg_push_header(struct msgb *msg, uint8_t proto) hh->len = htons(msgb_l2len(msg)); } -int ipa_msg_recv(int fd, struct msgb **rmsg) -{ - int rc = ipa_msg_recv_buffered(fd, rmsg, NULL); - if (rc < 0) { - errno = -rc; - rc = -1; - } - return rc; -} - -int ipa_msg_recv_buffered(int fd, struct msgb **rmsg, struct msgb **tmp_msg) -{ - struct msgb *msg = tmp_msg ? *tmp_msg : NULL; - struct ipaccess_head *hh; - int len, ret; - int needed; - - if (msg == NULL) { - msg = ipa_msg_alloc(0); - if (msg == NULL) { - ret = -ENOMEM; - goto discard_msg; - } - msg->l1h = msg->tail; - } - - if (msg->l2h == NULL) { - /* first read our 3-byte header */ - needed = sizeof(*hh) - msg->len; - ret = recv(fd, msg->tail, needed, 0); - if (ret == 0) - goto discard_msg; - - if (ret < 0) { - if (errno == EAGAIN || errno == EINTR) - ret = 0; - else { - ret = -errno; - goto discard_msg; - } - } - - msgb_put(msg, ret); - - if (ret < needed) { - if (msg->len == 0) { - ret = -EAGAIN; - goto discard_msg; - } - - LOGP(DLINP, LOGL_INFO, - "Received part of IPA message header (%d/%d)\n", - msg->len, sizeof(*hh)); - if (!tmp_msg) { - ret = -EIO; - goto discard_msg; - } - *tmp_msg = msg; - return -EAGAIN; - } - - msg->l2h = msg->tail; - } - - hh = (struct ipaccess_head *) msg->data; - - /* then read the length as specified in header */ - len = ntohs(hh->len); - - if (len < 0 || IPA_ALLOC_SIZE < len + sizeof(*hh)) { - LOGP(DLINP, LOGL_ERROR, "bad message length of %d bytes, " - "received %d bytes\n", len, msg->len); - ret = -EIO; - goto discard_msg; - } - - needed = len - msgb_l2len(msg); - - if (needed > 0) { - ret = recv(fd, msg->tail, needed, 0); - - if (ret == 0) - goto discard_msg; - - if (ret < 0) { - if (errno == EAGAIN || errno == EINTR) - ret = 0; - else { - ret = -errno; - goto discard_msg; - } - } - - msgb_put(msg, ret); - - if (ret < needed) { - LOGP(DLINP, LOGL_INFO, - "Received part of IPA message L2 data (%d/%d)\n", - msgb_l2len(msg), len); - if (!tmp_msg) { - ret = -EIO; - goto discard_msg; - } - *tmp_msg = msg; - return -EAGAIN; - } - } - - ret = msgb_l2len(msg); - - if (ret == 0) { - LOGP(DLINP, LOGL_INFO, - "Discarding IPA message without payload\n"); - ret = -EAGAIN; - goto discard_msg; - } - - if (tmp_msg) - *tmp_msg = NULL; - *rmsg = msg; - return ret; - -discard_msg: - if (tmp_msg) - *tmp_msg = NULL; - msgb_free(msg); - return ret; -} - void ipa_client_conn_close(struct ipa_client_conn *link) { /* be safe against multiple calls */ |