blob: f3b9c5d2179155c07596f584c8c61ce6919374e9 [file] [log] [blame]
Harald Welteccea8dd2016-12-24 10:27:55 +01001/*
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 Welte0e509162016-12-24 01:32:10 +010018
19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
22
23#include <osmocom/core/msgb.h>
Harald Welte6fc7f682016-12-24 10:01:28 +010024#include <osmocom/core/bit16gen.h>
25#include <osmocom/core/bit32gen.h>
Harald Welte0e509162016-12-24 01:32:10 +010026
Harald Welte84ec50f2016-12-24 10:16:00 +010027#include "protocol/protocol.h"
Harald Welte0e509162016-12-24 01:32:10 +010028#include "diag_msg.h"
Harald Welte84ec50f2016-12-24 10:16:00 +010029#include "protocol/diagcmd.h"
Harald Welte0e509162016-12-24 01:32:10 +010030
Harald Welte6fc7f682016-12-24 10:01:28 +010031struct 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
42struct 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
58int 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 Weltedc2cafc2017-01-01 11:15:35 +010061 struct msgb *rx;
Harald Weltef1801992017-01-01 11:47:31 +010062 struct diag_set_rt_mask_req *res;
63 int rc = 0;
Harald Weltedc2cafc2017-01-01 11:15:35 +010064
65 rx = diag_transceive_msg(di, msg);
Harald Weltef1801992017-01-01 11:47:31 +010066 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 Weltedc2cafc2017-01-01 11:15:35 +010075 msgb_free(rx);
Harald Welte6fc7f682016-12-24 10:01:28 +010076
Harald Weltef1801992017-01-01 11:47:31 +010077 return rc;
Harald Welte6fc7f682016-12-24 10:01:28 +010078}
Harald Welte0e509162016-12-24 01:32:10 +010079
80/* handler for EXT MSG */
81int 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 Welte7af93aa2017-01-01 12:00:38 +010099 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 Welte0e509162016-12-24 01:32:10 +0100102 switch (num_args) {
103 case 0:
104 fputs(fmt, stdout);
105 break;
106 case 1:
Harald Welte7af93aa2017-01-01 12:00:38 +0100107 printf(fmt, osmo_load32le(&msg->params[0]));
Harald Welte0e509162016-12-24 01:32:10 +0100108 break;
109 case 2:
Harald Welte7af93aa2017-01-01 12:00:38 +0100110 printf(fmt, osmo_load32le(&msg->params[0]),
111 osmo_load32le(&msg->params[1]));
Harald Welte0e509162016-12-24 01:32:10 +0100112 break;
113 case 3:
Harald Welte7af93aa2017-01-01 12:00:38 +0100114 printf(fmt, osmo_load32le(&msg->params[0]),
115 osmo_load32le(&msg->params[1]),
116 osmo_load32le(&msg->params[2]));
Harald Welte0e509162016-12-24 01:32:10 +0100117 break;
118 case 4:
Harald Welte7af93aa2017-01-01 12:00:38 +0100119 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 Welte0e509162016-12-24 01:32:10 +0100123 break;
124 }
125 fputc('\n', stdout);
126 return 0;
127}
128
129