blob: f3aa1a3fb29b9666b4ee581cf6322ff6e1c38296 [file] [log] [blame]
Harald Welte27f9c4a2015-08-30 22:47:18 +02001#include <stdint.h>
2
3#include <osmocom/core/msgb.h>
4
5#include "HNBAP-PDU.h"
6#include "hnbap_common.h"
Harald Weltec060b7b2015-09-07 22:40:41 +02007#include "hnbgw.h"
Harald Welte27f9c4a2015-08-30 22:47:18 +02008
9int asn_debug = 0;
10int asn1_xer_print = 0;
11
12static struct msgb *hnbap_msgb_alloc(void)
13{
14 return msgb_alloc(1024, "HNBAP Tx");
15}
16
17#if 0
18ssize_t s1ap_generate_initiating_message(uint8_t ** buffer,
19 uint32_t * length,
20 e_ProcedureCode procedureCode,
21 Criticality_t criticality,
22 asn_TYPE_descriptor_t * td, void *sptr)
23{
24
25 HNBAP_PDU_t pdu;
26 ssize_t encoded;
27
28 memset(&pdu, 0, sizeof(HNBAP_PDU_t));
29
30 pdu.present = HNBAP_PDU_PR_initiatingMessage;
31 pdu.choice.initiatingMessage.procedureCode = procedureCode;
32 pdu.choice.initiatingMessage.criticality = criticality;
33 ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr);
34
35 if (asn1_xer_print)
36 xer_fprint(stdout, &asn_DEF_HNBAP_PDU, (void *)&pdu);
37
38 if ((encoded =
39 aper_encode_to_new_buffer(&asn_DEF_HNBAP_PDU, 0, &pdu,
40 (void **)buffer)) < 0) {
41 return -1;
42 }
43
44 *length = encoded;
45 return encoded;
46}
47#endif
48
Harald Welte339b8e22015-08-30 23:08:32 +020049struct msgb *hnbap_generate_successful_outcome(
Harald Welte27f9c4a2015-08-30 22:47:18 +020050 e_ProcedureCode procedureCode,
51 Criticality_t criticality,
52 asn_TYPE_descriptor_t * td,
53 void *sptr)
54{
55
56 HNBAP_PDU_t pdu;
57 struct msgb *msg = hnbap_msgb_alloc();
58 asn_enc_rval_t rval;
Harald Weltec060b7b2015-09-07 22:40:41 +020059 int rc;
Harald Welte27f9c4a2015-08-30 22:47:18 +020060
61 memset(&pdu, 0, sizeof(HNBAP_PDU_t));
62 pdu.present = HNBAP_PDU_PR_successfulOutcome;
63 pdu.choice.successfulOutcome.procedureCode = procedureCode;
64 pdu.choice.successfulOutcome.criticality = criticality;
Harald Weltec060b7b2015-09-07 22:40:41 +020065 rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
66 if (rc < 0) {
67 LOGP(DMAIN, LOGL_ERROR, "Error in ANY_fromType_aper\n");
68 msgb_free(msg);
69 return NULL;
70 }
Harald Welte27f9c4a2015-08-30 22:47:18 +020071
72 rval = aper_encode_to_buffer(&asn_DEF_HNBAP_PDU, &pdu,
Harald Welte1c1c53c2015-09-07 22:41:02 +020073 msg->data, msgb_tailroom(msg));
Harald Welte27f9c4a2015-08-30 22:47:18 +020074 if (rval.encoded < 0) {
Harald Weltec060b7b2015-09-07 22:40:41 +020075 LOGP(DMAIN, LOGL_ERROR, "Error encoding type %s\n", rval.failed_type->name);
Harald Welte27f9c4a2015-08-30 22:47:18 +020076 msgb_free(msg);
77 return NULL;
78 }
79
Harald Weltee2e5d4d2015-09-10 23:49:45 +020080 msgb_put(msg, rval.encoded/8);
Harald Welte27f9c4a2015-08-30 22:47:18 +020081
82 return msg;
83}
84
85#if 0
Harald Welte339b8e22015-08-30 23:08:32 +020086ssize_t s1ap_generate_unsuccessful_outcome(uint8_t ** buffer,
Harald Welte27f9c4a2015-08-30 22:47:18 +020087 uint32_t * length,
88 e_ProcedureCode procedureCode,
89 Criticality_t criticality,
90 asn_TYPE_descriptor_t * td,
91 void *sptr)
92{
93
94 HNBAP_PDU_t pdu;
95 ssize_t encoded;
96
97 memset(&pdu, 0, sizeof(HNBAP_PDU_t));
98
99 pdu.present = HNBAP_PDU_PR_unsuccessfulOutcome;
100 pdu.choice.successfulOutcome.procedureCode = procedureCode;
101 pdu.choice.successfulOutcome.criticality = criticality;
102 ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr);
103
104 if ((encoded =
105 aper_encode_to_new_buffer(&asn_DEF_HNBAP_PDU, 0, &pdu,
106 (void **)buffer)) < 0) {
107 return -1;
108 }
109
110 *length = encoded;
111
112 return encoded;
113}
114#endif
115
116IE_t *hnbap_new_ie(ProtocolIE_ID_t id,
117 Criticality_t criticality,
118 asn_TYPE_descriptor_t * type, void *sptr)
119{
120
121 IE_t *buff;
122
123 if ((buff = malloc(sizeof(IE_t))) == NULL) {
124 // Possible error on malloc
125 return NULL;
126 }
127 memset((void *)buff, 0, sizeof(IE_t));
128
129 buff->id = id;
130 buff->criticality = criticality;
131
132 ANY_fromType_aper(&buff->value, type, sptr);
133
134 if (asn1_xer_print)
135 if (xer_fprint(stdout, &asn_DEF_IE, buff) < 0) {
136 free(buff);
137 return NULL;
138 }
139
140 return buff;
141}