aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/e1d/proto.h
blob: 6457f14daed6f4286e47393044cdd91f46a42370 (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
/*
 * proto.h
 *
 * (C) 2019 by Sylvain Munaut <tnt@246tNt.com>
 * (C) 2020 by Harald Welte <laforge@gnumonks.org>
 *
 * All Rights Reserved
 *
 * SPDX-License-Identifier: LGPL-3.0-or-later
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 3 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 Lesser General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include <stdint.h>

#include <osmocom/core/select.h>
#include <osmocom/core/utils.h>


/*	E1DP_CMD_INTF_QUERY
 *	filter: intf (optional)
 *	in: n/a
 *	out: array of osmo_e1dp_intf_info
 *
 * 	E1DP_CMD_LINE_QUERY
 * 	filter: intf (required), line (optional)
 * 	in: n/a
 * 	out: array of osmo_e1dp_line_info
 *
 * 	E1DP_CMD_TS_QUERY
 * 	filter: intf (required), line (required), ts (optional)
 * 	in: n/a
 * 	out: array of osmo_e1dp_ts_info
 *
 *      E1DP_CMD_LINE_CONFIG
 *      filter: intf (required), line (required)
 *      in: osmo_e1dp_line_config
 *      out: osmo_e1dp_line_info
 *
 * 	E1DP_CMD_TS_OPEN
 * 	filter: intf (required), line (required), ts (required)
 * 	in: osmo_e1dp_ts_config
 * 	out: osmo_e1dp_ts_info with the opened TS (or an invalid one with id == -1 for errors)
 * 	    + message with the file descriptor
 */

enum osmo_e1dp_msg_type {
	E1DP_CMD_INTF_QUERY	= 0x00,
	E1DP_CMD_LINE_QUERY	= 0x01,
	E1DP_CMD_TS_QUERY	= 0x02,
	E1DP_CMD_LINE_CONFIG	= 0x03,
	E1DP_CMD_TS_OPEN	= 0x04,
	E1DP_EVT_TYPE		= 0x40,
	E1DP_RESP_TYPE		= 0x80,
	E1DP_ERR_TYPE		= 0xc0,
	E1DP_TYPE_MSK		= 0xc0,
};

enum osmo_e1dp_line_mode {
	E1DP_LMODE_OFF		= 0x00,
	E1DP_LMODE_CHANNELIZED	= 0x20,
	E1DP_LMODE_SUPERCHANNEL	= 0x21,
};

enum osmo_e1dp_ts_mode {
	E1DP_TSMODE_OFF		= 0x00,
	E1DP_TSMODE_RAW		= 0x10,
	E1DP_TSMODE_HDLCFCS	= 0x11,
};

/* osmo_e1dp_ts_config.flags */
#define E1DP_TS_OPEN_F_FORCE	0x80

/* the idea here is to use the first byte as a version number, to prevent incompatible
 * clients from connecting to e1d */
#define E1DP_MAGIC	0x01e1
#define E1DP_MAX_LEN	4096
#define E1DP_TS_SUPERCHAN 0xfe
#define E1DP_INVALID	0xff
#define E1DP_DEFAULT_SOCKET "/tmp/osmo-e1d.ctl"


struct osmo_e1dp_msg_hdr {
	uint16_t magic;
	uint16_t len;

	uint8_t  type; 
	uint8_t  intf;
	uint8_t  line;
	uint8_t  ts;
} __attribute__((packed));

struct osmo_e1dp_intf_info {
	uint8_t id;
	uint8_t n_lines;
} __attribute__((packed));

struct osmo_e1dp_line_config {
	uint8_t mode;
} __attribute__((packed));

struct osmo_e1dp_line_info {
	uint8_t id;
	struct osmo_e1dp_line_config cfg;
	uint8_t status;		/* TBD */
} __attribute__((packed));

struct osmo_e1dp_ts_config {
	uint8_t mode;
	uint8_t flags;
	uint16_t read_bufsize;
} __attribute__((packed));

struct osmo_e1dp_ts_info {
	uint8_t id;
	struct osmo_e1dp_ts_config cfg;
	uint8_t status;		/* TBD */
} __attribute__((packed));


struct msgb *osmo_e1dp_recv(struct osmo_fd *ofd, int *fd);
int osmo_e1dp_send(struct osmo_fd *ofd, struct msgb *msgb, int fd);

extern const struct value_string osmo_e1dp_msg_type_names[];
extern const struct value_string osmo_e1dp_line_mode_names[];
extern const struct value_string osmo_e1dp_ts_mode_names[];