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 Q.SIG ROSE Call-Diversion-Operations
30  *
31  * Call-Diversion-Operations ECMA-174 Annex F Table F.1
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 IntResult 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 tag Component tag to identify the encoded component.
55  *   The tag should be ASN1_TAG_SEQUENCE unless the caller implicitly
56  *   tags it otherwise.
57  * \param int_result Forwarding record information to encode.
58  *
59  * \retval Start of the next ASN.1 component to encode on success.
60  * \retval NULL on error.
61  */
rose_enc_qsig_IntResult(struct pri * ctrl,unsigned char * pos,unsigned char * end,unsigned tag,const struct roseQsigForwardingRecord * int_result)62 static unsigned char *rose_enc_qsig_IntResult(struct pri *ctrl, unsigned char *pos,
63 	unsigned char *end, unsigned tag, const struct roseQsigForwardingRecord *int_result)
64 {
65 	unsigned char *seq_len;
66 
67 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, tag);
68 
69 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
70 		&int_result->served_user_number));
71 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
72 		int_result->basic_service));
73 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED, int_result->procedure));
74 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
75 		&int_result->diverted_to));
76 	if (int_result->remote_enabled) {
77 		/* Not the DEFAULT value */
78 		ASN1_CALL(pos, asn1_enc_boolean(pos, end, ASN1_TYPE_BOOLEAN,
79 			int_result->remote_enabled));
80 	}
81 
82 	/* No extension to encode */
83 
84 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
85 
86 	return pos;
87 }
88 
89 /*!
90  * \internal
91  * \brief Encode the IntResultList type.
92  *
93  * \param ctrl D channel controller for diagnostic messages or global options.
94  * \param pos Starting position to encode ASN.1 component.
95  * \param end End of ASN.1 encoding data buffer.
96  * \param tag Component tag to identify the encoded component.
97  *   The tag should be ASN1_TAG_SET unless the caller implicitly
98  *   tags it otherwise.
99  * \param int_result_list Forwarding record list information to encode.
100  *
101  * \retval Start of the next ASN.1 component to encode on success.
102  * \retval NULL on error.
103  */
rose_enc_qsig_IntResultList(struct pri * ctrl,unsigned char * pos,unsigned char * end,unsigned tag,const struct roseQsigForwardingList * int_result_list)104 static unsigned char *rose_enc_qsig_IntResultList(struct pri *ctrl, unsigned char *pos,
105 	unsigned char *end, unsigned tag,
106 	const struct roseQsigForwardingList *int_result_list)
107 {
108 	unsigned index;
109 	unsigned char *set_len;
110 
111 	ASN1_CONSTRUCTED_BEGIN(set_len, pos, end, tag);
112 
113 	for (index = 0; index < int_result_list->num_records; ++index) {
114 		ASN1_CALL(pos, rose_enc_qsig_IntResult(ctrl, pos, end, ASN1_TAG_SEQUENCE,
115 			&int_result_list->list[index]));
116 	}
117 
118 	ASN1_CONSTRUCTED_END(set_len, pos, end);
119 
120 	return pos;
121 }
122 
123 /*!
124  * \brief Encode the ActivateDiversionQ invoke facility ie arguments.
125  *
126  * \param ctrl D channel controller for diagnostic messages or global options.
127  * \param pos Starting position to encode ASN.1 component.
128  * \param end End of ASN.1 encoding data buffer.
129  * \param args Arguments to encode in the buffer.
130  *
131  * \retval Start of the next ASN.1 component to encode on success.
132  * \retval NULL on error.
133  */
rose_enc_qsig_ActivateDiversionQ_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)134 unsigned char *rose_enc_qsig_ActivateDiversionQ_ARG(struct pri *ctrl, unsigned char *pos,
135 	unsigned char *end, const union rose_msg_invoke_args *args)
136 {
137 	const struct roseQsigActivateDiversionQ_ARG *activate_diversion_q;
138 	unsigned char *seq_len;
139 
140 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
141 
142 	activate_diversion_q = &args->qsig.ActivateDiversionQ;
143 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
144 		activate_diversion_q->procedure));
145 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
146 		activate_diversion_q->basic_service));
147 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
148 		&activate_diversion_q->diverted_to));
149 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
150 		&activate_diversion_q->served_user_number));
151 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
152 		&activate_diversion_q->activating_user_number));
153 
154 	/* No extension to encode */
155 
156 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
157 
158 	return pos;
159 }
160 
161 /*!
162  * \brief Encode the DeactivateDiversionQ invoke facility ie arguments.
163  *
164  * \param ctrl D channel controller for diagnostic messages or global options.
165  * \param pos Starting position to encode ASN.1 component.
166  * \param end End of ASN.1 encoding data buffer.
167  * \param args Arguments to encode in the buffer.
168  *
169  * \retval Start of the next ASN.1 component to encode on success.
170  * \retval NULL on error.
171  */
rose_enc_qsig_DeactivateDiversionQ_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)172 unsigned char *rose_enc_qsig_DeactivateDiversionQ_ARG(struct pri *ctrl,
173 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
174 {
175 	const struct roseQsigDeactivateDiversionQ_ARG *deactivate_diversion_q;
176 	unsigned char *seq_len;
177 
178 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
179 
180 	deactivate_diversion_q = &args->qsig.DeactivateDiversionQ;
181 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
182 		deactivate_diversion_q->procedure));
183 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
184 		deactivate_diversion_q->basic_service));
185 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
186 		&deactivate_diversion_q->served_user_number));
187 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
188 		&deactivate_diversion_q->deactivating_user_number));
189 
190 	/* No extension to encode */
191 
192 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
193 
194 	return pos;
195 }
196 
197 /*!
198  * \brief Encode the InterrogateDiversionQ invoke facility ie arguments.
199  *
200  * \param ctrl D channel controller for diagnostic messages or global options.
201  * \param pos Starting position to encode ASN.1 component.
202  * \param end End of ASN.1 encoding data buffer.
203  * \param args Arguments to encode in the buffer.
204  *
205  * \retval Start of the next ASN.1 component to encode on success.
206  * \retval NULL on error.
207  */
rose_enc_qsig_InterrogateDiversionQ_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)208 unsigned char *rose_enc_qsig_InterrogateDiversionQ_ARG(struct pri *ctrl,
209 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
210 {
211 	const struct roseQsigInterrogateDiversionQ_ARG *interrogate_diversion_q;
212 	unsigned char *seq_len;
213 
214 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
215 
216 	interrogate_diversion_q = &args->qsig.InterrogateDiversionQ;
217 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
218 		interrogate_diversion_q->procedure));
219 	if (interrogate_diversion_q->basic_service) {
220 		/* Not the DEFAULT value */
221 		ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
222 			interrogate_diversion_q->basic_service));
223 	}
224 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
225 		&interrogate_diversion_q->served_user_number));
226 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
227 		&interrogate_diversion_q->interrogating_user_number));
228 
229 	/* No extension to encode */
230 
231 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
232 
233 	return pos;
234 }
235 
236 /*!
237  * \brief Encode the InterrogateDiversionQ result facility ie arguments.
238  *
239  * \param ctrl D channel controller for diagnostic messages or global options.
240  * \param pos Starting position to encode ASN.1 component.
241  * \param end End of ASN.1 encoding data buffer.
242  * \param args Arguments to encode in the buffer.
243  *
244  * \retval Start of the next ASN.1 component to encode on success.
245  * \retval NULL on error.
246  */
rose_enc_qsig_InterrogateDiversionQ_RES(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_result_args * args)247 unsigned char *rose_enc_qsig_InterrogateDiversionQ_RES(struct pri *ctrl,
248 	unsigned char *pos, unsigned char *end, const union rose_msg_result_args *args)
249 {
250 	return rose_enc_qsig_IntResultList(ctrl, pos, end, ASN1_TAG_SET,
251 		&args->qsig.InterrogateDiversionQ);
252 }
253 
254 /*!
255  * \brief Encode the CheckRestriction invoke facility ie arguments.
256  *
257  * \param ctrl D channel controller for diagnostic messages or global options.
258  * \param pos Starting position to encode ASN.1 component.
259  * \param end End of ASN.1 encoding data buffer.
260  * \param args Arguments to encode in the buffer.
261  *
262  * \retval Start of the next ASN.1 component to encode on success.
263  * \retval NULL on error.
264  */
rose_enc_qsig_CheckRestriction_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)265 unsigned char *rose_enc_qsig_CheckRestriction_ARG(struct pri *ctrl, unsigned char *pos,
266 	unsigned char *end, const union rose_msg_invoke_args *args)
267 {
268 	const struct roseQsigCheckRestriction_ARG *check_restriction;
269 	unsigned char *seq_len;
270 
271 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
272 
273 	check_restriction = &args->qsig.CheckRestriction;
274 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
275 		&check_restriction->served_user_number));
276 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
277 		check_restriction->basic_service));
278 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
279 		&check_restriction->diverted_to_number));
280 
281 	/* No extension to encode */
282 
283 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
284 
285 	return pos;
286 }
287 
288 /*!
289  * \brief Encode the CallRerouting invoke facility ie arguments.
290  *
291  * \param ctrl D channel controller for diagnostic messages or global options.
292  * \param pos Starting position to encode ASN.1 component.
293  * \param end End of ASN.1 encoding data buffer.
294  * \param args Arguments to encode in the buffer.
295  *
296  * \retval Start of the next ASN.1 component to encode on success.
297  * \retval NULL on error.
298  */
rose_enc_qsig_CallRerouting_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)299 unsigned char *rose_enc_qsig_CallRerouting_ARG(struct pri *ctrl, unsigned char *pos,
300 	unsigned char *end, const union rose_msg_invoke_args *args)
301 {
302 	const struct roseQsigCallRerouting_ARG *call_rerouting;
303 	unsigned char *seq_len;
304 	unsigned char *exp_len;
305 
306 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
307 
308 	call_rerouting = &args->qsig.CallRerouting;
309 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
310 		call_rerouting->rerouting_reason));
311 	if (call_rerouting->original_rerouting_reason_present) {
312 		ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 0,
313 			call_rerouting->original_rerouting_reason));
314 	}
315 	ASN1_CALL(pos, rose_enc_Address(ctrl, pos, end, ASN1_TAG_SEQUENCE,
316 		&call_rerouting->called));
317 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_INTEGER,
318 		call_rerouting->diversion_counter));
319 	ASN1_CALL(pos, rose_enc_Q931ie(ctrl, pos, end, ASN1_CLASS_APPLICATION | 0,
320 		&call_rerouting->q931ie));
321 
322 	/* EXPLICIT tag */
323 	ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 1);
324 	ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
325 		&call_rerouting->last_rerouting));
326 	ASN1_CONSTRUCTED_END(exp_len, pos, end);
327 
328 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 2,
329 		call_rerouting->subscription_option));
330 
331 	if (call_rerouting->calling_subaddress.length) {
332 		/* EXPLICIT tag */
333 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 3);
334 		ASN1_CALL(pos, rose_enc_PartySubaddress(ctrl, pos, end,
335 			&call_rerouting->calling_subaddress));
336 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
337 	}
338 
339 	/* EXPLICIT tag */
340 	ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 4);
341 	ASN1_CALL(pos, rose_enc_PresentedNumberScreened(ctrl, pos, end,
342 		&call_rerouting->calling));
343 	ASN1_CONSTRUCTED_END(exp_len, pos, end);
344 
345 	if (call_rerouting->calling_name_present) {
346 		/* EXPLICIT tag */
347 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 5);
348 		ASN1_CALL(pos, rose_enc_qsig_Name(ctrl, pos, end,
349 			&call_rerouting->calling_name));
350 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
351 	}
352 
353 	if (call_rerouting->original_called_present) {
354 		/* EXPLICIT tag */
355 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 6);
356 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
357 			&call_rerouting->original_called));
358 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
359 	}
360 
361 	if (call_rerouting->redirecting_name_present) {
362 		/* EXPLICIT tag */
363 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 7);
364 		ASN1_CALL(pos, rose_enc_qsig_Name(ctrl, pos, end,
365 			&call_rerouting->redirecting_name));
366 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
367 	}
368 
369 	if (call_rerouting->original_called_name_present) {
370 		/* EXPLICIT tag */
371 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 8);
372 		ASN1_CALL(pos, rose_enc_qsig_Name(ctrl, pos, end,
373 			&call_rerouting->original_called_name));
374 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
375 	}
376 
377 	/* No extension to encode */
378 
379 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
380 
381 	return pos;
382 }
383 
384 /*!
385  * \brief Encode the DivertingLegInformation1 invoke facility ie arguments.
386  *
387  * \param ctrl D channel controller for diagnostic messages or global options.
388  * \param pos Starting position to encode ASN.1 component.
389  * \param end End of ASN.1 encoding data buffer.
390  * \param args Arguments to encode in the buffer.
391  *
392  * \retval Start of the next ASN.1 component to encode on success.
393  * \retval NULL on error.
394  */
rose_enc_qsig_DivertingLegInformation1_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)395 unsigned char *rose_enc_qsig_DivertingLegInformation1_ARG(struct pri *ctrl,
396 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
397 {
398 	const struct roseQsigDivertingLegInformation1_ARG *diverting_leg_information_1;
399 	unsigned char *seq_len;
400 
401 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
402 
403 	diverting_leg_information_1 = &args->qsig.DivertingLegInformation1;
404 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
405 		diverting_leg_information_1->diversion_reason));
406 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
407 		diverting_leg_information_1->subscription_option));
408 	ASN1_CALL(pos, rose_enc_PartyNumber(ctrl, pos, end,
409 		&diverting_leg_information_1->nominated_number));
410 
411 	/* No extension to encode */
412 
413 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
414 
415 	return pos;
416 }
417 
418 /*!
419  * \brief Encode the DivertingLegInformation2 invoke facility ie arguments.
420  *
421  * \param ctrl D channel controller for diagnostic messages or global options.
422  * \param pos Starting position to encode ASN.1 component.
423  * \param end End of ASN.1 encoding data buffer.
424  * \param args Arguments to encode in the buffer.
425  *
426  * \retval Start of the next ASN.1 component to encode on success.
427  * \retval NULL on error.
428  */
rose_enc_qsig_DivertingLegInformation2_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)429 unsigned char *rose_enc_qsig_DivertingLegInformation2_ARG(struct pri *ctrl,
430 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
431 {
432 	const struct roseQsigDivertingLegInformation2_ARG *diverting_leg_information_2;
433 	unsigned char *seq_len;
434 	unsigned char *exp_len;
435 
436 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
437 
438 	diverting_leg_information_2 = &args->qsig.DivertingLegInformation2;
439 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_INTEGER,
440 		diverting_leg_information_2->diversion_counter));
441 	ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_TYPE_ENUMERATED,
442 		diverting_leg_information_2->diversion_reason));
443 	if (diverting_leg_information_2->original_diversion_reason_present) {
444 		ASN1_CALL(pos, asn1_enc_int(pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 0,
445 			diverting_leg_information_2->original_diversion_reason));
446 	}
447 
448 	if (diverting_leg_information_2->diverting_present) {
449 		/* EXPLICIT tag */
450 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 1);
451 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
452 			&diverting_leg_information_2->diverting));
453 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
454 	}
455 
456 	if (diverting_leg_information_2->original_called_present) {
457 		/* EXPLICIT tag */
458 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 2);
459 		ASN1_CALL(pos, rose_enc_PresentedNumberUnscreened(ctrl, pos, end,
460 			&diverting_leg_information_2->original_called));
461 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
462 	}
463 
464 	if (diverting_leg_information_2->redirecting_name_present) {
465 		/* EXPLICIT tag */
466 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 3);
467 		ASN1_CALL(pos, rose_enc_qsig_Name(ctrl, pos, end,
468 			&diverting_leg_information_2->redirecting_name));
469 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
470 	}
471 
472 	if (diverting_leg_information_2->original_called_name_present) {
473 		/* EXPLICIT tag */
474 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 4);
475 		ASN1_CALL(pos, rose_enc_qsig_Name(ctrl, pos, end,
476 			&diverting_leg_information_2->original_called_name));
477 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
478 	}
479 
480 	/* No extension to encode */
481 
482 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
483 
484 	return pos;
485 }
486 
487 /*!
488  * \brief Encode the DivertingLegInformation3 invoke facility ie arguments.
489  *
490  * \param ctrl D channel controller for diagnostic messages or global options.
491  * \param pos Starting position to encode ASN.1 component.
492  * \param end End of ASN.1 encoding data buffer.
493  * \param args Arguments to encode in the buffer.
494  *
495  * \retval Start of the next ASN.1 component to encode on success.
496  * \retval NULL on error.
497  */
rose_enc_qsig_DivertingLegInformation3_ARG(struct pri * ctrl,unsigned char * pos,unsigned char * end,const union rose_msg_invoke_args * args)498 unsigned char *rose_enc_qsig_DivertingLegInformation3_ARG(struct pri *ctrl,
499 	unsigned char *pos, unsigned char *end, const union rose_msg_invoke_args *args)
500 {
501 	const struct roseQsigDivertingLegInformation3_ARG *diverting_leg_information_3;
502 	unsigned char *seq_len;
503 	unsigned char *exp_len;
504 
505 	ASN1_CONSTRUCTED_BEGIN(seq_len, pos, end, ASN1_TAG_SEQUENCE);
506 
507 	diverting_leg_information_3 = &args->qsig.DivertingLegInformation3;
508 	ASN1_CALL(pos, asn1_enc_boolean(pos, end, ASN1_TYPE_BOOLEAN,
509 		diverting_leg_information_3->presentation_allowed_indicator));
510 
511 	if (diverting_leg_information_3->redirection_name_present) {
512 		/* EXPLICIT tag */
513 		ASN1_CONSTRUCTED_BEGIN(exp_len, pos, end, ASN1_CLASS_CONTEXT_SPECIFIC | 0);
514 		ASN1_CALL(pos, rose_enc_qsig_Name(ctrl, pos, end,
515 			&diverting_leg_information_3->redirection_name));
516 		ASN1_CONSTRUCTED_END(exp_len, pos, end);
517 	}
518 
519 	/* No extension to encode */
520 
521 	ASN1_CONSTRUCTED_END(seq_len, pos, end);
522 
523 	return pos;
524 }
525 
526 /*!
527  * \internal
528  * \brief Decode the IntResult argument parameters.
529  *
530  * \param ctrl D channel controller for any diagnostic messages.
531  * \param name Field name
532  * \param tag Component tag that identified this production.
533  * \param pos Starting position of the ASN.1 component length.
534  * \param end End of ASN.1 decoding data buffer.
535  * \param int_result Parameter storage to fill.
536  *
537  * \retval Start of the next ASN.1 component on success.
538  * \retval NULL on error.
539  */
rose_dec_qsig_IntResult(struct pri * ctrl,const char * name,unsigned tag,const unsigned char * pos,const unsigned char * end,struct roseQsigForwardingRecord * int_result)540 static const unsigned char *rose_dec_qsig_IntResult(struct pri *ctrl, const char *name,
541 	unsigned tag, const unsigned char *pos, const unsigned char *end,
542 	struct roseQsigForwardingRecord *int_result)
543 {
544 	int32_t value;
545 	int length;
546 	int seq_offset;
547 	const unsigned char *seq_end;
548 	const unsigned char *save_pos;
549 
550 	if (ctrl->debug & PRI_DEBUG_APDU) {
551 		pri_message(ctrl, "  %s IntResult %s\n", name, asn1_tag2str(tag));
552 	}
553 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
554 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
555 
556 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
557 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "servedUserNr", tag, pos, seq_end,
558 		&int_result->served_user_number));
559 
560 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
561 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
562 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
563 	int_result->basic_service = value;
564 
565 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
566 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
567 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
568 	int_result->procedure = value;
569 
570 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
571 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
572 	ASN1_CALL(pos, rose_dec_Address(ctrl, "divertedToAddress", tag, pos, seq_end,
573 		&int_result->diverted_to));
574 
575 	/*
576 	 * A sequence specifies an ordered list of component types.
577 	 * However, for simplicity we are not checking the order of
578 	 * the remaining optional components.
579 	 */
580 	int_result->remote_enabled = 0;	/* DEFAULT FALSE */
581 	while (pos < seq_end && *pos != ASN1_INDEF_TERM) {
582 		save_pos = pos;
583 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
584 		switch (tag & ~ASN1_PC_MASK) {
585 		case ASN1_TYPE_BOOLEAN:
586 			/* Must not be constructed but we will not check for it for simplicity. */
587 			ASN1_CALL(pos, asn1_dec_boolean(ctrl, "remoteEnabled", tag, pos, seq_end,
588 				&value));
589 			int_result->remote_enabled = value;
590 			break;
591 		case ASN1_CLASS_CONTEXT_SPECIFIC | 1:
592 		case ASN1_CLASS_CONTEXT_SPECIFIC | 2:
593 			if (ctrl->debug & PRI_DEBUG_APDU) {
594 				pri_message(ctrl, "  extension %s\n", asn1_tag2str(tag));
595 			}
596 			/* Fixup will skip over the manufacturer extension information */
597 		default:
598 			pos = save_pos;
599 			goto cancel_options;
600 		}
601 	}
602 cancel_options:;
603 
604 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
605 
606 	return pos;
607 }
608 
609 /*!
610  * \internal
611  * \brief Decode the IntResultList argument parameters.
612  *
613  * \param ctrl D channel controller for any diagnostic messages.
614  * \param name Field name
615  * \param tag Component tag that identified this production.
616  * \param pos Starting position of the ASN.1 component length.
617  * \param end End of ASN.1 decoding data buffer.
618  * \param int_result_list Parameter storage to fill.
619  *
620  * \retval Start of the next ASN.1 component on success.
621  * \retval NULL on error.
622  */
rose_dec_qsig_IntResultList(struct pri * ctrl,const char * name,unsigned tag,const unsigned char * pos,const unsigned char * end,struct roseQsigForwardingList * int_result_list)623 static const unsigned char *rose_dec_qsig_IntResultList(struct pri *ctrl,
624 	const char *name, unsigned tag, const unsigned char *pos, const unsigned char *end,
625 	struct roseQsigForwardingList *int_result_list)
626 {
627 	int length;
628 	int set_offset;
629 	const unsigned char *set_end;
630 
631 	if (ctrl->debug & PRI_DEBUG_APDU) {
632 		pri_message(ctrl, "  %s IntResultList %s\n", name, asn1_tag2str(tag));
633 	}
634 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
635 	ASN1_END_SETUP(set_end, set_offset, length, pos, end);
636 
637 	int_result_list->num_records = 0;
638 	while (pos < set_end && *pos != ASN1_INDEF_TERM) {
639 		if (int_result_list->num_records < ARRAY_LEN(int_result_list->list)) {
640 			ASN1_CALL(pos, asn1_dec_tag(pos, set_end, &tag));
641 			ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
642 			ASN1_CALL(pos, rose_dec_qsig_IntResult(ctrl, "listEntry", tag, pos, set_end,
643 				&int_result_list->list[int_result_list->num_records]));
644 			++int_result_list->num_records;
645 		} else {
646 			/* Too many records */
647 			return NULL;
648 		}
649 	}
650 
651 	ASN1_END_FIXUP(ctrl, pos, set_offset, set_end, end);
652 
653 	return pos;
654 }
655 
656 /*!
657  * \brief Decode the Q.SIG ActivateDiversionQ invoke argument parameters.
658  *
659  * \param ctrl D channel controller for diagnostic messages or global options.
660  * \param tag Component tag that identified this structure.
661  * \param pos Starting position of the ASN.1 component length.
662  * \param end End of ASN.1 decoding data buffer.
663  * \param args Arguments to fill in from the decoded buffer.
664  *
665  * \retval Start of the next ASN.1 component on success.
666  * \retval NULL on error.
667  */
rose_dec_qsig_ActivateDiversionQ_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)668 const unsigned char *rose_dec_qsig_ActivateDiversionQ_ARG(struct pri *ctrl, unsigned tag,
669 	const unsigned char *pos, const unsigned char *end, union rose_msg_invoke_args *args)
670 {
671 	int32_t value;
672 	int length;
673 	int seq_offset;
674 	const unsigned char *seq_end;
675 	struct roseQsigActivateDiversionQ_ARG *activate_diversion_q;
676 
677 	activate_diversion_q = &args->qsig.ActivateDiversionQ;
678 
679 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
680 	if (ctrl->debug & PRI_DEBUG_APDU) {
681 		pri_message(ctrl, "  ActivateDiversionQ %s\n", asn1_tag2str(tag));
682 	}
683 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
684 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
685 
686 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
687 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
688 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
689 	activate_diversion_q->procedure = value;
690 
691 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
692 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
693 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
694 	activate_diversion_q->basic_service = value;
695 
696 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
697 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
698 	ASN1_CALL(pos, rose_dec_Address(ctrl, "divertedToAddress", tag, pos, seq_end,
699 		&activate_diversion_q->diverted_to));
700 
701 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
702 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "servedUserNr", tag, pos, seq_end,
703 		&activate_diversion_q->served_user_number));
704 
705 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
706 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "activatingUserNr", tag, pos, seq_end,
707 		&activate_diversion_q->activating_user_number));
708 
709 	/* Fixup will skip over any OPTIONAL manufacturer extension information */
710 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
711 
712 	return pos;
713 }
714 
715 /*!
716  * \brief Decode the Q.SIG DeactivateDiversionQ invoke argument parameters.
717  *
718  * \param ctrl D channel controller for diagnostic messages or global options.
719  * \param tag Component tag that identified this structure.
720  * \param pos Starting position of the ASN.1 component length.
721  * \param end End of ASN.1 decoding data buffer.
722  * \param args Arguments to fill in from the decoded buffer.
723  *
724  * \retval Start of the next ASN.1 component on success.
725  * \retval NULL on error.
726  */
rose_dec_qsig_DeactivateDiversionQ_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)727 const unsigned char *rose_dec_qsig_DeactivateDiversionQ_ARG(struct pri *ctrl,
728 	unsigned tag, const unsigned char *pos, const unsigned char *end,
729 	union rose_msg_invoke_args *args)
730 {
731 	int32_t value;
732 	int length;
733 	int seq_offset;
734 	const unsigned char *seq_end;
735 	struct roseQsigDeactivateDiversionQ_ARG *deactivate_diversion_q;
736 
737 	deactivate_diversion_q = &args->qsig.DeactivateDiversionQ;
738 
739 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
740 	if (ctrl->debug & PRI_DEBUG_APDU) {
741 		pri_message(ctrl, "  DeactivateDiversionQ %s\n", asn1_tag2str(tag));
742 	}
743 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
744 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
745 
746 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
747 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
748 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
749 	deactivate_diversion_q->procedure = value;
750 
751 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
752 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
753 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
754 	deactivate_diversion_q->basic_service = value;
755 
756 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
757 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "servedUserNr", tag, pos, seq_end,
758 		&deactivate_diversion_q->served_user_number));
759 
760 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
761 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "deactivatingUserNr", tag, pos, seq_end,
762 		&deactivate_diversion_q->deactivating_user_number));
763 
764 	/* Fixup will skip over any OPTIONAL manufacturer extension information */
765 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
766 
767 	return pos;
768 }
769 
770 /*!
771  * \brief Decode the Q.SIG InterrogateDiversionQ invoke argument parameters.
772  *
773  * \param ctrl D channel controller for diagnostic messages or global options.
774  * \param tag Component tag that identified this structure.
775  * \param pos Starting position of the ASN.1 component length.
776  * \param end End of ASN.1 decoding data buffer.
777  * \param args Arguments to fill in from the decoded buffer.
778  *
779  * \retval Start of the next ASN.1 component on success.
780  * \retval NULL on error.
781  */
rose_dec_qsig_InterrogateDiversionQ_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)782 const unsigned char *rose_dec_qsig_InterrogateDiversionQ_ARG(struct pri *ctrl,
783 	unsigned tag, const unsigned char *pos, const unsigned char *end,
784 	union rose_msg_invoke_args *args)
785 {
786 	int32_t value;
787 	int length;
788 	int seq_offset;
789 	const unsigned char *seq_end;
790 	struct roseQsigInterrogateDiversionQ_ARG *interrogate_diversion_q;
791 
792 	interrogate_diversion_q = &args->qsig.InterrogateDiversionQ;
793 
794 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
795 	if (ctrl->debug & PRI_DEBUG_APDU) {
796 		pri_message(ctrl, "  InterrogateDiversionQ %s\n", asn1_tag2str(tag));
797 	}
798 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
799 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
800 
801 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
802 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
803 	ASN1_CALL(pos, asn1_dec_int(ctrl, "procedure", tag, pos, seq_end, &value));
804 	interrogate_diversion_q->procedure = value;
805 
806 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
807 	if (tag == ASN1_TYPE_ENUMERATED) {
808 		ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
809 		interrogate_diversion_q->basic_service = value;
810 
811 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
812 	} else {
813 		interrogate_diversion_q->basic_service = 0;	/* allServices */
814 	}
815 
816 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "servedUserNr", tag, pos, seq_end,
817 		&interrogate_diversion_q->served_user_number));
818 
819 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
820 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "interrogatingUserNr", tag, pos, seq_end,
821 		&interrogate_diversion_q->interrogating_user_number));
822 
823 	/* Fixup will skip over any OPTIONAL manufacturer extension information */
824 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
825 
826 	return pos;
827 }
828 
829 /*!
830  * \brief Decode the Q.SIG InterrogateDiversionQ result argument parameters.
831  *
832  * \param ctrl D channel controller for diagnostic messages or global options.
833  * \param tag Component tag that identified this structure.
834  * \param pos Starting position of the ASN.1 component length.
835  * \param end End of ASN.1 decoding data buffer.
836  * \param args Arguments to fill in from the decoded buffer.
837  *
838  * \retval Start of the next ASN.1 component on success.
839  * \retval NULL on error.
840  */
rose_dec_qsig_InterrogateDiversionQ_RES(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_result_args * args)841 const unsigned char *rose_dec_qsig_InterrogateDiversionQ_RES(struct pri *ctrl,
842 	unsigned tag, const unsigned char *pos, const unsigned char *end,
843 	union rose_msg_result_args *args)
844 {
845 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SET);
846 	return rose_dec_qsig_IntResultList(ctrl, "InterrogateDiversionQ", tag, pos, end,
847 		&args->qsig.InterrogateDiversionQ);
848 }
849 
850 /*!
851  * \brief Decode the Q.SIG CheckRestriction invoke argument parameters.
852  *
853  * \param ctrl D channel controller for diagnostic messages or global options.
854  * \param tag Component tag that identified this structure.
855  * \param pos Starting position of the ASN.1 component length.
856  * \param end End of ASN.1 decoding data buffer.
857  * \param args Arguments to fill in from the decoded buffer.
858  *
859  * \retval Start of the next ASN.1 component on success.
860  * \retval NULL on error.
861  */
rose_dec_qsig_CheckRestriction_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)862 const unsigned char *rose_dec_qsig_CheckRestriction_ARG(struct pri *ctrl, unsigned tag,
863 	const unsigned char *pos, const unsigned char *end, union rose_msg_invoke_args *args)
864 {
865 	int32_t value;
866 	int length;
867 	int seq_offset;
868 	const unsigned char *seq_end;
869 	struct roseQsigCheckRestriction_ARG *check_restriction;
870 
871 	check_restriction = &args->qsig.CheckRestriction;
872 
873 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
874 	if (ctrl->debug & PRI_DEBUG_APDU) {
875 		pri_message(ctrl, "  CheckRestriction %s\n", asn1_tag2str(tag));
876 	}
877 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
878 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
879 
880 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
881 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "servedUserNr", tag, pos, seq_end,
882 		&check_restriction->served_user_number));
883 
884 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
885 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
886 	ASN1_CALL(pos, asn1_dec_int(ctrl, "basicService", tag, pos, seq_end, &value));
887 	check_restriction->basic_service = value;
888 
889 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
890 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "divertedToNr", tag, pos, seq_end,
891 		&check_restriction->diverted_to_number));
892 
893 	/* Fixup will skip over any OPTIONAL manufacturer extension information */
894 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
895 
896 	return pos;
897 }
898 
899 /*!
900  * \brief Decode the Q.SIG CallRerouting invoke argument parameters.
901  *
902  * \param ctrl D channel controller for diagnostic messages or global options.
903  * \param tag Component tag that identified this structure.
904  * \param pos Starting position of the ASN.1 component length.
905  * \param end End of ASN.1 decoding data buffer.
906  * \param args Arguments to fill in from the decoded buffer.
907  *
908  * \retval Start of the next ASN.1 component on success.
909  * \retval NULL on error.
910  */
rose_dec_qsig_CallRerouting_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)911 const unsigned char *rose_dec_qsig_CallRerouting_ARG(struct pri *ctrl, unsigned tag,
912 	const unsigned char *pos, const unsigned char *end, union rose_msg_invoke_args *args)
913 {
914 	int32_t value;
915 	int length;
916 	int seq_offset;
917 	int explicit_offset;
918 	const unsigned char *explicit_end;
919 	const unsigned char *seq_end;
920 	const unsigned char *save_pos;
921 	struct roseQsigCallRerouting_ARG *call_rerouting;
922 
923 	call_rerouting = &args->qsig.CallRerouting;
924 
925 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
926 	if (ctrl->debug & PRI_DEBUG_APDU) {
927 		pri_message(ctrl, "  CallRerouting %s\n", asn1_tag2str(tag));
928 	}
929 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
930 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
931 
932 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
933 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
934 	ASN1_CALL(pos, asn1_dec_int(ctrl, "reroutingReason", tag, pos, seq_end, &value));
935 	call_rerouting->rerouting_reason = value;
936 
937 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
938 	if (tag == (ASN1_CLASS_CONTEXT_SPECIFIC | 0)) {
939 		ASN1_CALL(pos, asn1_dec_int(ctrl, "originalReroutingReason", tag, pos, seq_end,
940 			&value));
941 		call_rerouting->original_rerouting_reason = value;
942 		call_rerouting->original_rerouting_reason_present = 1;
943 
944 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
945 	} else {
946 		call_rerouting->original_rerouting_reason_present = 0;
947 	}
948 
949 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
950 	ASN1_CALL(pos, rose_dec_Address(ctrl, "calledAddress", tag, pos, seq_end,
951 		&call_rerouting->called));
952 
953 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
954 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_INTEGER);
955 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionCounter", tag, pos, seq_end, &value));
956 	call_rerouting->diversion_counter = value;
957 
958 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
959 	ASN1_CHECK_TAG(ctrl, tag, tag & ~ASN1_PC_MASK, ASN1_CLASS_APPLICATION | 0);
960 	ASN1_CALL(pos, rose_dec_Q931ie(ctrl, "pSS1InfoElement", tag, pos, seq_end,
961 		&call_rerouting->q931ie, sizeof(call_rerouting->q931ie_contents)));
962 
963 	/* Remove EXPLICIT tag */
964 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
965 	ASN1_CHECK_TAG(ctrl, tag, tag,
966 		ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 1);
967 	if (ctrl->debug & PRI_DEBUG_APDU) {
968 		pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
969 	}
970 	ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
971 	ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
972 
973 	ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
974 	ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "lastReroutingNr", tag, pos,
975 		explicit_end, &call_rerouting->last_rerouting));
976 
977 	ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
978 
979 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
980 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_CLASS_CONTEXT_SPECIFIC | 2);
981 	ASN1_CALL(pos, asn1_dec_int(ctrl, "subscriptionOption", tag, pos, seq_end, &value));
982 	call_rerouting->subscription_option = value;
983 
984 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
985 	if (tag == (ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 3)) {
986 		/* Remove EXPLICIT tag */
987 		if (ctrl->debug & PRI_DEBUG_APDU) {
988 			pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
989 		}
990 		ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
991 		ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
992 
993 		ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
994 		ASN1_CALL(pos, rose_dec_PartySubaddress(ctrl, "callingPartySubaddress", tag, pos,
995 			explicit_end, &call_rerouting->calling_subaddress));
996 
997 		ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
998 
999 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1000 	} else {
1001 		call_rerouting->calling_subaddress.length = 0;
1002 	}
1003 
1004 	/* Remove EXPLICIT tag */
1005 	ASN1_CHECK_TAG(ctrl, tag, tag,
1006 		ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 4);
1007 	if (ctrl->debug & PRI_DEBUG_APDU) {
1008 		pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1009 	}
1010 	ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1011 	ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1012 
1013 	ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1014 	ASN1_CALL(pos, rose_dec_PresentedNumberScreened(ctrl, "callingNumber", tag, pos,
1015 		explicit_end, &call_rerouting->calling));
1016 
1017 	ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1018 
1019 	/*
1020 	 * A sequence specifies an ordered list of component types.
1021 	 * However, for simplicity we are not checking the order of
1022 	 * the remaining optional components.
1023 	 */
1024 	call_rerouting->calling_name_present = 0;
1025 	call_rerouting->redirecting_name_present = 0;
1026 	call_rerouting->original_called_name_present = 0;
1027 	call_rerouting->original_called_present = 0;
1028 	while (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1029 		save_pos = pos;
1030 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1031 		switch (tag) {
1032 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 5:
1033 			/* Remove EXPLICIT tag */
1034 			if (ctrl->debug & PRI_DEBUG_APDU) {
1035 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1036 			}
1037 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1038 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1039 
1040 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1041 			ASN1_CALL(pos, rose_dec_qsig_Name(ctrl, "callingName", tag, pos,
1042 				explicit_end, &call_rerouting->calling_name));
1043 			call_rerouting->calling_name_present = 1;
1044 
1045 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1046 			break;
1047 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 6:
1048 			/* Remove EXPLICIT tag */
1049 			if (ctrl->debug & PRI_DEBUG_APDU) {
1050 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1051 			}
1052 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1053 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1054 
1055 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1056 			ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "originalCalledNr",
1057 				tag, pos, explicit_end, &call_rerouting->original_called));
1058 			call_rerouting->original_called_present = 1;
1059 
1060 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1061 			break;
1062 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 7:
1063 			/* Remove EXPLICIT tag */
1064 			if (ctrl->debug & PRI_DEBUG_APDU) {
1065 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1066 			}
1067 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1068 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1069 
1070 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1071 			ASN1_CALL(pos, rose_dec_qsig_Name(ctrl, "redirectingName", tag, pos,
1072 				explicit_end, &call_rerouting->redirecting_name));
1073 			call_rerouting->redirecting_name_present = 1;
1074 
1075 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1076 			break;
1077 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 8:
1078 			/* Remove EXPLICIT tag */
1079 			if (ctrl->debug & PRI_DEBUG_APDU) {
1080 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1081 			}
1082 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1083 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1084 
1085 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1086 			ASN1_CALL(pos, rose_dec_qsig_Name(ctrl, "originalCalledName", tag, pos,
1087 				explicit_end, &call_rerouting->original_called_name));
1088 			call_rerouting->original_called_name_present = 1;
1089 
1090 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1091 			break;
1092 		case ASN1_CLASS_CONTEXT_SPECIFIC | 9:
1093 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 9:
1094 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 10:
1095 			if (ctrl->debug & PRI_DEBUG_APDU) {
1096 				pri_message(ctrl, "  extension %s\n", asn1_tag2str(tag));
1097 			}
1098 			/* Fixup will skip over the manufacturer extension information */
1099 		default:
1100 			pos = save_pos;
1101 			goto cancel_options;
1102 		}
1103 	}
1104 cancel_options:;
1105 
1106 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1107 
1108 	return pos;
1109 }
1110 
1111 /*!
1112  * \brief Decode the Q.SIG DivertingLegInformation1 invoke argument parameters.
1113  *
1114  * \param ctrl D channel controller for diagnostic messages or global options.
1115  * \param tag Component tag that identified this structure.
1116  * \param pos Starting position of the ASN.1 component length.
1117  * \param end End of ASN.1 decoding data buffer.
1118  * \param args Arguments to fill in from the decoded buffer.
1119  *
1120  * \retval Start of the next ASN.1 component on success.
1121  * \retval NULL on error.
1122  */
rose_dec_qsig_DivertingLegInformation1_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1123 const unsigned char *rose_dec_qsig_DivertingLegInformation1_ARG(struct pri *ctrl,
1124 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1125 	union rose_msg_invoke_args *args)
1126 {
1127 	int32_t value;
1128 	int length;
1129 	int seq_offset;
1130 	const unsigned char *seq_end;
1131 	struct roseQsigDivertingLegInformation1_ARG *diverting_leg_information_1;
1132 
1133 	diverting_leg_information_1 = &args->qsig.DivertingLegInformation1;
1134 
1135 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1136 	if (ctrl->debug & PRI_DEBUG_APDU) {
1137 		pri_message(ctrl, "  DivertingLegInformation1 %s\n", asn1_tag2str(tag));
1138 	}
1139 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1140 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1141 
1142 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1143 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1144 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionReason", tag, pos, seq_end, &value));
1145 	diverting_leg_information_1->diversion_reason = value;
1146 
1147 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1148 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1149 	ASN1_CALL(pos, asn1_dec_int(ctrl, "subscriptionOption", tag, pos, seq_end, &value));
1150 	diverting_leg_information_1->subscription_option = value;
1151 
1152 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1153 	ASN1_CALL(pos, rose_dec_PartyNumber(ctrl, "nominatedNr", tag, pos, seq_end,
1154 		&diverting_leg_information_1->nominated_number));
1155 
1156 	/* Fixup will skip over any OPTIONAL manufacturer extension information */
1157 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1158 
1159 	return pos;
1160 }
1161 
1162 /*!
1163  * \brief Decode the Q.SIG DivertingLegInformation2 invoke argument parameters.
1164  *
1165  * \param ctrl D channel controller for diagnostic messages or global options.
1166  * \param tag Component tag that identified this structure.
1167  * \param pos Starting position of the ASN.1 component length.
1168  * \param end End of ASN.1 decoding data buffer.
1169  * \param args Arguments to fill in from the decoded buffer.
1170  *
1171  * \retval Start of the next ASN.1 component on success.
1172  * \retval NULL on error.
1173  */
rose_dec_qsig_DivertingLegInformation2_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1174 const unsigned char *rose_dec_qsig_DivertingLegInformation2_ARG(struct pri *ctrl,
1175 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1176 	union rose_msg_invoke_args *args)
1177 {
1178 	int32_t value;
1179 	int length;
1180 	int seq_offset;
1181 	int explicit_offset;
1182 	const unsigned char *explicit_end;
1183 	const unsigned char *seq_end;
1184 	const unsigned char *save_pos;
1185 	struct roseQsigDivertingLegInformation2_ARG *diverting_leg_information_2;
1186 
1187 	diverting_leg_information_2 = &args->qsig.DivertingLegInformation2;
1188 
1189 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1190 	if (ctrl->debug & PRI_DEBUG_APDU) {
1191 		pri_message(ctrl, "  DivertingLegInformation2 %s\n", asn1_tag2str(tag));
1192 	}
1193 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1194 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1195 
1196 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1197 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_INTEGER);
1198 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionCounter", tag, pos, seq_end, &value));
1199 	diverting_leg_information_2->diversion_counter = value;
1200 
1201 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1202 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_ENUMERATED);
1203 	ASN1_CALL(pos, asn1_dec_int(ctrl, "diversionReason", tag, pos, seq_end, &value));
1204 	diverting_leg_information_2->diversion_reason = value;
1205 
1206 	/*
1207 	 * A sequence specifies an ordered list of component types.
1208 	 * However, for simplicity we are not checking the order of
1209 	 * the remaining optional components.
1210 	 */
1211 	diverting_leg_information_2->original_diversion_reason_present = 0;
1212 	diverting_leg_information_2->diverting_present = 0;
1213 	diverting_leg_information_2->original_called_present = 0;
1214 	diverting_leg_information_2->redirecting_name_present = 0;
1215 	diverting_leg_information_2->original_called_name_present = 0;
1216 	while (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1217 		save_pos = pos;
1218 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1219 		switch (tag) {
1220 		case ASN1_CLASS_CONTEXT_SPECIFIC | 0:
1221 			ASN1_CALL(pos, asn1_dec_int(ctrl, "originalDiversionReason", tag, pos,
1222 				seq_end, &value));
1223 			diverting_leg_information_2->original_diversion_reason = value;
1224 			diverting_leg_information_2->original_diversion_reason_present = 1;
1225 			break;
1226 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 1:
1227 			/* Remove EXPLICIT tag */
1228 			if (ctrl->debug & PRI_DEBUG_APDU) {
1229 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1230 			}
1231 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1232 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1233 
1234 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1235 			ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "divertingNr", tag,
1236 				pos, explicit_end, &diverting_leg_information_2->diverting));
1237 			diverting_leg_information_2->diverting_present = 1;
1238 
1239 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1240 			break;
1241 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 2:
1242 			/* Remove EXPLICIT tag */
1243 			if (ctrl->debug & PRI_DEBUG_APDU) {
1244 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1245 			}
1246 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1247 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1248 
1249 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1250 			ASN1_CALL(pos, rose_dec_PresentedNumberUnscreened(ctrl, "originalCalledNr",
1251 				tag, pos, explicit_end, &diverting_leg_information_2->original_called));
1252 			diverting_leg_information_2->original_called_present = 1;
1253 
1254 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1255 			break;
1256 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 3:
1257 			/* Remove EXPLICIT tag */
1258 			if (ctrl->debug & PRI_DEBUG_APDU) {
1259 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1260 			}
1261 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1262 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1263 
1264 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1265 			ASN1_CALL(pos, rose_dec_qsig_Name(ctrl, "redirectingName", tag, pos,
1266 				explicit_end, &diverting_leg_information_2->redirecting_name));
1267 			diverting_leg_information_2->redirecting_name_present = 1;
1268 
1269 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1270 			break;
1271 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 4:
1272 			/* Remove EXPLICIT tag */
1273 			if (ctrl->debug & PRI_DEBUG_APDU) {
1274 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1275 			}
1276 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1277 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1278 
1279 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1280 			ASN1_CALL(pos, rose_dec_qsig_Name(ctrl, "originalCalledName", tag, pos,
1281 				explicit_end, &diverting_leg_information_2->original_called_name));
1282 			diverting_leg_information_2->original_called_name_present = 1;
1283 
1284 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1285 			break;
1286 		case ASN1_CLASS_CONTEXT_SPECIFIC | 5:
1287 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 5:
1288 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 6:
1289 			if (ctrl->debug & PRI_DEBUG_APDU) {
1290 				pri_message(ctrl, "  extension %s\n", asn1_tag2str(tag));
1291 			}
1292 			/* Fixup will skip over the manufacturer extension information */
1293 		default:
1294 			pos = save_pos;
1295 			goto cancel_options;
1296 		}
1297 	}
1298 cancel_options:;
1299 
1300 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1301 
1302 	return pos;
1303 }
1304 
1305 /*!
1306  * \brief Decode the Q.SIG DivertingLegInformation3 invoke argument parameters.
1307  *
1308  * \param ctrl D channel controller for diagnostic messages or global options.
1309  * \param tag Component tag that identified this structure.
1310  * \param pos Starting position of the ASN.1 component length.
1311  * \param end End of ASN.1 decoding data buffer.
1312  * \param args Arguments to fill in from the decoded buffer.
1313  *
1314  * \retval Start of the next ASN.1 component on success.
1315  * \retval NULL on error.
1316  */
rose_dec_qsig_DivertingLegInformation3_ARG(struct pri * ctrl,unsigned tag,const unsigned char * pos,const unsigned char * end,union rose_msg_invoke_args * args)1317 const unsigned char *rose_dec_qsig_DivertingLegInformation3_ARG(struct pri *ctrl,
1318 	unsigned tag, const unsigned char *pos, const unsigned char *end,
1319 	union rose_msg_invoke_args *args)
1320 {
1321 	int32_t value;
1322 	int length;
1323 	int seq_offset;
1324 	int explicit_offset;
1325 	const unsigned char *explicit_end;
1326 	const unsigned char *seq_end;
1327 	const unsigned char *save_pos;
1328 	struct roseQsigDivertingLegInformation3_ARG *diverting_leg_information_3;
1329 
1330 	diverting_leg_information_3 = &args->qsig.DivertingLegInformation3;
1331 
1332 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TAG_SEQUENCE);
1333 	if (ctrl->debug & PRI_DEBUG_APDU) {
1334 		pri_message(ctrl, "  DivertingLegInformation3 %s\n", asn1_tag2str(tag));
1335 	}
1336 	ASN1_CALL(pos, asn1_dec_length(pos, end, &length));
1337 	ASN1_END_SETUP(seq_end, seq_offset, length, pos, end);
1338 
1339 	ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1340 	ASN1_CHECK_TAG(ctrl, tag, tag, ASN1_TYPE_BOOLEAN);
1341 	ASN1_CALL(pos, asn1_dec_boolean(ctrl, "presentationAllowedIndicator", tag, pos,
1342 		seq_end, &value));
1343 	diverting_leg_information_3->presentation_allowed_indicator = value;
1344 
1345 	/*
1346 	 * A sequence specifies an ordered list of component types.
1347 	 * However, for simplicity we are not checking the order of
1348 	 * the remaining optional components.
1349 	 */
1350 	diverting_leg_information_3->redirection_name_present = 0;
1351 	while (pos < seq_end && *pos != ASN1_INDEF_TERM) {
1352 		save_pos = pos;
1353 		ASN1_CALL(pos, asn1_dec_tag(pos, seq_end, &tag));
1354 		switch (tag) {
1355 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 0:
1356 			/* Remove EXPLICIT tag */
1357 			if (ctrl->debug & PRI_DEBUG_APDU) {
1358 				pri_message(ctrl, "  Explicit %s\n", asn1_tag2str(tag));
1359 			}
1360 			ASN1_CALL(pos, asn1_dec_length(pos, seq_end, &length));
1361 			ASN1_END_SETUP(explicit_end, explicit_offset, length, pos, seq_end);
1362 
1363 			ASN1_CALL(pos, asn1_dec_tag(pos, explicit_end, &tag));
1364 			ASN1_CALL(pos, rose_dec_qsig_Name(ctrl, "redirectionName", tag, pos,
1365 				explicit_end, &diverting_leg_information_3->redirection_name));
1366 			diverting_leg_information_3->redirection_name_present = 1;
1367 
1368 			ASN1_END_FIXUP(ctrl, pos, explicit_offset, explicit_end, seq_end);
1369 			break;
1370 		case ASN1_CLASS_CONTEXT_SPECIFIC | 1:
1371 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 1:
1372 		case ASN1_CLASS_CONTEXT_SPECIFIC | ASN1_PC_CONSTRUCTED | 2:
1373 			if (ctrl->debug & PRI_DEBUG_APDU) {
1374 				pri_message(ctrl, "  extension %s\n", asn1_tag2str(tag));
1375 			}
1376 			/* Fixup will skip over the manufacturer extension information */
1377 		default:
1378 			pos = save_pos;
1379 			goto cancel_options;
1380 		}
1381 	}
1382 cancel_options:;
1383 
1384 	ASN1_END_FIXUP(ctrl, pos, seq_offset, seq_end, end);
1385 
1386 	return pos;
1387 }
1388 
1389 /* ------------------------------------------------------------------- */
1390 /* end rose_qsig_diversion.c */
1391