summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/src/misc/app_phy_info.c
blob: 508dabef6dbc99e397759a71dd911789ad6736f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * PHY info / features negotiation test
 *
 * (C) 2018 by Vadim Yanitskiy <axilirator@gmail.com>
 *
 * All Rights Reserved
 *
 * 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.
 *
 */

#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#include <osmocom/core/negotiation.h>
#include <osmocom/core/signal.h>
#include <osmocom/core/msgb.h>

#include <osmocom/bb/common/osmocom_data.h>
#include <osmocom/bb/common/l23_app.h>
#include <osmocom/bb/common/l1ctl.h>

#include <l1ctl_proto.h>

extern int quit;

static struct value_string fdesc[] = {
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_BAND_400),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_BAND_850),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_BAND_900),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_BAND_DCS),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_BAND_PCS),

	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CODEC_HR),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CODEC_FR),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CODEC_EFR),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CODEC_HR_AMR),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CODEC_FR_AMR),

	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CHAN_XCCH),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CHAN_TCHF),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CHAN_TCHH),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CHAN_CBCH),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_CHAN_PTCH),

	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_A5_1),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_A5_2),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_A5_3),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_A5_4),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_A5_5),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_A5_6),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_A5_7),

	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_TX),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_FH),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_PM),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_NEIGH_PM),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_SIM),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_MEAS_REP),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_BURST_TRX),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_BURST_IND),
	OSMO_VALUE_STRING(L1CTL_PHY_FEATURE_TRAFFIC),

	{ 0, NULL }
};

static void parse_nego_info(struct msgb *msg)
{
	struct l1ctl_phy_nego_ind *hdr;
	const uint8_t *features;
	size_t features_len;
	const char *info;
	bool present;
	int i;

	hdr = (struct l1ctl_phy_nego_ind *) msg->l1h;

	info = osmo_nego_get_info(hdr->data, hdr->len, L1CTL_PHY_INFO_NAME);
	printf("[i] PHY name: %s\n", info);

	features = (uint8_t *) osmo_nego_get_info(hdr->data, hdr->len,
		L1CTL_PHY_INFO_FEATURES);
	if (!features) {
		printf("[!] PHY features: none\n");
		quit = 1;
		return;
	}

	/* HACK, modify the API */
	features_len = msg->tail - features;

	for (i = 0; i < _L1CTL_PHY_FEATURE_MAX; i++) {
		present = osmo_nego_check_feature(features, features_len, i);
		if (present)
			printf("[i] PHY feature: %s\n", get_value_string(fdesc, i));
	}

	/* We are done */
	quit = 1;
}

static int signal_cb(unsigned int subsys, unsigned int signal,
		     void *handler_data, void *signal_data)
{
	struct osmocom_ms *ms = (struct osmocom_ms *) signal_data;

	/* FIXME: ignore other signals? */
	if (subsys != SS_L1CTL)
		return 0;

	switch (signal) {
	case S_L1CTL_RESET:
		printf("RESET received, requesting info negotiation again...\n");
		l1ctl_tx_nego_req(ms);
		break;
	case S_L1CTL_NEGO_IND:
		printf("Received negotiation response, parsing...\n\n");
		parse_nego_info(ms->phy_info);
	}

	return 0;
}

int l23_app_init(struct osmocom_ms *ms)
{
	/* Register L1CTL handler */
	osmo_signal_register_handler(SS_L1CTL, &signal_cb, NULL);

	/* Send negotiation request and wait for response */
	printf("Sending negotiation request...\n");
	l1ctl_tx_nego_req(ms);

	return 0;
}

static struct l23_app_info info = {
	.copyright = "(C) 2018 by Vadim Yanitskiy <axilirator@gmail.com>\n",
};

struct l23_app_info *l23_app_info()
{
	return &info;
}