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" |
Harald Welte | c060b7b | 2015-09-07 22:40:41 +0200 | [diff] [blame] | 7 | #include "hnbgw.h" |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 8 | |
Harald Welte | 3af1db8 | 2015-09-11 17:03:16 +0200 | [diff] [blame] | 9 | static const struct value_string hnbap_cause_radio_vals[] = { |
| 10 | { CauseRadioNetwork_overload, "overload" }, |
| 11 | { CauseRadioNetwork_unauthorised_Location, "unauthorized location" }, |
| 12 | { CauseRadioNetwork_unauthorised_HNB, "unauthorized HNB" }, |
| 13 | { CauseRadioNetwork_hNB_parameter_mismatch, "HNB parameter mismatch" }, |
| 14 | { CauseRadioNetwork_invalid_UE_identity, "invalid UE identity" }, |
| 15 | { CauseRadioNetwork_uE_not_allowed_on_this_HNB, |
| 16 | "UE not allowed on this HNB" }, |
| 17 | { CauseRadioNetwork_uE_unauthorised, "unauthorised UE" }, |
| 18 | { CauseRadioNetwork_connection_with_UE_lost, "connection with UE lost" }, |
| 19 | { CauseRadioNetwork_ue_RRC_release, "UE RRC release" }, |
| 20 | { CauseRadioNetwork_hNB_not_registered, "HNB not registered" }, |
| 21 | { CauseRadioNetwork_unspecified, "unspecified" }, |
| 22 | { CauseRadioNetwork_normal, "normal" }, |
| 23 | { CauseRadioNetwork_uE_relocated, "UE relocated" }, |
| 24 | { CauseRadioNetwork_ue_registered_in_another_HNB, |
| 25 | "UE registered in another HNB" }, |
| 26 | { 0, NULL } |
| 27 | }; |
| 28 | |
| 29 | static const struct value_string hnbap_cause_transp_vals[] = { |
| 30 | { CauseTransport_transport_resource_unavailable, |
| 31 | "transport resource unavailable" }, |
| 32 | { CauseTransport_unspecified, "unspecified" }, |
| 33 | { 0, NULL } |
| 34 | }; |
| 35 | |
| 36 | static const struct value_string hnbap_cause_prot_vals[] = { |
| 37 | { CauseProtocol_transfer_syntax_error, "syntax error" }, |
| 38 | { CauseProtocol_abstract_syntax_error_reject, |
| 39 | "abstract syntax error; reject" }, |
| 40 | { CauseProtocol_abstract_syntax_error_ignore_and_notify, |
| 41 | "abstract syntax error; ignore and notify" }, |
| 42 | { CauseProtocol_message_not_compatible_with_receiver_state, |
| 43 | "message not compatible with receiver state" }, |
| 44 | { CauseProtocol_semantic_error, "semantic error" }, |
| 45 | { CauseProtocol_unspecified, "unspecified" }, |
| 46 | { CauseProtocol_abstract_syntax_error_falsely_constructed_message, |
| 47 | "falsely constructed message" }, |
| 48 | { 0, NULL } |
| 49 | }; |
| 50 | |
| 51 | static const struct value_string hnbap_cause_misc_vals[] = { |
| 52 | { CauseMisc_processing_overload, "processing overload" }, |
| 53 | { CauseMisc_hardware_failure, "hardware failure" }, |
| 54 | { CauseMisc_o_and_m_intervention, "OAM intervention" }, |
| 55 | { CauseMisc_unspecified, "unspecified" }, |
| 56 | { 0, NULL } |
| 57 | }; |
| 58 | |
| 59 | char *hnbap_cause_str(Cause_t *cause) |
| 60 | { |
| 61 | static char buf[32]; |
| 62 | |
| 63 | switch (cause->present) { |
| 64 | case Cause_PR_radioNetwork: |
| 65 | snprintf(buf, sizeof(buf), "radio(%s)", |
| 66 | get_value_string(hnbap_cause_radio_vals, |
| 67 | cause->choice.radioNetwork)); |
| 68 | break; |
| 69 | case Cause_PR_transport: |
| 70 | snprintf(buf, sizeof(buf), "transport(%s)", |
| 71 | get_value_string(hnbap_cause_transp_vals, |
| 72 | cause->choice.transport)); |
| 73 | break; |
| 74 | case Cause_PR_protocol: |
| 75 | snprintf(buf, sizeof(buf), "protocol(%s)", |
| 76 | get_value_string(hnbap_cause_prot_vals, |
| 77 | cause->choice.protocol)); |
| 78 | break; |
| 79 | case Cause_PR_misc: |
| 80 | snprintf(buf, sizeof(buf), "misc(%s)", |
| 81 | get_value_string(hnbap_cause_misc_vals, |
| 82 | cause->choice.misc)); |
| 83 | break; |
| 84 | } |
| 85 | return buf; |
| 86 | } |
| 87 | |
| 88 | |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 89 | int asn_debug = 0; |
| 90 | int asn1_xer_print = 0; |
| 91 | |
| 92 | static struct msgb *hnbap_msgb_alloc(void) |
| 93 | { |
| 94 | return msgb_alloc(1024, "HNBAP Tx"); |
| 95 | } |
| 96 | |
| 97 | #if 0 |
| 98 | ssize_t s1ap_generate_initiating_message(uint8_t ** buffer, |
| 99 | uint32_t * length, |
| 100 | e_ProcedureCode procedureCode, |
| 101 | Criticality_t criticality, |
| 102 | asn_TYPE_descriptor_t * td, void *sptr) |
| 103 | { |
| 104 | |
| 105 | HNBAP_PDU_t pdu; |
| 106 | ssize_t encoded; |
| 107 | |
| 108 | memset(&pdu, 0, sizeof(HNBAP_PDU_t)); |
| 109 | |
| 110 | pdu.present = HNBAP_PDU_PR_initiatingMessage; |
| 111 | pdu.choice.initiatingMessage.procedureCode = procedureCode; |
| 112 | pdu.choice.initiatingMessage.criticality = criticality; |
| 113 | ANY_fromType_aper(&pdu.choice.initiatingMessage.value, td, sptr); |
| 114 | |
| 115 | if (asn1_xer_print) |
| 116 | xer_fprint(stdout, &asn_DEF_HNBAP_PDU, (void *)&pdu); |
| 117 | |
| 118 | if ((encoded = |
| 119 | aper_encode_to_new_buffer(&asn_DEF_HNBAP_PDU, 0, &pdu, |
| 120 | (void **)buffer)) < 0) { |
| 121 | return -1; |
| 122 | } |
| 123 | |
| 124 | *length = encoded; |
| 125 | return encoded; |
| 126 | } |
| 127 | #endif |
| 128 | |
Harald Welte | 339b8e2 | 2015-08-30 23:08:32 +0200 | [diff] [blame] | 129 | struct msgb *hnbap_generate_successful_outcome( |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 130 | e_ProcedureCode procedureCode, |
| 131 | Criticality_t criticality, |
| 132 | asn_TYPE_descriptor_t * td, |
| 133 | void *sptr) |
| 134 | { |
| 135 | |
| 136 | HNBAP_PDU_t pdu; |
| 137 | struct msgb *msg = hnbap_msgb_alloc(); |
| 138 | asn_enc_rval_t rval; |
Harald Welte | c060b7b | 2015-09-07 22:40:41 +0200 | [diff] [blame] | 139 | int rc; |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 140 | |
| 141 | memset(&pdu, 0, sizeof(HNBAP_PDU_t)); |
| 142 | pdu.present = HNBAP_PDU_PR_successfulOutcome; |
| 143 | pdu.choice.successfulOutcome.procedureCode = procedureCode; |
| 144 | pdu.choice.successfulOutcome.criticality = criticality; |
Harald Welte | c060b7b | 2015-09-07 22:40:41 +0200 | [diff] [blame] | 145 | rc = ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr); |
| 146 | if (rc < 0) { |
| 147 | LOGP(DMAIN, LOGL_ERROR, "Error in ANY_fromType_aper\n"); |
| 148 | msgb_free(msg); |
| 149 | return NULL; |
| 150 | } |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 151 | |
| 152 | rval = aper_encode_to_buffer(&asn_DEF_HNBAP_PDU, &pdu, |
Harald Welte | 1c1c53c | 2015-09-07 22:41:02 +0200 | [diff] [blame] | 153 | msg->data, msgb_tailroom(msg)); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 154 | if (rval.encoded < 0) { |
Harald Welte | c060b7b | 2015-09-07 22:40:41 +0200 | [diff] [blame] | 155 | LOGP(DMAIN, LOGL_ERROR, "Error encoding type %s\n", rval.failed_type->name); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 156 | msgb_free(msg); |
| 157 | return NULL; |
| 158 | } |
| 159 | |
Harald Welte | e2e5d4d | 2015-09-10 23:49:45 +0200 | [diff] [blame] | 160 | msgb_put(msg, rval.encoded/8); |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 161 | |
| 162 | return msg; |
| 163 | } |
| 164 | |
| 165 | #if 0 |
Harald Welte | 339b8e2 | 2015-08-30 23:08:32 +0200 | [diff] [blame] | 166 | ssize_t s1ap_generate_unsuccessful_outcome(uint8_t ** buffer, |
Harald Welte | 27f9c4a | 2015-08-30 22:47:18 +0200 | [diff] [blame] | 167 | uint32_t * length, |
| 168 | e_ProcedureCode procedureCode, |
| 169 | Criticality_t criticality, |
| 170 | asn_TYPE_descriptor_t * td, |
| 171 | void *sptr) |
| 172 | { |
| 173 | |
| 174 | HNBAP_PDU_t pdu; |
| 175 | ssize_t encoded; |
| 176 | |
| 177 | memset(&pdu, 0, sizeof(HNBAP_PDU_t)); |
| 178 | |
| 179 | pdu.present = HNBAP_PDU_PR_unsuccessfulOutcome; |
| 180 | pdu.choice.successfulOutcome.procedureCode = procedureCode; |
| 181 | pdu.choice.successfulOutcome.criticality = criticality; |
| 182 | ANY_fromType_aper(&pdu.choice.successfulOutcome.value, td, sptr); |
| 183 | |
| 184 | if ((encoded = |
| 185 | aper_encode_to_new_buffer(&asn_DEF_HNBAP_PDU, 0, &pdu, |
| 186 | (void **)buffer)) < 0) { |
| 187 | return -1; |
| 188 | } |
| 189 | |
| 190 | *length = encoded; |
| 191 | |
| 192 | return encoded; |
| 193 | } |
| 194 | #endif |
| 195 | |
| 196 | IE_t *hnbap_new_ie(ProtocolIE_ID_t id, |
| 197 | Criticality_t criticality, |
| 198 | asn_TYPE_descriptor_t * type, void *sptr) |
| 199 | { |
| 200 | |
| 201 | IE_t *buff; |
| 202 | |
| 203 | if ((buff = malloc(sizeof(IE_t))) == NULL) { |
| 204 | // Possible error on malloc |
| 205 | return NULL; |
| 206 | } |
| 207 | memset((void *)buff, 0, sizeof(IE_t)); |
| 208 | |
| 209 | buff->id = id; |
| 210 | buff->criticality = criticality; |
| 211 | |
| 212 | ANY_fromType_aper(&buff->value, type, sptr); |
| 213 | |
| 214 | if (asn1_xer_print) |
| 215 | if (xer_fprint(stdout, &asn_DEF_IE, buff) < 0) { |
| 216 | free(buff); |
| 217 | return NULL; |
| 218 | } |
| 219 | |
| 220 | return buff; |
| 221 | } |