summaryrefslogtreecommitdiffstats
path: root/include/lce.h
blob: 15b4ee687fbcc777010dccf4dae80b659203cb56 (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 * DECT Link Control Entity (LCE)
 *
 * Copyright (c) 2009 Patrick McHardy <kaber@trash.net>
 */

#ifndef _DECT_LCE_H
#define _DECT_LCE_H

#include <assert.h>
#include <linux/dect.h>
#include <list.h>
#include <s_fmt.h>
#include <utils.h>

static inline void dect_mbuf_dump(const struct dect_msg_buf *mb,
				  const char *prefix)
{
	dect_hexdump(prefix, mb->data, mb->len);
}

/**
 * enum dect_transaction_role - the LCE's role in a transaction
 *
 * @DECT_TRANSACTION_INITIATOR:	Transaction was initiated by higher layer protocol entity
 * @DECT_TRANSACTION_RESPONDER:	Transaction was initiated by network
 */
enum dect_transaction_role {
	DECT_TRANSACTION_INITIATOR,
	DECT_TRANSACTION_RESPONDER,
};

/* Connectionless NWK layer transaction value */
#define DECT_TV_CONNECTIONLESS		6

/**
 * struct dect_transaction - DECT protocol transaction
 *
 * @list:	Datalink transaction list node
 * @link:	Associated data link
 * @pd:		Protocol discriminator
 * @role:	Role (initiator/responder)
 * @tv:		Transaction value
 */
enum dect_s_pd_values;
struct dect_transaction {
	struct list_head		list;
	struct dect_data_link		*link;
	enum dect_s_pd_values		pd;
	enum dect_transaction_role	role;
	uint16_t			tv;
};

extern int dect_open_transaction(struct dect_handle *dh,
				 struct dect_transaction *ta,
				 const struct dect_ipui *ipui);
extern void dect_confirm_transaction(struct dect_handle *dh,
				     struct dect_transaction *ta,
				     const struct dect_transaction *req);
extern void dect_close_transaction(struct dect_handle *dh,
				   struct dect_transaction *ta);
extern void dect_transaction_get_ulei(struct sockaddr_dect_lu *addr,
				      const struct dect_transaction *ta);

extern int dect_lce_send(const struct dect_handle *dh,
			 const struct dect_transaction *ta,
	  		 const struct dect_sfmt_ie_desc *desc,
			 const struct dect_msg_common *msg, uint8_t type,
			 const char *prefix);

/**
 * struct dect_nwk_protocol - NWK layer protocol
 *
 * @name:	Protocol name
 * @pd:		Protocol discriminator
 * @open:	Open a new transaction initiated by the network
 * @shutdown:	Perform an active shutdown of the transaction
 * @rcv:	Receive a message related to an active transaction
 */
struct dect_nwk_protocol {
	const char		*name;
	enum dect_s_pd_values	pd;
	uint16_t		max_transactions;
	void			(*open)(struct dect_handle *dh,
				        const struct dect_transaction *req,
				        struct dect_msg_buf *mb);
	void			(*shutdown)(struct dect_handle *dh,
					    struct dect_transaction *req);
	void			(*rcv)(struct dect_handle *dh,
				       struct dect_transaction *ta,
				       struct dect_msg_buf *mb);
};

extern void dect_lce_register_protocol(const struct dect_nwk_protocol *protocol);

/**
 * struct dect_lte - Location Table Entry
 *
 * @list:	Location table list node
 * @ipui:	International Portable User ID
 * @tpui:	Temporary Portable User ID
 */
struct dect_lte {
	struct list_head		list;
	struct dect_ipui		ipui;
	struct dect_tpui		tpui;
};

struct dect_location_table {
	struct list_head		entries;
};

enum dect_data_link_states {
	DECT_DATA_LINK_RELEASED,
	DECT_DATA_LINK_ESTABLISHED,
	DECT_DATA_LINK_ESTABLISH_PENDING,
	DECT_DATA_LINK_RELEASE_PENDING,
	DECT_DATA_LINK_SUSPENDED,
	DECT_DATA_LINK_SUSPEND_PENDING,
	DECT_DATA_LINK_RESUME_PENDING,
	__DECT_DATA_LINK_STATE_MAX
};
#define DECT_DATA_LINK_STATE_MAX	(__DECT_DATA_LINK_STATE_MAX - 1)

/**
 * struct dect_data_link
 *
 * @list:	DECT handle link list node
 * @dfd:	Associated socket file descriptor
 * @dlei:	Data Link Endpoint identifier
 * @ipui:	International Portable User ID
 * @state:	Data link state
 * @sdu_timer:	Establish without SDU timer
 * @msg_queue:	Message queue used during ESTABLISH_PENDING state
 */
struct dect_data_link {
	struct list_head		list;
	struct sockaddr_dect_ssap	dlei;
	struct dect_ipui		ipui;
	struct dect_fd			*dfd;
	enum dect_data_link_states	state;
	struct dect_timer		*sdu_timer;
	struct list_head		transactions;
	struct list_head		msg_queue;
};

#define DECT_DDL_ESTABLISH_SDU_TIMEOUT	5	/* seconds */

extern int dect_lce_group_ring(struct dect_handle *dh,
			       enum dect_ring_patterns pattern);

/* LCE message types */
enum dect_lce_msg_types {
	DECT_LCE_PAGE_RESPONSE			= 0x71,
	DECT_LCE_PAGE_REJECT			= 0x72,
};

/**
 * struct dect_lce_page_response - LCE Page response S-Format message
 *
 * @common:			Message header
 * @portable_identity:		Portable Identity IE
 * @fixed_identity:		Fixed Identity IE
 * @nwk_assigned_identity:	NWK-assigned Identity IE (optional)
 * @cipher_info:		Cipher Info IE (optional)
 * @escape_to_proprietary:	Escape to proprietary IE (optional)
 */
struct dect_lce_page_response {
	struct dect_msg_common			common;
	struct dect_ie_portable_identity	*portable_identity;
	struct dect_ie_fixed_identity		*fixed_identity;
	struct dect_ie_nwk_assigned_identity	*nwk_assigned_identity;
	struct dect_ie_cipher_info		*cipher_info;
	struct dect_ie_escape_to_proprietary	*escape_to_proprietary;
};

/**
 * struct dect_lce_page_reject - LCE Page reject S-Format message
 *
 * @common:			Message header
 * @portable_identity:		Portable Identity IE
 * @fixed_identity:		Fixed Identity IE
 * @reject_reason:		Reject reason IE
 * @escape_to_proprietary:	Escape to proprietary IE (optional)
 */
struct dect_lce_page_reject {
	struct dect_msg_common			common;
	struct dect_ie_portable_identity	*portable_identity;
	struct dect_ie_fixed_identity		*fixed_identity;
	struct dect_ie_reject_reason		*reject_reason;
	struct dect_ie_escape_to_proprietary	*escape_to_proprietary;
};

extern int dect_lce_init(struct dect_handle *dh);
extern void dect_lce_exit(struct dect_handle *dh);

#endif /* _DECT_LCE_H */