summaryrefslogtreecommitdiffstats
path: root/include/s_fmt.h
blob: ed3d5cf24580c20347c763a18ac0de7a5b5a35f8 (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
#ifndef _DECT_S_FMT_H
#define _DECT_S_FMT_H

#include <assert.h>
#include <identities.h>

/*
 * S-Format message header
 */

#define DECT_S_HDR_SIZE				2

/* Transaction Identifier (TI) element */
#define DECT_S_TI_F_FLAG			0x80

#define DECT_S_TI_TV_MASK			0x70
#define DECT_S_TI_TV_SHIFT			4

#define DECT_S_TI_TV_EXT_FLAG			0x08

/* Protocol Descriminator (PD) element */
#define DECT_S_PD_MASK				0x0f

/**
 * @DECT_S_PD_LCE:	Link Control Entity (LCE) messages
 * @DECT_S_PD_CC:	Call Control (CC) messages
 * @DECT_S_PD_CISS:	Call Independant Supplementary Services (CISS) messages
 * @DECT_S_PD_MM:	Mobility Management (MM) messages
 * @DECT_S_PD_CLMS:	ConnectionLess Message Service (CLMS) messages
 * @DECT_S_PD_COMS:	Connection Orentied Message Service (COMS) messages
 * @DECT_S_PD_UNKNOWN:	Unknown protocol entity (bit 8)
 */
enum dect_s_pd_values {
	DECT_S_PD_LCE				= 0x0,
	DECT_S_PD_CC				= 0x3,
	DECT_S_PD_CISS				= 0x4,
	DECT_S_PD_MM				= 0x5,
	DECT_S_PD_CLMS				= 0x6,
	DECT_S_PD_COMS				= 0x7,
	DECT_S_PD_UNKNOWN			= 0x8,
	__DECT_S_PD_MAX
};
#define DECT_S_PD_MAX				(__DECT_S_PD_MAX - 1)

/* Message type element */
#define DECT_S_PD_MSG_TYPE_MASK			0x7f

/* CLMS message types */
enum dect_clms_msg_types {
	DECT_CLMS_VARIABLE			= 0x1,
};

/*
 * Information elements
 */

#define DECT_SFMT_IE_FIXED_LEN			0x80
#define DECT_SFMT_IE_FIXED_ID_MASK		0x70
#define DECT_SFMT_IE_FIXED_ID_SHIFT		4
#define DECT_SFMT_IE_FIXED_VAL_MASK		0x0f

enum dect_sfmt_single_octet_ies {
	S_SO_IE_RESERVED			= (0x00 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
	S_SO_IE_SHIFT				= (0x01 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
	S_SO_IE_EXT_PREFIX			= (0x02 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
	S_SO_IE_REPEAT_INDICATOR		= (0x05 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
	S_SO_IE_DOUBLE_OCTET_ELEMENT		= (0x06 << DECT_SFMT_IE_FIXED_ID_SHIFT) | DECT_SFMT_IE_FIXED_LEN,
};

enum dect_sfmt_single_octet_ext_ies {
	S_SE_IE_SENDING_COMPLETE		= 0x1 | S_SO_IE_EXT_PREFIX,
	S_SE_IE_DELIMITER_REQUEST		= 0x2 | S_SO_IE_EXT_PREFIX,
	S_SE_IE_USE_TPUI			= 0x3 | S_SO_IE_EXT_PREFIX,
};

enum dect_sfmt_double_octet_ies {
	S_DO_IE_BASIC_SERVICE			= 0x0 | S_SO_IE_DOUBLE_OCTET_ELEMENT,
	S_DO_IE_RELEASE_REASON			= 0x2 | S_SO_IE_DOUBLE_OCTET_ELEMENT,
	S_DO_IE_SIGNAL				= 0x4 | S_SO_IE_DOUBLE_OCTET_ELEMENT,
	S_DO_IE_TIMER_RESTART			= 0x5 | S_SO_IE_DOUBLE_OCTET_ELEMENT,
	S_DO_IE_TEST_HOOK_CONTROL		= 0x6 | S_SO_IE_DOUBLE_OCTET_ELEMENT,
	S_DO_IE_SINGLE_DISPLAY			= 0x8 | S_SO_IE_DOUBLE_OCTET_ELEMENT,
	S_DO_IE_SINGLE_KEYPAD			= 0x9 | S_SO_IE_DOUBLE_OCTET_ELEMENT,
	S_DO_IE_RESERVED			= 0xf | S_SO_IE_DOUBLE_OCTET_ELEMENT,
};

enum dect_sfmt_variable_length_ies {
	S_VL_IE_INFO_TYPE			= 0x01,
	S_VL_IE_IDENTITY_TYPE			= 0x02,
	S_VL_IE_PORTABLE_IDENTITY		= 0x05,
	S_VL_IE_FIXED_IDENTITY			= 0x06,
	S_VL_IE_LOCATION_AREA			= 0x07,
	S_VL_IE_NWK_ASSIGNED_IDENTITY		= 0x09,
	S_VL_IE_AUTH_TYPE			= 0x0a,
	S_VL_IE_ALLOCATION_TYPE			= 0x0b,
	S_VL_IE_RAND				= 0x0c,
	S_VL_IE_RES				= 0x0d,
	S_VL_IE_RS				= 0x0e,
	S_VL_IE_IWU_ATTRIBUTES			= 0x12,
	S_VL_IE_CALL_ATTRIBUTES			= 0x13,
	S_VL_IE_SERVICE_CHANGE_INFO		= 0x16,
	S_VL_IE_CONNECTION_ATTRIBUTES		= 0x17,
	S_VL_IE_CIPHER_INFO			= 0x19,
	S_VL_IE_CALL_IDENTITY			= 0x1a,
	S_VL_IE_CONNECTION_IDENTITY		= 0x1b,
	S_VL_IE_FACILITY			= 0x1c,
	S_VL_IE_PROGRESS_INDICATOR		= 0x1e,
	S_VL_IE_MMS_GENERIC_HEADER		= 0x20,
	S_VL_IE_MMS_OBJECT_HEADER		= 0x21,
	S_VL_IE_MMS_EXTENDED_HEADER		= 0x22,
	S_VL_IE_TIME_DATE			= 0x23,
	S_VL_IE_MULTI_DISPLAY			= 0x28,
	S_VL_IE_MULTI_KEYPAD			= 0x2c,
	S_VL_IE_FEATURE_ACTIVATE		= 0x38,
	S_VL_IE_FEATURE_INDICATE		= 0x39,
	S_VL_IE_NETWORK_PARAMETER		= 0x41,
	S_VL_IE_EXT_HO_INDICATOR		= 0x42,
	S_VL_IE_ZAP_FIELD			= 0x52,
	S_VL_IE_SERVICE_CLASS			= 0x54,
	S_VL_IE_KEY				= 0x56,
	S_VL_IE_REJECT_REASON			= 0x60,
	S_VL_IE_SETUP_CAPABILITY		= 0x62,
	S_VL_IE_TERMINAL_CAPABILITY		= 0x63,
	S_VL_IE_END_TO_END_COMPATIBILITY	= 0x64,
	S_VL_IE_RATE_PARAMETERS			= 0x65,
	S_VL_IE_TRANSIT_DELAY			= 0x66,
	S_VL_IE_WINDOW_SIZE			= 0x67,
	S_VL_IE_CALLING_PARTY_NUMBER		= 0x6c,
	S_VL_IE_CALLING_PARTY_NAME		= 0x6d,
	S_VL_IE_CALLED_PARTY_NUMBER		= 0x70,
	S_VL_IE_CALLED_PARTY_SUBADDR		= 0x71,
	S_VL_IE_DURATION			= 0x72,
	S_VL_IE_SEGMENTED_INFO			= 0x75,
	S_VL_IE_ALPHANUMERIC			= 0x76,
	S_VL_IE_IWU_TO_IWU			= 0x77,
	S_VL_IE_MODEL_IDENTIFIER		= 0x78,
	S_VL_IE_IWU_PACKET			= 0x7a,
	S_VL_IE_ESCAPE_TO_PROPRIETARY		= 0x7b,
	S_VL_IE_CODEC_LIST			= 0x7c,
	S_VL_IE_EVENTS_NOTIFICATION		= 0x7d,
	S_VL_IE_CALL_INFORMATION		= 0x7e,
	S_VL_IE_ESCAPE_FOR_EXTENSION		= 0x7f,
	__S_VL_IE_MAX
};

/* Repeat indicator */

/* Basic service */

#define DECT_BASIC_SERVICE_CALL_CLASS_MASK	0xf0
#define DECT_BASIC_SERVICE_CALL_CLASS_SHIFT	4

#define DECT_BASIC_SERVICE_SERVICE_MASK		0x0f

/* Single display IE */

/* Single keypad IE */

/* Release reason */

/* Allocation type IE */

/* Alphanumeric IE */

/* Auth type IE */

/* Call attributes IE */

/* Call identity IE */

/* Called party number IE */

/* Called party subaddress IE */

/* Calling party number IE */

/* Cipher info IE */

/* Connection attributes IE */

/* Connection identity IE */

/* Duration IE */

/* End-to-end compatibility IE */

/* Facility IE */

/* Feature activate IE */

/* Feature indicate IE */

/* Fixed identity IE */

#define S_VL_IE_FIXED_IDENTITY_MIN_SIZE		2

#define S_VL_IE_FIXED_IDENTITY_TYPE_MASK	0x7f
#define S_VL_IE_FIXED_IDENTITY_LENGTH_MASK	0x7f

/* Identity type IE */

/* Info type IE */

/* InterWorking Unit (IWU) attributes IE */

/* IWU packet IE */

/* IWU to IWU IE */

/* Key IE */

/* Location area IE */

/* Multi-display IE */

/* Multi-keypad IE */

/* NetWorK (NWK) assigned identity IE */

/* Network parameter IE */

/* Portable identity IE */

#define S_VL_IE_PORTABLE_IDENTITY_MIN_SIZE		2

#define S_VL_IE_PORTABLE_IDENTITY_TYPE_MASK		0x7f
#define S_VL_IE_PORTABLE_IDENTITY_LENGTH_MASK		0x7f

/* IPUI */

#define IPUI_BITS_PER_DIGIT			4
#define IPUI_PUT_PSTN_ISDN_NUMBER_MAX_DIGITS	60

#define IPUI_PUT_PRIVATE_NUMBER_MAX_LEN		60

/* Progress indicator IE */

#define DECT_SFMT_IE_PROGRESS_INDICATOR_LOCATION_MASK	0x0f

/* RAND IE */

/* Rate parameters IE */

/* Reject reason IE */

/* RES IE */

/* RS IE */

/* Segmented info IE */

/* Service change info IE */

/* Service class IE */

/* Setup capability IE */

/* Terminal capability IE */

/* Transit delay IE */

/* Window size IE */

/* ZAP field IE */

/* Escape to proprietary IE */

#define DECT_ESC_TO_PROPRIETARY_IE_DESC_TYPE_MASK	0x7f
#define DECT_ESC_TO_PROPRIETARY_IE_DESC_EMC		1

/* Model identifier IE */

/* MMS Generic Header IE */

/* MMS Object Header IE */

/* MMS Extended Header IE */

/* Time-Data IE */

/* Ext h/o indicator IE */

/* Authentication Reject Parameter IE */

/* Calling party Name IE */

/* Codec List IE */

/* Events notification IE */

/* Call information IE */

enum dect_sfmt_ie_status {
	DECT_SFMT_IE_NONE,
	DECT_SFMT_IE_OPTIONAL,
	DECT_SFMT_IE_MANDATORY
};

enum dect_sfmt_ie_flags {
	DECT_SFMT_IE_REPEAT		= 0x1,
	DECT_SFMT_IE_EITHER		= 0x2,
	DECT_SFMT_IE_END		= 0x4,
};

/**
 * struct dect_sfmt_ie_desc	- S-Format IE description
 *
 * @offset:	offset of corresponding S-Format IE storage
 * @type:	IE type
 * @f_p:	Status in direction FP->PP
 * @p_f:	Status in direction PP->FP
 * @flags:	Global flags
 */
struct dect_sfmt_ie_desc {
	uint16_t			type;
	enum dect_sfmt_ie_status	f_p:8;
	enum dect_sfmt_ie_status	p_f:8;
	uint8_t				flags;
};

#define DECT_SFMT_IE(_type, _f_p, _p_f, _flags) {	\
	.type	= (_type),				\
	.f_p	= DECT_SFMT_ ## _f_p,			\
	.p_f	= DECT_SFMT_ ## _p_f,			\
	.flags	= (_flags),				\
}

#define DECT_SFMT_IE_END_MSG {				\
	.flags	= DECT_SFMT_IE_END,			\
}


struct dect_sfmt_ie {
	uint8_t			*data;
	uint16_t		id;
	uint8_t			len;
};

/**
 * enum dect_sfmt_error - S-Format message parsing/construction state
 *
 * @DECT_SFMT_OK:			No error
 * @DECT_SFMT_MANDATORY_IE_MISSING:	A mandatory IE was missing
 * @DECT_SFMT_MANDATORY_IE_ERROR:	A mandatory IE had an internal structural error
 * @DECT_SFMT_INVALID_IE:		An invalid IE was passed to message construction
 */
enum dect_sfmt_error {
	DECT_SFMT_OK			= 0,
	DECT_SFMT_MANDATORY_IE_MISSING	= -1,
	DECT_SFMT_MANDATORY_IE_ERROR	= -2,
	DECT_SFMT_INVALID_IE		= -3,
};

/**
 * struct dect_msg_common - Common dummy msg structure to avoid casts
 *
 * @ie:		First IE
 */
struct dect_msg_common {
	struct dect_ie_common		*ie[0];
};

struct dect_msg_buf;
extern enum dect_sfmt_error dect_parse_sfmt_msg(const struct dect_handle *dh,
						const struct dect_sfmt_ie_desc *desc,
						struct dect_msg_common *dst,
						struct dect_msg_buf *mb);
extern enum dect_sfmt_error dect_build_sfmt_msg(const struct dect_handle *dh,
						const struct dect_sfmt_ie_desc *desc,
						const struct dect_msg_common *src,
						struct dect_msg_buf *mb);

extern void dect_msg_free(const struct dect_handle *dh,
			  const struct dect_sfmt_ie_desc *desc,
			  struct dect_msg_common *msg);

#endif /* _DECT_S_FMT_H */