blob: 916cb05bef90daf852ef2470346a3aea793949a8 [file] [log] [blame]
Harald Welte211dd6c2016-01-13 00:18:49 +01001#include <stdint.h>
2#include <osmocom/core/msgb.h>
3
4#include "diagcmd.h"
Harald Welte272b4ae2016-12-23 23:28:28 +01005#include "protocol.h"
Harald Welte211dd6c2016-01-13 00:18:49 +01006
7enum log_config_op {
8 LOG_CONFIG_DISABLE_OP = 0,
9 LOG_CONFIG_RETRIEVE_ID_RANGES_OP = 1,
10 LOG_CONFIG_RETRIEVE_VALID_MASK_OP = 2,
11 LOG_CONFIG_SET_MASK_OP = 3,
12 LOG_CONFIG_GET_LOGMASK_OP = 4,
13};
14
15struct diag_log_config_req_hdr {
16 uint8_t msg_type;
17 uint8_t pad[3];
18 uint32_t operation;
19} __attribute((packed));
20
21struct diag_log_config_set_mask {
22 struct diag_log_config_req_hdr hdr;
23 uint32_t equip_id;
24 uint32_t last_item;
25 uint8_t data[0];
26} __attribute((packed));
27
Harald Weltef5d6fee2016-01-13 22:29:10 +010028struct msgb *gen_log_config_set_mask(uint32_t equip_id, uint32_t last_item)
Harald Welte211dd6c2016-01-13 00:18:49 +010029{
Harald Welte272b4ae2016-12-23 23:28:28 +010030 struct msgb *msg = msgb_alloc(DIAG_MAX_REQ_SIZE, "Diag Tx");
Harald Welte211dd6c2016-01-13 00:18:49 +010031 struct diag_log_config_set_mask *dlcsm;
32 uint8_t *mask;
33
34 msg->l2h = msgb_put(msg, sizeof(*dlcsm));
35 dlcsm = (struct diag_log_config_set_mask *) msg->l2h;
36 dlcsm->hdr.msg_type = DIAG_LOG_CONFIG_F;
37 dlcsm->hdr.operation = LOG_CONFIG_SET_MASK_OP;
Harald Weltef5d6fee2016-01-13 22:29:10 +010038 dlcsm->equip_id = equip_id;
Harald Welte211dd6c2016-01-13 00:18:49 +010039 dlcsm->last_item = last_item;
40 msg->l3h = msgb_put(msg, dlcsm->last_item/8);
41
42 return msg;
43}
44
45int log_config_set_mask_bit(struct msgb *msg, uint32_t bit_in)
46{
47 struct diag_log_config_set_mask *dlcsm = msg->l2h;
48 uint8_t *mask = msg->l3h;
49 unsigned int byte = bit_in / 8;
50 unsigned int bit = bit_in % 8;
51
52 if (byte > dlcsm->last_item/8)
53 return -1;
54
55 mask[byte] |= (1 << bit);
56
57 return 0;
58}