libabis: ipaccess: conclude new ipaccess_send_*() functions and use them

This patch finishes the new ipaccess_send_*() functions and use them
in the ipaccess-proxy code.

I have also cleanup the definition of the PONG, ID_ACK and ID_REQ
messages (including some minor documentation about them).

I had to rename ipaccess_recvmsg() in ipaccess-proxy to avoid clashing
with the one defined in libabis.
This commit is contained in:
Pablo Neira Ayuso 2011-04-07 14:15:06 +02:00 committed by Holger Hans Peter Freyther
parent 3ab864a860
commit 22f58a9a58
4 changed files with 60 additions and 42 deletions

View File

@ -70,6 +70,7 @@ int ipaccess_connect(struct e1inp_line *line, struct sockaddr_in *sa);
int ipaccess_rcvmsg_base(struct msgb *msg, struct bsc_fd *bfd);
struct msgb *ipaccess_read_msg(struct bsc_fd *bfd, int *error);
void ipaccess_prepend_header(struct msgb *msg, int proto);
int ipaccess_send_pong(int fd);
int ipaccess_send_id_ack(int fd);
int ipaccess_send_id_req(int fd);

View File

@ -18,4 +18,9 @@ ipaccess_config_LDADD = $(top_builddir)/src/libbsc/libbsc.a \
-ldl -ldbi $(LIBCRYPT)
ipaccess_proxy_SOURCES = ipaccess-proxy.c
ipaccess_proxy_LDADD = $(top_builddir)/src/libcommon/libcommon.a
ipaccess_proxy_LDADD = $(top_builddir)/src/libbsc/libbsc.a \
$(top_builddir)/src/libmsc/libmsc.a \
$(top_builddir)/src/libabis/libabis.a \
$(top_builddir)/src/libbsc/libbsc.a \
$(top_builddir)/src/libtrau/libtrau.a \
$(top_builddir)/src/libcommon/libcommon.a

View File

@ -131,19 +131,6 @@ static int gprs_ns_cb(struct bsc_fd *bfd, unsigned int what);
#define PROXY_ALLOC_SIZE 1200
static const u_int8_t pong[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG };
static const u_int8_t id_ack[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK };
static const u_int8_t id_req[] = { 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
0x01, IPAC_IDTAG_UNIT,
0x01, IPAC_IDTAG_MACADDR,
0x01, IPAC_IDTAG_LOCATION1,
0x01, IPAC_IDTAG_LOCATION2,
0x01, IPAC_IDTAG_EQUIPVERS,
0x01, IPAC_IDTAG_SWVERSION,
0x01, IPAC_IDTAG_UNITNAME,
0x01, IPAC_IDTAG_SERNR,
};
static const char *idtag_names[] = {
[IPAC_IDTAG_SERNR] = "Serial_Number",
[IPAC_IDTAG_UNITNAME] = "Unit_Name",
@ -529,13 +516,7 @@ static int ipaccess_rcvmsg(struct ipa_proxy_conn *ipc, struct msgb *msg,
switch (msg_type) {
case IPAC_MSGT_PING:
ret = write(bfd->fd, pong, sizeof(pong));
if (ret < 0)
return ret;
if (ret < sizeof(pong)) {
DEBUGP(DINP, "short write\n");
return -EIO;
}
ret = ipaccess_send_pong(bfd->fd);
break;
case IPAC_MSGT_PONG:
DEBUGP(DMI, "PONG!\n");
@ -618,7 +599,7 @@ static int ipaccess_rcvmsg(struct ipa_proxy_conn *ipc, struct msgb *msg,
break;
case IPAC_MSGT_ID_ACK:
DEBUGP(DMI, "ID_ACK? -> ACK!\n");
ret = write(bfd->fd, id_ack, sizeof(id_ack));
ret = ipaccess_send_id_ack(bfd->fd);
break;
default:
LOGP(DMI, LOGL_ERROR, "Unhandled IPA type; %d\n", msg_type);
@ -628,7 +609,7 @@ static int ipaccess_rcvmsg(struct ipa_proxy_conn *ipc, struct msgb *msg,
return 0;
}
struct msgb *ipaccess_read_msg(struct bsc_fd *bfd, int *error)
struct msgb *ipaccess_proxy_read_msg(struct bsc_fd *bfd, int *error)
{
struct msgb *msg = msgb_alloc(PROXY_ALLOC_SIZE, "Abis/IP");
struct ipaccess_head *hh;
@ -868,7 +849,7 @@ static int handle_tcp_read(struct bsc_fd *bfd)
else
btsbsc = "BSC";
msg = ipaccess_read_msg(bfd, &ret);
msg = ipaccess_proxy_read_msg(bfd, &ret);
if (!msg) {
if (ret == 0) {
logp_ipbc_uid(DINP, LOGL_NOTICE, ipbc, bfd->priv_nr >> 8);
@ -1025,7 +1006,7 @@ static int listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what)
}
/* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
ret = write(bfd->fd, id_req, sizeof(id_req));
ret = ipaccess_send_id_req(bfd->fd);
return 0;
}

View File

@ -62,18 +62,31 @@ static struct ia_e1_handle *e1h;
#define TS1_ALLOC_SIZE 900
static const u_int8_t pong[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG };
static const u_int8_t id_ack[] = { 0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK };
static const u_int8_t id_req[] = { 0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
0x01, IPAC_IDTAG_UNIT,
0x01, IPAC_IDTAG_MACADDR,
0x01, IPAC_IDTAG_LOCATION1,
0x01, IPAC_IDTAG_LOCATION2,
0x01, IPAC_IDTAG_EQUIPVERS,
0x01, IPAC_IDTAG_SWVERSION,
0x01, IPAC_IDTAG_UNITNAME,
0x01, IPAC_IDTAG_SERNR,
};
/*
* Common propietary IPA messages:
* - PONG: in reply to PING.
* - ID_REQUEST: first messages once OML has been established.
* - ID_ACK: in reply to ID_ACK.
*/
const u_int8_t ipa_pong_msg[] = {
0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_PONG
};
const u_int8_t ipa_id_ack_msg[] = {
0, 1, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_ACK
};
const u_int8_t ipa_id_req_msg[] = {
0, 17, IPAC_PROTO_IPACCESS, IPAC_MSGT_ID_GET,
0x01, IPAC_IDTAG_UNIT,
0x01, IPAC_IDTAG_MACADDR,
0x01, IPAC_IDTAG_LOCATION1,
0x01, IPAC_IDTAG_LOCATION2,
0x01, IPAC_IDTAG_EQUIPVERS,
0x01, IPAC_IDTAG_SWVERSION,
0x01, IPAC_IDTAG_UNITNAME,
0x01, IPAC_IDTAG_SERNR,
};
static const char *idtag_names[] = {
[IPAC_IDTAG_SERNR] = "Serial_Number",
@ -179,15 +192,33 @@ static int parse_unitid(const char *str, u_int16_t *site_id, u_int16_t *bts_id,
return 0;
}
/* send the id ack */
static int ipaccess_send(int fd, const void *msg, size_t msglen)
{
int ret;
ret = write(fd, msg, msglen);
if (ret < 0)
return ret;
if (ret < msglen) {
DEBUGP(DINP, "ipaccess_send: short write\n");
return -EIO;
}
return ret;
}
int ipaccess_send_pong(int fd)
{
return ipaccess_send(fd, ipa_pong_msg, sizeof(ipa_pong_msg));
}
int ipaccess_send_id_ack(int fd)
{
return write(fd, id_ack, sizeof(id_ack));
return ipaccess_send(fd, ipa_id_ack_msg, sizeof(ipa_id_ack_msg));
}
int ipaccess_send_id_req(int fd)
{
return write(fd, id_req, sizeof(id_req));
return ipaccess_send(fd, ipa_id_req_msg, sizeof(ipa_id_req_msg));
}
/* base handling of the ip.access protocol */
@ -199,7 +230,7 @@ int ipaccess_rcvmsg_base(struct msgb *msg,
switch (msg_type) {
case IPAC_MSGT_PING:
ret = write(bfd->fd, pong, sizeof(pong));
ret = ipaccess_send_pong(bfd->fd);
break;
case IPAC_MSGT_PONG:
DEBUGP(DMI, "PONG!\n");
@ -721,7 +752,7 @@ static int rsl_listen_fd_cb(struct bsc_fd *listen_bfd, unsigned int what)
return ret;
}
/* Request ID. FIXME: request LOCATION, HW/SW VErsion, Unit Name, Serno */
ret = write(bfd->fd, id_req, sizeof(id_req));
ret = ipaccess_send_id_req(bfd->fd);
return 0;
}