static int ipa_client_read(struct ipa_client_conn *link) { struct osmo_fd *ofd = link->ofd; struct msgb *msg; int ret; LOGIPA(link, LOGL_DEBUG, "message received\n"); ret = ipa_msg_recv_buffered(ofd->fd, &msg, &link->pending_msg); if (ret <= 0) { if (ret == -EAGAIN) return 0; else if (ret == -EPIPE || ret == -ECONNRESET) LOGIPA(link, LOGL_ERROR, "lost connection with server\n"); else if (ret == 0) LOGIPA(link, LOGL_ERROR, "connection closed with server\n"); ipa_client_conn_close(link); if (link->updown_cb) link->updown_cb(link, 0); return -EBADF; } if (link->read_cb) return link->read_cb(link, msg); return 0; }
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; }
static int ussd_read_cb(struct osmo_fd *bfd) { struct bsc_nat_ussd_con *conn = bfd->data; struct msgb *msg = NULL; struct ipaccess_head *hh; int ret; ret = ipa_msg_recv_buffered(bfd->fd, &msg, &conn->pending_msg); if (ret <= 0) { if (ret == -EAGAIN) return 0; LOGP(DNAT, LOGL_ERROR, "USSD Connection was lost.\n"); bsc_nat_ussd_destroy(conn); return -1; } LOGP(DNAT, LOGL_NOTICE, "MSG from USSD: %s proto: %d\n", osmo_hexdump(msg->data, msg->len), msg->l2h[0]); hh = (struct ipaccess_head *) msg->data; if (hh->proto == IPAC_PROTO_IPACCESS) { if (msg->l2h[0] == IPAC_MSGT_ID_RESP) { struct tlv_parsed tvp; int ret; ret = ipa_ccm_idtag_parse(&tvp, (unsigned char *) msg->l2h + 2, msgb_l2len(msg) - 2); if (ret < 0) { LOGP(DNAT, LOGL_ERROR, "ignoring IPA response " "message with malformed TLVs\n"); msgb_free(msg); return ret; } if (TLVP_PRESENT(&tvp, IPAC_IDTAG_UNITNAME)) ussd_auth_con(&tvp, conn); } else if (msg->l2h[0] == IPAC_MSGT_PING) { LOGP(DNAT, LOGL_DEBUG, "Got USSD ping request.\n"); ussd_pong(conn); } else { LOGP(DNAT, LOGL_NOTICE, "Got unknown IPACCESS message 0x%02x.\n", msg->l2h[0]); } msgb_free(msg); } else if (hh->proto == IPAC_PROTO_SCCP) { forward_sccp(conn->nat, msg); } else { msgb_free(msg); } return 0; }
static int ipa_server_conn_read(struct ipa_server_conn *conn) { struct osmo_fd *ofd = &conn->ofd; struct msgb *msg; int ret; LOGIPA(conn, LOGL_DEBUG, "message received\n"); ret = ipa_msg_recv_buffered(ofd->fd, &msg, &conn->pending_msg); if (ret <= 0) { if (ret == -EAGAIN) return 0; else if (ret == -EPIPE || ret == -ECONNRESET) LOGIPA(conn, LOGL_ERROR, "lost connection with server\n"); else if (ret == 0) LOGIPA(conn, LOGL_ERROR, "connection closed with server\n"); ipa_server_conn_destroy(conn); return -EBADF; } if (conn->cb) return conn->cb(conn, msg); return 0; }