introduce new API for configuring the diag logging
diff --git a/src/GNUmakefile b/src/GNUmakefile
index bc3f189..9a52118 100644
--- a/src/GNUmakefile
+++ b/src/GNUmakefile
@@ -1,7 +1,8 @@
 CPPFLAGS ?= -O0 -Wall
+LIBS = -losmocore
 all: qxdm-log
 
-qxdm-log: framing.o serial.o qxdm-log.o
+qxdm-log: framing.o serial.o qxdm-log.o config.o
 	$(CC) $(CPPFLAGS) -o $@ $^ $(LIBS)
 
 clean:
diff --git a/src/config.c b/src/config.c
new file mode 100644
index 0000000..90887bb
--- /dev/null
+++ b/src/config.c
@@ -0,0 +1,58 @@
+#include <stdint.h>
+#include <osmocom/core/msgb.h>
+
+#include "diagcmd.h"
+#include "framing.h"
+
+enum log_config_op {
+	LOG_CONFIG_DISABLE_OP			= 0,
+	LOG_CONFIG_RETRIEVE_ID_RANGES_OP	= 1,
+	LOG_CONFIG_RETRIEVE_VALID_MASK_OP	= 2,
+	LOG_CONFIG_SET_MASK_OP			= 3,
+	LOG_CONFIG_GET_LOGMASK_OP		= 4,
+};
+
+struct diag_log_config_req_hdr {
+	uint8_t		msg_type;
+	uint8_t		pad[3];
+	uint32_t	operation;
+} __attribute((packed));
+
+struct diag_log_config_set_mask {
+	struct diag_log_config_req_hdr hdr;
+	uint32_t	equip_id;
+	uint32_t	last_item;
+	uint8_t		data[0];
+} __attribute((packed));
+
+struct msgb *gen_log_config_set_mask(uint32_t last_item)
+{
+	struct msgb *msg = msgb_alloc(MAX_PACKET, "Diag Tx");
+	struct diag_log_config_set_mask *dlcsm;
+	uint8_t *mask;
+
+	msg->l2h = msgb_put(msg, sizeof(*dlcsm));
+	dlcsm = (struct diag_log_config_set_mask *) msg->l2h;
+	dlcsm->hdr.msg_type = DIAG_LOG_CONFIG_F;
+	dlcsm->hdr.operation = LOG_CONFIG_SET_MASK_OP;
+	dlcsm->equip_id = 5;
+	dlcsm->last_item = last_item;
+	msg->l3h = msgb_put(msg, dlcsm->last_item/8);
+
+	return msg;
+}
+
+int log_config_set_mask_bit(struct msgb *msg, uint32_t bit_in)
+{
+	struct diag_log_config_set_mask *dlcsm = msg->l2h;
+	uint8_t *mask = msg->l3h;
+	unsigned int byte = bit_in / 8;
+	unsigned int bit = bit_in % 8;
+
+	if (byte > dlcsm->last_item/8)
+		return -1;
+
+	mask[byte] |= (1 << bit);
+
+	return 0;
+}
diff --git a/src/config.h b/src/config.h
new file mode 100644
index 0000000..1b74fde
--- /dev/null
+++ b/src/config.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include <stdint.h>
+
+struct msgb;
+
+struct msgb *gen_log_config_set_mask(uint32_t last_item);
+int log_config_set_mask_bit(struct msgb *msg, uint32_t bit_in);
diff --git a/src/qxdm-log.c b/src/qxdm-log.c
index 054407e..f58c875 100644
--- a/src/qxdm-log.c
+++ b/src/qxdm-log.c
@@ -1,6 +1,3 @@
-#include "framing.h"
-#include "protocol.h"
-#include "serial.h"
 
 #include <stdlib.h>
 #include <stddef.h>
@@ -13,6 +10,13 @@
 #include <unistd.h>
 #include <errno.h>
 
+#include <osmocom/core/msgb.h>
+
+#include "framing.h"
+#include "protocol.h"
+#include "serial.h"
+#include "config.h"
+
 char *DumpBYTEs(unsigned char *p, long n, int nBytesPerRow /* = 16 */, char *szLineSep /* = "\n" */, int bRaw /* = FALSE */, const char *szIndent /* = "" */)
 {
   long i;
@@ -63,6 +67,29 @@
   return szRes;
 }
 
+static int transmit_msgb(int fd, struct msgb *msg)
+{
+	int out_len, rc;
+	uint8_t packet[MAX_PACKET * 2];
+
+	out_len = frame_pack(msgb_data(msg), msgb_length(msg),
+			     packet, sizeof(packet));
+	if (out_len < 0) {
+		printf("Failed to pack packet\n");
+		return -1;
+	}
+
+	rc = write(fd, packet, out_len);
+	if (rc != out_len) {
+		printf("Short write on packet.\n");
+		return -1;
+	}
+
+	msgb_free(msg);
+
+	return 0;
+}
+
 static int transmit_packet(int fd, const uint8_t *data, size_t data_len)
 {
 	int out_len, rc;
@@ -174,27 +201,6 @@
 static void do_configure(int fd)
 {
 	static uint8_t timestamp[] = { 0x1D };
-	static uint8_t enable_logging[] = {
-		0x73, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
-		0x05, 0x00, 0x00, 0x00, 0x28, 0x04, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x02, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-		0x00, 0x00, 0x00, 0x00, 0x00
-	};
 #if 0
 	static const uint8_t enable_evt_report[] = {
 		0x60, 0x01
@@ -225,9 +231,14 @@
 	transmit_packet(fd, extended_report_cfg, sizeof(extended_report_cfg));
 	do_read(fd, data);
 
-	/* enable the logging */
-	transmit_packet(fd, enable_logging, sizeof(enable_logging));
-	do_read(fd, data);
+	struct msgb *msg = gen_log_config_set_mask(1064);
+	log_config_set_mask_bit(msg, 306);
+	log_config_set_mask_bit(msg, 544);
+	log_config_set_mask_bit(msg, 545);
+	log_config_set_mask_bit(msg, 546);
+	log_config_set_mask_bit(msg, 547);
+	log_config_set_mask_bit(msg, 553);
+	transmit_msgb(fd, msg);
 }
 
 int main(int argc, char **argv)