aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2017-01-01 19:49:47 +0100
committerHarald Welte <laforge@gnumonks.org>2017-01-01 19:51:50 +0100
commit3b144a27fa12e23a4049d1ede2403e7a6aba5d5b (patch)
tree1c0ef7e7c1fa7acfbe9a646dbec435683d1aff9a
parentf727edcd7d35bd28aea5d3939ea1d4b0f833ab2a (diff)
DPL: add parsing of results from modem
we can now get a list of DPL interfaces and their links.
-rw-r--r--src/diag_dpl.c34
-rw-r--r--src/diag_io.c21
-rw-r--r--src/diag_io.h2
3 files changed, 49 insertions, 8 deletions
diff --git a/src/diag_dpl.c b/src/diag_dpl.c
index a906d25..055018a 100644
--- a/src/diag_dpl.c
+++ b/src/diag_dpl.c
@@ -17,6 +17,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include <errno.h>
+#include <string.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/msgb.h>
@@ -48,10 +50,14 @@ int diag_dpl_get_sup_if(struct diag_instance *di)
{
struct msgb *msg = msgb_alloc_diag();
struct msgb *rx;
- diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING,
- DIAG_DPL_GET_SUPPORTED_IFACES);
- rx = diag_transceive_msg(di, msg);
- /* FIXME */
+ struct dpl_get_sup_if_resp *gsir;
+ rx = diag_subsys_transceive_msg(di, msg, DIAG_SUBSYS_PS_DATA_LOGGING,
+ DIAG_DPL_GET_SUPPORTED_IFACES);
+ if (!rx)
+ return -EINVAL;
+ gsir = (struct dpl_get_sup_if_resp *) msg->l3h;
+ printf("DPL Supported interfaces: %s\n",
+ osmo_hexdump(gsir->iface_id, gsir->num_ifaces));
msgb_free(rx);
return 0;
}
@@ -61,13 +67,25 @@ int diag_dpl_get_if_desc(struct diag_instance *di, uint8_t iface_id)
struct msgb *msg = msgb_alloc_diag();
struct msgb *rx;
struct dpl_get_if_desc_req *gidr;
+ uint8_t if_num, num_links;
+ char *if_name, *link_name;
+ unsigned int i;
gidr = (struct dpl_get_if_desc_req *) msgb_put(msg, sizeof(*gidr));
gidr->iface_id = iface_id;
- diag_push_subsys_hdr(msg, DIAG_SUBSYS_PS_DATA_LOGGING,
- DIAG_DPL_GET_IFACE_DESC);
- rx = diag_transceive_msg(di, msg);
- /* FIXME */
+ rx = diag_subsys_transceive_msg(di, msg, DIAG_SUBSYS_PS_DATA_LOGGING,
+ DIAG_DPL_GET_IFACE_DESC);
+ if (!rx)
+ return -EINVAL;
+ if_num = rx->l3h[0];
+ if_name = (char *)rx->l3h+1;
+ num_links = *(rx->l3h+1+strlen(if_name)+1);
+ printf("DPL Interface %u \"%s\" num_links=%u\n", if_num, if_name, num_links);
+ link_name = (char *) rx->l3h+1+strlen(if_name)+1+1;
+ for (i = 0; i < num_links; i++) {
+ printf("\tLink %u: %s\n", i, link_name);
+ link_name += strlen(link_name) + 1;
+ }
msgb_free(rx);
return 0;
}
diff --git a/src/diag_io.c b/src/diag_io.c
index 59bedab..bcae793 100644
--- a/src/diag_io.c
+++ b/src/diag_io.c
@@ -166,6 +166,27 @@ struct msgb *diag_transceive_msg(struct diag_instance *di, struct msgb *tx)
return NULL;
}
+struct msgb *diag_subsys_transceive_msg(struct diag_instance *di, struct msgb *tx,
+ uint8_t subsys, uint16_t code)
+{
+ struct msgb *rx;
+ struct diagpkt_subsys_hdr *dsh;
+
+ diag_push_subsys_hdr(tx, subsys, code);
+ rx = diag_transceive_msg(di, tx);
+ if (!rx)
+ return NULL;
+ dsh = (struct diagpkt_subsys_hdr *) rx->l2h;
+ if (msgb_l2len(rx) < sizeof(*dsh) ||
+ dsh->subsys_id != subsys ||
+ osmo_load16le(&dsh->subsys_cmd_code) != code) {
+ msgb_free(rx);
+ return NULL;
+ }
+ rx->l3h = rx->l2h + sizeof(*dsh);
+ return rx;
+}
+
/* transmit a message, wait for response, then ignore response */
void diag_transceive_msg_ign(struct diag_instance *di, struct msgb *tx)
{
diff --git a/src/diag_io.h b/src/diag_io.h
index 1dffa15..1e6d662 100644
--- a/src/diag_io.h
+++ b/src/diag_io.h
@@ -23,6 +23,8 @@ int diag_transmit_buf(struct diag_instance *di, const uint8_t *data, size_t data
struct msgb *diag_read_msg(struct diag_instance *di);
int diag_process_msg(struct diag_instance *di, struct msgb *msg);
struct msgb *diag_transceive_msg(struct diag_instance *di, struct msgb *tx);
+struct msgb *diag_subsys_transceive_msg(struct diag_instance *di, struct msgb *tx,
+ uint8_t subsys, uint16_t code);
void diag_transceive_msg_ign(struct diag_instance *di, struct msgb *tx);
struct msgb *diag_transceive_buf(struct diag_instance *di, const uint8_t *data, size_t data_len);
void diag_transceive_buf_ign(struct diag_instance *di, const uint8_t *data, size_t data_len);