Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | |
| 3 | #include <osmocom/core/msgb.h> |
| 4 | |
| 5 | #include "HNBAP-PDU.h" |
| 6 | #include "hnbap_common.h" |
| 7 | |
| 8 | int asn_debug = 0; |
| 9 | int asn1_xer_print = 0; |
| 10 | |
| 11 | static struct msgb *hnbap_msgb_alloc(void) |
| 12 | { |
| 13 | return msgb_alloc(1024, "HNBAP Tx"); |
| 14 | } |
| 15 | |
| 16 | #if 0 |
| 17 | ssize_t s1ap_generate_initiating_message(uint8_t ** buffer, |
| 18 | uint32_t * length, |
| 19 | e_ProcedureCode procedureCode, |
| 20 | Criticality_t criticality, |
| 21 | asn_TYPE_descriptor_t * td, void *sptr) |
| 22 | { |
| 23 | |
| 24 | HNBAP_PDU_t pdu; |
| 25 | ssize_t encoded; |
| 26 | |
| 27 | memset(&pdu, 0, sizeof(HNBAP_PDU_t)); |
| 28 | |
| 29 | pdu.present = HNBAP_PDU_PR_initiatingMessage; |
| 30 | pdu.choice.initiatingMessage.procedureCode = procedureCode; |
| 31 | pdu.choice.initiatingMessage.criticality = criticality; |
| 32 | ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr); |
| 33 | |
| 34 | if (asn1_xer_print) |
| 35 | xer_fprint(stdout, &asn_DEF_HNBAP_PDU, (void *)&pdu); |
| 36 | |
| 37 | if ((encoded = |
| 38 | aper_encode_to_new_buffer(&asn_DEF_HNBAP_PDU, 0, &pdu, |
| 39 | (void **)buffer)) < 0) { |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | *length = encoded; |
| 44 | return encoded; |
| 45 | } |
| 46 | #endif |
| 47 | |
Harald Welte | 339b8e2 | 2015-08-30 23:08:32 +0200 | [diff] [blame] | 48 | struct msgb *hnbap_generate_successful_outcome( |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 49 | e_ProcedureCode procedureCode, |
| 50 | Criticality_t criticality, |
| 51 | asn_TYPE_descriptor_t * td, |
| 52 | void *sptr) |
| 53 | { |
| 54 | |
| 55 | HNBAP_PDU_t pdu; |
| 56 | struct msgb *msg = hnbap_msgb_alloc(); |
| 57 | asn_enc_rval_t rval; |
| 58 | |
| 59 | memset(&pdu, 0, sizeof(HNBAP_PDU_t)); |
| 60 | pdu.present = HNBAP_PDU_PR_successfulOutcome; |
| 61 | pdu.choice.successfulOutcome.procedureCode = procedureCode; |
| 62 | pdu.choice.successfulOutcome.criticality = criticality; |
| 63 | ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr); |
| 64 | |
| 65 | rval = aper_encode_to_buffer(&asn_DEF_HNBAP_PDU, &pdu, |
| 66 | msg->data, msgb_length(msg)); |
| 67 | if (rval.encoded < 0) { |
| 68 | msgb_free(msg); |
| 69 | return NULL; |
| 70 | } |
| 71 | |
| 72 | msgb_put(msg, rval.encoded); |
| 73 | |
| 74 | return msg; |
| 75 | } |
| 76 | |
| 77 | #if 0 |
Harald Welte | 339b8e2 | 2015-08-30 23:08:32 +0200 | [diff] [blame] | 78 | ssize_t s1ap_generate_unsuccessful_outcome(uint8_t ** buffer, |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 79 | uint32_t * length, |
| 80 | e_ProcedureCode procedureCode, |
| 81 | Criticality_t criticality, |
| 82 | asn_TYPE_descriptor_t * td, |
| 83 | void *sptr) |
| 84 | { |
| 85 | |
| 86 | HNBAP_PDU_t pdu; |
| 87 | ssize_t encoded; |
| 88 | |
| 89 | memset(&pdu, 0, sizeof(HNBAP_PDU_t)); |
| 90 | |
| 91 | pdu.present = HNBAP_PDU_PR_unsuccessfulOutcome; |
| 92 | pdu.choice.successfulOutcome.procedureCode = procedureCode; |
| 93 | pdu.choice.successfulOutcome.criticality = criticality; |
| 94 | ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr); |
| 95 | |
| 96 | if ((encoded = |
| 97 | aper_encode_to_new_buffer(&asn_DEF_HNBAP_PDU, 0, &pdu, |
| 98 | (void **)buffer)) < 0) { |
| 99 | return -1; |
| 100 | } |
| 101 | |
| 102 | *length = encoded; |
| 103 | |
| 104 | return encoded; |
| 105 | } |
| 106 | #endif |
| 107 | |
| 108 | IE_t *hnbap_new_ie(ProtocolIE_ID_t id, |
| 109 | Criticality_t criticality, |
| 110 | asn_TYPE_descriptor_t * type, void *sptr) |
| 111 | { |
| 112 | |
| 113 | IE_t *buff; |
| 114 | |
| 115 | if ((buff = malloc(sizeof(IE_t))) == NULL) { |
| 116 | // Possible error on malloc |
| 117 | return NULL; |
| 118 | } |
| 119 | memset((void *)buff, 0, sizeof(IE_t)); |
| 120 | |
| 121 | buff->id = id; |
| 122 | buff->criticality = criticality; |
| 123 | |
| 124 | ANY_fromType_aper(&buff->value, type, sptr); |
| 125 | |
| 126 | if (asn1_xer_print) |
| 127 | if (xer_fprint(stdout, &asn_DEF_IE, buff) < 0) { |
| 128 | free(buff); |
| 129 | return NULL; |
| 130 | } |
| 131 | |
| 132 | return buff; |
| 133 | } |