Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | |
| 3 | #include <osmocom/core/msgb.h> |
| 4 | |
Harald Welte | 350814a | 2015-09-10 22:32:15 +0200 | [diff] [blame] | 5 | //#include "ranap_common.h" |
| 6 | #include "ranap/RANAP_RANAP-PDU.h" |
| 7 | #include "ranap/RANAP_ProtocolIE-ID.h" |
| 8 | #include "ranap/RANAP_IE.h" |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 9 | #include "hnbgw.h" |
| 10 | |
| 11 | extern int asn1_xer_print; |
| 12 | |
| 13 | static struct msgb *ranap_msgb_alloc(void) |
| 14 | { |
| 15 | return msgb_alloc(1024, "RANAP Tx"); |
| 16 | } |
| 17 | |
| 18 | #if 0 |
| 19 | ssize_t ranap_generate_initiating_message(uint8_t ** buffer, |
| 20 | uint32_t * length, |
| 21 | e_RANAP_ProcedureCode procedureCode, |
| 22 | RANAP_Criticality_t criticality, |
| 23 | asn_TYPE_descriptor_t * td, void *sptr) |
| 24 | { |
| 25 | RANAP_RANAP_PDU_t pdu; |
| 26 | ssize_t encoded; |
| 27 | |
| 28 | memset(&pdu, 0, sizeof(pdu)); |
| 29 | |
| 30 | pdu.present = RANAP_RANAP_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_RANAP_RAMAP_PDU, (void *)&pdu); |
| 37 | |
| 38 | if ((encoded = |
| 39 | aper_encode_to_new_buffer(&asn_DEF_RANAP_RANAP_PDU, 0, &pdu, |
| 40 | (void **)buffer)) < 0) { |
| 41 | return -1; |
| 42 | } |
| 43 | |
| 44 | *length = encoded; |
| 45 | return encoded; |
| 46 | } |
| 47 | #endif |
| 48 | |
| 49 | struct msgb *ranap_generate_successful_outcome( |
| 50 | e_RANAP_ProcedureCode procedureCode, |
| 51 | RANAP_Criticality_t criticality, |
| 52 | asn_TYPE_descriptor_t * td, |
| 53 | void *sptr) |
| 54 | { |
| 55 | |
| 56 | RANAP_RANAP_PDU_t pdu; |
| 57 | struct msgb *msg = ranap_msgb_alloc(); |
| 58 | asn_enc_rval_t rval; |
| 59 | int rc; |
| 60 | |
| 61 | memset(&pdu, 0, sizeof(pdu)); |
| 62 | pdu.present = RANAP_RANAP_PDU_PR_successfulOutcome; |
| 63 | pdu.choice.successfulOutcome.procedureCode = procedureCode; |
| 64 | pdu.choice.successfulOutcome.criticality = criticality; |
| 65 | 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 | } |
| 71 | |
| 72 | rval = aper_encode_to_buffer(&asn_DEF_RANAP_RANAP_PDU, &pdu, |
| 73 | msg->data, msgb_tailroom(msg)); |
| 74 | if (rval.encoded < 0) { |
| 75 | LOGP(DMAIN, LOGL_ERROR, "Error encoding type %s\n", rval.failed_type->name); |
| 76 | msgb_free(msg); |
| 77 | return NULL; |
| 78 | } |
| 79 | |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 80 | msgb_put(msg, rval.encoded/8); |
Harald Welte | ac9c024 | 2015-09-10 21:18:16 +0200 | [diff] [blame] | 81 | |
| 82 | return msg; |
| 83 | } |
| 84 | |
| 85 | #if 0 |
| 86 | ssize_t ranap_generate_unsuccessful_outcome(uint8_t ** buffer, |
| 87 | uint32_t * length, |
| 88 | e_RANAP_ProcedureCode procedureCode, |
| 89 | RANAP_Criticality_t criticality, |
| 90 | asn_TYPE_descriptor_t * td, |
| 91 | void *sptr) |
| 92 | { |
| 93 | |
| 94 | RANAP_RANAP_PDU_t pdu; |
| 95 | ssize_t encoded; |
| 96 | |
| 97 | memset(&pdu, 0, sizeof(pdu)); |
| 98 | |
| 99 | pdu.present = RANAP_RANAP_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_RANAP_RANAP_PDU, 0, &pdu, |
| 106 | (void **)buffer)) < 0) { |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | *length = encoded; |
| 111 | |
| 112 | return encoded; |
| 113 | } |
| 114 | #endif |
| 115 | |
| 116 | RANAP_IE_t *ranap_new_ie(RANAP_ProtocolIE_ID_t id, |
| 117 | RANAP_Criticality_t criticality, |
| 118 | asn_TYPE_descriptor_t * type, void *sptr) |
| 119 | { |
| 120 | |
| 121 | RANAP_IE_t *buff; |
| 122 | |
| 123 | if ((buff = malloc(sizeof(*buff))) == NULL) { |
| 124 | // Possible error on malloc |
| 125 | return NULL; |
| 126 | } |
| 127 | memset((void *)buff, 0, sizeof(*buff)); |
| 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_RANAP_IE, buff) < 0) { |
| 136 | free(buff); |
| 137 | return NULL; |
| 138 | } |
| 139 | |
| 140 | return buff; |
| 141 | } |