blob: f65a8f44bd604928e8f879b28e66b59c3b6d7f76 [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;
62
63 rx = diag_transceive_msg(di, msg);
64 /* FIXME */
65 msgb_free(rx);
Harald Welte6fc7f682016-12-24 10:01:28 +010066
67 return 0;
68}
Harald Welte0e509162016-12-24 01:32:10 +010069
70/* handler for EXT MSG */
71int diag_rx_ext_msg_f(struct diag_instance *di, struct msgb *msgb)
72{
73 const uint8_t *data = msgb_data(msgb);
74 const size_t len = msgb_length(msgb);
75 const struct ext_log_msg *msg;
76 const char *file = NULL, *fmt;
77 unsigned int num_args;
78
79 if (len < sizeof(struct ext_log_msg)) {
80 printf("too short ext_log_msg.\n");
81 return -1;
82 }
83
84 msg = (struct ext_log_msg *) data;
85 num_args = msg->num_args;
86 fmt = (const char *) msg->params + num_args*sizeof(msg->params[0]);
87 file = fmt + strlen(fmt) + 1;
88
89 printf("MSG(%u|%s:%u): ", diag_ts_to_epoch(msg->timestamp), file, msg->line_nr);
90 switch (num_args) {
91 case 0:
92 fputs(fmt, stdout);
93 break;
94 case 1:
95 printf(fmt, msg->params[0]);
96 break;
97 case 2:
98 printf(fmt, msg->params[0], msg->params[1]);
99 break;
100 case 3:
101 printf(fmt, msg->params[0], msg->params[1], msg->params[2]);
102 break;
103 case 4:
104 printf(fmt, msg->params[0], msg->params[1], msg->params[2], msg->params[3]);
105 break;
106 }
107 fputc('\n', stdout);
108 return 0;
109}
110
111