Harald Welte | 211dd6c | 2016-01-13 00:18:49 +0100 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | #include <osmocom/core/msgb.h> |
| 3 | |
| 4 | #include "diagcmd.h" |
Harald Welte | 272b4ae | 2016-12-23 23:28:28 +0100 | [diff] [blame] | 5 | #include "protocol.h" |
Harald Welte | 211dd6c | 2016-01-13 00:18:49 +0100 | [diff] [blame] | 6 | |
| 7 | enum 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 | |
| 15 | struct diag_log_config_req_hdr { |
| 16 | uint8_t msg_type; |
| 17 | uint8_t pad[3]; |
| 18 | uint32_t operation; |
| 19 | } __attribute((packed)); |
| 20 | |
| 21 | struct 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 Welte | f5d6fee | 2016-01-13 22:29:10 +0100 | [diff] [blame] | 28 | struct msgb *gen_log_config_set_mask(uint32_t equip_id, uint32_t last_item) |
Harald Welte | 211dd6c | 2016-01-13 00:18:49 +0100 | [diff] [blame] | 29 | { |
Harald Welte | 272b4ae | 2016-12-23 23:28:28 +0100 | [diff] [blame] | 30 | struct msgb *msg = msgb_alloc(DIAG_MAX_REQ_SIZE, "Diag Tx"); |
Harald Welte | 211dd6c | 2016-01-13 00:18:49 +0100 | [diff] [blame] | 31 | 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 Welte | f5d6fee | 2016-01-13 22:29:10 +0100 | [diff] [blame] | 38 | dlcsm->equip_id = equip_id; |
Harald Welte | 211dd6c | 2016-01-13 00:18:49 +0100 | [diff] [blame] | 39 | dlcsm->last_item = last_item; |
| 40 | msg->l3h = msgb_put(msg, dlcsm->last_item/8); |
| 41 | |
| 42 | return msg; |
| 43 | } |
| 44 | |
| 45 | int 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 | } |