blob: 637cd72a413b740760c0d553b05b8c9ccd2e05aa [file] [log] [blame]
Harald Welte656ad302015-09-10 18:33:47 +02001#include <stdint.h>
2
3#include <osmocom/core/msgb.h>
4
5#include "rua_common.h"
6#include "hnbgw.h"
7
8extern int asn1_xer_print;
9
10static struct msgb *rua_msgb_alloc(void)
11{
12 return msgb_alloc(1024, "RUA Tx");
13}
14
15#if 0
16ssize_t rua_generate_initiating_message(uint8_t ** buffer,
17 uint32_t * length,
18 e_RUA_ProcedureCode procedureCode,
19 RUA_Criticality_t criticality,
20 asn_TYPE_descriptor_t * td, void *sptr)
21{
22 RUA_RUA_PDU_t pdu;
23 ssize_t encoded;
24
25 memset(&pdu, 0, sizeof(pdu));
26
27 pdu.present = RUA_RUA_PDU_PR_initiatingMessage;
28 pdu.choice.initiatingMessage.procedureCode = procedureCode;
29 pdu.choice.initiatingMessage.criticality = criticality;
30 ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr);
31
32 if (asn1_xer_print)
33 xer_fprint(stdout, &asn_DEF_RUA_RUA_PDU, (void *)&pdu);
34
35 if ((encoded =
36 aper_encode_to_new_buffer(&asn_DEF_RUA_RUA_PDU, 0, &pdu,
37 (void **)buffer)) < 0) {
38 return -1;
39 }
40
41 *length = encoded;
42 return encoded;
43}
44#endif
45
46struct msgb *rua_generate_successful_outcome(
47 e_RUA_ProcedureCode procedureCode,
48 RUA_Criticality_t criticality,
49 asn_TYPE_descriptor_t * td,
50 void *sptr)
51{
52
53 RUA_RUA_PDU_t pdu;
54 struct msgb *msg = rua_msgb_alloc();
55 asn_enc_rval_t rval;
56 int rc;
57
58 memset(&pdu, 0, sizeof(pdu));
59 pdu.present = RUA_RUA_PDU_PR_successfulOutcome;
60 pdu.choice.successfulOutcome.procedureCode = procedureCode;
61 pdu.choice.successfulOutcome.criticality = criticality;
62 rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
63 if (rc < 0) {
64 LOGP(DMAIN, LOGL_ERROR, "Error in ANY_fromType_aper\n");
65 msgb_free(msg);
66 return NULL;
67 }
68
69 rval = aper_encode_to_buffer(&asn_DEF_RUA_RUA_PDU, &pdu,
70 msg->data, msgb_tailroom(msg));
71 if (rval.encoded < 0) {
72 LOGP(DMAIN, LOGL_ERROR, "Error encoding type %s\n", rval.failed_type->name);
73 msgb_free(msg);
74 return NULL;
75 }
76
77 msgb_put(msg, rval.encoded);
78
79 return msg;
80}
81
82#if 0
83ssize_t rua_generate_unsuccessful_outcome(uint8_t ** buffer,
84 uint32_t * length,
85 e_RUA_ProcedureCode procedureCode,
86 RUA_Criticality_t criticality,
87 asn_TYPE_descriptor_t * td,
88 void *sptr)
89{
90
91 RUA_RUA_PDU_t pdu;
92 ssize_t encoded;
93
94 memset(&pdu, 0, sizeof(pdu));
95
96 pdu.present = RUA_RUA_PDU_PR_unsuccessfulOutcome;
97 pdu.choice.successfulOutcome.procedureCode = procedureCode;
98 pdu.choice.successfulOutcome.criticality = criticality;
99 ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
100
101 if ((encoded =
102 aper_encode_to_new_buffer(&asn_DEF_RUA_RUA_PDU, 0, &pdu,
103 (void **)buffer)) < 0) {
104 return -1;
105 }
106
107 *length = encoded;
108
109 return encoded;
110}
111#endif
112
113RUA_IE_t *rua_new_ie(RUA_ProtocolIE_ID_t id,
114 RUA_Criticality_t criticality,
115 asn_TYPE_descriptor_t * type, void *sptr)
116{
117
118 RUA_IE_t *buff;
119
120 if ((buff = malloc(sizeof(*buff))) == NULL) {
121 // Possible error on malloc
122 return NULL;
123 }
124 memset((void *)buff, 0, sizeof(*buff));
125
126 buff->id = id;
127 buff->criticality = criticality;
128
129 ANY_fromType_aper(&buff->value, type, sptr);
130
131 if (asn1_xer_print)
132 if (xer_fprint(stdout, &asn_DEF_RUA_IE, buff) < 0) {
133 free(buff);
134 return NULL;
135 }
136
137 return buff;
138}