Harald Welte | ccea8dd | 2016-12-24 10:27:55 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2013-2016 by Harald Welte <laforge@gnumonks.org> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along |
| 15 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | */ |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 18 | |
| 19 | #include <stdlib.h> |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | |
| 23 | #include <osmocom/core/msgb.h> |
Harald Welte | 6fc7f68 | 2016-12-24 10:01:28 +0100 | [diff] [blame] | 24 | #include <osmocom/core/bit16gen.h> |
| 25 | #include <osmocom/core/bit32gen.h> |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 26 | |
Harald Welte | 84ec50f | 2016-12-24 10:16:00 +0100 | [diff] [blame] | 27 | #include "protocol/protocol.h" |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 28 | #include "diag_msg.h" |
Harald Welte | 84ec50f | 2016-12-24 10:16:00 +0100 | [diff] [blame] | 29 | #include "protocol/diagcmd.h" |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 30 | |
Harald Welte | 6fc7f68 | 2016-12-24 10:01:28 +0100 | [diff] [blame] | 31 | struct diag_set_rt_mask_req { |
| 32 | uint8_t cmd_code; |
| 33 | uint8_t sub_cmd; |
| 34 | uint16_t ssid_start; |
| 35 | uint16_t ssid_end; |
| 36 | uint16_t _pad; |
| 37 | uint32_t runtime_mask[1]; |
| 38 | }; |
| 39 | |
| 40 | #define MSG_EXT_SUBCMD_SET_RT_MASK 4 |
| 41 | |
| 42 | struct msgb *gen_msg_config_set_rt_mask(uint16_t ssid, uint32_t runtime_mask) |
| 43 | { |
| 44 | struct msgb *msg = msgb_alloc(DIAG_MAX_REQ_SIZE, "Diag Msg Config"); |
| 45 | struct diag_set_rt_mask_req *dsrmr; |
| 46 | |
| 47 | msg->l2h = msgb_put(msg, sizeof(*dsrmr)); |
| 48 | dsrmr = (struct diag_set_rt_mask_req *) msg->l2h; |
| 49 | dsrmr->cmd_code = DIAG_EXT_MSG_CONFIG_F; |
| 50 | dsrmr->sub_cmd = MSG_EXT_SUBCMD_SET_RT_MASK; |
| 51 | osmo_store16le(ssid, &dsrmr->ssid_start); |
| 52 | osmo_store16le(ssid, &dsrmr->ssid_end); |
| 53 | osmo_store32le(runtime_mask, &dsrmr->runtime_mask[0]); |
| 54 | |
| 55 | return msg; |
| 56 | } |
| 57 | |
| 58 | int diag_msg_config_set_rt_mask(struct diag_instance *di, uint16_t ssid, uint32_t runtime_mask) |
| 59 | { |
| 60 | struct msgb *msg = gen_msg_config_set_rt_mask(ssid, runtime_mask); |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 61 | struct msgb *rx; |
Harald Welte | f180199 | 2017-01-01 11:47:31 +0100 | [diff] [blame] | 62 | struct diag_set_rt_mask_req *res; |
| 63 | int rc = 0; |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 64 | |
| 65 | rx = diag_transceive_msg(di, msg); |
Harald Welte | f180199 | 2017-01-01 11:47:31 +0100 | [diff] [blame] | 66 | res = (struct diag_set_rt_mask_req *) (msgb_l2(msg)+1); |
| 67 | if ((rx->l2h[0] != 0x5d) || res->cmd_code != 0x5d || |
| 68 | res->sub_cmd != MSG_EXT_SUBCMD_SET_RT_MASK || |
| 69 | osmo_load16le(&res->ssid_start) != ssid || |
| 70 | osmo_load16le(&res->ssid_end) != ssid || |
| 71 | osmo_load32le(&res->runtime_mask) != runtime_mask) { |
| 72 | fprintf(stderr, "Error setting RT mask\n"); |
| 73 | rc = -1; |
| 74 | } |
Harald Welte | dc2cafc | 2017-01-01 11:15:35 +0100 | [diff] [blame] | 75 | msgb_free(rx); |
Harald Welte | 6fc7f68 | 2016-12-24 10:01:28 +0100 | [diff] [blame] | 76 | |
Harald Welte | f180199 | 2017-01-01 11:47:31 +0100 | [diff] [blame] | 77 | return rc; |
Harald Welte | 6fc7f68 | 2016-12-24 10:01:28 +0100 | [diff] [blame] | 78 | } |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 79 | |
| 80 | /* handler for EXT MSG */ |
| 81 | int diag_rx_ext_msg_f(struct diag_instance *di, struct msgb *msgb) |
| 82 | { |
| 83 | const uint8_t *data = msgb_data(msgb); |
| 84 | const size_t len = msgb_length(msgb); |
| 85 | const struct ext_log_msg *msg; |
| 86 | const char *file = NULL, *fmt; |
| 87 | unsigned int num_args; |
| 88 | |
| 89 | if (len < sizeof(struct ext_log_msg)) { |
| 90 | printf("too short ext_log_msg.\n"); |
| 91 | return -1; |
| 92 | } |
| 93 | |
| 94 | msg = (struct ext_log_msg *) data; |
| 95 | num_args = msg->num_args; |
| 96 | fmt = (const char *) msg->params + num_args*sizeof(msg->params[0]); |
| 97 | file = fmt + strlen(fmt) + 1; |
| 98 | |
Harald Welte | 7af93aa | 2017-01-01 12:00:38 +0100 | [diff] [blame] | 99 | printf("MSG(%u|%u|%s:%u): ", osmo_load16le(&msg->subsys_id), |
| 100 | diag_ts_to_epoch(osmo_load64le(&msg->timestamp)), |
| 101 | file, osmo_load16le(&msg->line_nr)); |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 102 | switch (num_args) { |
| 103 | case 0: |
| 104 | fputs(fmt, stdout); |
| 105 | break; |
| 106 | case 1: |
Harald Welte | 7af93aa | 2017-01-01 12:00:38 +0100 | [diff] [blame] | 107 | printf(fmt, osmo_load32le(&msg->params[0])); |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 108 | break; |
| 109 | case 2: |
Harald Welte | 7af93aa | 2017-01-01 12:00:38 +0100 | [diff] [blame] | 110 | printf(fmt, osmo_load32le(&msg->params[0]), |
| 111 | osmo_load32le(&msg->params[1])); |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 112 | break; |
| 113 | case 3: |
Harald Welte | 7af93aa | 2017-01-01 12:00:38 +0100 | [diff] [blame] | 114 | printf(fmt, osmo_load32le(&msg->params[0]), |
| 115 | osmo_load32le(&msg->params[1]), |
| 116 | osmo_load32le(&msg->params[2])); |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 117 | break; |
| 118 | case 4: |
Harald Welte | 7af93aa | 2017-01-01 12:00:38 +0100 | [diff] [blame] | 119 | printf(fmt, osmo_load32le(&msg->params[0]), |
| 120 | osmo_load32le(&msg->params[1]), |
| 121 | osmo_load32le(&msg->params[2]), |
| 122 | osmo_load32le(&msg->params[3])); |
Harald Welte | 0e50916 | 2016-12-24 01:32:10 +0100 | [diff] [blame] | 123 | break; |
| 124 | } |
| 125 | fputc('\n', stdout); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | |