1 /*
2  * libpri: An implementation of Primary Rate ISDN
3  *
4  * Copyright (C) 2009 Digium, Inc.
5  *
6  * Richard Mudgett <rmudgett@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2 as published by the
16  * Free Software Foundation. See the LICENSE file included with
17  * this program for more details.
18  *
19  * In addition, when this program is distributed with Asterisk in
20  * any form that would qualify as a 'combined work' or as a
21  * 'derivative work' (but not mere aggregation), you can redistribute
22  * and/or modify the combination under the terms of the license
23  * provided with that copy of Asterisk, instead of the license
24  * terms granted here.
25  */
26 
27 /*!
28  * \file
29  * \brief ROSE Call diversion operations
30  *
31  * Diversion Supplementary Services ETS 300 207-1 Table 3
32  *
33  * \author Richard Mudgett <rmudgett@digium.com>
34  */
35 
36 
37 #include "compat.h"
38 #include "libpri.h"
39 #include "pri_internal.h"
40 #include "rose.h"
41 #include "rose_internal.h"
42 #include "asn1.h"
43 
44 
45 /* ------------------------------------------------------------------- */
46 
47 /*!
48  * \internal
49  * \brief Encode the ServedUserNr type.
50  *
51  * \param ctrl D channel controller for diagnostic messages or global options.
52  * \param pos Starting position to encode ASN.1 component.
53  * \param end End of ASN.1 encoding data buffer.
54  * \param served_user_number Served user number information to encode.
55  *
56  * \retval Start of the next ASN.1 component to encode on success.
57  * \retval NULL on error.
58  */
rose_enc_etsi_ServedUserNumber(struct pri * ctrl,unsigned char * pos,unsigned char * end,const struct rosePartyNumber * served_user_number)59 static unsigned char *rose_enc_etsi_ServedUserNumber(struct pri *ctrl,
60 	unsigned char *pos, unsigned char *end,
61 	const struct rosePartyNumber *served_user_number)
62 {
63 	if (served_user_number->length) {
64 		/* Forward this number */
65 		pos = rose_enc_PartyNumber(ctrl, pos, end, served_user_number);
66 	} else {
67 		/* Forward all numbers */
68 		pos = asn1_enc_null(pos, end, ASN1_TYPE_NULL);
69 	}
70 
71 	return pos;
72 }
73 
74 /*!
75  * \internal
76  * \brief Encode the IntResult type.
77  *
78  * \param ctrl D channel controller for diagnostic messages or global options.
79  * \param pos Starting position to encode ASN.1 component.
80  * \param end End of ASN.1 encoding data buffer.
81  * \param tag Component tag to identify the encoded component.
82  *   The tag should be ASN1_TAG_SEQUENCE unless the caller implicitly
83  *   tags it otherwise.
84  * \param int_result Forwarding record information to encode.
85  *
86  * \retval Start of the next ASN.1 component to encode on success.
87  * \retval NULL on error.
88  */
rose_enc_etsi_IntResult(struct pri * ctrl,unsigned char * pos,unsigned char * end,unsigned tag,const struct roseEtsiForwardingRecord * int_result)89 static unsigned char *rose_enc_etsi_IntResult(struct pri *ctrl, unsigned char *pos,
90 	unsigned char *end, unsigned tag, const struct roseEtsiForwardingRecord *int_result)
91 {
92 	unsigned char *seq_len;
93 
94 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, tag);
95 
96 	ASN1_CALL(pos, rose_enc_etsi_ServedUserNumber(ctrl, pos, end,
97 		&int_result->served_user_number));
98 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
99 		int_result->basic_service));
100 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED, int_result->procedure));
101 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
102 		&int_result->forwarded_to));
103 
104 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
105 
106 	return pos;
107 }
108 
109 /*!
110  * \internal
111  * \brief Encode the IntResultList type.
112  *
113  * \param ctrl D channel controller for diagnostic messages or global options.
114  * \param pos Starting position to encode ASN.1 component.
115  * \param end End of ASN.1 encoding data buffer.
116  * \param tag Component tag to identify the encoded component.
117  *   The tag should be ASN1_TAG_SET unless the caller implicitly
118  *   tags it otherwise.
119  * \param int_result_list Forwarding record list information to encode.
120  *
121  * \retval Start of the next ASN.1 component to encode on success.
122  * \retval NULL on error.
123  */
rose_enc_etsi_IntResultList(struct pri * ctrl,unsigned char * pos,unsigned char * end,unsigned tag,const struct roseEtsiForwardingList * int_result_list)124 static unsigned char *rose_enc_etsi_IntResultList(struct pri *ctrl, unsigned char *pos,
125 	unsigned char *end, unsigned tag,
126 	const struct roseEtsiForwardingList *int_result_list)
127 {
128 	unsigned index;
129 	unsigned char *set_len;
130 
131 	ASN1_CONSTRUCTED_BEGIN(set_len, pos, end, tag);
132 
133 	for (index = 0; index < int_result_list->num_records; ++index) {
134 		ASN1_CALL(pos, rose_enc_etsi_IntResult(ctrl, pos, end, ASN1_TAG_SEQUENCE,
135 			&int_result_list->list[index]));
136 	}
137 
138 	ASN1_CONSTRUCTED_END(set_len, pos, end);
139 
140 	return pos;
141 }
142 
143 /*!
144  * \internal
145  * \brief Encode the ServedUserNumberList type.
146  *
147  * \param ctrl D channel controller for diagnostic messages or global options.
148  * \param pos Starting position to encode ASN.1 component.
149  * \param end End of ASN.1 encoding data buffer.
150  * \param tag Component tag to identify the encoded component.
151  *   The tag should be ASN1_TAG_SET unless the caller implicitly
152  *   tags it otherwise.
153  * \param served_user_number_list Served user record list information to encode.
154  *
155  * \retval Start of the next ASN.1 component to encode on success.
156  * \retval NULL on error.
157  */
rose_enc_etsi_ServedUserNumberList(struct pri * ctrl,unsigned char * pos,unsigned char * end,unsigned tag,const struct roseEtsiServedUserNumberList * served_user_number_list)158 static unsigned char *rose_enc_etsi_ServedUserNumberList(struct pri *ctrl,
159 	unsigned char *pos, unsigned char *end, unsigned tag,
160 	const struct roseEtsiServedUserNumberList *served_user_number_list)
161 {
162 	unsigned index;
163 	unsigned char *set_len;
164 
165 	ASN1_CONSTRUCTED_BEGIN(set_len, pos, end, tag);
166 
167 	for (index = 0; index < served_user_number_list->num_records; ++index) {
168 		ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
169 			&served_user_number_list->number[index]));
170 	}
171 
172 	ASN1_CONSTRUCTED_END(set_len, pos, end);
173 
174 	return pos;
175 }
176 
177 /*!
178  * \brief Encode the ActivationDiversion invoke facility ie arguments.
179  *
180  * \param ctrl D channel controller for diagnostic messages or global options.
181  * \param pos Starting position to encode ASN.1 component.
182  * \param end End of ASN.1 encoding data buffer.
183  * \param args Arguments to encode in the buffer.
184  *
185  * \retval Start of the next ASN.1 component to encode on success.
186  * \retval NULL on error.
187  */
rose_enc_etsi_ActivationDiversion_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)188 unsigned char *rose_enc_etsi_ActivationDiversion_ARG(struct pri *ctrl,
189 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
190 {
191 	const struct roseEtsiActivationDiversion_ARG *activation_diversion;
192 	unsigned char *seq_len;
193 
194 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
195 
196 	activation_diversion = &args->etsi.ActivationDiversion;
197 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
198 		activation_diversion->procedure));
199 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
200 		activation_diversion->basic_service));
201 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
202 		&activation_diversion->forwarded_to));
203 	ASN1_CALL(pos, rose_enc_etsi_ServedUserNumber(ctrl, pos, end,
204 		&activation_diversion->served_user_number));
205 
206 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
207 
208 	return pos;
209 }
210 
211 /*!
212  * \brief Encode the DeactivationDiversion invoke facility ie arguments.
213  *
214  * \param ctrl D channel controller for diagnostic messages or global options.
215  * \param pos Starting position to encode ASN.1 component.
216  * \param end End of ASN.1 encoding data buffer.
217  * \param args Arguments to encode in the buffer.
218  *
219  * \retval Start of the next ASN.1 component to encode on success.
220  * \retval NULL on error.
221  */
rose_enc_etsi_DeactivationDiversion_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)222 unsigned char *rose_enc_etsi_DeactivationDiversion_ARG(struct pri *ctrl,
223 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
224 {
225 	const struct roseEtsiDeactivationDiversion_ARG *deactivation_diversion;
226 	unsigned char *seq_len;
227 
228 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
229 
230 	deactivation_diversion = &args->etsi.DeactivationDiversion;
231 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
232 		deactivation_diversion->procedure));
233 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
234 		deactivation_diversion->basic_service));
235 	ASN1_CALL(pos, rose_enc_etsi_ServedUserNumber(ctrl, pos, end,
236 		&deactivation_diversion->served_user_number));
237 
238 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
239 
240 	return pos;
241 }
242 
243 /*!
244  * \brief Encode the ActivationStatusNotificationDiv invoke facility ie arguments.
245  *
246  * \param ctrl D channel controller for diagnostic messages or global options.
247  * \param pos Starting position to encode ASN.1 component.
248  * \param end End of ASN.1 encoding data buffer.
249  * \param args Arguments to encode in the buffer.
250  *
251  * \retval Start of the next ASN.1 component to encode on success.
252  * \retval NULL on error.
253  */
rose_enc_etsi_ActivationStatusNotificationDiv_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)254 unsigned char *rose_enc_etsi_ActivationStatusNotificationDiv_ARG(struct pri *ctrl,
255 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
256 {
257 	const struct roseEtsiActivationStatusNotificationDiv_ARG
258 		*activation_status_notification_div;
259 	unsigned char *seq_len;
260 
261 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
262 
263 	activation_status_notification_div = &args->etsi.ActivationStatusNotificationDiv;
264 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
265 		activation_status_notification_div->procedure));
266 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
267 		activation_status_notification_div->basic_service));
268 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
269 		&activation_status_notification_div->forwarded_to));
270 	ASN1_CALL(pos, rose_enc_etsi_ServedUserNumber(ctrl, pos, end,
271 		&activation_status_notification_div->served_user_number));
272 
273 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
274 
275 	return pos;
276 }
277 
278 /*!
279  * \brief Encode the DeactivationStatusNotificationDiv invoke facility ie arguments.
280  *
281  * \param ctrl D channel controller for diagnostic messages or global options.
282  * \param pos Starting position to encode ASN.1 component.
283  * \param end End of ASN.1 encoding data buffer.
284  * \param args Arguments to encode in the buffer.
285  *
286  * \retval Start of the next ASN.1 component to encode on success.
287  * \retval NULL on error.
288  */
rose_enc_etsi_DeactivationStatusNotificationDiv_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)289 unsigned char *rose_enc_etsi_DeactivationStatusNotificationDiv_ARG(struct pri *ctrl,
290 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
291 {
292 	const struct roseEtsiDeactivationStatusNotificationDiv_ARG
293 		*deactivation_status_notification_div;
294 	unsigned char *seq_len;
295 
296 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
297 
298 	deactivation_status_notification_div = &args->etsi.DeactivationStatusNotificationDiv;
299 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
300 		deactivation_status_notification_div->procedure));
301 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
302 		deactivation_status_notification_div->basic_service));
303 	ASN1_CALL(pos, rose_enc_etsi_ServedUserNumber(ctrl, pos, end,
304 		&deactivation_status_notification_div->served_user_number));
305 
306 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
307 
308 	return pos;
309 }
310 
311 /*!
312  * \brief Encode the InterrogationDiversion invoke facility ie arguments.
313  *
314  * \param ctrl D channel controller for diagnostic messages or global options.
315  * \param pos Starting position to encode ASN.1 component.
316  * \param end End of ASN.1 encoding data buffer.
317  * \param args Arguments to encode in the buffer.
318  *
319  * \retval Start of the next ASN.1 component to encode on success.
320  * \retval NULL on error.
321  */
rose_enc_etsi_InterrogationDiversion_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)322 unsigned char *rose_enc_etsi_InterrogationDiversion_ARG(struct pri *ctrl,
323 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
324 {
325 	const struct roseEtsiInterrogationDiversion_ARG *interrogation_diversion;
326 	unsigned char *seq_len;
327 
328 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
329 
330 	interrogation_diversion = &args->etsi.InterrogationDiversion;
331 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
332 		interrogation_diversion->procedure));
333 	if (interrogation_diversion->basic_service) {
334 		/* Not the DEFAULT value */
335 		ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
336 			interrogation_diversion->basic_service));
337 	}
338 	ASN1_CALL(pos, rose_enc_etsi_ServedUserNumber(ctrl, pos, end,
339 		&interrogation_diversion->served_user_number));
340 
341 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
342 
343 	return pos;
344 }
345 
346 /*!
347  * \brief Encode the InterrogationDiversion result facility ie arguments.
348  *
349  * \param ctrl D channel controller for diagnostic messages or global options.
350  * \param pos Starting position to encode ASN.1 component.
351  * \param end End of ASN.1 encoding data buffer.
352  * \param args Arguments to encode in the buffer.
353  *
354  * \retval Start of the next ASN.1 component to encode on success.
355  * \retval NULL on error.
356  */
rose_enc_etsi_InterrogationDiversion_RES(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_result_args * args)357 unsigned char *rose_enc_etsi_InterrogationDiversion_RES(struct pri *ctrl,
358 	unsigned char *pos, unsigned char *end, const union rose_msg_result_args *args)
359 {
360 	return rose_enc_etsi_IntResultList(ctrl, pos, end, ASN1_TAG_SET,
361 		&args->etsi.InterrogationDiversion);
362 }
363 
364 /*!
365  * \brief Encode the DiversionInformation invoke facility ie arguments.
366  *
367  * \param ctrl D channel controller for diagnostic messages or global options.
368  * \param pos Starting position to encode ASN.1 component.
369  * \param end End of ASN.1 encoding data buffer.
370  * \param args Arguments to encode in the buffer.
371  *
372  * \retval Start of the next ASN.1 component to encode on success.
373  * \retval NULL on error.
374  */
rose_enc_etsi_DiversionInformation_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)375 unsigned char *rose_enc_etsi_DiversionInformation_ARG(struct pri *ctrl,
376 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
377 {
378 	const struct roseEtsiDiversionInformation_ARG *diversion_information;
379 	unsigned char *seq_len;
380 	unsigned char *explicit_len;
381 
382 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
383 
384 	diversion_information = &args->etsi.DiversionInformation;
385 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
386 		diversion_information->diversion_reason));
387 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
388 		diversion_information->basic_service));
389 	if (diversion_information->served_user_subaddress.length) {
390 		ASN1_CALL(pos, rose_enc_PartySubaddress(ctrl, pos, end,
391 			&diversion_information->served_user_subaddress));
392 	}
393 	if (diversion_information->calling_present) {
394 		/* EXPLICIT tag */
395 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 0);
396 		ASN1_CALL(pos, rose_enc_PresentedAddressScreened(ctrl, pos, end,
397 			&diversion_information->calling));
398 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
399 	}
400 	if (diversion_information->original_called_present) {
401 		/* EXPLICIT tag */
402 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 1);
403 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
404 			&diversion_information->original_called));
405 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
406 	}
407 	if (diversion_information->last_diverting_present) {
408 		/* EXPLICIT tag */
409 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 2);
410 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
411 			&diversion_information->last_diverting));
412 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
413 	}
414 	if (diversion_information->last_diverting_reason_present) {
415 		/* EXPLICIT tag */
416 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 3);
417 		ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
418 			diversion_information->last_diverting_reason));
419 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
420 	}
421 	if (diversion_information->q931ie.length) {
422 		ASN1_CALL(pos, rose_enc_Q931ie(ctrl, pos, end, ASN1_CLASS_APPLICATION | 0,
423 			&diversion_information->q931ie));
424 	}
425 
426 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
427 
428 	return pos;
429 }
430 
431 /*!
432  * \brief Encode the CallDeflection invoke facility ie arguments.
433  *
434  * \param ctrl D channel controller for diagnostic messages or global options.
435  * \param pos Starting position to encode ASN.1 component.
436  * \param end End of ASN.1 encoding data buffer.
437  * \param args Arguments to encode in the buffer.
438  *
439  * \retval Start of the next ASN.1 component to encode on success.
440  * \retval NULL on error.
441  */
rose_enc_etsi_CallDeflection_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)442 unsigned char *rose_enc_etsi_CallDeflection_ARG(struct pri *ctrl, unsigned char *pos,
443 	unsigned char *end, const union rose_msg_invoke_args *args)
444 {
445 	const struct roseEtsiCallDeflection_ARG *call_deflection;
446 	unsigned char *seq_len;
447 
448 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
449 
450 	call_deflection = &args->etsi.CallDeflection;
451 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
452 		&call_deflection->deflection));
453 	if (call_deflection->presentation_allowed_to_diverted_to_user_present) {
454 		ASN1_CALL(pos, asn1_enc_boolean(pos, end, ASN1_TYPE_BOOLEAN,
455 			call_deflection->presentation_allowed_to_diverted_to_user));
456 	}
457 
458 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
459 
460 	return pos;
461 }
462 
463 /*!
464  * \brief Encode the CallRerouting invoke facility ie arguments.
465  *
466  * \param ctrl D channel controller for diagnostic messages or global options.
467  * \param pos Starting position to encode ASN.1 component.
468  * \param end End of ASN.1 encoding data buffer.
469  * \param args Arguments to encode in the buffer.
470  *
471  * \retval Start of the next ASN.1 component to encode on success.
472  * \retval NULL on error.
473  */
rose_enc_etsi_CallRerouting_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)474 unsigned char *rose_enc_etsi_CallRerouting_ARG(struct pri *ctrl, unsigned char *pos,
475 	unsigned char *end, const union rose_msg_invoke_args *args)
476 {
477 	const struct roseEtsiCallRerouting_ARG *call_rerouting;
478 	unsigned char *seq_len;
479 	unsigned char *explicit_len;
480 
481 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
482 
483 	call_rerouting = &args->etsi.CallRerouting;
484 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
485 		call_rerouting->rerouting_reason));
486 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
487 		&call_rerouting->called_address));
488 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_INTEGER,
489 		call_rerouting->rerouting_counter));
490 	ASN1_CALL(pos, rose_enc_Q931ie(ctrl, pos, end, ASN1_CLASS_APPLICATION | 0,
491 		&call_rerouting->q931ie));
492 
493 	/* EXPLICIT tag */
494 	ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 1);
495 	ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
496 		&call_rerouting->last_rerouting));
497 	ASN1_CONSTRUCTED_END(explicit_len, pos, end);
498 
499 	if (call_rerouting->subscription_option) {
500 		/* Not the DEFAULT value */
501 		/* EXPLICIT tag */
502 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 2);
503 		ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
504 			call_rerouting->subscription_option));
505 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
506 	}
507 
508 	if (call_rerouting->calling_subaddress.length) {
509 		/* EXPLICIT tag */
510 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 3);
511 		ASN1_CALL(pos, rose_enc_PartySubaddress(ctrl, pos, end,
512 			&call_rerouting->calling_subaddress));
513 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
514 	}
515 
516 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
517 
518 	return pos;
519 }
520 
521 /*!
522  * \brief Encode the InterrogateServedUserNumbers result facility ie arguments.
523  *
524  * \param ctrl D channel controller for diagnostic messages or global options.
525  * \param pos Starting position to encode ASN.1 component.
526  * \param end End of ASN.1 encoding data buffer.
527  * \param args Arguments to encode in the buffer.
528  *
529  * \retval Start of the next ASN.1 component to encode on success.
530  * \retval NULL on error.
531  */
rose_enc_etsi_InterrogateServedUserNumbers_RES(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_result_args * args)532 unsigned char *rose_enc_etsi_InterrogateServedUserNumbers_RES(struct pri *ctrl,
533 	unsigned char *pos, unsigned char *end, const union rose_msg_result_args *args)
534 {
535 	return rose_enc_etsi_ServedUserNumberList(ctrl, pos, end, ASN1_TAG_SET,
536 		&args->etsi.InterrogateServedUserNumbers);
537 }
538 
539 /*!
540  * \brief Encode the DivertingLegInformation1 invoke facility ie arguments.
541  *
542  * \param ctrl D channel controller for diagnostic messages or global options.
543  * \param pos Starting position to encode ASN.1 component.
544  * \param end End of ASN.1 encoding data buffer.
545  * \param args Arguments to encode in the buffer.
546  *
547  * \retval Start of the next ASN.1 component to encode on success.
548  * \retval NULL on error.
549  */
rose_enc_etsi_DivertingLegInformation1_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)550 unsigned char *rose_enc_etsi_DivertingLegInformation1_ARG(struct pri *ctrl,
551 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
552 {
553 	const struct roseEtsiDivertingLegInformation1_ARG *diverting_leg_information_1;
554 	unsigned char *seq_len;
555 
556 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
557 
558 	diverting_leg_information_1 = &args->etsi.DivertingLegInformation1;
559 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
560 		diverting_leg_information_1->diversion_reason));
561 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
562 		diverting_leg_information_1->subscription_option));
563 	if (diverting_leg_information_1->diverted_to_present) {
564 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
565 			&diverting_leg_information_1->diverted_to));
566 	}
567 
568 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
569 
570 	return pos;
571 }
572 
573 /*!
574  * \brief Encode the DivertingLegInformation2 invoke facility ie arguments.
575  *
576  * \param ctrl D channel controller for diagnostic messages or global options.
577  * \param pos Starting position to encode ASN.1 component.
578  * \param end End of ASN.1 encoding data buffer.
579  * \param args Arguments to encode in the buffer.
580  *
581  * \retval Start of the next ASN.1 component to encode on success.
582  * \retval NULL on error.
583  */
rose_enc_etsi_DivertingLegInformation2_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)584 unsigned char *rose_enc_etsi_DivertingLegInformation2_ARG(struct pri *ctrl,
585 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
586 {
587 	const struct roseEtsiDivertingLegInformation2_ARG *diverting_leg_information_2;
588 	unsigned char *seq_len;
589 	unsigned char *explicit_len;
590 
591 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
592 
593 	diverting_leg_information_2 = &args->etsi.DivertingLegInformation2;
594 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_INTEGER,
595 		diverting_leg_information_2->diversion_counter));
596 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
597 		diverting_leg_information_2->diversion_reason));
598 
599 	if (diverting_leg_information_2->diverting_present) {
600 		/* EXPLICIT tag */
601 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 1);
602 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
603 			&diverting_leg_information_2->diverting));
604 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
605 	}
606 
607 	if (diverting_leg_information_2->original_called_present) {
608 		/* EXPLICIT tag */
609 		ASN1_CONSTRUCTED_BEGIN(explicit_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 2);
610 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
611 			&diverting_leg_information_2->original_called));
612 		ASN1_CONSTRUCTED_END(explicit_len, pos, end);
613 	}
614 
615 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
616 
617 	return pos;
618 }
619 
620 /*!
621  * \brief Encode the DivertingLegInformation3 invoke facility ie arguments.
622  *
623  * \param ctrl D channel controller for diagnostic messages or global options.
624  * \param pos Starting position to encode ASN.1 component.
625  * \param end End of ASN.1 encoding data buffer.
626  * \param args Arguments to encode in the buffer.
627  *
628  * \retval Start of the next ASN.1 component to encode on success.
629  * \retval NULL on error.
630  */
rose_enc_etsi_DivertingLegInformation3_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)631 unsigned char *rose_enc_etsi_DivertingLegInformation3_ARG(struct pri *ctrl,
632 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
633 {
634 	return asn1_enc_boolean(pos, end, ASN1_TYPE_BOOLEAN,
635 		args->etsi.DivertingLegInformation3.presentation_allowed_indicator);
636 }
637 
638 /*!
639  * \internal
640  * \brief Decode the ServedUserNr argument parameters.
641  *
642  * \param ctrl D channel controller for any diagnostic messages.
643  * \param name Field name
644  * \param tag Component tag that identified this production.
645  * \param pos Starting position of the ASN.1 component length.
646  * \param end End of ASN.1 decoding data buffer.
647  * \param served_user_number Parameter storage to fill.
648  *
649  * \retval Start of the next ASN.1 component on success.
650  * \retval NULL on error.
651  */
rose_dec_etsi_ServedUserNumber(struct pri * ctrl,const char * name,unsigned tag,const unsigned char * pos,const unsigned char * end,struct rosePartyNumber * served_user_number)652 static const unsigned char *rose_dec_etsi_ServedUserNumber(struct pri *ctrl,
653 	const char *name, unsigned tag, const unsigned char *pos, const unsigned char *end,
654 	struct rosePartyNumber *served_user_number)
655 {
656 	if (ctrl->debug & PRI_DEBUG_APDU) {
657 		pri_message(ctrl, "  %s ServedUserNumber\n", name);
658 	}
659 	if (tag == ASN1_TYPE_NULL) {
660 		served_user_number->length = 0;
661 		pos = asn1_dec_null(ctrl, "allNumbers", tag, pos, end);
662 	} else {
663 		/* Must be a PartyNumber (Which is itself a CHOICE) */
664 		pos =
665 			rose_dec_PartyNumber(ctrl, "individualNumber", tag, pos, end,
666 				served_user_number);
667 	}
668 	return pos;
669 }
670 
671 /*!
672  * \internal
673  * \brief Decode the IntResult argument parameters.
674  *
675  * \param ctrl D channel controller for any diagnostic messages.
676  * \param name Field name
677  * \param tag Component tag that identified this production.
678  * \param pos Starting position of the ASN.1 component length.
679  * \param end End of ASN.1 decoding data buffer.
680  * \param int_result Parameter storage to fill.
681  *
682  * \retval Start of the next ASN.1 component on success.
683  * \retval NULL on error.
684  */
rose_dec_etsi_IntResult(struct pri * ctrl,const char * name,unsigned tag,const unsigned char * pos,const unsigned char * end,struct roseEtsiForwardingRecord * int_result)685 static const unsigned char *rose_dec_etsi_IntResult(struct pri *ctrl, const char *name,
686 	unsigned tag, const unsigned char *pos, const unsigned char *end,
687 	struct roseEtsiForwardingRecord *int_result)
688 {
689 	int32_t value;
690 	int length;
691 	int seq_offset;
692 	const unsigned char *seq_end;
693 
694 	if (ctrl->debug & PRI_DEBUG_APDU) {
695 		pri_message(ctrl, "  %s IntResult %s\n", name, asn1_tag2str(tag));
696 	}
697 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
698 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
699 
700 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
701 	ASN1_CALL(pos, rose_dec_etsi_ServedUserNumber(ctrl, "servedUserNr", tag, pos,
702 		seq_end, &int_result->served_user_number));
703 
704 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
705 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
706 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
707 	int_result->basic_service = value;
708 
709 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
710 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
711 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
712 	int_result->procedure = value;
713 
714 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
715 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
716 	ASN1_CALL(pos, rose_dec_Address(ctrl, "forwardedToAddress", tag, pos, seq_end,
717 		&int_result->forwarded_to));
718 
719 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
720 
721 	return pos;
722 }
723 
724 /*!
725  * \internal
726  * \brief Decode the IntResultList argument parameters.
727  *
728  * \param ctrl D channel controller for any diagnostic messages.
729  * \param name Field name
730  * \param tag Component tag that identified this production.
731  * \param pos Starting position of the ASN.1 component length.
732  * \param end End of ASN.1 decoding data buffer.
733  * \param int_result_list Parameter storage to fill.
734  *
735  * \retval Start of the next ASN.1 component on success.
736  * \retval NULL on error.
737  */
rose_dec_etsi_IntResultList(struct pri * ctrl,const char * name,unsigned tag,const unsigned char * pos,const unsigned char * end,struct roseEtsiForwardingList * int_result_list)738 static const unsigned char *rose_dec_etsi_IntResultList(struct pri *ctrl,
739 	const char *name, unsigned tag, const unsigned char *pos, const unsigned char *end,
740 	struct roseEtsiForwardingList *int_result_list)
741 {
742 	int length;
743 	int set_offset;
744 	const unsigned char *set_end;
745 
746 	if (ctrl->debug & PRI_DEBUG_APDU) {
747 		pri_message(ctrl, "  %s IntResultList %s\n", name, asn1_tag2str(tag));
748 	}
749 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
750 	ASN1_END_SETUP(set_end, set_offset, length, pos, end);
751 
752 	int_result_list->num_records = 0;
753 	while (pos < set_end && *pos != ASN1_INDEF_TERM) {
754 		if (int_result_list->num_records < ARRAY_LEN(int_result_list->list)) {
755 			ASN1_CALL(pos, asn1_dec_tag(pos, set_end, &tag));
756 			ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
757 			ASN1_CALL(pos, rose_dec_etsi_IntResult(ctrl, "listEntry", tag, pos, set_end,
758 				&int_result_list->list[int_result_list->num_records]));
759 			++int_result_list->num_records;
760 		} else {
761 			/* Too many records */
762 			return NULL;
763 		}
764 	}
765 
766 	ASN1_END_FIXUP(ctrl, pos, set_offset, set_end, end);
767 
768 	return pos;
769 }
770 
771 /*!
772  * \internal
773  * \brief Decode the ServedUserNumberList argument parameters.
774  *
775  * \param ctrl D channel controller for any diagnostic messages.
776  * \param name Field name
777  * \param tag Component tag that identified this production.
778  * \param pos Starting position of the ASN.1 component length.
779  * \param end End of ASN.1 decoding data buffer.
780  * \param served_user_number_list Parameter storage to fill.
781  *
782  * \retval Start of the next ASN.1 component on success.
783  * \retval NULL on error.
784  */
rose_dec_etsi_ServedUserNumberList(struct pri * ctrl,const char * name,unsigned tag,const unsigned char * pos,const unsigned char * end,struct roseEtsiServedUserNumberList * served_user_number_list)785 static const unsigned char *rose_dec_etsi_ServedUserNumberList(struct pri *ctrl,
786 	const char *name, unsigned tag, const unsigned char *pos, const unsigned char *end,
787 	struct roseEtsiServedUserNumberList *served_user_number_list)
788 {
789 	int length;
790 	int set_offset;
791 	const unsigned char *set_end;
792 
793 	if (ctrl->debug & PRI_DEBUG_APDU) {
794 		pri_message(ctrl, "  %s ServedUserNumberList %s\n", name, asn1_tag2str(tag));
795 	}
796 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
797 	ASN1_END_SETUP(set_end, set_offset, length, pos, end);
798 
799 	served_user_number_list->num_records = 0;
800 	while (pos < set_end && *pos != ASN1_INDEF_TERM) {
801 		if (served_user_number_list->num_records <
802 			ARRAY_LEN(served_user_number_list->number)) {
803 			ASN1_CALL(pos, asn1_dec_tag(pos, set_end, &tag));
804 			ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "listEntry", tag, pos, set_end,
805 				&served_user_number_list->number[served_user_number_list->num_records]));
806 			++served_user_number_list->num_records;
807 		} else {
808 			/* Too many records */
809 			return NULL;
810 		}
811 	}
812 
813 	ASN1_END_FIXUP(ctrl, pos, set_offset, set_end, end);
814 
815 	return pos;
816 }
817 
818 /*!
819  * \brief Decode the ActivationDiversion invoke argument parameters.
820  *
821  * \param ctrl D channel controller for diagnostic messages or global options.
822  * \param tag Component tag that identified this structure.
823  * \param pos Starting position of the ASN.1 component length.
824  * \param end End of ASN.1 decoding data buffer.
825  * \param args Arguments to fill in from the decoded buffer.
826  *
827  * \retval Start of the next ASN.1 component on success.
828  * \retval NULL on error.
829  */
rose_dec_etsi_ActivationDiversion_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)830 const unsigned char *rose_dec_etsi_ActivationDiversion_ARG(struct pri *ctrl,
831 	unsigned tag, const unsigned char *pos, const unsigned char *end,
832 	union rose_msg_invoke_args *args)
833 {
834 	struct roseEtsiActivationDiversion_ARG *activation_diversion;
835 	int length;
836 	int seq_offset;
837 	const unsigned char *seq_end;
838 	int32_t value;
839 
840 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
841 	if (ctrl->debug & PRI_DEBUG_APDU) {
842 		pri_message(ctrl, "  ActivationDiversion %s\n", asn1_tag2str(tag));
843 	}
844 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
845 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
846 
847 	activation_diversion = &args->etsi.ActivationDiversion;
848 
849 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
850 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
851 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
852 	activation_diversion->procedure = value;
853 
854 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
855 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
856 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
857 	activation_diversion->basic_service = value;
858 
859 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
860 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
861 	ASN1_CALL(pos, rose_dec_Address(ctrl, "forwardedToAddress", tag, pos, seq_end,
862 		&activation_diversion->forwarded_to));
863 
864 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
865 	ASN1_CALL(pos, rose_dec_etsi_ServedUserNumber(ctrl, "servedUserNr", tag, pos,
866 		seq_end, &activation_diversion->served_user_number));
867 
868 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
869 
870 	return pos;
871 }
872 
873 /*!
874  * \brief Decode the DeactivationDiversion invoke argument parameters.
875  *
876  * \param ctrl D channel controller for diagnostic messages or global options.
877  * \param tag Component tag that identified this structure.
878  * \param pos Starting position of the ASN.1 component length.
879  * \param end End of ASN.1 decoding data buffer.
880  * \param args Arguments to fill in from the decoded buffer.
881  *
882  * \retval Start of the next ASN.1 component on success.
883  * \retval NULL on error.
884  */
rose_dec_etsi_DeactivationDiversion_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)885 const unsigned char *rose_dec_etsi_DeactivationDiversion_ARG(struct pri *ctrl,
886 	unsigned tag, const unsigned char *pos, const unsigned char *end,
887 	union rose_msg_invoke_args *args)
888 {
889 	struct roseEtsiDeactivationDiversion_ARG *deactivation_diversion;
890 	int length;
891 	int seq_offset;
892 	const unsigned char *seq_end;
893 	int32_t value;
894 
895 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
896 	if (ctrl->debug & PRI_DEBUG_APDU) {
897 		pri_message(ctrl, "  DeactivationDiversion %s\n", asn1_tag2str(tag));
898 	}
899 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
900 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
901 
902 	deactivation_diversion = &args->etsi.DeactivationDiversion;
903 
904 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
905 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
906 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
907 	deactivation_diversion->procedure = value;
908 
909 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
910 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
911 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
912 	deactivation_diversion->basic_service = value;
913 
914 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
915 	ASN1_CALL(pos, rose_dec_etsi_ServedUserNumber(ctrl, "servedUserNr", tag, pos,
916 		seq_end, &deactivation_diversion->served_user_number));
917 
918 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
919 
920 	return pos;
921 }
922 
923 /*!
924  * \brief Decode the ActivationStatusNotificationDiv invoke argument parameters.
925  *
926  * \param ctrl D channel controller for diagnostic messages or global options.
927  * \param tag Component tag that identified this structure.
928  * \param pos Starting position of the ASN.1 component length.
929  * \param end End of ASN.1 decoding data buffer.
930  * \param args Arguments to fill in from the decoded buffer.
931  *
932  * \retval Start of the next ASN.1 component on success.
933  * \retval NULL on error.
934  */
rose_dec_etsi_ActivationStatusNotificationDiv_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)935 const unsigned char *rose_dec_etsi_ActivationStatusNotificationDiv_ARG(struct pri *ctrl,
936 	unsigned tag, const unsigned char *pos, const unsigned char *end,
937 	union rose_msg_invoke_args *args)
938 {
939 	struct roseEtsiActivationStatusNotificationDiv_ARG
940 		*activation_status_notification_div;
941 	int length;
942 	int seq_offset;
943 	const unsigned char *seq_end;
944 	int32_t value;
945 
946 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
947 	if (ctrl->debug & PRI_DEBUG_APDU) {
948 		pri_message(ctrl, "  ActivationStatusNotificationDiv %s\n", asn1_tag2str(tag));
949 	}
950 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
951 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
952 
953 	activation_status_notification_div = &args->etsi.ActivationStatusNotificationDiv;
954 
955 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
956 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
957 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
958 	activation_status_notification_div->procedure = value;
959 
960 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
961 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
962 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
963 	activation_status_notification_div->basic_service = value;
964 
965 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
966 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
967 	ASN1_CALL(pos, rose_dec_Address(ctrl, "forwardedToAddress", tag, pos, seq_end,
968 		&activation_status_notification_div->forwarded_to));
969 
970 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
971 	ASN1_CALL(pos, rose_dec_etsi_ServedUserNumber(ctrl, "servedUserNr", tag, pos,
972 		seq_end, &activation_status_notification_div->served_user_number));
973 
974 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
975 
976 	return pos;
977 }
978 
979 /*!
980  * \brief Decode the DeactivationStatusNotificationDiv invoke argument parameters.
981  *
982  * \param ctrl D channel controller for diagnostic messages or global options.
983  * \param tag Component tag that identified this structure.
984  * \param pos Starting position of the ASN.1 component length.
985  * \param end End of ASN.1 decoding data buffer.
986  * \param args Arguments to fill in from the decoded buffer.
987  *
988  * \retval Start of the next ASN.1 component on success.
989  * \retval NULL on error.
990  */
rose_dec_etsi_DeactivationStatusNotificationDiv_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)991 const unsigned char *rose_dec_etsi_DeactivationStatusNotificationDiv_ARG(struct pri
992 	*ctrl, unsigned tag, const unsigned char *pos, const unsigned char *end,
993 	union rose_msg_invoke_args *args)
994 {
995 	struct roseEtsiDeactivationStatusNotificationDiv_ARG
996 		*deactivation_status_notification_div;
997 	int length;
998 	int seq_offset;
999 	const unsigned char *seq_end;
1000 	int32_t value;
1001 
1002 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1003 	if (ctrl->debug & PRI_DEBUG_APDU) {
1004 		pri_message(ctrl, "  DeactivationStatusNotificationDiv %s\n", asn1_tag2str(tag));
1005 	}
1006 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1007 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1008 
1009 	deactivation_status_notification_div = &args->etsi.DeactivationStatusNotificationDiv;
1010 
1011 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1012 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1013 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
1014 	deactivation_status_notification_div->procedure = value;
1015 
1016 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1017 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1018 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
1019 	deactivation_status_notification_div->basic_service = value;
1020 
1021 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1022 	ASN1_CALL(pos, rose_dec_etsi_ServedUserNumber(ctrl, "forwardedToAddress", tag, pos,
1023 		seq_end, &deactivation_status_notification_div->served_user_number));
1024 
1025 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1026 
1027 	return pos;
1028 }
1029 
1030 /*!
1031  * \brief Decode the InterrogationDiversion invoke argument parameters.
1032  *
1033  * \param ctrl D channel controller for diagnostic messages or global options.
1034  * \param tag Component tag that identified this structure.
1035  * \param pos Starting position of the ASN.1 component length.
1036  * \param end End of ASN.1 decoding data buffer.
1037  * \param args Arguments to fill in from the decoded buffer.
1038  *
1039  * \retval Start of the next ASN.1 component on success.
1040  * \retval NULL on error.
1041  */
rose_dec_etsi_InterrogationDiversion_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1042 const unsigned char *rose_dec_etsi_InterrogationDiversion_ARG(struct pri *ctrl,
1043 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1044 	union rose_msg_invoke_args *args)
1045 {
1046 	struct roseEtsiInterrogationDiversion_ARG *interrogation_diversion;
1047 	int length;
1048 	int seq_offset;
1049 	const unsigned char *seq_end;
1050 	int32_t value;
1051 
1052 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1053 	if (ctrl->debug & PRI_DEBUG_APDU) {
1054 		pri_message(ctrl, "  InterrogationDiversion %s\n", asn1_tag2str(tag));
1055 	}
1056 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1057 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1058 
1059 	interrogation_diversion = &args->etsi.InterrogationDiversion;
1060 
1061 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1062 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1063 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
1064 	interrogation_diversion->procedure = value;
1065 
1066 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1067 	if (tag == ASN1_TYPE_ENUMERATED) {
1068 		ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
1069 
1070 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1071 	} else {
1072 		value = 0;	/* DEFAULT BasicService value (allServices) */
1073 	}
1074 	interrogation_diversion->basic_service = value;
1075 
1076 	ASN1_CALL(pos, rose_dec_etsi_ServedUserNumber(ctrl, "servedUserNr", tag, pos,
1077 		seq_end, &interrogation_diversion->served_user_number));
1078 
1079 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1080 
1081 	return pos;
1082 }
1083 
1084 /*!
1085  * \brief Decode the InterrogationDiversion result parameters.
1086  *
1087  * \param ctrl D channel controller for diagnostic messages or global options.
1088  * \param tag Component tag that identified this structure.
1089  * \param pos Starting position of the ASN.1 component length.
1090  * \param end End of ASN.1 decoding data buffer.
1091  * \param args Arguments to fill in from the decoded buffer.
1092  *
1093  * \retval Start of the next ASN.1 component on success.
1094  * \retval NULL on error.
1095  */
rose_dec_etsi_InterrogationDiversion_RES(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_result_args * args)1096 const unsigned char *rose_dec_etsi_InterrogationDiversion_RES(struct pri *ctrl,
1097 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1098 	union rose_msg_result_args *args)
1099 {
1100 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SET);
1101 	return rose_dec_etsi_IntResultList(ctrl, "diversionList", tag, pos, end,
1102 		&args->etsi.InterrogationDiversion);
1103 }
1104 
1105 /*!
1106  * \brief Decode the DiversionInformation invoke argument parameters.
1107  *
1108  * \param ctrl D channel controller for diagnostic messages or global options.
1109  * \param tag Component tag that identified this structure.
1110  * \param pos Starting position of the ASN.1 component length.
1111  * \param end End of ASN.1 decoding data buffer.
1112  * \param args Arguments to fill in from the decoded buffer.
1113  *
1114  * \retval Start of the next ASN.1 component on success.
1115  * \retval NULL on error.
1116  */
rose_dec_etsi_DiversionInformation_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1117 const unsigned char *rose_dec_etsi_DiversionInformation_ARG(struct pri *ctrl,
1118 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1119 	union rose_msg_invoke_args *args)
1120 {
1121 	struct roseEtsiDiversionInformation_ARG *diversion_information;
1122 	int length;
1123 	int seq_offset;
1124 	int explicit_offset;
1125 	const unsigned char *seq_end;
1126 	const unsigned char *explicit_end;
1127 	const unsigned char *save_pos;
1128 	int32_t value;
1129 
1130 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1131 	if (ctrl->debug & PRI_DEBUG_APDU) {
1132 		pri_message(ctrl, "  DiversionInformation %s\n", asn1_tag2str(tag));
1133 	}
1134 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1135 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1136 
1137 	diversion_information = &args->etsi.DiversionInformation;
1138 
1139 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1140 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1141 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionReason", tag, pos, seq_end, &value));
1142 	diversion_information->diversion_reason = value;
1143 
1144 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1145 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1146 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
1147 	diversion_information->basic_service = value;
1148 
1149 	/*
1150 	 * A sequence specifies an ordered list of component types.
1151 	 * However, for simplicity we are not checking the order of
1152 	 * the remaining optional components.
1153 	 */
1154 	diversion_information->served_user_subaddress.length = 0;
1155 	diversion_information->calling_present = 0;
1156 	diversion_information->original_called_present = 0;
1157 	diversion_information->last_diverting_present = 0;
1158 	diversion_information->last_diverting_reason_present = 0;
1159 	diversion_information->q931ie.length = 0;
1160 	while (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1161 		save_pos = pos;
1162 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1163 		switch (tag) {
1164 		case ASN1_TAG_SEQUENCE:
1165 		case ASN1_TYPE_OCTET_STRING:
1166 		case ASN1_TYPE_OCTET_STRING | ASN1_PC_CONSTRUCTED:
1167 			ASN1_CALL(pos, rose_dec_PartySubaddress(ctrl, "servedUserSubaddress", tag,
1168 				pos, seq_end, &diversion_information->served_user_subaddress));
1169 			break;
1170 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 0:
1171 			/* Remove EXPLICIT tag */
1172 			if (ctrl->debug & PRI_DEBUG_APDU) {
1173 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1174 			}
1175 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1176 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1177 
1178 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1179 			ASN1_CALL(pos, rose_dec_PresentedAddressScreened(ctrl, "callingAddress", tag,
1180 				pos, explicit_end, &diversion_information->calling));
1181 			diversion_information->calling_present = 1;
1182 
1183 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1184 			break;
1185 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 1:
1186 			/* Remove EXPLICIT tag */
1187 			if (ctrl->debug & PRI_DEBUG_APDU) {
1188 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1189 			}
1190 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1191 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1192 
1193 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1194 			ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "originalCalledNr",
1195 				tag, pos, explicit_end, &diversion_information->original_called));
1196 			diversion_information->original_called_present = 1;
1197 
1198 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1199 			break;
1200 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 2:
1201 			/* Remove EXPLICIT tag */
1202 			if (ctrl->debug & PRI_DEBUG_APDU) {
1203 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1204 			}
1205 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1206 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1207 
1208 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1209 			ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "lastDivertingNr",
1210 				tag, pos, explicit_end, &diversion_information->last_diverting));
1211 			diversion_information->last_diverting_present = 1;
1212 
1213 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1214 			break;
1215 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 3:
1216 			/* Remove EXPLICIT tag */
1217 			if (ctrl->debug & PRI_DEBUG_APDU) {
1218 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1219 			}
1220 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1221 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1222 
1223 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1224 			ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1225 			ASN1_CALL(pos, asn1_dec_int(ctrl, "lastDivertingReason", tag, pos,
1226 				explicit_end, &value));
1227 			diversion_information->last_diverting_reason = value;
1228 			diversion_information->last_diverting_reason_present = 1;
1229 
1230 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1231 			break;
1232 		case ASN1_CLASS_APPLICATION | 0:
1233 		case ASN1_CLASS_APPLICATION | ASN1_PC_CONSTRUCTED | 0:
1234 			ASN1_CALL(pos, rose_dec_Q931ie(ctrl, "userInfo", tag, pos, seq_end,
1235 				&diversion_information->q931ie,
1236 				sizeof(diversion_information->q931ie_contents)));
1237 			break;
1238 		default:
1239 			pos = save_pos;
1240 			goto cancel_options;
1241 		}
1242 	}
1243 cancel_options:;
1244 
1245 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1246 
1247 	return pos;
1248 }
1249 
1250 /*!
1251  * \brief Decode the CallDeflection invoke argument parameters.
1252  *
1253  * \param ctrl D channel controller for diagnostic messages or global options.
1254  * \param tag Component tag that identified this structure.
1255  * \param pos Starting position of the ASN.1 component length.
1256  * \param end End of ASN.1 decoding data buffer.
1257  * \param args Arguments to fill in from the decoded buffer.
1258  *
1259  * \retval Start of the next ASN.1 component on success.
1260  * \retval NULL on error.
1261  */
rose_dec_etsi_CallDeflection_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1262 const unsigned char *rose_dec_etsi_CallDeflection_ARG(struct pri *ctrl, unsigned tag,
1263 	const unsigned char *pos, const unsigned char *end, union rose_msg_invoke_args *args)
1264 {
1265 	struct roseEtsiCallDeflection_ARG *call_deflection;
1266 	int length;
1267 	int seq_offset;
1268 	const unsigned char *seq_end;
1269 	int32_t value;
1270 
1271 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1272 	if (ctrl->debug & PRI_DEBUG_APDU) {
1273 		pri_message(ctrl, "  CallDeflection %s\n", asn1_tag2str(tag));
1274 	}
1275 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1276 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1277 
1278 	call_deflection = &args->etsi.CallDeflection;
1279 
1280 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1281 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1282 	ASN1_CALL(pos, rose_dec_Address(ctrl, "deflectionAddress", tag, pos, seq_end,
1283 		&call_deflection->deflection));
1284 
1285 	if (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1286 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1287 		ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_BOOLEAN);
1288 		ASN1_CALL(pos, asn1_dec_boolean(ctrl, "presentationAllowedDivertedToUser", tag,
1289 			pos, seq_end, &value));
1290 		call_deflection->presentation_allowed_to_diverted_to_user = value;
1291 		call_deflection->presentation_allowed_to_diverted_to_user_present = 1;
1292 	} else {
1293 		call_deflection->presentation_allowed_to_diverted_to_user_present = 0;
1294 	}
1295 
1296 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1297 
1298 	return pos;
1299 }
1300 
1301 /*!
1302  * \brief Decode the CallRerouting invoke argument parameters.
1303  *
1304  * \param ctrl D channel controller for diagnostic messages or global options.
1305  * \param tag Component tag that identified this structure.
1306  * \param pos Starting position of the ASN.1 component length.
1307  * \param end End of ASN.1 decoding data buffer.
1308  * \param args Arguments to fill in from the decoded buffer.
1309  *
1310  * \retval Start of the next ASN.1 component on success.
1311  * \retval NULL on error.
1312  */
rose_dec_etsi_CallRerouting_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1313 const unsigned char *rose_dec_etsi_CallRerouting_ARG(struct pri *ctrl, unsigned tag,
1314 	const unsigned char *pos, const unsigned char *end, union rose_msg_invoke_args *args)
1315 {
1316 	struct roseEtsiCallRerouting_ARG *call_rerouting;
1317 	int length;
1318 	int seq_offset;
1319 	int explicit_offset;
1320 	const unsigned char *seq_end;
1321 	const unsigned char *explicit_end;
1322 	const unsigned char *save_pos;
1323 	int32_t value;
1324 
1325 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1326 	if (ctrl->debug & PRI_DEBUG_APDU) {
1327 		pri_message(ctrl, "  CallRerouting %s\n", asn1_tag2str(tag));
1328 	}
1329 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1330 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1331 
1332 	call_rerouting = &args->etsi.CallRerouting;
1333 
1334 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1335 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1336 	ASN1_CALL(pos, asn1_dec_int(ctrl, "reroutingReason", tag, pos, seq_end, &value));
1337 	call_rerouting->rerouting_reason = value;
1338 
1339 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1340 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1341 	ASN1_CALL(pos, rose_dec_Address(ctrl, "calledAddress", tag, pos, seq_end,
1342 		&call_rerouting->called_address));
1343 
1344 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1345 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_INTEGER);
1346 	ASN1_CALL(pos, asn1_dec_int(ctrl, "reroutingCounter", tag, pos, seq_end, &value));
1347 	call_rerouting->rerouting_counter = value;
1348 
1349 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1350 	ASN1_CHECK_TAG(ctrl, tag, tag & ~ASN1_PC_MASK, ASN1_CLASS_APPLICATION | 0);
1351 	ASN1_CALL(pos, rose_dec_Q931ie(ctrl, "q931ie", tag, pos, seq_end,
1352 		&call_rerouting->q931ie, sizeof(call_rerouting->q931ie_contents)));
1353 
1354 	/* Remove EXPLICIT tag */
1355 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1356 	ASN1_CHECK_TAG(ctrl, tag, tag,
1357 		ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 1);
1358 	if (ctrl->debug & PRI_DEBUG_APDU) {
1359 		pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1360 	}
1361 	ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1362 	ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1363 
1364 	ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1365 	ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "lastReroutingNr", tag, pos,
1366 		explicit_end, &call_rerouting->last_rerouting));
1367 
1368 	ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1369 
1370 	/*
1371 	 * A sequence specifies an ordered list of component types.
1372 	 * However, for simplicity we are not checking the order of
1373 	 * the remaining optional components.
1374 	 */
1375 	call_rerouting->subscription_option = 0;	/* DEFAULT value noNotification */
1376 	call_rerouting->calling_subaddress.length = 0;
1377 	while (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1378 		save_pos = pos;
1379 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1380 		switch (tag) {
1381 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 2:
1382 			/* Remove EXPLICIT tag */
1383 			if (ctrl->debug & PRI_DEBUG_APDU) {
1384 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1385 			}
1386 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1387 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1388 
1389 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1390 			ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1391 			ASN1_CALL(pos, asn1_dec_int(ctrl, "subscriptionOption", tag, pos,
1392 				explicit_end, &value));
1393 			call_rerouting->subscription_option = value;
1394 
1395 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1396 			break;
1397 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 3:
1398 			/* Remove EXPLICIT tag */
1399 			if (ctrl->debug & PRI_DEBUG_APDU) {
1400 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1401 			}
1402 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1403 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1404 
1405 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1406 			ASN1_CALL(pos, rose_dec_PartySubaddress(ctrl, "callingPartySubaddress", tag,
1407 				pos, explicit_end, &call_rerouting->calling_subaddress));
1408 
1409 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1410 			break;
1411 		default:
1412 			pos = save_pos;
1413 			goto cancel_options;
1414 		}
1415 	}
1416 cancel_options:;
1417 
1418 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1419 
1420 	return pos;
1421 }
1422 
1423 /*!
1424  * \brief Decode the InterrogateServedUserNumbers result parameters.
1425  *
1426  * \param ctrl D channel controller for diagnostic messages or global options.
1427  * \param tag Component tag that identified this structure.
1428  * \param pos Starting position of the ASN.1 component length.
1429  * \param end End of ASN.1 decoding data buffer.
1430  * \param args Arguments to fill in from the decoded buffer.
1431  *
1432  * \retval Start of the next ASN.1 component on success.
1433  * \retval NULL on error.
1434  */
rose_dec_etsi_InterrogateServedUserNumbers_RES(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_result_args * args)1435 const unsigned char *rose_dec_etsi_InterrogateServedUserNumbers_RES(struct pri *ctrl,
1436 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1437 	union rose_msg_result_args *args)
1438 {
1439 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SET);
1440 	return rose_dec_etsi_ServedUserNumberList(ctrl, "interrogateServedUserNumbers", tag,
1441 		pos, end, &args->etsi.InterrogateServedUserNumbers);
1442 }
1443 
1444 /*!
1445  * \brief Decode the DivertingLegInformation1 invoke argument parameters.
1446  *
1447  * \param ctrl D channel controller for diagnostic messages or global options.
1448  * \param tag Component tag that identified this structure.
1449  * \param pos Starting position of the ASN.1 component length.
1450  * \param end End of ASN.1 decoding data buffer.
1451  * \param args Arguments to fill in from the decoded buffer.
1452  *
1453  * \retval Start of the next ASN.1 component on success.
1454  * \retval NULL on error.
1455  */
rose_dec_etsi_DivertingLegInformation1_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1456 const unsigned char *rose_dec_etsi_DivertingLegInformation1_ARG(struct pri *ctrl,
1457 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1458 	union rose_msg_invoke_args *args)
1459 {
1460 	struct roseEtsiDivertingLegInformation1_ARG *diverting_leg_informtion_1;
1461 	int length;
1462 	int seq_offset;
1463 	const unsigned char *seq_end;
1464 	int32_t value;
1465 
1466 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1467 	if (ctrl->debug & PRI_DEBUG_APDU) {
1468 		pri_message(ctrl, "  DivertingLegInformation1 %s\n", asn1_tag2str(tag));
1469 	}
1470 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1471 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1472 
1473 	diverting_leg_informtion_1 = &args->etsi.DivertingLegInformation1;
1474 
1475 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1476 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1477 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionReason", tag, pos, seq_end, &value));
1478 	diverting_leg_informtion_1->diversion_reason = value;
1479 
1480 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1481 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1482 	ASN1_CALL(pos, asn1_dec_int(ctrl, "subscriptionOption", tag, pos, seq_end, &value));
1483 	diverting_leg_informtion_1->subscription_option = value;
1484 
1485 	if (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1486 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1487 		ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "divertedToNumber", tag,
1488 			pos, seq_end, &diverting_leg_informtion_1->diverted_to));
1489 		diverting_leg_informtion_1->diverted_to_present = 1;
1490 	} else {
1491 		diverting_leg_informtion_1->diverted_to_present = 0;
1492 	}
1493 
1494 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1495 
1496 	return pos;
1497 }
1498 
1499 /*!
1500  * \brief Decode the DivertingLegInformation2 invoke argument parameters.
1501  *
1502  * \param ctrl D channel controller for diagnostic messages or global options.
1503  * \param tag Component tag that identified this structure.
1504  * \param pos Starting position of the ASN.1 component length.
1505  * \param end End of ASN.1 decoding data buffer.
1506  * \param args Arguments to fill in from the decoded buffer.
1507  *
1508  * \retval Start of the next ASN.1 component on success.
1509  * \retval NULL on error.
1510  */
rose_dec_etsi_DivertingLegInformation2_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1511 const unsigned char *rose_dec_etsi_DivertingLegInformation2_ARG(struct pri *ctrl,
1512 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1513 	union rose_msg_invoke_args *args)
1514 {
1515 	struct roseEtsiDivertingLegInformation2_ARG *diverting_leg_information_2;
1516 	int length;
1517 	int seq_offset;
1518 	int explicit_offset;
1519 	const unsigned char *seq_end;
1520 	const unsigned char *explicit_end;
1521 	const unsigned char *save_pos;
1522 	int32_t value;
1523 
1524 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1525 	if (ctrl->debug & PRI_DEBUG_APDU) {
1526 		pri_message(ctrl, "  DivertingLegInformation2 %s\n", asn1_tag2str(tag));
1527 	}
1528 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1529 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1530 
1531 	diverting_leg_information_2 = &args->etsi.DivertingLegInformation2;
1532 
1533 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1534 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_INTEGER);
1535 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionCounter", tag, pos, seq_end, &value));
1536 	diverting_leg_information_2->diversion_counter = value;
1537 
1538 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1539 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1540 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionReason", tag, pos, seq_end, &value));
1541 	diverting_leg_information_2->diversion_reason = value;
1542 
1543 	/*
1544 	 * A sequence specifies an ordered list of component types.
1545 	 * However, for simplicity we are not checking the order of
1546 	 * the remaining optional components.
1547 	 */
1548 	diverting_leg_information_2->diverting_present = 0;
1549 	diverting_leg_information_2->original_called_present = 0;
1550 	while (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1551 		save_pos = pos;
1552 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1553 		switch (tag) {
1554 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 1:
1555 			/* Remove EXPLICIT tag */
1556 			if (ctrl->debug & PRI_DEBUG_APDU) {
1557 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1558 			}
1559 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1560 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1561 
1562 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1563 			ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "divertingNr", tag,
1564 				pos, explicit_end, &diverting_leg_information_2->diverting));
1565 			diverting_leg_information_2->diverting_present = 1;
1566 
1567 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1568 			break;
1569 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 2:
1570 			/* Remove EXPLICIT tag */
1571 			if (ctrl->debug & PRI_DEBUG_APDU) {
1572 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1573 			}
1574 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1575 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1576 
1577 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1578 			ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "originalCalledNr",
1579 				tag, pos, explicit_end, &diverting_leg_information_2->original_called));
1580 			diverting_leg_information_2->original_called_present = 1;
1581 
1582 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1583 			break;
1584 		default:
1585 			pos = save_pos;
1586 			goto cancel_options;
1587 		}
1588 	}
1589 cancel_options:;
1590 
1591 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1592 
1593 	return pos;
1594 }
1595 
1596 /*!
1597  * \brief Decode the DivertingLegInformation3 invoke argument parameters.
1598  *
1599  * \param ctrl D channel controller for diagnostic messages or global options.
1600  * \param tag Component tag that identified this structure.
1601  * \param pos Starting position of the ASN.1 component length.
1602  * \param end End of ASN.1 decoding data buffer.
1603  * \param args Arguments to fill in from the decoded buffer.
1604  *
1605  * \retval Start of the next ASN.1 component on success.
1606  * \retval NULL on error.
1607  */
rose_dec_etsi_DivertingLegInformation3_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1608 const unsigned char *rose_dec_etsi_DivertingLegInformation3_ARG(struct pri *ctrl,
1609 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1610 	union rose_msg_invoke_args *args)
1611 {
1612 	int32_t value;
1613 
1614 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_BOOLEAN);
1615 	ASN1_CALL(pos, asn1_dec_boolean(ctrl, "presentationAllowedIndicator", tag, pos, end,
1616 		&value));
1617 	args->etsi.DivertingLegInformation3.presentation_allowed_indicator = value;
1618 
1619 	return pos;
1620 }
1621 
1622 /* ------------------------------------------------------------------- */
1623 /* end rose_etsi_diversion.c */
1624