From 4f361fcb6898465e2368f2bfe15b72778ba26948 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sun, 15 Feb 2009 15:32:53 +0000 Subject: [PATCH] * add commond header file for ipaccess protocol * query for more attributes during ipaccess-find --- include/openbsc/ipaccess.h | 37 +++++++++++++++++++++++++++ src/input/ipaccess.c | 52 ++++++++++++-------------------------- src/ipaccess-find.c | 16 ++++++++++-- 3 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 include/openbsc/ipaccess.h diff --git a/include/openbsc/ipaccess.h b/include/openbsc/ipaccess.h new file mode 100644 index 000000000..d6ded3551 --- /dev/null +++ b/include/openbsc/ipaccess.h @@ -0,0 +1,37 @@ +#ifndef _IPACCESS_H +#define _IPACCESS_H + +struct ipaccess_head { + u_int8_t zero; + u_int8_t len; + u_int8_t proto; + u_int8_t data[0]; +} __attribute__ ((packed)); + +enum ipaccess_proto { + IPAC_PROTO_RSL = 0x00, + IPAC_PROTO_IPACCESS = 0xfe, + IPAC_PROTO_OML = 0xff, +}; + +enum ipaccess_msgtype { + IPAC_MSGT_PING = 0x00, + IPAC_MSGT_PONG = 0x01, + IPAC_MSGT_ID_GET = 0x04, + IPAC_MSGT_ID_RESP = 0x05, + IPAC_MSGT_ID_ACK = 0x06, +}; + +enum ipaccess_id_tags { + IPAC_IDTAG_SERNR = 0x00, + IPAC_IDTAG_UNITNAME = 0x01, + IPAC_IDTAG_LOCATION1 = 0x02, + IPAC_IDTAG_LOCATION2 = 0x03, + IPAC_IDTAG_EQUIPVERS = 0x04, + IPAC_IDTAG_SWVERSION = 0x05, + IPAC_IDTAG_IPADDR = 0x06, + IPAC_IDTAG_MACADDR = 0x07, + IPAC_IDTAG_UNIT = 0x08, +}; + +#endif /* _IPACCESS_H */ diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c index bfccbc768..98f47fb6c 100644 --- a/src/input/ipaccess.c +++ b/src/input/ipaccess.c @@ -40,6 +40,7 @@ #include #include #include +#include /* data structure for one E1 interface with A-bis */ struct ia_e1_handle { @@ -49,45 +50,24 @@ struct ia_e1_handle { #define TS1_ALLOC_SIZE 300 -struct ipaccess_head { - u_int8_t zero; - u_int8_t len; - u_int8_t proto; - u_int8_t data[0]; -} __attribute__ ((packed)); - -enum ipaccess_proto { - PROTO_RSL = 0x00, - PROTO_IPACCESS = 0xfe, - PROTO_OML = 0xff, -}; - -enum ipaccess_msg_type { - MSGT_PING = 0x00, - MSGT_PONG = 0x01, - MSGT_IDENTITY_GET = 0x04, - MSGT_IDENTITY_RESP = 0x05, - MSGT_IDENTITY_ACK = 0x06, -}; - -static const u_int8_t pong[] = { 0, 1, PROTO_IPACCESS, MSGT_PONG }; -static const u_int8_t id_ack[] = { 0, 1, PROTO_IPACCESS, MSGT_IDENTITY_ACK }; +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 int ipaccess_rcvmsg(struct msgb *msg, int fd) { u_int8_t msg_type = *(msg->l2h); switch (msg_type) { - case MSGT_PING: + case IPAC_MSGT_PING: write(fd, pong, sizeof(pong)); break; - case MSGT_PONG: + case IPAC_MSGT_PONG: DEBUGP(DMI, "PONG!\n"); break; - case MSGT_IDENTITY_RESP: + case IPAC_MSGT_ID_RESP: DEBUGP(DMI, "ID_RESP\n"); break; - case MSGT_IDENTITY_ACK: + case IPAC_MSGT_ID_ACK: DEBUGP(DMI, "ID_ACK? -> ACK!\n"); write(fd, id_ack, sizeof(id_ack)); break; @@ -123,8 +103,8 @@ static int handle_ts1_read(struct bsc_fd *bfd) } if (ret == 0) { fprintf(stderr, "BTS disappeared, dead socket\n"); - e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, PROTO_RSL); - e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, PROTO_OML); + e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, IPAC_PROTO_RSL); + e1inp_event(e1i_ts, EVT_E1_TEI_DN, 0, IPAC_PROTO_OML); bsc_unregister_fd(bfd); close(bfd->fd); bfd->fd = -1; @@ -141,7 +121,7 @@ static int handle_ts1_read(struct bsc_fd *bfd) } msgb_put(msg, ret); - if (hh->proto == PROTO_IPACCESS) + if (hh->proto == IPAC_PROTO_IPACCESS) return ipaccess_rcvmsg(msg, bfd->fd); if (debug_mask & DMI) { @@ -158,16 +138,16 @@ static int handle_ts1_read(struct bsc_fd *bfd) msg->trx = link->trx; switch (hh->proto) { - case PROTO_RSL: + case IPAC_PROTO_RSL: if (!rsl_up) { - e1inp_event(e1i_ts, EVT_E1_TEI_UP, 0, PROTO_RSL); + e1inp_event(e1i_ts, EVT_E1_TEI_UP, 0, IPAC_PROTO_RSL); rsl_up = 1; } ret = abis_rsl_rcvmsg(msg); break; - case PROTO_OML: + case IPAC_PROTO_OML: if (!oml_up) { - e1inp_event(e1i_ts, EVT_E1_TEI_UP, 0, PROTO_OML); + e1inp_event(e1i_ts, EVT_E1_TEI_UP, 0, IPAC_PROTO_OML); oml_up = 1; } ret = abis_nm_rcvmsg(msg); @@ -207,10 +187,10 @@ static int handle_ts1_write(struct bsc_fd *bfd) switch (sign_link->type) { case E1INP_SIGN_OML: - hh->proto = PROTO_OML; + hh->proto = IPAC_PROTO_OML; break; case E1INP_SIGN_RSL: - hh->proto = PROTO_RSL; + hh->proto = IPAC_PROTO_RSL; break; default: msgb_free(msg); diff --git a/src/ipaccess-find.c b/src/ipaccess-find.c index de96a163c..8a11cd32d 100644 --- a/src/ipaccess-find.c +++ b/src/ipaccess-find.c @@ -10,6 +10,7 @@ #include #include +#include static int udp_sock(void) { @@ -45,7 +46,18 @@ err: return rc; } -const unsigned char find_pkt[] = { 0x00, 0x0b, 0xfe, 0x00, 0x04, 0x01, 0x06, 0x01, 0x07, 0x01, 0x02, 0x01, 0x03, 0x01, 0x08 }; +const unsigned char find_pkt[] = { 0x00, 0x0b+8, IPAC_PROTO_IPACCESS, 0x00, + IPAC_MSGT_ID_GET, + 0x01, IPAC_IDTAG_MACADDR, + 0x01, IPAC_IDTAG_IPADDR, + 0x01, IPAC_IDTAG_UNIT, + 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 int bcast_find(int fd) @@ -71,7 +83,7 @@ static int parse_response(unsigned char *buf, int len) t_len = *cur++; t_tag = *cur++; - printf("tag=0x%02x, val='%s' ", t_tag, cur); + printf("tag(%02x)='%s' ", t_tag, cur); cur += t_len; }