aboutsummaryrefslogtreecommitdiffstats
path: root/sigtran/sua_test_common.c
blob: a0da4c1a8b73a256a192fc07f2683b05b58b986f (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
#include "sua_test_common.h"

static const struct log_info_cat log_cat[] = {
	[DMAIN] = {
		.name = "DMAIN", .loglevel = LOGL_DEBUG, .enabled = 1,
		.color = "",
		.description = "Main program",
	},
	[DSUA] = {
		.name = "DSUA", .loglevel = LOGL_DEBUG, .enabled = 1,
		.color = "",
		.description = "SCCP User Adaption",
	},
	[DXUA] = {
		.name = "DXUA", .loglevel = LOGL_DEBUG, .enabled = 1,
		.color = "",
		.description = "X User Adaption encoding/decoding",
	},

};

const struct log_info test_log_info = {
	.cat = log_cat,
	.num_cat = ARRAY_SIZE(log_cat),
};

int tx_unitdata(struct osmo_sua_link *link)
{
	struct msgb *msg = msgb_alloc(1024, "tx_unitdata");
	struct osmo_scu_prim *prim;
	struct osmo_scu_unitdata_param *param;
	uint8_t *cur;

	prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
	param = &prim->u.unitdata;
	param->calling_addr.presence = OSMO_SCCP_ADDR_T_SSN;
	param->called_addr.presence = OSMO_SCCP_ADDR_T_SSN;
	osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_REQUEST, msg);

	cur = msg->l2h = msgb_put(msg, 3);
	cur[0] = 1; cur[1] = 2; cur[2] = 3;

	return osmo_sua_user_link_down(link, &prim->oph);
}

static void sccp_make_addr_pc_ssn(struct osmo_sccp_addr *addr, uint32_t pc, uint32_t ssn)
{
	addr->presence = OSMO_SCCP_ADDR_T_SSN | OSMO_SCCP_ADDR_T_PC;
	addr->ssn = ssn;
	addr->pc = pc;
}

#define SSN_RANAP 142

struct osmo_prim_hdr *make_conn_req(uint32_t conn_id)
{
	struct msgb *msg = msgb_alloc(1024, "conn_req");
	struct osmo_scu_prim *prim;

	prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
	osmo_prim_init(&prim->oph, SCCP_SAP_USER,
			OSMO_SCU_PRIM_N_CONNECT,
			PRIM_OP_REQUEST, msg);
	/* Set SSN for calling and called addr */
	sccp_make_addr_pc_ssn(&prim->u.connect.called_addr, 2, SSN_RANAP);
	sccp_make_addr_pc_ssn(&prim->u.connect.calling_addr, 1, SSN_RANAP);
	prim->u.connect.sccp_class = 2;
	prim->u.connect.conn_id = conn_id;

	return &prim->oph;
}

int tx_conn_req(struct osmo_sua_link *link, uint32_t conn_id)
{
	struct osmo_prim_hdr *prim = make_conn_req(conn_id);
	return osmo_sua_user_link_down(link, prim);
}

struct osmo_prim_hdr *
make_dt1_req(uint32_t conn_id, const uint8_t *data, unsigned int len)
{
	struct msgb *msg = msgb_alloc(1024, "dt1");
	struct osmo_scu_prim *prim;

	prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
	osmo_prim_init(&prim->oph, SCCP_SAP_USER,
			OSMO_SCU_PRIM_N_DATA,
			PRIM_OP_REQUEST, msg);
	prim->u.data.conn_id = conn_id;

	msg->l2h = msgb_put(msg, len);
	memcpy(msg->l2h, data, len);

	return &prim->oph;
}