2016-12-24 09:27:55 +00:00
|
|
|
/*
|
|
|
|
* (C) 2013-2016 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2016-12-24 00:32:10 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/msgb.h>
|
2016-12-24 09:01:28 +00:00
|
|
|
#include <osmocom/core/bit16gen.h>
|
|
|
|
#include <osmocom/core/bit32gen.h>
|
2016-12-24 00:32:10 +00:00
|
|
|
|
2016-12-24 09:16:00 +00:00
|
|
|
#include "protocol/protocol.h"
|
2016-12-24 00:32:10 +00:00
|
|
|
#include "diag_msg.h"
|
2017-01-01 15:28:57 +00:00
|
|
|
#include "diag_cmd.h"
|
2016-12-24 09:16:00 +00:00
|
|
|
#include "protocol/diagcmd.h"
|
2016-12-24 00:32:10 +00:00
|
|
|
|
2016-12-24 09:01:28 +00:00
|
|
|
struct diag_set_rt_mask_req {
|
|
|
|
uint8_t cmd_code;
|
|
|
|
uint8_t sub_cmd;
|
|
|
|
uint16_t ssid_start;
|
|
|
|
uint16_t ssid_end;
|
|
|
|
uint16_t _pad;
|
|
|
|
uint32_t runtime_mask[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MSG_EXT_SUBCMD_SET_RT_MASK 4
|
|
|
|
|
|
|
|
struct msgb *gen_msg_config_set_rt_mask(uint16_t ssid, uint32_t runtime_mask)
|
|
|
|
{
|
|
|
|
struct msgb *msg = msgb_alloc(DIAG_MAX_REQ_SIZE, "Diag Msg Config");
|
|
|
|
struct diag_set_rt_mask_req *dsrmr;
|
|
|
|
|
|
|
|
msg->l2h = msgb_put(msg, sizeof(*dsrmr));
|
2017-01-07 14:54:41 +00:00
|
|
|
dsrmr = (struct diag_set_rt_mask_req *) msgb_l2(msg);
|
2016-12-24 09:01:28 +00:00
|
|
|
dsrmr->cmd_code = DIAG_EXT_MSG_CONFIG_F;
|
|
|
|
dsrmr->sub_cmd = MSG_EXT_SUBCMD_SET_RT_MASK;
|
|
|
|
osmo_store16le(ssid, &dsrmr->ssid_start);
|
|
|
|
osmo_store16le(ssid, &dsrmr->ssid_end);
|
|
|
|
osmo_store32le(runtime_mask, &dsrmr->runtime_mask[0]);
|
|
|
|
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int diag_msg_config_set_rt_mask(struct diag_instance *di, uint16_t ssid, uint32_t runtime_mask)
|
|
|
|
{
|
|
|
|
struct msgb *msg = gen_msg_config_set_rt_mask(ssid, runtime_mask);
|
2017-01-01 10:15:35 +00:00
|
|
|
struct msgb *rx;
|
2017-01-01 10:47:31 +00:00
|
|
|
struct diag_set_rt_mask_req *res;
|
|
|
|
int rc = 0;
|
2017-01-01 10:15:35 +00:00
|
|
|
|
|
|
|
rx = diag_transceive_msg(di, msg);
|
2017-01-01 10:47:31 +00:00
|
|
|
res = (struct diag_set_rt_mask_req *) (msgb_l2(msg)+1);
|
2017-01-01 23:53:11 +00:00
|
|
|
if ((rx->l2h[0] != DIAG_EXT_MSG_CONFIG_F) || res->cmd_code != MSG_EXT_SUBCMD_SET_RT_MASK ||
|
2017-01-01 10:47:31 +00:00
|
|
|
res->sub_cmd != MSG_EXT_SUBCMD_SET_RT_MASK ||
|
|
|
|
osmo_load16le(&res->ssid_start) != ssid ||
|
|
|
|
osmo_load16le(&res->ssid_end) != ssid ||
|
|
|
|
osmo_load32le(&res->runtime_mask) != runtime_mask) {
|
|
|
|
fprintf(stderr, "Error setting RT mask\n");
|
|
|
|
rc = -1;
|
|
|
|
}
|
2017-01-01 10:15:35 +00:00
|
|
|
msgb_free(rx);
|
2016-12-24 09:01:28 +00:00
|
|
|
|
2017-01-01 10:47:31 +00:00
|
|
|
return rc;
|
2016-12-24 09:01:28 +00:00
|
|
|
}
|
2016-12-24 00:32:10 +00:00
|
|
|
|
|
|
|
/* handler for EXT MSG */
|
2017-01-01 15:28:57 +00:00
|
|
|
static void diag_rx_ext_msg_f(struct diag_instance *di, struct msgb *msgb)
|
2016-12-24 00:32:10 +00:00
|
|
|
{
|
2017-01-21 10:20:07 +00:00
|
|
|
uint8_t *data = msgb_data(msgb);
|
2016-12-24 00:32:10 +00:00
|
|
|
const size_t len = msgb_length(msgb);
|
2017-01-21 10:20:07 +00:00
|
|
|
struct ext_log_msg *msg;
|
|
|
|
char *file = NULL, *fmt;
|
2016-12-24 00:32:10 +00:00
|
|
|
unsigned int num_args;
|
|
|
|
|
|
|
|
if (len < sizeof(struct ext_log_msg)) {
|
|
|
|
printf("too short ext_log_msg.\n");
|
2017-01-01 15:28:57 +00:00
|
|
|
return;
|
2016-12-24 00:32:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
msg = (struct ext_log_msg *) data;
|
2017-01-01 15:42:12 +00:00
|
|
|
num_args = msg->hdr.num_args;
|
2017-01-21 10:20:07 +00:00
|
|
|
fmt = (char *) msg->params + num_args*sizeof(msg->params[0]);
|
2016-12-24 00:32:10 +00:00
|
|
|
file = fmt + strlen(fmt) + 1;
|
|
|
|
|
2017-01-01 11:00:38 +00:00
|
|
|
printf("MSG(%u|%u|%s:%u): ", osmo_load16le(&msg->subsys_id),
|
2017-01-01 15:42:12 +00:00
|
|
|
diag_ts_to_epoch(osmo_load64le(&msg->hdr.timestamp)),
|
2017-01-01 11:00:38 +00:00
|
|
|
file, osmo_load16le(&msg->line_nr));
|
2017-01-08 12:45:54 +00:00
|
|
|
|
|
|
|
/* replace all '%s' with '%p', as %s obviously doesn't work */
|
|
|
|
for (char *cur = fmt; cur && (cur < fmt + strlen(fmt)); cur = strstr(fmt, "%s")) {
|
|
|
|
cur[1] = 'p';
|
|
|
|
}
|
|
|
|
|
2016-12-24 00:32:10 +00:00
|
|
|
switch (num_args) {
|
|
|
|
case 0:
|
|
|
|
fputs(fmt, stdout);
|
|
|
|
break;
|
|
|
|
case 1:
|
2017-01-01 11:00:38 +00:00
|
|
|
printf(fmt, osmo_load32le(&msg->params[0]));
|
2016-12-24 00:32:10 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
2017-01-01 11:00:38 +00:00
|
|
|
printf(fmt, osmo_load32le(&msg->params[0]),
|
|
|
|
osmo_load32le(&msg->params[1]));
|
2016-12-24 00:32:10 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2017-01-01 11:00:38 +00:00
|
|
|
printf(fmt, osmo_load32le(&msg->params[0]),
|
|
|
|
osmo_load32le(&msg->params[1]),
|
|
|
|
osmo_load32le(&msg->params[2]));
|
2016-12-24 00:32:10 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2017-01-01 11:00:38 +00:00
|
|
|
printf(fmt, osmo_load32le(&msg->params[0]),
|
|
|
|
osmo_load32le(&msg->params[1]),
|
|
|
|
osmo_load32le(&msg->params[2]),
|
|
|
|
osmo_load32le(&msg->params[3]));
|
2016-12-24 00:32:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|
|
|
|
|
2017-01-01 15:42:12 +00:00
|
|
|
static void diag_rx_ext_msg_terse_f(struct diag_instance *di, struct msgb *msgb)
|
|
|
|
{
|
|
|
|
const uint8_t *data = msgb_data(msgb);
|
|
|
|
const size_t len = msgb_length(msgb);
|
|
|
|
const struct qsr_ext_msg_terse *msg;
|
|
|
|
unsigned int num_args;
|
|
|
|
|
|
|
|
if (len < sizeof(struct qsr_ext_msg_terse)) {
|
|
|
|
printf("too short ext_log_msg.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = (struct qsr_ext_msg_terse *) data;
|
|
|
|
num_args = msg->hdr.num_args;
|
|
|
|
|
|
|
|
printf("MSG_QS(%u|%u|%08x:%u): ", osmo_load16le(&msg->subsys_id),
|
|
|
|
diag_ts_to_epoch(osmo_load64le(&msg->hdr.timestamp)),
|
|
|
|
osmo_load32le(&msg->hash), osmo_load16le(&msg->line_nr));
|
|
|
|
switch (num_args) {
|
|
|
|
case 0:
|
|
|
|
fputs("", stdout);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
printf("%08x", osmo_load32le(&msg->params[0]));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
printf("%08x %08x", osmo_load32le(&msg->params[0]),
|
|
|
|
osmo_load32le(&msg->params[1]));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
printf("%08x %08x %08x", osmo_load32le(&msg->params[0]),
|
|
|
|
osmo_load32le(&msg->params[1]),
|
|
|
|
osmo_load32le(&msg->params[2]));
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
printf("%08x %08x %08x %08x", osmo_load32le(&msg->params[0]),
|
|
|
|
osmo_load32le(&msg->params[1]),
|
|
|
|
osmo_load32le(&msg->params[2]),
|
|
|
|
osmo_load32le(&msg->params[3]));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fputc('\n', stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-01 15:28:57 +00:00
|
|
|
struct diag_cmd_dispatch_tbl cmd_tbl[] = {
|
|
|
|
{ DIAG_EXT_MSG_F, diag_rx_ext_msg_f },
|
2017-01-01 15:42:12 +00:00
|
|
|
{ DIAG_QSR_EXT_MSG_TERSE_F, diag_rx_ext_msg_terse_f },
|
2017-01-01 15:28:57 +00:00
|
|
|
};
|
2016-12-24 00:32:10 +00:00
|
|
|
|
2017-01-01 15:28:57 +00:00
|
|
|
static __attribute__((constructor)) void on_dso_load_msg(void)
|
|
|
|
{
|
|
|
|
diag_cmd_reg_dispatch(cmd_tbl, ARRAY_SIZE(cmd_tbl));
|
|
|
|
}
|