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 Q.931 ie encode/decode functions
30  *
31  * \author Richard Mudgett <rmudgett@digium.com>
32  */
33 
34 
35 #include "compat.h"
36 #include "libpri.h"
37 #include "pri_internal.h"
38 #include "rose.h"
39 #include "rose_internal.h"
40 #include "asn1.h"
41 
42 
43 /* ------------------------------------------------------------------- */
44 
45 /*!
46  * \brief Encode the Q.931 ie value.
47  *
48  * \param ctrl D channel controller for diagnostic messages or global options.
49  * \param pos Starting position to encode ASN.1 component.
50  * \param end End of ASN.1 encoding data buffer.
51  * \param tag Component tag to identify the encoded component.
52  *   The tag should be ASN1_CLASS_APPLICATION | 0 unless the caller
53  *   implicitly tags it otherwise.
54  * \param q931ie Q931 ie 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_Q931ie(struct pri * ctrl,unsigned char * pos,unsigned char * end,unsigned tag,const struct roseQ931ie * q931ie)59 unsigned char *rose_enc_Q931ie(struct pri *ctrl, unsigned char *pos, unsigned char *end,
60 	unsigned tag, const struct roseQ931ie *q931ie)
61 {
62 	return asn1_enc_string_bin(pos, end, tag, q931ie->contents, q931ie->length);
63 }
64 
65 /*!
66  * \brief Decode the Q.931 ie value.
67  *
68  * \param ctrl D channel controller for diagnostic messages or global options.
69  * \param name Field name
70  * \param tag Component tag that identified this production.
71  * \param pos Starting position of the ASN.1 component length.
72  * \param end End of ASN.1 decoding data buffer.
73  * \param q931ie Parameter storage to fill.
74  * \param contents_size Amount of space "allocated" for the q931ie->contents
75  * element.  Must have enough room for a null terminator.
76  *
77  * \retval Start of the next ASN.1 component on success.
78  * \retval NULL on error.
79  */
rose_dec_Q931ie(struct pri * ctrl,const char * name,unsigned tag,const unsigned char * pos,const unsigned char * end,struct roseQ931ie * q931ie,size_t contents_size)80 const unsigned char *rose_dec_Q931ie(struct pri *ctrl, const char *name, unsigned tag,
81 	const unsigned char *pos, const unsigned char *end, struct roseQ931ie *q931ie,
82 	size_t contents_size)
83 {
84 	size_t str_len;
85 
86 	/* NOTE: The q931ie->contents memory is "allocated" after the struct. */
87 	ASN1_CALL(pos, asn1_dec_string_bin(ctrl, name, tag, pos, end, contents_size,
88 		q931ie->contents, &str_len));
89 	q931ie->length = str_len;
90 
91 	/*
92 	 * NOTE: We may want to do some basic decoding of the Q.931 ie list
93 	 * for debug purposes.
94 	 */
95 
96 	return pos;
97 }
98 
99 /* ------------------------------------------------------------------- */
100 /* end rose_q931.c */
101